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 |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 7 | * Written by Juha Yrjölä <juha.yrjola@nokia.com> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 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 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include <linux/module.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 17 | #include <linux/sysdev.h> |
| 18 | #include <linux/err.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 19 | #include <linux/clk.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 20 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 21 | #include <mach/hardware.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 22 | #include <asm/irq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 23 | #include <mach/irqs.h> |
| 24 | #include <mach/gpio.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 25 | #include <asm/mach/irq.h> |
| 26 | |
| 27 | #include <asm/io.h> |
| 28 | |
| 29 | /* |
| 30 | * OMAP1510 GPIO registers |
| 31 | */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 32 | #define OMAP1510_GPIO_BASE (void __iomem *)0xfffce000 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 33 | #define OMAP1510_GPIO_DATA_INPUT 0x00 |
| 34 | #define OMAP1510_GPIO_DATA_OUTPUT 0x04 |
| 35 | #define OMAP1510_GPIO_DIR_CONTROL 0x08 |
| 36 | #define OMAP1510_GPIO_INT_CONTROL 0x0c |
| 37 | #define OMAP1510_GPIO_INT_MASK 0x10 |
| 38 | #define OMAP1510_GPIO_INT_STATUS 0x14 |
| 39 | #define OMAP1510_GPIO_PIN_CONTROL 0x18 |
| 40 | |
| 41 | #define OMAP1510_IH_GPIO_BASE 64 |
| 42 | |
| 43 | /* |
| 44 | * OMAP1610 specific GPIO registers |
| 45 | */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 46 | #define OMAP1610_GPIO1_BASE (void __iomem *)0xfffbe400 |
| 47 | #define OMAP1610_GPIO2_BASE (void __iomem *)0xfffbec00 |
| 48 | #define OMAP1610_GPIO3_BASE (void __iomem *)0xfffbb400 |
| 49 | #define OMAP1610_GPIO4_BASE (void __iomem *)0xfffbbc00 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 50 | #define OMAP1610_GPIO_REVISION 0x0000 |
| 51 | #define OMAP1610_GPIO_SYSCONFIG 0x0010 |
| 52 | #define OMAP1610_GPIO_SYSSTATUS 0x0014 |
| 53 | #define OMAP1610_GPIO_IRQSTATUS1 0x0018 |
| 54 | #define OMAP1610_GPIO_IRQENABLE1 0x001c |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 55 | #define OMAP1610_GPIO_WAKEUPENABLE 0x0028 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 56 | #define OMAP1610_GPIO_DATAIN 0x002c |
| 57 | #define OMAP1610_GPIO_DATAOUT 0x0030 |
| 58 | #define OMAP1610_GPIO_DIRECTION 0x0034 |
| 59 | #define OMAP1610_GPIO_EDGE_CTRL1 0x0038 |
| 60 | #define OMAP1610_GPIO_EDGE_CTRL2 0x003c |
| 61 | #define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 62 | #define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 63 | #define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0 |
| 64 | #define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 65 | #define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 66 | #define OMAP1610_GPIO_SET_DATAOUT 0x00f0 |
| 67 | |
| 68 | /* |
| 69 | * OMAP730 specific GPIO registers |
| 70 | */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 71 | #define OMAP730_GPIO1_BASE (void __iomem *)0xfffbc000 |
| 72 | #define OMAP730_GPIO2_BASE (void __iomem *)0xfffbc800 |
| 73 | #define OMAP730_GPIO3_BASE (void __iomem *)0xfffbd000 |
| 74 | #define OMAP730_GPIO4_BASE (void __iomem *)0xfffbd800 |
| 75 | #define OMAP730_GPIO5_BASE (void __iomem *)0xfffbe000 |
| 76 | #define OMAP730_GPIO6_BASE (void __iomem *)0xfffbe800 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 77 | #define OMAP730_GPIO_DATA_INPUT 0x00 |
| 78 | #define OMAP730_GPIO_DATA_OUTPUT 0x04 |
| 79 | #define OMAP730_GPIO_DIR_CONTROL 0x08 |
| 80 | #define OMAP730_GPIO_INT_CONTROL 0x0c |
| 81 | #define OMAP730_GPIO_INT_MASK 0x10 |
| 82 | #define OMAP730_GPIO_INT_STATUS 0x14 |
| 83 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 84 | /* |
| 85 | * omap24xx specific GPIO registers |
| 86 | */ |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 87 | #define OMAP242X_GPIO1_BASE (void __iomem *)0x48018000 |
| 88 | #define OMAP242X_GPIO2_BASE (void __iomem *)0x4801a000 |
| 89 | #define OMAP242X_GPIO3_BASE (void __iomem *)0x4801c000 |
| 90 | #define OMAP242X_GPIO4_BASE (void __iomem *)0x4801e000 |
| 91 | |
| 92 | #define OMAP243X_GPIO1_BASE (void __iomem *)0x4900C000 |
| 93 | #define OMAP243X_GPIO2_BASE (void __iomem *)0x4900E000 |
| 94 | #define OMAP243X_GPIO3_BASE (void __iomem *)0x49010000 |
| 95 | #define OMAP243X_GPIO4_BASE (void __iomem *)0x49012000 |
| 96 | #define OMAP243X_GPIO5_BASE (void __iomem *)0x480B6000 |
| 97 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 98 | #define OMAP24XX_GPIO_REVISION 0x0000 |
| 99 | #define OMAP24XX_GPIO_SYSCONFIG 0x0010 |
| 100 | #define OMAP24XX_GPIO_SYSSTATUS 0x0014 |
| 101 | #define OMAP24XX_GPIO_IRQSTATUS1 0x0018 |
Hiroshi DOYU | bee7930 | 2006-09-25 12:41:46 +0300 | [diff] [blame] | 102 | #define OMAP24XX_GPIO_IRQSTATUS2 0x0028 |
| 103 | #define OMAP24XX_GPIO_IRQENABLE2 0x002c |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 104 | #define OMAP24XX_GPIO_IRQENABLE1 0x001c |
| 105 | #define OMAP24XX_GPIO_CTRL 0x0030 |
| 106 | #define OMAP24XX_GPIO_OE 0x0034 |
| 107 | #define OMAP24XX_GPIO_DATAIN 0x0038 |
| 108 | #define OMAP24XX_GPIO_DATAOUT 0x003c |
| 109 | #define OMAP24XX_GPIO_LEVELDETECT0 0x0040 |
| 110 | #define OMAP24XX_GPIO_LEVELDETECT1 0x0044 |
| 111 | #define OMAP24XX_GPIO_RISINGDETECT 0x0048 |
| 112 | #define OMAP24XX_GPIO_FALLINGDETECT 0x004c |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 113 | #define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050 |
| 114 | #define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054 |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 115 | #define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060 |
| 116 | #define OMAP24XX_GPIO_SETIRQENABLE1 0x0064 |
| 117 | #define OMAP24XX_GPIO_CLEARWKUENA 0x0080 |
| 118 | #define OMAP24XX_GPIO_SETWKUENA 0x0084 |
| 119 | #define OMAP24XX_GPIO_CLEARDATAOUT 0x0090 |
| 120 | #define OMAP24XX_GPIO_SETDATAOUT 0x0094 |
| 121 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 122 | /* |
| 123 | * omap34xx specific GPIO registers |
| 124 | */ |
| 125 | |
| 126 | #define OMAP34XX_GPIO1_BASE (void __iomem *)0x48310000 |
| 127 | #define OMAP34XX_GPIO2_BASE (void __iomem *)0x49050000 |
| 128 | #define OMAP34XX_GPIO3_BASE (void __iomem *)0x49052000 |
| 129 | #define OMAP34XX_GPIO4_BASE (void __iomem *)0x49054000 |
| 130 | #define OMAP34XX_GPIO5_BASE (void __iomem *)0x49056000 |
| 131 | #define OMAP34XX_GPIO6_BASE (void __iomem *)0x49058000 |
| 132 | |
| 133 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 134 | struct gpio_bank { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 135 | void __iomem *base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 136 | u16 irq; |
| 137 | u16 virtual_irq_start; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 138 | int method; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 139 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 140 | u32 suspend_wakeup; |
| 141 | u32 saved_wakeup; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 142 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 143 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 144 | u32 non_wakeup_gpios; |
| 145 | u32 enabled_non_wakeup_gpios; |
| 146 | |
| 147 | u32 saved_datain; |
| 148 | u32 saved_fallingdetect; |
| 149 | u32 saved_risingdetect; |
| 150 | #endif |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 151 | u32 level_mask; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 152 | spinlock_t lock; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 153 | struct gpio_chip chip; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | #define METHOD_MPUIO 0 |
| 157 | #define METHOD_GPIO_1510 1 |
| 158 | #define METHOD_GPIO_1610 2 |
| 159 | #define METHOD_GPIO_730 3 |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 160 | #define METHOD_GPIO_24XX 4 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 161 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 162 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 163 | static struct gpio_bank gpio_bank_1610[5] = { |
| 164 | { OMAP_MPUIO_BASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO}, |
| 165 | { OMAP1610_GPIO1_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1610 }, |
| 166 | { OMAP1610_GPIO2_BASE, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16, METHOD_GPIO_1610 }, |
| 167 | { OMAP1610_GPIO3_BASE, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32, METHOD_GPIO_1610 }, |
| 168 | { OMAP1610_GPIO4_BASE, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48, METHOD_GPIO_1610 }, |
| 169 | }; |
| 170 | #endif |
| 171 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 172 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 173 | static struct gpio_bank gpio_bank_1510[2] = { |
| 174 | { OMAP_MPUIO_BASE, INT_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO }, |
| 175 | { OMAP1510_GPIO_BASE, INT_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_1510 } |
| 176 | }; |
| 177 | #endif |
| 178 | |
| 179 | #ifdef CONFIG_ARCH_OMAP730 |
| 180 | static struct gpio_bank gpio_bank_730[7] = { |
| 181 | { OMAP_MPUIO_BASE, INT_730_MPUIO, IH_MPUIO_BASE, METHOD_MPUIO }, |
| 182 | { OMAP730_GPIO1_BASE, INT_730_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_730 }, |
| 183 | { OMAP730_GPIO2_BASE, INT_730_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_730 }, |
| 184 | { OMAP730_GPIO3_BASE, INT_730_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_730 }, |
| 185 | { OMAP730_GPIO4_BASE, INT_730_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_730 }, |
| 186 | { OMAP730_GPIO5_BASE, INT_730_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_730 }, |
| 187 | { OMAP730_GPIO6_BASE, INT_730_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_730 }, |
| 188 | }; |
| 189 | #endif |
| 190 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 191 | #ifdef CONFIG_ARCH_OMAP24XX |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 192 | |
| 193 | static struct gpio_bank gpio_bank_242x[4] = { |
| 194 | { OMAP242X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX }, |
| 195 | { OMAP242X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX }, |
| 196 | { OMAP242X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX }, |
| 197 | { OMAP242X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX }, |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 198 | }; |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 199 | |
| 200 | static struct gpio_bank gpio_bank_243x[5] = { |
| 201 | { OMAP243X_GPIO1_BASE, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX }, |
| 202 | { OMAP243X_GPIO2_BASE, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX }, |
| 203 | { OMAP243X_GPIO3_BASE, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX }, |
| 204 | { OMAP243X_GPIO4_BASE, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX }, |
| 205 | { OMAP243X_GPIO5_BASE, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX }, |
| 206 | }; |
| 207 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 208 | #endif |
| 209 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 210 | #ifdef CONFIG_ARCH_OMAP34XX |
| 211 | static struct gpio_bank gpio_bank_34xx[6] = { |
| 212 | { OMAP34XX_GPIO1_BASE, INT_34XX_GPIO_BANK1, IH_GPIO_BASE, METHOD_GPIO_24XX }, |
| 213 | { OMAP34XX_GPIO2_BASE, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32, METHOD_GPIO_24XX }, |
| 214 | { OMAP34XX_GPIO3_BASE, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64, METHOD_GPIO_24XX }, |
| 215 | { OMAP34XX_GPIO4_BASE, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96, METHOD_GPIO_24XX }, |
| 216 | { OMAP34XX_GPIO5_BASE, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128, METHOD_GPIO_24XX }, |
| 217 | { OMAP34XX_GPIO6_BASE, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160, METHOD_GPIO_24XX }, |
| 218 | }; |
| 219 | |
| 220 | #endif |
| 221 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 222 | static struct gpio_bank *gpio_bank; |
| 223 | static int gpio_bank_count; |
| 224 | |
| 225 | static inline struct gpio_bank *get_gpio_bank(int gpio) |
| 226 | { |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 227 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 228 | if (OMAP_GPIO_IS_MPUIO(gpio)) |
| 229 | return &gpio_bank[0]; |
| 230 | return &gpio_bank[1]; |
| 231 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 232 | if (cpu_is_omap16xx()) { |
| 233 | if (OMAP_GPIO_IS_MPUIO(gpio)) |
| 234 | return &gpio_bank[0]; |
| 235 | return &gpio_bank[1 + (gpio >> 4)]; |
| 236 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 237 | if (cpu_is_omap730()) { |
| 238 | if (OMAP_GPIO_IS_MPUIO(gpio)) |
| 239 | return &gpio_bank[0]; |
| 240 | return &gpio_bank[1 + (gpio >> 5)]; |
| 241 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 242 | if (cpu_is_omap24xx()) |
| 243 | return &gpio_bank[gpio >> 5]; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 244 | if (cpu_is_omap34xx()) |
| 245 | return &gpio_bank[gpio >> 5]; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | static inline int get_gpio_index(int gpio) |
| 249 | { |
| 250 | if (cpu_is_omap730()) |
| 251 | return gpio & 0x1f; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 252 | if (cpu_is_omap24xx()) |
| 253 | return gpio & 0x1f; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 254 | if (cpu_is_omap34xx()) |
| 255 | return gpio & 0x1f; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 256 | return gpio & 0x0f; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | static inline int gpio_valid(int gpio) |
| 260 | { |
| 261 | if (gpio < 0) |
| 262 | return -1; |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 263 | if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) { |
Jonathan McDowell | 193e68b | 2006-09-25 12:41:30 +0300 | [diff] [blame] | 264 | if (gpio >= OMAP_MAX_GPIO_LINES + 16) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 265 | return -1; |
| 266 | return 0; |
| 267 | } |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 268 | if (cpu_is_omap15xx() && gpio < 16) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 269 | return 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 270 | if ((cpu_is_omap16xx()) && gpio < 64) |
| 271 | return 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 272 | if (cpu_is_omap730() && gpio < 192) |
| 273 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 274 | if (cpu_is_omap24xx() && gpio < 128) |
| 275 | return 0; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 276 | if (cpu_is_omap34xx() && gpio < 160) |
| 277 | return 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 278 | return -1; |
| 279 | } |
| 280 | |
| 281 | static int check_gpio(int gpio) |
| 282 | { |
| 283 | if (unlikely(gpio_valid(gpio)) < 0) { |
| 284 | printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio); |
| 285 | dump_stack(); |
| 286 | return -1; |
| 287 | } |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) |
| 292 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 293 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 294 | u32 l; |
| 295 | |
| 296 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 297 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 298 | case METHOD_MPUIO: |
| 299 | reg += OMAP_MPUIO_IO_CNTL; |
| 300 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 301 | #endif |
| 302 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 303 | case METHOD_GPIO_1510: |
| 304 | reg += OMAP1510_GPIO_DIR_CONTROL; |
| 305 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 306 | #endif |
| 307 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 308 | case METHOD_GPIO_1610: |
| 309 | reg += OMAP1610_GPIO_DIRECTION; |
| 310 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 311 | #endif |
| 312 | #ifdef CONFIG_ARCH_OMAP730 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 313 | case METHOD_GPIO_730: |
| 314 | reg += OMAP730_GPIO_DIR_CONTROL; |
| 315 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 316 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 317 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 318 | case METHOD_GPIO_24XX: |
| 319 | reg += OMAP24XX_GPIO_OE; |
| 320 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 321 | #endif |
| 322 | default: |
| 323 | WARN_ON(1); |
| 324 | return; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 325 | } |
| 326 | l = __raw_readl(reg); |
| 327 | if (is_input) |
| 328 | l |= 1 << gpio; |
| 329 | else |
| 330 | l &= ~(1 << gpio); |
| 331 | __raw_writel(l, reg); |
| 332 | } |
| 333 | |
| 334 | void omap_set_gpio_direction(int gpio, int is_input) |
| 335 | { |
| 336 | struct gpio_bank *bank; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 337 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 338 | |
| 339 | if (check_gpio(gpio) < 0) |
| 340 | return; |
| 341 | bank = get_gpio_bank(gpio); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 342 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 343 | _set_gpio_direction(bank, get_gpio_index(gpio), is_input); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 344 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable) |
| 348 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 349 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 350 | u32 l = 0; |
| 351 | |
| 352 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 353 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 354 | case METHOD_MPUIO: |
| 355 | reg += OMAP_MPUIO_OUTPUT; |
| 356 | l = __raw_readl(reg); |
| 357 | if (enable) |
| 358 | l |= 1 << gpio; |
| 359 | else |
| 360 | l &= ~(1 << gpio); |
| 361 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 362 | #endif |
| 363 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 364 | case METHOD_GPIO_1510: |
| 365 | reg += OMAP1510_GPIO_DATA_OUTPUT; |
| 366 | l = __raw_readl(reg); |
| 367 | if (enable) |
| 368 | l |= 1 << gpio; |
| 369 | else |
| 370 | l &= ~(1 << gpio); |
| 371 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 372 | #endif |
| 373 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 374 | case METHOD_GPIO_1610: |
| 375 | if (enable) |
| 376 | reg += OMAP1610_GPIO_SET_DATAOUT; |
| 377 | else |
| 378 | reg += OMAP1610_GPIO_CLEAR_DATAOUT; |
| 379 | l = 1 << gpio; |
| 380 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 381 | #endif |
| 382 | #ifdef CONFIG_ARCH_OMAP730 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 383 | case METHOD_GPIO_730: |
| 384 | reg += OMAP730_GPIO_DATA_OUTPUT; |
| 385 | l = __raw_readl(reg); |
| 386 | if (enable) |
| 387 | l |= 1 << gpio; |
| 388 | else |
| 389 | l &= ~(1 << gpio); |
| 390 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 391 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 392 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 393 | case METHOD_GPIO_24XX: |
| 394 | if (enable) |
| 395 | reg += OMAP24XX_GPIO_SETDATAOUT; |
| 396 | else |
| 397 | reg += OMAP24XX_GPIO_CLEARDATAOUT; |
| 398 | l = 1 << gpio; |
| 399 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 400 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 401 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 402 | WARN_ON(1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 403 | return; |
| 404 | } |
| 405 | __raw_writel(l, reg); |
| 406 | } |
| 407 | |
| 408 | void omap_set_gpio_dataout(int gpio, int enable) |
| 409 | { |
| 410 | struct gpio_bank *bank; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 411 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 412 | |
| 413 | if (check_gpio(gpio) < 0) |
| 414 | return; |
| 415 | bank = get_gpio_bank(gpio); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 416 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 417 | _set_gpio_dataout(bank, get_gpio_index(gpio), enable); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 418 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | int omap_get_gpio_datain(int gpio) |
| 422 | { |
| 423 | struct gpio_bank *bank; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 424 | void __iomem *reg; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 425 | |
| 426 | if (check_gpio(gpio) < 0) |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 427 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 428 | bank = get_gpio_bank(gpio); |
| 429 | reg = bank->base; |
| 430 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 431 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 432 | case METHOD_MPUIO: |
| 433 | reg += OMAP_MPUIO_INPUT_LATCH; |
| 434 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 435 | #endif |
| 436 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 437 | case METHOD_GPIO_1510: |
| 438 | reg += OMAP1510_GPIO_DATA_INPUT; |
| 439 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 440 | #endif |
| 441 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 442 | case METHOD_GPIO_1610: |
| 443 | reg += OMAP1610_GPIO_DATAIN; |
| 444 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 445 | #endif |
| 446 | #ifdef CONFIG_ARCH_OMAP730 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 447 | case METHOD_GPIO_730: |
| 448 | reg += OMAP730_GPIO_DATA_INPUT; |
| 449 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 450 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 451 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 452 | case METHOD_GPIO_24XX: |
| 453 | reg += OMAP24XX_GPIO_DATAIN; |
| 454 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 455 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 456 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 457 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 458 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 459 | return (__raw_readl(reg) |
| 460 | & (1 << get_gpio_index(gpio))) != 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 463 | #define MOD_REG_BIT(reg, bit_mask, set) \ |
| 464 | do { \ |
| 465 | int l = __raw_readl(base + reg); \ |
| 466 | if (set) l |= bit_mask; \ |
| 467 | else l &= ~bit_mask; \ |
| 468 | __raw_writel(l, base + reg); \ |
| 469 | } while(0) |
| 470 | |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 471 | void omap_set_gpio_debounce(int gpio, int enable) |
| 472 | { |
| 473 | struct gpio_bank *bank; |
| 474 | void __iomem *reg; |
| 475 | u32 val, l = 1 << get_gpio_index(gpio); |
| 476 | |
| 477 | if (cpu_class_is_omap1()) |
| 478 | return; |
| 479 | |
| 480 | bank = get_gpio_bank(gpio); |
| 481 | reg = bank->base; |
| 482 | |
| 483 | reg += OMAP24XX_GPIO_DEBOUNCE_EN; |
| 484 | val = __raw_readl(reg); |
| 485 | |
| 486 | if (enable) |
| 487 | val |= l; |
| 488 | else |
| 489 | val &= ~l; |
| 490 | |
| 491 | __raw_writel(val, reg); |
| 492 | } |
| 493 | EXPORT_SYMBOL(omap_set_gpio_debounce); |
| 494 | |
| 495 | void omap_set_gpio_debounce_time(int gpio, int enc_time) |
| 496 | { |
| 497 | struct gpio_bank *bank; |
| 498 | void __iomem *reg; |
| 499 | |
| 500 | if (cpu_class_is_omap1()) |
| 501 | return; |
| 502 | |
| 503 | bank = get_gpio_bank(gpio); |
| 504 | reg = bank->base; |
| 505 | |
| 506 | enc_time &= 0xff; |
| 507 | reg += OMAP24XX_GPIO_DEBOUNCE_VAL; |
| 508 | __raw_writel(enc_time, reg); |
| 509 | } |
| 510 | EXPORT_SYMBOL(omap_set_gpio_debounce_time); |
| 511 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 512 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 513 | static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio, |
| 514 | int trigger) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 515 | { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 516 | void __iomem *base = bank->base; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 517 | u32 gpio_bit = 1 << gpio; |
| 518 | |
| 519 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit, |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 520 | trigger & IRQ_TYPE_LEVEL_LOW); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 521 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit, |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 522 | trigger & IRQ_TYPE_LEVEL_HIGH); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 523 | MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit, |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 524 | trigger & IRQ_TYPE_EDGE_RISING); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 525 | MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit, |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 526 | trigger & IRQ_TYPE_EDGE_FALLING); |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 527 | |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 528 | if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { |
| 529 | if (trigger != 0) |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 530 | __raw_writel(1 << gpio, bank->base |
| 531 | + OMAP24XX_GPIO_SETWKUENA); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 532 | else |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 533 | __raw_writel(1 << gpio, bank->base |
| 534 | + OMAP24XX_GPIO_CLEARWKUENA); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 535 | } else { |
| 536 | if (trigger != 0) |
| 537 | bank->enabled_non_wakeup_gpios |= gpio_bit; |
| 538 | else |
| 539 | bank->enabled_non_wakeup_gpios &= ~gpio_bit; |
| 540 | } |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 541 | |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 542 | bank->level_mask = |
| 543 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) | |
| 544 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 545 | } |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 546 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 547 | |
| 548 | static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger) |
| 549 | { |
| 550 | void __iomem *reg = bank->base; |
| 551 | u32 l = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 552 | |
| 553 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 554 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 555 | case METHOD_MPUIO: |
| 556 | reg += OMAP_MPUIO_GPIO_INT_EDGE; |
| 557 | l = __raw_readl(reg); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 558 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 559 | l |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 560 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 561 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 562 | else |
| 563 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 564 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 565 | #endif |
| 566 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 567 | case METHOD_GPIO_1510: |
| 568 | reg += OMAP1510_GPIO_INT_CONTROL; |
| 569 | l = __raw_readl(reg); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 570 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 571 | l |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 572 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 573 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 574 | else |
| 575 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 576 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 577 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 578 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 579 | case METHOD_GPIO_1610: |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 580 | if (gpio & 0x08) |
| 581 | reg += OMAP1610_GPIO_EDGE_CTRL2; |
| 582 | else |
| 583 | reg += OMAP1610_GPIO_EDGE_CTRL1; |
| 584 | gpio &= 0x07; |
| 585 | l = __raw_readl(reg); |
| 586 | l &= ~(3 << (gpio << 1)); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 587 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 588 | l |= 2 << (gpio << 1); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 589 | if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 590 | l |= 1 << (gpio << 1); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 591 | if (trigger) |
| 592 | /* Enable wake-up during idle for dynamic tick */ |
| 593 | __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA); |
| 594 | else |
| 595 | __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 596 | break; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 597 | #endif |
| 598 | #ifdef CONFIG_ARCH_OMAP730 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 599 | case METHOD_GPIO_730: |
| 600 | reg += OMAP730_GPIO_INT_CONTROL; |
| 601 | l = __raw_readl(reg); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 602 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 603 | l |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 604 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 605 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 606 | else |
| 607 | goto bad; |
| 608 | break; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 609 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 610 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 611 | case METHOD_GPIO_24XX: |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 612 | set_24xx_gpio_triggering(bank, gpio, trigger); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 613 | break; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 614 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 615 | default: |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 616 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 617 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 618 | __raw_writel(l, reg); |
| 619 | return 0; |
| 620 | bad: |
| 621 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 622 | } |
| 623 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 624 | static int gpio_irq_type(unsigned irq, unsigned type) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 625 | { |
| 626 | struct gpio_bank *bank; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 627 | unsigned gpio; |
| 628 | int retval; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 629 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 630 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 631 | if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 632 | gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); |
| 633 | else |
| 634 | gpio = irq - IH_GPIO_BASE; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 635 | |
| 636 | if (check_gpio(gpio) < 0) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 637 | return -EINVAL; |
| 638 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 639 | if (type & ~IRQ_TYPE_SENSE_MASK) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 640 | return -EINVAL; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 641 | |
| 642 | /* OMAP1 allows only only edge triggering */ |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 643 | if (!cpu_class_is_omap2() |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 644 | && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 645 | return -EINVAL; |
| 646 | |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 647 | bank = get_irq_chip_data(irq); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 648 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 649 | retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 650 | if (retval == 0) { |
| 651 | irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK; |
| 652 | irq_desc[irq].status |= type; |
| 653 | } |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 654 | spin_unlock_irqrestore(&bank->lock, flags); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 655 | |
| 656 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
| 657 | __set_irq_handler_unlocked(irq, handle_level_irq); |
| 658 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
| 659 | __set_irq_handler_unlocked(irq, handle_edge_irq); |
| 660 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 661 | return retval; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
| 665 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 666 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 667 | |
| 668 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 669 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 670 | case METHOD_MPUIO: |
| 671 | /* MPUIO irqstatus is reset by reading the status register, |
| 672 | * so do nothing here */ |
| 673 | return; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 674 | #endif |
| 675 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 676 | case METHOD_GPIO_1510: |
| 677 | reg += OMAP1510_GPIO_INT_STATUS; |
| 678 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 679 | #endif |
| 680 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 681 | case METHOD_GPIO_1610: |
| 682 | reg += OMAP1610_GPIO_IRQSTATUS1; |
| 683 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 684 | #endif |
| 685 | #ifdef CONFIG_ARCH_OMAP730 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 686 | case METHOD_GPIO_730: |
| 687 | reg += OMAP730_GPIO_INT_STATUS; |
| 688 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 689 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 690 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 691 | case METHOD_GPIO_24XX: |
| 692 | reg += OMAP24XX_GPIO_IRQSTATUS1; |
| 693 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 694 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 695 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 696 | WARN_ON(1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 697 | return; |
| 698 | } |
| 699 | __raw_writel(gpio_mask, reg); |
Hiroshi DOYU | bee7930 | 2006-09-25 12:41:46 +0300 | [diff] [blame] | 700 | |
| 701 | /* Workaround for clearing DSP GPIO interrupts to allow retention */ |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 702 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
| 703 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) |
Hiroshi DOYU | bee7930 | 2006-09-25 12:41:46 +0300 | [diff] [blame] | 704 | __raw_writel(gpio_mask, bank->base + OMAP24XX_GPIO_IRQSTATUS2); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 705 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) |
| 709 | { |
| 710 | _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio)); |
| 711 | } |
| 712 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 713 | static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank) |
| 714 | { |
| 715 | void __iomem *reg = bank->base; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 716 | int inv = 0; |
| 717 | u32 l; |
| 718 | u32 mask; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 719 | |
| 720 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 721 | #ifdef CONFIG_ARCH_OMAP1 |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 722 | case METHOD_MPUIO: |
| 723 | reg += OMAP_MPUIO_GPIO_MASKIT; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 724 | mask = 0xffff; |
| 725 | inv = 1; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 726 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 727 | #endif |
| 728 | #ifdef CONFIG_ARCH_OMAP15XX |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 729 | case METHOD_GPIO_1510: |
| 730 | reg += OMAP1510_GPIO_INT_MASK; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 731 | mask = 0xffff; |
| 732 | inv = 1; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 733 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 734 | #endif |
| 735 | #ifdef CONFIG_ARCH_OMAP16XX |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 736 | case METHOD_GPIO_1610: |
| 737 | reg += OMAP1610_GPIO_IRQENABLE1; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 738 | mask = 0xffff; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 739 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 740 | #endif |
| 741 | #ifdef CONFIG_ARCH_OMAP730 |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 742 | case METHOD_GPIO_730: |
| 743 | reg += OMAP730_GPIO_INT_MASK; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 744 | mask = 0xffffffff; |
| 745 | inv = 1; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 746 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 747 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 748 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 749 | case METHOD_GPIO_24XX: |
| 750 | reg += OMAP24XX_GPIO_IRQENABLE1; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 751 | mask = 0xffffffff; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 752 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 753 | #endif |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 754 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 755 | WARN_ON(1); |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 756 | return 0; |
| 757 | } |
| 758 | |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 759 | l = __raw_readl(reg); |
| 760 | if (inv) |
| 761 | l = ~l; |
| 762 | l &= mask; |
| 763 | return l; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 766 | static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable) |
| 767 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 768 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 769 | u32 l; |
| 770 | |
| 771 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 772 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 773 | case METHOD_MPUIO: |
| 774 | reg += OMAP_MPUIO_GPIO_MASKIT; |
| 775 | l = __raw_readl(reg); |
| 776 | if (enable) |
| 777 | l &= ~(gpio_mask); |
| 778 | else |
| 779 | l |= gpio_mask; |
| 780 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 781 | #endif |
| 782 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 783 | case METHOD_GPIO_1510: |
| 784 | reg += OMAP1510_GPIO_INT_MASK; |
| 785 | l = __raw_readl(reg); |
| 786 | if (enable) |
| 787 | l &= ~(gpio_mask); |
| 788 | else |
| 789 | l |= gpio_mask; |
| 790 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 791 | #endif |
| 792 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 793 | case METHOD_GPIO_1610: |
| 794 | if (enable) |
| 795 | reg += OMAP1610_GPIO_SET_IRQENABLE1; |
| 796 | else |
| 797 | reg += OMAP1610_GPIO_CLEAR_IRQENABLE1; |
| 798 | l = gpio_mask; |
| 799 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 800 | #endif |
| 801 | #ifdef CONFIG_ARCH_OMAP730 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 802 | case METHOD_GPIO_730: |
| 803 | reg += OMAP730_GPIO_INT_MASK; |
| 804 | l = __raw_readl(reg); |
| 805 | if (enable) |
| 806 | l &= ~(gpio_mask); |
| 807 | else |
| 808 | l |= gpio_mask; |
| 809 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 810 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 811 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 812 | case METHOD_GPIO_24XX: |
| 813 | if (enable) |
| 814 | reg += OMAP24XX_GPIO_SETIRQENABLE1; |
| 815 | else |
| 816 | reg += OMAP24XX_GPIO_CLEARIRQENABLE1; |
| 817 | l = gpio_mask; |
| 818 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 819 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 820 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 821 | WARN_ON(1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 822 | return; |
| 823 | } |
| 824 | __raw_writel(l, reg); |
| 825 | } |
| 826 | |
| 827 | static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable) |
| 828 | { |
| 829 | _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable); |
| 830 | } |
| 831 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 832 | /* |
| 833 | * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register. |
| 834 | * 1510 does not seem to have a wake-up register. If JTAG is connected |
| 835 | * to the target, system will wake up always on GPIO events. While |
| 836 | * system is running all registered GPIO interrupts need to have wake-up |
| 837 | * enabled. When system is suspended, only selected GPIO interrupts need |
| 838 | * to have wake-up enabled. |
| 839 | */ |
| 840 | static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) |
| 841 | { |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 842 | unsigned long flags; |
| 843 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 844 | switch (bank->method) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 845 | #ifdef CONFIG_ARCH_OMAP16XX |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 846 | case METHOD_MPUIO: |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 847 | case METHOD_GPIO_1610: |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 848 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 849 | if (enable) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 850 | bank->suspend_wakeup |= (1 << gpio); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 851 | enable_irq_wake(bank->irq); |
| 852 | } else { |
| 853 | disable_irq_wake(bank->irq); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 854 | bank->suspend_wakeup &= ~(1 << gpio); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 855 | } |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 856 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 857 | return 0; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 858 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 859 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 860 | case METHOD_GPIO_24XX: |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 861 | if (bank->non_wakeup_gpios & (1 << gpio)) { |
| 862 | printk(KERN_ERR "Unable to modify wakeup on " |
| 863 | "non-wakeup GPIO%d\n", |
| 864 | (bank - gpio_bank) * 32 + gpio); |
| 865 | return -EINVAL; |
| 866 | } |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 867 | spin_lock_irqsave(&bank->lock, flags); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 868 | if (enable) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 869 | bank->suspend_wakeup |= (1 << gpio); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 870 | enable_irq_wake(bank->irq); |
| 871 | } else { |
| 872 | disable_irq_wake(bank->irq); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 873 | bank->suspend_wakeup &= ~(1 << gpio); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 874 | } |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 875 | spin_unlock_irqrestore(&bank->lock, flags); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 876 | return 0; |
| 877 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 878 | default: |
| 879 | printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n", |
| 880 | bank->method); |
| 881 | return -EINVAL; |
| 882 | } |
| 883 | } |
| 884 | |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 885 | static void _reset_gpio(struct gpio_bank *bank, int gpio) |
| 886 | { |
| 887 | _set_gpio_direction(bank, get_gpio_index(gpio), 1); |
| 888 | _set_gpio_irqenable(bank, gpio, 0); |
| 889 | _clear_gpio_irqstatus(bank, gpio); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 890 | _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 891 | } |
| 892 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 893 | /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ |
| 894 | static int gpio_wake_enable(unsigned int irq, unsigned int enable) |
| 895 | { |
| 896 | unsigned int gpio = irq - IH_GPIO_BASE; |
| 897 | struct gpio_bank *bank; |
| 898 | int retval; |
| 899 | |
| 900 | if (check_gpio(gpio) < 0) |
| 901 | return -ENODEV; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 902 | bank = get_irq_chip_data(irq); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 903 | retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 904 | |
| 905 | return retval; |
| 906 | } |
| 907 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 908 | int omap_request_gpio(int gpio) |
| 909 | { |
| 910 | struct gpio_bank *bank; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 911 | unsigned long flags; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 912 | int status; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 913 | |
| 914 | if (check_gpio(gpio) < 0) |
| 915 | return -EINVAL; |
| 916 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 917 | status = gpio_request(gpio, NULL); |
| 918 | if (status < 0) |
| 919 | return status; |
| 920 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 921 | bank = get_gpio_bank(gpio); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 922 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 923 | |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 924 | /* Set trigger to none. You need to enable the desired trigger with |
| 925 | * request_irq() or set_irq_type(). |
| 926 | */ |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 927 | _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 928 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 929 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 930 | if (bank->method == METHOD_GPIO_1510) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 931 | void __iomem *reg; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 932 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 933 | /* Claim the pin for MPU */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 934 | reg = bank->base + OMAP1510_GPIO_PIN_CONTROL; |
| 935 | __raw_writel(__raw_readl(reg) | (1 << get_gpio_index(gpio)), reg); |
| 936 | } |
| 937 | #endif |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 938 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 939 | |
| 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | void omap_free_gpio(int gpio) |
| 944 | { |
| 945 | struct gpio_bank *bank; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 946 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 947 | |
| 948 | if (check_gpio(gpio) < 0) |
| 949 | return; |
| 950 | bank = get_gpio_bank(gpio); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 951 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 952 | if (unlikely(!gpiochip_is_requested(&bank->chip, |
| 953 | get_gpio_index(gpio)))) { |
| 954 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 955 | printk(KERN_ERR "omap-gpio: GPIO %d wasn't reserved!\n", gpio); |
| 956 | dump_stack(); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 957 | return; |
| 958 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 959 | #ifdef CONFIG_ARCH_OMAP16XX |
| 960 | if (bank->method == METHOD_GPIO_1610) { |
| 961 | /* Disable wake-up during idle for dynamic tick */ |
| 962 | void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 963 | __raw_writel(1 << get_gpio_index(gpio), reg); |
| 964 | } |
| 965 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 966 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 967 | if (bank->method == METHOD_GPIO_24XX) { |
| 968 | /* Disable wake-up during idle for dynamic tick */ |
| 969 | void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 970 | __raw_writel(1 << get_gpio_index(gpio), reg); |
| 971 | } |
| 972 | #endif |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 973 | _reset_gpio(bank, gpio); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 974 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 975 | gpio_free(gpio); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | /* |
| 979 | * We need to unmask the GPIO bank interrupt as soon as possible to |
| 980 | * avoid missing GPIO interrupts for other lines in the bank. |
| 981 | * Then we need to mask-read-clear-unmask the triggered GPIO lines |
| 982 | * in the bank to avoid missing nested interrupts for a GPIO line. |
| 983 | * If we wait to unmask individual GPIO lines in the bank after the |
| 984 | * line's interrupt handler has been run, we may miss some nested |
| 985 | * interrupts. |
| 986 | */ |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 987 | static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 988 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 989 | void __iomem *isr_reg = NULL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 990 | u32 isr; |
| 991 | unsigned int gpio_irq; |
| 992 | struct gpio_bank *bank; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 993 | u32 retrigger = 0; |
| 994 | int unmasked = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 995 | |
| 996 | desc->chip->ack(irq); |
| 997 | |
Thomas Gleixner | 418ca1f | 2006-07-01 22:32:41 +0100 | [diff] [blame] | 998 | bank = get_irq_data(irq); |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 999 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1000 | if (bank->method == METHOD_MPUIO) |
| 1001 | isr_reg = bank->base + OMAP_MPUIO_GPIO_INT; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1002 | #endif |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1003 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1004 | if (bank->method == METHOD_GPIO_1510) |
| 1005 | isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS; |
| 1006 | #endif |
| 1007 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 1008 | if (bank->method == METHOD_GPIO_1610) |
| 1009 | isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1; |
| 1010 | #endif |
| 1011 | #ifdef CONFIG_ARCH_OMAP730 |
| 1012 | if (bank->method == METHOD_GPIO_730) |
| 1013 | isr_reg = bank->base + OMAP730_GPIO_INT_STATUS; |
| 1014 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1015 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1016 | if (bank->method == METHOD_GPIO_24XX) |
| 1017 | isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1; |
| 1018 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1019 | while(1) { |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1020 | u32 isr_saved, level_mask = 0; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1021 | u32 enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1022 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1023 | enabled = _get_gpio_irqbank_mask(bank); |
| 1024 | isr_saved = isr = __raw_readl(isr_reg) & enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1025 | |
| 1026 | if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO)) |
| 1027 | isr &= 0x0000ffff; |
| 1028 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1029 | if (cpu_class_is_omap2()) { |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 1030 | level_mask = bank->level_mask & enabled; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1031 | } |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1032 | |
| 1033 | /* clear edge sensitive interrupts before handler(s) are |
| 1034 | called so that we don't miss any interrupt occurred while |
| 1035 | executing them */ |
| 1036 | _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0); |
| 1037 | _clear_gpio_irqbank(bank, isr_saved & ~level_mask); |
| 1038 | _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1); |
| 1039 | |
| 1040 | /* if there is only edge sensitive GPIO pin interrupts |
| 1041 | configured, we could unmask GPIO bank interrupt immediately */ |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1042 | if (!level_mask && !unmasked) { |
| 1043 | unmasked = 1; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1044 | desc->chip->unmask(irq); |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1045 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1046 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1047 | isr |= retrigger; |
| 1048 | retrigger = 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1049 | if (!isr) |
| 1050 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1051 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1052 | gpio_irq = bank->virtual_irq_start; |
| 1053 | for (; isr != 0; isr >>= 1, gpio_irq++) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1054 | if (!(isr & 1)) |
| 1055 | continue; |
Thomas Gleixner | 29454dd | 2006-07-03 02:22:22 +0200 | [diff] [blame] | 1056 | |
Dmitry Baryshkov | d8aa025 | 2008-10-09 13:36:24 +0100 | [diff] [blame^] | 1057 | generic_handle_irq(gpio_irq); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1058 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1059 | } |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1060 | /* if bank has any level sensitive GPIO pin interrupt |
| 1061 | configured, we must unmask the bank interrupt only after |
| 1062 | handler(s) are executed in order to avoid spurious bank |
| 1063 | interrupt */ |
| 1064 | if (!unmasked) |
| 1065 | desc->chip->unmask(irq); |
| 1066 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1067 | } |
| 1068 | |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 1069 | static void gpio_irq_shutdown(unsigned int irq) |
| 1070 | { |
| 1071 | unsigned int gpio = irq - IH_GPIO_BASE; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1072 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 1073 | |
| 1074 | _reset_gpio(bank, gpio); |
| 1075 | } |
| 1076 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1077 | static void gpio_ack_irq(unsigned int irq) |
| 1078 | { |
| 1079 | unsigned int gpio = irq - IH_GPIO_BASE; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1080 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1081 | |
| 1082 | _clear_gpio_irqstatus(bank, gpio); |
| 1083 | } |
| 1084 | |
| 1085 | static void gpio_mask_irq(unsigned int irq) |
| 1086 | { |
| 1087 | unsigned int gpio = irq - IH_GPIO_BASE; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1088 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1089 | |
| 1090 | _set_gpio_irqenable(bank, gpio, 0); |
| 1091 | } |
| 1092 | |
| 1093 | static void gpio_unmask_irq(unsigned int irq) |
| 1094 | { |
| 1095 | unsigned int gpio = irq - IH_GPIO_BASE; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1096 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 1097 | unsigned int irq_mask = 1 << get_gpio_index(gpio); |
| 1098 | |
| 1099 | /* For level-triggered GPIOs, the clearing must be done after |
| 1100 | * the HW source is cleared, thus after the handler has run */ |
| 1101 | if (bank->level_mask & irq_mask) { |
| 1102 | _set_gpio_irqenable(bank, gpio, 0); |
| 1103 | _clear_gpio_irqstatus(bank, gpio); |
| 1104 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1105 | |
Kevin Hilman | 4de8c75 | 2008-01-16 21:56:14 -0800 | [diff] [blame] | 1106 | _set_gpio_irqenable(bank, gpio, 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1107 | } |
| 1108 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1109 | static struct irq_chip gpio_irq_chip = { |
| 1110 | .name = "GPIO", |
| 1111 | .shutdown = gpio_irq_shutdown, |
| 1112 | .ack = gpio_ack_irq, |
| 1113 | .mask = gpio_mask_irq, |
| 1114 | .unmask = gpio_unmask_irq, |
| 1115 | .set_type = gpio_irq_type, |
| 1116 | .set_wake = gpio_wake_enable, |
| 1117 | }; |
| 1118 | |
| 1119 | /*---------------------------------------------------------------------*/ |
| 1120 | |
| 1121 | #ifdef CONFIG_ARCH_OMAP1 |
| 1122 | |
| 1123 | /* MPUIO uses the always-on 32k clock */ |
| 1124 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1125 | static void mpuio_ack_irq(unsigned int irq) |
| 1126 | { |
| 1127 | /* The ISR is reset automatically, so do nothing here. */ |
| 1128 | } |
| 1129 | |
| 1130 | static void mpuio_mask_irq(unsigned int irq) |
| 1131 | { |
| 1132 | unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1133 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1134 | |
| 1135 | _set_gpio_irqenable(bank, gpio, 0); |
| 1136 | } |
| 1137 | |
| 1138 | static void mpuio_unmask_irq(unsigned int irq) |
| 1139 | { |
| 1140 | unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1141 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1142 | |
| 1143 | _set_gpio_irqenable(bank, gpio, 1); |
| 1144 | } |
| 1145 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1146 | static struct irq_chip mpuio_irq_chip = { |
| 1147 | .name = "MPUIO", |
| 1148 | .ack = mpuio_ack_irq, |
| 1149 | .mask = mpuio_mask_irq, |
| 1150 | .unmask = mpuio_unmask_irq, |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1151 | .set_type = gpio_irq_type, |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1152 | #ifdef CONFIG_ARCH_OMAP16XX |
| 1153 | /* REVISIT: assuming only 16xx supports MPUIO wake events */ |
| 1154 | .set_wake = gpio_wake_enable, |
| 1155 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1156 | }; |
| 1157 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1158 | |
| 1159 | #define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO) |
| 1160 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1161 | |
| 1162 | #ifdef CONFIG_ARCH_OMAP16XX |
| 1163 | |
| 1164 | #include <linux/platform_device.h> |
| 1165 | |
| 1166 | static int omap_mpuio_suspend_late(struct platform_device *pdev, pm_message_t mesg) |
| 1167 | { |
| 1168 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1169 | void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1170 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1171 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1172 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1173 | bank->saved_wakeup = __raw_readl(mask_reg); |
| 1174 | __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1175 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | static int omap_mpuio_resume_early(struct platform_device *pdev) |
| 1181 | { |
| 1182 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1183 | void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1184 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1185 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1186 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1187 | __raw_writel(bank->saved_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1188 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | /* use platform_driver for this, now that there's no longer any |
| 1194 | * point to sys_device (other than not disturbing old code). |
| 1195 | */ |
| 1196 | static struct platform_driver omap_mpuio_driver = { |
| 1197 | .suspend_late = omap_mpuio_suspend_late, |
| 1198 | .resume_early = omap_mpuio_resume_early, |
| 1199 | .driver = { |
| 1200 | .name = "mpuio", |
| 1201 | }, |
| 1202 | }; |
| 1203 | |
| 1204 | static struct platform_device omap_mpuio_device = { |
| 1205 | .name = "mpuio", |
| 1206 | .id = -1, |
| 1207 | .dev = { |
| 1208 | .driver = &omap_mpuio_driver.driver, |
| 1209 | } |
| 1210 | /* could list the /proc/iomem resources */ |
| 1211 | }; |
| 1212 | |
| 1213 | static inline void mpuio_init(void) |
| 1214 | { |
David Brownell | fcf126d | 2007-04-02 12:46:47 -0700 | [diff] [blame] | 1215 | platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]); |
| 1216 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1217 | if (platform_driver_register(&omap_mpuio_driver) == 0) |
| 1218 | (void) platform_device_register(&omap_mpuio_device); |
| 1219 | } |
| 1220 | |
| 1221 | #else |
| 1222 | static inline void mpuio_init(void) {} |
| 1223 | #endif /* 16xx */ |
| 1224 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1225 | #else |
| 1226 | |
| 1227 | extern struct irq_chip mpuio_irq_chip; |
| 1228 | |
| 1229 | #define bank_is_mpuio(bank) 0 |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1230 | static inline void mpuio_init(void) {} |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1231 | |
| 1232 | #endif |
| 1233 | |
| 1234 | /*---------------------------------------------------------------------*/ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1235 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1236 | /* REVISIT these are stupid implementations! replace by ones that |
| 1237 | * don't switch on METHOD_* and which mostly avoid spinlocks |
| 1238 | */ |
| 1239 | |
| 1240 | static int gpio_input(struct gpio_chip *chip, unsigned offset) |
| 1241 | { |
| 1242 | struct gpio_bank *bank; |
| 1243 | unsigned long flags; |
| 1244 | |
| 1245 | bank = container_of(chip, struct gpio_bank, chip); |
| 1246 | spin_lock_irqsave(&bank->lock, flags); |
| 1247 | _set_gpio_direction(bank, offset, 1); |
| 1248 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1249 | return 0; |
| 1250 | } |
| 1251 | |
| 1252 | static int gpio_get(struct gpio_chip *chip, unsigned offset) |
| 1253 | { |
| 1254 | return omap_get_gpio_datain(chip->base + offset); |
| 1255 | } |
| 1256 | |
| 1257 | static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) |
| 1258 | { |
| 1259 | struct gpio_bank *bank; |
| 1260 | unsigned long flags; |
| 1261 | |
| 1262 | bank = container_of(chip, struct gpio_bank, chip); |
| 1263 | spin_lock_irqsave(&bank->lock, flags); |
| 1264 | _set_gpio_dataout(bank, offset, value); |
| 1265 | _set_gpio_direction(bank, offset, 0); |
| 1266 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 1271 | { |
| 1272 | struct gpio_bank *bank; |
| 1273 | unsigned long flags; |
| 1274 | |
| 1275 | bank = container_of(chip, struct gpio_bank, chip); |
| 1276 | spin_lock_irqsave(&bank->lock, flags); |
| 1277 | _set_gpio_dataout(bank, offset, value); |
| 1278 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1279 | } |
| 1280 | |
| 1281 | /*---------------------------------------------------------------------*/ |
| 1282 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1283 | static int initialized; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1284 | #if !defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1285 | static struct clk * gpio_ick; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1286 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1287 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1288 | #if defined(CONFIG_ARCH_OMAP2) |
| 1289 | static struct clk * gpio_fck; |
| 1290 | #endif |
| 1291 | |
| 1292 | #if defined(CONFIG_ARCH_OMAP2430) |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1293 | static struct clk * gpio5_ick; |
| 1294 | static struct clk * gpio5_fck; |
| 1295 | #endif |
| 1296 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1297 | #if defined(CONFIG_ARCH_OMAP3) |
| 1298 | static struct clk *gpio_fclks[OMAP34XX_NR_GPIOS]; |
| 1299 | static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS]; |
| 1300 | #endif |
| 1301 | |
David Brownell | 8ba55c5 | 2008-02-26 11:10:50 -0800 | [diff] [blame] | 1302 | /* This lock class tells lockdep that GPIO irqs are in a different |
| 1303 | * category than their parents, so it won't report false recursion. |
| 1304 | */ |
| 1305 | static struct lock_class_key gpio_lock_class; |
| 1306 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1307 | static int __init _omap_gpio_init(void) |
| 1308 | { |
| 1309 | int i; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1310 | int gpio = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1311 | struct gpio_bank *bank; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1312 | #if defined(CONFIG_ARCH_OMAP3) |
| 1313 | char clk_name[11]; |
| 1314 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1315 | |
| 1316 | initialized = 1; |
| 1317 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1318 | #if defined(CONFIG_ARCH_OMAP1) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1319 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1320 | gpio_ick = clk_get(NULL, "arm_gpio_ck"); |
| 1321 | if (IS_ERR(gpio_ick)) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1322 | printk("Could not get arm_gpio_ck\n"); |
| 1323 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 1324 | clk_enable(gpio_ick); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1325 | } |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1326 | #endif |
| 1327 | #if defined(CONFIG_ARCH_OMAP2) |
| 1328 | if (cpu_class_is_omap2()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1329 | gpio_ick = clk_get(NULL, "gpios_ick"); |
| 1330 | if (IS_ERR(gpio_ick)) |
| 1331 | printk("Could not get gpios_ick\n"); |
| 1332 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 1333 | clk_enable(gpio_ick); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1334 | gpio_fck = clk_get(NULL, "gpios_fck"); |
Komal Shah | 1630b52 | 2006-09-25 12:51:08 +0300 | [diff] [blame] | 1335 | if (IS_ERR(gpio_fck)) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1336 | printk("Could not get gpios_fck\n"); |
| 1337 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 1338 | clk_enable(gpio_fck); |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1339 | |
| 1340 | /* |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1341 | * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1342 | */ |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1343 | #if defined(CONFIG_ARCH_OMAP2430) |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1344 | if (cpu_is_omap2430()) { |
| 1345 | gpio5_ick = clk_get(NULL, "gpio5_ick"); |
| 1346 | if (IS_ERR(gpio5_ick)) |
| 1347 | printk("Could not get gpio5_ick\n"); |
| 1348 | else |
| 1349 | clk_enable(gpio5_ick); |
| 1350 | gpio5_fck = clk_get(NULL, "gpio5_fck"); |
| 1351 | if (IS_ERR(gpio5_fck)) |
| 1352 | printk("Could not get gpio5_fck\n"); |
| 1353 | else |
| 1354 | clk_enable(gpio5_fck); |
| 1355 | } |
| 1356 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1357 | } |
| 1358 | #endif |
| 1359 | |
| 1360 | #if defined(CONFIG_ARCH_OMAP3) |
| 1361 | if (cpu_is_omap34xx()) { |
| 1362 | for (i = 0; i < OMAP34XX_NR_GPIOS; i++) { |
| 1363 | sprintf(clk_name, "gpio%d_ick", i + 1); |
| 1364 | gpio_iclks[i] = clk_get(NULL, clk_name); |
| 1365 | if (IS_ERR(gpio_iclks[i])) |
| 1366 | printk(KERN_ERR "Could not get %s\n", clk_name); |
| 1367 | else |
| 1368 | clk_enable(gpio_iclks[i]); |
| 1369 | sprintf(clk_name, "gpio%d_fck", i + 1); |
| 1370 | gpio_fclks[i] = clk_get(NULL, clk_name); |
| 1371 | if (IS_ERR(gpio_fclks[i])) |
| 1372 | printk(KERN_ERR "Could not get %s\n", clk_name); |
| 1373 | else |
| 1374 | clk_enable(gpio_fclks[i]); |
| 1375 | } |
| 1376 | } |
| 1377 | #endif |
| 1378 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1379 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1380 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1381 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1382 | printk(KERN_INFO "OMAP1510 GPIO hardware\n"); |
| 1383 | gpio_bank_count = 2; |
| 1384 | gpio_bank = gpio_bank_1510; |
| 1385 | } |
| 1386 | #endif |
| 1387 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 1388 | if (cpu_is_omap16xx()) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1389 | u32 rev; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1390 | |
| 1391 | gpio_bank_count = 5; |
| 1392 | gpio_bank = gpio_bank_1610; |
| 1393 | rev = omap_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION); |
| 1394 | printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n", |
| 1395 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1396 | } |
| 1397 | #endif |
| 1398 | #ifdef CONFIG_ARCH_OMAP730 |
| 1399 | if (cpu_is_omap730()) { |
| 1400 | printk(KERN_INFO "OMAP730 GPIO hardware\n"); |
| 1401 | gpio_bank_count = 7; |
| 1402 | gpio_bank = gpio_bank_730; |
| 1403 | } |
| 1404 | #endif |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1405 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1406 | #ifdef CONFIG_ARCH_OMAP24XX |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1407 | if (cpu_is_omap242x()) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1408 | int rev; |
| 1409 | |
| 1410 | gpio_bank_count = 4; |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1411 | gpio_bank = gpio_bank_242x; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1412 | rev = omap_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1413 | printk(KERN_INFO "OMAP242x GPIO hardware version %d.%d\n", |
| 1414 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1415 | } |
| 1416 | if (cpu_is_omap243x()) { |
| 1417 | int rev; |
| 1418 | |
| 1419 | gpio_bank_count = 5; |
| 1420 | gpio_bank = gpio_bank_243x; |
| 1421 | rev = omap_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); |
| 1422 | printk(KERN_INFO "OMAP243x GPIO hardware version %d.%d\n", |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1423 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1424 | } |
| 1425 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1426 | #ifdef CONFIG_ARCH_OMAP34XX |
| 1427 | if (cpu_is_omap34xx()) { |
| 1428 | int rev; |
| 1429 | |
| 1430 | gpio_bank_count = OMAP34XX_NR_GPIOS; |
| 1431 | gpio_bank = gpio_bank_34xx; |
| 1432 | rev = omap_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); |
| 1433 | printk(KERN_INFO "OMAP34xx GPIO hardware version %d.%d\n", |
| 1434 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1435 | } |
| 1436 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1437 | for (i = 0; i < gpio_bank_count; i++) { |
| 1438 | int j, gpio_count = 16; |
| 1439 | |
| 1440 | bank = &gpio_bank[i]; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1441 | bank->base = IO_ADDRESS(bank->base); |
| 1442 | spin_lock_init(&bank->lock); |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1443 | if (bank_is_mpuio(bank)) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1444 | omap_writew(0xFFFF, OMAP_MPUIO_BASE + OMAP_MPUIO_GPIO_MASKIT); |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1445 | if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1446 | __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK); |
| 1447 | __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS); |
| 1448 | } |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1449 | if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1450 | __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1); |
| 1451 | __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1452 | __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1453 | } |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1454 | if (cpu_is_omap730() && bank->method == METHOD_GPIO_730) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1455 | __raw_writel(0xffffffff, bank->base + OMAP730_GPIO_INT_MASK); |
| 1456 | __raw_writel(0x00000000, bank->base + OMAP730_GPIO_INT_STATUS); |
| 1457 | |
| 1458 | gpio_count = 32; /* 730 has 32-bit GPIOs */ |
| 1459 | } |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1460 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1461 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1462 | if (bank->method == METHOD_GPIO_24XX) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1463 | static const u32 non_wakeup_gpios[] = { |
| 1464 | 0xe203ffc0, 0x08700040 |
| 1465 | }; |
| 1466 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1467 | __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1); |
| 1468 | __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1); |
Juha Yrjola | 14f1c3b | 2006-12-06 17:13:48 -0800 | [diff] [blame] | 1469 | __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG); |
| 1470 | |
| 1471 | /* Initialize interface clock ungated, module enabled */ |
| 1472 | __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1473 | if (i < ARRAY_SIZE(non_wakeup_gpios)) |
| 1474 | bank->non_wakeup_gpios = non_wakeup_gpios[i]; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1475 | gpio_count = 32; |
| 1476 | } |
| 1477 | #endif |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1478 | |
| 1479 | /* REVISIT eventually switch from OMAP-specific gpio structs |
| 1480 | * over to the generic ones |
| 1481 | */ |
| 1482 | bank->chip.direction_input = gpio_input; |
| 1483 | bank->chip.get = gpio_get; |
| 1484 | bank->chip.direction_output = gpio_output; |
| 1485 | bank->chip.set = gpio_set; |
| 1486 | if (bank_is_mpuio(bank)) { |
| 1487 | bank->chip.label = "mpuio"; |
Russell King | 69114a4 | 2008-09-03 10:15:26 +0100 | [diff] [blame] | 1488 | #ifdef CONFIG_ARCH_OMAP16XX |
David Brownell | d8f388d | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 1489 | bank->chip.dev = &omap_mpuio_device.dev; |
| 1490 | #endif |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1491 | bank->chip.base = OMAP_MPUIO(0); |
| 1492 | } else { |
| 1493 | bank->chip.label = "gpio"; |
| 1494 | bank->chip.base = gpio; |
| 1495 | gpio += gpio_count; |
| 1496 | } |
| 1497 | bank->chip.ngpio = gpio_count; |
| 1498 | |
| 1499 | gpiochip_add(&bank->chip); |
| 1500 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1501 | for (j = bank->virtual_irq_start; |
| 1502 | j < bank->virtual_irq_start + gpio_count; j++) { |
David Brownell | 8ba55c5 | 2008-02-26 11:10:50 -0800 | [diff] [blame] | 1503 | lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class); |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1504 | set_irq_chip_data(j, bank); |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1505 | if (bank_is_mpuio(bank)) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1506 | set_irq_chip(j, &mpuio_irq_chip); |
| 1507 | else |
| 1508 | set_irq_chip(j, &gpio_irq_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 1509 | set_irq_handler(j, handle_simple_irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1510 | set_irq_flags(j, IRQF_VALID); |
| 1511 | } |
| 1512 | set_irq_chained_handler(bank->irq, gpio_irq_handler); |
| 1513 | set_irq_data(bank->irq, bank); |
| 1514 | } |
| 1515 | |
| 1516 | /* Enable system clock for GPIO module. |
| 1517 | * The CAM_CLK_CTRL *is* really the right place. */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1518 | if (cpu_is_omap16xx()) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1519 | omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL); |
| 1520 | |
Juha Yrjola | 14f1c3b | 2006-12-06 17:13:48 -0800 | [diff] [blame] | 1521 | /* Enable autoidle for the OCP interface */ |
| 1522 | if (cpu_is_omap24xx()) |
| 1523 | omap_writel(1 << 0, 0x48019010); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1524 | if (cpu_is_omap34xx()) |
| 1525 | omap_writel(1 << 0, 0x48306814); |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1526 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1527 | return 0; |
| 1528 | } |
| 1529 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1530 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1531 | static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg) |
| 1532 | { |
| 1533 | int i; |
| 1534 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1535 | if (!cpu_class_is_omap2() && !cpu_is_omap16xx()) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1536 | return 0; |
| 1537 | |
| 1538 | for (i = 0; i < gpio_bank_count; i++) { |
| 1539 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1540 | void __iomem *wake_status; |
| 1541 | void __iomem *wake_clear; |
| 1542 | void __iomem *wake_set; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1543 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1544 | |
| 1545 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1546 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1547 | case METHOD_GPIO_1610: |
| 1548 | wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE; |
| 1549 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1550 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1551 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1552 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1553 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1554 | case METHOD_GPIO_24XX: |
| 1555 | wake_status = bank->base + OMAP24XX_GPIO_SETWKUENA; |
| 1556 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 1557 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
| 1558 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1559 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1560 | default: |
| 1561 | continue; |
| 1562 | } |
| 1563 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1564 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1565 | bank->saved_wakeup = __raw_readl(wake_status); |
| 1566 | __raw_writel(0xffffffff, wake_clear); |
| 1567 | __raw_writel(bank->suspend_wakeup, wake_set); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1568 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | return 0; |
| 1572 | } |
| 1573 | |
| 1574 | static int omap_gpio_resume(struct sys_device *dev) |
| 1575 | { |
| 1576 | int i; |
| 1577 | |
| 1578 | if (!cpu_is_omap24xx() && !cpu_is_omap16xx()) |
| 1579 | return 0; |
| 1580 | |
| 1581 | for (i = 0; i < gpio_bank_count; i++) { |
| 1582 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1583 | void __iomem *wake_clear; |
| 1584 | void __iomem *wake_set; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1585 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1586 | |
| 1587 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1588 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1589 | case METHOD_GPIO_1610: |
| 1590 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1591 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1592 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1593 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1594 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1595 | case METHOD_GPIO_24XX: |
Tony Lindgren | 0d9356c | 2006-09-25 12:41:45 +0300 | [diff] [blame] | 1596 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 1597 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1598 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1599 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1600 | default: |
| 1601 | continue; |
| 1602 | } |
| 1603 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1604 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1605 | __raw_writel(0xffffffff, wake_clear); |
| 1606 | __raw_writel(bank->saved_wakeup, wake_set); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1607 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
| 1613 | static struct sysdev_class omap_gpio_sysclass = { |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 1614 | .name = "gpio", |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1615 | .suspend = omap_gpio_suspend, |
| 1616 | .resume = omap_gpio_resume, |
| 1617 | }; |
| 1618 | |
| 1619 | static struct sys_device omap_gpio_device = { |
| 1620 | .id = 0, |
| 1621 | .cls = &omap_gpio_sysclass, |
| 1622 | }; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1623 | |
| 1624 | #endif |
| 1625 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1626 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1627 | |
| 1628 | static int workaround_enabled; |
| 1629 | |
| 1630 | void omap2_gpio_prepare_for_retention(void) |
| 1631 | { |
| 1632 | int i, c = 0; |
| 1633 | |
| 1634 | /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious |
| 1635 | * IRQs will be generated. See OMAP2420 Errata item 1.101. */ |
| 1636 | for (i = 0; i < gpio_bank_count; i++) { |
| 1637 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1638 | u32 l1, l2; |
| 1639 | |
| 1640 | if (!(bank->enabled_non_wakeup_gpios)) |
| 1641 | continue; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1642 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1643 | bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN); |
| 1644 | l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 1645 | l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1646 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1647 | bank->saved_fallingdetect = l1; |
| 1648 | bank->saved_risingdetect = l2; |
| 1649 | l1 &= ~bank->enabled_non_wakeup_gpios; |
| 1650 | l2 &= ~bank->enabled_non_wakeup_gpios; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1651 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1652 | __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 1653 | __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1654 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1655 | c++; |
| 1656 | } |
| 1657 | if (!c) { |
| 1658 | workaround_enabled = 0; |
| 1659 | return; |
| 1660 | } |
| 1661 | workaround_enabled = 1; |
| 1662 | } |
| 1663 | |
| 1664 | void omap2_gpio_resume_after_retention(void) |
| 1665 | { |
| 1666 | int i; |
| 1667 | |
| 1668 | if (!workaround_enabled) |
| 1669 | return; |
| 1670 | for (i = 0; i < gpio_bank_count; i++) { |
| 1671 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1672 | u32 l; |
| 1673 | |
| 1674 | if (!(bank->enabled_non_wakeup_gpios)) |
| 1675 | continue; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1676 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1677 | __raw_writel(bank->saved_fallingdetect, |
| 1678 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 1679 | __raw_writel(bank->saved_risingdetect, |
| 1680 | bank->base + OMAP24XX_GPIO_RISINGDETECT); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1681 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1682 | /* Check if any of the non-wakeup interrupt GPIOs have changed |
| 1683 | * state. If so, generate an IRQ by software. This is |
| 1684 | * horribly racy, but it's the best we can do to work around |
| 1685 | * this silicon bug. */ |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1686 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1687 | l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1688 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1689 | l ^= bank->saved_datain; |
| 1690 | l &= bank->non_wakeup_gpios; |
| 1691 | if (l) { |
| 1692 | u32 old0, old1; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1693 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1694 | old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 1695 | old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 1696 | __raw_writel(old0 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 1697 | __raw_writel(old1 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 1698 | __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 1699 | __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1700 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | } |
| 1705 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1706 | #endif |
| 1707 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1708 | /* |
| 1709 | * This may get called early from board specific init |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1710 | * for boards that have interrupts routed via FPGA. |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1711 | */ |
David Brownell | 277d58e | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1712 | int __init omap_gpio_init(void) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1713 | { |
| 1714 | if (!initialized) |
| 1715 | return _omap_gpio_init(); |
| 1716 | else |
| 1717 | return 0; |
| 1718 | } |
| 1719 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1720 | static int __init omap_gpio_sysinit(void) |
| 1721 | { |
| 1722 | int ret = 0; |
| 1723 | |
| 1724 | if (!initialized) |
| 1725 | ret = _omap_gpio_init(); |
| 1726 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1727 | mpuio_init(); |
| 1728 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1729 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) |
| 1730 | if (cpu_is_omap16xx() || cpu_class_is_omap2()) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1731 | if (ret == 0) { |
| 1732 | ret = sysdev_class_register(&omap_gpio_sysclass); |
| 1733 | if (ret == 0) |
| 1734 | ret = sysdev_register(&omap_gpio_device); |
| 1735 | } |
| 1736 | } |
| 1737 | #endif |
| 1738 | |
| 1739 | return ret; |
| 1740 | } |
| 1741 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1742 | EXPORT_SYMBOL(omap_request_gpio); |
| 1743 | EXPORT_SYMBOL(omap_free_gpio); |
| 1744 | EXPORT_SYMBOL(omap_set_gpio_direction); |
| 1745 | EXPORT_SYMBOL(omap_set_gpio_dataout); |
| 1746 | EXPORT_SYMBOL(omap_get_gpio_datain); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1747 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1748 | arch_initcall(omap_gpio_sysinit); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1749 | |
| 1750 | |
| 1751 | #ifdef CONFIG_DEBUG_FS |
| 1752 | |
| 1753 | #include <linux/debugfs.h> |
| 1754 | #include <linux/seq_file.h> |
| 1755 | |
| 1756 | static int gpio_is_input(struct gpio_bank *bank, int mask) |
| 1757 | { |
| 1758 | void __iomem *reg = bank->base; |
| 1759 | |
| 1760 | switch (bank->method) { |
| 1761 | case METHOD_MPUIO: |
| 1762 | reg += OMAP_MPUIO_IO_CNTL; |
| 1763 | break; |
| 1764 | case METHOD_GPIO_1510: |
| 1765 | reg += OMAP1510_GPIO_DIR_CONTROL; |
| 1766 | break; |
| 1767 | case METHOD_GPIO_1610: |
| 1768 | reg += OMAP1610_GPIO_DIRECTION; |
| 1769 | break; |
| 1770 | case METHOD_GPIO_730: |
| 1771 | reg += OMAP730_GPIO_DIR_CONTROL; |
| 1772 | break; |
| 1773 | case METHOD_GPIO_24XX: |
| 1774 | reg += OMAP24XX_GPIO_OE; |
| 1775 | break; |
| 1776 | } |
| 1777 | return __raw_readl(reg) & mask; |
| 1778 | } |
| 1779 | |
| 1780 | |
| 1781 | static int dbg_gpio_show(struct seq_file *s, void *unused) |
| 1782 | { |
| 1783 | unsigned i, j, gpio; |
| 1784 | |
| 1785 | for (i = 0, gpio = 0; i < gpio_bank_count; i++) { |
| 1786 | struct gpio_bank *bank = gpio_bank + i; |
| 1787 | unsigned bankwidth = 16; |
| 1788 | u32 mask = 1; |
| 1789 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1790 | if (bank_is_mpuio(bank)) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1791 | gpio = OMAP_MPUIO(0); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1792 | else if (cpu_class_is_omap2() || cpu_is_omap730()) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1793 | bankwidth = 32; |
| 1794 | |
| 1795 | for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) { |
| 1796 | unsigned irq, value, is_in, irqstat; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1797 | const char *label; |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1798 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1799 | label = gpiochip_is_requested(&bank->chip, j); |
| 1800 | if (!label) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1801 | continue; |
| 1802 | |
| 1803 | irq = bank->virtual_irq_start + j; |
| 1804 | value = omap_get_gpio_datain(gpio); |
| 1805 | is_in = gpio_is_input(bank, mask); |
| 1806 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1807 | if (bank_is_mpuio(bank)) |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1808 | seq_printf(s, "MPUIO %2d ", j); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1809 | else |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1810 | seq_printf(s, "GPIO %3d ", gpio); |
| 1811 | seq_printf(s, "(%10s): %s %s", |
| 1812 | label, |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1813 | is_in ? "in " : "out", |
| 1814 | value ? "hi" : "lo"); |
| 1815 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1816 | /* FIXME for at least omap2, show pullup/pulldown state */ |
| 1817 | |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1818 | irqstat = irq_desc[irq].status; |
| 1819 | if (is_in && ((bank->suspend_wakeup & mask) |
| 1820 | || irqstat & IRQ_TYPE_SENSE_MASK)) { |
| 1821 | char *trigger = NULL; |
| 1822 | |
| 1823 | switch (irqstat & IRQ_TYPE_SENSE_MASK) { |
| 1824 | case IRQ_TYPE_EDGE_FALLING: |
| 1825 | trigger = "falling"; |
| 1826 | break; |
| 1827 | case IRQ_TYPE_EDGE_RISING: |
| 1828 | trigger = "rising"; |
| 1829 | break; |
| 1830 | case IRQ_TYPE_EDGE_BOTH: |
| 1831 | trigger = "bothedge"; |
| 1832 | break; |
| 1833 | case IRQ_TYPE_LEVEL_LOW: |
| 1834 | trigger = "low"; |
| 1835 | break; |
| 1836 | case IRQ_TYPE_LEVEL_HIGH: |
| 1837 | trigger = "high"; |
| 1838 | break; |
| 1839 | case IRQ_TYPE_NONE: |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1840 | trigger = "(?)"; |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1841 | break; |
| 1842 | } |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1843 | seq_printf(s, ", irq-%d %-8s%s", |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1844 | irq, trigger, |
| 1845 | (bank->suspend_wakeup & mask) |
| 1846 | ? " wakeup" : ""); |
| 1847 | } |
| 1848 | seq_printf(s, "\n"); |
| 1849 | } |
| 1850 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1851 | if (bank_is_mpuio(bank)) { |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1852 | seq_printf(s, "\n"); |
| 1853 | gpio = 0; |
| 1854 | } |
| 1855 | } |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
| 1859 | static int dbg_gpio_open(struct inode *inode, struct file *file) |
| 1860 | { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1861 | return single_open(file, dbg_gpio_show, &inode->i_private); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | static const struct file_operations debug_fops = { |
| 1865 | .open = dbg_gpio_open, |
| 1866 | .read = seq_read, |
| 1867 | .llseek = seq_lseek, |
| 1868 | .release = single_release, |
| 1869 | }; |
| 1870 | |
| 1871 | static int __init omap_gpio_debuginit(void) |
| 1872 | { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1873 | (void) debugfs_create_file("omap_gpio", S_IRUGO, |
| 1874 | NULL, NULL, &debug_fops); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1875 | return 0; |
| 1876 | } |
| 1877 | late_initcall(omap_gpio_debuginit); |
| 1878 | #endif |