blob: 3daedffbd707a7518c63107049fa743eb4ffc5f0 [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;
54 u32 saved_wakeup;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -080055 u32 non_wakeup_gpios;
56 u32 enabled_non_wakeup_gpios;
Charulatha V6d62e212011-04-18 15:06:51 +000057 struct gpio_regs context;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -080058 u32 saved_datain;
59 u32 saved_fallingdetect;
60 u32 saved_risingdetect;
Kevin Hilmanb144ff62008-01-16 21:56:15 -080061 u32 level_mask;
Cory Maccarrone4318f362010-01-08 10:29:04 -080062 u32 toggle_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010063 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -080064 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -080065 struct clk *dbck;
Charulatha V058af1e2009-11-22 10:11:25 -080066 u32 mod_usage;
Kevin Hilman8865b9b2009-01-27 11:15:34 -080067 u32 dbck_enable_mask;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -080068 struct device *dev;
69 bool dbck_flag;
Charulatha V0cde8d02011-05-05 20:15:16 +053070 bool loses_context;
Tony Lindgren5de62b82010-12-07 16:26:58 -080071 int stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -070072 u32 width;
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +053073 int context_loss_count;
Charulatha V03e128c2011-05-05 19:58:01 +053074 u16 id;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070075
76 void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable);
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +053077 int (*get_context_loss_count)(struct device *dev);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070078
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))
Charulatha Vc8eef652011-05-02 15:21:42 +053084#define GPIO_MOD_CTRL_BIT BIT(0)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010085
86static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
87{
Tony Lindgren92105bb2005-09-07 17:20:26 +010088 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010089 u32 l;
90
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070091 reg += bank->regs->direction;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010092 l = __raw_readl(reg);
93 if (is_input)
94 l |= 1 << gpio;
95 else
96 l &= ~(1 << gpio);
97 __raw_writel(l, reg);
98}
99
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700100
101/* set data out value using dedicate set/clear register */
102static void _set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, int enable)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100103{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100104 void __iomem *reg = bank->base;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700105 u32 l = GPIO_BIT(bank, gpio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100106
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700107 if (enable)
108 reg += bank->regs->set_dataout;
109 else
110 reg += bank->regs->clr_dataout;
111
112 __raw_writel(l, reg);
113}
114
115/* set data out value using mask register */
116static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable)
117{
118 void __iomem *reg = bank->base + bank->regs->dataout;
119 u32 gpio_bit = GPIO_BIT(bank, gpio);
120 u32 l;
121
122 l = __raw_readl(reg);
123 if (enable)
124 l |= gpio_bit;
125 else
126 l &= ~gpio_bit;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100127 __raw_writel(l, reg);
128}
129
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300130static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100131{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700132 void __iomem *reg = bank->base + bank->regs->datain;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100133
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700134 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100135}
136
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300137static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
138{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700139 void __iomem *reg = bank->base + bank->regs->dataout;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300140
Kevin Hilman129fd222011-04-22 07:59:07 -0700141 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300142}
143
Kevin Hilmanece95282011-07-12 08:18:15 -0700144static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
145{
146 int l = __raw_readl(base + reg);
147
148 if (set)
149 l |= mask;
150 else
151 l &= ~mask;
152
153 __raw_writel(l, base + reg);
154}
Tony Lindgren92105bb2005-09-07 17:20:26 +0100155
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700156/**
157 * _set_gpio_debounce - low level gpio debounce time
158 * @bank: the gpio bank we're acting upon
159 * @gpio: the gpio number on this @gpio
160 * @debounce: debounce time to use
161 *
162 * OMAP's debounce time is in 31us steps so we need
163 * to convert and round up to the closest unit.
164 */
165static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
166 unsigned debounce)
167{
Kevin Hilman9942da02011-04-22 12:02:05 -0700168 void __iomem *reg;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700169 u32 val;
170 u32 l;
171
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800172 if (!bank->dbck_flag)
173 return;
174
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700175 if (debounce < 32)
176 debounce = 0x01;
177 else if (debounce > 7936)
178 debounce = 0xff;
179 else
180 debounce = (debounce / 0x1f) - 1;
181
Kevin Hilman129fd222011-04-22 07:59:07 -0700182 l = GPIO_BIT(bank, gpio);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700183
Kevin Hilman9942da02011-04-22 12:02:05 -0700184 reg = bank->base + bank->regs->debounce;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700185 __raw_writel(debounce, reg);
186
Kevin Hilman9942da02011-04-22 12:02:05 -0700187 reg = bank->base + bank->regs->debounce_en;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700188 val = __raw_readl(reg);
189
190 if (debounce) {
191 val |= l;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800192 clk_enable(bank->dbck);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700193 } else {
194 val &= ~l;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800195 clk_disable(bank->dbck);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700196 }
Kevin Hilmanf7ec0b02010-06-09 13:53:07 +0300197 bank->dbck_enable_mask = val;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700198
199 __raw_writel(val, reg);
200}
201
Tony Lindgren140455f2010-02-12 12:26:48 -0800202#ifdef CONFIG_ARCH_OMAP2PLUS
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700203static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
204 int trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100205{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800206 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100207 u32 gpio_bit = 1 << gpio;
208
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530209 if (cpu_is_omap44xx()) {
Kevin Hilmanece95282011-07-12 08:18:15 -0700210 _gpio_rmw(base, OMAP4_GPIO_LEVELDETECT0, gpio_bit,
211 trigger & IRQ_TYPE_LEVEL_LOW);
212 _gpio_rmw(base, OMAP4_GPIO_LEVELDETECT1, gpio_bit,
213 trigger & IRQ_TYPE_LEVEL_HIGH);
214 _gpio_rmw(base, OMAP4_GPIO_RISINGDETECT, gpio_bit,
215 trigger & IRQ_TYPE_EDGE_RISING);
216 _gpio_rmw(base, OMAP4_GPIO_FALLINGDETECT, gpio_bit,
217 trigger & IRQ_TYPE_EDGE_FALLING);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530218 } else {
Kevin Hilmanece95282011-07-12 08:18:15 -0700219 _gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
220 trigger & IRQ_TYPE_LEVEL_LOW);
221 _gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
222 trigger & IRQ_TYPE_LEVEL_HIGH);
223 _gpio_rmw(base, OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
224 trigger & IRQ_TYPE_EDGE_RISING);
225 _gpio_rmw(base, OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
226 trigger & IRQ_TYPE_EDGE_FALLING);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530227 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800228 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530229 if (cpu_is_omap44xx()) {
Kevin Hilmanece95282011-07-12 08:18:15 -0700230 _gpio_rmw(base, OMAP4_GPIO_IRQWAKEN0, gpio_bit,
231 trigger != 0);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530232 } else {
Chunqiu Wang699117a62009-06-24 17:13:39 +0000233 /*
234 * GPIO wakeup request can only be generated on edge
235 * transitions
236 */
237 if (trigger & IRQ_TYPE_EDGE_BOTH)
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530238 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700239 + OMAP24XX_GPIO_SETWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530240 else
241 __raw_writel(1 << gpio, bank->base
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700242 + OMAP24XX_GPIO_CLEARWKUENA);
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530243 }
Tero Kristoa118b5f2008-12-22 14:27:12 +0200244 }
Ambresh K55b220c2011-06-15 13:40:45 -0700245 /* This part needs to be executed always for OMAP{34xx, 44xx} */
246 if (cpu_is_omap34xx() || cpu_is_omap44xx() ||
247 (bank->non_wakeup_gpios & gpio_bit)) {
Chunqiu Wang699117a62009-06-24 17:13:39 +0000248 /*
249 * Log the edge gpio and manually trigger the IRQ
250 * after resume if the input level changes
251 * to avoid irq lost during PER RET/OFF mode
252 * Applies for omap2 non-wakeup gpio and all omap3 gpios
253 */
254 if (trigger & IRQ_TYPE_EDGE_BOTH)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800255 bank->enabled_non_wakeup_gpios |= gpio_bit;
256 else
257 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
258 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700259
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +0530260 if (cpu_is_omap44xx()) {
261 bank->level_mask =
262 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
263 __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1);
264 } else {
265 bank->level_mask =
266 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) |
267 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
268 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100269}
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800270#endif
Tony Lindgren92105bb2005-09-07 17:20:26 +0100271
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800272#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800273/*
274 * This only applies to chips that can't do both rising and falling edge
275 * detection at once. For all other chips, this function is a noop.
276 */
277static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
278{
279 void __iomem *reg = bank->base;
280 u32 l = 0;
281
282 switch (bank->method) {
Cory Maccarrone4318f362010-01-08 10:29:04 -0800283 case METHOD_MPUIO:
Tony Lindgren5de62b82010-12-07 16:26:58 -0800284 reg += OMAP_MPUIO_GPIO_INT_EDGE / bank->stride;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800285 break;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800286#ifdef CONFIG_ARCH_OMAP15XX
287 case METHOD_GPIO_1510:
288 reg += OMAP1510_GPIO_INT_CONTROL;
289 break;
290#endif
291#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
292 case METHOD_GPIO_7XX:
293 reg += OMAP7XX_GPIO_INT_CONTROL;
294 break;
295#endif
296 default:
297 return;
298 }
299
300 l = __raw_readl(reg);
301 if ((l >> gpio) & 1)
302 l &= ~(1 << gpio);
303 else
304 l |= 1 << gpio;
305
306 __raw_writel(l, reg);
307}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800308#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800309
Tony Lindgren92105bb2005-09-07 17:20:26 +0100310static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger)
311{
312 void __iomem *reg = bank->base;
313 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100314
315 switch (bank->method) {
David Brownelle5c56ed2006-12-06 17:13:59 -0800316#ifdef CONFIG_ARCH_OMAP1
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100317 case METHOD_MPUIO:
Tony Lindgren5de62b82010-12-07 16:26:58 -0800318 reg += OMAP_MPUIO_GPIO_INT_EDGE / bank->stride;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100319 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000320 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800321 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100322 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100323 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100324 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100325 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100326 else
327 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100328 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800329#endif
330#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100331 case METHOD_GPIO_1510:
332 reg += OMAP1510_GPIO_INT_CONTROL;
333 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000334 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800335 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100336 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100337 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100338 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100339 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100340 else
341 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100342 break;
David Brownelle5c56ed2006-12-06 17:13:59 -0800343#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800344#ifdef CONFIG_ARCH_OMAP16XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100345 case METHOD_GPIO_1610:
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100346 if (gpio & 0x08)
347 reg += OMAP1610_GPIO_EDGE_CTRL2;
348 else
349 reg += OMAP1610_GPIO_EDGE_CTRL1;
350 gpio &= 0x07;
351 l = __raw_readl(reg);
352 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100353 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100354 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100355 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100356 l |= 1 << (gpio << 1);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800357 if (trigger)
358 /* Enable wake-up during idle for dynamic tick */
359 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA);
360 else
361 __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100362 break;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800363#endif
Alistair Buxtonb718aa82009-09-23 18:56:19 +0100364#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +0100365 case METHOD_GPIO_7XX:
366 reg += OMAP7XX_GPIO_INT_CONTROL;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700367 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000368 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800369 bank->toggle_mask |= 1 << gpio;
Zebediah C. McClure56739a62009-03-23 18:07:40 -0700370 if (trigger & IRQ_TYPE_EDGE_RISING)
371 l |= 1 << gpio;
372 else if (trigger & IRQ_TYPE_EDGE_FALLING)
373 l &= ~(1 << gpio);
374 else
375 goto bad;
376 break;
377#endif
Tony Lindgren140455f2010-02-12 12:26:48 -0800378#ifdef CONFIG_ARCH_OMAP2PLUS
Tony Lindgren92105bb2005-09-07 17:20:26 +0100379 case METHOD_GPIO_24XX:
Tony Lindgren3f1686a92010-02-15 09:27:25 -0800380 case METHOD_GPIO_44XX:
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800381 set_24xx_gpio_triggering(bank, gpio, trigger);
Mika Westerbergf7c5cc42010-12-29 13:01:31 +0200382 return 0;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800383#endif
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100384 default:
Tony Lindgren92105bb2005-09-07 17:20:26 +0100385 goto bad;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100386 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100387 __raw_writel(l, reg);
388 return 0;
389bad:
390 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100391}
392
Lennert Buytenheke9191022010-11-29 11:17:17 +0100393static int gpio_irq_type(struct irq_data *d, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100394{
395 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100396 unsigned gpio;
397 int retval;
David Brownella6472532008-03-03 04:33:30 -0800398 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100399
Lennert Buytenheke9191022010-11-29 11:17:17 +0100400 if (!cpu_class_is_omap2() && d->irq > IH_MPUIO_BASE)
401 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100402 else
Lennert Buytenheke9191022010-11-29 11:17:17 +0100403 gpio = d->irq - IH_GPIO_BASE;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100404
David Brownelle5c56ed2006-12-06 17:13:59 -0800405 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100406 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800407
408 /* OMAP1 allows only only edge triggering */
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800409 if (!cpu_class_is_omap2()
David Brownelle5c56ed2006-12-06 17:13:59 -0800410 && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100411 return -EINVAL;
412
Lennert Buytenheke9191022010-11-29 11:17:17 +0100413 bank = irq_data_get_irq_chip_data(d);
David Brownella6472532008-03-03 04:33:30 -0800414 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman129fd222011-04-22 07:59:07 -0700415 retval = _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), type);
David Brownella6472532008-03-03 04:33:30 -0800416 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800417
418 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100419 __irq_set_handler_locked(d->irq, handle_level_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800420 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100421 __irq_set_handler_locked(d->irq, handle_edge_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800422
Tony Lindgren92105bb2005-09-07 17:20:26 +0100423 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100424}
425
426static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
427{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100428 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100429
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700430 reg += bank->regs->irqstatus;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100431 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300432
433 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700434 if (bank->regs->irqstatus2) {
435 reg = bank->base + bank->regs->irqstatus2;
Roger Quadrosbedfd152009-04-23 11:10:50 -0700436 __raw_writel(gpio_mask, reg);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700437 }
Roger Quadrosbedfd152009-04-23 11:10:50 -0700438
439 /* Flush posted write for the irq status to avoid spurious interrupts */
440 __raw_readl(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100441}
442
443static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
444{
Kevin Hilman129fd222011-04-22 07:59:07 -0700445 _clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100446}
447
Imre Deakea6dedd2006-06-26 16:16:00 -0700448static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
449{
450 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700451 u32 l;
Kevin Hilmanc390aad02011-04-21 09:33:36 -0700452 u32 mask = (1 << bank->width) - 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700453
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700454 reg += bank->regs->irqenable;
Imre Deak99c47702006-06-26 16:16:07 -0700455 l = __raw_readl(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700456 if (bank->regs->irqenable_inv)
Imre Deak99c47702006-06-26 16:16:07 -0700457 l = ~l;
458 l &= mask;
459 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700460}
461
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700462static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100463{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100464 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100465 u32 l;
466
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700467 if (bank->regs->set_irqenable) {
468 reg += bank->regs->set_irqenable;
469 l = gpio_mask;
470 } else {
471 reg += bank->regs->irqenable;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100472 l = __raw_readl(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700473 if (bank->regs->irqenable_inv)
474 l &= ~gpio_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100475 else
476 l |= gpio_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100477 }
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700478
479 __raw_writel(l, reg);
480}
481
482static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
483{
484 void __iomem *reg = bank->base;
485 u32 l;
486
487 if (bank->regs->clr_irqenable) {
488 reg += bank->regs->clr_irqenable;
489 l = gpio_mask;
490 } else {
491 reg += bank->regs->irqenable;
492 l = __raw_readl(reg);
493 if (bank->regs->irqenable_inv)
494 l |= gpio_mask;
495 else
496 l &= ~gpio_mask;
497 }
498
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100499 __raw_writel(l, reg);
500}
501
502static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
503{
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700504 _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100505}
506
Tony Lindgren92105bb2005-09-07 17:20:26 +0100507/*
508 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
509 * 1510 does not seem to have a wake-up register. If JTAG is connected
510 * to the target, system will wake up always on GPIO events. While
511 * system is running all registered GPIO interrupts need to have wake-up
512 * enabled. When system is suspended, only selected GPIO interrupts need
513 * to have wake-up enabled.
514 */
515static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
516{
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700517 u32 gpio_bit = GPIO_BIT(bank, gpio);
518 unsigned long flags;
David Brownella6472532008-03-03 04:33:30 -0800519
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700520 if (bank->non_wakeup_gpios & gpio_bit) {
521 dev_err(bank->dev,
522 "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100523 return -EINVAL;
524 }
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700525
526 spin_lock_irqsave(&bank->lock, flags);
527 if (enable)
528 bank->suspend_wakeup |= gpio_bit;
529 else
530 bank->suspend_wakeup &= ~gpio_bit;
531
532 spin_unlock_irqrestore(&bank->lock, flags);
533
534 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100535}
536
Tony Lindgren4196dd62006-09-25 12:41:38 +0300537static void _reset_gpio(struct gpio_bank *bank, int gpio)
538{
Kevin Hilman129fd222011-04-22 07:59:07 -0700539 _set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300540 _set_gpio_irqenable(bank, gpio, 0);
541 _clear_gpio_irqstatus(bank, gpio);
Kevin Hilman129fd222011-04-22 07:59:07 -0700542 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300543}
544
Tony Lindgren92105bb2005-09-07 17:20:26 +0100545/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
Lennert Buytenheke9191022010-11-29 11:17:17 +0100546static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100547{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100548 unsigned int gpio = d->irq - IH_GPIO_BASE;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100549 struct gpio_bank *bank;
550 int retval;
551
Lennert Buytenheke9191022010-11-29 11:17:17 +0100552 bank = irq_data_get_irq_chip_data(d);
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700553 retval = _set_gpio_wakeup(bank, gpio, enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100554
555 return retval;
556}
557
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800558static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100559{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800560 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800561 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100562
David Brownella6472532008-03-03 04:33:30 -0800563 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100564
Tony Lindgren4196dd62006-09-25 12:41:38 +0300565 /* Set trigger to none. You need to enable the desired trigger with
566 * request_irq() or set_irq_type().
567 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800568 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100569
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000570#ifdef CONFIG_ARCH_OMAP15XX
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100571 if (bank->method == METHOD_GPIO_1510) {
Tony Lindgren92105bb2005-09-07 17:20:26 +0100572 void __iomem *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100573
Tony Lindgren92105bb2005-09-07 17:20:26 +0100574 /* Claim the pin for MPU */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100575 reg = bank->base + OMAP1510_GPIO_PIN_CONTROL;
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800576 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100577 }
578#endif
Charulatha Vc8eef652011-05-02 15:21:42 +0530579 if (bank->regs->ctrl && !bank->mod_usage) {
580 void __iomem *reg = bank->base + bank->regs->ctrl;
581 u32 ctrl;
Charulatha V9f096862010-05-14 12:05:27 -0700582
Charulatha Vc8eef652011-05-02 15:21:42 +0530583 ctrl = __raw_readl(reg);
584 /* Module is enabled, clocks are not gated */
585 ctrl &= ~GPIO_MOD_CTRL_BIT;
586 __raw_writel(ctrl, reg);
Charulatha V058af1e2009-11-22 10:11:25 -0800587 }
Charulatha Vc8eef652011-05-02 15:21:42 +0530588
589 bank->mod_usage |= 1 << offset;
590
David Brownella6472532008-03-03 04:33:30 -0800591 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100592
593 return 0;
594}
595
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800596static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100597{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800598 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +0530599 void __iomem *base = bank->base;
David Brownella6472532008-03-03 04:33:30 -0800600 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100601
David Brownella6472532008-03-03 04:33:30 -0800602 spin_lock_irqsave(&bank->lock, flags);
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +0530603
604 if (bank->regs->wkup_en)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100605 /* Disable wake-up during idle for dynamic tick */
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +0530606 _gpio_rmw(base, bank->regs->wkup_en, 1 << offset, 0);
607
Charulatha Vc8eef652011-05-02 15:21:42 +0530608 bank->mod_usage &= ~(1 << offset);
Charulatha V9f096862010-05-14 12:05:27 -0700609
Charulatha Vc8eef652011-05-02 15:21:42 +0530610 if (bank->regs->ctrl && !bank->mod_usage) {
611 void __iomem *reg = bank->base + bank->regs->ctrl;
612 u32 ctrl;
613
614 ctrl = __raw_readl(reg);
615 /* Module is disabled, clocks are gated */
616 ctrl |= GPIO_MOD_CTRL_BIT;
617 __raw_writel(ctrl, reg);
Charulatha V058af1e2009-11-22 10:11:25 -0800618 }
Charulatha Vc8eef652011-05-02 15:21:42 +0530619
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800620 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -0800621 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100622}
623
624/*
625 * We need to unmask the GPIO bank interrupt as soon as possible to
626 * avoid missing GPIO interrupts for other lines in the bank.
627 * Then we need to mask-read-clear-unmask the triggered GPIO lines
628 * in the bank to avoid missing nested interrupts for a GPIO line.
629 * If we wait to unmask individual GPIO lines in the bank after the
630 * line's interrupt handler has been run, we may miss some nested
631 * interrupts.
632 */
Russell King10dd5ce2006-11-23 11:41:32 +0000633static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100634{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100635 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100636 u32 isr;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800637 unsigned int gpio_irq, gpio_index;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100638 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -0700639 u32 retrigger = 0;
640 int unmasked = 0;
Will Deaconee144182011-02-21 13:46:08 +0000641 struct irq_chip *chip = irq_desc_get_chip(desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100642
Will Deaconee144182011-02-21 13:46:08 +0000643 chained_irq_enter(chip, desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100644
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100645 bank = irq_get_handler_data(irq);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700646 isr_reg = bank->base + bank->regs->irqstatus;
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800647
648 if (WARN_ON(!isr_reg))
649 goto exit;
650
Tony Lindgren92105bb2005-09-07 17:20:26 +0100651 while(1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +0100652 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -0700653 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100654
Imre Deakea6dedd2006-06-26 16:16:00 -0700655 enabled = _get_gpio_irqbank_mask(bank);
656 isr_saved = isr = __raw_readl(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100657
658 if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO))
659 isr &= 0x0000ffff;
660
Syed Mohammed, Khasim5492fb12007-11-29 16:15:11 -0800661 if (cpu_class_is_omap2()) {
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800662 level_mask = bank->level_mask & enabled;
Imre Deakea6dedd2006-06-26 16:16:00 -0700663 }
Tony Lindgren6e60e792006-04-02 17:46:23 +0100664
665 /* clear edge sensitive interrupts before handler(s) are
666 called so that we don't miss any interrupt occurred while
667 executing them */
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700668 _disable_gpio_irqbank(bank, isr_saved & ~level_mask);
Tony Lindgren6e60e792006-04-02 17:46:23 +0100669 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700670 _enable_gpio_irqbank(bank, isr_saved & ~level_mask);
Tony Lindgren6e60e792006-04-02 17:46:23 +0100671
672 /* if there is only edge sensitive GPIO pin interrupts
673 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -0700674 if (!level_mask && !unmasked) {
675 unmasked = 1;
Will Deaconee144182011-02-21 13:46:08 +0000676 chained_irq_exit(chip, desc);
Imre Deakea6dedd2006-06-26 16:16:00 -0700677 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100678
Imre Deakea6dedd2006-06-26 16:16:00 -0700679 isr |= retrigger;
680 retrigger = 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100681 if (!isr)
682 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100683
Tony Lindgren92105bb2005-09-07 17:20:26 +0100684 gpio_irq = bank->virtual_irq_start;
685 for (; isr != 0; isr >>= 1, gpio_irq++) {
Kevin Hilman129fd222011-04-22 07:59:07 -0700686 gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq));
Cory Maccarrone4318f362010-01-08 10:29:04 -0800687
Tony Lindgren92105bb2005-09-07 17:20:26 +0100688 if (!(isr & 1))
689 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +0200690
Cory Maccarrone4318f362010-01-08 10:29:04 -0800691#ifdef CONFIG_ARCH_OMAP1
692 /*
693 * Some chips can't respond to both rising and falling
694 * at the same time. If this irq was requested with
695 * both flags, we need to flip the ICR data for the IRQ
696 * to respond to the IRQ for the opposite direction.
697 * This will be indicated in the bank toggle_mask.
698 */
699 if (bank->toggle_mask & (1 << gpio_index))
700 _toggle_gpio_edge_triggering(bank, gpio_index);
701#endif
702
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100703 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100704 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000705 }
Imre Deakea6dedd2006-06-26 16:16:00 -0700706 /* if bank has any level sensitive GPIO pin interrupt
707 configured, we must unmask the bank interrupt only after
708 handler(s) are executed in order to avoid spurious bank
709 interrupt */
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800710exit:
Imre Deakea6dedd2006-06-26 16:16:00 -0700711 if (!unmasked)
Will Deaconee144182011-02-21 13:46:08 +0000712 chained_irq_exit(chip, desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100713}
714
Lennert Buytenheke9191022010-11-29 11:17:17 +0100715static void gpio_irq_shutdown(struct irq_data *d)
Tony Lindgren4196dd62006-09-25 12:41:38 +0300716{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100717 unsigned int gpio = d->irq - IH_GPIO_BASE;
718 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700719 unsigned long flags;
Tony Lindgren4196dd62006-09-25 12:41:38 +0300720
Colin Cross85ec7b92011-06-06 13:38:18 -0700721 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300722 _reset_gpio(bank, gpio);
Colin Cross85ec7b92011-06-06 13:38:18 -0700723 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300724}
725
Lennert Buytenheke9191022010-11-29 11:17:17 +0100726static void gpio_ack_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100727{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100728 unsigned int gpio = d->irq - IH_GPIO_BASE;
729 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100730
731 _clear_gpio_irqstatus(bank, gpio);
732}
733
Lennert Buytenheke9191022010-11-29 11:17:17 +0100734static void gpio_mask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100735{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100736 unsigned int gpio = d->irq - IH_GPIO_BASE;
737 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700738 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100739
Colin Cross85ec7b92011-06-06 13:38:18 -0700740 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100741 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman129fd222011-04-22 07:59:07 -0700742 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
Colin Cross85ec7b92011-06-06 13:38:18 -0700743 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100744}
745
Lennert Buytenheke9191022010-11-29 11:17:17 +0100746static void gpio_unmask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100747{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100748 unsigned int gpio = d->irq - IH_GPIO_BASE;
749 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Kevin Hilman129fd222011-04-22 07:59:07 -0700750 unsigned int irq_mask = GPIO_BIT(bank, gpio);
Thomas Gleixner8c04a172011-03-24 12:40:15 +0100751 u32 trigger = irqd_get_trigger_type(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700752 unsigned long flags;
Kevin Hilman55b60192009-06-04 15:57:10 -0700753
Colin Cross85ec7b92011-06-06 13:38:18 -0700754 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman55b60192009-06-04 15:57:10 -0700755 if (trigger)
Kevin Hilman129fd222011-04-22 07:59:07 -0700756 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800757
758 /* For level-triggered GPIOs, the clearing must be done after
759 * the HW source is cleared, thus after the handler has run */
760 if (bank->level_mask & irq_mask) {
761 _set_gpio_irqenable(bank, gpio, 0);
762 _clear_gpio_irqstatus(bank, gpio);
763 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100764
Kevin Hilman4de8c752008-01-16 21:56:14 -0800765 _set_gpio_irqenable(bank, gpio, 1);
Colin Cross85ec7b92011-06-06 13:38:18 -0700766 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100767}
768
David Brownelle5c56ed2006-12-06 17:13:59 -0800769static struct irq_chip gpio_irq_chip = {
770 .name = "GPIO",
Lennert Buytenheke9191022010-11-29 11:17:17 +0100771 .irq_shutdown = gpio_irq_shutdown,
772 .irq_ack = gpio_ack_irq,
773 .irq_mask = gpio_mask_irq,
774 .irq_unmask = gpio_unmask_irq,
775 .irq_set_type = gpio_irq_type,
776 .irq_set_wake = gpio_wake_enable,
David Brownelle5c56ed2006-12-06 17:13:59 -0800777};
778
779/*---------------------------------------------------------------------*/
780
781#ifdef CONFIG_ARCH_OMAP1
782
David Brownelle5c56ed2006-12-06 17:13:59 -0800783#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
784
David Brownell11a78b72006-12-06 17:14:11 -0800785#ifdef CONFIG_ARCH_OMAP16XX
786
787#include <linux/platform_device.h>
788
Magnus Damm79ee0312009-07-08 13:22:04 +0200789static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800790{
Magnus Damm79ee0312009-07-08 13:22:04 +0200791 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800792 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800793 void __iomem *mask_reg = bank->base +
794 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800795 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800796
David Brownella6472532008-03-03 04:33:30 -0800797 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800798 bank->saved_wakeup = __raw_readl(mask_reg);
799 __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800800 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800801
802 return 0;
803}
804
Magnus Damm79ee0312009-07-08 13:22:04 +0200805static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800806{
Magnus Damm79ee0312009-07-08 13:22:04 +0200807 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800808 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800809 void __iomem *mask_reg = bank->base +
810 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800811 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800812
David Brownella6472532008-03-03 04:33:30 -0800813 spin_lock_irqsave(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800814 __raw_writel(bank->saved_wakeup, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800815 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800816
817 return 0;
818}
819
Alexey Dobriyan47145212009-12-14 18:00:08 -0800820static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +0200821 .suspend_noirq = omap_mpuio_suspend_noirq,
822 .resume_noirq = omap_mpuio_resume_noirq,
823};
824
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +0200825/* use platform_driver for this. */
David Brownell11a78b72006-12-06 17:14:11 -0800826static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -0800827 .driver = {
828 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +0200829 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -0800830 },
831};
832
833static struct platform_device omap_mpuio_device = {
834 .name = "mpuio",
835 .id = -1,
836 .dev = {
837 .driver = &omap_mpuio_driver.driver,
838 }
839 /* could list the /proc/iomem resources */
840};
841
Charulatha V03e128c2011-05-05 19:58:01 +0530842static inline void mpuio_init(struct gpio_bank *bank)
David Brownell11a78b72006-12-06 17:14:11 -0800843{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800844 platform_set_drvdata(&omap_mpuio_device, bank);
David Brownellfcf126d2007-04-02 12:46:47 -0700845
David Brownell11a78b72006-12-06 17:14:11 -0800846 if (platform_driver_register(&omap_mpuio_driver) == 0)
847 (void) platform_device_register(&omap_mpuio_device);
848}
849
850#else
Charulatha V03e128c2011-05-05 19:58:01 +0530851static inline void mpuio_init(struct gpio_bank *bank) {}
David Brownell11a78b72006-12-06 17:14:11 -0800852#endif /* 16xx */
853
David Brownelle5c56ed2006-12-06 17:13:59 -0800854#else
855
David Brownelle5c56ed2006-12-06 17:13:59 -0800856#define bank_is_mpuio(bank) 0
Charulatha V03e128c2011-05-05 19:58:01 +0530857static inline void mpuio_init(struct gpio_bank *bank) {}
David Brownelle5c56ed2006-12-06 17:13:59 -0800858
859#endif
860
861/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100862
David Brownell52e31342008-03-03 12:43:23 -0800863/* REVISIT these are stupid implementations! replace by ones that
864 * don't switch on METHOD_* and which mostly avoid spinlocks
865 */
866
867static int gpio_input(struct gpio_chip *chip, unsigned offset)
868{
869 struct gpio_bank *bank;
870 unsigned long flags;
871
872 bank = container_of(chip, struct gpio_bank, chip);
873 spin_lock_irqsave(&bank->lock, flags);
874 _set_gpio_direction(bank, offset, 1);
875 spin_unlock_irqrestore(&bank->lock, flags);
876 return 0;
877}
878
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300879static int gpio_is_input(struct gpio_bank *bank, int mask)
880{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700881 void __iomem *reg = bank->base + bank->regs->direction;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300882
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300883 return __raw_readl(reg) & mask;
884}
885
David Brownell52e31342008-03-03 12:43:23 -0800886static int gpio_get(struct gpio_chip *chip, unsigned offset)
887{
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300888 struct gpio_bank *bank;
889 void __iomem *reg;
890 int gpio;
891 u32 mask;
892
893 gpio = chip->base + offset;
Charulatha Va8be8da2011-04-22 16:38:16 +0530894 bank = container_of(chip, struct gpio_bank, chip);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300895 reg = bank->base;
Kevin Hilman129fd222011-04-22 07:59:07 -0700896 mask = GPIO_BIT(bank, gpio);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300897
898 if (gpio_is_input(bank, mask))
899 return _get_gpio_datain(bank, gpio);
900 else
901 return _get_gpio_dataout(bank, gpio);
David Brownell52e31342008-03-03 12:43:23 -0800902}
903
904static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
905{
906 struct gpio_bank *bank;
907 unsigned long flags;
908
909 bank = container_of(chip, struct gpio_bank, chip);
910 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700911 bank->set_dataout(bank, offset, value);
David Brownell52e31342008-03-03 12:43:23 -0800912 _set_gpio_direction(bank, offset, 0);
913 spin_unlock_irqrestore(&bank->lock, flags);
914 return 0;
915}
916
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700917static int gpio_debounce(struct gpio_chip *chip, unsigned offset,
918 unsigned debounce)
919{
920 struct gpio_bank *bank;
921 unsigned long flags;
922
923 bank = container_of(chip, struct gpio_bank, chip);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800924
925 if (!bank->dbck) {
926 bank->dbck = clk_get(bank->dev, "dbclk");
927 if (IS_ERR(bank->dbck))
928 dev_err(bank->dev, "Could not get gpio dbck\n");
929 }
930
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700931 spin_lock_irqsave(&bank->lock, flags);
932 _set_gpio_debounce(bank, offset, debounce);
933 spin_unlock_irqrestore(&bank->lock, flags);
934
935 return 0;
936}
937
David Brownell52e31342008-03-03 12:43:23 -0800938static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
939{
940 struct gpio_bank *bank;
941 unsigned long flags;
942
943 bank = container_of(chip, struct gpio_bank, chip);
944 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700945 bank->set_dataout(bank, offset, value);
David Brownell52e31342008-03-03 12:43:23 -0800946 spin_unlock_irqrestore(&bank->lock, flags);
947}
948
David Brownella007b702008-12-10 17:35:25 -0800949static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
950{
951 struct gpio_bank *bank;
952
953 bank = container_of(chip, struct gpio_bank, chip);
954 return bank->virtual_irq_start + offset;
955}
956
David Brownell52e31342008-03-03 12:43:23 -0800957/*---------------------------------------------------------------------*/
958
Tony Lindgren9a748052010-12-07 16:26:56 -0800959static void __init omap_gpio_show_rev(struct gpio_bank *bank)
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700960{
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700961 static bool called;
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700962 u32 rev;
963
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700964 if (called || bank->regs->revision == USHRT_MAX)
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700965 return;
966
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700967 rev = __raw_readw(bank->base + bank->regs->revision);
968 pr_info("OMAP GPIO hardware version %d.%d\n",
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700969 (rev >> 4) & 0x0f, rev & 0x0f);
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700970
971 called = true;
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700972}
973
David Brownell8ba55c52008-02-26 11:10:50 -0800974/* This lock class tells lockdep that GPIO irqs are in a different
975 * category than their parents, so it won't report false recursion.
976 */
977static struct lock_class_key gpio_lock_class;
978
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800979/* TODO: Cleanup cpu_is_* checks */
Charulatha V03e128c2011-05-05 19:58:01 +0530980static void omap_gpio_mod_init(struct gpio_bank *bank)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -0800981{
982 if (cpu_class_is_omap2()) {
983 if (cpu_is_omap44xx()) {
984 __raw_writel(0xffffffff, bank->base +
985 OMAP4_GPIO_IRQSTATUSCLR0);
986 __raw_writel(0x00000000, bank->base +
987 OMAP4_GPIO_DEBOUNCENABLE);
988 /* Initialize interface clk ungated, module enabled */
989 __raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
990 } else if (cpu_is_omap34xx()) {
991 __raw_writel(0x00000000, bank->base +
992 OMAP24XX_GPIO_IRQENABLE1);
993 __raw_writel(0xffffffff, bank->base +
994 OMAP24XX_GPIO_IRQSTATUS1);
995 __raw_writel(0x00000000, bank->base +
996 OMAP24XX_GPIO_DEBOUNCE_EN);
997
998 /* Initialize interface clk ungated, module enabled */
999 __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL);
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001000 }
1001 } else if (cpu_class_is_omap1()) {
Charulatha V03e128c2011-05-05 19:58:01 +05301002 if (bank_is_mpuio(bank)) {
Tony Lindgren5de62b82010-12-07 16:26:58 -08001003 __raw_writew(0xffff, bank->base +
1004 OMAP_MPUIO_GPIO_MASKIT / bank->stride);
Charulatha V03e128c2011-05-05 19:58:01 +05301005 mpuio_init(bank);
1006 }
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001007 if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) {
1008 __raw_writew(0xffff, bank->base
1009 + OMAP1510_GPIO_INT_MASK);
1010 __raw_writew(0x0000, bank->base
1011 + OMAP1510_GPIO_INT_STATUS);
1012 }
1013 if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) {
1014 __raw_writew(0x0000, bank->base
1015 + OMAP1610_GPIO_IRQENABLE1);
1016 __raw_writew(0xffff, bank->base
1017 + OMAP1610_GPIO_IRQSTATUS1);
1018 __raw_writew(0x0014, bank->base
1019 + OMAP1610_GPIO_SYSCONFIG);
1020
1021 /*
1022 * Enable system clock for GPIO module.
1023 * The CAM_CLK_CTRL *is* really the right place.
1024 */
1025 omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04,
1026 ULPD_CAM_CLK_CTRL);
1027 }
1028 if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) {
1029 __raw_writel(0xffffffff, bank->base
1030 + OMAP7XX_GPIO_INT_MASK);
1031 __raw_writel(0x00000000, bank->base
1032 + OMAP7XX_GPIO_INT_STATUS);
1033 }
1034 }
1035}
1036
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001037static __init void
1038omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start,
1039 unsigned int num)
1040{
1041 struct irq_chip_generic *gc;
1042 struct irq_chip_type *ct;
1043
1044 gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base,
1045 handle_simple_irq);
Todd Poynor83233742011-07-18 07:43:14 -07001046 if (!gc) {
1047 dev_err(bank->dev, "Memory alloc failed for gc\n");
1048 return;
1049 }
1050
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001051 ct = gc->chip_types;
1052
1053 /* NOTE: No ack required, reading IRQ status clears it. */
1054 ct->chip.irq_mask = irq_gc_mask_set_bit;
1055 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
1056 ct->chip.irq_set_type = gpio_irq_type;
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301057
1058 if (bank->regs->wkup_en)
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001059 ct->chip.irq_set_wake = gpio_wake_enable,
1060
1061 ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride;
1062 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
1063 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
1064}
1065
Russell Kingd52b31d2011-05-27 13:56:12 -07001066static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001067{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001068 int j;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001069 static int gpio;
1070
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001071 bank->mod_usage = 0;
1072 /*
1073 * REVISIT eventually switch from OMAP-specific gpio structs
1074 * over to the generic ones
1075 */
1076 bank->chip.request = omap_gpio_request;
1077 bank->chip.free = omap_gpio_free;
1078 bank->chip.direction_input = gpio_input;
1079 bank->chip.get = gpio_get;
1080 bank->chip.direction_output = gpio_output;
1081 bank->chip.set_debounce = gpio_debounce;
1082 bank->chip.set = gpio_set;
1083 bank->chip.to_irq = gpio_2irq;
1084 if (bank_is_mpuio(bank)) {
1085 bank->chip.label = "mpuio";
1086#ifdef CONFIG_ARCH_OMAP16XX
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301087 if (bank->regs->wkup_en)
1088 bank->chip.dev = &omap_mpuio_device.dev;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001089#endif
1090 bank->chip.base = OMAP_MPUIO(0);
1091 } else {
1092 bank->chip.label = "gpio";
1093 bank->chip.base = gpio;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001094 gpio += bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001095 }
Kevin Hilmand5f46242011-04-21 09:23:00 -07001096 bank->chip.ngpio = bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001097
1098 gpiochip_add(&bank->chip);
1099
1100 for (j = bank->virtual_irq_start;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001101 j < bank->virtual_irq_start + bank->width; j++) {
Thomas Gleixner1475b852011-03-22 17:11:09 +01001102 irq_set_lockdep_class(j, &gpio_lock_class);
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001103 irq_set_chip_data(j, bank);
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001104 if (bank_is_mpuio(bank)) {
1105 omap_mpuio_alloc_gc(bank, j, bank->width);
1106 } else {
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001107 irq_set_chip(j, &gpio_irq_chip);
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001108 irq_set_handler(j, handle_simple_irq);
1109 set_irq_flags(j, IRQF_VALID);
1110 }
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001111 }
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001112 irq_set_chained_handler(bank->irq, gpio_irq_handler);
1113 irq_set_handler_data(bank->irq, bank);
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001114}
1115
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001116static int __devinit omap_gpio_probe(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001117{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001118 struct omap_gpio_platform_data *pdata;
1119 struct resource *res;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001120 struct gpio_bank *bank;
Charulatha V03e128c2011-05-05 19:58:01 +05301121 int ret = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001122
Charulatha V03e128c2011-05-05 19:58:01 +05301123 if (!pdev->dev.platform_data) {
1124 ret = -EINVAL;
1125 goto err_exit;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001126 }
1127
Charulatha V03e128c2011-05-05 19:58:01 +05301128 bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
1129 if (!bank) {
1130 dev_err(&pdev->dev, "Memory alloc failed for gpio_bank\n");
1131 ret = -ENOMEM;
1132 goto err_exit;
1133 }
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001134
1135 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1136 if (unlikely(!res)) {
Charulatha V03e128c2011-05-05 19:58:01 +05301137 dev_err(&pdev->dev, "GPIO Bank %i Invalid IRQ resource\n",
1138 pdev->id);
1139 ret = -ENODEV;
1140 goto err_free;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001141 }
1142
1143 bank->irq = res->start;
Charulatha V03e128c2011-05-05 19:58:01 +05301144 bank->id = pdev->id;
1145
1146 pdata = pdev->dev.platform_data;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001147 bank->virtual_irq_start = pdata->virtual_irq_start;
1148 bank->method = pdata->bank_type;
1149 bank->dev = &pdev->dev;
1150 bank->dbck_flag = pdata->dbck_flag;
Tony Lindgren5de62b82010-12-07 16:26:58 -08001151 bank->stride = pdata->bank_stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001152 bank->width = pdata->bank_width;
Charulatha V803a2432011-05-05 17:04:12 +05301153 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
Charulatha V0cde8d02011-05-05 20:15:16 +05301154 bank->loses_context = pdata->loses_context;
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301155 bank->get_context_loss_count = pdata->get_context_loss_count;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001156 bank->regs = pdata->regs;
1157
1158 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1159 bank->set_dataout = _set_gpio_dataout_reg;
1160 else
1161 bank->set_dataout = _set_gpio_dataout_mask;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001162
1163 spin_lock_init(&bank->lock);
1164
1165 /* Static mapping, never released */
1166 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1167 if (unlikely(!res)) {
Charulatha V03e128c2011-05-05 19:58:01 +05301168 dev_err(&pdev->dev, "GPIO Bank %i Invalid mem resource\n",
1169 pdev->id);
1170 ret = -ENODEV;
1171 goto err_free;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001172 }
1173
1174 bank->base = ioremap(res->start, resource_size(res));
1175 if (!bank->base) {
Charulatha V03e128c2011-05-05 19:58:01 +05301176 dev_err(&pdev->dev, "Could not ioremap gpio bank%i\n",
1177 pdev->id);
1178 ret = -ENOMEM;
1179 goto err_free;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001180 }
1181
1182 pm_runtime_enable(bank->dev);
1183 pm_runtime_get_sync(bank->dev);
1184
Charulatha V03e128c2011-05-05 19:58:01 +05301185 omap_gpio_mod_init(bank);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001186 omap_gpio_chip_init(bank);
Tony Lindgren9a748052010-12-07 16:26:56 -08001187 omap_gpio_show_rev(bank);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001188
Charulatha V03e128c2011-05-05 19:58:01 +05301189 list_add_tail(&bank->node, &omap_gpio_list);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001190
Charulatha V03e128c2011-05-05 19:58:01 +05301191 return ret;
1192
1193err_free:
1194 kfree(bank);
1195err_exit:
1196 return ret;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001197}
1198
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001199static int omap_gpio_suspend(void)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001200{
Charulatha V03e128c2011-05-05 19:58:01 +05301201 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001202
Charulatha V03e128c2011-05-05 19:58:01 +05301203 list_for_each_entry(bank, &omap_gpio_list, node) {
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301204 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001205 void __iomem *wake_status;
David Brownella6472532008-03-03 04:33:30 -08001206 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001207
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301208 if (!bank->regs->wkup_en)
1209 return 0;
1210
1211 wake_status = bank->base + bank->regs->wkup_en;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001212
David Brownella6472532008-03-03 04:33:30 -08001213 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001214 bank->saved_wakeup = __raw_readl(wake_status);
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301215 _gpio_rmw(base, bank->regs->wkup_en, 0xffffffff, 0);
1216 _gpio_rmw(base, bank->regs->wkup_en, bank->suspend_wakeup, 1);
David Brownella6472532008-03-03 04:33:30 -08001217 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001218 }
1219
1220 return 0;
1221}
1222
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001223static void omap_gpio_resume(void)
Tony Lindgren92105bb2005-09-07 17:20:26 +01001224{
Charulatha V03e128c2011-05-05 19:58:01 +05301225 struct gpio_bank *bank;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001226
Charulatha V03e128c2011-05-05 19:58:01 +05301227 list_for_each_entry(bank, &omap_gpio_list, node) {
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301228 void __iomem *base = bank->base;
David Brownella6472532008-03-03 04:33:30 -08001229 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001230
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301231 if (!bank->regs->wkup_en)
1232 return;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001233
David Brownella6472532008-03-03 04:33:30 -08001234 spin_lock_irqsave(&bank->lock, flags);
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301235 _gpio_rmw(base, bank->regs->wkup_en, 0xffffffff, 0);
1236 _gpio_rmw(base, bank->regs->wkup_en, bank->saved_wakeup, 1);
David Brownella6472532008-03-03 04:33:30 -08001237 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001238 }
Tony Lindgren92105bb2005-09-07 17:20:26 +01001239}
1240
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001241static struct syscore_ops omap_gpio_syscore_ops = {
Tony Lindgren92105bb2005-09-07 17:20:26 +01001242 .suspend = omap_gpio_suspend,
1243 .resume = omap_gpio_resume,
1244};
1245
Tony Lindgren140455f2010-02-12 12:26:48 -08001246#ifdef CONFIG_ARCH_OMAP2PLUS
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001247
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301248static void omap_gpio_save_context(struct gpio_bank *bank);
1249static void omap_gpio_restore_context(struct gpio_bank *bank);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001250
Paul Walmsley72e06d02010-12-21 21:05:16 -07001251void omap2_gpio_prepare_for_idle(int off_mode)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001252{
Charulatha V03e128c2011-05-05 19:58:01 +05301253 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001254
Charulatha V03e128c2011-05-05 19:58:01 +05301255 list_for_each_entry(bank, &omap_gpio_list, node) {
Sanjeev Premica828762010-09-23 18:27:18 -07001256 u32 l1 = 0, l2 = 0;
Kevin Hilman0aed04352010-09-22 16:06:27 -07001257 int j;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001258
Charulatha V0cde8d02011-05-05 20:15:16 +05301259 if (!bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301260 continue;
1261
Kevin Hilman0aed04352010-09-22 16:06:27 -07001262 for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++)
Kevin Hilman8865b9b2009-01-27 11:15:34 -08001263 clk_disable(bank->dbck);
1264
Paul Walmsley72e06d02010-12-21 21:05:16 -07001265 if (!off_mode)
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001266 continue;
1267
1268 /* If going to OFF, remove triggering for all
1269 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1270 * generated. See OMAP2420 Errata item 1.101. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001271 if (!(bank->enabled_non_wakeup_gpios))
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301272 goto save_gpio_context;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001273
1274 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
1275 bank->saved_datain = __raw_readl(bank->base +
1276 OMAP24XX_GPIO_DATAIN);
1277 l1 = __raw_readl(bank->base +
1278 OMAP24XX_GPIO_FALLINGDETECT);
1279 l2 = __raw_readl(bank->base +
1280 OMAP24XX_GPIO_RISINGDETECT);
1281 }
1282
1283 if (cpu_is_omap44xx()) {
1284 bank->saved_datain = __raw_readl(bank->base +
1285 OMAP4_GPIO_DATAIN);
1286 l1 = __raw_readl(bank->base +
1287 OMAP4_GPIO_FALLINGDETECT);
1288 l2 = __raw_readl(bank->base +
1289 OMAP4_GPIO_RISINGDETECT);
1290 }
1291
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001292 bank->saved_fallingdetect = l1;
1293 bank->saved_risingdetect = l2;
1294 l1 &= ~bank->enabled_non_wakeup_gpios;
1295 l2 &= ~bank->enabled_non_wakeup_gpios;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001296
1297 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
1298 __raw_writel(l1, bank->base +
1299 OMAP24XX_GPIO_FALLINGDETECT);
1300 __raw_writel(l2, bank->base +
1301 OMAP24XX_GPIO_RISINGDETECT);
1302 }
1303
1304 if (cpu_is_omap44xx()) {
1305 __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT);
1306 __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT);
1307 }
1308
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301309save_gpio_context:
1310 if (bank->get_context_loss_count)
1311 bank->context_loss_count =
1312 bank->get_context_loss_count(bank->dev);
1313
1314 omap_gpio_save_context(bank);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001315 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001316}
1317
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001318void omap2_gpio_resume_after_idle(void)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001319{
Charulatha V03e128c2011-05-05 19:58:01 +05301320 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001321
Charulatha V03e128c2011-05-05 19:58:01 +05301322 list_for_each_entry(bank, &omap_gpio_list, node) {
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301323 int context_lost_cnt_after;
Sanjeev Premica828762010-09-23 18:27:18 -07001324 u32 l = 0, gen, gen0, gen1;
Kevin Hilman0aed04352010-09-22 16:06:27 -07001325 int j;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001326
Charulatha V0cde8d02011-05-05 20:15:16 +05301327 if (!bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301328 continue;
1329
Kevin Hilman0aed04352010-09-22 16:06:27 -07001330 for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++)
Kevin Hilman8865b9b2009-01-27 11:15:34 -08001331 clk_enable(bank->dbck);
1332
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301333 if (bank->get_context_loss_count) {
1334 context_lost_cnt_after =
1335 bank->get_context_loss_count(bank->dev);
1336 if (context_lost_cnt_after != bank->context_loss_count
1337 || !context_lost_cnt_after)
1338 omap_gpio_restore_context(bank);
1339 }
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001340
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001341 if (!(bank->enabled_non_wakeup_gpios))
1342 continue;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001343
1344 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
1345 __raw_writel(bank->saved_fallingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001346 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001347 __raw_writel(bank->saved_risingdetect,
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001348 bank->base + OMAP24XX_GPIO_RISINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001349 l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN);
1350 }
1351
1352 if (cpu_is_omap44xx()) {
1353 __raw_writel(bank->saved_fallingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301354 bank->base + OMAP4_GPIO_FALLINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001355 __raw_writel(bank->saved_risingdetect,
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301356 bank->base + OMAP4_GPIO_RISINGDETECT);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001357 l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN);
1358 }
1359
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001360 /* Check if any of the non-wakeup interrupt GPIOs have changed
1361 * state. If so, generate an IRQ by software. This is
1362 * horribly racy, but it's the best we can do to work around
1363 * this silicon bug. */
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001364 l ^= bank->saved_datain;
Tero Kristoa118b5f2008-12-22 14:27:12 +02001365 l &= bank->enabled_non_wakeup_gpios;
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07001366
1367 /*
1368 * No need to generate IRQs for the rising edge for gpio IRQs
1369 * configured with falling edge only; and vice versa.
1370 */
1371 gen0 = l & bank->saved_fallingdetect;
1372 gen0 &= bank->saved_datain;
1373
1374 gen1 = l & bank->saved_risingdetect;
1375 gen1 &= ~(bank->saved_datain);
1376
1377 /* FIXME: Consider GPIO IRQs with level detections properly! */
1378 gen = l & (~(bank->saved_fallingdetect) &
1379 ~(bank->saved_risingdetect));
1380 /* Consider all GPIO IRQs needed to be updated */
1381 gen |= gen0 | gen1;
1382
1383 if (gen) {
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001384 u32 old0, old1;
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001385
Sergio Aguirref00d6492010-03-03 16:21:08 +00001386 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001387 old0 = __raw_readl(bank->base +
1388 OMAP24XX_GPIO_LEVELDETECT0);
1389 old1 = __raw_readl(bank->base +
1390 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00001391 __raw_writel(old0 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07001392 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00001393 __raw_writel(old1 | gen, bank->base +
Eero Nurkkala82dbb9d2009-08-28 10:51:36 -07001394 OMAP24XX_GPIO_LEVELDETECT1);
Sergio Aguirref00d6492010-03-03 16:21:08 +00001395 __raw_writel(old0, bank->base +
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001396 OMAP24XX_GPIO_LEVELDETECT0);
Sergio Aguirref00d6492010-03-03 16:21:08 +00001397 __raw_writel(old1, bank->base +
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001398 OMAP24XX_GPIO_LEVELDETECT1);
1399 }
1400
1401 if (cpu_is_omap44xx()) {
1402 old0 = __raw_readl(bank->base +
1403 OMAP4_GPIO_LEVELDETECT0);
1404 old1 = __raw_readl(bank->base +
Syed Rafiuddin78a1a6d2009-07-28 18:57:30 +05301405 OMAP4_GPIO_LEVELDETECT1);
Tony Lindgren3f1686a92010-02-15 09:27:25 -08001406 __raw_writel(old0 | l, bank->base +
1407 OMAP4_GPIO_LEVELDETECT0);
1408 __raw_writel(old1 | l, bank->base +
1409 OMAP4_GPIO_LEVELDETECT1);
1410 __raw_writel(old0, bank->base +
1411 OMAP4_GPIO_LEVELDETECT0);
1412 __raw_writel(old1, bank->base +
1413 OMAP4_GPIO_LEVELDETECT1);
1414 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001415 }
1416 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001417}
1418
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301419static void omap_gpio_save_context(struct gpio_bank *bank)
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301420{
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301421 bank->context.irqenable1 =
1422 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1);
1423 bank->context.irqenable2 =
1424 __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2);
1425 bank->context.wake_en =
1426 __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN);
1427 bank->context.ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL);
1428 bank->context.oe = __raw_readl(bank->base + OMAP24XX_GPIO_OE);
1429 bank->context.leveldetect0 =
1430 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1431 bank->context.leveldetect1 =
1432 __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1);
1433 bank->context.risingdetect =
1434 __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT);
1435 bank->context.fallingdetect =
1436 __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1437 bank->context.dataout =
1438 __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301439}
1440
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301441static void omap_gpio_restore_context(struct gpio_bank *bank)
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301442{
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301443 __raw_writel(bank->context.irqenable1,
1444 bank->base + OMAP24XX_GPIO_IRQENABLE1);
1445 __raw_writel(bank->context.irqenable2,
1446 bank->base + OMAP24XX_GPIO_IRQENABLE2);
1447 __raw_writel(bank->context.wake_en,
1448 bank->base + OMAP24XX_GPIO_WAKE_EN);
1449 __raw_writel(bank->context.ctrl, bank->base + OMAP24XX_GPIO_CTRL);
1450 __raw_writel(bank->context.oe, bank->base + OMAP24XX_GPIO_OE);
1451 __raw_writel(bank->context.leveldetect0,
1452 bank->base + OMAP24XX_GPIO_LEVELDETECT0);
1453 __raw_writel(bank->context.leveldetect1,
1454 bank->base + OMAP24XX_GPIO_LEVELDETECT1);
1455 __raw_writel(bank->context.risingdetect,
1456 bank->base + OMAP24XX_GPIO_RISINGDETECT);
1457 __raw_writel(bank->context.fallingdetect,
1458 bank->base + OMAP24XX_GPIO_FALLINGDETECT);
1459 __raw_writel(bank->context.dataout,
1460 bank->base + OMAP24XX_GPIO_DATAOUT);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301461}
1462#endif
1463
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001464static struct platform_driver omap_gpio_driver = {
1465 .probe = omap_gpio_probe,
1466 .driver = {
1467 .name = "omap_gpio",
1468 },
1469};
1470
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001471/*
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001472 * gpio driver register needs to be done before
1473 * machine_init functions access gpio APIs.
1474 * Hence omap_gpio_drv_reg() is a postcore_initcall.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001475 */
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001476static int __init omap_gpio_drv_reg(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001477{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001478 return platform_driver_register(&omap_gpio_driver);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001479}
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001480postcore_initcall(omap_gpio_drv_reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001481
Tony Lindgren92105bb2005-09-07 17:20:26 +01001482static int __init omap_gpio_sysinit(void)
1483{
David Brownell11a78b72006-12-06 17:14:11 -08001484
Tony Lindgren140455f2010-02-12 12:26:48 -08001485#if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS)
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001486 if (cpu_is_omap16xx() || cpu_class_is_omap2())
1487 register_syscore_ops(&omap_gpio_syscore_ops);
Tony Lindgren92105bb2005-09-07 17:20:26 +01001488#endif
1489
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +02001490 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +01001491}
1492
Tony Lindgren92105bb2005-09-07 17:20:26 +01001493arch_initcall(omap_gpio_sysinit);