cf86734afb5d8d246bb1362635f998e257602b04
[openwrt.git] / target / linux / mcs814x / files-3.3 / arch / arm / mach-mcs814x / irq.c
1 /*
2  * Moschip MCS814x generic interrupt controller routines
3  *
4  * Copyright (C) 2012, Florian Fainelli <florian@openwrt.org>
5  *
6  * Licensed under the GPLv2
7  */
8 #include <linux/init.h>
9 #include <linux/irq.h>
10 #include <linux/io.h>
11 #include <linux/of.h>
12 #include <linux/of_address.h>
13 #include <linux/irqdomain.h>
14
15 #include <asm/exception.h>
16 #include <asm/mach/irq.h>
17
18 #define MCS814X_IRQ_ICR         0x00
19 #define MCS814X_IRQ_ISR         0x04
20 #define MCS814X_IRQ_MASK        0x20
21 #define MCS814X_IRQ_STS0        0x40
22
23 static void __iomem *mcs814x_intc_base;
24
25 static void __init mcs814x_alloc_gc(void __iomem *base, unsigned int irq_start,
26                                         unsigned int num)
27 {
28         struct irq_chip_generic *gc;
29         struct irq_chip_type *ct;
30
31         gc = irq_alloc_generic_chip("mcs814x-intc", 1,
32                         irq_start, base, handle_level_irq);
33         if (!gc)
34                 panic("unable to allocate generic irq chip");
35
36         ct = gc->chip_types;
37         ct->chip.irq_ack = irq_gc_unmask_enable_reg;
38         ct->chip.irq_mask = irq_gc_mask_clr_bit;
39         ct->chip.irq_unmask = irq_gc_mask_set_bit;
40         ct->regs.mask = MCS814X_IRQ_MASK;
41         ct->regs.enable = MCS814X_IRQ_ICR;
42
43         irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
44                 IRQ_NOREQUEST, 0);
45
46         /* Clear all interrupts */
47         __raw_writel(0xffffffff, base + MCS814X_IRQ_ICR);
48 }
49
50 asmlinkage void __exception_irq_entry mcs814x_handle_irq(struct pt_regs *regs)
51 {
52         u32 status, irq;
53
54         do {
55                 /* read the status register */
56                 status = __raw_readl(mcs814x_intc_base + MCS814X_IRQ_STS0);
57                 if (!status)
58                         break;
59
60                 irq = ffs(status) - 1;
61                 status |= (1 << irq);
62                 /* clear the interrupt */
63                 __raw_writel(status, mcs814x_intc_base + MCS814X_IRQ_ICR);
64                 /* call the generic handler */
65                 handle_IRQ(irq, regs);
66
67         } while (1);
68 }
69
70 static const struct of_device_id mcs814x_intc_ids[] = {
71         { .compatible = "moschip,mcs814x-intc" },
72         { /* sentinel */ },
73 };
74
75 void __init mcs814x_of_irq_init(void)
76 {
77         struct device_node *np;
78
79         np = of_find_matching_node(NULL, mcs814x_intc_ids);
80         if (!np)
81                 panic("unable to find compatible intc node in dtb\n");
82
83         mcs814x_intc_base = of_iomap(np, 0);
84         if (!mcs814x_intc_base)
85                 panic("unable to map intc cpu registers\n");
86
87         irq_domain_add_simple(np, 0);
88
89         of_node_put(np);
90
91         mcs814x_alloc_gc(mcs814x_intc_base, 0, 32);
92 }
93