In preparation to converting several drivers to gpiod API, and to keep
existing DTS working, this series adds additional quirks to locate
gpio lines with legacy names.
Additionally the quirk handling has been reworked (once again) to pull
all simple renames (ones that do not involve change of indices or other
complex manipulations) into a single quirk with a table containing
transformations. This should make adding new quirks easier.
When using legacy names gpiolib will emit a message to nudge users to
update DTSes (when possible).
Note that the last patch requires the following change from the OF tree:
88269151be67 ("of: base: make of_device_compatible_match() accept const device node")
The change is also available in mainline - it has been merged in 6.1
merge window.
Thanks.
To: Linus Walleij <[email protected]>
To: Bartosz Golaszewski <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Alexander Stein <[email protected]>
Cc: Daniel Thompson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Changes in v2:
- fixed 'fsl,imx8mq-fec' & 'fsl,imx8qm-fec' compatibles issue noticed
by Alexander Stein
- implemented Daniel Thompson's suggestion on tightening configs
selecting renaming quirks and added a comment to discourage adding
rename quirks without checks for specific compatible(s)
- added a polarity quirk for Himax LCDs
- collected reviewed-by tags
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Dmitry Torokhov (9):
gpiolib: of: add a quirk for legacy names in Mediatek mt2701-cs42448
gpiolib: of: consolidate simple renames into a single quirk
gpiolib: of: tighten selection of gpio renaming quirks
gpiolib: of: add quirk for locating reset lines with legacy bindings
gpiolib: of: add a quirk for reset line for Marvell NFC controller
gpiolib: of: add a quirk for reset line for Cirrus CS42L56 codec
gpiolib: of: factor out code overriding gpio line polarity
gpiolib: of: add quirk for phy reset polarity for Freescale Ethernet
gpiolib: of: add a quirk for reset line polarity for Himax LCDs
drivers/gpio/gpiolib-of.c | 344 ++++++++++++++++++++++++++++++----------------
1 file changed, 222 insertions(+), 122 deletions(-)
---
base-commit: cd9fd78f5c11b5e165d9317ef11e613f4aef4dd1
change-id: 20221011-gpiolib-quirks-d452ed31d24e
Best regards,
Dmitry
Some legacy mappings used "gpio[s]-reset" instead of "reset-gpios",
add a quirk so that gpiod API will still work on unmodified DTSes.
Reviewed-by: Daniel Thompson <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 7d4bbf6484bc..2b5d1b3095c7 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -382,9 +382,18 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
*/
const char *compatible;
} gpios[] = {
+#if !IS_ENABLED(CONFIG_LCD_HX8357)
+ /* Himax LCD controllers used "gpios-reset" */
+ { "reset", "gpios-reset", "himax,hx8357" },
+ { "reset", "gpios-reset", "himax,hx8369" },
+#endif
#if IS_ENABLED(CONFIG_MFD_ARIZONA)
{ "wlf,reset", NULL, NULL },
#endif
+#if !IS_ENABLED(CONFIG_PCI_LANTIQ)
+ /* MIPS Lantiq PCI */
+ { "reset", "gpios-reset", "lantiq,pci-xway" },
+#endif
/*
* Some regulator bindings happened before we managed to
@@ -399,6 +408,13 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
{ "wlf,ldo2ena", NULL, NULL }, /* WM8994 */
#endif
+#if IS_ENABLED(CONFIG_SND_SOC_TLV320AIC3X)
+ { "reset", "gpio-reset", "ti,tlv320aic3x" },
+ { "reset", "gpio-reset", "ti,tlv320aic33" },
+ { "reset", "gpio-reset", "ti,tlv320aic3007" },
+ { "reset", "gpio-reset", "ti,tlv320aic3104" },
+ { "reset", "gpio-reset", "ti,tlv320aic3106" },
+#endif
#if IS_ENABLED(CONFIG_SPI_GPIO)
/*
* The SPI GPIO bindings happened before we managed to
--
b4 0.11.0-dev-5166b
The controller is using non-standard "cirrus,gpio-nreset" name for its
reset gpio property, whereas gpiod API expects "<name>-gpios".
Add a quirk so that gpiod API will still work on unmodified DTSes.
Reviewed-by: Daniel Thompson <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 5c11ee7638d1..77cabcfb2da0 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -418,6 +418,9 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
{ "wlf,ldo2ena", NULL, NULL }, /* WM8994 */
#endif
+#if IS_ENABLED(CONFIG_SND_SOC_CS42L56)
+ { "reset", "cirrus,gpio-nreset", "cirrus,cs42l56" },
+#endif
#if IS_ENABLED(CONFIG_SND_SOC_TLV320AIC3X)
{ "reset", "gpio-reset", "ti,tlv320aic3x" },
{ "reset", "gpio-reset", "ti,tlv320aic33" },
--
b4 0.11.0-dev-5166b
Tighten selection of legacy gpio renaming quirks so that they only
considered on more relevant configurations.
Suggested-by: Daniel Thompson <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 63c6fa3086f3..7d4bbf6484bc 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -385,18 +385,21 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
#if IS_ENABLED(CONFIG_MFD_ARIZONA)
{ "wlf,reset", NULL, NULL },
#endif
-#if IS_ENABLED(CONFIG_REGULATOR)
+
/*
* Some regulator bindings happened before we managed to
* establish that GPIO properties should be named
* "foo-gpios" so we have this special kludge for them.
*/
+#if IS_ENABLED(CONFIG_REGULATOR_ARIZONA_LDO1)
{ "wlf,ldoena", NULL, NULL }, /* Arizona */
+#endif
+#if IS_ENABLED(CONFIG_REGULATOR_WM8994)
{ "wlf,ldo1ena", NULL, NULL }, /* WM8994 */
{ "wlf,ldo2ena", NULL, NULL }, /* WM8994 */
#endif
-#if IS_ENABLED(CONFIG_SPI_MASTER)
+#if IS_ENABLED(CONFIG_SPI_GPIO)
/*
* The SPI GPIO bindings happened before we managed to
* establish that GPIO properties should be named
@@ -405,6 +408,7 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
{ "miso", "gpio-miso", "spi-gpio" },
{ "mosi", "gpio-mosi", "spi-gpio" },
{ "sck", "gpio-sck", "spi-gpio" },
+#endif
/*
* The old Freescale bindings use simply "gpios" as name
@@ -412,10 +416,14 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
* all other SPI hardware. Allow this specifically for
* Freescale and PPC devices.
*/
+#if IS_ENABLED(CONFIG_SPI_FSL_SPI)
{ "cs", "gpios", "fsl,spi" },
{ "cs", "gpios", "aeroflexgaisler,spictrl" },
+#endif
+#if IS_ENABLED(CONFIG_SPI_PPC4xx)
{ "cs", "gpios", "ibm,ppc4xx-spi" },
#endif
+
#if IS_ENABLED(CONFIG_TYPEC_FUSB302)
/*
* Fairchild FUSB302 host is using undocumented "fcs,int_n"
--
b4 0.11.0-dev-5166b
Existing DTS that use legacy (non-standard) property name for the reset
line "gpios-reset" also specify incorrect polarity (0 which maps to
"active high"). Add a quirk to force polarity to "active low" so that
once driver is converted to gpiod API that pays attention to line
polarity it will work properly.
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 805222a2e6bc..26d57465fec9 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -152,11 +152,47 @@ static void of_gpio_quirk_polarity(const struct device_node *np,
}
}
+/*
+ * This quirk does static polarity overrides in cases where existing
+ * DTS specified incorrect polarity.
+ */
+static void of_gpio_try_fixup_polarity(const struct device_node *np,
+ const char *propname,
+ enum of_gpio_flags *flags)
+{
+ static const struct {
+ const char *compatible;
+ const char *propname;
+ bool active_high;
+ } gpios[] = {
+#if !IS_ENABLED(CONFIG_LCD_HX8357)
+ /*
+ * Himax LCD controllers used incorrectly named
+ * "gpios-reset" property and also specified wrong
+ * polarity.
+ */
+ { "himax,hx8357", "gpios-reset", false },
+ { "himax,hx8369", "gpios-reset", false },
+#endif
+ };
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(gpios); i++) {
+ if (of_device_is_compatible(np, gpios[i].compatible) &&
+ !strcmp(propname, gpios[i].propname)) {
+ of_gpio_quirk_polarity(np, gpios[i].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);
+
/*
* Some GPIO fixed regulator quirks.
* Note that active low is the default.
--
b4 0.11.0-dev-5166b
There are several instances where we use a separate property to
override polarity specified in gpio property. Factor it out into
a separate function.
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 48 +++++++++++++++++++++++++++--------------------
1 file changed, 28 insertions(+), 20 deletions(-)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 77cabcfb2da0..da274d9adcdf 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -130,6 +130,28 @@ bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
return false;
}
+/*
+ * Overrides stated polarity of a gpio line and warns when there is a
+ * discrepancy.
+ */
+static void of_gpio_quirk_polarity(const struct device_node *np,
+ bool active_high,
+ enum of_gpio_flags *flags)
+{
+ if (active_high) {
+ 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;
+ }
+ } else {
+ if (!(*flags & OF_GPIO_ACTIVE_LOW))
+ pr_info("%s enforce active low on GPIO handle\n",
+ of_node_full_name(np));
+ *flags |= OF_GPIO_ACTIVE_LOW;
+ }
+}
+
static void of_gpio_flags_quirks(const struct device_node *np,
const char *propname,
enum of_gpio_flags *flags,
@@ -145,7 +167,7 @@ static void of_gpio_flags_quirks(const struct device_node *np,
(!(strcmp(propname, "enable-gpio") &&
strcmp(propname, "enable-gpios")) &&
of_device_is_compatible(np, "regulator-gpio")))) {
- bool active_low = !of_property_read_bool(np,
+ bool active_high = of_property_read_bool(np,
"enable-active-high");
/*
* The regulator GPIO handles are specified such that the
@@ -153,13 +175,7 @@ static void of_gpio_flags_quirks(const struct device_node *np,
* the polarity of the GPIO line. Any phandle flags must
* be actively ignored.
*/
- if ((*flags & OF_GPIO_ACTIVE_LOW) && !active_low) {
- pr_warn("%s GPIO handle specifies active low - ignored\n",
- of_node_full_name(np));
- *flags &= ~OF_GPIO_ACTIVE_LOW;
- }
- if (active_low)
- *flags |= OF_GPIO_ACTIVE_LOW;
+ of_gpio_quirk_polarity(np, active_high, flags);
}
/*
* Legacy open drain handling for fixed voltage regulators.
@@ -200,18 +216,10 @@ static void of_gpio_flags_quirks(const struct device_node *np,
* conflict and the "spi-cs-high" flag will
* take precedence.
*/
- if (of_property_read_bool(child, "spi-cs-high")) {
- if (*flags & OF_GPIO_ACTIVE_LOW) {
- pr_warn("%s GPIO handle specifies active low - ignored\n",
- of_node_full_name(child));
- *flags &= ~OF_GPIO_ACTIVE_LOW;
- }
- } else {
- if (!(*flags & OF_GPIO_ACTIVE_LOW))
- pr_info("%s enforce active low on chipselect handle\n",
- of_node_full_name(child));
- *flags |= OF_GPIO_ACTIVE_LOW;
- }
+ bool active_high = of_property_read_bool(child,
+ "spi-cs-high");
+ of_gpio_quirk_polarity(child, active_high,
+ flags);
of_node_put(child);
break;
}
--
b4 0.11.0-dev-5166b
This consolidates all quirks doing simple renames (either allowing
suffix-less names or trivial renames, when index changes are not
required) into a single quirk.
Reviewed-by: Daniel Thompson <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 183 ++++++++++++++++++----------------------------
1 file changed, 71 insertions(+), 112 deletions(-)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index cef4f6634125..63c6fa3086f3 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -365,127 +365,90 @@ struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
}
EXPORT_SYMBOL_GPL(gpiod_get_from_of_node);
-/*
- * The SPI GPIO bindings happened before we managed to establish that GPIO
- * properties should be named "foo-gpios" so we have this special kludge for
- * them.
- */
-static struct gpio_desc *of_find_spi_gpio(struct device_node *np,
- const char *con_id,
- unsigned int idx,
- enum of_gpio_flags *of_flags)
-{
- char prop_name[32]; /* 32 is max size of property name */
-
- /*
- * Hopefully the compiler stubs the rest of the function if this
- * is false.
- */
- if (!IS_ENABLED(CONFIG_SPI_MASTER))
- return ERR_PTR(-ENOENT);
-
- /* Allow this specifically for "spi-gpio" devices */
- if (!of_device_is_compatible(np, "spi-gpio") || !con_id)
- return ERR_PTR(-ENOENT);
-
- /* Will be "gpio-sck", "gpio-mosi" or "gpio-miso" */
- snprintf(prop_name, sizeof(prop_name), "%s-%s", "gpio", con_id);
-
- return of_get_named_gpiod_flags(np, prop_name, idx, of_flags);
-}
-
-/*
- * The old Freescale bindings use simply "gpios" as name for the chip select
- * lines rather than "cs-gpios" like all other SPI hardware. Account for this
- * with a special quirk.
- */
-static struct gpio_desc *of_find_spi_cs_gpio(struct device_node *np,
+static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
const char *con_id,
unsigned int idx,
enum of_gpio_flags *of_flags)
{
- if (!IS_ENABLED(CONFIG_SPI_MASTER))
- return ERR_PTR(-ENOENT);
-
- /* Allow this specifically for Freescale and PPC devices */
- if (!of_device_is_compatible(np, "fsl,spi") &&
- !of_device_is_compatible(np, "aeroflexgaisler,spictrl") &&
- !of_device_is_compatible(np, "ibm,ppc4xx-spi"))
- return ERR_PTR(-ENOENT);
- /* Allow only if asking for "cs-gpios" */
- if (!con_id || strcmp(con_id, "cs"))
- return ERR_PTR(-ENOENT);
+ static const struct of_rename_gpio {
+ const char *con_id;
+ const char *legacy_id; /* NULL - same as con_id */
+ /*
+ * Compatible string can be set to NULL in case where
+ * matching to a particular compatible is not practical,
+ * but it should only be done for gpio names that have
+ * vendor prefix to reduce risk of false positives.
+ * Addition of such entries is strongly discouraged.
+ */
+ const char *compatible;
+ } gpios[] = {
+#if IS_ENABLED(CONFIG_MFD_ARIZONA)
+ { "wlf,reset", NULL, NULL },
+#endif
+#if IS_ENABLED(CONFIG_REGULATOR)
+ /*
+ * Some regulator bindings happened before we managed to
+ * establish that GPIO properties should be named
+ * "foo-gpios" so we have this special kludge for them.
+ */
+ { "wlf,ldoena", NULL, NULL }, /* Arizona */
+ { "wlf,ldo1ena", NULL, NULL }, /* WM8994 */
+ { "wlf,ldo2ena", NULL, NULL }, /* WM8994 */
+#endif
+#if IS_ENABLED(CONFIG_SPI_MASTER)
- /*
- * While all other SPI controllers use "cs-gpios" the Freescale
- * uses just "gpios" so translate to that when "cs-gpios" is
- * requested.
- */
- return of_get_named_gpiod_flags(np, "gpios", idx, of_flags);
-}
+ /*
+ * The SPI GPIO bindings happened before we managed to
+ * establish that GPIO properties should be named
+ * "foo-gpios" so we have this special kludge for them.
+ */
+ { "miso", "gpio-miso", "spi-gpio" },
+ { "mosi", "gpio-mosi", "spi-gpio" },
+ { "sck", "gpio-sck", "spi-gpio" },
-/*
- * Some regulator bindings happened before we managed to establish that GPIO
- * properties should be named "foo-gpios" so we have this special kludge for
- * them.
- */
-static struct gpio_desc *of_find_regulator_gpio(struct device_node *np,
- const char *con_id,
- unsigned int idx,
- enum of_gpio_flags *of_flags)
-{
- /* These are the connection IDs we accept as legacy GPIO phandles */
- const char *whitelist[] = {
- "wlf,ldoena", /* Arizona */
- "wlf,ldo1ena", /* WM8994 */
- "wlf,ldo2ena", /* WM8994 */
+ /*
+ * The old Freescale bindings use simply "gpios" as name
+ * for the chip select lines rather than "cs-gpios" like
+ * all other SPI hardware. Allow this specifically for
+ * Freescale and PPC devices.
+ */
+ { "cs", "gpios", "fsl,spi" },
+ { "cs", "gpios", "aeroflexgaisler,spictrl" },
+ { "cs", "gpios", "ibm,ppc4xx-spi" },
+#endif
+#if IS_ENABLED(CONFIG_TYPEC_FUSB302)
+ /*
+ * Fairchild FUSB302 host is using undocumented "fcs,int_n"
+ * property without the compulsory "-gpios" suffix.
+ */
+ { "fcs,int_n", NULL, "fcs,fusb302" },
+#endif
};
- int i;
-
- if (!IS_ENABLED(CONFIG_REGULATOR))
- return ERR_PTR(-ENOENT);
+ struct gpio_desc *desc;
+ const char *legacy_id;
+ unsigned int i;
if (!con_id)
return ERR_PTR(-ENOENT);
- i = match_string(whitelist, ARRAY_SIZE(whitelist), con_id);
- if (i < 0)
- return ERR_PTR(-ENOENT);
-
- return of_get_named_gpiod_flags(np, con_id, idx, of_flags);
-}
-
-static struct gpio_desc *of_find_arizona_gpio(struct device_node *np,
- const char *con_id,
- unsigned int idx,
- enum of_gpio_flags *of_flags)
-{
- if (!IS_ENABLED(CONFIG_MFD_ARIZONA))
- return ERR_PTR(-ENOENT);
-
- if (!con_id || strcmp(con_id, "wlf,reset"))
- return ERR_PTR(-ENOENT);
-
- return of_get_named_gpiod_flags(np, con_id, idx, of_flags);
-}
+ for (i = 0; i < ARRAY_SIZE(gpios); i++) {
+ if (strcmp(con_id, gpios[i].con_id))
+ continue;
-static struct gpio_desc *of_find_usb_gpio(struct device_node *np,
- const char *con_id,
- unsigned int idx,
- enum of_gpio_flags *of_flags)
-{
- /*
- * Currently this USB quirk is only for the Fairchild FUSB302 host
- * which is using an undocumented DT GPIO line named "fcs,int_n"
- * without the compulsory "-gpios" suffix.
- */
- if (!IS_ENABLED(CONFIG_TYPEC_FUSB302))
- return ERR_PTR(-ENOENT);
+ if (gpios[i].compatible &&
+ !of_device_is_compatible(np, gpios[i].compatible))
+ continue;
- if (!con_id || strcmp(con_id, "fcs,int_n"))
- return ERR_PTR(-ENOENT);
+ legacy_id = gpios[i].legacy_id ?: gpios[i].con_id;
+ desc = of_get_named_gpiod_flags(np, legacy_id, idx, of_flags);
+ if (!gpiod_not_found(desc)) {
+ pr_info("%s uses legacy gpio name '%s' instead of '%s-gpios'\n",
+ of_node_full_name(np), legacy_id, con_id);
+ return desc;
+ }
+ }
- return of_get_named_gpiod_flags(np, con_id, idx, of_flags);
+ return ERR_PTR(-ENOENT);
}
static struct gpio_desc *of_find_mt2701_gpio(struct device_node *np,
@@ -525,11 +488,7 @@ typedef struct gpio_desc *(*of_find_gpio_quirk)(struct device_node *np,
unsigned int idx,
enum of_gpio_flags *of_flags);
static const of_find_gpio_quirk of_find_gpio_quirks[] = {
- of_find_spi_gpio,
- of_find_spi_cs_gpio,
- of_find_regulator_gpio,
- of_find_arizona_gpio,
- of_find_usb_gpio,
+ of_find_gpio_rename,
of_find_mt2701_gpio,
NULL
};
--
b4 0.11.0-dev-5166b
The driver is using non-standard "i2s1-in-sel-gpio1" and
"i2s1-in-sel-gpio2" names to describe its gpios. In preparation to
converting to the standard naming (i2s1-in-sel-gpios) and switching the
driver to gpiod API add a quirk to gpiolib to keep compatibility with
existing DTSes.
Reviewed-by: Daniel Thompson <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 0e4e1291604d..cef4f6634125 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -488,6 +488,38 @@ static struct gpio_desc *of_find_usb_gpio(struct device_node *np,
return of_get_named_gpiod_flags(np, con_id, idx, of_flags);
}
+static struct gpio_desc *of_find_mt2701_gpio(struct device_node *np,
+ const char *con_id,
+ unsigned int idx,
+ enum of_gpio_flags *of_flags)
+{
+ struct gpio_desc *desc;
+ const char *legacy_id;
+
+ if (!IS_ENABLED(CONFIG_SND_SOC_MT2701_CS42448))
+ return ERR_PTR(-ENOENT);
+
+ if (!of_device_is_compatible(np, "mediatek,mt2701-cs42448-machine"))
+ return ERR_PTR(-ENOENT);
+
+ if (!con_id || strcmp(con_id, "i2s1-in-sel"))
+ return ERR_PTR(-ENOENT);
+
+ if (idx == 0)
+ legacy_id = "i2s1-in-sel-gpio1";
+ else if (idx == 1)
+ legacy_id = "i2s1-in-sel-gpio2";
+ else
+ return ERR_PTR(-ENOENT);
+
+ desc = of_get_named_gpiod_flags(np, legacy_id, 0, of_flags);
+ if (!gpiod_not_found(desc))
+ pr_info("%s is using legacy gpio name '%s' instead of '%s-gpios'\n",
+ of_node_full_name(np), legacy_id, con_id);
+
+ return desc;
+}
+
typedef struct gpio_desc *(*of_find_gpio_quirk)(struct device_node *np,
const char *con_id,
unsigned int idx,
@@ -498,6 +530,7 @@ static const of_find_gpio_quirk of_find_gpio_quirks[] = {
of_find_regulator_gpio,
of_find_arizona_gpio,
of_find_usb_gpio,
+ of_find_mt2701_gpio,
NULL
};
--
b4 0.11.0-dev-5166b
The controller is using non-standard "reset-n-io" name for its reset
gpio property, whereas gpiod API expects "<name>-gpios". Add a quirk
so that gpiod API will still work on unmodified DTSes.
Reviewed-by: Daniel Thompson <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 2b5d1b3095c7..5c11ee7638d1 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -390,6 +390,16 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
#if IS_ENABLED(CONFIG_MFD_ARIZONA)
{ "wlf,reset", NULL, NULL },
#endif
+
+#if IS_ENABLED(CONFIG_NFC_MRVL_I2C)
+ { "reset", "reset-n-io", "marvell,nfc-i2c" },
+#endif
+#if IS_ENABLED(CONFIG_NFC_MRVL_SPI)
+ { "reset", "reset-n-io", "marvell,nfc-spi" },
+#endif
+#if IS_ENABLED(CONFIG_NFC_MRVL_UART)
+ { "reset", "reset-n-io", "marvell,nfc-uart" },
+#endif
#if !IS_ENABLED(CONFIG_PCI_LANTIQ)
/* MIPS Lantiq PCI */
{ "reset", "gpios-reset", "lantiq,pci-xway" },
--
b4 0.11.0-dev-5166b
Bindings for Freescale Fast Ethernet Controller use a separate
property "phy-reset-active-high" to specify polarity of its phy
gpio line. To allow converting the driver to gpiod API we need
to add this quirk to gpiolib.
Signed-off-by: Dmitry Torokhov <[email protected]>
---
drivers/gpio/gpiolib-of.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index da274d9adcdf..805222a2e6bc 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -231,6 +231,33 @@ 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);
+ }
+ }
}
/**
--
b4 0.11.0-dev-5166b
On Fri, Oct 14, 2022 at 10:54:27AM -0700, Dmitry Torokhov wrote:
> Tighten selection of legacy gpio renaming quirks so that they only
> considered on more relevant configurations.
>
> Suggested-by: Daniel Thompson <[email protected]>
> Signed-off-by: Dmitry Torokhov <[email protected]>
Reviewed-by: Daniel Thompson <[email protected]>
Daniel.
On Fri, Oct 14, 2022 at 10:54:29AM -0700, Dmitry Torokhov wrote:
> The controller is using non-standard "reset-n-io" name for its reset
> gpio property, whereas gpiod API expects "<name>-gpios". Add a quirk
> so that gpiod API will still work on unmodified DTSes.
>
> Reviewed-by: Daniel Thompson <[email protected]>
> Signed-off-by: Dmitry Torokhov <[email protected]>
> ---
> drivers/gpio/gpiolib-of.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index 2b5d1b3095c7..5c11ee7638d1 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -390,6 +390,16 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
> #if IS_ENABLED(CONFIG_MFD_ARIZONA)
> { "wlf,reset", NULL, NULL },
> #endif
> +
> +#if IS_ENABLED(CONFIG_NFC_MRVL_I2C)
> + { "reset", "reset-n-io", "marvell,nfc-i2c" },
> +#endif
> +#if IS_ENABLED(CONFIG_NFC_MRVL_SPI)
> + { "reset", "reset-n-io", "marvell,nfc-spi" },
> +#endif
> +#if IS_ENABLED(CONFIG_NFC_MRVL_UART)
> + { "reset", "reset-n-io", "marvell,nfc-uart" },
I just noticed that there is another compatible (not documented, so I
assume it is a legacy one): "mrvl,nfc-uart", so I will be adding it and
sending another version.
Thanks.
--
Dmitry
On Fri, Oct 14, 2022 at 7:54 PM Dmitry Torokhov
<[email protected]> wrote:
> In preparation to converting several drivers to gpiod API, and to keep
> existing DTS working, this series adds additional quirks to locate
> gpio lines with legacy names.
>
> Additionally the quirk handling has been reworked (once again) to pull
> all simple renames (ones that do not involve change of indices or other
> complex manipulations) into a single quirk with a table containing
> transformations. This should make adding new quirks easier.
> When using legacy names gpiolib will emit a message to nudge users to
> update DTSes (when possible).
>
> Note that the last patch requires the following change from the OF tree:
>
> 88269151be67 ("of: base: make of_device_compatible_match() accept const device node")
>
> The change is also available in mainline - it has been merged in 6.1
> merge window.
The series:
Reviewed-by: Linus Walleij <[email protected]>
Yours.
Linus Walleij