blob: 6216f4f09e82ab33650dc718a25c55611559ea67 [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 {
727 if (trigger != 0)
728 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700729 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530730 else
731 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700732 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530733 }
Tero Kristoa118b5f2008-12-22 14:27:12 +0200734 }
735 /* This part needs to be executed always for OMAP34xx */
736 if (cpu_is_omap34xx() || (bank->non_wakeup_gpios & gpio_bit)) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800737 if (trigger != 0)
738 bank->enabled_non_wakeup_gpios |= gpio_bit;
739 else
740 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
741 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700742
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530743 if (cpu_is_omap44xx()) {
744 bank->level_mask =
745 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
746 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
747 } else {
748 bank->level_mask =
749 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
750 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
751 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100752}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800753#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100754
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800755#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800756/*
757 * This only applies to chips that can't do both rising and falling edge
758 * detection at once. For all other chips, this function is a noop.
759 */
760static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
761{
762 void __iomem *reg = bank->base;
763 u32 l = 0;
764
765 switch (bank->method) {
Cory Maccarrone4318f362010-01-08 10:29:04 -0800766 case METHOD_MPUIO:
767 reg += OMAP_MPUIO_GPIO_INT_EDGE;
768 break;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800769#ifdef CONFIG_ARCH_OMAP15XX
770 case METHOD_GPIO_1510:
771 reg += OMAP1510_GPIO_INT_CONTROL;
772 break;
773#endif
774#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
775 case METHOD_GPIO_7XX:
776 reg += OMAP7XX_GPIO_INT_CONTROL;
777 break;
778#endif
779 default:
780 return;
781 }
782
783 l = __raw_readl(reg);
784 if ((l >> gpio) & 1)
785 l &= ~(1 << gpio);
786 else
787 l |= 1 << gpio;
788
789 __raw_writel(l, reg);
790}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800791#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800792
Tony Lindgren92105bb2005-09-07 17:20:26 +0100793static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
794{
795 void __iomem *reg = bank->base;
796 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100797
798 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800799#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100800 case METHOD_MPUIO:
801 reg += OMAP_MPUIO_GPIO_INT_EDGE;
802 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000803 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800804 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100805 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100806 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100807 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100808 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100809 else
810 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100811 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800812#endif
813#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100814 case METHOD_GPIO_1510:
815 reg += OMAP1510_GPIO_INT_CONTROL;
816 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000817 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800818 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100819 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100820 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100821 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100822 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100823 else
824 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100825 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800826#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800827#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100828 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100829 if (gpio & 0x08)
830 reg += OMAP1610_GPIO_EDGE_CTRL2;
831 else
832 reg += OMAP1610_GPIO_EDGE_CTRL1;
833 gpio &= 0x07;
834 l = __raw_readl(reg);
835 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100836 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100837 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100838 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100839 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800840 if (trigger)
841 /* Enable wake-up during idle for dynamic tick */
842 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
843 else
844 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100845 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800846#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100847#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100848 case METHOD_GPIO_7XX:
849 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700850 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000851 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800852 bank->toggle_mask |= 1 << gpio;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700853 if (trigger & IRQ_TYPE_EDGE_RISING)
854 l |= 1 << gpio;
855 else if (trigger & IRQ_TYPE_EDGE_FALLING)
856 l &= ~(1 << gpio);
857 else
858 goto bad;
859 break;
860#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800861#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +0100862 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800863 case METHOD_GPIO_44XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800864 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100865 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800866#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100867 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100868 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100869 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100870 __raw_writel(l, reg);
871 return 0;
872bad:
873 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100874}
875
Tony Lindgren92105bb2005-09-07 17:20:26 +0100876static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100877{
878 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100879 unsigned gpio;
880 int retval;
David Brownella6472532008-03-03 04:33:30 -0800881 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100882
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800883 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100884 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
885 else
886 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100887
888 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100889 return -EINVAL;
890
David Brownelle5c56ed2006-12-06 17:13:59 -0800891 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100892 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800893
894 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800895 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800896 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100897 return -EINVAL;
898
David Brownell58781012006-12-06 17:14:10 -0800899 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800900 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100901 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800902 if (retval == 0) {
903 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
904 irq_desc[irq].status |= type;
905 }
David Brownella6472532008-03-03 04:33:30 -0800906 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800907
908 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
909 __set_irq_handler_unlocked(irq, handle_level_irq);
910 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
911 __set_irq_handler_unlocked(irq, handle_edge_irq);
912
Tony Lindgren92105bb2005-09-07 17:20:26 +0100913 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100914}
915
916static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
917{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100918 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100919
920 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800921#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100922 case METHOD_MPUIO:
923 /* MPUIO irqstatus is reset by reading the status register,
924 * so do nothing here */
925 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800926#endif
927#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100928 case METHOD_GPIO_1510:
929 reg += OMAP1510_GPIO_INT_STATUS;
930 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800931#endif
932#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100933 case METHOD_GPIO_1610:
934 reg += OMAP1610_GPIO_IRQSTATUS1;
935 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800936#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100937#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100938 case METHOD_GPIO_7XX:
939 reg += OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700940 break;
941#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800942#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100943 case METHOD_GPIO_24XX:
944 reg += OMAP24XX_GPIO_IRQSTATUS1;
945 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800946#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530947#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800948 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530949 reg += OMAP4_GPIO_IRQSTATUS0;
950 break;
951#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100952 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800953 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100954 return;
955 }
956 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300957
958 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Tony Lindgren3f1686a2010-02-15 09:27:25 -0800959 if (cpu_is_omap24xx() || cpu_is_omap34xx())
960 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
961 else if (cpu_is_omap44xx())
962 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
963
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530964 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700965 __raw_writel(gpio_mask, reg);
966
967 /* Flush posted write for the irq status to avoid spurious interrupts */
968 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530969 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100970}
971
972static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
973{
974 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
975}
976
Imre Deakea6dedd2006-06-26 16:16:00 -0700977static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
978{
979 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700980 int inv = 0;
981 u32 l;
982 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700983
984 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800985#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700986 case METHOD_MPUIO:
987 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700988 mask = 0xffff;
989 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700990 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800991#endif
992#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700993 case METHOD_GPIO_1510:
994 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700995 mask = 0xffff;
996 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700997 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800998#endif
999#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -07001000 case METHOD_GPIO_1610:
1001 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001002 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001003 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001004#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001005#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001006 case METHOD_GPIO_7XX:
1007 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001008 mask = 0xffffffff;
1009 inv = 1;
1010 break;
1011#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001012#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Imre Deakea6dedd2006-06-26 16:16:00 -07001013 case METHOD_GPIO_24XX:
1014 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -07001015 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -07001016 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001017#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301018#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001019 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301020 reg += OMAP4_GPIO_IRQSTATUSSET0;
1021 mask = 0xffffffff;
1022 break;
1023#endif
Imre Deakea6dedd2006-06-26 16:16:00 -07001024 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001025 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -07001026 return 0;
1027 }
1028
Imre Deak99c47702006-06-26 16:16:07 -07001029 l = __raw_readl(reg);
1030 if (inv)
1031 l = ~l;
1032 l &= mask;
1033 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -07001034}
1035
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001036static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
1037{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001038 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001039 u32 l;
1040
1041 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001042#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001043 case METHOD_MPUIO:
1044 reg += OMAP_MPUIO_GPIO_MASKIT;
1045 l = __raw_readl(reg);
1046 if (enable)
1047 l &= ~(gpio_mask);
1048 else
1049 l |= gpio_mask;
1050 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001051#endif
1052#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001053 case METHOD_GPIO_1510:
1054 reg += OMAP1510_GPIO_INT_MASK;
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_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001063 case METHOD_GPIO_1610:
1064 if (enable)
1065 reg += OMAP1610_GPIO_SET_IRQENABLE1;
1066 else
1067 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
1068 l = gpio_mask;
1069 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001070#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001071#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001072 case METHOD_GPIO_7XX:
1073 reg += OMAP7XX_GPIO_INT_MASK;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001074 l = __raw_readl(reg);
1075 if (enable)
1076 l &= ~(gpio_mask);
1077 else
1078 l |= gpio_mask;
1079 break;
1080#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001081#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001082 case METHOD_GPIO_24XX:
1083 if (enable)
1084 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1085 else
1086 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1087 l = gpio_mask;
1088 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001089#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301090#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001091 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301092 if (enable)
1093 reg += OMAP4_GPIO_IRQSTATUSSET0;
1094 else
1095 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1096 l = gpio_mask;
1097 break;
1098#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001099 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001100 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001101 return;
1102 }
1103 __raw_writel(l, reg);
1104}
1105
1106static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1107{
1108 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1109}
1110
Tony Lindgren92105bb2005-09-07 17:20:26 +01001111/*
1112 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1113 * 1510 does not seem to have a wake-up register. If JTAG is connected
1114 * to the target, system will wake up always on GPIO events. While
1115 * system is running all registered GPIO interrupts need to have wake-up
1116 * enabled. When system is suspended, only selected GPIO interrupts need
1117 * to have wake-up enabled.
1118 */
1119static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1120{
Tony Lindgren4cc64202010-01-08 10:29:05 -08001121 unsigned long uninitialized_var(flags);
David Brownella6472532008-03-03 04:33:30 -08001122
Tony Lindgren92105bb2005-09-07 17:20:26 +01001123 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001124#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001125 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001126 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001127 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001128 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001129 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001130 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001131 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001132 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001133 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001134#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001135#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001136 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001137 case METHOD_GPIO_44XX:
David Brownell11a78b72006-12-06 17:14:11 -08001138 if (bank->non_wakeup_gpios & (1 << gpio)) {
1139 printk(KERN_ERR "Unable to modify wakeup on "
1140 "non-wakeup GPIO%d\n",
1141 (bank - gpio_bank) * 32 + gpio);
1142 return -EINVAL;
1143 }
David Brownella6472532008-03-03 04:33:30 -08001144 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001145 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001146 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001147 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001148 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001149 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001150 return 0;
1151#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001152 default:
1153 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1154 bank->method);
1155 return -EINVAL;
1156 }
1157}
1158
Tony Lindgren4196dd62006-09-25 12:41:38 +03001159static void _reset_gpio(struct gpio_bank *bank, int gpio)
1160{
1161 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1162 _set_gpio_irqenable(bank, gpio, 0);
1163 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001164 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001165}
1166
Tony Lindgren92105bb2005-09-07 17:20:26 +01001167/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1168static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1169{
1170 unsigned int gpio = irq - IH_GPIO_BASE;
1171 struct gpio_bank *bank;
1172 int retval;
1173
1174 if (check_gpio(gpio) < 0)
1175 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001176 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001177 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001178
1179 return retval;
1180}
1181
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001182static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001183{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001184 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001185 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001186
David Brownella6472532008-03-03 04:33:30 -08001187 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001188
Tony Lindgren4196dd62006-09-25 12:41:38 +03001189 /* Set trigger to none. You need to enable the desired trigger with
1190 * request_irq() or set_irq_type().
1191 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001192 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001193
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001194#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001195 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001196 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001197
Tony Lindgren92105bb2005-09-07 17:20:26 +01001198 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001199 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001200 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001201 }
1202#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001203 if (!cpu_class_is_omap1()) {
1204 if (!bank->mod_usage) {
1205 u32 ctrl;
1206 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1207 ctrl &= 0xFFFFFFFE;
1208 /* Module is enabled, clocks are not gated */
1209 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1210 }
1211 bank->mod_usage |= 1 << offset;
1212 }
David Brownella6472532008-03-03 04:33:30 -08001213 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001214
1215 return 0;
1216}
1217
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001218static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001219{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001220 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001221 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001222
David Brownella6472532008-03-03 04:33:30 -08001223 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001224#ifdef CONFIG_ARCH_OMAP16XX
1225 if (bank->method == METHOD_GPIO_1610) {
1226 /* Disable wake-up during idle for dynamic tick */
1227 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001228 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001229 }
1230#endif
Tony Lindgren140455f2010-02-12 12:26:48 -08001231#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001232 if ((bank->method == METHOD_GPIO_24XX) ||
1233 (bank->method == METHOD_GPIO_44XX)) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001234 /* Disable wake-up during idle for dynamic tick */
1235 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001236 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001237 }
1238#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001239 if (!cpu_class_is_omap1()) {
1240 bank->mod_usage &= ~(1 << offset);
1241 if (!bank->mod_usage) {
1242 u32 ctrl;
1243 ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1244 /* Module is disabled, clocks are gated */
1245 ctrl |= 1;
1246 __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1247 }
1248 }
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001249 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001250 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001251}
1252
1253/*
1254 * We need to unmask the GPIO bank interrupt as soon as possible to
1255 * avoid missing GPIO interrupts for other lines in the bank.
1256 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1257 * in the bank to avoid missing nested interrupts for a GPIO line.
1258 * If we wait to unmask individual GPIO lines in the bank after the
1259 * line's interrupt handler has been run, we may miss some nested
1260 * interrupts.
1261 */
Russell King10dd5ce2006-11-23 11:41:32 +00001262static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001263{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001264 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001265 u32 isr;
Cory Maccarrone4318f362010-01-08 10:29:04 -08001266 unsigned int gpio_irq, gpio_index;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001267 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001268 u32 retrigger = 0;
1269 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001270
1271 desc->chip->ack(irq);
1272
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001273 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001274#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001275 if (bank->method == METHOD_MPUIO)
1276 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001277#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001278#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001279 if (bank->method == METHOD_GPIO_1510)
1280 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1281#endif
1282#if defined(CONFIG_ARCH_OMAP16XX)
1283 if (bank->method == METHOD_GPIO_1610)
1284 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1285#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001286#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001287 if (bank->method == METHOD_GPIO_7XX)
1288 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001289#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001290#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001291 if (bank->method == METHOD_GPIO_24XX)
1292 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1293#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301294#if defined(CONFIG_ARCH_OMAP4)
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001295 if (bank->method == METHOD_GPIO_44XX)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301296 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1297#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001298 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001299 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001300 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001301
Imre Deakea6dedd2006-06-26 16:16:00 -07001302 enabled = _get_gpio_irqbank_mask(bank);
1303 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001304
1305 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1306 isr &= 0x0000ffff;
1307
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001308 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001309 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001310 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001311
1312 /* clear edge sensitive interrupts before handler(s) are
1313 called so that we don't miss any interrupt occurred while
1314 executing them */
1315 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1316 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1317 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1318
1319 /* if there is only edge sensitive GPIO pin interrupts
1320 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001321 if (!level_mask && !unmasked) {
1322 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001323 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001324 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001325
Imre Deakea6dedd2006-06-26 16:16:00 -07001326 isr |= retrigger;
1327 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001328 if (!isr)
1329 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001330
Tony Lindgren92105bb2005-09-07 17:20:26 +01001331 gpio_irq = bank->virtual_irq_start;
1332 for (; isr != 0; isr >>= 1, gpio_irq++) {
Cory Maccarrone4318f362010-01-08 10:29:04 -08001333 gpio_index = get_gpio_index(irq_to_gpio(gpio_irq));
1334
Tony Lindgren92105bb2005-09-07 17:20:26 +01001335 if (!(isr & 1))
1336 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001337
Cory Maccarrone4318f362010-01-08 10:29:04 -08001338#ifdef CONFIG_ARCH_OMAP1
1339 /*
1340 * Some chips can't respond to both rising and falling
1341 * at the same time. If this irq was requested with
1342 * both flags, we need to flip the ICR data for the IRQ
1343 * to respond to the IRQ for the opposite direction.
1344 * This will be indicated in the bank toggle_mask.
1345 */
1346 if (bank->toggle_mask & (1 << gpio_index))
1347 _toggle_gpio_edge_triggering(bank, gpio_index);
1348#endif
1349
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001350 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001351 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001352 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001353 /* if bank has any level sensitive GPIO pin interrupt
1354 configured, we must unmask the bank interrupt only after
1355 handler(s) are executed in order to avoid spurious bank
1356 interrupt */
1357 if (!unmasked)
1358 desc->chip->unmask(irq);
1359
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001360}
1361
Tony Lindgren4196dd62006-09-25 12:41:38 +03001362static void gpio_irq_shutdown(unsigned int irq)
1363{
1364 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001365 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001366
1367 _reset_gpio(bank, gpio);
1368}
1369
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001370static void gpio_ack_irq(unsigned int irq)
1371{
1372 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001373 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001374
1375 _clear_gpio_irqstatus(bank, gpio);
1376}
1377
1378static void gpio_mask_irq(unsigned int irq)
1379{
1380 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001381 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001382
1383 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001384 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001385}
1386
1387static void gpio_unmask_irq(unsigned int irq)
1388{
1389 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001390 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001391 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001392 struct irq_desc *desc = irq_to_desc(irq);
1393 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1394
1395 if (trigger)
1396 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001397
1398 /* For level-triggered GPIOs, the clearing must be done after
1399 * the HW source is cleared, thus after the handler has run */
1400 if (bank->level_mask & irq_mask) {
1401 _set_gpio_irqenable(bank, gpio, 0);
1402 _clear_gpio_irqstatus(bank, gpio);
1403 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001404
Kevin Hilman4de8c752008-01-16 21:56:14 -08001405 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001406}
1407
David Brownelle5c56ed2006-12-06 17:13:59 -08001408static struct irq_chip gpio_irq_chip = {
1409 .name = "GPIO",
1410 .shutdown = gpio_irq_shutdown,
1411 .ack = gpio_ack_irq,
1412 .mask = gpio_mask_irq,
1413 .unmask = gpio_unmask_irq,
1414 .set_type = gpio_irq_type,
1415 .set_wake = gpio_wake_enable,
1416};
1417
1418/*---------------------------------------------------------------------*/
1419
1420#ifdef CONFIG_ARCH_OMAP1
1421
1422/* MPUIO uses the always-on 32k clock */
1423
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001424static void mpuio_ack_irq(unsigned int irq)
1425{
1426 /* The ISR is reset automatically, so do nothing here. */
1427}
1428
1429static void mpuio_mask_irq(unsigned int irq)
1430{
1431 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001432 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001433
1434 _set_gpio_irqenable(bank, gpio, 0);
1435}
1436
1437static void mpuio_unmask_irq(unsigned int irq)
1438{
1439 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001440 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001441
1442 _set_gpio_irqenable(bank, gpio, 1);
1443}
1444
David Brownelle5c56ed2006-12-06 17:13:59 -08001445static struct irq_chip mpuio_irq_chip = {
1446 .name = "MPUIO",
1447 .ack = mpuio_ack_irq,
1448 .mask = mpuio_mask_irq,
1449 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001450 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001451#ifdef CONFIG_ARCH_OMAP16XX
1452 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1453 .set_wake = gpio_wake_enable,
1454#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001455};
1456
David Brownelle5c56ed2006-12-06 17:13:59 -08001457
1458#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1459
David Brownell11a78b72006-12-06 17:14:11 -08001460
1461#ifdef CONFIG_ARCH_OMAP16XX
1462
1463#include <linux/platform_device.h>
1464
Magnus Damm79ee0312009-07-08 13:22:04 +02001465static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001466{
Magnus Damm79ee0312009-07-08 13:22:04 +02001467 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001468 struct gpio_bank *bank = platform_get_drvdata(pdev);
1469 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001470 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001471
David Brownella6472532008-03-03 04:33:30 -08001472 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001473 bank->saved_wakeup = __raw_readl(mask_reg);
1474 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001475 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001476
1477 return 0;
1478}
1479
Magnus Damm79ee0312009-07-08 13:22:04 +02001480static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001481{
Magnus Damm79ee0312009-07-08 13:22:04 +02001482 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001483 struct gpio_bank *bank = platform_get_drvdata(pdev);
1484 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001485 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001486
David Brownella6472532008-03-03 04:33:30 -08001487 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001488 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001489 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001490
1491 return 0;
1492}
1493
Alexey Dobriyan47145212009-12-14 18:00:08 -08001494static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +02001495 .suspend_noirq = omap_mpuio_suspend_noirq,
1496 .resume_noirq = omap_mpuio_resume_noirq,
1497};
1498
David Brownell11a78b72006-12-06 17:14:11 -08001499/* use platform_driver for this, now that there's no longer any
1500 * point to sys_device (other than not disturbing old code).
1501 */
1502static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001503 .driver = {
1504 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001505 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001506 },
1507};
1508
1509static struct platform_device omap_mpuio_device = {
1510 .name = "mpuio",
1511 .id = -1,
1512 .dev = {
1513 .driver = &omap_mpuio_driver.driver,
1514 }
1515 /* could list the /proc/iomem resources */
1516};
1517
1518static inline void mpuio_init(void)
1519{
David Brownellfcf126d2007-04-02 12:46:47 -07001520 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1521
David Brownell11a78b72006-12-06 17:14:11 -08001522 if (platform_driver_register(&omap_mpuio_driver) == 0)
1523 (void) platform_device_register(&omap_mpuio_device);
1524}
1525
1526#else
1527static inline void mpuio_init(void) {}
1528#endif /* 16xx */
1529
David Brownelle5c56ed2006-12-06 17:13:59 -08001530#else
1531
1532extern struct irq_chip mpuio_irq_chip;
1533
1534#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001535static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001536
1537#endif
1538
1539/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001540
David Brownell52e31342008-03-03 12:43:23 -08001541/* REVISIT these are stupid implementations! replace by ones that
1542 * don't switch on METHOD_* and which mostly avoid spinlocks
1543 */
1544
1545static int gpio_input(struct gpio_chip *chip, unsigned offset)
1546{
1547 struct gpio_bank *bank;
1548 unsigned long flags;
1549
1550 bank = container_of(chip, struct gpio_bank, chip);
1551 spin_lock_irqsave(&bank->lock, flags);
1552 _set_gpio_direction(bank, offset, 1);
1553 spin_unlock_irqrestore(&bank->lock, flags);
1554 return 0;
1555}
1556
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001557static int gpio_is_input(struct gpio_bank *bank, int mask)
1558{
1559 void __iomem *reg = bank->base;
1560
1561 switch (bank->method) {
1562 case METHOD_MPUIO:
1563 reg += OMAP_MPUIO_IO_CNTL;
1564 break;
1565 case METHOD_GPIO_1510:
1566 reg += OMAP1510_GPIO_DIR_CONTROL;
1567 break;
1568 case METHOD_GPIO_1610:
1569 reg += OMAP1610_GPIO_DIRECTION;
1570 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001571 case METHOD_GPIO_7XX:
1572 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001573 break;
1574 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001575 case METHOD_GPIO_44XX:
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001576 reg += OMAP24XX_GPIO_OE;
1577 break;
1578 }
1579 return __raw_readl(reg) & mask;
1580}
1581
David Brownell52e31342008-03-03 12:43:23 -08001582static int gpio_get(struct gpio_chip *chip, unsigned offset)
1583{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001584 struct gpio_bank *bank;
1585 void __iomem *reg;
1586 int gpio;
1587 u32 mask;
1588
1589 gpio = chip->base + offset;
1590 bank = get_gpio_bank(gpio);
1591 reg = bank->base;
1592 mask = 1 << get_gpio_index(gpio);
1593
1594 if (gpio_is_input(bank, mask))
1595 return _get_gpio_datain(bank, gpio);
1596 else
1597 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001598}
1599
1600static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1601{
1602 struct gpio_bank *bank;
1603 unsigned long flags;
1604
1605 bank = container_of(chip, struct gpio_bank, chip);
1606 spin_lock_irqsave(&bank->lock, flags);
1607 _set_gpio_dataout(bank, offset, value);
1608 _set_gpio_direction(bank, offset, 0);
1609 spin_unlock_irqrestore(&bank->lock, flags);
1610 return 0;
1611}
1612
1613static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1614{
1615 struct gpio_bank *bank;
1616 unsigned long flags;
1617
1618 bank = container_of(chip, struct gpio_bank, chip);
1619 spin_lock_irqsave(&bank->lock, flags);
1620 _set_gpio_dataout(bank, offset, value);
1621 spin_unlock_irqrestore(&bank->lock, flags);
1622}
1623
David Brownella007b702008-12-10 17:35:25 -08001624static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1625{
1626 struct gpio_bank *bank;
1627
1628 bank = container_of(chip, struct gpio_bank, chip);
1629 return bank->virtual_irq_start + offset;
1630}
1631
David Brownell52e31342008-03-03 12:43:23 -08001632/*---------------------------------------------------------------------*/
1633
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001634static int initialized;
Tony Lindgren56213ca2010-02-12 12:26:46 -08001635#if defined(CONFIG_ARCH_OMAP1) || defined(CONFIG_ARCH_OMAP2)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001636static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001637#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001638
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001639#if defined(CONFIG_ARCH_OMAP2)
1640static struct clk * gpio_fck;
1641#endif
1642
1643#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001644static struct clk * gpio5_ick;
1645static struct clk * gpio5_fck;
1646#endif
1647
Santosh Shilimkar44169072009-05-28 14:16:04 -07001648#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001649static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1650#endif
1651
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001652static void __init omap_gpio_show_rev(void)
1653{
1654 u32 rev;
1655
1656 if (cpu_is_omap16xx())
1657 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1658 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1659 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1660 else if (cpu_is_omap44xx())
1661 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1662 else
1663 return;
1664
1665 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1666 (rev >> 4) & 0x0f, rev & 0x0f);
1667}
1668
David Brownell8ba55c52008-02-26 11:10:50 -08001669/* This lock class tells lockdep that GPIO irqs are in a different
1670 * category than their parents, so it won't report false recursion.
1671 */
1672static struct lock_class_key gpio_lock_class;
1673
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001674static int __init _omap_gpio_init(void)
1675{
1676 int i;
David Brownell52e31342008-03-03 12:43:23 -08001677 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001678 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001679 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001680 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001681
1682 initialized = 1;
1683
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001684#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001685 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001686 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1687 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001688 printk("Could not get arm_gpio_ck\n");
1689 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001690 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001691 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001692#endif
1693#if defined(CONFIG_ARCH_OMAP2)
1694 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001695 gpio_ick = clk_get(NULL, "gpios_ick");
1696 if (IS_ERR(gpio_ick))
1697 printk("Could not get gpios_ick\n");
1698 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001699 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001700 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001701 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001702 printk("Could not get gpios_fck\n");
1703 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001704 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001705
1706 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001707 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001708 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001709#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001710 if (cpu_is_omap2430()) {
1711 gpio5_ick = clk_get(NULL, "gpio5_ick");
1712 if (IS_ERR(gpio5_ick))
1713 printk("Could not get gpio5_ick\n");
1714 else
1715 clk_enable(gpio5_ick);
1716 gpio5_fck = clk_get(NULL, "gpio5_fck");
1717 if (IS_ERR(gpio5_fck))
1718 printk("Could not get gpio5_fck\n");
1719 else
1720 clk_enable(gpio5_fck);
1721 }
1722#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001723 }
1724#endif
1725
Santosh Shilimkar44169072009-05-28 14:16:04 -07001726#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1727 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001728 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1729 sprintf(clk_name, "gpio%d_ick", i + 1);
1730 gpio_iclks[i] = clk_get(NULL, clk_name);
1731 if (IS_ERR(gpio_iclks[i]))
1732 printk(KERN_ERR "Could not get %s\n", clk_name);
1733 else
1734 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001735 }
1736 }
1737#endif
1738
Tony Lindgren92105bb2005-09-07 17:20:26 +01001739
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001740#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001741 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001742 gpio_bank_count = 2;
1743 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001744 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001745 }
1746#endif
1747#if defined(CONFIG_ARCH_OMAP16XX)
1748 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001749 gpio_bank_count = 5;
1750 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001751 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001752 }
1753#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001754#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1755 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001756 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001757 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001758 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001759 }
1760#endif
Tony Lindgren088ef952010-02-12 12:26:47 -08001761#ifdef CONFIG_ARCH_OMAP2
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001762 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001763 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001764 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001765 }
1766 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001767 gpio_bank_count = 5;
1768 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001769 }
1770#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001771#ifdef CONFIG_ARCH_OMAP3
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001772 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001773 gpio_bank_count = OMAP34XX_NR_GPIOS;
1774 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001775 }
1776#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001777#ifdef CONFIG_ARCH_OMAP4
1778 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001779 gpio_bank_count = OMAP34XX_NR_GPIOS;
1780 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001781 }
1782#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001783 for (i = 0; i < gpio_bank_count; i++) {
1784 int j, gpio_count = 16;
1785
1786 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001787 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001788
1789 /* Static mapping, never released */
1790 bank->base = ioremap(bank->pbase, bank_size);
1791 if (!bank->base) {
1792 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1793 continue;
1794 }
1795
David Brownelle5c56ed2006-12-06 17:13:59 -08001796 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001797 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001798 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001799 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1800 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1801 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001802 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001803 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1804 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001805 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001806 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001807 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1808 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1809 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001810
Alistair Buxton7c006922009-09-22 10:02:58 +01001811 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001812 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001813
Tony Lindgren140455f2010-02-12 12:26:48 -08001814#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001815 if ((bank->method == METHOD_GPIO_24XX) ||
1816 (bank->method == METHOD_GPIO_44XX)) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001817 static const u32 non_wakeup_gpios[] = {
1818 0xe203ffc0, 0x08700040
1819 };
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001820
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001821 if (cpu_is_omap44xx()) {
1822 __raw_writel(0xffffffff, bank->base +
1823 OMAP4_GPIO_IRQSTATUSCLR0);
1824 __raw_writew(0x0015, bank->base +
1825 OMAP4_GPIO_SYSCONFIG);
1826 __raw_writel(0x00000000, bank->base +
1827 OMAP4_GPIO_DEBOUNCENABLE);
1828 /*
1829 * Initialize interface clock ungated,
1830 * module enabled
1831 */
1832 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1833 } else {
1834 __raw_writel(0x00000000, bank->base +
1835 OMAP24XX_GPIO_IRQENABLE1);
1836 __raw_writel(0xffffffff, bank->base +
1837 OMAP24XX_GPIO_IRQSTATUS1);
1838 __raw_writew(0x0015, bank->base +
1839 OMAP24XX_GPIO_SYSCONFIG);
1840 __raw_writel(0x00000000, bank->base +
1841 OMAP24XX_GPIO_DEBOUNCE_EN);
1842
1843 /*
1844 * Initialize interface clock ungated,
1845 * module enabled
1846 */
1847 __raw_writel(0, bank->base +
1848 OMAP24XX_GPIO_CTRL);
1849 }
Tero Kristoa118b5f2008-12-22 14:27:12 +02001850 if (cpu_is_omap24xx() &&
1851 i < ARRAY_SIZE(non_wakeup_gpios))
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001852 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001853 gpio_count = 32;
1854 }
1855#endif
Charulatha V058af1e2009-11-22 10:11:25 -08001856
1857 bank->mod_usage = 0;
David Brownell52e31342008-03-03 12:43:23 -08001858 /* REVISIT eventually switch from OMAP-specific gpio structs
1859 * over to the generic ones
1860 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001861 bank->chip.request = omap_gpio_request;
1862 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001863 bank->chip.direction_input = gpio_input;
1864 bank->chip.get = gpio_get;
1865 bank->chip.direction_output = gpio_output;
1866 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001867 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001868 if (bank_is_mpuio(bank)) {
1869 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001870#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001871 bank->chip.dev = &omap_mpuio_device.dev;
1872#endif
David Brownell52e31342008-03-03 12:43:23 -08001873 bank->chip.base = OMAP_MPUIO(0);
1874 } else {
1875 bank->chip.label = "gpio";
1876 bank->chip.base = gpio;
1877 gpio += gpio_count;
1878 }
1879 bank->chip.ngpio = gpio_count;
1880
1881 gpiochip_add(&bank->chip);
1882
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001883 for (j = bank->virtual_irq_start;
1884 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001885 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001886 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001887 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001888 set_irq_chip(j, &mpuio_irq_chip);
1889 else
1890 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001891 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001892 set_irq_flags(j, IRQF_VALID);
1893 }
1894 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1895 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001896
Santosh Shilimkar44169072009-05-28 14:16:04 -07001897 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001898 sprintf(clk_name, "gpio%d_dbck", i + 1);
1899 bank->dbck = clk_get(NULL, clk_name);
1900 if (IS_ERR(bank->dbck))
1901 printk(KERN_ERR "Could not get %s\n", clk_name);
1902 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001903 }
1904
1905 /* Enable system clock for GPIO module.
1906 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001907 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001908 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1909
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001910 /* Enable autoidle for the OCP interface */
1911 if (cpu_is_omap24xx())
1912 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001913 if (cpu_is_omap34xx())
1914 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001915
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001916 omap_gpio_show_rev();
1917
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001918 return 0;
1919}
1920
Tony Lindgren140455f2010-02-12 12:26:48 -08001921#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001922static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1923{
1924 int i;
1925
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001926 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001927 return 0;
1928
1929 for (i = 0; i < gpio_bank_count; i++) {
1930 struct gpio_bank *bank = &gpio_bank[i];
1931 void __iomem *wake_status;
1932 void __iomem *wake_clear;
1933 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001934 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001935
1936 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001937#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001938 case METHOD_GPIO_1610:
1939 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1940 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1941 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1942 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001943#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001944#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001945 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001946 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001947 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1948 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1949 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001950#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301951#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001952 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301953 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1954 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1955 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1956 break;
1957#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001958 default:
1959 continue;
1960 }
1961
David Brownella6472532008-03-03 04:33:30 -08001962 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001963 bank->saved_wakeup = __raw_readl(wake_status);
1964 __raw_writel(0xffffffff, wake_clear);
1965 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001966 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001967 }
1968
1969 return 0;
1970}
1971
1972static int omap_gpio_resume(struct sys_device *dev)
1973{
1974 int i;
1975
Tero Kristo723fdb72008-11-26 14:35:16 -08001976 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001977 return 0;
1978
1979 for (i = 0; i < gpio_bank_count; i++) {
1980 struct gpio_bank *bank = &gpio_bank[i];
1981 void __iomem *wake_clear;
1982 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001983 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001984
1985 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001986#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001987 case METHOD_GPIO_1610:
1988 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1989 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1990 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001991#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001992#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001993 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001994 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1995 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001996 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001997#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301998#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a2010-02-15 09:27:25 -08001999 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302000 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
2001 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
2002 break;
2003#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01002004 default:
2005 continue;
2006 }
2007
David Brownella6472532008-03-03 04:33:30 -08002008 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002009 __raw_writel(0xffffffff, wake_clear);
2010 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08002011 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01002012 }
2013
2014 return 0;
2015}
2016
2017static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01002018 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01002019 .suspend = omap_gpio_suspend,
2020 .resume = omap_gpio_resume,
2021};
2022
2023static struct sys_device omap_gpio_device = {
2024 .id = 0,
2025 .cls = &omap_gpio_sysclass,
2026};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002027
2028#endif
2029
Tony Lindgren140455f2010-02-12 12:26:48 -08002030#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002031
2032static int workaround_enabled;
2033
2034void omap2_gpio_prepare_for_retention(void)
2035{
2036 int i, c = 0;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002037 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002038
Tero Kristoa118b5f2008-12-22 14:27:12 +02002039 if (cpu_is_omap34xx())
2040 min = 1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002041 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
2042 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
Tero Kristoa118b5f2008-12-22 14:27:12 +02002043 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002044 struct gpio_bank *bank = &gpio_bank[i];
2045 u32 l1, l2;
2046
2047 if (!(bank->enabled_non_wakeup_gpios))
2048 continue;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002049
2050 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2051 bank->saved_datain = __raw_readl(bank->base +
2052 OMAP24XX_GPIO_DATAIN);
2053 l1 = __raw_readl(bank->base +
2054 OMAP24XX_GPIO_FALLINGDETECT);
2055 l2 = __raw_readl(bank->base +
2056 OMAP24XX_GPIO_RISINGDETECT);
2057 }
2058
2059 if (cpu_is_omap44xx()) {
2060 bank->saved_datain = __raw_readl(bank->base +
2061 OMAP4_GPIO_DATAIN);
2062 l1 = __raw_readl(bank->base +
2063 OMAP4_GPIO_FALLINGDETECT);
2064 l2 = __raw_readl(bank->base +
2065 OMAP4_GPIO_RISINGDETECT);
2066 }
2067
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002068 bank->saved_fallingdetect = l1;
2069 bank->saved_risingdetect = l2;
2070 l1 &= ~bank->enabled_non_wakeup_gpios;
2071 l2 &= ~bank->enabled_non_wakeup_gpios;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002072
2073 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2074 __raw_writel(l1, bank->base +
2075 OMAP24XX_GPIO_FALLINGDETECT);
2076 __raw_writel(l2, bank->base +
2077 OMAP24XX_GPIO_RISINGDETECT);
2078 }
2079
2080 if (cpu_is_omap44xx()) {
2081 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
2082 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
2083 }
2084
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002085 c++;
2086 }
2087 if (!c) {
2088 workaround_enabled = 0;
2089 return;
2090 }
2091 workaround_enabled = 1;
2092}
2093
2094void omap2_gpio_resume_after_retention(void)
2095{
2096 int i;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002097 int min = 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002098
2099 if (!workaround_enabled)
2100 return;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002101 if (cpu_is_omap34xx())
2102 min = 1;
2103 for (i = min; i < gpio_bank_count; i++) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002104 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002105 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002106
2107 if (!(bank->enabled_non_wakeup_gpios))
2108 continue;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002109
2110 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
2111 __raw_writel(bank->saved_fallingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002112 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002113 __raw_writel(bank->saved_risingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002114 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002115 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
2116 }
2117
2118 if (cpu_is_omap44xx()) {
2119 __raw_writel(bank->saved_fallingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302120 bank->base + OMAP4_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002121 __raw_writel(bank->saved_risingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302122 bank->base + OMAP4_GPIO_RISINGDETECT);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002123 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
2124 }
2125
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002126 /* Check if any of the non-wakeup interrupt GPIOs have changed
2127 * state. If so, generate an IRQ by software. This is
2128 * horribly racy, but it's the best we can do to work around
2129 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002130 l ^= bank->saved_datain;
Tero Kristoa118b5f2008-12-22 14:27:12 +02002131 l &= bank->enabled_non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002132
2133 /*
2134 * No need to generate IRQs for the rising edge for gpio IRQs
2135 * configured with falling edge only; and vice versa.
2136 */
2137 gen0 = l & bank->saved_fallingdetect;
2138 gen0 &= bank->saved_datain;
2139
2140 gen1 = l & bank->saved_risingdetect;
2141 gen1 &= ~(bank->saved_datain);
2142
2143 /* FIXME: Consider GPIO IRQs with level detections properly! */
2144 gen = l & (~(bank->saved_fallingdetect) &
2145 ~(bank->saved_risingdetect));
2146 /* Consider all GPIO IRQs needed to be updated */
2147 gen |= gen0 | gen1;
2148
2149 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002150 u32 old0, old1;
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002151
Sergio Aguirref00d6492010-03-03 16:21:08 +00002152 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002153 old0 = __raw_readl(bank->base +
2154 OMAP24XX_GPIO_LEVELDETECT0);
2155 old1 = __raw_readl(bank->base +
2156 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002157 __raw_writel(old0 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002158 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002159 __raw_writel(old1 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002160 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002161 __raw_writel(old0, bank->base +
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002162 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00002163 __raw_writel(old1, bank->base +
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002164 OMAP24XX_GPIO_LEVELDETECT1);
2165 }
2166
2167 if (cpu_is_omap44xx()) {
2168 old0 = __raw_readl(bank->base +
2169 OMAP4_GPIO_LEVELDETECT0);
2170 old1 = __raw_readl(bank->base +
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302171 OMAP4_GPIO_LEVELDETECT1);
Tony Lindgren3f1686a2010-02-15 09:27:25 -08002172 __raw_writel(old0 | l, bank->base +
2173 OMAP4_GPIO_LEVELDETECT0);
2174 __raw_writel(old1 | l, bank->base +
2175 OMAP4_GPIO_LEVELDETECT1);
2176 __raw_writel(old0, bank->base +
2177 OMAP4_GPIO_LEVELDETECT0);
2178 __raw_writel(old1, bank->base +
2179 OMAP4_GPIO_LEVELDETECT1);
2180 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002181 }
2182 }
2183
2184}
2185
Tony Lindgren92105bb2005-09-07 17:20:26 +01002186#endif
2187
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08002188#ifdef CONFIG_ARCH_OMAP3
Rajendra Nayak40c670f2008-09-26 17:47:48 +05302189/* save the registers of bank 2-6 */
2190void omap_gpio_save_context(void)
2191{
2192 int i;
2193
2194 /* saving banks from 2-6 only since GPIO1 is in WKUP */
2195 for (i = 1; i < gpio_bank_count; i++) {
2196 struct gpio_bank *bank = &gpio_bank[i];
2197 gpio_context[i].sysconfig =
2198 __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG);
2199 gpio_context[i].irqenable1 =
2200 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
2201 gpio_context[i].irqenable2 =
2202 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
2203 gpio_context[i].wake_en =
2204 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
2205 gpio_context[i].ctrl =
2206 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
2207 gpio_context[i].oe =
2208 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
2209 gpio_context[i].leveldetect0 =
2210 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2211 gpio_context[i].leveldetect1 =
2212 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2213 gpio_context[i].risingdetect =
2214 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
2215 gpio_context[i].fallingdetect =
2216 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2217 gpio_context[i].dataout =
2218 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
2219 gpio_context[i].setwkuena =
2220 __raw_readl(bank->base + OMAP24XX_GPIO_SETWKUENA);
2221 gpio_context[i].setdataout =
2222 __raw_readl(bank->base + OMAP24XX_GPIO_SETDATAOUT);
2223 }
2224}
2225
2226/* restore the required registers of bank 2-6 */
2227void omap_gpio_restore_context(void)
2228{
2229 int i;
2230
2231 for (i = 1; i < gpio_bank_count; i++) {
2232 struct gpio_bank *bank = &gpio_bank[i];
2233 __raw_writel(gpio_context[i].sysconfig,
2234 bank->base + OMAP24XX_GPIO_SYSCONFIG);
2235 __raw_writel(gpio_context[i].irqenable1,
2236 bank->base + OMAP24XX_GPIO_IRQENABLE1);
2237 __raw_writel(gpio_context[i].irqenable2,
2238 bank->base + OMAP24XX_GPIO_IRQENABLE2);
2239 __raw_writel(gpio_context[i].wake_en,
2240 bank->base + OMAP24XX_GPIO_WAKE_EN);
2241 __raw_writel(gpio_context[i].ctrl,
2242 bank->base + OMAP24XX_GPIO_CTRL);
2243 __raw_writel(gpio_context[i].oe,
2244 bank->base + OMAP24XX_GPIO_OE);
2245 __raw_writel(gpio_context[i].leveldetect0,
2246 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2247 __raw_writel(gpio_context[i].leveldetect1,
2248 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
2249 __raw_writel(gpio_context[i].risingdetect,
2250 bank->base + OMAP24XX_GPIO_RISINGDETECT);
2251 __raw_writel(gpio_context[i].fallingdetect,
2252 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
2253 __raw_writel(gpio_context[i].dataout,
2254 bank->base + OMAP24XX_GPIO_DATAOUT);
2255 __raw_writel(gpio_context[i].setwkuena,
2256 bank->base + OMAP24XX_GPIO_SETWKUENA);
2257 __raw_writel(gpio_context[i].setdataout,
2258 bank->base + OMAP24XX_GPIO_SETDATAOUT);
2259 }
2260}
2261#endif
2262
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002263/*
2264 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002265 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002266 */
David Brownell277d58e2006-12-06 17:13:59 -08002267int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002268{
2269 if (!initialized)
2270 return _omap_gpio_init();
2271 else
2272 return 0;
2273}
2274
Tony Lindgren92105bb2005-09-07 17:20:26 +01002275static int __init omap_gpio_sysinit(void)
2276{
2277 int ret = 0;
2278
2279 if (!initialized)
2280 ret = _omap_gpio_init();
2281
David Brownell11a78b72006-12-06 17:14:11 -08002282 mpuio_init();
2283
Tony Lindgren140455f2010-02-12 12:26:48 -08002284#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002285 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002286 if (ret == 0) {
2287 ret = sysdev_class_register(&omap_gpio_sysclass);
2288 if (ret == 0)
2289 ret = sysdev_register(&omap_gpio_device);
2290 }
2291 }
2292#endif
2293
2294 return ret;
2295}
2296
Tony Lindgren92105bb2005-09-07 17:20:26 +01002297arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002298
2299
2300#ifdef CONFIG_DEBUG_FS
2301
2302#include <linux/debugfs.h>
2303#include <linux/seq_file.h>
2304
David Brownellb9772a22006-12-06 17:13:53 -08002305static int dbg_gpio_show(struct seq_file *s, void *unused)
2306{
2307 unsigned i, j, gpio;
2308
2309 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2310 struct gpio_bank *bank = gpio_bank + i;
2311 unsigned bankwidth = 16;
2312 u32 mask = 1;
2313
David Brownelle5c56ed2006-12-06 17:13:59 -08002314 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002315 gpio = OMAP_MPUIO(0);
Alistair Buxtonb718aa82009-09-23 18:56:19 +01002316 else if (cpu_class_is_omap2() || cpu_is_omap7xx())
David Brownellb9772a22006-12-06 17:13:53 -08002317 bankwidth = 32;
2318
2319 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2320 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002321 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002322
David Brownell52e31342008-03-03 12:43:23 -08002323 label = gpiochip_is_requested(&bank->chip, j);
2324 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002325 continue;
2326
2327 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002328 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002329 is_in = gpio_is_input(bank, mask);
2330
David Brownelle5c56ed2006-12-06 17:13:59 -08002331 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002332 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002333 else
David Brownell52e31342008-03-03 12:43:23 -08002334 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002335 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002336 label,
David Brownellb9772a22006-12-06 17:13:53 -08002337 is_in ? "in " : "out",
2338 value ? "hi" : "lo");
2339
David Brownell52e31342008-03-03 12:43:23 -08002340/* FIXME for at least omap2, show pullup/pulldown state */
2341
David Brownellb9772a22006-12-06 17:13:53 -08002342 irqstat = irq_desc[irq].status;
Tony Lindgren140455f2010-02-12 12:26:48 -08002343#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
David Brownellb9772a22006-12-06 17:13:53 -08002344 if (is_in && ((bank->suspend_wakeup & mask)
2345 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2346 char *trigger = NULL;
2347
2348 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2349 case IRQ_TYPE_EDGE_FALLING:
2350 trigger = "falling";
2351 break;
2352 case IRQ_TYPE_EDGE_RISING:
2353 trigger = "rising";
2354 break;
2355 case IRQ_TYPE_EDGE_BOTH:
2356 trigger = "bothedge";
2357 break;
2358 case IRQ_TYPE_LEVEL_LOW:
2359 trigger = "low";
2360 break;
2361 case IRQ_TYPE_LEVEL_HIGH:
2362 trigger = "high";
2363 break;
2364 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002365 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002366 break;
2367 }
David Brownell52e31342008-03-03 12:43:23 -08002368 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002369 irq, trigger,
2370 (bank->suspend_wakeup & mask)
2371 ? " wakeup" : "");
2372 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002373#endif
David Brownellb9772a22006-12-06 17:13:53 -08002374 seq_printf(s, "\n");
2375 }
2376
David Brownelle5c56ed2006-12-06 17:13:59 -08002377 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002378 seq_printf(s, "\n");
2379 gpio = 0;
2380 }
2381 }
2382 return 0;
2383}
2384
2385static int dbg_gpio_open(struct inode *inode, struct file *file)
2386{
David Brownelle5c56ed2006-12-06 17:13:59 -08002387 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002388}
2389
2390static const struct file_operations debug_fops = {
2391 .open = dbg_gpio_open,
2392 .read = seq_read,
2393 .llseek = seq_lseek,
2394 .release = single_release,
2395};
2396
2397static int __init omap_gpio_debuginit(void)
2398{
David Brownelle5c56ed2006-12-06 17:13:59 -08002399 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2400 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002401 return 0;
2402}
2403late_initcall(omap_gpio_debuginit);
2404#endif