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