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