1
2
3
4
5
6
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
18
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
35 int (*flash_brightness_set)(struct led_classdev_flash *fled_cdev,
36 u32 brightness);
37
38 int (*flash_brightness_get)(struct led_classdev_flash *fled_cdev,
39 u32 *brightness);
40
41 int (*strobe_set)(struct led_classdev_flash *fled_cdev, bool state);
42
43 int (*strobe_get)(struct led_classdev_flash *fled_cdev, bool *state);
44
45 int (*timeout_set)(struct led_classdev_flash *fled_cdev, u32 timeout);
46
47 int (*fault_get)(struct led_classdev_flash *fled_cdev, u32 *fault);
48};
49
50
51
52
53
54struct led_flash_setting {
55
56 u32 min;
57
58 u32 max;
59
60 u32 step;
61
62 u32 val;
63};
64
65struct led_classdev_flash {
66
67 struct led_classdev led_cdev;
68
69
70 const struct led_flash_ops *ops;
71
72
73 struct led_flash_setting brightness;
74
75
76 struct led_flash_setting timeout;
77
78
79 const struct attribute_group *sysfs_groups[LED_FLASH_SYSFS_GROUPS_SIZE];
80};
81
82static inline struct led_classdev_flash *lcdev_to_flcdev(
83 struct led_classdev *lcdev)
84{
85 return container_of(lcdev, struct led_classdev_flash, led_cdev);
86}
87
88#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH)
89
90
91
92
93
94
95
96
97
98int led_classdev_flash_register_ext(struct device *parent,
99 struct led_classdev_flash *fled_cdev,
100 struct led_init_data *init_data);
101
102
103
104
105
106
107
108
109void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev);
110
111int devm_led_classdev_flash_register_ext(struct device *parent,
112 struct led_classdev_flash *fled_cdev,
113 struct led_init_data *init_data);
114
115
116void devm_led_classdev_flash_unregister(struct device *parent,
117 struct led_classdev_flash *fled_cdev);
118
119#else
120
121static inline int led_classdev_flash_register_ext(struct device *parent,
122 struct led_classdev_flash *fled_cdev,
123 struct led_init_data *init_data)
124{
125 return 0;
126}
127
128static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {};
129static inline int devm_led_classdev_flash_register_ext(struct device *parent,
130 struct led_classdev_flash *fled_cdev,
131 struct led_init_data *init_data)
132{
133 return 0;
134}
135
136static inline void devm_led_classdev_flash_unregister(struct device *parent,
137 struct led_classdev_flash *fled_cdev)
138{};
139
140#endif
141
142static inline int led_classdev_flash_register(struct device *parent,
143 struct led_classdev_flash *fled_cdev)
144{
145 return led_classdev_flash_register_ext(parent, fled_cdev, NULL);
146}
147
148static inline int devm_led_classdev_flash_register(struct device *parent,
149 struct led_classdev_flash *fled_cdev)
150{
151 return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL);
152}
153
154
155
156
157
158
159
160
161
162
163static inline int led_set_flash_strobe(struct led_classdev_flash *fled_cdev,
164 bool state)
165{
166 if (!fled_cdev)
167 return -EINVAL;
168 return fled_cdev->ops->strobe_set(fled_cdev, state);
169}
170
171
172
173
174
175
176
177
178
179
180static inline int led_get_flash_strobe(struct led_classdev_flash *fled_cdev,
181 bool *state)
182{
183 if (!fled_cdev)
184 return -EINVAL;
185 if (fled_cdev->ops->strobe_get)
186 return fled_cdev->ops->strobe_get(fled_cdev, state);
187
188 return -EINVAL;
189}
190
191
192
193
194
195
196
197
198
199
200int led_set_flash_brightness(struct led_classdev_flash *fled_cdev,
201 u32 brightness);
202
203
204
205
206
207
208
209
210
211
212int led_update_flash_brightness(struct led_classdev_flash *fled_cdev);
213
214
215
216
217
218
219
220
221
222
223int led_set_flash_timeout(struct led_classdev_flash *fled_cdev, u32 timeout);
224
225
226
227
228
229
230
231
232
233
234int led_get_flash_fault(struct led_classdev_flash *fled_cdev, u32 *fault);
235
236#endif
237