diff mbox series

[v3,1/1] of: Fix gpios supplier parsing

Message ID 20201126014716.34545-2-damien.lemoal@wdc.com
State Changes Requested
Headers show
Series Fix dwapb gpio snps,nr-gpios property handling | expand

Checks

Context Check Description
robh/checkpatch success

Commit Message

Damien Le Moal Nov. 26, 2020, 1:47 a.m. UTC
The DesignWare gpio-dwapb GPIO driver ("snps,dw-apb-gpio" or
"apm,xgene-gpio-v2" compatible string) defines the now deprecated
property "snps,nr-gpios" to specify the number of GPIOs available
on a port. However, if this property is used in a device tree, its
"-gpios" suffix causes the generic property supplier parsing code to
interpret it as a cell reference when properties are parsed in
of_link_to_suppliers(), leading to an error messages such as:

OF: /soc/bus@50200000/gpio-controller@50200000/gpio-port@0: could not
find phandle

As this deprecated property is still present in many device trees, fix
this problem by manually defining a parse_gpios() instead of using the
DEFINE_SUFFIX_PROP() macro. This new parsing function issues a warning
and then ignores the deprecated property, skipping the phandle parsing
and thus avoiding the device tree parsing error.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/of/property.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 408a7b5f06a9..304459add299 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1308,7 +1308,6 @@  DEFINE_SIMPLE_PROP(pinctrl7, "pinctrl-7", NULL)
 DEFINE_SIMPLE_PROP(pinctrl8, "pinctrl-8", NULL)
 DEFINE_SUFFIX_PROP(regulators, "-supply", NULL)
 DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
-DEFINE_SUFFIX_PROP(gpios, "-gpios", "#gpio-cells")
 
 static struct device_node *parse_iommu_maps(struct device_node *np,
 					    const char *prop_name, int index)
@@ -1319,6 +1318,25 @@  static struct device_node *parse_iommu_maps(struct device_node *np,
 	return of_parse_phandle(np, prop_name, (index * 4) + 1);
 }
 
+static struct device_node *parse_gpios(struct device_node *np,
+				       const char *prop_name, int index)
+{
+	/*
+	 * Quirk for the deprecated "snps,nr-gpios" property of the
+	 * DesignWare gpio-dwapb GPIO driver: as this property parsing
+	 * conflicts with the "xx-gpios" phandle reference property,
+	 * issue a warning and ignore it.
+	 */
+	if (strcmp(prop_name, "snps,nr-gpios") == 0) {
+		pr_warn("%pOF: \"snps,nr-gpios\" property is deprecated in favor of \"ngpios\"\n",
+			np);
+		return NULL;
+	}
+
+	return parse_suffix_prop_cells(np, prop_name, index,
+				       "-gpios", "#gpio-cells");
+}
+
 static const struct supplier_bindings of_supplier_bindings[] = {
 	{ .parse_prop = parse_clocks, },
 	{ .parse_prop = parse_interconnects, },