Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1 | /* |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2 | * Support functions for OMAP GPIO |
| 3 | * |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 4 | * Copyright (C) 2003-2005 Nokia Corporation |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 5 | * Written by Juha Yrjölä <juha.yrjola@nokia.com> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 6 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 7 | * Copyright (C) 2009 Texas Instruments |
| 8 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
| 9 | * |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 10 | * 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 Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 18 | #include <linux/syscore_ops.h> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 19 | #include <linux/err.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 20 | #include <linux/clk.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 21 | #include <linux/io.h> |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame^] | 22 | #include <linux/device.h> |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 23 | #include <linux/pm_runtime.h> |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 24 | #include <linux/pm.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 25 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 26 | #include <mach/hardware.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 27 | #include <asm/irq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/irqs.h> |
Russell King | 1bc857f | 2011-07-26 10:54:55 +0100 | [diff] [blame] | 29 | #include <asm/gpio.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 30 | #include <asm/mach/irq.h> |
| 31 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 32 | #define OFF_MODE 1 |
| 33 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 34 | static LIST_HEAD(omap_gpio_list); |
| 35 | |
Charulatha V | 6d62e21 | 2011-04-18 15:06:51 +0000 | [diff] [blame] | 36 | struct gpio_regs { |
| 37 | u32 irqenable1; |
| 38 | u32 irqenable2; |
| 39 | u32 wake_en; |
| 40 | u32 ctrl; |
| 41 | u32 oe; |
| 42 | u32 leveldetect0; |
| 43 | u32 leveldetect1; |
| 44 | u32 risingdetect; |
| 45 | u32 fallingdetect; |
| 46 | u32 dataout; |
Nishanth Menon | ae54735 | 2011-09-09 19:08:58 +0530 | [diff] [blame] | 47 | u32 debounce; |
| 48 | u32 debounce_en; |
Charulatha V | 6d62e21 | 2011-04-18 15:06:51 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 51 | struct gpio_bank { |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 52 | struct list_head node; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 53 | void __iomem *base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 54 | u16 irq; |
| 55 | u16 virtual_irq_start; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 56 | u32 suspend_wakeup; |
| 57 | u32 saved_wakeup; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 58 | u32 non_wakeup_gpios; |
| 59 | u32 enabled_non_wakeup_gpios; |
Charulatha V | 6d62e21 | 2011-04-18 15:06:51 +0000 | [diff] [blame] | 60 | struct gpio_regs context; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 61 | u32 saved_datain; |
| 62 | u32 saved_fallingdetect; |
| 63 | u32 saved_risingdetect; |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 64 | u32 level_mask; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 65 | u32 toggle_mask; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 66 | spinlock_t lock; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 67 | struct gpio_chip chip; |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 68 | struct clk *dbck; |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 69 | u32 mod_usage; |
Kevin Hilman | 8865b9b | 2009-01-27 11:15:34 -0800 | [diff] [blame] | 70 | u32 dbck_enable_mask; |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 71 | bool dbck_enabled; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 72 | struct device *dev; |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 73 | bool is_mpuio; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 74 | bool dbck_flag; |
Charulatha V | 0cde8d0 | 2011-05-05 20:15:16 +0530 | [diff] [blame] | 75 | bool loses_context; |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 76 | int stride; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 77 | u32 width; |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 78 | int context_loss_count; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 79 | int power_mode; |
| 80 | bool workaround_enabled; |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 81 | |
| 82 | void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable); |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 83 | int (*get_context_loss_count)(struct device *dev); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 84 | |
| 85 | struct omap_gpio_reg_offs *regs; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 88 | #define GPIO_INDEX(bank, gpio) (gpio % bank->width) |
| 89 | #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio)) |
Charulatha V | c8eef65 | 2011-05-02 15:21:42 +0530 | [diff] [blame] | 90 | #define GPIO_MOD_CTRL_BIT BIT(0) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 91 | |
| 92 | static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) |
| 93 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 94 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 95 | u32 l; |
| 96 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 97 | reg += bank->regs->direction; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 98 | l = __raw_readl(reg); |
| 99 | if (is_input) |
| 100 | l |= 1 << gpio; |
| 101 | else |
| 102 | l &= ~(1 << gpio); |
| 103 | __raw_writel(l, reg); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 104 | bank->context.oe = l; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 107 | |
| 108 | /* set data out value using dedicate set/clear register */ |
| 109 | static void _set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, int enable) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 110 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 111 | void __iomem *reg = bank->base; |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 112 | u32 l = GPIO_BIT(bank, gpio); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 113 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 114 | if (enable) |
| 115 | reg += bank->regs->set_dataout; |
| 116 | else |
| 117 | reg += bank->regs->clr_dataout; |
| 118 | |
| 119 | __raw_writel(l, reg); |
| 120 | } |
| 121 | |
| 122 | /* set data out value using mask register */ |
| 123 | static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable) |
| 124 | { |
| 125 | void __iomem *reg = bank->base + bank->regs->dataout; |
| 126 | u32 gpio_bit = GPIO_BIT(bank, gpio); |
| 127 | u32 l; |
| 128 | |
| 129 | l = __raw_readl(reg); |
| 130 | if (enable) |
| 131 | l |= gpio_bit; |
| 132 | else |
| 133 | l &= ~gpio_bit; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 134 | __raw_writel(l, reg); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 135 | bank->context.dataout = l; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 138 | static int _get_gpio_datain(struct gpio_bank *bank, int gpio) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 139 | { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 140 | void __iomem *reg = bank->base + bank->regs->datain; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 141 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 142 | return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 143 | } |
| 144 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 145 | static int _get_gpio_dataout(struct gpio_bank *bank, int gpio) |
| 146 | { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 147 | void __iomem *reg = bank->base + bank->regs->dataout; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 148 | |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 149 | return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 150 | } |
| 151 | |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 152 | static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) |
| 153 | { |
| 154 | int l = __raw_readl(base + reg); |
| 155 | |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 156 | if (set) |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 157 | l |= mask; |
| 158 | else |
| 159 | l &= ~mask; |
| 160 | |
| 161 | __raw_writel(l, base + reg); |
| 162 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 163 | |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 164 | static inline void _gpio_dbck_enable(struct gpio_bank *bank) |
| 165 | { |
| 166 | if (bank->dbck_enable_mask && !bank->dbck_enabled) { |
| 167 | clk_enable(bank->dbck); |
| 168 | bank->dbck_enabled = true; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | static inline void _gpio_dbck_disable(struct gpio_bank *bank) |
| 173 | { |
| 174 | if (bank->dbck_enable_mask && bank->dbck_enabled) { |
| 175 | clk_disable(bank->dbck); |
| 176 | bank->dbck_enabled = false; |
| 177 | } |
| 178 | } |
| 179 | |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 180 | /** |
| 181 | * _set_gpio_debounce - low level gpio debounce time |
| 182 | * @bank: the gpio bank we're acting upon |
| 183 | * @gpio: the gpio number on this @gpio |
| 184 | * @debounce: debounce time to use |
| 185 | * |
| 186 | * OMAP's debounce time is in 31us steps so we need |
| 187 | * to convert and round up to the closest unit. |
| 188 | */ |
| 189 | static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio, |
| 190 | unsigned debounce) |
| 191 | { |
Kevin Hilman | 9942da0 | 2011-04-22 12:02:05 -0700 | [diff] [blame] | 192 | void __iomem *reg; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 193 | u32 val; |
| 194 | u32 l; |
| 195 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 196 | if (!bank->dbck_flag) |
| 197 | return; |
| 198 | |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 199 | if (debounce < 32) |
| 200 | debounce = 0x01; |
| 201 | else if (debounce > 7936) |
| 202 | debounce = 0xff; |
| 203 | else |
| 204 | debounce = (debounce / 0x1f) - 1; |
| 205 | |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 206 | l = GPIO_BIT(bank, gpio); |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 207 | |
Tarun Kanti DebBarma | 6fd9c42 | 2011-11-24 03:58:54 +0530 | [diff] [blame] | 208 | clk_enable(bank->dbck); |
Kevin Hilman | 9942da0 | 2011-04-22 12:02:05 -0700 | [diff] [blame] | 209 | reg = bank->base + bank->regs->debounce; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 210 | __raw_writel(debounce, reg); |
| 211 | |
Kevin Hilman | 9942da0 | 2011-04-22 12:02:05 -0700 | [diff] [blame] | 212 | reg = bank->base + bank->regs->debounce_en; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 213 | val = __raw_readl(reg); |
| 214 | |
Tarun Kanti DebBarma | 6fd9c42 | 2011-11-24 03:58:54 +0530 | [diff] [blame] | 215 | if (debounce) |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 216 | val |= l; |
Tarun Kanti DebBarma | 6fd9c42 | 2011-11-24 03:58:54 +0530 | [diff] [blame] | 217 | else |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 218 | val &= ~l; |
Kevin Hilman | f7ec0b0 | 2010-06-09 13:53:07 +0300 | [diff] [blame] | 219 | bank->dbck_enable_mask = val; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 220 | |
| 221 | __raw_writel(val, reg); |
Tarun Kanti DebBarma | 6fd9c42 | 2011-11-24 03:58:54 +0530 | [diff] [blame] | 222 | clk_disable(bank->dbck); |
| 223 | /* |
| 224 | * Enable debounce clock per module. |
| 225 | * This call is mandatory because in omap_gpio_request() when |
| 226 | * *_runtime_get_sync() is called, _gpio_dbck_enable() within |
| 227 | * runtime callbck fails to turn on dbck because dbck_enable_mask |
| 228 | * used within _gpio_dbck_enable() is still not initialized at |
| 229 | * that point. Therefore we have to enable dbck here. |
| 230 | */ |
| 231 | _gpio_dbck_enable(bank); |
Nishanth Menon | ae54735 | 2011-09-09 19:08:58 +0530 | [diff] [blame] | 232 | if (bank->dbck_enable_mask) { |
| 233 | bank->context.debounce = debounce; |
| 234 | bank->context.debounce_en = val; |
| 235 | } |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 238 | static inline void set_gpio_trigger(struct gpio_bank *bank, int gpio, |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 239 | int trigger) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 240 | { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 241 | void __iomem *base = bank->base; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 242 | u32 gpio_bit = 1 << gpio; |
| 243 | |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 244 | _gpio_rmw(base, bank->regs->leveldetect0, gpio_bit, |
| 245 | trigger & IRQ_TYPE_LEVEL_LOW); |
| 246 | _gpio_rmw(base, bank->regs->leveldetect1, gpio_bit, |
| 247 | trigger & IRQ_TYPE_LEVEL_HIGH); |
| 248 | _gpio_rmw(base, bank->regs->risingdetect, gpio_bit, |
| 249 | trigger & IRQ_TYPE_EDGE_RISING); |
| 250 | _gpio_rmw(base, bank->regs->fallingdetect, gpio_bit, |
| 251 | trigger & IRQ_TYPE_EDGE_FALLING); |
| 252 | |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 253 | bank->context.leveldetect0 = |
| 254 | __raw_readl(bank->base + bank->regs->leveldetect0); |
| 255 | bank->context.leveldetect1 = |
| 256 | __raw_readl(bank->base + bank->regs->leveldetect1); |
| 257 | bank->context.risingdetect = |
| 258 | __raw_readl(bank->base + bank->regs->risingdetect); |
| 259 | bank->context.fallingdetect = |
| 260 | __raw_readl(bank->base + bank->regs->fallingdetect); |
| 261 | |
| 262 | if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 263 | _gpio_rmw(base, bank->regs->wkup_en, gpio_bit, trigger != 0); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 264 | bank->context.wake_en = |
| 265 | __raw_readl(bank->base + bank->regs->wkup_en); |
| 266 | } |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 267 | |
Ambresh K | 55b220c | 2011-06-15 13:40:45 -0700 | [diff] [blame] | 268 | /* This part needs to be executed always for OMAP{34xx, 44xx} */ |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 269 | if (!bank->regs->irqctrl) { |
| 270 | /* On omap24xx proceed only when valid GPIO bit is set */ |
| 271 | if (bank->non_wakeup_gpios) { |
| 272 | if (!(bank->non_wakeup_gpios & gpio_bit)) |
| 273 | goto exit; |
| 274 | } |
| 275 | |
Chunqiu Wang | 699117a6 | 2009-06-24 17:13:39 +0000 | [diff] [blame] | 276 | /* |
| 277 | * Log the edge gpio and manually trigger the IRQ |
| 278 | * after resume if the input level changes |
| 279 | * to avoid irq lost during PER RET/OFF mode |
| 280 | * Applies for omap2 non-wakeup gpio and all omap3 gpios |
| 281 | */ |
| 282 | if (trigger & IRQ_TYPE_EDGE_BOTH) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 283 | bank->enabled_non_wakeup_gpios |= gpio_bit; |
| 284 | else |
| 285 | bank->enabled_non_wakeup_gpios &= ~gpio_bit; |
| 286 | } |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 287 | |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 288 | exit: |
Tarun Kanti DebBarma | 9ea14d8 | 2011-08-30 15:05:44 +0530 | [diff] [blame] | 289 | bank->level_mask = |
| 290 | __raw_readl(bank->base + bank->regs->leveldetect0) | |
| 291 | __raw_readl(bank->base + bank->regs->leveldetect1); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 292 | } |
| 293 | |
Uwe Kleine-König | 9198bcd | 2010-01-29 14:20:05 -0800 | [diff] [blame] | 294 | #ifdef CONFIG_ARCH_OMAP1 |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 295 | /* |
| 296 | * This only applies to chips that can't do both rising and falling edge |
| 297 | * detection at once. For all other chips, this function is a noop. |
| 298 | */ |
| 299 | static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) |
| 300 | { |
| 301 | void __iomem *reg = bank->base; |
| 302 | u32 l = 0; |
| 303 | |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 304 | if (!bank->regs->irqctrl) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 305 | return; |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 306 | |
| 307 | reg += bank->regs->irqctrl; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 308 | |
| 309 | l = __raw_readl(reg); |
| 310 | if ((l >> gpio) & 1) |
| 311 | l &= ~(1 << gpio); |
| 312 | else |
| 313 | l |= 1 << gpio; |
| 314 | |
| 315 | __raw_writel(l, reg); |
| 316 | } |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 317 | #else |
| 318 | static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) {} |
Uwe Kleine-König | 9198bcd | 2010-01-29 14:20:05 -0800 | [diff] [blame] | 319 | #endif |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 320 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 321 | static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger) |
| 322 | { |
| 323 | void __iomem *reg = bank->base; |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 324 | void __iomem *base = bank->base; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 325 | u32 l = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 326 | |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 327 | if (bank->regs->leveldetect0 && bank->regs->wkup_en) { |
| 328 | set_gpio_trigger(bank, gpio, trigger); |
| 329 | } else if (bank->regs->irqctrl) { |
| 330 | reg += bank->regs->irqctrl; |
| 331 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 332 | l = __raw_readl(reg); |
Janusz Krzysztofik | 2950157 | 2010-04-05 11:38:06 +0000 | [diff] [blame] | 333 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 334 | bank->toggle_mask |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 335 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 336 | l |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 337 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 338 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 339 | else |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 340 | return -EINVAL; |
| 341 | |
| 342 | __raw_writel(l, reg); |
| 343 | } else if (bank->regs->edgectrl1) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 344 | if (gpio & 0x08) |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 345 | reg += bank->regs->edgectrl2; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 346 | else |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 347 | reg += bank->regs->edgectrl1; |
| 348 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 349 | gpio &= 0x07; |
| 350 | l = __raw_readl(reg); |
| 351 | l &= ~(3 << (gpio << 1)); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 352 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 353 | l |= 2 << (gpio << 1); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 354 | if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 355 | l |= 1 << (gpio << 1); |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 356 | |
| 357 | /* Enable wake-up during idle for dynamic tick */ |
| 358 | _gpio_rmw(base, bank->regs->wkup_en, 1 << gpio, trigger); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 359 | bank->context.wake_en = |
| 360 | __raw_readl(bank->base + bank->regs->wkup_en); |
Tarun Kanti DebBarma | 5e571f3 | 2011-09-13 15:02:14 +0530 | [diff] [blame] | 361 | __raw_writel(l, reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 362 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 363 | return 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 364 | } |
| 365 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 366 | static int gpio_irq_type(struct irq_data *d, unsigned type) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 367 | { |
| 368 | struct gpio_bank *bank; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 369 | unsigned gpio; |
| 370 | int retval; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 371 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 372 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 373 | if (!cpu_class_is_omap2() && d->irq > IH_MPUIO_BASE) |
| 374 | gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 375 | else |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 376 | gpio = d->irq - IH_GPIO_BASE; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 377 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 378 | if (type & ~IRQ_TYPE_SENSE_MASK) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 379 | return -EINVAL; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 380 | |
Tarun Kanti DebBarma | 9ea14d8 | 2011-08-30 15:05:44 +0530 | [diff] [blame] | 381 | bank = irq_data_get_irq_chip_data(d); |
| 382 | |
| 383 | if (!bank->regs->leveldetect0 && |
| 384 | (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 385 | return -EINVAL; |
| 386 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 387 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 388 | retval = _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), type); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 389 | spin_unlock_irqrestore(&bank->lock, flags); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 390 | |
| 391 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 392 | __irq_set_handler_locked(d->irq, handle_level_irq); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 393 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 394 | __irq_set_handler_locked(d->irq, handle_edge_irq); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 395 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 396 | return retval; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
| 400 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 401 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 402 | |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 403 | reg += bank->regs->irqstatus; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 404 | __raw_writel(gpio_mask, reg); |
Hiroshi DOYU | bee7930 | 2006-09-25 12:41:46 +0300 | [diff] [blame] | 405 | |
| 406 | /* Workaround for clearing DSP GPIO interrupts to allow retention */ |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 407 | if (bank->regs->irqstatus2) { |
| 408 | reg = bank->base + bank->regs->irqstatus2; |
Roger Quadros | bedfd15 | 2009-04-23 11:10:50 -0700 | [diff] [blame] | 409 | __raw_writel(gpio_mask, reg); |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 410 | } |
Roger Quadros | bedfd15 | 2009-04-23 11:10:50 -0700 | [diff] [blame] | 411 | |
| 412 | /* Flush posted write for the irq status to avoid spurious interrupts */ |
| 413 | __raw_readl(reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) |
| 417 | { |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 418 | _clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 419 | } |
| 420 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 421 | static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank) |
| 422 | { |
| 423 | void __iomem *reg = bank->base; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 424 | u32 l; |
Kevin Hilman | c390aad0 | 2011-04-21 09:33:36 -0700 | [diff] [blame] | 425 | u32 mask = (1 << bank->width) - 1; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 426 | |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 427 | reg += bank->regs->irqenable; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 428 | l = __raw_readl(reg); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 429 | if (bank->regs->irqenable_inv) |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 430 | l = ~l; |
| 431 | l &= mask; |
| 432 | return l; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 435 | static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 436 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 437 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 438 | u32 l; |
| 439 | |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 440 | if (bank->regs->set_irqenable) { |
| 441 | reg += bank->regs->set_irqenable; |
| 442 | l = gpio_mask; |
| 443 | } else { |
| 444 | reg += bank->regs->irqenable; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 445 | l = __raw_readl(reg); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 446 | if (bank->regs->irqenable_inv) |
| 447 | l &= ~gpio_mask; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 448 | else |
| 449 | l |= gpio_mask; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 450 | } |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 451 | |
| 452 | __raw_writel(l, reg); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 453 | bank->context.irqenable1 = l; |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
| 457 | { |
| 458 | void __iomem *reg = bank->base; |
| 459 | u32 l; |
| 460 | |
| 461 | if (bank->regs->clr_irqenable) { |
| 462 | reg += bank->regs->clr_irqenable; |
| 463 | l = gpio_mask; |
| 464 | } else { |
| 465 | reg += bank->regs->irqenable; |
| 466 | l = __raw_readl(reg); |
| 467 | if (bank->regs->irqenable_inv) |
| 468 | l |= gpio_mask; |
| 469 | else |
| 470 | l &= ~gpio_mask; |
| 471 | } |
| 472 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 473 | __raw_writel(l, reg); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 474 | bank->context.irqenable1 = l; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable) |
| 478 | { |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 479 | _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 482 | /* |
| 483 | * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register. |
| 484 | * 1510 does not seem to have a wake-up register. If JTAG is connected |
| 485 | * to the target, system will wake up always on GPIO events. While |
| 486 | * system is running all registered GPIO interrupts need to have wake-up |
| 487 | * enabled. When system is suspended, only selected GPIO interrupts need |
| 488 | * to have wake-up enabled. |
| 489 | */ |
| 490 | static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) |
| 491 | { |
Kevin Hilman | f64ad1a | 2011-04-22 09:45:27 -0700 | [diff] [blame] | 492 | u32 gpio_bit = GPIO_BIT(bank, gpio); |
| 493 | unsigned long flags; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 494 | |
Kevin Hilman | f64ad1a | 2011-04-22 09:45:27 -0700 | [diff] [blame] | 495 | if (bank->non_wakeup_gpios & gpio_bit) { |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 496 | dev_err(bank->dev, |
Kevin Hilman | f64ad1a | 2011-04-22 09:45:27 -0700 | [diff] [blame] | 497 | "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 498 | return -EINVAL; |
| 499 | } |
Kevin Hilman | f64ad1a | 2011-04-22 09:45:27 -0700 | [diff] [blame] | 500 | |
| 501 | spin_lock_irqsave(&bank->lock, flags); |
| 502 | if (enable) |
| 503 | bank->suspend_wakeup |= gpio_bit; |
| 504 | else |
| 505 | bank->suspend_wakeup &= ~gpio_bit; |
| 506 | |
| 507 | spin_unlock_irqrestore(&bank->lock, flags); |
| 508 | |
| 509 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 510 | } |
| 511 | |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 512 | static void _reset_gpio(struct gpio_bank *bank, int gpio) |
| 513 | { |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 514 | _set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 515 | _set_gpio_irqenable(bank, gpio, 0); |
| 516 | _clear_gpio_irqstatus(bank, gpio); |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 517 | _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 518 | } |
| 519 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 520 | /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 521 | static int gpio_wake_enable(struct irq_data *d, unsigned int enable) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 522 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 523 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 524 | struct gpio_bank *bank; |
| 525 | int retval; |
| 526 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 527 | bank = irq_data_get_irq_chip_data(d); |
Kevin Hilman | f64ad1a | 2011-04-22 09:45:27 -0700 | [diff] [blame] | 528 | retval = _set_gpio_wakeup(bank, gpio, enable); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 529 | |
| 530 | return retval; |
| 531 | } |
| 532 | |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 533 | static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 534 | { |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 535 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 536 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 537 | |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 538 | /* |
| 539 | * If this is the first gpio_request for the bank, |
| 540 | * enable the bank module. |
| 541 | */ |
| 542 | if (!bank->mod_usage) |
| 543 | pm_runtime_get_sync(bank->dev); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 544 | |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 545 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 546 | /* Set trigger to none. You need to enable the desired trigger with |
| 547 | * request_irq() or set_irq_type(). |
| 548 | */ |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 549 | _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 550 | |
Charulatha V | fad96ea | 2011-05-25 11:23:50 +0530 | [diff] [blame] | 551 | if (bank->regs->pinctrl) { |
| 552 | void __iomem *reg = bank->base + bank->regs->pinctrl; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 553 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 554 | /* Claim the pin for MPU */ |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 555 | __raw_writel(__raw_readl(reg) | (1 << offset), reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 556 | } |
Charulatha V | fad96ea | 2011-05-25 11:23:50 +0530 | [diff] [blame] | 557 | |
Charulatha V | c8eef65 | 2011-05-02 15:21:42 +0530 | [diff] [blame] | 558 | if (bank->regs->ctrl && !bank->mod_usage) { |
| 559 | void __iomem *reg = bank->base + bank->regs->ctrl; |
| 560 | u32 ctrl; |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 561 | |
Charulatha V | c8eef65 | 2011-05-02 15:21:42 +0530 | [diff] [blame] | 562 | ctrl = __raw_readl(reg); |
| 563 | /* Module is enabled, clocks are not gated */ |
| 564 | ctrl &= ~GPIO_MOD_CTRL_BIT; |
| 565 | __raw_writel(ctrl, reg); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 566 | bank->context.ctrl = ctrl; |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 567 | } |
Charulatha V | c8eef65 | 2011-05-02 15:21:42 +0530 | [diff] [blame] | 568 | |
| 569 | bank->mod_usage |= 1 << offset; |
| 570 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 571 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 576 | static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 577 | { |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 578 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); |
Tarun Kanti DebBarma | 6ed87c5 | 2011-09-13 14:41:44 +0530 | [diff] [blame] | 579 | void __iomem *base = bank->base; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 580 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 581 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 582 | spin_lock_irqsave(&bank->lock, flags); |
Tarun Kanti DebBarma | 6ed87c5 | 2011-09-13 14:41:44 +0530 | [diff] [blame] | 583 | |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 584 | if (bank->regs->wkup_en) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 585 | /* Disable wake-up during idle for dynamic tick */ |
Tarun Kanti DebBarma | 6ed87c5 | 2011-09-13 14:41:44 +0530 | [diff] [blame] | 586 | _gpio_rmw(base, bank->regs->wkup_en, 1 << offset, 0); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 587 | bank->context.wake_en = |
| 588 | __raw_readl(bank->base + bank->regs->wkup_en); |
| 589 | } |
Tarun Kanti DebBarma | 6ed87c5 | 2011-09-13 14:41:44 +0530 | [diff] [blame] | 590 | |
Charulatha V | c8eef65 | 2011-05-02 15:21:42 +0530 | [diff] [blame] | 591 | bank->mod_usage &= ~(1 << offset); |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 592 | |
Charulatha V | c8eef65 | 2011-05-02 15:21:42 +0530 | [diff] [blame] | 593 | if (bank->regs->ctrl && !bank->mod_usage) { |
| 594 | void __iomem *reg = bank->base + bank->regs->ctrl; |
| 595 | u32 ctrl; |
| 596 | |
| 597 | ctrl = __raw_readl(reg); |
| 598 | /* Module is disabled, clocks are gated */ |
| 599 | ctrl |= GPIO_MOD_CTRL_BIT; |
| 600 | __raw_writel(ctrl, reg); |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 601 | bank->context.ctrl = ctrl; |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 602 | } |
Charulatha V | c8eef65 | 2011-05-02 15:21:42 +0530 | [diff] [blame] | 603 | |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 604 | _reset_gpio(bank, bank->chip.base + offset); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 605 | spin_unlock_irqrestore(&bank->lock, flags); |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 606 | |
| 607 | /* |
| 608 | * If this is the last gpio to be freed in the bank, |
| 609 | * disable the bank module. |
| 610 | */ |
| 611 | if (!bank->mod_usage) |
| 612 | pm_runtime_put(bank->dev); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /* |
| 616 | * We need to unmask the GPIO bank interrupt as soon as possible to |
| 617 | * avoid missing GPIO interrupts for other lines in the bank. |
| 618 | * Then we need to mask-read-clear-unmask the triggered GPIO lines |
| 619 | * in the bank to avoid missing nested interrupts for a GPIO line. |
| 620 | * If we wait to unmask individual GPIO lines in the bank after the |
| 621 | * line's interrupt handler has been run, we may miss some nested |
| 622 | * interrupts. |
| 623 | */ |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 624 | static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 625 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 626 | void __iomem *isr_reg = NULL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 627 | u32 isr; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 628 | unsigned int gpio_irq, gpio_index; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 629 | struct gpio_bank *bank; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 630 | u32 retrigger = 0; |
| 631 | int unmasked = 0; |
Will Deacon | ee14418 | 2011-02-21 13:46:08 +0000 | [diff] [blame] | 632 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 633 | |
Will Deacon | ee14418 | 2011-02-21 13:46:08 +0000 | [diff] [blame] | 634 | chained_irq_enter(chip, desc); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 635 | |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 636 | bank = irq_get_handler_data(irq); |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 637 | isr_reg = bank->base + bank->regs->irqstatus; |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 638 | pm_runtime_get_sync(bank->dev); |
Evgeny Kuznetsov | b1cc4c5 | 2010-12-07 16:25:40 -0800 | [diff] [blame] | 639 | |
| 640 | if (WARN_ON(!isr_reg)) |
| 641 | goto exit; |
| 642 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 643 | while(1) { |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 644 | u32 isr_saved, level_mask = 0; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 645 | u32 enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 646 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 647 | enabled = _get_gpio_irqbank_mask(bank); |
| 648 | isr_saved = isr = __raw_readl(isr_reg) & enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 649 | |
Tarun Kanti DebBarma | 9ea14d8 | 2011-08-30 15:05:44 +0530 | [diff] [blame] | 650 | if (bank->level_mask) |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 651 | level_mask = bank->level_mask & enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 652 | |
| 653 | /* clear edge sensitive interrupts before handler(s) are |
| 654 | called so that we don't miss any interrupt occurred while |
| 655 | executing them */ |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 656 | _disable_gpio_irqbank(bank, isr_saved & ~level_mask); |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 657 | _clear_gpio_irqbank(bank, isr_saved & ~level_mask); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 658 | _enable_gpio_irqbank(bank, isr_saved & ~level_mask); |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 659 | |
| 660 | /* if there is only edge sensitive GPIO pin interrupts |
| 661 | configured, we could unmask GPIO bank interrupt immediately */ |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 662 | if (!level_mask && !unmasked) { |
| 663 | unmasked = 1; |
Will Deacon | ee14418 | 2011-02-21 13:46:08 +0000 | [diff] [blame] | 664 | chained_irq_exit(chip, desc); |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 665 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 666 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 667 | isr |= retrigger; |
| 668 | retrigger = 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 669 | if (!isr) |
| 670 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 671 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 672 | gpio_irq = bank->virtual_irq_start; |
| 673 | for (; isr != 0; isr >>= 1, gpio_irq++) { |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 674 | gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq)); |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 675 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 676 | if (!(isr & 1)) |
| 677 | continue; |
Thomas Gleixner | 29454dd | 2006-07-03 02:22:22 +0200 | [diff] [blame] | 678 | |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 679 | /* |
| 680 | * Some chips can't respond to both rising and falling |
| 681 | * at the same time. If this irq was requested with |
| 682 | * both flags, we need to flip the ICR data for the IRQ |
| 683 | * to respond to the IRQ for the opposite direction. |
| 684 | * This will be indicated in the bank toggle_mask. |
| 685 | */ |
| 686 | if (bank->toggle_mask & (1 << gpio_index)) |
| 687 | _toggle_gpio_edge_triggering(bank, gpio_index); |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 688 | |
Dmitry Baryshkov | d8aa025 | 2008-10-09 13:36:24 +0100 | [diff] [blame] | 689 | generic_handle_irq(gpio_irq); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 690 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 691 | } |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 692 | /* if bank has any level sensitive GPIO pin interrupt |
| 693 | configured, we must unmask the bank interrupt only after |
| 694 | handler(s) are executed in order to avoid spurious bank |
| 695 | interrupt */ |
Evgeny Kuznetsov | b1cc4c5 | 2010-12-07 16:25:40 -0800 | [diff] [blame] | 696 | exit: |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 697 | if (!unmasked) |
Will Deacon | ee14418 | 2011-02-21 13:46:08 +0000 | [diff] [blame] | 698 | chained_irq_exit(chip, desc); |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 699 | pm_runtime_put(bank->dev); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 700 | } |
| 701 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 702 | static void gpio_irq_shutdown(struct irq_data *d) |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 703 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 704 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
| 705 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 706 | unsigned long flags; |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 707 | |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 708 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 709 | _reset_gpio(bank, gpio); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 710 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 711 | } |
| 712 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 713 | static void gpio_ack_irq(struct irq_data *d) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 714 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 715 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
| 716 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 717 | |
| 718 | _clear_gpio_irqstatus(bank, gpio); |
| 719 | } |
| 720 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 721 | static void gpio_mask_irq(struct irq_data *d) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 722 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 723 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
| 724 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 725 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 726 | |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 727 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 728 | _set_gpio_irqenable(bank, gpio, 0); |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 729 | _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 730 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 731 | } |
| 732 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 733 | static void gpio_unmask_irq(struct irq_data *d) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 734 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 735 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
| 736 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 737 | unsigned int irq_mask = GPIO_BIT(bank, gpio); |
Thomas Gleixner | 8c04a17 | 2011-03-24 12:40:15 +0100 | [diff] [blame] | 738 | u32 trigger = irqd_get_trigger_type(d); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 739 | unsigned long flags; |
Kevin Hilman | 55b6019 | 2009-06-04 15:57:10 -0700 | [diff] [blame] | 740 | |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 741 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | 55b6019 | 2009-06-04 15:57:10 -0700 | [diff] [blame] | 742 | if (trigger) |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 743 | _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger); |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 744 | |
| 745 | /* For level-triggered GPIOs, the clearing must be done after |
| 746 | * the HW source is cleared, thus after the handler has run */ |
| 747 | if (bank->level_mask & irq_mask) { |
| 748 | _set_gpio_irqenable(bank, gpio, 0); |
| 749 | _clear_gpio_irqstatus(bank, gpio); |
| 750 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 751 | |
Kevin Hilman | 4de8c75 | 2008-01-16 21:56:14 -0800 | [diff] [blame] | 752 | _set_gpio_irqenable(bank, gpio, 1); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 753 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 754 | } |
| 755 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 756 | static struct irq_chip gpio_irq_chip = { |
| 757 | .name = "GPIO", |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 758 | .irq_shutdown = gpio_irq_shutdown, |
| 759 | .irq_ack = gpio_ack_irq, |
| 760 | .irq_mask = gpio_mask_irq, |
| 761 | .irq_unmask = gpio_unmask_irq, |
| 762 | .irq_set_type = gpio_irq_type, |
| 763 | .irq_set_wake = gpio_wake_enable, |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 764 | }; |
| 765 | |
| 766 | /*---------------------------------------------------------------------*/ |
| 767 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 768 | static int omap_mpuio_suspend_noirq(struct device *dev) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 769 | { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 770 | struct platform_device *pdev = to_platform_device(dev); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 771 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 772 | void __iomem *mask_reg = bank->base + |
| 773 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 774 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 775 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 776 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 777 | bank->saved_wakeup = __raw_readl(mask_reg); |
| 778 | __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 779 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 780 | |
| 781 | return 0; |
| 782 | } |
| 783 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 784 | static int omap_mpuio_resume_noirq(struct device *dev) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 785 | { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 786 | struct platform_device *pdev = to_platform_device(dev); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 787 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 788 | void __iomem *mask_reg = bank->base + |
| 789 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 790 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 791 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 792 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 793 | __raw_writel(bank->saved_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 794 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 799 | static const struct dev_pm_ops omap_mpuio_dev_pm_ops = { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 800 | .suspend_noirq = omap_mpuio_suspend_noirq, |
| 801 | .resume_noirq = omap_mpuio_resume_noirq, |
| 802 | }; |
| 803 | |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 804 | /* use platform_driver for this. */ |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 805 | static struct platform_driver omap_mpuio_driver = { |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 806 | .driver = { |
| 807 | .name = "mpuio", |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 808 | .pm = &omap_mpuio_dev_pm_ops, |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 809 | }, |
| 810 | }; |
| 811 | |
| 812 | static struct platform_device omap_mpuio_device = { |
| 813 | .name = "mpuio", |
| 814 | .id = -1, |
| 815 | .dev = { |
| 816 | .driver = &omap_mpuio_driver.driver, |
| 817 | } |
| 818 | /* could list the /proc/iomem resources */ |
| 819 | }; |
| 820 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 821 | static inline void mpuio_init(struct gpio_bank *bank) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 822 | { |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 823 | platform_set_drvdata(&omap_mpuio_device, bank); |
David Brownell | fcf126d | 2007-04-02 12:46:47 -0700 | [diff] [blame] | 824 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 825 | if (platform_driver_register(&omap_mpuio_driver) == 0) |
| 826 | (void) platform_device_register(&omap_mpuio_device); |
| 827 | } |
| 828 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 829 | /*---------------------------------------------------------------------*/ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 830 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 831 | static int gpio_input(struct gpio_chip *chip, unsigned offset) |
| 832 | { |
| 833 | struct gpio_bank *bank; |
| 834 | unsigned long flags; |
| 835 | |
| 836 | bank = container_of(chip, struct gpio_bank, chip); |
| 837 | spin_lock_irqsave(&bank->lock, flags); |
| 838 | _set_gpio_direction(bank, offset, 1); |
| 839 | spin_unlock_irqrestore(&bank->lock, flags); |
| 840 | return 0; |
| 841 | } |
| 842 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 843 | static int gpio_is_input(struct gpio_bank *bank, int mask) |
| 844 | { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 845 | void __iomem *reg = bank->base + bank->regs->direction; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 846 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 847 | return __raw_readl(reg) & mask; |
| 848 | } |
| 849 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 850 | static int gpio_get(struct gpio_chip *chip, unsigned offset) |
| 851 | { |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 852 | struct gpio_bank *bank; |
| 853 | void __iomem *reg; |
| 854 | int gpio; |
| 855 | u32 mask; |
| 856 | |
| 857 | gpio = chip->base + offset; |
Charulatha V | a8be8da | 2011-04-22 16:38:16 +0530 | [diff] [blame] | 858 | bank = container_of(chip, struct gpio_bank, chip); |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 859 | reg = bank->base; |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 860 | mask = GPIO_BIT(bank, gpio); |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 861 | |
| 862 | if (gpio_is_input(bank, mask)) |
| 863 | return _get_gpio_datain(bank, gpio); |
| 864 | else |
| 865 | return _get_gpio_dataout(bank, gpio); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) |
| 869 | { |
| 870 | struct gpio_bank *bank; |
| 871 | unsigned long flags; |
| 872 | |
| 873 | bank = container_of(chip, struct gpio_bank, chip); |
| 874 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 875 | bank->set_dataout(bank, offset, value); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 876 | _set_gpio_direction(bank, offset, 0); |
| 877 | spin_unlock_irqrestore(&bank->lock, flags); |
| 878 | return 0; |
| 879 | } |
| 880 | |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 881 | static int gpio_debounce(struct gpio_chip *chip, unsigned offset, |
| 882 | unsigned debounce) |
| 883 | { |
| 884 | struct gpio_bank *bank; |
| 885 | unsigned long flags; |
| 886 | |
| 887 | bank = container_of(chip, struct gpio_bank, chip); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 888 | |
| 889 | if (!bank->dbck) { |
| 890 | bank->dbck = clk_get(bank->dev, "dbclk"); |
| 891 | if (IS_ERR(bank->dbck)) |
| 892 | dev_err(bank->dev, "Could not get gpio dbck\n"); |
| 893 | } |
| 894 | |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 895 | spin_lock_irqsave(&bank->lock, flags); |
| 896 | _set_gpio_debounce(bank, offset, debounce); |
| 897 | spin_unlock_irqrestore(&bank->lock, flags); |
| 898 | |
| 899 | return 0; |
| 900 | } |
| 901 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 902 | static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 903 | { |
| 904 | struct gpio_bank *bank; |
| 905 | unsigned long flags; |
| 906 | |
| 907 | bank = container_of(chip, struct gpio_bank, chip); |
| 908 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 909 | bank->set_dataout(bank, offset, value); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 910 | spin_unlock_irqrestore(&bank->lock, flags); |
| 911 | } |
| 912 | |
David Brownell | a007b70 | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 913 | static int gpio_2irq(struct gpio_chip *chip, unsigned offset) |
| 914 | { |
| 915 | struct gpio_bank *bank; |
| 916 | |
| 917 | bank = container_of(chip, struct gpio_bank, chip); |
| 918 | return bank->virtual_irq_start + offset; |
| 919 | } |
| 920 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 921 | /*---------------------------------------------------------------------*/ |
| 922 | |
Tony Lindgren | 9a74805 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 923 | static void __init omap_gpio_show_rev(struct gpio_bank *bank) |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 924 | { |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 925 | static bool called; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 926 | u32 rev; |
| 927 | |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 928 | if (called || bank->regs->revision == USHRT_MAX) |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 929 | return; |
| 930 | |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 931 | rev = __raw_readw(bank->base + bank->regs->revision); |
| 932 | pr_info("OMAP GPIO hardware version %d.%d\n", |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 933 | (rev >> 4) & 0x0f, rev & 0x0f); |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 934 | |
| 935 | called = true; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 936 | } |
| 937 | |
David Brownell | 8ba55c5 | 2008-02-26 11:10:50 -0800 | [diff] [blame] | 938 | /* This lock class tells lockdep that GPIO irqs are in a different |
| 939 | * category than their parents, so it won't report false recursion. |
| 940 | */ |
| 941 | static struct lock_class_key gpio_lock_class; |
| 942 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 943 | static void omap_gpio_mod_init(struct gpio_bank *bank) |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 944 | { |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 945 | void __iomem *base = bank->base; |
| 946 | u32 l = 0xffffffff; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 947 | |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 948 | if (bank->width == 16) |
| 949 | l = 0xffff; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 950 | |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 951 | if (bank->is_mpuio) { |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 952 | __raw_writel(l, bank->base + bank->regs->irqenable); |
| 953 | return; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 954 | } |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 955 | |
| 956 | _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->irqenable_inv); |
| 957 | _gpio_rmw(base, bank->regs->irqstatus, l, |
| 958 | bank->regs->irqenable_inv == false); |
| 959 | _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->debounce_en != 0); |
| 960 | _gpio_rmw(base, bank->regs->irqenable, l, bank->regs->ctrl != 0); |
| 961 | if (bank->regs->debounce_en) |
| 962 | _gpio_rmw(base, bank->regs->debounce_en, 0, 1); |
| 963 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 964 | /* Save OE default value (0xffffffff) in the context */ |
| 965 | bank->context.oe = __raw_readl(bank->base + bank->regs->direction); |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 966 | /* Initialize interface clk ungated, module enabled */ |
| 967 | if (bank->regs->ctrl) |
| 968 | _gpio_rmw(base, bank->regs->ctrl, 0, 1); |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 969 | } |
| 970 | |
Kevin Hilman | f8b46b5 | 2011-04-21 13:23:34 -0700 | [diff] [blame] | 971 | static __init void |
| 972 | omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start, |
| 973 | unsigned int num) |
| 974 | { |
| 975 | struct irq_chip_generic *gc; |
| 976 | struct irq_chip_type *ct; |
| 977 | |
| 978 | gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base, |
| 979 | handle_simple_irq); |
Todd Poynor | 8323374 | 2011-07-18 07:43:14 -0700 | [diff] [blame] | 980 | if (!gc) { |
| 981 | dev_err(bank->dev, "Memory alloc failed for gc\n"); |
| 982 | return; |
| 983 | } |
| 984 | |
Kevin Hilman | f8b46b5 | 2011-04-21 13:23:34 -0700 | [diff] [blame] | 985 | ct = gc->chip_types; |
| 986 | |
| 987 | /* NOTE: No ack required, reading IRQ status clears it. */ |
| 988 | ct->chip.irq_mask = irq_gc_mask_set_bit; |
| 989 | ct->chip.irq_unmask = irq_gc_mask_clr_bit; |
| 990 | ct->chip.irq_set_type = gpio_irq_type; |
Tarun Kanti DebBarma | 6ed87c5 | 2011-09-13 14:41:44 +0530 | [diff] [blame] | 991 | |
| 992 | if (bank->regs->wkup_en) |
Kevin Hilman | f8b46b5 | 2011-04-21 13:23:34 -0700 | [diff] [blame] | 993 | ct->chip.irq_set_wake = gpio_wake_enable, |
| 994 | |
| 995 | ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride; |
| 996 | irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, |
| 997 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); |
| 998 | } |
| 999 | |
Russell King | d52b31d | 2011-05-27 13:56:12 -0700 | [diff] [blame] | 1000 | static void __devinit omap_gpio_chip_init(struct gpio_bank *bank) |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1001 | { |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1002 | int j; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1003 | static int gpio; |
| 1004 | |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1005 | /* |
| 1006 | * REVISIT eventually switch from OMAP-specific gpio structs |
| 1007 | * over to the generic ones |
| 1008 | */ |
| 1009 | bank->chip.request = omap_gpio_request; |
| 1010 | bank->chip.free = omap_gpio_free; |
| 1011 | bank->chip.direction_input = gpio_input; |
| 1012 | bank->chip.get = gpio_get; |
| 1013 | bank->chip.direction_output = gpio_output; |
| 1014 | bank->chip.set_debounce = gpio_debounce; |
| 1015 | bank->chip.set = gpio_set; |
| 1016 | bank->chip.to_irq = gpio_2irq; |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 1017 | if (bank->is_mpuio) { |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1018 | bank->chip.label = "mpuio"; |
Tarun Kanti DebBarma | 6ed87c5 | 2011-09-13 14:41:44 +0530 | [diff] [blame] | 1019 | if (bank->regs->wkup_en) |
| 1020 | bank->chip.dev = &omap_mpuio_device.dev; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1021 | bank->chip.base = OMAP_MPUIO(0); |
| 1022 | } else { |
| 1023 | bank->chip.label = "gpio"; |
| 1024 | bank->chip.base = gpio; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1025 | gpio += bank->width; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1026 | } |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1027 | bank->chip.ngpio = bank->width; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1028 | |
| 1029 | gpiochip_add(&bank->chip); |
| 1030 | |
| 1031 | for (j = bank->virtual_irq_start; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1032 | j < bank->virtual_irq_start + bank->width; j++) { |
Thomas Gleixner | 1475b85 | 2011-03-22 17:11:09 +0100 | [diff] [blame] | 1033 | irq_set_lockdep_class(j, &gpio_lock_class); |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 1034 | irq_set_chip_data(j, bank); |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 1035 | if (bank->is_mpuio) { |
Kevin Hilman | f8b46b5 | 2011-04-21 13:23:34 -0700 | [diff] [blame] | 1036 | omap_mpuio_alloc_gc(bank, j, bank->width); |
| 1037 | } else { |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 1038 | irq_set_chip(j, &gpio_irq_chip); |
Kevin Hilman | f8b46b5 | 2011-04-21 13:23:34 -0700 | [diff] [blame] | 1039 | irq_set_handler(j, handle_simple_irq); |
| 1040 | set_irq_flags(j, IRQF_VALID); |
| 1041 | } |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1042 | } |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 1043 | irq_set_chained_handler(bank->irq, gpio_irq_handler); |
| 1044 | irq_set_handler_data(bank->irq, bank); |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1045 | } |
| 1046 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1047 | static int __devinit omap_gpio_probe(struct platform_device *pdev) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1048 | { |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 1049 | struct device *dev = &pdev->dev; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1050 | struct omap_gpio_platform_data *pdata; |
| 1051 | struct resource *res; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1052 | struct gpio_bank *bank; |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1053 | int ret = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1054 | |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame^] | 1055 | if (!dev->platform_data) |
| 1056 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1057 | |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame^] | 1058 | bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL); |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1059 | if (!bank) { |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 1060 | dev_err(dev, "Memory alloc failed\n"); |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame^] | 1061 | return -ENOMEM; |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1062 | } |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1063 | |
| 1064 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1065 | if (unlikely(!res)) { |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 1066 | dev_err(dev, "Invalid IRQ resource\n"); |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame^] | 1067 | return -ENODEV; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | bank->irq = res->start; |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1071 | |
| 1072 | pdata = pdev->dev.platform_data; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1073 | bank->virtual_irq_start = pdata->virtual_irq_start; |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 1074 | bank->dev = dev; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1075 | bank->dbck_flag = pdata->dbck_flag; |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 1076 | bank->stride = pdata->bank_stride; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1077 | bank->width = pdata->bank_width; |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 1078 | bank->is_mpuio = pdata->is_mpuio; |
Charulatha V | 803a243 | 2011-05-05 17:04:12 +0530 | [diff] [blame] | 1079 | bank->non_wakeup_gpios = pdata->non_wakeup_gpios; |
Charulatha V | 0cde8d0 | 2011-05-05 20:15:16 +0530 | [diff] [blame] | 1080 | bank->loses_context = pdata->loses_context; |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1081 | bank->get_context_loss_count = pdata->get_context_loss_count; |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 1082 | bank->regs = pdata->regs; |
| 1083 | |
| 1084 | if (bank->regs->set_dataout && bank->regs->clr_dataout) |
| 1085 | bank->set_dataout = _set_gpio_dataout_reg; |
| 1086 | else |
| 1087 | bank->set_dataout = _set_gpio_dataout_mask; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1088 | |
| 1089 | spin_lock_init(&bank->lock); |
| 1090 | |
| 1091 | /* Static mapping, never released */ |
| 1092 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1093 | if (unlikely(!res)) { |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 1094 | dev_err(dev, "Invalid mem resource\n"); |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame^] | 1095 | return -ENODEV; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1096 | } |
| 1097 | |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame^] | 1098 | if (!devm_request_mem_region(dev, res->start, resource_size(res), |
| 1099 | pdev->name)) { |
| 1100 | dev_err(dev, "Region already claimed\n"); |
| 1101 | return -EBUSY; |
| 1102 | } |
| 1103 | |
| 1104 | bank->base = devm_ioremap(dev, res->start, resource_size(res)); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1105 | if (!bank->base) { |
Benoit Cousson | 862ff64 | 2012-02-01 15:58:56 +0100 | [diff] [blame] | 1106 | dev_err(dev, "Could not ioremap\n"); |
Benoit Cousson | 96751fc | 2012-02-01 16:01:39 +0100 | [diff] [blame^] | 1107 | return -ENOMEM; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1108 | } |
| 1109 | |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1110 | platform_set_drvdata(pdev, bank); |
| 1111 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1112 | pm_runtime_enable(bank->dev); |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1113 | pm_runtime_irq_safe(bank->dev); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1114 | pm_runtime_get_sync(bank->dev); |
| 1115 | |
Charulatha V | d0d665a | 2011-08-31 00:02:21 +0530 | [diff] [blame] | 1116 | if (bank->is_mpuio) |
Tarun Kanti DebBarma | ab985f0 | 2011-09-13 15:12:05 +0530 | [diff] [blame] | 1117 | mpuio_init(bank); |
| 1118 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1119 | omap_gpio_mod_init(bank); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1120 | omap_gpio_chip_init(bank); |
Tony Lindgren | 9a74805 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 1121 | omap_gpio_show_rev(bank); |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1122 | |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1123 | pm_runtime_put(bank->dev); |
| 1124 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1125 | list_add_tail(&bank->node, &omap_gpio_list); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1126 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1127 | return ret; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1128 | } |
| 1129 | |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1130 | #ifdef CONFIG_ARCH_OMAP2PLUS |
| 1131 | |
| 1132 | #if defined(CONFIG_PM_SLEEP) |
| 1133 | static int omap_gpio_suspend(struct device *dev) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1134 | { |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1135 | struct platform_device *pdev = to_platform_device(dev); |
| 1136 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1137 | void __iomem *base = bank->base; |
| 1138 | void __iomem *wakeup_enable; |
| 1139 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1140 | |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1141 | if (!bank->mod_usage || !bank->loses_context) |
| 1142 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1143 | |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1144 | if (!bank->regs->wkup_en || !bank->suspend_wakeup) |
| 1145 | return 0; |
Tarun Kanti DebBarma | 6ed87c5 | 2011-09-13 14:41:44 +0530 | [diff] [blame] | 1146 | |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1147 | wakeup_enable = bank->base + bank->regs->wkup_en; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1148 | |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1149 | spin_lock_irqsave(&bank->lock, flags); |
| 1150 | bank->saved_wakeup = __raw_readl(wakeup_enable); |
| 1151 | _gpio_rmw(base, bank->regs->wkup_en, 0xffffffff, 0); |
| 1152 | _gpio_rmw(base, bank->regs->wkup_en, bank->suspend_wakeup, 1); |
| 1153 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1158 | static int omap_gpio_resume(struct device *dev) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1159 | { |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1160 | struct platform_device *pdev = to_platform_device(dev); |
| 1161 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1162 | void __iomem *base = bank->base; |
| 1163 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1164 | |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1165 | if (!bank->mod_usage || !bank->loses_context) |
| 1166 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1167 | |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1168 | if (!bank->regs->wkup_en || !bank->saved_wakeup) |
| 1169 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1170 | |
Tarun Kanti DebBarma | 065cd79 | 2011-11-24 01:48:52 +0530 | [diff] [blame] | 1171 | spin_lock_irqsave(&bank->lock, flags); |
| 1172 | _gpio_rmw(base, bank->regs->wkup_en, 0xffffffff, 0); |
| 1173 | _gpio_rmw(base, bank->regs->wkup_en, bank->saved_wakeup, 1); |
| 1174 | spin_unlock_irqrestore(&bank->lock, flags); |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1175 | |
| 1176 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1177 | } |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1178 | #endif /* CONFIG_PM_SLEEP */ |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1179 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1180 | #if defined(CONFIG_PM_RUNTIME) |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1181 | static void omap_gpio_restore_context(struct gpio_bank *bank); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1182 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1183 | static int omap_gpio_runtime_suspend(struct device *dev) |
| 1184 | { |
| 1185 | struct platform_device *pdev = to_platform_device(dev); |
| 1186 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1187 | u32 l1 = 0, l2 = 0; |
| 1188 | unsigned long flags; |
| 1189 | |
| 1190 | spin_lock_irqsave(&bank->lock, flags); |
| 1191 | if (bank->power_mode != OFF_MODE) { |
| 1192 | bank->power_mode = 0; |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 1193 | goto update_gpio_context_count; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1194 | } |
| 1195 | /* |
| 1196 | * If going to OFF, remove triggering for all |
| 1197 | * non-wakeup GPIOs. Otherwise spurious IRQs will be |
| 1198 | * generated. See OMAP2420 Errata item 1.101. |
| 1199 | */ |
| 1200 | if (!(bank->enabled_non_wakeup_gpios)) |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 1201 | goto update_gpio_context_count; |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1202 | |
| 1203 | bank->saved_datain = __raw_readl(bank->base + |
| 1204 | bank->regs->datain); |
| 1205 | l1 = __raw_readl(bank->base + bank->regs->fallingdetect); |
| 1206 | l2 = __raw_readl(bank->base + bank->regs->risingdetect); |
| 1207 | |
| 1208 | bank->saved_fallingdetect = l1; |
| 1209 | bank->saved_risingdetect = l2; |
| 1210 | l1 &= ~bank->enabled_non_wakeup_gpios; |
| 1211 | l2 &= ~bank->enabled_non_wakeup_gpios; |
| 1212 | |
| 1213 | __raw_writel(l1, bank->base + bank->regs->fallingdetect); |
| 1214 | __raw_writel(l2, bank->base + bank->regs->risingdetect); |
| 1215 | |
| 1216 | bank->workaround_enabled = true; |
| 1217 | |
Tarun Kanti DebBarma | 41d87cb | 2011-11-15 12:52:38 +0530 | [diff] [blame] | 1218 | update_gpio_context_count: |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1219 | if (bank->get_context_loss_count) |
| 1220 | bank->context_loss_count = |
| 1221 | bank->get_context_loss_count(bank->dev); |
| 1222 | |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 1223 | _gpio_dbck_disable(bank); |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1224 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1225 | |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | static int omap_gpio_runtime_resume(struct device *dev) |
| 1230 | { |
| 1231 | struct platform_device *pdev = to_platform_device(dev); |
| 1232 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1233 | int context_lost_cnt_after; |
| 1234 | u32 l = 0, gen, gen0, gen1; |
| 1235 | unsigned long flags; |
| 1236 | |
| 1237 | spin_lock_irqsave(&bank->lock, flags); |
Tarun Kanti DebBarma | 72f83af9 | 2011-11-24 03:03:28 +0530 | [diff] [blame] | 1238 | _gpio_dbck_enable(bank); |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1239 | if (!bank->enabled_non_wakeup_gpios || !bank->workaround_enabled) { |
| 1240 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | if (bank->get_context_loss_count) { |
| 1245 | context_lost_cnt_after = |
| 1246 | bank->get_context_loss_count(bank->dev); |
| 1247 | if (context_lost_cnt_after != bank->context_loss_count || |
| 1248 | !context_lost_cnt_after) { |
| 1249 | omap_gpio_restore_context(bank); |
| 1250 | } else { |
| 1251 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1252 | return 0; |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | __raw_writel(bank->saved_fallingdetect, |
| 1257 | bank->base + bank->regs->fallingdetect); |
| 1258 | __raw_writel(bank->saved_risingdetect, |
| 1259 | bank->base + bank->regs->risingdetect); |
| 1260 | l = __raw_readl(bank->base + bank->regs->datain); |
| 1261 | |
| 1262 | /* |
| 1263 | * Check if any of the non-wakeup interrupt GPIOs have changed |
| 1264 | * state. If so, generate an IRQ by software. This is |
| 1265 | * horribly racy, but it's the best we can do to work around |
| 1266 | * this silicon bug. |
| 1267 | */ |
| 1268 | l ^= bank->saved_datain; |
| 1269 | l &= bank->enabled_non_wakeup_gpios; |
| 1270 | |
| 1271 | /* |
| 1272 | * No need to generate IRQs for the rising edge for gpio IRQs |
| 1273 | * configured with falling edge only; and vice versa. |
| 1274 | */ |
| 1275 | gen0 = l & bank->saved_fallingdetect; |
| 1276 | gen0 &= bank->saved_datain; |
| 1277 | |
| 1278 | gen1 = l & bank->saved_risingdetect; |
| 1279 | gen1 &= ~(bank->saved_datain); |
| 1280 | |
| 1281 | /* FIXME: Consider GPIO IRQs with level detections properly! */ |
| 1282 | gen = l & (~(bank->saved_fallingdetect) & ~(bank->saved_risingdetect)); |
| 1283 | /* Consider all GPIO IRQs needed to be updated */ |
| 1284 | gen |= gen0 | gen1; |
| 1285 | |
| 1286 | if (gen) { |
| 1287 | u32 old0, old1; |
| 1288 | |
| 1289 | old0 = __raw_readl(bank->base + bank->regs->leveldetect0); |
| 1290 | old1 = __raw_readl(bank->base + bank->regs->leveldetect1); |
| 1291 | |
| 1292 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 1293 | __raw_writel(old0 | gen, bank->base + |
| 1294 | bank->regs->leveldetect0); |
| 1295 | __raw_writel(old1 | gen, bank->base + |
| 1296 | bank->regs->leveldetect1); |
| 1297 | } |
| 1298 | |
| 1299 | if (cpu_is_omap44xx()) { |
| 1300 | __raw_writel(old0 | l, bank->base + |
| 1301 | bank->regs->leveldetect0); |
| 1302 | __raw_writel(old1 | l, bank->base + |
| 1303 | bank->regs->leveldetect1); |
| 1304 | } |
| 1305 | __raw_writel(old0, bank->base + bank->regs->leveldetect0); |
| 1306 | __raw_writel(old1, bank->base + bank->regs->leveldetect1); |
| 1307 | } |
| 1308 | |
| 1309 | bank->workaround_enabled = false; |
| 1310 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1311 | |
| 1312 | return 0; |
| 1313 | } |
| 1314 | #endif /* CONFIG_PM_RUNTIME */ |
| 1315 | |
| 1316 | void omap2_gpio_prepare_for_idle(int pwr_mode) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1317 | { |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1318 | struct gpio_bank *bank; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1319 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1320 | list_for_each_entry(bank, &omap_gpio_list, node) { |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1321 | if (!bank->mod_usage || !bank->loses_context) |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1322 | continue; |
| 1323 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1324 | bank->power_mode = pwr_mode; |
| 1325 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1326 | pm_runtime_put_sync_suspend(bank->dev); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1327 | } |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1328 | } |
| 1329 | |
Kevin Hilman | 43ffcd9 | 2009-01-27 11:09:24 -0800 | [diff] [blame] | 1330 | void omap2_gpio_resume_after_idle(void) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1331 | { |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1332 | struct gpio_bank *bank; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1333 | |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1334 | list_for_each_entry(bank, &omap_gpio_list, node) { |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1335 | if (!bank->mod_usage || !bank->loses_context) |
Charulatha V | 03e128c | 2011-05-05 19:58:01 +0530 | [diff] [blame] | 1336 | continue; |
| 1337 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1338 | pm_runtime_get_sync(bank->dev); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1339 | } |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1340 | } |
| 1341 | |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1342 | #if defined(CONFIG_PM_RUNTIME) |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1343 | static void omap_gpio_restore_context(struct gpio_bank *bank) |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1344 | { |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1345 | __raw_writel(bank->context.wake_en, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1346 | bank->base + bank->regs->wkup_en); |
| 1347 | __raw_writel(bank->context.ctrl, bank->base + bank->regs->ctrl); |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1348 | __raw_writel(bank->context.leveldetect0, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1349 | bank->base + bank->regs->leveldetect0); |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1350 | __raw_writel(bank->context.leveldetect1, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1351 | bank->base + bank->regs->leveldetect1); |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1352 | __raw_writel(bank->context.risingdetect, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1353 | bank->base + bank->regs->risingdetect); |
Tarun Kanti DebBarma | 60a3437 | 2011-09-29 04:47:25 +0530 | [diff] [blame] | 1354 | __raw_writel(bank->context.fallingdetect, |
Tarun Kanti DebBarma | ae10f23 | 2011-08-30 15:24:27 +0530 | [diff] [blame] | 1355 | bank->base + bank->regs->fallingdetect); |
Nishanth Menon | f86bcc3 | 2011-09-09 19:14:08 +0530 | [diff] [blame] | 1356 | if (bank->regs->set_dataout && bank->regs->clr_dataout) |
| 1357 | __raw_writel(bank->context.dataout, |
| 1358 | bank->base + bank->regs->set_dataout); |
| 1359 | else |
| 1360 | __raw_writel(bank->context.dataout, |
| 1361 | bank->base + bank->regs->dataout); |
Nishanth Menon | 6d13eaa | 2011-08-29 18:54:50 +0530 | [diff] [blame] | 1362 | __raw_writel(bank->context.oe, bank->base + bank->regs->direction); |
| 1363 | |
Nishanth Menon | ae54735 | 2011-09-09 19:08:58 +0530 | [diff] [blame] | 1364 | if (bank->dbck_enable_mask) { |
| 1365 | __raw_writel(bank->context.debounce, bank->base + |
| 1366 | bank->regs->debounce); |
| 1367 | __raw_writel(bank->context.debounce_en, |
| 1368 | bank->base + bank->regs->debounce_en); |
| 1369 | } |
Nishanth Menon | ba805be | 2011-08-29 18:41:08 +0530 | [diff] [blame] | 1370 | |
| 1371 | __raw_writel(bank->context.irqenable1, |
| 1372 | bank->base + bank->regs->irqenable); |
| 1373 | __raw_writel(bank->context.irqenable2, |
| 1374 | bank->base + bank->regs->irqenable2); |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1375 | } |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1376 | #endif /* CONFIG_PM_RUNTIME */ |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1377 | #else |
| 1378 | #define omap_gpio_suspend NULL |
| 1379 | #define omap_gpio_resume NULL |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1380 | #define omap_gpio_runtime_suspend NULL |
| 1381 | #define omap_gpio_runtime_resume NULL |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1382 | #endif |
| 1383 | |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1384 | static const struct dev_pm_ops gpio_pm_ops = { |
| 1385 | SET_SYSTEM_SLEEP_PM_OPS(omap_gpio_suspend, omap_gpio_resume) |
Tarun Kanti DebBarma | 2dc983c | 2011-11-24 02:44:29 +0530 | [diff] [blame] | 1386 | SET_RUNTIME_PM_OPS(omap_gpio_runtime_suspend, omap_gpio_runtime_resume, |
| 1387 | NULL) |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1388 | }; |
| 1389 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1390 | static struct platform_driver omap_gpio_driver = { |
| 1391 | .probe = omap_gpio_probe, |
| 1392 | .driver = { |
| 1393 | .name = "omap_gpio", |
Tarun Kanti DebBarma | 55b93c3 | 2011-09-29 07:23:22 +0530 | [diff] [blame] | 1394 | .pm = &gpio_pm_ops, |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1395 | }, |
| 1396 | }; |
| 1397 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1398 | /* |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1399 | * gpio driver register needs to be done before |
| 1400 | * machine_init functions access gpio APIs. |
| 1401 | * Hence omap_gpio_drv_reg() is a postcore_initcall. |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1402 | */ |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1403 | static int __init omap_gpio_drv_reg(void) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1404 | { |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1405 | return platform_driver_register(&omap_gpio_driver); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1406 | } |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1407 | postcore_initcall(omap_gpio_drv_reg); |