blob: a6353166289d294c416332ffc98faab9e7ee5343 [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
Marek Vasut03cadb62022-04-04 01:23:27 +020012enum led_state_t {
13 LEDST_OFF = 0,
14 LEDST_ON = 1,
15 LEDST_TOGGLE,
16#ifdef CONFIG_LED_BLINK
17 LEDST_BLINK,
18#endif
19
20 LEDST_COUNT,
21};
22
Simon Glasscce3aed2015-06-23 15:38:45 -060023/**
Simon Glassda01de92017-04-10 11:34:53 -060024 * struct led_uc_plat - Platform data the uclass stores about each device
Simon Glasscce3aed2015-06-23 15:38:45 -060025 *
26 * @label: LED label
Marek Vasut03cadb62022-04-04 01:23:27 +020027 * @default_state: LED default state
Simon Glasscce3aed2015-06-23 15:38:45 -060028 */
Simon Glassda01de92017-04-10 11:34:53 -060029struct led_uc_plat {
Simon Glasscce3aed2015-06-23 15:38:45 -060030 const char *label;
Marek Vasut03cadb62022-04-04 01:23:27 +020031 enum led_state_t default_state;
Simon Glasscce3aed2015-06-23 15:38:45 -060032};
33
Simon Glass3bd0c462017-04-10 11:34:57 -060034/**
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 Glasscce3aed2015-06-23 15:38:45 -060043struct led_ops {
44 /**
Simon Glass6ca19772017-04-10 11:34:54 -060045 * set_state() - set the state of an LED
Simon Glasscce3aed2015-06-23 15:38:45 -060046 *
47 * @dev: LED device to change
Simon Glass6ca19772017-04-10 11:34:54 -060048 * @state: LED state to set
Simon Glasscce3aed2015-06-23 15:38:45 -060049 * @return 0 if OK, -ve on error
50 */
Simon Glass6ca19772017-04-10 11:34:54 -060051 int (*set_state)(struct udevice *dev, enum led_state_t state);
Simon Glassdc531662017-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 Glass3bd0c462017-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 Glasscce3aed2015-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 Schuchardt47b4c022022-01-19 18:05:50 +010083 * Return: 0 if found, -ENODEV if not found, other -ve on error
Simon Glasscce3aed2015-06-23 15:38:45 -060084 */
85int led_get_by_label(const char *label, struct udevice **devp);
86
87/**
Simon Glass6ca19772017-04-10 11:34:54 -060088 * led_set_state() - set the state of an LED
Simon Glasscce3aed2015-06-23 15:38:45 -060089 *
90 * @dev: LED device to change
Simon Glass6ca19772017-04-10 11:34:54 -060091 * @state: LED state to set
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010092 * Return: 0 if OK, -ve on error
Simon Glasscce3aed2015-06-23 15:38:45 -060093 */
Simon Glass6ca19772017-04-10 11:34:54 -060094int led_set_state(struct udevice *dev, enum led_state_t state);
Simon Glasscce3aed2015-06-23 15:38:45 -060095
Simon Glassdc531662017-04-10 11:34:55 -060096/**
97 * led_get_state() - get the state of an LED
98 *
99 * @dev: LED device to change
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100100 * Return: LED state led_state_t, or -ve on error
Simon Glassdc531662017-04-10 11:34:55 -0600101 */
102enum led_state_t led_get_state(struct udevice *dev);
103
Simon Glass3bd0c462017-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 Schuchardt47b4c022022-01-19 18:05:50 +0100109 * Return: 0 if OK, -ve on error
Simon Glass3bd0c462017-04-10 11:34:57 -0600110 */
111int led_set_period(struct udevice *dev, int period_ms);
112
Rasmus Villemoes49ba9f02023-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 Glasscce3aed2015-06-23 15:38:45 -0600121#endif