2 * Moschip MCS814x generic interrupt controller routines
4 * Copyright (C) 2012, Florian Fainelli <florian@openwrt.org>
6 * Licensed under the GPLv2
8 #include <linux/init.h>
12 #include <linux/of_address.h>
13 #include <linux/irqdomain.h>
15 #include <asm/exception.h>
16 #include <asm/mach/irq.h>
17 #include <mach/mcs814x.h>
19 static void __iomem *mcs814x_intc_base;
20 static struct irq_domain *domain;
22 static void __init mcs814x_alloc_gc(void __iomem *base, unsigned int irq_start,
25 struct irq_chip_generic *gc;
26 struct irq_chip_type *ct;
28 if (irq_alloc_domain_generic_chips(domain, num, 1, "mcs814x-intc", handle_level_irq,
29 IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST, 0))
30 panic("unable to allocate domain generic irq chip");
32 gc = irq_get_domain_generic_chip(domain, irq_start);
34 panic("unable to get generic irq chip");
38 ct->chip.irq_ack = irq_gc_unmask_enable_reg;
39 ct->chip.irq_mask = irq_gc_mask_clr_bit;
40 ct->chip.irq_unmask = irq_gc_mask_set_bit;
41 ct->regs.mask = MCS814X_IRQ_MASK;
42 ct->regs.enable = MCS814X_IRQ_ICR;
44 /* Clear all interrupts */
45 writel_relaxed(0xffffffff, base + MCS814X_IRQ_ICR);
48 asmlinkage void __exception_irq_entry mcs814x_handle_irq(struct pt_regs *regs)
53 /* read the status register */
54 status = __raw_readl(mcs814x_intc_base + MCS814X_IRQ_STS0);
58 irq = ffs(status) - 1;
60 /* clear the interrupt */
61 __raw_writel(status, mcs814x_intc_base + MCS814X_IRQ_STS0);
62 /* call the generic handler */
63 handle_domain_irq(domain, irq, regs);
68 static const struct of_device_id mcs814x_intc_ids[] = {
69 { .compatible = "moschip,mcs814x-intc" },
73 void __init mcs814x_of_irq_init(void)
75 struct device_node *np;
77 np = of_find_matching_node(NULL, mcs814x_intc_ids);
79 panic("unable to find compatible intc node in dtb\n");
81 mcs814x_intc_base = of_iomap(np, 0);
82 if (!mcs814x_intc_base)
83 panic("unable to map intc cpu registers\n");
85 domain = irq_domain_add_linear(np, 32, &irq_generic_chip_ops, NULL);
87 panic("unable to add irq domain\n");
88 irq_set_default_host(domain);
92 mcs814x_alloc_gc(mcs814x_intc_base, 0, 32);