blob: 8c107e28e78e89d98c3a5cdc786016d4628bb118 [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,
Simon Glass9413ad42017-04-10 11:34:56 -060023 LEDST_TOGGLE,
Simon Glassddae9fc2017-04-10 11:34:54 -060024
25 LEDST_COUNT,
26};
27
Simon Glass59171122015-06-23 15:38:45 -060028struct led_ops {
29 /**
Simon Glassddae9fc2017-04-10 11:34:54 -060030 * set_state() - set the state of an LED
Simon Glass59171122015-06-23 15:38:45 -060031 *
32 * @dev: LED device to change
Simon Glassddae9fc2017-04-10 11:34:54 -060033 * @state: LED state to set
Simon Glass59171122015-06-23 15:38:45 -060034 * @return 0 if OK, -ve on error
35 */
Simon Glassddae9fc2017-04-10 11:34:54 -060036 int (*set_state)(struct udevice *dev, enum led_state_t state);
Simon Glass8f4b6122017-04-10 11:34:55 -060037
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 Glass59171122015-06-23 15:38:45 -060045};
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 Glassfb8a5ff2015-07-06 12:54:33 -060054 * @return 0 if found, -ENODEV if not found, other -ve on error
Simon Glass59171122015-06-23 15:38:45 -060055 */
56int led_get_by_label(const char *label, struct udevice **devp);
57
58/**
Simon Glassddae9fc2017-04-10 11:34:54 -060059 * led_set_state() - set the state of an LED
Simon Glass59171122015-06-23 15:38:45 -060060 *
61 * @dev: LED device to change
Simon Glassddae9fc2017-04-10 11:34:54 -060062 * @state: LED state to set
Simon Glass59171122015-06-23 15:38:45 -060063 * @return 0 if OK, -ve on error
64 */
Simon Glassddae9fc2017-04-10 11:34:54 -060065int led_set_state(struct udevice *dev, enum led_state_t state);
Simon Glass59171122015-06-23 15:38:45 -060066
Simon Glass8f4b6122017-04-10 11:34:55 -060067/**
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 */
73enum led_state_t led_get_state(struct udevice *dev);
74
Simon Glass59171122015-06-23 15:38:45 -060075#endif