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