blob: 9608019fd6e477c92c6e6057cbca7ae6fa1684c9 [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 Lindgren9f7065d2009-10-19 15:25:20 -070034#define OMAP1510_GPIO_BASE 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 Lindgren9f7065d2009-10-19 15:25:20 -070048#define OMAP1610_GPIO1_BASE 0xfffbe400
49#define OMAP1610_GPIO2_BASE 0xfffbec00
50#define OMAP1610_GPIO3_BASE 0xfffbb400
51#define OMAP1610_GPIO4_BASE 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/*
Alistair Buxton7c006922009-09-22 10:02:58 +010071 * OMAP7XX specific GPIO registers
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010072 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070073#define OMAP7XX_GPIO1_BASE 0xfffbc000
74#define OMAP7XX_GPIO2_BASE 0xfffbc800
75#define OMAP7XX_GPIO3_BASE 0xfffbd000
76#define OMAP7XX_GPIO4_BASE 0xfffbd800
77#define OMAP7XX_GPIO5_BASE 0xfffbe000
78#define OMAP7XX_GPIO6_BASE 0xfffbe800
Alistair Buxton7c006922009-09-22 10:02:58 +010079#define OMAP7XX_GPIO_DATA_INPUT 0x00
80#define OMAP7XX_GPIO_DATA_OUTPUT 0x04
81#define OMAP7XX_GPIO_DIR_CONTROL 0x08
82#define OMAP7XX_GPIO_INT_CONTROL 0x0c
83#define OMAP7XX_GPIO_INT_MASK 0x10
84#define OMAP7XX_GPIO_INT_STATUS 0x14
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010085
Tony Lindgren9f7065d2009-10-19 15:25:20 -070086#define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
Tony Lindgren94113262009-08-28 10:50:33 -070087
Zebediah C. McClure56739a62009-03-23 18:07:40 -070088/*
Tony Lindgren92105bb2005-09-07 17:20:26 +010089 * omap24xx specific GPIO registers
90 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070091#define OMAP242X_GPIO1_BASE 0x48018000
92#define OMAP242X_GPIO2_BASE 0x4801a000
93#define OMAP242X_GPIO3_BASE 0x4801c000
94#define OMAP242X_GPIO4_BASE 0x4801e000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -080095
Tony Lindgren9f7065d2009-10-19 15:25:20 -070096#define OMAP243X_GPIO1_BASE 0x4900C000
97#define OMAP243X_GPIO2_BASE 0x4900E000
98#define OMAP243X_GPIO3_BASE 0x49010000
99#define OMAP243X_GPIO4_BASE 0x49012000
100#define OMAP243X_GPIO5_BASE 0x480B6000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800101
Tony Lindgren92105bb2005-09-07 17:20:26 +0100102#define OMAP24XX_GPIO_REVISION 0x0000
103#define OMAP24XX_GPIO_SYSCONFIG 0x0010
104#define OMAP24XX_GPIO_SYSSTATUS 0x0014
105#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300106#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
107#define OMAP24XX_GPIO_IRQENABLE2 0x002c
Tony Lindgren92105bb2005-09-07 17:20:26 +0100108#define OMAP24XX_GPIO_IRQENABLE1 0x001c
Tero Kristo723fdb72008-11-26 14:35:16 -0800109#define OMAP24XX_GPIO_WAKE_EN 0x0020
Tony Lindgren92105bb2005-09-07 17:20:26 +0100110#define OMAP24XX_GPIO_CTRL 0x0030
111#define OMAP24XX_GPIO_OE 0x0034
112#define OMAP24XX_GPIO_DATAIN 0x0038
113#define OMAP24XX_GPIO_DATAOUT 0x003c
114#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
115#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
116#define OMAP24XX_GPIO_RISINGDETECT 0x0048
117#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700118#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
119#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
Tony Lindgren92105bb2005-09-07 17:20:26 +0100120#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
121#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
122#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
123#define OMAP24XX_GPIO_SETWKUENA 0x0084
124#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
125#define OMAP24XX_GPIO_SETDATAOUT 0x0094
126
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530127#define OMAP4_GPIO_REVISION 0x0000
128#define OMAP4_GPIO_SYSCONFIG 0x0010
129#define OMAP4_GPIO_EOI 0x0020
130#define OMAP4_GPIO_IRQSTATUSRAW0 0x0024
131#define OMAP4_GPIO_IRQSTATUSRAW1 0x0028
132#define OMAP4_GPIO_IRQSTATUS0 0x002c
133#define OMAP4_GPIO_IRQSTATUS1 0x0030
134#define OMAP4_GPIO_IRQSTATUSSET0 0x0034
135#define OMAP4_GPIO_IRQSTATUSSET1 0x0038
136#define OMAP4_GPIO_IRQSTATUSCLR0 0x003c
137#define OMAP4_GPIO_IRQSTATUSCLR1 0x0040
138#define OMAP4_GPIO_IRQWAKEN0 0x0044
139#define OMAP4_GPIO_IRQWAKEN1 0x0048
140#define OMAP4_GPIO_SYSSTATUS 0x0104
141#define OMAP4_GPIO_CTRL 0x0130
142#define OMAP4_GPIO_OE 0x0134
143#define OMAP4_GPIO_DATAIN 0x0138
144#define OMAP4_GPIO_DATAOUT 0x013c
145#define OMAP4_GPIO_LEVELDETECT0 0x0140
146#define OMAP4_GPIO_LEVELDETECT1 0x0144
147#define OMAP4_GPIO_RISINGDETECT 0x0148
148#define OMAP4_GPIO_FALLINGDETECT 0x014c
149#define OMAP4_GPIO_DEBOUNCENABLE 0x0150
150#define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
151#define OMAP4_GPIO_CLEARDATAOUT 0x0190
152#define OMAP4_GPIO_SETDATAOUT 0x0194
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800153/*
154 * omap34xx specific GPIO registers
155 */
156
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700157#define OMAP34XX_GPIO1_BASE 0x48310000
158#define OMAP34XX_GPIO2_BASE 0x49050000
159#define OMAP34XX_GPIO3_BASE 0x49052000
160#define OMAP34XX_GPIO4_BASE 0x49054000
161#define OMAP34XX_GPIO5_BASE 0x49056000
162#define OMAP34XX_GPIO6_BASE 0x49058000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800163
Santosh Shilimkar44169072009-05-28 14:16:04 -0700164/*
165 * OMAP44XX specific GPIO registers
166 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700167#define OMAP44XX_GPIO1_BASE 0x4a310000
168#define OMAP44XX_GPIO2_BASE 0x48055000
169#define OMAP44XX_GPIO3_BASE 0x48057000
170#define OMAP44XX_GPIO4_BASE 0x48059000
171#define OMAP44XX_GPIO5_BASE 0x4805B000
172#define OMAP44XX_GPIO6_BASE 0x4805D000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800173
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100174struct gpio_bank {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700175 unsigned long pbase;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100176 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100177 u16 irq;
178 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100179 int method;
Tony Lindgren088ef952010-02-12 12:26:47 -0800180#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2) || \
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800181 defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100182 u32 suspend_wakeup;
183 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800184#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800185#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -0700186 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800187 u32 non_wakeup_gpios;
188 u32 enabled_non_wakeup_gpios;
189
190 u32 saved_datain;
191 u32 saved_fallingdetect;
192 u32 saved_risingdetect;
193#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800194 u32 level_mask;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800195 u32 toggle_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100196 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800197 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800198 struct clk *dbck;
Charulatha V058af1e2009-11-22 10:11:25 -0800199 u32 mod_usage;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100200};
201
202#define METHOD_MPUIO 0
203#define METHOD_GPIO_1510 1
204#define METHOD_GPIO_1610 2
Alistair Buxton7c006922009-09-22 10:02:58 +0100205#define METHOD_GPIO_7XX 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700206#define METHOD_GPIO_24XX 5
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100207
Tony Lindgren92105bb2005-09-07 17:20:26 +0100208#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100209static struct gpio_bank gpio_bank_1610[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700210 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
211 METHOD_MPUIO },
212 { OMAP1610_GPIO1_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
213 METHOD_GPIO_1610 },
214 { OMAP1610_GPIO2_BASE, NULL, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16,
215 METHOD_GPIO_1610 },
216 { OMAP1610_GPIO3_BASE, NULL, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32,
217 METHOD_GPIO_1610 },
218 { OMAP1610_GPIO4_BASE, NULL, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48,
219 METHOD_GPIO_1610 },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100220};
221#endif
222
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000223#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100224static struct gpio_bank gpio_bank_1510[2] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700225 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
226 METHOD_MPUIO },
227 { OMAP1510_GPIO_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
228 METHOD_GPIO_1510 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100229};
230#endif
231
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100232#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100233static struct gpio_bank gpio_bank_7xx[7] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700234 { OMAP1_MPUIO_VBASE, NULL, INT_7XX_MPUIO, IH_MPUIO_BASE,
235 METHOD_MPUIO },
236 { OMAP7XX_GPIO1_BASE, NULL, INT_7XX_GPIO_BANK1, IH_GPIO_BASE,
237 METHOD_GPIO_7XX },
238 { OMAP7XX_GPIO2_BASE, NULL, INT_7XX_GPIO_BANK2, IH_GPIO_BASE + 32,
239 METHOD_GPIO_7XX },
240 { OMAP7XX_GPIO3_BASE, NULL, INT_7XX_GPIO_BANK3, IH_GPIO_BASE + 64,
241 METHOD_GPIO_7XX },
242 { OMAP7XX_GPIO4_BASE, NULL, INT_7XX_GPIO_BANK4, IH_GPIO_BASE + 96,
243 METHOD_GPIO_7XX },
244 { OMAP7XX_GPIO5_BASE, NULL, INT_7XX_GPIO_BANK5, IH_GPIO_BASE + 128,
245 METHOD_GPIO_7XX },
246 { OMAP7XX_GPIO6_BASE, NULL, INT_7XX_GPIO_BANK6, IH_GPIO_BASE + 160,
247 METHOD_GPIO_7XX },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100248};
249#endif
250
Tony Lindgren088ef952010-02-12 12:26:47 -0800251#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800252
253static struct gpio_bank gpio_bank_242x[4] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700254 { OMAP242X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
255 METHOD_GPIO_24XX },
256 { OMAP242X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
257 METHOD_GPIO_24XX },
258 { OMAP242X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
259 METHOD_GPIO_24XX },
260 { OMAP242X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
261 METHOD_GPIO_24XX },
Tony Lindgren92105bb2005-09-07 17:20:26 +0100262};
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800263
264static struct gpio_bank gpio_bank_243x[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700265 { OMAP243X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
266 METHOD_GPIO_24XX },
267 { OMAP243X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
268 METHOD_GPIO_24XX },
269 { OMAP243X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
270 METHOD_GPIO_24XX },
271 { OMAP243X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
272 METHOD_GPIO_24XX },
273 { OMAP243X_GPIO5_BASE, NULL, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128,
274 METHOD_GPIO_24XX },
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800275};
276
Tony Lindgren92105bb2005-09-07 17:20:26 +0100277#endif
278
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800279#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800280static struct gpio_bank gpio_bank_34xx[6] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700281 { OMAP34XX_GPIO1_BASE, NULL, INT_34XX_GPIO_BANK1, IH_GPIO_BASE,
282 METHOD_GPIO_24XX },
283 { OMAP34XX_GPIO2_BASE, NULL, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32,
284 METHOD_GPIO_24XX },
285 { OMAP34XX_GPIO3_BASE, NULL, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64,
286 METHOD_GPIO_24XX },
287 { OMAP34XX_GPIO4_BASE, NULL, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96,
288 METHOD_GPIO_24XX },
289 { OMAP34XX_GPIO5_BASE, NULL, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128,
290 METHOD_GPIO_24XX },
291 { OMAP34XX_GPIO6_BASE, NULL, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160,
292 METHOD_GPIO_24XX },
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800293};
294
Rajendra Nayak40c670f2008-09-26 17:47:48 +0530295struct omap3_gpio_regs {
296 u32 sysconfig;
297 u32 irqenable1;
298 u32 irqenable2;
299 u32 wake_en;
300 u32 ctrl;
301 u32 oe;
302 u32 leveldetect0;
303 u32 leveldetect1;
304 u32 risingdetect;
305 u32 fallingdetect;
306 u32 dataout;
307 u32 setwkuena;
308 u32 setdataout;
309};
310
311static struct omap3_gpio_regs gpio_context[OMAP34XX_NR_GPIOS];
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800312#endif
313
Santosh Shilimkar44169072009-05-28 14:16:04 -0700314#ifdef CONFIG_ARCH_OMAP4
315static struct gpio_bank gpio_bank_44xx[6] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700316 { OMAP44XX_GPIO1_BASE, NULL, INT_44XX_GPIO_BANK1, IH_GPIO_BASE,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700317 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700318 { OMAP44XX_GPIO2_BASE, NULL, INT_44XX_GPIO_BANK2, IH_GPIO_BASE + 32,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700319 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700320 { OMAP44XX_GPIO3_BASE, NULL, INT_44XX_GPIO_BANK3, IH_GPIO_BASE + 64,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700321 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700322 { OMAP44XX_GPIO4_BASE, NULL, INT_44XX_GPIO_BANK4, IH_GPIO_BASE + 96,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700323 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700324 { OMAP44XX_GPIO5_BASE, NULL, INT_44XX_GPIO_BANK5, IH_GPIO_BASE + 128,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700325 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700326 { OMAP44XX_GPIO6_BASE, NULL, INT_44XX_GPIO_BANK6, IH_GPIO_BASE + 160,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700327 METHOD_GPIO_24XX },
328};
329
330#endif
331
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100332static struct gpio_bank *gpio_bank;
333static int gpio_bank_count;
334
335static inline struct gpio_bank *get_gpio_bank(int gpio)
336{
Tony Lindgren6e60e792006-04-02 17:46:23 +0100337 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100338 if (OMAP_GPIO_IS_MPUIO(gpio))
339 return &gpio_bank[0];
340 return &gpio_bank[1];
341 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100342 if (cpu_is_omap16xx()) {
343 if (OMAP_GPIO_IS_MPUIO(gpio))
344 return &gpio_bank[0];
345 return &gpio_bank[1 + (gpio >> 4)];
346 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700347 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100348 if (OMAP_GPIO_IS_MPUIO(gpio))
349 return &gpio_bank[0];
350 return &gpio_bank[1 + (gpio >> 5)];
351 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100352 if (cpu_is_omap24xx())
353 return &gpio_bank[gpio >> 5];
Santosh Shilimkar44169072009-05-28 14:16:04 -0700354 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800355 return &gpio_bank[gpio >> 5];
David Brownelle031ab22008-12-10 17:35:27 -0800356 BUG();
357 return NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100358}
359
360static inline int get_gpio_index(int gpio)
361{
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700362 if (cpu_is_omap7xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100363 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100364 if (cpu_is_omap24xx())
365 return gpio & 0x1f;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700366 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800367 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100368 return gpio & 0x0f;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100369}
370
371static inline int gpio_valid(int gpio)
372{
373 if (gpio < 0)
374 return -1;
Tony Lindgrend11ac972008-01-12 15:35:04 -0800375 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
Jonathan McDowell193e68b2006-09-25 12:41:30 +0300376 if (gpio >= OMAP_MAX_GPIO_LINES + 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100377 return -1;
378 return 0;
379 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100380 if (cpu_is_omap15xx() && gpio < 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100381 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100382 if ((cpu_is_omap16xx()) && gpio < 64)
383 return 0;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700384 if (cpu_is_omap7xx() && gpio < 192)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100385 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100386 if (cpu_is_omap24xx() && gpio < 128)
387 return 0;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700388 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800389 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100390 return -1;
391}
392
393static int check_gpio(int gpio)
394{
Roel Kluind32b20f2009-11-17 14:39:03 -0800395 if (unlikely(gpio_valid(gpio) < 0)) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100396 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
397 dump_stack();
398 return -1;
399 }
400 return 0;
401}
402
403static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
404{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100405 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100406 u32 l;
407
408 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800409#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100410 case METHOD_MPUIO:
411 reg += OMAP_MPUIO_IO_CNTL;
412 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800413#endif
414#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100415 case METHOD_GPIO_1510:
416 reg += OMAP1510_GPIO_DIR_CONTROL;
417 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800418#endif
419#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100420 case METHOD_GPIO_1610:
421 reg += OMAP1610_GPIO_DIRECTION;
422 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800423#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100424#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100425 case METHOD_GPIO_7XX:
426 reg += OMAP7XX_GPIO_DIR_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700427 break;
428#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800429#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100430 case METHOD_GPIO_24XX:
431 reg += OMAP24XX_GPIO_OE;
432 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800433#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530434#if defined(CONFIG_ARCH_OMAP4)
435 case METHOD_GPIO_24XX:
436 reg += OMAP4_GPIO_OE;
437 break;
438#endif
David Brownelle5c56ed2006-12-06 17:13:59 -0800439 default:
440 WARN_ON(1);
441 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100442 }
443 l = __raw_readl(reg);
444 if (is_input)
445 l |= 1 << gpio;
446 else
447 l &= ~(1 << gpio);
448 __raw_writel(l, reg);
449}
450
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100451static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
452{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100453 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100454 u32 l = 0;
455
456 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800457#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100458 case METHOD_MPUIO:
459 reg += OMAP_MPUIO_OUTPUT;
460 l = __raw_readl(reg);
461 if (enable)
462 l |= 1 << gpio;
463 else
464 l &= ~(1 << gpio);
465 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800466#endif
467#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100468 case METHOD_GPIO_1510:
469 reg += OMAP1510_GPIO_DATA_OUTPUT;
470 l = __raw_readl(reg);
471 if (enable)
472 l |= 1 << gpio;
473 else
474 l &= ~(1 << gpio);
475 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800476#endif
477#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100478 case METHOD_GPIO_1610:
479 if (enable)
480 reg += OMAP1610_GPIO_SET_DATAOUT;
481 else
482 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
483 l = 1 << gpio;
484 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800485#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100486#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100487 case METHOD_GPIO_7XX:
488 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700489 l = __raw_readl(reg);
490 if (enable)
491 l |= 1 << gpio;
492 else
493 l &= ~(1 << gpio);
494 break;
495#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800496#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100497 case METHOD_GPIO_24XX:
498 if (enable)
499 reg += OMAP24XX_GPIO_SETDATAOUT;
500 else
501 reg += OMAP24XX_GPIO_CLEARDATAOUT;
502 l = 1 << gpio;
503 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800504#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530505#ifdef CONFIG_ARCH_OMAP4
506 case METHOD_GPIO_24XX:
507 if (enable)
508 reg += OMAP4_GPIO_SETDATAOUT;
509 else
510 reg += OMAP4_GPIO_CLEARDATAOUT;
511 l = 1 << gpio;
512 break;
513#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100514 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800515 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100516 return;
517 }
518 __raw_writel(l, reg);
519}
520
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300521static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100522{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100523 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100524
525 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800526 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100527 reg = bank->base;
528 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800529#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100530 case METHOD_MPUIO:
531 reg += OMAP_MPUIO_INPUT_LATCH;
532 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800533#endif
534#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100535 case METHOD_GPIO_1510:
536 reg += OMAP1510_GPIO_DATA_INPUT;
537 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800538#endif
539#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100540 case METHOD_GPIO_1610:
541 reg += OMAP1610_GPIO_DATAIN;
542 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800543#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100544#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100545 case METHOD_GPIO_7XX:
546 reg += OMAP7XX_GPIO_DATA_INPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700547 break;
548#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800549#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100550 case METHOD_GPIO_24XX:
551 reg += OMAP24XX_GPIO_DATAIN;
552 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800553#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530554#ifdef CONFIG_ARCH_OMAP4
555 case METHOD_GPIO_24XX:
556 reg += OMAP4_GPIO_DATAIN;
557 break;
558#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100559 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800560 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100561 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100562 return (__raw_readl(reg)
563 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100564}
565
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300566static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
567{
568 void __iomem *reg;
569
570 if (check_gpio(gpio) < 0)
571 return -EINVAL;
572 reg = bank->base;
573
574 switch (bank->method) {
575#ifdef CONFIG_ARCH_OMAP1
576 case METHOD_MPUIO:
577 reg += OMAP_MPUIO_OUTPUT;
578 break;
579#endif
580#ifdef CONFIG_ARCH_OMAP15XX
581 case METHOD_GPIO_1510:
582 reg += OMAP1510_GPIO_DATA_OUTPUT;
583 break;
584#endif
585#ifdef CONFIG_ARCH_OMAP16XX
586 case METHOD_GPIO_1610:
587 reg += OMAP1610_GPIO_DATAOUT;
588 break;
589#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100590#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100591 case METHOD_GPIO_7XX:
592 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300593 break;
594#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800595#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300596 defined(CONFIG_ARCH_OMAP4)
597 case METHOD_GPIO_24XX:
598 reg += OMAP24XX_GPIO_DATAOUT;
599 break;
600#endif
601 default:
602 return -EINVAL;
603 }
604
605 return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
606}
607
Tony Lindgren92105bb2005-09-07 17:20:26 +0100608#define MOD_REG_BIT(reg, bit_mask, set) \
609do { \
610 int l = __raw_readl(base + reg); \
611 if (set) l |= bit_mask; \
612 else l &= ~bit_mask; \
613 __raw_writel(l, base + reg); \
614} while(0)
615
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700616void omap_set_gpio_debounce(int gpio, int enable)
617{
618 struct gpio_bank *bank;
619 void __iomem *reg;
David Brownelle031ab22008-12-10 17:35:27 -0800620 unsigned long flags;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700621 u32 val, l = 1 << get_gpio_index(gpio);
622
623 if (cpu_class_is_omap1())
624 return;
625
626 bank = get_gpio_bank(gpio);
627 reg = bank->base;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530628#ifdef CONFIG_ARCH_OMAP4
629 reg += OMAP4_GPIO_DEBOUNCENABLE;
630#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700631 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530632#endif
Charulatha V058af1e2009-11-22 10:11:25 -0800633 if (!(bank->mod_usage & l)) {
634 printk(KERN_ERR "GPIO %d not requested\n", gpio);
635 return;
636 }
David Brownelle031ab22008-12-10 17:35:27 -0800637
638 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700639 val = __raw_readl(reg);
640
Jouni Hogander89db9482008-12-10 17:35:24 -0800641 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700642 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800643 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700644 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800645 else
David Brownelle031ab22008-12-10 17:35:27 -0800646 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800647
Santosh Shilimkar44169072009-05-28 14:16:04 -0700648 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800649 if (enable)
650 clk_enable(bank->dbck);
651 else
652 clk_disable(bank->dbck);
653 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700654
655 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800656done:
657 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700658}
659EXPORT_SYMBOL(omap_set_gpio_debounce);
660
661void omap_set_gpio_debounce_time(int gpio, int enc_time)
662{
663 struct gpio_bank *bank;
664 void __iomem *reg;
665
666 if (cpu_class_is_omap1())
667 return;
668
669 bank = get_gpio_bank(gpio);
670 reg = bank->base;
671
Charulatha V058af1e2009-11-22 10:11:25 -0800672 if (!bank->mod_usage) {
673 printk(KERN_ERR "GPIO not requested\n");
674 return;
675 }
676
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700677 enc_time &= 0xff;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530678#ifdef CONFIG_ARCH_OMAP4
679 reg += OMAP4_GPIO_DEBOUNCINGTIME;
680#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700681 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530682#endif
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700683 __raw_writel(enc_time, reg);
684}
685EXPORT_SYMBOL(omap_set_gpio_debounce_time);
686
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800687#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -0700688 defined(CONFIG_ARCH_OMAP4)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700689static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
690 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100691{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800692 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100693 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530694 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100695
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530696 if (cpu_is_omap44xx()) {
697 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
698 trigger & IRQ_TYPE_LEVEL_LOW);
699 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
700 trigger & IRQ_TYPE_LEVEL_HIGH);
701 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
702 trigger & IRQ_TYPE_EDGE_RISING);
703 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
704 trigger & IRQ_TYPE_EDGE_FALLING);
705 } else {
706 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
707 trigger & IRQ_TYPE_LEVEL_LOW);
708 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
709 trigger & IRQ_TYPE_LEVEL_HIGH);
710 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
711 trigger & IRQ_TYPE_EDGE_RISING);
712 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
713 trigger & IRQ_TYPE_EDGE_FALLING);
714 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800715 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530716 if (cpu_is_omap44xx()) {
717 if (trigger != 0)
718 __raw_writel(1 << gpio, bank->base+
719 OMAP4_GPIO_IRQWAKEN0);
720 else {
721 val = __raw_readl(bank->base +
722 OMAP4_GPIO_IRQWAKEN0);
723 __raw_writel(val & (~(1 << gpio)), bank->base +
724 OMAP4_GPIO_IRQWAKEN0);
725 }
726 } else {
727 if (trigger != 0)
728 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700729 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530730 else
731 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700732 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530733 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800734 } else {
735 if (trigger != 0)
736 bank->enabled_non_wakeup_gpios |= gpio_bit;
737 else
738 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
739 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700740
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530741 if (cpu_is_omap44xx()) {
742 bank->level_mask =
743 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
744 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
745 } else {
746 bank->level_mask =
747 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
748 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
749 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100750}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800751#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100752
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800753#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800754/*
755 * This only applies to chips that can't do both rising and falling edge
756 * detection at once. For all other chips, this function is a noop.
757 */
758static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
759{
760 void __iomem *reg = bank->base;
761 u32 l = 0;
762
763 switch (bank->method) {
Cory Maccarrone4318f362010-01-08 10:29:04 -0800764 case METHOD_MPUIO:
765 reg += OMAP_MPUIO_GPIO_INT_EDGE;
766 break;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800767#ifdef CONFIG_ARCH_OMAP15XX
768 case METHOD_GPIO_1510:
769 reg += OMAP1510_GPIO_INT_CONTROL;
770 break;
771#endif
772#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
773 case METHOD_GPIO_7XX:
774 reg += OMAP7XX_GPIO_INT_CONTROL;
775 break;
776#endif
777 default:
778 return;
779 }
780
781 l = __raw_readl(reg);
782 if ((l >> gpio) & 1)
783 l &= ~(1 << gpio);
784 else
785 l |= 1 << gpio;
786
787 __raw_writel(l, reg);
788}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800789#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800790
Tony Lindgren92105bb2005-09-07 17:20:26 +0100791static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
792{
793 void __iomem *reg = bank->base;
794 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100795
796 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800797#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100798 case METHOD_MPUIO:
799 reg += OMAP_MPUIO_GPIO_INT_EDGE;
800 l = __raw_readl(reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800801 if (trigger & IRQ_TYPE_EDGE_BOTH)
802 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100803 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100804 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100805 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100806 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100807 else
808 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100809 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800810#endif
811#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100812 case METHOD_GPIO_1510:
813 reg += OMAP1510_GPIO_INT_CONTROL;
814 l = __raw_readl(reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800815 if (trigger & IRQ_TYPE_EDGE_BOTH)
816 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100817 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100818 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100819 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100820 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100821 else
822 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100823 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800824#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800825#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100826 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100827 if (gpio & 0x08)
828 reg += OMAP1610_GPIO_EDGE_CTRL2;
829 else
830 reg += OMAP1610_GPIO_EDGE_CTRL1;
831 gpio &= 0x07;
832 l = __raw_readl(reg);
833 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100834 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100835 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100836 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100837 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800838 if (trigger)
839 /* Enable wake-up during idle for dynamic tick */
840 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
841 else
842 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100843 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800844#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100845#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100846 case METHOD_GPIO_7XX:
847 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700848 l = __raw_readl(reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800849 if (trigger & IRQ_TYPE_EDGE_BOTH)
850 bank->toggle_mask |= 1 << gpio;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700851 if (trigger & IRQ_TYPE_EDGE_RISING)
852 l |= 1 << gpio;
853 else if (trigger & IRQ_TYPE_EDGE_FALLING)
854 l &= ~(1 << gpio);
855 else
856 goto bad;
857 break;
858#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800859#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -0700860 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100861 case METHOD_GPIO_24XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800862 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100863 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800864#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100865 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100866 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100867 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100868 __raw_writel(l, reg);
869 return 0;
870bad:
871 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100872}
873
Tony Lindgren92105bb2005-09-07 17:20:26 +0100874static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100875{
876 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100877 unsigned gpio;
878 int retval;
David Brownella6472532008-03-03 04:33:30 -0800879 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100880
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800881 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100882 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
883 else
884 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100885
886 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100887 return -EINVAL;
888
David Brownelle5c56ed2006-12-06 17:13:59 -0800889 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100890 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800891
892 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800893 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800894 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100895 return -EINVAL;
896
David Brownell58781012006-12-06 17:14:10 -0800897 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800898 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100899 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800900 if (retval == 0) {
901 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
902 irq_desc[irq].status |= type;
903 }
David Brownella6472532008-03-03 04:33:30 -0800904 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800905
906 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
907 __set_irq_handler_unlocked(irq, handle_level_irq);
908 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
909 __set_irq_handler_unlocked(irq, handle_edge_irq);
910
Tony Lindgren92105bb2005-09-07 17:20:26 +0100911 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100912}
913
914static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
915{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100916 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100917
918 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800919#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100920 case METHOD_MPUIO:
921 /* MPUIO irqstatus is reset by reading the status register,
922 * so do nothing here */
923 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800924#endif
925#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100926 case METHOD_GPIO_1510:
927 reg += OMAP1510_GPIO_INT_STATUS;
928 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800929#endif
930#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100931 case METHOD_GPIO_1610:
932 reg += OMAP1610_GPIO_IRQSTATUS1;
933 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800934#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100935#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100936 case METHOD_GPIO_7XX:
937 reg += OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700938 break;
939#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800940#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100941 case METHOD_GPIO_24XX:
942 reg += OMAP24XX_GPIO_IRQSTATUS1;
943 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800944#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530945#if defined(CONFIG_ARCH_OMAP4)
946 case METHOD_GPIO_24XX:
947 reg += OMAP4_GPIO_IRQSTATUS0;
948 break;
949#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100950 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800951 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100952 return;
953 }
954 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300955
956 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800957#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Roger Quadrosbedfd152009-04-23 11:10:50 -0700958 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530959#endif
960#if defined(CONFIG_ARCH_OMAP4)
961 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
962#endif
963 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700964 __raw_writel(gpio_mask, reg);
965
966 /* Flush posted write for the irq status to avoid spurious interrupts */
967 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530968 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100969}
970
971static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
972{
973 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
974}
975
Imre Deakea6dedd2006-06-26 16:16:00 -0700976static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
977{
978 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700979 int inv = 0;
980 u32 l;
981 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700982
983 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800984#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700985 case METHOD_MPUIO:
986 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700987 mask = 0xffff;
988 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700989 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800990#endif
991#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700992 case METHOD_GPIO_1510:
993 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700994 mask = 0xffff;
995 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700996 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800997#endif
998#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700999 case METHOD_GPIO_1610:
1000 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001001 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001002 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001003#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001004#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001005 case METHOD_GPIO_7XX:
1006 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001007 mask = 0xffffffff;
1008 inv = 1;
1009 break;
1010#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001011#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Imre Deakea6dedd2006-06-26 16:16:00 -07001012 case METHOD_GPIO_24XX:
1013 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001014 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001015 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001016#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301017#if defined(CONFIG_ARCH_OMAP4)
1018 case METHOD_GPIO_24XX:
1019 reg += OMAP4_GPIO_IRQSTATUSSET0;
1020 mask = 0xffffffff;
1021 break;
1022#endif
Imre Deakea6dedd2006-06-26 16:16:00 -07001023 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001024 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -07001025 return 0;
1026 }
1027
Imre Deak99c47702006-06-26 16:16:07 -07001028 l = __raw_readl(reg);
1029 if (inv)
1030 l = ~l;
1031 l &= mask;
1032 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -07001033}
1034
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001035static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
1036{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001037 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001038 u32 l;
1039
1040 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001041#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001042 case METHOD_MPUIO:
1043 reg += OMAP_MPUIO_GPIO_MASKIT;
1044 l = __raw_readl(reg);
1045 if (enable)
1046 l &= ~(gpio_mask);
1047 else
1048 l |= gpio_mask;
1049 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001050#endif
1051#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001052 case METHOD_GPIO_1510:
1053 reg += OMAP1510_GPIO_INT_MASK;
1054 l = __raw_readl(reg);
1055 if (enable)
1056 l &= ~(gpio_mask);
1057 else
1058 l |= gpio_mask;
1059 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001060#endif
1061#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001062 case METHOD_GPIO_1610:
1063 if (enable)
1064 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1065 else
1066 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1067 l = gpio_mask;
1068 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001069#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001070#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001071 case METHOD_GPIO_7XX:
1072 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001073 l = __raw_readl(reg);
1074 if (enable)
1075 l &= ~(gpio_mask);
1076 else
1077 l |= gpio_mask;
1078 break;
1079#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001080#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001081 case METHOD_GPIO_24XX:
1082 if (enable)
1083 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1084 else
1085 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1086 l = gpio_mask;
1087 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001088#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301089#ifdef CONFIG_ARCH_OMAP4
1090 case METHOD_GPIO_24XX:
1091 if (enable)
1092 reg += OMAP4_GPIO_IRQSTATUSSET0;
1093 else
1094 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1095 l = gpio_mask;
1096 break;
1097#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001098 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001099 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001100 return;
1101 }
1102 __raw_writel(l, reg);
1103}
1104
1105static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1106{
1107 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1108}
1109
Tony Lindgren92105bb2005-09-07 17:20:26 +01001110/*
1111 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1112 * 1510 does not seem to have a wake-up register. If JTAG is connected
1113 * to the target, system will wake up always on GPIO events. While
1114 * system is running all registered GPIO interrupts need to have wake-up
1115 * enabled. When system is suspended, only selected GPIO interrupts need
1116 * to have wake-up enabled.
1117 */
1118static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1119{
Tony Lindgren4cc64202010-01-08 10:29:05 -08001120 unsigned long uninitialized_var(flags);
David Brownella6472532008-03-03 04:33:30 -08001121
Tony Lindgren92105bb2005-09-07 17:20:26 +01001122 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001123#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001124 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001125 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001126 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001127 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001128 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001129 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001130 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001131 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001132 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001133#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001134#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07001135 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001136 case METHOD_GPIO_24XX:
David Brownell11a78b72006-12-06 17:14:11 -08001137 if (bank->non_wakeup_gpios & (1 << gpio)) {
1138 printk(KERN_ERR "Unable to modify wakeup on "
1139 "non-wakeup GPIO%d\n",
1140 (bank - gpio_bank) * 32 + gpio);
1141 return -EINVAL;
1142 }
David Brownella6472532008-03-03 04:33:30 -08001143 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001144 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001145 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001146 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001147 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001148 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001149 return 0;
1150#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001151 default:
1152 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1153 bank->method);
1154 return -EINVAL;
1155 }
1156}
1157
Tony Lindgren4196dd62006-09-25 12:41:38 +03001158static void _reset_gpio(struct gpio_bank *bank, int gpio)
1159{
1160 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1161 _set_gpio_irqenable(bank, gpio, 0);
1162 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001163 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001164}
1165
Tony Lindgren92105bb2005-09-07 17:20:26 +01001166/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1167static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1168{
1169 unsigned int gpio = irq - IH_GPIO_BASE;
1170 struct gpio_bank *bank;
1171 int retval;
1172
1173 if (check_gpio(gpio) < 0)
1174 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001175 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001176 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001177
1178 return retval;
1179}
1180
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001181static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001182{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001183 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001184 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001185
David Brownella6472532008-03-03 04:33:30 -08001186 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001187
Tony Lindgren4196dd62006-09-25 12:41:38 +03001188 /* Set trigger to none. You need to enable the desired trigger with
1189 * request_irq() or set_irq_type().
1190 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001191 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001192
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001193#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001194 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001195 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001196
Tony Lindgren92105bb2005-09-07 17:20:26 +01001197 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001198 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001199 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001200 }
1201#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001202 if (!cpu_class_is_omap1()) {
1203 if (!bank->mod_usage) {
1204 u32 ctrl;
1205 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1206 ctrl &= 0xFFFFFFFE;
1207 /* Module is enabled, clocks are not gated */
1208 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1209 }
1210 bank->mod_usage |= 1 << offset;
1211 }
David Brownella6472532008-03-03 04:33:30 -08001212 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001213
1214 return 0;
1215}
1216
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001217static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001218{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001219 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001220 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001221
David Brownella6472532008-03-03 04:33:30 -08001222 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001223#ifdef CONFIG_ARCH_OMAP16XX
1224 if (bank->method == METHOD_GPIO_1610) {
1225 /* Disable wake-up during idle for dynamic tick */
1226 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001227 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001228 }
1229#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001230#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07001231 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001232 if (bank->method == METHOD_GPIO_24XX) {
1233 /* Disable wake-up during idle for dynamic tick */
1234 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001235 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001236 }
1237#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001238 if (!cpu_class_is_omap1()) {
1239 bank->mod_usage &= ~(1 << offset);
1240 if (!bank->mod_usage) {
1241 u32 ctrl;
1242 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1243 /* Module is disabled, clocks are gated */
1244 ctrl |= 1;
1245 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1246 }
1247 }
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001248 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001249 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001250}
1251
1252/*
1253 * We need to unmask the GPIO bank interrupt as soon as possible to
1254 * avoid missing GPIO interrupts for other lines in the bank.
1255 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1256 * in the bank to avoid missing nested interrupts for a GPIO line.
1257 * If we wait to unmask individual GPIO lines in the bank after the
1258 * line's interrupt handler has been run, we may miss some nested
1259 * interrupts.
1260 */
Russell King10dd5ce2006-11-23 11:41:32 +00001261static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001262{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001263 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001264 u32 isr;
Cory Maccarrone4318f362010-01-08 10:29:04 -08001265 unsigned int gpio_irq, gpio_index;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001266 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001267 u32 retrigger = 0;
1268 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001269
1270 desc->chip->ack(irq);
1271
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001272 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001273#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001274 if (bank->method == METHOD_MPUIO)
1275 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001276#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001277#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001278 if (bank->method == METHOD_GPIO_1510)
1279 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1280#endif
1281#if defined(CONFIG_ARCH_OMAP16XX)
1282 if (bank->method == METHOD_GPIO_1610)
1283 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1284#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001285#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001286 if (bank->method == METHOD_GPIO_7XX)
1287 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001288#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001289#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001290 if (bank->method == METHOD_GPIO_24XX)
1291 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1292#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301293#if defined(CONFIG_ARCH_OMAP4)
1294 if (bank->method == METHOD_GPIO_24XX)
1295 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1296#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001297 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001298 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001299 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001300
Imre Deakea6dedd2006-06-26 16:16:00 -07001301 enabled = _get_gpio_irqbank_mask(bank);
1302 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001303
1304 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1305 isr &= 0x0000ffff;
1306
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001307 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001308 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001309 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001310
1311 /* clear edge sensitive interrupts before handler(s) are
1312 called so that we don't miss any interrupt occurred while
1313 executing them */
1314 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1315 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1316 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1317
1318 /* if there is only edge sensitive GPIO pin interrupts
1319 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001320 if (!level_mask && !unmasked) {
1321 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001322 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001323 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001324
Imre Deakea6dedd2006-06-26 16:16:00 -07001325 isr |= retrigger;
1326 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001327 if (!isr)
1328 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001329
Tony Lindgren92105bb2005-09-07 17:20:26 +01001330 gpio_irq = bank->virtual_irq_start;
1331 for (; isr != 0; isr >>= 1, gpio_irq++) {
Cory Maccarrone4318f362010-01-08 10:29:04 -08001332 gpio_index = get_gpio_index(irq_to_gpio(gpio_irq));
1333
Tony Lindgren92105bb2005-09-07 17:20:26 +01001334 if (!(isr & 1))
1335 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001336
Cory Maccarrone4318f362010-01-08 10:29:04 -08001337#ifdef CONFIG_ARCH_OMAP1
1338 /*
1339 * Some chips can't respond to both rising and falling
1340 * at the same time. If this irq was requested with
1341 * both flags, we need to flip the ICR data for the IRQ
1342 * to respond to the IRQ for the opposite direction.
1343 * This will be indicated in the bank toggle_mask.
1344 */
1345 if (bank->toggle_mask & (1 << gpio_index))
1346 _toggle_gpio_edge_triggering(bank, gpio_index);
1347#endif
1348
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001349 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001350 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001351 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001352 /* if bank has any level sensitive GPIO pin interrupt
1353 configured, we must unmask the bank interrupt only after
1354 handler(s) are executed in order to avoid spurious bank
1355 interrupt */
1356 if (!unmasked)
1357 desc->chip->unmask(irq);
1358
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001359}
1360
Tony Lindgren4196dd62006-09-25 12:41:38 +03001361static void gpio_irq_shutdown(unsigned int irq)
1362{
1363 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001364 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001365
1366 _reset_gpio(bank, gpio);
1367}
1368
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001369static void gpio_ack_irq(unsigned int irq)
1370{
1371 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001372 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001373
1374 _clear_gpio_irqstatus(bank, gpio);
1375}
1376
1377static void gpio_mask_irq(unsigned int irq)
1378{
1379 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001380 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001381
1382 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001383 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001384}
1385
1386static void gpio_unmask_irq(unsigned int irq)
1387{
1388 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001389 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001390 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001391 struct irq_desc *desc = irq_to_desc(irq);
1392 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1393
1394 if (trigger)
1395 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001396
1397 /* For level-triggered GPIOs, the clearing must be done after
1398 * the HW source is cleared, thus after the handler has run */
1399 if (bank->level_mask & irq_mask) {
1400 _set_gpio_irqenable(bank, gpio, 0);
1401 _clear_gpio_irqstatus(bank, gpio);
1402 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001403
Kevin Hilman4de8c752008-01-16 21:56:14 -08001404 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001405}
1406
David Brownelle5c56ed2006-12-06 17:13:59 -08001407static struct irq_chip gpio_irq_chip = {
1408 .name = "GPIO",
1409 .shutdown = gpio_irq_shutdown,
1410 .ack = gpio_ack_irq,
1411 .mask = gpio_mask_irq,
1412 .unmask = gpio_unmask_irq,
1413 .set_type = gpio_irq_type,
1414 .set_wake = gpio_wake_enable,
1415};
1416
1417/*---------------------------------------------------------------------*/
1418
1419#ifdef CONFIG_ARCH_OMAP1
1420
1421/* MPUIO uses the always-on 32k clock */
1422
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001423static void mpuio_ack_irq(unsigned int irq)
1424{
1425 /* The ISR is reset automatically, so do nothing here. */
1426}
1427
1428static void mpuio_mask_irq(unsigned int irq)
1429{
1430 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001431 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001432
1433 _set_gpio_irqenable(bank, gpio, 0);
1434}
1435
1436static void mpuio_unmask_irq(unsigned int irq)
1437{
1438 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001439 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001440
1441 _set_gpio_irqenable(bank, gpio, 1);
1442}
1443
David Brownelle5c56ed2006-12-06 17:13:59 -08001444static struct irq_chip mpuio_irq_chip = {
1445 .name = "MPUIO",
1446 .ack = mpuio_ack_irq,
1447 .mask = mpuio_mask_irq,
1448 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001449 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001450#ifdef CONFIG_ARCH_OMAP16XX
1451 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1452 .set_wake = gpio_wake_enable,
1453#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001454};
1455
David Brownelle5c56ed2006-12-06 17:13:59 -08001456
1457#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1458
David Brownell11a78b72006-12-06 17:14:11 -08001459
1460#ifdef CONFIG_ARCH_OMAP16XX
1461
1462#include <linux/platform_device.h>
1463
Magnus Damm79ee0312009-07-08 13:22:04 +02001464static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001465{
Magnus Damm79ee0312009-07-08 13:22:04 +02001466 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001467 struct gpio_bank *bank = platform_get_drvdata(pdev);
1468 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001469 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001470
David Brownella6472532008-03-03 04:33:30 -08001471 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001472 bank->saved_wakeup = __raw_readl(mask_reg);
1473 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001474 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001475
1476 return 0;
1477}
1478
Magnus Damm79ee0312009-07-08 13:22:04 +02001479static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001480{
Magnus Damm79ee0312009-07-08 13:22:04 +02001481 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001482 struct gpio_bank *bank = platform_get_drvdata(pdev);
1483 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001484 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001485
David Brownella6472532008-03-03 04:33:30 -08001486 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001487 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001488 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001489
1490 return 0;
1491}
1492
Alexey Dobriyan47145212009-12-14 18:00:08 -08001493static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +02001494 .suspend_noirq = omap_mpuio_suspend_noirq,
1495 .resume_noirq = omap_mpuio_resume_noirq,
1496};
1497
David Brownell11a78b72006-12-06 17:14:11 -08001498/* use platform_driver for this, now that there's no longer any
1499 * point to sys_device (other than not disturbing old code).
1500 */
1501static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001502 .driver = {
1503 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001504 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001505 },
1506};
1507
1508static struct platform_device omap_mpuio_device = {
1509 .name = "mpuio",
1510 .id = -1,
1511 .dev = {
1512 .driver = &omap_mpuio_driver.driver,
1513 }
1514 /* could list the /proc/iomem resources */
1515};
1516
1517static inline void mpuio_init(void)
1518{
David Brownellfcf126d2007-04-02 12:46:47 -07001519 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1520
David Brownell11a78b72006-12-06 17:14:11 -08001521 if (platform_driver_register(&omap_mpuio_driver) == 0)
1522 (void) platform_device_register(&omap_mpuio_device);
1523}
1524
1525#else
1526static inline void mpuio_init(void) {}
1527#endif /* 16xx */
1528
David Brownelle5c56ed2006-12-06 17:13:59 -08001529#else
1530
1531extern struct irq_chip mpuio_irq_chip;
1532
1533#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001534static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001535
1536#endif
1537
1538/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001539
David Brownell52e31342008-03-03 12:43:23 -08001540/* REVISIT these are stupid implementations! replace by ones that
1541 * don't switch on METHOD_* and which mostly avoid spinlocks
1542 */
1543
1544static int gpio_input(struct gpio_chip *chip, unsigned offset)
1545{
1546 struct gpio_bank *bank;
1547 unsigned long flags;
1548
1549 bank = container_of(chip, struct gpio_bank, chip);
1550 spin_lock_irqsave(&bank->lock, flags);
1551 _set_gpio_direction(bank, offset, 1);
1552 spin_unlock_irqrestore(&bank->lock, flags);
1553 return 0;
1554}
1555
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001556static int gpio_is_input(struct gpio_bank *bank, int mask)
1557{
1558 void __iomem *reg = bank->base;
1559
1560 switch (bank->method) {
1561 case METHOD_MPUIO:
1562 reg += OMAP_MPUIO_IO_CNTL;
1563 break;
1564 case METHOD_GPIO_1510:
1565 reg += OMAP1510_GPIO_DIR_CONTROL;
1566 break;
1567 case METHOD_GPIO_1610:
1568 reg += OMAP1610_GPIO_DIRECTION;
1569 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001570 case METHOD_GPIO_7XX:
1571 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001572 break;
1573 case METHOD_GPIO_24XX:
1574 reg += OMAP24XX_GPIO_OE;
1575 break;
1576 }
1577 return __raw_readl(reg) & mask;
1578}
1579
David Brownell52e31342008-03-03 12:43:23 -08001580static int gpio_get(struct gpio_chip *chip, unsigned offset)
1581{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001582 struct gpio_bank *bank;
1583 void __iomem *reg;
1584 int gpio;
1585 u32 mask;
1586
1587 gpio = chip->base + offset;
1588 bank = get_gpio_bank(gpio);
1589 reg = bank->base;
1590 mask = 1 << get_gpio_index(gpio);
1591
1592 if (gpio_is_input(bank, mask))
1593 return _get_gpio_datain(bank, gpio);
1594 else
1595 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001596}
1597
1598static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1599{
1600 struct gpio_bank *bank;
1601 unsigned long flags;
1602
1603 bank = container_of(chip, struct gpio_bank, chip);
1604 spin_lock_irqsave(&bank->lock, flags);
1605 _set_gpio_dataout(bank, offset, value);
1606 _set_gpio_direction(bank, offset, 0);
1607 spin_unlock_irqrestore(&bank->lock, flags);
1608 return 0;
1609}
1610
1611static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1612{
1613 struct gpio_bank *bank;
1614 unsigned long flags;
1615
1616 bank = container_of(chip, struct gpio_bank, chip);
1617 spin_lock_irqsave(&bank->lock, flags);
1618 _set_gpio_dataout(bank, offset, value);
1619 spin_unlock_irqrestore(&bank->lock, flags);
1620}
1621
David Brownella007b702008-12-10 17:35:25 -08001622static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1623{
1624 struct gpio_bank *bank;
1625
1626 bank = container_of(chip, struct gpio_bank, chip);
1627 return bank->virtual_irq_start + offset;
1628}
1629
David Brownell52e31342008-03-03 12:43:23 -08001630/*---------------------------------------------------------------------*/
1631
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001632static int initialized;
Tony Lindgren56213ca2010-02-12 12:26:46 -08001633#if defined(CONFIG_ARCH_OMAP1) || defined(CONFIG_ARCH_OMAP2)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001634static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001635#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001636
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001637#if defined(CONFIG_ARCH_OMAP2)
1638static struct clk * gpio_fck;
1639#endif
1640
1641#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001642static struct clk * gpio5_ick;
1643static struct clk * gpio5_fck;
1644#endif
1645
Santosh Shilimkar44169072009-05-28 14:16:04 -07001646#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001647static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1648#endif
1649
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001650static void __init omap_gpio_show_rev(void)
1651{
1652 u32 rev;
1653
1654 if (cpu_is_omap16xx())
1655 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1656 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1657 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1658 else if (cpu_is_omap44xx())
1659 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1660 else
1661 return;
1662
1663 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1664 (rev >> 4) & 0x0f, rev & 0x0f);
1665}
1666
David Brownell8ba55c52008-02-26 11:10:50 -08001667/* This lock class tells lockdep that GPIO irqs are in a different
1668 * category than their parents, so it won't report false recursion.
1669 */
1670static struct lock_class_key gpio_lock_class;
1671
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001672static int __init _omap_gpio_init(void)
1673{
1674 int i;
David Brownell52e31342008-03-03 12:43:23 -08001675 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001676 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001677 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001678 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001679
1680 initialized = 1;
1681
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001682#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001683 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001684 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1685 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001686 printk("Could not get arm_gpio_ck\n");
1687 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001688 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001689 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001690#endif
1691#if defined(CONFIG_ARCH_OMAP2)
1692 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001693 gpio_ick = clk_get(NULL, "gpios_ick");
1694 if (IS_ERR(gpio_ick))
1695 printk("Could not get gpios_ick\n");
1696 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001697 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001698 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001699 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001700 printk("Could not get gpios_fck\n");
1701 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001702 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001703
1704 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001705 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001706 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001707#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001708 if (cpu_is_omap2430()) {
1709 gpio5_ick = clk_get(NULL, "gpio5_ick");
1710 if (IS_ERR(gpio5_ick))
1711 printk("Could not get gpio5_ick\n");
1712 else
1713 clk_enable(gpio5_ick);
1714 gpio5_fck = clk_get(NULL, "gpio5_fck");
1715 if (IS_ERR(gpio5_fck))
1716 printk("Could not get gpio5_fck\n");
1717 else
1718 clk_enable(gpio5_fck);
1719 }
1720#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001721 }
1722#endif
1723
Santosh Shilimkar44169072009-05-28 14:16:04 -07001724#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1725 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001726 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1727 sprintf(clk_name, "gpio%d_ick", i + 1);
1728 gpio_iclks[i] = clk_get(NULL, clk_name);
1729 if (IS_ERR(gpio_iclks[i]))
1730 printk(KERN_ERR "Could not get %s\n", clk_name);
1731 else
1732 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001733 }
1734 }
1735#endif
1736
Tony Lindgren92105bb2005-09-07 17:20:26 +01001737
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001738#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001739 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001740 gpio_bank_count = 2;
1741 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001742 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001743 }
1744#endif
1745#if defined(CONFIG_ARCH_OMAP16XX)
1746 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001747 gpio_bank_count = 5;
1748 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001749 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001750 }
1751#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001752#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1753 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001754 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001755 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001756 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001757 }
1758#endif
Tony Lindgren088ef952010-02-12 12:26:47 -08001759#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001760 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001761 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001762 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001763 }
1764 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001765 gpio_bank_count = 5;
1766 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001767 }
1768#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001769#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001770 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001771 gpio_bank_count = OMAP34XX_NR_GPIOS;
1772 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001773 }
1774#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001775#ifdef CONFIG_ARCH_OMAP4
1776 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001777 gpio_bank_count = OMAP34XX_NR_GPIOS;
1778 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001779 }
1780#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001781 for (i = 0; i < gpio_bank_count; i++) {
1782 int j, gpio_count = 16;
1783
1784 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001785 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001786
1787 /* Static mapping, never released */
1788 bank->base = ioremap(bank->pbase, bank_size);
1789 if (!bank->base) {
1790 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1791 continue;
1792 }
1793
David Brownelle5c56ed2006-12-06 17:13:59 -08001794 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001795 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001796 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001797 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1798 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1799 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001800 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001801 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1802 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001803 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001804 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001805 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1806 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1807 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001808
Alistair Buxton7c006922009-09-22 10:02:58 +01001809 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001810 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001811
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001812#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07001813 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001814 if (bank->method == METHOD_GPIO_24XX) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001815 static const u32 non_wakeup_gpios[] = {
1816 0xe203ffc0, 0x08700040
1817 };
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301818 if (cpu_is_omap44xx()) {
1819 __raw_writel(0xffffffff, bank->base +
1820 OMAP4_GPIO_IRQSTATUSCLR0);
1821 __raw_writew(0x0015, bank->base +
1822 OMAP4_GPIO_SYSCONFIG);
1823 __raw_writel(0x00000000, bank->base +
1824 OMAP4_GPIO_DEBOUNCENABLE);
1825 /* Initialize interface clock ungated, module enabled */
1826 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1827 } else {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001828 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1829 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001830 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
janboecb5793d2009-06-23 13:30:25 +03001831 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_DEBOUNCE_EN);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001832
1833 /* Initialize interface clock ungated, module enabled */
1834 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301835 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001836 if (i < ARRAY_SIZE(non_wakeup_gpios))
1837 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001838 gpio_count = 32;
1839 }
1840#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001841
1842 bank->mod_usage = 0;
David Brownell52e31342008-03-03 12:43:23 -08001843 /* REVISIT eventually switch from OMAP-specific gpio structs
1844 * over to the generic ones
1845 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001846 bank->chip.request = omap_gpio_request;
1847 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001848 bank->chip.direction_input = gpio_input;
1849 bank->chip.get = gpio_get;
1850 bank->chip.direction_output = gpio_output;
1851 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001852 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001853 if (bank_is_mpuio(bank)) {
1854 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001855#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001856 bank->chip.dev = &omap_mpuio_device.dev;
1857#endif
David Brownell52e31342008-03-03 12:43:23 -08001858 bank->chip.base = OMAP_MPUIO(0);
1859 } else {
1860 bank->chip.label = "gpio";
1861 bank->chip.base = gpio;
1862 gpio += gpio_count;
1863 }
1864 bank->chip.ngpio = gpio_count;
1865
1866 gpiochip_add(&bank->chip);
1867
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001868 for (j = bank->virtual_irq_start;
1869 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001870 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001871 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001872 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001873 set_irq_chip(j, &mpuio_irq_chip);
1874 else
1875 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001876 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001877 set_irq_flags(j, IRQF_VALID);
1878 }
1879 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1880 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001881
Santosh Shilimkar44169072009-05-28 14:16:04 -07001882 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001883 sprintf(clk_name, "gpio%d_dbck", i + 1);
1884 bank->dbck = clk_get(NULL, clk_name);
1885 if (IS_ERR(bank->dbck))
1886 printk(KERN_ERR "Could not get %s\n", clk_name);
1887 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001888 }
1889
1890 /* Enable system clock for GPIO module.
1891 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001892 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001893 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1894
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001895 /* Enable autoidle for the OCP interface */
1896 if (cpu_is_omap24xx())
1897 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001898 if (cpu_is_omap34xx())
1899 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001900
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001901 omap_gpio_show_rev();
1902
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001903 return 0;
1904}
1905
Tony Lindgren088ef952010-02-12 12:26:47 -08001906#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2) || \
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001907 defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001908static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1909{
1910 int i;
1911
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001912 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001913 return 0;
1914
1915 for (i = 0; i < gpio_bank_count; i++) {
1916 struct gpio_bank *bank = &gpio_bank[i];
1917 void __iomem *wake_status;
1918 void __iomem *wake_clear;
1919 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001920 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001921
1922 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001923#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001924 case METHOD_GPIO_1610:
1925 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1926 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1927 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1928 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001929#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001930#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001931 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001932 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001933 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1934 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1935 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001936#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301937#ifdef CONFIG_ARCH_OMAP4
1938 case METHOD_GPIO_24XX:
1939 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1940 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1941 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1942 break;
1943#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001944 default:
1945 continue;
1946 }
1947
David Brownella6472532008-03-03 04:33:30 -08001948 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001949 bank->saved_wakeup = __raw_readl(wake_status);
1950 __raw_writel(0xffffffff, wake_clear);
1951 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001952 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001953 }
1954
1955 return 0;
1956}
1957
1958static int omap_gpio_resume(struct sys_device *dev)
1959{
1960 int i;
1961
Tero Kristo723fdb72008-11-26 14:35:16 -08001962 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001963 return 0;
1964
1965 for (i = 0; i < gpio_bank_count; i++) {
1966 struct gpio_bank *bank = &gpio_bank[i];
1967 void __iomem *wake_clear;
1968 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001969 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001970
1971 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001972#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001973 case METHOD_GPIO_1610:
1974 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1975 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1976 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001977#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001978#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001979 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001980 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1981 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001982 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001983#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301984#ifdef CONFIG_ARCH_OMAP4
1985 case METHOD_GPIO_24XX:
1986 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1987 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1988 break;
1989#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001990 default:
1991 continue;
1992 }
1993
David Brownella6472532008-03-03 04:33:30 -08001994 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001995 __raw_writel(0xffffffff, wake_clear);
1996 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001997 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001998 }
1999
2000 return 0;
2001}
2002
2003static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01002004 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01002005 .suspend = omap_gpio_suspend,
2006 .resume = omap_gpio_resume,
2007};
2008
2009static struct sys_device omap_gpio_device = {
2010 .id = 0,
2011 .cls = &omap_gpio_sysclass,
2012};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002013
2014#endif
2015
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002016#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07002017 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002018
2019static int workaround_enabled;
2020
2021void omap2_gpio_prepare_for_retention(void)
2022{
2023 int i, c = 0;
2024
2025 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
2026 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
2027 for (i = 0; i < gpio_bank_count; i++) {
2028 struct gpio_bank *bank = &gpio_bank[i];
2029 u32 l1, l2;
2030
2031 if (!(bank->enabled_non_wakeup_gpios))
2032 continue;
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002033#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002034 bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2035 l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2036 l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002037#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302038#ifdef CONFIG_ARCH_OMAP4
2039 bank->saved_datain = __raw_readl(bank->base +
2040 OMAP4_GPIO_DATAIN);
2041 l1 = __raw_readl(bank->base + OMAP4_GPIO_FALLINGDETECT);
2042 l2 = __raw_readl(bank->base + OMAP4_GPIO_RISINGDETECT);
2043#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002044 bank->saved_fallingdetect = l1;
2045 bank->saved_risingdetect = l2;
2046 l1 &= ~bank->enabled_non_wakeup_gpios;
2047 l2 &= ~bank->enabled_non_wakeup_gpios;
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002048#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002049 __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2050 __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002051#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302052#ifdef CONFIG_ARCH_OMAP4
2053 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
2054 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
2055#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002056 c++;
2057 }
2058 if (!c) {
2059 workaround_enabled = 0;
2060 return;
2061 }
2062 workaround_enabled = 1;
2063}
2064
2065void omap2_gpio_resume_after_retention(void)
2066{
2067 int i;
2068
2069 if (!workaround_enabled)
2070 return;
2071 for (i = 0; i < gpio_bank_count; i++) {
2072 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002073 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002074
2075 if (!(bank->enabled_non_wakeup_gpios))
2076 continue;
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002077#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002078 __raw_writel(bank->saved_fallingdetect,
2079 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2080 __raw_writel(bank->saved_risingdetect,
2081 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302082 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2083#endif
2084#ifdef CONFIG_ARCH_OMAP4
2085 __raw_writel(bank->saved_fallingdetect,
2086 bank->base + OMAP4_GPIO_FALLINGDETECT);
2087 __raw_writel(bank->saved_risingdetect,
2088 bank->base + OMAP4_GPIO_RISINGDETECT);
2089 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002090#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002091 /* Check if any of the non-wakeup interrupt GPIOs have changed
2092 * state. If so, generate an IRQ by software. This is
2093 * horribly racy, but it's the best we can do to work around
2094 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002095 l ^= bank->saved_datain;
2096 l &= bank->non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002097
2098 /*
2099 * No need to generate IRQs for the rising edge for gpio IRQs
2100 * configured with falling edge only; and vice versa.
2101 */
2102 gen0 = l & bank->saved_fallingdetect;
2103 gen0 &= bank->saved_datain;
2104
2105 gen1 = l & bank->saved_risingdetect;
2106 gen1 &= ~(bank->saved_datain);
2107
2108 /* FIXME: Consider GPIO IRQs with level detections properly! */
2109 gen = l & (~(bank->saved_fallingdetect) &
2110 ~(bank->saved_risingdetect));
2111 /* Consider all GPIO IRQs needed to be updated */
2112 gen |= gen0 | gen1;
2113
2114 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002115 u32 old0, old1;
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002116#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002117 old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2118 old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002119 __raw_writel(old0 | gen, bank->base +
2120 OMAP24XX_GPIO_LEVELDETECT0);
2121 __raw_writel(old1 | gen, bank->base +
2122 OMAP24XX_GPIO_LEVELDETECT1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002123 __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2124 __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002125#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302126#ifdef CONFIG_ARCH_OMAP4
2127 old0 = __raw_readl(bank->base +
2128 OMAP4_GPIO_LEVELDETECT0);
2129 old1 = __raw_readl(bank->base +
2130 OMAP4_GPIO_LEVELDETECT1);
2131 __raw_writel(old0 | l, bank->base +
2132 OMAP4_GPIO_LEVELDETECT0);
2133 __raw_writel(old1 | l, bank->base +
2134 OMAP4_GPIO_LEVELDETECT1);
2135 __raw_writel(old0, bank->base +
2136 OMAP4_GPIO_LEVELDETECT0);
2137 __raw_writel(old1, bank->base +
2138 OMAP4_GPIO_LEVELDETECT1);
2139#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002140 }
2141 }
2142
2143}
2144
Tony Lindgren92105bb2005-09-07 17:20:26 +01002145#endif
2146
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002147#ifdef CONFIG_ARCH_OMAP3
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302148/* save the registers of bank 2-6 */
2149void omap_gpio_save_context(void)
2150{
2151 int i;
2152
2153 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2154 for (i = 1; i < gpio_bank_count; i++) {
2155 struct gpio_bank *bank = &gpio_bank[i];
2156 gpio_context[i].sysconfig =
2157 __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG);
2158 gpio_context[i].irqenable1 =
2159 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
2160 gpio_context[i].irqenable2 =
2161 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
2162 gpio_context[i].wake_en =
2163 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
2164 gpio_context[i].ctrl =
2165 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
2166 gpio_context[i].oe =
2167 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
2168 gpio_context[i].leveldetect0 =
2169 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2170 gpio_context[i].leveldetect1 =
2171 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2172 gpio_context[i].risingdetect =
2173 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
2174 gpio_context[i].fallingdetect =
2175 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2176 gpio_context[i].dataout =
2177 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
2178 gpio_context[i].setwkuena =
2179 __raw_readl(bank->base + OMAP24XX_GPIO_SETWKUENA);
2180 gpio_context[i].setdataout =
2181 __raw_readl(bank->base + OMAP24XX_GPIO_SETDATAOUT);
2182 }
2183}
2184
2185/* restore the required registers of bank 2-6 */
2186void omap_gpio_restore_context(void)
2187{
2188 int i;
2189
2190 for (i = 1; i < gpio_bank_count; i++) {
2191 struct gpio_bank *bank = &gpio_bank[i];
2192 __raw_writel(gpio_context[i].sysconfig,
2193 bank->base + OMAP24XX_GPIO_SYSCONFIG);
2194 __raw_writel(gpio_context[i].irqenable1,
2195 bank->base + OMAP24XX_GPIO_IRQENABLE1);
2196 __raw_writel(gpio_context[i].irqenable2,
2197 bank->base + OMAP24XX_GPIO_IRQENABLE2);
2198 __raw_writel(gpio_context[i].wake_en,
2199 bank->base + OMAP24XX_GPIO_WAKE_EN);
2200 __raw_writel(gpio_context[i].ctrl,
2201 bank->base + OMAP24XX_GPIO_CTRL);
2202 __raw_writel(gpio_context[i].oe,
2203 bank->base + OMAP24XX_GPIO_OE);
2204 __raw_writel(gpio_context[i].leveldetect0,
2205 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2206 __raw_writel(gpio_context[i].leveldetect1,
2207 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2208 __raw_writel(gpio_context[i].risingdetect,
2209 bank->base + OMAP24XX_GPIO_RISINGDETECT);
2210 __raw_writel(gpio_context[i].fallingdetect,
2211 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2212 __raw_writel(gpio_context[i].dataout,
2213 bank->base + OMAP24XX_GPIO_DATAOUT);
2214 __raw_writel(gpio_context[i].setwkuena,
2215 bank->base + OMAP24XX_GPIO_SETWKUENA);
2216 __raw_writel(gpio_context[i].setdataout,
2217 bank->base + OMAP24XX_GPIO_SETDATAOUT);
2218 }
2219}
2220#endif
2221
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002222/*
2223 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002224 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002225 */
David Brownell277d58e2006-12-06 17:13:59 -08002226int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002227{
2228 if (!initialized)
2229 return _omap_gpio_init();
2230 else
2231 return 0;
2232}
2233
Tony Lindgren92105bb2005-09-07 17:20:26 +01002234static int __init omap_gpio_sysinit(void)
2235{
2236 int ret = 0;
2237
2238 if (!initialized)
2239 ret = _omap_gpio_init();
2240
David Brownell11a78b72006-12-06 17:14:11 -08002241 mpuio_init();
2242
Tony Lindgren088ef952010-02-12 12:26:47 -08002243#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2) || \
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002244 defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002245 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002246 if (ret == 0) {
2247 ret = sysdev_class_register(&omap_gpio_sysclass);
2248 if (ret == 0)
2249 ret = sysdev_register(&omap_gpio_device);
2250 }
2251 }
2252#endif
2253
2254 return ret;
2255}
2256
Tony Lindgren92105bb2005-09-07 17:20:26 +01002257arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002258
2259
2260#ifdef CONFIG_DEBUG_FS
2261
2262#include <linux/debugfs.h>
2263#include <linux/seq_file.h>
2264
David Brownellb9772a22006-12-06 17:13:53 -08002265static int dbg_gpio_show(struct seq_file *s, void *unused)
2266{
2267 unsigned i, j, gpio;
2268
2269 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2270 struct gpio_bank *bank = gpio_bank + i;
2271 unsigned bankwidth = 16;
2272 u32 mask = 1;
2273
David Brownelle5c56ed2006-12-06 17:13:59 -08002274 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002275 gpio = OMAP_MPUIO(0);
Alistair Buxtonb718aa82009-09-23 18:56:19 +01002276 else if (cpu_class_is_omap2() || cpu_is_omap7xx())
David Brownellb9772a22006-12-06 17:13:53 -08002277 bankwidth = 32;
2278
2279 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2280 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002281 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002282
David Brownell52e31342008-03-03 12:43:23 -08002283 label = gpiochip_is_requested(&bank->chip, j);
2284 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002285 continue;
2286
2287 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002288 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002289 is_in = gpio_is_input(bank, mask);
2290
David Brownelle5c56ed2006-12-06 17:13:59 -08002291 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002292 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002293 else
David Brownell52e31342008-03-03 12:43:23 -08002294 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002295 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002296 label,
David Brownellb9772a22006-12-06 17:13:53 -08002297 is_in ? "in " : "out",
2298 value ? "hi" : "lo");
2299
David Brownell52e31342008-03-03 12:43:23 -08002300/* FIXME for at least omap2, show pullup/pulldown state */
2301
David Brownellb9772a22006-12-06 17:13:53 -08002302 irqstat = irq_desc[irq].status;
Tony Lindgren088ef952010-02-12 12:26:47 -08002303#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2) || \
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002304 defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
David Brownellb9772a22006-12-06 17:13:53 -08002305 if (is_in && ((bank->suspend_wakeup & mask)
2306 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2307 char *trigger = NULL;
2308
2309 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2310 case IRQ_TYPE_EDGE_FALLING:
2311 trigger = "falling";
2312 break;
2313 case IRQ_TYPE_EDGE_RISING:
2314 trigger = "rising";
2315 break;
2316 case IRQ_TYPE_EDGE_BOTH:
2317 trigger = "bothedge";
2318 break;
2319 case IRQ_TYPE_LEVEL_LOW:
2320 trigger = "low";
2321 break;
2322 case IRQ_TYPE_LEVEL_HIGH:
2323 trigger = "high";
2324 break;
2325 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002326 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002327 break;
2328 }
David Brownell52e31342008-03-03 12:43:23 -08002329 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002330 irq, trigger,
2331 (bank->suspend_wakeup & mask)
2332 ? " wakeup" : "");
2333 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002334#endif
David Brownellb9772a22006-12-06 17:13:53 -08002335 seq_printf(s, "\n");
2336 }
2337
David Brownelle5c56ed2006-12-06 17:13:59 -08002338 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002339 seq_printf(s, "\n");
2340 gpio = 0;
2341 }
2342 }
2343 return 0;
2344}
2345
2346static int dbg_gpio_open(struct inode *inode, struct file *file)
2347{
David Brownelle5c56ed2006-12-06 17:13:59 -08002348 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002349}
2350
2351static const struct file_operations debug_fops = {
2352 .open = dbg_gpio_open,
2353 .read = seq_read,
2354 .llseek = seq_lseek,
2355 .release = single_release,
2356};
2357
2358static int __init omap_gpio_debuginit(void)
2359{
David Brownelle5c56ed2006-12-06 17:13:59 -08002360 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2361 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002362 return 0;
2363}
2364late_initcall(omap_gpio_debuginit);
2365#endif