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