* [PATCH v2 1/2] gpiolib: of: factor out quirk setting polarity via separate property
@ 2022-10-30 4:40 Dmitry Torokhov
2022-10-30 4:40 ` [PATCH v2 2/2] gpiolib: of: add polarity quirk for Freescale PCIe controller Dmitry Torokhov
2022-11-04 15:15 ` [PATCH v2 1/2] gpiolib: of: factor out quirk setting polarity via separate property Bartosz Golaszewski
0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2022-10-30 4:40 UTC (permalink / raw)
To: Bartosz Golaszewski, Linus Walleij; +Cc: linux-gpio, linux-kernel
Several legacy bindings use a separate property to specify polarity of
GPIOs instead of specifying it directly in the GPIO property. Factor
out this code to make it easier to add more such cases.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
v2: no changes
drivers/gpio/gpiolib-of.c | 98 +++++++++++++++++++++------------------
1 file changed, 53 insertions(+), 45 deletions(-)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 52616848a37c..331744c75faf 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -186,33 +186,68 @@ static void of_gpio_try_fixup_polarity(const struct device_node *np,
}
}
-static void of_gpio_flags_quirks(const struct device_node *np,
- const char *propname,
- enum of_gpio_flags *flags,
- int index)
+static void of_gpio_set_polarity_by_property(const struct device_node *np,
+ const char *propname,
+ enum of_gpio_flags *flags)
{
- of_gpio_try_fixup_polarity(np, propname, flags);
+ static const struct {
+ const char *compatible;
+ const char *gpio_propname;
+ const char *polarity_propname;
+ } gpios[] = {
+#if IS_ENABLED(CONFIG_FEC)
+ /* Freescale Fast Ethernet Controller */
+ { "fsl,imx25-fec", "phy-reset-gpios", "phy-reset-active-high" },
+ { "fsl,imx27-fec", "phy-reset-gpios", "phy-reset-active-high" },
+ { "fsl,imx28-fec", "phy-reset-gpios", "phy-reset-active-high" },
+ { "fsl,imx6q-fec", "phy-reset-gpios", "phy-reset-active-high" },
+ { "fsl,mvf600-fec", "phy-reset-gpios", "phy-reset-active-high" },
+ { "fsl,imx6sx-fec", "phy-reset-gpios", "phy-reset-active-high" },
+ { "fsl,imx6ul-fec", "phy-reset-gpios", "phy-reset-active-high" },
+ { "fsl,imx8mq-fec", "phy-reset-gpios", "phy-reset-active-high" },
+ { "fsl,imx8qm-fec", "phy-reset-gpios", "phy-reset-active-high" },
+ { "fsl,s32v234-fec", "phy-reset-gpios", "phy-reset-active-high" },
+#endif
- /*
- * Some GPIO fixed regulator quirks.
- * Note that active low is the default.
- */
- if (IS_ENABLED(CONFIG_REGULATOR) &&
- (of_device_is_compatible(np, "regulator-fixed") ||
- of_device_is_compatible(np, "reg-fixed-voltage") ||
- (!(strcmp(propname, "enable-gpio") &&
- strcmp(propname, "enable-gpios")) &&
- of_device_is_compatible(np, "regulator-gpio")))) {
- bool active_high = of_property_read_bool(np,
- "enable-active-high");
/*
* 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.
*/
- of_gpio_quirk_polarity(np, active_high, flags);
+#if IS_ENABLED(CONFIG_REGULATOR_FIXED_VOLTAGE)
+ { "regulator-fixed", "gpios", "enable-active-high" },
+ { "regulator-fixed", "gpio", "enable-active-high" },
+ { "reg-fixed-voltage", "gpios", "enable-active-high" },
+ { "reg-fixed-voltage", "gpio", "enable-active-high" },
+#endif
+#if IS_ENABLED(CONFIG_REGULATOR_GPIO)
+ { "regulator-gpio", "enable-gpio", "enable-active-high" },
+ { "regulator-gpio", "enable-gpios", "enable-active-high" },
+#endif
+ };
+ unsigned int i;
+ bool active_high;
+
+ for (i = 0; i < ARRAY_SIZE(gpios); i++) {
+ if (of_device_is_compatible(np, gpios[i].compatible) &&
+ !strcmp(propname, gpios[i].gpio_propname)) {
+ active_high = of_property_read_bool(np,
+ gpios[i].polarity_propname);
+ of_gpio_quirk_polarity(np, active_high, flags);
+ break;
+ }
}
+}
+
+static void of_gpio_flags_quirks(const struct device_node *np,
+ const char *propname,
+ enum of_gpio_flags *flags,
+ int index)
+{
+ of_gpio_try_fixup_polarity(np, propname, flags);
+ of_gpio_set_polarity_by_property(np, propname, flags);
+
/*
* Legacy open drain handling for fixed voltage regulators.
*/
@@ -267,33 +302,6 @@ static void of_gpio_flags_quirks(const struct device_node *np,
!strcmp(propname, "snps,reset-gpio") &&
of_property_read_bool(np, "snps,reset-active-low"))
*flags |= OF_GPIO_ACTIVE_LOW;
-
- /*
- * Freescale Fast Ethernet Controller uses a separate property to
- * describe polarity of the phy reset line.
- */
- if (IS_ENABLED(CONFIG_FEC)) {
- static const char * const fec_devices[] = {
- "fsl,imx25-fec",
- "fsl,imx27-fec",
- "fsl,imx28-fec",
- "fsl,imx6q-fec",
- "fsl,mvf600-fec",
- "fsl,imx6sx-fec",
- "fsl,imx6ul-fec",
- "fsl,imx8mq-fec",
- "fsl,imx8qm-fec",
- "fsl,s32v234-fec",
- NULL
- };
-
- if (!strcmp(propname, "phy-reset-gpios") &&
- of_device_compatible_match(np, fec_devices)) {
- bool active_high = of_property_read_bool(np,
- "phy-reset-active-high");
- of_gpio_quirk_polarity(np, active_high, flags);
- }
- }
}
/**
--
2.38.1.273.g43a17bfeac-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/2] gpiolib: of: add polarity quirk for Freescale PCIe controller
2022-10-30 4:40 [PATCH v2 1/2] gpiolib: of: factor out quirk setting polarity via separate property Dmitry Torokhov
@ 2022-10-30 4:40 ` Dmitry Torokhov
2022-11-04 15:15 ` [PATCH v2 1/2] gpiolib: of: factor out quirk setting polarity via separate property Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2022-10-30 4:40 UTC (permalink / raw)
To: Bartosz Golaszewski, Linus Walleij; +Cc: linux-gpio, linux-kernel
Bindings for Freescale PCIe controller use a separate property called
"reset-gpio-active-high" to control polarity of its reset line, add it
to the list of quirks in gpiolib so that gpiod API can be used in the
driver.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
v2: make it actually compile
drivers/gpio/gpiolib-of.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 331744c75faf..206100d62db5 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -208,6 +208,15 @@ static void of_gpio_set_polarity_by_property(const struct device_node *np,
{ "fsl,imx8qm-fec", "phy-reset-gpios", "phy-reset-active-high" },
{ "fsl,s32v234-fec", "phy-reset-gpios", "phy-reset-active-high" },
#endif
+#if IS_ENABLED(CONFIG_PCI_IMX6)
+ { "fsl,imx6q-pcie", "reset-gpio", "reset-gpio-active-high" },
+ { "fsl,imx6sx-pcie", "reset-gpio", "reset-gpio-active-high" },
+ { "fsl,imx6qp-pcie", "reset-gpio", "reset-gpio-active-high" },
+ { "fsl,imx7d-pcie", "reset-gpio", "reset-gpio-active-high" },
+ { "fsl,imx8mq-pcie", "reset-gpio", "reset-gpio-active-high" },
+ { "fsl,imx8mm-pcie", "reset-gpio", "reset-gpio-active-high" },
+ { "fsl,imx8mp-pcie", "reset-gpio", "reset-gpio-active-high" },
+#endif
/*
* The regulator GPIO handles are specified such that the
--
2.38.1.273.g43a17bfeac-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/2] gpiolib: of: factor out quirk setting polarity via separate property
2022-10-30 4:40 [PATCH v2 1/2] gpiolib: of: factor out quirk setting polarity via separate property Dmitry Torokhov
2022-10-30 4:40 ` [PATCH v2 2/2] gpiolib: of: add polarity quirk for Freescale PCIe controller Dmitry Torokhov
@ 2022-11-04 15:15 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2022-11-04 15:15 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: Linus Walleij, linux-gpio, linux-kernel
On Sun, Oct 30, 2022 at 5:40 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> Several legacy bindings use a separate property to specify polarity of
> GPIOs instead of specifying it directly in the GPIO property. Factor
> out this code to make it easier to add more such cases.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
Both patches applied, thanks!
Bartosz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-04 15:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-30 4:40 [PATCH v2 1/2] gpiolib: of: factor out quirk setting polarity via separate property Dmitry Torokhov
2022-10-30 4:40 ` [PATCH v2 2/2] gpiolib: of: add polarity quirk for Freescale PCIe controller Dmitry Torokhov
2022-11-04 15:15 ` [PATCH v2 1/2] gpiolib: of: factor out quirk setting polarity via separate property Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).