blob: 02766fa56fb62ffe2f77e99c8afc0b1076b503ff [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glasscce3aed2015-06-23 15:38:45 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glasscce3aed2015-06-23 15:38:45 -06005 */
6
7#ifndef __LED_H
8#define __LED_H
9
Simon Glass3ba929a2020-10-30 21:38:53 -060010struct udevice;
11
Simon Glasscce3aed2015-06-23 15:38:45 -060012/**
Simon Glassda01de92017-04-10 11:34:53 -060013 * struct led_uc_plat - Platform data the uclass stores about each device
Simon Glasscce3aed2015-06-23 15:38:45 -060014 *
15 * @label: LED label
16 */
Simon Glassda01de92017-04-10 11:34:53 -060017struct led_uc_plat {
Simon Glasscce3aed2015-06-23 15:38:45 -060018 const char *label;
19};
20
Simon Glass3bd0c462017-04-10 11:34:57 -060021/**
22 * struct led_uc_priv - Private data the uclass stores about each device
23 *
24 * @period_ms: Flash period in milliseconds
25 */
26struct led_uc_priv {
27 int period_ms;
28};
29
Simon Glass6ca19772017-04-10 11:34:54 -060030enum led_state_t {
31 LEDST_OFF = 0,
32 LEDST_ON = 1,
Simon Glasse445dfd2017-04-10 11:34:56 -060033 LEDST_TOGGLE,
Simon Glass3bd0c462017-04-10 11:34:57 -060034#ifdef CONFIG_LED_BLINK
35 LEDST_BLINK,
36#endif
Simon Glass6ca19772017-04-10 11:34:54 -060037
38 LEDST_COUNT,
39};
40
Simon Glasscce3aed2015-06-23 15:38:45 -060041struct led_ops {
42 /**
Simon Glass6ca19772017-04-10 11:34:54 -060043 * set_state() - set the state of an LED
Simon Glasscce3aed2015-06-23 15:38:45 -060044 *
45 * @dev: LED device to change
Simon Glass6ca19772017-04-10 11:34:54 -060046 * @state: LED state to set
Simon Glasscce3aed2015-06-23 15:38:45 -060047 * @return 0 if OK, -ve on error
48 */
Simon Glass6ca19772017-04-10 11:34:54 -060049 int (*set_state)(struct udevice *dev, enum led_state_t state);
Simon Glassdc531662017-04-10 11:34:55 -060050
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);
Simon Glass3bd0c462017-04-10 11:34:57 -060058
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
Simon Glasscce3aed2015-06-23 15:38:45 -060072};
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
Simon Glassbf3ac8192015-07-06 12:54:33 -060081 * @return 0 if found, -ENODEV if not found, other -ve on error
Simon Glasscce3aed2015-06-23 15:38:45 -060082 */
83int led_get_by_label(const char *label, struct udevice **devp);
84
85/**
Simon Glass6ca19772017-04-10 11:34:54 -060086 * led_set_state() - set the state of an LED
Simon Glasscce3aed2015-06-23 15:38:45 -060087 *
88 * @dev: LED device to change
Simon Glass6ca19772017-04-10 11:34:54 -060089 * @state: LED state to set
Simon Glasscce3aed2015-06-23 15:38:45 -060090 * @return 0 if OK, -ve on error
91 */
Simon Glass6ca19772017-04-10 11:34:54 -060092int led_set_state(struct udevice *dev, enum led_state_t state);
Simon Glasscce3aed2015-06-23 15:38:45 -060093
Simon Glassdc531662017-04-10 11:34:55 -060094/**
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 */
100enum led_state_t led_get_state(struct udevice *dev);
101
Simon Glass3bd0c462017-04-10 11:34:57 -0600102/**
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 */
109int led_set_period(struct udevice *dev, int period_ms);
110
Patrick Delaunaya5bf9282018-07-27 16:37:07 +0200111/**
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 */
118int led_default_state(void);
119
Simon Glasscce3aed2015-06-23 15:38:45 -0600120#endif