blob: 1c81340ce65cf136025bb90210e8f348b8eba1bc [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>
Kevin Hilman43ffcd92009-01-27 11:09:24 -080030#include <plat/powerdomain.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010031
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010032/*
33 * OMAP1510 GPIO registers
34 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070035#define OMAP1510_GPIO_BASE 0xfffce000
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010036#define OMAP1510_GPIO_DATA_INPUT 0x00
37#define OMAP1510_GPIO_DATA_OUTPUT 0x04
38#define OMAP1510_GPIO_DIR_CONTROL 0x08
39#define OMAP1510_GPIO_INT_CONTROL 0x0c
40#define OMAP1510_GPIO_INT_MASK 0x10
41#define OMAP1510_GPIO_INT_STATUS 0x14
42#define OMAP1510_GPIO_PIN_CONTROL 0x18
43
44#define OMAP1510_IH_GPIO_BASE 64
45
46/*
47 * OMAP1610 specific GPIO registers
48 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070049#define OMAP1610_GPIO1_BASE 0xfffbe400
50#define OMAP1610_GPIO2_BASE 0xfffbec00
51#define OMAP1610_GPIO3_BASE 0xfffbb400
52#define OMAP1610_GPIO4_BASE 0xfffbbc00
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010053#define OMAP1610_GPIO_REVISION 0x0000
54#define OMAP1610_GPIO_SYSCONFIG 0x0010
55#define OMAP1610_GPIO_SYSSTATUS 0x0014
56#define OMAP1610_GPIO_IRQSTATUS1 0x0018
57#define OMAP1610_GPIO_IRQENABLE1 0x001c
Tony Lindgren92105bb2005-09-07 17:20:26 +010058#define OMAP1610_GPIO_WAKEUPENABLE 0x0028
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010059#define OMAP1610_GPIO_DATAIN 0x002c
60#define OMAP1610_GPIO_DATAOUT 0x0030
61#define OMAP1610_GPIO_DIRECTION 0x0034
62#define OMAP1610_GPIO_EDGE_CTRL1 0x0038
63#define OMAP1610_GPIO_EDGE_CTRL2 0x003c
64#define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
Tony Lindgren92105bb2005-09-07 17:20:26 +010065#define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010066#define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
67#define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
Tony Lindgren92105bb2005-09-07 17:20:26 +010068#define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010069#define OMAP1610_GPIO_SET_DATAOUT 0x00f0
70
71/*
Alistair Buxton7c006922009-09-22 10:02:58 +010072 * OMAP7XX specific GPIO registers
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010073 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070074#define OMAP7XX_GPIO1_BASE 0xfffbc000
75#define OMAP7XX_GPIO2_BASE 0xfffbc800
76#define OMAP7XX_GPIO3_BASE 0xfffbd000
77#define OMAP7XX_GPIO4_BASE 0xfffbd800
78#define OMAP7XX_GPIO5_BASE 0xfffbe000
79#define OMAP7XX_GPIO6_BASE 0xfffbe800
Alistair Buxton7c006922009-09-22 10:02:58 +010080#define OMAP7XX_GPIO_DATA_INPUT 0x00
81#define OMAP7XX_GPIO_DATA_OUTPUT 0x04
82#define OMAP7XX_GPIO_DIR_CONTROL 0x08
83#define OMAP7XX_GPIO_INT_CONTROL 0x0c
84#define OMAP7XX_GPIO_INT_MASK 0x10
85#define OMAP7XX_GPIO_INT_STATUS 0x14
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010086
Tony Lindgren9f7065d2009-10-19 15:25:20 -070087#define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
Tony Lindgren94113262009-08-28 10:50:33 -070088
Zebediah C. McClure56739a62009-03-23 18:07:40 -070089/*
Tony Lindgren92105bb2005-09-07 17:20:26 +010090 * omap24xx specific GPIO registers
91 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070092#define OMAP242X_GPIO1_BASE 0x48018000
93#define OMAP242X_GPIO2_BASE 0x4801a000
94#define OMAP242X_GPIO3_BASE 0x4801c000
95#define OMAP242X_GPIO4_BASE 0x4801e000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -080096
Tony Lindgren9f7065d2009-10-19 15:25:20 -070097#define OMAP243X_GPIO1_BASE 0x4900C000
98#define OMAP243X_GPIO2_BASE 0x4900E000
99#define OMAP243X_GPIO3_BASE 0x49010000
100#define OMAP243X_GPIO4_BASE 0x49012000
101#define OMAP243X_GPIO5_BASE 0x480B6000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800102
Tony Lindgren92105bb2005-09-07 17:20:26 +0100103#define OMAP24XX_GPIO_REVISION 0x0000
104#define OMAP24XX_GPIO_SYSCONFIG 0x0010
105#define OMAP24XX_GPIO_SYSSTATUS 0x0014
106#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300107#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
108#define OMAP24XX_GPIO_IRQENABLE2 0x002c
Tony Lindgren92105bb2005-09-07 17:20:26 +0100109#define OMAP24XX_GPIO_IRQENABLE1 0x001c
Tero Kristo723fdb72008-11-26 14:35:16 -0800110#define OMAP24XX_GPIO_WAKE_EN 0x0020
Tony Lindgren92105bb2005-09-07 17:20:26 +0100111#define OMAP24XX_GPIO_CTRL 0x0030
112#define OMAP24XX_GPIO_OE 0x0034
113#define OMAP24XX_GPIO_DATAIN 0x0038
114#define OMAP24XX_GPIO_DATAOUT 0x003c
115#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
116#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
117#define OMAP24XX_GPIO_RISINGDETECT 0x0048
118#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700119#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
120#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
Tony Lindgren92105bb2005-09-07 17:20:26 +0100121#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
122#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
123#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
124#define OMAP24XX_GPIO_SETWKUENA 0x0084
125#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
126#define OMAP24XX_GPIO_SETDATAOUT 0x0094
127
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530128#define OMAP4_GPIO_REVISION 0x0000
129#define OMAP4_GPIO_SYSCONFIG 0x0010
130#define OMAP4_GPIO_EOI 0x0020
131#define OMAP4_GPIO_IRQSTATUSRAW0 0x0024
132#define OMAP4_GPIO_IRQSTATUSRAW1 0x0028
133#define OMAP4_GPIO_IRQSTATUS0 0x002c
134#define OMAP4_GPIO_IRQSTATUS1 0x0030
135#define OMAP4_GPIO_IRQSTATUSSET0 0x0034
136#define OMAP4_GPIO_IRQSTATUSSET1 0x0038
137#define OMAP4_GPIO_IRQSTATUSCLR0 0x003c
138#define OMAP4_GPIO_IRQSTATUSCLR1 0x0040
139#define OMAP4_GPIO_IRQWAKEN0 0x0044
140#define OMAP4_GPIO_IRQWAKEN1 0x0048
141#define OMAP4_GPIO_SYSSTATUS 0x0104
142#define OMAP4_GPIO_CTRL 0x0130
143#define OMAP4_GPIO_OE 0x0134
144#define OMAP4_GPIO_DATAIN 0x0138
145#define OMAP4_GPIO_DATAOUT 0x013c
146#define OMAP4_GPIO_LEVELDETECT0 0x0140
147#define OMAP4_GPIO_LEVELDETECT1 0x0144
148#define OMAP4_GPIO_RISINGDETECT 0x0148
149#define OMAP4_GPIO_FALLINGDETECT 0x014c
150#define OMAP4_GPIO_DEBOUNCENABLE 0x0150
151#define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
152#define OMAP4_GPIO_CLEARDATAOUT 0x0190
153#define OMAP4_GPIO_SETDATAOUT 0x0194
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800154/*
155 * omap34xx specific GPIO registers
156 */
157
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700158#define OMAP34XX_GPIO1_BASE 0x48310000
159#define OMAP34XX_GPIO2_BASE 0x49050000
160#define OMAP34XX_GPIO3_BASE 0x49052000
161#define OMAP34XX_GPIO4_BASE 0x49054000
162#define OMAP34XX_GPIO5_BASE 0x49056000
163#define OMAP34XX_GPIO6_BASE 0x49058000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800164
Santosh Shilimkar44169072009-05-28 14:16:04 -0700165/*
166 * OMAP44XX specific GPIO registers
167 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700168#define OMAP44XX_GPIO1_BASE 0x4a310000
169#define OMAP44XX_GPIO2_BASE 0x48055000
170#define OMAP44XX_GPIO3_BASE 0x48057000
171#define OMAP44XX_GPIO4_BASE 0x48059000
172#define OMAP44XX_GPIO5_BASE 0x4805B000
173#define OMAP44XX_GPIO6_BASE 0x4805D000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800174
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100175struct gpio_bank {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700176 unsigned long pbase;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100177 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100178 u16 irq;
179 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100180 int method;
Tony Lindgren140455f2010-02-12 12:26:48 -0800181#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
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 Lindgren140455f2010-02-12 12:26:48 -0800185#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800186 u32 non_wakeup_gpios;
187 u32 enabled_non_wakeup_gpios;
188
189 u32 saved_datain;
190 u32 saved_fallingdetect;
191 u32 saved_risingdetect;
192#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800193 u32 level_mask;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800194 u32 toggle_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100195 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800196 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800197 struct clk *dbck;
Charulatha V058af1e2009-11-22 10:11:25 -0800198 u32 mod_usage;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100199};
200
201#define METHOD_MPUIO 0
202#define METHOD_GPIO_1510 1
203#define METHOD_GPIO_1610 2
Alistair Buxton7c006922009-09-22 10:02:58 +0100204#define METHOD_GPIO_7XX 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700205#define METHOD_GPIO_24XX 5
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800206#define METHOD_GPIO_44XX 6
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] = {
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530316 { OMAP44XX_GPIO1_BASE, NULL, OMAP44XX_IRQ_GPIO1, IH_GPIO_BASE,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800317 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530318 { OMAP44XX_GPIO2_BASE, NULL, OMAP44XX_IRQ_GPIO2, IH_GPIO_BASE + 32,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800319 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530320 { OMAP44XX_GPIO3_BASE, NULL, OMAP44XX_IRQ_GPIO3, IH_GPIO_BASE + 64,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800321 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530322 { OMAP44XX_GPIO4_BASE, NULL, OMAP44XX_IRQ_GPIO4, IH_GPIO_BASE + 96,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800323 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530324 { OMAP44XX_GPIO5_BASE, NULL, OMAP44XX_IRQ_GPIO5, IH_GPIO_BASE + 128,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800325 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530326 { OMAP44XX_GPIO6_BASE, NULL, OMAP44XX_IRQ_GPIO6, IH_GPIO_BASE + 160,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800327 METHOD_GPIO_44XX },
Santosh Shilimkar44169072009-05-28 14:16:04 -0700328};
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)
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800435 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530436 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
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800506 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530507 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
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800555 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530556 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 Lindgren140455f2010-02-12 12:26:48 -0800595#ifdef CONFIG_ARCH_OMAP2PLUS
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300596 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800597 case METHOD_GPIO_44XX:
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300598 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;
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800628
629 if (cpu_is_omap44xx())
630 reg += OMAP4_GPIO_DEBOUNCENABLE;
631 else
632 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
633
Charulatha V058af1e2009-11-22 10:11:25 -0800634 if (!(bank->mod_usage & l)) {
635 printk(KERN_ERR "GPIO %d not requested\n", gpio);
636 return;
637 }
David Brownelle031ab22008-12-10 17:35:27 -0800638
639 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700640 val = __raw_readl(reg);
641
Jouni Hogander89db9482008-12-10 17:35:24 -0800642 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700643 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800644 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700645 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800646 else
David Brownelle031ab22008-12-10 17:35:27 -0800647 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800648
Santosh Shilimkar44169072009-05-28 14:16:04 -0700649 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800650 if (enable)
651 clk_enable(bank->dbck);
652 else
653 clk_disable(bank->dbck);
654 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700655
656 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800657done:
658 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700659}
660EXPORT_SYMBOL(omap_set_gpio_debounce);
661
662void omap_set_gpio_debounce_time(int gpio, int enc_time)
663{
664 struct gpio_bank *bank;
665 void __iomem *reg;
666
667 if (cpu_class_is_omap1())
668 return;
669
670 bank = get_gpio_bank(gpio);
671 reg = bank->base;
672
Charulatha V058af1e2009-11-22 10:11:25 -0800673 if (!bank->mod_usage) {
674 printk(KERN_ERR "GPIO not requested\n");
675 return;
676 }
677
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700678 enc_time &= 0xff;
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800679
680 if (cpu_is_omap44xx())
681 reg += OMAP4_GPIO_DEBOUNCINGTIME;
682 else
683 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
684
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700685 __raw_writel(enc_time, reg);
686}
687EXPORT_SYMBOL(omap_set_gpio_debounce_time);
688
Tony Lindgren140455f2010-02-12 12:26:48 -0800689#ifdef CONFIG_ARCH_OMAP2PLUS
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700690static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
691 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100692{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800693 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100694 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530695 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100696
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530697 if (cpu_is_omap44xx()) {
698 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
699 trigger & IRQ_TYPE_LEVEL_LOW);
700 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
701 trigger & IRQ_TYPE_LEVEL_HIGH);
702 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
703 trigger & IRQ_TYPE_EDGE_RISING);
704 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
705 trigger & IRQ_TYPE_EDGE_FALLING);
706 } else {
707 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
708 trigger & IRQ_TYPE_LEVEL_LOW);
709 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
710 trigger & IRQ_TYPE_LEVEL_HIGH);
711 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
712 trigger & IRQ_TYPE_EDGE_RISING);
713 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
714 trigger & IRQ_TYPE_EDGE_FALLING);
715 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800716 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530717 if (cpu_is_omap44xx()) {
718 if (trigger != 0)
719 __raw_writel(1 << gpio, bank->base+
720 OMAP4_GPIO_IRQWAKEN0);
721 else {
722 val = __raw_readl(bank->base +
723 OMAP4_GPIO_IRQWAKEN0);
724 __raw_writel(val & (~(1 << gpio)), bank->base +
725 OMAP4_GPIO_IRQWAKEN0);
726 }
727 } else {
Chunqiu Wang699117a2009-06-24 17:13:39 +0000728 /*
729 * GPIO wakeup request can only be generated on edge
730 * transitions
731 */
732 if (trigger & IRQ_TYPE_EDGE_BOTH)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530733 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700734 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530735 else
736 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700737 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530738 }
Tero Kristoa118b5f2008-12-22 14:27:12 +0200739 }
740 /* This part needs to be executed always for OMAP34xx */
741 if (cpu_is_omap34xx() || (bank->non_wakeup_gpios & gpio_bit)) {
Chunqiu Wang699117a2009-06-24 17:13:39 +0000742 /*
743 * Log the edge gpio and manually trigger the IRQ
744 * after resume if the input level changes
745 * to avoid irq lost during PER RET/OFF mode
746 * Applies for omap2 non-wakeup gpio and all omap3 gpios
747 */
748 if (trigger & IRQ_TYPE_EDGE_BOTH)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800749 bank->enabled_non_wakeup_gpios |= gpio_bit;
750 else
751 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
752 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700753
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530754 if (cpu_is_omap44xx()) {
755 bank->level_mask =
756 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
757 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
758 } else {
759 bank->level_mask =
760 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
761 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
762 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100763}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800764#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100765
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800766#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800767/*
768 * This only applies to chips that can't do both rising and falling edge
769 * detection at once. For all other chips, this function is a noop.
770 */
771static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
772{
773 void __iomem *reg = bank->base;
774 u32 l = 0;
775
776 switch (bank->method) {
Cory Maccarrone4318f362010-01-08 10:29:04 -0800777 case METHOD_MPUIO:
778 reg += OMAP_MPUIO_GPIO_INT_EDGE;
779 break;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800780#ifdef CONFIG_ARCH_OMAP15XX
781 case METHOD_GPIO_1510:
782 reg += OMAP1510_GPIO_INT_CONTROL;
783 break;
784#endif
785#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
786 case METHOD_GPIO_7XX:
787 reg += OMAP7XX_GPIO_INT_CONTROL;
788 break;
789#endif
790 default:
791 return;
792 }
793
794 l = __raw_readl(reg);
795 if ((l >> gpio) & 1)
796 l &= ~(1 << gpio);
797 else
798 l |= 1 << gpio;
799
800 __raw_writel(l, reg);
801}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800802#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800803
Tony Lindgren92105bb2005-09-07 17:20:26 +0100804static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
805{
806 void __iomem *reg = bank->base;
807 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100808
809 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800810#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100811 case METHOD_MPUIO:
812 reg += OMAP_MPUIO_GPIO_INT_EDGE;
813 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000814 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800815 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100816 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100817 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100818 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100819 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100820 else
821 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100822 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800823#endif
824#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100825 case METHOD_GPIO_1510:
826 reg += OMAP1510_GPIO_INT_CONTROL;
827 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000828 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800829 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100830 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100831 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100832 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100833 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100834 else
835 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100836 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800837#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800838#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100839 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100840 if (gpio & 0x08)
841 reg += OMAP1610_GPIO_EDGE_CTRL2;
842 else
843 reg += OMAP1610_GPIO_EDGE_CTRL1;
844 gpio &= 0x07;
845 l = __raw_readl(reg);
846 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100847 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100848 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100849 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100850 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800851 if (trigger)
852 /* Enable wake-up during idle for dynamic tick */
853 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
854 else
855 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100856 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800857#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100858#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100859 case METHOD_GPIO_7XX:
860 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700861 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000862 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800863 bank->toggle_mask |= 1 << gpio;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700864 if (trigger & IRQ_TYPE_EDGE_RISING)
865 l |= 1 << gpio;
866 else if (trigger & IRQ_TYPE_EDGE_FALLING)
867 l &= ~(1 << gpio);
868 else
869 goto bad;
870 break;
871#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800872#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +0100873 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800874 case METHOD_GPIO_44XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800875 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100876 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800877#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100878 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100879 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100880 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100881 __raw_writel(l, reg);
882 return 0;
883bad:
884 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100885}
886
Tony Lindgren92105bb2005-09-07 17:20:26 +0100887static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100888{
889 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100890 unsigned gpio;
891 int retval;
David Brownella6472532008-03-03 04:33:30 -0800892 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100893
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800894 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100895 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
896 else
897 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100898
899 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100900 return -EINVAL;
901
David Brownelle5c56ed2006-12-06 17:13:59 -0800902 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100903 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800904
905 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800906 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800907 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100908 return -EINVAL;
909
David Brownell58781012006-12-06 17:14:10 -0800910 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800911 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100912 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800913 if (retval == 0) {
914 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
915 irq_desc[irq].status |= type;
916 }
David Brownella6472532008-03-03 04:33:30 -0800917 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800918
919 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
920 __set_irq_handler_unlocked(irq, handle_level_irq);
921 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
922 __set_irq_handler_unlocked(irq, handle_edge_irq);
923
Tony Lindgren92105bb2005-09-07 17:20:26 +0100924 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100925}
926
927static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
928{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100929 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100930
931 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800932#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100933 case METHOD_MPUIO:
934 /* MPUIO irqstatus is reset by reading the status register,
935 * so do nothing here */
936 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800937#endif
938#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100939 case METHOD_GPIO_1510:
940 reg += OMAP1510_GPIO_INT_STATUS;
941 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800942#endif
943#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100944 case METHOD_GPIO_1610:
945 reg += OMAP1610_GPIO_IRQSTATUS1;
946 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800947#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100948#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100949 case METHOD_GPIO_7XX:
950 reg += OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700951 break;
952#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800953#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100954 case METHOD_GPIO_24XX:
955 reg += OMAP24XX_GPIO_IRQSTATUS1;
956 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800957#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530958#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800959 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530960 reg += OMAP4_GPIO_IRQSTATUS0;
961 break;
962#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100963 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800964 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100965 return;
966 }
967 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300968
969 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800970 if (cpu_is_omap24xx() || cpu_is_omap34xx())
971 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
972 else if (cpu_is_omap44xx())
973 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
974
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530975 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700976 __raw_writel(gpio_mask, reg);
977
978 /* Flush posted write for the irq status to avoid spurious interrupts */
979 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530980 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100981}
982
983static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
984{
985 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
986}
987
Imre Deakea6dedd2006-06-26 16:16:00 -0700988static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
989{
990 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700991 int inv = 0;
992 u32 l;
993 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700994
995 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800996#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700997 case METHOD_MPUIO:
998 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700999 mask = 0xffff;
1000 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -07001001 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001002#endif
1003#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -07001004 case METHOD_GPIO_1510:
1005 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -07001006 mask = 0xffff;
1007 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -07001008 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001009#endif
1010#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -07001011 case METHOD_GPIO_1610:
1012 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001013 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001014 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001015#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001016#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001017 case METHOD_GPIO_7XX:
1018 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001019 mask = 0xffffffff;
1020 inv = 1;
1021 break;
1022#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001023#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Imre Deakea6dedd2006-06-26 16:16:00 -07001024 case METHOD_GPIO_24XX:
1025 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001026 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001027 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001028#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301029#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001030 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301031 reg += OMAP4_GPIO_IRQSTATUSSET0;
1032 mask = 0xffffffff;
1033 break;
1034#endif
Imre Deakea6dedd2006-06-26 16:16:00 -07001035 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001036 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -07001037 return 0;
1038 }
1039
Imre Deak99c47702006-06-26 16:16:07 -07001040 l = __raw_readl(reg);
1041 if (inv)
1042 l = ~l;
1043 l &= mask;
1044 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -07001045}
1046
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001047static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
1048{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001049 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001050 u32 l;
1051
1052 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001053#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001054 case METHOD_MPUIO:
1055 reg += OMAP_MPUIO_GPIO_MASKIT;
1056 l = __raw_readl(reg);
1057 if (enable)
1058 l &= ~(gpio_mask);
1059 else
1060 l |= gpio_mask;
1061 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001062#endif
1063#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001064 case METHOD_GPIO_1510:
1065 reg += OMAP1510_GPIO_INT_MASK;
1066 l = __raw_readl(reg);
1067 if (enable)
1068 l &= ~(gpio_mask);
1069 else
1070 l |= gpio_mask;
1071 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001072#endif
1073#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001074 case METHOD_GPIO_1610:
1075 if (enable)
1076 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1077 else
1078 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1079 l = gpio_mask;
1080 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001081#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001082#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001083 case METHOD_GPIO_7XX:
1084 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001085 l = __raw_readl(reg);
1086 if (enable)
1087 l &= ~(gpio_mask);
1088 else
1089 l |= gpio_mask;
1090 break;
1091#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001092#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001093 case METHOD_GPIO_24XX:
1094 if (enable)
1095 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1096 else
1097 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1098 l = gpio_mask;
1099 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001100#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301101#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001102 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301103 if (enable)
1104 reg += OMAP4_GPIO_IRQSTATUSSET0;
1105 else
1106 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1107 l = gpio_mask;
1108 break;
1109#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001110 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001111 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001112 return;
1113 }
1114 __raw_writel(l, reg);
1115}
1116
1117static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1118{
1119 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1120}
1121
Tony Lindgren92105bb2005-09-07 17:20:26 +01001122/*
1123 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1124 * 1510 does not seem to have a wake-up register. If JTAG is connected
1125 * to the target, system will wake up always on GPIO events. While
1126 * system is running all registered GPIO interrupts need to have wake-up
1127 * enabled. When system is suspended, only selected GPIO interrupts need
1128 * to have wake-up enabled.
1129 */
1130static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1131{
Tony Lindgren4cc64202010-01-08 10:29:05 -08001132 unsigned long uninitialized_var(flags);
David Brownella6472532008-03-03 04:33:30 -08001133
Tony Lindgren92105bb2005-09-07 17:20:26 +01001134 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001135#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001136 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001137 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001138 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001139 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001140 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001141 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001142 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001143 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001144 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001145#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001146#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001147 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001148 case METHOD_GPIO_44XX:
David Brownell11a78b72006-12-06 17:14:11 -08001149 if (bank->non_wakeup_gpios & (1 << gpio)) {
1150 printk(KERN_ERR "Unable to modify wakeup on "
1151 "non-wakeup GPIO%d\n",
1152 (bank - gpio_bank) * 32 + gpio);
1153 return -EINVAL;
1154 }
David Brownella6472532008-03-03 04:33:30 -08001155 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001156 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001157 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001158 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001159 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001160 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001161 return 0;
1162#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001163 default:
1164 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1165 bank->method);
1166 return -EINVAL;
1167 }
1168}
1169
Tony Lindgren4196dd62006-09-25 12:41:38 +03001170static void _reset_gpio(struct gpio_bank *bank, int gpio)
1171{
1172 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1173 _set_gpio_irqenable(bank, gpio, 0);
1174 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001175 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001176}
1177
Tony Lindgren92105bb2005-09-07 17:20:26 +01001178/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1179static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1180{
1181 unsigned int gpio = irq - IH_GPIO_BASE;
1182 struct gpio_bank *bank;
1183 int retval;
1184
1185 if (check_gpio(gpio) < 0)
1186 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001187 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001188 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001189
1190 return retval;
1191}
1192
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001193static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001194{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001195 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001196 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001197
David Brownella6472532008-03-03 04:33:30 -08001198 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001199
Tony Lindgren4196dd62006-09-25 12:41:38 +03001200 /* Set trigger to none. You need to enable the desired trigger with
1201 * request_irq() or set_irq_type().
1202 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001203 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001204
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001205#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001206 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001207 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001208
Tony Lindgren92105bb2005-09-07 17:20:26 +01001209 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001210 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001211 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001212 }
1213#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001214 if (!cpu_class_is_omap1()) {
1215 if (!bank->mod_usage) {
1216 u32 ctrl;
1217 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1218 ctrl &= 0xFFFFFFFE;
1219 /* Module is enabled, clocks are not gated */
1220 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1221 }
1222 bank->mod_usage |= 1 << offset;
1223 }
David Brownella6472532008-03-03 04:33:30 -08001224 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001225
1226 return 0;
1227}
1228
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001229static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001230{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001231 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001232 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001233
David Brownella6472532008-03-03 04:33:30 -08001234 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001235#ifdef CONFIG_ARCH_OMAP16XX
1236 if (bank->method == METHOD_GPIO_1610) {
1237 /* Disable wake-up during idle for dynamic tick */
1238 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001239 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001240 }
1241#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001242#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001243 if ((bank->method == METHOD_GPIO_24XX) ||
1244 (bank->method == METHOD_GPIO_44XX)) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001245 /* Disable wake-up during idle for dynamic tick */
1246 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001247 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001248 }
1249#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001250 if (!cpu_class_is_omap1()) {
1251 bank->mod_usage &= ~(1 << offset);
1252 if (!bank->mod_usage) {
1253 u32 ctrl;
1254 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1255 /* Module is disabled, clocks are gated */
1256 ctrl |= 1;
1257 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1258 }
1259 }
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001260 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001261 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001262}
1263
1264/*
1265 * We need to unmask the GPIO bank interrupt as soon as possible to
1266 * avoid missing GPIO interrupts for other lines in the bank.
1267 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1268 * in the bank to avoid missing nested interrupts for a GPIO line.
1269 * If we wait to unmask individual GPIO lines in the bank after the
1270 * line's interrupt handler has been run, we may miss some nested
1271 * interrupts.
1272 */
Russell King10dd5ce2006-11-23 11:41:32 +00001273static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001274{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001275 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001276 u32 isr;
Cory Maccarrone4318f362010-01-08 10:29:04 -08001277 unsigned int gpio_irq, gpio_index;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001278 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001279 u32 retrigger = 0;
1280 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001281
1282 desc->chip->ack(irq);
1283
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001284 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001285#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001286 if (bank->method == METHOD_MPUIO)
1287 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001288#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001289#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001290 if (bank->method == METHOD_GPIO_1510)
1291 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1292#endif
1293#if defined(CONFIG_ARCH_OMAP16XX)
1294 if (bank->method == METHOD_GPIO_1610)
1295 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1296#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001297#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001298 if (bank->method == METHOD_GPIO_7XX)
1299 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001300#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001301#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001302 if (bank->method == METHOD_GPIO_24XX)
1303 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1304#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301305#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001306 if (bank->method == METHOD_GPIO_44XX)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301307 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1308#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001309 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001310 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001311 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001312
Imre Deakea6dedd2006-06-26 16:16:00 -07001313 enabled = _get_gpio_irqbank_mask(bank);
1314 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001315
1316 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1317 isr &= 0x0000ffff;
1318
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001319 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001320 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001321 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001322
1323 /* clear edge sensitive interrupts before handler(s) are
1324 called so that we don't miss any interrupt occurred while
1325 executing them */
1326 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1327 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1328 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1329
1330 /* if there is only edge sensitive GPIO pin interrupts
1331 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001332 if (!level_mask && !unmasked) {
1333 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001334 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001335 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001336
Imre Deakea6dedd2006-06-26 16:16:00 -07001337 isr |= retrigger;
1338 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001339 if (!isr)
1340 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001341
Tony Lindgren92105bb2005-09-07 17:20:26 +01001342 gpio_irq = bank->virtual_irq_start;
1343 for (; isr != 0; isr >>= 1, gpio_irq++) {
Cory Maccarrone4318f362010-01-08 10:29:04 -08001344 gpio_index = get_gpio_index(irq_to_gpio(gpio_irq));
1345
Tony Lindgren92105bb2005-09-07 17:20:26 +01001346 if (!(isr & 1))
1347 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001348
Cory Maccarrone4318f362010-01-08 10:29:04 -08001349#ifdef CONFIG_ARCH_OMAP1
1350 /*
1351 * Some chips can't respond to both rising and falling
1352 * at the same time. If this irq was requested with
1353 * both flags, we need to flip the ICR data for the IRQ
1354 * to respond to the IRQ for the opposite direction.
1355 * This will be indicated in the bank toggle_mask.
1356 */
1357 if (bank->toggle_mask & (1 << gpio_index))
1358 _toggle_gpio_edge_triggering(bank, gpio_index);
1359#endif
1360
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001361 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001362 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001363 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001364 /* if bank has any level sensitive GPIO pin interrupt
1365 configured, we must unmask the bank interrupt only after
1366 handler(s) are executed in order to avoid spurious bank
1367 interrupt */
1368 if (!unmasked)
1369 desc->chip->unmask(irq);
1370
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001371}
1372
Tony Lindgren4196dd62006-09-25 12:41:38 +03001373static void gpio_irq_shutdown(unsigned int irq)
1374{
1375 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001376 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001377
1378 _reset_gpio(bank, gpio);
1379}
1380
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001381static void gpio_ack_irq(unsigned int irq)
1382{
1383 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001384 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001385
1386 _clear_gpio_irqstatus(bank, gpio);
1387}
1388
1389static void gpio_mask_irq(unsigned int irq)
1390{
1391 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001392 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001393
1394 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001395 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001396}
1397
1398static void gpio_unmask_irq(unsigned int irq)
1399{
1400 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001401 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001402 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001403 struct irq_desc *desc = irq_to_desc(irq);
1404 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1405
1406 if (trigger)
1407 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001408
1409 /* For level-triggered GPIOs, the clearing must be done after
1410 * the HW source is cleared, thus after the handler has run */
1411 if (bank->level_mask & irq_mask) {
1412 _set_gpio_irqenable(bank, gpio, 0);
1413 _clear_gpio_irqstatus(bank, gpio);
1414 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001415
Kevin Hilman4de8c752008-01-16 21:56:14 -08001416 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001417}
1418
David Brownelle5c56ed2006-12-06 17:13:59 -08001419static struct irq_chip gpio_irq_chip = {
1420 .name = "GPIO",
1421 .shutdown = gpio_irq_shutdown,
1422 .ack = gpio_ack_irq,
1423 .mask = gpio_mask_irq,
1424 .unmask = gpio_unmask_irq,
1425 .set_type = gpio_irq_type,
1426 .set_wake = gpio_wake_enable,
1427};
1428
1429/*---------------------------------------------------------------------*/
1430
1431#ifdef CONFIG_ARCH_OMAP1
1432
1433/* MPUIO uses the always-on 32k clock */
1434
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001435static void mpuio_ack_irq(unsigned int irq)
1436{
1437 /* The ISR is reset automatically, so do nothing here. */
1438}
1439
1440static void mpuio_mask_irq(unsigned int irq)
1441{
1442 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001443 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001444
1445 _set_gpio_irqenable(bank, gpio, 0);
1446}
1447
1448static void mpuio_unmask_irq(unsigned int irq)
1449{
1450 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001451 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001452
1453 _set_gpio_irqenable(bank, gpio, 1);
1454}
1455
David Brownelle5c56ed2006-12-06 17:13:59 -08001456static struct irq_chip mpuio_irq_chip = {
1457 .name = "MPUIO",
1458 .ack = mpuio_ack_irq,
1459 .mask = mpuio_mask_irq,
1460 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001461 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001462#ifdef CONFIG_ARCH_OMAP16XX
1463 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1464 .set_wake = gpio_wake_enable,
1465#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001466};
1467
David Brownelle5c56ed2006-12-06 17:13:59 -08001468
1469#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1470
David Brownell11a78b72006-12-06 17:14:11 -08001471
1472#ifdef CONFIG_ARCH_OMAP16XX
1473
1474#include <linux/platform_device.h>
1475
Magnus Damm79ee0312009-07-08 13:22:04 +02001476static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001477{
Magnus Damm79ee0312009-07-08 13:22:04 +02001478 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001479 struct gpio_bank *bank = platform_get_drvdata(pdev);
1480 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001481 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001482
David Brownella6472532008-03-03 04:33:30 -08001483 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001484 bank->saved_wakeup = __raw_readl(mask_reg);
1485 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001486 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001487
1488 return 0;
1489}
1490
Magnus Damm79ee0312009-07-08 13:22:04 +02001491static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001492{
Magnus Damm79ee0312009-07-08 13:22:04 +02001493 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001494 struct gpio_bank *bank = platform_get_drvdata(pdev);
1495 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001496 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001497
David Brownella6472532008-03-03 04:33:30 -08001498 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001499 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001500 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001501
1502 return 0;
1503}
1504
Alexey Dobriyan47145212009-12-14 18:00:08 -08001505static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +02001506 .suspend_noirq = omap_mpuio_suspend_noirq,
1507 .resume_noirq = omap_mpuio_resume_noirq,
1508};
1509
David Brownell11a78b72006-12-06 17:14:11 -08001510/* use platform_driver for this, now that there's no longer any
1511 * point to sys_device (other than not disturbing old code).
1512 */
1513static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001514 .driver = {
1515 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001516 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001517 },
1518};
1519
1520static struct platform_device omap_mpuio_device = {
1521 .name = "mpuio",
1522 .id = -1,
1523 .dev = {
1524 .driver = &omap_mpuio_driver.driver,
1525 }
1526 /* could list the /proc/iomem resources */
1527};
1528
1529static inline void mpuio_init(void)
1530{
David Brownellfcf126d2007-04-02 12:46:47 -07001531 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1532
David Brownell11a78b72006-12-06 17:14:11 -08001533 if (platform_driver_register(&omap_mpuio_driver) == 0)
1534 (void) platform_device_register(&omap_mpuio_device);
1535}
1536
1537#else
1538static inline void mpuio_init(void) {}
1539#endif /* 16xx */
1540
David Brownelle5c56ed2006-12-06 17:13:59 -08001541#else
1542
1543extern struct irq_chip mpuio_irq_chip;
1544
1545#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001546static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001547
1548#endif
1549
1550/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001551
David Brownell52e31342008-03-03 12:43:23 -08001552/* REVISIT these are stupid implementations! replace by ones that
1553 * don't switch on METHOD_* and which mostly avoid spinlocks
1554 */
1555
1556static int gpio_input(struct gpio_chip *chip, unsigned offset)
1557{
1558 struct gpio_bank *bank;
1559 unsigned long flags;
1560
1561 bank = container_of(chip, struct gpio_bank, chip);
1562 spin_lock_irqsave(&bank->lock, flags);
1563 _set_gpio_direction(bank, offset, 1);
1564 spin_unlock_irqrestore(&bank->lock, flags);
1565 return 0;
1566}
1567
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001568static int gpio_is_input(struct gpio_bank *bank, int mask)
1569{
1570 void __iomem *reg = bank->base;
1571
1572 switch (bank->method) {
1573 case METHOD_MPUIO:
1574 reg += OMAP_MPUIO_IO_CNTL;
1575 break;
1576 case METHOD_GPIO_1510:
1577 reg += OMAP1510_GPIO_DIR_CONTROL;
1578 break;
1579 case METHOD_GPIO_1610:
1580 reg += OMAP1610_GPIO_DIRECTION;
1581 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001582 case METHOD_GPIO_7XX:
1583 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001584 break;
1585 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001586 case METHOD_GPIO_44XX:
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001587 reg += OMAP24XX_GPIO_OE;
1588 break;
1589 }
1590 return __raw_readl(reg) & mask;
1591}
1592
David Brownell52e31342008-03-03 12:43:23 -08001593static int gpio_get(struct gpio_chip *chip, unsigned offset)
1594{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001595 struct gpio_bank *bank;
1596 void __iomem *reg;
1597 int gpio;
1598 u32 mask;
1599
1600 gpio = chip->base + offset;
1601 bank = get_gpio_bank(gpio);
1602 reg = bank->base;
1603 mask = 1 << get_gpio_index(gpio);
1604
1605 if (gpio_is_input(bank, mask))
1606 return _get_gpio_datain(bank, gpio);
1607 else
1608 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001609}
1610
1611static int gpio_output(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 _set_gpio_direction(bank, offset, 0);
1620 spin_unlock_irqrestore(&bank->lock, flags);
1621 return 0;
1622}
1623
1624static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1625{
1626 struct gpio_bank *bank;
1627 unsigned long flags;
1628
1629 bank = container_of(chip, struct gpio_bank, chip);
1630 spin_lock_irqsave(&bank->lock, flags);
1631 _set_gpio_dataout(bank, offset, value);
1632 spin_unlock_irqrestore(&bank->lock, flags);
1633}
1634
David Brownella007b702008-12-10 17:35:25 -08001635static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1636{
1637 struct gpio_bank *bank;
1638
1639 bank = container_of(chip, struct gpio_bank, chip);
1640 return bank->virtual_irq_start + offset;
1641}
1642
David Brownell52e31342008-03-03 12:43:23 -08001643/*---------------------------------------------------------------------*/
1644
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001645static int initialized;
Tony Lindgren56213ca2010-02-12 12:26:46 -08001646#if defined(CONFIG_ARCH_OMAP1) || defined(CONFIG_ARCH_OMAP2)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001647static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001648#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001649
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001650#if defined(CONFIG_ARCH_OMAP2)
1651static struct clk * gpio_fck;
1652#endif
1653
1654#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001655static struct clk * gpio5_ick;
1656static struct clk * gpio5_fck;
1657#endif
1658
Santosh Shilimkar44169072009-05-28 14:16:04 -07001659#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001660static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1661#endif
1662
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001663static void __init omap_gpio_show_rev(void)
1664{
1665 u32 rev;
1666
1667 if (cpu_is_omap16xx())
1668 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1669 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1670 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1671 else if (cpu_is_omap44xx())
1672 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1673 else
1674 return;
1675
1676 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1677 (rev >> 4) & 0x0f, rev & 0x0f);
1678}
1679
David Brownell8ba55c52008-02-26 11:10:50 -08001680/* This lock class tells lockdep that GPIO irqs are in a different
1681 * category than their parents, so it won't report false recursion.
1682 */
1683static struct lock_class_key gpio_lock_class;
1684
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001685static int __init _omap_gpio_init(void)
1686{
1687 int i;
David Brownell52e31342008-03-03 12:43:23 -08001688 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001689 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001690 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001691 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001692
1693 initialized = 1;
1694
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001695#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001696 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001697 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1698 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001699 printk("Could not get arm_gpio_ck\n");
1700 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001701 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001702 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001703#endif
1704#if defined(CONFIG_ARCH_OMAP2)
1705 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001706 gpio_ick = clk_get(NULL, "gpios_ick");
1707 if (IS_ERR(gpio_ick))
1708 printk("Could not get gpios_ick\n");
1709 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001710 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001711 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001712 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001713 printk("Could not get gpios_fck\n");
1714 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001715 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001716
1717 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001718 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001719 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001720#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001721 if (cpu_is_omap2430()) {
1722 gpio5_ick = clk_get(NULL, "gpio5_ick");
1723 if (IS_ERR(gpio5_ick))
1724 printk("Could not get gpio5_ick\n");
1725 else
1726 clk_enable(gpio5_ick);
1727 gpio5_fck = clk_get(NULL, "gpio5_fck");
1728 if (IS_ERR(gpio5_fck))
1729 printk("Could not get gpio5_fck\n");
1730 else
1731 clk_enable(gpio5_fck);
1732 }
1733#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001734 }
1735#endif
1736
Santosh Shilimkar44169072009-05-28 14:16:04 -07001737#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1738 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001739 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1740 sprintf(clk_name, "gpio%d_ick", i + 1);
1741 gpio_iclks[i] = clk_get(NULL, clk_name);
1742 if (IS_ERR(gpio_iclks[i]))
1743 printk(KERN_ERR "Could not get %s\n", clk_name);
1744 else
1745 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001746 }
1747 }
1748#endif
1749
Tony Lindgren92105bb2005-09-07 17:20:26 +01001750
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001751#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001752 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001753 gpio_bank_count = 2;
1754 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001755 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001756 }
1757#endif
1758#if defined(CONFIG_ARCH_OMAP16XX)
1759 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001760 gpio_bank_count = 5;
1761 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001762 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001763 }
1764#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001765#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1766 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001767 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001768 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001769 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001770 }
1771#endif
Tony Lindgren088ef952010-02-12 12:26:47 -08001772#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001773 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001774 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001775 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001776 }
1777 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001778 gpio_bank_count = 5;
1779 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001780 }
1781#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001782#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001783 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001784 gpio_bank_count = OMAP34XX_NR_GPIOS;
1785 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001786 }
1787#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001788#ifdef CONFIG_ARCH_OMAP4
1789 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001790 gpio_bank_count = OMAP34XX_NR_GPIOS;
1791 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001792 }
1793#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001794 for (i = 0; i < gpio_bank_count; i++) {
1795 int j, gpio_count = 16;
1796
1797 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001798 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001799
1800 /* Static mapping, never released */
1801 bank->base = ioremap(bank->pbase, bank_size);
1802 if (!bank->base) {
1803 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1804 continue;
1805 }
1806
David Brownelle5c56ed2006-12-06 17:13:59 -08001807 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001808 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001809 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001810 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1811 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1812 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001813 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001814 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1815 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001816 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001817 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001818 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1819 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1820 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001821
Alistair Buxton7c006922009-09-22 10:02:58 +01001822 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001823 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001824
Tony Lindgren140455f2010-02-12 12:26:48 -08001825#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001826 if ((bank->method == METHOD_GPIO_24XX) ||
1827 (bank->method == METHOD_GPIO_44XX)) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001828 static const u32 non_wakeup_gpios[] = {
1829 0xe203ffc0, 0x08700040
1830 };
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001831
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001832 if (cpu_is_omap44xx()) {
1833 __raw_writel(0xffffffff, bank->base +
1834 OMAP4_GPIO_IRQSTATUSCLR0);
1835 __raw_writew(0x0015, bank->base +
1836 OMAP4_GPIO_SYSCONFIG);
1837 __raw_writel(0x00000000, bank->base +
1838 OMAP4_GPIO_DEBOUNCENABLE);
1839 /*
1840 * Initialize interface clock ungated,
1841 * module enabled
1842 */
1843 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1844 } else {
1845 __raw_writel(0x00000000, bank->base +
1846 OMAP24XX_GPIO_IRQENABLE1);
1847 __raw_writel(0xffffffff, bank->base +
1848 OMAP24XX_GPIO_IRQSTATUS1);
1849 __raw_writew(0x0015, bank->base +
1850 OMAP24XX_GPIO_SYSCONFIG);
1851 __raw_writel(0x00000000, bank->base +
1852 OMAP24XX_GPIO_DEBOUNCE_EN);
1853
1854 /*
1855 * Initialize interface clock ungated,
1856 * module enabled
1857 */
1858 __raw_writel(0, bank->base +
1859 OMAP24XX_GPIO_CTRL);
1860 }
Tero Kristoa118b5f2008-12-22 14:27:12 +02001861 if (cpu_is_omap24xx() &&
1862 i < ARRAY_SIZE(non_wakeup_gpios))
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001863 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001864 gpio_count = 32;
1865 }
1866#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001867
1868 bank->mod_usage = 0;
David Brownell52e31342008-03-03 12:43:23 -08001869 /* REVISIT eventually switch from OMAP-specific gpio structs
1870 * over to the generic ones
1871 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001872 bank->chip.request = omap_gpio_request;
1873 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001874 bank->chip.direction_input = gpio_input;
1875 bank->chip.get = gpio_get;
1876 bank->chip.direction_output = gpio_output;
1877 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001878 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001879 if (bank_is_mpuio(bank)) {
1880 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001881#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001882 bank->chip.dev = &omap_mpuio_device.dev;
1883#endif
David Brownell52e31342008-03-03 12:43:23 -08001884 bank->chip.base = OMAP_MPUIO(0);
1885 } else {
1886 bank->chip.label = "gpio";
1887 bank->chip.base = gpio;
1888 gpio += gpio_count;
1889 }
1890 bank->chip.ngpio = gpio_count;
1891
1892 gpiochip_add(&bank->chip);
1893
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001894 for (j = bank->virtual_irq_start;
1895 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001896 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001897 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001898 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001899 set_irq_chip(j, &mpuio_irq_chip);
1900 else
1901 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001902 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001903 set_irq_flags(j, IRQF_VALID);
1904 }
1905 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1906 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001907
Santosh Shilimkar44169072009-05-28 14:16:04 -07001908 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001909 sprintf(clk_name, "gpio%d_dbck", i + 1);
1910 bank->dbck = clk_get(NULL, clk_name);
1911 if (IS_ERR(bank->dbck))
1912 printk(KERN_ERR "Could not get %s\n", clk_name);
1913 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001914 }
1915
1916 /* Enable system clock for GPIO module.
1917 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001918 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001919 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1920
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001921 /* Enable autoidle for the OCP interface */
1922 if (cpu_is_omap24xx())
1923 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001924 if (cpu_is_omap34xx())
1925 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001926
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001927 omap_gpio_show_rev();
1928
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001929 return 0;
1930}
1931
Tony Lindgren140455f2010-02-12 12:26:48 -08001932#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001933static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1934{
1935 int i;
1936
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001937 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001938 return 0;
1939
1940 for (i = 0; i < gpio_bank_count; i++) {
1941 struct gpio_bank *bank = &gpio_bank[i];
1942 void __iomem *wake_status;
1943 void __iomem *wake_clear;
1944 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001945 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001946
1947 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001948#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001949 case METHOD_GPIO_1610:
1950 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1951 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1952 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1953 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001954#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001955#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001956 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001957 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001958 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1959 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1960 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001961#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301962#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001963 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301964 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1965 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1966 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1967 break;
1968#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001969 default:
1970 continue;
1971 }
1972
David Brownella6472532008-03-03 04:33:30 -08001973 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001974 bank->saved_wakeup = __raw_readl(wake_status);
1975 __raw_writel(0xffffffff, wake_clear);
1976 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001977 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001978 }
1979
1980 return 0;
1981}
1982
1983static int omap_gpio_resume(struct sys_device *dev)
1984{
1985 int i;
1986
Tero Kristo723fdb72008-11-26 14:35:16 -08001987 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001988 return 0;
1989
1990 for (i = 0; i < gpio_bank_count; i++) {
1991 struct gpio_bank *bank = &gpio_bank[i];
1992 void __iomem *wake_clear;
1993 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001994 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001995
1996 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001997#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001998 case METHOD_GPIO_1610:
1999 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
2000 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
2001 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08002002#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002003#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01002004 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03002005 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
2006 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01002007 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08002008#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302009#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002010 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302011 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
2012 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
2013 break;
2014#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01002015 default:
2016 continue;
2017 }
2018
David Brownella6472532008-03-03 04:33:30 -08002019 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002020 __raw_writel(0xffffffff, wake_clear);
2021 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08002022 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002023 }
2024
2025 return 0;
2026}
2027
2028static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01002029 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01002030 .suspend = omap_gpio_suspend,
2031 .resume = omap_gpio_resume,
2032};
2033
2034static struct sys_device omap_gpio_device = {
2035 .id = 0,
2036 .cls = &omap_gpio_sysclass,
2037};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002038
2039#endif
2040
Tony Lindgren140455f2010-02-12 12:26:48 -08002041#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002042
2043static int workaround_enabled;
2044
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002045void omap2_gpio_prepare_for_idle(int power_state)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002046{
2047 int i, c = 0;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002048 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002049
Tero Kristoa118b5f2008-12-22 14:27:12 +02002050 if (cpu_is_omap34xx())
2051 min = 1;
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002052
Tero Kristoa118b5f2008-12-22 14:27:12 +02002053 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002054 struct gpio_bank *bank = &gpio_bank[i];
2055 u32 l1, l2;
2056
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002057 if (power_state > PWRDM_POWER_OFF)
2058 continue;
2059
2060 /* If going to OFF, remove triggering for all
2061 * non-wakeup GPIOs. Otherwise spurious IRQs will be
2062 * generated. See OMAP2420 Errata item 1.101. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002063 if (!(bank->enabled_non_wakeup_gpios))
2064 continue;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002065
2066 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2067 bank->saved_datain = __raw_readl(bank->base +
2068 OMAP24XX_GPIO_DATAIN);
2069 l1 = __raw_readl(bank->base +
2070 OMAP24XX_GPIO_FALLINGDETECT);
2071 l2 = __raw_readl(bank->base +
2072 OMAP24XX_GPIO_RISINGDETECT);
2073 }
2074
2075 if (cpu_is_omap44xx()) {
2076 bank->saved_datain = __raw_readl(bank->base +
2077 OMAP4_GPIO_DATAIN);
2078 l1 = __raw_readl(bank->base +
2079 OMAP4_GPIO_FALLINGDETECT);
2080 l2 = __raw_readl(bank->base +
2081 OMAP4_GPIO_RISINGDETECT);
2082 }
2083
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002084 bank->saved_fallingdetect = l1;
2085 bank->saved_risingdetect = l2;
2086 l1 &= ~bank->enabled_non_wakeup_gpios;
2087 l2 &= ~bank->enabled_non_wakeup_gpios;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002088
2089 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2090 __raw_writel(l1, bank->base +
2091 OMAP24XX_GPIO_FALLINGDETECT);
2092 __raw_writel(l2, bank->base +
2093 OMAP24XX_GPIO_RISINGDETECT);
2094 }
2095
2096 if (cpu_is_omap44xx()) {
2097 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
2098 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
2099 }
2100
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002101 c++;
2102 }
2103 if (!c) {
2104 workaround_enabled = 0;
2105 return;
2106 }
2107 workaround_enabled = 1;
2108}
2109
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002110void omap2_gpio_resume_after_idle(void)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002111{
2112 int i;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002113 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002114
Tero Kristoa118b5f2008-12-22 14:27:12 +02002115 if (cpu_is_omap34xx())
2116 min = 1;
2117 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002118 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002119 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002120
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002121 if (!workaround_enabled)
2122 continue;
2123
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002124 if (!(bank->enabled_non_wakeup_gpios))
2125 continue;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002126
2127 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2128 __raw_writel(bank->saved_fallingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002129 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002130 __raw_writel(bank->saved_risingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002131 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002132 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2133 }
2134
2135 if (cpu_is_omap44xx()) {
2136 __raw_writel(bank->saved_fallingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302137 bank->base + OMAP4_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002138 __raw_writel(bank->saved_risingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302139 bank->base + OMAP4_GPIO_RISINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002140 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
2141 }
2142
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002143 /* Check if any of the non-wakeup interrupt GPIOs have changed
2144 * state. If so, generate an IRQ by software. This is
2145 * horribly racy, but it's the best we can do to work around
2146 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002147 l ^= bank->saved_datain;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002148 l &= bank->enabled_non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002149
2150 /*
2151 * No need to generate IRQs for the rising edge for gpio IRQs
2152 * configured with falling edge only; and vice versa.
2153 */
2154 gen0 = l & bank->saved_fallingdetect;
2155 gen0 &= bank->saved_datain;
2156
2157 gen1 = l & bank->saved_risingdetect;
2158 gen1 &= ~(bank->saved_datain);
2159
2160 /* FIXME: Consider GPIO IRQs with level detections properly! */
2161 gen = l & (~(bank->saved_fallingdetect) &
2162 ~(bank->saved_risingdetect));
2163 /* Consider all GPIO IRQs needed to be updated */
2164 gen |= gen0 | gen1;
2165
2166 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002167 u32 old0, old1;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002168
Sergio Aguirref00d6492010-03-03 16:21:08 +00002169 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002170 old0 = __raw_readl(bank->base +
2171 OMAP24XX_GPIO_LEVELDETECT0);
2172 old1 = __raw_readl(bank->base +
2173 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002174 __raw_writel(old0 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002175 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002176 __raw_writel(old1 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002177 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002178 __raw_writel(old0, bank->base +
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002179 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002180 __raw_writel(old1, bank->base +
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002181 OMAP24XX_GPIO_LEVELDETECT1);
2182 }
2183
2184 if (cpu_is_omap44xx()) {
2185 old0 = __raw_readl(bank->base +
2186 OMAP4_GPIO_LEVELDETECT0);
2187 old1 = __raw_readl(bank->base +
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302188 OMAP4_GPIO_LEVELDETECT1);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002189 __raw_writel(old0 | l, bank->base +
2190 OMAP4_GPIO_LEVELDETECT0);
2191 __raw_writel(old1 | l, bank->base +
2192 OMAP4_GPIO_LEVELDETECT1);
2193 __raw_writel(old0, bank->base +
2194 OMAP4_GPIO_LEVELDETECT0);
2195 __raw_writel(old1, bank->base +
2196 OMAP4_GPIO_LEVELDETECT1);
2197 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002198 }
2199 }
2200
2201}
2202
Tony Lindgren92105bb2005-09-07 17:20:26 +01002203#endif
2204
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002205#ifdef CONFIG_ARCH_OMAP3
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302206/* save the registers of bank 2-6 */
2207void omap_gpio_save_context(void)
2208{
2209 int i;
2210
2211 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2212 for (i = 1; i < gpio_bank_count; i++) {
2213 struct gpio_bank *bank = &gpio_bank[i];
2214 gpio_context[i].sysconfig =
2215 __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG);
2216 gpio_context[i].irqenable1 =
2217 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
2218 gpio_context[i].irqenable2 =
2219 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
2220 gpio_context[i].wake_en =
2221 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
2222 gpio_context[i].ctrl =
2223 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
2224 gpio_context[i].oe =
2225 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
2226 gpio_context[i].leveldetect0 =
2227 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2228 gpio_context[i].leveldetect1 =
2229 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2230 gpio_context[i].risingdetect =
2231 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
2232 gpio_context[i].fallingdetect =
2233 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2234 gpio_context[i].dataout =
2235 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
2236 gpio_context[i].setwkuena =
2237 __raw_readl(bank->base + OMAP24XX_GPIO_SETWKUENA);
2238 gpio_context[i].setdataout =
2239 __raw_readl(bank->base + OMAP24XX_GPIO_SETDATAOUT);
2240 }
2241}
2242
2243/* restore the required registers of bank 2-6 */
2244void omap_gpio_restore_context(void)
2245{
2246 int i;
2247
2248 for (i = 1; i < gpio_bank_count; i++) {
2249 struct gpio_bank *bank = &gpio_bank[i];
2250 __raw_writel(gpio_context[i].sysconfig,
2251 bank->base + OMAP24XX_GPIO_SYSCONFIG);
2252 __raw_writel(gpio_context[i].irqenable1,
2253 bank->base + OMAP24XX_GPIO_IRQENABLE1);
2254 __raw_writel(gpio_context[i].irqenable2,
2255 bank->base + OMAP24XX_GPIO_IRQENABLE2);
2256 __raw_writel(gpio_context[i].wake_en,
2257 bank->base + OMAP24XX_GPIO_WAKE_EN);
2258 __raw_writel(gpio_context[i].ctrl,
2259 bank->base + OMAP24XX_GPIO_CTRL);
2260 __raw_writel(gpio_context[i].oe,
2261 bank->base + OMAP24XX_GPIO_OE);
2262 __raw_writel(gpio_context[i].leveldetect0,
2263 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2264 __raw_writel(gpio_context[i].leveldetect1,
2265 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2266 __raw_writel(gpio_context[i].risingdetect,
2267 bank->base + OMAP24XX_GPIO_RISINGDETECT);
2268 __raw_writel(gpio_context[i].fallingdetect,
2269 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2270 __raw_writel(gpio_context[i].dataout,
2271 bank->base + OMAP24XX_GPIO_DATAOUT);
2272 __raw_writel(gpio_context[i].setwkuena,
2273 bank->base + OMAP24XX_GPIO_SETWKUENA);
2274 __raw_writel(gpio_context[i].setdataout,
2275 bank->base + OMAP24XX_GPIO_SETDATAOUT);
2276 }
2277}
2278#endif
2279
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002280/*
2281 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002282 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002283 */
David Brownell277d58e2006-12-06 17:13:59 -08002284int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002285{
2286 if (!initialized)
2287 return _omap_gpio_init();
2288 else
2289 return 0;
2290}
2291
Tony Lindgren92105bb2005-09-07 17:20:26 +01002292static int __init omap_gpio_sysinit(void)
2293{
2294 int ret = 0;
2295
2296 if (!initialized)
2297 ret = _omap_gpio_init();
2298
David Brownell11a78b72006-12-06 17:14:11 -08002299 mpuio_init();
2300
Tony Lindgren140455f2010-02-12 12:26:48 -08002301#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002302 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002303 if (ret == 0) {
2304 ret = sysdev_class_register(&omap_gpio_sysclass);
2305 if (ret == 0)
2306 ret = sysdev_register(&omap_gpio_device);
2307 }
2308 }
2309#endif
2310
2311 return ret;
2312}
2313
Tony Lindgren92105bb2005-09-07 17:20:26 +01002314arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002315
2316
2317#ifdef CONFIG_DEBUG_FS
2318
2319#include <linux/debugfs.h>
2320#include <linux/seq_file.h>
2321
David Brownellb9772a22006-12-06 17:13:53 -08002322static int dbg_gpio_show(struct seq_file *s, void *unused)
2323{
2324 unsigned i, j, gpio;
2325
2326 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2327 struct gpio_bank *bank = gpio_bank + i;
2328 unsigned bankwidth = 16;
2329 u32 mask = 1;
2330
David Brownelle5c56ed2006-12-06 17:13:59 -08002331 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002332 gpio = OMAP_MPUIO(0);
Alistair Buxtonb718aa82009-09-23 18:56:19 +01002333 else if (cpu_class_is_omap2() || cpu_is_omap7xx())
David Brownellb9772a22006-12-06 17:13:53 -08002334 bankwidth = 32;
2335
2336 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2337 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002338 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002339
David Brownell52e31342008-03-03 12:43:23 -08002340 label = gpiochip_is_requested(&bank->chip, j);
2341 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002342 continue;
2343
2344 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002345 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002346 is_in = gpio_is_input(bank, mask);
2347
David Brownelle5c56ed2006-12-06 17:13:59 -08002348 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002349 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002350 else
David Brownell52e31342008-03-03 12:43:23 -08002351 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002352 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002353 label,
David Brownellb9772a22006-12-06 17:13:53 -08002354 is_in ? "in " : "out",
2355 value ? "hi" : "lo");
2356
David Brownell52e31342008-03-03 12:43:23 -08002357/* FIXME for at least omap2, show pullup/pulldown state */
2358
David Brownellb9772a22006-12-06 17:13:53 -08002359 irqstat = irq_desc[irq].status;
Tony Lindgren140455f2010-02-12 12:26:48 -08002360#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
David Brownellb9772a22006-12-06 17:13:53 -08002361 if (is_in && ((bank->suspend_wakeup & mask)
2362 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2363 char *trigger = NULL;
2364
2365 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2366 case IRQ_TYPE_EDGE_FALLING:
2367 trigger = "falling";
2368 break;
2369 case IRQ_TYPE_EDGE_RISING:
2370 trigger = "rising";
2371 break;
2372 case IRQ_TYPE_EDGE_BOTH:
2373 trigger = "bothedge";
2374 break;
2375 case IRQ_TYPE_LEVEL_LOW:
2376 trigger = "low";
2377 break;
2378 case IRQ_TYPE_LEVEL_HIGH:
2379 trigger = "high";
2380 break;
2381 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002382 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002383 break;
2384 }
David Brownell52e31342008-03-03 12:43:23 -08002385 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002386 irq, trigger,
2387 (bank->suspend_wakeup & mask)
2388 ? " wakeup" : "");
2389 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002390#endif
David Brownellb9772a22006-12-06 17:13:53 -08002391 seq_printf(s, "\n");
2392 }
2393
David Brownelle5c56ed2006-12-06 17:13:59 -08002394 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002395 seq_printf(s, "\n");
2396 gpio = 0;
2397 }
2398 }
2399 return 0;
2400}
2401
2402static int dbg_gpio_open(struct inode *inode, struct file *file)
2403{
David Brownelle5c56ed2006-12-06 17:13:59 -08002404 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002405}
2406
2407static const struct file_operations debug_fops = {
2408 .open = dbg_gpio_open,
2409 .read = seq_read,
2410 .llseek = seq_lseek,
2411 .release = single_release,
2412};
2413
2414static int __init omap_gpio_debuginit(void)
2415{
David Brownelle5c56ed2006-12-06 17:13:59 -08002416 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2417 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002418 return 0;
2419}
2420late_initcall(omap_gpio_debuginit);
2421#endif