| From ccbea9b7d8121cdefb2d5458a67fac8282dd2b95 Mon Sep 17 00:00:00 2001 |
| From: Magnus Damm <damm@opensource.se> |
| Date: Wed, 3 Jul 2013 13:14:32 +0900 |
| Subject: 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> |
| (cherry picked from commit 640efa08cb635ae43d5ceae302b20c2c3f2035e5) |
| Signed-off-by: Simon Horman <horms+renesas@verge.net.au> |
| --- |
| drivers/gpio/gpio-em.c | 25 +++++++++++++++++++++++++ |
| include/linux/platform_data/gpio-em.h | 1 + |
| 2 files changed, 26 insertions(+) |
| |
| diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c |
| index 847987c4f04a..c6e1f086efe8 100644 |
| --- a/drivers/gpio/gpio-em.c |
| +++ b/drivers/gpio/gpio-em.c |
| @@ -30,6 +30,7 @@ |
| #include <linux/gpio.h> |
| #include <linux/slab.h> |
| #include <linux/module.h> |
| +#include <linux/pinctrl/consumer.h> |
| #include <linux/platform_data/gpio-em.h> |
| |
| struct em_gio_priv { |
| @@ -216,6 +217,21 @@ static int em_gio_to_irq(struct gpio_chip *chip, unsigned offset) |
| return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset); |
| } |
| |
| +static int em_gio_request(struct gpio_chip *chip, unsigned offset) |
| +{ |
| + return pinctrl_request_gpio(chip->base + offset); |
| +} |
| + |
| +static void em_gio_free(struct gpio_chip *chip, unsigned offset) |
| +{ |
| + pinctrl_free_gpio(chip->base + offset); |
| + |
| + /* Set the GPIO as an input to ensure that the next GPIO request won't |
| + * drive the GPIO pin as an output. |
| + */ |
| + em_gio_direction_input(chip, offset); |
| +} |
| + |
| static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int virq, |
| irq_hw_number_t hw) |
| { |
| @@ -308,6 +324,8 @@ static int em_gio_probe(struct platform_device *pdev) |
| gpio_chip->direction_output = em_gio_direction_output; |
| gpio_chip->set = em_gio_set; |
| gpio_chip->to_irq = em_gio_to_irq; |
| + gpio_chip->request = em_gio_request; |
| + gpio_chip->free = em_gio_free; |
| gpio_chip->label = name; |
| gpio_chip->owner = THIS_MODULE; |
| gpio_chip->base = pdata->gpio_base; |
| @@ -351,6 +369,13 @@ static int em_gio_probe(struct platform_device *pdev) |
| dev_err(&pdev->dev, "failed to add GPIO controller\n"); |
| goto err1; |
| } |
| + |
| + if (pdata->pctl_name) { |
| + ret = gpiochip_add_pin_range(gpio_chip, pdata->pctl_name, 0, |
| + gpio_chip->base, gpio_chip->ngpio); |
| + if (ret < 0) |
| + dev_warn(&pdev->dev, "failed to add pin range\n"); |
| + } |
| return 0; |
| |
| 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 { |
| unsigned int gpio_base; |
| unsigned int irq_base; |
| unsigned int number_of_pins; |
| + const char *pctl_name; |
| }; |
| |
| #endif /* __GPIO_EM_H__ */ |
| -- |
| 1.8.5.rc3 |
| |