aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-omap.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio/gpio-omap.c')
-rw-r--r--drivers/gpio/gpio-omap.c131
1 files changed, 55 insertions, 76 deletions
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index f476ae2eb0b3..cd1d5bf48f36 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -75,14 +75,12 @@ struct gpio_bank {
75 int power_mode; 75 int power_mode;
76 bool workaround_enabled; 76 bool workaround_enabled;
77 77
78 void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable); 78 void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable);
79 int (*get_context_loss_count)(struct device *dev); 79 int (*get_context_loss_count)(struct device *dev);
80 80
81 struct omap_gpio_reg_offs *regs; 81 struct omap_gpio_reg_offs *regs;
82}; 82};
83 83
84#define GPIO_INDEX(bank, gpio) (gpio % bank->width)
85#define GPIO_BIT(bank, gpio) (BIT(GPIO_INDEX(bank, gpio)))
86#define GPIO_MOD_CTRL_BIT BIT(0) 84#define GPIO_MOD_CTRL_BIT BIT(0)
87 85
88#define BANK_USED(bank) (bank->mod_usage || bank->irq_usage) 86#define BANK_USED(bank) (bank->mod_usage || bank->irq_usage)
@@ -90,11 +88,6 @@ struct gpio_bank {
90 88
91static void omap_gpio_unmask_irq(struct irq_data *d); 89static void omap_gpio_unmask_irq(struct irq_data *d);
92 90
93static int omap_irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq)
94{
95 return bank->chip.base + gpio_irq;
96}
97
98static inline struct gpio_bank *omap_irq_data_get_bank(struct irq_data *d) 91static inline struct gpio_bank *omap_irq_data_get_bank(struct irq_data *d)
99{ 92{
100 struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 93 struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
@@ -119,11 +112,11 @@ static void omap_set_gpio_direction(struct gpio_bank *bank, int gpio,
119 112
120 113
121/* set data out value using dedicate set/clear register */ 114/* set data out value using dedicate set/clear register */
122static void omap_set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, 115static void omap_set_gpio_dataout_reg(struct gpio_bank *bank, unsigned offset,
123 int enable) 116 int enable)
124{ 117{
125 void __iomem *reg = bank->base; 118 void __iomem *reg = bank->base;
126 u32 l = GPIO_BIT(bank, gpio); 119 u32 l = BIT(offset);
127 120
128 if (enable) { 121 if (enable) {
129 reg += bank->regs->set_dataout; 122 reg += bank->regs->set_dataout;
@@ -137,11 +130,11 @@ static void omap_set_gpio_dataout_reg(struct gpio_bank *bank, int gpio,
137} 130}
138 131
139/* set data out value using mask register */ 132/* set data out value using mask register */
140static void omap_set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, 133static void omap_set_gpio_dataout_mask(struct gpio_bank *bank, unsigned offset,
141 int enable) 134 int enable)
142{ 135{
143 void __iomem *reg = bank->base + bank->regs->dataout; 136 void __iomem *reg = bank->base + bank->regs->dataout;
144 u32 gpio_bit = GPIO_BIT(bank, gpio); 137 u32 gpio_bit = BIT(offset);
145 u32 l; 138 u32 l;
146 139
147 l = readl_relaxed(reg); 140 l = readl_relaxed(reg);
@@ -208,13 +201,13 @@ static inline void omap_gpio_dbck_disable(struct gpio_bank *bank)
208/** 201/**
209 * omap2_set_gpio_debounce - low level gpio debounce time 202 * omap2_set_gpio_debounce - low level gpio debounce time
210 * @bank: the gpio bank we're acting upon 203 * @bank: the gpio bank we're acting upon
211 * @gpio: the gpio number on this @gpio 204 * @offset: the gpio number on this @bank
212 * @debounce: debounce time to use 205 * @debounce: debounce time to use
213 * 206 *
214 * OMAP's debounce time is in 31us steps so we need 207 * OMAP's debounce time is in 31us steps so we need
215 * to convert and round up to the closest unit. 208 * to convert and round up to the closest unit.
216 */ 209 */
217static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned gpio, 210static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
218 unsigned debounce) 211 unsigned debounce)
219{ 212{
220 void __iomem *reg; 213 void __iomem *reg;
@@ -231,7 +224,7 @@ static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
231 else 224 else
232 debounce = (debounce / 0x1f) - 1; 225 debounce = (debounce / 0x1f) - 1;
233 226
234 l = GPIO_BIT(bank, gpio); 227 l = BIT(offset);
235 228
236 clk_prepare_enable(bank->dbck); 229 clk_prepare_enable(bank->dbck);
237 reg = bank->base + bank->regs->debounce; 230 reg = bank->base + bank->regs->debounce;
@@ -266,16 +259,16 @@ static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
266/** 259/**
267 * omap_clear_gpio_debounce - clear debounce settings for a gpio 260 * omap_clear_gpio_debounce - clear debounce settings for a gpio
268 * @bank: the gpio bank we're acting upon 261 * @bank: the gpio bank we're acting upon
269 * @gpio: the gpio number on this @gpio 262 * @offset: the gpio number on this @bank
270 * 263 *
271 * If a gpio is using debounce, then clear the debounce enable bit and if 264 * If a gpio is using debounce, then clear the debounce enable bit and if
272 * this is the only gpio in this bank using debounce, then clear the debounce 265 * this is the only gpio in this bank using debounce, then clear the debounce
273 * time too. The debounce clock will also be disabled when calling this function 266 * time too. The debounce clock will also be disabled when calling this function
274 * if this is the only gpio in the bank using debounce. 267 * if this is the only gpio in the bank using debounce.
275 */ 268 */
276static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned gpio) 269static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset)
277{ 270{
278 u32 gpio_bit = GPIO_BIT(bank, gpio); 271 u32 gpio_bit = BIT(offset);
279 272
280 if (!bank->dbck_flag) 273 if (!bank->dbck_flag)
281 return; 274 return;
@@ -472,42 +465,32 @@ static void omap_disable_gpio_module(struct gpio_bank *bank, unsigned offset)
472 } 465 }
473} 466}
474 467
475static int omap_gpio_is_input(struct gpio_bank *bank, int mask) 468static int omap_gpio_is_input(struct gpio_bank *bank, unsigned offset)
476{ 469{
477 void __iomem *reg = bank->base + bank->regs->direction; 470 void __iomem *reg = bank->base + bank->regs->direction;
478 471
479 return readl_relaxed(reg) & mask; 472 return readl_relaxed(reg) & BIT(offset);
480} 473}
481 474
482static void omap_gpio_init_irq(struct gpio_bank *bank, unsigned gpio, 475static void omap_gpio_init_irq(struct gpio_bank *bank, unsigned offset)
483 unsigned offset)
484{ 476{
485 if (!LINE_USED(bank->mod_usage, offset)) { 477 if (!LINE_USED(bank->mod_usage, offset)) {
486 omap_enable_gpio_module(bank, offset); 478 omap_enable_gpio_module(bank, offset);
487 omap_set_gpio_direction(bank, offset, 1); 479 omap_set_gpio_direction(bank, offset, 1);
488 } 480 }
489 bank->irq_usage |= BIT(GPIO_INDEX(bank, gpio)); 481 bank->irq_usage |= BIT(offset);
490} 482}
491 483
492static int omap_gpio_irq_type(struct irq_data *d, unsigned type) 484static int omap_gpio_irq_type(struct irq_data *d, unsigned type)
493{ 485{
494 struct gpio_bank *bank = omap_irq_data_get_bank(d); 486 struct gpio_bank *bank = omap_irq_data_get_bank(d);
495 unsigned gpio = 0;
496 int retval; 487 int retval;
497 unsigned long flags; 488 unsigned long flags;
498 unsigned offset; 489 unsigned offset = d->hwirq;
499 490
500 if (!BANK_USED(bank)) 491 if (!BANK_USED(bank))
501 pm_runtime_get_sync(bank->dev); 492 pm_runtime_get_sync(bank->dev);
502 493
503#ifdef CONFIG_ARCH_OMAP1
504 if (d->irq > IH_MPUIO_BASE)
505 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
506#endif
507
508 if (!gpio)
509 gpio = omap_irq_to_gpio(bank, d->hwirq);
510
511 if (type & ~IRQ_TYPE_SENSE_MASK) 494 if (type & ~IRQ_TYPE_SENSE_MASK)
512 return -EINVAL; 495 return -EINVAL;
513 496
@@ -516,10 +499,9 @@ static int omap_gpio_irq_type(struct irq_data *d, unsigned type)
516 return -EINVAL; 499 return -EINVAL;
517 500
518 spin_lock_irqsave(&bank->lock, flags); 501 spin_lock_irqsave(&bank->lock, flags);
519 offset = GPIO_INDEX(bank, gpio);
520 retval = omap_set_gpio_triggering(bank, offset, type); 502 retval = omap_set_gpio_triggering(bank, offset, type);
521 omap_gpio_init_irq(bank, gpio, offset); 503 omap_gpio_init_irq(bank, offset);
522 if (!omap_gpio_is_input(bank, BIT(offset))) { 504 if (!omap_gpio_is_input(bank, offset)) {
523 spin_unlock_irqrestore(&bank->lock, flags); 505 spin_unlock_irqrestore(&bank->lock, flags);
524 return -EINVAL; 506 return -EINVAL;
525 } 507 }
@@ -550,9 +532,10 @@ static void omap_clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
550 readl_relaxed(reg); 532 readl_relaxed(reg);
551} 533}
552 534
553static inline void omap_clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) 535static inline void omap_clear_gpio_irqstatus(struct gpio_bank *bank,
536 unsigned offset)
554{ 537{
555 omap_clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); 538 omap_clear_gpio_irqbank(bank, BIT(offset));
556} 539}
557 540
558static u32 omap_get_gpio_irqbank_mask(struct gpio_bank *bank) 541static u32 omap_get_gpio_irqbank_mask(struct gpio_bank *bank)
@@ -613,13 +596,13 @@ static void omap_disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
613 writel_relaxed(l, reg); 596 writel_relaxed(l, reg);
614} 597}
615 598
616static inline void omap_set_gpio_irqenable(struct gpio_bank *bank, int gpio, 599static inline void omap_set_gpio_irqenable(struct gpio_bank *bank,
617 int enable) 600 unsigned offset, int enable)
618{ 601{
619 if (enable) 602 if (enable)
620 omap_enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); 603 omap_enable_gpio_irqbank(bank, BIT(offset));
621 else 604 else
622 omap_disable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); 605 omap_disable_gpio_irqbank(bank, BIT(offset));
623} 606}
624 607
625/* 608/*
@@ -630,14 +613,16 @@ static inline void omap_set_gpio_irqenable(struct gpio_bank *bank, int gpio,
630 * enabled. When system is suspended, only selected GPIO interrupts need 613 * enabled. When system is suspended, only selected GPIO interrupts need
631 * to have wake-up enabled. 614 * to have wake-up enabled.
632 */ 615 */
633static int omap_set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) 616static int omap_set_gpio_wakeup(struct gpio_bank *bank, unsigned offset,
617 int enable)
634{ 618{
635 u32 gpio_bit = GPIO_BIT(bank, gpio); 619 u32 gpio_bit = BIT(offset);
636 unsigned long flags; 620 unsigned long flags;
637 621
638 if (bank->non_wakeup_gpios & gpio_bit) { 622 if (bank->non_wakeup_gpios & gpio_bit) {
639 dev_err(bank->dev, 623 dev_err(bank->dev,
640 "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio); 624 "Unable to modify wakeup on non-wakeup GPIO%d\n",
625 offset);
641 return -EINVAL; 626 return -EINVAL;
642 } 627 }
643 628
@@ -653,22 +638,22 @@ static int omap_set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
653 return 0; 638 return 0;
654} 639}
655 640
656static void omap_reset_gpio(struct gpio_bank *bank, int gpio) 641static void omap_reset_gpio(struct gpio_bank *bank, unsigned offset)
657{ 642{
658 omap_set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1); 643 omap_set_gpio_direction(bank, offset, 1);
659 omap_set_gpio_irqenable(bank, gpio, 0); 644 omap_set_gpio_irqenable(bank, offset, 0);
660 omap_clear_gpio_irqstatus(bank, gpio); 645 omap_clear_gpio_irqstatus(bank, offset);
661 omap_set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); 646 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
662 omap_clear_gpio_debounce(bank, gpio); 647 omap_clear_gpio_debounce(bank, offset);
663} 648}
664 649
665/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ 650/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
666static int omap_gpio_wake_enable(struct irq_data *d, unsigned int enable) 651static int omap_gpio_wake_enable(struct irq_data *d, unsigned int enable)
667{ 652{
668 struct gpio_bank *bank = omap_irq_data_get_bank(d); 653 struct gpio_bank *bank = omap_irq_data_get_bank(d);
669 unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq); 654 unsigned offset = d->hwirq;
670 655
671 return omap_set_gpio_wakeup(bank, gpio, enable); 656 return omap_set_gpio_wakeup(bank, offset, enable);
672} 657}
673 658
674static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) 659static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
@@ -706,7 +691,7 @@ static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
706 spin_lock_irqsave(&bank->lock, flags); 691 spin_lock_irqsave(&bank->lock, flags);
707 bank->mod_usage &= ~(BIT(offset)); 692 bank->mod_usage &= ~(BIT(offset));
708 omap_disable_gpio_module(bank, offset); 693 omap_disable_gpio_module(bank, offset);
709 omap_reset_gpio(bank, bank->chip.base + offset); 694 omap_reset_gpio(bank, offset);
710 spin_unlock_irqrestore(&bank->lock, flags); 695 spin_unlock_irqrestore(&bank->lock, flags);
711 696
712 /* 697 /*
@@ -803,15 +788,14 @@ exit:
803static unsigned int omap_gpio_irq_startup(struct irq_data *d) 788static unsigned int omap_gpio_irq_startup(struct irq_data *d)
804{ 789{
805 struct gpio_bank *bank = omap_irq_data_get_bank(d); 790 struct gpio_bank *bank = omap_irq_data_get_bank(d);
806 unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq);
807 unsigned long flags; 791 unsigned long flags;
808 unsigned offset = GPIO_INDEX(bank, gpio); 792 unsigned offset = d->hwirq;
809 793
810 if (!BANK_USED(bank)) 794 if (!BANK_USED(bank))
811 pm_runtime_get_sync(bank->dev); 795 pm_runtime_get_sync(bank->dev);
812 796
813 spin_lock_irqsave(&bank->lock, flags); 797 spin_lock_irqsave(&bank->lock, flags);
814 omap_gpio_init_irq(bank, gpio, offset); 798 omap_gpio_init_irq(bank, offset);
815 spin_unlock_irqrestore(&bank->lock, flags); 799 spin_unlock_irqrestore(&bank->lock, flags);
816 omap_gpio_unmask_irq(d); 800 omap_gpio_unmask_irq(d);
817 801
@@ -821,15 +805,13 @@ static unsigned int omap_gpio_irq_startup(struct irq_data *d)
821static void omap_gpio_irq_shutdown(struct irq_data *d) 805static void omap_gpio_irq_shutdown(struct irq_data *d)
822{ 806{
823 struct gpio_bank *bank = omap_irq_data_get_bank(d); 807 struct gpio_bank *bank = omap_irq_data_get_bank(d);
824 unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq);
825 unsigned long flags; 808 unsigned long flags;
826 unsigned offset = GPIO_INDEX(bank, gpio); 809 unsigned offset = d->hwirq;
827 810
828 spin_lock_irqsave(&bank->lock, flags); 811 spin_lock_irqsave(&bank->lock, flags);
829 gpiochip_unlock_as_irq(&bank->chip, offset);
830 bank->irq_usage &= ~(BIT(offset)); 812 bank->irq_usage &= ~(BIT(offset));
831 omap_disable_gpio_module(bank, offset); 813 omap_disable_gpio_module(bank, offset);
832 omap_reset_gpio(bank, gpio); 814 omap_reset_gpio(bank, offset);
833 spin_unlock_irqrestore(&bank->lock, flags); 815 spin_unlock_irqrestore(&bank->lock, flags);
834 816
835 /* 817 /*
@@ -843,43 +825,42 @@ static void omap_gpio_irq_shutdown(struct irq_data *d)
843static void omap_gpio_ack_irq(struct irq_data *d) 825static void omap_gpio_ack_irq(struct irq_data *d)
844{ 826{
845 struct gpio_bank *bank = omap_irq_data_get_bank(d); 827 struct gpio_bank *bank = omap_irq_data_get_bank(d);
846 unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq); 828 unsigned offset = d->hwirq;
847 829
848 omap_clear_gpio_irqstatus(bank, gpio); 830 omap_clear_gpio_irqstatus(bank, offset);
849} 831}
850 832
851static void omap_gpio_mask_irq(struct irq_data *d) 833static void omap_gpio_mask_irq(struct irq_data *d)
852{ 834{
853 struct gpio_bank *bank = omap_irq_data_get_bank(d); 835 struct gpio_bank *bank = omap_irq_data_get_bank(d);
854 unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq); 836 unsigned offset = d->hwirq;
855 unsigned long flags; 837 unsigned long flags;
856 838
857 spin_lock_irqsave(&bank->lock, flags); 839 spin_lock_irqsave(&bank->lock, flags);
858 omap_set_gpio_irqenable(bank, gpio, 0); 840 omap_set_gpio_irqenable(bank, offset, 0);
859 omap_set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); 841 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
860 spin_unlock_irqrestore(&bank->lock, flags); 842 spin_unlock_irqrestore(&bank->lock, flags);
861} 843}
862 844
863static void omap_gpio_unmask_irq(struct irq_data *d) 845static void omap_gpio_unmask_irq(struct irq_data *d)
864{ 846{
865 struct gpio_bank *bank = omap_irq_data_get_bank(d); 847 struct gpio_bank *bank = omap_irq_data_get_bank(d);
866 unsigned int gpio = omap_irq_to_gpio(bank, d->hwirq); 848 unsigned offset = d->hwirq;
867 unsigned int irq_mask = GPIO_BIT(bank, gpio);
868 u32 trigger = irqd_get_trigger_type(d); 849 u32 trigger = irqd_get_trigger_type(d);
869 unsigned long flags; 850 unsigned long flags;
870 851
871 spin_lock_irqsave(&bank->lock, flags); 852 spin_lock_irqsave(&bank->lock, flags);
872 if (trigger) 853 if (trigger)
873 omap_set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger); 854 omap_set_gpio_triggering(bank, offset, trigger);
874 855
875 /* For level-triggered GPIOs, the clearing must be done after 856 /* For level-triggered GPIOs, the clearing must be done after
876 * the HW source is cleared, thus after the handler has run */ 857 * the HW source is cleared, thus after the handler has run */
877 if (bank->level_mask & irq_mask) { 858 if (bank->level_mask & BIT(offset)) {
878 omap_set_gpio_irqenable(bank, gpio, 0); 859 omap_set_gpio_irqenable(bank, offset, 0);
879 omap_clear_gpio_irqstatus(bank, gpio); 860 omap_clear_gpio_irqstatus(bank, offset);
880 } 861 }
881 862
882 omap_set_gpio_irqenable(bank, gpio, 1); 863 omap_set_gpio_irqenable(bank, offset, 1);
883 spin_unlock_irqrestore(&bank->lock, flags); 864 spin_unlock_irqrestore(&bank->lock, flags);
884} 865}
885 866
@@ -977,12 +958,10 @@ static int omap_gpio_input(struct gpio_chip *chip, unsigned offset)
977static int omap_gpio_get(struct gpio_chip *chip, unsigned offset) 958static int omap_gpio_get(struct gpio_chip *chip, unsigned offset)
978{ 959{
979 struct gpio_bank *bank; 960 struct gpio_bank *bank;
980 u32 mask;
981 961
982 bank = container_of(chip, struct gpio_bank, chip); 962 bank = container_of(chip, struct gpio_bank, chip);
983 mask = (BIT(offset));
984 963
985 if (omap_gpio_is_input(bank, mask)) 964 if (omap_gpio_is_input(bank, offset))
986 return omap_get_gpio_datain(bank, offset); 965 return omap_get_gpio_datain(bank, offset);
987 else 966 else
988 return omap_get_gpio_dataout(bank, offset); 967 return omap_get_gpio_dataout(bank, offset);