aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2017-12-27 10:37:44 -0500
committerLinus Walleij <linus.walleij@linaro.org>2018-01-08 11:29:25 -0500
commitc85823390215e52d68d3826df92a447ed31e5c80 (patch)
treef55b031e90ed59b7939d40f7a898103de043ab4d
parent24e78079bf2250874e33da2e7cfbb6db72d3caf4 (diff)
gpio: of: Support SPI nonstandard GPIO properties
Before it was clearly established that all GPIO properties in the device tree shall be named "foo-gpios" (with the deprecated variant "foo-gpio" for single lines) we unfortunately merged a few bindings which named the lines "gpio-foo" instead. This is most prominent in the GPIO SPI driver in Linux which names the lines "gpio-sck", "gpio-mosi" and "gpio-miso". As we want to switch the GPIO SPI driver to using descriptors, we need devm_gpiod_get() to return something reasonable when looking up these in the device tree. Put in a special #ifdef:ed kludge to do this special lookup only for the SPI case and gets compiled out if we're not enabling SPI. If we have more oddly defined legacy GPIOs like this, they can be handled in a similar manner. Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/gpiolib-of.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 4a2b8d3397c7..13acd0378884 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -117,6 +117,36 @@ int of_get_named_gpio_flags(struct device_node *np, const char *list_name,
117} 117}
118EXPORT_SYMBOL(of_get_named_gpio_flags); 118EXPORT_SYMBOL(of_get_named_gpio_flags);
119 119
120/*
121 * The SPI GPIO bindings happened before we managed to establish that GPIO
122 * properties should be named "foo-gpios" so we have this special kludge for
123 * them.
124 */
125static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id,
126 enum of_gpio_flags *of_flags)
127{
128 char prop_name[32]; /* 32 is max size of property name */
129 struct device_node *np = dev->of_node;
130 struct gpio_desc *desc;
131
132 /*
133 * Hopefully the compiler stubs the rest of the function if this
134 * is false.
135 */
136 if (!IS_ENABLED(CONFIG_SPI_MASTER))
137 return ERR_PTR(-ENOENT);
138
139 /* Allow this specifically for "spi-gpio" devices */
140 if (!of_device_is_compatible(np, "spi-gpio") || !con_id)
141 return ERR_PTR(-ENOENT);
142
143 /* Will be "gpio-sck", "gpio-mosi" or "gpio-miso" */
144 snprintf(prop_name, sizeof(prop_name), "%s-%s", "gpio", con_id);
145
146 desc = of_get_named_gpiod_flags(np, prop_name, 0, of_flags);
147 return desc;
148}
149
120struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, 150struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
121 unsigned int idx, 151 unsigned int idx,
122 enum gpio_lookup_flags *flags) 152 enum gpio_lookup_flags *flags)
@@ -126,6 +156,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
126 struct gpio_desc *desc; 156 struct gpio_desc *desc;
127 unsigned int i; 157 unsigned int i;
128 158
159 /* Try GPIO property "foo-gpios" and "foo-gpio" */
129 for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { 160 for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
130 if (con_id) 161 if (con_id)
131 snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, 162 snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id,
@@ -140,6 +171,10 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
140 break; 171 break;
141 } 172 }
142 173
174 /* Special handling for SPI GPIOs if used */
175 if (IS_ERR(desc))
176 desc = of_find_spi_gpio(dev, con_id, &of_flags);
177
143 if (IS_ERR(desc)) 178 if (IS_ERR(desc))
144 return desc; 179 return desc;
145 180