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>
21 #include <asm/hardware.h>
23 #include <asm/arch/irqs.h>
24 #include <asm/arch/gpio.h>
25 #include <asm/mach/irq.h>
30 * OMAP1510 GPIO registers
32 #define OMAP1510_GPIO_BASE (void __iomem *)0xfffce000
33 #define OMAP1510_GPIO_DATA_INPUT 0x00
34 #define OMAP1510_GPIO_DATA_OUTPUT 0x04
35 #define OMAP1510_GPIO_DIR_CONTROL 0x08
36 #define OMAP1510_GPIO_INT_CONTROL 0x0c
37 #define OMAP1510_GPIO_INT_MASK 0x10
38 #define OMAP1510_GPIO_INT_STATUS 0x14
39 #define OMAP1510_GPIO_PIN_CONTROL 0x18
41 #define OMAP1510_IH_GPIO_BASE 64
44 * OMAP1610 specific GPIO registers
46 #define OMAP1610_GPIO1_BASE (void __iomem *)0xfffbe400
47 #define OMAP1610_GPIO2_BASE (void __iomem *)0xfffbec00
48 #define OMAP1610_GPIO3_BASE (void __iomem *)0xfffbb400
49 #define OMAP1610_GPIO4_BASE (void __iomem *)0xfffbbc00
50 #define OMAP1610_GPIO_REVISION 0x0000
51 #define OMAP1610_GPIO_SYSCONFIG 0x0010
52 #define OMAP1610_GPIO_SYSSTATUS 0x0014
53 #define OMAP1610_GPIO_IRQSTATUS1 0x0018
54 #define OMAP1610_GPIO_IRQENABLE1 0x001c
55 #define OMAP1610_GPIO_WAKEUPENABLE 0x0028
56 #define OMAP1610_GPIO_DATAIN 0x002c
57 #define OMAP1610_GPIO_DATAOUT 0x0030
58 #define OMAP1610_GPIO_DIRECTION 0x0034
59 #define OMAP1610_GPIO_EDGE_CTRL1 0x0038
60 #define OMAP1610_GPIO_EDGE_CTRL2 0x003c
61 #define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
62 #define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
63 #define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
64 #define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
65 #define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
66 #define OMAP1610_GPIO_SET_DATAOUT 0x00f0
69 * OMAP730 specific GPIO registers
71 #define OMAP730_GPIO1_BASE (void __iomem *)0xfffbc000
72 #define OMAP730_GPIO2_BASE (void __iomem *)0xfffbc800
73 #define OMAP730_GPIO3_BASE (void __iomem *)0xfffbd000
74 #define OMAP730_GPIO4_BASE (void __iomem *)0xfffbd800
75 #define OMAP730_GPIO5_BASE (void __iomem *)0xfffbe000
76 #define OMAP730_GPIO6_BASE (void __iomem *)0xfffbe800
77 #define OMAP730_GPIO_DATA_INPUT 0x00
78 #define OMAP730_GPIO_DATA_OUTPUT 0x04
79 #define OMAP730_GPIO_DIR_CONTROL 0x08
80 #define OMAP730_GPIO_INT_CONTROL 0x0c
81 #define OMAP730_GPIO_INT_MASK 0x10
82 #define OMAP730_GPIO_INT_STATUS 0x14
85 * omap24xx specific GPIO registers
87 #define OMAP242X_GPIO1_BASE (void __iomem *)0x48018000
88 #define OMAP242X_GPIO2_BASE (void __iomem *)0x4801a000
89 #define OMAP242X_GPIO3_BASE (void __iomem *)0x4801c000
90 #define OMAP242X_GPIO4_BASE (void __iomem *)0x4801e000
92 #define OMAP243X_GPIO1_BASE (void __iomem *)0x4900C000
93 #define OMAP243X_GPIO2_BASE (void __iomem *)0x4900E000
94 #define OMAP243X_GPIO3_BASE (void __iomem *)0x49010000
95 #define OMAP243X_GPIO4_BASE (void __iomem *)0x49012000
96 #define OMAP243X_GPIO5_BASE (void __iomem *)0x480B6000
98 #define OMAP24XX_GPIO_REVISION 0x0000
99 #define OMAP24XX_GPIO_SYSCONFIG 0x0010
100 #define OMAP24XX_GPIO_SYSSTATUS 0x0014
101 #define OMAP24XX_GPIO_IRQSTATUS1 0x0018
102 #define OMAP24XX_GPIO_IRQSTATUS2 0x0028
103 #define OMAP24XX_GPIO_IRQENABLE2 0x002c
104 #define OMAP24XX_GPIO_IRQENABLE1 0x001c
105 #define OMAP24XX_GPIO_CTRL 0x0030
106 #define OMAP24XX_GPIO_OE 0x0034
107 #define OMAP24XX_GPIO_DATAIN 0x0038
108 #define OMAP24XX_GPIO_DATAOUT 0x003c
109 #define OMAP24XX_GPIO_LEVELDETECT0 0x0040
110 #define OMAP24XX_GPIO_LEVELDETECT1 0x0044
111 #define OMAP24XX_GPIO_RISINGDETECT 0x0048
112 #define OMAP24XX_GPIO_FALLINGDETECT 0x004c
113 #define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
114 #define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
115 #define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
116 #define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
117 #define OMAP24XX_GPIO_CLEARWKUENA 0x0080
118 #define OMAP24XX_GPIO_SETWKUENA 0x0084
119 #define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
120 #define OMAP24XX_GPIO_SETDATAOUT 0x0094
123 * omap34xx specific GPIO registers
126 #define OMAP34XX_GPIO1_BASE (void __iomem *)0x48310000
127 #define OMAP34XX_GPIO2_BASE (void __iomem *)0x49050000
128 #define OMAP34XX_GPIO3_BASE (void __iomem *)0x49052000
129 #define OMAP34XX_GPIO4_BASE (void __iomem *)0x49054000
130 #define OMAP34XX_GPIO5_BASE (void __iomem *)0x49056000
131 #define OMAP34XX_GPIO6_BASE (void __iomem *)0x49058000
137 u16 virtual_irq_start
;
139 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
143 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
144 u32 non_wakeup_gpios
;
145 u32 enabled_non_wakeup_gpios
;
148 u32 saved_fallingdetect
;
149 u32 saved_risingdetect
;
153 struct gpio_chip chip
;
156 #define METHOD_MPUIO 0
157 #define METHOD_GPIO_1510 1
158 #define METHOD_GPIO_1610 2
159 #define METHOD_GPIO_730 3
160 #define METHOD_GPIO_24XX 4
162 #ifdef CONFIG_ARCH_OMAP16XX
163 static struct gpio_bank gpio_bank_1610
[5] = {
164 { OMAP_MPUIO_BASE
, INT_MPUIO
, IH_MPUIO_BASE
, METHOD_MPUIO
},
165 { OMAP1610_GPIO1_BASE
, INT_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_1610
},
166 { OMAP1610_GPIO2_BASE
, INT_1610_GPIO_BANK2
, IH_GPIO_BASE
+ 16, METHOD_GPIO_1610
},
167 { OMAP1610_GPIO3_BASE
, INT_1610_GPIO_BANK3
, IH_GPIO_BASE
+ 32, METHOD_GPIO_1610
},
168 { OMAP1610_GPIO4_BASE
, INT_1610_GPIO_BANK4
, IH_GPIO_BASE
+ 48, METHOD_GPIO_1610
},
172 #ifdef CONFIG_ARCH_OMAP15XX
173 static struct gpio_bank gpio_bank_1510
[2] = {
174 { OMAP_MPUIO_BASE
, INT_MPUIO
, IH_MPUIO_BASE
, METHOD_MPUIO
},
175 { OMAP1510_GPIO_BASE
, INT_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_1510
}
179 #ifdef CONFIG_ARCH_OMAP730
180 static struct gpio_bank gpio_bank_730
[7] = {
181 { OMAP_MPUIO_BASE
, INT_730_MPUIO
, IH_MPUIO_BASE
, METHOD_MPUIO
},
182 { OMAP730_GPIO1_BASE
, INT_730_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_730
},
183 { OMAP730_GPIO2_BASE
, INT_730_GPIO_BANK2
, IH_GPIO_BASE
+ 32, METHOD_GPIO_730
},
184 { OMAP730_GPIO3_BASE
, INT_730_GPIO_BANK3
, IH_GPIO_BASE
+ 64, METHOD_GPIO_730
},
185 { OMAP730_GPIO4_BASE
, INT_730_GPIO_BANK4
, IH_GPIO_BASE
+ 96, METHOD_GPIO_730
},
186 { OMAP730_GPIO5_BASE
, INT_730_GPIO_BANK5
, IH_GPIO_BASE
+ 128, METHOD_GPIO_730
},
187 { OMAP730_GPIO6_BASE
, INT_730_GPIO_BANK6
, IH_GPIO_BASE
+ 160, METHOD_GPIO_730
},
191 #ifdef CONFIG_ARCH_OMAP24XX
193 static struct gpio_bank gpio_bank_242x
[4] = {
194 { OMAP242X_GPIO1_BASE
, INT_24XX_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_24XX
},
195 { OMAP242X_GPIO2_BASE
, INT_24XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32, METHOD_GPIO_24XX
},
196 { OMAP242X_GPIO3_BASE
, INT_24XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64, METHOD_GPIO_24XX
},
197 { OMAP242X_GPIO4_BASE
, INT_24XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96, METHOD_GPIO_24XX
},
200 static struct gpio_bank gpio_bank_243x
[5] = {
201 { OMAP243X_GPIO1_BASE
, INT_24XX_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_24XX
},
202 { OMAP243X_GPIO2_BASE
, INT_24XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32, METHOD_GPIO_24XX
},
203 { OMAP243X_GPIO3_BASE
, INT_24XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64, METHOD_GPIO_24XX
},
204 { OMAP243X_GPIO4_BASE
, INT_24XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96, METHOD_GPIO_24XX
},
205 { OMAP243X_GPIO5_BASE
, INT_24XX_GPIO_BANK5
, IH_GPIO_BASE
+ 128, METHOD_GPIO_24XX
},
210 #ifdef CONFIG_ARCH_OMAP34XX
211 static struct gpio_bank gpio_bank_34xx
[6] = {
212 { OMAP34XX_GPIO1_BASE
, INT_34XX_GPIO_BANK1
, IH_GPIO_BASE
, METHOD_GPIO_24XX
},
213 { OMAP34XX_GPIO2_BASE
, INT_34XX_GPIO_BANK2
, IH_GPIO_BASE
+ 32, METHOD_GPIO_24XX
},
214 { OMAP34XX_GPIO3_BASE
, INT_34XX_GPIO_BANK3
, IH_GPIO_BASE
+ 64, METHOD_GPIO_24XX
},
215 { OMAP34XX_GPIO4_BASE
, INT_34XX_GPIO_BANK4
, IH_GPIO_BASE
+ 96, METHOD_GPIO_24XX
},
216 { OMAP34XX_GPIO5_BASE
, INT_34XX_GPIO_BANK5
, IH_GPIO_BASE
+ 128, METHOD_GPIO_24XX
},
217 { OMAP34XX_GPIO6_BASE
, INT_34XX_GPIO_BANK6
, IH_GPIO_BASE
+ 160, METHOD_GPIO_24XX
},
222 static struct gpio_bank
*gpio_bank
;
223 static int gpio_bank_count
;
225 static inline struct gpio_bank
*get_gpio_bank(int gpio
)
227 if (cpu_is_omap15xx()) {
228 if (OMAP_GPIO_IS_MPUIO(gpio
))
229 return &gpio_bank
[0];
230 return &gpio_bank
[1];
232 if (cpu_is_omap16xx()) {
233 if (OMAP_GPIO_IS_MPUIO(gpio
))
234 return &gpio_bank
[0];
235 return &gpio_bank
[1 + (gpio
>> 4)];
237 if (cpu_is_omap730()) {
238 if (OMAP_GPIO_IS_MPUIO(gpio
))
239 return &gpio_bank
[0];
240 return &gpio_bank
[1 + (gpio
>> 5)];
242 if (cpu_is_omap24xx())
243 return &gpio_bank
[gpio
>> 5];
244 if (cpu_is_omap34xx())
245 return &gpio_bank
[gpio
>> 5];
248 static inline int get_gpio_index(int gpio
)
250 if (cpu_is_omap730())
252 if (cpu_is_omap24xx())
254 if (cpu_is_omap34xx())
259 static inline int gpio_valid(int gpio
)
263 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio
)) {
264 if (gpio
>= OMAP_MAX_GPIO_LINES
+ 16)
268 if (cpu_is_omap15xx() && gpio
< 16)
270 if ((cpu_is_omap16xx()) && gpio
< 64)
272 if (cpu_is_omap730() && gpio
< 192)
274 if (cpu_is_omap24xx() && gpio
< 128)
276 if (cpu_is_omap34xx() && gpio
< 160)
281 static int check_gpio(int gpio
)
283 if (unlikely(gpio_valid(gpio
)) < 0) {
284 printk(KERN_ERR
"omap-gpio: invalid GPIO %d\n", gpio
);
291 static void _set_gpio_direction(struct gpio_bank
*bank
, int gpio
, int is_input
)
293 void __iomem
*reg
= bank
->base
;
296 switch (bank
->method
) {
297 #ifdef CONFIG_ARCH_OMAP1
299 reg
+= OMAP_MPUIO_IO_CNTL
;
302 #ifdef CONFIG_ARCH_OMAP15XX
303 case METHOD_GPIO_1510
:
304 reg
+= OMAP1510_GPIO_DIR_CONTROL
;
307 #ifdef CONFIG_ARCH_OMAP16XX
308 case METHOD_GPIO_1610
:
309 reg
+= OMAP1610_GPIO_DIRECTION
;
312 #ifdef CONFIG_ARCH_OMAP730
313 case METHOD_GPIO_730
:
314 reg
+= OMAP730_GPIO_DIR_CONTROL
;
317 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
318 case METHOD_GPIO_24XX
:
319 reg
+= OMAP24XX_GPIO_OE
;
326 l
= __raw_readl(reg
);
331 __raw_writel(l
, reg
);
334 void omap_set_gpio_direction(int gpio
, int is_input
)
336 struct gpio_bank
*bank
;
339 if (check_gpio(gpio
) < 0)
341 bank
= get_gpio_bank(gpio
);
342 spin_lock_irqsave(&bank
->lock
, flags
);
343 _set_gpio_direction(bank
, get_gpio_index(gpio
), is_input
);
344 spin_unlock_irqrestore(&bank
->lock
, flags
);
347 static void _set_gpio_dataout(struct gpio_bank
*bank
, int gpio
, int enable
)
349 void __iomem
*reg
= bank
->base
;
352 switch (bank
->method
) {
353 #ifdef CONFIG_ARCH_OMAP1
355 reg
+= OMAP_MPUIO_OUTPUT
;
356 l
= __raw_readl(reg
);
363 #ifdef CONFIG_ARCH_OMAP15XX
364 case METHOD_GPIO_1510
:
365 reg
+= OMAP1510_GPIO_DATA_OUTPUT
;
366 l
= __raw_readl(reg
);
373 #ifdef CONFIG_ARCH_OMAP16XX
374 case METHOD_GPIO_1610
:
376 reg
+= OMAP1610_GPIO_SET_DATAOUT
;
378 reg
+= OMAP1610_GPIO_CLEAR_DATAOUT
;
382 #ifdef CONFIG_ARCH_OMAP730
383 case METHOD_GPIO_730
:
384 reg
+= OMAP730_GPIO_DATA_OUTPUT
;
385 l
= __raw_readl(reg
);
392 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
393 case METHOD_GPIO_24XX
:
395 reg
+= OMAP24XX_GPIO_SETDATAOUT
;
397 reg
+= OMAP24XX_GPIO_CLEARDATAOUT
;
405 __raw_writel(l
, reg
);
408 void omap_set_gpio_dataout(int gpio
, int enable
)
410 struct gpio_bank
*bank
;
413 if (check_gpio(gpio
) < 0)
415 bank
= get_gpio_bank(gpio
);
416 spin_lock_irqsave(&bank
->lock
, flags
);
417 _set_gpio_dataout(bank
, get_gpio_index(gpio
), enable
);
418 spin_unlock_irqrestore(&bank
->lock
, flags
);
421 int omap_get_gpio_datain(int gpio
)
423 struct gpio_bank
*bank
;
426 if (check_gpio(gpio
) < 0)
428 bank
= get_gpio_bank(gpio
);
430 switch (bank
->method
) {
431 #ifdef CONFIG_ARCH_OMAP1
433 reg
+= OMAP_MPUIO_INPUT_LATCH
;
436 #ifdef CONFIG_ARCH_OMAP15XX
437 case METHOD_GPIO_1510
:
438 reg
+= OMAP1510_GPIO_DATA_INPUT
;
441 #ifdef CONFIG_ARCH_OMAP16XX
442 case METHOD_GPIO_1610
:
443 reg
+= OMAP1610_GPIO_DATAIN
;
446 #ifdef CONFIG_ARCH_OMAP730
447 case METHOD_GPIO_730
:
448 reg
+= OMAP730_GPIO_DATA_INPUT
;
451 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
452 case METHOD_GPIO_24XX
:
453 reg
+= OMAP24XX_GPIO_DATAIN
;
459 return (__raw_readl(reg
)
460 & (1 << get_gpio_index(gpio
))) != 0;
463 #define MOD_REG_BIT(reg, bit_mask, set) \
465 int l = __raw_readl(base + reg); \
466 if (set) l |= bit_mask; \
467 else l &= ~bit_mask; \
468 __raw_writel(l, base + reg); \
471 void omap_set_gpio_debounce(int gpio
, int enable
)
473 struct gpio_bank
*bank
;
475 u32 val
, l
= 1 << get_gpio_index(gpio
);
477 if (cpu_class_is_omap1())
480 bank
= get_gpio_bank(gpio
);
483 reg
+= OMAP24XX_GPIO_DEBOUNCE_EN
;
484 val
= __raw_readl(reg
);
491 __raw_writel(val
, reg
);
493 EXPORT_SYMBOL(omap_set_gpio_debounce
);
495 void omap_set_gpio_debounce_time(int gpio
, int enc_time
)
497 struct gpio_bank
*bank
;
500 if (cpu_class_is_omap1())
503 bank
= get_gpio_bank(gpio
);
507 reg
+= OMAP24XX_GPIO_DEBOUNCE_VAL
;
508 __raw_writel(enc_time
, reg
);
510 EXPORT_SYMBOL(omap_set_gpio_debounce_time
);
512 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
513 static inline void set_24xx_gpio_triggering(struct gpio_bank
*bank
, int gpio
,
516 void __iomem
*base
= bank
->base
;
517 u32 gpio_bit
= 1 << gpio
;
519 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0
, gpio_bit
,
520 trigger
& __IRQT_LOWLVL
);
521 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1
, gpio_bit
,
522 trigger
& __IRQT_HIGHLVL
);
523 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT
, gpio_bit
,
524 trigger
& __IRQT_RISEDGE
);
525 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT
, gpio_bit
,
526 trigger
& __IRQT_FALEDGE
);
528 if (likely(!(bank
->non_wakeup_gpios
& gpio_bit
))) {
530 __raw_writel(1 << gpio
, bank
->base
531 + OMAP24XX_GPIO_SETWKUENA
);
533 __raw_writel(1 << gpio
, bank
->base
534 + OMAP24XX_GPIO_CLEARWKUENA
);
537 bank
->enabled_non_wakeup_gpios
|= gpio_bit
;
539 bank
->enabled_non_wakeup_gpios
&= ~gpio_bit
;
543 __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
) |
544 __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
546 * FIXME: Possibly do 'set_irq_handler(j, handle_level_irq)' if only
547 * level triggering requested.
552 static int _set_gpio_triggering(struct gpio_bank
*bank
, int gpio
, int trigger
)
554 void __iomem
*reg
= bank
->base
;
557 switch (bank
->method
) {
558 #ifdef CONFIG_ARCH_OMAP1
560 reg
+= OMAP_MPUIO_GPIO_INT_EDGE
;
561 l
= __raw_readl(reg
);
562 if (trigger
& __IRQT_RISEDGE
)
564 else if (trigger
& __IRQT_FALEDGE
)
570 #ifdef CONFIG_ARCH_OMAP15XX
571 case METHOD_GPIO_1510
:
572 reg
+= OMAP1510_GPIO_INT_CONTROL
;
573 l
= __raw_readl(reg
);
574 if (trigger
& __IRQT_RISEDGE
)
576 else if (trigger
& __IRQT_FALEDGE
)
582 #ifdef CONFIG_ARCH_OMAP16XX
583 case METHOD_GPIO_1610
:
585 reg
+= OMAP1610_GPIO_EDGE_CTRL2
;
587 reg
+= OMAP1610_GPIO_EDGE_CTRL1
;
589 l
= __raw_readl(reg
);
590 l
&= ~(3 << (gpio
<< 1));
591 if (trigger
& __IRQT_RISEDGE
)
592 l
|= 2 << (gpio
<< 1);
593 if (trigger
& __IRQT_FALEDGE
)
594 l
|= 1 << (gpio
<< 1);
596 /* Enable wake-up during idle for dynamic tick */
597 __raw_writel(1 << gpio
, bank
->base
+ OMAP1610_GPIO_SET_WAKEUPENA
);
599 __raw_writel(1 << gpio
, bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
);
602 #ifdef CONFIG_ARCH_OMAP730
603 case METHOD_GPIO_730
:
604 reg
+= OMAP730_GPIO_INT_CONTROL
;
605 l
= __raw_readl(reg
);
606 if (trigger
& __IRQT_RISEDGE
)
608 else if (trigger
& __IRQT_FALEDGE
)
614 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
615 case METHOD_GPIO_24XX
:
616 set_24xx_gpio_triggering(bank
, gpio
, trigger
);
622 __raw_writel(l
, reg
);
628 static int gpio_irq_type(unsigned irq
, unsigned type
)
630 struct gpio_bank
*bank
;
635 if (!cpu_class_is_omap2() && irq
> IH_MPUIO_BASE
)
636 gpio
= OMAP_MPUIO(irq
- IH_MPUIO_BASE
);
638 gpio
= irq
- IH_GPIO_BASE
;
640 if (check_gpio(gpio
) < 0)
643 if (type
& ~IRQ_TYPE_SENSE_MASK
)
646 /* OMAP1 allows only only edge triggering */
647 if (!cpu_class_is_omap2()
648 && (type
& (IRQ_TYPE_LEVEL_LOW
|IRQ_TYPE_LEVEL_HIGH
)))
651 bank
= get_irq_chip_data(irq
);
652 spin_lock_irqsave(&bank
->lock
, flags
);
653 retval
= _set_gpio_triggering(bank
, get_gpio_index(gpio
), type
);
655 irq_desc
[irq
].status
&= ~IRQ_TYPE_SENSE_MASK
;
656 irq_desc
[irq
].status
|= type
;
658 spin_unlock_irqrestore(&bank
->lock
, flags
);
662 static void _clear_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
)
664 void __iomem
*reg
= bank
->base
;
666 switch (bank
->method
) {
667 #ifdef CONFIG_ARCH_OMAP1
669 /* MPUIO irqstatus is reset by reading the status register,
670 * so do nothing here */
673 #ifdef CONFIG_ARCH_OMAP15XX
674 case METHOD_GPIO_1510
:
675 reg
+= OMAP1510_GPIO_INT_STATUS
;
678 #ifdef CONFIG_ARCH_OMAP16XX
679 case METHOD_GPIO_1610
:
680 reg
+= OMAP1610_GPIO_IRQSTATUS1
;
683 #ifdef CONFIG_ARCH_OMAP730
684 case METHOD_GPIO_730
:
685 reg
+= OMAP730_GPIO_INT_STATUS
;
688 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
689 case METHOD_GPIO_24XX
:
690 reg
+= OMAP24XX_GPIO_IRQSTATUS1
;
697 __raw_writel(gpio_mask
, reg
);
699 /* Workaround for clearing DSP GPIO interrupts to allow retention */
700 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
701 if (cpu_is_omap24xx() || cpu_is_omap34xx())
702 __raw_writel(gpio_mask
, bank
->base
+ OMAP24XX_GPIO_IRQSTATUS2
);
706 static inline void _clear_gpio_irqstatus(struct gpio_bank
*bank
, int gpio
)
708 _clear_gpio_irqbank(bank
, 1 << get_gpio_index(gpio
));
711 static u32
_get_gpio_irqbank_mask(struct gpio_bank
*bank
)
713 void __iomem
*reg
= bank
->base
;
718 switch (bank
->method
) {
719 #ifdef CONFIG_ARCH_OMAP1
721 reg
+= OMAP_MPUIO_GPIO_MASKIT
;
726 #ifdef CONFIG_ARCH_OMAP15XX
727 case METHOD_GPIO_1510
:
728 reg
+= OMAP1510_GPIO_INT_MASK
;
733 #ifdef CONFIG_ARCH_OMAP16XX
734 case METHOD_GPIO_1610
:
735 reg
+= OMAP1610_GPIO_IRQENABLE1
;
739 #ifdef CONFIG_ARCH_OMAP730
740 case METHOD_GPIO_730
:
741 reg
+= OMAP730_GPIO_INT_MASK
;
746 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
747 case METHOD_GPIO_24XX
:
748 reg
+= OMAP24XX_GPIO_IRQENABLE1
;
757 l
= __raw_readl(reg
);
764 static void _enable_gpio_irqbank(struct gpio_bank
*bank
, int gpio_mask
, int enable
)
766 void __iomem
*reg
= bank
->base
;
769 switch (bank
->method
) {
770 #ifdef CONFIG_ARCH_OMAP1
772 reg
+= OMAP_MPUIO_GPIO_MASKIT
;
773 l
= __raw_readl(reg
);
780 #ifdef CONFIG_ARCH_OMAP15XX
781 case METHOD_GPIO_1510
:
782 reg
+= OMAP1510_GPIO_INT_MASK
;
783 l
= __raw_readl(reg
);
790 #ifdef CONFIG_ARCH_OMAP16XX
791 case METHOD_GPIO_1610
:
793 reg
+= OMAP1610_GPIO_SET_IRQENABLE1
;
795 reg
+= OMAP1610_GPIO_CLEAR_IRQENABLE1
;
799 #ifdef CONFIG_ARCH_OMAP730
800 case METHOD_GPIO_730
:
801 reg
+= OMAP730_GPIO_INT_MASK
;
802 l
= __raw_readl(reg
);
809 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
810 case METHOD_GPIO_24XX
:
812 reg
+= OMAP24XX_GPIO_SETIRQENABLE1
;
814 reg
+= OMAP24XX_GPIO_CLEARIRQENABLE1
;
822 __raw_writel(l
, reg
);
825 static inline void _set_gpio_irqenable(struct gpio_bank
*bank
, int gpio
, int enable
)
827 _enable_gpio_irqbank(bank
, 1 << get_gpio_index(gpio
), enable
);
831 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
832 * 1510 does not seem to have a wake-up register. If JTAG is connected
833 * to the target, system will wake up always on GPIO events. While
834 * system is running all registered GPIO interrupts need to have wake-up
835 * enabled. When system is suspended, only selected GPIO interrupts need
836 * to have wake-up enabled.
838 static int _set_gpio_wakeup(struct gpio_bank
*bank
, int gpio
, int enable
)
842 switch (bank
->method
) {
843 #ifdef CONFIG_ARCH_OMAP16XX
845 case METHOD_GPIO_1610
:
846 spin_lock_irqsave(&bank
->lock
, flags
);
848 bank
->suspend_wakeup
|= (1 << gpio
);
849 enable_irq_wake(bank
->irq
);
851 disable_irq_wake(bank
->irq
);
852 bank
->suspend_wakeup
&= ~(1 << gpio
);
854 spin_unlock_irqrestore(&bank
->lock
, flags
);
857 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
858 case METHOD_GPIO_24XX
:
859 if (bank
->non_wakeup_gpios
& (1 << gpio
)) {
860 printk(KERN_ERR
"Unable to modify wakeup on "
861 "non-wakeup GPIO%d\n",
862 (bank
- gpio_bank
) * 32 + gpio
);
865 spin_lock_irqsave(&bank
->lock
, flags
);
867 bank
->suspend_wakeup
|= (1 << gpio
);
868 enable_irq_wake(bank
->irq
);
870 disable_irq_wake(bank
->irq
);
871 bank
->suspend_wakeup
&= ~(1 << gpio
);
873 spin_unlock_irqrestore(&bank
->lock
, flags
);
877 printk(KERN_ERR
"Can't enable GPIO wakeup for method %i\n",
883 static void _reset_gpio(struct gpio_bank
*bank
, int gpio
)
885 _set_gpio_direction(bank
, get_gpio_index(gpio
), 1);
886 _set_gpio_irqenable(bank
, gpio
, 0);
887 _clear_gpio_irqstatus(bank
, gpio
);
888 _set_gpio_triggering(bank
, get_gpio_index(gpio
), IRQT_NOEDGE
);
891 /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
892 static int gpio_wake_enable(unsigned int irq
, unsigned int enable
)
894 unsigned int gpio
= irq
- IH_GPIO_BASE
;
895 struct gpio_bank
*bank
;
898 if (check_gpio(gpio
) < 0)
900 bank
= get_irq_chip_data(irq
);
901 retval
= _set_gpio_wakeup(bank
, get_gpio_index(gpio
), enable
);
906 int omap_request_gpio(int gpio
)
908 struct gpio_bank
*bank
;
912 if (check_gpio(gpio
) < 0)
915 status
= gpio_request(gpio
, NULL
);
919 bank
= get_gpio_bank(gpio
);
920 spin_lock_irqsave(&bank
->lock
, flags
);
922 /* Set trigger to none. You need to enable the desired trigger with
923 * request_irq() or set_irq_type().
925 _set_gpio_triggering(bank
, get_gpio_index(gpio
), IRQT_NOEDGE
);
927 #ifdef CONFIG_ARCH_OMAP15XX
928 if (bank
->method
== METHOD_GPIO_1510
) {
931 /* Claim the pin for MPU */
932 reg
= bank
->base
+ OMAP1510_GPIO_PIN_CONTROL
;
933 __raw_writel(__raw_readl(reg
) | (1 << get_gpio_index(gpio
)), reg
);
936 spin_unlock_irqrestore(&bank
->lock
, flags
);
941 void omap_free_gpio(int gpio
)
943 struct gpio_bank
*bank
;
946 if (check_gpio(gpio
) < 0)
948 bank
= get_gpio_bank(gpio
);
949 spin_lock_irqsave(&bank
->lock
, flags
);
950 if (unlikely(!gpiochip_is_requested(&bank
->chip
,
951 get_gpio_index(gpio
)))) {
952 spin_unlock_irqrestore(&bank
->lock
, flags
);
953 printk(KERN_ERR
"omap-gpio: GPIO %d wasn't reserved!\n", gpio
);
957 #ifdef CONFIG_ARCH_OMAP16XX
958 if (bank
->method
== METHOD_GPIO_1610
) {
959 /* Disable wake-up during idle for dynamic tick */
960 void __iomem
*reg
= bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
;
961 __raw_writel(1 << get_gpio_index(gpio
), reg
);
964 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
965 if (bank
->method
== METHOD_GPIO_24XX
) {
966 /* Disable wake-up during idle for dynamic tick */
967 void __iomem
*reg
= bank
->base
+ OMAP24XX_GPIO_CLEARWKUENA
;
968 __raw_writel(1 << get_gpio_index(gpio
), reg
);
971 _reset_gpio(bank
, gpio
);
972 spin_unlock_irqrestore(&bank
->lock
, flags
);
977 * We need to unmask the GPIO bank interrupt as soon as possible to
978 * avoid missing GPIO interrupts for other lines in the bank.
979 * Then we need to mask-read-clear-unmask the triggered GPIO lines
980 * in the bank to avoid missing nested interrupts for a GPIO line.
981 * If we wait to unmask individual GPIO lines in the bank after the
982 * line's interrupt handler has been run, we may miss some nested
985 static void gpio_irq_handler(unsigned int irq
, struct irq_desc
*desc
)
987 void __iomem
*isr_reg
= NULL
;
989 unsigned int gpio_irq
;
990 struct gpio_bank
*bank
;
994 desc
->chip
->ack(irq
);
996 bank
= get_irq_data(irq
);
997 #ifdef CONFIG_ARCH_OMAP1
998 if (bank
->method
== METHOD_MPUIO
)
999 isr_reg
= bank
->base
+ OMAP_MPUIO_GPIO_INT
;
1001 #ifdef CONFIG_ARCH_OMAP15XX
1002 if (bank
->method
== METHOD_GPIO_1510
)
1003 isr_reg
= bank
->base
+ OMAP1510_GPIO_INT_STATUS
;
1005 #if defined(CONFIG_ARCH_OMAP16XX)
1006 if (bank
->method
== METHOD_GPIO_1610
)
1007 isr_reg
= bank
->base
+ OMAP1610_GPIO_IRQSTATUS1
;
1009 #ifdef CONFIG_ARCH_OMAP730
1010 if (bank
->method
== METHOD_GPIO_730
)
1011 isr_reg
= bank
->base
+ OMAP730_GPIO_INT_STATUS
;
1013 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1014 if (bank
->method
== METHOD_GPIO_24XX
)
1015 isr_reg
= bank
->base
+ OMAP24XX_GPIO_IRQSTATUS1
;
1018 u32 isr_saved
, level_mask
= 0;
1021 enabled
= _get_gpio_irqbank_mask(bank
);
1022 isr_saved
= isr
= __raw_readl(isr_reg
) & enabled
;
1024 if (cpu_is_omap15xx() && (bank
->method
== METHOD_MPUIO
))
1027 if (cpu_class_is_omap2()) {
1028 level_mask
= bank
->level_mask
& enabled
;
1031 /* clear edge sensitive interrupts before handler(s) are
1032 called so that we don't miss any interrupt occurred while
1034 _enable_gpio_irqbank(bank
, isr_saved
& ~level_mask
, 0);
1035 _clear_gpio_irqbank(bank
, isr_saved
& ~level_mask
);
1036 _enable_gpio_irqbank(bank
, isr_saved
& ~level_mask
, 1);
1038 /* if there is only edge sensitive GPIO pin interrupts
1039 configured, we could unmask GPIO bank interrupt immediately */
1040 if (!level_mask
&& !unmasked
) {
1042 desc
->chip
->unmask(irq
);
1050 gpio_irq
= bank
->virtual_irq_start
;
1051 for (; isr
!= 0; isr
>>= 1, gpio_irq
++) {
1056 d
= irq_desc
+ gpio_irq
;
1057 /* Don't run the handler if it's already running
1058 * or was disabled lazely.
1060 if (unlikely((d
->depth
||
1061 (d
->status
& IRQ_INPROGRESS
)))) {
1063 (gpio_irq
- bank
->virtual_irq_start
);
1064 /* The unmasking will be done by
1065 * enable_irq in case it is disabled or
1066 * after returning from the handler if
1067 * it's already running.
1069 _enable_gpio_irqbank(bank
, irq_mask
, 0);
1071 /* Level triggered interrupts
1072 * won't ever be reentered
1074 BUG_ON(level_mask
& irq_mask
);
1075 d
->status
|= IRQ_PENDING
;
1080 desc_handle_irq(gpio_irq
, d
);
1082 if (unlikely((d
->status
& IRQ_PENDING
) && !d
->depth
)) {
1084 (gpio_irq
- bank
->virtual_irq_start
);
1085 d
->status
&= ~IRQ_PENDING
;
1086 _enable_gpio_irqbank(bank
, irq_mask
, 1);
1087 retrigger
|= irq_mask
;
1091 /* if bank has any level sensitive GPIO pin interrupt
1092 configured, we must unmask the bank interrupt only after
1093 handler(s) are executed in order to avoid spurious bank
1096 desc
->chip
->unmask(irq
);
1100 static void gpio_irq_shutdown(unsigned int irq
)
1102 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1103 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1105 _reset_gpio(bank
, gpio
);
1108 static void gpio_ack_irq(unsigned int irq
)
1110 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1111 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1113 _clear_gpio_irqstatus(bank
, gpio
);
1116 static void gpio_mask_irq(unsigned int irq
)
1118 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1119 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1121 _set_gpio_irqenable(bank
, gpio
, 0);
1124 static void gpio_unmask_irq(unsigned int irq
)
1126 unsigned int gpio
= irq
- IH_GPIO_BASE
;
1127 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1128 unsigned int irq_mask
= 1 << get_gpio_index(gpio
);
1130 /* For level-triggered GPIOs, the clearing must be done after
1131 * the HW source is cleared, thus after the handler has run */
1132 if (bank
->level_mask
& irq_mask
) {
1133 _set_gpio_irqenable(bank
, gpio
, 0);
1134 _clear_gpio_irqstatus(bank
, gpio
);
1137 _set_gpio_irqenable(bank
, gpio
, 1);
1140 static struct irq_chip gpio_irq_chip
= {
1142 .shutdown
= gpio_irq_shutdown
,
1143 .ack
= gpio_ack_irq
,
1144 .mask
= gpio_mask_irq
,
1145 .unmask
= gpio_unmask_irq
,
1146 .set_type
= gpio_irq_type
,
1147 .set_wake
= gpio_wake_enable
,
1150 /*---------------------------------------------------------------------*/
1152 #ifdef CONFIG_ARCH_OMAP1
1154 /* MPUIO uses the always-on 32k clock */
1156 static void mpuio_ack_irq(unsigned int irq
)
1158 /* The ISR is reset automatically, so do nothing here. */
1161 static void mpuio_mask_irq(unsigned int irq
)
1163 unsigned int gpio
= OMAP_MPUIO(irq
- IH_MPUIO_BASE
);
1164 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1166 _set_gpio_irqenable(bank
, gpio
, 0);
1169 static void mpuio_unmask_irq(unsigned int irq
)
1171 unsigned int gpio
= OMAP_MPUIO(irq
- IH_MPUIO_BASE
);
1172 struct gpio_bank
*bank
= get_irq_chip_data(irq
);
1174 _set_gpio_irqenable(bank
, gpio
, 1);
1177 static struct irq_chip mpuio_irq_chip
= {
1179 .ack
= mpuio_ack_irq
,
1180 .mask
= mpuio_mask_irq
,
1181 .unmask
= mpuio_unmask_irq
,
1182 .set_type
= gpio_irq_type
,
1183 #ifdef CONFIG_ARCH_OMAP16XX
1184 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1185 .set_wake
= gpio_wake_enable
,
1190 #define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1193 #ifdef CONFIG_ARCH_OMAP16XX
1195 #include <linux/platform_device.h>
1197 static int omap_mpuio_suspend_late(struct platform_device
*pdev
, pm_message_t mesg
)
1199 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1200 void __iomem
*mask_reg
= bank
->base
+ OMAP_MPUIO_GPIO_MASKIT
;
1201 unsigned long flags
;
1203 spin_lock_irqsave(&bank
->lock
, flags
);
1204 bank
->saved_wakeup
= __raw_readl(mask_reg
);
1205 __raw_writel(0xffff & ~bank
->suspend_wakeup
, mask_reg
);
1206 spin_unlock_irqrestore(&bank
->lock
, flags
);
1211 static int omap_mpuio_resume_early(struct platform_device
*pdev
)
1213 struct gpio_bank
*bank
= platform_get_drvdata(pdev
);
1214 void __iomem
*mask_reg
= bank
->base
+ OMAP_MPUIO_GPIO_MASKIT
;
1215 unsigned long flags
;
1217 spin_lock_irqsave(&bank
->lock
, flags
);
1218 __raw_writel(bank
->saved_wakeup
, mask_reg
);
1219 spin_unlock_irqrestore(&bank
->lock
, flags
);
1224 /* use platform_driver for this, now that there's no longer any
1225 * point to sys_device (other than not disturbing old code).
1227 static struct platform_driver omap_mpuio_driver
= {
1228 .suspend_late
= omap_mpuio_suspend_late
,
1229 .resume_early
= omap_mpuio_resume_early
,
1235 static struct platform_device omap_mpuio_device
= {
1239 .driver
= &omap_mpuio_driver
.driver
,
1241 /* could list the /proc/iomem resources */
1244 static inline void mpuio_init(void)
1246 platform_set_drvdata(&omap_mpuio_device
, &gpio_bank_1610
[0]);
1248 if (platform_driver_register(&omap_mpuio_driver
) == 0)
1249 (void) platform_device_register(&omap_mpuio_device
);
1253 static inline void mpuio_init(void) {}
1258 extern struct irq_chip mpuio_irq_chip
;
1260 #define bank_is_mpuio(bank) 0
1261 static inline void mpuio_init(void) {}
1265 /*---------------------------------------------------------------------*/
1267 /* REVISIT these are stupid implementations! replace by ones that
1268 * don't switch on METHOD_* and which mostly avoid spinlocks
1271 static int gpio_input(struct gpio_chip
*chip
, unsigned offset
)
1273 struct gpio_bank
*bank
;
1274 unsigned long flags
;
1276 bank
= container_of(chip
, struct gpio_bank
, chip
);
1277 spin_lock_irqsave(&bank
->lock
, flags
);
1278 _set_gpio_direction(bank
, offset
, 1);
1279 spin_unlock_irqrestore(&bank
->lock
, flags
);
1283 static int gpio_get(struct gpio_chip
*chip
, unsigned offset
)
1285 return omap_get_gpio_datain(chip
->base
+ offset
);
1288 static int gpio_output(struct gpio_chip
*chip
, unsigned offset
, int value
)
1290 struct gpio_bank
*bank
;
1291 unsigned long flags
;
1293 bank
= container_of(chip
, struct gpio_bank
, chip
);
1294 spin_lock_irqsave(&bank
->lock
, flags
);
1295 _set_gpio_dataout(bank
, offset
, value
);
1296 _set_gpio_direction(bank
, offset
, 0);
1297 spin_unlock_irqrestore(&bank
->lock
, flags
);
1301 static void gpio_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
1303 struct gpio_bank
*bank
;
1304 unsigned long flags
;
1306 bank
= container_of(chip
, struct gpio_bank
, chip
);
1307 spin_lock_irqsave(&bank
->lock
, flags
);
1308 _set_gpio_dataout(bank
, offset
, value
);
1309 spin_unlock_irqrestore(&bank
->lock
, flags
);
1312 /*---------------------------------------------------------------------*/
1314 static int initialized
;
1315 #if !defined(CONFIG_ARCH_OMAP3)
1316 static struct clk
* gpio_ick
;
1319 #if defined(CONFIG_ARCH_OMAP2)
1320 static struct clk
* gpio_fck
;
1323 #if defined(CONFIG_ARCH_OMAP2430)
1324 static struct clk
* gpio5_ick
;
1325 static struct clk
* gpio5_fck
;
1328 #if defined(CONFIG_ARCH_OMAP3)
1329 static struct clk
*gpio_fclks
[OMAP34XX_NR_GPIOS
];
1330 static struct clk
*gpio_iclks
[OMAP34XX_NR_GPIOS
];
1333 /* This lock class tells lockdep that GPIO irqs are in a different
1334 * category than their parents, so it won't report false recursion.
1336 static struct lock_class_key gpio_lock_class
;
1338 static int __init
_omap_gpio_init(void)
1342 struct gpio_bank
*bank
;
1343 #if defined(CONFIG_ARCH_OMAP3)
1349 #if defined(CONFIG_ARCH_OMAP1)
1350 if (cpu_is_omap15xx()) {
1351 gpio_ick
= clk_get(NULL
, "arm_gpio_ck");
1352 if (IS_ERR(gpio_ick
))
1353 printk("Could not get arm_gpio_ck\n");
1355 clk_enable(gpio_ick
);
1358 #if defined(CONFIG_ARCH_OMAP2)
1359 if (cpu_class_is_omap2()) {
1360 gpio_ick
= clk_get(NULL
, "gpios_ick");
1361 if (IS_ERR(gpio_ick
))
1362 printk("Could not get gpios_ick\n");
1364 clk_enable(gpio_ick
);
1365 gpio_fck
= clk_get(NULL
, "gpios_fck");
1366 if (IS_ERR(gpio_fck
))
1367 printk("Could not get gpios_fck\n");
1369 clk_enable(gpio_fck
);
1372 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
1374 #if defined(CONFIG_ARCH_OMAP2430)
1375 if (cpu_is_omap2430()) {
1376 gpio5_ick
= clk_get(NULL
, "gpio5_ick");
1377 if (IS_ERR(gpio5_ick
))
1378 printk("Could not get gpio5_ick\n");
1380 clk_enable(gpio5_ick
);
1381 gpio5_fck
= clk_get(NULL
, "gpio5_fck");
1382 if (IS_ERR(gpio5_fck
))
1383 printk("Could not get gpio5_fck\n");
1385 clk_enable(gpio5_fck
);
1391 #if defined(CONFIG_ARCH_OMAP3)
1392 if (cpu_is_omap34xx()) {
1393 for (i
= 0; i
< OMAP34XX_NR_GPIOS
; i
++) {
1394 sprintf(clk_name
, "gpio%d_ick", i
+ 1);
1395 gpio_iclks
[i
] = clk_get(NULL
, clk_name
);
1396 if (IS_ERR(gpio_iclks
[i
]))
1397 printk(KERN_ERR
"Could not get %s\n", clk_name
);
1399 clk_enable(gpio_iclks
[i
]);
1400 sprintf(clk_name
, "gpio%d_fck", i
+ 1);
1401 gpio_fclks
[i
] = clk_get(NULL
, clk_name
);
1402 if (IS_ERR(gpio_fclks
[i
]))
1403 printk(KERN_ERR
"Could not get %s\n", clk_name
);
1405 clk_enable(gpio_fclks
[i
]);
1411 #ifdef CONFIG_ARCH_OMAP15XX
1412 if (cpu_is_omap15xx()) {
1413 printk(KERN_INFO
"OMAP1510 GPIO hardware\n");
1414 gpio_bank_count
= 2;
1415 gpio_bank
= gpio_bank_1510
;
1418 #if defined(CONFIG_ARCH_OMAP16XX)
1419 if (cpu_is_omap16xx()) {
1422 gpio_bank_count
= 5;
1423 gpio_bank
= gpio_bank_1610
;
1424 rev
= omap_readw(gpio_bank
[1].base
+ OMAP1610_GPIO_REVISION
);
1425 printk(KERN_INFO
"OMAP GPIO hardware version %d.%d\n",
1426 (rev
>> 4) & 0x0f, rev
& 0x0f);
1429 #ifdef CONFIG_ARCH_OMAP730
1430 if (cpu_is_omap730()) {
1431 printk(KERN_INFO
"OMAP730 GPIO hardware\n");
1432 gpio_bank_count
= 7;
1433 gpio_bank
= gpio_bank_730
;
1437 #ifdef CONFIG_ARCH_OMAP24XX
1438 if (cpu_is_omap242x()) {
1441 gpio_bank_count
= 4;
1442 gpio_bank
= gpio_bank_242x
;
1443 rev
= omap_readl(gpio_bank
[0].base
+ OMAP24XX_GPIO_REVISION
);
1444 printk(KERN_INFO
"OMAP242x GPIO hardware version %d.%d\n",
1445 (rev
>> 4) & 0x0f, rev
& 0x0f);
1447 if (cpu_is_omap243x()) {
1450 gpio_bank_count
= 5;
1451 gpio_bank
= gpio_bank_243x
;
1452 rev
= omap_readl(gpio_bank
[0].base
+ OMAP24XX_GPIO_REVISION
);
1453 printk(KERN_INFO
"OMAP243x GPIO hardware version %d.%d\n",
1454 (rev
>> 4) & 0x0f, rev
& 0x0f);
1457 #ifdef CONFIG_ARCH_OMAP34XX
1458 if (cpu_is_omap34xx()) {
1461 gpio_bank_count
= OMAP34XX_NR_GPIOS
;
1462 gpio_bank
= gpio_bank_34xx
;
1463 rev
= omap_readl(gpio_bank
[0].base
+ OMAP24XX_GPIO_REVISION
);
1464 printk(KERN_INFO
"OMAP34xx GPIO hardware version %d.%d\n",
1465 (rev
>> 4) & 0x0f, rev
& 0x0f);
1468 for (i
= 0; i
< gpio_bank_count
; i
++) {
1469 int j
, gpio_count
= 16;
1471 bank
= &gpio_bank
[i
];
1472 bank
->base
= IO_ADDRESS(bank
->base
);
1473 spin_lock_init(&bank
->lock
);
1474 if (bank_is_mpuio(bank
))
1475 omap_writew(0xFFFF, OMAP_MPUIO_BASE
+ OMAP_MPUIO_GPIO_MASKIT
);
1476 if (cpu_is_omap15xx() && bank
->method
== METHOD_GPIO_1510
) {
1477 __raw_writew(0xffff, bank
->base
+ OMAP1510_GPIO_INT_MASK
);
1478 __raw_writew(0x0000, bank
->base
+ OMAP1510_GPIO_INT_STATUS
);
1480 if (cpu_is_omap16xx() && bank
->method
== METHOD_GPIO_1610
) {
1481 __raw_writew(0x0000, bank
->base
+ OMAP1610_GPIO_IRQENABLE1
);
1482 __raw_writew(0xffff, bank
->base
+ OMAP1610_GPIO_IRQSTATUS1
);
1483 __raw_writew(0x0014, bank
->base
+ OMAP1610_GPIO_SYSCONFIG
);
1485 if (cpu_is_omap730() && bank
->method
== METHOD_GPIO_730
) {
1486 __raw_writel(0xffffffff, bank
->base
+ OMAP730_GPIO_INT_MASK
);
1487 __raw_writel(0x00000000, bank
->base
+ OMAP730_GPIO_INT_STATUS
);
1489 gpio_count
= 32; /* 730 has 32-bit GPIOs */
1492 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1493 if (bank
->method
== METHOD_GPIO_24XX
) {
1494 static const u32 non_wakeup_gpios
[] = {
1495 0xe203ffc0, 0x08700040
1498 __raw_writel(0x00000000, bank
->base
+ OMAP24XX_GPIO_IRQENABLE1
);
1499 __raw_writel(0xffffffff, bank
->base
+ OMAP24XX_GPIO_IRQSTATUS1
);
1500 __raw_writew(0x0015, bank
->base
+ OMAP24XX_GPIO_SYSCONFIG
);
1502 /* Initialize interface clock ungated, module enabled */
1503 __raw_writel(0, bank
->base
+ OMAP24XX_GPIO_CTRL
);
1504 if (i
< ARRAY_SIZE(non_wakeup_gpios
))
1505 bank
->non_wakeup_gpios
= non_wakeup_gpios
[i
];
1510 /* REVISIT eventually switch from OMAP-specific gpio structs
1511 * over to the generic ones
1513 bank
->chip
.direction_input
= gpio_input
;
1514 bank
->chip
.get
= gpio_get
;
1515 bank
->chip
.direction_output
= gpio_output
;
1516 bank
->chip
.set
= gpio_set
;
1517 if (bank_is_mpuio(bank
)) {
1518 bank
->chip
.label
= "mpuio";
1519 bank
->chip
.base
= OMAP_MPUIO(0);
1521 bank
->chip
.label
= "gpio";
1522 bank
->chip
.base
= gpio
;
1525 bank
->chip
.ngpio
= gpio_count
;
1527 gpiochip_add(&bank
->chip
);
1529 for (j
= bank
->virtual_irq_start
;
1530 j
< bank
->virtual_irq_start
+ gpio_count
; j
++) {
1531 lockdep_set_class(&irq_desc
[j
].lock
, &gpio_lock_class
);
1532 set_irq_chip_data(j
, bank
);
1533 if (bank_is_mpuio(bank
))
1534 set_irq_chip(j
, &mpuio_irq_chip
);
1536 set_irq_chip(j
, &gpio_irq_chip
);
1537 set_irq_handler(j
, handle_simple_irq
);
1538 set_irq_flags(j
, IRQF_VALID
);
1540 set_irq_chained_handler(bank
->irq
, gpio_irq_handler
);
1541 set_irq_data(bank
->irq
, bank
);
1544 /* Enable system clock for GPIO module.
1545 * The CAM_CLK_CTRL *is* really the right place. */
1546 if (cpu_is_omap16xx())
1547 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL
) | 0x04, ULPD_CAM_CLK_CTRL
);
1549 /* Enable autoidle for the OCP interface */
1550 if (cpu_is_omap24xx())
1551 omap_writel(1 << 0, 0x48019010);
1552 if (cpu_is_omap34xx())
1553 omap_writel(1 << 0, 0x48306814);
1558 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1559 static int omap_gpio_suspend(struct sys_device
*dev
, pm_message_t mesg
)
1563 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
1566 for (i
= 0; i
< gpio_bank_count
; i
++) {
1567 struct gpio_bank
*bank
= &gpio_bank
[i
];
1568 void __iomem
*wake_status
;
1569 void __iomem
*wake_clear
;
1570 void __iomem
*wake_set
;
1571 unsigned long flags
;
1573 switch (bank
->method
) {
1574 #ifdef CONFIG_ARCH_OMAP16XX
1575 case METHOD_GPIO_1610
:
1576 wake_status
= bank
->base
+ OMAP1610_GPIO_WAKEUPENABLE
;
1577 wake_clear
= bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
;
1578 wake_set
= bank
->base
+ OMAP1610_GPIO_SET_WAKEUPENA
;
1581 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1582 case METHOD_GPIO_24XX
:
1583 wake_status
= bank
->base
+ OMAP24XX_GPIO_SETWKUENA
;
1584 wake_clear
= bank
->base
+ OMAP24XX_GPIO_CLEARWKUENA
;
1585 wake_set
= bank
->base
+ OMAP24XX_GPIO_SETWKUENA
;
1592 spin_lock_irqsave(&bank
->lock
, flags
);
1593 bank
->saved_wakeup
= __raw_readl(wake_status
);
1594 __raw_writel(0xffffffff, wake_clear
);
1595 __raw_writel(bank
->suspend_wakeup
, wake_set
);
1596 spin_unlock_irqrestore(&bank
->lock
, flags
);
1602 static int omap_gpio_resume(struct sys_device
*dev
)
1606 if (!cpu_is_omap24xx() && !cpu_is_omap16xx())
1609 for (i
= 0; i
< gpio_bank_count
; i
++) {
1610 struct gpio_bank
*bank
= &gpio_bank
[i
];
1611 void __iomem
*wake_clear
;
1612 void __iomem
*wake_set
;
1613 unsigned long flags
;
1615 switch (bank
->method
) {
1616 #ifdef CONFIG_ARCH_OMAP16XX
1617 case METHOD_GPIO_1610
:
1618 wake_clear
= bank
->base
+ OMAP1610_GPIO_CLEAR_WAKEUPENA
;
1619 wake_set
= bank
->base
+ OMAP1610_GPIO_SET_WAKEUPENA
;
1622 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1623 case METHOD_GPIO_24XX
:
1624 wake_clear
= bank
->base
+ OMAP24XX_GPIO_CLEARWKUENA
;
1625 wake_set
= bank
->base
+ OMAP24XX_GPIO_SETWKUENA
;
1632 spin_lock_irqsave(&bank
->lock
, flags
);
1633 __raw_writel(0xffffffff, wake_clear
);
1634 __raw_writel(bank
->saved_wakeup
, wake_set
);
1635 spin_unlock_irqrestore(&bank
->lock
, flags
);
1641 static struct sysdev_class omap_gpio_sysclass
= {
1643 .suspend
= omap_gpio_suspend
,
1644 .resume
= omap_gpio_resume
,
1647 static struct sys_device omap_gpio_device
= {
1649 .cls
= &omap_gpio_sysclass
,
1654 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1656 static int workaround_enabled
;
1658 void omap2_gpio_prepare_for_retention(void)
1662 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
1663 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
1664 for (i
= 0; i
< gpio_bank_count
; i
++) {
1665 struct gpio_bank
*bank
= &gpio_bank
[i
];
1668 if (!(bank
->enabled_non_wakeup_gpios
))
1670 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1671 bank
->saved_datain
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_DATAIN
);
1672 l1
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
1673 l2
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
1675 bank
->saved_fallingdetect
= l1
;
1676 bank
->saved_risingdetect
= l2
;
1677 l1
&= ~bank
->enabled_non_wakeup_gpios
;
1678 l2
&= ~bank
->enabled_non_wakeup_gpios
;
1679 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1680 __raw_writel(l1
, bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
1681 __raw_writel(l2
, bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
1686 workaround_enabled
= 0;
1689 workaround_enabled
= 1;
1692 void omap2_gpio_resume_after_retention(void)
1696 if (!workaround_enabled
)
1698 for (i
= 0; i
< gpio_bank_count
; i
++) {
1699 struct gpio_bank
*bank
= &gpio_bank
[i
];
1702 if (!(bank
->enabled_non_wakeup_gpios
))
1704 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1705 __raw_writel(bank
->saved_fallingdetect
,
1706 bank
->base
+ OMAP24XX_GPIO_FALLINGDETECT
);
1707 __raw_writel(bank
->saved_risingdetect
,
1708 bank
->base
+ OMAP24XX_GPIO_RISINGDETECT
);
1710 /* Check if any of the non-wakeup interrupt GPIOs have changed
1711 * state. If so, generate an IRQ by software. This is
1712 * horribly racy, but it's the best we can do to work around
1713 * this silicon bug. */
1714 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1715 l
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_DATAIN
);
1717 l
^= bank
->saved_datain
;
1718 l
&= bank
->non_wakeup_gpios
;
1721 #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1722 old0
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
1723 old1
= __raw_readl(bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
1724 __raw_writel(old0
| l
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
1725 __raw_writel(old1
| l
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
1726 __raw_writel(old0
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT0
);
1727 __raw_writel(old1
, bank
->base
+ OMAP24XX_GPIO_LEVELDETECT1
);
1737 * This may get called early from board specific init
1738 * for boards that have interrupts routed via FPGA.
1740 int __init
omap_gpio_init(void)
1743 return _omap_gpio_init();
1748 static int __init
omap_gpio_sysinit(void)
1753 ret
= _omap_gpio_init();
1757 #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1758 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
1760 ret
= sysdev_class_register(&omap_gpio_sysclass
);
1762 ret
= sysdev_register(&omap_gpio_device
);
1770 EXPORT_SYMBOL(omap_request_gpio
);
1771 EXPORT_SYMBOL(omap_free_gpio
);
1772 EXPORT_SYMBOL(omap_set_gpio_direction
);
1773 EXPORT_SYMBOL(omap_set_gpio_dataout
);
1774 EXPORT_SYMBOL(omap_get_gpio_datain
);
1776 arch_initcall(omap_gpio_sysinit
);
1779 #ifdef CONFIG_DEBUG_FS
1781 #include <linux/debugfs.h>
1782 #include <linux/seq_file.h>
1784 static int gpio_is_input(struct gpio_bank
*bank
, int mask
)
1786 void __iomem
*reg
= bank
->base
;
1788 switch (bank
->method
) {
1790 reg
+= OMAP_MPUIO_IO_CNTL
;
1792 case METHOD_GPIO_1510
:
1793 reg
+= OMAP1510_GPIO_DIR_CONTROL
;
1795 case METHOD_GPIO_1610
:
1796 reg
+= OMAP1610_GPIO_DIRECTION
;
1798 case METHOD_GPIO_730
:
1799 reg
+= OMAP730_GPIO_DIR_CONTROL
;
1801 case METHOD_GPIO_24XX
:
1802 reg
+= OMAP24XX_GPIO_OE
;
1805 return __raw_readl(reg
) & mask
;
1809 static int dbg_gpio_show(struct seq_file
*s
, void *unused
)
1811 unsigned i
, j
, gpio
;
1813 for (i
= 0, gpio
= 0; i
< gpio_bank_count
; i
++) {
1814 struct gpio_bank
*bank
= gpio_bank
+ i
;
1815 unsigned bankwidth
= 16;
1818 if (bank_is_mpuio(bank
))
1819 gpio
= OMAP_MPUIO(0);
1820 else if (cpu_class_is_omap2() || cpu_is_omap730())
1823 for (j
= 0; j
< bankwidth
; j
++, gpio
++, mask
<<= 1) {
1824 unsigned irq
, value
, is_in
, irqstat
;
1827 label
= gpiochip_is_requested(&bank
->chip
, j
);
1831 irq
= bank
->virtual_irq_start
+ j
;
1832 value
= omap_get_gpio_datain(gpio
);
1833 is_in
= gpio_is_input(bank
, mask
);
1835 if (bank_is_mpuio(bank
))
1836 seq_printf(s
, "MPUIO %2d ", j
);
1838 seq_printf(s
, "GPIO %3d ", gpio
);
1839 seq_printf(s
, "(%10s): %s %s",
1841 is_in
? "in " : "out",
1842 value
? "hi" : "lo");
1844 /* FIXME for at least omap2, show pullup/pulldown state */
1846 irqstat
= irq_desc
[irq
].status
;
1847 if (is_in
&& ((bank
->suspend_wakeup
& mask
)
1848 || irqstat
& IRQ_TYPE_SENSE_MASK
)) {
1849 char *trigger
= NULL
;
1851 switch (irqstat
& IRQ_TYPE_SENSE_MASK
) {
1852 case IRQ_TYPE_EDGE_FALLING
:
1853 trigger
= "falling";
1855 case IRQ_TYPE_EDGE_RISING
:
1858 case IRQ_TYPE_EDGE_BOTH
:
1859 trigger
= "bothedge";
1861 case IRQ_TYPE_LEVEL_LOW
:
1864 case IRQ_TYPE_LEVEL_HIGH
:
1871 seq_printf(s
, ", irq-%d %-8s%s",
1873 (bank
->suspend_wakeup
& mask
)
1876 seq_printf(s
, "\n");
1879 if (bank_is_mpuio(bank
)) {
1880 seq_printf(s
, "\n");
1887 static int dbg_gpio_open(struct inode
*inode
, struct file
*file
)
1889 return single_open(file
, dbg_gpio_show
, &inode
->i_private
);
1892 static const struct file_operations debug_fops
= {
1893 .open
= dbg_gpio_open
,
1895 .llseek
= seq_lseek
,
1896 .release
= single_release
,
1899 static int __init
omap_gpio_debuginit(void)
1901 (void) debugfs_create_file("omap_gpio", S_IRUGO
,
1902 NULL
, NULL
, &debug_fops
);
1905 late_initcall(omap_gpio_debuginit
);