blob: 7c345b757df12d17014416116ce07a39d663c634 [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 */
Tony Lindgren94113262009-08-28 10:50:33 -070034#define OMAP1510_GPIO_BASE OMAP1_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 */
Tony Lindgren94113262009-08-28 10:50:33 -070048#define OMAP1610_GPIO1_BASE OMAP1_IO_ADDRESS(0xfffbe400)
49#define OMAP1610_GPIO2_BASE OMAP1_IO_ADDRESS(0xfffbec00)
50#define OMAP1610_GPIO3_BASE OMAP1_IO_ADDRESS(0xfffbb400)
51#define OMAP1610_GPIO4_BASE OMAP1_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 */
Tony Lindgren94113262009-08-28 10:50:33 -070073#define OMAP730_GPIO1_BASE OMAP1_IO_ADDRESS(0xfffbc000)
74#define OMAP730_GPIO2_BASE OMAP1_IO_ADDRESS(0xfffbc800)
75#define OMAP730_GPIO3_BASE OMAP1_IO_ADDRESS(0xfffbd000)
76#define OMAP730_GPIO4_BASE OMAP1_IO_ADDRESS(0xfffbd800)
77#define OMAP730_GPIO5_BASE OMAP1_IO_ADDRESS(0xfffbe000)
78#define OMAP730_GPIO6_BASE OMAP1_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 */
Tony Lindgren94113262009-08-28 10:50:33 -070089#define OMAP850_GPIO1_BASE OMAP1_IO_ADDRESS(0xfffbc000)
90#define OMAP850_GPIO2_BASE OMAP1_IO_ADDRESS(0xfffbc800)
91#define OMAP850_GPIO3_BASE OMAP1_IO_ADDRESS(0xfffbd000)
92#define OMAP850_GPIO4_BASE OMAP1_IO_ADDRESS(0xfffbd800)
93#define OMAP850_GPIO5_BASE OMAP1_IO_ADDRESS(0xfffbe000)
94#define OMAP850_GPIO6_BASE OMAP1_IO_ADDRESS(0xfffbe800)
Zebediah C. McClure56739a62009-03-23 18:07:40 -070095#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
Tony Lindgren61755562009-08-28 10:50:34 -0700102#define OMAP1_MPUIO_VBASE OMAP1_IO_ADDRESS(OMAP1_MPUIO_BASE)
Tony Lindgren94113262009-08-28 10:50:33 -0700103
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700104/*
Tony Lindgren92105bb2005-09-07 17:20:26 +0100105 * omap24xx specific GPIO registers
106 */
Tony Lindgren94113262009-08-28 10:50:33 -0700107#define OMAP242X_GPIO1_BASE OMAP2_IO_ADDRESS(0x48018000)
108#define OMAP242X_GPIO2_BASE OMAP2_IO_ADDRESS(0x4801a000)
109#define OMAP242X_GPIO3_BASE OMAP2_IO_ADDRESS(0x4801c000)
110#define OMAP242X_GPIO4_BASE OMAP2_IO_ADDRESS(0x4801e000)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800111
Tony Lindgren94113262009-08-28 10:50:33 -0700112#define OMAP243X_GPIO1_BASE OMAP2_IO_ADDRESS(0x4900C000)
113#define OMAP243X_GPIO2_BASE OMAP2_IO_ADDRESS(0x4900E000)
114#define OMAP243X_GPIO3_BASE OMAP2_IO_ADDRESS(0x49010000)
115#define OMAP243X_GPIO4_BASE OMAP2_IO_ADDRESS(0x49012000)
116#define OMAP243X_GPIO5_BASE OMAP2_IO_ADDRESS(0x480B6000)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800117
Tony Lindgren92105bb2005-09-07 17:20:26 +0100118#define OMAP24XX_GPIO_REVISION 0x0000
119#define OMAP24XX_GPIO_SYSCONFIG 0x0010
120#define OMAP24XX_GPIO_SYSSTATUS 0x0014
121#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300122#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
123#define OMAP24XX_GPIO_IRQENABLE2 0x002c
Tony Lindgren92105bb2005-09-07 17:20:26 +0100124#define OMAP24XX_GPIO_IRQENABLE1 0x001c
Tero Kristo723fdb72008-11-26 14:35:16 -0800125#define OMAP24XX_GPIO_WAKE_EN 0x0020
Tony Lindgren92105bb2005-09-07 17:20:26 +0100126#define OMAP24XX_GPIO_CTRL 0x0030
127#define OMAP24XX_GPIO_OE 0x0034
128#define OMAP24XX_GPIO_DATAIN 0x0038
129#define OMAP24XX_GPIO_DATAOUT 0x003c
130#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
131#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
132#define OMAP24XX_GPIO_RISINGDETECT 0x0048
133#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700134#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
135#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
Tony Lindgren92105bb2005-09-07 17:20:26 +0100136#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
137#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
138#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
139#define OMAP24XX_GPIO_SETWKUENA 0x0084
140#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
141#define OMAP24XX_GPIO_SETDATAOUT 0x0094
142
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530143#define OMAP4_GPIO_REVISION 0x0000
144#define OMAP4_GPIO_SYSCONFIG 0x0010
145#define OMAP4_GPIO_EOI 0x0020
146#define OMAP4_GPIO_IRQSTATUSRAW0 0x0024
147#define OMAP4_GPIO_IRQSTATUSRAW1 0x0028
148#define OMAP4_GPIO_IRQSTATUS0 0x002c
149#define OMAP4_GPIO_IRQSTATUS1 0x0030
150#define OMAP4_GPIO_IRQSTATUSSET0 0x0034
151#define OMAP4_GPIO_IRQSTATUSSET1 0x0038
152#define OMAP4_GPIO_IRQSTATUSCLR0 0x003c
153#define OMAP4_GPIO_IRQSTATUSCLR1 0x0040
154#define OMAP4_GPIO_IRQWAKEN0 0x0044
155#define OMAP4_GPIO_IRQWAKEN1 0x0048
156#define OMAP4_GPIO_SYSSTATUS 0x0104
157#define OMAP4_GPIO_CTRL 0x0130
158#define OMAP4_GPIO_OE 0x0134
159#define OMAP4_GPIO_DATAIN 0x0138
160#define OMAP4_GPIO_DATAOUT 0x013c
161#define OMAP4_GPIO_LEVELDETECT0 0x0140
162#define OMAP4_GPIO_LEVELDETECT1 0x0144
163#define OMAP4_GPIO_RISINGDETECT 0x0148
164#define OMAP4_GPIO_FALLINGDETECT 0x014c
165#define OMAP4_GPIO_DEBOUNCENABLE 0x0150
166#define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
167#define OMAP4_GPIO_CLEARDATAOUT 0x0190
168#define OMAP4_GPIO_SETDATAOUT 0x0194
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800169/*
170 * omap34xx specific GPIO registers
171 */
172
Tony Lindgren94113262009-08-28 10:50:33 -0700173#define OMAP34XX_GPIO1_BASE OMAP2_IO_ADDRESS(0x48310000)
174#define OMAP34XX_GPIO2_BASE OMAP2_IO_ADDRESS(0x49050000)
175#define OMAP34XX_GPIO3_BASE OMAP2_IO_ADDRESS(0x49052000)
176#define OMAP34XX_GPIO4_BASE OMAP2_IO_ADDRESS(0x49054000)
177#define OMAP34XX_GPIO5_BASE OMAP2_IO_ADDRESS(0x49056000)
178#define OMAP34XX_GPIO6_BASE OMAP2_IO_ADDRESS(0x49058000)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800179
Santosh Shilimkar44169072009-05-28 14:16:04 -0700180/*
181 * OMAP44XX specific GPIO registers
182 */
Tony Lindgren94113262009-08-28 10:50:33 -0700183#define OMAP44XX_GPIO1_BASE OMAP2_IO_ADDRESS(0x4a310000)
184#define OMAP44XX_GPIO2_BASE OMAP2_IO_ADDRESS(0x48055000)
185#define OMAP44XX_GPIO3_BASE OMAP2_IO_ADDRESS(0x48057000)
186#define OMAP44XX_GPIO4_BASE OMAP2_IO_ADDRESS(0x48059000)
187#define OMAP44XX_GPIO5_BASE OMAP2_IO_ADDRESS(0x4805B000)
188#define OMAP44XX_GPIO6_BASE OMAP2_IO_ADDRESS(0x4805D000)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800189
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100190struct gpio_bank {
Tony Lindgren92105bb2005-09-07 17:20:26 +0100191 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100192 u16 irq;
193 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100194 int method;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700195#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
196 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100197 u32 suspend_wakeup;
198 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800199#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700200#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
201 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800202 u32 non_wakeup_gpios;
203 u32 enabled_non_wakeup_gpios;
204
205 u32 saved_datain;
206 u32 saved_fallingdetect;
207 u32 saved_risingdetect;
208#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800209 u32 level_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100210 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800211 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800212 struct clk *dbck;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100213};
214
215#define METHOD_MPUIO 0
216#define METHOD_GPIO_1510 1
217#define METHOD_GPIO_1610 2
218#define METHOD_GPIO_730 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700219#define METHOD_GPIO_850 4
220#define METHOD_GPIO_24XX 5
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100221
Tony Lindgren92105bb2005-09-07 17:20:26 +0100222#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100223static struct gpio_bank gpio_bank_1610[5] = {
Tony Lindgren94113262009-08-28 10:50:33 -0700224 { OMAP1_MPUIO_VBASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO},
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100225 { OMAP1610_GPIO1_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1610 },
226 { OMAP1610_GPIO2_BASE, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16, METHOD_GPIO_1610 },
227 { OMAP1610_GPIO3_BASE, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32, METHOD_GPIO_1610 },
228 { OMAP1610_GPIO4_BASE, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48, METHOD_GPIO_1610 },
229};
230#endif
231
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000232#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100233static struct gpio_bank gpio_bank_1510[2] = {
Tony Lindgren94113262009-08-28 10:50:33 -0700234 { OMAP1_MPUIO_VBASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100235 { OMAP1510_GPIO_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1510 }
236};
237#endif
238
239#ifdef CONFIG_ARCH_OMAP730
240static struct gpio_bank gpio_bank_730[7] = {
Tony Lindgren94113262009-08-28 10:50:33 -0700241 { OMAP1_MPUIO_VBASE, INT_730_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100242 { OMAP730_GPIO1_BASE, INT_730_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_730 },
243 { OMAP730_GPIO2_BASE, INT_730_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_730 },
244 { OMAP730_GPIO3_BASE, INT_730_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_730 },
245 { OMAP730_GPIO4_BASE, INT_730_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_730 },
246 { OMAP730_GPIO5_BASE, INT_730_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_730 },
247 { OMAP730_GPIO6_BASE, INT_730_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_730 },
248};
249#endif
250
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700251#ifdef CONFIG_ARCH_OMAP850
252static struct gpio_bank gpio_bank_850[7] = {
Angelo Arrifano501e9bd2009-09-24 16:23:14 -0700253 { OMAP1_MPUIO_VBASE, INT_850_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700254 { OMAP850_GPIO1_BASE, INT_850_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_850 },
255 { OMAP850_GPIO2_BASE, INT_850_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_850 },
256 { OMAP850_GPIO3_BASE, INT_850_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_850 },
257 { OMAP850_GPIO4_BASE, INT_850_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_850 },
258 { OMAP850_GPIO5_BASE, INT_850_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_850 },
259 { OMAP850_GPIO6_BASE, INT_850_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_850 },
260};
261#endif
262
263
Tony Lindgren92105bb2005-09-07 17:20:26 +0100264#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800265
266static struct gpio_bank gpio_bank_242x[4] = {
267 { OMAP242X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
268 { OMAP242X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
269 { OMAP242X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
270 { OMAP242X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
Tony Lindgren92105bb2005-09-07 17:20:26 +0100271};
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800272
273static struct gpio_bank gpio_bank_243x[5] = {
274 { OMAP243X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
275 { OMAP243X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
276 { OMAP243X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
277 { OMAP243X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
278 { OMAP243X_GPIO5_BASE, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX },
279};
280
Tony Lindgren92105bb2005-09-07 17:20:26 +0100281#endif
282
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800283#ifdef CONFIG_ARCH_OMAP34XX
284static struct gpio_bank gpio_bank_34xx[6] = {
285 { OMAP34XX_GPIO1_BASE, INT_34XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
286 { OMAP34XX_GPIO2_BASE, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
287 { OMAP34XX_GPIO3_BASE, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
288 { OMAP34XX_GPIO4_BASE, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
289 { OMAP34XX_GPIO5_BASE, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX },
290 { OMAP34XX_GPIO6_BASE, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_24XX },
291};
292
293#endif
294
Santosh Shilimkar44169072009-05-28 14:16:04 -0700295#ifdef CONFIG_ARCH_OMAP4
296static struct gpio_bank gpio_bank_44xx[6] = {
297 { OMAP44XX_GPIO1_BASE, INT_44XX_GPIO_BANK1, IH_GPIO_BASE, \
298 METHOD_GPIO_24XX },
299 { OMAP44XX_GPIO2_BASE, INT_44XX_GPIO_BANK2, IH_GPIO_BASE + 32, \
300 METHOD_GPIO_24XX },
301 { OMAP44XX_GPIO3_BASE, INT_44XX_GPIO_BANK3, IH_GPIO_BASE + 64, \
302 METHOD_GPIO_24XX },
303 { OMAP44XX_GPIO4_BASE, INT_44XX_GPIO_BANK4, IH_GPIO_BASE + 96, \
304 METHOD_GPIO_24XX },
305 { OMAP44XX_GPIO5_BASE, INT_44XX_GPIO_BANK5, IH_GPIO_BASE + 128, \
306 METHOD_GPIO_24XX },
307 { OMAP44XX_GPIO6_BASE, INT_44XX_GPIO_BANK6, IH_GPIO_BASE + 160, \
308 METHOD_GPIO_24XX },
309};
310
311#endif
312
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100313static struct gpio_bank *gpio_bank;
314static int gpio_bank_count;
315
316static inline struct gpio_bank *get_gpio_bank(int gpio)
317{
Tony Lindgren6e60e792006-04-02 17:46:23 +0100318 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100319 if (OMAP_GPIO_IS_MPUIO(gpio))
320 return &gpio_bank[0];
321 return &gpio_bank[1];
322 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100323 if (cpu_is_omap16xx()) {
324 if (OMAP_GPIO_IS_MPUIO(gpio))
325 return &gpio_bank[0];
326 return &gpio_bank[1 + (gpio >> 4)];
327 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700328 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100329 if (OMAP_GPIO_IS_MPUIO(gpio))
330 return &gpio_bank[0];
331 return &gpio_bank[1 + (gpio >> 5)];
332 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100333 if (cpu_is_omap24xx())
334 return &gpio_bank[gpio >> 5];
Santosh Shilimkar44169072009-05-28 14:16:04 -0700335 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800336 return &gpio_bank[gpio >> 5];
David Brownelle031ab22008-12-10 17:35:27 -0800337 BUG();
338 return NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100339}
340
341static inline int get_gpio_index(int gpio)
342{
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700343 if (cpu_is_omap7xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100344 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100345 if (cpu_is_omap24xx())
346 return gpio & 0x1f;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700347 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800348 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100349 return gpio & 0x0f;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100350}
351
352static inline int gpio_valid(int gpio)
353{
354 if (gpio < 0)
355 return -1;
Tony Lindgrend11ac972008-01-12 15:35:04 -0800356 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
Jonathan McDowell193e68b2006-09-25 12:41:30 +0300357 if (gpio >= OMAP_MAX_GPIO_LINES + 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100358 return -1;
359 return 0;
360 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100361 if (cpu_is_omap15xx() && gpio < 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100362 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100363 if ((cpu_is_omap16xx()) && gpio < 64)
364 return 0;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700365 if (cpu_is_omap7xx() && gpio < 192)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100366 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100367 if (cpu_is_omap24xx() && gpio < 128)
368 return 0;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700369 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800370 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100371 return -1;
372}
373
374static int check_gpio(int gpio)
375{
Roel Kluind32b20f2009-11-17 14:39:03 -0800376 if (unlikely(gpio_valid(gpio) < 0)) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100377 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
378 dump_stack();
379 return -1;
380 }
381 return 0;
382}
383
384static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
385{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100386 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100387 u32 l;
388
389 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800390#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100391 case METHOD_MPUIO:
392 reg += OMAP_MPUIO_IO_CNTL;
393 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800394#endif
395#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100396 case METHOD_GPIO_1510:
397 reg += OMAP1510_GPIO_DIR_CONTROL;
398 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800399#endif
400#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100401 case METHOD_GPIO_1610:
402 reg += OMAP1610_GPIO_DIRECTION;
403 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800404#endif
405#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100406 case METHOD_GPIO_730:
407 reg += OMAP730_GPIO_DIR_CONTROL;
408 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800409#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700410#ifdef CONFIG_ARCH_OMAP850
411 case METHOD_GPIO_850:
412 reg += OMAP850_GPIO_DIR_CONTROL;
413 break;
414#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530415#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100416 case METHOD_GPIO_24XX:
417 reg += OMAP24XX_GPIO_OE;
418 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800419#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530420#if defined(CONFIG_ARCH_OMAP4)
421 case METHOD_GPIO_24XX:
422 reg += OMAP4_GPIO_OE;
423 break;
424#endif
David Brownelle5c56ed2006-12-06 17:13:59 -0800425 default:
426 WARN_ON(1);
427 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100428 }
429 l = __raw_readl(reg);
430 if (is_input)
431 l |= 1 << gpio;
432 else
433 l &= ~(1 << gpio);
434 __raw_writel(l, reg);
435}
436
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100437static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
438{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100439 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100440 u32 l = 0;
441
442 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800443#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100444 case METHOD_MPUIO:
445 reg += OMAP_MPUIO_OUTPUT;
446 l = __raw_readl(reg);
447 if (enable)
448 l |= 1 << gpio;
449 else
450 l &= ~(1 << gpio);
451 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800452#endif
453#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100454 case METHOD_GPIO_1510:
455 reg += OMAP1510_GPIO_DATA_OUTPUT;
456 l = __raw_readl(reg);
457 if (enable)
458 l |= 1 << gpio;
459 else
460 l &= ~(1 << gpio);
461 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800462#endif
463#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100464 case METHOD_GPIO_1610:
465 if (enable)
466 reg += OMAP1610_GPIO_SET_DATAOUT;
467 else
468 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
469 l = 1 << gpio;
470 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800471#endif
472#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100473 case METHOD_GPIO_730:
474 reg += OMAP730_GPIO_DATA_OUTPUT;
475 l = __raw_readl(reg);
476 if (enable)
477 l |= 1 << gpio;
478 else
479 l &= ~(1 << gpio);
480 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800481#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700482#ifdef CONFIG_ARCH_OMAP850
483 case METHOD_GPIO_850:
484 reg += OMAP850_GPIO_DATA_OUTPUT;
485 l = __raw_readl(reg);
486 if (enable)
487 l |= 1 << gpio;
488 else
489 l &= ~(1 << gpio);
490 break;
491#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530492#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100493 case METHOD_GPIO_24XX:
494 if (enable)
495 reg += OMAP24XX_GPIO_SETDATAOUT;
496 else
497 reg += OMAP24XX_GPIO_CLEARDATAOUT;
498 l = 1 << gpio;
499 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800500#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530501#ifdef CONFIG_ARCH_OMAP4
502 case METHOD_GPIO_24XX:
503 if (enable)
504 reg += OMAP4_GPIO_SETDATAOUT;
505 else
506 reg += OMAP4_GPIO_CLEARDATAOUT;
507 l = 1 << gpio;
508 break;
509#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100510 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800511 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100512 return;
513 }
514 __raw_writel(l, reg);
515}
516
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300517static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100518{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100519 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100520
521 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800522 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100523 reg = bank->base;
524 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800525#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100526 case METHOD_MPUIO:
527 reg += OMAP_MPUIO_INPUT_LATCH;
528 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800529#endif
530#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100531 case METHOD_GPIO_1510:
532 reg += OMAP1510_GPIO_DATA_INPUT;
533 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800534#endif
535#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100536 case METHOD_GPIO_1610:
537 reg += OMAP1610_GPIO_DATAIN;
538 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800539#endif
540#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100541 case METHOD_GPIO_730:
542 reg += OMAP730_GPIO_DATA_INPUT;
543 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800544#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700545#ifdef CONFIG_ARCH_OMAP850
546 case METHOD_GPIO_850:
547 reg += OMAP850_GPIO_DATA_INPUT;
548 break;
549#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530550#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100551 case METHOD_GPIO_24XX:
552 reg += OMAP24XX_GPIO_DATAIN;
553 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800554#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530555#ifdef CONFIG_ARCH_OMAP4
556 case METHOD_GPIO_24XX:
557 reg += OMAP4_GPIO_DATAIN;
558 break;
559#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100560 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800561 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100562 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100563 return (__raw_readl(reg)
564 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100565}
566
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300567static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
568{
569 void __iomem *reg;
570
571 if (check_gpio(gpio) < 0)
572 return -EINVAL;
573 reg = bank->base;
574
575 switch (bank->method) {
576#ifdef CONFIG_ARCH_OMAP1
577 case METHOD_MPUIO:
578 reg += OMAP_MPUIO_OUTPUT;
579 break;
580#endif
581#ifdef CONFIG_ARCH_OMAP15XX
582 case METHOD_GPIO_1510:
583 reg += OMAP1510_GPIO_DATA_OUTPUT;
584 break;
585#endif
586#ifdef CONFIG_ARCH_OMAP16XX
587 case METHOD_GPIO_1610:
588 reg += OMAP1610_GPIO_DATAOUT;
589 break;
590#endif
591#ifdef CONFIG_ARCH_OMAP730
592 case METHOD_GPIO_730:
593 reg += OMAP730_GPIO_DATA_OUTPUT;
594 break;
595#endif
596#ifdef CONFIG_ARCH_OMAP850
597 case METHOD_GPIO_850:
598 reg += OMAP850_GPIO_DATA_OUTPUT;
599 break;
600#endif
601#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
602 defined(CONFIG_ARCH_OMAP4)
603 case METHOD_GPIO_24XX:
604 reg += OMAP24XX_GPIO_DATAOUT;
605 break;
606#endif
607 default:
608 return -EINVAL;
609 }
610
611 return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
612}
613
Tony Lindgren92105bb2005-09-07 17:20:26 +0100614#define MOD_REG_BIT(reg, bit_mask, set) \
615do { \
616 int l = __raw_readl(base + reg); \
617 if (set) l |= bit_mask; \
618 else l &= ~bit_mask; \
619 __raw_writel(l, base + reg); \
620} while(0)
621
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700622void omap_set_gpio_debounce(int gpio, int enable)
623{
624 struct gpio_bank *bank;
625 void __iomem *reg;
David Brownelle031ab22008-12-10 17:35:27 -0800626 unsigned long flags;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700627 u32 val, l = 1 << get_gpio_index(gpio);
628
629 if (cpu_class_is_omap1())
630 return;
631
632 bank = get_gpio_bank(gpio);
633 reg = bank->base;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530634#ifdef CONFIG_ARCH_OMAP4
635 reg += OMAP4_GPIO_DEBOUNCENABLE;
636#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700637 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530638#endif
David Brownelle031ab22008-12-10 17:35:27 -0800639
640 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700641 val = __raw_readl(reg);
642
Jouni Hogander89db9482008-12-10 17:35:24 -0800643 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700644 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800645 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700646 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800647 else
David Brownelle031ab22008-12-10 17:35:27 -0800648 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800649
Santosh Shilimkar44169072009-05-28 14:16:04 -0700650 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800651 if (enable)
652 clk_enable(bank->dbck);
653 else
654 clk_disable(bank->dbck);
655 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700656
657 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800658done:
659 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700660}
661EXPORT_SYMBOL(omap_set_gpio_debounce);
662
663void omap_set_gpio_debounce_time(int gpio, int enc_time)
664{
665 struct gpio_bank *bank;
666 void __iomem *reg;
667
668 if (cpu_class_is_omap1())
669 return;
670
671 bank = get_gpio_bank(gpio);
672 reg = bank->base;
673
674 enc_time &= 0xff;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530675#ifdef CONFIG_ARCH_OMAP4
676 reg += OMAP4_GPIO_DEBOUNCINGTIME;
677#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700678 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530679#endif
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700680 __raw_writel(enc_time, reg);
681}
682EXPORT_SYMBOL(omap_set_gpio_debounce_time);
683
Santosh Shilimkar44169072009-05-28 14:16:04 -0700684#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
685 defined(CONFIG_ARCH_OMAP4)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700686static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
687 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100688{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800689 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100690 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530691 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100692
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530693 if (cpu_is_omap44xx()) {
694 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
695 trigger & IRQ_TYPE_LEVEL_LOW);
696 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
697 trigger & IRQ_TYPE_LEVEL_HIGH);
698 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
699 trigger & IRQ_TYPE_EDGE_RISING);
700 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
701 trigger & IRQ_TYPE_EDGE_FALLING);
702 } else {
703 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
704 trigger & IRQ_TYPE_LEVEL_LOW);
705 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
706 trigger & IRQ_TYPE_LEVEL_HIGH);
707 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
708 trigger & IRQ_TYPE_EDGE_RISING);
709 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
710 trigger & IRQ_TYPE_EDGE_FALLING);
711 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800712 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530713 if (cpu_is_omap44xx()) {
714 if (trigger != 0)
715 __raw_writel(1 << gpio, bank->base+
716 OMAP4_GPIO_IRQWAKEN0);
717 else {
718 val = __raw_readl(bank->base +
719 OMAP4_GPIO_IRQWAKEN0);
720 __raw_writel(val & (~(1 << gpio)), bank->base +
721 OMAP4_GPIO_IRQWAKEN0);
722 }
723 } else {
724 if (trigger != 0)
725 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700726 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530727 else
728 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700729 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530730 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800731 } else {
732 if (trigger != 0)
733 bank->enabled_non_wakeup_gpios |= gpio_bit;
734 else
735 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
736 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700737
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530738 if (cpu_is_omap44xx()) {
739 bank->level_mask =
740 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
741 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
742 } else {
743 bank->level_mask =
744 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
745 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
746 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100747}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800748#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100749
750static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
751{
752 void __iomem *reg = bank->base;
753 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100754
755 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800756#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100757 case METHOD_MPUIO:
758 reg += OMAP_MPUIO_GPIO_INT_EDGE;
759 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100760 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100761 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100762 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100763 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100764 else
765 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100766 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800767#endif
768#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100769 case METHOD_GPIO_1510:
770 reg += OMAP1510_GPIO_INT_CONTROL;
771 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100772 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100773 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100774 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100775 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100776 else
777 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100778 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800779#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800780#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100781 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100782 if (gpio & 0x08)
783 reg += OMAP1610_GPIO_EDGE_CTRL2;
784 else
785 reg += OMAP1610_GPIO_EDGE_CTRL1;
786 gpio &= 0x07;
787 l = __raw_readl(reg);
788 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100789 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100790 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100791 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100792 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800793 if (trigger)
794 /* Enable wake-up during idle for dynamic tick */
795 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
796 else
797 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100798 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800799#endif
800#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100801 case METHOD_GPIO_730:
802 reg += OMAP730_GPIO_INT_CONTROL;
803 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100804 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100805 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100806 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100807 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100808 else
809 goto bad;
810 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800811#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700812#ifdef CONFIG_ARCH_OMAP850
813 case METHOD_GPIO_850:
814 reg += OMAP850_GPIO_INT_CONTROL;
815 l = __raw_readl(reg);
816 if (trigger & IRQ_TYPE_EDGE_RISING)
817 l |= 1 << gpio;
818 else if (trigger & IRQ_TYPE_EDGE_FALLING)
819 l &= ~(1 << gpio);
820 else
821 goto bad;
822 break;
823#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700824#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
825 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100826 case METHOD_GPIO_24XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800827 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100828 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800829#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100830 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100831 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100832 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100833 __raw_writel(l, reg);
834 return 0;
835bad:
836 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100837}
838
Tony Lindgren92105bb2005-09-07 17:20:26 +0100839static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100840{
841 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100842 unsigned gpio;
843 int retval;
David Brownella6472532008-03-03 04:33:30 -0800844 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100845
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800846 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100847 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
848 else
849 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100850
851 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100852 return -EINVAL;
853
David Brownelle5c56ed2006-12-06 17:13:59 -0800854 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100855 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800856
857 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800858 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800859 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100860 return -EINVAL;
861
David Brownell58781012006-12-06 17:14:10 -0800862 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800863 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100864 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800865 if (retval == 0) {
866 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
867 irq_desc[irq].status |= type;
868 }
David Brownella6472532008-03-03 04:33:30 -0800869 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800870
871 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
872 __set_irq_handler_unlocked(irq, handle_level_irq);
873 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
874 __set_irq_handler_unlocked(irq, handle_edge_irq);
875
Tony Lindgren92105bb2005-09-07 17:20:26 +0100876 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100877}
878
879static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
880{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100881 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100882
883 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800884#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100885 case METHOD_MPUIO:
886 /* MPUIO irqstatus is reset by reading the status register,
887 * so do nothing here */
888 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800889#endif
890#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100891 case METHOD_GPIO_1510:
892 reg += OMAP1510_GPIO_INT_STATUS;
893 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800894#endif
895#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100896 case METHOD_GPIO_1610:
897 reg += OMAP1610_GPIO_IRQSTATUS1;
898 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800899#endif
900#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100901 case METHOD_GPIO_730:
902 reg += OMAP730_GPIO_INT_STATUS;
903 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800904#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700905#ifdef CONFIG_ARCH_OMAP850
906 case METHOD_GPIO_850:
907 reg += OMAP850_GPIO_INT_STATUS;
908 break;
909#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530910#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100911 case METHOD_GPIO_24XX:
912 reg += OMAP24XX_GPIO_IRQSTATUS1;
913 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800914#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530915#if defined(CONFIG_ARCH_OMAP4)
916 case METHOD_GPIO_24XX:
917 reg += OMAP4_GPIO_IRQSTATUS0;
918 break;
919#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100920 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800921 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100922 return;
923 }
924 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300925
926 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800927#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Roger Quadrosbedfd152009-04-23 11:10:50 -0700928 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530929#endif
930#if defined(CONFIG_ARCH_OMAP4)
931 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
932#endif
933 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700934 __raw_writel(gpio_mask, reg);
935
936 /* Flush posted write for the irq status to avoid spurious interrupts */
937 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530938 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100939}
940
941static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
942{
943 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
944}
945
Imre Deakea6dedd2006-06-26 16:16:00 -0700946static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
947{
948 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700949 int inv = 0;
950 u32 l;
951 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700952
953 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800954#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700955 case METHOD_MPUIO:
956 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700957 mask = 0xffff;
958 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700959 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800960#endif
961#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700962 case METHOD_GPIO_1510:
963 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700964 mask = 0xffff;
965 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700966 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800967#endif
968#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700969 case METHOD_GPIO_1610:
970 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700971 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700972 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800973#endif
974#ifdef CONFIG_ARCH_OMAP730
Imre Deakea6dedd2006-06-26 16:16:00 -0700975 case METHOD_GPIO_730:
976 reg += OMAP730_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700977 mask = 0xffffffff;
978 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700979 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800980#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700981#ifdef CONFIG_ARCH_OMAP850
982 case METHOD_GPIO_850:
983 reg += OMAP850_GPIO_INT_MASK;
984 mask = 0xffffffff;
985 inv = 1;
986 break;
987#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530988#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Imre Deakea6dedd2006-06-26 16:16:00 -0700989 case METHOD_GPIO_24XX:
990 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700991 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700992 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800993#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530994#if defined(CONFIG_ARCH_OMAP4)
995 case METHOD_GPIO_24XX:
996 reg += OMAP4_GPIO_IRQSTATUSSET0;
997 mask = 0xffffffff;
998 break;
999#endif
Imre Deakea6dedd2006-06-26 16:16:00 -07001000 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001001 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -07001002 return 0;
1003 }
1004
Imre Deak99c47702006-06-26 16:16:07 -07001005 l = __raw_readl(reg);
1006 if (inv)
1007 l = ~l;
1008 l &= mask;
1009 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -07001010}
1011
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001012static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
1013{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001014 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001015 u32 l;
1016
1017 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001018#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001019 case METHOD_MPUIO:
1020 reg += OMAP_MPUIO_GPIO_MASKIT;
1021 l = __raw_readl(reg);
1022 if (enable)
1023 l &= ~(gpio_mask);
1024 else
1025 l |= gpio_mask;
1026 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001027#endif
1028#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001029 case METHOD_GPIO_1510:
1030 reg += OMAP1510_GPIO_INT_MASK;
1031 l = __raw_readl(reg);
1032 if (enable)
1033 l &= ~(gpio_mask);
1034 else
1035 l |= gpio_mask;
1036 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001037#endif
1038#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001039 case METHOD_GPIO_1610:
1040 if (enable)
1041 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1042 else
1043 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1044 l = gpio_mask;
1045 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001046#endif
1047#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001048 case METHOD_GPIO_730:
1049 reg += OMAP730_GPIO_INT_MASK;
1050 l = __raw_readl(reg);
1051 if (enable)
1052 l &= ~(gpio_mask);
1053 else
1054 l |= gpio_mask;
1055 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001056#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001057#ifdef CONFIG_ARCH_OMAP850
1058 case METHOD_GPIO_850:
1059 reg += OMAP850_GPIO_INT_MASK;
1060 l = __raw_readl(reg);
1061 if (enable)
1062 l &= ~(gpio_mask);
1063 else
1064 l |= gpio_mask;
1065 break;
1066#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301067#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001068 case METHOD_GPIO_24XX:
1069 if (enable)
1070 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1071 else
1072 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1073 l = gpio_mask;
1074 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001075#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301076#ifdef CONFIG_ARCH_OMAP4
1077 case METHOD_GPIO_24XX:
1078 if (enable)
1079 reg += OMAP4_GPIO_IRQSTATUSSET0;
1080 else
1081 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1082 l = gpio_mask;
1083 break;
1084#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001085 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001086 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001087 return;
1088 }
1089 __raw_writel(l, reg);
1090}
1091
1092static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1093{
1094 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1095}
1096
Tony Lindgren92105bb2005-09-07 17:20:26 +01001097/*
1098 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1099 * 1510 does not seem to have a wake-up register. If JTAG is connected
1100 * to the target, system will wake up always on GPIO events. While
1101 * system is running all registered GPIO interrupts need to have wake-up
1102 * enabled. When system is suspended, only selected GPIO interrupts need
1103 * to have wake-up enabled.
1104 */
1105static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1106{
David Brownella6472532008-03-03 04:33:30 -08001107 unsigned long flags;
1108
Tony Lindgren92105bb2005-09-07 17:20:26 +01001109 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001110#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001111 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001112 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001113 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001114 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001115 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001116 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001117 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001118 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001119 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001120#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001121#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1122 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001123 case METHOD_GPIO_24XX:
David Brownell11a78b72006-12-06 17:14:11 -08001124 if (bank->non_wakeup_gpios & (1 << gpio)) {
1125 printk(KERN_ERR "Unable to modify wakeup on "
1126 "non-wakeup GPIO%d\n",
1127 (bank - gpio_bank) * 32 + gpio);
1128 return -EINVAL;
1129 }
David Brownella6472532008-03-03 04:33:30 -08001130 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001131 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001132 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001133 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001134 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001135 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001136 return 0;
1137#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001138 default:
1139 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1140 bank->method);
1141 return -EINVAL;
1142 }
1143}
1144
Tony Lindgren4196dd62006-09-25 12:41:38 +03001145static void _reset_gpio(struct gpio_bank *bank, int gpio)
1146{
1147 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1148 _set_gpio_irqenable(bank, gpio, 0);
1149 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001150 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001151}
1152
Tony Lindgren92105bb2005-09-07 17:20:26 +01001153/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1154static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1155{
1156 unsigned int gpio = irq - IH_GPIO_BASE;
1157 struct gpio_bank *bank;
1158 int retval;
1159
1160 if (check_gpio(gpio) < 0)
1161 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001162 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001163 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001164
1165 return retval;
1166}
1167
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001168static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001169{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001170 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001171 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001172
David Brownella6472532008-03-03 04:33:30 -08001173 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001174
Tony Lindgren4196dd62006-09-25 12:41:38 +03001175 /* Set trigger to none. You need to enable the desired trigger with
1176 * request_irq() or set_irq_type().
1177 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001178 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001179
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001180#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001181 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001182 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001183
Tony Lindgren92105bb2005-09-07 17:20:26 +01001184 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001185 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001186 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001187 }
1188#endif
David Brownella6472532008-03-03 04:33:30 -08001189 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001190
1191 return 0;
1192}
1193
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001194static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001195{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001196 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001197 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001198
David Brownella6472532008-03-03 04:33:30 -08001199 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001200#ifdef CONFIG_ARCH_OMAP16XX
1201 if (bank->method == METHOD_GPIO_1610) {
1202 /* Disable wake-up during idle for dynamic tick */
1203 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001204 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001205 }
1206#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001207#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1208 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001209 if (bank->method == METHOD_GPIO_24XX) {
1210 /* Disable wake-up during idle for dynamic tick */
1211 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001212 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001213 }
1214#endif
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001215 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001216 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001217}
1218
1219/*
1220 * We need to unmask the GPIO bank interrupt as soon as possible to
1221 * avoid missing GPIO interrupts for other lines in the bank.
1222 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1223 * in the bank to avoid missing nested interrupts for a GPIO line.
1224 * If we wait to unmask individual GPIO lines in the bank after the
1225 * line's interrupt handler has been run, we may miss some nested
1226 * interrupts.
1227 */
Russell King10dd5ce2006-11-23 11:41:32 +00001228static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001229{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001230 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001231 u32 isr;
1232 unsigned int gpio_irq;
1233 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001234 u32 retrigger = 0;
1235 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001236
1237 desc->chip->ack(irq);
1238
Thomas Gleixner418ca1f02006-07-01 22:32:41 +01001239 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001240#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001241 if (bank->method == METHOD_MPUIO)
1242 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001243#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001244#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001245 if (bank->method == METHOD_GPIO_1510)
1246 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1247#endif
1248#if defined(CONFIG_ARCH_OMAP16XX)
1249 if (bank->method == METHOD_GPIO_1610)
1250 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1251#endif
1252#ifdef CONFIG_ARCH_OMAP730
1253 if (bank->method == METHOD_GPIO_730)
1254 isr_reg = bank->base + OMAP730_GPIO_INT_STATUS;
1255#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001256#ifdef CONFIG_ARCH_OMAP850
1257 if (bank->method == METHOD_GPIO_850)
1258 isr_reg = bank->base + OMAP850_GPIO_INT_STATUS;
1259#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301260#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001261 if (bank->method == METHOD_GPIO_24XX)
1262 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1263#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301264#if defined(CONFIG_ARCH_OMAP4)
1265 if (bank->method == METHOD_GPIO_24XX)
1266 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1267#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001268 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001269 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001270 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001271
Imre Deakea6dedd2006-06-26 16:16:00 -07001272 enabled = _get_gpio_irqbank_mask(bank);
1273 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001274
1275 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1276 isr &= 0x0000ffff;
1277
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001278 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001279 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001280 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001281
1282 /* clear edge sensitive interrupts before handler(s) are
1283 called so that we don't miss any interrupt occurred while
1284 executing them */
1285 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1286 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1287 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1288
1289 /* if there is only edge sensitive GPIO pin interrupts
1290 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001291 if (!level_mask && !unmasked) {
1292 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001293 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001294 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001295
Imre Deakea6dedd2006-06-26 16:16:00 -07001296 isr |= retrigger;
1297 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001298 if (!isr)
1299 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001300
Tony Lindgren92105bb2005-09-07 17:20:26 +01001301 gpio_irq = bank->virtual_irq_start;
1302 for (; isr != 0; isr >>= 1, gpio_irq++) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001303 if (!(isr & 1))
1304 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001305
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001306 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001307 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001308 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001309 /* if bank has any level sensitive GPIO pin interrupt
1310 configured, we must unmask the bank interrupt only after
1311 handler(s) are executed in order to avoid spurious bank
1312 interrupt */
1313 if (!unmasked)
1314 desc->chip->unmask(irq);
1315
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001316}
1317
Tony Lindgren4196dd62006-09-25 12:41:38 +03001318static void gpio_irq_shutdown(unsigned int irq)
1319{
1320 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001321 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001322
1323 _reset_gpio(bank, gpio);
1324}
1325
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001326static void gpio_ack_irq(unsigned int irq)
1327{
1328 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001329 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001330
1331 _clear_gpio_irqstatus(bank, gpio);
1332}
1333
1334static void gpio_mask_irq(unsigned int irq)
1335{
1336 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001337 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001338
1339 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001340 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001341}
1342
1343static void gpio_unmask_irq(unsigned int irq)
1344{
1345 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001346 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001347 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001348 struct irq_desc *desc = irq_to_desc(irq);
1349 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1350
1351 if (trigger)
1352 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001353
1354 /* For level-triggered GPIOs, the clearing must be done after
1355 * the HW source is cleared, thus after the handler has run */
1356 if (bank->level_mask & irq_mask) {
1357 _set_gpio_irqenable(bank, gpio, 0);
1358 _clear_gpio_irqstatus(bank, gpio);
1359 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001360
Kevin Hilman4de8c752008-01-16 21:56:14 -08001361 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001362}
1363
David Brownelle5c56ed2006-12-06 17:13:59 -08001364static struct irq_chip gpio_irq_chip = {
1365 .name = "GPIO",
1366 .shutdown = gpio_irq_shutdown,
1367 .ack = gpio_ack_irq,
1368 .mask = gpio_mask_irq,
1369 .unmask = gpio_unmask_irq,
1370 .set_type = gpio_irq_type,
1371 .set_wake = gpio_wake_enable,
1372};
1373
1374/*---------------------------------------------------------------------*/
1375
1376#ifdef CONFIG_ARCH_OMAP1
1377
1378/* MPUIO uses the always-on 32k clock */
1379
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001380static void mpuio_ack_irq(unsigned int irq)
1381{
1382 /* The ISR is reset automatically, so do nothing here. */
1383}
1384
1385static void mpuio_mask_irq(unsigned int irq)
1386{
1387 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001388 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001389
1390 _set_gpio_irqenable(bank, gpio, 0);
1391}
1392
1393static void mpuio_unmask_irq(unsigned int irq)
1394{
1395 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001396 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001397
1398 _set_gpio_irqenable(bank, gpio, 1);
1399}
1400
David Brownelle5c56ed2006-12-06 17:13:59 -08001401static struct irq_chip mpuio_irq_chip = {
1402 .name = "MPUIO",
1403 .ack = mpuio_ack_irq,
1404 .mask = mpuio_mask_irq,
1405 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001406 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001407#ifdef CONFIG_ARCH_OMAP16XX
1408 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1409 .set_wake = gpio_wake_enable,
1410#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001411};
1412
David Brownelle5c56ed2006-12-06 17:13:59 -08001413
1414#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1415
David Brownell11a78b72006-12-06 17:14:11 -08001416
1417#ifdef CONFIG_ARCH_OMAP16XX
1418
1419#include <linux/platform_device.h>
1420
Magnus Damm79ee0312009-07-08 13:22:04 +02001421static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001422{
Magnus Damm79ee0312009-07-08 13:22:04 +02001423 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001424 struct gpio_bank *bank = platform_get_drvdata(pdev);
1425 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001426 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001427
David Brownella6472532008-03-03 04:33:30 -08001428 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001429 bank->saved_wakeup = __raw_readl(mask_reg);
1430 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001431 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001432
1433 return 0;
1434}
1435
Magnus Damm79ee0312009-07-08 13:22:04 +02001436static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001437{
Magnus Damm79ee0312009-07-08 13:22:04 +02001438 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001439 struct gpio_bank *bank = platform_get_drvdata(pdev);
1440 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001441 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001442
David Brownella6472532008-03-03 04:33:30 -08001443 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001444 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001445 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001446
1447 return 0;
1448}
1449
Magnus Damm79ee0312009-07-08 13:22:04 +02001450static struct dev_pm_ops omap_mpuio_dev_pm_ops = {
1451 .suspend_noirq = omap_mpuio_suspend_noirq,
1452 .resume_noirq = omap_mpuio_resume_noirq,
1453};
1454
David Brownell11a78b72006-12-06 17:14:11 -08001455/* use platform_driver for this, now that there's no longer any
1456 * point to sys_device (other than not disturbing old code).
1457 */
1458static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001459 .driver = {
1460 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001461 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001462 },
1463};
1464
1465static struct platform_device omap_mpuio_device = {
1466 .name = "mpuio",
1467 .id = -1,
1468 .dev = {
1469 .driver = &omap_mpuio_driver.driver,
1470 }
1471 /* could list the /proc/iomem resources */
1472};
1473
1474static inline void mpuio_init(void)
1475{
David Brownellfcf126d2007-04-02 12:46:47 -07001476 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1477
David Brownell11a78b72006-12-06 17:14:11 -08001478 if (platform_driver_register(&omap_mpuio_driver) == 0)
1479 (void) platform_device_register(&omap_mpuio_device);
1480}
1481
1482#else
1483static inline void mpuio_init(void) {}
1484#endif /* 16xx */
1485
David Brownelle5c56ed2006-12-06 17:13:59 -08001486#else
1487
1488extern struct irq_chip mpuio_irq_chip;
1489
1490#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001491static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001492
1493#endif
1494
1495/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001496
David Brownell52e31342008-03-03 12:43:23 -08001497/* REVISIT these are stupid implementations! replace by ones that
1498 * don't switch on METHOD_* and which mostly avoid spinlocks
1499 */
1500
1501static int gpio_input(struct gpio_chip *chip, unsigned offset)
1502{
1503 struct gpio_bank *bank;
1504 unsigned long flags;
1505
1506 bank = container_of(chip, struct gpio_bank, chip);
1507 spin_lock_irqsave(&bank->lock, flags);
1508 _set_gpio_direction(bank, offset, 1);
1509 spin_unlock_irqrestore(&bank->lock, flags);
1510 return 0;
1511}
1512
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001513static int gpio_is_input(struct gpio_bank *bank, int mask)
1514{
1515 void __iomem *reg = bank->base;
1516
1517 switch (bank->method) {
1518 case METHOD_MPUIO:
1519 reg += OMAP_MPUIO_IO_CNTL;
1520 break;
1521 case METHOD_GPIO_1510:
1522 reg += OMAP1510_GPIO_DIR_CONTROL;
1523 break;
1524 case METHOD_GPIO_1610:
1525 reg += OMAP1610_GPIO_DIRECTION;
1526 break;
1527 case METHOD_GPIO_730:
1528 reg += OMAP730_GPIO_DIR_CONTROL;
1529 break;
1530 case METHOD_GPIO_850:
1531 reg += OMAP850_GPIO_DIR_CONTROL;
1532 break;
1533 case METHOD_GPIO_24XX:
1534 reg += OMAP24XX_GPIO_OE;
1535 break;
1536 }
1537 return __raw_readl(reg) & mask;
1538}
1539
David Brownell52e31342008-03-03 12:43:23 -08001540static int gpio_get(struct gpio_chip *chip, unsigned offset)
1541{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001542 struct gpio_bank *bank;
1543 void __iomem *reg;
1544 int gpio;
1545 u32 mask;
1546
1547 gpio = chip->base + offset;
1548 bank = get_gpio_bank(gpio);
1549 reg = bank->base;
1550 mask = 1 << get_gpio_index(gpio);
1551
1552 if (gpio_is_input(bank, mask))
1553 return _get_gpio_datain(bank, gpio);
1554 else
1555 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001556}
1557
1558static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1559{
1560 struct gpio_bank *bank;
1561 unsigned long flags;
1562
1563 bank = container_of(chip, struct gpio_bank, chip);
1564 spin_lock_irqsave(&bank->lock, flags);
1565 _set_gpio_dataout(bank, offset, value);
1566 _set_gpio_direction(bank, offset, 0);
1567 spin_unlock_irqrestore(&bank->lock, flags);
1568 return 0;
1569}
1570
1571static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1572{
1573 struct gpio_bank *bank;
1574 unsigned long flags;
1575
1576 bank = container_of(chip, struct gpio_bank, chip);
1577 spin_lock_irqsave(&bank->lock, flags);
1578 _set_gpio_dataout(bank, offset, value);
1579 spin_unlock_irqrestore(&bank->lock, flags);
1580}
1581
David Brownella007b702008-12-10 17:35:25 -08001582static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1583{
1584 struct gpio_bank *bank;
1585
1586 bank = container_of(chip, struct gpio_bank, chip);
1587 return bank->virtual_irq_start + offset;
1588}
1589
David Brownell52e31342008-03-03 12:43:23 -08001590/*---------------------------------------------------------------------*/
1591
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001592static int initialized;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001593#if !(defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001594static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001595#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001596
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001597#if defined(CONFIG_ARCH_OMAP2)
1598static struct clk * gpio_fck;
1599#endif
1600
1601#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001602static struct clk * gpio5_ick;
1603static struct clk * gpio5_fck;
1604#endif
1605
Santosh Shilimkar44169072009-05-28 14:16:04 -07001606#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001607static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1608#endif
1609
David Brownell8ba55c52008-02-26 11:10:50 -08001610/* This lock class tells lockdep that GPIO irqs are in a different
1611 * category than their parents, so it won't report false recursion.
1612 */
1613static struct lock_class_key gpio_lock_class;
1614
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001615static int __init _omap_gpio_init(void)
1616{
1617 int i;
David Brownell52e31342008-03-03 12:43:23 -08001618 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001619 struct gpio_bank *bank;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001620 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001621
1622 initialized = 1;
1623
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001624#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001625 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001626 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1627 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001628 printk("Could not get arm_gpio_ck\n");
1629 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001630 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001631 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001632#endif
1633#if defined(CONFIG_ARCH_OMAP2)
1634 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001635 gpio_ick = clk_get(NULL, "gpios_ick");
1636 if (IS_ERR(gpio_ick))
1637 printk("Could not get gpios_ick\n");
1638 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001639 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001640 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001641 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001642 printk("Could not get gpios_fck\n");
1643 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001644 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001645
1646 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001647 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001648 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001649#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001650 if (cpu_is_omap2430()) {
1651 gpio5_ick = clk_get(NULL, "gpio5_ick");
1652 if (IS_ERR(gpio5_ick))
1653 printk("Could not get gpio5_ick\n");
1654 else
1655 clk_enable(gpio5_ick);
1656 gpio5_fck = clk_get(NULL, "gpio5_fck");
1657 if (IS_ERR(gpio5_fck))
1658 printk("Could not get gpio5_fck\n");
1659 else
1660 clk_enable(gpio5_fck);
1661 }
1662#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001663 }
1664#endif
1665
Santosh Shilimkar44169072009-05-28 14:16:04 -07001666#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1667 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001668 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1669 sprintf(clk_name, "gpio%d_ick", i + 1);
1670 gpio_iclks[i] = clk_get(NULL, clk_name);
1671 if (IS_ERR(gpio_iclks[i]))
1672 printk(KERN_ERR "Could not get %s\n", clk_name);
1673 else
1674 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001675 }
1676 }
1677#endif
1678
Tony Lindgren92105bb2005-09-07 17:20:26 +01001679
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001680#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001681 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001682 printk(KERN_INFO "OMAP1510 GPIO hardware\n");
1683 gpio_bank_count = 2;
1684 gpio_bank = gpio_bank_1510;
1685 }
1686#endif
1687#if defined(CONFIG_ARCH_OMAP16XX)
1688 if (cpu_is_omap16xx()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001689 u32 rev;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001690
1691 gpio_bank_count = 5;
1692 gpio_bank = gpio_bank_1610;
Russell King7c7095a2008-09-05 15:49:14 +01001693 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001694 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1695 (rev >> 4) & 0x0f, rev & 0x0f);
1696 }
1697#endif
1698#ifdef CONFIG_ARCH_OMAP730
1699 if (cpu_is_omap730()) {
1700 printk(KERN_INFO "OMAP730 GPIO hardware\n");
1701 gpio_bank_count = 7;
1702 gpio_bank = gpio_bank_730;
1703 }
1704#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001705#ifdef CONFIG_ARCH_OMAP850
1706 if (cpu_is_omap850()) {
1707 printk(KERN_INFO "OMAP850 GPIO hardware\n");
1708 gpio_bank_count = 7;
1709 gpio_bank = gpio_bank_850;
1710 }
1711#endif
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001712
Tony Lindgren92105bb2005-09-07 17:20:26 +01001713#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001714 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001715 int rev;
1716
1717 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001718 gpio_bank = gpio_bank_242x;
Russell King7c7095a2008-09-05 15:49:14 +01001719 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001720 printk(KERN_INFO "OMAP242x GPIO hardware version %d.%d\n",
1721 (rev >> 4) & 0x0f, rev & 0x0f);
1722 }
1723 if (cpu_is_omap243x()) {
1724 int rev;
1725
1726 gpio_bank_count = 5;
1727 gpio_bank = gpio_bank_243x;
Russell King7c7095a2008-09-05 15:49:14 +01001728 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001729 printk(KERN_INFO "OMAP243x GPIO hardware version %d.%d\n",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001730 (rev >> 4) & 0x0f, rev & 0x0f);
1731 }
1732#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001733#ifdef CONFIG_ARCH_OMAP34XX
1734 if (cpu_is_omap34xx()) {
1735 int rev;
1736
1737 gpio_bank_count = OMAP34XX_NR_GPIOS;
1738 gpio_bank = gpio_bank_34xx;
Russell King7c7095a2008-09-05 15:49:14 +01001739 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001740 printk(KERN_INFO "OMAP34xx GPIO hardware version %d.%d\n",
1741 (rev >> 4) & 0x0f, rev & 0x0f);
1742 }
1743#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001744#ifdef CONFIG_ARCH_OMAP4
1745 if (cpu_is_omap44xx()) {
1746 int rev;
1747
1748 gpio_bank_count = OMAP34XX_NR_GPIOS;
1749 gpio_bank = gpio_bank_44xx;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301750 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
Santosh Shilimkar44169072009-05-28 14:16:04 -07001751 printk(KERN_INFO "OMAP44xx GPIO hardware version %d.%d\n",
1752 (rev >> 4) & 0x0f, rev & 0x0f);
1753 }
1754#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001755 for (i = 0; i < gpio_bank_count; i++) {
1756 int j, gpio_count = 16;
1757
1758 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001759 spin_lock_init(&bank->lock);
David Brownelle5c56ed2006-12-06 17:13:59 -08001760 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001761 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001762 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001763 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1764 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1765 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001766 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001767 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1768 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001769 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001770 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001771 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_730) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001772 __raw_writel(0xffffffff, bank->base + OMAP730_GPIO_INT_MASK);
1773 __raw_writel(0x00000000, bank->base + OMAP730_GPIO_INT_STATUS);
1774
1775 gpio_count = 32; /* 730 has 32-bit GPIOs */
1776 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001777
Santosh Shilimkar44169072009-05-28 14:16:04 -07001778#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1779 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001780 if (bank->method == METHOD_GPIO_24XX) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001781 static const u32 non_wakeup_gpios[] = {
1782 0xe203ffc0, 0x08700040
1783 };
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301784 if (cpu_is_omap44xx()) {
1785 __raw_writel(0xffffffff, bank->base +
1786 OMAP4_GPIO_IRQSTATUSCLR0);
1787 __raw_writew(0x0015, bank->base +
1788 OMAP4_GPIO_SYSCONFIG);
1789 __raw_writel(0x00000000, bank->base +
1790 OMAP4_GPIO_DEBOUNCENABLE);
1791 /* Initialize interface clock ungated, module enabled */
1792 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1793 } else {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001794 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1795 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001796 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
janboecb5793d2009-06-23 13:30:25 +03001797 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_DEBOUNCE_EN);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001798
1799 /* Initialize interface clock ungated, module enabled */
1800 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301801 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001802 if (i < ARRAY_SIZE(non_wakeup_gpios))
1803 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001804 gpio_count = 32;
1805 }
1806#endif
David Brownell52e31342008-03-03 12:43:23 -08001807 /* REVISIT eventually switch from OMAP-specific gpio structs
1808 * over to the generic ones
1809 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001810 bank->chip.request = omap_gpio_request;
1811 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001812 bank->chip.direction_input = gpio_input;
1813 bank->chip.get = gpio_get;
1814 bank->chip.direction_output = gpio_output;
1815 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001816 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001817 if (bank_is_mpuio(bank)) {
1818 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001819#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001820 bank->chip.dev = &omap_mpuio_device.dev;
1821#endif
David Brownell52e31342008-03-03 12:43:23 -08001822 bank->chip.base = OMAP_MPUIO(0);
1823 } else {
1824 bank->chip.label = "gpio";
1825 bank->chip.base = gpio;
1826 gpio += gpio_count;
1827 }
1828 bank->chip.ngpio = gpio_count;
1829
1830 gpiochip_add(&bank->chip);
1831
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001832 for (j = bank->virtual_irq_start;
1833 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001834 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001835 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001836 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001837 set_irq_chip(j, &mpuio_irq_chip);
1838 else
1839 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001840 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001841 set_irq_flags(j, IRQF_VALID);
1842 }
1843 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1844 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001845
Santosh Shilimkar44169072009-05-28 14:16:04 -07001846 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001847 sprintf(clk_name, "gpio%d_dbck", i + 1);
1848 bank->dbck = clk_get(NULL, clk_name);
1849 if (IS_ERR(bank->dbck))
1850 printk(KERN_ERR "Could not get %s\n", clk_name);
1851 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001852 }
1853
1854 /* Enable system clock for GPIO module.
1855 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001856 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001857 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1858
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001859 /* Enable autoidle for the OCP interface */
1860 if (cpu_is_omap24xx())
1861 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001862 if (cpu_is_omap34xx())
1863 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001864
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001865 return 0;
1866}
1867
Santosh Shilimkar44169072009-05-28 14:16:04 -07001868#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1869 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001870static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1871{
1872 int i;
1873
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001874 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001875 return 0;
1876
1877 for (i = 0; i < gpio_bank_count; i++) {
1878 struct gpio_bank *bank = &gpio_bank[i];
1879 void __iomem *wake_status;
1880 void __iomem *wake_clear;
1881 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001882 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001883
1884 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001885#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001886 case METHOD_GPIO_1610:
1887 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1888 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1889 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1890 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001891#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301892#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001893 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001894 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001895 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1896 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1897 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001898#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301899#ifdef CONFIG_ARCH_OMAP4
1900 case METHOD_GPIO_24XX:
1901 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1902 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1903 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1904 break;
1905#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001906 default:
1907 continue;
1908 }
1909
David Brownella6472532008-03-03 04:33:30 -08001910 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001911 bank->saved_wakeup = __raw_readl(wake_status);
1912 __raw_writel(0xffffffff, wake_clear);
1913 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001914 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001915 }
1916
1917 return 0;
1918}
1919
1920static int omap_gpio_resume(struct sys_device *dev)
1921{
1922 int i;
1923
Tero Kristo723fdb72008-11-26 14:35:16 -08001924 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001925 return 0;
1926
1927 for (i = 0; i < gpio_bank_count; i++) {
1928 struct gpio_bank *bank = &gpio_bank[i];
1929 void __iomem *wake_clear;
1930 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001931 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001932
1933 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001934#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001935 case METHOD_GPIO_1610:
1936 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1937 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1938 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001939#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301940#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001941 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001942 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1943 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001944 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001945#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301946#ifdef CONFIG_ARCH_OMAP4
1947 case METHOD_GPIO_24XX:
1948 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1949 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1950 break;
1951#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001952 default:
1953 continue;
1954 }
1955
David Brownella6472532008-03-03 04:33:30 -08001956 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001957 __raw_writel(0xffffffff, wake_clear);
1958 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001959 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001960 }
1961
1962 return 0;
1963}
1964
1965static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01001966 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001967 .suspend = omap_gpio_suspend,
1968 .resume = omap_gpio_resume,
1969};
1970
1971static struct sys_device omap_gpio_device = {
1972 .id = 0,
1973 .cls = &omap_gpio_sysclass,
1974};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001975
1976#endif
1977
Santosh Shilimkar44169072009-05-28 14:16:04 -07001978#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1979 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001980
1981static int workaround_enabled;
1982
1983void omap2_gpio_prepare_for_retention(void)
1984{
1985 int i, c = 0;
1986
1987 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
1988 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
1989 for (i = 0; i < gpio_bank_count; i++) {
1990 struct gpio_bank *bank = &gpio_bank[i];
1991 u32 l1, l2;
1992
1993 if (!(bank->enabled_non_wakeup_gpios))
1994 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301995#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001996 bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1997 l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1998 l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001999#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302000#ifdef CONFIG_ARCH_OMAP4
2001 bank->saved_datain = __raw_readl(bank->base +
2002 OMAP4_GPIO_DATAIN);
2003 l1 = __raw_readl(bank->base + OMAP4_GPIO_FALLINGDETECT);
2004 l2 = __raw_readl(bank->base + OMAP4_GPIO_RISINGDETECT);
2005#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002006 bank->saved_fallingdetect = l1;
2007 bank->saved_risingdetect = l2;
2008 l1 &= ~bank->enabled_non_wakeup_gpios;
2009 l2 &= ~bank->enabled_non_wakeup_gpios;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302010#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002011 __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2012 __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002013#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302014#ifdef CONFIG_ARCH_OMAP4
2015 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
2016 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
2017#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002018 c++;
2019 }
2020 if (!c) {
2021 workaround_enabled = 0;
2022 return;
2023 }
2024 workaround_enabled = 1;
2025}
2026
2027void omap2_gpio_resume_after_retention(void)
2028{
2029 int i;
2030
2031 if (!workaround_enabled)
2032 return;
2033 for (i = 0; i < gpio_bank_count; i++) {
2034 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002035 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002036
2037 if (!(bank->enabled_non_wakeup_gpios))
2038 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302039#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002040 __raw_writel(bank->saved_fallingdetect,
2041 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2042 __raw_writel(bank->saved_risingdetect,
2043 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302044 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2045#endif
2046#ifdef CONFIG_ARCH_OMAP4
2047 __raw_writel(bank->saved_fallingdetect,
2048 bank->base + OMAP4_GPIO_FALLINGDETECT);
2049 __raw_writel(bank->saved_risingdetect,
2050 bank->base + OMAP4_GPIO_RISINGDETECT);
2051 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002052#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002053 /* Check if any of the non-wakeup interrupt GPIOs have changed
2054 * state. If so, generate an IRQ by software. This is
2055 * horribly racy, but it's the best we can do to work around
2056 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002057 l ^= bank->saved_datain;
2058 l &= bank->non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002059
2060 /*
2061 * No need to generate IRQs for the rising edge for gpio IRQs
2062 * configured with falling edge only; and vice versa.
2063 */
2064 gen0 = l & bank->saved_fallingdetect;
2065 gen0 &= bank->saved_datain;
2066
2067 gen1 = l & bank->saved_risingdetect;
2068 gen1 &= ~(bank->saved_datain);
2069
2070 /* FIXME: Consider GPIO IRQs with level detections properly! */
2071 gen = l & (~(bank->saved_fallingdetect) &
2072 ~(bank->saved_risingdetect));
2073 /* Consider all GPIO IRQs needed to be updated */
2074 gen |= gen0 | gen1;
2075
2076 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002077 u32 old0, old1;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302078#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002079 old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2080 old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002081 __raw_writel(old0 | gen, bank->base +
2082 OMAP24XX_GPIO_LEVELDETECT0);
2083 __raw_writel(old1 | gen, bank->base +
2084 OMAP24XX_GPIO_LEVELDETECT1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002085 __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2086 __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002087#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302088#ifdef CONFIG_ARCH_OMAP4
2089 old0 = __raw_readl(bank->base +
2090 OMAP4_GPIO_LEVELDETECT0);
2091 old1 = __raw_readl(bank->base +
2092 OMAP4_GPIO_LEVELDETECT1);
2093 __raw_writel(old0 | l, bank->base +
2094 OMAP4_GPIO_LEVELDETECT0);
2095 __raw_writel(old1 | l, bank->base +
2096 OMAP4_GPIO_LEVELDETECT1);
2097 __raw_writel(old0, bank->base +
2098 OMAP4_GPIO_LEVELDETECT0);
2099 __raw_writel(old1, bank->base +
2100 OMAP4_GPIO_LEVELDETECT1);
2101#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002102 }
2103 }
2104
2105}
2106
Tony Lindgren92105bb2005-09-07 17:20:26 +01002107#endif
2108
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002109/*
2110 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002111 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002112 */
David Brownell277d58e2006-12-06 17:13:59 -08002113int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002114{
2115 if (!initialized)
2116 return _omap_gpio_init();
2117 else
2118 return 0;
2119}
2120
Tony Lindgren92105bb2005-09-07 17:20:26 +01002121static int __init omap_gpio_sysinit(void)
2122{
2123 int ret = 0;
2124
2125 if (!initialized)
2126 ret = _omap_gpio_init();
2127
David Brownell11a78b72006-12-06 17:14:11 -08002128 mpuio_init();
2129
Santosh Shilimkar44169072009-05-28 14:16:04 -07002130#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
2131 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002132 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002133 if (ret == 0) {
2134 ret = sysdev_class_register(&omap_gpio_sysclass);
2135 if (ret == 0)
2136 ret = sysdev_register(&omap_gpio_device);
2137 }
2138 }
2139#endif
2140
2141 return ret;
2142}
2143
Tony Lindgren92105bb2005-09-07 17:20:26 +01002144arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002145
2146
2147#ifdef CONFIG_DEBUG_FS
2148
2149#include <linux/debugfs.h>
2150#include <linux/seq_file.h>
2151
David Brownellb9772a22006-12-06 17:13:53 -08002152static int dbg_gpio_show(struct seq_file *s, void *unused)
2153{
2154 unsigned i, j, gpio;
2155
2156 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2157 struct gpio_bank *bank = gpio_bank + i;
2158 unsigned bankwidth = 16;
2159 u32 mask = 1;
2160
David Brownelle5c56ed2006-12-06 17:13:59 -08002161 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002162 gpio = OMAP_MPUIO(0);
Zebediah C. McClure56739a62009-03-23 18:07:40 -07002163 else if (cpu_class_is_omap2() || cpu_is_omap730() ||
2164 cpu_is_omap850())
David Brownellb9772a22006-12-06 17:13:53 -08002165 bankwidth = 32;
2166
2167 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2168 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002169 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002170
David Brownell52e31342008-03-03 12:43:23 -08002171 label = gpiochip_is_requested(&bank->chip, j);
2172 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002173 continue;
2174
2175 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002176 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002177 is_in = gpio_is_input(bank, mask);
2178
David Brownelle5c56ed2006-12-06 17:13:59 -08002179 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002180 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002181 else
David Brownell52e31342008-03-03 12:43:23 -08002182 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002183 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002184 label,
David Brownellb9772a22006-12-06 17:13:53 -08002185 is_in ? "in " : "out",
2186 value ? "hi" : "lo");
2187
David Brownell52e31342008-03-03 12:43:23 -08002188/* FIXME for at least omap2, show pullup/pulldown state */
2189
David Brownellb9772a22006-12-06 17:13:53 -08002190 irqstat = irq_desc[irq].status;
Tony Lindgren3a26e332009-01-15 13:09:53 +02002191#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07002192 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
David Brownellb9772a22006-12-06 17:13:53 -08002193 if (is_in && ((bank->suspend_wakeup & mask)
2194 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2195 char *trigger = NULL;
2196
2197 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2198 case IRQ_TYPE_EDGE_FALLING:
2199 trigger = "falling";
2200 break;
2201 case IRQ_TYPE_EDGE_RISING:
2202 trigger = "rising";
2203 break;
2204 case IRQ_TYPE_EDGE_BOTH:
2205 trigger = "bothedge";
2206 break;
2207 case IRQ_TYPE_LEVEL_LOW:
2208 trigger = "low";
2209 break;
2210 case IRQ_TYPE_LEVEL_HIGH:
2211 trigger = "high";
2212 break;
2213 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002214 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002215 break;
2216 }
David Brownell52e31342008-03-03 12:43:23 -08002217 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002218 irq, trigger,
2219 (bank->suspend_wakeup & mask)
2220 ? " wakeup" : "");
2221 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002222#endif
David Brownellb9772a22006-12-06 17:13:53 -08002223 seq_printf(s, "\n");
2224 }
2225
David Brownelle5c56ed2006-12-06 17:13:59 -08002226 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002227 seq_printf(s, "\n");
2228 gpio = 0;
2229 }
2230 }
2231 return 0;
2232}
2233
2234static int dbg_gpio_open(struct inode *inode, struct file *file)
2235{
David Brownelle5c56ed2006-12-06 17:13:59 -08002236 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002237}
2238
2239static const struct file_operations debug_fops = {
2240 .open = dbg_gpio_open,
2241 .read = seq_read,
2242 .llseek = seq_lseek,
2243 .release = single_release,
2244};
2245
2246static int __init omap_gpio_debuginit(void)
2247{
David Brownelle5c56ed2006-12-06 17:13:59 -08002248 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2249 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002250 return 0;
2251}
2252late_initcall(omap_gpio_debuginit);
2253#endif