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