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