blob: bbab4d14c9856025cd06a0fa1dcd9ca6357064d6 [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 Glassddae9fc2017-04-10 11:34:54 -060020enum led_state_t {
21 LEDST_OFF = 0,
22 LEDST_ON = 1,
23
24 LEDST_COUNT,
25};
26
Simon Glass59171122015-06-23 15:38:45 -060027struct led_ops {
28 /**
Simon Glassddae9fc2017-04-10 11:34:54 -060029 * set_state() - set the state of an LED
Simon Glass59171122015-06-23 15:38:45 -060030 *
31 * @dev: LED device to change
Simon Glassddae9fc2017-04-10 11:34:54 -060032 * @state: LED state to set
Simon Glass59171122015-06-23 15:38:45 -060033 * @return 0 if OK, -ve on error
34 */
Simon Glassddae9fc2017-04-10 11:34:54 -060035 int (*set_state)(struct udevice *dev, enum led_state_t state);
Simon Glass8f4b6122017-04-10 11:34:55 -060036
37 /**
38 * led_get_state() - get the state of an LED
39 *
40 * @dev: LED device to change
41 * @return LED state led_state_t, or -ve on error
42 */
43 enum led_state_t (*get_state)(struct udevice *dev);
Simon Glass59171122015-06-23 15:38:45 -060044};
45
46#define led_get_ops(dev) ((struct led_ops *)(dev)->driver->ops)
47
48/**
49 * led_get_by_label() - Find an LED device by label
50 *
51 * @label: LED label to look up
52 * @devp: Returns the associated device, if found
Simon Glassfb8a5ff2015-07-06 12:54:33 -060053 * @return 0 if found, -ENODEV if not found, other -ve on error
Simon Glass59171122015-06-23 15:38:45 -060054 */
55int led_get_by_label(const char *label, struct udevice **devp);
56
57/**
Simon Glassddae9fc2017-04-10 11:34:54 -060058 * led_set_state() - set the state of an LED
Simon Glass59171122015-06-23 15:38:45 -060059 *
60 * @dev: LED device to change
Simon Glassddae9fc2017-04-10 11:34:54 -060061 * @state: LED state to set
Simon Glass59171122015-06-23 15:38:45 -060062 * @return 0 if OK, -ve on error
63 */
Simon Glassddae9fc2017-04-10 11:34:54 -060064int led_set_state(struct udevice *dev, enum led_state_t state);
Simon Glass59171122015-06-23 15:38:45 -060065
Simon Glass8f4b6122017-04-10 11:34:55 -060066/**
67 * led_get_state() - get the state of an LED
68 *
69 * @dev: LED device to change
70 * @return LED state led_state_t, or -ve on error
71 */
72enum led_state_t led_get_state(struct udevice *dev);
73
Simon Glass59171122015-06-23 15:38:45 -060074#endif