blob: ec3a5742e413d8a60e1cb1d0b1b86dfbe8ecb0aa [file] [log] [blame]
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001/*
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 Walleij33d78642011-06-09 11:08:47 +02007 * Copyright (C) 2011 Linus Walleij <linus.walleij@linaro.org>
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01008 *
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 Vincent3e3c62c2010-03-03 04:52:34 +010017#include <linux/platform_device.h>
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010018#include <linux/io.h>
Rabin Vincentaf7dc222010-05-06 11:14:17 +010019#include <linux/clk.h>
20#include <linux/err.h>
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010021#include <linux/gpio.h>
22#include <linux/spinlock.h>
23#include <linux/interrupt.h>
24#include <linux/irq.h>
Lee Jonesa60b57e2012-04-19 21:36:31 +010025#include <linux/irqdomain.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Lee Jones855f80c2012-05-26 06:09:29 +010027#include <linux/of_device.h>
Gabriel Fernandeze32af882012-12-17 15:53:24 +010028#include <linux/pinctrl/machine.h>
Linus Walleije98ea772012-04-26 23:57:25 +020029#include <linux/pinctrl/pinctrl.h>
Linus Walleijdbfe8ca2012-05-02 22:56:47 +020030#include <linux/pinctrl/pinmux.h>
Linus Walleijd41af622012-05-03 15:58:12 +020031#include <linux/pinctrl/pinconf.h>
Linus Walleijdbfe8ca2012-05-02 22:56:47 +020032/* Since we request GPIOs from ourself */
33#include <linux/pinctrl/consumer.h>
Linus Walleijbb16bd92012-10-10 14:27:58 +020034#include <linux/platform_data/pinctrl-nomadik.h>
Will Deaconadfed152011-02-28 10:12:29 +000035#include <asm/mach/irq.h>
Linus Walleije98ea772012-04-26 23:57:25 +020036#include "pinctrl-nomadik.h"
Julien Delacou8d99b322012-12-11 09:17:47 +010037#include "core.h"
Linus Walleije98ea772012-04-26 23:57:25 +020038
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010039/*
40 * The GPIO module in the Nomadik family of Systems-on-Chip is an
41 * AMBA device, managing 32 pins and alternate functions. The logic block
Jonas Aaberg9c66ee62010-10-13 13:14:17 +020042 * is currently used in the Nomadik and ux500.
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010043 *
44 * Symbols in this file are called "nmk_gpio" for "nomadik gpio"
45 */
46
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010047struct nmk_gpio_chip {
48 struct gpio_chip chip;
Lee Jonesa60b57e2012-04-19 21:36:31 +010049 struct irq_domain *domain;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010050 void __iomem *addr;
Rabin Vincentaf7dc222010-05-06 11:14:17 +010051 struct clk *clk;
Rabin Vincent33b744b2010-10-14 10:38:03 +053052 unsigned int bank;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010053 unsigned int parent_irq;
Virupax Sadashivpetimath2c8bb0e2010-11-11 14:10:38 +053054 int secondary_parent_irq;
Rabin Vincent33b744b2010-10-14 10:38:03 +053055 u32 (*get_secondary_status)(unsigned int bank);
Rabin Vincent01727e62010-12-13 12:02:40 +053056 void (*set_ioforce)(bool enable);
Rabin Vincentc0fcb8d2010-03-03 04:48:54 +010057 spinlock_t lock;
Linus Walleij33d78642011-06-09 11:08:47 +020058 bool sleepmode;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010059 /* Keep track of configured edges */
60 u32 edge_rising;
61 u32 edge_falling;
Rabin Vincentb9df4682011-02-10 11:45:58 +053062 u32 real_wake;
63 u32 rwimsc;
64 u32 fwimsc;
Rabin Vincent6c12fe82011-05-23 12:13:33 +053065 u32 rimsc;
66 u32 fimsc;
Rickard Anderssonbc6f5cf2011-05-24 23:07:17 +020067 u32 pull_up;
Rabin Vincentebc61782011-09-28 15:49:11 +053068 u32 lowemi;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010069};
70
Jonas Aabergf1671bf2012-10-25 08:40:42 +020071/**
72 * struct nmk_pinctrl - state container for the Nomadik pin controller
73 * @dev: containing device pointer
74 * @pctl: corresponding pin controller device
75 * @soc: SoC data for this specific chip
76 * @prcm_base: PRCM register range virtual base
77 */
Linus Walleije98ea772012-04-26 23:57:25 +020078struct nmk_pinctrl {
79 struct device *dev;
80 struct pinctrl_dev *pctl;
81 const struct nmk_pinctrl_soc_data *soc;
Jonas Aabergf1671bf2012-10-25 08:40:42 +020082 void __iomem *prcm_base;
Linus Walleije98ea772012-04-26 23:57:25 +020083};
84
Rabin Vincent01727e62010-12-13 12:02:40 +053085static struct nmk_gpio_chip *
86nmk_gpio_chips[DIV_ROUND_UP(ARCH_NR_GPIOS, NMK_GPIO_PER_CHIP)];
87
88static DEFINE_SPINLOCK(nmk_gpio_slpm_lock);
89
90#define NUM_BANKS ARRAY_SIZE(nmk_gpio_chips)
91
Rabin Vincent6f9a9742010-06-02 05:50:28 +010092static void __nmk_gpio_set_mode(struct nmk_gpio_chip *nmk_chip,
93 unsigned offset, int gpio_mode)
94{
95 u32 bit = 1 << offset;
96 u32 afunc, bfunc;
97
98 afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & ~bit;
99 bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & ~bit;
100 if (gpio_mode & NMK_GPIO_ALT_A)
101 afunc |= bit;
102 if (gpio_mode & NMK_GPIO_ALT_B)
103 bfunc |= bit;
104 writel(afunc, nmk_chip->addr + NMK_GPIO_AFSLA);
105 writel(bfunc, nmk_chip->addr + NMK_GPIO_AFSLB);
106}
107
Rabin Vincent81a3c292010-05-27 12:39:23 +0100108static void __nmk_gpio_set_slpm(struct nmk_gpio_chip *nmk_chip,
109 unsigned offset, enum nmk_gpio_slpm mode)
110{
111 u32 bit = 1 << offset;
112 u32 slpm;
113
114 slpm = readl(nmk_chip->addr + NMK_GPIO_SLPC);
115 if (mode == NMK_GPIO_SLPM_NOCHANGE)
116 slpm |= bit;
117 else
118 slpm &= ~bit;
119 writel(slpm, nmk_chip->addr + NMK_GPIO_SLPC);
120}
121
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100122static void __nmk_gpio_set_pull(struct nmk_gpio_chip *nmk_chip,
123 unsigned offset, enum nmk_gpio_pull pull)
124{
125 u32 bit = 1 << offset;
126 u32 pdis;
127
128 pdis = readl(nmk_chip->addr + NMK_GPIO_PDIS);
Rickard Anderssonbc6f5cf2011-05-24 23:07:17 +0200129 if (pull == NMK_GPIO_PULL_NONE) {
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100130 pdis |= bit;
Rickard Anderssonbc6f5cf2011-05-24 23:07:17 +0200131 nmk_chip->pull_up &= ~bit;
132 } else {
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100133 pdis &= ~bit;
Rickard Anderssonbc6f5cf2011-05-24 23:07:17 +0200134 }
135
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100136 writel(pdis, nmk_chip->addr + NMK_GPIO_PDIS);
137
Rickard Anderssonbc6f5cf2011-05-24 23:07:17 +0200138 if (pull == NMK_GPIO_PULL_UP) {
139 nmk_chip->pull_up |= bit;
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100140 writel(bit, nmk_chip->addr + NMK_GPIO_DATS);
Rickard Anderssonbc6f5cf2011-05-24 23:07:17 +0200141 } else if (pull == NMK_GPIO_PULL_DOWN) {
142 nmk_chip->pull_up &= ~bit;
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100143 writel(bit, nmk_chip->addr + NMK_GPIO_DATC);
Rickard Anderssonbc6f5cf2011-05-24 23:07:17 +0200144 }
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100145}
146
Rabin Vincentebc61782011-09-28 15:49:11 +0530147static void __nmk_gpio_set_lowemi(struct nmk_gpio_chip *nmk_chip,
148 unsigned offset, bool lowemi)
149{
150 u32 bit = BIT(offset);
151 bool enabled = nmk_chip->lowemi & bit;
152
153 if (lowemi == enabled)
154 return;
155
156 if (lowemi)
157 nmk_chip->lowemi |= bit;
158 else
159 nmk_chip->lowemi &= ~bit;
160
161 writel_relaxed(nmk_chip->lowemi,
162 nmk_chip->addr + NMK_GPIO_LOWEMI);
163}
164
Rabin Vincent378be062010-06-02 06:06:29 +0100165static void __nmk_gpio_make_input(struct nmk_gpio_chip *nmk_chip,
166 unsigned offset)
167{
168 writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC);
169}
170
Rabin Vincent6720db72010-09-02 11:28:48 +0100171static void __nmk_gpio_set_output(struct nmk_gpio_chip *nmk_chip,
172 unsigned offset, int val)
173{
174 if (val)
175 writel(1 << offset, nmk_chip->addr + NMK_GPIO_DATS);
176 else
177 writel(1 << offset, nmk_chip->addr + NMK_GPIO_DATC);
178}
179
180static void __nmk_gpio_make_output(struct nmk_gpio_chip *nmk_chip,
181 unsigned offset, int val)
182{
183 writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRS);
184 __nmk_gpio_set_output(nmk_chip, offset, val);
185}
186
Rabin Vincent01727e62010-12-13 12:02:40 +0530187static void __nmk_gpio_set_mode_safe(struct nmk_gpio_chip *nmk_chip,
188 unsigned offset, int gpio_mode,
189 bool glitch)
190{
Rabin Vincent6c12fe82011-05-23 12:13:33 +0530191 u32 rwimsc = nmk_chip->rwimsc;
192 u32 fwimsc = nmk_chip->fwimsc;
Rabin Vincent01727e62010-12-13 12:02:40 +0530193
194 if (glitch && nmk_chip->set_ioforce) {
195 u32 bit = BIT(offset);
196
Rabin Vincent01727e62010-12-13 12:02:40 +0530197 /* Prevent spurious wakeups */
198 writel(rwimsc & ~bit, nmk_chip->addr + NMK_GPIO_RWIMSC);
199 writel(fwimsc & ~bit, nmk_chip->addr + NMK_GPIO_FWIMSC);
200
201 nmk_chip->set_ioforce(true);
202 }
203
204 __nmk_gpio_set_mode(nmk_chip, offset, gpio_mode);
205
206 if (glitch && nmk_chip->set_ioforce) {
207 nmk_chip->set_ioforce(false);
208
209 writel(rwimsc, nmk_chip->addr + NMK_GPIO_RWIMSC);
210 writel(fwimsc, nmk_chip->addr + NMK_GPIO_FWIMSC);
211 }
212}
213
Rabin Vincent6c42ad12011-05-23 12:22:18 +0530214static void
215nmk_gpio_disable_lazy_irq(struct nmk_gpio_chip *nmk_chip, unsigned offset)
216{
217 u32 falling = nmk_chip->fimsc & BIT(offset);
218 u32 rising = nmk_chip->rimsc & BIT(offset);
219 int gpio = nmk_chip->chip.base + offset;
Linus Walleijaa6e3792013-01-07 14:54:39 +0100220 int irq = irq_find_mapping(nmk_chip->domain, offset);
Rabin Vincent6c42ad12011-05-23 12:22:18 +0530221 struct irq_data *d = irq_get_irq_data(irq);
222
223 if (!rising && !falling)
224 return;
225
226 if (!d || !irqd_irq_disabled(d))
227 return;
228
229 if (rising) {
230 nmk_chip->rimsc &= ~BIT(offset);
231 writel_relaxed(nmk_chip->rimsc,
232 nmk_chip->addr + NMK_GPIO_RIMSC);
233 }
234
235 if (falling) {
236 nmk_chip->fimsc &= ~BIT(offset);
237 writel_relaxed(nmk_chip->fimsc,
238 nmk_chip->addr + NMK_GPIO_FIMSC);
239 }
240
241 dev_dbg(nmk_chip->chip.dev, "%d: clearing interrupt mask\n", gpio);
242}
243
Jonas Aabergf1671bf2012-10-25 08:40:42 +0200244static void nmk_write_masked(void __iomem *reg, u32 mask, u32 value)
245{
246 u32 val;
247
248 val = readl(reg);
249 val = ((val & ~mask) | (value & mask));
250 writel(val, reg);
251}
252
Jean-Nicolas Grauxc22df082012-09-27 15:38:50 +0200253static void nmk_prcm_altcx_set_mode(struct nmk_pinctrl *npct,
254 unsigned offset, unsigned alt_num)
255{
256 int i;
257 u16 reg;
258 u8 bit;
259 u8 alt_index;
260 const struct prcm_gpiocr_altcx_pin_desc *pin_desc;
261 const u16 *gpiocr_regs;
262
Fabio Baltieri4ca075d2012-12-18 10:12:11 +0100263 if (!npct->prcm_base)
264 return;
265
Jean-Nicolas Grauxc22df082012-09-27 15:38:50 +0200266 if (alt_num > PRCM_IDX_GPIOCR_ALTC_MAX) {
267 dev_err(npct->dev, "PRCM GPIOCR: alternate-C%i is invalid\n",
268 alt_num);
269 return;
270 }
271
272 for (i = 0 ; i < npct->soc->npins_altcx ; i++) {
273 if (npct->soc->altcx_pins[i].pin == offset)
274 break;
275 }
276 if (i == npct->soc->npins_altcx) {
277 dev_dbg(npct->dev, "PRCM GPIOCR: pin %i is not found\n",
278 offset);
279 return;
280 }
281
282 pin_desc = npct->soc->altcx_pins + i;
283 gpiocr_regs = npct->soc->prcm_gpiocr_registers;
284
285 /*
286 * If alt_num is NULL, just clear current ALTCx selection
287 * to make sure we come back to a pure ALTC selection
288 */
289 if (!alt_num) {
290 for (i = 0 ; i < PRCM_IDX_GPIOCR_ALTC_MAX ; i++) {
291 if (pin_desc->altcx[i].used == true) {
292 reg = gpiocr_regs[pin_desc->altcx[i].reg_index];
293 bit = pin_desc->altcx[i].control_bit;
Jonas Aabergf1671bf2012-10-25 08:40:42 +0200294 if (readl(npct->prcm_base + reg) & BIT(bit)) {
295 nmk_write_masked(npct->prcm_base + reg, BIT(bit), 0);
Jean-Nicolas Grauxc22df082012-09-27 15:38:50 +0200296 dev_dbg(npct->dev,
297 "PRCM GPIOCR: pin %i: alternate-C%i has been disabled\n",
298 offset, i+1);
299 }
300 }
301 }
302 return;
303 }
304
305 alt_index = alt_num - 1;
306 if (pin_desc->altcx[alt_index].used == false) {
307 dev_warn(npct->dev,
308 "PRCM GPIOCR: pin %i: alternate-C%i does not exist\n",
309 offset, alt_num);
310 return;
311 }
312
313 /*
314 * Check if any other ALTCx functions are activated on this pin
315 * and disable it first.
316 */
317 for (i = 0 ; i < PRCM_IDX_GPIOCR_ALTC_MAX ; i++) {
318 if (i == alt_index)
319 continue;
320 if (pin_desc->altcx[i].used == true) {
321 reg = gpiocr_regs[pin_desc->altcx[i].reg_index];
322 bit = pin_desc->altcx[i].control_bit;
Jonas Aabergf1671bf2012-10-25 08:40:42 +0200323 if (readl(npct->prcm_base + reg) & BIT(bit)) {
324 nmk_write_masked(npct->prcm_base + reg, BIT(bit), 0);
Jean-Nicolas Grauxc22df082012-09-27 15:38:50 +0200325 dev_dbg(npct->dev,
326 "PRCM GPIOCR: pin %i: alternate-C%i has been disabled\n",
327 offset, i+1);
328 }
329 }
330 }
331
332 reg = gpiocr_regs[pin_desc->altcx[alt_index].reg_index];
333 bit = pin_desc->altcx[alt_index].control_bit;
334 dev_dbg(npct->dev, "PRCM GPIOCR: pin %i: alternate-C%i has been selected\n",
335 offset, alt_index+1);
Jonas Aabergf1671bf2012-10-25 08:40:42 +0200336 nmk_write_masked(npct->prcm_base + reg, BIT(bit), BIT(bit));
Jean-Nicolas Grauxc22df082012-09-27 15:38:50 +0200337}
338
Rabin Vincent378be062010-06-02 06:06:29 +0100339static void __nmk_config_pin(struct nmk_gpio_chip *nmk_chip, unsigned offset,
Rabin Vincent01727e62010-12-13 12:02:40 +0530340 pin_cfg_t cfg, bool sleep, unsigned int *slpmregs)
Rabin Vincent378be062010-06-02 06:06:29 +0100341{
342 static const char *afnames[] = {
343 [NMK_GPIO_ALT_GPIO] = "GPIO",
344 [NMK_GPIO_ALT_A] = "A",
345 [NMK_GPIO_ALT_B] = "B",
346 [NMK_GPIO_ALT_C] = "C"
347 };
348 static const char *pullnames[] = {
349 [NMK_GPIO_PULL_NONE] = "none",
350 [NMK_GPIO_PULL_UP] = "up",
351 [NMK_GPIO_PULL_DOWN] = "down",
352 [3] /* illegal */ = "??"
353 };
354 static const char *slpmnames[] = {
Rabin Vincent7e3f7e52010-09-02 11:28:05 +0100355 [NMK_GPIO_SLPM_INPUT] = "input/wakeup",
356 [NMK_GPIO_SLPM_NOCHANGE] = "no-change/no-wakeup",
Rabin Vincent378be062010-06-02 06:06:29 +0100357 };
358
359 int pin = PIN_NUM(cfg);
360 int pull = PIN_PULL(cfg);
361 int af = PIN_ALT(cfg);
362 int slpm = PIN_SLPM(cfg);
Rabin Vincent6720db72010-09-02 11:28:48 +0100363 int output = PIN_DIR(cfg);
364 int val = PIN_VAL(cfg);
Rabin Vincent01727e62010-12-13 12:02:40 +0530365 bool glitch = af == NMK_GPIO_ALT_C;
Rabin Vincent378be062010-06-02 06:06:29 +0100366
Rabin Vincentdacdc962010-12-03 20:35:37 +0530367 dev_dbg(nmk_chip->chip.dev, "pin %d [%#lx]: af %s, pull %s, slpm %s (%s%s)\n",
368 pin, cfg, afnames[af], pullnames[pull], slpmnames[slpm],
Rabin Vincent6720db72010-09-02 11:28:48 +0100369 output ? "output " : "input",
370 output ? (val ? "high" : "low") : "");
Rabin Vincent378be062010-06-02 06:06:29 +0100371
Rabin Vincentdacdc962010-12-03 20:35:37 +0530372 if (sleep) {
373 int slpm_pull = PIN_SLPM_PULL(cfg);
374 int slpm_output = PIN_SLPM_DIR(cfg);
375 int slpm_val = PIN_SLPM_VAL(cfg);
376
Rabin Vincent3546d152010-11-25 11:38:27 +0530377 af = NMK_GPIO_ALT_GPIO;
378
Rabin Vincentdacdc962010-12-03 20:35:37 +0530379 /*
380 * The SLPM_* values are normal values + 1 to allow zero to
381 * mean "same as normal".
382 */
383 if (slpm_pull)
384 pull = slpm_pull - 1;
385 if (slpm_output)
386 output = slpm_output - 1;
387 if (slpm_val)
388 val = slpm_val - 1;
389
390 dev_dbg(nmk_chip->chip.dev, "pin %d: sleep pull %s, dir %s, val %s\n",
391 pin,
392 slpm_pull ? pullnames[pull] : "same",
393 slpm_output ? (output ? "output" : "input") : "same",
394 slpm_val ? (val ? "high" : "low") : "same");
395 }
396
Rabin Vincent6720db72010-09-02 11:28:48 +0100397 if (output)
398 __nmk_gpio_make_output(nmk_chip, offset, val);
399 else {
400 __nmk_gpio_make_input(nmk_chip, offset);
401 __nmk_gpio_set_pull(nmk_chip, offset, pull);
402 }
403
Rabin Vincentebc61782011-09-28 15:49:11 +0530404 __nmk_gpio_set_lowemi(nmk_chip, offset, PIN_LOWEMI(cfg));
405
Rabin Vincent01727e62010-12-13 12:02:40 +0530406 /*
Rabin Vincent6c42ad12011-05-23 12:22:18 +0530407 * If the pin is switching to altfunc, and there was an interrupt
408 * installed on it which has been lazy disabled, actually mask the
409 * interrupt to prevent spurious interrupts that would occur while the
410 * pin is under control of the peripheral. Only SKE does this.
411 */
412 if (af != NMK_GPIO_ALT_GPIO)
413 nmk_gpio_disable_lazy_irq(nmk_chip, offset);
414
415 /*
Rabin Vincent01727e62010-12-13 12:02:40 +0530416 * If we've backed up the SLPM registers (glitch workaround), modify
417 * the backups since they will be restored.
418 */
419 if (slpmregs) {
420 if (slpm == NMK_GPIO_SLPM_NOCHANGE)
421 slpmregs[nmk_chip->bank] |= BIT(offset);
422 else
423 slpmregs[nmk_chip->bank] &= ~BIT(offset);
424 } else
425 __nmk_gpio_set_slpm(nmk_chip, offset, slpm);
426
427 __nmk_gpio_set_mode_safe(nmk_chip, offset, af, glitch);
428}
429
430/*
431 * Safe sequence used to switch IOs between GPIO and Alternate-C mode:
432 * - Save SLPM registers
433 * - Set SLPM=0 for the IOs you want to switch and others to 1
434 * - Configure the GPIO registers for the IOs that are being switched
435 * - Set IOFORCE=1
436 * - Modify the AFLSA/B registers for the IOs that are being switched
437 * - Set IOFORCE=0
438 * - Restore SLPM registers
439 * - Any spurious wake up event during switch sequence to be ignored and
440 * cleared
441 */
442static void nmk_gpio_glitch_slpm_init(unsigned int *slpm)
443{
444 int i;
445
446 for (i = 0; i < NUM_BANKS; i++) {
447 struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
448 unsigned int temp = slpm[i];
449
450 if (!chip)
451 break;
452
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200453 clk_enable(chip->clk);
454
Rabin Vincent01727e62010-12-13 12:02:40 +0530455 slpm[i] = readl(chip->addr + NMK_GPIO_SLPC);
456 writel(temp, chip->addr + NMK_GPIO_SLPC);
457 }
458}
459
460static void nmk_gpio_glitch_slpm_restore(unsigned int *slpm)
461{
462 int i;
463
464 for (i = 0; i < NUM_BANKS; i++) {
465 struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
466
467 if (!chip)
468 break;
469
470 writel(slpm[i], chip->addr + NMK_GPIO_SLPC);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200471
472 clk_disable(chip->clk);
Rabin Vincent01727e62010-12-13 12:02:40 +0530473 }
474}
475
476static int __nmk_config_pins(pin_cfg_t *cfgs, int num, bool sleep)
477{
478 static unsigned int slpm[NUM_BANKS];
479 unsigned long flags;
480 bool glitch = false;
481 int ret = 0;
482 int i;
483
484 for (i = 0; i < num; i++) {
485 if (PIN_ALT(cfgs[i]) == NMK_GPIO_ALT_C) {
486 glitch = true;
487 break;
488 }
489 }
490
491 spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
492
493 if (glitch) {
494 memset(slpm, 0xff, sizeof(slpm));
495
496 for (i = 0; i < num; i++) {
497 int pin = PIN_NUM(cfgs[i]);
498 int offset = pin % NMK_GPIO_PER_CHIP;
499
500 if (PIN_ALT(cfgs[i]) == NMK_GPIO_ALT_C)
501 slpm[pin / NMK_GPIO_PER_CHIP] &= ~BIT(offset);
502 }
503
504 nmk_gpio_glitch_slpm_init(slpm);
505 }
506
507 for (i = 0; i < num; i++) {
508 struct nmk_gpio_chip *nmk_chip;
509 int pin = PIN_NUM(cfgs[i]);
510
Lee Jonesa60b57e2012-04-19 21:36:31 +0100511 nmk_chip = nmk_gpio_chips[pin / NMK_GPIO_PER_CHIP];
Rabin Vincent01727e62010-12-13 12:02:40 +0530512 if (!nmk_chip) {
513 ret = -EINVAL;
514 break;
515 }
516
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200517 clk_enable(nmk_chip->clk);
Rabin Vincent01727e62010-12-13 12:02:40 +0530518 spin_lock(&nmk_chip->lock);
Lee Jonesa60b57e2012-04-19 21:36:31 +0100519 __nmk_config_pin(nmk_chip, pin % NMK_GPIO_PER_CHIP,
Rabin Vincent01727e62010-12-13 12:02:40 +0530520 cfgs[i], sleep, glitch ? slpm : NULL);
521 spin_unlock(&nmk_chip->lock);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200522 clk_disable(nmk_chip->clk);
Rabin Vincent01727e62010-12-13 12:02:40 +0530523 }
524
525 if (glitch)
526 nmk_gpio_glitch_slpm_restore(slpm);
527
528 spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
529
530 return ret;
Rabin Vincent378be062010-06-02 06:06:29 +0100531}
532
533/**
534 * nmk_config_pin - configure a pin's mux attributes
535 * @cfg: pin confguration
Linus Walleij50bcd472012-07-04 11:25:36 +0200536 * @sleep: Non-zero to apply the sleep mode configuration
Rabin Vincent378be062010-06-02 06:06:29 +0100537 * Configures a pin's mode (alternate function or GPIO), its pull up status,
538 * and its sleep mode based on the specified configuration. The @cfg is
539 * usually one of the SoC specific macros defined in mach/<soc>-pins.h. These
540 * are constructed using, and can be further enhanced with, the macros in
Linus Walleij287f1212012-10-10 14:35:17 +0200541 * <linux/platform_data/pinctrl-nomadik.h>
Rabin Vincent378be062010-06-02 06:06:29 +0100542 *
543 * If a pin's mode is set to GPIO, it is configured as an input to avoid
544 * side-effects. The gpio can be manipulated later using standard GPIO API
545 * calls.
546 */
Rabin Vincentdacdc962010-12-03 20:35:37 +0530547int nmk_config_pin(pin_cfg_t cfg, bool sleep)
Rabin Vincent378be062010-06-02 06:06:29 +0100548{
Rabin Vincent01727e62010-12-13 12:02:40 +0530549 return __nmk_config_pins(&cfg, 1, sleep);
Rabin Vincent378be062010-06-02 06:06:29 +0100550}
551EXPORT_SYMBOL(nmk_config_pin);
552
553/**
554 * nmk_config_pins - configure several pins at once
555 * @cfgs: array of pin configurations
556 * @num: number of elments in the array
557 *
558 * Configures several pins using nmk_config_pin(). Refer to that function for
559 * further information.
560 */
561int nmk_config_pins(pin_cfg_t *cfgs, int num)
562{
Rabin Vincent01727e62010-12-13 12:02:40 +0530563 return __nmk_config_pins(cfgs, num, false);
Rabin Vincent378be062010-06-02 06:06:29 +0100564}
565EXPORT_SYMBOL(nmk_config_pins);
566
Rabin Vincentdacdc962010-12-03 20:35:37 +0530567int nmk_config_pins_sleep(pin_cfg_t *cfgs, int num)
568{
Rabin Vincent01727e62010-12-13 12:02:40 +0530569 return __nmk_config_pins(cfgs, num, true);
Rabin Vincentdacdc962010-12-03 20:35:37 +0530570}
571EXPORT_SYMBOL(nmk_config_pins_sleep);
572
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100573/**
Rabin Vincent81a3c292010-05-27 12:39:23 +0100574 * nmk_gpio_set_slpm() - configure the sleep mode of a pin
575 * @gpio: pin number
576 * @mode: NMK_GPIO_SLPM_INPUT or NMK_GPIO_SLPM_NOCHANGE,
577 *
Linus Walleij33d78642011-06-09 11:08:47 +0200578 * This register is actually in the pinmux layer, not the GPIO block itself.
579 * The GPIO1B_SLPM register defines the GPIO mode when SLEEP/DEEP-SLEEP
580 * mode is entered (i.e. when signal IOFORCE is HIGH by the platform code).
581 * Each GPIO can be configured to be forced into GPIO mode when IOFORCE is
582 * HIGH, overriding the normal setting defined by GPIO_AFSELx registers.
583 * When IOFORCE returns LOW (by software, after SLEEP/DEEP-SLEEP exit),
584 * the GPIOs return to the normal setting defined by GPIO_AFSELx registers.
Rabin Vincent7e3f7e52010-09-02 11:28:05 +0100585 *
Linus Walleij33d78642011-06-09 11:08:47 +0200586 * If @mode is NMK_GPIO_SLPM_INPUT, the corresponding GPIO is switched to GPIO
587 * mode when signal IOFORCE is HIGH (i.e. when SLEEP/DEEP-SLEEP mode is
588 * entered) regardless of the altfunction selected. Also wake-up detection is
589 * ENABLED.
590 *
591 * If @mode is NMK_GPIO_SLPM_NOCHANGE, the corresponding GPIO remains
592 * controlled by NMK_GPIO_DATC, NMK_GPIO_DATS, NMK_GPIO_DIR, NMK_GPIO_PDIS
593 * (for altfunction GPIO) or respective on-chip peripherals (for other
594 * altfuncs) when IOFORCE is HIGH. Also wake-up detection DISABLED.
595 *
596 * Note that enable_irq_wake() will automatically enable wakeup detection.
Rabin Vincent81a3c292010-05-27 12:39:23 +0100597 */
598int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode)
599{
600 struct nmk_gpio_chip *nmk_chip;
601 unsigned long flags;
602
Lee Jonesa60b57e2012-04-19 21:36:31 +0100603 nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
Rabin Vincent81a3c292010-05-27 12:39:23 +0100604 if (!nmk_chip)
605 return -EINVAL;
606
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200607 clk_enable(nmk_chip->clk);
Rabin Vincent01727e62010-12-13 12:02:40 +0530608 spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
609 spin_lock(&nmk_chip->lock);
610
Lee Jonesa60b57e2012-04-19 21:36:31 +0100611 __nmk_gpio_set_slpm(nmk_chip, gpio % NMK_GPIO_PER_CHIP, mode);
Rabin Vincent01727e62010-12-13 12:02:40 +0530612
613 spin_unlock(&nmk_chip->lock);
614 spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200615 clk_disable(nmk_chip->clk);
Rabin Vincent81a3c292010-05-27 12:39:23 +0100616
617 return 0;
618}
619
620/**
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100621 * nmk_gpio_set_pull() - enable/disable pull up/down on a gpio
622 * @gpio: pin number
623 * @pull: one of NMK_GPIO_PULL_DOWN, NMK_GPIO_PULL_UP, and NMK_GPIO_PULL_NONE
624 *
625 * Enables/disables pull up/down on a specified pin. This only takes effect if
626 * the pin is configured as an input (either explicitly or by the alternate
627 * function).
628 *
629 * NOTE: If enabling the pull up/down, the caller must ensure that the GPIO is
630 * configured as an input. Otherwise, due to the way the controller registers
631 * work, this function will change the value output on the pin.
632 */
633int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull)
634{
635 struct nmk_gpio_chip *nmk_chip;
636 unsigned long flags;
637
Lee Jonesa60b57e2012-04-19 21:36:31 +0100638 nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100639 if (!nmk_chip)
640 return -EINVAL;
641
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200642 clk_enable(nmk_chip->clk);
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100643 spin_lock_irqsave(&nmk_chip->lock, flags);
Lee Jonesa60b57e2012-04-19 21:36:31 +0100644 __nmk_gpio_set_pull(nmk_chip, gpio % NMK_GPIO_PER_CHIP, pull);
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100645 spin_unlock_irqrestore(&nmk_chip->lock, flags);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200646 clk_disable(nmk_chip->clk);
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100647
648 return 0;
649}
650
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100651/* Mode functions */
Jonas Aaberg9c66ee62010-10-13 13:14:17 +0200652/**
653 * nmk_gpio_set_mode() - set the mux mode of a gpio pin
654 * @gpio: pin number
655 * @gpio_mode: one of NMK_GPIO_ALT_GPIO, NMK_GPIO_ALT_A,
656 * NMK_GPIO_ALT_B, and NMK_GPIO_ALT_C
657 *
658 * Sets the mode of the specified pin to one of the alternate functions or
659 * plain GPIO.
660 */
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100661int nmk_gpio_set_mode(int gpio, int gpio_mode)
662{
663 struct nmk_gpio_chip *nmk_chip;
664 unsigned long flags;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100665
Lee Jonesa60b57e2012-04-19 21:36:31 +0100666 nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100667 if (!nmk_chip)
668 return -EINVAL;
669
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200670 clk_enable(nmk_chip->clk);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100671 spin_lock_irqsave(&nmk_chip->lock, flags);
Lee Jonesa60b57e2012-04-19 21:36:31 +0100672 __nmk_gpio_set_mode(nmk_chip, gpio % NMK_GPIO_PER_CHIP, gpio_mode);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100673 spin_unlock_irqrestore(&nmk_chip->lock, flags);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200674 clk_disable(nmk_chip->clk);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100675
676 return 0;
677}
678EXPORT_SYMBOL(nmk_gpio_set_mode);
679
Jean-Nicolas Graux2249b192012-10-15 09:47:05 +0200680static int nmk_prcm_gpiocr_get_mode(struct pinctrl_dev *pctldev, int gpio)
681{
682 int i;
683 u16 reg;
684 u8 bit;
685 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
686 const struct prcm_gpiocr_altcx_pin_desc *pin_desc;
687 const u16 *gpiocr_regs;
688
Fabio Baltieri4ca075d2012-12-18 10:12:11 +0100689 if (!npct->prcm_base)
690 return NMK_GPIO_ALT_C;
691
Jean-Nicolas Graux2249b192012-10-15 09:47:05 +0200692 for (i = 0; i < npct->soc->npins_altcx; i++) {
693 if (npct->soc->altcx_pins[i].pin == gpio)
694 break;
695 }
696 if (i == npct->soc->npins_altcx)
697 return NMK_GPIO_ALT_C;
698
699 pin_desc = npct->soc->altcx_pins + i;
700 gpiocr_regs = npct->soc->prcm_gpiocr_registers;
701 for (i = 0; i < PRCM_IDX_GPIOCR_ALTC_MAX; i++) {
702 if (pin_desc->altcx[i].used == true) {
703 reg = gpiocr_regs[pin_desc->altcx[i].reg_index];
704 bit = pin_desc->altcx[i].control_bit;
Jonas Aabergf1671bf2012-10-25 08:40:42 +0200705 if (readl(npct->prcm_base + reg) & BIT(bit))
Jean-Nicolas Graux2249b192012-10-15 09:47:05 +0200706 return NMK_GPIO_ALT_C+i+1;
707 }
708 }
709 return NMK_GPIO_ALT_C;
710}
711
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100712int nmk_gpio_get_mode(int gpio)
713{
714 struct nmk_gpio_chip *nmk_chip;
715 u32 afunc, bfunc, bit;
716
Lee Jonesa60b57e2012-04-19 21:36:31 +0100717 nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100718 if (!nmk_chip)
719 return -EINVAL;
720
Lee Jonesa60b57e2012-04-19 21:36:31 +0100721 bit = 1 << (gpio % NMK_GPIO_PER_CHIP);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100722
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200723 clk_enable(nmk_chip->clk);
724
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100725 afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & bit;
726 bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & bit;
727
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200728 clk_disable(nmk_chip->clk);
729
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100730 return (afunc ? NMK_GPIO_ALT_A : 0) | (bfunc ? NMK_GPIO_ALT_B : 0);
731}
732EXPORT_SYMBOL(nmk_gpio_get_mode);
733
734
735/* IRQ functions */
736static inline int nmk_gpio_get_bitmask(int gpio)
737{
Lee Jonesa60b57e2012-04-19 21:36:31 +0100738 return 1 << (gpio % NMK_GPIO_PER_CHIP);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100739}
740
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100741static void nmk_gpio_irq_ack(struct irq_data *d)
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100742{
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100743 struct nmk_gpio_chip *nmk_chip;
744
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100745 nmk_chip = irq_data_get_irq_chip_data(d);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100746 if (!nmk_chip)
747 return;
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200748
749 clk_enable(nmk_chip->clk);
Lee Jonesa60b57e2012-04-19 21:36:31 +0100750 writel(nmk_gpio_get_bitmask(d->hwirq), nmk_chip->addr + NMK_GPIO_IC);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200751 clk_disable(nmk_chip->clk);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100752}
753
Rabin Vincent4d4e20f2010-06-16 06:09:34 +0100754enum nmk_gpio_irq_type {
755 NORMAL,
756 WAKE,
757};
758
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100759static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip,
Rabin Vincent4d4e20f2010-06-16 06:09:34 +0100760 int gpio, enum nmk_gpio_irq_type which,
761 bool enable)
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100762{
763 u32 bitmask = nmk_gpio_get_bitmask(gpio);
Rabin Vincent6c12fe82011-05-23 12:13:33 +0530764 u32 *rimscval;
765 u32 *fimscval;
766 u32 rimscreg;
767 u32 fimscreg;
768
769 if (which == NORMAL) {
770 rimscreg = NMK_GPIO_RIMSC;
771 fimscreg = NMK_GPIO_FIMSC;
772 rimscval = &nmk_chip->rimsc;
773 fimscval = &nmk_chip->fimsc;
774 } else {
775 rimscreg = NMK_GPIO_RWIMSC;
776 fimscreg = NMK_GPIO_FWIMSC;
777 rimscval = &nmk_chip->rwimsc;
778 fimscval = &nmk_chip->fwimsc;
779 }
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100780
781 /* we must individually set/clear the two edges */
782 if (nmk_chip->edge_rising & bitmask) {
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100783 if (enable)
Rabin Vincent6c12fe82011-05-23 12:13:33 +0530784 *rimscval |= bitmask;
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100785 else
Rabin Vincent6c12fe82011-05-23 12:13:33 +0530786 *rimscval &= ~bitmask;
787 writel(*rimscval, nmk_chip->addr + rimscreg);
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100788 }
789 if (nmk_chip->edge_falling & bitmask) {
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100790 if (enable)
Rabin Vincent6c12fe82011-05-23 12:13:33 +0530791 *fimscval |= bitmask;
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100792 else
Rabin Vincent6c12fe82011-05-23 12:13:33 +0530793 *fimscval &= ~bitmask;
794 writel(*fimscval, nmk_chip->addr + fimscreg);
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100795 }
796}
797
Rabin Vincentb9df4682011-02-10 11:45:58 +0530798static void __nmk_gpio_set_wake(struct nmk_gpio_chip *nmk_chip,
799 int gpio, bool on)
800{
Rabin Vincentb982ff02011-04-26 09:03:27 +0530801 /*
802 * Ensure WAKEUP_ENABLE is on. No need to disable it if wakeup is
803 * disabled, since setting SLPM to 1 increases power consumption, and
804 * wakeup is anyhow controlled by the RIMSC and FIMSC registers.
805 */
806 if (nmk_chip->sleepmode && on) {
Linus Walleije85bbc12012-06-12 12:43:06 +0200807 __nmk_gpio_set_slpm(nmk_chip, gpio % NMK_GPIO_PER_CHIP,
Rabin Vincentb982ff02011-04-26 09:03:27 +0530808 NMK_GPIO_SLPM_WAKEUP_ENABLE);
Linus Walleij33d78642011-06-09 11:08:47 +0200809 }
810
Rabin Vincentb9df4682011-02-10 11:45:58 +0530811 __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, on);
812}
813
814static int nmk_gpio_irq_maskunmask(struct irq_data *d, bool enable)
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100815{
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100816 struct nmk_gpio_chip *nmk_chip;
817 unsigned long flags;
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100818 u32 bitmask;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100819
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100820 nmk_chip = irq_data_get_irq_chip_data(d);
Lee Jonesa60b57e2012-04-19 21:36:31 +0100821 bitmask = nmk_gpio_get_bitmask(d->hwirq);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100822 if (!nmk_chip)
Rabin Vincent4d4e20f2010-06-16 06:09:34 +0100823 return -EINVAL;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100824
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200825 clk_enable(nmk_chip->clk);
Rabin Vincentb9df4682011-02-10 11:45:58 +0530826 spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
827 spin_lock(&nmk_chip->lock);
828
Lee Jonesa60b57e2012-04-19 21:36:31 +0100829 __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, enable);
Rabin Vincentb9df4682011-02-10 11:45:58 +0530830
831 if (!(nmk_chip->real_wake & bitmask))
Lee Jonesa60b57e2012-04-19 21:36:31 +0100832 __nmk_gpio_set_wake(nmk_chip, d->hwirq, enable);
Rabin Vincentb9df4682011-02-10 11:45:58 +0530833
834 spin_unlock(&nmk_chip->lock);
835 spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200836 clk_disable(nmk_chip->clk);
Rabin Vincent4d4e20f2010-06-16 06:09:34 +0100837
838 return 0;
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100839}
840
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100841static void nmk_gpio_irq_mask(struct irq_data *d)
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100842{
Rabin Vincentb9df4682011-02-10 11:45:58 +0530843 nmk_gpio_irq_maskunmask(d, false);
Rabin Vincent4d4e20f2010-06-16 06:09:34 +0100844}
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100845
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100846static void nmk_gpio_irq_unmask(struct irq_data *d)
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100847{
Rabin Vincentb9df4682011-02-10 11:45:58 +0530848 nmk_gpio_irq_maskunmask(d, true);
Rabin Vincent4d4e20f2010-06-16 06:09:34 +0100849}
850
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100851static int nmk_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
Rabin Vincent4d4e20f2010-06-16 06:09:34 +0100852{
Rabin Vincent7e3f7e52010-09-02 11:28:05 +0100853 struct nmk_gpio_chip *nmk_chip;
854 unsigned long flags;
Rabin Vincentb9df4682011-02-10 11:45:58 +0530855 u32 bitmask;
Rabin Vincent7e3f7e52010-09-02 11:28:05 +0100856
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100857 nmk_chip = irq_data_get_irq_chip_data(d);
Rabin Vincent7e3f7e52010-09-02 11:28:05 +0100858 if (!nmk_chip)
859 return -EINVAL;
Lee Jonesa60b57e2012-04-19 21:36:31 +0100860 bitmask = nmk_gpio_get_bitmask(d->hwirq);
Rabin Vincent7e3f7e52010-09-02 11:28:05 +0100861
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200862 clk_enable(nmk_chip->clk);
Rabin Vincent01727e62010-12-13 12:02:40 +0530863 spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
864 spin_lock(&nmk_chip->lock);
865
Linus Walleij479a0c72011-09-20 10:50:15 +0200866 if (irqd_irq_disabled(d))
Lee Jonesa60b57e2012-04-19 21:36:31 +0100867 __nmk_gpio_set_wake(nmk_chip, d->hwirq, on);
Rabin Vincentb9df4682011-02-10 11:45:58 +0530868
869 if (on)
870 nmk_chip->real_wake |= bitmask;
871 else
872 nmk_chip->real_wake &= ~bitmask;
Rabin Vincent01727e62010-12-13 12:02:40 +0530873
874 spin_unlock(&nmk_chip->lock);
875 spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200876 clk_disable(nmk_chip->clk);
Rabin Vincent7e3f7e52010-09-02 11:28:05 +0100877
878 return 0;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100879}
880
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100881static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100882{
Linus Walleij479a0c72011-09-20 10:50:15 +0200883 bool enabled = !irqd_irq_disabled(d);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200884 bool wake = irqd_is_wakeup_set(d);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100885 struct nmk_gpio_chip *nmk_chip;
886 unsigned long flags;
887 u32 bitmask;
888
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100889 nmk_chip = irq_data_get_irq_chip_data(d);
Lee Jonesa60b57e2012-04-19 21:36:31 +0100890 bitmask = nmk_gpio_get_bitmask(d->hwirq);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100891 if (!nmk_chip)
892 return -EINVAL;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100893 if (type & IRQ_TYPE_LEVEL_HIGH)
894 return -EINVAL;
895 if (type & IRQ_TYPE_LEVEL_LOW)
896 return -EINVAL;
897
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200898 clk_enable(nmk_chip->clk);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100899 spin_lock_irqsave(&nmk_chip->lock, flags);
900
Rabin Vincent7a852d82010-05-06 10:43:55 +0100901 if (enabled)
Lee Jonesa60b57e2012-04-19 21:36:31 +0100902 __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, false);
Rabin Vincent4d4e20f2010-06-16 06:09:34 +0100903
Rabin Vincentb9df4682011-02-10 11:45:58 +0530904 if (enabled || wake)
Lee Jonesa60b57e2012-04-19 21:36:31 +0100905 __nmk_gpio_irq_modify(nmk_chip, d->hwirq, WAKE, false);
Rabin Vincent7a852d82010-05-06 10:43:55 +0100906
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100907 nmk_chip->edge_rising &= ~bitmask;
908 if (type & IRQ_TYPE_EDGE_RISING)
909 nmk_chip->edge_rising |= bitmask;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100910
911 nmk_chip->edge_falling &= ~bitmask;
912 if (type & IRQ_TYPE_EDGE_FALLING)
913 nmk_chip->edge_falling |= bitmask;
Rabin Vincent7a852d82010-05-06 10:43:55 +0100914
915 if (enabled)
Lee Jonesa60b57e2012-04-19 21:36:31 +0100916 __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, true);
Rabin Vincent4d4e20f2010-06-16 06:09:34 +0100917
Rabin Vincentb9df4682011-02-10 11:45:58 +0530918 if (enabled || wake)
Lee Jonesa60b57e2012-04-19 21:36:31 +0100919 __nmk_gpio_irq_modify(nmk_chip, d->hwirq, WAKE, true);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100920
921 spin_unlock_irqrestore(&nmk_chip->lock, flags);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200922 clk_disable(nmk_chip->clk);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100923
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100924 return 0;
925}
926
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200927static unsigned int nmk_gpio_irq_startup(struct irq_data *d)
928{
929 struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d);
930
931 clk_enable(nmk_chip->clk);
932 nmk_gpio_irq_unmask(d);
933 return 0;
934}
935
936static void nmk_gpio_irq_shutdown(struct irq_data *d)
937{
938 struct nmk_gpio_chip *nmk_chip = irq_data_get_irq_chip_data(d);
939
940 nmk_gpio_irq_mask(d);
941 clk_disable(nmk_chip->clk);
942}
943
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100944static struct irq_chip nmk_gpio_irq_chip = {
945 .name = "Nomadik-GPIO",
Lennert Buytenhekf272c002010-11-29 11:16:48 +0100946 .irq_ack = nmk_gpio_irq_ack,
947 .irq_mask = nmk_gpio_irq_mask,
948 .irq_unmask = nmk_gpio_irq_unmask,
949 .irq_set_type = nmk_gpio_irq_set_type,
950 .irq_set_wake = nmk_gpio_irq_set_wake,
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200951 .irq_startup = nmk_gpio_irq_startup,
952 .irq_shutdown = nmk_gpio_irq_shutdown,
Etienne Carriere4921e7452012-08-22 10:44:16 +0200953 .flags = IRQCHIP_MASK_ON_SUSPEND,
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100954};
955
Rabin Vincent33b744b2010-10-14 10:38:03 +0530956static void __nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc,
957 u32 status)
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100958{
959 struct nmk_gpio_chip *nmk_chip;
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100960 struct irq_chip *host_chip = irq_get_chip(irq);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100961
Will Deaconadfed152011-02-28 10:12:29 +0000962 chained_irq_enter(host_chip, desc);
Rabin Vincentaaedaa22010-03-03 04:50:27 +0100963
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100964 nmk_chip = irq_get_handler_data(irq);
Rabin Vincent33b744b2010-10-14 10:38:03 +0530965 while (status) {
966 int bit = __ffs(status);
967
Linus Walleij95f0bc92012-09-27 14:14:09 +0200968 generic_handle_irq(irq_find_mapping(nmk_chip->domain, bit));
Rabin Vincent33b744b2010-10-14 10:38:03 +0530969 status &= ~BIT(bit);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100970 }
Rabin Vincentaaedaa22010-03-03 04:50:27 +0100971
Will Deaconadfed152011-02-28 10:12:29 +0000972 chained_irq_exit(host_chip, desc);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100973}
974
Rabin Vincent33b744b2010-10-14 10:38:03 +0530975static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
976{
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100977 struct nmk_gpio_chip *nmk_chip = irq_get_handler_data(irq);
Rabin Vincent3c0227d2011-09-20 10:50:03 +0200978 u32 status;
979
980 clk_enable(nmk_chip->clk);
981 status = readl(nmk_chip->addr + NMK_GPIO_IS);
982 clk_disable(nmk_chip->clk);
Rabin Vincent33b744b2010-10-14 10:38:03 +0530983
984 __nmk_gpio_irq_handler(irq, desc, status);
985}
986
987static void nmk_gpio_secondary_irq_handler(unsigned int irq,
988 struct irq_desc *desc)
989{
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100990 struct nmk_gpio_chip *nmk_chip = irq_get_handler_data(irq);
Rabin Vincent33b744b2010-10-14 10:38:03 +0530991 u32 status = nmk_chip->get_secondary_status(nmk_chip->bank);
992
993 __nmk_gpio_irq_handler(irq, desc, status);
994}
995
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100996static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip)
997{
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100998 irq_set_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler);
999 irq_set_handler_data(nmk_chip->parent_irq, nmk_chip);
Rabin Vincent33b744b2010-10-14 10:38:03 +05301000
1001 if (nmk_chip->secondary_parent_irq >= 0) {
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001002 irq_set_chained_handler(nmk_chip->secondary_parent_irq,
Rabin Vincent33b744b2010-10-14 10:38:03 +05301003 nmk_gpio_secondary_irq_handler);
Thomas Gleixner6845664a2011-03-24 13:25:22 +01001004 irq_set_handler_data(nmk_chip->secondary_parent_irq, nmk_chip);
Rabin Vincent33b744b2010-10-14 10:38:03 +05301005 }
1006
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001007 return 0;
1008}
1009
1010/* I/O Functions */
Linus Walleijdbfe8ca2012-05-02 22:56:47 +02001011
1012static int nmk_gpio_request(struct gpio_chip *chip, unsigned offset)
1013{
1014 /*
1015 * Map back to global GPIO space and request muxing, the direction
1016 * parameter does not matter for this controller.
1017 */
1018 int gpio = chip->base + offset;
1019
1020 return pinctrl_request_gpio(gpio);
1021}
1022
1023static void nmk_gpio_free(struct gpio_chip *chip, unsigned offset)
1024{
1025 int gpio = chip->base + offset;
1026
1027 pinctrl_free_gpio(gpio);
1028}
1029
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001030static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset)
1031{
1032 struct nmk_gpio_chip *nmk_chip =
1033 container_of(chip, struct nmk_gpio_chip, chip);
1034
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001035 clk_enable(nmk_chip->clk);
1036
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001037 writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC);
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001038
1039 clk_disable(nmk_chip->clk);
1040
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001041 return 0;
1042}
1043
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001044static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset)
1045{
1046 struct nmk_gpio_chip *nmk_chip =
1047 container_of(chip, struct nmk_gpio_chip, chip);
1048 u32 bit = 1 << offset;
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001049 int value;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001050
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001051 clk_enable(nmk_chip->clk);
1052
1053 value = (readl(nmk_chip->addr + NMK_GPIO_DAT) & bit) != 0;
1054
1055 clk_disable(nmk_chip->clk);
1056
1057 return value;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001058}
1059
1060static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset,
1061 int val)
1062{
1063 struct nmk_gpio_chip *nmk_chip =
1064 container_of(chip, struct nmk_gpio_chip, chip);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001065
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001066 clk_enable(nmk_chip->clk);
1067
Rabin Vincent6720db72010-09-02 11:28:48 +01001068 __nmk_gpio_set_output(nmk_chip, offset, val);
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001069
1070 clk_disable(nmk_chip->clk);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001071}
1072
Rabin Vincent6647c6c2010-05-27 12:22:42 +01001073static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset,
1074 int val)
1075{
1076 struct nmk_gpio_chip *nmk_chip =
1077 container_of(chip, struct nmk_gpio_chip, chip);
1078
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001079 clk_enable(nmk_chip->clk);
1080
Rabin Vincent6720db72010-09-02 11:28:48 +01001081 __nmk_gpio_make_output(nmk_chip, offset, val);
Rabin Vincent6647c6c2010-05-27 12:22:42 +01001082
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001083 clk_disable(nmk_chip->clk);
1084
Rabin Vincent6647c6c2010-05-27 12:22:42 +01001085 return 0;
1086}
1087
Rabin Vincent0d2aec92010-06-16 06:10:43 +01001088static int nmk_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
1089{
1090 struct nmk_gpio_chip *nmk_chip =
1091 container_of(chip, struct nmk_gpio_chip, chip);
1092
Linus Walleij268300b2012-10-19 17:06:54 +02001093 return irq_create_mapping(nmk_chip->domain, offset);
Rabin Vincent0d2aec92010-06-16 06:10:43 +01001094}
1095
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301096#ifdef CONFIG_DEBUG_FS
1097
1098#include <linux/seq_file.h>
1099
Jean-Nicolas Graux2249b192012-10-15 09:47:05 +02001100static void nmk_gpio_dbg_show_one(struct seq_file *s,
1101 struct pinctrl_dev *pctldev, struct gpio_chip *chip,
1102 unsigned offset, unsigned gpio)
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301103{
Linus Walleij6f4350a2012-05-02 21:06:13 +02001104 const char *label = gpiochip_is_requested(chip, offset);
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301105 struct nmk_gpio_chip *nmk_chip =
1106 container_of(chip, struct nmk_gpio_chip, chip);
Linus Walleij6f4350a2012-05-02 21:06:13 +02001107 int mode;
1108 bool is_out;
1109 bool pull;
1110 u32 bit = 1 << offset;
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301111 const char *modes[] = {
1112 [NMK_GPIO_ALT_GPIO] = "gpio",
1113 [NMK_GPIO_ALT_A] = "altA",
1114 [NMK_GPIO_ALT_B] = "altB",
1115 [NMK_GPIO_ALT_C] = "altC",
Jean-Nicolas Graux2249b192012-10-15 09:47:05 +02001116 [NMK_GPIO_ALT_C+1] = "altC1",
1117 [NMK_GPIO_ALT_C+2] = "altC2",
1118 [NMK_GPIO_ALT_C+3] = "altC3",
1119 [NMK_GPIO_ALT_C+4] = "altC4",
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301120 };
1121
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001122 clk_enable(nmk_chip->clk);
Linus Walleij6f4350a2012-05-02 21:06:13 +02001123 is_out = !!(readl(nmk_chip->addr + NMK_GPIO_DIR) & bit);
1124 pull = !(readl(nmk_chip->addr + NMK_GPIO_PDIS) & bit);
1125 mode = nmk_gpio_get_mode(gpio);
Jean-Nicolas Graux2249b192012-10-15 09:47:05 +02001126 if ((mode == NMK_GPIO_ALT_C) && pctldev)
1127 mode = nmk_prcm_gpiocr_get_mode(pctldev, gpio);
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001128
Linus Walleij6f4350a2012-05-02 21:06:13 +02001129 seq_printf(s, " gpio-%-3d (%-20.20s) %s %s %s %s",
1130 gpio, label ?: "(none)",
1131 is_out ? "out" : "in ",
1132 chip->get
1133 ? (chip->get(chip, offset) ? "hi" : "lo")
1134 : "? ",
1135 (mode < 0) ? "unknown" : modes[mode],
1136 pull ? "pull" : "none");
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301137
Linus Walleij6f4350a2012-05-02 21:06:13 +02001138 if (label && !is_out) {
1139 int irq = gpio_to_irq(gpio);
1140 struct irq_desc *desc = irq_to_desc(irq);
Rabin Vincent8ea72a32011-05-24 23:07:09 +02001141
Linus Walleij6f4350a2012-05-02 21:06:13 +02001142 /* This races with request_irq(), set_irq_type(),
1143 * and set_irq_wake() ... but those are "rare".
1144 */
1145 if (irq >= 0 && desc->action) {
1146 char *trigger;
1147 u32 bitmask = nmk_gpio_get_bitmask(gpio);
Rabin Vincent8ea72a32011-05-24 23:07:09 +02001148
Linus Walleij6f4350a2012-05-02 21:06:13 +02001149 if (nmk_chip->edge_rising & bitmask)
1150 trigger = "edge-rising";
1151 else if (nmk_chip->edge_falling & bitmask)
1152 trigger = "edge-falling";
1153 else
1154 trigger = "edge-undefined";
Rabin Vincent8ea72a32011-05-24 23:07:09 +02001155
Linus Walleij6f4350a2012-05-02 21:06:13 +02001156 seq_printf(s, " irq-%d %s%s",
1157 irq, trigger,
1158 irqd_is_wakeup_set(&desc->irq_data)
1159 ? " wakeup" : "");
Rabin Vincent8ea72a32011-05-24 23:07:09 +02001160 }
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301161 }
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001162 clk_disable(nmk_chip->clk);
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301163}
1164
Linus Walleij6f4350a2012-05-02 21:06:13 +02001165static void nmk_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
1166{
1167 unsigned i;
1168 unsigned gpio = chip->base;
1169
1170 for (i = 0; i < chip->ngpio; i++, gpio++) {
Jean-Nicolas Graux2249b192012-10-15 09:47:05 +02001171 nmk_gpio_dbg_show_one(s, NULL, chip, i, gpio);
Linus Walleij6f4350a2012-05-02 21:06:13 +02001172 seq_printf(s, "\n");
1173 }
1174}
1175
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301176#else
Linus Walleij6f4350a2012-05-02 21:06:13 +02001177static inline void nmk_gpio_dbg_show_one(struct seq_file *s,
Jean-Nicolas Graux2249b192012-10-15 09:47:05 +02001178 struct pinctrl_dev *pctldev,
Linus Walleij6f4350a2012-05-02 21:06:13 +02001179 struct gpio_chip *chip,
1180 unsigned offset, unsigned gpio)
1181{
1182}
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301183#define nmk_gpio_dbg_show NULL
1184#endif
1185
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001186/* This structure is replicated for each GPIO block allocated at probe time */
1187static struct gpio_chip nmk_gpio_template = {
Linus Walleijdbfe8ca2012-05-02 22:56:47 +02001188 .request = nmk_gpio_request,
1189 .free = nmk_gpio_free,
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001190 .direction_input = nmk_gpio_make_input,
1191 .get = nmk_gpio_get_input,
1192 .direction_output = nmk_gpio_make_output,
1193 .set = nmk_gpio_set_output,
Rabin Vincent0d2aec92010-06-16 06:10:43 +01001194 .to_irq = nmk_gpio_to_irq,
Rabin Vincentd0b543c2010-03-04 17:39:05 +05301195 .dbg_show = nmk_gpio_dbg_show,
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001196 .can_sleep = 0,
1197};
1198
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001199void nmk_gpio_clocks_enable(void)
1200{
1201 int i;
1202
1203 for (i = 0; i < NUM_BANKS; i++) {
1204 struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
1205
1206 if (!chip)
1207 continue;
1208
1209 clk_enable(chip->clk);
1210 }
1211}
1212
1213void nmk_gpio_clocks_disable(void)
1214{
1215 int i;
1216
1217 for (i = 0; i < NUM_BANKS; i++) {
1218 struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
1219
1220 if (!chip)
1221 continue;
1222
1223 clk_disable(chip->clk);
1224 }
1225}
1226
Rabin Vincentb9df4682011-02-10 11:45:58 +05301227/*
1228 * Called from the suspend/resume path to only keep the real wakeup interrupts
1229 * (those that have had set_irq_wake() called on them) as wakeup interrupts,
1230 * and not the rest of the interrupts which we needed to have as wakeups for
1231 * cpuidle.
1232 *
1233 * PM ops are not used since this needs to be done at the end, after all the
1234 * other drivers are done with their suspend callbacks.
1235 */
1236void nmk_gpio_wakeups_suspend(void)
1237{
1238 int i;
1239
1240 for (i = 0; i < NUM_BANKS; i++) {
1241 struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
1242
1243 if (!chip)
1244 break;
1245
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001246 clk_enable(chip->clk);
1247
Rabin Vincentb9df4682011-02-10 11:45:58 +05301248 writel(chip->rwimsc & chip->real_wake,
1249 chip->addr + NMK_GPIO_RWIMSC);
1250 writel(chip->fwimsc & chip->real_wake,
1251 chip->addr + NMK_GPIO_FWIMSC);
1252
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001253 clk_disable(chip->clk);
Rabin Vincentb9df4682011-02-10 11:45:58 +05301254 }
1255}
1256
1257void nmk_gpio_wakeups_resume(void)
1258{
1259 int i;
1260
1261 for (i = 0; i < NUM_BANKS; i++) {
1262 struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
1263
1264 if (!chip)
1265 break;
1266
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001267 clk_enable(chip->clk);
1268
Rabin Vincentb9df4682011-02-10 11:45:58 +05301269 writel(chip->rwimsc, chip->addr + NMK_GPIO_RWIMSC);
1270 writel(chip->fwimsc, chip->addr + NMK_GPIO_FWIMSC);
1271
Rabin Vincent3c0227d2011-09-20 10:50:03 +02001272 clk_disable(chip->clk);
Rabin Vincentb9df4682011-02-10 11:45:58 +05301273 }
1274}
1275
Rickard Anderssonbc6f5cf2011-05-24 23:07:17 +02001276/*
1277 * Read the pull up/pull down status.
1278 * A bit set in 'pull_up' means that pull up
1279 * is selected if pull is enabled in PDIS register.
1280 * Note: only pull up/down set via this driver can
1281 * be detected due to HW limitations.
1282 */
1283void nmk_gpio_read_pull(int gpio_bank, u32 *pull_up)
1284{
1285 if (gpio_bank < NUM_BANKS) {
1286 struct nmk_gpio_chip *chip = nmk_gpio_chips[gpio_bank];
1287
1288 if (!chip)
1289 return;
1290
1291 *pull_up = chip->pull_up;
1292 }
1293}
1294
Axel Lin5212d092012-11-16 00:01:35 +08001295static int nmk_gpio_irq_map(struct irq_domain *d, unsigned int irq,
1296 irq_hw_number_t hwirq)
Lee Jonesa60b57e2012-04-19 21:36:31 +01001297{
1298 struct nmk_gpio_chip *nmk_chip = d->host_data;
1299
1300 if (!nmk_chip)
1301 return -EINVAL;
1302
1303 irq_set_chip_and_handler(irq, &nmk_gpio_irq_chip, handle_edge_irq);
1304 set_irq_flags(irq, IRQF_VALID);
1305 irq_set_chip_data(irq, nmk_chip);
1306 irq_set_irq_type(irq, IRQ_TYPE_EDGE_FALLING);
1307
1308 return 0;
1309}
1310
1311const struct irq_domain_ops nmk_gpio_irq_simple_ops = {
1312 .map = nmk_gpio_irq_map,
1313 .xlate = irq_domain_xlate_twocell,
1314};
1315
Greg Kroah-Hartman150632b2012-12-21 13:10:23 -08001316static int nmk_gpio_probe(struct platform_device *dev)
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001317{
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01001318 struct nmk_gpio_platform_data *pdata = dev->dev.platform_data;
Lee Jones513c27f2012-04-13 15:05:05 +01001319 struct device_node *np = dev->dev.of_node;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001320 struct nmk_gpio_chip *nmk_chip;
1321 struct gpio_chip *chip;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01001322 struct resource *res;
Rabin Vincentaf7dc222010-05-06 11:14:17 +01001323 struct clk *clk;
Rabin Vincent33b744b2010-10-14 10:38:03 +05301324 int secondary_irq;
Linus Walleij8d917712012-04-17 10:15:54 +02001325 void __iomem *base;
Linus Walleij832b6cd2012-10-23 09:50:17 +02001326 int irq_start = 0;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01001327 int irq;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001328 int ret;
1329
Lee Jones513c27f2012-04-13 15:05:05 +01001330 if (!pdata && !np) {
1331 dev_err(&dev->dev, "No platform data or device tree found\n");
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01001332 return -ENODEV;
Lee Jones513c27f2012-04-13 15:05:05 +01001333 }
1334
1335 if (np) {
Linus Walleij5e754f32012-07-03 23:05:14 +02001336 pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL);
Lee Jones513c27f2012-04-13 15:05:05 +01001337 if (!pdata)
1338 return -ENOMEM;
1339
Lee Jones612e1d52012-06-14 11:27:56 +01001340 if (of_get_property(np, "st,supports-sleepmode", NULL))
Lee Jones513c27f2012-04-13 15:05:05 +01001341 pdata->supports_sleepmode = true;
1342
1343 if (of_property_read_u32(np, "gpio-bank", &dev->id)) {
1344 dev_err(&dev->dev, "gpio-bank property not found\n");
Linus Walleij50f690d2013-01-07 14:04:56 +01001345 return -EINVAL;
Lee Jones513c27f2012-04-13 15:05:05 +01001346 }
1347
1348 pdata->first_gpio = dev->id * NMK_GPIO_PER_CHIP;
1349 pdata->num_gpio = NMK_GPIO_PER_CHIP;
1350 }
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01001351
1352 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
Linus Walleij50f690d2013-01-07 14:04:56 +01001353 if (!res)
1354 return -ENOENT;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01001355
1356 irq = platform_get_irq(dev, 0);
Linus Walleij50f690d2013-01-07 14:04:56 +01001357 if (irq < 0)
1358 return irq;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01001359
Rabin Vincent33b744b2010-10-14 10:38:03 +05301360 secondary_irq = platform_get_irq(dev, 1);
Linus Walleij50f690d2013-01-07 14:04:56 +01001361 if (secondary_irq >= 0 && !pdata->get_secondary_status)
1362 return -EINVAL;
Rabin Vincent33b744b2010-10-14 10:38:03 +05301363
Linus Walleij5e754f32012-07-03 23:05:14 +02001364 base = devm_request_and_ioremap(&dev->dev, res);
Linus Walleij50f690d2013-01-07 14:04:56 +01001365 if (!base)
1366 return -ENOMEM;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001367
Linus Walleij5e754f32012-07-03 23:05:14 +02001368 clk = devm_clk_get(&dev->dev, NULL);
Linus Walleij50f690d2013-01-07 14:04:56 +01001369 if (IS_ERR(clk))
1370 return PTR_ERR(clk);
Linus Walleijefec3812012-06-06 22:50:41 +02001371 clk_prepare(clk);
Rabin Vincentaf7dc222010-05-06 11:14:17 +01001372
Linus Walleij5e754f32012-07-03 23:05:14 +02001373 nmk_chip = devm_kzalloc(&dev->dev, sizeof(*nmk_chip), GFP_KERNEL);
Linus Walleij50f690d2013-01-07 14:04:56 +01001374 if (!nmk_chip)
1375 return -ENOMEM;
Lee Jones513c27f2012-04-13 15:05:05 +01001376
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001377 /*
1378 * The virt address in nmk_chip->addr is in the nomadik register space,
1379 * so we can simply convert the resource address, without remapping
1380 */
Rabin Vincent33b744b2010-10-14 10:38:03 +05301381 nmk_chip->bank = dev->id;
Rabin Vincentaf7dc222010-05-06 11:14:17 +01001382 nmk_chip->clk = clk;
Linus Walleij8d917712012-04-17 10:15:54 +02001383 nmk_chip->addr = base;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001384 nmk_chip->chip = nmk_gpio_template;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01001385 nmk_chip->parent_irq = irq;
Rabin Vincent33b744b2010-10-14 10:38:03 +05301386 nmk_chip->secondary_parent_irq = secondary_irq;
1387 nmk_chip->get_secondary_status = pdata->get_secondary_status;
Rabin Vincent01727e62010-12-13 12:02:40 +05301388 nmk_chip->set_ioforce = pdata->set_ioforce;
Linus Walleij33d78642011-06-09 11:08:47 +02001389 nmk_chip->sleepmode = pdata->supports_sleepmode;
Rabin Vincentc0fcb8d2010-03-03 04:48:54 +01001390 spin_lock_init(&nmk_chip->lock);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001391
1392 chip = &nmk_chip->chip;
1393 chip->base = pdata->first_gpio;
Rabin Vincente493e062010-03-18 12:35:22 +05301394 chip->ngpio = pdata->num_gpio;
Rabin Vincent8d568ae2010-12-08 11:07:54 +05301395 chip->label = pdata->name ?: dev_name(&dev->dev);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001396 chip->dev = &dev->dev;
1397 chip->owner = THIS_MODULE;
1398
Rabin Vincentebc61782011-09-28 15:49:11 +05301399 clk_enable(nmk_chip->clk);
1400 nmk_chip->lowemi = readl_relaxed(nmk_chip->addr + NMK_GPIO_LOWEMI);
1401 clk_disable(nmk_chip->clk);
1402
Arnd Bergmann072e82a2012-05-10 13:39:52 +02001403#ifdef CONFIG_OF_GPIO
Lee Jones513c27f2012-04-13 15:05:05 +01001404 chip->of_node = np;
Arnd Bergmann072e82a2012-05-10 13:39:52 +02001405#endif
Lee Jones513c27f2012-04-13 15:05:05 +01001406
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001407 ret = gpiochip_add(&nmk_chip->chip);
1408 if (ret)
Linus Walleij50f690d2013-01-07 14:04:56 +01001409 return ret;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001410
Rabin Vincent01727e62010-12-13 12:02:40 +05301411 BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips));
1412
1413 nmk_gpio_chips[nmk_chip->bank] = nmk_chip;
Lee Jones513c27f2012-04-13 15:05:05 +01001414
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01001415 platform_set_drvdata(dev, nmk_chip);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001416
Linus Walleij51f58c62012-10-11 16:33:44 +02001417 if (!np)
Linus Walleijaa6e3792013-01-07 14:54:39 +01001418 irq_start = pdata->first_irq;
Linus Walleij38843e22012-10-23 11:44:42 +02001419 nmk_chip->domain = irq_domain_add_simple(np,
Linus Walleij6054b9c2012-09-26 19:03:51 +02001420 NMK_GPIO_PER_CHIP, irq_start,
1421 &nmk_gpio_irq_simple_ops, nmk_chip);
Lee Jonesa60b57e2012-04-19 21:36:31 +01001422 if (!nmk_chip->domain) {
Linus Walleij2ee38d42012-08-10 11:07:51 +02001423 dev_err(&dev->dev, "failed to create irqdomain\n");
Linus Walleij50f690d2013-01-07 14:04:56 +01001424 /* Just do this, no matter if it fails */
1425 ret = gpiochip_remove(&nmk_chip->chip);
1426 return -ENOSYS;
Lee Jonesa60b57e2012-04-19 21:36:31 +01001427 }
1428
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001429 nmk_gpio_init_irq(nmk_chip);
1430
Lee Jones513c27f2012-04-13 15:05:05 +01001431 dev_info(&dev->dev, "at address %p\n", nmk_chip->addr);
1432
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001433 return 0;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001434}
1435
Linus Walleije98ea772012-04-26 23:57:25 +02001436static int nmk_get_groups_cnt(struct pinctrl_dev *pctldev)
1437{
1438 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1439
1440 return npct->soc->ngroups;
1441}
1442
1443static const char *nmk_get_group_name(struct pinctrl_dev *pctldev,
1444 unsigned selector)
1445{
1446 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1447
1448 return npct->soc->groups[selector].name;
1449}
1450
1451static int nmk_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
1452 const unsigned **pins,
1453 unsigned *num_pins)
1454{
1455 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1456
1457 *pins = npct->soc->groups[selector].pins;
1458 *num_pins = npct->soc->groups[selector].npins;
1459 return 0;
1460}
1461
Linus Walleij24cbdd72012-05-02 21:28:00 +02001462static struct pinctrl_gpio_range *
1463nmk_match_gpio_range(struct pinctrl_dev *pctldev, unsigned offset)
1464{
1465 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1466 int i;
1467
1468 for (i = 0; i < npct->soc->gpio_num_ranges; i++) {
1469 struct pinctrl_gpio_range *range;
1470
1471 range = &npct->soc->gpio_ranges[i];
1472 if (offset >= range->pin_base &&
1473 offset <= (range->pin_base + range->npins - 1))
1474 return range;
1475 }
1476 return NULL;
1477}
1478
Linus Walleije98ea772012-04-26 23:57:25 +02001479static void nmk_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
1480 unsigned offset)
1481{
Linus Walleij24cbdd72012-05-02 21:28:00 +02001482 struct pinctrl_gpio_range *range;
1483 struct gpio_chip *chip;
1484
1485 range = nmk_match_gpio_range(pctldev, offset);
1486 if (!range || !range->gc) {
1487 seq_printf(s, "invalid pin offset");
1488 return;
1489 }
1490 chip = range->gc;
Jean-Nicolas Graux2249b192012-10-15 09:47:05 +02001491 nmk_gpio_dbg_show_one(s, pctldev, chip, offset - chip->base, offset);
Linus Walleije98ea772012-04-26 23:57:25 +02001492}
1493
Gabriel Fernandeze32af882012-12-17 15:53:24 +01001494static void nmk_pinctrl_dt_free_map(struct pinctrl_dev *pctldev,
1495 struct pinctrl_map *map, unsigned num_maps)
1496{
1497 int i;
1498
1499 for (i = 0; i < num_maps; i++)
1500 if (map[i].type == PIN_MAP_TYPE_CONFIGS_PIN)
1501 kfree(map[i].data.configs.configs);
1502 kfree(map);
1503}
1504
1505static int nmk_dt_reserve_map(struct pinctrl_map **map, unsigned *reserved_maps,
1506 unsigned *num_maps, unsigned reserve)
1507{
1508 unsigned old_num = *reserved_maps;
1509 unsigned new_num = *num_maps + reserve;
1510 struct pinctrl_map *new_map;
1511
1512 if (old_num >= new_num)
1513 return 0;
1514
1515 new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);
1516 if (!new_map)
1517 return -ENOMEM;
1518
1519 memset(new_map + old_num, 0, (new_num - old_num) * sizeof(*new_map));
1520
1521 *map = new_map;
1522 *reserved_maps = new_num;
1523
1524 return 0;
1525}
1526
1527static int nmk_dt_add_map_mux(struct pinctrl_map **map, unsigned *reserved_maps,
1528 unsigned *num_maps, const char *group,
1529 const char *function)
1530{
1531 if (*num_maps == *reserved_maps)
1532 return -ENOSPC;
1533
1534 (*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
1535 (*map)[*num_maps].data.mux.group = group;
1536 (*map)[*num_maps].data.mux.function = function;
1537 (*num_maps)++;
1538
1539 return 0;
1540}
1541
1542static int nmk_dt_add_map_configs(struct pinctrl_map **map,
1543 unsigned *reserved_maps,
1544 unsigned *num_maps, const char *group,
1545 unsigned long *configs, unsigned num_configs)
1546{
1547 unsigned long *dup_configs;
1548
1549 if (*num_maps == *reserved_maps)
1550 return -ENOSPC;
1551
1552 dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
1553 GFP_KERNEL);
1554 if (!dup_configs)
1555 return -ENOMEM;
1556
1557 (*map)[*num_maps].type = PIN_MAP_TYPE_CONFIGS_PIN;
1558
1559 (*map)[*num_maps].data.configs.group_or_pin = group;
1560 (*map)[*num_maps].data.configs.configs = dup_configs;
1561 (*map)[*num_maps].data.configs.num_configs = num_configs;
1562 (*num_maps)++;
1563
1564 return 0;
1565}
1566
1567#define NMK_CONFIG_PIN(x,y) { .property = x, .config = y, }
1568#define NMK_CONFIG_PIN_ARRAY(x,y) { .property = x, .choice = y, \
1569 .size = ARRAY_SIZE(y), }
1570
1571static const unsigned long nmk_pin_input_modes[] = {
1572 PIN_INPUT_NOPULL,
1573 PIN_INPUT_PULLUP,
1574 PIN_INPUT_PULLDOWN,
1575};
1576
1577static const unsigned long nmk_pin_output_modes[] = {
1578 PIN_OUTPUT_LOW,
1579 PIN_OUTPUT_HIGH,
1580 PIN_DIR_OUTPUT,
1581};
1582
1583static const unsigned long nmk_pin_sleep_modes[] = {
1584 PIN_SLEEPMODE_DISABLED,
1585 PIN_SLEEPMODE_ENABLED,
1586};
1587
1588static const unsigned long nmk_pin_sleep_input_modes[] = {
1589 PIN_SLPM_INPUT_NOPULL,
1590 PIN_SLPM_INPUT_PULLUP,
1591 PIN_SLPM_INPUT_PULLDOWN,
1592 PIN_SLPM_DIR_INPUT,
1593};
1594
1595static const unsigned long nmk_pin_sleep_output_modes[] = {
1596 PIN_SLPM_OUTPUT_LOW,
1597 PIN_SLPM_OUTPUT_HIGH,
1598 PIN_SLPM_DIR_OUTPUT,
1599};
1600
1601static const unsigned long nmk_pin_sleep_wakeup_modes[] = {
1602 PIN_SLPM_WAKEUP_DISABLE,
1603 PIN_SLPM_WAKEUP_ENABLE,
1604};
1605
1606static const unsigned long nmk_pin_gpio_modes[] = {
1607 PIN_GPIOMODE_DISABLED,
1608 PIN_GPIOMODE_ENABLED,
1609};
1610
1611static const unsigned long nmk_pin_sleep_pdis_modes[] = {
1612 PIN_SLPM_PDIS_DISABLED,
1613 PIN_SLPM_PDIS_ENABLED,
1614};
1615
1616struct nmk_cfg_param {
1617 const char *property;
1618 unsigned long config;
1619 const unsigned long *choice;
1620 int size;
1621};
1622
1623static const struct nmk_cfg_param nmk_cfg_params[] = {
1624 NMK_CONFIG_PIN_ARRAY("ste,input", nmk_pin_input_modes),
1625 NMK_CONFIG_PIN_ARRAY("ste,output", nmk_pin_output_modes),
1626 NMK_CONFIG_PIN_ARRAY("ste,sleep", nmk_pin_sleep_modes),
1627 NMK_CONFIG_PIN_ARRAY("ste,sleep-input", nmk_pin_sleep_input_modes),
1628 NMK_CONFIG_PIN_ARRAY("ste,sleep-output", nmk_pin_sleep_output_modes),
1629 NMK_CONFIG_PIN_ARRAY("ste,sleep-wakeup", nmk_pin_sleep_wakeup_modes),
1630 NMK_CONFIG_PIN_ARRAY("ste,gpio", nmk_pin_gpio_modes),
1631 NMK_CONFIG_PIN_ARRAY("ste,sleep-pull-disable", nmk_pin_sleep_pdis_modes),
1632};
1633
1634static int nmk_dt_pin_config(int index, int val, unsigned long *config)
1635{
1636 int ret = 0;
1637
1638 if (nmk_cfg_params[index].choice == NULL)
1639 *config = nmk_cfg_params[index].config;
1640 else {
1641 /* test if out of range */
1642 if (val < nmk_cfg_params[index].size) {
1643 *config = nmk_cfg_params[index].config |
1644 nmk_cfg_params[index].choice[val];
1645 }
1646 }
1647 return ret;
1648}
1649
1650static const char *nmk_find_pin_name(struct pinctrl_dev *pctldev, const char *pin_name)
1651{
1652 int i, pin_number;
1653 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1654
1655 if (sscanf((char *)pin_name, "GPIO%d", &pin_number) == 1)
1656 for (i = 0; i < npct->soc->npins; i++)
1657 if (npct->soc->pins[i].number == pin_number)
1658 return npct->soc->pins[i].name;
1659 return NULL;
1660}
1661
1662static bool nmk_pinctrl_dt_get_config(struct device_node *np,
1663 unsigned long *configs)
1664{
1665 bool has_config = 0;
1666 unsigned long cfg = 0;
1667 int i, val, ret;
1668
1669 for (i = 0; i < ARRAY_SIZE(nmk_cfg_params); i++) {
1670 ret = of_property_read_u32(np,
1671 nmk_cfg_params[i].property, &val);
1672 if (ret != -EINVAL) {
1673 if (nmk_dt_pin_config(i, val, &cfg) == 0) {
1674 *configs |= cfg;
1675 has_config = 1;
1676 }
1677 }
1678 }
1679
1680 return has_config;
1681}
1682
1683int nmk_pinctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev,
1684 struct device_node *np,
1685 struct pinctrl_map **map,
1686 unsigned *reserved_maps,
1687 unsigned *num_maps)
1688{
1689 int ret;
1690 const char *function = NULL;
1691 unsigned long configs = 0;
1692 bool has_config = 0;
1693 unsigned reserve = 0;
1694 struct property *prop;
1695 const char *group, *gpio_name;
1696 struct device_node *np_config;
1697
1698 ret = of_property_read_string(np, "ste,function", &function);
1699 if (ret >= 0)
1700 reserve = 1;
1701
1702 has_config = nmk_pinctrl_dt_get_config(np, &configs);
1703
1704 np_config = of_parse_phandle(np, "ste,config", 0);
1705 if (np_config)
1706 has_config |= nmk_pinctrl_dt_get_config(np_config, &configs);
1707
1708 ret = of_property_count_strings(np, "ste,pins");
1709 if (ret < 0)
1710 goto exit;
1711
1712 if (has_config)
1713 reserve++;
1714
1715 reserve *= ret;
1716
1717 ret = nmk_dt_reserve_map(map, reserved_maps, num_maps, reserve);
1718 if (ret < 0)
1719 goto exit;
1720
1721 of_property_for_each_string(np, "ste,pins", prop, group) {
1722 if (function) {
1723 ret = nmk_dt_add_map_mux(map, reserved_maps, num_maps,
1724 group, function);
1725 if (ret < 0)
1726 goto exit;
1727 }
1728 if (has_config) {
1729 gpio_name = nmk_find_pin_name(pctldev, group);
1730
1731 ret = nmk_dt_add_map_configs(map, reserved_maps, num_maps,
1732 gpio_name, &configs, 1);
1733 if (ret < 0)
1734 goto exit;
1735 }
1736
1737 }
1738exit:
1739 return ret;
1740}
1741
1742int nmk_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
1743 struct device_node *np_config,
1744 struct pinctrl_map **map, unsigned *num_maps)
1745{
1746 unsigned reserved_maps;
1747 struct device_node *np;
1748 int ret;
1749
1750 reserved_maps = 0;
1751 *map = NULL;
1752 *num_maps = 0;
1753
1754 for_each_child_of_node(np_config, np) {
1755 ret = nmk_pinctrl_dt_subnode_to_map(pctldev, np, map,
1756 &reserved_maps, num_maps);
1757 if (ret < 0) {
1758 nmk_pinctrl_dt_free_map(pctldev, *map, *num_maps);
1759 return ret;
1760 }
1761 }
1762
1763 return 0;
1764}
1765
Linus Walleije98ea772012-04-26 23:57:25 +02001766static struct pinctrl_ops nmk_pinctrl_ops = {
1767 .get_groups_count = nmk_get_groups_cnt,
1768 .get_group_name = nmk_get_group_name,
1769 .get_group_pins = nmk_get_group_pins,
1770 .pin_dbg_show = nmk_pin_dbg_show,
Gabriel Fernandeze32af882012-12-17 15:53:24 +01001771 .dt_node_to_map = nmk_pinctrl_dt_node_to_map,
1772 .dt_free_map = nmk_pinctrl_dt_free_map,
Linus Walleije98ea772012-04-26 23:57:25 +02001773};
1774
Linus Walleijdbfe8ca2012-05-02 22:56:47 +02001775static int nmk_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev)
1776{
1777 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1778
1779 return npct->soc->nfunctions;
1780}
1781
1782static const char *nmk_pmx_get_func_name(struct pinctrl_dev *pctldev,
1783 unsigned function)
1784{
1785 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1786
1787 return npct->soc->functions[function].name;
1788}
1789
1790static int nmk_pmx_get_func_groups(struct pinctrl_dev *pctldev,
1791 unsigned function,
1792 const char * const **groups,
1793 unsigned * const num_groups)
1794{
1795 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1796
1797 *groups = npct->soc->functions[function].groups;
1798 *num_groups = npct->soc->functions[function].ngroups;
1799
1800 return 0;
1801}
1802
1803static int nmk_pmx_enable(struct pinctrl_dev *pctldev, unsigned function,
1804 unsigned group)
1805{
1806 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1807 const struct nmk_pingroup *g;
1808 static unsigned int slpm[NUM_BANKS];
1809 unsigned long flags;
1810 bool glitch;
1811 int ret = -EINVAL;
1812 int i;
1813
1814 g = &npct->soc->groups[group];
1815
1816 if (g->altsetting < 0)
1817 return -EINVAL;
1818
1819 dev_dbg(npct->dev, "enable group %s, %u pins\n", g->name, g->npins);
1820
Linus Walleijdaf73172012-05-22 11:46:45 +02001821 /*
1822 * If we're setting altfunc C by setting both AFSLA and AFSLB to 1,
1823 * we may pass through an undesired state. In this case we take
1824 * some extra care.
1825 *
1826 * Safe sequence used to switch IOs between GPIO and Alternate-C mode:
1827 * - Save SLPM registers (since we have a shadow register in the
1828 * nmk_chip we're using that as backup)
1829 * - Set SLPM=0 for the IOs you want to switch and others to 1
1830 * - Configure the GPIO registers for the IOs that are being switched
1831 * - Set IOFORCE=1
1832 * - Modify the AFLSA/B registers for the IOs that are being switched
1833 * - Set IOFORCE=0
1834 * - Restore SLPM registers
1835 * - Any spurious wake up event during switch sequence to be ignored
1836 * and cleared
1837 *
1838 * We REALLY need to save ALL slpm registers, because the external
1839 * IOFORCE will switch *all* ports to their sleepmode setting to as
1840 * to avoid glitches. (Not just one port!)
1841 */
Jean-Nicolas Grauxc22df082012-09-27 15:38:50 +02001842 glitch = ((g->altsetting & NMK_GPIO_ALT_C) == NMK_GPIO_ALT_C);
Linus Walleijdbfe8ca2012-05-02 22:56:47 +02001843
1844 if (glitch) {
1845 spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
1846
1847 /* Initially don't put any pins to sleep when switching */
1848 memset(slpm, 0xff, sizeof(slpm));
1849
1850 /*
1851 * Then mask the pins that need to be sleeping now when we're
1852 * switching to the ALT C function.
1853 */
1854 for (i = 0; i < g->npins; i++)
1855 slpm[g->pins[i] / NMK_GPIO_PER_CHIP] &= ~BIT(g->pins[i]);
1856 nmk_gpio_glitch_slpm_init(slpm);
1857 }
1858
1859 for (i = 0; i < g->npins; i++) {
1860 struct pinctrl_gpio_range *range;
1861 struct nmk_gpio_chip *nmk_chip;
1862 struct gpio_chip *chip;
1863 unsigned bit;
1864
1865 range = nmk_match_gpio_range(pctldev, g->pins[i]);
1866 if (!range) {
1867 dev_err(npct->dev,
1868 "invalid pin offset %d in group %s at index %d\n",
1869 g->pins[i], g->name, i);
1870 goto out_glitch;
1871 }
1872 if (!range->gc) {
1873 dev_err(npct->dev, "GPIO chip missing in range for pin offset %d in group %s at index %d\n",
1874 g->pins[i], g->name, i);
1875 goto out_glitch;
1876 }
1877 chip = range->gc;
1878 nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
1879 dev_dbg(npct->dev, "setting pin %d to altsetting %d\n", g->pins[i], g->altsetting);
1880
1881 clk_enable(nmk_chip->clk);
1882 bit = g->pins[i] % NMK_GPIO_PER_CHIP;
1883 /*
1884 * If the pin is switching to altfunc, and there was an
1885 * interrupt installed on it which has been lazy disabled,
1886 * actually mask the interrupt to prevent spurious interrupts
1887 * that would occur while the pin is under control of the
1888 * peripheral. Only SKE does this.
1889 */
1890 nmk_gpio_disable_lazy_irq(nmk_chip, bit);
1891
Jean-Nicolas Grauxc22df082012-09-27 15:38:50 +02001892 __nmk_gpio_set_mode_safe(nmk_chip, bit,
1893 (g->altsetting & NMK_GPIO_ALT_C), glitch);
Linus Walleijdbfe8ca2012-05-02 22:56:47 +02001894 clk_disable(nmk_chip->clk);
Jean-Nicolas Grauxc22df082012-09-27 15:38:50 +02001895
1896 /*
1897 * Call PRCM GPIOCR config function in case ALTC
1898 * has been selected:
1899 * - If selection is a ALTCx, some bits in PRCM GPIOCR registers
1900 * must be set.
1901 * - If selection is pure ALTC and previous selection was ALTCx,
1902 * then some bits in PRCM GPIOCR registers must be cleared.
1903 */
1904 if ((g->altsetting & NMK_GPIO_ALT_C) == NMK_GPIO_ALT_C)
1905 nmk_prcm_altcx_set_mode(npct, g->pins[i],
1906 g->altsetting >> NMK_GPIO_ALT_CX_SHIFT);
Linus Walleijdbfe8ca2012-05-02 22:56:47 +02001907 }
1908
1909 /* When all pins are successfully reconfigured we get here */
1910 ret = 0;
1911
1912out_glitch:
1913 if (glitch) {
1914 nmk_gpio_glitch_slpm_restore(slpm);
1915 spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
1916 }
1917
1918 return ret;
1919}
1920
1921static void nmk_pmx_disable(struct pinctrl_dev *pctldev,
1922 unsigned function, unsigned group)
1923{
1924 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1925 const struct nmk_pingroup *g;
1926
1927 g = &npct->soc->groups[group];
1928
1929 if (g->altsetting < 0)
1930 return;
1931
1932 /* Poke out the mux, set the pin to some default state? */
1933 dev_dbg(npct->dev, "disable group %s, %u pins\n", g->name, g->npins);
1934}
1935
Axel Lin5212d092012-11-16 00:01:35 +08001936static int nmk_gpio_request_enable(struct pinctrl_dev *pctldev,
1937 struct pinctrl_gpio_range *range,
1938 unsigned offset)
Linus Walleijdbfe8ca2012-05-02 22:56:47 +02001939{
1940 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1941 struct nmk_gpio_chip *nmk_chip;
1942 struct gpio_chip *chip;
1943 unsigned bit;
1944
1945 if (!range) {
1946 dev_err(npct->dev, "invalid range\n");
1947 return -EINVAL;
1948 }
1949 if (!range->gc) {
1950 dev_err(npct->dev, "missing GPIO chip in range\n");
1951 return -EINVAL;
1952 }
1953 chip = range->gc;
1954 nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
1955
1956 dev_dbg(npct->dev, "enable pin %u as GPIO\n", offset);
1957
1958 clk_enable(nmk_chip->clk);
1959 bit = offset % NMK_GPIO_PER_CHIP;
1960 /* There is no glitch when converting any pin to GPIO */
1961 __nmk_gpio_set_mode(nmk_chip, bit, NMK_GPIO_ALT_GPIO);
1962 clk_disable(nmk_chip->clk);
1963
1964 return 0;
1965}
1966
Axel Lin5212d092012-11-16 00:01:35 +08001967static void nmk_gpio_disable_free(struct pinctrl_dev *pctldev,
1968 struct pinctrl_gpio_range *range,
1969 unsigned offset)
Linus Walleijdbfe8ca2012-05-02 22:56:47 +02001970{
1971 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
1972
1973 dev_dbg(npct->dev, "disable pin %u as GPIO\n", offset);
1974 /* Set the pin to some default state, GPIO is usually default */
1975}
1976
1977static struct pinmux_ops nmk_pinmux_ops = {
1978 .get_functions_count = nmk_pmx_get_funcs_cnt,
1979 .get_function_name = nmk_pmx_get_func_name,
1980 .get_function_groups = nmk_pmx_get_func_groups,
1981 .enable = nmk_pmx_enable,
1982 .disable = nmk_pmx_disable,
1983 .gpio_request_enable = nmk_gpio_request_enable,
1984 .gpio_disable_free = nmk_gpio_disable_free,
1985};
1986
Axel Lin5212d092012-11-16 00:01:35 +08001987static int nmk_pin_config_get(struct pinctrl_dev *pctldev, unsigned pin,
1988 unsigned long *config)
Linus Walleijd41af622012-05-03 15:58:12 +02001989{
1990 /* Not implemented */
1991 return -EINVAL;
1992}
1993
Axel Lin5212d092012-11-16 00:01:35 +08001994static int nmk_pin_config_set(struct pinctrl_dev *pctldev, unsigned pin,
1995 unsigned long config)
Linus Walleijd41af622012-05-03 15:58:12 +02001996{
1997 static const char *pullnames[] = {
1998 [NMK_GPIO_PULL_NONE] = "none",
1999 [NMK_GPIO_PULL_UP] = "up",
2000 [NMK_GPIO_PULL_DOWN] = "down",
2001 [3] /* illegal */ = "??"
2002 };
2003 static const char *slpmnames[] = {
2004 [NMK_GPIO_SLPM_INPUT] = "input/wakeup",
2005 [NMK_GPIO_SLPM_NOCHANGE] = "no-change/no-wakeup",
2006 };
2007 struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
2008 struct nmk_gpio_chip *nmk_chip;
2009 struct pinctrl_gpio_range *range;
2010 struct gpio_chip *chip;
2011 unsigned bit;
2012
2013 /*
2014 * The pin config contains pin number and altfunction fields, here
2015 * we just ignore that part. It's being handled by the framework and
2016 * pinmux callback respectively.
2017 */
2018 pin_cfg_t cfg = (pin_cfg_t) config;
2019 int pull = PIN_PULL(cfg);
2020 int slpm = PIN_SLPM(cfg);
2021 int output = PIN_DIR(cfg);
2022 int val = PIN_VAL(cfg);
2023 bool lowemi = PIN_LOWEMI(cfg);
2024 bool gpiomode = PIN_GPIOMODE(cfg);
2025 bool sleep = PIN_SLEEPMODE(cfg);
2026
2027 range = nmk_match_gpio_range(pctldev, pin);
2028 if (!range) {
2029 dev_err(npct->dev, "invalid pin offset %d\n", pin);
2030 return -EINVAL;
2031 }
2032 if (!range->gc) {
2033 dev_err(npct->dev, "GPIO chip missing in range for pin %d\n",
2034 pin);
2035 return -EINVAL;
2036 }
2037 chip = range->gc;
2038 nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
2039
2040 if (sleep) {
2041 int slpm_pull = PIN_SLPM_PULL(cfg);
2042 int slpm_output = PIN_SLPM_DIR(cfg);
2043 int slpm_val = PIN_SLPM_VAL(cfg);
2044
2045 /* All pins go into GPIO mode at sleep */
2046 gpiomode = true;
2047
2048 /*
2049 * The SLPM_* values are normal values + 1 to allow zero to
2050 * mean "same as normal".
2051 */
2052 if (slpm_pull)
2053 pull = slpm_pull - 1;
2054 if (slpm_output)
2055 output = slpm_output - 1;
2056 if (slpm_val)
2057 val = slpm_val - 1;
2058
2059 dev_dbg(nmk_chip->chip.dev, "pin %d: sleep pull %s, dir %s, val %s\n",
2060 pin,
2061 slpm_pull ? pullnames[pull] : "same",
2062 slpm_output ? (output ? "output" : "input") : "same",
2063 slpm_val ? (val ? "high" : "low") : "same");
2064 }
2065
2066 dev_dbg(nmk_chip->chip.dev, "pin %d [%#lx]: pull %s, slpm %s (%s%s), lowemi %s\n",
2067 pin, cfg, pullnames[pull], slpmnames[slpm],
2068 output ? "output " : "input",
2069 output ? (val ? "high" : "low") : "",
2070 lowemi ? "on" : "off" );
2071
2072 clk_enable(nmk_chip->clk);
2073 bit = pin % NMK_GPIO_PER_CHIP;
2074 if (gpiomode)
2075 /* No glitch when going to GPIO mode */
2076 __nmk_gpio_set_mode(nmk_chip, bit, NMK_GPIO_ALT_GPIO);
2077 if (output)
2078 __nmk_gpio_make_output(nmk_chip, bit, val);
2079 else {
2080 __nmk_gpio_make_input(nmk_chip, bit);
2081 __nmk_gpio_set_pull(nmk_chip, bit, pull);
2082 }
2083 /* TODO: isn't this only applicable on output pins? */
2084 __nmk_gpio_set_lowemi(nmk_chip, bit, lowemi);
2085
2086 __nmk_gpio_set_slpm(nmk_chip, bit, slpm);
2087 clk_disable(nmk_chip->clk);
2088 return 0;
2089}
2090
2091static struct pinconf_ops nmk_pinconf_ops = {
2092 .pin_config_get = nmk_pin_config_get,
2093 .pin_config_set = nmk_pin_config_set,
2094};
2095
Linus Walleije98ea772012-04-26 23:57:25 +02002096static struct pinctrl_desc nmk_pinctrl_desc = {
2097 .name = "pinctrl-nomadik",
2098 .pctlops = &nmk_pinctrl_ops,
Linus Walleijdbfe8ca2012-05-02 22:56:47 +02002099 .pmxops = &nmk_pinmux_ops,
Linus Walleijd41af622012-05-03 15:58:12 +02002100 .confops = &nmk_pinconf_ops,
Linus Walleije98ea772012-04-26 23:57:25 +02002101 .owner = THIS_MODULE,
2102};
2103
Lee Jones855f80c2012-05-26 06:09:29 +01002104static const struct of_device_id nmk_pinctrl_match[] = {
2105 {
Gabriel Fernandeze32af882012-12-17 15:53:24 +01002106 .compatible = "stericsson,nmk-pinctrl",
Lee Jones855f80c2012-05-26 06:09:29 +01002107 .data = (void *)PINCTRL_NMK_DB8500,
2108 },
2109 {},
2110};
2111
Julien Delacou8d99b322012-12-11 09:17:47 +01002112static int nmk_pinctrl_suspend(struct platform_device *pdev, pm_message_t state)
2113{
2114 struct nmk_pinctrl *npct;
2115
2116 npct = platform_get_drvdata(pdev);
2117 if (!npct)
2118 return -EINVAL;
2119
2120 return pinctrl_force_sleep(npct->pctl);
2121}
2122
2123static int nmk_pinctrl_resume(struct platform_device *pdev)
2124{
2125 struct nmk_pinctrl *npct;
2126
2127 npct = platform_get_drvdata(pdev);
2128 if (!npct)
2129 return -EINVAL;
2130
2131 return pinctrl_force_default(npct->pctl);
2132}
2133
Greg Kroah-Hartman150632b2012-12-21 13:10:23 -08002134static int nmk_pinctrl_probe(struct platform_device *pdev)
Linus Walleije98ea772012-04-26 23:57:25 +02002135{
2136 const struct platform_device_id *platid = platform_get_device_id(pdev);
Lee Jones855f80c2012-05-26 06:09:29 +01002137 struct device_node *np = pdev->dev.of_node;
Linus Walleije98ea772012-04-26 23:57:25 +02002138 struct nmk_pinctrl *npct;
Jonas Aabergf1671bf2012-10-25 08:40:42 +02002139 struct resource *res;
Lee Jones855f80c2012-05-26 06:09:29 +01002140 unsigned int version = 0;
Linus Walleije98ea772012-04-26 23:57:25 +02002141 int i;
2142
2143 npct = devm_kzalloc(&pdev->dev, sizeof(*npct), GFP_KERNEL);
2144 if (!npct)
2145 return -ENOMEM;
2146
Lee Jones855f80c2012-05-26 06:09:29 +01002147 if (platid)
2148 version = platid->driver_data;
Axel Lin953e9e92012-11-15 12:56:05 +08002149 else if (np) {
2150 const struct of_device_id *match;
2151
2152 match = of_match_device(nmk_pinctrl_match, &pdev->dev);
2153 if (!match)
2154 return -ENODEV;
2155 version = (unsigned int) match->data;
2156 }
Lee Jones855f80c2012-05-26 06:09:29 +01002157
Linus Walleije98ea772012-04-26 23:57:25 +02002158 /* Poke in other ASIC variants here */
Linus Walleijf79c5ed2012-08-10 00:43:28 +02002159 if (version == PINCTRL_NMK_STN8815)
2160 nmk_pinctrl_stn8815_init(&npct->soc);
Lee Jones855f80c2012-05-26 06:09:29 +01002161 if (version == PINCTRL_NMK_DB8500)
Linus Walleije98ea772012-04-26 23:57:25 +02002162 nmk_pinctrl_db8500_init(&npct->soc);
Patrice Chotard45a1b532012-07-20 15:45:22 +02002163 if (version == PINCTRL_NMK_DB8540)
2164 nmk_pinctrl_db8540_init(&npct->soc);
Linus Walleije98ea772012-04-26 23:57:25 +02002165
Jonas Aabergf1671bf2012-10-25 08:40:42 +02002166 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2167 if (res) {
2168 npct->prcm_base = devm_ioremap(&pdev->dev, res->start,
2169 resource_size(res));
2170 if (!npct->prcm_base) {
2171 dev_err(&pdev->dev,
2172 "failed to ioremap PRCM registers\n");
2173 return -ENOMEM;
2174 }
Fabio Baltieri4ca075d2012-12-18 10:12:11 +01002175 } else if (version == PINCTRL_NMK_STN8815) {
Jonas Aabergf1671bf2012-10-25 08:40:42 +02002176 dev_info(&pdev->dev,
2177 "No PRCM base, assume no ALT-Cx control is available\n");
Fabio Baltieri4ca075d2012-12-18 10:12:11 +01002178 } else {
2179 dev_err(&pdev->dev, "missing PRCM base address\n");
2180 return -EINVAL;
Jonas Aabergf1671bf2012-10-25 08:40:42 +02002181 }
2182
Linus Walleije98ea772012-04-26 23:57:25 +02002183 /*
2184 * We need all the GPIO drivers to probe FIRST, or we will not be able
2185 * to obtain references to the struct gpio_chip * for them, and we
2186 * need this to proceed.
2187 */
2188 for (i = 0; i < npct->soc->gpio_num_ranges; i++) {
Patrice Chotard1d853ca2012-10-08 16:50:24 +02002189 if (!nmk_gpio_chips[npct->soc->gpio_ranges[i].id]) {
Linus Walleije98ea772012-04-26 23:57:25 +02002190 dev_warn(&pdev->dev, "GPIO chip %d not registered yet\n", i);
Linus Walleije98ea772012-04-26 23:57:25 +02002191 return -EPROBE_DEFER;
2192 }
Patrice Chotard1d853ca2012-10-08 16:50:24 +02002193 npct->soc->gpio_ranges[i].gc = &nmk_gpio_chips[npct->soc->gpio_ranges[i].id]->chip;
Linus Walleije98ea772012-04-26 23:57:25 +02002194 }
2195
2196 nmk_pinctrl_desc.pins = npct->soc->pins;
2197 nmk_pinctrl_desc.npins = npct->soc->npins;
2198 npct->dev = &pdev->dev;
Jonas Aabergf1671bf2012-10-25 08:40:42 +02002199
Linus Walleije98ea772012-04-26 23:57:25 +02002200 npct->pctl = pinctrl_register(&nmk_pinctrl_desc, &pdev->dev, npct);
2201 if (!npct->pctl) {
2202 dev_err(&pdev->dev, "could not register Nomadik pinctrl driver\n");
2203 return -EINVAL;
2204 }
2205
2206 /* We will handle a range of GPIO pins */
2207 for (i = 0; i < npct->soc->gpio_num_ranges; i++)
2208 pinctrl_add_gpio_range(npct->pctl, &npct->soc->gpio_ranges[i]);
2209
2210 platform_set_drvdata(pdev, npct);
2211 dev_info(&pdev->dev, "initialized Nomadik pin control driver\n");
2212
2213 return 0;
2214}
2215
Lee Jones513c27f2012-04-13 15:05:05 +01002216static const struct of_device_id nmk_gpio_match[] = {
2217 { .compatible = "st,nomadik-gpio", },
2218 {}
2219};
2220
Rabin Vincent3e3c62c2010-03-03 04:52:34 +01002221static struct platform_driver nmk_gpio_driver = {
2222 .driver = {
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01002223 .owner = THIS_MODULE,
2224 .name = "gpio",
Lee Jones513c27f2012-04-13 15:05:05 +01002225 .of_match_table = nmk_gpio_match,
Rabin Vincent5317e4d12011-02-10 09:29:53 +05302226 },
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01002227 .probe = nmk_gpio_probe,
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01002228};
2229
Linus Walleije98ea772012-04-26 23:57:25 +02002230static const struct platform_device_id nmk_pinctrl_id[] = {
2231 { "pinctrl-stn8815", PINCTRL_NMK_STN8815 },
2232 { "pinctrl-db8500", PINCTRL_NMK_DB8500 },
Patrice Chotard45a1b532012-07-20 15:45:22 +02002233 { "pinctrl-db8540", PINCTRL_NMK_DB8540 },
Axel Lin8c995d62012-11-04 23:30:42 +08002234 { }
Linus Walleije98ea772012-04-26 23:57:25 +02002235};
2236
2237static struct platform_driver nmk_pinctrl_driver = {
2238 .driver = {
2239 .owner = THIS_MODULE,
2240 .name = "pinctrl-nomadik",
Lee Jones855f80c2012-05-26 06:09:29 +01002241 .of_match_table = nmk_pinctrl_match,
Linus Walleije98ea772012-04-26 23:57:25 +02002242 },
2243 .probe = nmk_pinctrl_probe,
2244 .id_table = nmk_pinctrl_id,
Julien Delacou8d99b322012-12-11 09:17:47 +01002245#ifdef CONFIG_PM
2246 .suspend = nmk_pinctrl_suspend,
2247 .resume = nmk_pinctrl_resume,
2248#endif
Linus Walleije98ea772012-04-26 23:57:25 +02002249};
2250
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01002251static int __init nmk_gpio_init(void)
2252{
Linus Walleije98ea772012-04-26 23:57:25 +02002253 int ret;
2254
2255 ret = platform_driver_register(&nmk_gpio_driver);
2256 if (ret)
2257 return ret;
2258 return platform_driver_register(&nmk_pinctrl_driver);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01002259}
2260
Rabin Vincent33f45ea2010-06-02 06:09:52 +01002261core_initcall(nmk_gpio_init);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01002262
2263MODULE_AUTHOR("Prafulla WADASKAR and Alessandro Rubini");
2264MODULE_DESCRIPTION("Nomadik GPIO Driver");
2265MODULE_LICENSE("GPL");