Skip to content

Commit a603a2b

Browse files
author
Linus Walleij
committed
gpio: of: Add special quirk to parse regulator flags
While most GPIOs are indicated to be active low or open drain using their twocell flags, we have legacy regulator bindings to take into account. Add a quirk respecting the special boolean active-high and open drain flags when parsing regulator nodes for GPIOs. This makes it possible to get rid of duplicated inversion semantics handling in the regulator core and any regulator drivers parsing and handling this separately. Unfortunately the old regulator inversion semantics are specified such that the presence or absence of "enable-active-high" solely controls the semantics, so we cannot deprecate this in favor of the phandle-provided inversion flag, instead any such phandle inversion flag provided in the second cell of a GPIO handle must be actively ignored, so we print a warning to contain the situation and make things easy for the users. Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 92542ed commit a603a2b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

drivers/gpio/gpiolib-of.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,42 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
5656
return gpiochip_get_desc(chip, ret);
5757
}
5858

59+
static void of_gpio_flags_quirks(struct device_node *np,
60+
enum of_gpio_flags *flags)
61+
{
62+
/*
63+
* Some GPIO fixed regulator quirks.
64+
* Note that active low is the default.
65+
*/
66+
if (IS_ENABLED(CONFIG_REGULATOR) &&
67+
(of_device_is_compatible(np, "reg-fixed-voltage") ||
68+
of_device_is_compatible(np, "regulator-gpio"))) {
69+
/*
70+
* The regulator GPIO handles are specified such that the
71+
* presence or absence of "enable-active-high" solely controls
72+
* the polarity of the GPIO line. Any phandle flags must
73+
* be actively ignored.
74+
*/
75+
if (*flags & OF_GPIO_ACTIVE_LOW) {
76+
pr_warn("%s GPIO handle specifies active low - ignored\n",
77+
of_node_full_name(np));
78+
*flags &= ~OF_GPIO_ACTIVE_LOW;
79+
}
80+
if (!of_property_read_bool(np, "enable-active-high"))
81+
*flags |= OF_GPIO_ACTIVE_LOW;
82+
}
83+
/*
84+
* Legacy open drain handling for fixed voltage regulators.
85+
*/
86+
if (IS_ENABLED(CONFIG_REGULATOR) &&
87+
of_device_is_compatible(np, "reg-fixed-voltage") &&
88+
of_property_read_bool(np, "gpio-open-drain")) {
89+
*flags |= (OF_GPIO_SINGLE_ENDED | OF_GPIO_OPEN_DRAIN);
90+
pr_info("%s uses legacy open drain flag - update the DTS if you can\n",
91+
of_node_full_name(np));
92+
}
93+
}
94+
5995
/**
6096
* of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API
6197
* @np: device node to get GPIO from
@@ -93,6 +129,8 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
93129
if (IS_ERR(desc))
94130
goto out;
95131

132+
of_gpio_flags_quirks(np, flags);
133+
96134
pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n",
97135
__func__, propname, np, index,
98136
PTR_ERR_OR_ZERO(desc));

0 commit comments

Comments
 (0)