blob: b71052c6581bba8f342ca2f9544239fa7d262840 [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;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700180#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
181 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100182 u32 suspend_wakeup;
183 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800184#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700185#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
186 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800187 u32 non_wakeup_gpios;
188 u32 enabled_non_wakeup_gpios;
189
190 u32 saved_datain;
191 u32 saved_fallingdetect;
192 u32 saved_risingdetect;
193#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800194 u32 level_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100195 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800196 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800197 struct clk *dbck;
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 Lindgren92105bb2005-09-07 17:20:26 +0100249#ifdef CONFIG_ARCH_OMAP24XX
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
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800277#ifdef CONFIG_ARCH_OMAP34XX
278static 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{
393 if (unlikely(gpio_valid(gpio)) < 0) {
394 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;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100425 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800426#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530427#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
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;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100487 l = __raw_readl(reg);
488 if (enable)
489 l |= 1 << gpio;
490 else
491 l &= ~(1 << gpio);
492 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800493#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530494#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
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;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100545 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800546#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530547#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
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
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300593#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
594 defined(CONFIG_ARCH_OMAP4)
595 case METHOD_GPIO_24XX:
596 reg += OMAP24XX_GPIO_DATAOUT;
597 break;
598#endif
599 default:
600 return -EINVAL;
601 }
602
603 return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
604}
605
Tony Lindgren92105bb2005-09-07 17:20:26 +0100606#define MOD_REG_BIT(reg, bit_mask, set) \
607do { \
608 int l = __raw_readl(base + reg); \
609 if (set) l |= bit_mask; \
610 else l &= ~bit_mask; \
611 __raw_writel(l, base + reg); \
612} while(0)
613
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700614void omap_set_gpio_debounce(int gpio, int enable)
615{
616 struct gpio_bank *bank;
617 void __iomem *reg;
David Brownelle031ab22008-12-10 17:35:27 -0800618 unsigned long flags;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700619 u32 val, l = 1 << get_gpio_index(gpio);
620
621 if (cpu_class_is_omap1())
622 return;
623
624 bank = get_gpio_bank(gpio);
625 reg = bank->base;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530626#ifdef CONFIG_ARCH_OMAP4
627 reg += OMAP4_GPIO_DEBOUNCENABLE;
628#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700629 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530630#endif
David Brownelle031ab22008-12-10 17:35:27 -0800631
632 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700633 val = __raw_readl(reg);
634
Jouni Hogander89db9482008-12-10 17:35:24 -0800635 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700636 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800637 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700638 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800639 else
David Brownelle031ab22008-12-10 17:35:27 -0800640 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800641
Santosh Shilimkar44169072009-05-28 14:16:04 -0700642 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800643 if (enable)
644 clk_enable(bank->dbck);
645 else
646 clk_disable(bank->dbck);
647 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700648
649 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800650done:
651 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700652}
653EXPORT_SYMBOL(omap_set_gpio_debounce);
654
655void omap_set_gpio_debounce_time(int gpio, int enc_time)
656{
657 struct gpio_bank *bank;
658 void __iomem *reg;
659
660 if (cpu_class_is_omap1())
661 return;
662
663 bank = get_gpio_bank(gpio);
664 reg = bank->base;
665
666 enc_time &= 0xff;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530667#ifdef CONFIG_ARCH_OMAP4
668 reg += OMAP4_GPIO_DEBOUNCINGTIME;
669#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700670 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530671#endif
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700672 __raw_writel(enc_time, reg);
673}
674EXPORT_SYMBOL(omap_set_gpio_debounce_time);
675
Santosh Shilimkar44169072009-05-28 14:16:04 -0700676#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
677 defined(CONFIG_ARCH_OMAP4)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700678static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
679 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100680{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800681 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100682 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530683 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100684
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530685 if (cpu_is_omap44xx()) {
686 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
687 trigger & IRQ_TYPE_LEVEL_LOW);
688 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
689 trigger & IRQ_TYPE_LEVEL_HIGH);
690 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
691 trigger & IRQ_TYPE_EDGE_RISING);
692 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
693 trigger & IRQ_TYPE_EDGE_FALLING);
694 } else {
695 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
696 trigger & IRQ_TYPE_LEVEL_LOW);
697 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
698 trigger & IRQ_TYPE_LEVEL_HIGH);
699 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
700 trigger & IRQ_TYPE_EDGE_RISING);
701 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
702 trigger & IRQ_TYPE_EDGE_FALLING);
703 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800704 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530705 if (cpu_is_omap44xx()) {
706 if (trigger != 0)
707 __raw_writel(1 << gpio, bank->base+
708 OMAP4_GPIO_IRQWAKEN0);
709 else {
710 val = __raw_readl(bank->base +
711 OMAP4_GPIO_IRQWAKEN0);
712 __raw_writel(val & (~(1 << gpio)), bank->base +
713 OMAP4_GPIO_IRQWAKEN0);
714 }
715 } else {
716 if (trigger != 0)
717 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700718 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530719 else
720 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700721 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530722 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800723 } else {
724 if (trigger != 0)
725 bank->enabled_non_wakeup_gpios |= gpio_bit;
726 else
727 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
728 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700729
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530730 if (cpu_is_omap44xx()) {
731 bank->level_mask =
732 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
733 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
734 } else {
735 bank->level_mask =
736 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
737 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
738 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100739}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800740#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100741
742static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
743{
744 void __iomem *reg = bank->base;
745 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100746
747 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800748#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100749 case METHOD_MPUIO:
750 reg += OMAP_MPUIO_GPIO_INT_EDGE;
751 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100752 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100753 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100754 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100755 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100756 else
757 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100758 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800759#endif
760#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100761 case METHOD_GPIO_1510:
762 reg += OMAP1510_GPIO_INT_CONTROL;
763 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100764 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100765 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100766 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100767 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100768 else
769 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100770 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800771#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800772#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100773 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100774 if (gpio & 0x08)
775 reg += OMAP1610_GPIO_EDGE_CTRL2;
776 else
777 reg += OMAP1610_GPIO_EDGE_CTRL1;
778 gpio &= 0x07;
779 l = __raw_readl(reg);
780 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100781 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100782 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100783 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100784 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800785 if (trigger)
786 /* Enable wake-up during idle for dynamic tick */
787 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
788 else
789 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100790 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800791#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100792#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100793 case METHOD_GPIO_7XX:
794 reg += OMAP7XX_GPIO_INT_CONTROL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100795 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100796 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100797 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100798 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100799 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100800 else
801 goto bad;
802 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800803#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700804#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
805 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100806 case METHOD_GPIO_24XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800807 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100808 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800809#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100810 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100811 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100812 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100813 __raw_writel(l, reg);
814 return 0;
815bad:
816 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100817}
818
Tony Lindgren92105bb2005-09-07 17:20:26 +0100819static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100820{
821 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100822 unsigned gpio;
823 int retval;
David Brownella6472532008-03-03 04:33:30 -0800824 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100825
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800826 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100827 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
828 else
829 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100830
831 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100832 return -EINVAL;
833
David Brownelle5c56ed2006-12-06 17:13:59 -0800834 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100835 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800836
837 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800838 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800839 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100840 return -EINVAL;
841
David Brownell58781012006-12-06 17:14:10 -0800842 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800843 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100844 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800845 if (retval == 0) {
846 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
847 irq_desc[irq].status |= type;
848 }
David Brownella6472532008-03-03 04:33:30 -0800849 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800850
851 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
852 __set_irq_handler_unlocked(irq, handle_level_irq);
853 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
854 __set_irq_handler_unlocked(irq, handle_edge_irq);
855
Tony Lindgren92105bb2005-09-07 17:20:26 +0100856 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100857}
858
859static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
860{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100861 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100862
863 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800864#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100865 case METHOD_MPUIO:
866 /* MPUIO irqstatus is reset by reading the status register,
867 * so do nothing here */
868 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800869#endif
870#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100871 case METHOD_GPIO_1510:
872 reg += OMAP1510_GPIO_INT_STATUS;
873 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800874#endif
875#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100876 case METHOD_GPIO_1610:
877 reg += OMAP1610_GPIO_IRQSTATUS1;
878 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800879#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100880#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100881 case METHOD_GPIO_7XX:
882 reg += OMAP7XX_GPIO_INT_STATUS;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100883 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800884#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530885#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100886 case METHOD_GPIO_24XX:
887 reg += OMAP24XX_GPIO_IRQSTATUS1;
888 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800889#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530890#if defined(CONFIG_ARCH_OMAP4)
891 case METHOD_GPIO_24XX:
892 reg += OMAP4_GPIO_IRQSTATUS0;
893 break;
894#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100895 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800896 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100897 return;
898 }
899 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300900
901 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800902#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Roger Quadrosbedfd152009-04-23 11:10:50 -0700903 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530904#endif
905#if defined(CONFIG_ARCH_OMAP4)
906 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
907#endif
908 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700909 __raw_writel(gpio_mask, reg);
910
911 /* Flush posted write for the irq status to avoid spurious interrupts */
912 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530913 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100914}
915
916static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
917{
918 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
919}
920
Imre Deakea6dedd2006-06-26 16:16:00 -0700921static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
922{
923 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700924 int inv = 0;
925 u32 l;
926 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700927
928 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800929#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700930 case METHOD_MPUIO:
931 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700932 mask = 0xffff;
933 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700934 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800935#endif
936#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700937 case METHOD_GPIO_1510:
938 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700939 mask = 0xffff;
940 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700941 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800942#endif
943#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700944 case METHOD_GPIO_1610:
945 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700946 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700947 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800948#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100949#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100950 case METHOD_GPIO_7XX:
951 reg += OMAP7XX_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700952 mask = 0xffffffff;
953 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700954 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800955#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530956#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Imre Deakea6dedd2006-06-26 16:16:00 -0700957 case METHOD_GPIO_24XX:
958 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700959 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700960 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800961#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530962#if defined(CONFIG_ARCH_OMAP4)
963 case METHOD_GPIO_24XX:
964 reg += OMAP4_GPIO_IRQSTATUSSET0;
965 mask = 0xffffffff;
966 break;
967#endif
Imre Deakea6dedd2006-06-26 16:16:00 -0700968 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800969 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -0700970 return 0;
971 }
972
Imre Deak99c47702006-06-26 16:16:07 -0700973 l = __raw_readl(reg);
974 if (inv)
975 l = ~l;
976 l &= mask;
977 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700978}
979
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100980static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
981{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100982 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100983 u32 l;
984
985 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800986#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100987 case METHOD_MPUIO:
988 reg += OMAP_MPUIO_GPIO_MASKIT;
989 l = __raw_readl(reg);
990 if (enable)
991 l &= ~(gpio_mask);
992 else
993 l |= gpio_mask;
994 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800995#endif
996#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100997 case METHOD_GPIO_1510:
998 reg += OMAP1510_GPIO_INT_MASK;
999 l = __raw_readl(reg);
1000 if (enable)
1001 l &= ~(gpio_mask);
1002 else
1003 l |= gpio_mask;
1004 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001005#endif
1006#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001007 case METHOD_GPIO_1610:
1008 if (enable)
1009 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1010 else
1011 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1012 l = gpio_mask;
1013 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001014#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001015#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001016 case METHOD_GPIO_7XX:
1017 reg += OMAP7XX_GPIO_INT_MASK;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001018 l = __raw_readl(reg);
1019 if (enable)
1020 l &= ~(gpio_mask);
1021 else
1022 l |= gpio_mask;
1023 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001024#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301025#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001026 case METHOD_GPIO_24XX:
1027 if (enable)
1028 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1029 else
1030 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1031 l = gpio_mask;
1032 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001033#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301034#ifdef CONFIG_ARCH_OMAP4
1035 case METHOD_GPIO_24XX:
1036 if (enable)
1037 reg += OMAP4_GPIO_IRQSTATUSSET0;
1038 else
1039 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1040 l = gpio_mask;
1041 break;
1042#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001043 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001044 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001045 return;
1046 }
1047 __raw_writel(l, reg);
1048}
1049
1050static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1051{
1052 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1053}
1054
Tony Lindgren92105bb2005-09-07 17:20:26 +01001055/*
1056 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1057 * 1510 does not seem to have a wake-up register. If JTAG is connected
1058 * to the target, system will wake up always on GPIO events. While
1059 * system is running all registered GPIO interrupts need to have wake-up
1060 * enabled. When system is suspended, only selected GPIO interrupts need
1061 * to have wake-up enabled.
1062 */
1063static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1064{
David Brownella6472532008-03-03 04:33:30 -08001065 unsigned long flags;
1066
Tony Lindgren92105bb2005-09-07 17:20:26 +01001067 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001068#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001069 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001070 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001071 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001072 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001073 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001074 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001075 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001076 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001077 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001078#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001079#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1080 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001081 case METHOD_GPIO_24XX:
David Brownell11a78b72006-12-06 17:14:11 -08001082 if (bank->non_wakeup_gpios & (1 << gpio)) {
1083 printk(KERN_ERR "Unable to modify wakeup on "
1084 "non-wakeup GPIO%d\n",
1085 (bank - gpio_bank) * 32 + gpio);
1086 return -EINVAL;
1087 }
David Brownella6472532008-03-03 04:33:30 -08001088 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001089 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001090 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001091 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001092 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001093 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001094 return 0;
1095#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001096 default:
1097 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1098 bank->method);
1099 return -EINVAL;
1100 }
1101}
1102
Tony Lindgren4196dd62006-09-25 12:41:38 +03001103static void _reset_gpio(struct gpio_bank *bank, int gpio)
1104{
1105 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1106 _set_gpio_irqenable(bank, gpio, 0);
1107 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001108 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001109}
1110
Tony Lindgren92105bb2005-09-07 17:20:26 +01001111/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1112static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1113{
1114 unsigned int gpio = irq - IH_GPIO_BASE;
1115 struct gpio_bank *bank;
1116 int retval;
1117
1118 if (check_gpio(gpio) < 0)
1119 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001120 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001121 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001122
1123 return retval;
1124}
1125
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001126static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001127{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001128 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001129 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001130
David Brownella6472532008-03-03 04:33:30 -08001131 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001132
Tony Lindgren4196dd62006-09-25 12:41:38 +03001133 /* Set trigger to none. You need to enable the desired trigger with
1134 * request_irq() or set_irq_type().
1135 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001136 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001137
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001138#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001139 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001140 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001141
Tony Lindgren92105bb2005-09-07 17:20:26 +01001142 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001143 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001144 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001145 }
1146#endif
David Brownella6472532008-03-03 04:33:30 -08001147 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001148
1149 return 0;
1150}
1151
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001152static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001153{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001154 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001155 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001156
David Brownella6472532008-03-03 04:33:30 -08001157 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001158#ifdef CONFIG_ARCH_OMAP16XX
1159 if (bank->method == METHOD_GPIO_1610) {
1160 /* Disable wake-up during idle for dynamic tick */
1161 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001162 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001163 }
1164#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001165#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1166 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001167 if (bank->method == METHOD_GPIO_24XX) {
1168 /* Disable wake-up during idle for dynamic tick */
1169 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001170 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001171 }
1172#endif
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001173 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001174 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001175}
1176
1177/*
1178 * We need to unmask the GPIO bank interrupt as soon as possible to
1179 * avoid missing GPIO interrupts for other lines in the bank.
1180 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1181 * in the bank to avoid missing nested interrupts for a GPIO line.
1182 * If we wait to unmask individual GPIO lines in the bank after the
1183 * line's interrupt handler has been run, we may miss some nested
1184 * interrupts.
1185 */
Russell King10dd5ce2006-11-23 11:41:32 +00001186static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001187{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001188 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001189 u32 isr;
1190 unsigned int gpio_irq;
1191 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001192 u32 retrigger = 0;
1193 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001194
1195 desc->chip->ack(irq);
1196
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001197 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001198#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001199 if (bank->method == METHOD_MPUIO)
1200 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001201#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001202#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001203 if (bank->method == METHOD_GPIO_1510)
1204 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1205#endif
1206#if defined(CONFIG_ARCH_OMAP16XX)
1207 if (bank->method == METHOD_GPIO_1610)
1208 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1209#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001210#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001211 if (bank->method == METHOD_GPIO_7XX)
1212 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001213#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301214#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001215 if (bank->method == METHOD_GPIO_24XX)
1216 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1217#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301218#if defined(CONFIG_ARCH_OMAP4)
1219 if (bank->method == METHOD_GPIO_24XX)
1220 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1221#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001222 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001223 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001224 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001225
Imre Deakea6dedd2006-06-26 16:16:00 -07001226 enabled = _get_gpio_irqbank_mask(bank);
1227 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001228
1229 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1230 isr &= 0x0000ffff;
1231
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001232 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001233 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001234 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001235
1236 /* clear edge sensitive interrupts before handler(s) are
1237 called so that we don't miss any interrupt occurred while
1238 executing them */
1239 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1240 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1241 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1242
1243 /* if there is only edge sensitive GPIO pin interrupts
1244 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001245 if (!level_mask && !unmasked) {
1246 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001247 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001248 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001249
Imre Deakea6dedd2006-06-26 16:16:00 -07001250 isr |= retrigger;
1251 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001252 if (!isr)
1253 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001254
Tony Lindgren92105bb2005-09-07 17:20:26 +01001255 gpio_irq = bank->virtual_irq_start;
1256 for (; isr != 0; isr >>= 1, gpio_irq++) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001257 if (!(isr & 1))
1258 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001259
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001260 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001261 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001262 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001263 /* if bank has any level sensitive GPIO pin interrupt
1264 configured, we must unmask the bank interrupt only after
1265 handler(s) are executed in order to avoid spurious bank
1266 interrupt */
1267 if (!unmasked)
1268 desc->chip->unmask(irq);
1269
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001270}
1271
Tony Lindgren4196dd62006-09-25 12:41:38 +03001272static void gpio_irq_shutdown(unsigned int irq)
1273{
1274 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001275 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001276
1277 _reset_gpio(bank, gpio);
1278}
1279
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001280static void gpio_ack_irq(unsigned int irq)
1281{
1282 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001283 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001284
1285 _clear_gpio_irqstatus(bank, gpio);
1286}
1287
1288static void gpio_mask_irq(unsigned int irq)
1289{
1290 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001291 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001292
1293 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001294 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001295}
1296
1297static void gpio_unmask_irq(unsigned int irq)
1298{
1299 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001300 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001301 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001302 struct irq_desc *desc = irq_to_desc(irq);
1303 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1304
1305 if (trigger)
1306 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001307
1308 /* For level-triggered GPIOs, the clearing must be done after
1309 * the HW source is cleared, thus after the handler has run */
1310 if (bank->level_mask & irq_mask) {
1311 _set_gpio_irqenable(bank, gpio, 0);
1312 _clear_gpio_irqstatus(bank, gpio);
1313 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001314
Kevin Hilman4de8c752008-01-16 21:56:14 -08001315 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001316}
1317
David Brownelle5c56ed2006-12-06 17:13:59 -08001318static struct irq_chip gpio_irq_chip = {
1319 .name = "GPIO",
1320 .shutdown = gpio_irq_shutdown,
1321 .ack = gpio_ack_irq,
1322 .mask = gpio_mask_irq,
1323 .unmask = gpio_unmask_irq,
1324 .set_type = gpio_irq_type,
1325 .set_wake = gpio_wake_enable,
1326};
1327
1328/*---------------------------------------------------------------------*/
1329
1330#ifdef CONFIG_ARCH_OMAP1
1331
1332/* MPUIO uses the always-on 32k clock */
1333
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001334static void mpuio_ack_irq(unsigned int irq)
1335{
1336 /* The ISR is reset automatically, so do nothing here. */
1337}
1338
1339static void mpuio_mask_irq(unsigned int irq)
1340{
1341 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001342 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001343
1344 _set_gpio_irqenable(bank, gpio, 0);
1345}
1346
1347static void mpuio_unmask_irq(unsigned int irq)
1348{
1349 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001350 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001351
1352 _set_gpio_irqenable(bank, gpio, 1);
1353}
1354
David Brownelle5c56ed2006-12-06 17:13:59 -08001355static struct irq_chip mpuio_irq_chip = {
1356 .name = "MPUIO",
1357 .ack = mpuio_ack_irq,
1358 .mask = mpuio_mask_irq,
1359 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001360 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001361#ifdef CONFIG_ARCH_OMAP16XX
1362 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1363 .set_wake = gpio_wake_enable,
1364#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001365};
1366
David Brownelle5c56ed2006-12-06 17:13:59 -08001367
1368#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1369
David Brownell11a78b72006-12-06 17:14:11 -08001370
1371#ifdef CONFIG_ARCH_OMAP16XX
1372
1373#include <linux/platform_device.h>
1374
Magnus Damm79ee0312009-07-08 13:22:04 +02001375static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001376{
Magnus Damm79ee0312009-07-08 13:22:04 +02001377 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001378 struct gpio_bank *bank = platform_get_drvdata(pdev);
1379 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001380 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001381
David Brownella6472532008-03-03 04:33:30 -08001382 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001383 bank->saved_wakeup = __raw_readl(mask_reg);
1384 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001385 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001386
1387 return 0;
1388}
1389
Magnus Damm79ee0312009-07-08 13:22:04 +02001390static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001391{
Magnus Damm79ee0312009-07-08 13:22:04 +02001392 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001393 struct gpio_bank *bank = platform_get_drvdata(pdev);
1394 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001395 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001396
David Brownella6472532008-03-03 04:33:30 -08001397 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001398 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001399 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001400
1401 return 0;
1402}
1403
Magnus Damm79ee0312009-07-08 13:22:04 +02001404static struct dev_pm_ops omap_mpuio_dev_pm_ops = {
1405 .suspend_noirq = omap_mpuio_suspend_noirq,
1406 .resume_noirq = omap_mpuio_resume_noirq,
1407};
1408
David Brownell11a78b72006-12-06 17:14:11 -08001409/* use platform_driver for this, now that there's no longer any
1410 * point to sys_device (other than not disturbing old code).
1411 */
1412static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001413 .driver = {
1414 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001415 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001416 },
1417};
1418
1419static struct platform_device omap_mpuio_device = {
1420 .name = "mpuio",
1421 .id = -1,
1422 .dev = {
1423 .driver = &omap_mpuio_driver.driver,
1424 }
1425 /* could list the /proc/iomem resources */
1426};
1427
1428static inline void mpuio_init(void)
1429{
David Brownellfcf126d2007-04-02 12:46:47 -07001430 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1431
David Brownell11a78b72006-12-06 17:14:11 -08001432 if (platform_driver_register(&omap_mpuio_driver) == 0)
1433 (void) platform_device_register(&omap_mpuio_device);
1434}
1435
1436#else
1437static inline void mpuio_init(void) {}
1438#endif /* 16xx */
1439
David Brownelle5c56ed2006-12-06 17:13:59 -08001440#else
1441
1442extern struct irq_chip mpuio_irq_chip;
1443
1444#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001445static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001446
1447#endif
1448
1449/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001450
David Brownell52e31342008-03-03 12:43:23 -08001451/* REVISIT these are stupid implementations! replace by ones that
1452 * don't switch on METHOD_* and which mostly avoid spinlocks
1453 */
1454
1455static int gpio_input(struct gpio_chip *chip, unsigned offset)
1456{
1457 struct gpio_bank *bank;
1458 unsigned long flags;
1459
1460 bank = container_of(chip, struct gpio_bank, chip);
1461 spin_lock_irqsave(&bank->lock, flags);
1462 _set_gpio_direction(bank, offset, 1);
1463 spin_unlock_irqrestore(&bank->lock, flags);
1464 return 0;
1465}
1466
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001467static int gpio_is_input(struct gpio_bank *bank, int mask)
1468{
1469 void __iomem *reg = bank->base;
1470
1471 switch (bank->method) {
1472 case METHOD_MPUIO:
1473 reg += OMAP_MPUIO_IO_CNTL;
1474 break;
1475 case METHOD_GPIO_1510:
1476 reg += OMAP1510_GPIO_DIR_CONTROL;
1477 break;
1478 case METHOD_GPIO_1610:
1479 reg += OMAP1610_GPIO_DIRECTION;
1480 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001481 case METHOD_GPIO_7XX:
1482 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001483 break;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001484 case METHOD_GPIO_24XX:
1485 reg += OMAP24XX_GPIO_OE;
1486 break;
1487 }
1488 return __raw_readl(reg) & mask;
1489}
1490
David Brownell52e31342008-03-03 12:43:23 -08001491static int gpio_get(struct gpio_chip *chip, unsigned offset)
1492{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001493 struct gpio_bank *bank;
1494 void __iomem *reg;
1495 int gpio;
1496 u32 mask;
1497
1498 gpio = chip->base + offset;
1499 bank = get_gpio_bank(gpio);
1500 reg = bank->base;
1501 mask = 1 << get_gpio_index(gpio);
1502
1503 if (gpio_is_input(bank, mask))
1504 return _get_gpio_datain(bank, gpio);
1505 else
1506 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001507}
1508
1509static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1510{
1511 struct gpio_bank *bank;
1512 unsigned long flags;
1513
1514 bank = container_of(chip, struct gpio_bank, chip);
1515 spin_lock_irqsave(&bank->lock, flags);
1516 _set_gpio_dataout(bank, offset, value);
1517 _set_gpio_direction(bank, offset, 0);
1518 spin_unlock_irqrestore(&bank->lock, flags);
1519 return 0;
1520}
1521
1522static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1523{
1524 struct gpio_bank *bank;
1525 unsigned long flags;
1526
1527 bank = container_of(chip, struct gpio_bank, chip);
1528 spin_lock_irqsave(&bank->lock, flags);
1529 _set_gpio_dataout(bank, offset, value);
1530 spin_unlock_irqrestore(&bank->lock, flags);
1531}
1532
David Brownella007b702008-12-10 17:35:25 -08001533static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1534{
1535 struct gpio_bank *bank;
1536
1537 bank = container_of(chip, struct gpio_bank, chip);
1538 return bank->virtual_irq_start + offset;
1539}
1540
David Brownell52e31342008-03-03 12:43:23 -08001541/*---------------------------------------------------------------------*/
1542
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001543static int initialized;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001544#if !(defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001545static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001546#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001547
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001548#if defined(CONFIG_ARCH_OMAP2)
1549static struct clk * gpio_fck;
1550#endif
1551
1552#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001553static struct clk * gpio5_ick;
1554static struct clk * gpio5_fck;
1555#endif
1556
Santosh Shilimkar44169072009-05-28 14:16:04 -07001557#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001558static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1559#endif
1560
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001561static void __init omap_gpio_show_rev(void)
1562{
1563 u32 rev;
1564
1565 if (cpu_is_omap16xx())
1566 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1567 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1568 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1569 else if (cpu_is_omap44xx())
1570 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1571 else
1572 return;
1573
1574 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1575 (rev >> 4) & 0x0f, rev & 0x0f);
1576}
1577
David Brownell8ba55c52008-02-26 11:10:50 -08001578/* This lock class tells lockdep that GPIO irqs are in a different
1579 * category than their parents, so it won't report false recursion.
1580 */
1581static struct lock_class_key gpio_lock_class;
1582
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001583static int __init _omap_gpio_init(void)
1584{
1585 int i;
David Brownell52e31342008-03-03 12:43:23 -08001586 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001587 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001588 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001589 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001590
1591 initialized = 1;
1592
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001593#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001594 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001595 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1596 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001597 printk("Could not get arm_gpio_ck\n");
1598 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001599 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001600 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001601#endif
1602#if defined(CONFIG_ARCH_OMAP2)
1603 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001604 gpio_ick = clk_get(NULL, "gpios_ick");
1605 if (IS_ERR(gpio_ick))
1606 printk("Could not get gpios_ick\n");
1607 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001608 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001609 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001610 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001611 printk("Could not get gpios_fck\n");
1612 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001613 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001614
1615 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001616 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001617 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001618#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001619 if (cpu_is_omap2430()) {
1620 gpio5_ick = clk_get(NULL, "gpio5_ick");
1621 if (IS_ERR(gpio5_ick))
1622 printk("Could not get gpio5_ick\n");
1623 else
1624 clk_enable(gpio5_ick);
1625 gpio5_fck = clk_get(NULL, "gpio5_fck");
1626 if (IS_ERR(gpio5_fck))
1627 printk("Could not get gpio5_fck\n");
1628 else
1629 clk_enable(gpio5_fck);
1630 }
1631#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001632 }
1633#endif
1634
Santosh Shilimkar44169072009-05-28 14:16:04 -07001635#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1636 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001637 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1638 sprintf(clk_name, "gpio%d_ick", i + 1);
1639 gpio_iclks[i] = clk_get(NULL, clk_name);
1640 if (IS_ERR(gpio_iclks[i]))
1641 printk(KERN_ERR "Could not get %s\n", clk_name);
1642 else
1643 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001644 }
1645 }
1646#endif
1647
Tony Lindgren92105bb2005-09-07 17:20:26 +01001648
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001649#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001650 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001651 gpio_bank_count = 2;
1652 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001653 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001654 }
1655#endif
1656#if defined(CONFIG_ARCH_OMAP16XX)
1657 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001658 gpio_bank_count = 5;
1659 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001660 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001661 }
1662#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001663#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1664 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001665 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001666 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001667 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001668 }
1669#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001670#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001671 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001672 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001673 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001674 }
1675 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001676 gpio_bank_count = 5;
1677 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001678 }
1679#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001680#ifdef CONFIG_ARCH_OMAP34XX
1681 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001682 gpio_bank_count = OMAP34XX_NR_GPIOS;
1683 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001684 }
1685#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001686#ifdef CONFIG_ARCH_OMAP4
1687 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001688 gpio_bank_count = OMAP34XX_NR_GPIOS;
1689 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001690 }
1691#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001692 for (i = 0; i < gpio_bank_count; i++) {
1693 int j, gpio_count = 16;
1694
1695 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001696 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001697
1698 /* Static mapping, never released */
1699 bank->base = ioremap(bank->pbase, bank_size);
1700 if (!bank->base) {
1701 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1702 continue;
1703 }
1704
David Brownelle5c56ed2006-12-06 17:13:59 -08001705 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001706 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001707 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001708 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1709 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1710 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001711 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001712 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1713 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001714 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001715 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001716 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1717 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1718 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001719
Alistair Buxton7c006922009-09-22 10:02:58 +01001720 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001721 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001722
Santosh Shilimkar44169072009-05-28 14:16:04 -07001723#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1724 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001725 if (bank->method == METHOD_GPIO_24XX) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001726 static const u32 non_wakeup_gpios[] = {
1727 0xe203ffc0, 0x08700040
1728 };
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301729 if (cpu_is_omap44xx()) {
1730 __raw_writel(0xffffffff, bank->base +
1731 OMAP4_GPIO_IRQSTATUSCLR0);
1732 __raw_writew(0x0015, bank->base +
1733 OMAP4_GPIO_SYSCONFIG);
1734 __raw_writel(0x00000000, bank->base +
1735 OMAP4_GPIO_DEBOUNCENABLE);
1736 /* Initialize interface clock ungated, module enabled */
1737 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1738 } else {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001739 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1740 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001741 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
janboecb5793d2009-06-23 13:30:25 +03001742 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_DEBOUNCE_EN);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001743
1744 /* Initialize interface clock ungated, module enabled */
1745 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301746 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001747 if (i < ARRAY_SIZE(non_wakeup_gpios))
1748 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001749 gpio_count = 32;
1750 }
1751#endif
David Brownell52e31342008-03-03 12:43:23 -08001752 /* REVISIT eventually switch from OMAP-specific gpio structs
1753 * over to the generic ones
1754 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001755 bank->chip.request = omap_gpio_request;
1756 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001757 bank->chip.direction_input = gpio_input;
1758 bank->chip.get = gpio_get;
1759 bank->chip.direction_output = gpio_output;
1760 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001761 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001762 if (bank_is_mpuio(bank)) {
1763 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001764#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001765 bank->chip.dev = &omap_mpuio_device.dev;
1766#endif
David Brownell52e31342008-03-03 12:43:23 -08001767 bank->chip.base = OMAP_MPUIO(0);
1768 } else {
1769 bank->chip.label = "gpio";
1770 bank->chip.base = gpio;
1771 gpio += gpio_count;
1772 }
1773 bank->chip.ngpio = gpio_count;
1774
1775 gpiochip_add(&bank->chip);
1776
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001777 for (j = bank->virtual_irq_start;
1778 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001779 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001780 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001781 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001782 set_irq_chip(j, &mpuio_irq_chip);
1783 else
1784 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001785 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001786 set_irq_flags(j, IRQF_VALID);
1787 }
1788 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1789 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001790
Santosh Shilimkar44169072009-05-28 14:16:04 -07001791 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001792 sprintf(clk_name, "gpio%d_dbck", i + 1);
1793 bank->dbck = clk_get(NULL, clk_name);
1794 if (IS_ERR(bank->dbck))
1795 printk(KERN_ERR "Could not get %s\n", clk_name);
1796 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001797 }
1798
1799 /* Enable system clock for GPIO module.
1800 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001801 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001802 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1803
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001804 /* Enable autoidle for the OCP interface */
1805 if (cpu_is_omap24xx())
1806 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001807 if (cpu_is_omap34xx())
1808 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001809
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001810 omap_gpio_show_rev();
1811
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001812 return 0;
1813}
1814
Santosh Shilimkar44169072009-05-28 14:16:04 -07001815#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1816 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001817static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1818{
1819 int i;
1820
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001821 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001822 return 0;
1823
1824 for (i = 0; i < gpio_bank_count; i++) {
1825 struct gpio_bank *bank = &gpio_bank[i];
1826 void __iomem *wake_status;
1827 void __iomem *wake_clear;
1828 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001829 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001830
1831 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001832#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001833 case METHOD_GPIO_1610:
1834 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1835 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1836 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1837 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001838#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301839#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001840 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001841 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001842 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1843 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1844 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001845#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301846#ifdef CONFIG_ARCH_OMAP4
1847 case METHOD_GPIO_24XX:
1848 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1849 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1850 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1851 break;
1852#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001853 default:
1854 continue;
1855 }
1856
David Brownella6472532008-03-03 04:33:30 -08001857 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001858 bank->saved_wakeup = __raw_readl(wake_status);
1859 __raw_writel(0xffffffff, wake_clear);
1860 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001861 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001862 }
1863
1864 return 0;
1865}
1866
1867static int omap_gpio_resume(struct sys_device *dev)
1868{
1869 int i;
1870
Tero Kristo723fdb72008-11-26 14:35:16 -08001871 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001872 return 0;
1873
1874 for (i = 0; i < gpio_bank_count; i++) {
1875 struct gpio_bank *bank = &gpio_bank[i];
1876 void __iomem *wake_clear;
1877 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001878 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001879
1880 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001881#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001882 case METHOD_GPIO_1610:
1883 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1884 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1885 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001886#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301887#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001888 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001889 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1890 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001891 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001892#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301893#ifdef CONFIG_ARCH_OMAP4
1894 case METHOD_GPIO_24XX:
1895 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1896 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1897 break;
1898#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001899 default:
1900 continue;
1901 }
1902
David Brownella6472532008-03-03 04:33:30 -08001903 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001904 __raw_writel(0xffffffff, wake_clear);
1905 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001906 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001907 }
1908
1909 return 0;
1910}
1911
1912static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01001913 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001914 .suspend = omap_gpio_suspend,
1915 .resume = omap_gpio_resume,
1916};
1917
1918static struct sys_device omap_gpio_device = {
1919 .id = 0,
1920 .cls = &omap_gpio_sysclass,
1921};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001922
1923#endif
1924
Santosh Shilimkar44169072009-05-28 14:16:04 -07001925#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1926 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001927
1928static int workaround_enabled;
1929
1930void omap2_gpio_prepare_for_retention(void)
1931{
1932 int i, c = 0;
1933
1934 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
1935 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
1936 for (i = 0; i < gpio_bank_count; i++) {
1937 struct gpio_bank *bank = &gpio_bank[i];
1938 u32 l1, l2;
1939
1940 if (!(bank->enabled_non_wakeup_gpios))
1941 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301942#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001943 bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1944 l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1945 l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001946#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301947#ifdef CONFIG_ARCH_OMAP4
1948 bank->saved_datain = __raw_readl(bank->base +
1949 OMAP4_GPIO_DATAIN);
1950 l1 = __raw_readl(bank->base + OMAP4_GPIO_FALLINGDETECT);
1951 l2 = __raw_readl(bank->base + OMAP4_GPIO_RISINGDETECT);
1952#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001953 bank->saved_fallingdetect = l1;
1954 bank->saved_risingdetect = l2;
1955 l1 &= ~bank->enabled_non_wakeup_gpios;
1956 l2 &= ~bank->enabled_non_wakeup_gpios;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301957#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001958 __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1959 __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001960#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301961#ifdef CONFIG_ARCH_OMAP4
1962 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
1963 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
1964#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001965 c++;
1966 }
1967 if (!c) {
1968 workaround_enabled = 0;
1969 return;
1970 }
1971 workaround_enabled = 1;
1972}
1973
1974void omap2_gpio_resume_after_retention(void)
1975{
1976 int i;
1977
1978 if (!workaround_enabled)
1979 return;
1980 for (i = 0; i < gpio_bank_count; i++) {
1981 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07001982 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001983
1984 if (!(bank->enabled_non_wakeup_gpios))
1985 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301986#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001987 __raw_writel(bank->saved_fallingdetect,
1988 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1989 __raw_writel(bank->saved_risingdetect,
1990 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301991 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1992#endif
1993#ifdef CONFIG_ARCH_OMAP4
1994 __raw_writel(bank->saved_fallingdetect,
1995 bank->base + OMAP4_GPIO_FALLINGDETECT);
1996 __raw_writel(bank->saved_risingdetect,
1997 bank->base + OMAP4_GPIO_RISINGDETECT);
1998 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001999#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002000 /* Check if any of the non-wakeup interrupt GPIOs have changed
2001 * state. If so, generate an IRQ by software. This is
2002 * horribly racy, but it's the best we can do to work around
2003 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002004 l ^= bank->saved_datain;
2005 l &= bank->non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002006
2007 /*
2008 * No need to generate IRQs for the rising edge for gpio IRQs
2009 * configured with falling edge only; and vice versa.
2010 */
2011 gen0 = l & bank->saved_fallingdetect;
2012 gen0 &= bank->saved_datain;
2013
2014 gen1 = l & bank->saved_risingdetect;
2015 gen1 &= ~(bank->saved_datain);
2016
2017 /* FIXME: Consider GPIO IRQs with level detections properly! */
2018 gen = l & (~(bank->saved_fallingdetect) &
2019 ~(bank->saved_risingdetect));
2020 /* Consider all GPIO IRQs needed to be updated */
2021 gen |= gen0 | gen1;
2022
2023 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002024 u32 old0, old1;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302025#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002026 old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2027 old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002028 __raw_writel(old0 | gen, bank->base +
2029 OMAP24XX_GPIO_LEVELDETECT0);
2030 __raw_writel(old1 | gen, bank->base +
2031 OMAP24XX_GPIO_LEVELDETECT1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002032 __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2033 __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002034#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302035#ifdef CONFIG_ARCH_OMAP4
2036 old0 = __raw_readl(bank->base +
2037 OMAP4_GPIO_LEVELDETECT0);
2038 old1 = __raw_readl(bank->base +
2039 OMAP4_GPIO_LEVELDETECT1);
2040 __raw_writel(old0 | l, bank->base +
2041 OMAP4_GPIO_LEVELDETECT0);
2042 __raw_writel(old1 | l, bank->base +
2043 OMAP4_GPIO_LEVELDETECT1);
2044 __raw_writel(old0, bank->base +
2045 OMAP4_GPIO_LEVELDETECT0);
2046 __raw_writel(old1, bank->base +
2047 OMAP4_GPIO_LEVELDETECT1);
2048#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002049 }
2050 }
2051
2052}
2053
Tony Lindgren92105bb2005-09-07 17:20:26 +01002054#endif
2055
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302056#ifdef CONFIG_ARCH_OMAP34XX
2057/* save the registers of bank 2-6 */
2058void omap_gpio_save_context(void)
2059{
2060 int i;
2061
2062 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2063 for (i = 1; i < gpio_bank_count; i++) {
2064 struct gpio_bank *bank = &gpio_bank[i];
2065 gpio_context[i].sysconfig =
2066 __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG);
2067 gpio_context[i].irqenable1 =
2068 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
2069 gpio_context[i].irqenable2 =
2070 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
2071 gpio_context[i].wake_en =
2072 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
2073 gpio_context[i].ctrl =
2074 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
2075 gpio_context[i].oe =
2076 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
2077 gpio_context[i].leveldetect0 =
2078 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2079 gpio_context[i].leveldetect1 =
2080 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2081 gpio_context[i].risingdetect =
2082 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
2083 gpio_context[i].fallingdetect =
2084 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2085 gpio_context[i].dataout =
2086 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
2087 gpio_context[i].setwkuena =
2088 __raw_readl(bank->base + OMAP24XX_GPIO_SETWKUENA);
2089 gpio_context[i].setdataout =
2090 __raw_readl(bank->base + OMAP24XX_GPIO_SETDATAOUT);
2091 }
2092}
2093
2094/* restore the required registers of bank 2-6 */
2095void omap_gpio_restore_context(void)
2096{
2097 int i;
2098
2099 for (i = 1; i < gpio_bank_count; i++) {
2100 struct gpio_bank *bank = &gpio_bank[i];
2101 __raw_writel(gpio_context[i].sysconfig,
2102 bank->base + OMAP24XX_GPIO_SYSCONFIG);
2103 __raw_writel(gpio_context[i].irqenable1,
2104 bank->base + OMAP24XX_GPIO_IRQENABLE1);
2105 __raw_writel(gpio_context[i].irqenable2,
2106 bank->base + OMAP24XX_GPIO_IRQENABLE2);
2107 __raw_writel(gpio_context[i].wake_en,
2108 bank->base + OMAP24XX_GPIO_WAKE_EN);
2109 __raw_writel(gpio_context[i].ctrl,
2110 bank->base + OMAP24XX_GPIO_CTRL);
2111 __raw_writel(gpio_context[i].oe,
2112 bank->base + OMAP24XX_GPIO_OE);
2113 __raw_writel(gpio_context[i].leveldetect0,
2114 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2115 __raw_writel(gpio_context[i].leveldetect1,
2116 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2117 __raw_writel(gpio_context[i].risingdetect,
2118 bank->base + OMAP24XX_GPIO_RISINGDETECT);
2119 __raw_writel(gpio_context[i].fallingdetect,
2120 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2121 __raw_writel(gpio_context[i].dataout,
2122 bank->base + OMAP24XX_GPIO_DATAOUT);
2123 __raw_writel(gpio_context[i].setwkuena,
2124 bank->base + OMAP24XX_GPIO_SETWKUENA);
2125 __raw_writel(gpio_context[i].setdataout,
2126 bank->base + OMAP24XX_GPIO_SETDATAOUT);
2127 }
2128}
2129#endif
2130
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002131/*
2132 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002133 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002134 */
David Brownell277d58e2006-12-06 17:13:59 -08002135int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002136{
2137 if (!initialized)
2138 return _omap_gpio_init();
2139 else
2140 return 0;
2141}
2142
Tony Lindgren92105bb2005-09-07 17:20:26 +01002143static int __init omap_gpio_sysinit(void)
2144{
2145 int ret = 0;
2146
2147 if (!initialized)
2148 ret = _omap_gpio_init();
2149
David Brownell11a78b72006-12-06 17:14:11 -08002150 mpuio_init();
2151
Santosh Shilimkar44169072009-05-28 14:16:04 -07002152#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
2153 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002154 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002155 if (ret == 0) {
2156 ret = sysdev_class_register(&omap_gpio_sysclass);
2157 if (ret == 0)
2158 ret = sysdev_register(&omap_gpio_device);
2159 }
2160 }
2161#endif
2162
2163 return ret;
2164}
2165
Tony Lindgren92105bb2005-09-07 17:20:26 +01002166arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002167
2168
2169#ifdef CONFIG_DEBUG_FS
2170
2171#include <linux/debugfs.h>
2172#include <linux/seq_file.h>
2173
David Brownellb9772a22006-12-06 17:13:53 -08002174static int dbg_gpio_show(struct seq_file *s, void *unused)
2175{
2176 unsigned i, j, gpio;
2177
2178 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2179 struct gpio_bank *bank = gpio_bank + i;
2180 unsigned bankwidth = 16;
2181 u32 mask = 1;
2182
David Brownelle5c56ed2006-12-06 17:13:59 -08002183 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002184 gpio = OMAP_MPUIO(0);
Alistair Buxtonb718aa82009-09-23 18:56:19 +01002185 else if (cpu_class_is_omap2() || cpu_is_omap7xx())
David Brownellb9772a22006-12-06 17:13:53 -08002186 bankwidth = 32;
2187
2188 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2189 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002190 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002191
David Brownell52e31342008-03-03 12:43:23 -08002192 label = gpiochip_is_requested(&bank->chip, j);
2193 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002194 continue;
2195
2196 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002197 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002198 is_in = gpio_is_input(bank, mask);
2199
David Brownelle5c56ed2006-12-06 17:13:59 -08002200 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002201 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002202 else
David Brownell52e31342008-03-03 12:43:23 -08002203 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002204 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002205 label,
David Brownellb9772a22006-12-06 17:13:53 -08002206 is_in ? "in " : "out",
2207 value ? "hi" : "lo");
2208
David Brownell52e31342008-03-03 12:43:23 -08002209/* FIXME for at least omap2, show pullup/pulldown state */
2210
David Brownellb9772a22006-12-06 17:13:53 -08002211 irqstat = irq_desc[irq].status;
Tony Lindgren3a26e332009-01-15 13:09:53 +02002212#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07002213 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
David Brownellb9772a22006-12-06 17:13:53 -08002214 if (is_in && ((bank->suspend_wakeup & mask)
2215 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2216 char *trigger = NULL;
2217
2218 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2219 case IRQ_TYPE_EDGE_FALLING:
2220 trigger = "falling";
2221 break;
2222 case IRQ_TYPE_EDGE_RISING:
2223 trigger = "rising";
2224 break;
2225 case IRQ_TYPE_EDGE_BOTH:
2226 trigger = "bothedge";
2227 break;
2228 case IRQ_TYPE_LEVEL_LOW:
2229 trigger = "low";
2230 break;
2231 case IRQ_TYPE_LEVEL_HIGH:
2232 trigger = "high";
2233 break;
2234 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002235 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002236 break;
2237 }
David Brownell52e31342008-03-03 12:43:23 -08002238 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002239 irq, trigger,
2240 (bank->suspend_wakeup & mask)
2241 ? " wakeup" : "");
2242 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002243#endif
David Brownellb9772a22006-12-06 17:13:53 -08002244 seq_printf(s, "\n");
2245 }
2246
David Brownelle5c56ed2006-12-06 17:13:59 -08002247 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002248 seq_printf(s, "\n");
2249 gpio = 0;
2250 }
2251 }
2252 return 0;
2253}
2254
2255static int dbg_gpio_open(struct inode *inode, struct file *file)
2256{
David Brownelle5c56ed2006-12-06 17:13:59 -08002257 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002258}
2259
2260static const struct file_operations debug_fops = {
2261 .open = dbg_gpio_open,
2262 .read = seq_read,
2263 .llseek = seq_lseek,
2264 .release = single_release,
2265};
2266
2267static int __init omap_gpio_debuginit(void)
2268{
David Brownelle5c56ed2006-12-06 17:13:59 -08002269 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2270 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002271 return 0;
2272}
2273late_initcall(omap_gpio_debuginit);
2274#endif