blob: b2fcdf4f8bd769c87d0df55d51746b958b752880 [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
David Brownelle5c56ed2006-12-06 17:13:59 -0800491 if (type & ~IRQ_TYPE_SENSE_MASK)
Tony Lindgren6e60e792006-04-02 17:46:23 +0100492 return -EINVAL;
David Brownelle5c56ed2006-12-06 17:13:59 -0800493
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530494 if (!bank->regs->leveldetect0 &&
495 (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
Tony Lindgren92105bb2005-09-07 17:20:26 +0100496 return -EINVAL;
497
Grygorii Strashko1562e462015-05-22 17:35:49 +0300498 if (!BANK_USED(bank))
499 pm_runtime_get_sync(bank->dev);
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 Strashko1562e462015-05-22 17:35:49 +0300503 if (retval)
504 goto error;
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200505 omap_gpio_init_irq(bank, offset);
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200506 if (!omap_gpio_is_input(bank, offset)) {
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200507 spin_unlock_irqrestore(&bank->lock, flags);
Grygorii Strashko1562e462015-05-22 17:35:49 +0300508 retval = -EINVAL;
509 goto error;
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200510 }
David Brownella6472532008-03-03 04:33:30 -0800511 spin_unlock_irqrestore(&bank->lock, flags);
Kevin Hilman672e3022008-01-16 21:56:16 -0800512
513 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100514 __irq_set_handler_locked(d->irq, handle_level_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800515 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100516 __irq_set_handler_locked(d->irq, handle_edge_irq);
Kevin Hilman672e3022008-01-16 21:56:16 -0800517
Grygorii Strashko1562e462015-05-22 17:35:49 +0300518 return 0;
519
520error:
521 if (!BANK_USED(bank))
522 pm_runtime_put(bank->dev);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100523 return retval;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100524}
525
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200526static void omap_clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100527{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100528 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100529
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700530 reg += bank->regs->irqstatus;
Victor Kamensky661553b2013-11-16 02:01:04 +0200531 writel_relaxed(gpio_mask, reg);
Hiroshi DOYUbee79302006-09-25 12:41:46 +0300532
533 /* Workaround for clearing DSP GPIO interrupts to allow retention */
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700534 if (bank->regs->irqstatus2) {
535 reg = bank->base + bank->regs->irqstatus2;
Victor Kamensky661553b2013-11-16 02:01:04 +0200536 writel_relaxed(gpio_mask, reg);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700537 }
Roger Quadrosbedfd152009-04-23 11:10:50 -0700538
539 /* Flush posted write for the irq status to avoid spurious interrupts */
Victor Kamensky661553b2013-11-16 02:01:04 +0200540 readl_relaxed(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100541}
542
Grygorii Strashko9943f262015-03-23 14:18:27 +0200543static inline void omap_clear_gpio_irqstatus(struct gpio_bank *bank,
544 unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100545{
Grygorii Strashko9943f262015-03-23 14:18:27 +0200546 omap_clear_gpio_irqbank(bank, BIT(offset));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100547}
548
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200549static u32 omap_get_gpio_irqbank_mask(struct gpio_bank *bank)
Imre Deakea6dedd2006-06-26 16:16:00 -0700550{
551 void __iomem *reg = bank->base;
Imre Deak99c47702006-06-26 16:16:07 -0700552 u32 l;
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200553 u32 mask = (BIT(bank->width)) - 1;
Imre Deakea6dedd2006-06-26 16:16:00 -0700554
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700555 reg += bank->regs->irqenable;
Victor Kamensky661553b2013-11-16 02:01:04 +0200556 l = readl_relaxed(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700557 if (bank->regs->irqenable_inv)
Imre Deak99c47702006-06-26 16:16:07 -0700558 l = ~l;
559 l &= mask;
560 return l;
Imre Deakea6dedd2006-06-26 16:16:00 -0700561}
562
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200563static void omap_enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100564{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100565 void __iomem *reg = bank->base;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100566 u32 l;
567
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700568 if (bank->regs->set_irqenable) {
569 reg += bank->regs->set_irqenable;
570 l = gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530571 bank->context.irqenable1 |= gpio_mask;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700572 } else {
573 reg += bank->regs->irqenable;
Victor Kamensky661553b2013-11-16 02:01:04 +0200574 l = readl_relaxed(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700575 if (bank->regs->irqenable_inv)
576 l &= ~gpio_mask;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100577 else
578 l |= gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530579 bank->context.irqenable1 = l;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100580 }
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700581
Victor Kamensky661553b2013-11-16 02:01:04 +0200582 writel_relaxed(l, reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700583}
584
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200585static void omap_disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700586{
587 void __iomem *reg = bank->base;
588 u32 l;
589
590 if (bank->regs->clr_irqenable) {
591 reg += bank->regs->clr_irqenable;
592 l = gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530593 bank->context.irqenable1 &= ~gpio_mask;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700594 } else {
595 reg += bank->regs->irqenable;
Victor Kamensky661553b2013-11-16 02:01:04 +0200596 l = readl_relaxed(reg);
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700597 if (bank->regs->irqenable_inv)
598 l |= gpio_mask;
599 else
600 l &= ~gpio_mask;
Tarun Kanti DebBarma2a900eb2012-03-06 12:08:16 +0530601 bank->context.irqenable1 = l;
Kevin Hilman28f3b5a2011-04-21 09:53:06 -0700602 }
603
Victor Kamensky661553b2013-11-16 02:01:04 +0200604 writel_relaxed(l, reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100605}
606
Grygorii Strashko9943f262015-03-23 14:18:27 +0200607static inline void omap_set_gpio_irqenable(struct gpio_bank *bank,
608 unsigned offset, int enable)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100609{
Tarun Kanti DebBarma8276536c2011-11-25 15:27:37 +0530610 if (enable)
Grygorii Strashko9943f262015-03-23 14:18:27 +0200611 omap_enable_gpio_irqbank(bank, BIT(offset));
Tarun Kanti DebBarma8276536c2011-11-25 15:27:37 +0530612 else
Grygorii Strashko9943f262015-03-23 14:18:27 +0200613 omap_disable_gpio_irqbank(bank, BIT(offset));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100614}
615
Tony Lindgren92105bb2005-09-07 17:20:26 +0100616/*
617 * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register.
618 * 1510 does not seem to have a wake-up register. If JTAG is connected
619 * to the target, system will wake up always on GPIO events. While
620 * system is running all registered GPIO interrupts need to have wake-up
621 * enabled. When system is suspended, only selected GPIO interrupts need
622 * to have wake-up enabled.
623 */
Grygorii Strashko9943f262015-03-23 14:18:27 +0200624static int omap_set_gpio_wakeup(struct gpio_bank *bank, unsigned offset,
625 int enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100626{
Grygorii Strashko9943f262015-03-23 14:18:27 +0200627 u32 gpio_bit = BIT(offset);
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700628 unsigned long flags;
David Brownella6472532008-03-03 04:33:30 -0800629
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700630 if (bank->non_wakeup_gpios & gpio_bit) {
Benoit Cousson862ff642012-02-01 15:58:56 +0100631 dev_err(bank->dev,
Grygorii Strashko9943f262015-03-23 14:18:27 +0200632 "Unable to modify wakeup on non-wakeup GPIO%d\n",
633 offset);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100634 return -EINVAL;
635 }
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700636
637 spin_lock_irqsave(&bank->lock, flags);
638 if (enable)
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530639 bank->context.wake_en |= gpio_bit;
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700640 else
Tarun Kanti DebBarma0aa27272012-04-27 19:43:33 +0530641 bank->context.wake_en &= ~gpio_bit;
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700642
Victor Kamensky661553b2013-11-16 02:01:04 +0200643 writel_relaxed(bank->context.wake_en, bank->base + bank->regs->wkup_en);
Kevin Hilmanf64ad1a2011-04-22 09:45:27 -0700644 spin_unlock_irqrestore(&bank->lock, flags);
645
646 return 0;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100647}
648
649/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200650static int omap_gpio_wake_enable(struct irq_data *d, unsigned int enable)
Tony Lindgren92105bb2005-09-07 17:20:26 +0100651{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200652 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200653 unsigned offset = d->hwirq;
Tony Lindgren92105bb2005-09-07 17:20:26 +0100654
Grygorii Strashko9943f262015-03-23 14:18:27 +0200655 return omap_set_gpio_wakeup(bank, offset, enable);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100656}
657
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800658static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100659{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800660 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800661 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100662
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530663 /*
664 * If this is the first gpio_request for the bank,
665 * enable the bank module.
666 */
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200667 if (!BANK_USED(bank))
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530668 pm_runtime_get_sync(bank->dev);
Tony Lindgren92105bb2005-09-07 17:20:26 +0100669
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530670 spin_lock_irqsave(&bank->lock, flags);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300671 /* Set trigger to none. You need to enable the desired trigger with
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200672 * request_irq() or set_irq_type(). Only do this if the IRQ line has
673 * not already been requested.
Tony Lindgren4196dd62006-09-25 12:41:38 +0300674 */
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200675 if (!LINE_USED(bank->irq_usage, offset)) {
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200676 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
677 omap_enable_gpio_module(bank, offset);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100678 }
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200679 bank->mod_usage |= BIT(offset);
David Brownella6472532008-03-03 04:33:30 -0800680 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100681
682 return 0;
683}
684
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800685static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100686{
Jarkko Nikula3ff164e2008-12-10 17:35:27 -0800687 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
David Brownella6472532008-03-03 04:33:30 -0800688 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100689
David Brownella6472532008-03-03 04:33:30 -0800690 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200691 bank->mod_usage &= ~(BIT(offset));
Grygorii Strashko5f982c72015-05-22 17:35:48 +0300692 if (!LINE_USED(bank->irq_usage, offset)) {
693 omap_set_gpio_direction(bank, offset, 1);
694 omap_clear_gpio_debounce(bank, offset);
695 }
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200696 omap_disable_gpio_module(bank, offset);
David Brownella6472532008-03-03 04:33:30 -0800697 spin_unlock_irqrestore(&bank->lock, flags);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530698
699 /*
700 * If this is the last gpio to be freed in the bank,
701 * disable the bank module.
702 */
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +0200703 if (!BANK_USED(bank))
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530704 pm_runtime_put(bank->dev);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100705}
706
707/*
708 * We need to unmask the GPIO bank interrupt as soon as possible to
709 * avoid missing GPIO interrupts for other lines in the bank.
710 * Then we need to mask-read-clear-unmask the triggered GPIO lines
711 * in the bank to avoid missing nested interrupts for a GPIO line.
712 * If we wait to unmask individual GPIO lines in the bank after the
713 * line's interrupt handler has been run, we may miss some nested
714 * interrupts.
715 */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200716static void omap_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100717{
Tony Lindgren92105bb2005-09-07 17:20:26 +0100718 void __iomem *isr_reg = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100719 u32 isr;
Jon Hunter3513cde2013-04-04 15:16:14 -0500720 unsigned int bit;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100721 struct gpio_bank *bank;
Imre Deakea6dedd2006-06-26 16:16:00 -0700722 int unmasked = 0;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200723 struct irq_chip *irqchip = irq_desc_get_chip(desc);
724 struct gpio_chip *chip = irq_get_handler_data(irq);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100725
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200726 chained_irq_enter(irqchip, desc);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100727
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200728 bank = container_of(chip, struct gpio_bank, chip);
Kevin Hilmaneef4bec2011-04-21 09:17:35 -0700729 isr_reg = bank->base + bank->regs->irqstatus;
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530730 pm_runtime_get_sync(bank->dev);
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800731
732 if (WARN_ON(!isr_reg))
733 goto exit;
734
Laurent Navete83507b2013-03-20 13:15:57 +0100735 while (1) {
Tony Lindgren6e60e792006-04-02 17:46:23 +0100736 u32 isr_saved, level_mask = 0;
Imre Deakea6dedd2006-06-26 16:16:00 -0700737 u32 enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100738
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200739 enabled = omap_get_gpio_irqbank_mask(bank);
Victor Kamensky661553b2013-11-16 02:01:04 +0200740 isr_saved = isr = readl_relaxed(isr_reg) & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100741
Tarun Kanti DebBarma9ea14d82011-08-30 15:05:44 +0530742 if (bank->level_mask)
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800743 level_mask = bank->level_mask & enabled;
Tony Lindgren6e60e792006-04-02 17:46:23 +0100744
745 /* clear edge sensitive interrupts before handler(s) are
746 called so that we don't miss any interrupt occurred while
747 executing them */
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200748 omap_disable_gpio_irqbank(bank, isr_saved & ~level_mask);
749 omap_clear_gpio_irqbank(bank, isr_saved & ~level_mask);
750 omap_enable_gpio_irqbank(bank, isr_saved & ~level_mask);
Tony Lindgren6e60e792006-04-02 17:46:23 +0100751
752 /* if there is only edge sensitive GPIO pin interrupts
753 configured, we could unmask GPIO bank interrupt immediately */
Imre Deakea6dedd2006-06-26 16:16:00 -0700754 if (!level_mask && !unmasked) {
755 unmasked = 1;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200756 chained_irq_exit(irqchip, desc);
Imre Deakea6dedd2006-06-26 16:16:00 -0700757 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100758
Tony Lindgren92105bb2005-09-07 17:20:26 +0100759 if (!isr)
760 break;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100761
Jon Hunter3513cde2013-04-04 15:16:14 -0500762 while (isr) {
763 bit = __ffs(isr);
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200764 isr &= ~(BIT(bit));
Benoit Cousson25db7112012-02-23 21:50:10 +0100765
Cory Maccarrone4318f362010-01-08 10:29:04 -0800766 /*
767 * Some chips can't respond to both rising and falling
768 * at the same time. If this irq was requested with
769 * both flags, we need to flip the ICR data for the IRQ
770 * to respond to the IRQ for the opposite direction.
771 * This will be indicated in the bank toggle_mask.
772 */
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200773 if (bank->toggle_mask & (BIT(bit)))
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200774 omap_toggle_gpio_edge_triggering(bank, bit);
Cory Maccarrone4318f362010-01-08 10:29:04 -0800775
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200776 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain,
777 bit));
Tony Lindgren92105bb2005-09-07 17:20:26 +0100778 }
Tony Lindgren1a8bfa12005-11-10 14:26:50 +0000779 }
Imre Deakea6dedd2006-06-26 16:16:00 -0700780 /* if bank has any level sensitive GPIO pin interrupt
781 configured, we must unmask the bank interrupt only after
782 handler(s) are executed in order to avoid spurious bank
783 interrupt */
Evgeny Kuznetsovb1cc4c52010-12-07 16:25:40 -0800784exit:
Imre Deakea6dedd2006-06-26 16:16:00 -0700785 if (!unmasked)
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +0200786 chained_irq_exit(irqchip, desc);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +0530787 pm_runtime_put(bank->dev);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100788}
789
Tony Lindgren3d009c82015-01-16 14:50:50 -0800790static unsigned int omap_gpio_irq_startup(struct irq_data *d)
791{
792 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Tony Lindgren3d009c82015-01-16 14:50:50 -0800793 unsigned long flags;
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200794 unsigned offset = d->hwirq;
Tony Lindgren3d009c82015-01-16 14:50:50 -0800795
796 if (!BANK_USED(bank))
797 pm_runtime_get_sync(bank->dev);
798
799 spin_lock_irqsave(&bank->lock, flags);
Grygorii Strashko37e14ec2015-03-23 14:18:26 +0200800 omap_gpio_init_irq(bank, offset);
Tony Lindgren3d009c82015-01-16 14:50:50 -0800801 spin_unlock_irqrestore(&bank->lock, flags);
802 omap_gpio_unmask_irq(d);
803
804 return 0;
805}
806
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200807static void omap_gpio_irq_shutdown(struct irq_data *d)
Tony Lindgren4196dd62006-09-25 12:41:38 +0300808{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200809 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700810 unsigned long flags;
Grygorii Strashko9943f262015-03-23 14:18:27 +0200811 unsigned offset = d->hwirq;
Tony Lindgren4196dd62006-09-25 12:41:38 +0300812
Colin Cross85ec7b92011-06-06 13:38:18 -0700813 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasb1e9fec2014-04-27 02:00:49 +0200814 bank->irq_usage &= ~(BIT(offset));
Grygorii Strashko6e96c1b2015-05-22 17:35:50 +0300815 omap_set_gpio_irqenable(bank, offset, 0);
816 omap_clear_gpio_irqstatus(bank, offset);
817 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
818 if (!LINE_USED(bank->mod_usage, offset))
819 omap_clear_gpio_debounce(bank, offset);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200820 omap_disable_gpio_module(bank, offset);
Colin Cross85ec7b92011-06-06 13:38:18 -0700821 spin_unlock_irqrestore(&bank->lock, flags);
Javier Martinez Canillasfac7fa12013-09-25 02:36:54 +0200822
823 /*
824 * If this is the last IRQ to be freed in the bank,
825 * disable the bank module.
826 */
827 if (!BANK_USED(bank))
828 pm_runtime_put(bank->dev);
Tony Lindgren4196dd62006-09-25 12:41:38 +0300829}
830
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200831static void omap_gpio_ack_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100832{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200833 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200834 unsigned offset = d->hwirq;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100835
Grygorii Strashko9943f262015-03-23 14:18:27 +0200836 omap_clear_gpio_irqstatus(bank, offset);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100837}
838
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200839static void omap_gpio_mask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100840{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200841 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200842 unsigned offset = d->hwirq;
Colin Cross85ec7b92011-06-06 13:38:18 -0700843 unsigned long flags;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100844
Colin Cross85ec7b92011-06-06 13:38:18 -0700845 spin_lock_irqsave(&bank->lock, flags);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200846 omap_set_gpio_irqenable(bank, offset, 0);
847 omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
Colin Cross85ec7b92011-06-06 13:38:18 -0700848 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100849}
850
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200851static void omap_gpio_unmask_irq(struct irq_data *d)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100852{
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200853 struct gpio_bank *bank = omap_irq_data_get_bank(d);
Grygorii Strashko9943f262015-03-23 14:18:27 +0200854 unsigned offset = d->hwirq;
Thomas Gleixner8c04a172011-03-24 12:40:15 +0100855 u32 trigger = irqd_get_trigger_type(d);
Colin Cross85ec7b92011-06-06 13:38:18 -0700856 unsigned long flags;
Kevin Hilman55b60192009-06-04 15:57:10 -0700857
Colin Cross85ec7b92011-06-06 13:38:18 -0700858 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman55b60192009-06-04 15:57:10 -0700859 if (trigger)
Grygorii Strashko9943f262015-03-23 14:18:27 +0200860 omap_set_gpio_triggering(bank, offset, trigger);
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800861
862 /* For level-triggered GPIOs, the clearing must be done after
863 * the HW source is cleared, thus after the handler has run */
Grygorii Strashko9943f262015-03-23 14:18:27 +0200864 if (bank->level_mask & BIT(offset)) {
865 omap_set_gpio_irqenable(bank, offset, 0);
866 omap_clear_gpio_irqstatus(bank, offset);
Kevin Hilmanb144ff62008-01-16 21:56:15 -0800867 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100868
Grygorii Strashko9943f262015-03-23 14:18:27 +0200869 omap_set_gpio_irqenable(bank, offset, 1);
Colin Cross85ec7b92011-06-06 13:38:18 -0700870 spin_unlock_irqrestore(&bank->lock, flags);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100871}
872
David Brownelle5c56ed2006-12-06 17:13:59 -0800873/*---------------------------------------------------------------------*/
874
Magnus Damm79ee0312009-07-08 13:22:04 +0200875static int omap_mpuio_suspend_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800876{
Magnus Damm79ee0312009-07-08 13:22:04 +0200877 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800878 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800879 void __iomem *mask_reg = bank->base +
880 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800881 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800882
David Brownella6472532008-03-03 04:33:30 -0800883 spin_lock_irqsave(&bank->lock, flags);
Victor Kamensky661553b2013-11-16 02:01:04 +0200884 writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800885 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800886
887 return 0;
888}
889
Magnus Damm79ee0312009-07-08 13:22:04 +0200890static int omap_mpuio_resume_noirq(struct device *dev)
David Brownell11a78b72006-12-06 17:14:11 -0800891{
Magnus Damm79ee0312009-07-08 13:22:04 +0200892 struct platform_device *pdev = to_platform_device(dev);
David Brownell11a78b72006-12-06 17:14:11 -0800893 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tony Lindgren5de62b82010-12-07 16:26:58 -0800894 void __iomem *mask_reg = bank->base +
895 OMAP_MPUIO_GPIO_MASKIT / bank->stride;
David Brownella6472532008-03-03 04:33:30 -0800896 unsigned long flags;
David Brownell11a78b72006-12-06 17:14:11 -0800897
David Brownella6472532008-03-03 04:33:30 -0800898 spin_lock_irqsave(&bank->lock, flags);
Victor Kamensky661553b2013-11-16 02:01:04 +0200899 writel_relaxed(bank->context.wake_en, mask_reg);
David Brownella6472532008-03-03 04:33:30 -0800900 spin_unlock_irqrestore(&bank->lock, flags);
David Brownell11a78b72006-12-06 17:14:11 -0800901
902 return 0;
903}
904
Alexey Dobriyan47145212009-12-14 18:00:08 -0800905static const struct dev_pm_ops omap_mpuio_dev_pm_ops = {
Magnus Damm79ee0312009-07-08 13:22:04 +0200906 .suspend_noirq = omap_mpuio_suspend_noirq,
907 .resume_noirq = omap_mpuio_resume_noirq,
908};
909
Rafael J. Wysocki3c437ff2011-04-22 22:02:46 +0200910/* use platform_driver for this. */
David Brownell11a78b72006-12-06 17:14:11 -0800911static struct platform_driver omap_mpuio_driver = {
David Brownell11a78b72006-12-06 17:14:11 -0800912 .driver = {
913 .name = "mpuio",
Magnus Damm79ee0312009-07-08 13:22:04 +0200914 .pm = &omap_mpuio_dev_pm_ops,
David Brownell11a78b72006-12-06 17:14:11 -0800915 },
916};
917
918static struct platform_device omap_mpuio_device = {
919 .name = "mpuio",
920 .id = -1,
921 .dev = {
922 .driver = &omap_mpuio_driver.driver,
923 }
924 /* could list the /proc/iomem resources */
925};
926
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200927static inline void omap_mpuio_init(struct gpio_bank *bank)
David Brownell11a78b72006-12-06 17:14:11 -0800928{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800929 platform_set_drvdata(&omap_mpuio_device, bank);
David Brownellfcf126d2007-04-02 12:46:47 -0700930
David Brownell11a78b72006-12-06 17:14:11 -0800931 if (platform_driver_register(&omap_mpuio_driver) == 0)
932 (void) platform_device_register(&omap_mpuio_device);
933}
934
David Brownelle5c56ed2006-12-06 17:13:59 -0800935/*---------------------------------------------------------------------*/
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100936
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200937static int omap_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
Yegor Yefremov93700842014-04-24 08:57:39 +0200938{
939 struct gpio_bank *bank;
940 unsigned long flags;
941 void __iomem *reg;
942 int dir;
943
944 bank = container_of(chip, struct gpio_bank, chip);
945 reg = bank->base + bank->regs->direction;
946 spin_lock_irqsave(&bank->lock, flags);
947 dir = !!(readl_relaxed(reg) & BIT(offset));
948 spin_unlock_irqrestore(&bank->lock, flags);
949 return dir;
950}
951
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200952static int omap_gpio_input(struct gpio_chip *chip, unsigned offset)
David Brownell52e31342008-03-03 12:43:23 -0800953{
954 struct gpio_bank *bank;
955 unsigned long flags;
956
957 bank = container_of(chip, struct gpio_bank, chip);
958 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200959 omap_set_gpio_direction(bank, offset, 1);
David Brownell52e31342008-03-03 12:43:23 -0800960 spin_unlock_irqrestore(&bank->lock, flags);
961 return 0;
962}
963
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200964static int omap_gpio_get(struct gpio_chip *chip, unsigned offset)
David Brownell52e31342008-03-03 12:43:23 -0800965{
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300966 struct gpio_bank *bank;
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300967
Charulatha Va8be8da2011-04-22 16:38:16 +0530968 bank = container_of(chip, struct gpio_bank, chip);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300969
Grygorii Strashkob2b20042015-03-23 14:18:23 +0200970 if (omap_gpio_is_input(bank, offset))
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200971 return omap_get_gpio_datain(bank, offset);
Roger Quadrosb37c45b2009-08-05 16:53:24 +0300972 else
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200973 return omap_get_gpio_dataout(bank, offset);
David Brownell52e31342008-03-03 12:43:23 -0800974}
975
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200976static int omap_gpio_output(struct gpio_chip *chip, unsigned offset, int value)
David Brownell52e31342008-03-03 12:43:23 -0800977{
978 struct gpio_bank *bank;
979 unsigned long flags;
980
981 bank = container_of(chip, struct gpio_bank, chip);
982 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -0700983 bank->set_dataout(bank, offset, value);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200984 omap_set_gpio_direction(bank, offset, 0);
David Brownell52e31342008-03-03 12:43:23 -0800985 spin_unlock_irqrestore(&bank->lock, flags);
Javier Martinez Canillas2f56e0a2013-10-16 02:47:30 +0200986 return 0;
David Brownell52e31342008-03-03 12:43:23 -0800987}
988
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200989static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset,
990 unsigned debounce)
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700991{
992 struct gpio_bank *bank;
993 unsigned long flags;
994
995 bank = container_of(chip, struct gpio_bank, chip);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -0800996
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700997 spin_lock_irqsave(&bank->lock, flags);
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +0200998 omap2_set_gpio_debounce(bank, offset, debounce);
Felipe Balbi168ef3d2010-05-26 14:42:23 -0700999 spin_unlock_irqrestore(&bank->lock, flags);
1000
1001 return 0;
1002}
1003
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001004static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
David Brownell52e31342008-03-03 12:43:23 -08001005{
1006 struct gpio_bank *bank;
1007 unsigned long flags;
1008
1009 bank = container_of(chip, struct gpio_bank, chip);
1010 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001011 bank->set_dataout(bank, offset, value);
David Brownell52e31342008-03-03 12:43:23 -08001012 spin_unlock_irqrestore(&bank->lock, flags);
1013}
1014
1015/*---------------------------------------------------------------------*/
1016
Tony Lindgren9a748052010-12-07 16:26:56 -08001017static void __init omap_gpio_show_rev(struct gpio_bank *bank)
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001018{
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001019 static bool called;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001020 u32 rev;
1021
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001022 if (called || bank->regs->revision == USHRT_MAX)
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001023 return;
1024
Victor Kamensky661553b2013-11-16 02:01:04 +02001025 rev = readw_relaxed(bank->base + bank->regs->revision);
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001026 pr_info("OMAP GPIO hardware version %d.%d\n",
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001027 (rev >> 4) & 0x0f, rev & 0x0f);
Kevin Hilmane5ff4442011-04-22 14:37:16 -07001028
1029 called = true;
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001030}
1031
Charulatha V03e128c2011-05-05 19:58:01 +05301032static void omap_gpio_mod_init(struct gpio_bank *bank)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001033{
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301034 void __iomem *base = bank->base;
1035 u32 l = 0xffffffff;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001036
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301037 if (bank->width == 16)
1038 l = 0xffff;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001039
Charulatha Vd0d665a2011-08-31 00:02:21 +05301040 if (bank->is_mpuio) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001041 writel_relaxed(l, bank->base + bank->regs->irqenable);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301042 return;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001043 }
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301044
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001045 omap_gpio_rmw(base, bank->regs->irqenable, l,
1046 bank->regs->irqenable_inv);
1047 omap_gpio_rmw(base, bank->regs->irqstatus, l,
1048 !bank->regs->irqenable_inv);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301049 if (bank->regs->debounce_en)
Victor Kamensky661553b2013-11-16 02:01:04 +02001050 writel_relaxed(0, base + bank->regs->debounce_en);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301051
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301052 /* Save OE default value (0xffffffff) in the context */
Victor Kamensky661553b2013-11-16 02:01:04 +02001053 bank->context.oe = readl_relaxed(bank->base + bank->regs->direction);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301054 /* Initialize interface clk ungated, module enabled */
1055 if (bank->regs->ctrl)
Victor Kamensky661553b2013-11-16 02:01:04 +02001056 writel_relaxed(0, base + bank->regs->ctrl);
Tarun Kanti DebBarma34672012012-07-11 14:43:14 +05301057
1058 bank->dbck = clk_get(bank->dev, "dbclk");
1059 if (IS_ERR(bank->dbck))
1060 dev_err(bank->dev, "Could not get gpio dbck\n");
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001061}
1062
Nishanth Menon46824e22014-09-05 14:52:55 -05001063static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc)
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001064{
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001065 static int gpio;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001066 int irq_base = 0;
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001067 int ret;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001068
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001069 /*
1070 * REVISIT eventually switch from OMAP-specific gpio structs
1071 * over to the generic ones
1072 */
1073 bank->chip.request = omap_gpio_request;
1074 bank->chip.free = omap_gpio_free;
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001075 bank->chip.get_direction = omap_gpio_get_direction;
1076 bank->chip.direction_input = omap_gpio_input;
1077 bank->chip.get = omap_gpio_get;
1078 bank->chip.direction_output = omap_gpio_output;
1079 bank->chip.set_debounce = omap_gpio_debounce;
1080 bank->chip.set = omap_gpio_set;
Charulatha Vd0d665a2011-08-31 00:02:21 +05301081 if (bank->is_mpuio) {
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001082 bank->chip.label = "mpuio";
Tarun Kanti DebBarma6ed87c52011-09-13 14:41:44 +05301083 if (bank->regs->wkup_en)
1084 bank->chip.dev = &omap_mpuio_device.dev;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001085 bank->chip.base = OMAP_MPUIO(0);
1086 } else {
1087 bank->chip.label = "gpio";
1088 bank->chip.base = gpio;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001089 gpio += bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001090 }
Kevin Hilmand5f46242011-04-21 09:23:00 -07001091 bank->chip.ngpio = bank->width;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001092
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001093 ret = gpiochip_add(&bank->chip);
1094 if (ret) {
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001095 dev_err(bank->dev, "Could not register gpio chip %d\n", ret);
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001096 return ret;
1097 }
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001098
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001099#ifdef CONFIG_ARCH_OMAP1
1100 /*
1101 * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop
1102 * irq_alloc_descs() since a base IRQ offset will no longer be needed.
1103 */
1104 irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
1105 if (irq_base < 0) {
1106 dev_err(bank->dev, "Couldn't allocate IRQ numbers\n");
1107 return -ENODEV;
1108 }
1109#endif
1110
Tony Lindgrend2d05c62015-04-23 16:54:17 -07001111 /* MPUIO is a bit different, reading IRQ status clears it */
1112 if (bank->is_mpuio) {
1113 irqc->irq_ack = dummy_irq_chip.irq_ack;
1114 irqc->irq_mask = irq_gc_mask_set_bit;
1115 irqc->irq_unmask = irq_gc_mask_clr_bit;
1116 if (!bank->regs->wkup_en)
1117 irqc->irq_set_wake = NULL;
1118 }
1119
Nishanth Menon46824e22014-09-05 14:52:55 -05001120 ret = gpiochip_irqchip_add(&bank->chip, irqc,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001121 irq_base, omap_gpio_irq_handler,
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001122 IRQ_TYPE_NONE);
1123
1124 if (ret) {
1125 dev_err(bank->dev, "Couldn't add irqchip to gpiochip %d\n", ret);
Linus Walleijda26d5d2014-09-16 15:11:41 -07001126 gpiochip_remove(&bank->chip);
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001127 return -ENODEV;
1128 }
1129
Nishanth Menon46824e22014-09-05 14:52:55 -05001130 gpiochip_set_chained_irqchip(&bank->chip, irqc,
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001131 bank->irq, omap_gpio_irq_handler);
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001132
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001133 return 0;
Varadarajan, Charulatha2fae7fb2010-12-07 16:26:55 -08001134}
1135
Benoit Cousson384ebe12011-08-16 11:53:02 +02001136static const struct of_device_id omap_gpio_match[];
1137
Bill Pemberton38363092012-11-19 13:22:34 -05001138static int omap_gpio_probe(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001139{
Benoit Cousson862ff642012-02-01 15:58:56 +01001140 struct device *dev = &pdev->dev;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001141 struct device_node *node = dev->of_node;
1142 const struct of_device_id *match;
Uwe Kleine-Königf6817a22012-05-21 21:57:39 +02001143 const struct omap_gpio_platform_data *pdata;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001144 struct resource *res;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001145 struct gpio_bank *bank;
Nishanth Menon46824e22014-09-05 14:52:55 -05001146 struct irq_chip *irqc;
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001147 int ret;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001148
Benoit Cousson384ebe12011-08-16 11:53:02 +02001149 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
1150
Jingoo Hane56aee12013-07-30 17:08:05 +09001151 pdata = match ? match->data : dev_get_platdata(dev);
Benoit Cousson384ebe12011-08-16 11:53:02 +02001152 if (!pdata)
Benoit Cousson96751fc2012-02-01 16:01:39 +01001153 return -EINVAL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001154
Tobias Klauser086d5852012-10-05 11:37:38 +02001155 bank = devm_kzalloc(dev, sizeof(struct gpio_bank), GFP_KERNEL);
Charulatha V03e128c2011-05-05 19:58:01 +05301156 if (!bank) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001157 dev_err(dev, "Memory alloc failed\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001158 return -ENOMEM;
Charulatha V03e128c2011-05-05 19:58:01 +05301159 }
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001160
Nishanth Menon46824e22014-09-05 14:52:55 -05001161 irqc = devm_kzalloc(dev, sizeof(*irqc), GFP_KERNEL);
1162 if (!irqc)
1163 return -ENOMEM;
1164
Tony Lindgren3d009c82015-01-16 14:50:50 -08001165 irqc->irq_startup = omap_gpio_irq_startup,
Nishanth Menon46824e22014-09-05 14:52:55 -05001166 irqc->irq_shutdown = omap_gpio_irq_shutdown,
1167 irqc->irq_ack = omap_gpio_ack_irq,
1168 irqc->irq_mask = omap_gpio_mask_irq,
1169 irqc->irq_unmask = omap_gpio_unmask_irq,
1170 irqc->irq_set_type = omap_gpio_irq_type,
1171 irqc->irq_set_wake = omap_gpio_wake_enable,
1172 irqc->name = dev_name(&pdev->dev);
1173
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001174 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1175 if (unlikely(!res)) {
Benoit Cousson862ff642012-02-01 15:58:56 +01001176 dev_err(dev, "Invalid IRQ resource\n");
Benoit Cousson96751fc2012-02-01 16:01:39 +01001177 return -ENODEV;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001178 }
1179
1180 bank->irq = res->start;
Benoit Cousson862ff642012-02-01 15:58:56 +01001181 bank->dev = dev;
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001182 bank->chip.dev = dev;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001183 bank->dbck_flag = pdata->dbck_flag;
Tony Lindgren5de62b82010-12-07 16:26:58 -08001184 bank->stride = pdata->bank_stride;
Kevin Hilmand5f46242011-04-21 09:23:00 -07001185 bank->width = pdata->bank_width;
Charulatha Vd0d665a2011-08-31 00:02:21 +05301186 bank->is_mpuio = pdata->is_mpuio;
Charulatha V803a2432011-05-05 17:04:12 +05301187 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001188 bank->regs = pdata->regs;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001189#ifdef CONFIG_OF_GPIO
1190 bank->chip.of_node = of_node_get(node);
1191#endif
Jon Huntera2797be2013-04-04 15:16:15 -05001192 if (node) {
1193 if (!of_property_read_bool(node, "ti,gpio-always-on"))
1194 bank->loses_context = true;
1195 } else {
1196 bank->loses_context = pdata->loses_context;
Jon Hunter352a2d52013-04-15 13:06:54 -05001197
1198 if (bank->loses_context)
1199 bank->get_context_loss_count =
1200 pdata->get_context_loss_count;
Benoit Cousson384ebe12011-08-16 11:53:02 +02001201 }
1202
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001203 if (bank->regs->set_dataout && bank->regs->clr_dataout)
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001204 bank->set_dataout = omap_set_gpio_dataout_reg;
Kevin Hilmanfa87931a2011-04-20 16:31:23 -07001205 else
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001206 bank->set_dataout = omap_set_gpio_dataout_mask;
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001207
1208 spin_lock_init(&bank->lock);
1209
1210 /* Static mapping, never released */
1211 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Jingoo Han717f70e2014-02-12 11:51:38 +09001212 bank->base = devm_ioremap_resource(dev, res);
1213 if (IS_ERR(bank->base)) {
Javier Martinez Canillasfb655f52014-04-06 16:58:16 +02001214 irq_domain_remove(bank->chip.irqdomain);
Jingoo Han717f70e2014-02-12 11:51:38 +09001215 return PTR_ERR(bank->base);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001216 }
1217
Tarun Kanti DebBarma065cd792011-11-24 01:48:52 +05301218 platform_set_drvdata(pdev, bank);
1219
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001220 pm_runtime_enable(bank->dev);
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301221 pm_runtime_irq_safe(bank->dev);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001222 pm_runtime_get_sync(bank->dev);
1223
Charulatha Vd0d665a2011-08-31 00:02:21 +05301224 if (bank->is_mpuio)
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001225 omap_mpuio_init(bank);
Tarun Kanti DebBarmaab985f02011-09-13 15:12:05 +05301226
Charulatha V03e128c2011-05-05 19:58:01 +05301227 omap_gpio_mod_init(bank);
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001228
Nishanth Menon46824e22014-09-05 14:52:55 -05001229 ret = omap_gpio_chip_init(bank, irqc);
Javier Martinez Canillas6ef7f382014-04-06 16:58:14 +02001230 if (ret)
1231 return ret;
1232
Tony Lindgren9a748052010-12-07 16:26:56 -08001233 omap_gpio_show_rev(bank);
Tony Lindgren9f7065d2009-10-19 15:25:20 -07001234
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301235 pm_runtime_put(bank->dev);
1236
Charulatha V03e128c2011-05-05 19:58:01 +05301237 list_add_tail(&bank->node, &omap_gpio_list);
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001238
Jon Hunter879fe322013-04-04 15:16:12 -05001239 return 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001240}
1241
Tony Lindgrencac089f2015-04-23 16:56:22 -07001242static int omap_gpio_remove(struct platform_device *pdev)
1243{
1244 struct gpio_bank *bank = platform_get_drvdata(pdev);
1245
1246 list_del(&bank->node);
1247 gpiochip_remove(&bank->chip);
1248 pm_runtime_disable(bank->dev);
1249
1250 return 0;
1251}
1252
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301253#ifdef CONFIG_ARCH_OMAP2PLUS
1254
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001255#if defined(CONFIG_PM)
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301256static void omap_gpio_restore_context(struct gpio_bank *bank);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001257
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301258static int omap_gpio_runtime_suspend(struct device *dev)
1259{
1260 struct platform_device *pdev = to_platform_device(dev);
1261 struct gpio_bank *bank = platform_get_drvdata(pdev);
1262 u32 l1 = 0, l2 = 0;
1263 unsigned long flags;
Kevin Hilman68942ed2012-03-05 15:10:04 -08001264 u32 wake_low, wake_hi;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301265
1266 spin_lock_irqsave(&bank->lock, flags);
Kevin Hilman68942ed2012-03-05 15:10:04 -08001267
1268 /*
1269 * Only edges can generate a wakeup event to the PRCM.
1270 *
1271 * Therefore, ensure any wake-up capable GPIOs have
1272 * edge-detection enabled before going idle to ensure a wakeup
1273 * to the PRCM is generated on a GPIO transition. (c.f. 34xx
1274 * NDA TRM 25.5.3.1)
1275 *
1276 * The normal values will be restored upon ->runtime_resume()
1277 * by writing back the values saved in bank->context.
1278 */
1279 wake_low = bank->context.leveldetect0 & bank->context.wake_en;
1280 if (wake_low)
Victor Kamensky661553b2013-11-16 02:01:04 +02001281 writel_relaxed(wake_low | bank->context.fallingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001282 bank->base + bank->regs->fallingdetect);
1283 wake_hi = bank->context.leveldetect1 & bank->context.wake_en;
1284 if (wake_hi)
Victor Kamensky661553b2013-11-16 02:01:04 +02001285 writel_relaxed(wake_hi | bank->context.risingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001286 bank->base + bank->regs->risingdetect);
1287
Kevin Hilmanb3c64bc2012-05-17 16:42:16 -07001288 if (!bank->enabled_non_wakeup_gpios)
1289 goto update_gpio_context_count;
1290
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301291 if (bank->power_mode != OFF_MODE) {
1292 bank->power_mode = 0;
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +05301293 goto update_gpio_context_count;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301294 }
1295 /*
1296 * If going to OFF, remove triggering for all
1297 * non-wakeup GPIOs. Otherwise spurious IRQs will be
1298 * generated. See OMAP2420 Errata item 1.101.
1299 */
Victor Kamensky661553b2013-11-16 02:01:04 +02001300 bank->saved_datain = readl_relaxed(bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301301 bank->regs->datain);
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301302 l1 = bank->context.fallingdetect;
1303 l2 = bank->context.risingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301304
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301305 l1 &= ~bank->enabled_non_wakeup_gpios;
1306 l2 &= ~bank->enabled_non_wakeup_gpios;
1307
Victor Kamensky661553b2013-11-16 02:01:04 +02001308 writel_relaxed(l1, bank->base + bank->regs->fallingdetect);
1309 writel_relaxed(l2, bank->base + bank->regs->risingdetect);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301310
1311 bank->workaround_enabled = true;
1312
Tarun Kanti DebBarma41d87cb2011-11-15 12:52:38 +05301313update_gpio_context_count:
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301314 if (bank->get_context_loss_count)
1315 bank->context_loss_count =
1316 bank->get_context_loss_count(bank->dev);
1317
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001318 omap_gpio_dbck_disable(bank);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301319 spin_unlock_irqrestore(&bank->lock, flags);
1320
1321 return 0;
1322}
1323
Jon Hunter352a2d52013-04-15 13:06:54 -05001324static void omap_gpio_init_context(struct gpio_bank *p);
1325
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301326static int omap_gpio_runtime_resume(struct device *dev)
1327{
1328 struct platform_device *pdev = to_platform_device(dev);
1329 struct gpio_bank *bank = platform_get_drvdata(pdev);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301330 u32 l = 0, gen, gen0, gen1;
1331 unsigned long flags;
Jon Huntera2797be2013-04-04 15:16:15 -05001332 int c;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301333
1334 spin_lock_irqsave(&bank->lock, flags);
Jon Hunter352a2d52013-04-15 13:06:54 -05001335
1336 /*
1337 * On the first resume during the probe, the context has not
1338 * been initialised and so initialise it now. Also initialise
1339 * the context loss count.
1340 */
1341 if (bank->loses_context && !bank->context_valid) {
1342 omap_gpio_init_context(bank);
1343
1344 if (bank->get_context_loss_count)
1345 bank->context_loss_count =
1346 bank->get_context_loss_count(bank->dev);
1347 }
1348
Javier Martinez Canillasa0e827c2014-06-27 22:17:37 +02001349 omap_gpio_dbck_enable(bank);
Kevin Hilman68942ed2012-03-05 15:10:04 -08001350
1351 /*
1352 * In ->runtime_suspend(), level-triggered, wakeup-enabled
1353 * GPIOs were set to edge trigger also in order to be able to
1354 * generate a PRCM wakeup. Here we restore the
1355 * pre-runtime_suspend() values for edge triggering.
1356 */
Victor Kamensky661553b2013-11-16 02:01:04 +02001357 writel_relaxed(bank->context.fallingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001358 bank->base + bank->regs->fallingdetect);
Victor Kamensky661553b2013-11-16 02:01:04 +02001359 writel_relaxed(bank->context.risingdetect,
Kevin Hilman68942ed2012-03-05 15:10:04 -08001360 bank->base + bank->regs->risingdetect);
1361
Jon Huntera2797be2013-04-04 15:16:15 -05001362 if (bank->loses_context) {
1363 if (!bank->get_context_loss_count) {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301364 omap_gpio_restore_context(bank);
1365 } else {
Jon Huntera2797be2013-04-04 15:16:15 -05001366 c = bank->get_context_loss_count(bank->dev);
1367 if (c != bank->context_loss_count) {
1368 omap_gpio_restore_context(bank);
1369 } else {
1370 spin_unlock_irqrestore(&bank->lock, flags);
1371 return 0;
1372 }
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301373 }
1374 }
1375
Tarun Kanti DebBarma1b1287032012-04-27 19:43:38 +05301376 if (!bank->workaround_enabled) {
1377 spin_unlock_irqrestore(&bank->lock, flags);
1378 return 0;
1379 }
1380
Victor Kamensky661553b2013-11-16 02:01:04 +02001381 l = readl_relaxed(bank->base + bank->regs->datain);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301382
1383 /*
1384 * Check if any of the non-wakeup interrupt GPIOs have changed
1385 * state. If so, generate an IRQ by software. This is
1386 * horribly racy, but it's the best we can do to work around
1387 * this silicon bug.
1388 */
1389 l ^= bank->saved_datain;
1390 l &= bank->enabled_non_wakeup_gpios;
1391
1392 /*
1393 * No need to generate IRQs for the rising edge for gpio IRQs
1394 * configured with falling edge only; and vice versa.
1395 */
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301396 gen0 = l & bank->context.fallingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301397 gen0 &= bank->saved_datain;
1398
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301399 gen1 = l & bank->context.risingdetect;
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301400 gen1 &= ~(bank->saved_datain);
1401
1402 /* FIXME: Consider GPIO IRQs with level detections properly! */
Tarun Kanti DebBarmac6f31c92012-04-27 19:43:32 +05301403 gen = l & (~(bank->context.fallingdetect) &
1404 ~(bank->context.risingdetect));
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301405 /* Consider all GPIO IRQs needed to be updated */
1406 gen |= gen0 | gen1;
1407
1408 if (gen) {
1409 u32 old0, old1;
1410
Victor Kamensky661553b2013-11-16 02:01:04 +02001411 old0 = readl_relaxed(bank->base + bank->regs->leveldetect0);
1412 old1 = readl_relaxed(bank->base + bank->regs->leveldetect1);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301413
Tarun Kanti DebBarma4e962e82012-04-27 19:43:37 +05301414 if (!bank->regs->irqstatus_raw0) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001415 writel_relaxed(old0 | gen, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301416 bank->regs->leveldetect0);
Victor Kamensky661553b2013-11-16 02:01:04 +02001417 writel_relaxed(old1 | gen, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301418 bank->regs->leveldetect1);
1419 }
1420
Tarun Kanti DebBarma4e962e82012-04-27 19:43:37 +05301421 if (bank->regs->irqstatus_raw0) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001422 writel_relaxed(old0 | l, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301423 bank->regs->leveldetect0);
Victor Kamensky661553b2013-11-16 02:01:04 +02001424 writel_relaxed(old1 | l, bank->base +
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301425 bank->regs->leveldetect1);
1426 }
Victor Kamensky661553b2013-11-16 02:01:04 +02001427 writel_relaxed(old0, bank->base + bank->regs->leveldetect0);
1428 writel_relaxed(old1, bank->base + bank->regs->leveldetect1);
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301429 }
1430
1431 bank->workaround_enabled = false;
1432 spin_unlock_irqrestore(&bank->lock, flags);
1433
1434 return 0;
1435}
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001436#endif /* CONFIG_PM */
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301437
Tony Lindgrencac089f2015-04-23 16:56:22 -07001438#if IS_BUILTIN(CONFIG_GPIO_OMAP)
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301439void omap2_gpio_prepare_for_idle(int pwr_mode)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001440{
Charulatha V03e128c2011-05-05 19:58:01 +05301441 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001442
Charulatha V03e128c2011-05-05 19:58:01 +05301443 list_for_each_entry(bank, &omap_gpio_list, node) {
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +02001444 if (!BANK_USED(bank) || !bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301445 continue;
1446
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301447 bank->power_mode = pwr_mode;
1448
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301449 pm_runtime_put_sync_suspend(bank->dev);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001450 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001451}
1452
Kevin Hilman43ffcd92009-01-27 11:09:24 -08001453void omap2_gpio_resume_after_idle(void)
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001454{
Charulatha V03e128c2011-05-05 19:58:01 +05301455 struct gpio_bank *bank;
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001456
Charulatha V03e128c2011-05-05 19:58:01 +05301457 list_for_each_entry(bank, &omap_gpio_list, node) {
Javier Martinez Canillasfa365e42013-09-25 02:36:52 +02001458 if (!BANK_USED(bank) || !bank->loses_context)
Charulatha V03e128c2011-05-05 19:58:01 +05301459 continue;
1460
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301461 pm_runtime_get_sync(bank->dev);
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001462 }
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001463}
Tony Lindgrencac089f2015-04-23 16:56:22 -07001464#endif
Juha Yrjola3ac4fa92006-12-06 17:13:52 -08001465
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001466#if defined(CONFIG_PM)
Jon Hunter352a2d52013-04-15 13:06:54 -05001467static void omap_gpio_init_context(struct gpio_bank *p)
1468{
1469 struct omap_gpio_reg_offs *regs = p->regs;
1470 void __iomem *base = p->base;
1471
Victor Kamensky661553b2013-11-16 02:01:04 +02001472 p->context.ctrl = readl_relaxed(base + regs->ctrl);
1473 p->context.oe = readl_relaxed(base + regs->direction);
1474 p->context.wake_en = readl_relaxed(base + regs->wkup_en);
1475 p->context.leveldetect0 = readl_relaxed(base + regs->leveldetect0);
1476 p->context.leveldetect1 = readl_relaxed(base + regs->leveldetect1);
1477 p->context.risingdetect = readl_relaxed(base + regs->risingdetect);
1478 p->context.fallingdetect = readl_relaxed(base + regs->fallingdetect);
1479 p->context.irqenable1 = readl_relaxed(base + regs->irqenable);
1480 p->context.irqenable2 = readl_relaxed(base + regs->irqenable2);
Jon Hunter352a2d52013-04-15 13:06:54 -05001481
1482 if (regs->set_dataout && p->regs->clr_dataout)
Victor Kamensky661553b2013-11-16 02:01:04 +02001483 p->context.dataout = readl_relaxed(base + regs->set_dataout);
Jon Hunter352a2d52013-04-15 13:06:54 -05001484 else
Victor Kamensky661553b2013-11-16 02:01:04 +02001485 p->context.dataout = readl_relaxed(base + regs->dataout);
Jon Hunter352a2d52013-04-15 13:06:54 -05001486
1487 p->context_valid = true;
1488}
1489
Tarun Kanti DebBarma60a34372011-09-29 04:47:25 +05301490static void omap_gpio_restore_context(struct gpio_bank *bank)
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301491{
Victor Kamensky661553b2013-11-16 02:01:04 +02001492 writel_relaxed(bank->context.wake_en,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301493 bank->base + bank->regs->wkup_en);
Victor Kamensky661553b2013-11-16 02:01:04 +02001494 writel_relaxed(bank->context.ctrl, bank->base + bank->regs->ctrl);
1495 writel_relaxed(bank->context.leveldetect0,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301496 bank->base + bank->regs->leveldetect0);
Victor Kamensky661553b2013-11-16 02:01:04 +02001497 writel_relaxed(bank->context.leveldetect1,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301498 bank->base + bank->regs->leveldetect1);
Victor Kamensky661553b2013-11-16 02:01:04 +02001499 writel_relaxed(bank->context.risingdetect,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301500 bank->base + bank->regs->risingdetect);
Victor Kamensky661553b2013-11-16 02:01:04 +02001501 writel_relaxed(bank->context.fallingdetect,
Tarun Kanti DebBarmaae10f232011-08-30 15:24:27 +05301502 bank->base + bank->regs->fallingdetect);
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301503 if (bank->regs->set_dataout && bank->regs->clr_dataout)
Victor Kamensky661553b2013-11-16 02:01:04 +02001504 writel_relaxed(bank->context.dataout,
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301505 bank->base + bank->regs->set_dataout);
1506 else
Victor Kamensky661553b2013-11-16 02:01:04 +02001507 writel_relaxed(bank->context.dataout,
Nishanth Menonf86bcc32011-09-09 19:14:08 +05301508 bank->base + bank->regs->dataout);
Victor Kamensky661553b2013-11-16 02:01:04 +02001509 writel_relaxed(bank->context.oe, bank->base + bank->regs->direction);
Nishanth Menon6d13eaa2011-08-29 18:54:50 +05301510
Nishanth Menonae547352011-09-09 19:08:58 +05301511 if (bank->dbck_enable_mask) {
Victor Kamensky661553b2013-11-16 02:01:04 +02001512 writel_relaxed(bank->context.debounce, bank->base +
Nishanth Menonae547352011-09-09 19:08:58 +05301513 bank->regs->debounce);
Victor Kamensky661553b2013-11-16 02:01:04 +02001514 writel_relaxed(bank->context.debounce_en,
Nishanth Menonae547352011-09-09 19:08:58 +05301515 bank->base + bank->regs->debounce_en);
1516 }
Nishanth Menonba805be2011-08-29 18:41:08 +05301517
Victor Kamensky661553b2013-11-16 02:01:04 +02001518 writel_relaxed(bank->context.irqenable1,
Nishanth Menonba805be2011-08-29 18:41:08 +05301519 bank->base + bank->regs->irqenable);
Victor Kamensky661553b2013-11-16 02:01:04 +02001520 writel_relaxed(bank->context.irqenable2,
Nishanth Menonba805be2011-08-29 18:41:08 +05301521 bank->base + bank->regs->irqenable2);
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301522}
Rafael J. Wysockiecb23122014-12-04 01:03:40 +01001523#endif /* CONFIG_PM */
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301524#else
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301525#define omap_gpio_runtime_suspend NULL
1526#define omap_gpio_runtime_resume NULL
Arnd Bergmannea4a21a2013-05-31 17:59:46 +02001527static inline void omap_gpio_init_context(struct gpio_bank *p) {}
Rajendra Nayak40c670f2008-09-26 17:47:48 +05301528#endif
1529
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301530static const struct dev_pm_ops gpio_pm_ops = {
Tarun Kanti DebBarma2dc983c2011-11-24 02:44:29 +05301531 SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume,
1532 NULL)
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301533};
1534
Benoit Cousson384ebe12011-08-16 11:53:02 +02001535#if defined(CONFIG_OF)
1536static struct omap_gpio_reg_offs omap2_gpio_regs = {
1537 .revision = OMAP24XX_GPIO_REVISION,
1538 .direction = OMAP24XX_GPIO_OE,
1539 .datain = OMAP24XX_GPIO_DATAIN,
1540 .dataout = OMAP24XX_GPIO_DATAOUT,
1541 .set_dataout = OMAP24XX_GPIO_SETDATAOUT,
1542 .clr_dataout = OMAP24XX_GPIO_CLEARDATAOUT,
1543 .irqstatus = OMAP24XX_GPIO_IRQSTATUS1,
1544 .irqstatus2 = OMAP24XX_GPIO_IRQSTATUS2,
1545 .irqenable = OMAP24XX_GPIO_IRQENABLE1,
1546 .irqenable2 = OMAP24XX_GPIO_IRQENABLE2,
1547 .set_irqenable = OMAP24XX_GPIO_SETIRQENABLE1,
1548 .clr_irqenable = OMAP24XX_GPIO_CLEARIRQENABLE1,
1549 .debounce = OMAP24XX_GPIO_DEBOUNCE_VAL,
1550 .debounce_en = OMAP24XX_GPIO_DEBOUNCE_EN,
1551 .ctrl = OMAP24XX_GPIO_CTRL,
1552 .wkup_en = OMAP24XX_GPIO_WAKE_EN,
1553 .leveldetect0 = OMAP24XX_GPIO_LEVELDETECT0,
1554 .leveldetect1 = OMAP24XX_GPIO_LEVELDETECT1,
1555 .risingdetect = OMAP24XX_GPIO_RISINGDETECT,
1556 .fallingdetect = OMAP24XX_GPIO_FALLINGDETECT,
1557};
1558
1559static struct omap_gpio_reg_offs omap4_gpio_regs = {
1560 .revision = OMAP4_GPIO_REVISION,
1561 .direction = OMAP4_GPIO_OE,
1562 .datain = OMAP4_GPIO_DATAIN,
1563 .dataout = OMAP4_GPIO_DATAOUT,
1564 .set_dataout = OMAP4_GPIO_SETDATAOUT,
1565 .clr_dataout = OMAP4_GPIO_CLEARDATAOUT,
1566 .irqstatus = OMAP4_GPIO_IRQSTATUS0,
1567 .irqstatus2 = OMAP4_GPIO_IRQSTATUS1,
1568 .irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1569 .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1,
1570 .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0,
1571 .clr_irqenable = OMAP4_GPIO_IRQSTATUSCLR0,
1572 .debounce = OMAP4_GPIO_DEBOUNCINGTIME,
1573 .debounce_en = OMAP4_GPIO_DEBOUNCENABLE,
1574 .ctrl = OMAP4_GPIO_CTRL,
1575 .wkup_en = OMAP4_GPIO_IRQWAKEN0,
1576 .leveldetect0 = OMAP4_GPIO_LEVELDETECT0,
1577 .leveldetect1 = OMAP4_GPIO_LEVELDETECT1,
1578 .risingdetect = OMAP4_GPIO_RISINGDETECT,
1579 .fallingdetect = OMAP4_GPIO_FALLINGDETECT,
1580};
1581
Chen Gange9a65bb2013-02-06 18:44:32 +08001582static const struct omap_gpio_platform_data omap2_pdata = {
Benoit Cousson384ebe12011-08-16 11:53:02 +02001583 .regs = &omap2_gpio_regs,
1584 .bank_width = 32,
1585 .dbck_flag = false,
1586};
1587
Chen Gange9a65bb2013-02-06 18:44:32 +08001588static const struct omap_gpio_platform_data omap3_pdata = {
Benoit Cousson384ebe12011-08-16 11:53:02 +02001589 .regs = &omap2_gpio_regs,
1590 .bank_width = 32,
1591 .dbck_flag = true,
1592};
1593
Chen Gange9a65bb2013-02-06 18:44:32 +08001594static const struct omap_gpio_platform_data omap4_pdata = {
Benoit Cousson384ebe12011-08-16 11:53:02 +02001595 .regs = &omap4_gpio_regs,
1596 .bank_width = 32,
1597 .dbck_flag = true,
1598};
1599
1600static const struct of_device_id omap_gpio_match[] = {
1601 {
1602 .compatible = "ti,omap4-gpio",
1603 .data = &omap4_pdata,
1604 },
1605 {
1606 .compatible = "ti,omap3-gpio",
1607 .data = &omap3_pdata,
1608 },
1609 {
1610 .compatible = "ti,omap2-gpio",
1611 .data = &omap2_pdata,
1612 },
1613 { },
1614};
1615MODULE_DEVICE_TABLE(of, omap_gpio_match);
1616#endif
1617
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001618static struct platform_driver omap_gpio_driver = {
1619 .probe = omap_gpio_probe,
Tony Lindgrencac089f2015-04-23 16:56:22 -07001620 .remove = omap_gpio_remove,
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001621 .driver = {
1622 .name = "omap_gpio",
Tarun Kanti DebBarma55b93c32011-09-29 07:23:22 +05301623 .pm = &gpio_pm_ops,
Benoit Cousson384ebe12011-08-16 11:53:02 +02001624 .of_match_table = of_match_ptr(omap_gpio_match),
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001625 },
1626};
1627
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001628/*
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001629 * gpio driver register needs to be done before
1630 * machine_init functions access gpio APIs.
1631 * Hence omap_gpio_drv_reg() is a postcore_initcall.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001632 */
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001633static int __init omap_gpio_drv_reg(void)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001634{
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001635 return platform_driver_register(&omap_gpio_driver);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001636}
Varadarajan, Charulatha77640aa2010-12-07 16:26:57 -08001637postcore_initcall(omap_gpio_drv_reg);
Tony Lindgrencac089f2015-04-23 16:56:22 -07001638
1639static void __exit omap_gpio_exit(void)
1640{
1641 platform_driver_unregister(&omap_gpio_driver);
1642}
1643module_exit(omap_gpio_exit);
1644
1645MODULE_DESCRIPTION("omap gpio driver");
1646MODULE_ALIAS("platform:gpio-omap");
1647MODULE_LICENSE("GPL v2");