[U-Boot] [PATCH20/23] LED: provide functionality to get led status

Benjamin Tietz uboot at dresden.micronet24.de
Sat Jun 18 14:57:07 CEST 2016


From: Benjamin Tietz <benjamin at micronet24.de>


---
 drivers/led/led-uclass.c |   10 ++++++++++
 include/led.h            |   18 ++++++++++++++++++
 2 files changed, 28 insertions(+)
-------------- next part --------------
From: Benjamin Tietz <benjamin at micronet24.de>


---
 drivers/led/led-uclass.c |   10 ++++++++++
 include/led.h            |   18 ++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c
index ce519d0..7d7dec3 100644
--- a/drivers/led/led-uclass.c
+++ b/drivers/led/led-uclass.c
@@ -101,6 +101,16 @@ int led_set_on(struct udevice *dev, int on)
 	return ops->set_on(dev, on);
 }
 
+int led_get_on(struct udevice *dev)
+{
+	struct led_ops *ops = led_get_ops(dev);
+
+	if (!ops->get_on)
+		return -ENOSYS;
+
+	return ops->get_on(dev);
+}
+
 UCLASS_DRIVER(led) = {
 	.id		= UCLASS_LED,
 	.name		= "led",
diff --git a/include/led.h b/include/led.h
index 4b1bd56..4709013 100644
--- a/include/led.h
+++ b/include/led.h
@@ -26,6 +26,16 @@ struct led_ops {
 	 * @return 0 if OK, -ve on error
 	 */
 	int (*set_on)(struct udevice *dev, int on);
+
+	/**
+	 * get_on() - get the current state of an LED
+	 *
+	 * function is optional.
+	 *
+	 * @dev:	LED device to check
+	 * @return 0 if OFF, 1 if ON, -ve on error
+	 */
+	int (*get_on)(struct udevice *dev);
 };
 
 #define led_get_ops(dev)	((struct led_ops *)(dev)->driver->ops)
@@ -74,4 +84,12 @@ int led_get_all(struct udevice **devarr, int maxitm);
  */
 int led_set_on(struct udevice *dev, int on);
 
+/**
+ * led_get_on() - get the current state of an LED
+ *
+ * @dev:	LED device to check
+ * @return 0 if OFF, 1 if ON, -ve on error
+ */
+int led_get_on(struct udevice *dev);
+
 #endif


More information about the U-Boot mailing list