1*8dab9197SMauro Carvalho Chehab============================== 2*8dab9197SMauro Carvalho ChehabFlash LED handling under Linux 3*8dab9197SMauro Carvalho Chehab============================== 4*8dab9197SMauro Carvalho Chehab 5*8dab9197SMauro Carvalho ChehabSome LED devices provide two modes - torch and flash. In the LED subsystem 6*8dab9197SMauro Carvalho Chehabthose modes are supported by LED class (see Documentation/leds/leds-class.rst) 7*8dab9197SMauro Carvalho Chehaband LED Flash class respectively. The torch mode related features are enabled 8*8dab9197SMauro Carvalho Chehabby default and the flash ones only if a driver declares it by setting 9*8dab9197SMauro Carvalho ChehabLED_DEV_CAP_FLASH flag. 10*8dab9197SMauro Carvalho Chehab 11*8dab9197SMauro Carvalho ChehabIn order to enable the support for flash LEDs CONFIG_LEDS_CLASS_FLASH symbol 12*8dab9197SMauro Carvalho Chehabmust be defined in the kernel config. A LED Flash class driver must be 13*8dab9197SMauro Carvalho Chehabregistered in the LED subsystem with led_classdev_flash_register function. 14*8dab9197SMauro Carvalho Chehab 15*8dab9197SMauro Carvalho ChehabFollowing sysfs attributes are exposed for controlling flash LED devices: 16*8dab9197SMauro Carvalho Chehab(see Documentation/ABI/testing/sysfs-class-led-flash) 17*8dab9197SMauro Carvalho Chehab 18*8dab9197SMauro Carvalho Chehab - flash_brightness 19*8dab9197SMauro Carvalho Chehab - max_flash_brightness 20*8dab9197SMauro Carvalho Chehab - flash_timeout 21*8dab9197SMauro Carvalho Chehab - max_flash_timeout 22*8dab9197SMauro Carvalho Chehab - flash_strobe 23*8dab9197SMauro Carvalho Chehab - flash_fault 24*8dab9197SMauro Carvalho Chehab 25*8dab9197SMauro Carvalho Chehab 26*8dab9197SMauro Carvalho ChehabV4L2 flash wrapper for flash LEDs 27*8dab9197SMauro Carvalho Chehab================================= 28*8dab9197SMauro Carvalho Chehab 29*8dab9197SMauro Carvalho ChehabA LED subsystem driver can be controlled also from the level of VideoForLinux2 30*8dab9197SMauro Carvalho Chehabsubsystem. In order to enable this CONFIG_V4L2_FLASH_LED_CLASS symbol has to 31*8dab9197SMauro Carvalho Chehabbe defined in the kernel config. 32*8dab9197SMauro Carvalho Chehab 33*8dab9197SMauro Carvalho ChehabThe driver must call the v4l2_flash_init function to get registered in the 34*8dab9197SMauro Carvalho ChehabV4L2 subsystem. The function takes six arguments: 35*8dab9197SMauro Carvalho Chehab 36*8dab9197SMauro Carvalho Chehab- dev: 37*8dab9197SMauro Carvalho Chehab flash device, e.g. an I2C device 38*8dab9197SMauro Carvalho Chehab- of_node: 39*8dab9197SMauro Carvalho Chehab of_node of the LED, may be NULL if the same as device's 40*8dab9197SMauro Carvalho Chehab- fled_cdev: 41*8dab9197SMauro Carvalho Chehab LED flash class device to wrap 42*8dab9197SMauro Carvalho Chehab- iled_cdev: 43*8dab9197SMauro Carvalho Chehab LED flash class device representing indicator LED associated with 44*8dab9197SMauro Carvalho Chehab fled_cdev, may be NULL 45*8dab9197SMauro Carvalho Chehab- ops: 46*8dab9197SMauro Carvalho Chehab V4L2 specific ops 47*8dab9197SMauro Carvalho Chehab 48*8dab9197SMauro Carvalho Chehab * external_strobe_set 49*8dab9197SMauro Carvalho Chehab defines the source of the flash LED strobe - 50*8dab9197SMauro Carvalho Chehab V4L2_CID_FLASH_STROBE control or external source, typically 51*8dab9197SMauro Carvalho Chehab a sensor, which makes it possible to synchronise the flash 52*8dab9197SMauro Carvalho Chehab strobe start with exposure start, 53*8dab9197SMauro Carvalho Chehab * intensity_to_led_brightness and led_brightness_to_intensity 54*8dab9197SMauro Carvalho Chehab perform 55*8dab9197SMauro Carvalho Chehab enum led_brightness <-> V4L2 intensity conversion in a device 56*8dab9197SMauro Carvalho Chehab specific manner - they can be used for devices with non-linear 57*8dab9197SMauro Carvalho Chehab LED current scale. 58*8dab9197SMauro Carvalho Chehab- config: 59*8dab9197SMauro Carvalho Chehab configuration for V4L2 Flash sub-device 60*8dab9197SMauro Carvalho Chehab 61*8dab9197SMauro Carvalho Chehab * dev_name 62*8dab9197SMauro Carvalho Chehab the name of the media entity, unique in the system, 63*8dab9197SMauro Carvalho Chehab * flash_faults 64*8dab9197SMauro Carvalho Chehab bitmask of flash faults that the LED flash class 65*8dab9197SMauro Carvalho Chehab device can report; corresponding LED_FAULT* bit definitions are 66*8dab9197SMauro Carvalho Chehab available in <linux/led-class-flash.h>, 67*8dab9197SMauro Carvalho Chehab * torch_intensity 68*8dab9197SMauro Carvalho Chehab constraints for the LED in TORCH mode 69*8dab9197SMauro Carvalho Chehab in microamperes, 70*8dab9197SMauro Carvalho Chehab * indicator_intensity 71*8dab9197SMauro Carvalho Chehab constraints for the indicator LED 72*8dab9197SMauro Carvalho Chehab in microamperes, 73*8dab9197SMauro Carvalho Chehab * has_external_strobe 74*8dab9197SMauro Carvalho Chehab determines whether the flash strobe source 75*8dab9197SMauro Carvalho Chehab can be switched to external, 76*8dab9197SMauro Carvalho Chehab 77*8dab9197SMauro Carvalho ChehabOn remove the v4l2_flash_release function has to be called, which takes one 78*8dab9197SMauro Carvalho Chehabargument - struct v4l2_flash pointer returned previously by v4l2_flash_init. 79*8dab9197SMauro Carvalho ChehabThis function can be safely called with NULL or error pointer argument. 80*8dab9197SMauro Carvalho Chehab 81*8dab9197SMauro Carvalho ChehabPlease refer to drivers/leds/leds-max77693.c for an exemplary usage of the 82*8dab9197SMauro Carvalho Chehabv4l2 flash wrapper. 83*8dab9197SMauro Carvalho Chehab 84*8dab9197SMauro Carvalho ChehabOnce the V4L2 sub-device is registered by the driver which created the Media 85*8dab9197SMauro Carvalho Chehabcontroller device, the sub-device node acts just as a node of a native V4L2 86*8dab9197SMauro Carvalho Chehabflash API device would. The calls are simply routed to the LED flash API. 87*8dab9197SMauro Carvalho Chehab 88*8dab9197SMauro Carvalho ChehabOpening the V4L2 flash sub-device makes the LED subsystem sysfs interface 89*8dab9197SMauro Carvalho Chehabunavailable. The interface is re-enabled after the V4L2 flash sub-device 90*8dab9197SMauro Carvalho Chehabis closed. 91