[U-Boot] [PATCH 2/6] led: gpio: add support for get_status function

techping.chan at gmail.com techping.chan at gmail.com
Mon Mar 27 14:38:39 UTC 2017


From: Ziping Chen <techping.chan at gmail.com>

The status of a GPIO-connected LED can be read back by reading the GPO
value.

Add the support for get_status function in led_gpio driver.

Signed-off-by: Ziping Chen <techping.chan at gmail.com>
---
 drivers/led/led_gpio.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/led/led_gpio.c b/drivers/led/led_gpio.c
index 5b11990..b64721e 100644
--- a/drivers/led/led_gpio.c
+++ b/drivers/led/led_gpio.c
@@ -28,6 +28,16 @@ static int gpio_led_set_on(struct udevice *dev, int on)
 	return dm_gpio_set_value(&priv->gpio, on);
 }
 
+static int gpio_led_get_status(struct udevice *dev)
+{
+	struct led_gpio_priv *priv = dev_get_priv(dev);
+
+	if (!dm_gpio_is_valid(&priv->gpio))
+		return -EREMOTEIO;
+
+	return dm_gpio_get_value(&priv->gpio);
+}
+
 static int led_gpio_probe(struct udevice *dev)
 {
 	struct led_uclass_plat *uc_plat = dev_get_uclass_platdata(dev);
@@ -88,6 +98,7 @@ static int led_gpio_bind(struct udevice *parent)
 
 static const struct led_ops gpio_led_ops = {
 	.set_on		= gpio_led_set_on,
+	.get_status	= gpio_led_get_status,
 };
 
 static const struct udevice_id led_gpio_ids[] = {
-- 
2.7.4



More information about the U-Boot mailing list