blob: 9b7e3545f32552e1cdb7d4bfc0b9cc6331de8b0f [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
Charulatha V9f096862010-05-14 12:05:27 -0700141#define OMAP4_GPIO_SYSSTATUS 0x0114
142#define OMAP4_GPIO_IRQENABLE1 0x011c
143#define OMAP4_GPIO_WAKE_EN 0x0120
144#define OMAP4_GPIO_IRQSTATUS2 0x0128
145#define OMAP4_GPIO_IRQENABLE2 0x012c
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530146#define OMAP4_GPIO_CTRL 0x0130
147#define OMAP4_GPIO_OE 0x0134
148#define OMAP4_GPIO_DATAIN 0x0138
149#define OMAP4_GPIO_DATAOUT 0x013c
150#define OMAP4_GPIO_LEVELDETECT0 0x0140
151#define OMAP4_GPIO_LEVELDETECT1 0x0144
152#define OMAP4_GPIO_RISINGDETECT 0x0148
153#define OMAP4_GPIO_FALLINGDETECT 0x014c
154#define OMAP4_GPIO_DEBOUNCENABLE 0x0150
155#define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
Charulatha V9f096862010-05-14 12:05:27 -0700156#define OMAP4_GPIO_CLEARIRQENABLE1 0x0160
157#define OMAP4_GPIO_SETIRQENABLE1 0x0164
158#define OMAP4_GPIO_CLEARWKUENA 0x0180
159#define OMAP4_GPIO_SETWKUENA 0x0184
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530160#define OMAP4_GPIO_CLEARDATAOUT 0x0190
161#define OMAP4_GPIO_SETDATAOUT 0x0194
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800162/*
163 * omap34xx specific GPIO registers
164 */
165
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700166#define OMAP34XX_GPIO1_BASE 0x48310000
167#define OMAP34XX_GPIO2_BASE 0x49050000
168#define OMAP34XX_GPIO3_BASE 0x49052000
169#define OMAP34XX_GPIO4_BASE 0x49054000
170#define OMAP34XX_GPIO5_BASE 0x49056000
171#define OMAP34XX_GPIO6_BASE 0x49058000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800172
Santosh Shilimkar44169072009-05-28 14:16:04 -0700173/*
174 * OMAP44XX specific GPIO registers
175 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700176#define OMAP44XX_GPIO1_BASE 0x4a310000
177#define OMAP44XX_GPIO2_BASE 0x48055000
178#define OMAP44XX_GPIO3_BASE 0x48057000
179#define OMAP44XX_GPIO4_BASE 0x48059000
180#define OMAP44XX_GPIO5_BASE 0x4805B000
181#define OMAP44XX_GPIO6_BASE 0x4805D000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800182
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100183struct gpio_bank {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700184 unsigned long pbase;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100185 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100186 u16 irq;
187 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100188 int method;
Tony Lindgren140455f2010-02-12 12:26:48 -0800189#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100190 u32 suspend_wakeup;
191 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800192#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800193#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800194 u32 non_wakeup_gpios;
195 u32 enabled_non_wakeup_gpios;
196
197 u32 saved_datain;
198 u32 saved_fallingdetect;
199 u32 saved_risingdetect;
200#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800201 u32 level_mask;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800202 u32 toggle_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100203 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800204 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800205 struct clk *dbck;
Charulatha V058af1e2009-11-22 10:11:25 -0800206 u32 mod_usage;
Kevin Hilman8865b9b2009-01-27 11:15:34 -0800207 u32 dbck_enable_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100208};
209
210#define METHOD_MPUIO 0
211#define METHOD_GPIO_1510 1
212#define METHOD_GPIO_1610 2
Alistair Buxton7c006922009-09-22 10:02:58 +0100213#define METHOD_GPIO_7XX 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700214#define METHOD_GPIO_24XX 5
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800215#define METHOD_GPIO_44XX 6
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100216
Tony Lindgren92105bb2005-09-07 17:20:26 +0100217#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100218static struct gpio_bank gpio_bank_1610[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700219 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
220 METHOD_MPUIO },
221 { OMAP1610_GPIO1_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
222 METHOD_GPIO_1610 },
223 { OMAP1610_GPIO2_BASE, NULL, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16,
224 METHOD_GPIO_1610 },
225 { OMAP1610_GPIO3_BASE, NULL, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32,
226 METHOD_GPIO_1610 },
227 { OMAP1610_GPIO4_BASE, NULL, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48,
228 METHOD_GPIO_1610 },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100229};
230#endif
231
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000232#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100233static struct gpio_bank gpio_bank_1510[2] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700234 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
235 METHOD_MPUIO },
236 { OMAP1510_GPIO_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
237 METHOD_GPIO_1510 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100238};
239#endif
240
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100241#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100242static struct gpio_bank gpio_bank_7xx[7] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700243 { OMAP1_MPUIO_VBASE, NULL, INT_7XX_MPUIO, IH_MPUIO_BASE,
244 METHOD_MPUIO },
245 { OMAP7XX_GPIO1_BASE, NULL, INT_7XX_GPIO_BANK1, IH_GPIO_BASE,
246 METHOD_GPIO_7XX },
247 { OMAP7XX_GPIO2_BASE, NULL, INT_7XX_GPIO_BANK2, IH_GPIO_BASE + 32,
248 METHOD_GPIO_7XX },
249 { OMAP7XX_GPIO3_BASE, NULL, INT_7XX_GPIO_BANK3, IH_GPIO_BASE + 64,
250 METHOD_GPIO_7XX },
251 { OMAP7XX_GPIO4_BASE, NULL, INT_7XX_GPIO_BANK4, IH_GPIO_BASE + 96,
252 METHOD_GPIO_7XX },
253 { OMAP7XX_GPIO5_BASE, NULL, INT_7XX_GPIO_BANK5, IH_GPIO_BASE + 128,
254 METHOD_GPIO_7XX },
255 { OMAP7XX_GPIO6_BASE, NULL, INT_7XX_GPIO_BANK6, IH_GPIO_BASE + 160,
256 METHOD_GPIO_7XX },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100257};
258#endif
259
Tony Lindgren088ef952010-02-12 12:26:47 -0800260#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800261
262static struct gpio_bank gpio_bank_242x[4] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700263 { OMAP242X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
264 METHOD_GPIO_24XX },
265 { OMAP242X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
266 METHOD_GPIO_24XX },
267 { OMAP242X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
268 METHOD_GPIO_24XX },
269 { OMAP242X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
270 METHOD_GPIO_24XX },
Tony Lindgren92105bb2005-09-07 17:20:26 +0100271};
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800272
273static struct gpio_bank gpio_bank_243x[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700274 { OMAP243X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
275 METHOD_GPIO_24XX },
276 { OMAP243X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
277 METHOD_GPIO_24XX },
278 { OMAP243X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
279 METHOD_GPIO_24XX },
280 { OMAP243X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
281 METHOD_GPIO_24XX },
282 { OMAP243X_GPIO5_BASE, NULL, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128,
283 METHOD_GPIO_24XX },
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800284};
285
Tony Lindgren92105bb2005-09-07 17:20:26 +0100286#endif
287
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800288#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800289static struct gpio_bank gpio_bank_34xx[6] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700290 { OMAP34XX_GPIO1_BASE, NULL, INT_34XX_GPIO_BANK1, IH_GPIO_BASE,
291 METHOD_GPIO_24XX },
292 { OMAP34XX_GPIO2_BASE, NULL, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32,
293 METHOD_GPIO_24XX },
294 { OMAP34XX_GPIO3_BASE, NULL, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64,
295 METHOD_GPIO_24XX },
296 { OMAP34XX_GPIO4_BASE, NULL, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96,
297 METHOD_GPIO_24XX },
298 { OMAP34XX_GPIO5_BASE, NULL, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128,
299 METHOD_GPIO_24XX },
300 { OMAP34XX_GPIO6_BASE, NULL, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160,
301 METHOD_GPIO_24XX },
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800302};
303
Rajendra Nayak40c670f2008-09-26 17:47:48 +0530304struct omap3_gpio_regs {
305 u32 sysconfig;
306 u32 irqenable1;
307 u32 irqenable2;
308 u32 wake_en;
309 u32 ctrl;
310 u32 oe;
311 u32 leveldetect0;
312 u32 leveldetect1;
313 u32 risingdetect;
314 u32 fallingdetect;
315 u32 dataout;
Rajendra Nayak40c670f2008-09-26 17:47:48 +0530316};
317
318static struct omap3_gpio_regs gpio_context[OMAP34XX_NR_GPIOS];
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800319#endif
320
Santosh Shilimkar44169072009-05-28 14:16:04 -0700321#ifdef CONFIG_ARCH_OMAP4
322static struct gpio_bank gpio_bank_44xx[6] = {
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530323 { OMAP44XX_GPIO1_BASE, NULL, OMAP44XX_IRQ_GPIO1, IH_GPIO_BASE,
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800324 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530325 { OMAP44XX_GPIO2_BASE, NULL, OMAP44XX_IRQ_GPIO2, IH_GPIO_BASE + 32,
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800326 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530327 { OMAP44XX_GPIO3_BASE, NULL, OMAP44XX_IRQ_GPIO3, IH_GPIO_BASE + 64,
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800328 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530329 { OMAP44XX_GPIO4_BASE, NULL, OMAP44XX_IRQ_GPIO4, IH_GPIO_BASE + 96,
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800330 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530331 { OMAP44XX_GPIO5_BASE, NULL, OMAP44XX_IRQ_GPIO5, IH_GPIO_BASE + 128,
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800332 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530333 { OMAP44XX_GPIO6_BASE, NULL, OMAP44XX_IRQ_GPIO6, IH_GPIO_BASE + 160,
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800334 METHOD_GPIO_44XX },
Santosh Shilimkar44169072009-05-28 14:16:04 -0700335};
336
337#endif
338
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100339static struct gpio_bank *gpio_bank;
340static int gpio_bank_count;
341
342static inline struct gpio_bank *get_gpio_bank(int gpio)
343{
Tony Lindgren6e60e792006-04-02 17:46:23 +0100344 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100345 if (OMAP_GPIO_IS_MPUIO(gpio))
346 return &gpio_bank[0];
347 return &gpio_bank[1];
348 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100349 if (cpu_is_omap16xx()) {
350 if (OMAP_GPIO_IS_MPUIO(gpio))
351 return &gpio_bank[0];
352 return &gpio_bank[1 + (gpio >> 4)];
353 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700354 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100355 if (OMAP_GPIO_IS_MPUIO(gpio))
356 return &gpio_bank[0];
357 return &gpio_bank[1 + (gpio >> 5)];
358 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100359 if (cpu_is_omap24xx())
360 return &gpio_bank[gpio >> 5];
Santosh Shilimkar44169072009-05-28 14:16:04 -0700361 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800362 return &gpio_bank[gpio >> 5];
David Brownelle031ab22008-12-10 17:35:27 -0800363 BUG();
364 return NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100365}
366
367static inline int get_gpio_index(int gpio)
368{
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700369 if (cpu_is_omap7xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100370 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100371 if (cpu_is_omap24xx())
372 return gpio & 0x1f;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700373 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800374 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100375 return gpio & 0x0f;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100376}
377
378static inline int gpio_valid(int gpio)
379{
380 if (gpio < 0)
381 return -1;
Tony Lindgrend11ac972008-01-12 15:35:04 -0800382 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
Jonathan McDowell193e68b2006-09-25 12:41:30 +0300383 if (gpio >= OMAP_MAX_GPIO_LINES + 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100384 return -1;
385 return 0;
386 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100387 if (cpu_is_omap15xx() && gpio < 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100388 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100389 if ((cpu_is_omap16xx()) && gpio < 64)
390 return 0;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700391 if (cpu_is_omap7xx() && gpio < 192)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100392 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100393 if (cpu_is_omap24xx() && gpio < 128)
394 return 0;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700395 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800396 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100397 return -1;
398}
399
400static int check_gpio(int gpio)
401{
Roel Kluind32b20f2009-11-17 14:39:03 -0800402 if (unlikely(gpio_valid(gpio) < 0)) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100403 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
404 dump_stack();
405 return -1;
406 }
407 return 0;
408}
409
410static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
411{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100412 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100413 u32 l;
414
415 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800416#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100417 case METHOD_MPUIO:
418 reg += OMAP_MPUIO_IO_CNTL;
419 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800420#endif
421#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100422 case METHOD_GPIO_1510:
423 reg += OMAP1510_GPIO_DIR_CONTROL;
424 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800425#endif
426#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100427 case METHOD_GPIO_1610:
428 reg += OMAP1610_GPIO_DIRECTION;
429 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800430#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100431#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100432 case METHOD_GPIO_7XX:
433 reg += OMAP7XX_GPIO_DIR_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700434 break;
435#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800436#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100437 case METHOD_GPIO_24XX:
438 reg += OMAP24XX_GPIO_OE;
439 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800440#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530441#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800442 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530443 reg += OMAP4_GPIO_OE;
444 break;
445#endif
David Brownelle5c56ed2006-12-06 17:13:59 -0800446 default:
447 WARN_ON(1);
448 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100449 }
450 l = __raw_readl(reg);
451 if (is_input)
452 l |= 1 << gpio;
453 else
454 l &= ~(1 << gpio);
455 __raw_writel(l, reg);
456}
457
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100458static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
459{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100460 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100461 u32 l = 0;
462
463 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800464#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100465 case METHOD_MPUIO:
466 reg += OMAP_MPUIO_OUTPUT;
467 l = __raw_readl(reg);
468 if (enable)
469 l |= 1 << gpio;
470 else
471 l &= ~(1 << gpio);
472 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800473#endif
474#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100475 case METHOD_GPIO_1510:
476 reg += OMAP1510_GPIO_DATA_OUTPUT;
477 l = __raw_readl(reg);
478 if (enable)
479 l |= 1 << gpio;
480 else
481 l &= ~(1 << gpio);
482 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800483#endif
484#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100485 case METHOD_GPIO_1610:
486 if (enable)
487 reg += OMAP1610_GPIO_SET_DATAOUT;
488 else
489 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
490 l = 1 << gpio;
491 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800492#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100493#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100494 case METHOD_GPIO_7XX:
495 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700496 l = __raw_readl(reg);
497 if (enable)
498 l |= 1 << gpio;
499 else
500 l &= ~(1 << gpio);
501 break;
502#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800503#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100504 case METHOD_GPIO_24XX:
505 if (enable)
506 reg += OMAP24XX_GPIO_SETDATAOUT;
507 else
508 reg += OMAP24XX_GPIO_CLEARDATAOUT;
509 l = 1 << gpio;
510 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800511#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530512#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800513 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530514 if (enable)
515 reg += OMAP4_GPIO_SETDATAOUT;
516 else
517 reg += OMAP4_GPIO_CLEARDATAOUT;
518 l = 1 << gpio;
519 break;
520#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100521 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800522 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100523 return;
524 }
525 __raw_writel(l, reg);
526}
527
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300528static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100529{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100530 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100531
532 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800533 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100534 reg = bank->base;
535 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800536#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100537 case METHOD_MPUIO:
538 reg += OMAP_MPUIO_INPUT_LATCH;
539 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800540#endif
541#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100542 case METHOD_GPIO_1510:
543 reg += OMAP1510_GPIO_DATA_INPUT;
544 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800545#endif
546#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100547 case METHOD_GPIO_1610:
548 reg += OMAP1610_GPIO_DATAIN;
549 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800550#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100551#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100552 case METHOD_GPIO_7XX:
553 reg += OMAP7XX_GPIO_DATA_INPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700554 break;
555#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800556#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100557 case METHOD_GPIO_24XX:
558 reg += OMAP24XX_GPIO_DATAIN;
559 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800560#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530561#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800562 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530563 reg += OMAP4_GPIO_DATAIN;
564 break;
565#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100566 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800567 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100568 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100569 return (__raw_readl(reg)
570 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100571}
572
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300573static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
574{
575 void __iomem *reg;
576
577 if (check_gpio(gpio) < 0)
578 return -EINVAL;
579 reg = bank->base;
580
581 switch (bank->method) {
582#ifdef CONFIG_ARCH_OMAP1
583 case METHOD_MPUIO:
584 reg += OMAP_MPUIO_OUTPUT;
585 break;
586#endif
587#ifdef CONFIG_ARCH_OMAP15XX
588 case METHOD_GPIO_1510:
589 reg += OMAP1510_GPIO_DATA_OUTPUT;
590 break;
591#endif
592#ifdef CONFIG_ARCH_OMAP16XX
593 case METHOD_GPIO_1610:
594 reg += OMAP1610_GPIO_DATAOUT;
595 break;
596#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100597#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100598 case METHOD_GPIO_7XX:
599 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300600 break;
601#endif
Charulatha V9f096862010-05-14 12:05:27 -0700602#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300603 case METHOD_GPIO_24XX:
604 reg += OMAP24XX_GPIO_DATAOUT;
605 break;
606#endif
Charulatha V9f096862010-05-14 12:05:27 -0700607#ifdef CONFIG_ARCH_OMAP4
608 case METHOD_GPIO_44XX:
609 reg += OMAP4_GPIO_DATAOUT;
610 break;
611#endif
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300612 default:
613 return -EINVAL;
614 }
615
616 return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
617}
618
Tony Lindgren92105bb2005-09-07 17:20:26 +0100619#define MOD_REG_BIT(reg, bit_mask, set) \
620do { \
621 int l = __raw_readl(base + reg); \
622 if (set) l |= bit_mask; \
623 else l &= ~bit_mask; \
624 __raw_writel(l, base + reg); \
625} while(0)
626
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700627/**
628 * _set_gpio_debounce - low level gpio debounce time
629 * @bank: the gpio bank we're acting upon
630 * @gpio: the gpio number on this @gpio
631 * @debounce: debounce time to use
632 *
633 * OMAP's debounce time is in 31us steps so we need
634 * to convert and round up to the closest unit.
635 */
636static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
637 unsigned debounce)
638{
639 void __iomem *reg = bank->base;
640 u32 val;
641 u32 l;
642
643 if (debounce < 32)
644 debounce = 0x01;
645 else if (debounce > 7936)
646 debounce = 0xff;
647 else
648 debounce = (debounce / 0x1f) - 1;
649
650 l = 1 << get_gpio_index(gpio);
651
652 if (cpu_is_omap44xx())
653 reg += OMAP4_GPIO_DEBOUNCINGTIME;
654 else
655 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
656
657 __raw_writel(debounce, reg);
658
659 reg = bank->base;
660 if (cpu_is_omap44xx())
661 reg += OMAP4_GPIO_DEBOUNCENABLE;
662 else
663 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
664
665 val = __raw_readl(reg);
666
667 if (debounce) {
668 val |= l;
669 if (cpu_is_omap34xx() || cpu_is_omap44xx())
670 clk_enable(bank->dbck);
671 } else {
672 val &= ~l;
673 if (cpu_is_omap34xx() || cpu_is_omap44xx())
674 clk_disable(bank->dbck);
675 }
Kevin Hilmanf7ec0b02010-06-09 13:53:07 +0300676 bank->dbck_enable_mask = val;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700677
678 __raw_writel(val, reg);
679}
680
Tony Lindgren140455f2010-02-12 12:26:48 -0800681#ifdef CONFIG_ARCH_OMAP2PLUS
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700682static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
683 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100684{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800685 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100686 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530687 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100688
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530689 if (cpu_is_omap44xx()) {
690 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
691 trigger & IRQ_TYPE_LEVEL_LOW);
692 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
693 trigger & IRQ_TYPE_LEVEL_HIGH);
694 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
695 trigger & IRQ_TYPE_EDGE_RISING);
696 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
697 trigger & IRQ_TYPE_EDGE_FALLING);
698 } else {
699 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
700 trigger & IRQ_TYPE_LEVEL_LOW);
701 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
702 trigger & IRQ_TYPE_LEVEL_HIGH);
703 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
704 trigger & IRQ_TYPE_EDGE_RISING);
705 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
706 trigger & IRQ_TYPE_EDGE_FALLING);
707 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800708 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530709 if (cpu_is_omap44xx()) {
710 if (trigger != 0)
711 __raw_writel(1 << gpio, bank->base+
712 OMAP4_GPIO_IRQWAKEN0);
713 else {
714 val = __raw_readl(bank->base +
715 OMAP4_GPIO_IRQWAKEN0);
716 __raw_writel(val & (~(1 << gpio)), bank->base +
717 OMAP4_GPIO_IRQWAKEN0);
718 }
719 } else {
Chunqiu Wang699117a62009-06-24 17:13:39 +0000720 /*
721 * GPIO wakeup request can only be generated on edge
722 * transitions
723 */
724 if (trigger & IRQ_TYPE_EDGE_BOTH)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530725 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700726 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530727 else
728 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700729 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530730 }
Tero Kristoa118b5f2008-12-22 14:27:12 +0200731 }
732 /* This part needs to be executed always for OMAP34xx */
733 if (cpu_is_omap34xx() || (bank->non_wakeup_gpios & gpio_bit)) {
Chunqiu Wang699117a62009-06-24 17:13:39 +0000734 /*
735 * Log the edge gpio and manually trigger the IRQ
736 * after resume if the input level changes
737 * to avoid irq lost during PER RET/OFF mode
738 * Applies for omap2 non-wakeup gpio and all omap3 gpios
739 */
740 if (trigger & IRQ_TYPE_EDGE_BOTH)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800741 bank->enabled_non_wakeup_gpios |= gpio_bit;
742 else
743 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
744 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700745
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530746 if (cpu_is_omap44xx()) {
747 bank->level_mask =
748 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
749 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
750 } else {
751 bank->level_mask =
752 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
753 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
754 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100755}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800756#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100757
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800758#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800759/*
760 * This only applies to chips that can't do both rising and falling edge
761 * detection at once. For all other chips, this function is a noop.
762 */
763static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
764{
765 void __iomem *reg = bank->base;
766 u32 l = 0;
767
768 switch (bank->method) {
Cory Maccarrone4318f362010-01-08 10:29:04 -0800769 case METHOD_MPUIO:
770 reg += OMAP_MPUIO_GPIO_INT_EDGE;
771 break;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800772#ifdef CONFIG_ARCH_OMAP15XX
773 case METHOD_GPIO_1510:
774 reg += OMAP1510_GPIO_INT_CONTROL;
775 break;
776#endif
777#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
778 case METHOD_GPIO_7XX:
779 reg += OMAP7XX_GPIO_INT_CONTROL;
780 break;
781#endif
782 default:
783 return;
784 }
785
786 l = __raw_readl(reg);
787 if ((l >> gpio) & 1)
788 l &= ~(1 << gpio);
789 else
790 l |= 1 << gpio;
791
792 __raw_writel(l, reg);
793}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800794#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800795
Tony Lindgren92105bb2005-09-07 17:20:26 +0100796static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
797{
798 void __iomem *reg = bank->base;
799 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100800
801 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800802#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100803 case METHOD_MPUIO:
804 reg += OMAP_MPUIO_GPIO_INT_EDGE;
805 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000806 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800807 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100808 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100809 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100810 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100811 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100812 else
813 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100814 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800815#endif
816#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100817 case METHOD_GPIO_1510:
818 reg += OMAP1510_GPIO_INT_CONTROL;
819 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000820 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800821 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100822 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100823 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100824 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100825 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100826 else
827 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100828 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800829#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800830#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100831 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100832 if (gpio & 0x08)
833 reg += OMAP1610_GPIO_EDGE_CTRL2;
834 else
835 reg += OMAP1610_GPIO_EDGE_CTRL1;
836 gpio &= 0x07;
837 l = __raw_readl(reg);
838 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100839 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100840 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100841 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100842 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800843 if (trigger)
844 /* Enable wake-up during idle for dynamic tick */
845 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
846 else
847 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100848 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800849#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100850#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100851 case METHOD_GPIO_7XX:
852 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700853 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000854 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800855 bank->toggle_mask |= 1 << gpio;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700856 if (trigger & IRQ_TYPE_EDGE_RISING)
857 l |= 1 << gpio;
858 else if (trigger & IRQ_TYPE_EDGE_FALLING)
859 l &= ~(1 << gpio);
860 else
861 goto bad;
862 break;
863#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800864#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +0100865 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800866 case METHOD_GPIO_44XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800867 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100868 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800869#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100870 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100871 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100872 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100873 __raw_writel(l, reg);
874 return 0;
875bad:
876 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100877}
878
Tony Lindgren92105bb2005-09-07 17:20:26 +0100879static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100880{
881 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100882 unsigned gpio;
883 int retval;
David Brownella6472532008-03-03 04:33:30 -0800884 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100885
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800886 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100887 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
888 else
889 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100890
891 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100892 return -EINVAL;
893
David Brownelle5c56ed2006-12-06 17:13:59 -0800894 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100895 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800896
897 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800898 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800899 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100900 return -EINVAL;
901
David Brownell58781012006-12-06 17:14:10 -0800902 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800903 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100904 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800905 if (retval == 0) {
906 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
907 irq_desc[irq].status |= type;
908 }
David Brownella6472532008-03-03 04:33:30 -0800909 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800910
911 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
912 __set_irq_handler_unlocked(irq, handle_level_irq);
913 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
914 __set_irq_handler_unlocked(irq, handle_edge_irq);
915
Tony Lindgren92105bb2005-09-07 17:20:26 +0100916 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100917}
918
919static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
920{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100921 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100922
923 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800924#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100925 case METHOD_MPUIO:
926 /* MPUIO irqstatus is reset by reading the status register,
927 * so do nothing here */
928 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800929#endif
930#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100931 case METHOD_GPIO_1510:
932 reg += OMAP1510_GPIO_INT_STATUS;
933 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800934#endif
935#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100936 case METHOD_GPIO_1610:
937 reg += OMAP1610_GPIO_IRQSTATUS1;
938 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800939#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100940#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100941 case METHOD_GPIO_7XX:
942 reg += OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700943 break;
944#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800945#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100946 case METHOD_GPIO_24XX:
947 reg += OMAP24XX_GPIO_IRQSTATUS1;
948 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800949#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530950#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800951 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530952 reg += OMAP4_GPIO_IRQSTATUS0;
953 break;
954#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100955 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800956 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100957 return;
958 }
959 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300960
961 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800962 if (cpu_is_omap24xx() || cpu_is_omap34xx())
963 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
964 else if (cpu_is_omap44xx())
965 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
966
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530967 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700968 __raw_writel(gpio_mask, reg);
969
970 /* Flush posted write for the irq status to avoid spurious interrupts */
971 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530972 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100973}
974
975static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
976{
977 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
978}
979
Imre Deakea6dedd2006-06-26 16:16:00 -0700980static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
981{
982 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700983 int inv = 0;
984 u32 l;
985 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700986
987 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800988#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700989 case METHOD_MPUIO:
990 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700991 mask = 0xffff;
992 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700993 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800994#endif
995#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700996 case METHOD_GPIO_1510:
997 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700998 mask = 0xffff;
999 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -07001000 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001001#endif
1002#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -07001003 case METHOD_GPIO_1610:
1004 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001005 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001006 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001007#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001008#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001009 case METHOD_GPIO_7XX:
1010 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001011 mask = 0xffffffff;
1012 inv = 1;
1013 break;
1014#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001015#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Imre Deakea6dedd2006-06-26 16:16:00 -07001016 case METHOD_GPIO_24XX:
1017 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001018 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001019 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001020#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301021#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001022 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301023 reg += OMAP4_GPIO_IRQSTATUSSET0;
1024 mask = 0xffffffff;
1025 break;
1026#endif
Imre Deakea6dedd2006-06-26 16:16:00 -07001027 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001028 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -07001029 return 0;
1030 }
1031
Imre Deak99c47702006-06-26 16:16:07 -07001032 l = __raw_readl(reg);
1033 if (inv)
1034 l = ~l;
1035 l &= mask;
1036 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -07001037}
1038
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001039static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
1040{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001041 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001042 u32 l;
1043
1044 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001045#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001046 case METHOD_MPUIO:
1047 reg += OMAP_MPUIO_GPIO_MASKIT;
1048 l = __raw_readl(reg);
1049 if (enable)
1050 l &= ~(gpio_mask);
1051 else
1052 l |= gpio_mask;
1053 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001054#endif
1055#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001056 case METHOD_GPIO_1510:
1057 reg += OMAP1510_GPIO_INT_MASK;
1058 l = __raw_readl(reg);
1059 if (enable)
1060 l &= ~(gpio_mask);
1061 else
1062 l |= gpio_mask;
1063 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001064#endif
1065#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001066 case METHOD_GPIO_1610:
1067 if (enable)
1068 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1069 else
1070 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1071 l = gpio_mask;
1072 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001073#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001074#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001075 case METHOD_GPIO_7XX:
1076 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001077 l = __raw_readl(reg);
1078 if (enable)
1079 l &= ~(gpio_mask);
1080 else
1081 l |= gpio_mask;
1082 break;
1083#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001084#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001085 case METHOD_GPIO_24XX:
1086 if (enable)
1087 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1088 else
1089 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1090 l = gpio_mask;
1091 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001092#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301093#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001094 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301095 if (enable)
1096 reg += OMAP4_GPIO_IRQSTATUSSET0;
1097 else
1098 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1099 l = gpio_mask;
1100 break;
1101#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001102 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001103 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001104 return;
1105 }
1106 __raw_writel(l, reg);
1107}
1108
1109static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1110{
1111 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1112}
1113
Tony Lindgren92105bb2005-09-07 17:20:26 +01001114/*
1115 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1116 * 1510 does not seem to have a wake-up register. If JTAG is connected
1117 * to the target, system will wake up always on GPIO events. While
1118 * system is running all registered GPIO interrupts need to have wake-up
1119 * enabled. When system is suspended, only selected GPIO interrupts need
1120 * to have wake-up enabled.
1121 */
1122static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1123{
Tony Lindgren4cc64202010-01-08 10:29:05 -08001124 unsigned long uninitialized_var(flags);
David Brownella6472532008-03-03 04:33:30 -08001125
Tony Lindgren92105bb2005-09-07 17:20:26 +01001126 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001127#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001128 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001129 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001130 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001131 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001132 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001133 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001134 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001135 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001136 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001137#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001138#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001139 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001140 case METHOD_GPIO_44XX:
David Brownell11a78b72006-12-06 17:14:11 -08001141 if (bank->non_wakeup_gpios & (1 << gpio)) {
1142 printk(KERN_ERR "Unable to modify wakeup on "
1143 "non-wakeup GPIO%d\n",
1144 (bank - gpio_bank) * 32 + gpio);
1145 return -EINVAL;
1146 }
David Brownella6472532008-03-03 04:33:30 -08001147 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001148 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001149 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001150 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001151 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001152 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001153 return 0;
1154#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001155 default:
1156 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1157 bank->method);
1158 return -EINVAL;
1159 }
1160}
1161
Tony Lindgren4196dd62006-09-25 12:41:38 +03001162static void _reset_gpio(struct gpio_bank *bank, int gpio)
1163{
1164 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1165 _set_gpio_irqenable(bank, gpio, 0);
1166 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001167 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001168}
1169
Tony Lindgren92105bb2005-09-07 17:20:26 +01001170/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1171static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1172{
1173 unsigned int gpio = irq - IH_GPIO_BASE;
1174 struct gpio_bank *bank;
1175 int retval;
1176
1177 if (check_gpio(gpio) < 0)
1178 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001179 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001180 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001181
1182 return retval;
1183}
1184
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001185static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001186{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001187 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001188 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001189
David Brownella6472532008-03-03 04:33:30 -08001190 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001191
Tony Lindgren4196dd62006-09-25 12:41:38 +03001192 /* Set trigger to none. You need to enable the desired trigger with
1193 * request_irq() or set_irq_type().
1194 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001195 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001196
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001197#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001198 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001199 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001200
Tony Lindgren92105bb2005-09-07 17:20:26 +01001201 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001202 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001203 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001204 }
1205#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001206 if (!cpu_class_is_omap1()) {
1207 if (!bank->mod_usage) {
Charulatha V9f096862010-05-14 12:05:27 -07001208 void __iomem *reg = bank->base;
Charulatha V058af1e2009-11-22 10:11:25 -08001209 u32 ctrl;
Charulatha V9f096862010-05-14 12:05:27 -07001210
1211 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1212 reg += OMAP24XX_GPIO_CTRL;
1213 else if (cpu_is_omap44xx())
1214 reg += OMAP4_GPIO_CTRL;
1215 ctrl = __raw_readl(reg);
Charulatha V058af1e2009-11-22 10:11:25 -08001216 /* Module is enabled, clocks are not gated */
Charulatha V9f096862010-05-14 12:05:27 -07001217 ctrl &= 0xFFFFFFFE;
1218 __raw_writel(ctrl, reg);
Charulatha V058af1e2009-11-22 10:11:25 -08001219 }
1220 bank->mod_usage |= 1 << offset;
1221 }
David Brownella6472532008-03-03 04:33:30 -08001222 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001223
1224 return 0;
1225}
1226
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001227static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001228{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001229 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001230 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001231
David Brownella6472532008-03-03 04:33:30 -08001232 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001233#ifdef CONFIG_ARCH_OMAP16XX
1234 if (bank->method == METHOD_GPIO_1610) {
1235 /* Disable wake-up during idle for dynamic tick */
1236 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001237 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001238 }
1239#endif
Charulatha V9f096862010-05-14 12:05:27 -07001240#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
1241 if (bank->method == METHOD_GPIO_24XX) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001242 /* Disable wake-up during idle for dynamic tick */
1243 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001244 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001245 }
1246#endif
Charulatha V9f096862010-05-14 12:05:27 -07001247#ifdef CONFIG_ARCH_OMAP4
1248 if (bank->method == METHOD_GPIO_44XX) {
1249 /* Disable wake-up during idle for dynamic tick */
1250 void __iomem *reg = bank->base + OMAP4_GPIO_IRQWAKEN0;
1251 __raw_writel(1 << offset, reg);
1252 }
1253#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001254 if (!cpu_class_is_omap1()) {
1255 bank->mod_usage &= ~(1 << offset);
1256 if (!bank->mod_usage) {
Charulatha V9f096862010-05-14 12:05:27 -07001257 void __iomem *reg = bank->base;
Charulatha V058af1e2009-11-22 10:11:25 -08001258 u32 ctrl;
Charulatha V9f096862010-05-14 12:05:27 -07001259
1260 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1261 reg += OMAP24XX_GPIO_CTRL;
1262 else if (cpu_is_omap44xx())
1263 reg += OMAP4_GPIO_CTRL;
1264 ctrl = __raw_readl(reg);
Charulatha V058af1e2009-11-22 10:11:25 -08001265 /* Module is disabled, clocks are gated */
1266 ctrl |= 1;
Charulatha V9f096862010-05-14 12:05:27 -07001267 __raw_writel(ctrl, reg);
Charulatha V058af1e2009-11-22 10:11:25 -08001268 }
1269 }
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001270 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001271 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001272}
1273
1274/*
1275 * We need to unmask the GPIO bank interrupt as soon as possible to
1276 * avoid missing GPIO interrupts for other lines in the bank.
1277 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1278 * in the bank to avoid missing nested interrupts for a GPIO line.
1279 * If we wait to unmask individual GPIO lines in the bank after the
1280 * line's interrupt handler has been run, we may miss some nested
1281 * interrupts.
1282 */
Russell King10dd5ce2006-11-23 11:41:32 +00001283static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001284{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001285 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001286 u32 isr;
Cory Maccarrone4318f362010-01-08 10:29:04 -08001287 unsigned int gpio_irq, gpio_index;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001288 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001289 u32 retrigger = 0;
1290 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001291
1292 desc->chip->ack(irq);
1293
Thomas Gleixner418ca1f02006-07-01 22:32:41 +01001294 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001295#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001296 if (bank->method == METHOD_MPUIO)
1297 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001298#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001299#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001300 if (bank->method == METHOD_GPIO_1510)
1301 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1302#endif
1303#if defined(CONFIG_ARCH_OMAP16XX)
1304 if (bank->method == METHOD_GPIO_1610)
1305 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1306#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001307#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001308 if (bank->method == METHOD_GPIO_7XX)
1309 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001310#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001311#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001312 if (bank->method == METHOD_GPIO_24XX)
1313 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1314#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301315#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001316 if (bank->method == METHOD_GPIO_44XX)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301317 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1318#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001319 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001320 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001321 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001322
Imre Deakea6dedd2006-06-26 16:16:00 -07001323 enabled = _get_gpio_irqbank_mask(bank);
1324 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001325
1326 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1327 isr &= 0x0000ffff;
1328
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001329 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001330 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001331 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001332
1333 /* clear edge sensitive interrupts before handler(s) are
1334 called so that we don't miss any interrupt occurred while
1335 executing them */
1336 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1337 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1338 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1339
1340 /* if there is only edge sensitive GPIO pin interrupts
1341 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001342 if (!level_mask && !unmasked) {
1343 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001344 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001345 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001346
Imre Deakea6dedd2006-06-26 16:16:00 -07001347 isr |= retrigger;
1348 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001349 if (!isr)
1350 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001351
Tony Lindgren92105bb2005-09-07 17:20:26 +01001352 gpio_irq = bank->virtual_irq_start;
1353 for (; isr != 0; isr >>= 1, gpio_irq++) {
Cory Maccarrone4318f362010-01-08 10:29:04 -08001354 gpio_index = get_gpio_index(irq_to_gpio(gpio_irq));
1355
Tony Lindgren92105bb2005-09-07 17:20:26 +01001356 if (!(isr & 1))
1357 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001358
Cory Maccarrone4318f362010-01-08 10:29:04 -08001359#ifdef CONFIG_ARCH_OMAP1
1360 /*
1361 * Some chips can't respond to both rising and falling
1362 * at the same time. If this irq was requested with
1363 * both flags, we need to flip the ICR data for the IRQ
1364 * to respond to the IRQ for the opposite direction.
1365 * This will be indicated in the bank toggle_mask.
1366 */
1367 if (bank->toggle_mask & (1 << gpio_index))
1368 _toggle_gpio_edge_triggering(bank, gpio_index);
1369#endif
1370
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001371 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001372 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001373 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001374 /* if bank has any level sensitive GPIO pin interrupt
1375 configured, we must unmask the bank interrupt only after
1376 handler(s) are executed in order to avoid spurious bank
1377 interrupt */
1378 if (!unmasked)
1379 desc->chip->unmask(irq);
1380
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001381}
1382
Tony Lindgren4196dd62006-09-25 12:41:38 +03001383static void gpio_irq_shutdown(unsigned int irq)
1384{
1385 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001386 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001387
1388 _reset_gpio(bank, gpio);
1389}
1390
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001391static void gpio_ack_irq(unsigned int irq)
1392{
1393 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001394 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001395
1396 _clear_gpio_irqstatus(bank, gpio);
1397}
1398
1399static void gpio_mask_irq(unsigned int irq)
1400{
1401 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001402 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001403
1404 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001405 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001406}
1407
1408static void gpio_unmask_irq(unsigned int irq)
1409{
1410 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001411 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001412 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001413 struct irq_desc *desc = irq_to_desc(irq);
1414 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1415
1416 if (trigger)
1417 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001418
1419 /* For level-triggered GPIOs, the clearing must be done after
1420 * the HW source is cleared, thus after the handler has run */
1421 if (bank->level_mask & irq_mask) {
1422 _set_gpio_irqenable(bank, gpio, 0);
1423 _clear_gpio_irqstatus(bank, gpio);
1424 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001425
Kevin Hilman4de8c752008-01-16 21:56:14 -08001426 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001427}
1428
David Brownelle5c56ed2006-12-06 17:13:59 -08001429static struct irq_chip gpio_irq_chip = {
1430 .name = "GPIO",
1431 .shutdown = gpio_irq_shutdown,
1432 .ack = gpio_ack_irq,
1433 .mask = gpio_mask_irq,
1434 .unmask = gpio_unmask_irq,
1435 .set_type = gpio_irq_type,
1436 .set_wake = gpio_wake_enable,
1437};
1438
1439/*---------------------------------------------------------------------*/
1440
1441#ifdef CONFIG_ARCH_OMAP1
1442
1443/* MPUIO uses the always-on 32k clock */
1444
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001445static void mpuio_ack_irq(unsigned int irq)
1446{
1447 /* The ISR is reset automatically, so do nothing here. */
1448}
1449
1450static void mpuio_mask_irq(unsigned int irq)
1451{
1452 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001453 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001454
1455 _set_gpio_irqenable(bank, gpio, 0);
1456}
1457
1458static void mpuio_unmask_irq(unsigned int irq)
1459{
1460 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001461 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001462
1463 _set_gpio_irqenable(bank, gpio, 1);
1464}
1465
David Brownelle5c56ed2006-12-06 17:13:59 -08001466static struct irq_chip mpuio_irq_chip = {
1467 .name = "MPUIO",
1468 .ack = mpuio_ack_irq,
1469 .mask = mpuio_mask_irq,
1470 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001471 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001472#ifdef CONFIG_ARCH_OMAP16XX
1473 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1474 .set_wake = gpio_wake_enable,
1475#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001476};
1477
David Brownelle5c56ed2006-12-06 17:13:59 -08001478
1479#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1480
David Brownell11a78b72006-12-06 17:14:11 -08001481
1482#ifdef CONFIG_ARCH_OMAP16XX
1483
1484#include <linux/platform_device.h>
1485
Magnus Damm79ee0312009-07-08 13:22:04 +02001486static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001487{
Magnus Damm79ee0312009-07-08 13:22:04 +02001488 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001489 struct gpio_bank *bank = platform_get_drvdata(pdev);
1490 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001491 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001492
David Brownella6472532008-03-03 04:33:30 -08001493 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001494 bank->saved_wakeup = __raw_readl(mask_reg);
1495 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001496 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001497
1498 return 0;
1499}
1500
Magnus Damm79ee0312009-07-08 13:22:04 +02001501static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001502{
Magnus Damm79ee0312009-07-08 13:22:04 +02001503 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001504 struct gpio_bank *bank = platform_get_drvdata(pdev);
1505 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001506 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001507
David Brownella6472532008-03-03 04:33:30 -08001508 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001509 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001510 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001511
1512 return 0;
1513}
1514
Alexey Dobriyan47145212009-12-14 18:00:08 -08001515static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +02001516 .suspend_noirq = omap_mpuio_suspend_noirq,
1517 .resume_noirq = omap_mpuio_resume_noirq,
1518};
1519
David Brownell11a78b72006-12-06 17:14:11 -08001520/* use platform_driver for this, now that there's no longer any
1521 * point to sys_device (other than not disturbing old code).
1522 */
1523static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001524 .driver = {
1525 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001526 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001527 },
1528};
1529
1530static struct platform_device omap_mpuio_device = {
1531 .name = "mpuio",
1532 .id = -1,
1533 .dev = {
1534 .driver = &omap_mpuio_driver.driver,
1535 }
1536 /* could list the /proc/iomem resources */
1537};
1538
1539static inline void mpuio_init(void)
1540{
David Brownellfcf126d2007-04-02 12:46:47 -07001541 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1542
David Brownell11a78b72006-12-06 17:14:11 -08001543 if (platform_driver_register(&omap_mpuio_driver) == 0)
1544 (void) platform_device_register(&omap_mpuio_device);
1545}
1546
1547#else
1548static inline void mpuio_init(void) {}
1549#endif /* 16xx */
1550
David Brownelle5c56ed2006-12-06 17:13:59 -08001551#else
1552
1553extern struct irq_chip mpuio_irq_chip;
1554
1555#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001556static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001557
1558#endif
1559
1560/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001561
David Brownell52e31342008-03-03 12:43:23 -08001562/* REVISIT these are stupid implementations! replace by ones that
1563 * don't switch on METHOD_* and which mostly avoid spinlocks
1564 */
1565
1566static int gpio_input(struct gpio_chip *chip, unsigned offset)
1567{
1568 struct gpio_bank *bank;
1569 unsigned long flags;
1570
1571 bank = container_of(chip, struct gpio_bank, chip);
1572 spin_lock_irqsave(&bank->lock, flags);
1573 _set_gpio_direction(bank, offset, 1);
1574 spin_unlock_irqrestore(&bank->lock, flags);
1575 return 0;
1576}
1577
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001578static int gpio_is_input(struct gpio_bank *bank, int mask)
1579{
1580 void __iomem *reg = bank->base;
1581
1582 switch (bank->method) {
1583 case METHOD_MPUIO:
1584 reg += OMAP_MPUIO_IO_CNTL;
1585 break;
1586 case METHOD_GPIO_1510:
1587 reg += OMAP1510_GPIO_DIR_CONTROL;
1588 break;
1589 case METHOD_GPIO_1610:
1590 reg += OMAP1610_GPIO_DIRECTION;
1591 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001592 case METHOD_GPIO_7XX:
1593 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001594 break;
1595 case METHOD_GPIO_24XX:
1596 reg += OMAP24XX_GPIO_OE;
1597 break;
Charulatha V9f096862010-05-14 12:05:27 -07001598 case METHOD_GPIO_44XX:
1599 reg += OMAP4_GPIO_OE;
1600 break;
1601 default:
1602 WARN_ONCE(1, "gpio_is_input: incorrect OMAP GPIO method");
1603 return -EINVAL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001604 }
1605 return __raw_readl(reg) & mask;
1606}
1607
David Brownell52e31342008-03-03 12:43:23 -08001608static int gpio_get(struct gpio_chip *chip, unsigned offset)
1609{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001610 struct gpio_bank *bank;
1611 void __iomem *reg;
1612 int gpio;
1613 u32 mask;
1614
1615 gpio = chip->base + offset;
1616 bank = get_gpio_bank(gpio);
1617 reg = bank->base;
1618 mask = 1 << get_gpio_index(gpio);
1619
1620 if (gpio_is_input(bank, mask))
1621 return _get_gpio_datain(bank, gpio);
1622 else
1623 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001624}
1625
1626static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1627{
1628 struct gpio_bank *bank;
1629 unsigned long flags;
1630
1631 bank = container_of(chip, struct gpio_bank, chip);
1632 spin_lock_irqsave(&bank->lock, flags);
1633 _set_gpio_dataout(bank, offset, value);
1634 _set_gpio_direction(bank, offset, 0);
1635 spin_unlock_irqrestore(&bank->lock, flags);
1636 return 0;
1637}
1638
Felipe Balbi168ef3d2010-05-26 14:42:23 -07001639static int gpio_debounce(struct gpio_chip *chip, unsigned offset,
1640 unsigned debounce)
1641{
1642 struct gpio_bank *bank;
1643 unsigned long flags;
1644
1645 bank = container_of(chip, struct gpio_bank, chip);
1646 spin_lock_irqsave(&bank->lock, flags);
1647 _set_gpio_debounce(bank, offset, debounce);
1648 spin_unlock_irqrestore(&bank->lock, flags);
1649
1650 return 0;
1651}
1652
David Brownell52e31342008-03-03 12:43:23 -08001653static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1654{
1655 struct gpio_bank *bank;
1656 unsigned long flags;
1657
1658 bank = container_of(chip, struct gpio_bank, chip);
1659 spin_lock_irqsave(&bank->lock, flags);
1660 _set_gpio_dataout(bank, offset, value);
1661 spin_unlock_irqrestore(&bank->lock, flags);
1662}
1663
David Brownella007b702008-12-10 17:35:25 -08001664static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1665{
1666 struct gpio_bank *bank;
1667
1668 bank = container_of(chip, struct gpio_bank, chip);
1669 return bank->virtual_irq_start + offset;
1670}
1671
David Brownell52e31342008-03-03 12:43:23 -08001672/*---------------------------------------------------------------------*/
1673
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001674static int initialized;
Tony Lindgren56213ca2010-02-12 12:26:46 -08001675#if defined(CONFIG_ARCH_OMAP1) || defined(CONFIG_ARCH_OMAP2)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001676static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001677#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001678
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001679#if defined(CONFIG_ARCH_OMAP2)
1680static struct clk * gpio_fck;
1681#endif
1682
1683#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001684static struct clk * gpio5_ick;
1685static struct clk * gpio5_fck;
1686#endif
1687
Santosh Shilimkar44169072009-05-28 14:16:04 -07001688#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001689static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1690#endif
1691
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001692static void __init omap_gpio_show_rev(void)
1693{
1694 u32 rev;
1695
1696 if (cpu_is_omap16xx())
1697 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1698 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1699 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1700 else if (cpu_is_omap44xx())
1701 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1702 else
1703 return;
1704
1705 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1706 (rev >> 4) & 0x0f, rev & 0x0f);
1707}
1708
David Brownell8ba55c52008-02-26 11:10:50 -08001709/* This lock class tells lockdep that GPIO irqs are in a different
1710 * category than their parents, so it won't report false recursion.
1711 */
1712static struct lock_class_key gpio_lock_class;
1713
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001714static int __init _omap_gpio_init(void)
1715{
1716 int i;
David Brownell52e31342008-03-03 12:43:23 -08001717 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001718 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001719 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001720 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001721
1722 initialized = 1;
1723
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001724#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001725 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001726 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1727 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001728 printk("Could not get arm_gpio_ck\n");
1729 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001730 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001731 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001732#endif
1733#if defined(CONFIG_ARCH_OMAP2)
1734 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001735 gpio_ick = clk_get(NULL, "gpios_ick");
1736 if (IS_ERR(gpio_ick))
1737 printk("Could not get gpios_ick\n");
1738 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001739 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001740 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001741 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001742 printk("Could not get gpios_fck\n");
1743 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001744 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001745
1746 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001747 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001748 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001749#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001750 if (cpu_is_omap2430()) {
1751 gpio5_ick = clk_get(NULL, "gpio5_ick");
1752 if (IS_ERR(gpio5_ick))
1753 printk("Could not get gpio5_ick\n");
1754 else
1755 clk_enable(gpio5_ick);
1756 gpio5_fck = clk_get(NULL, "gpio5_fck");
1757 if (IS_ERR(gpio5_fck))
1758 printk("Could not get gpio5_fck\n");
1759 else
1760 clk_enable(gpio5_fck);
1761 }
1762#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001763 }
1764#endif
1765
Santosh Shilimkar44169072009-05-28 14:16:04 -07001766#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1767 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001768 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1769 sprintf(clk_name, "gpio%d_ick", i + 1);
1770 gpio_iclks[i] = clk_get(NULL, clk_name);
1771 if (IS_ERR(gpio_iclks[i]))
1772 printk(KERN_ERR "Could not get %s\n", clk_name);
1773 else
1774 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001775 }
1776 }
1777#endif
1778
Tony Lindgren92105bb2005-09-07 17:20:26 +01001779
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001780#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001781 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001782 gpio_bank_count = 2;
1783 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001784 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001785 }
1786#endif
1787#if defined(CONFIG_ARCH_OMAP16XX)
1788 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001789 gpio_bank_count = 5;
1790 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001791 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001792 }
1793#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001794#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1795 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001796 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001797 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001798 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001799 }
1800#endif
Tony Lindgren088ef952010-02-12 12:26:47 -08001801#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001802 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001803 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001804 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001805 }
1806 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001807 gpio_bank_count = 5;
1808 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001809 }
1810#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001811#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001812 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001813 gpio_bank_count = OMAP34XX_NR_GPIOS;
1814 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001815 }
1816#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001817#ifdef CONFIG_ARCH_OMAP4
1818 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001819 gpio_bank_count = OMAP34XX_NR_GPIOS;
1820 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001821 }
1822#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001823 for (i = 0; i < gpio_bank_count; i++) {
1824 int j, gpio_count = 16;
1825
1826 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001827 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001828
1829 /* Static mapping, never released */
1830 bank->base = ioremap(bank->pbase, bank_size);
1831 if (!bank->base) {
1832 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1833 continue;
1834 }
1835
David Brownelle5c56ed2006-12-06 17:13:59 -08001836 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001837 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001838 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001839 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1840 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1841 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001842 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001843 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1844 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001845 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001846 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001847 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1848 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1849 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001850
Alistair Buxton7c006922009-09-22 10:02:58 +01001851 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001852 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001853
Tony Lindgren140455f2010-02-12 12:26:48 -08001854#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001855 if ((bank->method == METHOD_GPIO_24XX) ||
1856 (bank->method == METHOD_GPIO_44XX)) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001857 static const u32 non_wakeup_gpios[] = {
1858 0xe203ffc0, 0x08700040
1859 };
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001860
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001861 if (cpu_is_omap44xx()) {
1862 __raw_writel(0xffffffff, bank->base +
1863 OMAP4_GPIO_IRQSTATUSCLR0);
1864 __raw_writew(0x0015, bank->base +
1865 OMAP4_GPIO_SYSCONFIG);
1866 __raw_writel(0x00000000, bank->base +
1867 OMAP4_GPIO_DEBOUNCENABLE);
1868 /*
1869 * Initialize interface clock ungated,
1870 * module enabled
1871 */
1872 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1873 } else {
1874 __raw_writel(0x00000000, bank->base +
1875 OMAP24XX_GPIO_IRQENABLE1);
1876 __raw_writel(0xffffffff, bank->base +
1877 OMAP24XX_GPIO_IRQSTATUS1);
1878 __raw_writew(0x0015, bank->base +
1879 OMAP24XX_GPIO_SYSCONFIG);
1880 __raw_writel(0x00000000, bank->base +
1881 OMAP24XX_GPIO_DEBOUNCE_EN);
1882
1883 /*
1884 * Initialize interface clock ungated,
1885 * module enabled
1886 */
1887 __raw_writel(0, bank->base +
1888 OMAP24XX_GPIO_CTRL);
1889 }
Tero Kristoa118b5f2008-12-22 14:27:12 +02001890 if (cpu_is_omap24xx() &&
1891 i < ARRAY_SIZE(non_wakeup_gpios))
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001892 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001893 gpio_count = 32;
1894 }
1895#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001896
1897 bank->mod_usage = 0;
David Brownell52e31342008-03-03 12:43:23 -08001898 /* REVISIT eventually switch from OMAP-specific gpio structs
1899 * over to the generic ones
1900 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001901 bank->chip.request = omap_gpio_request;
1902 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001903 bank->chip.direction_input = gpio_input;
1904 bank->chip.get = gpio_get;
1905 bank->chip.direction_output = gpio_output;
Felipe Balbi168ef3d2010-05-26 14:42:23 -07001906 bank->chip.set_debounce = gpio_debounce;
David Brownell52e31342008-03-03 12:43:23 -08001907 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001908 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001909 if (bank_is_mpuio(bank)) {
1910 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001911#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d82008-07-25 01:46:07 -07001912 bank->chip.dev = &omap_mpuio_device.dev;
1913#endif
David Brownell52e31342008-03-03 12:43:23 -08001914 bank->chip.base = OMAP_MPUIO(0);
1915 } else {
1916 bank->chip.label = "gpio";
1917 bank->chip.base = gpio;
1918 gpio += gpio_count;
1919 }
1920 bank->chip.ngpio = gpio_count;
1921
1922 gpiochip_add(&bank->chip);
1923
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001924 for (j = bank->virtual_irq_start;
1925 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001926 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001927 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001928 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001929 set_irq_chip(j, &mpuio_irq_chip);
1930 else
1931 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001932 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001933 set_irq_flags(j, IRQF_VALID);
1934 }
1935 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1936 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001937
Santosh Shilimkar44169072009-05-28 14:16:04 -07001938 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001939 sprintf(clk_name, "gpio%d_dbck", i + 1);
1940 bank->dbck = clk_get(NULL, clk_name);
1941 if (IS_ERR(bank->dbck))
1942 printk(KERN_ERR "Could not get %s\n", clk_name);
1943 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001944 }
1945
1946 /* Enable system clock for GPIO module.
1947 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001948 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001949 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1950
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001951 /* Enable autoidle for the OCP interface */
1952 if (cpu_is_omap24xx())
1953 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001954 if (cpu_is_omap34xx())
1955 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001956
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001957 omap_gpio_show_rev();
1958
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001959 return 0;
1960}
1961
Tony Lindgren140455f2010-02-12 12:26:48 -08001962#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001963static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1964{
1965 int i;
1966
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001967 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001968 return 0;
1969
1970 for (i = 0; i < gpio_bank_count; i++) {
1971 struct gpio_bank *bank = &gpio_bank[i];
1972 void __iomem *wake_status;
1973 void __iomem *wake_clear;
1974 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001975 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001976
1977 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001978#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001979 case METHOD_GPIO_1610:
1980 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1981 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1982 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1983 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001984#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001985#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001986 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001987 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001988 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1989 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1990 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001991#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301992#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001993 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301994 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1995 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1996 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1997 break;
1998#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001999 default:
2000 continue;
2001 }
2002
David Brownella6472532008-03-03 04:33:30 -08002003 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002004 bank->saved_wakeup = __raw_readl(wake_status);
2005 __raw_writel(0xffffffff, wake_clear);
2006 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08002007 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002008 }
2009
2010 return 0;
2011}
2012
2013static int omap_gpio_resume(struct sys_device *dev)
2014{
2015 int i;
2016
Tero Kristo723fdb72008-11-26 14:35:16 -08002017 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01002018 return 0;
2019
2020 for (i = 0; i < gpio_bank_count; i++) {
2021 struct gpio_bank *bank = &gpio_bank[i];
2022 void __iomem *wake_clear;
2023 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08002024 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01002025
2026 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08002027#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01002028 case METHOD_GPIO_1610:
2029 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
2030 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
2031 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08002032#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002033#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01002034 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03002035 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
2036 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01002037 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08002038#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302039#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002040 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302041 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
2042 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
2043 break;
2044#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01002045 default:
2046 continue;
2047 }
2048
David Brownella6472532008-03-03 04:33:30 -08002049 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002050 __raw_writel(0xffffffff, wake_clear);
2051 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08002052 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002053 }
2054
2055 return 0;
2056}
2057
2058static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f42007-12-20 02:09:39 +01002059 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01002060 .suspend = omap_gpio_suspend,
2061 .resume = omap_gpio_resume,
2062};
2063
2064static struct sys_device omap_gpio_device = {
2065 .id = 0,
2066 .cls = &omap_gpio_sysclass,
2067};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002068
2069#endif
2070
Tony Lindgren140455f2010-02-12 12:26:48 -08002071#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002072
2073static int workaround_enabled;
2074
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002075void omap2_gpio_prepare_for_idle(int power_state)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002076{
2077 int i, c = 0;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002078 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002079
Tero Kristoa118b5f2008-12-22 14:27:12 +02002080 if (cpu_is_omap34xx())
2081 min = 1;
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002082
Tero Kristoa118b5f2008-12-22 14:27:12 +02002083 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002084 struct gpio_bank *bank = &gpio_bank[i];
2085 u32 l1, l2;
2086
Kevin Hilman8865b9b2009-01-27 11:15:34 -08002087 if (bank->dbck_enable_mask)
2088 clk_disable(bank->dbck);
2089
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002090 if (power_state > PWRDM_POWER_OFF)
2091 continue;
2092
2093 /* If going to OFF, remove triggering for all
2094 * non-wakeup GPIOs. Otherwise spurious IRQs will be
2095 * generated. See OMAP2420 Errata item 1.101. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002096 if (!(bank->enabled_non_wakeup_gpios))
2097 continue;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002098
2099 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2100 bank->saved_datain = __raw_readl(bank->base +
2101 OMAP24XX_GPIO_DATAIN);
2102 l1 = __raw_readl(bank->base +
2103 OMAP24XX_GPIO_FALLINGDETECT);
2104 l2 = __raw_readl(bank->base +
2105 OMAP24XX_GPIO_RISINGDETECT);
2106 }
2107
2108 if (cpu_is_omap44xx()) {
2109 bank->saved_datain = __raw_readl(bank->base +
2110 OMAP4_GPIO_DATAIN);
2111 l1 = __raw_readl(bank->base +
2112 OMAP4_GPIO_FALLINGDETECT);
2113 l2 = __raw_readl(bank->base +
2114 OMAP4_GPIO_RISINGDETECT);
2115 }
2116
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002117 bank->saved_fallingdetect = l1;
2118 bank->saved_risingdetect = l2;
2119 l1 &= ~bank->enabled_non_wakeup_gpios;
2120 l2 &= ~bank->enabled_non_wakeup_gpios;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002121
2122 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2123 __raw_writel(l1, bank->base +
2124 OMAP24XX_GPIO_FALLINGDETECT);
2125 __raw_writel(l2, bank->base +
2126 OMAP24XX_GPIO_RISINGDETECT);
2127 }
2128
2129 if (cpu_is_omap44xx()) {
2130 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
2131 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
2132 }
2133
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002134 c++;
2135 }
2136 if (!c) {
2137 workaround_enabled = 0;
2138 return;
2139 }
2140 workaround_enabled = 1;
2141}
2142
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002143void omap2_gpio_resume_after_idle(void)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002144{
2145 int i;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002146 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002147
Tero Kristoa118b5f2008-12-22 14:27:12 +02002148 if (cpu_is_omap34xx())
2149 min = 1;
2150 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002151 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002152 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002153
Kevin Hilman8865b9b2009-01-27 11:15:34 -08002154 if (bank->dbck_enable_mask)
2155 clk_enable(bank->dbck);
2156
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002157 if (!workaround_enabled)
2158 continue;
2159
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002160 if (!(bank->enabled_non_wakeup_gpios))
2161 continue;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002162
2163 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2164 __raw_writel(bank->saved_fallingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002165 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002166 __raw_writel(bank->saved_risingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002167 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002168 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2169 }
2170
2171 if (cpu_is_omap44xx()) {
2172 __raw_writel(bank->saved_fallingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302173 bank->base + OMAP4_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002174 __raw_writel(bank->saved_risingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302175 bank->base + OMAP4_GPIO_RISINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002176 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
2177 }
2178
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002179 /* Check if any of the non-wakeup interrupt GPIOs have changed
2180 * state. If so, generate an IRQ by software. This is
2181 * horribly racy, but it's the best we can do to work around
2182 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002183 l ^= bank->saved_datain;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002184 l &= bank->enabled_non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002185
2186 /*
2187 * No need to generate IRQs for the rising edge for gpio IRQs
2188 * configured with falling edge only; and vice versa.
2189 */
2190 gen0 = l & bank->saved_fallingdetect;
2191 gen0 &= bank->saved_datain;
2192
2193 gen1 = l & bank->saved_risingdetect;
2194 gen1 &= ~(bank->saved_datain);
2195
2196 /* FIXME: Consider GPIO IRQs with level detections properly! */
2197 gen = l & (~(bank->saved_fallingdetect) &
2198 ~(bank->saved_risingdetect));
2199 /* Consider all GPIO IRQs needed to be updated */
2200 gen |= gen0 | gen1;
2201
2202 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002203 u32 old0, old1;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002204
Sergio Aguirref00d6492010-03-03 16:21:08 +00002205 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002206 old0 = __raw_readl(bank->base +
2207 OMAP24XX_GPIO_LEVELDETECT0);
2208 old1 = __raw_readl(bank->base +
2209 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002210 __raw_writel(old0 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002211 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002212 __raw_writel(old1 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002213 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002214 __raw_writel(old0, bank->base +
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002215 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002216 __raw_writel(old1, bank->base +
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002217 OMAP24XX_GPIO_LEVELDETECT1);
2218 }
2219
2220 if (cpu_is_omap44xx()) {
2221 old0 = __raw_readl(bank->base +
2222 OMAP4_GPIO_LEVELDETECT0);
2223 old1 = __raw_readl(bank->base +
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302224 OMAP4_GPIO_LEVELDETECT1);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08002225 __raw_writel(old0 | l, bank->base +
2226 OMAP4_GPIO_LEVELDETECT0);
2227 __raw_writel(old1 | l, bank->base +
2228 OMAP4_GPIO_LEVELDETECT1);
2229 __raw_writel(old0, bank->base +
2230 OMAP4_GPIO_LEVELDETECT0);
2231 __raw_writel(old1, bank->base +
2232 OMAP4_GPIO_LEVELDETECT1);
2233 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002234 }
2235 }
2236
2237}
2238
Tony Lindgren92105bb2005-09-07 17:20:26 +01002239#endif
2240
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002241#ifdef CONFIG_ARCH_OMAP3
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302242/* save the registers of bank 2-6 */
2243void omap_gpio_save_context(void)
2244{
2245 int i;
2246
2247 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2248 for (i = 1; i < gpio_bank_count; i++) {
2249 struct gpio_bank *bank = &gpio_bank[i];
2250 gpio_context[i].sysconfig =
2251 __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG);
2252 gpio_context[i].irqenable1 =
2253 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
2254 gpio_context[i].irqenable2 =
2255 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
2256 gpio_context[i].wake_en =
2257 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
2258 gpio_context[i].ctrl =
2259 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
2260 gpio_context[i].oe =
2261 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
2262 gpio_context[i].leveldetect0 =
2263 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2264 gpio_context[i].leveldetect1 =
2265 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2266 gpio_context[i].risingdetect =
2267 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
2268 gpio_context[i].fallingdetect =
2269 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2270 gpio_context[i].dataout =
2271 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302272 }
2273}
2274
2275/* restore the required registers of bank 2-6 */
2276void omap_gpio_restore_context(void)
2277{
2278 int i;
2279
2280 for (i = 1; i < gpio_bank_count; i++) {
2281 struct gpio_bank *bank = &gpio_bank[i];
2282 __raw_writel(gpio_context[i].sysconfig,
2283 bank->base + OMAP24XX_GPIO_SYSCONFIG);
2284 __raw_writel(gpio_context[i].irqenable1,
2285 bank->base + OMAP24XX_GPIO_IRQENABLE1);
2286 __raw_writel(gpio_context[i].irqenable2,
2287 bank->base + OMAP24XX_GPIO_IRQENABLE2);
2288 __raw_writel(gpio_context[i].wake_en,
2289 bank->base + OMAP24XX_GPIO_WAKE_EN);
2290 __raw_writel(gpio_context[i].ctrl,
2291 bank->base + OMAP24XX_GPIO_CTRL);
2292 __raw_writel(gpio_context[i].oe,
2293 bank->base + OMAP24XX_GPIO_OE);
2294 __raw_writel(gpio_context[i].leveldetect0,
2295 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2296 __raw_writel(gpio_context[i].leveldetect1,
2297 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2298 __raw_writel(gpio_context[i].risingdetect,
2299 bank->base + OMAP24XX_GPIO_RISINGDETECT);
2300 __raw_writel(gpio_context[i].fallingdetect,
2301 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2302 __raw_writel(gpio_context[i].dataout,
2303 bank->base + OMAP24XX_GPIO_DATAOUT);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302304 }
2305}
2306#endif
2307
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002308/*
2309 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002310 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002311 */
David Brownell277d58e2006-12-06 17:13:59 -08002312int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002313{
2314 if (!initialized)
2315 return _omap_gpio_init();
2316 else
2317 return 0;
2318}
2319
Tony Lindgren92105bb2005-09-07 17:20:26 +01002320static int __init omap_gpio_sysinit(void)
2321{
2322 int ret = 0;
2323
2324 if (!initialized)
2325 ret = _omap_gpio_init();
2326
David Brownell11a78b72006-12-06 17:14:11 -08002327 mpuio_init();
2328
Tony Lindgren140455f2010-02-12 12:26:48 -08002329#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002330 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002331 if (ret == 0) {
2332 ret = sysdev_class_register(&omap_gpio_sysclass);
2333 if (ret == 0)
2334 ret = sysdev_register(&omap_gpio_device);
2335 }
2336 }
2337#endif
2338
2339 return ret;
2340}
2341
Tony Lindgren92105bb2005-09-07 17:20:26 +01002342arch_initcall(omap_gpio_sysinit);