2 * Copyright (C) 2007-2013 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2012-2013 Xilinx, Inc.
4 * Copyright (C) 2007-2009 PetaLogix
5 * Copyright (C) 2006 Atmark Techno, Inc.
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
12 #include <linux/irqdomain.h>
13 #include <linux/irq.h>
14 #include <linux/of_address.h>
16 #include <linux/bug.h>
18 #include "../../drivers/irqchip/irqchip.h"
20 static void __iomem
*intc_baseaddr
;
22 /* No one else should require these constants, so define them locally here. */
23 #define ISR 0x00 /* Interrupt Status Register */
24 #define IPR 0x04 /* Interrupt Pending Register */
25 #define IER 0x08 /* Interrupt Enable Register */
26 #define IAR 0x0c /* Interrupt Acknowledge Register */
27 #define SIE 0x10 /* Set Interrupt Enable bits */
28 #define CIE 0x14 /* Clear Interrupt Enable bits */
29 #define IVR 0x18 /* Interrupt Vector Register */
30 #define MER 0x1c /* Master Enable Register */
33 #define MER_HIE (1<<1)
35 static void intc_enable_or_unmask(struct irq_data
*d
)
37 unsigned long mask
= 1 << d
->hwirq
;
39 pr_debug("enable_or_unmask: %ld\n", d
->hwirq
);
41 /* ack level irqs because they can't be acked during
42 * ack function since the handle_level_irq function
43 * acks the irq before calling the interrupt handler
45 if (irqd_is_level_type(d
))
46 out_be32(intc_baseaddr
+ IAR
, mask
);
48 out_be32(intc_baseaddr
+ SIE
, mask
);
51 static void intc_disable_or_mask(struct irq_data
*d
)
53 pr_debug("disable: %ld\n", d
->hwirq
);
54 out_be32(intc_baseaddr
+ CIE
, 1 << d
->hwirq
);
57 static void intc_ack(struct irq_data
*d
)
59 pr_debug("ack: %ld\n", d
->hwirq
);
60 out_be32(intc_baseaddr
+ IAR
, 1 << d
->hwirq
);
63 static void intc_mask_ack(struct irq_data
*d
)
65 unsigned long mask
= 1 << d
->hwirq
;
67 pr_debug("disable_and_ack: %ld\n", d
->hwirq
);
68 out_be32(intc_baseaddr
+ CIE
, mask
);
69 out_be32(intc_baseaddr
+ IAR
, mask
);
72 static struct irq_chip intc_dev
= {
73 .name
= "Xilinx INTC",
74 .irq_unmask
= intc_enable_or_unmask
,
75 .irq_mask
= intc_disable_or_mask
,
77 .irq_mask_ack
= intc_mask_ack
,
80 static struct irq_domain
*root_domain
;
82 unsigned int get_irq(void)
84 unsigned int hwirq
, irq
= -1;
86 hwirq
= in_be32(intc_baseaddr
+ IVR
);
88 irq
= irq_find_mapping(root_domain
, hwirq
);
90 pr_debug("get_irq: hwirq=%d, irq=%d\n", hwirq
, irq
);
95 static int xintc_map(struct irq_domain
*d
, unsigned int irq
, irq_hw_number_t hw
)
97 u32 intr_mask
= (u32
)d
->host_data
;
99 if (intr_mask
& (1 << hw
)) {
100 irq_set_chip_and_handler_name(irq
, &intc_dev
,
101 handle_edge_irq
, "edge");
102 irq_clear_status_flags(irq
, IRQ_LEVEL
);
104 irq_set_chip_and_handler_name(irq
, &intc_dev
,
105 handle_level_irq
, "level");
106 irq_set_status_flags(irq
, IRQ_LEVEL
);
111 static const struct irq_domain_ops xintc_irq_domain_ops
= {
112 .xlate
= irq_domain_xlate_onetwocell
,
116 static int __init
xilinx_intc_of_init(struct device_node
*intc
,
117 struct device_node
*parent
)
119 u32 nr_irq
, intr_mask
;
122 intc_baseaddr
= of_iomap(intc
, 0);
123 BUG_ON(!intc_baseaddr
);
125 ret
= of_property_read_u32(intc
, "xlnx,num-intr-inputs", &nr_irq
);
127 pr_err("%s: unable to read xlnx,num-intr-inputs\n", __func__
);
131 ret
= of_property_read_u32(intc
, "xlnx,kind-of-intr", &intr_mask
);
133 pr_err("%s: unable to read xlnx,kind-of-intr\n", __func__
);
137 if (intr_mask
> (u32
)((1ULL << nr_irq
) - 1))
138 pr_info(" ERROR: Mismatch in kind-of-intr param\n");
140 pr_info("%s: num_irq=%d, edge=0x%x\n",
141 intc
->full_name
, nr_irq
, intr_mask
);
144 * Disable all external interrupts until they are
145 * explicity requested.
147 out_be32(intc_baseaddr
+ IER
, 0);
149 /* Acknowledge any pending interrupts just in case. */
150 out_be32(intc_baseaddr
+ IAR
, 0xffffffff);
152 /* Turn on the Master Enable. */
153 out_be32(intc_baseaddr
+ MER
, MER_HIE
| MER_ME
);
155 /* Yeah, okay, casting the intr_mask to a void* is butt-ugly, but I'm
156 * lazy and Michal can clean it up to something nicer when he tests
157 * and commits this patch. ~~gcl */
158 root_domain
= irq_domain_add_linear(intc
, nr_irq
, &xintc_irq_domain_ops
,
161 irq_set_default_host(root_domain
);
166 IRQCHIP_DECLARE(xilinx_intc
, "xlnx,xps-intc-1.00.a", xilinx_intc_of_init
);