diff options
author | Barry Song <Baohua.Song@csr.com> | 2014-04-15 02:43:46 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2014-04-23 16:01:31 -0400 |
commit | c5eb757ca87d0fffcface683b8efda193cf3d4d4 (patch) | |
tree | 7d506eb9a124891227ea423bbb716b5aeae90532 /drivers/pinctrl/sirf | |
parent | aef95b691feb44cd98010085295e23f209571b3b (diff) |
pinctrl: sirf: wrap all gpio banks into one gpio_chip
all gpio banks are in one chip, that makes software clean in mapping
irq and gpio.
Signed-off-by: Barry Song <Baohua.Song@csr.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/sirf')
-rw-r--r-- | drivers/pinctrl/sirf/pinctrl-sirf.c | 217 |
1 files changed, 91 insertions, 126 deletions
diff --git a/drivers/pinctrl/sirf/pinctrl-sirf.c b/drivers/pinctrl/sirf/pinctrl-sirf.c index 2c3eb207ff87..cb81b1558cef 100644 --- a/drivers/pinctrl/sirf/pinctrl-sirf.c +++ b/drivers/pinctrl/sirf/pinctrl-sirf.c | |||
@@ -34,15 +34,19 @@ | |||
34 | #define DRIVER_NAME "pinmux-sirf" | 34 | #define DRIVER_NAME "pinmux-sirf" |
35 | 35 | ||
36 | struct sirfsoc_gpio_bank { | 36 | struct sirfsoc_gpio_bank { |
37 | struct of_mm_gpio_chip chip; | ||
38 | struct irq_domain *domain; | ||
39 | int id; | 37 | int id; |
40 | int parent_irq; | 38 | int parent_irq; |
41 | spinlock_t lock; | 39 | spinlock_t lock; |
40 | }; | ||
41 | |||
42 | struct sirfsoc_gpio_chip { | ||
43 | struct of_mm_gpio_chip chip; | ||
44 | struct irq_domain *domain; | ||
42 | bool is_marco; /* for marco, some registers are different with prima2 */ | 45 | bool is_marco; /* for marco, some registers are different with prima2 */ |
46 | struct sirfsoc_gpio_bank sgpio_bank[SIRFSOC_GPIO_NO_OF_BANKS]; | ||
43 | }; | 47 | }; |
44 | 48 | ||
45 | static struct sirfsoc_gpio_bank sgpio_bank[SIRFSOC_GPIO_NO_OF_BANKS]; | 49 | static struct sirfsoc_gpio_chip sgpio_chip; |
46 | static DEFINE_SPINLOCK(sgpio_lock); | 50 | static DEFINE_SPINLOCK(sgpio_lock); |
47 | 51 | ||
48 | static struct sirfsoc_pin_group *sirfsoc_pin_groups; | 52 | static struct sirfsoc_pin_group *sirfsoc_pin_groups; |
@@ -258,32 +262,12 @@ static struct pinctrl_desc sirfsoc_pinmux_desc = { | |||
258 | /* | 262 | /* |
259 | * Todo: bind irq_chip to every pinctrl_gpio_range | 263 | * Todo: bind irq_chip to every pinctrl_gpio_range |
260 | */ | 264 | */ |
261 | static struct pinctrl_gpio_range sirfsoc_gpio_ranges[] = { | 265 | static struct pinctrl_gpio_range sirfsoc_gpio_ranges = { |
262 | { | 266 | .name = "sirfsoc-gpio*", |
263 | .name = "sirfsoc-gpio*", | 267 | .id = 0, |
264 | .id = 0, | 268 | .base = 0, |
265 | .base = 0, | 269 | .pin_base = 0, |
266 | .pin_base = 0, | 270 | .npins = SIRFSOC_GPIO_BANK_SIZE * SIRFSOC_GPIO_NO_OF_BANKS, |
267 | .npins = 32, | ||
268 | }, { | ||
269 | .name = "sirfsoc-gpio*", | ||
270 | .id = 1, | ||
271 | .base = 32, | ||
272 | .pin_base = 32, | ||
273 | .npins = 32, | ||
274 | }, { | ||
275 | .name = "sirfsoc-gpio*", | ||
276 | .id = 2, | ||
277 | .base = 64, | ||
278 | .pin_base = 64, | ||
279 | .npins = 32, | ||
280 | }, { | ||
281 | .name = "sirfsoc-gpio*", | ||
282 | .id = 3, | ||
283 | .base = 96, | ||
284 | .pin_base = 96, | ||
285 | .npins = 19, | ||
286 | }, | ||
287 | }; | 271 | }; |
288 | 272 | ||
289 | static void __iomem *sirfsoc_rsc_of_iomap(void) | 273 | static void __iomem *sirfsoc_rsc_of_iomap(void) |
@@ -303,19 +287,19 @@ static void __iomem *sirfsoc_rsc_of_iomap(void) | |||
303 | } | 287 | } |
304 | 288 | ||
305 | static int sirfsoc_gpio_of_xlate(struct gpio_chip *gc, | 289 | static int sirfsoc_gpio_of_xlate(struct gpio_chip *gc, |
306 | const struct of_phandle_args *gpiospec, | 290 | const struct of_phandle_args *gpiospec, |
307 | u32 *flags) | 291 | u32 *flags) |
308 | { | 292 | { |
309 | if (gpiospec->args[0] > SIRFSOC_GPIO_NO_OF_BANKS * SIRFSOC_GPIO_BANK_SIZE) | 293 | if (gpiospec->args[0] > SIRFSOC_GPIO_NO_OF_BANKS * SIRFSOC_GPIO_BANK_SIZE) |
310 | return -EINVAL; | 294 | return -EINVAL; |
311 | 295 | ||
312 | if (gc != &sgpio_bank[gpiospec->args[0] / SIRFSOC_GPIO_BANK_SIZE].chip.gc) | 296 | if (gc != &sgpio_chip.chip.gc) |
313 | return -EINVAL; | 297 | return -EINVAL; |
314 | 298 | ||
315 | if (flags) | 299 | if (flags) |
316 | *flags = gpiospec->args[1]; | 300 | *flags = gpiospec->args[1]; |
317 | 301 | ||
318 | return gpiospec->args[0] % SIRFSOC_GPIO_BANK_SIZE; | 302 | return gpiospec->args[0]; |
319 | } | 303 | } |
320 | 304 | ||
321 | static const struct of_device_id pinmux_ids[] = { | 305 | static const struct of_device_id pinmux_ids[] = { |
@@ -331,7 +315,6 @@ static int sirfsoc_pinmux_probe(struct platform_device *pdev) | |||
331 | struct sirfsoc_pmx *spmx; | 315 | struct sirfsoc_pmx *spmx; |
332 | struct device_node *np = pdev->dev.of_node; | 316 | struct device_node *np = pdev->dev.of_node; |
333 | const struct sirfsoc_pinctrl_data *pdata; | 317 | const struct sirfsoc_pinctrl_data *pdata; |
334 | int i; | ||
335 | 318 | ||
336 | /* Create state holders etc for this driver */ | 319 | /* Create state holders etc for this driver */ |
337 | spmx = devm_kzalloc(&pdev->dev, sizeof(*spmx), GFP_KERNEL); | 320 | spmx = devm_kzalloc(&pdev->dev, sizeof(*spmx), GFP_KERNEL); |
@@ -375,10 +358,8 @@ static int sirfsoc_pinmux_probe(struct platform_device *pdev) | |||
375 | goto out_no_pmx; | 358 | goto out_no_pmx; |
376 | } | 359 | } |
377 | 360 | ||
378 | for (i = 0; i < ARRAY_SIZE(sirfsoc_gpio_ranges); i++) { | 361 | sirfsoc_gpio_ranges.gc = &sgpio_chip.chip.gc; |
379 | sirfsoc_gpio_ranges[i].gc = &sgpio_bank[i].chip.gc; | 362 | pinctrl_add_gpio_range(spmx->pmx, &sirfsoc_gpio_ranges); |
380 | pinctrl_add_gpio_range(spmx->pmx, &sirfsoc_gpio_ranges[i]); | ||
381 | } | ||
382 | 363 | ||
383 | dev_info(&pdev->dev, "initialized SIRFSOC pinmux driver\n"); | 364 | dev_info(&pdev->dev, "initialized SIRFSOC pinmux driver\n"); |
384 | 365 | ||
@@ -464,33 +445,23 @@ static int __init sirfsoc_pinmux_init(void) | |||
464 | } | 445 | } |
465 | arch_initcall(sirfsoc_pinmux_init); | 446 | arch_initcall(sirfsoc_pinmux_init); |
466 | 447 | ||
467 | static inline int sirfsoc_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | 448 | static inline struct sirfsoc_gpio_bank *sirfsoc_gpio_to_bank(unsigned int gpio) |
468 | { | 449 | { |
469 | struct sirfsoc_gpio_bank *bank = container_of(to_of_mm_gpio_chip(chip), | 450 | return &sgpio_chip.sgpio_bank[gpio / SIRFSOC_GPIO_BANK_SIZE]; |
470 | struct sirfsoc_gpio_bank, chip); | ||
471 | |||
472 | return irq_create_mapping(bank->domain, offset + bank->id * | ||
473 | SIRFSOC_GPIO_BANK_SIZE); | ||
474 | } | 451 | } |
475 | 452 | ||
476 | static inline int sirfsoc_gpio_to_offset(unsigned int gpio) | 453 | static int sirfsoc_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
477 | { | 454 | { |
478 | return gpio % SIRFSOC_GPIO_BANK_SIZE; | 455 | return irq_create_mapping(sgpio_chip.domain, offset); |
479 | } | 456 | } |
480 | 457 | ||
481 | static inline struct sirfsoc_gpio_bank *sirfsoc_gpio_to_bank(unsigned int gpio) | 458 | static inline int sirfsoc_gpio_to_bankoff(unsigned int gpio) |
482 | { | 459 | { |
483 | return &sgpio_bank[gpio / SIRFSOC_GPIO_BANK_SIZE]; | 460 | return gpio % SIRFSOC_GPIO_BANK_SIZE; |
484 | } | ||
485 | |||
486 | static inline struct sirfsoc_gpio_bank *sirfsoc_gpiochip_to_bank(struct gpio_chip *chip) | ||
487 | { | ||
488 | return container_of(to_of_mm_gpio_chip(chip), struct sirfsoc_gpio_bank, chip); | ||
489 | } | 461 | } |
490 | |||
491 | static void sirfsoc_gpio_irq_ack(struct irq_data *d) | 462 | static void sirfsoc_gpio_irq_ack(struct irq_data *d) |
492 | { | 463 | { |
493 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); | 464 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(d->hwirq); |
494 | int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE; | 465 | int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE; |
495 | u32 val, offset; | 466 | u32 val, offset; |
496 | unsigned long flags; | 467 | unsigned long flags; |
@@ -499,9 +470,9 @@ static void sirfsoc_gpio_irq_ack(struct irq_data *d) | |||
499 | 470 | ||
500 | spin_lock_irqsave(&sgpio_lock, flags); | 471 | spin_lock_irqsave(&sgpio_lock, flags); |
501 | 472 | ||
502 | val = readl(bank->chip.regs + offset); | 473 | val = readl(sgpio_chip.chip.regs + offset); |
503 | 474 | ||
504 | writel(val, bank->chip.regs + offset); | 475 | writel(val, sgpio_chip.chip.regs + offset); |
505 | 476 | ||
506 | spin_unlock_irqrestore(&sgpio_lock, flags); | 477 | spin_unlock_irqrestore(&sgpio_lock, flags); |
507 | } | 478 | } |
@@ -515,24 +486,24 @@ static void __sirfsoc_gpio_irq_mask(struct sirfsoc_gpio_bank *bank, int idx) | |||
515 | 486 | ||
516 | spin_lock_irqsave(&sgpio_lock, flags); | 487 | spin_lock_irqsave(&sgpio_lock, flags); |
517 | 488 | ||
518 | val = readl(bank->chip.regs + offset); | 489 | val = readl(sgpio_chip.chip.regs + offset); |
519 | val &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK; | 490 | val &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK; |
520 | val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK; | 491 | val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK; |
521 | writel(val, bank->chip.regs + offset); | 492 | writel(val, sgpio_chip.chip.regs + offset); |
522 | 493 | ||
523 | spin_unlock_irqrestore(&sgpio_lock, flags); | 494 | spin_unlock_irqrestore(&sgpio_lock, flags); |
524 | } | 495 | } |
525 | 496 | ||
526 | static void sirfsoc_gpio_irq_mask(struct irq_data *d) | 497 | static void sirfsoc_gpio_irq_mask(struct irq_data *d) |
527 | { | 498 | { |
528 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); | 499 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(d->hwirq); |
529 | 500 | ||
530 | __sirfsoc_gpio_irq_mask(bank, d->hwirq % SIRFSOC_GPIO_BANK_SIZE); | 501 | __sirfsoc_gpio_irq_mask(bank, d->hwirq % SIRFSOC_GPIO_BANK_SIZE); |
531 | } | 502 | } |
532 | 503 | ||
533 | static void sirfsoc_gpio_irq_unmask(struct irq_data *d) | 504 | static void sirfsoc_gpio_irq_unmask(struct irq_data *d) |
534 | { | 505 | { |
535 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); | 506 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(d->hwirq); |
536 | int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE; | 507 | int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE; |
537 | u32 val, offset; | 508 | u32 val, offset; |
538 | unsigned long flags; | 509 | unsigned long flags; |
@@ -541,17 +512,17 @@ static void sirfsoc_gpio_irq_unmask(struct irq_data *d) | |||
541 | 512 | ||
542 | spin_lock_irqsave(&sgpio_lock, flags); | 513 | spin_lock_irqsave(&sgpio_lock, flags); |
543 | 514 | ||
544 | val = readl(bank->chip.regs + offset); | 515 | val = readl(sgpio_chip.chip.regs + offset); |
545 | val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK; | 516 | val &= ~SIRFSOC_GPIO_CTL_INTR_STS_MASK; |
546 | val |= SIRFSOC_GPIO_CTL_INTR_EN_MASK; | 517 | val |= SIRFSOC_GPIO_CTL_INTR_EN_MASK; |
547 | writel(val, bank->chip.regs + offset); | 518 | writel(val, sgpio_chip.chip.regs + offset); |
548 | 519 | ||
549 | spin_unlock_irqrestore(&sgpio_lock, flags); | 520 | spin_unlock_irqrestore(&sgpio_lock, flags); |
550 | } | 521 | } |
551 | 522 | ||
552 | static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type) | 523 | static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type) |
553 | { | 524 | { |
554 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); | 525 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(d->hwirq); |
555 | int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE; | 526 | int idx = d->hwirq % SIRFSOC_GPIO_BANK_SIZE; |
556 | u32 val, offset; | 527 | u32 val, offset; |
557 | unsigned long flags; | 528 | unsigned long flags; |
@@ -560,7 +531,7 @@ static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type) | |||
560 | 531 | ||
561 | spin_lock_irqsave(&sgpio_lock, flags); | 532 | spin_lock_irqsave(&sgpio_lock, flags); |
562 | 533 | ||
563 | val = readl(bank->chip.regs + offset); | 534 | val = readl(sgpio_chip.chip.regs + offset); |
564 | val &= ~(SIRFSOC_GPIO_CTL_INTR_STS_MASK | SIRFSOC_GPIO_CTL_OUT_EN_MASK); | 535 | val &= ~(SIRFSOC_GPIO_CTL_INTR_STS_MASK | SIRFSOC_GPIO_CTL_OUT_EN_MASK); |
565 | 536 | ||
566 | switch (type) { | 537 | switch (type) { |
@@ -588,7 +559,7 @@ static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type) | |||
588 | break; | 559 | break; |
589 | } | 560 | } |
590 | 561 | ||
591 | writel(val, bank->chip.regs + offset); | 562 | writel(val, sgpio_chip.chip.regs + offset); |
592 | 563 | ||
593 | spin_unlock_irqrestore(&sgpio_lock, flags); | 564 | spin_unlock_irqrestore(&sgpio_lock, flags); |
594 | 565 | ||
@@ -597,10 +568,8 @@ static int sirfsoc_gpio_irq_type(struct irq_data *d, unsigned type) | |||
597 | 568 | ||
598 | static int sirfsoc_gpio_irq_reqres(struct irq_data *d) | 569 | static int sirfsoc_gpio_irq_reqres(struct irq_data *d) |
599 | { | 570 | { |
600 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); | 571 | if (gpio_lock_as_irq(&sgpio_chip.chip.gc, d->hwirq)) { |
601 | 572 | dev_err(sgpio_chip.chip.gc.dev, | |
602 | if (gpio_lock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE)) { | ||
603 | dev_err(bank->chip.gc.dev, | ||
604 | "unable to lock HW IRQ %lu for IRQ\n", | 573 | "unable to lock HW IRQ %lu for IRQ\n", |
605 | d->hwirq); | 574 | d->hwirq); |
606 | return -EINVAL; | 575 | return -EINVAL; |
@@ -610,9 +579,7 @@ static int sirfsoc_gpio_irq_reqres(struct irq_data *d) | |||
610 | 579 | ||
611 | static void sirfsoc_gpio_irq_relres(struct irq_data *d) | 580 | static void sirfsoc_gpio_irq_relres(struct irq_data *d) |
612 | { | 581 | { |
613 | struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); | 582 | gpio_unlock_as_irq(&sgpio_chip.chip.gc, d->hwirq); |
614 | |||
615 | gpio_unlock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE); | ||
616 | } | 583 | } |
617 | 584 | ||
618 | static struct irq_chip sirfsoc_irq_chip = { | 585 | static struct irq_chip sirfsoc_irq_chip = { |
@@ -634,7 +601,7 @@ static void sirfsoc_gpio_handle_irq(unsigned int irq, struct irq_desc *desc) | |||
634 | 601 | ||
635 | chained_irq_enter(chip, desc); | 602 | chained_irq_enter(chip, desc); |
636 | 603 | ||
637 | status = readl(bank->chip.regs + SIRFSOC_GPIO_INT_STATUS(bank->id)); | 604 | status = readl(sgpio_chip.chip.regs + SIRFSOC_GPIO_INT_STATUS(bank->id)); |
638 | if (!status) { | 605 | if (!status) { |
639 | printk(KERN_WARNING | 606 | printk(KERN_WARNING |
640 | "%s: gpio id %d status %#x no interrupt is flaged\n", | 607 | "%s: gpio id %d status %#x no interrupt is flaged\n", |
@@ -644,7 +611,7 @@ static void sirfsoc_gpio_handle_irq(unsigned int irq, struct irq_desc *desc) | |||
644 | } | 611 | } |
645 | 612 | ||
646 | while (status) { | 613 | while (status) { |
647 | ctrl = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, idx)); | 614 | ctrl = readl(sgpio_chip.chip.regs + SIRFSOC_GPIO_CTRL(bank->id, idx)); |
648 | 615 | ||
649 | /* | 616 | /* |
650 | * Here we must check whether the corresponding GPIO's interrupt | 617 | * Here we must check whether the corresponding GPIO's interrupt |
@@ -653,7 +620,7 @@ static void sirfsoc_gpio_handle_irq(unsigned int irq, struct irq_desc *desc) | |||
653 | if ((status & 0x1) && (ctrl & SIRFSOC_GPIO_CTL_INTR_EN_MASK)) { | 620 | if ((status & 0x1) && (ctrl & SIRFSOC_GPIO_CTL_INTR_EN_MASK)) { |
654 | pr_debug("%s: gpio id %d idx %d happens\n", | 621 | pr_debug("%s: gpio id %d idx %d happens\n", |
655 | __func__, bank->id, idx); | 622 | __func__, bank->id, idx); |
656 | generic_handle_irq(irq_find_mapping(bank->domain, idx + | 623 | generic_handle_irq(irq_find_mapping(sgpio_chip.domain, idx + |
657 | bank->id * SIRFSOC_GPIO_BANK_SIZE)); | 624 | bank->id * SIRFSOC_GPIO_BANK_SIZE)); |
658 | } | 625 | } |
659 | 626 | ||
@@ -668,14 +635,14 @@ static inline void sirfsoc_gpio_set_input(struct sirfsoc_gpio_bank *bank, unsign | |||
668 | { | 635 | { |
669 | u32 val; | 636 | u32 val; |
670 | 637 | ||
671 | val = readl(bank->chip.regs + ctrl_offset); | 638 | val = readl(sgpio_chip.chip.regs + ctrl_offset); |
672 | val &= ~SIRFSOC_GPIO_CTL_OUT_EN_MASK; | 639 | val &= ~SIRFSOC_GPIO_CTL_OUT_EN_MASK; |
673 | writel(val, bank->chip.regs + ctrl_offset); | 640 | writel(val, sgpio_chip.chip.regs + ctrl_offset); |
674 | } | 641 | } |
675 | 642 | ||
676 | static int sirfsoc_gpio_request(struct gpio_chip *chip, unsigned offset) | 643 | static int sirfsoc_gpio_request(struct gpio_chip *chip, unsigned offset) |
677 | { | 644 | { |
678 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpiochip_to_bank(chip); | 645 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(offset); |
679 | unsigned long flags; | 646 | unsigned long flags; |
680 | 647 | ||
681 | if (pinctrl_request_gpio(chip->base + offset)) | 648 | if (pinctrl_request_gpio(chip->base + offset)) |
@@ -697,7 +664,7 @@ static int sirfsoc_gpio_request(struct gpio_chip *chip, unsigned offset) | |||
697 | 664 | ||
698 | static void sirfsoc_gpio_free(struct gpio_chip *chip, unsigned offset) | 665 | static void sirfsoc_gpio_free(struct gpio_chip *chip, unsigned offset) |
699 | { | 666 | { |
700 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpiochip_to_bank(chip); | 667 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(offset); |
701 | unsigned long flags; | 668 | unsigned long flags; |
702 | 669 | ||
703 | spin_lock_irqsave(&bank->lock, flags); | 670 | spin_lock_irqsave(&bank->lock, flags); |
@@ -712,8 +679,8 @@ static void sirfsoc_gpio_free(struct gpio_chip *chip, unsigned offset) | |||
712 | 679 | ||
713 | static int sirfsoc_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) | 680 | static int sirfsoc_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) |
714 | { | 681 | { |
715 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpiochip_to_bank(chip); | 682 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(gpio); |
716 | int idx = sirfsoc_gpio_to_offset(gpio); | 683 | int idx = sirfsoc_gpio_to_bankoff(gpio); |
717 | unsigned long flags; | 684 | unsigned long flags; |
718 | unsigned offset; | 685 | unsigned offset; |
719 | 686 | ||
@@ -736,7 +703,7 @@ static inline void sirfsoc_gpio_set_output(struct sirfsoc_gpio_bank *bank, unsig | |||
736 | 703 | ||
737 | spin_lock_irqsave(&bank->lock, flags); | 704 | spin_lock_irqsave(&bank->lock, flags); |
738 | 705 | ||
739 | out_ctrl = readl(bank->chip.regs + offset); | 706 | out_ctrl = readl(sgpio_chip.chip.regs + offset); |
740 | if (value) | 707 | if (value) |
741 | out_ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK; | 708 | out_ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK; |
742 | else | 709 | else |
@@ -744,15 +711,15 @@ static inline void sirfsoc_gpio_set_output(struct sirfsoc_gpio_bank *bank, unsig | |||
744 | 711 | ||
745 | out_ctrl &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK; | 712 | out_ctrl &= ~SIRFSOC_GPIO_CTL_INTR_EN_MASK; |
746 | out_ctrl |= SIRFSOC_GPIO_CTL_OUT_EN_MASK; | 713 | out_ctrl |= SIRFSOC_GPIO_CTL_OUT_EN_MASK; |
747 | writel(out_ctrl, bank->chip.regs + offset); | 714 | writel(out_ctrl, sgpio_chip.chip.regs + offset); |
748 | 715 | ||
749 | spin_unlock_irqrestore(&bank->lock, flags); | 716 | spin_unlock_irqrestore(&bank->lock, flags); |
750 | } | 717 | } |
751 | 718 | ||
752 | static int sirfsoc_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value) | 719 | static int sirfsoc_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value) |
753 | { | 720 | { |
754 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpiochip_to_bank(chip); | 721 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(gpio); |
755 | int idx = sirfsoc_gpio_to_offset(gpio); | 722 | int idx = sirfsoc_gpio_to_bankoff(gpio); |
756 | u32 offset; | 723 | u32 offset; |
757 | unsigned long flags; | 724 | unsigned long flags; |
758 | 725 | ||
@@ -769,13 +736,13 @@ static int sirfsoc_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, | |||
769 | 736 | ||
770 | static int sirfsoc_gpio_get_value(struct gpio_chip *chip, unsigned offset) | 737 | static int sirfsoc_gpio_get_value(struct gpio_chip *chip, unsigned offset) |
771 | { | 738 | { |
772 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpiochip_to_bank(chip); | 739 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(offset); |
773 | u32 val; | 740 | u32 val; |
774 | unsigned long flags; | 741 | unsigned long flags; |
775 | 742 | ||
776 | spin_lock_irqsave(&bank->lock, flags); | 743 | spin_lock_irqsave(&bank->lock, flags); |
777 | 744 | ||
778 | val = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset)); | 745 | val = readl(sgpio_chip.chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset)); |
779 | 746 | ||
780 | spin_unlock_irqrestore(&bank->lock, flags); | 747 | spin_unlock_irqrestore(&bank->lock, flags); |
781 | 748 | ||
@@ -785,18 +752,18 @@ static int sirfsoc_gpio_get_value(struct gpio_chip *chip, unsigned offset) | |||
785 | static void sirfsoc_gpio_set_value(struct gpio_chip *chip, unsigned offset, | 752 | static void sirfsoc_gpio_set_value(struct gpio_chip *chip, unsigned offset, |
786 | int value) | 753 | int value) |
787 | { | 754 | { |
788 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpiochip_to_bank(chip); | 755 | struct sirfsoc_gpio_bank *bank = sirfsoc_gpio_to_bank(offset); |
789 | u32 ctrl; | 756 | u32 ctrl; |
790 | unsigned long flags; | 757 | unsigned long flags; |
791 | 758 | ||
792 | spin_lock_irqsave(&bank->lock, flags); | 759 | spin_lock_irqsave(&bank->lock, flags); |
793 | 760 | ||
794 | ctrl = readl(bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset)); | 761 | ctrl = readl(sgpio_chip.chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset)); |
795 | if (value) | 762 | if (value) |
796 | ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK; | 763 | ctrl |= SIRFSOC_GPIO_CTL_DATAOUT_MASK; |
797 | else | 764 | else |
798 | ctrl &= ~SIRFSOC_GPIO_CTL_DATAOUT_MASK; | 765 | ctrl &= ~SIRFSOC_GPIO_CTL_DATAOUT_MASK; |
799 | writel(ctrl, bank->chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset)); | 766 | writel(ctrl, sgpio_chip.chip.regs + SIRFSOC_GPIO_CTRL(bank->id, offset)); |
800 | 767 | ||
801 | spin_unlock_irqrestore(&bank->lock, flags); | 768 | spin_unlock_irqrestore(&bank->lock, flags); |
802 | } | 769 | } |
@@ -811,7 +778,6 @@ static int sirfsoc_gpio_irq_map(struct irq_domain *d, unsigned int irq, | |||
811 | 778 | ||
812 | irq_set_chip(irq, &sirfsoc_irq_chip); | 779 | irq_set_chip(irq, &sirfsoc_irq_chip); |
813 | irq_set_handler(irq, handle_level_irq); | 780 | irq_set_handler(irq, handle_level_irq); |
814 | irq_set_chip_data(irq, bank + hwirq / SIRFSOC_GPIO_BANK_SIZE); | ||
815 | set_irq_flags(irq, IRQF_VALID); | 781 | set_irq_flags(irq, IRQF_VALID); |
816 | 782 | ||
817 | return 0; | 783 | return 0; |
@@ -830,10 +796,10 @@ static void sirfsoc_gpio_set_pullup(const u32 *pullups) | |||
830 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { | 796 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { |
831 | for_each_set_bit(n, p + i, BITS_PER_LONG) { | 797 | for_each_set_bit(n, p + i, BITS_PER_LONG) { |
832 | u32 offset = SIRFSOC_GPIO_CTRL(i, n); | 798 | u32 offset = SIRFSOC_GPIO_CTRL(i, n); |
833 | u32 val = readl(sgpio_bank[i].chip.regs + offset); | 799 | u32 val = readl(sgpio_chip.chip.regs + offset); |
834 | val |= SIRFSOC_GPIO_CTL_PULL_MASK; | 800 | val |= SIRFSOC_GPIO_CTL_PULL_MASK; |
835 | val |= SIRFSOC_GPIO_CTL_PULL_HIGH; | 801 | val |= SIRFSOC_GPIO_CTL_PULL_HIGH; |
836 | writel(val, sgpio_bank[i].chip.regs + offset); | 802 | writel(val, sgpio_chip.chip.regs + offset); |
837 | } | 803 | } |
838 | } | 804 | } |
839 | } | 805 | } |
@@ -846,10 +812,10 @@ static void sirfsoc_gpio_set_pulldown(const u32 *pulldowns) | |||
846 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { | 812 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { |
847 | for_each_set_bit(n, p + i, BITS_PER_LONG) { | 813 | for_each_set_bit(n, p + i, BITS_PER_LONG) { |
848 | u32 offset = SIRFSOC_GPIO_CTRL(i, n); | 814 | u32 offset = SIRFSOC_GPIO_CTRL(i, n); |
849 | u32 val = readl(sgpio_bank[i].chip.regs + offset); | 815 | u32 val = readl(sgpio_chip.chip.regs + offset); |
850 | val |= SIRFSOC_GPIO_CTL_PULL_MASK; | 816 | val |= SIRFSOC_GPIO_CTL_PULL_MASK; |
851 | val &= ~SIRFSOC_GPIO_CTL_PULL_HIGH; | 817 | val &= ~SIRFSOC_GPIO_CTL_PULL_HIGH; |
852 | writel(val, sgpio_bank[i].chip.regs + offset); | 818 | writel(val, sgpio_chip.chip.regs + offset); |
853 | } | 819 | } |
854 | } | 820 | } |
855 | } | 821 | } |
@@ -877,48 +843,47 @@ static int sirfsoc_gpio_probe(struct device_node *np) | |||
877 | is_marco = 1; | 843 | is_marco = 1; |
878 | 844 | ||
879 | domain = irq_domain_add_linear(np, SIRFSOC_GPIO_BANK_SIZE * SIRFSOC_GPIO_NO_OF_BANKS, | 845 | domain = irq_domain_add_linear(np, SIRFSOC_GPIO_BANK_SIZE * SIRFSOC_GPIO_NO_OF_BANKS, |
880 | &sirfsoc_gpio_irq_simple_ops, sgpio_bank); | 846 | &sirfsoc_gpio_irq_simple_ops, &sgpio_chip); |
881 | if (!domain) { | 847 | if (!domain) { |
882 | pr_err("%s: Failed to create irqdomain\n", np->full_name); | 848 | pr_err("%s: Failed to create irqdomain\n", np->full_name); |
883 | err = -ENOSYS; | 849 | err = -ENOSYS; |
884 | goto out; | 850 | goto out; |
885 | } | 851 | } |
886 | 852 | ||
853 | sgpio_chip.chip.gc.request = sirfsoc_gpio_request; | ||
854 | sgpio_chip.chip.gc.free = sirfsoc_gpio_free; | ||
855 | sgpio_chip.chip.gc.direction_input = sirfsoc_gpio_direction_input; | ||
856 | sgpio_chip.chip.gc.get = sirfsoc_gpio_get_value; | ||
857 | sgpio_chip.chip.gc.direction_output = sirfsoc_gpio_direction_output; | ||
858 | sgpio_chip.chip.gc.set = sirfsoc_gpio_set_value; | ||
859 | sgpio_chip.chip.gc.to_irq = sirfsoc_gpio_to_irq; | ||
860 | sgpio_chip.chip.gc.base = 0; | ||
861 | sgpio_chip.chip.gc.ngpio = SIRFSOC_GPIO_BANK_SIZE * SIRFSOC_GPIO_NO_OF_BANKS; | ||
862 | sgpio_chip.chip.gc.label = kstrdup(np->full_name, GFP_KERNEL); | ||
863 | sgpio_chip.chip.gc.of_node = np; | ||
864 | sgpio_chip.chip.gc.of_xlate = sirfsoc_gpio_of_xlate; | ||
865 | sgpio_chip.chip.gc.of_gpio_n_cells = 2; | ||
866 | sgpio_chip.chip.gc.dev = &pdev->dev; | ||
867 | sgpio_chip.chip.regs = regs; | ||
868 | sgpio_chip.is_marco = is_marco; | ||
869 | sgpio_chip.domain = domain; | ||
870 | |||
871 | err = gpiochip_add(&sgpio_chip.chip.gc); | ||
872 | if (err) { | ||
873 | pr_err("%s: error in probe function with status %d\n", | ||
874 | np->full_name, err); | ||
875 | goto out; | ||
876 | } | ||
877 | |||
887 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { | 878 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { |
888 | bank = &sgpio_bank[i]; | 879 | bank = &sgpio_chip.sgpio_bank[i]; |
889 | spin_lock_init(&bank->lock); | 880 | spin_lock_init(&bank->lock); |
890 | bank->chip.gc.request = sirfsoc_gpio_request; | ||
891 | bank->chip.gc.free = sirfsoc_gpio_free; | ||
892 | bank->chip.gc.direction_input = sirfsoc_gpio_direction_input; | ||
893 | bank->chip.gc.get = sirfsoc_gpio_get_value; | ||
894 | bank->chip.gc.direction_output = sirfsoc_gpio_direction_output; | ||
895 | bank->chip.gc.set = sirfsoc_gpio_set_value; | ||
896 | bank->chip.gc.to_irq = sirfsoc_gpio_to_irq; | ||
897 | bank->chip.gc.base = i * SIRFSOC_GPIO_BANK_SIZE; | ||
898 | bank->chip.gc.ngpio = SIRFSOC_GPIO_BANK_SIZE; | ||
899 | bank->chip.gc.label = kstrdup(np->full_name, GFP_KERNEL); | ||
900 | bank->chip.gc.of_node = np; | ||
901 | bank->chip.gc.of_xlate = sirfsoc_gpio_of_xlate; | ||
902 | bank->chip.gc.of_gpio_n_cells = 2; | ||
903 | bank->chip.gc.dev = &pdev->dev; | ||
904 | bank->chip.regs = regs; | ||
905 | bank->id = i; | ||
906 | bank->is_marco = is_marco; | ||
907 | bank->parent_irq = platform_get_irq(pdev, i); | 881 | bank->parent_irq = platform_get_irq(pdev, i); |
908 | if (bank->parent_irq < 0) { | 882 | if (bank->parent_irq < 0) { |
909 | err = bank->parent_irq; | 883 | err = bank->parent_irq; |
910 | goto out; | 884 | goto out; |
911 | } | 885 | } |
912 | 886 | ||
913 | err = gpiochip_add(&bank->chip.gc); | ||
914 | if (err) { | ||
915 | pr_err("%s: error in probe function with status %d\n", | ||
916 | np->full_name, err); | ||
917 | goto out; | ||
918 | } | ||
919 | |||
920 | bank->domain = domain; | ||
921 | |||
922 | irq_set_chained_handler(bank->parent_irq, sirfsoc_gpio_handle_irq); | 887 | irq_set_chained_handler(bank->parent_irq, sirfsoc_gpio_handle_irq); |
923 | irq_set_handler_data(bank->parent_irq, bank); | 888 | irq_set_handler_data(bank->parent_irq, bank); |
924 | } | 889 | } |