Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1 | /* |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 2 | * Support functions for OMAP GPIO |
| 3 | * |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 4 | * Copyright (C) 2003-2005 Nokia Corporation |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 5 | * Written by Juha Yrjölä <juha.yrjola@nokia.com> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 6 | * |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 7 | * Copyright (C) 2009 Texas Instruments |
| 8 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
| 9 | * |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 18 | #include <linux/syscore_ops.h> |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 19 | #include <linux/err.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 20 | #include <linux/clk.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 21 | #include <linux/io.h> |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 22 | #include <linux/slab.h> |
| 23 | #include <linux/pm_runtime.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 24 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 25 | #include <mach/hardware.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 26 | #include <asm/irq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/irqs.h> |
Russell King | 1bc857f | 2011-07-26 10:54:55 +0100 | [diff] [blame] | 28 | #include <asm/gpio.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 29 | #include <asm/mach/irq.h> |
| 30 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 31 | struct gpio_bank { |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 32 | unsigned long pbase; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 33 | void __iomem *base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 34 | u16 irq; |
| 35 | u16 virtual_irq_start; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 36 | int method; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 37 | u32 suspend_wakeup; |
Janusz Krzysztofik | 78a4315 | 2011-08-23 13:42:24 +0200 | [diff] [blame] | 38 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 39 | u32 saved_wakeup; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 40 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 41 | u32 non_wakeup_gpios; |
| 42 | u32 enabled_non_wakeup_gpios; |
| 43 | |
| 44 | u32 saved_datain; |
| 45 | u32 saved_fallingdetect; |
| 46 | u32 saved_risingdetect; |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 47 | u32 level_mask; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 48 | u32 toggle_mask; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 49 | spinlock_t lock; |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 50 | struct gpio_chip chip; |
Jouni Hogander | 89db948 | 2008-12-10 17:35:24 -0800 | [diff] [blame] | 51 | struct clk *dbck; |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 52 | u32 mod_usage; |
Kevin Hilman | 8865b9b | 2009-01-27 11:15:34 -0800 | [diff] [blame] | 53 | u32 dbck_enable_mask; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 54 | struct device *dev; |
| 55 | bool dbck_flag; |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 56 | int stride; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 57 | u32 width; |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 58 | |
| 59 | void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable); |
| 60 | |
| 61 | struct omap_gpio_reg_offs *regs; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 64 | #ifdef CONFIG_ARCH_OMAP3 |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 65 | struct omap3_gpio_regs { |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 66 | u32 irqenable1; |
| 67 | u32 irqenable2; |
| 68 | u32 wake_en; |
| 69 | u32 ctrl; |
| 70 | u32 oe; |
| 71 | u32 leveldetect0; |
| 72 | u32 leveldetect1; |
| 73 | u32 risingdetect; |
| 74 | u32 fallingdetect; |
| 75 | u32 dataout; |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | static struct omap3_gpio_regs gpio_context[OMAP34XX_NR_GPIOS]; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 79 | #endif |
| 80 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 81 | /* |
| 82 | * TODO: Cleanup gpio_bank usage as it is having information |
| 83 | * related to all instances of the device |
| 84 | */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 85 | static struct gpio_bank *gpio_bank; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 86 | |
Varadarajan, Charulatha | c95d10b | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 87 | /* TODO: Analyze removing gpio_bank_count usage from driver code */ |
| 88 | int gpio_bank_count; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 89 | |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 90 | #define GPIO_INDEX(bank, gpio) (gpio % bank->width) |
| 91 | #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio)) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 92 | |
| 93 | static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) |
| 94 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 95 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 96 | u32 l; |
| 97 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 98 | reg += bank->regs->direction; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 99 | l = __raw_readl(reg); |
| 100 | if (is_input) |
| 101 | l |= 1 << gpio; |
| 102 | else |
| 103 | l &= ~(1 << gpio); |
| 104 | __raw_writel(l, reg); |
| 105 | } |
| 106 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 107 | |
| 108 | /* set data out value using dedicate set/clear register */ |
| 109 | static void _set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, int enable) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 110 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 111 | void __iomem *reg = bank->base; |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 112 | u32 l = GPIO_BIT(bank, gpio); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 113 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 114 | if (enable) |
| 115 | reg += bank->regs->set_dataout; |
| 116 | else |
| 117 | reg += bank->regs->clr_dataout; |
| 118 | |
| 119 | __raw_writel(l, reg); |
| 120 | } |
| 121 | |
| 122 | /* set data out value using mask register */ |
| 123 | static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable) |
| 124 | { |
| 125 | void __iomem *reg = bank->base + bank->regs->dataout; |
| 126 | u32 gpio_bit = GPIO_BIT(bank, gpio); |
| 127 | u32 l; |
| 128 | |
| 129 | l = __raw_readl(reg); |
| 130 | if (enable) |
| 131 | l |= gpio_bit; |
| 132 | else |
| 133 | l &= ~gpio_bit; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 134 | __raw_writel(l, reg); |
| 135 | } |
| 136 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 137 | static int _get_gpio_datain(struct gpio_bank *bank, int gpio) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 138 | { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 139 | void __iomem *reg = bank->base + bank->regs->datain; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 140 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 141 | return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 142 | } |
| 143 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 144 | static int _get_gpio_dataout(struct gpio_bank *bank, int gpio) |
| 145 | { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 146 | void __iomem *reg = bank->base + bank->regs->dataout; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 147 | |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 148 | return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 149 | } |
| 150 | |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 151 | static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) |
| 152 | { |
| 153 | int l = __raw_readl(base + reg); |
| 154 | |
| 155 | if (set) |
| 156 | l |= mask; |
| 157 | else |
| 158 | l &= ~mask; |
| 159 | |
| 160 | __raw_writel(l, base + reg); |
| 161 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 162 | |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 163 | /** |
| 164 | * _set_gpio_debounce - low level gpio debounce time |
| 165 | * @bank: the gpio bank we're acting upon |
| 166 | * @gpio: the gpio number on this @gpio |
| 167 | * @debounce: debounce time to use |
| 168 | * |
| 169 | * OMAP's debounce time is in 31us steps so we need |
| 170 | * to convert and round up to the closest unit. |
| 171 | */ |
| 172 | static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio, |
| 173 | unsigned debounce) |
| 174 | { |
Kevin Hilman | 9942da0 | 2011-04-22 12:02:05 -0700 | [diff] [blame] | 175 | void __iomem *reg; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 176 | u32 val; |
| 177 | u32 l; |
| 178 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 179 | if (!bank->dbck_flag) |
| 180 | return; |
| 181 | |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 182 | if (debounce < 32) |
| 183 | debounce = 0x01; |
| 184 | else if (debounce > 7936) |
| 185 | debounce = 0xff; |
| 186 | else |
| 187 | debounce = (debounce / 0x1f) - 1; |
| 188 | |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 189 | l = GPIO_BIT(bank, gpio); |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 190 | |
Kevin Hilman | 9942da0 | 2011-04-22 12:02:05 -0700 | [diff] [blame] | 191 | reg = bank->base + bank->regs->debounce; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 192 | __raw_writel(debounce, reg); |
| 193 | |
Kevin Hilman | 9942da0 | 2011-04-22 12:02:05 -0700 | [diff] [blame] | 194 | reg = bank->base + bank->regs->debounce_en; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 195 | val = __raw_readl(reg); |
| 196 | |
| 197 | if (debounce) { |
| 198 | val |= l; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 199 | clk_enable(bank->dbck); |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 200 | } else { |
| 201 | val &= ~l; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 202 | clk_disable(bank->dbck); |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 203 | } |
Kevin Hilman | f7ec0b0 | 2010-06-09 13:53:07 +0300 | [diff] [blame] | 204 | bank->dbck_enable_mask = val; |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 205 | |
| 206 | __raw_writel(val, reg); |
| 207 | } |
| 208 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 209 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 210 | static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio, |
| 211 | int trigger) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 212 | { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 213 | void __iomem *base = bank->base; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 214 | u32 gpio_bit = 1 << gpio; |
| 215 | |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 216 | if (cpu_is_omap44xx()) { |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 217 | _gpio_rmw(base, OMAP4_GPIO_LEVELDETECT0, gpio_bit, |
| 218 | trigger & IRQ_TYPE_LEVEL_LOW); |
| 219 | _gpio_rmw(base, OMAP4_GPIO_LEVELDETECT1, gpio_bit, |
| 220 | trigger & IRQ_TYPE_LEVEL_HIGH); |
| 221 | _gpio_rmw(base, OMAP4_GPIO_RISINGDETECT, gpio_bit, |
| 222 | trigger & IRQ_TYPE_EDGE_RISING); |
| 223 | _gpio_rmw(base, OMAP4_GPIO_FALLINGDETECT, gpio_bit, |
| 224 | trigger & IRQ_TYPE_EDGE_FALLING); |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 225 | } else { |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 226 | _gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT0, gpio_bit, |
| 227 | trigger & IRQ_TYPE_LEVEL_LOW); |
| 228 | _gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT1, gpio_bit, |
| 229 | trigger & IRQ_TYPE_LEVEL_HIGH); |
| 230 | _gpio_rmw(base, OMAP24XX_GPIO_RISINGDETECT, gpio_bit, |
| 231 | trigger & IRQ_TYPE_EDGE_RISING); |
| 232 | _gpio_rmw(base, OMAP24XX_GPIO_FALLINGDETECT, gpio_bit, |
| 233 | trigger & IRQ_TYPE_EDGE_FALLING); |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 234 | } |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 235 | if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 236 | if (cpu_is_omap44xx()) { |
Kevin Hilman | ece9528 | 2011-07-12 08:18:15 -0700 | [diff] [blame] | 237 | _gpio_rmw(base, OMAP4_GPIO_IRQWAKEN0, gpio_bit, |
| 238 | trigger != 0); |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 239 | } else { |
Chunqiu Wang | 699117a6 | 2009-06-24 17:13:39 +0000 | [diff] [blame] | 240 | /* |
| 241 | * GPIO wakeup request can only be generated on edge |
| 242 | * transitions |
| 243 | */ |
| 244 | if (trigger & IRQ_TYPE_EDGE_BOTH) |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 245 | __raw_writel(1 << gpio, bank->base |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 246 | + OMAP24XX_GPIO_SETWKUENA); |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 247 | else |
| 248 | __raw_writel(1 << gpio, bank->base |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 249 | + OMAP24XX_GPIO_CLEARWKUENA); |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 250 | } |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame] | 251 | } |
Ambresh K | 55b220c | 2011-06-15 13:40:45 -0700 | [diff] [blame] | 252 | /* This part needs to be executed always for OMAP{34xx, 44xx} */ |
| 253 | if (cpu_is_omap34xx() || cpu_is_omap44xx() || |
| 254 | (bank->non_wakeup_gpios & gpio_bit)) { |
Chunqiu Wang | 699117a6 | 2009-06-24 17:13:39 +0000 | [diff] [blame] | 255 | /* |
| 256 | * Log the edge gpio and manually trigger the IRQ |
| 257 | * after resume if the input level changes |
| 258 | * to avoid irq lost during PER RET/OFF mode |
| 259 | * Applies for omap2 non-wakeup gpio and all omap3 gpios |
| 260 | */ |
| 261 | if (trigger & IRQ_TYPE_EDGE_BOTH) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 262 | bank->enabled_non_wakeup_gpios |= gpio_bit; |
| 263 | else |
| 264 | bank->enabled_non_wakeup_gpios &= ~gpio_bit; |
| 265 | } |
Kevin Hilman | 5eb3bb9 | 2007-05-05 11:40:29 -0700 | [diff] [blame] | 266 | |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 267 | if (cpu_is_omap44xx()) { |
| 268 | bank->level_mask = |
| 269 | __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) | |
| 270 | __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT1); |
| 271 | } else { |
| 272 | bank->level_mask = |
| 273 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0) | |
| 274 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 275 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 276 | } |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 277 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 278 | |
Uwe Kleine-König | 9198bcd | 2010-01-29 14:20:05 -0800 | [diff] [blame] | 279 | #ifdef CONFIG_ARCH_OMAP1 |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 280 | /* |
| 281 | * This only applies to chips that can't do both rising and falling edge |
| 282 | * detection at once. For all other chips, this function is a noop. |
| 283 | */ |
| 284 | static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio) |
| 285 | { |
| 286 | void __iomem *reg = bank->base; |
| 287 | u32 l = 0; |
| 288 | |
| 289 | switch (bank->method) { |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 290 | case METHOD_MPUIO: |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 291 | reg += OMAP_MPUIO_GPIO_INT_EDGE / bank->stride; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 292 | break; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 293 | #ifdef CONFIG_ARCH_OMAP15XX |
| 294 | case METHOD_GPIO_1510: |
| 295 | reg += OMAP1510_GPIO_INT_CONTROL; |
| 296 | break; |
| 297 | #endif |
| 298 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
| 299 | case METHOD_GPIO_7XX: |
| 300 | reg += OMAP7XX_GPIO_INT_CONTROL; |
| 301 | break; |
| 302 | #endif |
| 303 | default: |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | l = __raw_readl(reg); |
| 308 | if ((l >> gpio) & 1) |
| 309 | l &= ~(1 << gpio); |
| 310 | else |
| 311 | l |= 1 << gpio; |
| 312 | |
| 313 | __raw_writel(l, reg); |
| 314 | } |
Uwe Kleine-König | 9198bcd | 2010-01-29 14:20:05 -0800 | [diff] [blame] | 315 | #endif |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 316 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 317 | static int _set_gpio_triggering(struct gpio_bank *bank, int gpio, int trigger) |
| 318 | { |
| 319 | void __iomem *reg = bank->base; |
| 320 | u32 l = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 321 | |
| 322 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 323 | #ifdef CONFIG_ARCH_OMAP1 |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 324 | case METHOD_MPUIO: |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 325 | reg += OMAP_MPUIO_GPIO_INT_EDGE / bank->stride; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 326 | l = __raw_readl(reg); |
Janusz Krzysztofik | 2950157 | 2010-04-05 11:38:06 +0000 | [diff] [blame] | 327 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 328 | bank->toggle_mask |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 329 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 330 | l |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 331 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 332 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 333 | else |
| 334 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 335 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 336 | #endif |
| 337 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 338 | case METHOD_GPIO_1510: |
| 339 | reg += OMAP1510_GPIO_INT_CONTROL; |
| 340 | l = __raw_readl(reg); |
Janusz Krzysztofik | 2950157 | 2010-04-05 11:38:06 +0000 | [diff] [blame] | 341 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 342 | bank->toggle_mask |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 343 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 344 | l |= 1 << gpio; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 345 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 346 | l &= ~(1 << gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 347 | else |
| 348 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 349 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 350 | #endif |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 351 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 352 | case METHOD_GPIO_1610: |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 353 | if (gpio & 0x08) |
| 354 | reg += OMAP1610_GPIO_EDGE_CTRL2; |
| 355 | else |
| 356 | reg += OMAP1610_GPIO_EDGE_CTRL1; |
| 357 | gpio &= 0x07; |
| 358 | l = __raw_readl(reg); |
| 359 | l &= ~(3 << (gpio << 1)); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 360 | if (trigger & IRQ_TYPE_EDGE_RISING) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 361 | l |= 2 << (gpio << 1); |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 362 | if (trigger & IRQ_TYPE_EDGE_FALLING) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 363 | l |= 1 << (gpio << 1); |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 364 | if (trigger) |
| 365 | /* Enable wake-up during idle for dynamic tick */ |
| 366 | __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_SET_WAKEUPENA); |
| 367 | else |
| 368 | __raw_writel(1 << gpio, bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 369 | break; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 370 | #endif |
Alistair Buxton | b718aa8 | 2009-09-23 18:56:19 +0100 | [diff] [blame] | 371 | #if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850) |
Alistair Buxton | 7c00692 | 2009-09-22 10:02:58 +0100 | [diff] [blame] | 372 | case METHOD_GPIO_7XX: |
| 373 | reg += OMAP7XX_GPIO_INT_CONTROL; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 374 | l = __raw_readl(reg); |
Janusz Krzysztofik | 2950157 | 2010-04-05 11:38:06 +0000 | [diff] [blame] | 375 | if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 376 | bank->toggle_mask |= 1 << gpio; |
Zebediah C. McClure | 56739a6 | 2009-03-23 18:07:40 -0700 | [diff] [blame] | 377 | if (trigger & IRQ_TYPE_EDGE_RISING) |
| 378 | l |= 1 << gpio; |
| 379 | else if (trigger & IRQ_TYPE_EDGE_FALLING) |
| 380 | l &= ~(1 << gpio); |
| 381 | else |
| 382 | goto bad; |
| 383 | break; |
| 384 | #endif |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 385 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 386 | case METHOD_GPIO_24XX: |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 387 | case METHOD_GPIO_44XX: |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 388 | set_24xx_gpio_triggering(bank, gpio, trigger); |
Mika Westerberg | f7c5cc4 | 2010-12-29 13:01:31 +0200 | [diff] [blame] | 389 | return 0; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 390 | #endif |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 391 | default: |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 392 | goto bad; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 393 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 394 | __raw_writel(l, reg); |
| 395 | return 0; |
| 396 | bad: |
| 397 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 398 | } |
| 399 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 400 | static int gpio_irq_type(struct irq_data *d, unsigned type) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 401 | { |
| 402 | struct gpio_bank *bank; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 403 | unsigned gpio; |
| 404 | int retval; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 405 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 406 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 407 | if (!cpu_class_is_omap2() && d->irq > IH_MPUIO_BASE) |
| 408 | gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 409 | else |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 410 | gpio = d->irq - IH_GPIO_BASE; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 411 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 412 | if (type & ~IRQ_TYPE_SENSE_MASK) |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 413 | return -EINVAL; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 414 | |
| 415 | /* OMAP1 allows only only edge triggering */ |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 416 | if (!cpu_class_is_omap2() |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 417 | && (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 418 | return -EINVAL; |
| 419 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 420 | bank = irq_data_get_irq_chip_data(d); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 421 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 422 | retval = _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), type); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 423 | spin_unlock_irqrestore(&bank->lock, flags); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 424 | |
| 425 | if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 426 | __irq_set_handler_locked(d->irq, handle_level_irq); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 427 | else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 428 | __irq_set_handler_locked(d->irq, handle_edge_irq); |
Kevin Hilman | 672e302 | 2008-01-16 21:56:16 -0800 | [diff] [blame] | 429 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 430 | return retval; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
| 434 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 435 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 436 | |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 437 | reg += bank->regs->irqstatus; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 438 | __raw_writel(gpio_mask, reg); |
Hiroshi DOYU | bee7930 | 2006-09-25 12:41:46 +0300 | [diff] [blame] | 439 | |
| 440 | /* Workaround for clearing DSP GPIO interrupts to allow retention */ |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 441 | if (bank->regs->irqstatus2) { |
| 442 | reg = bank->base + bank->regs->irqstatus2; |
Roger Quadros | bedfd15 | 2009-04-23 11:10:50 -0700 | [diff] [blame] | 443 | __raw_writel(gpio_mask, reg); |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 444 | } |
Roger Quadros | bedfd15 | 2009-04-23 11:10:50 -0700 | [diff] [blame] | 445 | |
| 446 | /* Flush posted write for the irq status to avoid spurious interrupts */ |
| 447 | __raw_readl(reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) |
| 451 | { |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 452 | _clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 453 | } |
| 454 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 455 | static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank) |
| 456 | { |
| 457 | void __iomem *reg = bank->base; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 458 | u32 l; |
Kevin Hilman | c390aad0 | 2011-04-21 09:33:36 -0700 | [diff] [blame] | 459 | u32 mask = (1 << bank->width) - 1; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 460 | |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 461 | reg += bank->regs->irqenable; |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 462 | l = __raw_readl(reg); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 463 | if (bank->regs->irqenable_inv) |
Imre Deak | 99c4770 | 2006-06-26 16:16:07 -0700 | [diff] [blame] | 464 | l = ~l; |
| 465 | l &= mask; |
| 466 | return l; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 469 | static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 470 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 471 | void __iomem *reg = bank->base; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 472 | u32 l; |
| 473 | |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 474 | if (bank->regs->set_irqenable) { |
| 475 | reg += bank->regs->set_irqenable; |
| 476 | l = gpio_mask; |
| 477 | } else { |
| 478 | reg += bank->regs->irqenable; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 479 | l = __raw_readl(reg); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 480 | if (bank->regs->irqenable_inv) |
| 481 | l &= ~gpio_mask; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 482 | else |
| 483 | l |= gpio_mask; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 484 | } |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 485 | |
| 486 | __raw_writel(l, reg); |
| 487 | } |
| 488 | |
| 489 | static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask) |
| 490 | { |
| 491 | void __iomem *reg = bank->base; |
| 492 | u32 l; |
| 493 | |
| 494 | if (bank->regs->clr_irqenable) { |
| 495 | reg += bank->regs->clr_irqenable; |
| 496 | l = gpio_mask; |
| 497 | } else { |
| 498 | reg += bank->regs->irqenable; |
| 499 | l = __raw_readl(reg); |
| 500 | if (bank->regs->irqenable_inv) |
| 501 | l |= gpio_mask; |
| 502 | else |
| 503 | l &= ~gpio_mask; |
| 504 | } |
| 505 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 506 | __raw_writel(l, reg); |
| 507 | } |
| 508 | |
| 509 | static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable) |
| 510 | { |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 511 | _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio)); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 512 | } |
| 513 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 514 | /* |
| 515 | * Note that ENAWAKEUP needs to be enabled in GPIO_SYSCONFIG register. |
| 516 | * 1510 does not seem to have a wake-up register. If JTAG is connected |
| 517 | * to the target, system will wake up always on GPIO events. While |
| 518 | * system is running all registered GPIO interrupts need to have wake-up |
| 519 | * enabled. When system is suspended, only selected GPIO interrupts need |
| 520 | * to have wake-up enabled. |
| 521 | */ |
| 522 | static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) |
| 523 | { |
Kevin Hilman | f64ad1a | 2011-04-22 09:45:27 -0700 | [diff] [blame] | 524 | u32 gpio_bit = GPIO_BIT(bank, gpio); |
| 525 | unsigned long flags; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 526 | |
Kevin Hilman | f64ad1a | 2011-04-22 09:45:27 -0700 | [diff] [blame] | 527 | if (bank->non_wakeup_gpios & gpio_bit) { |
| 528 | dev_err(bank->dev, |
| 529 | "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 530 | return -EINVAL; |
| 531 | } |
Kevin Hilman | f64ad1a | 2011-04-22 09:45:27 -0700 | [diff] [blame] | 532 | |
| 533 | spin_lock_irqsave(&bank->lock, flags); |
| 534 | if (enable) |
| 535 | bank->suspend_wakeup |= gpio_bit; |
| 536 | else |
| 537 | bank->suspend_wakeup &= ~gpio_bit; |
| 538 | |
| 539 | spin_unlock_irqrestore(&bank->lock, flags); |
| 540 | |
| 541 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 542 | } |
| 543 | |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 544 | static void _reset_gpio(struct gpio_bank *bank, int gpio) |
| 545 | { |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 546 | _set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 547 | _set_gpio_irqenable(bank, gpio, 0); |
| 548 | _clear_gpio_irqstatus(bank, gpio); |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 549 | _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 550 | } |
| 551 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 552 | /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 553 | static int gpio_wake_enable(struct irq_data *d, unsigned int enable) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 554 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 555 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 556 | struct gpio_bank *bank; |
| 557 | int retval; |
| 558 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 559 | bank = irq_data_get_irq_chip_data(d); |
Kevin Hilman | f64ad1a | 2011-04-22 09:45:27 -0700 | [diff] [blame] | 560 | retval = _set_gpio_wakeup(bank, gpio, enable); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 561 | |
| 562 | return retval; |
| 563 | } |
| 564 | |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 565 | static int omap_gpio_request(struct gpio_chip *chip, unsigned offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 566 | { |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 567 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 568 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 569 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 570 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 571 | |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 572 | /* Set trigger to none. You need to enable the desired trigger with |
| 573 | * request_irq() or set_irq_type(). |
| 574 | */ |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 575 | _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 576 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 577 | #ifdef CONFIG_ARCH_OMAP15XX |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 578 | if (bank->method == METHOD_GPIO_1510) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 579 | void __iomem *reg; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 580 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 581 | /* Claim the pin for MPU */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 582 | reg = bank->base + OMAP1510_GPIO_PIN_CONTROL; |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 583 | __raw_writel(__raw_readl(reg) | (1 << offset), reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 584 | } |
| 585 | #endif |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 586 | if (!cpu_class_is_omap1()) { |
| 587 | if (!bank->mod_usage) { |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 588 | void __iomem *reg = bank->base; |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 589 | u32 ctrl; |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 590 | |
| 591 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) |
| 592 | reg += OMAP24XX_GPIO_CTRL; |
| 593 | else if (cpu_is_omap44xx()) |
| 594 | reg += OMAP4_GPIO_CTRL; |
| 595 | ctrl = __raw_readl(reg); |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 596 | /* Module is enabled, clocks are not gated */ |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 597 | ctrl &= 0xFFFFFFFE; |
| 598 | __raw_writel(ctrl, reg); |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 599 | } |
| 600 | bank->mod_usage |= 1 << offset; |
| 601 | } |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 602 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 603 | |
| 604 | return 0; |
| 605 | } |
| 606 | |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 607 | static void omap_gpio_free(struct gpio_chip *chip, unsigned offset) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 608 | { |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 609 | struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 610 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 611 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 612 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 613 | #ifdef CONFIG_ARCH_OMAP16XX |
| 614 | if (bank->method == METHOD_GPIO_1610) { |
| 615 | /* Disable wake-up during idle for dynamic tick */ |
| 616 | void __iomem *reg = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 617 | __raw_writel(1 << offset, reg); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 618 | } |
| 619 | #endif |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 620 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
| 621 | if (bank->method == METHOD_GPIO_24XX) { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 622 | /* Disable wake-up during idle for dynamic tick */ |
| 623 | void __iomem *reg = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 624 | __raw_writel(1 << offset, reg); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 625 | } |
| 626 | #endif |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 627 | #ifdef CONFIG_ARCH_OMAP4 |
| 628 | if (bank->method == METHOD_GPIO_44XX) { |
| 629 | /* Disable wake-up during idle for dynamic tick */ |
| 630 | void __iomem *reg = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 631 | __raw_writel(1 << offset, reg); |
| 632 | } |
| 633 | #endif |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 634 | if (!cpu_class_is_omap1()) { |
| 635 | bank->mod_usage &= ~(1 << offset); |
| 636 | if (!bank->mod_usage) { |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 637 | void __iomem *reg = bank->base; |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 638 | u32 ctrl; |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 639 | |
| 640 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) |
| 641 | reg += OMAP24XX_GPIO_CTRL; |
| 642 | else if (cpu_is_omap44xx()) |
| 643 | reg += OMAP4_GPIO_CTRL; |
| 644 | ctrl = __raw_readl(reg); |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 645 | /* Module is disabled, clocks are gated */ |
| 646 | ctrl |= 1; |
Charulatha V | 9f09686 | 2010-05-14 12:05:27 -0700 | [diff] [blame] | 647 | __raw_writel(ctrl, reg); |
Charulatha V | 058af1e | 2009-11-22 10:11:25 -0800 | [diff] [blame] | 648 | } |
| 649 | } |
Jarkko Nikula | 3ff164e | 2008-12-10 17:35:27 -0800 | [diff] [blame] | 650 | _reset_gpio(bank, bank->chip.base + offset); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 651 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /* |
| 655 | * We need to unmask the GPIO bank interrupt as soon as possible to |
| 656 | * avoid missing GPIO interrupts for other lines in the bank. |
| 657 | * Then we need to mask-read-clear-unmask the triggered GPIO lines |
| 658 | * in the bank to avoid missing nested interrupts for a GPIO line. |
| 659 | * If we wait to unmask individual GPIO lines in the bank after the |
| 660 | * line's interrupt handler has been run, we may miss some nested |
| 661 | * interrupts. |
| 662 | */ |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 663 | static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 664 | { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 665 | void __iomem *isr_reg = NULL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 666 | u32 isr; |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 667 | unsigned int gpio_irq, gpio_index; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 668 | struct gpio_bank *bank; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 669 | u32 retrigger = 0; |
| 670 | int unmasked = 0; |
Will Deacon | ee14418 | 2011-02-21 13:46:08 +0000 | [diff] [blame] | 671 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 672 | |
Will Deacon | ee14418 | 2011-02-21 13:46:08 +0000 | [diff] [blame] | 673 | chained_irq_enter(chip, desc); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 674 | |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 675 | bank = irq_get_handler_data(irq); |
Kevin Hilman | eef4bec | 2011-04-21 09:17:35 -0700 | [diff] [blame] | 676 | isr_reg = bank->base + bank->regs->irqstatus; |
Evgeny Kuznetsov | b1cc4c5 | 2010-12-07 16:25:40 -0800 | [diff] [blame] | 677 | |
| 678 | if (WARN_ON(!isr_reg)) |
| 679 | goto exit; |
| 680 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 681 | while(1) { |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 682 | u32 isr_saved, level_mask = 0; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 683 | u32 enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 684 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 685 | enabled = _get_gpio_irqbank_mask(bank); |
| 686 | isr_saved = isr = __raw_readl(isr_reg) & enabled; |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 687 | |
| 688 | if (cpu_is_omap15xx() && (bank->method == METHOD_MPUIO)) |
| 689 | isr &= 0x0000ffff; |
| 690 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 691 | if (cpu_class_is_omap2()) { |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 692 | level_mask = bank->level_mask & enabled; |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 693 | } |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 694 | |
| 695 | /* clear edge sensitive interrupts before handler(s) are |
| 696 | called so that we don't miss any interrupt occurred while |
| 697 | executing them */ |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 698 | _disable_gpio_irqbank(bank, isr_saved & ~level_mask); |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 699 | _clear_gpio_irqbank(bank, isr_saved & ~level_mask); |
Kevin Hilman | 28f3b5a | 2011-04-21 09:53:06 -0700 | [diff] [blame] | 700 | _enable_gpio_irqbank(bank, isr_saved & ~level_mask); |
Tony Lindgren | 6e60e79 | 2006-04-02 17:46:23 +0100 | [diff] [blame] | 701 | |
| 702 | /* if there is only edge sensitive GPIO pin interrupts |
| 703 | configured, we could unmask GPIO bank interrupt immediately */ |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 704 | if (!level_mask && !unmasked) { |
| 705 | unmasked = 1; |
Will Deacon | ee14418 | 2011-02-21 13:46:08 +0000 | [diff] [blame] | 706 | chained_irq_exit(chip, desc); |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 707 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 708 | |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 709 | isr |= retrigger; |
| 710 | retrigger = 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 711 | if (!isr) |
| 712 | break; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 713 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 714 | gpio_irq = bank->virtual_irq_start; |
| 715 | for (; isr != 0; isr >>= 1, gpio_irq++) { |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 716 | gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq)); |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 717 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 718 | if (!(isr & 1)) |
| 719 | continue; |
Thomas Gleixner | 29454dd | 2006-07-03 02:22:22 +0200 | [diff] [blame] | 720 | |
Cory Maccarrone | 4318f36 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 721 | #ifdef CONFIG_ARCH_OMAP1 |
| 722 | /* |
| 723 | * Some chips can't respond to both rising and falling |
| 724 | * at the same time. If this irq was requested with |
| 725 | * both flags, we need to flip the ICR data for the IRQ |
| 726 | * to respond to the IRQ for the opposite direction. |
| 727 | * This will be indicated in the bank toggle_mask. |
| 728 | */ |
| 729 | if (bank->toggle_mask & (1 << gpio_index)) |
| 730 | _toggle_gpio_edge_triggering(bank, gpio_index); |
| 731 | #endif |
| 732 | |
Dmitry Baryshkov | d8aa025 | 2008-10-09 13:36:24 +0100 | [diff] [blame] | 733 | generic_handle_irq(gpio_irq); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 734 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 735 | } |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 736 | /* if bank has any level sensitive GPIO pin interrupt |
| 737 | configured, we must unmask the bank interrupt only after |
| 738 | handler(s) are executed in order to avoid spurious bank |
| 739 | interrupt */ |
Evgeny Kuznetsov | b1cc4c5 | 2010-12-07 16:25:40 -0800 | [diff] [blame] | 740 | exit: |
Imre Deak | ea6dedd | 2006-06-26 16:16:00 -0700 | [diff] [blame] | 741 | if (!unmasked) |
Will Deacon | ee14418 | 2011-02-21 13:46:08 +0000 | [diff] [blame] | 742 | chained_irq_exit(chip, desc); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 743 | } |
| 744 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 745 | static void gpio_irq_shutdown(struct irq_data *d) |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 746 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 747 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
| 748 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 749 | unsigned long flags; |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 750 | |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 751 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 752 | _reset_gpio(bank, gpio); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 753 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 4196dd6 | 2006-09-25 12:41:38 +0300 | [diff] [blame] | 754 | } |
| 755 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 756 | static void gpio_ack_irq(struct irq_data *d) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 757 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 758 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
| 759 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 760 | |
| 761 | _clear_gpio_irqstatus(bank, gpio); |
| 762 | } |
| 763 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 764 | static void gpio_mask_irq(struct irq_data *d) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 765 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 766 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
| 767 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 768 | unsigned long flags; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 769 | |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 770 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 771 | _set_gpio_irqenable(bank, gpio, 0); |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 772 | _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 773 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 774 | } |
| 775 | |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 776 | static void gpio_unmask_irq(struct irq_data *d) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 777 | { |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 778 | unsigned int gpio = d->irq - IH_GPIO_BASE; |
| 779 | struct gpio_bank *bank = irq_data_get_irq_chip_data(d); |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 780 | unsigned int irq_mask = GPIO_BIT(bank, gpio); |
Thomas Gleixner | 8c04a17 | 2011-03-24 12:40:15 +0100 | [diff] [blame] | 781 | u32 trigger = irqd_get_trigger_type(d); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 782 | unsigned long flags; |
Kevin Hilman | 55b6019 | 2009-06-04 15:57:10 -0700 | [diff] [blame] | 783 | |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 784 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | 55b6019 | 2009-06-04 15:57:10 -0700 | [diff] [blame] | 785 | if (trigger) |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 786 | _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger); |
Kevin Hilman | b144ff6 | 2008-01-16 21:56:15 -0800 | [diff] [blame] | 787 | |
| 788 | /* For level-triggered GPIOs, the clearing must be done after |
| 789 | * the HW source is cleared, thus after the handler has run */ |
| 790 | if (bank->level_mask & irq_mask) { |
| 791 | _set_gpio_irqenable(bank, gpio, 0); |
| 792 | _clear_gpio_irqstatus(bank, gpio); |
| 793 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 794 | |
Kevin Hilman | 4de8c75 | 2008-01-16 21:56:14 -0800 | [diff] [blame] | 795 | _set_gpio_irqenable(bank, gpio, 1); |
Colin Cross | 85ec7b9 | 2011-06-06 13:38:18 -0700 | [diff] [blame] | 796 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 797 | } |
| 798 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 799 | static struct irq_chip gpio_irq_chip = { |
| 800 | .name = "GPIO", |
Lennert Buytenhek | e919102 | 2010-11-29 11:17:17 +0100 | [diff] [blame] | 801 | .irq_shutdown = gpio_irq_shutdown, |
| 802 | .irq_ack = gpio_ack_irq, |
| 803 | .irq_mask = gpio_mask_irq, |
| 804 | .irq_unmask = gpio_unmask_irq, |
| 805 | .irq_set_type = gpio_irq_type, |
| 806 | .irq_set_wake = gpio_wake_enable, |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 807 | }; |
| 808 | |
| 809 | /*---------------------------------------------------------------------*/ |
| 810 | |
| 811 | #ifdef CONFIG_ARCH_OMAP1 |
| 812 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 813 | #define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO) |
| 814 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 815 | #ifdef CONFIG_ARCH_OMAP16XX |
| 816 | |
| 817 | #include <linux/platform_device.h> |
| 818 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 819 | static int omap_mpuio_suspend_noirq(struct device *dev) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 820 | { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 821 | struct platform_device *pdev = to_platform_device(dev); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 822 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 823 | void __iomem *mask_reg = bank->base + |
| 824 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 825 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 826 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 827 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 828 | bank->saved_wakeup = __raw_readl(mask_reg); |
| 829 | __raw_writel(0xffff & ~bank->suspend_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 830 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 831 | |
| 832 | return 0; |
| 833 | } |
| 834 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 835 | static int omap_mpuio_resume_noirq(struct device *dev) |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 836 | { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 837 | struct platform_device *pdev = to_platform_device(dev); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 838 | struct gpio_bank *bank = platform_get_drvdata(pdev); |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 839 | void __iomem *mask_reg = bank->base + |
| 840 | OMAP_MPUIO_GPIO_MASKIT / bank->stride; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 841 | unsigned long flags; |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 842 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 843 | spin_lock_irqsave(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 844 | __raw_writel(bank->saved_wakeup, mask_reg); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 845 | spin_unlock_irqrestore(&bank->lock, flags); |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 846 | |
| 847 | return 0; |
| 848 | } |
| 849 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 850 | static const struct dev_pm_ops omap_mpuio_dev_pm_ops = { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 851 | .suspend_noirq = omap_mpuio_suspend_noirq, |
| 852 | .resume_noirq = omap_mpuio_resume_noirq, |
| 853 | }; |
| 854 | |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 855 | /* use platform_driver for this. */ |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 856 | static struct platform_driver omap_mpuio_driver = { |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 857 | .driver = { |
| 858 | .name = "mpuio", |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 859 | .pm = &omap_mpuio_dev_pm_ops, |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 860 | }, |
| 861 | }; |
| 862 | |
| 863 | static struct platform_device omap_mpuio_device = { |
| 864 | .name = "mpuio", |
| 865 | .id = -1, |
| 866 | .dev = { |
| 867 | .driver = &omap_mpuio_driver.driver, |
| 868 | } |
| 869 | /* could list the /proc/iomem resources */ |
| 870 | }; |
| 871 | |
| 872 | static inline void mpuio_init(void) |
| 873 | { |
Charulatha V | a8be8da | 2011-04-22 16:38:16 +0530 | [diff] [blame] | 874 | struct gpio_bank *bank = &gpio_bank[0]; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 875 | platform_set_drvdata(&omap_mpuio_device, bank); |
David Brownell | fcf126d | 2007-04-02 12:46:47 -0700 | [diff] [blame] | 876 | |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 877 | if (platform_driver_register(&omap_mpuio_driver) == 0) |
| 878 | (void) platform_device_register(&omap_mpuio_device); |
| 879 | } |
| 880 | |
| 881 | #else |
| 882 | static inline void mpuio_init(void) {} |
| 883 | #endif /* 16xx */ |
| 884 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 885 | #else |
| 886 | |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 887 | #define bank_is_mpuio(bank) 0 |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 888 | static inline void mpuio_init(void) {} |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 889 | |
| 890 | #endif |
| 891 | |
| 892 | /*---------------------------------------------------------------------*/ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 893 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 894 | /* REVISIT these are stupid implementations! replace by ones that |
| 895 | * don't switch on METHOD_* and which mostly avoid spinlocks |
| 896 | */ |
| 897 | |
| 898 | static int gpio_input(struct gpio_chip *chip, unsigned offset) |
| 899 | { |
| 900 | struct gpio_bank *bank; |
| 901 | unsigned long flags; |
| 902 | |
| 903 | bank = container_of(chip, struct gpio_bank, chip); |
| 904 | spin_lock_irqsave(&bank->lock, flags); |
| 905 | _set_gpio_direction(bank, offset, 1); |
| 906 | spin_unlock_irqrestore(&bank->lock, flags); |
| 907 | return 0; |
| 908 | } |
| 909 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 910 | static int gpio_is_input(struct gpio_bank *bank, int mask) |
| 911 | { |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 912 | void __iomem *reg = bank->base + bank->regs->direction; |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 913 | |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 914 | return __raw_readl(reg) & mask; |
| 915 | } |
| 916 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 917 | static int gpio_get(struct gpio_chip *chip, unsigned offset) |
| 918 | { |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 919 | struct gpio_bank *bank; |
| 920 | void __iomem *reg; |
| 921 | int gpio; |
| 922 | u32 mask; |
| 923 | |
| 924 | gpio = chip->base + offset; |
Charulatha V | a8be8da | 2011-04-22 16:38:16 +0530 | [diff] [blame] | 925 | bank = container_of(chip, struct gpio_bank, chip); |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 926 | reg = bank->base; |
Kevin Hilman | 129fd22 | 2011-04-22 07:59:07 -0700 | [diff] [blame] | 927 | mask = GPIO_BIT(bank, gpio); |
Roger Quadros | b37c45b | 2009-08-05 16:53:24 +0300 | [diff] [blame] | 928 | |
| 929 | if (gpio_is_input(bank, mask)) |
| 930 | return _get_gpio_datain(bank, gpio); |
| 931 | else |
| 932 | return _get_gpio_dataout(bank, gpio); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | static int gpio_output(struct gpio_chip *chip, unsigned offset, int value) |
| 936 | { |
| 937 | struct gpio_bank *bank; |
| 938 | unsigned long flags; |
| 939 | |
| 940 | bank = container_of(chip, struct gpio_bank, chip); |
| 941 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 942 | bank->set_dataout(bank, offset, value); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 943 | _set_gpio_direction(bank, offset, 0); |
| 944 | spin_unlock_irqrestore(&bank->lock, flags); |
| 945 | return 0; |
| 946 | } |
| 947 | |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 948 | static int gpio_debounce(struct gpio_chip *chip, unsigned offset, |
| 949 | unsigned debounce) |
| 950 | { |
| 951 | struct gpio_bank *bank; |
| 952 | unsigned long flags; |
| 953 | |
| 954 | bank = container_of(chip, struct gpio_bank, chip); |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 955 | |
| 956 | if (!bank->dbck) { |
| 957 | bank->dbck = clk_get(bank->dev, "dbclk"); |
| 958 | if (IS_ERR(bank->dbck)) |
| 959 | dev_err(bank->dev, "Could not get gpio dbck\n"); |
| 960 | } |
| 961 | |
Felipe Balbi | 168ef3d | 2010-05-26 14:42:23 -0700 | [diff] [blame] | 962 | spin_lock_irqsave(&bank->lock, flags); |
| 963 | _set_gpio_debounce(bank, offset, debounce); |
| 964 | spin_unlock_irqrestore(&bank->lock, flags); |
| 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 969 | static void gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 970 | { |
| 971 | struct gpio_bank *bank; |
| 972 | unsigned long flags; |
| 973 | |
| 974 | bank = container_of(chip, struct gpio_bank, chip); |
| 975 | spin_lock_irqsave(&bank->lock, flags); |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 976 | bank->set_dataout(bank, offset, value); |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 977 | spin_unlock_irqrestore(&bank->lock, flags); |
| 978 | } |
| 979 | |
David Brownell | a007b70 | 2008-12-10 17:35:25 -0800 | [diff] [blame] | 980 | static int gpio_2irq(struct gpio_chip *chip, unsigned offset) |
| 981 | { |
| 982 | struct gpio_bank *bank; |
| 983 | |
| 984 | bank = container_of(chip, struct gpio_bank, chip); |
| 985 | return bank->virtual_irq_start + offset; |
| 986 | } |
| 987 | |
David Brownell | 52e3134 | 2008-03-03 12:43:23 -0800 | [diff] [blame] | 988 | /*---------------------------------------------------------------------*/ |
| 989 | |
Tony Lindgren | 9a74805 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 990 | static void __init omap_gpio_show_rev(struct gpio_bank *bank) |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 991 | { |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 992 | static bool called; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 993 | u32 rev; |
| 994 | |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 995 | if (called || bank->regs->revision == USHRT_MAX) |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 996 | return; |
| 997 | |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 998 | rev = __raw_readw(bank->base + bank->regs->revision); |
| 999 | pr_info("OMAP GPIO hardware version %d.%d\n", |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1000 | (rev >> 4) & 0x0f, rev & 0x0f); |
Kevin Hilman | e5ff444 | 2011-04-22 14:37:16 -0700 | [diff] [blame] | 1001 | |
| 1002 | called = true; |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
David Brownell | 8ba55c5 | 2008-02-26 11:10:50 -0800 | [diff] [blame] | 1005 | /* This lock class tells lockdep that GPIO irqs are in a different |
| 1006 | * category than their parents, so it won't report false recursion. |
| 1007 | */ |
| 1008 | static struct lock_class_key gpio_lock_class; |
| 1009 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1010 | static inline int init_gpio_info(struct platform_device *pdev) |
| 1011 | { |
| 1012 | /* TODO: Analyze removing gpio_bank_count usage from driver code */ |
| 1013 | gpio_bank = kzalloc(gpio_bank_count * sizeof(struct gpio_bank), |
| 1014 | GFP_KERNEL); |
| 1015 | if (!gpio_bank) { |
| 1016 | dev_err(&pdev->dev, "Memory alloc failed for gpio_bank\n"); |
| 1017 | return -ENOMEM; |
| 1018 | } |
| 1019 | return 0; |
| 1020 | } |
| 1021 | |
| 1022 | /* TODO: Cleanup cpu_is_* checks */ |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1023 | static void omap_gpio_mod_init(struct gpio_bank *bank, int id) |
| 1024 | { |
| 1025 | if (cpu_class_is_omap2()) { |
| 1026 | if (cpu_is_omap44xx()) { |
| 1027 | __raw_writel(0xffffffff, bank->base + |
| 1028 | OMAP4_GPIO_IRQSTATUSCLR0); |
| 1029 | __raw_writel(0x00000000, bank->base + |
| 1030 | OMAP4_GPIO_DEBOUNCENABLE); |
| 1031 | /* Initialize interface clk ungated, module enabled */ |
| 1032 | __raw_writel(0, bank->base + OMAP4_GPIO_CTRL); |
| 1033 | } else if (cpu_is_omap34xx()) { |
| 1034 | __raw_writel(0x00000000, bank->base + |
| 1035 | OMAP24XX_GPIO_IRQENABLE1); |
| 1036 | __raw_writel(0xffffffff, bank->base + |
| 1037 | OMAP24XX_GPIO_IRQSTATUS1); |
| 1038 | __raw_writel(0x00000000, bank->base + |
| 1039 | OMAP24XX_GPIO_DEBOUNCE_EN); |
| 1040 | |
| 1041 | /* Initialize interface clk ungated, module enabled */ |
| 1042 | __raw_writel(0, bank->base + OMAP24XX_GPIO_CTRL); |
| 1043 | } else if (cpu_is_omap24xx()) { |
| 1044 | static const u32 non_wakeup_gpios[] = { |
| 1045 | 0xe203ffc0, 0x08700040 |
| 1046 | }; |
| 1047 | if (id < ARRAY_SIZE(non_wakeup_gpios)) |
| 1048 | bank->non_wakeup_gpios = non_wakeup_gpios[id]; |
| 1049 | } |
| 1050 | } else if (cpu_class_is_omap1()) { |
| 1051 | if (bank_is_mpuio(bank)) |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 1052 | __raw_writew(0xffff, bank->base + |
| 1053 | OMAP_MPUIO_GPIO_MASKIT / bank->stride); |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1054 | if (cpu_is_omap15xx() && bank->method == METHOD_GPIO_1510) { |
| 1055 | __raw_writew(0xffff, bank->base |
| 1056 | + OMAP1510_GPIO_INT_MASK); |
| 1057 | __raw_writew(0x0000, bank->base |
| 1058 | + OMAP1510_GPIO_INT_STATUS); |
| 1059 | } |
| 1060 | if (cpu_is_omap16xx() && bank->method == METHOD_GPIO_1610) { |
| 1061 | __raw_writew(0x0000, bank->base |
| 1062 | + OMAP1610_GPIO_IRQENABLE1); |
| 1063 | __raw_writew(0xffff, bank->base |
| 1064 | + OMAP1610_GPIO_IRQSTATUS1); |
| 1065 | __raw_writew(0x0014, bank->base |
| 1066 | + OMAP1610_GPIO_SYSCONFIG); |
| 1067 | |
| 1068 | /* |
| 1069 | * Enable system clock for GPIO module. |
| 1070 | * The CAM_CLK_CTRL *is* really the right place. |
| 1071 | */ |
| 1072 | omap_writel(omap_readl(ULPD_CAM_CLK_CTRL) | 0x04, |
| 1073 | ULPD_CAM_CLK_CTRL); |
| 1074 | } |
| 1075 | if (cpu_is_omap7xx() && bank->method == METHOD_GPIO_7XX) { |
| 1076 | __raw_writel(0xffffffff, bank->base |
| 1077 | + OMAP7XX_GPIO_INT_MASK); |
| 1078 | __raw_writel(0x00000000, bank->base |
| 1079 | + OMAP7XX_GPIO_INT_STATUS); |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | |
Kevin Hilman | f8b46b5 | 2011-04-21 13:23:34 -0700 | [diff] [blame] | 1084 | static __init void |
| 1085 | omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start, |
| 1086 | unsigned int num) |
| 1087 | { |
| 1088 | struct irq_chip_generic *gc; |
| 1089 | struct irq_chip_type *ct; |
| 1090 | |
| 1091 | gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base, |
| 1092 | handle_simple_irq); |
Todd Poynor | 8323374 | 2011-07-18 07:43:14 -0700 | [diff] [blame] | 1093 | if (!gc) { |
| 1094 | dev_err(bank->dev, "Memory alloc failed for gc\n"); |
| 1095 | return; |
| 1096 | } |
| 1097 | |
Kevin Hilman | f8b46b5 | 2011-04-21 13:23:34 -0700 | [diff] [blame] | 1098 | ct = gc->chip_types; |
| 1099 | |
| 1100 | /* NOTE: No ack required, reading IRQ status clears it. */ |
| 1101 | ct->chip.irq_mask = irq_gc_mask_set_bit; |
| 1102 | ct->chip.irq_unmask = irq_gc_mask_clr_bit; |
| 1103 | ct->chip.irq_set_type = gpio_irq_type; |
| 1104 | /* REVISIT: assuming only 16xx supports MPUIO wake events */ |
| 1105 | if (cpu_is_omap16xx()) |
| 1106 | ct->chip.irq_set_wake = gpio_wake_enable, |
| 1107 | |
| 1108 | ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride; |
| 1109 | irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, |
| 1110 | IRQ_NOREQUEST | IRQ_NOPROBE, 0); |
| 1111 | } |
| 1112 | |
Russell King | d52b31d | 2011-05-27 13:56:12 -0700 | [diff] [blame] | 1113 | static void __devinit omap_gpio_chip_init(struct gpio_bank *bank) |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1114 | { |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1115 | int j; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1116 | static int gpio; |
| 1117 | |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1118 | bank->mod_usage = 0; |
| 1119 | /* |
| 1120 | * REVISIT eventually switch from OMAP-specific gpio structs |
| 1121 | * over to the generic ones |
| 1122 | */ |
| 1123 | bank->chip.request = omap_gpio_request; |
| 1124 | bank->chip.free = omap_gpio_free; |
| 1125 | bank->chip.direction_input = gpio_input; |
| 1126 | bank->chip.get = gpio_get; |
| 1127 | bank->chip.direction_output = gpio_output; |
| 1128 | bank->chip.set_debounce = gpio_debounce; |
| 1129 | bank->chip.set = gpio_set; |
| 1130 | bank->chip.to_irq = gpio_2irq; |
| 1131 | if (bank_is_mpuio(bank)) { |
| 1132 | bank->chip.label = "mpuio"; |
| 1133 | #ifdef CONFIG_ARCH_OMAP16XX |
| 1134 | bank->chip.dev = &omap_mpuio_device.dev; |
| 1135 | #endif |
| 1136 | bank->chip.base = OMAP_MPUIO(0); |
| 1137 | } else { |
| 1138 | bank->chip.label = "gpio"; |
| 1139 | bank->chip.base = gpio; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1140 | gpio += bank->width; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1141 | } |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1142 | bank->chip.ngpio = bank->width; |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1143 | |
| 1144 | gpiochip_add(&bank->chip); |
| 1145 | |
| 1146 | for (j = bank->virtual_irq_start; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1147 | j < bank->virtual_irq_start + bank->width; j++) { |
Thomas Gleixner | 1475b85 | 2011-03-22 17:11:09 +0100 | [diff] [blame] | 1148 | irq_set_lockdep_class(j, &gpio_lock_class); |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 1149 | irq_set_chip_data(j, bank); |
Kevin Hilman | f8b46b5 | 2011-04-21 13:23:34 -0700 | [diff] [blame] | 1150 | if (bank_is_mpuio(bank)) { |
| 1151 | omap_mpuio_alloc_gc(bank, j, bank->width); |
| 1152 | } else { |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 1153 | irq_set_chip(j, &gpio_irq_chip); |
Kevin Hilman | f8b46b5 | 2011-04-21 13:23:34 -0700 | [diff] [blame] | 1154 | irq_set_handler(j, handle_simple_irq); |
| 1155 | set_irq_flags(j, IRQF_VALID); |
| 1156 | } |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1157 | } |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 1158 | irq_set_chained_handler(bank->irq, gpio_irq_handler); |
| 1159 | irq_set_handler_data(bank->irq, bank); |
Varadarajan, Charulatha | 2fae7fb | 2010-12-07 16:26:55 -0800 | [diff] [blame] | 1160 | } |
| 1161 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1162 | static int __devinit omap_gpio_probe(struct platform_device *pdev) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1163 | { |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1164 | static int gpio_init_done; |
| 1165 | struct omap_gpio_platform_data *pdata; |
| 1166 | struct resource *res; |
| 1167 | int id; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1168 | struct gpio_bank *bank; |
| 1169 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1170 | if (!pdev->dev.platform_data) |
| 1171 | return -EINVAL; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1172 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1173 | pdata = pdev->dev.platform_data; |
Syed Mohammed Khasim | 56a2564 | 2006-12-06 17:14:08 -0800 | [diff] [blame] | 1174 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1175 | if (!gpio_init_done) { |
| 1176 | int ret; |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1177 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1178 | ret = init_gpio_info(pdev); |
| 1179 | if (ret) |
| 1180 | return ret; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1181 | } |
| 1182 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1183 | id = pdev->id; |
| 1184 | bank = &gpio_bank[id]; |
| 1185 | |
| 1186 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1187 | if (unlikely(!res)) { |
| 1188 | dev_err(&pdev->dev, "GPIO Bank %i Invalid IRQ resource\n", id); |
| 1189 | return -ENODEV; |
| 1190 | } |
| 1191 | |
| 1192 | bank->irq = res->start; |
| 1193 | bank->virtual_irq_start = pdata->virtual_irq_start; |
| 1194 | bank->method = pdata->bank_type; |
| 1195 | bank->dev = &pdev->dev; |
| 1196 | bank->dbck_flag = pdata->dbck_flag; |
Tony Lindgren | 5de62b8 | 2010-12-07 16:26:58 -0800 | [diff] [blame] | 1197 | bank->stride = pdata->bank_stride; |
Kevin Hilman | d5f4624 | 2011-04-21 09:23:00 -0700 | [diff] [blame] | 1198 | bank->width = pdata->bank_width; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1199 | |
Kevin Hilman | fa87931a | 2011-04-20 16:31:23 -0700 | [diff] [blame] | 1200 | bank->regs = pdata->regs; |
| 1201 | |
| 1202 | if (bank->regs->set_dataout && bank->regs->clr_dataout) |
| 1203 | bank->set_dataout = _set_gpio_dataout_reg; |
| 1204 | else |
| 1205 | bank->set_dataout = _set_gpio_dataout_mask; |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1206 | |
| 1207 | spin_lock_init(&bank->lock); |
| 1208 | |
| 1209 | /* Static mapping, never released */ |
| 1210 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1211 | if (unlikely(!res)) { |
| 1212 | dev_err(&pdev->dev, "GPIO Bank %i Invalid mem resource\n", id); |
| 1213 | return -ENODEV; |
| 1214 | } |
| 1215 | |
| 1216 | bank->base = ioremap(res->start, resource_size(res)); |
| 1217 | if (!bank->base) { |
| 1218 | dev_err(&pdev->dev, "Could not ioremap gpio bank%i\n", id); |
| 1219 | return -ENOMEM; |
| 1220 | } |
| 1221 | |
| 1222 | pm_runtime_enable(bank->dev); |
| 1223 | pm_runtime_get_sync(bank->dev); |
| 1224 | |
| 1225 | omap_gpio_mod_init(bank, id); |
| 1226 | omap_gpio_chip_init(bank); |
Tony Lindgren | 9a74805 | 2010-12-07 16:26:56 -0800 | [diff] [blame] | 1227 | omap_gpio_show_rev(bank); |
Tony Lindgren | 9f7065d | 2009-10-19 15:25:20 -0700 | [diff] [blame] | 1228 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1229 | if (!gpio_init_done) |
| 1230 | gpio_init_done = 1; |
| 1231 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1232 | return 0; |
| 1233 | } |
| 1234 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1235 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 1236 | static int omap_gpio_suspend(void) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1237 | { |
| 1238 | int i; |
| 1239 | |
Syed Mohammed, Khasim | 5492fb1 | 2007-11-29 16:15:11 -0800 | [diff] [blame] | 1240 | if (!cpu_class_is_omap2() && !cpu_is_omap16xx()) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1241 | return 0; |
| 1242 | |
| 1243 | for (i = 0; i < gpio_bank_count; i++) { |
| 1244 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1245 | void __iomem *wake_status; |
| 1246 | void __iomem *wake_clear; |
| 1247 | void __iomem *wake_set; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1248 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1249 | |
| 1250 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1251 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1252 | case METHOD_GPIO_1610: |
| 1253 | wake_status = bank->base + OMAP1610_GPIO_WAKEUPENABLE; |
| 1254 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1255 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1256 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1257 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1258 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1259 | case METHOD_GPIO_24XX: |
Tero Kristo | 723fdb7 | 2008-11-26 14:35:16 -0800 | [diff] [blame] | 1260 | wake_status = bank->base + OMAP24XX_GPIO_WAKE_EN; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1261 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 1262 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
| 1263 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1264 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1265 | #ifdef CONFIG_ARCH_OMAP4 |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1266 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1267 | wake_status = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 1268 | wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 1269 | wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 1270 | break; |
| 1271 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1272 | default: |
| 1273 | continue; |
| 1274 | } |
| 1275 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1276 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1277 | bank->saved_wakeup = __raw_readl(wake_status); |
| 1278 | __raw_writel(0xffffffff, wake_clear); |
| 1279 | __raw_writel(bank->suspend_wakeup, wake_set); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1280 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 1286 | static void omap_gpio_resume(void) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1287 | { |
| 1288 | int i; |
| 1289 | |
Tero Kristo | 723fdb7 | 2008-11-26 14:35:16 -0800 | [diff] [blame] | 1290 | if (!cpu_class_is_omap2() && !cpu_is_omap16xx()) |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 1291 | return; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1292 | |
| 1293 | for (i = 0; i < gpio_bank_count; i++) { |
| 1294 | struct gpio_bank *bank = &gpio_bank[i]; |
| 1295 | void __iomem *wake_clear; |
| 1296 | void __iomem *wake_set; |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1297 | unsigned long flags; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1298 | |
| 1299 | switch (bank->method) { |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1300 | #ifdef CONFIG_ARCH_OMAP16XX |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1301 | case METHOD_GPIO_1610: |
| 1302 | wake_clear = bank->base + OMAP1610_GPIO_CLEAR_WAKEUPENA; |
| 1303 | wake_set = bank->base + OMAP1610_GPIO_SET_WAKEUPENA; |
| 1304 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1305 | #endif |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1306 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1307 | case METHOD_GPIO_24XX: |
Tony Lindgren | 0d9356c | 2006-09-25 12:41:45 +0300 | [diff] [blame] | 1308 | wake_clear = bank->base + OMAP24XX_GPIO_CLEARWKUENA; |
| 1309 | wake_set = bank->base + OMAP24XX_GPIO_SETWKUENA; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1310 | break; |
David Brownell | e5c56ed | 2006-12-06 17:13:59 -0800 | [diff] [blame] | 1311 | #endif |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1312 | #ifdef CONFIG_ARCH_OMAP4 |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1313 | case METHOD_GPIO_44XX: |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1314 | wake_clear = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 1315 | wake_set = bank->base + OMAP4_GPIO_IRQWAKEN0; |
| 1316 | break; |
| 1317 | #endif |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1318 | default: |
| 1319 | continue; |
| 1320 | } |
| 1321 | |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1322 | spin_lock_irqsave(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1323 | __raw_writel(0xffffffff, wake_clear); |
| 1324 | __raw_writel(bank->saved_wakeup, wake_set); |
David Brownell | a647253 | 2008-03-03 04:33:30 -0800 | [diff] [blame] | 1325 | spin_unlock_irqrestore(&bank->lock, flags); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1326 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1327 | } |
| 1328 | |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 1329 | static struct syscore_ops omap_gpio_syscore_ops = { |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1330 | .suspend = omap_gpio_suspend, |
| 1331 | .resume = omap_gpio_resume, |
| 1332 | }; |
| 1333 | |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1334 | #endif |
| 1335 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1336 | #ifdef CONFIG_ARCH_OMAP2PLUS |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1337 | |
| 1338 | static int workaround_enabled; |
| 1339 | |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 1340 | void omap2_gpio_prepare_for_idle(int off_mode) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1341 | { |
| 1342 | int i, c = 0; |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame] | 1343 | int min = 0; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1344 | |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame] | 1345 | if (cpu_is_omap34xx()) |
| 1346 | min = 1; |
Kevin Hilman | 43ffcd9 | 2009-01-27 11:09:24 -0800 | [diff] [blame] | 1347 | |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame] | 1348 | for (i = min; i < gpio_bank_count; i++) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1349 | struct gpio_bank *bank = &gpio_bank[i]; |
Sanjeev Premi | ca82876 | 2010-09-23 18:27:18 -0700 | [diff] [blame] | 1350 | u32 l1 = 0, l2 = 0; |
Kevin Hilman | 0aed0435 | 2010-09-22 16:06:27 -0700 | [diff] [blame] | 1351 | int j; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1352 | |
Kevin Hilman | 0aed0435 | 2010-09-22 16:06:27 -0700 | [diff] [blame] | 1353 | for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++) |
Kevin Hilman | 8865b9b | 2009-01-27 11:15:34 -0800 | [diff] [blame] | 1354 | clk_disable(bank->dbck); |
| 1355 | |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 1356 | if (!off_mode) |
Kevin Hilman | 43ffcd9 | 2009-01-27 11:09:24 -0800 | [diff] [blame] | 1357 | continue; |
| 1358 | |
| 1359 | /* If going to OFF, remove triggering for all |
| 1360 | * non-wakeup GPIOs. Otherwise spurious IRQs will be |
| 1361 | * generated. See OMAP2420 Errata item 1.101. */ |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1362 | if (!(bank->enabled_non_wakeup_gpios)) |
| 1363 | continue; |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1364 | |
| 1365 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 1366 | bank->saved_datain = __raw_readl(bank->base + |
| 1367 | OMAP24XX_GPIO_DATAIN); |
| 1368 | l1 = __raw_readl(bank->base + |
| 1369 | OMAP24XX_GPIO_FALLINGDETECT); |
| 1370 | l2 = __raw_readl(bank->base + |
| 1371 | OMAP24XX_GPIO_RISINGDETECT); |
| 1372 | } |
| 1373 | |
| 1374 | if (cpu_is_omap44xx()) { |
| 1375 | bank->saved_datain = __raw_readl(bank->base + |
| 1376 | OMAP4_GPIO_DATAIN); |
| 1377 | l1 = __raw_readl(bank->base + |
| 1378 | OMAP4_GPIO_FALLINGDETECT); |
| 1379 | l2 = __raw_readl(bank->base + |
| 1380 | OMAP4_GPIO_RISINGDETECT); |
| 1381 | } |
| 1382 | |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1383 | bank->saved_fallingdetect = l1; |
| 1384 | bank->saved_risingdetect = l2; |
| 1385 | l1 &= ~bank->enabled_non_wakeup_gpios; |
| 1386 | l2 &= ~bank->enabled_non_wakeup_gpios; |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1387 | |
| 1388 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 1389 | __raw_writel(l1, bank->base + |
| 1390 | OMAP24XX_GPIO_FALLINGDETECT); |
| 1391 | __raw_writel(l2, bank->base + |
| 1392 | OMAP24XX_GPIO_RISINGDETECT); |
| 1393 | } |
| 1394 | |
| 1395 | if (cpu_is_omap44xx()) { |
| 1396 | __raw_writel(l1, bank->base + OMAP4_GPIO_FALLINGDETECT); |
| 1397 | __raw_writel(l2, bank->base + OMAP4_GPIO_RISINGDETECT); |
| 1398 | } |
| 1399 | |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1400 | c++; |
| 1401 | } |
| 1402 | if (!c) { |
| 1403 | workaround_enabled = 0; |
| 1404 | return; |
| 1405 | } |
| 1406 | workaround_enabled = 1; |
| 1407 | } |
| 1408 | |
Kevin Hilman | 43ffcd9 | 2009-01-27 11:09:24 -0800 | [diff] [blame] | 1409 | void omap2_gpio_resume_after_idle(void) |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1410 | { |
| 1411 | int i; |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame] | 1412 | int min = 0; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1413 | |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame] | 1414 | if (cpu_is_omap34xx()) |
| 1415 | min = 1; |
| 1416 | for (i = min; i < gpio_bank_count; i++) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1417 | struct gpio_bank *bank = &gpio_bank[i]; |
Sanjeev Premi | ca82876 | 2010-09-23 18:27:18 -0700 | [diff] [blame] | 1418 | u32 l = 0, gen, gen0, gen1; |
Kevin Hilman | 0aed0435 | 2010-09-22 16:06:27 -0700 | [diff] [blame] | 1419 | int j; |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1420 | |
Kevin Hilman | 0aed0435 | 2010-09-22 16:06:27 -0700 | [diff] [blame] | 1421 | for (j = 0; j < hweight_long(bank->dbck_enable_mask); j++) |
Kevin Hilman | 8865b9b | 2009-01-27 11:15:34 -0800 | [diff] [blame] | 1422 | clk_enable(bank->dbck); |
| 1423 | |
Kevin Hilman | 43ffcd9 | 2009-01-27 11:09:24 -0800 | [diff] [blame] | 1424 | if (!workaround_enabled) |
| 1425 | continue; |
| 1426 | |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1427 | if (!(bank->enabled_non_wakeup_gpios)) |
| 1428 | continue; |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1429 | |
| 1430 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
| 1431 | __raw_writel(bank->saved_fallingdetect, |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1432 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1433 | __raw_writel(bank->saved_risingdetect, |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1434 | bank->base + OMAP24XX_GPIO_RISINGDETECT); |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1435 | l = __raw_readl(bank->base + OMAP24XX_GPIO_DATAIN); |
| 1436 | } |
| 1437 | |
| 1438 | if (cpu_is_omap44xx()) { |
| 1439 | __raw_writel(bank->saved_fallingdetect, |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1440 | bank->base + OMAP4_GPIO_FALLINGDETECT); |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1441 | __raw_writel(bank->saved_risingdetect, |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1442 | bank->base + OMAP4_GPIO_RISINGDETECT); |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1443 | l = __raw_readl(bank->base + OMAP4_GPIO_DATAIN); |
| 1444 | } |
| 1445 | |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1446 | /* Check if any of the non-wakeup interrupt GPIOs have changed |
| 1447 | * state. If so, generate an IRQ by software. This is |
| 1448 | * horribly racy, but it's the best we can do to work around |
| 1449 | * this silicon bug. */ |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1450 | l ^= bank->saved_datain; |
Tero Kristo | a118b5f | 2008-12-22 14:27:12 +0200 | [diff] [blame] | 1451 | l &= bank->enabled_non_wakeup_gpios; |
Eero Nurkkala | 82dbb9d | 2009-08-28 10:51:36 -0700 | [diff] [blame] | 1452 | |
| 1453 | /* |
| 1454 | * No need to generate IRQs for the rising edge for gpio IRQs |
| 1455 | * configured with falling edge only; and vice versa. |
| 1456 | */ |
| 1457 | gen0 = l & bank->saved_fallingdetect; |
| 1458 | gen0 &= bank->saved_datain; |
| 1459 | |
| 1460 | gen1 = l & bank->saved_risingdetect; |
| 1461 | gen1 &= ~(bank->saved_datain); |
| 1462 | |
| 1463 | /* FIXME: Consider GPIO IRQs with level detections properly! */ |
| 1464 | gen = l & (~(bank->saved_fallingdetect) & |
| 1465 | ~(bank->saved_risingdetect)); |
| 1466 | /* Consider all GPIO IRQs needed to be updated */ |
| 1467 | gen |= gen0 | gen1; |
| 1468 | |
| 1469 | if (gen) { |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1470 | u32 old0, old1; |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1471 | |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 1472 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) { |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1473 | old0 = __raw_readl(bank->base + |
| 1474 | OMAP24XX_GPIO_LEVELDETECT0); |
| 1475 | old1 = __raw_readl(bank->base + |
| 1476 | OMAP24XX_GPIO_LEVELDETECT1); |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 1477 | __raw_writel(old0 | gen, bank->base + |
Eero Nurkkala | 82dbb9d | 2009-08-28 10:51:36 -0700 | [diff] [blame] | 1478 | OMAP24XX_GPIO_LEVELDETECT0); |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 1479 | __raw_writel(old1 | gen, bank->base + |
Eero Nurkkala | 82dbb9d | 2009-08-28 10:51:36 -0700 | [diff] [blame] | 1480 | OMAP24XX_GPIO_LEVELDETECT1); |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 1481 | __raw_writel(old0, bank->base + |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1482 | OMAP24XX_GPIO_LEVELDETECT0); |
Sergio Aguirre | f00d649 | 2010-03-03 16:21:08 +0000 | [diff] [blame] | 1483 | __raw_writel(old1, bank->base + |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1484 | OMAP24XX_GPIO_LEVELDETECT1); |
| 1485 | } |
| 1486 | |
| 1487 | if (cpu_is_omap44xx()) { |
| 1488 | old0 = __raw_readl(bank->base + |
| 1489 | OMAP4_GPIO_LEVELDETECT0); |
| 1490 | old1 = __raw_readl(bank->base + |
Syed Rafiuddin | 78a1a6d | 2009-07-28 18:57:30 +0530 | [diff] [blame] | 1491 | OMAP4_GPIO_LEVELDETECT1); |
Tony Lindgren | 3f1686a9 | 2010-02-15 09:27:25 -0800 | [diff] [blame] | 1492 | __raw_writel(old0 | l, bank->base + |
| 1493 | OMAP4_GPIO_LEVELDETECT0); |
| 1494 | __raw_writel(old1 | l, bank->base + |
| 1495 | OMAP4_GPIO_LEVELDETECT1); |
| 1496 | __raw_writel(old0, bank->base + |
| 1497 | OMAP4_GPIO_LEVELDETECT0); |
| 1498 | __raw_writel(old1, bank->base + |
| 1499 | OMAP4_GPIO_LEVELDETECT1); |
| 1500 | } |
Juha Yrjola | 3ac4fa9 | 2006-12-06 17:13:52 -0800 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | } |
| 1505 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1506 | #endif |
| 1507 | |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1508 | #ifdef CONFIG_ARCH_OMAP3 |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1509 | /* save the registers of bank 2-6 */ |
| 1510 | void omap_gpio_save_context(void) |
| 1511 | { |
| 1512 | int i; |
| 1513 | |
| 1514 | /* saving banks from 2-6 only since GPIO1 is in WKUP */ |
| 1515 | for (i = 1; i < gpio_bank_count; i++) { |
| 1516 | struct gpio_bank *bank = &gpio_bank[i]; |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1517 | gpio_context[i].irqenable1 = |
| 1518 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE1); |
| 1519 | gpio_context[i].irqenable2 = |
| 1520 | __raw_readl(bank->base + OMAP24XX_GPIO_IRQENABLE2); |
| 1521 | gpio_context[i].wake_en = |
| 1522 | __raw_readl(bank->base + OMAP24XX_GPIO_WAKE_EN); |
| 1523 | gpio_context[i].ctrl = |
| 1524 | __raw_readl(bank->base + OMAP24XX_GPIO_CTRL); |
| 1525 | gpio_context[i].oe = |
| 1526 | __raw_readl(bank->base + OMAP24XX_GPIO_OE); |
| 1527 | gpio_context[i].leveldetect0 = |
| 1528 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 1529 | gpio_context[i].leveldetect1 = |
| 1530 | __raw_readl(bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 1531 | gpio_context[i].risingdetect = |
| 1532 | __raw_readl(bank->base + OMAP24XX_GPIO_RISINGDETECT); |
| 1533 | gpio_context[i].fallingdetect = |
| 1534 | __raw_readl(bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 1535 | gpio_context[i].dataout = |
| 1536 | __raw_readl(bank->base + OMAP24XX_GPIO_DATAOUT); |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | /* restore the required registers of bank 2-6 */ |
| 1541 | void omap_gpio_restore_context(void) |
| 1542 | { |
| 1543 | int i; |
| 1544 | |
| 1545 | for (i = 1; i < gpio_bank_count; i++) { |
| 1546 | struct gpio_bank *bank = &gpio_bank[i]; |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1547 | __raw_writel(gpio_context[i].irqenable1, |
| 1548 | bank->base + OMAP24XX_GPIO_IRQENABLE1); |
| 1549 | __raw_writel(gpio_context[i].irqenable2, |
| 1550 | bank->base + OMAP24XX_GPIO_IRQENABLE2); |
| 1551 | __raw_writel(gpio_context[i].wake_en, |
| 1552 | bank->base + OMAP24XX_GPIO_WAKE_EN); |
| 1553 | __raw_writel(gpio_context[i].ctrl, |
| 1554 | bank->base + OMAP24XX_GPIO_CTRL); |
| 1555 | __raw_writel(gpio_context[i].oe, |
| 1556 | bank->base + OMAP24XX_GPIO_OE); |
| 1557 | __raw_writel(gpio_context[i].leveldetect0, |
| 1558 | bank->base + OMAP24XX_GPIO_LEVELDETECT0); |
| 1559 | __raw_writel(gpio_context[i].leveldetect1, |
| 1560 | bank->base + OMAP24XX_GPIO_LEVELDETECT1); |
| 1561 | __raw_writel(gpio_context[i].risingdetect, |
| 1562 | bank->base + OMAP24XX_GPIO_RISINGDETECT); |
| 1563 | __raw_writel(gpio_context[i].fallingdetect, |
| 1564 | bank->base + OMAP24XX_GPIO_FALLINGDETECT); |
| 1565 | __raw_writel(gpio_context[i].dataout, |
| 1566 | bank->base + OMAP24XX_GPIO_DATAOUT); |
Rajendra Nayak | 40c670f | 2008-09-26 17:47:48 +0530 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | #endif |
| 1570 | |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1571 | static struct platform_driver omap_gpio_driver = { |
| 1572 | .probe = omap_gpio_probe, |
| 1573 | .driver = { |
| 1574 | .name = "omap_gpio", |
| 1575 | }, |
| 1576 | }; |
| 1577 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1578 | /* |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1579 | * gpio driver register needs to be done before |
| 1580 | * machine_init functions access gpio APIs. |
| 1581 | * Hence omap_gpio_drv_reg() is a postcore_initcall. |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1582 | */ |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1583 | static int __init omap_gpio_drv_reg(void) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1584 | { |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1585 | return platform_driver_register(&omap_gpio_driver); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1586 | } |
Varadarajan, Charulatha | 77640aa | 2010-12-07 16:26:57 -0800 | [diff] [blame] | 1587 | postcore_initcall(omap_gpio_drv_reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1588 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1589 | static int __init omap_gpio_sysinit(void) |
| 1590 | { |
David Brownell | 11a78b7 | 2006-12-06 17:14:11 -0800 | [diff] [blame] | 1591 | mpuio_init(); |
| 1592 | |
Tony Lindgren | 140455f | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1593 | #if defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP2PLUS) |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 1594 | if (cpu_is_omap16xx() || cpu_class_is_omap2()) |
| 1595 | register_syscore_ops(&omap_gpio_syscore_ops); |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1596 | #endif |
| 1597 | |
Rafael J. Wysocki | 3c437ff | 2011-04-22 22:02:46 +0200 | [diff] [blame] | 1598 | return 0; |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1599 | } |
| 1600 | |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 1601 | arch_initcall(omap_gpio_sysinit); |