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 | 418ca1f0 | 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 | |
| 1267 | static int omap_mpuio_suspend_late(struct platform_device *pdev, pm_message_t mesg) |
| 1268 | { |
| 1269 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1270 | void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1271 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1272 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1273 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1274 | bank->saved_wakeup = __raw_readl(mask_reg); |
| 1275 | __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1276 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1277 | |
| 1278 | return 0; |
| 1279 | } |
| 1280 | |
| 1281 | static int omap_mpuio_resume_early(struct platform_device *pdev) |
| 1282 | { |
| 1283 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
| 1284 | void __iomem *mask_reg = bank->base + OMAP_MPUIO_GPIO_MASKIT; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1285 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1286 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1287 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1288 | __raw_writel(bank->saved_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1289 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1290 | |
| 1291 | return 0; |
| 1292 | } |
| 1293 | |
| 1294 | /* use platform_driver for this, now that there's no longer any |
| 1295 | * point to sys_device (other than not disturbing old code). |
| 1296 | */ |
| 1297 | static struct platform_driver omap_mpuio_driver = { |
| 1298 | .suspend_late = omap_mpuio_suspend_late, |
| 1299 | .resume_early = omap_mpuio_resume_early, |
| 1300 | .driver = { |
| 1301 | .name = "mpuio", |
| 1302 | }, |
| 1303 | }; |
| 1304 | |
| 1305 | static struct platform_device omap_mpuio_device = { |
| 1306 | .name = "mpuio", |
| 1307 | .id = -1, |
| 1308 | .dev = { |
| 1309 | .driver = &omap_mpuio_driver.driver, |
| 1310 | } |
| 1311 | /* could list the /proc/iomem resources */ |
| 1312 | }; |
| 1313 | |
| 1314 | static inline void mpuio_init(void) |
| 1315 | { |
David Brownell | fcf126d | 2007-04-02 12:46:47 -0700 | [diff] [blame] | 1316 | platform_set_drvdata(&omap_mpuio_device, &gpio_bank_1610[0]); |
| 1317 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1318 | if (platform_driver_register(&omap_mpuio_driver) == 0) |
| 1319 | (void) platform_device_register(&omap_mpuio_device); |
| 1320 | } |
| 1321 | |
| 1322 | #else |
| 1323 | static inline void mpuio_init(void) {} |
| 1324 | #endif /* 16xx */ |
| 1325 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1326 | #else |
| 1327 | |
| 1328 | extern struct irq_chip mpuio_irq_chip; |
| 1329 | |
| 1330 | #define bank_is_mpuio(bank) 0 |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1331 | static inline void mpuio_init(void) {} |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1332 | |
| 1333 | #endif |
| 1334 | |
| 1335 | /*---------------------------------------------------------------------*/ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1336 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1337 | /* REVISIT these are stupid implementations! replace by ones that |
| 1338 | * don't switch on METHOD_* and which mostly avoid spinlocks |
| 1339 | */ |
| 1340 | |
| 1341 | static int gpio_input(struct gpio_chip *chip, unsigned offset) |
| 1342 | { |
| 1343 | struct gpio_bank *bank; |
| 1344 | unsigned long flags; |
| 1345 | |
| 1346 | bank = container_of(chip, struct gpio_bank, chip); |
| 1347 | spin_lock_irqsave(&bank->lock, flags); |
| 1348 | _set_gpio_direction(bank, offset, 1); |
| 1349 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
| 1353 | static int gpio_get(struct gpio_chip *chip, unsigned offset) |
| 1354 | { |
David Brownell | 0b84b5c | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 1355 | return __omap_get_gpio_datain(chip->base + offset); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) |
| 1359 | { |
| 1360 | struct gpio_bank *bank; |
| 1361 | unsigned long flags; |
| 1362 | |
| 1363 | bank = container_of(chip, struct gpio_bank, chip); |
| 1364 | spin_lock_irqsave(&bank->lock, flags); |
| 1365 | _set_gpio_dataout(bank, offset, value); |
| 1366 | _set_gpio_direction(bank, offset, 0); |
| 1367 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
| 1371 | static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 1372 | { |
| 1373 | struct gpio_bank *bank; |
| 1374 | unsigned long flags; |
| 1375 | |
| 1376 | bank = container_of(chip, struct gpio_bank, chip); |
| 1377 | spin_lock_irqsave(&bank->lock, flags); |
| 1378 | _set_gpio_dataout(bank, offset, value); |
| 1379 | spin_unlock_irqrestore(&bank->lock, flags); |
| 1380 | } |
| 1381 | |
David Brownell | a007b70 | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 1382 | static int gpio_2irq(struct gpio_chip *chip, unsigned offset) |
| 1383 | { |
| 1384 | struct gpio_bank *bank; |
| 1385 | |
| 1386 | bank = container_of(chip, struct gpio_bank, chip); |
| 1387 | return bank->virtual_irq_start + offset; |
| 1388 | } |
| 1389 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1390 | /*---------------------------------------------------------------------*/ |
| 1391 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1392 | static int initialized; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1393 | #if !(defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4)) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1394 | static struct clk * gpio_ick; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1395 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1396 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1397 | #if defined(CONFIG_ARCH_OMAP2) |
| 1398 | static struct clk * gpio_fck; |
| 1399 | #endif |
| 1400 | |
| 1401 | #if defined(CONFIG_ARCH_OMAP2430) |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1402 | static struct clk * gpio5_ick; |
| 1403 | static struct clk * gpio5_fck; |
| 1404 | #endif |
| 1405 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1406 | #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4) |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1407 | static struct clk *gpio_iclks[OMAP34XX_NR_GPIOS]; |
| 1408 | #endif |
| 1409 | |
David Brownell | 8ba55c5 | 2008-02-26 11:10:50 -0800 | [diff] [blame] | 1410 | /* This lock class tells lockdep that GPIO irqs are in a different |
| 1411 | * category than their parents, so it won't report false recursion. |
| 1412 | */ |
| 1413 | static struct lock_class_key gpio_lock_class; |
| 1414 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1415 | static int __init _omap_gpio_init(void) |
| 1416 | { |
| 1417 | int i; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1418 | int gpio = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1419 | struct gpio_bank *bank; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1420 | char clk_name[11]; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1421 | |
| 1422 | initialized = 1; |
| 1423 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1424 | #if defined(CONFIG_ARCH_OMAP1) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1425 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1426 | gpio_ick = clk_get(NULL, "arm_gpio_ck"); |
| 1427 | if (IS_ERR(gpio_ick)) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1428 | printk("Could not get arm_gpio_ck\n"); |
| 1429 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 1430 | clk_enable(gpio_ick); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1431 | } |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1432 | #endif |
| 1433 | #if defined(CONFIG_ARCH_OMAP2) |
| 1434 | if (cpu_class_is_omap2()) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1435 | gpio_ick = clk_get(NULL, "gpios_ick"); |
| 1436 | if (IS_ERR(gpio_ick)) |
| 1437 | printk("Could not get gpios_ick\n"); |
| 1438 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 1439 | clk_enable(gpio_ick); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1440 | gpio_fck = clk_get(NULL, "gpios_fck"); |
Komal Shah | 1630b52 | 2006-09-25 12:51:08 +0300 | [diff] [blame] | 1441 | if (IS_ERR(gpio_fck)) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1442 | printk("Could not get gpios_fck\n"); |
| 1443 | else |
Tony Lindgren | 30ff720 | 2006-01-17 15:33:51 -0800 | [diff] [blame] | 1444 | clk_enable(gpio_fck); |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1445 | |
| 1446 | /* |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1447 | * On 2430 & 3430 GPIO 5 uses CORE L4 ICLK |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1448 | */ |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1449 | #if defined(CONFIG_ARCH_OMAP2430) |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1450 | if (cpu_is_omap2430()) { |
| 1451 | gpio5_ick = clk_get(NULL, "gpio5_ick"); |
| 1452 | if (IS_ERR(gpio5_ick)) |
| 1453 | printk("Could not get gpio5_ick\n"); |
| 1454 | else |
| 1455 | clk_enable(gpio5_ick); |
| 1456 | gpio5_fck = clk_get(NULL, "gpio5_fck"); |
| 1457 | if (IS_ERR(gpio5_fck)) |
| 1458 | printk("Could not get gpio5_fck\n"); |
| 1459 | else |
| 1460 | clk_enable(gpio5_fck); |
| 1461 | } |
| 1462 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1463 | } |
| 1464 | #endif |
| 1465 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1466 | #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_ARCH_OMAP4) |
| 1467 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1468 | for (i = 0; i < OMAP34XX_NR_GPIOS; i++) { |
| 1469 | sprintf(clk_name, "gpio%d_ick", i + 1); |
| 1470 | gpio_iclks[i] = clk_get(NULL, clk_name); |
| 1471 | if (IS_ERR(gpio_iclks[i])) |
| 1472 | printk(KERN_ERR "Could not get %s\n", clk_name); |
| 1473 | else |
| 1474 | clk_enable(gpio_iclks[i]); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | #endif |
| 1478 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1479 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1480 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 1481 | if (cpu_is_omap15xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1482 | printk(KERN_INFO "OMAP1510 GPIO hardware\n"); |
| 1483 | gpio_bank_count = 2; |
| 1484 | gpio_bank = gpio_bank_1510; |
| 1485 | } |
| 1486 | #endif |
| 1487 | #if defined(CONFIG_ARCH_OMAP16XX) |
| 1488 | if (cpu_is_omap16xx()) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1489 | u32 rev; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1490 | |
| 1491 | gpio_bank_count = 5; |
| 1492 | gpio_bank = gpio_bank_1610; |
Russell King | 7c7095a | 2008-09-05 15:49:14 +0100 | [diff] [blame] | 1493 | rev = __raw_readw(gpio_bank[1].base + OMAP1610_GPIO_REVISION); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1494 | printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n", |
| 1495 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1496 | } |
| 1497 | #endif |
| 1498 | #ifdef CONFIG_ARCH_OMAP730 |
| 1499 | if (cpu_is_omap730()) { |
| 1500 | printk(KERN_INFO "OMAP730 GPIO hardware\n"); |
| 1501 | gpio_bank_count = 7; |
| 1502 | gpio_bank = gpio_bank_730; |
| 1503 | } |
| 1504 | #endif |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 1505 | #ifdef CONFIG_ARCH_OMAP850 |
| 1506 | if (cpu_is_omap850()) { |
| 1507 | printk(KERN_INFO "OMAP850 GPIO hardware\n"); |
| 1508 | gpio_bank_count = 7; |
| 1509 | gpio_bank = gpio_bank_850; |
| 1510 | } |
| 1511 | #endif |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1512 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1513 | #ifdef CONFIG_ARCH_OMAP24XX |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1514 | if (cpu_is_omap242x()) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1515 | int rev; |
| 1516 | |
| 1517 | gpio_bank_count = 4; |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1518 | gpio_bank = gpio_bank_242x; |
Russell King | 7c7095a | 2008-09-05 15:49:14 +0100 | [diff] [blame] | 1519 | rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1520 | printk(KERN_INFO "OMAP242x GPIO hardware version %d.%d\n", |
| 1521 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1522 | } |
| 1523 | if (cpu_is_omap243x()) { |
| 1524 | int rev; |
| 1525 | |
| 1526 | gpio_bank_count = 5; |
| 1527 | gpio_bank = gpio_bank_243x; |
Russell King | 7c7095a | 2008-09-05 15:49:14 +0100 | [diff] [blame] | 1528 | rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1529 | printk(KERN_INFO "OMAP243x GPIO hardware version %d.%d\n", |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1530 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1531 | } |
| 1532 | #endif |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1533 | #ifdef CONFIG_ARCH_OMAP34XX |
| 1534 | if (cpu_is_omap34xx()) { |
| 1535 | int rev; |
| 1536 | |
| 1537 | gpio_bank_count = OMAP34XX_NR_GPIOS; |
| 1538 | gpio_bank = gpio_bank_34xx; |
Russell King | 7c7095a | 2008-09-05 15:49:14 +0100 | [diff] [blame] | 1539 | rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1540 | printk(KERN_INFO "OMAP34xx GPIO hardware version %d.%d\n", |
| 1541 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1542 | } |
| 1543 | #endif |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1544 | #ifdef CONFIG_ARCH_OMAP4 |
| 1545 | if (cpu_is_omap44xx()) { |
| 1546 | int rev; |
| 1547 | |
| 1548 | gpio_bank_count = OMAP34XX_NR_GPIOS; |
| 1549 | gpio_bank = gpio_bank_44xx; |
| 1550 | rev = __raw_readl(gpio_bank[0].base + OMAP24XX_GPIO_REVISION); |
| 1551 | printk(KERN_INFO "OMAP44xx GPIO hardware version %d.%d\n", |
| 1552 | (rev >> 4) & 0x0f, rev & 0x0f); |
| 1553 | } |
| 1554 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1555 | for (i = 0; i < gpio_bank_count; i++) { |
| 1556 | int j, gpio_count = 16; |
| 1557 | |
| 1558 | bank = &gpio_bank[i]; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1559 | spin_lock_init(&bank->lock); |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1560 | if (bank_is_mpuio(bank)) |
Russell King | 7c7095a | 2008-09-05 15:49:14 +0100 | [diff] [blame] | 1561 | __raw_writew(0xffff, bank->base + OMAP_MPUIO_GPIO_MASKIT); |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1562 | if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1563 | __raw_writew(0xffff, bank->base + OMAP1510_GPIO_INT_MASK); |
| 1564 | __raw_writew(0x0000, bank->base + OMAP1510_GPIO_INT_STATUS); |
| 1565 | } |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1566 | if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1567 | __raw_writew(0x0000, bank->base + OMAP1610_GPIO_IRQENABLE1); |
| 1568 | __raw_writew(0xffff, bank->base + OMAP1610_GPIO_IRQSTATUS1); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1569 | __raw_writew(0x0014, bank->base + OMAP1610_GPIO_SYSCONFIG); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1570 | } |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 1571 | if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_730) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1572 | __raw_writel(0xffffffff, bank->base + OMAP730_GPIO_INT_MASK); |
| 1573 | __raw_writel(0x00000000, bank->base + OMAP730_GPIO_INT_STATUS); |
| 1574 | |
| 1575 | gpio_count = 32; /* 730 has 32-bit GPIOs */ |
| 1576 | } |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1577 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1578 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \ |
| 1579 | defined(CONFIG_ARCH_OMAP4) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1580 | if (bank->method == METHOD_GPIO_24XX) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1581 | static const u32 non_wakeup_gpios[] = { |
| 1582 | 0xe203ffc0, 0x08700040 |
| 1583 | }; |
| 1584 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1585 | __raw_writel(0x00000000, bank->base + OMAP24XX_GPIO_IRQENABLE1); |
| 1586 | __raw_writel(0xffffffff, bank->base + OMAP24XX_GPIO_IRQSTATUS1); |
Juha Yrjola | 14f1c3b | 2006-12-06 17:13:48 -0800 | [diff] [blame] | 1587 | __raw_writew(0x0015, bank->base + OMAP24XX_GPIO_SYSCONFIG); |
| 1588 | |
| 1589 | /* Initialize interface clock ungated, module enabled */ |
| 1590 | __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1591 | if (i < ARRAY_SIZE(non_wakeup_gpios)) |
| 1592 | bank->non_wakeup_gpios = non_wakeup_gpios[i]; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1593 | gpio_count = 32; |
| 1594 | } |
| 1595 | #endif |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1596 | |
| 1597 | /* REVISIT eventually switch from OMAP-specific gpio structs |
| 1598 | * over to the generic ones |
| 1599 | */ |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 1600 | bank->chip.request = omap_gpio_request; |
| 1601 | bank->chip.free = omap_gpio_free; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1602 | bank->chip.direction_input = gpio_input; |
| 1603 | bank->chip.get = gpio_get; |
| 1604 | bank->chip.direction_output = gpio_output; |
| 1605 | bank->chip.set = gpio_set; |
David Brownell | a007b70 | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 1606 | bank->chip.to_irq = gpio_2irq; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1607 | if (bank_is_mpuio(bank)) { |
| 1608 | bank->chip.label = "mpuio"; |
Russell King | 69114a4 | 2008-09-03 10:15:26 +0100 | [diff] [blame] | 1609 | #ifdef CONFIG_ARCH_OMAP16XX |
David Brownell | d8f388d8 | 2008-07-25 01:46:07 -0700 | [diff] [blame] | 1610 | bank->chip.dev = &omap_mpuio_device.dev; |
| 1611 | #endif |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1612 | bank->chip.base = OMAP_MPUIO(0); |
| 1613 | } else { |
| 1614 | bank->chip.label = "gpio"; |
| 1615 | bank->chip.base = gpio; |
| 1616 | gpio += gpio_count; |
| 1617 | } |
| 1618 | bank->chip.ngpio = gpio_count; |
| 1619 | |
| 1620 | gpiochip_add(&bank->chip); |
| 1621 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1622 | for (j = bank->virtual_irq_start; |
| 1623 | j < bank->virtual_irq_start + gpio_count; j++) { |
David Brownell | 8ba55c5 | 2008-02-26 11:10:50 -0800 | [diff] [blame] | 1624 | lockdep_set_class(&irq_desc[j].lock, &gpio_lock_class); |
David Brownell | 5878101 | 2006-12-06 17:14:10 -0800 | [diff] [blame] | 1625 | set_irq_chip_data(j, bank); |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1626 | if (bank_is_mpuio(bank)) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1627 | set_irq_chip(j, &mpuio_irq_chip); |
| 1628 | else |
| 1629 | set_irq_chip(j, &gpio_irq_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 1630 | set_irq_handler(j, handle_simple_irq); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1631 | set_irq_flags(j, IRQF_VALID); |
| 1632 | } |
| 1633 | set_irq_chained_handler(bank->irq, gpio_irq_handler); |
| 1634 | set_irq_data(bank->irq, bank); |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 1635 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1636 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 1637 | sprintf(clk_name, "gpio%d_dbck", i + 1); |
| 1638 | bank->dbck = clk_get(NULL, clk_name); |
| 1639 | if (IS_ERR(bank->dbck)) |
| 1640 | printk(KERN_ERR "Could not get %s\n", clk_name); |
| 1641 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | /* Enable system clock for GPIO module. |
| 1645 | * The CAM_CLK_CTRL *is* really the right place. */ |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1646 | if (cpu_is_omap16xx()) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1647 | omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, ULPD_CAM_CLK_CTRL); |
| 1648 | |
Juha Yrjola | 14f1c3b | 2006-12-06 17:13:48 -0800 | [diff] [blame] | 1649 | /* Enable autoidle for the OCP interface */ |
| 1650 | if (cpu_is_omap24xx()) |
| 1651 | omap_writel(1 << 0, 0x48019010); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1652 | if (cpu_is_omap34xx()) |
| 1653 | omap_writel(1 << 0, 0x48306814); |
Tony Lindgren | d11ac97 | 2008-01-12 15:35:04 -0800 | [diff] [blame] | 1654 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1655 | return 0; |
| 1656 | } |
| 1657 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1658 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \ |
| 1659 | defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1660 | static int omap_gpio_suspend(struct sys_device *dev, pm_message_t mesg) |
| 1661 | { |
| 1662 | int i; |
| 1663 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1664 | if (!cpu_class_is_omap2() && !cpu_is_omap16xx()) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1665 | return 0; |
| 1666 | |
| 1667 | for (i = 0; i < gpio_bank_count; i++) { |
| 1668 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1669 | void __iomem *wake_status; |
| 1670 | void __iomem *wake_clear; |
| 1671 | void __iomem *wake_set; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1672 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1673 | |
| 1674 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1675 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1676 | case METHOD_GPIO_1610: |
| 1677 | wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE; |
| 1678 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1679 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1680 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1681 | #endif |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1682 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \ |
| 1683 | defined(CONFIG_ARCH_OMAP4) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1684 | case METHOD_GPIO_24XX: |
Tero Kristo | 723fdb7 | 2008-11-26 14:35:16 -0800 | [diff] [blame] | 1685 | wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1686 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 1687 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
| 1688 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1689 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1690 | default: |
| 1691 | continue; |
| 1692 | } |
| 1693 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1694 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1695 | bank->saved_wakeup = __raw_readl(wake_status); |
| 1696 | __raw_writel(0xffffffff, wake_clear); |
| 1697 | __raw_writel(bank->suspend_wakeup, wake_set); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1698 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | return 0; |
| 1702 | } |
| 1703 | |
| 1704 | static int omap_gpio_resume(struct sys_device *dev) |
| 1705 | { |
| 1706 | int i; |
| 1707 | |
Tero Kristo | 723fdb7 | 2008-11-26 14:35:16 -0800 | [diff] [blame] | 1708 | if (!cpu_class_is_omap2() && !cpu_is_omap16xx()) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1709 | return 0; |
| 1710 | |
| 1711 | for (i = 0; i < gpio_bank_count; i++) { |
| 1712 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1713 | void __iomem *wake_clear; |
| 1714 | void __iomem *wake_set; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1715 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1716 | |
| 1717 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1718 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1719 | case METHOD_GPIO_1610: |
| 1720 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1721 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1722 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1723 | #endif |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1724 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \ |
| 1725 | defined(CONFIG_ARCH_OMAP4) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1726 | case METHOD_GPIO_24XX: |
Tony Lindgren | 0d9356c | 2006-09-25 12:41:45 +0300 | [diff] [blame] | 1727 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 1728 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1729 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1730 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1731 | default: |
| 1732 | continue; |
| 1733 | } |
| 1734 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1735 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1736 | __raw_writel(0xffffffff, wake_clear); |
| 1737 | __raw_writel(bank->saved_wakeup, wake_set); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1738 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
| 1744 | static struct sysdev_class omap_gpio_sysclass = { |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 1745 | .name = "gpio", |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1746 | .suspend = omap_gpio_suspend, |
| 1747 | .resume = omap_gpio_resume, |
| 1748 | }; |
| 1749 | |
| 1750 | static struct sys_device omap_gpio_device = { |
| 1751 | .id = 0, |
| 1752 | .cls = &omap_gpio_sysclass, |
| 1753 | }; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1754 | |
| 1755 | #endif |
| 1756 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1757 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \ |
| 1758 | defined(CONFIG_ARCH_OMAP4) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1759 | |
| 1760 | static int workaround_enabled; |
| 1761 | |
| 1762 | void omap2_gpio_prepare_for_retention(void) |
| 1763 | { |
| 1764 | int i, c = 0; |
| 1765 | |
| 1766 | /* Remove triggering for all non-wakeup GPIOs. Otherwise spurious |
| 1767 | * IRQs will be generated. See OMAP2420 Errata item 1.101. */ |
| 1768 | for (i = 0; i < gpio_bank_count; i++) { |
| 1769 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1770 | u32 l1, l2; |
| 1771 | |
| 1772 | if (!(bank->enabled_non_wakeup_gpios)) |
| 1773 | continue; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1774 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \ |
| 1775 | defined(CONFIG_ARCH_OMAP4) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1776 | bank->saved_datain = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN); |
| 1777 | l1 = __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 1778 | l2 = __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1779 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1780 | bank->saved_fallingdetect = l1; |
| 1781 | bank->saved_risingdetect = l2; |
| 1782 | l1 &= ~bank->enabled_non_wakeup_gpios; |
| 1783 | l2 &= ~bank->enabled_non_wakeup_gpios; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1784 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \ |
| 1785 | defined(CONFIG_ARCH_OMAP4) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1786 | __raw_writel(l1, bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 1787 | __raw_writel(l2, bank->base + OMAP24XX_GPIO_RISINGDETECT); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1788 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1789 | c++; |
| 1790 | } |
| 1791 | if (!c) { |
| 1792 | workaround_enabled = 0; |
| 1793 | return; |
| 1794 | } |
| 1795 | workaround_enabled = 1; |
| 1796 | } |
| 1797 | |
| 1798 | void omap2_gpio_resume_after_retention(void) |
| 1799 | { |
| 1800 | int i; |
| 1801 | |
| 1802 | if (!workaround_enabled) |
| 1803 | return; |
| 1804 | for (i = 0; i < gpio_bank_count; i++) { |
| 1805 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1806 | u32 l; |
| 1807 | |
| 1808 | if (!(bank->enabled_non_wakeup_gpios)) |
| 1809 | continue; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1810 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \ |
| 1811 | defined(CONFIG_ARCH_OMAP4) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1812 | __raw_writel(bank->saved_fallingdetect, |
| 1813 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 1814 | __raw_writel(bank->saved_risingdetect, |
| 1815 | bank->base + OMAP24XX_GPIO_RISINGDETECT); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1816 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1817 | /* Check if any of the non-wakeup interrupt GPIOs have changed |
| 1818 | * state. If so, generate an IRQ by software. This is |
| 1819 | * horribly racy, but it's the best we can do to work around |
| 1820 | * this silicon bug. */ |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1821 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \ |
| 1822 | defined(CONFIG_ARCH_OMAP4) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1823 | l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1824 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1825 | l ^= bank->saved_datain; |
| 1826 | l &= bank->non_wakeup_gpios; |
| 1827 | if (l) { |
| 1828 | u32 old0, old1; |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1829 | #if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \ |
| 1830 | defined(CONFIG_ARCH_OMAP4) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1831 | old0 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 1832 | old1 = __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 1833 | __raw_writel(old0 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 1834 | __raw_writel(old1 | l, bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 1835 | __raw_writel(old0, bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 1836 | __raw_writel(old1, bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1837 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1838 | } |
| 1839 | } |
| 1840 | |
| 1841 | } |
| 1842 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1843 | #endif |
| 1844 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1845 | /* |
| 1846 | * This may get called early from board specific init |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1847 | * for boards that have interrupts routed via FPGA. |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1848 | */ |
David Brownell | 277d58e | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1849 | int __init omap_gpio_init(void) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1850 | { |
| 1851 | if (!initialized) |
| 1852 | return _omap_gpio_init(); |
| 1853 | else |
| 1854 | return 0; |
| 1855 | } |
| 1856 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1857 | static int __init omap_gpio_sysinit(void) |
| 1858 | { |
| 1859 | int ret = 0; |
| 1860 | |
| 1861 | if (!initialized) |
| 1862 | ret = _omap_gpio_init(); |
| 1863 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1864 | mpuio_init(); |
| 1865 | |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1866 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \ |
| 1867 | defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4) |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1868 | if (cpu_is_omap16xx() || cpu_class_is_omap2()) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1869 | if (ret == 0) { |
| 1870 | ret = sysdev_class_register(&omap_gpio_sysclass); |
| 1871 | if (ret == 0) |
| 1872 | ret = sysdev_register(&omap_gpio_device); |
| 1873 | } |
| 1874 | } |
| 1875 | #endif |
| 1876 | |
| 1877 | return ret; |
| 1878 | } |
| 1879 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1880 | arch_initcall(omap_gpio_sysinit); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1881 | |
| 1882 | |
| 1883 | #ifdef CONFIG_DEBUG_FS |
| 1884 | |
| 1885 | #include <linux/debugfs.h> |
| 1886 | #include <linux/seq_file.h> |
| 1887 | |
| 1888 | static int gpio_is_input(struct gpio_bank *bank, int mask) |
| 1889 | { |
| 1890 | void __iomem *reg = bank->base; |
| 1891 | |
| 1892 | switch (bank->method) { |
| 1893 | case METHOD_MPUIO: |
| 1894 | reg += OMAP_MPUIO_IO_CNTL; |
| 1895 | break; |
| 1896 | case METHOD_GPIO_1510: |
| 1897 | reg += OMAP1510_GPIO_DIR_CONTROL; |
| 1898 | break; |
| 1899 | case METHOD_GPIO_1610: |
| 1900 | reg += OMAP1610_GPIO_DIRECTION; |
| 1901 | break; |
| 1902 | case METHOD_GPIO_730: |
| 1903 | reg += OMAP730_GPIO_DIR_CONTROL; |
| 1904 | break; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 1905 | case METHOD_GPIO_850: |
| 1906 | reg += OMAP850_GPIO_DIR_CONTROL; |
| 1907 | break; |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1908 | case METHOD_GPIO_24XX: |
| 1909 | reg += OMAP24XX_GPIO_OE; |
| 1910 | break; |
| 1911 | } |
| 1912 | return __raw_readl(reg) & mask; |
| 1913 | } |
| 1914 | |
| 1915 | |
| 1916 | static int dbg_gpio_show(struct seq_file *s, void *unused) |
| 1917 | { |
| 1918 | unsigned i, j, gpio; |
| 1919 | |
| 1920 | for (i = 0, gpio = 0; i < gpio_bank_count; i++) { |
| 1921 | struct gpio_bank *bank = gpio_bank + i; |
| 1922 | unsigned bankwidth = 16; |
| 1923 | u32 mask = 1; |
| 1924 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1925 | if (bank_is_mpuio(bank)) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1926 | gpio = OMAP_MPUIO(0); |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 1927 | else if (cpu_class_is_omap2() || cpu_is_omap730() || |
| 1928 | cpu_is_omap850()) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1929 | bankwidth = 32; |
| 1930 | |
| 1931 | for (j = 0; j < bankwidth; j++, gpio++, mask <<= 1) { |
| 1932 | unsigned irq, value, is_in, irqstat; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1933 | const char *label; |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1934 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1935 | label = gpiochip_is_requested(&bank->chip, j); |
| 1936 | if (!label) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1937 | continue; |
| 1938 | |
| 1939 | irq = bank->virtual_irq_start + j; |
David Brownell | 0b84b5c | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 1940 | value = gpio_get_value(gpio); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1941 | is_in = gpio_is_input(bank, mask); |
| 1942 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1943 | if (bank_is_mpuio(bank)) |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1944 | seq_printf(s, "MPUIO %2d ", j); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1945 | else |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1946 | seq_printf(s, "GPIO %3d ", gpio); |
Jarkko Nikula | 21c867f | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 1947 | seq_printf(s, "(%-20.20s): %s %s", |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1948 | label, |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1949 | is_in ? "in " : "out", |
| 1950 | value ? "hi" : "lo"); |
| 1951 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1952 | /* FIXME for at least omap2, show pullup/pulldown state */ |
| 1953 | |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1954 | irqstat = irq_desc[irq].status; |
Tony Lindgren | 3a26e33 | 2009-01-15 13:09:53 +0200 | [diff] [blame] | 1955 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP24XX) || \ |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame^] | 1956 | defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP4) |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1957 | if (is_in && ((bank->suspend_wakeup & mask) |
| 1958 | || irqstat & IRQ_TYPE_SENSE_MASK)) { |
| 1959 | char *trigger = NULL; |
| 1960 | |
| 1961 | switch (irqstat & IRQ_TYPE_SENSE_MASK) { |
| 1962 | case IRQ_TYPE_EDGE_FALLING: |
| 1963 | trigger = "falling"; |
| 1964 | break; |
| 1965 | case IRQ_TYPE_EDGE_RISING: |
| 1966 | trigger = "rising"; |
| 1967 | break; |
| 1968 | case IRQ_TYPE_EDGE_BOTH: |
| 1969 | trigger = "bothedge"; |
| 1970 | break; |
| 1971 | case IRQ_TYPE_LEVEL_LOW: |
| 1972 | trigger = "low"; |
| 1973 | break; |
| 1974 | case IRQ_TYPE_LEVEL_HIGH: |
| 1975 | trigger = "high"; |
| 1976 | break; |
| 1977 | case IRQ_TYPE_NONE: |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1978 | trigger = "(?)"; |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1979 | break; |
| 1980 | } |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 1981 | seq_printf(s, ", irq-%d %-8s%s", |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1982 | irq, trigger, |
| 1983 | (bank->suspend_wakeup & mask) |
| 1984 | ? " wakeup" : ""); |
| 1985 | } |
Tony Lindgren | 3a26e33 | 2009-01-15 13:09:53 +0200 | [diff] [blame] | 1986 | #endif |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1987 | seq_printf(s, "\n"); |
| 1988 | } |
| 1989 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1990 | if (bank_is_mpuio(bank)) { |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 1991 | seq_printf(s, "\n"); |
| 1992 | gpio = 0; |
| 1993 | } |
| 1994 | } |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
| 1998 | static int dbg_gpio_open(struct inode *inode, struct file *file) |
| 1999 | { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 2000 | return single_open(file, dbg_gpio_show, &inode->i_private); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | static const struct file_operations debug_fops = { |
| 2004 | .open = dbg_gpio_open, |
| 2005 | .read = seq_read, |
| 2006 | .llseek = seq_lseek, |
| 2007 | .release = single_release, |
| 2008 | }; |
| 2009 | |
| 2010 | static int __init omap_gpio_debuginit(void) |
| 2011 | { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 2012 | (void) debugfs_create_file("omap_gpio", S_IRUGO, |
| 2013 | NULL, NULL, &debug_fops); |
David Brownell | b9772a2 | 2006-12-06 17:13:53 -0800 | [diff] [blame] | 2014 | return 0; |
| 2015 | } |
| 2016 | late_initcall(omap_gpio_debuginit); |
| 2017 | #endif |