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