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