diff options
author | Tony Lindgren <tony@atomide.com> | 2005-09-07 12:20:26 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2005-09-07 12:20:26 -0400 |
commit | 92105bb70634abacc08bbe12bf6f888fbd7dad38 (patch) | |
tree | 194e3032671ee3a90644c68cda8ddf471cb09d0e /arch/arm/plat-omap/gpio.c | |
parent | 7efb833d645d10258e32664404354d26cf6070e3 (diff) |
[ARM] 2887/1: OMAP 2/4: Update files common to omap1 and omap2, take 2
Patch from Tony Lindgren
This patch syncs the mainline kernel with linux-omap tree.
The highlights of the patch are:
- Clock updates by Tuukka Tikkanen, Juha Yrjola,
Daniel Petrini and Tony Lindgren
- DMA fixes by Imre Deak, Juha Yrjola and Daniel Petrini
- Add support to dual-mode hardware timers by Lauri Leukkunen
- GPIO support for 24xx by Paul Mundt
- GPIO wake-up support by Tony Lindgren
- Better GPIO interrupt handler to not lose interrupts by
Ralph Walden and Ladislav Michl
- Power Management updates by Tuukka Tikkanen
- Make Power Management code use new SRAM functions by
Tony Lindgren
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/plat-omap/gpio.c')
-rw-r--r-- | arch/arm/plat-omap/gpio.c | 524 |
1 files changed, 419 insertions, 105 deletions
diff --git a/arch/arm/plat-omap/gpio.c b/arch/arm/plat-omap/gpio.c index aa481ea3d702..55059a24ad41 100644 --- a/arch/arm/plat-omap/gpio.c +++ b/arch/arm/plat-omap/gpio.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Support functions for OMAP GPIO | 4 | * Support functions for OMAP GPIO |
5 | * | 5 | * |
6 | * Copyright (C) 2003 Nokia Corporation | 6 | * Copyright (C) 2003-2005 Nokia Corporation |
7 | * Written by Juha Yrjölä <juha.yrjola@nokia.com> | 7 | * Written by Juha Yrjölä <juha.yrjola@nokia.com> |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
@@ -17,8 +17,11 @@ | |||
17 | #include <linux/sched.h> | 17 | #include <linux/sched.h> |
18 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
19 | #include <linux/ptrace.h> | 19 | #include <linux/ptrace.h> |
20 | #include <linux/sysdev.h> | ||
21 | #include <linux/err.h> | ||
20 | 22 | ||
21 | #include <asm/hardware.h> | 23 | #include <asm/hardware.h> |
24 | #include <asm/hardware/clock.h> | ||
22 | #include <asm/irq.h> | 25 | #include <asm/irq.h> |
23 | #include <asm/arch/irqs.h> | 26 | #include <asm/arch/irqs.h> |
24 | #include <asm/arch/gpio.h> | 27 | #include <asm/arch/gpio.h> |
@@ -29,7 +32,7 @@ | |||
29 | /* | 32 | /* |
30 | * OMAP1510 GPIO registers | 33 | * OMAP1510 GPIO registers |
31 | */ | 34 | */ |
32 | #define OMAP1510_GPIO_BASE 0xfffce000 | 35 | #define OMAP1510_GPIO_BASE (void __iomem *)0xfffce000 |
33 | #define OMAP1510_GPIO_DATA_INPUT 0x00 | 36 | #define OMAP1510_GPIO_DATA_INPUT 0x00 |
34 | #define OMAP1510_GPIO_DATA_OUTPUT 0x04 | 37 | #define OMAP1510_GPIO_DATA_OUTPUT 0x04 |
35 | #define OMAP1510_GPIO_DIR_CONTROL 0x08 | 38 | #define OMAP1510_GPIO_DIR_CONTROL 0x08 |
@@ -43,34 +46,37 @@ | |||
43 | /* | 46 | /* |
44 | * OMAP1610 specific GPIO registers | 47 | * OMAP1610 specific GPIO registers |
45 | */ | 48 | */ |
46 | #define OMAP1610_GPIO1_BASE 0xfffbe400 | 49 | #define OMAP1610_GPIO1_BASE (void __iomem *)0xfffbe400 |
47 | #define OMAP1610_GPIO2_BASE 0xfffbec00 | 50 | #define OMAP1610_GPIO2_BASE (void __iomem *)0xfffbec00 |
48 | #define OMAP1610_GPIO3_BASE 0xfffbb400 | 51 | #define OMAP1610_GPIO3_BASE (void __iomem *)0xfffbb400 |
49 | #define OMAP1610_GPIO4_BASE 0xfffbbc00 | 52 | #define OMAP1610_GPIO4_BASE (void __iomem *)0xfffbbc00 |
50 | #define OMAP1610_GPIO_REVISION 0x0000 | 53 | #define OMAP1610_GPIO_REVISION 0x0000 |
51 | #define OMAP1610_GPIO_SYSCONFIG 0x0010 | 54 | #define OMAP1610_GPIO_SYSCONFIG 0x0010 |
52 | #define OMAP1610_GPIO_SYSSTATUS 0x0014 | 55 | #define OMAP1610_GPIO_SYSSTATUS 0x0014 |
53 | #define OMAP1610_GPIO_IRQSTATUS1 0x0018 | 56 | #define OMAP1610_GPIO_IRQSTATUS1 0x0018 |
54 | #define OMAP1610_GPIO_IRQENABLE1 0x001c | 57 | #define OMAP1610_GPIO_IRQENABLE1 0x001c |
58 | #define OMAP1610_GPIO_WAKEUPENABLE 0x0028 | ||
55 | #define OMAP1610_GPIO_DATAIN 0x002c | 59 | #define OMAP1610_GPIO_DATAIN 0x002c |
56 | #define OMAP1610_GPIO_DATAOUT 0x0030 | 60 | #define OMAP1610_GPIO_DATAOUT 0x0030 |
57 | #define OMAP1610_GPIO_DIRECTION 0x0034 | 61 | #define OMAP1610_GPIO_DIRECTION 0x0034 |
58 | #define OMAP1610_GPIO_EDGE_CTRL1 0x0038 | 62 | #define OMAP1610_GPIO_EDGE_CTRL1 0x0038 |
59 | #define OMAP1610_GPIO_EDGE_CTRL2 0x003c | 63 | #define OMAP1610_GPIO_EDGE_CTRL2 0x003c |
60 | #define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c | 64 | #define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c |
65 | #define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8 | ||
61 | #define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0 | 66 | #define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0 |
62 | #define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc | 67 | #define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc |
68 | #define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8 | ||
63 | #define OMAP1610_GPIO_SET_DATAOUT 0x00f0 | 69 | #define OMAP1610_GPIO_SET_DATAOUT 0x00f0 |
64 | 70 | ||
65 | /* | 71 | /* |
66 | * OMAP730 specific GPIO registers | 72 | * OMAP730 specific GPIO registers |
67 | */ | 73 | */ |
68 | #define OMAP730_GPIO1_BASE 0xfffbc000 | 74 | #define OMAP730_GPIO1_BASE (void __iomem *)0xfffbc000 |
69 | #define OMAP730_GPIO2_BASE 0xfffbc800 | 75 | #define OMAP730_GPIO2_BASE (void __iomem *)0xfffbc800 |
70 | #define OMAP730_GPIO3_BASE 0xfffbd000 | 76 | #define OMAP730_GPIO3_BASE (void __iomem *)0xfffbd000 |
71 | #define OMAP730_GPIO4_BASE 0xfffbd800 | 77 | #define OMAP730_GPIO4_BASE (void __iomem *)0xfffbd800 |
72 | #define OMAP730_GPIO5_BASE 0xfffbe000 | 78 | #define OMAP730_GPIO5_BASE (void __iomem *)0xfffbe000 |
73 | #define OMAP730_GPIO6_BASE 0xfffbe800 | 79 | #define OMAP730_GPIO6_BASE (void __iomem *)0xfffbe800 |
74 | #define OMAP730_GPIO_DATA_INPUT 0x00 | 80 | #define OMAP730_GPIO_DATA_INPUT 0x00 |
75 | #define OMAP730_GPIO_DATA_OUTPUT 0x04 | 81 | #define OMAP730_GPIO_DATA_OUTPUT 0x04 |
76 | #define OMAP730_GPIO_DIR_CONTROL 0x08 | 82 | #define OMAP730_GPIO_DIR_CONTROL 0x08 |
@@ -78,14 +84,43 @@ | |||
78 | #define OMAP730_GPIO_INT_MASK 0x10 | 84 | #define OMAP730_GPIO_INT_MASK 0x10 |
79 | #define OMAP730_GPIO_INT_STATUS 0x14 | 85 | #define OMAP730_GPIO_INT_STATUS 0x14 |
80 | 86 | ||
87 | /* | ||
88 | * omap24xx specific GPIO registers | ||
89 | */ | ||
90 | #define OMAP24XX_GPIO1_BASE (void __iomem *)0x48018000 | ||
91 | #define OMAP24XX_GPIO2_BASE (void __iomem *)0x4801a000 | ||
92 | #define OMAP24XX_GPIO3_BASE (void __iomem *)0x4801c000 | ||
93 | #define OMAP24XX_GPIO4_BASE (void __iomem *)0x4801e000 | ||
94 | #define OMAP24XX_GPIO_REVISION 0x0000 | ||
95 | #define OMAP24XX_GPIO_SYSCONFIG 0x0010 | ||
96 | #define OMAP24XX_GPIO_SYSSTATUS 0x0014 | ||
97 | #define OMAP24XX_GPIO_IRQSTATUS1 0x0018 | ||
98 | #define OMAP24XX_GPIO_IRQENABLE1 0x001c | ||
99 | #define OMAP24XX_GPIO_CTRL 0x0030 | ||
100 | #define OMAP24XX_GPIO_OE 0x0034 | ||
101 | #define OMAP24XX_GPIO_DATAIN 0x0038 | ||
102 | #define OMAP24XX_GPIO_DATAOUT 0x003c | ||
103 | #define OMAP24XX_GPIO_LEVELDETECT0 0x0040 | ||
104 | #define OMAP24XX_GPIO_LEVELDETECT1 0x0044 | ||
105 | #define OMAP24XX_GPIO_RISINGDETECT 0x0048 | ||
106 | #define OMAP24XX_GPIO_FALLINGDETECT 0x004c | ||
107 | #define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060 | ||
108 | #define OMAP24XX_GPIO_SETIRQENABLE1 0x0064 | ||
109 | #define OMAP24XX_GPIO_CLEARWKUENA 0x0080 | ||
110 | #define OMAP24XX_GPIO_SETWKUENA 0x0084 | ||
111 | #define OMAP24XX_GPIO_CLEARDATAOUT 0x0090 | ||
112 | #define OMAP24XX_GPIO_SETDATAOUT 0x0094 | ||
113 | |||
81 | #define OMAP_MPUIO_MASK (~OMAP_MAX_GPIO_LINES & 0xff) | 114 | #define OMAP_MPUIO_MASK (~OMAP_MAX_GPIO_LINES & 0xff) |
82 | 115 | ||
83 | struct gpio_bank { | 116 | struct gpio_bank { |
84 | u32 base; | 117 | void __iomem *base; |
85 | u16 irq; | 118 | u16 irq; |
86 | u16 virtual_irq_start; | 119 | u16 virtual_irq_start; |
87 | u8 method; | 120 | int method; |
88 | u32 reserved_map; | 121 | u32 reserved_map; |
122 | u32 suspend_wakeup; | ||
123 | u32 saved_wakeup; | ||
89 | spinlock_t lock; | 124 | spinlock_t lock; |
90 | }; | 125 | }; |
91 | 126 | ||
@@ -93,8 +128,9 @@ struct gpio_bank { | |||
93 | #define METHOD_GPIO_1510 1 | 128 | #define METHOD_GPIO_1510 1 |
94 | #define METHOD_GPIO_1610 2 | 129 | #define METHOD_GPIO_1610 2 |
95 | #define METHOD_GPIO_730 3 | 130 | #define METHOD_GPIO_730 3 |
131 | #define METHOD_GPIO_24XX 4 | ||
96 | 132 | ||
97 | #if defined(CONFIG_ARCH_OMAP16XX) | 133 | #ifdef CONFIG_ARCH_OMAP16XX |
98 | static struct gpio_bank gpio_bank_1610[5] = { | 134 | static struct gpio_bank gpio_bank_1610[5] = { |
99 | { OMAP_MPUIO_BASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO}, | 135 | { OMAP_MPUIO_BASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO}, |
100 | { OMAP1610_GPIO1_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1610 }, | 136 | { OMAP1610_GPIO1_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1610 }, |
@@ -123,6 +159,15 @@ static struct gpio_bank gpio_bank_730[7] = { | |||
123 | }; | 159 | }; |
124 | #endif | 160 | #endif |
125 | 161 | ||
162 | #ifdef CONFIG_ARCH_OMAP24XX | ||
163 | static struct gpio_bank gpio_bank_24xx[4] = { | ||
164 | { OMAP24XX_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX }, | ||
165 | { OMAP24XX_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX }, | ||
166 | { OMAP24XX_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX }, | ||
167 | { OMAP24XX_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX }, | ||
168 | }; | ||
169 | #endif | ||
170 | |||
126 | static struct gpio_bank *gpio_bank; | 171 | static struct gpio_bank *gpio_bank; |
127 | static int gpio_bank_count; | 172 | static int gpio_bank_count; |
128 | 173 | ||
@@ -149,14 +194,23 @@ static inline struct gpio_bank *get_gpio_bank(int gpio) | |||
149 | return &gpio_bank[1 + (gpio >> 5)]; | 194 | return &gpio_bank[1 + (gpio >> 5)]; |
150 | } | 195 | } |
151 | #endif | 196 | #endif |
197 | #ifdef CONFIG_ARCH_OMAP24XX | ||
198 | if (cpu_is_omap24xx()) | ||
199 | return &gpio_bank[gpio >> 5]; | ||
200 | #endif | ||
152 | } | 201 | } |
153 | 202 | ||
154 | static inline int get_gpio_index(int gpio) | 203 | static inline int get_gpio_index(int gpio) |
155 | { | 204 | { |
205 | #ifdef CONFIG_ARCH_OMAP730 | ||
156 | if (cpu_is_omap730()) | 206 | if (cpu_is_omap730()) |
157 | return gpio & 0x1f; | 207 | return gpio & 0x1f; |
158 | else | 208 | #endif |
159 | return gpio & 0x0f; | 209 | #ifdef CONFIG_ARCH_OMAP24XX |
210 | if (cpu_is_omap24xx()) | ||
211 | return gpio & 0x1f; | ||
212 | #endif | ||
213 | return gpio & 0x0f; | ||
160 | } | 214 | } |
161 | 215 | ||
162 | static inline int gpio_valid(int gpio) | 216 | static inline int gpio_valid(int gpio) |
@@ -180,6 +234,10 @@ static inline int gpio_valid(int gpio) | |||
180 | if (cpu_is_omap730() && gpio < 192) | 234 | if (cpu_is_omap730() && gpio < 192) |
181 | return 0; | 235 | return 0; |
182 | #endif | 236 | #endif |
237 | #ifdef CONFIG_ARCH_OMAP24XX | ||
238 | if (cpu_is_omap24xx() && gpio < 128) | ||
239 | return 0; | ||
240 | #endif | ||
183 | return -1; | 241 | return -1; |
184 | } | 242 | } |
185 | 243 | ||
@@ -195,7 +253,7 @@ static int check_gpio(int gpio) | |||
195 | 253 | ||
196 | static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) | 254 | static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) |
197 | { | 255 | { |
198 | u32 reg = bank->base; | 256 | void __iomem *reg = bank->base; |
199 | u32 l; | 257 | u32 l; |
200 | 258 | ||
201 | switch (bank->method) { | 259 | switch (bank->method) { |
@@ -211,6 +269,9 @@ static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) | |||
211 | case METHOD_GPIO_730: | 269 | case METHOD_GPIO_730: |
212 | reg += OMAP730_GPIO_DIR_CONTROL; | 270 | reg += OMAP730_GPIO_DIR_CONTROL; |
213 | break; | 271 | break; |
272 | case METHOD_GPIO_24XX: | ||
273 | reg += OMAP24XX_GPIO_OE; | ||
274 | break; | ||
214 | } | 275 | } |
215 | l = __raw_readl(reg); | 276 | l = __raw_readl(reg); |
216 | if (is_input) | 277 | if (is_input) |
@@ -234,7 +295,7 @@ void omap_set_gpio_direction(int gpio, int is_input) | |||
234 | 295 | ||
235 | static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable) | 296 | static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable) |
236 | { | 297 | { |
237 | u32 reg = bank->base; | 298 | void __iomem *reg = bank->base; |
238 | u32 l = 0; | 299 | u32 l = 0; |
239 | 300 | ||
240 | switch (bank->method) { | 301 | switch (bank->method) { |
@@ -269,6 +330,13 @@ static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable) | |||
269 | else | 330 | else |
270 | l &= ~(1 << gpio); | 331 | l &= ~(1 << gpio); |
271 | break; | 332 | break; |
333 | case METHOD_GPIO_24XX: | ||
334 | if (enable) | ||
335 | reg += OMAP24XX_GPIO_SETDATAOUT; | ||
336 | else | ||
337 | reg += OMAP24XX_GPIO_CLEARDATAOUT; | ||
338 | l = 1 << gpio; | ||
339 | break; | ||
272 | default: | 340 | default: |
273 | BUG(); | 341 | BUG(); |
274 | return; | 342 | return; |
@@ -291,7 +359,7 @@ void omap_set_gpio_dataout(int gpio, int enable) | |||
291 | int omap_get_gpio_datain(int gpio) | 359 | int omap_get_gpio_datain(int gpio) |
292 | { | 360 | { |
293 | struct gpio_bank *bank; | 361 | struct gpio_bank *bank; |
294 | u32 reg; | 362 | void __iomem *reg; |
295 | 363 | ||
296 | if (check_gpio(gpio) < 0) | 364 | if (check_gpio(gpio) < 0) |
297 | return -1; | 365 | return -1; |
@@ -310,109 +378,132 @@ int omap_get_gpio_datain(int gpio) | |||
310 | case METHOD_GPIO_730: | 378 | case METHOD_GPIO_730: |
311 | reg += OMAP730_GPIO_DATA_INPUT; | 379 | reg += OMAP730_GPIO_DATA_INPUT; |
312 | break; | 380 | break; |
381 | case METHOD_GPIO_24XX: | ||
382 | reg += OMAP24XX_GPIO_DATAIN; | ||
383 | break; | ||
313 | default: | 384 | default: |
314 | BUG(); | 385 | BUG(); |
315 | return -1; | 386 | return -1; |
316 | } | 387 | } |
317 | return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0; | 388 | return (__raw_readl(reg) |
389 | & (1 << get_gpio_index(gpio))) != 0; | ||
318 | } | 390 | } |
319 | 391 | ||
320 | static void _set_gpio_edge_ctrl(struct gpio_bank *bank, int gpio, int edge) | 392 | #define MOD_REG_BIT(reg, bit_mask, set) \ |
393 | do { \ | ||
394 | int l = __raw_readl(base + reg); \ | ||
395 | if (set) l |= bit_mask; \ | ||
396 | else l &= ~bit_mask; \ | ||
397 | __raw_writel(l, base + reg); \ | ||
398 | } while(0) | ||
399 | |||
400 | static inline void set_24xx_gpio_triggering(void __iomem *base, int gpio, int trigger) | ||
321 | { | 401 | { |
322 | u32 reg = bank->base; | 402 | u32 gpio_bit = 1 << gpio; |
323 | u32 l; | 403 | |
404 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit, | ||
405 | trigger & IRQT_LOW); | ||
406 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit, | ||
407 | trigger & IRQT_HIGH); | ||
408 | MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit, | ||
409 | trigger & IRQT_RISING); | ||
410 | MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit, | ||
411 | trigger & IRQT_FALLING); | ||
412 | /* FIXME: Possibly do 'set_irq_handler(j, do_level_IRQ)' if only level | ||
413 | * triggering requested. */ | ||
414 | } | ||
415 | |||
416 | static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger) | ||
417 | { | ||
418 | void __iomem *reg = bank->base; | ||
419 | u32 l = 0; | ||
324 | 420 | ||
325 | switch (bank->method) { | 421 | switch (bank->method) { |
326 | case METHOD_MPUIO: | 422 | case METHOD_MPUIO: |
327 | reg += OMAP_MPUIO_GPIO_INT_EDGE; | 423 | reg += OMAP_MPUIO_GPIO_INT_EDGE; |
328 | l = __raw_readl(reg); | 424 | l = __raw_readl(reg); |
329 | if (edge == OMAP_GPIO_RISING_EDGE) | 425 | if (trigger == IRQT_RISING) |
330 | l |= 1 << gpio; | 426 | l |= 1 << gpio; |
331 | else | 427 | else if (trigger == IRQT_FALLING) |
332 | l &= ~(1 << gpio); | 428 | l &= ~(1 << gpio); |
333 | __raw_writel(l, reg); | 429 | else |
430 | goto bad; | ||
334 | break; | 431 | break; |
335 | case METHOD_GPIO_1510: | 432 | case METHOD_GPIO_1510: |
336 | reg += OMAP1510_GPIO_INT_CONTROL; | 433 | reg += OMAP1510_GPIO_INT_CONTROL; |
337 | l = __raw_readl(reg); | 434 | l = __raw_readl(reg); |
338 | if (edge == OMAP_GPIO_RISING_EDGE) | 435 | if (trigger == IRQT_RISING) |
339 | l |= 1 << gpio; | 436 | l |= 1 << gpio; |
340 | else | 437 | else if (trigger == IRQT_FALLING) |
341 | l &= ~(1 << gpio); | 438 | l &= ~(1 << gpio); |
342 | __raw_writel(l, reg); | 439 | else |
440 | goto bad; | ||
343 | break; | 441 | break; |
344 | case METHOD_GPIO_1610: | 442 | case METHOD_GPIO_1610: |
345 | edge &= 0x03; | ||
346 | if (gpio & 0x08) | 443 | if (gpio & 0x08) |
347 | reg += OMAP1610_GPIO_EDGE_CTRL2; | 444 | reg += OMAP1610_GPIO_EDGE_CTRL2; |
348 | else | 445 | else |
349 | reg += OMAP1610_GPIO_EDGE_CTRL1; | 446 | reg += OMAP1610_GPIO_EDGE_CTRL1; |
350 | gpio &= 0x07; | 447 | gpio &= 0x07; |
448 | /* We allow only edge triggering, i.e. two lowest bits */ | ||
449 | if (trigger & ~IRQT_BOTHEDGE) | ||
450 | BUG(); | ||
451 | /* NOTE: knows __IRQT_{FAL,RIS}EDGE match OMAP hardware */ | ||
452 | trigger &= 0x03; | ||
351 | l = __raw_readl(reg); | 453 | l = __raw_readl(reg); |
352 | l &= ~(3 << (gpio << 1)); | 454 | l &= ~(3 << (gpio << 1)); |
353 | l |= edge << (gpio << 1); | 455 | l |= trigger << (gpio << 1); |
354 | __raw_writel(l, reg); | ||
355 | break; | 456 | break; |
356 | case METHOD_GPIO_730: | 457 | case METHOD_GPIO_730: |
357 | reg += OMAP730_GPIO_INT_CONTROL; | 458 | reg += OMAP730_GPIO_INT_CONTROL; |
358 | l = __raw_readl(reg); | 459 | l = __raw_readl(reg); |
359 | if (edge == OMAP_GPIO_RISING_EDGE) | 460 | if (trigger == IRQT_RISING) |
360 | l |= 1 << gpio; | 461 | l |= 1 << gpio; |
361 | else | 462 | else if (trigger == IRQT_FALLING) |
362 | l &= ~(1 << gpio); | 463 | l &= ~(1 << gpio); |
363 | __raw_writel(l, reg); | 464 | else |
465 | goto bad; | ||
466 | break; | ||
467 | case METHOD_GPIO_24XX: | ||
468 | set_24xx_gpio_triggering(reg, gpio, trigger); | ||
364 | break; | 469 | break; |
365 | default: | 470 | default: |
366 | BUG(); | 471 | BUG(); |
367 | return; | 472 | goto bad; |
368 | } | 473 | } |
474 | __raw_writel(l, reg); | ||
475 | return 0; | ||
476 | bad: | ||
477 | return -EINVAL; | ||
369 | } | 478 | } |
370 | 479 | ||
371 | void omap_set_gpio_edge_ctrl(int gpio, int edge) | 480 | static int gpio_irq_type(unsigned irq, unsigned type) |
372 | { | 481 | { |
373 | struct gpio_bank *bank; | 482 | struct gpio_bank *bank; |
483 | unsigned gpio; | ||
484 | int retval; | ||
485 | |||
486 | if (irq > IH_MPUIO_BASE) | ||
487 | gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); | ||
488 | else | ||
489 | gpio = irq - IH_GPIO_BASE; | ||
374 | 490 | ||
375 | if (check_gpio(gpio) < 0) | 491 | if (check_gpio(gpio) < 0) |
376 | return; | 492 | return -EINVAL; |
493 | |||
494 | if (type & (__IRQT_LOWLVL|__IRQT_HIGHLVL|IRQT_PROBE)) | ||
495 | return -EINVAL; | ||
496 | |||
377 | bank = get_gpio_bank(gpio); | 497 | bank = get_gpio_bank(gpio); |
378 | spin_lock(&bank->lock); | 498 | spin_lock(&bank->lock); |
379 | _set_gpio_edge_ctrl(bank, get_gpio_index(gpio), edge); | 499 | retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type); |
380 | spin_unlock(&bank->lock); | 500 | spin_unlock(&bank->lock); |
381 | } | 501 | return retval; |
382 | |||
383 | |||
384 | static int _get_gpio_edge_ctrl(struct gpio_bank *bank, int gpio) | ||
385 | { | ||
386 | u32 reg = bank->base, l; | ||
387 | |||
388 | switch (bank->method) { | ||
389 | case METHOD_MPUIO: | ||
390 | l = __raw_readl(reg + OMAP_MPUIO_GPIO_INT_EDGE); | ||
391 | return (l & (1 << gpio)) ? | ||
392 | OMAP_GPIO_RISING_EDGE : OMAP_GPIO_FALLING_EDGE; | ||
393 | case METHOD_GPIO_1510: | ||
394 | l = __raw_readl(reg + OMAP1510_GPIO_INT_CONTROL); | ||
395 | return (l & (1 << gpio)) ? | ||
396 | OMAP_GPIO_RISING_EDGE : OMAP_GPIO_FALLING_EDGE; | ||
397 | case METHOD_GPIO_1610: | ||
398 | if (gpio & 0x08) | ||
399 | reg += OMAP1610_GPIO_EDGE_CTRL2; | ||
400 | else | ||
401 | reg += OMAP1610_GPIO_EDGE_CTRL1; | ||
402 | return (__raw_readl(reg) >> ((gpio & 0x07) << 1)) & 0x03; | ||
403 | case METHOD_GPIO_730: | ||
404 | l = __raw_readl(reg + OMAP730_GPIO_INT_CONTROL); | ||
405 | return (l & (1 << gpio)) ? | ||
406 | OMAP_GPIO_RISING_EDGE : OMAP_GPIO_FALLING_EDGE; | ||
407 | default: | ||
408 | BUG(); | ||
409 | return -1; | ||
410 | } | ||
411 | } | 502 | } |
412 | 503 | ||
413 | static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) | 504 | static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
414 | { | 505 | { |
415 | u32 reg = bank->base; | 506 | void __iomem *reg = bank->base; |
416 | 507 | ||
417 | switch (bank->method) { | 508 | switch (bank->method) { |
418 | case METHOD_MPUIO: | 509 | case METHOD_MPUIO: |
@@ -428,6 +519,9 @@ static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) | |||
428 | case METHOD_GPIO_730: | 519 | case METHOD_GPIO_730: |
429 | reg += OMAP730_GPIO_INT_STATUS; | 520 | reg += OMAP730_GPIO_INT_STATUS; |
430 | break; | 521 | break; |
522 | case METHOD_GPIO_24XX: | ||
523 | reg += OMAP24XX_GPIO_IRQSTATUS1; | ||
524 | break; | ||
431 | default: | 525 | default: |
432 | BUG(); | 526 | BUG(); |
433 | return; | 527 | return; |
@@ -442,7 +536,7 @@ static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) | |||
442 | 536 | ||
443 | static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable) | 537 | static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable) |
444 | { | 538 | { |
445 | u32 reg = bank->base; | 539 | void __iomem *reg = bank->base; |
446 | u32 l; | 540 | u32 l; |
447 | 541 | ||
448 | switch (bank->method) { | 542 | switch (bank->method) { |
@@ -477,6 +571,13 @@ static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enab | |||
477 | else | 571 | else |
478 | l |= gpio_mask; | 572 | l |= gpio_mask; |
479 | break; | 573 | break; |
574 | case METHOD_GPIO_24XX: | ||
575 | if (enable) | ||
576 | reg += OMAP24XX_GPIO_SETIRQENABLE1; | ||
577 | else | ||
578 | reg += OMAP24XX_GPIO_CLEARIRQENABLE1; | ||
579 | l = gpio_mask; | ||
580 | break; | ||
480 | default: | 581 | default: |
481 | BUG(); | 582 | BUG(); |
482 | return; | 583 | return; |
@@ -489,6 +590,50 @@ static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int ena | |||
489 | _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable); | 590 | _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable); |
490 | } | 591 | } |
491 | 592 | ||
593 | /* | ||
594 | * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register. | ||
595 | * 1510 does not seem to have a wake-up register. If JTAG is connected | ||
596 | * to the target, system will wake up always on GPIO events. While | ||
597 | * system is running all registered GPIO interrupts need to have wake-up | ||
598 | * enabled. When system is suspended, only selected GPIO interrupts need | ||
599 | * to have wake-up enabled. | ||
600 | */ | ||
601 | static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) | ||
602 | { | ||
603 | switch (bank->method) { | ||
604 | case METHOD_GPIO_1610: | ||
605 | case METHOD_GPIO_24XX: | ||
606 | spin_lock(&bank->lock); | ||
607 | if (enable) | ||
608 | bank->suspend_wakeup |= (1 << gpio); | ||
609 | else | ||
610 | bank->suspend_wakeup &= ~(1 << gpio); | ||
611 | spin_unlock(&bank->lock); | ||
612 | return 0; | ||
613 | default: | ||
614 | printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n", | ||
615 | bank->method); | ||
616 | return -EINVAL; | ||
617 | } | ||
618 | } | ||
619 | |||
620 | /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ | ||
621 | static int gpio_wake_enable(unsigned int irq, unsigned int enable) | ||
622 | { | ||
623 | unsigned int gpio = irq - IH_GPIO_BASE; | ||
624 | struct gpio_bank *bank; | ||
625 | int retval; | ||
626 | |||
627 | if (check_gpio(gpio) < 0) | ||
628 | return -ENODEV; | ||
629 | bank = get_gpio_bank(gpio); | ||
630 | spin_lock(&bank->lock); | ||
631 | retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable); | ||
632 | spin_unlock(&bank->lock); | ||
633 | |||
634 | return retval; | ||
635 | } | ||
636 | |||
492 | int omap_request_gpio(int gpio) | 637 | int omap_request_gpio(int gpio) |
493 | { | 638 | { |
494 | struct gpio_bank *bank; | 639 | struct gpio_bank *bank; |
@@ -505,15 +650,33 @@ int omap_request_gpio(int gpio) | |||
505 | return -1; | 650 | return -1; |
506 | } | 651 | } |
507 | bank->reserved_map |= (1 << get_gpio_index(gpio)); | 652 | bank->reserved_map |= (1 << get_gpio_index(gpio)); |
653 | |||
654 | /* Set trigger to none. You need to enable the trigger after request_irq */ | ||
655 | _set_gpio_triggering(bank, get_gpio_index(gpio), IRQT_NOEDGE); | ||
656 | |||
508 | #ifdef CONFIG_ARCH_OMAP1510 | 657 | #ifdef CONFIG_ARCH_OMAP1510 |
509 | if (bank->method == METHOD_GPIO_1510) { | 658 | if (bank->method == METHOD_GPIO_1510) { |
510 | u32 reg; | 659 | void __iomem *reg; |
511 | 660 | ||
512 | /* Claim the pin for the ARM */ | 661 | /* Claim the pin for MPU */ |
513 | reg = bank->base + OMAP1510_GPIO_PIN_CONTROL; | 662 | reg = bank->base + OMAP1510_GPIO_PIN_CONTROL; |
514 | __raw_writel(__raw_readl(reg) | (1 << get_gpio_index(gpio)), reg); | 663 | __raw_writel(__raw_readl(reg) | (1 << get_gpio_index(gpio)), reg); |
515 | } | 664 | } |
516 | #endif | 665 | #endif |
666 | #ifdef CONFIG_ARCH_OMAP16XX | ||
667 | if (bank->method == METHOD_GPIO_1610) { | ||
668 | /* Enable wake-up during idle for dynamic tick */ | ||
669 | void __iomem *reg = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; | ||
670 | __raw_writel(1 << get_gpio_index(gpio), reg); | ||
671 | } | ||
672 | #endif | ||
673 | #ifdef CONFIG_ARCH_OMAP24XX | ||
674 | if (bank->method == METHOD_GPIO_24XX) { | ||
675 | /* Enable wake-up during idle for dynamic tick */ | ||
676 | void __iomem *reg = bank->base + OMAP24XX_GPIO_SETWKUENA; | ||
677 | __raw_writel(1 << get_gpio_index(gpio), reg); | ||
678 | } | ||
679 | #endif | ||
517 | spin_unlock(&bank->lock); | 680 | spin_unlock(&bank->lock); |
518 | 681 | ||
519 | return 0; | 682 | return 0; |
@@ -533,6 +696,20 @@ void omap_free_gpio(int gpio) | |||
533 | spin_unlock(&bank->lock); | 696 | spin_unlock(&bank->lock); |
534 | return; | 697 | return; |
535 | } | 698 | } |
699 | #ifdef CONFIG_ARCH_OMAP16XX | ||
700 | if (bank->method == METHOD_GPIO_1610) { | ||
701 | /* Disable wake-up during idle for dynamic tick */ | ||
702 | void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; | ||
703 | __raw_writel(1 << get_gpio_index(gpio), reg); | ||
704 | } | ||
705 | #endif | ||
706 | #ifdef CONFIG_ARCH_OMAP24XX | ||
707 | if (bank->method == METHOD_GPIO_24XX) { | ||
708 | /* Disable wake-up during idle for dynamic tick */ | ||
709 | void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA; | ||
710 | __raw_writel(1 << get_gpio_index(gpio), reg); | ||
711 | } | ||
712 | #endif | ||
536 | bank->reserved_map &= ~(1 << get_gpio_index(gpio)); | 713 | bank->reserved_map &= ~(1 << get_gpio_index(gpio)); |
537 | _set_gpio_direction(bank, get_gpio_index(gpio), 1); | 714 | _set_gpio_direction(bank, get_gpio_index(gpio), 1); |
538 | _set_gpio_irqenable(bank, gpio, 0); | 715 | _set_gpio_irqenable(bank, gpio, 0); |
@@ -552,7 +729,7 @@ void omap_free_gpio(int gpio) | |||
552 | static void gpio_irq_handler(unsigned int irq, struct irqdesc *desc, | 729 | static void gpio_irq_handler(unsigned int irq, struct irqdesc *desc, |
553 | struct pt_regs *regs) | 730 | struct pt_regs *regs) |
554 | { | 731 | { |
555 | u32 isr_reg = 0; | 732 | void __iomem *isr_reg = NULL; |
556 | u32 isr; | 733 | u32 isr; |
557 | unsigned int gpio_irq; | 734 | unsigned int gpio_irq; |
558 | struct gpio_bank *bank; | 735 | struct gpio_bank *bank; |
@@ -574,24 +751,30 @@ static void gpio_irq_handler(unsigned int irq, struct irqdesc *desc, | |||
574 | if (bank->method == METHOD_GPIO_730) | 751 | if (bank->method == METHOD_GPIO_730) |
575 | isr_reg = bank->base + OMAP730_GPIO_INT_STATUS; | 752 | isr_reg = bank->base + OMAP730_GPIO_INT_STATUS; |
576 | #endif | 753 | #endif |
754 | #ifdef CONFIG_ARCH_OMAP24XX | ||
755 | if (bank->method == METHOD_GPIO_24XX) | ||
756 | isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1; | ||
757 | #endif | ||
577 | 758 | ||
578 | isr = __raw_readl(isr_reg); | 759 | while(1) { |
579 | _enable_gpio_irqbank(bank, isr, 0); | 760 | isr = __raw_readl(isr_reg); |
580 | _clear_gpio_irqbank(bank, isr); | 761 | _enable_gpio_irqbank(bank, isr, 0); |
581 | _enable_gpio_irqbank(bank, isr, 1); | 762 | _clear_gpio_irqbank(bank, isr); |
582 | desc->chip->unmask(irq); | 763 | _enable_gpio_irqbank(bank, isr, 1); |
583 | 764 | desc->chip->unmask(irq); | |
584 | if (unlikely(!isr)) | 765 | |
585 | return; | 766 | if (!isr) |
586 | 767 | break; | |
587 | gpio_irq = bank->virtual_irq_start; | 768 | |
588 | for (; isr != 0; isr >>= 1, gpio_irq++) { | 769 | gpio_irq = bank->virtual_irq_start; |
589 | struct irqdesc *d; | 770 | for (; isr != 0; isr >>= 1, gpio_irq++) { |
590 | if (!(isr & 1)) | 771 | struct irqdesc *d; |
591 | continue; | 772 | if (!(isr & 1)) |
592 | d = irq_desc + gpio_irq; | 773 | continue; |
593 | desc_handle_irq(gpio_irq, d, regs); | 774 | d = irq_desc + gpio_irq; |
594 | } | 775 | desc_handle_irq(gpio_irq, d, regs); |
776 | } | ||
777 | } | ||
595 | } | 778 | } |
596 | 779 | ||
597 | static void gpio_ack_irq(unsigned int irq) | 780 | static void gpio_ack_irq(unsigned int irq) |
@@ -613,14 +796,10 @@ static void gpio_mask_irq(unsigned int irq) | |||
613 | static void gpio_unmask_irq(unsigned int irq) | 796 | static void gpio_unmask_irq(unsigned int irq) |
614 | { | 797 | { |
615 | unsigned int gpio = irq - IH_GPIO_BASE; | 798 | unsigned int gpio = irq - IH_GPIO_BASE; |
799 | unsigned int gpio_idx = get_gpio_index(gpio); | ||
616 | struct gpio_bank *bank = get_gpio_bank(gpio); | 800 | struct gpio_bank *bank = get_gpio_bank(gpio); |
617 | 801 | ||
618 | if (_get_gpio_edge_ctrl(bank, get_gpio_index(gpio)) == OMAP_GPIO_NO_EDGE) { | 802 | _set_gpio_irqenable(bank, gpio_idx, 1); |
619 | printk(KERN_ERR "OMAP GPIO %d: trying to enable GPIO IRQ while no edge is set\n", | ||
620 | gpio); | ||
621 | _set_gpio_edge_ctrl(bank, get_gpio_index(gpio), OMAP_GPIO_RISING_EDGE); | ||
622 | } | ||
623 | _set_gpio_irqenable(bank, gpio, 1); | ||
624 | } | 803 | } |
625 | 804 | ||
626 | static void mpuio_ack_irq(unsigned int irq) | 805 | static void mpuio_ack_irq(unsigned int irq) |
@@ -645,9 +824,11 @@ static void mpuio_unmask_irq(unsigned int irq) | |||
645 | } | 824 | } |
646 | 825 | ||
647 | static struct irqchip gpio_irq_chip = { | 826 | static struct irqchip gpio_irq_chip = { |
648 | .ack = gpio_ack_irq, | 827 | .ack = gpio_ack_irq, |
649 | .mask = gpio_mask_irq, | 828 | .mask = gpio_mask_irq, |
650 | .unmask = gpio_unmask_irq, | 829 | .unmask = gpio_unmask_irq, |
830 | .set_type = gpio_irq_type, | ||
831 | .set_wake = gpio_wake_enable, | ||
651 | }; | 832 | }; |
652 | 833 | ||
653 | static struct irqchip mpuio_irq_chip = { | 834 | static struct irqchip mpuio_irq_chip = { |
@@ -657,6 +838,7 @@ static struct irqchip mpuio_irq_chip = { | |||
657 | }; | 838 | }; |
658 | 839 | ||
659 | static int initialized = 0; | 840 | static int initialized = 0; |
841 | static struct clk * gpio_ck = NULL; | ||
660 | 842 | ||
661 | static int __init _omap_gpio_init(void) | 843 | static int __init _omap_gpio_init(void) |
662 | { | 844 | { |
@@ -665,6 +847,14 @@ static int __init _omap_gpio_init(void) | |||
665 | 847 | ||
666 | initialized = 1; | 848 | initialized = 1; |
667 | 849 | ||
850 | if (cpu_is_omap1510()) { | ||
851 | gpio_ck = clk_get(NULL, "arm_gpio_ck"); | ||
852 | if (IS_ERR(gpio_ck)) | ||
853 | printk("Could not get arm_gpio_ck\n"); | ||
854 | else | ||
855 | clk_use(gpio_ck); | ||
856 | } | ||
857 | |||
668 | #ifdef CONFIG_ARCH_OMAP1510 | 858 | #ifdef CONFIG_ARCH_OMAP1510 |
669 | if (cpu_is_omap1510()) { | 859 | if (cpu_is_omap1510()) { |
670 | printk(KERN_INFO "OMAP1510 GPIO hardware\n"); | 860 | printk(KERN_INFO "OMAP1510 GPIO hardware\n"); |
@@ -674,7 +864,7 @@ static int __init _omap_gpio_init(void) | |||
674 | #endif | 864 | #endif |
675 | #if defined(CONFIG_ARCH_OMAP16XX) | 865 | #if defined(CONFIG_ARCH_OMAP16XX) |
676 | if (cpu_is_omap16xx()) { | 866 | if (cpu_is_omap16xx()) { |
677 | int rev; | 867 | u32 rev; |
678 | 868 | ||
679 | gpio_bank_count = 5; | 869 | gpio_bank_count = 5; |
680 | gpio_bank = gpio_bank_1610; | 870 | gpio_bank = gpio_bank_1610; |
@@ -690,6 +880,17 @@ static int __init _omap_gpio_init(void) | |||
690 | gpio_bank = gpio_bank_730; | 880 | gpio_bank = gpio_bank_730; |
691 | } | 881 | } |
692 | #endif | 882 | #endif |
883 | #ifdef CONFIG_ARCH_OMAP24XX | ||
884 | if (cpu_is_omap24xx()) { | ||
885 | int rev; | ||
886 | |||
887 | gpio_bank_count = 4; | ||
888 | gpio_bank = gpio_bank_24xx; | ||
889 | rev = omap_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); | ||
890 | printk(KERN_INFO "OMAP24xx GPIO hardware version %d.%d\n", | ||
891 | (rev >> 4) & 0x0f, rev & 0x0f); | ||
892 | } | ||
893 | #endif | ||
693 | for (i = 0; i < gpio_bank_count; i++) { | 894 | for (i = 0; i < gpio_bank_count; i++) { |
694 | int j, gpio_count = 16; | 895 | int j, gpio_count = 16; |
695 | 896 | ||
@@ -710,6 +911,7 @@ static int __init _omap_gpio_init(void) | |||
710 | if (bank->method == METHOD_GPIO_1610) { | 911 | if (bank->method == METHOD_GPIO_1610) { |
711 | __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1); | 912 | __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1); |
712 | __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1); | 913 | __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1); |
914 | __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG); | ||
713 | } | 915 | } |
714 | #endif | 916 | #endif |
715 | #ifdef CONFIG_ARCH_OMAP730 | 917 | #ifdef CONFIG_ARCH_OMAP730 |
@@ -720,6 +922,14 @@ static int __init _omap_gpio_init(void) | |||
720 | gpio_count = 32; /* 730 has 32-bit GPIOs */ | 922 | gpio_count = 32; /* 730 has 32-bit GPIOs */ |
721 | } | 923 | } |
722 | #endif | 924 | #endif |
925 | #ifdef CONFIG_ARCH_OMAP24XX | ||
926 | if (bank->method == METHOD_GPIO_24XX) { | ||
927 | __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1); | ||
928 | __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1); | ||
929 | |||
930 | gpio_count = 32; | ||
931 | } | ||
932 | #endif | ||
723 | for (j = bank->virtual_irq_start; | 933 | for (j = bank->virtual_irq_start; |
724 | j < bank->virtual_irq_start + gpio_count; j++) { | 934 | j < bank->virtual_irq_start + gpio_count; j++) { |
725 | if (bank->method == METHOD_MPUIO) | 935 | if (bank->method == METHOD_MPUIO) |
@@ -735,12 +945,97 @@ static int __init _omap_gpio_init(void) | |||
735 | 945 | ||
736 | /* Enable system clock for GPIO module. | 946 | /* Enable system clock for GPIO module. |
737 | * The CAM_CLK_CTRL *is* really the right place. */ | 947 | * The CAM_CLK_CTRL *is* really the right place. */ |
738 | if (cpu_is_omap1610() || cpu_is_omap1710()) | 948 | if (cpu_is_omap16xx()) |
739 | omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL); | 949 | omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL); |
740 | 950 | ||
741 | return 0; | 951 | return 0; |
742 | } | 952 | } |
743 | 953 | ||
954 | #if defined (CONFIG_ARCH_OMAP16XX) || defined (CONFIG_ARCH_OMAP24XX) | ||
955 | static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg) | ||
956 | { | ||
957 | int i; | ||
958 | |||
959 | if (!cpu_is_omap24xx() && !cpu_is_omap16xx()) | ||
960 | return 0; | ||
961 | |||
962 | for (i = 0; i < gpio_bank_count; i++) { | ||
963 | struct gpio_bank *bank = &gpio_bank[i]; | ||
964 | void __iomem *wake_status; | ||
965 | void __iomem *wake_clear; | ||
966 | void __iomem *wake_set; | ||
967 | |||
968 | switch (bank->method) { | ||
969 | case METHOD_GPIO_1610: | ||
970 | wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE; | ||
971 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; | ||
972 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; | ||
973 | break; | ||
974 | case METHOD_GPIO_24XX: | ||
975 | wake_status = bank->base + OMAP24XX_GPIO_SETWKUENA; | ||
976 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; | ||
977 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; | ||
978 | break; | ||
979 | default: | ||
980 | continue; | ||
981 | } | ||
982 | |||
983 | spin_lock(&bank->lock); | ||
984 | bank->saved_wakeup = __raw_readl(wake_status); | ||
985 | __raw_writel(0xffffffff, wake_clear); | ||
986 | __raw_writel(bank->suspend_wakeup, wake_set); | ||
987 | spin_unlock(&bank->lock); | ||
988 | } | ||
989 | |||
990 | return 0; | ||
991 | } | ||
992 | |||
993 | static int omap_gpio_resume(struct sys_device *dev) | ||
994 | { | ||
995 | int i; | ||
996 | |||
997 | if (!cpu_is_omap24xx() && !cpu_is_omap16xx()) | ||
998 | return 0; | ||
999 | |||
1000 | for (i = 0; i < gpio_bank_count; i++) { | ||
1001 | struct gpio_bank *bank = &gpio_bank[i]; | ||
1002 | void __iomem *wake_clear; | ||
1003 | void __iomem *wake_set; | ||
1004 | |||
1005 | switch (bank->method) { | ||
1006 | case METHOD_GPIO_1610: | ||
1007 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; | ||
1008 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; | ||
1009 | break; | ||
1010 | case METHOD_GPIO_24XX: | ||
1011 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; | ||
1012 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; | ||
1013 | break; | ||
1014 | default: | ||
1015 | continue; | ||
1016 | } | ||
1017 | |||
1018 | spin_lock(&bank->lock); | ||
1019 | __raw_writel(0xffffffff, wake_clear); | ||
1020 | __raw_writel(bank->saved_wakeup, wake_set); | ||
1021 | spin_unlock(&bank->lock); | ||
1022 | } | ||
1023 | |||
1024 | return 0; | ||
1025 | } | ||
1026 | |||
1027 | static struct sysdev_class omap_gpio_sysclass = { | ||
1028 | set_kset_name("gpio"), | ||
1029 | .suspend = omap_gpio_suspend, | ||
1030 | .resume = omap_gpio_resume, | ||
1031 | }; | ||
1032 | |||
1033 | static struct sys_device omap_gpio_device = { | ||
1034 | .id = 0, | ||
1035 | .cls = &omap_gpio_sysclass, | ||
1036 | }; | ||
1037 | #endif | ||
1038 | |||
744 | /* | 1039 | /* |
745 | * This may get called early from board specific init | 1040 | * This may get called early from board specific init |
746 | */ | 1041 | */ |
@@ -752,11 +1047,30 @@ int omap_gpio_init(void) | |||
752 | return 0; | 1047 | return 0; |
753 | } | 1048 | } |
754 | 1049 | ||
1050 | static int __init omap_gpio_sysinit(void) | ||
1051 | { | ||
1052 | int ret = 0; | ||
1053 | |||
1054 | if (!initialized) | ||
1055 | ret = _omap_gpio_init(); | ||
1056 | |||
1057 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) | ||
1058 | if (cpu_is_omap16xx() || cpu_is_omap24xx()) { | ||
1059 | if (ret == 0) { | ||
1060 | ret = sysdev_class_register(&omap_gpio_sysclass); | ||
1061 | if (ret == 0) | ||
1062 | ret = sysdev_register(&omap_gpio_device); | ||
1063 | } | ||
1064 | } | ||
1065 | #endif | ||
1066 | |||
1067 | return ret; | ||
1068 | } | ||
1069 | |||
755 | EXPORT_SYMBOL(omap_request_gpio); | 1070 | EXPORT_SYMBOL(omap_request_gpio); |
756 | EXPORT_SYMBOL(omap_free_gpio); | 1071 | EXPORT_SYMBOL(omap_free_gpio); |
757 | EXPORT_SYMBOL(omap_set_gpio_direction); | 1072 | EXPORT_SYMBOL(omap_set_gpio_direction); |
758 | EXPORT_SYMBOL(omap_set_gpio_dataout); | 1073 | EXPORT_SYMBOL(omap_set_gpio_dataout); |
759 | EXPORT_SYMBOL(omap_get_gpio_datain); | 1074 | EXPORT_SYMBOL(omap_get_gpio_datain); |
760 | EXPORT_SYMBOL(omap_set_gpio_edge_ctrl); | ||
761 | 1075 | ||
762 | arch_initcall(omap_gpio_init); | 1076 | arch_initcall(omap_gpio_sysinit); |