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