blob: a6353166289d294c416332ffc98faab9e7ee5343 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass59171122015-06-23 15:38:45 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass59171122015-06-23 15:38:45 -06005 */
6
7#ifndef __LED_H
8#define __LED_H
9
Simon Glass401d1c42020-10-30 21:38:53 -060010struct udevice;
11
Simon Glassddae9fc2017-04-10 11:34:54 -060012enum led_state_t {
13 LEDST_OFF = 0,
14 LEDST_ON = 1,
Simon Glass9413ad42017-04-10 11:34:56 -060015 LEDST_TOGGLE,
Simon Glass53378da2017-04-10 11:34:57 -060016#ifdef CONFIG_LED_BLINK
17 LEDST_BLINK,
18#endif
Simon Glassddae9fc2017-04-10 11:34:54 -060019
20 LEDST_COUNT,
21};
22
Marek Vasut72675b02022-04-04 01:23:27 +020023/**
24 * struct led_uc_plat - Platform data the uclass stores about each device
25 *
26 * @label: LED label
27 * @default_state: LED default state
28 */
29struct led_uc_plat {
30 const char *label;
31 enum led_state_t default_state;
32};
33
34/**
35 * struct led_uc_priv - Private data the uclass stores about each device
36 *
37 * @period_ms: Flash period in milliseconds
38 */
39struct led_uc_priv {
40 int period_ms;
41};
42
Simon Glass59171122015-06-23 15:38:45 -060043struct led_ops {
44 /**
Simon Glassddae9fc2017-04-10 11:34:54 -060045 * set_state() - set the state of an LED
Simon Glass59171122015-06-23 15:38:45 -060046 *
47 * @dev: LED device to change
Simon Glassddae9fc2017-04-10 11:34:54 -060048 * @state: LED state to set
Simon Glass59171122015-06-23 15:38:45 -060049 * @return 0 if OK, -ve on error
50 */
Simon Glassddae9fc2017-04-10 11:34:54 -060051 int (*set_state)(struct udevice *dev, enum led_state_t state);
Simon Glass8f4b6122017-04-10 11:34:55 -060052
53 /**
54 * led_get_state() - get the state of an LED
55 *
56 * @dev: LED device to change
57 * @return LED state led_state_t, or -ve on error
58 */
59 enum led_state_t (*get_state)(struct udevice *dev);
Simon Glass53378da2017-04-10 11:34:57 -060060
61#ifdef CONFIG_LED_BLINK
62 /**
63 * led_set_period() - set the blink period of an LED
64 *
65 * Thie records the period if supported, or returns -ENOSYS if not.
66 * To start the LED blinking, use set_state().
67 *
68 * @dev: LED device to change
69 * @period_ms: LED blink period in milliseconds
70 * @return 0 if OK, -ve on error
71 */
72 int (*set_period)(struct udevice *dev, int period_ms);
73#endif
Simon Glass59171122015-06-23 15:38:45 -060074};
75
76#define led_get_ops(dev) ((struct led_ops *)(dev)->driver->ops)
77
78/**
79 * led_get_by_label() - Find an LED device by label
80 *
81 * @label: LED label to look up
82 * @devp: Returns the associated device, if found
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010083 * Return: 0 if found, -ENODEV if not found, other -ve on error
Simon Glass59171122015-06-23 15:38:45 -060084 */
85int led_get_by_label(const char *label, struct udevice **devp);
86
87/**
Simon Glassddae9fc2017-04-10 11:34:54 -060088 * led_set_state() - set the state of an LED
Simon Glass59171122015-06-23 15:38:45 -060089 *
90 * @dev: LED device to change
Simon Glassddae9fc2017-04-10 11:34:54 -060091 * @state: LED state to set
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010092 * Return: 0 if OK, -ve on error
Simon Glass59171122015-06-23 15:38:45 -060093 */
Simon Glassddae9fc2017-04-10 11:34:54 -060094int led_set_state(struct udevice *dev, enum led_state_t state);
Simon Glass59171122015-06-23 15:38:45 -060095
Simon Glass8f4b6122017-04-10 11:34:55 -060096/**
97 * led_get_state() - get the state of an LED
98 *
99 * @dev: LED device to change
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100100 * Return: LED state led_state_t, or -ve on error
Simon Glass8f4b6122017-04-10 11:34:55 -0600101 */
102enum led_state_t led_get_state(struct udevice *dev);
103
Simon Glass53378da2017-04-10 11:34:57 -0600104/**
105 * led_set_period() - set the blink period of an LED
106 *
107 * @dev: LED device to change
108 * @period_ms: LED blink period in milliseconds
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100109 * Return: 0 if OK, -ve on error
Simon Glass53378da2017-04-10 11:34:57 -0600110 */
111int led_set_period(struct udevice *dev, int period_ms);
112
Rasmus Villemoes3bf05152023-11-17 12:38:08 +0100113/**
114 * led_bind_generic() - bind children of parent to given driver
115 *
116 * @parent: Top-level LED device
117 * @driver_name: Driver for handling individual child nodes
118 */
119int led_bind_generic(struct udevice *parent, const char *driver_name);
120
Simon Glass59171122015-06-23 15:38:45 -0600121#endif