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 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/interrupt.h>
17 #include <linux/sysdev.h>
18 #include <linux/err.h>
19 #include <linux/clk.h>
22 #include <mach/hardware.h>
24 #include <mach/irqs.h>
25 #include <mach/gpio.h>
26 #include <asm/mach/irq.h>
29 * OMAP1510 GPIO registers
31 #define OMAP1510_GPIO_BASE IO_ADDRESS(0xfffce000)
32 #define OMAP1510_GPIO_DATA_INPUT 0x00
33 #define OMAP1510_GPIO_DATA_OUTPUT 0x04
34 #define OMAP1510_GPIO_DIR_CONTROL 0x08
35 #define OMAP1510_GPIO_INT_CONTROL 0x0c
36 #define OMAP1510_GPIO_INT_MASK 0x10
37 #define OMAP1510_GPIO_INT_STATUS 0x14
38 #define OMAP1510_GPIO_PIN_CONTROL 0x18
40 #define OMAP1510_IH_GPIO_BASE 64
43 * OMAP1610 specific GPIO registers
45 #define OMAP1610_GPIO1_BASE IO_ADDRESS(0xfffbe400)
46 #define OMAP1610_GPIO2_BASE IO_ADDRESS(0xfffbec00)
47 #define OMAP1610_GPIO3_BASE IO_ADDRESS(0xfffbb400)
48 #define OMAP1610_GPIO4_BASE IO_ADDRESS(0xfffbbc00)
49 #define OMAP1610_GPIO_REVISION 0x0000
50 #define OMAP1610_GPIO_SYSCONFIG 0x0010
51 #define OMAP1610_GPIO_SYSSTATUS 0x0014
52 #define OMAP1610_GPIO_IRQSTATUS1 0x0018
53 #define OMAP1610_GPIO_IRQENABLE1 0x001c
54 #define OMAP1610_GPIO_WAKEUPENABLE 0x0028
55 #define OMAP1610_GPIO_DATAIN 0x002c
56 #define OMAP1610_GPIO_DATAOUT 0x0030
57 #define OMAP1610_GPIO_DIRECTION 0x0034
58 #define OMAP1610_GPIO_EDGE_CTRL1 0x0038
59 #define OMAP1610_GPIO_EDGE_CTRL2 0x003c
60 #define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
61 #define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
62 #define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
63 #define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
64 #define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
65 #define OMAP1610_GPIO_SET_DATAOUT 0x00f0
68 * OMAP730 specific GPIO registers
70 #define OMAP730_GPIO1_BASE IO_ADDRESS(0xfffbc000)
71 #define OMAP730_GPIO2_BASE IO_ADDRESS(0xfffbc800)
72 #define OMAP730_GPIO3_BASE IO_ADDRESS(0xfffbd000)
73 #define OMAP730_GPIO4_BASE IO_ADDRESS(0xfffbd800)
74 #define OMAP730_GPIO5_BASE IO_ADDRESS(0xfffbe000)
75 #define OMAP730_GPIO6_BASE IO_ADDRESS(0xfffbe800)
76 #define OMAP730_GPIO_DATA_INPUT 0x00
77 #define OMAP730_GPIO_DATA_OUTPUT 0x04
78 #define OMAP730_GPIO_DIR_CONTROL 0x08
79 #define OMAP730_GPIO_INT_CONTROL 0x0c
80 #define OMAP730_GPIO_INT_MASK 0x10
81 #define OMAP730_GPIO_INT_STATUS 0x14
84 * OMAP850 specific GPIO registers
86 #define OMAP850_GPIO1_BASE IO_ADDRESS(0xfffbc000)
87 #define OMAP850_GPIO2_BASE IO_ADDRESS(0xfffbc800)
88 #define OMAP850_GPIO3_BASE IO_ADDRESS(0xfffbd000)
89 #define OMAP850_GPIO4_BASE IO_ADDRESS(0xfffbd800)
90 #define OMAP850_GPIO5_BASE IO_ADDRESS(0xfffbe000)
91 #define OMAP850_GPIO6_BASE IO_ADDRESS(0xfffbe800)
92 #define OMAP850_GPIO_DATA_INPUT 0x00
93 #define OMAP850_GPIO_DATA_OUTPUT 0x04
94 #define OMAP850_GPIO_DIR_CONTROL 0x08
95 #define OMAP850_GPIO_INT_CONTROL 0x0c
96 #define OMAP850_GPIO_INT_MASK 0x10
97 #define OMAP850_GPIO_INT_STATUS 0x14
100 * omap24xx specific GPIO registers
102 #define OMAP242X_GPIO1_BASE IO_ADDRESS(0x48018000)
103 #define OMAP242X_GPIO2_BASE IO_ADDRESS(0x4801a000)
104 #define OMAP242X_GPIO3_BASE IO_ADDRESS(0x4801c000)
105 #define OMAP242X_GPIO4_BASE IO_ADDRESS(0x4801e000)
107 #define OMAP243X_GPIO1_BASE IO_ADDRESS(0x4900C000)
108 #define OMAP243X_GPIO2_BASE IO_ADDRESS(0x4900E000)
109 #define OMAP243X_GPIO3_BASE IO_ADDRESS(0x49010000)
110 #define OMAP243X_GPIO4_BASE IO_ADDRESS(0x49012000)
111 #define OMAP243X_GPIO5_BASE IO_ADDRESS(0x480B6000)
113 #define OMAP24XX_GPIO_REVISION 0x0000
114 #define OMAP24XX_GPIO_SYSCONFIG 0x0010
115 #define OMAP24XX_GPIO_SYSSTATUS 0x0014
116 #define OMAP24XX_GPIO_IRQSTATUS1 0x0018
117 #define OMAP24XX_GPIO_IRQSTATUS2 0x0028
118 #define OMAP24XX_GPIO_IRQENABLE2 0x002c
119 #define OMAP24XX_GPIO_IRQENABLE1 0x001c
120 #define OMAP24XX_GPIO_WAKE_EN 0x0020
121 #define OMAP24XX_GPIO_CTRL 0x0030
122 #define OMAP24XX_GPIO_OE 0x0034
123 #define OMAP24XX_GPIO_DATAIN 0x0038
124 #define OMAP24XX_GPIO_DATAOUT 0x003c
125 #define OMAP24XX_GPIO_LEVELDETECT0 0x0040
126 #define OMAP24XX_GPIO_LEVELDETECT1 0x0044
127 #define OMAP24XX_GPIO_RISINGDETECT 0x0048
128 #define OMAP24XX_GPIO_FALLINGDETECT 0x004c
129 #define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
130 #define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
131 #define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
132 #define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
133 #define OMAP24XX_GPIO_CLEARWKUENA 0x0080
134 #define OMAP24XX_GPIO_SETWKUENA 0x0084
135 #define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
136 #define OMAP24XX_GPIO_SETDATAOUT 0x0094
139 * omap34xx specific GPIO registers
142 #define OMAP34XX_GPIO1_BASE IO_ADDRESS(0x48310000)
143 #define OMAP34XX_GPIO2_BASE IO_ADDRESS(0x49050000)
144 #define OMAP34XX_GPIO3_BASE IO_ADDRESS(0x49052000)
145 #define OMAP34XX_GPIO4_BASE IO_ADDRESS(0x49054000)
146 #define OMAP34XX_GPIO5_BASE IO_ADDRESS(0x49056000)
147 #define OMAP34XX_GPIO6_BASE IO_ADDRESS(0x49058000)
149 #define OMAP_MPUIO_VBASE IO_ADDRESS(OMAP_MPUIO_BASE)
154 u16 virtual_irq_start
;
156 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
160 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
161 u32 non_wakeup_gpios
;
162 u32 enabled_non_wakeup_gpios
;
165 u32 saved_fallingdetect
;
166 u32 saved_risingdetect
;
170 struct gpio_chip chip
;
174 #define METHOD_MPUIO 0
175 #define METHOD_GPIO_1510 1
176 #define METHOD_GPIO_1610 2
177 #define METHOD_GPIO_730 3
178 #define METHOD_GPIO_850 4
179 #define METHOD_GPIO_24XX 5
181 #ifdef CONFIG_ARCH_OMAP16XX
182 static struct gpio_bank gpio_bank_1610
[5] = {
183 { OMAP_MPUIO_VBASE
, INT_MPUIO
, IH_MPUIO_BASE
, METHOD_MPUIO
},
184 { OMAP1610_GPIO1_BASE
, INT_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_1610
},
185 { OMAP1610_GPIO2_BASE
, INT_1610_GPIO_BANK2
, IH_GPIO_BASE
+ 16, METHOD_GPIO_1610
},
186 { OMAP1610_GPIO3_BASE
, INT_1610_GPIO_BANK3
, IH_GPIO_BASE
+ 32, METHOD_GPIO_1610
},
187 { OMAP1610_GPIO4_BASE
, INT_1610_GPIO_BANK4
, IH_GPIO_BASE
+ 48, METHOD_GPIO_1610
},
191 #ifdef CONFIG_ARCH_OMAP15XX
192 static struct gpio_bank gpio_bank_1510
[2] = {
193 { OMAP_MPUIO_VBASE
, INT_MPUIO
, IH_MPUIO_BASE
, METHOD_MPUIO
},
194 { OMAP1510_GPIO_BASE
, INT_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_1510
}
198 #ifdef CONFIG_ARCH_OMAP730
199 static struct gpio_bank gpio_bank_730
[7] = {
200 { OMAP_MPUIO_VBASE
, INT_730_MPUIO
, IH_MPUIO_BASE
, METHOD_MPUIO
},
201 { OMAP730_GPIO1_BASE
, INT_730_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_730
},
202 { OMAP730_GPIO2_BASE
, INT_730_GPIO_BANK2
, IH_GPIO_BASE
+ 32, METHOD_GPIO_730
},
203 { OMAP730_GPIO3_BASE
, INT_730_GPIO_BANK3
, IH_GPIO_BASE
+ 64, METHOD_GPIO_730
},
204 { OMAP730_GPIO4_BASE
, INT_730_GPIO_BANK4
, IH_GPIO_BASE
+ 96, METHOD_GPIO_730
},
205 { OMAP730_GPIO5_BASE
, INT_730_GPIO_BANK5
, IH_GPIO_BASE
+ 128, METHOD_GPIO_730
},
206 { OMAP730_GPIO6_BASE
, INT_730_GPIO_BANK6
, IH_GPIO_BASE
+ 160, METHOD_GPIO_730
},
210 #ifdef CONFIG_ARCH_OMAP850
211 static struct gpio_bank gpio_bank_850
[7] = {
212 { OMAP_MPUIO_BASE
, INT_850_MPUIO
, IH_MPUIO_BASE
, METHOD_MPUIO
},
213 { OMAP850_GPIO1_BASE
, INT_850_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_850
},
214 { OMAP850_GPIO2_BASE
, INT_850_GPIO_BANK2
, IH_GPIO_BASE
+ 32, METHOD_GPIO_850
},
215 { OMAP850_GPIO3_BASE
, INT_850_GPIO_BANK3
, IH_GPIO_BASE
+ 64, METHOD_GPIO_850
},
216 { OMAP850_GPIO4_BASE
, INT_850_GPIO_BANK4
, IH_GPIO_BASE
+ 96, METHOD_GPIO_850
},
217 { OMAP850_GPIO5_BASE
, INT_850_GPIO_BANK5
, IH_GPIO_BASE
+ 128, METHOD_GPIO_850
},
218 { OMAP850_GPIO6_BASE
, INT_850_GPIO_BANK6
, IH_GPIO_BASE
+ 160, METHOD_GPIO_850
},
223 #ifdef CONFIG_ARCH_OMAP24XX
225 static struct gpio_bank gpio_bank_242x
[4] = {
226 { OMAP242X_GPIO1_BASE
, INT_24XX_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_24XX
},
227 { OMAP242X_GPIO2_BASE
, INT_24XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32, METHOD_GPIO_24XX
},
228 { OMAP242X_GPIO3_BASE
, INT_24XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64, METHOD_GPIO_24XX
},
229 { OMAP242X_GPIO4_BASE
, INT_24XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96, METHOD_GPIO_24XX
},
232 static struct gpio_bank gpio_bank_243x
[5] = {
233 { OMAP243X_GPIO1_BASE
, INT_24XX_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_24XX
},
234 { OMAP243X_GPIO2_BASE
, INT_24XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32, METHOD_GPIO_24XX
},
235 { OMAP243X_GPIO3_BASE
, INT_24XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64, METHOD_GPIO_24XX
},
236 { OMAP243X_GPIO4_BASE
, INT_24XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96, METHOD_GPIO_24XX
},
237 { OMAP243X_GPIO5_BASE
, INT_24XX_GPIO_BANK5
, IH_GPIO_BASE
+ 128, METHOD_GPIO_24XX
},
242 #ifdef CONFIG_ARCH_OMAP34XX
243 static struct gpio_bank gpio_bank_34xx
[6] = {
244 { OMAP34XX_GPIO1_BASE
, INT_34XX_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_24XX
},
245 { OMAP34XX_GPIO2_BASE
, INT_34XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32, METHOD_GPIO_24XX
},
246 { OMAP34XX_GPIO3_BASE
, INT_34XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64, METHOD_GPIO_24XX
},
247 { OMAP34XX_GPIO4_BASE
, INT_34XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96, METHOD_GPIO_24XX
},
248 { OMAP34XX_GPIO5_BASE
, INT_34XX_GPIO_BANK5
, IH_GPIO_BASE
+ 128, METHOD_GPIO_24XX
},
249 { OMAP34XX_GPIO6_BASE
, INT_34XX_GPIO_BANK6
, IH_GPIO_BASE
+ 160, METHOD_GPIO_24XX
},
254 static struct gpio_bank
*gpio_bank
;
255 static int gpio_bank_count
;
257 static inline struct gpio_bank
*get_gpio_bank(int gpio
)
259 if (cpu_is_omap15xx()) {
260 if (OMAP_GPIO_IS_MPUIO(gpio
))
261 return &gpio_bank
[0];
262 return &gpio_bank
[1];
264 if (cpu_is_omap16xx()) {
265 if (OMAP_GPIO_IS_MPUIO(gpio
))
266 return &gpio_bank
[0];
267 return &gpio_bank
[1 + (gpio
>> 4)];
269 if (cpu_is_omap7xx()) {
270 if (OMAP_GPIO_IS_MPUIO(gpio
))
271 return &gpio_bank
[0];
272 return &gpio_bank
[1 + (gpio
>> 5)];
274 if (cpu_is_omap24xx())
275 return &gpio_bank
[gpio
>> 5];
276 if (cpu_is_omap34xx())
277 return &gpio_bank
[gpio
>> 5];
282 static inline int get_gpio_index(int gpio
)
284 if (cpu_is_omap7xx())
286 if (cpu_is_omap24xx())
288 if (cpu_is_omap34xx())
293 static inline int gpio_valid(int gpio
)
297 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio
)) {
298 if (gpio
>= OMAP_MAX_GPIO_LINES
+ 16)
302 if (cpu_is_omap15xx() && gpio
< 16)
304 if ((cpu_is_omap16xx()) && gpio
< 64)
306 if (cpu_is_omap7xx() && gpio
< 192)
308 if (cpu_is_omap24xx() && gpio
< 128)
310 if (cpu_is_omap34xx() && gpio
< 192)
315 static int check_gpio(int gpio
)
317 if (unlikely(gpio_valid(gpio
)) < 0) {
318 printk(KERN_ERR
"omap-gpio: invalid GPIO %d\n", gpio
);
325 static void _set_gpio_direction(struct gpio_bank
*bank
, int gpio
, int is_input
)
327 void __iomem
*reg
= bank
->base
;
330 switch (bank
->method
) {
331 #ifdef CONFIG_ARCH_OMAP1
333 reg
+= OMAP_MPUIO_IO_CNTL
;
336 #ifdef CONFIG_ARCH_OMAP15XX
337 case METHOD_GPIO_1510
:
338 reg
+= OMAP1510_GPIO_DIR_CONTROL
;
341 #ifdef CONFIG_ARCH_OMAP16XX
342 case METHOD_GPIO_1610
:
343 reg
+= OMAP1610_GPIO_DIRECTION
;
346 #ifdef CONFIG_ARCH_OMAP730
347 case METHOD_GPIO_730
:
348 reg
+= OMAP730_GPIO_DIR_CONTROL
;
351 #ifdef CONFIG_ARCH_OMAP850
352 case METHOD_GPIO_850
:
353 reg
+= OMAP850_GPIO_DIR_CONTROL
;
356 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
357 case METHOD_GPIO_24XX
:
358 reg
+= OMAP24XX_GPIO_OE
;
365 l
= __raw_readl(reg
);
370 __raw_writel(l
, reg
);
373 static void _set_gpio_dataout(struct gpio_bank
*bank
, int gpio
, int enable
)
375 void __iomem
*reg
= bank
->base
;
378 switch (bank
->method
) {
379 #ifdef CONFIG_ARCH_OMAP1
381 reg
+= OMAP_MPUIO_OUTPUT
;
382 l
= __raw_readl(reg
);
389 #ifdef CONFIG_ARCH_OMAP15XX
390 case METHOD_GPIO_1510
:
391 reg
+= OMAP1510_GPIO_DATA_OUTPUT
;
392 l
= __raw_readl(reg
);
399 #ifdef CONFIG_ARCH_OMAP16XX
400 case METHOD_GPIO_1610
:
402 reg
+= OMAP1610_GPIO_SET_DATAOUT
;
404 reg
+= OMAP1610_GPIO_CLEAR_DATAOUT
;
408 #ifdef CONFIG_ARCH_OMAP730
409 case METHOD_GPIO_730
:
410 reg
+= OMAP730_GPIO_DATA_OUTPUT
;
411 l
= __raw_readl(reg
);
418 #ifdef CONFIG_ARCH_OMAP850
419 case METHOD_GPIO_850
:
420 reg
+= OMAP850_GPIO_DATA_OUTPUT
;
421 l
= __raw_readl(reg
);
428 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
429 case METHOD_GPIO_24XX
:
431 reg
+= OMAP24XX_GPIO_SETDATAOUT
;
433 reg
+= OMAP24XX_GPIO_CLEARDATAOUT
;
441 __raw_writel(l
, reg
);
444 static int __omap_get_gpio_datain(int gpio
)
446 struct gpio_bank
*bank
;
449 if (check_gpio(gpio
) < 0)
451 bank
= get_gpio_bank(gpio
);
453 switch (bank
->method
) {
454 #ifdef CONFIG_ARCH_OMAP1
456 reg
+= OMAP_MPUIO_INPUT_LATCH
;
459 #ifdef CONFIG_ARCH_OMAP15XX
460 case METHOD_GPIO_1510
:
461 reg
+= OMAP1510_GPIO_DATA_INPUT
;
464 #ifdef CONFIG_ARCH_OMAP16XX
465 case METHOD_GPIO_1610
:
466 reg
+= OMAP1610_GPIO_DATAIN
;
469 #ifdef CONFIG_ARCH_OMAP730
470 case METHOD_GPIO_730
:
471 reg
+= OMAP730_GPIO_DATA_INPUT
;
474 #ifdef CONFIG_ARCH_OMAP850
475 case METHOD_GPIO_850
:
476 reg
+= OMAP850_GPIO_DATA_INPUT
;
479 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
480 case METHOD_GPIO_24XX
:
481 reg
+= OMAP24XX_GPIO_DATAIN
;
487 return (__raw_readl(reg
)
488 & (1 << get_gpio_index(gpio
))) != 0;
491 #define MOD_REG_BIT(reg, bit_mask, set) \
493 int l = __raw_readl(base + reg); \
494 if (set) l |= bit_mask; \
495 else l &= ~bit_mask; \
496 __raw_writel(l, base + reg); \
499 void omap_set_gpio_debounce(int gpio
, int enable
)
501 struct gpio_bank
*bank
;
504 u32 val
, l
= 1 << get_gpio_index(gpio
);
506 if (cpu_class_is_omap1())
509 bank
= get_gpio_bank(gpio
);
511 reg
+= OMAP24XX_GPIO_DEBOUNCE_EN
;
513 spin_lock_irqsave(&bank
->lock
, flags
);
514 val
= __raw_readl(reg
);
516 if (enable
&& !(val
& l
))
518 else if (!enable
&& (val
& l
))
523 if (cpu_is_omap34xx()) {
525 clk_enable(bank
->dbck
);
527 clk_disable(bank
->dbck
);
530 __raw_writel(val
, reg
);
532 spin_unlock_irqrestore(&bank
->lock
, flags
);
534 EXPORT_SYMBOL(omap_set_gpio_debounce
);
536 void omap_set_gpio_debounce_time(int gpio
, int enc_time
)
538 struct gpio_bank
*bank
;
541 if (cpu_class_is_omap1())
544 bank
= get_gpio_bank(gpio
);
548 reg
+= OMAP24XX_GPIO_DEBOUNCE_VAL
;
549 __raw_writel(enc_time
, reg
);
551 EXPORT_SYMBOL(omap_set_gpio_debounce_time
);
553 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
554 static inline void set_24xx_gpio_triggering(struct gpio_bank
*bank
, int gpio
,
557 void __iomem
*base
= bank
->base
;
558 u32 gpio_bit
= 1 << gpio
;
560 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0
, gpio_bit
,
561 trigger
& IRQ_TYPE_LEVEL_LOW
);
562 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1
, gpio_bit
,
563 trigger
& IRQ_TYPE_LEVEL_HIGH
);
564 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT
, gpio_bit
,
565 trigger
& IRQ_TYPE_EDGE_RISING
);
566 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT
, gpio_bit
,
567 trigger
& IRQ_TYPE_EDGE_FALLING
);
569 if (likely(!(bank
->non_wakeup_gpios
& gpio_bit
))) {
571 __raw_writel(1 << gpio
, bank
->base
572 + OMAP24XX_GPIO_SETWKUENA
);
574 __raw_writel(1 << gpio
, bank
->base
575 + OMAP24XX_GPIO_CLEARWKUENA
);
578 bank
->enabled_non_wakeup_gpios
|= gpio_bit
;
580 bank
->enabled_non_wakeup_gpios
&= ~gpio_bit
;
584 __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
) |
585 __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
589 static int _set_gpio_triggering(struct gpio_bank
*bank
, int gpio
, int trigger
)
591 void __iomem
*reg
= bank
->base
;
594 switch (bank
->method
) {
595 #ifdef CONFIG_ARCH_OMAP1
597 reg
+= OMAP_MPUIO_GPIO_INT_EDGE
;
598 l
= __raw_readl(reg
);
599 if (trigger
& IRQ_TYPE_EDGE_RISING
)
601 else if (trigger
& IRQ_TYPE_EDGE_FALLING
)
607 #ifdef CONFIG_ARCH_OMAP15XX
608 case METHOD_GPIO_1510
:
609 reg
+= OMAP1510_GPIO_INT_CONTROL
;
610 l
= __raw_readl(reg
);
611 if (trigger
& IRQ_TYPE_EDGE_RISING
)
613 else if (trigger
& IRQ_TYPE_EDGE_FALLING
)
619 #ifdef CONFIG_ARCH_OMAP16XX
620 case METHOD_GPIO_1610
:
622 reg
+= OMAP1610_GPIO_EDGE_CTRL2
;
624 reg
+= OMAP1610_GPIO_EDGE_CTRL1
;
626 l
= __raw_readl(reg
);
627 l
&= ~(3 << (gpio
<< 1));
628 if (trigger
& IRQ_TYPE_EDGE_RISING
)
629 l
|= 2 << (gpio
<< 1);
630 if (trigger
& IRQ_TYPE_EDGE_FALLING
)
631 l
|= 1 << (gpio
<< 1);
633 /* Enable wake-up during idle for dynamic tick */
634 __raw_writel(1 << gpio
, bank
->base
+ OMAP1610_GPIO_SET_WAKEUPENA
);
636 __raw_writel(1 << gpio
, bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
);
639 #ifdef CONFIG_ARCH_OMAP730
640 case METHOD_GPIO_730
:
641 reg
+= OMAP730_GPIO_INT_CONTROL
;
642 l
= __raw_readl(reg
);
643 if (trigger
& IRQ_TYPE_EDGE_RISING
)
645 else if (trigger
& IRQ_TYPE_EDGE_FALLING
)
651 #ifdef CONFIG_ARCH_OMAP850
652 case METHOD_GPIO_850
:
653 reg
+= OMAP850_GPIO_INT_CONTROL
;
654 l
= __raw_readl(reg
);
655 if (trigger
& IRQ_TYPE_EDGE_RISING
)
657 else if (trigger
& IRQ_TYPE_EDGE_FALLING
)
663 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
664 case METHOD_GPIO_24XX
:
665 set_24xx_gpio_triggering(bank
, gpio
, trigger
);
671 __raw_writel(l
, reg
);
677 static int gpio_irq_type(unsigned irq
, unsigned type
)
679 struct gpio_bank
*bank
;
684 if (!cpu_class_is_omap2() && irq
> IH_MPUIO_BASE
)
685 gpio
= OMAP_MPUIO(irq
- IH_MPUIO_BASE
);
687 gpio
= irq
- IH_GPIO_BASE
;
689 if (check_gpio(gpio
) < 0)
692 if (type
& ~IRQ_TYPE_SENSE_MASK
)
695 /* OMAP1 allows only only edge triggering */
696 if (!cpu_class_is_omap2()
697 && (type
& (IRQ_TYPE_LEVEL_LOW
|IRQ_TYPE_LEVEL_HIGH
)))
700 bank
= get_irq_chip_data(irq
);
701 spin_lock_irqsave(&bank
->lock
, flags
);
702 retval
= _set_gpio_triggering(bank
, get_gpio_index(gpio
), type
);
704 irq_desc
[irq
].status
&= ~IRQ_TYPE_SENSE_MASK
;
705 irq_desc
[irq
].status
|= type
;
707 spin_unlock_irqrestore(&bank
->lock
, flags
);
709 if (type
& (IRQ_TYPE_LEVEL_LOW
| IRQ_TYPE_LEVEL_HIGH
))
710 __set_irq_handler_unlocked(irq
, handle_level_irq
);
711 else if (type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_EDGE_RISING
))
712 __set_irq_handler_unlocked(irq
, handle_edge_irq
);
717 static void _clear_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
)
719 void __iomem
*reg
= bank
->base
;
721 switch (bank
->method
) {
722 #ifdef CONFIG_ARCH_OMAP1
724 /* MPUIO irqstatus is reset by reading the status register,
725 * so do nothing here */
728 #ifdef CONFIG_ARCH_OMAP15XX
729 case METHOD_GPIO_1510
:
730 reg
+= OMAP1510_GPIO_INT_STATUS
;
733 #ifdef CONFIG_ARCH_OMAP16XX
734 case METHOD_GPIO_1610
:
735 reg
+= OMAP1610_GPIO_IRQSTATUS1
;
738 #ifdef CONFIG_ARCH_OMAP730
739 case METHOD_GPIO_730
:
740 reg
+= OMAP730_GPIO_INT_STATUS
;
743 #ifdef CONFIG_ARCH_OMAP850
744 case METHOD_GPIO_850
:
745 reg
+= OMAP850_GPIO_INT_STATUS
;
748 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
749 case METHOD_GPIO_24XX
:
750 reg
+= OMAP24XX_GPIO_IRQSTATUS1
;
757 __raw_writel(gpio_mask
, reg
);
759 /* Workaround for clearing DSP GPIO interrupts to allow retention */
760 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
761 reg
= bank
->base
+ OMAP24XX_GPIO_IRQSTATUS2
;
762 if (cpu_is_omap24xx() || cpu_is_omap34xx())
763 __raw_writel(gpio_mask
, reg
);
765 /* Flush posted write for the irq status to avoid spurious interrupts */
770 static inline void _clear_gpio_irqstatus(struct gpio_bank
*bank
, int gpio
)
772 _clear_gpio_irqbank(bank
, 1 << get_gpio_index(gpio
));
775 static u32
_get_gpio_irqbank_mask(struct gpio_bank
*bank
)
777 void __iomem
*reg
= bank
->base
;
782 switch (bank
->method
) {
783 #ifdef CONFIG_ARCH_OMAP1
785 reg
+= OMAP_MPUIO_GPIO_MASKIT
;
790 #ifdef CONFIG_ARCH_OMAP15XX
791 case METHOD_GPIO_1510
:
792 reg
+= OMAP1510_GPIO_INT_MASK
;
797 #ifdef CONFIG_ARCH_OMAP16XX
798 case METHOD_GPIO_1610
:
799 reg
+= OMAP1610_GPIO_IRQENABLE1
;
803 #ifdef CONFIG_ARCH_OMAP730
804 case METHOD_GPIO_730
:
805 reg
+= OMAP730_GPIO_INT_MASK
;
810 #ifdef CONFIG_ARCH_OMAP850
811 case METHOD_GPIO_850
:
812 reg
+= OMAP850_GPIO_INT_MASK
;
817 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
818 case METHOD_GPIO_24XX
:
819 reg
+= OMAP24XX_GPIO_IRQENABLE1
;
828 l
= __raw_readl(reg
);
835 static void _enable_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
, int enable
)
837 void __iomem
*reg
= bank
->base
;
840 switch (bank
->method
) {
841 #ifdef CONFIG_ARCH_OMAP1
843 reg
+= OMAP_MPUIO_GPIO_MASKIT
;
844 l
= __raw_readl(reg
);
851 #ifdef CONFIG_ARCH_OMAP15XX
852 case METHOD_GPIO_1510
:
853 reg
+= OMAP1510_GPIO_INT_MASK
;
854 l
= __raw_readl(reg
);
861 #ifdef CONFIG_ARCH_OMAP16XX
862 case METHOD_GPIO_1610
:
864 reg
+= OMAP1610_GPIO_SET_IRQENABLE1
;
866 reg
+= OMAP1610_GPIO_CLEAR_IRQENABLE1
;
870 #ifdef CONFIG_ARCH_OMAP730
871 case METHOD_GPIO_730
:
872 reg
+= OMAP730_GPIO_INT_MASK
;
873 l
= __raw_readl(reg
);
880 #ifdef CONFIG_ARCH_OMAP850
881 case METHOD_GPIO_850
:
882 reg
+= OMAP850_GPIO_INT_MASK
;
883 l
= __raw_readl(reg
);
890 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
891 case METHOD_GPIO_24XX
:
893 reg
+= OMAP24XX_GPIO_SETIRQENABLE1
;
895 reg
+= OMAP24XX_GPIO_CLEARIRQENABLE1
;
903 __raw_writel(l
, reg
);
906 static inline void _set_gpio_irqenable(struct gpio_bank
*bank
, int gpio
, int enable
)
908 _enable_gpio_irqbank(bank
, 1 << get_gpio_index(gpio
), enable
);
912 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
913 * 1510 does not seem to have a wake-up register. If JTAG is connected
914 * to the target, system will wake up always on GPIO events. While
915 * system is running all registered GPIO interrupts need to have wake-up
916 * enabled. When system is suspended, only selected GPIO interrupts need
917 * to have wake-up enabled.
919 static int _set_gpio_wakeup(struct gpio_bank
*bank
, int gpio
, int enable
)
923 switch (bank
->method
) {
924 #ifdef CONFIG_ARCH_OMAP16XX
926 case METHOD_GPIO_1610
:
927 spin_lock_irqsave(&bank
->lock
, flags
);
929 bank
->suspend_wakeup
|= (1 << gpio
);
931 bank
->suspend_wakeup
&= ~(1 << gpio
);
932 spin_unlock_irqrestore(&bank
->lock
, flags
);
935 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
936 case METHOD_GPIO_24XX
:
937 if (bank
->non_wakeup_gpios
& (1 << gpio
)) {
938 printk(KERN_ERR
"Unable to modify wakeup on "
939 "non-wakeup GPIO%d\n",
940 (bank
- gpio_bank
) * 32 + gpio
);
943 spin_lock_irqsave(&bank
->lock
, flags
);
945 bank
->suspend_wakeup
|= (1 << gpio
);
947 bank
->suspend_wakeup
&= ~(1 << gpio
);
948 spin_unlock_irqrestore(&bank
->lock
, flags
);
952 printk(KERN_ERR
"Can't enable GPIO wakeup for method %i\n",
958 static void _reset_gpio(struct gpio_bank
*bank
, int gpio
)
960 _set_gpio_direction(bank
, get_gpio_index(gpio
), 1);
961 _set_gpio_irqenable(bank
, gpio
, 0);
962 _clear_gpio_irqstatus(bank
, gpio
);
963 _set_gpio_triggering(bank
, get_gpio_index(gpio
), IRQ_TYPE_NONE
);
966 /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
967 static int gpio_wake_enable(unsigned int irq
, unsigned int enable
)
969 unsigned int gpio
= irq
- IH_GPIO_BASE
;
970 struct gpio_bank
*bank
;
973 if (check_gpio(gpio
) < 0)
975 bank
= get_irq_chip_data(irq
);
976 retval
= _set_gpio_wakeup(bank
, get_gpio_index(gpio
), enable
);
981 static int omap_gpio_request(struct gpio_chip
*chip
, unsigned offset
)
983 struct gpio_bank
*bank
= container_of(chip
, struct gpio_bank
, chip
);
986 spin_lock_irqsave(&bank
->lock
, flags
);
988 /* Set trigger to none. You need to enable the desired trigger with
989 * request_irq() or set_irq_type().
991 _set_gpio_triggering(bank
, offset
, IRQ_TYPE_NONE
);
993 #ifdef CONFIG_ARCH_OMAP15XX
994 if (bank
->method
== METHOD_GPIO_1510
) {
997 /* Claim the pin for MPU */
998 reg
= bank
->base
+ OMAP1510_GPIO_PIN_CONTROL
;
999 __raw_writel(__raw_readl(reg
) | (1 << offset
), reg
);
1002 spin_unlock_irqrestore(&bank
->lock
, flags
);
1007 static void omap_gpio_free(struct gpio_chip
*chip
, unsigned offset
)
1009 struct gpio_bank
*bank
= container_of(chip
, struct gpio_bank
, chip
);
1010 unsigned long flags
;
1012 spin_lock_irqsave(&bank
->lock
, flags
);
1013 #ifdef CONFIG_ARCH_OMAP16XX
1014 if (bank
->method
== METHOD_GPIO_1610
) {
1015 /* Disable wake-up during idle for dynamic tick */
1016 void __iomem
*reg
= bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
;
1017 __raw_writel(1 << offset
, reg
);
1020 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1021 if (bank
->method
== METHOD_GPIO_24XX
) {
1022 /* Disable wake-up during idle for dynamic tick */
1023 void __iomem
*reg
= bank
->base
+ OMAP24XX_GPIO_CLEARWKUENA
;
1024 __raw_writel(1 << offset
, reg
);
1027 _reset_gpio(bank
, bank
->chip
.base
+ offset
);
1028 spin_unlock_irqrestore(&bank
->lock
, flags
);
1032 * We need to unmask the GPIO bank interrupt as soon as possible to
1033 * avoid missing GPIO interrupts for other lines in the bank.
1034 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1035 * in the bank to avoid missing nested interrupts for a GPIO line.
1036 * If we wait to unmask individual GPIO lines in the bank after the
1037 * line's interrupt handler has been run, we may miss some nested
1040 static void gpio_irq_handler(unsigned int irq
, struct irq_desc
*desc
)
1042 void __iomem
*isr_reg
= NULL
;
1044 unsigned int gpio_irq
;
1045 struct gpio_bank
*bank
;
1049 desc
->chip
->ack(irq
);
1051 bank
= get_irq_data(irq
);
1052 #ifdef CONFIG_ARCH_OMAP1
1053 if (bank
->method
== METHOD_MPUIO
)
1054 isr_reg
= bank
->base
+ OMAP_MPUIO_GPIO_INT
;
1056 #ifdef CONFIG_ARCH_OMAP15XX
1057 if (bank
->method
== METHOD_GPIO_1510
)
1058 isr_reg
= bank
->base
+ OMAP1510_GPIO_INT_STATUS
;
1060 #if defined(CONFIG_ARCH_OMAP16XX)
1061 if (bank
->method
== METHOD_GPIO_1610
)
1062 isr_reg
= bank
->base
+ OMAP1610_GPIO_IRQSTATUS1
;
1064 #ifdef CONFIG_ARCH_OMAP730
1065 if (bank
->method
== METHOD_GPIO_730
)
1066 isr_reg
= bank
->base
+ OMAP730_GPIO_INT_STATUS
;
1068 #ifdef CONFIG_ARCH_OMAP850
1069 if (bank
->method
== METHOD_GPIO_850
)
1070 isr_reg
= bank
->base
+ OMAP850_GPIO_INT_STATUS
;
1072 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1073 if (bank
->method
== METHOD_GPIO_24XX
)
1074 isr_reg
= bank
->base
+ OMAP24XX_GPIO_IRQSTATUS1
;
1077 u32 isr_saved
, level_mask
= 0;
1080 enabled
= _get_gpio_irqbank_mask(bank
);
1081 isr_saved
= isr
= __raw_readl(isr_reg
) & enabled
;
1083 if (cpu_is_omap15xx() && (bank
->method
== METHOD_MPUIO
))
1086 if (cpu_class_is_omap2()) {
1087 level_mask
= bank
->level_mask
& enabled
;
1090 /* clear edge sensitive interrupts before handler(s) are
1091 called so that we don't miss any interrupt occurred while
1093 _enable_gpio_irqbank(bank
, isr_saved
& ~level_mask
, 0);
1094 _clear_gpio_irqbank(bank
, isr_saved
& ~level_mask
);
1095 _enable_gpio_irqbank(bank
, isr_saved
& ~level_mask
, 1);
1097 /* if there is only edge sensitive GPIO pin interrupts
1098 configured, we could unmask GPIO bank interrupt immediately */
1099 if (!level_mask
&& !unmasked
) {
1101 desc
->chip
->unmask(irq
);
1109 gpio_irq
= bank
->virtual_irq_start
;
1110 for (; isr
!= 0; isr
>>= 1, gpio_irq
++) {
1114 generic_handle_irq(gpio_irq
);
1117 /* if bank has any level sensitive GPIO pin interrupt
1118 configured, we must unmask the bank interrupt only after
1119 handler(s) are executed in order to avoid spurious bank
1122 desc
->chip
->unmask(irq
);
1126 static void gpio_irq_shutdown(unsigned int irq
)
1128 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1129 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1131 _reset_gpio(bank
, gpio
);
1134 static void gpio_ack_irq(unsigned int irq
)
1136 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1137 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1139 _clear_gpio_irqstatus(bank
, gpio
);
1142 static void gpio_mask_irq(unsigned int irq
)
1144 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1145 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1147 _set_gpio_irqenable(bank
, gpio
, 0);
1150 static void gpio_unmask_irq(unsigned int irq
)
1152 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1153 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1154 unsigned int irq_mask
= 1 << get_gpio_index(gpio
);
1156 /* For level-triggered GPIOs, the clearing must be done after
1157 * the HW source is cleared, thus after the handler has run */
1158 if (bank
->level_mask
& irq_mask
) {
1159 _set_gpio_irqenable(bank
, gpio
, 0);
1160 _clear_gpio_irqstatus(bank
, gpio
);
1163 _set_gpio_irqenable(bank
, gpio
, 1);
1166 static struct irq_chip gpio_irq_chip
= {
1168 .shutdown
= gpio_irq_shutdown
,
1169 .ack
= gpio_ack_irq
,
1170 .mask
= gpio_mask_irq
,
1171 .unmask
= gpio_unmask_irq
,
1172 .set_type
= gpio_irq_type
,
1173 .set_wake
= gpio_wake_enable
,
1176 /*---------------------------------------------------------------------*/
1178 #ifdef CONFIG_ARCH_OMAP1
1180 /* MPUIO uses the always-on 32k clock */
1182 static void mpuio_ack_irq(unsigned int irq
)
1184 /* The ISR is reset automatically, so do nothing here. */
1187 static void mpuio_mask_irq(unsigned int irq
)
1189 unsigned int gpio
= OMAP_MPUIO(irq
- IH_MPUIO_BASE
);
1190 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1192 _set_gpio_irqenable(bank
, gpio
, 0);
1195 static void mpuio_unmask_irq(unsigned int irq
)
1197 unsigned int gpio
= OMAP_MPUIO(irq
- IH_MPUIO_BASE
);
1198 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1200 _set_gpio_irqenable(bank
, gpio
, 1);
1203 static struct irq_chip mpuio_irq_chip
= {
1205 .ack
= mpuio_ack_irq
,
1206 .mask
= mpuio_mask_irq
,
1207 .unmask
= mpuio_unmask_irq
,
1208 .set_type
= gpio_irq_type
,
1209 #ifdef CONFIG_ARCH_OMAP16XX
1210 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1211 .set_wake
= gpio_wake_enable
,
1216 #define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1219 #ifdef CONFIG_ARCH_OMAP16XX
1221 #include <linux/platform_device.h>
1223 static int omap_mpuio_suspend_late(struct platform_device
*pdev
, pm_message_t mesg
)
1225 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1226 void __iomem
*mask_reg
= bank
->base
+ OMAP_MPUIO_GPIO_MASKIT
;
1227 unsigned long flags
;
1229 spin_lock_irqsave(&bank
->lock
, flags
);
1230 bank
->saved_wakeup
= __raw_readl(mask_reg
);
1231 __raw_writel(0xffff & ~bank
->suspend_wakeup
, mask_reg
);
1232 spin_unlock_irqrestore(&bank
->lock
, flags
);
1237 static int omap_mpuio_resume_early(struct platform_device
*pdev
)
1239 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1240 void __iomem
*mask_reg
= bank
->base
+ OMAP_MPUIO_GPIO_MASKIT
;
1241 unsigned long flags
;
1243 spin_lock_irqsave(&bank
->lock
, flags
);
1244 __raw_writel(bank
->saved_wakeup
, mask_reg
);
1245 spin_unlock_irqrestore(&bank
->lock
, flags
);
1250 /* use platform_driver for this, now that there's no longer any
1251 * point to sys_device (other than not disturbing old code).
1253 static struct platform_driver omap_mpuio_driver
= {
1254 .suspend_late
= omap_mpuio_suspend_late
,
1255 .resume_early
= omap_mpuio_resume_early
,
1261 static struct platform_device omap_mpuio_device
= {
1265 .driver
= &omap_mpuio_driver
.driver
,
1267 /* could list the /proc/iomem resources */
1270 static inline void mpuio_init(void)
1272 platform_set_drvdata(&omap_mpuio_device
, &gpio_bank_1610
[0]);
1274 if (platform_driver_register(&omap_mpuio_driver
) == 0)
1275 (void) platform_device_register(&omap_mpuio_device
);
1279 static inline void mpuio_init(void) {}
1284 extern struct irq_chip mpuio_irq_chip
;
1286 #define bank_is_mpuio(bank) 0
1287 static inline void mpuio_init(void) {}
1291 /*---------------------------------------------------------------------*/
1293 /* REVISIT these are stupid implementations! replace by ones that
1294 * don't switch on METHOD_* and which mostly avoid spinlocks
1297 static int gpio_input(struct gpio_chip
*chip
, unsigned offset
)
1299 struct gpio_bank
*bank
;
1300 unsigned long flags
;
1302 bank
= container_of(chip
, struct gpio_bank
, chip
);
1303 spin_lock_irqsave(&bank
->lock
, flags
);
1304 _set_gpio_direction(bank
, offset
, 1);
1305 spin_unlock_irqrestore(&bank
->lock
, flags
);
1309 static int gpio_get(struct gpio_chip
*chip
, unsigned offset
)
1311 return __omap_get_gpio_datain(chip
->base
+ offset
);
1314 static int gpio_output(struct gpio_chip
*chip
, unsigned offset
, int value
)
1316 struct gpio_bank
*bank
;
1317 unsigned long flags
;
1319 bank
= container_of(chip
, struct gpio_bank
, chip
);
1320 spin_lock_irqsave(&bank
->lock
, flags
);
1321 _set_gpio_dataout(bank
, offset
, value
);
1322 _set_gpio_direction(bank
, offset
, 0);
1323 spin_unlock_irqrestore(&bank
->lock
, flags
);
1327 static void gpio_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
1329 struct gpio_bank
*bank
;
1330 unsigned long flags
;
1332 bank
= container_of(chip
, struct gpio_bank
, chip
);
1333 spin_lock_irqsave(&bank
->lock
, flags
);
1334 _set_gpio_dataout(bank
, offset
, value
);
1335 spin_unlock_irqrestore(&bank
->lock
, flags
);
1338 static int gpio_2irq(struct gpio_chip
*chip
, unsigned offset
)
1340 struct gpio_bank
*bank
;
1342 bank
= container_of(chip
, struct gpio_bank
, chip
);
1343 return bank
->virtual_irq_start
+ offset
;
1346 /*---------------------------------------------------------------------*/
1348 static int initialized
;
1349 #if !defined(CONFIG_ARCH_OMAP3)
1350 static struct clk
* gpio_ick
;
1353 #if defined(CONFIG_ARCH_OMAP2)
1354 static struct clk
* gpio_fck
;
1357 #if defined(CONFIG_ARCH_OMAP2430)
1358 static struct clk
* gpio5_ick
;
1359 static struct clk
* gpio5_fck
;
1362 #if defined(CONFIG_ARCH_OMAP3)
1363 static struct clk
*gpio_iclks
[OMAP34XX_NR_GPIOS
];
1366 /* This lock class tells lockdep that GPIO irqs are in a different
1367 * category than their parents, so it won't report false recursion.
1369 static struct lock_class_key gpio_lock_class
;
1371 static int __init
_omap_gpio_init(void)
1375 struct gpio_bank
*bank
;
1380 #if defined(CONFIG_ARCH_OMAP1)
1381 if (cpu_is_omap15xx()) {
1382 gpio_ick
= clk_get(NULL
, "arm_gpio_ck");
1383 if (IS_ERR(gpio_ick
))
1384 printk("Could not get arm_gpio_ck\n");
1386 clk_enable(gpio_ick
);
1389 #if defined(CONFIG_ARCH_OMAP2)
1390 if (cpu_class_is_omap2()) {
1391 gpio_ick
= clk_get(NULL
, "gpios_ick");
1392 if (IS_ERR(gpio_ick
))
1393 printk("Could not get gpios_ick\n");
1395 clk_enable(gpio_ick
);
1396 gpio_fck
= clk_get(NULL
, "gpios_fck");
1397 if (IS_ERR(gpio_fck
))
1398 printk("Could not get gpios_fck\n");
1400 clk_enable(gpio_fck
);
1403 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
1405 #if defined(CONFIG_ARCH_OMAP2430)
1406 if (cpu_is_omap2430()) {
1407 gpio5_ick
= clk_get(NULL
, "gpio5_ick");
1408 if (IS_ERR(gpio5_ick
))
1409 printk("Could not get gpio5_ick\n");
1411 clk_enable(gpio5_ick
);
1412 gpio5_fck
= clk_get(NULL
, "gpio5_fck");
1413 if (IS_ERR(gpio5_fck
))
1414 printk("Could not get gpio5_fck\n");
1416 clk_enable(gpio5_fck
);
1422 #if defined(CONFIG_ARCH_OMAP3)
1423 if (cpu_is_omap34xx()) {
1424 for (i
= 0; i
< OMAP34XX_NR_GPIOS
; i
++) {
1425 sprintf(clk_name
, "gpio%d_ick", i
+ 1);
1426 gpio_iclks
[i
] = clk_get(NULL
, clk_name
);
1427 if (IS_ERR(gpio_iclks
[i
]))
1428 printk(KERN_ERR
"Could not get %s\n", clk_name
);
1430 clk_enable(gpio_iclks
[i
]);
1436 #ifdef CONFIG_ARCH_OMAP15XX
1437 if (cpu_is_omap15xx()) {
1438 printk(KERN_INFO
"OMAP1510 GPIO hardware\n");
1439 gpio_bank_count
= 2;
1440 gpio_bank
= gpio_bank_1510
;
1443 #if defined(CONFIG_ARCH_OMAP16XX)
1444 if (cpu_is_omap16xx()) {
1447 gpio_bank_count
= 5;
1448 gpio_bank
= gpio_bank_1610
;
1449 rev
= __raw_readw(gpio_bank
[1].base
+ OMAP1610_GPIO_REVISION
);
1450 printk(KERN_INFO
"OMAP GPIO hardware version %d.%d\n",
1451 (rev
>> 4) & 0x0f, rev
& 0x0f);
1454 #ifdef CONFIG_ARCH_OMAP730
1455 if (cpu_is_omap730()) {
1456 printk(KERN_INFO
"OMAP730 GPIO hardware\n");
1457 gpio_bank_count
= 7;
1458 gpio_bank
= gpio_bank_730
;
1461 #ifdef CONFIG_ARCH_OMAP850
1462 if (cpu_is_omap850()) {
1463 printk(KERN_INFO
"OMAP850 GPIO hardware\n");
1464 gpio_bank_count
= 7;
1465 gpio_bank
= gpio_bank_850
;
1469 #ifdef CONFIG_ARCH_OMAP24XX
1470 if (cpu_is_omap242x()) {
1473 gpio_bank_count
= 4;
1474 gpio_bank
= gpio_bank_242x
;
1475 rev
= __raw_readl(gpio_bank
[0].base
+ OMAP24XX_GPIO_REVISION
);
1476 printk(KERN_INFO
"OMAP242x GPIO hardware version %d.%d\n",
1477 (rev
>> 4) & 0x0f, rev
& 0x0f);
1479 if (cpu_is_omap243x()) {
1482 gpio_bank_count
= 5;
1483 gpio_bank
= gpio_bank_243x
;
1484 rev
= __raw_readl(gpio_bank
[0].base
+ OMAP24XX_GPIO_REVISION
);
1485 printk(KERN_INFO
"OMAP243x GPIO hardware version %d.%d\n",
1486 (rev
>> 4) & 0x0f, rev
& 0x0f);
1489 #ifdef CONFIG_ARCH_OMAP34XX
1490 if (cpu_is_omap34xx()) {
1493 gpio_bank_count
= OMAP34XX_NR_GPIOS
;
1494 gpio_bank
= gpio_bank_34xx
;
1495 rev
= __raw_readl(gpio_bank
[0].base
+ OMAP24XX_GPIO_REVISION
);
1496 printk(KERN_INFO
"OMAP34xx GPIO hardware version %d.%d\n",
1497 (rev
>> 4) & 0x0f, rev
& 0x0f);
1500 for (i
= 0; i
< gpio_bank_count
; i
++) {
1501 int j
, gpio_count
= 16;
1503 bank
= &gpio_bank
[i
];
1504 spin_lock_init(&bank
->lock
);
1505 if (bank_is_mpuio(bank
))
1506 __raw_writew(0xffff, bank
->base
+ OMAP_MPUIO_GPIO_MASKIT
);
1507 if (cpu_is_omap15xx() && bank
->method
== METHOD_GPIO_1510
) {
1508 __raw_writew(0xffff, bank
->base
+ OMAP1510_GPIO_INT_MASK
);
1509 __raw_writew(0x0000, bank
->base
+ OMAP1510_GPIO_INT_STATUS
);
1511 if (cpu_is_omap16xx() && bank
->method
== METHOD_GPIO_1610
) {
1512 __raw_writew(0x0000, bank
->base
+ OMAP1610_GPIO_IRQENABLE1
);
1513 __raw_writew(0xffff, bank
->base
+ OMAP1610_GPIO_IRQSTATUS1
);
1514 __raw_writew(0x0014, bank
->base
+ OMAP1610_GPIO_SYSCONFIG
);
1516 if (cpu_is_omap7xx() && bank
->method
== METHOD_GPIO_730
) {
1517 __raw_writel(0xffffffff, bank
->base
+ OMAP730_GPIO_INT_MASK
);
1518 __raw_writel(0x00000000, bank
->base
+ OMAP730_GPIO_INT_STATUS
);
1520 gpio_count
= 32; /* 730 has 32-bit GPIOs */
1523 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1524 if (bank
->method
== METHOD_GPIO_24XX
) {
1525 static const u32 non_wakeup_gpios
[] = {
1526 0xe203ffc0, 0x08700040
1529 __raw_writel(0x00000000, bank
->base
+ OMAP24XX_GPIO_IRQENABLE1
);
1530 __raw_writel(0xffffffff, bank
->base
+ OMAP24XX_GPIO_IRQSTATUS1
);
1531 __raw_writew(0x0015, bank
->base
+ OMAP24XX_GPIO_SYSCONFIG
);
1533 /* Initialize interface clock ungated, module enabled */
1534 __raw_writel(0, bank
->base
+ OMAP24XX_GPIO_CTRL
);
1535 if (i
< ARRAY_SIZE(non_wakeup_gpios
))
1536 bank
->non_wakeup_gpios
= non_wakeup_gpios
[i
];
1541 /* REVISIT eventually switch from OMAP-specific gpio structs
1542 * over to the generic ones
1544 bank
->chip
.request
= omap_gpio_request
;
1545 bank
->chip
.free
= omap_gpio_free
;
1546 bank
->chip
.direction_input
= gpio_input
;
1547 bank
->chip
.get
= gpio_get
;
1548 bank
->chip
.direction_output
= gpio_output
;
1549 bank
->chip
.set
= gpio_set
;
1550 bank
->chip
.to_irq
= gpio_2irq
;
1551 if (bank_is_mpuio(bank
)) {
1552 bank
->chip
.label
= "mpuio";
1553 #ifdef CONFIG_ARCH_OMAP16XX
1554 bank
->chip
.dev
= &omap_mpuio_device
.dev
;
1556 bank
->chip
.base
= OMAP_MPUIO(0);
1558 bank
->chip
.label
= "gpio";
1559 bank
->chip
.base
= gpio
;
1562 bank
->chip
.ngpio
= gpio_count
;
1564 gpiochip_add(&bank
->chip
);
1566 for (j
= bank
->virtual_irq_start
;
1567 j
< bank
->virtual_irq_start
+ gpio_count
; j
++) {
1568 lockdep_set_class(&irq_desc
[j
].lock
, &gpio_lock_class
);
1569 set_irq_chip_data(j
, bank
);
1570 if (bank_is_mpuio(bank
))
1571 set_irq_chip(j
, &mpuio_irq_chip
);
1573 set_irq_chip(j
, &gpio_irq_chip
);
1574 set_irq_handler(j
, handle_simple_irq
);
1575 set_irq_flags(j
, IRQF_VALID
);
1577 set_irq_chained_handler(bank
->irq
, gpio_irq_handler
);
1578 set_irq_data(bank
->irq
, bank
);
1580 if (cpu_is_omap34xx()) {
1581 sprintf(clk_name
, "gpio%d_dbck", i
+ 1);
1582 bank
->dbck
= clk_get(NULL
, clk_name
);
1583 if (IS_ERR(bank
->dbck
))
1584 printk(KERN_ERR
"Could not get %s\n", clk_name
);
1588 /* Enable system clock for GPIO module.
1589 * The CAM_CLK_CTRL *is* really the right place. */
1590 if (cpu_is_omap16xx())
1591 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL
) | 0x04, ULPD_CAM_CLK_CTRL
);
1593 /* Enable autoidle for the OCP interface */
1594 if (cpu_is_omap24xx())
1595 omap_writel(1 << 0, 0x48019010);
1596 if (cpu_is_omap34xx())
1597 omap_writel(1 << 0, 0x48306814);
1602 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1603 static int omap_gpio_suspend(struct sys_device
*dev
, pm_message_t mesg
)
1607 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
1610 for (i
= 0; i
< gpio_bank_count
; i
++) {
1611 struct gpio_bank
*bank
= &gpio_bank
[i
];
1612 void __iomem
*wake_status
;
1613 void __iomem
*wake_clear
;
1614 void __iomem
*wake_set
;
1615 unsigned long flags
;
1617 switch (bank
->method
) {
1618 #ifdef CONFIG_ARCH_OMAP16XX
1619 case METHOD_GPIO_1610
:
1620 wake_status
= bank
->base
+ OMAP1610_GPIO_WAKEUPENABLE
;
1621 wake_clear
= bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
;
1622 wake_set
= bank
->base
+ OMAP1610_GPIO_SET_WAKEUPENA
;
1625 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1626 case METHOD_GPIO_24XX
:
1627 wake_status
= bank
->base
+ OMAP24XX_GPIO_WAKE_EN
;
1628 wake_clear
= bank
->base
+ OMAP24XX_GPIO_CLEARWKUENA
;
1629 wake_set
= bank
->base
+ OMAP24XX_GPIO_SETWKUENA
;
1636 spin_lock_irqsave(&bank
->lock
, flags
);
1637 bank
->saved_wakeup
= __raw_readl(wake_status
);
1638 __raw_writel(0xffffffff, wake_clear
);
1639 __raw_writel(bank
->suspend_wakeup
, wake_set
);
1640 spin_unlock_irqrestore(&bank
->lock
, flags
);
1646 static int omap_gpio_resume(struct sys_device
*dev
)
1650 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
1653 for (i
= 0; i
< gpio_bank_count
; i
++) {
1654 struct gpio_bank
*bank
= &gpio_bank
[i
];
1655 void __iomem
*wake_clear
;
1656 void __iomem
*wake_set
;
1657 unsigned long flags
;
1659 switch (bank
->method
) {
1660 #ifdef CONFIG_ARCH_OMAP16XX
1661 case METHOD_GPIO_1610
:
1662 wake_clear
= bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
;
1663 wake_set
= bank
->base
+ OMAP1610_GPIO_SET_WAKEUPENA
;
1666 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1667 case METHOD_GPIO_24XX
:
1668 wake_clear
= bank
->base
+ OMAP24XX_GPIO_CLEARWKUENA
;
1669 wake_set
= bank
->base
+ OMAP24XX_GPIO_SETWKUENA
;
1676 spin_lock_irqsave(&bank
->lock
, flags
);
1677 __raw_writel(0xffffffff, wake_clear
);
1678 __raw_writel(bank
->saved_wakeup
, wake_set
);
1679 spin_unlock_irqrestore(&bank
->lock
, flags
);
1685 static struct sysdev_class omap_gpio_sysclass
= {
1687 .suspend
= omap_gpio_suspend
,
1688 .resume
= omap_gpio_resume
,
1691 static struct sys_device omap_gpio_device
= {
1693 .cls
= &omap_gpio_sysclass
,
1698 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1700 static int workaround_enabled
;
1702 void omap2_gpio_prepare_for_retention(void)
1706 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
1707 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
1708 for (i
= 0; i
< gpio_bank_count
; i
++) {
1709 struct gpio_bank
*bank
= &gpio_bank
[i
];
1712 if (!(bank
->enabled_non_wakeup_gpios
))
1714 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1715 bank
->saved_datain
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_DATAIN
);
1716 l1
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
1717 l2
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
1719 bank
->saved_fallingdetect
= l1
;
1720 bank
->saved_risingdetect
= l2
;
1721 l1
&= ~bank
->enabled_non_wakeup_gpios
;
1722 l2
&= ~bank
->enabled_non_wakeup_gpios
;
1723 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1724 __raw_writel(l1
, bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
1725 __raw_writel(l2
, bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
1730 workaround_enabled
= 0;
1733 workaround_enabled
= 1;
1736 void omap2_gpio_resume_after_retention(void)
1740 if (!workaround_enabled
)
1742 for (i
= 0; i
< gpio_bank_count
; i
++) {
1743 struct gpio_bank
*bank
= &gpio_bank
[i
];
1746 if (!(bank
->enabled_non_wakeup_gpios
))
1748 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1749 __raw_writel(bank
->saved_fallingdetect
,
1750 bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
1751 __raw_writel(bank
->saved_risingdetect
,
1752 bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
1754 /* Check if any of the non-wakeup interrupt GPIOs have changed
1755 * state. If so, generate an IRQ by software. This is
1756 * horribly racy, but it's the best we can do to work around
1757 * this silicon bug. */
1758 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1759 l
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_DATAIN
);
1761 l
^= bank
->saved_datain
;
1762 l
&= bank
->non_wakeup_gpios
;
1765 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1766 old0
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
1767 old1
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
1768 __raw_writel(old0
| l
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
1769 __raw_writel(old1
| l
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
1770 __raw_writel(old0
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
1771 __raw_writel(old1
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
1781 * This may get called early from board specific init
1782 * for boards that have interrupts routed via FPGA.
1784 int __init
omap_gpio_init(void)
1787 return _omap_gpio_init();
1792 static int __init
omap_gpio_sysinit(void)
1797 ret
= _omap_gpio_init();
1801 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1802 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
1804 ret
= sysdev_class_register(&omap_gpio_sysclass
);
1806 ret
= sysdev_register(&omap_gpio_device
);
1814 arch_initcall(omap_gpio_sysinit
);
1817 #ifdef CONFIG_DEBUG_FS
1819 #include <linux/debugfs.h>
1820 #include <linux/seq_file.h>
1822 static int gpio_is_input(struct gpio_bank
*bank
, int mask
)
1824 void __iomem
*reg
= bank
->base
;
1826 switch (bank
->method
) {
1828 reg
+= OMAP_MPUIO_IO_CNTL
;
1830 case METHOD_GPIO_1510
:
1831 reg
+= OMAP1510_GPIO_DIR_CONTROL
;
1833 case METHOD_GPIO_1610
:
1834 reg
+= OMAP1610_GPIO_DIRECTION
;
1836 case METHOD_GPIO_730
:
1837 reg
+= OMAP730_GPIO_DIR_CONTROL
;
1839 case METHOD_GPIO_850
:
1840 reg
+= OMAP850_GPIO_DIR_CONTROL
;
1842 case METHOD_GPIO_24XX
:
1843 reg
+= OMAP24XX_GPIO_OE
;
1846 return __raw_readl(reg
) & mask
;
1850 static int dbg_gpio_show(struct seq_file
*s
, void *unused
)
1852 unsigned i
, j
, gpio
;
1854 for (i
= 0, gpio
= 0; i
< gpio_bank_count
; i
++) {
1855 struct gpio_bank
*bank
= gpio_bank
+ i
;
1856 unsigned bankwidth
= 16;
1859 if (bank_is_mpuio(bank
))
1860 gpio
= OMAP_MPUIO(0);
1861 else if (cpu_class_is_omap2() || cpu_is_omap730() ||
1865 for (j
= 0; j
< bankwidth
; j
++, gpio
++, mask
<<= 1) {
1866 unsigned irq
, value
, is_in
, irqstat
;
1869 label
= gpiochip_is_requested(&bank
->chip
, j
);
1873 irq
= bank
->virtual_irq_start
+ j
;
1874 value
= gpio_get_value(gpio
);
1875 is_in
= gpio_is_input(bank
, mask
);
1877 if (bank_is_mpuio(bank
))
1878 seq_printf(s
, "MPUIO %2d ", j
);
1880 seq_printf(s
, "GPIO %3d ", gpio
);
1881 seq_printf(s
, "(%-20.20s): %s %s",
1883 is_in
? "in " : "out",
1884 value
? "hi" : "lo");
1886 /* FIXME for at least omap2, show pullup/pulldown state */
1888 irqstat
= irq_desc
[irq
].status
;
1889 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1890 defined(CONFIG_ARCH_OMAP34XX)
1891 if (is_in
&& ((bank
->suspend_wakeup
& mask
)
1892 || irqstat
& IRQ_TYPE_SENSE_MASK
)) {
1893 char *trigger
= NULL
;
1895 switch (irqstat
& IRQ_TYPE_SENSE_MASK
) {
1896 case IRQ_TYPE_EDGE_FALLING
:
1897 trigger
= "falling";
1899 case IRQ_TYPE_EDGE_RISING
:
1902 case IRQ_TYPE_EDGE_BOTH
:
1903 trigger
= "bothedge";
1905 case IRQ_TYPE_LEVEL_LOW
:
1908 case IRQ_TYPE_LEVEL_HIGH
:
1915 seq_printf(s
, ", irq-%d %-8s%s",
1917 (bank
->suspend_wakeup
& mask
)
1921 seq_printf(s
, "\n");
1924 if (bank_is_mpuio(bank
)) {
1925 seq_printf(s
, "\n");
1932 static int dbg_gpio_open(struct inode
*inode
, struct file
*file
)
1934 return single_open(file
, dbg_gpio_show
, &inode
->i_private
);
1937 static const struct file_operations debug_fops
= {
1938 .open
= dbg_gpio_open
,
1940 .llseek
= seq_lseek
,
1941 .release
= single_release
,
1944 static int __init
omap_gpio_debuginit(void)
1946 (void) debugfs_create_file("omap_gpio", S_IRUGO
,
1947 NULL
, NULL
, &debug_fops
);
1950 late_initcall(omap_gpio_debuginit
);