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/irqdomain.h>
29 #include <mach/hardware.h>
31 #include <mach/irqs.h>
33 #include <asm/mach/irq.h>
37 static LIST_HEAD(omap_gpio_list
);
55 struct list_head node
;
59 struct irq_domain
*domain
;
63 u32 enabled_non_wakeup_gpios
;
64 struct gpio_regs context
;
66 u32 saved_fallingdetect
;
67 u32 saved_risingdetect
;
71 struct gpio_chip chip
;
82 int context_loss_count
;
84 bool workaround_enabled
;
86 void (*set_dataout
)(struct gpio_bank
*bank
, int gpio
, int enable
);
87 int (*get_context_loss_count
)(struct device
*dev
);
89 struct omap_gpio_reg_offs
*regs
;
92 #define GPIO_INDEX(bank, gpio) (gpio % bank->width)
93 #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))
94 #define GPIO_MOD_CTRL_BIT BIT(0)
96 static int irq_to_gpio(struct gpio_bank
*bank
, unsigned int gpio_irq
)
98 return gpio_irq
- bank
->irq_base
+ bank
->chip
.base
;
101 static void _set_gpio_direction(struct gpio_bank
*bank
, int gpio
, int is_input
)
103 void __iomem
*reg
= bank
->base
;
106 reg
+= bank
->regs
->direction
;
107 l
= __raw_readl(reg
);
112 __raw_writel(l
, reg
);
113 bank
->context
.oe
= l
;
117 /* set data out value using dedicate set/clear register */
118 static void _set_gpio_dataout_reg(struct gpio_bank
*bank
, int gpio
, int enable
)
120 void __iomem
*reg
= bank
->base
;
121 u32 l
= GPIO_BIT(bank
, gpio
);
124 reg
+= bank
->regs
->set_dataout
;
125 bank
->context
.dataout
|= l
;
127 reg
+= bank
->regs
->clr_dataout
;
128 bank
->context
.dataout
&= ~l
;
131 __raw_writel(l
, reg
);
134 /* set data out value using mask register */
135 static void _set_gpio_dataout_mask(struct gpio_bank
*bank
, int gpio
, int enable
)
137 void __iomem
*reg
= bank
->base
+ bank
->regs
->dataout
;
138 u32 gpio_bit
= GPIO_BIT(bank
, gpio
);
141 l
= __raw_readl(reg
);
146 __raw_writel(l
, reg
);
147 bank
->context
.dataout
= l
;
150 static int _get_gpio_datain(struct gpio_bank
*bank
, int offset
)
152 void __iomem
*reg
= bank
->base
+ bank
->regs
->datain
;
154 return (__raw_readl(reg
) & (1 << offset
)) != 0;
157 static int _get_gpio_dataout(struct gpio_bank
*bank
, int offset
)
159 void __iomem
*reg
= bank
->base
+ bank
->regs
->dataout
;
161 return (__raw_readl(reg
) & (1 << offset
)) != 0;
164 static inline void _gpio_rmw(void __iomem
*base
, u32 reg
, u32 mask
, bool set
)
166 int l
= __raw_readl(base
+ reg
);
173 __raw_writel(l
, base
+ reg
);
176 static inline void _gpio_dbck_enable(struct gpio_bank
*bank
)
178 if (bank
->dbck_enable_mask
&& !bank
->dbck_enabled
) {
179 clk_enable(bank
->dbck
);
180 bank
->dbck_enabled
= true;
184 static inline void _gpio_dbck_disable(struct gpio_bank
*bank
)
186 if (bank
->dbck_enable_mask
&& bank
->dbck_enabled
) {
187 clk_disable(bank
->dbck
);
188 bank
->dbck_enabled
= false;
193 * _set_gpio_debounce - low level gpio debounce time
194 * @bank: the gpio bank we're acting upon
195 * @gpio: the gpio number on this @gpio
196 * @debounce: debounce time to use
198 * OMAP's debounce time is in 31us steps so we need
199 * to convert and round up to the closest unit.
201 static void _set_gpio_debounce(struct gpio_bank
*bank
, unsigned gpio
,
208 if (!bank
->dbck_flag
)
213 else if (debounce
> 7936)
216 debounce
= (debounce
/ 0x1f) - 1;
218 l
= GPIO_BIT(bank
, gpio
);
220 clk_enable(bank
->dbck
);
221 reg
= bank
->base
+ bank
->regs
->debounce
;
222 __raw_writel(debounce
, reg
);
224 reg
= bank
->base
+ bank
->regs
->debounce_en
;
225 val
= __raw_readl(reg
);
231 bank
->dbck_enable_mask
= val
;
233 __raw_writel(val
, reg
);
234 clk_disable(bank
->dbck
);
236 * Enable debounce clock per module.
237 * This call is mandatory because in omap_gpio_request() when
238 * *_runtime_get_sync() is called, _gpio_dbck_enable() within
239 * runtime callbck fails to turn on dbck because dbck_enable_mask
240 * used within _gpio_dbck_enable() is still not initialized at
241 * that point. Therefore we have to enable dbck here.
243 _gpio_dbck_enable(bank
);
244 if (bank
->dbck_enable_mask
) {
245 bank
->context
.debounce
= debounce
;
246 bank
->context
.debounce_en
= val
;
250 static inline void set_gpio_trigger(struct gpio_bank
*bank
, int gpio
,
253 void __iomem
*base
= bank
->base
;
254 u32 gpio_bit
= 1 << gpio
;
256 _gpio_rmw(base
, bank
->regs
->leveldetect0
, gpio_bit
,
257 trigger
& IRQ_TYPE_LEVEL_LOW
);
258 _gpio_rmw(base
, bank
->regs
->leveldetect1
, gpio_bit
,
259 trigger
& IRQ_TYPE_LEVEL_HIGH
);
260 _gpio_rmw(base
, bank
->regs
->risingdetect
, gpio_bit
,
261 trigger
& IRQ_TYPE_EDGE_RISING
);
262 _gpio_rmw(base
, bank
->regs
->fallingdetect
, gpio_bit
,
263 trigger
& IRQ_TYPE_EDGE_FALLING
);
265 bank
->context
.leveldetect0
=
266 __raw_readl(bank
->base
+ bank
->regs
->leveldetect0
);
267 bank
->context
.leveldetect1
=
268 __raw_readl(bank
->base
+ bank
->regs
->leveldetect1
);
269 bank
->context
.risingdetect
=
270 __raw_readl(bank
->base
+ bank
->regs
->risingdetect
);
271 bank
->context
.fallingdetect
=
272 __raw_readl(bank
->base
+ bank
->regs
->fallingdetect
);
274 if (likely(!(bank
->non_wakeup_gpios
& gpio_bit
))) {
275 _gpio_rmw(base
, bank
->regs
->wkup_en
, gpio_bit
, trigger
!= 0);
276 bank
->context
.wake_en
=
277 __raw_readl(bank
->base
+ bank
->regs
->wkup_en
);
280 /* This part needs to be executed always for OMAP{34xx, 44xx} */
281 if (!bank
->regs
->irqctrl
) {
282 /* On omap24xx proceed only when valid GPIO bit is set */
283 if (bank
->non_wakeup_gpios
) {
284 if (!(bank
->non_wakeup_gpios
& gpio_bit
))
289 * Log the edge gpio and manually trigger the IRQ
290 * after resume if the input level changes
291 * to avoid irq lost during PER RET/OFF mode
292 * Applies for omap2 non-wakeup gpio and all omap3 gpios
294 if (trigger
& IRQ_TYPE_EDGE_BOTH
)
295 bank
->enabled_non_wakeup_gpios
|= gpio_bit
;
297 bank
->enabled_non_wakeup_gpios
&= ~gpio_bit
;
302 __raw_readl(bank
->base
+ bank
->regs
->leveldetect0
) |
303 __raw_readl(bank
->base
+ bank
->regs
->leveldetect1
);
306 #ifdef CONFIG_ARCH_OMAP1
308 * This only applies to chips that can't do both rising and falling edge
309 * detection at once. For all other chips, this function is a noop.
311 static void _toggle_gpio_edge_triggering(struct gpio_bank
*bank
, int gpio
)
313 void __iomem
*reg
= bank
->base
;
316 if (!bank
->regs
->irqctrl
)
319 reg
+= bank
->regs
->irqctrl
;
321 l
= __raw_readl(reg
);
327 __raw_writel(l
, reg
);
330 static void _toggle_gpio_edge_triggering(struct gpio_bank
*bank
, int gpio
) {}
333 static int _set_gpio_triggering(struct gpio_bank
*bank
, int gpio
,
336 void __iomem
*reg
= bank
->base
;
337 void __iomem
*base
= bank
->base
;
340 if (bank
->regs
->leveldetect0
&& bank
->regs
->wkup_en
) {
341 set_gpio_trigger(bank
, gpio
, trigger
);
342 } else if (bank
->regs
->irqctrl
) {
343 reg
+= bank
->regs
->irqctrl
;
345 l
= __raw_readl(reg
);
346 if ((trigger
& IRQ_TYPE_SENSE_MASK
) == IRQ_TYPE_EDGE_BOTH
)
347 bank
->toggle_mask
|= 1 << gpio
;
348 if (trigger
& IRQ_TYPE_EDGE_RISING
)
350 else if (trigger
& IRQ_TYPE_EDGE_FALLING
)
355 __raw_writel(l
, reg
);
356 } else if (bank
->regs
->edgectrl1
) {
358 reg
+= bank
->regs
->edgectrl2
;
360 reg
+= bank
->regs
->edgectrl1
;
363 l
= __raw_readl(reg
);
364 l
&= ~(3 << (gpio
<< 1));
365 if (trigger
& IRQ_TYPE_EDGE_RISING
)
366 l
|= 2 << (gpio
<< 1);
367 if (trigger
& IRQ_TYPE_EDGE_FALLING
)
368 l
|= 1 << (gpio
<< 1);
370 /* Enable wake-up during idle for dynamic tick */
371 _gpio_rmw(base
, bank
->regs
->wkup_en
, 1 << gpio
, trigger
);
372 bank
->context
.wake_en
=
373 __raw_readl(bank
->base
+ bank
->regs
->wkup_en
);
374 __raw_writel(l
, reg
);
379 static int gpio_irq_type(struct irq_data
*d
, unsigned type
)
381 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
386 if (!cpu_class_is_omap2() && d
->irq
> IH_MPUIO_BASE
)
387 gpio
= OMAP_MPUIO(d
->irq
- IH_MPUIO_BASE
);
389 gpio
= irq_to_gpio(bank
, d
->irq
);
391 if (type
& ~IRQ_TYPE_SENSE_MASK
)
394 if (!bank
->regs
->leveldetect0
&&
395 (type
& (IRQ_TYPE_LEVEL_LOW
|IRQ_TYPE_LEVEL_HIGH
)))
398 spin_lock_irqsave(&bank
->lock
, flags
);
399 retval
= _set_gpio_triggering(bank
, GPIO_INDEX(bank
, gpio
), type
);
400 spin_unlock_irqrestore(&bank
->lock
, flags
);
402 if (type
& (IRQ_TYPE_LEVEL_LOW
| IRQ_TYPE_LEVEL_HIGH
))
403 __irq_set_handler_locked(d
->irq
, handle_level_irq
);
404 else if (type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_EDGE_RISING
))
405 __irq_set_handler_locked(d
->irq
, handle_edge_irq
);
410 static void _clear_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
)
412 void __iomem
*reg
= bank
->base
;
414 reg
+= bank
->regs
->irqstatus
;
415 __raw_writel(gpio_mask
, reg
);
417 /* Workaround for clearing DSP GPIO interrupts to allow retention */
418 if (bank
->regs
->irqstatus2
) {
419 reg
= bank
->base
+ bank
->regs
->irqstatus2
;
420 __raw_writel(gpio_mask
, reg
);
423 /* Flush posted write for the irq status to avoid spurious interrupts */
427 static inline void _clear_gpio_irqstatus(struct gpio_bank
*bank
, int gpio
)
429 _clear_gpio_irqbank(bank
, GPIO_BIT(bank
, gpio
));
432 static u32
_get_gpio_irqbank_mask(struct gpio_bank
*bank
)
434 void __iomem
*reg
= bank
->base
;
436 u32 mask
= (1 << bank
->width
) - 1;
438 reg
+= bank
->regs
->irqenable
;
439 l
= __raw_readl(reg
);
440 if (bank
->regs
->irqenable_inv
)
446 static void _enable_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
)
448 void __iomem
*reg
= bank
->base
;
451 if (bank
->regs
->set_irqenable
) {
452 reg
+= bank
->regs
->set_irqenable
;
454 bank
->context
.irqenable1
|= gpio_mask
;
456 reg
+= bank
->regs
->irqenable
;
457 l
= __raw_readl(reg
);
458 if (bank
->regs
->irqenable_inv
)
462 bank
->context
.irqenable1
= l
;
465 __raw_writel(l
, reg
);
468 static void _disable_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
)
470 void __iomem
*reg
= bank
->base
;
473 if (bank
->regs
->clr_irqenable
) {
474 reg
+= bank
->regs
->clr_irqenable
;
476 bank
->context
.irqenable1
&= ~gpio_mask
;
478 reg
+= bank
->regs
->irqenable
;
479 l
= __raw_readl(reg
);
480 if (bank
->regs
->irqenable_inv
)
484 bank
->context
.irqenable1
= l
;
487 __raw_writel(l
, reg
);
490 static inline void _set_gpio_irqenable(struct gpio_bank
*bank
, int gpio
, int enable
)
493 _enable_gpio_irqbank(bank
, GPIO_BIT(bank
, gpio
));
495 _disable_gpio_irqbank(bank
, GPIO_BIT(bank
, gpio
));
499 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
500 * 1510 does not seem to have a wake-up register. If JTAG is connected
501 * to the target, system will wake up always on GPIO events. While
502 * system is running all registered GPIO interrupts need to have wake-up
503 * enabled. When system is suspended, only selected GPIO interrupts need
504 * to have wake-up enabled.
506 static int _set_gpio_wakeup(struct gpio_bank
*bank
, int gpio
, int enable
)
508 u32 gpio_bit
= GPIO_BIT(bank
, gpio
);
511 if (bank
->non_wakeup_gpios
& gpio_bit
) {
513 "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio
);
517 spin_lock_irqsave(&bank
->lock
, flags
);
519 bank
->suspend_wakeup
|= gpio_bit
;
521 bank
->suspend_wakeup
&= ~gpio_bit
;
523 __raw_writel(bank
->suspend_wakeup
, bank
->base
+ bank
->regs
->wkup_en
);
524 spin_unlock_irqrestore(&bank
->lock
, flags
);
529 static void _reset_gpio(struct gpio_bank
*bank
, int gpio
)
531 _set_gpio_direction(bank
, GPIO_INDEX(bank
, gpio
), 1);
532 _set_gpio_irqenable(bank
, gpio
, 0);
533 _clear_gpio_irqstatus(bank
, gpio
);
534 _set_gpio_triggering(bank
, GPIO_INDEX(bank
, gpio
), IRQ_TYPE_NONE
);
537 /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
538 static int gpio_wake_enable(struct irq_data
*d
, unsigned int enable
)
540 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
541 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
543 return _set_gpio_wakeup(bank
, gpio
, enable
);
546 static int omap_gpio_request(struct gpio_chip
*chip
, unsigned offset
)
548 struct gpio_bank
*bank
= container_of(chip
, struct gpio_bank
, chip
);
552 * If this is the first gpio_request for the bank,
553 * enable the bank module.
555 if (!bank
->mod_usage
)
556 pm_runtime_get_sync(bank
->dev
);
558 spin_lock_irqsave(&bank
->lock
, flags
);
559 /* Set trigger to none. You need to enable the desired trigger with
560 * request_irq() or set_irq_type().
562 _set_gpio_triggering(bank
, offset
, IRQ_TYPE_NONE
);
564 if (bank
->regs
->pinctrl
) {
565 void __iomem
*reg
= bank
->base
+ bank
->regs
->pinctrl
;
567 /* Claim the pin for MPU */
568 __raw_writel(__raw_readl(reg
) | (1 << offset
), reg
);
571 if (bank
->regs
->ctrl
&& !bank
->mod_usage
) {
572 void __iomem
*reg
= bank
->base
+ bank
->regs
->ctrl
;
575 ctrl
= __raw_readl(reg
);
576 /* Module is enabled, clocks are not gated */
577 ctrl
&= ~GPIO_MOD_CTRL_BIT
;
578 __raw_writel(ctrl
, reg
);
579 bank
->context
.ctrl
= ctrl
;
582 bank
->mod_usage
|= 1 << offset
;
584 spin_unlock_irqrestore(&bank
->lock
, flags
);
589 static void omap_gpio_free(struct gpio_chip
*chip
, unsigned offset
)
591 struct gpio_bank
*bank
= container_of(chip
, struct gpio_bank
, chip
);
592 void __iomem
*base
= bank
->base
;
595 spin_lock_irqsave(&bank
->lock
, flags
);
597 if (bank
->regs
->wkup_en
) {
598 /* Disable wake-up during idle for dynamic tick */
599 _gpio_rmw(base
, bank
->regs
->wkup_en
, 1 << offset
, 0);
600 bank
->context
.wake_en
=
601 __raw_readl(bank
->base
+ bank
->regs
->wkup_en
);
604 bank
->mod_usage
&= ~(1 << offset
);
606 if (bank
->regs
->ctrl
&& !bank
->mod_usage
) {
607 void __iomem
*reg
= bank
->base
+ bank
->regs
->ctrl
;
610 ctrl
= __raw_readl(reg
);
611 /* Module is disabled, clocks are gated */
612 ctrl
|= GPIO_MOD_CTRL_BIT
;
613 __raw_writel(ctrl
, reg
);
614 bank
->context
.ctrl
= ctrl
;
617 _reset_gpio(bank
, bank
->chip
.base
+ offset
);
618 spin_unlock_irqrestore(&bank
->lock
, flags
);
621 * If this is the last gpio to be freed in the bank,
622 * disable the bank module.
624 if (!bank
->mod_usage
)
625 pm_runtime_put(bank
->dev
);
629 * We need to unmask the GPIO bank interrupt as soon as possible to
630 * avoid missing GPIO interrupts for other lines in the bank.
631 * Then we need to mask-read-clear-unmask the triggered GPIO lines
632 * in the bank to avoid missing nested interrupts for a GPIO line.
633 * If we wait to unmask individual GPIO lines in the bank after the
634 * line's interrupt handler has been run, we may miss some nested
637 static void gpio_irq_handler(unsigned int irq
, struct irq_desc
*desc
)
639 void __iomem
*isr_reg
= NULL
;
641 unsigned int gpio_irq
, gpio_index
;
642 struct gpio_bank
*bank
;
645 struct irq_chip
*chip
= irq_desc_get_chip(desc
);
647 chained_irq_enter(chip
, desc
);
649 bank
= irq_get_handler_data(irq
);
650 isr_reg
= bank
->base
+ bank
->regs
->irqstatus
;
651 pm_runtime_get_sync(bank
->dev
);
653 if (WARN_ON(!isr_reg
))
657 u32 isr_saved
, level_mask
= 0;
660 enabled
= _get_gpio_irqbank_mask(bank
);
661 isr_saved
= isr
= __raw_readl(isr_reg
) & enabled
;
663 if (bank
->level_mask
)
664 level_mask
= bank
->level_mask
& enabled
;
666 /* clear edge sensitive interrupts before handler(s) are
667 called so that we don't miss any interrupt occurred while
669 _disable_gpio_irqbank(bank
, isr_saved
& ~level_mask
);
670 _clear_gpio_irqbank(bank
, isr_saved
& ~level_mask
);
671 _enable_gpio_irqbank(bank
, isr_saved
& ~level_mask
);
673 /* if there is only edge sensitive GPIO pin interrupts
674 configured, we could unmask GPIO bank interrupt immediately */
675 if (!level_mask
&& !unmasked
) {
677 chained_irq_exit(chip
, desc
);
685 gpio_irq
= bank
->irq_base
;
686 for (; isr
!= 0; isr
>>= 1, gpio_irq
++) {
687 int gpio
= irq_to_gpio(bank
, gpio_irq
);
692 gpio_index
= GPIO_INDEX(bank
, gpio
);
695 * Some chips can't respond to both rising and falling
696 * at the same time. If this irq was requested with
697 * both flags, we need to flip the ICR data for the IRQ
698 * to respond to the IRQ for the opposite direction.
699 * This will be indicated in the bank toggle_mask.
701 if (bank
->toggle_mask
& (1 << gpio_index
))
702 _toggle_gpio_edge_triggering(bank
, gpio_index
);
704 generic_handle_irq(gpio_irq
);
707 /* if bank has any level sensitive GPIO pin interrupt
708 configured, we must unmask the bank interrupt only after
709 handler(s) are executed in order to avoid spurious bank
713 chained_irq_exit(chip
, desc
);
714 pm_runtime_put(bank
->dev
);
717 static void gpio_irq_shutdown(struct irq_data
*d
)
719 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
720 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
723 spin_lock_irqsave(&bank
->lock
, flags
);
724 _reset_gpio(bank
, gpio
);
725 spin_unlock_irqrestore(&bank
->lock
, flags
);
728 static void gpio_ack_irq(struct irq_data
*d
)
730 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
731 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
733 _clear_gpio_irqstatus(bank
, gpio
);
736 static void gpio_mask_irq(struct irq_data
*d
)
738 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
739 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
742 spin_lock_irqsave(&bank
->lock
, flags
);
743 _set_gpio_irqenable(bank
, gpio
, 0);
744 _set_gpio_triggering(bank
, GPIO_INDEX(bank
, gpio
), IRQ_TYPE_NONE
);
745 spin_unlock_irqrestore(&bank
->lock
, flags
);
748 static void gpio_unmask_irq(struct irq_data
*d
)
750 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
751 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
752 unsigned int irq_mask
= GPIO_BIT(bank
, gpio
);
753 u32 trigger
= irqd_get_trigger_type(d
);
756 spin_lock_irqsave(&bank
->lock
, flags
);
758 _set_gpio_triggering(bank
, GPIO_INDEX(bank
, gpio
), trigger
);
760 /* For level-triggered GPIOs, the clearing must be done after
761 * the HW source is cleared, thus after the handler has run */
762 if (bank
->level_mask
& irq_mask
) {
763 _set_gpio_irqenable(bank
, gpio
, 0);
764 _clear_gpio_irqstatus(bank
, gpio
);
767 _set_gpio_irqenable(bank
, gpio
, 1);
768 spin_unlock_irqrestore(&bank
->lock
, flags
);
771 static struct irq_chip gpio_irq_chip
= {
773 .irq_shutdown
= gpio_irq_shutdown
,
774 .irq_ack
= gpio_ack_irq
,
775 .irq_mask
= gpio_mask_irq
,
776 .irq_unmask
= gpio_unmask_irq
,
777 .irq_set_type
= gpio_irq_type
,
778 .irq_set_wake
= gpio_wake_enable
,
781 /*---------------------------------------------------------------------*/
783 static int omap_mpuio_suspend_noirq(struct device
*dev
)
785 struct platform_device
*pdev
= to_platform_device(dev
);
786 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
787 void __iomem
*mask_reg
= bank
->base
+
788 OMAP_MPUIO_GPIO_MASKIT
/ bank
->stride
;
791 spin_lock_irqsave(&bank
->lock
, flags
);
792 bank
->saved_wakeup
= __raw_readl(mask_reg
);
793 __raw_writel(0xffff & ~bank
->suspend_wakeup
, mask_reg
);
794 spin_unlock_irqrestore(&bank
->lock
, flags
);
799 static int omap_mpuio_resume_noirq(struct device
*dev
)
801 struct platform_device
*pdev
= to_platform_device(dev
);
802 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
803 void __iomem
*mask_reg
= bank
->base
+
804 OMAP_MPUIO_GPIO_MASKIT
/ bank
->stride
;
807 spin_lock_irqsave(&bank
->lock
, flags
);
808 __raw_writel(bank
->saved_wakeup
, mask_reg
);
809 spin_unlock_irqrestore(&bank
->lock
, flags
);
814 static const struct dev_pm_ops omap_mpuio_dev_pm_ops
= {
815 .suspend_noirq
= omap_mpuio_suspend_noirq
,
816 .resume_noirq
= omap_mpuio_resume_noirq
,
819 /* use platform_driver for this. */
820 static struct platform_driver omap_mpuio_driver
= {
823 .pm
= &omap_mpuio_dev_pm_ops
,
827 static struct platform_device omap_mpuio_device
= {
831 .driver
= &omap_mpuio_driver
.driver
,
833 /* could list the /proc/iomem resources */
836 static inline void mpuio_init(struct gpio_bank
*bank
)
838 platform_set_drvdata(&omap_mpuio_device
, bank
);
840 if (platform_driver_register(&omap_mpuio_driver
) == 0)
841 (void) platform_device_register(&omap_mpuio_device
);
844 /*---------------------------------------------------------------------*/
846 static int gpio_input(struct gpio_chip
*chip
, unsigned offset
)
848 struct gpio_bank
*bank
;
851 bank
= container_of(chip
, struct gpio_bank
, chip
);
852 spin_lock_irqsave(&bank
->lock
, flags
);
853 _set_gpio_direction(bank
, offset
, 1);
854 spin_unlock_irqrestore(&bank
->lock
, flags
);
858 static int gpio_is_input(struct gpio_bank
*bank
, int mask
)
860 void __iomem
*reg
= bank
->base
+ bank
->regs
->direction
;
862 return __raw_readl(reg
) & mask
;
865 static int gpio_get(struct gpio_chip
*chip
, unsigned offset
)
867 struct gpio_bank
*bank
;
870 bank
= container_of(chip
, struct gpio_bank
, chip
);
871 mask
= (1 << offset
);
873 if (gpio_is_input(bank
, mask
))
874 return _get_gpio_datain(bank
, offset
);
876 return _get_gpio_dataout(bank
, offset
);
879 static int gpio_output(struct gpio_chip
*chip
, unsigned offset
, int value
)
881 struct gpio_bank
*bank
;
884 bank
= container_of(chip
, struct gpio_bank
, chip
);
885 spin_lock_irqsave(&bank
->lock
, flags
);
886 bank
->set_dataout(bank
, offset
, value
);
887 _set_gpio_direction(bank
, offset
, 0);
888 spin_unlock_irqrestore(&bank
->lock
, flags
);
892 static int gpio_debounce(struct gpio_chip
*chip
, unsigned offset
,
895 struct gpio_bank
*bank
;
898 bank
= container_of(chip
, struct gpio_bank
, chip
);
901 bank
->dbck
= clk_get(bank
->dev
, "dbclk");
902 if (IS_ERR(bank
->dbck
))
903 dev_err(bank
->dev
, "Could not get gpio dbck\n");
906 spin_lock_irqsave(&bank
->lock
, flags
);
907 _set_gpio_debounce(bank
, offset
, debounce
);
908 spin_unlock_irqrestore(&bank
->lock
, flags
);
913 static void gpio_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
915 struct gpio_bank
*bank
;
918 bank
= container_of(chip
, struct gpio_bank
, chip
);
919 spin_lock_irqsave(&bank
->lock
, flags
);
920 bank
->set_dataout(bank
, offset
, value
);
921 spin_unlock_irqrestore(&bank
->lock
, flags
);
924 static int gpio_2irq(struct gpio_chip
*chip
, unsigned offset
)
926 struct gpio_bank
*bank
;
928 bank
= container_of(chip
, struct gpio_bank
, chip
);
929 return bank
->irq_base
+ offset
;
932 /*---------------------------------------------------------------------*/
934 static void __init
omap_gpio_show_rev(struct gpio_bank
*bank
)
939 if (called
|| bank
->regs
->revision
== USHRT_MAX
)
942 rev
= __raw_readw(bank
->base
+ bank
->regs
->revision
);
943 pr_info("OMAP GPIO hardware version %d.%d\n",
944 (rev
>> 4) & 0x0f, rev
& 0x0f);
949 /* This lock class tells lockdep that GPIO irqs are in a different
950 * category than their parents, so it won't report false recursion.
952 static struct lock_class_key gpio_lock_class
;
954 static void omap_gpio_mod_init(struct gpio_bank
*bank
)
956 void __iomem
*base
= bank
->base
;
959 if (bank
->width
== 16)
962 if (bank
->is_mpuio
) {
963 __raw_writel(l
, bank
->base
+ bank
->regs
->irqenable
);
967 _gpio_rmw(base
, bank
->regs
->irqenable
, l
, bank
->regs
->irqenable_inv
);
968 _gpio_rmw(base
, bank
->regs
->irqstatus
, l
, !bank
->regs
->irqenable_inv
);
969 if (bank
->regs
->debounce_en
)
970 __raw_writel(0, base
+ bank
->regs
->debounce_en
);
972 /* Save OE default value (0xffffffff) in the context */
973 bank
->context
.oe
= __raw_readl(bank
->base
+ bank
->regs
->direction
);
974 /* Initialize interface clk ungated, module enabled */
975 if (bank
->regs
->ctrl
)
976 __raw_writel(0, base
+ bank
->regs
->ctrl
);
979 static __devinit
void
980 omap_mpuio_alloc_gc(struct gpio_bank
*bank
, unsigned int irq_start
,
983 struct irq_chip_generic
*gc
;
984 struct irq_chip_type
*ct
;
986 gc
= irq_alloc_generic_chip("MPUIO", 1, irq_start
, bank
->base
,
989 dev_err(bank
->dev
, "Memory alloc failed for gc\n");
995 /* NOTE: No ack required, reading IRQ status clears it. */
996 ct
->chip
.irq_mask
= irq_gc_mask_set_bit
;
997 ct
->chip
.irq_unmask
= irq_gc_mask_clr_bit
;
998 ct
->chip
.irq_set_type
= gpio_irq_type
;
1000 if (bank
->regs
->wkup_en
)
1001 ct
->chip
.irq_set_wake
= gpio_wake_enable
,
1003 ct
->regs
.mask
= OMAP_MPUIO_GPIO_INT
/ bank
->stride
;
1004 irq_setup_generic_chip(gc
, IRQ_MSK(num
), IRQ_GC_INIT_MASK_CACHE
,
1005 IRQ_NOREQUEST
| IRQ_NOPROBE
, 0);
1008 static void __devinit
omap_gpio_chip_init(struct gpio_bank
*bank
)
1014 * REVISIT eventually switch from OMAP-specific gpio structs
1015 * over to the generic ones
1017 bank
->chip
.request
= omap_gpio_request
;
1018 bank
->chip
.free
= omap_gpio_free
;
1019 bank
->chip
.direction_input
= gpio_input
;
1020 bank
->chip
.get
= gpio_get
;
1021 bank
->chip
.direction_output
= gpio_output
;
1022 bank
->chip
.set_debounce
= gpio_debounce
;
1023 bank
->chip
.set
= gpio_set
;
1024 bank
->chip
.to_irq
= gpio_2irq
;
1025 if (bank
->is_mpuio
) {
1026 bank
->chip
.label
= "mpuio";
1027 if (bank
->regs
->wkup_en
)
1028 bank
->chip
.dev
= &omap_mpuio_device
.dev
;
1029 bank
->chip
.base
= OMAP_MPUIO(0);
1031 bank
->chip
.label
= "gpio";
1032 bank
->chip
.base
= gpio
;
1033 gpio
+= bank
->width
;
1035 bank
->chip
.ngpio
= bank
->width
;
1037 gpiochip_add(&bank
->chip
);
1039 for (j
= bank
->irq_base
; j
< bank
->irq_base
+ bank
->width
; j
++) {
1040 irq_set_lockdep_class(j
, &gpio_lock_class
);
1041 irq_set_chip_data(j
, bank
);
1042 if (bank
->is_mpuio
) {
1043 omap_mpuio_alloc_gc(bank
, j
, bank
->width
);
1045 irq_set_chip(j
, &gpio_irq_chip
);
1046 irq_set_handler(j
, handle_simple_irq
);
1047 set_irq_flags(j
, IRQF_VALID
);
1050 irq_set_chained_handler(bank
->irq
, gpio_irq_handler
);
1051 irq_set_handler_data(bank
->irq
, bank
);
1054 static const struct of_device_id omap_gpio_match
[];
1056 static int __devinit
omap_gpio_probe(struct platform_device
*pdev
)
1058 struct device
*dev
= &pdev
->dev
;
1059 struct device_node
*node
= dev
->of_node
;
1060 const struct of_device_id
*match
;
1061 struct omap_gpio_platform_data
*pdata
;
1062 struct resource
*res
;
1063 struct gpio_bank
*bank
;
1066 match
= of_match_device(of_match_ptr(omap_gpio_match
), dev
);
1068 pdata
= match
? match
->data
: dev
->platform_data
;
1072 bank
= devm_kzalloc(&pdev
->dev
, sizeof(struct gpio_bank
), GFP_KERNEL
);
1074 dev_err(dev
, "Memory alloc failed\n");
1078 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1079 if (unlikely(!res
)) {
1080 dev_err(dev
, "Invalid IRQ resource\n");
1084 bank
->irq
= res
->start
;
1086 bank
->dbck_flag
= pdata
->dbck_flag
;
1087 bank
->stride
= pdata
->bank_stride
;
1088 bank
->width
= pdata
->bank_width
;
1089 bank
->is_mpuio
= pdata
->is_mpuio
;
1090 bank
->non_wakeup_gpios
= pdata
->non_wakeup_gpios
;
1091 bank
->loses_context
= pdata
->loses_context
;
1092 bank
->get_context_loss_count
= pdata
->get_context_loss_count
;
1093 bank
->regs
= pdata
->regs
;
1094 #ifdef CONFIG_OF_GPIO
1095 bank
->chip
.of_node
= of_node_get(node
);
1098 bank
->irq_base
= irq_alloc_descs(-1, 0, bank
->width
, 0);
1099 if (bank
->irq_base
< 0) {
1100 dev_err(dev
, "Couldn't allocate IRQ numbers\n");
1104 bank
->domain
= irq_domain_add_legacy(node
, bank
->width
, bank
->irq_base
,
1105 0, &irq_domain_simple_ops
, NULL
);
1107 if (bank
->regs
->set_dataout
&& bank
->regs
->clr_dataout
)
1108 bank
->set_dataout
= _set_gpio_dataout_reg
;
1110 bank
->set_dataout
= _set_gpio_dataout_mask
;
1112 spin_lock_init(&bank
->lock
);
1114 /* Static mapping, never released */
1115 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1116 if (unlikely(!res
)) {
1117 dev_err(dev
, "Invalid mem resource\n");
1121 if (!devm_request_mem_region(dev
, res
->start
, resource_size(res
),
1123 dev_err(dev
, "Region already claimed\n");
1127 bank
->base
= devm_ioremap(dev
, res
->start
, resource_size(res
));
1129 dev_err(dev
, "Could not ioremap\n");
1133 platform_set_drvdata(pdev
, bank
);
1135 pm_runtime_enable(bank
->dev
);
1136 pm_runtime_irq_safe(bank
->dev
);
1137 pm_runtime_get_sync(bank
->dev
);
1142 omap_gpio_mod_init(bank
);
1143 omap_gpio_chip_init(bank
);
1144 omap_gpio_show_rev(bank
);
1146 pm_runtime_put(bank
->dev
);
1148 list_add_tail(&bank
->node
, &omap_gpio_list
);
1153 #ifdef CONFIG_ARCH_OMAP2PLUS
1155 #if defined(CONFIG_PM_SLEEP)
1156 static int omap_gpio_suspend(struct device
*dev
)
1158 struct platform_device
*pdev
= to_platform_device(dev
);
1159 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1160 void __iomem
*base
= bank
->base
;
1161 void __iomem
*wakeup_enable
;
1162 unsigned long flags
;
1164 if (!bank
->mod_usage
|| !bank
->loses_context
)
1167 if (!bank
->regs
->wkup_en
|| !bank
->suspend_wakeup
)
1170 wakeup_enable
= bank
->base
+ bank
->regs
->wkup_en
;
1172 spin_lock_irqsave(&bank
->lock
, flags
);
1173 bank
->saved_wakeup
= __raw_readl(wakeup_enable
);
1174 _gpio_rmw(base
, bank
->regs
->wkup_en
, 0xffffffff, 0);
1175 _gpio_rmw(base
, bank
->regs
->wkup_en
, bank
->suspend_wakeup
, 1);
1176 spin_unlock_irqrestore(&bank
->lock
, flags
);
1181 static int omap_gpio_resume(struct device
*dev
)
1183 struct platform_device
*pdev
= to_platform_device(dev
);
1184 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1185 void __iomem
*base
= bank
->base
;
1186 unsigned long flags
;
1188 if (!bank
->mod_usage
|| !bank
->loses_context
)
1191 if (!bank
->regs
->wkup_en
|| !bank
->saved_wakeup
)
1194 spin_lock_irqsave(&bank
->lock
, flags
);
1195 _gpio_rmw(base
, bank
->regs
->wkup_en
, 0xffffffff, 0);
1196 _gpio_rmw(base
, bank
->regs
->wkup_en
, bank
->saved_wakeup
, 1);
1197 spin_unlock_irqrestore(&bank
->lock
, flags
);
1201 #endif /* CONFIG_PM_SLEEP */
1203 #if defined(CONFIG_PM_RUNTIME)
1204 static void omap_gpio_restore_context(struct gpio_bank
*bank
);
1206 static int omap_gpio_runtime_suspend(struct device
*dev
)
1208 struct platform_device
*pdev
= to_platform_device(dev
);
1209 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1211 unsigned long flags
;
1212 u32 wake_low
, wake_hi
;
1214 spin_lock_irqsave(&bank
->lock
, flags
);
1217 * Only edges can generate a wakeup event to the PRCM.
1219 * Therefore, ensure any wake-up capable GPIOs have
1220 * edge-detection enabled before going idle to ensure a wakeup
1221 * to the PRCM is generated on a GPIO transition. (c.f. 34xx
1224 * The normal values will be restored upon ->runtime_resume()
1225 * by writing back the values saved in bank->context.
1227 wake_low
= bank
->context
.leveldetect0
& bank
->context
.wake_en
;
1229 __raw_writel(wake_low
| bank
->context
.fallingdetect
,
1230 bank
->base
+ bank
->regs
->fallingdetect
);
1231 wake_hi
= bank
->context
.leveldetect1
& bank
->context
.wake_en
;
1233 __raw_writel(wake_hi
| bank
->context
.risingdetect
,
1234 bank
->base
+ bank
->regs
->risingdetect
);
1236 if (bank
->power_mode
!= OFF_MODE
) {
1237 bank
->power_mode
= 0;
1238 goto update_gpio_context_count
;
1241 * If going to OFF, remove triggering for all
1242 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1243 * generated. See OMAP2420 Errata item 1.101.
1245 bank
->saved_datain
= __raw_readl(bank
->base
+
1246 bank
->regs
->datain
);
1247 l1
= __raw_readl(bank
->base
+ bank
->regs
->fallingdetect
);
1248 l2
= __raw_readl(bank
->base
+ bank
->regs
->risingdetect
);
1250 bank
->saved_fallingdetect
= l1
;
1251 bank
->saved_risingdetect
= l2
;
1252 l1
&= ~bank
->enabled_non_wakeup_gpios
;
1253 l2
&= ~bank
->enabled_non_wakeup_gpios
;
1255 __raw_writel(l1
, bank
->base
+ bank
->regs
->fallingdetect
);
1256 __raw_writel(l2
, bank
->base
+ bank
->regs
->risingdetect
);
1258 bank
->workaround_enabled
= true;
1260 update_gpio_context_count
:
1261 if (bank
->get_context_loss_count
)
1262 bank
->context_loss_count
=
1263 bank
->get_context_loss_count(bank
->dev
);
1265 _gpio_dbck_disable(bank
);
1266 spin_unlock_irqrestore(&bank
->lock
, flags
);
1271 static int omap_gpio_runtime_resume(struct device
*dev
)
1273 struct platform_device
*pdev
= to_platform_device(dev
);
1274 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1275 int context_lost_cnt_after
;
1276 u32 l
= 0, gen
, gen0
, gen1
;
1277 unsigned long flags
;
1279 spin_lock_irqsave(&bank
->lock
, flags
);
1280 _gpio_dbck_enable(bank
);
1283 * In ->runtime_suspend(), level-triggered, wakeup-enabled
1284 * GPIOs were set to edge trigger also in order to be able to
1285 * generate a PRCM wakeup. Here we restore the
1286 * pre-runtime_suspend() values for edge triggering.
1288 __raw_writel(bank
->context
.fallingdetect
,
1289 bank
->base
+ bank
->regs
->fallingdetect
);
1290 __raw_writel(bank
->context
.risingdetect
,
1291 bank
->base
+ bank
->regs
->risingdetect
);
1293 if (!bank
->workaround_enabled
) {
1294 spin_unlock_irqrestore(&bank
->lock
, flags
);
1298 if (bank
->get_context_loss_count
) {
1299 context_lost_cnt_after
=
1300 bank
->get_context_loss_count(bank
->dev
);
1301 if (context_lost_cnt_after
!= bank
->context_loss_count
||
1302 !context_lost_cnt_after
) {
1303 omap_gpio_restore_context(bank
);
1305 spin_unlock_irqrestore(&bank
->lock
, flags
);
1310 __raw_writel(bank
->saved_fallingdetect
,
1311 bank
->base
+ bank
->regs
->fallingdetect
);
1312 __raw_writel(bank
->saved_risingdetect
,
1313 bank
->base
+ bank
->regs
->risingdetect
);
1314 l
= __raw_readl(bank
->base
+ bank
->regs
->datain
);
1317 * Check if any of the non-wakeup interrupt GPIOs have changed
1318 * state. If so, generate an IRQ by software. This is
1319 * horribly racy, but it's the best we can do to work around
1322 l
^= bank
->saved_datain
;
1323 l
&= bank
->enabled_non_wakeup_gpios
;
1326 * No need to generate IRQs for the rising edge for gpio IRQs
1327 * configured with falling edge only; and vice versa.
1329 gen0
= l
& bank
->saved_fallingdetect
;
1330 gen0
&= bank
->saved_datain
;
1332 gen1
= l
& bank
->saved_risingdetect
;
1333 gen1
&= ~(bank
->saved_datain
);
1335 /* FIXME: Consider GPIO IRQs with level detections properly! */
1336 gen
= l
& (~(bank
->saved_fallingdetect
) & ~(bank
->saved_risingdetect
));
1337 /* Consider all GPIO IRQs needed to be updated */
1343 old0
= __raw_readl(bank
->base
+ bank
->regs
->leveldetect0
);
1344 old1
= __raw_readl(bank
->base
+ bank
->regs
->leveldetect1
);
1346 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
1347 __raw_writel(old0
| gen
, bank
->base
+
1348 bank
->regs
->leveldetect0
);
1349 __raw_writel(old1
| gen
, bank
->base
+
1350 bank
->regs
->leveldetect1
);
1353 if (cpu_is_omap44xx()) {
1354 __raw_writel(old0
| l
, bank
->base
+
1355 bank
->regs
->leveldetect0
);
1356 __raw_writel(old1
| l
, bank
->base
+
1357 bank
->regs
->leveldetect1
);
1359 __raw_writel(old0
, bank
->base
+ bank
->regs
->leveldetect0
);
1360 __raw_writel(old1
, bank
->base
+ bank
->regs
->leveldetect1
);
1363 bank
->workaround_enabled
= false;
1364 spin_unlock_irqrestore(&bank
->lock
, flags
);
1368 #endif /* CONFIG_PM_RUNTIME */
1370 void omap2_gpio_prepare_for_idle(int pwr_mode
)
1372 struct gpio_bank
*bank
;
1374 list_for_each_entry(bank
, &omap_gpio_list
, node
) {
1375 if (!bank
->mod_usage
|| !bank
->loses_context
)
1378 bank
->power_mode
= pwr_mode
;
1380 pm_runtime_put_sync_suspend(bank
->dev
);
1384 void omap2_gpio_resume_after_idle(void)
1386 struct gpio_bank
*bank
;
1388 list_for_each_entry(bank
, &omap_gpio_list
, node
) {
1389 if (!bank
->mod_usage
|| !bank
->loses_context
)
1392 pm_runtime_get_sync(bank
->dev
);
1396 #if defined(CONFIG_PM_RUNTIME)
1397 static void omap_gpio_restore_context(struct gpio_bank
*bank
)
1399 __raw_writel(bank
->context
.wake_en
,
1400 bank
->base
+ bank
->regs
->wkup_en
);
1401 __raw_writel(bank
->context
.ctrl
, bank
->base
+ bank
->regs
->ctrl
);
1402 __raw_writel(bank
->context
.leveldetect0
,
1403 bank
->base
+ bank
->regs
->leveldetect0
);
1404 __raw_writel(bank
->context
.leveldetect1
,
1405 bank
->base
+ bank
->regs
->leveldetect1
);
1406 __raw_writel(bank
->context
.risingdetect
,
1407 bank
->base
+ bank
->regs
->risingdetect
);
1408 __raw_writel(bank
->context
.fallingdetect
,
1409 bank
->base
+ bank
->regs
->fallingdetect
);
1410 if (bank
->regs
->set_dataout
&& bank
->regs
->clr_dataout
)
1411 __raw_writel(bank
->context
.dataout
,
1412 bank
->base
+ bank
->regs
->set_dataout
);
1414 __raw_writel(bank
->context
.dataout
,
1415 bank
->base
+ bank
->regs
->dataout
);
1416 __raw_writel(bank
->context
.oe
, bank
->base
+ bank
->regs
->direction
);
1418 if (bank
->dbck_enable_mask
) {
1419 __raw_writel(bank
->context
.debounce
, bank
->base
+
1420 bank
->regs
->debounce
);
1421 __raw_writel(bank
->context
.debounce_en
,
1422 bank
->base
+ bank
->regs
->debounce_en
);
1425 __raw_writel(bank
->context
.irqenable1
,
1426 bank
->base
+ bank
->regs
->irqenable
);
1427 __raw_writel(bank
->context
.irqenable2
,
1428 bank
->base
+ bank
->regs
->irqenable2
);
1430 #endif /* CONFIG_PM_RUNTIME */
1432 #define omap_gpio_suspend NULL
1433 #define omap_gpio_resume NULL
1434 #define omap_gpio_runtime_suspend NULL
1435 #define omap_gpio_runtime_resume NULL
1438 static const struct dev_pm_ops gpio_pm_ops
= {
1439 SET_SYSTEM_SLEEP_PM_OPS(omap_gpio_suspend
, omap_gpio_resume
)
1440 SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend
, omap_gpio_runtime_resume
,
1444 #if defined(CONFIG_OF)
1445 static struct omap_gpio_reg_offs omap2_gpio_regs
= {
1446 .revision
= OMAP24XX_GPIO_REVISION
,
1447 .direction
= OMAP24XX_GPIO_OE
,
1448 .datain
= OMAP24XX_GPIO_DATAIN
,
1449 .dataout
= OMAP24XX_GPIO_DATAOUT
,
1450 .set_dataout
= OMAP24XX_GPIO_SETDATAOUT
,
1451 .clr_dataout
= OMAP24XX_GPIO_CLEARDATAOUT
,
1452 .irqstatus
= OMAP24XX_GPIO_IRQSTATUS1
,
1453 .irqstatus2
= OMAP24XX_GPIO_IRQSTATUS2
,
1454 .irqenable
= OMAP24XX_GPIO_IRQENABLE1
,
1455 .irqenable2
= OMAP24XX_GPIO_IRQENABLE2
,
1456 .set_irqenable
= OMAP24XX_GPIO_SETIRQENABLE1
,
1457 .clr_irqenable
= OMAP24XX_GPIO_CLEARIRQENABLE1
,
1458 .debounce
= OMAP24XX_GPIO_DEBOUNCE_VAL
,
1459 .debounce_en
= OMAP24XX_GPIO_DEBOUNCE_EN
,
1460 .ctrl
= OMAP24XX_GPIO_CTRL
,
1461 .wkup_en
= OMAP24XX_GPIO_WAKE_EN
,
1462 .leveldetect0
= OMAP24XX_GPIO_LEVELDETECT0
,
1463 .leveldetect1
= OMAP24XX_GPIO_LEVELDETECT1
,
1464 .risingdetect
= OMAP24XX_GPIO_RISINGDETECT
,
1465 .fallingdetect
= OMAP24XX_GPIO_FALLINGDETECT
,
1468 static struct omap_gpio_reg_offs omap4_gpio_regs
= {
1469 .revision
= OMAP4_GPIO_REVISION
,
1470 .direction
= OMAP4_GPIO_OE
,
1471 .datain
= OMAP4_GPIO_DATAIN
,
1472 .dataout
= OMAP4_GPIO_DATAOUT
,
1473 .set_dataout
= OMAP4_GPIO_SETDATAOUT
,
1474 .clr_dataout
= OMAP4_GPIO_CLEARDATAOUT
,
1475 .irqstatus
= OMAP4_GPIO_IRQSTATUS0
,
1476 .irqstatus2
= OMAP4_GPIO_IRQSTATUS1
,
1477 .irqenable
= OMAP4_GPIO_IRQSTATUSSET0
,
1478 .irqenable2
= OMAP4_GPIO_IRQSTATUSSET1
,
1479 .set_irqenable
= OMAP4_GPIO_IRQSTATUSSET0
,
1480 .clr_irqenable
= OMAP4_GPIO_IRQSTATUSCLR0
,
1481 .debounce
= OMAP4_GPIO_DEBOUNCINGTIME
,
1482 .debounce_en
= OMAP4_GPIO_DEBOUNCENABLE
,
1483 .ctrl
= OMAP4_GPIO_CTRL
,
1484 .wkup_en
= OMAP4_GPIO_IRQWAKEN0
,
1485 .leveldetect0
= OMAP4_GPIO_LEVELDETECT0
,
1486 .leveldetect1
= OMAP4_GPIO_LEVELDETECT1
,
1487 .risingdetect
= OMAP4_GPIO_RISINGDETECT
,
1488 .fallingdetect
= OMAP4_GPIO_FALLINGDETECT
,
1491 static struct omap_gpio_platform_data omap2_pdata
= {
1492 .regs
= &omap2_gpio_regs
,
1497 static struct omap_gpio_platform_data omap3_pdata
= {
1498 .regs
= &omap2_gpio_regs
,
1503 static struct omap_gpio_platform_data omap4_pdata
= {
1504 .regs
= &omap4_gpio_regs
,
1509 static const struct of_device_id omap_gpio_match
[] = {
1511 .compatible
= "ti,omap4-gpio",
1512 .data
= &omap4_pdata
,
1515 .compatible
= "ti,omap3-gpio",
1516 .data
= &omap3_pdata
,
1519 .compatible
= "ti,omap2-gpio",
1520 .data
= &omap2_pdata
,
1524 MODULE_DEVICE_TABLE(of
, omap_gpio_match
);
1527 static struct platform_driver omap_gpio_driver
= {
1528 .probe
= omap_gpio_probe
,
1530 .name
= "omap_gpio",
1532 .of_match_table
= of_match_ptr(omap_gpio_match
),
1537 * gpio driver register needs to be done before
1538 * machine_init functions access gpio APIs.
1539 * Hence omap_gpio_drv_reg() is a postcore_initcall.
1541 static int __init
omap_gpio_drv_reg(void)
1543 return platform_driver_register(&omap_gpio_driver
);
1545 postcore_initcall(omap_gpio_drv_reg
);