]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
5917112c SG |
2 | /* |
3 | * Copyright (c) 2015 Google, Inc | |
4 | * Written by Simon Glass <[email protected]> | |
5917112c SG |
5 | */ |
6 | ||
7 | #ifndef __LED_H | |
8 | #define __LED_H | |
9 | ||
401d1c4f SG |
10 | struct udevice; |
11 | ||
5917112c | 12 | /** |
56e19871 | 13 | * struct led_uc_plat - Platform data the uclass stores about each device |
5917112c SG |
14 | * |
15 | * @label: LED label | |
16 | */ | |
56e19871 | 17 | struct led_uc_plat { |
5917112c SG |
18 | const char *label; |
19 | }; | |
20 | ||
53378dac SG |
21 | /** |
22 | * struct led_uc_priv - Private data the uclass stores about each device | |
23 | * | |
24 | * @period_ms: Flash period in milliseconds | |
25 | */ | |
26 | struct led_uc_priv { | |
27 | int period_ms; | |
28 | }; | |
29 | ||
ddae9fcd SG |
30 | enum led_state_t { |
31 | LEDST_OFF = 0, | |
32 | LEDST_ON = 1, | |
9413ad4f | 33 | LEDST_TOGGLE, |
53378dac SG |
34 | #ifdef CONFIG_LED_BLINK |
35 | LEDST_BLINK, | |
36 | #endif | |
ddae9fcd SG |
37 | |
38 | LEDST_COUNT, | |
39 | }; | |
40 | ||
5917112c SG |
41 | struct led_ops { |
42 | /** | |
ddae9fcd | 43 | * set_state() - set the state of an LED |
5917112c SG |
44 | * |
45 | * @dev: LED device to change | |
ddae9fcd | 46 | * @state: LED state to set |
5917112c SG |
47 | * @return 0 if OK, -ve on error |
48 | */ | |
ddae9fcd | 49 | int (*set_state)(struct udevice *dev, enum led_state_t state); |
8f4b6123 SG |
50 | |
51 | /** | |
52 | * led_get_state() - get the state of an LED | |
53 | * | |
54 | * @dev: LED device to change | |
55 | * @return LED state led_state_t, or -ve on error | |
56 | */ | |
57 | enum led_state_t (*get_state)(struct udevice *dev); | |
53378dac SG |
58 | |
59 | #ifdef CONFIG_LED_BLINK | |
60 | /** | |
61 | * led_set_period() - set the blink period of an LED | |
62 | * | |
63 | * Thie records the period if supported, or returns -ENOSYS if not. | |
64 | * To start the LED blinking, use set_state(). | |
65 | * | |
66 | * @dev: LED device to change | |
67 | * @period_ms: LED blink period in milliseconds | |
68 | * @return 0 if OK, -ve on error | |
69 | */ | |
70 | int (*set_period)(struct udevice *dev, int period_ms); | |
71 | #endif | |
5917112c SG |
72 | }; |
73 | ||
74 | #define led_get_ops(dev) ((struct led_ops *)(dev)->driver->ops) | |
75 | ||
76 | /** | |
77 | * led_get_by_label() - Find an LED device by label | |
78 | * | |
79 | * @label: LED label to look up | |
80 | * @devp: Returns the associated device, if found | |
fb8a5ffc | 81 | * @return 0 if found, -ENODEV if not found, other -ve on error |
5917112c SG |
82 | */ |
83 | int led_get_by_label(const char *label, struct udevice **devp); | |
84 | ||
85 | /** | |
ddae9fcd | 86 | * led_set_state() - set the state of an LED |
5917112c SG |
87 | * |
88 | * @dev: LED device to change | |
ddae9fcd | 89 | * @state: LED state to set |
5917112c SG |
90 | * @return 0 if OK, -ve on error |
91 | */ | |
ddae9fcd | 92 | int led_set_state(struct udevice *dev, enum led_state_t state); |
5917112c | 93 | |
8f4b6123 SG |
94 | /** |
95 | * led_get_state() - get the state of an LED | |
96 | * | |
97 | * @dev: LED device to change | |
98 | * @return LED state led_state_t, or -ve on error | |
99 | */ | |
100 | enum led_state_t led_get_state(struct udevice *dev); | |
101 | ||
53378dac SG |
102 | /** |
103 | * led_set_period() - set the blink period of an LED | |
104 | * | |
105 | * @dev: LED device to change | |
106 | * @period_ms: LED blink period in milliseconds | |
107 | * @return 0 if OK, -ve on error | |
108 | */ | |
109 | int led_set_period(struct udevice *dev, int period_ms); | |
110 | ||
d7a435a2 PD |
111 | /** |
112 | * led_default_state() - set the default state for all the LED | |
113 | * | |
114 | * This enables all leds which have default state. | |
115 | * see Documentation/devicetree/bindings/leds/common.txt | |
116 | * | |
117 | */ | |
118 | int led_default_state(void); | |
119 | ||
5917112c | 120 | #endif |