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