devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of/gpio: Define OF_GPIO_OPEN_DRAIN flag for Open Drain outputs.
@ 2014-02-10 22:05 David Daney
  2014-02-11  4:31 ` Alexandre Courbot
       [not found] ` <1392069908-22017-1-git-send-email-ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 2 replies; 4+ messages in thread
From: David Daney @ 2014-02-10 22:05 UTC (permalink / raw)
  To: Grant Likely, Rob Herring, devicetree, Linus Walleij,
	Alexandre Courbot, linux-gpio
  Cc: linux-kernel, David Daney

From: David Daney <david.daney@cavium.com>

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);
	.
	.
	.

Signed-off-by: David Daney <david.daney@cavium.com>
---
 include/linux/of_gpio.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index f14123a..0e374774 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -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
-- 
1.7.11.7


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

* Re: [PATCH] of/gpio: Define OF_GPIO_OPEN_DRAIN flag for Open Drain outputs.
  2014-02-10 22:05 [PATCH] of/gpio: Define OF_GPIO_OPEN_DRAIN flag for Open Drain outputs David Daney
@ 2014-02-11  4:31 ` Alexandre Courbot
  2014-02-11 18:51   ` David Daney
       [not found] ` <1392069908-22017-1-git-send-email-ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  1 sibling, 1 reply; 4+ messages in thread
From: Alexandre Courbot @ 2014-02-11  4:31 UTC (permalink / raw)
  To: David Daney
  Cc: Grant Likely, Rob Herring, devicetree@vger.kernel.org,
	Linus Walleij, linux-gpio@vger.kernel.org,
	Linux Kernel Mailing List, David Daney

On Tue, Feb 11, 2014 at 7:05 AM, David Daney <ddaney.cavm@gmail.com> wrote:
> From: David Daney <david.daney@cavium.com>
>
> 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);

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.

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

* Re: [PATCH] of/gpio: Define OF_GPIO_OPEN_DRAIN flag for Open Drain outputs.
  2014-02-11  4:31 ` Alexandre Courbot
@ 2014-02-11 18:51   ` David Daney
  0 siblings, 0 replies; 4+ messages in thread
From: David Daney @ 2014-02-11 18:51 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: David Daney, Grant Likely, Rob Herring,
	devicetree@vger.kernel.org, Linus Walleij,
	linux-gpio@vger.kernel.org, Linux Kernel Mailing List,
	David Daney

On 02/10/2014 08:31 PM, Alexandre Courbot wrote:
> On Tue, Feb 11, 2014 at 7:05 AM, David Daney <ddaney.cavm@gmail.com> wrote:
>> From: David Daney <david.daney@cavium.com>
>>
>> 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);
>
> 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 for the suggestion.  I will send a revised patch set for your 
consideration.

David Daney

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

* Re: [PATCH] of/gpio: Define OF_GPIO_OPEN_DRAIN flag for Open Drain outputs.
       [not found] ` <1392069908-22017-1-git-send-email-ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-02-24 12:08   ` Linus Walleij
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2014-02-24 12:08 UTC (permalink / raw)
  To: David Daney
  Cc: Grant Likely, Rob Herring,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Alexandre Courbot,
	linux-gpio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, David Daney

On Mon, Feb 10, 2014 at 11:05 PM, David Daney <ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> From: David Daney <david.daney-YGCgFSpz5w/QT0dZR+AlfA@public.gmane.org>
>
> 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2014-02-24 12:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-10 22:05 [PATCH] of/gpio: Define OF_GPIO_OPEN_DRAIN flag for Open Drain outputs David Daney
2014-02-11  4:31 ` Alexandre Courbot
2014-02-11 18:51   ` David Daney
     [not found] ` <1392069908-22017-1-git-send-email-ddaney.cavm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-02-24 12:08   ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).