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