Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Generic GPIO driver for logic cells found in the Nomadik SoC |
| 3 | * |
| 4 | * Copyright (C) 2008,2009 STMicroelectronics |
| 5 | * Copyright (C) 2009 Alessandro Rubini <rubini@unipv.it> |
| 6 | * Rewritten based on work by Prafulla WADASKAR <prafulla.wadaskar@st.com> |
Linus Walleij | 33d7864 | 2011-06-09 11:08:47 +0200 | [diff] [blame] | 7 | * Copyright (C) 2011 Linus Walleij <linus.walleij@linaro.org> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/device.h> |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 18 | #include <linux/io.h> |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 19 | #include <linux/clk.h> |
| 20 | #include <linux/err.h> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 21 | #include <linux/gpio.h> |
| 22 | #include <linux/spinlock.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/irq.h> |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 25 | #include <linux/irqdomain.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 27 | #include <linux/pinctrl/pinctrl.h> |
Linus Walleij | dbfe8ca | 2012-05-02 22:56:47 +0200 | [diff] [blame^] | 28 | #include <linux/pinctrl/pinmux.h> |
| 29 | /* Since we request GPIOs from ourself */ |
| 30 | #include <linux/pinctrl/consumer.h> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 31 | |
Will Deacon | adfed15 | 2011-02-28 10:12:29 +0000 | [diff] [blame] | 32 | #include <asm/mach/irq.h> |
| 33 | |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 34 | #include <plat/pincfg.h> |
Linus Walleij | 0f33286 | 2011-08-22 08:33:30 +0100 | [diff] [blame] | 35 | #include <plat/gpio-nomadik.h> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 36 | |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 37 | #include "pinctrl-nomadik.h" |
| 38 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 39 | /* |
| 40 | * The GPIO module in the Nomadik family of Systems-on-Chip is an |
| 41 | * AMBA device, managing 32 pins and alternate functions. The logic block |
Jonas Aaberg | 9c66ee6 | 2010-10-13 13:14:17 +0200 | [diff] [blame] | 42 | * is currently used in the Nomadik and ux500. |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 43 | * |
| 44 | * Symbols in this file are called "nmk_gpio" for "nomadik gpio" |
| 45 | */ |
| 46 | |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 47 | #define NMK_GPIO_PER_CHIP 32 |
| 48 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 49 | struct nmk_gpio_chip { |
| 50 | struct gpio_chip chip; |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 51 | struct irq_domain *domain; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 52 | void __iomem *addr; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 53 | struct clk *clk; |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 54 | unsigned int bank; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 55 | unsigned int parent_irq; |
Virupax Sadashivpetimath | 2c8bb0e | 2010-11-11 14:10:38 +0530 | [diff] [blame] | 56 | int secondary_parent_irq; |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 57 | u32 (*get_secondary_status)(unsigned int bank); |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 58 | void (*set_ioforce)(bool enable); |
Rabin Vincent | c0fcb8d | 2010-03-03 04:48:54 +0100 | [diff] [blame] | 59 | spinlock_t lock; |
Linus Walleij | 33d7864 | 2011-06-09 11:08:47 +0200 | [diff] [blame] | 60 | bool sleepmode; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 61 | /* Keep track of configured edges */ |
| 62 | u32 edge_rising; |
| 63 | u32 edge_falling; |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 64 | u32 real_wake; |
| 65 | u32 rwimsc; |
| 66 | u32 fwimsc; |
Rabin Vincent | 6c12fe8 | 2011-05-23 12:13:33 +0530 | [diff] [blame] | 67 | u32 rimsc; |
| 68 | u32 fimsc; |
Rickard Andersson | bc6f5cf | 2011-05-24 23:07:17 +0200 | [diff] [blame] | 69 | u32 pull_up; |
Rabin Vincent | ebc6178 | 2011-09-28 15:49:11 +0530 | [diff] [blame] | 70 | u32 lowemi; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 73 | struct nmk_pinctrl { |
| 74 | struct device *dev; |
| 75 | struct pinctrl_dev *pctl; |
| 76 | const struct nmk_pinctrl_soc_data *soc; |
| 77 | }; |
| 78 | |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 79 | static struct nmk_gpio_chip * |
| 80 | nmk_gpio_chips[DIV_ROUND_UP(ARCH_NR_GPIOS, NMK_GPIO_PER_CHIP)]; |
| 81 | |
| 82 | static DEFINE_SPINLOCK(nmk_gpio_slpm_lock); |
| 83 | |
| 84 | #define NUM_BANKS ARRAY_SIZE(nmk_gpio_chips) |
| 85 | |
Rabin Vincent | 6f9a974 | 2010-06-02 05:50:28 +0100 | [diff] [blame] | 86 | static void __nmk_gpio_set_mode(struct nmk_gpio_chip *nmk_chip, |
| 87 | unsigned offset, int gpio_mode) |
| 88 | { |
| 89 | u32 bit = 1 << offset; |
| 90 | u32 afunc, bfunc; |
| 91 | |
| 92 | afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & ~bit; |
| 93 | bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & ~bit; |
| 94 | if (gpio_mode & NMK_GPIO_ALT_A) |
| 95 | afunc |= bit; |
| 96 | if (gpio_mode & NMK_GPIO_ALT_B) |
| 97 | bfunc |= bit; |
| 98 | writel(afunc, nmk_chip->addr + NMK_GPIO_AFSLA); |
| 99 | writel(bfunc, nmk_chip->addr + NMK_GPIO_AFSLB); |
| 100 | } |
| 101 | |
Rabin Vincent | 81a3c29 | 2010-05-27 12:39:23 +0100 | [diff] [blame] | 102 | static void __nmk_gpio_set_slpm(struct nmk_gpio_chip *nmk_chip, |
| 103 | unsigned offset, enum nmk_gpio_slpm mode) |
| 104 | { |
| 105 | u32 bit = 1 << offset; |
| 106 | u32 slpm; |
| 107 | |
| 108 | slpm = readl(nmk_chip->addr + NMK_GPIO_SLPC); |
| 109 | if (mode == NMK_GPIO_SLPM_NOCHANGE) |
| 110 | slpm |= bit; |
| 111 | else |
| 112 | slpm &= ~bit; |
| 113 | writel(slpm, nmk_chip->addr + NMK_GPIO_SLPC); |
| 114 | } |
| 115 | |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 116 | static void __nmk_gpio_set_pull(struct nmk_gpio_chip *nmk_chip, |
| 117 | unsigned offset, enum nmk_gpio_pull pull) |
| 118 | { |
| 119 | u32 bit = 1 << offset; |
| 120 | u32 pdis; |
| 121 | |
| 122 | pdis = readl(nmk_chip->addr + NMK_GPIO_PDIS); |
Rickard Andersson | bc6f5cf | 2011-05-24 23:07:17 +0200 | [diff] [blame] | 123 | if (pull == NMK_GPIO_PULL_NONE) { |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 124 | pdis |= bit; |
Rickard Andersson | bc6f5cf | 2011-05-24 23:07:17 +0200 | [diff] [blame] | 125 | nmk_chip->pull_up &= ~bit; |
| 126 | } else { |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 127 | pdis &= ~bit; |
Rickard Andersson | bc6f5cf | 2011-05-24 23:07:17 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 130 | writel(pdis, nmk_chip->addr + NMK_GPIO_PDIS); |
| 131 | |
Rickard Andersson | bc6f5cf | 2011-05-24 23:07:17 +0200 | [diff] [blame] | 132 | if (pull == NMK_GPIO_PULL_UP) { |
| 133 | nmk_chip->pull_up |= bit; |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 134 | writel(bit, nmk_chip->addr + NMK_GPIO_DATS); |
Rickard Andersson | bc6f5cf | 2011-05-24 23:07:17 +0200 | [diff] [blame] | 135 | } else if (pull == NMK_GPIO_PULL_DOWN) { |
| 136 | nmk_chip->pull_up &= ~bit; |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 137 | writel(bit, nmk_chip->addr + NMK_GPIO_DATC); |
Rickard Andersson | bc6f5cf | 2011-05-24 23:07:17 +0200 | [diff] [blame] | 138 | } |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 139 | } |
| 140 | |
Rabin Vincent | ebc6178 | 2011-09-28 15:49:11 +0530 | [diff] [blame] | 141 | static void __nmk_gpio_set_lowemi(struct nmk_gpio_chip *nmk_chip, |
| 142 | unsigned offset, bool lowemi) |
| 143 | { |
| 144 | u32 bit = BIT(offset); |
| 145 | bool enabled = nmk_chip->lowemi & bit; |
| 146 | |
| 147 | if (lowemi == enabled) |
| 148 | return; |
| 149 | |
| 150 | if (lowemi) |
| 151 | nmk_chip->lowemi |= bit; |
| 152 | else |
| 153 | nmk_chip->lowemi &= ~bit; |
| 154 | |
| 155 | writel_relaxed(nmk_chip->lowemi, |
| 156 | nmk_chip->addr + NMK_GPIO_LOWEMI); |
| 157 | } |
| 158 | |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 159 | static void __nmk_gpio_make_input(struct nmk_gpio_chip *nmk_chip, |
| 160 | unsigned offset) |
| 161 | { |
| 162 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC); |
| 163 | } |
| 164 | |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 165 | static void __nmk_gpio_set_output(struct nmk_gpio_chip *nmk_chip, |
| 166 | unsigned offset, int val) |
| 167 | { |
| 168 | if (val) |
| 169 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DATS); |
| 170 | else |
| 171 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DATC); |
| 172 | } |
| 173 | |
| 174 | static void __nmk_gpio_make_output(struct nmk_gpio_chip *nmk_chip, |
| 175 | unsigned offset, int val) |
| 176 | { |
| 177 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRS); |
| 178 | __nmk_gpio_set_output(nmk_chip, offset, val); |
| 179 | } |
| 180 | |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 181 | static void __nmk_gpio_set_mode_safe(struct nmk_gpio_chip *nmk_chip, |
| 182 | unsigned offset, int gpio_mode, |
| 183 | bool glitch) |
| 184 | { |
Rabin Vincent | 6c12fe8 | 2011-05-23 12:13:33 +0530 | [diff] [blame] | 185 | u32 rwimsc = nmk_chip->rwimsc; |
| 186 | u32 fwimsc = nmk_chip->fwimsc; |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 187 | |
| 188 | if (glitch && nmk_chip->set_ioforce) { |
| 189 | u32 bit = BIT(offset); |
| 190 | |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 191 | /* Prevent spurious wakeups */ |
| 192 | writel(rwimsc & ~bit, nmk_chip->addr + NMK_GPIO_RWIMSC); |
| 193 | writel(fwimsc & ~bit, nmk_chip->addr + NMK_GPIO_FWIMSC); |
| 194 | |
| 195 | nmk_chip->set_ioforce(true); |
| 196 | } |
| 197 | |
| 198 | __nmk_gpio_set_mode(nmk_chip, offset, gpio_mode); |
| 199 | |
| 200 | if (glitch && nmk_chip->set_ioforce) { |
| 201 | nmk_chip->set_ioforce(false); |
| 202 | |
| 203 | writel(rwimsc, nmk_chip->addr + NMK_GPIO_RWIMSC); |
| 204 | writel(fwimsc, nmk_chip->addr + NMK_GPIO_FWIMSC); |
| 205 | } |
| 206 | } |
| 207 | |
Rabin Vincent | 6c42ad1 | 2011-05-23 12:22:18 +0530 | [diff] [blame] | 208 | static void |
| 209 | nmk_gpio_disable_lazy_irq(struct nmk_gpio_chip *nmk_chip, unsigned offset) |
| 210 | { |
| 211 | u32 falling = nmk_chip->fimsc & BIT(offset); |
| 212 | u32 rising = nmk_chip->rimsc & BIT(offset); |
| 213 | int gpio = nmk_chip->chip.base + offset; |
| 214 | int irq = NOMADIK_GPIO_TO_IRQ(gpio); |
| 215 | struct irq_data *d = irq_get_irq_data(irq); |
| 216 | |
| 217 | if (!rising && !falling) |
| 218 | return; |
| 219 | |
| 220 | if (!d || !irqd_irq_disabled(d)) |
| 221 | return; |
| 222 | |
| 223 | if (rising) { |
| 224 | nmk_chip->rimsc &= ~BIT(offset); |
| 225 | writel_relaxed(nmk_chip->rimsc, |
| 226 | nmk_chip->addr + NMK_GPIO_RIMSC); |
| 227 | } |
| 228 | |
| 229 | if (falling) { |
| 230 | nmk_chip->fimsc &= ~BIT(offset); |
| 231 | writel_relaxed(nmk_chip->fimsc, |
| 232 | nmk_chip->addr + NMK_GPIO_FIMSC); |
| 233 | } |
| 234 | |
| 235 | dev_dbg(nmk_chip->chip.dev, "%d: clearing interrupt mask\n", gpio); |
| 236 | } |
| 237 | |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 238 | static void __nmk_config_pin(struct nmk_gpio_chip *nmk_chip, unsigned offset, |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 239 | pin_cfg_t cfg, bool sleep, unsigned int *slpmregs) |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 240 | { |
| 241 | static const char *afnames[] = { |
| 242 | [NMK_GPIO_ALT_GPIO] = "GPIO", |
| 243 | [NMK_GPIO_ALT_A] = "A", |
| 244 | [NMK_GPIO_ALT_B] = "B", |
| 245 | [NMK_GPIO_ALT_C] = "C" |
| 246 | }; |
| 247 | static const char *pullnames[] = { |
| 248 | [NMK_GPIO_PULL_NONE] = "none", |
| 249 | [NMK_GPIO_PULL_UP] = "up", |
| 250 | [NMK_GPIO_PULL_DOWN] = "down", |
| 251 | [3] /* illegal */ = "??" |
| 252 | }; |
| 253 | static const char *slpmnames[] = { |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 254 | [NMK_GPIO_SLPM_INPUT] = "input/wakeup", |
| 255 | [NMK_GPIO_SLPM_NOCHANGE] = "no-change/no-wakeup", |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 256 | }; |
| 257 | |
| 258 | int pin = PIN_NUM(cfg); |
| 259 | int pull = PIN_PULL(cfg); |
| 260 | int af = PIN_ALT(cfg); |
| 261 | int slpm = PIN_SLPM(cfg); |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 262 | int output = PIN_DIR(cfg); |
| 263 | int val = PIN_VAL(cfg); |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 264 | bool glitch = af == NMK_GPIO_ALT_C; |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 265 | |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 266 | dev_dbg(nmk_chip->chip.dev, "pin %d [%#lx]: af %s, pull %s, slpm %s (%s%s)\n", |
| 267 | pin, cfg, afnames[af], pullnames[pull], slpmnames[slpm], |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 268 | output ? "output " : "input", |
| 269 | output ? (val ? "high" : "low") : ""); |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 270 | |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 271 | if (sleep) { |
| 272 | int slpm_pull = PIN_SLPM_PULL(cfg); |
| 273 | int slpm_output = PIN_SLPM_DIR(cfg); |
| 274 | int slpm_val = PIN_SLPM_VAL(cfg); |
| 275 | |
Rabin Vincent | 3546d15 | 2010-11-25 11:38:27 +0530 | [diff] [blame] | 276 | af = NMK_GPIO_ALT_GPIO; |
| 277 | |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 278 | /* |
| 279 | * The SLPM_* values are normal values + 1 to allow zero to |
| 280 | * mean "same as normal". |
| 281 | */ |
| 282 | if (slpm_pull) |
| 283 | pull = slpm_pull - 1; |
| 284 | if (slpm_output) |
| 285 | output = slpm_output - 1; |
| 286 | if (slpm_val) |
| 287 | val = slpm_val - 1; |
| 288 | |
| 289 | dev_dbg(nmk_chip->chip.dev, "pin %d: sleep pull %s, dir %s, val %s\n", |
| 290 | pin, |
| 291 | slpm_pull ? pullnames[pull] : "same", |
| 292 | slpm_output ? (output ? "output" : "input") : "same", |
| 293 | slpm_val ? (val ? "high" : "low") : "same"); |
| 294 | } |
| 295 | |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 296 | if (output) |
| 297 | __nmk_gpio_make_output(nmk_chip, offset, val); |
| 298 | else { |
| 299 | __nmk_gpio_make_input(nmk_chip, offset); |
| 300 | __nmk_gpio_set_pull(nmk_chip, offset, pull); |
| 301 | } |
| 302 | |
Rabin Vincent | ebc6178 | 2011-09-28 15:49:11 +0530 | [diff] [blame] | 303 | __nmk_gpio_set_lowemi(nmk_chip, offset, PIN_LOWEMI(cfg)); |
| 304 | |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 305 | /* |
Rabin Vincent | 6c42ad1 | 2011-05-23 12:22:18 +0530 | [diff] [blame] | 306 | * If the pin is switching to altfunc, and there was an interrupt |
| 307 | * installed on it which has been lazy disabled, actually mask the |
| 308 | * interrupt to prevent spurious interrupts that would occur while the |
| 309 | * pin is under control of the peripheral. Only SKE does this. |
| 310 | */ |
| 311 | if (af != NMK_GPIO_ALT_GPIO) |
| 312 | nmk_gpio_disable_lazy_irq(nmk_chip, offset); |
| 313 | |
| 314 | /* |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 315 | * If we've backed up the SLPM registers (glitch workaround), modify |
| 316 | * the backups since they will be restored. |
| 317 | */ |
| 318 | if (slpmregs) { |
| 319 | if (slpm == NMK_GPIO_SLPM_NOCHANGE) |
| 320 | slpmregs[nmk_chip->bank] |= BIT(offset); |
| 321 | else |
| 322 | slpmregs[nmk_chip->bank] &= ~BIT(offset); |
| 323 | } else |
| 324 | __nmk_gpio_set_slpm(nmk_chip, offset, slpm); |
| 325 | |
| 326 | __nmk_gpio_set_mode_safe(nmk_chip, offset, af, glitch); |
| 327 | } |
| 328 | |
| 329 | /* |
| 330 | * Safe sequence used to switch IOs between GPIO and Alternate-C mode: |
| 331 | * - Save SLPM registers |
| 332 | * - Set SLPM=0 for the IOs you want to switch and others to 1 |
| 333 | * - Configure the GPIO registers for the IOs that are being switched |
| 334 | * - Set IOFORCE=1 |
| 335 | * - Modify the AFLSA/B registers for the IOs that are being switched |
| 336 | * - Set IOFORCE=0 |
| 337 | * - Restore SLPM registers |
| 338 | * - Any spurious wake up event during switch sequence to be ignored and |
| 339 | * cleared |
| 340 | */ |
| 341 | static void nmk_gpio_glitch_slpm_init(unsigned int *slpm) |
| 342 | { |
| 343 | int i; |
| 344 | |
| 345 | for (i = 0; i < NUM_BANKS; i++) { |
| 346 | struct nmk_gpio_chip *chip = nmk_gpio_chips[i]; |
| 347 | unsigned int temp = slpm[i]; |
| 348 | |
| 349 | if (!chip) |
| 350 | break; |
| 351 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 352 | clk_enable(chip->clk); |
| 353 | |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 354 | slpm[i] = readl(chip->addr + NMK_GPIO_SLPC); |
| 355 | writel(temp, chip->addr + NMK_GPIO_SLPC); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | static void nmk_gpio_glitch_slpm_restore(unsigned int *slpm) |
| 360 | { |
| 361 | int i; |
| 362 | |
| 363 | for (i = 0; i < NUM_BANKS; i++) { |
| 364 | struct nmk_gpio_chip *chip = nmk_gpio_chips[i]; |
| 365 | |
| 366 | if (!chip) |
| 367 | break; |
| 368 | |
| 369 | writel(slpm[i], chip->addr + NMK_GPIO_SLPC); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 370 | |
| 371 | clk_disable(chip->clk); |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
| 375 | static int __nmk_config_pins(pin_cfg_t *cfgs, int num, bool sleep) |
| 376 | { |
| 377 | static unsigned int slpm[NUM_BANKS]; |
| 378 | unsigned long flags; |
| 379 | bool glitch = false; |
| 380 | int ret = 0; |
| 381 | int i; |
| 382 | |
| 383 | for (i = 0; i < num; i++) { |
| 384 | if (PIN_ALT(cfgs[i]) == NMK_GPIO_ALT_C) { |
| 385 | glitch = true; |
| 386 | break; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | spin_lock_irqsave(&nmk_gpio_slpm_lock, flags); |
| 391 | |
| 392 | if (glitch) { |
| 393 | memset(slpm, 0xff, sizeof(slpm)); |
| 394 | |
| 395 | for (i = 0; i < num; i++) { |
| 396 | int pin = PIN_NUM(cfgs[i]); |
| 397 | int offset = pin % NMK_GPIO_PER_CHIP; |
| 398 | |
| 399 | if (PIN_ALT(cfgs[i]) == NMK_GPIO_ALT_C) |
| 400 | slpm[pin / NMK_GPIO_PER_CHIP] &= ~BIT(offset); |
| 401 | } |
| 402 | |
| 403 | nmk_gpio_glitch_slpm_init(slpm); |
| 404 | } |
| 405 | |
| 406 | for (i = 0; i < num; i++) { |
| 407 | struct nmk_gpio_chip *nmk_chip; |
| 408 | int pin = PIN_NUM(cfgs[i]); |
| 409 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 410 | nmk_chip = nmk_gpio_chips[pin / NMK_GPIO_PER_CHIP]; |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 411 | if (!nmk_chip) { |
| 412 | ret = -EINVAL; |
| 413 | break; |
| 414 | } |
| 415 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 416 | clk_enable(nmk_chip->clk); |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 417 | spin_lock(&nmk_chip->lock); |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 418 | __nmk_config_pin(nmk_chip, pin % NMK_GPIO_PER_CHIP, |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 419 | cfgs[i], sleep, glitch ? slpm : NULL); |
| 420 | spin_unlock(&nmk_chip->lock); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 421 | clk_disable(nmk_chip->clk); |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | if (glitch) |
| 425 | nmk_gpio_glitch_slpm_restore(slpm); |
| 426 | |
| 427 | spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags); |
| 428 | |
| 429 | return ret; |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /** |
| 433 | * nmk_config_pin - configure a pin's mux attributes |
| 434 | * @cfg: pin confguration |
| 435 | * |
| 436 | * Configures a pin's mode (alternate function or GPIO), its pull up status, |
| 437 | * and its sleep mode based on the specified configuration. The @cfg is |
| 438 | * usually one of the SoC specific macros defined in mach/<soc>-pins.h. These |
| 439 | * are constructed using, and can be further enhanced with, the macros in |
| 440 | * plat/pincfg.h. |
| 441 | * |
| 442 | * If a pin's mode is set to GPIO, it is configured as an input to avoid |
| 443 | * side-effects. The gpio can be manipulated later using standard GPIO API |
| 444 | * calls. |
| 445 | */ |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 446 | int nmk_config_pin(pin_cfg_t cfg, bool sleep) |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 447 | { |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 448 | return __nmk_config_pins(&cfg, 1, sleep); |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 449 | } |
| 450 | EXPORT_SYMBOL(nmk_config_pin); |
| 451 | |
| 452 | /** |
| 453 | * nmk_config_pins - configure several pins at once |
| 454 | * @cfgs: array of pin configurations |
| 455 | * @num: number of elments in the array |
| 456 | * |
| 457 | * Configures several pins using nmk_config_pin(). Refer to that function for |
| 458 | * further information. |
| 459 | */ |
| 460 | int nmk_config_pins(pin_cfg_t *cfgs, int num) |
| 461 | { |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 462 | return __nmk_config_pins(cfgs, num, false); |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 463 | } |
| 464 | EXPORT_SYMBOL(nmk_config_pins); |
| 465 | |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 466 | int nmk_config_pins_sleep(pin_cfg_t *cfgs, int num) |
| 467 | { |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 468 | return __nmk_config_pins(cfgs, num, true); |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 469 | } |
| 470 | EXPORT_SYMBOL(nmk_config_pins_sleep); |
| 471 | |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 472 | /** |
Rabin Vincent | 81a3c29 | 2010-05-27 12:39:23 +0100 | [diff] [blame] | 473 | * nmk_gpio_set_slpm() - configure the sleep mode of a pin |
| 474 | * @gpio: pin number |
| 475 | * @mode: NMK_GPIO_SLPM_INPUT or NMK_GPIO_SLPM_NOCHANGE, |
| 476 | * |
Linus Walleij | 33d7864 | 2011-06-09 11:08:47 +0200 | [diff] [blame] | 477 | * This register is actually in the pinmux layer, not the GPIO block itself. |
| 478 | * The GPIO1B_SLPM register defines the GPIO mode when SLEEP/DEEP-SLEEP |
| 479 | * mode is entered (i.e. when signal IOFORCE is HIGH by the platform code). |
| 480 | * Each GPIO can be configured to be forced into GPIO mode when IOFORCE is |
| 481 | * HIGH, overriding the normal setting defined by GPIO_AFSELx registers. |
| 482 | * When IOFORCE returns LOW (by software, after SLEEP/DEEP-SLEEP exit), |
| 483 | * the GPIOs return to the normal setting defined by GPIO_AFSELx registers. |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 484 | * |
Linus Walleij | 33d7864 | 2011-06-09 11:08:47 +0200 | [diff] [blame] | 485 | * If @mode is NMK_GPIO_SLPM_INPUT, the corresponding GPIO is switched to GPIO |
| 486 | * mode when signal IOFORCE is HIGH (i.e. when SLEEP/DEEP-SLEEP mode is |
| 487 | * entered) regardless of the altfunction selected. Also wake-up detection is |
| 488 | * ENABLED. |
| 489 | * |
| 490 | * If @mode is NMK_GPIO_SLPM_NOCHANGE, the corresponding GPIO remains |
| 491 | * controlled by NMK_GPIO_DATC, NMK_GPIO_DATS, NMK_GPIO_DIR, NMK_GPIO_PDIS |
| 492 | * (for altfunction GPIO) or respective on-chip peripherals (for other |
| 493 | * altfuncs) when IOFORCE is HIGH. Also wake-up detection DISABLED. |
| 494 | * |
| 495 | * Note that enable_irq_wake() will automatically enable wakeup detection. |
Rabin Vincent | 81a3c29 | 2010-05-27 12:39:23 +0100 | [diff] [blame] | 496 | */ |
| 497 | int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode) |
| 498 | { |
| 499 | struct nmk_gpio_chip *nmk_chip; |
| 500 | unsigned long flags; |
| 501 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 502 | nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP]; |
Rabin Vincent | 81a3c29 | 2010-05-27 12:39:23 +0100 | [diff] [blame] | 503 | if (!nmk_chip) |
| 504 | return -EINVAL; |
| 505 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 506 | clk_enable(nmk_chip->clk); |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 507 | spin_lock_irqsave(&nmk_gpio_slpm_lock, flags); |
| 508 | spin_lock(&nmk_chip->lock); |
| 509 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 510 | __nmk_gpio_set_slpm(nmk_chip, gpio % NMK_GPIO_PER_CHIP, mode); |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 511 | |
| 512 | spin_unlock(&nmk_chip->lock); |
| 513 | spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 514 | clk_disable(nmk_chip->clk); |
Rabin Vincent | 81a3c29 | 2010-05-27 12:39:23 +0100 | [diff] [blame] | 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | /** |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 520 | * nmk_gpio_set_pull() - enable/disable pull up/down on a gpio |
| 521 | * @gpio: pin number |
| 522 | * @pull: one of NMK_GPIO_PULL_DOWN, NMK_GPIO_PULL_UP, and NMK_GPIO_PULL_NONE |
| 523 | * |
| 524 | * Enables/disables pull up/down on a specified pin. This only takes effect if |
| 525 | * the pin is configured as an input (either explicitly or by the alternate |
| 526 | * function). |
| 527 | * |
| 528 | * NOTE: If enabling the pull up/down, the caller must ensure that the GPIO is |
| 529 | * configured as an input. Otherwise, due to the way the controller registers |
| 530 | * work, this function will change the value output on the pin. |
| 531 | */ |
| 532 | int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull) |
| 533 | { |
| 534 | struct nmk_gpio_chip *nmk_chip; |
| 535 | unsigned long flags; |
| 536 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 537 | nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP]; |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 538 | if (!nmk_chip) |
| 539 | return -EINVAL; |
| 540 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 541 | clk_enable(nmk_chip->clk); |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 542 | spin_lock_irqsave(&nmk_chip->lock, flags); |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 543 | __nmk_gpio_set_pull(nmk_chip, gpio % NMK_GPIO_PER_CHIP, pull); |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 544 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 545 | clk_disable(nmk_chip->clk); |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 550 | /* Mode functions */ |
Jonas Aaberg | 9c66ee6 | 2010-10-13 13:14:17 +0200 | [diff] [blame] | 551 | /** |
| 552 | * nmk_gpio_set_mode() - set the mux mode of a gpio pin |
| 553 | * @gpio: pin number |
| 554 | * @gpio_mode: one of NMK_GPIO_ALT_GPIO, NMK_GPIO_ALT_A, |
| 555 | * NMK_GPIO_ALT_B, and NMK_GPIO_ALT_C |
| 556 | * |
| 557 | * Sets the mode of the specified pin to one of the alternate functions or |
| 558 | * plain GPIO. |
| 559 | */ |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 560 | int nmk_gpio_set_mode(int gpio, int gpio_mode) |
| 561 | { |
| 562 | struct nmk_gpio_chip *nmk_chip; |
| 563 | unsigned long flags; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 564 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 565 | nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP]; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 566 | if (!nmk_chip) |
| 567 | return -EINVAL; |
| 568 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 569 | clk_enable(nmk_chip->clk); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 570 | spin_lock_irqsave(&nmk_chip->lock, flags); |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 571 | __nmk_gpio_set_mode(nmk_chip, gpio % NMK_GPIO_PER_CHIP, gpio_mode); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 572 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 573 | clk_disable(nmk_chip->clk); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 574 | |
| 575 | return 0; |
| 576 | } |
| 577 | EXPORT_SYMBOL(nmk_gpio_set_mode); |
| 578 | |
| 579 | int nmk_gpio_get_mode(int gpio) |
| 580 | { |
| 581 | struct nmk_gpio_chip *nmk_chip; |
| 582 | u32 afunc, bfunc, bit; |
| 583 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 584 | nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP]; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 585 | if (!nmk_chip) |
| 586 | return -EINVAL; |
| 587 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 588 | bit = 1 << (gpio % NMK_GPIO_PER_CHIP); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 589 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 590 | clk_enable(nmk_chip->clk); |
| 591 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 592 | afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & bit; |
| 593 | bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & bit; |
| 594 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 595 | clk_disable(nmk_chip->clk); |
| 596 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 597 | return (afunc ? NMK_GPIO_ALT_A : 0) | (bfunc ? NMK_GPIO_ALT_B : 0); |
| 598 | } |
| 599 | EXPORT_SYMBOL(nmk_gpio_get_mode); |
| 600 | |
| 601 | |
| 602 | /* IRQ functions */ |
| 603 | static inline int nmk_gpio_get_bitmask(int gpio) |
| 604 | { |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 605 | return 1 << (gpio % NMK_GPIO_PER_CHIP); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 606 | } |
| 607 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 608 | static void nmk_gpio_irq_ack(struct irq_data *d) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 609 | { |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 610 | struct nmk_gpio_chip *nmk_chip; |
| 611 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 612 | nmk_chip = irq_data_get_irq_chip_data(d); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 613 | if (!nmk_chip) |
| 614 | return; |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 615 | |
| 616 | clk_enable(nmk_chip->clk); |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 617 | writel(nmk_gpio_get_bitmask(d->hwirq), nmk_chip->addr + NMK_GPIO_IC); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 618 | clk_disable(nmk_chip->clk); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 619 | } |
| 620 | |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 621 | enum nmk_gpio_irq_type { |
| 622 | NORMAL, |
| 623 | WAKE, |
| 624 | }; |
| 625 | |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 626 | static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip, |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 627 | int gpio, enum nmk_gpio_irq_type which, |
| 628 | bool enable) |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 629 | { |
| 630 | u32 bitmask = nmk_gpio_get_bitmask(gpio); |
Rabin Vincent | 6c12fe8 | 2011-05-23 12:13:33 +0530 | [diff] [blame] | 631 | u32 *rimscval; |
| 632 | u32 *fimscval; |
| 633 | u32 rimscreg; |
| 634 | u32 fimscreg; |
| 635 | |
| 636 | if (which == NORMAL) { |
| 637 | rimscreg = NMK_GPIO_RIMSC; |
| 638 | fimscreg = NMK_GPIO_FIMSC; |
| 639 | rimscval = &nmk_chip->rimsc; |
| 640 | fimscval = &nmk_chip->fimsc; |
| 641 | } else { |
| 642 | rimscreg = NMK_GPIO_RWIMSC; |
| 643 | fimscreg = NMK_GPIO_FWIMSC; |
| 644 | rimscval = &nmk_chip->rwimsc; |
| 645 | fimscval = &nmk_chip->fwimsc; |
| 646 | } |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 647 | |
| 648 | /* we must individually set/clear the two edges */ |
| 649 | if (nmk_chip->edge_rising & bitmask) { |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 650 | if (enable) |
Rabin Vincent | 6c12fe8 | 2011-05-23 12:13:33 +0530 | [diff] [blame] | 651 | *rimscval |= bitmask; |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 652 | else |
Rabin Vincent | 6c12fe8 | 2011-05-23 12:13:33 +0530 | [diff] [blame] | 653 | *rimscval &= ~bitmask; |
| 654 | writel(*rimscval, nmk_chip->addr + rimscreg); |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 655 | } |
| 656 | if (nmk_chip->edge_falling & bitmask) { |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 657 | if (enable) |
Rabin Vincent | 6c12fe8 | 2011-05-23 12:13:33 +0530 | [diff] [blame] | 658 | *fimscval |= bitmask; |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 659 | else |
Rabin Vincent | 6c12fe8 | 2011-05-23 12:13:33 +0530 | [diff] [blame] | 660 | *fimscval &= ~bitmask; |
| 661 | writel(*fimscval, nmk_chip->addr + fimscreg); |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 665 | static void __nmk_gpio_set_wake(struct nmk_gpio_chip *nmk_chip, |
| 666 | int gpio, bool on) |
| 667 | { |
Rabin Vincent | b982ff0 | 2011-04-26 09:03:27 +0530 | [diff] [blame] | 668 | /* |
| 669 | * Ensure WAKEUP_ENABLE is on. No need to disable it if wakeup is |
| 670 | * disabled, since setting SLPM to 1 increases power consumption, and |
| 671 | * wakeup is anyhow controlled by the RIMSC and FIMSC registers. |
| 672 | */ |
| 673 | if (nmk_chip->sleepmode && on) { |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 674 | __nmk_gpio_set_slpm(nmk_chip, gpio % nmk_chip->chip.base, |
Rabin Vincent | b982ff0 | 2011-04-26 09:03:27 +0530 | [diff] [blame] | 675 | NMK_GPIO_SLPM_WAKEUP_ENABLE); |
Linus Walleij | 33d7864 | 2011-06-09 11:08:47 +0200 | [diff] [blame] | 676 | } |
| 677 | |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 678 | __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, on); |
| 679 | } |
| 680 | |
| 681 | static int nmk_gpio_irq_maskunmask(struct irq_data *d, bool enable) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 682 | { |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 683 | struct nmk_gpio_chip *nmk_chip; |
| 684 | unsigned long flags; |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 685 | u32 bitmask; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 686 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 687 | nmk_chip = irq_data_get_irq_chip_data(d); |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 688 | bitmask = nmk_gpio_get_bitmask(d->hwirq); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 689 | if (!nmk_chip) |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 690 | return -EINVAL; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 691 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 692 | clk_enable(nmk_chip->clk); |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 693 | spin_lock_irqsave(&nmk_gpio_slpm_lock, flags); |
| 694 | spin_lock(&nmk_chip->lock); |
| 695 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 696 | __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, enable); |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 697 | |
| 698 | if (!(nmk_chip->real_wake & bitmask)) |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 699 | __nmk_gpio_set_wake(nmk_chip, d->hwirq, enable); |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 700 | |
| 701 | spin_unlock(&nmk_chip->lock); |
| 702 | spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 703 | clk_disable(nmk_chip->clk); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 704 | |
| 705 | return 0; |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 706 | } |
| 707 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 708 | static void nmk_gpio_irq_mask(struct irq_data *d) |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 709 | { |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 710 | nmk_gpio_irq_maskunmask(d, false); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 711 | } |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 712 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 713 | static void nmk_gpio_irq_unmask(struct irq_data *d) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 714 | { |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 715 | nmk_gpio_irq_maskunmask(d, true); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 716 | } |
| 717 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 718 | static int nmk_gpio_irq_set_wake(struct irq_data *d, unsigned int on) |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 719 | { |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 720 | struct nmk_gpio_chip *nmk_chip; |
| 721 | unsigned long flags; |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 722 | u32 bitmask; |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 723 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 724 | nmk_chip = irq_data_get_irq_chip_data(d); |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 725 | if (!nmk_chip) |
| 726 | return -EINVAL; |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 727 | bitmask = nmk_gpio_get_bitmask(d->hwirq); |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 728 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 729 | clk_enable(nmk_chip->clk); |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 730 | spin_lock_irqsave(&nmk_gpio_slpm_lock, flags); |
| 731 | spin_lock(&nmk_chip->lock); |
| 732 | |
Linus Walleij | 479a0c7 | 2011-09-20 10:50:15 +0200 | [diff] [blame] | 733 | if (irqd_irq_disabled(d)) |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 734 | __nmk_gpio_set_wake(nmk_chip, d->hwirq, on); |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 735 | |
| 736 | if (on) |
| 737 | nmk_chip->real_wake |= bitmask; |
| 738 | else |
| 739 | nmk_chip->real_wake &= ~bitmask; |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 740 | |
| 741 | spin_unlock(&nmk_chip->lock); |
| 742 | spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 743 | clk_disable(nmk_chip->clk); |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 744 | |
| 745 | return 0; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 746 | } |
| 747 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 748 | static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 749 | { |
Linus Walleij | 479a0c7 | 2011-09-20 10:50:15 +0200 | [diff] [blame] | 750 | bool enabled = !irqd_irq_disabled(d); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 751 | bool wake = irqd_is_wakeup_set(d); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 752 | struct nmk_gpio_chip *nmk_chip; |
| 753 | unsigned long flags; |
| 754 | u32 bitmask; |
| 755 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 756 | nmk_chip = irq_data_get_irq_chip_data(d); |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 757 | bitmask = nmk_gpio_get_bitmask(d->hwirq); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 758 | if (!nmk_chip) |
| 759 | return -EINVAL; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 760 | if (type & IRQ_TYPE_LEVEL_HIGH) |
| 761 | return -EINVAL; |
| 762 | if (type & IRQ_TYPE_LEVEL_LOW) |
| 763 | return -EINVAL; |
| 764 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 765 | clk_enable(nmk_chip->clk); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 766 | spin_lock_irqsave(&nmk_chip->lock, flags); |
| 767 | |
Rabin Vincent | 7a852d8 | 2010-05-06 10:43:55 +0100 | [diff] [blame] | 768 | if (enabled) |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 769 | __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, false); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 770 | |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 771 | if (enabled || wake) |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 772 | __nmk_gpio_irq_modify(nmk_chip, d->hwirq, WAKE, false); |
Rabin Vincent | 7a852d8 | 2010-05-06 10:43:55 +0100 | [diff] [blame] | 773 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 774 | nmk_chip->edge_rising &= ~bitmask; |
| 775 | if (type & IRQ_TYPE_EDGE_RISING) |
| 776 | nmk_chip->edge_rising |= bitmask; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 777 | |
| 778 | nmk_chip->edge_falling &= ~bitmask; |
| 779 | if (type & IRQ_TYPE_EDGE_FALLING) |
| 780 | nmk_chip->edge_falling |= bitmask; |
Rabin Vincent | 7a852d8 | 2010-05-06 10:43:55 +0100 | [diff] [blame] | 781 | |
| 782 | if (enabled) |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 783 | __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, true); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 784 | |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 785 | if (enabled || wake) |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 786 | __nmk_gpio_irq_modify(nmk_chip, d->hwirq, WAKE, true); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 787 | |
| 788 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 789 | clk_disable(nmk_chip->clk); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 790 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 791 | return 0; |
| 792 | } |
| 793 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 794 | static unsigned int nmk_gpio_irq_startup(struct irq_data *d) |
| 795 | { |
| 796 | struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d); |
| 797 | |
| 798 | clk_enable(nmk_chip->clk); |
| 799 | nmk_gpio_irq_unmask(d); |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | static void nmk_gpio_irq_shutdown(struct irq_data *d) |
| 804 | { |
| 805 | struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d); |
| 806 | |
| 807 | nmk_gpio_irq_mask(d); |
| 808 | clk_disable(nmk_chip->clk); |
| 809 | } |
| 810 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 811 | static struct irq_chip nmk_gpio_irq_chip = { |
| 812 | .name = "Nomadik-GPIO", |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 813 | .irq_ack = nmk_gpio_irq_ack, |
| 814 | .irq_mask = nmk_gpio_irq_mask, |
| 815 | .irq_unmask = nmk_gpio_irq_unmask, |
| 816 | .irq_set_type = nmk_gpio_irq_set_type, |
| 817 | .irq_set_wake = nmk_gpio_irq_set_wake, |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 818 | .irq_startup = nmk_gpio_irq_startup, |
| 819 | .irq_shutdown = nmk_gpio_irq_shutdown, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 820 | }; |
| 821 | |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 822 | static void __nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc, |
| 823 | u32 status) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 824 | { |
| 825 | struct nmk_gpio_chip *nmk_chip; |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 826 | struct irq_chip *host_chip = irq_get_chip(irq); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 827 | unsigned int first_irq; |
| 828 | |
Will Deacon | adfed15 | 2011-02-28 10:12:29 +0000 | [diff] [blame] | 829 | chained_irq_enter(host_chip, desc); |
Rabin Vincent | aaedaa2 | 2010-03-03 04:50:27 +0100 | [diff] [blame] | 830 | |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 831 | nmk_chip = irq_get_handler_data(irq); |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 832 | first_irq = nmk_chip->domain->revmap_data.legacy.first_irq; |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 833 | while (status) { |
| 834 | int bit = __ffs(status); |
| 835 | |
| 836 | generic_handle_irq(first_irq + bit); |
| 837 | status &= ~BIT(bit); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 838 | } |
Rabin Vincent | aaedaa2 | 2010-03-03 04:50:27 +0100 | [diff] [blame] | 839 | |
Will Deacon | adfed15 | 2011-02-28 10:12:29 +0000 | [diff] [blame] | 840 | chained_irq_exit(host_chip, desc); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 841 | } |
| 842 | |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 843 | static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) |
| 844 | { |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 845 | struct nmk_gpio_chip *nmk_chip = irq_get_handler_data(irq); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 846 | u32 status; |
| 847 | |
| 848 | clk_enable(nmk_chip->clk); |
| 849 | status = readl(nmk_chip->addr + NMK_GPIO_IS); |
| 850 | clk_disable(nmk_chip->clk); |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 851 | |
| 852 | __nmk_gpio_irq_handler(irq, desc, status); |
| 853 | } |
| 854 | |
| 855 | static void nmk_gpio_secondary_irq_handler(unsigned int irq, |
| 856 | struct irq_desc *desc) |
| 857 | { |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 858 | struct nmk_gpio_chip *nmk_chip = irq_get_handler_data(irq); |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 859 | u32 status = nmk_chip->get_secondary_status(nmk_chip->bank); |
| 860 | |
| 861 | __nmk_gpio_irq_handler(irq, desc, status); |
| 862 | } |
| 863 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 864 | static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip) |
| 865 | { |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 866 | irq_set_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler); |
| 867 | irq_set_handler_data(nmk_chip->parent_irq, nmk_chip); |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 868 | |
| 869 | if (nmk_chip->secondary_parent_irq >= 0) { |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 870 | irq_set_chained_handler(nmk_chip->secondary_parent_irq, |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 871 | nmk_gpio_secondary_irq_handler); |
Thomas Gleixner | 6845664a | 2011-03-24 13:25:22 +0100 | [diff] [blame] | 872 | irq_set_handler_data(nmk_chip->secondary_parent_irq, nmk_chip); |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 873 | } |
| 874 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | /* I/O Functions */ |
Linus Walleij | dbfe8ca | 2012-05-02 22:56:47 +0200 | [diff] [blame^] | 879 | |
| 880 | static int nmk_gpio_request(struct gpio_chip *chip, unsigned offset) |
| 881 | { |
| 882 | /* |
| 883 | * Map back to global GPIO space and request muxing, the direction |
| 884 | * parameter does not matter for this controller. |
| 885 | */ |
| 886 | int gpio = chip->base + offset; |
| 887 | |
| 888 | return pinctrl_request_gpio(gpio); |
| 889 | } |
| 890 | |
| 891 | static void nmk_gpio_free(struct gpio_chip *chip, unsigned offset) |
| 892 | { |
| 893 | int gpio = chip->base + offset; |
| 894 | |
| 895 | pinctrl_free_gpio(gpio); |
| 896 | } |
| 897 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 898 | static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset) |
| 899 | { |
| 900 | struct nmk_gpio_chip *nmk_chip = |
| 901 | container_of(chip, struct nmk_gpio_chip, chip); |
| 902 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 903 | clk_enable(nmk_chip->clk); |
| 904 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 905 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 906 | |
| 907 | clk_disable(nmk_chip->clk); |
| 908 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 909 | return 0; |
| 910 | } |
| 911 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 912 | static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset) |
| 913 | { |
| 914 | struct nmk_gpio_chip *nmk_chip = |
| 915 | container_of(chip, struct nmk_gpio_chip, chip); |
| 916 | u32 bit = 1 << offset; |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 917 | int value; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 918 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 919 | clk_enable(nmk_chip->clk); |
| 920 | |
| 921 | value = (readl(nmk_chip->addr + NMK_GPIO_DAT) & bit) != 0; |
| 922 | |
| 923 | clk_disable(nmk_chip->clk); |
| 924 | |
| 925 | return value; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset, |
| 929 | int val) |
| 930 | { |
| 931 | struct nmk_gpio_chip *nmk_chip = |
| 932 | container_of(chip, struct nmk_gpio_chip, chip); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 933 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 934 | clk_enable(nmk_chip->clk); |
| 935 | |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 936 | __nmk_gpio_set_output(nmk_chip, offset, val); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 937 | |
| 938 | clk_disable(nmk_chip->clk); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 939 | } |
| 940 | |
Rabin Vincent | 6647c6c | 2010-05-27 12:22:42 +0100 | [diff] [blame] | 941 | static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset, |
| 942 | int val) |
| 943 | { |
| 944 | struct nmk_gpio_chip *nmk_chip = |
| 945 | container_of(chip, struct nmk_gpio_chip, chip); |
| 946 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 947 | clk_enable(nmk_chip->clk); |
| 948 | |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 949 | __nmk_gpio_make_output(nmk_chip, offset, val); |
Rabin Vincent | 6647c6c | 2010-05-27 12:22:42 +0100 | [diff] [blame] | 950 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 951 | clk_disable(nmk_chip->clk); |
| 952 | |
Rabin Vincent | 6647c6c | 2010-05-27 12:22:42 +0100 | [diff] [blame] | 953 | return 0; |
| 954 | } |
| 955 | |
Rabin Vincent | 0d2aec9 | 2010-06-16 06:10:43 +0100 | [diff] [blame] | 956 | static int nmk_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
| 957 | { |
| 958 | struct nmk_gpio_chip *nmk_chip = |
| 959 | container_of(chip, struct nmk_gpio_chip, chip); |
| 960 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 961 | return irq_find_mapping(nmk_chip->domain, offset); |
Rabin Vincent | 0d2aec9 | 2010-06-16 06:10:43 +0100 | [diff] [blame] | 962 | } |
| 963 | |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 964 | #ifdef CONFIG_DEBUG_FS |
| 965 | |
| 966 | #include <linux/seq_file.h> |
| 967 | |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 968 | static void nmk_gpio_dbg_show_one(struct seq_file *s, struct gpio_chip *chip, |
| 969 | unsigned offset, unsigned gpio) |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 970 | { |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 971 | const char *label = gpiochip_is_requested(chip, offset); |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 972 | struct nmk_gpio_chip *nmk_chip = |
| 973 | container_of(chip, struct nmk_gpio_chip, chip); |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 974 | int mode; |
| 975 | bool is_out; |
| 976 | bool pull; |
| 977 | u32 bit = 1 << offset; |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 978 | const char *modes[] = { |
| 979 | [NMK_GPIO_ALT_GPIO] = "gpio", |
| 980 | [NMK_GPIO_ALT_A] = "altA", |
| 981 | [NMK_GPIO_ALT_B] = "altB", |
| 982 | [NMK_GPIO_ALT_C] = "altC", |
| 983 | }; |
| 984 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 985 | clk_enable(nmk_chip->clk); |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 986 | is_out = !!(readl(nmk_chip->addr + NMK_GPIO_DIR) & bit); |
| 987 | pull = !(readl(nmk_chip->addr + NMK_GPIO_PDIS) & bit); |
| 988 | mode = nmk_gpio_get_mode(gpio); |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 989 | |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 990 | seq_printf(s, " gpio-%-3d (%-20.20s) %s %s %s %s", |
| 991 | gpio, label ?: "(none)", |
| 992 | is_out ? "out" : "in ", |
| 993 | chip->get |
| 994 | ? (chip->get(chip, offset) ? "hi" : "lo") |
| 995 | : "? ", |
| 996 | (mode < 0) ? "unknown" : modes[mode], |
| 997 | pull ? "pull" : "none"); |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 998 | |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 999 | if (label && !is_out) { |
| 1000 | int irq = gpio_to_irq(gpio); |
| 1001 | struct irq_desc *desc = irq_to_desc(irq); |
Rabin Vincent | 8ea72a3 | 2011-05-24 23:07:09 +0200 | [diff] [blame] | 1002 | |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 1003 | /* This races with request_irq(), set_irq_type(), |
| 1004 | * and set_irq_wake() ... but those are "rare". |
| 1005 | */ |
| 1006 | if (irq >= 0 && desc->action) { |
| 1007 | char *trigger; |
| 1008 | u32 bitmask = nmk_gpio_get_bitmask(gpio); |
Rabin Vincent | 8ea72a3 | 2011-05-24 23:07:09 +0200 | [diff] [blame] | 1009 | |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 1010 | if (nmk_chip->edge_rising & bitmask) |
| 1011 | trigger = "edge-rising"; |
| 1012 | else if (nmk_chip->edge_falling & bitmask) |
| 1013 | trigger = "edge-falling"; |
| 1014 | else |
| 1015 | trigger = "edge-undefined"; |
Rabin Vincent | 8ea72a3 | 2011-05-24 23:07:09 +0200 | [diff] [blame] | 1016 | |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 1017 | seq_printf(s, " irq-%d %s%s", |
| 1018 | irq, trigger, |
| 1019 | irqd_is_wakeup_set(&desc->irq_data) |
| 1020 | ? " wakeup" : ""); |
Rabin Vincent | 8ea72a3 | 2011-05-24 23:07:09 +0200 | [diff] [blame] | 1021 | } |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 1022 | } |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 1023 | clk_disable(nmk_chip->clk); |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 1024 | } |
| 1025 | |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 1026 | static void nmk_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) |
| 1027 | { |
| 1028 | unsigned i; |
| 1029 | unsigned gpio = chip->base; |
| 1030 | |
| 1031 | for (i = 0; i < chip->ngpio; i++, gpio++) { |
| 1032 | nmk_gpio_dbg_show_one(s, chip, i, gpio); |
| 1033 | seq_printf(s, "\n"); |
| 1034 | } |
| 1035 | } |
| 1036 | |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 1037 | #else |
Linus Walleij | 6f4350a | 2012-05-02 21:06:13 +0200 | [diff] [blame] | 1038 | static inline void nmk_gpio_dbg_show_one(struct seq_file *s, |
| 1039 | struct gpio_chip *chip, |
| 1040 | unsigned offset, unsigned gpio) |
| 1041 | { |
| 1042 | } |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 1043 | #define nmk_gpio_dbg_show NULL |
| 1044 | #endif |
| 1045 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1046 | /* This structure is replicated for each GPIO block allocated at probe time */ |
| 1047 | static struct gpio_chip nmk_gpio_template = { |
Linus Walleij | dbfe8ca | 2012-05-02 22:56:47 +0200 | [diff] [blame^] | 1048 | .request = nmk_gpio_request, |
| 1049 | .free = nmk_gpio_free, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1050 | .direction_input = nmk_gpio_make_input, |
| 1051 | .get = nmk_gpio_get_input, |
| 1052 | .direction_output = nmk_gpio_make_output, |
| 1053 | .set = nmk_gpio_set_output, |
Rabin Vincent | 0d2aec9 | 2010-06-16 06:10:43 +0100 | [diff] [blame] | 1054 | .to_irq = nmk_gpio_to_irq, |
Rabin Vincent | d0b543c | 2010-03-04 17:39:05 +0530 | [diff] [blame] | 1055 | .dbg_show = nmk_gpio_dbg_show, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1056 | .can_sleep = 0, |
| 1057 | }; |
| 1058 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 1059 | void nmk_gpio_clocks_enable(void) |
| 1060 | { |
| 1061 | int i; |
| 1062 | |
| 1063 | for (i = 0; i < NUM_BANKS; i++) { |
| 1064 | struct nmk_gpio_chip *chip = nmk_gpio_chips[i]; |
| 1065 | |
| 1066 | if (!chip) |
| 1067 | continue; |
| 1068 | |
| 1069 | clk_enable(chip->clk); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | void nmk_gpio_clocks_disable(void) |
| 1074 | { |
| 1075 | int i; |
| 1076 | |
| 1077 | for (i = 0; i < NUM_BANKS; i++) { |
| 1078 | struct nmk_gpio_chip *chip = nmk_gpio_chips[i]; |
| 1079 | |
| 1080 | if (!chip) |
| 1081 | continue; |
| 1082 | |
| 1083 | clk_disable(chip->clk); |
| 1084 | } |
| 1085 | } |
| 1086 | |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 1087 | /* |
| 1088 | * Called from the suspend/resume path to only keep the real wakeup interrupts |
| 1089 | * (those that have had set_irq_wake() called on them) as wakeup interrupts, |
| 1090 | * and not the rest of the interrupts which we needed to have as wakeups for |
| 1091 | * cpuidle. |
| 1092 | * |
| 1093 | * PM ops are not used since this needs to be done at the end, after all the |
| 1094 | * other drivers are done with their suspend callbacks. |
| 1095 | */ |
| 1096 | void nmk_gpio_wakeups_suspend(void) |
| 1097 | { |
| 1098 | int i; |
| 1099 | |
| 1100 | for (i = 0; i < NUM_BANKS; i++) { |
| 1101 | struct nmk_gpio_chip *chip = nmk_gpio_chips[i]; |
| 1102 | |
| 1103 | if (!chip) |
| 1104 | break; |
| 1105 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 1106 | clk_enable(chip->clk); |
| 1107 | |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 1108 | writel(chip->rwimsc & chip->real_wake, |
| 1109 | chip->addr + NMK_GPIO_RWIMSC); |
| 1110 | writel(chip->fwimsc & chip->real_wake, |
| 1111 | chip->addr + NMK_GPIO_FWIMSC); |
| 1112 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 1113 | clk_disable(chip->clk); |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | void nmk_gpio_wakeups_resume(void) |
| 1118 | { |
| 1119 | int i; |
| 1120 | |
| 1121 | for (i = 0; i < NUM_BANKS; i++) { |
| 1122 | struct nmk_gpio_chip *chip = nmk_gpio_chips[i]; |
| 1123 | |
| 1124 | if (!chip) |
| 1125 | break; |
| 1126 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 1127 | clk_enable(chip->clk); |
| 1128 | |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 1129 | writel(chip->rwimsc, chip->addr + NMK_GPIO_RWIMSC); |
| 1130 | writel(chip->fwimsc, chip->addr + NMK_GPIO_FWIMSC); |
| 1131 | |
Rabin Vincent | 3c0227d | 2011-09-20 10:50:03 +0200 | [diff] [blame] | 1132 | clk_disable(chip->clk); |
Rabin Vincent | b9df468 | 2011-02-10 11:45:58 +0530 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | |
Rickard Andersson | bc6f5cf | 2011-05-24 23:07:17 +0200 | [diff] [blame] | 1136 | /* |
| 1137 | * Read the pull up/pull down status. |
| 1138 | * A bit set in 'pull_up' means that pull up |
| 1139 | * is selected if pull is enabled in PDIS register. |
| 1140 | * Note: only pull up/down set via this driver can |
| 1141 | * be detected due to HW limitations. |
| 1142 | */ |
| 1143 | void nmk_gpio_read_pull(int gpio_bank, u32 *pull_up) |
| 1144 | { |
| 1145 | if (gpio_bank < NUM_BANKS) { |
| 1146 | struct nmk_gpio_chip *chip = nmk_gpio_chips[gpio_bank]; |
| 1147 | |
| 1148 | if (!chip) |
| 1149 | return; |
| 1150 | |
| 1151 | *pull_up = chip->pull_up; |
| 1152 | } |
| 1153 | } |
| 1154 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 1155 | int nmk_gpio_irq_map(struct irq_domain *d, unsigned int irq, |
| 1156 | irq_hw_number_t hwirq) |
| 1157 | { |
| 1158 | struct nmk_gpio_chip *nmk_chip = d->host_data; |
| 1159 | |
| 1160 | if (!nmk_chip) |
| 1161 | return -EINVAL; |
| 1162 | |
| 1163 | irq_set_chip_and_handler(irq, &nmk_gpio_irq_chip, handle_edge_irq); |
| 1164 | set_irq_flags(irq, IRQF_VALID); |
| 1165 | irq_set_chip_data(irq, nmk_chip); |
| 1166 | irq_set_irq_type(irq, IRQ_TYPE_EDGE_FALLING); |
| 1167 | |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | const struct irq_domain_ops nmk_gpio_irq_simple_ops = { |
| 1172 | .map = nmk_gpio_irq_map, |
| 1173 | .xlate = irq_domain_xlate_twocell, |
| 1174 | }; |
| 1175 | |
Uwe Kleine-König | fd0d67d | 2010-09-02 16:13:35 +0100 | [diff] [blame] | 1176 | static int __devinit nmk_gpio_probe(struct platform_device *dev) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1177 | { |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1178 | struct nmk_gpio_platform_data *pdata = dev->dev.platform_data; |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1179 | struct device_node *np = dev->dev.of_node; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1180 | struct nmk_gpio_chip *nmk_chip; |
| 1181 | struct gpio_chip *chip; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1182 | struct resource *res; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 1183 | struct clk *clk; |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 1184 | int secondary_irq; |
Linus Walleij | 8d91771 | 2012-04-17 10:15:54 +0200 | [diff] [blame] | 1185 | void __iomem *base; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1186 | int irq; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1187 | int ret; |
| 1188 | |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1189 | if (!pdata && !np) { |
| 1190 | dev_err(&dev->dev, "No platform data or device tree found\n"); |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1191 | return -ENODEV; |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | if (np) { |
| 1195 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); |
| 1196 | if (!pdata) |
| 1197 | return -ENOMEM; |
| 1198 | |
| 1199 | if (of_get_property(np, "supports-sleepmode", NULL)) |
| 1200 | pdata->supports_sleepmode = true; |
| 1201 | |
| 1202 | if (of_property_read_u32(np, "gpio-bank", &dev->id)) { |
| 1203 | dev_err(&dev->dev, "gpio-bank property not found\n"); |
| 1204 | ret = -EINVAL; |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 1205 | goto out; |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | pdata->first_gpio = dev->id * NMK_GPIO_PER_CHIP; |
| 1209 | pdata->num_gpio = NMK_GPIO_PER_CHIP; |
| 1210 | } |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1211 | |
| 1212 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 1213 | if (!res) { |
| 1214 | ret = -ENOENT; |
| 1215 | goto out; |
| 1216 | } |
| 1217 | |
| 1218 | irq = platform_get_irq(dev, 0); |
| 1219 | if (irq < 0) { |
| 1220 | ret = irq; |
| 1221 | goto out; |
| 1222 | } |
| 1223 | |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 1224 | secondary_irq = platform_get_irq(dev, 1); |
| 1225 | if (secondary_irq >= 0 && !pdata->get_secondary_status) { |
| 1226 | ret = -EINVAL; |
| 1227 | goto out; |
| 1228 | } |
| 1229 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1230 | if (request_mem_region(res->start, resource_size(res), |
| 1231 | dev_name(&dev->dev)) == NULL) { |
| 1232 | ret = -EBUSY; |
| 1233 | goto out; |
| 1234 | } |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1235 | |
Linus Walleij | 8d91771 | 2012-04-17 10:15:54 +0200 | [diff] [blame] | 1236 | base = ioremap(res->start, resource_size(res)); |
| 1237 | if (!base) { |
| 1238 | ret = -ENOMEM; |
| 1239 | goto out_release; |
| 1240 | } |
| 1241 | |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 1242 | clk = clk_get(&dev->dev, NULL); |
| 1243 | if (IS_ERR(clk)) { |
| 1244 | ret = PTR_ERR(clk); |
Linus Walleij | 8d91771 | 2012-04-17 10:15:54 +0200 | [diff] [blame] | 1245 | goto out_unmap; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 1246 | } |
| 1247 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1248 | nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL); |
| 1249 | if (!nmk_chip) { |
| 1250 | ret = -ENOMEM; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 1251 | goto out_clk; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1252 | } |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1253 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1254 | /* |
| 1255 | * The virt address in nmk_chip->addr is in the nomadik register space, |
| 1256 | * so we can simply convert the resource address, without remapping |
| 1257 | */ |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 1258 | nmk_chip->bank = dev->id; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 1259 | nmk_chip->clk = clk; |
Linus Walleij | 8d91771 | 2012-04-17 10:15:54 +0200 | [diff] [blame] | 1260 | nmk_chip->addr = base; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1261 | nmk_chip->chip = nmk_gpio_template; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1262 | nmk_chip->parent_irq = irq; |
Rabin Vincent | 33b744b | 2010-10-14 10:38:03 +0530 | [diff] [blame] | 1263 | nmk_chip->secondary_parent_irq = secondary_irq; |
| 1264 | nmk_chip->get_secondary_status = pdata->get_secondary_status; |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 1265 | nmk_chip->set_ioforce = pdata->set_ioforce; |
Linus Walleij | 33d7864 | 2011-06-09 11:08:47 +0200 | [diff] [blame] | 1266 | nmk_chip->sleepmode = pdata->supports_sleepmode; |
Rabin Vincent | c0fcb8d | 2010-03-03 04:48:54 +0100 | [diff] [blame] | 1267 | spin_lock_init(&nmk_chip->lock); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1268 | |
| 1269 | chip = &nmk_chip->chip; |
| 1270 | chip->base = pdata->first_gpio; |
Rabin Vincent | e493e06 | 2010-03-18 12:35:22 +0530 | [diff] [blame] | 1271 | chip->ngpio = pdata->num_gpio; |
Rabin Vincent | 8d568ae | 2010-12-08 11:07:54 +0530 | [diff] [blame] | 1272 | chip->label = pdata->name ?: dev_name(&dev->dev); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1273 | chip->dev = &dev->dev; |
| 1274 | chip->owner = THIS_MODULE; |
| 1275 | |
Rabin Vincent | ebc6178 | 2011-09-28 15:49:11 +0530 | [diff] [blame] | 1276 | clk_enable(nmk_chip->clk); |
| 1277 | nmk_chip->lowemi = readl_relaxed(nmk_chip->addr + NMK_GPIO_LOWEMI); |
| 1278 | clk_disable(nmk_chip->clk); |
| 1279 | |
Arnd Bergmann | 072e82a | 2012-05-10 13:39:52 +0200 | [diff] [blame] | 1280 | #ifdef CONFIG_OF_GPIO |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1281 | chip->of_node = np; |
Arnd Bergmann | 072e82a | 2012-05-10 13:39:52 +0200 | [diff] [blame] | 1282 | #endif |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1283 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1284 | ret = gpiochip_add(&nmk_chip->chip); |
| 1285 | if (ret) |
| 1286 | goto out_free; |
| 1287 | |
Rabin Vincent | 01727e6 | 2010-12-13 12:02:40 +0530 | [diff] [blame] | 1288 | BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips)); |
| 1289 | |
| 1290 | nmk_gpio_chips[nmk_chip->bank] = nmk_chip; |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1291 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1292 | platform_set_drvdata(dev, nmk_chip); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1293 | |
Lee Jones | a60b57e | 2012-04-19 21:36:31 +0100 | [diff] [blame] | 1294 | nmk_chip->domain = irq_domain_add_legacy(np, NMK_GPIO_PER_CHIP, |
| 1295 | NOMADIK_GPIO_TO_IRQ(pdata->first_gpio), |
| 1296 | 0, &nmk_gpio_irq_simple_ops, nmk_chip); |
| 1297 | if (!nmk_chip->domain) { |
| 1298 | pr_err("%s: Failed to create irqdomain\n", np->full_name); |
| 1299 | ret = -ENOSYS; |
| 1300 | goto out_free; |
| 1301 | } |
| 1302 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1303 | nmk_gpio_init_irq(nmk_chip); |
| 1304 | |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1305 | dev_info(&dev->dev, "at address %p\n", nmk_chip->addr); |
| 1306 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1307 | return 0; |
| 1308 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1309 | out_free: |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1310 | kfree(nmk_chip); |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 1311 | out_clk: |
| 1312 | clk_disable(clk); |
| 1313 | clk_put(clk); |
Linus Walleij | 8d91771 | 2012-04-17 10:15:54 +0200 | [diff] [blame] | 1314 | out_unmap: |
| 1315 | iounmap(base); |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1316 | out_release: |
| 1317 | release_mem_region(res->start, resource_size(res)); |
| 1318 | out: |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1319 | dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret, |
| 1320 | pdata->first_gpio, pdata->first_gpio+31); |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1321 | if (np) |
| 1322 | kfree(pdata); |
| 1323 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1324 | return ret; |
| 1325 | } |
| 1326 | |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 1327 | static int nmk_get_groups_cnt(struct pinctrl_dev *pctldev) |
| 1328 | { |
| 1329 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1330 | |
| 1331 | return npct->soc->ngroups; |
| 1332 | } |
| 1333 | |
| 1334 | static const char *nmk_get_group_name(struct pinctrl_dev *pctldev, |
| 1335 | unsigned selector) |
| 1336 | { |
| 1337 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1338 | |
| 1339 | return npct->soc->groups[selector].name; |
| 1340 | } |
| 1341 | |
| 1342 | static int nmk_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector, |
| 1343 | const unsigned **pins, |
| 1344 | unsigned *num_pins) |
| 1345 | { |
| 1346 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1347 | |
| 1348 | *pins = npct->soc->groups[selector].pins; |
| 1349 | *num_pins = npct->soc->groups[selector].npins; |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
Linus Walleij | 24cbdd7 | 2012-05-02 21:28:00 +0200 | [diff] [blame] | 1353 | static struct pinctrl_gpio_range * |
| 1354 | nmk_match_gpio_range(struct pinctrl_dev *pctldev, unsigned offset) |
| 1355 | { |
| 1356 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1357 | int i; |
| 1358 | |
| 1359 | for (i = 0; i < npct->soc->gpio_num_ranges; i++) { |
| 1360 | struct pinctrl_gpio_range *range; |
| 1361 | |
| 1362 | range = &npct->soc->gpio_ranges[i]; |
| 1363 | if (offset >= range->pin_base && |
| 1364 | offset <= (range->pin_base + range->npins - 1)) |
| 1365 | return range; |
| 1366 | } |
| 1367 | return NULL; |
| 1368 | } |
| 1369 | |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 1370 | static void nmk_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, |
| 1371 | unsigned offset) |
| 1372 | { |
Linus Walleij | 24cbdd7 | 2012-05-02 21:28:00 +0200 | [diff] [blame] | 1373 | struct pinctrl_gpio_range *range; |
| 1374 | struct gpio_chip *chip; |
| 1375 | |
| 1376 | range = nmk_match_gpio_range(pctldev, offset); |
| 1377 | if (!range || !range->gc) { |
| 1378 | seq_printf(s, "invalid pin offset"); |
| 1379 | return; |
| 1380 | } |
| 1381 | chip = range->gc; |
| 1382 | nmk_gpio_dbg_show_one(s, chip, offset - chip->base, offset); |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | static struct pinctrl_ops nmk_pinctrl_ops = { |
| 1386 | .get_groups_count = nmk_get_groups_cnt, |
| 1387 | .get_group_name = nmk_get_group_name, |
| 1388 | .get_group_pins = nmk_get_group_pins, |
| 1389 | .pin_dbg_show = nmk_pin_dbg_show, |
| 1390 | }; |
| 1391 | |
Linus Walleij | dbfe8ca | 2012-05-02 22:56:47 +0200 | [diff] [blame^] | 1392 | static int nmk_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev) |
| 1393 | { |
| 1394 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1395 | |
| 1396 | return npct->soc->nfunctions; |
| 1397 | } |
| 1398 | |
| 1399 | static const char *nmk_pmx_get_func_name(struct pinctrl_dev *pctldev, |
| 1400 | unsigned function) |
| 1401 | { |
| 1402 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1403 | |
| 1404 | return npct->soc->functions[function].name; |
| 1405 | } |
| 1406 | |
| 1407 | static int nmk_pmx_get_func_groups(struct pinctrl_dev *pctldev, |
| 1408 | unsigned function, |
| 1409 | const char * const **groups, |
| 1410 | unsigned * const num_groups) |
| 1411 | { |
| 1412 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1413 | |
| 1414 | *groups = npct->soc->functions[function].groups; |
| 1415 | *num_groups = npct->soc->functions[function].ngroups; |
| 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
| 1420 | static int nmk_pmx_enable(struct pinctrl_dev *pctldev, unsigned function, |
| 1421 | unsigned group) |
| 1422 | { |
| 1423 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1424 | const struct nmk_pingroup *g; |
| 1425 | static unsigned int slpm[NUM_BANKS]; |
| 1426 | unsigned long flags; |
| 1427 | bool glitch; |
| 1428 | int ret = -EINVAL; |
| 1429 | int i; |
| 1430 | |
| 1431 | g = &npct->soc->groups[group]; |
| 1432 | |
| 1433 | if (g->altsetting < 0) |
| 1434 | return -EINVAL; |
| 1435 | |
| 1436 | dev_dbg(npct->dev, "enable group %s, %u pins\n", g->name, g->npins); |
| 1437 | |
| 1438 | /* Handle this special glitch on altfunction C */ |
| 1439 | glitch = (g->altsetting == NMK_GPIO_ALT_C); |
| 1440 | |
| 1441 | if (glitch) { |
| 1442 | spin_lock_irqsave(&nmk_gpio_slpm_lock, flags); |
| 1443 | |
| 1444 | /* Initially don't put any pins to sleep when switching */ |
| 1445 | memset(slpm, 0xff, sizeof(slpm)); |
| 1446 | |
| 1447 | /* |
| 1448 | * Then mask the pins that need to be sleeping now when we're |
| 1449 | * switching to the ALT C function. |
| 1450 | */ |
| 1451 | for (i = 0; i < g->npins; i++) |
| 1452 | slpm[g->pins[i] / NMK_GPIO_PER_CHIP] &= ~BIT(g->pins[i]); |
| 1453 | nmk_gpio_glitch_slpm_init(slpm); |
| 1454 | } |
| 1455 | |
| 1456 | for (i = 0; i < g->npins; i++) { |
| 1457 | struct pinctrl_gpio_range *range; |
| 1458 | struct nmk_gpio_chip *nmk_chip; |
| 1459 | struct gpio_chip *chip; |
| 1460 | unsigned bit; |
| 1461 | |
| 1462 | range = nmk_match_gpio_range(pctldev, g->pins[i]); |
| 1463 | if (!range) { |
| 1464 | dev_err(npct->dev, |
| 1465 | "invalid pin offset %d in group %s at index %d\n", |
| 1466 | g->pins[i], g->name, i); |
| 1467 | goto out_glitch; |
| 1468 | } |
| 1469 | if (!range->gc) { |
| 1470 | dev_err(npct->dev, "GPIO chip missing in range for pin offset %d in group %s at index %d\n", |
| 1471 | g->pins[i], g->name, i); |
| 1472 | goto out_glitch; |
| 1473 | } |
| 1474 | chip = range->gc; |
| 1475 | nmk_chip = container_of(chip, struct nmk_gpio_chip, chip); |
| 1476 | dev_dbg(npct->dev, "setting pin %d to altsetting %d\n", g->pins[i], g->altsetting); |
| 1477 | |
| 1478 | clk_enable(nmk_chip->clk); |
| 1479 | bit = g->pins[i] % NMK_GPIO_PER_CHIP; |
| 1480 | /* |
| 1481 | * If the pin is switching to altfunc, and there was an |
| 1482 | * interrupt installed on it which has been lazy disabled, |
| 1483 | * actually mask the interrupt to prevent spurious interrupts |
| 1484 | * that would occur while the pin is under control of the |
| 1485 | * peripheral. Only SKE does this. |
| 1486 | */ |
| 1487 | nmk_gpio_disable_lazy_irq(nmk_chip, bit); |
| 1488 | |
| 1489 | __nmk_gpio_set_mode_safe(nmk_chip, bit, g->altsetting, glitch); |
| 1490 | clk_disable(nmk_chip->clk); |
| 1491 | } |
| 1492 | |
| 1493 | /* When all pins are successfully reconfigured we get here */ |
| 1494 | ret = 0; |
| 1495 | |
| 1496 | out_glitch: |
| 1497 | if (glitch) { |
| 1498 | nmk_gpio_glitch_slpm_restore(slpm); |
| 1499 | spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags); |
| 1500 | } |
| 1501 | |
| 1502 | return ret; |
| 1503 | } |
| 1504 | |
| 1505 | static void nmk_pmx_disable(struct pinctrl_dev *pctldev, |
| 1506 | unsigned function, unsigned group) |
| 1507 | { |
| 1508 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1509 | const struct nmk_pingroup *g; |
| 1510 | |
| 1511 | g = &npct->soc->groups[group]; |
| 1512 | |
| 1513 | if (g->altsetting < 0) |
| 1514 | return; |
| 1515 | |
| 1516 | /* Poke out the mux, set the pin to some default state? */ |
| 1517 | dev_dbg(npct->dev, "disable group %s, %u pins\n", g->name, g->npins); |
| 1518 | } |
| 1519 | |
| 1520 | int nmk_gpio_request_enable(struct pinctrl_dev *pctldev, |
| 1521 | struct pinctrl_gpio_range *range, |
| 1522 | unsigned offset) |
| 1523 | { |
| 1524 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1525 | struct nmk_gpio_chip *nmk_chip; |
| 1526 | struct gpio_chip *chip; |
| 1527 | unsigned bit; |
| 1528 | |
| 1529 | if (!range) { |
| 1530 | dev_err(npct->dev, "invalid range\n"); |
| 1531 | return -EINVAL; |
| 1532 | } |
| 1533 | if (!range->gc) { |
| 1534 | dev_err(npct->dev, "missing GPIO chip in range\n"); |
| 1535 | return -EINVAL; |
| 1536 | } |
| 1537 | chip = range->gc; |
| 1538 | nmk_chip = container_of(chip, struct nmk_gpio_chip, chip); |
| 1539 | |
| 1540 | dev_dbg(npct->dev, "enable pin %u as GPIO\n", offset); |
| 1541 | |
| 1542 | clk_enable(nmk_chip->clk); |
| 1543 | bit = offset % NMK_GPIO_PER_CHIP; |
| 1544 | /* There is no glitch when converting any pin to GPIO */ |
| 1545 | __nmk_gpio_set_mode(nmk_chip, bit, NMK_GPIO_ALT_GPIO); |
| 1546 | clk_disable(nmk_chip->clk); |
| 1547 | |
| 1548 | return 0; |
| 1549 | } |
| 1550 | |
| 1551 | void nmk_gpio_disable_free(struct pinctrl_dev *pctldev, |
| 1552 | struct pinctrl_gpio_range *range, |
| 1553 | unsigned offset) |
| 1554 | { |
| 1555 | struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev); |
| 1556 | |
| 1557 | dev_dbg(npct->dev, "disable pin %u as GPIO\n", offset); |
| 1558 | /* Set the pin to some default state, GPIO is usually default */ |
| 1559 | } |
| 1560 | |
| 1561 | static struct pinmux_ops nmk_pinmux_ops = { |
| 1562 | .get_functions_count = nmk_pmx_get_funcs_cnt, |
| 1563 | .get_function_name = nmk_pmx_get_func_name, |
| 1564 | .get_function_groups = nmk_pmx_get_func_groups, |
| 1565 | .enable = nmk_pmx_enable, |
| 1566 | .disable = nmk_pmx_disable, |
| 1567 | .gpio_request_enable = nmk_gpio_request_enable, |
| 1568 | .gpio_disable_free = nmk_gpio_disable_free, |
| 1569 | }; |
| 1570 | |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 1571 | static struct pinctrl_desc nmk_pinctrl_desc = { |
| 1572 | .name = "pinctrl-nomadik", |
| 1573 | .pctlops = &nmk_pinctrl_ops, |
Linus Walleij | dbfe8ca | 2012-05-02 22:56:47 +0200 | [diff] [blame^] | 1574 | .pmxops = &nmk_pinmux_ops, |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 1575 | .owner = THIS_MODULE, |
| 1576 | }; |
| 1577 | |
| 1578 | static int __devinit nmk_pinctrl_probe(struct platform_device *pdev) |
| 1579 | { |
| 1580 | const struct platform_device_id *platid = platform_get_device_id(pdev); |
| 1581 | struct nmk_pinctrl *npct; |
| 1582 | int i; |
| 1583 | |
| 1584 | npct = devm_kzalloc(&pdev->dev, sizeof(*npct), GFP_KERNEL); |
| 1585 | if (!npct) |
| 1586 | return -ENOMEM; |
| 1587 | |
| 1588 | /* Poke in other ASIC variants here */ |
| 1589 | if (platid->driver_data == PINCTRL_NMK_DB8500) |
| 1590 | nmk_pinctrl_db8500_init(&npct->soc); |
| 1591 | |
| 1592 | /* |
| 1593 | * We need all the GPIO drivers to probe FIRST, or we will not be able |
| 1594 | * to obtain references to the struct gpio_chip * for them, and we |
| 1595 | * need this to proceed. |
| 1596 | */ |
| 1597 | for (i = 0; i < npct->soc->gpio_num_ranges; i++) { |
| 1598 | if (!nmk_gpio_chips[i]) { |
| 1599 | dev_warn(&pdev->dev, "GPIO chip %d not registered yet\n", i); |
| 1600 | devm_kfree(&pdev->dev, npct); |
| 1601 | return -EPROBE_DEFER; |
| 1602 | } |
| 1603 | npct->soc->gpio_ranges[i].gc = &nmk_gpio_chips[i]->chip; |
| 1604 | } |
| 1605 | |
| 1606 | nmk_pinctrl_desc.pins = npct->soc->pins; |
| 1607 | nmk_pinctrl_desc.npins = npct->soc->npins; |
| 1608 | npct->dev = &pdev->dev; |
| 1609 | npct->pctl = pinctrl_register(&nmk_pinctrl_desc, &pdev->dev, npct); |
| 1610 | if (!npct->pctl) { |
| 1611 | dev_err(&pdev->dev, "could not register Nomadik pinctrl driver\n"); |
| 1612 | return -EINVAL; |
| 1613 | } |
| 1614 | |
| 1615 | /* We will handle a range of GPIO pins */ |
| 1616 | for (i = 0; i < npct->soc->gpio_num_ranges; i++) |
| 1617 | pinctrl_add_gpio_range(npct->pctl, &npct->soc->gpio_ranges[i]); |
| 1618 | |
| 1619 | platform_set_drvdata(pdev, npct); |
| 1620 | dev_info(&pdev->dev, "initialized Nomadik pin control driver\n"); |
| 1621 | |
| 1622 | return 0; |
| 1623 | } |
| 1624 | |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1625 | static const struct of_device_id nmk_gpio_match[] = { |
| 1626 | { .compatible = "st,nomadik-gpio", }, |
| 1627 | {} |
| 1628 | }; |
| 1629 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 1630 | static struct platform_driver nmk_gpio_driver = { |
| 1631 | .driver = { |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1632 | .owner = THIS_MODULE, |
| 1633 | .name = "gpio", |
Lee Jones | 513c27f | 2012-04-13 15:05:05 +0100 | [diff] [blame] | 1634 | .of_match_table = nmk_gpio_match, |
Rabin Vincent | 5317e4d1 | 2011-02-10 09:29:53 +0530 | [diff] [blame] | 1635 | }, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1636 | .probe = nmk_gpio_probe, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1637 | }; |
| 1638 | |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 1639 | static const struct platform_device_id nmk_pinctrl_id[] = { |
| 1640 | { "pinctrl-stn8815", PINCTRL_NMK_STN8815 }, |
| 1641 | { "pinctrl-db8500", PINCTRL_NMK_DB8500 }, |
| 1642 | }; |
| 1643 | |
| 1644 | static struct platform_driver nmk_pinctrl_driver = { |
| 1645 | .driver = { |
| 1646 | .owner = THIS_MODULE, |
| 1647 | .name = "pinctrl-nomadik", |
| 1648 | }, |
| 1649 | .probe = nmk_pinctrl_probe, |
| 1650 | .id_table = nmk_pinctrl_id, |
| 1651 | }; |
| 1652 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1653 | static int __init nmk_gpio_init(void) |
| 1654 | { |
Linus Walleij | e98ea77 | 2012-04-26 23:57:25 +0200 | [diff] [blame] | 1655 | int ret; |
| 1656 | |
| 1657 | ret = platform_driver_register(&nmk_gpio_driver); |
| 1658 | if (ret) |
| 1659 | return ret; |
| 1660 | return platform_driver_register(&nmk_pinctrl_driver); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
Rabin Vincent | 33f45ea | 2010-06-02 06:09:52 +0100 | [diff] [blame] | 1663 | core_initcall(nmk_gpio_init); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1664 | |
| 1665 | MODULE_AUTHOR("Prafulla WADASKAR and Alessandro Rubini"); |
| 1666 | MODULE_DESCRIPTION("Nomadik GPIO Driver"); |
| 1667 | MODULE_LICENSE("GPL"); |