blob: 2f185ffaca4ae2ed2de8b838cc88dda437e06f9c [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
2 * linux/arch/arm/plat-omap/gpio.c
3 *
4 * Support functions for OMAP GPIO
5 *
Tony Lindgren92105bb2005-09-07 17:20:26 +01006 * Copyright (C) 2003-2005 Nokia Corporation
Jan Engelhardt96de0e22007-10-19 23:21:04 +02007 * Written by Juha Yrjölä <juha.yrjola@nokia.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01008 *
Santosh Shilimkar44169072009-05-28 14:16:04 -07009 * Copyright (C) 2009 Texas Instruments
10 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
11 *
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010017#include <linux/init.h>
18#include <linux/module.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010019#include <linux/interrupt.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010020#include <linux/sysdev.h>
21#include <linux/err.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000022#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010024
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010026#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/irqs.h>
28#include <mach/gpio.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010029#include <asm/mach/irq.h>
30
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010031/*
32 * OMAP1510 GPIO registers
33 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070034#define OMAP1510_GPIO_BASE 0xfffce000
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010035#define OMAP1510_GPIO_DATA_INPUT 0x00
36#define OMAP1510_GPIO_DATA_OUTPUT 0x04
37#define OMAP1510_GPIO_DIR_CONTROL 0x08
38#define OMAP1510_GPIO_INT_CONTROL 0x0c
39#define OMAP1510_GPIO_INT_MASK 0x10
40#define OMAP1510_GPIO_INT_STATUS 0x14
41#define OMAP1510_GPIO_PIN_CONTROL 0x18
42
43#define OMAP1510_IH_GPIO_BASE 64
44
45/*
46 * OMAP1610 specific GPIO registers
47 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070048#define OMAP1610_GPIO1_BASE 0xfffbe400
49#define OMAP1610_GPIO2_BASE 0xfffbec00
50#define OMAP1610_GPIO3_BASE 0xfffbb400
51#define OMAP1610_GPIO4_BASE 0xfffbbc00
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010052#define OMAP1610_GPIO_REVISION 0x0000
53#define OMAP1610_GPIO_SYSCONFIG 0x0010
54#define OMAP1610_GPIO_SYSSTATUS 0x0014
55#define OMAP1610_GPIO_IRQSTATUS1 0x0018
56#define OMAP1610_GPIO_IRQENABLE1 0x001c
Tony Lindgren92105bb2005-09-07 17:20:26 +010057#define OMAP1610_GPIO_WAKEUPENABLE 0x0028
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010058#define OMAP1610_GPIO_DATAIN 0x002c
59#define OMAP1610_GPIO_DATAOUT 0x0030
60#define OMAP1610_GPIO_DIRECTION 0x0034
61#define OMAP1610_GPIO_EDGE_CTRL1 0x0038
62#define OMAP1610_GPIO_EDGE_CTRL2 0x003c
63#define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
Tony Lindgren92105bb2005-09-07 17:20:26 +010064#define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010065#define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
66#define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
Tony Lindgren92105bb2005-09-07 17:20:26 +010067#define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010068#define OMAP1610_GPIO_SET_DATAOUT 0x00f0
69
70/*
Alistair Buxton7c006922009-09-22 10:02:58 +010071 * OMAP7XX specific GPIO registers
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010072 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070073#define OMAP7XX_GPIO1_BASE 0xfffbc000
74#define OMAP7XX_GPIO2_BASE 0xfffbc800
75#define OMAP7XX_GPIO3_BASE 0xfffbd000
76#define OMAP7XX_GPIO4_BASE 0xfffbd800
77#define OMAP7XX_GPIO5_BASE 0xfffbe000
78#define OMAP7XX_GPIO6_BASE 0xfffbe800
Alistair Buxton7c006922009-09-22 10:02:58 +010079#define OMAP7XX_GPIO_DATA_INPUT 0x00
80#define OMAP7XX_GPIO_DATA_OUTPUT 0x04
81#define OMAP7XX_GPIO_DIR_CONTROL 0x08
82#define OMAP7XX_GPIO_INT_CONTROL 0x0c
83#define OMAP7XX_GPIO_INT_MASK 0x10
84#define OMAP7XX_GPIO_INT_STATUS 0x14
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010085
Tony Lindgren9f7065d2009-10-19 15:25:20 -070086#define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
Tony Lindgren94113262009-08-28 10:50:33 -070087
Zebediah C. McClure56739a62009-03-23 18:07:40 -070088/*
Tony Lindgren92105bb2005-09-07 17:20:26 +010089 * omap24xx specific GPIO registers
90 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070091#define OMAP242X_GPIO1_BASE 0x48018000
92#define OMAP242X_GPIO2_BASE 0x4801a000
93#define OMAP242X_GPIO3_BASE 0x4801c000
94#define OMAP242X_GPIO4_BASE 0x4801e000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -080095
Tony Lindgren9f7065d2009-10-19 15:25:20 -070096#define OMAP243X_GPIO1_BASE 0x4900C000
97#define OMAP243X_GPIO2_BASE 0x4900E000
98#define OMAP243X_GPIO3_BASE 0x49010000
99#define OMAP243X_GPIO4_BASE 0x49012000
100#define OMAP243X_GPIO5_BASE 0x480B6000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800101
Tony Lindgren92105bb2005-09-07 17:20:26 +0100102#define OMAP24XX_GPIO_REVISION 0x0000
103#define OMAP24XX_GPIO_SYSCONFIG 0x0010
104#define OMAP24XX_GPIO_SYSSTATUS 0x0014
105#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300106#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
107#define OMAP24XX_GPIO_IRQENABLE2 0x002c
Tony Lindgren92105bb2005-09-07 17:20:26 +0100108#define OMAP24XX_GPIO_IRQENABLE1 0x001c
Tero Kristo723fdb72008-11-26 14:35:16 -0800109#define OMAP24XX_GPIO_WAKE_EN 0x0020
Tony Lindgren92105bb2005-09-07 17:20:26 +0100110#define OMAP24XX_GPIO_CTRL 0x0030
111#define OMAP24XX_GPIO_OE 0x0034
112#define OMAP24XX_GPIO_DATAIN 0x0038
113#define OMAP24XX_GPIO_DATAOUT 0x003c
114#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
115#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
116#define OMAP24XX_GPIO_RISINGDETECT 0x0048
117#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700118#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
119#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
Tony Lindgren92105bb2005-09-07 17:20:26 +0100120#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
121#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
122#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
123#define OMAP24XX_GPIO_SETWKUENA 0x0084
124#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
125#define OMAP24XX_GPIO_SETDATAOUT 0x0094
126
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530127#define OMAP4_GPIO_REVISION 0x0000
128#define OMAP4_GPIO_SYSCONFIG 0x0010
129#define OMAP4_GPIO_EOI 0x0020
130#define OMAP4_GPIO_IRQSTATUSRAW0 0x0024
131#define OMAP4_GPIO_IRQSTATUSRAW1 0x0028
132#define OMAP4_GPIO_IRQSTATUS0 0x002c
133#define OMAP4_GPIO_IRQSTATUS1 0x0030
134#define OMAP4_GPIO_IRQSTATUSSET0 0x0034
135#define OMAP4_GPIO_IRQSTATUSSET1 0x0038
136#define OMAP4_GPIO_IRQSTATUSCLR0 0x003c
137#define OMAP4_GPIO_IRQSTATUSCLR1 0x0040
138#define OMAP4_GPIO_IRQWAKEN0 0x0044
139#define OMAP4_GPIO_IRQWAKEN1 0x0048
140#define OMAP4_GPIO_SYSSTATUS 0x0104
141#define OMAP4_GPIO_CTRL 0x0130
142#define OMAP4_GPIO_OE 0x0134
143#define OMAP4_GPIO_DATAIN 0x0138
144#define OMAP4_GPIO_DATAOUT 0x013c
145#define OMAP4_GPIO_LEVELDETECT0 0x0140
146#define OMAP4_GPIO_LEVELDETECT1 0x0144
147#define OMAP4_GPIO_RISINGDETECT 0x0148
148#define OMAP4_GPIO_FALLINGDETECT 0x014c
149#define OMAP4_GPIO_DEBOUNCENABLE 0x0150
150#define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
151#define OMAP4_GPIO_CLEARDATAOUT 0x0190
152#define OMAP4_GPIO_SETDATAOUT 0x0194
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800153/*
154 * omap34xx specific GPIO registers
155 */
156
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700157#define OMAP34XX_GPIO1_BASE 0x48310000
158#define OMAP34XX_GPIO2_BASE 0x49050000
159#define OMAP34XX_GPIO3_BASE 0x49052000
160#define OMAP34XX_GPIO4_BASE 0x49054000
161#define OMAP34XX_GPIO5_BASE 0x49056000
162#define OMAP34XX_GPIO6_BASE 0x49058000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800163
Santosh Shilimkar44169072009-05-28 14:16:04 -0700164/*
165 * OMAP44XX specific GPIO registers
166 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700167#define OMAP44XX_GPIO1_BASE 0x4a310000
168#define OMAP44XX_GPIO2_BASE 0x48055000
169#define OMAP44XX_GPIO3_BASE 0x48057000
170#define OMAP44XX_GPIO4_BASE 0x48059000
171#define OMAP44XX_GPIO5_BASE 0x4805B000
172#define OMAP44XX_GPIO6_BASE 0x4805D000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800173
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100174struct gpio_bank {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700175 unsigned long pbase;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100176 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100177 u16 irq;
178 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100179 int method;
Tony Lindgren140455f2010-02-12 12:26:48 -0800180#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100181 u32 suspend_wakeup;
182 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800183#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800184#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800185 u32 non_wakeup_gpios;
186 u32 enabled_non_wakeup_gpios;
187
188 u32 saved_datain;
189 u32 saved_fallingdetect;
190 u32 saved_risingdetect;
191#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800192 u32 level_mask;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800193 u32 toggle_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100194 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800195 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800196 struct clk *dbck;
Charulatha V058af1e2009-11-22 10:11:25 -0800197 u32 mod_usage;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100198};
199
200#define METHOD_MPUIO 0
201#define METHOD_GPIO_1510 1
202#define METHOD_GPIO_1610 2
Alistair Buxton7c006922009-09-22 10:02:58 +0100203#define METHOD_GPIO_7XX 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700204#define METHOD_GPIO_24XX 5
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800205#define METHOD_GPIO_44XX 6
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 Lindgren088ef952010-02-12 12:26:47 -0800250#ifdef CONFIG_ARCH_OMAP2
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
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800278#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800279static 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] = {
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530315 { OMAP44XX_GPIO1_BASE, NULL, OMAP44XX_IRQ_GPIO1, IH_GPIO_BASE,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800316 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530317 { OMAP44XX_GPIO2_BASE, NULL, OMAP44XX_IRQ_GPIO2, IH_GPIO_BASE + 32,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800318 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530319 { OMAP44XX_GPIO3_BASE, NULL, OMAP44XX_IRQ_GPIO3, IH_GPIO_BASE + 64,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800320 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530321 { OMAP44XX_GPIO4_BASE, NULL, OMAP44XX_IRQ_GPIO4, IH_GPIO_BASE + 96,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800322 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530323 { OMAP44XX_GPIO5_BASE, NULL, OMAP44XX_IRQ_GPIO5, IH_GPIO_BASE + 128,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800324 METHOD_GPIO_44XX },
Santosh Shilimkar5772ca72010-02-18 03:14:12 +0530325 { OMAP44XX_GPIO6_BASE, NULL, OMAP44XX_IRQ_GPIO6, IH_GPIO_BASE + 160,
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800326 METHOD_GPIO_44XX },
Santosh Shilimkar44169072009-05-28 14:16:04 -0700327};
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
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800428#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
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)
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800434 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530435 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
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800495#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
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
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800505 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530506 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
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800548#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
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
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800554 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530555 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
Tony Lindgren140455f2010-02-12 12:26:48 -0800594#ifdef CONFIG_ARCH_OMAP2PLUS
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300595 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800596 case METHOD_GPIO_44XX:
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300597 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;
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800627
628 if (cpu_is_omap44xx())
629 reg += OMAP4_GPIO_DEBOUNCENABLE;
630 else
631 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
632
Charulatha V058af1e2009-11-22 10:11:25 -0800633 if (!(bank->mod_usage & l)) {
634 printk(KERN_ERR "GPIO %d not requested\n", gpio);
635 return;
636 }
David Brownelle031ab22008-12-10 17:35:27 -0800637
638 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700639 val = __raw_readl(reg);
640
Jouni Hogander89db9482008-12-10 17:35:24 -0800641 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700642 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800643 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700644 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800645 else
David Brownelle031ab22008-12-10 17:35:27 -0800646 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800647
Santosh Shilimkar44169072009-05-28 14:16:04 -0700648 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800649 if (enable)
650 clk_enable(bank->dbck);
651 else
652 clk_disable(bank->dbck);
653 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700654
655 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800656done:
657 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700658}
659EXPORT_SYMBOL(omap_set_gpio_debounce);
660
661void omap_set_gpio_debounce_time(int gpio, int enc_time)
662{
663 struct gpio_bank *bank;
664 void __iomem *reg;
665
666 if (cpu_class_is_omap1())
667 return;
668
669 bank = get_gpio_bank(gpio);
670 reg = bank->base;
671
Charulatha V058af1e2009-11-22 10:11:25 -0800672 if (!bank->mod_usage) {
673 printk(KERN_ERR "GPIO not requested\n");
674 return;
675 }
676
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700677 enc_time &= 0xff;
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800678
679 if (cpu_is_omap44xx())
680 reg += OMAP4_GPIO_DEBOUNCINGTIME;
681 else
682 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
683
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700684 __raw_writel(enc_time, reg);
685}
686EXPORT_SYMBOL(omap_set_gpio_debounce_time);
687
Tony Lindgren140455f2010-02-12 12:26:48 -0800688#ifdef CONFIG_ARCH_OMAP2PLUS
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700689static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
690 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100691{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800692 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100693 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530694 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100695
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530696 if (cpu_is_omap44xx()) {
697 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
698 trigger & IRQ_TYPE_LEVEL_LOW);
699 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
700 trigger & IRQ_TYPE_LEVEL_HIGH);
701 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
702 trigger & IRQ_TYPE_EDGE_RISING);
703 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
704 trigger & IRQ_TYPE_EDGE_FALLING);
705 } else {
706 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
707 trigger & IRQ_TYPE_LEVEL_LOW);
708 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
709 trigger & IRQ_TYPE_LEVEL_HIGH);
710 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
711 trigger & IRQ_TYPE_EDGE_RISING);
712 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
713 trigger & IRQ_TYPE_EDGE_FALLING);
714 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800715 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530716 if (cpu_is_omap44xx()) {
717 if (trigger != 0)
718 __raw_writel(1 << gpio, bank->base+
719 OMAP4_GPIO_IRQWAKEN0);
720 else {
721 val = __raw_readl(bank->base +
722 OMAP4_GPIO_IRQWAKEN0);
723 __raw_writel(val & (~(1 << gpio)), bank->base +
724 OMAP4_GPIO_IRQWAKEN0);
725 }
726 } else {
Chunqiu Wang699117a2009-06-24 17:13:39 +0000727 /*
728 * GPIO wakeup request can only be generated on edge
729 * transitions
730 */
731 if (trigger & IRQ_TYPE_EDGE_BOTH)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530732 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700733 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530734 else
735 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700736 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530737 }
Tero Kristoa118b5f2008-12-22 14:27:12 +0200738 }
739 /* This part needs to be executed always for OMAP34xx */
740 if (cpu_is_omap34xx() || (bank->non_wakeup_gpios & gpio_bit)) {
Chunqiu Wang699117a2009-06-24 17:13:39 +0000741 /*
742 * Log the edge gpio and manually trigger the IRQ
743 * after resume if the input level changes
744 * to avoid irq lost during PER RET/OFF mode
745 * Applies for omap2 non-wakeup gpio and all omap3 gpios
746 */
747 if (trigger & IRQ_TYPE_EDGE_BOTH)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800748 bank->enabled_non_wakeup_gpios |= gpio_bit;
749 else
750 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
751 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700752
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530753 if (cpu_is_omap44xx()) {
754 bank->level_mask =
755 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
756 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
757 } else {
758 bank->level_mask =
759 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
760 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
761 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100762}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800763#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100764
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800765#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800766/*
767 * This only applies to chips that can't do both rising and falling edge
768 * detection at once. For all other chips, this function is a noop.
769 */
770static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
771{
772 void __iomem *reg = bank->base;
773 u32 l = 0;
774
775 switch (bank->method) {
Cory Maccarrone4318f362010-01-08 10:29:04 -0800776 case METHOD_MPUIO:
777 reg += OMAP_MPUIO_GPIO_INT_EDGE;
778 break;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800779#ifdef CONFIG_ARCH_OMAP15XX
780 case METHOD_GPIO_1510:
781 reg += OMAP1510_GPIO_INT_CONTROL;
782 break;
783#endif
784#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
785 case METHOD_GPIO_7XX:
786 reg += OMAP7XX_GPIO_INT_CONTROL;
787 break;
788#endif
789 default:
790 return;
791 }
792
793 l = __raw_readl(reg);
794 if ((l >> gpio) & 1)
795 l &= ~(1 << gpio);
796 else
797 l |= 1 << gpio;
798
799 __raw_writel(l, reg);
800}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800801#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800802
Tony Lindgren92105bb2005-09-07 17:20:26 +0100803static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
804{
805 void __iomem *reg = bank->base;
806 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100807
808 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800809#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100810 case METHOD_MPUIO:
811 reg += OMAP_MPUIO_GPIO_INT_EDGE;
812 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000813 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800814 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100815 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100816 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100817 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100818 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100819 else
820 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100821 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800822#endif
823#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100824 case METHOD_GPIO_1510:
825 reg += OMAP1510_GPIO_INT_CONTROL;
826 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000827 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800828 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100829 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100830 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100831 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100832 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100833 else
834 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100835 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800836#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800837#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100838 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100839 if (gpio & 0x08)
840 reg += OMAP1610_GPIO_EDGE_CTRL2;
841 else
842 reg += OMAP1610_GPIO_EDGE_CTRL1;
843 gpio &= 0x07;
844 l = __raw_readl(reg);
845 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100846 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100847 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100848 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100849 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800850 if (trigger)
851 /* Enable wake-up during idle for dynamic tick */
852 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
853 else
854 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100855 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800856#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100857#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100858 case METHOD_GPIO_7XX:
859 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700860 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000861 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800862 bank->toggle_mask |= 1 << gpio;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700863 if (trigger & IRQ_TYPE_EDGE_RISING)
864 l |= 1 << gpio;
865 else if (trigger & IRQ_TYPE_EDGE_FALLING)
866 l &= ~(1 << gpio);
867 else
868 goto bad;
869 break;
870#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800871#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +0100872 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800873 case METHOD_GPIO_44XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800874 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100875 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800876#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100877 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100878 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100879 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100880 __raw_writel(l, reg);
881 return 0;
882bad:
883 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100884}
885
Tony Lindgren92105bb2005-09-07 17:20:26 +0100886static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100887{
888 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100889 unsigned gpio;
890 int retval;
David Brownella6472532008-03-03 04:33:30 -0800891 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100892
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800893 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100894 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
895 else
896 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100897
898 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100899 return -EINVAL;
900
David Brownelle5c56ed2006-12-06 17:13:59 -0800901 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100902 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800903
904 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800905 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800906 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100907 return -EINVAL;
908
David Brownell58781012006-12-06 17:14:10 -0800909 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800910 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100911 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800912 if (retval == 0) {
913 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
914 irq_desc[irq].status |= type;
915 }
David Brownella6472532008-03-03 04:33:30 -0800916 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800917
918 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
919 __set_irq_handler_unlocked(irq, handle_level_irq);
920 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
921 __set_irq_handler_unlocked(irq, handle_edge_irq);
922
Tony Lindgren92105bb2005-09-07 17:20:26 +0100923 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100924}
925
926static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
927{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100928 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100929
930 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800931#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100932 case METHOD_MPUIO:
933 /* MPUIO irqstatus is reset by reading the status register,
934 * so do nothing here */
935 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800936#endif
937#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100938 case METHOD_GPIO_1510:
939 reg += OMAP1510_GPIO_INT_STATUS;
940 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800941#endif
942#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100943 case METHOD_GPIO_1610:
944 reg += OMAP1610_GPIO_IRQSTATUS1;
945 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800946#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100947#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100948 case METHOD_GPIO_7XX:
949 reg += OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700950 break;
951#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800952#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100953 case METHOD_GPIO_24XX:
954 reg += OMAP24XX_GPIO_IRQSTATUS1;
955 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800956#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530957#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800958 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530959 reg += OMAP4_GPIO_IRQSTATUS0;
960 break;
961#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100962 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800963 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100964 return;
965 }
966 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300967
968 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800969 if (cpu_is_omap24xx() || cpu_is_omap34xx())
970 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
971 else if (cpu_is_omap44xx())
972 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
973
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530974 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700975 __raw_writel(gpio_mask, reg);
976
977 /* Flush posted write for the irq status to avoid spurious interrupts */
978 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530979 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100980}
981
982static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
983{
984 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
985}
986
Imre Deakea6dedd2006-06-26 16:16:00 -0700987static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
988{
989 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700990 int inv = 0;
991 u32 l;
992 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700993
994 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800995#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700996 case METHOD_MPUIO:
997 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700998 mask = 0xffff;
999 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -07001000 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001001#endif
1002#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -07001003 case METHOD_GPIO_1510:
1004 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -07001005 mask = 0xffff;
1006 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -07001007 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001008#endif
1009#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -07001010 case METHOD_GPIO_1610:
1011 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001012 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001013 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001014#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001015#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001016 case METHOD_GPIO_7XX:
1017 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001018 mask = 0xffffffff;
1019 inv = 1;
1020 break;
1021#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001022#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Imre Deakea6dedd2006-06-26 16:16:00 -07001023 case METHOD_GPIO_24XX:
1024 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001025 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001026 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001027#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301028#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001029 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301030 reg += OMAP4_GPIO_IRQSTATUSSET0;
1031 mask = 0xffffffff;
1032 break;
1033#endif
Imre Deakea6dedd2006-06-26 16:16:00 -07001034 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001035 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -07001036 return 0;
1037 }
1038
Imre Deak99c47702006-06-26 16:16:07 -07001039 l = __raw_readl(reg);
1040 if (inv)
1041 l = ~l;
1042 l &= mask;
1043 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -07001044}
1045
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001046static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
1047{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001048 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001049 u32 l;
1050
1051 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001052#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001053 case METHOD_MPUIO:
1054 reg += OMAP_MPUIO_GPIO_MASKIT;
1055 l = __raw_readl(reg);
1056 if (enable)
1057 l &= ~(gpio_mask);
1058 else
1059 l |= gpio_mask;
1060 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001061#endif
1062#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001063 case METHOD_GPIO_1510:
1064 reg += OMAP1510_GPIO_INT_MASK;
1065 l = __raw_readl(reg);
1066 if (enable)
1067 l &= ~(gpio_mask);
1068 else
1069 l |= gpio_mask;
1070 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001071#endif
1072#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001073 case METHOD_GPIO_1610:
1074 if (enable)
1075 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1076 else
1077 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1078 l = gpio_mask;
1079 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001080#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001081#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001082 case METHOD_GPIO_7XX:
1083 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001084 l = __raw_readl(reg);
1085 if (enable)
1086 l &= ~(gpio_mask);
1087 else
1088 l |= gpio_mask;
1089 break;
1090#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001091#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001092 case METHOD_GPIO_24XX:
1093 if (enable)
1094 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1095 else
1096 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1097 l = gpio_mask;
1098 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001099#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301100#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001101 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301102 if (enable)
1103 reg += OMAP4_GPIO_IRQSTATUSSET0;
1104 else
1105 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1106 l = gpio_mask;
1107 break;
1108#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001109 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001110 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001111 return;
1112 }
1113 __raw_writel(l, reg);
1114}
1115
1116static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1117{
1118 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1119}
1120
Tony Lindgren92105bb2005-09-07 17:20:26 +01001121/*
1122 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1123 * 1510 does not seem to have a wake-up register. If JTAG is connected
1124 * to the target, system will wake up always on GPIO events. While
1125 * system is running all registered GPIO interrupts need to have wake-up
1126 * enabled. When system is suspended, only selected GPIO interrupts need
1127 * to have wake-up enabled.
1128 */
1129static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1130{
Tony Lindgren4cc64202010-01-08 10:29:05 -08001131 unsigned long uninitialized_var(flags);
David Brownella6472532008-03-03 04:33:30 -08001132
Tony Lindgren92105bb2005-09-07 17:20:26 +01001133 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001134#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001135 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001136 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001137 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001138 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001139 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001140 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001141 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001142 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001143 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001144#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001145#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001146 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001147 case METHOD_GPIO_44XX:
David Brownell11a78b72006-12-06 17:14:11 -08001148 if (bank->non_wakeup_gpios & (1 << gpio)) {
1149 printk(KERN_ERR "Unable to modify wakeup on "
1150 "non-wakeup GPIO%d\n",
1151 (bank - gpio_bank) * 32 + gpio);
1152 return -EINVAL;
1153 }
David Brownella6472532008-03-03 04:33:30 -08001154 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001155 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001156 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001157 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001158 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001159 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001160 return 0;
1161#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001162 default:
1163 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1164 bank->method);
1165 return -EINVAL;
1166 }
1167}
1168
Tony Lindgren4196dd62006-09-25 12:41:38 +03001169static void _reset_gpio(struct gpio_bank *bank, int gpio)
1170{
1171 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1172 _set_gpio_irqenable(bank, gpio, 0);
1173 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001174 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001175}
1176
Tony Lindgren92105bb2005-09-07 17:20:26 +01001177/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1178static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1179{
1180 unsigned int gpio = irq - IH_GPIO_BASE;
1181 struct gpio_bank *bank;
1182 int retval;
1183
1184 if (check_gpio(gpio) < 0)
1185 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001186 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001187 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001188
1189 return retval;
1190}
1191
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001192static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001193{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001194 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001195 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001196
David Brownella6472532008-03-03 04:33:30 -08001197 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001198
Tony Lindgren4196dd62006-09-25 12:41:38 +03001199 /* Set trigger to none. You need to enable the desired trigger with
1200 * request_irq() or set_irq_type().
1201 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001202 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001203
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001204#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001205 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001206 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001207
Tony Lindgren92105bb2005-09-07 17:20:26 +01001208 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001209 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001210 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001211 }
1212#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001213 if (!cpu_class_is_omap1()) {
1214 if (!bank->mod_usage) {
1215 u32 ctrl;
1216 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1217 ctrl &= 0xFFFFFFFE;
1218 /* Module is enabled, clocks are not gated */
1219 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1220 }
1221 bank->mod_usage |= 1 << offset;
1222 }
David Brownella6472532008-03-03 04:33:30 -08001223 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001224
1225 return 0;
1226}
1227
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001228static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001229{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001230 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001231 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001232
David Brownella6472532008-03-03 04:33:30 -08001233 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001234#ifdef CONFIG_ARCH_OMAP16XX
1235 if (bank->method == METHOD_GPIO_1610) {
1236 /* Disable wake-up during idle for dynamic tick */
1237 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001238 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001239 }
1240#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001241#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001242 if ((bank->method == METHOD_GPIO_24XX) ||
1243 (bank->method == METHOD_GPIO_44XX)) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001244 /* Disable wake-up during idle for dynamic tick */
1245 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001246 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001247 }
1248#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001249 if (!cpu_class_is_omap1()) {
1250 bank->mod_usage &= ~(1 << offset);
1251 if (!bank->mod_usage) {
1252 u32 ctrl;
1253 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1254 /* Module is disabled, clocks are gated */
1255 ctrl |= 1;
1256 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1257 }
1258 }
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001259 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001260 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001261}
1262
1263/*
1264 * We need to unmask the GPIO bank interrupt as soon as possible to
1265 * avoid missing GPIO interrupts for other lines in the bank.
1266 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1267 * in the bank to avoid missing nested interrupts for a GPIO line.
1268 * If we wait to unmask individual GPIO lines in the bank after the
1269 * line's interrupt handler has been run, we may miss some nested
1270 * interrupts.
1271 */
Russell King10dd5ce2006-11-23 11:41:32 +00001272static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001273{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001274 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001275 u32 isr;
Cory Maccarrone4318f362010-01-08 10:29:04 -08001276 unsigned int gpio_irq, gpio_index;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001277 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001278 u32 retrigger = 0;
1279 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001280
1281 desc->chip->ack(irq);
1282
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001283 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001284#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001285 if (bank->method == METHOD_MPUIO)
1286 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001287#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001288#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001289 if (bank->method == METHOD_GPIO_1510)
1290 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1291#endif
1292#if defined(CONFIG_ARCH_OMAP16XX)
1293 if (bank->method == METHOD_GPIO_1610)
1294 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1295#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001296#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001297 if (bank->method == METHOD_GPIO_7XX)
1298 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001299#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001300#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001301 if (bank->method == METHOD_GPIO_24XX)
1302 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1303#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301304#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001305 if (bank->method == METHOD_GPIO_44XX)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301306 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1307#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001308 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001309 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001310 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001311
Imre Deakea6dedd2006-06-26 16:16:00 -07001312 enabled = _get_gpio_irqbank_mask(bank);
1313 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001314
1315 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1316 isr &= 0x0000ffff;
1317
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001318 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001319 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001320 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001321
1322 /* clear edge sensitive interrupts before handler(s) are
1323 called so that we don't miss any interrupt occurred while
1324 executing them */
1325 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1326 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1327 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1328
1329 /* if there is only edge sensitive GPIO pin interrupts
1330 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001331 if (!level_mask && !unmasked) {
1332 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001333 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001334 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001335
Imre Deakea6dedd2006-06-26 16:16:00 -07001336 isr |= retrigger;
1337 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001338 if (!isr)
1339 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001340
Tony Lindgren92105bb2005-09-07 17:20:26 +01001341 gpio_irq = bank->virtual_irq_start;
1342 for (; isr != 0; isr >>= 1, gpio_irq++) {
Cory Maccarrone4318f362010-01-08 10:29:04 -08001343 gpio_index = get_gpio_index(irq_to_gpio(gpio_irq));
1344
Tony Lindgren92105bb2005-09-07 17:20:26 +01001345 if (!(isr & 1))
1346 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001347
Cory Maccarrone4318f362010-01-08 10:29:04 -08001348#ifdef CONFIG_ARCH_OMAP1
1349 /*
1350 * Some chips can't respond to both rising and falling
1351 * at the same time. If this irq was requested with
1352 * both flags, we need to flip the ICR data for the IRQ
1353 * to respond to the IRQ for the opposite direction.
1354 * This will be indicated in the bank toggle_mask.
1355 */
1356 if (bank->toggle_mask & (1 << gpio_index))
1357 _toggle_gpio_edge_triggering(bank, gpio_index);
1358#endif
1359
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001360 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001361 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001362 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001363 /* if bank has any level sensitive GPIO pin interrupt
1364 configured, we must unmask the bank interrupt only after
1365 handler(s) are executed in order to avoid spurious bank
1366 interrupt */
1367 if (!unmasked)
1368 desc->chip->unmask(irq);
1369
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001370}
1371
Tony Lindgren4196dd62006-09-25 12:41:38 +03001372static void gpio_irq_shutdown(unsigned int irq)
1373{
1374 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001375 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001376
1377 _reset_gpio(bank, gpio);
1378}
1379
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001380static void gpio_ack_irq(unsigned int irq)
1381{
1382 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001383 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001384
1385 _clear_gpio_irqstatus(bank, gpio);
1386}
1387
1388static void gpio_mask_irq(unsigned int irq)
1389{
1390 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001391 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001392
1393 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001394 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001395}
1396
1397static void gpio_unmask_irq(unsigned int irq)
1398{
1399 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001400 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001401 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001402 struct irq_desc *desc = irq_to_desc(irq);
1403 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1404
1405 if (trigger)
1406 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001407
1408 /* For level-triggered GPIOs, the clearing must be done after
1409 * the HW source is cleared, thus after the handler has run */
1410 if (bank->level_mask & irq_mask) {
1411 _set_gpio_irqenable(bank, gpio, 0);
1412 _clear_gpio_irqstatus(bank, gpio);
1413 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001414
Kevin Hilman4de8c752008-01-16 21:56:14 -08001415 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001416}
1417
David Brownelle5c56ed2006-12-06 17:13:59 -08001418static struct irq_chip gpio_irq_chip = {
1419 .name = "GPIO",
1420 .shutdown = gpio_irq_shutdown,
1421 .ack = gpio_ack_irq,
1422 .mask = gpio_mask_irq,
1423 .unmask = gpio_unmask_irq,
1424 .set_type = gpio_irq_type,
1425 .set_wake = gpio_wake_enable,
1426};
1427
1428/*---------------------------------------------------------------------*/
1429
1430#ifdef CONFIG_ARCH_OMAP1
1431
1432/* MPUIO uses the always-on 32k clock */
1433
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001434static void mpuio_ack_irq(unsigned int irq)
1435{
1436 /* The ISR is reset automatically, so do nothing here. */
1437}
1438
1439static void mpuio_mask_irq(unsigned int irq)
1440{
1441 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001442 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001443
1444 _set_gpio_irqenable(bank, gpio, 0);
1445}
1446
1447static void mpuio_unmask_irq(unsigned int irq)
1448{
1449 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001450 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001451
1452 _set_gpio_irqenable(bank, gpio, 1);
1453}
1454
David Brownelle5c56ed2006-12-06 17:13:59 -08001455static struct irq_chip mpuio_irq_chip = {
1456 .name = "MPUIO",
1457 .ack = mpuio_ack_irq,
1458 .mask = mpuio_mask_irq,
1459 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001460 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001461#ifdef CONFIG_ARCH_OMAP16XX
1462 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1463 .set_wake = gpio_wake_enable,
1464#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001465};
1466
David Brownelle5c56ed2006-12-06 17:13:59 -08001467
1468#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1469
David Brownell11a78b72006-12-06 17:14:11 -08001470
1471#ifdef CONFIG_ARCH_OMAP16XX
1472
1473#include <linux/platform_device.h>
1474
Magnus Damm79ee0312009-07-08 13:22:04 +02001475static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001476{
Magnus Damm79ee0312009-07-08 13:22:04 +02001477 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001478 struct gpio_bank *bank = platform_get_drvdata(pdev);
1479 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001480 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001481
David Brownella6472532008-03-03 04:33:30 -08001482 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001483 bank->saved_wakeup = __raw_readl(mask_reg);
1484 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001485 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001486
1487 return 0;
1488}
1489
Magnus Damm79ee0312009-07-08 13:22:04 +02001490static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001491{
Magnus Damm79ee0312009-07-08 13:22:04 +02001492 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001493 struct gpio_bank *bank = platform_get_drvdata(pdev);
1494 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001495 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001496
David Brownella6472532008-03-03 04:33:30 -08001497 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001498 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001499 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001500
1501 return 0;
1502}
1503
Alexey Dobriyan47145212009-12-14 18:00:08 -08001504static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +02001505 .suspend_noirq = omap_mpuio_suspend_noirq,
1506 .resume_noirq = omap_mpuio_resume_noirq,
1507};
1508
David Brownell11a78b72006-12-06 17:14:11 -08001509/* use platform_driver for this, now that there's no longer any
1510 * point to sys_device (other than not disturbing old code).
1511 */
1512static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001513 .driver = {
1514 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001515 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001516 },
1517};
1518
1519static struct platform_device omap_mpuio_device = {
1520 .name = "mpuio",
1521 .id = -1,
1522 .dev = {
1523 .driver = &omap_mpuio_driver.driver,
1524 }
1525 /* could list the /proc/iomem resources */
1526};
1527
1528static inline void mpuio_init(void)
1529{
David Brownellfcf126d2007-04-02 12:46:47 -07001530 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1531
David Brownell11a78b72006-12-06 17:14:11 -08001532 if (platform_driver_register(&omap_mpuio_driver) == 0)
1533 (void) platform_device_register(&omap_mpuio_device);
1534}
1535
1536#else
1537static inline void mpuio_init(void) {}
1538#endif /* 16xx */
1539
David Brownelle5c56ed2006-12-06 17:13:59 -08001540#else
1541
1542extern struct irq_chip mpuio_irq_chip;
1543
1544#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001545static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001546
1547#endif
1548
1549/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001550
David Brownell52e31342008-03-03 12:43:23 -08001551/* REVISIT these are stupid implementations! replace by ones that
1552 * don't switch on METHOD_* and which mostly avoid spinlocks
1553 */
1554
1555static int gpio_input(struct gpio_chip *chip, unsigned offset)
1556{
1557 struct gpio_bank *bank;
1558 unsigned long flags;
1559
1560 bank = container_of(chip, struct gpio_bank, chip);
1561 spin_lock_irqsave(&bank->lock, flags);
1562 _set_gpio_direction(bank, offset, 1);
1563 spin_unlock_irqrestore(&bank->lock, flags);
1564 return 0;
1565}
1566
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001567static int gpio_is_input(struct gpio_bank *bank, int mask)
1568{
1569 void __iomem *reg = bank->base;
1570
1571 switch (bank->method) {
1572 case METHOD_MPUIO:
1573 reg += OMAP_MPUIO_IO_CNTL;
1574 break;
1575 case METHOD_GPIO_1510:
1576 reg += OMAP1510_GPIO_DIR_CONTROL;
1577 break;
1578 case METHOD_GPIO_1610:
1579 reg += OMAP1610_GPIO_DIRECTION;
1580 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001581 case METHOD_GPIO_7XX:
1582 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001583 break;
1584 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001585 case METHOD_GPIO_44XX:
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001586 reg += OMAP24XX_GPIO_OE;
1587 break;
1588 }
1589 return __raw_readl(reg) & mask;
1590}
1591
David Brownell52e31342008-03-03 12:43:23 -08001592static int gpio_get(struct gpio_chip *chip, unsigned offset)
1593{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001594 struct gpio_bank *bank;
1595 void __iomem *reg;
1596 int gpio;
1597 u32 mask;
1598
1599 gpio = chip->base + offset;
1600 bank = get_gpio_bank(gpio);
1601 reg = bank->base;
1602 mask = 1 << get_gpio_index(gpio);
1603
1604 if (gpio_is_input(bank, mask))
1605 return _get_gpio_datain(bank, gpio);
1606 else
1607 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001608}
1609
1610static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1611{
1612 struct gpio_bank *bank;
1613 unsigned long flags;
1614
1615 bank = container_of(chip, struct gpio_bank, chip);
1616 spin_lock_irqsave(&bank->lock, flags);
1617 _set_gpio_dataout(bank, offset, value);
1618 _set_gpio_direction(bank, offset, 0);
1619 spin_unlock_irqrestore(&bank->lock, flags);
1620 return 0;
1621}
1622
1623static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1624{
1625 struct gpio_bank *bank;
1626 unsigned long flags;
1627
1628 bank = container_of(chip, struct gpio_bank, chip);
1629 spin_lock_irqsave(&bank->lock, flags);
1630 _set_gpio_dataout(bank, offset, value);
1631 spin_unlock_irqrestore(&bank->lock, flags);
1632}
1633
David Brownella007b702008-12-10 17:35:25 -08001634static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1635{
1636 struct gpio_bank *bank;
1637
1638 bank = container_of(chip, struct gpio_bank, chip);
1639 return bank->virtual_irq_start + offset;
1640}
1641
David Brownell52e31342008-03-03 12:43:23 -08001642/*---------------------------------------------------------------------*/
1643
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001644static int initialized;
Tony Lindgren56213ca2010-02-12 12:26:46 -08001645#if defined(CONFIG_ARCH_OMAP1) || defined(CONFIG_ARCH_OMAP2)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001646static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001647#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001648
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001649#if defined(CONFIG_ARCH_OMAP2)
1650static struct clk * gpio_fck;
1651#endif
1652
1653#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001654static struct clk * gpio5_ick;
1655static struct clk * gpio5_fck;
1656#endif
1657
Santosh Shilimkar44169072009-05-28 14:16:04 -07001658#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001659static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1660#endif
1661
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001662static void __init omap_gpio_show_rev(void)
1663{
1664 u32 rev;
1665
1666 if (cpu_is_omap16xx())
1667 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1668 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1669 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1670 else if (cpu_is_omap44xx())
1671 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1672 else
1673 return;
1674
1675 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1676 (rev >> 4) & 0x0f, rev & 0x0f);
1677}
1678
David Brownell8ba55c52008-02-26 11:10:50 -08001679/* This lock class tells lockdep that GPIO irqs are in a different
1680 * category than their parents, so it won't report false recursion.
1681 */
1682static struct lock_class_key gpio_lock_class;
1683
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001684static int __init _omap_gpio_init(void)
1685{
1686 int i;
David Brownell52e31342008-03-03 12:43:23 -08001687 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001688 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001689 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001690 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001691
1692 initialized = 1;
1693
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001694#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001695 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001696 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1697 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001698 printk("Could not get arm_gpio_ck\n");
1699 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001700 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001701 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001702#endif
1703#if defined(CONFIG_ARCH_OMAP2)
1704 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001705 gpio_ick = clk_get(NULL, "gpios_ick");
1706 if (IS_ERR(gpio_ick))
1707 printk("Could not get gpios_ick\n");
1708 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001709 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001710 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001711 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001712 printk("Could not get gpios_fck\n");
1713 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001714 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001715
1716 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001717 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001718 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001719#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001720 if (cpu_is_omap2430()) {
1721 gpio5_ick = clk_get(NULL, "gpio5_ick");
1722 if (IS_ERR(gpio5_ick))
1723 printk("Could not get gpio5_ick\n");
1724 else
1725 clk_enable(gpio5_ick);
1726 gpio5_fck = clk_get(NULL, "gpio5_fck");
1727 if (IS_ERR(gpio5_fck))
1728 printk("Could not get gpio5_fck\n");
1729 else
1730 clk_enable(gpio5_fck);
1731 }
1732#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001733 }
1734#endif
1735
Santosh Shilimkar44169072009-05-28 14:16:04 -07001736#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1737 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001738 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1739 sprintf(clk_name, "gpio%d_ick", i + 1);
1740 gpio_iclks[i] = clk_get(NULL, clk_name);
1741 if (IS_ERR(gpio_iclks[i]))
1742 printk(KERN_ERR "Could not get %s\n", clk_name);
1743 else
1744 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001745 }
1746 }
1747#endif
1748
Tony Lindgren92105bb2005-09-07 17:20:26 +01001749
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001750#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001751 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001752 gpio_bank_count = 2;
1753 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001754 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001755 }
1756#endif
1757#if defined(CONFIG_ARCH_OMAP16XX)
1758 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001759 gpio_bank_count = 5;
1760 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001761 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001762 }
1763#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001764#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1765 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001766 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001767 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001768 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001769 }
1770#endif
Tony Lindgren088ef952010-02-12 12:26:47 -08001771#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001772 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001773 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001774 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001775 }
1776 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001777 gpio_bank_count = 5;
1778 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001779 }
1780#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001781#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001782 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001783 gpio_bank_count = OMAP34XX_NR_GPIOS;
1784 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001785 }
1786#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001787#ifdef CONFIG_ARCH_OMAP4
1788 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001789 gpio_bank_count = OMAP34XX_NR_GPIOS;
1790 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001791 }
1792#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001793 for (i = 0; i < gpio_bank_count; i++) {
1794 int j, gpio_count = 16;
1795
1796 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001797 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001798
1799 /* Static mapping, never released */
1800 bank->base = ioremap(bank->pbase, bank_size);
1801 if (!bank->base) {
1802 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1803 continue;
1804 }
1805
David Brownelle5c56ed2006-12-06 17:13:59 -08001806 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001807 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001808 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001809 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1810 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1811 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001812 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001813 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1814 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001815 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001816 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001817 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1818 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1819 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001820
Alistair Buxton7c006922009-09-22 10:02:58 +01001821 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001822 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001823
Tony Lindgren140455f2010-02-12 12:26:48 -08001824#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001825 if ((bank->method == METHOD_GPIO_24XX) ||
1826 (bank->method == METHOD_GPIO_44XX)) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001827 static const u32 non_wakeup_gpios[] = {
1828 0xe203ffc0, 0x08700040
1829 };
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001830
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001831 if (cpu_is_omap44xx()) {
1832 __raw_writel(0xffffffff, bank->base +
1833 OMAP4_GPIO_IRQSTATUSCLR0);
1834 __raw_writew(0x0015, bank->base +
1835 OMAP4_GPIO_SYSCONFIG);
1836 __raw_writel(0x00000000, bank->base +
1837 OMAP4_GPIO_DEBOUNCENABLE);
1838 /*
1839 * Initialize interface clock ungated,
1840 * module enabled
1841 */
1842 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1843 } else {
1844 __raw_writel(0x00000000, bank->base +
1845 OMAP24XX_GPIO_IRQENABLE1);
1846 __raw_writel(0xffffffff, bank->base +
1847 OMAP24XX_GPIO_IRQSTATUS1);
1848 __raw_writew(0x0015, bank->base +
1849 OMAP24XX_GPIO_SYSCONFIG);
1850 __raw_writel(0x00000000, bank->base +
1851 OMAP24XX_GPIO_DEBOUNCE_EN);
1852
1853 /*
1854 * Initialize interface clock ungated,
1855 * module enabled
1856 */
1857 __raw_writel(0, bank->base +
1858 OMAP24XX_GPIO_CTRL);
1859 }
Tero Kristoa118b5f2008-12-22 14:27:12 +02001860 if (cpu_is_omap24xx() &&
1861 i < ARRAY_SIZE(non_wakeup_gpios))
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001862 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001863 gpio_count = 32;
1864 }
1865#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001866
1867 bank->mod_usage = 0;
David Brownell52e31342008-03-03 12:43:23 -08001868 /* REVISIT eventually switch from OMAP-specific gpio structs
1869 * over to the generic ones
1870 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001871 bank->chip.request = omap_gpio_request;
1872 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001873 bank->chip.direction_input = gpio_input;
1874 bank->chip.get = gpio_get;
1875 bank->chip.direction_output = gpio_output;
1876 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001877 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001878 if (bank_is_mpuio(bank)) {
1879 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001880#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001881 bank->chip.dev = &omap_mpuio_device.dev;
1882#endif
David Brownell52e31342008-03-03 12:43:23 -08001883 bank->chip.base = OMAP_MPUIO(0);
1884 } else {
1885 bank->chip.label = "gpio";
1886 bank->chip.base = gpio;
1887 gpio += gpio_count;
1888 }
1889 bank->chip.ngpio = gpio_count;
1890
1891 gpiochip_add(&bank->chip);
1892
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001893 for (j = bank->virtual_irq_start;
1894 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001895 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001896 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001897 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001898 set_irq_chip(j, &mpuio_irq_chip);
1899 else
1900 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001901 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001902 set_irq_flags(j, IRQF_VALID);
1903 }
1904 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1905 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001906
Santosh Shilimkar44169072009-05-28 14:16:04 -07001907 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001908 sprintf(clk_name, "gpio%d_dbck", i + 1);
1909 bank->dbck = clk_get(NULL, clk_name);
1910 if (IS_ERR(bank->dbck))
1911 printk(KERN_ERR "Could not get %s\n", clk_name);
1912 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001913 }
1914
1915 /* Enable system clock for GPIO module.
1916 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001917 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001918 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1919
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001920 /* Enable autoidle for the OCP interface */
1921 if (cpu_is_omap24xx())
1922 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001923 if (cpu_is_omap34xx())
1924 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001925
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001926 omap_gpio_show_rev();
1927
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001928 return 0;
1929}
1930
Tony Lindgren140455f2010-02-12 12:26:48 -08001931#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001932static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1933{
1934 int i;
1935
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001936 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001937 return 0;
1938
1939 for (i = 0; i < gpio_bank_count; i++) {
1940 struct gpio_bank *bank = &gpio_bank[i];
1941 void __iomem *wake_status;
1942 void __iomem *wake_clear;
1943 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001944 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001945
1946 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001947#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001948 case METHOD_GPIO_1610:
1949 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1950 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1951 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1952 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001953#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001954#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001955 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001956 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001957 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1958 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1959 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001960#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301961#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001962 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301963 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1964 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1965 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1966 break;
1967#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001968 default:
1969 continue;
1970 }
1971
David Brownella6472532008-03-03 04:33:30 -08001972 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001973 bank->saved_wakeup = __raw_readl(wake_status);
1974 __raw_writel(0xffffffff, wake_clear);
1975 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001976 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001977 }
1978
1979 return 0;
1980}
1981
1982static int omap_gpio_resume(struct sys_device *dev)
1983{
1984 int i;
1985
Tero Kristo723fdb72008-11-26 14:35:16 -08001986 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001987 return 0;
1988
1989 for (i = 0; i < gpio_bank_count; i++) {
1990 struct gpio_bank *bank = &gpio_bank[i];
1991 void __iomem *wake_clear;
1992 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001993 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001994
1995 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001996#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001997 case METHOD_GPIO_1610:
1998 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1999 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
2000 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08002001#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002002#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01002003 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03002004 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
2005 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01002006 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08002007#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302008#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002009 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302010 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
2011 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
2012 break;
2013#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01002014 default:
2015 continue;
2016 }
2017
David Brownella6472532008-03-03 04:33:30 -08002018 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002019 __raw_writel(0xffffffff, wake_clear);
2020 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08002021 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002022 }
2023
2024 return 0;
2025}
2026
2027static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01002028 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01002029 .suspend = omap_gpio_suspend,
2030 .resume = omap_gpio_resume,
2031};
2032
2033static struct sys_device omap_gpio_device = {
2034 .id = 0,
2035 .cls = &omap_gpio_sysclass,
2036};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002037
2038#endif
2039
Tony Lindgren140455f2010-02-12 12:26:48 -08002040#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002041
2042static int workaround_enabled;
2043
2044void omap2_gpio_prepare_for_retention(void)
2045{
2046 int i, c = 0;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002047 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002048
Tero Kristoa118b5f2008-12-22 14:27:12 +02002049 if (cpu_is_omap34xx())
2050 min = 1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002051 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
2052 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
Tero Kristoa118b5f2008-12-22 14:27:12 +02002053 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002054 struct gpio_bank *bank = &gpio_bank[i];
2055 u32 l1, l2;
2056
2057 if (!(bank->enabled_non_wakeup_gpios))
2058 continue;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002059
2060 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2061 bank->saved_datain = __raw_readl(bank->base +
2062 OMAP24XX_GPIO_DATAIN);
2063 l1 = __raw_readl(bank->base +
2064 OMAP24XX_GPIO_FALLINGDETECT);
2065 l2 = __raw_readl(bank->base +
2066 OMAP24XX_GPIO_RISINGDETECT);
2067 }
2068
2069 if (cpu_is_omap44xx()) {
2070 bank->saved_datain = __raw_readl(bank->base +
2071 OMAP4_GPIO_DATAIN);
2072 l1 = __raw_readl(bank->base +
2073 OMAP4_GPIO_FALLINGDETECT);
2074 l2 = __raw_readl(bank->base +
2075 OMAP4_GPIO_RISINGDETECT);
2076 }
2077
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002078 bank->saved_fallingdetect = l1;
2079 bank->saved_risingdetect = l2;
2080 l1 &= ~bank->enabled_non_wakeup_gpios;
2081 l2 &= ~bank->enabled_non_wakeup_gpios;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002082
2083 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2084 __raw_writel(l1, bank->base +
2085 OMAP24XX_GPIO_FALLINGDETECT);
2086 __raw_writel(l2, bank->base +
2087 OMAP24XX_GPIO_RISINGDETECT);
2088 }
2089
2090 if (cpu_is_omap44xx()) {
2091 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
2092 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
2093 }
2094
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002095 c++;
2096 }
2097 if (!c) {
2098 workaround_enabled = 0;
2099 return;
2100 }
2101 workaround_enabled = 1;
2102}
2103
2104void omap2_gpio_resume_after_retention(void)
2105{
2106 int i;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002107 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002108
2109 if (!workaround_enabled)
2110 return;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002111 if (cpu_is_omap34xx())
2112 min = 1;
2113 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002114 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002115 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002116
2117 if (!(bank->enabled_non_wakeup_gpios))
2118 continue;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002119
2120 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2121 __raw_writel(bank->saved_fallingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002122 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002123 __raw_writel(bank->saved_risingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002124 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002125 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2126 }
2127
2128 if (cpu_is_omap44xx()) {
2129 __raw_writel(bank->saved_fallingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302130 bank->base + OMAP4_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002131 __raw_writel(bank->saved_risingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302132 bank->base + OMAP4_GPIO_RISINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002133 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
2134 }
2135
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002136 /* Check if any of the non-wakeup interrupt GPIOs have changed
2137 * state. If so, generate an IRQ by software. This is
2138 * horribly racy, but it's the best we can do to work around
2139 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002140 l ^= bank->saved_datain;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002141 l &= bank->enabled_non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002142
2143 /*
2144 * No need to generate IRQs for the rising edge for gpio IRQs
2145 * configured with falling edge only; and vice versa.
2146 */
2147 gen0 = l & bank->saved_fallingdetect;
2148 gen0 &= bank->saved_datain;
2149
2150 gen1 = l & bank->saved_risingdetect;
2151 gen1 &= ~(bank->saved_datain);
2152
2153 /* FIXME: Consider GPIO IRQs with level detections properly! */
2154 gen = l & (~(bank->saved_fallingdetect) &
2155 ~(bank->saved_risingdetect));
2156 /* Consider all GPIO IRQs needed to be updated */
2157 gen |= gen0 | gen1;
2158
2159 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002160 u32 old0, old1;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002161
Sergio Aguirref00d6492010-03-03 16:21:08 +00002162 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002163 old0 = __raw_readl(bank->base +
2164 OMAP24XX_GPIO_LEVELDETECT0);
2165 old1 = __raw_readl(bank->base +
2166 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002167 __raw_writel(old0 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002168 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002169 __raw_writel(old1 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002170 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002171 __raw_writel(old0, bank->base +
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002172 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002173 __raw_writel(old1, bank->base +
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002174 OMAP24XX_GPIO_LEVELDETECT1);
2175 }
2176
2177 if (cpu_is_omap44xx()) {
2178 old0 = __raw_readl(bank->base +
2179 OMAP4_GPIO_LEVELDETECT0);
2180 old1 = __raw_readl(bank->base +
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302181 OMAP4_GPIO_LEVELDETECT1);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002182 __raw_writel(old0 | l, bank->base +
2183 OMAP4_GPIO_LEVELDETECT0);
2184 __raw_writel(old1 | l, bank->base +
2185 OMAP4_GPIO_LEVELDETECT1);
2186 __raw_writel(old0, bank->base +
2187 OMAP4_GPIO_LEVELDETECT0);
2188 __raw_writel(old1, bank->base +
2189 OMAP4_GPIO_LEVELDETECT1);
2190 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002191 }
2192 }
2193
2194}
2195
Tony Lindgren92105bb2005-09-07 17:20:26 +01002196#endif
2197
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002198#ifdef CONFIG_ARCH_OMAP3
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302199/* save the registers of bank 2-6 */
2200void omap_gpio_save_context(void)
2201{
2202 int i;
2203
2204 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2205 for (i = 1; i < gpio_bank_count; i++) {
2206 struct gpio_bank *bank = &gpio_bank[i];
2207 gpio_context[i].sysconfig =
2208 __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG);
2209 gpio_context[i].irqenable1 =
2210 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
2211 gpio_context[i].irqenable2 =
2212 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
2213 gpio_context[i].wake_en =
2214 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
2215 gpio_context[i].ctrl =
2216 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
2217 gpio_context[i].oe =
2218 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
2219 gpio_context[i].leveldetect0 =
2220 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2221 gpio_context[i].leveldetect1 =
2222 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2223 gpio_context[i].risingdetect =
2224 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
2225 gpio_context[i].fallingdetect =
2226 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2227 gpio_context[i].dataout =
2228 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
2229 gpio_context[i].setwkuena =
2230 __raw_readl(bank->base + OMAP24XX_GPIO_SETWKUENA);
2231 gpio_context[i].setdataout =
2232 __raw_readl(bank->base + OMAP24XX_GPIO_SETDATAOUT);
2233 }
2234}
2235
2236/* restore the required registers of bank 2-6 */
2237void omap_gpio_restore_context(void)
2238{
2239 int i;
2240
2241 for (i = 1; i < gpio_bank_count; i++) {
2242 struct gpio_bank *bank = &gpio_bank[i];
2243 __raw_writel(gpio_context[i].sysconfig,
2244 bank->base + OMAP24XX_GPIO_SYSCONFIG);
2245 __raw_writel(gpio_context[i].irqenable1,
2246 bank->base + OMAP24XX_GPIO_IRQENABLE1);
2247 __raw_writel(gpio_context[i].irqenable2,
2248 bank->base + OMAP24XX_GPIO_IRQENABLE2);
2249 __raw_writel(gpio_context[i].wake_en,
2250 bank->base + OMAP24XX_GPIO_WAKE_EN);
2251 __raw_writel(gpio_context[i].ctrl,
2252 bank->base + OMAP24XX_GPIO_CTRL);
2253 __raw_writel(gpio_context[i].oe,
2254 bank->base + OMAP24XX_GPIO_OE);
2255 __raw_writel(gpio_context[i].leveldetect0,
2256 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2257 __raw_writel(gpio_context[i].leveldetect1,
2258 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2259 __raw_writel(gpio_context[i].risingdetect,
2260 bank->base + OMAP24XX_GPIO_RISINGDETECT);
2261 __raw_writel(gpio_context[i].fallingdetect,
2262 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2263 __raw_writel(gpio_context[i].dataout,
2264 bank->base + OMAP24XX_GPIO_DATAOUT);
2265 __raw_writel(gpio_context[i].setwkuena,
2266 bank->base + OMAP24XX_GPIO_SETWKUENA);
2267 __raw_writel(gpio_context[i].setdataout,
2268 bank->base + OMAP24XX_GPIO_SETDATAOUT);
2269 }
2270}
2271#endif
2272
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002273/*
2274 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002275 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002276 */
David Brownell277d58e2006-12-06 17:13:59 -08002277int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002278{
2279 if (!initialized)
2280 return _omap_gpio_init();
2281 else
2282 return 0;
2283}
2284
Tony Lindgren92105bb2005-09-07 17:20:26 +01002285static int __init omap_gpio_sysinit(void)
2286{
2287 int ret = 0;
2288
2289 if (!initialized)
2290 ret = _omap_gpio_init();
2291
David Brownell11a78b72006-12-06 17:14:11 -08002292 mpuio_init();
2293
Tony Lindgren140455f2010-02-12 12:26:48 -08002294#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002295 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002296 if (ret == 0) {
2297 ret = sysdev_class_register(&omap_gpio_sysclass);
2298 if (ret == 0)
2299 ret = sysdev_register(&omap_gpio_device);
2300 }
2301 }
2302#endif
2303
2304 return ret;
2305}
2306
Tony Lindgren92105bb2005-09-07 17:20:26 +01002307arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002308
2309
2310#ifdef CONFIG_DEBUG_FS
2311
2312#include <linux/debugfs.h>
2313#include <linux/seq_file.h>
2314
David Brownellb9772a22006-12-06 17:13:53 -08002315static int dbg_gpio_show(struct seq_file *s, void *unused)
2316{
2317 unsigned i, j, gpio;
2318
2319 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2320 struct gpio_bank *bank = gpio_bank + i;
2321 unsigned bankwidth = 16;
2322 u32 mask = 1;
2323
David Brownelle5c56ed2006-12-06 17:13:59 -08002324 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002325 gpio = OMAP_MPUIO(0);
Alistair Buxtonb718aa82009-09-23 18:56:19 +01002326 else if (cpu_class_is_omap2() || cpu_is_omap7xx())
David Brownellb9772a22006-12-06 17:13:53 -08002327 bankwidth = 32;
2328
2329 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2330 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002331 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002332
David Brownell52e31342008-03-03 12:43:23 -08002333 label = gpiochip_is_requested(&bank->chip, j);
2334 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002335 continue;
2336
2337 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002338 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002339 is_in = gpio_is_input(bank, mask);
2340
David Brownelle5c56ed2006-12-06 17:13:59 -08002341 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002342 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002343 else
David Brownell52e31342008-03-03 12:43:23 -08002344 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002345 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002346 label,
David Brownellb9772a22006-12-06 17:13:53 -08002347 is_in ? "in " : "out",
2348 value ? "hi" : "lo");
2349
David Brownell52e31342008-03-03 12:43:23 -08002350/* FIXME for at least omap2, show pullup/pulldown state */
2351
David Brownellb9772a22006-12-06 17:13:53 -08002352 irqstat = irq_desc[irq].status;
Tony Lindgren140455f2010-02-12 12:26:48 -08002353#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
David Brownellb9772a22006-12-06 17:13:53 -08002354 if (is_in && ((bank->suspend_wakeup & mask)
2355 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2356 char *trigger = NULL;
2357
2358 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2359 case IRQ_TYPE_EDGE_FALLING:
2360 trigger = "falling";
2361 break;
2362 case IRQ_TYPE_EDGE_RISING:
2363 trigger = "rising";
2364 break;
2365 case IRQ_TYPE_EDGE_BOTH:
2366 trigger = "bothedge";
2367 break;
2368 case IRQ_TYPE_LEVEL_LOW:
2369 trigger = "low";
2370 break;
2371 case IRQ_TYPE_LEVEL_HIGH:
2372 trigger = "high";
2373 break;
2374 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002375 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002376 break;
2377 }
David Brownell52e31342008-03-03 12:43:23 -08002378 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002379 irq, trigger,
2380 (bank->suspend_wakeup & mask)
2381 ? " wakeup" : "");
2382 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002383#endif
David Brownellb9772a22006-12-06 17:13:53 -08002384 seq_printf(s, "\n");
2385 }
2386
David Brownelle5c56ed2006-12-06 17:13:59 -08002387 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002388 seq_printf(s, "\n");
2389 gpio = 0;
2390 }
2391 }
2392 return 0;
2393}
2394
2395static int dbg_gpio_open(struct inode *inode, struct file *file)
2396{
David Brownelle5c56ed2006-12-06 17:13:59 -08002397 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002398}
2399
2400static const struct file_operations debug_fops = {
2401 .open = dbg_gpio_open,
2402 .read = seq_read,
2403 .llseek = seq_lseek,
2404 .release = single_release,
2405};
2406
2407static int __init omap_gpio_debuginit(void)
2408{
David Brownelle5c56ed2006-12-06 17:13:59 -08002409 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2410 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002411 return 0;
2412}
2413late_initcall(omap_gpio_debuginit);
2414#endif