blob: 7951eefe1a0e90d634c315882427f94fc9c32faa [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 Lindgren3f1686a2010-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 Lindgren3f1686a2010-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 Lindgren3f1686a2010-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 Lindgren3f1686a2010-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 Lindgren3f1686a2010-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 Lindgren3f1686a2010-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 Lindgren3f1686a2010-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 Lindgren25d6f632010-08-02 14:21:39 +0300393 if (cpu_is_omap2420() && gpio < 128)
394 return 0;
395 if (cpu_is_omap2430() && gpio < 160)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100396 return 0;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700397 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800398 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100399 return -1;
400}
401
402static int check_gpio(int gpio)
403{
Roel Kluind32b20f2009-11-17 14:39:03 -0800404 if (unlikely(gpio_valid(gpio) < 0)) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100405 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
406 dump_stack();
407 return -1;
408 }
409 return 0;
410}
411
412static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
413{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100414 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100415 u32 l;
416
417 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800418#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100419 case METHOD_MPUIO:
420 reg += OMAP_MPUIO_IO_CNTL;
421 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800422#endif
423#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100424 case METHOD_GPIO_1510:
425 reg += OMAP1510_GPIO_DIR_CONTROL;
426 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800427#endif
428#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100429 case METHOD_GPIO_1610:
430 reg += OMAP1610_GPIO_DIRECTION;
431 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800432#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100433#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100434 case METHOD_GPIO_7XX:
435 reg += OMAP7XX_GPIO_DIR_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700436 break;
437#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800438#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100439 case METHOD_GPIO_24XX:
440 reg += OMAP24XX_GPIO_OE;
441 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800442#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530443#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800444 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530445 reg += OMAP4_GPIO_OE;
446 break;
447#endif
David Brownelle5c56ed2006-12-06 17:13:59 -0800448 default:
449 WARN_ON(1);
450 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100451 }
452 l = __raw_readl(reg);
453 if (is_input)
454 l |= 1 << gpio;
455 else
456 l &= ~(1 << gpio);
457 __raw_writel(l, reg);
458}
459
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100460static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
461{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100462 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100463 u32 l = 0;
464
465 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800466#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100467 case METHOD_MPUIO:
468 reg += OMAP_MPUIO_OUTPUT;
469 l = __raw_readl(reg);
470 if (enable)
471 l |= 1 << gpio;
472 else
473 l &= ~(1 << gpio);
474 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800475#endif
476#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100477 case METHOD_GPIO_1510:
478 reg += OMAP1510_GPIO_DATA_OUTPUT;
479 l = __raw_readl(reg);
480 if (enable)
481 l |= 1 << gpio;
482 else
483 l &= ~(1 << gpio);
484 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800485#endif
486#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100487 case METHOD_GPIO_1610:
488 if (enable)
489 reg += OMAP1610_GPIO_SET_DATAOUT;
490 else
491 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
492 l = 1 << gpio;
493 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800494#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100495#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100496 case METHOD_GPIO_7XX:
497 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700498 l = __raw_readl(reg);
499 if (enable)
500 l |= 1 << gpio;
501 else
502 l &= ~(1 << gpio);
503 break;
504#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800505#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100506 case METHOD_GPIO_24XX:
507 if (enable)
508 reg += OMAP24XX_GPIO_SETDATAOUT;
509 else
510 reg += OMAP24XX_GPIO_CLEARDATAOUT;
511 l = 1 << gpio;
512 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800513#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530514#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800515 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530516 if (enable)
517 reg += OMAP4_GPIO_SETDATAOUT;
518 else
519 reg += OMAP4_GPIO_CLEARDATAOUT;
520 l = 1 << gpio;
521 break;
522#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100523 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800524 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100525 return;
526 }
527 __raw_writel(l, reg);
528}
529
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300530static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100531{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100532 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100533
534 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800535 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100536 reg = bank->base;
537 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800538#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100539 case METHOD_MPUIO:
540 reg += OMAP_MPUIO_INPUT_LATCH;
541 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800542#endif
543#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100544 case METHOD_GPIO_1510:
545 reg += OMAP1510_GPIO_DATA_INPUT;
546 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800547#endif
548#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100549 case METHOD_GPIO_1610:
550 reg += OMAP1610_GPIO_DATAIN;
551 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800552#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100553#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100554 case METHOD_GPIO_7XX:
555 reg += OMAP7XX_GPIO_DATA_INPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700556 break;
557#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800558#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100559 case METHOD_GPIO_24XX:
560 reg += OMAP24XX_GPIO_DATAIN;
561 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800562#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530563#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800564 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530565 reg += OMAP4_GPIO_DATAIN;
566 break;
567#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100568 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800569 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100570 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100571 return (__raw_readl(reg)
572 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100573}
574
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300575static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
576{
577 void __iomem *reg;
578
579 if (check_gpio(gpio) < 0)
580 return -EINVAL;
581 reg = bank->base;
582
583 switch (bank->method) {
584#ifdef CONFIG_ARCH_OMAP1
585 case METHOD_MPUIO:
586 reg += OMAP_MPUIO_OUTPUT;
587 break;
588#endif
589#ifdef CONFIG_ARCH_OMAP15XX
590 case METHOD_GPIO_1510:
591 reg += OMAP1510_GPIO_DATA_OUTPUT;
592 break;
593#endif
594#ifdef CONFIG_ARCH_OMAP16XX
595 case METHOD_GPIO_1610:
596 reg += OMAP1610_GPIO_DATAOUT;
597 break;
598#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100599#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100600 case METHOD_GPIO_7XX:
601 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300602 break;
603#endif
Charulatha V9f096862010-05-14 12:05:27 -0700604#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300605 case METHOD_GPIO_24XX:
606 reg += OMAP24XX_GPIO_DATAOUT;
607 break;
608#endif
Charulatha V9f096862010-05-14 12:05:27 -0700609#ifdef CONFIG_ARCH_OMAP4
610 case METHOD_GPIO_44XX:
611 reg += OMAP4_GPIO_DATAOUT;
612 break;
613#endif
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300614 default:
615 return -EINVAL;
616 }
617
618 return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
619}
620
Tony Lindgren92105bb2005-09-07 17:20:26 +0100621#define MOD_REG_BIT(reg, bit_mask, set) \
622do { \
623 int l = __raw_readl(base + reg); \
624 if (set) l |= bit_mask; \
625 else l &= ~bit_mask; \
626 __raw_writel(l, base + reg); \
627} while(0)
628
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700629/**
630 * _set_gpio_debounce - low level gpio debounce time
631 * @bank: the gpio bank we're acting upon
632 * @gpio: the gpio number on this @gpio
633 * @debounce: debounce time to use
634 *
635 * OMAP's debounce time is in 31us steps so we need
636 * to convert and round up to the closest unit.
637 */
638static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
639 unsigned debounce)
640{
641 void __iomem *reg = bank->base;
642 u32 val;
643 u32 l;
644
645 if (debounce < 32)
646 debounce = 0x01;
647 else if (debounce > 7936)
648 debounce = 0xff;
649 else
650 debounce = (debounce / 0x1f) - 1;
651
652 l = 1 << get_gpio_index(gpio);
653
654 if (cpu_is_omap44xx())
655 reg += OMAP4_GPIO_DEBOUNCINGTIME;
656 else
657 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
658
659 __raw_writel(debounce, reg);
660
661 reg = bank->base;
662 if (cpu_is_omap44xx())
663 reg += OMAP4_GPIO_DEBOUNCENABLE;
664 else
665 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
666
667 val = __raw_readl(reg);
668
669 if (debounce) {
670 val |= l;
671 if (cpu_is_omap34xx() || cpu_is_omap44xx())
672 clk_enable(bank->dbck);
673 } else {
674 val &= ~l;
675 if (cpu_is_omap34xx() || cpu_is_omap44xx())
676 clk_disable(bank->dbck);
677 }
Kevin Hilmanf7ec0b02010-06-09 13:53:07 +0300678 bank->dbck_enable_mask = val;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700679
680 __raw_writel(val, reg);
681}
682
Tony Lindgren140455f2010-02-12 12:26:48 -0800683#ifdef CONFIG_ARCH_OMAP2PLUS
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700684static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
685 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100686{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800687 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100688 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530689 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100690
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530691 if (cpu_is_omap44xx()) {
692 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
693 trigger & IRQ_TYPE_LEVEL_LOW);
694 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
695 trigger & IRQ_TYPE_LEVEL_HIGH);
696 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
697 trigger & IRQ_TYPE_EDGE_RISING);
698 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
699 trigger & IRQ_TYPE_EDGE_FALLING);
700 } else {
701 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
702 trigger & IRQ_TYPE_LEVEL_LOW);
703 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
704 trigger & IRQ_TYPE_LEVEL_HIGH);
705 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
706 trigger & IRQ_TYPE_EDGE_RISING);
707 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
708 trigger & IRQ_TYPE_EDGE_FALLING);
709 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800710 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530711 if (cpu_is_omap44xx()) {
712 if (trigger != 0)
713 __raw_writel(1 << gpio, bank->base+
714 OMAP4_GPIO_IRQWAKEN0);
715 else {
716 val = __raw_readl(bank->base +
717 OMAP4_GPIO_IRQWAKEN0);
718 __raw_writel(val & (~(1 << gpio)), bank->base +
719 OMAP4_GPIO_IRQWAKEN0);
720 }
721 } else {
Chunqiu Wang699117a2009-06-24 17:13:39 +0000722 /*
723 * GPIO wakeup request can only be generated on edge
724 * transitions
725 */
726 if (trigger & IRQ_TYPE_EDGE_BOTH)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530727 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700728 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530729 else
730 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700731 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530732 }
Tero Kristoa118b5f2008-12-22 14:27:12 +0200733 }
734 /* This part needs to be executed always for OMAP34xx */
735 if (cpu_is_omap34xx() || (bank->non_wakeup_gpios & gpio_bit)) {
Chunqiu Wang699117a2009-06-24 17:13:39 +0000736 /*
737 * Log the edge gpio and manually trigger the IRQ
738 * after resume if the input level changes
739 * to avoid irq lost during PER RET/OFF mode
740 * Applies for omap2 non-wakeup gpio and all omap3 gpios
741 */
742 if (trigger & IRQ_TYPE_EDGE_BOTH)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800743 bank->enabled_non_wakeup_gpios |= gpio_bit;
744 else
745 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
746 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700747
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530748 if (cpu_is_omap44xx()) {
749 bank->level_mask =
750 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
751 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
752 } else {
753 bank->level_mask =
754 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
755 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
756 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100757}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800758#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100759
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800760#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800761/*
762 * This only applies to chips that can't do both rising and falling edge
763 * detection at once. For all other chips, this function is a noop.
764 */
765static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
766{
767 void __iomem *reg = bank->base;
768 u32 l = 0;
769
770 switch (bank->method) {
Cory Maccarrone4318f362010-01-08 10:29:04 -0800771 case METHOD_MPUIO:
772 reg += OMAP_MPUIO_GPIO_INT_EDGE;
773 break;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800774#ifdef CONFIG_ARCH_OMAP15XX
775 case METHOD_GPIO_1510:
776 reg += OMAP1510_GPIO_INT_CONTROL;
777 break;
778#endif
779#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
780 case METHOD_GPIO_7XX:
781 reg += OMAP7XX_GPIO_INT_CONTROL;
782 break;
783#endif
784 default:
785 return;
786 }
787
788 l = __raw_readl(reg);
789 if ((l >> gpio) & 1)
790 l &= ~(1 << gpio);
791 else
792 l |= 1 << gpio;
793
794 __raw_writel(l, reg);
795}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800796#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800797
Tony Lindgren92105bb2005-09-07 17:20:26 +0100798static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
799{
800 void __iomem *reg = bank->base;
801 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100802
803 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800804#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100805 case METHOD_MPUIO:
806 reg += OMAP_MPUIO_GPIO_INT_EDGE;
807 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000808 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800809 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100810 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100811 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100812 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100813 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100814 else
815 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100816 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800817#endif
818#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100819 case METHOD_GPIO_1510:
820 reg += OMAP1510_GPIO_INT_CONTROL;
821 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000822 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800823 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100824 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100825 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100826 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100827 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100828 else
829 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100830 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800831#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800832#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100833 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100834 if (gpio & 0x08)
835 reg += OMAP1610_GPIO_EDGE_CTRL2;
836 else
837 reg += OMAP1610_GPIO_EDGE_CTRL1;
838 gpio &= 0x07;
839 l = __raw_readl(reg);
840 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100841 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100842 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100843 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100844 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800845 if (trigger)
846 /* Enable wake-up during idle for dynamic tick */
847 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
848 else
849 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100850 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800851#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100852#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100853 case METHOD_GPIO_7XX:
854 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700855 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000856 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800857 bank->toggle_mask |= 1 << gpio;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700858 if (trigger & IRQ_TYPE_EDGE_RISING)
859 l |= 1 << gpio;
860 else if (trigger & IRQ_TYPE_EDGE_FALLING)
861 l &= ~(1 << gpio);
862 else
863 goto bad;
864 break;
865#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800866#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +0100867 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800868 case METHOD_GPIO_44XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800869 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100870 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800871#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100872 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100873 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100874 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100875 __raw_writel(l, reg);
876 return 0;
877bad:
878 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100879}
880
Tony Lindgren92105bb2005-09-07 17:20:26 +0100881static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100882{
883 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100884 unsigned gpio;
885 int retval;
David Brownella6472532008-03-03 04:33:30 -0800886 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100887
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800888 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100889 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
890 else
891 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100892
893 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100894 return -EINVAL;
895
David Brownelle5c56ed2006-12-06 17:13:59 -0800896 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100897 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800898
899 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800900 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800901 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100902 return -EINVAL;
903
David Brownell58781012006-12-06 17:14:10 -0800904 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800905 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100906 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800907 if (retval == 0) {
908 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
909 irq_desc[irq].status |= type;
910 }
David Brownella6472532008-03-03 04:33:30 -0800911 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800912
913 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
914 __set_irq_handler_unlocked(irq, handle_level_irq);
915 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
916 __set_irq_handler_unlocked(irq, handle_edge_irq);
917
Tony Lindgren92105bb2005-09-07 17:20:26 +0100918 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100919}
920
921static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
922{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100923 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100924
925 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800926#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100927 case METHOD_MPUIO:
928 /* MPUIO irqstatus is reset by reading the status register,
929 * so do nothing here */
930 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800931#endif
932#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100933 case METHOD_GPIO_1510:
934 reg += OMAP1510_GPIO_INT_STATUS;
935 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800936#endif
937#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100938 case METHOD_GPIO_1610:
939 reg += OMAP1610_GPIO_IRQSTATUS1;
940 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800941#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100942#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100943 case METHOD_GPIO_7XX:
944 reg += OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700945 break;
946#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800947#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100948 case METHOD_GPIO_24XX:
949 reg += OMAP24XX_GPIO_IRQSTATUS1;
950 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800951#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530952#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800953 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530954 reg += OMAP4_GPIO_IRQSTATUS0;
955 break;
956#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100957 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800958 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100959 return;
960 }
961 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300962
963 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800964 if (cpu_is_omap24xx() || cpu_is_omap34xx())
965 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
966 else if (cpu_is_omap44xx())
967 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
968
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530969 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700970 __raw_writel(gpio_mask, reg);
971
972 /* Flush posted write for the irq status to avoid spurious interrupts */
973 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530974 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100975}
976
977static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
978{
979 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
980}
981
Imre Deakea6dedd2006-06-26 16:16:00 -0700982static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
983{
984 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700985 int inv = 0;
986 u32 l;
987 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700988
989 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800990#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700991 case METHOD_MPUIO:
992 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700993 mask = 0xffff;
994 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700995 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800996#endif
997#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700998 case METHOD_GPIO_1510:
999 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -07001000 mask = 0xffff;
1001 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -07001002 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001003#endif
1004#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -07001005 case METHOD_GPIO_1610:
1006 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001007 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001008 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001009#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001010#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001011 case METHOD_GPIO_7XX:
1012 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001013 mask = 0xffffffff;
1014 inv = 1;
1015 break;
1016#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001017#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Imre Deakea6dedd2006-06-26 16:16:00 -07001018 case METHOD_GPIO_24XX:
1019 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001020 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001021 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001022#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301023#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001024 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301025 reg += OMAP4_GPIO_IRQSTATUSSET0;
1026 mask = 0xffffffff;
1027 break;
1028#endif
Imre Deakea6dedd2006-06-26 16:16:00 -07001029 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001030 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -07001031 return 0;
1032 }
1033
Imre Deak99c47702006-06-26 16:16:07 -07001034 l = __raw_readl(reg);
1035 if (inv)
1036 l = ~l;
1037 l &= mask;
1038 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -07001039}
1040
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001041static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
1042{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001043 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001044 u32 l;
1045
1046 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001047#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001048 case METHOD_MPUIO:
1049 reg += OMAP_MPUIO_GPIO_MASKIT;
1050 l = __raw_readl(reg);
1051 if (enable)
1052 l &= ~(gpio_mask);
1053 else
1054 l |= gpio_mask;
1055 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001056#endif
1057#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001058 case METHOD_GPIO_1510:
1059 reg += OMAP1510_GPIO_INT_MASK;
1060 l = __raw_readl(reg);
1061 if (enable)
1062 l &= ~(gpio_mask);
1063 else
1064 l |= gpio_mask;
1065 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001066#endif
1067#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001068 case METHOD_GPIO_1610:
1069 if (enable)
1070 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1071 else
1072 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1073 l = gpio_mask;
1074 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001075#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001076#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001077 case METHOD_GPIO_7XX:
1078 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001079 l = __raw_readl(reg);
1080 if (enable)
1081 l &= ~(gpio_mask);
1082 else
1083 l |= gpio_mask;
1084 break;
1085#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001086#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001087 case METHOD_GPIO_24XX:
1088 if (enable)
1089 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1090 else
1091 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1092 l = gpio_mask;
1093 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001094#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301095#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001096 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301097 if (enable)
1098 reg += OMAP4_GPIO_IRQSTATUSSET0;
1099 else
1100 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1101 l = gpio_mask;
1102 break;
1103#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001104 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001105 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001106 return;
1107 }
1108 __raw_writel(l, reg);
1109}
1110
1111static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1112{
1113 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1114}
1115
Tony Lindgren92105bb2005-09-07 17:20:26 +01001116/*
1117 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1118 * 1510 does not seem to have a wake-up register. If JTAG is connected
1119 * to the target, system will wake up always on GPIO events. While
1120 * system is running all registered GPIO interrupts need to have wake-up
1121 * enabled. When system is suspended, only selected GPIO interrupts need
1122 * to have wake-up enabled.
1123 */
1124static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1125{
Tony Lindgren4cc64202010-01-08 10:29:05 -08001126 unsigned long uninitialized_var(flags);
David Brownella6472532008-03-03 04:33:30 -08001127
Tony Lindgren92105bb2005-09-07 17:20:26 +01001128 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001129#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001130 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001131 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001132 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001133 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001134 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001135 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001136 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001137 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001138 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001139#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001140#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001141 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001142 case METHOD_GPIO_44XX:
David Brownell11a78b72006-12-06 17:14:11 -08001143 if (bank->non_wakeup_gpios & (1 << gpio)) {
1144 printk(KERN_ERR "Unable to modify wakeup on "
1145 "non-wakeup GPIO%d\n",
1146 (bank - gpio_bank) * 32 + gpio);
1147 return -EINVAL;
1148 }
David Brownella6472532008-03-03 04:33:30 -08001149 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001150 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001151 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001152 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001153 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001154 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001155 return 0;
1156#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001157 default:
1158 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1159 bank->method);
1160 return -EINVAL;
1161 }
1162}
1163
Tony Lindgren4196dd62006-09-25 12:41:38 +03001164static void _reset_gpio(struct gpio_bank *bank, int gpio)
1165{
1166 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1167 _set_gpio_irqenable(bank, gpio, 0);
1168 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001169 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001170}
1171
Tony Lindgren92105bb2005-09-07 17:20:26 +01001172/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1173static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1174{
1175 unsigned int gpio = irq - IH_GPIO_BASE;
1176 struct gpio_bank *bank;
1177 int retval;
1178
1179 if (check_gpio(gpio) < 0)
1180 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001181 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001182 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001183
1184 return retval;
1185}
1186
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001187static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001188{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001189 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001190 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001191
David Brownella6472532008-03-03 04:33:30 -08001192 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001193
Tony Lindgren4196dd62006-09-25 12:41:38 +03001194 /* Set trigger to none. You need to enable the desired trigger with
1195 * request_irq() or set_irq_type().
1196 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001197 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001198
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001199#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001200 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001201 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001202
Tony Lindgren92105bb2005-09-07 17:20:26 +01001203 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001204 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001205 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001206 }
1207#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001208 if (!cpu_class_is_omap1()) {
1209 if (!bank->mod_usage) {
Charulatha V9f096862010-05-14 12:05:27 -07001210 void __iomem *reg = bank->base;
Charulatha V058af1e2009-11-22 10:11:25 -08001211 u32 ctrl;
Charulatha V9f096862010-05-14 12:05:27 -07001212
1213 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1214 reg += OMAP24XX_GPIO_CTRL;
1215 else if (cpu_is_omap44xx())
1216 reg += OMAP4_GPIO_CTRL;
1217 ctrl = __raw_readl(reg);
Charulatha V058af1e2009-11-22 10:11:25 -08001218 /* Module is enabled, clocks are not gated */
Charulatha V9f096862010-05-14 12:05:27 -07001219 ctrl &= 0xFFFFFFFE;
1220 __raw_writel(ctrl, reg);
Charulatha V058af1e2009-11-22 10:11:25 -08001221 }
1222 bank->mod_usage |= 1 << offset;
1223 }
David Brownella6472532008-03-03 04:33:30 -08001224 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001225
1226 return 0;
1227}
1228
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001229static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001230{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001231 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001232 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001233
David Brownella6472532008-03-03 04:33:30 -08001234 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001235#ifdef CONFIG_ARCH_OMAP16XX
1236 if (bank->method == METHOD_GPIO_1610) {
1237 /* Disable wake-up during idle for dynamic tick */
1238 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001239 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001240 }
1241#endif
Charulatha V9f096862010-05-14 12:05:27 -07001242#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
1243 if (bank->method == METHOD_GPIO_24XX) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001244 /* Disable wake-up during idle for dynamic tick */
1245 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001246 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001247 }
1248#endif
Charulatha V9f096862010-05-14 12:05:27 -07001249#ifdef CONFIG_ARCH_OMAP4
1250 if (bank->method == METHOD_GPIO_44XX) {
1251 /* Disable wake-up during idle for dynamic tick */
1252 void __iomem *reg = bank->base + OMAP4_GPIO_IRQWAKEN0;
1253 __raw_writel(1 << offset, reg);
1254 }
1255#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001256 if (!cpu_class_is_omap1()) {
1257 bank->mod_usage &= ~(1 << offset);
1258 if (!bank->mod_usage) {
Charulatha V9f096862010-05-14 12:05:27 -07001259 void __iomem *reg = bank->base;
Charulatha V058af1e2009-11-22 10:11:25 -08001260 u32 ctrl;
Charulatha V9f096862010-05-14 12:05:27 -07001261
1262 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1263 reg += OMAP24XX_GPIO_CTRL;
1264 else if (cpu_is_omap44xx())
1265 reg += OMAP4_GPIO_CTRL;
1266 ctrl = __raw_readl(reg);
Charulatha V058af1e2009-11-22 10:11:25 -08001267 /* Module is disabled, clocks are gated */
1268 ctrl |= 1;
Charulatha V9f096862010-05-14 12:05:27 -07001269 __raw_writel(ctrl, reg);
Charulatha V058af1e2009-11-22 10:11:25 -08001270 }
1271 }
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001272 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001273 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001274}
1275
1276/*
1277 * We need to unmask the GPIO bank interrupt as soon as possible to
1278 * avoid missing GPIO interrupts for other lines in the bank.
1279 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1280 * in the bank to avoid missing nested interrupts for a GPIO line.
1281 * If we wait to unmask individual GPIO lines in the bank after the
1282 * line's interrupt handler has been run, we may miss some nested
1283 * interrupts.
1284 */
Russell King10dd5ce2006-11-23 11:41:32 +00001285static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001286{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001287 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001288 u32 isr;
Cory Maccarrone4318f362010-01-08 10:29:04 -08001289 unsigned int gpio_irq, gpio_index;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001290 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001291 u32 retrigger = 0;
1292 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001293
1294 desc->chip->ack(irq);
1295
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001296 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001297#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001298 if (bank->method == METHOD_MPUIO)
1299 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001300#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001301#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001302 if (bank->method == METHOD_GPIO_1510)
1303 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1304#endif
1305#if defined(CONFIG_ARCH_OMAP16XX)
1306 if (bank->method == METHOD_GPIO_1610)
1307 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1308#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001309#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001310 if (bank->method == METHOD_GPIO_7XX)
1311 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001312#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001313#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001314 if (bank->method == METHOD_GPIO_24XX)
1315 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1316#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301317#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001318 if (bank->method == METHOD_GPIO_44XX)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301319 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1320#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001321 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001322 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001323 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001324
Imre Deakea6dedd2006-06-26 16:16:00 -07001325 enabled = _get_gpio_irqbank_mask(bank);
1326 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001327
1328 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1329 isr &= 0x0000ffff;
1330
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001331 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001332 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001333 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001334
1335 /* clear edge sensitive interrupts before handler(s) are
1336 called so that we don't miss any interrupt occurred while
1337 executing them */
1338 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1339 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1340 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1341
1342 /* if there is only edge sensitive GPIO pin interrupts
1343 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001344 if (!level_mask && !unmasked) {
1345 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001346 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001347 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001348
Imre Deakea6dedd2006-06-26 16:16:00 -07001349 isr |= retrigger;
1350 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001351 if (!isr)
1352 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001353
Tony Lindgren92105bb2005-09-07 17:20:26 +01001354 gpio_irq = bank->virtual_irq_start;
1355 for (; isr != 0; isr >>= 1, gpio_irq++) {
Cory Maccarrone4318f362010-01-08 10:29:04 -08001356 gpio_index = get_gpio_index(irq_to_gpio(gpio_irq));
1357
Tony Lindgren92105bb2005-09-07 17:20:26 +01001358 if (!(isr & 1))
1359 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001360
Cory Maccarrone4318f362010-01-08 10:29:04 -08001361#ifdef CONFIG_ARCH_OMAP1
1362 /*
1363 * Some chips can't respond to both rising and falling
1364 * at the same time. If this irq was requested with
1365 * both flags, we need to flip the ICR data for the IRQ
1366 * to respond to the IRQ for the opposite direction.
1367 * This will be indicated in the bank toggle_mask.
1368 */
1369 if (bank->toggle_mask & (1 << gpio_index))
1370 _toggle_gpio_edge_triggering(bank, gpio_index);
1371#endif
1372
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001373 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001374 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001375 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001376 /* if bank has any level sensitive GPIO pin interrupt
1377 configured, we must unmask the bank interrupt only after
1378 handler(s) are executed in order to avoid spurious bank
1379 interrupt */
1380 if (!unmasked)
1381 desc->chip->unmask(irq);
1382
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001383}
1384
Tony Lindgren4196dd62006-09-25 12:41:38 +03001385static void gpio_irq_shutdown(unsigned int irq)
1386{
1387 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001388 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001389
1390 _reset_gpio(bank, gpio);
1391}
1392
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001393static void gpio_ack_irq(unsigned int irq)
1394{
1395 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001396 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001397
1398 _clear_gpio_irqstatus(bank, gpio);
1399}
1400
1401static void gpio_mask_irq(unsigned int irq)
1402{
1403 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001404 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001405
1406 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001407 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001408}
1409
1410static void gpio_unmask_irq(unsigned int irq)
1411{
1412 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001413 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001414 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001415 struct irq_desc *desc = irq_to_desc(irq);
1416 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1417
1418 if (trigger)
1419 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001420
1421 /* For level-triggered GPIOs, the clearing must be done after
1422 * the HW source is cleared, thus after the handler has run */
1423 if (bank->level_mask & irq_mask) {
1424 _set_gpio_irqenable(bank, gpio, 0);
1425 _clear_gpio_irqstatus(bank, gpio);
1426 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001427
Kevin Hilman4de8c752008-01-16 21:56:14 -08001428 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001429}
1430
David Brownelle5c56ed2006-12-06 17:13:59 -08001431static struct irq_chip gpio_irq_chip = {
1432 .name = "GPIO",
1433 .shutdown = gpio_irq_shutdown,
1434 .ack = gpio_ack_irq,
1435 .mask = gpio_mask_irq,
1436 .unmask = gpio_unmask_irq,
1437 .set_type = gpio_irq_type,
1438 .set_wake = gpio_wake_enable,
1439};
1440
1441/*---------------------------------------------------------------------*/
1442
1443#ifdef CONFIG_ARCH_OMAP1
1444
1445/* MPUIO uses the always-on 32k clock */
1446
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001447static void mpuio_ack_irq(unsigned int irq)
1448{
1449 /* The ISR is reset automatically, so do nothing here. */
1450}
1451
1452static void mpuio_mask_irq(unsigned int irq)
1453{
1454 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001455 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001456
1457 _set_gpio_irqenable(bank, gpio, 0);
1458}
1459
1460static void mpuio_unmask_irq(unsigned int irq)
1461{
1462 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001463 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001464
1465 _set_gpio_irqenable(bank, gpio, 1);
1466}
1467
David Brownelle5c56ed2006-12-06 17:13:59 -08001468static struct irq_chip mpuio_irq_chip = {
1469 .name = "MPUIO",
1470 .ack = mpuio_ack_irq,
1471 .mask = mpuio_mask_irq,
1472 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001473 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001474#ifdef CONFIG_ARCH_OMAP16XX
1475 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1476 .set_wake = gpio_wake_enable,
1477#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001478};
1479
David Brownelle5c56ed2006-12-06 17:13:59 -08001480
1481#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1482
David Brownell11a78b72006-12-06 17:14:11 -08001483
1484#ifdef CONFIG_ARCH_OMAP16XX
1485
1486#include <linux/platform_device.h>
1487
Magnus Damm79ee0312009-07-08 13:22:04 +02001488static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001489{
Magnus Damm79ee0312009-07-08 13:22:04 +02001490 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001491 struct gpio_bank *bank = platform_get_drvdata(pdev);
1492 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001493 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001494
David Brownella6472532008-03-03 04:33:30 -08001495 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001496 bank->saved_wakeup = __raw_readl(mask_reg);
1497 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001498 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001499
1500 return 0;
1501}
1502
Magnus Damm79ee0312009-07-08 13:22:04 +02001503static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001504{
Magnus Damm79ee0312009-07-08 13:22:04 +02001505 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001506 struct gpio_bank *bank = platform_get_drvdata(pdev);
1507 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001508 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001509
David Brownella6472532008-03-03 04:33:30 -08001510 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001511 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001512 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001513
1514 return 0;
1515}
1516
Alexey Dobriyan47145212009-12-14 18:00:08 -08001517static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +02001518 .suspend_noirq = omap_mpuio_suspend_noirq,
1519 .resume_noirq = omap_mpuio_resume_noirq,
1520};
1521
David Brownell11a78b72006-12-06 17:14:11 -08001522/* use platform_driver for this, now that there's no longer any
1523 * point to sys_device (other than not disturbing old code).
1524 */
1525static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001526 .driver = {
1527 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001528 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001529 },
1530};
1531
1532static struct platform_device omap_mpuio_device = {
1533 .name = "mpuio",
1534 .id = -1,
1535 .dev = {
1536 .driver = &omap_mpuio_driver.driver,
1537 }
1538 /* could list the /proc/iomem resources */
1539};
1540
1541static inline void mpuio_init(void)
1542{
David Brownellfcf126d2007-04-02 12:46:47 -07001543 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1544
David Brownell11a78b72006-12-06 17:14:11 -08001545 if (platform_driver_register(&omap_mpuio_driver) == 0)
1546 (void) platform_device_register(&omap_mpuio_device);
1547}
1548
1549#else
1550static inline void mpuio_init(void) {}
1551#endif /* 16xx */
1552
David Brownelle5c56ed2006-12-06 17:13:59 -08001553#else
1554
1555extern struct irq_chip mpuio_irq_chip;
1556
1557#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001558static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001559
1560#endif
1561
1562/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001563
David Brownell52e31342008-03-03 12:43:23 -08001564/* REVISIT these are stupid implementations! replace by ones that
1565 * don't switch on METHOD_* and which mostly avoid spinlocks
1566 */
1567
1568static int gpio_input(struct gpio_chip *chip, unsigned offset)
1569{
1570 struct gpio_bank *bank;
1571 unsigned long flags;
1572
1573 bank = container_of(chip, struct gpio_bank, chip);
1574 spin_lock_irqsave(&bank->lock, flags);
1575 _set_gpio_direction(bank, offset, 1);
1576 spin_unlock_irqrestore(&bank->lock, flags);
1577 return 0;
1578}
1579
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001580static int gpio_is_input(struct gpio_bank *bank, int mask)
1581{
1582 void __iomem *reg = bank->base;
1583
1584 switch (bank->method) {
1585 case METHOD_MPUIO:
1586 reg += OMAP_MPUIO_IO_CNTL;
1587 break;
1588 case METHOD_GPIO_1510:
1589 reg += OMAP1510_GPIO_DIR_CONTROL;
1590 break;
1591 case METHOD_GPIO_1610:
1592 reg += OMAP1610_GPIO_DIRECTION;
1593 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001594 case METHOD_GPIO_7XX:
1595 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001596 break;
1597 case METHOD_GPIO_24XX:
1598 reg += OMAP24XX_GPIO_OE;
1599 break;
Charulatha V9f096862010-05-14 12:05:27 -07001600 case METHOD_GPIO_44XX:
1601 reg += OMAP4_GPIO_OE;
1602 break;
1603 default:
1604 WARN_ONCE(1, "gpio_is_input: incorrect OMAP GPIO method");
1605 return -EINVAL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001606 }
1607 return __raw_readl(reg) & mask;
1608}
1609
David Brownell52e31342008-03-03 12:43:23 -08001610static int gpio_get(struct gpio_chip *chip, unsigned offset)
1611{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001612 struct gpio_bank *bank;
1613 void __iomem *reg;
1614 int gpio;
1615 u32 mask;
1616
1617 gpio = chip->base + offset;
1618 bank = get_gpio_bank(gpio);
1619 reg = bank->base;
1620 mask = 1 << get_gpio_index(gpio);
1621
1622 if (gpio_is_input(bank, mask))
1623 return _get_gpio_datain(bank, gpio);
1624 else
1625 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001626}
1627
1628static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1629{
1630 struct gpio_bank *bank;
1631 unsigned long flags;
1632
1633 bank = container_of(chip, struct gpio_bank, chip);
1634 spin_lock_irqsave(&bank->lock, flags);
1635 _set_gpio_dataout(bank, offset, value);
1636 _set_gpio_direction(bank, offset, 0);
1637 spin_unlock_irqrestore(&bank->lock, flags);
1638 return 0;
1639}
1640
Felipe Balbi168ef3d2010-05-26 14:42:23 -07001641static int gpio_debounce(struct gpio_chip *chip, unsigned offset,
1642 unsigned debounce)
1643{
1644 struct gpio_bank *bank;
1645 unsigned long flags;
1646
1647 bank = container_of(chip, struct gpio_bank, chip);
1648 spin_lock_irqsave(&bank->lock, flags);
1649 _set_gpio_debounce(bank, offset, debounce);
1650 spin_unlock_irqrestore(&bank->lock, flags);
1651
1652 return 0;
1653}
1654
David Brownell52e31342008-03-03 12:43:23 -08001655static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1656{
1657 struct gpio_bank *bank;
1658 unsigned long flags;
1659
1660 bank = container_of(chip, struct gpio_bank, chip);
1661 spin_lock_irqsave(&bank->lock, flags);
1662 _set_gpio_dataout(bank, offset, value);
1663 spin_unlock_irqrestore(&bank->lock, flags);
1664}
1665
David Brownella007b702008-12-10 17:35:25 -08001666static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1667{
1668 struct gpio_bank *bank;
1669
1670 bank = container_of(chip, struct gpio_bank, chip);
1671 return bank->virtual_irq_start + offset;
1672}
1673
David Brownell52e31342008-03-03 12:43:23 -08001674/*---------------------------------------------------------------------*/
1675
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001676static int initialized;
Tony Lindgren56213ca2010-02-12 12:26:46 -08001677#if defined(CONFIG_ARCH_OMAP1) || defined(CONFIG_ARCH_OMAP2)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001678static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001679#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001680
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001681#if defined(CONFIG_ARCH_OMAP2)
1682static struct clk * gpio_fck;
1683#endif
1684
1685#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001686static struct clk * gpio5_ick;
1687static struct clk * gpio5_fck;
1688#endif
1689
Santosh Shilimkar44169072009-05-28 14:16:04 -07001690#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001691static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1692#endif
1693
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001694static void __init omap_gpio_show_rev(void)
1695{
1696 u32 rev;
1697
1698 if (cpu_is_omap16xx())
1699 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1700 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1701 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1702 else if (cpu_is_omap44xx())
1703 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1704 else
1705 return;
1706
1707 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1708 (rev >> 4) & 0x0f, rev & 0x0f);
1709}
1710
David Brownell8ba55c52008-02-26 11:10:50 -08001711/* This lock class tells lockdep that GPIO irqs are in a different
1712 * category than their parents, so it won't report false recursion.
1713 */
1714static struct lock_class_key gpio_lock_class;
1715
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001716static int __init _omap_gpio_init(void)
1717{
1718 int i;
David Brownell52e31342008-03-03 12:43:23 -08001719 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001720 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001721 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001722 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001723
1724 initialized = 1;
1725
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001726#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001727 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001728 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1729 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001730 printk("Could not get arm_gpio_ck\n");
1731 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001732 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001733 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001734#endif
1735#if defined(CONFIG_ARCH_OMAP2)
1736 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001737 gpio_ick = clk_get(NULL, "gpios_ick");
1738 if (IS_ERR(gpio_ick))
1739 printk("Could not get gpios_ick\n");
1740 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001741 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001742 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001743 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001744 printk("Could not get gpios_fck\n");
1745 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001746 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001747
1748 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001749 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001750 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001751#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001752 if (cpu_is_omap2430()) {
1753 gpio5_ick = clk_get(NULL, "gpio5_ick");
1754 if (IS_ERR(gpio5_ick))
1755 printk("Could not get gpio5_ick\n");
1756 else
1757 clk_enable(gpio5_ick);
1758 gpio5_fck = clk_get(NULL, "gpio5_fck");
1759 if (IS_ERR(gpio5_fck))
1760 printk("Could not get gpio5_fck\n");
1761 else
1762 clk_enable(gpio5_fck);
1763 }
1764#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001765 }
1766#endif
1767
Santosh Shilimkar44169072009-05-28 14:16:04 -07001768#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1769 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001770 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1771 sprintf(clk_name, "gpio%d_ick", i + 1);
1772 gpio_iclks[i] = clk_get(NULL, clk_name);
1773 if (IS_ERR(gpio_iclks[i]))
1774 printk(KERN_ERR "Could not get %s\n", clk_name);
1775 else
1776 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001777 }
1778 }
1779#endif
1780
Tony Lindgren92105bb2005-09-07 17:20:26 +01001781
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001782#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001783 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001784 gpio_bank_count = 2;
1785 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001786 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001787 }
1788#endif
1789#if defined(CONFIG_ARCH_OMAP16XX)
1790 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001791 gpio_bank_count = 5;
1792 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001793 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001794 }
1795#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001796#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1797 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001798 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001799 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001800 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001801 }
1802#endif
Tony Lindgren088ef952010-02-12 12:26:47 -08001803#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001804 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001805 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001806 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001807 }
1808 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001809 gpio_bank_count = 5;
1810 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001811 }
1812#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001813#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001814 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001815 gpio_bank_count = OMAP34XX_NR_GPIOS;
1816 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001817 }
1818#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001819#ifdef CONFIG_ARCH_OMAP4
1820 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001821 gpio_bank_count = OMAP34XX_NR_GPIOS;
1822 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001823 }
1824#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001825 for (i = 0; i < gpio_bank_count; i++) {
1826 int j, gpio_count = 16;
1827
1828 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001829 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001830
1831 /* Static mapping, never released */
1832 bank->base = ioremap(bank->pbase, bank_size);
1833 if (!bank->base) {
1834 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1835 continue;
1836 }
1837
David Brownelle5c56ed2006-12-06 17:13:59 -08001838 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001839 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001840 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001841 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1842 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1843 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001844 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001845 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1846 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001847 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001848 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001849 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1850 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1851 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001852
Alistair Buxton7c006922009-09-22 10:02:58 +01001853 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001854 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001855
Tony Lindgren140455f2010-02-12 12:26:48 -08001856#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001857 if ((bank->method == METHOD_GPIO_24XX) ||
1858 (bank->method == METHOD_GPIO_44XX)) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001859 static const u32 non_wakeup_gpios[] = {
1860 0xe203ffc0, 0x08700040
1861 };
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001862
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001863 if (cpu_is_omap44xx()) {
1864 __raw_writel(0xffffffff, bank->base +
1865 OMAP4_GPIO_IRQSTATUSCLR0);
1866 __raw_writew(0x0015, bank->base +
1867 OMAP4_GPIO_SYSCONFIG);
1868 __raw_writel(0x00000000, bank->base +
1869 OMAP4_GPIO_DEBOUNCENABLE);
1870 /*
1871 * Initialize interface clock ungated,
1872 * module enabled
1873 */
1874 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1875 } else {
1876 __raw_writel(0x00000000, bank->base +
1877 OMAP24XX_GPIO_IRQENABLE1);
1878 __raw_writel(0xffffffff, bank->base +
1879 OMAP24XX_GPIO_IRQSTATUS1);
1880 __raw_writew(0x0015, bank->base +
1881 OMAP24XX_GPIO_SYSCONFIG);
1882 __raw_writel(0x00000000, bank->base +
1883 OMAP24XX_GPIO_DEBOUNCE_EN);
1884
1885 /*
1886 * Initialize interface clock ungated,
1887 * module enabled
1888 */
1889 __raw_writel(0, bank->base +
1890 OMAP24XX_GPIO_CTRL);
1891 }
Tero Kristoa118b5f2008-12-22 14:27:12 +02001892 if (cpu_is_omap24xx() &&
1893 i < ARRAY_SIZE(non_wakeup_gpios))
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001894 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001895 gpio_count = 32;
1896 }
1897#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001898
1899 bank->mod_usage = 0;
David Brownell52e31342008-03-03 12:43:23 -08001900 /* REVISIT eventually switch from OMAP-specific gpio structs
1901 * over to the generic ones
1902 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001903 bank->chip.request = omap_gpio_request;
1904 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001905 bank->chip.direction_input = gpio_input;
1906 bank->chip.get = gpio_get;
1907 bank->chip.direction_output = gpio_output;
Felipe Balbi168ef3d2010-05-26 14:42:23 -07001908 bank->chip.set_debounce = gpio_debounce;
David Brownell52e31342008-03-03 12:43:23 -08001909 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001910 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001911 if (bank_is_mpuio(bank)) {
1912 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001913#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001914 bank->chip.dev = &omap_mpuio_device.dev;
1915#endif
David Brownell52e31342008-03-03 12:43:23 -08001916 bank->chip.base = OMAP_MPUIO(0);
1917 } else {
1918 bank->chip.label = "gpio";
1919 bank->chip.base = gpio;
1920 gpio += gpio_count;
1921 }
1922 bank->chip.ngpio = gpio_count;
1923
1924 gpiochip_add(&bank->chip);
1925
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001926 for (j = bank->virtual_irq_start;
1927 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001928 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001929 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001930 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001931 set_irq_chip(j, &mpuio_irq_chip);
1932 else
1933 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001934 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001935 set_irq_flags(j, IRQF_VALID);
1936 }
1937 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1938 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001939
Santosh Shilimkar44169072009-05-28 14:16:04 -07001940 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001941 sprintf(clk_name, "gpio%d_dbck", i + 1);
1942 bank->dbck = clk_get(NULL, clk_name);
1943 if (IS_ERR(bank->dbck))
1944 printk(KERN_ERR "Could not get %s\n", clk_name);
1945 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001946 }
1947
1948 /* Enable system clock for GPIO module.
1949 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001950 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001951 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1952
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001953 /* Enable autoidle for the OCP interface */
1954 if (cpu_is_omap24xx())
1955 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001956 if (cpu_is_omap34xx())
1957 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001958
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001959 omap_gpio_show_rev();
1960
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001961 return 0;
1962}
1963
Tony Lindgren140455f2010-02-12 12:26:48 -08001964#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001965static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1966{
1967 int i;
1968
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001969 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001970 return 0;
1971
1972 for (i = 0; i < gpio_bank_count; i++) {
1973 struct gpio_bank *bank = &gpio_bank[i];
1974 void __iomem *wake_status;
1975 void __iomem *wake_clear;
1976 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001977 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001978
1979 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001980#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001981 case METHOD_GPIO_1610:
1982 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1983 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1984 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1985 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001986#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001987#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001988 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001989 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001990 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1991 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1992 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001993#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301994#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001995 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301996 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1997 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1998 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1999 break;
2000#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01002001 default:
2002 continue;
2003 }
2004
David Brownella6472532008-03-03 04:33:30 -08002005 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002006 bank->saved_wakeup = __raw_readl(wake_status);
2007 __raw_writel(0xffffffff, wake_clear);
2008 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08002009 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002010 }
2011
2012 return 0;
2013}
2014
2015static int omap_gpio_resume(struct sys_device *dev)
2016{
2017 int i;
2018
Tero Kristo723fdb72008-11-26 14:35:16 -08002019 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01002020 return 0;
2021
2022 for (i = 0; i < gpio_bank_count; i++) {
2023 struct gpio_bank *bank = &gpio_bank[i];
2024 void __iomem *wake_clear;
2025 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08002026 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01002027
2028 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08002029#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01002030 case METHOD_GPIO_1610:
2031 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
2032 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
2033 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08002034#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002035#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01002036 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03002037 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
2038 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01002039 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08002040#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302041#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002042 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302043 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
2044 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
2045 break;
2046#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01002047 default:
2048 continue;
2049 }
2050
David Brownella6472532008-03-03 04:33:30 -08002051 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002052 __raw_writel(0xffffffff, wake_clear);
2053 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08002054 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002055 }
2056
2057 return 0;
2058}
2059
2060static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01002061 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01002062 .suspend = omap_gpio_suspend,
2063 .resume = omap_gpio_resume,
2064};
2065
2066static struct sys_device omap_gpio_device = {
2067 .id = 0,
2068 .cls = &omap_gpio_sysclass,
2069};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002070
2071#endif
2072
Tony Lindgren140455f2010-02-12 12:26:48 -08002073#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002074
2075static int workaround_enabled;
2076
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002077void omap2_gpio_prepare_for_idle(int power_state)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002078{
2079 int i, c = 0;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002080 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002081
Tero Kristoa118b5f2008-12-22 14:27:12 +02002082 if (cpu_is_omap34xx())
2083 min = 1;
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002084
Tero Kristoa118b5f2008-12-22 14:27:12 +02002085 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002086 struct gpio_bank *bank = &gpio_bank[i];
2087 u32 l1, l2;
2088
Kevin Hilman8865b9b2009-01-27 11:15:34 -08002089 if (bank->dbck_enable_mask)
2090 clk_disable(bank->dbck);
2091
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002092 if (power_state > PWRDM_POWER_OFF)
2093 continue;
2094
2095 /* If going to OFF, remove triggering for all
2096 * non-wakeup GPIOs. Otherwise spurious IRQs will be
2097 * generated. See OMAP2420 Errata item 1.101. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002098 if (!(bank->enabled_non_wakeup_gpios))
2099 continue;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002100
2101 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2102 bank->saved_datain = __raw_readl(bank->base +
2103 OMAP24XX_GPIO_DATAIN);
2104 l1 = __raw_readl(bank->base +
2105 OMAP24XX_GPIO_FALLINGDETECT);
2106 l2 = __raw_readl(bank->base +
2107 OMAP24XX_GPIO_RISINGDETECT);
2108 }
2109
2110 if (cpu_is_omap44xx()) {
2111 bank->saved_datain = __raw_readl(bank->base +
2112 OMAP4_GPIO_DATAIN);
2113 l1 = __raw_readl(bank->base +
2114 OMAP4_GPIO_FALLINGDETECT);
2115 l2 = __raw_readl(bank->base +
2116 OMAP4_GPIO_RISINGDETECT);
2117 }
2118
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002119 bank->saved_fallingdetect = l1;
2120 bank->saved_risingdetect = l2;
2121 l1 &= ~bank->enabled_non_wakeup_gpios;
2122 l2 &= ~bank->enabled_non_wakeup_gpios;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002123
2124 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2125 __raw_writel(l1, bank->base +
2126 OMAP24XX_GPIO_FALLINGDETECT);
2127 __raw_writel(l2, bank->base +
2128 OMAP24XX_GPIO_RISINGDETECT);
2129 }
2130
2131 if (cpu_is_omap44xx()) {
2132 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
2133 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
2134 }
2135
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002136 c++;
2137 }
2138 if (!c) {
2139 workaround_enabled = 0;
2140 return;
2141 }
2142 workaround_enabled = 1;
2143}
2144
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002145void omap2_gpio_resume_after_idle(void)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002146{
2147 int i;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002148 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002149
Tero Kristoa118b5f2008-12-22 14:27:12 +02002150 if (cpu_is_omap34xx())
2151 min = 1;
2152 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002153 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002154 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002155
Kevin Hilman8865b9b2009-01-27 11:15:34 -08002156 if (bank->dbck_enable_mask)
2157 clk_enable(bank->dbck);
2158
Kevin Hilman43ffcd92009-01-27 11:09:24 -08002159 if (!workaround_enabled)
2160 continue;
2161
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002162 if (!(bank->enabled_non_wakeup_gpios))
2163 continue;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002164
2165 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2166 __raw_writel(bank->saved_fallingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002167 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002168 __raw_writel(bank->saved_risingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002169 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002170 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2171 }
2172
2173 if (cpu_is_omap44xx()) {
2174 __raw_writel(bank->saved_fallingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302175 bank->base + OMAP4_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002176 __raw_writel(bank->saved_risingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302177 bank->base + OMAP4_GPIO_RISINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002178 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
2179 }
2180
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002181 /* Check if any of the non-wakeup interrupt GPIOs have changed
2182 * state. If so, generate an IRQ by software. This is
2183 * horribly racy, but it's the best we can do to work around
2184 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002185 l ^= bank->saved_datain;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002186 l &= bank->enabled_non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002187
2188 /*
2189 * No need to generate IRQs for the rising edge for gpio IRQs
2190 * configured with falling edge only; and vice versa.
2191 */
2192 gen0 = l & bank->saved_fallingdetect;
2193 gen0 &= bank->saved_datain;
2194
2195 gen1 = l & bank->saved_risingdetect;
2196 gen1 &= ~(bank->saved_datain);
2197
2198 /* FIXME: Consider GPIO IRQs with level detections properly! */
2199 gen = l & (~(bank->saved_fallingdetect) &
2200 ~(bank->saved_risingdetect));
2201 /* Consider all GPIO IRQs needed to be updated */
2202 gen |= gen0 | gen1;
2203
2204 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002205 u32 old0, old1;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002206
Sergio Aguirref00d6492010-03-03 16:21:08 +00002207 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002208 old0 = __raw_readl(bank->base +
2209 OMAP24XX_GPIO_LEVELDETECT0);
2210 old1 = __raw_readl(bank->base +
2211 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002212 __raw_writel(old0 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002213 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002214 __raw_writel(old1 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002215 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002216 __raw_writel(old0, bank->base +
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002217 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002218 __raw_writel(old1, bank->base +
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002219 OMAP24XX_GPIO_LEVELDETECT1);
2220 }
2221
2222 if (cpu_is_omap44xx()) {
2223 old0 = __raw_readl(bank->base +
2224 OMAP4_GPIO_LEVELDETECT0);
2225 old1 = __raw_readl(bank->base +
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302226 OMAP4_GPIO_LEVELDETECT1);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002227 __raw_writel(old0 | l, bank->base +
2228 OMAP4_GPIO_LEVELDETECT0);
2229 __raw_writel(old1 | l, bank->base +
2230 OMAP4_GPIO_LEVELDETECT1);
2231 __raw_writel(old0, bank->base +
2232 OMAP4_GPIO_LEVELDETECT0);
2233 __raw_writel(old1, bank->base +
2234 OMAP4_GPIO_LEVELDETECT1);
2235 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002236 }
2237 }
2238
2239}
2240
Tony Lindgren92105bb2005-09-07 17:20:26 +01002241#endif
2242
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002243#ifdef CONFIG_ARCH_OMAP3
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302244/* save the registers of bank 2-6 */
2245void omap_gpio_save_context(void)
2246{
2247 int i;
2248
2249 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2250 for (i = 1; i < gpio_bank_count; i++) {
2251 struct gpio_bank *bank = &gpio_bank[i];
2252 gpio_context[i].sysconfig =
2253 __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG);
2254 gpio_context[i].irqenable1 =
2255 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
2256 gpio_context[i].irqenable2 =
2257 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
2258 gpio_context[i].wake_en =
2259 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
2260 gpio_context[i].ctrl =
2261 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
2262 gpio_context[i].oe =
2263 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
2264 gpio_context[i].leveldetect0 =
2265 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2266 gpio_context[i].leveldetect1 =
2267 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2268 gpio_context[i].risingdetect =
2269 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
2270 gpio_context[i].fallingdetect =
2271 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2272 gpio_context[i].dataout =
2273 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302274 }
2275}
2276
2277/* restore the required registers of bank 2-6 */
2278void omap_gpio_restore_context(void)
2279{
2280 int i;
2281
2282 for (i = 1; i < gpio_bank_count; i++) {
2283 struct gpio_bank *bank = &gpio_bank[i];
2284 __raw_writel(gpio_context[i].sysconfig,
2285 bank->base + OMAP24XX_GPIO_SYSCONFIG);
2286 __raw_writel(gpio_context[i].irqenable1,
2287 bank->base + OMAP24XX_GPIO_IRQENABLE1);
2288 __raw_writel(gpio_context[i].irqenable2,
2289 bank->base + OMAP24XX_GPIO_IRQENABLE2);
2290 __raw_writel(gpio_context[i].wake_en,
2291 bank->base + OMAP24XX_GPIO_WAKE_EN);
2292 __raw_writel(gpio_context[i].ctrl,
2293 bank->base + OMAP24XX_GPIO_CTRL);
2294 __raw_writel(gpio_context[i].oe,
2295 bank->base + OMAP24XX_GPIO_OE);
2296 __raw_writel(gpio_context[i].leveldetect0,
2297 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2298 __raw_writel(gpio_context[i].leveldetect1,
2299 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2300 __raw_writel(gpio_context[i].risingdetect,
2301 bank->base + OMAP24XX_GPIO_RISINGDETECT);
2302 __raw_writel(gpio_context[i].fallingdetect,
2303 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2304 __raw_writel(gpio_context[i].dataout,
2305 bank->base + OMAP24XX_GPIO_DATAOUT);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302306 }
2307}
2308#endif
2309
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002310/*
2311 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002312 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002313 */
David Brownell277d58e2006-12-06 17:13:59 -08002314int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002315{
2316 if (!initialized)
2317 return _omap_gpio_init();
2318 else
2319 return 0;
2320}
2321
Tony Lindgren92105bb2005-09-07 17:20:26 +01002322static int __init omap_gpio_sysinit(void)
2323{
2324 int ret = 0;
2325
2326 if (!initialized)
2327 ret = _omap_gpio_init();
2328
David Brownell11a78b72006-12-06 17:14:11 -08002329 mpuio_init();
2330
Tony Lindgren140455f2010-02-12 12:26:48 -08002331#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002332 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002333 if (ret == 0) {
2334 ret = sysdev_class_register(&omap_gpio_sysclass);
2335 if (ret == 0)
2336 ret = sysdev_register(&omap_gpio_device);
2337 }
2338 }
2339#endif
2340
2341 return ret;
2342}
2343
Tony Lindgren92105bb2005-09-07 17:20:26 +01002344arch_initcall(omap_gpio_sysinit);