Skip to content

Commit 89a5e15

Browse files
committed
gpio/mmc/of: Respect polarity in the device tree
The device tree bindings for the MMC card detect and write protect lines specify that these should be active low unless "cd-inverted" or "wp-inverted" has been specified. However that is not how the kernel code has worked. It has always respected the flags passed to the phandle in the device tree, but respected the "cd-inverted" and "wp-inverted" flags such that if those are set, the polarity will be the inverse of that specified in the device tree. Switch to behaving like the old code did and fix the regression. Fixes: 81c85ec ("gpio: OF: Parse MMC-specific CD and WP properties") Cc: Bartosz Golaszewski <[email protected]> Cc: Guenter Roeck <[email protected]> Reported-by: Guenter Roeck <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 12d6dd0 commit 89a5e15

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

drivers/gpio/gpiolib-of.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,46 +54,29 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
5454
}
5555

5656
static void of_gpio_flags_quirks(struct device_node *np,
57+
const char *propname,
5758
enum of_gpio_flags *flags,
5859
int index)
5960
{
6061
/*
6162
* Handle MMC "cd-inverted" and "wp-inverted" semantics.
6263
*/
6364
if (IS_ENABLED(CONFIG_MMC)) {
64-
if (of_property_read_bool(np, "cd-gpios")) {
65-
if (of_property_read_bool(np, "cd-inverted")) {
66-
if (*flags & OF_GPIO_ACTIVE_LOW) {
67-
/* "cd-inverted" takes precedence */
68-
*flags &= ~OF_GPIO_ACTIVE_LOW;
69-
pr_warn("%s GPIO handle specifies CD active low - ignored\n",
70-
of_node_full_name(np));
71-
}
72-
} else {
73-
/*
74-
* Active low is the default according to the
75-
* SDHCI specification. If the GPIO handle
76-
* specifies the same thing - good.
77-
*/
78-
*flags |= OF_GPIO_ACTIVE_LOW;
79-
}
65+
/*
66+
* Active low is the default according to the
67+
* SDHCI specification and the device tree
68+
* bindings. However the code in the current
69+
* kernel was written such that the phandle
70+
* flags were always respected, and "cd-inverted"
71+
* would invert the flag from the device phandle.
72+
*/
73+
if (!strcmp(propname, "cd-gpios")) {
74+
if (of_property_read_bool(np, "cd-inverted"))
75+
*flags ^= OF_GPIO_ACTIVE_LOW;
8076
}
81-
if (of_property_read_bool(np, "wp-gpios")) {
82-
if (of_property_read_bool(np, "wp-inverted")) {
83-
/* "wp-inverted" takes precedence */
84-
if (*flags & OF_GPIO_ACTIVE_LOW) {
85-
*flags &= ~OF_GPIO_ACTIVE_LOW;
86-
pr_warn("%s GPIO handle specifies WP active low - ignored\n",
87-
of_node_full_name(np));
88-
}
89-
} else {
90-
/*
91-
* Active low is the default according to the
92-
* SDHCI specification. If the GPIO handle
93-
* specifies the same thing - good.
94-
*/
95-
*flags |= OF_GPIO_ACTIVE_LOW;
96-
}
77+
if (!strcmp(propname, "wp-gpios")) {
78+
if (of_property_read_bool(np, "wp-inverted"))
79+
*flags ^= OF_GPIO_ACTIVE_LOW;
9780
}
9881
}
9982
/*
@@ -213,7 +196,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
213196
goto out;
214197

215198
if (flags)
216-
of_gpio_flags_quirks(np, flags, index);
199+
of_gpio_flags_quirks(np, propname, flags, index);
217200

218201
pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n",
219202
__func__, propname, np, index,

0 commit comments

Comments
 (0)