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 | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 20 | enum led_state_t { |
| 21 | LEDST_OFF = 0, |
| 22 | LEDST_ON = 1, |
Simon Glass | 9413ad4 | 2017-04-10 11:34:56 -0600 | [diff] [blame^] | 23 | LEDST_TOGGLE, |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 24 | |
| 25 | LEDST_COUNT, |
| 26 | }; |
| 27 | |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 28 | struct led_ops { |
| 29 | /** |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 30 | * set_state() - set the state of an LED |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 31 | * |
| 32 | * @dev: LED device to change |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 33 | * @state: LED state to set |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 34 | * @return 0 if OK, -ve on error |
| 35 | */ |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 36 | int (*set_state)(struct udevice *dev, enum led_state_t state); |
Simon Glass | 8f4b612 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * led_get_state() - get the state of an LED |
| 40 | * |
| 41 | * @dev: LED device to change |
| 42 | * @return LED state led_state_t, or -ve on error |
| 43 | */ |
| 44 | enum led_state_t (*get_state)(struct udevice *dev); |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | #define led_get_ops(dev) ((struct led_ops *)(dev)->driver->ops) |
| 48 | |
| 49 | /** |
| 50 | * led_get_by_label() - Find an LED device by label |
| 51 | * |
| 52 | * @label: LED label to look up |
| 53 | * @devp: Returns the associated device, if found |
Simon Glass | fb8a5ff | 2015-07-06 12:54:33 -0600 | [diff] [blame] | 54 | * @return 0 if found, -ENODEV if not found, other -ve on error |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 55 | */ |
| 56 | int led_get_by_label(const char *label, struct udevice **devp); |
| 57 | |
| 58 | /** |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 59 | * led_set_state() - set the state of an LED |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 60 | * |
| 61 | * @dev: LED device to change |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 62 | * @state: LED state to set |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 63 | * @return 0 if OK, -ve on error |
| 64 | */ |
Simon Glass | ddae9fc | 2017-04-10 11:34:54 -0600 | [diff] [blame] | 65 | int led_set_state(struct udevice *dev, enum led_state_t state); |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 66 | |
Simon Glass | 8f4b612 | 2017-04-10 11:34:55 -0600 | [diff] [blame] | 67 | /** |
| 68 | * led_get_state() - get the state of an LED |
| 69 | * |
| 70 | * @dev: LED device to change |
| 71 | * @return LED state led_state_t, or -ve on error |
| 72 | */ |
| 73 | enum led_state_t led_get_state(struct udevice *dev); |
| 74 | |
Simon Glass | 5917112 | 2015-06-23 15:38:45 -0600 | [diff] [blame] | 75 | #endif |