diff options
author | Magnus Damm <damm@opensource.se> | 2013-07-03 00:14:32 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2013-07-21 11:24:41 -0400 |
commit | 640efa08cb635ae43d5ceae302b20c2c3f2035e5 (patch) | |
tree | ce19cf6c4395f2e463c43e259734c775346412b5 | |
parent | d22fcde0b5409a946567387dfdde79a07843bb78 (diff) |
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>
-rw-r--r-- | drivers/gpio/gpio-em.c | 25 | ||||
-rw-r--r-- | include/linux/platform_data/gpio-em.h | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c index 5cba855638bf..eca119b58c21 100644 --- a/drivers/gpio/gpio-em.c +++ b/drivers/gpio/gpio-em.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/gpio.h> | 30 | #include <linux/gpio.h> |
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/module.h> | 32 | #include <linux/module.h> |
33 | #include <linux/pinctrl/consumer.h> | ||
33 | #include <linux/platform_data/gpio-em.h> | 34 | #include <linux/platform_data/gpio-em.h> |
34 | 35 | ||
35 | struct em_gio_priv { | 36 | struct em_gio_priv { |
@@ -216,6 +217,21 @@ static int em_gio_to_irq(struct gpio_chip *chip, unsigned offset) | |||
216 | return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset); | 217 | return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset); |
217 | } | 218 | } |
218 | 219 | ||
220 | static int em_gio_request(struct gpio_chip *chip, unsigned offset) | ||
221 | { | ||
222 | return pinctrl_request_gpio(chip->base + offset); | ||
223 | } | ||
224 | |||
225 | static void em_gio_free(struct gpio_chip *chip, unsigned offset) | ||
226 | { | ||
227 | pinctrl_free_gpio(chip->base + offset); | ||
228 | |||
229 | /* Set the GPIO as an input to ensure that the next GPIO request won't | ||
230 | * drive the GPIO pin as an output. | ||
231 | */ | ||
232 | em_gio_direction_input(chip, offset); | ||
233 | } | ||
234 | |||
219 | static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int virq, | 235 | static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int virq, |
220 | irq_hw_number_t hw) | 236 | irq_hw_number_t hw) |
221 | { | 237 | { |
@@ -308,6 +324,8 @@ static int em_gio_probe(struct platform_device *pdev) | |||
308 | gpio_chip->direction_output = em_gio_direction_output; | 324 | gpio_chip->direction_output = em_gio_direction_output; |
309 | gpio_chip->set = em_gio_set; | 325 | gpio_chip->set = em_gio_set; |
310 | gpio_chip->to_irq = em_gio_to_irq; | 326 | gpio_chip->to_irq = em_gio_to_irq; |
327 | gpio_chip->request = em_gio_request; | ||
328 | gpio_chip->free = em_gio_free; | ||
311 | gpio_chip->label = name; | 329 | gpio_chip->label = name; |
312 | gpio_chip->owner = THIS_MODULE; | 330 | gpio_chip->owner = THIS_MODULE; |
313 | gpio_chip->base = pdata->gpio_base; | 331 | gpio_chip->base = pdata->gpio_base; |
@@ -351,6 +369,13 @@ static int em_gio_probe(struct platform_device *pdev) | |||
351 | dev_err(&pdev->dev, "failed to add GPIO controller\n"); | 369 | dev_err(&pdev->dev, "failed to add GPIO controller\n"); |
352 | goto err1; | 370 | goto err1; |
353 | } | 371 | } |
372 | |||
373 | if (pdata->pctl_name) { | ||
374 | ret = gpiochip_add_pin_range(gpio_chip, pdata->pctl_name, 0, | ||
375 | gpio_chip->base, gpio_chip->ngpio); | ||
376 | if (ret < 0) | ||
377 | dev_warn(&pdev->dev, "failed to add pin range\n"); | ||
378 | } | ||
354 | return 0; | 379 | return 0; |
355 | 380 | ||
356 | err1: | 381 | err1: |
diff --git a/include/linux/platform_data/gpio-em.h b/include/linux/platform_data/gpio-em.h index 573edfb046c4..7c5a519d2dcd 100644 --- a/include/linux/platform_data/gpio-em.h +++ b/include/linux/platform_data/gpio-em.h | |||
@@ -5,6 +5,7 @@ struct gpio_em_config { | |||
5 | unsigned int gpio_base; | 5 | unsigned int gpio_base; |
6 | unsigned int irq_base; | 6 | unsigned int irq_base; |
7 | unsigned int number_of_pins; | 7 | unsigned int number_of_pins; |
8 | const char *pctl_name; | ||
8 | }; | 9 | }; |
9 | 10 | ||
10 | #endif /* __GPIO_EM_H__ */ | 11 | #endif /* __GPIO_EM_H__ */ |