2 * Support functions for OMAP GPIO
4 * Copyright (C) 2003-2005 Nokia Corporation
5 * Written by Juha Yrjölä <juha.yrjola@nokia.com>
7 * Copyright (C) 2009 Texas Instruments
8 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/interrupt.h>
18 #include <linux/syscore_ops.h>
19 #include <linux/err.h>
20 #include <linux/clk.h>
22 #include <linux/device.h>
23 #include <linux/pm_runtime.h>
26 #include <linux/of_device.h>
27 #include <linux/irqchip/chained_irq.h>
28 #include <linux/gpio.h>
29 #include <linux/platform_data/gpio-omap.h>
33 static LIST_HEAD(omap_gpio_list);
51 struct list_head node;
55 u32 enabled_non_wakeup_gpios;
56 struct gpio_regs context;
61 struct gpio_chip chip;
74 int context_loss_count;
76 bool workaround_enabled;
78 void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable);
79 int (*get_context_loss_count)(struct device *dev);
81 struct omap_gpio_reg_offs *regs;
84 #define GPIO_INDEX(bank, gpio) (gpio % bank->width)
85 #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))
86 #define GPIO_MOD_CTRL_BIT BIT(0)
88 #define BANK_USED(bank) (bank->mod_usage || bank->irq_usage)
89 #define LINE_USED(line, offset) (line & (1 << offset))
91 static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq)
93 return bank->chip.base + gpio_irq;
96 static inline struct gpio_bank *_irq_data_get_bank(struct irq_data *d)
98 struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
99 return container_of(chip, struct gpio_bank, chip);
102 static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
104 void __iomem *reg = bank->base;
107 reg += bank->regs->direction;
108 l = readl_relaxed(reg);
113 writel_relaxed(l, reg);
114 bank->context.oe = l;
118 /* set data out value using dedicate set/clear register */
119 static void _set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, int enable)
121 void __iomem *reg = bank->base;
122 u32 l = GPIO_BIT(bank, gpio);
125 reg += bank->regs->set_dataout;
126 bank->context.dataout |= l;
128 reg += bank->regs->clr_dataout;
129 bank->context.dataout &= ~l;
132 writel_relaxed(l, reg);
135 /* set data out value using mask register */
136 static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable)
138 void __iomem *reg = bank->base + bank->regs->dataout;
139 u32 gpio_bit = GPIO_BIT(bank, gpio);
142 l = readl_relaxed(reg);
147 writel_relaxed(l, reg);
148 bank->context.dataout = l;
151 static int _get_gpio_datain(struct gpio_bank *bank, int offset)
153 void __iomem *reg = bank->base + bank->regs->datain;
155 return (readl_relaxed(reg) & (1 << offset)) != 0;
158 static int _get_gpio_dataout(struct gpio_bank *bank, int offset)
160 void __iomem *reg = bank->base + bank->regs->dataout;
162 return (readl_relaxed(reg) & (1 << offset)) != 0;
165 static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
167 int l = readl_relaxed(base + reg);
174 writel_relaxed(l, base + reg);
177 static inline void _gpio_dbck_enable(struct gpio_bank *bank)
179 if (bank->dbck_enable_mask && !bank->dbck_enabled) {
180 clk_enable(bank->dbck);
181 bank->dbck_enabled = true;
183 writel_relaxed(bank->dbck_enable_mask,
184 bank->base + bank->regs->debounce_en);
188 static inline void _gpio_dbck_disable(struct gpio_bank *bank)
190 if (bank->dbck_enable_mask && bank->dbck_enabled) {
192 * Disable debounce before cutting it's clock. If debounce is
193 * enabled but the clock is not, GPIO module seems to be unable
194 * to detect events and generate interrupts at least on OMAP3.
196 writel_relaxed(0, bank->base + bank->regs->debounce_en);
198 clk_disable(bank->dbck);
199 bank->dbck_enabled = false;
204 * _set_gpio_debounce - low level gpio debounce time
205 * @bank: the gpio bank we're acting upon
206 * @gpio: the gpio number on this @gpio
207 * @debounce: debounce time to use
209 * OMAP's debounce time is in 31us steps so we need
210 * to convert and round up to the closest unit.
212 static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
219 if (!bank->dbck_flag)
224 else if (debounce > 7936)
227 debounce = (debounce / 0x1f) - 1;
229 l = GPIO_BIT(bank, gpio);
231 clk_enable(bank->dbck);
232 reg = bank->base + bank->regs->debounce;
233 writel_relaxed(debounce, reg);
235 reg = bank->base + bank->regs->debounce_en;
236 val = readl_relaxed(reg);
242 bank->dbck_enable_mask = val;
244 writel_relaxed(val, reg);
245 clk_disable(bank->dbck);
247 * Enable debounce clock per module.
248 * This call is mandatory because in omap_gpio_request() when
249 * *_runtime_get_sync() is called, _gpio_dbck_enable() within
250 * runtime callbck fails to turn on dbck because dbck_enable_mask
251 * used within _gpio_dbck_enable() is still not initialized at
252 * that point. Therefore we have to enable dbck here.
254 _gpio_dbck_enable(bank);
255 if (bank->dbck_enable_mask) {
256 bank->context.debounce = debounce;
257 bank->context.debounce_en = val;
262 * _clear_gpio_debounce - clear debounce settings for a gpio
263 * @bank: the gpio bank we're acting upon
264 * @gpio: the gpio number on this @gpio
266 * If a gpio is using debounce, then clear the debounce enable bit and if
267 * this is the only gpio in this bank using debounce, then clear the debounce
268 * time too. The debounce clock will also be disabled when calling this function
269 * if this is the only gpio in the bank using debounce.
271 static void _clear_gpio_debounce(struct gpio_bank *bank, unsigned gpio)
273 u32 gpio_bit = GPIO_BIT(bank, gpio);
275 if (!bank->dbck_flag)
278 if (!(bank->dbck_enable_mask & gpio_bit))
281 bank->dbck_enable_mask &= ~gpio_bit;
282 bank->context.debounce_en &= ~gpio_bit;
283 writel_relaxed(bank->context.debounce_en,
284 bank->base + bank->regs->debounce_en);
286 if (!bank->dbck_enable_mask) {
287 bank->context.debounce = 0;
288 writel_relaxed(bank->context.debounce, bank->base +
289 bank->regs->debounce);
290 clk_disable(bank->dbck);
291 bank->dbck_enabled = false;
295 static inline void set_gpio_trigger(struct gpio_bank *bank, int gpio,
298 void __iomem *base = bank->base;
299 u32 gpio_bit = 1 << gpio;
301 _gpio_rmw(base, bank->regs->leveldetect0, gpio_bit,
302 trigger & IRQ_TYPE_LEVEL_LOW);
303 _gpio_rmw(base, bank->regs->leveldetect1, gpio_bit,
304 trigger & IRQ_TYPE_LEVEL_HIGH);
305 _gpio_rmw(base, bank->regs->risingdetect, gpio_bit,
306 trigger & IRQ_TYPE_EDGE_RISING);
307 _gpio_rmw(base, bank->regs->fallingdetect, gpio_bit,
308 trigger & IRQ_TYPE_EDGE_FALLING);
310 bank->context.leveldetect0 =
311 readl_relaxed(bank->base + bank->regs->leveldetect0);
312 bank->context.leveldetect1 =
313 readl_relaxed(bank->base + bank->regs->leveldetect1);
314 bank->context.risingdetect =
315 readl_relaxed(bank->base + bank->regs->risingdetect);
316 bank->context.fallingdetect =
317 readl_relaxed(bank->base + bank->regs->fallingdetect);
319 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
320 _gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0);
321 bank->context.wake_en =
322 readl_relaxed(bank->base + bank->regs->wkup_en);
325 /* This part needs to be executed always for OMAP{34xx, 44xx} */
326 if (!bank->regs->irqctrl) {
327 /* On omap24xx proceed only when valid GPIO bit is set */
328 if (bank->non_wakeup_gpios) {
329 if (!(bank->non_wakeup_gpios & gpio_bit))
334 * Log the edge gpio and manually trigger the IRQ
335 * after resume if the input level changes
336 * to avoid irq lost during PER RET/OFF mode
337 * Applies for omap2 non-wakeup gpio and all omap3 gpios
339 if (trigger & IRQ_TYPE_EDGE_BOTH)
340 bank->enabled_non_wakeup_gpios |= gpio_bit;
342 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
347 readl_relaxed(bank->base + bank->regs->leveldetect0) |
348 readl_relaxed(bank->base + bank->regs->leveldetect1);
351 #ifdef CONFIG_ARCH_OMAP1
353 * This only applies to chips that can't do both rising and falling edge
354 * detection at once. For all other chips, this function is a noop.
356 static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
358 void __iomem *reg = bank->base;
361 if (!bank->regs->irqctrl)
364 reg += bank->regs->irqctrl;
366 l = readl_relaxed(reg);
372 writel_relaxed(l, reg);
375 static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {}
378 static int _set_gpio_triggering(struct gpio_bank *bank, int gpio,
381 void __iomem *reg = bank->base;
382 void __iomem *base = bank->base;
385 if (bank->regs->leveldetect0 && bank->regs->wkup_en) {
386 set_gpio_trigger(bank, gpio, trigger);
387 } else if (bank->regs->irqctrl) {
388 reg += bank->regs->irqctrl;
390 l = readl_relaxed(reg);
391 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
392 bank->toggle_mask |= 1 << gpio;
393 if (trigger & IRQ_TYPE_EDGE_RISING)
395 else if (trigger & IRQ_TYPE_EDGE_FALLING)
400 writel_relaxed(l, reg);
401 } else if (bank->regs->edgectrl1) {
403 reg += bank->regs->edgectrl2;
405 reg += bank->regs->edgectrl1;
408 l = readl_relaxed(reg);
409 l &= ~(3 << (gpio << 1));
410 if (trigger & IRQ_TYPE_EDGE_RISING)
411 l |= 2 << (gpio << 1);
412 if (trigger & IRQ_TYPE_EDGE_FALLING)
413 l |= 1 << (gpio << 1);
415 /* Enable wake-up during idle for dynamic tick */
416 _gpio_rmw(base, bank->regs->wkup_en, 1 << gpio, trigger);
417 bank->context.wake_en =
418 readl_relaxed(bank->base + bank->regs->wkup_en);
419 writel_relaxed(l, reg);
424 static void _enable_gpio_module(struct gpio_bank *bank, unsigned offset)
426 if (bank->regs->pinctrl) {
427 void __iomem *reg = bank->base + bank->regs->pinctrl;
429 /* Claim the pin for MPU */
430 writel_relaxed(readl_relaxed(reg) | (1 << offset), reg);
433 if (bank->regs->ctrl && !BANK_USED(bank)) {
434 void __iomem *reg = bank->base + bank->regs->ctrl;
437 ctrl = readl_relaxed(reg);
438 /* Module is enabled, clocks are not gated */
439 ctrl &= ~GPIO_MOD_CTRL_BIT;
440 writel_relaxed(ctrl, reg);
441 bank->context.ctrl = ctrl;
445 static void _disable_gpio_module(struct gpio_bank *bank, unsigned offset)
447 void __iomem *base = bank->base;
449 if (bank->regs->wkup_en &&
450 !LINE_USED(bank->mod_usage, offset) &&
451 !LINE_USED(bank->irq_usage, offset)) {
452 /* Disable wake-up during idle for dynamic tick */
453 _gpio_rmw(base, bank->regs->wkup_en, 1 << offset, 0);
454 bank->context.wake_en =
455 readl_relaxed(bank->base + bank->regs->wkup_en);
458 if (bank->regs->ctrl && !BANK_USED(bank)) {
459 void __iomem *reg = bank->base + bank->regs->ctrl;
462 ctrl = readl_relaxed(reg);
463 /* Module is disabled, clocks are gated */
464 ctrl |= GPIO_MOD_CTRL_BIT;
465 writel_relaxed(ctrl, reg);
466 bank->context.ctrl = ctrl;
470 static int gpio_is_input(struct gpio_bank *bank, int mask)
472 void __iomem *reg = bank->base + bank->regs->direction;
474 return readl_relaxed(reg) & mask;
477 static int gpio_irq_type(struct irq_data *d, unsigned type)
479 struct gpio_bank *bank = _irq_data_get_bank(d);
485 if (!BANK_USED(bank))
486 pm_runtime_get_sync(bank->dev);
488 #ifdef CONFIG_ARCH_OMAP1
489 if (d->irq > IH_MPUIO_BASE)
490 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
494 gpio = irq_to_gpio(bank, d->hwirq);
496 if (type & ~IRQ_TYPE_SENSE_MASK)
499 if (!bank->regs->leveldetect0 &&
500 (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
503 spin_lock_irqsave(&bank->lock, flags);
504 offset = GPIO_INDEX(bank, gpio);
505 retval = _set_gpio_triggering(bank, offset, type);
506 if (!LINE_USED(bank->mod_usage, offset)) {
507 _enable_gpio_module(bank, offset);
508 _set_gpio_direction(bank, offset, 1);
509 } else if (!gpio_is_input(bank, 1 << offset)) {
510 spin_unlock_irqrestore(&bank->lock, flags);
514 bank->irq_usage |= 1 << GPIO_INDEX(bank, gpio);
515 spin_unlock_irqrestore(&bank->lock, flags);
517 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
518 __irq_set_handler_locked(d->irq, handle_level_irq);
519 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
520 __irq_set_handler_locked(d->irq, handle_edge_irq);
525 static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
527 void __iomem *reg = bank->base;
529 reg += bank->regs->irqstatus;
530 writel_relaxed(gpio_mask, reg);
532 /* Workaround for clearing DSP GPIO interrupts to allow retention */
533 if (bank->regs->irqstatus2) {
534 reg = bank->base + bank->regs->irqstatus2;
535 writel_relaxed(gpio_mask, reg);
538 /* Flush posted write for the irq status to avoid spurious interrupts */
542 static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
544 _clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
547 static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
549 void __iomem *reg = bank->base;
551 u32 mask = (1 << bank->width) - 1;
553 reg += bank->regs->irqenable;
554 l = readl_relaxed(reg);
555 if (bank->regs->irqenable_inv)
561 static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
563 void __iomem *reg = bank->base;
566 if (bank->regs->set_irqenable) {
567 reg += bank->regs->set_irqenable;
569 bank->context.irqenable1 |= gpio_mask;
571 reg += bank->regs->irqenable;
572 l = readl_relaxed(reg);
573 if (bank->regs->irqenable_inv)
577 bank->context.irqenable1 = l;
580 writel_relaxed(l, reg);
583 static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
585 void __iomem *reg = bank->base;
588 if (bank->regs->clr_irqenable) {
589 reg += bank->regs->clr_irqenable;
591 bank->context.irqenable1 &= ~gpio_mask;
593 reg += bank->regs->irqenable;
594 l = readl_relaxed(reg);
595 if (bank->regs->irqenable_inv)
599 bank->context.irqenable1 = l;
602 writel_relaxed(l, reg);
605 static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
608 _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
610 _disable_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
614 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
615 * 1510 does not seem to have a wake-up register. If JTAG is connected
616 * to the target, system will wake up always on GPIO events. While
617 * system is running all registered GPIO interrupts need to have wake-up
618 * enabled. When system is suspended, only selected GPIO interrupts need
619 * to have wake-up enabled.
621 static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
623 u32 gpio_bit = GPIO_BIT(bank, gpio);
626 if (bank->non_wakeup_gpios & gpio_bit) {
628 "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio);
632 spin_lock_irqsave(&bank->lock, flags);
634 bank->context.wake_en |= gpio_bit;
636 bank->context.wake_en &= ~gpio_bit;
638 writel_relaxed(bank->context.wake_en, bank->base + bank->regs->wkup_en);
639 spin_unlock_irqrestore(&bank->lock, flags);
644 static void _reset_gpio(struct gpio_bank *bank, int gpio)
646 _set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1);
647 _set_gpio_irqenable(bank, gpio, 0);
648 _clear_gpio_irqstatus(bank, gpio);
649 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
650 _clear_gpio_debounce(bank, gpio);
653 /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
654 static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
656 struct gpio_bank *bank = _irq_data_get_bank(d);
657 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
659 return _set_gpio_wakeup(bank, gpio, enable);
662 static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
664 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
668 * If this is the first gpio_request for the bank,
669 * enable the bank module.
671 if (!BANK_USED(bank))
672 pm_runtime_get_sync(bank->dev);
674 spin_lock_irqsave(&bank->lock, flags);
675 /* Set trigger to none. You need to enable the desired trigger with
676 * request_irq() or set_irq_type(). Only do this if the IRQ line has
677 * not already been requested.
679 if (!LINE_USED(bank->irq_usage, offset)) {
680 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
681 _enable_gpio_module(bank, offset);
683 bank->mod_usage |= 1 << offset;
684 spin_unlock_irqrestore(&bank->lock, flags);
689 static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
691 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
694 spin_lock_irqsave(&bank->lock, flags);
695 bank->mod_usage &= ~(1 << offset);
696 _disable_gpio_module(bank, offset);
697 _reset_gpio(bank, bank->chip.base + offset);
698 spin_unlock_irqrestore(&bank->lock, flags);
701 * If this is the last gpio to be freed in the bank,
702 * disable the bank module.
704 if (!BANK_USED(bank))
705 pm_runtime_put(bank->dev);
709 * We need to unmask the GPIO bank interrupt as soon as possible to
710 * avoid missing GPIO interrupts for other lines in the bank.
711 * Then we need to mask-read-clear-unmask the triggered GPIO lines
712 * in the bank to avoid missing nested interrupts for a GPIO line.
713 * If we wait to unmask individual GPIO lines in the bank after the
714 * line's interrupt handler has been run, we may miss some nested
717 static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
719 void __iomem *isr_reg = NULL;
722 struct gpio_bank *bank;
724 struct irq_chip *irqchip = irq_desc_get_chip(desc);
725 struct gpio_chip *chip = irq_get_handler_data(irq);
727 chained_irq_enter(irqchip, desc);
729 bank = container_of(chip, struct gpio_bank, chip);
730 isr_reg = bank->base + bank->regs->irqstatus;
731 pm_runtime_get_sync(bank->dev);
733 if (WARN_ON(!isr_reg))
737 u32 isr_saved, level_mask = 0;
740 enabled = _get_gpio_irqbank_mask(bank);
741 isr_saved = isr = readl_relaxed(isr_reg) & enabled;
743 if (bank->level_mask)
744 level_mask = bank->level_mask & enabled;
746 /* clear edge sensitive interrupts before handler(s) are
747 called so that we don't miss any interrupt occurred while
749 _disable_gpio_irqbank(bank, isr_saved & ~level_mask);
750 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
751 _enable_gpio_irqbank(bank, isr_saved & ~level_mask);
753 /* if there is only edge sensitive GPIO pin interrupts
754 configured, we could unmask GPIO bank interrupt immediately */
755 if (!level_mask && !unmasked) {
757 chained_irq_exit(irqchip, desc);
768 * Some chips can't respond to both rising and falling
769 * at the same time. If this irq was requested with
770 * both flags, we need to flip the ICR data for the IRQ
771 * to respond to the IRQ for the opposite direction.
772 * This will be indicated in the bank toggle_mask.
774 if (bank->toggle_mask & (1 << bit))
775 _toggle_gpio_edge_triggering(bank, bit);
777 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain,
781 /* if bank has any level sensitive GPIO pin interrupt
782 configured, we must unmask the bank interrupt only after
783 handler(s) are executed in order to avoid spurious bank
787 chained_irq_exit(irqchip, desc);
788 pm_runtime_put(bank->dev);
791 static void gpio_irq_shutdown(struct irq_data *d)
793 struct gpio_bank *bank = _irq_data_get_bank(d);
794 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
796 unsigned offset = GPIO_INDEX(bank, gpio);
798 spin_lock_irqsave(&bank->lock, flags);
799 gpio_unlock_as_irq(&bank->chip, offset);
800 bank->irq_usage &= ~(1 << offset);
801 _disable_gpio_module(bank, offset);
802 _reset_gpio(bank, gpio);
803 spin_unlock_irqrestore(&bank->lock, flags);
806 * If this is the last IRQ to be freed in the bank,
807 * disable the bank module.
809 if (!BANK_USED(bank))
810 pm_runtime_put(bank->dev);
813 static void gpio_ack_irq(struct irq_data *d)
815 struct gpio_bank *bank = _irq_data_get_bank(d);
816 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
818 _clear_gpio_irqstatus(bank, gpio);
821 static void gpio_mask_irq(struct irq_data *d)
823 struct gpio_bank *bank = _irq_data_get_bank(d);
824 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
827 spin_lock_irqsave(&bank->lock, flags);
828 _set_gpio_irqenable(bank, gpio, 0);
829 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
830 spin_unlock_irqrestore(&bank->lock, flags);
833 static void gpio_unmask_irq(struct irq_data *d)
835 struct gpio_bank *bank = _irq_data_get_bank(d);
836 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
837 unsigned int irq_mask = GPIO_BIT(bank, gpio);
838 u32 trigger = irqd_get_trigger_type(d);
841 spin_lock_irqsave(&bank->lock, flags);
843 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger);
845 /* For level-triggered GPIOs, the clearing must be done after
846 * the HW source is cleared, thus after the handler has run */
847 if (bank->level_mask & irq_mask) {
848 _set_gpio_irqenable(bank, gpio, 0);
849 _clear_gpio_irqstatus(bank, gpio);
852 _set_gpio_irqenable(bank, gpio, 1);
853 spin_unlock_irqrestore(&bank->lock, flags);
856 static struct irq_chip gpio_irq_chip = {
858 .irq_shutdown = gpio_irq_shutdown,
859 .irq_ack = gpio_ack_irq,
860 .irq_mask = gpio_mask_irq,
861 .irq_unmask = gpio_unmask_irq,
862 .irq_set_type = gpio_irq_type,
863 .irq_set_wake = gpio_wake_enable,
866 /*---------------------------------------------------------------------*/
868 static int omap_mpuio_suspend_noirq(struct device *dev)
870 struct platform_device *pdev = to_platform_device(dev);
871 struct gpio_bank *bank = platform_get_drvdata(pdev);
872 void __iomem *mask_reg = bank->base +
873 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
876 spin_lock_irqsave(&bank->lock, flags);
877 writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg);
878 spin_unlock_irqrestore(&bank->lock, flags);
883 static int omap_mpuio_resume_noirq(struct device *dev)
885 struct platform_device *pdev = to_platform_device(dev);
886 struct gpio_bank *bank = platform_get_drvdata(pdev);
887 void __iomem *mask_reg = bank->base +
888 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
891 spin_lock_irqsave(&bank->lock, flags);
892 writel_relaxed(bank->context.wake_en, mask_reg);
893 spin_unlock_irqrestore(&bank->lock, flags);
898 static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
899 .suspend_noirq = omap_mpuio_suspend_noirq,
900 .resume_noirq = omap_mpuio_resume_noirq,
903 /* use platform_driver for this. */
904 static struct platform_driver omap_mpuio_driver = {
907 .pm = &omap_mpuio_dev_pm_ops,
911 static struct platform_device omap_mpuio_device = {
915 .driver = &omap_mpuio_driver.driver,
917 /* could list the /proc/iomem resources */
920 static inline void mpuio_init(struct gpio_bank *bank)
922 platform_set_drvdata(&omap_mpuio_device, bank);
924 if (platform_driver_register(&omap_mpuio_driver) == 0)
925 (void) platform_device_register(&omap_mpuio_device);
928 /*---------------------------------------------------------------------*/
930 static int gpio_input(struct gpio_chip *chip, unsigned offset)
932 struct gpio_bank *bank;
935 bank = container_of(chip, struct gpio_bank, chip);
936 spin_lock_irqsave(&bank->lock, flags);
937 _set_gpio_direction(bank, offset, 1);
938 spin_unlock_irqrestore(&bank->lock, flags);
942 static int gpio_get(struct gpio_chip *chip, unsigned offset)
944 struct gpio_bank *bank;
947 bank = container_of(chip, struct gpio_bank, chip);
948 mask = (1 << offset);
950 if (gpio_is_input(bank, mask))
951 return _get_gpio_datain(bank, offset);
953 return _get_gpio_dataout(bank, offset);
956 static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
958 struct gpio_bank *bank;
961 bank = container_of(chip, struct gpio_bank, chip);
962 spin_lock_irqsave(&bank->lock, flags);
963 bank->set_dataout(bank, offset, value);
964 _set_gpio_direction(bank, offset, 0);
965 spin_unlock_irqrestore(&bank->lock, flags);
969 static int gpio_debounce(struct gpio_chip *chip, unsigned offset,
972 struct gpio_bank *bank;
975 bank = container_of(chip, struct gpio_bank, chip);
977 spin_lock_irqsave(&bank->lock, flags);
978 _set_gpio_debounce(bank, offset, debounce);
979 spin_unlock_irqrestore(&bank->lock, flags);
984 static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
986 struct gpio_bank *bank;
989 bank = container_of(chip, struct gpio_bank, chip);
990 spin_lock_irqsave(&bank->lock, flags);
991 bank->set_dataout(bank, offset, value);
992 spin_unlock_irqrestore(&bank->lock, flags);
995 /*---------------------------------------------------------------------*/
997 static void __init omap_gpio_show_rev(struct gpio_bank *bank)
1002 if (called || bank->regs->revision == USHRT_MAX)
1005 rev = readw_relaxed(bank->base + bank->regs->revision);
1006 pr_info("OMAP GPIO hardware version %d.%d\n",
1007 (rev >> 4) & 0x0f, rev & 0x0f);
1012 /* This lock class tells lockdep that GPIO irqs are in a different
1013 * category than their parents, so it won't report false recursion.
1015 static struct lock_class_key gpio_lock_class;
1017 static void omap_gpio_mod_init(struct gpio_bank *bank)
1019 void __iomem *base = bank->base;
1022 if (bank->width == 16)
1025 if (bank->is_mpuio) {
1026 writel_relaxed(l, bank->base + bank->regs->irqenable);
1030 _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->irqenable_inv);
1031 _gpio_rmw(base, bank->regs->irqstatus, l, !bank->regs->irqenable_inv);
1032 if (bank->regs->debounce_en)
1033 writel_relaxed(0, base + bank->regs->debounce_en);
1035 /* Save OE default value (0xffffffff) in the context */
1036 bank->context.oe = readl_relaxed(bank->base + bank->regs->direction);
1037 /* Initialize interface clk ungated, module enabled */
1038 if (bank->regs->ctrl)
1039 writel_relaxed(0, base + bank->regs->ctrl);
1041 bank->dbck = clk_get(bank->dev, "dbclk");
1042 if (IS_ERR(bank->dbck))
1043 dev_err(bank->dev, "Could not get gpio dbck\n");
1047 omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start,
1050 struct irq_chip_generic *gc;
1051 struct irq_chip_type *ct;
1053 gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base,
1056 dev_err(bank->dev, "Memory alloc failed for gc\n");
1060 ct = gc->chip_types;
1062 /* NOTE: No ack required, reading IRQ status clears it. */
1063 ct->chip.irq_mask = irq_gc_mask_set_bit;
1064 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
1065 ct->chip.irq_set_type = gpio_irq_type;
1067 if (bank->regs->wkup_en)
1068 ct->chip.irq_set_wake = gpio_wake_enable;
1070 ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride;
1071 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
1072 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
1075 static int omap_gpio_chip_init(struct gpio_bank *bank)
1083 * REVISIT eventually switch from OMAP-specific gpio structs
1084 * over to the generic ones
1086 bank->chip.request = omap_gpio_request;
1087 bank->chip.free = omap_gpio_free;
1088 bank->chip.direction_input = gpio_input;
1089 bank->chip.get = gpio_get;
1090 bank->chip.direction_output = gpio_output;
1091 bank->chip.set_debounce = gpio_debounce;
1092 bank->chip.set = gpio_set;
1093 if (bank->is_mpuio) {
1094 bank->chip.label = "mpuio";
1095 if (bank->regs->wkup_en)
1096 bank->chip.dev = &omap_mpuio_device.dev;
1097 bank->chip.base = OMAP_MPUIO(0);
1099 bank->chip.label = "gpio";
1100 bank->chip.base = gpio;
1101 gpio += bank->width;
1103 bank->chip.ngpio = bank->width;
1105 ret = gpiochip_add(&bank->chip);
1107 dev_err(bank->dev, "Could not register gpio chip %d\n", ret);
1111 #ifdef CONFIG_ARCH_OMAP1
1113 * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop
1114 * irq_alloc_descs() since a base IRQ offset will no longer be needed.
1116 irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
1118 dev_err(bank->dev, "Couldn't allocate IRQ numbers\n");
1123 ret = gpiochip_irqchip_add(&bank->chip, &gpio_irq_chip,
1124 irq_base, gpio_irq_handler,
1128 dev_err(bank->dev, "Couldn't add irqchip to gpiochip %d\n", ret);
1129 ret = gpiochip_remove(&bank->chip);
1133 gpiochip_set_chained_irqchip(&bank->chip, &gpio_irq_chip,
1134 bank->irq, gpio_irq_handler);
1136 for (j = 0; j < bank->width; j++) {
1137 int irq = irq_find_mapping(bank->chip.irqdomain, j);
1138 irq_set_lockdep_class(irq, &gpio_lock_class);
1139 if (bank->is_mpuio) {
1140 omap_mpuio_alloc_gc(bank, irq, bank->width);
1141 irq_set_chip_and_handler(irq, NULL, NULL);
1142 set_irq_flags(irq, 0);
1149 static const struct of_device_id omap_gpio_match[];
1151 static int omap_gpio_probe(struct platform_device *pdev)
1153 struct device *dev = &pdev->dev;
1154 struct device_node *node = dev->of_node;
1155 const struct of_device_id *match;
1156 const struct omap_gpio_platform_data *pdata;
1157 struct resource *res;
1158 struct gpio_bank *bank;
1161 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
1163 pdata = match ? match->data : dev_get_platdata(dev);
1167 bank = devm_kzalloc(dev, sizeof(struct gpio_bank), GFP_KERNEL);
1169 dev_err(dev, "Memory alloc failed\n");
1173 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1174 if (unlikely(!res)) {
1175 dev_err(dev, "Invalid IRQ resource\n");
1179 bank->irq = res->start;
1181 bank->chip.dev = dev;
1182 bank->dbck_flag = pdata->dbck_flag;
1183 bank->stride = pdata->bank_stride;
1184 bank->width = pdata->bank_width;
1185 bank->is_mpuio = pdata->is_mpuio;
1186 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
1187 bank->regs = pdata->regs;
1188 #ifdef CONFIG_OF_GPIO
1189 bank->chip.of_node = of_node_get(node);
1192 if (!of_property_read_bool(node, "ti,gpio-always-on"))
1193 bank->loses_context = true;
1195 bank->loses_context = pdata->loses_context;
1197 if (bank->loses_context)
1198 bank->get_context_loss_count =
1199 pdata->get_context_loss_count;
1202 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1203 bank->set_dataout = _set_gpio_dataout_reg;
1205 bank->set_dataout = _set_gpio_dataout_mask;
1207 spin_lock_init(&bank->lock);
1209 /* Static mapping, never released */
1210 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1211 bank->base = devm_ioremap_resource(dev, res);
1212 if (IS_ERR(bank->base)) {
1213 irq_domain_remove(bank->chip.irqdomain);
1214 return PTR_ERR(bank->base);
1217 platform_set_drvdata(pdev, bank);
1219 pm_runtime_enable(bank->dev);
1220 pm_runtime_irq_safe(bank->dev);
1221 pm_runtime_get_sync(bank->dev);
1226 omap_gpio_mod_init(bank);
1228 ret = omap_gpio_chip_init(bank);
1232 omap_gpio_show_rev(bank);
1234 pm_runtime_put(bank->dev);
1236 list_add_tail(&bank->node, &omap_gpio_list);
1241 #ifdef CONFIG_ARCH_OMAP2PLUS
1243 #if defined(CONFIG_PM_RUNTIME)
1244 static void omap_gpio_restore_context(struct gpio_bank *bank);
1246 static int omap_gpio_runtime_suspend(struct device *dev)
1248 struct platform_device *pdev = to_platform_device(dev);
1249 struct gpio_bank *bank = platform_get_drvdata(pdev);
1251 unsigned long flags;
1252 u32 wake_low, wake_hi;
1254 spin_lock_irqsave(&bank->lock, flags);
1257 * Only edges can generate a wakeup event to the PRCM.
1259 * Therefore, ensure any wake-up capable GPIOs have
1260 * edge-detection enabled before going idle to ensure a wakeup
1261 * to the PRCM is generated on a GPIO transition. (c.f. 34xx
1264 * The normal values will be restored upon ->runtime_resume()
1265 * by writing back the values saved in bank->context.
1267 wake_low = bank->context.leveldetect0 & bank->context.wake_en;
1269 writel_relaxed(wake_low | bank->context.fallingdetect,
1270 bank->base + bank->regs->fallingdetect);
1271 wake_hi = bank->context.leveldetect1 & bank->context.wake_en;
1273 writel_relaxed(wake_hi | bank->context.risingdetect,
1274 bank->base + bank->regs->risingdetect);
1276 if (!bank->enabled_non_wakeup_gpios)
1277 goto update_gpio_context_count;
1279 if (bank->power_mode != OFF_MODE) {
1280 bank->power_mode = 0;
1281 goto update_gpio_context_count;
1284 * If going to OFF, remove triggering for all
1285 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1286 * generated. See OMAP2420 Errata item 1.101.
1288 bank->saved_datain = readl_relaxed(bank->base +
1289 bank->regs->datain);
1290 l1 = bank->context.fallingdetect;
1291 l2 = bank->context.risingdetect;
1293 l1 &= ~bank->enabled_non_wakeup_gpios;
1294 l2 &= ~bank->enabled_non_wakeup_gpios;
1296 writel_relaxed(l1, bank->base + bank->regs->fallingdetect);
1297 writel_relaxed(l2, bank->base + bank->regs->risingdetect);
1299 bank->workaround_enabled = true;
1301 update_gpio_context_count:
1302 if (bank->get_context_loss_count)
1303 bank->context_loss_count =
1304 bank->get_context_loss_count(bank->dev);
1306 _gpio_dbck_disable(bank);
1307 spin_unlock_irqrestore(&bank->lock, flags);
1312 static void omap_gpio_init_context(struct gpio_bank *p);
1314 static int omap_gpio_runtime_resume(struct device *dev)
1316 struct platform_device *pdev = to_platform_device(dev);
1317 struct gpio_bank *bank = platform_get_drvdata(pdev);
1318 u32 l = 0, gen, gen0, gen1;
1319 unsigned long flags;
1322 spin_lock_irqsave(&bank->lock, flags);
1325 * On the first resume during the probe, the context has not
1326 * been initialised and so initialise it now. Also initialise
1327 * the context loss count.
1329 if (bank->loses_context && !bank->context_valid) {
1330 omap_gpio_init_context(bank);
1332 if (bank->get_context_loss_count)
1333 bank->context_loss_count =
1334 bank->get_context_loss_count(bank->dev);
1337 _gpio_dbck_enable(bank);
1340 * In ->runtime_suspend(), level-triggered, wakeup-enabled
1341 * GPIOs were set to edge trigger also in order to be able to
1342 * generate a PRCM wakeup. Here we restore the
1343 * pre-runtime_suspend() values for edge triggering.
1345 writel_relaxed(bank->context.fallingdetect,
1346 bank->base + bank->regs->fallingdetect);
1347 writel_relaxed(bank->context.risingdetect,
1348 bank->base + bank->regs->risingdetect);
1350 if (bank->loses_context) {
1351 if (!bank->get_context_loss_count) {
1352 omap_gpio_restore_context(bank);
1354 c = bank->get_context_loss_count(bank->dev);
1355 if (c != bank->context_loss_count) {
1356 omap_gpio_restore_context(bank);
1358 spin_unlock_irqrestore(&bank->lock, flags);
1364 if (!bank->workaround_enabled) {
1365 spin_unlock_irqrestore(&bank->lock, flags);
1369 l = readl_relaxed(bank->base + bank->regs->datain);
1372 * Check if any of the non-wakeup interrupt GPIOs have changed
1373 * state. If so, generate an IRQ by software. This is
1374 * horribly racy, but it's the best we can do to work around
1377 l ^= bank->saved_datain;
1378 l &= bank->enabled_non_wakeup_gpios;
1381 * No need to generate IRQs for the rising edge for gpio IRQs
1382 * configured with falling edge only; and vice versa.
1384 gen0 = l & bank->context.fallingdetect;
1385 gen0 &= bank->saved_datain;
1387 gen1 = l & bank->context.risingdetect;
1388 gen1 &= ~(bank->saved_datain);
1390 /* FIXME: Consider GPIO IRQs with level detections properly! */
1391 gen = l & (~(bank->context.fallingdetect) &
1392 ~(bank->context.risingdetect));
1393 /* Consider all GPIO IRQs needed to be updated */
1399 old0 = readl_relaxed(bank->base + bank->regs->leveldetect0);
1400 old1 = readl_relaxed(bank->base + bank->regs->leveldetect1);
1402 if (!bank->regs->irqstatus_raw0) {
1403 writel_relaxed(old0 | gen, bank->base +
1404 bank->regs->leveldetect0);
1405 writel_relaxed(old1 | gen, bank->base +
1406 bank->regs->leveldetect1);
1409 if (bank->regs->irqstatus_raw0) {
1410 writel_relaxed(old0 | l, bank->base +
1411 bank->regs->leveldetect0);
1412 writel_relaxed(old1 | l, bank->base +
1413 bank->regs->leveldetect1);
1415 writel_relaxed(old0, bank->base + bank->regs->leveldetect0);
1416 writel_relaxed(old1, bank->base + bank->regs->leveldetect1);
1419 bank->workaround_enabled = false;
1420 spin_unlock_irqrestore(&bank->lock, flags);
1424 #endif /* CONFIG_PM_RUNTIME */
1426 void omap2_gpio_prepare_for_idle(int pwr_mode)
1428 struct gpio_bank *bank;
1430 list_for_each_entry(bank, &omap_gpio_list, node) {
1431 if (!BANK_USED(bank) || !bank->loses_context)
1434 bank->power_mode = pwr_mode;
1436 pm_runtime_put_sync_suspend(bank->dev);
1440 void omap2_gpio_resume_after_idle(void)
1442 struct gpio_bank *bank;
1444 list_for_each_entry(bank, &omap_gpio_list, node) {
1445 if (!BANK_USED(bank) || !bank->loses_context)
1448 pm_runtime_get_sync(bank->dev);
1452 #if defined(CONFIG_PM_RUNTIME)
1453 static void omap_gpio_init_context(struct gpio_bank *p)
1455 struct omap_gpio_reg_offs *regs = p->regs;
1456 void __iomem *base = p->base;
1458 p->context.ctrl = readl_relaxed(base + regs->ctrl);
1459 p->context.oe = readl_relaxed(base + regs->direction);
1460 p->context.wake_en = readl_relaxed(base + regs->wkup_en);
1461 p->context.leveldetect0 = readl_relaxed(base + regs->leveldetect0);
1462 p->context.leveldetect1 = readl_relaxed(base + regs->leveldetect1);
1463 p->context.risingdetect = readl_relaxed(base + regs->risingdetect);
1464 p->context.fallingdetect = readl_relaxed(base + regs->fallingdetect);
1465 p->context.irqenable1 = readl_relaxed(base + regs->irqenable);
1466 p->context.irqenable2 = readl_relaxed(base + regs->irqenable2);
1468 if (regs->set_dataout && p->regs->clr_dataout)
1469 p->context.dataout = readl_relaxed(base + regs->set_dataout);
1471 p->context.dataout = readl_relaxed(base + regs->dataout);
1473 p->context_valid = true;
1476 static void omap_gpio_restore_context(struct gpio_bank *bank)
1478 writel_relaxed(bank->context.wake_en,
1479 bank->base + bank->regs->wkup_en);
1480 writel_relaxed(bank->context.ctrl, bank->base + bank->regs->ctrl);
1481 writel_relaxed(bank->context.leveldetect0,
1482 bank->base + bank->regs->leveldetect0);
1483 writel_relaxed(bank->context.leveldetect1,
1484 bank->base + bank->regs->leveldetect1);
1485 writel_relaxed(bank->context.risingdetect,
1486 bank->base + bank->regs->risingdetect);
1487 writel_relaxed(bank->context.fallingdetect,
1488 bank->base + bank->regs->fallingdetect);
1489 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1490 writel_relaxed(bank->context.dataout,
1491 bank->base + bank->regs->set_dataout);
1493 writel_relaxed(bank->context.dataout,
1494 bank->base + bank->regs->dataout);
1495 writel_relaxed(bank->context.oe, bank->base + bank->regs->direction);
1497 if (bank->dbck_enable_mask) {
1498 writel_relaxed(bank->context.debounce, bank->base +
1499 bank->regs->debounce);
1500 writel_relaxed(bank->context.debounce_en,
1501 bank->base + bank->regs->debounce_en);
1504 writel_relaxed(bank->context.irqenable1,
1505 bank->base + bank->regs->irqenable);
1506 writel_relaxed(bank->context.irqenable2,
1507 bank->base + bank->regs->irqenable2);
1509 #endif /* CONFIG_PM_RUNTIME */
1511 #define omap_gpio_runtime_suspend NULL
1512 #define omap_gpio_runtime_resume NULL
1513 static inline void omap_gpio_init_context(struct gpio_bank *p) {}
1516 static const struct dev_pm_ops gpio_pm_ops = {
1517 SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume,
1521 #if defined(CONFIG_OF)
1522 static struct omap_gpio_reg_offs omap2_gpio_regs = {
1523 .revision = OMAP24XX_GPIO_REVISION,
1524 .direction = OMAP24XX_GPIO_OE,
1525 .datain = OMAP24XX_GPIO_DATAIN,
1526 .dataout = OMAP24XX_GPIO_DATAOUT,
1527 .set_dataout = OMAP24XX_GPIO_SETDATAOUT,
1528 .clr_dataout = OMAP24XX_GPIO_CLEARDATAOUT,
1529 .irqstatus = OMAP24XX_GPIO_IRQSTATUS1,
1530 .irqstatus2 = OMAP24XX_GPIO_IRQSTATUS2,
1531 .irqenable = OMAP24XX_GPIO_IRQENABLE1,
1532 .irqenable2 = OMAP24XX_GPIO_IRQENABLE2,
1533 .set_irqenable = OMAP24XX_GPIO_SETIRQENABLE1,
1534 .clr_irqenable = OMAP24XX_GPIO_CLEARIRQENABLE1,
1535 .debounce = OMAP24XX_GPIO_DEBOUNCE_VAL,
1536 .debounce_en = OMAP24XX_GPIO_DEBOUNCE_EN,
1537 .ctrl = OMAP24XX_GPIO_CTRL,
1538 .wkup_en = OMAP24XX_GPIO_WAKE_EN,
1539 .leveldetect0 = OMAP24XX_GPIO_LEVELDETECT0,
1540 .leveldetect1 = OMAP24XX_GPIO_LEVELDETECT1,
1541 .risingdetect = OMAP24XX_GPIO_RISINGDETECT,
1542 .fallingdetect = OMAP24XX_GPIO_FALLINGDETECT,
1545 static struct omap_gpio_reg_offs omap4_gpio_regs = {
1546 .revision = OMAP4_GPIO_REVISION,
1547 .direction = OMAP4_GPIO_OE,
1548 .datain = OMAP4_GPIO_DATAIN,
1549 .dataout = OMAP4_GPIO_DATAOUT,
1550 .set_dataout = OMAP4_GPIO_SETDATAOUT,
1551 .clr_dataout = OMAP4_GPIO_CLEARDATAOUT,
1552 .irqstatus = OMAP4_GPIO_IRQSTATUS0,
1553 .irqstatus2 = OMAP4_GPIO_IRQSTATUS1,
1554 .irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1555 .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1,
1556 .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1557 .clr_irqenable = OMAP4_GPIO_IRQSTATUSCLR0,
1558 .debounce = OMAP4_GPIO_DEBOUNCINGTIME,
1559 .debounce_en = OMAP4_GPIO_DEBOUNCENABLE,
1560 .ctrl = OMAP4_GPIO_CTRL,
1561 .wkup_en = OMAP4_GPIO_IRQWAKEN0,
1562 .leveldetect0 = OMAP4_GPIO_LEVELDETECT0,
1563 .leveldetect1 = OMAP4_GPIO_LEVELDETECT1,
1564 .risingdetect = OMAP4_GPIO_RISINGDETECT,
1565 .fallingdetect = OMAP4_GPIO_FALLINGDETECT,
1568 static const struct omap_gpio_platform_data omap2_pdata = {
1569 .regs = &omap2_gpio_regs,
1574 static const struct omap_gpio_platform_data omap3_pdata = {
1575 .regs = &omap2_gpio_regs,
1580 static const struct omap_gpio_platform_data omap4_pdata = {
1581 .regs = &omap4_gpio_regs,
1586 static const struct of_device_id omap_gpio_match[] = {
1588 .compatible = "ti,omap4-gpio",
1589 .data = &omap4_pdata,
1592 .compatible = "ti,omap3-gpio",
1593 .data = &omap3_pdata,
1596 .compatible = "ti,omap2-gpio",
1597 .data = &omap2_pdata,
1601 MODULE_DEVICE_TABLE(of, omap_gpio_match);
1604 static struct platform_driver omap_gpio_driver = {
1605 .probe = omap_gpio_probe,
1607 .name = "omap_gpio",
1609 .of_match_table = of_match_ptr(omap_gpio_match),
1614 * gpio driver register needs to be done before
1615 * machine_init functions access gpio APIs.
1616 * Hence omap_gpio_drv_reg() is a postcore_initcall.
1618 static int __init omap_gpio_drv_reg(void)
1620 return platform_driver_register(&omap_gpio_driver);
1622 postcore_initcall(omap_gpio_drv_reg);