blob: c67af22591206117bd716defe115bc3fb06212e3 [file] [log] [blame]
Simon Glass59171122015-06-23 15:38:45 -06001/*
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 Glass56e19872017-04-10 11:34:53 -060012 * struct led_uc_plat - Platform data the uclass stores about each device
Simon Glass59171122015-06-23 15:38:45 -060013 *
14 * @label: LED label
15 */
Simon Glass56e19872017-04-10 11:34:53 -060016struct led_uc_plat {
Simon Glass59171122015-06-23 15:38:45 -060017 const char *label;
18};
19
Simon Glass53378da2017-04-10 11:34:57 -060020/**
21 * struct led_uc_priv - Private data the uclass stores about each device
22 *
23 * @period_ms: Flash period in milliseconds
24 */
25struct led_uc_priv {
26 int period_ms;
27};
28
Simon Glassddae9fc2017-04-10 11:34:54 -060029enum led_state_t {
30 LEDST_OFF = 0,
31 LEDST_ON = 1,
Simon Glass9413ad42017-04-10 11:34:56 -060032 LEDST_TOGGLE,
Simon Glass53378da2017-04-10 11:34:57 -060033#ifdef CONFIG_LED_BLINK
34 LEDST_BLINK,
35#endif
Simon Glassddae9fc2017-04-10 11:34:54 -060036
37 LEDST_COUNT,
38};
39
Simon Glass59171122015-06-23 15:38:45 -060040struct led_ops {
41 /**
Simon Glassddae9fc2017-04-10 11:34:54 -060042 * set_state() - set the state of an LED
Simon Glass59171122015-06-23 15:38:45 -060043 *
44 * @dev: LED device to change
Simon Glassddae9fc2017-04-10 11:34:54 -060045 * @state: LED state to set
Simon Glass59171122015-06-23 15:38:45 -060046 * @return 0 if OK, -ve on error
47 */
Simon Glassddae9fc2017-04-10 11:34:54 -060048 int (*set_state)(struct udevice *dev, enum led_state_t state);
Simon Glass8f4b6122017-04-10 11:34:55 -060049
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 Glass53378da2017-04-10 11:34:57 -060057
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 Glass59171122015-06-23 15:38:45 -060071};
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 Glassfb8a5ff2015-07-06 12:54:33 -060080 * @return 0 if found, -ENODEV if not found, other -ve on error
Simon Glass59171122015-06-23 15:38:45 -060081 */
82int led_get_by_label(const char *label, struct udevice **devp);
83
84/**
Simon Glassddae9fc2017-04-10 11:34:54 -060085 * led_set_state() - set the state of an LED
Simon Glass59171122015-06-23 15:38:45 -060086 *
87 * @dev: LED device to change
Simon Glassddae9fc2017-04-10 11:34:54 -060088 * @state: LED state to set
Simon Glass59171122015-06-23 15:38:45 -060089 * @return 0 if OK, -ve on error
90 */
Simon Glassddae9fc2017-04-10 11:34:54 -060091int led_set_state(struct udevice *dev, enum led_state_t state);
Simon Glass59171122015-06-23 15:38:45 -060092
Simon Glass8f4b6122017-04-10 11:34:55 -060093/**
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 */
99enum led_state_t led_get_state(struct udevice *dev);
100
Simon Glass53378da2017-04-10 11:34:57 -0600101/**
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 */
108int led_set_period(struct udevice *dev, int period_ms);
109
Simon Glass59171122015-06-23 15:38:45 -0600110#endif