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