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
;
61 u32 enabled_non_wakeup_gpios
;
62 struct gpio_regs context
;
67 struct gpio_chip chip
;
78 int context_loss_count
;
80 bool workaround_enabled
;
82 void (*set_dataout
)(struct gpio_bank
*bank
, int gpio
, int enable
);
83 int (*get_context_loss_count
)(struct device
*dev
);
85 struct omap_gpio_reg_offs
*regs
;
88 #define GPIO_INDEX(bank, gpio) (gpio % bank->width)
89 #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))
90 #define GPIO_MOD_CTRL_BIT BIT(0)
92 static int irq_to_gpio(struct gpio_bank
*bank
, unsigned int gpio_irq
)
94 return gpio_irq
- bank
->irq_base
+ bank
->chip
.base
;
97 static void _set_gpio_direction(struct gpio_bank
*bank
, int gpio
, int is_input
)
99 void __iomem
*reg
= bank
->base
;
102 reg
+= bank
->regs
->direction
;
103 l
= __raw_readl(reg
);
108 __raw_writel(l
, reg
);
109 bank
->context
.oe
= l
;
113 /* set data out value using dedicate set/clear register */
114 static void _set_gpio_dataout_reg(struct gpio_bank
*bank
, int gpio
, int enable
)
116 void __iomem
*reg
= bank
->base
;
117 u32 l
= GPIO_BIT(bank
, gpio
);
120 reg
+= bank
->regs
->set_dataout
;
121 bank
->context
.dataout
|= l
;
123 reg
+= bank
->regs
->clr_dataout
;
124 bank
->context
.dataout
&= ~l
;
127 __raw_writel(l
, reg
);
130 /* set data out value using mask register */
131 static void _set_gpio_dataout_mask(struct gpio_bank
*bank
, int gpio
, int enable
)
133 void __iomem
*reg
= bank
->base
+ bank
->regs
->dataout
;
134 u32 gpio_bit
= GPIO_BIT(bank
, gpio
);
137 l
= __raw_readl(reg
);
142 __raw_writel(l
, reg
);
143 bank
->context
.dataout
= l
;
146 static int _get_gpio_datain(struct gpio_bank
*bank
, int offset
)
148 void __iomem
*reg
= bank
->base
+ bank
->regs
->datain
;
150 return (__raw_readl(reg
) & (1 << offset
)) != 0;
153 static int _get_gpio_dataout(struct gpio_bank
*bank
, int offset
)
155 void __iomem
*reg
= bank
->base
+ bank
->regs
->dataout
;
157 return (__raw_readl(reg
) & (1 << offset
)) != 0;
160 static inline void _gpio_rmw(void __iomem
*base
, u32 reg
, u32 mask
, bool set
)
162 int l
= __raw_readl(base
+ reg
);
169 __raw_writel(l
, base
+ reg
);
172 static inline void _gpio_dbck_enable(struct gpio_bank
*bank
)
174 if (bank
->dbck_enable_mask
&& !bank
->dbck_enabled
) {
175 clk_enable(bank
->dbck
);
176 bank
->dbck_enabled
= true;
178 __raw_writel(bank
->dbck_enable_mask
,
179 bank
->base
+ bank
->regs
->debounce_en
);
183 static inline void _gpio_dbck_disable(struct gpio_bank
*bank
)
185 if (bank
->dbck_enable_mask
&& bank
->dbck_enabled
) {
187 * Disable debounce before cutting it's clock. If debounce is
188 * enabled but the clock is not, GPIO module seems to be unable
189 * to detect events and generate interrupts at least on OMAP3.
191 __raw_writel(0, bank
->base
+ bank
->regs
->debounce_en
);
193 clk_disable(bank
->dbck
);
194 bank
->dbck_enabled
= false;
199 * _set_gpio_debounce - low level gpio debounce time
200 * @bank: the gpio bank we're acting upon
201 * @gpio: the gpio number on this @gpio
202 * @debounce: debounce time to use
204 * OMAP's debounce time is in 31us steps so we need
205 * to convert and round up to the closest unit.
207 static void _set_gpio_debounce(struct gpio_bank
*bank
, unsigned gpio
,
214 if (!bank
->dbck_flag
)
219 else if (debounce
> 7936)
222 debounce
= (debounce
/ 0x1f) - 1;
224 l
= GPIO_BIT(bank
, gpio
);
226 clk_enable(bank
->dbck
);
227 reg
= bank
->base
+ bank
->regs
->debounce
;
228 __raw_writel(debounce
, reg
);
230 reg
= bank
->base
+ bank
->regs
->debounce_en
;
231 val
= __raw_readl(reg
);
237 bank
->dbck_enable_mask
= val
;
239 __raw_writel(val
, reg
);
240 clk_disable(bank
->dbck
);
242 * Enable debounce clock per module.
243 * This call is mandatory because in omap_gpio_request() when
244 * *_runtime_get_sync() is called, _gpio_dbck_enable() within
245 * runtime callbck fails to turn on dbck because dbck_enable_mask
246 * used within _gpio_dbck_enable() is still not initialized at
247 * that point. Therefore we have to enable dbck here.
249 _gpio_dbck_enable(bank
);
250 if (bank
->dbck_enable_mask
) {
251 bank
->context
.debounce
= debounce
;
252 bank
->context
.debounce_en
= val
;
256 static inline void set_gpio_trigger(struct gpio_bank
*bank
, int gpio
,
259 void __iomem
*base
= bank
->base
;
260 u32 gpio_bit
= 1 << gpio
;
262 _gpio_rmw(base
, bank
->regs
->leveldetect0
, gpio_bit
,
263 trigger
& IRQ_TYPE_LEVEL_LOW
);
264 _gpio_rmw(base
, bank
->regs
->leveldetect1
, gpio_bit
,
265 trigger
& IRQ_TYPE_LEVEL_HIGH
);
266 _gpio_rmw(base
, bank
->regs
->risingdetect
, gpio_bit
,
267 trigger
& IRQ_TYPE_EDGE_RISING
);
268 _gpio_rmw(base
, bank
->regs
->fallingdetect
, gpio_bit
,
269 trigger
& IRQ_TYPE_EDGE_FALLING
);
271 bank
->context
.leveldetect0
=
272 __raw_readl(bank
->base
+ bank
->regs
->leveldetect0
);
273 bank
->context
.leveldetect1
=
274 __raw_readl(bank
->base
+ bank
->regs
->leveldetect1
);
275 bank
->context
.risingdetect
=
276 __raw_readl(bank
->base
+ bank
->regs
->risingdetect
);
277 bank
->context
.fallingdetect
=
278 __raw_readl(bank
->base
+ bank
->regs
->fallingdetect
);
280 if (likely(!(bank
->non_wakeup_gpios
& gpio_bit
))) {
281 _gpio_rmw(base
, bank
->regs
->wkup_en
, gpio_bit
, trigger
!= 0);
282 bank
->context
.wake_en
=
283 __raw_readl(bank
->base
+ bank
->regs
->wkup_en
);
286 /* This part needs to be executed always for OMAP{34xx, 44xx} */
287 if (!bank
->regs
->irqctrl
) {
288 /* On omap24xx proceed only when valid GPIO bit is set */
289 if (bank
->non_wakeup_gpios
) {
290 if (!(bank
->non_wakeup_gpios
& gpio_bit
))
295 * Log the edge gpio and manually trigger the IRQ
296 * after resume if the input level changes
297 * to avoid irq lost during PER RET/OFF mode
298 * Applies for omap2 non-wakeup gpio and all omap3 gpios
300 if (trigger
& IRQ_TYPE_EDGE_BOTH
)
301 bank
->enabled_non_wakeup_gpios
|= gpio_bit
;
303 bank
->enabled_non_wakeup_gpios
&= ~gpio_bit
;
308 __raw_readl(bank
->base
+ bank
->regs
->leveldetect0
) |
309 __raw_readl(bank
->base
+ bank
->regs
->leveldetect1
);
312 #ifdef CONFIG_ARCH_OMAP1
314 * This only applies to chips that can't do both rising and falling edge
315 * detection at once. For all other chips, this function is a noop.
317 static void _toggle_gpio_edge_triggering(struct gpio_bank
*bank
, int gpio
)
319 void __iomem
*reg
= bank
->base
;
322 if (!bank
->regs
->irqctrl
)
325 reg
+= bank
->regs
->irqctrl
;
327 l
= __raw_readl(reg
);
333 __raw_writel(l
, reg
);
336 static void _toggle_gpio_edge_triggering(struct gpio_bank
*bank
, int gpio
) {}
339 static int _set_gpio_triggering(struct gpio_bank
*bank
, int gpio
,
342 void __iomem
*reg
= bank
->base
;
343 void __iomem
*base
= bank
->base
;
346 if (bank
->regs
->leveldetect0
&& bank
->regs
->wkup_en
) {
347 set_gpio_trigger(bank
, gpio
, trigger
);
348 } else if (bank
->regs
->irqctrl
) {
349 reg
+= bank
->regs
->irqctrl
;
351 l
= __raw_readl(reg
);
352 if ((trigger
& IRQ_TYPE_SENSE_MASK
) == IRQ_TYPE_EDGE_BOTH
)
353 bank
->toggle_mask
|= 1 << gpio
;
354 if (trigger
& IRQ_TYPE_EDGE_RISING
)
356 else if (trigger
& IRQ_TYPE_EDGE_FALLING
)
361 __raw_writel(l
, reg
);
362 } else if (bank
->regs
->edgectrl1
) {
364 reg
+= bank
->regs
->edgectrl2
;
366 reg
+= bank
->regs
->edgectrl1
;
369 l
= __raw_readl(reg
);
370 l
&= ~(3 << (gpio
<< 1));
371 if (trigger
& IRQ_TYPE_EDGE_RISING
)
372 l
|= 2 << (gpio
<< 1);
373 if (trigger
& IRQ_TYPE_EDGE_FALLING
)
374 l
|= 1 << (gpio
<< 1);
376 /* Enable wake-up during idle for dynamic tick */
377 _gpio_rmw(base
, bank
->regs
->wkup_en
, 1 << gpio
, trigger
);
378 bank
->context
.wake_en
=
379 __raw_readl(bank
->base
+ bank
->regs
->wkup_en
);
380 __raw_writel(l
, reg
);
385 static int gpio_irq_type(struct irq_data
*d
, unsigned type
)
387 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
392 if (!cpu_class_is_omap2() && d
->irq
> IH_MPUIO_BASE
)
393 gpio
= OMAP_MPUIO(d
->irq
- IH_MPUIO_BASE
);
395 gpio
= irq_to_gpio(bank
, d
->irq
);
397 if (type
& ~IRQ_TYPE_SENSE_MASK
)
400 if (!bank
->regs
->leveldetect0
&&
401 (type
& (IRQ_TYPE_LEVEL_LOW
|IRQ_TYPE_LEVEL_HIGH
)))
404 spin_lock_irqsave(&bank
->lock
, flags
);
405 retval
= _set_gpio_triggering(bank
, GPIO_INDEX(bank
, gpio
), type
);
406 spin_unlock_irqrestore(&bank
->lock
, flags
);
408 if (type
& (IRQ_TYPE_LEVEL_LOW
| IRQ_TYPE_LEVEL_HIGH
))
409 __irq_set_handler_locked(d
->irq
, handle_level_irq
);
410 else if (type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_EDGE_RISING
))
411 __irq_set_handler_locked(d
->irq
, handle_edge_irq
);
416 static void _clear_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
)
418 void __iomem
*reg
= bank
->base
;
420 reg
+= bank
->regs
->irqstatus
;
421 __raw_writel(gpio_mask
, reg
);
423 /* Workaround for clearing DSP GPIO interrupts to allow retention */
424 if (bank
->regs
->irqstatus2
) {
425 reg
= bank
->base
+ bank
->regs
->irqstatus2
;
426 __raw_writel(gpio_mask
, reg
);
429 /* Flush posted write for the irq status to avoid spurious interrupts */
433 static inline void _clear_gpio_irqstatus(struct gpio_bank
*bank
, int gpio
)
435 _clear_gpio_irqbank(bank
, GPIO_BIT(bank
, gpio
));
438 static u32
_get_gpio_irqbank_mask(struct gpio_bank
*bank
)
440 void __iomem
*reg
= bank
->base
;
442 u32 mask
= (1 << bank
->width
) - 1;
444 reg
+= bank
->regs
->irqenable
;
445 l
= __raw_readl(reg
);
446 if (bank
->regs
->irqenable_inv
)
452 static void _enable_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
)
454 void __iomem
*reg
= bank
->base
;
457 if (bank
->regs
->set_irqenable
) {
458 reg
+= bank
->regs
->set_irqenable
;
460 bank
->context
.irqenable1
|= gpio_mask
;
462 reg
+= bank
->regs
->irqenable
;
463 l
= __raw_readl(reg
);
464 if (bank
->regs
->irqenable_inv
)
468 bank
->context
.irqenable1
= l
;
471 __raw_writel(l
, reg
);
474 static void _disable_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
)
476 void __iomem
*reg
= bank
->base
;
479 if (bank
->regs
->clr_irqenable
) {
480 reg
+= bank
->regs
->clr_irqenable
;
482 bank
->context
.irqenable1
&= ~gpio_mask
;
484 reg
+= bank
->regs
->irqenable
;
485 l
= __raw_readl(reg
);
486 if (bank
->regs
->irqenable_inv
)
490 bank
->context
.irqenable1
= l
;
493 __raw_writel(l
, reg
);
496 static inline void _set_gpio_irqenable(struct gpio_bank
*bank
, int gpio
, int enable
)
499 _enable_gpio_irqbank(bank
, GPIO_BIT(bank
, gpio
));
501 _disable_gpio_irqbank(bank
, GPIO_BIT(bank
, gpio
));
505 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
506 * 1510 does not seem to have a wake-up register. If JTAG is connected
507 * to the target, system will wake up always on GPIO events. While
508 * system is running all registered GPIO interrupts need to have wake-up
509 * enabled. When system is suspended, only selected GPIO interrupts need
510 * to have wake-up enabled.
512 static int _set_gpio_wakeup(struct gpio_bank
*bank
, int gpio
, int enable
)
514 u32 gpio_bit
= GPIO_BIT(bank
, gpio
);
517 if (bank
->non_wakeup_gpios
& gpio_bit
) {
519 "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio
);
523 spin_lock_irqsave(&bank
->lock
, flags
);
525 bank
->context
.wake_en
|= gpio_bit
;
527 bank
->context
.wake_en
&= ~gpio_bit
;
529 __raw_writel(bank
->context
.wake_en
, bank
->base
+ bank
->regs
->wkup_en
);
530 spin_unlock_irqrestore(&bank
->lock
, flags
);
535 static void _reset_gpio(struct gpio_bank
*bank
, int gpio
)
537 _set_gpio_direction(bank
, GPIO_INDEX(bank
, gpio
), 1);
538 _set_gpio_irqenable(bank
, gpio
, 0);
539 _clear_gpio_irqstatus(bank
, gpio
);
540 _set_gpio_triggering(bank
, GPIO_INDEX(bank
, gpio
), IRQ_TYPE_NONE
);
543 /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
544 static int gpio_wake_enable(struct irq_data
*d
, unsigned int enable
)
546 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
547 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
549 return _set_gpio_wakeup(bank
, gpio
, enable
);
552 static int omap_gpio_request(struct gpio_chip
*chip
, unsigned offset
)
554 struct gpio_bank
*bank
= container_of(chip
, struct gpio_bank
, chip
);
558 * If this is the first gpio_request for the bank,
559 * enable the bank module.
561 if (!bank
->mod_usage
)
562 pm_runtime_get_sync(bank
->dev
);
564 spin_lock_irqsave(&bank
->lock
, flags
);
565 /* Set trigger to none. You need to enable the desired trigger with
566 * request_irq() or set_irq_type().
568 _set_gpio_triggering(bank
, offset
, IRQ_TYPE_NONE
);
570 if (bank
->regs
->pinctrl
) {
571 void __iomem
*reg
= bank
->base
+ bank
->regs
->pinctrl
;
573 /* Claim the pin for MPU */
574 __raw_writel(__raw_readl(reg
) | (1 << offset
), reg
);
577 if (bank
->regs
->ctrl
&& !bank
->mod_usage
) {
578 void __iomem
*reg
= bank
->base
+ bank
->regs
->ctrl
;
581 ctrl
= __raw_readl(reg
);
582 /* Module is enabled, clocks are not gated */
583 ctrl
&= ~GPIO_MOD_CTRL_BIT
;
584 __raw_writel(ctrl
, reg
);
585 bank
->context
.ctrl
= ctrl
;
588 bank
->mod_usage
|= 1 << offset
;
590 spin_unlock_irqrestore(&bank
->lock
, flags
);
595 static void omap_gpio_free(struct gpio_chip
*chip
, unsigned offset
)
597 struct gpio_bank
*bank
= container_of(chip
, struct gpio_bank
, chip
);
598 void __iomem
*base
= bank
->base
;
601 spin_lock_irqsave(&bank
->lock
, flags
);
603 if (bank
->regs
->wkup_en
) {
604 /* Disable wake-up during idle for dynamic tick */
605 _gpio_rmw(base
, bank
->regs
->wkup_en
, 1 << offset
, 0);
606 bank
->context
.wake_en
=
607 __raw_readl(bank
->base
+ bank
->regs
->wkup_en
);
610 bank
->mod_usage
&= ~(1 << offset
);
612 if (bank
->regs
->ctrl
&& !bank
->mod_usage
) {
613 void __iomem
*reg
= bank
->base
+ bank
->regs
->ctrl
;
616 ctrl
= __raw_readl(reg
);
617 /* Module is disabled, clocks are gated */
618 ctrl
|= GPIO_MOD_CTRL_BIT
;
619 __raw_writel(ctrl
, reg
);
620 bank
->context
.ctrl
= ctrl
;
623 _reset_gpio(bank
, bank
->chip
.base
+ offset
);
624 spin_unlock_irqrestore(&bank
->lock
, flags
);
627 * If this is the last gpio to be freed in the bank,
628 * disable the bank module.
630 if (!bank
->mod_usage
)
631 pm_runtime_put(bank
->dev
);
635 * We need to unmask the GPIO bank interrupt as soon as possible to
636 * avoid missing GPIO interrupts for other lines in the bank.
637 * Then we need to mask-read-clear-unmask the triggered GPIO lines
638 * in the bank to avoid missing nested interrupts for a GPIO line.
639 * If we wait to unmask individual GPIO lines in the bank after the
640 * line's interrupt handler has been run, we may miss some nested
643 static void gpio_irq_handler(unsigned int irq
, struct irq_desc
*desc
)
645 void __iomem
*isr_reg
= NULL
;
647 unsigned int gpio_irq
, gpio_index
;
648 struct gpio_bank
*bank
;
650 struct irq_chip
*chip
= irq_desc_get_chip(desc
);
652 chained_irq_enter(chip
, desc
);
654 bank
= irq_get_handler_data(irq
);
655 isr_reg
= bank
->base
+ bank
->regs
->irqstatus
;
656 pm_runtime_get_sync(bank
->dev
);
658 if (WARN_ON(!isr_reg
))
662 u32 isr_saved
, level_mask
= 0;
665 enabled
= _get_gpio_irqbank_mask(bank
);
666 isr_saved
= isr
= __raw_readl(isr_reg
) & enabled
;
668 if (bank
->level_mask
)
669 level_mask
= bank
->level_mask
& enabled
;
671 /* clear edge sensitive interrupts before handler(s) are
672 called so that we don't miss any interrupt occurred while
674 _disable_gpio_irqbank(bank
, isr_saved
& ~level_mask
);
675 _clear_gpio_irqbank(bank
, isr_saved
& ~level_mask
);
676 _enable_gpio_irqbank(bank
, isr_saved
& ~level_mask
);
678 /* if there is only edge sensitive GPIO pin interrupts
679 configured, we could unmask GPIO bank interrupt immediately */
680 if (!level_mask
&& !unmasked
) {
682 chained_irq_exit(chip
, desc
);
688 gpio_irq
= bank
->irq_base
;
689 for (; isr
!= 0; isr
>>= 1, gpio_irq
++) {
690 int gpio
= irq_to_gpio(bank
, gpio_irq
);
695 gpio_index
= GPIO_INDEX(bank
, gpio
);
698 * Some chips can't respond to both rising and falling
699 * at the same time. If this irq was requested with
700 * both flags, we need to flip the ICR data for the IRQ
701 * to respond to the IRQ for the opposite direction.
702 * This will be indicated in the bank toggle_mask.
704 if (bank
->toggle_mask
& (1 << gpio_index
))
705 _toggle_gpio_edge_triggering(bank
, gpio_index
);
707 generic_handle_irq(gpio_irq
);
710 /* if bank has any level sensitive GPIO pin interrupt
711 configured, we must unmask the bank interrupt only after
712 handler(s) are executed in order to avoid spurious bank
716 chained_irq_exit(chip
, desc
);
717 pm_runtime_put(bank
->dev
);
720 static void gpio_irq_shutdown(struct irq_data
*d
)
722 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
723 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
726 spin_lock_irqsave(&bank
->lock
, flags
);
727 _reset_gpio(bank
, gpio
);
728 spin_unlock_irqrestore(&bank
->lock
, flags
);
731 static void gpio_ack_irq(struct irq_data
*d
)
733 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
734 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
736 _clear_gpio_irqstatus(bank
, gpio
);
739 static void gpio_mask_irq(struct irq_data
*d
)
741 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
742 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
745 spin_lock_irqsave(&bank
->lock
, flags
);
746 _set_gpio_irqenable(bank
, gpio
, 0);
747 _set_gpio_triggering(bank
, GPIO_INDEX(bank
, gpio
), IRQ_TYPE_NONE
);
748 spin_unlock_irqrestore(&bank
->lock
, flags
);
751 static void gpio_unmask_irq(struct irq_data
*d
)
753 struct gpio_bank
*bank
= irq_data_get_irq_chip_data(d
);
754 unsigned int gpio
= irq_to_gpio(bank
, d
->irq
);
755 unsigned int irq_mask
= GPIO_BIT(bank
, gpio
);
756 u32 trigger
= irqd_get_trigger_type(d
);
759 spin_lock_irqsave(&bank
->lock
, flags
);
761 _set_gpio_triggering(bank
, GPIO_INDEX(bank
, gpio
), trigger
);
763 /* For level-triggered GPIOs, the clearing must be done after
764 * the HW source is cleared, thus after the handler has run */
765 if (bank
->level_mask
& irq_mask
) {
766 _set_gpio_irqenable(bank
, gpio
, 0);
767 _clear_gpio_irqstatus(bank
, gpio
);
770 _set_gpio_irqenable(bank
, gpio
, 1);
771 spin_unlock_irqrestore(&bank
->lock
, flags
);
774 static struct irq_chip gpio_irq_chip
= {
776 .irq_shutdown
= gpio_irq_shutdown
,
777 .irq_ack
= gpio_ack_irq
,
778 .irq_mask
= gpio_mask_irq
,
779 .irq_unmask
= gpio_unmask_irq
,
780 .irq_set_type
= gpio_irq_type
,
781 .irq_set_wake
= gpio_wake_enable
,
784 /*---------------------------------------------------------------------*/
786 static int omap_mpuio_suspend_noirq(struct device
*dev
)
788 struct platform_device
*pdev
= to_platform_device(dev
);
789 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
790 void __iomem
*mask_reg
= bank
->base
+
791 OMAP_MPUIO_GPIO_MASKIT
/ bank
->stride
;
794 spin_lock_irqsave(&bank
->lock
, flags
);
795 __raw_writel(0xffff & ~bank
->context
.wake_en
, mask_reg
);
796 spin_unlock_irqrestore(&bank
->lock
, flags
);
801 static int omap_mpuio_resume_noirq(struct device
*dev
)
803 struct platform_device
*pdev
= to_platform_device(dev
);
804 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
805 void __iomem
*mask_reg
= bank
->base
+
806 OMAP_MPUIO_GPIO_MASKIT
/ bank
->stride
;
809 spin_lock_irqsave(&bank
->lock
, flags
);
810 __raw_writel(bank
->context
.wake_en
, mask_reg
);
811 spin_unlock_irqrestore(&bank
->lock
, flags
);
816 static const struct dev_pm_ops omap_mpuio_dev_pm_ops
= {
817 .suspend_noirq
= omap_mpuio_suspend_noirq
,
818 .resume_noirq
= omap_mpuio_resume_noirq
,
821 /* use platform_driver for this. */
822 static struct platform_driver omap_mpuio_driver
= {
825 .pm
= &omap_mpuio_dev_pm_ops
,
829 static struct platform_device omap_mpuio_device
= {
833 .driver
= &omap_mpuio_driver
.driver
,
835 /* could list the /proc/iomem resources */
838 static inline void mpuio_init(struct gpio_bank
*bank
)
840 platform_set_drvdata(&omap_mpuio_device
, bank
);
842 if (platform_driver_register(&omap_mpuio_driver
) == 0)
843 (void) platform_device_register(&omap_mpuio_device
);
846 /*---------------------------------------------------------------------*/
848 static int gpio_input(struct gpio_chip
*chip
, unsigned offset
)
850 struct gpio_bank
*bank
;
853 bank
= container_of(chip
, struct gpio_bank
, chip
);
854 spin_lock_irqsave(&bank
->lock
, flags
);
855 _set_gpio_direction(bank
, offset
, 1);
856 spin_unlock_irqrestore(&bank
->lock
, flags
);
860 static int gpio_is_input(struct gpio_bank
*bank
, int mask
)
862 void __iomem
*reg
= bank
->base
+ bank
->regs
->direction
;
864 return __raw_readl(reg
) & mask
;
867 static int gpio_get(struct gpio_chip
*chip
, unsigned offset
)
869 struct gpio_bank
*bank
;
872 bank
= container_of(chip
, struct gpio_bank
, chip
);
873 mask
= (1 << offset
);
875 if (gpio_is_input(bank
, mask
))
876 return _get_gpio_datain(bank
, offset
);
878 return _get_gpio_dataout(bank
, offset
);
881 static int gpio_output(struct gpio_chip
*chip
, unsigned offset
, int value
)
883 struct gpio_bank
*bank
;
886 bank
= container_of(chip
, struct gpio_bank
, chip
);
887 spin_lock_irqsave(&bank
->lock
, flags
);
888 bank
->set_dataout(bank
, offset
, value
);
889 _set_gpio_direction(bank
, offset
, 0);
890 spin_unlock_irqrestore(&bank
->lock
, flags
);
894 static int gpio_debounce(struct gpio_chip
*chip
, unsigned offset
,
897 struct gpio_bank
*bank
;
900 bank
= container_of(chip
, struct gpio_bank
, chip
);
903 bank
->dbck
= clk_get(bank
->dev
, "dbclk");
904 if (IS_ERR(bank
->dbck
))
905 dev_err(bank
->dev
, "Could not get gpio dbck\n");
908 spin_lock_irqsave(&bank
->lock
, flags
);
909 _set_gpio_debounce(bank
, offset
, debounce
);
910 spin_unlock_irqrestore(&bank
->lock
, flags
);
915 static void gpio_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
917 struct gpio_bank
*bank
;
920 bank
= container_of(chip
, struct gpio_bank
, chip
);
921 spin_lock_irqsave(&bank
->lock
, flags
);
922 bank
->set_dataout(bank
, offset
, value
);
923 spin_unlock_irqrestore(&bank
->lock
, flags
);
926 static int gpio_2irq(struct gpio_chip
*chip
, unsigned offset
)
928 struct gpio_bank
*bank
;
930 bank
= container_of(chip
, struct gpio_bank
, chip
);
931 return bank
->irq_base
+ offset
;
934 /*---------------------------------------------------------------------*/
936 static void __init
omap_gpio_show_rev(struct gpio_bank
*bank
)
941 if (called
|| bank
->regs
->revision
== USHRT_MAX
)
944 rev
= __raw_readw(bank
->base
+ bank
->regs
->revision
);
945 pr_info("OMAP GPIO hardware version %d.%d\n",
946 (rev
>> 4) & 0x0f, rev
& 0x0f);
951 /* This lock class tells lockdep that GPIO irqs are in a different
952 * category than their parents, so it won't report false recursion.
954 static struct lock_class_key gpio_lock_class
;
956 static void omap_gpio_mod_init(struct gpio_bank
*bank
)
958 void __iomem
*base
= bank
->base
;
961 if (bank
->width
== 16)
964 if (bank
->is_mpuio
) {
965 __raw_writel(l
, bank
->base
+ bank
->regs
->irqenable
);
969 _gpio_rmw(base
, bank
->regs
->irqenable
, l
, bank
->regs
->irqenable_inv
);
970 _gpio_rmw(base
, bank
->regs
->irqstatus
, l
, !bank
->regs
->irqenable_inv
);
971 if (bank
->regs
->debounce_en
)
972 __raw_writel(0, base
+ bank
->regs
->debounce_en
);
974 /* Save OE default value (0xffffffff) in the context */
975 bank
->context
.oe
= __raw_readl(bank
->base
+ bank
->regs
->direction
);
976 /* Initialize interface clk ungated, module enabled */
977 if (bank
->regs
->ctrl
)
978 __raw_writel(0, base
+ bank
->regs
->ctrl
);
981 static __devinit
void
982 omap_mpuio_alloc_gc(struct gpio_bank
*bank
, unsigned int irq_start
,
985 struct irq_chip_generic
*gc
;
986 struct irq_chip_type
*ct
;
988 gc
= irq_alloc_generic_chip("MPUIO", 1, irq_start
, bank
->base
,
991 dev_err(bank
->dev
, "Memory alloc failed for gc\n");
997 /* NOTE: No ack required, reading IRQ status clears it. */
998 ct
->chip
.irq_mask
= irq_gc_mask_set_bit
;
999 ct
->chip
.irq_unmask
= irq_gc_mask_clr_bit
;
1000 ct
->chip
.irq_set_type
= gpio_irq_type
;
1002 if (bank
->regs
->wkup_en
)
1003 ct
->chip
.irq_set_wake
= gpio_wake_enable
,
1005 ct
->regs
.mask
= OMAP_MPUIO_GPIO_INT
/ bank
->stride
;
1006 irq_setup_generic_chip(gc
, IRQ_MSK(num
), IRQ_GC_INIT_MASK_CACHE
,
1007 IRQ_NOREQUEST
| IRQ_NOPROBE
, 0);
1010 static void __devinit
omap_gpio_chip_init(struct gpio_bank
*bank
)
1016 * REVISIT eventually switch from OMAP-specific gpio structs
1017 * over to the generic ones
1019 bank
->chip
.request
= omap_gpio_request
;
1020 bank
->chip
.free
= omap_gpio_free
;
1021 bank
->chip
.direction_input
= gpio_input
;
1022 bank
->chip
.get
= gpio_get
;
1023 bank
->chip
.direction_output
= gpio_output
;
1024 bank
->chip
.set_debounce
= gpio_debounce
;
1025 bank
->chip
.set
= gpio_set
;
1026 bank
->chip
.to_irq
= gpio_2irq
;
1027 if (bank
->is_mpuio
) {
1028 bank
->chip
.label
= "mpuio";
1029 if (bank
->regs
->wkup_en
)
1030 bank
->chip
.dev
= &omap_mpuio_device
.dev
;
1031 bank
->chip
.base
= OMAP_MPUIO(0);
1033 bank
->chip
.label
= "gpio";
1034 bank
->chip
.base
= gpio
;
1035 gpio
+= bank
->width
;
1037 bank
->chip
.ngpio
= bank
->width
;
1039 gpiochip_add(&bank
->chip
);
1041 for (j
= bank
->irq_base
; j
< bank
->irq_base
+ bank
->width
; j
++) {
1042 irq_set_lockdep_class(j
, &gpio_lock_class
);
1043 irq_set_chip_data(j
, bank
);
1044 if (bank
->is_mpuio
) {
1045 omap_mpuio_alloc_gc(bank
, j
, bank
->width
);
1047 irq_set_chip(j
, &gpio_irq_chip
);
1048 irq_set_handler(j
, handle_simple_irq
);
1049 set_irq_flags(j
, IRQF_VALID
);
1052 irq_set_chained_handler(bank
->irq
, gpio_irq_handler
);
1053 irq_set_handler_data(bank
->irq
, bank
);
1056 static const struct of_device_id omap_gpio_match
[];
1058 static int __devinit
omap_gpio_probe(struct platform_device
*pdev
)
1060 struct device
*dev
= &pdev
->dev
;
1061 struct device_node
*node
= dev
->of_node
;
1062 const struct of_device_id
*match
;
1063 struct omap_gpio_platform_data
*pdata
;
1064 struct resource
*res
;
1065 struct gpio_bank
*bank
;
1068 match
= of_match_device(of_match_ptr(omap_gpio_match
), dev
);
1070 pdata
= match
? match
->data
: dev
->platform_data
;
1074 bank
= devm_kzalloc(&pdev
->dev
, sizeof(struct gpio_bank
), GFP_KERNEL
);
1076 dev_err(dev
, "Memory alloc failed\n");
1080 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
1081 if (unlikely(!res
)) {
1082 dev_err(dev
, "Invalid IRQ resource\n");
1086 bank
->irq
= res
->start
;
1088 bank
->dbck_flag
= pdata
->dbck_flag
;
1089 bank
->stride
= pdata
->bank_stride
;
1090 bank
->width
= pdata
->bank_width
;
1091 bank
->is_mpuio
= pdata
->is_mpuio
;
1092 bank
->non_wakeup_gpios
= pdata
->non_wakeup_gpios
;
1093 bank
->loses_context
= pdata
->loses_context
;
1094 bank
->regs
= pdata
->regs
;
1095 #ifdef CONFIG_OF_GPIO
1096 bank
->chip
.of_node
= of_node_get(node
);
1099 bank
->irq_base
= irq_alloc_descs(-1, 0, bank
->width
, 0);
1100 if (bank
->irq_base
< 0) {
1101 dev_err(dev
, "Couldn't allocate IRQ numbers\n");
1105 bank
->domain
= irq_domain_add_legacy(node
, bank
->width
, bank
->irq_base
,
1106 0, &irq_domain_simple_ops
, NULL
);
1108 if (bank
->regs
->set_dataout
&& bank
->regs
->clr_dataout
)
1109 bank
->set_dataout
= _set_gpio_dataout_reg
;
1111 bank
->set_dataout
= _set_gpio_dataout_mask
;
1113 spin_lock_init(&bank
->lock
);
1115 /* Static mapping, never released */
1116 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1117 if (unlikely(!res
)) {
1118 dev_err(dev
, "Invalid mem resource\n");
1122 if (!devm_request_mem_region(dev
, res
->start
, resource_size(res
),
1124 dev_err(dev
, "Region already claimed\n");
1128 bank
->base
= devm_ioremap(dev
, res
->start
, resource_size(res
));
1130 dev_err(dev
, "Could not ioremap\n");
1134 platform_set_drvdata(pdev
, bank
);
1136 pm_runtime_enable(bank
->dev
);
1137 pm_runtime_irq_safe(bank
->dev
);
1138 pm_runtime_get_sync(bank
->dev
);
1143 omap_gpio_mod_init(bank
);
1144 omap_gpio_chip_init(bank
);
1145 omap_gpio_show_rev(bank
);
1147 if (bank
->loses_context
)
1148 bank
->get_context_loss_count
= pdata
->get_context_loss_count
;
1150 pm_runtime_put(bank
->dev
);
1152 list_add_tail(&bank
->node
, &omap_gpio_list
);
1157 #ifdef CONFIG_ARCH_OMAP2PLUS
1159 #if defined(CONFIG_PM_RUNTIME)
1160 static void omap_gpio_restore_context(struct gpio_bank
*bank
);
1162 static int omap_gpio_runtime_suspend(struct device
*dev
)
1164 struct platform_device
*pdev
= to_platform_device(dev
);
1165 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1167 unsigned long flags
;
1168 u32 wake_low
, wake_hi
;
1170 spin_lock_irqsave(&bank
->lock
, flags
);
1173 * Only edges can generate a wakeup event to the PRCM.
1175 * Therefore, ensure any wake-up capable GPIOs have
1176 * edge-detection enabled before going idle to ensure a wakeup
1177 * to the PRCM is generated on a GPIO transition. (c.f. 34xx
1180 * The normal values will be restored upon ->runtime_resume()
1181 * by writing back the values saved in bank->context.
1183 wake_low
= bank
->context
.leveldetect0
& bank
->context
.wake_en
;
1185 __raw_writel(wake_low
| bank
->context
.fallingdetect
,
1186 bank
->base
+ bank
->regs
->fallingdetect
);
1187 wake_hi
= bank
->context
.leveldetect1
& bank
->context
.wake_en
;
1189 __raw_writel(wake_hi
| bank
->context
.risingdetect
,
1190 bank
->base
+ bank
->regs
->risingdetect
);
1192 if (!bank
->enabled_non_wakeup_gpios
)
1193 goto update_gpio_context_count
;
1195 if (bank
->power_mode
!= OFF_MODE
) {
1196 bank
->power_mode
= 0;
1197 goto update_gpio_context_count
;
1200 * If going to OFF, remove triggering for all
1201 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1202 * generated. See OMAP2420 Errata item 1.101.
1204 bank
->saved_datain
= __raw_readl(bank
->base
+
1205 bank
->regs
->datain
);
1206 l1
= bank
->context
.fallingdetect
;
1207 l2
= bank
->context
.risingdetect
;
1209 l1
&= ~bank
->enabled_non_wakeup_gpios
;
1210 l2
&= ~bank
->enabled_non_wakeup_gpios
;
1212 __raw_writel(l1
, bank
->base
+ bank
->regs
->fallingdetect
);
1213 __raw_writel(l2
, bank
->base
+ bank
->regs
->risingdetect
);
1215 bank
->workaround_enabled
= true;
1217 update_gpio_context_count
:
1218 if (bank
->get_context_loss_count
)
1219 bank
->context_loss_count
=
1220 bank
->get_context_loss_count(bank
->dev
);
1222 _gpio_dbck_disable(bank
);
1223 spin_unlock_irqrestore(&bank
->lock
, flags
);
1228 static int omap_gpio_runtime_resume(struct device
*dev
)
1230 struct platform_device
*pdev
= to_platform_device(dev
);
1231 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1232 int context_lost_cnt_after
;
1233 u32 l
= 0, gen
, gen0
, gen1
;
1234 unsigned long flags
;
1236 spin_lock_irqsave(&bank
->lock
, flags
);
1237 _gpio_dbck_enable(bank
);
1240 * In ->runtime_suspend(), level-triggered, wakeup-enabled
1241 * GPIOs were set to edge trigger also in order to be able to
1242 * generate a PRCM wakeup. Here we restore the
1243 * pre-runtime_suspend() values for edge triggering.
1245 __raw_writel(bank
->context
.fallingdetect
,
1246 bank
->base
+ bank
->regs
->fallingdetect
);
1247 __raw_writel(bank
->context
.risingdetect
,
1248 bank
->base
+ bank
->regs
->risingdetect
);
1250 if (bank
->get_context_loss_count
) {
1251 context_lost_cnt_after
=
1252 bank
->get_context_loss_count(bank
->dev
);
1253 if (context_lost_cnt_after
!= bank
->context_loss_count
) {
1254 omap_gpio_restore_context(bank
);
1256 spin_unlock_irqrestore(&bank
->lock
, flags
);
1261 if (!bank
->workaround_enabled
) {
1262 spin_unlock_irqrestore(&bank
->lock
, flags
);
1266 __raw_writel(bank
->context
.fallingdetect
,
1267 bank
->base
+ bank
->regs
->fallingdetect
);
1268 __raw_writel(bank
->context
.risingdetect
,
1269 bank
->base
+ bank
->regs
->risingdetect
);
1270 l
= __raw_readl(bank
->base
+ bank
->regs
->datain
);
1273 * Check if any of the non-wakeup interrupt GPIOs have changed
1274 * state. If so, generate an IRQ by software. This is
1275 * horribly racy, but it's the best we can do to work around
1278 l
^= bank
->saved_datain
;
1279 l
&= bank
->enabled_non_wakeup_gpios
;
1282 * No need to generate IRQs for the rising edge for gpio IRQs
1283 * configured with falling edge only; and vice versa.
1285 gen0
= l
& bank
->context
.fallingdetect
;
1286 gen0
&= bank
->saved_datain
;
1288 gen1
= l
& bank
->context
.risingdetect
;
1289 gen1
&= ~(bank
->saved_datain
);
1291 /* FIXME: Consider GPIO IRQs with level detections properly! */
1292 gen
= l
& (~(bank
->context
.fallingdetect
) &
1293 ~(bank
->context
.risingdetect
));
1294 /* Consider all GPIO IRQs needed to be updated */
1300 old0
= __raw_readl(bank
->base
+ bank
->regs
->leveldetect0
);
1301 old1
= __raw_readl(bank
->base
+ bank
->regs
->leveldetect1
);
1303 if (!bank
->regs
->irqstatus_raw0
) {
1304 __raw_writel(old0
| gen
, bank
->base
+
1305 bank
->regs
->leveldetect0
);
1306 __raw_writel(old1
| gen
, bank
->base
+
1307 bank
->regs
->leveldetect1
);
1310 if (bank
->regs
->irqstatus_raw0
) {
1311 __raw_writel(old0
| l
, bank
->base
+
1312 bank
->regs
->leveldetect0
);
1313 __raw_writel(old1
| l
, bank
->base
+
1314 bank
->regs
->leveldetect1
);
1316 __raw_writel(old0
, bank
->base
+ bank
->regs
->leveldetect0
);
1317 __raw_writel(old1
, bank
->base
+ bank
->regs
->leveldetect1
);
1320 bank
->workaround_enabled
= false;
1321 spin_unlock_irqrestore(&bank
->lock
, flags
);
1325 #endif /* CONFIG_PM_RUNTIME */
1327 void omap2_gpio_prepare_for_idle(int pwr_mode
)
1329 struct gpio_bank
*bank
;
1331 list_for_each_entry(bank
, &omap_gpio_list
, node
) {
1332 if (!bank
->mod_usage
|| !bank
->loses_context
)
1335 bank
->power_mode
= pwr_mode
;
1337 pm_runtime_put_sync_suspend(bank
->dev
);
1341 void omap2_gpio_resume_after_idle(void)
1343 struct gpio_bank
*bank
;
1345 list_for_each_entry(bank
, &omap_gpio_list
, node
) {
1346 if (!bank
->mod_usage
|| !bank
->loses_context
)
1349 pm_runtime_get_sync(bank
->dev
);
1353 #if defined(CONFIG_PM_RUNTIME)
1354 static void omap_gpio_restore_context(struct gpio_bank
*bank
)
1356 __raw_writel(bank
->context
.wake_en
,
1357 bank
->base
+ bank
->regs
->wkup_en
);
1358 __raw_writel(bank
->context
.ctrl
, bank
->base
+ bank
->regs
->ctrl
);
1359 __raw_writel(bank
->context
.leveldetect0
,
1360 bank
->base
+ bank
->regs
->leveldetect0
);
1361 __raw_writel(bank
->context
.leveldetect1
,
1362 bank
->base
+ bank
->regs
->leveldetect1
);
1363 __raw_writel(bank
->context
.risingdetect
,
1364 bank
->base
+ bank
->regs
->risingdetect
);
1365 __raw_writel(bank
->context
.fallingdetect
,
1366 bank
->base
+ bank
->regs
->fallingdetect
);
1367 if (bank
->regs
->set_dataout
&& bank
->regs
->clr_dataout
)
1368 __raw_writel(bank
->context
.dataout
,
1369 bank
->base
+ bank
->regs
->set_dataout
);
1371 __raw_writel(bank
->context
.dataout
,
1372 bank
->base
+ bank
->regs
->dataout
);
1373 __raw_writel(bank
->context
.oe
, bank
->base
+ bank
->regs
->direction
);
1375 if (bank
->dbck_enable_mask
) {
1376 __raw_writel(bank
->context
.debounce
, bank
->base
+
1377 bank
->regs
->debounce
);
1378 __raw_writel(bank
->context
.debounce_en
,
1379 bank
->base
+ bank
->regs
->debounce_en
);
1382 __raw_writel(bank
->context
.irqenable1
,
1383 bank
->base
+ bank
->regs
->irqenable
);
1384 __raw_writel(bank
->context
.irqenable2
,
1385 bank
->base
+ bank
->regs
->irqenable2
);
1387 #endif /* CONFIG_PM_RUNTIME */
1389 #define omap_gpio_runtime_suspend NULL
1390 #define omap_gpio_runtime_resume NULL
1393 static const struct dev_pm_ops gpio_pm_ops
= {
1394 SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend
, omap_gpio_runtime_resume
,
1398 #if defined(CONFIG_OF)
1399 static struct omap_gpio_reg_offs omap2_gpio_regs
= {
1400 .revision
= OMAP24XX_GPIO_REVISION
,
1401 .direction
= OMAP24XX_GPIO_OE
,
1402 .datain
= OMAP24XX_GPIO_DATAIN
,
1403 .dataout
= OMAP24XX_GPIO_DATAOUT
,
1404 .set_dataout
= OMAP24XX_GPIO_SETDATAOUT
,
1405 .clr_dataout
= OMAP24XX_GPIO_CLEARDATAOUT
,
1406 .irqstatus
= OMAP24XX_GPIO_IRQSTATUS1
,
1407 .irqstatus2
= OMAP24XX_GPIO_IRQSTATUS2
,
1408 .irqenable
= OMAP24XX_GPIO_IRQENABLE1
,
1409 .irqenable2
= OMAP24XX_GPIO_IRQENABLE2
,
1410 .set_irqenable
= OMAP24XX_GPIO_SETIRQENABLE1
,
1411 .clr_irqenable
= OMAP24XX_GPIO_CLEARIRQENABLE1
,
1412 .debounce
= OMAP24XX_GPIO_DEBOUNCE_VAL
,
1413 .debounce_en
= OMAP24XX_GPIO_DEBOUNCE_EN
,
1414 .ctrl
= OMAP24XX_GPIO_CTRL
,
1415 .wkup_en
= OMAP24XX_GPIO_WAKE_EN
,
1416 .leveldetect0
= OMAP24XX_GPIO_LEVELDETECT0
,
1417 .leveldetect1
= OMAP24XX_GPIO_LEVELDETECT1
,
1418 .risingdetect
= OMAP24XX_GPIO_RISINGDETECT
,
1419 .fallingdetect
= OMAP24XX_GPIO_FALLINGDETECT
,
1422 static struct omap_gpio_reg_offs omap4_gpio_regs
= {
1423 .revision
= OMAP4_GPIO_REVISION
,
1424 .direction
= OMAP4_GPIO_OE
,
1425 .datain
= OMAP4_GPIO_DATAIN
,
1426 .dataout
= OMAP4_GPIO_DATAOUT
,
1427 .set_dataout
= OMAP4_GPIO_SETDATAOUT
,
1428 .clr_dataout
= OMAP4_GPIO_CLEARDATAOUT
,
1429 .irqstatus
= OMAP4_GPIO_IRQSTATUS0
,
1430 .irqstatus2
= OMAP4_GPIO_IRQSTATUS1
,
1431 .irqenable
= OMAP4_GPIO_IRQSTATUSSET0
,
1432 .irqenable2
= OMAP4_GPIO_IRQSTATUSSET1
,
1433 .set_irqenable
= OMAP4_GPIO_IRQSTATUSSET0
,
1434 .clr_irqenable
= OMAP4_GPIO_IRQSTATUSCLR0
,
1435 .debounce
= OMAP4_GPIO_DEBOUNCINGTIME
,
1436 .debounce_en
= OMAP4_GPIO_DEBOUNCENABLE
,
1437 .ctrl
= OMAP4_GPIO_CTRL
,
1438 .wkup_en
= OMAP4_GPIO_IRQWAKEN0
,
1439 .leveldetect0
= OMAP4_GPIO_LEVELDETECT0
,
1440 .leveldetect1
= OMAP4_GPIO_LEVELDETECT1
,
1441 .risingdetect
= OMAP4_GPIO_RISINGDETECT
,
1442 .fallingdetect
= OMAP4_GPIO_FALLINGDETECT
,
1445 static struct omap_gpio_platform_data omap2_pdata
= {
1446 .regs
= &omap2_gpio_regs
,
1451 static struct omap_gpio_platform_data omap3_pdata
= {
1452 .regs
= &omap2_gpio_regs
,
1457 static struct omap_gpio_platform_data omap4_pdata
= {
1458 .regs
= &omap4_gpio_regs
,
1463 static const struct of_device_id omap_gpio_match
[] = {
1465 .compatible
= "ti,omap4-gpio",
1466 .data
= &omap4_pdata
,
1469 .compatible
= "ti,omap3-gpio",
1470 .data
= &omap3_pdata
,
1473 .compatible
= "ti,omap2-gpio",
1474 .data
= &omap2_pdata
,
1478 MODULE_DEVICE_TABLE(of
, omap_gpio_match
);
1481 static struct platform_driver omap_gpio_driver
= {
1482 .probe
= omap_gpio_probe
,
1484 .name
= "omap_gpio",
1486 .of_match_table
= of_match_ptr(omap_gpio_match
),
1491 * gpio driver register needs to be done before
1492 * machine_init functions access gpio APIs.
1493 * Hence omap_gpio_drv_reg() is a postcore_initcall.
1495 static int __init
omap_gpio_drv_reg(void)
1497 return platform_driver_register(&omap_gpio_driver
);
1499 postcore_initcall(omap_gpio_drv_reg
);