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