Skip to content

Commit bf3692d

Browse files
ldewangancommodo
authored andcommitted
[backport] gpio: core: Decouple open drain/source flag with active low/high
[ upstream commit 4c0facd ("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 <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 5f79e44 commit bf3692d

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
@@ -3262,6 +3262,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
32623262
struct gpio_desc *desc = ERR_PTR(-ENODEV);
32633263
bool active_low = false;
32643264
bool single_ended = false;
3265+
bool open_drain = false;
32653266
int ret;
32663267

32673268
if (!fwnode)
@@ -3275,6 +3276,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
32753276
if (!IS_ERR(desc)) {
32763277
active_low = flags & OF_GPIO_ACTIVE_LOW;
32773278
single_ended = flags & OF_GPIO_SINGLE_ENDED;
3279+
open_drain = flags & OF_GPIO_OPEN_DRAIN;
32783280
}
32793281
} else if (is_acpi_node(fwnode)) {
32803282
struct acpi_gpio_info info;
@@ -3295,7 +3297,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
32953297
set_bit(FLAG_ACTIVE_LOW, &desc->flags);
32963298

32973299
if (single_ended) {
3298-
if (active_low)
3300+
if (open_drain)
32993301
set_bit(FLAG_OPEN_DRAIN, &desc->flags);
33003302
else
33013303
set_bit(FLAG_OPEN_SOURCE, &desc->flags);

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)