diff options
author | Gernot Vormayr <gvormayr@gmail.com> | 2014-09-23 18:58:45 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2014-09-24 07:37:38 -0400 |
commit | 1b4c5a6e6b73b082170bfcbf1ff3e2fcf2e7530c (patch) | |
tree | 8d691c89257a7fe3b2bf773b47ebb13e0e1cc9cd | |
parent | 58a3b92d33d289e2f3390b40a2c5cfd7f32cfe7a (diff) |
gpio: Fix ngpio in gpio-xilinx driver
If one adds gpio-controller; to the chip in the devicetree, then
initialization fails with 'gpiochip_find_base: cannot find free range',
because ngpio is 0. This patch fixes the bug.
This version includes the suggestions from Linus Walleij.
Tested on ml507 board.
Signed-off-by: Gernot Vormayr <gvormayr@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | drivers/gpio/gpio-xilinx.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index 12481867daf1..ba18b06c9a21 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c | |||
@@ -197,6 +197,7 @@ static int xgpio_of_probe(struct device_node *np) | |||
197 | struct xgpio_instance *chip; | 197 | struct xgpio_instance *chip; |
198 | int status = 0; | 198 | int status = 0; |
199 | const u32 *tree_info; | 199 | const u32 *tree_info; |
200 | u32 ngpio; | ||
200 | 201 | ||
201 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 202 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
202 | if (!chip) | 203 | if (!chip) |
@@ -211,12 +212,13 @@ static int xgpio_of_probe(struct device_node *np) | |||
211 | /* Update GPIO direction shadow register with default value */ | 212 | /* Update GPIO direction shadow register with default value */ |
212 | of_property_read_u32(np, "xlnx,tri-default", &chip->gpio_dir); | 213 | of_property_read_u32(np, "xlnx,tri-default", &chip->gpio_dir); |
213 | 214 | ||
214 | /* By default assume full GPIO controller */ | 215 | /* |
215 | chip->mmchip.gc.ngpio = 32; | 216 | * Check device node and parent device node for device width |
216 | 217 | * and assume default width of 32 | |
217 | /* Check device node and parent device node for device width */ | 218 | */ |
218 | of_property_read_u32(np, "xlnx,gpio-width", | 219 | if (of_property_read_u32(np, "xlnx,gpio-width", &ngpio)) |
219 | (u32 *)&chip->mmchip.gc.ngpio); | 220 | ngpio = 32; |
221 | chip->mmchip.gc.ngpio = (u16)ngpio; | ||
220 | 222 | ||
221 | spin_lock_init(&chip->gpio_lock); | 223 | spin_lock_init(&chip->gpio_lock); |
222 | 224 | ||
@@ -258,12 +260,13 @@ static int xgpio_of_probe(struct device_node *np) | |||
258 | /* Update GPIO direction shadow register with default value */ | 260 | /* Update GPIO direction shadow register with default value */ |
259 | of_property_read_u32(np, "xlnx,tri-default-2", &chip->gpio_dir); | 261 | of_property_read_u32(np, "xlnx,tri-default-2", &chip->gpio_dir); |
260 | 262 | ||
261 | /* By default assume full GPIO controller */ | 263 | /* |
262 | chip->mmchip.gc.ngpio = 32; | 264 | * Check device node and parent device node for device width |
263 | 265 | * and assume default width of 32 | |
264 | /* Check device node and parent device node for device width */ | 266 | */ |
265 | of_property_read_u32(np, "xlnx,gpio2-width", | 267 | if (of_property_read_u32(np, "xlnx,gpio2-width", &ngpio)) |
266 | (u32 *)&chip->mmchip.gc.ngpio); | 268 | ngpio = 32; |
269 | chip->mmchip.gc.ngpio = (u16)ngpio; | ||
267 | 270 | ||
268 | spin_lock_init(&chip->gpio_lock); | 271 | spin_lock_init(&chip->gpio_lock); |
269 | 272 | ||