blob: 7fd89ba8d3b5939684ab6999a12fc19c5430b31e [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
2 * linux/arch/arm/plat-omap/gpio.c
3 *
4 * Support functions for OMAP GPIO
5 *
Tony Lindgren92105bb2005-09-07 17:20:26 +01006 * Copyright (C) 2003-2005 Nokia Corporation
Jan Engelhardt96de0e22007-10-19 23:21:04 +02007 * Written by Juha Yrjölä <juha.yrjola@nokia.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01008 *
Santosh Shilimkar44169072009-05-28 14:16:04 -07009 * Copyright (C) 2009 Texas Instruments
10 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
11 *
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010017#include <linux/init.h>
18#include <linux/module.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010019#include <linux/interrupt.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010020#include <linux/sysdev.h>
21#include <linux/err.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000022#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010024
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010026#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/irqs.h>
28#include <mach/gpio.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010029#include <asm/mach/irq.h>
30
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010031/*
32 * OMAP1510 GPIO registers
33 */
Russell King7c7095a2008-09-05 15:49:14 +010034#define OMAP1510_GPIO_BASE IO_ADDRESS(0xfffce000)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010035#define OMAP1510_GPIO_DATA_INPUT 0x00
36#define OMAP1510_GPIO_DATA_OUTPUT 0x04
37#define OMAP1510_GPIO_DIR_CONTROL 0x08
38#define OMAP1510_GPIO_INT_CONTROL 0x0c
39#define OMAP1510_GPIO_INT_MASK 0x10
40#define OMAP1510_GPIO_INT_STATUS 0x14
41#define OMAP1510_GPIO_PIN_CONTROL 0x18
42
43#define OMAP1510_IH_GPIO_BASE 64
44
45/*
46 * OMAP1610 specific GPIO registers
47 */
Russell King7c7095a2008-09-05 15:49:14 +010048#define OMAP1610_GPIO1_BASE IO_ADDRESS(0xfffbe400)
49#define OMAP1610_GPIO2_BASE IO_ADDRESS(0xfffbec00)
50#define OMAP1610_GPIO3_BASE IO_ADDRESS(0xfffbb400)
51#define OMAP1610_GPIO4_BASE IO_ADDRESS(0xfffbbc00)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010052#define OMAP1610_GPIO_REVISION 0x0000
53#define OMAP1610_GPIO_SYSCONFIG 0x0010
54#define OMAP1610_GPIO_SYSSTATUS 0x0014
55#define OMAP1610_GPIO_IRQSTATUS1 0x0018
56#define OMAP1610_GPIO_IRQENABLE1 0x001c
Tony Lindgren92105bb2005-09-07 17:20:26 +010057#define OMAP1610_GPIO_WAKEUPENABLE 0x0028
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010058#define OMAP1610_GPIO_DATAIN 0x002c
59#define OMAP1610_GPIO_DATAOUT 0x0030
60#define OMAP1610_GPIO_DIRECTION 0x0034
61#define OMAP1610_GPIO_EDGE_CTRL1 0x0038
62#define OMAP1610_GPIO_EDGE_CTRL2 0x003c
63#define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
Tony Lindgren92105bb2005-09-07 17:20:26 +010064#define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010065#define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
66#define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
Tony Lindgren92105bb2005-09-07 17:20:26 +010067#define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010068#define OMAP1610_GPIO_SET_DATAOUT 0x00f0
69
70/*
71 * OMAP730 specific GPIO registers
72 */
Russell King7c7095a2008-09-05 15:49:14 +010073#define OMAP730_GPIO1_BASE IO_ADDRESS(0xfffbc000)
74#define OMAP730_GPIO2_BASE IO_ADDRESS(0xfffbc800)
75#define OMAP730_GPIO3_BASE IO_ADDRESS(0xfffbd000)
76#define OMAP730_GPIO4_BASE IO_ADDRESS(0xfffbd800)
77#define OMAP730_GPIO5_BASE IO_ADDRESS(0xfffbe000)
78#define OMAP730_GPIO6_BASE IO_ADDRESS(0xfffbe800)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010079#define OMAP730_GPIO_DATA_INPUT 0x00
80#define OMAP730_GPIO_DATA_OUTPUT 0x04
81#define OMAP730_GPIO_DIR_CONTROL 0x08
82#define OMAP730_GPIO_INT_CONTROL 0x0c
83#define OMAP730_GPIO_INT_MASK 0x10
84#define OMAP730_GPIO_INT_STATUS 0x14
85
Tony Lindgren92105bb2005-09-07 17:20:26 +010086/*
Zebediah C. McClure56739a62009-03-23 18:07:40 -070087 * OMAP850 specific GPIO registers
88 */
89#define OMAP850_GPIO1_BASE IO_ADDRESS(0xfffbc000)
90#define OMAP850_GPIO2_BASE IO_ADDRESS(0xfffbc800)
91#define OMAP850_GPIO3_BASE IO_ADDRESS(0xfffbd000)
92#define OMAP850_GPIO4_BASE IO_ADDRESS(0xfffbd800)
93#define OMAP850_GPIO5_BASE IO_ADDRESS(0xfffbe000)
94#define OMAP850_GPIO6_BASE IO_ADDRESS(0xfffbe800)
95#define OMAP850_GPIO_DATA_INPUT 0x00
96#define OMAP850_GPIO_DATA_OUTPUT 0x04
97#define OMAP850_GPIO_DIR_CONTROL 0x08
98#define OMAP850_GPIO_INT_CONTROL 0x0c
99#define OMAP850_GPIO_INT_MASK 0x10
100#define OMAP850_GPIO_INT_STATUS 0x14
101
102/*
Tony Lindgren92105bb2005-09-07 17:20:26 +0100103 * omap24xx specific GPIO registers
104 */
Russell King7c7095a2008-09-05 15:49:14 +0100105#define OMAP242X_GPIO1_BASE IO_ADDRESS(0x48018000)
106#define OMAP242X_GPIO2_BASE IO_ADDRESS(0x4801a000)
107#define OMAP242X_GPIO3_BASE IO_ADDRESS(0x4801c000)
108#define OMAP242X_GPIO4_BASE IO_ADDRESS(0x4801e000)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800109
Russell King7c7095a2008-09-05 15:49:14 +0100110#define OMAP243X_GPIO1_BASE IO_ADDRESS(0x4900C000)
111#define OMAP243X_GPIO2_BASE IO_ADDRESS(0x4900E000)
112#define OMAP243X_GPIO3_BASE IO_ADDRESS(0x49010000)
113#define OMAP243X_GPIO4_BASE IO_ADDRESS(0x49012000)
114#define OMAP243X_GPIO5_BASE IO_ADDRESS(0x480B6000)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800115
Tony Lindgren92105bb2005-09-07 17:20:26 +0100116#define OMAP24XX_GPIO_REVISION 0x0000
117#define OMAP24XX_GPIO_SYSCONFIG 0x0010
118#define OMAP24XX_GPIO_SYSSTATUS 0x0014
119#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300120#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
121#define OMAP24XX_GPIO_IRQENABLE2 0x002c
Tony Lindgren92105bb2005-09-07 17:20:26 +0100122#define OMAP24XX_GPIO_IRQENABLE1 0x001c
Tero Kristo723fdb72008-11-26 14:35:16 -0800123#define OMAP24XX_GPIO_WAKE_EN 0x0020
Tony Lindgren92105bb2005-09-07 17:20:26 +0100124#define OMAP24XX_GPIO_CTRL 0x0030
125#define OMAP24XX_GPIO_OE 0x0034
126#define OMAP24XX_GPIO_DATAIN 0x0038
127#define OMAP24XX_GPIO_DATAOUT 0x003c
128#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
129#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
130#define OMAP24XX_GPIO_RISINGDETECT 0x0048
131#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700132#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
133#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
Tony Lindgren92105bb2005-09-07 17:20:26 +0100134#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
135#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
136#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
137#define OMAP24XX_GPIO_SETWKUENA 0x0084
138#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
139#define OMAP24XX_GPIO_SETDATAOUT 0x0094
140
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800141/*
142 * omap34xx specific GPIO registers
143 */
144
Russell King7c7095a2008-09-05 15:49:14 +0100145#define OMAP34XX_GPIO1_BASE IO_ADDRESS(0x48310000)
146#define OMAP34XX_GPIO2_BASE IO_ADDRESS(0x49050000)
147#define OMAP34XX_GPIO3_BASE IO_ADDRESS(0x49052000)
148#define OMAP34XX_GPIO4_BASE IO_ADDRESS(0x49054000)
149#define OMAP34XX_GPIO5_BASE IO_ADDRESS(0x49056000)
150#define OMAP34XX_GPIO6_BASE IO_ADDRESS(0x49058000)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800151
Santosh Shilimkar44169072009-05-28 14:16:04 -0700152/*
153 * OMAP44XX specific GPIO registers
154 */
155#define OMAP44XX_GPIO1_BASE IO_ADDRESS(0x4a310000)
156#define OMAP44XX_GPIO2_BASE IO_ADDRESS(0x48055000)
157#define OMAP44XX_GPIO3_BASE IO_ADDRESS(0x48057000)
158#define OMAP44XX_GPIO4_BASE IO_ADDRESS(0x48059000)
159#define OMAP44XX_GPIO5_BASE IO_ADDRESS(0x4805B000)
160#define OMAP44XX_GPIO6_BASE IO_ADDRESS(0x4805D000)
161
Russell King7c7095a2008-09-05 15:49:14 +0100162#define OMAP_MPUIO_VBASE IO_ADDRESS(OMAP_MPUIO_BASE)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800163
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100164struct gpio_bank {
Tony Lindgren92105bb2005-09-07 17:20:26 +0100165 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100166 u16 irq;
167 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100168 int method;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700169#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
170 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100171 u32 suspend_wakeup;
172 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800173#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700174#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
175 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800176 u32 non_wakeup_gpios;
177 u32 enabled_non_wakeup_gpios;
178
179 u32 saved_datain;
180 u32 saved_fallingdetect;
181 u32 saved_risingdetect;
182#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800183 u32 level_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100184 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800185 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800186 struct clk *dbck;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100187};
188
189#define METHOD_MPUIO 0
190#define METHOD_GPIO_1510 1
191#define METHOD_GPIO_1610 2
192#define METHOD_GPIO_730 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700193#define METHOD_GPIO_850 4
194#define METHOD_GPIO_24XX 5
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100195
Tony Lindgren92105bb2005-09-07 17:20:26 +0100196#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100197static struct gpio_bank gpio_bank_1610[5] = {
Russell King7c7095a2008-09-05 15:49:14 +0100198 { OMAP_MPUIO_VBASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO},
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100199 { OMAP1610_GPIO1_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1610 },
200 { OMAP1610_GPIO2_BASE, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16, METHOD_GPIO_1610 },
201 { OMAP1610_GPIO3_BASE, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32, METHOD_GPIO_1610 },
202 { OMAP1610_GPIO4_BASE, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48, METHOD_GPIO_1610 },
203};
204#endif
205
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000206#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100207static struct gpio_bank gpio_bank_1510[2] = {
Russell King7c7095a2008-09-05 15:49:14 +0100208 { OMAP_MPUIO_VBASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100209 { OMAP1510_GPIO_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1510 }
210};
211#endif
212
213#ifdef CONFIG_ARCH_OMAP730
214static struct gpio_bank gpio_bank_730[7] = {
Russell King7c7095a2008-09-05 15:49:14 +0100215 { OMAP_MPUIO_VBASE, INT_730_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100216 { OMAP730_GPIO1_BASE, INT_730_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_730 },
217 { OMAP730_GPIO2_BASE, INT_730_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_730 },
218 { OMAP730_GPIO3_BASE, INT_730_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_730 },
219 { OMAP730_GPIO4_BASE, INT_730_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_730 },
220 { OMAP730_GPIO5_BASE, INT_730_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_730 },
221 { OMAP730_GPIO6_BASE, INT_730_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_730 },
222};
223#endif
224
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700225#ifdef CONFIG_ARCH_OMAP850
226static struct gpio_bank gpio_bank_850[7] = {
227 { OMAP_MPUIO_BASE, INT_850_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
228 { OMAP850_GPIO1_BASE, INT_850_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_850 },
229 { OMAP850_GPIO2_BASE, INT_850_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_850 },
230 { OMAP850_GPIO3_BASE, INT_850_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_850 },
231 { OMAP850_GPIO4_BASE, INT_850_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_850 },
232 { OMAP850_GPIO5_BASE, INT_850_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_850 },
233 { OMAP850_GPIO6_BASE, INT_850_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_850 },
234};
235#endif
236
237
Tony Lindgren92105bb2005-09-07 17:20:26 +0100238#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800239
240static struct gpio_bank gpio_bank_242x[4] = {
241 { OMAP242X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
242 { OMAP242X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
243 { OMAP242X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
244 { OMAP242X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
Tony Lindgren92105bb2005-09-07 17:20:26 +0100245};
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800246
247static struct gpio_bank gpio_bank_243x[5] = {
248 { OMAP243X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
249 { OMAP243X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
250 { OMAP243X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
251 { OMAP243X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
252 { OMAP243X_GPIO5_BASE, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX },
253};
254
Tony Lindgren92105bb2005-09-07 17:20:26 +0100255#endif
256
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800257#ifdef CONFIG_ARCH_OMAP34XX
258static struct gpio_bank gpio_bank_34xx[6] = {
259 { OMAP34XX_GPIO1_BASE, INT_34XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
260 { OMAP34XX_GPIO2_BASE, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
261 { OMAP34XX_GPIO3_BASE, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
262 { OMAP34XX_GPIO4_BASE, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
263 { OMAP34XX_GPIO5_BASE, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX },
264 { OMAP34XX_GPIO6_BASE, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_24XX },
265};
266
267#endif
268
Santosh Shilimkar44169072009-05-28 14:16:04 -0700269#ifdef CONFIG_ARCH_OMAP4
270static struct gpio_bank gpio_bank_44xx[6] = {
271 { OMAP44XX_GPIO1_BASE, INT_44XX_GPIO_BANK1, IH_GPIO_BASE, \
272 METHOD_GPIO_24XX },
273 { OMAP44XX_GPIO2_BASE, INT_44XX_GPIO_BANK2, IH_GPIO_BASE + 32, \
274 METHOD_GPIO_24XX },
275 { OMAP44XX_GPIO3_BASE, INT_44XX_GPIO_BANK3, IH_GPIO_BASE + 64, \
276 METHOD_GPIO_24XX },
277 { OMAP44XX_GPIO4_BASE, INT_44XX_GPIO_BANK4, IH_GPIO_BASE + 96, \
278 METHOD_GPIO_24XX },
279 { OMAP44XX_GPIO5_BASE, INT_44XX_GPIO_BANK5, IH_GPIO_BASE + 128, \
280 METHOD_GPIO_24XX },
281 { OMAP44XX_GPIO6_BASE, INT_44XX_GPIO_BANK6, IH_GPIO_BASE + 160, \
282 METHOD_GPIO_24XX },
283};
284
285#endif
286
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100287static struct gpio_bank *gpio_bank;
288static int gpio_bank_count;
289
290static inline struct gpio_bank *get_gpio_bank(int gpio)
291{
Tony Lindgren6e60e792006-04-02 17:46:23 +0100292 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100293 if (OMAP_GPIO_IS_MPUIO(gpio))
294 return &gpio_bank[0];
295 return &gpio_bank[1];
296 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100297 if (cpu_is_omap16xx()) {
298 if (OMAP_GPIO_IS_MPUIO(gpio))
299 return &gpio_bank[0];
300 return &gpio_bank[1 + (gpio >> 4)];
301 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700302 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100303 if (OMAP_GPIO_IS_MPUIO(gpio))
304 return &gpio_bank[0];
305 return &gpio_bank[1 + (gpio >> 5)];
306 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100307 if (cpu_is_omap24xx())
308 return &gpio_bank[gpio >> 5];
Santosh Shilimkar44169072009-05-28 14:16:04 -0700309 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800310 return &gpio_bank[gpio >> 5];
David Brownelle031ab22008-12-10 17:35:27 -0800311 BUG();
312 return NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100313}
314
315static inline int get_gpio_index(int gpio)
316{
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700317 if (cpu_is_omap7xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100318 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100319 if (cpu_is_omap24xx())
320 return gpio & 0x1f;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700321 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800322 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100323 return gpio & 0x0f;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100324}
325
326static inline int gpio_valid(int gpio)
327{
328 if (gpio < 0)
329 return -1;
Tony Lindgrend11ac972008-01-12 15:35:04 -0800330 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
Jonathan McDowell193e68b2006-09-25 12:41:30 +0300331 if (gpio >= OMAP_MAX_GPIO_LINES + 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100332 return -1;
333 return 0;
334 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100335 if (cpu_is_omap15xx() && gpio < 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100336 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100337 if ((cpu_is_omap16xx()) && gpio < 64)
338 return 0;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700339 if (cpu_is_omap7xx() && gpio < 192)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100340 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100341 if (cpu_is_omap24xx() && gpio < 128)
342 return 0;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700343 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800344 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100345 return -1;
346}
347
348static int check_gpio(int gpio)
349{
350 if (unlikely(gpio_valid(gpio)) < 0) {
351 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
352 dump_stack();
353 return -1;
354 }
355 return 0;
356}
357
358static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
359{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100360 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100361 u32 l;
362
363 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800364#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100365 case METHOD_MPUIO:
366 reg += OMAP_MPUIO_IO_CNTL;
367 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800368#endif
369#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100370 case METHOD_GPIO_1510:
371 reg += OMAP1510_GPIO_DIR_CONTROL;
372 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800373#endif
374#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100375 case METHOD_GPIO_1610:
376 reg += OMAP1610_GPIO_DIRECTION;
377 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800378#endif
379#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100380 case METHOD_GPIO_730:
381 reg += OMAP730_GPIO_DIR_CONTROL;
382 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800383#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700384#ifdef CONFIG_ARCH_OMAP850
385 case METHOD_GPIO_850:
386 reg += OMAP850_GPIO_DIR_CONTROL;
387 break;
388#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700389#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
390 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100391 case METHOD_GPIO_24XX:
392 reg += OMAP24XX_GPIO_OE;
393 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800394#endif
395 default:
396 WARN_ON(1);
397 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100398 }
399 l = __raw_readl(reg);
400 if (is_input)
401 l |= 1 << gpio;
402 else
403 l &= ~(1 << gpio);
404 __raw_writel(l, reg);
405}
406
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100407static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
408{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100409 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100410 u32 l = 0;
411
412 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800413#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100414 case METHOD_MPUIO:
415 reg += OMAP_MPUIO_OUTPUT;
416 l = __raw_readl(reg);
417 if (enable)
418 l |= 1 << gpio;
419 else
420 l &= ~(1 << gpio);
421 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800422#endif
423#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100424 case METHOD_GPIO_1510:
425 reg += OMAP1510_GPIO_DATA_OUTPUT;
426 l = __raw_readl(reg);
427 if (enable)
428 l |= 1 << gpio;
429 else
430 l &= ~(1 << gpio);
431 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800432#endif
433#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100434 case METHOD_GPIO_1610:
435 if (enable)
436 reg += OMAP1610_GPIO_SET_DATAOUT;
437 else
438 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
439 l = 1 << gpio;
440 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800441#endif
442#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100443 case METHOD_GPIO_730:
444 reg += OMAP730_GPIO_DATA_OUTPUT;
445 l = __raw_readl(reg);
446 if (enable)
447 l |= 1 << gpio;
448 else
449 l &= ~(1 << gpio);
450 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800451#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700452#ifdef CONFIG_ARCH_OMAP850
453 case METHOD_GPIO_850:
454 reg += OMAP850_GPIO_DATA_OUTPUT;
455 l = __raw_readl(reg);
456 if (enable)
457 l |= 1 << gpio;
458 else
459 l &= ~(1 << gpio);
460 break;
461#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700462#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
463 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100464 case METHOD_GPIO_24XX:
465 if (enable)
466 reg += OMAP24XX_GPIO_SETDATAOUT;
467 else
468 reg += OMAP24XX_GPIO_CLEARDATAOUT;
469 l = 1 << gpio;
470 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800471#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100472 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800473 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100474 return;
475 }
476 __raw_writel(l, reg);
477}
478
David Brownell0b84b5c2008-12-10 17:35:25 -0800479static int __omap_get_gpio_datain(int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100480{
481 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100482 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100483
484 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800485 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100486 bank = get_gpio_bank(gpio);
487 reg = bank->base;
488 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800489#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100490 case METHOD_MPUIO:
491 reg += OMAP_MPUIO_INPUT_LATCH;
492 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800493#endif
494#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100495 case METHOD_GPIO_1510:
496 reg += OMAP1510_GPIO_DATA_INPUT;
497 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800498#endif
499#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100500 case METHOD_GPIO_1610:
501 reg += OMAP1610_GPIO_DATAIN;
502 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800503#endif
504#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100505 case METHOD_GPIO_730:
506 reg += OMAP730_GPIO_DATA_INPUT;
507 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800508#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700509#ifdef CONFIG_ARCH_OMAP850
510 case METHOD_GPIO_850:
511 reg += OMAP850_GPIO_DATA_INPUT;
512 break;
513#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700514#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
515 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100516 case METHOD_GPIO_24XX:
517 reg += OMAP24XX_GPIO_DATAIN;
518 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800519#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100520 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800521 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100522 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100523 return (__raw_readl(reg)
524 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100525}
526
Tony Lindgren92105bb2005-09-07 17:20:26 +0100527#define MOD_REG_BIT(reg, bit_mask, set) \
528do { \
529 int l = __raw_readl(base + reg); \
530 if (set) l |= bit_mask; \
531 else l &= ~bit_mask; \
532 __raw_writel(l, base + reg); \
533} while(0)
534
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700535void omap_set_gpio_debounce(int gpio, int enable)
536{
537 struct gpio_bank *bank;
538 void __iomem *reg;
David Brownelle031ab22008-12-10 17:35:27 -0800539 unsigned long flags;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700540 u32 val, l = 1 << get_gpio_index(gpio);
541
542 if (cpu_class_is_omap1())
543 return;
544
545 bank = get_gpio_bank(gpio);
546 reg = bank->base;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700547 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
David Brownelle031ab22008-12-10 17:35:27 -0800548
549 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700550 val = __raw_readl(reg);
551
Jouni Hogander89db9482008-12-10 17:35:24 -0800552 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700553 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800554 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700555 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800556 else
David Brownelle031ab22008-12-10 17:35:27 -0800557 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800558
Santosh Shilimkar44169072009-05-28 14:16:04 -0700559 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800560 if (enable)
561 clk_enable(bank->dbck);
562 else
563 clk_disable(bank->dbck);
564 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700565
566 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800567done:
568 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700569}
570EXPORT_SYMBOL(omap_set_gpio_debounce);
571
572void omap_set_gpio_debounce_time(int gpio, int enc_time)
573{
574 struct gpio_bank *bank;
575 void __iomem *reg;
576
577 if (cpu_class_is_omap1())
578 return;
579
580 bank = get_gpio_bank(gpio);
581 reg = bank->base;
582
583 enc_time &= 0xff;
584 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
585 __raw_writel(enc_time, reg);
586}
587EXPORT_SYMBOL(omap_set_gpio_debounce_time);
588
Santosh Shilimkar44169072009-05-28 14:16:04 -0700589#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
590 defined(CONFIG_ARCH_OMAP4)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700591static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
592 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100593{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800594 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100595 u32 gpio_bit = 1 << gpio;
596
597 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100598 trigger & IRQ_TYPE_LEVEL_LOW);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100599 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100600 trigger & IRQ_TYPE_LEVEL_HIGH);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100601 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100602 trigger & IRQ_TYPE_EDGE_RISING);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100603 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100604 trigger & IRQ_TYPE_EDGE_FALLING);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700605
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800606 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
607 if (trigger != 0)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700608 __raw_writel(1 << gpio, bank->base
609 + OMAP24XX_GPIO_SETWKUENA);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800610 else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700611 __raw_writel(1 << gpio, bank->base
612 + OMAP24XX_GPIO_CLEARWKUENA);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800613 } else {
614 if (trigger != 0)
615 bank->enabled_non_wakeup_gpios |= gpio_bit;
616 else
617 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
618 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700619
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800620 bank->level_mask =
621 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
622 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100623}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800624#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100625
626static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
627{
628 void __iomem *reg = bank->base;
629 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100630
631 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800632#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100633 case METHOD_MPUIO:
634 reg += OMAP_MPUIO_GPIO_INT_EDGE;
635 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100636 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100637 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100638 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100639 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100640 else
641 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100642 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800643#endif
644#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100645 case METHOD_GPIO_1510:
646 reg += OMAP1510_GPIO_INT_CONTROL;
647 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100648 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100649 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100650 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100651 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100652 else
653 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100654 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800655#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800656#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100657 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100658 if (gpio & 0x08)
659 reg += OMAP1610_GPIO_EDGE_CTRL2;
660 else
661 reg += OMAP1610_GPIO_EDGE_CTRL1;
662 gpio &= 0x07;
663 l = __raw_readl(reg);
664 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100665 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100666 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100667 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100668 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800669 if (trigger)
670 /* Enable wake-up during idle for dynamic tick */
671 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
672 else
673 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100674 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800675#endif
676#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100677 case METHOD_GPIO_730:
678 reg += OMAP730_GPIO_INT_CONTROL;
679 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100680 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100681 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100682 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100683 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100684 else
685 goto bad;
686 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800687#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700688#ifdef CONFIG_ARCH_OMAP850
689 case METHOD_GPIO_850:
690 reg += OMAP850_GPIO_INT_CONTROL;
691 l = __raw_readl(reg);
692 if (trigger & IRQ_TYPE_EDGE_RISING)
693 l |= 1 << gpio;
694 else if (trigger & IRQ_TYPE_EDGE_FALLING)
695 l &= ~(1 << gpio);
696 else
697 goto bad;
698 break;
699#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700700#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
701 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100702 case METHOD_GPIO_24XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800703 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100704 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800705#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100706 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100707 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100708 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100709 __raw_writel(l, reg);
710 return 0;
711bad:
712 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100713}
714
Tony Lindgren92105bb2005-09-07 17:20:26 +0100715static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100716{
717 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100718 unsigned gpio;
719 int retval;
David Brownella6472532008-03-03 04:33:30 -0800720 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100721
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800722 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100723 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
724 else
725 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100726
727 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100728 return -EINVAL;
729
David Brownelle5c56ed2006-12-06 17:13:59 -0800730 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100731 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800732
733 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800734 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800735 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100736 return -EINVAL;
737
David Brownell58781012006-12-06 17:14:10 -0800738 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800739 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100740 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800741 if (retval == 0) {
742 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
743 irq_desc[irq].status |= type;
744 }
David Brownella6472532008-03-03 04:33:30 -0800745 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800746
747 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
748 __set_irq_handler_unlocked(irq, handle_level_irq);
749 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
750 __set_irq_handler_unlocked(irq, handle_edge_irq);
751
Tony Lindgren92105bb2005-09-07 17:20:26 +0100752 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100753}
754
755static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
756{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100757 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100758
759 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800760#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100761 case METHOD_MPUIO:
762 /* MPUIO irqstatus is reset by reading the status register,
763 * so do nothing here */
764 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800765#endif
766#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100767 case METHOD_GPIO_1510:
768 reg += OMAP1510_GPIO_INT_STATUS;
769 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800770#endif
771#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100772 case METHOD_GPIO_1610:
773 reg += OMAP1610_GPIO_IRQSTATUS1;
774 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800775#endif
776#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100777 case METHOD_GPIO_730:
778 reg += OMAP730_GPIO_INT_STATUS;
779 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800780#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700781#ifdef CONFIG_ARCH_OMAP850
782 case METHOD_GPIO_850:
783 reg += OMAP850_GPIO_INT_STATUS;
784 break;
785#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700786#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
787 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100788 case METHOD_GPIO_24XX:
789 reg += OMAP24XX_GPIO_IRQSTATUS1;
790 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800791#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100792 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800793 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100794 return;
795 }
796 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300797
798 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800799#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Roger Quadrosbedfd152009-04-23 11:10:50 -0700800 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800801 if (cpu_is_omap24xx() || cpu_is_omap34xx())
Roger Quadrosbedfd152009-04-23 11:10:50 -0700802 __raw_writel(gpio_mask, reg);
803
804 /* Flush posted write for the irq status to avoid spurious interrupts */
805 __raw_readl(reg);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800806#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100807}
808
809static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
810{
811 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
812}
813
Imre Deakea6dedd2006-06-26 16:16:00 -0700814static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
815{
816 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700817 int inv = 0;
818 u32 l;
819 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700820
821 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800822#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700823 case METHOD_MPUIO:
824 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700825 mask = 0xffff;
826 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700827 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800828#endif
829#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700830 case METHOD_GPIO_1510:
831 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700832 mask = 0xffff;
833 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700834 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800835#endif
836#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700837 case METHOD_GPIO_1610:
838 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700839 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700840 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800841#endif
842#ifdef CONFIG_ARCH_OMAP730
Imre Deakea6dedd2006-06-26 16:16:00 -0700843 case METHOD_GPIO_730:
844 reg += OMAP730_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700845 mask = 0xffffffff;
846 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700847 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800848#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700849#ifdef CONFIG_ARCH_OMAP850
850 case METHOD_GPIO_850:
851 reg += OMAP850_GPIO_INT_MASK;
852 mask = 0xffffffff;
853 inv = 1;
854 break;
855#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700856#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
857 defined(CONFIG_ARCH_OMAP4)
Imre Deakea6dedd2006-06-26 16:16:00 -0700858 case METHOD_GPIO_24XX:
859 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700860 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700861 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800862#endif
Imre Deakea6dedd2006-06-26 16:16:00 -0700863 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800864 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -0700865 return 0;
866 }
867
Imre Deak99c47702006-06-26 16:16:07 -0700868 l = __raw_readl(reg);
869 if (inv)
870 l = ~l;
871 l &= mask;
872 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700873}
874
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100875static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
876{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100877 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100878 u32 l;
879
880 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800881#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100882 case METHOD_MPUIO:
883 reg += OMAP_MPUIO_GPIO_MASKIT;
884 l = __raw_readl(reg);
885 if (enable)
886 l &= ~(gpio_mask);
887 else
888 l |= gpio_mask;
889 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800890#endif
891#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100892 case METHOD_GPIO_1510:
893 reg += OMAP1510_GPIO_INT_MASK;
894 l = __raw_readl(reg);
895 if (enable)
896 l &= ~(gpio_mask);
897 else
898 l |= gpio_mask;
899 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800900#endif
901#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100902 case METHOD_GPIO_1610:
903 if (enable)
904 reg += OMAP1610_GPIO_SET_IRQENABLE1;
905 else
906 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
907 l = gpio_mask;
908 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800909#endif
910#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100911 case METHOD_GPIO_730:
912 reg += OMAP730_GPIO_INT_MASK;
913 l = __raw_readl(reg);
914 if (enable)
915 l &= ~(gpio_mask);
916 else
917 l |= gpio_mask;
918 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800919#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700920#ifdef CONFIG_ARCH_OMAP850
921 case METHOD_GPIO_850:
922 reg += OMAP850_GPIO_INT_MASK;
923 l = __raw_readl(reg);
924 if (enable)
925 l &= ~(gpio_mask);
926 else
927 l |= gpio_mask;
928 break;
929#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700930#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
931 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100932 case METHOD_GPIO_24XX:
933 if (enable)
934 reg += OMAP24XX_GPIO_SETIRQENABLE1;
935 else
936 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
937 l = gpio_mask;
938 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800939#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100940 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800941 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100942 return;
943 }
944 __raw_writel(l, reg);
945}
946
947static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
948{
949 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
950}
951
Tony Lindgren92105bb2005-09-07 17:20:26 +0100952/*
953 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
954 * 1510 does not seem to have a wake-up register. If JTAG is connected
955 * to the target, system will wake up always on GPIO events. While
956 * system is running all registered GPIO interrupts need to have wake-up
957 * enabled. When system is suspended, only selected GPIO interrupts need
958 * to have wake-up enabled.
959 */
960static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
961{
David Brownella6472532008-03-03 04:33:30 -0800962 unsigned long flags;
963
Tony Lindgren92105bb2005-09-07 17:20:26 +0100964 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800965#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -0800966 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100967 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -0800968 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -0700969 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100970 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -0700971 else
Tony Lindgren92105bb2005-09-07 17:20:26 +0100972 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -0800973 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100974 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800975#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700976#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
977 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800978 case METHOD_GPIO_24XX:
David Brownell11a78b72006-12-06 17:14:11 -0800979 if (bank->non_wakeup_gpios & (1 << gpio)) {
980 printk(KERN_ERR "Unable to modify wakeup on "
981 "non-wakeup GPIO%d\n",
982 (bank - gpio_bank) * 32 + gpio);
983 return -EINVAL;
984 }
David Brownella6472532008-03-03 04:33:30 -0800985 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -0700986 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800987 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -0700988 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800989 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -0800990 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800991 return 0;
992#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100993 default:
994 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
995 bank->method);
996 return -EINVAL;
997 }
998}
999
Tony Lindgren4196dd62006-09-25 12:41:38 +03001000static void _reset_gpio(struct gpio_bank *bank, int gpio)
1001{
1002 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1003 _set_gpio_irqenable(bank, gpio, 0);
1004 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001005 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001006}
1007
Tony Lindgren92105bb2005-09-07 17:20:26 +01001008/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1009static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1010{
1011 unsigned int gpio = irq - IH_GPIO_BASE;
1012 struct gpio_bank *bank;
1013 int retval;
1014
1015 if (check_gpio(gpio) < 0)
1016 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001017 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001018 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001019
1020 return retval;
1021}
1022
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001023static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001024{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001025 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001026 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001027
David Brownella6472532008-03-03 04:33:30 -08001028 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001029
Tony Lindgren4196dd62006-09-25 12:41:38 +03001030 /* Set trigger to none. You need to enable the desired trigger with
1031 * request_irq() or set_irq_type().
1032 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001033 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001034
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001035#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001036 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001037 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001038
Tony Lindgren92105bb2005-09-07 17:20:26 +01001039 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001040 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001041 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001042 }
1043#endif
David Brownella6472532008-03-03 04:33:30 -08001044 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001045
1046 return 0;
1047}
1048
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001049static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001050{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001051 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001052 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001053
David Brownella6472532008-03-03 04:33:30 -08001054 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001055#ifdef CONFIG_ARCH_OMAP16XX
1056 if (bank->method == METHOD_GPIO_1610) {
1057 /* Disable wake-up during idle for dynamic tick */
1058 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001059 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001060 }
1061#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001062#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1063 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001064 if (bank->method == METHOD_GPIO_24XX) {
1065 /* Disable wake-up during idle for dynamic tick */
1066 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001067 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001068 }
1069#endif
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001070 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001071 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001072}
1073
1074/*
1075 * We need to unmask the GPIO bank interrupt as soon as possible to
1076 * avoid missing GPIO interrupts for other lines in the bank.
1077 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1078 * in the bank to avoid missing nested interrupts for a GPIO line.
1079 * If we wait to unmask individual GPIO lines in the bank after the
1080 * line's interrupt handler has been run, we may miss some nested
1081 * interrupts.
1082 */
Russell King10dd5ce2006-11-23 11:41:32 +00001083static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001084{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001085 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001086 u32 isr;
1087 unsigned int gpio_irq;
1088 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001089 u32 retrigger = 0;
1090 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001091
1092 desc->chip->ack(irq);
1093
Thomas Gleixner418ca1f02006-07-01 22:32:41 +01001094 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001095#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001096 if (bank->method == METHOD_MPUIO)
1097 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001098#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001099#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001100 if (bank->method == METHOD_GPIO_1510)
1101 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1102#endif
1103#if defined(CONFIG_ARCH_OMAP16XX)
1104 if (bank->method == METHOD_GPIO_1610)
1105 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1106#endif
1107#ifdef CONFIG_ARCH_OMAP730
1108 if (bank->method == METHOD_GPIO_730)
1109 isr_reg = bank->base + OMAP730_GPIO_INT_STATUS;
1110#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001111#ifdef CONFIG_ARCH_OMAP850
1112 if (bank->method == METHOD_GPIO_850)
1113 isr_reg = bank->base + OMAP850_GPIO_INT_STATUS;
1114#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001115#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1116 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001117 if (bank->method == METHOD_GPIO_24XX)
1118 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1119#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001120 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001121 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001122 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001123
Imre Deakea6dedd2006-06-26 16:16:00 -07001124 enabled = _get_gpio_irqbank_mask(bank);
1125 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001126
1127 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1128 isr &= 0x0000ffff;
1129
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001130 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001131 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001132 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001133
1134 /* clear edge sensitive interrupts before handler(s) are
1135 called so that we don't miss any interrupt occurred while
1136 executing them */
1137 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1138 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1139 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1140
1141 /* if there is only edge sensitive GPIO pin interrupts
1142 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001143 if (!level_mask && !unmasked) {
1144 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001145 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001146 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001147
Imre Deakea6dedd2006-06-26 16:16:00 -07001148 isr |= retrigger;
1149 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001150 if (!isr)
1151 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001152
Tony Lindgren92105bb2005-09-07 17:20:26 +01001153 gpio_irq = bank->virtual_irq_start;
1154 for (; isr != 0; isr >>= 1, gpio_irq++) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001155 if (!(isr & 1))
1156 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001157
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001158 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001159 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001160 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001161 /* if bank has any level sensitive GPIO pin interrupt
1162 configured, we must unmask the bank interrupt only after
1163 handler(s) are executed in order to avoid spurious bank
1164 interrupt */
1165 if (!unmasked)
1166 desc->chip->unmask(irq);
1167
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001168}
1169
Tony Lindgren4196dd62006-09-25 12:41:38 +03001170static void gpio_irq_shutdown(unsigned int irq)
1171{
1172 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001173 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001174
1175 _reset_gpio(bank, gpio);
1176}
1177
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001178static void gpio_ack_irq(unsigned int irq)
1179{
1180 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001181 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001182
1183 _clear_gpio_irqstatus(bank, gpio);
1184}
1185
1186static void gpio_mask_irq(unsigned int irq)
1187{
1188 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001189 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001190
1191 _set_gpio_irqenable(bank, gpio, 0);
1192}
1193
1194static void gpio_unmask_irq(unsigned int irq)
1195{
1196 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001197 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001198 unsigned int irq_mask = 1 << get_gpio_index(gpio);
1199
1200 /* For level-triggered GPIOs, the clearing must be done after
1201 * the HW source is cleared, thus after the handler has run */
1202 if (bank->level_mask & irq_mask) {
1203 _set_gpio_irqenable(bank, gpio, 0);
1204 _clear_gpio_irqstatus(bank, gpio);
1205 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001206
Kevin Hilman4de8c752008-01-16 21:56:14 -08001207 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001208}
1209
David Brownelle5c56ed2006-12-06 17:13:59 -08001210static struct irq_chip gpio_irq_chip = {
1211 .name = "GPIO",
1212 .shutdown = gpio_irq_shutdown,
1213 .ack = gpio_ack_irq,
1214 .mask = gpio_mask_irq,
1215 .unmask = gpio_unmask_irq,
1216 .set_type = gpio_irq_type,
1217 .set_wake = gpio_wake_enable,
1218};
1219
1220/*---------------------------------------------------------------------*/
1221
1222#ifdef CONFIG_ARCH_OMAP1
1223
1224/* MPUIO uses the always-on 32k clock */
1225
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001226static void mpuio_ack_irq(unsigned int irq)
1227{
1228 /* The ISR is reset automatically, so do nothing here. */
1229}
1230
1231static void mpuio_mask_irq(unsigned int irq)
1232{
1233 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001234 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001235
1236 _set_gpio_irqenable(bank, gpio, 0);
1237}
1238
1239static void mpuio_unmask_irq(unsigned int irq)
1240{
1241 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001242 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001243
1244 _set_gpio_irqenable(bank, gpio, 1);
1245}
1246
David Brownelle5c56ed2006-12-06 17:13:59 -08001247static struct irq_chip mpuio_irq_chip = {
1248 .name = "MPUIO",
1249 .ack = mpuio_ack_irq,
1250 .mask = mpuio_mask_irq,
1251 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001252 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001253#ifdef CONFIG_ARCH_OMAP16XX
1254 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1255 .set_wake = gpio_wake_enable,
1256#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001257};
1258
David Brownelle5c56ed2006-12-06 17:13:59 -08001259
1260#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1261
David Brownell11a78b72006-12-06 17:14:11 -08001262
1263#ifdef CONFIG_ARCH_OMAP16XX
1264
1265#include <linux/platform_device.h>
1266
1267static int omap_mpuio_suspend_late(struct platform_device *pdev, pm_message_t mesg)
1268{
1269 struct gpio_bank *bank = platform_get_drvdata(pdev);
1270 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001271 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001272
David Brownella6472532008-03-03 04:33:30 -08001273 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001274 bank->saved_wakeup = __raw_readl(mask_reg);
1275 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001276 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001277
1278 return 0;
1279}
1280
1281static int omap_mpuio_resume_early(struct platform_device *pdev)
1282{
1283 struct gpio_bank *bank = platform_get_drvdata(pdev);
1284 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001285 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001286
David Brownella6472532008-03-03 04:33:30 -08001287 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001288 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001289 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001290
1291 return 0;
1292}
1293
1294/* use platform_driver for this, now that there's no longer any
1295 * point to sys_device (other than not disturbing old code).
1296 */
1297static struct platform_driver omap_mpuio_driver = {
1298 .suspend_late = omap_mpuio_suspend_late,
1299 .resume_early = omap_mpuio_resume_early,
1300 .driver = {
1301 .name = "mpuio",
1302 },
1303};
1304
1305static struct platform_device omap_mpuio_device = {
1306 .name = "mpuio",
1307 .id = -1,
1308 .dev = {
1309 .driver = &omap_mpuio_driver.driver,
1310 }
1311 /* could list the /proc/iomem resources */
1312};
1313
1314static inline void mpuio_init(void)
1315{
David Brownellfcf126d2007-04-02 12:46:47 -07001316 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1317
David Brownell11a78b72006-12-06 17:14:11 -08001318 if (platform_driver_register(&omap_mpuio_driver) == 0)
1319 (void) platform_device_register(&omap_mpuio_device);
1320}
1321
1322#else
1323static inline void mpuio_init(void) {}
1324#endif /* 16xx */
1325
David Brownelle5c56ed2006-12-06 17:13:59 -08001326#else
1327
1328extern struct irq_chip mpuio_irq_chip;
1329
1330#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001331static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001332
1333#endif
1334
1335/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001336
David Brownell52e31342008-03-03 12:43:23 -08001337/* REVISIT these are stupid implementations! replace by ones that
1338 * don't switch on METHOD_* and which mostly avoid spinlocks
1339 */
1340
1341static int gpio_input(struct gpio_chip *chip, unsigned offset)
1342{
1343 struct gpio_bank *bank;
1344 unsigned long flags;
1345
1346 bank = container_of(chip, struct gpio_bank, chip);
1347 spin_lock_irqsave(&bank->lock, flags);
1348 _set_gpio_direction(bank, offset, 1);
1349 spin_unlock_irqrestore(&bank->lock, flags);
1350 return 0;
1351}
1352
1353static int gpio_get(struct gpio_chip *chip, unsigned offset)
1354{
David Brownell0b84b5c2008-12-10 17:35:25 -08001355 return __omap_get_gpio_datain(chip->base + offset);
David Brownell52e31342008-03-03 12:43:23 -08001356}
1357
1358static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1359{
1360 struct gpio_bank *bank;
1361 unsigned long flags;
1362
1363 bank = container_of(chip, struct gpio_bank, chip);
1364 spin_lock_irqsave(&bank->lock, flags);
1365 _set_gpio_dataout(bank, offset, value);
1366 _set_gpio_direction(bank, offset, 0);
1367 spin_unlock_irqrestore(&bank->lock, flags);
1368 return 0;
1369}
1370
1371static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1372{
1373 struct gpio_bank *bank;
1374 unsigned long flags;
1375
1376 bank = container_of(chip, struct gpio_bank, chip);
1377 spin_lock_irqsave(&bank->lock, flags);
1378 _set_gpio_dataout(bank, offset, value);
1379 spin_unlock_irqrestore(&bank->lock, flags);
1380}
1381
David Brownella007b702008-12-10 17:35:25 -08001382static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1383{
1384 struct gpio_bank *bank;
1385
1386 bank = container_of(chip, struct gpio_bank, chip);
1387 return bank->virtual_irq_start + offset;
1388}
1389
David Brownell52e31342008-03-03 12:43:23 -08001390/*---------------------------------------------------------------------*/
1391
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001392static int initialized;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001393#if !(defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001394static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001395#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001396
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001397#if defined(CONFIG_ARCH_OMAP2)
1398static struct clk * gpio_fck;
1399#endif
1400
1401#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001402static struct clk * gpio5_ick;
1403static struct clk * gpio5_fck;
1404#endif
1405
Santosh Shilimkar44169072009-05-28 14:16:04 -07001406#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001407static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1408#endif
1409
David Brownell8ba55c52008-02-26 11:10:50 -08001410/* This lock class tells lockdep that GPIO irqs are in a different
1411 * category than their parents, so it won't report false recursion.
1412 */
1413static struct lock_class_key gpio_lock_class;
1414
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001415static int __init _omap_gpio_init(void)
1416{
1417 int i;
David Brownell52e31342008-03-03 12:43:23 -08001418 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001419 struct gpio_bank *bank;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001420 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001421
1422 initialized = 1;
1423
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001424#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001425 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001426 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1427 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001428 printk("Could not get arm_gpio_ck\n");
1429 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001430 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001431 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001432#endif
1433#if defined(CONFIG_ARCH_OMAP2)
1434 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001435 gpio_ick = clk_get(NULL, "gpios_ick");
1436 if (IS_ERR(gpio_ick))
1437 printk("Could not get gpios_ick\n");
1438 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001439 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001440 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001441 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001442 printk("Could not get gpios_fck\n");
1443 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001444 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001445
1446 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001447 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001448 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001449#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001450 if (cpu_is_omap2430()) {
1451 gpio5_ick = clk_get(NULL, "gpio5_ick");
1452 if (IS_ERR(gpio5_ick))
1453 printk("Could not get gpio5_ick\n");
1454 else
1455 clk_enable(gpio5_ick);
1456 gpio5_fck = clk_get(NULL, "gpio5_fck");
1457 if (IS_ERR(gpio5_fck))
1458 printk("Could not get gpio5_fck\n");
1459 else
1460 clk_enable(gpio5_fck);
1461 }
1462#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001463 }
1464#endif
1465
Santosh Shilimkar44169072009-05-28 14:16:04 -07001466#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1467 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001468 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1469 sprintf(clk_name, "gpio%d_ick", i + 1);
1470 gpio_iclks[i] = clk_get(NULL, clk_name);
1471 if (IS_ERR(gpio_iclks[i]))
1472 printk(KERN_ERR "Could not get %s\n", clk_name);
1473 else
1474 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001475 }
1476 }
1477#endif
1478
Tony Lindgren92105bb2005-09-07 17:20:26 +01001479
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001480#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001481 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001482 printk(KERN_INFO "OMAP1510 GPIO hardware\n");
1483 gpio_bank_count = 2;
1484 gpio_bank = gpio_bank_1510;
1485 }
1486#endif
1487#if defined(CONFIG_ARCH_OMAP16XX)
1488 if (cpu_is_omap16xx()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001489 u32 rev;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001490
1491 gpio_bank_count = 5;
1492 gpio_bank = gpio_bank_1610;
Russell King7c7095a2008-09-05 15:49:14 +01001493 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001494 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1495 (rev >> 4) & 0x0f, rev & 0x0f);
1496 }
1497#endif
1498#ifdef CONFIG_ARCH_OMAP730
1499 if (cpu_is_omap730()) {
1500 printk(KERN_INFO "OMAP730 GPIO hardware\n");
1501 gpio_bank_count = 7;
1502 gpio_bank = gpio_bank_730;
1503 }
1504#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001505#ifdef CONFIG_ARCH_OMAP850
1506 if (cpu_is_omap850()) {
1507 printk(KERN_INFO "OMAP850 GPIO hardware\n");
1508 gpio_bank_count = 7;
1509 gpio_bank = gpio_bank_850;
1510 }
1511#endif
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001512
Tony Lindgren92105bb2005-09-07 17:20:26 +01001513#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001514 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001515 int rev;
1516
1517 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001518 gpio_bank = gpio_bank_242x;
Russell King7c7095a2008-09-05 15:49:14 +01001519 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001520 printk(KERN_INFO "OMAP242x GPIO hardware version %d.%d\n",
1521 (rev >> 4) & 0x0f, rev & 0x0f);
1522 }
1523 if (cpu_is_omap243x()) {
1524 int rev;
1525
1526 gpio_bank_count = 5;
1527 gpio_bank = gpio_bank_243x;
Russell King7c7095a2008-09-05 15:49:14 +01001528 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001529 printk(KERN_INFO "OMAP243x GPIO hardware version %d.%d\n",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001530 (rev >> 4) & 0x0f, rev & 0x0f);
1531 }
1532#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001533#ifdef CONFIG_ARCH_OMAP34XX
1534 if (cpu_is_omap34xx()) {
1535 int rev;
1536
1537 gpio_bank_count = OMAP34XX_NR_GPIOS;
1538 gpio_bank = gpio_bank_34xx;
Russell King7c7095a2008-09-05 15:49:14 +01001539 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001540 printk(KERN_INFO "OMAP34xx GPIO hardware version %d.%d\n",
1541 (rev >> 4) & 0x0f, rev & 0x0f);
1542 }
1543#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001544#ifdef CONFIG_ARCH_OMAP4
1545 if (cpu_is_omap44xx()) {
1546 int rev;
1547
1548 gpio_bank_count = OMAP34XX_NR_GPIOS;
1549 gpio_bank = gpio_bank_44xx;
1550 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1551 printk(KERN_INFO "OMAP44xx GPIO hardware version %d.%d\n",
1552 (rev >> 4) & 0x0f, rev & 0x0f);
1553 }
1554#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001555 for (i = 0; i < gpio_bank_count; i++) {
1556 int j, gpio_count = 16;
1557
1558 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001559 spin_lock_init(&bank->lock);
David Brownelle5c56ed2006-12-06 17:13:59 -08001560 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001561 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001562 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001563 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1564 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1565 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001566 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001567 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1568 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001569 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001570 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001571 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_730) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001572 __raw_writel(0xffffffff, bank->base + OMAP730_GPIO_INT_MASK);
1573 __raw_writel(0x00000000, bank->base + OMAP730_GPIO_INT_STATUS);
1574
1575 gpio_count = 32; /* 730 has 32-bit GPIOs */
1576 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001577
Santosh Shilimkar44169072009-05-28 14:16:04 -07001578#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1579 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001580 if (bank->method == METHOD_GPIO_24XX) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001581 static const u32 non_wakeup_gpios[] = {
1582 0xe203ffc0, 0x08700040
1583 };
1584
Tony Lindgren92105bb2005-09-07 17:20:26 +01001585 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1586 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001587 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
1588
1589 /* Initialize interface clock ungated, module enabled */
1590 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001591 if (i < ARRAY_SIZE(non_wakeup_gpios))
1592 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001593 gpio_count = 32;
1594 }
1595#endif
David Brownell52e31342008-03-03 12:43:23 -08001596
1597 /* REVISIT eventually switch from OMAP-specific gpio structs
1598 * over to the generic ones
1599 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001600 bank->chip.request = omap_gpio_request;
1601 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001602 bank->chip.direction_input = gpio_input;
1603 bank->chip.get = gpio_get;
1604 bank->chip.direction_output = gpio_output;
1605 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001606 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001607 if (bank_is_mpuio(bank)) {
1608 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001609#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d82008-07-25 01:46:07 -07001610 bank->chip.dev = &omap_mpuio_device.dev;
1611#endif
David Brownell52e31342008-03-03 12:43:23 -08001612 bank->chip.base = OMAP_MPUIO(0);
1613 } else {
1614 bank->chip.label = "gpio";
1615 bank->chip.base = gpio;
1616 gpio += gpio_count;
1617 }
1618 bank->chip.ngpio = gpio_count;
1619
1620 gpiochip_add(&bank->chip);
1621
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001622 for (j = bank->virtual_irq_start;
1623 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001624 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001625 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001626 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001627 set_irq_chip(j, &mpuio_irq_chip);
1628 else
1629 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001630 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001631 set_irq_flags(j, IRQF_VALID);
1632 }
1633 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1634 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001635
Santosh Shilimkar44169072009-05-28 14:16:04 -07001636 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001637 sprintf(clk_name, "gpio%d_dbck", i + 1);
1638 bank->dbck = clk_get(NULL, clk_name);
1639 if (IS_ERR(bank->dbck))
1640 printk(KERN_ERR "Could not get %s\n", clk_name);
1641 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001642 }
1643
1644 /* Enable system clock for GPIO module.
1645 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001646 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001647 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1648
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001649 /* Enable autoidle for the OCP interface */
1650 if (cpu_is_omap24xx())
1651 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001652 if (cpu_is_omap34xx())
1653 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001654
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001655 return 0;
1656}
1657
Santosh Shilimkar44169072009-05-28 14:16:04 -07001658#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1659 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001660static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1661{
1662 int i;
1663
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001664 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001665 return 0;
1666
1667 for (i = 0; i < gpio_bank_count; i++) {
1668 struct gpio_bank *bank = &gpio_bank[i];
1669 void __iomem *wake_status;
1670 void __iomem *wake_clear;
1671 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001672 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001673
1674 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001675#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001676 case METHOD_GPIO_1610:
1677 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1678 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1679 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1680 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001681#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001682#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1683 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001684 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001685 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001686 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1687 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1688 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001689#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001690 default:
1691 continue;
1692 }
1693
David Brownella6472532008-03-03 04:33:30 -08001694 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001695 bank->saved_wakeup = __raw_readl(wake_status);
1696 __raw_writel(0xffffffff, wake_clear);
1697 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001698 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001699 }
1700
1701 return 0;
1702}
1703
1704static int omap_gpio_resume(struct sys_device *dev)
1705{
1706 int i;
1707
Tero Kristo723fdb72008-11-26 14:35:16 -08001708 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001709 return 0;
1710
1711 for (i = 0; i < gpio_bank_count; i++) {
1712 struct gpio_bank *bank = &gpio_bank[i];
1713 void __iomem *wake_clear;
1714 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001715 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001716
1717 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001718#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001719 case METHOD_GPIO_1610:
1720 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1721 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1722 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001723#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001724#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1725 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001726 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001727 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1728 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001729 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001730#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001731 default:
1732 continue;
1733 }
1734
David Brownella6472532008-03-03 04:33:30 -08001735 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001736 __raw_writel(0xffffffff, wake_clear);
1737 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001738 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001739 }
1740
1741 return 0;
1742}
1743
1744static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01001745 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001746 .suspend = omap_gpio_suspend,
1747 .resume = omap_gpio_resume,
1748};
1749
1750static struct sys_device omap_gpio_device = {
1751 .id = 0,
1752 .cls = &omap_gpio_sysclass,
1753};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001754
1755#endif
1756
Santosh Shilimkar44169072009-05-28 14:16:04 -07001757#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1758 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001759
1760static int workaround_enabled;
1761
1762void omap2_gpio_prepare_for_retention(void)
1763{
1764 int i, c = 0;
1765
1766 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
1767 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
1768 for (i = 0; i < gpio_bank_count; i++) {
1769 struct gpio_bank *bank = &gpio_bank[i];
1770 u32 l1, l2;
1771
1772 if (!(bank->enabled_non_wakeup_gpios))
1773 continue;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001774#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1775 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001776 bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1777 l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1778 l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001779#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001780 bank->saved_fallingdetect = l1;
1781 bank->saved_risingdetect = l2;
1782 l1 &= ~bank->enabled_non_wakeup_gpios;
1783 l2 &= ~bank->enabled_non_wakeup_gpios;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001784#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1785 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001786 __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1787 __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001788#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001789 c++;
1790 }
1791 if (!c) {
1792 workaround_enabled = 0;
1793 return;
1794 }
1795 workaround_enabled = 1;
1796}
1797
1798void omap2_gpio_resume_after_retention(void)
1799{
1800 int i;
1801
1802 if (!workaround_enabled)
1803 return;
1804 for (i = 0; i < gpio_bank_count; i++) {
1805 struct gpio_bank *bank = &gpio_bank[i];
1806 u32 l;
1807
1808 if (!(bank->enabled_non_wakeup_gpios))
1809 continue;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001810#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1811 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001812 __raw_writel(bank->saved_fallingdetect,
1813 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1814 __raw_writel(bank->saved_risingdetect,
1815 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001816#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001817 /* Check if any of the non-wakeup interrupt GPIOs have changed
1818 * state. If so, generate an IRQ by software. This is
1819 * horribly racy, but it's the best we can do to work around
1820 * this silicon bug. */
Santosh Shilimkar44169072009-05-28 14:16:04 -07001821#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1822 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001823 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001824#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001825 l ^= bank->saved_datain;
1826 l &= bank->non_wakeup_gpios;
1827 if (l) {
1828 u32 old0, old1;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001829#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1830 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001831 old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1832 old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
1833 __raw_writel(old0 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1834 __raw_writel(old1 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
1835 __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1836 __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001837#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001838 }
1839 }
1840
1841}
1842
Tony Lindgren92105bb2005-09-07 17:20:26 +01001843#endif
1844
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001845/*
1846 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001847 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001848 */
David Brownell277d58e2006-12-06 17:13:59 -08001849int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001850{
1851 if (!initialized)
1852 return _omap_gpio_init();
1853 else
1854 return 0;
1855}
1856
Tony Lindgren92105bb2005-09-07 17:20:26 +01001857static int __init omap_gpio_sysinit(void)
1858{
1859 int ret = 0;
1860
1861 if (!initialized)
1862 ret = _omap_gpio_init();
1863
David Brownell11a78b72006-12-06 17:14:11 -08001864 mpuio_init();
1865
Santosh Shilimkar44169072009-05-28 14:16:04 -07001866#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1867 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001868 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001869 if (ret == 0) {
1870 ret = sysdev_class_register(&omap_gpio_sysclass);
1871 if (ret == 0)
1872 ret = sysdev_register(&omap_gpio_device);
1873 }
1874 }
1875#endif
1876
1877 return ret;
1878}
1879
Tony Lindgren92105bb2005-09-07 17:20:26 +01001880arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08001881
1882
1883#ifdef CONFIG_DEBUG_FS
1884
1885#include <linux/debugfs.h>
1886#include <linux/seq_file.h>
1887
1888static int gpio_is_input(struct gpio_bank *bank, int mask)
1889{
1890 void __iomem *reg = bank->base;
1891
1892 switch (bank->method) {
1893 case METHOD_MPUIO:
1894 reg += OMAP_MPUIO_IO_CNTL;
1895 break;
1896 case METHOD_GPIO_1510:
1897 reg += OMAP1510_GPIO_DIR_CONTROL;
1898 break;
1899 case METHOD_GPIO_1610:
1900 reg += OMAP1610_GPIO_DIRECTION;
1901 break;
1902 case METHOD_GPIO_730:
1903 reg += OMAP730_GPIO_DIR_CONTROL;
1904 break;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001905 case METHOD_GPIO_850:
1906 reg += OMAP850_GPIO_DIR_CONTROL;
1907 break;
David Brownellb9772a22006-12-06 17:13:53 -08001908 case METHOD_GPIO_24XX:
1909 reg += OMAP24XX_GPIO_OE;
1910 break;
1911 }
1912 return __raw_readl(reg) & mask;
1913}
1914
1915
1916static int dbg_gpio_show(struct seq_file *s, void *unused)
1917{
1918 unsigned i, j, gpio;
1919
1920 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
1921 struct gpio_bank *bank = gpio_bank + i;
1922 unsigned bankwidth = 16;
1923 u32 mask = 1;
1924
David Brownelle5c56ed2006-12-06 17:13:59 -08001925 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08001926 gpio = OMAP_MPUIO(0);
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001927 else if (cpu_class_is_omap2() || cpu_is_omap730() ||
1928 cpu_is_omap850())
David Brownellb9772a22006-12-06 17:13:53 -08001929 bankwidth = 32;
1930
1931 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
1932 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08001933 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08001934
David Brownell52e31342008-03-03 12:43:23 -08001935 label = gpiochip_is_requested(&bank->chip, j);
1936 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08001937 continue;
1938
1939 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08001940 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08001941 is_in = gpio_is_input(bank, mask);
1942
David Brownelle5c56ed2006-12-06 17:13:59 -08001943 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08001944 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08001945 else
David Brownell52e31342008-03-03 12:43:23 -08001946 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08001947 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08001948 label,
David Brownellb9772a22006-12-06 17:13:53 -08001949 is_in ? "in " : "out",
1950 value ? "hi" : "lo");
1951
David Brownell52e31342008-03-03 12:43:23 -08001952/* FIXME for at least omap2, show pullup/pulldown state */
1953
David Brownellb9772a22006-12-06 17:13:53 -08001954 irqstat = irq_desc[irq].status;
Tony Lindgren3a26e332009-01-15 13:09:53 +02001955#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07001956 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
David Brownellb9772a22006-12-06 17:13:53 -08001957 if (is_in && ((bank->suspend_wakeup & mask)
1958 || irqstat & IRQ_TYPE_SENSE_MASK)) {
1959 char *trigger = NULL;
1960
1961 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
1962 case IRQ_TYPE_EDGE_FALLING:
1963 trigger = "falling";
1964 break;
1965 case IRQ_TYPE_EDGE_RISING:
1966 trigger = "rising";
1967 break;
1968 case IRQ_TYPE_EDGE_BOTH:
1969 trigger = "bothedge";
1970 break;
1971 case IRQ_TYPE_LEVEL_LOW:
1972 trigger = "low";
1973 break;
1974 case IRQ_TYPE_LEVEL_HIGH:
1975 trigger = "high";
1976 break;
1977 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08001978 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08001979 break;
1980 }
David Brownell52e31342008-03-03 12:43:23 -08001981 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08001982 irq, trigger,
1983 (bank->suspend_wakeup & mask)
1984 ? " wakeup" : "");
1985 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02001986#endif
David Brownellb9772a22006-12-06 17:13:53 -08001987 seq_printf(s, "\n");
1988 }
1989
David Brownelle5c56ed2006-12-06 17:13:59 -08001990 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08001991 seq_printf(s, "\n");
1992 gpio = 0;
1993 }
1994 }
1995 return 0;
1996}
1997
1998static int dbg_gpio_open(struct inode *inode, struct file *file)
1999{
David Brownelle5c56ed2006-12-06 17:13:59 -08002000 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002001}
2002
2003static const struct file_operations debug_fops = {
2004 .open = dbg_gpio_open,
2005 .read = seq_read,
2006 .llseek = seq_lseek,
2007 .release = single_release,
2008};
2009
2010static int __init omap_gpio_debuginit(void)
2011{
David Brownelle5c56ed2006-12-06 17:13:59 -08002012 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2013 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002014 return 0;
2015}
2016late_initcall(omap_gpio_debuginit);
2017#endif