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