Skip to contentSkip to conversation

led: gpio: handle GPIO_ACTIVE_LOW flag properly

PATCH In review FUKAUMI Naoki 1 participant 2 messages Aug 28, 2024 – Aug 29, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 led: gpio: handle GPIO_ACTIVE_LOW flag properly

invert gpio state if GPIO_ACTIVE_LOW is specified in dts.

---
 drivers/led/led_gpio.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/led/led_gpio.c +5 -0
index ce22fb49f2a..54aa84e0726 100644
@@ -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;
 }
 
Signature · 1 line
2.43.0
#1 lore raw

sorry, this patch seems to be wrong.
I'll check it again.

Best regards,

--
FUKAUMI Naoki
Radxa Computer (Shenzhen) Co., Ltd.

Quoted 30 lines · FUKAUMI Naoki

invert gpio state if GPIO_ACTIVE_LOW is specified in dts.

---
  drivers/led/led_gpio.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/led/led_gpio.c +5 -0
index ce22fb49f2a..54aa84e0726 100644
@@ -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;
  }