blob: f0b71680ec52fe67bcf861566222febd72b3ea36 [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 */
Russell King7c7095a2008-09-05 15:49:14 +010034#define OMAP1510_GPIO_BASE IO_ADDRESS(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 */
Russell King7c7095a2008-09-05 15:49:14 +010048#define OMAP1610_GPIO1_BASE IO_ADDRESS(0xfffbe400)
49#define OMAP1610_GPIO2_BASE IO_ADDRESS(0xfffbec00)
50#define OMAP1610_GPIO3_BASE IO_ADDRESS(0xfffbb400)
51#define OMAP1610_GPIO4_BASE IO_ADDRESS(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/*
71 * OMAP730 specific GPIO registers
72 */
Russell King7c7095a2008-09-05 15:49:14 +010073#define OMAP730_GPIO1_BASE IO_ADDRESS(0xfffbc000)
74#define OMAP730_GPIO2_BASE IO_ADDRESS(0xfffbc800)
75#define OMAP730_GPIO3_BASE IO_ADDRESS(0xfffbd000)
76#define OMAP730_GPIO4_BASE IO_ADDRESS(0xfffbd800)
77#define OMAP730_GPIO5_BASE IO_ADDRESS(0xfffbe000)
78#define OMAP730_GPIO6_BASE IO_ADDRESS(0xfffbe800)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010079#define OMAP730_GPIO_DATA_INPUT 0x00
80#define OMAP730_GPIO_DATA_OUTPUT 0x04
81#define OMAP730_GPIO_DIR_CONTROL 0x08
82#define OMAP730_GPIO_INT_CONTROL 0x0c
83#define OMAP730_GPIO_INT_MASK 0x10
84#define OMAP730_GPIO_INT_STATUS 0x14
85
Tony Lindgren92105bb2005-09-07 17:20:26 +010086/*
Zebediah C. McClure56739a62009-03-23 18:07:40 -070087 * OMAP850 specific GPIO registers
88 */
89#define OMAP850_GPIO1_BASE IO_ADDRESS(0xfffbc000)
90#define OMAP850_GPIO2_BASE IO_ADDRESS(0xfffbc800)
91#define OMAP850_GPIO3_BASE IO_ADDRESS(0xfffbd000)
92#define OMAP850_GPIO4_BASE IO_ADDRESS(0xfffbd800)
93#define OMAP850_GPIO5_BASE IO_ADDRESS(0xfffbe000)
94#define OMAP850_GPIO6_BASE IO_ADDRESS(0xfffbe800)
95#define OMAP850_GPIO_DATA_INPUT 0x00
96#define OMAP850_GPIO_DATA_OUTPUT 0x04
97#define OMAP850_GPIO_DIR_CONTROL 0x08
98#define OMAP850_GPIO_INT_CONTROL 0x0c
99#define OMAP850_GPIO_INT_MASK 0x10
100#define OMAP850_GPIO_INT_STATUS 0x14
101
102/*
Tony Lindgren92105bb2005-09-07 17:20:26 +0100103 * omap24xx specific GPIO registers
104 */
Russell King7c7095a2008-09-05 15:49:14 +0100105#define OMAP242X_GPIO1_BASE IO_ADDRESS(0x48018000)
106#define OMAP242X_GPIO2_BASE IO_ADDRESS(0x4801a000)
107#define OMAP242X_GPIO3_BASE IO_ADDRESS(0x4801c000)
108#define OMAP242X_GPIO4_BASE IO_ADDRESS(0x4801e000)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800109
Russell King7c7095a2008-09-05 15:49:14 +0100110#define OMAP243X_GPIO1_BASE IO_ADDRESS(0x4900C000)
111#define OMAP243X_GPIO2_BASE IO_ADDRESS(0x4900E000)
112#define OMAP243X_GPIO3_BASE IO_ADDRESS(0x49010000)
113#define OMAP243X_GPIO4_BASE IO_ADDRESS(0x49012000)
114#define OMAP243X_GPIO5_BASE IO_ADDRESS(0x480B6000)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800115
Tony Lindgren92105bb2005-09-07 17:20:26 +0100116#define OMAP24XX_GPIO_REVISION 0x0000
117#define OMAP24XX_GPIO_SYSCONFIG 0x0010
118#define OMAP24XX_GPIO_SYSSTATUS 0x0014
119#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300120#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
121#define OMAP24XX_GPIO_IRQENABLE2 0x002c
Tony Lindgren92105bb2005-09-07 17:20:26 +0100122#define OMAP24XX_GPIO_IRQENABLE1 0x001c
Tero Kristo723fdb72008-11-26 14:35:16 -0800123#define OMAP24XX_GPIO_WAKE_EN 0x0020
Tony Lindgren92105bb2005-09-07 17:20:26 +0100124#define OMAP24XX_GPIO_CTRL 0x0030
125#define OMAP24XX_GPIO_OE 0x0034
126#define OMAP24XX_GPIO_DATAIN 0x0038
127#define OMAP24XX_GPIO_DATAOUT 0x003c
128#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
129#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
130#define OMAP24XX_GPIO_RISINGDETECT 0x0048
131#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700132#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
133#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
Tony Lindgren92105bb2005-09-07 17:20:26 +0100134#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
135#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
136#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
137#define OMAP24XX_GPIO_SETWKUENA 0x0084
138#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
139#define OMAP24XX_GPIO_SETDATAOUT 0x0094
140
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530141#define OMAP4_GPIO_REVISION 0x0000
142#define OMAP4_GPIO_SYSCONFIG 0x0010
143#define OMAP4_GPIO_EOI 0x0020
144#define OMAP4_GPIO_IRQSTATUSRAW0 0x0024
145#define OMAP4_GPIO_IRQSTATUSRAW1 0x0028
146#define OMAP4_GPIO_IRQSTATUS0 0x002c
147#define OMAP4_GPIO_IRQSTATUS1 0x0030
148#define OMAP4_GPIO_IRQSTATUSSET0 0x0034
149#define OMAP4_GPIO_IRQSTATUSSET1 0x0038
150#define OMAP4_GPIO_IRQSTATUSCLR0 0x003c
151#define OMAP4_GPIO_IRQSTATUSCLR1 0x0040
152#define OMAP4_GPIO_IRQWAKEN0 0x0044
153#define OMAP4_GPIO_IRQWAKEN1 0x0048
154#define OMAP4_GPIO_SYSSTATUS 0x0104
155#define OMAP4_GPIO_CTRL 0x0130
156#define OMAP4_GPIO_OE 0x0134
157#define OMAP4_GPIO_DATAIN 0x0138
158#define OMAP4_GPIO_DATAOUT 0x013c
159#define OMAP4_GPIO_LEVELDETECT0 0x0140
160#define OMAP4_GPIO_LEVELDETECT1 0x0144
161#define OMAP4_GPIO_RISINGDETECT 0x0148
162#define OMAP4_GPIO_FALLINGDETECT 0x014c
163#define OMAP4_GPIO_DEBOUNCENABLE 0x0150
164#define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
165#define OMAP4_GPIO_CLEARDATAOUT 0x0190
166#define OMAP4_GPIO_SETDATAOUT 0x0194
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800167/*
168 * omap34xx specific GPIO registers
169 */
170
Russell King7c7095a2008-09-05 15:49:14 +0100171#define OMAP34XX_GPIO1_BASE IO_ADDRESS(0x48310000)
172#define OMAP34XX_GPIO2_BASE IO_ADDRESS(0x49050000)
173#define OMAP34XX_GPIO3_BASE IO_ADDRESS(0x49052000)
174#define OMAP34XX_GPIO4_BASE IO_ADDRESS(0x49054000)
175#define OMAP34XX_GPIO5_BASE IO_ADDRESS(0x49056000)
176#define OMAP34XX_GPIO6_BASE IO_ADDRESS(0x49058000)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800177
Santosh Shilimkar44169072009-05-28 14:16:04 -0700178/*
179 * OMAP44XX specific GPIO registers
180 */
181#define OMAP44XX_GPIO1_BASE IO_ADDRESS(0x4a310000)
182#define OMAP44XX_GPIO2_BASE IO_ADDRESS(0x48055000)
183#define OMAP44XX_GPIO3_BASE IO_ADDRESS(0x48057000)
184#define OMAP44XX_GPIO4_BASE IO_ADDRESS(0x48059000)
185#define OMAP44XX_GPIO5_BASE IO_ADDRESS(0x4805B000)
186#define OMAP44XX_GPIO6_BASE IO_ADDRESS(0x4805D000)
187
Russell King7c7095a2008-09-05 15:49:14 +0100188#define OMAP_MPUIO_VBASE IO_ADDRESS(OMAP_MPUIO_BASE)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800189
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100190struct gpio_bank {
Tony Lindgren92105bb2005-09-07 17:20:26 +0100191 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100192 u16 irq;
193 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100194 int method;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700195#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
196 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100197 u32 suspend_wakeup;
198 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800199#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700200#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
201 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800202 u32 non_wakeup_gpios;
203 u32 enabled_non_wakeup_gpios;
204
205 u32 saved_datain;
206 u32 saved_fallingdetect;
207 u32 saved_risingdetect;
208#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800209 u32 level_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100210 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800211 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800212 struct clk *dbck;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100213};
214
215#define METHOD_MPUIO 0
216#define METHOD_GPIO_1510 1
217#define METHOD_GPIO_1610 2
218#define METHOD_GPIO_730 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700219#define METHOD_GPIO_850 4
220#define METHOD_GPIO_24XX 5
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100221
Tony Lindgren92105bb2005-09-07 17:20:26 +0100222#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100223static struct gpio_bank gpio_bank_1610[5] = {
Russell King7c7095a2008-09-05 15:49:14 +0100224 { OMAP_MPUIO_VBASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO},
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100225 { OMAP1610_GPIO1_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1610 },
226 { OMAP1610_GPIO2_BASE, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16, METHOD_GPIO_1610 },
227 { OMAP1610_GPIO3_BASE, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32, METHOD_GPIO_1610 },
228 { OMAP1610_GPIO4_BASE, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48, METHOD_GPIO_1610 },
229};
230#endif
231
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000232#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100233static struct gpio_bank gpio_bank_1510[2] = {
Russell King7c7095a2008-09-05 15:49:14 +0100234 { OMAP_MPUIO_VBASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100235 { OMAP1510_GPIO_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1510 }
236};
237#endif
238
239#ifdef CONFIG_ARCH_OMAP730
240static struct gpio_bank gpio_bank_730[7] = {
Russell King7c7095a2008-09-05 15:49:14 +0100241 { OMAP_MPUIO_VBASE, INT_730_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100242 { OMAP730_GPIO1_BASE, INT_730_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_730 },
243 { OMAP730_GPIO2_BASE, INT_730_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_730 },
244 { OMAP730_GPIO3_BASE, INT_730_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_730 },
245 { OMAP730_GPIO4_BASE, INT_730_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_730 },
246 { OMAP730_GPIO5_BASE, INT_730_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_730 },
247 { OMAP730_GPIO6_BASE, INT_730_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_730 },
248};
249#endif
250
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700251#ifdef CONFIG_ARCH_OMAP850
252static struct gpio_bank gpio_bank_850[7] = {
253 { OMAP_MPUIO_BASE, INT_850_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
254 { OMAP850_GPIO1_BASE, INT_850_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_850 },
255 { OMAP850_GPIO2_BASE, INT_850_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_850 },
256 { OMAP850_GPIO3_BASE, INT_850_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_850 },
257 { OMAP850_GPIO4_BASE, INT_850_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_850 },
258 { OMAP850_GPIO5_BASE, INT_850_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_850 },
259 { OMAP850_GPIO6_BASE, INT_850_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_850 },
260};
261#endif
262
263
Tony Lindgren92105bb2005-09-07 17:20:26 +0100264#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800265
266static struct gpio_bank gpio_bank_242x[4] = {
267 { OMAP242X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
268 { OMAP242X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
269 { OMAP242X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
270 { OMAP242X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
Tony Lindgren92105bb2005-09-07 17:20:26 +0100271};
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800272
273static struct gpio_bank gpio_bank_243x[5] = {
274 { OMAP243X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
275 { OMAP243X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
276 { OMAP243X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
277 { OMAP243X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
278 { OMAP243X_GPIO5_BASE, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX },
279};
280
Tony Lindgren92105bb2005-09-07 17:20:26 +0100281#endif
282
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800283#ifdef CONFIG_ARCH_OMAP34XX
284static struct gpio_bank gpio_bank_34xx[6] = {
285 { OMAP34XX_GPIO1_BASE, INT_34XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
286 { OMAP34XX_GPIO2_BASE, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
287 { OMAP34XX_GPIO3_BASE, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
288 { OMAP34XX_GPIO4_BASE, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
289 { OMAP34XX_GPIO5_BASE, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX },
290 { OMAP34XX_GPIO6_BASE, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_24XX },
291};
292
293#endif
294
Santosh Shilimkar44169072009-05-28 14:16:04 -0700295#ifdef CONFIG_ARCH_OMAP4
296static struct gpio_bank gpio_bank_44xx[6] = {
297 { OMAP44XX_GPIO1_BASE, INT_44XX_GPIO_BANK1, IH_GPIO_BASE, \
298 METHOD_GPIO_24XX },
299 { OMAP44XX_GPIO2_BASE, INT_44XX_GPIO_BANK2, IH_GPIO_BASE + 32, \
300 METHOD_GPIO_24XX },
301 { OMAP44XX_GPIO3_BASE, INT_44XX_GPIO_BANK3, IH_GPIO_BASE + 64, \
302 METHOD_GPIO_24XX },
303 { OMAP44XX_GPIO4_BASE, INT_44XX_GPIO_BANK4, IH_GPIO_BASE + 96, \
304 METHOD_GPIO_24XX },
305 { OMAP44XX_GPIO5_BASE, INT_44XX_GPIO_BANK5, IH_GPIO_BASE + 128, \
306 METHOD_GPIO_24XX },
307 { OMAP44XX_GPIO6_BASE, INT_44XX_GPIO_BANK6, IH_GPIO_BASE + 160, \
308 METHOD_GPIO_24XX },
309};
310
311#endif
312
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100313static struct gpio_bank *gpio_bank;
314static int gpio_bank_count;
315
316static inline struct gpio_bank *get_gpio_bank(int gpio)
317{
Tony Lindgren6e60e792006-04-02 17:46:23 +0100318 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100319 if (OMAP_GPIO_IS_MPUIO(gpio))
320 return &gpio_bank[0];
321 return &gpio_bank[1];
322 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100323 if (cpu_is_omap16xx()) {
324 if (OMAP_GPIO_IS_MPUIO(gpio))
325 return &gpio_bank[0];
326 return &gpio_bank[1 + (gpio >> 4)];
327 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700328 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100329 if (OMAP_GPIO_IS_MPUIO(gpio))
330 return &gpio_bank[0];
331 return &gpio_bank[1 + (gpio >> 5)];
332 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100333 if (cpu_is_omap24xx())
334 return &gpio_bank[gpio >> 5];
Santosh Shilimkar44169072009-05-28 14:16:04 -0700335 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800336 return &gpio_bank[gpio >> 5];
David Brownelle031ab22008-12-10 17:35:27 -0800337 BUG();
338 return NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100339}
340
341static inline int get_gpio_index(int gpio)
342{
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700343 if (cpu_is_omap7xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100344 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100345 if (cpu_is_omap24xx())
346 return gpio & 0x1f;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700347 if (cpu_is_omap34xx() || cpu_is_omap44xx())
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800348 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100349 return gpio & 0x0f;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100350}
351
352static inline int gpio_valid(int gpio)
353{
354 if (gpio < 0)
355 return -1;
Tony Lindgrend11ac972008-01-12 15:35:04 -0800356 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
Jonathan McDowell193e68b2006-09-25 12:41:30 +0300357 if (gpio >= OMAP_MAX_GPIO_LINES + 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100358 return -1;
359 return 0;
360 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100361 if (cpu_is_omap15xx() && gpio < 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100362 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100363 if ((cpu_is_omap16xx()) && gpio < 64)
364 return 0;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700365 if (cpu_is_omap7xx() && gpio < 192)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100366 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100367 if (cpu_is_omap24xx() && gpio < 128)
368 return 0;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700369 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800370 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100371 return -1;
372}
373
374static int check_gpio(int gpio)
375{
376 if (unlikely(gpio_valid(gpio)) < 0) {
377 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
378 dump_stack();
379 return -1;
380 }
381 return 0;
382}
383
384static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
385{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100386 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100387 u32 l;
388
389 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800390#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100391 case METHOD_MPUIO:
392 reg += OMAP_MPUIO_IO_CNTL;
393 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800394#endif
395#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100396 case METHOD_GPIO_1510:
397 reg += OMAP1510_GPIO_DIR_CONTROL;
398 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800399#endif
400#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100401 case METHOD_GPIO_1610:
402 reg += OMAP1610_GPIO_DIRECTION;
403 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800404#endif
405#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100406 case METHOD_GPIO_730:
407 reg += OMAP730_GPIO_DIR_CONTROL;
408 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800409#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700410#ifdef CONFIG_ARCH_OMAP850
411 case METHOD_GPIO_850:
412 reg += OMAP850_GPIO_DIR_CONTROL;
413 break;
414#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530415#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100416 case METHOD_GPIO_24XX:
417 reg += OMAP24XX_GPIO_OE;
418 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800419#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530420#if defined(CONFIG_ARCH_OMAP4)
421 case METHOD_GPIO_24XX:
422 reg += OMAP4_GPIO_OE;
423 break;
424#endif
David Brownelle5c56ed2006-12-06 17:13:59 -0800425 default:
426 WARN_ON(1);
427 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100428 }
429 l = __raw_readl(reg);
430 if (is_input)
431 l |= 1 << gpio;
432 else
433 l &= ~(1 << gpio);
434 __raw_writel(l, reg);
435}
436
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100437static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
438{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100439 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100440 u32 l = 0;
441
442 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800443#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100444 case METHOD_MPUIO:
445 reg += OMAP_MPUIO_OUTPUT;
446 l = __raw_readl(reg);
447 if (enable)
448 l |= 1 << gpio;
449 else
450 l &= ~(1 << gpio);
451 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800452#endif
453#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100454 case METHOD_GPIO_1510:
455 reg += OMAP1510_GPIO_DATA_OUTPUT;
456 l = __raw_readl(reg);
457 if (enable)
458 l |= 1 << gpio;
459 else
460 l &= ~(1 << gpio);
461 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800462#endif
463#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100464 case METHOD_GPIO_1610:
465 if (enable)
466 reg += OMAP1610_GPIO_SET_DATAOUT;
467 else
468 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
469 l = 1 << gpio;
470 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800471#endif
472#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100473 case METHOD_GPIO_730:
474 reg += OMAP730_GPIO_DATA_OUTPUT;
475 l = __raw_readl(reg);
476 if (enable)
477 l |= 1 << gpio;
478 else
479 l &= ~(1 << gpio);
480 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800481#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700482#ifdef CONFIG_ARCH_OMAP850
483 case METHOD_GPIO_850:
484 reg += OMAP850_GPIO_DATA_OUTPUT;
485 l = __raw_readl(reg);
486 if (enable)
487 l |= 1 << gpio;
488 else
489 l &= ~(1 << gpio);
490 break;
491#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530492#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100493 case METHOD_GPIO_24XX:
494 if (enable)
495 reg += OMAP24XX_GPIO_SETDATAOUT;
496 else
497 reg += OMAP24XX_GPIO_CLEARDATAOUT;
498 l = 1 << gpio;
499 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800500#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530501#ifdef CONFIG_ARCH_OMAP4
502 case METHOD_GPIO_24XX:
503 if (enable)
504 reg += OMAP4_GPIO_SETDATAOUT;
505 else
506 reg += OMAP4_GPIO_CLEARDATAOUT;
507 l = 1 << gpio;
508 break;
509#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100510 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800511 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100512 return;
513 }
514 __raw_writel(l, reg);
515}
516
David Brownell0b84b5c2008-12-10 17:35:25 -0800517static int __omap_get_gpio_datain(int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100518{
519 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100520 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100521
522 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800523 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100524 bank = get_gpio_bank(gpio);
525 reg = bank->base;
526 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800527#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100528 case METHOD_MPUIO:
529 reg += OMAP_MPUIO_INPUT_LATCH;
530 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800531#endif
532#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100533 case METHOD_GPIO_1510:
534 reg += OMAP1510_GPIO_DATA_INPUT;
535 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800536#endif
537#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100538 case METHOD_GPIO_1610:
539 reg += OMAP1610_GPIO_DATAIN;
540 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800541#endif
542#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100543 case METHOD_GPIO_730:
544 reg += OMAP730_GPIO_DATA_INPUT;
545 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800546#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700547#ifdef CONFIG_ARCH_OMAP850
548 case METHOD_GPIO_850:
549 reg += OMAP850_GPIO_DATA_INPUT;
550 break;
551#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530552#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100553 case METHOD_GPIO_24XX:
554 reg += OMAP24XX_GPIO_DATAIN;
555 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800556#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530557#ifdef CONFIG_ARCH_OMAP4
558 case METHOD_GPIO_24XX:
559 reg += OMAP4_GPIO_DATAIN;
560 break;
561#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100562 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800563 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100564 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100565 return (__raw_readl(reg)
566 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100567}
568
Tony Lindgren92105bb2005-09-07 17:20:26 +0100569#define MOD_REG_BIT(reg, bit_mask, set) \
570do { \
571 int l = __raw_readl(base + reg); \
572 if (set) l |= bit_mask; \
573 else l &= ~bit_mask; \
574 __raw_writel(l, base + reg); \
575} while(0)
576
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700577void omap_set_gpio_debounce(int gpio, int enable)
578{
579 struct gpio_bank *bank;
580 void __iomem *reg;
David Brownelle031ab22008-12-10 17:35:27 -0800581 unsigned long flags;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700582 u32 val, l = 1 << get_gpio_index(gpio);
583
584 if (cpu_class_is_omap1())
585 return;
586
587 bank = get_gpio_bank(gpio);
588 reg = bank->base;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530589#ifdef CONFIG_ARCH_OMAP4
590 reg += OMAP4_GPIO_DEBOUNCENABLE;
591#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700592 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530593#endif
David Brownelle031ab22008-12-10 17:35:27 -0800594
595 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700596 val = __raw_readl(reg);
597
Jouni Hogander89db9482008-12-10 17:35:24 -0800598 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700599 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800600 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700601 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800602 else
David Brownelle031ab22008-12-10 17:35:27 -0800603 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800604
Santosh Shilimkar44169072009-05-28 14:16:04 -0700605 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800606 if (enable)
607 clk_enable(bank->dbck);
608 else
609 clk_disable(bank->dbck);
610 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700611
612 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800613done:
614 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700615}
616EXPORT_SYMBOL(omap_set_gpio_debounce);
617
618void omap_set_gpio_debounce_time(int gpio, int enc_time)
619{
620 struct gpio_bank *bank;
621 void __iomem *reg;
622
623 if (cpu_class_is_omap1())
624 return;
625
626 bank = get_gpio_bank(gpio);
627 reg = bank->base;
628
629 enc_time &= 0xff;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530630#ifdef CONFIG_ARCH_OMAP4
631 reg += OMAP4_GPIO_DEBOUNCINGTIME;
632#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700633 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530634#endif
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700635 __raw_writel(enc_time, reg);
636}
637EXPORT_SYMBOL(omap_set_gpio_debounce_time);
638
Santosh Shilimkar44169072009-05-28 14:16:04 -0700639#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
640 defined(CONFIG_ARCH_OMAP4)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700641static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
642 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100643{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800644 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100645 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530646 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100647
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530648 if (cpu_is_omap44xx()) {
649 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
650 trigger & IRQ_TYPE_LEVEL_LOW);
651 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
652 trigger & IRQ_TYPE_LEVEL_HIGH);
653 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
654 trigger & IRQ_TYPE_EDGE_RISING);
655 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
656 trigger & IRQ_TYPE_EDGE_FALLING);
657 } else {
658 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
659 trigger & IRQ_TYPE_LEVEL_LOW);
660 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
661 trigger & IRQ_TYPE_LEVEL_HIGH);
662 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
663 trigger & IRQ_TYPE_EDGE_RISING);
664 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
665 trigger & IRQ_TYPE_EDGE_FALLING);
666 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800667 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530668 if (cpu_is_omap44xx()) {
669 if (trigger != 0)
670 __raw_writel(1 << gpio, bank->base+
671 OMAP4_GPIO_IRQWAKEN0);
672 else {
673 val = __raw_readl(bank->base +
674 OMAP4_GPIO_IRQWAKEN0);
675 __raw_writel(val & (~(1 << gpio)), bank->base +
676 OMAP4_GPIO_IRQWAKEN0);
677 }
678 } else {
679 if (trigger != 0)
680 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700681 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530682 else
683 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700684 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530685 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800686 } else {
687 if (trigger != 0)
688 bank->enabled_non_wakeup_gpios |= gpio_bit;
689 else
690 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
691 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700692
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530693 if (cpu_is_omap44xx()) {
694 bank->level_mask =
695 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
696 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
697 } else {
698 bank->level_mask =
699 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
700 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
701 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100702}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800703#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100704
705static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
706{
707 void __iomem *reg = bank->base;
708 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100709
710 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800711#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100712 case METHOD_MPUIO:
713 reg += OMAP_MPUIO_GPIO_INT_EDGE;
714 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100715 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100716 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100717 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100718 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100719 else
720 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100721 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800722#endif
723#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100724 case METHOD_GPIO_1510:
725 reg += OMAP1510_GPIO_INT_CONTROL;
726 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100727 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100728 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100729 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100730 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100731 else
732 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100733 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800734#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800735#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100736 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100737 if (gpio & 0x08)
738 reg += OMAP1610_GPIO_EDGE_CTRL2;
739 else
740 reg += OMAP1610_GPIO_EDGE_CTRL1;
741 gpio &= 0x07;
742 l = __raw_readl(reg);
743 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100744 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100745 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100746 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100747 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800748 if (trigger)
749 /* Enable wake-up during idle for dynamic tick */
750 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
751 else
752 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100753 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800754#endif
755#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100756 case METHOD_GPIO_730:
757 reg += OMAP730_GPIO_INT_CONTROL;
758 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100759 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100760 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100761 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100762 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100763 else
764 goto bad;
765 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800766#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700767#ifdef CONFIG_ARCH_OMAP850
768 case METHOD_GPIO_850:
769 reg += OMAP850_GPIO_INT_CONTROL;
770 l = __raw_readl(reg);
771 if (trigger & IRQ_TYPE_EDGE_RISING)
772 l |= 1 << gpio;
773 else if (trigger & IRQ_TYPE_EDGE_FALLING)
774 l &= ~(1 << gpio);
775 else
776 goto bad;
777 break;
778#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700779#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
780 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100781 case METHOD_GPIO_24XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800782 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100783 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800784#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100785 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100786 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100787 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100788 __raw_writel(l, reg);
789 return 0;
790bad:
791 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100792}
793
Tony Lindgren92105bb2005-09-07 17:20:26 +0100794static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100795{
796 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100797 unsigned gpio;
798 int retval;
David Brownella6472532008-03-03 04:33:30 -0800799 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100800
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800801 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100802 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
803 else
804 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100805
806 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100807 return -EINVAL;
808
David Brownelle5c56ed2006-12-06 17:13:59 -0800809 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100810 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800811
812 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800813 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800814 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100815 return -EINVAL;
816
David Brownell58781012006-12-06 17:14:10 -0800817 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800818 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100819 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800820 if (retval == 0) {
821 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
822 irq_desc[irq].status |= type;
823 }
David Brownella6472532008-03-03 04:33:30 -0800824 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800825
826 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
827 __set_irq_handler_unlocked(irq, handle_level_irq);
828 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
829 __set_irq_handler_unlocked(irq, handle_edge_irq);
830
Tony Lindgren92105bb2005-09-07 17:20:26 +0100831 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100832}
833
834static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
835{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100836 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100837
838 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800839#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100840 case METHOD_MPUIO:
841 /* MPUIO irqstatus is reset by reading the status register,
842 * so do nothing here */
843 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800844#endif
845#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100846 case METHOD_GPIO_1510:
847 reg += OMAP1510_GPIO_INT_STATUS;
848 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800849#endif
850#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100851 case METHOD_GPIO_1610:
852 reg += OMAP1610_GPIO_IRQSTATUS1;
853 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800854#endif
855#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100856 case METHOD_GPIO_730:
857 reg += OMAP730_GPIO_INT_STATUS;
858 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800859#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700860#ifdef CONFIG_ARCH_OMAP850
861 case METHOD_GPIO_850:
862 reg += OMAP850_GPIO_INT_STATUS;
863 break;
864#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530865#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100866 case METHOD_GPIO_24XX:
867 reg += OMAP24XX_GPIO_IRQSTATUS1;
868 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800869#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530870#if defined(CONFIG_ARCH_OMAP4)
871 case METHOD_GPIO_24XX:
872 reg += OMAP4_GPIO_IRQSTATUS0;
873 break;
874#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100875 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800876 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100877 return;
878 }
879 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300880
881 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800882#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Roger Quadrosbedfd152009-04-23 11:10:50 -0700883 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530884#endif
885#if defined(CONFIG_ARCH_OMAP4)
886 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
887#endif
888 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700889 __raw_writel(gpio_mask, reg);
890
891 /* Flush posted write for the irq status to avoid spurious interrupts */
892 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530893 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100894}
895
896static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
897{
898 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
899}
900
Imre Deakea6dedd2006-06-26 16:16:00 -0700901static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
902{
903 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700904 int inv = 0;
905 u32 l;
906 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700907
908 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800909#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700910 case METHOD_MPUIO:
911 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700912 mask = 0xffff;
913 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700914 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800915#endif
916#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700917 case METHOD_GPIO_1510:
918 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700919 mask = 0xffff;
920 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700921 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800922#endif
923#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700924 case METHOD_GPIO_1610:
925 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700926 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700927 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800928#endif
929#ifdef CONFIG_ARCH_OMAP730
Imre Deakea6dedd2006-06-26 16:16:00 -0700930 case METHOD_GPIO_730:
931 reg += OMAP730_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700932 mask = 0xffffffff;
933 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700934 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800935#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700936#ifdef CONFIG_ARCH_OMAP850
937 case METHOD_GPIO_850:
938 reg += OMAP850_GPIO_INT_MASK;
939 mask = 0xffffffff;
940 inv = 1;
941 break;
942#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530943#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Imre Deakea6dedd2006-06-26 16:16:00 -0700944 case METHOD_GPIO_24XX:
945 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700946 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700947 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800948#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530949#if defined(CONFIG_ARCH_OMAP4)
950 case METHOD_GPIO_24XX:
951 reg += OMAP4_GPIO_IRQSTATUSSET0;
952 mask = 0xffffffff;
953 break;
954#endif
Imre Deakea6dedd2006-06-26 16:16:00 -0700955 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800956 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -0700957 return 0;
958 }
959
Imre Deak99c47702006-06-26 16:16:07 -0700960 l = __raw_readl(reg);
961 if (inv)
962 l = ~l;
963 l &= mask;
964 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700965}
966
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100967static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
968{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100969 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100970 u32 l;
971
972 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800973#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100974 case METHOD_MPUIO:
975 reg += OMAP_MPUIO_GPIO_MASKIT;
976 l = __raw_readl(reg);
977 if (enable)
978 l &= ~(gpio_mask);
979 else
980 l |= gpio_mask;
981 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800982#endif
983#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100984 case METHOD_GPIO_1510:
985 reg += OMAP1510_GPIO_INT_MASK;
986 l = __raw_readl(reg);
987 if (enable)
988 l &= ~(gpio_mask);
989 else
990 l |= gpio_mask;
991 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800992#endif
993#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100994 case METHOD_GPIO_1610:
995 if (enable)
996 reg += OMAP1610_GPIO_SET_IRQENABLE1;
997 else
998 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
999 l = gpio_mask;
1000 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001001#endif
1002#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001003 case METHOD_GPIO_730:
1004 reg += OMAP730_GPIO_INT_MASK;
1005 l = __raw_readl(reg);
1006 if (enable)
1007 l &= ~(gpio_mask);
1008 else
1009 l |= gpio_mask;
1010 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001011#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001012#ifdef CONFIG_ARCH_OMAP850
1013 case METHOD_GPIO_850:
1014 reg += OMAP850_GPIO_INT_MASK;
1015 l = __raw_readl(reg);
1016 if (enable)
1017 l &= ~(gpio_mask);
1018 else
1019 l |= gpio_mask;
1020 break;
1021#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301022#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001023 case METHOD_GPIO_24XX:
1024 if (enable)
1025 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1026 else
1027 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1028 l = gpio_mask;
1029 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001030#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301031#ifdef CONFIG_ARCH_OMAP4
1032 case METHOD_GPIO_24XX:
1033 if (enable)
1034 reg += OMAP4_GPIO_IRQSTATUSSET0;
1035 else
1036 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1037 l = gpio_mask;
1038 break;
1039#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001040 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001041 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001042 return;
1043 }
1044 __raw_writel(l, reg);
1045}
1046
1047static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1048{
1049 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1050}
1051
Tony Lindgren92105bb2005-09-07 17:20:26 +01001052/*
1053 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1054 * 1510 does not seem to have a wake-up register. If JTAG is connected
1055 * to the target, system will wake up always on GPIO events. While
1056 * system is running all registered GPIO interrupts need to have wake-up
1057 * enabled. When system is suspended, only selected GPIO interrupts need
1058 * to have wake-up enabled.
1059 */
1060static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1061{
David Brownella6472532008-03-03 04:33:30 -08001062 unsigned long flags;
1063
Tony Lindgren92105bb2005-09-07 17:20:26 +01001064 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001065#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001066 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001067 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001068 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001069 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001070 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001071 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001072 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001073 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001074 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001075#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001076#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1077 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001078 case METHOD_GPIO_24XX:
David Brownell11a78b72006-12-06 17:14:11 -08001079 if (bank->non_wakeup_gpios & (1 << gpio)) {
1080 printk(KERN_ERR "Unable to modify wakeup on "
1081 "non-wakeup GPIO%d\n",
1082 (bank - gpio_bank) * 32 + gpio);
1083 return -EINVAL;
1084 }
David Brownella6472532008-03-03 04:33:30 -08001085 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001086 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001087 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001088 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001089 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001090 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001091 return 0;
1092#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001093 default:
1094 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1095 bank->method);
1096 return -EINVAL;
1097 }
1098}
1099
Tony Lindgren4196dd62006-09-25 12:41:38 +03001100static void _reset_gpio(struct gpio_bank *bank, int gpio)
1101{
1102 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1103 _set_gpio_irqenable(bank, gpio, 0);
1104 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001105 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001106}
1107
Tony Lindgren92105bb2005-09-07 17:20:26 +01001108/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1109static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1110{
1111 unsigned int gpio = irq - IH_GPIO_BASE;
1112 struct gpio_bank *bank;
1113 int retval;
1114
1115 if (check_gpio(gpio) < 0)
1116 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001117 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001118 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001119
1120 return retval;
1121}
1122
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001123static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001124{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001125 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001126 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001127
David Brownella6472532008-03-03 04:33:30 -08001128 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001129
Tony Lindgren4196dd62006-09-25 12:41:38 +03001130 /* Set trigger to none. You need to enable the desired trigger with
1131 * request_irq() or set_irq_type().
1132 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001133 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001134
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001135#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001136 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001137 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001138
Tony Lindgren92105bb2005-09-07 17:20:26 +01001139 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001140 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001141 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001142 }
1143#endif
David Brownella6472532008-03-03 04:33:30 -08001144 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001145
1146 return 0;
1147}
1148
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001149static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001150{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001151 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001152 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001153
David Brownella6472532008-03-03 04:33:30 -08001154 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001155#ifdef CONFIG_ARCH_OMAP16XX
1156 if (bank->method == METHOD_GPIO_1610) {
1157 /* Disable wake-up during idle for dynamic tick */
1158 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001159 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001160 }
1161#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001162#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1163 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001164 if (bank->method == METHOD_GPIO_24XX) {
1165 /* Disable wake-up during idle for dynamic tick */
1166 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001167 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001168 }
1169#endif
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001170 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001171 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001172}
1173
1174/*
1175 * We need to unmask the GPIO bank interrupt as soon as possible to
1176 * avoid missing GPIO interrupts for other lines in the bank.
1177 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1178 * in the bank to avoid missing nested interrupts for a GPIO line.
1179 * If we wait to unmask individual GPIO lines in the bank after the
1180 * line's interrupt handler has been run, we may miss some nested
1181 * interrupts.
1182 */
Russell King10dd5ce2006-11-23 11:41:32 +00001183static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001184{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001185 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001186 u32 isr;
1187 unsigned int gpio_irq;
1188 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001189 u32 retrigger = 0;
1190 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001191
1192 desc->chip->ack(irq);
1193
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001194 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001195#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001196 if (bank->method == METHOD_MPUIO)
1197 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001198#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001199#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001200 if (bank->method == METHOD_GPIO_1510)
1201 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1202#endif
1203#if defined(CONFIG_ARCH_OMAP16XX)
1204 if (bank->method == METHOD_GPIO_1610)
1205 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1206#endif
1207#ifdef CONFIG_ARCH_OMAP730
1208 if (bank->method == METHOD_GPIO_730)
1209 isr_reg = bank->base + OMAP730_GPIO_INT_STATUS;
1210#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001211#ifdef CONFIG_ARCH_OMAP850
1212 if (bank->method == METHOD_GPIO_850)
1213 isr_reg = bank->base + OMAP850_GPIO_INT_STATUS;
1214#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301215#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001216 if (bank->method == METHOD_GPIO_24XX)
1217 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1218#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301219#if defined(CONFIG_ARCH_OMAP4)
1220 if (bank->method == METHOD_GPIO_24XX)
1221 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1222#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001223 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001224 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001225 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001226
Imre Deakea6dedd2006-06-26 16:16:00 -07001227 enabled = _get_gpio_irqbank_mask(bank);
1228 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001229
1230 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1231 isr &= 0x0000ffff;
1232
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001233 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001234 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001235 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001236
1237 /* clear edge sensitive interrupts before handler(s) are
1238 called so that we don't miss any interrupt occurred while
1239 executing them */
1240 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1241 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1242 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1243
1244 /* if there is only edge sensitive GPIO pin interrupts
1245 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001246 if (!level_mask && !unmasked) {
1247 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001248 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001249 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001250
Imre Deakea6dedd2006-06-26 16:16:00 -07001251 isr |= retrigger;
1252 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001253 if (!isr)
1254 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001255
Tony Lindgren92105bb2005-09-07 17:20:26 +01001256 gpio_irq = bank->virtual_irq_start;
1257 for (; isr != 0; isr >>= 1, gpio_irq++) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001258 if (!(isr & 1))
1259 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001260
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001261 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001262 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001263 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001264 /* if bank has any level sensitive GPIO pin interrupt
1265 configured, we must unmask the bank interrupt only after
1266 handler(s) are executed in order to avoid spurious bank
1267 interrupt */
1268 if (!unmasked)
1269 desc->chip->unmask(irq);
1270
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001271}
1272
Tony Lindgren4196dd62006-09-25 12:41:38 +03001273static void gpio_irq_shutdown(unsigned int irq)
1274{
1275 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001276 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001277
1278 _reset_gpio(bank, gpio);
1279}
1280
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001281static void gpio_ack_irq(unsigned int irq)
1282{
1283 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001284 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001285
1286 _clear_gpio_irqstatus(bank, gpio);
1287}
1288
1289static void gpio_mask_irq(unsigned int irq)
1290{
1291 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001292 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001293
1294 _set_gpio_irqenable(bank, gpio, 0);
1295}
1296
1297static void gpio_unmask_irq(unsigned int irq)
1298{
1299 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001300 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001301 unsigned int irq_mask = 1 << get_gpio_index(gpio);
1302
1303 /* For level-triggered GPIOs, the clearing must be done after
1304 * the HW source is cleared, thus after the handler has run */
1305 if (bank->level_mask & irq_mask) {
1306 _set_gpio_irqenable(bank, gpio, 0);
1307 _clear_gpio_irqstatus(bank, gpio);
1308 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001309
Kevin Hilman4de8c752008-01-16 21:56:14 -08001310 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001311}
1312
David Brownelle5c56ed2006-12-06 17:13:59 -08001313static struct irq_chip gpio_irq_chip = {
1314 .name = "GPIO",
1315 .shutdown = gpio_irq_shutdown,
1316 .ack = gpio_ack_irq,
1317 .mask = gpio_mask_irq,
1318 .unmask = gpio_unmask_irq,
1319 .set_type = gpio_irq_type,
1320 .set_wake = gpio_wake_enable,
1321};
1322
1323/*---------------------------------------------------------------------*/
1324
1325#ifdef CONFIG_ARCH_OMAP1
1326
1327/* MPUIO uses the always-on 32k clock */
1328
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001329static void mpuio_ack_irq(unsigned int irq)
1330{
1331 /* The ISR is reset automatically, so do nothing here. */
1332}
1333
1334static void mpuio_mask_irq(unsigned int irq)
1335{
1336 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001337 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001338
1339 _set_gpio_irqenable(bank, gpio, 0);
1340}
1341
1342static void mpuio_unmask_irq(unsigned int irq)
1343{
1344 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001345 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001346
1347 _set_gpio_irqenable(bank, gpio, 1);
1348}
1349
David Brownelle5c56ed2006-12-06 17:13:59 -08001350static struct irq_chip mpuio_irq_chip = {
1351 .name = "MPUIO",
1352 .ack = mpuio_ack_irq,
1353 .mask = mpuio_mask_irq,
1354 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001355 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001356#ifdef CONFIG_ARCH_OMAP16XX
1357 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1358 .set_wake = gpio_wake_enable,
1359#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001360};
1361
David Brownelle5c56ed2006-12-06 17:13:59 -08001362
1363#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1364
David Brownell11a78b72006-12-06 17:14:11 -08001365
1366#ifdef CONFIG_ARCH_OMAP16XX
1367
1368#include <linux/platform_device.h>
1369
1370static int omap_mpuio_suspend_late(struct platform_device *pdev, pm_message_t mesg)
1371{
1372 struct gpio_bank *bank = platform_get_drvdata(pdev);
1373 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001374 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001375
David Brownella6472532008-03-03 04:33:30 -08001376 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001377 bank->saved_wakeup = __raw_readl(mask_reg);
1378 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001379 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001380
1381 return 0;
1382}
1383
1384static int omap_mpuio_resume_early(struct platform_device *pdev)
1385{
1386 struct gpio_bank *bank = platform_get_drvdata(pdev);
1387 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001388 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001389
David Brownella6472532008-03-03 04:33:30 -08001390 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001391 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001392 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001393
1394 return 0;
1395}
1396
1397/* use platform_driver for this, now that there's no longer any
1398 * point to sys_device (other than not disturbing old code).
1399 */
1400static struct platform_driver omap_mpuio_driver = {
1401 .suspend_late = omap_mpuio_suspend_late,
1402 .resume_early = omap_mpuio_resume_early,
1403 .driver = {
1404 .name = "mpuio",
1405 },
1406};
1407
1408static struct platform_device omap_mpuio_device = {
1409 .name = "mpuio",
1410 .id = -1,
1411 .dev = {
1412 .driver = &omap_mpuio_driver.driver,
1413 }
1414 /* could list the /proc/iomem resources */
1415};
1416
1417static inline void mpuio_init(void)
1418{
David Brownellfcf126d2007-04-02 12:46:47 -07001419 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1420
David Brownell11a78b72006-12-06 17:14:11 -08001421 if (platform_driver_register(&omap_mpuio_driver) == 0)
1422 (void) platform_device_register(&omap_mpuio_device);
1423}
1424
1425#else
1426static inline void mpuio_init(void) {}
1427#endif /* 16xx */
1428
David Brownelle5c56ed2006-12-06 17:13:59 -08001429#else
1430
1431extern struct irq_chip mpuio_irq_chip;
1432
1433#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001434static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001435
1436#endif
1437
1438/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001439
David Brownell52e31342008-03-03 12:43:23 -08001440/* REVISIT these are stupid implementations! replace by ones that
1441 * don't switch on METHOD_* and which mostly avoid spinlocks
1442 */
1443
1444static int gpio_input(struct gpio_chip *chip, unsigned offset)
1445{
1446 struct gpio_bank *bank;
1447 unsigned long flags;
1448
1449 bank = container_of(chip, struct gpio_bank, chip);
1450 spin_lock_irqsave(&bank->lock, flags);
1451 _set_gpio_direction(bank, offset, 1);
1452 spin_unlock_irqrestore(&bank->lock, flags);
1453 return 0;
1454}
1455
1456static int gpio_get(struct gpio_chip *chip, unsigned offset)
1457{
David Brownell0b84b5c2008-12-10 17:35:25 -08001458 return __omap_get_gpio_datain(chip->base + offset);
David Brownell52e31342008-03-03 12:43:23 -08001459}
1460
1461static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1462{
1463 struct gpio_bank *bank;
1464 unsigned long flags;
1465
1466 bank = container_of(chip, struct gpio_bank, chip);
1467 spin_lock_irqsave(&bank->lock, flags);
1468 _set_gpio_dataout(bank, offset, value);
1469 _set_gpio_direction(bank, offset, 0);
1470 spin_unlock_irqrestore(&bank->lock, flags);
1471 return 0;
1472}
1473
1474static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1475{
1476 struct gpio_bank *bank;
1477 unsigned long flags;
1478
1479 bank = container_of(chip, struct gpio_bank, chip);
1480 spin_lock_irqsave(&bank->lock, flags);
1481 _set_gpio_dataout(bank, offset, value);
1482 spin_unlock_irqrestore(&bank->lock, flags);
1483}
1484
David Brownella007b702008-12-10 17:35:25 -08001485static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1486{
1487 struct gpio_bank *bank;
1488
1489 bank = container_of(chip, struct gpio_bank, chip);
1490 return bank->virtual_irq_start + offset;
1491}
1492
David Brownell52e31342008-03-03 12:43:23 -08001493/*---------------------------------------------------------------------*/
1494
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001495static int initialized;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001496#if !(defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001497static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001498#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001499
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001500#if defined(CONFIG_ARCH_OMAP2)
1501static struct clk * gpio_fck;
1502#endif
1503
1504#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001505static struct clk * gpio5_ick;
1506static struct clk * gpio5_fck;
1507#endif
1508
Santosh Shilimkar44169072009-05-28 14:16:04 -07001509#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001510static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1511#endif
1512
David Brownell8ba55c52008-02-26 11:10:50 -08001513/* This lock class tells lockdep that GPIO irqs are in a different
1514 * category than their parents, so it won't report false recursion.
1515 */
1516static struct lock_class_key gpio_lock_class;
1517
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001518static int __init _omap_gpio_init(void)
1519{
1520 int i;
David Brownell52e31342008-03-03 12:43:23 -08001521 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001522 struct gpio_bank *bank;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001523 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001524
1525 initialized = 1;
1526
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001527#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001528 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001529 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1530 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001531 printk("Could not get arm_gpio_ck\n");
1532 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001533 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001534 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001535#endif
1536#if defined(CONFIG_ARCH_OMAP2)
1537 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001538 gpio_ick = clk_get(NULL, "gpios_ick");
1539 if (IS_ERR(gpio_ick))
1540 printk("Could not get gpios_ick\n");
1541 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001542 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001543 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001544 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001545 printk("Could not get gpios_fck\n");
1546 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001547 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001548
1549 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001550 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001551 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001552#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001553 if (cpu_is_omap2430()) {
1554 gpio5_ick = clk_get(NULL, "gpio5_ick");
1555 if (IS_ERR(gpio5_ick))
1556 printk("Could not get gpio5_ick\n");
1557 else
1558 clk_enable(gpio5_ick);
1559 gpio5_fck = clk_get(NULL, "gpio5_fck");
1560 if (IS_ERR(gpio5_fck))
1561 printk("Could not get gpio5_fck\n");
1562 else
1563 clk_enable(gpio5_fck);
1564 }
1565#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001566 }
1567#endif
1568
Santosh Shilimkar44169072009-05-28 14:16:04 -07001569#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1570 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001571 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1572 sprintf(clk_name, "gpio%d_ick", i + 1);
1573 gpio_iclks[i] = clk_get(NULL, clk_name);
1574 if (IS_ERR(gpio_iclks[i]))
1575 printk(KERN_ERR "Could not get %s\n", clk_name);
1576 else
1577 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001578 }
1579 }
1580#endif
1581
Tony Lindgren92105bb2005-09-07 17:20:26 +01001582
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001583#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001584 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001585 printk(KERN_INFO "OMAP1510 GPIO hardware\n");
1586 gpio_bank_count = 2;
1587 gpio_bank = gpio_bank_1510;
1588 }
1589#endif
1590#if defined(CONFIG_ARCH_OMAP16XX)
1591 if (cpu_is_omap16xx()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001592 u32 rev;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001593
1594 gpio_bank_count = 5;
1595 gpio_bank = gpio_bank_1610;
Russell King7c7095a2008-09-05 15:49:14 +01001596 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001597 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1598 (rev >> 4) & 0x0f, rev & 0x0f);
1599 }
1600#endif
1601#ifdef CONFIG_ARCH_OMAP730
1602 if (cpu_is_omap730()) {
1603 printk(KERN_INFO "OMAP730 GPIO hardware\n");
1604 gpio_bank_count = 7;
1605 gpio_bank = gpio_bank_730;
1606 }
1607#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001608#ifdef CONFIG_ARCH_OMAP850
1609 if (cpu_is_omap850()) {
1610 printk(KERN_INFO "OMAP850 GPIO hardware\n");
1611 gpio_bank_count = 7;
1612 gpio_bank = gpio_bank_850;
1613 }
1614#endif
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001615
Tony Lindgren92105bb2005-09-07 17:20:26 +01001616#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001617 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001618 int rev;
1619
1620 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001621 gpio_bank = gpio_bank_242x;
Russell King7c7095a2008-09-05 15:49:14 +01001622 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001623 printk(KERN_INFO "OMAP242x GPIO hardware version %d.%d\n",
1624 (rev >> 4) & 0x0f, rev & 0x0f);
1625 }
1626 if (cpu_is_omap243x()) {
1627 int rev;
1628
1629 gpio_bank_count = 5;
1630 gpio_bank = gpio_bank_243x;
Russell King7c7095a2008-09-05 15:49:14 +01001631 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001632 printk(KERN_INFO "OMAP243x GPIO hardware version %d.%d\n",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001633 (rev >> 4) & 0x0f, rev & 0x0f);
1634 }
1635#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001636#ifdef CONFIG_ARCH_OMAP34XX
1637 if (cpu_is_omap34xx()) {
1638 int rev;
1639
1640 gpio_bank_count = OMAP34XX_NR_GPIOS;
1641 gpio_bank = gpio_bank_34xx;
Russell King7c7095a2008-09-05 15:49:14 +01001642 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001643 printk(KERN_INFO "OMAP34xx GPIO hardware version %d.%d\n",
1644 (rev >> 4) & 0x0f, rev & 0x0f);
1645 }
1646#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001647#ifdef CONFIG_ARCH_OMAP4
1648 if (cpu_is_omap44xx()) {
1649 int rev;
1650
1651 gpio_bank_count = OMAP34XX_NR_GPIOS;
1652 gpio_bank = gpio_bank_44xx;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301653 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
Santosh Shilimkar44169072009-05-28 14:16:04 -07001654 printk(KERN_INFO "OMAP44xx GPIO hardware version %d.%d\n",
1655 (rev >> 4) & 0x0f, rev & 0x0f);
1656 }
1657#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001658 for (i = 0; i < gpio_bank_count; i++) {
1659 int j, gpio_count = 16;
1660
1661 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001662 spin_lock_init(&bank->lock);
David Brownelle5c56ed2006-12-06 17:13:59 -08001663 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001664 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001665 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001666 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1667 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1668 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001669 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001670 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1671 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001672 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001673 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001674 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_730) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001675 __raw_writel(0xffffffff, bank->base + OMAP730_GPIO_INT_MASK);
1676 __raw_writel(0x00000000, bank->base + OMAP730_GPIO_INT_STATUS);
1677
1678 gpio_count = 32; /* 730 has 32-bit GPIOs */
1679 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001680
Santosh Shilimkar44169072009-05-28 14:16:04 -07001681#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1682 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001683 if (bank->method == METHOD_GPIO_24XX) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001684 static const u32 non_wakeup_gpios[] = {
1685 0xe203ffc0, 0x08700040
1686 };
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301687 if (cpu_is_omap44xx()) {
1688 __raw_writel(0xffffffff, bank->base +
1689 OMAP4_GPIO_IRQSTATUSCLR0);
1690 __raw_writew(0x0015, bank->base +
1691 OMAP4_GPIO_SYSCONFIG);
1692 __raw_writel(0x00000000, bank->base +
1693 OMAP4_GPIO_DEBOUNCENABLE);
1694 /* Initialize interface clock ungated, module enabled */
1695 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1696 } else {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001697 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1698 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001699 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
janboecb5793d2009-06-23 13:30:25 +03001700 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_DEBOUNCE_EN);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001701
1702 /* Initialize interface clock ungated, module enabled */
1703 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301704 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001705 if (i < ARRAY_SIZE(non_wakeup_gpios))
1706 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001707 gpio_count = 32;
1708 }
1709#endif
David Brownell52e31342008-03-03 12:43:23 -08001710 /* REVISIT eventually switch from OMAP-specific gpio structs
1711 * over to the generic ones
1712 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001713 bank->chip.request = omap_gpio_request;
1714 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001715 bank->chip.direction_input = gpio_input;
1716 bank->chip.get = gpio_get;
1717 bank->chip.direction_output = gpio_output;
1718 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001719 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001720 if (bank_is_mpuio(bank)) {
1721 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001722#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001723 bank->chip.dev = &omap_mpuio_device.dev;
1724#endif
David Brownell52e31342008-03-03 12:43:23 -08001725 bank->chip.base = OMAP_MPUIO(0);
1726 } else {
1727 bank->chip.label = "gpio";
1728 bank->chip.base = gpio;
1729 gpio += gpio_count;
1730 }
1731 bank->chip.ngpio = gpio_count;
1732
1733 gpiochip_add(&bank->chip);
1734
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001735 for (j = bank->virtual_irq_start;
1736 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001737 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001738 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001739 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001740 set_irq_chip(j, &mpuio_irq_chip);
1741 else
1742 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001743 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001744 set_irq_flags(j, IRQF_VALID);
1745 }
1746 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1747 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001748
Santosh Shilimkar44169072009-05-28 14:16:04 -07001749 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001750 sprintf(clk_name, "gpio%d_dbck", i + 1);
1751 bank->dbck = clk_get(NULL, clk_name);
1752 if (IS_ERR(bank->dbck))
1753 printk(KERN_ERR "Could not get %s\n", clk_name);
1754 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001755 }
1756
1757 /* Enable system clock for GPIO module.
1758 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001759 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001760 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1761
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001762 /* Enable autoidle for the OCP interface */
1763 if (cpu_is_omap24xx())
1764 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001765 if (cpu_is_omap34xx())
1766 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001767
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001768 return 0;
1769}
1770
Santosh Shilimkar44169072009-05-28 14:16:04 -07001771#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1772 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001773static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1774{
1775 int i;
1776
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001777 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001778 return 0;
1779
1780 for (i = 0; i < gpio_bank_count; i++) {
1781 struct gpio_bank *bank = &gpio_bank[i];
1782 void __iomem *wake_status;
1783 void __iomem *wake_clear;
1784 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001785 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001786
1787 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001788#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001789 case METHOD_GPIO_1610:
1790 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1791 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1792 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1793 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001794#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301795#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001796 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001797 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001798 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1799 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1800 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001801#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301802#ifdef CONFIG_ARCH_OMAP4
1803 case METHOD_GPIO_24XX:
1804 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1805 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1806 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1807 break;
1808#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001809 default:
1810 continue;
1811 }
1812
David Brownella6472532008-03-03 04:33:30 -08001813 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001814 bank->saved_wakeup = __raw_readl(wake_status);
1815 __raw_writel(0xffffffff, wake_clear);
1816 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001817 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001818 }
1819
1820 return 0;
1821}
1822
1823static int omap_gpio_resume(struct sys_device *dev)
1824{
1825 int i;
1826
Tero Kristo723fdb72008-11-26 14:35:16 -08001827 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001828 return 0;
1829
1830 for (i = 0; i < gpio_bank_count; i++) {
1831 struct gpio_bank *bank = &gpio_bank[i];
1832 void __iomem *wake_clear;
1833 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001834 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001835
1836 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001837#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001838 case METHOD_GPIO_1610:
1839 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1840 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1841 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001842#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301843#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001844 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001845 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1846 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001847 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001848#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301849#ifdef CONFIG_ARCH_OMAP4
1850 case METHOD_GPIO_24XX:
1851 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1852 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1853 break;
1854#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001855 default:
1856 continue;
1857 }
1858
David Brownella6472532008-03-03 04:33:30 -08001859 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001860 __raw_writel(0xffffffff, wake_clear);
1861 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001862 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001863 }
1864
1865 return 0;
1866}
1867
1868static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01001869 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001870 .suspend = omap_gpio_suspend,
1871 .resume = omap_gpio_resume,
1872};
1873
1874static struct sys_device omap_gpio_device = {
1875 .id = 0,
1876 .cls = &omap_gpio_sysclass,
1877};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001878
1879#endif
1880
Santosh Shilimkar44169072009-05-28 14:16:04 -07001881#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1882 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001883
1884static int workaround_enabled;
1885
1886void omap2_gpio_prepare_for_retention(void)
1887{
1888 int i, c = 0;
1889
1890 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
1891 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
1892 for (i = 0; i < gpio_bank_count; i++) {
1893 struct gpio_bank *bank = &gpio_bank[i];
1894 u32 l1, l2;
1895
1896 if (!(bank->enabled_non_wakeup_gpios))
1897 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301898#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001899 bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1900 l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1901 l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001902#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301903#ifdef CONFIG_ARCH_OMAP4
1904 bank->saved_datain = __raw_readl(bank->base +
1905 OMAP4_GPIO_DATAIN);
1906 l1 = __raw_readl(bank->base + OMAP4_GPIO_FALLINGDETECT);
1907 l2 = __raw_readl(bank->base + OMAP4_GPIO_RISINGDETECT);
1908#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001909 bank->saved_fallingdetect = l1;
1910 bank->saved_risingdetect = l2;
1911 l1 &= ~bank->enabled_non_wakeup_gpios;
1912 l2 &= ~bank->enabled_non_wakeup_gpios;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301913#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001914 __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1915 __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001916#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301917#ifdef CONFIG_ARCH_OMAP4
1918 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
1919 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
1920#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001921 c++;
1922 }
1923 if (!c) {
1924 workaround_enabled = 0;
1925 return;
1926 }
1927 workaround_enabled = 1;
1928}
1929
1930void omap2_gpio_resume_after_retention(void)
1931{
1932 int i;
1933
1934 if (!workaround_enabled)
1935 return;
1936 for (i = 0; i < gpio_bank_count; i++) {
1937 struct gpio_bank *bank = &gpio_bank[i];
1938 u32 l;
1939
1940 if (!(bank->enabled_non_wakeup_gpios))
1941 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301942#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001943 __raw_writel(bank->saved_fallingdetect,
1944 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1945 __raw_writel(bank->saved_risingdetect,
1946 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301947 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1948#endif
1949#ifdef CONFIG_ARCH_OMAP4
1950 __raw_writel(bank->saved_fallingdetect,
1951 bank->base + OMAP4_GPIO_FALLINGDETECT);
1952 __raw_writel(bank->saved_risingdetect,
1953 bank->base + OMAP4_GPIO_RISINGDETECT);
1954 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001955#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001956 /* Check if any of the non-wakeup interrupt GPIOs have changed
1957 * state. If so, generate an IRQ by software. This is
1958 * horribly racy, but it's the best we can do to work around
1959 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001960 l ^= bank->saved_datain;
1961 l &= bank->non_wakeup_gpios;
1962 if (l) {
1963 u32 old0, old1;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301964#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001965 old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1966 old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
1967 __raw_writel(old0 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1968 __raw_writel(old1 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
1969 __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1970 __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001971#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301972#ifdef CONFIG_ARCH_OMAP4
1973 old0 = __raw_readl(bank->base +
1974 OMAP4_GPIO_LEVELDETECT0);
1975 old1 = __raw_readl(bank->base +
1976 OMAP4_GPIO_LEVELDETECT1);
1977 __raw_writel(old0 | l, bank->base +
1978 OMAP4_GPIO_LEVELDETECT0);
1979 __raw_writel(old1 | l, bank->base +
1980 OMAP4_GPIO_LEVELDETECT1);
1981 __raw_writel(old0, bank->base +
1982 OMAP4_GPIO_LEVELDETECT0);
1983 __raw_writel(old1, bank->base +
1984 OMAP4_GPIO_LEVELDETECT1);
1985#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001986 }
1987 }
1988
1989}
1990
Tony Lindgren92105bb2005-09-07 17:20:26 +01001991#endif
1992
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001993/*
1994 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001995 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001996 */
David Brownell277d58e2006-12-06 17:13:59 -08001997int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001998{
1999 if (!initialized)
2000 return _omap_gpio_init();
2001 else
2002 return 0;
2003}
2004
Tony Lindgren92105bb2005-09-07 17:20:26 +01002005static int __init omap_gpio_sysinit(void)
2006{
2007 int ret = 0;
2008
2009 if (!initialized)
2010 ret = _omap_gpio_init();
2011
David Brownell11a78b72006-12-06 17:14:11 -08002012 mpuio_init();
2013
Santosh Shilimkar44169072009-05-28 14:16:04 -07002014#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
2015 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002016 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002017 if (ret == 0) {
2018 ret = sysdev_class_register(&omap_gpio_sysclass);
2019 if (ret == 0)
2020 ret = sysdev_register(&omap_gpio_device);
2021 }
2022 }
2023#endif
2024
2025 return ret;
2026}
2027
Tony Lindgren92105bb2005-09-07 17:20:26 +01002028arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002029
2030
2031#ifdef CONFIG_DEBUG_FS
2032
2033#include <linux/debugfs.h>
2034#include <linux/seq_file.h>
2035
2036static int gpio_is_input(struct gpio_bank *bank, int mask)
2037{
2038 void __iomem *reg = bank->base;
2039
2040 switch (bank->method) {
2041 case METHOD_MPUIO:
2042 reg += OMAP_MPUIO_IO_CNTL;
2043 break;
2044 case METHOD_GPIO_1510:
2045 reg += OMAP1510_GPIO_DIR_CONTROL;
2046 break;
2047 case METHOD_GPIO_1610:
2048 reg += OMAP1610_GPIO_DIRECTION;
2049 break;
2050 case METHOD_GPIO_730:
2051 reg += OMAP730_GPIO_DIR_CONTROL;
2052 break;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07002053 case METHOD_GPIO_850:
2054 reg += OMAP850_GPIO_DIR_CONTROL;
2055 break;
David Brownellb9772a22006-12-06 17:13:53 -08002056 case METHOD_GPIO_24XX:
2057 reg += OMAP24XX_GPIO_OE;
2058 break;
2059 }
2060 return __raw_readl(reg) & mask;
2061}
2062
2063
2064static int dbg_gpio_show(struct seq_file *s, void *unused)
2065{
2066 unsigned i, j, gpio;
2067
2068 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2069 struct gpio_bank *bank = gpio_bank + i;
2070 unsigned bankwidth = 16;
2071 u32 mask = 1;
2072
David Brownelle5c56ed2006-12-06 17:13:59 -08002073 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002074 gpio = OMAP_MPUIO(0);
Zebediah C. McClure56739a62009-03-23 18:07:40 -07002075 else if (cpu_class_is_omap2() || cpu_is_omap730() ||
2076 cpu_is_omap850())
David Brownellb9772a22006-12-06 17:13:53 -08002077 bankwidth = 32;
2078
2079 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2080 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002081 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002082
David Brownell52e31342008-03-03 12:43:23 -08002083 label = gpiochip_is_requested(&bank->chip, j);
2084 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002085 continue;
2086
2087 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002088 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002089 is_in = gpio_is_input(bank, mask);
2090
David Brownelle5c56ed2006-12-06 17:13:59 -08002091 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002092 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002093 else
David Brownell52e31342008-03-03 12:43:23 -08002094 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002095 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002096 label,
David Brownellb9772a22006-12-06 17:13:53 -08002097 is_in ? "in " : "out",
2098 value ? "hi" : "lo");
2099
David Brownell52e31342008-03-03 12:43:23 -08002100/* FIXME for at least omap2, show pullup/pulldown state */
2101
David Brownellb9772a22006-12-06 17:13:53 -08002102 irqstat = irq_desc[irq].status;
Tony Lindgren3a26e332009-01-15 13:09:53 +02002103#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07002104 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
David Brownellb9772a22006-12-06 17:13:53 -08002105 if (is_in && ((bank->suspend_wakeup & mask)
2106 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2107 char *trigger = NULL;
2108
2109 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2110 case IRQ_TYPE_EDGE_FALLING:
2111 trigger = "falling";
2112 break;
2113 case IRQ_TYPE_EDGE_RISING:
2114 trigger = "rising";
2115 break;
2116 case IRQ_TYPE_EDGE_BOTH:
2117 trigger = "bothedge";
2118 break;
2119 case IRQ_TYPE_LEVEL_LOW:
2120 trigger = "low";
2121 break;
2122 case IRQ_TYPE_LEVEL_HIGH:
2123 trigger = "high";
2124 break;
2125 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002126 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002127 break;
2128 }
David Brownell52e31342008-03-03 12:43:23 -08002129 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002130 irq, trigger,
2131 (bank->suspend_wakeup & mask)
2132 ? " wakeup" : "");
2133 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002134#endif
David Brownellb9772a22006-12-06 17:13:53 -08002135 seq_printf(s, "\n");
2136 }
2137
David Brownelle5c56ed2006-12-06 17:13:59 -08002138 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002139 seq_printf(s, "\n");
2140 gpio = 0;
2141 }
2142 }
2143 return 0;
2144}
2145
2146static int dbg_gpio_open(struct inode *inode, struct file *file)
2147{
David Brownelle5c56ed2006-12-06 17:13:59 -08002148 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002149}
2150
2151static const struct file_operations debug_fops = {
2152 .open = dbg_gpio_open,
2153 .read = seq_read,
2154 .llseek = seq_lseek,
2155 .release = single_release,
2156};
2157
2158static int __init omap_gpio_debuginit(void)
2159{
David Brownelle5c56ed2006-12-06 17:13:59 -08002160 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2161 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002162 return 0;
2163}
2164late_initcall(omap_gpio_debuginit);
2165#endif