Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * LED Flash class interface
4 *
5 * Copyright (C) 2015 Samsung Electronics Co., Ltd.
6 * Author: Jacek Anaszewski <j.anaszewski@samsung.com>
7 */
8#ifndef __LINUX_FLASH_LEDS_H_INCLUDED
9#define __LINUX_FLASH_LEDS_H_INCLUDED
10
11#include <linux/leds.h>
12
13struct device_node;
14struct led_classdev_flash;
15
16/*
17 * Supported led fault bits - must be kept in synch
18 * with V4L2_FLASH_FAULT bits.
19 */
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
30
31#define LED_FLASH_SYSFS_GROUPS_SIZE 5
32
33struct led_flash_ops {
34 /* set flash brightness */
35 int (*flash_brightness_set)(struct led_classdev_flash *fled_cdev,
36 u32 brightness);
37 /* get flash brightness */
38 int (*flash_brightness_get)(struct led_classdev_flash *fled_cdev,
39 u32 *brightness);
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);
48 /* set flash duration */
49 int (*duration_set)(struct led_classdev_flash *fled_cdev, u32 duration);
50};
51
52/*
53 * Current value of a flash setting along
54 * with its constraints.
55 */
56struct led_flash_setting {
57 /* maximum allowed value */
58 u32 min;
59 /* maximum allowed value */
60 u32 max;
61 /* step value */
62 u32 step;
63 /* current value */
64 u32 val;
65};
66
67struct led_classdev_flash {
68 /* led class device */
69 struct led_classdev led_cdev;
70
71 /* flash led specific ops */
72 const struct led_flash_ops *ops;
73
74 /* flash brightness value in microamperes along with its constraints */
75 struct led_flash_setting brightness;
76
77 /* flash timeout value in microseconds along with its constraints */
78 struct led_flash_setting timeout;
79
80 /* flash timeout value in microseconds along with its constraints */
81 struct led_flash_setting duration;
82
83 /* LED Flash class sysfs groups */
84 const struct attribute_group *sysfs_groups[LED_FLASH_SYSFS_GROUPS_SIZE];
85};
86
87static inline struct led_classdev_flash *lcdev_to_flcdev(
88 struct led_classdev *lcdev)
89{
90 return container_of(lcdev, struct led_classdev_flash, led_cdev);
91}
92
93/**
94 * led_classdev_flash_register_ext - register a new object of LED class with
95 * init data and with support for flash LEDs
96 * @parent: LED flash controller device this flash LED is driven by
97 * @fled_cdev: the led_classdev_flash structure for this device
98 * @init_data: the LED class flash device initialization data
99 *
100 * Returns: 0 on success or negative error value on failure
101 */
102int led_classdev_flash_register_ext(struct device *parent,
103 struct led_classdev_flash *fled_cdev,
104 struct led_init_data *init_data);
105
106/**
107 * led_classdev_flash_unregister - unregisters an object of led_classdev class
108 * with support for flash LEDs
109 * @fled_cdev: the flash LED to unregister
110 *
111 * Unregister a previously registered via led_classdev_flash_register object
112 */
113void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev);
114
115int devm_led_classdev_flash_register_ext(struct device *parent,
116 struct led_classdev_flash *fled_cdev,
117 struct led_init_data *init_data);
118
119
120void devm_led_classdev_flash_unregister(struct device *parent,
121 struct led_classdev_flash *fled_cdev);
122
123static inline int led_classdev_flash_register(struct device *parent,
124 struct led_classdev_flash *fled_cdev)
125{
126 return led_classdev_flash_register_ext(parent, fled_cdev, NULL);
127}
128
129static inline int devm_led_classdev_flash_register(struct device *parent,
130 struct led_classdev_flash *fled_cdev)
131{
132 return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL);
133}
134
135/**
136 * led_set_flash_strobe - setup flash strobe
137 * @fled_cdev: the flash LED to set strobe on
138 * @state: 1 - strobe flash, 0 - stop flash strobe
139 *
140 * Strobe the flash LED.
141 *
142 * Returns: 0 on success or negative error value on failure
143 */
144static inline int led_set_flash_strobe(struct led_classdev_flash *fled_cdev,
145 bool state)
146{
147 if (!fled_cdev)
148 return -EINVAL;
149 return fled_cdev->ops->strobe_set(fled_cdev, state);
150}
151
152/**
153 * led_get_flash_strobe - get flash strobe status
154 * @fled_cdev: the flash LED to query
155 * @state: 1 - flash is strobing, 0 - flash is off
156 *
157 * Check whether the flash is strobing at the moment.
158 *
159 * Returns: 0 on success or negative error value on failure
160 */
161static inline int led_get_flash_strobe(struct led_classdev_flash *fled_cdev,
162 bool *state)
163{
164 if (!fled_cdev)
165 return -EINVAL;
166 if (fled_cdev->ops->strobe_get)
167 return fled_cdev->ops->strobe_get(fled_cdev, state);
168
169 return -EINVAL;
170}
171
172/**
173 * led_set_flash_brightness - set flash LED brightness
174 * @fled_cdev: the flash LED to set
175 * @brightness: the brightness to set it to
176 *
177 * Set a flash LED's brightness.
178 *
179 * Returns: 0 on success or negative error value on failure
180 */
181int led_set_flash_brightness(struct led_classdev_flash *fled_cdev,
182 u32 brightness);
183
184/**
185 * led_update_flash_brightness - update flash LED brightness
186 * @fled_cdev: the flash LED to query
187 *
188 * Get a flash LED's current brightness and update led_flash->brightness
189 * member with the obtained value.
190 *
191 * Returns: 0 on success or negative error value on failure
192 */
193int led_update_flash_brightness(struct led_classdev_flash *fled_cdev);
194
195/**
196 * led_set_flash_timeout - set flash LED timeout
197 * @fled_cdev: the flash LED to set
198 * @timeout: the flash timeout to set it to
199 *
200 * Set the flash strobe timeout.
201 *
202 * Returns: 0 on success or negative error value on failure
203 */
204int led_set_flash_timeout(struct led_classdev_flash *fled_cdev, u32 timeout);
205
206/**
207 * led_get_flash_fault - get the flash LED fault
208 * @fled_cdev: the flash LED to query
209 * @fault: bitmask containing flash faults
210 *
211 * Get the flash LED fault.
212 *
213 * Returns: 0 on success or negative error value on failure
214 */
215int led_get_flash_fault(struct led_classdev_flash *fled_cdev, u32 *fault);
216
217/**
218 * led_set_flash_duration - set flash LED duration
219 * @fled_cdev: the flash LED to set
220 * @timeout: the flash duration to set it to
221 *
222 * Set the flash strobe duration.
223 *
224 * Returns: 0 on success or negative error value on failure
225 */
226int led_set_flash_duration(struct led_classdev_flash *fled_cdev, u32 duration);
227
228#endif /* __LINUX_FLASH_LEDS_H_INCLUDED */