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