Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __LED_H |
| 8 | #define __LED_H |
| 9 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | struct udevice; |
| 11 | |
Marek Vasut | 03cadb6 | 2022-04-04 01:23:27 +0200 | [diff] [blame] | 12 | enum 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 Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 23 | /** |
Simon Glass | da01de9 | 2017-04-10 11:34:53 -0600 | [diff] [blame] | 24 | * struct led_uc_plat - Platform data the uclass stores about each device |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 25 | * |
| 26 | * @label: LED label |
Marek Vasut | 03cadb6 | 2022-04-04 01:23:27 +0200 | [diff] [blame] | 27 | * @default_state: LED default state |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 28 | */ |
Simon Glass | da01de9 | 2017-04-10 11:34:53 -0600 | [diff] [blame] | 29 | struct led_uc_plat { |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 30 | const char *label; |
Marek Vasut | 03cadb6 | 2022-04-04 01:23:27 +0200 | [diff] [blame] | 31 | enum led_state_t default_state; |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 32 | }; |
| 33 | |
Simon Glass | 3bd0c46 | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 34 | /** |
| 35 | * struct led_uc_priv - Private data the uclass stores about each device |
| 36 | * |
| 37 | * @period_ms: Flash period in milliseconds |
| 38 | */ |
| 39 | struct led_uc_priv { |
| 40 | int period_ms; |
| 41 | }; |
| 42 | |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 43 | struct led_ops { |
| 44 | /** |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 45 | * set_state() - set the state of an LED |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 46 | * |
| 47 | * @dev: LED device to change |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 48 | * @state: LED state to set |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 49 | * @return 0 if OK, -ve on error |
| 50 | */ |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 51 | int (*set_state)(struct udevice *dev, enum led_state_t state); |
Simon Glass | dc53166 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 52 | |
| 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 Glass | 3bd0c46 | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 60 | |
| 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 Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 74 | }; |
| 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 Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 83 | * Return: 0 if found, -ENODEV if not found, other -ve on error |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 84 | */ |
| 85 | int led_get_by_label(const char *label, struct udevice **devp); |
| 86 | |
| 87 | /** |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 88 | * led_set_state() - set the state of an LED |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 89 | * |
| 90 | * @dev: LED device to change |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 91 | * @state: LED state to set |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 92 | * Return: 0 if OK, -ve on error |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 93 | */ |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 94 | int led_set_state(struct udevice *dev, enum led_state_t state); |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 95 | |
Simon Glass | dc53166 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 96 | /** |
| 97 | * led_get_state() - get the state of an LED |
| 98 | * |
| 99 | * @dev: LED device to change |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 100 | * Return: LED state led_state_t, or -ve on error |
Simon Glass | dc53166 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 101 | */ |
| 102 | enum led_state_t led_get_state(struct udevice *dev); |
| 103 | |
Simon Glass | 3bd0c46 | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 104 | /** |
| 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 Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 109 | * Return: 0 if OK, -ve on error |
Simon Glass | 3bd0c46 | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 110 | */ |
| 111 | int led_set_period(struct udevice *dev, int period_ms); |
| 112 | |
Rasmus Villemoes | 49ba9f0 | 2023-11-17 12:38:08 +0100 | [diff] [blame] | 113 | /** |
| 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 | */ |
| 119 | int led_bind_generic(struct udevice *parent, const char *driver_name); |
| 120 | |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 121 | #endif |