blob: 6788c8a2a77018592be77dd1fc97a4b618ae98b5 [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002 * Support functions for OMAP GPIO
3 *
Tony Lindgren92105bb2005-09-07 17:20:26 +01004 * Copyright (C) 2003-2005 Nokia Corporation
Jan Engelhardt96de0e22007-10-19 23:21:04 +02005 * Written by Juha Yrjölä <juha.yrjola@nokia.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01006 *
Santosh Shilimkar44169072009-05-28 14:16:04 -07007 * Copyright (C) 2009 Texas Instruments
8 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
9 *
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010015#include <linux/init.h>
16#include <linux/module.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010017#include <linux/interrupt.h>
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +020018#include <linux/syscore_ops.h>
Tony Lindgren92105bb2005-09-07 17:20:26 +010019#include <linux/err.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000020#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010021#include <linux/io.h>
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -080022#include <linux/slab.h>
23#include <linux/pm_runtime.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>
Russell King1bc857f2011-07-26 10:54:55 +010028#include <asm/gpio.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010029#include <asm/mach/irq.h>
30
Charulatha V03e128c2011-05-05 19:58:01 +053031static LIST_HEAD(omap_gpio_list);
32
Charulatha V6d62e212011-04-18 15:06:51 +000033struct gpio_regs {
34 u32 irqenable1;
35 u32 irqenable2;
36 u32 wake_en;
37 u32 ctrl;
38 u32 oe;
39 u32 leveldetect0;
40 u32 leveldetect1;
41 u32 risingdetect;
42 u32 fallingdetect;
43 u32 dataout;
44};
45
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010046struct gpio_bank {
Charulatha V03e128c2011-05-05 19:58:01 +053047 struct list_head node;
Tony Lindgren9f7065d2009-10-19 15:25:20 -070048 unsigned long pbase;
Tony Lindgren92105bb2005-09-07 17:20:26 +010049 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010050 u16 irq;
51 u16 virtual_irq_start;
Tony Lindgren92105bb2005-09-07 17:20:26 +010052 int method;
Tony Lindgren92105bb2005-09-07 17:20:26 +010053 u32 suspend_wakeup;
Janusz Krzysztofik78a43152011-08-23 13:42:24 +020054#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Tony Lindgren92105bb2005-09-07 17:20:26 +010055 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -080056#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -080057 u32 non_wakeup_gpios;
58 u32 enabled_non_wakeup_gpios;
Charulatha V6d62e212011-04-18 15:06:51 +000059 struct gpio_regs context;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -080060 u32 saved_datain;
61 u32 saved_fallingdetect;
62 u32 saved_risingdetect;
Kevin Hilmanb144ff62008-01-16 21:56:15 -080063 u32 level_mask;
Cory Maccarrone4318f362010-01-08 10:29:04 -080064 u32 toggle_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010065 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -080066 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -080067 struct clk *dbck;
Charulatha V058af1e2009-11-22 10:11:25 -080068 u32 mod_usage;
Kevin Hilman8865b9b2009-01-27 11:15:34 -080069 u32 dbck_enable_mask;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -080070 struct device *dev;
71 bool dbck_flag;
Charulatha V0cde8d02011-05-05 20:15:16 +053072 bool loses_context;
Tony Lindgren5de62b82010-12-07 16:26:58 -080073 int stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -070074 u32 width;
Charulatha V03e128c2011-05-05 19:58:01 +053075 u16 id;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070076
77 void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable);
78
79 struct omap_gpio_reg_offs *regs;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010080};
81
Kevin Hilman129fd222011-04-22 07:59:07 -070082#define GPIO_INDEX(bank, gpio) (gpio % bank->width)
83#define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010084
85static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
86{
Tony Lindgren92105bb2005-09-07 17:20:26 +010087 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010088 u32 l;
89
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070090 reg += bank->regs->direction;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010091 l = __raw_readl(reg);
92 if (is_input)
93 l |= 1 << gpio;
94 else
95 l &= ~(1 << gpio);
96 __raw_writel(l, reg);
97}
98
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070099
100/* set data out value using dedicate set/clear register */
101static void _set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, int enable)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100102{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100103 void __iomem *reg = bank->base;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700104 u32 l = GPIO_BIT(bank, gpio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100105
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700106 if (enable)
107 reg += bank->regs->set_dataout;
108 else
109 reg += bank->regs->clr_dataout;
110
111 __raw_writel(l, reg);
112}
113
114/* set data out value using mask register */
115static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable)
116{
117 void __iomem *reg = bank->base + bank->regs->dataout;
118 u32 gpio_bit = GPIO_BIT(bank, gpio);
119 u32 l;
120
121 l = __raw_readl(reg);
122 if (enable)
123 l |= gpio_bit;
124 else
125 l &= ~gpio_bit;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100126 __raw_writel(l, reg);
127}
128
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300129static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100130{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700131 void __iomem *reg = bank->base + bank->regs->datain;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100132
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700133 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100134}
135
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300136static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
137{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700138 void __iomem *reg = bank->base + bank->regs->dataout;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300139
Kevin Hilman129fd222011-04-22 07:59:07 -0700140 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300141}
142
Kevin Hilmanece95282011-07-12 08:18:15 -0700143static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
144{
145 int l = __raw_readl(base + reg);
146
147 if (set)
148 l |= mask;
149 else
150 l &= ~mask;
151
152 __raw_writel(l, base + reg);
153}
Tony Lindgren92105bb2005-09-07 17:20:26 +0100154
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700155/**
156 * _set_gpio_debounce - low level gpio debounce time
157 * @bank: the gpio bank we're acting upon
158 * @gpio: the gpio number on this @gpio
159 * @debounce: debounce time to use
160 *
161 * OMAP's debounce time is in 31us steps so we need
162 * to convert and round up to the closest unit.
163 */
164static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
165 unsigned debounce)
166{
Kevin Hilman9942da02011-04-22 12:02:05 -0700167 void __iomem *reg;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700168 u32 val;
169 u32 l;
170
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800171 if (!bank->dbck_flag)
172 return;
173
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700174 if (debounce < 32)
175 debounce = 0x01;
176 else if (debounce > 7936)
177 debounce = 0xff;
178 else
179 debounce = (debounce / 0x1f) - 1;
180
Kevin Hilman129fd222011-04-22 07:59:07 -0700181 l = GPIO_BIT(bank, gpio);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700182
Kevin Hilman9942da02011-04-22 12:02:05 -0700183 reg = bank->base + bank->regs->debounce;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700184 __raw_writel(debounce, reg);
185
Kevin Hilman9942da02011-04-22 12:02:05 -0700186 reg = bank->base + bank->regs->debounce_en;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700187 val = __raw_readl(reg);
188
189 if (debounce) {
190 val |= l;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800191 clk_enable(bank->dbck);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700192 } else {
193 val &= ~l;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800194 clk_disable(bank->dbck);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700195 }
Kevin Hilmanf7ec0b02010-06-09 13:53:07 +0300196 bank->dbck_enable_mask = val;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700197
198 __raw_writel(val, reg);
199}
200
Tony Lindgren140455f2010-02-12 12:26:48 -0800201#ifdef CONFIG_ARCH_OMAP2PLUS
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700202static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
203 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100204{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800205 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100206 u32 gpio_bit = 1 << gpio;
207
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530208 if (cpu_is_omap44xx()) {
Kevin Hilmanece95282011-07-12 08:18:15 -0700209 _gpio_rmw(base, OMAP4_GPIO_LEVELDETECT0, gpio_bit,
210 trigger & IRQ_TYPE_LEVEL_LOW);
211 _gpio_rmw(base, OMAP4_GPIO_LEVELDETECT1, gpio_bit,
212 trigger & IRQ_TYPE_LEVEL_HIGH);
213 _gpio_rmw(base, OMAP4_GPIO_RISINGDETECT, gpio_bit,
214 trigger & IRQ_TYPE_EDGE_RISING);
215 _gpio_rmw(base, OMAP4_GPIO_FALLINGDETECT, gpio_bit,
216 trigger & IRQ_TYPE_EDGE_FALLING);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530217 } else {
Kevin Hilmanece95282011-07-12 08:18:15 -0700218 _gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
219 trigger & IRQ_TYPE_LEVEL_LOW);
220 _gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
221 trigger & IRQ_TYPE_LEVEL_HIGH);
222 _gpio_rmw(base, OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
223 trigger & IRQ_TYPE_EDGE_RISING);
224 _gpio_rmw(base, OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
225 trigger & IRQ_TYPE_EDGE_FALLING);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530226 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800227 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530228 if (cpu_is_omap44xx()) {
Kevin Hilmanece95282011-07-12 08:18:15 -0700229 _gpio_rmw(base, OMAP4_GPIO_IRQWAKEN0, gpio_bit,
230 trigger != 0);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530231 } else {
Chunqiu Wang699117a62009-06-24 17:13:39 +0000232 /*
233 * GPIO wakeup request can only be generated on edge
234 * transitions
235 */
236 if (trigger & IRQ_TYPE_EDGE_BOTH)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530237 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700238 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530239 else
240 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700241 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530242 }
Tero Kristoa118b5f2008-12-22 14:27:12 +0200243 }
Ambresh K55b220c2011-06-15 13:40:45 -0700244 /* This part needs to be executed always for OMAP{34xx, 44xx} */
245 if (cpu_is_omap34xx() || cpu_is_omap44xx() ||
246 (bank->non_wakeup_gpios & gpio_bit)) {
Chunqiu Wang699117a62009-06-24 17:13:39 +0000247 /*
248 * Log the edge gpio and manually trigger the IRQ
249 * after resume if the input level changes
250 * to avoid irq lost during PER RET/OFF mode
251 * Applies for omap2 non-wakeup gpio and all omap3 gpios
252 */
253 if (trigger & IRQ_TYPE_EDGE_BOTH)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800254 bank->enabled_non_wakeup_gpios |= gpio_bit;
255 else
256 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
257 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700258
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530259 if (cpu_is_omap44xx()) {
260 bank->level_mask =
261 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
262 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
263 } else {
264 bank->level_mask =
265 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
266 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
267 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100268}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800269#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100270
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800271#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800272/*
273 * This only applies to chips that can't do both rising and falling edge
274 * detection at once. For all other chips, this function is a noop.
275 */
276static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
277{
278 void __iomem *reg = bank->base;
279 u32 l = 0;
280
281 switch (bank->method) {
Cory Maccarrone4318f362010-01-08 10:29:04 -0800282 case METHOD_MPUIO:
Tony Lindgren5de62b82010-12-07 16:26:58 -0800283 reg += OMAP_MPUIO_GPIO_INT_EDGE / bank->stride;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800284 break;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800285#ifdef CONFIG_ARCH_OMAP15XX
286 case METHOD_GPIO_1510:
287 reg += OMAP1510_GPIO_INT_CONTROL;
288 break;
289#endif
290#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
291 case METHOD_GPIO_7XX:
292 reg += OMAP7XX_GPIO_INT_CONTROL;
293 break;
294#endif
295 default:
296 return;
297 }
298
299 l = __raw_readl(reg);
300 if ((l >> gpio) & 1)
301 l &= ~(1 << gpio);
302 else
303 l |= 1 << gpio;
304
305 __raw_writel(l, reg);
306}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800307#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800308
Tony Lindgren92105bb2005-09-07 17:20:26 +0100309static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
310{
311 void __iomem *reg = bank->base;
312 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100313
314 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800315#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100316 case METHOD_MPUIO:
Tony Lindgren5de62b82010-12-07 16:26:58 -0800317 reg += OMAP_MPUIO_GPIO_INT_EDGE / bank->stride;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100318 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000319 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800320 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100321 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100322 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100323 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100324 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100325 else
326 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100327 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800328#endif
329#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100330 case METHOD_GPIO_1510:
331 reg += OMAP1510_GPIO_INT_CONTROL;
332 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000333 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800334 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100335 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100336 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100337 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100338 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100339 else
340 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100341 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800342#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800343#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100344 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100345 if (gpio & 0x08)
346 reg += OMAP1610_GPIO_EDGE_CTRL2;
347 else
348 reg += OMAP1610_GPIO_EDGE_CTRL1;
349 gpio &= 0x07;
350 l = __raw_readl(reg);
351 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100352 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100353 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100354 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100355 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800356 if (trigger)
357 /* Enable wake-up during idle for dynamic tick */
358 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
359 else
360 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100361 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800362#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100363#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100364 case METHOD_GPIO_7XX:
365 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700366 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000367 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800368 bank->toggle_mask |= 1 << gpio;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700369 if (trigger & IRQ_TYPE_EDGE_RISING)
370 l |= 1 << gpio;
371 else if (trigger & IRQ_TYPE_EDGE_FALLING)
372 l &= ~(1 << gpio);
373 else
374 goto bad;
375 break;
376#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800377#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +0100378 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800379 case METHOD_GPIO_44XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800380 set_24xx_gpio_triggering(bank, gpio, trigger);
Mika Westerbergf7c5cc42010-12-29 13:01:31 +0200381 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800382#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100383 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100384 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100385 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100386 __raw_writel(l, reg);
387 return 0;
388bad:
389 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100390}
391
Lennert Buytenheke9191022010-11-29 11:17:17 +0100392static int gpio_irq_type(struct irq_data *d, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100393{
394 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100395 unsigned gpio;
396 int retval;
David Brownella6472532008-03-03 04:33:30 -0800397 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100398
Lennert Buytenheke9191022010-11-29 11:17:17 +0100399 if (!cpu_class_is_omap2() && d->irq > IH_MPUIO_BASE)
400 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100401 else
Lennert Buytenheke9191022010-11-29 11:17:17 +0100402 gpio = d->irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100403
David Brownelle5c56ed2006-12-06 17:13:59 -0800404 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100405 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800406
407 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800408 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800409 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100410 return -EINVAL;
411
Lennert Buytenheke9191022010-11-29 11:17:17 +0100412 bank = irq_data_get_irq_chip_data(d);
David Brownella6472532008-03-03 04:33:30 -0800413 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman129fd222011-04-22 07:59:07 -0700414 retval = _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), type);
David Brownella6472532008-03-03 04:33:30 -0800415 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800416
417 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100418 __irq_set_handler_locked(d->irq, handle_level_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800419 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100420 __irq_set_handler_locked(d->irq, handle_edge_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800421
Tony Lindgren92105bb2005-09-07 17:20:26 +0100422 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100423}
424
425static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
426{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100427 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100428
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700429 reg += bank->regs->irqstatus;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100430 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300431
432 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700433 if (bank->regs->irqstatus2) {
434 reg = bank->base + bank->regs->irqstatus2;
Roger Quadrosbedfd152009-04-23 11:10:50 -0700435 __raw_writel(gpio_mask, reg);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700436 }
Roger Quadrosbedfd152009-04-23 11:10:50 -0700437
438 /* Flush posted write for the irq status to avoid spurious interrupts */
439 __raw_readl(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100440}
441
442static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
443{
Kevin Hilman129fd222011-04-22 07:59:07 -0700444 _clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100445}
446
Imre Deakea6dedd2006-06-26 16:16:00 -0700447static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
448{
449 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700450 u32 l;
Kevin Hilmanc390aad02011-04-21 09:33:36 -0700451 u32 mask = (1 << bank->width) - 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700452
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700453 reg += bank->regs->irqenable;
Imre Deak99c47702006-06-26 16:16:07 -0700454 l = __raw_readl(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700455 if (bank->regs->irqenable_inv)
Imre Deak99c47702006-06-26 16:16:07 -0700456 l = ~l;
457 l &= mask;
458 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700459}
460
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700461static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100462{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100463 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100464 u32 l;
465
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700466 if (bank->regs->set_irqenable) {
467 reg += bank->regs->set_irqenable;
468 l = gpio_mask;
469 } else {
470 reg += bank->regs->irqenable;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100471 l = __raw_readl(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700472 if (bank->regs->irqenable_inv)
473 l &= ~gpio_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100474 else
475 l |= gpio_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100476 }
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700477
478 __raw_writel(l, reg);
479}
480
481static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
482{
483 void __iomem *reg = bank->base;
484 u32 l;
485
486 if (bank->regs->clr_irqenable) {
487 reg += bank->regs->clr_irqenable;
488 l = gpio_mask;
489 } else {
490 reg += bank->regs->irqenable;
491 l = __raw_readl(reg);
492 if (bank->regs->irqenable_inv)
493 l |= gpio_mask;
494 else
495 l &= ~gpio_mask;
496 }
497
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100498 __raw_writel(l, reg);
499}
500
501static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
502{
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700503 _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100504}
505
Tony Lindgren92105bb2005-09-07 17:20:26 +0100506/*
507 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
508 * 1510 does not seem to have a wake-up register. If JTAG is connected
509 * to the target, system will wake up always on GPIO events. While
510 * system is running all registered GPIO interrupts need to have wake-up
511 * enabled. When system is suspended, only selected GPIO interrupts need
512 * to have wake-up enabled.
513 */
514static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
515{
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700516 u32 gpio_bit = GPIO_BIT(bank, gpio);
517 unsigned long flags;
David Brownella6472532008-03-03 04:33:30 -0800518
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700519 if (bank->non_wakeup_gpios & gpio_bit) {
520 dev_err(bank->dev,
521 "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100522 return -EINVAL;
523 }
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700524
525 spin_lock_irqsave(&bank->lock, flags);
526 if (enable)
527 bank->suspend_wakeup |= gpio_bit;
528 else
529 bank->suspend_wakeup &= ~gpio_bit;
530
531 spin_unlock_irqrestore(&bank->lock, flags);
532
533 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100534}
535
Tony Lindgren4196dd62006-09-25 12:41:38 +0300536static void _reset_gpio(struct gpio_bank *bank, int gpio)
537{
Kevin Hilman129fd222011-04-22 07:59:07 -0700538 _set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300539 _set_gpio_irqenable(bank, gpio, 0);
540 _clear_gpio_irqstatus(bank, gpio);
Kevin Hilman129fd222011-04-22 07:59:07 -0700541 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300542}
543
Tony Lindgren92105bb2005-09-07 17:20:26 +0100544/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
Lennert Buytenheke9191022010-11-29 11:17:17 +0100545static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100546{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100547 unsigned int gpio = d->irq - IH_GPIO_BASE;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100548 struct gpio_bank *bank;
549 int retval;
550
Lennert Buytenheke9191022010-11-29 11:17:17 +0100551 bank = irq_data_get_irq_chip_data(d);
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700552 retval = _set_gpio_wakeup(bank, gpio, enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100553
554 return retval;
555}
556
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800557static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100558{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800559 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800560 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100561
David Brownella6472532008-03-03 04:33:30 -0800562 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100563
Tony Lindgren4196dd62006-09-25 12:41:38 +0300564 /* Set trigger to none. You need to enable the desired trigger with
565 * request_irq() or set_irq_type().
566 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800567 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100568
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000569#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100570 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +0100571 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100572
Tony Lindgren92105bb2005-09-07 17:20:26 +0100573 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100574 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800575 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100576 }
577#endif
Charulatha V058af1e2009-11-22 10:11:25 -0800578 if (!cpu_class_is_omap1()) {
579 if (!bank->mod_usage) {
Charulatha V9f096862010-05-14 12:05:27 -0700580 void __iomem *reg = bank->base;
Charulatha V058af1e2009-11-22 10:11:25 -0800581 u32 ctrl;
Charulatha V9f096862010-05-14 12:05:27 -0700582
583 if (cpu_is_omap24xx() || cpu_is_omap34xx())
584 reg += OMAP24XX_GPIO_CTRL;
585 else if (cpu_is_omap44xx())
586 reg += OMAP4_GPIO_CTRL;
587 ctrl = __raw_readl(reg);
Charulatha V058af1e2009-11-22 10:11:25 -0800588 /* Module is enabled, clocks are not gated */
Charulatha V9f096862010-05-14 12:05:27 -0700589 ctrl &= 0xFFFFFFFE;
590 __raw_writel(ctrl, reg);
Charulatha V058af1e2009-11-22 10:11:25 -0800591 }
592 bank->mod_usage |= 1 << offset;
593 }
David Brownella6472532008-03-03 04:33:30 -0800594 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100595
596 return 0;
597}
598
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800599static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100600{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800601 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800602 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100603
David Brownella6472532008-03-03 04:33:30 -0800604 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100605#ifdef CONFIG_ARCH_OMAP16XX
606 if (bank->method == METHOD_GPIO_1610) {
607 /* Disable wake-up during idle for dynamic tick */
608 void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800609 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100610 }
611#endif
Charulatha V9f096862010-05-14 12:05:27 -0700612#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
613 if (bank->method == METHOD_GPIO_24XX) {
Tony Lindgren92105bb2005-09-07 17:20:26 +0100614 /* Disable wake-up during idle for dynamic tick */
615 void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800616 __raw_writel(1 << offset, reg);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100617 }
618#endif
Charulatha V9f096862010-05-14 12:05:27 -0700619#ifdef CONFIG_ARCH_OMAP4
620 if (bank->method == METHOD_GPIO_44XX) {
621 /* Disable wake-up during idle for dynamic tick */
622 void __iomem *reg = bank->base + OMAP4_GPIO_IRQWAKEN0;
623 __raw_writel(1 << offset, reg);
624 }
625#endif
Charulatha V058af1e2009-11-22 10:11:25 -0800626 if (!cpu_class_is_omap1()) {
627 bank->mod_usage &= ~(1 << offset);
628 if (!bank->mod_usage) {
Charulatha V9f096862010-05-14 12:05:27 -0700629 void __iomem *reg = bank->base;
Charulatha V058af1e2009-11-22 10:11:25 -0800630 u32 ctrl;
Charulatha V9f096862010-05-14 12:05:27 -0700631
632 if (cpu_is_omap24xx() || cpu_is_omap34xx())
633 reg += OMAP24XX_GPIO_CTRL;
634 else if (cpu_is_omap44xx())
635 reg += OMAP4_GPIO_CTRL;
636 ctrl = __raw_readl(reg);
Charulatha V058af1e2009-11-22 10:11:25 -0800637 /* Module is disabled, clocks are gated */
638 ctrl |= 1;
Charulatha V9f096862010-05-14 12:05:27 -0700639 __raw_writel(ctrl, reg);
Charulatha V058af1e2009-11-22 10:11:25 -0800640 }
641 }
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800642 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -0800643 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100644}
645
646/*
647 * We need to unmask the GPIO bank interrupt as soon as possible to
648 * avoid missing GPIO interrupts for other lines in the bank.
649 * Then we need to mask-read-clear-unmask the triggered GPIO lines
650 * in the bank to avoid missing nested interrupts for a GPIO line.
651 * If we wait to unmask individual GPIO lines in the bank after the
652 * line's interrupt handler has been run, we may miss some nested
653 * interrupts.
654 */
Russell King10dd5ce2006-11-23 11:41:32 +0000655static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100656{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100657 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100658 u32 isr;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800659 unsigned int gpio_irq, gpio_index;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100660 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -0700661 u32 retrigger = 0;
662 int unmasked = 0;
Will Deaconee144182011-02-21 13:46:08 +0000663 struct irq_chip *chip = irq_desc_get_chip(desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100664
Will Deaconee144182011-02-21 13:46:08 +0000665 chained_irq_enter(chip, desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100666
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100667 bank = irq_get_handler_data(irq);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700668 isr_reg = bank->base + bank->regs->irqstatus;
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800669
670 if (WARN_ON(!isr_reg))
671 goto exit;
672
Tony Lindgren92105bb2005-09-07 17:20:26 +0100673 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +0100674 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -0700675 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100676
Imre Deakea6dedd2006-06-26 16:16:00 -0700677 enabled = _get_gpio_irqbank_mask(bank);
678 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100679
680 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
681 isr &= 0x0000ffff;
682
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800683 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800684 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -0700685 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100686
687 /* clear edge sensitive interrupts before handler(s) are
688 called so that we don't miss any interrupt occurred while
689 executing them */
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700690 _disable_gpio_irqbank(bank, isr_saved & ~level_mask);
Tony Lindgren6e60e792006-04-02 17:46:23 +0100691 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700692 _enable_gpio_irqbank(bank, isr_saved & ~level_mask);
Tony Lindgren6e60e792006-04-02 17:46:23 +0100693
694 /* if there is only edge sensitive GPIO pin interrupts
695 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -0700696 if (!level_mask && !unmasked) {
697 unmasked = 1;
Will Deaconee144182011-02-21 13:46:08 +0000698 chained_irq_exit(chip, desc);
Imre Deakea6dedd2006-06-26 16:16:00 -0700699 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100700
Imre Deakea6dedd2006-06-26 16:16:00 -0700701 isr |= retrigger;
702 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100703 if (!isr)
704 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100705
Tony Lindgren92105bb2005-09-07 17:20:26 +0100706 gpio_irq = bank->virtual_irq_start;
707 for (; isr != 0; isr >>= 1, gpio_irq++) {
Kevin Hilman129fd222011-04-22 07:59:07 -0700708 gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq));
Cory Maccarrone4318f362010-01-08 10:29:04 -0800709
Tony Lindgren92105bb2005-09-07 17:20:26 +0100710 if (!(isr & 1))
711 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +0200712
Cory Maccarrone4318f362010-01-08 10:29:04 -0800713#ifdef CONFIG_ARCH_OMAP1
714 /*
715 * Some chips can't respond to both rising and falling
716 * at the same time. If this irq was requested with
717 * both flags, we need to flip the ICR data for the IRQ
718 * to respond to the IRQ for the opposite direction.
719 * This will be indicated in the bank toggle_mask.
720 */
721 if (bank->toggle_mask & (1 << gpio_index))
722 _toggle_gpio_edge_triggering(bank, gpio_index);
723#endif
724
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100725 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100726 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000727 }
Imre Deakea6dedd2006-06-26 16:16:00 -0700728 /* if bank has any level sensitive GPIO pin interrupt
729 configured, we must unmask the bank interrupt only after
730 handler(s) are executed in order to avoid spurious bank
731 interrupt */
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800732exit:
Imre Deakea6dedd2006-06-26 16:16:00 -0700733 if (!unmasked)
Will Deaconee144182011-02-21 13:46:08 +0000734 chained_irq_exit(chip, desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100735}
736
Lennert Buytenheke9191022010-11-29 11:17:17 +0100737static void gpio_irq_shutdown(struct irq_data *d)
Tony Lindgren4196dd62006-09-25 12:41:38 +0300738{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100739 unsigned int gpio = d->irq - IH_GPIO_BASE;
740 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700741 unsigned long flags;
Tony Lindgren4196dd62006-09-25 12:41:38 +0300742
Colin Cross85ec7b92011-06-06 13:38:18 -0700743 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300744 _reset_gpio(bank, gpio);
Colin Cross85ec7b92011-06-06 13:38:18 -0700745 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300746}
747
Lennert Buytenheke9191022010-11-29 11:17:17 +0100748static void gpio_ack_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100749{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100750 unsigned int gpio = d->irq - IH_GPIO_BASE;
751 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100752
753 _clear_gpio_irqstatus(bank, gpio);
754}
755
Lennert Buytenheke9191022010-11-29 11:17:17 +0100756static void gpio_mask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100757{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100758 unsigned int gpio = d->irq - IH_GPIO_BASE;
759 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700760 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100761
Colin Cross85ec7b92011-06-06 13:38:18 -0700762 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100763 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman129fd222011-04-22 07:59:07 -0700764 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
Colin Cross85ec7b92011-06-06 13:38:18 -0700765 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100766}
767
Lennert Buytenheke9191022010-11-29 11:17:17 +0100768static void gpio_unmask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100769{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100770 unsigned int gpio = d->irq - IH_GPIO_BASE;
771 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Kevin Hilman129fd222011-04-22 07:59:07 -0700772 unsigned int irq_mask = GPIO_BIT(bank, gpio);
Thomas Gleixner8c04a172011-03-24 12:40:15 +0100773 u32 trigger = irqd_get_trigger_type(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700774 unsigned long flags;
Kevin Hilman55b60192009-06-04 15:57:10 -0700775
Colin Cross85ec7b92011-06-06 13:38:18 -0700776 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman55b60192009-06-04 15:57:10 -0700777 if (trigger)
Kevin Hilman129fd222011-04-22 07:59:07 -0700778 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800779
780 /* For level-triggered GPIOs, the clearing must be done after
781 * the HW source is cleared, thus after the handler has run */
782 if (bank->level_mask & irq_mask) {
783 _set_gpio_irqenable(bank, gpio, 0);
784 _clear_gpio_irqstatus(bank, gpio);
785 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100786
Kevin Hilman4de8c752008-01-16 21:56:14 -0800787 _set_gpio_irqenable(bank, gpio, 1);
Colin Cross85ec7b92011-06-06 13:38:18 -0700788 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100789}
790
David Brownelle5c56ed2006-12-06 17:13:59 -0800791static struct irq_chip gpio_irq_chip = {
792 .name = "GPIO",
Lennert Buytenheke9191022010-11-29 11:17:17 +0100793 .irq_shutdown = gpio_irq_shutdown,
794 .irq_ack = gpio_ack_irq,
795 .irq_mask = gpio_mask_irq,
796 .irq_unmask = gpio_unmask_irq,
797 .irq_set_type = gpio_irq_type,
798 .irq_set_wake = gpio_wake_enable,
David Brownelle5c56ed2006-12-06 17:13:59 -0800799};
800
801/*---------------------------------------------------------------------*/
802
803#ifdef CONFIG_ARCH_OMAP1
804
David Brownelle5c56ed2006-12-06 17:13:59 -0800805#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
806
David Brownell11a78b72006-12-06 17:14:11 -0800807#ifdef CONFIG_ARCH_OMAP16XX
808
809#include <linux/platform_device.h>
810
Magnus Damm79ee0312009-07-08 13:22:04 +0200811static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800812{
Magnus Damm79ee0312009-07-08 13:22:04 +0200813 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800814 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800815 void __iomem *mask_reg = bank->base +
816 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800817 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800818
David Brownella6472532008-03-03 04:33:30 -0800819 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800820 bank->saved_wakeup = __raw_readl(mask_reg);
821 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800822 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800823
824 return 0;
825}
826
Magnus Damm79ee0312009-07-08 13:22:04 +0200827static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800828{
Magnus Damm79ee0312009-07-08 13:22:04 +0200829 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800830 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800831 void __iomem *mask_reg = bank->base +
832 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800833 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800834
David Brownella6472532008-03-03 04:33:30 -0800835 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800836 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800837 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800838
839 return 0;
840}
841
Alexey Dobriyan47145212009-12-14 18:00:08 -0800842static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +0200843 .suspend_noirq = omap_mpuio_suspend_noirq,
844 .resume_noirq = omap_mpuio_resume_noirq,
845};
846
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +0200847/* use platform_driver for this. */
David Brownell11a78b72006-12-06 17:14:11 -0800848static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -0800849 .driver = {
850 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +0200851 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -0800852 },
853};
854
855static struct platform_device omap_mpuio_device = {
856 .name = "mpuio",
857 .id = -1,
858 .dev = {
859 .driver = &omap_mpuio_driver.driver,
860 }
861 /* could list the /proc/iomem resources */
862};
863
Charulatha V03e128c2011-05-05 19:58:01 +0530864static inline void mpuio_init(struct gpio_bank *bank)
David Brownell11a78b72006-12-06 17:14:11 -0800865{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800866 platform_set_drvdata(&omap_mpuio_device, bank);
David Brownellfcf126d2007-04-02 12:46:47 -0700867
David Brownell11a78b72006-12-06 17:14:11 -0800868 if (platform_driver_register(&omap_mpuio_driver) == 0)
869 (void) platform_device_register(&omap_mpuio_device);
870}
871
872#else
Charulatha V03e128c2011-05-05 19:58:01 +0530873static inline void mpuio_init(struct gpio_bank *bank) {}
David Brownell11a78b72006-12-06 17:14:11 -0800874#endif /* 16xx */
875
David Brownelle5c56ed2006-12-06 17:13:59 -0800876#else
877
David Brownelle5c56ed2006-12-06 17:13:59 -0800878#define bank_is_mpuio(bank) 0
Charulatha V03e128c2011-05-05 19:58:01 +0530879static inline void mpuio_init(struct gpio_bank *bank) {}
David Brownelle5c56ed2006-12-06 17:13:59 -0800880
881#endif
882
883/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100884
David Brownell52e31342008-03-03 12:43:23 -0800885/* REVISIT these are stupid implementations! replace by ones that
886 * don't switch on METHOD_* and which mostly avoid spinlocks
887 */
888
889static int gpio_input(struct gpio_chip *chip, unsigned offset)
890{
891 struct gpio_bank *bank;
892 unsigned long flags;
893
894 bank = container_of(chip, struct gpio_bank, chip);
895 spin_lock_irqsave(&bank->lock, flags);
896 _set_gpio_direction(bank, offset, 1);
897 spin_unlock_irqrestore(&bank->lock, flags);
898 return 0;
899}
900
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300901static int gpio_is_input(struct gpio_bank *bank, int mask)
902{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700903 void __iomem *reg = bank->base + bank->regs->direction;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300904
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300905 return __raw_readl(reg) & mask;
906}
907
David Brownell52e31342008-03-03 12:43:23 -0800908static int gpio_get(struct gpio_chip *chip, unsigned offset)
909{
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300910 struct gpio_bank *bank;
911 void __iomem *reg;
912 int gpio;
913 u32 mask;
914
915 gpio = chip->base + offset;
Charulatha Va8be8da2011-04-22 16:38:16 +0530916 bank = container_of(chip, struct gpio_bank, chip);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300917 reg = bank->base;
Kevin Hilman129fd222011-04-22 07:59:07 -0700918 mask = GPIO_BIT(bank, gpio);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300919
920 if (gpio_is_input(bank, mask))
921 return _get_gpio_datain(bank, gpio);
922 else
923 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -0800924}
925
926static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
927{
928 struct gpio_bank *bank;
929 unsigned long flags;
930
931 bank = container_of(chip, struct gpio_bank, chip);
932 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700933 bank->set_dataout(bank, offset, value);
David Brownell52e31342008-03-03 12:43:23 -0800934 _set_gpio_direction(bank, offset, 0);
935 spin_unlock_irqrestore(&bank->lock, flags);
936 return 0;
937}
938
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700939static int gpio_debounce(struct gpio_chip *chip, unsigned offset,
940 unsigned debounce)
941{
942 struct gpio_bank *bank;
943 unsigned long flags;
944
945 bank = container_of(chip, struct gpio_bank, chip);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800946
947 if (!bank->dbck) {
948 bank->dbck = clk_get(bank->dev, "dbclk");
949 if (IS_ERR(bank->dbck))
950 dev_err(bank->dev, "Could not get gpio dbck\n");
951 }
952
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700953 spin_lock_irqsave(&bank->lock, flags);
954 _set_gpio_debounce(bank, offset, debounce);
955 spin_unlock_irqrestore(&bank->lock, flags);
956
957 return 0;
958}
959
David Brownell52e31342008-03-03 12:43:23 -0800960static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
961{
962 struct gpio_bank *bank;
963 unsigned long flags;
964
965 bank = container_of(chip, struct gpio_bank, chip);
966 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700967 bank->set_dataout(bank, offset, value);
David Brownell52e31342008-03-03 12:43:23 -0800968 spin_unlock_irqrestore(&bank->lock, flags);
969}
970
David Brownella007b702008-12-10 17:35:25 -0800971static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
972{
973 struct gpio_bank *bank;
974
975 bank = container_of(chip, struct gpio_bank, chip);
976 return bank->virtual_irq_start + offset;
977}
978
David Brownell52e31342008-03-03 12:43:23 -0800979/*---------------------------------------------------------------------*/
980
Tony Lindgren9a748052010-12-07 16:26:56 -0800981static void __init omap_gpio_show_rev(struct gpio_bank *bank)
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700982{
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700983 static bool called;
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700984 u32 rev;
985
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700986 if (called || bank->regs->revision == USHRT_MAX)
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700987 return;
988
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700989 rev = __raw_readw(bank->base + bank->regs->revision);
990 pr_info("OMAP GPIO hardware version %d.%d\n",
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700991 (rev >> 4) & 0x0f, rev & 0x0f);
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700992
993 called = true;
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700994}
995
David Brownell8ba55c52008-02-26 11:10:50 -0800996/* This lock class tells lockdep that GPIO irqs are in a different
997 * category than their parents, so it won't report false recursion.
998 */
999static struct lock_class_key gpio_lock_class;
1000
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001001/* TODO: Cleanup cpu_is_* checks */
Charulatha V03e128c2011-05-05 19:58:01 +05301002static void omap_gpio_mod_init(struct gpio_bank *bank)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001003{
1004 if (cpu_class_is_omap2()) {
1005 if (cpu_is_omap44xx()) {
1006 __raw_writel(0xffffffff, bank->base +
1007 OMAP4_GPIO_IRQSTATUSCLR0);
1008 __raw_writel(0x00000000, bank->base +
1009 OMAP4_GPIO_DEBOUNCENABLE);
1010 /* Initialize interface clk ungated, module enabled */
1011 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
1012 } else if (cpu_is_omap34xx()) {
1013 __raw_writel(0x00000000, bank->base +
1014 OMAP24XX_GPIO_IRQENABLE1);
1015 __raw_writel(0xffffffff, bank->base +
1016 OMAP24XX_GPIO_IRQSTATUS1);
1017 __raw_writel(0x00000000, bank->base +
1018 OMAP24XX_GPIO_DEBOUNCE_EN);
1019
1020 /* Initialize interface clk ungated, module enabled */
1021 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
1022 } else if (cpu_is_omap24xx()) {
1023 static const u32 non_wakeup_gpios[] = {
1024 0xe203ffc0, 0x08700040
1025 };
Charulatha V03e128c2011-05-05 19:58:01 +05301026 if (bank->id < ARRAY_SIZE(non_wakeup_gpios))
1027 bank->non_wakeup_gpios =
1028 non_wakeup_gpios[bank->id];
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001029 }
1030 } else if (cpu_class_is_omap1()) {
Charulatha V03e128c2011-05-05 19:58:01 +05301031 if (bank_is_mpuio(bank)) {
Tony Lindgren5de62b82010-12-07 16:26:58 -08001032 __raw_writew(0xffff, bank->base +
1033 OMAP_MPUIO_GPIO_MASKIT / bank->stride);
Charulatha V03e128c2011-05-05 19:58:01 +05301034 mpuio_init(bank);
1035 }
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001036 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
1037 __raw_writew(0xffff, bank->base
1038 + OMAP1510_GPIO_INT_MASK);
1039 __raw_writew(0x0000, bank->base
1040 + OMAP1510_GPIO_INT_STATUS);
1041 }
1042 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
1043 __raw_writew(0x0000, bank->base
1044 + OMAP1610_GPIO_IRQENABLE1);
1045 __raw_writew(0xffff, bank->base
1046 + OMAP1610_GPIO_IRQSTATUS1);
1047 __raw_writew(0x0014, bank->base
1048 + OMAP1610_GPIO_SYSCONFIG);
1049
1050 /*
1051 * Enable system clock for GPIO module.
1052 * The CAM_CLK_CTRL *is* really the right place.
1053 */
1054 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04,
1055 ULPD_CAM_CLK_CTRL);
1056 }
1057 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1058 __raw_writel(0xffffffff, bank->base
1059 + OMAP7XX_GPIO_INT_MASK);
1060 __raw_writel(0x00000000, bank->base
1061 + OMAP7XX_GPIO_INT_STATUS);
1062 }
1063 }
1064}
1065
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001066static __init void
1067omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start,
1068 unsigned int num)
1069{
1070 struct irq_chip_generic *gc;
1071 struct irq_chip_type *ct;
1072
1073 gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base,
1074 handle_simple_irq);
Todd Poynor83233742011-07-18 07:43:14 -07001075 if (!gc) {
1076 dev_err(bank->dev, "Memory alloc failed for gc\n");
1077 return;
1078 }
1079
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001080 ct = gc->chip_types;
1081
1082 /* NOTE: No ack required, reading IRQ status clears it. */
1083 ct->chip.irq_mask = irq_gc_mask_set_bit;
1084 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
1085 ct->chip.irq_set_type = gpio_irq_type;
1086 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1087 if (cpu_is_omap16xx())
1088 ct->chip.irq_set_wake = gpio_wake_enable,
1089
1090 ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride;
1091 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
1092 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
1093}
1094
Russell Kingd52b31d2011-05-27 13:56:12 -07001095static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001096{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001097 int j;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001098 static int gpio;
1099
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001100 bank->mod_usage = 0;
1101 /*
1102 * REVISIT eventually switch from OMAP-specific gpio structs
1103 * over to the generic ones
1104 */
1105 bank->chip.request = omap_gpio_request;
1106 bank->chip.free = omap_gpio_free;
1107 bank->chip.direction_input = gpio_input;
1108 bank->chip.get = gpio_get;
1109 bank->chip.direction_output = gpio_output;
1110 bank->chip.set_debounce = gpio_debounce;
1111 bank->chip.set = gpio_set;
1112 bank->chip.to_irq = gpio_2irq;
1113 if (bank_is_mpuio(bank)) {
1114 bank->chip.label = "mpuio";
1115#ifdef CONFIG_ARCH_OMAP16XX
1116 bank->chip.dev = &omap_mpuio_device.dev;
1117#endif
1118 bank->chip.base = OMAP_MPUIO(0);
1119 } else {
1120 bank->chip.label = "gpio";
1121 bank->chip.base = gpio;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001122 gpio += bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001123 }
Kevin Hilmand5f46242011-04-21 09:23:00 -07001124 bank->chip.ngpio = bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001125
1126 gpiochip_add(&bank->chip);
1127
1128 for (j = bank->virtual_irq_start;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001129 j < bank->virtual_irq_start + bank->width; j++) {
Thomas Gleixner1475b852011-03-22 17:11:09 +01001130 irq_set_lockdep_class(j, &gpio_lock_class);
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001131 irq_set_chip_data(j, bank);
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001132 if (bank_is_mpuio(bank)) {
1133 omap_mpuio_alloc_gc(bank, j, bank->width);
1134 } else {
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001135 irq_set_chip(j, &gpio_irq_chip);
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001136 irq_set_handler(j, handle_simple_irq);
1137 set_irq_flags(j, IRQF_VALID);
1138 }
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001139 }
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001140 irq_set_chained_handler(bank->irq, gpio_irq_handler);
1141 irq_set_handler_data(bank->irq, bank);
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001142}
1143
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001144static int __devinit omap_gpio_probe(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001145{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001146 struct omap_gpio_platform_data *pdata;
1147 struct resource *res;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001148 struct gpio_bank *bank;
Charulatha V03e128c2011-05-05 19:58:01 +05301149 int ret = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001150
Charulatha V03e128c2011-05-05 19:58:01 +05301151 if (!pdev->dev.platform_data) {
1152 ret = -EINVAL;
1153 goto err_exit;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001154 }
1155
Charulatha V03e128c2011-05-05 19:58:01 +05301156 bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
1157 if (!bank) {
1158 dev_err(&pdev->dev, "Memory alloc failed for gpio_bank\n");
1159 ret = -ENOMEM;
1160 goto err_exit;
1161 }
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001162
1163 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1164 if (unlikely(!res)) {
Charulatha V03e128c2011-05-05 19:58:01 +05301165 dev_err(&pdev->dev, "GPIO Bank %i Invalid IRQ resource\n",
1166 pdev->id);
1167 ret = -ENODEV;
1168 goto err_free;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001169 }
1170
1171 bank->irq = res->start;
Charulatha V03e128c2011-05-05 19:58:01 +05301172 bank->id = pdev->id;
1173
1174 pdata = pdev->dev.platform_data;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001175 bank->virtual_irq_start = pdata->virtual_irq_start;
1176 bank->method = pdata->bank_type;
1177 bank->dev = &pdev->dev;
1178 bank->dbck_flag = pdata->dbck_flag;
Tony Lindgren5de62b82010-12-07 16:26:58 -08001179 bank->stride = pdata->bank_stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001180 bank->width = pdata->bank_width;
Charulatha V0cde8d02011-05-05 20:15:16 +05301181 bank->loses_context = pdata->loses_context;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001182 bank->regs = pdata->regs;
1183
1184 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1185 bank->set_dataout = _set_gpio_dataout_reg;
1186 else
1187 bank->set_dataout = _set_gpio_dataout_mask;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001188
1189 spin_lock_init(&bank->lock);
1190
1191 /* Static mapping, never released */
1192 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1193 if (unlikely(!res)) {
Charulatha V03e128c2011-05-05 19:58:01 +05301194 dev_err(&pdev->dev, "GPIO Bank %i Invalid mem resource\n",
1195 pdev->id);
1196 ret = -ENODEV;
1197 goto err_free;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001198 }
1199
1200 bank->base = ioremap(res->start, resource_size(res));
1201 if (!bank->base) {
Charulatha V03e128c2011-05-05 19:58:01 +05301202 dev_err(&pdev->dev, "Could not ioremap gpio bank%i\n",
1203 pdev->id);
1204 ret = -ENOMEM;
1205 goto err_free;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001206 }
1207
1208 pm_runtime_enable(bank->dev);
1209 pm_runtime_get_sync(bank->dev);
1210
Charulatha V03e128c2011-05-05 19:58:01 +05301211 omap_gpio_mod_init(bank);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001212 omap_gpio_chip_init(bank);
Tony Lindgren9a748052010-12-07 16:26:56 -08001213 omap_gpio_show_rev(bank);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001214
Charulatha V03e128c2011-05-05 19:58:01 +05301215 list_add_tail(&bank->node, &omap_gpio_list);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001216
Charulatha V03e128c2011-05-05 19:58:01 +05301217 return ret;
1218
1219err_free:
1220 kfree(bank);
1221err_exit:
1222 return ret;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001223}
1224
Tony Lindgren140455f2010-02-12 12:26:48 -08001225#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001226static int omap_gpio_suspend(void)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001227{
Charulatha V03e128c2011-05-05 19:58:01 +05301228 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001229
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -08001230 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Tony Lindgren92105bb2005-09-07 17:20:26 +01001231 return 0;
1232
Charulatha V03e128c2011-05-05 19:58:01 +05301233 list_for_each_entry(bank, &omap_gpio_list, node) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001234 void __iomem *wake_status;
1235 void __iomem *wake_clear;
1236 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001237 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001238
1239 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001240#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001241 case METHOD_GPIO_1610:
1242 wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE;
1243 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1244 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1245 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001246#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001247#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001248 case METHOD_GPIO_24XX:
Tero Kristo723fdb72008-11-26 14:35:16 -08001249 wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001250 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1251 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
1252 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001253#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301254#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001255 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301256 wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0;
1257 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1258 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1259 break;
1260#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001261 default:
1262 continue;
1263 }
1264
David Brownella6472532008-03-03 04:33:30 -08001265 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001266 bank->saved_wakeup = __raw_readl(wake_status);
1267 __raw_writel(0xffffffff, wake_clear);
1268 __raw_writel(bank->suspend_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001269 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001270 }
1271
1272 return 0;
1273}
1274
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001275static void omap_gpio_resume(void)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001276{
Charulatha V03e128c2011-05-05 19:58:01 +05301277 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001278
Tero Kristo723fdb72008-11-26 14:35:16 -08001279 if (!cpu_class_is_omap2() && !cpu_is_omap16xx())
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001280 return;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001281
Charulatha V03e128c2011-05-05 19:58:01 +05301282 list_for_each_entry(bank, &omap_gpio_list, node) {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001283 void __iomem *wake_clear;
1284 void __iomem *wake_set;
David Brownella6472532008-03-03 04:33:30 -08001285 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001286
1287 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -08001288#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren92105bb2005-09-07 17:20:26 +01001289 case METHOD_GPIO_1610:
1290 wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA;
1291 wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA;
1292 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001293#endif
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001294#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001295 case METHOD_GPIO_24XX:
Tony Lindgren0d9356c2006-09-25 12:41:45 +03001296 wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA;
1297 wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001298 break;
David Brownelle5c56ed2006-12-06 17:13:59 -08001299#endif
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301300#ifdef CONFIG_ARCH_OMAP4
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001301 case METHOD_GPIO_44XX:
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301302 wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0;
1303 wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0;
1304 break;
1305#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +01001306 default:
1307 continue;
1308 }
1309
David Brownella6472532008-03-03 04:33:30 -08001310 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001311 __raw_writel(0xffffffff, wake_clear);
1312 __raw_writel(bank->saved_wakeup, wake_set);
David Brownella6472532008-03-03 04:33:30 -08001313 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001314 }
Tony Lindgren92105bb2005-09-07 17:20:26 +01001315}
1316
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001317static struct syscore_ops omap_gpio_syscore_ops = {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001318 .suspend = omap_gpio_suspend,
1319 .resume = omap_gpio_resume,
1320};
1321
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001322#endif
1323
Tony Lindgren140455f2010-02-12 12:26:48 -08001324#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001325
1326static int workaround_enabled;
1327
Paul Walmsley72e06d02010-12-21 21:05:16 -07001328void omap2_gpio_prepare_for_idle(int off_mode)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001329{
Charulatha V03e128c2011-05-05 19:58:01 +05301330 int c = 0;
1331 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001332
Charulatha V03e128c2011-05-05 19:58:01 +05301333 list_for_each_entry(bank, &omap_gpio_list, node) {
Sanjeev Premica828762010-09-23 18:27:18 -07001334 u32 l1 = 0, l2 = 0;
Kevin Hilman0aed04352010-09-22 16:06:27 -07001335 int j;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001336
Charulatha V0cde8d02011-05-05 20:15:16 +05301337 if (!bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301338 continue;
1339
Kevin Hilman0aed04352010-09-22 16:06:27 -07001340 for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++)
Kevin Hilman8865b9b2009-01-27 11:15:34 -08001341 clk_disable(bank->dbck);
1342
Paul Walmsley72e06d02010-12-21 21:05:16 -07001343 if (!off_mode)
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001344 continue;
1345
1346 /* If going to OFF, remove triggering for all
1347 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1348 * generated. See OMAP2420 Errata item 1.101. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001349 if (!(bank->enabled_non_wakeup_gpios))
1350 continue;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001351
1352 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
1353 bank->saved_datain = __raw_readl(bank->base +
1354 OMAP24XX_GPIO_DATAIN);
1355 l1 = __raw_readl(bank->base +
1356 OMAP24XX_GPIO_FALLINGDETECT);
1357 l2 = __raw_readl(bank->base +
1358 OMAP24XX_GPIO_RISINGDETECT);
1359 }
1360
1361 if (cpu_is_omap44xx()) {
1362 bank->saved_datain = __raw_readl(bank->base +
1363 OMAP4_GPIO_DATAIN);
1364 l1 = __raw_readl(bank->base +
1365 OMAP4_GPIO_FALLINGDETECT);
1366 l2 = __raw_readl(bank->base +
1367 OMAP4_GPIO_RISINGDETECT);
1368 }
1369
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001370 bank->saved_fallingdetect = l1;
1371 bank->saved_risingdetect = l2;
1372 l1 &= ~bank->enabled_non_wakeup_gpios;
1373 l2 &= ~bank->enabled_non_wakeup_gpios;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001374
1375 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
1376 __raw_writel(l1, bank->base +
1377 OMAP24XX_GPIO_FALLINGDETECT);
1378 __raw_writel(l2, bank->base +
1379 OMAP24XX_GPIO_RISINGDETECT);
1380 }
1381
1382 if (cpu_is_omap44xx()) {
1383 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
1384 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
1385 }
1386
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001387 c++;
1388 }
1389 if (!c) {
1390 workaround_enabled = 0;
1391 return;
1392 }
1393 workaround_enabled = 1;
1394}
1395
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001396void omap2_gpio_resume_after_idle(void)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001397{
Charulatha V03e128c2011-05-05 19:58:01 +05301398 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001399
Charulatha V03e128c2011-05-05 19:58:01 +05301400 list_for_each_entry(bank, &omap_gpio_list, node) {
Sanjeev Premica828762010-09-23 18:27:18 -07001401 u32 l = 0, gen, gen0, gen1;
Kevin Hilman0aed04352010-09-22 16:06:27 -07001402 int j;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001403
Charulatha V0cde8d02011-05-05 20:15:16 +05301404 if (!bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301405 continue;
1406
Kevin Hilman0aed04352010-09-22 16:06:27 -07001407 for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++)
Kevin Hilman8865b9b2009-01-27 11:15:34 -08001408 clk_enable(bank->dbck);
1409
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001410 if (!workaround_enabled)
1411 continue;
1412
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001413 if (!(bank->enabled_non_wakeup_gpios))
1414 continue;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001415
1416 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
1417 __raw_writel(bank->saved_fallingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001418 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001419 __raw_writel(bank->saved_risingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001420 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001421 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1422 }
1423
1424 if (cpu_is_omap44xx()) {
1425 __raw_writel(bank->saved_fallingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301426 bank->base + OMAP4_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001427 __raw_writel(bank->saved_risingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301428 bank->base + OMAP4_GPIO_RISINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001429 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
1430 }
1431
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001432 /* Check if any of the non-wakeup interrupt GPIOs have changed
1433 * state. If so, generate an IRQ by software. This is
1434 * horribly racy, but it's the best we can do to work around
1435 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001436 l ^= bank->saved_datain;
Tero Kristoa118b5f2008-12-22 14:27:12 +02001437 l &= bank->enabled_non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07001438
1439 /*
1440 * No need to generate IRQs for the rising edge for gpio IRQs
1441 * configured with falling edge only; and vice versa.
1442 */
1443 gen0 = l & bank->saved_fallingdetect;
1444 gen0 &= bank->saved_datain;
1445
1446 gen1 = l & bank->saved_risingdetect;
1447 gen1 &= ~(bank->saved_datain);
1448
1449 /* FIXME: Consider GPIO IRQs with level detections properly! */
1450 gen = l & (~(bank->saved_fallingdetect) &
1451 ~(bank->saved_risingdetect));
1452 /* Consider all GPIO IRQs needed to be updated */
1453 gen |= gen0 | gen1;
1454
1455 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001456 u32 old0, old1;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001457
Sergio Aguirref00d6492010-03-03 16:21:08 +00001458 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001459 old0 = __raw_readl(bank->base +
1460 OMAP24XX_GPIO_LEVELDETECT0);
1461 old1 = __raw_readl(bank->base +
1462 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00001463 __raw_writel(old0 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07001464 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00001465 __raw_writel(old1 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07001466 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00001467 __raw_writel(old0, bank->base +
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001468 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00001469 __raw_writel(old1, bank->base +
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001470 OMAP24XX_GPIO_LEVELDETECT1);
1471 }
1472
1473 if (cpu_is_omap44xx()) {
1474 old0 = __raw_readl(bank->base +
1475 OMAP4_GPIO_LEVELDETECT0);
1476 old1 = __raw_readl(bank->base +
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301477 OMAP4_GPIO_LEVELDETECT1);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001478 __raw_writel(old0 | l, bank->base +
1479 OMAP4_GPIO_LEVELDETECT0);
1480 __raw_writel(old1 | l, bank->base +
1481 OMAP4_GPIO_LEVELDETECT1);
1482 __raw_writel(old0, bank->base +
1483 OMAP4_GPIO_LEVELDETECT0);
1484 __raw_writel(old1, bank->base +
1485 OMAP4_GPIO_LEVELDETECT1);
1486 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001487 }
1488 }
1489
1490}
1491
Tony Lindgren92105bb2005-09-07 17:20:26 +01001492#endif
1493
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001494#ifdef CONFIG_ARCH_OMAP3
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301495void omap_gpio_save_context(void)
1496{
Charulatha V03e128c2011-05-05 19:58:01 +05301497 struct gpio_bank *bank;
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301498
Charulatha V03e128c2011-05-05 19:58:01 +05301499 list_for_each_entry(bank, &omap_gpio_list, node) {
Charulatha V03e128c2011-05-05 19:58:01 +05301500
Charulatha V0cde8d02011-05-05 20:15:16 +05301501 if (!bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301502 continue;
1503
Charulatha V6d62e212011-04-18 15:06:51 +00001504 bank->context.irqenable1 =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301505 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
Charulatha V6d62e212011-04-18 15:06:51 +00001506 bank->context.irqenable2 =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301507 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
Charulatha V6d62e212011-04-18 15:06:51 +00001508 bank->context.wake_en =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301509 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
Charulatha V6d62e212011-04-18 15:06:51 +00001510 bank->context.ctrl =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301511 __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
Charulatha V6d62e212011-04-18 15:06:51 +00001512 bank->context.oe =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301513 __raw_readl(bank->base + OMAP24XX_GPIO_OE);
Charulatha V6d62e212011-04-18 15:06:51 +00001514 bank->context.leveldetect0 =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301515 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
Charulatha V6d62e212011-04-18 15:06:51 +00001516 bank->context.leveldetect1 =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301517 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Charulatha V6d62e212011-04-18 15:06:51 +00001518 bank->context.risingdetect =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301519 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
Charulatha V6d62e212011-04-18 15:06:51 +00001520 bank->context.fallingdetect =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301521 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
Charulatha V6d62e212011-04-18 15:06:51 +00001522 bank->context.dataout =
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301523 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301524 }
1525}
1526
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301527void omap_gpio_restore_context(void)
1528{
Charulatha V03e128c2011-05-05 19:58:01 +05301529 struct gpio_bank *bank;
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301530
Charulatha V03e128c2011-05-05 19:58:01 +05301531 list_for_each_entry(bank, &omap_gpio_list, node) {
Charulatha V03e128c2011-05-05 19:58:01 +05301532
Charulatha V0cde8d02011-05-05 20:15:16 +05301533 if (!bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301534 continue;
1535
Charulatha V6d62e212011-04-18 15:06:51 +00001536 __raw_writel(bank->context.irqenable1,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301537 bank->base + OMAP24XX_GPIO_IRQENABLE1);
Charulatha V6d62e212011-04-18 15:06:51 +00001538 __raw_writel(bank->context.irqenable2,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301539 bank->base + OMAP24XX_GPIO_IRQENABLE2);
Charulatha V6d62e212011-04-18 15:06:51 +00001540 __raw_writel(bank->context.wake_en,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301541 bank->base + OMAP24XX_GPIO_WAKE_EN);
Charulatha V6d62e212011-04-18 15:06:51 +00001542 __raw_writel(bank->context.ctrl,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301543 bank->base + OMAP24XX_GPIO_CTRL);
Charulatha V6d62e212011-04-18 15:06:51 +00001544 __raw_writel(bank->context.oe,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301545 bank->base + OMAP24XX_GPIO_OE);
Charulatha V6d62e212011-04-18 15:06:51 +00001546 __raw_writel(bank->context.leveldetect0,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301547 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
Charulatha V6d62e212011-04-18 15:06:51 +00001548 __raw_writel(bank->context.leveldetect1,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301549 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
Charulatha V6d62e212011-04-18 15:06:51 +00001550 __raw_writel(bank->context.risingdetect,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301551 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Charulatha V6d62e212011-04-18 15:06:51 +00001552 __raw_writel(bank->context.fallingdetect,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301553 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
Charulatha V6d62e212011-04-18 15:06:51 +00001554 __raw_writel(bank->context.dataout,
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301555 bank->base + OMAP24XX_GPIO_DATAOUT);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301556 }
1557}
1558#endif
1559
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001560static struct platform_driver omap_gpio_driver = {
1561 .probe = omap_gpio_probe,
1562 .driver = {
1563 .name = "omap_gpio",
1564 },
1565};
1566
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001567/*
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001568 * gpio driver register needs to be done before
1569 * machine_init functions access gpio APIs.
1570 * Hence omap_gpio_drv_reg() is a postcore_initcall.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001571 */
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001572static int __init omap_gpio_drv_reg(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001573{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001574 return platform_driver_register(&omap_gpio_driver);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001575}
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001576postcore_initcall(omap_gpio_drv_reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001577
Tony Lindgren92105bb2005-09-07 17:20:26 +01001578static int __init omap_gpio_sysinit(void)
1579{
David Brownell11a78b72006-12-06 17:14:11 -08001580
Tony Lindgren140455f2010-02-12 12:26:48 -08001581#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001582 if (cpu_is_omap16xx() || cpu_class_is_omap2())
1583 register_syscore_ops(&omap_gpio_syscore_ops);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001584#endif
1585
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001586 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001587}
1588
Tony Lindgren92105bb2005-09-07 17:20:26 +01001589arch_initcall(omap_gpio_sysinit);