2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2015-06-23 21:38:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LED_H
|
|
|
|
#define __LED_H
|
|
|
|
|
2020-10-31 03:38:53 +00:00
|
|
|
struct udevice;
|
|
|
|
|
2022-04-03 23:23:27 +00:00
|
|
|
enum led_state_t {
|
|
|
|
LEDST_OFF = 0,
|
|
|
|
LEDST_ON = 1,
|
|
|
|
LEDST_TOGGLE,
|
|
|
|
#ifdef CONFIG_LED_BLINK
|
|
|
|
LEDST_BLINK,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LEDST_COUNT,
|
|
|
|
};
|
|
|
|
|
2015-06-23 21:38:45 +00:00
|
|
|
/**
|
2017-04-10 17:34:53 +00:00
|
|
|
* struct led_uc_plat - Platform data the uclass stores about each device
|
2015-06-23 21:38:45 +00:00
|
|
|
*
|
|
|
|
* @label: LED label
|
2022-04-03 23:23:27 +00:00
|
|
|
* @default_state: LED default state
|
2015-06-23 21:38:45 +00:00
|
|
|
*/
|
2017-04-10 17:34:53 +00:00
|
|
|
struct led_uc_plat {
|
2015-06-23 21:38:45 +00:00
|
|
|
const char *label;
|
2022-04-03 23:23:27 +00:00
|
|
|
enum led_state_t default_state;
|
2015-06-23 21:38:45 +00:00
|
|
|
};
|
|
|
|
|
2017-04-10 17:34:57 +00:00
|
|
|
/**
|
|
|
|
* struct led_uc_priv - Private data the uclass stores about each device
|
|
|
|
*
|
|
|
|
* @period_ms: Flash period in milliseconds
|
|
|
|
*/
|
|
|
|
struct led_uc_priv {
|
|
|
|
int period_ms;
|
|
|
|
};
|
|
|
|
|
2015-06-23 21:38:45 +00:00
|
|
|
struct led_ops {
|
|
|
|
/**
|
2017-04-10 17:34:54 +00:00
|
|
|
* set_state() - set the state of an LED
|
2015-06-23 21:38:45 +00:00
|
|
|
*
|
|
|
|
* @dev: LED device to change
|
2017-04-10 17:34:54 +00:00
|
|
|
* @state: LED state to set
|
2015-06-23 21:38:45 +00:00
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*/
|
2017-04-10 17:34:54 +00:00
|
|
|
int (*set_state)(struct udevice *dev, enum led_state_t state);
|
2017-04-10 17:34:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* led_get_state() - get the state of an LED
|
|
|
|
*
|
|
|
|
* @dev: LED device to change
|
|
|
|
* @return LED state led_state_t, or -ve on error
|
|
|
|
*/
|
|
|
|
enum led_state_t (*get_state)(struct udevice *dev);
|
2017-04-10 17:34:57 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_LED_BLINK
|
|
|
|
/**
|
|
|
|
* led_set_period() - set the blink period of an LED
|
|
|
|
*
|
|
|
|
* Thie records the period if supported, or returns -ENOSYS if not.
|
|
|
|
* To start the LED blinking, use set_state().
|
|
|
|
*
|
|
|
|
* @dev: LED device to change
|
|
|
|
* @period_ms: LED blink period in milliseconds
|
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int (*set_period)(struct udevice *dev, int period_ms);
|
|
|
|
#endif
|
2015-06-23 21:38:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define led_get_ops(dev) ((struct led_ops *)(dev)->driver->ops)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* led_get_by_label() - Find an LED device by label
|
|
|
|
*
|
|
|
|
* @label: LED label to look up
|
|
|
|
* @devp: Returns the associated device, if found
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -ENODEV if not found, other -ve on error
|
2015-06-23 21:38:45 +00:00
|
|
|
*/
|
|
|
|
int led_get_by_label(const char *label, struct udevice **devp);
|
|
|
|
|
|
|
|
/**
|
2017-04-10 17:34:54 +00:00
|
|
|
* led_set_state() - set the state of an LED
|
2015-06-23 21:38:45 +00:00
|
|
|
*
|
|
|
|
* @dev: LED device to change
|
2017-04-10 17:34:54 +00:00
|
|
|
* @state: LED state to set
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2015-06-23 21:38:45 +00:00
|
|
|
*/
|
2017-04-10 17:34:54 +00:00
|
|
|
int led_set_state(struct udevice *dev, enum led_state_t state);
|
2015-06-23 21:38:45 +00:00
|
|
|
|
2017-04-10 17:34:55 +00:00
|
|
|
/**
|
|
|
|
* led_get_state() - get the state of an LED
|
|
|
|
*
|
|
|
|
* @dev: LED device to change
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: LED state led_state_t, or -ve on error
|
2017-04-10 17:34:55 +00:00
|
|
|
*/
|
|
|
|
enum led_state_t led_get_state(struct udevice *dev);
|
|
|
|
|
2017-04-10 17:34:57 +00:00
|
|
|
/**
|
|
|
|
* led_set_period() - set the blink period of an LED
|
|
|
|
*
|
|
|
|
* @dev: LED device to change
|
|
|
|
* @period_ms: LED blink period in milliseconds
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2017-04-10 17:34:57 +00:00
|
|
|
*/
|
|
|
|
int led_set_period(struct udevice *dev, int period_ms);
|
|
|
|
|
2018-07-27 14:37:07 +00:00
|
|
|
/**
|
|
|
|
* led_default_state() - set the default state for all the LED
|
|
|
|
*
|
|
|
|
* This enables all leds which have default state.
|
|
|
|
* see Documentation/devicetree/bindings/leds/common.txt
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int led_default_state(void);
|
|
|
|
|
2015-06-23 21:38:45 +00:00
|
|
|
#endif
|