aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2013-01-31 05:43:00 -0500
committerLinus Walleij <linus.walleij@linaro.org>2013-02-10 09:14:13 -0500
commitac652d7941f84c24cb27378aefbb4015f4c1da67 (patch)
treee0ab3c787f478562d41112710ac0aa18ae03c80a /drivers/pinctrl
parent7ac63ac61d67703aba1add4a89c4de702068d2f2 (diff)
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>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r--drivers/pinctrl/pinctrl-abx500.c299
1 files changed, 3 insertions, 296 deletions
diff --git a/drivers/pinctrl/pinctrl-abx500.c b/drivers/pinctrl/pinctrl-abx500.c
index 0b3aa1c28fba..b8f6c7597d53 100644
--- a/drivers/pinctrl/pinctrl-abx500.c
+++ b/drivers/pinctrl/pinctrl-abx500.c
@@ -19,6 +19,7 @@
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/gpio.h> 20#include <linux/gpio.h>
21#include <linux/irq.h> 21#include <linux/irq.h>
22#include <linux/irqdomain.h>
22#include <linux/interrupt.h> 23#include <linux/interrupt.h>
23#include <linux/bitops.h> 24#include <linux/bitops.h>
24#include <linux/mfd/abx500.h> 25#include <linux/mfd/abx500.h>
@@ -87,20 +88,11 @@
87#define AB8540_GPIO_VINSEL_REG 0x47 88#define AB8540_GPIO_VINSEL_REG 0x47
88#define AB8540_GPIO_PULL_UPDOWN_REG 0x48 89#define AB8540_GPIO_PULL_UPDOWN_REG 0x48
89#define AB8500_GPIO_ALTFUN_REG 0x50 90#define AB8500_GPIO_ALTFUN_REG 0x50
90#define AB8500_NUM_VIR_GPIO_IRQ 16
91#define AB8540_GPIO_PULL_UPDOWN_MASK 0x03 91#define AB8540_GPIO_PULL_UPDOWN_MASK 0x03
92#define AB8540_GPIO_VINSEL_MASK 0x03 92#define AB8540_GPIO_VINSEL_MASK 0x03
93#define AB8540_GPIOX_VBAT_START 51 93#define AB8540_GPIOX_VBAT_START 51
94#define AB8540_GPIOX_VBAT_END 54 94#define AB8540_GPIOX_VBAT_END 54
95 95
96enum abx500_gpio_action {
97 NONE,
98 STARTUP,
99 SHUTDOWN,
100 MASK,
101 UNMASK
102};
103
104struct abx500_pinctrl { 96struct abx500_pinctrl {
105 struct device *dev; 97 struct device *dev;
106 struct pinctrl_dev *pctldev; 98 struct pinctrl_dev *pctldev;
@@ -109,14 +101,8 @@ struct abx500_pinctrl {
109 struct ab8500 *parent; 101 struct ab8500 *parent;
110 struct mutex lock; 102 struct mutex lock;
111 u32 irq_base; 103 u32 irq_base;
112 enum abx500_gpio_action irq_action;
113 u16 rising;
114 u16 falling;
115 struct abx500_gpio_irq_cluster *irq_cluster; 104 struct abx500_gpio_irq_cluster *irq_cluster;
116 int irq_cluster_size; 105 int irq_cluster_size;
117 int irq_gpio_rising_offset;
118 int irq_gpio_falling_offset;
119 int irq_gpio_factor;
120}; 106};
121 107
122/** 108/**
@@ -473,7 +459,6 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s,
473 struct gpio_chip *chip, 459 struct gpio_chip *chip,
474 unsigned offset, unsigned gpio) 460 unsigned offset, unsigned gpio)
475{ 461{
476 struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
477 const char *label = gpiochip_is_requested(chip, offset - 1); 462 const char *label = gpiochip_is_requested(chip, offset - 1);
478 u8 gpio_offset = offset - 1; 463 u8 gpio_offset = offset - 1;
479 int mode = -1; 464 int mode = -1;
@@ -502,25 +487,6 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s,
502 : "? ") 487 : "? ")
503 : (pull ? "pull up" : "pull down"), 488 : (pull ? "pull up" : "pull down"),
504 (mode < 0) ? "unknown" : modes[mode]); 489 (mode < 0) ? "unknown" : modes[mode]);
505
506 if (label && !is_out) {
507 int irq = gpio_to_irq(gpio);
508 struct irq_desc *desc = irq_to_desc(irq);
509
510 if (irq >= 0 && desc->action) {
511 char *trigger;
512 int irq_offset = irq - pct->irq_base;
513
514 if (pct->rising & BIT(irq_offset))
515 trigger = "edge-rising";
516 else if (pct->falling & BIT(irq_offset))
517 trigger = "edge-falling";
518 else
519 trigger = "edge-undefined";
520
521 seq_printf(s, " irq-%d %s", irq, trigger);
522 }
523 }
524} 490}
525 491
526static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 492static void abx500_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
@@ -574,219 +540,6 @@ static struct gpio_chip abx500gpio_chip = {
574 .dbg_show = abx500_gpio_dbg_show, 540 .dbg_show = abx500_gpio_dbg_show,
575}; 541};
576 542
577static unsigned int irq_to_rising(unsigned int irq)
578{
579 struct abx500_pinctrl *pct = irq_get_chip_data(irq);
580 int offset = irq - pct->irq_base;
581 int new_irq;
582
583 new_irq = offset * pct->irq_gpio_factor
584 + pct->irq_gpio_rising_offset
585 + pct->parent->irq_base;
586
587 return new_irq;
588}
589
590static unsigned int irq_to_falling(unsigned int irq)
591{
592 struct abx500_pinctrl *pct = irq_get_chip_data(irq);
593 int offset = irq - pct->irq_base;
594 int new_irq;
595
596 new_irq = offset * pct->irq_gpio_factor
597 + pct->irq_gpio_falling_offset
598 + pct->parent->irq_base;
599 return new_irq;
600
601}
602
603static unsigned int rising_to_irq(unsigned int irq, void *dev)
604{
605 struct abx500_pinctrl *pct = dev;
606 int offset, new_irq;
607
608 offset = irq - pct->irq_gpio_rising_offset
609 - pct->parent->irq_base;
610 new_irq = (offset / pct->irq_gpio_factor)
611 + pct->irq_base;
612
613 return new_irq;
614}
615
616static unsigned int falling_to_irq(unsigned int irq, void *dev)
617{
618 struct abx500_pinctrl *pct = dev;
619 int offset, new_irq;
620
621 offset = irq - pct->irq_gpio_falling_offset
622 - pct->parent->irq_base;
623 new_irq = (offset / pct->irq_gpio_factor)
624 + pct->irq_base;
625
626 return new_irq;
627}
628
629/*
630 * IRQ handler
631 */
632
633static irqreturn_t handle_rising(int irq, void *dev)
634{
635
636 handle_nested_irq(rising_to_irq(irq , dev));
637 return IRQ_HANDLED;
638}
639
640static irqreturn_t handle_falling(int irq, void *dev)
641{
642
643 handle_nested_irq(falling_to_irq(irq, dev));
644 return IRQ_HANDLED;
645}
646
647static void abx500_gpio_irq_lock(struct irq_data *data)
648{
649 struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
650 mutex_lock(&pct->lock);
651}
652
653static void abx500_gpio_irq_sync_unlock(struct irq_data *data)
654{
655 struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
656 unsigned int irq = data->irq;
657 int offset = irq - pct->irq_base;
658 bool rising = pct->rising & BIT(offset);
659 bool falling = pct->falling & BIT(offset);
660 int ret;
661
662 switch (pct->irq_action) {
663 case STARTUP:
664 if (rising)
665 ret = request_threaded_irq(irq_to_rising(irq),
666 NULL, handle_rising,
667 IRQF_TRIGGER_RISING | IRQF_NO_SUSPEND,
668 "abx500-gpio-r", pct);
669 if (falling)
670 ret = request_threaded_irq(irq_to_falling(irq),
671 NULL, handle_falling,
672 IRQF_TRIGGER_FALLING | IRQF_NO_SUSPEND,
673 "abx500-gpio-f", pct);
674 break;
675 case SHUTDOWN:
676 if (rising)
677 free_irq(irq_to_rising(irq), pct);
678 if (falling)
679 free_irq(irq_to_falling(irq), pct);
680 break;
681 case MASK:
682 if (rising)
683 disable_irq(irq_to_rising(irq));
684 if (falling)
685 disable_irq(irq_to_falling(irq));
686 break;
687 case UNMASK:
688 if (rising)
689 enable_irq(irq_to_rising(irq));
690 if (falling)
691 enable_irq(irq_to_falling(irq));
692 break;
693 case NONE:
694 break;
695 }
696 pct->irq_action = NONE;
697 pct->rising &= ~(BIT(offset));
698 pct->falling &= ~(BIT(offset));
699 mutex_unlock(&pct->lock);
700}
701
702
703static void abx500_gpio_irq_mask(struct irq_data *data)
704{
705 struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
706 pct->irq_action = MASK;
707}
708
709static void abx500_gpio_irq_unmask(struct irq_data *data)
710{
711 struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
712 pct->irq_action = UNMASK;
713}
714
715static int abx500_gpio_irq_set_type(struct irq_data *data, unsigned int type)
716{
717 struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
718 unsigned int irq = data->irq;
719 int offset = irq - pct->irq_base;
720
721 if (type == IRQ_TYPE_EDGE_BOTH) {
722 pct->rising = BIT(offset);
723 pct->falling = BIT(offset);
724 } else if (type == IRQ_TYPE_EDGE_RISING) {
725 pct->rising = BIT(offset);
726 } else {
727 pct->falling = BIT(offset);
728 }
729 return 0;
730}
731
732static unsigned int abx500_gpio_irq_startup(struct irq_data *data)
733{
734 struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
735 pct->irq_action = STARTUP;
736 return 0;
737}
738
739static void abx500_gpio_irq_shutdown(struct irq_data *data)
740{
741 struct abx500_pinctrl *pct = irq_data_get_irq_chip_data(data);
742 pct->irq_action = SHUTDOWN;
743}
744
745static struct irq_chip abx500_gpio_irq_chip = {
746 .name = "abx500-gpio",
747 .irq_startup = abx500_gpio_irq_startup,
748 .irq_shutdown = abx500_gpio_irq_shutdown,
749 .irq_bus_lock = abx500_gpio_irq_lock,
750 .irq_bus_sync_unlock = abx500_gpio_irq_sync_unlock,
751 .irq_mask = abx500_gpio_irq_mask,
752 .irq_unmask = abx500_gpio_irq_unmask,
753 .irq_set_type = abx500_gpio_irq_set_type,
754};
755
756static int abx500_gpio_irq_init(struct abx500_pinctrl *pct)
757{
758 u32 base = pct->irq_base;
759 int irq;
760
761 for (irq = base; irq < base + AB8500_NUM_VIR_GPIO_IRQ ; irq++) {
762 irq_set_chip_data(irq, pct);
763 irq_set_chip_and_handler(irq, &abx500_gpio_irq_chip,
764 handle_simple_irq);
765 irq_set_nested_thread(irq, 1);
766#ifdef CONFIG_ARM
767 set_irq_flags(irq, IRQF_VALID);
768#else
769 irq_set_noprobe(irq);
770#endif
771 }
772
773 return 0;
774}
775
776static void abx500_gpio_irq_remove(struct abx500_pinctrl *pct)
777{
778 int base = pct->irq_base;
779 int irq;
780
781 for (irq = base; irq < base + AB8500_NUM_VIR_GPIO_IRQ; irq++) {
782#ifdef CONFIG_ARM
783 set_irq_flags(irq, 0);
784#endif
785 irq_set_chip_and_handler(irq, NULL, NULL);
786 irq_set_chip_data(irq, NULL);
787 }
788}
789
790static int abx500_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev) 543static int abx500_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev)
791{ 544{
792 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); 545 struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev);
@@ -815,43 +568,6 @@ static int abx500_pmx_get_func_groups(struct pinctrl_dev *pctldev,
815 return 0; 568 return 0;
816} 569}
817 570
818static void abx500_disable_lazy_irq(struct gpio_chip *chip, unsigned gpio)
819{
820 struct abx500_pinctrl *pct = to_abx500_pinctrl(chip);
821 int irq;
822 int offset;
823 bool rising;
824 bool falling;
825
826 /*
827 * check if gpio has interrupt capability and convert
828 * gpio number to irq
829 * On ABx5xx, there is no GPIO0, GPIO1 is the
830 * first one, so adjust gpio number
831 */
832 gpio--;
833 irq = gpio_to_irq(gpio + chip->base);
834 if (irq < 0)
835 return;
836
837 offset = irq - pct->irq_base;
838 rising = pct->rising & BIT(offset);
839 falling = pct->falling & BIT(offset);
840
841 /* nothing to do ?*/
842 if (!rising && !falling)
843 return;
844
845 if (rising) {
846 disable_irq(irq_to_rising(irq));
847 free_irq(irq_to_rising(irq), pct);
848 }
849 if (falling) {
850 disable_irq(irq_to_falling(irq));
851 free_irq(irq_to_falling(irq), pct);
852 }
853}
854
855static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function, 571static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
856 unsigned group) 572 unsigned group)
857{ 573{
@@ -871,7 +587,6 @@ static int abx500_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
871 dev_dbg(pct->dev, "setting pin %d to altsetting %d\n", 587 dev_dbg(pct->dev, "setting pin %d to altsetting %d\n",
872 g->pins[i], g->altsetting); 588 g->pins[i], g->altsetting);
873 589
874 abx500_disable_lazy_irq(chip, g->pins[i]);
875 ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting); 590 ret = abx500_set_mode(pctldev, chip, g->pins[i], g->altsetting);
876 } 591 }
877 592
@@ -1197,18 +912,12 @@ static int abx500_gpio_probe(struct platform_device *pdev)
1197 pct->chip.ngpio = abx500_get_gpio_num(pct->soc); 912 pct->chip.ngpio = abx500_get_gpio_num(pct->soc);
1198 pct->irq_cluster = pct->soc->gpio_irq_cluster; 913 pct->irq_cluster = pct->soc->gpio_irq_cluster;
1199 pct->irq_cluster_size = pct->soc->ngpio_irq_cluster; 914 pct->irq_cluster_size = pct->soc->ngpio_irq_cluster;
1200 pct->irq_gpio_rising_offset = pct->soc->irq_gpio_rising_offset;
1201 pct->irq_gpio_falling_offset = pct->soc->irq_gpio_falling_offset;
1202 pct->irq_gpio_factor = pct->soc->irq_gpio_factor;
1203 915
1204 ret = abx500_gpio_irq_init(pct);
1205 if (ret)
1206 goto out_free;
1207 ret = gpiochip_add(&pct->chip); 916 ret = gpiochip_add(&pct->chip);
1208 if (ret) { 917 if (ret) {
1209 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 918 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
1210 mutex_destroy(&pct->lock); 919 mutex_destroy(&pct->lock);
1211 goto out_rem_irq; 920 return ret;
1212 } 921 }
1213 dev_info(&pdev->dev, "added gpiochip\n"); 922 dev_info(&pdev->dev, "added gpiochip\n");
1214 923
@@ -1243,9 +952,7 @@ out_rem_chip:
1243 err = gpiochip_remove(&pct->chip); 952 err = gpiochip_remove(&pct->chip);
1244 if (err) 953 if (err)
1245 dev_info(&pdev->dev, "failed to remove gpiochip\n"); 954 dev_info(&pdev->dev, "failed to remove gpiochip\n");
1246out_rem_irq: 955
1247 abx500_gpio_irq_remove(pct);
1248out_free:
1249 mutex_destroy(&pct->lock); 956 mutex_destroy(&pct->lock);
1250 return ret; 957 return ret;
1251} 958}