blob: a888304b838355307040ccb8c49c57ffabf4744c [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
2 * linux/arch/arm/plat-omap/gpio.c
3 *
4 * Support functions for OMAP GPIO
5 *
Tony Lindgren92105bb2005-09-07 17:20:26 +01006 * Copyright (C) 2003-2005 Nokia Corporation
Jan Engelhardt96de0e22007-10-19 23:21:04 +02007 * Written by Juha Yrjölä <juha.yrjola@nokia.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01008 *
Santosh Shilimkar44169072009-05-28 14:16:04 -07009 * Copyright (C) 2009 Texas Instruments
10 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
11 *
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010017#include <linux/init.h>
18#include <linux/module.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010019#include <linux/interrupt.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010020#include <linux/sysdev.h>
21#include <linux/err.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000022#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010024
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010026#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/irqs.h>
28#include <mach/gpio.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010029#include <asm/mach/irq.h>
30
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010031/*
32 * OMAP1510 GPIO registers
33 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070034#define OMAP1510_GPIO_BASE 0xfffce000
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010035#define OMAP1510_GPIO_DATA_INPUT 0x00
36#define OMAP1510_GPIO_DATA_OUTPUT 0x04
37#define OMAP1510_GPIO_DIR_CONTROL 0x08
38#define OMAP1510_GPIO_INT_CONTROL 0x0c
39#define OMAP1510_GPIO_INT_MASK 0x10
40#define OMAP1510_GPIO_INT_STATUS 0x14
41#define OMAP1510_GPIO_PIN_CONTROL 0x18
42
43#define OMAP1510_IH_GPIO_BASE 64
44
45/*
46 * OMAP1610 specific GPIO registers
47 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070048#define OMAP1610_GPIO1_BASE 0xfffbe400
49#define OMAP1610_GPIO2_BASE 0xfffbec00
50#define OMAP1610_GPIO3_BASE 0xfffbb400
51#define OMAP1610_GPIO4_BASE 0xfffbbc00
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010052#define OMAP1610_GPIO_REVISION 0x0000
53#define OMAP1610_GPIO_SYSCONFIG 0x0010
54#define OMAP1610_GPIO_SYSSTATUS 0x0014
55#define OMAP1610_GPIO_IRQSTATUS1 0x0018
56#define OMAP1610_GPIO_IRQENABLE1 0x001c
Tony Lindgren92105bb2005-09-07 17:20:26 +010057#define OMAP1610_GPIO_WAKEUPENABLE 0x0028
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010058#define OMAP1610_GPIO_DATAIN 0x002c
59#define OMAP1610_GPIO_DATAOUT 0x0030
60#define OMAP1610_GPIO_DIRECTION 0x0034
61#define OMAP1610_GPIO_EDGE_CTRL1 0x0038
62#define OMAP1610_GPIO_EDGE_CTRL2 0x003c
63#define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
Tony Lindgren92105bb2005-09-07 17:20:26 +010064#define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010065#define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
66#define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
Tony Lindgren92105bb2005-09-07 17:20:26 +010067#define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010068#define OMAP1610_GPIO_SET_DATAOUT 0x00f0
69
70/*
Alistair Buxton7c006922009-09-22 10:02:58 +010071 * OMAP7XX specific GPIO registers
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010072 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070073#define OMAP7XX_GPIO1_BASE 0xfffbc000
74#define OMAP7XX_GPIO2_BASE 0xfffbc800
75#define OMAP7XX_GPIO3_BASE 0xfffbd000
76#define OMAP7XX_GPIO4_BASE 0xfffbd800
77#define OMAP7XX_GPIO5_BASE 0xfffbe000
78#define OMAP7XX_GPIO6_BASE 0xfffbe800
Alistair Buxton7c006922009-09-22 10:02:58 +010079#define OMAP7XX_GPIO_DATA_INPUT 0x00
80#define OMAP7XX_GPIO_DATA_OUTPUT 0x04
81#define OMAP7XX_GPIO_DIR_CONTROL 0x08
82#define OMAP7XX_GPIO_INT_CONTROL 0x0c
83#define OMAP7XX_GPIO_INT_MASK 0x10
84#define OMAP7XX_GPIO_INT_STATUS 0x14
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010085
Tony Lindgren9f7065d2009-10-19 15:25:20 -070086#define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
Tony Lindgren94113262009-08-28 10:50:33 -070087
Zebediah C. McClure56739a62009-03-23 18:07:40 -070088/*
Tony Lindgren92105bb2005-09-07 17:20:26 +010089 * omap24xx specific GPIO registers
90 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070091#define OMAP242X_GPIO1_BASE 0x48018000
92#define OMAP242X_GPIO2_BASE 0x4801a000
93#define OMAP242X_GPIO3_BASE 0x4801c000
94#define OMAP242X_GPIO4_BASE 0x4801e000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -080095
Tony Lindgren9f7065d2009-10-19 15:25:20 -070096#define OMAP243X_GPIO1_BASE 0x4900C000
97#define OMAP243X_GPIO2_BASE 0x4900E000
98#define OMAP243X_GPIO3_BASE 0x49010000
99#define OMAP243X_GPIO4_BASE 0x49012000
100#define OMAP243X_GPIO5_BASE 0x480B6000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800101
Tony Lindgren92105bb2005-09-07 17:20:26 +0100102#define OMAP24XX_GPIO_REVISION 0x0000
103#define OMAP24XX_GPIO_SYSCONFIG 0x0010
104#define OMAP24XX_GPIO_SYSSTATUS 0x0014
105#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300106#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
107#define OMAP24XX_GPIO_IRQENABLE2 0x002c
Tony Lindgren92105bb2005-09-07 17:20:26 +0100108#define OMAP24XX_GPIO_IRQENABLE1 0x001c
Tero Kristo723fdb72008-11-26 14:35:16 -0800109#define OMAP24XX_GPIO_WAKE_EN 0x0020
Tony Lindgren92105bb2005-09-07 17:20:26 +0100110#define OMAP24XX_GPIO_CTRL 0x0030
111#define OMAP24XX_GPIO_OE 0x0034
112#define OMAP24XX_GPIO_DATAIN 0x0038
113#define OMAP24XX_GPIO_DATAOUT 0x003c
114#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
115#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
116#define OMAP24XX_GPIO_RISINGDETECT 0x0048
117#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700118#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
119#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
Tony Lindgren92105bb2005-09-07 17:20:26 +0100120#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
121#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
122#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
123#define OMAP24XX_GPIO_SETWKUENA 0x0084
124#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
125#define OMAP24XX_GPIO_SETDATAOUT 0x0094
126
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530127#define OMAP4_GPIO_REVISION 0x0000
128#define OMAP4_GPIO_SYSCONFIG 0x0010
129#define OMAP4_GPIO_EOI 0x0020
130#define OMAP4_GPIO_IRQSTATUSRAW0 0x0024
131#define OMAP4_GPIO_IRQSTATUSRAW1 0x0028
132#define OMAP4_GPIO_IRQSTATUS0 0x002c
133#define OMAP4_GPIO_IRQSTATUS1 0x0030
134#define OMAP4_GPIO_IRQSTATUSSET0 0x0034
135#define OMAP4_GPIO_IRQSTATUSSET1 0x0038
136#define OMAP4_GPIO_IRQSTATUSCLR0 0x003c
137#define OMAP4_GPIO_IRQSTATUSCLR1 0x0040
138#define OMAP4_GPIO_IRQWAKEN0 0x0044
139#define OMAP4_GPIO_IRQWAKEN1 0x0048
140#define OMAP4_GPIO_SYSSTATUS 0x0104
141#define OMAP4_GPIO_CTRL 0x0130
142#define OMAP4_GPIO_OE 0x0134
143#define OMAP4_GPIO_DATAIN 0x0138
144#define OMAP4_GPIO_DATAOUT 0x013c
145#define OMAP4_GPIO_LEVELDETECT0 0x0140
146#define OMAP4_GPIO_LEVELDETECT1 0x0144
147#define OMAP4_GPIO_RISINGDETECT 0x0148
148#define OMAP4_GPIO_FALLINGDETECT 0x014c
149#define OMAP4_GPIO_DEBOUNCENABLE 0x0150
150#define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
151#define OMAP4_GPIO_CLEARDATAOUT 0x0190
152#define OMAP4_GPIO_SETDATAOUT 0x0194
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800153/*
154 * omap34xx specific GPIO registers
155 */
156
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700157#define OMAP34XX_GPIO1_BASE 0x48310000
158#define OMAP34XX_GPIO2_BASE 0x49050000
159#define OMAP34XX_GPIO3_BASE 0x49052000
160#define OMAP34XX_GPIO4_BASE 0x49054000
161#define OMAP34XX_GPIO5_BASE 0x49056000
162#define OMAP34XX_GPIO6_BASE 0x49058000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800163
Santosh Shilimkar44169072009-05-28 14:16:04 -0700164/*
165 * OMAP44XX specific GPIO registers
166 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700167#define OMAP44XX_GPIO1_BASE 0x4a310000
168#define OMAP44XX_GPIO2_BASE 0x48055000
169#define OMAP44XX_GPIO3_BASE 0x48057000
170#define OMAP44XX_GPIO4_BASE 0x48059000
171#define OMAP44XX_GPIO5_BASE 0x4805B000
172#define OMAP44XX_GPIO6_BASE 0x4805D000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800173
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100174struct gpio_bank {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700175 unsigned long pbase;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100176 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100177 u16 irq;
178 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100179 int method;
Tony Lindgren140455f2010-02-12 12:26:48 -0800180#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100181 u32 suspend_wakeup;
182 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800183#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800184#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800185 u32 non_wakeup_gpios;
186 u32 enabled_non_wakeup_gpios;
187
188 u32 saved_datain;
189 u32 saved_fallingdetect;
190 u32 saved_risingdetect;
191#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800192 u32 level_mask;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800193 u32 toggle_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100194 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800195 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800196 struct clk *dbck;
Charulatha V058af1e2009-11-22 10:11:25 -0800197 u32 mod_usage;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100198};
199
200#define METHOD_MPUIO 0
201#define METHOD_GPIO_1510 1
202#define METHOD_GPIO_1610 2
Alistair Buxton7c006922009-09-22 10:02:58 +0100203#define METHOD_GPIO_7XX 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700204#define METHOD_GPIO_24XX 5
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100205
Tony Lindgren92105bb2005-09-07 17:20:26 +0100206#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100207static struct gpio_bank gpio_bank_1610[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700208 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
209 METHOD_MPUIO },
210 { OMAP1610_GPIO1_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
211 METHOD_GPIO_1610 },
212 { OMAP1610_GPIO2_BASE, NULL, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16,
213 METHOD_GPIO_1610 },
214 { OMAP1610_GPIO3_BASE, NULL, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32,
215 METHOD_GPIO_1610 },
216 { OMAP1610_GPIO4_BASE, NULL, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48,
217 METHOD_GPIO_1610 },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100218};
219#endif
220
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000221#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100222static struct gpio_bank gpio_bank_1510[2] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700223 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
224 METHOD_MPUIO },
225 { OMAP1510_GPIO_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
226 METHOD_GPIO_1510 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100227};
228#endif
229
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100230#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100231static struct gpio_bank gpio_bank_7xx[7] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700232 { OMAP1_MPUIO_VBASE, NULL, INT_7XX_MPUIO, IH_MPUIO_BASE,
233 METHOD_MPUIO },
234 { OMAP7XX_GPIO1_BASE, NULL, INT_7XX_GPIO_BANK1, IH_GPIO_BASE,
235 METHOD_GPIO_7XX },
236 { OMAP7XX_GPIO2_BASE, NULL, INT_7XX_GPIO_BANK2, IH_GPIO_BASE + 32,
237 METHOD_GPIO_7XX },
238 { OMAP7XX_GPIO3_BASE, NULL, INT_7XX_GPIO_BANK3, IH_GPIO_BASE + 64,
239 METHOD_GPIO_7XX },
240 { OMAP7XX_GPIO4_BASE, NULL, INT_7XX_GPIO_BANK4, IH_GPIO_BASE + 96,
241 METHOD_GPIO_7XX },
242 { OMAP7XX_GPIO5_BASE, NULL, INT_7XX_GPIO_BANK5, IH_GPIO_BASE + 128,
243 METHOD_GPIO_7XX },
244 { OMAP7XX_GPIO6_BASE, NULL, INT_7XX_GPIO_BANK6, IH_GPIO_BASE + 160,
245 METHOD_GPIO_7XX },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100246};
247#endif
248
Tony Lindgren088ef952010-02-12 12:26:47 -0800249#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800250
251static struct gpio_bank gpio_bank_242x[4] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700252 { OMAP242X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
253 METHOD_GPIO_24XX },
254 { OMAP242X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
255 METHOD_GPIO_24XX },
256 { OMAP242X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
257 METHOD_GPIO_24XX },
258 { OMAP242X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
259 METHOD_GPIO_24XX },
Tony Lindgren92105bb2005-09-07 17:20:26 +0100260};
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800261
262static struct gpio_bank gpio_bank_243x[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700263 { OMAP243X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
264 METHOD_GPIO_24XX },
265 { OMAP243X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
266 METHOD_GPIO_24XX },
267 { OMAP243X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
268 METHOD_GPIO_24XX },
269 { OMAP243X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
270 METHOD_GPIO_24XX },
271 { OMAP243X_GPIO5_BASE, NULL, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128,
272 METHOD_GPIO_24XX },
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800273};
274
Tony Lindgren92105bb2005-09-07 17:20:26 +0100275#endif
276
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800277#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800278static struct gpio_bank gpio_bank_34xx[6] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700279 { OMAP34XX_GPIO1_BASE, NULL, INT_34XX_GPIO_BANK1, IH_GPIO_BASE,
280 METHOD_GPIO_24XX },
281 { OMAP34XX_GPIO2_BASE, NULL, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32,
282 METHOD_GPIO_24XX },
283 { OMAP34XX_GPIO3_BASE, NULL, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64,
284 METHOD_GPIO_24XX },
285 { OMAP34XX_GPIO4_BASE, NULL, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96,
286 METHOD_GPIO_24XX },
287 { OMAP34XX_GPIO5_BASE, NULL, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128,
288 METHOD_GPIO_24XX },
289 { OMAP34XX_GPIO6_BASE, NULL, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160,
290 METHOD_GPIO_24XX },
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800291};
292
Rajendra Nayak40c670f2008-09-26 17:47:48 +0530293struct omap3_gpio_regs {
294 u32 sysconfig;
295 u32 irqenable1;
296 u32 irqenable2;
297 u32 wake_en;
298 u32 ctrl;
299 u32 oe;
300 u32 leveldetect0;
301 u32 leveldetect1;
302 u32 risingdetect;
303 u32 fallingdetect;
304 u32 dataout;
305 u32 setwkuena;
306 u32 setdataout;
307};
308
309static struct omap3_gpio_regs gpio_context[OMAP34XX_NR_GPIOS];
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800310#endif
311
Santosh Shilimkar44169072009-05-28 14:16:04 -0700312#ifdef CONFIG_ARCH_OMAP4
313static struct gpio_bank gpio_bank_44xx[6] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700314 { OMAP44XX_GPIO1_BASE, NULL, INT_44XX_GPIO_BANK1, IH_GPIO_BASE,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700315 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700316 { OMAP44XX_GPIO2_BASE, NULL, INT_44XX_GPIO_BANK2, IH_GPIO_BASE + 32,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700317 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700318 { OMAP44XX_GPIO3_BASE, NULL, INT_44XX_GPIO_BANK3, IH_GPIO_BASE + 64,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700319 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700320 { OMAP44XX_GPIO4_BASE, NULL, INT_44XX_GPIO_BANK4, IH_GPIO_BASE + 96,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700321 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700322 { OMAP44XX_GPIO5_BASE, NULL, INT_44XX_GPIO_BANK5, IH_GPIO_BASE + 128,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700323 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700324 { OMAP44XX_GPIO6_BASE, NULL, INT_44XX_GPIO_BANK6, IH_GPIO_BASE + 160,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700325 METHOD_GPIO_24XX },
326};
327
328#endif
329
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100330static struct gpio_bank *gpio_bank;
331static int gpio_bank_count;
332
333static inline struct gpio_bank *get_gpio_bank(int gpio)
334{
Tony Lindgren6e60e792006-04-02 17:46:23 +0100335 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100336 if (OMAP_GPIO_IS_MPUIO(gpio))
337 return &gpio_bank[0];
338 return &gpio_bank[1];
339 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100340 if (cpu_is_omap16xx()) {
341 if (OMAP_GPIO_IS_MPUIO(gpio))
342 return &gpio_bank[0];
343 return &gpio_bank[1 + (gpio >> 4)];
344 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700345 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100346 if (OMAP_GPIO_IS_MPUIO(gpio))
347 return &gpio_bank[0];
348 return &gpio_bank[1 + (gpio >> 5)];
349 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100350 if (cpu_is_omap24xx())
351 return &gpio_bank[gpio >> 5];
Santosh Shilimkar44169072009-05-28 14:16:04 -0700352 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800353 return &gpio_bank[gpio >> 5];
David Brownelle031ab22008-12-10 17:35:27 -0800354 BUG();
355 return NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100356}
357
358static inline int get_gpio_index(int gpio)
359{
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700360 if (cpu_is_omap7xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100361 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100362 if (cpu_is_omap24xx())
363 return gpio & 0x1f;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700364 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800365 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100366 return gpio & 0x0f;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100367}
368
369static inline int gpio_valid(int gpio)
370{
371 if (gpio < 0)
372 return -1;
Tony Lindgrend11ac972008-01-12 15:35:04 -0800373 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
Jonathan McDowell193e68b2006-09-25 12:41:30 +0300374 if (gpio >= OMAP_MAX_GPIO_LINES + 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100375 return -1;
376 return 0;
377 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100378 if (cpu_is_omap15xx() && gpio < 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100379 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100380 if ((cpu_is_omap16xx()) && gpio < 64)
381 return 0;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700382 if (cpu_is_omap7xx() && gpio < 192)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100383 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100384 if (cpu_is_omap24xx() && gpio < 128)
385 return 0;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700386 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800387 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100388 return -1;
389}
390
391static int check_gpio(int gpio)
392{
Roel Kluind32b20f2009-11-17 14:39:03 -0800393 if (unlikely(gpio_valid(gpio) < 0)) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100394 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
395 dump_stack();
396 return -1;
397 }
398 return 0;
399}
400
401static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
402{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100403 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100404 u32 l;
405
406 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800407#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100408 case METHOD_MPUIO:
409 reg += OMAP_MPUIO_IO_CNTL;
410 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800411#endif
412#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100413 case METHOD_GPIO_1510:
414 reg += OMAP1510_GPIO_DIR_CONTROL;
415 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800416#endif
417#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100418 case METHOD_GPIO_1610:
419 reg += OMAP1610_GPIO_DIRECTION;
420 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800421#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100422#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100423 case METHOD_GPIO_7XX:
424 reg += OMAP7XX_GPIO_DIR_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700425 break;
426#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800427#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100428 case METHOD_GPIO_24XX:
429 reg += OMAP24XX_GPIO_OE;
430 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800431#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530432#if defined(CONFIG_ARCH_OMAP4)
433 case METHOD_GPIO_24XX:
434 reg += OMAP4_GPIO_OE;
435 break;
436#endif
David Brownelle5c56ed2006-12-06 17:13:59 -0800437 default:
438 WARN_ON(1);
439 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100440 }
441 l = __raw_readl(reg);
442 if (is_input)
443 l |= 1 << gpio;
444 else
445 l &= ~(1 << gpio);
446 __raw_writel(l, reg);
447}
448
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100449static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
450{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100451 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100452 u32 l = 0;
453
454 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800455#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100456 case METHOD_MPUIO:
457 reg += OMAP_MPUIO_OUTPUT;
458 l = __raw_readl(reg);
459 if (enable)
460 l |= 1 << gpio;
461 else
462 l &= ~(1 << gpio);
463 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800464#endif
465#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100466 case METHOD_GPIO_1510:
467 reg += OMAP1510_GPIO_DATA_OUTPUT;
468 l = __raw_readl(reg);
469 if (enable)
470 l |= 1 << gpio;
471 else
472 l &= ~(1 << gpio);
473 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800474#endif
475#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100476 case METHOD_GPIO_1610:
477 if (enable)
478 reg += OMAP1610_GPIO_SET_DATAOUT;
479 else
480 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
481 l = 1 << gpio;
482 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800483#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100484#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100485 case METHOD_GPIO_7XX:
486 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700487 l = __raw_readl(reg);
488 if (enable)
489 l |= 1 << gpio;
490 else
491 l &= ~(1 << gpio);
492 break;
493#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800494#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100495 case METHOD_GPIO_24XX:
496 if (enable)
497 reg += OMAP24XX_GPIO_SETDATAOUT;
498 else
499 reg += OMAP24XX_GPIO_CLEARDATAOUT;
500 l = 1 << gpio;
501 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800502#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530503#ifdef CONFIG_ARCH_OMAP4
504 case METHOD_GPIO_24XX:
505 if (enable)
506 reg += OMAP4_GPIO_SETDATAOUT;
507 else
508 reg += OMAP4_GPIO_CLEARDATAOUT;
509 l = 1 << gpio;
510 break;
511#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100512 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800513 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100514 return;
515 }
516 __raw_writel(l, reg);
517}
518
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300519static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100520{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100521 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100522
523 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800524 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100525 reg = bank->base;
526 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800527#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100528 case METHOD_MPUIO:
529 reg += OMAP_MPUIO_INPUT_LATCH;
530 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800531#endif
532#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100533 case METHOD_GPIO_1510:
534 reg += OMAP1510_GPIO_DATA_INPUT;
535 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800536#endif
537#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100538 case METHOD_GPIO_1610:
539 reg += OMAP1610_GPIO_DATAIN;
540 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800541#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100542#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100543 case METHOD_GPIO_7XX:
544 reg += OMAP7XX_GPIO_DATA_INPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700545 break;
546#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800547#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100548 case METHOD_GPIO_24XX:
549 reg += OMAP24XX_GPIO_DATAIN;
550 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800551#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530552#ifdef CONFIG_ARCH_OMAP4
553 case METHOD_GPIO_24XX:
554 reg += OMAP4_GPIO_DATAIN;
555 break;
556#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100557 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800558 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100559 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100560 return (__raw_readl(reg)
561 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100562}
563
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300564static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
565{
566 void __iomem *reg;
567
568 if (check_gpio(gpio) < 0)
569 return -EINVAL;
570 reg = bank->base;
571
572 switch (bank->method) {
573#ifdef CONFIG_ARCH_OMAP1
574 case METHOD_MPUIO:
575 reg += OMAP_MPUIO_OUTPUT;
576 break;
577#endif
578#ifdef CONFIG_ARCH_OMAP15XX
579 case METHOD_GPIO_1510:
580 reg += OMAP1510_GPIO_DATA_OUTPUT;
581 break;
582#endif
583#ifdef CONFIG_ARCH_OMAP16XX
584 case METHOD_GPIO_1610:
585 reg += OMAP1610_GPIO_DATAOUT;
586 break;
587#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100588#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100589 case METHOD_GPIO_7XX:
590 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300591 break;
592#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800593#ifdef CONFIG_ARCH_OMAP2PLUS
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300594 case METHOD_GPIO_24XX:
595 reg += OMAP24XX_GPIO_DATAOUT;
596 break;
597#endif
598 default:
599 return -EINVAL;
600 }
601
602 return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
603}
604
Tony Lindgren92105bb2005-09-07 17:20:26 +0100605#define MOD_REG_BIT(reg, bit_mask, set) \
606do { \
607 int l = __raw_readl(base + reg); \
608 if (set) l |= bit_mask; \
609 else l &= ~bit_mask; \
610 __raw_writel(l, base + reg); \
611} while(0)
612
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700613void omap_set_gpio_debounce(int gpio, int enable)
614{
615 struct gpio_bank *bank;
616 void __iomem *reg;
David Brownelle031ab22008-12-10 17:35:27 -0800617 unsigned long flags;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700618 u32 val, l = 1 << get_gpio_index(gpio);
619
620 if (cpu_class_is_omap1())
621 return;
622
623 bank = get_gpio_bank(gpio);
624 reg = bank->base;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530625#ifdef CONFIG_ARCH_OMAP4
626 reg += OMAP4_GPIO_DEBOUNCENABLE;
627#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700628 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530629#endif
Charulatha V058af1e2009-11-22 10:11:25 -0800630 if (!(bank->mod_usage & l)) {
631 printk(KERN_ERR "GPIO %d not requested\n", gpio);
632 return;
633 }
David Brownelle031ab22008-12-10 17:35:27 -0800634
635 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700636 val = __raw_readl(reg);
637
Jouni Hogander89db9482008-12-10 17:35:24 -0800638 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700639 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800640 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700641 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800642 else
David Brownelle031ab22008-12-10 17:35:27 -0800643 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800644
Santosh Shilimkar44169072009-05-28 14:16:04 -0700645 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800646 if (enable)
647 clk_enable(bank->dbck);
648 else
649 clk_disable(bank->dbck);
650 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700651
652 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800653done:
654 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700655}
656EXPORT_SYMBOL(omap_set_gpio_debounce);
657
658void omap_set_gpio_debounce_time(int gpio, int enc_time)
659{
660 struct gpio_bank *bank;
661 void __iomem *reg;
662
663 if (cpu_class_is_omap1())
664 return;
665
666 bank = get_gpio_bank(gpio);
667 reg = bank->base;
668
Charulatha V058af1e2009-11-22 10:11:25 -0800669 if (!bank->mod_usage) {
670 printk(KERN_ERR "GPIO not requested\n");
671 return;
672 }
673
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700674 enc_time &= 0xff;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530675#ifdef CONFIG_ARCH_OMAP4
676 reg += OMAP4_GPIO_DEBOUNCINGTIME;
677#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700678 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530679#endif
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700680 __raw_writel(enc_time, reg);
681}
682EXPORT_SYMBOL(omap_set_gpio_debounce_time);
683
Tony Lindgren140455f2010-02-12 12:26:48 -0800684#ifdef CONFIG_ARCH_OMAP2PLUS
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700685static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
686 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100687{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800688 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100689 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530690 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100691
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530692 if (cpu_is_omap44xx()) {
693 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
694 trigger & IRQ_TYPE_LEVEL_LOW);
695 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
696 trigger & IRQ_TYPE_LEVEL_HIGH);
697 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
698 trigger & IRQ_TYPE_EDGE_RISING);
699 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
700 trigger & IRQ_TYPE_EDGE_FALLING);
701 } else {
702 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
703 trigger & IRQ_TYPE_LEVEL_LOW);
704 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
705 trigger & IRQ_TYPE_LEVEL_HIGH);
706 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
707 trigger & IRQ_TYPE_EDGE_RISING);
708 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
709 trigger & IRQ_TYPE_EDGE_FALLING);
710 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800711 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530712 if (cpu_is_omap44xx()) {
713 if (trigger != 0)
714 __raw_writel(1 << gpio, bank->base+
715 OMAP4_GPIO_IRQWAKEN0);
716 else {
717 val = __raw_readl(bank->base +
718 OMAP4_GPIO_IRQWAKEN0);
719 __raw_writel(val & (~(1 << gpio)), bank->base +
720 OMAP4_GPIO_IRQWAKEN0);
721 }
722 } else {
723 if (trigger != 0)
724 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700725 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530726 else
727 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700728 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530729 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800730 } else {
731 if (trigger != 0)
732 bank->enabled_non_wakeup_gpios |= gpio_bit;
733 else
734 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
735 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700736
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530737 if (cpu_is_omap44xx()) {
738 bank->level_mask =
739 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
740 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
741 } else {
742 bank->level_mask =
743 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
744 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
745 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100746}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800747#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100748
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800749#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800750/*
751 * This only applies to chips that can't do both rising and falling edge
752 * detection at once. For all other chips, this function is a noop.
753 */
754static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
755{
756 void __iomem *reg = bank->base;
757 u32 l = 0;
758
759 switch (bank->method) {
Cory Maccarrone4318f362010-01-08 10:29:04 -0800760 case METHOD_MPUIO:
761 reg += OMAP_MPUIO_GPIO_INT_EDGE;
762 break;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800763#ifdef CONFIG_ARCH_OMAP15XX
764 case METHOD_GPIO_1510:
765 reg += OMAP1510_GPIO_INT_CONTROL;
766 break;
767#endif
768#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
769 case METHOD_GPIO_7XX:
770 reg += OMAP7XX_GPIO_INT_CONTROL;
771 break;
772#endif
773 default:
774 return;
775 }
776
777 l = __raw_readl(reg);
778 if ((l >> gpio) & 1)
779 l &= ~(1 << gpio);
780 else
781 l |= 1 << gpio;
782
783 __raw_writel(l, reg);
784}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800785#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800786
Tony Lindgren92105bb2005-09-07 17:20:26 +0100787static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
788{
789 void __iomem *reg = bank->base;
790 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100791
792 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800793#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100794 case METHOD_MPUIO:
795 reg += OMAP_MPUIO_GPIO_INT_EDGE;
796 l = __raw_readl(reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800797 if (trigger & IRQ_TYPE_EDGE_BOTH)
798 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100799 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100800 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100801 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100802 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100803 else
804 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100805 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800806#endif
807#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100808 case METHOD_GPIO_1510:
809 reg += OMAP1510_GPIO_INT_CONTROL;
810 l = __raw_readl(reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800811 if (trigger & IRQ_TYPE_EDGE_BOTH)
812 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100813 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100814 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100815 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100816 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100817 else
818 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100819 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800820#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800821#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100822 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100823 if (gpio & 0x08)
824 reg += OMAP1610_GPIO_EDGE_CTRL2;
825 else
826 reg += OMAP1610_GPIO_EDGE_CTRL1;
827 gpio &= 0x07;
828 l = __raw_readl(reg);
829 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100830 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100831 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100832 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100833 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800834 if (trigger)
835 /* Enable wake-up during idle for dynamic tick */
836 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
837 else
838 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100839 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800840#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100841#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100842 case METHOD_GPIO_7XX:
843 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700844 l = __raw_readl(reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800845 if (trigger & IRQ_TYPE_EDGE_BOTH)
846 bank->toggle_mask |= 1 << gpio;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700847 if (trigger & IRQ_TYPE_EDGE_RISING)
848 l |= 1 << gpio;
849 else if (trigger & IRQ_TYPE_EDGE_FALLING)
850 l &= ~(1 << gpio);
851 else
852 goto bad;
853 break;
854#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800855#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +0100856 case METHOD_GPIO_24XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800857 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100858 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800859#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100860 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100861 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100862 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100863 __raw_writel(l, reg);
864 return 0;
865bad:
866 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100867}
868
Tony Lindgren92105bb2005-09-07 17:20:26 +0100869static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100870{
871 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100872 unsigned gpio;
873 int retval;
David Brownella6472532008-03-03 04:33:30 -0800874 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100875
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800876 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100877 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
878 else
879 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100880
881 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100882 return -EINVAL;
883
David Brownelle5c56ed2006-12-06 17:13:59 -0800884 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100885 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800886
887 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800888 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800889 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100890 return -EINVAL;
891
David Brownell58781012006-12-06 17:14:10 -0800892 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800893 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100894 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800895 if (retval == 0) {
896 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
897 irq_desc[irq].status |= type;
898 }
David Brownella6472532008-03-03 04:33:30 -0800899 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800900
901 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
902 __set_irq_handler_unlocked(irq, handle_level_irq);
903 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
904 __set_irq_handler_unlocked(irq, handle_edge_irq);
905
Tony Lindgren92105bb2005-09-07 17:20:26 +0100906 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100907}
908
909static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
910{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100911 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100912
913 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800914#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100915 case METHOD_MPUIO:
916 /* MPUIO irqstatus is reset by reading the status register,
917 * so do nothing here */
918 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800919#endif
920#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100921 case METHOD_GPIO_1510:
922 reg += OMAP1510_GPIO_INT_STATUS;
923 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800924#endif
925#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100926 case METHOD_GPIO_1610:
927 reg += OMAP1610_GPIO_IRQSTATUS1;
928 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800929#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100930#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100931 case METHOD_GPIO_7XX:
932 reg += OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700933 break;
934#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800935#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100936 case METHOD_GPIO_24XX:
937 reg += OMAP24XX_GPIO_IRQSTATUS1;
938 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800939#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530940#if defined(CONFIG_ARCH_OMAP4)
941 case METHOD_GPIO_24XX:
942 reg += OMAP4_GPIO_IRQSTATUS0;
943 break;
944#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100945 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800946 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100947 return;
948 }
949 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300950
951 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800952#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Roger Quadrosbedfd152009-04-23 11:10:50 -0700953 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530954#endif
955#if defined(CONFIG_ARCH_OMAP4)
956 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
957#endif
958 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700959 __raw_writel(gpio_mask, reg);
960
961 /* Flush posted write for the irq status to avoid spurious interrupts */
962 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530963 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100964}
965
966static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
967{
968 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
969}
970
Imre Deakea6dedd2006-06-26 16:16:00 -0700971static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
972{
973 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700974 int inv = 0;
975 u32 l;
976 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700977
978 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800979#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700980 case METHOD_MPUIO:
981 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700982 mask = 0xffff;
983 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700984 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800985#endif
986#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700987 case METHOD_GPIO_1510:
988 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700989 mask = 0xffff;
990 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700991 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800992#endif
993#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700994 case METHOD_GPIO_1610:
995 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700996 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700997 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800998#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100999#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001000 case METHOD_GPIO_7XX:
1001 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001002 mask = 0xffffffff;
1003 inv = 1;
1004 break;
1005#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001006#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Imre Deakea6dedd2006-06-26 16:16:00 -07001007 case METHOD_GPIO_24XX:
1008 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001009 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001010 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001011#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301012#if defined(CONFIG_ARCH_OMAP4)
1013 case METHOD_GPIO_24XX:
1014 reg += OMAP4_GPIO_IRQSTATUSSET0;
1015 mask = 0xffffffff;
1016 break;
1017#endif
Imre Deakea6dedd2006-06-26 16:16:00 -07001018 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001019 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -07001020 return 0;
1021 }
1022
Imre Deak99c47702006-06-26 16:16:07 -07001023 l = __raw_readl(reg);
1024 if (inv)
1025 l = ~l;
1026 l &= mask;
1027 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -07001028}
1029
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001030static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
1031{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001032 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001033 u32 l;
1034
1035 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001036#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001037 case METHOD_MPUIO:
1038 reg += OMAP_MPUIO_GPIO_MASKIT;
1039 l = __raw_readl(reg);
1040 if (enable)
1041 l &= ~(gpio_mask);
1042 else
1043 l |= gpio_mask;
1044 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001045#endif
1046#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001047 case METHOD_GPIO_1510:
1048 reg += OMAP1510_GPIO_INT_MASK;
1049 l = __raw_readl(reg);
1050 if (enable)
1051 l &= ~(gpio_mask);
1052 else
1053 l |= gpio_mask;
1054 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001055#endif
1056#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001057 case METHOD_GPIO_1610:
1058 if (enable)
1059 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1060 else
1061 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1062 l = gpio_mask;
1063 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001064#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001065#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001066 case METHOD_GPIO_7XX:
1067 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001068 l = __raw_readl(reg);
1069 if (enable)
1070 l &= ~(gpio_mask);
1071 else
1072 l |= gpio_mask;
1073 break;
1074#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001075#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001076 case METHOD_GPIO_24XX:
1077 if (enable)
1078 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1079 else
1080 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1081 l = gpio_mask;
1082 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001083#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301084#ifdef CONFIG_ARCH_OMAP4
1085 case METHOD_GPIO_24XX:
1086 if (enable)
1087 reg += OMAP4_GPIO_IRQSTATUSSET0;
1088 else
1089 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1090 l = gpio_mask;
1091 break;
1092#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001093 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001094 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001095 return;
1096 }
1097 __raw_writel(l, reg);
1098}
1099
1100static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1101{
1102 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1103}
1104
Tony Lindgren92105bb2005-09-07 17:20:26 +01001105/*
1106 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1107 * 1510 does not seem to have a wake-up register. If JTAG is connected
1108 * to the target, system will wake up always on GPIO events. While
1109 * system is running all registered GPIO interrupts need to have wake-up
1110 * enabled. When system is suspended, only selected GPIO interrupts need
1111 * to have wake-up enabled.
1112 */
1113static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1114{
Tony Lindgren4cc64202010-01-08 10:29:05 -08001115 unsigned long uninitialized_var(flags);
David Brownella6472532008-03-03 04:33:30 -08001116
Tony Lindgren92105bb2005-09-07 17:20:26 +01001117 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001118#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001119 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001120 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001121 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001122 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001123 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001124 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001125 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001126 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001127 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001128#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001129#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001130 case METHOD_GPIO_24XX:
David Brownell11a78b72006-12-06 17:14:11 -08001131 if (bank->non_wakeup_gpios & (1 << gpio)) {
1132 printk(KERN_ERR "Unable to modify wakeup on "
1133 "non-wakeup GPIO%d\n",
1134 (bank - gpio_bank) * 32 + gpio);
1135 return -EINVAL;
1136 }
David Brownella6472532008-03-03 04:33:30 -08001137 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001138 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001139 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001140 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001141 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001142 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001143 return 0;
1144#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001145 default:
1146 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1147 bank->method);
1148 return -EINVAL;
1149 }
1150}
1151
Tony Lindgren4196dd62006-09-25 12:41:38 +03001152static void _reset_gpio(struct gpio_bank *bank, int gpio)
1153{
1154 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1155 _set_gpio_irqenable(bank, gpio, 0);
1156 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001157 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001158}
1159
Tony Lindgren92105bb2005-09-07 17:20:26 +01001160/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1161static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1162{
1163 unsigned int gpio = irq - IH_GPIO_BASE;
1164 struct gpio_bank *bank;
1165 int retval;
1166
1167 if (check_gpio(gpio) < 0)
1168 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001169 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001170 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001171
1172 return retval;
1173}
1174
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001175static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001176{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001177 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001178 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001179
David Brownella6472532008-03-03 04:33:30 -08001180 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001181
Tony Lindgren4196dd62006-09-25 12:41:38 +03001182 /* Set trigger to none. You need to enable the desired trigger with
1183 * request_irq() or set_irq_type().
1184 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001185 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001186
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001187#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001188 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001189 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001190
Tony Lindgren92105bb2005-09-07 17:20:26 +01001191 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001192 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001193 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001194 }
1195#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001196 if (!cpu_class_is_omap1()) {
1197 if (!bank->mod_usage) {
1198 u32 ctrl;
1199 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1200 ctrl &= 0xFFFFFFFE;
1201 /* Module is enabled, clocks are not gated */
1202 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1203 }
1204 bank->mod_usage |= 1 << offset;
1205 }
David Brownella6472532008-03-03 04:33:30 -08001206 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001207
1208 return 0;
1209}
1210
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001211static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001212{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001213 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001214 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001215
David Brownella6472532008-03-03 04:33:30 -08001216 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001217#ifdef CONFIG_ARCH_OMAP16XX
1218 if (bank->method == METHOD_GPIO_1610) {
1219 /* Disable wake-up during idle for dynamic tick */
1220 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001221 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001222 }
1223#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001224#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +01001225 if (bank->method == METHOD_GPIO_24XX) {
1226 /* Disable wake-up during idle for dynamic tick */
1227 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001228 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001229 }
1230#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001231 if (!cpu_class_is_omap1()) {
1232 bank->mod_usage &= ~(1 << offset);
1233 if (!bank->mod_usage) {
1234 u32 ctrl;
1235 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1236 /* Module is disabled, clocks are gated */
1237 ctrl |= 1;
1238 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1239 }
1240 }
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001241 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001242 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001243}
1244
1245/*
1246 * We need to unmask the GPIO bank interrupt as soon as possible to
1247 * avoid missing GPIO interrupts for other lines in the bank.
1248 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1249 * in the bank to avoid missing nested interrupts for a GPIO line.
1250 * If we wait to unmask individual GPIO lines in the bank after the
1251 * line's interrupt handler has been run, we may miss some nested
1252 * interrupts.
1253 */
Russell King10dd5ce2006-11-23 11:41:32 +00001254static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001255{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001256 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001257 u32 isr;
Cory Maccarrone4318f362010-01-08 10:29:04 -08001258 unsigned int gpio_irq, gpio_index;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001259 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001260 u32 retrigger = 0;
1261 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001262
1263 desc->chip->ack(irq);
1264
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001265 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001266#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001267 if (bank->method == METHOD_MPUIO)
1268 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001269#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001270#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001271 if (bank->method == METHOD_GPIO_1510)
1272 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1273#endif
1274#if defined(CONFIG_ARCH_OMAP16XX)
1275 if (bank->method == METHOD_GPIO_1610)
1276 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1277#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001278#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001279 if (bank->method == METHOD_GPIO_7XX)
1280 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001281#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001282#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001283 if (bank->method == METHOD_GPIO_24XX)
1284 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1285#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301286#if defined(CONFIG_ARCH_OMAP4)
1287 if (bank->method == METHOD_GPIO_24XX)
1288 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1289#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001290 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001291 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001292 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001293
Imre Deakea6dedd2006-06-26 16:16:00 -07001294 enabled = _get_gpio_irqbank_mask(bank);
1295 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001296
1297 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1298 isr &= 0x0000ffff;
1299
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001300 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001301 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001302 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001303
1304 /* clear edge sensitive interrupts before handler(s) are
1305 called so that we don't miss any interrupt occurred while
1306 executing them */
1307 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1308 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1309 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1310
1311 /* if there is only edge sensitive GPIO pin interrupts
1312 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001313 if (!level_mask && !unmasked) {
1314 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001315 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001316 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001317
Imre Deakea6dedd2006-06-26 16:16:00 -07001318 isr |= retrigger;
1319 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001320 if (!isr)
1321 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001322
Tony Lindgren92105bb2005-09-07 17:20:26 +01001323 gpio_irq = bank->virtual_irq_start;
1324 for (; isr != 0; isr >>= 1, gpio_irq++) {
Cory Maccarrone4318f362010-01-08 10:29:04 -08001325 gpio_index = get_gpio_index(irq_to_gpio(gpio_irq));
1326
Tony Lindgren92105bb2005-09-07 17:20:26 +01001327 if (!(isr & 1))
1328 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001329
Cory Maccarrone4318f362010-01-08 10:29:04 -08001330#ifdef CONFIG_ARCH_OMAP1
1331 /*
1332 * Some chips can't respond to both rising and falling
1333 * at the same time. If this irq was requested with
1334 * both flags, we need to flip the ICR data for the IRQ
1335 * to respond to the IRQ for the opposite direction.
1336 * This will be indicated in the bank toggle_mask.
1337 */
1338 if (bank->toggle_mask & (1 << gpio_index))
1339 _toggle_gpio_edge_triggering(bank, gpio_index);
1340#endif
1341
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001342 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001343 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001344 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001345 /* if bank has any level sensitive GPIO pin interrupt
1346 configured, we must unmask the bank interrupt only after
1347 handler(s) are executed in order to avoid spurious bank
1348 interrupt */
1349 if (!unmasked)
1350 desc->chip->unmask(irq);
1351
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001352}
1353
Tony Lindgren4196dd62006-09-25 12:41:38 +03001354static void gpio_irq_shutdown(unsigned int irq)
1355{
1356 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001357 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001358
1359 _reset_gpio(bank, gpio);
1360}
1361
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001362static void gpio_ack_irq(unsigned int irq)
1363{
1364 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001365 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001366
1367 _clear_gpio_irqstatus(bank, gpio);
1368}
1369
1370static void gpio_mask_irq(unsigned int irq)
1371{
1372 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001373 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001374
1375 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001376 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001377}
1378
1379static void gpio_unmask_irq(unsigned int irq)
1380{
1381 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001382 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001383 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001384 struct irq_desc *desc = irq_to_desc(irq);
1385 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1386
1387 if (trigger)
1388 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001389
1390 /* For level-triggered GPIOs, the clearing must be done after
1391 * the HW source is cleared, thus after the handler has run */
1392 if (bank->level_mask & irq_mask) {
1393 _set_gpio_irqenable(bank, gpio, 0);
1394 _clear_gpio_irqstatus(bank, gpio);
1395 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001396
Kevin Hilman4de8c752008-01-16 21:56:14 -08001397 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001398}
1399
David Brownelle5c56ed2006-12-06 17:13:59 -08001400static struct irq_chip gpio_irq_chip = {
1401 .name = "GPIO",
1402 .shutdown = gpio_irq_shutdown,
1403 .ack = gpio_ack_irq,
1404 .mask = gpio_mask_irq,
1405 .unmask = gpio_unmask_irq,
1406 .set_type = gpio_irq_type,
1407 .set_wake = gpio_wake_enable,
1408};
1409
1410/*---------------------------------------------------------------------*/
1411
1412#ifdef CONFIG_ARCH_OMAP1
1413
1414/* MPUIO uses the always-on 32k clock */
1415
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001416static void mpuio_ack_irq(unsigned int irq)
1417{
1418 /* The ISR is reset automatically, so do nothing here. */
1419}
1420
1421static void mpuio_mask_irq(unsigned int irq)
1422{
1423 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001424 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001425
1426 _set_gpio_irqenable(bank, gpio, 0);
1427}
1428
1429static void mpuio_unmask_irq(unsigned int irq)
1430{
1431 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001432 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001433
1434 _set_gpio_irqenable(bank, gpio, 1);
1435}
1436
David Brownelle5c56ed2006-12-06 17:13:59 -08001437static struct irq_chip mpuio_irq_chip = {
1438 .name = "MPUIO",
1439 .ack = mpuio_ack_irq,
1440 .mask = mpuio_mask_irq,
1441 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001442 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001443#ifdef CONFIG_ARCH_OMAP16XX
1444 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1445 .set_wake = gpio_wake_enable,
1446#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001447};
1448
David Brownelle5c56ed2006-12-06 17:13:59 -08001449
1450#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1451
David Brownell11a78b72006-12-06 17:14:11 -08001452
1453#ifdef CONFIG_ARCH_OMAP16XX
1454
1455#include <linux/platform_device.h>
1456
Magnus Damm79ee0312009-07-08 13:22:04 +02001457static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001458{
Magnus Damm79ee0312009-07-08 13:22:04 +02001459 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001460 struct gpio_bank *bank = platform_get_drvdata(pdev);
1461 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001462 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001463
David Brownella6472532008-03-03 04:33:30 -08001464 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001465 bank->saved_wakeup = __raw_readl(mask_reg);
1466 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001467 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001468
1469 return 0;
1470}
1471
Magnus Damm79ee0312009-07-08 13:22:04 +02001472static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001473{
Magnus Damm79ee0312009-07-08 13:22:04 +02001474 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001475 struct gpio_bank *bank = platform_get_drvdata(pdev);
1476 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001477 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001478
David Brownella6472532008-03-03 04:33:30 -08001479 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001480 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001481 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001482
1483 return 0;
1484}
1485
Alexey Dobriyan47145212009-12-14 18:00:08 -08001486static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +02001487 .suspend_noirq = omap_mpuio_suspend_noirq,
1488 .resume_noirq = omap_mpuio_resume_noirq,
1489};
1490
David Brownell11a78b72006-12-06 17:14:11 -08001491/* use platform_driver for this, now that there's no longer any
1492 * point to sys_device (other than not disturbing old code).
1493 */
1494static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001495 .driver = {
1496 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001497 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001498 },
1499};
1500
1501static struct platform_device omap_mpuio_device = {
1502 .name = "mpuio",
1503 .id = -1,
1504 .dev = {
1505 .driver = &omap_mpuio_driver.driver,
1506 }
1507 /* could list the /proc/iomem resources */
1508};
1509
1510static inline void mpuio_init(void)
1511{
David Brownellfcf126d2007-04-02 12:46:47 -07001512 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1513
David Brownell11a78b72006-12-06 17:14:11 -08001514 if (platform_driver_register(&omap_mpuio_driver) == 0)
1515 (void) platform_device_register(&omap_mpuio_device);
1516}
1517
1518#else
1519static inline void mpuio_init(void) {}
1520#endif /* 16xx */
1521
David Brownelle5c56ed2006-12-06 17:13:59 -08001522#else
1523
1524extern struct irq_chip mpuio_irq_chip;
1525
1526#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001527static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001528
1529#endif
1530
1531/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001532
David Brownell52e31342008-03-03 12:43:23 -08001533/* REVISIT these are stupid implementations! replace by ones that
1534 * don't switch on METHOD_* and which mostly avoid spinlocks
1535 */
1536
1537static int gpio_input(struct gpio_chip *chip, unsigned offset)
1538{
1539 struct gpio_bank *bank;
1540 unsigned long flags;
1541
1542 bank = container_of(chip, struct gpio_bank, chip);
1543 spin_lock_irqsave(&bank->lock, flags);
1544 _set_gpio_direction(bank, offset, 1);
1545 spin_unlock_irqrestore(&bank->lock, flags);
1546 return 0;
1547}
1548
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001549static int gpio_is_input(struct gpio_bank *bank, int mask)
1550{
1551 void __iomem *reg = bank->base;
1552
1553 switch (bank->method) {
1554 case METHOD_MPUIO:
1555 reg += OMAP_MPUIO_IO_CNTL;
1556 break;
1557 case METHOD_GPIO_1510:
1558 reg += OMAP1510_GPIO_DIR_CONTROL;
1559 break;
1560 case METHOD_GPIO_1610:
1561 reg += OMAP1610_GPIO_DIRECTION;
1562 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001563 case METHOD_GPIO_7XX:
1564 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001565 break;
1566 case METHOD_GPIO_24XX:
1567 reg += OMAP24XX_GPIO_OE;
1568 break;
1569 }
1570 return __raw_readl(reg) & mask;
1571}
1572
David Brownell52e31342008-03-03 12:43:23 -08001573static int gpio_get(struct gpio_chip *chip, unsigned offset)
1574{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001575 struct gpio_bank *bank;
1576 void __iomem *reg;
1577 int gpio;
1578 u32 mask;
1579
1580 gpio = chip->base + offset;
1581 bank = get_gpio_bank(gpio);
1582 reg = bank->base;
1583 mask = 1 << get_gpio_index(gpio);
1584
1585 if (gpio_is_input(bank, mask))
1586 return _get_gpio_datain(bank, gpio);
1587 else
1588 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001589}
1590
1591static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1592{
1593 struct gpio_bank *bank;
1594 unsigned long flags;
1595
1596 bank = container_of(chip, struct gpio_bank, chip);
1597 spin_lock_irqsave(&bank->lock, flags);
1598 _set_gpio_dataout(bank, offset, value);
1599 _set_gpio_direction(bank, offset, 0);
1600 spin_unlock_irqrestore(&bank->lock, flags);
1601 return 0;
1602}
1603
1604static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1605{
1606 struct gpio_bank *bank;
1607 unsigned long flags;
1608
1609 bank = container_of(chip, struct gpio_bank, chip);
1610 spin_lock_irqsave(&bank->lock, flags);
1611 _set_gpio_dataout(bank, offset, value);
1612 spin_unlock_irqrestore(&bank->lock, flags);
1613}
1614
David Brownella007b702008-12-10 17:35:25 -08001615static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1616{
1617 struct gpio_bank *bank;
1618
1619 bank = container_of(chip, struct gpio_bank, chip);
1620 return bank->virtual_irq_start + offset;
1621}
1622
David Brownell52e31342008-03-03 12:43:23 -08001623/*---------------------------------------------------------------------*/
1624
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001625static int initialized;
Tony Lindgren56213ca2010-02-12 12:26:46 -08001626#if defined(CONFIG_ARCH_OMAP1) || defined(CONFIG_ARCH_OMAP2)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001627static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001628#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001629
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001630#if defined(CONFIG_ARCH_OMAP2)
1631static struct clk * gpio_fck;
1632#endif
1633
1634#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001635static struct clk * gpio5_ick;
1636static struct clk * gpio5_fck;
1637#endif
1638
Santosh Shilimkar44169072009-05-28 14:16:04 -07001639#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001640static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1641#endif
1642
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001643static void __init omap_gpio_show_rev(void)
1644{
1645 u32 rev;
1646
1647 if (cpu_is_omap16xx())
1648 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1649 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1650 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1651 else if (cpu_is_omap44xx())
1652 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1653 else
1654 return;
1655
1656 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1657 (rev >> 4) & 0x0f, rev & 0x0f);
1658}
1659
David Brownell8ba55c52008-02-26 11:10:50 -08001660/* This lock class tells lockdep that GPIO irqs are in a different
1661 * category than their parents, so it won't report false recursion.
1662 */
1663static struct lock_class_key gpio_lock_class;
1664
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001665static int __init _omap_gpio_init(void)
1666{
1667 int i;
David Brownell52e31342008-03-03 12:43:23 -08001668 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001669 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001670 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001671 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001672
1673 initialized = 1;
1674
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001675#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001676 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001677 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1678 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001679 printk("Could not get arm_gpio_ck\n");
1680 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001681 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001682 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001683#endif
1684#if defined(CONFIG_ARCH_OMAP2)
1685 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001686 gpio_ick = clk_get(NULL, "gpios_ick");
1687 if (IS_ERR(gpio_ick))
1688 printk("Could not get gpios_ick\n");
1689 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001690 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001691 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001692 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001693 printk("Could not get gpios_fck\n");
1694 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001695 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001696
1697 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001698 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001699 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001700#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001701 if (cpu_is_omap2430()) {
1702 gpio5_ick = clk_get(NULL, "gpio5_ick");
1703 if (IS_ERR(gpio5_ick))
1704 printk("Could not get gpio5_ick\n");
1705 else
1706 clk_enable(gpio5_ick);
1707 gpio5_fck = clk_get(NULL, "gpio5_fck");
1708 if (IS_ERR(gpio5_fck))
1709 printk("Could not get gpio5_fck\n");
1710 else
1711 clk_enable(gpio5_fck);
1712 }
1713#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001714 }
1715#endif
1716
Santosh Shilimkar44169072009-05-28 14:16:04 -07001717#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1718 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001719 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1720 sprintf(clk_name, "gpio%d_ick", i + 1);
1721 gpio_iclks[i] = clk_get(NULL, clk_name);
1722 if (IS_ERR(gpio_iclks[i]))
1723 printk(KERN_ERR "Could not get %s\n", clk_name);
1724 else
1725 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001726 }
1727 }
1728#endif
1729
Tony Lindgren92105bb2005-09-07 17:20:26 +01001730
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001731#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001732 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001733 gpio_bank_count = 2;
1734 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001735 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001736 }
1737#endif
1738#if defined(CONFIG_ARCH_OMAP16XX)
1739 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001740 gpio_bank_count = 5;
1741 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001742 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001743 }
1744#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001745#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1746 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001747 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001748 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001749 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001750 }
1751#endif
Tony Lindgren088ef952010-02-12 12:26:47 -08001752#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001753 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001754 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001755 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001756 }
1757 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001758 gpio_bank_count = 5;
1759 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001760 }
1761#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001762#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001763 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001764 gpio_bank_count = OMAP34XX_NR_GPIOS;
1765 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001766 }
1767#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001768#ifdef CONFIG_ARCH_OMAP4
1769 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001770 gpio_bank_count = OMAP34XX_NR_GPIOS;
1771 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001772 }
1773#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001774 for (i = 0; i < gpio_bank_count; i++) {
1775 int j, gpio_count = 16;
1776
1777 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001778 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001779
1780 /* Static mapping, never released */
1781 bank->base = ioremap(bank->pbase, bank_size);
1782 if (!bank->base) {
1783 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1784 continue;
1785 }
1786
David Brownelle5c56ed2006-12-06 17:13:59 -08001787 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001788 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001789 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001790 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1791 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1792 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001793 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001794 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1795 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001796 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001797 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001798 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1799 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1800 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001801
Alistair Buxton7c006922009-09-22 10:02:58 +01001802 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001803 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001804
Tony Lindgren140455f2010-02-12 12:26:48 -08001805#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +01001806 if (bank->method == METHOD_GPIO_24XX) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001807 static const u32 non_wakeup_gpios[] = {
1808 0xe203ffc0, 0x08700040
1809 };
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301810 if (cpu_is_omap44xx()) {
1811 __raw_writel(0xffffffff, bank->base +
1812 OMAP4_GPIO_IRQSTATUSCLR0);
1813 __raw_writew(0x0015, bank->base +
1814 OMAP4_GPIO_SYSCONFIG);
1815 __raw_writel(0x00000000, bank->base +
1816 OMAP4_GPIO_DEBOUNCENABLE);
1817 /* Initialize interface clock ungated, module enabled */
1818 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1819 } else {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001820 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1821 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001822 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
janboecb5793d2009-06-23 13:30:25 +03001823 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_DEBOUNCE_EN);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001824
1825 /* Initialize interface clock ungated, module enabled */
1826 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301827 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001828 if (i < ARRAY_SIZE(non_wakeup_gpios))
1829 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001830 gpio_count = 32;
1831 }
1832#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001833
1834 bank->mod_usage = 0;
David Brownell52e31342008-03-03 12:43:23 -08001835 /* REVISIT eventually switch from OMAP-specific gpio structs
1836 * over to the generic ones
1837 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001838 bank->chip.request = omap_gpio_request;
1839 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001840 bank->chip.direction_input = gpio_input;
1841 bank->chip.get = gpio_get;
1842 bank->chip.direction_output = gpio_output;
1843 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001844 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001845 if (bank_is_mpuio(bank)) {
1846 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001847#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001848 bank->chip.dev = &omap_mpuio_device.dev;
1849#endif
David Brownell52e31342008-03-03 12:43:23 -08001850 bank->chip.base = OMAP_MPUIO(0);
1851 } else {
1852 bank->chip.label = "gpio";
1853 bank->chip.base = gpio;
1854 gpio += gpio_count;
1855 }
1856 bank->chip.ngpio = gpio_count;
1857
1858 gpiochip_add(&bank->chip);
1859
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001860 for (j = bank->virtual_irq_start;
1861 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001862 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001863 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001864 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001865 set_irq_chip(j, &mpuio_irq_chip);
1866 else
1867 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001868 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001869 set_irq_flags(j, IRQF_VALID);
1870 }
1871 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1872 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001873
Santosh Shilimkar44169072009-05-28 14:16:04 -07001874 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001875 sprintf(clk_name, "gpio%d_dbck", i + 1);
1876 bank->dbck = clk_get(NULL, clk_name);
1877 if (IS_ERR(bank->dbck))
1878 printk(KERN_ERR "Could not get %s\n", clk_name);
1879 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001880 }
1881
1882 /* Enable system clock for GPIO module.
1883 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001884 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001885 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1886
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001887 /* Enable autoidle for the OCP interface */
1888 if (cpu_is_omap24xx())
1889 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001890 if (cpu_is_omap34xx())
1891 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001892
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001893 omap_gpio_show_rev();
1894
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001895 return 0;
1896}
1897
Tony Lindgren140455f2010-02-12 12:26:48 -08001898#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001899static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1900{
1901 int i;
1902
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001903 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001904 return 0;
1905
1906 for (i = 0; i < gpio_bank_count; i++) {
1907 struct gpio_bank *bank = &gpio_bank[i];
1908 void __iomem *wake_status;
1909 void __iomem *wake_clear;
1910 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001911 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001912
1913 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001914#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001915 case METHOD_GPIO_1610:
1916 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1917 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1918 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1919 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001920#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001921#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001922 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001923 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001924 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1925 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1926 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001927#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301928#ifdef CONFIG_ARCH_OMAP4
1929 case METHOD_GPIO_24XX:
1930 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1931 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1932 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1933 break;
1934#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001935 default:
1936 continue;
1937 }
1938
David Brownella6472532008-03-03 04:33:30 -08001939 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001940 bank->saved_wakeup = __raw_readl(wake_status);
1941 __raw_writel(0xffffffff, wake_clear);
1942 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001943 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001944 }
1945
1946 return 0;
1947}
1948
1949static int omap_gpio_resume(struct sys_device *dev)
1950{
1951 int i;
1952
Tero Kristo723fdb72008-11-26 14:35:16 -08001953 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001954 return 0;
1955
1956 for (i = 0; i < gpio_bank_count; i++) {
1957 struct gpio_bank *bank = &gpio_bank[i];
1958 void __iomem *wake_clear;
1959 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001960 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001961
1962 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001963#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001964 case METHOD_GPIO_1610:
1965 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1966 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1967 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001968#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001969#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001970 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001971 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1972 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001973 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001974#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301975#ifdef CONFIG_ARCH_OMAP4
1976 case METHOD_GPIO_24XX:
1977 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1978 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1979 break;
1980#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001981 default:
1982 continue;
1983 }
1984
David Brownella6472532008-03-03 04:33:30 -08001985 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001986 __raw_writel(0xffffffff, wake_clear);
1987 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001988 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001989 }
1990
1991 return 0;
1992}
1993
1994static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01001995 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001996 .suspend = omap_gpio_suspend,
1997 .resume = omap_gpio_resume,
1998};
1999
2000static struct sys_device omap_gpio_device = {
2001 .id = 0,
2002 .cls = &omap_gpio_sysclass,
2003};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002004
2005#endif
2006
Tony Lindgren140455f2010-02-12 12:26:48 -08002007#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002008
2009static int workaround_enabled;
2010
2011void omap2_gpio_prepare_for_retention(void)
2012{
2013 int i, c = 0;
2014
2015 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
2016 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
2017 for (i = 0; i < gpio_bank_count; i++) {
2018 struct gpio_bank *bank = &gpio_bank[i];
2019 u32 l1, l2;
2020
2021 if (!(bank->enabled_non_wakeup_gpios))
2022 continue;
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002023#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002024 bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2025 l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2026 l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002027#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302028#ifdef CONFIG_ARCH_OMAP4
2029 bank->saved_datain = __raw_readl(bank->base +
2030 OMAP4_GPIO_DATAIN);
2031 l1 = __raw_readl(bank->base + OMAP4_GPIO_FALLINGDETECT);
2032 l2 = __raw_readl(bank->base + OMAP4_GPIO_RISINGDETECT);
2033#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002034 bank->saved_fallingdetect = l1;
2035 bank->saved_risingdetect = l2;
2036 l1 &= ~bank->enabled_non_wakeup_gpios;
2037 l2 &= ~bank->enabled_non_wakeup_gpios;
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002038#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002039 __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2040 __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002041#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302042#ifdef CONFIG_ARCH_OMAP4
2043 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
2044 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
2045#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002046 c++;
2047 }
2048 if (!c) {
2049 workaround_enabled = 0;
2050 return;
2051 }
2052 workaround_enabled = 1;
2053}
2054
2055void omap2_gpio_resume_after_retention(void)
2056{
2057 int i;
2058
2059 if (!workaround_enabled)
2060 return;
2061 for (i = 0; i < gpio_bank_count; i++) {
2062 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002063 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002064
2065 if (!(bank->enabled_non_wakeup_gpios))
2066 continue;
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002067#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002068 __raw_writel(bank->saved_fallingdetect,
2069 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2070 __raw_writel(bank->saved_risingdetect,
2071 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302072 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2073#endif
2074#ifdef CONFIG_ARCH_OMAP4
2075 __raw_writel(bank->saved_fallingdetect,
2076 bank->base + OMAP4_GPIO_FALLINGDETECT);
2077 __raw_writel(bank->saved_risingdetect,
2078 bank->base + OMAP4_GPIO_RISINGDETECT);
2079 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002080#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002081 /* Check if any of the non-wakeup interrupt GPIOs have changed
2082 * state. If so, generate an IRQ by software. This is
2083 * horribly racy, but it's the best we can do to work around
2084 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002085 l ^= bank->saved_datain;
2086 l &= bank->non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002087
2088 /*
2089 * No need to generate IRQs for the rising edge for gpio IRQs
2090 * configured with falling edge only; and vice versa.
2091 */
2092 gen0 = l & bank->saved_fallingdetect;
2093 gen0 &= bank->saved_datain;
2094
2095 gen1 = l & bank->saved_risingdetect;
2096 gen1 &= ~(bank->saved_datain);
2097
2098 /* FIXME: Consider GPIO IRQs with level detections properly! */
2099 gen = l & (~(bank->saved_fallingdetect) &
2100 ~(bank->saved_risingdetect));
2101 /* Consider all GPIO IRQs needed to be updated */
2102 gen |= gen0 | gen1;
2103
2104 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002105 u32 old0, old1;
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002106#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002107 old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2108 old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002109 __raw_writel(old0 | gen, bank->base +
2110 OMAP24XX_GPIO_LEVELDETECT0);
2111 __raw_writel(old1 | gen, bank->base +
2112 OMAP24XX_GPIO_LEVELDETECT1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002113 __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2114 __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002115#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302116#ifdef CONFIG_ARCH_OMAP4
2117 old0 = __raw_readl(bank->base +
2118 OMAP4_GPIO_LEVELDETECT0);
2119 old1 = __raw_readl(bank->base +
2120 OMAP4_GPIO_LEVELDETECT1);
2121 __raw_writel(old0 | l, bank->base +
2122 OMAP4_GPIO_LEVELDETECT0);
2123 __raw_writel(old1 | l, bank->base +
2124 OMAP4_GPIO_LEVELDETECT1);
2125 __raw_writel(old0, bank->base +
2126 OMAP4_GPIO_LEVELDETECT0);
2127 __raw_writel(old1, bank->base +
2128 OMAP4_GPIO_LEVELDETECT1);
2129#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002130 }
2131 }
2132
2133}
2134
Tony Lindgren92105bb2005-09-07 17:20:26 +01002135#endif
2136
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002137#ifdef CONFIG_ARCH_OMAP3
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302138/* save the registers of bank 2-6 */
2139void omap_gpio_save_context(void)
2140{
2141 int i;
2142
2143 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2144 for (i = 1; i < gpio_bank_count; i++) {
2145 struct gpio_bank *bank = &gpio_bank[i];
2146 gpio_context[i].sysconfig =
2147 __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG);
2148 gpio_context[i].irqenable1 =
2149 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
2150 gpio_context[i].irqenable2 =
2151 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
2152 gpio_context[i].wake_en =
2153 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
2154 gpio_context[i].ctrl =
2155 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
2156 gpio_context[i].oe =
2157 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
2158 gpio_context[i].leveldetect0 =
2159 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2160 gpio_context[i].leveldetect1 =
2161 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2162 gpio_context[i].risingdetect =
2163 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
2164 gpio_context[i].fallingdetect =
2165 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2166 gpio_context[i].dataout =
2167 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
2168 gpio_context[i].setwkuena =
2169 __raw_readl(bank->base + OMAP24XX_GPIO_SETWKUENA);
2170 gpio_context[i].setdataout =
2171 __raw_readl(bank->base + OMAP24XX_GPIO_SETDATAOUT);
2172 }
2173}
2174
2175/* restore the required registers of bank 2-6 */
2176void omap_gpio_restore_context(void)
2177{
2178 int i;
2179
2180 for (i = 1; i < gpio_bank_count; i++) {
2181 struct gpio_bank *bank = &gpio_bank[i];
2182 __raw_writel(gpio_context[i].sysconfig,
2183 bank->base + OMAP24XX_GPIO_SYSCONFIG);
2184 __raw_writel(gpio_context[i].irqenable1,
2185 bank->base + OMAP24XX_GPIO_IRQENABLE1);
2186 __raw_writel(gpio_context[i].irqenable2,
2187 bank->base + OMAP24XX_GPIO_IRQENABLE2);
2188 __raw_writel(gpio_context[i].wake_en,
2189 bank->base + OMAP24XX_GPIO_WAKE_EN);
2190 __raw_writel(gpio_context[i].ctrl,
2191 bank->base + OMAP24XX_GPIO_CTRL);
2192 __raw_writel(gpio_context[i].oe,
2193 bank->base + OMAP24XX_GPIO_OE);
2194 __raw_writel(gpio_context[i].leveldetect0,
2195 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2196 __raw_writel(gpio_context[i].leveldetect1,
2197 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2198 __raw_writel(gpio_context[i].risingdetect,
2199 bank->base + OMAP24XX_GPIO_RISINGDETECT);
2200 __raw_writel(gpio_context[i].fallingdetect,
2201 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2202 __raw_writel(gpio_context[i].dataout,
2203 bank->base + OMAP24XX_GPIO_DATAOUT);
2204 __raw_writel(gpio_context[i].setwkuena,
2205 bank->base + OMAP24XX_GPIO_SETWKUENA);
2206 __raw_writel(gpio_context[i].setdataout,
2207 bank->base + OMAP24XX_GPIO_SETDATAOUT);
2208 }
2209}
2210#endif
2211
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002212/*
2213 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002214 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002215 */
David Brownell277d58e2006-12-06 17:13:59 -08002216int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002217{
2218 if (!initialized)
2219 return _omap_gpio_init();
2220 else
2221 return 0;
2222}
2223
Tony Lindgren92105bb2005-09-07 17:20:26 +01002224static int __init omap_gpio_sysinit(void)
2225{
2226 int ret = 0;
2227
2228 if (!initialized)
2229 ret = _omap_gpio_init();
2230
David Brownell11a78b72006-12-06 17:14:11 -08002231 mpuio_init();
2232
Tony Lindgren140455f2010-02-12 12:26:48 -08002233#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002234 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002235 if (ret == 0) {
2236 ret = sysdev_class_register(&omap_gpio_sysclass);
2237 if (ret == 0)
2238 ret = sysdev_register(&omap_gpio_device);
2239 }
2240 }
2241#endif
2242
2243 return ret;
2244}
2245
Tony Lindgren92105bb2005-09-07 17:20:26 +01002246arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002247
2248
2249#ifdef CONFIG_DEBUG_FS
2250
2251#include <linux/debugfs.h>
2252#include <linux/seq_file.h>
2253
David Brownellb9772a22006-12-06 17:13:53 -08002254static int dbg_gpio_show(struct seq_file *s, void *unused)
2255{
2256 unsigned i, j, gpio;
2257
2258 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2259 struct gpio_bank *bank = gpio_bank + i;
2260 unsigned bankwidth = 16;
2261 u32 mask = 1;
2262
David Brownelle5c56ed2006-12-06 17:13:59 -08002263 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002264 gpio = OMAP_MPUIO(0);
Alistair Buxtonb718aa82009-09-23 18:56:19 +01002265 else if (cpu_class_is_omap2() || cpu_is_omap7xx())
David Brownellb9772a22006-12-06 17:13:53 -08002266 bankwidth = 32;
2267
2268 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2269 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002270 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002271
David Brownell52e31342008-03-03 12:43:23 -08002272 label = gpiochip_is_requested(&bank->chip, j);
2273 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002274 continue;
2275
2276 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002277 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002278 is_in = gpio_is_input(bank, mask);
2279
David Brownelle5c56ed2006-12-06 17:13:59 -08002280 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002281 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002282 else
David Brownell52e31342008-03-03 12:43:23 -08002283 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002284 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002285 label,
David Brownellb9772a22006-12-06 17:13:53 -08002286 is_in ? "in " : "out",
2287 value ? "hi" : "lo");
2288
David Brownell52e31342008-03-03 12:43:23 -08002289/* FIXME for at least omap2, show pullup/pulldown state */
2290
David Brownellb9772a22006-12-06 17:13:53 -08002291 irqstat = irq_desc[irq].status;
Tony Lindgren140455f2010-02-12 12:26:48 -08002292#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
David Brownellb9772a22006-12-06 17:13:53 -08002293 if (is_in && ((bank->suspend_wakeup & mask)
2294 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2295 char *trigger = NULL;
2296
2297 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2298 case IRQ_TYPE_EDGE_FALLING:
2299 trigger = "falling";
2300 break;
2301 case IRQ_TYPE_EDGE_RISING:
2302 trigger = "rising";
2303 break;
2304 case IRQ_TYPE_EDGE_BOTH:
2305 trigger = "bothedge";
2306 break;
2307 case IRQ_TYPE_LEVEL_LOW:
2308 trigger = "low";
2309 break;
2310 case IRQ_TYPE_LEVEL_HIGH:
2311 trigger = "high";
2312 break;
2313 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002314 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002315 break;
2316 }
David Brownell52e31342008-03-03 12:43:23 -08002317 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002318 irq, trigger,
2319 (bank->suspend_wakeup & mask)
2320 ? " wakeup" : "");
2321 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002322#endif
David Brownellb9772a22006-12-06 17:13:53 -08002323 seq_printf(s, "\n");
2324 }
2325
David Brownelle5c56ed2006-12-06 17:13:59 -08002326 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002327 seq_printf(s, "\n");
2328 gpio = 0;
2329 }
2330 }
2331 return 0;
2332}
2333
2334static int dbg_gpio_open(struct inode *inode, struct file *file)
2335{
David Brownelle5c56ed2006-12-06 17:13:59 -08002336 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002337}
2338
2339static const struct file_operations debug_fops = {
2340 .open = dbg_gpio_open,
2341 .read = seq_read,
2342 .llseek = seq_lseek,
2343 .release = single_release,
2344};
2345
2346static int __init omap_gpio_debuginit(void)
2347{
David Brownelle5c56ed2006-12-06 17:13:59 -08002348 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2349 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002350 return 0;
2351}
2352late_initcall(omap_gpio_debuginit);
2353#endif