Commit 9450be76 authored by Daniel Mack's avatar Daniel Mack Committed by Haojian Zhuang

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: default avatarDaniel Mack <zonque@gmail.com>
Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarHaojian Zhuang <haojian.zhuang@gmail.com>
parent 1e7ba630
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2)) #define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))
int pxa_last_gpio; int pxa_last_gpio;
static int irq_base;
#ifdef CONFIG_OF #ifdef CONFIG_OF
static struct irq_domain *domain; static struct irq_domain *domain;
...@@ -166,63 +167,14 @@ static inline int __gpio_is_occupied(unsigned gpio) ...@@ -166,63 +167,14 @@ static inline int __gpio_is_occupied(unsigned gpio)
return ret; return ret;
} }
#ifdef CONFIG_ARCH_PXA
static inline int __pxa_gpio_to_irq(int gpio)
{
if (gpio_is_pxa_type(gpio_type))
return PXA_GPIO_TO_IRQ(gpio);
return -1;
}
static inline int __pxa_irq_to_gpio(int irq)
{
if (gpio_is_pxa_type(gpio_type))
return irq - PXA_GPIO_TO_IRQ(0);
return -1;
}
#else
static inline int __pxa_gpio_to_irq(int gpio) { return -1; }
static inline int __pxa_irq_to_gpio(int irq) { return -1; }
#endif
#ifdef CONFIG_ARCH_MMP
static inline int __mmp_gpio_to_irq(int gpio)
{
if (gpio_is_mmp_type(gpio_type))
return MMP_GPIO_TO_IRQ(gpio);
return -1;
}
static inline int __mmp_irq_to_gpio(int irq)
{
if (gpio_is_mmp_type(gpio_type))
return irq - MMP_GPIO_TO_IRQ(0);
return -1;
}
#else
static inline int __mmp_gpio_to_irq(int gpio) { return -1; }
static inline int __mmp_irq_to_gpio(int irq) { return -1; }
#endif
static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
{ {
int gpio, ret; return chip->base + offset + irq_base;
gpio = chip->base + offset;
ret = __pxa_gpio_to_irq(gpio);
if (ret >= 0)
return ret;
return __mmp_gpio_to_irq(gpio);
} }
int pxa_irq_to_gpio(int irq) int pxa_irq_to_gpio(int irq)
{ {
int ret; return irq - irq_base;
ret = __pxa_irq_to_gpio(irq);
if (ret >= 0)
return ret;
return __mmp_irq_to_gpio(irq);
} }
static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) static 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,7 +462,7 @@ const struct irq_domain_ops pxa_irq_domain_ops = {
#ifdef CONFIG_OF #ifdef CONFIG_OF
static int __devinit pxa_gpio_probe_dt(struct platform_device *pdev) static int __devinit pxa_gpio_probe_dt(struct platform_device *pdev)
{ {
int ret, nr_banks, nr_gpios, irq_base; int ret, nr_banks, nr_gpios;
struct device_node *prev, *next, *np = pdev->dev.of_node; struct device_node *prev, *next, *np = pdev->dev.of_node;
const struct of_device_id *of_id = const struct of_device_id *of_id =
of_match_device(pxa_gpio_dt_ids, &pdev->dev); of_match_device(pxa_gpio_dt_ids, &pdev->dev);
...@@ -564,10 +516,20 @@ static int __devinit pxa_gpio_probe(struct platform_device *pdev) ...@@ -564,10 +516,20 @@ static int __devinit pxa_gpio_probe(struct platform_device *pdev)
int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0; int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0;
ret = pxa_gpio_probe_dt(pdev); ret = pxa_gpio_probe_dt(pdev);
if (ret < 0) if (ret < 0) {
pxa_last_gpio = pxa_gpio_nums(); pxa_last_gpio = pxa_gpio_nums();
else #ifdef CONFIG_ARCH_PXA
if (gpio_is_pxa_type(gpio_type))
irq_base = PXA_GPIO_TO_IRQ(0);
#endif
#ifdef CONFIG_ARCH_MMP
if (gpio_is_mmp_type(gpio_type))
irq_base = MMP_GPIO_TO_IRQ(0);
#endif
} else {
use_of = 1; use_of = 1;
}
if (!pxa_last_gpio) if (!pxa_last_gpio)
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment