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