aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-at91/gpio.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2011-09-17 09:49:36 -0400
committerArnd Bergmann <arnd@arndb.de>2011-11-29 10:46:18 -0500
commitd0fbda9add3281c97205649150fc99fc26148792 (patch)
tree9e3488936b75252a512bb7e13dedfbbbacf9f363 /arch/arm/mach-at91/gpio.c
parent3285e0ec088febc5a88f57ddd78385a7da71476c (diff)
ARM: at91/gpio: drop PIN_BASE
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'arch/arm/mach-at91/gpio.c')
-rw-r--r--arch/arm/mach-at91/gpio.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/arch/arm/mach-at91/gpio.c b/arch/arm/mach-at91/gpio.c
index 163c724882c2..d000448b11ac 100644
--- a/arch/arm/mach-at91/gpio.c
+++ b/arch/arm/mach-at91/gpio.c
@@ -59,18 +59,17 @@ static int at91_gpiolib_direction_input(struct gpio_chip *chip,
59 } 59 }
60 60
61static struct at91_gpio_chip gpio_chip[] = { 61static struct at91_gpio_chip gpio_chip[] = {
62 AT91_GPIO_CHIP("pioA", 0x00 + PIN_BASE, 32), 62 AT91_GPIO_CHIP("pioA", 0x00, 32),
63 AT91_GPIO_CHIP("pioB", 0x20 + PIN_BASE, 32), 63 AT91_GPIO_CHIP("pioB", 0x20, 32),
64 AT91_GPIO_CHIP("pioC", 0x40 + PIN_BASE, 32), 64 AT91_GPIO_CHIP("pioC", 0x40, 32),
65 AT91_GPIO_CHIP("pioD", 0x60 + PIN_BASE, 32), 65 AT91_GPIO_CHIP("pioD", 0x60, 32),
66 AT91_GPIO_CHIP("pioE", 0x80 + PIN_BASE, 32), 66 AT91_GPIO_CHIP("pioE", 0x80, 32),
67}; 67};
68 68
69static int gpio_banks; 69static int gpio_banks;
70 70
71static inline void __iomem *pin_to_controller(unsigned pin) 71static inline void __iomem *pin_to_controller(unsigned pin)
72{ 72{
73 pin -= PIN_BASE;
74 pin /= 32; 73 pin /= 32;
75 if (likely(pin < gpio_banks)) 74 if (likely(pin < gpio_banks))
76 return gpio_chip[pin].regbase; 75 return gpio_chip[pin].regbase;
@@ -80,7 +79,6 @@ static inline void __iomem *pin_to_controller(unsigned pin)
80 79
81static inline unsigned pin_to_mask(unsigned pin) 80static inline unsigned pin_to_mask(unsigned pin)
82{ 81{
83 pin -= PIN_BASE;
84 return 1 << (pin % 32); 82 return 1 << (pin % 32);
85} 83}
86 84
@@ -275,8 +273,9 @@ static u32 backups[MAX_GPIO_BANKS];
275 273
276static int gpio_irq_set_wake(struct irq_data *d, unsigned state) 274static int gpio_irq_set_wake(struct irq_data *d, unsigned state)
277{ 275{
278 unsigned mask = pin_to_mask(d->irq); 276 unsigned pin = irq_to_gpio(d->irq);
279 unsigned bank = (d->irq - PIN_BASE) / 32; 277 unsigned mask = pin_to_mask(pin);
278 unsigned bank = pin / 32;
280 279
281 if (unlikely(bank >= MAX_GPIO_BANKS)) 280 if (unlikely(bank >= MAX_GPIO_BANKS))
282 return -EINVAL; 281 return -EINVAL;
@@ -345,8 +344,9 @@ void at91_gpio_resume(void)
345 344
346static void gpio_irq_mask(struct irq_data *d) 345static void gpio_irq_mask(struct irq_data *d)
347{ 346{
348 void __iomem *pio = pin_to_controller(d->irq); 347 unsigned pin = irq_to_gpio(d->irq);
349 unsigned mask = pin_to_mask(d->irq); 348 void __iomem *pio = pin_to_controller(pin);
349 unsigned mask = pin_to_mask(pin);
350 350
351 if (pio) 351 if (pio)
352 __raw_writel(mask, pio + PIO_IDR); 352 __raw_writel(mask, pio + PIO_IDR);
@@ -354,8 +354,9 @@ static void gpio_irq_mask(struct irq_data *d)
354 354
355static void gpio_irq_unmask(struct irq_data *d) 355static void gpio_irq_unmask(struct irq_data *d)
356{ 356{
357 void __iomem *pio = pin_to_controller(d->irq); 357 unsigned pin = irq_to_gpio(d->irq);
358 unsigned mask = pin_to_mask(d->irq); 358 void __iomem *pio = pin_to_controller(pin);
359 unsigned mask = pin_to_mask(pin);
359 360
360 if (pio) 361 if (pio)
361 __raw_writel(mask, pio + PIO_IER); 362 __raw_writel(mask, pio + PIO_IER);
@@ -383,7 +384,7 @@ static struct irq_chip gpio_irqchip = {
383 384
384static void gpio_irq_handler(unsigned irq, struct irq_desc *desc) 385static void gpio_irq_handler(unsigned irq, struct irq_desc *desc)
385{ 386{
386 unsigned pin; 387 unsigned irq_pin;
387 struct irq_data *idata = irq_desc_get_irq_data(desc); 388 struct irq_data *idata = irq_desc_get_irq_data(desc);
388 struct irq_chip *chip = irq_data_get_irq_chip(idata); 389 struct irq_chip *chip = irq_data_get_irq_chip(idata);
389 struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(idata); 390 struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(idata);
@@ -406,12 +407,12 @@ static void gpio_irq_handler(unsigned irq, struct irq_desc *desc)
406 continue; 407 continue;
407 } 408 }
408 409
409 pin = at91_gpio->chip.base; 410 irq_pin = gpio_to_irq(at91_gpio->chip.base);
410 411
411 while (isr) { 412 while (isr) {
412 if (isr & 1) 413 if (isr & 1)
413 generic_handle_irq(pin); 414 generic_handle_irq(irq_pin);
414 pin++; 415 irq_pin++;
415 isr >>= 1; 416 isr >>= 1;
416 } 417 }
417 } 418 }
@@ -439,7 +440,7 @@ static int at91_gpio_show(struct seq_file *s, void *unused)
439 seq_printf(s, "%i:\t", j); 440 seq_printf(s, "%i:\t", j);
440 441
441 for (bank = 0; bank < gpio_banks; bank++) { 442 for (bank = 0; bank < gpio_banks; bank++) {
442 unsigned pin = PIN_BASE + (32 * bank) + j; 443 unsigned pin = (32 * bank) + j;
443 void __iomem *pio = pin_to_controller(pin); 444 void __iomem *pio = pin_to_controller(pin);
444 unsigned mask = pin_to_mask(pin); 445 unsigned mask = pin_to_mask(pin);
445 446
@@ -492,10 +493,10 @@ static struct lock_class_key gpio_lock_class;
492 */ 493 */
493void __init at91_gpio_irq_setup(void) 494void __init at91_gpio_irq_setup(void)
494{ 495{
495 unsigned pioc, pin; 496 unsigned pioc, irq = gpio_to_irq(0);
496 struct at91_gpio_chip *this, *prev; 497 struct at91_gpio_chip *this, *prev;
497 498
498 for (pioc = 0, pin = PIN_BASE, this = gpio_chip, prev = NULL; 499 for (pioc = 0, this = gpio_chip, prev = NULL;
499 pioc++ < gpio_banks; 500 pioc++ < gpio_banks;
500 prev = this, this++) { 501 prev = this, this++) {
501 unsigned id = this->id; 502 unsigned id = this->id;
@@ -503,16 +504,17 @@ void __init at91_gpio_irq_setup(void)
503 504
504 __raw_writel(~0, this->regbase + PIO_IDR); 505 __raw_writel(~0, this->regbase + PIO_IDR);
505 506
506 for (i = 0, pin = this->chip.base; i < 32; i++, pin++) { 507 for (i = 0, irq = gpio_to_irq(this->chip.base); i < 32;
507 irq_set_lockdep_class(pin, &gpio_lock_class); 508 i++, irq++) {
509 irq_set_lockdep_class(irq, &gpio_lock_class);
508 510
509 /* 511 /*
510 * Can use the "simple" and not "edge" handler since it's 512 * Can use the "simple" and not "edge" handler since it's
511 * shorter, and the AIC handles interrupts sanely. 513 * shorter, and the AIC handles interrupts sanely.
512 */ 514 */
513 irq_set_chip_and_handler(pin, &gpio_irqchip, 515 irq_set_chip_and_handler(irq, &gpio_irqchip,
514 handle_simple_irq); 516 handle_simple_irq);
515 set_irq_flags(pin, IRQF_VALID); 517 set_irq_flags(irq, IRQF_VALID);
516 } 518 }
517 519
518 /* The toplevel handler handles one bank of GPIOs, except 520 /* The toplevel handler handles one bank of GPIOs, except
@@ -525,7 +527,7 @@ void __init at91_gpio_irq_setup(void)
525 irq_set_chip_data(id, this); 527 irq_set_chip_data(id, this);
526 irq_set_chained_handler(id, gpio_irq_handler); 528 irq_set_chained_handler(id, gpio_irq_handler);
527 } 529 }
528 pr_info("AT91: %d gpio irqs in %d banks\n", pin - PIN_BASE, gpio_banks); 530 pr_info("AT91: %d gpio irqs in %d banks\n", irq, gpio_banks);
529} 531}
530 532
531/* gpiolib support */ 533/* gpiolib support */
@@ -614,7 +616,7 @@ void __init at91_gpio_init(struct at91_gpio_bank *data, int nr_banks)
614 at91_gpio = &gpio_chip[i]; 616 at91_gpio = &gpio_chip[i];
615 617
616 at91_gpio->id = data[i].id; 618 at91_gpio->id = data[i].id;
617 at91_gpio->chip.base = PIN_BASE + i * 32; 619 at91_gpio->chip.base = i * 32;
618 620
619 at91_gpio->regbase = ioremap(data[i].regbase, 512); 621 at91_gpio->regbase = ioremap(data[i].regbase, 512);
620 if (!at91_gpio->regbase) { 622 if (!at91_gpio->regbase) {