Commit a603a2b8 authored by Linus Walleij's avatar Linus Walleij

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: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 92542edc
...@@ -56,6 +56,42 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, ...@@ -56,6 +56,42 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
return gpiochip_get_desc(chip, ret); return gpiochip_get_desc(chip, ret);
} }
static void of_gpio_flags_quirks(struct device_node *np,
enum of_gpio_flags *flags)
{
/*
* Some GPIO fixed regulator quirks.
* Note that active low is the default.
*/
if (IS_ENABLED(CONFIG_REGULATOR) &&
(of_device_is_compatible(np, "reg-fixed-voltage") ||
of_device_is_compatible(np, "regulator-gpio"))) {
/*
* The regulator GPIO handles are specified such that the
* presence or absence of "enable-active-high" solely controls
* the polarity of the GPIO line. Any phandle flags must
* be actively ignored.
*/
if (*flags & OF_GPIO_ACTIVE_LOW) {
pr_warn("%s GPIO handle specifies active low - ignored\n",
of_node_full_name(np));
*flags &= ~OF_GPIO_ACTIVE_LOW;
}
if (!of_property_read_bool(np, "enable-active-high"))
*flags |= OF_GPIO_ACTIVE_LOW;
}
/*
* Legacy open drain handling for fixed voltage regulators.
*/
if (IS_ENABLED(CONFIG_REGULATOR) &&
of_device_is_compatible(np, "reg-fixed-voltage") &&
of_property_read_bool(np, "gpio-open-drain")) {
*flags |= (OF_GPIO_SINGLE_ENDED | OF_GPIO_OPEN_DRAIN);
pr_info("%s uses legacy open drain flag - update the DTS if you can\n",
of_node_full_name(np));
}
}
/** /**
* of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API
* @np: device node to get GPIO from * @np: device node to get GPIO from
...@@ -93,6 +129,8 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, ...@@ -93,6 +129,8 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
if (IS_ERR(desc)) if (IS_ERR(desc))
goto out; goto out;
of_gpio_flags_quirks(np, flags);
pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n",
__func__, propname, np, index, __func__, propname, np, index,
PTR_ERR_OR_ZERO(desc)); PTR_ERR_OR_ZERO(desc));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment