Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: davinci: fix gpio selection for OF

The driver missed an of_xlate function to translate gpio numbers
as found in the DT to the correct chip and number.

While there I've set #gpio_cells to a fixed value of 2.

I've used gpio-pxa.c as template for those changes and tested my changes
successfully on a da850 board using entries for gpio-leds in a DT. So I didn't
reinvent the wheel but just copied and tested stuff.

Thanks to Grygorii Strashko for the hint to the existing code in gpio-pxa.

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Alexander Holler and committed by
Linus Walleij
758afe42 d3e14453

+24
+24
drivers/gpio/gpio-davinci.c
··· 174 174 return NULL; 175 175 } 176 176 177 + #ifdef CONFIG_OF_GPIO 178 + static int davinci_gpio_of_xlate(struct gpio_chip *gc, 179 + const struct of_phandle_args *gpiospec, 180 + u32 *flags) 181 + { 182 + struct davinci_gpio_controller *chips = dev_get_drvdata(gc->dev); 183 + struct davinci_gpio_platform_data *pdata = dev_get_platdata(gc->dev); 184 + 185 + if (gpiospec->args[0] > pdata->ngpio) 186 + return -EINVAL; 187 + 188 + if (gc != &chips[gpiospec->args[0] / 32].chip) 189 + return -EINVAL; 190 + 191 + if (flags) 192 + *flags = gpiospec->args[1]; 193 + 194 + return gpiospec->args[0] % 32; 195 + } 196 + #endif 197 + 177 198 static int davinci_gpio_probe(struct platform_device *pdev) 178 199 { 179 200 int i, base; ··· 259 238 chips[i].chip.ngpio = 32; 260 239 261 240 #ifdef CONFIG_OF_GPIO 241 + chips[i].chip.of_gpio_n_cells = 2; 242 + chips[i].chip.of_xlate = davinci_gpio_of_xlate; 243 + chips[i].chip.dev = dev; 262 244 chips[i].chip.of_node = dev->of_node; 263 245 #endif 264 246 spin_lock_init(&chips[i].lock);