2 * linux/arch/arm/plat-omap/gpio.c
4 * Support functions for OMAP GPIO
6 * Copyright (C) 2003-2005 Nokia Corporation
7 * Written by Juha Yrjölä <juha.yrjola@nokia.com>
9 * Copyright (C) 2009 Texas Instruments
10 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/interrupt.h>
20 #include <linux/sysdev.h>
21 #include <linux/err.h>
22 #include <linux/clk.h>
25 #include <mach/hardware.h>
26 #include <plat/control.h>
28 #include <mach/irqs.h>
29 #include <mach/gpio.h>
30 #include <asm/mach/irq.h>
31 #include <plat/powerdomain.h>
35 * OMAP1510 GPIO registers
37 #define OMAP1510_GPIO_BASE 0xfffce000
38 #define OMAP1510_GPIO_DATA_INPUT 0x00
39 #define OMAP1510_GPIO_DATA_OUTPUT 0x04
40 #define OMAP1510_GPIO_DIR_CONTROL 0x08
41 #define OMAP1510_GPIO_INT_CONTROL 0x0c
42 #define OMAP1510_GPIO_INT_MASK 0x10
43 #define OMAP1510_GPIO_INT_STATUS 0x14
44 #define OMAP1510_GPIO_PIN_CONTROL 0x18
46 #define OMAP1510_IH_GPIO_BASE 64
49 * OMAP1610 specific GPIO registers
51 #define OMAP1610_GPIO1_BASE 0xfffbe400
52 #define OMAP1610_GPIO2_BASE 0xfffbec00
53 #define OMAP1610_GPIO3_BASE 0xfffbb400
54 #define OMAP1610_GPIO4_BASE 0xfffbbc00
55 #define OMAP1610_GPIO_REVISION 0x0000
56 #define OMAP1610_GPIO_SYSCONFIG 0x0010
57 #define OMAP1610_GPIO_SYSSTATUS 0x0014
58 #define OMAP1610_GPIO_IRQSTATUS1 0x0018
59 #define OMAP1610_GPIO_IRQENABLE1 0x001c
60 #define OMAP1610_GPIO_WAKEUPENABLE 0x0028
61 #define OMAP1610_GPIO_DATAIN 0x002c
62 #define OMAP1610_GPIO_DATAOUT 0x0030
63 #define OMAP1610_GPIO_DIRECTION 0x0034
64 #define OMAP1610_GPIO_EDGE_CTRL1 0x0038
65 #define OMAP1610_GPIO_EDGE_CTRL2 0x003c
66 #define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
67 #define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
68 #define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
69 #define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
70 #define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
71 #define OMAP1610_GPIO_SET_DATAOUT 0x00f0
74 * OMAP7XX specific GPIO registers
76 #define OMAP7XX_GPIO1_BASE 0xfffbc000
77 #define OMAP7XX_GPIO2_BASE 0xfffbc800
78 #define OMAP7XX_GPIO3_BASE 0xfffbd000
79 #define OMAP7XX_GPIO4_BASE 0xfffbd800
80 #define OMAP7XX_GPIO5_BASE 0xfffbe000
81 #define OMAP7XX_GPIO6_BASE 0xfffbe800
82 #define OMAP7XX_GPIO_DATA_INPUT 0x00
83 #define OMAP7XX_GPIO_DATA_OUTPUT 0x04
84 #define OMAP7XX_GPIO_DIR_CONTROL 0x08
85 #define OMAP7XX_GPIO_INT_CONTROL 0x0c
86 #define OMAP7XX_GPIO_INT_MASK 0x10
87 #define OMAP7XX_GPIO_INT_STATUS 0x14
89 #define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
92 * omap24xx specific GPIO registers
94 #define OMAP242X_GPIO1_BASE 0x48018000
95 #define OMAP242X_GPIO2_BASE 0x4801a000
96 #define OMAP242X_GPIO3_BASE 0x4801c000
97 #define OMAP242X_GPIO4_BASE 0x4801e000
99 #define OMAP243X_GPIO1_BASE 0x4900C000
100 #define OMAP243X_GPIO2_BASE 0x4900E000
101 #define OMAP243X_GPIO3_BASE 0x49010000
102 #define OMAP243X_GPIO4_BASE 0x49012000
103 #define OMAP243X_GPIO5_BASE 0x480B6000
105 #define OMAP24XX_GPIO_REVISION 0x0000
106 #define OMAP24XX_GPIO_SYSCONFIG 0x0010
107 #define OMAP24XX_GPIO_SYSSTATUS 0x0014
108 #define OMAP24XX_GPIO_IRQSTATUS1 0x0018
109 #define OMAP24XX_GPIO_IRQSTATUS2 0x0028
110 #define OMAP24XX_GPIO_IRQENABLE2 0x002c
111 #define OMAP24XX_GPIO_IRQENABLE1 0x001c
112 #define OMAP24XX_GPIO_WAKE_EN 0x0020
113 #define OMAP24XX_GPIO_CTRL 0x0030
114 #define OMAP24XX_GPIO_OE 0x0034
115 #define OMAP24XX_GPIO_DATAIN 0x0038
116 #define OMAP24XX_GPIO_DATAOUT 0x003c
117 #define OMAP24XX_GPIO_LEVELDETECT0 0x0040
118 #define OMAP24XX_GPIO_LEVELDETECT1 0x0044
119 #define OMAP24XX_GPIO_RISINGDETECT 0x0048
120 #define OMAP24XX_GPIO_FALLINGDETECT 0x004c
121 #define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
122 #define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
123 #define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
124 #define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
125 #define OMAP24XX_GPIO_CLEARWKUENA 0x0080
126 #define OMAP24XX_GPIO_SETWKUENA 0x0084
127 #define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
128 #define OMAP24XX_GPIO_SETDATAOUT 0x0094
130 #define OMAP4_GPIO_REVISION 0x0000
131 #define OMAP4_GPIO_SYSCONFIG 0x0010
132 #define OMAP4_GPIO_EOI 0x0020
133 #define OMAP4_GPIO_IRQSTATUSRAW0 0x0024
134 #define OMAP4_GPIO_IRQSTATUSRAW1 0x0028
135 #define OMAP4_GPIO_IRQSTATUS0 0x002c
136 #define OMAP4_GPIO_IRQSTATUS1 0x0030
137 #define OMAP4_GPIO_IRQSTATUSSET0 0x0034
138 #define OMAP4_GPIO_IRQSTATUSSET1 0x0038
139 #define OMAP4_GPIO_IRQSTATUSCLR0 0x003c
140 #define OMAP4_GPIO_IRQSTATUSCLR1 0x0040
141 #define OMAP4_GPIO_IRQWAKEN0 0x0044
142 #define OMAP4_GPIO_IRQWAKEN1 0x0048
143 #define OMAP4_GPIO_SYSSTATUS 0x0104
144 #define OMAP4_GPIO_CTRL 0x0130
145 #define OMAP4_GPIO_OE 0x0134
146 #define OMAP4_GPIO_DATAIN 0x0138
147 #define OMAP4_GPIO_DATAOUT 0x013c
148 #define OMAP4_GPIO_LEVELDETECT0 0x0140
149 #define OMAP4_GPIO_LEVELDETECT1 0x0144
150 #define OMAP4_GPIO_RISINGDETECT 0x0148
151 #define OMAP4_GPIO_FALLINGDETECT 0x014c
152 #define OMAP4_GPIO_DEBOUNCENABLE 0x0150
153 #define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
154 #define OMAP4_GPIO_CLEARDATAOUT 0x0190
155 #define OMAP4_GPIO_SETDATAOUT 0x0194
157 * omap34xx specific GPIO registers
160 #define OMAP34XX_GPIO1_BASE 0x48310000
161 #define OMAP34XX_GPIO2_BASE 0x49050000
162 #define OMAP34XX_GPIO3_BASE 0x49052000
163 #define OMAP34XX_GPIO4_BASE 0x49054000
164 #define OMAP34XX_GPIO5_BASE 0x49056000
165 #define OMAP34XX_GPIO6_BASE 0x49058000
168 * OMAP44XX specific GPIO registers
170 #define OMAP44XX_GPIO1_BASE 0x4a310000
171 #define OMAP44XX_GPIO2_BASE 0x48055000
172 #define OMAP44XX_GPIO3_BASE 0x48057000
173 #define OMAP44XX_GPIO4_BASE 0x48059000
174 #define OMAP44XX_GPIO5_BASE 0x4805B000
175 #define OMAP44XX_GPIO6_BASE 0x4805D000
181 u16 virtual_irq_start
;
183 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
184 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
188 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
189 defined(CONFIG_ARCH_OMAP4)
190 u32 non_wakeup_gpios
;
191 u32 enabled_non_wakeup_gpios
;
194 u32 saved_fallingdetect
;
195 u32 saved_risingdetect
;
199 struct gpio_chip chip
;
201 u32 dbck_enable_mask
;
204 #define METHOD_MPUIO 0
205 #define METHOD_GPIO_1510 1
206 #define METHOD_GPIO_1610 2
207 #define METHOD_GPIO_7XX 3
208 #define METHOD_GPIO_24XX 5
210 #ifdef CONFIG_ARCH_OMAP16XX
211 static struct gpio_bank gpio_bank_1610
[5] = {
212 { OMAP1_MPUIO_VBASE
, NULL
, INT_MPUIO
, IH_MPUIO_BASE
,
214 { OMAP1610_GPIO1_BASE
, NULL
, INT_GPIO_BANK1
, IH_GPIO_BASE
,
216 { OMAP1610_GPIO2_BASE
, NULL
, INT_1610_GPIO_BANK2
, IH_GPIO_BASE
+ 16,
218 { OMAP1610_GPIO3_BASE
, NULL
, INT_1610_GPIO_BANK3
, IH_GPIO_BASE
+ 32,
220 { OMAP1610_GPIO4_BASE
, NULL
, INT_1610_GPIO_BANK4
, IH_GPIO_BASE
+ 48,
225 #ifdef CONFIG_ARCH_OMAP15XX
226 static struct gpio_bank gpio_bank_1510
[2] = {
227 { OMAP1_MPUIO_VBASE
, NULL
, INT_MPUIO
, IH_MPUIO_BASE
,
229 { OMAP1510_GPIO_BASE
, NULL
, INT_GPIO_BANK1
, IH_GPIO_BASE
,
234 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
235 static struct gpio_bank gpio_bank_7xx
[7] = {
236 { OMAP1_MPUIO_VBASE
, NULL
, INT_7XX_MPUIO
, IH_MPUIO_BASE
,
238 { OMAP7XX_GPIO1_BASE
, NULL
, INT_7XX_GPIO_BANK1
, IH_GPIO_BASE
,
240 { OMAP7XX_GPIO2_BASE
, NULL
, INT_7XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32,
242 { OMAP7XX_GPIO3_BASE
, NULL
, INT_7XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64,
244 { OMAP7XX_GPIO4_BASE
, NULL
, INT_7XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96,
246 { OMAP7XX_GPIO5_BASE
, NULL
, INT_7XX_GPIO_BANK5
, IH_GPIO_BASE
+ 128,
248 { OMAP7XX_GPIO6_BASE
, NULL
, INT_7XX_GPIO_BANK6
, IH_GPIO_BASE
+ 160,
253 #ifdef CONFIG_ARCH_OMAP24XX
255 static struct gpio_bank gpio_bank_242x
[4] = {
256 { OMAP242X_GPIO1_BASE
, NULL
, INT_24XX_GPIO_BANK1
, IH_GPIO_BASE
,
258 { OMAP242X_GPIO2_BASE
, NULL
, INT_24XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32,
260 { OMAP242X_GPIO3_BASE
, NULL
, INT_24XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64,
262 { OMAP242X_GPIO4_BASE
, NULL
, INT_24XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96,
266 static struct gpio_bank gpio_bank_243x
[5] = {
267 { OMAP243X_GPIO1_BASE
, NULL
, INT_24XX_GPIO_BANK1
, IH_GPIO_BASE
,
269 { OMAP243X_GPIO2_BASE
, NULL
, INT_24XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32,
271 { OMAP243X_GPIO3_BASE
, NULL
, INT_24XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64,
273 { OMAP243X_GPIO4_BASE
, NULL
, INT_24XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96,
275 { OMAP243X_GPIO5_BASE
, NULL
, INT_24XX_GPIO_BANK5
, IH_GPIO_BASE
+ 128,
281 #ifdef CONFIG_ARCH_OMAP34XX
282 static struct gpio_bank gpio_bank_34xx
[6] = {
283 { OMAP34XX_GPIO1_BASE
, NULL
, INT_34XX_GPIO_BANK1
, IH_GPIO_BASE
,
285 { OMAP34XX_GPIO2_BASE
, NULL
, INT_34XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32,
287 { OMAP34XX_GPIO3_BASE
, NULL
, INT_34XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64,
289 { OMAP34XX_GPIO4_BASE
, NULL
, INT_34XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96,
291 { OMAP34XX_GPIO5_BASE
, NULL
, INT_34XX_GPIO_BANK5
, IH_GPIO_BASE
+ 128,
293 { OMAP34XX_GPIO6_BASE
, NULL
, INT_34XX_GPIO_BANK6
, IH_GPIO_BASE
+ 160,
297 #define OMAP34XX_PAD_SAFE_MODE 0x7
298 #define OMAP34XX_PAD_IN_PU_GPIO 0x11c
299 #define OMAP34XX_PAD_IN_PD_GPIO 0x10c
301 struct omap3_gpio_regs
{
315 static struct omap3_gpio_regs gpio_context
[OMAP34XX_NR_GPIOS
];
317 /* GPIO -> PAD init configuration struct */
318 struct gpio_pad_range
{
319 /* Range start GPIO # */
321 /* Range end GPIO # */
323 /* Start pad config offset */
328 * Defines GPIO to padconfig mapping. For example first definition tells
329 * us that there is a range of GPIOs 34...43 which have their padconfigs
330 * starting from offset 0x7a, i.e. gpio 34->0x7a, 35->0x7c, 36->0x7e ... etc.
332 static const struct gpio_pad_range gpio_pads_config
[] = {
361 /* GPIO -> PAD config mapping for OMAP3 */
368 #define OMAP34XX_GPIO_AMT (32 * OMAP34XX_NR_GPIOS)
370 static struct gpio_pad
*gpio_pads
;
371 static u16 gpio_pad_map
[OMAP34XX_GPIO_AMT
];
374 #ifdef CONFIG_ARCH_OMAP4
375 static struct gpio_bank gpio_bank_44xx
[6] = {
376 { OMAP44XX_GPIO1_BASE
, NULL
, INT_44XX_GPIO_BANK1
, IH_GPIO_BASE
,
378 { OMAP44XX_GPIO2_BASE
, NULL
, INT_44XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32,
380 { OMAP44XX_GPIO3_BASE
, NULL
, INT_44XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64,
382 { OMAP44XX_GPIO4_BASE
, NULL
, INT_44XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96,
384 { OMAP44XX_GPIO5_BASE
, NULL
, INT_44XX_GPIO_BANK5
, IH_GPIO_BASE
+ 128,
386 { OMAP44XX_GPIO6_BASE
, NULL
, INT_44XX_GPIO_BANK6
, IH_GPIO_BASE
+ 160,
392 static struct gpio_bank
*gpio_bank
;
393 static int gpio_bank_count
;
395 static inline struct gpio_bank
*get_gpio_bank(int gpio
)
397 if (cpu_is_omap15xx()) {
398 if (OMAP_GPIO_IS_MPUIO(gpio
))
399 return &gpio_bank
[0];
400 return &gpio_bank
[1];
402 if (cpu_is_omap16xx()) {
403 if (OMAP_GPIO_IS_MPUIO(gpio
))
404 return &gpio_bank
[0];
405 return &gpio_bank
[1 + (gpio
>> 4)];
407 if (cpu_is_omap7xx()) {
408 if (OMAP_GPIO_IS_MPUIO(gpio
))
409 return &gpio_bank
[0];
410 return &gpio_bank
[1 + (gpio
>> 5)];
412 if (cpu_is_omap24xx())
413 return &gpio_bank
[gpio
>> 5];
414 if (cpu_is_omap34xx() || cpu_is_omap44xx())
415 return &gpio_bank
[gpio
>> 5];
420 static inline int get_gpio_index(int gpio
)
422 if (cpu_is_omap7xx())
424 if (cpu_is_omap24xx())
426 if (cpu_is_omap34xx() || cpu_is_omap44xx())
431 static inline int gpio_valid(int gpio
)
435 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio
)) {
436 if (gpio
>= OMAP_MAX_GPIO_LINES
+ 16)
440 if (cpu_is_omap15xx() && gpio
< 16)
442 if ((cpu_is_omap16xx()) && gpio
< 64)
444 if (cpu_is_omap7xx() && gpio
< 192)
446 if (cpu_is_omap24xx() && gpio
< 128)
448 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio
< 192)
453 static int check_gpio(int gpio
)
455 if (unlikely(gpio_valid(gpio
) < 0)) {
456 printk(KERN_ERR
"omap-gpio: invalid GPIO %d\n", gpio
);
463 static void _set_gpio_direction(struct gpio_bank
*bank
, int gpio
, int is_input
)
465 void __iomem
*reg
= bank
->base
;
468 switch (bank
->method
) {
469 #ifdef CONFIG_ARCH_OMAP1
471 reg
+= OMAP_MPUIO_IO_CNTL
;
474 #ifdef CONFIG_ARCH_OMAP15XX
475 case METHOD_GPIO_1510
:
476 reg
+= OMAP1510_GPIO_DIR_CONTROL
;
479 #ifdef CONFIG_ARCH_OMAP16XX
480 case METHOD_GPIO_1610
:
481 reg
+= OMAP1610_GPIO_DIRECTION
;
484 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
485 case METHOD_GPIO_7XX
:
486 reg
+= OMAP7XX_GPIO_DIR_CONTROL
;
489 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
490 case METHOD_GPIO_24XX
:
491 reg
+= OMAP24XX_GPIO_OE
;
494 #if defined(CONFIG_ARCH_OMAP4)
495 case METHOD_GPIO_24XX
:
496 reg
+= OMAP4_GPIO_OE
;
503 l
= __raw_readl(reg
);
508 __raw_writel(l
, reg
);
511 static void _set_gpio_dataout(struct gpio_bank
*bank
, int gpio
, int enable
)
513 void __iomem
*reg
= bank
->base
;
516 switch (bank
->method
) {
517 #ifdef CONFIG_ARCH_OMAP1
519 reg
+= OMAP_MPUIO_OUTPUT
;
520 l
= __raw_readl(reg
);
527 #ifdef CONFIG_ARCH_OMAP15XX
528 case METHOD_GPIO_1510
:
529 reg
+= OMAP1510_GPIO_DATA_OUTPUT
;
530 l
= __raw_readl(reg
);
537 #ifdef CONFIG_ARCH_OMAP16XX
538 case METHOD_GPIO_1610
:
540 reg
+= OMAP1610_GPIO_SET_DATAOUT
;
542 reg
+= OMAP1610_GPIO_CLEAR_DATAOUT
;
546 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
547 case METHOD_GPIO_7XX
:
548 reg
+= OMAP7XX_GPIO_DATA_OUTPUT
;
549 l
= __raw_readl(reg
);
556 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
557 case METHOD_GPIO_24XX
:
559 reg
+= OMAP24XX_GPIO_SETDATAOUT
;
561 reg
+= OMAP24XX_GPIO_CLEARDATAOUT
;
565 #ifdef CONFIG_ARCH_OMAP4
566 case METHOD_GPIO_24XX
:
568 reg
+= OMAP4_GPIO_SETDATAOUT
;
570 reg
+= OMAP4_GPIO_CLEARDATAOUT
;
578 __raw_writel(l
, reg
);
581 static int _get_gpio_datain(struct gpio_bank
*bank
, int gpio
)
585 if (check_gpio(gpio
) < 0)
588 switch (bank
->method
) {
589 #ifdef CONFIG_ARCH_OMAP1
591 reg
+= OMAP_MPUIO_INPUT_LATCH
;
594 #ifdef CONFIG_ARCH_OMAP15XX
595 case METHOD_GPIO_1510
:
596 reg
+= OMAP1510_GPIO_DATA_INPUT
;
599 #ifdef CONFIG_ARCH_OMAP16XX
600 case METHOD_GPIO_1610
:
601 reg
+= OMAP1610_GPIO_DATAIN
;
604 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
605 case METHOD_GPIO_7XX
:
606 reg
+= OMAP7XX_GPIO_DATA_INPUT
;
609 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
610 case METHOD_GPIO_24XX
:
611 reg
+= OMAP24XX_GPIO_DATAIN
;
614 #ifdef CONFIG_ARCH_OMAP4
615 case METHOD_GPIO_24XX
:
616 reg
+= OMAP4_GPIO_DATAIN
;
622 return (__raw_readl(reg
)
623 & (1 << get_gpio_index(gpio
))) != 0;
626 static int _get_gpio_dataout(struct gpio_bank
*bank
, int gpio
)
630 if (check_gpio(gpio
) < 0)
634 switch (bank
->method
) {
635 #ifdef CONFIG_ARCH_OMAP1
637 reg
+= OMAP_MPUIO_OUTPUT
;
640 #ifdef CONFIG_ARCH_OMAP15XX
641 case METHOD_GPIO_1510
:
642 reg
+= OMAP1510_GPIO_DATA_OUTPUT
;
645 #ifdef CONFIG_ARCH_OMAP16XX
646 case METHOD_GPIO_1610
:
647 reg
+= OMAP1610_GPIO_DATAOUT
;
650 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
651 case METHOD_GPIO_7XX
:
652 reg
+= OMAP7XX_GPIO_DATA_OUTPUT
;
655 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
656 defined(CONFIG_ARCH_OMAP4)
657 case METHOD_GPIO_24XX
:
658 reg
+= OMAP24XX_GPIO_DATAOUT
;
665 return (__raw_readl(reg
) & (1 << get_gpio_index(gpio
))) != 0;
668 #define MOD_REG_BIT(reg, bit_mask, set) \
670 int l = __raw_readl(base + reg); \
671 if (set) l |= bit_mask; \
672 else l &= ~bit_mask; \
673 __raw_writel(l, base + reg); \
676 void omap_set_gpio_debounce(int gpio
, int enable
)
678 struct gpio_bank
*bank
;
681 u32 val
, l
= 1 << get_gpio_index(gpio
);
683 if (cpu_class_is_omap1())
686 bank
= get_gpio_bank(gpio
);
688 #ifdef CONFIG_ARCH_OMAP4
689 reg
+= OMAP4_GPIO_DEBOUNCENABLE
;
691 reg
+= OMAP24XX_GPIO_DEBOUNCE_EN
;
694 spin_lock_irqsave(&bank
->lock
, flags
);
695 val
= __raw_readl(reg
);
697 if (enable
&& !(val
& l
))
699 else if (!enable
&& (val
& l
))
704 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
705 bank
->dbck_enable_mask
= val
;
707 clk_enable(bank
->dbck
);
709 clk_disable(bank
->dbck
);
712 __raw_writel(val
, reg
);
714 spin_unlock_irqrestore(&bank
->lock
, flags
);
716 EXPORT_SYMBOL(omap_set_gpio_debounce
);
718 void omap_set_gpio_debounce_time(int gpio
, int enc_time
)
720 struct gpio_bank
*bank
;
723 if (cpu_class_is_omap1())
726 bank
= get_gpio_bank(gpio
);
730 #ifdef CONFIG_ARCH_OMAP4
731 reg
+= OMAP4_GPIO_DEBOUNCINGTIME
;
733 reg
+= OMAP24XX_GPIO_DEBOUNCE_VAL
;
735 __raw_writel(enc_time
, reg
);
737 EXPORT_SYMBOL(omap_set_gpio_debounce_time
);
739 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
740 defined(CONFIG_ARCH_OMAP4)
741 static inline void set_24xx_gpio_triggering(struct gpio_bank
*bank
, int gpio
,
744 void __iomem
*base
= bank
->base
;
745 u32 gpio_bit
= 1 << gpio
;
748 if (cpu_is_omap44xx()) {
749 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0
, gpio_bit
,
750 trigger
& IRQ_TYPE_LEVEL_LOW
);
751 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1
, gpio_bit
,
752 trigger
& IRQ_TYPE_LEVEL_HIGH
);
753 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT
, gpio_bit
,
754 trigger
& IRQ_TYPE_EDGE_RISING
);
755 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT
, gpio_bit
,
756 trigger
& IRQ_TYPE_EDGE_FALLING
);
758 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0
, gpio_bit
,
759 trigger
& IRQ_TYPE_LEVEL_LOW
);
760 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1
, gpio_bit
,
761 trigger
& IRQ_TYPE_LEVEL_HIGH
);
762 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT
, gpio_bit
,
763 trigger
& IRQ_TYPE_EDGE_RISING
);
764 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT
, gpio_bit
,
765 trigger
& IRQ_TYPE_EDGE_FALLING
);
767 if (likely(!(bank
->non_wakeup_gpios
& gpio_bit
))) {
768 if (cpu_is_omap44xx()) {
770 __raw_writel(1 << gpio
, bank
->base
+
771 OMAP4_GPIO_IRQWAKEN0
);
773 val
= __raw_readl(bank
->base
+
774 OMAP4_GPIO_IRQWAKEN0
);
775 __raw_writel(val
& (~(1 << gpio
)), bank
->base
+
776 OMAP4_GPIO_IRQWAKEN0
);
780 * GPIO wakeup request can only be generated on edge
783 if (trigger
& IRQ_TYPE_EDGE_BOTH
)
784 __raw_writel(1 << gpio
, bank
->base
785 + OMAP24XX_GPIO_SETWKUENA
);
787 __raw_writel(1 << gpio
, bank
->base
788 + OMAP24XX_GPIO_CLEARWKUENA
);
791 /* This part needs to be executed always for OMAP34xx */
792 if (cpu_is_omap34xx() || (bank
->non_wakeup_gpios
& gpio_bit
)) {
794 * Log the edge gpio and manually trigger the IRQ
795 * after resume if the input level changes
796 * to avoid irq lost during PER RET/OFF mode
797 * Applies for omap2 non-wakeup gpio and all omap3 gpios
799 if (trigger
& IRQ_TYPE_EDGE_BOTH
)
800 bank
->enabled_non_wakeup_gpios
|= gpio_bit
;
802 bank
->enabled_non_wakeup_gpios
&= ~gpio_bit
;
805 if (cpu_is_omap44xx()) {
807 __raw_readl(bank
->base
+ OMAP4_GPIO_LEVELDETECT0
) |
808 __raw_readl(bank
->base
+ OMAP4_GPIO_LEVELDETECT1
);
811 __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
) |
812 __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
817 static int _set_gpio_triggering(struct gpio_bank
*bank
, int gpio
, int trigger
)
819 void __iomem
*reg
= bank
->base
;
822 switch (bank
->method
) {
823 #ifdef CONFIG_ARCH_OMAP1
825 reg
+= OMAP_MPUIO_GPIO_INT_EDGE
;
826 l
= __raw_readl(reg
);
827 if (trigger
& IRQ_TYPE_EDGE_RISING
)
829 else if (trigger
& IRQ_TYPE_EDGE_FALLING
)
835 #ifdef CONFIG_ARCH_OMAP15XX
836 case METHOD_GPIO_1510
:
837 reg
+= OMAP1510_GPIO_INT_CONTROL
;
838 l
= __raw_readl(reg
);
839 if (trigger
& IRQ_TYPE_EDGE_RISING
)
841 else if (trigger
& IRQ_TYPE_EDGE_FALLING
)
847 #ifdef CONFIG_ARCH_OMAP16XX
848 case METHOD_GPIO_1610
:
850 reg
+= OMAP1610_GPIO_EDGE_CTRL2
;
852 reg
+= OMAP1610_GPIO_EDGE_CTRL1
;
854 l
= __raw_readl(reg
);
855 l
&= ~(3 << (gpio
<< 1));
856 if (trigger
& IRQ_TYPE_EDGE_RISING
)
857 l
|= 2 << (gpio
<< 1);
858 if (trigger
& IRQ_TYPE_EDGE_FALLING
)
859 l
|= 1 << (gpio
<< 1);
861 /* Enable wake-up during idle for dynamic tick */
862 __raw_writel(1 << gpio
, bank
->base
+ OMAP1610_GPIO_SET_WAKEUPENA
);
864 __raw_writel(1 << gpio
, bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
);
867 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
868 case METHOD_GPIO_7XX
:
869 reg
+= OMAP7XX_GPIO_INT_CONTROL
;
870 l
= __raw_readl(reg
);
871 if (trigger
& IRQ_TYPE_EDGE_RISING
)
873 else if (trigger
& IRQ_TYPE_EDGE_FALLING
)
879 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
880 defined(CONFIG_ARCH_OMAP4)
881 case METHOD_GPIO_24XX
:
882 set_24xx_gpio_triggering(bank
, gpio
, trigger
);
888 __raw_writel(l
, reg
);
894 static int gpio_irq_type(unsigned irq
, unsigned type
)
896 struct gpio_bank
*bank
;
901 if (!cpu_class_is_omap2() && irq
> IH_MPUIO_BASE
)
902 gpio
= OMAP_MPUIO(irq
- IH_MPUIO_BASE
);
904 gpio
= irq
- IH_GPIO_BASE
;
906 if (check_gpio(gpio
) < 0)
909 if (type
& ~IRQ_TYPE_SENSE_MASK
)
912 /* OMAP1 allows only only edge triggering */
913 if (!cpu_class_is_omap2()
914 && (type
& (IRQ_TYPE_LEVEL_LOW
|IRQ_TYPE_LEVEL_HIGH
)))
917 bank
= get_irq_chip_data(irq
);
918 spin_lock_irqsave(&bank
->lock
, flags
);
919 retval
= _set_gpio_triggering(bank
, get_gpio_index(gpio
), type
);
921 irq_desc
[irq
].status
&= ~IRQ_TYPE_SENSE_MASK
;
922 irq_desc
[irq
].status
|= type
;
924 spin_unlock_irqrestore(&bank
->lock
, flags
);
926 if (type
& (IRQ_TYPE_LEVEL_LOW
| IRQ_TYPE_LEVEL_HIGH
))
927 __set_irq_handler_unlocked(irq
, handle_level_irq
);
928 else if (type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_EDGE_RISING
))
929 __set_irq_handler_unlocked(irq
, handle_edge_irq
);
934 static void _clear_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
)
936 void __iomem
*reg
= bank
->base
;
938 switch (bank
->method
) {
939 #ifdef CONFIG_ARCH_OMAP1
941 /* MPUIO irqstatus is reset by reading the status register,
942 * so do nothing here */
945 #ifdef CONFIG_ARCH_OMAP15XX
946 case METHOD_GPIO_1510
:
947 reg
+= OMAP1510_GPIO_INT_STATUS
;
950 #ifdef CONFIG_ARCH_OMAP16XX
951 case METHOD_GPIO_1610
:
952 reg
+= OMAP1610_GPIO_IRQSTATUS1
;
955 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
956 case METHOD_GPIO_7XX
:
957 reg
+= OMAP7XX_GPIO_INT_STATUS
;
960 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
961 case METHOD_GPIO_24XX
:
962 reg
+= OMAP24XX_GPIO_IRQSTATUS1
;
965 #if defined(CONFIG_ARCH_OMAP4)
966 case METHOD_GPIO_24XX
:
967 reg
+= OMAP4_GPIO_IRQSTATUS0
;
974 __raw_writel(gpio_mask
, reg
);
976 /* Workaround for clearing DSP GPIO interrupts to allow retention */
977 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
978 reg
= bank
->base
+ OMAP24XX_GPIO_IRQSTATUS2
;
980 #if defined(CONFIG_ARCH_OMAP4)
981 reg
= bank
->base
+ OMAP4_GPIO_IRQSTATUS1
;
983 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
984 __raw_writel(gpio_mask
, reg
);
986 /* Flush posted write for the irq status to avoid spurious interrupts */
991 static inline void _clear_gpio_irqstatus(struct gpio_bank
*bank
, int gpio
)
993 _clear_gpio_irqbank(bank
, 1 << get_gpio_index(gpio
));
996 static u32
_get_gpio_irqbank_mask(struct gpio_bank
*bank
)
998 void __iomem
*reg
= bank
->base
;
1003 switch (bank
->method
) {
1004 #ifdef CONFIG_ARCH_OMAP1
1006 reg
+= OMAP_MPUIO_GPIO_MASKIT
;
1011 #ifdef CONFIG_ARCH_OMAP15XX
1012 case METHOD_GPIO_1510
:
1013 reg
+= OMAP1510_GPIO_INT_MASK
;
1018 #ifdef CONFIG_ARCH_OMAP16XX
1019 case METHOD_GPIO_1610
:
1020 reg
+= OMAP1610_GPIO_IRQENABLE1
;
1024 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1025 case METHOD_GPIO_7XX
:
1026 reg
+= OMAP7XX_GPIO_INT_MASK
;
1031 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1032 case METHOD_GPIO_24XX
:
1033 reg
+= OMAP24XX_GPIO_IRQENABLE1
;
1037 #if defined(CONFIG_ARCH_OMAP4)
1038 case METHOD_GPIO_24XX
:
1039 reg
+= OMAP4_GPIO_IRQSTATUSSET0
;
1048 l
= __raw_readl(reg
);
1055 static void _enable_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
, int enable
)
1057 void __iomem
*reg
= bank
->base
;
1060 switch (bank
->method
) {
1061 #ifdef CONFIG_ARCH_OMAP1
1063 reg
+= OMAP_MPUIO_GPIO_MASKIT
;
1064 l
= __raw_readl(reg
);
1071 #ifdef CONFIG_ARCH_OMAP15XX
1072 case METHOD_GPIO_1510
:
1073 reg
+= OMAP1510_GPIO_INT_MASK
;
1074 l
= __raw_readl(reg
);
1081 #ifdef CONFIG_ARCH_OMAP16XX
1082 case METHOD_GPIO_1610
:
1084 reg
+= OMAP1610_GPIO_SET_IRQENABLE1
;
1086 reg
+= OMAP1610_GPIO_CLEAR_IRQENABLE1
;
1090 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1091 case METHOD_GPIO_7XX
:
1092 reg
+= OMAP7XX_GPIO_INT_MASK
;
1093 l
= __raw_readl(reg
);
1100 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1101 case METHOD_GPIO_24XX
:
1103 reg
+= OMAP24XX_GPIO_SETIRQENABLE1
;
1105 reg
+= OMAP24XX_GPIO_CLEARIRQENABLE1
;
1109 #ifdef CONFIG_ARCH_OMAP4
1110 case METHOD_GPIO_24XX
:
1112 reg
+= OMAP4_GPIO_IRQSTATUSSET0
;
1114 reg
+= OMAP4_GPIO_IRQSTATUSCLR0
;
1122 __raw_writel(l
, reg
);
1125 static inline void _set_gpio_irqenable(struct gpio_bank
*bank
, int gpio
, int enable
)
1127 _enable_gpio_irqbank(bank
, 1 << get_gpio_index(gpio
), enable
);
1131 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1132 * 1510 does not seem to have a wake-up register. If JTAG is connected
1133 * to the target, system will wake up always on GPIO events. While
1134 * system is running all registered GPIO interrupts need to have wake-up
1135 * enabled. When system is suspended, only selected GPIO interrupts need
1136 * to have wake-up enabled.
1138 static int _set_gpio_wakeup(struct gpio_bank
*bank
, int gpio
, int enable
)
1140 unsigned long flags
;
1142 switch (bank
->method
) {
1143 #ifdef CONFIG_ARCH_OMAP16XX
1145 case METHOD_GPIO_1610
:
1146 spin_lock_irqsave(&bank
->lock
, flags
);
1148 bank
->suspend_wakeup
|= (1 << gpio
);
1150 bank
->suspend_wakeup
&= ~(1 << gpio
);
1151 spin_unlock_irqrestore(&bank
->lock
, flags
);
1154 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1155 defined(CONFIG_ARCH_OMAP4)
1156 case METHOD_GPIO_24XX
:
1157 if (bank
->non_wakeup_gpios
& (1 << gpio
)) {
1158 printk(KERN_ERR
"Unable to modify wakeup on "
1159 "non-wakeup GPIO%d\n",
1160 (bank
- gpio_bank
) * 32 + gpio
);
1163 spin_lock_irqsave(&bank
->lock
, flags
);
1165 bank
->suspend_wakeup
|= (1 << gpio
);
1167 bank
->suspend_wakeup
&= ~(1 << gpio
);
1168 spin_unlock_irqrestore(&bank
->lock
, flags
);
1172 printk(KERN_ERR
"Can't enable GPIO wakeup for method %i\n",
1178 static void _reset_gpio(struct gpio_bank
*bank
, int gpio
)
1180 _set_gpio_direction(bank
, get_gpio_index(gpio
), 1);
1181 _set_gpio_irqenable(bank
, gpio
, 0);
1182 _clear_gpio_irqstatus(bank
, gpio
);
1183 _set_gpio_triggering(bank
, get_gpio_index(gpio
), IRQ_TYPE_NONE
);
1186 /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1187 static int gpio_wake_enable(unsigned int irq
, unsigned int enable
)
1189 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1190 struct gpio_bank
*bank
;
1193 if (check_gpio(gpio
) < 0)
1195 bank
= get_irq_chip_data(irq
);
1196 retval
= _set_gpio_wakeup(bank
, get_gpio_index(gpio
), enable
);
1201 static int omap_gpio_request(struct gpio_chip
*chip
, unsigned offset
)
1203 struct gpio_bank
*bank
= container_of(chip
, struct gpio_bank
, chip
);
1204 unsigned long flags
;
1206 spin_lock_irqsave(&bank
->lock
, flags
);
1208 /* Set trigger to none. You need to enable the desired trigger with
1209 * request_irq() or set_irq_type().
1211 _set_gpio_triggering(bank
, offset
, IRQ_TYPE_NONE
);
1213 #ifdef CONFIG_ARCH_OMAP15XX
1214 if (bank
->method
== METHOD_GPIO_1510
) {
1217 /* Claim the pin for MPU */
1218 reg
= bank
->base
+ OMAP1510_GPIO_PIN_CONTROL
;
1219 __raw_writel(__raw_readl(reg
) | (1 << offset
), reg
);
1222 spin_unlock_irqrestore(&bank
->lock
, flags
);
1227 static void omap_gpio_free(struct gpio_chip
*chip
, unsigned offset
)
1229 struct gpio_bank
*bank
= container_of(chip
, struct gpio_bank
, chip
);
1230 unsigned long flags
;
1232 spin_lock_irqsave(&bank
->lock
, flags
);
1233 #ifdef CONFIG_ARCH_OMAP16XX
1234 if (bank
->method
== METHOD_GPIO_1610
) {
1235 /* Disable wake-up during idle for dynamic tick */
1236 void __iomem
*reg
= bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
;
1237 __raw_writel(1 << offset
, reg
);
1240 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1241 defined(CONFIG_ARCH_OMAP4)
1242 if (bank
->method
== METHOD_GPIO_24XX
) {
1243 /* Disable wake-up during idle for dynamic tick */
1244 void __iomem
*reg
= bank
->base
+ OMAP24XX_GPIO_CLEARWKUENA
;
1245 __raw_writel(1 << offset
, reg
);
1248 _reset_gpio(bank
, bank
->chip
.base
+ offset
);
1249 spin_unlock_irqrestore(&bank
->lock
, flags
);
1253 * We need to unmask the GPIO bank interrupt as soon as possible to
1254 * avoid missing GPIO interrupts for other lines in the bank.
1255 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1256 * in the bank to avoid missing nested interrupts for a GPIO line.
1257 * If we wait to unmask individual GPIO lines in the bank after the
1258 * line's interrupt handler has been run, we may miss some nested
1261 static void gpio_irq_handler(unsigned int irq
, struct irq_desc
*desc
)
1263 void __iomem
*isr_reg
= NULL
;
1265 unsigned int gpio_irq
;
1266 struct gpio_bank
*bank
;
1270 desc
->chip
->ack(irq
);
1272 bank
= get_irq_data(irq
);
1273 #ifdef CONFIG_ARCH_OMAP1
1274 if (bank
->method
== METHOD_MPUIO
)
1275 isr_reg
= bank
->base
+ OMAP_MPUIO_GPIO_INT
;
1277 #ifdef CONFIG_ARCH_OMAP15XX
1278 if (bank
->method
== METHOD_GPIO_1510
)
1279 isr_reg
= bank
->base
+ OMAP1510_GPIO_INT_STATUS
;
1281 #if defined(CONFIG_ARCH_OMAP16XX)
1282 if (bank
->method
== METHOD_GPIO_1610
)
1283 isr_reg
= bank
->base
+ OMAP1610_GPIO_IRQSTATUS1
;
1285 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1286 if (bank
->method
== METHOD_GPIO_7XX
)
1287 isr_reg
= bank
->base
+ OMAP7XX_GPIO_INT_STATUS
;
1289 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1290 if (bank
->method
== METHOD_GPIO_24XX
)
1291 isr_reg
= bank
->base
+ OMAP24XX_GPIO_IRQSTATUS1
;
1293 #if defined(CONFIG_ARCH_OMAP4)
1294 if (bank
->method
== METHOD_GPIO_24XX
)
1295 isr_reg
= bank
->base
+ OMAP4_GPIO_IRQSTATUS0
;
1298 u32 isr_saved
, level_mask
= 0;
1301 enabled
= _get_gpio_irqbank_mask(bank
);
1302 isr_saved
= isr
= __raw_readl(isr_reg
) & enabled
;
1304 if (cpu_is_omap15xx() && (bank
->method
== METHOD_MPUIO
))
1307 if (cpu_class_is_omap2()) {
1308 level_mask
= bank
->level_mask
& enabled
;
1311 /* clear edge sensitive interrupts before handler(s) are
1312 called so that we don't miss any interrupt occurred while
1314 _enable_gpio_irqbank(bank
, isr_saved
& ~level_mask
, 0);
1315 _clear_gpio_irqbank(bank
, isr_saved
& ~level_mask
);
1316 _enable_gpio_irqbank(bank
, isr_saved
& ~level_mask
, 1);
1318 /* if there is only edge sensitive GPIO pin interrupts
1319 configured, we could unmask GPIO bank interrupt immediately */
1320 if (!level_mask
&& !unmasked
) {
1322 desc
->chip
->unmask(irq
);
1330 gpio_irq
= bank
->virtual_irq_start
;
1331 for (; isr
!= 0; isr
>>= 1, gpio_irq
++) {
1335 generic_handle_irq(gpio_irq
);
1338 /* if bank has any level sensitive GPIO pin interrupt
1339 configured, we must unmask the bank interrupt only after
1340 handler(s) are executed in order to avoid spurious bank
1343 desc
->chip
->unmask(irq
);
1347 static void gpio_irq_shutdown(unsigned int irq
)
1349 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1350 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1352 _reset_gpio(bank
, gpio
);
1355 static void gpio_ack_irq(unsigned int irq
)
1357 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1358 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1360 _clear_gpio_irqstatus(bank
, gpio
);
1363 static void gpio_mask_irq(unsigned int irq
)
1365 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1366 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1368 _set_gpio_irqenable(bank
, gpio
, 0);
1369 _set_gpio_triggering(bank
, get_gpio_index(gpio
), IRQ_TYPE_NONE
);
1372 static void gpio_unmask_irq(unsigned int irq
)
1374 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1375 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1376 unsigned int irq_mask
= 1 << get_gpio_index(gpio
);
1377 struct irq_desc
*desc
= irq_to_desc(irq
);
1378 u32 trigger
= desc
->status
& IRQ_TYPE_SENSE_MASK
;
1381 _set_gpio_triggering(bank
, get_gpio_index(gpio
), trigger
);
1383 /* For level-triggered GPIOs, the clearing must be done after
1384 * the HW source is cleared, thus after the handler has run */
1385 if (bank
->level_mask
& irq_mask
) {
1386 _set_gpio_irqenable(bank
, gpio
, 0);
1387 _clear_gpio_irqstatus(bank
, gpio
);
1390 _set_gpio_irqenable(bank
, gpio
, 1);
1393 static struct irq_chip gpio_irq_chip
= {
1395 .shutdown
= gpio_irq_shutdown
,
1396 .ack
= gpio_ack_irq
,
1397 .mask
= gpio_mask_irq
,
1398 .unmask
= gpio_unmask_irq
,
1399 .set_type
= gpio_irq_type
,
1400 .set_wake
= gpio_wake_enable
,
1403 /*---------------------------------------------------------------------*/
1405 #ifdef CONFIG_ARCH_OMAP1
1407 /* MPUIO uses the always-on 32k clock */
1409 static void mpuio_ack_irq(unsigned int irq
)
1411 /* The ISR is reset automatically, so do nothing here. */
1414 static void mpuio_mask_irq(unsigned int irq
)
1416 unsigned int gpio
= OMAP_MPUIO(irq
- IH_MPUIO_BASE
);
1417 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1419 _set_gpio_irqenable(bank
, gpio
, 0);
1422 static void mpuio_unmask_irq(unsigned int irq
)
1424 unsigned int gpio
= OMAP_MPUIO(irq
- IH_MPUIO_BASE
);
1425 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1427 _set_gpio_irqenable(bank
, gpio
, 1);
1430 static struct irq_chip mpuio_irq_chip
= {
1432 .ack
= mpuio_ack_irq
,
1433 .mask
= mpuio_mask_irq
,
1434 .unmask
= mpuio_unmask_irq
,
1435 .set_type
= gpio_irq_type
,
1436 #ifdef CONFIG_ARCH_OMAP16XX
1437 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1438 .set_wake
= gpio_wake_enable
,
1443 #define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1446 #ifdef CONFIG_ARCH_OMAP16XX
1448 #include <linux/platform_device.h>
1450 static int omap_mpuio_suspend_noirq(struct device
*dev
)
1452 struct platform_device
*pdev
= to_platform_device(dev
);
1453 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1454 void __iomem
*mask_reg
= bank
->base
+ OMAP_MPUIO_GPIO_MASKIT
;
1455 unsigned long flags
;
1457 spin_lock_irqsave(&bank
->lock
, flags
);
1458 bank
->saved_wakeup
= __raw_readl(mask_reg
);
1459 __raw_writel(0xffff & ~bank
->suspend_wakeup
, mask_reg
);
1460 spin_unlock_irqrestore(&bank
->lock
, flags
);
1465 static int omap_mpuio_resume_noirq(struct device
*dev
)
1467 struct platform_device
*pdev
= to_platform_device(dev
);
1468 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1469 void __iomem
*mask_reg
= bank
->base
+ OMAP_MPUIO_GPIO_MASKIT
;
1470 unsigned long flags
;
1472 spin_lock_irqsave(&bank
->lock
, flags
);
1473 __raw_writel(bank
->saved_wakeup
, mask_reg
);
1474 spin_unlock_irqrestore(&bank
->lock
, flags
);
1479 static struct dev_pm_ops omap_mpuio_dev_pm_ops
= {
1480 .suspend_noirq
= omap_mpuio_suspend_noirq
,
1481 .resume_noirq
= omap_mpuio_resume_noirq
,
1484 /* use platform_driver for this, now that there's no longer any
1485 * point to sys_device (other than not disturbing old code).
1487 static struct platform_driver omap_mpuio_driver
= {
1490 .pm
= &omap_mpuio_dev_pm_ops
,
1494 static struct platform_device omap_mpuio_device
= {
1498 .driver
= &omap_mpuio_driver
.driver
,
1500 /* could list the /proc/iomem resources */
1503 static inline void mpuio_init(void)
1505 platform_set_drvdata(&omap_mpuio_device
, &gpio_bank_1610
[0]);
1507 if (platform_driver_register(&omap_mpuio_driver
) == 0)
1508 (void) platform_device_register(&omap_mpuio_device
);
1512 static inline void mpuio_init(void) {}
1517 extern struct irq_chip mpuio_irq_chip
;
1519 #define bank_is_mpuio(bank) 0
1520 static inline void mpuio_init(void) {}
1524 /*---------------------------------------------------------------------*/
1526 /* REVISIT these are stupid implementations! replace by ones that
1527 * don't switch on METHOD_* and which mostly avoid spinlocks
1530 static int gpio_input(struct gpio_chip
*chip
, unsigned offset
)
1532 struct gpio_bank
*bank
;
1533 unsigned long flags
;
1535 bank
= container_of(chip
, struct gpio_bank
, chip
);
1536 spin_lock_irqsave(&bank
->lock
, flags
);
1537 _set_gpio_direction(bank
, offset
, 1);
1538 spin_unlock_irqrestore(&bank
->lock
, flags
);
1542 static int gpio_is_input(struct gpio_bank
*bank
, int mask
)
1544 void __iomem
*reg
= bank
->base
;
1546 switch (bank
->method
) {
1548 reg
+= OMAP_MPUIO_IO_CNTL
;
1550 case METHOD_GPIO_1510
:
1551 reg
+= OMAP1510_GPIO_DIR_CONTROL
;
1553 case METHOD_GPIO_1610
:
1554 reg
+= OMAP1610_GPIO_DIRECTION
;
1556 case METHOD_GPIO_7XX
:
1557 reg
+= OMAP7XX_GPIO_DIR_CONTROL
;
1559 case METHOD_GPIO_24XX
:
1560 reg
+= OMAP24XX_GPIO_OE
;
1563 return __raw_readl(reg
) & mask
;
1566 static int gpio_get(struct gpio_chip
*chip
, unsigned offset
)
1568 struct gpio_bank
*bank
;
1573 gpio
= chip
->base
+ offset
;
1574 bank
= get_gpio_bank(gpio
);
1576 mask
= 1 << get_gpio_index(gpio
);
1578 if (gpio_is_input(bank
, mask
))
1579 return _get_gpio_datain(bank
, gpio
);
1581 return _get_gpio_dataout(bank
, gpio
);
1584 static int gpio_output(struct gpio_chip
*chip
, unsigned offset
, int value
)
1586 struct gpio_bank
*bank
;
1587 unsigned long flags
;
1589 bank
= container_of(chip
, struct gpio_bank
, chip
);
1590 spin_lock_irqsave(&bank
->lock
, flags
);
1591 _set_gpio_dataout(bank
, offset
, value
);
1592 _set_gpio_direction(bank
, offset
, 0);
1593 spin_unlock_irqrestore(&bank
->lock
, flags
);
1597 static void gpio_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
1599 struct gpio_bank
*bank
;
1600 unsigned long flags
;
1602 bank
= container_of(chip
, struct gpio_bank
, chip
);
1603 spin_lock_irqsave(&bank
->lock
, flags
);
1604 _set_gpio_dataout(bank
, offset
, value
);
1605 spin_unlock_irqrestore(&bank
->lock
, flags
);
1608 static int gpio_2irq(struct gpio_chip
*chip
, unsigned offset
)
1610 struct gpio_bank
*bank
;
1612 bank
= container_of(chip
, struct gpio_bank
, chip
);
1613 return bank
->virtual_irq_start
+ offset
;
1616 /*---------------------------------------------------------------------*/
1618 static int initialized
;
1619 #if !(defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4))
1620 static struct clk
* gpio_ick
;
1623 #if defined(CONFIG_ARCH_OMAP2)
1624 static struct clk
* gpio_fck
;
1627 #if defined(CONFIG_ARCH_OMAP2430)
1628 static struct clk
* gpio5_ick
;
1629 static struct clk
* gpio5_fck
;
1632 #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1633 static struct clk
*gpio_iclks
[OMAP34XX_NR_GPIOS
];
1636 * Following pad init code in addition to the context / restore hooks are
1637 * needed to fix glitches in GPIO outputs during off-mode. See OMAP3
1638 * errate section 1.158
1640 static int __init
omap3_gpio_pads_init(void)
1642 int i
, j
, min
, max
, gpio_amt
;
1647 for (i
= 0; i
< ARRAY_SIZE(gpio_pads_config
); i
++) {
1648 min
= gpio_pads_config
[i
].min
;
1649 max
= gpio_pads_config
[i
].max
;
1650 offset
= gpio_pads_config
[i
].offset
;
1652 for (j
= min
; j
<= max
; j
++) {
1653 /* Check if pad has been configured as GPIO. */
1654 if ((omap_ctrl_readw(offset
) &
1655 OMAP34XX_MUX_MODE7
) == OMAP34XX_MUX_MODE4
) {
1656 gpio_pad_map
[j
] = offset
;
1663 gpio_pads
= kmalloc(sizeof(struct gpio_pad
) * (gpio_amt
+ 1),
1666 if (gpio_pads
== NULL
) {
1667 printk(KERN_ERR
"FATAL: Failed to allocate gpio_pads\n");
1672 for (i
= 0; i
< OMAP34XX_GPIO_AMT
; i
++) {
1674 * First module (gpio 0...31) is ignored as it is
1675 * in wakeup domain and does not need special
1676 * handling during off mode.
1678 if (gpio_pad_map
[i
] && i
> 31) {
1679 gpio_pads
[gpio_amt
].gpio
= i
;
1680 gpio_pads
[gpio_amt
].offset
= gpio_pad_map
[i
];
1684 gpio_pads
[gpio_amt
].gpio
= -1;
1687 late_initcall(omap3_gpio_pads_init
);
1690 static void __init
omap_gpio_show_rev(void)
1694 if (cpu_is_omap16xx())
1695 rev
= __raw_readw(gpio_bank
[1].base
+ OMAP1610_GPIO_REVISION
);
1696 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1697 rev
= __raw_readl(gpio_bank
[0].base
+ OMAP24XX_GPIO_REVISION
);
1698 else if (cpu_is_omap44xx())
1699 rev
= __raw_readl(gpio_bank
[0].base
+ OMAP4_GPIO_REVISION
);
1703 printk(KERN_INFO
"OMAP GPIO hardware version %d.%d\n",
1704 (rev
>> 4) & 0x0f, rev
& 0x0f);
1707 /* This lock class tells lockdep that GPIO irqs are in a different
1708 * category than their parents, so it won't report false recursion.
1710 static struct lock_class_key gpio_lock_class
;
1712 static int __init
_omap_gpio_init(void)
1716 struct gpio_bank
*bank
;
1717 int bank_size
= SZ_8K
; /* Module 4KB + L4 4KB except on omap1 */
1722 #if defined(CONFIG_ARCH_OMAP1)
1723 if (cpu_is_omap15xx()) {
1724 gpio_ick
= clk_get(NULL
, "arm_gpio_ck");
1725 if (IS_ERR(gpio_ick
))
1726 printk("Could not get arm_gpio_ck\n");
1728 clk_enable(gpio_ick
);
1731 #if defined(CONFIG_ARCH_OMAP2)
1732 if (cpu_class_is_omap2()) {
1733 gpio_ick
= clk_get(NULL
, "gpios_ick");
1734 if (IS_ERR(gpio_ick
))
1735 printk("Could not get gpios_ick\n");
1737 clk_enable(gpio_ick
);
1738 gpio_fck
= clk_get(NULL
, "gpios_fck");
1739 if (IS_ERR(gpio_fck
))
1740 printk("Could not get gpios_fck\n");
1742 clk_enable(gpio_fck
);
1745 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
1747 #if defined(CONFIG_ARCH_OMAP2430)
1748 if (cpu_is_omap2430()) {
1749 gpio5_ick
= clk_get(NULL
, "gpio5_ick");
1750 if (IS_ERR(gpio5_ick
))
1751 printk("Could not get gpio5_ick\n");
1753 clk_enable(gpio5_ick
);
1754 gpio5_fck
= clk_get(NULL
, "gpio5_fck");
1755 if (IS_ERR(gpio5_fck
))
1756 printk("Could not get gpio5_fck\n");
1758 clk_enable(gpio5_fck
);
1764 #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1765 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
1766 for (i
= 0; i
< OMAP34XX_NR_GPIOS
; i
++) {
1767 sprintf(clk_name
, "gpio%d_ick", i
+ 1);
1768 gpio_iclks
[i
] = clk_get(NULL
, clk_name
);
1769 if (IS_ERR(gpio_iclks
[i
]))
1770 printk(KERN_ERR
"Could not get %s\n", clk_name
);
1772 clk_enable(gpio_iclks
[i
]);
1778 #ifdef CONFIG_ARCH_OMAP15XX
1779 if (cpu_is_omap15xx()) {
1780 gpio_bank_count
= 2;
1781 gpio_bank
= gpio_bank_1510
;
1785 #if defined(CONFIG_ARCH_OMAP16XX)
1786 if (cpu_is_omap16xx()) {
1787 gpio_bank_count
= 5;
1788 gpio_bank
= gpio_bank_1610
;
1792 #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1793 if (cpu_is_omap7xx()) {
1794 gpio_bank_count
= 7;
1795 gpio_bank
= gpio_bank_7xx
;
1799 #ifdef CONFIG_ARCH_OMAP24XX
1800 if (cpu_is_omap242x()) {
1801 gpio_bank_count
= 4;
1802 gpio_bank
= gpio_bank_242x
;
1804 if (cpu_is_omap243x()) {
1805 gpio_bank_count
= 5;
1806 gpio_bank
= gpio_bank_243x
;
1809 #ifdef CONFIG_ARCH_OMAP34XX
1810 if (cpu_is_omap34xx()) {
1811 gpio_bank_count
= OMAP34XX_NR_GPIOS
;
1812 gpio_bank
= gpio_bank_34xx
;
1815 #ifdef CONFIG_ARCH_OMAP4
1816 if (cpu_is_omap44xx()) {
1817 gpio_bank_count
= OMAP34XX_NR_GPIOS
;
1818 gpio_bank
= gpio_bank_44xx
;
1821 for (i
= 0; i
< gpio_bank_count
; i
++) {
1822 int j
, gpio_count
= 16;
1824 bank
= &gpio_bank
[i
];
1825 spin_lock_init(&bank
->lock
);
1827 /* Static mapping, never released */
1828 bank
->base
= ioremap(bank
->pbase
, bank_size
);
1830 printk(KERN_ERR
"Could not ioremap gpio bank%i\n", i
);
1834 if (bank_is_mpuio(bank
))
1835 __raw_writew(0xffff, bank
->base
+ OMAP_MPUIO_GPIO_MASKIT
);
1836 if (cpu_is_omap15xx() && bank
->method
== METHOD_GPIO_1510
) {
1837 __raw_writew(0xffff, bank
->base
+ OMAP1510_GPIO_INT_MASK
);
1838 __raw_writew(0x0000, bank
->base
+ OMAP1510_GPIO_INT_STATUS
);
1840 if (cpu_is_omap16xx() && bank
->method
== METHOD_GPIO_1610
) {
1841 __raw_writew(0x0000, bank
->base
+ OMAP1610_GPIO_IRQENABLE1
);
1842 __raw_writew(0xffff, bank
->base
+ OMAP1610_GPIO_IRQSTATUS1
);
1843 __raw_writew(0x0014, bank
->base
+ OMAP1610_GPIO_SYSCONFIG
);
1845 if (cpu_is_omap7xx() && bank
->method
== METHOD_GPIO_7XX
) {
1846 __raw_writel(0xffffffff, bank
->base
+ OMAP7XX_GPIO_INT_MASK
);
1847 __raw_writel(0x00000000, bank
->base
+ OMAP7XX_GPIO_INT_STATUS
);
1849 gpio_count
= 32; /* 7xx has 32-bit GPIOs */
1852 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1853 defined(CONFIG_ARCH_OMAP4)
1854 if (bank
->method
== METHOD_GPIO_24XX
) {
1855 static const u32 non_wakeup_gpios
[] = {
1856 0xe203ffc0, 0x08700040
1858 if (cpu_is_omap44xx()) {
1859 __raw_writel(0xffffffff, bank
->base
+
1860 OMAP4_GPIO_IRQSTATUSCLR0
);
1861 __raw_writew(0x0015, bank
->base
+
1862 OMAP4_GPIO_SYSCONFIG
);
1863 __raw_writel(0x00000000, bank
->base
+
1864 OMAP4_GPIO_DEBOUNCENABLE
);
1865 /* Initialize interface clock ungated, module enabled */
1866 __raw_writel(0, bank
->base
+ OMAP4_GPIO_CTRL
);
1868 __raw_writel(0x00000000, bank
->base
+ OMAP24XX_GPIO_IRQENABLE1
);
1869 __raw_writel(0xffffffff, bank
->base
+ OMAP24XX_GPIO_IRQSTATUS1
);
1870 __raw_writew(0x0015, bank
->base
+ OMAP24XX_GPIO_SYSCONFIG
);
1871 __raw_writel(0x00000000, bank
->base
+ OMAP24XX_GPIO_DEBOUNCE_EN
);
1873 /* Initialize interface clock ungated, module enabled */
1874 __raw_writel(0, bank
->base
+ OMAP24XX_GPIO_CTRL
);
1876 if (cpu_is_omap24xx() &&
1877 i
< ARRAY_SIZE(non_wakeup_gpios
))
1878 bank
->non_wakeup_gpios
= non_wakeup_gpios
[i
];
1882 /* REVISIT eventually switch from OMAP-specific gpio structs
1883 * over to the generic ones
1885 bank
->chip
.request
= omap_gpio_request
;
1886 bank
->chip
.free
= omap_gpio_free
;
1887 bank
->chip
.direction_input
= gpio_input
;
1888 bank
->chip
.get
= gpio_get
;
1889 bank
->chip
.direction_output
= gpio_output
;
1890 bank
->chip
.set
= gpio_set
;
1891 bank
->chip
.to_irq
= gpio_2irq
;
1892 if (bank_is_mpuio(bank
)) {
1893 bank
->chip
.label
= "mpuio";
1894 #ifdef CONFIG_ARCH_OMAP16XX
1895 bank
->chip
.dev
= &omap_mpuio_device
.dev
;
1897 bank
->chip
.base
= OMAP_MPUIO(0);
1899 bank
->chip
.label
= "gpio";
1900 bank
->chip
.base
= gpio
;
1903 bank
->chip
.ngpio
= gpio_count
;
1905 gpiochip_add(&bank
->chip
);
1907 for (j
= bank
->virtual_irq_start
;
1908 j
< bank
->virtual_irq_start
+ gpio_count
; j
++) {
1909 lockdep_set_class(&irq_desc
[j
].lock
, &gpio_lock_class
);
1910 set_irq_chip_data(j
, bank
);
1911 if (bank_is_mpuio(bank
))
1912 set_irq_chip(j
, &mpuio_irq_chip
);
1914 set_irq_chip(j
, &gpio_irq_chip
);
1915 set_irq_handler(j
, handle_simple_irq
);
1916 set_irq_flags(j
, IRQF_VALID
);
1918 set_irq_chained_handler(bank
->irq
, gpio_irq_handler
);
1919 set_irq_data(bank
->irq
, bank
);
1921 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
1922 sprintf(clk_name
, "gpio%d_dbck", i
+ 1);
1923 bank
->dbck
= clk_get(NULL
, clk_name
);
1924 if (IS_ERR(bank
->dbck
))
1925 printk(KERN_ERR
"Could not get %s\n", clk_name
);
1929 /* Enable system clock for GPIO module.
1930 * The CAM_CLK_CTRL *is* really the right place. */
1931 if (cpu_is_omap16xx())
1932 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL
) | 0x04, ULPD_CAM_CLK_CTRL
);
1934 /* Enable autoidle for the OCP interface */
1935 if (cpu_is_omap24xx())
1936 omap_writel(1 << 0, 0x48019010);
1937 if (cpu_is_omap34xx())
1938 omap_writel(1 << 0, 0x48306814);
1940 omap_gpio_show_rev();
1945 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1946 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
1947 static int omap_gpio_suspend(struct sys_device
*dev
, pm_message_t mesg
)
1951 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
1954 for (i
= 0; i
< gpio_bank_count
; i
++) {
1955 struct gpio_bank
*bank
= &gpio_bank
[i
];
1956 void __iomem
*wake_status
;
1957 void __iomem
*wake_clear
;
1958 void __iomem
*wake_set
;
1959 unsigned long flags
;
1961 switch (bank
->method
) {
1962 #ifdef CONFIG_ARCH_OMAP16XX
1963 case METHOD_GPIO_1610
:
1964 wake_status
= bank
->base
+ OMAP1610_GPIO_WAKEUPENABLE
;
1965 wake_clear
= bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
;
1966 wake_set
= bank
->base
+ OMAP1610_GPIO_SET_WAKEUPENA
;
1969 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1970 case METHOD_GPIO_24XX
:
1971 wake_status
= bank
->base
+ OMAP24XX_GPIO_WAKE_EN
;
1972 wake_clear
= bank
->base
+ OMAP24XX_GPIO_CLEARWKUENA
;
1973 wake_set
= bank
->base
+ OMAP24XX_GPIO_SETWKUENA
;
1976 #ifdef CONFIG_ARCH_OMAP4
1977 case METHOD_GPIO_24XX
:
1978 wake_status
= bank
->base
+ OMAP4_GPIO_IRQWAKEN0
;
1979 wake_clear
= bank
->base
+ OMAP4_GPIO_IRQWAKEN0
;
1980 wake_set
= bank
->base
+ OMAP4_GPIO_IRQWAKEN0
;
1987 spin_lock_irqsave(&bank
->lock
, flags
);
1988 bank
->saved_wakeup
= __raw_readl(wake_status
);
1989 __raw_writel(0xffffffff, wake_clear
);
1990 __raw_writel(bank
->suspend_wakeup
, wake_set
);
1991 spin_unlock_irqrestore(&bank
->lock
, flags
);
1993 #ifdef CONFIG_ARCH_OMAP34XX
1994 if (bank
->method
== METHOD_GPIO_24XX
) {
1996 for (j
= 0; j
< 32; j
++) {
1997 int offset
= gpio_pad_map
[j
+ i
* 32];
2003 v
= omap_ctrl_readw(offset
);
2004 if (bank
->suspend_wakeup
& (1 << j
))
2005 v
|= OMAP3_PADCONF_WAKEUPENABLE0
;
2007 v
&= ~OMAP3_PADCONF_WAKEUPENABLE0
;
2008 omap_ctrl_writew(v
, offset
);
2017 static int omap_gpio_resume(struct sys_device
*dev
)
2021 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
2024 for (i
= 0; i
< gpio_bank_count
; i
++) {
2025 struct gpio_bank
*bank
= &gpio_bank
[i
];
2026 void __iomem
*wake_clear
;
2027 void __iomem
*wake_set
;
2028 unsigned long flags
;
2030 switch (bank
->method
) {
2031 #ifdef CONFIG_ARCH_OMAP16XX
2032 case METHOD_GPIO_1610
:
2033 wake_clear
= bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
;
2034 wake_set
= bank
->base
+ OMAP1610_GPIO_SET_WAKEUPENA
;
2037 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
2038 case METHOD_GPIO_24XX
:
2039 wake_clear
= bank
->base
+ OMAP24XX_GPIO_CLEARWKUENA
;
2040 wake_set
= bank
->base
+ OMAP24XX_GPIO_SETWKUENA
;
2043 #ifdef CONFIG_ARCH_OMAP4
2044 case METHOD_GPIO_24XX
:
2045 wake_clear
= bank
->base
+ OMAP4_GPIO_IRQWAKEN0
;
2046 wake_set
= bank
->base
+ OMAP4_GPIO_IRQWAKEN0
;
2053 spin_lock_irqsave(&bank
->lock
, flags
);
2054 __raw_writel(0xffffffff, wake_clear
);
2055 __raw_writel(bank
->saved_wakeup
, wake_set
);
2056 spin_unlock_irqrestore(&bank
->lock
, flags
);
2062 static struct sysdev_class omap_gpio_sysclass
= {
2064 .suspend
= omap_gpio_suspend
,
2065 .resume
= omap_gpio_resume
,
2068 static struct sys_device omap_gpio_device
= {
2070 .cls
= &omap_gpio_sysclass
,
2075 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
2076 defined(CONFIG_ARCH_OMAP4)
2078 static int workaround_enabled
;
2080 void omap2_gpio_prepare_for_idle(int power_state
)
2085 if (cpu_is_omap34xx())
2088 for (i
= min
; i
< gpio_bank_count
; i
++) {
2089 struct gpio_bank
*bank
= &gpio_bank
[i
];
2092 if (cpu_is_omap34xx() && bank
->dbck_enable_mask
)
2093 clk_disable(bank
->dbck
);
2095 if (power_state
> PWRDM_POWER_OFF
)
2098 /* If going to OFF, remove triggering for all
2099 * non-wakeup GPIOs. Otherwise spurious IRQs will be
2100 * generated. See OMAP2420 Errata item 1.101. */
2101 if (!(bank
->enabled_non_wakeup_gpios
))
2103 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
2104 bank
->saved_datain
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_DATAIN
);
2105 l1
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
2106 l2
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
2108 #ifdef CONFIG_ARCH_OMAP4
2109 bank
->saved_datain
= __raw_readl(bank
->base
+
2111 l1
= __raw_readl(bank
->base
+ OMAP4_GPIO_FALLINGDETECT
);
2112 l2
= __raw_readl(bank
->base
+ OMAP4_GPIO_RISINGDETECT
);
2114 bank
->saved_fallingdetect
= l1
;
2115 bank
->saved_risingdetect
= l2
;
2116 l1
&= ~bank
->enabled_non_wakeup_gpios
;
2117 l2
&= ~bank
->enabled_non_wakeup_gpios
;
2118 if (cpu_is_omap24xx()) {
2119 __raw_writel(l1
, bank
->base
+
2120 OMAP24XX_GPIO_FALLINGDETECT
);
2121 __raw_writel(l2
, bank
->base
+
2122 OMAP24XX_GPIO_RISINGDETECT
);
2127 workaround_enabled
= 0;
2130 workaround_enabled
= 1;
2133 void omap2_gpio_resume_after_idle(void)
2138 if (cpu_is_omap34xx())
2140 for (i
= min
; i
< gpio_bank_count
; i
++) {
2141 struct gpio_bank
*bank
= &gpio_bank
[i
];
2142 u32 l
, gen
, gen0
, gen1
;
2144 if (cpu_is_omap34xx() && bank
->dbck_enable_mask
)
2145 clk_enable(bank
->dbck
);
2147 if (!workaround_enabled
)
2150 if (!(bank
->enabled_non_wakeup_gpios
))
2152 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
2153 __raw_writel(bank
->saved_fallingdetect
,
2154 bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
2155 __raw_writel(bank
->saved_risingdetect
,
2156 bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
2157 l
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_DATAIN
);
2159 #ifdef CONFIG_ARCH_OMAP4
2160 __raw_writel(bank
->saved_fallingdetect
,
2161 bank
->base
+ OMAP4_GPIO_FALLINGDETECT
);
2162 __raw_writel(bank
->saved_risingdetect
,
2163 bank
->base
+ OMAP4_GPIO_RISINGDETECT
);
2164 l
= __raw_readl(bank
->base
+ OMAP4_GPIO_DATAIN
);
2166 /* Check if any of the non-wakeup interrupt GPIOs have changed
2167 * state. If so, generate an IRQ by software. This is
2168 * horribly racy, but it's the best we can do to work around
2169 * this silicon bug. */
2170 l
^= bank
->saved_datain
;
2171 l
&= bank
->enabled_non_wakeup_gpios
;
2174 * No need to generate IRQs for the rising edge for gpio IRQs
2175 * configured with falling edge only; and vice versa.
2177 gen0
= l
& bank
->saved_fallingdetect
;
2178 gen0
&= bank
->saved_datain
;
2180 gen1
= l
& bank
->saved_risingdetect
;
2181 gen1
&= ~(bank
->saved_datain
);
2183 /* FIXME: Consider GPIO IRQs with level detections properly! */
2184 gen
= l
& (~(bank
->saved_fallingdetect
) &
2185 ~(bank
->saved_risingdetect
));
2186 /* Consider all GPIO IRQs needed to be updated */
2191 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
2192 old0
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
2193 old1
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
2194 __raw_writel(old0
| gen
, bank
->base
+
2195 OMAP24XX_GPIO_LEVELDETECT0
);
2196 __raw_writel(old1
| gen
, bank
->base
+
2197 OMAP24XX_GPIO_LEVELDETECT1
);
2198 __raw_writel(old0
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
2199 __raw_writel(old1
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
2201 #ifdef CONFIG_ARCH_OMAP4
2202 old0
= __raw_readl(bank
->base
+
2203 OMAP4_GPIO_LEVELDETECT0
);
2204 old1
= __raw_readl(bank
->base
+
2205 OMAP4_GPIO_LEVELDETECT1
);
2206 __raw_writel(old0
| l
, bank
->base
+
2207 OMAP4_GPIO_LEVELDETECT0
);
2208 __raw_writel(old1
| l
, bank
->base
+
2209 OMAP4_GPIO_LEVELDETECT1
);
2210 __raw_writel(old0
, bank
->base
+
2211 OMAP4_GPIO_LEVELDETECT0
);
2212 __raw_writel(old1
, bank
->base
+
2213 OMAP4_GPIO_LEVELDETECT1
);
2222 #ifdef CONFIG_ARCH_OMAP34XX
2223 /* save the registers of bank 2-6 */
2224 void omap_gpio_save_context(void)
2227 struct gpio_bank
*bank
;
2231 struct gpio_pad
*pad
;
2232 u32 tmp_oe
[OMAP34XX_NR_GPIOS
];
2234 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2235 for (i
= 1; i
< gpio_bank_count
; i
++) {
2236 bank
= &gpio_bank
[i
];
2237 gpio_context
[i
].sysconfig
=
2238 __raw_readl(bank
->base
+ OMAP24XX_GPIO_SYSCONFIG
);
2239 gpio_context
[i
].irqenable1
=
2240 __raw_readl(bank
->base
+ OMAP24XX_GPIO_IRQENABLE1
);
2241 gpio_context
[i
].irqenable2
=
2242 __raw_readl(bank
->base
+ OMAP24XX_GPIO_IRQENABLE2
);
2243 gpio_context
[i
].wake_en
=
2244 __raw_readl(bank
->base
+ OMAP24XX_GPIO_WAKE_EN
);
2245 gpio_context
[i
].ctrl
=
2246 __raw_readl(bank
->base
+ OMAP24XX_GPIO_CTRL
);
2247 gpio_context
[i
].oe
=
2248 __raw_readl(bank
->base
+ OMAP24XX_GPIO_OE
);
2249 tmp_oe
[i
] = gpio_context
[i
].oe
;
2250 gpio_context
[i
].leveldetect0
=
2251 __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
2252 gpio_context
[i
].leveldetect1
=
2253 __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
2254 gpio_context
[i
].risingdetect
=
2255 __raw_readl(bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
2256 gpio_context
[i
].fallingdetect
=
2257 __raw_readl(bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
2258 gpio_context
[i
].dataout
=
2259 __raw_readl(bank
->base
+ OMAP24XX_GPIO_DATAOUT
);
2266 while (pad
->gpio
>= 0) {
2267 /* n = gpio number, 0..191 */
2269 /* i = gpio bank, 0..5 */
2271 /* offset of padconf register */
2272 offset
= pad
->offset
;
2273 bank
= &gpio_bank
[i
];
2274 /* bit position of gpio in the bank 0..31 */
2275 pin
= 1 << (n
& 0x1f);
2277 /* check if gpio is configured as output => need hack */
2278 if (!(tmp_oe
[i
] & pin
)) {
2279 /* save current padconf setting */
2280 pad
->save
= omap_ctrl_readw(offset
);
2281 out
= gpio_context
[i
].dataout
;
2283 /* High: PU + input */
2284 conf
= OMAP34XX_PAD_IN_PU_GPIO
;
2286 /* Low: PD + input */
2287 conf
= OMAP34XX_PAD_IN_PD_GPIO
;
2288 /* Set PAD to GPIO + input */
2289 omap_ctrl_writew(conf
, offset
);
2290 /* Set GPIO to input */
2292 __raw_writel(tmp_oe
[i
],
2293 bank
->base
+ OMAP24XX_GPIO_OE
);
2294 /* Set PAD to safe mode */
2295 omap_ctrl_writew(conf
| OMAP34XX_PAD_SAFE_MODE
, offset
);
2302 /* restore the required registers of bank 2-6 */
2303 void omap_gpio_restore_context(void)
2307 for (i
= 1; i
< gpio_bank_count
; i
++) {
2308 struct gpio_bank
*bank
= &gpio_bank
[i
];
2309 __raw_writel(gpio_context
[i
].sysconfig
,
2310 bank
->base
+ OMAP24XX_GPIO_SYSCONFIG
);
2311 __raw_writel(gpio_context
[i
].irqenable1
,
2312 bank
->base
+ OMAP24XX_GPIO_IRQENABLE1
);
2313 __raw_writel(gpio_context
[i
].irqenable2
,
2314 bank
->base
+ OMAP24XX_GPIO_IRQENABLE2
);
2315 __raw_writel(gpio_context
[i
].wake_en
,
2316 bank
->base
+ OMAP24XX_GPIO_WAKE_EN
);
2317 __raw_writel(gpio_context
[i
].ctrl
,
2318 bank
->base
+ OMAP24XX_GPIO_CTRL
);
2319 __raw_writel(gpio_context
[i
].leveldetect0
,
2320 bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
2321 __raw_writel(gpio_context
[i
].leveldetect1
,
2322 bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
2323 __raw_writel(gpio_context
[i
].risingdetect
,
2324 bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
2325 __raw_writel(gpio_context
[i
].fallingdetect
,
2326 bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
2327 __raw_writel(gpio_context
[i
].dataout
,
2328 bank
->base
+ OMAP24XX_GPIO_DATAOUT
);
2329 __raw_writel(gpio_context
[i
].oe
,
2330 bank
->base
+ OMAP24XX_GPIO_OE
);
2334 void omap3_gpio_restore_pad_context(int restore_oe
)
2336 struct gpio_pad
*pad
;
2342 for (i
= 1; i
< gpio_bank_count
; i
++) {
2343 struct gpio_bank
*bank
= &gpio_bank
[i
];
2344 __raw_writel(gpio_context
[i
].oe
,
2345 bank
->base
+ OMAP24XX_GPIO_OE
);
2352 while (pad
->gpio
>= 0) {
2354 omap_ctrl_writew(pad
->save
, pad
->offset
);
2361 * This may get called early from board specific init
2362 * for boards that have interrupts routed via FPGA.
2364 int __init
omap_gpio_init(void)
2367 return _omap_gpio_init();
2372 static int __init
omap_gpio_sysinit(void)
2377 ret
= _omap_gpio_init();
2381 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
2382 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
2383 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
2385 ret
= sysdev_class_register(&omap_gpio_sysclass
);
2387 ret
= sysdev_register(&omap_gpio_device
);
2395 arch_initcall(omap_gpio_sysinit
);
2398 #ifdef CONFIG_DEBUG_FS
2400 #include <linux/debugfs.h>
2401 #include <linux/seq_file.h>
2403 static int dbg_gpio_show(struct seq_file
*s
, void *unused
)
2405 unsigned i
, j
, gpio
;
2407 for (i
= 0, gpio
= 0; i
< gpio_bank_count
; i
++) {
2408 struct gpio_bank
*bank
= gpio_bank
+ i
;
2409 unsigned bankwidth
= 16;
2412 if (bank_is_mpuio(bank
))
2413 gpio
= OMAP_MPUIO(0);
2414 else if (cpu_class_is_omap2() || cpu_is_omap7xx())
2417 for (j
= 0; j
< bankwidth
; j
++, gpio
++, mask
<<= 1) {
2418 unsigned irq
, value
, is_in
, irqstat
;
2421 label
= gpiochip_is_requested(&bank
->chip
, j
);
2425 irq
= bank
->virtual_irq_start
+ j
;
2426 value
= gpio_get_value(gpio
);
2427 is_in
= gpio_is_input(bank
, mask
);
2429 if (bank_is_mpuio(bank
))
2430 seq_printf(s
, "MPUIO %2d ", j
);
2432 seq_printf(s
, "GPIO %3d ", gpio
);
2433 seq_printf(s
, "(%-20.20s): %s %s",
2435 is_in
? "in " : "out",
2436 value
? "hi" : "lo");
2438 /* FIXME for at least omap2, show pullup/pulldown state */
2440 irqstat
= irq_desc
[irq
].status
;
2441 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
2442 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
2443 if (is_in
&& ((bank
->suspend_wakeup
& mask
)
2444 || irqstat
& IRQ_TYPE_SENSE_MASK
)) {
2445 char *trigger
= NULL
;
2447 switch (irqstat
& IRQ_TYPE_SENSE_MASK
) {
2448 case IRQ_TYPE_EDGE_FALLING
:
2449 trigger
= "falling";
2451 case IRQ_TYPE_EDGE_RISING
:
2454 case IRQ_TYPE_EDGE_BOTH
:
2455 trigger
= "bothedge";
2457 case IRQ_TYPE_LEVEL_LOW
:
2460 case IRQ_TYPE_LEVEL_HIGH
:
2467 seq_printf(s
, ", irq-%d %-8s%s",
2469 (bank
->suspend_wakeup
& mask
)
2473 seq_printf(s
, "\n");
2476 if (bank_is_mpuio(bank
)) {
2477 seq_printf(s
, "\n");
2484 static int dbg_gpio_open(struct inode
*inode
, struct file
*file
)
2486 return single_open(file
, dbg_gpio_show
, &inode
->i_private
);
2489 static const struct file_operations debug_fops
= {
2490 .open
= dbg_gpio_open
,
2492 .llseek
= seq_lseek
,
2493 .release
= single_release
,
2496 static int __init
omap_gpio_debuginit(void)
2498 (void) debugfs_create_file("omap_gpio", S_IRUGO
,
2499 NULL
, NULL
, &debug_fops
);
2502 late_initcall(omap_gpio_debuginit
);