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