1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * LED Flash class interface
5 * Copyright (C) 2015 Samsung Electronics Co., Ltd.
8 #ifndef __LINUX_FLASH_LEDS_H_INCLUDED
9 #define __LINUX_FLASH_LEDS_H_INCLUDED
11 #include <linux/leds.h>
14 struct led_classdev_flash;
17 * Supported led fault bits - must be kept in synch
18 * with V4L2_FLASH_FAULT bits.
20 #define LED_FAULT_OVER_VOLTAGE (1 << 0)
21 #define LED_FAULT_TIMEOUT (1 << 1)
22 #define LED_FAULT_OVER_TEMPERATURE (1 << 2)
23 #define LED_FAULT_SHORT_CIRCUIT (1 << 3)
24 #define LED_FAULT_OVER_CURRENT (1 << 4)
25 #define LED_FAULT_INDICATOR (1 << 5)
26 #define LED_FAULT_UNDER_VOLTAGE (1 << 6)
27 #define LED_FAULT_INPUT_VOLTAGE (1 << 7)
28 #define LED_FAULT_LED_OVER_TEMPERATURE (1 << 8)
29 #define LED_NUM_FLASH_FAULTS 9
31 #define LED_FLASH_SYSFS_GROUPS_SIZE 5
33 struct led_flash_ops {
34 /* set flash brightness */
35 int (*flash_brightness_set)(struct led_classdev_flash *fled_cdev,
37 /* get flash brightness */
38 int (*flash_brightness_get)(struct led_classdev_flash *fled_cdev,
40 /* set flash strobe state */
41 int (*strobe_set)(struct led_classdev_flash *fled_cdev, bool state);
42 /* get flash strobe state */
43 int (*strobe_get)(struct led_classdev_flash *fled_cdev, bool *state);
44 /* set flash timeout */
45 int (*timeout_set)(struct led_classdev_flash *fled_cdev, u32 timeout);
46 /* get the flash LED fault */
47 int (*fault_get)(struct led_classdev_flash *fled_cdev, u32 *fault);
51 * Current value of a flash setting along
52 * with its constraints.
54 struct led_flash_setting {
55 /* maximum allowed value */
57 /* maximum allowed value */
65 struct led_classdev_flash {
66 /* led class device */
67 struct led_classdev led_cdev;
69 /* flash led specific ops */
70 const struct led_flash_ops *ops;
72 /* flash brightness value in microamperes along with its constraints */
73 struct led_flash_setting brightness;
75 /* flash timeout value in microseconds along with its constraints */
76 struct led_flash_setting timeout;
78 /* LED Flash class sysfs groups */
79 const struct attribute_group *sysfs_groups[LED_FLASH_SYSFS_GROUPS_SIZE];
82 static inline struct led_classdev_flash *lcdev_to_flcdev(
83 struct led_classdev *lcdev)
85 return container_of(lcdev, struct led_classdev_flash, led_cdev);
89 * led_classdev_flash_register - register a new object of led_classdev class
90 * with support for flash LEDs
91 * @parent: the flash LED to register
92 * @fled_cdev: the led_classdev_flash structure for this device
94 * Returns: 0 on success or negative error value on failure
96 extern int led_classdev_flash_register(struct device *parent,
97 struct led_classdev_flash *fled_cdev);
100 * led_classdev_flash_unregister - unregisters an object of led_classdev class
101 * with support for flash LEDs
102 * @fled_cdev: the flash LED to unregister
104 * Unregister a previously registered via led_classdev_flash_register object
106 extern void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev);
109 * led_set_flash_strobe - setup flash strobe
110 * @fled_cdev: the flash LED to set strobe on
111 * @state: 1 - strobe flash, 0 - stop flash strobe
113 * Strobe the flash LED.
115 * Returns: 0 on success or negative error value on failure
117 static inline int led_set_flash_strobe(struct led_classdev_flash *fled_cdev,
122 return fled_cdev->ops->strobe_set(fled_cdev, state);
126 * led_get_flash_strobe - get flash strobe status
127 * @fled_cdev: the flash LED to query
128 * @state: 1 - flash is strobing, 0 - flash is off
130 * Check whether the flash is strobing at the moment.
132 * Returns: 0 on success or negative error value on failure
134 static inline int led_get_flash_strobe(struct led_classdev_flash *fled_cdev,
139 if (fled_cdev->ops->strobe_get)
140 return fled_cdev->ops->strobe_get(fled_cdev, state);
146 * led_set_flash_brightness - set flash LED brightness
147 * @fled_cdev: the flash LED to set
148 * @brightness: the brightness to set it to
150 * Set a flash LED's brightness.
152 * Returns: 0 on success or negative error value on failure
154 extern int led_set_flash_brightness(struct led_classdev_flash *fled_cdev,
158 * led_update_flash_brightness - update flash LED brightness
159 * @fled_cdev: the flash LED to query
161 * Get a flash LED's current brightness and update led_flash->brightness
162 * member with the obtained value.
164 * Returns: 0 on success or negative error value on failure
166 extern int led_update_flash_brightness(struct led_classdev_flash *fled_cdev);
169 * led_set_flash_timeout - set flash LED timeout
170 * @fled_cdev: the flash LED to set
171 * @timeout: the flash timeout to set it to
173 * Set the flash strobe duration.
175 * Returns: 0 on success or negative error value on failure
177 extern int led_set_flash_timeout(struct led_classdev_flash *fled_cdev,
181 * led_get_flash_fault - get the flash LED fault
182 * @fled_cdev: the flash LED to query
183 * @fault: bitmask containing flash faults
185 * Get the flash LED fault.
187 * Returns: 0 on success or negative error value on failure
189 extern int led_get_flash_fault(struct led_classdev_flash *fled_cdev,
192 #endif /* __LINUX_FLASH_LEDS_H_INCLUDED */