blob: 35a59ce5a2b47ddfe60238b63f7dc0dd4d20dc34 [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
2 * linux/arch/arm/plat-omap/gpio.c
3 *
4 * Support functions for OMAP GPIO
5 *
Tony Lindgren92105bb2005-09-07 17:20:26 +01006 * Copyright (C) 2003-2005 Nokia Corporation
Jan Engelhardt96de0e22007-10-19 23:21:04 +02007 * Written by Juha Yrjölä <juha.yrjola@nokia.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01008 *
Santosh Shilimkar44169072009-05-28 14:16:04 -07009 * Copyright (C) 2009 Texas Instruments
10 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
11 *
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010017#include <linux/init.h>
18#include <linux/module.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010019#include <linux/interrupt.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010020#include <linux/sysdev.h>
21#include <linux/err.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000022#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010024
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010026#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/irqs.h>
28#include <mach/gpio.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010029#include <asm/mach/irq.h>
30
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010031/*
32 * OMAP1510 GPIO registers
33 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070034#define OMAP1510_GPIO_BASE 0xfffce000
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010035#define OMAP1510_GPIO_DATA_INPUT 0x00
36#define OMAP1510_GPIO_DATA_OUTPUT 0x04
37#define OMAP1510_GPIO_DIR_CONTROL 0x08
38#define OMAP1510_GPIO_INT_CONTROL 0x0c
39#define OMAP1510_GPIO_INT_MASK 0x10
40#define OMAP1510_GPIO_INT_STATUS 0x14
41#define OMAP1510_GPIO_PIN_CONTROL 0x18
42
43#define OMAP1510_IH_GPIO_BASE 64
44
45/*
46 * OMAP1610 specific GPIO registers
47 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070048#define OMAP1610_GPIO1_BASE 0xfffbe400
49#define OMAP1610_GPIO2_BASE 0xfffbec00
50#define OMAP1610_GPIO3_BASE 0xfffbb400
51#define OMAP1610_GPIO4_BASE 0xfffbbc00
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010052#define OMAP1610_GPIO_REVISION 0x0000
53#define OMAP1610_GPIO_SYSCONFIG 0x0010
54#define OMAP1610_GPIO_SYSSTATUS 0x0014
55#define OMAP1610_GPIO_IRQSTATUS1 0x0018
56#define OMAP1610_GPIO_IRQENABLE1 0x001c
Tony Lindgren92105bb2005-09-07 17:20:26 +010057#define OMAP1610_GPIO_WAKEUPENABLE 0x0028
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010058#define OMAP1610_GPIO_DATAIN 0x002c
59#define OMAP1610_GPIO_DATAOUT 0x0030
60#define OMAP1610_GPIO_DIRECTION 0x0034
61#define OMAP1610_GPIO_EDGE_CTRL1 0x0038
62#define OMAP1610_GPIO_EDGE_CTRL2 0x003c
63#define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
Tony Lindgren92105bb2005-09-07 17:20:26 +010064#define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010065#define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
66#define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
Tony Lindgren92105bb2005-09-07 17:20:26 +010067#define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010068#define OMAP1610_GPIO_SET_DATAOUT 0x00f0
69
70/*
Alistair Buxton7c006922009-09-22 10:02:58 +010071 * OMAP7XX specific GPIO registers
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010072 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070073#define OMAP7XX_GPIO1_BASE 0xfffbc000
74#define OMAP7XX_GPIO2_BASE 0xfffbc800
75#define OMAP7XX_GPIO3_BASE 0xfffbd000
76#define OMAP7XX_GPIO4_BASE 0xfffbd800
77#define OMAP7XX_GPIO5_BASE 0xfffbe000
78#define OMAP7XX_GPIO6_BASE 0xfffbe800
Alistair Buxton7c006922009-09-22 10:02:58 +010079#define OMAP7XX_GPIO_DATA_INPUT 0x00
80#define OMAP7XX_GPIO_DATA_OUTPUT 0x04
81#define OMAP7XX_GPIO_DIR_CONTROL 0x08
82#define OMAP7XX_GPIO_INT_CONTROL 0x0c
83#define OMAP7XX_GPIO_INT_MASK 0x10
84#define OMAP7XX_GPIO_INT_STATUS 0x14
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010085
Tony Lindgren9f7065d2009-10-19 15:25:20 -070086#define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE
Tony Lindgren94113262009-08-28 10:50:33 -070087
Zebediah C. McClure56739a62009-03-23 18:07:40 -070088/*
Tony Lindgren92105bb2005-09-07 17:20:26 +010089 * omap24xx specific GPIO registers
90 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -070091#define OMAP242X_GPIO1_BASE 0x48018000
92#define OMAP242X_GPIO2_BASE 0x4801a000
93#define OMAP242X_GPIO3_BASE 0x4801c000
94#define OMAP242X_GPIO4_BASE 0x4801e000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -080095
Tony Lindgren9f7065d2009-10-19 15:25:20 -070096#define OMAP243X_GPIO1_BASE 0x4900C000
97#define OMAP243X_GPIO2_BASE 0x4900E000
98#define OMAP243X_GPIO3_BASE 0x49010000
99#define OMAP243X_GPIO4_BASE 0x49012000
100#define OMAP243X_GPIO5_BASE 0x480B6000
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800101
Tony Lindgren92105bb2005-09-07 17:20:26 +0100102#define OMAP24XX_GPIO_REVISION 0x0000
103#define OMAP24XX_GPIO_SYSCONFIG 0x0010
104#define OMAP24XX_GPIO_SYSSTATUS 0x0014
105#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300106#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
107#define OMAP24XX_GPIO_IRQENABLE2 0x002c
Tony Lindgren92105bb2005-09-07 17:20:26 +0100108#define OMAP24XX_GPIO_IRQENABLE1 0x001c
Tero Kristo723fdb72008-11-26 14:35:16 -0800109#define OMAP24XX_GPIO_WAKE_EN 0x0020
Tony Lindgren92105bb2005-09-07 17:20:26 +0100110#define OMAP24XX_GPIO_CTRL 0x0030
111#define OMAP24XX_GPIO_OE 0x0034
112#define OMAP24XX_GPIO_DATAIN 0x0038
113#define OMAP24XX_GPIO_DATAOUT 0x003c
114#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
115#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
116#define OMAP24XX_GPIO_RISINGDETECT 0x0048
117#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700118#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
119#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
Tony Lindgren92105bb2005-09-07 17:20:26 +0100120#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
121#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
122#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
123#define OMAP24XX_GPIO_SETWKUENA 0x0084
124#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
125#define OMAP24XX_GPIO_SETDATAOUT 0x0094
126
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530127#define OMAP4_GPIO_REVISION 0x0000
128#define OMAP4_GPIO_SYSCONFIG 0x0010
129#define OMAP4_GPIO_EOI 0x0020
130#define OMAP4_GPIO_IRQSTATUSRAW0 0x0024
131#define OMAP4_GPIO_IRQSTATUSRAW1 0x0028
132#define OMAP4_GPIO_IRQSTATUS0 0x002c
133#define OMAP4_GPIO_IRQSTATUS1 0x0030
134#define OMAP4_GPIO_IRQSTATUSSET0 0x0034
135#define OMAP4_GPIO_IRQSTATUSSET1 0x0038
136#define OMAP4_GPIO_IRQSTATUSCLR0 0x003c
137#define OMAP4_GPIO_IRQSTATUSCLR1 0x0040
138#define OMAP4_GPIO_IRQWAKEN0 0x0044
139#define OMAP4_GPIO_IRQWAKEN1 0x0048
140#define OMAP4_GPIO_SYSSTATUS 0x0104
141#define OMAP4_GPIO_CTRL 0x0130
142#define OMAP4_GPIO_OE 0x0134
143#define OMAP4_GPIO_DATAIN 0x0138
144#define OMAP4_GPIO_DATAOUT 0x013c
145#define OMAP4_GPIO_LEVELDETECT0 0x0140
146#define OMAP4_GPIO_LEVELDETECT1 0x0144
147#define OMAP4_GPIO_RISINGDETECT 0x0148
148#define OMAP4_GPIO_FALLINGDETECT 0x014c
149#define OMAP4_GPIO_DEBOUNCENABLE 0x0150
150#define OMAP4_GPIO_DEBOUNCINGTIME 0x0154
151#define OMAP4_GPIO_CLEARDATAOUT 0x0190
152#define OMAP4_GPIO_SETDATAOUT 0x0194
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800153/*
154 * omap34xx specific GPIO registers
155 */
156
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700157#define OMAP34XX_GPIO1_BASE 0x48310000
158#define OMAP34XX_GPIO2_BASE 0x49050000
159#define OMAP34XX_GPIO3_BASE 0x49052000
160#define OMAP34XX_GPIO4_BASE 0x49054000
161#define OMAP34XX_GPIO5_BASE 0x49056000
162#define OMAP34XX_GPIO6_BASE 0x49058000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800163
Santosh Shilimkar44169072009-05-28 14:16:04 -0700164/*
165 * OMAP44XX specific GPIO registers
166 */
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700167#define OMAP44XX_GPIO1_BASE 0x4a310000
168#define OMAP44XX_GPIO2_BASE 0x48055000
169#define OMAP44XX_GPIO3_BASE 0x48057000
170#define OMAP44XX_GPIO4_BASE 0x48059000
171#define OMAP44XX_GPIO5_BASE 0x4805B000
172#define OMAP44XX_GPIO6_BASE 0x4805D000
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800173
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100174struct gpio_bank {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700175 unsigned long pbase;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100176 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100177 u16 irq;
178 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100179 int method;
Santosh Shilimkar44169072009-05-28 14:16:04 -0700180#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
181 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100182 u32 suspend_wakeup;
183 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800184#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700185#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
186 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800187 u32 non_wakeup_gpios;
188 u32 enabled_non_wakeup_gpios;
189
190 u32 saved_datain;
191 u32 saved_fallingdetect;
192 u32 saved_risingdetect;
193#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800194 u32 level_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100195 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800196 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800197 struct clk *dbck;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100198};
199
200#define METHOD_MPUIO 0
201#define METHOD_GPIO_1510 1
202#define METHOD_GPIO_1610 2
Alistair Buxton7c006922009-09-22 10:02:58 +0100203#define METHOD_GPIO_7XX 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700204#define METHOD_GPIO_24XX 5
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100205
Tony Lindgren92105bb2005-09-07 17:20:26 +0100206#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100207static struct gpio_bank gpio_bank_1610[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700208 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
209 METHOD_MPUIO },
210 { OMAP1610_GPIO1_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
211 METHOD_GPIO_1610 },
212 { OMAP1610_GPIO2_BASE, NULL, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16,
213 METHOD_GPIO_1610 },
214 { OMAP1610_GPIO3_BASE, NULL, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32,
215 METHOD_GPIO_1610 },
216 { OMAP1610_GPIO4_BASE, NULL, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48,
217 METHOD_GPIO_1610 },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100218};
219#endif
220
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000221#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100222static struct gpio_bank gpio_bank_1510[2] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700223 { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE,
224 METHOD_MPUIO },
225 { OMAP1510_GPIO_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE,
226 METHOD_GPIO_1510 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100227};
228#endif
229
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100230#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100231static struct gpio_bank gpio_bank_7xx[7] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700232 { OMAP1_MPUIO_VBASE, NULL, INT_7XX_MPUIO, IH_MPUIO_BASE,
233 METHOD_MPUIO },
234 { OMAP7XX_GPIO1_BASE, NULL, INT_7XX_GPIO_BANK1, IH_GPIO_BASE,
235 METHOD_GPIO_7XX },
236 { OMAP7XX_GPIO2_BASE, NULL, INT_7XX_GPIO_BANK2, IH_GPIO_BASE + 32,
237 METHOD_GPIO_7XX },
238 { OMAP7XX_GPIO3_BASE, NULL, INT_7XX_GPIO_BANK3, IH_GPIO_BASE + 64,
239 METHOD_GPIO_7XX },
240 { OMAP7XX_GPIO4_BASE, NULL, INT_7XX_GPIO_BANK4, IH_GPIO_BASE + 96,
241 METHOD_GPIO_7XX },
242 { OMAP7XX_GPIO5_BASE, NULL, INT_7XX_GPIO_BANK5, IH_GPIO_BASE + 128,
243 METHOD_GPIO_7XX },
244 { OMAP7XX_GPIO6_BASE, NULL, INT_7XX_GPIO_BANK6, IH_GPIO_BASE + 160,
245 METHOD_GPIO_7XX },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100246};
247#endif
248
Tony Lindgren92105bb2005-09-07 17:20:26 +0100249#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800250
251static struct gpio_bank gpio_bank_242x[4] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700252 { OMAP242X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
253 METHOD_GPIO_24XX },
254 { OMAP242X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
255 METHOD_GPIO_24XX },
256 { OMAP242X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
257 METHOD_GPIO_24XX },
258 { OMAP242X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
259 METHOD_GPIO_24XX },
Tony Lindgren92105bb2005-09-07 17:20:26 +0100260};
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800261
262static struct gpio_bank gpio_bank_243x[5] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700263 { OMAP243X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE,
264 METHOD_GPIO_24XX },
265 { OMAP243X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32,
266 METHOD_GPIO_24XX },
267 { OMAP243X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64,
268 METHOD_GPIO_24XX },
269 { OMAP243X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96,
270 METHOD_GPIO_24XX },
271 { OMAP243X_GPIO5_BASE, NULL, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128,
272 METHOD_GPIO_24XX },
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800273};
274
Tony Lindgren92105bb2005-09-07 17:20:26 +0100275#endif
276
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800277#ifdef CONFIG_ARCH_OMAP34XX
278static struct gpio_bank gpio_bank_34xx[6] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700279 { OMAP34XX_GPIO1_BASE, NULL, INT_34XX_GPIO_BANK1, IH_GPIO_BASE,
280 METHOD_GPIO_24XX },
281 { OMAP34XX_GPIO2_BASE, NULL, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32,
282 METHOD_GPIO_24XX },
283 { OMAP34XX_GPIO3_BASE, NULL, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64,
284 METHOD_GPIO_24XX },
285 { OMAP34XX_GPIO4_BASE, NULL, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96,
286 METHOD_GPIO_24XX },
287 { OMAP34XX_GPIO5_BASE, NULL, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128,
288 METHOD_GPIO_24XX },
289 { OMAP34XX_GPIO6_BASE, NULL, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160,
290 METHOD_GPIO_24XX },
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800291};
292
293#endif
294
Santosh Shilimkar44169072009-05-28 14:16:04 -0700295#ifdef CONFIG_ARCH_OMAP4
296static struct gpio_bank gpio_bank_44xx[6] = {
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700297 { OMAP44XX_GPIO1_BASE, NULL, INT_44XX_GPIO_BANK1, IH_GPIO_BASE,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700298 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700299 { OMAP44XX_GPIO2_BASE, NULL, INT_44XX_GPIO_BANK2, IH_GPIO_BASE + 32,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700300 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700301 { OMAP44XX_GPIO3_BASE, NULL, INT_44XX_GPIO_BANK3, IH_GPIO_BASE + 64,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700302 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700303 { OMAP44XX_GPIO4_BASE, NULL, INT_44XX_GPIO_BANK4, IH_GPIO_BASE + 96,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700304 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700305 { OMAP44XX_GPIO5_BASE, NULL, INT_44XX_GPIO_BANK5, IH_GPIO_BASE + 128,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700306 METHOD_GPIO_24XX },
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700307 { OMAP44XX_GPIO6_BASE, NULL, INT_44XX_GPIO_BANK6, IH_GPIO_BASE + 160,
Santosh Shilimkar44169072009-05-28 14:16:04 -0700308 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
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100405#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100406 case METHOD_GPIO_7XX:
407 reg += OMAP7XX_GPIO_DIR_CONTROL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100408 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800409#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530410#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100411 case METHOD_GPIO_24XX:
412 reg += OMAP24XX_GPIO_OE;
413 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800414#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530415#if defined(CONFIG_ARCH_OMAP4)
416 case METHOD_GPIO_24XX:
417 reg += OMAP4_GPIO_OE;
418 break;
419#endif
David Brownelle5c56ed2006-12-06 17:13:59 -0800420 default:
421 WARN_ON(1);
422 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100423 }
424 l = __raw_readl(reg);
425 if (is_input)
426 l |= 1 << gpio;
427 else
428 l &= ~(1 << gpio);
429 __raw_writel(l, reg);
430}
431
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100432static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
433{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100434 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100435 u32 l = 0;
436
437 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800438#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100439 case METHOD_MPUIO:
440 reg += OMAP_MPUIO_OUTPUT;
441 l = __raw_readl(reg);
442 if (enable)
443 l |= 1 << gpio;
444 else
445 l &= ~(1 << gpio);
446 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800447#endif
448#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100449 case METHOD_GPIO_1510:
450 reg += OMAP1510_GPIO_DATA_OUTPUT;
451 l = __raw_readl(reg);
452 if (enable)
453 l |= 1 << gpio;
454 else
455 l &= ~(1 << gpio);
456 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800457#endif
458#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100459 case METHOD_GPIO_1610:
460 if (enable)
461 reg += OMAP1610_GPIO_SET_DATAOUT;
462 else
463 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
464 l = 1 << gpio;
465 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800466#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100467#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100468 case METHOD_GPIO_7XX:
469 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100470 l = __raw_readl(reg);
471 if (enable)
472 l |= 1 << gpio;
473 else
474 l &= ~(1 << gpio);
475 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800476#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530477#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100478 case METHOD_GPIO_24XX:
479 if (enable)
480 reg += OMAP24XX_GPIO_SETDATAOUT;
481 else
482 reg += OMAP24XX_GPIO_CLEARDATAOUT;
483 l = 1 << gpio;
484 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800485#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530486#ifdef CONFIG_ARCH_OMAP4
487 case METHOD_GPIO_24XX:
488 if (enable)
489 reg += OMAP4_GPIO_SETDATAOUT;
490 else
491 reg += OMAP4_GPIO_CLEARDATAOUT;
492 l = 1 << gpio;
493 break;
494#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100495 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800496 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100497 return;
498 }
499 __raw_writel(l, reg);
500}
501
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300502static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100503{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100504 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100505
506 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800507 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100508 reg = bank->base;
509 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800510#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100511 case METHOD_MPUIO:
512 reg += OMAP_MPUIO_INPUT_LATCH;
513 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800514#endif
515#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100516 case METHOD_GPIO_1510:
517 reg += OMAP1510_GPIO_DATA_INPUT;
518 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800519#endif
520#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100521 case METHOD_GPIO_1610:
522 reg += OMAP1610_GPIO_DATAIN;
523 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800524#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100525#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100526 case METHOD_GPIO_7XX:
527 reg += OMAP7XX_GPIO_DATA_INPUT;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100528 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800529#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530530#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100531 case METHOD_GPIO_24XX:
532 reg += OMAP24XX_GPIO_DATAIN;
533 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800534#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530535#ifdef CONFIG_ARCH_OMAP4
536 case METHOD_GPIO_24XX:
537 reg += OMAP4_GPIO_DATAIN;
538 break;
539#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100540 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800541 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100542 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100543 return (__raw_readl(reg)
544 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100545}
546
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300547static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
548{
549 void __iomem *reg;
550
551 if (check_gpio(gpio) < 0)
552 return -EINVAL;
553 reg = bank->base;
554
555 switch (bank->method) {
556#ifdef CONFIG_ARCH_OMAP1
557 case METHOD_MPUIO:
558 reg += OMAP_MPUIO_OUTPUT;
559 break;
560#endif
561#ifdef CONFIG_ARCH_OMAP15XX
562 case METHOD_GPIO_1510:
563 reg += OMAP1510_GPIO_DATA_OUTPUT;
564 break;
565#endif
566#ifdef CONFIG_ARCH_OMAP16XX
567 case METHOD_GPIO_1610:
568 reg += OMAP1610_GPIO_DATAOUT;
569 break;
570#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100571#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100572 case METHOD_GPIO_7XX:
573 reg += OMAP7XX_GPIO_DATA_OUTPUT;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300574 break;
575#endif
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300576#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
577 defined(CONFIG_ARCH_OMAP4)
578 case METHOD_GPIO_24XX:
579 reg += OMAP24XX_GPIO_DATAOUT;
580 break;
581#endif
582 default:
583 return -EINVAL;
584 }
585
586 return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0;
587}
588
Tony Lindgren92105bb2005-09-07 17:20:26 +0100589#define MOD_REG_BIT(reg, bit_mask, set) \
590do { \
591 int l = __raw_readl(base + reg); \
592 if (set) l |= bit_mask; \
593 else l &= ~bit_mask; \
594 __raw_writel(l, base + reg); \
595} while(0)
596
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700597void omap_set_gpio_debounce(int gpio, int enable)
598{
599 struct gpio_bank *bank;
600 void __iomem *reg;
David Brownelle031ab22008-12-10 17:35:27 -0800601 unsigned long flags;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700602 u32 val, l = 1 << get_gpio_index(gpio);
603
604 if (cpu_class_is_omap1())
605 return;
606
607 bank = get_gpio_bank(gpio);
608 reg = bank->base;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530609#ifdef CONFIG_ARCH_OMAP4
610 reg += OMAP4_GPIO_DEBOUNCENABLE;
611#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700612 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530613#endif
David Brownelle031ab22008-12-10 17:35:27 -0800614
615 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700616 val = __raw_readl(reg);
617
Jouni Hogander89db9482008-12-10 17:35:24 -0800618 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700619 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800620 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700621 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800622 else
David Brownelle031ab22008-12-10 17:35:27 -0800623 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800624
Santosh Shilimkar44169072009-05-28 14:16:04 -0700625 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
David Brownelle031ab22008-12-10 17:35:27 -0800626 if (enable)
627 clk_enable(bank->dbck);
628 else
629 clk_disable(bank->dbck);
630 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700631
632 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800633done:
634 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700635}
636EXPORT_SYMBOL(omap_set_gpio_debounce);
637
638void omap_set_gpio_debounce_time(int gpio, int enc_time)
639{
640 struct gpio_bank *bank;
641 void __iomem *reg;
642
643 if (cpu_class_is_omap1())
644 return;
645
646 bank = get_gpio_bank(gpio);
647 reg = bank->base;
648
649 enc_time &= 0xff;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530650#ifdef CONFIG_ARCH_OMAP4
651 reg += OMAP4_GPIO_DEBOUNCINGTIME;
652#else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700653 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530654#endif
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700655 __raw_writel(enc_time, reg);
656}
657EXPORT_SYMBOL(omap_set_gpio_debounce_time);
658
Santosh Shilimkar44169072009-05-28 14:16:04 -0700659#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
660 defined(CONFIG_ARCH_OMAP4)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700661static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
662 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100663{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800664 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100665 u32 gpio_bit = 1 << gpio;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530666 u32 val;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100667
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530668 if (cpu_is_omap44xx()) {
669 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
670 trigger & IRQ_TYPE_LEVEL_LOW);
671 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
672 trigger & IRQ_TYPE_LEVEL_HIGH);
673 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
674 trigger & IRQ_TYPE_EDGE_RISING);
675 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
676 trigger & IRQ_TYPE_EDGE_FALLING);
677 } else {
678 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
679 trigger & IRQ_TYPE_LEVEL_LOW);
680 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
681 trigger & IRQ_TYPE_LEVEL_HIGH);
682 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
683 trigger & IRQ_TYPE_EDGE_RISING);
684 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
685 trigger & IRQ_TYPE_EDGE_FALLING);
686 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800687 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530688 if (cpu_is_omap44xx()) {
689 if (trigger != 0)
690 __raw_writel(1 << gpio, bank->base+
691 OMAP4_GPIO_IRQWAKEN0);
692 else {
693 val = __raw_readl(bank->base +
694 OMAP4_GPIO_IRQWAKEN0);
695 __raw_writel(val & (~(1 << gpio)), bank->base +
696 OMAP4_GPIO_IRQWAKEN0);
697 }
698 } else {
699 if (trigger != 0)
700 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700701 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530702 else
703 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700704 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530705 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800706 } else {
707 if (trigger != 0)
708 bank->enabled_non_wakeup_gpios |= gpio_bit;
709 else
710 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
711 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700712
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530713 if (cpu_is_omap44xx()) {
714 bank->level_mask =
715 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
716 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
717 } else {
718 bank->level_mask =
719 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
720 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
721 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100722}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800723#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100724
725static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
726{
727 void __iomem *reg = bank->base;
728 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100729
730 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800731#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100732 case METHOD_MPUIO:
733 reg += OMAP_MPUIO_GPIO_INT_EDGE;
734 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100735 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100736 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100737 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100738 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100739 else
740 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100741 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800742#endif
743#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100744 case METHOD_GPIO_1510:
745 reg += OMAP1510_GPIO_INT_CONTROL;
746 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100747 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100748 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100749 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100750 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100751 else
752 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100753 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800754#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800755#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100756 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100757 if (gpio & 0x08)
758 reg += OMAP1610_GPIO_EDGE_CTRL2;
759 else
760 reg += OMAP1610_GPIO_EDGE_CTRL1;
761 gpio &= 0x07;
762 l = __raw_readl(reg);
763 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100764 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100765 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100766 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100767 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800768 if (trigger)
769 /* Enable wake-up during idle for dynamic tick */
770 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
771 else
772 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100773 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800774#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100775#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100776 case METHOD_GPIO_7XX:
777 reg += OMAP7XX_GPIO_INT_CONTROL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100778 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100779 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100780 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100781 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100782 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100783 else
784 goto bad;
785 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800786#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -0700787#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
788 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100789 case METHOD_GPIO_24XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800790 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100791 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800792#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100793 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100794 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100795 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100796 __raw_writel(l, reg);
797 return 0;
798bad:
799 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100800}
801
Tony Lindgren92105bb2005-09-07 17:20:26 +0100802static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100803{
804 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100805 unsigned gpio;
806 int retval;
David Brownella6472532008-03-03 04:33:30 -0800807 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100808
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800809 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100810 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
811 else
812 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100813
814 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100815 return -EINVAL;
816
David Brownelle5c56ed2006-12-06 17:13:59 -0800817 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100818 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800819
820 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800821 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800822 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100823 return -EINVAL;
824
David Brownell58781012006-12-06 17:14:10 -0800825 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800826 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100827 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800828 if (retval == 0) {
829 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
830 irq_desc[irq].status |= type;
831 }
David Brownella6472532008-03-03 04:33:30 -0800832 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800833
834 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
835 __set_irq_handler_unlocked(irq, handle_level_irq);
836 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
837 __set_irq_handler_unlocked(irq, handle_edge_irq);
838
Tony Lindgren92105bb2005-09-07 17:20:26 +0100839 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100840}
841
842static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
843{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100844 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100845
846 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800847#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100848 case METHOD_MPUIO:
849 /* MPUIO irqstatus is reset by reading the status register,
850 * so do nothing here */
851 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800852#endif
853#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100854 case METHOD_GPIO_1510:
855 reg += OMAP1510_GPIO_INT_STATUS;
856 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800857#endif
858#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100859 case METHOD_GPIO_1610:
860 reg += OMAP1610_GPIO_IRQSTATUS1;
861 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800862#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100863#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100864 case METHOD_GPIO_7XX:
865 reg += OMAP7XX_GPIO_INT_STATUS;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100866 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800867#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530868#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100869 case METHOD_GPIO_24XX:
870 reg += OMAP24XX_GPIO_IRQSTATUS1;
871 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800872#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530873#if defined(CONFIG_ARCH_OMAP4)
874 case METHOD_GPIO_24XX:
875 reg += OMAP4_GPIO_IRQSTATUS0;
876 break;
877#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100878 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800879 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100880 return;
881 }
882 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300883
884 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800885#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Roger Quadrosbedfd152009-04-23 11:10:50 -0700886 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530887#endif
888#if defined(CONFIG_ARCH_OMAP4)
889 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
890#endif
891 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Roger Quadrosbedfd152009-04-23 11:10:50 -0700892 __raw_writel(gpio_mask, reg);
893
894 /* Flush posted write for the irq status to avoid spurious interrupts */
895 __raw_readl(reg);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530896 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100897}
898
899static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
900{
901 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
902}
903
Imre Deakea6dedd2006-06-26 16:16:00 -0700904static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
905{
906 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700907 int inv = 0;
908 u32 l;
909 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700910
911 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800912#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700913 case METHOD_MPUIO:
914 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700915 mask = 0xffff;
916 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700917 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800918#endif
919#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700920 case METHOD_GPIO_1510:
921 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700922 mask = 0xffff;
923 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700924 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800925#endif
926#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700927 case METHOD_GPIO_1610:
928 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700929 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700930 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800931#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100932#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100933 case METHOD_GPIO_7XX:
934 reg += OMAP7XX_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700935 mask = 0xffffffff;
936 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700937 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800938#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530939#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Imre Deakea6dedd2006-06-26 16:16:00 -0700940 case METHOD_GPIO_24XX:
941 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700942 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700943 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800944#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530945#if defined(CONFIG_ARCH_OMAP4)
946 case METHOD_GPIO_24XX:
947 reg += OMAP4_GPIO_IRQSTATUSSET0;
948 mask = 0xffffffff;
949 break;
950#endif
Imre Deakea6dedd2006-06-26 16:16:00 -0700951 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800952 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -0700953 return 0;
954 }
955
Imre Deak99c47702006-06-26 16:16:07 -0700956 l = __raw_readl(reg);
957 if (inv)
958 l = ~l;
959 l &= mask;
960 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700961}
962
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100963static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
964{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100965 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100966 u32 l;
967
968 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800969#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100970 case METHOD_MPUIO:
971 reg += OMAP_MPUIO_GPIO_MASKIT;
972 l = __raw_readl(reg);
973 if (enable)
974 l &= ~(gpio_mask);
975 else
976 l |= gpio_mask;
977 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800978#endif
979#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100980 case METHOD_GPIO_1510:
981 reg += OMAP1510_GPIO_INT_MASK;
982 l = __raw_readl(reg);
983 if (enable)
984 l &= ~(gpio_mask);
985 else
986 l |= gpio_mask;
987 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800988#endif
989#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100990 case METHOD_GPIO_1610:
991 if (enable)
992 reg += OMAP1610_GPIO_SET_IRQENABLE1;
993 else
994 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
995 l = gpio_mask;
996 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800997#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100998#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100999 case METHOD_GPIO_7XX:
1000 reg += OMAP7XX_GPIO_INT_MASK;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001001 l = __raw_readl(reg);
1002 if (enable)
1003 l &= ~(gpio_mask);
1004 else
1005 l |= gpio_mask;
1006 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001007#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301008#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001009 case METHOD_GPIO_24XX:
1010 if (enable)
1011 reg += OMAP24XX_GPIO_SETIRQENABLE1;
1012 else
1013 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
1014 l = gpio_mask;
1015 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001016#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301017#ifdef CONFIG_ARCH_OMAP4
1018 case METHOD_GPIO_24XX:
1019 if (enable)
1020 reg += OMAP4_GPIO_IRQSTATUSSET0;
1021 else
1022 reg += OMAP4_GPIO_IRQSTATUSCLR0;
1023 l = gpio_mask;
1024 break;
1025#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001026 default:
David Brownelle5c56ed2006-12-06 17:13:59 -08001027 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001028 return;
1029 }
1030 __raw_writel(l, reg);
1031}
1032
1033static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
1034{
1035 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
1036}
1037
Tony Lindgren92105bb2005-09-07 17:20:26 +01001038/*
1039 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
1040 * 1510 does not seem to have a wake-up register. If JTAG is connected
1041 * to the target, system will wake up always on GPIO events. While
1042 * system is running all registered GPIO interrupts need to have wake-up
1043 * enabled. When system is suspended, only selected GPIO interrupts need
1044 * to have wake-up enabled.
1045 */
1046static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
1047{
David Brownella6472532008-03-03 04:33:30 -08001048 unsigned long flags;
1049
Tony Lindgren92105bb2005-09-07 17:20:26 +01001050 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001051#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -08001052 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +01001053 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -08001054 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001055 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001056 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001057 else
Tony Lindgren92105bb2005-09-07 17:20:26 +01001058 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001059 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001060 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001061#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001062#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1063 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001064 case METHOD_GPIO_24XX:
David Brownell11a78b72006-12-06 17:14:11 -08001065 if (bank->non_wakeup_gpios & (1 << gpio)) {
1066 printk(KERN_ERR "Unable to modify wakeup on "
1067 "non-wakeup GPIO%d\n",
1068 (bank - gpio_bank) * 32 + gpio);
1069 return -EINVAL;
1070 }
David Brownella6472532008-03-03 04:33:30 -08001071 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001072 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001073 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -07001074 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001075 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -08001076 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001077 return 0;
1078#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001079 default:
1080 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
1081 bank->method);
1082 return -EINVAL;
1083 }
1084}
1085
Tony Lindgren4196dd62006-09-25 12:41:38 +03001086static void _reset_gpio(struct gpio_bank *bank, int gpio)
1087{
1088 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
1089 _set_gpio_irqenable(bank, gpio, 0);
1090 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +01001091 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001092}
1093
Tony Lindgren92105bb2005-09-07 17:20:26 +01001094/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
1095static int gpio_wake_enable(unsigned int irq, unsigned int enable)
1096{
1097 unsigned int gpio = irq - IH_GPIO_BASE;
1098 struct gpio_bank *bank;
1099 int retval;
1100
1101 if (check_gpio(gpio) < 0)
1102 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -08001103 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001104 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001105
1106 return retval;
1107}
1108
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001109static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001110{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001111 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001112 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001113
David Brownella6472532008-03-03 04:33:30 -08001114 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001115
Tony Lindgren4196dd62006-09-25 12:41:38 +03001116 /* Set trigger to none. You need to enable the desired trigger with
1117 * request_irq() or set_irq_type().
1118 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001119 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001120
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001121#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001122 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001123 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001124
Tony Lindgren92105bb2005-09-07 17:20:26 +01001125 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001126 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001127 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001128 }
1129#endif
David Brownella6472532008-03-03 04:33:30 -08001130 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001131
1132 return 0;
1133}
1134
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001135static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001136{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001137 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001138 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001139
David Brownella6472532008-03-03 04:33:30 -08001140 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001141#ifdef CONFIG_ARCH_OMAP16XX
1142 if (bank->method == METHOD_GPIO_1610) {
1143 /* Disable wake-up during idle for dynamic tick */
1144 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001145 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001146 }
1147#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001148#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1149 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001150 if (bank->method == METHOD_GPIO_24XX) {
1151 /* Disable wake-up during idle for dynamic tick */
1152 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001153 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001154 }
1155#endif
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001156 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001157 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001158}
1159
1160/*
1161 * We need to unmask the GPIO bank interrupt as soon as possible to
1162 * avoid missing GPIO interrupts for other lines in the bank.
1163 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1164 * in the bank to avoid missing nested interrupts for a GPIO line.
1165 * If we wait to unmask individual GPIO lines in the bank after the
1166 * line's interrupt handler has been run, we may miss some nested
1167 * interrupts.
1168 */
Russell King10dd5ce2006-11-23 11:41:32 +00001169static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001170{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001171 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001172 u32 isr;
1173 unsigned int gpio_irq;
1174 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001175 u32 retrigger = 0;
1176 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001177
1178 desc->chip->ack(irq);
1179
Thomas Gleixner418ca1f02006-07-01 22:32:41 +01001180 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001181#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001182 if (bank->method == METHOD_MPUIO)
1183 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001184#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001185#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001186 if (bank->method == METHOD_GPIO_1510)
1187 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1188#endif
1189#if defined(CONFIG_ARCH_OMAP16XX)
1190 if (bank->method == METHOD_GPIO_1610)
1191 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1192#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001193#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +01001194 if (bank->method == METHOD_GPIO_7XX)
1195 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001196#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301197#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001198 if (bank->method == METHOD_GPIO_24XX)
1199 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1200#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301201#if defined(CONFIG_ARCH_OMAP4)
1202 if (bank->method == METHOD_GPIO_24XX)
1203 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1204#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001205 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001206 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001207 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001208
Imre Deakea6dedd2006-06-26 16:16:00 -07001209 enabled = _get_gpio_irqbank_mask(bank);
1210 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001211
1212 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1213 isr &= 0x0000ffff;
1214
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001215 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001216 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001217 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001218
1219 /* clear edge sensitive interrupts before handler(s) are
1220 called so that we don't miss any interrupt occurred while
1221 executing them */
1222 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1223 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1224 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1225
1226 /* if there is only edge sensitive GPIO pin interrupts
1227 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001228 if (!level_mask && !unmasked) {
1229 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001230 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001231 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001232
Imre Deakea6dedd2006-06-26 16:16:00 -07001233 isr |= retrigger;
1234 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001235 if (!isr)
1236 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001237
Tony Lindgren92105bb2005-09-07 17:20:26 +01001238 gpio_irq = bank->virtual_irq_start;
1239 for (; isr != 0; isr >>= 1, gpio_irq++) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001240 if (!(isr & 1))
1241 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001242
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001243 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001244 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001245 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001246 /* if bank has any level sensitive GPIO pin interrupt
1247 configured, we must unmask the bank interrupt only after
1248 handler(s) are executed in order to avoid spurious bank
1249 interrupt */
1250 if (!unmasked)
1251 desc->chip->unmask(irq);
1252
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001253}
1254
Tony Lindgren4196dd62006-09-25 12:41:38 +03001255static void gpio_irq_shutdown(unsigned int irq)
1256{
1257 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001258 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001259
1260 _reset_gpio(bank, gpio);
1261}
1262
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001263static void gpio_ack_irq(unsigned int irq)
1264{
1265 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001266 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001267
1268 _clear_gpio_irqstatus(bank, gpio);
1269}
1270
1271static void gpio_mask_irq(unsigned int irq)
1272{
1273 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001274 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001275
1276 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman55b60192009-06-04 15:57:10 -07001277 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001278}
1279
1280static void gpio_unmask_irq(unsigned int irq)
1281{
1282 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001283 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001284 unsigned int irq_mask = 1 << get_gpio_index(gpio);
Kevin Hilman55b60192009-06-04 15:57:10 -07001285 struct irq_desc *desc = irq_to_desc(irq);
1286 u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK;
1287
1288 if (trigger)
1289 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001290
1291 /* For level-triggered GPIOs, the clearing must be done after
1292 * the HW source is cleared, thus after the handler has run */
1293 if (bank->level_mask & irq_mask) {
1294 _set_gpio_irqenable(bank, gpio, 0);
1295 _clear_gpio_irqstatus(bank, gpio);
1296 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001297
Kevin Hilman4de8c752008-01-16 21:56:14 -08001298 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001299}
1300
David Brownelle5c56ed2006-12-06 17:13:59 -08001301static struct irq_chip gpio_irq_chip = {
1302 .name = "GPIO",
1303 .shutdown = gpio_irq_shutdown,
1304 .ack = gpio_ack_irq,
1305 .mask = gpio_mask_irq,
1306 .unmask = gpio_unmask_irq,
1307 .set_type = gpio_irq_type,
1308 .set_wake = gpio_wake_enable,
1309};
1310
1311/*---------------------------------------------------------------------*/
1312
1313#ifdef CONFIG_ARCH_OMAP1
1314
1315/* MPUIO uses the always-on 32k clock */
1316
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001317static void mpuio_ack_irq(unsigned int irq)
1318{
1319 /* The ISR is reset automatically, so do nothing here. */
1320}
1321
1322static void mpuio_mask_irq(unsigned int irq)
1323{
1324 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001325 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001326
1327 _set_gpio_irqenable(bank, gpio, 0);
1328}
1329
1330static void mpuio_unmask_irq(unsigned int irq)
1331{
1332 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001333 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001334
1335 _set_gpio_irqenable(bank, gpio, 1);
1336}
1337
David Brownelle5c56ed2006-12-06 17:13:59 -08001338static struct irq_chip mpuio_irq_chip = {
1339 .name = "MPUIO",
1340 .ack = mpuio_ack_irq,
1341 .mask = mpuio_mask_irq,
1342 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001343 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001344#ifdef CONFIG_ARCH_OMAP16XX
1345 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1346 .set_wake = gpio_wake_enable,
1347#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001348};
1349
David Brownelle5c56ed2006-12-06 17:13:59 -08001350
1351#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1352
David Brownell11a78b72006-12-06 17:14:11 -08001353
1354#ifdef CONFIG_ARCH_OMAP16XX
1355
1356#include <linux/platform_device.h>
1357
Magnus Damm79ee0312009-07-08 13:22:04 +02001358static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001359{
Magnus Damm79ee0312009-07-08 13:22:04 +02001360 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001361 struct gpio_bank *bank = platform_get_drvdata(pdev);
1362 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001363 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001364
David Brownella6472532008-03-03 04:33:30 -08001365 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001366 bank->saved_wakeup = __raw_readl(mask_reg);
1367 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001368 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001369
1370 return 0;
1371}
1372
Magnus Damm79ee0312009-07-08 13:22:04 +02001373static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -08001374{
Magnus Damm79ee0312009-07-08 13:22:04 +02001375 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -08001376 struct gpio_bank *bank = platform_get_drvdata(pdev);
1377 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001378 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001379
David Brownella6472532008-03-03 04:33:30 -08001380 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001381 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001382 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001383
1384 return 0;
1385}
1386
Magnus Damm79ee0312009-07-08 13:22:04 +02001387static struct dev_pm_ops omap_mpuio_dev_pm_ops = {
1388 .suspend_noirq = omap_mpuio_suspend_noirq,
1389 .resume_noirq = omap_mpuio_resume_noirq,
1390};
1391
David Brownell11a78b72006-12-06 17:14:11 -08001392/* use platform_driver for this, now that there's no longer any
1393 * point to sys_device (other than not disturbing old code).
1394 */
1395static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -08001396 .driver = {
1397 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +02001398 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -08001399 },
1400};
1401
1402static struct platform_device omap_mpuio_device = {
1403 .name = "mpuio",
1404 .id = -1,
1405 .dev = {
1406 .driver = &omap_mpuio_driver.driver,
1407 }
1408 /* could list the /proc/iomem resources */
1409};
1410
1411static inline void mpuio_init(void)
1412{
David Brownellfcf126d2007-04-02 12:46:47 -07001413 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1414
David Brownell11a78b72006-12-06 17:14:11 -08001415 if (platform_driver_register(&omap_mpuio_driver) == 0)
1416 (void) platform_device_register(&omap_mpuio_device);
1417}
1418
1419#else
1420static inline void mpuio_init(void) {}
1421#endif /* 16xx */
1422
David Brownelle5c56ed2006-12-06 17:13:59 -08001423#else
1424
1425extern struct irq_chip mpuio_irq_chip;
1426
1427#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001428static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001429
1430#endif
1431
1432/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001433
David Brownell52e31342008-03-03 12:43:23 -08001434/* REVISIT these are stupid implementations! replace by ones that
1435 * don't switch on METHOD_* and which mostly avoid spinlocks
1436 */
1437
1438static int gpio_input(struct gpio_chip *chip, unsigned offset)
1439{
1440 struct gpio_bank *bank;
1441 unsigned long flags;
1442
1443 bank = container_of(chip, struct gpio_bank, chip);
1444 spin_lock_irqsave(&bank->lock, flags);
1445 _set_gpio_direction(bank, offset, 1);
1446 spin_unlock_irqrestore(&bank->lock, flags);
1447 return 0;
1448}
1449
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001450static int gpio_is_input(struct gpio_bank *bank, int mask)
1451{
1452 void __iomem *reg = bank->base;
1453
1454 switch (bank->method) {
1455 case METHOD_MPUIO:
1456 reg += OMAP_MPUIO_IO_CNTL;
1457 break;
1458 case METHOD_GPIO_1510:
1459 reg += OMAP1510_GPIO_DIR_CONTROL;
1460 break;
1461 case METHOD_GPIO_1610:
1462 reg += OMAP1610_GPIO_DIRECTION;
1463 break;
Alistair Buxton7c006922009-09-22 10:02:58 +01001464 case METHOD_GPIO_7XX:
1465 reg += OMAP7XX_GPIO_DIR_CONTROL;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001466 break;
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001467 case METHOD_GPIO_24XX:
1468 reg += OMAP24XX_GPIO_OE;
1469 break;
1470 }
1471 return __raw_readl(reg) & mask;
1472}
1473
David Brownell52e31342008-03-03 12:43:23 -08001474static int gpio_get(struct gpio_chip *chip, unsigned offset)
1475{
Roger Quadrosb37c45b2009-08-05 16:53:24 +03001476 struct gpio_bank *bank;
1477 void __iomem *reg;
1478 int gpio;
1479 u32 mask;
1480
1481 gpio = chip->base + offset;
1482 bank = get_gpio_bank(gpio);
1483 reg = bank->base;
1484 mask = 1 << get_gpio_index(gpio);
1485
1486 if (gpio_is_input(bank, mask))
1487 return _get_gpio_datain(bank, gpio);
1488 else
1489 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -08001490}
1491
1492static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1493{
1494 struct gpio_bank *bank;
1495 unsigned long flags;
1496
1497 bank = container_of(chip, struct gpio_bank, chip);
1498 spin_lock_irqsave(&bank->lock, flags);
1499 _set_gpio_dataout(bank, offset, value);
1500 _set_gpio_direction(bank, offset, 0);
1501 spin_unlock_irqrestore(&bank->lock, flags);
1502 return 0;
1503}
1504
1505static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1506{
1507 struct gpio_bank *bank;
1508 unsigned long flags;
1509
1510 bank = container_of(chip, struct gpio_bank, chip);
1511 spin_lock_irqsave(&bank->lock, flags);
1512 _set_gpio_dataout(bank, offset, value);
1513 spin_unlock_irqrestore(&bank->lock, flags);
1514}
1515
David Brownella007b702008-12-10 17:35:25 -08001516static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1517{
1518 struct gpio_bank *bank;
1519
1520 bank = container_of(chip, struct gpio_bank, chip);
1521 return bank->virtual_irq_start + offset;
1522}
1523
David Brownell52e31342008-03-03 12:43:23 -08001524/*---------------------------------------------------------------------*/
1525
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001526static int initialized;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001527#if !(defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001528static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001529#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001530
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001531#if defined(CONFIG_ARCH_OMAP2)
1532static struct clk * gpio_fck;
1533#endif
1534
1535#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001536static struct clk * gpio5_ick;
1537static struct clk * gpio5_fck;
1538#endif
1539
Santosh Shilimkar44169072009-05-28 14:16:04 -07001540#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001541static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1542#endif
1543
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001544static void __init omap_gpio_show_rev(void)
1545{
1546 u32 rev;
1547
1548 if (cpu_is_omap16xx())
1549 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
1550 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1551 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
1552 else if (cpu_is_omap44xx())
1553 rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION);
1554 else
1555 return;
1556
1557 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1558 (rev >> 4) & 0x0f, rev & 0x0f);
1559}
1560
David Brownell8ba55c52008-02-26 11:10:50 -08001561/* This lock class tells lockdep that GPIO irqs are in a different
1562 * category than their parents, so it won't report false recursion.
1563 */
1564static struct lock_class_key gpio_lock_class;
1565
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001566static int __init _omap_gpio_init(void)
1567{
1568 int i;
David Brownell52e31342008-03-03 12:43:23 -08001569 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001570 struct gpio_bank *bank;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001571 int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001572 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001573
1574 initialized = 1;
1575
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001576#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001577 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001578 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1579 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001580 printk("Could not get arm_gpio_ck\n");
1581 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001582 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001583 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001584#endif
1585#if defined(CONFIG_ARCH_OMAP2)
1586 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001587 gpio_ick = clk_get(NULL, "gpios_ick");
1588 if (IS_ERR(gpio_ick))
1589 printk("Could not get gpios_ick\n");
1590 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001591 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001592 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001593 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001594 printk("Could not get gpios_fck\n");
1595 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001596 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001597
1598 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001599 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001600 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001601#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001602 if (cpu_is_omap2430()) {
1603 gpio5_ick = clk_get(NULL, "gpio5_ick");
1604 if (IS_ERR(gpio5_ick))
1605 printk("Could not get gpio5_ick\n");
1606 else
1607 clk_enable(gpio5_ick);
1608 gpio5_fck = clk_get(NULL, "gpio5_fck");
1609 if (IS_ERR(gpio5_fck))
1610 printk("Could not get gpio5_fck\n");
1611 else
1612 clk_enable(gpio5_fck);
1613 }
1614#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001615 }
1616#endif
1617
Santosh Shilimkar44169072009-05-28 14:16:04 -07001618#if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)
1619 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001620 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1621 sprintf(clk_name, "gpio%d_ick", i + 1);
1622 gpio_iclks[i] = clk_get(NULL, clk_name);
1623 if (IS_ERR(gpio_iclks[i]))
1624 printk(KERN_ERR "Could not get %s\n", clk_name);
1625 else
1626 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001627 }
1628 }
1629#endif
1630
Tony Lindgren92105bb2005-09-07 17:20:26 +01001631
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001632#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001633 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001634 gpio_bank_count = 2;
1635 gpio_bank = gpio_bank_1510;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001636 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001637 }
1638#endif
1639#if defined(CONFIG_ARCH_OMAP16XX)
1640 if (cpu_is_omap16xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001641 gpio_bank_count = 5;
1642 gpio_bank = gpio_bank_1610;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001643 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001644 }
1645#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +01001646#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1647 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001648 gpio_bank_count = 7;
Alistair Buxton7c006922009-09-22 10:02:58 +01001649 gpio_bank = gpio_bank_7xx;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001650 bank_size = SZ_2K;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001651 }
1652#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001653#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001654 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001655 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001656 gpio_bank = gpio_bank_242x;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001657 }
1658 if (cpu_is_omap243x()) {
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001659 gpio_bank_count = 5;
1660 gpio_bank = gpio_bank_243x;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001661 }
1662#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001663#ifdef CONFIG_ARCH_OMAP34XX
1664 if (cpu_is_omap34xx()) {
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001665 gpio_bank_count = OMAP34XX_NR_GPIOS;
1666 gpio_bank = gpio_bank_34xx;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001667 }
1668#endif
Santosh Shilimkar44169072009-05-28 14:16:04 -07001669#ifdef CONFIG_ARCH_OMAP4
1670 if (cpu_is_omap44xx()) {
Santosh Shilimkar44169072009-05-28 14:16:04 -07001671 gpio_bank_count = OMAP34XX_NR_GPIOS;
1672 gpio_bank = gpio_bank_44xx;
Santosh Shilimkar44169072009-05-28 14:16:04 -07001673 }
1674#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001675 for (i = 0; i < gpio_bank_count; i++) {
1676 int j, gpio_count = 16;
1677
1678 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001679 spin_lock_init(&bank->lock);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001680
1681 /* Static mapping, never released */
1682 bank->base = ioremap(bank->pbase, bank_size);
1683 if (!bank->base) {
1684 printk(KERN_ERR "Could not ioremap gpio bank%i\n", i);
1685 continue;
1686 }
1687
David Brownelle5c56ed2006-12-06 17:13:59 -08001688 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001689 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001690 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001691 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1692 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1693 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001694 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001695 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1696 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001697 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001698 }
Alistair Buxton7c006922009-09-22 10:02:58 +01001699 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1700 __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK);
1701 __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001702
Alistair Buxton7c006922009-09-22 10:02:58 +01001703 gpio_count = 32; /* 7xx has 32-bit GPIOs */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001704 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001705
Santosh Shilimkar44169072009-05-28 14:16:04 -07001706#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1707 defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001708 if (bank->method == METHOD_GPIO_24XX) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001709 static const u32 non_wakeup_gpios[] = {
1710 0xe203ffc0, 0x08700040
1711 };
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301712 if (cpu_is_omap44xx()) {
1713 __raw_writel(0xffffffff, bank->base +
1714 OMAP4_GPIO_IRQSTATUSCLR0);
1715 __raw_writew(0x0015, bank->base +
1716 OMAP4_GPIO_SYSCONFIG);
1717 __raw_writel(0x00000000, bank->base +
1718 OMAP4_GPIO_DEBOUNCENABLE);
1719 /* Initialize interface clock ungated, module enabled */
1720 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1721 } else {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001722 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1723 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001724 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
janboecb5793d2009-06-23 13:30:25 +03001725 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_DEBOUNCE_EN);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001726
1727 /* Initialize interface clock ungated, module enabled */
1728 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301729 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001730 if (i < ARRAY_SIZE(non_wakeup_gpios))
1731 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001732 gpio_count = 32;
1733 }
1734#endif
David Brownell52e31342008-03-03 12:43:23 -08001735 /* REVISIT eventually switch from OMAP-specific gpio structs
1736 * over to the generic ones
1737 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001738 bank->chip.request = omap_gpio_request;
1739 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001740 bank->chip.direction_input = gpio_input;
1741 bank->chip.get = gpio_get;
1742 bank->chip.direction_output = gpio_output;
1743 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001744 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001745 if (bank_is_mpuio(bank)) {
1746 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001747#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d82008-07-25 01:46:07 -07001748 bank->chip.dev = &omap_mpuio_device.dev;
1749#endif
David Brownell52e31342008-03-03 12:43:23 -08001750 bank->chip.base = OMAP_MPUIO(0);
1751 } else {
1752 bank->chip.label = "gpio";
1753 bank->chip.base = gpio;
1754 gpio += gpio_count;
1755 }
1756 bank->chip.ngpio = gpio_count;
1757
1758 gpiochip_add(&bank->chip);
1759
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001760 for (j = bank->virtual_irq_start;
1761 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001762 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001763 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001764 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001765 set_irq_chip(j, &mpuio_irq_chip);
1766 else
1767 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001768 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001769 set_irq_flags(j, IRQF_VALID);
1770 }
1771 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1772 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001773
Santosh Shilimkar44169072009-05-28 14:16:04 -07001774 if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
Jouni Hogander89db9482008-12-10 17:35:24 -08001775 sprintf(clk_name, "gpio%d_dbck", i + 1);
1776 bank->dbck = clk_get(NULL, clk_name);
1777 if (IS_ERR(bank->dbck))
1778 printk(KERN_ERR "Could not get %s\n", clk_name);
1779 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001780 }
1781
1782 /* Enable system clock for GPIO module.
1783 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001784 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001785 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1786
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001787 /* Enable autoidle for the OCP interface */
1788 if (cpu_is_omap24xx())
1789 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001790 if (cpu_is_omap34xx())
1791 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001792
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001793 omap_gpio_show_rev();
1794
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001795 return 0;
1796}
1797
Santosh Shilimkar44169072009-05-28 14:16:04 -07001798#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1799 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001800static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1801{
1802 int i;
1803
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001804 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001805 return 0;
1806
1807 for (i = 0; i < gpio_bank_count; i++) {
1808 struct gpio_bank *bank = &gpio_bank[i];
1809 void __iomem *wake_status;
1810 void __iomem *wake_clear;
1811 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001812 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001813
1814 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001815#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001816 case METHOD_GPIO_1610:
1817 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1818 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1819 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1820 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001821#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301822#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001823 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001824 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001825 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1826 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1827 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001828#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301829#ifdef CONFIG_ARCH_OMAP4
1830 case METHOD_GPIO_24XX:
1831 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1832 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1833 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1834 break;
1835#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001836 default:
1837 continue;
1838 }
1839
David Brownella6472532008-03-03 04:33:30 -08001840 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001841 bank->saved_wakeup = __raw_readl(wake_status);
1842 __raw_writel(0xffffffff, wake_clear);
1843 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001844 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001845 }
1846
1847 return 0;
1848}
1849
1850static int omap_gpio_resume(struct sys_device *dev)
1851{
1852 int i;
1853
Tero Kristo723fdb72008-11-26 14:35:16 -08001854 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001855 return 0;
1856
1857 for (i = 0; i < gpio_bank_count; i++) {
1858 struct gpio_bank *bank = &gpio_bank[i];
1859 void __iomem *wake_clear;
1860 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001861 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001862
1863 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001864#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001865 case METHOD_GPIO_1610:
1866 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1867 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1868 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001869#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301870#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001871 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001872 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1873 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001874 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001875#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301876#ifdef CONFIG_ARCH_OMAP4
1877 case METHOD_GPIO_24XX:
1878 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1879 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1880 break;
1881#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001882 default:
1883 continue;
1884 }
1885
David Brownella6472532008-03-03 04:33:30 -08001886 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001887 __raw_writel(0xffffffff, wake_clear);
1888 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001889 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001890 }
1891
1892 return 0;
1893}
1894
1895static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f42007-12-20 02:09:39 +01001896 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001897 .suspend = omap_gpio_suspend,
1898 .resume = omap_gpio_resume,
1899};
1900
1901static struct sys_device omap_gpio_device = {
1902 .id = 0,
1903 .cls = &omap_gpio_sysclass,
1904};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001905
1906#endif
1907
Santosh Shilimkar44169072009-05-28 14:16:04 -07001908#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
1909 defined(CONFIG_ARCH_OMAP4)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001910
1911static int workaround_enabled;
1912
1913void omap2_gpio_prepare_for_retention(void)
1914{
1915 int i, c = 0;
1916
1917 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
1918 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
1919 for (i = 0; i < gpio_bank_count; i++) {
1920 struct gpio_bank *bank = &gpio_bank[i];
1921 u32 l1, l2;
1922
1923 if (!(bank->enabled_non_wakeup_gpios))
1924 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301925#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001926 bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1927 l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1928 l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001929#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301930#ifdef CONFIG_ARCH_OMAP4
1931 bank->saved_datain = __raw_readl(bank->base +
1932 OMAP4_GPIO_DATAIN);
1933 l1 = __raw_readl(bank->base + OMAP4_GPIO_FALLINGDETECT);
1934 l2 = __raw_readl(bank->base + OMAP4_GPIO_RISINGDETECT);
1935#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001936 bank->saved_fallingdetect = l1;
1937 bank->saved_risingdetect = l2;
1938 l1 &= ~bank->enabled_non_wakeup_gpios;
1939 l2 &= ~bank->enabled_non_wakeup_gpios;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301940#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001941 __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1942 __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001943#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301944#ifdef CONFIG_ARCH_OMAP4
1945 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
1946 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
1947#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001948 c++;
1949 }
1950 if (!c) {
1951 workaround_enabled = 0;
1952 return;
1953 }
1954 workaround_enabled = 1;
1955}
1956
1957void omap2_gpio_resume_after_retention(void)
1958{
1959 int i;
1960
1961 if (!workaround_enabled)
1962 return;
1963 for (i = 0; i < gpio_bank_count; i++) {
1964 struct gpio_bank *bank = &gpio_bank[i];
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07001965 u32 l, gen, gen0, gen1;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001966
1967 if (!(bank->enabled_non_wakeup_gpios))
1968 continue;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301969#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001970 __raw_writel(bank->saved_fallingdetect,
1971 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1972 __raw_writel(bank->saved_risingdetect,
1973 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301974 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1975#endif
1976#ifdef CONFIG_ARCH_OMAP4
1977 __raw_writel(bank->saved_fallingdetect,
1978 bank->base + OMAP4_GPIO_FALLINGDETECT);
1979 __raw_writel(bank->saved_risingdetect,
1980 bank->base + OMAP4_GPIO_RISINGDETECT);
1981 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001982#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001983 /* Check if any of the non-wakeup interrupt GPIOs have changed
1984 * state. If so, generate an IRQ by software. This is
1985 * horribly racy, but it's the best we can do to work around
1986 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001987 l ^= bank->saved_datain;
1988 l &= bank->non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07001989
1990 /*
1991 * No need to generate IRQs for the rising edge for gpio IRQs
1992 * configured with falling edge only; and vice versa.
1993 */
1994 gen0 = l & bank->saved_fallingdetect;
1995 gen0 &= bank->saved_datain;
1996
1997 gen1 = l & bank->saved_risingdetect;
1998 gen1 &= ~(bank->saved_datain);
1999
2000 /* FIXME: Consider GPIO IRQs with level detections properly! */
2001 gen = l & (~(bank->saved_fallingdetect) &
2002 ~(bank->saved_risingdetect));
2003 /* Consider all GPIO IRQs needed to be updated */
2004 gen |= gen0 | gen1;
2005
2006 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002007 u32 old0, old1;
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302008#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002009 old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2010 old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07002011 __raw_writel(old0 | gen, bank->base +
2012 OMAP24XX_GPIO_LEVELDETECT0);
2013 __raw_writel(old1 | gen, bank->base +
2014 OMAP24XX_GPIO_LEVELDETECT1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002015 __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
2016 __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002017#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05302018#ifdef CONFIG_ARCH_OMAP4
2019 old0 = __raw_readl(bank->base +
2020 OMAP4_GPIO_LEVELDETECT0);
2021 old1 = __raw_readl(bank->base +
2022 OMAP4_GPIO_LEVELDETECT1);
2023 __raw_writel(old0 | l, bank->base +
2024 OMAP4_GPIO_LEVELDETECT0);
2025 __raw_writel(old1 | l, bank->base +
2026 OMAP4_GPIO_LEVELDETECT1);
2027 __raw_writel(old0, bank->base +
2028 OMAP4_GPIO_LEVELDETECT0);
2029 __raw_writel(old1, bank->base +
2030 OMAP4_GPIO_LEVELDETECT1);
2031#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08002032 }
2033 }
2034
2035}
2036
Tony Lindgren92105bb2005-09-07 17:20:26 +01002037#endif
2038
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002039/*
2040 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00002041 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002042 */
David Brownell277d58e2006-12-06 17:13:59 -08002043int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002044{
2045 if (!initialized)
2046 return _omap_gpio_init();
2047 else
2048 return 0;
2049}
2050
Tony Lindgren92105bb2005-09-07 17:20:26 +01002051static int __init omap_gpio_sysinit(void)
2052{
2053 int ret = 0;
2054
2055 if (!initialized)
2056 ret = _omap_gpio_init();
2057
David Brownell11a78b72006-12-06 17:14:11 -08002058 mpuio_init();
2059
Santosh Shilimkar44169072009-05-28 14:16:04 -07002060#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
2061 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08002062 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01002063 if (ret == 0) {
2064 ret = sysdev_class_register(&omap_gpio_sysclass);
2065 if (ret == 0)
2066 ret = sysdev_register(&omap_gpio_device);
2067 }
2068 }
2069#endif
2070
2071 return ret;
2072}
2073
Tony Lindgren92105bb2005-09-07 17:20:26 +01002074arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08002075
2076
2077#ifdef CONFIG_DEBUG_FS
2078
2079#include <linux/debugfs.h>
2080#include <linux/seq_file.h>
2081
David Brownellb9772a22006-12-06 17:13:53 -08002082static int dbg_gpio_show(struct seq_file *s, void *unused)
2083{
2084 unsigned i, j, gpio;
2085
2086 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
2087 struct gpio_bank *bank = gpio_bank + i;
2088 unsigned bankwidth = 16;
2089 u32 mask = 1;
2090
David Brownelle5c56ed2006-12-06 17:13:59 -08002091 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08002092 gpio = OMAP_MPUIO(0);
Alistair Buxtonb718aa82009-09-23 18:56:19 +01002093 else if (cpu_class_is_omap2() || cpu_is_omap7xx())
David Brownellb9772a22006-12-06 17:13:53 -08002094 bankwidth = 32;
2095
2096 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
2097 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08002098 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08002099
David Brownell52e31342008-03-03 12:43:23 -08002100 label = gpiochip_is_requested(&bank->chip, j);
2101 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08002102 continue;
2103
2104 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08002105 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08002106 is_in = gpio_is_input(bank, mask);
2107
David Brownelle5c56ed2006-12-06 17:13:59 -08002108 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08002109 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08002110 else
David Brownell52e31342008-03-03 12:43:23 -08002111 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08002112 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08002113 label,
David Brownellb9772a22006-12-06 17:13:53 -08002114 is_in ? "in " : "out",
2115 value ? "hi" : "lo");
2116
David Brownell52e31342008-03-03 12:43:23 -08002117/* FIXME for at least omap2, show pullup/pulldown state */
2118
David Brownellb9772a22006-12-06 17:13:53 -08002119 irqstat = irq_desc[irq].status;
Tony Lindgren3a26e332009-01-15 13:09:53 +02002120#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
Santosh Shilimkar44169072009-05-28 14:16:04 -07002121 defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4)
David Brownellb9772a22006-12-06 17:13:53 -08002122 if (is_in && ((bank->suspend_wakeup & mask)
2123 || irqstat & IRQ_TYPE_SENSE_MASK)) {
2124 char *trigger = NULL;
2125
2126 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
2127 case IRQ_TYPE_EDGE_FALLING:
2128 trigger = "falling";
2129 break;
2130 case IRQ_TYPE_EDGE_RISING:
2131 trigger = "rising";
2132 break;
2133 case IRQ_TYPE_EDGE_BOTH:
2134 trigger = "bothedge";
2135 break;
2136 case IRQ_TYPE_LEVEL_LOW:
2137 trigger = "low";
2138 break;
2139 case IRQ_TYPE_LEVEL_HIGH:
2140 trigger = "high";
2141 break;
2142 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08002143 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08002144 break;
2145 }
David Brownell52e31342008-03-03 12:43:23 -08002146 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08002147 irq, trigger,
2148 (bank->suspend_wakeup & mask)
2149 ? " wakeup" : "");
2150 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02002151#endif
David Brownellb9772a22006-12-06 17:13:53 -08002152 seq_printf(s, "\n");
2153 }
2154
David Brownelle5c56ed2006-12-06 17:13:59 -08002155 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08002156 seq_printf(s, "\n");
2157 gpio = 0;
2158 }
2159 }
2160 return 0;
2161}
2162
2163static int dbg_gpio_open(struct inode *inode, struct file *file)
2164{
David Brownelle5c56ed2006-12-06 17:13:59 -08002165 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08002166}
2167
2168static const struct file_operations debug_fops = {
2169 .open = dbg_gpio_open,
2170 .read = seq_read,
2171 .llseek = seq_lseek,
2172 .release = single_release,
2173};
2174
2175static int __init omap_gpio_debuginit(void)
2176{
David Brownelle5c56ed2006-12-06 17:13:59 -08002177 (void) debugfs_create_file("omap_gpio", S_IRUGO,
2178 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08002179 return 0;
2180}
2181late_initcall(omap_gpio_debuginit);
2182#endif