blob: 615e9507de1516c4a3d34d0e4a8ca2180573df7b [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>
Tony Lindgren4b254082012-08-30 15:37:24 -070027#include <linux/gpio.h>
Yegor Yefremov93700842014-04-24 08:57:39 +020028#include <linux/bitops.h>
Tony Lindgren4b254082012-08-30 15:37:24 -070029#include <linux/platform_data/gpio-omap.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010030
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +053031#define OFF_MODE 1
32
Charulatha V03e128c2011-05-05 19:58:01 +053033static LIST_HEAD(omap_gpio_list);
34
Charulatha V6d62e212011-04-18 15:06:51 +000035struct gpio_regs {
36 u32 irqenable1;
37 u32 irqenable2;
38 u32 wake_en;
39 u32 ctrl;
40 u32 oe;
41 u32 leveldetect0;
42 u32 leveldetect1;
43 u32 risingdetect;
44 u32 fallingdetect;
45 u32 dataout;
Nishanth Menonae547352011-09-09 19:08:58 +053046 u32 debounce;
47 u32 debounce_en;
Charulatha V6d62e212011-04-18 15:06:51 +000048};
49
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010050struct gpio_bank {
Charulatha V03e128c2011-05-05 19:58:01 +053051 struct list_head node;
Tony Lindgren92105bb2005-09-07 17:20:26 +010052 void __iomem *base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010053 u16 irq;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -080054 u32 non_wakeup_gpios;
55 u32 enabled_non_wakeup_gpios;
Charulatha V6d62e212011-04-18 15:06:51 +000056 struct gpio_regs context;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -080057 u32 saved_datain;
Kevin Hilmanb144ff62008-01-16 21:56:15 -080058 u32 level_mask;
Cory Maccarrone4318f362010-01-08 10:29:04 -080059 u32 toggle_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010060 spinlock_t lock;
David Brownell52e31342008-03-03 12:43:23 -080061 struct gpio_chip chip;
Jouni Hogander89db9482008-12-10 17:35:24 -080062 struct clk *dbck;
Charulatha V058af1e2009-11-22 10:11:25 -080063 u32 mod_usage;
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +020064 u32 irq_usage;
Kevin Hilman8865b9b2009-01-27 11:15:34 -080065 u32 dbck_enable_mask;
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +053066 bool dbck_enabled;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -080067 struct device *dev;
Charulatha Vd0d665a2011-08-31 00:02:21 +053068 bool is_mpuio;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -080069 bool dbck_flag;
Charulatha V0cde8d02011-05-05 20:15:16 +053070 bool loses_context;
Jon Hunter352a2d52013-04-15 13:06:54 -050071 bool context_valid;
Tony Lindgren5de62b82010-12-07 16:26:58 -080072 int stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -070073 u32 width;
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +053074 int context_loss_count;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +053075 int power_mode;
76 bool workaround_enabled;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070077
Grygorii Strashko04ebcbd2015-03-23 14:18:24 +020078 void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable);
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +053079 int (*get_context_loss_count)(struct device *dev);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -070080
81 struct omap_gpio_reg_offs *regs;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010082};
83
Kevin Hilman129fd222011-04-22 07:59:07 -070084#define GPIO_INDEX(bank, gpio) (gpio % bank->width)
Charulatha Vc8eef652011-05-02 15:21:42 +053085#define GPIO_MOD_CTRL_BIT BIT(0)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010086
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +020087#define BANK_USED(bank) (bank->mod_usage || bank->irq_usage)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +020088#define LINE_USED(line, offset) (line & (BIT(offset)))
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +020089
Tony Lindgren3d009c82015-01-16 14:50:50 -080090static void omap_gpio_unmask_irq(struct irq_data *d);
91
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +020092static inline struct gpio_bank *omap_irq_data_get_bank(struct irq_data *d)
Jon Hunterede4d7a2013-03-01 11:22:47 -060093{
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +020094 struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
95 return container_of(chip, struct gpio_bank, chip);
Benoit Cousson25db7112012-02-23 21:50:10 +010096}
97
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +020098static void omap_set_gpio_direction(struct gpio_bank *bank, int gpio,
99 int is_input)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100100{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100101 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100102 u32 l;
103
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700104 reg += bank->regs->direction;
Victor Kamensky661553b2013-11-16 02:01:04 +0200105 l = readl_relaxed(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100106 if (is_input)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200107 l |= BIT(gpio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100108 else
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200109 l &= ~(BIT(gpio));
Victor Kamensky661553b2013-11-16 02:01:04 +0200110 writel_relaxed(l, reg);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530111 bank->context.oe = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100112}
113
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700114
115/* set data out value using dedicate set/clear register */
Grygorii Strashko04ebcbd2015-03-23 14:18:24 +0200116static void omap_set_gpio_dataout_reg(struct gpio_bank *bank, unsigned offset,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200117 int enable)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100118{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100119 void __iomem *reg = bank->base;
Grygorii Strashko04ebcbd2015-03-23 14:18:24 +0200120 u32 l = BIT(offset);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100121
Tarun Kanti DebBarma2c836f72012-03-02 12:52:52 +0530122 if (enable) {
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700123 reg += bank->regs->set_dataout;
Tarun Kanti DebBarma2c836f72012-03-02 12:52:52 +0530124 bank->context.dataout |= l;
125 } else {
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700126 reg += bank->regs->clr_dataout;
Tarun Kanti DebBarma2c836f72012-03-02 12:52:52 +0530127 bank->context.dataout &= ~l;
128 }
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700129
Victor Kamensky661553b2013-11-16 02:01:04 +0200130 writel_relaxed(l, reg);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700131}
132
133/* set data out value using mask register */
Grygorii Strashko04ebcbd2015-03-23 14:18:24 +0200134static void omap_set_gpio_dataout_mask(struct gpio_bank *bank, unsigned offset,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200135 int enable)
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700136{
137 void __iomem *reg = bank->base + bank->regs->dataout;
Grygorii Strashko04ebcbd2015-03-23 14:18:24 +0200138 u32 gpio_bit = BIT(offset);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700139 u32 l;
140
Victor Kamensky661553b2013-11-16 02:01:04 +0200141 l = readl_relaxed(reg);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700142 if (enable)
143 l |= gpio_bit;
144 else
145 l &= ~gpio_bit;
Victor Kamensky661553b2013-11-16 02:01:04 +0200146 writel_relaxed(l, reg);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530147 bank->context.dataout = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100148}
149
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200150static int omap_get_gpio_datain(struct gpio_bank *bank, int offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100151{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700152 void __iomem *reg = bank->base + bank->regs->datain;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100153
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200154 return (readl_relaxed(reg) & (BIT(offset))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100155}
156
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200157static int omap_get_gpio_dataout(struct gpio_bank *bank, int offset)
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300158{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700159 void __iomem *reg = bank->base + bank->regs->dataout;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300160
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200161 return (readl_relaxed(reg) & (BIT(offset))) != 0;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300162}
163
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200164static inline void omap_gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
Kevin Hilmanece95282011-07-12 08:18:15 -0700165{
Victor Kamensky661553b2013-11-16 02:01:04 +0200166 int l = readl_relaxed(base + reg);
Kevin Hilmanece95282011-07-12 08:18:15 -0700167
Benoit Cousson862ff642012-02-01 15:58:56 +0100168 if (set)
Kevin Hilmanece95282011-07-12 08:18:15 -0700169 l |= mask;
170 else
171 l &= ~mask;
172
Victor Kamensky661553b2013-11-16 02:01:04 +0200173 writel_relaxed(l, base + reg);
Kevin Hilmanece95282011-07-12 08:18:15 -0700174}
Tony Lindgren92105bb2005-09-07 17:20:26 +0100175
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200176static inline void omap_gpio_dbck_enable(struct gpio_bank *bank)
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530177{
178 if (bank->dbck_enable_mask && !bank->dbck_enabled) {
Rajendra Nayak345477f2014-04-23 11:41:03 +0530179 clk_prepare_enable(bank->dbck);
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530180 bank->dbck_enabled = true;
Grazvydas Ignotas9e303f22012-06-16 22:01:25 +0300181
Victor Kamensky661553b2013-11-16 02:01:04 +0200182 writel_relaxed(bank->dbck_enable_mask,
Grazvydas Ignotas9e303f22012-06-16 22:01:25 +0300183 bank->base + bank->regs->debounce_en);
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530184 }
185}
186
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200187static inline void omap_gpio_dbck_disable(struct gpio_bank *bank)
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530188{
189 if (bank->dbck_enable_mask && bank->dbck_enabled) {
Grazvydas Ignotas9e303f22012-06-16 22:01:25 +0300190 /*
191 * Disable debounce before cutting it's clock. If debounce is
192 * enabled but the clock is not, GPIO module seems to be unable
193 * to detect events and generate interrupts at least on OMAP3.
194 */
Victor Kamensky661553b2013-11-16 02:01:04 +0200195 writel_relaxed(0, bank->base + bank->regs->debounce_en);
Grazvydas Ignotas9e303f22012-06-16 22:01:25 +0300196
Rajendra Nayak345477f2014-04-23 11:41:03 +0530197 clk_disable_unprepare(bank->dbck);
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530198 bank->dbck_enabled = false;
199 }
200}
201
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700202/**
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200203 * omap2_set_gpio_debounce - low level gpio debounce time
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700204 * @bank: the gpio bank we're acting upon
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200205 * @offset: the gpio number on this @bank
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700206 * @debounce: debounce time to use
207 *
208 * OMAP's debounce time is in 31us steps so we need
209 * to convert and round up to the closest unit.
210 */
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200211static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200212 unsigned debounce)
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700213{
Kevin Hilman9942da02011-04-22 12:02:05 -0700214 void __iomem *reg;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700215 u32 val;
216 u32 l;
217
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800218 if (!bank->dbck_flag)
219 return;
220
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700221 if (debounce < 32)
222 debounce = 0x01;
223 else if (debounce > 7936)
224 debounce = 0xff;
225 else
226 debounce = (debounce / 0x1f) - 1;
227
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200228 l = BIT(offset);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700229
Rajendra Nayak345477f2014-04-23 11:41:03 +0530230 clk_prepare_enable(bank->dbck);
Kevin Hilman9942da02011-04-22 12:02:05 -0700231 reg = bank->base + bank->regs->debounce;
Victor Kamensky661553b2013-11-16 02:01:04 +0200232 writel_relaxed(debounce, reg);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700233
Kevin Hilman9942da02011-04-22 12:02:05 -0700234 reg = bank->base + bank->regs->debounce_en;
Victor Kamensky661553b2013-11-16 02:01:04 +0200235 val = readl_relaxed(reg);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700236
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530237 if (debounce)
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700238 val |= l;
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530239 else
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700240 val &= ~l;
Kevin Hilmanf7ec0b02010-06-09 13:53:07 +0300241 bank->dbck_enable_mask = val;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700242
Victor Kamensky661553b2013-11-16 02:01:04 +0200243 writel_relaxed(val, reg);
Rajendra Nayak345477f2014-04-23 11:41:03 +0530244 clk_disable_unprepare(bank->dbck);
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530245 /*
246 * Enable debounce clock per module.
247 * This call is mandatory because in omap_gpio_request() when
248 * *_runtime_get_sync() is called, _gpio_dbck_enable() within
249 * runtime callbck fails to turn on dbck because dbck_enable_mask
250 * used within _gpio_dbck_enable() is still not initialized at
251 * that point. Therefore we have to enable dbck here.
252 */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200253 omap_gpio_dbck_enable(bank);
Nishanth Menonae547352011-09-09 19:08:58 +0530254 if (bank->dbck_enable_mask) {
255 bank->context.debounce = debounce;
256 bank->context.debounce_en = val;
257 }
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700258}
259
Jon Hunterc9c55d92012-10-26 14:26:04 -0500260/**
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200261 * omap_clear_gpio_debounce - clear debounce settings for a gpio
Jon Hunterc9c55d92012-10-26 14:26:04 -0500262 * @bank: the gpio bank we're acting upon
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200263 * @offset: the gpio number on this @bank
Jon Hunterc9c55d92012-10-26 14:26:04 -0500264 *
265 * If a gpio is using debounce, then clear the debounce enable bit and if
266 * this is the only gpio in this bank using debounce, then clear the debounce
267 * time too. The debounce clock will also be disabled when calling this function
268 * if this is the only gpio in the bank using debounce.
269 */
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200270static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset)
Jon Hunterc9c55d92012-10-26 14:26:04 -0500271{
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200272 u32 gpio_bit = BIT(offset);
Jon Hunterc9c55d92012-10-26 14:26:04 -0500273
274 if (!bank->dbck_flag)
275 return;
276
277 if (!(bank->dbck_enable_mask & gpio_bit))
278 return;
279
280 bank->dbck_enable_mask &= ~gpio_bit;
281 bank->context.debounce_en &= ~gpio_bit;
Victor Kamensky661553b2013-11-16 02:01:04 +0200282 writel_relaxed(bank->context.debounce_en,
Jon Hunterc9c55d92012-10-26 14:26:04 -0500283 bank->base + bank->regs->debounce_en);
284
285 if (!bank->dbck_enable_mask) {
286 bank->context.debounce = 0;
Victor Kamensky661553b2013-11-16 02:01:04 +0200287 writel_relaxed(bank->context.debounce, bank->base +
Jon Hunterc9c55d92012-10-26 14:26:04 -0500288 bank->regs->debounce);
Rajendra Nayak345477f2014-04-23 11:41:03 +0530289 clk_disable_unprepare(bank->dbck);
Jon Hunterc9c55d92012-10-26 14:26:04 -0500290 bank->dbck_enabled = false;
291 }
292}
293
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200294static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
Tarun Kanti DebBarma00ece7e2011-11-25 15:41:06 +0530295 unsigned trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100296{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800297 void __iomem *base = bank->base;
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200298 u32 gpio_bit = BIT(gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100299
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200300 omap_gpio_rmw(base, bank->regs->leveldetect0, gpio_bit,
301 trigger & IRQ_TYPE_LEVEL_LOW);
302 omap_gpio_rmw(base, bank->regs->leveldetect1, gpio_bit,
303 trigger & IRQ_TYPE_LEVEL_HIGH);
304 omap_gpio_rmw(base, bank->regs->risingdetect, gpio_bit,
305 trigger & IRQ_TYPE_EDGE_RISING);
306 omap_gpio_rmw(base, bank->regs->fallingdetect, gpio_bit,
307 trigger & IRQ_TYPE_EDGE_FALLING);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530308
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530309 bank->context.leveldetect0 =
Victor Kamensky661553b2013-11-16 02:01:04 +0200310 readl_relaxed(bank->base + bank->regs->leveldetect0);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530311 bank->context.leveldetect1 =
Victor Kamensky661553b2013-11-16 02:01:04 +0200312 readl_relaxed(bank->base + bank->regs->leveldetect1);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530313 bank->context.risingdetect =
Victor Kamensky661553b2013-11-16 02:01:04 +0200314 readl_relaxed(bank->base + bank->regs->risingdetect);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530315 bank->context.fallingdetect =
Victor Kamensky661553b2013-11-16 02:01:04 +0200316 readl_relaxed(bank->base + bank->regs->fallingdetect);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530317
318 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200319 omap_gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530320 bank->context.wake_en =
Victor Kamensky661553b2013-11-16 02:01:04 +0200321 readl_relaxed(bank->base + bank->regs->wkup_en);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530322 }
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530323
Ambresh K55b220c2011-06-15 13:40:45 -0700324 /* This part needs to be executed always for OMAP{34xx, 44xx} */
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530325 if (!bank->regs->irqctrl) {
326 /* On omap24xx proceed only when valid GPIO bit is set */
327 if (bank->non_wakeup_gpios) {
328 if (!(bank->non_wakeup_gpios & gpio_bit))
329 goto exit;
330 }
331
Chunqiu Wang699117a62009-06-24 17:13:39 +0000332 /*
333 * Log the edge gpio and manually trigger the IRQ
334 * after resume if the input level changes
335 * to avoid irq lost during PER RET/OFF mode
336 * Applies for omap2 non-wakeup gpio and all omap3 gpios
337 */
338 if (trigger & IRQ_TYPE_EDGE_BOTH)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800339 bank->enabled_non_wakeup_gpios |= gpio_bit;
340 else
341 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
342 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700343
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530344exit:
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530345 bank->level_mask =
Victor Kamensky661553b2013-11-16 02:01:04 +0200346 readl_relaxed(bank->base + bank->regs->leveldetect0) |
347 readl_relaxed(bank->base + bank->regs->leveldetect1);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100348}
349
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800350#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800351/*
352 * This only applies to chips that can't do both rising and falling edge
353 * detection at once. For all other chips, this function is a noop.
354 */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200355static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800356{
357 void __iomem *reg = bank->base;
358 u32 l = 0;
359
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530360 if (!bank->regs->irqctrl)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800361 return;
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530362
363 reg += bank->regs->irqctrl;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800364
Victor Kamensky661553b2013-11-16 02:01:04 +0200365 l = readl_relaxed(reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800366 if ((l >> gpio) & 1)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200367 l &= ~(BIT(gpio));
Cory Maccarrone4318f362010-01-08 10:29:04 -0800368 else
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200369 l |= BIT(gpio);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800370
Victor Kamensky661553b2013-11-16 02:01:04 +0200371 writel_relaxed(l, reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800372}
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530373#else
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200374static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800375#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800376
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200377static int omap_set_gpio_triggering(struct gpio_bank *bank, int gpio,
378 unsigned trigger)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100379{
380 void __iomem *reg = bank->base;
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530381 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100382 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100383
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530384 if (bank->regs->leveldetect0 && bank->regs->wkup_en) {
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200385 omap_set_gpio_trigger(bank, gpio, trigger);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530386 } else if (bank->regs->irqctrl) {
387 reg += bank->regs->irqctrl;
388
Victor Kamensky661553b2013-11-16 02:01:04 +0200389 l = readl_relaxed(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000390 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200391 bank->toggle_mask |= BIT(gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100392 if (trigger & IRQ_TYPE_EDGE_RISING)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200393 l |= BIT(gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100394 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200395 l &= ~(BIT(gpio));
Tony Lindgren92105bb2005-09-07 17:20:26 +0100396 else
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530397 return -EINVAL;
398
Victor Kamensky661553b2013-11-16 02:01:04 +0200399 writel_relaxed(l, reg);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530400 } else if (bank->regs->edgectrl1) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100401 if (gpio & 0x08)
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530402 reg += bank->regs->edgectrl2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100403 else
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530404 reg += bank->regs->edgectrl1;
405
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100406 gpio &= 0x07;
Victor Kamensky661553b2013-11-16 02:01:04 +0200407 l = readl_relaxed(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100408 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100409 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100410 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100411 if (trigger & IRQ_TYPE_EDGE_FALLING)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200412 l |= BIT(gpio << 1);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530413
414 /* Enable wake-up during idle for dynamic tick */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200415 omap_gpio_rmw(base, bank->regs->wkup_en, BIT(gpio), trigger);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530416 bank->context.wake_en =
Victor Kamensky661553b2013-11-16 02:01:04 +0200417 readl_relaxed(bank->base + bank->regs->wkup_en);
418 writel_relaxed(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100419 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100420 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100421}
422
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200423static void omap_enable_gpio_module(struct gpio_bank *bank, unsigned offset)
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200424{
425 if (bank->regs->pinctrl) {
426 void __iomem *reg = bank->base + bank->regs->pinctrl;
427
428 /* Claim the pin for MPU */
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200429 writel_relaxed(readl_relaxed(reg) | (BIT(offset)), reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200430 }
431
432 if (bank->regs->ctrl && !BANK_USED(bank)) {
433 void __iomem *reg = bank->base + bank->regs->ctrl;
434 u32 ctrl;
435
Victor Kamensky661553b2013-11-16 02:01:04 +0200436 ctrl = readl_relaxed(reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200437 /* Module is enabled, clocks are not gated */
438 ctrl &= ~GPIO_MOD_CTRL_BIT;
Victor Kamensky661553b2013-11-16 02:01:04 +0200439 writel_relaxed(ctrl, reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200440 bank->context.ctrl = ctrl;
441 }
442}
443
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200444static void omap_disable_gpio_module(struct gpio_bank *bank, unsigned offset)
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200445{
446 void __iomem *base = bank->base;
447
448 if (bank->regs->wkup_en &&
449 !LINE_USED(bank->mod_usage, offset) &&
450 !LINE_USED(bank->irq_usage, offset)) {
451 /* Disable wake-up during idle for dynamic tick */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200452 omap_gpio_rmw(base, bank->regs->wkup_en, BIT(offset), 0);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200453 bank->context.wake_en =
Victor Kamensky661553b2013-11-16 02:01:04 +0200454 readl_relaxed(bank->base + bank->regs->wkup_en);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200455 }
456
457 if (bank->regs->ctrl && !BANK_USED(bank)) {
458 void __iomem *reg = bank->base + bank->regs->ctrl;
459 u32 ctrl;
460
Victor Kamensky661553b2013-11-16 02:01:04 +0200461 ctrl = readl_relaxed(reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200462 /* Module is disabled, clocks are gated */
463 ctrl |= GPIO_MOD_CTRL_BIT;
Victor Kamensky661553b2013-11-16 02:01:04 +0200464 writel_relaxed(ctrl, reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200465 bank->context.ctrl = ctrl;
466 }
467}
468
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200469static int omap_gpio_is_input(struct gpio_bank *bank, unsigned offset)
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200470{
471 void __iomem *reg = bank->base + bank->regs->direction;
472
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200473 return readl_relaxed(reg) & BIT(offset);
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200474}
475
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200476static void omap_gpio_init_irq(struct gpio_bank *bank, unsigned offset)
Tony Lindgren3d009c82015-01-16 14:50:50 -0800477{
478 if (!LINE_USED(bank->mod_usage, offset)) {
479 omap_enable_gpio_module(bank, offset);
480 omap_set_gpio_direction(bank, offset, 1);
481 }
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200482 bank->irq_usage |= BIT(offset);
Tony Lindgren3d009c82015-01-16 14:50:50 -0800483}
484
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200485static int omap_gpio_irq_type(struct irq_data *d, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100486{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200487 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100488 int retval;
David Brownella6472532008-03-03 04:33:30 -0800489 unsigned long flags;
Grygorii Strashkoea5fbe82015-03-23 14:18:29 +0200490 unsigned offset = d->hwirq;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100491
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200492 if (!BANK_USED(bank))
493 pm_runtime_get_sync(bank->dev);
Jon Hunter8d4c2772013-03-01 11:22:48 -0600494
Tony Lindgren4b254082012-08-30 15:37:24 -0700495#ifdef CONFIG_ARCH_OMAP1
Grygorii Strashkoea5fbe82015-03-23 14:18:29 +0200496 if (d->irq > IH_MPUIO_BASE) {
497 unsigned gpio = 0;
Lennert Buytenheke9191022010-11-29 11:17:17 +0100498 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
Grygorii Strashkoea5fbe82015-03-23 14:18:29 +0200499 offset = GPIO_INDEX(bank, gpio);
500 }
Tony Lindgren4b254082012-08-30 15:37:24 -0700501#endif
502
David Brownelle5c56ed2006-12-06 17:13:59 -0800503 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100504 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800505
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530506 if (!bank->regs->leveldetect0 &&
507 (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100508 return -EINVAL;
509
David Brownella6472532008-03-03 04:33:30 -0800510 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200511 retval = omap_set_gpio_triggering(bank, offset, type);
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200512 omap_gpio_init_irq(bank, offset);
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200513 if (!omap_gpio_is_input(bank, offset)) {
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200514 spin_unlock_irqrestore(&bank->lock, flags);
515 return -EINVAL;
516 }
David Brownella6472532008-03-03 04:33:30 -0800517 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800518
519 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100520 __irq_set_handler_locked(d->irq, handle_level_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800521 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100522 __irq_set_handler_locked(d->irq, handle_edge_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800523
Tony Lindgren92105bb2005-09-07 17:20:26 +0100524 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100525}
526
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200527static void omap_clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100528{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100529 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100530
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700531 reg += bank->regs->irqstatus;
Victor Kamensky661553b2013-11-16 02:01:04 +0200532 writel_relaxed(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300533
534 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700535 if (bank->regs->irqstatus2) {
536 reg = bank->base + bank->regs->irqstatus2;
Victor Kamensky661553b2013-11-16 02:01:04 +0200537 writel_relaxed(gpio_mask, reg);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700538 }
Roger Quadrosbedfd152009-04-23 11:10:50 -0700539
540 /* Flush posted write for the irq status to avoid spurious interrupts */
Victor Kamensky661553b2013-11-16 02:01:04 +0200541 readl_relaxed(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100542}
543
Grygorii Strashko9943f262015-03-23 14:18:27 +0200544static inline void omap_clear_gpio_irqstatus(struct gpio_bank *bank,
545 unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100546{
Grygorii Strashko9943f262015-03-23 14:18:27 +0200547 omap_clear_gpio_irqbank(bank, BIT(offset));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100548}
549
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200550static u32 omap_get_gpio_irqbank_mask(struct gpio_bank *bank)
Imre Deakea6dedd2006-06-26 16:16:00 -0700551{
552 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700553 u32 l;
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200554 u32 mask = (BIT(bank->width)) - 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700555
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700556 reg += bank->regs->irqenable;
Victor Kamensky661553b2013-11-16 02:01:04 +0200557 l = readl_relaxed(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700558 if (bank->regs->irqenable_inv)
Imre Deak99c47702006-06-26 16:16:07 -0700559 l = ~l;
560 l &= mask;
561 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700562}
563
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200564static void omap_enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100565{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100566 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100567 u32 l;
568
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700569 if (bank->regs->set_irqenable) {
570 reg += bank->regs->set_irqenable;
571 l = gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530572 bank->context.irqenable1 |= gpio_mask;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700573 } else {
574 reg += bank->regs->irqenable;
Victor Kamensky661553b2013-11-16 02:01:04 +0200575 l = readl_relaxed(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700576 if (bank->regs->irqenable_inv)
577 l &= ~gpio_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100578 else
579 l |= gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530580 bank->context.irqenable1 = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100581 }
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700582
Victor Kamensky661553b2013-11-16 02:01:04 +0200583 writel_relaxed(l, reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700584}
585
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200586static void omap_disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700587{
588 void __iomem *reg = bank->base;
589 u32 l;
590
591 if (bank->regs->clr_irqenable) {
592 reg += bank->regs->clr_irqenable;
593 l = gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530594 bank->context.irqenable1 &= ~gpio_mask;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700595 } else {
596 reg += bank->regs->irqenable;
Victor Kamensky661553b2013-11-16 02:01:04 +0200597 l = readl_relaxed(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700598 if (bank->regs->irqenable_inv)
599 l |= gpio_mask;
600 else
601 l &= ~gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530602 bank->context.irqenable1 = l;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700603 }
604
Victor Kamensky661553b2013-11-16 02:01:04 +0200605 writel_relaxed(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100606}
607
Grygorii Strashko9943f262015-03-23 14:18:27 +0200608static inline void omap_set_gpio_irqenable(struct gpio_bank *bank,
609 unsigned offset, int enable)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100610{
Tarun Kanti DebBarma8276536c2011-11-25 15:27:37 +0530611 if (enable)
Grygorii Strashko9943f262015-03-23 14:18:27 +0200612 omap_enable_gpio_irqbank(bank, BIT(offset));
Tarun Kanti DebBarma8276536c2011-11-25 15:27:37 +0530613 else
Grygorii Strashko9943f262015-03-23 14:18:27 +0200614 omap_disable_gpio_irqbank(bank, BIT(offset));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100615}
616
Tony Lindgren92105bb2005-09-07 17:20:26 +0100617/*
618 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
619 * 1510 does not seem to have a wake-up register. If JTAG is connected
620 * to the target, system will wake up always on GPIO events. While
621 * system is running all registered GPIO interrupts need to have wake-up
622 * enabled. When system is suspended, only selected GPIO interrupts need
623 * to have wake-up enabled.
624 */
Grygorii Strashko9943f262015-03-23 14:18:27 +0200625static int omap_set_gpio_wakeup(struct gpio_bank *bank, unsigned offset,
626 int enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100627{
Grygorii Strashko9943f262015-03-23 14:18:27 +0200628 u32 gpio_bit = BIT(offset);
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700629 unsigned long flags;
David Brownella6472532008-03-03 04:33:30 -0800630
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700631 if (bank->non_wakeup_gpios & gpio_bit) {
Benoit Cousson862ff642012-02-01 15:58:56 +0100632 dev_err(bank->dev,
Grygorii Strashko9943f262015-03-23 14:18:27 +0200633 "Unable to modify wakeup on non-wakeup GPIO%d\n",
634 offset);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100635 return -EINVAL;
636 }
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700637
638 spin_lock_irqsave(&bank->lock, flags);
639 if (enable)
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530640 bank->context.wake_en |= gpio_bit;
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700641 else
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530642 bank->context.wake_en &= ~gpio_bit;
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700643
Victor Kamensky661553b2013-11-16 02:01:04 +0200644 writel_relaxed(bank->context.wake_en, bank->base + bank->regs->wkup_en);
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700645 spin_unlock_irqrestore(&bank->lock, flags);
646
647 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100648}
649
Grygorii Strashko9943f262015-03-23 14:18:27 +0200650static void omap_reset_gpio(struct gpio_bank *bank, unsigned offset)
Tony Lindgren4196dd62006-09-25 12:41:38 +0300651{
Grygorii Strashko9943f262015-03-23 14:18:27 +0200652 omap_set_gpio_direction(bank, offset, 1);
653 omap_set_gpio_irqenable(bank, offset, 0);
654 omap_clear_gpio_irqstatus(bank, offset);
655 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
656 omap_clear_gpio_debounce(bank, offset);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300657}
658
Tony Lindgren92105bb2005-09-07 17:20:26 +0100659/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200660static int omap_gpio_wake_enable(struct irq_data *d, unsigned int enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100661{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200662 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200663 unsigned offset = d->hwirq;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100664
Grygorii Strashko9943f262015-03-23 14:18:27 +0200665 return omap_set_gpio_wakeup(bank, offset, enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100666}
667
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800668static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100669{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800670 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800671 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100672
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530673 /*
674 * If this is the first gpio_request for the bank,
675 * enable the bank module.
676 */
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200677 if (!BANK_USED(bank))
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530678 pm_runtime_get_sync(bank->dev);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100679
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530680 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300681 /* Set trigger to none. You need to enable the desired trigger with
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200682 * request_irq() or set_irq_type(). Only do this if the IRQ line has
683 * not already been requested.
Tony Lindgren4196dd62006-09-25 12:41:38 +0300684 */
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200685 if (!LINE_USED(bank->irq_usage, offset)) {
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200686 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
687 omap_enable_gpio_module(bank, offset);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100688 }
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200689 bank->mod_usage |= BIT(offset);
David Brownella6472532008-03-03 04:33:30 -0800690 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100691
692 return 0;
693}
694
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800695static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100696{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800697 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800698 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100699
David Brownella6472532008-03-03 04:33:30 -0800700 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200701 bank->mod_usage &= ~(BIT(offset));
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200702 omap_disable_gpio_module(bank, offset);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200703 omap_reset_gpio(bank, offset);
David Brownella6472532008-03-03 04:33:30 -0800704 spin_unlock_irqrestore(&bank->lock, flags);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530705
706 /*
707 * If this is the last gpio to be freed in the bank,
708 * disable the bank module.
709 */
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200710 if (!BANK_USED(bank))
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530711 pm_runtime_put(bank->dev);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100712}
713
714/*
715 * We need to unmask the GPIO bank interrupt as soon as possible to
716 * avoid missing GPIO interrupts for other lines in the bank.
717 * Then we need to mask-read-clear-unmask the triggered GPIO lines
718 * in the bank to avoid missing nested interrupts for a GPIO line.
719 * If we wait to unmask individual GPIO lines in the bank after the
720 * line's interrupt handler has been run, we may miss some nested
721 * interrupts.
722 */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200723static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100724{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100725 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100726 u32 isr;
Jon Hunter3513cde2013-04-04 15:16:14 -0500727 unsigned int bit;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100728 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -0700729 int unmasked = 0;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200730 struct irq_chip *irqchip = irq_desc_get_chip(desc);
731 struct gpio_chip *chip = irq_get_handler_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100732
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200733 chained_irq_enter(irqchip, desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100734
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200735 bank = container_of(chip, struct gpio_bank, chip);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700736 isr_reg = bank->base + bank->regs->irqstatus;
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530737 pm_runtime_get_sync(bank->dev);
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800738
739 if (WARN_ON(!isr_reg))
740 goto exit;
741
Laurent Navete83507b2013-03-20 13:15:57 +0100742 while (1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +0100743 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -0700744 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100745
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200746 enabled = omap_get_gpio_irqbank_mask(bank);
Victor Kamensky661553b2013-11-16 02:01:04 +0200747 isr_saved = isr = readl_relaxed(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100748
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530749 if (bank->level_mask)
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800750 level_mask = bank->level_mask & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100751
752 /* clear edge sensitive interrupts before handler(s) are
753 called so that we don't miss any interrupt occurred while
754 executing them */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200755 omap_disable_gpio_irqbank(bank, isr_saved & ~level_mask);
756 omap_clear_gpio_irqbank(bank, isr_saved & ~level_mask);
757 omap_enable_gpio_irqbank(bank, isr_saved & ~level_mask);
Tony Lindgren6e60e792006-04-02 17:46:23 +0100758
759 /* if there is only edge sensitive GPIO pin interrupts
760 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -0700761 if (!level_mask && !unmasked) {
762 unmasked = 1;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200763 chained_irq_exit(irqchip, desc);
Imre Deakea6dedd2006-06-26 16:16:00 -0700764 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100765
Tony Lindgren92105bb2005-09-07 17:20:26 +0100766 if (!isr)
767 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100768
Jon Hunter3513cde2013-04-04 15:16:14 -0500769 while (isr) {
770 bit = __ffs(isr);
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200771 isr &= ~(BIT(bit));
Benoit Cousson25db7112012-02-23 21:50:10 +0100772
Cory Maccarrone4318f362010-01-08 10:29:04 -0800773 /*
774 * Some chips can't respond to both rising and falling
775 * at the same time. If this irq was requested with
776 * both flags, we need to flip the ICR data for the IRQ
777 * to respond to the IRQ for the opposite direction.
778 * This will be indicated in the bank toggle_mask.
779 */
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200780 if (bank->toggle_mask & (BIT(bit)))
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200781 omap_toggle_gpio_edge_triggering(bank, bit);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800782
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200783 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain,
784 bit));
Tony Lindgren92105bb2005-09-07 17:20:26 +0100785 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000786 }
Imre Deakea6dedd2006-06-26 16:16:00 -0700787 /* if bank has any level sensitive GPIO pin interrupt
788 configured, we must unmask the bank interrupt only after
789 handler(s) are executed in order to avoid spurious bank
790 interrupt */
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800791exit:
Imre Deakea6dedd2006-06-26 16:16:00 -0700792 if (!unmasked)
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200793 chained_irq_exit(irqchip, desc);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530794 pm_runtime_put(bank->dev);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100795}
796
Tony Lindgren3d009c82015-01-16 14:50:50 -0800797static unsigned int omap_gpio_irq_startup(struct irq_data *d)
798{
799 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Tony Lindgren3d009c82015-01-16 14:50:50 -0800800 unsigned long flags;
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200801 unsigned offset = d->hwirq;
Tony Lindgren3d009c82015-01-16 14:50:50 -0800802
803 if (!BANK_USED(bank))
804 pm_runtime_get_sync(bank->dev);
805
806 spin_lock_irqsave(&bank->lock, flags);
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200807 omap_gpio_init_irq(bank, offset);
Tony Lindgren3d009c82015-01-16 14:50:50 -0800808 spin_unlock_irqrestore(&bank->lock, flags);
809 omap_gpio_unmask_irq(d);
810
811 return 0;
812}
813
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200814static void omap_gpio_irq_shutdown(struct irq_data *d)
Tony Lindgren4196dd62006-09-25 12:41:38 +0300815{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200816 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700817 unsigned long flags;
Grygorii Strashko9943f262015-03-23 14:18:27 +0200818 unsigned offset = d->hwirq;
Tony Lindgren4196dd62006-09-25 12:41:38 +0300819
Colin Cross85ec7b92011-06-06 13:38:18 -0700820 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200821 bank->irq_usage &= ~(BIT(offset));
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200822 omap_disable_gpio_module(bank, offset);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200823 omap_reset_gpio(bank, offset);
Colin Cross85ec7b92011-06-06 13:38:18 -0700824 spin_unlock_irqrestore(&bank->lock, flags);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200825
826 /*
827 * If this is the last IRQ to be freed in the bank,
828 * disable the bank module.
829 */
830 if (!BANK_USED(bank))
831 pm_runtime_put(bank->dev);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300832}
833
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200834static void omap_gpio_ack_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100835{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200836 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200837 unsigned offset = d->hwirq;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100838
Grygorii Strashko9943f262015-03-23 14:18:27 +0200839 omap_clear_gpio_irqstatus(bank, offset);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100840}
841
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200842static void omap_gpio_mask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100843{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200844 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200845 unsigned offset = d->hwirq;
Colin Cross85ec7b92011-06-06 13:38:18 -0700846 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100847
Colin Cross85ec7b92011-06-06 13:38:18 -0700848 spin_lock_irqsave(&bank->lock, flags);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200849 omap_set_gpio_irqenable(bank, offset, 0);
850 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Colin Cross85ec7b92011-06-06 13:38:18 -0700851 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100852}
853
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200854static void omap_gpio_unmask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100855{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200856 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200857 unsigned offset = d->hwirq;
Thomas Gleixner8c04a172011-03-24 12:40:15 +0100858 u32 trigger = irqd_get_trigger_type(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700859 unsigned long flags;
Kevin Hilman55b60192009-06-04 15:57:10 -0700860
Colin Cross85ec7b92011-06-06 13:38:18 -0700861 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman55b60192009-06-04 15:57:10 -0700862 if (trigger)
Grygorii Strashko9943f262015-03-23 14:18:27 +0200863 omap_set_gpio_triggering(bank, offset, trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800864
865 /* For level-triggered GPIOs, the clearing must be done after
866 * the HW source is cleared, thus after the handler has run */
Grygorii Strashko9943f262015-03-23 14:18:27 +0200867 if (bank->level_mask & BIT(offset)) {
868 omap_set_gpio_irqenable(bank, offset, 0);
869 omap_clear_gpio_irqstatus(bank, offset);
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800870 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100871
Grygorii Strashko9943f262015-03-23 14:18:27 +0200872 omap_set_gpio_irqenable(bank, offset, 1);
Colin Cross85ec7b92011-06-06 13:38:18 -0700873 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100874}
875
David Brownelle5c56ed2006-12-06 17:13:59 -0800876/*---------------------------------------------------------------------*/
877
Magnus Damm79ee0312009-07-08 13:22:04 +0200878static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800879{
Magnus Damm79ee0312009-07-08 13:22:04 +0200880 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800881 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800882 void __iomem *mask_reg = bank->base +
883 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800884 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800885
David Brownella6472532008-03-03 04:33:30 -0800886 spin_lock_irqsave(&bank->lock, flags);
Victor Kamensky661553b2013-11-16 02:01:04 +0200887 writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800888 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800889
890 return 0;
891}
892
Magnus Damm79ee0312009-07-08 13:22:04 +0200893static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800894{
Magnus Damm79ee0312009-07-08 13:22:04 +0200895 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800896 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800897 void __iomem *mask_reg = bank->base +
898 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800899 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800900
David Brownella6472532008-03-03 04:33:30 -0800901 spin_lock_irqsave(&bank->lock, flags);
Victor Kamensky661553b2013-11-16 02:01:04 +0200902 writel_relaxed(bank->context.wake_en, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800903 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800904
905 return 0;
906}
907
Alexey Dobriyan47145212009-12-14 18:00:08 -0800908static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +0200909 .suspend_noirq = omap_mpuio_suspend_noirq,
910 .resume_noirq = omap_mpuio_resume_noirq,
911};
912
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +0200913/* use platform_driver for this. */
David Brownell11a78b72006-12-06 17:14:11 -0800914static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -0800915 .driver = {
916 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +0200917 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -0800918 },
919};
920
921static struct platform_device omap_mpuio_device = {
922 .name = "mpuio",
923 .id = -1,
924 .dev = {
925 .driver = &omap_mpuio_driver.driver,
926 }
927 /* could list the /proc/iomem resources */
928};
929
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200930static inline void omap_mpuio_init(struct gpio_bank *bank)
David Brownell11a78b72006-12-06 17:14:11 -0800931{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800932 platform_set_drvdata(&omap_mpuio_device, bank);
David Brownellfcf126d2007-04-02 12:46:47 -0700933
David Brownell11a78b72006-12-06 17:14:11 -0800934 if (platform_driver_register(&omap_mpuio_driver) == 0)
935 (void) platform_device_register(&omap_mpuio_device);
936}
937
David Brownelle5c56ed2006-12-06 17:13:59 -0800938/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100939
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200940static int omap_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
Yegor Yefremov93700842014-04-24 08:57:39 +0200941{
942 struct gpio_bank *bank;
943 unsigned long flags;
944 void __iomem *reg;
945 int dir;
946
947 bank = container_of(chip, struct gpio_bank, chip);
948 reg = bank->base + bank->regs->direction;
949 spin_lock_irqsave(&bank->lock, flags);
950 dir = !!(readl_relaxed(reg) & BIT(offset));
951 spin_unlock_irqrestore(&bank->lock, flags);
952 return dir;
953}
954
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200955static int omap_gpio_input(struct gpio_chip *chip, unsigned offset)
David Brownell52e31342008-03-03 12:43:23 -0800956{
957 struct gpio_bank *bank;
958 unsigned long flags;
959
960 bank = container_of(chip, struct gpio_bank, chip);
961 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200962 omap_set_gpio_direction(bank, offset, 1);
David Brownell52e31342008-03-03 12:43:23 -0800963 spin_unlock_irqrestore(&bank->lock, flags);
964 return 0;
965}
966
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200967static int omap_gpio_get(struct gpio_chip *chip, unsigned offset)
David Brownell52e31342008-03-03 12:43:23 -0800968{
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300969 struct gpio_bank *bank;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300970
Charulatha Va8be8da2011-04-22 16:38:16 +0530971 bank = container_of(chip, struct gpio_bank, chip);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300972
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200973 if (omap_gpio_is_input(bank, offset))
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200974 return omap_get_gpio_datain(bank, offset);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300975 else
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200976 return omap_get_gpio_dataout(bank, offset);
David Brownell52e31342008-03-03 12:43:23 -0800977}
978
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200979static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value)
David Brownell52e31342008-03-03 12:43:23 -0800980{
981 struct gpio_bank *bank;
982 unsigned long flags;
983
984 bank = container_of(chip, struct gpio_bank, chip);
985 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700986 bank->set_dataout(bank, offset, value);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200987 omap_set_gpio_direction(bank, offset, 0);
David Brownell52e31342008-03-03 12:43:23 -0800988 spin_unlock_irqrestore(&bank->lock, flags);
Javier Martinez Canillas2f56e0a2013-10-16 02:47:30 +0200989 return 0;
David Brownell52e31342008-03-03 12:43:23 -0800990}
991
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200992static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset,
993 unsigned debounce)
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700994{
995 struct gpio_bank *bank;
996 unsigned long flags;
997
998 bank = container_of(chip, struct gpio_bank, chip);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800999
Felipe Balbi168ef3d2010-05-26 14:42:23 -07001000 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001001 omap2_set_gpio_debounce(bank, offset, debounce);
Felipe Balbi168ef3d2010-05-26 14:42:23 -07001002 spin_unlock_irqrestore(&bank->lock, flags);
1003
1004 return 0;
1005}
1006
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001007static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
David Brownell52e31342008-03-03 12:43:23 -08001008{
1009 struct gpio_bank *bank;
1010 unsigned long flags;
1011
1012 bank = container_of(chip, struct gpio_bank, chip);
1013 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001014 bank->set_dataout(bank, offset, value);
David Brownell52e31342008-03-03 12:43:23 -08001015 spin_unlock_irqrestore(&bank->lock, flags);
1016}
1017
1018/*---------------------------------------------------------------------*/
1019
Tony Lindgren9a748052010-12-07 16:26:56 -08001020static void __init omap_gpio_show_rev(struct gpio_bank *bank)
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001021{
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001022 static bool called;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001023 u32 rev;
1024
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001025 if (called || bank->regs->revision == USHRT_MAX)
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001026 return;
1027
Victor Kamensky661553b2013-11-16 02:01:04 +02001028 rev = readw_relaxed(bank->base + bank->regs->revision);
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001029 pr_info("OMAP GPIO hardware version %d.%d\n",
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001030 (rev >> 4) & 0x0f, rev & 0x0f);
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001031
1032 called = true;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001033}
1034
Charulatha V03e128c2011-05-05 19:58:01 +05301035static void omap_gpio_mod_init(struct gpio_bank *bank)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001036{
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301037 void __iomem *base = bank->base;
1038 u32 l = 0xffffffff;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001039
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301040 if (bank->width == 16)
1041 l = 0xffff;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001042
Charulatha Vd0d665a2011-08-31 00:02:21 +05301043 if (bank->is_mpuio) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001044 writel_relaxed(l, bank->base + bank->regs->irqenable);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301045 return;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001046 }
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301047
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001048 omap_gpio_rmw(base, bank->regs->irqenable, l,
1049 bank->regs->irqenable_inv);
1050 omap_gpio_rmw(base, bank->regs->irqstatus, l,
1051 !bank->regs->irqenable_inv);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301052 if (bank->regs->debounce_en)
Victor Kamensky661553b2013-11-16 02:01:04 +02001053 writel_relaxed(0, base + bank->regs->debounce_en);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301054
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301055 /* Save OE default value (0xffffffff) in the context */
Victor Kamensky661553b2013-11-16 02:01:04 +02001056 bank->context.oe = readl_relaxed(bank->base + bank->regs->direction);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301057 /* Initialize interface clk ungated, module enabled */
1058 if (bank->regs->ctrl)
Victor Kamensky661553b2013-11-16 02:01:04 +02001059 writel_relaxed(0, base + bank->regs->ctrl);
Tarun Kanti DebBarma34672012012-07-11 14:43:14 +05301060
1061 bank->dbck = clk_get(bank->dev, "dbclk");
1062 if (IS_ERR(bank->dbck))
1063 dev_err(bank->dev, "Could not get gpio dbck\n");
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001064}
1065
Bill Pemberton38363092012-11-19 13:22:34 -05001066static void
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001067omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start,
1068 unsigned int num)
1069{
1070 struct irq_chip_generic *gc;
1071 struct irq_chip_type *ct;
1072
1073 gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base,
1074 handle_simple_irq);
Todd Poynor83233742011-07-18 07:43:14 -07001075 if (!gc) {
1076 dev_err(bank->dev, "Memory alloc failed for gc\n");
1077 return;
1078 }
1079
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001080 ct = gc->chip_types;
1081
1082 /* NOTE: No ack required, reading IRQ status clears it. */
1083 ct->chip.irq_mask = irq_gc_mask_set_bit;
1084 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001085 ct->chip.irq_set_type = omap_gpio_irq_type;
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301086
1087 if (bank->regs->wkup_en)
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001088 ct->chip.irq_set_wake = omap_gpio_wake_enable;
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001089
1090 ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride;
1091 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
1092 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
1093}
1094
Nishanth Menon46824e222014-09-05 14:52:55 -05001095static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001096{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001097 int j;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001098 static int gpio;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001099 int irq_base = 0;
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001100 int ret;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001101
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001102 /*
1103 * REVISIT eventually switch from OMAP-specific gpio structs
1104 * over to the generic ones
1105 */
1106 bank->chip.request = omap_gpio_request;
1107 bank->chip.free = omap_gpio_free;
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001108 bank->chip.get_direction = omap_gpio_get_direction;
1109 bank->chip.direction_input = omap_gpio_input;
1110 bank->chip.get = omap_gpio_get;
1111 bank->chip.direction_output = omap_gpio_output;
1112 bank->chip.set_debounce = omap_gpio_debounce;
1113 bank->chip.set = omap_gpio_set;
Charulatha Vd0d665a2011-08-31 00:02:21 +05301114 if (bank->is_mpuio) {
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001115 bank->chip.label = "mpuio";
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301116 if (bank->regs->wkup_en)
1117 bank->chip.dev = &omap_mpuio_device.dev;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001118 bank->chip.base = OMAP_MPUIO(0);
1119 } else {
1120 bank->chip.label = "gpio";
1121 bank->chip.base = gpio;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001122 gpio += bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001123 }
Kevin Hilmand5f46242011-04-21 09:23:00 -07001124 bank->chip.ngpio = bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001125
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001126 ret = gpiochip_add(&bank->chip);
1127 if (ret) {
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001128 dev_err(bank->dev, "Could not register gpio chip %d\n", ret);
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001129 return ret;
1130 }
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001131
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001132#ifdef CONFIG_ARCH_OMAP1
1133 /*
1134 * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop
1135 * irq_alloc_descs() since a base IRQ offset will no longer be needed.
1136 */
1137 irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
1138 if (irq_base < 0) {
1139 dev_err(bank->dev, "Couldn't allocate IRQ numbers\n");
1140 return -ENODEV;
1141 }
1142#endif
1143
Nishanth Menon46824e222014-09-05 14:52:55 -05001144 ret = gpiochip_irqchip_add(&bank->chip, irqc,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001145 irq_base, omap_gpio_irq_handler,
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001146 IRQ_TYPE_NONE);
1147
1148 if (ret) {
1149 dev_err(bank->dev, "Couldn't add irqchip to gpiochip %d\n", ret);
Linus Walleijda26d5d2014-09-16 15:11:41 -07001150 gpiochip_remove(&bank->chip);
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001151 return -ENODEV;
1152 }
1153
Nishanth Menon46824e222014-09-05 14:52:55 -05001154 gpiochip_set_chained_irqchip(&bank->chip, irqc,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001155 bank->irq, omap_gpio_irq_handler);
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001156
Jon Hunterede4d7a2013-03-01 11:22:47 -06001157 for (j = 0; j < bank->width; j++) {
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001158 int irq = irq_find_mapping(bank->chip.irqdomain, j);
Charulatha Vd0d665a2011-08-31 00:02:21 +05301159 if (bank->is_mpuio) {
Jon Hunterede4d7a2013-03-01 11:22:47 -06001160 omap_mpuio_alloc_gc(bank, irq, bank->width);
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001161 irq_set_chip_and_handler(irq, NULL, NULL);
1162 set_irq_flags(irq, 0);
Kevin Hilmanf8b46b52011-04-21 13:23:34 -07001163 }
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001164 }
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001165
1166 return 0;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001167}
1168
Benoit Cousson384ebe12011-08-16 11:53:02 +02001169static const struct of_device_id omap_gpio_match[];
1170
Bill Pemberton38363092012-11-19 13:22:34 -05001171static int omap_gpio_probe(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001172{
Benoit Cousson862ff642012-02-01 15:58:56 +01001173 struct device *dev = &pdev->dev;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001174 struct device_node *node = dev->of_node;
1175 const struct of_device_id *match;
Uwe Kleine-Königf6817a22012-05-21 21:57:39 +02001176 const struct omap_gpio_platform_data *pdata;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001177 struct resource *res;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001178 struct gpio_bank *bank;
Nishanth Menon46824e222014-09-05 14:52:55 -05001179 struct irq_chip *irqc;
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001180 int ret;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001181
Benoit Cousson384ebe12011-08-16 11:53:02 +02001182 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
1183
Jingoo Hane56aee12013-07-30 17:08:05 +09001184 pdata = match ? match->data : dev_get_platdata(dev);
Benoit Cousson384ebe12011-08-16 11:53:02 +02001185 if (!pdata)
Benoit Cousson96751fc2012-02-01 16:01:39 +01001186 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001187
Tobias Klauser086d5852012-10-05 11:37:38 +02001188 bank = devm_kzalloc(dev, sizeof(struct gpio_bank), GFP_KERNEL);
Charulatha V03e128c2011-05-05 19:58:01 +05301189 if (!bank) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001190 dev_err(dev, "Memory alloc failed\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001191 return -ENOMEM;
Charulatha V03e128c2011-05-05 19:58:01 +05301192 }
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001193
Nishanth Menon46824e222014-09-05 14:52:55 -05001194 irqc = devm_kzalloc(dev, sizeof(*irqc), GFP_KERNEL);
1195 if (!irqc)
1196 return -ENOMEM;
1197
Tony Lindgren3d009c82015-01-16 14:50:50 -08001198 irqc->irq_startup = omap_gpio_irq_startup,
Nishanth Menon46824e222014-09-05 14:52:55 -05001199 irqc->irq_shutdown = omap_gpio_irq_shutdown,
1200 irqc->irq_ack = omap_gpio_ack_irq,
1201 irqc->irq_mask = omap_gpio_mask_irq,
1202 irqc->irq_unmask = omap_gpio_unmask_irq,
1203 irqc->irq_set_type = omap_gpio_irq_type,
1204 irqc->irq_set_wake = omap_gpio_wake_enable,
1205 irqc->name = dev_name(&pdev->dev);
1206
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001207 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1208 if (unlikely(!res)) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001209 dev_err(dev, "Invalid IRQ resource\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001210 return -ENODEV;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001211 }
1212
1213 bank->irq = res->start;
Benoit Cousson862ff642012-02-01 15:58:56 +01001214 bank->dev = dev;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001215 bank->chip.dev = dev;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001216 bank->dbck_flag = pdata->dbck_flag;
Tony Lindgren5de62b82010-12-07 16:26:58 -08001217 bank->stride = pdata->bank_stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001218 bank->width = pdata->bank_width;
Charulatha Vd0d665a2011-08-31 00:02:21 +05301219 bank->is_mpuio = pdata->is_mpuio;
Charulatha V803a2432011-05-05 17:04:12 +05301220 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001221 bank->regs = pdata->regs;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001222#ifdef CONFIG_OF_GPIO
1223 bank->chip.of_node = of_node_get(node);
1224#endif
Jon Huntera2797be2013-04-04 15:16:15 -05001225 if (node) {
1226 if (!of_property_read_bool(node, "ti,gpio-always-on"))
1227 bank->loses_context = true;
1228 } else {
1229 bank->loses_context = pdata->loses_context;
Jon Hunter352a2d52013-04-15 13:06:54 -05001230
1231 if (bank->loses_context)
1232 bank->get_context_loss_count =
1233 pdata->get_context_loss_count;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001234 }
1235
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001236 if (bank->regs->set_dataout && bank->regs->clr_dataout)
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001237 bank->set_dataout = omap_set_gpio_dataout_reg;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001238 else
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001239 bank->set_dataout = omap_set_gpio_dataout_mask;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001240
1241 spin_lock_init(&bank->lock);
1242
1243 /* Static mapping, never released */
1244 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Jingoo Han717f70e2014-02-12 11:51:38 +09001245 bank->base = devm_ioremap_resource(dev, res);
1246 if (IS_ERR(bank->base)) {
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001247 irq_domain_remove(bank->chip.irqdomain);
Jingoo Han717f70e2014-02-12 11:51:38 +09001248 return PTR_ERR(bank->base);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001249 }
1250
Tarun Kanti DebBarma065cd792011-11-24 01:48:52 +05301251 platform_set_drvdata(pdev, bank);
1252
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001253 pm_runtime_enable(bank->dev);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301254 pm_runtime_irq_safe(bank->dev);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001255 pm_runtime_get_sync(bank->dev);
1256
Charulatha Vd0d665a2011-08-31 00:02:21 +05301257 if (bank->is_mpuio)
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001258 omap_mpuio_init(bank);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301259
Charulatha V03e128c2011-05-05 19:58:01 +05301260 omap_gpio_mod_init(bank);
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001261
Nishanth Menon46824e222014-09-05 14:52:55 -05001262 ret = omap_gpio_chip_init(bank, irqc);
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001263 if (ret)
1264 return ret;
1265
Tony Lindgren9a748052010-12-07 16:26:56 -08001266 omap_gpio_show_rev(bank);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001267
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301268 pm_runtime_put(bank->dev);
1269
Charulatha V03e128c2011-05-05 19:58:01 +05301270 list_add_tail(&bank->node, &omap_gpio_list);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001271
Jon Hunter879fe322013-04-04 15:16:12 -05001272 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001273}
1274
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301275#ifdef CONFIG_ARCH_OMAP2PLUS
1276
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001277#if defined(CONFIG_PM)
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301278static void omap_gpio_restore_context(struct gpio_bank *bank);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001279
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301280static int omap_gpio_runtime_suspend(struct device *dev)
1281{
1282 struct platform_device *pdev = to_platform_device(dev);
1283 struct gpio_bank *bank = platform_get_drvdata(pdev);
1284 u32 l1 = 0, l2 = 0;
1285 unsigned long flags;
Kevin Hilman68942ed2012-03-05 15:10:04 -08001286 u32 wake_low, wake_hi;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301287
1288 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman68942ed2012-03-05 15:10:04 -08001289
1290 /*
1291 * Only edges can generate a wakeup event to the PRCM.
1292 *
1293 * Therefore, ensure any wake-up capable GPIOs have
1294 * edge-detection enabled before going idle to ensure a wakeup
1295 * to the PRCM is generated on a GPIO transition. (c.f. 34xx
1296 * NDA TRM 25.5.3.1)
1297 *
1298 * The normal values will be restored upon ->runtime_resume()
1299 * by writing back the values saved in bank->context.
1300 */
1301 wake_low = bank->context.leveldetect0 & bank->context.wake_en;
1302 if (wake_low)
Victor Kamensky661553b2013-11-16 02:01:04 +02001303 writel_relaxed(wake_low | bank->context.fallingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001304 bank->base + bank->regs->fallingdetect);
1305 wake_hi = bank->context.leveldetect1 & bank->context.wake_en;
1306 if (wake_hi)
Victor Kamensky661553b2013-11-16 02:01:04 +02001307 writel_relaxed(wake_hi | bank->context.risingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001308 bank->base + bank->regs->risingdetect);
1309
Kevin Hilmanb3c64bc2012-05-17 16:42:16 -07001310 if (!bank->enabled_non_wakeup_gpios)
1311 goto update_gpio_context_count;
1312
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301313 if (bank->power_mode != OFF_MODE) {
1314 bank->power_mode = 0;
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +05301315 goto update_gpio_context_count;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301316 }
1317 /*
1318 * If going to OFF, remove triggering for all
1319 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1320 * generated. See OMAP2420 Errata item 1.101.
1321 */
Victor Kamensky661553b2013-11-16 02:01:04 +02001322 bank->saved_datain = readl_relaxed(bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301323 bank->regs->datain);
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301324 l1 = bank->context.fallingdetect;
1325 l2 = bank->context.risingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301326
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301327 l1 &= ~bank->enabled_non_wakeup_gpios;
1328 l2 &= ~bank->enabled_non_wakeup_gpios;
1329
Victor Kamensky661553b2013-11-16 02:01:04 +02001330 writel_relaxed(l1, bank->base + bank->regs->fallingdetect);
1331 writel_relaxed(l2, bank->base + bank->regs->risingdetect);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301332
1333 bank->workaround_enabled = true;
1334
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +05301335update_gpio_context_count:
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301336 if (bank->get_context_loss_count)
1337 bank->context_loss_count =
1338 bank->get_context_loss_count(bank->dev);
1339
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001340 omap_gpio_dbck_disable(bank);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301341 spin_unlock_irqrestore(&bank->lock, flags);
1342
1343 return 0;
1344}
1345
Jon Hunter352a2d52013-04-15 13:06:54 -05001346static void omap_gpio_init_context(struct gpio_bank *p);
1347
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301348static int omap_gpio_runtime_resume(struct device *dev)
1349{
1350 struct platform_device *pdev = to_platform_device(dev);
1351 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301352 u32 l = 0, gen, gen0, gen1;
1353 unsigned long flags;
Jon Huntera2797be2013-04-04 15:16:15 -05001354 int c;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301355
1356 spin_lock_irqsave(&bank->lock, flags);
Jon Hunter352a2d52013-04-15 13:06:54 -05001357
1358 /*
1359 * On the first resume during the probe, the context has not
1360 * been initialised and so initialise it now. Also initialise
1361 * the context loss count.
1362 */
1363 if (bank->loses_context && !bank->context_valid) {
1364 omap_gpio_init_context(bank);
1365
1366 if (bank->get_context_loss_count)
1367 bank->context_loss_count =
1368 bank->get_context_loss_count(bank->dev);
1369 }
1370
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001371 omap_gpio_dbck_enable(bank);
Kevin Hilman68942ed2012-03-05 15:10:04 -08001372
1373 /*
1374 * In ->runtime_suspend(), level-triggered, wakeup-enabled
1375 * GPIOs were set to edge trigger also in order to be able to
1376 * generate a PRCM wakeup. Here we restore the
1377 * pre-runtime_suspend() values for edge triggering.
1378 */
Victor Kamensky661553b2013-11-16 02:01:04 +02001379 writel_relaxed(bank->context.fallingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001380 bank->base + bank->regs->fallingdetect);
Victor Kamensky661553b2013-11-16 02:01:04 +02001381 writel_relaxed(bank->context.risingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001382 bank->base + bank->regs->risingdetect);
1383
Jon Huntera2797be2013-04-04 15:16:15 -05001384 if (bank->loses_context) {
1385 if (!bank->get_context_loss_count) {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301386 omap_gpio_restore_context(bank);
1387 } else {
Jon Huntera2797be2013-04-04 15:16:15 -05001388 c = bank->get_context_loss_count(bank->dev);
1389 if (c != bank->context_loss_count) {
1390 omap_gpio_restore_context(bank);
1391 } else {
1392 spin_unlock_irqrestore(&bank->lock, flags);
1393 return 0;
1394 }
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301395 }
1396 }
1397
Tarun Kanti DebBarma1b1287032012-04-27 19:43:38 +05301398 if (!bank->workaround_enabled) {
1399 spin_unlock_irqrestore(&bank->lock, flags);
1400 return 0;
1401 }
1402
Victor Kamensky661553b2013-11-16 02:01:04 +02001403 l = readl_relaxed(bank->base + bank->regs->datain);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301404
1405 /*
1406 * Check if any of the non-wakeup interrupt GPIOs have changed
1407 * state. If so, generate an IRQ by software. This is
1408 * horribly racy, but it's the best we can do to work around
1409 * this silicon bug.
1410 */
1411 l ^= bank->saved_datain;
1412 l &= bank->enabled_non_wakeup_gpios;
1413
1414 /*
1415 * No need to generate IRQs for the rising edge for gpio IRQs
1416 * configured with falling edge only; and vice versa.
1417 */
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301418 gen0 = l & bank->context.fallingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301419 gen0 &= bank->saved_datain;
1420
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301421 gen1 = l & bank->context.risingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301422 gen1 &= ~(bank->saved_datain);
1423
1424 /* FIXME: Consider GPIO IRQs with level detections properly! */
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301425 gen = l & (~(bank->context.fallingdetect) &
1426 ~(bank->context.risingdetect));
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301427 /* Consider all GPIO IRQs needed to be updated */
1428 gen |= gen0 | gen1;
1429
1430 if (gen) {
1431 u32 old0, old1;
1432
Victor Kamensky661553b2013-11-16 02:01:04 +02001433 old0 = readl_relaxed(bank->base + bank->regs->leveldetect0);
1434 old1 = readl_relaxed(bank->base + bank->regs->leveldetect1);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301435
Tarun Kanti DebBarma4e962e82012-04-27 19:43:37 +05301436 if (!bank->regs->irqstatus_raw0) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001437 writel_relaxed(old0 | gen, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301438 bank->regs->leveldetect0);
Victor Kamensky661553b2013-11-16 02:01:04 +02001439 writel_relaxed(old1 | gen, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301440 bank->regs->leveldetect1);
1441 }
1442
Tarun Kanti DebBarma4e962e82012-04-27 19:43:37 +05301443 if (bank->regs->irqstatus_raw0) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001444 writel_relaxed(old0 | l, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301445 bank->regs->leveldetect0);
Victor Kamensky661553b2013-11-16 02:01:04 +02001446 writel_relaxed(old1 | l, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301447 bank->regs->leveldetect1);
1448 }
Victor Kamensky661553b2013-11-16 02:01:04 +02001449 writel_relaxed(old0, bank->base + bank->regs->leveldetect0);
1450 writel_relaxed(old1, bank->base + bank->regs->leveldetect1);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301451 }
1452
1453 bank->workaround_enabled = false;
1454 spin_unlock_irqrestore(&bank->lock, flags);
1455
1456 return 0;
1457}
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001458#endif /* CONFIG_PM */
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301459
1460void omap2_gpio_prepare_for_idle(int pwr_mode)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001461{
Charulatha V03e128c2011-05-05 19:58:01 +05301462 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001463
Charulatha V03e128c2011-05-05 19:58:01 +05301464 list_for_each_entry(bank, &omap_gpio_list, node) {
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +02001465 if (!BANK_USED(bank) || !bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301466 continue;
1467
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301468 bank->power_mode = pwr_mode;
1469
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301470 pm_runtime_put_sync_suspend(bank->dev);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001471 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001472}
1473
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001474void omap2_gpio_resume_after_idle(void)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001475{
Charulatha V03e128c2011-05-05 19:58:01 +05301476 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001477
Charulatha V03e128c2011-05-05 19:58:01 +05301478 list_for_each_entry(bank, &omap_gpio_list, node) {
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +02001479 if (!BANK_USED(bank) || !bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301480 continue;
1481
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301482 pm_runtime_get_sync(bank->dev);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001483 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001484}
1485
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001486#if defined(CONFIG_PM)
Jon Hunter352a2d52013-04-15 13:06:54 -05001487static void omap_gpio_init_context(struct gpio_bank *p)
1488{
1489 struct omap_gpio_reg_offs *regs = p->regs;
1490 void __iomem *base = p->base;
1491
Victor Kamensky661553b2013-11-16 02:01:04 +02001492 p->context.ctrl = readl_relaxed(base + regs->ctrl);
1493 p->context.oe = readl_relaxed(base + regs->direction);
1494 p->context.wake_en = readl_relaxed(base + regs->wkup_en);
1495 p->context.leveldetect0 = readl_relaxed(base + regs->leveldetect0);
1496 p->context.leveldetect1 = readl_relaxed(base + regs->leveldetect1);
1497 p->context.risingdetect = readl_relaxed(base + regs->risingdetect);
1498 p->context.fallingdetect = readl_relaxed(base + regs->fallingdetect);
1499 p->context.irqenable1 = readl_relaxed(base + regs->irqenable);
1500 p->context.irqenable2 = readl_relaxed(base + regs->irqenable2);
Jon Hunter352a2d52013-04-15 13:06:54 -05001501
1502 if (regs->set_dataout && p->regs->clr_dataout)
Victor Kamensky661553b2013-11-16 02:01:04 +02001503 p->context.dataout = readl_relaxed(base + regs->set_dataout);
Jon Hunter352a2d52013-04-15 13:06:54 -05001504 else
Victor Kamensky661553b2013-11-16 02:01:04 +02001505 p->context.dataout = readl_relaxed(base + regs->dataout);
Jon Hunter352a2d52013-04-15 13:06:54 -05001506
1507 p->context_valid = true;
1508}
1509
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301510static void omap_gpio_restore_context(struct gpio_bank *bank)
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301511{
Victor Kamensky661553b2013-11-16 02:01:04 +02001512 writel_relaxed(bank->context.wake_en,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301513 bank->base + bank->regs->wkup_en);
Victor Kamensky661553b2013-11-16 02:01:04 +02001514 writel_relaxed(bank->context.ctrl, bank->base + bank->regs->ctrl);
1515 writel_relaxed(bank->context.leveldetect0,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301516 bank->base + bank->regs->leveldetect0);
Victor Kamensky661553b2013-11-16 02:01:04 +02001517 writel_relaxed(bank->context.leveldetect1,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301518 bank->base + bank->regs->leveldetect1);
Victor Kamensky661553b2013-11-16 02:01:04 +02001519 writel_relaxed(bank->context.risingdetect,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301520 bank->base + bank->regs->risingdetect);
Victor Kamensky661553b2013-11-16 02:01:04 +02001521 writel_relaxed(bank->context.fallingdetect,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301522 bank->base + bank->regs->fallingdetect);
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301523 if (bank->regs->set_dataout && bank->regs->clr_dataout)
Victor Kamensky661553b2013-11-16 02:01:04 +02001524 writel_relaxed(bank->context.dataout,
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301525 bank->base + bank->regs->set_dataout);
1526 else
Victor Kamensky661553b2013-11-16 02:01:04 +02001527 writel_relaxed(bank->context.dataout,
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301528 bank->base + bank->regs->dataout);
Victor Kamensky661553b2013-11-16 02:01:04 +02001529 writel_relaxed(bank->context.oe, bank->base + bank->regs->direction);
Nishanth Menon6d13eaa2011-08-29 18:54:50 +05301530
Nishanth Menonae547352011-09-09 19:08:58 +05301531 if (bank->dbck_enable_mask) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001532 writel_relaxed(bank->context.debounce, bank->base +
Nishanth Menonae547352011-09-09 19:08:58 +05301533 bank->regs->debounce);
Victor Kamensky661553b2013-11-16 02:01:04 +02001534 writel_relaxed(bank->context.debounce_en,
Nishanth Menonae547352011-09-09 19:08:58 +05301535 bank->base + bank->regs->debounce_en);
1536 }
Nishanth Menonba805be2011-08-29 18:41:08 +05301537
Victor Kamensky661553b2013-11-16 02:01:04 +02001538 writel_relaxed(bank->context.irqenable1,
Nishanth Menonba805be2011-08-29 18:41:08 +05301539 bank->base + bank->regs->irqenable);
Victor Kamensky661553b2013-11-16 02:01:04 +02001540 writel_relaxed(bank->context.irqenable2,
Nishanth Menonba805be2011-08-29 18:41:08 +05301541 bank->base + bank->regs->irqenable2);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301542}
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001543#endif /* CONFIG_PM */
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301544#else
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301545#define omap_gpio_runtime_suspend NULL
1546#define omap_gpio_runtime_resume NULL
Arnd Bergmannea4a21a2013-05-31 17:59:46 +02001547static inline void omap_gpio_init_context(struct gpio_bank *p) {}
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301548#endif
1549
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301550static const struct dev_pm_ops gpio_pm_ops = {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301551 SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume,
1552 NULL)
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301553};
1554
Benoit Cousson384ebe12011-08-16 11:53:02 +02001555#if defined(CONFIG_OF)
1556static struct omap_gpio_reg_offs omap2_gpio_regs = {
1557 .revision = OMAP24XX_GPIO_REVISION,
1558 .direction = OMAP24XX_GPIO_OE,
1559 .datain = OMAP24XX_GPIO_DATAIN,
1560 .dataout = OMAP24XX_GPIO_DATAOUT,
1561 .set_dataout = OMAP24XX_GPIO_SETDATAOUT,
1562 .clr_dataout = OMAP24XX_GPIO_CLEARDATAOUT,
1563 .irqstatus = OMAP24XX_GPIO_IRQSTATUS1,
1564 .irqstatus2 = OMAP24XX_GPIO_IRQSTATUS2,
1565 .irqenable = OMAP24XX_GPIO_IRQENABLE1,
1566 .irqenable2 = OMAP24XX_GPIO_IRQENABLE2,
1567 .set_irqenable = OMAP24XX_GPIO_SETIRQENABLE1,
1568 .clr_irqenable = OMAP24XX_GPIO_CLEARIRQENABLE1,
1569 .debounce = OMAP24XX_GPIO_DEBOUNCE_VAL,
1570 .debounce_en = OMAP24XX_GPIO_DEBOUNCE_EN,
1571 .ctrl = OMAP24XX_GPIO_CTRL,
1572 .wkup_en = OMAP24XX_GPIO_WAKE_EN,
1573 .leveldetect0 = OMAP24XX_GPIO_LEVELDETECT0,
1574 .leveldetect1 = OMAP24XX_GPIO_LEVELDETECT1,
1575 .risingdetect = OMAP24XX_GPIO_RISINGDETECT,
1576 .fallingdetect = OMAP24XX_GPIO_FALLINGDETECT,
1577};
1578
1579static struct omap_gpio_reg_offs omap4_gpio_regs = {
1580 .revision = OMAP4_GPIO_REVISION,
1581 .direction = OMAP4_GPIO_OE,
1582 .datain = OMAP4_GPIO_DATAIN,
1583 .dataout = OMAP4_GPIO_DATAOUT,
1584 .set_dataout = OMAP4_GPIO_SETDATAOUT,
1585 .clr_dataout = OMAP4_GPIO_CLEARDATAOUT,
1586 .irqstatus = OMAP4_GPIO_IRQSTATUS0,
1587 .irqstatus2 = OMAP4_GPIO_IRQSTATUS1,
1588 .irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1589 .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1,
1590 .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1591 .clr_irqenable = OMAP4_GPIO_IRQSTATUSCLR0,
1592 .debounce = OMAP4_GPIO_DEBOUNCINGTIME,
1593 .debounce_en = OMAP4_GPIO_DEBOUNCENABLE,
1594 .ctrl = OMAP4_GPIO_CTRL,
1595 .wkup_en = OMAP4_GPIO_IRQWAKEN0,
1596 .leveldetect0 = OMAP4_GPIO_LEVELDETECT0,
1597 .leveldetect1 = OMAP4_GPIO_LEVELDETECT1,
1598 .risingdetect = OMAP4_GPIO_RISINGDETECT,
1599 .fallingdetect = OMAP4_GPIO_FALLINGDETECT,
1600};
1601
Chen Gange9a65bb2013-02-06 18:44:32 +08001602static const struct omap_gpio_platform_data omap2_pdata = {
Benoit Cousson384ebe12011-08-16 11:53:02 +02001603 .regs = &omap2_gpio_regs,
1604 .bank_width = 32,
1605 .dbck_flag = false,
1606};
1607
Chen Gange9a65bb2013-02-06 18:44:32 +08001608static const struct omap_gpio_platform_data omap3_pdata = {
Benoit Cousson384ebe12011-08-16 11:53:02 +02001609 .regs = &omap2_gpio_regs,
1610 .bank_width = 32,
1611 .dbck_flag = true,
1612};
1613
Chen Gange9a65bb2013-02-06 18:44:32 +08001614static const struct omap_gpio_platform_data omap4_pdata = {
Benoit Cousson384ebe12011-08-16 11:53:02 +02001615 .regs = &omap4_gpio_regs,
1616 .bank_width = 32,
1617 .dbck_flag = true,
1618};
1619
1620static const struct of_device_id omap_gpio_match[] = {
1621 {
1622 .compatible = "ti,omap4-gpio",
1623 .data = &omap4_pdata,
1624 },
1625 {
1626 .compatible = "ti,omap3-gpio",
1627 .data = &omap3_pdata,
1628 },
1629 {
1630 .compatible = "ti,omap2-gpio",
1631 .data = &omap2_pdata,
1632 },
1633 { },
1634};
1635MODULE_DEVICE_TABLE(of, omap_gpio_match);
1636#endif
1637
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001638static struct platform_driver omap_gpio_driver = {
1639 .probe = omap_gpio_probe,
1640 .driver = {
1641 .name = "omap_gpio",
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301642 .pm = &gpio_pm_ops,
Benoit Cousson384ebe12011-08-16 11:53:02 +02001643 .of_match_table = of_match_ptr(omap_gpio_match),
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001644 },
1645};
1646
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001647/*
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001648 * gpio driver register needs to be done before
1649 * machine_init functions access gpio APIs.
1650 * Hence omap_gpio_drv_reg() is a postcore_initcall.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001651 */
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001652static int __init omap_gpio_drv_reg(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001653{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001654 return platform_driver_register(&omap_gpio_driver);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001655}
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001656postcore_initcall(omap_gpio_drv_reg);