Skip to contentSkip to conversation

of/gpio: Automatic handling of devicetree open-drain GPIO specifications.

PATCH In review David Daney 3 participants 7 messages Feb 11, 2014 – Feb 24, 2014

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

v2 cover of/gpio: Automatic handling of devicetree open-drain GPIO specifications.

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

Add two new flags for open-drain and open-source GPIOs and the corresponding handling in gpiod_get() to automatically set the corresponding flags in the GPIO system.

Changes from v1 (suggested by Alexandre Courbot):

o Add OF_GPIO_OPEN_SOURCE
o Add automatic propagation of the flags in gpiod_get() et al.

David Daney (2):
of/gpio: Define OF_GPIO_OPEN_DRAIN and OF_GPIO_OPEN_SOURCE flags. of/gpio: Automatically decode OF_GPIO_OPEN_DRAIN and
OF_GPIO_OPEN_SOURCE flags in gpiolib.

 drivers/gpio/gpiolib.c  | 6 ++++++
 include/linux/of_gpio.h | 2 ++
 2 files changed, 8 insertions(+)
Signature · 6 lines
1.7.11.7

--
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
#1 lore raw

PATCH v2 1/2 of/gpio: Define OF_GPIO_OPEN_DRAIN and OF_GPIO_OPEN_SOURCE flags.

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

Since the same arguments hold for open-source configurations, add a definition for OF_GPIO_OPEN_SOURCE as well.

---
 include/linux/of_gpio.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/of_gpio.h +2 -0
index f14123a..cfacf5875 100644
@@ -30,6 +30,8 @@ struct device_node;
  */
 enum of_gpio_flags {
 	OF_GPIO_ACTIVE_LOW = 0x1,
+	OF_GPIO_OPEN_DRAIN = 0x2,
+	OF_GPIO_OPEN_SOURCE = 0x4,
 };
 
 #ifdef CONFIG_OF_GPIO
Signature · 1 line
1.7.11.7
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] of/gpio: Define OF_GPIO_OPEN_DRAIN and OF_GPIO_OPEN_SOURCE flags.

Quoted 30 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,
                 "reset");
        .
        .
        .
        gpio_direction_output(reset_gpio, 1);
        gpio_set_value(reset_gpio, 0);
        msleep(20);
        gpio_set_value(reset_gpio, 1);
        .
        .
        .
Quoted 4 lines

Since the same arguments hold for open-source configurations, add a definition for OF_GPIO_OPEN_SOURCE as well.

#3 lore raw

Re: [PATCH v2 1/2] of/gpio: Define OF_GPIO_OPEN_DRAIN and OF_GPIO_OPEN_SOURCE flags.

In reply to David Daney
Quoted 5 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.

Same comments as for v1...

Yours,
Linus Walleij

#4 lore raw

Re: [PATCH v2 1/2] of/gpio: Define OF_GPIO_OPEN_DRAIN and OF_GPIO_OPEN_SOURCE flags.

In reply to David Daney

include/linux/of_gpio.h struct device_node; · line 35

Quoted 5 lines · David Daney
 enum of_gpio_flags {
        OF_GPIO_ACTIVE_LOW = 0x1,
include/linux/of_gpio.h +2 -0
+       OF_GPIO_OPEN_DRAIN = 0x2,
+       OF_GPIO_OPEN_SOURCE = 0x4,
 };

BTW I think this enum shall be deleted and replaced by #include <dt-bindings/gpio/gpio.h> and use the definition from there.

Yours,
Linus Walleij

#5 lore raw

PATCH v2 2/2 of/gpio: Automatically decode OF_GPIO_OPEN_DRAIN and OF_GPIO_OPEN_SOURCE flags in gpiolib.

In reply to David Daney

From: David Daney <[email protected]>

Just as gpiod_get() automatically interprets the OF_GPIO_ACTIVE_LOW flag from the device tree, add handling for OF_GPIO_OPEN_DRAIN and OF_GPIO_OPEN_SOURCE.

This keeps the details of handling open-drain GPIOs in the core GPIO code, and out of the individual drivers.

---
 drivers/gpio/gpiolib.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpio/gpiolib.c +6 -0
index 50c4922..7f596d0 100644
@@ -2307,6 +2307,12 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
 	if (of_flags & OF_GPIO_ACTIVE_LOW)
 		*flags |= GPIO_ACTIVE_LOW;
 
+	if (of_flags & OF_GPIO_OPEN_DRAIN)
+		*flags |= GPIO_OPEN_DRAIN;
+
+	if (of_flags & OF_GPIO_OPEN_SOURCE)
+		*flags |= GPIO_OPEN_SOURCE;
+
 	return desc;
 }
 #else
Signature · 1 line
1.7.11.7
Reviewed-by on v2 2/2
#6 lore raw

Re: [PATCH v2 2/2] of/gpio: Automatically decode OF_GPIO_OPEN_DRAIN and OF_GPIO_OPEN_SOURCE flags in gpiolib.

Quoted 20 lines · David Daney

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

Just as gpiod_get() automatically interprets the OF_GPIO_ACTIVE_LOW flag from the device tree, add handling for OF_GPIO_OPEN_DRAIN and OF_GPIO_OPEN_SOURCE.

This keeps the details of handling open-drain GPIOs in the core GPIO code, and out of the individual drivers.

---
 drivers/gpio/gpiolib.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpio/gpiolib.c +0 -0
index 50c4922..7f596d0 100644
@@ -2307,6 +2307,12 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
        if (of_flags & OF_GPIO_ACTIVE_LOW)

drivers/gpio/gpiolib.c static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, · line 2317

Quoted 10 lines
drivers/gpio/gpiolib.c +6 -0
                *flags |= GPIO_ACTIVE_LOW;
 
+       if (of_flags & OF_GPIO_OPEN_DRAIN)
+               *flags |= GPIO_OPEN_DRAIN;
+
+       if (of_flags & OF_GPIO_OPEN_SOURCE)
+               *flags |= GPIO_OPEN_SOURCE;
+
        return desc;
 }

Thanks for taking the time to do this!
--
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