aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDaniel Mack <zonque@gmail.com>2012-07-22 10:55:44 -0400
committerHaojian Zhuang <haojian.zhuang@gmail.com>2012-08-16 04:14:36 -0400
commit9450be76d0e3ebedf301aa09e4f98b4d3a175229 (patch)
tree728c52b9fae8251ceeb9cde66b32e1200d0049e7 /drivers
parent1e7ba630d4aeabef8e022a4099b20ab9f660d37d (diff)
GPIO: gpio-pxa: simplify pxa_gpio_to_irq() and pxa_irq_to_chip()
Simplify the code in gpio-pxa.c and make them based on irq_base. When not probed from devicetree, initialize irq_base from PXA_GPIO_TO_IRQ() or MMP_GPIO_TO_IRQ(), respectively, so the non-DT case still works. Only tested on PXA3xx. Signed-off-by: Daniel Mack <zonque@gmail.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Haojian Zhuang <haojian.zhuang@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/gpio-pxa.c70
1 files changed, 16 insertions, 54 deletions
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index 58a6a63a6ece..6d0cb9dff27d 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -59,6 +59,7 @@
59#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2)) 59#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))
60 60
61int pxa_last_gpio; 61int pxa_last_gpio;
62static int irq_base;
62 63
63#ifdef CONFIG_OF 64#ifdef CONFIG_OF
64static struct irq_domain *domain; 65static struct irq_domain *domain;
@@ -166,63 +167,14 @@ static inline int __gpio_is_occupied(unsigned gpio)
166 return ret; 167 return ret;
167} 168}
168 169
169#ifdef CONFIG_ARCH_PXA
170static inline int __pxa_gpio_to_irq(int gpio)
171{
172 if (gpio_is_pxa_type(gpio_type))
173 return PXA_GPIO_TO_IRQ(gpio);
174 return -1;
175}
176
177static inline int __pxa_irq_to_gpio(int irq)
178{
179 if (gpio_is_pxa_type(gpio_type))
180 return irq - PXA_GPIO_TO_IRQ(0);
181 return -1;
182}
183#else
184static inline int __pxa_gpio_to_irq(int gpio) { return -1; }
185static inline int __pxa_irq_to_gpio(int irq) { return -1; }
186#endif
187
188#ifdef CONFIG_ARCH_MMP
189static inline int __mmp_gpio_to_irq(int gpio)
190{
191 if (gpio_is_mmp_type(gpio_type))
192 return MMP_GPIO_TO_IRQ(gpio);
193 return -1;
194}
195
196static inline int __mmp_irq_to_gpio(int irq)
197{
198 if (gpio_is_mmp_type(gpio_type))
199 return irq - MMP_GPIO_TO_IRQ(0);
200 return -1;
201}
202#else
203static inline int __mmp_gpio_to_irq(int gpio) { return -1; }
204static inline int __mmp_irq_to_gpio(int irq) { return -1; }
205#endif
206
207static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 170static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
208{ 171{
209 int gpio, ret; 172 return chip->base + offset + irq_base;
210
211 gpio = chip->base + offset;
212 ret = __pxa_gpio_to_irq(gpio);
213 if (ret >= 0)
214 return ret;
215 return __mmp_gpio_to_irq(gpio);
216} 173}
217 174
218int pxa_irq_to_gpio(int irq) 175int pxa_irq_to_gpio(int irq)
219{ 176{
220 int ret; 177 return irq - irq_base;
221
222 ret = __pxa_irq_to_gpio(irq);
223 if (ret >= 0)
224 return ret;
225 return __mmp_irq_to_gpio(irq);
226} 178}
227 179
228static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 180static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
@@ -510,7 +462,7 @@ const struct irq_domain_ops pxa_irq_domain_ops = {
510#ifdef CONFIG_OF 462#ifdef CONFIG_OF
511static int __devinit pxa_gpio_probe_dt(struct platform_device *pdev) 463static int __devinit pxa_gpio_probe_dt(struct platform_device *pdev)
512{ 464{
513 int ret, nr_banks, nr_gpios, irq_base; 465 int ret, nr_banks, nr_gpios;
514 struct device_node *prev, *next, *np = pdev->dev.of_node; 466 struct device_node *prev, *next, *np = pdev->dev.of_node;
515 const struct of_device_id *of_id = 467 const struct of_device_id *of_id =
516 of_match_device(pxa_gpio_dt_ids, &pdev->dev); 468 of_match_device(pxa_gpio_dt_ids, &pdev->dev);
@@ -564,10 +516,20 @@ static int __devinit pxa_gpio_probe(struct platform_device *pdev)
564 int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0; 516 int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0;
565 517
566 ret = pxa_gpio_probe_dt(pdev); 518 ret = pxa_gpio_probe_dt(pdev);
567 if (ret < 0) 519 if (ret < 0) {
568 pxa_last_gpio = pxa_gpio_nums(); 520 pxa_last_gpio = pxa_gpio_nums();
569 else 521#ifdef CONFIG_ARCH_PXA
522 if (gpio_is_pxa_type(gpio_type))
523 irq_base = PXA_GPIO_TO_IRQ(0);
524#endif
525#ifdef CONFIG_ARCH_MMP
526 if (gpio_is_mmp_type(gpio_type))
527 irq_base = MMP_GPIO_TO_IRQ(0);
528#endif
529 } else {
570 use_of = 1; 530 use_of = 1;
531 }
532
571 if (!pxa_last_gpio) 533 if (!pxa_last_gpio)
572 return -EINVAL; 534 return -EINVAL;
573 535