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