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

gpio: em: Add pinctrl support

Register the GPIO pin range, and request and free GPIO pins using the
pinctrl API. The pctl_name platform data member should be used by
platform devices to point out which pinctrl device to use.

Follows same style as "dc3465a gpio-rcar: Add pinctrl support",
by Laurent Pinchart, thanks to him.

Signed-off-by: Magnus Damm <damm@opensource.se>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Magnus Damm and committed by
Linus Walleij
640efa08 d22fcde0

+26
+25
drivers/gpio/gpio-em.c
··· 30 30 #include <linux/gpio.h> 31 31 #include <linux/slab.h> 32 32 #include <linux/module.h> 33 + #include <linux/pinctrl/consumer.h> 33 34 #include <linux/platform_data/gpio-em.h> 34 35 35 36 struct em_gio_priv { ··· 217 216 return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset); 218 217 } 219 218 219 + static int em_gio_request(struct gpio_chip *chip, unsigned offset) 220 + { 221 + return pinctrl_request_gpio(chip->base + offset); 222 + } 223 + 224 + static void em_gio_free(struct gpio_chip *chip, unsigned offset) 225 + { 226 + pinctrl_free_gpio(chip->base + offset); 227 + 228 + /* Set the GPIO as an input to ensure that the next GPIO request won't 229 + * drive the GPIO pin as an output. 230 + */ 231 + em_gio_direction_input(chip, offset); 232 + } 233 + 220 234 static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int virq, 221 235 irq_hw_number_t hw) 222 236 { ··· 324 308 gpio_chip->direction_output = em_gio_direction_output; 325 309 gpio_chip->set = em_gio_set; 326 310 gpio_chip->to_irq = em_gio_to_irq; 311 + gpio_chip->request = em_gio_request; 312 + gpio_chip->free = em_gio_free; 327 313 gpio_chip->label = name; 328 314 gpio_chip->owner = THIS_MODULE; 329 315 gpio_chip->base = pdata->gpio_base; ··· 368 350 if (ret) { 369 351 dev_err(&pdev->dev, "failed to add GPIO controller\n"); 370 352 goto err1; 353 + } 354 + 355 + if (pdata->pctl_name) { 356 + ret = gpiochip_add_pin_range(gpio_chip, pdata->pctl_name, 0, 357 + gpio_chip->base, gpio_chip->ngpio); 358 + if (ret < 0) 359 + dev_warn(&pdev->dev, "failed to add pin range\n"); 371 360 } 372 361 return 0; 373 362
+1
include/linux/platform_data/gpio-em.h
··· 5 5 unsigned int gpio_base; 6 6 unsigned int irq_base; 7 7 unsigned int number_of_pins; 8 + const char *pctl_name; 8 9 }; 9 10 10 11 #endif /* __GPIO_EM_H__ */