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 | |
| 10 | /** |
Simon Glass | 56e1987 | 2017-04-10 11:34:53 -0600 | [diff] [blame] | 11 | * struct led_uc_plat - Platform data the uclass stores about each device |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 12 | * |
| 13 | * @label: LED label |
| 14 | */ |
Simon Glass | 56e1987 | 2017-04-10 11:34:53 -0600 | [diff] [blame] | 15 | struct led_uc_plat { |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 16 | const char *label; |
| 17 | }; |
| 18 | |
Simon Glass | 53378da | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 19 | /** |
| 20 | * struct led_uc_priv - Private data the uclass stores about each device |
| 21 | * |
| 22 | * @period_ms: Flash period in milliseconds |
| 23 | */ |
| 24 | struct led_uc_priv { |
| 25 | int period_ms; |
| 26 | }; |
| 27 | |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 28 | enum led_state_t { |
| 29 | LEDST_OFF = 0, |
| 30 | LEDST_ON = 1, |
Simon Glass | 9413ad4 | 2017-04-10 11:34:56 -0600 | [diff] [blame] | 31 | LEDST_TOGGLE, |
Simon Glass | 53378da | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 32 | #ifdef CONFIG_LED_BLINK |
| 33 | LEDST_BLINK, |
| 34 | #endif |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 35 | |
| 36 | LEDST_COUNT, |
| 37 | }; |
| 38 | |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 39 | struct led_ops { |
| 40 | /** |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 41 | * set_state() - set the state of an LED |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 42 | * |
| 43 | * @dev: LED device to change |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 44 | * @state: LED state to set |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 45 | * @return 0 if OK, -ve on error |
| 46 | */ |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 47 | int (*set_state)(struct udevice *dev, enum led_state_t state); |
Simon Glass | 8f4b612 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * led_get_state() - get the state of an LED |
| 51 | * |
| 52 | * @dev: LED device to change |
| 53 | * @return LED state led_state_t, or -ve on error |
| 54 | */ |
| 55 | enum led_state_t (*get_state)(struct udevice *dev); |
Simon Glass | 53378da | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 56 | |
| 57 | #ifdef CONFIG_LED_BLINK |
| 58 | /** |
| 59 | * led_set_period() - set the blink period of an LED |
| 60 | * |
| 61 | * Thie records the period if supported, or returns -ENOSYS if not. |
| 62 | * To start the LED blinking, use set_state(). |
| 63 | * |
| 64 | * @dev: LED device to change |
| 65 | * @period_ms: LED blink period in milliseconds |
| 66 | * @return 0 if OK, -ve on error |
| 67 | */ |
| 68 | int (*set_period)(struct udevice *dev, int period_ms); |
| 69 | #endif |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | #define led_get_ops(dev) ((struct led_ops *)(dev)->driver->ops) |
| 73 | |
| 74 | /** |
| 75 | * led_get_by_label() - Find an LED device by label |
| 76 | * |
| 77 | * @label: LED label to look up |
| 78 | * @devp: Returns the associated device, if found |
Simon Glass | fb8a5ff | 2015-07-06 12:54:33 -0600 | [diff] [blame] | 79 | * @return 0 if found, -ENODEV if not found, other -ve on error |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 80 | */ |
| 81 | int led_get_by_label(const char *label, struct udevice **devp); |
| 82 | |
| 83 | /** |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 84 | * led_set_state() - set the state of an LED |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 85 | * |
| 86 | * @dev: LED device to change |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 87 | * @state: LED state to set |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 88 | * @return 0 if OK, -ve on error |
| 89 | */ |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 90 | int led_set_state(struct udevice *dev, enum led_state_t state); |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 91 | |
Simon Glass | 8f4b612 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 92 | /** |
| 93 | * led_get_state() - get the state of an LED |
| 94 | * |
| 95 | * @dev: LED device to change |
| 96 | * @return LED state led_state_t, or -ve on error |
| 97 | */ |
| 98 | enum led_state_t led_get_state(struct udevice *dev); |
| 99 | |
Simon Glass | 53378da | 2017-04-10 11:34:57 -0600 | [diff] [blame] | 100 | /** |
| 101 | * led_set_period() - set the blink period of an LED |
| 102 | * |
| 103 | * @dev: LED device to change |
| 104 | * @period_ms: LED blink period in milliseconds |
| 105 | * @return 0 if OK, -ve on error |
| 106 | */ |
| 107 | int led_set_period(struct udevice *dev, int period_ms); |
| 108 | |
Patrick Delaunay | d7a435a | 2018-07-27 16:37:07 +0200 | [diff] [blame] | 109 | /** |
| 110 | * led_default_state() - set the default state for all the LED |
| 111 | * |
| 112 | * This enables all leds which have default state. |
| 113 | * see Documentation/devicetree/bindings/leds/common.txt |
| 114 | * |
| 115 | */ |
| 116 | int led_default_state(void); |
| 117 | |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 118 | #endif |