xref: /openbmc/u-boot/include/led.h (revision 10e40d54)
1 /*
2  * Copyright (c) 2015 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #ifndef __LED_H
9 #define __LED_H
10 
11 /**
12  * struct led_uc_plat - Platform data the uclass stores about each device
13  *
14  * @label:	LED label
15  */
16 struct led_uc_plat {
17 	const char *label;
18 };
19 
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 
29 enum led_state_t {
30 	LEDST_OFF = 0,
31 	LEDST_ON = 1,
32 	LEDST_TOGGLE,
33 #ifdef CONFIG_LED_BLINK
34 	LEDST_BLINK,
35 #endif
36 
37 	LEDST_COUNT,
38 };
39 
40 struct led_ops {
41 	/**
42 	 * set_state() - set the state of an LED
43 	 *
44 	 * @dev:	LED device to change
45 	 * @state:	LED state to set
46 	 * @return 0 if OK, -ve on error
47 	 */
48 	int (*set_state)(struct udevice *dev, enum led_state_t state);
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);
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
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
80  * @return 0 if found, -ENODEV if not found, other -ve on error
81  */
82 int led_get_by_label(const char *label, struct udevice **devp);
83 
84 /**
85  * led_set_state() - set the state of an LED
86  *
87  * @dev:	LED device to change
88  * @state:	LED state to set
89  * @return 0 if OK, -ve on error
90  */
91 int led_set_state(struct udevice *dev, enum led_state_t state);
92 
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 
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 
110 #endif
111