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