Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 5917112 | 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 | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __LED_H |
| 8 | #define __LED_H |
| 9 | |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | struct udevice; |
| 11 | |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 12 | enum led_state_t { |
| 13 | LEDST_OFF = 0, |
| 14 | LEDST_ON = 1, |
Simon Glass | 9413ad4 | 2017-04-10 11:34:56 -0600 | [diff] [blame] | 15 | LEDST_TOGGLE, |
Simon Glass | 53378da | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 16 | #ifdef CONFIG_LED_BLINK |
| 17 | LEDST_BLINK, |
| 18 | #endif |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 19 | |
| 20 | LEDST_COUNT, |
| 21 | }; |
| 22 | |
Marek Vasut | 72675b0 | 2022-04-04 01:23:27 +0200 | [diff] [blame] | 23 | /** |
| 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 | */ |
| 29 | struct 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 | */ |
| 39 | struct led_uc_priv { |
| 40 | int period_ms; |
| 41 | }; |
| 42 | |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 43 | struct led_ops { |
| 44 | /** |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 45 | * set_state() - set the state of an LED |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 46 | * |
| 47 | * @dev: LED device to change |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 48 | * @state: LED state to set |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 49 | * @return 0 if OK, -ve on error |
| 50 | */ |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 51 | int (*set_state)(struct udevice *dev, enum led_state_t state); |
Simon Glass | 8f4b612 | 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 | 53378da | 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 | 5917112 | 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 | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 83 | * Return: 0 if found, -ENODEV if not found, other -ve on error |
Simon Glass | 5917112 | 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 | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 88 | * led_set_state() - set the state of an LED |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 89 | * |
| 90 | * @dev: LED device to change |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 91 | * @state: LED state to set |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 92 | * Return: 0 if OK, -ve on error |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 93 | */ |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 94 | int led_set_state(struct udevice *dev, enum led_state_t state); |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 95 | |
Simon Glass | 8f4b612 | 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 | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 100 | * Return: LED state led_state_t, or -ve on error |
Simon Glass | 8f4b612 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 101 | */ |
| 102 | enum led_state_t led_get_state(struct udevice *dev); |
| 103 | |
Simon Glass | 53378da | 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 | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 109 | * Return: 0 if OK, -ve on error |
Simon Glass | 53378da | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 110 | */ |
| 111 | int led_set_period(struct udevice *dev, int period_ms); |
| 112 | |
Rasmus Villemoes | 3bf0515 | 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 | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 121 | #endif |