public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] gpio: emulate open drain & open source in dm_gpio_set_value()
@ 2020-04-29  8:06 Neil Armstrong
  2020-04-29 18:04 ` Simon Glass
  0 siblings, 1 reply; 3+ messages in thread
From: Neil Armstrong @ 2020-04-29  8:06 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
---
 drivers/gpio/gpio-uclass.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 757ab7106e..6b82d02a4d 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -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;
 }
-- 
2.22.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] gpio: emulate open drain & open source in dm_gpio_set_value()
  2020-04-29  8:06 [PATCH] gpio: emulate open drain & open source in dm_gpio_set_value() Neil Armstrong
@ 2020-04-29 18:04 ` Simon Glass
  2020-04-30 12:27   ` Neil Armstrong
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Glass @ 2020-04-29 18:04 UTC (permalink / raw)
  To: u-boot

Hi Neil,

On Wed, 29 Apr 2020 at 02:06, Neil Armstrong <narmstrong@baylibre.com> wrote:
>
> 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.
>
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> ---
>  drivers/gpio/gpio-uclass.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)

Can you update the GPIO test please?

Regards,
Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] gpio: emulate open drain & open source in dm_gpio_set_value()
  2020-04-29 18:04 ` Simon Glass
@ 2020-04-30 12:27   ` Neil Armstrong
  0 siblings, 0 replies; 3+ messages in thread
From: Neil Armstrong @ 2020-04-30 12:27 UTC (permalink / raw)
  To: u-boot

On 29/04/2020 20:04, Simon Glass wrote:
> Hi Neil,
> 
> On Wed, 29 Apr 2020 at 02:06, Neil Armstrong <narmstrong@baylibre.com> wrote:
>>
>> 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.
>>
>> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
>> ---
>>  drivers/gpio/gpio-uclass.c | 13 +++++++++++++
>>  1 file changed, 13 insertions(+)
> 
> Can you update the GPIO test please?
> 
> Regards,
> Simon
> 

Sure,

Thanks,
Neil

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-30 12:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-29  8:06 [PATCH] gpio: emulate open drain & open source in dm_gpio_set_value() Neil Armstrong
2020-04-29 18:04 ` Simon Glass
2020-04-30 12:27   ` Neil Armstrong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox