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