[PATCH] led: gpio: handle GPIO_ACTIVE_LOW flag properly

FUKAUMI Naoki naoki at radxa.com
Wed Aug 28 14:15:16 CEST 2024


invert gpio state if GPIO_ACTIVE_LOW is specified in dts.

Signed-off-by: FUKAUMI Naoki <naoki at radxa.com>
---
 drivers/led/led_gpio.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/led/led_gpio.c b/drivers/led/led_gpio.c
index ce22fb49f2a..54aa84e0726 100644
--- a/drivers/led/led_gpio.c
+++ b/drivers/led/led_gpio.c
@@ -25,6 +25,8 @@ static int gpio_led_set_state(struct udevice *dev, enum led_state_t state)
 	switch (state) {
 	case LEDST_OFF:
 	case LEDST_ON:
+		if (priv->gpio.flags & GPIOD_ACTIVE_LOW)
+			state = !state;
 		break;
 	case LEDST_TOGGLE:
 		ret = dm_gpio_get_value(&priv->gpio);
@@ -50,6 +52,9 @@ static enum led_state_t gpio_led_get_state(struct udevice *dev)
 	if (ret < 0)
 		return ret;
 
+	if (priv->gpio.flags & GPIOD_ACTIVE_LOW)
+		ret = !ret;
+
 	return ret ? LEDST_ON : LEDST_OFF;
 }
 
-- 
2.43.0



More information about the U-Boot mailing list