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