Merge tag 'gpio-v5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux...
[sfrench/cifs-2.6.git] / drivers / gpio / gpiolib-of.c
index 9c9b965d7d6dbcbc2ba0f11f16245d0b113ead70..f974075ff00e77debf8c8247aa280d7270343743 100644 (file)
@@ -165,6 +165,12 @@ static void of_gpio_flags_quirks(struct device_node *np,
                        }
                }
        }
+
+       /* Legacy handling of stmmac's active-low PHY reset line */
+       if (IS_ENABLED(CONFIG_STMMAC_ETH) &&
+           !strcmp(propname, "snps,reset-gpio") &&
+           of_property_read_bool(np, "snps,reset-active-low"))
+               *flags |= OF_GPIO_ACTIVE_LOW;
 }
 
 /**
@@ -261,6 +267,37 @@ static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id
        return desc;
 }
 
+/*
+ * 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 *dev,
+                                            const char *con_id,
+                                            unsigned int idx,
+                                            unsigned long *flags)
+{
+       struct device_node *np = dev->of_node;
+
+       if (!IS_ENABLED(CONFIG_SPI_MASTER))
+               return ERR_PTR(-ENOENT);
+
+       /* Allow this specifically for Freescale devices */
+       if (!of_device_is_compatible(np, "fsl,spi") &&
+           !of_device_is_compatible(np, "aeroflexgaisler,spictrl"))
+               return ERR_PTR(-ENOENT);
+       /* Allow only if asking for "cs-gpios" */
+       if (!con_id || strcmp(con_id, "cs"))
+               return ERR_PTR(-ENOENT);
+
+       /*
+        * While all other SPI controllers use "cs-gpios" the Freescale
+        * uses just "gpios" so translate to that when "cs-gpios" is
+        * requested.
+        */
+       return of_find_gpio(dev, NULL, idx, flags);
+}
+
 /*
  * Some regulator bindings happened before we managed to establish that GPIO
  * properties should be named "foo-gpios" so we have this special kludge for
@@ -332,6 +369,12 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
        /* Special handling for SPI GPIOs if used */
        if (IS_ERR(desc))
                desc = of_find_spi_gpio(dev, con_id, &of_flags);
+       if (IS_ERR(desc)) {
+               /* This quirk looks up flags and all */
+               desc = of_find_spi_cs_gpio(dev, con_id, idx, flags);
+               if (!IS_ERR(desc))
+                       return desc;
+       }
 
        /* Special handling for regulator GPIOs if used */
        if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER)