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