blob: afecdccfc66ee597d933421862c73459b8ec5183 [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>
Benoit Cousson96751fc2012-02-01 16:01:39 +010022#include <linux/device.h>
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -080023#include <linux/pm_runtime.h>
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +053024#include <linux/pm.h>
Benoit Cousson384ebe12011-08-16 11:53:02 +020025#include <linux/of.h>
26#include <linux/of_device.h>
27#include <linux/irqdomain.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010028
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/hardware.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010030#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010031#include <mach/irqs.h>
Russell King1bc857f2011-07-26 10:54:55 +010032#include <asm/gpio.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010033#include <asm/mach/irq.h>
34
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +053035#define OFF_MODE 1
36
Charulatha V03e128c2011-05-05 19:58:01 +053037static LIST_HEAD(omap_gpio_list);
38
Charulatha V6d62e212011-04-18 15:06:51 +000039struct gpio_regs {
40 u32 irqenable1;
41 u32 irqenable2;
42 u32 wake_en;
43 u32 ctrl;
44 u32 oe;
45 u32 leveldetect0;
46 u32 leveldetect1;
47 u32 risingdetect;
48 u32 fallingdetect;
49 u32 dataout;
Nishanth Menonae547352011-09-09 19:08:58 +053050 u32 debounce;
51 u32 debounce_en;
Charulatha V6d62e212011-04-18 15:06:51 +000052};
53
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010054struct gpio_bank {
Charulatha V03e128c2011-05-05 19:58:01 +053055 struct list_head node;
Tony Lindgren92105bb2005-09-07 17:20:26 +010056 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010057 u16 irq;
Benoit Cousson384ebe12011-08-16 11:53:02 +020058 int irq_base;
59 struct irq_domain *domain;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -080060 u32 non_wakeup_gpios;
61 u32 enabled_non_wakeup_gpios;
Charulatha V6d62e212011-04-18 15:06:51 +000062 struct gpio_regs context;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -080063 u32 saved_datain;
Kevin Hilmanb144ff62008-01-16 21:56:15 -080064 u32 level_mask;
Cory Maccarrone4318f362010-01-08 10:29:04 -080065 u32 toggle_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010066 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -080067 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -080068 struct clk *dbck;
Charulatha V058af1e2009-11-22 10:11:25 -080069 u32 mod_usage;
Kevin Hilman8865b9b2009-01-27 11:15:34 -080070 u32 dbck_enable_mask;
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +053071 bool dbck_enabled;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -080072 struct device *dev;
Charulatha Vd0d665a2011-08-31 00:02:21 +053073 bool is_mpuio;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -080074 bool dbck_flag;
Charulatha V0cde8d02011-05-05 20:15:16 +053075 bool loses_context;
Tony Lindgren5de62b82010-12-07 16:26:58 -080076 int stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -070077 u32 width;
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +053078 int context_loss_count;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +053079 int power_mode;
80 bool workaround_enabled;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070081
82 void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable);
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +053083 int (*get_context_loss_count)(struct device *dev);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070084
85 struct omap_gpio_reg_offs *regs;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010086};
87
Kevin Hilman129fd222011-04-22 07:59:07 -070088#define GPIO_INDEX(bank, gpio) (gpio % bank->width)
89#define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))
Charulatha Vc8eef652011-05-02 15:21:42 +053090#define GPIO_MOD_CTRL_BIT BIT(0)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010091
Benoit Cousson25db7112012-02-23 21:50:10 +010092static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq)
93{
94 return gpio_irq - bank->irq_base + bank->chip.base;
95}
96
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010097static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
98{
Tony Lindgren92105bb2005-09-07 17:20:26 +010099 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100100 u32 l;
101
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700102 reg += bank->regs->direction;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100103 l = __raw_readl(reg);
104 if (is_input)
105 l |= 1 << gpio;
106 else
107 l &= ~(1 << gpio);
108 __raw_writel(l, reg);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530109 bank->context.oe = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100110}
111
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700112
113/* set data out value using dedicate set/clear register */
114static void _set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, int enable)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100115{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100116 void __iomem *reg = bank->base;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700117 u32 l = GPIO_BIT(bank, gpio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100118
Tarun Kanti DebBarma2c836f72012-03-02 12:52:52 +0530119 if (enable) {
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700120 reg += bank->regs->set_dataout;
Tarun Kanti DebBarma2c836f72012-03-02 12:52:52 +0530121 bank->context.dataout |= l;
122 } else {
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700123 reg += bank->regs->clr_dataout;
Tarun Kanti DebBarma2c836f72012-03-02 12:52:52 +0530124 bank->context.dataout &= ~l;
125 }
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700126
127 __raw_writel(l, reg);
128}
129
130/* set data out value using mask register */
131static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable)
132{
133 void __iomem *reg = bank->base + bank->regs->dataout;
134 u32 gpio_bit = GPIO_BIT(bank, gpio);
135 u32 l;
136
137 l = __raw_readl(reg);
138 if (enable)
139 l |= gpio_bit;
140 else
141 l &= ~gpio_bit;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100142 __raw_writel(l, reg);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530143 bank->context.dataout = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100144}
145
Tarun Kanti DebBarma7fcca712012-02-27 11:46:09 +0530146static int _get_gpio_datain(struct gpio_bank *bank, int offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100147{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700148 void __iomem *reg = bank->base + bank->regs->datain;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100149
Tarun Kanti DebBarma7fcca712012-02-27 11:46:09 +0530150 return (__raw_readl(reg) & (1 << offset)) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100151}
152
Tarun Kanti DebBarma7fcca712012-02-27 11:46:09 +0530153static int _get_gpio_dataout(struct gpio_bank *bank, int offset)
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300154{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700155 void __iomem *reg = bank->base + bank->regs->dataout;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300156
Tarun Kanti DebBarma7fcca712012-02-27 11:46:09 +0530157 return (__raw_readl(reg) & (1 << offset)) != 0;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300158}
159
Kevin Hilmanece95282011-07-12 08:18:15 -0700160static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
161{
162 int l = __raw_readl(base + reg);
163
Benoit Cousson862ff642012-02-01 15:58:56 +0100164 if (set)
Kevin Hilmanece95282011-07-12 08:18:15 -0700165 l |= mask;
166 else
167 l &= ~mask;
168
169 __raw_writel(l, base + reg);
170}
Tony Lindgren92105bb2005-09-07 17:20:26 +0100171
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530172static inline void _gpio_dbck_enable(struct gpio_bank *bank)
173{
174 if (bank->dbck_enable_mask && !bank->dbck_enabled) {
175 clk_enable(bank->dbck);
176 bank->dbck_enabled = true;
177 }
178}
179
180static inline void _gpio_dbck_disable(struct gpio_bank *bank)
181{
182 if (bank->dbck_enable_mask && bank->dbck_enabled) {
183 clk_disable(bank->dbck);
184 bank->dbck_enabled = false;
185 }
186}
187
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700188/**
189 * _set_gpio_debounce - low level gpio debounce time
190 * @bank: the gpio bank we're acting upon
191 * @gpio: the gpio number on this @gpio
192 * @debounce: debounce time to use
193 *
194 * OMAP's debounce time is in 31us steps so we need
195 * to convert and round up to the closest unit.
196 */
197static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
198 unsigned debounce)
199{
Kevin Hilman9942da02011-04-22 12:02:05 -0700200 void __iomem *reg;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700201 u32 val;
202 u32 l;
203
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800204 if (!bank->dbck_flag)
205 return;
206
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700207 if (debounce < 32)
208 debounce = 0x01;
209 else if (debounce > 7936)
210 debounce = 0xff;
211 else
212 debounce = (debounce / 0x1f) - 1;
213
Kevin Hilman129fd222011-04-22 07:59:07 -0700214 l = GPIO_BIT(bank, gpio);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700215
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530216 clk_enable(bank->dbck);
Kevin Hilman9942da02011-04-22 12:02:05 -0700217 reg = bank->base + bank->regs->debounce;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700218 __raw_writel(debounce, reg);
219
Kevin Hilman9942da02011-04-22 12:02:05 -0700220 reg = bank->base + bank->regs->debounce_en;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700221 val = __raw_readl(reg);
222
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530223 if (debounce)
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700224 val |= l;
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530225 else
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700226 val &= ~l;
Kevin Hilmanf7ec0b02010-06-09 13:53:07 +0300227 bank->dbck_enable_mask = val;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700228
229 __raw_writel(val, reg);
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530230 clk_disable(bank->dbck);
231 /*
232 * Enable debounce clock per module.
233 * This call is mandatory because in omap_gpio_request() when
234 * *_runtime_get_sync() is called, _gpio_dbck_enable() within
235 * runtime callbck fails to turn on dbck because dbck_enable_mask
236 * used within _gpio_dbck_enable() is still not initialized at
237 * that point. Therefore we have to enable dbck here.
238 */
239 _gpio_dbck_enable(bank);
Nishanth Menonae547352011-09-09 19:08:58 +0530240 if (bank->dbck_enable_mask) {
241 bank->context.debounce = debounce;
242 bank->context.debounce_en = val;
243 }
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700244}
245
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530246static inline void set_gpio_trigger(struct gpio_bank *bank, int gpio,
Tarun Kanti DebBarma00ece7e2011-11-25 15:41:06 +0530247 unsigned trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100248{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800249 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100250 u32 gpio_bit = 1 << gpio;
251
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530252 _gpio_rmw(base, bank->regs->leveldetect0, gpio_bit,
253 trigger & IRQ_TYPE_LEVEL_LOW);
254 _gpio_rmw(base, bank->regs->leveldetect1, gpio_bit,
255 trigger & IRQ_TYPE_LEVEL_HIGH);
256 _gpio_rmw(base, bank->regs->risingdetect, gpio_bit,
257 trigger & IRQ_TYPE_EDGE_RISING);
258 _gpio_rmw(base, bank->regs->fallingdetect, gpio_bit,
259 trigger & IRQ_TYPE_EDGE_FALLING);
260
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530261 bank->context.leveldetect0 =
262 __raw_readl(bank->base + bank->regs->leveldetect0);
263 bank->context.leveldetect1 =
264 __raw_readl(bank->base + bank->regs->leveldetect1);
265 bank->context.risingdetect =
266 __raw_readl(bank->base + bank->regs->risingdetect);
267 bank->context.fallingdetect =
268 __raw_readl(bank->base + bank->regs->fallingdetect);
269
270 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530271 _gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530272 bank->context.wake_en =
273 __raw_readl(bank->base + bank->regs->wkup_en);
274 }
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530275
Ambresh K55b220c2011-06-15 13:40:45 -0700276 /* This part needs to be executed always for OMAP{34xx, 44xx} */
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530277 if (!bank->regs->irqctrl) {
278 /* On omap24xx proceed only when valid GPIO bit is set */
279 if (bank->non_wakeup_gpios) {
280 if (!(bank->non_wakeup_gpios & gpio_bit))
281 goto exit;
282 }
283
Chunqiu Wang699117a62009-06-24 17:13:39 +0000284 /*
285 * Log the edge gpio and manually trigger the IRQ
286 * after resume if the input level changes
287 * to avoid irq lost during PER RET/OFF mode
288 * Applies for omap2 non-wakeup gpio and all omap3 gpios
289 */
290 if (trigger & IRQ_TYPE_EDGE_BOTH)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800291 bank->enabled_non_wakeup_gpios |= gpio_bit;
292 else
293 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
294 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700295
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530296exit:
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530297 bank->level_mask =
298 __raw_readl(bank->base + bank->regs->leveldetect0) |
299 __raw_readl(bank->base + bank->regs->leveldetect1);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100300}
301
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800302#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800303/*
304 * This only applies to chips that can't do both rising and falling edge
305 * detection at once. For all other chips, this function is a noop.
306 */
307static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
308{
309 void __iomem *reg = bank->base;
310 u32 l = 0;
311
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530312 if (!bank->regs->irqctrl)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800313 return;
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530314
315 reg += bank->regs->irqctrl;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800316
317 l = __raw_readl(reg);
318 if ((l >> gpio) & 1)
319 l &= ~(1 << gpio);
320 else
321 l |= 1 << gpio;
322
323 __raw_writel(l, reg);
324}
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530325#else
326static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800327#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800328
Tarun Kanti DebBarma00ece7e2011-11-25 15:41:06 +0530329static int _set_gpio_triggering(struct gpio_bank *bank, int gpio,
330 unsigned trigger)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100331{
332 void __iomem *reg = bank->base;
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530333 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100334 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100335
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530336 if (bank->regs->leveldetect0 && bank->regs->wkup_en) {
337 set_gpio_trigger(bank, gpio, trigger);
338 } else if (bank->regs->irqctrl) {
339 reg += bank->regs->irqctrl;
340
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100341 l = __raw_readl(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000342 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800343 bank->toggle_mask |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100344 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100345 l |= 1 << gpio;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100346 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100347 l &= ~(1 << gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100348 else
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530349 return -EINVAL;
350
351 __raw_writel(l, reg);
352 } else if (bank->regs->edgectrl1) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100353 if (gpio & 0x08)
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530354 reg += bank->regs->edgectrl2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100355 else
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530356 reg += bank->regs->edgectrl1;
357
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100358 gpio &= 0x07;
359 l = __raw_readl(reg);
360 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100361 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100362 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100363 if (trigger & IRQ_TYPE_EDGE_FALLING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100364 l |= 1 << (gpio << 1);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530365
366 /* Enable wake-up during idle for dynamic tick */
367 _gpio_rmw(base, bank->regs->wkup_en, 1 << gpio, trigger);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530368 bank->context.wake_en =
369 __raw_readl(bank->base + bank->regs->wkup_en);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530370 __raw_writel(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100371 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100372 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100373}
374
Lennert Buytenheke9191022010-11-29 11:17:17 +0100375static int gpio_irq_type(struct irq_data *d, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100376{
Benoit Cousson25db7112012-02-23 21:50:10 +0100377 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100378 unsigned gpio;
379 int retval;
David Brownella6472532008-03-03 04:33:30 -0800380 unsigned long flags;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100381
Lennert Buytenheke9191022010-11-29 11:17:17 +0100382 if (!cpu_class_is_omap2() && d->irq > IH_MPUIO_BASE)
383 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100384 else
Benoit Cousson25db7112012-02-23 21:50:10 +0100385 gpio = irq_to_gpio(bank, d->irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100386
David Brownelle5c56ed2006-12-06 17:13:59 -0800387 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100388 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800389
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530390 if (!bank->regs->leveldetect0 &&
391 (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100392 return -EINVAL;
393
David Brownella6472532008-03-03 04:33:30 -0800394 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman129fd222011-04-22 07:59:07 -0700395 retval = _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), type);
David Brownella6472532008-03-03 04:33:30 -0800396 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800397
398 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100399 __irq_set_handler_locked(d->irq, handle_level_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800400 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100401 __irq_set_handler_locked(d->irq, handle_edge_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800402
Tony Lindgren92105bb2005-09-07 17:20:26 +0100403 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100404}
405
406static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
407{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100408 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100409
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700410 reg += bank->regs->irqstatus;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100411 __raw_writel(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300412
413 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700414 if (bank->regs->irqstatus2) {
415 reg = bank->base + bank->regs->irqstatus2;
Roger Quadrosbedfd152009-04-23 11:10:50 -0700416 __raw_writel(gpio_mask, reg);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700417 }
Roger Quadrosbedfd152009-04-23 11:10:50 -0700418
419 /* Flush posted write for the irq status to avoid spurious interrupts */
420 __raw_readl(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100421}
422
423static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
424{
Kevin Hilman129fd222011-04-22 07:59:07 -0700425 _clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100426}
427
Imre Deakea6dedd2006-06-26 16:16:00 -0700428static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
429{
430 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700431 u32 l;
Kevin Hilmanc390aad02011-04-21 09:33:36 -0700432 u32 mask = (1 << bank->width) - 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700433
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700434 reg += bank->regs->irqenable;
Imre Deak99c47702006-06-26 16:16:07 -0700435 l = __raw_readl(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700436 if (bank->regs->irqenable_inv)
Imre Deak99c47702006-06-26 16:16:07 -0700437 l = ~l;
438 l &= mask;
439 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700440}
441
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700442static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100443{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100444 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100445 u32 l;
446
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700447 if (bank->regs->set_irqenable) {
448 reg += bank->regs->set_irqenable;
449 l = gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530450 bank->context.irqenable1 |= gpio_mask;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700451 } else {
452 reg += bank->regs->irqenable;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100453 l = __raw_readl(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700454 if (bank->regs->irqenable_inv)
455 l &= ~gpio_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100456 else
457 l |= gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530458 bank->context.irqenable1 = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100459 }
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700460
461 __raw_writel(l, reg);
462}
463
464static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
465{
466 void __iomem *reg = bank->base;
467 u32 l;
468
469 if (bank->regs->clr_irqenable) {
470 reg += bank->regs->clr_irqenable;
471 l = gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530472 bank->context.irqenable1 &= ~gpio_mask;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700473 } else {
474 reg += bank->regs->irqenable;
475 l = __raw_readl(reg);
476 if (bank->regs->irqenable_inv)
477 l |= gpio_mask;
478 else
479 l &= ~gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530480 bank->context.irqenable1 = l;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700481 }
482
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100483 __raw_writel(l, reg);
484}
485
486static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
487{
Tarun Kanti DebBarma8276536c2011-11-25 15:27:37 +0530488 if (enable)
489 _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
490 else
491 _disable_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100492}
493
Tony Lindgren92105bb2005-09-07 17:20:26 +0100494/*
495 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
496 * 1510 does not seem to have a wake-up register. If JTAG is connected
497 * to the target, system will wake up always on GPIO events. While
498 * system is running all registered GPIO interrupts need to have wake-up
499 * enabled. When system is suspended, only selected GPIO interrupts need
500 * to have wake-up enabled.
501 */
502static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
503{
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700504 u32 gpio_bit = GPIO_BIT(bank, gpio);
505 unsigned long flags;
David Brownella6472532008-03-03 04:33:30 -0800506
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700507 if (bank->non_wakeup_gpios & gpio_bit) {
Benoit Cousson862ff642012-02-01 15:58:56 +0100508 dev_err(bank->dev,
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700509 "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100510 return -EINVAL;
511 }
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700512
513 spin_lock_irqsave(&bank->lock, flags);
514 if (enable)
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530515 bank->context.wake_en |= gpio_bit;
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700516 else
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530517 bank->context.wake_en &= ~gpio_bit;
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700518
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530519 __raw_writel(bank->context.wake_en, bank->base + bank->regs->wkup_en);
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700520 spin_unlock_irqrestore(&bank->lock, flags);
521
522 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100523}
524
Tony Lindgren4196dd62006-09-25 12:41:38 +0300525static void _reset_gpio(struct gpio_bank *bank, int gpio)
526{
Kevin Hilman129fd222011-04-22 07:59:07 -0700527 _set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300528 _set_gpio_irqenable(bank, gpio, 0);
529 _clear_gpio_irqstatus(bank, gpio);
Kevin Hilman129fd222011-04-22 07:59:07 -0700530 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300531}
532
Tony Lindgren92105bb2005-09-07 17:20:26 +0100533/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
Lennert Buytenheke9191022010-11-29 11:17:17 +0100534static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100535{
Benoit Cousson25db7112012-02-23 21:50:10 +0100536 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
537 unsigned int gpio = irq_to_gpio(bank, d->irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100538
Benoit Cousson25db7112012-02-23 21:50:10 +0100539 return _set_gpio_wakeup(bank, gpio, enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100540}
541
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800542static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100543{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800544 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800545 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100546
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530547 /*
548 * If this is the first gpio_request for the bank,
549 * enable the bank module.
550 */
551 if (!bank->mod_usage)
552 pm_runtime_get_sync(bank->dev);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100553
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530554 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300555 /* Set trigger to none. You need to enable the desired trigger with
556 * request_irq() or set_irq_type().
557 */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800558 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100559
Charulatha Vfad96ea2011-05-25 11:23:50 +0530560 if (bank->regs->pinctrl) {
561 void __iomem *reg = bank->base + bank->regs->pinctrl;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100562
Tony Lindgren92105bb2005-09-07 17:20:26 +0100563 /* Claim the pin for MPU */
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800564 __raw_writel(__raw_readl(reg) | (1 << offset), reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100565 }
Charulatha Vfad96ea2011-05-25 11:23:50 +0530566
Charulatha Vc8eef652011-05-02 15:21:42 +0530567 if (bank->regs->ctrl && !bank->mod_usage) {
568 void __iomem *reg = bank->base + bank->regs->ctrl;
569 u32 ctrl;
Charulatha V9f096862010-05-14 12:05:27 -0700570
Charulatha Vc8eef652011-05-02 15:21:42 +0530571 ctrl = __raw_readl(reg);
572 /* Module is enabled, clocks are not gated */
573 ctrl &= ~GPIO_MOD_CTRL_BIT;
574 __raw_writel(ctrl, reg);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530575 bank->context.ctrl = ctrl;
Charulatha V058af1e2009-11-22 10:11:25 -0800576 }
Charulatha Vc8eef652011-05-02 15:21:42 +0530577
578 bank->mod_usage |= 1 << offset;
579
David Brownella6472532008-03-03 04:33:30 -0800580 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100581
582 return 0;
583}
584
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800585static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100586{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800587 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +0530588 void __iomem *base = bank->base;
David Brownella6472532008-03-03 04:33:30 -0800589 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100590
David Brownella6472532008-03-03 04:33:30 -0800591 spin_lock_irqsave(&bank->lock, flags);
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +0530592
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530593 if (bank->regs->wkup_en) {
Tony Lindgren92105bb2005-09-07 17:20:26 +0100594 /* Disable wake-up during idle for dynamic tick */
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +0530595 _gpio_rmw(base, bank->regs->wkup_en, 1 << offset, 0);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530596 bank->context.wake_en =
597 __raw_readl(bank->base + bank->regs->wkup_en);
598 }
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +0530599
Charulatha Vc8eef652011-05-02 15:21:42 +0530600 bank->mod_usage &= ~(1 << offset);
Charulatha V9f096862010-05-14 12:05:27 -0700601
Charulatha Vc8eef652011-05-02 15:21:42 +0530602 if (bank->regs->ctrl && !bank->mod_usage) {
603 void __iomem *reg = bank->base + bank->regs->ctrl;
604 u32 ctrl;
605
606 ctrl = __raw_readl(reg);
607 /* Module is disabled, clocks are gated */
608 ctrl |= GPIO_MOD_CTRL_BIT;
609 __raw_writel(ctrl, reg);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530610 bank->context.ctrl = ctrl;
Charulatha V058af1e2009-11-22 10:11:25 -0800611 }
Charulatha Vc8eef652011-05-02 15:21:42 +0530612
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800613 _reset_gpio(bank, bank->chip.base + offset);
David Brownella6472532008-03-03 04:33:30 -0800614 spin_unlock_irqrestore(&bank->lock, flags);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530615
616 /*
617 * If this is the last gpio to be freed in the bank,
618 * disable the bank module.
619 */
620 if (!bank->mod_usage)
621 pm_runtime_put(bank->dev);
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 int unmasked = 0;
Will Deaconee144182011-02-21 13:46:08 +0000640 struct irq_chip *chip = irq_desc_get_chip(desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100641
Will Deaconee144182011-02-21 13:46:08 +0000642 chained_irq_enter(chip, desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100643
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100644 bank = irq_get_handler_data(irq);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700645 isr_reg = bank->base + bank->regs->irqstatus;
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530646 pm_runtime_get_sync(bank->dev);
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
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530658 if (bank->level_mask)
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800659 level_mask = bank->level_mask & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100660
661 /* clear edge sensitive interrupts before handler(s) are
662 called so that we don't miss any interrupt occurred while
663 executing them */
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700664 _disable_gpio_irqbank(bank, isr_saved & ~level_mask);
Tony Lindgren6e60e792006-04-02 17:46:23 +0100665 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700666 _enable_gpio_irqbank(bank, isr_saved & ~level_mask);
Tony Lindgren6e60e792006-04-02 17:46:23 +0100667
668 /* if there is only edge sensitive GPIO pin interrupts
669 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -0700670 if (!level_mask && !unmasked) {
671 unmasked = 1;
Will Deaconee144182011-02-21 13:46:08 +0000672 chained_irq_exit(chip, desc);
Imre Deakea6dedd2006-06-26 16:16:00 -0700673 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100674
Tony Lindgren92105bb2005-09-07 17:20:26 +0100675 if (!isr)
676 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100677
Benoit Cousson384ebe12011-08-16 11:53:02 +0200678 gpio_irq = bank->irq_base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100679 for (; isr != 0; isr >>= 1, gpio_irq++) {
Benoit Cousson25db7112012-02-23 21:50:10 +0100680 int gpio = irq_to_gpio(bank, gpio_irq);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800681
Tony Lindgren92105bb2005-09-07 17:20:26 +0100682 if (!(isr & 1))
683 continue;
Thomas Gleixner29454dd2006-07-03 02:22:22 +0200684
Benoit Cousson25db7112012-02-23 21:50:10 +0100685 gpio_index = GPIO_INDEX(bank, gpio);
686
Cory Maccarrone4318f362010-01-08 10:29:04 -0800687 /*
688 * Some chips can't respond to both rising and falling
689 * at the same time. If this irq was requested with
690 * both flags, we need to flip the ICR data for the IRQ
691 * to respond to the IRQ for the opposite direction.
692 * This will be indicated in the bank toggle_mask.
693 */
694 if (bank->toggle_mask & (1 << gpio_index))
695 _toggle_gpio_edge_triggering(bank, gpio_index);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800696
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100697 generic_handle_irq(gpio_irq);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100698 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000699 }
Imre Deakea6dedd2006-06-26 16:16:00 -0700700 /* if bank has any level sensitive GPIO pin interrupt
701 configured, we must unmask the bank interrupt only after
702 handler(s) are executed in order to avoid spurious bank
703 interrupt */
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800704exit:
Imre Deakea6dedd2006-06-26 16:16:00 -0700705 if (!unmasked)
Will Deaconee144182011-02-21 13:46:08 +0000706 chained_irq_exit(chip, desc);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530707 pm_runtime_put(bank->dev);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100708}
709
Lennert Buytenheke9191022010-11-29 11:17:17 +0100710static void gpio_irq_shutdown(struct irq_data *d)
Tony Lindgren4196dd62006-09-25 12:41:38 +0300711{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100712 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Benoit Cousson25db7112012-02-23 21:50:10 +0100713 unsigned int gpio = irq_to_gpio(bank, d->irq);
Colin Cross85ec7b92011-06-06 13:38:18 -0700714 unsigned long flags;
Tony Lindgren4196dd62006-09-25 12:41:38 +0300715
Colin Cross85ec7b92011-06-06 13:38:18 -0700716 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300717 _reset_gpio(bank, gpio);
Colin Cross85ec7b92011-06-06 13:38:18 -0700718 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300719}
720
Lennert Buytenheke9191022010-11-29 11:17:17 +0100721static void gpio_ack_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100722{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100723 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Benoit Cousson25db7112012-02-23 21:50:10 +0100724 unsigned int gpio = irq_to_gpio(bank, d->irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100725
726 _clear_gpio_irqstatus(bank, gpio);
727}
728
Lennert Buytenheke9191022010-11-29 11:17:17 +0100729static void gpio_mask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100730{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100731 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Benoit Cousson25db7112012-02-23 21:50:10 +0100732 unsigned int gpio = irq_to_gpio(bank, d->irq);
Colin Cross85ec7b92011-06-06 13:38:18 -0700733 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100734
Colin Cross85ec7b92011-06-06 13:38:18 -0700735 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100736 _set_gpio_irqenable(bank, gpio, 0);
Kevin Hilman129fd222011-04-22 07:59:07 -0700737 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
Colin Cross85ec7b92011-06-06 13:38:18 -0700738 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100739}
740
Lennert Buytenheke9191022010-11-29 11:17:17 +0100741static void gpio_unmask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100742{
Lennert Buytenheke9191022010-11-29 11:17:17 +0100743 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
Benoit Cousson25db7112012-02-23 21:50:10 +0100744 unsigned int gpio = irq_to_gpio(bank, d->irq);
Kevin Hilman129fd222011-04-22 07:59:07 -0700745 unsigned int irq_mask = GPIO_BIT(bank, gpio);
Thomas Gleixner8c04a172011-03-24 12:40:15 +0100746 u32 trigger = irqd_get_trigger_type(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700747 unsigned long flags;
Kevin Hilman55b60192009-06-04 15:57:10 -0700748
Colin Cross85ec7b92011-06-06 13:38:18 -0700749 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman55b60192009-06-04 15:57:10 -0700750 if (trigger)
Kevin Hilman129fd222011-04-22 07:59:07 -0700751 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800752
753 /* For level-triggered GPIOs, the clearing must be done after
754 * the HW source is cleared, thus after the handler has run */
755 if (bank->level_mask & irq_mask) {
756 _set_gpio_irqenable(bank, gpio, 0);
757 _clear_gpio_irqstatus(bank, gpio);
758 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100759
Kevin Hilman4de8c752008-01-16 21:56:14 -0800760 _set_gpio_irqenable(bank, gpio, 1);
Colin Cross85ec7b92011-06-06 13:38:18 -0700761 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100762}
763
David Brownelle5c56ed2006-12-06 17:13:59 -0800764static struct irq_chip gpio_irq_chip = {
765 .name = "GPIO",
Lennert Buytenheke9191022010-11-29 11:17:17 +0100766 .irq_shutdown = gpio_irq_shutdown,
767 .irq_ack = gpio_ack_irq,
768 .irq_mask = gpio_mask_irq,
769 .irq_unmask = gpio_unmask_irq,
770 .irq_set_type = gpio_irq_type,
771 .irq_set_wake = gpio_wake_enable,
David Brownelle5c56ed2006-12-06 17:13:59 -0800772};
773
774/*---------------------------------------------------------------------*/
775
Magnus Damm79ee0312009-07-08 13:22:04 +0200776static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800777{
Magnus Damm79ee0312009-07-08 13:22:04 +0200778 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800779 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800780 void __iomem *mask_reg = bank->base +
781 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800782 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800783
David Brownella6472532008-03-03 04:33:30 -0800784 spin_lock_irqsave(&bank->lock, flags);
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530785 __raw_writel(0xffff & ~bank->context.wake_en, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800786 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800787
788 return 0;
789}
790
Magnus Damm79ee0312009-07-08 13:22:04 +0200791static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800792{
Magnus Damm79ee0312009-07-08 13:22:04 +0200793 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800794 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800795 void __iomem *mask_reg = bank->base +
796 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800797 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800798
David Brownella6472532008-03-03 04:33:30 -0800799 spin_lock_irqsave(&bank->lock, flags);
Tarun Kanti DebBarma499fa282012-04-27 19:43:34 +0530800 __raw_writel(bank->context.wake_en, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800801 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800802
803 return 0;
804}
805
Alexey Dobriyan47145212009-12-14 18:00:08 -0800806static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +0200807 .suspend_noirq = omap_mpuio_suspend_noirq,
808 .resume_noirq = omap_mpuio_resume_noirq,
809};
810
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +0200811/* use platform_driver for this. */
David Brownell11a78b72006-12-06 17:14:11 -0800812static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -0800813 .driver = {
814 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +0200815 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -0800816 },
817};
818
819static struct platform_device omap_mpuio_device = {
820 .name = "mpuio",
821 .id = -1,
822 .dev = {
823 .driver = &omap_mpuio_driver.driver,
824 }
825 /* could list the /proc/iomem resources */
826};
827
Charulatha V03e128c2011-05-05 19:58:01 +0530828static inline void mpuio_init(struct gpio_bank *bank)
David Brownell11a78b72006-12-06 17:14:11 -0800829{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800830 platform_set_drvdata(&omap_mpuio_device, bank);
David Brownellfcf126d2007-04-02 12:46:47 -0700831
David Brownell11a78b72006-12-06 17:14:11 -0800832 if (platform_driver_register(&omap_mpuio_driver) == 0)
833 (void) platform_device_register(&omap_mpuio_device);
834}
835
David Brownelle5c56ed2006-12-06 17:13:59 -0800836/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100837
David Brownell52e31342008-03-03 12:43:23 -0800838static int gpio_input(struct gpio_chip *chip, unsigned offset)
839{
840 struct gpio_bank *bank;
841 unsigned long flags;
842
843 bank = container_of(chip, struct gpio_bank, chip);
844 spin_lock_irqsave(&bank->lock, flags);
845 _set_gpio_direction(bank, offset, 1);
846 spin_unlock_irqrestore(&bank->lock, flags);
847 return 0;
848}
849
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300850static int gpio_is_input(struct gpio_bank *bank, int mask)
851{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700852 void __iomem *reg = bank->base + bank->regs->direction;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300853
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300854 return __raw_readl(reg) & mask;
855}
856
David Brownell52e31342008-03-03 12:43:23 -0800857static int gpio_get(struct gpio_chip *chip, unsigned offset)
858{
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300859 struct gpio_bank *bank;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300860 u32 mask;
861
Charulatha Va8be8da2011-04-22 16:38:16 +0530862 bank = container_of(chip, struct gpio_bank, chip);
Tarun Kanti DebBarma7fcca712012-02-27 11:46:09 +0530863 mask = (1 << offset);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300864
865 if (gpio_is_input(bank, mask))
Tarun Kanti DebBarma7fcca712012-02-27 11:46:09 +0530866 return _get_gpio_datain(bank, offset);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300867 else
Tarun Kanti DebBarma7fcca712012-02-27 11:46:09 +0530868 return _get_gpio_dataout(bank, offset);
David Brownell52e31342008-03-03 12:43:23 -0800869}
870
871static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
872{
873 struct gpio_bank *bank;
874 unsigned long flags;
875
876 bank = container_of(chip, struct gpio_bank, chip);
877 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700878 bank->set_dataout(bank, offset, value);
David Brownell52e31342008-03-03 12:43:23 -0800879 _set_gpio_direction(bank, offset, 0);
880 spin_unlock_irqrestore(&bank->lock, flags);
881 return 0;
882}
883
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700884static int gpio_debounce(struct gpio_chip *chip, unsigned offset,
885 unsigned debounce)
886{
887 struct gpio_bank *bank;
888 unsigned long flags;
889
890 bank = container_of(chip, struct gpio_bank, chip);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800891
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700892 spin_lock_irqsave(&bank->lock, flags);
893 _set_gpio_debounce(bank, offset, debounce);
894 spin_unlock_irqrestore(&bank->lock, flags);
895
896 return 0;
897}
898
David Brownell52e31342008-03-03 12:43:23 -0800899static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
900{
901 struct gpio_bank *bank;
902 unsigned long flags;
903
904 bank = container_of(chip, struct gpio_bank, chip);
905 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700906 bank->set_dataout(bank, offset, value);
David Brownell52e31342008-03-03 12:43:23 -0800907 spin_unlock_irqrestore(&bank->lock, flags);
908}
909
David Brownella007b702008-12-10 17:35:25 -0800910static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
911{
912 struct gpio_bank *bank;
913
914 bank = container_of(chip, struct gpio_bank, chip);
Benoit Cousson384ebe12011-08-16 11:53:02 +0200915 return bank->irq_base + offset;
David Brownella007b702008-12-10 17:35:25 -0800916}
917
David Brownell52e31342008-03-03 12:43:23 -0800918/*---------------------------------------------------------------------*/
919
Tony Lindgren9a748052010-12-07 16:26:56 -0800920static void __init omap_gpio_show_rev(struct gpio_bank *bank)
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700921{
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700922 static bool called;
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700923 u32 rev;
924
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700925 if (called || bank->regs->revision == USHRT_MAX)
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700926 return;
927
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700928 rev = __raw_readw(bank->base + bank->regs->revision);
929 pr_info("OMAP GPIO hardware version %d.%d\n",
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700930 (rev >> 4) & 0x0f, rev & 0x0f);
Kevin Hilmane5ff4442011-04-22 14:37:16 -0700931
932 called = true;
Tony Lindgren9f7065d2009-10-19 15:25:20 -0700933}
934
David Brownell8ba55c52008-02-26 11:10:50 -0800935/* This lock class tells lockdep that GPIO irqs are in a different
936 * category than their parents, so it won't report false recursion.
937 */
938static struct lock_class_key gpio_lock_class;
939
Charulatha V03e128c2011-05-05 19:58:01 +0530940static void omap_gpio_mod_init(struct gpio_bank *bank)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -0800941{
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530942 void __iomem *base = bank->base;
943 u32 l = 0xffffffff;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -0800944
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530945 if (bank->width == 16)
946 l = 0xffff;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -0800947
Charulatha Vd0d665a2011-08-31 00:02:21 +0530948 if (bank->is_mpuio) {
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530949 __raw_writel(l, bank->base + bank->regs->irqenable);
950 return;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -0800951 }
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530952
953 _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->irqenable_inv);
Tarun Kanti DebBarma6edd94d2012-04-30 12:50:12 +0530954 _gpio_rmw(base, bank->regs->irqstatus, l, !bank->regs->irqenable_inv);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530955 if (bank->regs->debounce_en)
Tarun Kanti DebBarma6edd94d2012-04-30 12:50:12 +0530956 __raw_writel(0, base + bank->regs->debounce_en);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530957
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +0530958 /* Save OE default value (0xffffffff) in the context */
959 bank->context.oe = __raw_readl(bank->base + bank->regs->direction);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +0530960 /* Initialize interface clk ungated, module enabled */
961 if (bank->regs->ctrl)
Tarun Kanti DebBarma6edd94d2012-04-30 12:50:12 +0530962 __raw_writel(0, base + bank->regs->ctrl);
Tarun Kanti DebBarma34672012012-07-11 14:43:14 +0530963
964 bank->dbck = clk_get(bank->dev, "dbclk");
965 if (IS_ERR(bank->dbck))
966 dev_err(bank->dev, "Could not get gpio dbck\n");
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -0800967}
968
Tony Lindgren8805f412012-03-05 15:32:38 -0800969static __devinit void
Kevin Hilmanf8b46b52011-04-21 13:23:34 -0700970omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start,
971 unsigned int num)
972{
973 struct irq_chip_generic *gc;
974 struct irq_chip_type *ct;
975
976 gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base,
977 handle_simple_irq);
Todd Poynor83233742011-07-18 07:43:14 -0700978 if (!gc) {
979 dev_err(bank->dev, "Memory alloc failed for gc\n");
980 return;
981 }
982
Kevin Hilmanf8b46b52011-04-21 13:23:34 -0700983 ct = gc->chip_types;
984
985 /* NOTE: No ack required, reading IRQ status clears it. */
986 ct->chip.irq_mask = irq_gc_mask_set_bit;
987 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
988 ct->chip.irq_set_type = gpio_irq_type;
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +0530989
990 if (bank->regs->wkup_en)
Kevin Hilmanf8b46b52011-04-21 13:23:34 -0700991 ct->chip.irq_set_wake = gpio_wake_enable,
992
993 ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride;
994 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
995 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
996}
997
Russell Kingd52b31d2011-05-27 13:56:12 -0700998static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -0800999{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001000 int j;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001001 static int gpio;
1002
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001003 /*
1004 * REVISIT eventually switch from OMAP-specific gpio structs
1005 * over to the generic ones
1006 */
1007 bank->chip.request = omap_gpio_request;
1008 bank->chip.free = omap_gpio_free;
1009 bank->chip.direction_input = gpio_input;
1010 bank->chip.get = gpio_get;
1011 bank->chip.direction_output = gpio_output;
1012 bank->chip.set_debounce = gpio_debounce;
1013 bank->chip.set = gpio_set;
1014 bank->chip.to_irq = gpio_2irq;
Charulatha Vd0d665a2011-08-31 00:02:21 +05301015 if (bank->is_mpuio) {
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001016 bank->chip.label = "mpuio";
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301017 if (bank->regs->wkup_en)
1018 bank->chip.dev = &omap_mpuio_device.dev;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001019 bank->chip.base = OMAP_MPUIO(0);
1020 } else {
1021 bank->chip.label = "gpio";
1022 bank->chip.base = gpio;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001023 gpio += bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001024 }
Kevin Hilmand5f46242011-04-21 09:23:00 -07001025 bank->chip.ngpio = bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001026
1027 gpiochip_add(&bank->chip);
1028
Benoit Cousson384ebe12011-08-16 11:53:02 +02001029 for (j = bank->irq_base; j < bank->irq_base + bank->width; j++) {
Thomas Gleixner1475b852011-03-22 17:11:09 +01001030 irq_set_lockdep_class(j, &gpio_lock_class);
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001031 irq_set_chip_data(j, bank);
Charulatha Vd0d665a2011-08-31 00:02:21 +05301032 if (bank->is_mpuio) {
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001033 omap_mpuio_alloc_gc(bank, j, bank->width);
1034 } else {
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001035 irq_set_chip(j, &gpio_irq_chip);
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001036 irq_set_handler(j, handle_simple_irq);
1037 set_irq_flags(j, IRQF_VALID);
1038 }
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001039 }
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001040 irq_set_chained_handler(bank->irq, gpio_irq_handler);
1041 irq_set_handler_data(bank->irq, bank);
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001042}
1043
Benoit Cousson384ebe12011-08-16 11:53:02 +02001044static const struct of_device_id omap_gpio_match[];
1045
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001046static int __devinit omap_gpio_probe(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001047{
Benoit Cousson862ff642012-02-01 15:58:56 +01001048 struct device *dev = &pdev->dev;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001049 struct device_node *node = dev->of_node;
1050 const struct of_device_id *match;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001051 struct omap_gpio_platform_data *pdata;
1052 struct resource *res;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001053 struct gpio_bank *bank;
Charulatha V03e128c2011-05-05 19:58:01 +05301054 int ret = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001055
Benoit Cousson384ebe12011-08-16 11:53:02 +02001056 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
1057
1058 pdata = match ? match->data : dev->platform_data;
1059 if (!pdata)
Benoit Cousson96751fc2012-02-01 16:01:39 +01001060 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001061
Benoit Cousson96751fc2012-02-01 16:01:39 +01001062 bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
Charulatha V03e128c2011-05-05 19:58:01 +05301063 if (!bank) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001064 dev_err(dev, "Memory alloc failed\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001065 return -ENOMEM;
Charulatha V03e128c2011-05-05 19:58:01 +05301066 }
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001067
1068 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1069 if (unlikely(!res)) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001070 dev_err(dev, "Invalid IRQ resource\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001071 return -ENODEV;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001072 }
1073
1074 bank->irq = res->start;
Benoit Cousson862ff642012-02-01 15:58:56 +01001075 bank->dev = dev;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001076 bank->dbck_flag = pdata->dbck_flag;
Tony Lindgren5de62b82010-12-07 16:26:58 -08001077 bank->stride = pdata->bank_stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001078 bank->width = pdata->bank_width;
Charulatha Vd0d665a2011-08-31 00:02:21 +05301079 bank->is_mpuio = pdata->is_mpuio;
Charulatha V803a2432011-05-05 17:04:12 +05301080 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
Charulatha V0cde8d02011-05-05 20:15:16 +05301081 bank->loses_context = pdata->loses_context;
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301082 bank->get_context_loss_count = pdata->get_context_loss_count;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001083 bank->regs = pdata->regs;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001084#ifdef CONFIG_OF_GPIO
1085 bank->chip.of_node = of_node_get(node);
1086#endif
1087
1088 bank->irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
1089 if (bank->irq_base < 0) {
1090 dev_err(dev, "Couldn't allocate IRQ numbers\n");
1091 return -ENODEV;
1092 }
1093
1094 bank->domain = irq_domain_add_legacy(node, bank->width, bank->irq_base,
1095 0, &irq_domain_simple_ops, NULL);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001096
1097 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1098 bank->set_dataout = _set_gpio_dataout_reg;
1099 else
1100 bank->set_dataout = _set_gpio_dataout_mask;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001101
1102 spin_lock_init(&bank->lock);
1103
1104 /* Static mapping, never released */
1105 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1106 if (unlikely(!res)) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001107 dev_err(dev, "Invalid mem resource\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001108 return -ENODEV;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001109 }
1110
Benoit Cousson96751fc2012-02-01 16:01:39 +01001111 if (!devm_request_mem_region(dev, res->start, resource_size(res),
1112 pdev->name)) {
1113 dev_err(dev, "Region already claimed\n");
1114 return -EBUSY;
1115 }
1116
1117 bank->base = devm_ioremap(dev, res->start, resource_size(res));
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001118 if (!bank->base) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001119 dev_err(dev, "Could not ioremap\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001120 return -ENOMEM;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001121 }
1122
Tarun Kanti DebBarma065cd792011-11-24 01:48:52 +05301123 platform_set_drvdata(pdev, bank);
1124
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001125 pm_runtime_enable(bank->dev);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301126 pm_runtime_irq_safe(bank->dev);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001127 pm_runtime_get_sync(bank->dev);
1128
Charulatha Vd0d665a2011-08-31 00:02:21 +05301129 if (bank->is_mpuio)
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301130 mpuio_init(bank);
1131
Charulatha V03e128c2011-05-05 19:58:01 +05301132 omap_gpio_mod_init(bank);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001133 omap_gpio_chip_init(bank);
Tony Lindgren9a748052010-12-07 16:26:56 -08001134 omap_gpio_show_rev(bank);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001135
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301136 pm_runtime_put(bank->dev);
1137
Charulatha V03e128c2011-05-05 19:58:01 +05301138 list_add_tail(&bank->node, &omap_gpio_list);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001139
Charulatha V03e128c2011-05-05 19:58:01 +05301140 return ret;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001141}
1142
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301143#ifdef CONFIG_ARCH_OMAP2PLUS
1144
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301145#if defined(CONFIG_PM_RUNTIME)
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301146static void omap_gpio_restore_context(struct gpio_bank *bank);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001147
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301148static int omap_gpio_runtime_suspend(struct device *dev)
1149{
1150 struct platform_device *pdev = to_platform_device(dev);
1151 struct gpio_bank *bank = platform_get_drvdata(pdev);
1152 u32 l1 = 0, l2 = 0;
1153 unsigned long flags;
Kevin Hilman68942ed2012-03-05 15:10:04 -08001154 u32 wake_low, wake_hi;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301155
1156 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman68942ed2012-03-05 15:10:04 -08001157
1158 /*
1159 * Only edges can generate a wakeup event to the PRCM.
1160 *
1161 * Therefore, ensure any wake-up capable GPIOs have
1162 * edge-detection enabled before going idle to ensure a wakeup
1163 * to the PRCM is generated on a GPIO transition. (c.f. 34xx
1164 * NDA TRM 25.5.3.1)
1165 *
1166 * The normal values will be restored upon ->runtime_resume()
1167 * by writing back the values saved in bank->context.
1168 */
1169 wake_low = bank->context.leveldetect0 & bank->context.wake_en;
1170 if (wake_low)
1171 __raw_writel(wake_low | bank->context.fallingdetect,
1172 bank->base + bank->regs->fallingdetect);
1173 wake_hi = bank->context.leveldetect1 & bank->context.wake_en;
1174 if (wake_hi)
1175 __raw_writel(wake_hi | bank->context.risingdetect,
1176 bank->base + bank->regs->risingdetect);
1177
Kevin Hilmanb3c64bc2012-05-17 16:42:16 -07001178 if (!bank->enabled_non_wakeup_gpios)
1179 goto update_gpio_context_count;
1180
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301181 if (bank->power_mode != OFF_MODE) {
1182 bank->power_mode = 0;
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +05301183 goto update_gpio_context_count;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301184 }
1185 /*
1186 * If going to OFF, remove triggering for all
1187 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1188 * generated. See OMAP2420 Errata item 1.101.
1189 */
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301190 bank->saved_datain = __raw_readl(bank->base +
1191 bank->regs->datain);
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301192 l1 = bank->context.fallingdetect;
1193 l2 = bank->context.risingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301194
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301195 l1 &= ~bank->enabled_non_wakeup_gpios;
1196 l2 &= ~bank->enabled_non_wakeup_gpios;
1197
1198 __raw_writel(l1, bank->base + bank->regs->fallingdetect);
1199 __raw_writel(l2, bank->base + bank->regs->risingdetect);
1200
1201 bank->workaround_enabled = true;
1202
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +05301203update_gpio_context_count:
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301204 if (bank->get_context_loss_count)
1205 bank->context_loss_count =
1206 bank->get_context_loss_count(bank->dev);
1207
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +05301208 _gpio_dbck_disable(bank);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301209 spin_unlock_irqrestore(&bank->lock, flags);
1210
1211 return 0;
1212}
1213
1214static int omap_gpio_runtime_resume(struct device *dev)
1215{
1216 struct platform_device *pdev = to_platform_device(dev);
1217 struct gpio_bank *bank = platform_get_drvdata(pdev);
1218 int context_lost_cnt_after;
1219 u32 l = 0, gen, gen0, gen1;
1220 unsigned long flags;
1221
1222 spin_lock_irqsave(&bank->lock, flags);
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +05301223 _gpio_dbck_enable(bank);
Kevin Hilman68942ed2012-03-05 15:10:04 -08001224
1225 /*
1226 * In ->runtime_suspend(), level-triggered, wakeup-enabled
1227 * GPIOs were set to edge trigger also in order to be able to
1228 * generate a PRCM wakeup. Here we restore the
1229 * pre-runtime_suspend() values for edge triggering.
1230 */
1231 __raw_writel(bank->context.fallingdetect,
1232 bank->base + bank->regs->fallingdetect);
1233 __raw_writel(bank->context.risingdetect,
1234 bank->base + bank->regs->risingdetect);
1235
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301236 if (bank->get_context_loss_count) {
1237 context_lost_cnt_after =
1238 bank->get_context_loss_count(bank->dev);
Kevin Hilman22770de2012-05-17 14:52:56 -07001239 if (context_lost_cnt_after != bank->context_loss_count) {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301240 omap_gpio_restore_context(bank);
1241 } else {
1242 spin_unlock_irqrestore(&bank->lock, flags);
1243 return 0;
1244 }
1245 }
1246
Tarun Kanti DebBarma1b1287032012-04-27 19:43:38 +05301247 if (!bank->workaround_enabled) {
1248 spin_unlock_irqrestore(&bank->lock, flags);
1249 return 0;
1250 }
1251
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301252 __raw_writel(bank->context.fallingdetect,
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301253 bank->base + bank->regs->fallingdetect);
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301254 __raw_writel(bank->context.risingdetect,
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301255 bank->base + bank->regs->risingdetect);
1256 l = __raw_readl(bank->base + bank->regs->datain);
1257
1258 /*
1259 * Check if any of the non-wakeup interrupt GPIOs have changed
1260 * state. If so, generate an IRQ by software. This is
1261 * horribly racy, but it's the best we can do to work around
1262 * this silicon bug.
1263 */
1264 l ^= bank->saved_datain;
1265 l &= bank->enabled_non_wakeup_gpios;
1266
1267 /*
1268 * No need to generate IRQs for the rising edge for gpio IRQs
1269 * configured with falling edge only; and vice versa.
1270 */
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301271 gen0 = l & bank->context.fallingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301272 gen0 &= bank->saved_datain;
1273
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301274 gen1 = l & bank->context.risingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301275 gen1 &= ~(bank->saved_datain);
1276
1277 /* FIXME: Consider GPIO IRQs with level detections properly! */
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301278 gen = l & (~(bank->context.fallingdetect) &
1279 ~(bank->context.risingdetect));
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301280 /* Consider all GPIO IRQs needed to be updated */
1281 gen |= gen0 | gen1;
1282
1283 if (gen) {
1284 u32 old0, old1;
1285
1286 old0 = __raw_readl(bank->base + bank->regs->leveldetect0);
1287 old1 = __raw_readl(bank->base + bank->regs->leveldetect1);
1288
Tarun Kanti DebBarma4e962e82012-04-27 19:43:37 +05301289 if (!bank->regs->irqstatus_raw0) {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301290 __raw_writel(old0 | gen, bank->base +
1291 bank->regs->leveldetect0);
1292 __raw_writel(old1 | gen, bank->base +
1293 bank->regs->leveldetect1);
1294 }
1295
Tarun Kanti DebBarma4e962e82012-04-27 19:43:37 +05301296 if (bank->regs->irqstatus_raw0) {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301297 __raw_writel(old0 | l, bank->base +
1298 bank->regs->leveldetect0);
1299 __raw_writel(old1 | l, bank->base +
1300 bank->regs->leveldetect1);
1301 }
1302 __raw_writel(old0, bank->base + bank->regs->leveldetect0);
1303 __raw_writel(old1, bank->base + bank->regs->leveldetect1);
1304 }
1305
1306 bank->workaround_enabled = false;
1307 spin_unlock_irqrestore(&bank->lock, flags);
1308
1309 return 0;
1310}
1311#endif /* CONFIG_PM_RUNTIME */
1312
1313void omap2_gpio_prepare_for_idle(int pwr_mode)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001314{
Charulatha V03e128c2011-05-05 19:58:01 +05301315 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001316
Charulatha V03e128c2011-05-05 19:58:01 +05301317 list_for_each_entry(bank, &omap_gpio_list, node) {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301318 if (!bank->mod_usage || !bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301319 continue;
1320
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301321 bank->power_mode = pwr_mode;
1322
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301323 pm_runtime_put_sync_suspend(bank->dev);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001324 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001325}
1326
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001327void omap2_gpio_resume_after_idle(void)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001328{
Charulatha V03e128c2011-05-05 19:58:01 +05301329 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001330
Charulatha V03e128c2011-05-05 19:58:01 +05301331 list_for_each_entry(bank, &omap_gpio_list, node) {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301332 if (!bank->mod_usage || !bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301333 continue;
1334
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301335 pm_runtime_get_sync(bank->dev);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001336 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001337}
1338
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301339#if defined(CONFIG_PM_RUNTIME)
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301340static void omap_gpio_restore_context(struct gpio_bank *bank)
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301341{
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301342 __raw_writel(bank->context.wake_en,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301343 bank->base + bank->regs->wkup_en);
1344 __raw_writel(bank->context.ctrl, bank->base + bank->regs->ctrl);
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301345 __raw_writel(bank->context.leveldetect0,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301346 bank->base + bank->regs->leveldetect0);
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301347 __raw_writel(bank->context.leveldetect1,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301348 bank->base + bank->regs->leveldetect1);
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301349 __raw_writel(bank->context.risingdetect,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301350 bank->base + bank->regs->risingdetect);
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301351 __raw_writel(bank->context.fallingdetect,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301352 bank->base + bank->regs->fallingdetect);
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301353 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1354 __raw_writel(bank->context.dataout,
1355 bank->base + bank->regs->set_dataout);
1356 else
1357 __raw_writel(bank->context.dataout,
1358 bank->base + bank->regs->dataout);
Nishanth Menon6d13eaa2011-08-29 18:54:50 +05301359 __raw_writel(bank->context.oe, bank->base + bank->regs->direction);
1360
Nishanth Menonae547352011-09-09 19:08:58 +05301361 if (bank->dbck_enable_mask) {
1362 __raw_writel(bank->context.debounce, bank->base +
1363 bank->regs->debounce);
1364 __raw_writel(bank->context.debounce_en,
1365 bank->base + bank->regs->debounce_en);
1366 }
Nishanth Menonba805be2011-08-29 18:41:08 +05301367
1368 __raw_writel(bank->context.irqenable1,
1369 bank->base + bank->regs->irqenable);
1370 __raw_writel(bank->context.irqenable2,
1371 bank->base + bank->regs->irqenable2);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301372}
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301373#endif /* CONFIG_PM_RUNTIME */
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301374#else
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301375#define omap_gpio_runtime_suspend NULL
1376#define omap_gpio_runtime_resume NULL
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301377#endif
1378
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301379static const struct dev_pm_ops gpio_pm_ops = {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301380 SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume,
1381 NULL)
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301382};
1383
Benoit Cousson384ebe12011-08-16 11:53:02 +02001384#if defined(CONFIG_OF)
1385static struct omap_gpio_reg_offs omap2_gpio_regs = {
1386 .revision = OMAP24XX_GPIO_REVISION,
1387 .direction = OMAP24XX_GPIO_OE,
1388 .datain = OMAP24XX_GPIO_DATAIN,
1389 .dataout = OMAP24XX_GPIO_DATAOUT,
1390 .set_dataout = OMAP24XX_GPIO_SETDATAOUT,
1391 .clr_dataout = OMAP24XX_GPIO_CLEARDATAOUT,
1392 .irqstatus = OMAP24XX_GPIO_IRQSTATUS1,
1393 .irqstatus2 = OMAP24XX_GPIO_IRQSTATUS2,
1394 .irqenable = OMAP24XX_GPIO_IRQENABLE1,
1395 .irqenable2 = OMAP24XX_GPIO_IRQENABLE2,
1396 .set_irqenable = OMAP24XX_GPIO_SETIRQENABLE1,
1397 .clr_irqenable = OMAP24XX_GPIO_CLEARIRQENABLE1,
1398 .debounce = OMAP24XX_GPIO_DEBOUNCE_VAL,
1399 .debounce_en = OMAP24XX_GPIO_DEBOUNCE_EN,
1400 .ctrl = OMAP24XX_GPIO_CTRL,
1401 .wkup_en = OMAP24XX_GPIO_WAKE_EN,
1402 .leveldetect0 = OMAP24XX_GPIO_LEVELDETECT0,
1403 .leveldetect1 = OMAP24XX_GPIO_LEVELDETECT1,
1404 .risingdetect = OMAP24XX_GPIO_RISINGDETECT,
1405 .fallingdetect = OMAP24XX_GPIO_FALLINGDETECT,
1406};
1407
1408static struct omap_gpio_reg_offs omap4_gpio_regs = {
1409 .revision = OMAP4_GPIO_REVISION,
1410 .direction = OMAP4_GPIO_OE,
1411 .datain = OMAP4_GPIO_DATAIN,
1412 .dataout = OMAP4_GPIO_DATAOUT,
1413 .set_dataout = OMAP4_GPIO_SETDATAOUT,
1414 .clr_dataout = OMAP4_GPIO_CLEARDATAOUT,
1415 .irqstatus = OMAP4_GPIO_IRQSTATUS0,
1416 .irqstatus2 = OMAP4_GPIO_IRQSTATUS1,
1417 .irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1418 .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1,
1419 .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1420 .clr_irqenable = OMAP4_GPIO_IRQSTATUSCLR0,
1421 .debounce = OMAP4_GPIO_DEBOUNCINGTIME,
1422 .debounce_en = OMAP4_GPIO_DEBOUNCENABLE,
1423 .ctrl = OMAP4_GPIO_CTRL,
1424 .wkup_en = OMAP4_GPIO_IRQWAKEN0,
1425 .leveldetect0 = OMAP4_GPIO_LEVELDETECT0,
1426 .leveldetect1 = OMAP4_GPIO_LEVELDETECT1,
1427 .risingdetect = OMAP4_GPIO_RISINGDETECT,
1428 .fallingdetect = OMAP4_GPIO_FALLINGDETECT,
1429};
1430
1431static struct omap_gpio_platform_data omap2_pdata = {
1432 .regs = &omap2_gpio_regs,
1433 .bank_width = 32,
1434 .dbck_flag = false,
1435};
1436
1437static struct omap_gpio_platform_data omap3_pdata = {
1438 .regs = &omap2_gpio_regs,
1439 .bank_width = 32,
1440 .dbck_flag = true,
1441};
1442
1443static struct omap_gpio_platform_data omap4_pdata = {
1444 .regs = &omap4_gpio_regs,
1445 .bank_width = 32,
1446 .dbck_flag = true,
1447};
1448
1449static const struct of_device_id omap_gpio_match[] = {
1450 {
1451 .compatible = "ti,omap4-gpio",
1452 .data = &omap4_pdata,
1453 },
1454 {
1455 .compatible = "ti,omap3-gpio",
1456 .data = &omap3_pdata,
1457 },
1458 {
1459 .compatible = "ti,omap2-gpio",
1460 .data = &omap2_pdata,
1461 },
1462 { },
1463};
1464MODULE_DEVICE_TABLE(of, omap_gpio_match);
1465#endif
1466
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001467static struct platform_driver omap_gpio_driver = {
1468 .probe = omap_gpio_probe,
1469 .driver = {
1470 .name = "omap_gpio",
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301471 .pm = &gpio_pm_ops,
Benoit Cousson384ebe12011-08-16 11:53:02 +02001472 .of_match_table = of_match_ptr(omap_gpio_match),
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001473 },
1474};
1475
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001476/*
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001477 * gpio driver register needs to be done before
1478 * machine_init functions access gpio APIs.
1479 * Hence omap_gpio_drv_reg() is a postcore_initcall.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001480 */
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001481static int __init omap_gpio_drv_reg(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001482{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001483 return platform_driver_register(&omap_gpio_driver);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001484}
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001485postcore_initcall(omap_gpio_drv_reg);