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 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 9 | * Copyright (C) 2009 Texas Instruments |
| 10 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
| 11 | * |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
| 15 | */ |
| 16 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 17 | #include <linux/init.h> |
| 18 | #include <linux/module.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 19 | #include <linux/interrupt.h> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 20 | #include <linux/sysdev.h> |
| 21 | #include <linux/err.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 22 | #include <linux/clk.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 23 | #include <linux/io.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 24 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 25 | #include <mach/hardware.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 26 | #include <asm/irq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/irqs.h> |
| 28 | #include <mach/gpio.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 29 | #include <asm/mach/irq.h> |
| 30 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 31 | /* |
| 32 | * OMAP1510 GPIO registers |
| 33 | */ |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 34 | #define OMAP1510_GPIO_BASE 0xfffce000 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 35 | #define OMAP1510_GPIO_DATA_INPUT 0x00 |
| 36 | #define OMAP1510_GPIO_DATA_OUTPUT 0x04 |
| 37 | #define OMAP1510_GPIO_DIR_CONTROL 0x08 |
| 38 | #define OMAP1510_GPIO_INT_CONTROL 0x0c |
| 39 | #define OMAP1510_GPIO_INT_MASK 0x10 |
| 40 | #define OMAP1510_GPIO_INT_STATUS 0x14 |
| 41 | #define OMAP1510_GPIO_PIN_CONTROL 0x18 |
| 42 | |
| 43 | #define OMAP1510_IH_GPIO_BASE 64 |
| 44 | |
| 45 | /* |
| 46 | * OMAP1610 specific GPIO registers |
| 47 | */ |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 48 | #define OMAP1610_GPIO1_BASE 0xfffbe400 |
| 49 | #define OMAP1610_GPIO2_BASE 0xfffbec00 |
| 50 | #define OMAP1610_GPIO3_BASE 0xfffbb400 |
| 51 | #define OMAP1610_GPIO4_BASE 0xfffbbc00 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 52 | #define OMAP1610_GPIO_REVISION 0x0000 |
| 53 | #define OMAP1610_GPIO_SYSCONFIG 0x0010 |
| 54 | #define OMAP1610_GPIO_SYSSTATUS 0x0014 |
| 55 | #define OMAP1610_GPIO_IRQSTATUS1 0x0018 |
| 56 | #define OMAP1610_GPIO_IRQENABLE1 0x001c |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 57 | #define OMAP1610_GPIO_WAKEUPENABLE 0x0028 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 58 | #define OMAP1610_GPIO_DATAIN 0x002c |
| 59 | #define OMAP1610_GPIO_DATAOUT 0x0030 |
| 60 | #define OMAP1610_GPIO_DIRECTION 0x0034 |
| 61 | #define OMAP1610_GPIO_EDGE_CTRL1 0x0038 |
| 62 | #define OMAP1610_GPIO_EDGE_CTRL2 0x003c |
| 63 | #define OMAP1610_GPIO_CLEAR_IRQENABLE1 0x009c |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 64 | #define OMAP1610_GPIO_CLEAR_WAKEUPENA 0x00a8 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 65 | #define OMAP1610_GPIO_CLEAR_DATAOUT 0x00b0 |
| 66 | #define OMAP1610_GPIO_SET_IRQENABLE1 0x00dc |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 67 | #define OMAP1610_GPIO_SET_WAKEUPENA 0x00e8 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 68 | #define OMAP1610_GPIO_SET_DATAOUT 0x00f0 |
| 69 | |
| 70 | /* |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 71 | * OMAP7XX specific GPIO registers |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 72 | */ |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 73 | #define OMAP7XX_GPIO1_BASE 0xfffbc000 |
| 74 | #define OMAP7XX_GPIO2_BASE 0xfffbc800 |
| 75 | #define OMAP7XX_GPIO3_BASE 0xfffbd000 |
| 76 | #define OMAP7XX_GPIO4_BASE 0xfffbd800 |
| 77 | #define OMAP7XX_GPIO5_BASE 0xfffbe000 |
| 78 | #define OMAP7XX_GPIO6_BASE 0xfffbe800 |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 79 | #define OMAP7XX_GPIO_DATA_INPUT 0x00 |
| 80 | #define OMAP7XX_GPIO_DATA_OUTPUT 0x04 |
| 81 | #define OMAP7XX_GPIO_DIR_CONTROL 0x08 |
| 82 | #define OMAP7XX_GPIO_INT_CONTROL 0x0c |
| 83 | #define OMAP7XX_GPIO_INT_MASK 0x10 |
| 84 | #define OMAP7XX_GPIO_INT_STATUS 0x14 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 85 | |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 86 | #define OMAP1_MPUIO_VBASE OMAP1_MPUIO_BASE |
Tony Lindgren | 9411326 | 2009-08-28 10:50:33 -0700 | [diff] [blame] | 87 | |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 88 | /* |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 89 | * omap24xx specific GPIO registers |
| 90 | */ |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 91 | #define OMAP242X_GPIO1_BASE 0x48018000 |
| 92 | #define OMAP242X_GPIO2_BASE 0x4801a000 |
| 93 | #define OMAP242X_GPIO3_BASE 0x4801c000 |
| 94 | #define OMAP242X_GPIO4_BASE 0x4801e000 |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 95 | |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 96 | #define OMAP243X_GPIO1_BASE 0x4900C000 |
| 97 | #define OMAP243X_GPIO2_BASE 0x4900E000 |
| 98 | #define OMAP243X_GPIO3_BASE 0x49010000 |
| 99 | #define OMAP243X_GPIO4_BASE 0x49012000 |
| 100 | #define OMAP243X_GPIO5_BASE 0x480B6000 |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 101 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 102 | #define OMAP24XX_GPIO_REVISION 0x0000 |
| 103 | #define OMAP24XX_GPIO_SYSCONFIG 0x0010 |
| 104 | #define OMAP24XX_GPIO_SYSSTATUS 0x0014 |
| 105 | #define OMAP24XX_GPIO_IRQSTATUS1 0x0018 |
Hiroshi DOYU | bee7930 | 2006-09-25 12:41:46 +0300 | [diff] [blame] | 106 | #define OMAP24XX_GPIO_IRQSTATUS2 0x0028 |
| 107 | #define OMAP24XX_GPIO_IRQENABLE2 0x002c |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 108 | #define OMAP24XX_GPIO_IRQENABLE1 0x001c |
Tero Kristo | 723fdb7 | 2008-11-26 14:35:16 -0800 | [diff] [blame] | 109 | #define OMAP24XX_GPIO_WAKE_EN 0x0020 |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 110 | #define OMAP24XX_GPIO_CTRL 0x0030 |
| 111 | #define OMAP24XX_GPIO_OE 0x0034 |
| 112 | #define OMAP24XX_GPIO_DATAIN 0x0038 |
| 113 | #define OMAP24XX_GPIO_DATAOUT 0x003c |
| 114 | #define OMAP24XX_GPIO_LEVELDETECT0 0x0040 |
| 115 | #define OMAP24XX_GPIO_LEVELDETECT1 0x0044 |
| 116 | #define OMAP24XX_GPIO_RISINGDETECT 0x0048 |
| 117 | #define OMAP24XX_GPIO_FALLINGDETECT 0x004c |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 118 | #define OMAP24XX_GPIO_DEBOUNCE_EN 0x0050 |
| 119 | #define OMAP24XX_GPIO_DEBOUNCE_VAL 0x0054 |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 120 | #define OMAP24XX_GPIO_CLEARIRQENABLE1 0x0060 |
| 121 | #define OMAP24XX_GPIO_SETIRQENABLE1 0x0064 |
| 122 | #define OMAP24XX_GPIO_CLEARWKUENA 0x0080 |
| 123 | #define OMAP24XX_GPIO_SETWKUENA 0x0084 |
| 124 | #define OMAP24XX_GPIO_CLEARDATAOUT 0x0090 |
| 125 | #define OMAP24XX_GPIO_SETDATAOUT 0x0094 |
| 126 | |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 127 | #define OMAP4_GPIO_REVISION 0x0000 |
| 128 | #define OMAP4_GPIO_SYSCONFIG 0x0010 |
| 129 | #define OMAP4_GPIO_EOI 0x0020 |
| 130 | #define OMAP4_GPIO_IRQSTATUSRAW0 0x0024 |
| 131 | #define OMAP4_GPIO_IRQSTATUSRAW1 0x0028 |
| 132 | #define OMAP4_GPIO_IRQSTATUS0 0x002c |
| 133 | #define OMAP4_GPIO_IRQSTATUS1 0x0030 |
| 134 | #define OMAP4_GPIO_IRQSTATUSSET0 0x0034 |
| 135 | #define OMAP4_GPIO_IRQSTATUSSET1 0x0038 |
| 136 | #define OMAP4_GPIO_IRQSTATUSCLR0 0x003c |
| 137 | #define OMAP4_GPIO_IRQSTATUSCLR1 0x0040 |
| 138 | #define OMAP4_GPIO_IRQWAKEN0 0x0044 |
| 139 | #define OMAP4_GPIO_IRQWAKEN1 0x0048 |
| 140 | #define OMAP4_GPIO_SYSSTATUS 0x0104 |
| 141 | #define OMAP4_GPIO_CTRL 0x0130 |
| 142 | #define OMAP4_GPIO_OE 0x0134 |
| 143 | #define OMAP4_GPIO_DATAIN 0x0138 |
| 144 | #define OMAP4_GPIO_DATAOUT 0x013c |
| 145 | #define OMAP4_GPIO_LEVELDETECT0 0x0140 |
| 146 | #define OMAP4_GPIO_LEVELDETECT1 0x0144 |
| 147 | #define OMAP4_GPIO_RISINGDETECT 0x0148 |
| 148 | #define OMAP4_GPIO_FALLINGDETECT 0x014c |
| 149 | #define OMAP4_GPIO_DEBOUNCENABLE 0x0150 |
| 150 | #define OMAP4_GPIO_DEBOUNCINGTIME 0x0154 |
| 151 | #define OMAP4_GPIO_CLEARDATAOUT 0x0190 |
| 152 | #define OMAP4_GPIO_SETDATAOUT 0x0194 |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 153 | /* |
| 154 | * omap34xx specific GPIO registers |
| 155 | */ |
| 156 | |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 157 | #define OMAP34XX_GPIO1_BASE 0x48310000 |
| 158 | #define OMAP34XX_GPIO2_BASE 0x49050000 |
| 159 | #define OMAP34XX_GPIO3_BASE 0x49052000 |
| 160 | #define OMAP34XX_GPIO4_BASE 0x49054000 |
| 161 | #define OMAP34XX_GPIO5_BASE 0x49056000 |
| 162 | #define OMAP34XX_GPIO6_BASE 0x49058000 |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 163 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 164 | /* |
| 165 | * OMAP44XX specific GPIO registers |
| 166 | */ |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 167 | #define OMAP44XX_GPIO1_BASE 0x4a310000 |
| 168 | #define OMAP44XX_GPIO2_BASE 0x48055000 |
| 169 | #define OMAP44XX_GPIO3_BASE 0x48057000 |
| 170 | #define OMAP44XX_GPIO4_BASE 0x48059000 |
| 171 | #define OMAP44XX_GPIO5_BASE 0x4805B000 |
| 172 | #define OMAP44XX_GPIO6_BASE 0x4805D000 |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 173 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 174 | struct gpio_bank { |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 175 | unsigned long pbase; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 176 | void __iomem *base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 177 | u16 irq; |
| 178 | u16 virtual_irq_start; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 179 | int method; |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 180 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 181 | u32 suspend_wakeup; |
| 182 | u32 saved_wakeup; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 183 | #endif |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 184 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 185 | u32 non_wakeup_gpios; |
| 186 | u32 enabled_non_wakeup_gpios; |
| 187 | |
| 188 | u32 saved_datain; |
| 189 | u32 saved_fallingdetect; |
| 190 | u32 saved_risingdetect; |
| 191 | #endif |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 192 | u32 level_mask; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 193 | u32 toggle_mask; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 194 | spinlock_t lock; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 195 | struct gpio_chip chip; |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 196 | struct clk *dbck; |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 197 | u32 mod_usage; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | #define METHOD_MPUIO 0 |
| 201 | #define METHOD_GPIO_1510 1 |
| 202 | #define METHOD_GPIO_1610 2 |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 203 | #define METHOD_GPIO_7XX 3 |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 204 | #define METHOD_GPIO_24XX 5 |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 205 | #define METHOD_GPIO_44XX 6 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 206 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 207 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 208 | static struct gpio_bank gpio_bank_1610[5] = { |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 209 | { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE, |
| 210 | METHOD_MPUIO }, |
| 211 | { OMAP1610_GPIO1_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE, |
| 212 | METHOD_GPIO_1610 }, |
| 213 | { OMAP1610_GPIO2_BASE, NULL, INT_1610_GPIO_BANK2, IH_GPIO_BASE + 16, |
| 214 | METHOD_GPIO_1610 }, |
| 215 | { OMAP1610_GPIO3_BASE, NULL, INT_1610_GPIO_BANK3, IH_GPIO_BASE + 32, |
| 216 | METHOD_GPIO_1610 }, |
| 217 | { OMAP1610_GPIO4_BASE, NULL, INT_1610_GPIO_BANK4, IH_GPIO_BASE + 48, |
| 218 | METHOD_GPIO_1610 }, |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 219 | }; |
| 220 | #endif |
| 221 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 222 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 223 | static struct gpio_bank gpio_bank_1510[2] = { |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 224 | { OMAP1_MPUIO_VBASE, NULL, INT_MPUIO, IH_MPUIO_BASE, |
| 225 | METHOD_MPUIO }, |
| 226 | { OMAP1510_GPIO_BASE, NULL, INT_GPIO_BANK1, IH_GPIO_BASE, |
| 227 | METHOD_GPIO_1510 } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 228 | }; |
| 229 | #endif |
| 230 | |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 231 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 232 | static struct gpio_bank gpio_bank_7xx[7] = { |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 233 | { OMAP1_MPUIO_VBASE, NULL, INT_7XX_MPUIO, IH_MPUIO_BASE, |
| 234 | METHOD_MPUIO }, |
| 235 | { OMAP7XX_GPIO1_BASE, NULL, INT_7XX_GPIO_BANK1, IH_GPIO_BASE, |
| 236 | METHOD_GPIO_7XX }, |
| 237 | { OMAP7XX_GPIO2_BASE, NULL, INT_7XX_GPIO_BANK2, IH_GPIO_BASE + 32, |
| 238 | METHOD_GPIO_7XX }, |
| 239 | { OMAP7XX_GPIO3_BASE, NULL, INT_7XX_GPIO_BANK3, IH_GPIO_BASE + 64, |
| 240 | METHOD_GPIO_7XX }, |
| 241 | { OMAP7XX_GPIO4_BASE, NULL, INT_7XX_GPIO_BANK4, IH_GPIO_BASE + 96, |
| 242 | METHOD_GPIO_7XX }, |
| 243 | { OMAP7XX_GPIO5_BASE, NULL, INT_7XX_GPIO_BANK5, IH_GPIO_BASE + 128, |
| 244 | METHOD_GPIO_7XX }, |
| 245 | { OMAP7XX_GPIO6_BASE, NULL, INT_7XX_GPIO_BANK6, IH_GPIO_BASE + 160, |
| 246 | METHOD_GPIO_7XX }, |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 247 | }; |
| 248 | #endif |
| 249 | |
Tony Lindgren | 088ef95 | 2010-02-12 12:26:47 -0800 | [diff] [blame] | 250 | #ifdef CONFIG_ARCH_OMAP2 |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 251 | |
| 252 | static struct gpio_bank gpio_bank_242x[4] = { |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 253 | { OMAP242X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, |
| 254 | METHOD_GPIO_24XX }, |
| 255 | { OMAP242X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, |
| 256 | METHOD_GPIO_24XX }, |
| 257 | { OMAP242X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, |
| 258 | METHOD_GPIO_24XX }, |
| 259 | { OMAP242X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, |
| 260 | METHOD_GPIO_24XX }, |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 261 | }; |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 262 | |
| 263 | static struct gpio_bank gpio_bank_243x[5] = { |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 264 | { OMAP243X_GPIO1_BASE, NULL, INT_24XX_GPIO_BANK1, IH_GPIO_BASE, |
| 265 | METHOD_GPIO_24XX }, |
| 266 | { OMAP243X_GPIO2_BASE, NULL, INT_24XX_GPIO_BANK2, IH_GPIO_BASE + 32, |
| 267 | METHOD_GPIO_24XX }, |
| 268 | { OMAP243X_GPIO3_BASE, NULL, INT_24XX_GPIO_BANK3, IH_GPIO_BASE + 64, |
| 269 | METHOD_GPIO_24XX }, |
| 270 | { OMAP243X_GPIO4_BASE, NULL, INT_24XX_GPIO_BANK4, IH_GPIO_BASE + 96, |
| 271 | METHOD_GPIO_24XX }, |
| 272 | { OMAP243X_GPIO5_BASE, NULL, INT_24XX_GPIO_BANK5, IH_GPIO_BASE + 128, |
| 273 | METHOD_GPIO_24XX }, |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 274 | }; |
| 275 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 276 | #endif |
| 277 | |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 278 | #ifdef CONFIG_ARCH_OMAP3 |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 279 | static struct gpio_bank gpio_bank_34xx[6] = { |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 280 | { OMAP34XX_GPIO1_BASE, NULL, INT_34XX_GPIO_BANK1, IH_GPIO_BASE, |
| 281 | METHOD_GPIO_24XX }, |
| 282 | { OMAP34XX_GPIO2_BASE, NULL, INT_34XX_GPIO_BANK2, IH_GPIO_BASE + 32, |
| 283 | METHOD_GPIO_24XX }, |
| 284 | { OMAP34XX_GPIO3_BASE, NULL, INT_34XX_GPIO_BANK3, IH_GPIO_BASE + 64, |
| 285 | METHOD_GPIO_24XX }, |
| 286 | { OMAP34XX_GPIO4_BASE, NULL, INT_34XX_GPIO_BANK4, IH_GPIO_BASE + 96, |
| 287 | METHOD_GPIO_24XX }, |
| 288 | { OMAP34XX_GPIO5_BASE, NULL, INT_34XX_GPIO_BANK5, IH_GPIO_BASE + 128, |
| 289 | METHOD_GPIO_24XX }, |
| 290 | { OMAP34XX_GPIO6_BASE, NULL, INT_34XX_GPIO_BANK6, IH_GPIO_BASE + 160, |
| 291 | METHOD_GPIO_24XX }, |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 292 | }; |
| 293 | |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 294 | struct omap3_gpio_regs { |
| 295 | u32 sysconfig; |
| 296 | u32 irqenable1; |
| 297 | u32 irqenable2; |
| 298 | u32 wake_en; |
| 299 | u32 ctrl; |
| 300 | u32 oe; |
| 301 | u32 leveldetect0; |
| 302 | u32 leveldetect1; |
| 303 | u32 risingdetect; |
| 304 | u32 fallingdetect; |
| 305 | u32 dataout; |
| 306 | u32 setwkuena; |
| 307 | u32 setdataout; |
| 308 | }; |
| 309 | |
| 310 | static struct omap3_gpio_regs gpio_context[OMAP34XX_NR_GPIOS]; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 311 | #endif |
| 312 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 313 | #ifdef CONFIG_ARCH_OMAP4 |
| 314 | static struct gpio_bank gpio_bank_44xx[6] = { |
Santosh Shilimkar | 5772ca7 | 2010-02-18 03:14:12 +0530 | [diff] [blame] | 315 | { OMAP44XX_GPIO1_BASE, NULL, OMAP44XX_IRQ_GPIO1, IH_GPIO_BASE, |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 316 | METHOD_GPIO_44XX }, |
Santosh Shilimkar | 5772ca7 | 2010-02-18 03:14:12 +0530 | [diff] [blame] | 317 | { OMAP44XX_GPIO2_BASE, NULL, OMAP44XX_IRQ_GPIO2, IH_GPIO_BASE + 32, |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 318 | METHOD_GPIO_44XX }, |
Santosh Shilimkar | 5772ca7 | 2010-02-18 03:14:12 +0530 | [diff] [blame] | 319 | { OMAP44XX_GPIO3_BASE, NULL, OMAP44XX_IRQ_GPIO3, IH_GPIO_BASE + 64, |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 320 | METHOD_GPIO_44XX }, |
Santosh Shilimkar | 5772ca7 | 2010-02-18 03:14:12 +0530 | [diff] [blame] | 321 | { OMAP44XX_GPIO4_BASE, NULL, OMAP44XX_IRQ_GPIO4, IH_GPIO_BASE + 96, |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 322 | METHOD_GPIO_44XX }, |
Santosh Shilimkar | 5772ca7 | 2010-02-18 03:14:12 +0530 | [diff] [blame] | 323 | { OMAP44XX_GPIO5_BASE, NULL, OMAP44XX_IRQ_GPIO5, IH_GPIO_BASE + 128, |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 324 | METHOD_GPIO_44XX }, |
Santosh Shilimkar | 5772ca7 | 2010-02-18 03:14:12 +0530 | [diff] [blame] | 325 | { OMAP44XX_GPIO6_BASE, NULL, OMAP44XX_IRQ_GPIO6, IH_GPIO_BASE + 160, |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 326 | METHOD_GPIO_44XX }, |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | #endif |
| 330 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 331 | static struct gpio_bank *gpio_bank; |
| 332 | static int gpio_bank_count; |
| 333 | |
| 334 | static inline struct gpio_bank *get_gpio_bank(int gpio) |
| 335 | { |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 336 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 337 | if (OMAP_GPIO_IS_MPUIO(gpio)) |
| 338 | return &gpio_bank[0]; |
| 339 | return &gpio_bank[1]; |
| 340 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 341 | if (cpu_is_omap16xx()) { |
| 342 | if (OMAP_GPIO_IS_MPUIO(gpio)) |
| 343 | return &gpio_bank[0]; |
| 344 | return &gpio_bank[1 + (gpio >> 4)]; |
| 345 | } |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 346 | if (cpu_is_omap7xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 347 | if (OMAP_GPIO_IS_MPUIO(gpio)) |
| 348 | return &gpio_bank[0]; |
| 349 | return &gpio_bank[1 + (gpio >> 5)]; |
| 350 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 351 | if (cpu_is_omap24xx()) |
| 352 | return &gpio_bank[gpio >> 5]; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 353 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 354 | return &gpio_bank[gpio >> 5]; |
David Brownell | e031ab2 | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 355 | BUG(); |
| 356 | return NULL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static inline int get_gpio_index(int gpio) |
| 360 | { |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 361 | if (cpu_is_omap7xx()) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 362 | return gpio & 0x1f; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 363 | if (cpu_is_omap24xx()) |
| 364 | return gpio & 0x1f; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 365 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 366 | return gpio & 0x1f; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 367 | return gpio & 0x0f; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | static inline int gpio_valid(int gpio) |
| 371 | { |
| 372 | if (gpio < 0) |
| 373 | return -1; |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 374 | if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) { |
Jonathan McDowell | 193e68b | 2006-09-25 12:41:30 +0300 | [diff] [blame] | 375 | if (gpio >= OMAP_MAX_GPIO_LINES + 16) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 376 | return -1; |
| 377 | return 0; |
| 378 | } |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 379 | if (cpu_is_omap15xx() && gpio < 16) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 380 | return 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 381 | if ((cpu_is_omap16xx()) && gpio < 64) |
| 382 | return 0; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 383 | if (cpu_is_omap7xx() && gpio < 192) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 384 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 385 | if (cpu_is_omap24xx() && gpio < 128) |
| 386 | return 0; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 387 | if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192) |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 388 | return 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 389 | return -1; |
| 390 | } |
| 391 | |
| 392 | static int check_gpio(int gpio) |
| 393 | { |
Roel Kluin | d32b20f | 2009-11-17 14:39:03 -0800 | [diff] [blame] | 394 | if (unlikely(gpio_valid(gpio) < 0)) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 395 | printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio); |
| 396 | dump_stack(); |
| 397 | return -1; |
| 398 | } |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) |
| 403 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 404 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 405 | u32 l; |
| 406 | |
| 407 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 408 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 409 | case METHOD_MPUIO: |
| 410 | reg += OMAP_MPUIO_IO_CNTL; |
| 411 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 412 | #endif |
| 413 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 414 | case METHOD_GPIO_1510: |
| 415 | reg += OMAP1510_GPIO_DIR_CONTROL; |
| 416 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 417 | #endif |
| 418 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 419 | case METHOD_GPIO_1610: |
| 420 | reg += OMAP1610_GPIO_DIRECTION; |
| 421 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 422 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 423 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 424 | case METHOD_GPIO_7XX: |
| 425 | reg += OMAP7XX_GPIO_DIR_CONTROL; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 426 | break; |
| 427 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 428 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 429 | case METHOD_GPIO_24XX: |
| 430 | reg += OMAP24XX_GPIO_OE; |
| 431 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 432 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 433 | #if defined(CONFIG_ARCH_OMAP4) |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 434 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 435 | reg += OMAP4_GPIO_OE; |
| 436 | break; |
| 437 | #endif |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 438 | default: |
| 439 | WARN_ON(1); |
| 440 | return; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 441 | } |
| 442 | l = __raw_readl(reg); |
| 443 | if (is_input) |
| 444 | l |= 1 << gpio; |
| 445 | else |
| 446 | l &= ~(1 << gpio); |
| 447 | __raw_writel(l, reg); |
| 448 | } |
| 449 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 450 | static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable) |
| 451 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 452 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 453 | u32 l = 0; |
| 454 | |
| 455 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 456 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 457 | case METHOD_MPUIO: |
| 458 | reg += OMAP_MPUIO_OUTPUT; |
| 459 | l = __raw_readl(reg); |
| 460 | if (enable) |
| 461 | l |= 1 << gpio; |
| 462 | else |
| 463 | l &= ~(1 << gpio); |
| 464 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 465 | #endif |
| 466 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 467 | case METHOD_GPIO_1510: |
| 468 | reg += OMAP1510_GPIO_DATA_OUTPUT; |
| 469 | l = __raw_readl(reg); |
| 470 | if (enable) |
| 471 | l |= 1 << gpio; |
| 472 | else |
| 473 | l &= ~(1 << gpio); |
| 474 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 475 | #endif |
| 476 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 477 | case METHOD_GPIO_1610: |
| 478 | if (enable) |
| 479 | reg += OMAP1610_GPIO_SET_DATAOUT; |
| 480 | else |
| 481 | reg += OMAP1610_GPIO_CLEAR_DATAOUT; |
| 482 | l = 1 << gpio; |
| 483 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 484 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 485 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 486 | case METHOD_GPIO_7XX: |
| 487 | reg += OMAP7XX_GPIO_DATA_OUTPUT; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 488 | l = __raw_readl(reg); |
| 489 | if (enable) |
| 490 | l |= 1 << gpio; |
| 491 | else |
| 492 | l &= ~(1 << gpio); |
| 493 | break; |
| 494 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 495 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 496 | case METHOD_GPIO_24XX: |
| 497 | if (enable) |
| 498 | reg += OMAP24XX_GPIO_SETDATAOUT; |
| 499 | else |
| 500 | reg += OMAP24XX_GPIO_CLEARDATAOUT; |
| 501 | l = 1 << gpio; |
| 502 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 503 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 504 | #ifdef CONFIG_ARCH_OMAP4 |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 505 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 506 | if (enable) |
| 507 | reg += OMAP4_GPIO_SETDATAOUT; |
| 508 | else |
| 509 | reg += OMAP4_GPIO_CLEARDATAOUT; |
| 510 | l = 1 << gpio; |
| 511 | break; |
| 512 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 513 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 514 | WARN_ON(1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 515 | return; |
| 516 | } |
| 517 | __raw_writel(l, reg); |
| 518 | } |
| 519 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 520 | static int _get_gpio_datain(struct gpio_bank *bank, int gpio) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 521 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 522 | void __iomem *reg; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 523 | |
| 524 | if (check_gpio(gpio) < 0) |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 525 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 526 | reg = bank->base; |
| 527 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 528 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 529 | case METHOD_MPUIO: |
| 530 | reg += OMAP_MPUIO_INPUT_LATCH; |
| 531 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 532 | #endif |
| 533 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 534 | case METHOD_GPIO_1510: |
| 535 | reg += OMAP1510_GPIO_DATA_INPUT; |
| 536 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 537 | #endif |
| 538 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 539 | case METHOD_GPIO_1610: |
| 540 | reg += OMAP1610_GPIO_DATAIN; |
| 541 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 542 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 543 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 544 | case METHOD_GPIO_7XX: |
| 545 | reg += OMAP7XX_GPIO_DATA_INPUT; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 546 | break; |
| 547 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 548 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 549 | case METHOD_GPIO_24XX: |
| 550 | reg += OMAP24XX_GPIO_DATAIN; |
| 551 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 552 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 553 | #ifdef CONFIG_ARCH_OMAP4 |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 554 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 555 | reg += OMAP4_GPIO_DATAIN; |
| 556 | break; |
| 557 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 558 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 559 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 560 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 561 | return (__raw_readl(reg) |
| 562 | & (1 << get_gpio_index(gpio))) != 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 563 | } |
| 564 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 565 | static int _get_gpio_dataout(struct gpio_bank *bank, int gpio) |
| 566 | { |
| 567 | void __iomem *reg; |
| 568 | |
| 569 | if (check_gpio(gpio) < 0) |
| 570 | return -EINVAL; |
| 571 | reg = bank->base; |
| 572 | |
| 573 | switch (bank->method) { |
| 574 | #ifdef CONFIG_ARCH_OMAP1 |
| 575 | case METHOD_MPUIO: |
| 576 | reg += OMAP_MPUIO_OUTPUT; |
| 577 | break; |
| 578 | #endif |
| 579 | #ifdef CONFIG_ARCH_OMAP15XX |
| 580 | case METHOD_GPIO_1510: |
| 581 | reg += OMAP1510_GPIO_DATA_OUTPUT; |
| 582 | break; |
| 583 | #endif |
| 584 | #ifdef CONFIG_ARCH_OMAP16XX |
| 585 | case METHOD_GPIO_1610: |
| 586 | reg += OMAP1610_GPIO_DATAOUT; |
| 587 | break; |
| 588 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 589 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 590 | case METHOD_GPIO_7XX: |
| 591 | reg += OMAP7XX_GPIO_DATA_OUTPUT; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 592 | break; |
| 593 | #endif |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 594 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 595 | case METHOD_GPIO_24XX: |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 596 | case METHOD_GPIO_44XX: |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 597 | reg += OMAP24XX_GPIO_DATAOUT; |
| 598 | break; |
| 599 | #endif |
| 600 | default: |
| 601 | return -EINVAL; |
| 602 | } |
| 603 | |
| 604 | return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0; |
| 605 | } |
| 606 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 607 | #define MOD_REG_BIT(reg, bit_mask, set) \ |
| 608 | do { \ |
| 609 | int l = __raw_readl(base + reg); \ |
| 610 | if (set) l |= bit_mask; \ |
| 611 | else l &= ~bit_mask; \ |
| 612 | __raw_writel(l, base + reg); \ |
| 613 | } while(0) |
| 614 | |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 615 | void omap_set_gpio_debounce(int gpio, int enable) |
| 616 | { |
| 617 | struct gpio_bank *bank; |
| 618 | void __iomem *reg; |
David Brownell | e031ab2 | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 619 | unsigned long flags; |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 620 | u32 val, l = 1 << get_gpio_index(gpio); |
| 621 | |
| 622 | if (cpu_class_is_omap1()) |
| 623 | return; |
| 624 | |
| 625 | bank = get_gpio_bank(gpio); |
| 626 | reg = bank->base; |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 627 | |
| 628 | if (cpu_is_omap44xx()) |
| 629 | reg += OMAP4_GPIO_DEBOUNCENABLE; |
| 630 | else |
| 631 | reg += OMAP24XX_GPIO_DEBOUNCE_EN; |
| 632 | |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 633 | if (!(bank->mod_usage & l)) { |
| 634 | printk(KERN_ERR "GPIO %d not requested\n", gpio); |
| 635 | return; |
| 636 | } |
David Brownell | e031ab2 | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 637 | |
| 638 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 639 | val = __raw_readl(reg); |
| 640 | |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 641 | if (enable && !(val & l)) |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 642 | val |= l; |
David Brownell | e031ab2 | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 643 | else if (!enable && (val & l)) |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 644 | val &= ~l; |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 645 | else |
David Brownell | e031ab2 | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 646 | goto done; |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 647 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 648 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
David Brownell | e031ab2 | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 649 | if (enable) |
| 650 | clk_enable(bank->dbck); |
| 651 | else |
| 652 | clk_disable(bank->dbck); |
| 653 | } |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 654 | |
| 655 | __raw_writel(val, reg); |
David Brownell | e031ab2 | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 656 | done: |
| 657 | spin_unlock_irqrestore(&bank->lock, flags); |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 658 | } |
| 659 | EXPORT_SYMBOL(omap_set_gpio_debounce); |
| 660 | |
| 661 | void omap_set_gpio_debounce_time(int gpio, int enc_time) |
| 662 | { |
| 663 | struct gpio_bank *bank; |
| 664 | void __iomem *reg; |
| 665 | |
| 666 | if (cpu_class_is_omap1()) |
| 667 | return; |
| 668 | |
| 669 | bank = get_gpio_bank(gpio); |
| 670 | reg = bank->base; |
| 671 | |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 672 | if (!bank->mod_usage) { |
| 673 | printk(KERN_ERR "GPIO not requested\n"); |
| 674 | return; |
| 675 | } |
| 676 | |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 677 | enc_time &= 0xff; |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 678 | |
| 679 | if (cpu_is_omap44xx()) |
| 680 | reg += OMAP4_GPIO_DEBOUNCINGTIME; |
| 681 | else |
| 682 | reg += OMAP24XX_GPIO_DEBOUNCE_VAL; |
| 683 | |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 684 | __raw_writel(enc_time, reg); |
| 685 | } |
| 686 | EXPORT_SYMBOL(omap_set_gpio_debounce_time); |
| 687 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 688 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 689 | static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio, |
| 690 | int trigger) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 691 | { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 692 | void __iomem *base = bank->base; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 693 | u32 gpio_bit = 1 << gpio; |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 694 | u32 val; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 695 | |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 696 | if (cpu_is_omap44xx()) { |
| 697 | MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit, |
| 698 | trigger & IRQ_TYPE_LEVEL_LOW); |
| 699 | MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit, |
| 700 | trigger & IRQ_TYPE_LEVEL_HIGH); |
| 701 | MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit, |
| 702 | trigger & IRQ_TYPE_EDGE_RISING); |
| 703 | MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit, |
| 704 | trigger & IRQ_TYPE_EDGE_FALLING); |
| 705 | } else { |
| 706 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit, |
| 707 | trigger & IRQ_TYPE_LEVEL_LOW); |
| 708 | MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit, |
| 709 | trigger & IRQ_TYPE_LEVEL_HIGH); |
| 710 | MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit, |
| 711 | trigger & IRQ_TYPE_EDGE_RISING); |
| 712 | MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit, |
| 713 | trigger & IRQ_TYPE_EDGE_FALLING); |
| 714 | } |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 715 | if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 716 | if (cpu_is_omap44xx()) { |
| 717 | if (trigger != 0) |
| 718 | __raw_writel(1 << gpio, bank->base+ |
| 719 | OMAP4_GPIO_IRQWAKEN0); |
| 720 | else { |
| 721 | val = __raw_readl(bank->base + |
| 722 | OMAP4_GPIO_IRQWAKEN0); |
| 723 | __raw_writel(val & (~(1 << gpio)), bank->base + |
| 724 | OMAP4_GPIO_IRQWAKEN0); |
| 725 | } |
| 726 | } else { |
| 727 | if (trigger != 0) |
| 728 | __raw_writel(1 << gpio, bank->base |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 729 | + OMAP24XX_GPIO_SETWKUENA); |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 730 | else |
| 731 | __raw_writel(1 << gpio, bank->base |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 732 | + OMAP24XX_GPIO_CLEARWKUENA); |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 733 | } |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame^] | 734 | } |
| 735 | /* This part needs to be executed always for OMAP34xx */ |
| 736 | if (cpu_is_omap34xx() || (bank->non_wakeup_gpios & gpio_bit)) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 737 | if (trigger != 0) |
| 738 | bank->enabled_non_wakeup_gpios |= gpio_bit; |
| 739 | else |
| 740 | bank->enabled_non_wakeup_gpios &= ~gpio_bit; |
| 741 | } |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 742 | |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 743 | if (cpu_is_omap44xx()) { |
| 744 | bank->level_mask = |
| 745 | __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) | |
| 746 | __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1); |
| 747 | } else { |
| 748 | bank->level_mask = |
| 749 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) | |
| 750 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 751 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 752 | } |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 753 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 754 | |
Uwe Kleine-König | 9198bcd | 2010-01-29 14:20:05 -0800 | [diff] [blame] | 755 | #ifdef CONFIG_ARCH_OMAP1 |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 756 | /* |
| 757 | * This only applies to chips that can't do both rising and falling edge |
| 758 | * detection at once. For all other chips, this function is a noop. |
| 759 | */ |
| 760 | static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) |
| 761 | { |
| 762 | void __iomem *reg = bank->base; |
| 763 | u32 l = 0; |
| 764 | |
| 765 | switch (bank->method) { |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 766 | case METHOD_MPUIO: |
| 767 | reg += OMAP_MPUIO_GPIO_INT_EDGE; |
| 768 | break; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 769 | #ifdef CONFIG_ARCH_OMAP15XX |
| 770 | case METHOD_GPIO_1510: |
| 771 | reg += OMAP1510_GPIO_INT_CONTROL; |
| 772 | break; |
| 773 | #endif |
| 774 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
| 775 | case METHOD_GPIO_7XX: |
| 776 | reg += OMAP7XX_GPIO_INT_CONTROL; |
| 777 | break; |
| 778 | #endif |
| 779 | default: |
| 780 | return; |
| 781 | } |
| 782 | |
| 783 | l = __raw_readl(reg); |
| 784 | if ((l >> gpio) & 1) |
| 785 | l &= ~(1 << gpio); |
| 786 | else |
| 787 | l |= 1 << gpio; |
| 788 | |
| 789 | __raw_writel(l, reg); |
| 790 | } |
Uwe Kleine-König | 9198bcd | 2010-01-29 14:20:05 -0800 | [diff] [blame] | 791 | #endif |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 792 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 793 | static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger) |
| 794 | { |
| 795 | void __iomem *reg = bank->base; |
| 796 | u32 l = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 797 | |
| 798 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 799 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 800 | case METHOD_MPUIO: |
| 801 | reg += OMAP_MPUIO_GPIO_INT_EDGE; |
| 802 | l = __raw_readl(reg); |
Janusz Krzysztofik | 2950157 | 2010-04-05 11:38:06 +0000 | [diff] [blame] | 803 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 804 | bank->toggle_mask |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 805 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 806 | l |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 807 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 808 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 809 | else |
| 810 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 811 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 812 | #endif |
| 813 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 814 | case METHOD_GPIO_1510: |
| 815 | reg += OMAP1510_GPIO_INT_CONTROL; |
| 816 | l = __raw_readl(reg); |
Janusz Krzysztofik | 2950157 | 2010-04-05 11:38:06 +0000 | [diff] [blame] | 817 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 818 | bank->toggle_mask |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 819 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 820 | l |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 821 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 822 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 823 | else |
| 824 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 825 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 826 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 827 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 828 | case METHOD_GPIO_1610: |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 829 | if (gpio & 0x08) |
| 830 | reg += OMAP1610_GPIO_EDGE_CTRL2; |
| 831 | else |
| 832 | reg += OMAP1610_GPIO_EDGE_CTRL1; |
| 833 | gpio &= 0x07; |
| 834 | l = __raw_readl(reg); |
| 835 | l &= ~(3 << (gpio << 1)); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 836 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 837 | l |= 2 << (gpio << 1); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 838 | if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 839 | l |= 1 << (gpio << 1); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 840 | if (trigger) |
| 841 | /* Enable wake-up during idle for dynamic tick */ |
| 842 | __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA); |
| 843 | else |
| 844 | __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 845 | break; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 846 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 847 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 848 | case METHOD_GPIO_7XX: |
| 849 | reg += OMAP7XX_GPIO_INT_CONTROL; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 850 | l = __raw_readl(reg); |
Janusz Krzysztofik | 2950157 | 2010-04-05 11:38:06 +0000 | [diff] [blame] | 851 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 852 | bank->toggle_mask |= 1 << gpio; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 853 | if (trigger & IRQ_TYPE_EDGE_RISING) |
| 854 | l |= 1 << gpio; |
| 855 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
| 856 | l &= ~(1 << gpio); |
| 857 | else |
| 858 | goto bad; |
| 859 | break; |
| 860 | #endif |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 861 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 862 | case METHOD_GPIO_24XX: |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 863 | case METHOD_GPIO_44XX: |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 864 | set_24xx_gpio_triggering(bank, gpio, trigger); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 865 | break; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 866 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 867 | default: |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 868 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 869 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 870 | __raw_writel(l, reg); |
| 871 | return 0; |
| 872 | bad: |
| 873 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 874 | } |
| 875 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 876 | static int gpio_irq_type(unsigned irq, unsigned type) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 877 | { |
| 878 | struct gpio_bank *bank; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 879 | unsigned gpio; |
| 880 | int retval; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 881 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 882 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 883 | if (!cpu_class_is_omap2() && irq > IH_MPUIO_BASE) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 884 | gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); |
| 885 | else |
| 886 | gpio = irq - IH_GPIO_BASE; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 887 | |
| 888 | if (check_gpio(gpio) < 0) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 889 | return -EINVAL; |
| 890 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 891 | if (type & ~IRQ_TYPE_SENSE_MASK) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 892 | return -EINVAL; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 893 | |
| 894 | /* OMAP1 allows only only edge triggering */ |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 895 | if (!cpu_class_is_omap2() |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 896 | && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 897 | return -EINVAL; |
| 898 | |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 899 | bank = get_irq_chip_data(irq); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 900 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 901 | retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 902 | if (retval == 0) { |
| 903 | irq_desc[irq].status &= ~IRQ_TYPE_SENSE_MASK; |
| 904 | irq_desc[irq].status |= type; |
| 905 | } |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 906 | spin_unlock_irqrestore(&bank->lock, flags); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 907 | |
| 908 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
| 909 | __set_irq_handler_unlocked(irq, handle_level_irq); |
| 910 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
| 911 | __set_irq_handler_unlocked(irq, handle_edge_irq); |
| 912 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 913 | return retval; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
| 917 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 918 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 919 | |
| 920 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 921 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 922 | case METHOD_MPUIO: |
| 923 | /* MPUIO irqstatus is reset by reading the status register, |
| 924 | * so do nothing here */ |
| 925 | return; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 926 | #endif |
| 927 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 928 | case METHOD_GPIO_1510: |
| 929 | reg += OMAP1510_GPIO_INT_STATUS; |
| 930 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 931 | #endif |
| 932 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 933 | case METHOD_GPIO_1610: |
| 934 | reg += OMAP1610_GPIO_IRQSTATUS1; |
| 935 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 936 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 937 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 938 | case METHOD_GPIO_7XX: |
| 939 | reg += OMAP7XX_GPIO_INT_STATUS; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 940 | break; |
| 941 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 942 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 943 | case METHOD_GPIO_24XX: |
| 944 | reg += OMAP24XX_GPIO_IRQSTATUS1; |
| 945 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 946 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 947 | #if defined(CONFIG_ARCH_OMAP4) |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 948 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 949 | reg += OMAP4_GPIO_IRQSTATUS0; |
| 950 | break; |
| 951 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 952 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 953 | WARN_ON(1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 954 | return; |
| 955 | } |
| 956 | __raw_writel(gpio_mask, reg); |
Hiroshi DOYU | bee7930 | 2006-09-25 12:41:46 +0300 | [diff] [blame] | 957 | |
| 958 | /* Workaround for clearing DSP GPIO interrupts to allow retention */ |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 959 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) |
| 960 | reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2; |
| 961 | else if (cpu_is_omap44xx()) |
| 962 | reg = bank->base + OMAP4_GPIO_IRQSTATUS1; |
| 963 | |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 964 | if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Roger Quadros | bedfd15 | 2009-04-23 11:10:50 -0700 | [diff] [blame] | 965 | __raw_writel(gpio_mask, reg); |
| 966 | |
| 967 | /* Flush posted write for the irq status to avoid spurious interrupts */ |
| 968 | __raw_readl(reg); |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 969 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) |
| 973 | { |
| 974 | _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio)); |
| 975 | } |
| 976 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 977 | static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank) |
| 978 | { |
| 979 | void __iomem *reg = bank->base; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 980 | int inv = 0; |
| 981 | u32 l; |
| 982 | u32 mask; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 983 | |
| 984 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 985 | #ifdef CONFIG_ARCH_OMAP1 |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 986 | case METHOD_MPUIO: |
| 987 | reg += OMAP_MPUIO_GPIO_MASKIT; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 988 | mask = 0xffff; |
| 989 | inv = 1; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 990 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 991 | #endif |
| 992 | #ifdef CONFIG_ARCH_OMAP15XX |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 993 | case METHOD_GPIO_1510: |
| 994 | reg += OMAP1510_GPIO_INT_MASK; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 995 | mask = 0xffff; |
| 996 | inv = 1; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 997 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 998 | #endif |
| 999 | #ifdef CONFIG_ARCH_OMAP16XX |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1000 | case METHOD_GPIO_1610: |
| 1001 | reg += OMAP1610_GPIO_IRQENABLE1; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 1002 | mask = 0xffff; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1003 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1004 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 1005 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 1006 | case METHOD_GPIO_7XX: |
| 1007 | reg += OMAP7XX_GPIO_INT_MASK; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 1008 | mask = 0xffffffff; |
| 1009 | inv = 1; |
| 1010 | break; |
| 1011 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1012 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1013 | case METHOD_GPIO_24XX: |
| 1014 | reg += OMAP24XX_GPIO_IRQENABLE1; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 1015 | mask = 0xffffffff; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1016 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1017 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1018 | #if defined(CONFIG_ARCH_OMAP4) |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1019 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1020 | reg += OMAP4_GPIO_IRQSTATUSSET0; |
| 1021 | mask = 0xffffffff; |
| 1022 | break; |
| 1023 | #endif |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1024 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1025 | WARN_ON(1); |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1026 | return 0; |
| 1027 | } |
| 1028 | |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 1029 | l = __raw_readl(reg); |
| 1030 | if (inv) |
| 1031 | l = ~l; |
| 1032 | l &= mask; |
| 1033 | return l; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1036 | static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable) |
| 1037 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1038 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1039 | u32 l; |
| 1040 | |
| 1041 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1042 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1043 | case METHOD_MPUIO: |
| 1044 | reg += OMAP_MPUIO_GPIO_MASKIT; |
| 1045 | l = __raw_readl(reg); |
| 1046 | if (enable) |
| 1047 | l &= ~(gpio_mask); |
| 1048 | else |
| 1049 | l |= gpio_mask; |
| 1050 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1051 | #endif |
| 1052 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1053 | case METHOD_GPIO_1510: |
| 1054 | reg += OMAP1510_GPIO_INT_MASK; |
| 1055 | l = __raw_readl(reg); |
| 1056 | if (enable) |
| 1057 | l &= ~(gpio_mask); |
| 1058 | else |
| 1059 | l |= gpio_mask; |
| 1060 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1061 | #endif |
| 1062 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1063 | case METHOD_GPIO_1610: |
| 1064 | if (enable) |
| 1065 | reg += OMAP1610_GPIO_SET_IRQENABLE1; |
| 1066 | else |
| 1067 | reg += OMAP1610_GPIO_CLEAR_IRQENABLE1; |
| 1068 | l = gpio_mask; |
| 1069 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1070 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 1071 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 1072 | case METHOD_GPIO_7XX: |
| 1073 | reg += OMAP7XX_GPIO_INT_MASK; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 1074 | l = __raw_readl(reg); |
| 1075 | if (enable) |
| 1076 | l &= ~(gpio_mask); |
| 1077 | else |
| 1078 | l |= gpio_mask; |
| 1079 | break; |
| 1080 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1081 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1082 | case METHOD_GPIO_24XX: |
| 1083 | if (enable) |
| 1084 | reg += OMAP24XX_GPIO_SETIRQENABLE1; |
| 1085 | else |
| 1086 | reg += OMAP24XX_GPIO_CLEARIRQENABLE1; |
| 1087 | l = gpio_mask; |
| 1088 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1089 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1090 | #ifdef CONFIG_ARCH_OMAP4 |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1091 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1092 | if (enable) |
| 1093 | reg += OMAP4_GPIO_IRQSTATUSSET0; |
| 1094 | else |
| 1095 | reg += OMAP4_GPIO_IRQSTATUSCLR0; |
| 1096 | l = gpio_mask; |
| 1097 | break; |
| 1098 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1099 | default: |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1100 | WARN_ON(1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1101 | return; |
| 1102 | } |
| 1103 | __raw_writel(l, reg); |
| 1104 | } |
| 1105 | |
| 1106 | static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable) |
| 1107 | { |
| 1108 | _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable); |
| 1109 | } |
| 1110 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1111 | /* |
| 1112 | * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register. |
| 1113 | * 1510 does not seem to have a wake-up register. If JTAG is connected |
| 1114 | * to the target, system will wake up always on GPIO events. While |
| 1115 | * system is running all registered GPIO interrupts need to have wake-up |
| 1116 | * enabled. When system is suspended, only selected GPIO interrupts need |
| 1117 | * to have wake-up enabled. |
| 1118 | */ |
| 1119 | static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) |
| 1120 | { |
Tony Lindgren | 4cc6420 | 2010-01-08 10:29:05 -0800 | [diff] [blame] | 1121 | unsigned long uninitialized_var(flags); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1122 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1123 | switch (bank->method) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1124 | #ifdef CONFIG_ARCH_OMAP16XX |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1125 | case METHOD_MPUIO: |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1126 | case METHOD_GPIO_1610: |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1127 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | b3bb4f6 | 2009-04-23 11:10:49 -0700 | [diff] [blame] | 1128 | if (enable) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1129 | bank->suspend_wakeup |= (1 << gpio); |
Kevin Hilman | b3bb4f6 | 2009-04-23 11:10:49 -0700 | [diff] [blame] | 1130 | else |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1131 | bank->suspend_wakeup &= ~(1 << gpio); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1132 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1133 | return 0; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1134 | #endif |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1135 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1136 | case METHOD_GPIO_24XX: |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1137 | case METHOD_GPIO_44XX: |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1138 | if (bank->non_wakeup_gpios & (1 << gpio)) { |
| 1139 | printk(KERN_ERR "Unable to modify wakeup on " |
| 1140 | "non-wakeup GPIO%d\n", |
| 1141 | (bank - gpio_bank) * 32 + gpio); |
| 1142 | return -EINVAL; |
| 1143 | } |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1144 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | b3bb4f6 | 2009-04-23 11:10:49 -0700 | [diff] [blame] | 1145 | if (enable) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1146 | bank->suspend_wakeup |= (1 << gpio); |
Kevin Hilman | b3bb4f6 | 2009-04-23 11:10:49 -0700 | [diff] [blame] | 1147 | else |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1148 | bank->suspend_wakeup &= ~(1 << gpio); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1149 | spin_unlock_irqrestore(&bank->lock, flags); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1150 | return 0; |
| 1151 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1152 | default: |
| 1153 | printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n", |
| 1154 | bank->method); |
| 1155 | return -EINVAL; |
| 1156 | } |
| 1157 | } |
| 1158 | |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 1159 | static void _reset_gpio(struct gpio_bank *bank, int gpio) |
| 1160 | { |
| 1161 | _set_gpio_direction(bank, get_gpio_index(gpio), 1); |
| 1162 | _set_gpio_irqenable(bank, gpio, 0); |
| 1163 | _clear_gpio_irqstatus(bank, gpio); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 1164 | _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 1165 | } |
| 1166 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1167 | /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ |
| 1168 | static int gpio_wake_enable(unsigned int irq, unsigned int enable) |
| 1169 | { |
| 1170 | unsigned int gpio = irq - IH_GPIO_BASE; |
| 1171 | struct gpio_bank *bank; |
| 1172 | int retval; |
| 1173 | |
| 1174 | if (check_gpio(gpio) < 0) |
| 1175 | return -ENODEV; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1176 | bank = get_irq_chip_data(irq); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1177 | retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1178 | |
| 1179 | return retval; |
| 1180 | } |
| 1181 | |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1182 | static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1183 | { |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1184 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1185 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1186 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1187 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1188 | |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 1189 | /* Set trigger to none. You need to enable the desired trigger with |
| 1190 | * request_irq() or set_irq_type(). |
| 1191 | */ |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1192 | _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1193 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1194 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1195 | if (bank->method == METHOD_GPIO_1510) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1196 | void __iomem *reg; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1197 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1198 | /* Claim the pin for MPU */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1199 | reg = bank->base + OMAP1510_GPIO_PIN_CONTROL; |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1200 | __raw_writel(__raw_readl(reg) | (1 << offset), reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1201 | } |
| 1202 | #endif |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 1203 | if (!cpu_class_is_omap1()) { |
| 1204 | if (!bank->mod_usage) { |
| 1205 | u32 ctrl; |
| 1206 | ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL); |
| 1207 | ctrl &= 0xFFFFFFFE; |
| 1208 | /* Module is enabled, clocks are not gated */ |
| 1209 | __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL); |
| 1210 | } |
| 1211 | bank->mod_usage |= 1 << offset; |
| 1212 | } |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1213 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1218 | static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1219 | { |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1220 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1221 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1222 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1223 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1224 | #ifdef CONFIG_ARCH_OMAP16XX |
| 1225 | if (bank->method == METHOD_GPIO_1610) { |
| 1226 | /* Disable wake-up during idle for dynamic tick */ |
| 1227 | void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1228 | __raw_writel(1 << offset, reg); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1229 | } |
| 1230 | #endif |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1231 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1232 | if ((bank->method == METHOD_GPIO_24XX) || |
| 1233 | (bank->method == METHOD_GPIO_44XX)) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1234 | /* Disable wake-up during idle for dynamic tick */ |
| 1235 | void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1236 | __raw_writel(1 << offset, reg); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1237 | } |
| 1238 | #endif |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 1239 | if (!cpu_class_is_omap1()) { |
| 1240 | bank->mod_usage &= ~(1 << offset); |
| 1241 | if (!bank->mod_usage) { |
| 1242 | u32 ctrl; |
| 1243 | ctrl = __raw_readl(bank->base + OMAP24XX_GPIO_CTRL); |
| 1244 | /* Module is disabled, clocks are gated */ |
| 1245 | ctrl |= 1; |
| 1246 | __raw_writel(ctrl, bank->base + OMAP24XX_GPIO_CTRL); |
| 1247 | } |
| 1248 | } |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1249 | _reset_gpio(bank, bank->chip.base + offset); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1250 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /* |
| 1254 | * We need to unmask the GPIO bank interrupt as soon as possible to |
| 1255 | * avoid missing GPIO interrupts for other lines in the bank. |
| 1256 | * Then we need to mask-read-clear-unmask the triggered GPIO lines |
| 1257 | * in the bank to avoid missing nested interrupts for a GPIO line. |
| 1258 | * If we wait to unmask individual GPIO lines in the bank after the |
| 1259 | * line's interrupt handler has been run, we may miss some nested |
| 1260 | * interrupts. |
| 1261 | */ |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 1262 | static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1263 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1264 | void __iomem *isr_reg = NULL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1265 | u32 isr; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 1266 | unsigned int gpio_irq, gpio_index; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1267 | struct gpio_bank *bank; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1268 | u32 retrigger = 0; |
| 1269 | int unmasked = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1270 | |
| 1271 | desc->chip->ack(irq); |
| 1272 | |
Thomas Gleixner | 418ca1f | 2006-07-01 22:32:41 +0100 | [diff] [blame] | 1273 | bank = get_irq_data(irq); |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1274 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1275 | if (bank->method == METHOD_MPUIO) |
| 1276 | isr_reg = bank->base + OMAP_MPUIO_GPIO_INT; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1277 | #endif |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1278 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1279 | if (bank->method == METHOD_GPIO_1510) |
| 1280 | isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS; |
| 1281 | #endif |
| 1282 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 1283 | if (bank->method == METHOD_GPIO_1610) |
| 1284 | isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1; |
| 1285 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 1286 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 1287 | if (bank->method == METHOD_GPIO_7XX) |
| 1288 | isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 1289 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1290 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1291 | if (bank->method == METHOD_GPIO_24XX) |
| 1292 | isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1; |
| 1293 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1294 | #if defined(CONFIG_ARCH_OMAP4) |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1295 | if (bank->method == METHOD_GPIO_44XX) |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1296 | isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0; |
| 1297 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1298 | while(1) { |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1299 | u32 isr_saved, level_mask = 0; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1300 | u32 enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1301 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1302 | enabled = _get_gpio_irqbank_mask(bank); |
| 1303 | isr_saved = isr = __raw_readl(isr_reg) & enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1304 | |
| 1305 | if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO)) |
| 1306 | isr &= 0x0000ffff; |
| 1307 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1308 | if (cpu_class_is_omap2()) { |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 1309 | level_mask = bank->level_mask & enabled; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1310 | } |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1311 | |
| 1312 | /* clear edge sensitive interrupts before handler(s) are |
| 1313 | called so that we don't miss any interrupt occurred while |
| 1314 | executing them */ |
| 1315 | _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0); |
| 1316 | _clear_gpio_irqbank(bank, isr_saved & ~level_mask); |
| 1317 | _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1); |
| 1318 | |
| 1319 | /* if there is only edge sensitive GPIO pin interrupts |
| 1320 | configured, we could unmask GPIO bank interrupt immediately */ |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1321 | if (!level_mask && !unmasked) { |
| 1322 | unmasked = 1; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1323 | desc->chip->unmask(irq); |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1324 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1325 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1326 | isr |= retrigger; |
| 1327 | retrigger = 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1328 | if (!isr) |
| 1329 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1330 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1331 | gpio_irq = bank->virtual_irq_start; |
| 1332 | for (; isr != 0; isr >>= 1, gpio_irq++) { |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 1333 | gpio_index = get_gpio_index(irq_to_gpio(gpio_irq)); |
| 1334 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1335 | if (!(isr & 1)) |
| 1336 | continue; |
Thomas Gleixner | 29454dd | 2006-07-03 02:22:22 +0200 | [diff] [blame] | 1337 | |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 1338 | #ifdef CONFIG_ARCH_OMAP1 |
| 1339 | /* |
| 1340 | * Some chips can't respond to both rising and falling |
| 1341 | * at the same time. If this irq was requested with |
| 1342 | * both flags, we need to flip the ICR data for the IRQ |
| 1343 | * to respond to the IRQ for the opposite direction. |
| 1344 | * This will be indicated in the bank toggle_mask. |
| 1345 | */ |
| 1346 | if (bank->toggle_mask & (1 << gpio_index)) |
| 1347 | _toggle_gpio_edge_triggering(bank, gpio_index); |
| 1348 | #endif |
| 1349 | |
Dmitry Baryshkov | d8aa025 | 2008-10-09 13:36:24 +0100 | [diff] [blame] | 1350 | generic_handle_irq(gpio_irq); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1351 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1352 | } |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 1353 | /* if bank has any level sensitive GPIO pin interrupt |
| 1354 | configured, we must unmask the bank interrupt only after |
| 1355 | handler(s) are executed in order to avoid spurious bank |
| 1356 | interrupt */ |
| 1357 | if (!unmasked) |
| 1358 | desc->chip->unmask(irq); |
| 1359 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1360 | } |
| 1361 | |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 1362 | static void gpio_irq_shutdown(unsigned int irq) |
| 1363 | { |
| 1364 | unsigned int gpio = irq - IH_GPIO_BASE; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1365 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 1366 | |
| 1367 | _reset_gpio(bank, gpio); |
| 1368 | } |
| 1369 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1370 | static void gpio_ack_irq(unsigned int irq) |
| 1371 | { |
| 1372 | unsigned int gpio = irq - IH_GPIO_BASE; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1373 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1374 | |
| 1375 | _clear_gpio_irqstatus(bank, gpio); |
| 1376 | } |
| 1377 | |
| 1378 | static void gpio_mask_irq(unsigned int irq) |
| 1379 | { |
| 1380 | unsigned int gpio = irq - IH_GPIO_BASE; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1381 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1382 | |
| 1383 | _set_gpio_irqenable(bank, gpio, 0); |
Kevin Hilman | 55b6019 | 2009-06-04 15:57:10 -0700 | [diff] [blame] | 1384 | _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | static void gpio_unmask_irq(unsigned int irq) |
| 1388 | { |
| 1389 | unsigned int gpio = irq - IH_GPIO_BASE; |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1390 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 1391 | unsigned int irq_mask = 1 << get_gpio_index(gpio); |
Kevin Hilman | 55b6019 | 2009-06-04 15:57:10 -0700 | [diff] [blame] | 1392 | struct irq_desc *desc = irq_to_desc(irq); |
| 1393 | u32 trigger = desc->status & IRQ_TYPE_SENSE_MASK; |
| 1394 | |
| 1395 | if (trigger) |
| 1396 | _set_gpio_triggering(bank, get_gpio_index(gpio), trigger); |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 1397 | |
| 1398 | /* For level-triggered GPIOs, the clearing must be done after |
| 1399 | * the HW source is cleared, thus after the handler has run */ |
| 1400 | if (bank->level_mask & irq_mask) { |
| 1401 | _set_gpio_irqenable(bank, gpio, 0); |
| 1402 | _clear_gpio_irqstatus(bank, gpio); |
| 1403 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1404 | |
Kevin Hilman | 4de8c75 | 2008-01-16 21:56:14 -0800 | [diff] [blame] | 1405 | _set_gpio_irqenable(bank, gpio, 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1406 | } |
| 1407 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1408 | static struct irq_chip gpio_irq_chip = { |
| 1409 | .name = "GPIO", |
| 1410 | .shutdown = gpio_irq_shutdown, |
| 1411 | .ack = gpio_ack_irq, |
| 1412 | .mask = gpio_mask_irq, |
| 1413 | .unmask = gpio_unmask_irq, |
| 1414 | .set_type = gpio_irq_type, |
| 1415 | .set_wake = gpio_wake_enable, |
| 1416 | }; |
| 1417 | |
| 1418 | /*---------------------------------------------------------------------*/ |
| 1419 | |
| 1420 | #ifdef CONFIG_ARCH_OMAP1 |
| 1421 | |
| 1422 | /* MPUIO uses the always-on 32k clock */ |
| 1423 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1424 | static void mpuio_ack_irq(unsigned int irq) |
| 1425 | { |
| 1426 | /* The ISR is reset automatically, so do nothing here. */ |
| 1427 | } |
| 1428 | |
| 1429 | static void mpuio_mask_irq(unsigned int irq) |
| 1430 | { |
| 1431 | unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1432 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1433 | |
| 1434 | _set_gpio_irqenable(bank, gpio, 0); |
| 1435 | } |
| 1436 | |
| 1437 | static void mpuio_unmask_irq(unsigned int irq) |
| 1438 | { |
| 1439 | unsigned int gpio = OMAP_MPUIO(irq - IH_MPUIO_BASE); |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1440 | struct gpio_bank *bank = get_irq_chip_data(irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1441 | |
| 1442 | _set_gpio_irqenable(bank, gpio, 1); |
| 1443 | } |
| 1444 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1445 | static struct irq_chip mpuio_irq_chip = { |
| 1446 | .name = "MPUIO", |
| 1447 | .ack = mpuio_ack_irq, |
| 1448 | .mask = mpuio_mask_irq, |
| 1449 | .unmask = mpuio_unmask_irq, |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1450 | .set_type = gpio_irq_type, |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1451 | #ifdef CONFIG_ARCH_OMAP16XX |
| 1452 | /* REVISIT: assuming only 16xx supports MPUIO wake events */ |
| 1453 | .set_wake = gpio_wake_enable, |
| 1454 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1455 | }; |
| 1456 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1457 | |
| 1458 | #define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO) |
| 1459 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1460 | |
| 1461 | #ifdef CONFIG_ARCH_OMAP16XX |
| 1462 | |
| 1463 | #include <linux/platform_device.h> |
| 1464 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 1465 | static int omap_mpuio_suspend_noirq(struct device *dev) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1466 | { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 1467 | struct platform_device *pdev = to_platform_device(dev); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1468 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1469 | void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1470 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1471 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1472 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1473 | bank->saved_wakeup = __raw_readl(mask_reg); |
| 1474 | __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1475 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1476 | |
| 1477 | return 0; |
| 1478 | } |
| 1479 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 1480 | static int omap_mpuio_resume_noirq(struct device *dev) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1481 | { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 1482 | struct platform_device *pdev = to_platform_device(dev); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1483 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1484 | void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1485 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1486 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1487 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1488 | __raw_writel(bank->saved_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1489 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1490 | |
| 1491 | return 0; |
| 1492 | } |
| 1493 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1494 | static const struct dev_pm_ops omap_mpuio_dev_pm_ops = { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 1495 | .suspend_noirq = omap_mpuio_suspend_noirq, |
| 1496 | .resume_noirq = omap_mpuio_resume_noirq, |
| 1497 | }; |
| 1498 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1499 | /* use platform_driver for this, now that there's no longer any |
| 1500 | * point to sys_device (other than not disturbing old code). |
| 1501 | */ |
| 1502 | static struct platform_driver omap_mpuio_driver = { |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1503 | .driver = { |
| 1504 | .name = "mpuio", |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 1505 | .pm = &omap_mpuio_dev_pm_ops, |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1506 | }, |
| 1507 | }; |
| 1508 | |
| 1509 | static struct platform_device omap_mpuio_device = { |
| 1510 | .name = "mpuio", |
| 1511 | .id = -1, |
| 1512 | .dev = { |
| 1513 | .driver = &omap_mpuio_driver.driver, |
| 1514 | } |
| 1515 | /* could list the /proc/iomem resources */ |
| 1516 | }; |
| 1517 | |
| 1518 | static inline void mpuio_init(void) |
| 1519 | { |
David Brownell | fcf126d | 2007-04-02 12:46:47 -0700 | [diff] [blame] | 1520 | platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]); |
| 1521 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1522 | if (platform_driver_register(&omap_mpuio_driver) == 0) |
| 1523 | (void) platform_device_register(&omap_mpuio_device); |
| 1524 | } |
| 1525 | |
| 1526 | #else |
| 1527 | static inline void mpuio_init(void) {} |
| 1528 | #endif /* 16xx */ |
| 1529 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1530 | #else |
| 1531 | |
| 1532 | extern struct irq_chip mpuio_irq_chip; |
| 1533 | |
| 1534 | #define bank_is_mpuio(bank) 0 |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1535 | static inline void mpuio_init(void) {} |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1536 | |
| 1537 | #endif |
| 1538 | |
| 1539 | /*---------------------------------------------------------------------*/ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1540 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1541 | /* REVISIT these are stupid implementations! replace by ones that |
| 1542 | * don't switch on METHOD_* and which mostly avoid spinlocks |
| 1543 | */ |
| 1544 | |
| 1545 | static int gpio_input(struct gpio_chip *chip, unsigned offset) |
| 1546 | { |
| 1547 | struct gpio_bank *bank; |
| 1548 | unsigned long flags; |
| 1549 | |
| 1550 | bank = container_of(chip, struct gpio_bank, chip); |
| 1551 | spin_lock_irqsave(&bank->lock, flags); |
| 1552 | _set_gpio_direction(bank, offset, 1); |
| 1553 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1554 | return 0; |
| 1555 | } |
| 1556 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 1557 | static int gpio_is_input(struct gpio_bank *bank, int mask) |
| 1558 | { |
| 1559 | void __iomem *reg = bank->base; |
| 1560 | |
| 1561 | switch (bank->method) { |
| 1562 | case METHOD_MPUIO: |
| 1563 | reg += OMAP_MPUIO_IO_CNTL; |
| 1564 | break; |
| 1565 | case METHOD_GPIO_1510: |
| 1566 | reg += OMAP1510_GPIO_DIR_CONTROL; |
| 1567 | break; |
| 1568 | case METHOD_GPIO_1610: |
| 1569 | reg += OMAP1610_GPIO_DIRECTION; |
| 1570 | break; |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 1571 | case METHOD_GPIO_7XX: |
| 1572 | reg += OMAP7XX_GPIO_DIR_CONTROL; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 1573 | break; |
| 1574 | case METHOD_GPIO_24XX: |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1575 | case METHOD_GPIO_44XX: |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 1576 | reg += OMAP24XX_GPIO_OE; |
| 1577 | break; |
| 1578 | } |
| 1579 | return __raw_readl(reg) & mask; |
| 1580 | } |
| 1581 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1582 | static int gpio_get(struct gpio_chip *chip, unsigned offset) |
| 1583 | { |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 1584 | struct gpio_bank *bank; |
| 1585 | void __iomem *reg; |
| 1586 | int gpio; |
| 1587 | u32 mask; |
| 1588 | |
| 1589 | gpio = chip->base + offset; |
| 1590 | bank = get_gpio_bank(gpio); |
| 1591 | reg = bank->base; |
| 1592 | mask = 1 << get_gpio_index(gpio); |
| 1593 | |
| 1594 | if (gpio_is_input(bank, mask)) |
| 1595 | return _get_gpio_datain(bank, gpio); |
| 1596 | else |
| 1597 | return _get_gpio_dataout(bank, gpio); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) |
| 1601 | { |
| 1602 | struct gpio_bank *bank; |
| 1603 | unsigned long flags; |
| 1604 | |
| 1605 | bank = container_of(chip, struct gpio_bank, chip); |
| 1606 | spin_lock_irqsave(&bank->lock, flags); |
| 1607 | _set_gpio_dataout(bank, offset, value); |
| 1608 | _set_gpio_direction(bank, offset, 0); |
| 1609 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
| 1613 | static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 1614 | { |
| 1615 | struct gpio_bank *bank; |
| 1616 | unsigned long flags; |
| 1617 | |
| 1618 | bank = container_of(chip, struct gpio_bank, chip); |
| 1619 | spin_lock_irqsave(&bank->lock, flags); |
| 1620 | _set_gpio_dataout(bank, offset, value); |
| 1621 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1622 | } |
| 1623 | |
David Brownell | a007b70 | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 1624 | static int gpio_2irq(struct gpio_chip *chip, unsigned offset) |
| 1625 | { |
| 1626 | struct gpio_bank *bank; |
| 1627 | |
| 1628 | bank = container_of(chip, struct gpio_bank, chip); |
| 1629 | return bank->virtual_irq_start + offset; |
| 1630 | } |
| 1631 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1632 | /*---------------------------------------------------------------------*/ |
| 1633 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1634 | static int initialized; |
Tony Lindgren | 56213ca | 2010-02-12 12:26:46 -0800 | [diff] [blame] | 1635 | #if defined(CONFIG_ARCH_OMAP1) || defined(CONFIG_ARCH_OMAP2) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1636 | static struct clk * gpio_ick; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1637 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1638 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1639 | #if defined(CONFIG_ARCH_OMAP2) |
| 1640 | static struct clk * gpio_fck; |
| 1641 | #endif |
| 1642 | |
| 1643 | #if defined(CONFIG_ARCH_OMAP2430) |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1644 | static struct clk * gpio5_ick; |
| 1645 | static struct clk * gpio5_fck; |
| 1646 | #endif |
| 1647 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 1648 | #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4) |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1649 | static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS]; |
| 1650 | #endif |
| 1651 | |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1652 | static void __init omap_gpio_show_rev(void) |
| 1653 | { |
| 1654 | u32 rev; |
| 1655 | |
| 1656 | if (cpu_is_omap16xx()) |
| 1657 | rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION); |
| 1658 | else if (cpu_is_omap24xx() || cpu_is_omap34xx()) |
| 1659 | rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); |
| 1660 | else if (cpu_is_omap44xx()) |
| 1661 | rev = __raw_readl(gpio_bank[0].base + OMAP4_GPIO_REVISION); |
| 1662 | else |
| 1663 | return; |
| 1664 | |
| 1665 | printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n", |
| 1666 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1667 | } |
| 1668 | |
David Brownell | 8ba55c5 | 2008-02-26 11:10:50 -0800 | [diff] [blame] | 1669 | /* This lock class tells lockdep that GPIO irqs are in a different |
| 1670 | * category than their parents, so it won't report false recursion. |
| 1671 | */ |
| 1672 | static struct lock_class_key gpio_lock_class; |
| 1673 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1674 | static int __init _omap_gpio_init(void) |
| 1675 | { |
| 1676 | int i; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1677 | int gpio = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1678 | struct gpio_bank *bank; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1679 | int bank_size = SZ_8K; /* Module 4KB + L4 4KB except on omap1 */ |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1680 | char clk_name[11]; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1681 | |
| 1682 | initialized = 1; |
| 1683 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1684 | #if defined(CONFIG_ARCH_OMAP1) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1685 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1686 | gpio_ick = clk_get(NULL, "arm_gpio_ck"); |
| 1687 | if (IS_ERR(gpio_ick)) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1688 | printk("Could not get arm_gpio_ck\n"); |
| 1689 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 1690 | clk_enable(gpio_ick); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1691 | } |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1692 | #endif |
| 1693 | #if defined(CONFIG_ARCH_OMAP2) |
| 1694 | if (cpu_class_is_omap2()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1695 | gpio_ick = clk_get(NULL, "gpios_ick"); |
| 1696 | if (IS_ERR(gpio_ick)) |
| 1697 | printk("Could not get gpios_ick\n"); |
| 1698 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 1699 | clk_enable(gpio_ick); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1700 | gpio_fck = clk_get(NULL, "gpios_fck"); |
Komal Shah | 1630b52 | 2006-09-25 12:51:08 +0300 | [diff] [blame] | 1701 | if (IS_ERR(gpio_fck)) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1702 | printk("Could not get gpios_fck\n"); |
| 1703 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 1704 | clk_enable(gpio_fck); |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1705 | |
| 1706 | /* |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1707 | * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1708 | */ |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1709 | #if defined(CONFIG_ARCH_OMAP2430) |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1710 | if (cpu_is_omap2430()) { |
| 1711 | gpio5_ick = clk_get(NULL, "gpio5_ick"); |
| 1712 | if (IS_ERR(gpio5_ick)) |
| 1713 | printk("Could not get gpio5_ick\n"); |
| 1714 | else |
| 1715 | clk_enable(gpio5_ick); |
| 1716 | gpio5_fck = clk_get(NULL, "gpio5_fck"); |
| 1717 | if (IS_ERR(gpio5_fck)) |
| 1718 | printk("Could not get gpio5_fck\n"); |
| 1719 | else |
| 1720 | clk_enable(gpio5_fck); |
| 1721 | } |
| 1722 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1723 | } |
| 1724 | #endif |
| 1725 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 1726 | #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4) |
| 1727 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1728 | for (i = 0; i < OMAP34XX_NR_GPIOS; i++) { |
| 1729 | sprintf(clk_name, "gpio%d_ick", i + 1); |
| 1730 | gpio_iclks[i] = clk_get(NULL, clk_name); |
| 1731 | if (IS_ERR(gpio_iclks[i])) |
| 1732 | printk(KERN_ERR "Could not get %s\n", clk_name); |
| 1733 | else |
| 1734 | clk_enable(gpio_iclks[i]); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | #endif |
| 1738 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1739 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1740 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1741 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1742 | gpio_bank_count = 2; |
| 1743 | gpio_bank = gpio_bank_1510; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1744 | bank_size = SZ_2K; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1745 | } |
| 1746 | #endif |
| 1747 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 1748 | if (cpu_is_omap16xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1749 | gpio_bank_count = 5; |
| 1750 | gpio_bank = gpio_bank_1610; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1751 | bank_size = SZ_2K; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1752 | } |
| 1753 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 1754 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
| 1755 | if (cpu_is_omap7xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1756 | gpio_bank_count = 7; |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 1757 | gpio_bank = gpio_bank_7xx; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1758 | bank_size = SZ_2K; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1759 | } |
| 1760 | #endif |
Tony Lindgren | 088ef95 | 2010-02-12 12:26:47 -0800 | [diff] [blame] | 1761 | #ifdef CONFIG_ARCH_OMAP2 |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1762 | if (cpu_is_omap242x()) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1763 | gpio_bank_count = 4; |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1764 | gpio_bank = gpio_bank_242x; |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1765 | } |
| 1766 | if (cpu_is_omap243x()) { |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1767 | gpio_bank_count = 5; |
| 1768 | gpio_bank = gpio_bank_243x; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1769 | } |
| 1770 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1771 | #ifdef CONFIG_ARCH_OMAP3 |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1772 | if (cpu_is_omap34xx()) { |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1773 | gpio_bank_count = OMAP34XX_NR_GPIOS; |
| 1774 | gpio_bank = gpio_bank_34xx; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1775 | } |
| 1776 | #endif |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 1777 | #ifdef CONFIG_ARCH_OMAP4 |
| 1778 | if (cpu_is_omap44xx()) { |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 1779 | gpio_bank_count = OMAP34XX_NR_GPIOS; |
| 1780 | gpio_bank = gpio_bank_44xx; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 1781 | } |
| 1782 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1783 | for (i = 0; i < gpio_bank_count; i++) { |
| 1784 | int j, gpio_count = 16; |
| 1785 | |
| 1786 | bank = &gpio_bank[i]; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1787 | spin_lock_init(&bank->lock); |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1788 | |
| 1789 | /* Static mapping, never released */ |
| 1790 | bank->base = ioremap(bank->pbase, bank_size); |
| 1791 | if (!bank->base) { |
| 1792 | printk(KERN_ERR "Could not ioremap gpio bank%i\n", i); |
| 1793 | continue; |
| 1794 | } |
| 1795 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1796 | if (bank_is_mpuio(bank)) |
Russell King | 7c7095a | 2008-09-05 15:49:14 +0100 | [diff] [blame] | 1797 | __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT); |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1798 | if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1799 | __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK); |
| 1800 | __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS); |
| 1801 | } |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1802 | if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1803 | __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1); |
| 1804 | __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1805 | __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1806 | } |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 1807 | if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) { |
| 1808 | __raw_writel(0xffffffff, bank->base + OMAP7XX_GPIO_INT_MASK); |
| 1809 | __raw_writel(0x00000000, bank->base + OMAP7XX_GPIO_INT_STATUS); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1810 | |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 1811 | gpio_count = 32; /* 7xx has 32-bit GPIOs */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1812 | } |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1813 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1814 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1815 | if ((bank->method == METHOD_GPIO_24XX) || |
| 1816 | (bank->method == METHOD_GPIO_44XX)) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1817 | static const u32 non_wakeup_gpios[] = { |
| 1818 | 0xe203ffc0, 0x08700040 |
| 1819 | }; |
Juha Yrjola | 14f1c3b | 2006-12-06 17:13:48 -0800 | [diff] [blame] | 1820 | |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1821 | if (cpu_is_omap44xx()) { |
| 1822 | __raw_writel(0xffffffff, bank->base + |
| 1823 | OMAP4_GPIO_IRQSTATUSCLR0); |
| 1824 | __raw_writew(0x0015, bank->base + |
| 1825 | OMAP4_GPIO_SYSCONFIG); |
| 1826 | __raw_writel(0x00000000, bank->base + |
| 1827 | OMAP4_GPIO_DEBOUNCENABLE); |
| 1828 | /* |
| 1829 | * Initialize interface clock ungated, |
| 1830 | * module enabled |
| 1831 | */ |
| 1832 | __raw_writel(0, bank->base + OMAP4_GPIO_CTRL); |
| 1833 | } else { |
| 1834 | __raw_writel(0x00000000, bank->base + |
| 1835 | OMAP24XX_GPIO_IRQENABLE1); |
| 1836 | __raw_writel(0xffffffff, bank->base + |
| 1837 | OMAP24XX_GPIO_IRQSTATUS1); |
| 1838 | __raw_writew(0x0015, bank->base + |
| 1839 | OMAP24XX_GPIO_SYSCONFIG); |
| 1840 | __raw_writel(0x00000000, bank->base + |
| 1841 | OMAP24XX_GPIO_DEBOUNCE_EN); |
| 1842 | |
| 1843 | /* |
| 1844 | * Initialize interface clock ungated, |
| 1845 | * module enabled |
| 1846 | */ |
| 1847 | __raw_writel(0, bank->base + |
| 1848 | OMAP24XX_GPIO_CTRL); |
| 1849 | } |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame^] | 1850 | if (cpu_is_omap24xx() && |
| 1851 | i < ARRAY_SIZE(non_wakeup_gpios)) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1852 | bank->non_wakeup_gpios = non_wakeup_gpios[i]; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1853 | gpio_count = 32; |
| 1854 | } |
| 1855 | #endif |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 1856 | |
| 1857 | bank->mod_usage = 0; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1858 | /* REVISIT eventually switch from OMAP-specific gpio structs |
| 1859 | * over to the generic ones |
| 1860 | */ |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1861 | bank->chip.request = omap_gpio_request; |
| 1862 | bank->chip.free = omap_gpio_free; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1863 | bank->chip.direction_input = gpio_input; |
| 1864 | bank->chip.get = gpio_get; |
| 1865 | bank->chip.direction_output = gpio_output; |
| 1866 | bank->chip.set = gpio_set; |
David Brownell | a007b70 | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 1867 | bank->chip.to_irq = gpio_2irq; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1868 | if (bank_is_mpuio(bank)) { |
| 1869 | bank->chip.label = "mpuio"; |
Russell King | 69114a4 | 2008-09-03 10:15:26 +0100 | [diff] [blame] | 1870 | #ifdef CONFIG_ARCH_OMAP16XX |
David Brownell | d8f388d | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 1871 | bank->chip.dev = &omap_mpuio_device.dev; |
| 1872 | #endif |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1873 | bank->chip.base = OMAP_MPUIO(0); |
| 1874 | } else { |
| 1875 | bank->chip.label = "gpio"; |
| 1876 | bank->chip.base = gpio; |
| 1877 | gpio += gpio_count; |
| 1878 | } |
| 1879 | bank->chip.ngpio = gpio_count; |
| 1880 | |
| 1881 | gpiochip_add(&bank->chip); |
| 1882 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1883 | for (j = bank->virtual_irq_start; |
| 1884 | j < bank->virtual_irq_start + gpio_count; j++) { |
David Brownell | 8ba55c5 | 2008-02-26 11:10:50 -0800 | [diff] [blame] | 1885 | lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class); |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1886 | set_irq_chip_data(j, bank); |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1887 | if (bank_is_mpuio(bank)) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1888 | set_irq_chip(j, &mpuio_irq_chip); |
| 1889 | else |
| 1890 | set_irq_chip(j, &gpio_irq_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 1891 | set_irq_handler(j, handle_simple_irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1892 | set_irq_flags(j, IRQF_VALID); |
| 1893 | } |
| 1894 | set_irq_chained_handler(bank->irq, gpio_irq_handler); |
| 1895 | set_irq_data(bank->irq, bank); |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 1896 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 1897 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 1898 | sprintf(clk_name, "gpio%d_dbck", i + 1); |
| 1899 | bank->dbck = clk_get(NULL, clk_name); |
| 1900 | if (IS_ERR(bank->dbck)) |
| 1901 | printk(KERN_ERR "Could not get %s\n", clk_name); |
| 1902 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | /* Enable system clock for GPIO module. |
| 1906 | * The CAM_CLK_CTRL *is* really the right place. */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1907 | if (cpu_is_omap16xx()) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1908 | omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL); |
| 1909 | |
Juha Yrjola | 14f1c3b | 2006-12-06 17:13:48 -0800 | [diff] [blame] | 1910 | /* Enable autoidle for the OCP interface */ |
| 1911 | if (cpu_is_omap24xx()) |
| 1912 | omap_writel(1 << 0, 0x48019010); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1913 | if (cpu_is_omap34xx()) |
| 1914 | omap_writel(1 << 0, 0x48306814); |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1915 | |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1916 | omap_gpio_show_rev(); |
| 1917 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1918 | return 0; |
| 1919 | } |
| 1920 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1921 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1922 | static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg) |
| 1923 | { |
| 1924 | int i; |
| 1925 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1926 | if (!cpu_class_is_omap2() && !cpu_is_omap16xx()) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1927 | return 0; |
| 1928 | |
| 1929 | for (i = 0; i < gpio_bank_count; i++) { |
| 1930 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1931 | void __iomem *wake_status; |
| 1932 | void __iomem *wake_clear; |
| 1933 | void __iomem *wake_set; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1934 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1935 | |
| 1936 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1937 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1938 | case METHOD_GPIO_1610: |
| 1939 | wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE; |
| 1940 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1941 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1942 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1943 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1944 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1945 | case METHOD_GPIO_24XX: |
Tero Kristo | 723fdb7 | 2008-11-26 14:35:16 -0800 | [diff] [blame] | 1946 | wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1947 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 1948 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
| 1949 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1950 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1951 | #ifdef CONFIG_ARCH_OMAP4 |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1952 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1953 | wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 1954 | wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 1955 | wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 1956 | break; |
| 1957 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1958 | default: |
| 1959 | continue; |
| 1960 | } |
| 1961 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1962 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1963 | bank->saved_wakeup = __raw_readl(wake_status); |
| 1964 | __raw_writel(0xffffffff, wake_clear); |
| 1965 | __raw_writel(bank->suspend_wakeup, wake_set); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1966 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | return 0; |
| 1970 | } |
| 1971 | |
| 1972 | static int omap_gpio_resume(struct sys_device *dev) |
| 1973 | { |
| 1974 | int i; |
| 1975 | |
Tero Kristo | 723fdb7 | 2008-11-26 14:35:16 -0800 | [diff] [blame] | 1976 | if (!cpu_class_is_omap2() && !cpu_is_omap16xx()) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1977 | return 0; |
| 1978 | |
| 1979 | for (i = 0; i < gpio_bank_count; i++) { |
| 1980 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1981 | void __iomem *wake_clear; |
| 1982 | void __iomem *wake_set; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1983 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1984 | |
| 1985 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1986 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1987 | case METHOD_GPIO_1610: |
| 1988 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1989 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1990 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1991 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1992 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1993 | case METHOD_GPIO_24XX: |
Tony Lindgren | 0d9356c | 2006-09-25 12:41:45 +0300 | [diff] [blame] | 1994 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 1995 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1996 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1997 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1998 | #ifdef CONFIG_ARCH_OMAP4 |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1999 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 2000 | wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 2001 | wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 2002 | break; |
| 2003 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 2004 | default: |
| 2005 | continue; |
| 2006 | } |
| 2007 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 2008 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 2009 | __raw_writel(0xffffffff, wake_clear); |
| 2010 | __raw_writel(bank->saved_wakeup, wake_set); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 2011 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | return 0; |
| 2015 | } |
| 2016 | |
| 2017 | static struct sysdev_class omap_gpio_sysclass = { |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 2018 | .name = "gpio", |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 2019 | .suspend = omap_gpio_suspend, |
| 2020 | .resume = omap_gpio_resume, |
| 2021 | }; |
| 2022 | |
| 2023 | static struct sys_device omap_gpio_device = { |
| 2024 | .id = 0, |
| 2025 | .cls = &omap_gpio_sysclass, |
| 2026 | }; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2027 | |
| 2028 | #endif |
| 2029 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 2030 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2031 | |
| 2032 | static int workaround_enabled; |
| 2033 | |
| 2034 | void omap2_gpio_prepare_for_retention(void) |
| 2035 | { |
| 2036 | int i, c = 0; |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame^] | 2037 | int min = 0; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2038 | |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame^] | 2039 | if (cpu_is_omap34xx()) |
| 2040 | min = 1; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2041 | /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious |
| 2042 | * IRQs will be generated. See OMAP2420 Errata item 1.101. */ |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame^] | 2043 | for (i = min; i < gpio_bank_count; i++) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2044 | struct gpio_bank *bank = &gpio_bank[i]; |
| 2045 | u32 l1, l2; |
| 2046 | |
| 2047 | if (!(bank->enabled_non_wakeup_gpios)) |
| 2048 | continue; |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2049 | |
| 2050 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 2051 | bank->saved_datain = __raw_readl(bank->base + |
| 2052 | OMAP24XX_GPIO_DATAIN); |
| 2053 | l1 = __raw_readl(bank->base + |
| 2054 | OMAP24XX_GPIO_FALLINGDETECT); |
| 2055 | l2 = __raw_readl(bank->base + |
| 2056 | OMAP24XX_GPIO_RISINGDETECT); |
| 2057 | } |
| 2058 | |
| 2059 | if (cpu_is_omap44xx()) { |
| 2060 | bank->saved_datain = __raw_readl(bank->base + |
| 2061 | OMAP4_GPIO_DATAIN); |
| 2062 | l1 = __raw_readl(bank->base + |
| 2063 | OMAP4_GPIO_FALLINGDETECT); |
| 2064 | l2 = __raw_readl(bank->base + |
| 2065 | OMAP4_GPIO_RISINGDETECT); |
| 2066 | } |
| 2067 | |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2068 | bank->saved_fallingdetect = l1; |
| 2069 | bank->saved_risingdetect = l2; |
| 2070 | l1 &= ~bank->enabled_non_wakeup_gpios; |
| 2071 | l2 &= ~bank->enabled_non_wakeup_gpios; |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2072 | |
| 2073 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 2074 | __raw_writel(l1, bank->base + |
| 2075 | OMAP24XX_GPIO_FALLINGDETECT); |
| 2076 | __raw_writel(l2, bank->base + |
| 2077 | OMAP24XX_GPIO_RISINGDETECT); |
| 2078 | } |
| 2079 | |
| 2080 | if (cpu_is_omap44xx()) { |
| 2081 | __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT); |
| 2082 | __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT); |
| 2083 | } |
| 2084 | |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2085 | c++; |
| 2086 | } |
| 2087 | if (!c) { |
| 2088 | workaround_enabled = 0; |
| 2089 | return; |
| 2090 | } |
| 2091 | workaround_enabled = 1; |
| 2092 | } |
| 2093 | |
| 2094 | void omap2_gpio_resume_after_retention(void) |
| 2095 | { |
| 2096 | int i; |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame^] | 2097 | int min = 0; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2098 | |
| 2099 | if (!workaround_enabled) |
| 2100 | return; |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame^] | 2101 | if (cpu_is_omap34xx()) |
| 2102 | min = 1; |
| 2103 | for (i = min; i < gpio_bank_count; i++) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2104 | struct gpio_bank *bank = &gpio_bank[i]; |
Eero Nurkkala | 82dbb9d | 2009-08-28 10:51:36 -0700 | [diff] [blame] | 2105 | u32 l, gen, gen0, gen1; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2106 | |
| 2107 | if (!(bank->enabled_non_wakeup_gpios)) |
| 2108 | continue; |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2109 | |
| 2110 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 2111 | __raw_writel(bank->saved_fallingdetect, |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2112 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2113 | __raw_writel(bank->saved_risingdetect, |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2114 | bank->base + OMAP24XX_GPIO_RISINGDETECT); |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2115 | l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN); |
| 2116 | } |
| 2117 | |
| 2118 | if (cpu_is_omap44xx()) { |
| 2119 | __raw_writel(bank->saved_fallingdetect, |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 2120 | bank->base + OMAP4_GPIO_FALLINGDETECT); |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2121 | __raw_writel(bank->saved_risingdetect, |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 2122 | bank->base + OMAP4_GPIO_RISINGDETECT); |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2123 | l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN); |
| 2124 | } |
| 2125 | |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2126 | /* Check if any of the non-wakeup interrupt GPIOs have changed |
| 2127 | * state. If so, generate an IRQ by software. This is |
| 2128 | * horribly racy, but it's the best we can do to work around |
| 2129 | * this silicon bug. */ |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2130 | l ^= bank->saved_datain; |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame^] | 2131 | l &= bank->enabled_non_wakeup_gpios; |
Eero Nurkkala | 82dbb9d | 2009-08-28 10:51:36 -0700 | [diff] [blame] | 2132 | |
| 2133 | /* |
| 2134 | * No need to generate IRQs for the rising edge for gpio IRQs |
| 2135 | * configured with falling edge only; and vice versa. |
| 2136 | */ |
| 2137 | gen0 = l & bank->saved_fallingdetect; |
| 2138 | gen0 &= bank->saved_datain; |
| 2139 | |
| 2140 | gen1 = l & bank->saved_risingdetect; |
| 2141 | gen1 &= ~(bank->saved_datain); |
| 2142 | |
| 2143 | /* FIXME: Consider GPIO IRQs with level detections properly! */ |
| 2144 | gen = l & (~(bank->saved_fallingdetect) & |
| 2145 | ~(bank->saved_risingdetect)); |
| 2146 | /* Consider all GPIO IRQs needed to be updated */ |
| 2147 | gen |= gen0 | gen1; |
| 2148 | |
| 2149 | if (gen) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2150 | u32 old0, old1; |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2151 | |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 2152 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2153 | old0 = __raw_readl(bank->base + |
| 2154 | OMAP24XX_GPIO_LEVELDETECT0); |
| 2155 | old1 = __raw_readl(bank->base + |
| 2156 | OMAP24XX_GPIO_LEVELDETECT1); |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 2157 | __raw_writel(old0 | gen, bank->base + |
Eero Nurkkala | 82dbb9d | 2009-08-28 10:51:36 -0700 | [diff] [blame] | 2158 | OMAP24XX_GPIO_LEVELDETECT0); |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 2159 | __raw_writel(old1 | gen, bank->base + |
Eero Nurkkala | 82dbb9d | 2009-08-28 10:51:36 -0700 | [diff] [blame] | 2160 | OMAP24XX_GPIO_LEVELDETECT1); |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 2161 | __raw_writel(old0, bank->base + |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2162 | OMAP24XX_GPIO_LEVELDETECT0); |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 2163 | __raw_writel(old1, bank->base + |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2164 | OMAP24XX_GPIO_LEVELDETECT1); |
| 2165 | } |
| 2166 | |
| 2167 | if (cpu_is_omap44xx()) { |
| 2168 | old0 = __raw_readl(bank->base + |
| 2169 | OMAP4_GPIO_LEVELDETECT0); |
| 2170 | old1 = __raw_readl(bank->base + |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 2171 | OMAP4_GPIO_LEVELDETECT1); |
Tony Lindgren | 3f1686a | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 2172 | __raw_writel(old0 | l, bank->base + |
| 2173 | OMAP4_GPIO_LEVELDETECT0); |
| 2174 | __raw_writel(old1 | l, bank->base + |
| 2175 | OMAP4_GPIO_LEVELDETECT1); |
| 2176 | __raw_writel(old0, bank->base + |
| 2177 | OMAP4_GPIO_LEVELDETECT0); |
| 2178 | __raw_writel(old1, bank->base + |
| 2179 | OMAP4_GPIO_LEVELDETECT1); |
| 2180 | } |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | } |
| 2185 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 2186 | #endif |
| 2187 | |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 2188 | #ifdef CONFIG_ARCH_OMAP3 |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 2189 | /* save the registers of bank 2-6 */ |
| 2190 | void omap_gpio_save_context(void) |
| 2191 | { |
| 2192 | int i; |
| 2193 | |
| 2194 | /* saving banks from 2-6 only since GPIO1 is in WKUP */ |
| 2195 | for (i = 1; i < gpio_bank_count; i++) { |
| 2196 | struct gpio_bank *bank = &gpio_bank[i]; |
| 2197 | gpio_context[i].sysconfig = |
| 2198 | __raw_readl(bank->base + OMAP24XX_GPIO_SYSCONFIG); |
| 2199 | gpio_context[i].irqenable1 = |
| 2200 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1); |
| 2201 | gpio_context[i].irqenable2 = |
| 2202 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2); |
| 2203 | gpio_context[i].wake_en = |
| 2204 | __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN); |
| 2205 | gpio_context[i].ctrl = |
| 2206 | __raw_readl(bank->base + OMAP24XX_GPIO_CTRL); |
| 2207 | gpio_context[i].oe = |
| 2208 | __raw_readl(bank->base + OMAP24XX_GPIO_OE); |
| 2209 | gpio_context[i].leveldetect0 = |
| 2210 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 2211 | gpio_context[i].leveldetect1 = |
| 2212 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 2213 | gpio_context[i].risingdetect = |
| 2214 | __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT); |
| 2215 | gpio_context[i].fallingdetect = |
| 2216 | __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 2217 | gpio_context[i].dataout = |
| 2218 | __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT); |
| 2219 | gpio_context[i].setwkuena = |
| 2220 | __raw_readl(bank->base + OMAP24XX_GPIO_SETWKUENA); |
| 2221 | gpio_context[i].setdataout = |
| 2222 | __raw_readl(bank->base + OMAP24XX_GPIO_SETDATAOUT); |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | /* restore the required registers of bank 2-6 */ |
| 2227 | void omap_gpio_restore_context(void) |
| 2228 | { |
| 2229 | int i; |
| 2230 | |
| 2231 | for (i = 1; i < gpio_bank_count; i++) { |
| 2232 | struct gpio_bank *bank = &gpio_bank[i]; |
| 2233 | __raw_writel(gpio_context[i].sysconfig, |
| 2234 | bank->base + OMAP24XX_GPIO_SYSCONFIG); |
| 2235 | __raw_writel(gpio_context[i].irqenable1, |
| 2236 | bank->base + OMAP24XX_GPIO_IRQENABLE1); |
| 2237 | __raw_writel(gpio_context[i].irqenable2, |
| 2238 | bank->base + OMAP24XX_GPIO_IRQENABLE2); |
| 2239 | __raw_writel(gpio_context[i].wake_en, |
| 2240 | bank->base + OMAP24XX_GPIO_WAKE_EN); |
| 2241 | __raw_writel(gpio_context[i].ctrl, |
| 2242 | bank->base + OMAP24XX_GPIO_CTRL); |
| 2243 | __raw_writel(gpio_context[i].oe, |
| 2244 | bank->base + OMAP24XX_GPIO_OE); |
| 2245 | __raw_writel(gpio_context[i].leveldetect0, |
| 2246 | bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 2247 | __raw_writel(gpio_context[i].leveldetect1, |
| 2248 | bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 2249 | __raw_writel(gpio_context[i].risingdetect, |
| 2250 | bank->base + OMAP24XX_GPIO_RISINGDETECT); |
| 2251 | __raw_writel(gpio_context[i].fallingdetect, |
| 2252 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 2253 | __raw_writel(gpio_context[i].dataout, |
| 2254 | bank->base + OMAP24XX_GPIO_DATAOUT); |
| 2255 | __raw_writel(gpio_context[i].setwkuena, |
| 2256 | bank->base + OMAP24XX_GPIO_SETWKUENA); |
| 2257 | __raw_writel(gpio_context[i].setdataout, |
| 2258 | bank->base + OMAP24XX_GPIO_SETDATAOUT); |
| 2259 | } |
| 2260 | } |
| 2261 | #endif |
| 2262 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2263 | /* |
| 2264 | * This may get called early from board specific init |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 2265 | * for boards that have interrupts routed via FPGA. |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2266 | */ |
David Brownell | 277d58e | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 2267 | int __init omap_gpio_init(void) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2268 | { |
| 2269 | if (!initialized) |
| 2270 | return _omap_gpio_init(); |
| 2271 | else |
| 2272 | return 0; |
| 2273 | } |
| 2274 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 2275 | static int __init omap_gpio_sysinit(void) |
| 2276 | { |
| 2277 | int ret = 0; |
| 2278 | |
| 2279 | if (!initialized) |
| 2280 | ret = _omap_gpio_init(); |
| 2281 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 2282 | mpuio_init(); |
| 2283 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 2284 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 2285 | if (cpu_is_omap16xx() || cpu_class_is_omap2()) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 2286 | if (ret == 0) { |
| 2287 | ret = sysdev_class_register(&omap_gpio_sysclass); |
| 2288 | if (ret == 0) |
| 2289 | ret = sysdev_register(&omap_gpio_device); |
| 2290 | } |
| 2291 | } |
| 2292 | #endif |
| 2293 | |
| 2294 | return ret; |
| 2295 | } |
| 2296 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 2297 | arch_initcall(omap_gpio_sysinit); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2298 | |
| 2299 | |
| 2300 | #ifdef CONFIG_DEBUG_FS |
| 2301 | |
| 2302 | #include <linux/debugfs.h> |
| 2303 | #include <linux/seq_file.h> |
| 2304 | |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2305 | static int dbg_gpio_show(struct seq_file *s, void *unused) |
| 2306 | { |
| 2307 | unsigned i, j, gpio; |
| 2308 | |
| 2309 | for (i = 0, gpio = 0; i < gpio_bank_count; i++) { |
| 2310 | struct gpio_bank *bank = gpio_bank + i; |
| 2311 | unsigned bankwidth = 16; |
| 2312 | u32 mask = 1; |
| 2313 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 2314 | if (bank_is_mpuio(bank)) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2315 | gpio = OMAP_MPUIO(0); |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 2316 | else if (cpu_class_is_omap2() || cpu_is_omap7xx()) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2317 | bankwidth = 32; |
| 2318 | |
| 2319 | for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) { |
| 2320 | unsigned irq, value, is_in, irqstat; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 2321 | const char *label; |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2322 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 2323 | label = gpiochip_is_requested(&bank->chip, j); |
| 2324 | if (!label) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2325 | continue; |
| 2326 | |
| 2327 | irq = bank->virtual_irq_start + j; |
David Brownell | 0b84b5c | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 2328 | value = gpio_get_value(gpio); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2329 | is_in = gpio_is_input(bank, mask); |
| 2330 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 2331 | if (bank_is_mpuio(bank)) |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 2332 | seq_printf(s, "MPUIO %2d ", j); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2333 | else |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 2334 | seq_printf(s, "GPIO %3d ", gpio); |
Jarkko Nikula | 21c867f | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 2335 | seq_printf(s, "(%-20.20s): %s %s", |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 2336 | label, |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2337 | is_in ? "in " : "out", |
| 2338 | value ? "hi" : "lo"); |
| 2339 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 2340 | /* FIXME for at least omap2, show pullup/pulldown state */ |
| 2341 | |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2342 | irqstat = irq_desc[irq].status; |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 2343 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2344 | if (is_in && ((bank->suspend_wakeup & mask) |
| 2345 | || irqstat & IRQ_TYPE_SENSE_MASK)) { |
| 2346 | char *trigger = NULL; |
| 2347 | |
| 2348 | switch (irqstat & IRQ_TYPE_SENSE_MASK) { |
| 2349 | case IRQ_TYPE_EDGE_FALLING: |
| 2350 | trigger = "falling"; |
| 2351 | break; |
| 2352 | case IRQ_TYPE_EDGE_RISING: |
| 2353 | trigger = "rising"; |
| 2354 | break; |
| 2355 | case IRQ_TYPE_EDGE_BOTH: |
| 2356 | trigger = "bothedge"; |
| 2357 | break; |
| 2358 | case IRQ_TYPE_LEVEL_LOW: |
| 2359 | trigger = "low"; |
| 2360 | break; |
| 2361 | case IRQ_TYPE_LEVEL_HIGH: |
| 2362 | trigger = "high"; |
| 2363 | break; |
| 2364 | case IRQ_TYPE_NONE: |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 2365 | trigger = "(?)"; |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2366 | break; |
| 2367 | } |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 2368 | seq_printf(s, ", irq-%d %-8s%s", |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2369 | irq, trigger, |
| 2370 | (bank->suspend_wakeup & mask) |
| 2371 | ? " wakeup" : ""); |
| 2372 | } |
Tony Lindgren | 3a26e33 | 2009-01-15 13:09:53 +0200 | [diff] [blame] | 2373 | #endif |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2374 | seq_printf(s, "\n"); |
| 2375 | } |
| 2376 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 2377 | if (bank_is_mpuio(bank)) { |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2378 | seq_printf(s, "\n"); |
| 2379 | gpio = 0; |
| 2380 | } |
| 2381 | } |
| 2382 | return 0; |
| 2383 | } |
| 2384 | |
| 2385 | static int dbg_gpio_open(struct inode *inode, struct file *file) |
| 2386 | { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 2387 | return single_open(file, dbg_gpio_show, &inode->i_private); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | static const struct file_operations debug_fops = { |
| 2391 | .open = dbg_gpio_open, |
| 2392 | .read = seq_read, |
| 2393 | .llseek = seq_lseek, |
| 2394 | .release = single_release, |
| 2395 | }; |
| 2396 | |
| 2397 | static int __init omap_gpio_debuginit(void) |
| 2398 | { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 2399 | (void) debugfs_create_file("omap_gpio", S_IRUGO, |
| 2400 | NULL, NULL, &debug_fops); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2401 | return 0; |
| 2402 | } |
| 2403 | late_initcall(omap_gpio_debuginit); |
| 2404 | #endif |