Skip to contentSkip to conversation

gpio: emulate open drain & open source in dm_gpio_set_value()

PATCH New Neil Armstrong 2 participants 3 messages Apr 29, 2020 – Apr 30, 2020 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: emulate open drain & open source in dm_gpio_set_value()

Handle the GPIOD_OPEN_DRAIN & GPIOD_OPEN_SOURCE flags to emulate open drain and open source by setting the GPIO line as input depending on the requested value.

The behaviour is taken from the Linux gpiolib.

It notably permits enabling a GPIO regulator used as Open Drain on the Amlogic G12A/g12B/SM1 platforms for HDMI output feature.

---
 drivers/gpio/gpio-uclass.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpio/gpio-uclass.c +13 -0
index 757ab7106e..6b82d02a4d 100644
@@ -524,8 +524,21 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value)
 	if (ret)
 		return ret;
 
+	/*
+	 * Emulate open drain by not actively driving the line high or
+	 * Emulate open source by not actively driving the line low
+	 */
+	if ((desc->flags & GPIOD_OPEN_DRAIN && value) ||
+	    (desc->flags & GPIOD_OPEN_SOURCE && !value))
+		return gpio_get_ops(desc->dev)->direction_input(desc->dev,
+								desc->offset);
+	else if ((desc->flags & (GPIOD_OPEN_DRAIN | GPIOD_OPEN_SOURCE))
+		goto set_output_value;
+
 	if (desc->flags & GPIOD_ACTIVE_LOW)
 		value = !value;
+
+set_output_value:
 	gpio_get_ops(desc->dev)->set_value(desc->dev, desc->offset, value);
 	return 0;
 }
Signature · 1 line
2.22.0
#1 lore raw

PATCH 1/1 gpio: emulate open drain & open source in dm_gpio_set_value()

Hi Neil,

Quoted 7 lines · Neil Armstrong

Handle the GPIOD_OPEN_DRAIN & GPIOD_OPEN_SOURCE flags to emulate open drain and open source by setting the GPIO line as input depending on the requested value.

The behaviour is taken from the Linux gpiolib.

Quoted 7 lines

It notably permits enabling a GPIO regulator used as Open Drain on the Amlogic G12A/g12B/SM1 platforms for HDMI output feature.

---
 drivers/gpio/gpio-uclass.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Can you update the GPIO test please?

Regards,
Simon

#2 lore raw

PATCH 1/1 gpio: emulate open drain & open source in dm_gpio_set_value()

Quoted 18 lines · Simon Glass

Hi Neil,

Quoted 7 lines · Neil Armstrong

Handle the GPIOD_OPEN_DRAIN & GPIOD_OPEN_SOURCE flags to emulate open drain and open source by setting the GPIO line as input depending on the requested value.

The behaviour is taken from the Linux gpiolib.

Quoted 7 lines

It notably permits enabling a GPIO regulator used as Open Drain on the Amlogic G12A/g12B/SM1 platforms for HDMI output feature.

---
 drivers/gpio/gpio-uclass.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Quoted 5 lines

Can you update the GPIO test please?

Regards,
Simon

Sure,

Thanks,
Neil