blob: b232397ad7ec1599ffda494f73fdc02fe8e83875 [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
Charulatha Vc8eef652011-05-02 15:21:42 +053084#define GPIO_MOD_CTRL_BIT BIT(0)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010085
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +020086#define BANK_USED(bank) (bank->mod_usage || bank->irq_usage)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +020087#define LINE_USED(line, offset) (line & (BIT(offset)))
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +020088
Tony Lindgren3d009c82015-01-16 14:50:50 -080089static void omap_gpio_unmask_irq(struct irq_data *d);
90
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +020091static inline struct gpio_bank *omap_irq_data_get_bank(struct irq_data *d)
Jon Hunterede4d7a2013-03-01 11:22:47 -060092{
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +020093 struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
94 return container_of(chip, struct gpio_bank, chip);
Benoit Cousson25db7112012-02-23 21:50:10 +010095}
96
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +020097static void omap_set_gpio_direction(struct gpio_bank *bank, int gpio,
98 int is_input)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010099{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100100 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100101 u32 l;
102
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700103 reg += bank->regs->direction;
Victor Kamensky661553b2013-11-16 02:01:04 +0200104 l = readl_relaxed(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100105 if (is_input)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200106 l |= BIT(gpio);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100107 else
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200108 l &= ~(BIT(gpio));
Victor Kamensky661553b2013-11-16 02:01:04 +0200109 writel_relaxed(l, reg);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530110 bank->context.oe = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100111}
112
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700113
114/* set data out value using dedicate set/clear register */
Grygorii Strashko04ebcbd2015-03-23 14:18:24 +0200115static void omap_set_gpio_dataout_reg(struct gpio_bank *bank, unsigned offset,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200116 int enable)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100117{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100118 void __iomem *reg = bank->base;
Grygorii Strashko04ebcbd2015-03-23 14:18:24 +0200119 u32 l = BIT(offset);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100120
Tarun Kanti DebBarma2c836f72012-03-02 12:52:52 +0530121 if (enable) {
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700122 reg += bank->regs->set_dataout;
Tarun Kanti DebBarma2c836f72012-03-02 12:52:52 +0530123 bank->context.dataout |= l;
124 } else {
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700125 reg += bank->regs->clr_dataout;
Tarun Kanti DebBarma2c836f72012-03-02 12:52:52 +0530126 bank->context.dataout &= ~l;
127 }
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700128
Victor Kamensky661553b2013-11-16 02:01:04 +0200129 writel_relaxed(l, reg);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700130}
131
132/* set data out value using mask register */
Grygorii Strashko04ebcbd2015-03-23 14:18:24 +0200133static void omap_set_gpio_dataout_mask(struct gpio_bank *bank, unsigned offset,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200134 int enable)
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700135{
136 void __iomem *reg = bank->base + bank->regs->dataout;
Grygorii Strashko04ebcbd2015-03-23 14:18:24 +0200137 u32 gpio_bit = BIT(offset);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700138 u32 l;
139
Victor Kamensky661553b2013-11-16 02:01:04 +0200140 l = readl_relaxed(reg);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700141 if (enable)
142 l |= gpio_bit;
143 else
144 l &= ~gpio_bit;
Victor Kamensky661553b2013-11-16 02:01:04 +0200145 writel_relaxed(l, reg);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530146 bank->context.dataout = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100147}
148
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200149static int omap_get_gpio_datain(struct gpio_bank *bank, int offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100150{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700151 void __iomem *reg = bank->base + bank->regs->datain;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100152
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200153 return (readl_relaxed(reg) & (BIT(offset))) != 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100154}
155
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200156static int omap_get_gpio_dataout(struct gpio_bank *bank, int offset)
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300157{
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700158 void __iomem *reg = bank->base + bank->regs->dataout;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300159
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200160 return (readl_relaxed(reg) & (BIT(offset))) != 0;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300161}
162
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200163static inline void omap_gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
Kevin Hilmanece95282011-07-12 08:18:15 -0700164{
Victor Kamensky661553b2013-11-16 02:01:04 +0200165 int l = readl_relaxed(base + reg);
Kevin Hilmanece95282011-07-12 08:18:15 -0700166
Benoit Cousson862ff642012-02-01 15:58:56 +0100167 if (set)
Kevin Hilmanece95282011-07-12 08:18:15 -0700168 l |= mask;
169 else
170 l &= ~mask;
171
Victor Kamensky661553b2013-11-16 02:01:04 +0200172 writel_relaxed(l, base + reg);
Kevin Hilmanece95282011-07-12 08:18:15 -0700173}
Tony Lindgren92105bb2005-09-07 17:20:26 +0100174
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200175static inline void omap_gpio_dbck_enable(struct gpio_bank *bank)
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530176{
177 if (bank->dbck_enable_mask && !bank->dbck_enabled) {
Rajendra Nayak345477f2014-04-23 11:41:03 +0530178 clk_prepare_enable(bank->dbck);
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530179 bank->dbck_enabled = true;
Grazvydas Ignotas9e303f22012-06-16 22:01:25 +0300180
Victor Kamensky661553b2013-11-16 02:01:04 +0200181 writel_relaxed(bank->dbck_enable_mask,
Grazvydas Ignotas9e303f22012-06-16 22:01:25 +0300182 bank->base + bank->regs->debounce_en);
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530183 }
184}
185
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200186static inline void omap_gpio_dbck_disable(struct gpio_bank *bank)
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530187{
188 if (bank->dbck_enable_mask && bank->dbck_enabled) {
Grazvydas Ignotas9e303f22012-06-16 22:01:25 +0300189 /*
190 * Disable debounce before cutting it's clock. If debounce is
191 * enabled but the clock is not, GPIO module seems to be unable
192 * to detect events and generate interrupts at least on OMAP3.
193 */
Victor Kamensky661553b2013-11-16 02:01:04 +0200194 writel_relaxed(0, bank->base + bank->regs->debounce_en);
Grazvydas Ignotas9e303f22012-06-16 22:01:25 +0300195
Rajendra Nayak345477f2014-04-23 11:41:03 +0530196 clk_disable_unprepare(bank->dbck);
Tarun Kanti DebBarma72f83af92011-11-24 03:03:28 +0530197 bank->dbck_enabled = false;
198 }
199}
200
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700201/**
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200202 * omap2_set_gpio_debounce - low level gpio debounce time
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700203 * @bank: the gpio bank we're acting upon
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200204 * @offset: the gpio number on this @bank
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700205 * @debounce: debounce time to use
206 *
207 * OMAP's debounce time is in 31us steps so we need
208 * to convert and round up to the closest unit.
209 */
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200210static void omap2_set_gpio_debounce(struct gpio_bank *bank, unsigned offset,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200211 unsigned debounce)
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700212{
Kevin Hilman9942da02011-04-22 12:02:05 -0700213 void __iomem *reg;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700214 u32 val;
215 u32 l;
216
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800217 if (!bank->dbck_flag)
218 return;
219
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700220 if (debounce < 32)
221 debounce = 0x01;
222 else if (debounce > 7936)
223 debounce = 0xff;
224 else
225 debounce = (debounce / 0x1f) - 1;
226
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200227 l = BIT(offset);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700228
Rajendra Nayak345477f2014-04-23 11:41:03 +0530229 clk_prepare_enable(bank->dbck);
Kevin Hilman9942da02011-04-22 12:02:05 -0700230 reg = bank->base + bank->regs->debounce;
Victor Kamensky661553b2013-11-16 02:01:04 +0200231 writel_relaxed(debounce, reg);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700232
Kevin Hilman9942da02011-04-22 12:02:05 -0700233 reg = bank->base + bank->regs->debounce_en;
Victor Kamensky661553b2013-11-16 02:01:04 +0200234 val = readl_relaxed(reg);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700235
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530236 if (debounce)
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700237 val |= l;
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530238 else
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700239 val &= ~l;
Kevin Hilmanf7ec0b02010-06-09 13:53:07 +0300240 bank->dbck_enable_mask = val;
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700241
Victor Kamensky661553b2013-11-16 02:01:04 +0200242 writel_relaxed(val, reg);
Rajendra Nayak345477f2014-04-23 11:41:03 +0530243 clk_disable_unprepare(bank->dbck);
Tarun Kanti DebBarma6fd9c422011-11-24 03:58:54 +0530244 /*
245 * Enable debounce clock per module.
246 * This call is mandatory because in omap_gpio_request() when
247 * *_runtime_get_sync() is called, _gpio_dbck_enable() within
248 * runtime callbck fails to turn on dbck because dbck_enable_mask
249 * used within _gpio_dbck_enable() is still not initialized at
250 * that point. Therefore we have to enable dbck here.
251 */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200252 omap_gpio_dbck_enable(bank);
Nishanth Menonae547352011-09-09 19:08:58 +0530253 if (bank->dbck_enable_mask) {
254 bank->context.debounce = debounce;
255 bank->context.debounce_en = val;
256 }
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700257}
258
Jon Hunterc9c55d92012-10-26 14:26:04 -0500259/**
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200260 * omap_clear_gpio_debounce - clear debounce settings for a gpio
Jon Hunterc9c55d92012-10-26 14:26:04 -0500261 * @bank: the gpio bank we're acting upon
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200262 * @offset: the gpio number on this @bank
Jon Hunterc9c55d92012-10-26 14:26:04 -0500263 *
264 * If a gpio is using debounce, then clear the debounce enable bit and if
265 * this is the only gpio in this bank using debounce, then clear the debounce
266 * time too. The debounce clock will also be disabled when calling this function
267 * if this is the only gpio in the bank using debounce.
268 */
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200269static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset)
Jon Hunterc9c55d92012-10-26 14:26:04 -0500270{
Grygorii Strashko4a58d222015-03-23 14:18:25 +0200271 u32 gpio_bit = BIT(offset);
Jon Hunterc9c55d92012-10-26 14:26:04 -0500272
273 if (!bank->dbck_flag)
274 return;
275
276 if (!(bank->dbck_enable_mask & gpio_bit))
277 return;
278
279 bank->dbck_enable_mask &= ~gpio_bit;
280 bank->context.debounce_en &= ~gpio_bit;
Victor Kamensky661553b2013-11-16 02:01:04 +0200281 writel_relaxed(bank->context.debounce_en,
Jon Hunterc9c55d92012-10-26 14:26:04 -0500282 bank->base + bank->regs->debounce_en);
283
284 if (!bank->dbck_enable_mask) {
285 bank->context.debounce = 0;
Victor Kamensky661553b2013-11-16 02:01:04 +0200286 writel_relaxed(bank->context.debounce, bank->base +
Jon Hunterc9c55d92012-10-26 14:26:04 -0500287 bank->regs->debounce);
Rajendra Nayak345477f2014-04-23 11:41:03 +0530288 clk_disable_unprepare(bank->dbck);
Jon Hunterc9c55d92012-10-26 14:26:04 -0500289 bank->dbck_enabled = false;
290 }
291}
292
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200293static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
Tarun Kanti DebBarma00ece7e2011-11-25 15:41:06 +0530294 unsigned trigger)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100295{
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800296 void __iomem *base = bank->base;
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200297 u32 gpio_bit = BIT(gpio);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100298
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200299 omap_gpio_rmw(base, bank->regs->leveldetect0, gpio_bit,
300 trigger & IRQ_TYPE_LEVEL_LOW);
301 omap_gpio_rmw(base, bank->regs->leveldetect1, gpio_bit,
302 trigger & IRQ_TYPE_LEVEL_HIGH);
303 omap_gpio_rmw(base, bank->regs->risingdetect, gpio_bit,
304 trigger & IRQ_TYPE_EDGE_RISING);
305 omap_gpio_rmw(base, bank->regs->fallingdetect, gpio_bit,
306 trigger & IRQ_TYPE_EDGE_FALLING);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530307
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530308 bank->context.leveldetect0 =
Victor Kamensky661553b2013-11-16 02:01:04 +0200309 readl_relaxed(bank->base + bank->regs->leveldetect0);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530310 bank->context.leveldetect1 =
Victor Kamensky661553b2013-11-16 02:01:04 +0200311 readl_relaxed(bank->base + bank->regs->leveldetect1);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530312 bank->context.risingdetect =
Victor Kamensky661553b2013-11-16 02:01:04 +0200313 readl_relaxed(bank->base + bank->regs->risingdetect);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530314 bank->context.fallingdetect =
Victor Kamensky661553b2013-11-16 02:01:04 +0200315 readl_relaxed(bank->base + bank->regs->fallingdetect);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530316
317 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200318 omap_gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530319 bank->context.wake_en =
Victor Kamensky661553b2013-11-16 02:01:04 +0200320 readl_relaxed(bank->base + bank->regs->wkup_en);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530321 }
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530322
Ambresh K55b220c2011-06-15 13:40:45 -0700323 /* This part needs to be executed always for OMAP{34xx, 44xx} */
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530324 if (!bank->regs->irqctrl) {
325 /* On omap24xx proceed only when valid GPIO bit is set */
326 if (bank->non_wakeup_gpios) {
327 if (!(bank->non_wakeup_gpios & gpio_bit))
328 goto exit;
329 }
330
Chunqiu Wang699117a62009-06-24 17:13:39 +0000331 /*
332 * Log the edge gpio and manually trigger the IRQ
333 * after resume if the input level changes
334 * to avoid irq lost during PER RET/OFF mode
335 * Applies for omap2 non-wakeup gpio and all omap3 gpios
336 */
337 if (trigger & IRQ_TYPE_EDGE_BOTH)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -0800338 bank->enabled_non_wakeup_gpios |= gpio_bit;
339 else
340 bank->enabled_non_wakeup_gpios &= ~gpio_bit;
341 }
Kevin Hilman5eb3bb92007-05-05 11:40:29 -0700342
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530343exit:
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530344 bank->level_mask =
Victor Kamensky661553b2013-11-16 02:01:04 +0200345 readl_relaxed(bank->base + bank->regs->leveldetect0) |
346 readl_relaxed(bank->base + bank->regs->leveldetect1);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100347}
348
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800349#ifdef CONFIG_ARCH_OMAP1
Cory Maccarrone4318f362010-01-08 10:29:04 -0800350/*
351 * This only applies to chips that can't do both rising and falling edge
352 * detection at once. For all other chips, this function is a noop.
353 */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200354static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800355{
356 void __iomem *reg = bank->base;
357 u32 l = 0;
358
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530359 if (!bank->regs->irqctrl)
Cory Maccarrone4318f362010-01-08 10:29:04 -0800360 return;
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530361
362 reg += bank->regs->irqctrl;
Cory Maccarrone4318f362010-01-08 10:29:04 -0800363
Victor Kamensky661553b2013-11-16 02:01:04 +0200364 l = readl_relaxed(reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800365 if ((l >> gpio) & 1)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200366 l &= ~(BIT(gpio));
Cory Maccarrone4318f362010-01-08 10:29:04 -0800367 else
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200368 l |= BIT(gpio);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800369
Victor Kamensky661553b2013-11-16 02:01:04 +0200370 writel_relaxed(l, reg);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800371}
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530372#else
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200373static void omap_toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {}
Uwe Kleine-König9198bcd2010-01-29 14:20:05 -0800374#endif
Cory Maccarrone4318f362010-01-08 10:29:04 -0800375
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200376static int omap_set_gpio_triggering(struct gpio_bank *bank, int gpio,
377 unsigned trigger)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100378{
379 void __iomem *reg = bank->base;
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530380 void __iomem *base = bank->base;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100381 u32 l = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100382
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530383 if (bank->regs->leveldetect0 && bank->regs->wkup_en) {
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200384 omap_set_gpio_trigger(bank, gpio, trigger);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530385 } else if (bank->regs->irqctrl) {
386 reg += bank->regs->irqctrl;
387
Victor Kamensky661553b2013-11-16 02:01:04 +0200388 l = readl_relaxed(reg);
Janusz Krzysztofik29501572010-04-05 11:38:06 +0000389 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200390 bank->toggle_mask |= BIT(gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100391 if (trigger & IRQ_TYPE_EDGE_RISING)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200392 l |= BIT(gpio);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100393 else if (trigger & IRQ_TYPE_EDGE_FALLING)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200394 l &= ~(BIT(gpio));
Tony Lindgren92105bb2005-09-07 17:20:26 +0100395 else
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530396 return -EINVAL;
397
Victor Kamensky661553b2013-11-16 02:01:04 +0200398 writel_relaxed(l, reg);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530399 } else if (bank->regs->edgectrl1) {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100400 if (gpio & 0x08)
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530401 reg += bank->regs->edgectrl2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100402 else
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530403 reg += bank->regs->edgectrl1;
404
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100405 gpio &= 0x07;
Victor Kamensky661553b2013-11-16 02:01:04 +0200406 l = readl_relaxed(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100407 l &= ~(3 << (gpio << 1));
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100408 if (trigger & IRQ_TYPE_EDGE_RISING)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100409 l |= 2 << (gpio << 1);
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100410 if (trigger & IRQ_TYPE_EDGE_FALLING)
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200411 l |= BIT(gpio << 1);
Tarun Kanti DebBarma5e571f32011-09-13 15:02:14 +0530412
413 /* Enable wake-up during idle for dynamic tick */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200414 omap_gpio_rmw(base, bank->regs->wkup_en, BIT(gpio), trigger);
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +0530415 bank->context.wake_en =
Victor Kamensky661553b2013-11-16 02:01:04 +0200416 readl_relaxed(bank->base + bank->regs->wkup_en);
417 writel_relaxed(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100418 }
Tony Lindgren92105bb2005-09-07 17:20:26 +0100419 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100420}
421
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200422static void omap_enable_gpio_module(struct gpio_bank *bank, unsigned offset)
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200423{
424 if (bank->regs->pinctrl) {
425 void __iomem *reg = bank->base + bank->regs->pinctrl;
426
427 /* Claim the pin for MPU */
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200428 writel_relaxed(readl_relaxed(reg) | (BIT(offset)), reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200429 }
430
431 if (bank->regs->ctrl && !BANK_USED(bank)) {
432 void __iomem *reg = bank->base + bank->regs->ctrl;
433 u32 ctrl;
434
Victor Kamensky661553b2013-11-16 02:01:04 +0200435 ctrl = readl_relaxed(reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200436 /* Module is enabled, clocks are not gated */
437 ctrl &= ~GPIO_MOD_CTRL_BIT;
Victor Kamensky661553b2013-11-16 02:01:04 +0200438 writel_relaxed(ctrl, reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200439 bank->context.ctrl = ctrl;
440 }
441}
442
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200443static void omap_disable_gpio_module(struct gpio_bank *bank, unsigned offset)
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200444{
445 void __iomem *base = bank->base;
446
447 if (bank->regs->wkup_en &&
448 !LINE_USED(bank->mod_usage, offset) &&
449 !LINE_USED(bank->irq_usage, offset)) {
450 /* Disable wake-up during idle for dynamic tick */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200451 omap_gpio_rmw(base, bank->regs->wkup_en, BIT(offset), 0);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200452 bank->context.wake_en =
Victor Kamensky661553b2013-11-16 02:01:04 +0200453 readl_relaxed(bank->base + bank->regs->wkup_en);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200454 }
455
456 if (bank->regs->ctrl && !BANK_USED(bank)) {
457 void __iomem *reg = bank->base + bank->regs->ctrl;
458 u32 ctrl;
459
Victor Kamensky661553b2013-11-16 02:01:04 +0200460 ctrl = readl_relaxed(reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200461 /* Module is disabled, clocks are gated */
462 ctrl |= GPIO_MOD_CTRL_BIT;
Victor Kamensky661553b2013-11-16 02:01:04 +0200463 writel_relaxed(ctrl, reg);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200464 bank->context.ctrl = ctrl;
465 }
466}
467
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200468static int omap_gpio_is_input(struct gpio_bank *bank, unsigned offset)
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200469{
470 void __iomem *reg = bank->base + bank->regs->direction;
471
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200472 return readl_relaxed(reg) & BIT(offset);
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200473}
474
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200475static void omap_gpio_init_irq(struct gpio_bank *bank, unsigned offset)
Tony Lindgren3d009c82015-01-16 14:50:50 -0800476{
477 if (!LINE_USED(bank->mod_usage, offset)) {
478 omap_enable_gpio_module(bank, offset);
479 omap_set_gpio_direction(bank, offset, 1);
480 }
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200481 bank->irq_usage |= BIT(offset);
Tony Lindgren3d009c82015-01-16 14:50:50 -0800482}
483
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200484static int omap_gpio_irq_type(struct irq_data *d, unsigned type)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100485{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200486 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100487 int retval;
David Brownella6472532008-03-03 04:33:30 -0800488 unsigned long flags;
Grygorii Strashkoea5fbe82015-03-23 14:18:29 +0200489 unsigned offset = d->hwirq;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100490
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200491 if (!BANK_USED(bank))
492 pm_runtime_get_sync(bank->dev);
Jon Hunter8d4c2772013-03-01 11:22:48 -0600493
David Brownelle5c56ed2006-12-06 17:13:59 -0800494 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100495 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800496
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530497 if (!bank->regs->leveldetect0 &&
498 (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100499 return -EINVAL;
500
David Brownella6472532008-03-03 04:33:30 -0800501 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200502 retval = omap_set_gpio_triggering(bank, offset, type);
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200503 omap_gpio_init_irq(bank, offset);
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200504 if (!omap_gpio_is_input(bank, offset)) {
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200505 spin_unlock_irqrestore(&bank->lock, flags);
506 return -EINVAL;
507 }
David Brownella6472532008-03-03 04:33:30 -0800508 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800509
510 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100511 __irq_set_handler_locked(d->irq, handle_level_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800512 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100513 __irq_set_handler_locked(d->irq, handle_edge_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800514
Tony Lindgren92105bb2005-09-07 17:20:26 +0100515 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100516}
517
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200518static void omap_clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100519{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100520 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100521
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700522 reg += bank->regs->irqstatus;
Victor Kamensky661553b2013-11-16 02:01:04 +0200523 writel_relaxed(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300524
525 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700526 if (bank->regs->irqstatus2) {
527 reg = bank->base + bank->regs->irqstatus2;
Victor Kamensky661553b2013-11-16 02:01:04 +0200528 writel_relaxed(gpio_mask, reg);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700529 }
Roger Quadrosbedfd152009-04-23 11:10:50 -0700530
531 /* Flush posted write for the irq status to avoid spurious interrupts */
Victor Kamensky661553b2013-11-16 02:01:04 +0200532 readl_relaxed(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100533}
534
Grygorii Strashko9943f262015-03-23 14:18:27 +0200535static inline void omap_clear_gpio_irqstatus(struct gpio_bank *bank,
536 unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100537{
Grygorii Strashko9943f262015-03-23 14:18:27 +0200538 omap_clear_gpio_irqbank(bank, BIT(offset));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100539}
540
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200541static u32 omap_get_gpio_irqbank_mask(struct gpio_bank *bank)
Imre Deakea6dedd2006-06-26 16:16:00 -0700542{
543 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700544 u32 l;
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200545 u32 mask = (BIT(bank->width)) - 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700546
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700547 reg += bank->regs->irqenable;
Victor Kamensky661553b2013-11-16 02:01:04 +0200548 l = readl_relaxed(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700549 if (bank->regs->irqenable_inv)
Imre Deak99c47702006-06-26 16:16:07 -0700550 l = ~l;
551 l &= mask;
552 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700553}
554
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200555static void omap_enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100556{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100557 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100558 u32 l;
559
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700560 if (bank->regs->set_irqenable) {
561 reg += bank->regs->set_irqenable;
562 l = gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530563 bank->context.irqenable1 |= gpio_mask;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700564 } else {
565 reg += bank->regs->irqenable;
Victor Kamensky661553b2013-11-16 02:01:04 +0200566 l = readl_relaxed(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700567 if (bank->regs->irqenable_inv)
568 l &= ~gpio_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100569 else
570 l |= gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530571 bank->context.irqenable1 = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100572 }
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700573
Victor Kamensky661553b2013-11-16 02:01:04 +0200574 writel_relaxed(l, reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700575}
576
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200577static void omap_disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700578{
579 void __iomem *reg = bank->base;
580 u32 l;
581
582 if (bank->regs->clr_irqenable) {
583 reg += bank->regs->clr_irqenable;
584 l = gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530585 bank->context.irqenable1 &= ~gpio_mask;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700586 } else {
587 reg += bank->regs->irqenable;
Victor Kamensky661553b2013-11-16 02:01:04 +0200588 l = readl_relaxed(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700589 if (bank->regs->irqenable_inv)
590 l |= gpio_mask;
591 else
592 l &= ~gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530593 bank->context.irqenable1 = l;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700594 }
595
Victor Kamensky661553b2013-11-16 02:01:04 +0200596 writel_relaxed(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100597}
598
Grygorii Strashko9943f262015-03-23 14:18:27 +0200599static inline void omap_set_gpio_irqenable(struct gpio_bank *bank,
600 unsigned offset, int enable)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100601{
Tarun Kanti DebBarma8276536c2011-11-25 15:27:37 +0530602 if (enable)
Grygorii Strashko9943f262015-03-23 14:18:27 +0200603 omap_enable_gpio_irqbank(bank, BIT(offset));
Tarun Kanti DebBarma8276536c2011-11-25 15:27:37 +0530604 else
Grygorii Strashko9943f262015-03-23 14:18:27 +0200605 omap_disable_gpio_irqbank(bank, BIT(offset));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100606}
607
Tony Lindgren92105bb2005-09-07 17:20:26 +0100608/*
609 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
610 * 1510 does not seem to have a wake-up register. If JTAG is connected
611 * to the target, system will wake up always on GPIO events. While
612 * system is running all registered GPIO interrupts need to have wake-up
613 * enabled. When system is suspended, only selected GPIO interrupts need
614 * to have wake-up enabled.
615 */
Grygorii Strashko9943f262015-03-23 14:18:27 +0200616static int omap_set_gpio_wakeup(struct gpio_bank *bank, unsigned offset,
617 int enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100618{
Grygorii Strashko9943f262015-03-23 14:18:27 +0200619 u32 gpio_bit = BIT(offset);
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700620 unsigned long flags;
David Brownella6472532008-03-03 04:33:30 -0800621
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700622 if (bank->non_wakeup_gpios & gpio_bit) {
Benoit Cousson862ff642012-02-01 15:58:56 +0100623 dev_err(bank->dev,
Grygorii Strashko9943f262015-03-23 14:18:27 +0200624 "Unable to modify wakeup on non-wakeup GPIO%d\n",
625 offset);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100626 return -EINVAL;
627 }
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700628
629 spin_lock_irqsave(&bank->lock, flags);
630 if (enable)
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530631 bank->context.wake_en |= gpio_bit;
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700632 else
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530633 bank->context.wake_en &= ~gpio_bit;
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700634
Victor Kamensky661553b2013-11-16 02:01:04 +0200635 writel_relaxed(bank->context.wake_en, bank->base + bank->regs->wkup_en);
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700636 spin_unlock_irqrestore(&bank->lock, flags);
637
638 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100639}
640
Grygorii Strashko9943f262015-03-23 14:18:27 +0200641static void omap_reset_gpio(struct gpio_bank *bank, unsigned offset)
Tony Lindgren4196dd62006-09-25 12:41:38 +0300642{
Grygorii Strashko9943f262015-03-23 14:18:27 +0200643 omap_set_gpio_direction(bank, offset, 1);
644 omap_set_gpio_irqenable(bank, offset, 0);
645 omap_clear_gpio_irqstatus(bank, offset);
646 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
647 omap_clear_gpio_debounce(bank, offset);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300648}
649
Tony Lindgren92105bb2005-09-07 17:20:26 +0100650/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200651static int omap_gpio_wake_enable(struct irq_data *d, unsigned int enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100652{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200653 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200654 unsigned offset = d->hwirq;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100655
Grygorii Strashko9943f262015-03-23 14:18:27 +0200656 return omap_set_gpio_wakeup(bank, offset, enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100657}
658
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800659static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100660{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800661 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800662 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100663
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530664 /*
665 * If this is the first gpio_request for the bank,
666 * enable the bank module.
667 */
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200668 if (!BANK_USED(bank))
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530669 pm_runtime_get_sync(bank->dev);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100670
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530671 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300672 /* Set trigger to none. You need to enable the desired trigger with
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200673 * request_irq() or set_irq_type(). Only do this if the IRQ line has
674 * not already been requested.
Tony Lindgren4196dd62006-09-25 12:41:38 +0300675 */
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200676 if (!LINE_USED(bank->irq_usage, offset)) {
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200677 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
678 omap_enable_gpio_module(bank, offset);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100679 }
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200680 bank->mod_usage |= BIT(offset);
David Brownella6472532008-03-03 04:33:30 -0800681 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100682
683 return 0;
684}
685
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800686static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100687{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800688 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800689 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100690
David Brownella6472532008-03-03 04:33:30 -0800691 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200692 bank->mod_usage &= ~(BIT(offset));
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200693 omap_disable_gpio_module(bank, offset);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200694 omap_reset_gpio(bank, offset);
David Brownella6472532008-03-03 04:33:30 -0800695 spin_unlock_irqrestore(&bank->lock, flags);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530696
697 /*
698 * If this is the last gpio to be freed in the bank,
699 * disable the bank module.
700 */
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200701 if (!BANK_USED(bank))
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530702 pm_runtime_put(bank->dev);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100703}
704
705/*
706 * We need to unmask the GPIO bank interrupt as soon as possible to
707 * avoid missing GPIO interrupts for other lines in the bank.
708 * Then we need to mask-read-clear-unmask the triggered GPIO lines
709 * in the bank to avoid missing nested interrupts for a GPIO line.
710 * If we wait to unmask individual GPIO lines in the bank after the
711 * line's interrupt handler has been run, we may miss some nested
712 * interrupts.
713 */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200714static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100715{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100716 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100717 u32 isr;
Jon Hunter3513cde2013-04-04 15:16:14 -0500718 unsigned int bit;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100719 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -0700720 int unmasked = 0;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200721 struct irq_chip *irqchip = irq_desc_get_chip(desc);
722 struct gpio_chip *chip = irq_get_handler_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100723
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200724 chained_irq_enter(irqchip, desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100725
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200726 bank = container_of(chip, struct gpio_bank, chip);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700727 isr_reg = bank->base + bank->regs->irqstatus;
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530728 pm_runtime_get_sync(bank->dev);
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800729
730 if (WARN_ON(!isr_reg))
731 goto exit;
732
Laurent Navete83507b2013-03-20 13:15:57 +0100733 while (1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +0100734 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -0700735 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100736
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200737 enabled = omap_get_gpio_irqbank_mask(bank);
Victor Kamensky661553b2013-11-16 02:01:04 +0200738 isr_saved = isr = readl_relaxed(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100739
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530740 if (bank->level_mask)
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800741 level_mask = bank->level_mask & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100742
743 /* clear edge sensitive interrupts before handler(s) are
744 called so that we don't miss any interrupt occurred while
745 executing them */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200746 omap_disable_gpio_irqbank(bank, isr_saved & ~level_mask);
747 omap_clear_gpio_irqbank(bank, isr_saved & ~level_mask);
748 omap_enable_gpio_irqbank(bank, isr_saved & ~level_mask);
Tony Lindgren6e60e792006-04-02 17:46:23 +0100749
750 /* if there is only edge sensitive GPIO pin interrupts
751 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -0700752 if (!level_mask && !unmasked) {
753 unmasked = 1;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200754 chained_irq_exit(irqchip, desc);
Imre Deakea6dedd2006-06-26 16:16:00 -0700755 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100756
Tony Lindgren92105bb2005-09-07 17:20:26 +0100757 if (!isr)
758 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100759
Jon Hunter3513cde2013-04-04 15:16:14 -0500760 while (isr) {
761 bit = __ffs(isr);
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200762 isr &= ~(BIT(bit));
Benoit Cousson25db7112012-02-23 21:50:10 +0100763
Cory Maccarrone4318f362010-01-08 10:29:04 -0800764 /*
765 * Some chips can't respond to both rising and falling
766 * at the same time. If this irq was requested with
767 * both flags, we need to flip the ICR data for the IRQ
768 * to respond to the IRQ for the opposite direction.
769 * This will be indicated in the bank toggle_mask.
770 */
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200771 if (bank->toggle_mask & (BIT(bit)))
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200772 omap_toggle_gpio_edge_triggering(bank, bit);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800773
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200774 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain,
775 bit));
Tony Lindgren92105bb2005-09-07 17:20:26 +0100776 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000777 }
Imre Deakea6dedd2006-06-26 16:16:00 -0700778 /* if bank has any level sensitive GPIO pin interrupt
779 configured, we must unmask the bank interrupt only after
780 handler(s) are executed in order to avoid spurious bank
781 interrupt */
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800782exit:
Imre Deakea6dedd2006-06-26 16:16:00 -0700783 if (!unmasked)
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200784 chained_irq_exit(irqchip, desc);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530785 pm_runtime_put(bank->dev);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100786}
787
Tony Lindgren3d009c82015-01-16 14:50:50 -0800788static unsigned int omap_gpio_irq_startup(struct irq_data *d)
789{
790 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Tony Lindgren3d009c82015-01-16 14:50:50 -0800791 unsigned long flags;
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200792 unsigned offset = d->hwirq;
Tony Lindgren3d009c82015-01-16 14:50:50 -0800793
794 if (!BANK_USED(bank))
795 pm_runtime_get_sync(bank->dev);
796
797 spin_lock_irqsave(&bank->lock, flags);
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200798 omap_gpio_init_irq(bank, offset);
Tony Lindgren3d009c82015-01-16 14:50:50 -0800799 spin_unlock_irqrestore(&bank->lock, flags);
800 omap_gpio_unmask_irq(d);
801
802 return 0;
803}
804
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200805static void omap_gpio_irq_shutdown(struct irq_data *d)
Tony Lindgren4196dd62006-09-25 12:41:38 +0300806{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200807 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700808 unsigned long flags;
Grygorii Strashko9943f262015-03-23 14:18:27 +0200809 unsigned offset = d->hwirq;
Tony Lindgren4196dd62006-09-25 12:41:38 +0300810
Colin Cross85ec7b92011-06-06 13:38:18 -0700811 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200812 bank->irq_usage &= ~(BIT(offset));
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200813 omap_disable_gpio_module(bank, offset);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200814 omap_reset_gpio(bank, offset);
Colin Cross85ec7b92011-06-06 13:38:18 -0700815 spin_unlock_irqrestore(&bank->lock, flags);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200816
817 /*
818 * If this is the last IRQ to be freed in the bank,
819 * disable the bank module.
820 */
821 if (!BANK_USED(bank))
822 pm_runtime_put(bank->dev);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300823}
824
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200825static void omap_gpio_ack_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100826{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200827 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200828 unsigned offset = d->hwirq;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100829
Grygorii Strashko9943f262015-03-23 14:18:27 +0200830 omap_clear_gpio_irqstatus(bank, offset);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100831}
832
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200833static void omap_gpio_mask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100834{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200835 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200836 unsigned offset = d->hwirq;
Colin Cross85ec7b92011-06-06 13:38:18 -0700837 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100838
Colin Cross85ec7b92011-06-06 13:38:18 -0700839 spin_lock_irqsave(&bank->lock, flags);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200840 omap_set_gpio_irqenable(bank, offset, 0);
841 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Colin Cross85ec7b92011-06-06 13:38:18 -0700842 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100843}
844
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200845static void omap_gpio_unmask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100846{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200847 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200848 unsigned offset = d->hwirq;
Thomas Gleixner8c04a172011-03-24 12:40:15 +0100849 u32 trigger = irqd_get_trigger_type(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700850 unsigned long flags;
Kevin Hilman55b60192009-06-04 15:57:10 -0700851
Colin Cross85ec7b92011-06-06 13:38:18 -0700852 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman55b60192009-06-04 15:57:10 -0700853 if (trigger)
Grygorii Strashko9943f262015-03-23 14:18:27 +0200854 omap_set_gpio_triggering(bank, offset, trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800855
856 /* For level-triggered GPIOs, the clearing must be done after
857 * the HW source is cleared, thus after the handler has run */
Grygorii Strashko9943f262015-03-23 14:18:27 +0200858 if (bank->level_mask & BIT(offset)) {
859 omap_set_gpio_irqenable(bank, offset, 0);
860 omap_clear_gpio_irqstatus(bank, offset);
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800861 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100862
Grygorii Strashko9943f262015-03-23 14:18:27 +0200863 omap_set_gpio_irqenable(bank, offset, 1);
Colin Cross85ec7b92011-06-06 13:38:18 -0700864 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100865}
866
David Brownelle5c56ed2006-12-06 17:13:59 -0800867/*---------------------------------------------------------------------*/
868
Magnus Damm79ee0312009-07-08 13:22:04 +0200869static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800870{
Magnus Damm79ee0312009-07-08 13:22:04 +0200871 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800872 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800873 void __iomem *mask_reg = bank->base +
874 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800875 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800876
David Brownella6472532008-03-03 04:33:30 -0800877 spin_lock_irqsave(&bank->lock, flags);
Victor Kamensky661553b2013-11-16 02:01:04 +0200878 writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800879 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800880
881 return 0;
882}
883
Magnus Damm79ee0312009-07-08 13:22:04 +0200884static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800885{
Magnus Damm79ee0312009-07-08 13:22:04 +0200886 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800887 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800888 void __iomem *mask_reg = bank->base +
889 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800890 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800891
David Brownella6472532008-03-03 04:33:30 -0800892 spin_lock_irqsave(&bank->lock, flags);
Victor Kamensky661553b2013-11-16 02:01:04 +0200893 writel_relaxed(bank->context.wake_en, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800894 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800895
896 return 0;
897}
898
Alexey Dobriyan47145212009-12-14 18:00:08 -0800899static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +0200900 .suspend_noirq = omap_mpuio_suspend_noirq,
901 .resume_noirq = omap_mpuio_resume_noirq,
902};
903
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +0200904/* use platform_driver for this. */
David Brownell11a78b72006-12-06 17:14:11 -0800905static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -0800906 .driver = {
907 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +0200908 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -0800909 },
910};
911
912static struct platform_device omap_mpuio_device = {
913 .name = "mpuio",
914 .id = -1,
915 .dev = {
916 .driver = &omap_mpuio_driver.driver,
917 }
918 /* could list the /proc/iomem resources */
919};
920
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200921static inline void omap_mpuio_init(struct gpio_bank *bank)
David Brownell11a78b72006-12-06 17:14:11 -0800922{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800923 platform_set_drvdata(&omap_mpuio_device, bank);
David Brownellfcf126d2007-04-02 12:46:47 -0700924
David Brownell11a78b72006-12-06 17:14:11 -0800925 if (platform_driver_register(&omap_mpuio_driver) == 0)
926 (void) platform_device_register(&omap_mpuio_device);
927}
928
David Brownelle5c56ed2006-12-06 17:13:59 -0800929/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100930
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200931static int omap_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
Yegor Yefremov93700842014-04-24 08:57:39 +0200932{
933 struct gpio_bank *bank;
934 unsigned long flags;
935 void __iomem *reg;
936 int dir;
937
938 bank = container_of(chip, struct gpio_bank, chip);
939 reg = bank->base + bank->regs->direction;
940 spin_lock_irqsave(&bank->lock, flags);
941 dir = !!(readl_relaxed(reg) & BIT(offset));
942 spin_unlock_irqrestore(&bank->lock, flags);
943 return dir;
944}
945
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200946static int omap_gpio_input(struct gpio_chip *chip, unsigned offset)
David Brownell52e31342008-03-03 12:43:23 -0800947{
948 struct gpio_bank *bank;
949 unsigned long flags;
950
951 bank = container_of(chip, struct gpio_bank, chip);
952 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200953 omap_set_gpio_direction(bank, offset, 1);
David Brownell52e31342008-03-03 12:43:23 -0800954 spin_unlock_irqrestore(&bank->lock, flags);
955 return 0;
956}
957
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200958static int omap_gpio_get(struct gpio_chip *chip, unsigned offset)
David Brownell52e31342008-03-03 12:43:23 -0800959{
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300960 struct gpio_bank *bank;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300961
Charulatha Va8be8da2011-04-22 16:38:16 +0530962 bank = container_of(chip, struct gpio_bank, chip);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300963
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200964 if (omap_gpio_is_input(bank, offset))
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200965 return omap_get_gpio_datain(bank, offset);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300966 else
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200967 return omap_get_gpio_dataout(bank, offset);
David Brownell52e31342008-03-03 12:43:23 -0800968}
969
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200970static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value)
David Brownell52e31342008-03-03 12:43:23 -0800971{
972 struct gpio_bank *bank;
973 unsigned long flags;
974
975 bank = container_of(chip, struct gpio_bank, chip);
976 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700977 bank->set_dataout(bank, offset, value);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200978 omap_set_gpio_direction(bank, offset, 0);
David Brownell52e31342008-03-03 12:43:23 -0800979 spin_unlock_irqrestore(&bank->lock, flags);
Javier Martinez Canillas2f56e0a2013-10-16 02:47:30 +0200980 return 0;
David Brownell52e31342008-03-03 12:43:23 -0800981}
982
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200983static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset,
984 unsigned debounce)
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700985{
986 struct gpio_bank *bank;
987 unsigned long flags;
988
989 bank = container_of(chip, struct gpio_bank, chip);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800990
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700991 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200992 omap2_set_gpio_debounce(bank, offset, debounce);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700993 spin_unlock_irqrestore(&bank->lock, flags);
994
995 return 0;
996}
997
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200998static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
David Brownell52e31342008-03-03 12:43:23 -0800999{
1000 struct gpio_bank *bank;
1001 unsigned long flags;
1002
1003 bank = container_of(chip, struct gpio_bank, chip);
1004 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001005 bank->set_dataout(bank, offset, value);
David Brownell52e31342008-03-03 12:43:23 -08001006 spin_unlock_irqrestore(&bank->lock, flags);
1007}
1008
1009/*---------------------------------------------------------------------*/
1010
Tony Lindgren9a748052010-12-07 16:26:56 -08001011static void __init omap_gpio_show_rev(struct gpio_bank *bank)
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001012{
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001013 static bool called;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001014 u32 rev;
1015
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001016 if (called || bank->regs->revision == USHRT_MAX)
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001017 return;
1018
Victor Kamensky661553b2013-11-16 02:01:04 +02001019 rev = readw_relaxed(bank->base + bank->regs->revision);
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001020 pr_info("OMAP GPIO hardware version %d.%d\n",
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001021 (rev >> 4) & 0x0f, rev & 0x0f);
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001022
1023 called = true;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001024}
1025
Charulatha V03e128c2011-05-05 19:58:01 +05301026static void omap_gpio_mod_init(struct gpio_bank *bank)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001027{
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301028 void __iomem *base = bank->base;
1029 u32 l = 0xffffffff;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001030
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301031 if (bank->width == 16)
1032 l = 0xffff;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001033
Charulatha Vd0d665a2011-08-31 00:02:21 +05301034 if (bank->is_mpuio) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001035 writel_relaxed(l, bank->base + bank->regs->irqenable);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301036 return;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001037 }
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301038
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001039 omap_gpio_rmw(base, bank->regs->irqenable, l,
1040 bank->regs->irqenable_inv);
1041 omap_gpio_rmw(base, bank->regs->irqstatus, l,
1042 !bank->regs->irqenable_inv);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301043 if (bank->regs->debounce_en)
Victor Kamensky661553b2013-11-16 02:01:04 +02001044 writel_relaxed(0, base + bank->regs->debounce_en);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301045
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301046 /* Save OE default value (0xffffffff) in the context */
Victor Kamensky661553b2013-11-16 02:01:04 +02001047 bank->context.oe = readl_relaxed(bank->base + bank->regs->direction);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301048 /* Initialize interface clk ungated, module enabled */
1049 if (bank->regs->ctrl)
Victor Kamensky661553b2013-11-16 02:01:04 +02001050 writel_relaxed(0, base + bank->regs->ctrl);
Tarun Kanti DebBarma34672012012-07-11 14:43:14 +05301051
1052 bank->dbck = clk_get(bank->dev, "dbclk");
1053 if (IS_ERR(bank->dbck))
1054 dev_err(bank->dev, "Could not get gpio dbck\n");
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001055}
1056
Nishanth Menon46824e222014-09-05 14:52:55 -05001057static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001058{
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001059 static int gpio;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001060 int irq_base = 0;
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001061 int ret;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001062
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001063 /*
1064 * REVISIT eventually switch from OMAP-specific gpio structs
1065 * over to the generic ones
1066 */
1067 bank->chip.request = omap_gpio_request;
1068 bank->chip.free = omap_gpio_free;
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001069 bank->chip.get_direction = omap_gpio_get_direction;
1070 bank->chip.direction_input = omap_gpio_input;
1071 bank->chip.get = omap_gpio_get;
1072 bank->chip.direction_output = omap_gpio_output;
1073 bank->chip.set_debounce = omap_gpio_debounce;
1074 bank->chip.set = omap_gpio_set;
Charulatha Vd0d665a2011-08-31 00:02:21 +05301075 if (bank->is_mpuio) {
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001076 bank->chip.label = "mpuio";
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301077 if (bank->regs->wkup_en)
1078 bank->chip.dev = &omap_mpuio_device.dev;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001079 bank->chip.base = OMAP_MPUIO(0);
1080 } else {
1081 bank->chip.label = "gpio";
1082 bank->chip.base = gpio;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001083 gpio += bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001084 }
Kevin Hilmand5f46242011-04-21 09:23:00 -07001085 bank->chip.ngpio = bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001086
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001087 ret = gpiochip_add(&bank->chip);
1088 if (ret) {
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001089 dev_err(bank->dev, "Could not register gpio chip %d\n", ret);
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001090 return ret;
1091 }
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001092
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001093#ifdef CONFIG_ARCH_OMAP1
1094 /*
1095 * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop
1096 * irq_alloc_descs() since a base IRQ offset will no longer be needed.
1097 */
1098 irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
1099 if (irq_base < 0) {
1100 dev_err(bank->dev, "Couldn't allocate IRQ numbers\n");
1101 return -ENODEV;
1102 }
1103#endif
1104
Tony Lindgrend2d05c62015-04-23 16:54:17 -07001105 /* MPUIO is a bit different, reading IRQ status clears it */
1106 if (bank->is_mpuio) {
1107 irqc->irq_ack = dummy_irq_chip.irq_ack;
1108 irqc->irq_mask = irq_gc_mask_set_bit;
1109 irqc->irq_unmask = irq_gc_mask_clr_bit;
1110 if (!bank->regs->wkup_en)
1111 irqc->irq_set_wake = NULL;
1112 }
1113
Nishanth Menon46824e222014-09-05 14:52:55 -05001114 ret = gpiochip_irqchip_add(&bank->chip, irqc,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001115 irq_base, omap_gpio_irq_handler,
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001116 IRQ_TYPE_NONE);
1117
1118 if (ret) {
1119 dev_err(bank->dev, "Couldn't add irqchip to gpiochip %d\n", ret);
Linus Walleijda26d5d2014-09-16 15:11:41 -07001120 gpiochip_remove(&bank->chip);
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001121 return -ENODEV;
1122 }
1123
Nishanth Menon46824e222014-09-05 14:52:55 -05001124 gpiochip_set_chained_irqchip(&bank->chip, irqc,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001125 bank->irq, omap_gpio_irq_handler);
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001126
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001127 return 0;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001128}
1129
Benoit Cousson384ebe12011-08-16 11:53:02 +02001130static const struct of_device_id omap_gpio_match[];
1131
Bill Pemberton38363092012-11-19 13:22:34 -05001132static int omap_gpio_probe(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001133{
Benoit Cousson862ff642012-02-01 15:58:56 +01001134 struct device *dev = &pdev->dev;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001135 struct device_node *node = dev->of_node;
1136 const struct of_device_id *match;
Uwe Kleine-Königf6817a22012-05-21 21:57:39 +02001137 const struct omap_gpio_platform_data *pdata;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001138 struct resource *res;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001139 struct gpio_bank *bank;
Nishanth Menon46824e222014-09-05 14:52:55 -05001140 struct irq_chip *irqc;
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001141 int ret;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001142
Benoit Cousson384ebe12011-08-16 11:53:02 +02001143 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
1144
Jingoo Hane56aee12013-07-30 17:08:05 +09001145 pdata = match ? match->data : dev_get_platdata(dev);
Benoit Cousson384ebe12011-08-16 11:53:02 +02001146 if (!pdata)
Benoit Cousson96751fc2012-02-01 16:01:39 +01001147 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001148
Tobias Klauser086d5852012-10-05 11:37:38 +02001149 bank = devm_kzalloc(dev, sizeof(struct gpio_bank), GFP_KERNEL);
Charulatha V03e128c2011-05-05 19:58:01 +05301150 if (!bank) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001151 dev_err(dev, "Memory alloc failed\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001152 return -ENOMEM;
Charulatha V03e128c2011-05-05 19:58:01 +05301153 }
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001154
Nishanth Menon46824e222014-09-05 14:52:55 -05001155 irqc = devm_kzalloc(dev, sizeof(*irqc), GFP_KERNEL);
1156 if (!irqc)
1157 return -ENOMEM;
1158
Tony Lindgren3d009c82015-01-16 14:50:50 -08001159 irqc->irq_startup = omap_gpio_irq_startup,
Nishanth Menon46824e222014-09-05 14:52:55 -05001160 irqc->irq_shutdown = omap_gpio_irq_shutdown,
1161 irqc->irq_ack = omap_gpio_ack_irq,
1162 irqc->irq_mask = omap_gpio_mask_irq,
1163 irqc->irq_unmask = omap_gpio_unmask_irq,
1164 irqc->irq_set_type = omap_gpio_irq_type,
1165 irqc->irq_set_wake = omap_gpio_wake_enable,
1166 irqc->name = dev_name(&pdev->dev);
1167
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001168 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1169 if (unlikely(!res)) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001170 dev_err(dev, "Invalid IRQ resource\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001171 return -ENODEV;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001172 }
1173
1174 bank->irq = res->start;
Benoit Cousson862ff642012-02-01 15:58:56 +01001175 bank->dev = dev;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001176 bank->chip.dev = dev;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001177 bank->dbck_flag = pdata->dbck_flag;
Tony Lindgren5de62b82010-12-07 16:26:58 -08001178 bank->stride = pdata->bank_stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001179 bank->width = pdata->bank_width;
Charulatha Vd0d665a2011-08-31 00:02:21 +05301180 bank->is_mpuio = pdata->is_mpuio;
Charulatha V803a2432011-05-05 17:04:12 +05301181 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001182 bank->regs = pdata->regs;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001183#ifdef CONFIG_OF_GPIO
1184 bank->chip.of_node = of_node_get(node);
1185#endif
Jon Huntera2797be2013-04-04 15:16:15 -05001186 if (node) {
1187 if (!of_property_read_bool(node, "ti,gpio-always-on"))
1188 bank->loses_context = true;
1189 } else {
1190 bank->loses_context = pdata->loses_context;
Jon Hunter352a2d52013-04-15 13:06:54 -05001191
1192 if (bank->loses_context)
1193 bank->get_context_loss_count =
1194 pdata->get_context_loss_count;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001195 }
1196
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001197 if (bank->regs->set_dataout && bank->regs->clr_dataout)
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001198 bank->set_dataout = omap_set_gpio_dataout_reg;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001199 else
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001200 bank->set_dataout = omap_set_gpio_dataout_mask;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001201
1202 spin_lock_init(&bank->lock);
1203
1204 /* Static mapping, never released */
1205 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Jingoo Han717f70e2014-02-12 11:51:38 +09001206 bank->base = devm_ioremap_resource(dev, res);
1207 if (IS_ERR(bank->base)) {
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001208 irq_domain_remove(bank->chip.irqdomain);
Jingoo Han717f70e2014-02-12 11:51:38 +09001209 return PTR_ERR(bank->base);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001210 }
1211
Tarun Kanti DebBarma065cd792011-11-24 01:48:52 +05301212 platform_set_drvdata(pdev, bank);
1213
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001214 pm_runtime_enable(bank->dev);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301215 pm_runtime_irq_safe(bank->dev);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001216 pm_runtime_get_sync(bank->dev);
1217
Charulatha Vd0d665a2011-08-31 00:02:21 +05301218 if (bank->is_mpuio)
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001219 omap_mpuio_init(bank);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301220
Charulatha V03e128c2011-05-05 19:58:01 +05301221 omap_gpio_mod_init(bank);
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001222
Nishanth Menon46824e222014-09-05 14:52:55 -05001223 ret = omap_gpio_chip_init(bank, irqc);
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001224 if (ret)
1225 return ret;
1226
Tony Lindgren9a748052010-12-07 16:26:56 -08001227 omap_gpio_show_rev(bank);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001228
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301229 pm_runtime_put(bank->dev);
1230
Charulatha V03e128c2011-05-05 19:58:01 +05301231 list_add_tail(&bank->node, &omap_gpio_list);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001232
Jon Hunter879fe322013-04-04 15:16:12 -05001233 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001234}
1235
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301236#ifdef CONFIG_ARCH_OMAP2PLUS
1237
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001238#if defined(CONFIG_PM)
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301239static void omap_gpio_restore_context(struct gpio_bank *bank);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001240
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301241static int omap_gpio_runtime_suspend(struct device *dev)
1242{
1243 struct platform_device *pdev = to_platform_device(dev);
1244 struct gpio_bank *bank = platform_get_drvdata(pdev);
1245 u32 l1 = 0, l2 = 0;
1246 unsigned long flags;
Kevin Hilman68942ed2012-03-05 15:10:04 -08001247 u32 wake_low, wake_hi;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301248
1249 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman68942ed2012-03-05 15:10:04 -08001250
1251 /*
1252 * Only edges can generate a wakeup event to the PRCM.
1253 *
1254 * Therefore, ensure any wake-up capable GPIOs have
1255 * edge-detection enabled before going idle to ensure a wakeup
1256 * to the PRCM is generated on a GPIO transition. (c.f. 34xx
1257 * NDA TRM 25.5.3.1)
1258 *
1259 * The normal values will be restored upon ->runtime_resume()
1260 * by writing back the values saved in bank->context.
1261 */
1262 wake_low = bank->context.leveldetect0 & bank->context.wake_en;
1263 if (wake_low)
Victor Kamensky661553b2013-11-16 02:01:04 +02001264 writel_relaxed(wake_low | bank->context.fallingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001265 bank->base + bank->regs->fallingdetect);
1266 wake_hi = bank->context.leveldetect1 & bank->context.wake_en;
1267 if (wake_hi)
Victor Kamensky661553b2013-11-16 02:01:04 +02001268 writel_relaxed(wake_hi | bank->context.risingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001269 bank->base + bank->regs->risingdetect);
1270
Kevin Hilmanb3c64bc2012-05-17 16:42:16 -07001271 if (!bank->enabled_non_wakeup_gpios)
1272 goto update_gpio_context_count;
1273
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301274 if (bank->power_mode != OFF_MODE) {
1275 bank->power_mode = 0;
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +05301276 goto update_gpio_context_count;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301277 }
1278 /*
1279 * If going to OFF, remove triggering for all
1280 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1281 * generated. See OMAP2420 Errata item 1.101.
1282 */
Victor Kamensky661553b2013-11-16 02:01:04 +02001283 bank->saved_datain = readl_relaxed(bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301284 bank->regs->datain);
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301285 l1 = bank->context.fallingdetect;
1286 l2 = bank->context.risingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301287
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301288 l1 &= ~bank->enabled_non_wakeup_gpios;
1289 l2 &= ~bank->enabled_non_wakeup_gpios;
1290
Victor Kamensky661553b2013-11-16 02:01:04 +02001291 writel_relaxed(l1, bank->base + bank->regs->fallingdetect);
1292 writel_relaxed(l2, bank->base + bank->regs->risingdetect);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301293
1294 bank->workaround_enabled = true;
1295
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +05301296update_gpio_context_count:
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301297 if (bank->get_context_loss_count)
1298 bank->context_loss_count =
1299 bank->get_context_loss_count(bank->dev);
1300
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001301 omap_gpio_dbck_disable(bank);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301302 spin_unlock_irqrestore(&bank->lock, flags);
1303
1304 return 0;
1305}
1306
Jon Hunter352a2d52013-04-15 13:06:54 -05001307static void omap_gpio_init_context(struct gpio_bank *p);
1308
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301309static int omap_gpio_runtime_resume(struct device *dev)
1310{
1311 struct platform_device *pdev = to_platform_device(dev);
1312 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301313 u32 l = 0, gen, gen0, gen1;
1314 unsigned long flags;
Jon Huntera2797be2013-04-04 15:16:15 -05001315 int c;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301316
1317 spin_lock_irqsave(&bank->lock, flags);
Jon Hunter352a2d52013-04-15 13:06:54 -05001318
1319 /*
1320 * On the first resume during the probe, the context has not
1321 * been initialised and so initialise it now. Also initialise
1322 * the context loss count.
1323 */
1324 if (bank->loses_context && !bank->context_valid) {
1325 omap_gpio_init_context(bank);
1326
1327 if (bank->get_context_loss_count)
1328 bank->context_loss_count =
1329 bank->get_context_loss_count(bank->dev);
1330 }
1331
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001332 omap_gpio_dbck_enable(bank);
Kevin Hilman68942ed2012-03-05 15:10:04 -08001333
1334 /*
1335 * In ->runtime_suspend(), level-triggered, wakeup-enabled
1336 * GPIOs were set to edge trigger also in order to be able to
1337 * generate a PRCM wakeup. Here we restore the
1338 * pre-runtime_suspend() values for edge triggering.
1339 */
Victor Kamensky661553b2013-11-16 02:01:04 +02001340 writel_relaxed(bank->context.fallingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001341 bank->base + bank->regs->fallingdetect);
Victor Kamensky661553b2013-11-16 02:01:04 +02001342 writel_relaxed(bank->context.risingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001343 bank->base + bank->regs->risingdetect);
1344
Jon Huntera2797be2013-04-04 15:16:15 -05001345 if (bank->loses_context) {
1346 if (!bank->get_context_loss_count) {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301347 omap_gpio_restore_context(bank);
1348 } else {
Jon Huntera2797be2013-04-04 15:16:15 -05001349 c = bank->get_context_loss_count(bank->dev);
1350 if (c != bank->context_loss_count) {
1351 omap_gpio_restore_context(bank);
1352 } else {
1353 spin_unlock_irqrestore(&bank->lock, flags);
1354 return 0;
1355 }
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301356 }
1357 }
1358
Tarun Kanti DebBarma1b1287032012-04-27 19:43:38 +05301359 if (!bank->workaround_enabled) {
1360 spin_unlock_irqrestore(&bank->lock, flags);
1361 return 0;
1362 }
1363
Victor Kamensky661553b2013-11-16 02:01:04 +02001364 l = readl_relaxed(bank->base + bank->regs->datain);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301365
1366 /*
1367 * Check if any of the non-wakeup interrupt GPIOs have changed
1368 * state. If so, generate an IRQ by software. This is
1369 * horribly racy, but it's the best we can do to work around
1370 * this silicon bug.
1371 */
1372 l ^= bank->saved_datain;
1373 l &= bank->enabled_non_wakeup_gpios;
1374
1375 /*
1376 * No need to generate IRQs for the rising edge for gpio IRQs
1377 * configured with falling edge only; and vice versa.
1378 */
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301379 gen0 = l & bank->context.fallingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301380 gen0 &= bank->saved_datain;
1381
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301382 gen1 = l & bank->context.risingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301383 gen1 &= ~(bank->saved_datain);
1384
1385 /* FIXME: Consider GPIO IRQs with level detections properly! */
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301386 gen = l & (~(bank->context.fallingdetect) &
1387 ~(bank->context.risingdetect));
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301388 /* Consider all GPIO IRQs needed to be updated */
1389 gen |= gen0 | gen1;
1390
1391 if (gen) {
1392 u32 old0, old1;
1393
Victor Kamensky661553b2013-11-16 02:01:04 +02001394 old0 = readl_relaxed(bank->base + bank->regs->leveldetect0);
1395 old1 = readl_relaxed(bank->base + bank->regs->leveldetect1);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301396
Tarun Kanti DebBarma4e962e82012-04-27 19:43:37 +05301397 if (!bank->regs->irqstatus_raw0) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001398 writel_relaxed(old0 | gen, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301399 bank->regs->leveldetect0);
Victor Kamensky661553b2013-11-16 02:01:04 +02001400 writel_relaxed(old1 | gen, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301401 bank->regs->leveldetect1);
1402 }
1403
Tarun Kanti DebBarma4e962e82012-04-27 19:43:37 +05301404 if (bank->regs->irqstatus_raw0) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001405 writel_relaxed(old0 | l, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301406 bank->regs->leveldetect0);
Victor Kamensky661553b2013-11-16 02:01:04 +02001407 writel_relaxed(old1 | l, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301408 bank->regs->leveldetect1);
1409 }
Victor Kamensky661553b2013-11-16 02:01:04 +02001410 writel_relaxed(old0, bank->base + bank->regs->leveldetect0);
1411 writel_relaxed(old1, bank->base + bank->regs->leveldetect1);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301412 }
1413
1414 bank->workaround_enabled = false;
1415 spin_unlock_irqrestore(&bank->lock, flags);
1416
1417 return 0;
1418}
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001419#endif /* CONFIG_PM */
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301420
1421void omap2_gpio_prepare_for_idle(int pwr_mode)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001422{
Charulatha V03e128c2011-05-05 19:58:01 +05301423 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001424
Charulatha V03e128c2011-05-05 19:58:01 +05301425 list_for_each_entry(bank, &omap_gpio_list, node) {
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +02001426 if (!BANK_USED(bank) || !bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301427 continue;
1428
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301429 bank->power_mode = pwr_mode;
1430
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301431 pm_runtime_put_sync_suspend(bank->dev);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001432 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001433}
1434
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001435void omap2_gpio_resume_after_idle(void)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001436{
Charulatha V03e128c2011-05-05 19:58:01 +05301437 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001438
Charulatha V03e128c2011-05-05 19:58:01 +05301439 list_for_each_entry(bank, &omap_gpio_list, node) {
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +02001440 if (!BANK_USED(bank) || !bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301441 continue;
1442
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301443 pm_runtime_get_sync(bank->dev);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001444 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001445}
1446
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001447#if defined(CONFIG_PM)
Jon Hunter352a2d52013-04-15 13:06:54 -05001448static void omap_gpio_init_context(struct gpio_bank *p)
1449{
1450 struct omap_gpio_reg_offs *regs = p->regs;
1451 void __iomem *base = p->base;
1452
Victor Kamensky661553b2013-11-16 02:01:04 +02001453 p->context.ctrl = readl_relaxed(base + regs->ctrl);
1454 p->context.oe = readl_relaxed(base + regs->direction);
1455 p->context.wake_en = readl_relaxed(base + regs->wkup_en);
1456 p->context.leveldetect0 = readl_relaxed(base + regs->leveldetect0);
1457 p->context.leveldetect1 = readl_relaxed(base + regs->leveldetect1);
1458 p->context.risingdetect = readl_relaxed(base + regs->risingdetect);
1459 p->context.fallingdetect = readl_relaxed(base + regs->fallingdetect);
1460 p->context.irqenable1 = readl_relaxed(base + regs->irqenable);
1461 p->context.irqenable2 = readl_relaxed(base + regs->irqenable2);
Jon Hunter352a2d52013-04-15 13:06:54 -05001462
1463 if (regs->set_dataout && p->regs->clr_dataout)
Victor Kamensky661553b2013-11-16 02:01:04 +02001464 p->context.dataout = readl_relaxed(base + regs->set_dataout);
Jon Hunter352a2d52013-04-15 13:06:54 -05001465 else
Victor Kamensky661553b2013-11-16 02:01:04 +02001466 p->context.dataout = readl_relaxed(base + regs->dataout);
Jon Hunter352a2d52013-04-15 13:06:54 -05001467
1468 p->context_valid = true;
1469}
1470
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301471static void omap_gpio_restore_context(struct gpio_bank *bank)
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301472{
Victor Kamensky661553b2013-11-16 02:01:04 +02001473 writel_relaxed(bank->context.wake_en,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301474 bank->base + bank->regs->wkup_en);
Victor Kamensky661553b2013-11-16 02:01:04 +02001475 writel_relaxed(bank->context.ctrl, bank->base + bank->regs->ctrl);
1476 writel_relaxed(bank->context.leveldetect0,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301477 bank->base + bank->regs->leveldetect0);
Victor Kamensky661553b2013-11-16 02:01:04 +02001478 writel_relaxed(bank->context.leveldetect1,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301479 bank->base + bank->regs->leveldetect1);
Victor Kamensky661553b2013-11-16 02:01:04 +02001480 writel_relaxed(bank->context.risingdetect,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301481 bank->base + bank->regs->risingdetect);
Victor Kamensky661553b2013-11-16 02:01:04 +02001482 writel_relaxed(bank->context.fallingdetect,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301483 bank->base + bank->regs->fallingdetect);
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301484 if (bank->regs->set_dataout && bank->regs->clr_dataout)
Victor Kamensky661553b2013-11-16 02:01:04 +02001485 writel_relaxed(bank->context.dataout,
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301486 bank->base + bank->regs->set_dataout);
1487 else
Victor Kamensky661553b2013-11-16 02:01:04 +02001488 writel_relaxed(bank->context.dataout,
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301489 bank->base + bank->regs->dataout);
Victor Kamensky661553b2013-11-16 02:01:04 +02001490 writel_relaxed(bank->context.oe, bank->base + bank->regs->direction);
Nishanth Menon6d13eaa2011-08-29 18:54:50 +05301491
Nishanth Menonae547352011-09-09 19:08:58 +05301492 if (bank->dbck_enable_mask) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001493 writel_relaxed(bank->context.debounce, bank->base +
Nishanth Menonae547352011-09-09 19:08:58 +05301494 bank->regs->debounce);
Victor Kamensky661553b2013-11-16 02:01:04 +02001495 writel_relaxed(bank->context.debounce_en,
Nishanth Menonae547352011-09-09 19:08:58 +05301496 bank->base + bank->regs->debounce_en);
1497 }
Nishanth Menonba805be2011-08-29 18:41:08 +05301498
Victor Kamensky661553b2013-11-16 02:01:04 +02001499 writel_relaxed(bank->context.irqenable1,
Nishanth Menonba805be2011-08-29 18:41:08 +05301500 bank->base + bank->regs->irqenable);
Victor Kamensky661553b2013-11-16 02:01:04 +02001501 writel_relaxed(bank->context.irqenable2,
Nishanth Menonba805be2011-08-29 18:41:08 +05301502 bank->base + bank->regs->irqenable2);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301503}
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001504#endif /* CONFIG_PM */
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301505#else
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301506#define omap_gpio_runtime_suspend NULL
1507#define omap_gpio_runtime_resume NULL
Arnd Bergmannea4a21a2013-05-31 17:59:46 +02001508static inline void omap_gpio_init_context(struct gpio_bank *p) {}
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301509#endif
1510
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301511static const struct dev_pm_ops gpio_pm_ops = {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301512 SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume,
1513 NULL)
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301514};
1515
Benoit Cousson384ebe12011-08-16 11:53:02 +02001516#if defined(CONFIG_OF)
1517static struct omap_gpio_reg_offs omap2_gpio_regs = {
1518 .revision = OMAP24XX_GPIO_REVISION,
1519 .direction = OMAP24XX_GPIO_OE,
1520 .datain = OMAP24XX_GPIO_DATAIN,
1521 .dataout = OMAP24XX_GPIO_DATAOUT,
1522 .set_dataout = OMAP24XX_GPIO_SETDATAOUT,
1523 .clr_dataout = OMAP24XX_GPIO_CLEARDATAOUT,
1524 .irqstatus = OMAP24XX_GPIO_IRQSTATUS1,
1525 .irqstatus2 = OMAP24XX_GPIO_IRQSTATUS2,
1526 .irqenable = OMAP24XX_GPIO_IRQENABLE1,
1527 .irqenable2 = OMAP24XX_GPIO_IRQENABLE2,
1528 .set_irqenable = OMAP24XX_GPIO_SETIRQENABLE1,
1529 .clr_irqenable = OMAP24XX_GPIO_CLEARIRQENABLE1,
1530 .debounce = OMAP24XX_GPIO_DEBOUNCE_VAL,
1531 .debounce_en = OMAP24XX_GPIO_DEBOUNCE_EN,
1532 .ctrl = OMAP24XX_GPIO_CTRL,
1533 .wkup_en = OMAP24XX_GPIO_WAKE_EN,
1534 .leveldetect0 = OMAP24XX_GPIO_LEVELDETECT0,
1535 .leveldetect1 = OMAP24XX_GPIO_LEVELDETECT1,
1536 .risingdetect = OMAP24XX_GPIO_RISINGDETECT,
1537 .fallingdetect = OMAP24XX_GPIO_FALLINGDETECT,
1538};
1539
1540static struct omap_gpio_reg_offs omap4_gpio_regs = {
1541 .revision = OMAP4_GPIO_REVISION,
1542 .direction = OMAP4_GPIO_OE,
1543 .datain = OMAP4_GPIO_DATAIN,
1544 .dataout = OMAP4_GPIO_DATAOUT,
1545 .set_dataout = OMAP4_GPIO_SETDATAOUT,
1546 .clr_dataout = OMAP4_GPIO_CLEARDATAOUT,
1547 .irqstatus = OMAP4_GPIO_IRQSTATUS0,
1548 .irqstatus2 = OMAP4_GPIO_IRQSTATUS1,
1549 .irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1550 .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1,
1551 .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1552 .clr_irqenable = OMAP4_GPIO_IRQSTATUSCLR0,
1553 .debounce = OMAP4_GPIO_DEBOUNCINGTIME,
1554 .debounce_en = OMAP4_GPIO_DEBOUNCENABLE,
1555 .ctrl = OMAP4_GPIO_CTRL,
1556 .wkup_en = OMAP4_GPIO_IRQWAKEN0,
1557 .leveldetect0 = OMAP4_GPIO_LEVELDETECT0,
1558 .leveldetect1 = OMAP4_GPIO_LEVELDETECT1,
1559 .risingdetect = OMAP4_GPIO_RISINGDETECT,
1560 .fallingdetect = OMAP4_GPIO_FALLINGDETECT,
1561};
1562
Chen Gange9a65bb2013-02-06 18:44:32 +08001563static const struct omap_gpio_platform_data omap2_pdata = {
Benoit Cousson384ebe12011-08-16 11:53:02 +02001564 .regs = &omap2_gpio_regs,
1565 .bank_width = 32,
1566 .dbck_flag = false,
1567};
1568
Chen Gange9a65bb2013-02-06 18:44:32 +08001569static const struct omap_gpio_platform_data omap3_pdata = {
Benoit Cousson384ebe12011-08-16 11:53:02 +02001570 .regs = &omap2_gpio_regs,
1571 .bank_width = 32,
1572 .dbck_flag = true,
1573};
1574
Chen Gange9a65bb2013-02-06 18:44:32 +08001575static const struct omap_gpio_platform_data omap4_pdata = {
Benoit Cousson384ebe12011-08-16 11:53:02 +02001576 .regs = &omap4_gpio_regs,
1577 .bank_width = 32,
1578 .dbck_flag = true,
1579};
1580
1581static const struct of_device_id omap_gpio_match[] = {
1582 {
1583 .compatible = "ti,omap4-gpio",
1584 .data = &omap4_pdata,
1585 },
1586 {
1587 .compatible = "ti,omap3-gpio",
1588 .data = &omap3_pdata,
1589 },
1590 {
1591 .compatible = "ti,omap2-gpio",
1592 .data = &omap2_pdata,
1593 },
1594 { },
1595};
1596MODULE_DEVICE_TABLE(of, omap_gpio_match);
1597#endif
1598
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001599static struct platform_driver omap_gpio_driver = {
1600 .probe = omap_gpio_probe,
1601 .driver = {
1602 .name = "omap_gpio",
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301603 .pm = &gpio_pm_ops,
Benoit Cousson384ebe12011-08-16 11:53:02 +02001604 .of_match_table = of_match_ptr(omap_gpio_match),
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001605 },
1606};
1607
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001608/*
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001609 * gpio driver register needs to be done before
1610 * machine_init functions access gpio APIs.
1611 * Hence omap_gpio_drv_reg() is a postcore_initcall.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001612 */
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001613static int __init omap_gpio_drv_reg(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001614{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001615 return platform_driver_register(&omap_gpio_driver);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001616}
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001617postcore_initcall(omap_gpio_drv_reg);