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