blob: 210a1c04555488cf9d4d39856557b9caac029b53 [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 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010014#include <linux/init.h>
15#include <linux/module.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010016#include <linux/interrupt.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010017#include <linux/sysdev.h>
18#include <linux/err.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000019#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010020#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010021
Russell Kinga09e64f2008-08-05 16:14:15 +010022#include <mach/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010023#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/irqs.h>
25#include <mach/gpio.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010026#include <asm/mach/irq.h>
27
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010028/*
29 * OMAP1510 GPIO registers
30 */
Russell King7c7095a2008-09-05 15:49:14 +010031#define OMAP1510_GPIO_BASE IO_ADDRESS(0xfffce000)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010032#define OMAP1510_GPIO_DATA_INPUT 0x00
33#define OMAP1510_GPIO_DATA_OUTPUT 0x04
34#define OMAP1510_GPIO_DIR_CONTROL 0x08
35#define OMAP1510_GPIO_INT_CONTROL 0x0c
36#define OMAP1510_GPIO_INT_MASK 0x10
37#define OMAP1510_GPIO_INT_STATUS 0x14
38#define OMAP1510_GPIO_PIN_CONTROL 0x18
39
40#define OMAP1510_IH_GPIO_BASE 64
41
42/*
43 * OMAP1610 specific GPIO registers
44 */
Russell King7c7095a2008-09-05 15:49:14 +010045#define OMAP1610_GPIO1_BASE IO_ADDRESS(0xfffbe400)
46#define OMAP1610_GPIO2_BASE IO_ADDRESS(0xfffbec00)
47#define OMAP1610_GPIO3_BASE IO_ADDRESS(0xfffbb400)
48#define OMAP1610_GPIO4_BASE IO_ADDRESS(0xfffbbc00)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010049#define OMAP1610_GPIO_REVISION 0x0000
50#define OMAP1610_GPIO_SYSCONFIG 0x0010
51#define OMAP1610_GPIO_SYSSTATUS 0x0014
52#define OMAP1610_GPIO_IRQSTATUS1 0x0018
53#define OMAP1610_GPIO_IRQENABLE1 0x001c
Tony Lindgren92105bb2005-09-07 17:20:26 +010054#define OMAP1610_GPIO_WAKEUPENABLE 0x0028
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010055#define OMAP1610_GPIO_DATAIN 0x002c
56#define OMAP1610_GPIO_DATAOUT 0x0030
57#define OMAP1610_GPIO_DIRECTION 0x0034
58#define OMAP1610_GPIO_EDGE_CTRL1 0x0038
59#define OMAP1610_GPIO_EDGE_CTRL2 0x003c
60#define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c
Tony Lindgren92105bb2005-09-07 17:20:26 +010061#define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010062#define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0
63#define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc
Tony Lindgren92105bb2005-09-07 17:20:26 +010064#define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010065#define OMAP1610_GPIO_SET_DATAOUT 0x00f0
66
67/*
68 * OMAP730 specific GPIO registers
69 */
Russell King7c7095a2008-09-05 15:49:14 +010070#define OMAP730_GPIO1_BASE IO_ADDRESS(0xfffbc000)
71#define OMAP730_GPIO2_BASE IO_ADDRESS(0xfffbc800)
72#define OMAP730_GPIO3_BASE IO_ADDRESS(0xfffbd000)
73#define OMAP730_GPIO4_BASE IO_ADDRESS(0xfffbd800)
74#define OMAP730_GPIO5_BASE IO_ADDRESS(0xfffbe000)
75#define OMAP730_GPIO6_BASE IO_ADDRESS(0xfffbe800)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010076#define OMAP730_GPIO_DATA_INPUT 0x00
77#define OMAP730_GPIO_DATA_OUTPUT 0x04
78#define OMAP730_GPIO_DIR_CONTROL 0x08
79#define OMAP730_GPIO_INT_CONTROL 0x0c
80#define OMAP730_GPIO_INT_MASK 0x10
81#define OMAP730_GPIO_INT_STATUS 0x14
82
Tony Lindgren92105bb2005-09-07 17:20:26 +010083/*
Zebediah C. McClure56739a62009-03-23 18:07:40 -070084 * OMAP850 specific GPIO registers
85 */
86#define OMAP850_GPIO1_BASE IO_ADDRESS(0xfffbc000)
87#define OMAP850_GPIO2_BASE IO_ADDRESS(0xfffbc800)
88#define OMAP850_GPIO3_BASE IO_ADDRESS(0xfffbd000)
89#define OMAP850_GPIO4_BASE IO_ADDRESS(0xfffbd800)
90#define OMAP850_GPIO5_BASE IO_ADDRESS(0xfffbe000)
91#define OMAP850_GPIO6_BASE IO_ADDRESS(0xfffbe800)
92#define OMAP850_GPIO_DATA_INPUT 0x00
93#define OMAP850_GPIO_DATA_OUTPUT 0x04
94#define OMAP850_GPIO_DIR_CONTROL 0x08
95#define OMAP850_GPIO_INT_CONTROL 0x0c
96#define OMAP850_GPIO_INT_MASK 0x10
97#define OMAP850_GPIO_INT_STATUS 0x14
98
99/*
Tony Lindgren92105bb2005-09-07 17:20:26 +0100100 * omap24xx specific GPIO registers
101 */
Russell King7c7095a2008-09-05 15:49:14 +0100102#define OMAP242X_GPIO1_BASE IO_ADDRESS(0x48018000)
103#define OMAP242X_GPIO2_BASE IO_ADDRESS(0x4801a000)
104#define OMAP242X_GPIO3_BASE IO_ADDRESS(0x4801c000)
105#define OMAP242X_GPIO4_BASE IO_ADDRESS(0x4801e000)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800106
Russell King7c7095a2008-09-05 15:49:14 +0100107#define OMAP243X_GPIO1_BASE IO_ADDRESS(0x4900C000)
108#define OMAP243X_GPIO2_BASE IO_ADDRESS(0x4900E000)
109#define OMAP243X_GPIO3_BASE IO_ADDRESS(0x49010000)
110#define OMAP243X_GPIO4_BASE IO_ADDRESS(0x49012000)
111#define OMAP243X_GPIO5_BASE IO_ADDRESS(0x480B6000)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800112
Tony Lindgren92105bb2005-09-07 17:20:26 +0100113#define OMAP24XX_GPIO_REVISION 0x0000
114#define OMAP24XX_GPIO_SYSCONFIG 0x0010
115#define OMAP24XX_GPIO_SYSSTATUS 0x0014
116#define OMAP24XX_GPIO_IRQSTATUS1 0x0018
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300117#define OMAP24XX_GPIO_IRQSTATUS2 0x0028
118#define OMAP24XX_GPIO_IRQENABLE2 0x002c
Tony Lindgren92105bb2005-09-07 17:20:26 +0100119#define OMAP24XX_GPIO_IRQENABLE1 0x001c
Tero Kristo723fdb72008-11-26 14:35:16 -0800120#define OMAP24XX_GPIO_WAKE_EN 0x0020
Tony Lindgren92105bb2005-09-07 17:20:26 +0100121#define OMAP24XX_GPIO_CTRL 0x0030
122#define OMAP24XX_GPIO_OE 0x0034
123#define OMAP24XX_GPIO_DATAIN 0x0038
124#define OMAP24XX_GPIO_DATAOUT 0x003c
125#define OMAP24XX_GPIO_LEVELDETECT0 0x0040
126#define OMAP24XX_GPIO_LEVELDETECT1 0x0044
127#define OMAP24XX_GPIO_RISINGDETECT 0x0048
128#define OMAP24XX_GPIO_FALLINGDETECT 0x004c
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700129#define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050
130#define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054
Tony Lindgren92105bb2005-09-07 17:20:26 +0100131#define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060
132#define OMAP24XX_GPIO_SETIRQENABLE1 0x0064
133#define OMAP24XX_GPIO_CLEARWKUENA 0x0080
134#define OMAP24XX_GPIO_SETWKUENA 0x0084
135#define OMAP24XX_GPIO_CLEARDATAOUT 0x0090
136#define OMAP24XX_GPIO_SETDATAOUT 0x0094
137
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800138/*
139 * omap34xx specific GPIO registers
140 */
141
Russell King7c7095a2008-09-05 15:49:14 +0100142#define OMAP34XX_GPIO1_BASE IO_ADDRESS(0x48310000)
143#define OMAP34XX_GPIO2_BASE IO_ADDRESS(0x49050000)
144#define OMAP34XX_GPIO3_BASE IO_ADDRESS(0x49052000)
145#define OMAP34XX_GPIO4_BASE IO_ADDRESS(0x49054000)
146#define OMAP34XX_GPIO5_BASE IO_ADDRESS(0x49056000)
147#define OMAP34XX_GPIO6_BASE IO_ADDRESS(0x49058000)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800148
Russell King7c7095a2008-09-05 15:49:14 +0100149#define OMAP_MPUIO_VBASE IO_ADDRESS(OMAP_MPUIO_BASE)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800150
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100151struct gpio_bank {
Tony Lindgren92105bb2005-09-07 17:20:26 +0100152 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100153 u16 irq;
154 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100155 int method;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800156#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100157 u32 suspend_wakeup;
158 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800159#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800160#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800161 u32 non_wakeup_gpios;
162 u32 enabled_non_wakeup_gpios;
163
164 u32 saved_datain;
165 u32 saved_fallingdetect;
166 u32 saved_risingdetect;
167#endif
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800168 u32 level_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100169 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -0800170 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -0800171 struct clk *dbck;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100172};
173
174#define METHOD_MPUIO 0
175#define METHOD_GPIO_1510 1
176#define METHOD_GPIO_1610 2
177#define METHOD_GPIO_730 3
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700178#define METHOD_GPIO_850 4
179#define METHOD_GPIO_24XX 5
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100180
Tony Lindgren92105bb2005-09-07 17:20:26 +0100181#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100182static struct gpio_bank gpio_bank_1610[5] = {
Russell King7c7095a2008-09-05 15:49:14 +0100183 { OMAP_MPUIO_VBASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO},
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100184 { OMAP1610_GPIO1_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1610 },
185 { OMAP1610_GPIO2_BASE, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16, METHOD_GPIO_1610 },
186 { OMAP1610_GPIO3_BASE, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32, METHOD_GPIO_1610 },
187 { OMAP1610_GPIO4_BASE, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48, METHOD_GPIO_1610 },
188};
189#endif
190
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000191#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100192static struct gpio_bank gpio_bank_1510[2] = {
Russell King7c7095a2008-09-05 15:49:14 +0100193 { OMAP_MPUIO_VBASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100194 { OMAP1510_GPIO_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1510 }
195};
196#endif
197
198#ifdef CONFIG_ARCH_OMAP730
199static struct gpio_bank gpio_bank_730[7] = {
Russell King7c7095a2008-09-05 15:49:14 +0100200 { OMAP_MPUIO_VBASE, INT_730_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100201 { OMAP730_GPIO1_BASE, INT_730_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_730 },
202 { OMAP730_GPIO2_BASE, INT_730_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_730 },
203 { OMAP730_GPIO3_BASE, INT_730_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_730 },
204 { OMAP730_GPIO4_BASE, INT_730_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_730 },
205 { OMAP730_GPIO5_BASE, INT_730_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_730 },
206 { OMAP730_GPIO6_BASE, INT_730_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_730 },
207};
208#endif
209
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700210#ifdef CONFIG_ARCH_OMAP850
211static struct gpio_bank gpio_bank_850[7] = {
212 { OMAP_MPUIO_BASE, INT_850_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO },
213 { OMAP850_GPIO1_BASE, INT_850_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_850 },
214 { OMAP850_GPIO2_BASE, INT_850_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_850 },
215 { OMAP850_GPIO3_BASE, INT_850_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_850 },
216 { OMAP850_GPIO4_BASE, INT_850_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_850 },
217 { OMAP850_GPIO5_BASE, INT_850_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_850 },
218 { OMAP850_GPIO6_BASE, INT_850_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_850 },
219};
220#endif
221
222
Tony Lindgren92105bb2005-09-07 17:20:26 +0100223#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800224
225static struct gpio_bank gpio_bank_242x[4] = {
226 { OMAP242X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
227 { OMAP242X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
228 { OMAP242X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
229 { OMAP242X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
Tony Lindgren92105bb2005-09-07 17:20:26 +0100230};
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -0800231
232static struct gpio_bank gpio_bank_243x[5] = {
233 { OMAP243X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
234 { OMAP243X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
235 { OMAP243X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
236 { OMAP243X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
237 { OMAP243X_GPIO5_BASE, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX },
238};
239
Tony Lindgren92105bb2005-09-07 17:20:26 +0100240#endif
241
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800242#ifdef CONFIG_ARCH_OMAP34XX
243static struct gpio_bank gpio_bank_34xx[6] = {
244 { OMAP34XX_GPIO1_BASE, INT_34XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX },
245 { OMAP34XX_GPIO2_BASE, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX },
246 { OMAP34XX_GPIO3_BASE, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX },
247 { OMAP34XX_GPIO4_BASE, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX },
248 { OMAP34XX_GPIO5_BASE, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX },
249 { OMAP34XX_GPIO6_BASE, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_24XX },
250};
251
252#endif
253
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100254static struct gpio_bank *gpio_bank;
255static int gpio_bank_count;
256
257static inline struct gpio_bank *get_gpio_bank(int gpio)
258{
Tony Lindgren6e60e792006-04-02 17:46:23 +0100259 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100260 if (OMAP_GPIO_IS_MPUIO(gpio))
261 return &gpio_bank[0];
262 return &gpio_bank[1];
263 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100264 if (cpu_is_omap16xx()) {
265 if (OMAP_GPIO_IS_MPUIO(gpio))
266 return &gpio_bank[0];
267 return &gpio_bank[1 + (gpio >> 4)];
268 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700269 if (cpu_is_omap7xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100270 if (OMAP_GPIO_IS_MPUIO(gpio))
271 return &gpio_bank[0];
272 return &gpio_bank[1 + (gpio >> 5)];
273 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100274 if (cpu_is_omap24xx())
275 return &gpio_bank[gpio >> 5];
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800276 if (cpu_is_omap34xx())
277 return &gpio_bank[gpio >> 5];
David Brownelle031ab22008-12-10 17:35:27 -0800278 BUG();
279 return NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100280}
281
282static inline int get_gpio_index(int gpio)
283{
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700284 if (cpu_is_omap7xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100285 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100286 if (cpu_is_omap24xx())
287 return gpio & 0x1f;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800288 if (cpu_is_omap34xx())
289 return gpio & 0x1f;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100290 return gpio & 0x0f;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100291}
292
293static inline int gpio_valid(int gpio)
294{
295 if (gpio < 0)
296 return -1;
Tony Lindgrend11ac972008-01-12 15:35:04 -0800297 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
Jonathan McDowell193e68b2006-09-25 12:41:30 +0300298 if (gpio >= OMAP_MAX_GPIO_LINES + 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100299 return -1;
300 return 0;
301 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100302 if (cpu_is_omap15xx() && gpio < 16)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100303 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100304 if ((cpu_is_omap16xx()) && gpio < 64)
305 return 0;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700306 if (cpu_is_omap7xx() && gpio < 192)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100307 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100308 if (cpu_is_omap24xx() && gpio < 128)
309 return 0;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800310 if (cpu_is_omap34xx() && gpio < 160)
311 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100312 return -1;
313}
314
315static int check_gpio(int gpio)
316{
317 if (unlikely(gpio_valid(gpio)) < 0) {
318 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
319 dump_stack();
320 return -1;
321 }
322 return 0;
323}
324
325static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
326{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100327 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100328 u32 l;
329
330 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800331#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100332 case METHOD_MPUIO:
333 reg += OMAP_MPUIO_IO_CNTL;
334 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800335#endif
336#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100337 case METHOD_GPIO_1510:
338 reg += OMAP1510_GPIO_DIR_CONTROL;
339 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800340#endif
341#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100342 case METHOD_GPIO_1610:
343 reg += OMAP1610_GPIO_DIRECTION;
344 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800345#endif
346#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100347 case METHOD_GPIO_730:
348 reg += OMAP730_GPIO_DIR_CONTROL;
349 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800350#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700351#ifdef CONFIG_ARCH_OMAP850
352 case METHOD_GPIO_850:
353 reg += OMAP850_GPIO_DIR_CONTROL;
354 break;
355#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800356#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100357 case METHOD_GPIO_24XX:
358 reg += OMAP24XX_GPIO_OE;
359 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800360#endif
361 default:
362 WARN_ON(1);
363 return;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100364 }
365 l = __raw_readl(reg);
366 if (is_input)
367 l |= 1 << gpio;
368 else
369 l &= ~(1 << gpio);
370 __raw_writel(l, reg);
371}
372
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100373static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable)
374{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100375 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100376 u32 l = 0;
377
378 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800379#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100380 case METHOD_MPUIO:
381 reg += OMAP_MPUIO_OUTPUT;
382 l = __raw_readl(reg);
383 if (enable)
384 l |= 1 << gpio;
385 else
386 l &= ~(1 << gpio);
387 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800388#endif
389#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100390 case METHOD_GPIO_1510:
391 reg += OMAP1510_GPIO_DATA_OUTPUT;
392 l = __raw_readl(reg);
393 if (enable)
394 l |= 1 << gpio;
395 else
396 l &= ~(1 << gpio);
397 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800398#endif
399#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100400 case METHOD_GPIO_1610:
401 if (enable)
402 reg += OMAP1610_GPIO_SET_DATAOUT;
403 else
404 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
405 l = 1 << gpio;
406 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800407#endif
408#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100409 case METHOD_GPIO_730:
410 reg += OMAP730_GPIO_DATA_OUTPUT;
411 l = __raw_readl(reg);
412 if (enable)
413 l |= 1 << gpio;
414 else
415 l &= ~(1 << gpio);
416 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800417#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700418#ifdef CONFIG_ARCH_OMAP850
419 case METHOD_GPIO_850:
420 reg += OMAP850_GPIO_DATA_OUTPUT;
421 l = __raw_readl(reg);
422 if (enable)
423 l |= 1 << gpio;
424 else
425 l &= ~(1 << gpio);
426 break;
427#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800428#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100429 case METHOD_GPIO_24XX:
430 if (enable)
431 reg += OMAP24XX_GPIO_SETDATAOUT;
432 else
433 reg += OMAP24XX_GPIO_CLEARDATAOUT;
434 l = 1 << gpio;
435 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800436#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100437 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800438 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100439 return;
440 }
441 __raw_writel(l, reg);
442}
443
David Brownell0b84b5c2008-12-10 17:35:25 -0800444static int __omap_get_gpio_datain(int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100445{
446 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100447 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100448
449 if (check_gpio(gpio) < 0)
David Brownelle5c56ed2006-12-06 17:13:59 -0800450 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100451 bank = get_gpio_bank(gpio);
452 reg = bank->base;
453 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800454#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100455 case METHOD_MPUIO:
456 reg += OMAP_MPUIO_INPUT_LATCH;
457 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800458#endif
459#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100460 case METHOD_GPIO_1510:
461 reg += OMAP1510_GPIO_DATA_INPUT;
462 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800463#endif
464#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100465 case METHOD_GPIO_1610:
466 reg += OMAP1610_GPIO_DATAIN;
467 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800468#endif
469#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100470 case METHOD_GPIO_730:
471 reg += OMAP730_GPIO_DATA_INPUT;
472 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800473#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700474#ifdef CONFIG_ARCH_OMAP850
475 case METHOD_GPIO_850:
476 reg += OMAP850_GPIO_DATA_INPUT;
477 break;
478#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800479#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100480 case METHOD_GPIO_24XX:
481 reg += OMAP24XX_GPIO_DATAIN;
482 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800483#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100484 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800485 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100486 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100487 return (__raw_readl(reg)
488 & (1 << get_gpio_index(gpio))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100489}
490
Tony Lindgren92105bb2005-09-07 17:20:26 +0100491#define MOD_REG_BIT(reg, bit_mask, set) \
492do { \
493 int l = __raw_readl(base + reg); \
494 if (set) l |= bit_mask; \
495 else l &= ~bit_mask; \
496 __raw_writel(l, base + reg); \
497} while(0)
498
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700499void omap_set_gpio_debounce(int gpio, int enable)
500{
501 struct gpio_bank *bank;
502 void __iomem *reg;
David Brownelle031ab22008-12-10 17:35:27 -0800503 unsigned long flags;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700504 u32 val, l = 1 << get_gpio_index(gpio);
505
506 if (cpu_class_is_omap1())
507 return;
508
509 bank = get_gpio_bank(gpio);
510 reg = bank->base;
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700511 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
David Brownelle031ab22008-12-10 17:35:27 -0800512
513 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700514 val = __raw_readl(reg);
515
Jouni Hogander89db9482008-12-10 17:35:24 -0800516 if (enable && !(val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700517 val |= l;
David Brownelle031ab22008-12-10 17:35:27 -0800518 else if (!enable && (val & l))
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700519 val &= ~l;
Jouni Hogander89db9482008-12-10 17:35:24 -0800520 else
David Brownelle031ab22008-12-10 17:35:27 -0800521 goto done;
Jouni Hogander89db9482008-12-10 17:35:24 -0800522
David Brownelle031ab22008-12-10 17:35:27 -0800523 if (cpu_is_omap34xx()) {
524 if (enable)
525 clk_enable(bank->dbck);
526 else
527 clk_disable(bank->dbck);
528 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700529
530 __raw_writel(val, reg);
David Brownelle031ab22008-12-10 17:35:27 -0800531done:
532 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700533}
534EXPORT_SYMBOL(omap_set_gpio_debounce);
535
536void omap_set_gpio_debounce_time(int gpio, int enc_time)
537{
538 struct gpio_bank *bank;
539 void __iomem *reg;
540
541 if (cpu_class_is_omap1())
542 return;
543
544 bank = get_gpio_bank(gpio);
545 reg = bank->base;
546
547 enc_time &= 0xff;
548 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
549 __raw_writel(enc_time, reg);
550}
551EXPORT_SYMBOL(omap_set_gpio_debounce_time);
552
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800553#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700554static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
555 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100556{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800557 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100558 u32 gpio_bit = 1 << gpio;
559
560 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100561 trigger & IRQ_TYPE_LEVEL_LOW);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100562 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100563 trigger & IRQ_TYPE_LEVEL_HIGH);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100564 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100565 trigger & IRQ_TYPE_EDGE_RISING);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100566 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100567 trigger & IRQ_TYPE_EDGE_FALLING);
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700568
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800569 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
570 if (trigger != 0)
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700571 __raw_writel(1 << gpio, bank->base
572 + OMAP24XX_GPIO_SETWKUENA);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800573 else
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700574 __raw_writel(1 << gpio, bank->base
575 + OMAP24XX_GPIO_CLEARWKUENA);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800576 } else {
577 if (trigger != 0)
578 bank->enabled_non_wakeup_gpios |= gpio_bit;
579 else
580 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
581 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700582
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800583 bank->level_mask =
584 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
585 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100586}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800587#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100588
589static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
590{
591 void __iomem *reg = bank->base;
592 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100593
594 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800595#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100596 case METHOD_MPUIO:
597 reg += OMAP_MPUIO_GPIO_INT_EDGE;
598 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100599 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100600 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100601 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100602 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100603 else
604 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100605 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800606#endif
607#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100608 case METHOD_GPIO_1510:
609 reg += OMAP1510_GPIO_INT_CONTROL;
610 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100611 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100612 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100613 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100614 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100615 else
616 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100617 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800618#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800619#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100620 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100621 if (gpio & 0x08)
622 reg += OMAP1610_GPIO_EDGE_CTRL2;
623 else
624 reg += OMAP1610_GPIO_EDGE_CTRL1;
625 gpio &= 0x07;
626 l = __raw_readl(reg);
627 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100628 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100629 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100630 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100631 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800632 if (trigger)
633 /* Enable wake-up during idle for dynamic tick */
634 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
635 else
636 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100637 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800638#endif
639#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100640 case METHOD_GPIO_730:
641 reg += OMAP730_GPIO_INT_CONTROL;
642 l = __raw_readl(reg);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100643 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100644 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100645 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100646 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100647 else
648 goto bad;
649 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800650#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700651#ifdef CONFIG_ARCH_OMAP850
652 case METHOD_GPIO_850:
653 reg += OMAP850_GPIO_INT_CONTROL;
654 l = __raw_readl(reg);
655 if (trigger & IRQ_TYPE_EDGE_RISING)
656 l |= 1 << gpio;
657 else if (trigger & IRQ_TYPE_EDGE_FALLING)
658 l &= ~(1 << gpio);
659 else
660 goto bad;
661 break;
662#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800663#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100664 case METHOD_GPIO_24XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800665 set_24xx_gpio_triggering(bank, gpio, trigger);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100666 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800667#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100668 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100669 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100670 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100671 __raw_writel(l, reg);
672 return 0;
673bad:
674 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100675}
676
Tony Lindgren92105bb2005-09-07 17:20:26 +0100677static int gpio_irq_type(unsigned irq, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100678{
679 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100680 unsigned gpio;
681 int retval;
David Brownella6472532008-03-03 04:33:30 -0800682 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100683
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800684 if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100685 gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
686 else
687 gpio = irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100688
689 if (check_gpio(gpio) < 0)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100690 return -EINVAL;
691
David Brownelle5c56ed2006-12-06 17:13:59 -0800692 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100693 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800694
695 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800696 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800697 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100698 return -EINVAL;
699
David Brownell58781012006-12-06 17:14:10 -0800700 bank = get_irq_chip_data(irq);
David Brownella6472532008-03-03 04:33:30 -0800701 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100702 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type);
David Brownellb9772a22006-12-06 17:13:53 -0800703 if (retval == 0) {
704 irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK;
705 irq_desc[irq].status |= type;
706 }
David Brownella6472532008-03-03 04:33:30 -0800707 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800708
709 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
710 __set_irq_handler_unlocked(irq, handle_level_irq);
711 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
712 __set_irq_handler_unlocked(irq, handle_edge_irq);
713
Tony Lindgren92105bb2005-09-07 17:20:26 +0100714 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100715}
716
717static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
718{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100719 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100720
721 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800722#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100723 case METHOD_MPUIO:
724 /* MPUIO irqstatus is reset by reading the status register,
725 * so do nothing here */
726 return;
David Brownelle5c56ed2006-12-06 17:13:59 -0800727#endif
728#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100729 case METHOD_GPIO_1510:
730 reg += OMAP1510_GPIO_INT_STATUS;
731 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800732#endif
733#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100734 case METHOD_GPIO_1610:
735 reg += OMAP1610_GPIO_IRQSTATUS1;
736 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800737#endif
738#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100739 case METHOD_GPIO_730:
740 reg += OMAP730_GPIO_INT_STATUS;
741 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800742#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700743#ifdef CONFIG_ARCH_OMAP850
744 case METHOD_GPIO_850:
745 reg += OMAP850_GPIO_INT_STATUS;
746 break;
747#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800748#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100749 case METHOD_GPIO_24XX:
750 reg += OMAP24XX_GPIO_IRQSTATUS1;
751 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800752#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100753 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800754 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100755 return;
756 }
757 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300758
759 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800760#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
761 if (cpu_is_omap24xx() || cpu_is_omap34xx())
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300762 __raw_writel(gpio_mask, bank->base + OMAP24XX_GPIO_IRQSTATUS2);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800763#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100764}
765
766static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
767{
768 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio));
769}
770
Imre Deakea6dedd2006-06-26 16:16:00 -0700771static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
772{
773 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700774 int inv = 0;
775 u32 l;
776 u32 mask;
Imre Deakea6dedd2006-06-26 16:16:00 -0700777
778 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800779#ifdef CONFIG_ARCH_OMAP1
Imre Deakea6dedd2006-06-26 16:16:00 -0700780 case METHOD_MPUIO:
781 reg += OMAP_MPUIO_GPIO_MASKIT;
Imre Deak99c47702006-06-26 16:16:07 -0700782 mask = 0xffff;
783 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700784 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800785#endif
786#ifdef CONFIG_ARCH_OMAP15XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700787 case METHOD_GPIO_1510:
788 reg += OMAP1510_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700789 mask = 0xffff;
790 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700791 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800792#endif
793#ifdef CONFIG_ARCH_OMAP16XX
Imre Deakea6dedd2006-06-26 16:16:00 -0700794 case METHOD_GPIO_1610:
795 reg += OMAP1610_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700796 mask = 0xffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700797 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800798#endif
799#ifdef CONFIG_ARCH_OMAP730
Imre Deakea6dedd2006-06-26 16:16:00 -0700800 case METHOD_GPIO_730:
801 reg += OMAP730_GPIO_INT_MASK;
Imre Deak99c47702006-06-26 16:16:07 -0700802 mask = 0xffffffff;
803 inv = 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700804 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800805#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700806#ifdef CONFIG_ARCH_OMAP850
807 case METHOD_GPIO_850:
808 reg += OMAP850_GPIO_INT_MASK;
809 mask = 0xffffffff;
810 inv = 1;
811 break;
812#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800813#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Imre Deakea6dedd2006-06-26 16:16:00 -0700814 case METHOD_GPIO_24XX:
815 reg += OMAP24XX_GPIO_IRQENABLE1;
Imre Deak99c47702006-06-26 16:16:07 -0700816 mask = 0xffffffff;
Imre Deakea6dedd2006-06-26 16:16:00 -0700817 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800818#endif
Imre Deakea6dedd2006-06-26 16:16:00 -0700819 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800820 WARN_ON(1);
Imre Deakea6dedd2006-06-26 16:16:00 -0700821 return 0;
822 }
823
Imre Deak99c47702006-06-26 16:16:07 -0700824 l = __raw_readl(reg);
825 if (inv)
826 l = ~l;
827 l &= mask;
828 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700829}
830
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100831static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable)
832{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100833 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100834 u32 l;
835
836 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800837#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100838 case METHOD_MPUIO:
839 reg += OMAP_MPUIO_GPIO_MASKIT;
840 l = __raw_readl(reg);
841 if (enable)
842 l &= ~(gpio_mask);
843 else
844 l |= gpio_mask;
845 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800846#endif
847#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100848 case METHOD_GPIO_1510:
849 reg += OMAP1510_GPIO_INT_MASK;
850 l = __raw_readl(reg);
851 if (enable)
852 l &= ~(gpio_mask);
853 else
854 l |= gpio_mask;
855 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800856#endif
857#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100858 case METHOD_GPIO_1610:
859 if (enable)
860 reg += OMAP1610_GPIO_SET_IRQENABLE1;
861 else
862 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1;
863 l = gpio_mask;
864 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800865#endif
866#ifdef CONFIG_ARCH_OMAP730
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100867 case METHOD_GPIO_730:
868 reg += OMAP730_GPIO_INT_MASK;
869 l = __raw_readl(reg);
870 if (enable)
871 l &= ~(gpio_mask);
872 else
873 l |= gpio_mask;
874 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800875#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700876#ifdef CONFIG_ARCH_OMAP850
877 case METHOD_GPIO_850:
878 reg += OMAP850_GPIO_INT_MASK;
879 l = __raw_readl(reg);
880 if (enable)
881 l &= ~(gpio_mask);
882 else
883 l |= gpio_mask;
884 break;
885#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800886#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100887 case METHOD_GPIO_24XX:
888 if (enable)
889 reg += OMAP24XX_GPIO_SETIRQENABLE1;
890 else
891 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
892 l = gpio_mask;
893 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800894#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100895 default:
David Brownelle5c56ed2006-12-06 17:13:59 -0800896 WARN_ON(1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100897 return;
898 }
899 __raw_writel(l, reg);
900}
901
902static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
903{
904 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable);
905}
906
Tony Lindgren92105bb2005-09-07 17:20:26 +0100907/*
908 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
909 * 1510 does not seem to have a wake-up register. If JTAG is connected
910 * to the target, system will wake up always on GPIO events. While
911 * system is running all registered GPIO interrupts need to have wake-up
912 * enabled. When system is suspended, only selected GPIO interrupts need
913 * to have wake-up enabled.
914 */
915static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
916{
David Brownella6472532008-03-03 04:33:30 -0800917 unsigned long flags;
918
Tony Lindgren92105bb2005-09-07 17:20:26 +0100919 switch (bank->method) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800920#ifdef CONFIG_ARCH_OMAP16XX
David Brownell11a78b72006-12-06 17:14:11 -0800921 case METHOD_MPUIO:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100922 case METHOD_GPIO_1610:
David Brownella6472532008-03-03 04:33:30 -0800923 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -0700924 if (enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100925 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -0700926 else
Tony Lindgren92105bb2005-09-07 17:20:26 +0100927 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -0800928 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100929 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800930#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800931#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800932 case METHOD_GPIO_24XX:
David Brownell11a78b72006-12-06 17:14:11 -0800933 if (bank->non_wakeup_gpios & (1 << gpio)) {
934 printk(KERN_ERR "Unable to modify wakeup on "
935 "non-wakeup GPIO%d\n",
936 (bank - gpio_bank) * 32 + gpio);
937 return -EINVAL;
938 }
David Brownella6472532008-03-03 04:33:30 -0800939 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -0700940 if (enable)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800941 bank->suspend_wakeup |= (1 << gpio);
Kevin Hilmanb3bb4f62009-04-23 11:10:49 -0700942 else
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800943 bank->suspend_wakeup &= ~(1 << gpio);
David Brownella6472532008-03-03 04:33:30 -0800944 spin_unlock_irqrestore(&bank->lock, flags);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800945 return 0;
946#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100947 default:
948 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
949 bank->method);
950 return -EINVAL;
951 }
952}
953
Tony Lindgren4196dd62006-09-25 12:41:38 +0300954static void _reset_gpio(struct gpio_bank *bank, int gpio)
955{
956 _set_gpio_direction(bank, get_gpio_index(gpio), 1);
957 _set_gpio_irqenable(bank, gpio, 0);
958 _clear_gpio_irqstatus(bank, gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100959 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300960}
961
Tony Lindgren92105bb2005-09-07 17:20:26 +0100962/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
963static int gpio_wake_enable(unsigned int irq, unsigned int enable)
964{
965 unsigned int gpio = irq - IH_GPIO_BASE;
966 struct gpio_bank *bank;
967 int retval;
968
969 if (check_gpio(gpio) < 0)
970 return -ENODEV;
David Brownell58781012006-12-06 17:14:10 -0800971 bank = get_irq_chip_data(irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100972 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100973
974 return retval;
975}
976
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800977static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100978{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800979 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800980 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100981
David Brownella6472532008-03-03 04:33:30 -0800982 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100983
Tony Lindgren4196dd62006-09-25 12:41:38 +0300984 /* Set trigger to none. You need to enable the desired trigger with
985 * request_irq() or set_irq_type().
986 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800987 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100988
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000989#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100990 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +0100991 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100992
Tony Lindgren92105bb2005-09-07 17:20:26 +0100993 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100994 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800995 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100996 }
997#endif
David Brownella6472532008-03-03 04:33:30 -0800998 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100999
1000 return 0;
1001}
1002
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001003static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001004{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001005 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -08001006 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001007
David Brownella6472532008-03-03 04:33:30 -08001008 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001009#ifdef CONFIG_ARCH_OMAP16XX
1010 if (bank->method == METHOD_GPIO_1610) {
1011 /* Disable wake-up during idle for dynamic tick */
1012 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001013 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001014 }
1015#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001016#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001017 if (bank->method == METHOD_GPIO_24XX) {
1018 /* Disable wake-up during idle for dynamic tick */
1019 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001020 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001021 }
1022#endif
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001023 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -08001024 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001025}
1026
1027/*
1028 * We need to unmask the GPIO bank interrupt as soon as possible to
1029 * avoid missing GPIO interrupts for other lines in the bank.
1030 * Then we need to mask-read-clear-unmask the triggered GPIO lines
1031 * in the bank to avoid missing nested interrupts for a GPIO line.
1032 * If we wait to unmask individual GPIO lines in the bank after the
1033 * line's interrupt handler has been run, we may miss some nested
1034 * interrupts.
1035 */
Russell King10dd5ce2006-11-23 11:41:32 +00001036static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001037{
Tony Lindgren92105bb2005-09-07 17:20:26 +01001038 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001039 u32 isr;
1040 unsigned int gpio_irq;
1041 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -07001042 u32 retrigger = 0;
1043 int unmasked = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001044
1045 desc->chip->ack(irq);
1046
Thomas Gleixner418ca1f2006-07-01 22:32:41 +01001047 bank = get_irq_data(irq);
David Brownelle5c56ed2006-12-06 17:13:59 -08001048#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001049 if (bank->method == METHOD_MPUIO)
1050 isr_reg = bank->base + OMAP_MPUIO_GPIO_INT;
David Brownelle5c56ed2006-12-06 17:13:59 -08001051#endif
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001052#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001053 if (bank->method == METHOD_GPIO_1510)
1054 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1055#endif
1056#if defined(CONFIG_ARCH_OMAP16XX)
1057 if (bank->method == METHOD_GPIO_1610)
1058 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1059#endif
1060#ifdef CONFIG_ARCH_OMAP730
1061 if (bank->method == METHOD_GPIO_730)
1062 isr_reg = bank->base + OMAP730_GPIO_INT_STATUS;
1063#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001064#ifdef CONFIG_ARCH_OMAP850
1065 if (bank->method == METHOD_GPIO_850)
1066 isr_reg = bank->base + OMAP850_GPIO_INT_STATUS;
1067#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001068#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001069 if (bank->method == METHOD_GPIO_24XX)
1070 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1071#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001072 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +01001073 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -07001074 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001075
Imre Deakea6dedd2006-06-26 16:16:00 -07001076 enabled = _get_gpio_irqbank_mask(bank);
1077 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001078
1079 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
1080 isr &= 0x0000ffff;
1081
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001082 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001083 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -07001084 }
Tony Lindgren6e60e792006-04-02 17:46:23 +01001085
1086 /* clear edge sensitive interrupts before handler(s) are
1087 called so that we don't miss any interrupt occurred while
1088 executing them */
1089 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0);
1090 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1091 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1);
1092
1093 /* if there is only edge sensitive GPIO pin interrupts
1094 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -07001095 if (!level_mask && !unmasked) {
1096 unmasked = 1;
Tony Lindgren6e60e792006-04-02 17:46:23 +01001097 desc->chip->unmask(irq);
Imre Deakea6dedd2006-06-26 16:16:00 -07001098 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001099
Imre Deakea6dedd2006-06-26 16:16:00 -07001100 isr |= retrigger;
1101 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001102 if (!isr)
1103 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001104
Tony Lindgren92105bb2005-09-07 17:20:26 +01001105 gpio_irq = bank->virtual_irq_start;
1106 for (; isr != 0; isr >>= 1, gpio_irq++) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001107 if (!(isr & 1))
1108 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +02001109
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +01001110 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001111 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001112 }
Imre Deakea6dedd2006-06-26 16:16:00 -07001113 /* if bank has any level sensitive GPIO pin interrupt
1114 configured, we must unmask the bank interrupt only after
1115 handler(s) are executed in order to avoid spurious bank
1116 interrupt */
1117 if (!unmasked)
1118 desc->chip->unmask(irq);
1119
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001120}
1121
Tony Lindgren4196dd62006-09-25 12:41:38 +03001122static void gpio_irq_shutdown(unsigned int irq)
1123{
1124 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001125 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren4196dd62006-09-25 12:41:38 +03001126
1127 _reset_gpio(bank, gpio);
1128}
1129
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001130static void gpio_ack_irq(unsigned int irq)
1131{
1132 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001133 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001134
1135 _clear_gpio_irqstatus(bank, gpio);
1136}
1137
1138static void gpio_mask_irq(unsigned int irq)
1139{
1140 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001141 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001142
1143 _set_gpio_irqenable(bank, gpio, 0);
1144}
1145
1146static void gpio_unmask_irq(unsigned int irq)
1147{
1148 unsigned int gpio = irq - IH_GPIO_BASE;
David Brownell58781012006-12-06 17:14:10 -08001149 struct gpio_bank *bank = get_irq_chip_data(irq);
Kevin Hilmanb144ff62008-01-16 21:56:15 -08001150 unsigned int irq_mask = 1 << get_gpio_index(gpio);
1151
1152 /* For level-triggered GPIOs, the clearing must be done after
1153 * the HW source is cleared, thus after the handler has run */
1154 if (bank->level_mask & irq_mask) {
1155 _set_gpio_irqenable(bank, gpio, 0);
1156 _clear_gpio_irqstatus(bank, gpio);
1157 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001158
Kevin Hilman4de8c752008-01-16 21:56:14 -08001159 _set_gpio_irqenable(bank, gpio, 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001160}
1161
David Brownelle5c56ed2006-12-06 17:13:59 -08001162static struct irq_chip gpio_irq_chip = {
1163 .name = "GPIO",
1164 .shutdown = gpio_irq_shutdown,
1165 .ack = gpio_ack_irq,
1166 .mask = gpio_mask_irq,
1167 .unmask = gpio_unmask_irq,
1168 .set_type = gpio_irq_type,
1169 .set_wake = gpio_wake_enable,
1170};
1171
1172/*---------------------------------------------------------------------*/
1173
1174#ifdef CONFIG_ARCH_OMAP1
1175
1176/* MPUIO uses the always-on 32k clock */
1177
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001178static void mpuio_ack_irq(unsigned int irq)
1179{
1180 /* The ISR is reset automatically, so do nothing here. */
1181}
1182
1183static void mpuio_mask_irq(unsigned int irq)
1184{
1185 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001186 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001187
1188 _set_gpio_irqenable(bank, gpio, 0);
1189}
1190
1191static void mpuio_unmask_irq(unsigned int irq)
1192{
1193 unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE);
David Brownell58781012006-12-06 17:14:10 -08001194 struct gpio_bank *bank = get_irq_chip_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001195
1196 _set_gpio_irqenable(bank, gpio, 1);
1197}
1198
David Brownelle5c56ed2006-12-06 17:13:59 -08001199static struct irq_chip mpuio_irq_chip = {
1200 .name = "MPUIO",
1201 .ack = mpuio_ack_irq,
1202 .mask = mpuio_mask_irq,
1203 .unmask = mpuio_unmask_irq,
Tony Lindgren92105bb2005-09-07 17:20:26 +01001204 .set_type = gpio_irq_type,
David Brownell11a78b72006-12-06 17:14:11 -08001205#ifdef CONFIG_ARCH_OMAP16XX
1206 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1207 .set_wake = gpio_wake_enable,
1208#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001209};
1210
David Brownelle5c56ed2006-12-06 17:13:59 -08001211
1212#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1213
David Brownell11a78b72006-12-06 17:14:11 -08001214
1215#ifdef CONFIG_ARCH_OMAP16XX
1216
1217#include <linux/platform_device.h>
1218
1219static int omap_mpuio_suspend_late(struct platform_device *pdev, pm_message_t mesg)
1220{
1221 struct gpio_bank *bank = platform_get_drvdata(pdev);
1222 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001223 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001224
David Brownella6472532008-03-03 04:33:30 -08001225 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001226 bank->saved_wakeup = __raw_readl(mask_reg);
1227 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001228 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001229
1230 return 0;
1231}
1232
1233static int omap_mpuio_resume_early(struct platform_device *pdev)
1234{
1235 struct gpio_bank *bank = platform_get_drvdata(pdev);
1236 void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT;
David Brownella6472532008-03-03 04:33:30 -08001237 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -08001238
David Brownella6472532008-03-03 04:33:30 -08001239 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001240 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -08001241 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -08001242
1243 return 0;
1244}
1245
1246/* use platform_driver for this, now that there's no longer any
1247 * point to sys_device (other than not disturbing old code).
1248 */
1249static struct platform_driver omap_mpuio_driver = {
1250 .suspend_late = omap_mpuio_suspend_late,
1251 .resume_early = omap_mpuio_resume_early,
1252 .driver = {
1253 .name = "mpuio",
1254 },
1255};
1256
1257static struct platform_device omap_mpuio_device = {
1258 .name = "mpuio",
1259 .id = -1,
1260 .dev = {
1261 .driver = &omap_mpuio_driver.driver,
1262 }
1263 /* could list the /proc/iomem resources */
1264};
1265
1266static inline void mpuio_init(void)
1267{
David Brownellfcf126d2007-04-02 12:46:47 -07001268 platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]);
1269
David Brownell11a78b72006-12-06 17:14:11 -08001270 if (platform_driver_register(&omap_mpuio_driver) == 0)
1271 (void) platform_device_register(&omap_mpuio_device);
1272}
1273
1274#else
1275static inline void mpuio_init(void) {}
1276#endif /* 16xx */
1277
David Brownelle5c56ed2006-12-06 17:13:59 -08001278#else
1279
1280extern struct irq_chip mpuio_irq_chip;
1281
1282#define bank_is_mpuio(bank) 0
David Brownell11a78b72006-12-06 17:14:11 -08001283static inline void mpuio_init(void) {}
David Brownelle5c56ed2006-12-06 17:13:59 -08001284
1285#endif
1286
1287/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001288
David Brownell52e31342008-03-03 12:43:23 -08001289/* REVISIT these are stupid implementations! replace by ones that
1290 * don't switch on METHOD_* and which mostly avoid spinlocks
1291 */
1292
1293static int gpio_input(struct gpio_chip *chip, unsigned offset)
1294{
1295 struct gpio_bank *bank;
1296 unsigned long flags;
1297
1298 bank = container_of(chip, struct gpio_bank, chip);
1299 spin_lock_irqsave(&bank->lock, flags);
1300 _set_gpio_direction(bank, offset, 1);
1301 spin_unlock_irqrestore(&bank->lock, flags);
1302 return 0;
1303}
1304
1305static int gpio_get(struct gpio_chip *chip, unsigned offset)
1306{
David Brownell0b84b5c2008-12-10 17:35:25 -08001307 return __omap_get_gpio_datain(chip->base + offset);
David Brownell52e31342008-03-03 12:43:23 -08001308}
1309
1310static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1311{
1312 struct gpio_bank *bank;
1313 unsigned long flags;
1314
1315 bank = container_of(chip, struct gpio_bank, chip);
1316 spin_lock_irqsave(&bank->lock, flags);
1317 _set_gpio_dataout(bank, offset, value);
1318 _set_gpio_direction(bank, offset, 0);
1319 spin_unlock_irqrestore(&bank->lock, flags);
1320 return 0;
1321}
1322
1323static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1324{
1325 struct gpio_bank *bank;
1326 unsigned long flags;
1327
1328 bank = container_of(chip, struct gpio_bank, chip);
1329 spin_lock_irqsave(&bank->lock, flags);
1330 _set_gpio_dataout(bank, offset, value);
1331 spin_unlock_irqrestore(&bank->lock, flags);
1332}
1333
David Brownella007b702008-12-10 17:35:25 -08001334static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1335{
1336 struct gpio_bank *bank;
1337
1338 bank = container_of(chip, struct gpio_bank, chip);
1339 return bank->virtual_irq_start + offset;
1340}
1341
David Brownell52e31342008-03-03 12:43:23 -08001342/*---------------------------------------------------------------------*/
1343
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001344static int initialized;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001345#if !defined(CONFIG_ARCH_OMAP3)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001346static struct clk * gpio_ick;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001347#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001348
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001349#if defined(CONFIG_ARCH_OMAP2)
1350static struct clk * gpio_fck;
1351#endif
1352
1353#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001354static struct clk * gpio5_ick;
1355static struct clk * gpio5_fck;
1356#endif
1357
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001358#if defined(CONFIG_ARCH_OMAP3)
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001359static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS];
1360#endif
1361
David Brownell8ba55c52008-02-26 11:10:50 -08001362/* This lock class tells lockdep that GPIO irqs are in a different
1363 * category than their parents, so it won't report false recursion.
1364 */
1365static struct lock_class_key gpio_lock_class;
1366
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001367static int __init _omap_gpio_init(void)
1368{
1369 int i;
David Brownell52e31342008-03-03 12:43:23 -08001370 int gpio = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001371 struct gpio_bank *bank;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001372 char clk_name[11];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001373
1374 initialized = 1;
1375
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001376#if defined(CONFIG_ARCH_OMAP1)
Tony Lindgren6e60e792006-04-02 17:46:23 +01001377 if (cpu_is_omap15xx()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001378 gpio_ick = clk_get(NULL, "arm_gpio_ck");
1379 if (IS_ERR(gpio_ick))
Tony Lindgren92105bb2005-09-07 17:20:26 +01001380 printk("Could not get arm_gpio_ck\n");
1381 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001382 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001383 }
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001384#endif
1385#if defined(CONFIG_ARCH_OMAP2)
1386 if (cpu_class_is_omap2()) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001387 gpio_ick = clk_get(NULL, "gpios_ick");
1388 if (IS_ERR(gpio_ick))
1389 printk("Could not get gpios_ick\n");
1390 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001391 clk_enable(gpio_ick);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001392 gpio_fck = clk_get(NULL, "gpios_fck");
Komal Shah1630b522006-09-25 12:51:08 +03001393 if (IS_ERR(gpio_fck))
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001394 printk("Could not get gpios_fck\n");
1395 else
Tony Lindgren30ff7202006-01-17 15:33:51 -08001396 clk_enable(gpio_fck);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001397
1398 /*
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001399 * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001400 */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001401#if defined(CONFIG_ARCH_OMAP2430)
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001402 if (cpu_is_omap2430()) {
1403 gpio5_ick = clk_get(NULL, "gpio5_ick");
1404 if (IS_ERR(gpio5_ick))
1405 printk("Could not get gpio5_ick\n");
1406 else
1407 clk_enable(gpio5_ick);
1408 gpio5_fck = clk_get(NULL, "gpio5_fck");
1409 if (IS_ERR(gpio5_fck))
1410 printk("Could not get gpio5_fck\n");
1411 else
1412 clk_enable(gpio5_fck);
1413 }
1414#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001415 }
1416#endif
1417
1418#if defined(CONFIG_ARCH_OMAP3)
1419 if (cpu_is_omap34xx()) {
1420 for (i = 0; i < OMAP34XX_NR_GPIOS; i++) {
1421 sprintf(clk_name, "gpio%d_ick", i + 1);
1422 gpio_iclks[i] = clk_get(NULL, clk_name);
1423 if (IS_ERR(gpio_iclks[i]))
1424 printk(KERN_ERR "Could not get %s\n", clk_name);
1425 else
1426 clk_enable(gpio_iclks[i]);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001427 }
1428 }
1429#endif
1430
Tony Lindgren92105bb2005-09-07 17:20:26 +01001431
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001432#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren6e60e792006-04-02 17:46:23 +01001433 if (cpu_is_omap15xx()) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001434 printk(KERN_INFO "OMAP1510 GPIO hardware\n");
1435 gpio_bank_count = 2;
1436 gpio_bank = gpio_bank_1510;
1437 }
1438#endif
1439#if defined(CONFIG_ARCH_OMAP16XX)
1440 if (cpu_is_omap16xx()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001441 u32 rev;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001442
1443 gpio_bank_count = 5;
1444 gpio_bank = gpio_bank_1610;
Russell King7c7095a2008-09-05 15:49:14 +01001445 rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001446 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
1447 (rev >> 4) & 0x0f, rev & 0x0f);
1448 }
1449#endif
1450#ifdef CONFIG_ARCH_OMAP730
1451 if (cpu_is_omap730()) {
1452 printk(KERN_INFO "OMAP730 GPIO hardware\n");
1453 gpio_bank_count = 7;
1454 gpio_bank = gpio_bank_730;
1455 }
1456#endif
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001457#ifdef CONFIG_ARCH_OMAP850
1458 if (cpu_is_omap850()) {
1459 printk(KERN_INFO "OMAP850 GPIO hardware\n");
1460 gpio_bank_count = 7;
1461 gpio_bank = gpio_bank_850;
1462 }
1463#endif
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001464
Tony Lindgren92105bb2005-09-07 17:20:26 +01001465#ifdef CONFIG_ARCH_OMAP24XX
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001466 if (cpu_is_omap242x()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001467 int rev;
1468
1469 gpio_bank_count = 4;
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001470 gpio_bank = gpio_bank_242x;
Russell King7c7095a2008-09-05 15:49:14 +01001471 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001472 printk(KERN_INFO "OMAP242x GPIO hardware version %d.%d\n",
1473 (rev >> 4) & 0x0f, rev & 0x0f);
1474 }
1475 if (cpu_is_omap243x()) {
1476 int rev;
1477
1478 gpio_bank_count = 5;
1479 gpio_bank = gpio_bank_243x;
Russell King7c7095a2008-09-05 15:49:14 +01001480 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed Khasim56a25642006-12-06 17:14:08 -08001481 printk(KERN_INFO "OMAP243x GPIO hardware version %d.%d\n",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001482 (rev >> 4) & 0x0f, rev & 0x0f);
1483 }
1484#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001485#ifdef CONFIG_ARCH_OMAP34XX
1486 if (cpu_is_omap34xx()) {
1487 int rev;
1488
1489 gpio_bank_count = OMAP34XX_NR_GPIOS;
1490 gpio_bank = gpio_bank_34xx;
Russell King7c7095a2008-09-05 15:49:14 +01001491 rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001492 printk(KERN_INFO "OMAP34xx GPIO hardware version %d.%d\n",
1493 (rev >> 4) & 0x0f, rev & 0x0f);
1494 }
1495#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001496 for (i = 0; i < gpio_bank_count; i++) {
1497 int j, gpio_count = 16;
1498
1499 bank = &gpio_bank[i];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001500 spin_lock_init(&bank->lock);
David Brownelle5c56ed2006-12-06 17:13:59 -08001501 if (bank_is_mpuio(bank))
Russell King7c7095a2008-09-05 15:49:14 +01001502 __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001503 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001504 __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK);
1505 __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS);
1506 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001507 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001508 __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1);
1509 __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001510 __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001511 }
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001512 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_730) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001513 __raw_writel(0xffffffff, bank->base + OMAP730_GPIO_INT_MASK);
1514 __raw_writel(0x00000000, bank->base + OMAP730_GPIO_INT_STATUS);
1515
1516 gpio_count = 32; /* 730 has 32-bit GPIOs */
1517 }
Tony Lindgrend11ac972008-01-12 15:35:04 -08001518
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001519#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001520 if (bank->method == METHOD_GPIO_24XX) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001521 static const u32 non_wakeup_gpios[] = {
1522 0xe203ffc0, 0x08700040
1523 };
1524
Tony Lindgren92105bb2005-09-07 17:20:26 +01001525 __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1);
1526 __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1);
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001527 __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG);
1528
1529 /* Initialize interface clock ungated, module enabled */
1530 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001531 if (i < ARRAY_SIZE(non_wakeup_gpios))
1532 bank->non_wakeup_gpios = non_wakeup_gpios[i];
Tony Lindgren92105bb2005-09-07 17:20:26 +01001533 gpio_count = 32;
1534 }
1535#endif
David Brownell52e31342008-03-03 12:43:23 -08001536
1537 /* REVISIT eventually switch from OMAP-specific gpio structs
1538 * over to the generic ones
1539 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -08001540 bank->chip.request = omap_gpio_request;
1541 bank->chip.free = omap_gpio_free;
David Brownell52e31342008-03-03 12:43:23 -08001542 bank->chip.direction_input = gpio_input;
1543 bank->chip.get = gpio_get;
1544 bank->chip.direction_output = gpio_output;
1545 bank->chip.set = gpio_set;
David Brownella007b702008-12-10 17:35:25 -08001546 bank->chip.to_irq = gpio_2irq;
David Brownell52e31342008-03-03 12:43:23 -08001547 if (bank_is_mpuio(bank)) {
1548 bank->chip.label = "mpuio";
Russell King69114a42008-09-03 10:15:26 +01001549#ifdef CONFIG_ARCH_OMAP16XX
David Brownelld8f388d2008-07-25 01:46:07 -07001550 bank->chip.dev = &omap_mpuio_device.dev;
1551#endif
David Brownell52e31342008-03-03 12:43:23 -08001552 bank->chip.base = OMAP_MPUIO(0);
1553 } else {
1554 bank->chip.label = "gpio";
1555 bank->chip.base = gpio;
1556 gpio += gpio_count;
1557 }
1558 bank->chip.ngpio = gpio_count;
1559
1560 gpiochip_add(&bank->chip);
1561
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001562 for (j = bank->virtual_irq_start;
1563 j < bank->virtual_irq_start + gpio_count; j++) {
David Brownell8ba55c52008-02-26 11:10:50 -08001564 lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class);
David Brownell58781012006-12-06 17:14:10 -08001565 set_irq_chip_data(j, bank);
David Brownelle5c56ed2006-12-06 17:13:59 -08001566 if (bank_is_mpuio(bank))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001567 set_irq_chip(j, &mpuio_irq_chip);
1568 else
1569 set_irq_chip(j, &gpio_irq_chip);
Russell King10dd5ce2006-11-23 11:41:32 +00001570 set_irq_handler(j, handle_simple_irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001571 set_irq_flags(j, IRQF_VALID);
1572 }
1573 set_irq_chained_handler(bank->irq, gpio_irq_handler);
1574 set_irq_data(bank->irq, bank);
Jouni Hogander89db9482008-12-10 17:35:24 -08001575
1576 if (cpu_is_omap34xx()) {
1577 sprintf(clk_name, "gpio%d_dbck", i + 1);
1578 bank->dbck = clk_get(NULL, clk_name);
1579 if (IS_ERR(bank->dbck))
1580 printk(KERN_ERR "Could not get %s\n", clk_name);
1581 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001582 }
1583
1584 /* Enable system clock for GPIO module.
1585 * The CAM_CLK_CTRL *is* really the right place. */
Tony Lindgren92105bb2005-09-07 17:20:26 +01001586 if (cpu_is_omap16xx())
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001587 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL);
1588
Juha Yrjola14f1c3b2006-12-06 17:13:48 -08001589 /* Enable autoidle for the OCP interface */
1590 if (cpu_is_omap24xx())
1591 omap_writel(1 << 0, 0x48019010);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001592 if (cpu_is_omap34xx())
1593 omap_writel(1 << 0, 0x48306814);
Tony Lindgrend11ac972008-01-12 15:35:04 -08001594
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001595 return 0;
1596}
1597
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001598#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001599static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg)
1600{
1601 int i;
1602
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001603 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001604 return 0;
1605
1606 for (i = 0; i < gpio_bank_count; i++) {
1607 struct gpio_bank *bank = &gpio_bank[i];
1608 void __iomem *wake_status;
1609 void __iomem *wake_clear;
1610 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001611 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001612
1613 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001614#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001615 case METHOD_GPIO_1610:
1616 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1617 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1618 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1619 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001620#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001621#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001622 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001623 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001624 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1625 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1626 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001627#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001628 default:
1629 continue;
1630 }
1631
David Brownella6472532008-03-03 04:33:30 -08001632 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001633 bank->saved_wakeup = __raw_readl(wake_status);
1634 __raw_writel(0xffffffff, wake_clear);
1635 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001636 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001637 }
1638
1639 return 0;
1640}
1641
1642static int omap_gpio_resume(struct sys_device *dev)
1643{
1644 int i;
1645
Tero Kristo723fdb72008-11-26 14:35:16 -08001646 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001647 return 0;
1648
1649 for (i = 0; i < gpio_bank_count; i++) {
1650 struct gpio_bank *bank = &gpio_bank[i];
1651 void __iomem *wake_clear;
1652 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001653 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001654
1655 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001656#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001657 case METHOD_GPIO_1610:
1658 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1659 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1660 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001661#endif
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001662#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001663 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001664 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1665 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001666 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001667#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001668 default:
1669 continue;
1670 }
1671
David Brownella6472532008-03-03 04:33:30 -08001672 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001673 __raw_writel(0xffffffff, wake_clear);
1674 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001675 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001676 }
1677
1678 return 0;
1679}
1680
1681static struct sysdev_class omap_gpio_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01001682 .name = "gpio",
Tony Lindgren92105bb2005-09-07 17:20:26 +01001683 .suspend = omap_gpio_suspend,
1684 .resume = omap_gpio_resume,
1685};
1686
1687static struct sys_device omap_gpio_device = {
1688 .id = 0,
1689 .cls = &omap_gpio_sysclass,
1690};
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001691
1692#endif
1693
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001694#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001695
1696static int workaround_enabled;
1697
1698void omap2_gpio_prepare_for_retention(void)
1699{
1700 int i, c = 0;
1701
1702 /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious
1703 * IRQs will be generated. See OMAP2420 Errata item 1.101. */
1704 for (i = 0; i < gpio_bank_count; i++) {
1705 struct gpio_bank *bank = &gpio_bank[i];
1706 u32 l1, l2;
1707
1708 if (!(bank->enabled_non_wakeup_gpios))
1709 continue;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001710#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001711 bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1712 l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1713 l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001714#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001715 bank->saved_fallingdetect = l1;
1716 bank->saved_risingdetect = l2;
1717 l1 &= ~bank->enabled_non_wakeup_gpios;
1718 l2 &= ~bank->enabled_non_wakeup_gpios;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001719#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001720 __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1721 __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001722#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001723 c++;
1724 }
1725 if (!c) {
1726 workaround_enabled = 0;
1727 return;
1728 }
1729 workaround_enabled = 1;
1730}
1731
1732void omap2_gpio_resume_after_retention(void)
1733{
1734 int i;
1735
1736 if (!workaround_enabled)
1737 return;
1738 for (i = 0; i < gpio_bank_count; i++) {
1739 struct gpio_bank *bank = &gpio_bank[i];
1740 u32 l;
1741
1742 if (!(bank->enabled_non_wakeup_gpios))
1743 continue;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001744#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001745 __raw_writel(bank->saved_fallingdetect,
1746 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1747 __raw_writel(bank->saved_risingdetect,
1748 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001749#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001750 /* Check if any of the non-wakeup interrupt GPIOs have changed
1751 * state. If so, generate an IRQ by software. This is
1752 * horribly racy, but it's the best we can do to work around
1753 * this silicon bug. */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001754#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001755 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001756#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001757 l ^= bank->saved_datain;
1758 l &= bank->non_wakeup_gpios;
1759 if (l) {
1760 u32 old0, old1;
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001761#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001762 old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1763 old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
1764 __raw_writel(old0 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1765 __raw_writel(old1 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
1766 __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1767 __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001768#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001769 }
1770 }
1771
1772}
1773
Tony Lindgren92105bb2005-09-07 17:20:26 +01001774#endif
1775
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001776/*
1777 * This may get called early from board specific init
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001778 * for boards that have interrupts routed via FPGA.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001779 */
David Brownell277d58e2006-12-06 17:13:59 -08001780int __init omap_gpio_init(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001781{
1782 if (!initialized)
1783 return _omap_gpio_init();
1784 else
1785 return 0;
1786}
1787
Tony Lindgren92105bb2005-09-07 17:20:26 +01001788static int __init omap_gpio_sysinit(void)
1789{
1790 int ret = 0;
1791
1792 if (!initialized)
1793 ret = _omap_gpio_init();
1794
David Brownell11a78b72006-12-06 17:14:11 -08001795 mpuio_init();
1796
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001797#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
1798 if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001799 if (ret == 0) {
1800 ret = sysdev_class_register(&omap_gpio_sysclass);
1801 if (ret == 0)
1802 ret = sysdev_register(&omap_gpio_device);
1803 }
1804 }
1805#endif
1806
1807 return ret;
1808}
1809
Tony Lindgren92105bb2005-09-07 17:20:26 +01001810arch_initcall(omap_gpio_sysinit);
David Brownellb9772a22006-12-06 17:13:53 -08001811
1812
1813#ifdef CONFIG_DEBUG_FS
1814
1815#include <linux/debugfs.h>
1816#include <linux/seq_file.h>
1817
1818static int gpio_is_input(struct gpio_bank *bank, int mask)
1819{
1820 void __iomem *reg = bank->base;
1821
1822 switch (bank->method) {
1823 case METHOD_MPUIO:
1824 reg += OMAP_MPUIO_IO_CNTL;
1825 break;
1826 case METHOD_GPIO_1510:
1827 reg += OMAP1510_GPIO_DIR_CONTROL;
1828 break;
1829 case METHOD_GPIO_1610:
1830 reg += OMAP1610_GPIO_DIRECTION;
1831 break;
1832 case METHOD_GPIO_730:
1833 reg += OMAP730_GPIO_DIR_CONTROL;
1834 break;
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001835 case METHOD_GPIO_850:
1836 reg += OMAP850_GPIO_DIR_CONTROL;
1837 break;
David Brownellb9772a22006-12-06 17:13:53 -08001838 case METHOD_GPIO_24XX:
1839 reg += OMAP24XX_GPIO_OE;
1840 break;
1841 }
1842 return __raw_readl(reg) & mask;
1843}
1844
1845
1846static int dbg_gpio_show(struct seq_file *s, void *unused)
1847{
1848 unsigned i, j, gpio;
1849
1850 for (i = 0, gpio = 0; i < gpio_bank_count; i++) {
1851 struct gpio_bank *bank = gpio_bank + i;
1852 unsigned bankwidth = 16;
1853 u32 mask = 1;
1854
David Brownelle5c56ed2006-12-06 17:13:59 -08001855 if (bank_is_mpuio(bank))
David Brownellb9772a22006-12-06 17:13:53 -08001856 gpio = OMAP_MPUIO(0);
Zebediah C. McClure56739a62009-03-23 18:07:40 -07001857 else if (cpu_class_is_omap2() || cpu_is_omap730() ||
1858 cpu_is_omap850())
David Brownellb9772a22006-12-06 17:13:53 -08001859 bankwidth = 32;
1860
1861 for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) {
1862 unsigned irq, value, is_in, irqstat;
David Brownell52e31342008-03-03 12:43:23 -08001863 const char *label;
David Brownellb9772a22006-12-06 17:13:53 -08001864
David Brownell52e31342008-03-03 12:43:23 -08001865 label = gpiochip_is_requested(&bank->chip, j);
1866 if (!label)
David Brownellb9772a22006-12-06 17:13:53 -08001867 continue;
1868
1869 irq = bank->virtual_irq_start + j;
David Brownell0b84b5c2008-12-10 17:35:25 -08001870 value = gpio_get_value(gpio);
David Brownellb9772a22006-12-06 17:13:53 -08001871 is_in = gpio_is_input(bank, mask);
1872
David Brownelle5c56ed2006-12-06 17:13:59 -08001873 if (bank_is_mpuio(bank))
David Brownell52e31342008-03-03 12:43:23 -08001874 seq_printf(s, "MPUIO %2d ", j);
David Brownellb9772a22006-12-06 17:13:53 -08001875 else
David Brownell52e31342008-03-03 12:43:23 -08001876 seq_printf(s, "GPIO %3d ", gpio);
Jarkko Nikula21c867f2008-12-10 17:35:24 -08001877 seq_printf(s, "(%-20.20s): %s %s",
David Brownell52e31342008-03-03 12:43:23 -08001878 label,
David Brownellb9772a22006-12-06 17:13:53 -08001879 is_in ? "in " : "out",
1880 value ? "hi" : "lo");
1881
David Brownell52e31342008-03-03 12:43:23 -08001882/* FIXME for at least omap2, show pullup/pulldown state */
1883
David Brownellb9772a22006-12-06 17:13:53 -08001884 irqstat = irq_desc[irq].status;
Tony Lindgren3a26e332009-01-15 13:09:53 +02001885#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \
1886 defined(CONFIG_ARCH_OMAP34XX)
David Brownellb9772a22006-12-06 17:13:53 -08001887 if (is_in && ((bank->suspend_wakeup & mask)
1888 || irqstat & IRQ_TYPE_SENSE_MASK)) {
1889 char *trigger = NULL;
1890
1891 switch (irqstat & IRQ_TYPE_SENSE_MASK) {
1892 case IRQ_TYPE_EDGE_FALLING:
1893 trigger = "falling";
1894 break;
1895 case IRQ_TYPE_EDGE_RISING:
1896 trigger = "rising";
1897 break;
1898 case IRQ_TYPE_EDGE_BOTH:
1899 trigger = "bothedge";
1900 break;
1901 case IRQ_TYPE_LEVEL_LOW:
1902 trigger = "low";
1903 break;
1904 case IRQ_TYPE_LEVEL_HIGH:
1905 trigger = "high";
1906 break;
1907 case IRQ_TYPE_NONE:
David Brownell52e31342008-03-03 12:43:23 -08001908 trigger = "(?)";
David Brownellb9772a22006-12-06 17:13:53 -08001909 break;
1910 }
David Brownell52e31342008-03-03 12:43:23 -08001911 seq_printf(s, ", irq-%d %-8s%s",
David Brownellb9772a22006-12-06 17:13:53 -08001912 irq, trigger,
1913 (bank->suspend_wakeup & mask)
1914 ? " wakeup" : "");
1915 }
Tony Lindgren3a26e332009-01-15 13:09:53 +02001916#endif
David Brownellb9772a22006-12-06 17:13:53 -08001917 seq_printf(s, "\n");
1918 }
1919
David Brownelle5c56ed2006-12-06 17:13:59 -08001920 if (bank_is_mpuio(bank)) {
David Brownellb9772a22006-12-06 17:13:53 -08001921 seq_printf(s, "\n");
1922 gpio = 0;
1923 }
1924 }
1925 return 0;
1926}
1927
1928static int dbg_gpio_open(struct inode *inode, struct file *file)
1929{
David Brownelle5c56ed2006-12-06 17:13:59 -08001930 return single_open(file, dbg_gpio_show, &inode->i_private);
David Brownellb9772a22006-12-06 17:13:53 -08001931}
1932
1933static const struct file_operations debug_fops = {
1934 .open = dbg_gpio_open,
1935 .read = seq_read,
1936 .llseek = seq_lseek,
1937 .release = single_release,
1938};
1939
1940static int __init omap_gpio_debuginit(void)
1941{
David Brownelle5c56ed2006-12-06 17:13:59 -08001942 (void) debugfs_create_file("omap_gpio", S_IRUGO,
1943 NULL, NULL, &debug_fops);
David Brownellb9772a22006-12-06 17:13:53 -08001944 return 0;
1945}
1946late_initcall(omap_gpio_debuginit);
1947#endif