blob: 8b10b1ac9071374b557ece6c38eaf0b927e53812 [file] [log] [blame]
Thomas Abraham43b169d2012-09-07 06:07:19 +09001/*
2 * Exynos specific support for Samsung pinctrl/gpiolib driver with eint support.
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
6 * Copyright (c) 2012 Linaro Ltd
7 * http://www.linaro.org
8 *
9 * Author: Thomas Abraham <thomas.ab@samsung.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This file contains the Samsung Exynos specific information required by the
17 * the Samsung pinctrl/gpiolib driver. It also includes the implementation of
18 * external gpio and wakeup interrupt support.
19 */
20
21#include <linux/module.h>
22#include <linux/device.h>
23#include <linux/interrupt.h>
24#include <linux/irqdomain.h>
25#include <linux/irq.h>
26#include <linux/of_irq.h>
27#include <linux/io.h>
28#include <linux/slab.h>
Tomasz Figa19846952013-03-18 22:31:50 +010029#include <linux/spinlock.h>
Thomas Abraham43b169d2012-09-07 06:07:19 +090030#include <linux/err.h>
31
32#include <asm/mach/irq.h>
33
34#include "pinctrl-samsung.h"
35#include "pinctrl-exynos.h"
36
Tomasz Figa499147c2013-03-18 22:31:52 +010037
38static struct samsung_pin_bank_type bank_type_off = {
39 .fld_width = { 4, 1, 2, 2, 2, 2, },
Tomasz Figa43fc9e72013-03-18 22:31:53 +010040 .reg_offset = { 0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, },
Tomasz Figa499147c2013-03-18 22:31:52 +010041};
42
43static struct samsung_pin_bank_type bank_type_alive = {
44 .fld_width = { 4, 1, 2, 2, },
Tomasz Figa43fc9e72013-03-18 22:31:53 +010045 .reg_offset = { 0x00, 0x04, 0x08, 0x0c, },
Tomasz Figa499147c2013-03-18 22:31:52 +010046};
47
Thomas Abraham43b169d2012-09-07 06:07:19 +090048/* list of external wakeup controllers supported */
49static const struct of_device_id exynos_wkup_irq_ids[] = {
50 { .compatible = "samsung,exynos4210-wakeup-eint", },
Axel Linafa538c2012-11-02 21:46:13 +080051 { }
Thomas Abraham43b169d2012-09-07 06:07:19 +090052};
53
54static void exynos_gpio_irq_unmask(struct irq_data *irqd)
55{
Tomasz Figa595be722012-10-11 10:11:16 +020056 struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
57 struct samsung_pinctrl_drv_data *d = bank->drvdata;
58 unsigned long reg_mask = d->ctrl->geint_mask + bank->eint_offset;
Thomas Abraham43b169d2012-09-07 06:07:19 +090059 unsigned long mask;
60
61 mask = readl(d->virt_base + reg_mask);
Tomasz Figa595be722012-10-11 10:11:16 +020062 mask &= ~(1 << irqd->hwirq);
Thomas Abraham43b169d2012-09-07 06:07:19 +090063 writel(mask, d->virt_base + reg_mask);
64}
65
66static void exynos_gpio_irq_mask(struct irq_data *irqd)
67{
Tomasz Figa595be722012-10-11 10:11:16 +020068 struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
69 struct samsung_pinctrl_drv_data *d = bank->drvdata;
70 unsigned long reg_mask = d->ctrl->geint_mask + bank->eint_offset;
Thomas Abraham43b169d2012-09-07 06:07:19 +090071 unsigned long mask;
72
73 mask = readl(d->virt_base + reg_mask);
Tomasz Figa595be722012-10-11 10:11:16 +020074 mask |= 1 << irqd->hwirq;
Thomas Abraham43b169d2012-09-07 06:07:19 +090075 writel(mask, d->virt_base + reg_mask);
76}
77
78static void exynos_gpio_irq_ack(struct irq_data *irqd)
79{
Tomasz Figa595be722012-10-11 10:11:16 +020080 struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
81 struct samsung_pinctrl_drv_data *d = bank->drvdata;
82 unsigned long reg_pend = d->ctrl->geint_pend + bank->eint_offset;
Thomas Abraham43b169d2012-09-07 06:07:19 +090083
Tomasz Figa595be722012-10-11 10:11:16 +020084 writel(1 << irqd->hwirq, d->virt_base + reg_pend);
Thomas Abraham43b169d2012-09-07 06:07:19 +090085}
86
87static int exynos_gpio_irq_set_type(struct irq_data *irqd, unsigned int type)
88{
Tomasz Figa595be722012-10-11 10:11:16 +020089 struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
Tomasz Figa499147c2013-03-18 22:31:52 +010090 struct samsung_pin_bank_type *bank_type = bank->type;
Tomasz Figa595be722012-10-11 10:11:16 +020091 struct samsung_pinctrl_drv_data *d = bank->drvdata;
Thomas Abraham43b169d2012-09-07 06:07:19 +090092 struct samsung_pin_ctrl *ctrl = d->ctrl;
Tomasz Figa595be722012-10-11 10:11:16 +020093 unsigned int pin = irqd->hwirq;
94 unsigned int shift = EXYNOS_EINT_CON_LEN * pin;
Thomas Abraham43b169d2012-09-07 06:07:19 +090095 unsigned int con, trig_type;
Tomasz Figa595be722012-10-11 10:11:16 +020096 unsigned long reg_con = ctrl->geint_con + bank->eint_offset;
Tomasz Figa19846952013-03-18 22:31:50 +010097 unsigned long flags;
Tomasz Figaee2f5732012-09-21 07:33:48 +090098 unsigned int mask;
Thomas Abraham43b169d2012-09-07 06:07:19 +090099
100 switch (type) {
101 case IRQ_TYPE_EDGE_RISING:
102 trig_type = EXYNOS_EINT_EDGE_RISING;
103 break;
104 case IRQ_TYPE_EDGE_FALLING:
105 trig_type = EXYNOS_EINT_EDGE_FALLING;
106 break;
107 case IRQ_TYPE_EDGE_BOTH:
108 trig_type = EXYNOS_EINT_EDGE_BOTH;
109 break;
110 case IRQ_TYPE_LEVEL_HIGH:
111 trig_type = EXYNOS_EINT_LEVEL_HIGH;
112 break;
113 case IRQ_TYPE_LEVEL_LOW:
114 trig_type = EXYNOS_EINT_LEVEL_LOW;
115 break;
116 default:
117 pr_err("unsupported external interrupt type\n");
118 return -EINVAL;
119 }
120
121 if (type & IRQ_TYPE_EDGE_BOTH)
122 __irq_set_handler_locked(irqd->irq, handle_edge_irq);
123 else
124 __irq_set_handler_locked(irqd->irq, handle_level_irq);
125
126 con = readl(d->virt_base + reg_con);
127 con &= ~(EXYNOS_EINT_CON_MASK << shift);
128 con |= trig_type << shift;
129 writel(con, d->virt_base + reg_con);
Tomasz Figaee2f5732012-09-21 07:33:48 +0900130
Tomasz Figa43fc9e72013-03-18 22:31:53 +0100131 reg_con = bank->pctl_offset + bank_type->reg_offset[PINCFG_TYPE_FUNC];
Tomasz Figa499147c2013-03-18 22:31:52 +0100132 shift = pin * bank_type->fld_width[PINCFG_TYPE_FUNC];
133 mask = (1 << bank_type->fld_width[PINCFG_TYPE_FUNC]) - 1;
Tomasz Figaee2f5732012-09-21 07:33:48 +0900134
Tomasz Figa19846952013-03-18 22:31:50 +0100135 spin_lock_irqsave(&bank->slock, flags);
136
Tomasz Figaee2f5732012-09-21 07:33:48 +0900137 con = readl(d->virt_base + reg_con);
138 con &= ~(mask << shift);
139 con |= EXYNOS_EINT_FUNC << shift;
140 writel(con, d->virt_base + reg_con);
141
Tomasz Figa19846952013-03-18 22:31:50 +0100142 spin_unlock_irqrestore(&bank->slock, flags);
143
Thomas Abraham43b169d2012-09-07 06:07:19 +0900144 return 0;
145}
146
147/*
148 * irq_chip for gpio interrupts.
149 */
150static struct irq_chip exynos_gpio_irq_chip = {
151 .name = "exynos_gpio_irq_chip",
152 .irq_unmask = exynos_gpio_irq_unmask,
153 .irq_mask = exynos_gpio_irq_mask,
154 .irq_ack = exynos_gpio_irq_ack,
155 .irq_set_type = exynos_gpio_irq_set_type,
156};
157
Thomas Abraham43b169d2012-09-07 06:07:19 +0900158static int exynos_gpio_irq_map(struct irq_domain *h, unsigned int virq,
159 irq_hw_number_t hw)
160{
Tomasz Figa595be722012-10-11 10:11:16 +0200161 struct samsung_pin_bank *b = h->host_data;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900162
Tomasz Figa595be722012-10-11 10:11:16 +0200163 irq_set_chip_data(virq, b);
Thomas Abraham43b169d2012-09-07 06:07:19 +0900164 irq_set_chip_and_handler(virq, &exynos_gpio_irq_chip,
165 handle_level_irq);
166 set_irq_flags(virq, IRQF_VALID);
167 return 0;
168}
169
Thomas Abraham43b169d2012-09-07 06:07:19 +0900170/*
171 * irq domain callbacks for external gpio interrupt controller.
172 */
173static const struct irq_domain_ops exynos_gpio_irqd_ops = {
174 .map = exynos_gpio_irq_map,
Thomas Abraham43b169d2012-09-07 06:07:19 +0900175 .xlate = irq_domain_xlate_twocell,
176};
177
178static irqreturn_t exynos_eint_gpio_irq(int irq, void *data)
179{
180 struct samsung_pinctrl_drv_data *d = data;
181 struct samsung_pin_ctrl *ctrl = d->ctrl;
182 struct samsung_pin_bank *bank = ctrl->pin_banks;
183 unsigned int svc, group, pin, virq;
184
185 svc = readl(d->virt_base + ctrl->svc);
186 group = EXYNOS_SVC_GROUP(svc);
187 pin = svc & EXYNOS_SVC_NUM_MASK;
188
189 if (!group)
190 return IRQ_HANDLED;
191 bank += (group - 1);
192
Tomasz Figa595be722012-10-11 10:11:16 +0200193 virq = irq_linear_revmap(bank->irq_domain, pin);
Thomas Abraham43b169d2012-09-07 06:07:19 +0900194 if (!virq)
195 return IRQ_NONE;
196 generic_handle_irq(virq);
197 return IRQ_HANDLED;
198}
199
200/*
201 * exynos_eint_gpio_init() - setup handling of external gpio interrupts.
202 * @d: driver data of samsung pinctrl driver.
203 */
204static int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d)
205{
Tomasz Figa595be722012-10-11 10:11:16 +0200206 struct samsung_pin_bank *bank;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900207 struct device *dev = d->dev;
208 unsigned int ret;
Tomasz Figa595be722012-10-11 10:11:16 +0200209 unsigned int i;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900210
211 if (!d->irq) {
212 dev_err(dev, "irq number not available\n");
213 return -EINVAL;
214 }
215
216 ret = devm_request_irq(dev, d->irq, exynos_eint_gpio_irq,
217 0, dev_name(dev), d);
218 if (ret) {
219 dev_err(dev, "irq request failed\n");
220 return -ENXIO;
221 }
222
Tomasz Figa595be722012-10-11 10:11:16 +0200223 bank = d->ctrl->pin_banks;
224 for (i = 0; i < d->ctrl->nr_banks; ++i, ++bank) {
225 if (bank->eint_type != EINT_TYPE_GPIO)
226 continue;
227 bank->irq_domain = irq_domain_add_linear(bank->of_node,
228 bank->nr_pins, &exynos_gpio_irqd_ops, bank);
229 if (!bank->irq_domain) {
230 dev_err(dev, "gpio irq domain add failed\n");
231 return -ENXIO;
232 }
Thomas Abraham43b169d2012-09-07 06:07:19 +0900233 }
234
235 return 0;
236}
237
238static void exynos_wkup_irq_unmask(struct irq_data *irqd)
239{
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200240 struct samsung_pin_bank *b = irq_data_get_irq_chip_data(irqd);
241 struct samsung_pinctrl_drv_data *d = b->drvdata;
242 unsigned long reg_mask = d->ctrl->weint_mask + b->eint_offset;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900243 unsigned long mask;
244
245 mask = readl(d->virt_base + reg_mask);
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200246 mask &= ~(1 << irqd->hwirq);
Thomas Abraham43b169d2012-09-07 06:07:19 +0900247 writel(mask, d->virt_base + reg_mask);
248}
249
250static void exynos_wkup_irq_mask(struct irq_data *irqd)
251{
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200252 struct samsung_pin_bank *b = irq_data_get_irq_chip_data(irqd);
253 struct samsung_pinctrl_drv_data *d = b->drvdata;
254 unsigned long reg_mask = d->ctrl->weint_mask + b->eint_offset;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900255 unsigned long mask;
256
257 mask = readl(d->virt_base + reg_mask);
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200258 mask |= 1 << irqd->hwirq;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900259 writel(mask, d->virt_base + reg_mask);
260}
261
262static void exynos_wkup_irq_ack(struct irq_data *irqd)
263{
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200264 struct samsung_pin_bank *b = irq_data_get_irq_chip_data(irqd);
265 struct samsung_pinctrl_drv_data *d = b->drvdata;
266 unsigned long pend = d->ctrl->weint_pend + b->eint_offset;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900267
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200268 writel(1 << irqd->hwirq, d->virt_base + pend);
Thomas Abraham43b169d2012-09-07 06:07:19 +0900269}
270
271static int exynos_wkup_irq_set_type(struct irq_data *irqd, unsigned int type)
272{
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200273 struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
Tomasz Figa499147c2013-03-18 22:31:52 +0100274 struct samsung_pin_bank_type *bank_type = bank->type;
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200275 struct samsung_pinctrl_drv_data *d = bank->drvdata;
276 unsigned int pin = irqd->hwirq;
277 unsigned long reg_con = d->ctrl->weint_con + bank->eint_offset;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900278 unsigned long shift = EXYNOS_EINT_CON_LEN * pin;
279 unsigned long con, trig_type;
Tomasz Figa19846952013-03-18 22:31:50 +0100280 unsigned long flags;
Tomasz Figa22b9ba02012-10-11 10:11:19 +0200281 unsigned int mask;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900282
283 switch (type) {
284 case IRQ_TYPE_EDGE_RISING:
285 trig_type = EXYNOS_EINT_EDGE_RISING;
286 break;
287 case IRQ_TYPE_EDGE_FALLING:
288 trig_type = EXYNOS_EINT_EDGE_FALLING;
289 break;
290 case IRQ_TYPE_EDGE_BOTH:
291 trig_type = EXYNOS_EINT_EDGE_BOTH;
292 break;
293 case IRQ_TYPE_LEVEL_HIGH:
294 trig_type = EXYNOS_EINT_LEVEL_HIGH;
295 break;
296 case IRQ_TYPE_LEVEL_LOW:
297 trig_type = EXYNOS_EINT_LEVEL_LOW;
298 break;
299 default:
300 pr_err("unsupported external interrupt type\n");
301 return -EINVAL;
302 }
303
304 if (type & IRQ_TYPE_EDGE_BOTH)
305 __irq_set_handler_locked(irqd->irq, handle_edge_irq);
306 else
307 __irq_set_handler_locked(irqd->irq, handle_level_irq);
308
309 con = readl(d->virt_base + reg_con);
310 con &= ~(EXYNOS_EINT_CON_MASK << shift);
311 con |= trig_type << shift;
312 writel(con, d->virt_base + reg_con);
Tomasz Figa22b9ba02012-10-11 10:11:19 +0200313
Tomasz Figa43fc9e72013-03-18 22:31:53 +0100314 reg_con = bank->pctl_offset + bank_type->reg_offset[PINCFG_TYPE_FUNC];
Tomasz Figa499147c2013-03-18 22:31:52 +0100315 shift = pin * bank_type->fld_width[PINCFG_TYPE_FUNC];
316 mask = (1 << bank_type->fld_width[PINCFG_TYPE_FUNC]) - 1;
Tomasz Figa22b9ba02012-10-11 10:11:19 +0200317
Tomasz Figa19846952013-03-18 22:31:50 +0100318 spin_lock_irqsave(&bank->slock, flags);
319
Tomasz Figa22b9ba02012-10-11 10:11:19 +0200320 con = readl(d->virt_base + reg_con);
321 con &= ~(mask << shift);
322 con |= EXYNOS_EINT_FUNC << shift;
323 writel(con, d->virt_base + reg_con);
324
Tomasz Figa19846952013-03-18 22:31:50 +0100325 spin_unlock_irqrestore(&bank->slock, flags);
326
Thomas Abraham43b169d2012-09-07 06:07:19 +0900327 return 0;
328}
329
330/*
331 * irq_chip for wakeup interrupts
332 */
333static struct irq_chip exynos_wkup_irq_chip = {
334 .name = "exynos_wkup_irq_chip",
335 .irq_unmask = exynos_wkup_irq_unmask,
336 .irq_mask = exynos_wkup_irq_mask,
337 .irq_ack = exynos_wkup_irq_ack,
338 .irq_set_type = exynos_wkup_irq_set_type,
339};
340
341/* interrupt handler for wakeup interrupts 0..15 */
342static void exynos_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
343{
344 struct exynos_weint_data *eintd = irq_get_handler_data(irq);
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200345 struct samsung_pin_bank *bank = eintd->bank;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900346 struct irq_chip *chip = irq_get_chip(irq);
347 int eint_irq;
348
349 chained_irq_enter(chip, desc);
350 chip->irq_mask(&desc->irq_data);
351
352 if (chip->irq_ack)
353 chip->irq_ack(&desc->irq_data);
354
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200355 eint_irq = irq_linear_revmap(bank->irq_domain, eintd->irq);
Thomas Abraham43b169d2012-09-07 06:07:19 +0900356 generic_handle_irq(eint_irq);
357 chip->irq_unmask(&desc->irq_data);
358 chained_irq_exit(chip, desc);
359}
360
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200361static inline void exynos_irq_demux_eint(unsigned long pend,
362 struct irq_domain *domain)
Thomas Abraham43b169d2012-09-07 06:07:19 +0900363{
364 unsigned int irq;
365
366 while (pend) {
367 irq = fls(pend) - 1;
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200368 generic_handle_irq(irq_find_mapping(domain, irq));
Thomas Abraham43b169d2012-09-07 06:07:19 +0900369 pend &= ~(1 << irq);
370 }
371}
372
373/* interrupt handler for wakeup interrupt 16 */
374static void exynos_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
375{
376 struct irq_chip *chip = irq_get_chip(irq);
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200377 struct exynos_muxed_weint_data *eintd = irq_get_handler_data(irq);
378 struct samsung_pinctrl_drv_data *d = eintd->banks[0]->drvdata;
379 struct samsung_pin_ctrl *ctrl = d->ctrl;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900380 unsigned long pend;
Tomasz Figade590492012-09-21 07:33:55 +0900381 unsigned long mask;
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200382 int i;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900383
384 chained_irq_enter(chip, desc);
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200385
386 for (i = 0; i < eintd->nr_banks; ++i) {
387 struct samsung_pin_bank *b = eintd->banks[i];
388 pend = readl(d->virt_base + ctrl->weint_pend + b->eint_offset);
389 mask = readl(d->virt_base + ctrl->weint_mask + b->eint_offset);
390 exynos_irq_demux_eint(pend & ~mask, b->irq_domain);
391 }
392
Thomas Abraham43b169d2012-09-07 06:07:19 +0900393 chained_irq_exit(chip, desc);
394}
395
396static int exynos_wkup_irq_map(struct irq_domain *h, unsigned int virq,
397 irq_hw_number_t hw)
398{
399 irq_set_chip_and_handler(virq, &exynos_wkup_irq_chip, handle_level_irq);
400 irq_set_chip_data(virq, h->host_data);
401 set_irq_flags(virq, IRQF_VALID);
402 return 0;
403}
404
405/*
406 * irq domain callbacks for external wakeup interrupt controller.
407 */
408static const struct irq_domain_ops exynos_wkup_irqd_ops = {
409 .map = exynos_wkup_irq_map,
410 .xlate = irq_domain_xlate_twocell,
411};
412
413/*
414 * exynos_eint_wkup_init() - setup handling of external wakeup interrupts.
415 * @d: driver data of samsung pinctrl driver.
416 */
417static int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
418{
419 struct device *dev = d->dev;
Tomasz Figac3ad0562012-09-21 07:34:01 +0900420 struct device_node *wkup_np = NULL;
421 struct device_node *np;
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200422 struct samsung_pin_bank *bank;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900423 struct exynos_weint_data *weint_data;
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200424 struct exynos_muxed_weint_data *muxed_data;
425 unsigned int muxed_banks = 0;
426 unsigned int i;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900427 int idx, irq;
428
Tomasz Figac3ad0562012-09-21 07:34:01 +0900429 for_each_child_of_node(dev->of_node, np) {
430 if (of_match_node(exynos_wkup_irq_ids, np)) {
431 wkup_np = np;
432 break;
433 }
Thomas Abraham43b169d2012-09-07 06:07:19 +0900434 }
Tomasz Figac3ad0562012-09-21 07:34:01 +0900435 if (!wkup_np)
436 return -ENODEV;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900437
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200438 bank = d->ctrl->pin_banks;
439 for (i = 0; i < d->ctrl->nr_banks; ++i, ++bank) {
440 if (bank->eint_type != EINT_TYPE_WKUP)
441 continue;
442
443 bank->irq_domain = irq_domain_add_linear(bank->of_node,
444 bank->nr_pins, &exynos_wkup_irqd_ops, bank);
445 if (!bank->irq_domain) {
446 dev_err(dev, "wkup irq domain add failed\n");
447 return -ENXIO;
448 }
449
450 if (!of_find_property(bank->of_node, "interrupts", NULL)) {
451 bank->eint_type = EINT_TYPE_WKUP_MUX;
452 ++muxed_banks;
453 continue;
454 }
455
456 weint_data = devm_kzalloc(dev, bank->nr_pins
457 * sizeof(*weint_data), GFP_KERNEL);
458 if (!weint_data) {
459 dev_err(dev, "could not allocate memory for weint_data\n");
460 return -ENOMEM;
461 }
462
463 for (idx = 0; idx < bank->nr_pins; ++idx) {
464 irq = irq_of_parse_and_map(bank->of_node, idx);
465 if (!irq) {
466 dev_err(dev, "irq number for eint-%s-%d not found\n",
467 bank->name, idx);
468 continue;
469 }
470 weint_data[idx].irq = idx;
471 weint_data[idx].bank = bank;
472 irq_set_handler_data(irq, &weint_data[idx]);
473 irq_set_chained_handler(irq, exynos_irq_eint0_15);
474 }
Thomas Abraham43b169d2012-09-07 06:07:19 +0900475 }
476
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200477 if (!muxed_banks)
478 return 0;
479
480 irq = irq_of_parse_and_map(wkup_np, 0);
481 if (!irq) {
482 dev_err(dev, "irq number for muxed EINTs not found\n");
483 return 0;
484 }
485
486 muxed_data = devm_kzalloc(dev, sizeof(*muxed_data)
487 + muxed_banks*sizeof(struct samsung_pin_bank *), GFP_KERNEL);
488 if (!muxed_data) {
489 dev_err(dev, "could not allocate memory for muxed_data\n");
Thomas Abraham43b169d2012-09-07 06:07:19 +0900490 return -ENOMEM;
491 }
492
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200493 irq_set_chained_handler(irq, exynos_irq_demux_eint16_31);
494 irq_set_handler_data(irq, muxed_data);
Thomas Abraham43b169d2012-09-07 06:07:19 +0900495
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200496 bank = d->ctrl->pin_banks;
497 idx = 0;
498 for (i = 0; i < d->ctrl->nr_banks; ++i, ++bank) {
499 if (bank->eint_type != EINT_TYPE_WKUP_MUX)
500 continue;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900501
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200502 muxed_data->banks[idx++] = bank;
Thomas Abraham43b169d2012-09-07 06:07:19 +0900503 }
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200504 muxed_data->nr_banks = muxed_banks;
505
Thomas Abraham43b169d2012-09-07 06:07:19 +0900506 return 0;
507}
508
509/* pin banks of exynos4210 pin-controller 0 */
510static struct samsung_pin_bank exynos4210_pin_banks0[] = {
Tomasz Figa1b6056d2012-10-11 10:11:15 +0200511 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00),
512 EXYNOS_PIN_BANK_EINTG(6, 0x020, "gpa1", 0x04),
513 EXYNOS_PIN_BANK_EINTG(8, 0x040, "gpb", 0x08),
514 EXYNOS_PIN_BANK_EINTG(5, 0x060, "gpc0", 0x0c),
515 EXYNOS_PIN_BANK_EINTG(5, 0x080, "gpc1", 0x10),
516 EXYNOS_PIN_BANK_EINTG(4, 0x0A0, "gpd0", 0x14),
517 EXYNOS_PIN_BANK_EINTG(4, 0x0C0, "gpd1", 0x18),
518 EXYNOS_PIN_BANK_EINTG(5, 0x0E0, "gpe0", 0x1c),
519 EXYNOS_PIN_BANK_EINTG(8, 0x100, "gpe1", 0x20),
520 EXYNOS_PIN_BANK_EINTG(6, 0x120, "gpe2", 0x24),
521 EXYNOS_PIN_BANK_EINTG(8, 0x140, "gpe3", 0x28),
522 EXYNOS_PIN_BANK_EINTG(8, 0x160, "gpe4", 0x2c),
523 EXYNOS_PIN_BANK_EINTG(8, 0x180, "gpf0", 0x30),
524 EXYNOS_PIN_BANK_EINTG(8, 0x1A0, "gpf1", 0x34),
525 EXYNOS_PIN_BANK_EINTG(8, 0x1C0, "gpf2", 0x38),
526 EXYNOS_PIN_BANK_EINTG(6, 0x1E0, "gpf3", 0x3c),
Thomas Abraham43b169d2012-09-07 06:07:19 +0900527};
528
529/* pin banks of exynos4210 pin-controller 1 */
530static struct samsung_pin_bank exynos4210_pin_banks1[] = {
Tomasz Figa1b6056d2012-10-11 10:11:15 +0200531 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpj0", 0x00),
532 EXYNOS_PIN_BANK_EINTG(5, 0x020, "gpj1", 0x04),
533 EXYNOS_PIN_BANK_EINTG(7, 0x040, "gpk0", 0x08),
534 EXYNOS_PIN_BANK_EINTG(7, 0x060, "gpk1", 0x0c),
535 EXYNOS_PIN_BANK_EINTG(7, 0x080, "gpk2", 0x10),
536 EXYNOS_PIN_BANK_EINTG(7, 0x0A0, "gpk3", 0x14),
537 EXYNOS_PIN_BANK_EINTG(8, 0x0C0, "gpl0", 0x18),
538 EXYNOS_PIN_BANK_EINTG(3, 0x0E0, "gpl1", 0x1c),
539 EXYNOS_PIN_BANK_EINTG(8, 0x100, "gpl2", 0x20),
Tomasz Figa40ba6222012-10-11 10:11:09 +0200540 EXYNOS_PIN_BANK_EINTN(6, 0x120, "gpy0"),
541 EXYNOS_PIN_BANK_EINTN(4, 0x140, "gpy1"),
542 EXYNOS_PIN_BANK_EINTN(6, 0x160, "gpy2"),
543 EXYNOS_PIN_BANK_EINTN(8, 0x180, "gpy3"),
544 EXYNOS_PIN_BANK_EINTN(8, 0x1A0, "gpy4"),
545 EXYNOS_PIN_BANK_EINTN(8, 0x1C0, "gpy5"),
546 EXYNOS_PIN_BANK_EINTN(8, 0x1E0, "gpy6"),
Tomasz Figaa04b07c2012-10-11 10:11:18 +0200547 EXYNOS_PIN_BANK_EINTW(8, 0xC00, "gpx0", 0x00),
548 EXYNOS_PIN_BANK_EINTW(8, 0xC20, "gpx1", 0x04),
549 EXYNOS_PIN_BANK_EINTW(8, 0xC40, "gpx2", 0x08),
550 EXYNOS_PIN_BANK_EINTW(8, 0xC60, "gpx3", 0x0c),
Thomas Abraham43b169d2012-09-07 06:07:19 +0900551};
552
553/* pin banks of exynos4210 pin-controller 2 */
554static struct samsung_pin_bank exynos4210_pin_banks2[] = {
Tomasz Figa40ba6222012-10-11 10:11:09 +0200555 EXYNOS_PIN_BANK_EINTN(7, 0x000, "gpz"),
Thomas Abraham43b169d2012-09-07 06:07:19 +0900556};
557
558/*
559 * Samsung pinctrl driver data for Exynos4210 SoC. Exynos4210 SoC includes
560 * three gpio/pin-mux/pinconfig controllers.
561 */
562struct samsung_pin_ctrl exynos4210_pin_ctrl[] = {
563 {
564 /* pin-controller instance 0 data */
565 .pin_banks = exynos4210_pin_banks0,
566 .nr_banks = ARRAY_SIZE(exynos4210_pin_banks0),
Thomas Abraham43b169d2012-09-07 06:07:19 +0900567 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
568 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
569 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
570 .svc = EXYNOS_SVC_OFFSET,
571 .eint_gpio_init = exynos_eint_gpio_init,
572 .label = "exynos4210-gpio-ctrl0",
573 }, {
574 /* pin-controller instance 1 data */
575 .pin_banks = exynos4210_pin_banks1,
576 .nr_banks = ARRAY_SIZE(exynos4210_pin_banks1),
Thomas Abraham43b169d2012-09-07 06:07:19 +0900577 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
578 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
579 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
580 .weint_con = EXYNOS_WKUP_ECON_OFFSET,
581 .weint_mask = EXYNOS_WKUP_EMASK_OFFSET,
582 .weint_pend = EXYNOS_WKUP_EPEND_OFFSET,
583 .svc = EXYNOS_SVC_OFFSET,
584 .eint_gpio_init = exynos_eint_gpio_init,
585 .eint_wkup_init = exynos_eint_wkup_init,
586 .label = "exynos4210-gpio-ctrl1",
587 }, {
588 /* pin-controller instance 2 data */
589 .pin_banks = exynos4210_pin_banks2,
590 .nr_banks = ARRAY_SIZE(exynos4210_pin_banks2),
Thomas Abraham43b169d2012-09-07 06:07:19 +0900591 .label = "exynos4210-gpio-ctrl2",
592 },
593};
Tomasz Figa6edc7942012-11-07 08:44:59 +0900594
595/* pin banks of exynos4x12 pin-controller 0 */
596static struct samsung_pin_bank exynos4x12_pin_banks0[] = {
597 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpa0", 0x00),
598 EXYNOS_PIN_BANK_EINTG(6, 0x020, "gpa1", 0x04),
599 EXYNOS_PIN_BANK_EINTG(8, 0x040, "gpb", 0x08),
600 EXYNOS_PIN_BANK_EINTG(5, 0x060, "gpc0", 0x0c),
601 EXYNOS_PIN_BANK_EINTG(5, 0x080, "gpc1", 0x10),
602 EXYNOS_PIN_BANK_EINTG(4, 0x0A0, "gpd0", 0x14),
603 EXYNOS_PIN_BANK_EINTG(4, 0x0C0, "gpd1", 0x18),
604 EXYNOS_PIN_BANK_EINTG(8, 0x180, "gpf0", 0x30),
605 EXYNOS_PIN_BANK_EINTG(8, 0x1A0, "gpf1", 0x34),
606 EXYNOS_PIN_BANK_EINTG(8, 0x1C0, "gpf2", 0x38),
607 EXYNOS_PIN_BANK_EINTG(6, 0x1E0, "gpf3", 0x3c),
608 EXYNOS_PIN_BANK_EINTG(8, 0x240, "gpj0", 0x40),
609 EXYNOS_PIN_BANK_EINTG(5, 0x260, "gpj1", 0x44),
610};
611
612/* pin banks of exynos4x12 pin-controller 1 */
613static struct samsung_pin_bank exynos4x12_pin_banks1[] = {
614 EXYNOS_PIN_BANK_EINTG(7, 0x040, "gpk0", 0x08),
615 EXYNOS_PIN_BANK_EINTG(7, 0x060, "gpk1", 0x0c),
616 EXYNOS_PIN_BANK_EINTG(7, 0x080, "gpk2", 0x10),
617 EXYNOS_PIN_BANK_EINTG(7, 0x0A0, "gpk3", 0x14),
618 EXYNOS_PIN_BANK_EINTG(7, 0x0C0, "gpl0", 0x18),
619 EXYNOS_PIN_BANK_EINTG(2, 0x0E0, "gpl1", 0x1c),
620 EXYNOS_PIN_BANK_EINTG(8, 0x100, "gpl2", 0x20),
621 EXYNOS_PIN_BANK_EINTG(8, 0x260, "gpm0", 0x24),
622 EXYNOS_PIN_BANK_EINTG(7, 0x280, "gpm1", 0x28),
623 EXYNOS_PIN_BANK_EINTG(5, 0x2A0, "gpm2", 0x2c),
624 EXYNOS_PIN_BANK_EINTG(8, 0x2C0, "gpm3", 0x30),
625 EXYNOS_PIN_BANK_EINTG(8, 0x2E0, "gpm4", 0x34),
626 EXYNOS_PIN_BANK_EINTN(6, 0x120, "gpy0"),
627 EXYNOS_PIN_BANK_EINTN(4, 0x140, "gpy1"),
628 EXYNOS_PIN_BANK_EINTN(6, 0x160, "gpy2"),
629 EXYNOS_PIN_BANK_EINTN(8, 0x180, "gpy3"),
630 EXYNOS_PIN_BANK_EINTN(8, 0x1A0, "gpy4"),
631 EXYNOS_PIN_BANK_EINTN(8, 0x1C0, "gpy5"),
632 EXYNOS_PIN_BANK_EINTN(8, 0x1E0, "gpy6"),
633 EXYNOS_PIN_BANK_EINTW(8, 0xC00, "gpx0", 0x00),
634 EXYNOS_PIN_BANK_EINTW(8, 0xC20, "gpx1", 0x04),
635 EXYNOS_PIN_BANK_EINTW(8, 0xC40, "gpx2", 0x08),
636 EXYNOS_PIN_BANK_EINTW(8, 0xC60, "gpx3", 0x0c),
637};
638
639/* pin banks of exynos4x12 pin-controller 2 */
640static struct samsung_pin_bank exynos4x12_pin_banks2[] = {
641 EXYNOS_PIN_BANK_EINTG(7, 0x000, "gpz", 0x00),
642};
643
644/* pin banks of exynos4x12 pin-controller 3 */
645static struct samsung_pin_bank exynos4x12_pin_banks3[] = {
646 EXYNOS_PIN_BANK_EINTG(8, 0x000, "gpv0", 0x00),
647 EXYNOS_PIN_BANK_EINTG(8, 0x020, "gpv1", 0x04),
648 EXYNOS_PIN_BANK_EINTG(8, 0x040, "gpv2", 0x08),
649 EXYNOS_PIN_BANK_EINTG(8, 0x060, "gpv3", 0x0c),
650 EXYNOS_PIN_BANK_EINTG(2, 0x080, "gpv4", 0x10),
651};
652
653/*
654 * Samsung pinctrl driver data for Exynos4x12 SoC. Exynos4x12 SoC includes
655 * four gpio/pin-mux/pinconfig controllers.
656 */
657struct samsung_pin_ctrl exynos4x12_pin_ctrl[] = {
658 {
659 /* pin-controller instance 0 data */
660 .pin_banks = exynos4x12_pin_banks0,
661 .nr_banks = ARRAY_SIZE(exynos4x12_pin_banks0),
662 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
663 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
664 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
665 .svc = EXYNOS_SVC_OFFSET,
666 .eint_gpio_init = exynos_eint_gpio_init,
667 .label = "exynos4x12-gpio-ctrl0",
668 }, {
669 /* pin-controller instance 1 data */
670 .pin_banks = exynos4x12_pin_banks1,
671 .nr_banks = ARRAY_SIZE(exynos4x12_pin_banks1),
672 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
673 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
674 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
675 .weint_con = EXYNOS_WKUP_ECON_OFFSET,
676 .weint_mask = EXYNOS_WKUP_EMASK_OFFSET,
677 .weint_pend = EXYNOS_WKUP_EPEND_OFFSET,
678 .svc = EXYNOS_SVC_OFFSET,
679 .eint_gpio_init = exynos_eint_gpio_init,
680 .eint_wkup_init = exynos_eint_wkup_init,
681 .label = "exynos4x12-gpio-ctrl1",
682 }, {
683 /* pin-controller instance 2 data */
684 .pin_banks = exynos4x12_pin_banks2,
685 .nr_banks = ARRAY_SIZE(exynos4x12_pin_banks2),
686 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
687 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
688 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
689 .svc = EXYNOS_SVC_OFFSET,
690 .eint_gpio_init = exynos_eint_gpio_init,
691 .label = "exynos4x12-gpio-ctrl2",
692 }, {
693 /* pin-controller instance 3 data */
694 .pin_banks = exynos4x12_pin_banks3,
695 .nr_banks = ARRAY_SIZE(exynos4x12_pin_banks3),
696 .geint_con = EXYNOS_GPIO_ECON_OFFSET,
697 .geint_mask = EXYNOS_GPIO_EMASK_OFFSET,
698 .geint_pend = EXYNOS_GPIO_EPEND_OFFSET,
699 .svc = EXYNOS_SVC_OFFSET,
700 .eint_gpio_init = exynos_eint_gpio_init,
701 .label = "exynos4x12-gpio-ctrl3",
702 },
703};