2 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2007-2009 PetaLogix
4 * Copyright (C) 2006 Atmark Techno, Inc.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
11 #include <linux/init.h>
12 #include <linux/irqdomain.h>
13 #include <linux/irq.h>
16 #include <linux/bug.h>
21 static unsigned int intc_baseaddr;
23 /* No one else should require these constants, so define them locally here. */
24 #define ISR 0x00 /* Interrupt Status Register */
25 #define IPR 0x04 /* Interrupt Pending Register */
26 #define IER 0x08 /* Interrupt Enable Register */
27 #define IAR 0x0c /* Interrupt Acknowledge Register */
28 #define SIE 0x10 /* Set Interrupt Enable bits */
29 #define CIE 0x14 /* Clear Interrupt Enable bits */
30 #define IVR 0x18 /* Interrupt Vector Register */
31 #define MER 0x1c /* Master Enable Register */
34 #define MER_HIE (1<<1)
36 static void intc_enable_or_unmask(struct irq_data *d)
38 unsigned long mask = 1 << d->hwirq;
40 pr_debug("enable_or_unmask: %ld\n", d->hwirq);
42 /* ack level irqs because they can't be acked during
43 * ack function since the handle_level_irq function
44 * acks the irq before calling the interrupt handler
46 if (irqd_is_level_type(d))
47 out_be32(intc_baseaddr + IAR, mask);
49 out_be32(intc_baseaddr + SIE, mask);
52 static void intc_disable_or_mask(struct irq_data *d)
54 pr_debug("disable: %ld\n", d->hwirq);
55 out_be32(intc_baseaddr + CIE, 1 << d->hwirq);
58 static void intc_ack(struct irq_data *d)
60 pr_debug("ack: %ld\n", d->hwirq);
61 out_be32(intc_baseaddr + IAR, 1 << d->hwirq);
64 static void intc_mask_ack(struct irq_data *d)
66 unsigned long mask = 1 << d->hwirq;
68 pr_debug("disable_and_ack: %ld\n", d->hwirq);
69 out_be32(intc_baseaddr + CIE, mask);
70 out_be32(intc_baseaddr + IAR, mask);
73 static struct irq_chip intc_dev = {
74 .name = "Xilinx INTC",
75 .irq_unmask = intc_enable_or_unmask,
76 .irq_mask = intc_disable_or_mask,
78 .irq_mask_ack = intc_mask_ack,
81 static struct irq_domain *root_domain;
83 unsigned int get_irq(void)
85 unsigned int hwirq, irq = -1;
87 hwirq = in_be32(intc_baseaddr + IVR);
89 irq = irq_find_mapping(root_domain, hwirq);
91 pr_debug("get_irq: hwirq=%d, irq=%d\n", hwirq, irq);
96 static int xintc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
98 u32 intr_mask = (u32)d->host_data;
100 if (intr_mask & (1 << hw)) {
101 irq_set_chip_and_handler_name(irq, &intc_dev,
102 handle_edge_irq, "edge");
103 irq_clear_status_flags(irq, IRQ_LEVEL);
105 irq_set_chip_and_handler_name(irq, &intc_dev,
106 handle_level_irq, "level");
107 irq_set_status_flags(irq, IRQ_LEVEL);
112 static const struct irq_domain_ops xintc_irq_domain_ops = {
113 .xlate = irq_domain_xlate_onetwocell,
117 void __init init_IRQ(void)
119 u32 nr_irq, intr_mask;
120 struct device_node *intc = NULL;
122 intc = of_find_compatible_node(NULL, NULL, "xlnx,xps-intc-1.00.a");
125 intc_baseaddr = be32_to_cpup(of_get_property(intc, "reg", NULL));
126 intc_baseaddr = (unsigned long) ioremap(intc_baseaddr, PAGE_SIZE);
127 nr_irq = be32_to_cpup(of_get_property(intc,
128 "xlnx,num-intr-inputs", NULL));
131 be32_to_cpup(of_get_property(intc, "xlnx,kind-of-intr", NULL));
132 if (intr_mask > (u32)((1ULL << nr_irq) - 1))
133 pr_info(" ERROR: Mismatch in kind-of-intr param\n");
135 pr_info("%s #0 at 0x%08x, num_irq=%d, edge=0x%x\n",
136 intc->name, intc_baseaddr, nr_irq, intr_mask);
139 * Disable all external interrupts until they are
140 * explicity requested.
142 out_be32(intc_baseaddr + IER, 0);
144 /* Acknowledge any pending interrupts just in case. */
145 out_be32(intc_baseaddr + IAR, 0xffffffff);
147 /* Turn on the Master Enable. */
148 out_be32(intc_baseaddr + MER, MER_HIE | MER_ME);
150 /* Yeah, okay, casting the intr_mask to a void* is butt-ugly, but I'm
151 * lazy and Michal can clean it up to something nicer when he tests
152 * and commits this patch. ~~gcl */
153 root_domain = irq_domain_add_linear(intc, nr_irq, &xintc_irq_domain_ops,
156 irq_set_default_host(root_domain);