From: zonque@gmail.com (Daniel Mack)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 4/9] GPIO: gpio-pxa: simplify pxa_gpio_to_irq() and pxa_irq_to_chip()
Date: Sat, 28 Jul 2012 12:07:36 +0200 [thread overview]
Message-ID: <1343470061-16879-5-git-send-email-zonque@gmail.com> (raw)
In-Reply-To: <1343470061-16879-1-git-send-email-zonque@gmail.com>
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>
---
drivers/gpio/gpio-pxa.c | 70 +++++++++++--------------------------------------
1 file changed, 16 insertions(+), 54 deletions(-)
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index 58a6a63..6d0cb9d 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -59,6 +59,7 @@
#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))
int pxa_last_gpio;
+static int irq_base;
#ifdef CONFIG_OF
static struct irq_domain *domain;
@@ -166,63 +167,14 @@ static inline int __gpio_is_occupied(unsigned gpio)
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)
{
- int gpio, ret;
-
- gpio = chip->base + offset;
- ret = __pxa_gpio_to_irq(gpio);
- if (ret >= 0)
- return ret;
- return __mmp_gpio_to_irq(gpio);
+ return chip->base + offset + irq_base;
}
int pxa_irq_to_gpio(int irq)
{
- int ret;
-
- ret = __pxa_irq_to_gpio(irq);
- if (ret >= 0)
- return ret;
- return __mmp_irq_to_gpio(irq);
+ return irq - irq_base;
}
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 = {
#ifdef CONFIG_OF
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;
const struct of_device_id *of_id =
of_match_device(pxa_gpio_dt_ids, &pdev->dev);
@@ -564,10 +516,20 @@ static int __devinit pxa_gpio_probe(struct platform_device *pdev)
int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0;
ret = pxa_gpio_probe_dt(pdev);
- if (ret < 0)
+ if (ret < 0) {
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;
+ }
+
if (!pxa_last_gpio)
return -EINVAL;
--
1.7.11.2
next prev parent reply other threads:[~2012-07-28 10:07 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-28 10:07 [PATCH v3 0/9] Assorted PXA3xx DT patches Daniel Mack
2012-07-28 10:07 ` [PATCH v3 1/9] RTC: add DT bindings to pxa-rtc Daniel Mack
2012-07-28 10:07 ` [PATCH v3 2/9] MMC: pxa-mci: add DT bindings Daniel Mack
2012-08-03 23:52 ` Chris Ball
2012-08-04 1:30 ` Haojian Zhuang
2012-07-28 10:07 ` [PATCH v3 3/9] MTD: pxa3xx-nand: add devicetree bindings Daniel Mack
2012-07-28 10:07 ` Daniel Mack [this message]
2012-08-05 0:12 ` [PATCH v3 4/9] GPIO: gpio-pxa: simplify pxa_gpio_to_irq() and pxa_irq_to_chip() Linus Walleij
2012-08-05 2:56 ` Haojian Zhuang
2012-08-05 9:37 ` Linus Walleij
2012-08-06 8:09 ` Arnd Bergmann
2012-08-06 8:11 ` Daniel Mack
2012-07-28 10:07 ` [PATCH v3 5/9] GPIO: gpio-pxa: fix devicetree functions Daniel Mack
2012-08-04 23:40 ` Linus Walleij
2012-08-05 2:58 ` Haojian Zhuang
2012-07-28 10:07 ` [PATCH v3 6/9] ARM: pxa: add devicetree code for irq handling Daniel Mack
2012-07-28 10:07 ` [PATCH v3 7/9] ARM: pxa3xx: skip default device initialization when booting via DT Daniel Mack
2012-07-28 10:07 ` [PATCH v3 8/9] ARM: pxa3xx: add generic DT machine code Daniel Mack
2012-07-28 10:07 ` [PATCH v3 9/9] ARM: pxa: add .dtsi files Daniel Mack
2012-07-28 18:42 ` Amar Nath
2012-07-29 0:02 ` Daniel Mack
2012-07-29 19:05 ` Daniel Mack
2012-07-29 13:04 ` [PATCH v3 0/9] Assorted PXA3xx DT patches Arnd Bergmann
2012-07-30 14:01 ` Haojian Zhuang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343470061-16879-5-git-send-email-zonque@gmail.com \
--to=zonque@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).