Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl/abx500: move IRQ handling to ab8500-core

In its current state the gpio-ab8500 driver looks after some GPIO
lines found on the AB8500 MFD chip. It also controls all of its
own IRQ handling for these GPIOs by inventing some virtual IRQs
and handing those out to sub-devices. There has been quite a bit
of controversy over this and it was a contributing factor to the
driver being marked as BROKEN in Mainline.

The reason for adopting this method was due to added complexity
in the hardware. Unusually, each GPIO has two separate IRQs
associated with it, one for a rising and a different one for a
falling interrupt. Using this method complicates matters further
because the GPIO IRQs are actually sandwiched between a bunch
of IRQs which are handled solely by the AB8500 core driver.

The best way for us to take this forward is to get rid of the
virtual IRQs and only hand out the rising IRQ lines. If a
sub-driver wishes to request a falling interrupt, they can do
so by requesting a rising line in the normal way. They just
have to add IRQ_TYPE_EDGE_FALLING or IRQ_TYPE_EDGE_BOTH, if
they require both in the flags. Then if a falling IRQ is
triggered, the AB8500 core driver will know how to handle the
added complexity accordingly. This should greatly simply things.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
[Augment to keep irq_base for a while (removed later)]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Lee Jones and committed by
Linus Walleij
ac652d79 7ac63ac6

+3 -296
+3 -296
drivers/pinctrl/pinctrl-abx500.c
··· 19 19 #include <linux/platform_device.h> 20 20 #include <linux/gpio.h> 21 21 #include <linux/irq.h> 22 + #include <linux/irqdomain.h> 22 23 #include <linux/interrupt.h> 23 24 #include <linux/bitops.h> 24 25 #include <linux/mfd/abx500.h> ··· 88 87 #define AB8540_GPIO_VINSEL_REG 0x47 89 88 #define AB8540_GPIO_PULL_UPDOWN_REG 0x48 90 89 #define AB8500_GPIO_ALTFUN_REG 0x50 91 - #define AB8500_NUM_VIR_GPIO_IRQ 16 92 90 #define AB8540_GPIO_PULL_UPDOWN_MASK 0x03 93 91 #define AB8540_GPIO_VINSEL_MASK 0x03 94 92 #define AB8540_GPIOX_VBAT_START 51 95 93 #define AB8540_GPIOX_VBAT_END 54 96 - 97 - enum abx500_gpio_action { 98 - NONE, 99 - STARTUP, 100 - SHUTDOWN, 101 - MASK, 102 - UNMASK 103 - }; 104 94 105 95 struct abx500_pinctrl { 106 96 struct device *dev; ··· 101 109 struct ab8500 *parent; 102 110 struct mutex lock; 103 111 u32 irq_base; 104 - enum abx500_gpio_action irq_action; 105 - u16 rising; 106 - u16 falling; 107 112 struct abx500_gpio_irq_cluster *irq_cluster; 108 113 int irq_cluster_size; 109 - int irq_gpio_rising_offset; 110 - int irq_gpio_falling_offset; 111 - int irq_gpio_factor; 112 114 }; 113 115 114 116 /** ··· 459 473 struct gpio_chip *chip, 460 474 unsigned offset, unsigned gpio) 461 475 { 462 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 463 476 const char *label = gpiochip_is_requested(chip, offset - 1); 464 477 u8 gpio_offset = offset - 1; 465 478 int mode = -1; ··· 487 502 : "? ") 488 503 : (pull ? "pull up" : "pull down"), 489 504 (mode < 0) ? "unknown" : modes[mode]); 490 - 491 - if (label && !is_out) { 492 - int irq = gpio_to_irq(gpio); 493 - struct irq_desc *desc = irq_to_desc(irq); 494 - 495 - if (irq >= 0 && desc->action) { 496 - char *trigger; 497 - int irq_offset = irq - pct->irq_base; 498 - 499 - if (pct->rising & BIT(irq_offset)) 500 - trigger = "edge-rising"; 501 - else if (pct->falling & BIT(irq_offset)) 502 - trigger = "edge-falling"; 503 - else 504 - trigger = "edge-undefined"; 505 - 506 - seq_printf(s, " irq-%d %s", irq, trigger); 507 - } 508 - } 509 505 } 510 506 511 507 static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) ··· 540 574 .dbg_show = abx500_gpio_dbg_show, 541 575 }; 542 576 543 - static unsigned int irq_to_rising(unsigned int irq) 544 - { 545 - struct abx500_pinctrl *pct = irq_get_chip_data(irq); 546 - int offset = irq - pct->irq_base; 547 - int new_irq; 548 - 549 - new_irq = offset * pct->irq_gpio_factor 550 - + pct->irq_gpio_rising_offset 551 - + pct->parent->irq_base; 552 - 553 - return new_irq; 554 - } 555 - 556 - static unsigned int irq_to_falling(unsigned int irq) 557 - { 558 - struct abx500_pinctrl *pct = irq_get_chip_data(irq); 559 - int offset = irq - pct->irq_base; 560 - int new_irq; 561 - 562 - new_irq = offset * pct->irq_gpio_factor 563 - + pct->irq_gpio_falling_offset 564 - + pct->parent->irq_base; 565 - return new_irq; 566 - 567 - } 568 - 569 - static unsigned int rising_to_irq(unsigned int irq, void *dev) 570 - { 571 - struct abx500_pinctrl *pct = dev; 572 - int offset, new_irq; 573 - 574 - offset = irq - pct->irq_gpio_rising_offset 575 - - pct->parent->irq_base; 576 - new_irq = (offset / pct->irq_gpio_factor) 577 - + pct->irq_base; 578 - 579 - return new_irq; 580 - } 581 - 582 - static unsigned int falling_to_irq(unsigned int irq, void *dev) 583 - { 584 - struct abx500_pinctrl *pct = dev; 585 - int offset, new_irq; 586 - 587 - offset = irq - pct->irq_gpio_falling_offset 588 - - pct->parent->irq_base; 589 - new_irq = (offset / pct->irq_gpio_factor) 590 - + pct->irq_base; 591 - 592 - return new_irq; 593 - } 594 - 595 - /* 596 - * IRQ handler 597 - */ 598 - 599 - static irqreturn_t handle_rising(int irq, void *dev) 600 - { 601 - 602 - handle_nested_irq(rising_to_irq(irq , dev)); 603 - return IRQ_HANDLED; 604 - } 605 - 606 - static irqreturn_t handle_falling(int irq, void *dev) 607 - { 608 - 609 - handle_nested_irq(falling_to_irq(irq, dev)); 610 - return IRQ_HANDLED; 611 - } 612 - 613 - static void abx500_gpio_irq_lock(struct irq_data *data) 614 - { 615 - struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data); 616 - mutex_lock(&pct->lock); 617 - } 618 - 619 - static void abx500_gpio_irq_sync_unlock(struct irq_data *data) 620 - { 621 - struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data); 622 - unsigned int irq = data->irq; 623 - int offset = irq - pct->irq_base; 624 - bool rising = pct->rising & BIT(offset); 625 - bool falling = pct->falling & BIT(offset); 626 - int ret; 627 - 628 - switch (pct->irq_action) { 629 - case STARTUP: 630 - if (rising) 631 - ret = request_threaded_irq(irq_to_rising(irq), 632 - NULL, handle_rising, 633 - IRQF_TRIGGER_RISING | IRQF_NO_SUSPEND, 634 - "abx500-gpio-r", pct); 635 - if (falling) 636 - ret = request_threaded_irq(irq_to_falling(irq), 637 - NULL, handle_falling, 638 - IRQF_TRIGGER_FALLING | IRQF_NO_SUSPEND, 639 - "abx500-gpio-f", pct); 640 - break; 641 - case SHUTDOWN: 642 - if (rising) 643 - free_irq(irq_to_rising(irq), pct); 644 - if (falling) 645 - free_irq(irq_to_falling(irq), pct); 646 - break; 647 - case MASK: 648 - if (rising) 649 - disable_irq(irq_to_rising(irq)); 650 - if (falling) 651 - disable_irq(irq_to_falling(irq)); 652 - break; 653 - case UNMASK: 654 - if (rising) 655 - enable_irq(irq_to_rising(irq)); 656 - if (falling) 657 - enable_irq(irq_to_falling(irq)); 658 - break; 659 - case NONE: 660 - break; 661 - } 662 - pct->irq_action = NONE; 663 - pct->rising &= ~(BIT(offset)); 664 - pct->falling &= ~(BIT(offset)); 665 - mutex_unlock(&pct->lock); 666 - } 667 - 668 - 669 - static void abx500_gpio_irq_mask(struct irq_data *data) 670 - { 671 - struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data); 672 - pct->irq_action = MASK; 673 - } 674 - 675 - static void abx500_gpio_irq_unmask(struct irq_data *data) 676 - { 677 - struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data); 678 - pct->irq_action = UNMASK; 679 - } 680 - 681 - static int abx500_gpio_irq_set_type(struct irq_data *data, unsigned int type) 682 - { 683 - struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data); 684 - unsigned int irq = data->irq; 685 - int offset = irq - pct->irq_base; 686 - 687 - if (type == IRQ_TYPE_EDGE_BOTH) { 688 - pct->rising = BIT(offset); 689 - pct->falling = BIT(offset); 690 - } else if (type == IRQ_TYPE_EDGE_RISING) { 691 - pct->rising = BIT(offset); 692 - } else { 693 - pct->falling = BIT(offset); 694 - } 695 - return 0; 696 - } 697 - 698 - static unsigned int abx500_gpio_irq_startup(struct irq_data *data) 699 - { 700 - struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data); 701 - pct->irq_action = STARTUP; 702 - return 0; 703 - } 704 - 705 - static void abx500_gpio_irq_shutdown(struct irq_data *data) 706 - { 707 - struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data); 708 - pct->irq_action = SHUTDOWN; 709 - } 710 - 711 - static struct irq_chip abx500_gpio_irq_chip = { 712 - .name = "abx500-gpio", 713 - .irq_startup = abx500_gpio_irq_startup, 714 - .irq_shutdown = abx500_gpio_irq_shutdown, 715 - .irq_bus_lock = abx500_gpio_irq_lock, 716 - .irq_bus_sync_unlock = abx500_gpio_irq_sync_unlock, 717 - .irq_mask = abx500_gpio_irq_mask, 718 - .irq_unmask = abx500_gpio_irq_unmask, 719 - .irq_set_type = abx500_gpio_irq_set_type, 720 - }; 721 - 722 - static int abx500_gpio_irq_init(struct abx500_pinctrl *pct) 723 - { 724 - u32 base = pct->irq_base; 725 - int irq; 726 - 727 - for (irq = base; irq < base + AB8500_NUM_VIR_GPIO_IRQ ; irq++) { 728 - irq_set_chip_data(irq, pct); 729 - irq_set_chip_and_handler(irq, &abx500_gpio_irq_chip, 730 - handle_simple_irq); 731 - irq_set_nested_thread(irq, 1); 732 - #ifdef CONFIG_ARM 733 - set_irq_flags(irq, IRQF_VALID); 734 - #else 735 - irq_set_noprobe(irq); 736 - #endif 737 - } 738 - 739 - return 0; 740 - } 741 - 742 - static void abx500_gpio_irq_remove(struct abx500_pinctrl *pct) 743 - { 744 - int base = pct->irq_base; 745 - int irq; 746 - 747 - for (irq = base; irq < base + AB8500_NUM_VIR_GPIO_IRQ; irq++) { 748 - #ifdef CONFIG_ARM 749 - set_irq_flags(irq, 0); 750 - #endif 751 - irq_set_chip_and_handler(irq, NULL, NULL); 752 - irq_set_chip_data(irq, NULL); 753 - } 754 - } 755 - 756 577 static int abx500_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev) 757 578 { 758 579 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); ··· 568 815 return 0; 569 816 } 570 817 571 - static void abx500_disable_lazy_irq(struct gpio_chip *chip, unsigned gpio) 572 - { 573 - struct abx500_pinctrl *pct = to_abx500_pinctrl(chip); 574 - int irq; 575 - int offset; 576 - bool rising; 577 - bool falling; 578 - 579 - /* 580 - * check if gpio has interrupt capability and convert 581 - * gpio number to irq 582 - * On ABx5xx, there is no GPIO0, GPIO1 is the 583 - * first one, so adjust gpio number 584 - */ 585 - gpio--; 586 - irq = gpio_to_irq(gpio + chip->base); 587 - if (irq < 0) 588 - return; 589 - 590 - offset = irq - pct->irq_base; 591 - rising = pct->rising & BIT(offset); 592 - falling = pct->falling & BIT(offset); 593 - 594 - /* nothing to do ?*/ 595 - if (!rising && !falling) 596 - return; 597 - 598 - if (rising) { 599 - disable_irq(irq_to_rising(irq)); 600 - free_irq(irq_to_rising(irq), pct); 601 - } 602 - if (falling) { 603 - disable_irq(irq_to_falling(irq)); 604 - free_irq(irq_to_falling(irq), pct); 605 - } 606 - } 607 - 608 818 static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function, 609 819 unsigned group) 610 820 { ··· 587 871 dev_dbg(pct->dev, "setting pin %d to altsetting %d\n", 588 872 g->pins[i], g->altsetting); 589 873 590 - abx500_disable_lazy_irq(chip, g->pins[i]); 591 874 ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting); 592 875 } 593 876 ··· 912 1197 pct->chip.ngpio = abx500_get_gpio_num(pct->soc); 913 1198 pct->irq_cluster = pct->soc->gpio_irq_cluster; 914 1199 pct->irq_cluster_size = pct->soc->ngpio_irq_cluster; 915 - pct->irq_gpio_rising_offset = pct->soc->irq_gpio_rising_offset; 916 - pct->irq_gpio_falling_offset = pct->soc->irq_gpio_falling_offset; 917 - pct->irq_gpio_factor = pct->soc->irq_gpio_factor; 918 1200 919 - ret = abx500_gpio_irq_init(pct); 920 - if (ret) 921 - goto out_free; 922 1201 ret = gpiochip_add(&pct->chip); 923 1202 if (ret) { 924 1203 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 925 1204 mutex_destroy(&pct->lock); 926 - goto out_rem_irq; 1205 + return ret; 927 1206 } 928 1207 dev_info(&pdev->dev, "added gpiochip\n"); 929 1208 ··· 952 1243 err = gpiochip_remove(&pct->chip); 953 1244 if (err) 954 1245 dev_info(&pdev->dev, "failed to remove gpiochip\n"); 955 - out_rem_irq: 956 - abx500_gpio_irq_remove(pct); 957 - out_free: 1246 + 958 1247 mutex_destroy(&pct->lock); 959 1248 return ret; 960 1249 }