Skip to contentSkip to conversation

of/gpio: Define OF_GPIO_OPEN_DRAIN flag for Open Drain outputs.

PATCH In review David Daney 4 participants 4 messages Feb 10, 2014 – Feb 24, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of/gpio: Define OF_GPIO_OPEN_DRAIN flag for Open Drain outputs.

From: David Daney <[email protected]>

When we have a GPIO pin connected to an open-drain network, we want a standard way of specifying this in the device tree. So we choose bit 1 of the flag field to indicate open drain.

A typical use case would be something like:

	enum of_gpio_flags f;
	.
	.
	.
	reset_gpio = of_get_named_gpio_flags(node, "reset", 0, &f);
	.
	.
	.
	ret = gpio_request_one(reset_gpio,
		(f & OF_GPIO_OPEN_DRAIN) ? GPIOF_OPEN_DRAIN : 0,
		 "reset");
	.
	.
	.
	gpio_direction_output(reset_gpio, 1);
	gpio_set_value(reset_gpio, 0);
	msleep(20);
	gpio_set_value(reset_gpio, 1);
	.
	.
	.
---
 include/linux/of_gpio.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/of_gpio.h +1 -0
index f14123a..0e374774 100644
@@ -30,6 +30,7 @@ struct device_node;
  */
 enum of_gpio_flags {
 	OF_GPIO_ACTIVE_LOW = 0x1,
+	OF_GPIO_OPEN_DRAIN = 0x2,
 };
 
 #ifdef CONFIG_OF_GPIO
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 18 lines · David Daney

From: David Daney <[email protected]>

When we have a GPIO pin connected to an open-drain network, we want a standard way of specifying this in the device tree. So we choose bit 1 of the flag field to indicate open drain.

A typical use case would be something like:

        enum of_gpio_flags f;
        .
        .
        .
        reset_gpio = of_get_named_gpio_flags(node, "reset", 0, &f);
        .
        .
        .
        ret = gpio_request_one(reset_gpio,
                (f & OF_GPIO_OPEN_DRAIN) ? GPIOF_OPEN_DRAIN : 0,
Quoted 8 lines
                 "reset");
        .
        .
        .
        gpio_direction_output(reset_gpio, 1);
        gpio_set_value(reset_gpio, 0);
        msleep(20);
        gpio_set_value(reset_gpio, 1);

This is also useful for gpiod_get(). However, while you are at it, could you also add a flag for the OF_GPIO_OPEN_SOURCE property? My joy would be complete if you could also take the time to update of_find_gpio() to pass these new flags back to the caller as it already does for OF_GPIO_ACTIVE_LOW.

Then you could even switch your use-case to the gpiod interface and not bother with passing these flags by yourself anymore. Just sayin'. ;)

Thanks,
Alex.

#2 lore raw
Quoted 34 lines · Alexandre Courbot
Quoted 18 lines · David Daney

From: David Daney <[email protected]>

When we have a GPIO pin connected to an open-drain network, we want a standard way of specifying this in the device tree. So we choose bit 1 of the flag field to indicate open drain.

A typical use case would be something like:

         enum of_gpio_flags f;
         .
         .
         .
         reset_gpio = of_get_named_gpio_flags(node, "reset", 0, &f);
         .
         .
         .
         ret = gpio_request_one(reset_gpio,
                 (f & OF_GPIO_OPEN_DRAIN) ? GPIOF_OPEN_DRAIN : 0,
Quoted 8 lines
                  "reset");
         .
         .
         .
         gpio_direction_output(reset_gpio, 1);
         gpio_set_value(reset_gpio, 0);
         msleep(20);
         gpio_set_value(reset_gpio, 1);

This is also useful for gpiod_get(). However, while you are at it, could you also add a flag for the OF_GPIO_OPEN_SOURCE property? My joy would be complete if you could also take the time to update of_find_gpio() to pass these new flags back to the caller as it already does for OF_GPIO_ACTIVE_LOW.

Quoted 3 lines

Then you could even switch your use-case to the gpiod interface and not bother with passing these flags by yourself anymore. Just sayin'. ;)

Thanks for the suggestion. I will send a revised patch set for your consideration.

David Daney

#3 lore raw
In reply to David Daney
Quoted 5 lines · David Daney

From: David Daney <david.daney-YGCgFSpz5w/[email protected]>

When we have a GPIO pin connected to an open-drain network, we want a standard way of specifying this in the device tree. So we choose bit 1 of the flag field to indicate open drain.

This is a good idea.

But the patch is missing two things:

- Add open source as well, as indicated.

- Add this definition to include/dt-bindings/gpio/gpio.h

- Add this *and* the missing active low property to the binding documentation in:
Documentation/devicetree/bindings/gpio/gpio.txt (pls help with this!)

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html