Skip to content

Commit 4c0facd

Browse files
ldewanganlinusw
authored andcommitted
gpio: core: Decouple open drain/source flag with active low/high
Currently, the GPIO interface is said to Open Drain if it is Single Ended and active LOW. Similarly, it is said as Open Source if it is Single Ended and active HIGH. The active HIGH/LOW is used in the interface for setting the pin state to HIGH or LOW when enabling/disabling the interface. In Open Drain interface, pin is set to HIGH by putting pin in high impedance and LOW by driving to the LOW. In Open Source interface, pin is set to HIGH by driving pin to HIGH and set to LOW by putting pin in high impedance. With above, the Open Drain/Source is unrelated to the active LOW/HIGH in interface. There is interface where the enable/disable of interface is ether active LOW or HIGH but it is Open Drain type. Hence decouple the Open Drain with Single Ended + Active LOW and Open Source with Single Ended + Active HIGH. Adding different flag for the Open Drain/Open Source which is valid only when Single ended flag is enabled. Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 11598d1 commit 4c0facd

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

drivers/gpio/gpiolib-of.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
147147
*flags |= GPIO_ACTIVE_LOW;
148148

149149
if (of_flags & OF_GPIO_SINGLE_ENDED) {
150-
if (of_flags & OF_GPIO_ACTIVE_LOW)
150+
if (of_flags & OF_GPIO_OPEN_DRAIN)
151151
*flags |= GPIO_OPEN_DRAIN;
152152
else
153153
*flags |= GPIO_OPEN_SOURCE;

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3340,6 +3340,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
33403340
unsigned long lflags = 0;
33413341
bool active_low = false;
33423342
bool single_ended = false;
3343+
bool open_drain = false;
33433344
int ret;
33443345

33453346
if (!fwnode)
@@ -3353,6 +3354,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
33533354
if (!IS_ERR(desc)) {
33543355
active_low = flags & OF_GPIO_ACTIVE_LOW;
33553356
single_ended = flags & OF_GPIO_SINGLE_ENDED;
3357+
open_drain = flags & OF_GPIO_OPEN_DRAIN;
33563358
}
33573359
} else if (is_acpi_node(fwnode)) {
33583360
struct acpi_gpio_info info;
@@ -3373,7 +3375,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
33733375
lflags |= GPIO_ACTIVE_LOW;
33743376

33753377
if (single_ended) {
3376-
if (active_low)
3378+
if (open_drain)
33773379
lflags |= GPIO_OPEN_DRAIN;
33783380
else
33793381
lflags |= GPIO_OPEN_SOURCE;

include/dt-bindings/gpio/gpio.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
#define GPIO_PUSH_PULL 0
1818
#define GPIO_SINGLE_ENDED 2
1919

20+
/* Bit 2 express Open drain or open source */
21+
#define GPIO_LINE_OPEN_SOURCE 0
22+
#define GPIO_LINE_OPEN_DRAIN 4
23+
2024
/*
21-
* Open Drain/Collector is the combination of single-ended active low,
22-
* Open Source/Emitter is the combination of single-ended active high.
25+
* Open Drain/Collector is the combination of single-ended open drain interface.
26+
* Open Source/Emitter is the combination of single-ended open source interface.
2327
*/
24-
#define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_ACTIVE_LOW)
25-
#define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_ACTIVE_HIGH)
28+
#define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN)
29+
#define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE)
2630

2731
#endif

include/linux/of_gpio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct device_node;
3030
enum of_gpio_flags {
3131
OF_GPIO_ACTIVE_LOW = 0x1,
3232
OF_GPIO_SINGLE_ENDED = 0x2,
33+
OF_GPIO_OPEN_DRAIN = 0x4,
3334
};
3435

3536
#ifdef CONFIG_OF_GPIO

0 commit comments

Comments
 (0)