blob: e4c0e4ed5d5abbec4f680739c7778a13ebad2257 [file] [log] [blame]
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -06001/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/init.h>
18#include <linux/bitmap.h>
19#include <linux/bitops.h>
20#include <linux/interrupt.h>
21#include <linux/io.h>
22#include <linux/irq.h>
23#include <linux/irqdomain.h>
24#include <linux/list.h>
25#include <linux/platform_device.h>
26#include <linux/of.h>
27#include <linux/of_address.h>
28#include <linux/slab.h>
29#include <linux/spinlock.h>
30#include <asm/hardware/gic.h>
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -060031#include <asm/arch_timer.h>
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -060032#include <mach/gpio.h>
33#include <mach/mpm.h>
34
35enum {
36 MSM_MPM_GIC_IRQ_DOMAIN,
37 MSM_MPM_GPIO_IRQ_DOMAIN,
38 MSM_MPM_NR_IRQ_DOMAINS,
39};
40
41enum {
42 MSM_MPM_SET_ENABLED,
43 MSM_MPM_SET_WAKEUP,
44 MSM_NR_IRQS_SET,
45};
46
47struct mpm_irqs_a2m {
48 struct irq_domain *domain;
49 struct device_node *parent;
50 irq_hw_number_t hwirq;
51 unsigned long pin;
52 struct hlist_node node;
53};
54
55struct mpm_irqs {
56 struct irq_domain *domain;
57 unsigned long *enabled_irqs;
58 unsigned long *wakeup_irqs;
59};
60
61static struct mpm_irqs unlisted_irqs[MSM_MPM_NR_IRQ_DOMAINS];
62
63static struct hlist_head irq_hash[MSM_MPM_NR_MPM_IRQS];
64static unsigned int msm_mpm_irqs_m2a[MSM_MPM_NR_MPM_IRQS];
65#define MSM_MPM_REG_WIDTH DIV_ROUND_UP(MSM_MPM_NR_MPM_IRQS, 32)
66
67#define MSM_MPM_IRQ_INDEX(irq) (irq / 32)
68#define MSM_MPM_IRQ_MASK(irq) BIT(irq % 32)
69
70#define MSM_MPM_DETECT_CTL_INDEX(irq) (irq / 16)
71#define MSM_MPM_DETECT_CTL_SHIFT(irq) ((irq % 16) * 2)
72
73#define hashfn(val) (val % MSM_MPM_NR_MPM_IRQS)
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -060074#define SCLK_HZ (32768)
75#define ARCH_TIMER_HZ (19200000)
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -060076static struct msm_mpm_device_data msm_mpm_dev_data;
77
78enum mpm_reg_offsets {
79 MSM_MPM_REG_WAKEUP,
80 MSM_MPM_REG_ENABLE,
81 MSM_MPM_REG_DETECT_CTL,
82 MSM_MPM_REG_DETECT_CTL1,
83 MSM_MPM_REG_POLARITY,
84 MSM_MPM_REG_STATUS,
85};
86
87static DEFINE_SPINLOCK(msm_mpm_lock);
88
89static uint32_t msm_mpm_enabled_irq[MSM_MPM_REG_WIDTH];
90static uint32_t msm_mpm_wake_irq[MSM_MPM_REG_WIDTH];
91static uint32_t msm_mpm_detect_ctl[MSM_MPM_REG_WIDTH * 2];
92static uint32_t msm_mpm_polarity[MSM_MPM_REG_WIDTH];
93
94enum {
95 MSM_MPM_DEBUG_NON_DETECTABLE_IRQ = BIT(0),
96 MSM_MPM_DEBUG_PENDING_IRQ = BIT(1),
97 MSM_MPM_DEBUG_WRITE = BIT(2),
98 MSM_MPM_DEBUG_NON_DETECTABLE_IRQ_IDLE = BIT(3),
99};
100
101static int msm_mpm_debug_mask = 1;
102module_param_named(
103 debug_mask, msm_mpm_debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP
104);
105
106enum mpm_state {
107 MSM_MPM_IRQ_MAPPING_DONE = BIT(0),
108 MSM_MPM_DEVICE_PROBED = BIT(1),
109};
110
111static enum mpm_state msm_mpm_initialized;
112
113static inline bool msm_mpm_is_initialized(void)
114{
115 return msm_mpm_initialized &
116 (MSM_MPM_IRQ_MAPPING_DONE | MSM_MPM_DEVICE_PROBED);
117
118}
119
120static inline uint32_t msm_mpm_read(
121 unsigned int reg, unsigned int subreg_index)
122{
123 unsigned int offset = reg * MSM_MPM_REG_WIDTH + subreg_index;
124 return __raw_readl(msm_mpm_dev_data.mpm_request_reg_base + offset * 4);
125}
126
127static inline void msm_mpm_write(
128 unsigned int reg, unsigned int subreg_index, uint32_t value)
129{
130 unsigned int offset = reg * MSM_MPM_REG_WIDTH + subreg_index;
131
132 __raw_writel(value, msm_mpm_dev_data.mpm_request_reg_base + offset * 4);
133 if (MSM_MPM_DEBUG_WRITE & msm_mpm_debug_mask)
134 pr_info("%s: reg %u.%u: 0x%08x\n",
135 __func__, reg, subreg_index, value);
136}
137
138static inline void msm_mpm_send_interrupt(void)
139{
140 __raw_writel(msm_mpm_dev_data.mpm_apps_ipc_val,
141 msm_mpm_dev_data.mpm_apps_ipc_reg);
142 /* Ensure the write is complete before returning. */
143 wmb();
144}
145
146static irqreturn_t msm_mpm_irq(int irq, void *dev_id)
147{
148 /*
149 * When the system resumes from deep sleep mode, the RPM hardware wakes
150 * up the Apps processor by triggering this interrupt. This interrupt
151 * has to be enabled and set as wake for the irq to get SPM out of
152 * sleep. Handle the interrupt here to make sure that it gets cleared.
153 */
154 return IRQ_HANDLED;
155}
156
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -0600157static void msm_mpm_set(cycle_t wakeup, bool wakeset)
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -0600158{
159 uint32_t *irqs;
160 unsigned int reg;
161 int i;
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -0600162 uint32_t *expiry_timer;
163
164 expiry_timer = (uint32_t *)&wakeup;
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -0600165
166 irqs = wakeset ? msm_mpm_wake_irq : msm_mpm_enabled_irq;
167 for (i = 0; i < MSM_MPM_REG_WIDTH; i++) {
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -0600168 reg = MSM_MPM_REG_WAKEUP;
169 msm_mpm_write(reg, i, expiry_timer[i]);
170
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -0600171 reg = MSM_MPM_REG_ENABLE;
172 msm_mpm_write(reg, i, irqs[i]);
173
174 reg = MSM_MPM_REG_DETECT_CTL;
175 msm_mpm_write(reg, i, msm_mpm_detect_ctl[i]);
176
177 reg = MSM_MPM_REG_DETECT_CTL1;
178 msm_mpm_write(reg, i, msm_mpm_detect_ctl[2+i]);
179
180 reg = MSM_MPM_REG_POLARITY;
181 msm_mpm_write(reg, i, msm_mpm_polarity[i]);
182 }
183
184 /*
185 * Ensure that the set operation is complete before sending the
186 * interrupt
187 */
188 wmb();
189 msm_mpm_send_interrupt();
190}
191
192static inline unsigned int msm_mpm_get_irq_m2a(unsigned int pin)
193{
194 return msm_mpm_irqs_m2a[pin];
195}
196
197static inline uint16_t msm_mpm_get_irq_a2m(struct irq_data *d)
198{
199 struct hlist_node *elem;
200 struct mpm_irqs_a2m *node = NULL;
201
202 hlist_for_each_entry(node, elem, &irq_hash[hashfn(d->hwirq)], node) {
203 if ((node->hwirq == d->hwirq)
204 && (d->domain == node->domain)) {
205 /* Update the linux irq mapping */
206 msm_mpm_irqs_m2a[node->pin] = d->irq;
207 break;
208 }
209 }
210 return node ? node->pin : 0;
211}
212
213static int msm_mpm_enable_irq_exclusive(
214 struct irq_data *d, bool enable, bool wakeset)
215{
216 uint16_t mpm_pin;
217
218 WARN_ON(!d);
219 if (!d)
220 return 0;
221
222 mpm_pin = msm_mpm_get_irq_a2m(d);
223
224 if (mpm_pin == 0xff)
225 return 0;
226
227 if (mpm_pin) {
228 uint32_t *mpm_irq_masks = wakeset ?
229 msm_mpm_wake_irq : msm_mpm_enabled_irq;
230 uint32_t index = MSM_MPM_IRQ_INDEX(mpm_pin);
231 uint32_t mask = MSM_MPM_IRQ_MASK(mpm_pin);
232
233 if (enable)
234 mpm_irq_masks[index] |= mask;
235 else
236 mpm_irq_masks[index] &= ~mask;
237 } else {
238 int i;
239 unsigned long *irq_apps;
240
241 for (i = 0; i < MSM_MPM_NR_IRQ_DOMAINS; i++) {
242 if (d->domain == unlisted_irqs[i].domain)
243 break;
244 }
245
246 if (i == MSM_MPM_NR_IRQ_DOMAINS)
247 return 0;
248 irq_apps = wakeset ? unlisted_irqs[i].wakeup_irqs :
249 unlisted_irqs[i].enabled_irqs;
250
251 if (enable)
252 __set_bit(d->hwirq, irq_apps);
253 else
254 __clear_bit(d->hwirq, irq_apps);
255
256 }
257
258 return 0;
259}
260
261static void msm_mpm_set_detect_ctl(int pin, unsigned int flow_type)
262{
263 uint32_t index;
264 uint32_t val = 0;
265 uint32_t shift;
266
267 index = MSM_MPM_DETECT_CTL_INDEX(pin);
268 shift = MSM_MPM_DETECT_CTL_SHIFT(pin);
269
270 if (flow_type & IRQ_TYPE_EDGE_RISING)
271 val |= 0x02;
272
273 if (flow_type & IRQ_TYPE_EDGE_FALLING)
274 val |= 0x01;
275
276 msm_mpm_detect_ctl[index] &= ~(0x3 << shift);
277 msm_mpm_detect_ctl[index] |= (val & 0x03) << shift;
278}
279
280static int msm_mpm_set_irq_type_exclusive(
281 struct irq_data *d, unsigned int flow_type)
282{
283 uint32_t mpm_irq;
284
285 mpm_irq = msm_mpm_get_irq_a2m(d);
286
287 if (mpm_irq == 0xff)
288 return 0;
289
290 if (mpm_irq) {
291 uint32_t index = MSM_MPM_IRQ_INDEX(mpm_irq);
292 uint32_t mask = MSM_MPM_IRQ_MASK(mpm_irq);
293
294 if (index >= MSM_MPM_REG_WIDTH)
295 return -EFAULT;
296
297 msm_mpm_set_detect_ctl(mpm_irq, flow_type);
298
299 if (flow_type & IRQ_TYPE_LEVEL_HIGH)
300 msm_mpm_polarity[index] |= mask;
301 else
302 msm_mpm_polarity[index] &= ~mask;
303 }
304 return 0;
305}
306
307static int __msm_mpm_enable_irq(struct irq_data *d, bool enable)
308{
309 unsigned long flags;
310 int rc;
311
312 if (!msm_mpm_is_initialized())
313 return -EINVAL;
314
315 spin_lock_irqsave(&msm_mpm_lock, flags);
316
317 rc = msm_mpm_enable_irq_exclusive(d, enable, false);
318 spin_unlock_irqrestore(&msm_mpm_lock, flags);
319
320 return rc;
321}
322
323static void msm_mpm_enable_irq(struct irq_data *d)
324{
325 __msm_mpm_enable_irq(d, true);
326}
327
328static void msm_mpm_disable_irq(struct irq_data *d)
329{
330 __msm_mpm_enable_irq(d, false);
331}
332
333static int msm_mpm_set_irq_wake(struct irq_data *d, unsigned int on)
334{
335 unsigned long flags;
336 int rc;
337
338 if (!msm_mpm_is_initialized())
339 return -EINVAL;
340
341 spin_lock_irqsave(&msm_mpm_lock, flags);
342 rc = msm_mpm_enable_irq_exclusive(d, (bool)on, true);
343 spin_unlock_irqrestore(&msm_mpm_lock, flags);
344
345 return rc;
346}
347
348static int msm_mpm_set_irq_type(struct irq_data *d, unsigned int flow_type)
349{
350 unsigned long flags;
351 int rc;
352
353 if (!msm_mpm_is_initialized())
354 return -EINVAL;
355
356 spin_lock_irqsave(&msm_mpm_lock, flags);
357 rc = msm_mpm_set_irq_type_exclusive(d, flow_type);
358 spin_unlock_irqrestore(&msm_mpm_lock, flags);
359
360 return rc;
361}
362
363/******************************************************************************
364 * Public functions
365 *****************************************************************************/
366int msm_mpm_enable_pin(unsigned int pin, unsigned int enable)
367{
368 uint32_t index = MSM_MPM_IRQ_INDEX(pin);
369 uint32_t mask = MSM_MPM_IRQ_MASK(pin);
370 unsigned long flags;
371
372 if (!msm_mpm_is_initialized())
373 return -EINVAL;
374
375 if (pin > MSM_MPM_NR_MPM_IRQS)
376 return -EINVAL;
377
378 spin_lock_irqsave(&msm_mpm_lock, flags);
379
380 if (enable)
381 msm_mpm_enabled_irq[index] |= mask;
382 else
383 msm_mpm_enabled_irq[index] &= ~mask;
384
385 spin_unlock_irqrestore(&msm_mpm_lock, flags);
386 return 0;
387}
388
389int msm_mpm_set_pin_wake(unsigned int pin, unsigned int on)
390{
391 uint32_t index = MSM_MPM_IRQ_INDEX(pin);
392 uint32_t mask = MSM_MPM_IRQ_MASK(pin);
393 unsigned long flags;
394
395 if (!msm_mpm_is_initialized())
396 return -EINVAL;
397
398 if (pin >= MSM_MPM_NR_MPM_IRQS)
399 return -EINVAL;
400
401 spin_lock_irqsave(&msm_mpm_lock, flags);
402
403 if (on)
404 msm_mpm_wake_irq[index] |= mask;
405 else
406 msm_mpm_wake_irq[index] &= ~mask;
407
408 spin_unlock_irqrestore(&msm_mpm_lock, flags);
409 return 0;
410}
411
412int msm_mpm_set_pin_type(unsigned int pin, unsigned int flow_type)
413{
414 uint32_t index = MSM_MPM_IRQ_INDEX(pin);
415 uint32_t mask = MSM_MPM_IRQ_MASK(pin);
416 unsigned long flags;
417
418 if (!msm_mpm_is_initialized())
419 return -EINVAL;
420
421 if (pin >= MSM_MPM_NR_MPM_IRQS)
422 return -EINVAL;
423
424 spin_lock_irqsave(&msm_mpm_lock, flags);
425
426 msm_mpm_set_detect_ctl(pin, flow_type);
427
428 if (flow_type & IRQ_TYPE_LEVEL_HIGH)
429 msm_mpm_polarity[index] |= mask;
430 else
431 msm_mpm_polarity[index] &= ~mask;
432
433 spin_unlock_irqrestore(&msm_mpm_lock, flags);
434 return 0;
435}
436
437bool msm_mpm_irqs_detectable(bool from_idle)
438{
439 /* TODO:
440 * Return true if unlisted irqs is empty
441 */
442
443 if (!msm_mpm_is_initialized())
444 return false;
445
446 return true;
447}
448
449bool msm_mpm_gpio_irqs_detectable(bool from_idle)
450{
451 /* TODO:
452 * Return true if unlisted irqs is empty
453 */
454 if (!msm_mpm_is_initialized())
455 return false;
456 return true;
457}
458
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -0600459void msm_mpm_enter_sleep(uint32_t sclk_count, bool from_idle)
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -0600460{
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -0600461 cycle_t wakeup = (u64)sclk_count * ARCH_TIMER_HZ;
462
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -0600463 if (!msm_mpm_is_initialized()) {
464 pr_err("%s(): MPM not initialized\n", __func__);
465 return;
466 }
467
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -0600468 if (sclk_count) {
469 do_div(wakeup, SCLK_HZ);
470 wakeup += arch_counter_get_cntpct();
471 } else {
472 wakeup = (~0ULL);
473 }
474
475 msm_mpm_set(wakeup, !from_idle);
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -0600476}
477
478void msm_mpm_exit_sleep(bool from_idle)
479{
480 unsigned long pending;
481 int i;
482 int k;
483
484 if (!msm_mpm_is_initialized()) {
485 pr_err("%s(): MPM not initialized\n", __func__);
486 return;
487 }
488
489 for (i = 0; i < MSM_MPM_REG_WIDTH; i++) {
490 pending = msm_mpm_read(MSM_MPM_REG_STATUS, i);
491
492 if (MSM_MPM_DEBUG_PENDING_IRQ & msm_mpm_debug_mask)
493 pr_info("%s: pending.%d: 0x%08lx", __func__,
494 i, pending);
495
496 k = find_first_bit(&pending, 32);
497 while (k < 32) {
498 unsigned int mpm_irq = 32 * i + k;
499 unsigned int apps_irq = msm_mpm_get_irq_m2a(mpm_irq);
500 struct irq_desc *desc = apps_irq ?
501 irq_to_desc(apps_irq) : NULL;
502
503 if (desc && !irqd_is_level_type(&desc->irq_data)) {
504 irq_set_pending(apps_irq);
505 if (from_idle) {
506 raw_spin_lock(&desc->lock);
507 check_irq_resend(desc, apps_irq);
508 raw_spin_unlock(&desc->lock);
509 }
510 }
511
512 k = find_next_bit(&pending, 32, k + 1);
513 }
514 }
515}
516
517static int __devinit msm_mpm_dev_probe(struct platform_device *pdev)
518{
519 struct resource *res = NULL;
520 int offset, ret;
521 struct msm_mpm_device_data *dev = &msm_mpm_dev_data;
522
523 if (msm_mpm_initialized & MSM_MPM_DEVICE_PROBED) {
524 pr_warn("MPM device probed multiple times\n");
525 return 0;
526 }
527
528 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vmpm");
529 if (!res) {
530 pr_err("%s(): Missing RPM memory resource\n", __func__);
531 goto fail;
532 }
533
534 dev->mpm_request_reg_base = devm_request_and_ioremap(&pdev->dev, res);
535
536 if (!dev->mpm_request_reg_base) {
537 pr_err("%s(): Unable to iomap\n", __func__);
538 goto fail;
539 }
540
541 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ipc");
542 if (!res) {
543 pr_err("%s(): Missing GCC memory resource\n", __func__);
544 goto failed_irq_get;
545 }
546
547 dev->mpm_apps_ipc_reg = devm_ioremap(&pdev->dev, res->start,
548 resource_size(res));
549
550 if (of_property_read_u32(pdev->dev.of_node,
551 "qcom,ipc-bit-offset", &offset)) {
552 pr_info("%s(): Cannot read ipc bit offset\n", __func__);
553 goto failed_free_irq;
554 }
555
556 dev->mpm_apps_ipc_val = (1 << offset);
557
558 if (!dev->mpm_apps_ipc_reg)
559 goto failed_irq_get;
560
561 dev->mpm_ipc_irq = platform_get_irq(pdev, 0);
562
563 if (dev->mpm_ipc_irq == -ENXIO) {
564 pr_info("%s(): Cannot find IRQ resource\n", __func__);
565 goto failed_irq_get;
566 }
567 ret = request_irq(dev->mpm_ipc_irq, msm_mpm_irq,
568 IRQF_TRIGGER_RISING, pdev->name, msm_mpm_irq);
569
570 if (ret) {
571 pr_info("%s(): request_irq failed errno: %d\n", __func__, ret);
572 goto failed_irq_get;
573 }
Mahesh Sivasubramanian62360c62012-07-26 15:27:16 -0600574 ret = irq_set_irq_wake(dev->mpm_ipc_irq, 1);
575
576 if (ret) {
577 pr_err("%s: failed to set wakeup irq %u: %d\n",
578 __func__, dev->mpm_ipc_irq, ret);
579 goto failed_irq_get;
580
581 }
Mahesh Sivasubramanianb9498582012-07-25 11:22:56 -0600582 msm_mpm_initialized |= MSM_MPM_DEVICE_PROBED;
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -0600583
584 return 0;
585
586failed_free_irq:
587 free_irq(dev->mpm_ipc_irq, msm_mpm_irq);
588failed_irq_get:
589 if (dev->mpm_apps_ipc_reg)
590 devm_iounmap(&pdev->dev, dev->mpm_apps_ipc_reg);
591 if (dev->mpm_request_reg_base)
592 devm_iounmap(&pdev->dev, dev->mpm_request_reg_base);
593fail:
594 return -EINVAL;
595}
596
597static inline int __init mpm_irq_domain_linear_size(struct irq_domain *d)
598{
599 return d->revmap_data.linear.size;
600}
601
602static inline int __init mpm_irq_domain_legacy_size(struct irq_domain *d)
603{
604 return d->revmap_data.legacy.size;
605}
606
607void __init of_mpm_init(struct device_node *node)
608{
609 const __be32 *list;
610
611 struct mpm_of {
612 char *pkey;
613 char *map;
614 struct irq_chip *chip;
615 int (*get_max_irqs)(struct irq_domain *d);
616 };
617 int i;
618
619 struct mpm_of mpm_of_map[MSM_MPM_NR_IRQ_DOMAINS] = {
620 {
621 "qcom,gic-parent",
622 "qcom,gic-map",
623 &gic_arch_extn,
624 mpm_irq_domain_linear_size,
625 },
626 {
627 "qcom,gpio-parent",
628 "qcom,gpio-map",
629 &msm_gpio_irq_extn,
630 mpm_irq_domain_legacy_size,
631 },
632 };
633
634 if (msm_mpm_initialized & MSM_MPM_IRQ_MAPPING_DONE) {
635 pr_warn("%s(): MPM driver mapping exists\n", __func__);
636 return;
637 }
638
639 for (i = 0; i < MSM_MPM_NR_MPM_IRQS; i++)
640 INIT_HLIST_HEAD(&irq_hash[i]);
641
642 for (i = 0; i < MSM_MPM_NR_IRQ_DOMAINS; i++) {
643 struct device_node *parent = NULL;
644 struct mpm_irqs_a2m *mpm_node = NULL;
645 struct irq_domain *domain = NULL;
646 int size;
647
648 parent = of_parse_phandle(node, mpm_of_map[i].pkey, 0);
649
650 if (!parent) {
651 pr_warn("%s(): %s Not found\n", __func__,
652 mpm_of_map[i].pkey);
653 continue;
654 }
655
656 domain = irq_find_host(parent);
657
658 if (!domain) {
659 pr_warn("%s(): Cannot find irq controller for %s\n",
660 __func__, mpm_of_map[i].pkey);
661 continue;
662 }
663
664 size = mpm_of_map[i].get_max_irqs(domain);
665
666 unlisted_irqs[i].enabled_irqs =
667 kzalloc(BITS_TO_LONGS(size) * sizeof(unsigned long),
668 GFP_KERNEL);
669
670 if (!unlisted_irqs[i].enabled_irqs)
671 goto failed_malloc;
672
673 unlisted_irqs[i].wakeup_irqs =
674 kzalloc(BITS_TO_LONGS(size) * sizeof(unsigned long),
675 GFP_KERNEL);
676
677 if (!unlisted_irqs[i].wakeup_irqs)
678 goto failed_malloc;
679
680 unlisted_irqs[i].domain = domain;
681
682 list = of_get_property(node, mpm_of_map[i].map, &size);
683
684 if (!list || !size) {
685 __WARN();
686 continue;
687 }
688
689 /*
690 * Size is in bytes. Convert to size of uint32_t
691 */
692 size /= sizeof(*list);
693
694 /*
695 * The data is represented by a tuple mapping hwirq to a MPM
696 * pin. The number of mappings in the device tree would be
697 * size/2
698 */
699 mpm_node = kzalloc(sizeof(struct mpm_irqs_a2m) * size / 2,
700 GFP_KERNEL);
701 if (!mpm_node)
702 goto failed_malloc;
703
704 while (size) {
705 unsigned long pin = be32_to_cpup(list++);
706 irq_hw_number_t hwirq = be32_to_cpup(list++);
707
708 mpm_node->pin = pin;
709 mpm_node->hwirq = hwirq;
710 mpm_node->parent = parent;
711 mpm_node->domain = domain;
712 INIT_HLIST_NODE(&mpm_node->node);
713
714 hlist_add_head(&mpm_node->node,
715 &irq_hash[hashfn(mpm_node->hwirq)]);
716 size -= 2;
717 mpm_node++;
718 }
719
720 if (mpm_of_map[i].chip) {
721 mpm_of_map[i].chip->irq_mask = msm_mpm_disable_irq;
722 mpm_of_map[i].chip->irq_unmask = msm_mpm_enable_irq;
723 mpm_of_map[i].chip->irq_disable = msm_mpm_disable_irq;
724 mpm_of_map[i].chip->irq_set_type = msm_mpm_set_irq_type;
725 mpm_of_map[i].chip->irq_set_wake = msm_mpm_set_irq_wake;
726 }
727
728 }
Mahesh Sivasubramanianb9498582012-07-25 11:22:56 -0600729 msm_mpm_initialized |= MSM_MPM_IRQ_MAPPING_DONE;
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -0600730
731 return;
Mahesh Sivasubramanianb9498582012-07-25 11:22:56 -0600732
Mahesh Sivasubramanian102e5962012-06-20 13:12:11 -0600733failed_malloc:
734 for (i = 0; i < MSM_MPM_NR_MPM_IRQS; i++) {
735 mpm_of_map[i].chip->irq_mask = NULL;
736 mpm_of_map[i].chip->irq_unmask = NULL;
737 mpm_of_map[i].chip->irq_disable = NULL;
738 mpm_of_map[i].chip->irq_set_type = NULL;
739 mpm_of_map[i].chip->irq_set_wake = NULL;
740
741 kfree(unlisted_irqs[i].enabled_irqs);
742 kfree(unlisted_irqs[i].wakeup_irqs);
743
744 }
745}
746
747static struct of_device_id msm_mpm_match_table[] = {
748 {.compatible = "qcom,mpm-v2"},
749 {},
750};
751
752static struct platform_driver msm_mpm_dev_driver = {
753 .probe = msm_mpm_dev_probe,
754 .driver = {
755 .name = "mpm-v2",
756 .owner = THIS_MODULE,
757 .of_match_table = msm_mpm_match_table,
758 },
759};
760
761int __init msm_mpm_device_init(void)
762{
763 return platform_driver_register(&msm_mpm_dev_driver);
764}
765arch_initcall(msm_mpm_device_init);