Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/plat-omap/gpio.c |
| 3 | * |
| 4 | * Support functions for OMAP GPIO |
| 5 | * |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 6 | * Copyright (C) 2003-2005 Nokia Corporation |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 7 | * Written by Juha Yrjölä <juha.yrjola@nokia.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/config.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/sched.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/ptrace.h> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 20 | #include <linux/sysdev.h> |
| 21 | #include <linux/err.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 22 | #include <linux/clk.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 23 | |
| 24 | #include <asm/hardware.h> |
| 25 | #include <asm/irq.h> |
| 26 | #include <asm/arch/irqs.h> |
| 27 | #include <asm/arch/gpio.h> |
| 28 | #include <asm/mach/irq.h> |
| 29 | |
| 30 | #include <asm/io.h> |
| 31 | |
| 32 | /* |
| 33 | * OMAP1510 GPIO registers |
| 34 | */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 35 | #define OMAP1510_GPIO_BASE (void __iomem *)0xfffce000 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 36 | #define OMAP1510_GPIO_DATA_INPUT 0x00 |
| 37 | #define OMAP1510_GPIO_DATA_OUTPUT 0x04 |
| 38 | #define OMAP1510_GPIO_DIR_CONTROL 0x08 |
| 39 | #define OMAP1510_GPIO_INT_CONTROL 0x0c |
| 40 | #define OMAP1510_GPIO_INT_MASK 0x10 |
| 41 | #define OMAP1510_GPIO_INT_STATUS 0x14 |
| 42 | #define OMAP1510_GPIO_PIN_CONTROL 0x18 |
| 43 | |
| 44 | #define OMAP1510_IH_GPIO_BASE 64 |
| 45 | |
| 46 | /* |
| 47 | * OMAP1610 specific GPIO registers |
| 48 | */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 49 | #define OMAP1610_GPIO1_BASE (void __iomem *)0xfffbe400 |
| 50 | #define OMAP1610_GPIO2_BASE (void __iomem *)0xfffbec00 |
| 51 | #define OMAP1610_GPIO3_BASE (void __iomem *)0xfffbb400 |
| 52 | #define OMAP1610_GPIO4_BASE (void __iomem *)0xfffbbc00 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 53 | #define OMAP1610_GPIO_REVISION 0x0000 |
| 54 | #define OMAP1610_GPIO_SYSCONFIG 0x0010 |
| 55 | #define OMAP1610_GPIO_SYSSTATUS 0x0014 |
| 56 | #define OMAP1610_GPIO_IRQSTATUS1 0x0018 |
| 57 | #define OMAP1610_GPIO_IRQENABLE1 0x001c |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 58 | #define OMAP1610_GPIO_WAKEUPENABLE 0x0028 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 59 | #define OMAP1610_GPIO_DATAIN 0x002c |
| 60 | #define OMAP1610_GPIO_DATAOUT 0x0030 |
| 61 | #define OMAP1610_GPIO_DIRECTION 0x0034 |
| 62 | #define OMAP1610_GPIO_EDGE_CTRL1 0x0038 |
| 63 | #define OMAP1610_GPIO_EDGE_CTRL2 0x003c |
| 64 | #define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 65 | #define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 66 | #define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0 |
| 67 | #define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 68 | #define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 69 | #define OMAP1610_GPIO_SET_DATAOUT 0x00f0 |
| 70 | |
| 71 | /* |
| 72 | * OMAP730 specific GPIO registers |
| 73 | */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 74 | #define OMAP730_GPIO1_BASE (void __iomem *)0xfffbc000 |
| 75 | #define OMAP730_GPIO2_BASE (void __iomem *)0xfffbc800 |
| 76 | #define OMAP730_GPIO3_BASE (void __iomem *)0xfffbd000 |
| 77 | #define OMAP730_GPIO4_BASE (void __iomem *)0xfffbd800 |
| 78 | #define OMAP730_GPIO5_BASE (void __iomem *)0xfffbe000 |
| 79 | #define OMAP730_GPIO6_BASE (void __iomem *)0xfffbe800 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 80 | #define OMAP730_GPIO_DATA_INPUT 0x00 |
| 81 | #define OMAP730_GPIO_DATA_OUTPUT 0x04 |
| 82 | #define OMAP730_GPIO_DIR_CONTROL 0x08 |
| 83 | #define OMAP730_GPIO_INT_CONTROL 0x0c |
| 84 | #define OMAP730_GPIO_INT_MASK 0x10 |
| 85 | #define OMAP730_GPIO_INT_STATUS 0x14 |
| 86 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 87 | /* |
| 88 | * omap24xx specific GPIO registers |
| 89 | */ |
| 90 | #define OMAP24XX_GPIO1_BASE (void __iomem *)0x48018000 |
| 91 | #define OMAP24XX_GPIO2_BASE (void __iomem *)0x4801a000 |
| 92 | #define OMAP24XX_GPIO3_BASE (void __iomem *)0x4801c000 |
| 93 | #define OMAP24XX_GPIO4_BASE (void __iomem *)0x4801e000 |
| 94 | #define OMAP24XX_GPIO_REVISION 0x0000 |
| 95 | #define OMAP24XX_GPIO_SYSCONFIG 0x0010 |
| 96 | #define OMAP24XX_GPIO_SYSSTATUS 0x0014 |
| 97 | #define OMAP24XX_GPIO_IRQSTATUS1 0x0018 |
| 98 | #define OMAP24XX_GPIO_IRQENABLE1 0x001c |
| 99 | #define OMAP24XX_GPIO_CTRL 0x0030 |
| 100 | #define OMAP24XX_GPIO_OE 0x0034 |
| 101 | #define OMAP24XX_GPIO_DATAIN 0x0038 |
| 102 | #define OMAP24XX_GPIO_DATAOUT 0x003c |
| 103 | #define OMAP24XX_GPIO_LEVELDETECT0 0x0040 |
| 104 | #define OMAP24XX_GPIO_LEVELDETECT1 0x0044 |
| 105 | #define OMAP24XX_GPIO_RISINGDETECT 0x0048 |
| 106 | #define OMAP24XX_GPIO_FALLINGDETECT 0x004c |
| 107 | #define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060 |
| 108 | #define OMAP24XX_GPIO_SETIRQENABLE1 0x0064 |
| 109 | #define OMAP24XX_GPIO_CLEARWKUENA 0x0080 |
| 110 | #define OMAP24XX_GPIO_SETWKUENA 0x0084 |
| 111 | #define OMAP24XX_GPIO_CLEARDATAOUT 0x0090 |
| 112 | #define OMAP24XX_GPIO_SETDATAOUT 0x0094 |
| 113 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 114 | #define OMAP_MPUIO_MASK (~OMAP_MAX_GPIO_LINES & 0xff) |
| 115 | |
| 116 | struct gpio_bank { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 117 | void __iomem *base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 118 | u16 irq; |
| 119 | u16 virtual_irq_start; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 120 | int method; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 121 | u32 reserved_map; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 122 | u32 suspend_wakeup; |
| 123 | u32 saved_wakeup; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 124 | spinlock_t lock; |
| 125 | }; |
| 126 | |
| 127 | #define METHOD_MPUIO 0 |
| 128 | #define METHOD_GPIO_1510 1 |
| 129 | #define METHOD_GPIO_1610 2 |
| 130 | #define METHOD_GPIO_730 3 |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 131 | #define METHOD_GPIO_24XX 4 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 132 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 133 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 134 | static struct gpio_bank gpio_bank_1610[5] = { |
| 135 | { OMAP_MPUIO_BASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO}, |
| 136 | { OMAP1610_GPIO1_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1610 }, |
| 137 | { OMAP1610_GPIO2_BASE, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16, METHOD_GPIO_1610 }, |
| 138 | { OMAP1610_GPIO3_BASE, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32, METHOD_GPIO_1610 }, |
| 139 | { OMAP1610_GPIO4_BASE, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48, METHOD_GPIO_1610 }, |
| 140 | }; |
| 141 | #endif |
| 142 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 143 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 144 | static struct gpio_bank gpio_bank_1510[2] = { |
| 145 | { OMAP_MPUIO_BASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO }, |
| 146 | { OMAP1510_GPIO_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1510 } |
| 147 | }; |
| 148 | #endif |
| 149 | |
| 150 | #ifdef CONFIG_ARCH_OMAP730 |
| 151 | static struct gpio_bank gpio_bank_730[7] = { |
| 152 | { OMAP_MPUIO_BASE, INT_730_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO }, |
| 153 | { OMAP730_GPIO1_BASE, INT_730_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_730 }, |
| 154 | { OMAP730_GPIO2_BASE, INT_730_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_730 }, |
| 155 | { OMAP730_GPIO3_BASE, INT_730_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_730 }, |
| 156 | { OMAP730_GPIO4_BASE, INT_730_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_730 }, |
| 157 | { OMAP730_GPIO5_BASE, INT_730_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_730 }, |
| 158 | { OMAP730_GPIO6_BASE, INT_730_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_730 }, |
| 159 | }; |
| 160 | #endif |
| 161 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 162 | #ifdef CONFIG_ARCH_OMAP24XX |
| 163 | static struct gpio_bank gpio_bank_24xx[4] = { |
| 164 | { OMAP24XX_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX }, |
| 165 | { OMAP24XX_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX }, |
| 166 | { OMAP24XX_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX }, |
| 167 | { OMAP24XX_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX }, |
| 168 | }; |
| 169 | #endif |
| 170 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 171 | static struct gpio_bank *gpio_bank; |
| 172 | static int gpio_bank_count; |
| 173 | |
| 174 | static inline struct gpio_bank *get_gpio_bank(int gpio) |
| 175 | { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 176 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 177 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 178 | if (OMAP_GPIO_IS_MPUIO(gpio)) |
| 179 | return &gpio_bank[0]; |
| 180 | return &gpio_bank[1]; |
| 181 | } |
| 182 | #endif |
| 183 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 184 | if (cpu_is_omap16xx()) { |
| 185 | if (OMAP_GPIO_IS_MPUIO(gpio)) |
| 186 | return &gpio_bank[0]; |
| 187 | return &gpio_bank[1 + (gpio >> 4)]; |
| 188 | } |
| 189 | #endif |
| 190 | #ifdef CONFIG_ARCH_OMAP730 |
| 191 | if (cpu_is_omap730()) { |
| 192 | if (OMAP_GPIO_IS_MPUIO(gpio)) |
| 193 | return &gpio_bank[0]; |
| 194 | return &gpio_bank[1 + (gpio >> 5)]; |
| 195 | } |
| 196 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 197 | #ifdef CONFIG_ARCH_OMAP24XX |
| 198 | if (cpu_is_omap24xx()) |
| 199 | return &gpio_bank[gpio >> 5]; |
| 200 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static inline int get_gpio_index(int gpio) |
| 204 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 205 | #ifdef CONFIG_ARCH_OMAP730 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 206 | if (cpu_is_omap730()) |
| 207 | return gpio & 0x1f; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 208 | #endif |
| 209 | #ifdef CONFIG_ARCH_OMAP24XX |
| 210 | if (cpu_is_omap24xx()) |
| 211 | return gpio & 0x1f; |
| 212 | #endif |
| 213 | return gpio & 0x0f; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static inline int gpio_valid(int gpio) |
| 217 | { |
| 218 | if (gpio < 0) |
| 219 | return -1; |
| 220 | if (OMAP_GPIO_IS_MPUIO(gpio)) { |
| 221 | if ((gpio & OMAP_MPUIO_MASK) > 16) |
| 222 | return -1; |
| 223 | return 0; |
| 224 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 225 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 226 | if (cpu_is_omap15xx() && gpio < 16) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 227 | return 0; |
| 228 | #endif |
| 229 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 230 | if ((cpu_is_omap16xx()) && gpio < 64) |
| 231 | return 0; |
| 232 | #endif |
| 233 | #ifdef CONFIG_ARCH_OMAP730 |
| 234 | if (cpu_is_omap730() && gpio < 192) |
| 235 | return 0; |
| 236 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 237 | #ifdef CONFIG_ARCH_OMAP24XX |
| 238 | if (cpu_is_omap24xx() && gpio < 128) |
| 239 | return 0; |
| 240 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 241 | return -1; |
| 242 | } |
| 243 | |
| 244 | static int check_gpio(int gpio) |
| 245 | { |
| 246 | if (unlikely(gpio_valid(gpio)) < 0) { |
| 247 | printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio); |
| 248 | dump_stack(); |
| 249 | return -1; |
| 250 | } |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) |
| 255 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 256 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 257 | u32 l; |
| 258 | |
| 259 | switch (bank->method) { |
| 260 | case METHOD_MPUIO: |
| 261 | reg += OMAP_MPUIO_IO_CNTL; |
| 262 | break; |
| 263 | case METHOD_GPIO_1510: |
| 264 | reg += OMAP1510_GPIO_DIR_CONTROL; |
| 265 | break; |
| 266 | case METHOD_GPIO_1610: |
| 267 | reg += OMAP1610_GPIO_DIRECTION; |
| 268 | break; |
| 269 | case METHOD_GPIO_730: |
| 270 | reg += OMAP730_GPIO_DIR_CONTROL; |
| 271 | break; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 272 | case METHOD_GPIO_24XX: |
| 273 | reg += OMAP24XX_GPIO_OE; |
| 274 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 275 | } |
| 276 | l = __raw_readl(reg); |
| 277 | if (is_input) |
| 278 | l |= 1 << gpio; |
| 279 | else |
| 280 | l &= ~(1 << gpio); |
| 281 | __raw_writel(l, reg); |
| 282 | } |
| 283 | |
| 284 | void omap_set_gpio_direction(int gpio, int is_input) |
| 285 | { |
| 286 | struct gpio_bank *bank; |
| 287 | |
| 288 | if (check_gpio(gpio) < 0) |
| 289 | return; |
| 290 | bank = get_gpio_bank(gpio); |
| 291 | spin_lock(&bank->lock); |
| 292 | _set_gpio_direction(bank, get_gpio_index(gpio), is_input); |
| 293 | spin_unlock(&bank->lock); |
| 294 | } |
| 295 | |
| 296 | static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable) |
| 297 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 298 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 299 | u32 l = 0; |
| 300 | |
| 301 | switch (bank->method) { |
| 302 | case METHOD_MPUIO: |
| 303 | reg += OMAP_MPUIO_OUTPUT; |
| 304 | l = __raw_readl(reg); |
| 305 | if (enable) |
| 306 | l |= 1 << gpio; |
| 307 | else |
| 308 | l &= ~(1 << gpio); |
| 309 | break; |
| 310 | case METHOD_GPIO_1510: |
| 311 | reg += OMAP1510_GPIO_DATA_OUTPUT; |
| 312 | l = __raw_readl(reg); |
| 313 | if (enable) |
| 314 | l |= 1 << gpio; |
| 315 | else |
| 316 | l &= ~(1 << gpio); |
| 317 | break; |
| 318 | case METHOD_GPIO_1610: |
| 319 | if (enable) |
| 320 | reg += OMAP1610_GPIO_SET_DATAOUT; |
| 321 | else |
| 322 | reg += OMAP1610_GPIO_CLEAR_DATAOUT; |
| 323 | l = 1 << gpio; |
| 324 | break; |
| 325 | case METHOD_GPIO_730: |
| 326 | reg += OMAP730_GPIO_DATA_OUTPUT; |
| 327 | l = __raw_readl(reg); |
| 328 | if (enable) |
| 329 | l |= 1 << gpio; |
| 330 | else |
| 331 | l &= ~(1 << gpio); |
| 332 | break; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 333 | case METHOD_GPIO_24XX: |
| 334 | if (enable) |
| 335 | reg += OMAP24XX_GPIO_SETDATAOUT; |
| 336 | else |
| 337 | reg += OMAP24XX_GPIO_CLEARDATAOUT; |
| 338 | l = 1 << gpio; |
| 339 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 340 | default: |
| 341 | BUG(); |
| 342 | return; |
| 343 | } |
| 344 | __raw_writel(l, reg); |
| 345 | } |
| 346 | |
| 347 | void omap_set_gpio_dataout(int gpio, int enable) |
| 348 | { |
| 349 | struct gpio_bank *bank; |
| 350 | |
| 351 | if (check_gpio(gpio) < 0) |
| 352 | return; |
| 353 | bank = get_gpio_bank(gpio); |
| 354 | spin_lock(&bank->lock); |
| 355 | _set_gpio_dataout(bank, get_gpio_index(gpio), enable); |
| 356 | spin_unlock(&bank->lock); |
| 357 | } |
| 358 | |
| 359 | int omap_get_gpio_datain(int gpio) |
| 360 | { |
| 361 | struct gpio_bank *bank; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 362 | void __iomem *reg; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 363 | |
| 364 | if (check_gpio(gpio) < 0) |
| 365 | return -1; |
| 366 | bank = get_gpio_bank(gpio); |
| 367 | reg = bank->base; |
| 368 | switch (bank->method) { |
| 369 | case METHOD_MPUIO: |
| 370 | reg += OMAP_MPUIO_INPUT_LATCH; |
| 371 | break; |
| 372 | case METHOD_GPIO_1510: |
| 373 | reg += OMAP1510_GPIO_DATA_INPUT; |
| 374 | break; |
| 375 | case METHOD_GPIO_1610: |
| 376 | reg += OMAP1610_GPIO_DATAIN; |
| 377 | break; |
| 378 | case METHOD_GPIO_730: |
| 379 | reg += OMAP730_GPIO_DATA_INPUT; |
| 380 | break; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 381 | case METHOD_GPIO_24XX: |
| 382 | reg += OMAP24XX_GPIO_DATAIN; |
| 383 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 384 | default: |
| 385 | BUG(); |
| 386 | return -1; |
| 387 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 388 | return (__raw_readl(reg) |
| 389 | & (1 << get_gpio_index(gpio))) != 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 390 | } |
| 391 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 392 | #define MOD_REG_BIT(reg, bit_mask, set) \ |
| 393 | do { \ |
| 394 | int l = __raw_readl(base + reg); \ |
| 395 | if (set) l |= bit_mask; \ |
| 396 | else l &= ~bit_mask; \ |
| 397 | __raw_writel(l, base + reg); \ |
| 398 | } while(0) |
| 399 | |
| 400 | static inline void set_24xx_gpio_triggering(void __iomem *base, int gpio, int trigger) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 401 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 402 | u32 gpio_bit = 1 << gpio; |
| 403 | |
| 404 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit, |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 405 | trigger & __IRQT_LOWLVL); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 406 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit, |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 407 | trigger & __IRQT_HIGHLVL); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 408 | MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit, |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 409 | trigger & __IRQT_RISEDGE); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 410 | MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit, |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 411 | trigger & __IRQT_FALEDGE); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 412 | /* FIXME: Possibly do 'set_irq_handler(j, do_level_IRQ)' if only level |
| 413 | * triggering requested. */ |
| 414 | } |
| 415 | |
| 416 | static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger) |
| 417 | { |
| 418 | void __iomem *reg = bank->base; |
| 419 | u32 l = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 420 | |
| 421 | switch (bank->method) { |
| 422 | case METHOD_MPUIO: |
| 423 | reg += OMAP_MPUIO_GPIO_INT_EDGE; |
| 424 | l = __raw_readl(reg); |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 425 | if (trigger & __IRQT_RISEDGE) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 426 | l |= 1 << gpio; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 427 | else if (trigger & __IRQT_FALEDGE) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 428 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 429 | else |
| 430 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 431 | break; |
| 432 | case METHOD_GPIO_1510: |
| 433 | reg += OMAP1510_GPIO_INT_CONTROL; |
| 434 | l = __raw_readl(reg); |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 435 | if (trigger & __IRQT_RISEDGE) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 436 | l |= 1 << gpio; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 437 | else if (trigger & __IRQT_FALEDGE) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 438 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 439 | else |
| 440 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 441 | break; |
| 442 | case METHOD_GPIO_1610: |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 443 | if (gpio & 0x08) |
| 444 | reg += OMAP1610_GPIO_EDGE_CTRL2; |
| 445 | else |
| 446 | reg += OMAP1610_GPIO_EDGE_CTRL1; |
| 447 | gpio &= 0x07; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 448 | /* We allow only edge triggering, i.e. two lowest bits */ |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 449 | if (trigger & (__IRQT_LOWLVL | __IRQT_HIGHLVL)) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 450 | BUG(); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 451 | l = __raw_readl(reg); |
| 452 | l &= ~(3 << (gpio << 1)); |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 453 | if (trigger & __IRQT_RISEDGE) |
| 454 | l |= 2 << (gpio << 1); |
| 455 | if (trigger & __IRQT_FALEDGE) |
| 456 | l |= 1 << (gpio << 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 457 | break; |
| 458 | case METHOD_GPIO_730: |
| 459 | reg += OMAP730_GPIO_INT_CONTROL; |
| 460 | l = __raw_readl(reg); |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 461 | if (trigger & __IRQT_RISEDGE) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 462 | l |= 1 << gpio; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 463 | else if (trigger & __IRQT_FALEDGE) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 464 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 465 | else |
| 466 | goto bad; |
| 467 | break; |
| 468 | case METHOD_GPIO_24XX: |
| 469 | set_24xx_gpio_triggering(reg, gpio, trigger); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 470 | break; |
| 471 | default: |
| 472 | BUG(); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 473 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 474 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 475 | __raw_writel(l, reg); |
| 476 | return 0; |
| 477 | bad: |
| 478 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 481 | static int gpio_irq_type(unsigned irq, unsigned type) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 482 | { |
| 483 | struct gpio_bank *bank; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 484 | unsigned gpio; |
| 485 | int retval; |
| 486 | |
| 487 | if (irq > IH_MPUIO_BASE) |
| 488 | gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); |
| 489 | else |
| 490 | gpio = irq - IH_GPIO_BASE; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 491 | |
| 492 | if (check_gpio(gpio) < 0) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 493 | return -EINVAL; |
| 494 | |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 495 | if (type & IRQT_PROBE) |
| 496 | return -EINVAL; |
| 497 | if (!cpu_is_omap24xx() && (type & (__IRQT_LOWLVL|__IRQT_HIGHLVL))) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 498 | return -EINVAL; |
| 499 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 500 | bank = get_gpio_bank(gpio); |
| 501 | spin_lock(&bank->lock); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 502 | retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 503 | spin_unlock(&bank->lock); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 504 | return retval; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
| 508 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 509 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 510 | |
| 511 | switch (bank->method) { |
| 512 | case METHOD_MPUIO: |
| 513 | /* MPUIO irqstatus is reset by reading the status register, |
| 514 | * so do nothing here */ |
| 515 | return; |
| 516 | case METHOD_GPIO_1510: |
| 517 | reg += OMAP1510_GPIO_INT_STATUS; |
| 518 | break; |
| 519 | case METHOD_GPIO_1610: |
| 520 | reg += OMAP1610_GPIO_IRQSTATUS1; |
| 521 | break; |
| 522 | case METHOD_GPIO_730: |
| 523 | reg += OMAP730_GPIO_INT_STATUS; |
| 524 | break; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 525 | case METHOD_GPIO_24XX: |
| 526 | reg += OMAP24XX_GPIO_IRQSTATUS1; |
| 527 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 528 | default: |
| 529 | BUG(); |
| 530 | return; |
| 531 | } |
| 532 | __raw_writel(gpio_mask, reg); |
| 533 | } |
| 534 | |
| 535 | static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) |
| 536 | { |
| 537 | _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio)); |
| 538 | } |
| 539 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 540 | static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank) |
| 541 | { |
| 542 | void __iomem *reg = bank->base; |
| 543 | |
| 544 | switch (bank->method) { |
| 545 | case METHOD_MPUIO: |
| 546 | reg += OMAP_MPUIO_GPIO_MASKIT; |
| 547 | break; |
| 548 | case METHOD_GPIO_1510: |
| 549 | reg += OMAP1510_GPIO_INT_MASK; |
| 550 | break; |
| 551 | case METHOD_GPIO_1610: |
| 552 | reg += OMAP1610_GPIO_IRQENABLE1; |
| 553 | break; |
| 554 | case METHOD_GPIO_730: |
| 555 | reg += OMAP730_GPIO_INT_MASK; |
| 556 | break; |
| 557 | case METHOD_GPIO_24XX: |
| 558 | reg += OMAP24XX_GPIO_IRQENABLE1; |
| 559 | break; |
| 560 | default: |
| 561 | BUG(); |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | return __raw_readl(reg); |
| 566 | } |
| 567 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 568 | static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable) |
| 569 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 570 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 571 | u32 l; |
| 572 | |
| 573 | switch (bank->method) { |
| 574 | case METHOD_MPUIO: |
| 575 | reg += OMAP_MPUIO_GPIO_MASKIT; |
| 576 | l = __raw_readl(reg); |
| 577 | if (enable) |
| 578 | l &= ~(gpio_mask); |
| 579 | else |
| 580 | l |= gpio_mask; |
| 581 | break; |
| 582 | case METHOD_GPIO_1510: |
| 583 | reg += OMAP1510_GPIO_INT_MASK; |
| 584 | l = __raw_readl(reg); |
| 585 | if (enable) |
| 586 | l &= ~(gpio_mask); |
| 587 | else |
| 588 | l |= gpio_mask; |
| 589 | break; |
| 590 | case METHOD_GPIO_1610: |
| 591 | if (enable) |
| 592 | reg += OMAP1610_GPIO_SET_IRQENABLE1; |
| 593 | else |
| 594 | reg += OMAP1610_GPIO_CLEAR_IRQENABLE1; |
| 595 | l = gpio_mask; |
| 596 | break; |
| 597 | case METHOD_GPIO_730: |
| 598 | reg += OMAP730_GPIO_INT_MASK; |
| 599 | l = __raw_readl(reg); |
| 600 | if (enable) |
| 601 | l &= ~(gpio_mask); |
| 602 | else |
| 603 | l |= gpio_mask; |
| 604 | break; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 605 | case METHOD_GPIO_24XX: |
| 606 | if (enable) |
| 607 | reg += OMAP24XX_GPIO_SETIRQENABLE1; |
| 608 | else |
| 609 | reg += OMAP24XX_GPIO_CLEARIRQENABLE1; |
| 610 | l = gpio_mask; |
| 611 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 612 | default: |
| 613 | BUG(); |
| 614 | return; |
| 615 | } |
| 616 | __raw_writel(l, reg); |
| 617 | } |
| 618 | |
| 619 | static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable) |
| 620 | { |
| 621 | _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable); |
| 622 | } |
| 623 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 624 | /* |
| 625 | * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register. |
| 626 | * 1510 does not seem to have a wake-up register. If JTAG is connected |
| 627 | * to the target, system will wake up always on GPIO events. While |
| 628 | * system is running all registered GPIO interrupts need to have wake-up |
| 629 | * enabled. When system is suspended, only selected GPIO interrupts need |
| 630 | * to have wake-up enabled. |
| 631 | */ |
| 632 | static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) |
| 633 | { |
| 634 | switch (bank->method) { |
| 635 | case METHOD_GPIO_1610: |
| 636 | case METHOD_GPIO_24XX: |
| 637 | spin_lock(&bank->lock); |
| 638 | if (enable) |
| 639 | bank->suspend_wakeup |= (1 << gpio); |
| 640 | else |
| 641 | bank->suspend_wakeup &= ~(1 << gpio); |
| 642 | spin_unlock(&bank->lock); |
| 643 | return 0; |
| 644 | default: |
| 645 | printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n", |
| 646 | bank->method); |
| 647 | return -EINVAL; |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ |
| 652 | static int gpio_wake_enable(unsigned int irq, unsigned int enable) |
| 653 | { |
| 654 | unsigned int gpio = irq - IH_GPIO_BASE; |
| 655 | struct gpio_bank *bank; |
| 656 | int retval; |
| 657 | |
| 658 | if (check_gpio(gpio) < 0) |
| 659 | return -ENODEV; |
| 660 | bank = get_gpio_bank(gpio); |
| 661 | spin_lock(&bank->lock); |
| 662 | retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable); |
| 663 | spin_unlock(&bank->lock); |
| 664 | |
| 665 | return retval; |
| 666 | } |
| 667 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 668 | int omap_request_gpio(int gpio) |
| 669 | { |
| 670 | struct gpio_bank *bank; |
| 671 | |
| 672 | if (check_gpio(gpio) < 0) |
| 673 | return -EINVAL; |
| 674 | |
| 675 | bank = get_gpio_bank(gpio); |
| 676 | spin_lock(&bank->lock); |
| 677 | if (unlikely(bank->reserved_map & (1 << get_gpio_index(gpio)))) { |
| 678 | printk(KERN_ERR "omap-gpio: GPIO %d is already reserved!\n", gpio); |
| 679 | dump_stack(); |
| 680 | spin_unlock(&bank->lock); |
| 681 | return -1; |
| 682 | } |
| 683 | bank->reserved_map |= (1 << get_gpio_index(gpio)); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 684 | |
| 685 | /* Set trigger to none. You need to enable the trigger after request_irq */ |
| 686 | _set_gpio_triggering(bank, get_gpio_index(gpio), IRQT_NOEDGE); |
| 687 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 688 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 689 | if (bank->method == METHOD_GPIO_1510) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 690 | void __iomem *reg; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 691 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 692 | /* Claim the pin for MPU */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 693 | reg = bank->base + OMAP1510_GPIO_PIN_CONTROL; |
| 694 | __raw_writel(__raw_readl(reg) | (1 << get_gpio_index(gpio)), reg); |
| 695 | } |
| 696 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 697 | #ifdef CONFIG_ARCH_OMAP16XX |
| 698 | if (bank->method == METHOD_GPIO_1610) { |
| 699 | /* Enable wake-up during idle for dynamic tick */ |
| 700 | void __iomem *reg = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 701 | __raw_writel(1 << get_gpio_index(gpio), reg); |
| 702 | } |
| 703 | #endif |
| 704 | #ifdef CONFIG_ARCH_OMAP24XX |
| 705 | if (bank->method == METHOD_GPIO_24XX) { |
| 706 | /* Enable wake-up during idle for dynamic tick */ |
| 707 | void __iomem *reg = bank->base + OMAP24XX_GPIO_SETWKUENA; |
| 708 | __raw_writel(1 << get_gpio_index(gpio), reg); |
| 709 | } |
| 710 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 711 | spin_unlock(&bank->lock); |
| 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | void omap_free_gpio(int gpio) |
| 717 | { |
| 718 | struct gpio_bank *bank; |
| 719 | |
| 720 | if (check_gpio(gpio) < 0) |
| 721 | return; |
| 722 | bank = get_gpio_bank(gpio); |
| 723 | spin_lock(&bank->lock); |
| 724 | if (unlikely(!(bank->reserved_map & (1 << get_gpio_index(gpio))))) { |
| 725 | printk(KERN_ERR "omap-gpio: GPIO %d wasn't reserved!\n", gpio); |
| 726 | dump_stack(); |
| 727 | spin_unlock(&bank->lock); |
| 728 | return; |
| 729 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 730 | #ifdef CONFIG_ARCH_OMAP16XX |
| 731 | if (bank->method == METHOD_GPIO_1610) { |
| 732 | /* Disable wake-up during idle for dynamic tick */ |
| 733 | void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 734 | __raw_writel(1 << get_gpio_index(gpio), reg); |
| 735 | } |
| 736 | #endif |
| 737 | #ifdef CONFIG_ARCH_OMAP24XX |
| 738 | if (bank->method == METHOD_GPIO_24XX) { |
| 739 | /* Disable wake-up during idle for dynamic tick */ |
| 740 | void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 741 | __raw_writel(1 << get_gpio_index(gpio), reg); |
| 742 | } |
| 743 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 744 | bank->reserved_map &= ~(1 << get_gpio_index(gpio)); |
| 745 | _set_gpio_direction(bank, get_gpio_index(gpio), 1); |
| 746 | _set_gpio_irqenable(bank, gpio, 0); |
| 747 | _clear_gpio_irqstatus(bank, gpio); |
| 748 | spin_unlock(&bank->lock); |
| 749 | } |
| 750 | |
| 751 | /* |
| 752 | * We need to unmask the GPIO bank interrupt as soon as possible to |
| 753 | * avoid missing GPIO interrupts for other lines in the bank. |
| 754 | * Then we need to mask-read-clear-unmask the triggered GPIO lines |
| 755 | * in the bank to avoid missing nested interrupts for a GPIO line. |
| 756 | * If we wait to unmask individual GPIO lines in the bank after the |
| 757 | * line's interrupt handler has been run, we may miss some nested |
| 758 | * interrupts. |
| 759 | */ |
| 760 | static void gpio_irq_handler(unsigned int irq, struct irqdesc *desc, |
| 761 | struct pt_regs *regs) |
| 762 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 763 | void __iomem *isr_reg = NULL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 764 | u32 isr; |
| 765 | unsigned int gpio_irq; |
| 766 | struct gpio_bank *bank; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 767 | u32 retrigger = 0; |
| 768 | int unmasked = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 769 | |
| 770 | desc->chip->ack(irq); |
| 771 | |
| 772 | bank = (struct gpio_bank *) desc->data; |
| 773 | if (bank->method == METHOD_MPUIO) |
| 774 | isr_reg = bank->base + OMAP_MPUIO_GPIO_INT; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 775 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 776 | if (bank->method == METHOD_GPIO_1510) |
| 777 | isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS; |
| 778 | #endif |
| 779 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 780 | if (bank->method == METHOD_GPIO_1610) |
| 781 | isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1; |
| 782 | #endif |
| 783 | #ifdef CONFIG_ARCH_OMAP730 |
| 784 | if (bank->method == METHOD_GPIO_730) |
| 785 | isr_reg = bank->base + OMAP730_GPIO_INT_STATUS; |
| 786 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 787 | #ifdef CONFIG_ARCH_OMAP24XX |
| 788 | if (bank->method == METHOD_GPIO_24XX) |
| 789 | isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1; |
| 790 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 791 | while(1) { |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 792 | u32 isr_saved, level_mask = 0; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 793 | u32 enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 794 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 795 | enabled = _get_gpio_irqbank_mask(bank); |
| 796 | isr_saved = isr = __raw_readl(isr_reg) & enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 797 | |
| 798 | if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO)) |
| 799 | isr &= 0x0000ffff; |
| 800 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 801 | if (cpu_is_omap24xx()) { |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 802 | level_mask = |
| 803 | __raw_readl(bank->base + |
| 804 | OMAP24XX_GPIO_LEVELDETECT0) | |
| 805 | __raw_readl(bank->base + |
| 806 | OMAP24XX_GPIO_LEVELDETECT1); |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 807 | level_mask &= enabled; |
| 808 | } |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 809 | |
| 810 | /* clear edge sensitive interrupts before handler(s) are |
| 811 | called so that we don't miss any interrupt occurred while |
| 812 | executing them */ |
| 813 | _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0); |
| 814 | _clear_gpio_irqbank(bank, isr_saved & ~level_mask); |
| 815 | _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1); |
| 816 | |
| 817 | /* if there is only edge sensitive GPIO pin interrupts |
| 818 | configured, we could unmask GPIO bank interrupt immediately */ |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 819 | if (!level_mask && !unmasked) { |
| 820 | unmasked = 1; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 821 | desc->chip->unmask(irq); |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 822 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 823 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 824 | isr |= retrigger; |
| 825 | retrigger = 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 826 | if (!isr) |
| 827 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 828 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 829 | gpio_irq = bank->virtual_irq_start; |
| 830 | for (; isr != 0; isr >>= 1, gpio_irq++) { |
| 831 | struct irqdesc *d; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 832 | int irq_mask; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 833 | if (!(isr & 1)) |
| 834 | continue; |
| 835 | d = irq_desc + gpio_irq; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 836 | /* Don't run the handler if it's already running |
| 837 | * or was disabled lazely. |
| 838 | */ |
| 839 | if (unlikely((d->disable_depth || d->running))) { |
| 840 | irq_mask = 1 << |
| 841 | (gpio_irq - bank->virtual_irq_start); |
| 842 | /* The unmasking will be done by |
| 843 | * enable_irq in case it is disabled or |
| 844 | * after returning from the handler if |
| 845 | * it's already running. |
| 846 | */ |
| 847 | _enable_gpio_irqbank(bank, irq_mask, 0); |
| 848 | if (!d->disable_depth) { |
| 849 | /* Level triggered interrupts |
| 850 | * won't ever be reentered |
| 851 | */ |
| 852 | BUG_ON(level_mask & irq_mask); |
| 853 | d->pending = 1; |
| 854 | } |
| 855 | continue; |
| 856 | } |
| 857 | d->running = 1; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 858 | desc_handle_irq(gpio_irq, d, regs); |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 859 | d->running = 0; |
| 860 | if (unlikely(d->pending && !d->disable_depth)) { |
| 861 | irq_mask = 1 << |
| 862 | (gpio_irq - bank->virtual_irq_start); |
| 863 | d->pending = 0; |
| 864 | _enable_gpio_irqbank(bank, irq_mask, 1); |
| 865 | retrigger |= irq_mask; |
| 866 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 867 | } |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 868 | |
| 869 | if (cpu_is_omap24xx()) { |
| 870 | /* clear level sensitive interrupts after handler(s) */ |
| 871 | _enable_gpio_irqbank(bank, isr_saved & level_mask, 0); |
| 872 | _clear_gpio_irqbank(bank, isr_saved & level_mask); |
| 873 | _enable_gpio_irqbank(bank, isr_saved & level_mask, 1); |
| 874 | } |
| 875 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 876 | } |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame^] | 877 | /* if bank has any level sensitive GPIO pin interrupt |
| 878 | configured, we must unmask the bank interrupt only after |
| 879 | handler(s) are executed in order to avoid spurious bank |
| 880 | interrupt */ |
| 881 | if (!unmasked) |
| 882 | desc->chip->unmask(irq); |
| 883 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static void gpio_ack_irq(unsigned int irq) |
| 887 | { |
| 888 | unsigned int gpio = irq - IH_GPIO_BASE; |
| 889 | struct gpio_bank *bank = get_gpio_bank(gpio); |
| 890 | |
| 891 | _clear_gpio_irqstatus(bank, gpio); |
| 892 | } |
| 893 | |
| 894 | static void gpio_mask_irq(unsigned int irq) |
| 895 | { |
| 896 | unsigned int gpio = irq - IH_GPIO_BASE; |
| 897 | struct gpio_bank *bank = get_gpio_bank(gpio); |
| 898 | |
| 899 | _set_gpio_irqenable(bank, gpio, 0); |
| 900 | } |
| 901 | |
| 902 | static void gpio_unmask_irq(unsigned int irq) |
| 903 | { |
| 904 | unsigned int gpio = irq - IH_GPIO_BASE; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 905 | unsigned int gpio_idx = get_gpio_index(gpio); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 906 | struct gpio_bank *bank = get_gpio_bank(gpio); |
| 907 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 908 | _set_gpio_irqenable(bank, gpio_idx, 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static void mpuio_ack_irq(unsigned int irq) |
| 912 | { |
| 913 | /* The ISR is reset automatically, so do nothing here. */ |
| 914 | } |
| 915 | |
| 916 | static void mpuio_mask_irq(unsigned int irq) |
| 917 | { |
| 918 | unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); |
| 919 | struct gpio_bank *bank = get_gpio_bank(gpio); |
| 920 | |
| 921 | _set_gpio_irqenable(bank, gpio, 0); |
| 922 | } |
| 923 | |
| 924 | static void mpuio_unmask_irq(unsigned int irq) |
| 925 | { |
| 926 | unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); |
| 927 | struct gpio_bank *bank = get_gpio_bank(gpio); |
| 928 | |
| 929 | _set_gpio_irqenable(bank, gpio, 1); |
| 930 | } |
| 931 | |
| 932 | static struct irqchip gpio_irq_chip = { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 933 | .ack = gpio_ack_irq, |
| 934 | .mask = gpio_mask_irq, |
| 935 | .unmask = gpio_unmask_irq, |
| 936 | .set_type = gpio_irq_type, |
| 937 | .set_wake = gpio_wake_enable, |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 938 | }; |
| 939 | |
| 940 | static struct irqchip mpuio_irq_chip = { |
| 941 | .ack = mpuio_ack_irq, |
| 942 | .mask = mpuio_mask_irq, |
| 943 | .unmask = mpuio_unmask_irq |
| 944 | }; |
| 945 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 946 | static int initialized; |
| 947 | static struct clk * gpio_ick; |
| 948 | static struct clk * gpio_fck; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 949 | |
| 950 | static int __init _omap_gpio_init(void) |
| 951 | { |
| 952 | int i; |
| 953 | struct gpio_bank *bank; |
| 954 | |
| 955 | initialized = 1; |
| 956 | |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 957 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 958 | gpio_ick = clk_get(NULL, "arm_gpio_ck"); |
| 959 | if (IS_ERR(gpio_ick)) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 960 | printk("Could not get arm_gpio_ck\n"); |
| 961 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 962 | clk_enable(gpio_ick); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 963 | } |
| 964 | if (cpu_is_omap24xx()) { |
| 965 | gpio_ick = clk_get(NULL, "gpios_ick"); |
| 966 | if (IS_ERR(gpio_ick)) |
| 967 | printk("Could not get gpios_ick\n"); |
| 968 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 969 | clk_enable(gpio_ick); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 970 | gpio_fck = clk_get(NULL, "gpios_fck"); |
| 971 | if (IS_ERR(gpio_ick)) |
| 972 | printk("Could not get gpios_fck\n"); |
| 973 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 974 | clk_enable(gpio_fck); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 975 | } |
| 976 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 977 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 978 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 979 | printk(KERN_INFO "OMAP1510 GPIO hardware\n"); |
| 980 | gpio_bank_count = 2; |
| 981 | gpio_bank = gpio_bank_1510; |
| 982 | } |
| 983 | #endif |
| 984 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 985 | if (cpu_is_omap16xx()) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 986 | u32 rev; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 987 | |
| 988 | gpio_bank_count = 5; |
| 989 | gpio_bank = gpio_bank_1610; |
| 990 | rev = omap_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION); |
| 991 | printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n", |
| 992 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 993 | } |
| 994 | #endif |
| 995 | #ifdef CONFIG_ARCH_OMAP730 |
| 996 | if (cpu_is_omap730()) { |
| 997 | printk(KERN_INFO "OMAP730 GPIO hardware\n"); |
| 998 | gpio_bank_count = 7; |
| 999 | gpio_bank = gpio_bank_730; |
| 1000 | } |
| 1001 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1002 | #ifdef CONFIG_ARCH_OMAP24XX |
| 1003 | if (cpu_is_omap24xx()) { |
| 1004 | int rev; |
| 1005 | |
| 1006 | gpio_bank_count = 4; |
| 1007 | gpio_bank = gpio_bank_24xx; |
| 1008 | rev = omap_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); |
| 1009 | printk(KERN_INFO "OMAP24xx GPIO hardware version %d.%d\n", |
| 1010 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1011 | } |
| 1012 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1013 | for (i = 0; i < gpio_bank_count; i++) { |
| 1014 | int j, gpio_count = 16; |
| 1015 | |
| 1016 | bank = &gpio_bank[i]; |
| 1017 | bank->reserved_map = 0; |
| 1018 | bank->base = IO_ADDRESS(bank->base); |
| 1019 | spin_lock_init(&bank->lock); |
| 1020 | if (bank->method == METHOD_MPUIO) { |
| 1021 | omap_writew(0xFFFF, OMAP_MPUIO_BASE + OMAP_MPUIO_GPIO_MASKIT); |
| 1022 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1023 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1024 | if (bank->method == METHOD_GPIO_1510) { |
| 1025 | __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK); |
| 1026 | __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS); |
| 1027 | } |
| 1028 | #endif |
| 1029 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 1030 | if (bank->method == METHOD_GPIO_1610) { |
| 1031 | __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1); |
| 1032 | __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1033 | __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1034 | } |
| 1035 | #endif |
| 1036 | #ifdef CONFIG_ARCH_OMAP730 |
| 1037 | if (bank->method == METHOD_GPIO_730) { |
| 1038 | __raw_writel(0xffffffff, bank->base + OMAP730_GPIO_INT_MASK); |
| 1039 | __raw_writel(0x00000000, bank->base + OMAP730_GPIO_INT_STATUS); |
| 1040 | |
| 1041 | gpio_count = 32; /* 730 has 32-bit GPIOs */ |
| 1042 | } |
| 1043 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1044 | #ifdef CONFIG_ARCH_OMAP24XX |
| 1045 | if (bank->method == METHOD_GPIO_24XX) { |
| 1046 | __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1); |
| 1047 | __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1); |
| 1048 | |
| 1049 | gpio_count = 32; |
| 1050 | } |
| 1051 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1052 | for (j = bank->virtual_irq_start; |
| 1053 | j < bank->virtual_irq_start + gpio_count; j++) { |
| 1054 | if (bank->method == METHOD_MPUIO) |
| 1055 | set_irq_chip(j, &mpuio_irq_chip); |
| 1056 | else |
| 1057 | set_irq_chip(j, &gpio_irq_chip); |
| 1058 | set_irq_handler(j, do_simple_IRQ); |
| 1059 | set_irq_flags(j, IRQF_VALID); |
| 1060 | } |
| 1061 | set_irq_chained_handler(bank->irq, gpio_irq_handler); |
| 1062 | set_irq_data(bank->irq, bank); |
| 1063 | } |
| 1064 | |
| 1065 | /* Enable system clock for GPIO module. |
| 1066 | * The CAM_CLK_CTRL *is* really the right place. */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1067 | if (cpu_is_omap16xx()) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1068 | omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL); |
| 1069 | |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1073 | #if defined (CONFIG_ARCH_OMAP16XX) || defined (CONFIG_ARCH_OMAP24XX) |
| 1074 | static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg) |
| 1075 | { |
| 1076 | int i; |
| 1077 | |
| 1078 | if (!cpu_is_omap24xx() && !cpu_is_omap16xx()) |
| 1079 | return 0; |
| 1080 | |
| 1081 | for (i = 0; i < gpio_bank_count; i++) { |
| 1082 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1083 | void __iomem *wake_status; |
| 1084 | void __iomem *wake_clear; |
| 1085 | void __iomem *wake_set; |
| 1086 | |
| 1087 | switch (bank->method) { |
| 1088 | case METHOD_GPIO_1610: |
| 1089 | wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE; |
| 1090 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1091 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1092 | break; |
| 1093 | case METHOD_GPIO_24XX: |
| 1094 | wake_status = bank->base + OMAP24XX_GPIO_SETWKUENA; |
| 1095 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 1096 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
| 1097 | break; |
| 1098 | default: |
| 1099 | continue; |
| 1100 | } |
| 1101 | |
| 1102 | spin_lock(&bank->lock); |
| 1103 | bank->saved_wakeup = __raw_readl(wake_status); |
| 1104 | __raw_writel(0xffffffff, wake_clear); |
| 1105 | __raw_writel(bank->suspend_wakeup, wake_set); |
| 1106 | spin_unlock(&bank->lock); |
| 1107 | } |
| 1108 | |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
| 1112 | static int omap_gpio_resume(struct sys_device *dev) |
| 1113 | { |
| 1114 | int i; |
| 1115 | |
| 1116 | if (!cpu_is_omap24xx() && !cpu_is_omap16xx()) |
| 1117 | return 0; |
| 1118 | |
| 1119 | for (i = 0; i < gpio_bank_count; i++) { |
| 1120 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1121 | void __iomem *wake_clear; |
| 1122 | void __iomem *wake_set; |
| 1123 | |
| 1124 | switch (bank->method) { |
| 1125 | case METHOD_GPIO_1610: |
| 1126 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1127 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1128 | break; |
| 1129 | case METHOD_GPIO_24XX: |
| 1130 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1131 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1132 | break; |
| 1133 | default: |
| 1134 | continue; |
| 1135 | } |
| 1136 | |
| 1137 | spin_lock(&bank->lock); |
| 1138 | __raw_writel(0xffffffff, wake_clear); |
| 1139 | __raw_writel(bank->saved_wakeup, wake_set); |
| 1140 | spin_unlock(&bank->lock); |
| 1141 | } |
| 1142 | |
| 1143 | return 0; |
| 1144 | } |
| 1145 | |
| 1146 | static struct sysdev_class omap_gpio_sysclass = { |
| 1147 | set_kset_name("gpio"), |
| 1148 | .suspend = omap_gpio_suspend, |
| 1149 | .resume = omap_gpio_resume, |
| 1150 | }; |
| 1151 | |
| 1152 | static struct sys_device omap_gpio_device = { |
| 1153 | .id = 0, |
| 1154 | .cls = &omap_gpio_sysclass, |
| 1155 | }; |
| 1156 | #endif |
| 1157 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1158 | /* |
| 1159 | * This may get called early from board specific init |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1160 | * for boards that have interrupts routed via FPGA. |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1161 | */ |
| 1162 | int omap_gpio_init(void) |
| 1163 | { |
| 1164 | if (!initialized) |
| 1165 | return _omap_gpio_init(); |
| 1166 | else |
| 1167 | return 0; |
| 1168 | } |
| 1169 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1170 | static int __init omap_gpio_sysinit(void) |
| 1171 | { |
| 1172 | int ret = 0; |
| 1173 | |
| 1174 | if (!initialized) |
| 1175 | ret = _omap_gpio_init(); |
| 1176 | |
| 1177 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) |
| 1178 | if (cpu_is_omap16xx() || cpu_is_omap24xx()) { |
| 1179 | if (ret == 0) { |
| 1180 | ret = sysdev_class_register(&omap_gpio_sysclass); |
| 1181 | if (ret == 0) |
| 1182 | ret = sysdev_register(&omap_gpio_device); |
| 1183 | } |
| 1184 | } |
| 1185 | #endif |
| 1186 | |
| 1187 | return ret; |
| 1188 | } |
| 1189 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1190 | EXPORT_SYMBOL(omap_request_gpio); |
| 1191 | EXPORT_SYMBOL(omap_free_gpio); |
| 1192 | EXPORT_SYMBOL(omap_set_gpio_direction); |
| 1193 | EXPORT_SYMBOL(omap_set_gpio_dataout); |
| 1194 | EXPORT_SYMBOL(omap_get_gpio_datain); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1195 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1196 | arch_initcall(omap_gpio_sysinit); |