blob: 8af87ea8ea8c68a45b420dec1d18643724dd3087 [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 Glass59171122015-06-23 15:38:45 -060036};
37
38#define led_get_ops(dev) ((struct led_ops *)(dev)->driver->ops)
39
40/**
41 * led_get_by_label() - Find an LED device by label
42 *
43 * @label: LED label to look up
44 * @devp: Returns the associated device, if found
Simon Glassfb8a5ff2015-07-06 12:54:33 -060045 * @return 0 if found, -ENODEV if not found, other -ve on error
Simon Glass59171122015-06-23 15:38:45 -060046 */
47int led_get_by_label(const char *label, struct udevice **devp);
48
49/**
Simon Glassddae9fc2017-04-10 11:34:54 -060050 * led_set_state() - set the state of an LED
Simon Glass59171122015-06-23 15:38:45 -060051 *
52 * @dev: LED device to change
Simon Glassddae9fc2017-04-10 11:34:54 -060053 * @state: LED state to set
Simon Glass59171122015-06-23 15:38:45 -060054 * @return 0 if OK, -ve on error
55 */
Simon Glassddae9fc2017-04-10 11:34:54 -060056int led_set_state(struct udevice *dev, enum led_state_t state);
Simon Glass59171122015-06-23 15:38:45 -060057
58#endif