blob: 055160e0620e33db3c31e0d2182e27b3381d2964 [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;
Charulatha V058af1e2009-11-22 10:11:25 -0800198 u32 mod_usage;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100199};
200
201#define METHOD_MPUIO 0
202#define METHOD_GPIO_1510 1
203#define METHOD_GPIO_1610 2
Alistair Buxton7c006922009-09-22 10:02:58 +0100204#define METHOD_GPIO_7XX 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700205#define METHOD_GPIO_24XX 5
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100206
Tony Lindgren92105bb2005-09-07 17:20:26 +0100207#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100208static struct gpio_bank gpio_bank_1610[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700209 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
210 METHOD_MPUIO },
211 { OMAP1610_GPIO1_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
212 METHOD_GPIO_1610 },
213 { OMAP1610_GPIO2_BASE, NULL, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16,
214 METHOD_GPIO_1610 },
215 { OMAP1610_GPIO3_BASE, NULL, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32,
216 METHOD_GPIO_1610 },
217 { OMAP1610_GPIO4_BASE, NULL, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48,
218 METHOD_GPIO_1610 },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100219};
220#endif
221
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000222#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100223static struct gpio_bank gpio_bank_1510[2] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700224 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
225 METHOD_MPUIO },
226 { OMAP1510_GPIO_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
227 METHOD_GPIO_1510 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100228};
229#endif
230
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100231#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100232static struct gpio_bank gpio_bank_7xx[7] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700233 { OMAP1_MPUIO_VBASE, NULL, INT_7XX_MPUIO, IH_MPUIO_BASE,
234 METHOD_MPUIO },
235 { OMAP7XX_GPIO1_BASE, NULL, INT_7XX_GPIO_BANK1, IH_GPIO_BASE,
236 METHOD_GPIO_7XX },
237 { OMAP7XX_GPIO2_BASE, NULL, INT_7XX_GPIO_BANK2, IH_GPIO_BASE + 32,
238 METHOD_GPIO_7XX },
239 { OMAP7XX_GPIO3_BASE, NULL, INT_7XX_GPIO_BANK3, IH_GPIO_BASE + 64,
240 METHOD_GPIO_7XX },
241 { OMAP7XX_GPIO4_BASE, NULL, INT_7XX_GPIO_BANK4, IH_GPIO_BASE + 96,
242 METHOD_GPIO_7XX },
243 { OMAP7XX_GPIO5_BASE, NULL, INT_7XX_GPIO_BANK5, IH_GPIO_BASE + 128,
244 METHOD_GPIO_7XX },
245 { OMAP7XX_GPIO6_BASE, NULL, INT_7XX_GPIO_BANK6, IH_GPIO_BASE + 160,
246 METHOD_GPIO_7XX },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100247};
248#endif
249
Tony Lindgren92105bb2005-09-07 17:20:26 +0100250#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800251
252static struct gpio_bank gpio_bank_242x[4] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700253 { OMAP242X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
254 METHOD_GPIO_24XX },
255 { OMAP242X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
256 METHOD_GPIO_24XX },
257 { OMAP242X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
258 METHOD_GPIO_24XX },
259 { OMAP242X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
260 METHOD_GPIO_24XX },
Tony Lindgren92105bb2005-09-07 17:20:26 +0100261};
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800262
263static struct gpio_bank gpio_bank_243x[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700264 { OMAP243X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
265 METHOD_GPIO_24XX },
266 { OMAP243X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
267 METHOD_GPIO_24XX },
268 { OMAP243X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
269 METHOD_GPIO_24XX },
270 { OMAP243X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
271 METHOD_GPIO_24XX },
272 { OMAP243X_GPIO5_BASE, NULL, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128,
273 METHOD_GPIO_24XX },
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800274};
275
Tony Lindgren92105bb2005-09-07 17:20:26 +0100276#endif
277
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800278#ifdef CONFIG_ARCH_OMAP34XX
279static struct gpio_bank gpio_bank_34xx[6] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700280 { OMAP34XX_GPIO1_BASE, NULL, INT_34XX_GPIO_BANK1, IH_GPIO_BASE,
281 METHOD_GPIO_24XX },
282 { OMAP34XX_GPIO2_BASE, NULL, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32,
283 METHOD_GPIO_24XX },
284 { OMAP34XX_GPIO3_BASE, NULL, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64,
285 METHOD_GPIO_24XX },
286 { OMAP34XX_GPIO4_BASE, NULL, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96,
287 METHOD_GPIO_24XX },
288 { OMAP34XX_GPIO5_BASE, NULL, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128,
289 METHOD_GPIO_24XX },
290 { OMAP34XX_GPIO6_BASE, NULL, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160,
291 METHOD_GPIO_24XX },
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800292};
293
Rajendra Nayak40c670f2008-09-26 17:47:48 +0530294struct omap3_gpio_regs {
295 u32 sysconfig;
296 u32 irqenable1;
297 u32 irqenable2;
298 u32 wake_en;
299 u32 ctrl;
300 u32 oe;
301 u32 leveldetect0;
302 u32 leveldetect1;
303 u32 risingdetect;
304 u32 fallingdetect;
305 u32 dataout;
306 u32 setwkuena;
307 u32 setdataout;
308};
309
310static struct omap3_gpio_regs gpio_context[OMAP34XX_NR_GPIOS];
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800311#endif
312
Santosh Shilimkar44169072009-05-28 14:16:04 -0700313#ifdef CONFIG_ARCH_OMAP4
314static struct gpio_bank gpio_bank_44xx[6] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700315 { OMAP44XX_GPIO1_BASE, NULL, INT_44XX_GPIO_BANK1, IH_GPIO_BASE,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700316 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700317 { OMAP44XX_GPIO2_BASE, NULL, INT_44XX_GPIO_BANK2, IH_GPIO_BASE + 32,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700318 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700319 { OMAP44XX_GPIO3_BASE, NULL, INT_44XX_GPIO_BANK3, IH_GPIO_BASE + 64,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700320 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700321 { OMAP44XX_GPIO4_BASE, NULL, INT_44XX_GPIO_BANK4, IH_GPIO_BASE + 96,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700322 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700323 { OMAP44XX_GPIO5_BASE, NULL, INT_44XX_GPIO_BANK5, IH_GPIO_BASE + 128,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700324 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700325 { OMAP44XX_GPIO6_BASE, NULL, INT_44XX_GPIO_BANK6, IH_GPIO_BASE + 160,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700326 METHOD_GPIO_24XX },
327};
328
329#endif
330
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100331static struct gpio_bank *gpio_bank;
332static int gpio_bank_count;
333
334static inline struct gpio_bank *get_gpio_bank(int gpio)
335{
Tony Lindgren6e60e792006-04-02 17:46:23 +0100336 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100337 if (OMAP_GPIO_IS_MPUIO(gpio))
338 return &gpio_bank[0];
339 return &gpio_bank[1];
340 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100341 if (cpu_is_omap16xx()) {
342 if (OMAP_GPIO_IS_MPUIO(gpio))
343 return &gpio_bank[0];
344 return &gpio_bank[1 + (gpio >> 4)];
345 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700346 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100347 if (OMAP_GPIO_IS_MPUIO(gpio))
348 return &gpio_bank[0];
349 return &gpio_bank[1 + (gpio >> 5)];
350 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100351 if (cpu_is_omap24xx())
352 return &gpio_bank[gpio >> 5];
Santosh Shilimkar44169072009-05-28 14:16:04 -0700353 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800354 return &gpio_bank[gpio >> 5];
David Brownelle031ab22008-12-10 17:35:27 -0800355 BUG();
356 return NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100357}
358
359static inline int get_gpio_index(int gpio)
360{
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700361 if (cpu_is_omap7xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100362 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100363 if (cpu_is_omap24xx())
364 return gpio & 0x1f;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700365 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800366 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100367 return gpio & 0x0f;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100368}
369
370static inline int gpio_valid(int gpio)
371{
372 if (gpio < 0)
373 return -1;
Tony Lindgrend11ac972008-01-12 15:35:04 -0800374 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
Jonathan McDowell193e68b2006-09-25 12:41:30 +0300375 if (gpio >= OMAP_MAX_GPIO_LINES + 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100376 return -1;
377 return 0;
378 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100379 if (cpu_is_omap15xx() && gpio < 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100380 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100381 if ((cpu_is_omap16xx()) && gpio < 64)
382 return 0;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700383 if (cpu_is_omap7xx() && gpio < 192)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100384 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100385 if (cpu_is_omap24xx() && gpio < 128)
386 return 0;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700387 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800388 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100389 return -1;
390}
391
392static int check_gpio(int gpio)
393{
Roel Kluind32b20f2009-11-17 14:39:03 -0800394 if (unlikely(gpio_valid(gpio) < 0)) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100395 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
396 dump_stack();
397 return -1;
398 }
399 return 0;
400}
401
402static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
403{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100404 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100405 u32 l;
406
407 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800408#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100409 case METHOD_MPUIO:
410 reg += OMAP_MPUIO_IO_CNTL;
411 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800412#endif
413#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100414 case METHOD_GPIO_1510:
415 reg += OMAP1510_GPIO_DIR_CONTROL;
416 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800417#endif
418#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100419 case METHOD_GPIO_1610:
420 reg += OMAP1610_GPIO_DIRECTION;
421 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800422#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100423#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100424 case METHOD_GPIO_7XX:
425 reg += OMAP7XX_GPIO_DIR_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700426 break;
427#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530428#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100429 case METHOD_GPIO_24XX:
430 reg += OMAP24XX_GPIO_OE;
431 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800432#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530433#if defined(CONFIG_ARCH_OMAP4)
434 case METHOD_GPIO_24XX:
435 reg += OMAP4_GPIO_OE;
436 break;
437#endif
David Brownelle5c56ed2006-12-06 17:13:59 -0800438 default:
439 WARN_ON(1);
440 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100441 }
442 l = __raw_readl(reg);
443 if (is_input)
444 l |= 1 << gpio;
445 else
446 l &= ~(1 << gpio);
447 __raw_writel(l, reg);
448}
449
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100450static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
451{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100452 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100453 u32 l = 0;
454
455 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800456#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100457 case METHOD_MPUIO:
458 reg += OMAP_MPUIO_OUTPUT;
459 l = __raw_readl(reg);
460 if (enable)
461 l |= 1 << gpio;
462 else
463 l &= ~(1 << gpio);
464 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800465#endif
466#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100467 case METHOD_GPIO_1510:
468 reg += OMAP1510_GPIO_DATA_OUTPUT;
469 l = __raw_readl(reg);
470 if (enable)
471 l |= 1 << gpio;
472 else
473 l &= ~(1 << gpio);
474 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800475#endif
476#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100477 case METHOD_GPIO_1610:
478 if (enable)
479 reg += OMAP1610_GPIO_SET_DATAOUT;
480 else
481 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
482 l = 1 << gpio;
483 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800484#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100485#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100486 case METHOD_GPIO_7XX:
487 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700488 l = __raw_readl(reg);
489 if (enable)
490 l |= 1 << gpio;
491 else
492 l &= ~(1 << gpio);
493 break;
494#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530495#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100496 case METHOD_GPIO_24XX:
497 if (enable)
498 reg += OMAP24XX_GPIO_SETDATAOUT;
499 else
500 reg += OMAP24XX_GPIO_CLEARDATAOUT;
501 l = 1 << gpio;
502 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800503#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530504#ifdef CONFIG_ARCH_OMAP4
505 case METHOD_GPIO_24XX:
506 if (enable)
507 reg += OMAP4_GPIO_SETDATAOUT;
508 else
509 reg += OMAP4_GPIO_CLEARDATAOUT;
510 l = 1 << gpio;
511 break;
512#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100513 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800514 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100515 return;
516 }
517 __raw_writel(l, reg);
518}
519
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300520static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100521{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100522 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100523
524 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800525 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100526 reg = bank->base;
527 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800528#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100529 case METHOD_MPUIO:
530 reg += OMAP_MPUIO_INPUT_LATCH;
531 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800532#endif
533#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100534 case METHOD_GPIO_1510:
535 reg += OMAP1510_GPIO_DATA_INPUT;
536 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800537#endif
538#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100539 case METHOD_GPIO_1610:
540 reg += OMAP1610_GPIO_DATAIN;
541 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800542#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100543#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100544 case METHOD_GPIO_7XX:
545 reg += OMAP7XX_GPIO_DATA_INPUT;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700546 break;
547#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530548#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100549 case METHOD_GPIO_24XX:
550 reg += OMAP24XX_GPIO_DATAIN;
551 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800552#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530553#ifdef CONFIG_ARCH_OMAP4
554 case METHOD_GPIO_24XX:
555 reg += OMAP4_GPIO_DATAIN;
556 break;
557#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100558 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800559 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100560 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100561 return (__raw_readl(reg)
562 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100563}
564
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300565static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
566{
567 void __iomem *reg;
568
569 if (check_gpio(gpio) < 0)
570 return -EINVAL;
571 reg = bank->base;
572
573 switch (bank->method) {
574#ifdef CONFIG_ARCH_OMAP1
575 case METHOD_MPUIO:
576 reg += OMAP_MPUIO_OUTPUT;
577 break;
578#endif
579#ifdef CONFIG_ARCH_OMAP15XX
580 case METHOD_GPIO_1510:
581 reg += OMAP1510_GPIO_DATA_OUTPUT;
582 break;
583#endif
584#ifdef CONFIG_ARCH_OMAP16XX
585 case METHOD_GPIO_1610:
586 reg += OMAP1610_GPIO_DATAOUT;
587 break;
588#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100589#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100590 case METHOD_GPIO_7XX:
591 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300592 break;
593#endif
594#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
595 defined(CONFIG_ARCH_OMAP4)
596 case METHOD_GPIO_24XX:
597 reg += OMAP24XX_GPIO_DATAOUT;
598 break;
599#endif
600 default:
601 return -EINVAL;
602 }
603
604 return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
605}
606
Tony Lindgren92105bb2005-09-07 17:20:26 +0100607#define MOD_REG_BIT(reg, bit_mask, set) \
608do { \
609 int l = __raw_readl(base + reg); \
610 if (set) l |= bit_mask; \
611 else l &= ~bit_mask; \
612 __raw_writel(l, base + reg); \
613} while(0)
614
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700615void omap_set_gpio_debounce(int gpio, int enable)
616{
617 struct gpio_bank *bank;
618 void __iomem *reg;
David Brownelle031ab22008-12-10 17:35:27 -0800619 unsigned long flags;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700620 u32 val, l = 1 << get_gpio_index(gpio);
621
622 if (cpu_class_is_omap1())
623 return;
624
625 bank = get_gpio_bank(gpio);
626 reg = bank->base;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530627#ifdef CONFIG_ARCH_OMAP4
628 reg += OMAP4_GPIO_DEBOUNCENABLE;
629#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700630 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530631#endif
Charulatha V058af1e2009-11-22 10:11:25 -0800632 if (!(bank->mod_usage & l)) {
633 printk(KERN_ERR "GPIO %d not requested\n", gpio);
634 return;
635 }
David Brownelle031ab22008-12-10 17:35:27 -0800636
637 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700638 val = __raw_readl(reg);
639
Jouni Hogander89db9482008-12-10 17:35:24 -0800640 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700641 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800642 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700643 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800644 else
David Brownelle031ab22008-12-10 17:35:27 -0800645 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800646
Santosh Shilimkar44169072009-05-28 14:16:04 -0700647 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800648 if (enable)
649 clk_enable(bank->dbck);
650 else
651 clk_disable(bank->dbck);
652 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700653
654 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800655done:
656 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700657}
658EXPORT_SYMBOL(omap_set_gpio_debounce);
659
660void omap_set_gpio_debounce_time(int gpio, int enc_time)
661{
662 struct gpio_bank *bank;
663 void __iomem *reg;
664
665 if (cpu_class_is_omap1())
666 return;
667
668 bank = get_gpio_bank(gpio);
669 reg = bank->base;
670
Charulatha V058af1e2009-11-22 10:11:25 -0800671 if (!bank->mod_usage) {
672 printk(KERN_ERR "GPIO not requested\n");
673 return;
674 }
675
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700676 enc_time &= 0xff;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530677#ifdef CONFIG_ARCH_OMAP4
678 reg += OMAP4_GPIO_DEBOUNCINGTIME;
679#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700680 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530681#endif
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700682 __raw_writel(enc_time, reg);
683}
684EXPORT_SYMBOL(omap_set_gpio_debounce_time);
685
Santosh Shilimkar44169072009-05-28 14:16:04 -0700686#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
687 defined(CONFIG_ARCH_OMAP4)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700688static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
689 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100690{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800691 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100692 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530693 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100694
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530695 if (cpu_is_omap44xx()) {
696 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
697 trigger & IRQ_TYPE_LEVEL_LOW);
698 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
699 trigger & IRQ_TYPE_LEVEL_HIGH);
700 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
701 trigger & IRQ_TYPE_EDGE_RISING);
702 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
703 trigger & IRQ_TYPE_EDGE_FALLING);
704 } else {
705 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
706 trigger & IRQ_TYPE_LEVEL_LOW);
707 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
708 trigger & IRQ_TYPE_LEVEL_HIGH);
709 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
710 trigger & IRQ_TYPE_EDGE_RISING);
711 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
712 trigger & IRQ_TYPE_EDGE_FALLING);
713 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800714 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530715 if (cpu_is_omap44xx()) {
716 if (trigger != 0)
717 __raw_writel(1 << gpio, bank->base+
718 OMAP4_GPIO_IRQWAKEN0);
719 else {
720 val = __raw_readl(bank->base +
721 OMAP4_GPIO_IRQWAKEN0);
722 __raw_writel(val & (~(1 << gpio)), bank->base +
723 OMAP4_GPIO_IRQWAKEN0);
724 }
725 } else {
726 if (trigger != 0)
727 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700728 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530729 else
730 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700731 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530732 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800733 } else {
734 if (trigger != 0)
735 bank->enabled_non_wakeup_gpios |= gpio_bit;
736 else
737 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
738 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700739
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530740 if (cpu_is_omap44xx()) {
741 bank->level_mask =
742 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
743 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
744 } else {
745 bank->level_mask =
746 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
747 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
748 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100749}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800750#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100751
752static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
753{
754 void __iomem *reg = bank->base;
755 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100756
757 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800758#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100759 case METHOD_MPUIO:
760 reg += OMAP_MPUIO_GPIO_INT_EDGE;
761 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100762 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100763 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100764 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100765 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100766 else
767 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100768 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800769#endif
770#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100771 case METHOD_GPIO_1510:
772 reg += OMAP1510_GPIO_INT_CONTROL;
773 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100774 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100775 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100776 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100777 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100778 else
779 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100780 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800781#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800782#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100783 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100784 if (gpio & 0x08)
785 reg += OMAP1610_GPIO_EDGE_CTRL2;
786 else
787 reg += OMAP1610_GPIO_EDGE_CTRL1;
788 gpio &= 0x07;
789 l = __raw_readl(reg);
790 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100791 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100792 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100793 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100794 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800795 if (trigger)
796 /* Enable wake-up during idle for dynamic tick */
797 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
798 else
799 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100800 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800801#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100802#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100803 case METHOD_GPIO_7XX:
804 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700805 l = __raw_readl(reg);
806 if (trigger & IRQ_TYPE_EDGE_RISING)
807 l |= 1 << gpio;
808 else if (trigger & IRQ_TYPE_EDGE_FALLING)
809 l &= ~(1 << gpio);
810 else
811 goto bad;
812 break;
813#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700814#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
815 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100816 case METHOD_GPIO_24XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800817 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100818 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800819#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100820 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100821 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100822 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100823 __raw_writel(l, reg);
824 return 0;
825bad:
826 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100827}
828
Tony Lindgren92105bb2005-09-07 17:20:26 +0100829static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100830{
831 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100832 unsigned gpio;
833 int retval;
David Brownella6472532008-03-03 04:33:30 -0800834 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100835
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800836 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100837 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
838 else
839 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100840
841 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100842 return -EINVAL;
843
David Brownelle5c56ed2006-12-06 17:13:59 -0800844 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100845 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800846
847 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800848 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800849 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100850 return -EINVAL;
851
David Brownell58781012006-12-06 17:14:10 -0800852 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800853 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100854 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800855 if (retval == 0) {
856 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
857 irq_desc[irq].status |= type;
858 }
David Brownella6472532008-03-03 04:33:30 -0800859 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800860
861 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
862 __set_irq_handler_unlocked(irq, handle_level_irq);
863 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
864 __set_irq_handler_unlocked(irq, handle_edge_irq);
865
Tony Lindgren92105bb2005-09-07 17:20:26 +0100866 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100867}
868
869static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
870{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100871 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100872
873 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800874#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100875 case METHOD_MPUIO:
876 /* MPUIO irqstatus is reset by reading the status register,
877 * so do nothing here */
878 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800879#endif
880#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100881 case METHOD_GPIO_1510:
882 reg += OMAP1510_GPIO_INT_STATUS;
883 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800884#endif
885#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100886 case METHOD_GPIO_1610:
887 reg += OMAP1610_GPIO_IRQSTATUS1;
888 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800889#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100890#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100891 case METHOD_GPIO_7XX:
892 reg += OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700893 break;
894#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530895#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100896 case METHOD_GPIO_24XX:
897 reg += OMAP24XX_GPIO_IRQSTATUS1;
898 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800899#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530900#if defined(CONFIG_ARCH_OMAP4)
901 case METHOD_GPIO_24XX:
902 reg += OMAP4_GPIO_IRQSTATUS0;
903 break;
904#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100905 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800906 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100907 return;
908 }
909 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300910
911 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800912#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Roger Quadrosbedfd152009-04-23 11:10:50 -0700913 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530914#endif
915#if defined(CONFIG_ARCH_OMAP4)
916 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
917#endif
918 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700919 __raw_writel(gpio_mask, reg);
920
921 /* Flush posted write for the irq status to avoid spurious interrupts */
922 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530923 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100924}
925
926static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
927{
928 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
929}
930
Imre Deakea6dedd2006-06-26 16:16:00 -0700931static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
932{
933 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700934 int inv = 0;
935 u32 l;
936 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700937
938 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800939#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700940 case METHOD_MPUIO:
941 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700942 mask = 0xffff;
943 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700944 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800945#endif
946#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700947 case METHOD_GPIO_1510:
948 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700949 mask = 0xffff;
950 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700951 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800952#endif
953#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700954 case METHOD_GPIO_1610:
955 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700956 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700957 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800958#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100959#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100960 case METHOD_GPIO_7XX:
961 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700962 mask = 0xffffffff;
963 inv = 1;
964 break;
965#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530966#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Imre Deakea6dedd2006-06-26 16:16:00 -0700967 case METHOD_GPIO_24XX:
968 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700969 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700970 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800971#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530972#if defined(CONFIG_ARCH_OMAP4)
973 case METHOD_GPIO_24XX:
974 reg += OMAP4_GPIO_IRQSTATUSSET0;
975 mask = 0xffffffff;
976 break;
977#endif
Imre Deakea6dedd2006-06-26 16:16:00 -0700978 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800979 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -0700980 return 0;
981 }
982
Imre Deak99c47702006-06-26 16:16:07 -0700983 l = __raw_readl(reg);
984 if (inv)
985 l = ~l;
986 l &= mask;
987 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700988}
989
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100990static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
991{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100992 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100993 u32 l;
994
995 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800996#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100997 case METHOD_MPUIO:
998 reg += OMAP_MPUIO_GPIO_MASKIT;
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_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001007 case METHOD_GPIO_1510:
1008 reg += OMAP1510_GPIO_INT_MASK;
1009 l = __raw_readl(reg);
1010 if (enable)
1011 l &= ~(gpio_mask);
1012 else
1013 l |= gpio_mask;
1014 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001015#endif
1016#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001017 case METHOD_GPIO_1610:
1018 if (enable)
1019 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1020 else
1021 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1022 l = gpio_mask;
1023 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001024#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001025#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001026 case METHOD_GPIO_7XX:
1027 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001028 l = __raw_readl(reg);
1029 if (enable)
1030 l &= ~(gpio_mask);
1031 else
1032 l |= gpio_mask;
1033 break;
1034#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301035#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001036 case METHOD_GPIO_24XX:
1037 if (enable)
1038 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1039 else
1040 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1041 l = gpio_mask;
1042 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001043#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301044#ifdef CONFIG_ARCH_OMAP4
1045 case METHOD_GPIO_24XX:
1046 if (enable)
1047 reg += OMAP4_GPIO_IRQSTATUSSET0;
1048 else
1049 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1050 l = gpio_mask;
1051 break;
1052#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001053 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001054 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001055 return;
1056 }
1057 __raw_writel(l, reg);
1058}
1059
1060static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1061{
1062 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1063}
1064
Tony Lindgren92105bb2005-09-07 17:20:26 +01001065/*
1066 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1067 * 1510 does not seem to have a wake-up register. If JTAG is connected
1068 * to the target, system will wake up always on GPIO events. While
1069 * system is running all registered GPIO interrupts need to have wake-up
1070 * enabled. When system is suspended, only selected GPIO interrupts need
1071 * to have wake-up enabled.
1072 */
1073static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1074{
David Brownella6472532008-03-03 04:33:30 -08001075 unsigned long flags;
1076
Tony Lindgren92105bb2005-09-07 17:20:26 +01001077 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001078#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001079 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001080 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001081 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001082 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001083 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001084 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001085 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001086 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001087 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001088#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001089#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1090 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001091 case METHOD_GPIO_24XX:
David Brownell11a78b72006-12-06 17:14:11 -08001092 if (bank->non_wakeup_gpios & (1 << gpio)) {
1093 printk(KERN_ERR "Unable to modify wakeup on "
1094 "non-wakeup GPIO%d\n",
1095 (bank - gpio_bank) * 32 + gpio);
1096 return -EINVAL;
1097 }
David Brownella6472532008-03-03 04:33:30 -08001098 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001099 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001100 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001101 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001102 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001103 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001104 return 0;
1105#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001106 default:
1107 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1108 bank->method);
1109 return -EINVAL;
1110 }
1111}
1112
Tony Lindgren4196dd62006-09-25 12:41:38 +03001113static void _reset_gpio(struct gpio_bank *bank, int gpio)
1114{
1115 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1116 _set_gpio_irqenable(bank, gpio, 0);
1117 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001118 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001119}
1120
Tony Lindgren92105bb2005-09-07 17:20:26 +01001121/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1122static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1123{
1124 unsigned int gpio = irq - IH_GPIO_BASE;
1125 struct gpio_bank *bank;
1126 int retval;
1127
1128 if (check_gpio(gpio) < 0)
1129 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001130 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001131 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001132
1133 return retval;
1134}
1135
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001136static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001137{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001138 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001139 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001140
David Brownella6472532008-03-03 04:33:30 -08001141 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001142
Tony Lindgren4196dd62006-09-25 12:41:38 +03001143 /* Set trigger to none. You need to enable the desired trigger with
1144 * request_irq() or set_irq_type().
1145 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001146 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001147
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001148#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001149 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001150 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001151
Tony Lindgren92105bb2005-09-07 17:20:26 +01001152 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001153 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001154 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001155 }
1156#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001157 if (!cpu_class_is_omap1()) {
1158 if (!bank->mod_usage) {
1159 u32 ctrl;
1160 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1161 ctrl &= 0xFFFFFFFE;
1162 /* Module is enabled, clocks are not gated */
1163 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1164 }
1165 bank->mod_usage |= 1 << offset;
1166 }
David Brownella6472532008-03-03 04:33:30 -08001167 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001168
1169 return 0;
1170}
1171
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001172static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001173{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001174 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001175 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001176
David Brownella6472532008-03-03 04:33:30 -08001177 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001178#ifdef CONFIG_ARCH_OMAP16XX
1179 if (bank->method == METHOD_GPIO_1610) {
1180 /* Disable wake-up during idle for dynamic tick */
1181 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001182 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001183 }
1184#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001185#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1186 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001187 if (bank->method == METHOD_GPIO_24XX) {
1188 /* Disable wake-up during idle for dynamic tick */
1189 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001190 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001191 }
1192#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001193 if (!cpu_class_is_omap1()) {
1194 bank->mod_usage &= ~(1 << offset);
1195 if (!bank->mod_usage) {
1196 u32 ctrl;
1197 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1198 /* Module is disabled, clocks are gated */
1199 ctrl |= 1;
1200 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1201 }
1202 }
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001203 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001204 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001205}
1206
1207/*
1208 * We need to unmask the GPIO bank interrupt as soon as possible to
1209 * avoid missing GPIO interrupts for other lines in the bank.
1210 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1211 * in the bank to avoid missing nested interrupts for a GPIO line.
1212 * If we wait to unmask individual GPIO lines in the bank after the
1213 * line's interrupt handler has been run, we may miss some nested
1214 * interrupts.
1215 */
Russell King10dd5ce2006-11-23 11:41:32 +00001216static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001217{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001218 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001219 u32 isr;
1220 unsigned int gpio_irq;
1221 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001222 u32 retrigger = 0;
1223 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001224
1225 desc->chip->ack(irq);
1226
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001227 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001228#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001229 if (bank->method == METHOD_MPUIO)
1230 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001231#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001232#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001233 if (bank->method == METHOD_GPIO_1510)
1234 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1235#endif
1236#if defined(CONFIG_ARCH_OMAP16XX)
1237 if (bank->method == METHOD_GPIO_1610)
1238 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1239#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001240#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001241 if (bank->method == METHOD_GPIO_7XX)
1242 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001243#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301244#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001245 if (bank->method == METHOD_GPIO_24XX)
1246 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1247#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301248#if defined(CONFIG_ARCH_OMAP4)
1249 if (bank->method == METHOD_GPIO_24XX)
1250 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1251#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001252 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001253 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001254 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001255
Imre Deakea6dedd2006-06-26 16:16:00 -07001256 enabled = _get_gpio_irqbank_mask(bank);
1257 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001258
1259 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1260 isr &= 0x0000ffff;
1261
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001262 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001263 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001264 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001265
1266 /* clear edge sensitive interrupts before handler(s) are
1267 called so that we don't miss any interrupt occurred while
1268 executing them */
1269 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1270 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1271 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1272
1273 /* if there is only edge sensitive GPIO pin interrupts
1274 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001275 if (!level_mask && !unmasked) {
1276 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001277 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001278 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001279
Imre Deakea6dedd2006-06-26 16:16:00 -07001280 isr |= retrigger;
1281 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001282 if (!isr)
1283 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001284
Tony Lindgren92105bb2005-09-07 17:20:26 +01001285 gpio_irq = bank->virtual_irq_start;
1286 for (; isr != 0; isr >>= 1, gpio_irq++) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001287 if (!(isr & 1))
1288 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001289
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001290 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001291 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001292 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001293 /* if bank has any level sensitive GPIO pin interrupt
1294 configured, we must unmask the bank interrupt only after
1295 handler(s) are executed in order to avoid spurious bank
1296 interrupt */
1297 if (!unmasked)
1298 desc->chip->unmask(irq);
1299
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001300}
1301
Tony Lindgren4196dd62006-09-25 12:41:38 +03001302static void gpio_irq_shutdown(unsigned int irq)
1303{
1304 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001305 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001306
1307 _reset_gpio(bank, gpio);
1308}
1309
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001310static void gpio_ack_irq(unsigned int irq)
1311{
1312 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001313 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001314
1315 _clear_gpio_irqstatus(bank, gpio);
1316}
1317
1318static void gpio_mask_irq(unsigned int irq)
1319{
1320 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001321 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001322
1323 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001324 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001325}
1326
1327static void gpio_unmask_irq(unsigned int irq)
1328{
1329 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001330 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001331 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001332 struct irq_desc *desc = irq_to_desc(irq);
1333 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1334
1335 if (trigger)
1336 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001337
1338 /* For level-triggered GPIOs, the clearing must be done after
1339 * the HW source is cleared, thus after the handler has run */
1340 if (bank->level_mask & irq_mask) {
1341 _set_gpio_irqenable(bank, gpio, 0);
1342 _clear_gpio_irqstatus(bank, gpio);
1343 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001344
Kevin Hilman4de8c752008-01-16 21:56:14 -08001345 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001346}
1347
David Brownelle5c56ed2006-12-06 17:13:59 -08001348static struct irq_chip gpio_irq_chip = {
1349 .name = "GPIO",
1350 .shutdown = gpio_irq_shutdown,
1351 .ack = gpio_ack_irq,
1352 .mask = gpio_mask_irq,
1353 .unmask = gpio_unmask_irq,
1354 .set_type = gpio_irq_type,
1355 .set_wake = gpio_wake_enable,
1356};
1357
1358/*---------------------------------------------------------------------*/
1359
1360#ifdef CONFIG_ARCH_OMAP1
1361
1362/* MPUIO uses the always-on 32k clock */
1363
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001364static void mpuio_ack_irq(unsigned int irq)
1365{
1366 /* The ISR is reset automatically, so do nothing here. */
1367}
1368
1369static void mpuio_mask_irq(unsigned int irq)
1370{
1371 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001372 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001373
1374 _set_gpio_irqenable(bank, gpio, 0);
1375}
1376
1377static void mpuio_unmask_irq(unsigned int irq)
1378{
1379 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001380 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001381
1382 _set_gpio_irqenable(bank, gpio, 1);
1383}
1384
David Brownelle5c56ed2006-12-06 17:13:59 -08001385static struct irq_chip mpuio_irq_chip = {
1386 .name = "MPUIO",
1387 .ack = mpuio_ack_irq,
1388 .mask = mpuio_mask_irq,
1389 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001390 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001391#ifdef CONFIG_ARCH_OMAP16XX
1392 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1393 .set_wake = gpio_wake_enable,
1394#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001395};
1396
David Brownelle5c56ed2006-12-06 17:13:59 -08001397
1398#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1399
David Brownell11a78b72006-12-06 17:14:11 -08001400
1401#ifdef CONFIG_ARCH_OMAP16XX
1402
1403#include <linux/platform_device.h>
1404
Magnus Damm79ee0312009-07-08 13:22:04 +02001405static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001406{
Magnus Damm79ee0312009-07-08 13:22:04 +02001407 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001408 struct gpio_bank *bank = platform_get_drvdata(pdev);
1409 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001410 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001411
David Brownella6472532008-03-03 04:33:30 -08001412 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001413 bank->saved_wakeup = __raw_readl(mask_reg);
1414 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001415 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001416
1417 return 0;
1418}
1419
Magnus Damm79ee0312009-07-08 13:22:04 +02001420static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001421{
Magnus Damm79ee0312009-07-08 13:22:04 +02001422 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001423 struct gpio_bank *bank = platform_get_drvdata(pdev);
1424 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001425 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001426
David Brownella6472532008-03-03 04:33:30 -08001427 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001428 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001429 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001430
1431 return 0;
1432}
1433
Magnus Damm79ee0312009-07-08 13:22:04 +02001434static struct dev_pm_ops omap_mpuio_dev_pm_ops = {
1435 .suspend_noirq = omap_mpuio_suspend_noirq,
1436 .resume_noirq = omap_mpuio_resume_noirq,
1437};
1438
David Brownell11a78b72006-12-06 17:14:11 -08001439/* use platform_driver for this, now that there's no longer any
1440 * point to sys_device (other than not disturbing old code).
1441 */
1442static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001443 .driver = {
1444 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001445 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001446 },
1447};
1448
1449static struct platform_device omap_mpuio_device = {
1450 .name = "mpuio",
1451 .id = -1,
1452 .dev = {
1453 .driver = &omap_mpuio_driver.driver,
1454 }
1455 /* could list the /proc/iomem resources */
1456};
1457
1458static inline void mpuio_init(void)
1459{
David Brownellfcf126d2007-04-02 12:46:47 -07001460 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1461
David Brownell11a78b72006-12-06 17:14:11 -08001462 if (platform_driver_register(&omap_mpuio_driver) == 0)
1463 (void) platform_device_register(&omap_mpuio_device);
1464}
1465
1466#else
1467static inline void mpuio_init(void) {}
1468#endif /* 16xx */
1469
David Brownelle5c56ed2006-12-06 17:13:59 -08001470#else
1471
1472extern struct irq_chip mpuio_irq_chip;
1473
1474#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001475static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001476
1477#endif
1478
1479/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001480
David Brownell52e31342008-03-03 12:43:23 -08001481/* REVISIT these are stupid implementations! replace by ones that
1482 * don't switch on METHOD_* and which mostly avoid spinlocks
1483 */
1484
1485static int gpio_input(struct gpio_chip *chip, unsigned offset)
1486{
1487 struct gpio_bank *bank;
1488 unsigned long flags;
1489
1490 bank = container_of(chip, struct gpio_bank, chip);
1491 spin_lock_irqsave(&bank->lock, flags);
1492 _set_gpio_direction(bank, offset, 1);
1493 spin_unlock_irqrestore(&bank->lock, flags);
1494 return 0;
1495}
1496
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001497static int gpio_is_input(struct gpio_bank *bank, int mask)
1498{
1499 void __iomem *reg = bank->base;
1500
1501 switch (bank->method) {
1502 case METHOD_MPUIO:
1503 reg += OMAP_MPUIO_IO_CNTL;
1504 break;
1505 case METHOD_GPIO_1510:
1506 reg += OMAP1510_GPIO_DIR_CONTROL;
1507 break;
1508 case METHOD_GPIO_1610:
1509 reg += OMAP1610_GPIO_DIRECTION;
1510 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001511 case METHOD_GPIO_7XX:
1512 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001513 break;
1514 case METHOD_GPIO_24XX:
1515 reg += OMAP24XX_GPIO_OE;
1516 break;
1517 }
1518 return __raw_readl(reg) & mask;
1519}
1520
David Brownell52e31342008-03-03 12:43:23 -08001521static int gpio_get(struct gpio_chip *chip, unsigned offset)
1522{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001523 struct gpio_bank *bank;
1524 void __iomem *reg;
1525 int gpio;
1526 u32 mask;
1527
1528 gpio = chip->base + offset;
1529 bank = get_gpio_bank(gpio);
1530 reg = bank->base;
1531 mask = 1 << get_gpio_index(gpio);
1532
1533 if (gpio_is_input(bank, mask))
1534 return _get_gpio_datain(bank, gpio);
1535 else
1536 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001537}
1538
1539static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1540{
1541 struct gpio_bank *bank;
1542 unsigned long flags;
1543
1544 bank = container_of(chip, struct gpio_bank, chip);
1545 spin_lock_irqsave(&bank->lock, flags);
1546 _set_gpio_dataout(bank, offset, value);
1547 _set_gpio_direction(bank, offset, 0);
1548 spin_unlock_irqrestore(&bank->lock, flags);
1549 return 0;
1550}
1551
1552static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1553{
1554 struct gpio_bank *bank;
1555 unsigned long flags;
1556
1557 bank = container_of(chip, struct gpio_bank, chip);
1558 spin_lock_irqsave(&bank->lock, flags);
1559 _set_gpio_dataout(bank, offset, value);
1560 spin_unlock_irqrestore(&bank->lock, flags);
1561}
1562
David Brownella007b702008-12-10 17:35:25 -08001563static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1564{
1565 struct gpio_bank *bank;
1566
1567 bank = container_of(chip, struct gpio_bank, chip);
1568 return bank->virtual_irq_start + offset;
1569}
1570
David Brownell52e31342008-03-03 12:43:23 -08001571/*---------------------------------------------------------------------*/
1572
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001573static int initialized;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001574#if !(defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001575static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001576#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001577
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001578#if defined(CONFIG_ARCH_OMAP2)
1579static struct clk * gpio_fck;
1580#endif
1581
1582#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001583static struct clk * gpio5_ick;
1584static struct clk * gpio5_fck;
1585#endif
1586
Santosh Shilimkar44169072009-05-28 14:16:04 -07001587#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001588static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1589#endif
1590
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001591static void __init omap_gpio_show_rev(void)
1592{
1593 u32 rev;
1594
1595 if (cpu_is_omap16xx())
1596 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1597 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1598 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1599 else if (cpu_is_omap44xx())
1600 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1601 else
1602 return;
1603
1604 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1605 (rev >> 4) & 0x0f, rev & 0x0f);
1606}
1607
David Brownell8ba55c52008-02-26 11:10:50 -08001608/* This lock class tells lockdep that GPIO irqs are in a different
1609 * category than their parents, so it won't report false recursion.
1610 */
1611static struct lock_class_key gpio_lock_class;
1612
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001613static int __init _omap_gpio_init(void)
1614{
1615 int i;
David Brownell52e31342008-03-03 12:43:23 -08001616 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001617 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001618 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001619 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001620
1621 initialized = 1;
1622
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001623#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001624 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001625 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1626 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001627 printk("Could not get arm_gpio_ck\n");
1628 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001629 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001630 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001631#endif
1632#if defined(CONFIG_ARCH_OMAP2)
1633 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001634 gpio_ick = clk_get(NULL, "gpios_ick");
1635 if (IS_ERR(gpio_ick))
1636 printk("Could not get gpios_ick\n");
1637 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001638 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001639 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001640 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001641 printk("Could not get gpios_fck\n");
1642 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001643 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001644
1645 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001646 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001647 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001648#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001649 if (cpu_is_omap2430()) {
1650 gpio5_ick = clk_get(NULL, "gpio5_ick");
1651 if (IS_ERR(gpio5_ick))
1652 printk("Could not get gpio5_ick\n");
1653 else
1654 clk_enable(gpio5_ick);
1655 gpio5_fck = clk_get(NULL, "gpio5_fck");
1656 if (IS_ERR(gpio5_fck))
1657 printk("Could not get gpio5_fck\n");
1658 else
1659 clk_enable(gpio5_fck);
1660 }
1661#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001662 }
1663#endif
1664
Santosh Shilimkar44169072009-05-28 14:16:04 -07001665#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1666 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001667 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1668 sprintf(clk_name, "gpio%d_ick", i + 1);
1669 gpio_iclks[i] = clk_get(NULL, clk_name);
1670 if (IS_ERR(gpio_iclks[i]))
1671 printk(KERN_ERR "Could not get %s\n", clk_name);
1672 else
1673 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001674 }
1675 }
1676#endif
1677
Tony Lindgren92105bb2005-09-07 17:20:26 +01001678
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001679#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001680 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001681 gpio_bank_count = 2;
1682 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001683 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001684 }
1685#endif
1686#if defined(CONFIG_ARCH_OMAP16XX)
1687 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001688 gpio_bank_count = 5;
1689 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001690 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001691 }
1692#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001693#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1694 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001695 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001696 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001697 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001698 }
1699#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001700#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001701 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001702 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001703 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001704 }
1705 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001706 gpio_bank_count = 5;
1707 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001708 }
1709#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001710#ifdef CONFIG_ARCH_OMAP34XX
1711 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001712 gpio_bank_count = OMAP34XX_NR_GPIOS;
1713 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001714 }
1715#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001716#ifdef CONFIG_ARCH_OMAP4
1717 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001718 gpio_bank_count = OMAP34XX_NR_GPIOS;
1719 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001720 }
1721#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001722 for (i = 0; i < gpio_bank_count; i++) {
1723 int j, gpio_count = 16;
1724
1725 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001726 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001727
1728 /* Static mapping, never released */
1729 bank->base = ioremap(bank->pbase, bank_size);
1730 if (!bank->base) {
1731 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1732 continue;
1733 }
1734
David Brownelle5c56ed2006-12-06 17:13:59 -08001735 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001736 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001737 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001738 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1739 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1740 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001741 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001742 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1743 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001744 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001745 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001746 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1747 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1748 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001749
Alistair Buxton7c006922009-09-22 10:02:58 +01001750 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001751 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001752
Santosh Shilimkar44169072009-05-28 14:16:04 -07001753#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1754 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001755 if (bank->method == METHOD_GPIO_24XX) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001756 static const u32 non_wakeup_gpios[] = {
1757 0xe203ffc0, 0x08700040
1758 };
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301759 if (cpu_is_omap44xx()) {
1760 __raw_writel(0xffffffff, bank->base +
1761 OMAP4_GPIO_IRQSTATUSCLR0);
1762 __raw_writew(0x0015, bank->base +
1763 OMAP4_GPIO_SYSCONFIG);
1764 __raw_writel(0x00000000, bank->base +
1765 OMAP4_GPIO_DEBOUNCENABLE);
1766 /* Initialize interface clock ungated, module enabled */
1767 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1768 } else {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001769 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1770 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001771 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
janboecb5793d2009-06-23 13:30:25 +03001772 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_DEBOUNCE_EN);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001773
1774 /* Initialize interface clock ungated, module enabled */
1775 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301776 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001777 if (i < ARRAY_SIZE(non_wakeup_gpios))
1778 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001779 gpio_count = 32;
1780 }
1781#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001782
1783 bank->mod_usage = 0;
David Brownell52e31342008-03-03 12:43:23 -08001784 /* REVISIT eventually switch from OMAP-specific gpio structs
1785 * over to the generic ones
1786 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001787 bank->chip.request = omap_gpio_request;
1788 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001789 bank->chip.direction_input = gpio_input;
1790 bank->chip.get = gpio_get;
1791 bank->chip.direction_output = gpio_output;
1792 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001793 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001794 if (bank_is_mpuio(bank)) {
1795 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001796#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001797 bank->chip.dev = &omap_mpuio_device.dev;
1798#endif
David Brownell52e31342008-03-03 12:43:23 -08001799 bank->chip.base = OMAP_MPUIO(0);
1800 } else {
1801 bank->chip.label = "gpio";
1802 bank->chip.base = gpio;
1803 gpio += gpio_count;
1804 }
1805 bank->chip.ngpio = gpio_count;
1806
1807 gpiochip_add(&bank->chip);
1808
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001809 for (j = bank->virtual_irq_start;
1810 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001811 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001812 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001813 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001814 set_irq_chip(j, &mpuio_irq_chip);
1815 else
1816 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001817 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001818 set_irq_flags(j, IRQF_VALID);
1819 }
1820 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1821 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001822
Santosh Shilimkar44169072009-05-28 14:16:04 -07001823 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001824 sprintf(clk_name, "gpio%d_dbck", i + 1);
1825 bank->dbck = clk_get(NULL, clk_name);
1826 if (IS_ERR(bank->dbck))
1827 printk(KERN_ERR "Could not get %s\n", clk_name);
1828 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001829 }
1830
1831 /* Enable system clock for GPIO module.
1832 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001833 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001834 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1835
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001836 /* Enable autoidle for the OCP interface */
1837 if (cpu_is_omap24xx())
1838 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001839 if (cpu_is_omap34xx())
1840 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001841
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001842 omap_gpio_show_rev();
1843
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001844 return 0;
1845}
1846
Santosh Shilimkar44169072009-05-28 14:16:04 -07001847#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1848 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001849static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1850{
1851 int i;
1852
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001853 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001854 return 0;
1855
1856 for (i = 0; i < gpio_bank_count; i++) {
1857 struct gpio_bank *bank = &gpio_bank[i];
1858 void __iomem *wake_status;
1859 void __iomem *wake_clear;
1860 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001861 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001862
1863 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001864#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001865 case METHOD_GPIO_1610:
1866 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1867 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1868 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1869 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001870#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301871#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001872 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001873 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001874 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1875 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1876 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001877#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301878#ifdef CONFIG_ARCH_OMAP4
1879 case METHOD_GPIO_24XX:
1880 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1881 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1882 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1883 break;
1884#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001885 default:
1886 continue;
1887 }
1888
David Brownella6472532008-03-03 04:33:30 -08001889 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001890 bank->saved_wakeup = __raw_readl(wake_status);
1891 __raw_writel(0xffffffff, wake_clear);
1892 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001893 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001894 }
1895
1896 return 0;
1897}
1898
1899static int omap_gpio_resume(struct sys_device *dev)
1900{
1901 int i;
1902
Tero Kristo723fdb72008-11-26 14:35:16 -08001903 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001904 return 0;
1905
1906 for (i = 0; i < gpio_bank_count; i++) {
1907 struct gpio_bank *bank = &gpio_bank[i];
1908 void __iomem *wake_clear;
1909 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001910 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001911
1912 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001913#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001914 case METHOD_GPIO_1610:
1915 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1916 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1917 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001918#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301919#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001920 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001921 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1922 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001923 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001924#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301925#ifdef CONFIG_ARCH_OMAP4
1926 case METHOD_GPIO_24XX:
1927 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1928 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1929 break;
1930#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001931 default:
1932 continue;
1933 }
1934
David Brownella6472532008-03-03 04:33:30 -08001935 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001936 __raw_writel(0xffffffff, wake_clear);
1937 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001938 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001939 }
1940
1941 return 0;
1942}
1943
1944static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01001945 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001946 .suspend = omap_gpio_suspend,
1947 .resume = omap_gpio_resume,
1948};
1949
1950static struct sys_device omap_gpio_device = {
1951 .id = 0,
1952 .cls = &omap_gpio_sysclass,
1953};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001954
1955#endif
1956
Santosh Shilimkar44169072009-05-28 14:16:04 -07001957#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1958 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001959
1960static int workaround_enabled;
1961
1962void omap2_gpio_prepare_for_retention(void)
1963{
1964 int i, c = 0;
1965
1966 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
1967 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
1968 for (i = 0; i < gpio_bank_count; i++) {
1969 struct gpio_bank *bank = &gpio_bank[i];
1970 u32 l1, l2;
1971
1972 if (!(bank->enabled_non_wakeup_gpios))
1973 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301974#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001975 bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1976 l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1977 l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001978#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301979#ifdef CONFIG_ARCH_OMAP4
1980 bank->saved_datain = __raw_readl(bank->base +
1981 OMAP4_GPIO_DATAIN);
1982 l1 = __raw_readl(bank->base + OMAP4_GPIO_FALLINGDETECT);
1983 l2 = __raw_readl(bank->base + OMAP4_GPIO_RISINGDETECT);
1984#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001985 bank->saved_fallingdetect = l1;
1986 bank->saved_risingdetect = l2;
1987 l1 &= ~bank->enabled_non_wakeup_gpios;
1988 l2 &= ~bank->enabled_non_wakeup_gpios;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301989#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001990 __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1991 __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001992#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301993#ifdef CONFIG_ARCH_OMAP4
1994 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
1995 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
1996#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001997 c++;
1998 }
1999 if (!c) {
2000 workaround_enabled = 0;
2001 return;
2002 }
2003 workaround_enabled = 1;
2004}
2005
2006void omap2_gpio_resume_after_retention(void)
2007{
2008 int i;
2009
2010 if (!workaround_enabled)
2011 return;
2012 for (i = 0; i < gpio_bank_count; i++) {
2013 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002014 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002015
2016 if (!(bank->enabled_non_wakeup_gpios))
2017 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302018#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002019 __raw_writel(bank->saved_fallingdetect,
2020 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2021 __raw_writel(bank->saved_risingdetect,
2022 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302023 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2024#endif
2025#ifdef CONFIG_ARCH_OMAP4
2026 __raw_writel(bank->saved_fallingdetect,
2027 bank->base + OMAP4_GPIO_FALLINGDETECT);
2028 __raw_writel(bank->saved_risingdetect,
2029 bank->base + OMAP4_GPIO_RISINGDETECT);
2030 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002031#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002032 /* Check if any of the non-wakeup interrupt GPIOs have changed
2033 * state. If so, generate an IRQ by software. This is
2034 * horribly racy, but it's the best we can do to work around
2035 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002036 l ^= bank->saved_datain;
2037 l &= bank->non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002038
2039 /*
2040 * No need to generate IRQs for the rising edge for gpio IRQs
2041 * configured with falling edge only; and vice versa.
2042 */
2043 gen0 = l & bank->saved_fallingdetect;
2044 gen0 &= bank->saved_datain;
2045
2046 gen1 = l & bank->saved_risingdetect;
2047 gen1 &= ~(bank->saved_datain);
2048
2049 /* FIXME: Consider GPIO IRQs with level detections properly! */
2050 gen = l & (~(bank->saved_fallingdetect) &
2051 ~(bank->saved_risingdetect));
2052 /* Consider all GPIO IRQs needed to be updated */
2053 gen |= gen0 | gen1;
2054
2055 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002056 u32 old0, old1;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302057#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002058 old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2059 old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002060 __raw_writel(old0 | gen, bank->base +
2061 OMAP24XX_GPIO_LEVELDETECT0);
2062 __raw_writel(old1 | gen, bank->base +
2063 OMAP24XX_GPIO_LEVELDETECT1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002064 __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2065 __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002066#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302067#ifdef CONFIG_ARCH_OMAP4
2068 old0 = __raw_readl(bank->base +
2069 OMAP4_GPIO_LEVELDETECT0);
2070 old1 = __raw_readl(bank->base +
2071 OMAP4_GPIO_LEVELDETECT1);
2072 __raw_writel(old0 | l, bank->base +
2073 OMAP4_GPIO_LEVELDETECT0);
2074 __raw_writel(old1 | l, bank->base +
2075 OMAP4_GPIO_LEVELDETECT1);
2076 __raw_writel(old0, bank->base +
2077 OMAP4_GPIO_LEVELDETECT0);
2078 __raw_writel(old1, bank->base +
2079 OMAP4_GPIO_LEVELDETECT1);
2080#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002081 }
2082 }
2083
2084}
2085
Tony Lindgren92105bb2005-09-07 17:20:26 +01002086#endif
2087
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302088#ifdef CONFIG_ARCH_OMAP34XX
2089/* save the registers of bank 2-6 */
2090void omap_gpio_save_context(void)
2091{
2092 int i;
2093
2094 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2095 for (i = 1; i < gpio_bank_count; i++) {
2096 struct gpio_bank *bank = &gpio_bank[i];
2097 gpio_context[i].sysconfig =
2098 __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG);
2099 gpio_context[i].irqenable1 =
2100 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
2101 gpio_context[i].irqenable2 =
2102 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
2103 gpio_context[i].wake_en =
2104 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
2105 gpio_context[i].ctrl =
2106 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
2107 gpio_context[i].oe =
2108 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
2109 gpio_context[i].leveldetect0 =
2110 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2111 gpio_context[i].leveldetect1 =
2112 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2113 gpio_context[i].risingdetect =
2114 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
2115 gpio_context[i].fallingdetect =
2116 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2117 gpio_context[i].dataout =
2118 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
2119 gpio_context[i].setwkuena =
2120 __raw_readl(bank->base + OMAP24XX_GPIO_SETWKUENA);
2121 gpio_context[i].setdataout =
2122 __raw_readl(bank->base + OMAP24XX_GPIO_SETDATAOUT);
2123 }
2124}
2125
2126/* restore the required registers of bank 2-6 */
2127void omap_gpio_restore_context(void)
2128{
2129 int i;
2130
2131 for (i = 1; i < gpio_bank_count; i++) {
2132 struct gpio_bank *bank = &gpio_bank[i];
2133 __raw_writel(gpio_context[i].sysconfig,
2134 bank->base + OMAP24XX_GPIO_SYSCONFIG);
2135 __raw_writel(gpio_context[i].irqenable1,
2136 bank->base + OMAP24XX_GPIO_IRQENABLE1);
2137 __raw_writel(gpio_context[i].irqenable2,
2138 bank->base + OMAP24XX_GPIO_IRQENABLE2);
2139 __raw_writel(gpio_context[i].wake_en,
2140 bank->base + OMAP24XX_GPIO_WAKE_EN);
2141 __raw_writel(gpio_context[i].ctrl,
2142 bank->base + OMAP24XX_GPIO_CTRL);
2143 __raw_writel(gpio_context[i].oe,
2144 bank->base + OMAP24XX_GPIO_OE);
2145 __raw_writel(gpio_context[i].leveldetect0,
2146 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2147 __raw_writel(gpio_context[i].leveldetect1,
2148 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2149 __raw_writel(gpio_context[i].risingdetect,
2150 bank->base + OMAP24XX_GPIO_RISINGDETECT);
2151 __raw_writel(gpio_context[i].fallingdetect,
2152 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2153 __raw_writel(gpio_context[i].dataout,
2154 bank->base + OMAP24XX_GPIO_DATAOUT);
2155 __raw_writel(gpio_context[i].setwkuena,
2156 bank->base + OMAP24XX_GPIO_SETWKUENA);
2157 __raw_writel(gpio_context[i].setdataout,
2158 bank->base + OMAP24XX_GPIO_SETDATAOUT);
2159 }
2160}
2161#endif
2162
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002163/*
2164 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002165 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002166 */
David Brownell277d58e2006-12-06 17:13:59 -08002167int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002168{
2169 if (!initialized)
2170 return _omap_gpio_init();
2171 else
2172 return 0;
2173}
2174
Tony Lindgren92105bb2005-09-07 17:20:26 +01002175static int __init omap_gpio_sysinit(void)
2176{
2177 int ret = 0;
2178
2179 if (!initialized)
2180 ret = _omap_gpio_init();
2181
David Brownell11a78b72006-12-06 17:14:11 -08002182 mpuio_init();
2183
Santosh Shilimkar44169072009-05-28 14:16:04 -07002184#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
2185 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002186 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002187 if (ret == 0) {
2188 ret = sysdev_class_register(&omap_gpio_sysclass);
2189 if (ret == 0)
2190 ret = sysdev_register(&omap_gpio_device);
2191 }
2192 }
2193#endif
2194
2195 return ret;
2196}
2197
Tony Lindgren92105bb2005-09-07 17:20:26 +01002198arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002199
2200
2201#ifdef CONFIG_DEBUG_FS
2202
2203#include <linux/debugfs.h>
2204#include <linux/seq_file.h>
2205
David Brownellb9772a22006-12-06 17:13:53 -08002206static int dbg_gpio_show(struct seq_file *s, void *unused)
2207{
2208 unsigned i, j, gpio;
2209
2210 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2211 struct gpio_bank *bank = gpio_bank + i;
2212 unsigned bankwidth = 16;
2213 u32 mask = 1;
2214
David Brownelle5c56ed2006-12-06 17:13:59 -08002215 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002216 gpio = OMAP_MPUIO(0);
Alistair Buxtonb718aa82009-09-23 18:56:19 +01002217 else if (cpu_class_is_omap2() || cpu_is_omap7xx())
David Brownellb9772a22006-12-06 17:13:53 -08002218 bankwidth = 32;
2219
2220 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2221 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002222 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002223
David Brownell52e31342008-03-03 12:43:23 -08002224 label = gpiochip_is_requested(&bank->chip, j);
2225 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002226 continue;
2227
2228 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002229 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002230 is_in = gpio_is_input(bank, mask);
2231
David Brownelle5c56ed2006-12-06 17:13:59 -08002232 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002233 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002234 else
David Brownell52e31342008-03-03 12:43:23 -08002235 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002236 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002237 label,
David Brownellb9772a22006-12-06 17:13:53 -08002238 is_in ? "in " : "out",
2239 value ? "hi" : "lo");
2240
David Brownell52e31342008-03-03 12:43:23 -08002241/* FIXME for at least omap2, show pullup/pulldown state */
2242
David Brownellb9772a22006-12-06 17:13:53 -08002243 irqstat = irq_desc[irq].status;
Tony Lindgren3a26e332009-01-15 13:09:53 +02002244#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07002245 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
David Brownellb9772a22006-12-06 17:13:53 -08002246 if (is_in && ((bank->suspend_wakeup & mask)
2247 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2248 char *trigger = NULL;
2249
2250 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2251 case IRQ_TYPE_EDGE_FALLING:
2252 trigger = "falling";
2253 break;
2254 case IRQ_TYPE_EDGE_RISING:
2255 trigger = "rising";
2256 break;
2257 case IRQ_TYPE_EDGE_BOTH:
2258 trigger = "bothedge";
2259 break;
2260 case IRQ_TYPE_LEVEL_LOW:
2261 trigger = "low";
2262 break;
2263 case IRQ_TYPE_LEVEL_HIGH:
2264 trigger = "high";
2265 break;
2266 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002267 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002268 break;
2269 }
David Brownell52e31342008-03-03 12:43:23 -08002270 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002271 irq, trigger,
2272 (bank->suspend_wakeup & mask)
2273 ? " wakeup" : "");
2274 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002275#endif
David Brownellb9772a22006-12-06 17:13:53 -08002276 seq_printf(s, "\n");
2277 }
2278
David Brownelle5c56ed2006-12-06 17:13:59 -08002279 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002280 seq_printf(s, "\n");
2281 gpio = 0;
2282 }
2283 }
2284 return 0;
2285}
2286
2287static int dbg_gpio_open(struct inode *inode, struct file *file)
2288{
David Brownelle5c56ed2006-12-06 17:13:59 -08002289 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002290}
2291
2292static const struct file_operations debug_fops = {
2293 .open = dbg_gpio_open,
2294 .read = seq_read,
2295 .llseek = seq_lseek,
2296 .release = single_release,
2297};
2298
2299static int __init omap_gpio_debuginit(void)
2300{
David Brownelle5c56ed2006-12-06 17:13:59 -08002301 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2302 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002303 return 0;
2304}
2305late_initcall(omap_gpio_debuginit);
2306#endif