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 | |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 12 | /** |
Simon Glass | da01de9 | 2017-04-10 11:34:53 -0600 | [diff] [blame] | 13 | * struct led_uc_plat - Platform data the uclass stores about each device |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 14 | * |
| 15 | * @label: LED label |
| 16 | */ |
Simon Glass | da01de9 | 2017-04-10 11:34:53 -0600 | [diff] [blame] | 17 | struct led_uc_plat { |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 18 | const char *label; |
| 19 | }; |
| 20 | |
Simon Glass | 3bd0c46 | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 21 | /** |
| 22 | * struct led_uc_priv - Private data the uclass stores about each device |
| 23 | * |
| 24 | * @period_ms: Flash period in milliseconds |
| 25 | */ |
| 26 | struct led_uc_priv { |
| 27 | int period_ms; |
| 28 | }; |
| 29 | |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 30 | enum led_state_t { |
| 31 | LEDST_OFF = 0, |
| 32 | LEDST_ON = 1, |
Simon Glass | e445dfd | 2017-04-10 11:34:56 -0600 | [diff] [blame] | 33 | LEDST_TOGGLE, |
Simon Glass | 3bd0c46 | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 34 | #ifdef CONFIG_LED_BLINK |
| 35 | LEDST_BLINK, |
| 36 | #endif |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 37 | |
| 38 | LEDST_COUNT, |
| 39 | }; |
| 40 | |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 41 | struct led_ops { |
| 42 | /** |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 43 | * set_state() - set the state of an LED |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 44 | * |
| 45 | * @dev: LED device to change |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 46 | * @state: LED state to set |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 47 | * @return 0 if OK, -ve on error |
| 48 | */ |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 49 | int (*set_state)(struct udevice *dev, enum led_state_t state); |
Simon Glass | dc53166 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 50 | |
| 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 Glass | 3bd0c46 | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 58 | |
| 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 Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 72 | }; |
| 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 |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 81 | * Return: 0 if found, -ENODEV if not found, other -ve on error |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 82 | */ |
| 83 | int led_get_by_label(const char *label, struct udevice **devp); |
| 84 | |
| 85 | /** |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 86 | * led_set_state() - set the state of an LED |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 87 | * |
| 88 | * @dev: LED device to change |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 89 | * @state: LED state to set |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 90 | * Return: 0 if OK, -ve on error |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 91 | */ |
Simon Glass | 6ca1977 | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 92 | int led_set_state(struct udevice *dev, enum led_state_t state); |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 93 | |
Simon Glass | dc53166 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 94 | /** |
| 95 | * led_get_state() - get the state of an LED |
| 96 | * |
| 97 | * @dev: LED device to change |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 98 | * Return: LED state led_state_t, or -ve on error |
Simon Glass | dc53166 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 99 | */ |
| 100 | enum led_state_t led_get_state(struct udevice *dev); |
| 101 | |
Simon Glass | 3bd0c46 | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 102 | /** |
| 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 |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 107 | * Return: 0 if OK, -ve on error |
Simon Glass | 3bd0c46 | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 108 | */ |
| 109 | int led_set_period(struct udevice *dev, int period_ms); |
| 110 | |
Patrick Delaunay | a5bf928 | 2018-07-27 16:37:07 +0200 | [diff] [blame] | 111 | /** |
| 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 | */ |
| 118 | int led_default_state(void); |
| 119 | |
Simon Glass | cce3aed | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 120 | #endif |