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