microblaze: Remove selfmodified feature
[linux.git] / arch / microblaze / kernel / intc.c
1 /*
2  * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3  * Copyright (C) 2007-2009 PetaLogix
4  * Copyright (C) 2006 Atmark Techno, Inc.
5  *
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
8  * for more details.
9  */
10
11 #include <linux/init.h>
12 #include <linux/irqdomain.h>
13 #include <linux/irq.h>
14 #include <asm/page.h>
15 #include <linux/io.h>
16 #include <linux/bug.h>
17
18 #include <asm/prom.h>
19 #include <asm/irq.h>
20
21 static unsigned int intc_baseaddr;
22
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 */
32
33 #define MER_ME (1<<0)
34 #define MER_HIE (1<<1)
35
36 static void intc_enable_or_unmask(struct irq_data *d)
37 {
38         unsigned long mask = 1 << d->hwirq;
39
40         pr_debug("enable_or_unmask: %ld\n", d->hwirq);
41
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
45          */
46         if (irqd_is_level_type(d))
47                 out_be32(intc_baseaddr + IAR, mask);
48
49         out_be32(intc_baseaddr + SIE, mask);
50 }
51
52 static void intc_disable_or_mask(struct irq_data *d)
53 {
54         pr_debug("disable: %ld\n", d->hwirq);
55         out_be32(intc_baseaddr + CIE, 1 << d->hwirq);
56 }
57
58 static void intc_ack(struct irq_data *d)
59 {
60         pr_debug("ack: %ld\n", d->hwirq);
61         out_be32(intc_baseaddr + IAR, 1 << d->hwirq);
62 }
63
64 static void intc_mask_ack(struct irq_data *d)
65 {
66         unsigned long mask = 1 << d->hwirq;
67
68         pr_debug("disable_and_ack: %ld\n", d->hwirq);
69         out_be32(intc_baseaddr + CIE, mask);
70         out_be32(intc_baseaddr + IAR, mask);
71 }
72
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,
77         .irq_ack = intc_ack,
78         .irq_mask_ack = intc_mask_ack,
79 };
80
81 static struct irq_domain *root_domain;
82
83 unsigned int get_irq(void)
84 {
85         unsigned int hwirq, irq = -1;
86
87         hwirq = in_be32(intc_baseaddr + IVR);
88         if (hwirq != -1U)
89                 irq = irq_find_mapping(root_domain, hwirq);
90
91         pr_debug("get_irq: hwirq=%d, irq=%d\n", hwirq, irq);
92
93         return irq;
94 }
95
96 static int xintc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
97 {
98         u32 intr_mask = (u32)d->host_data;
99
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);
104         } else {
105                 irq_set_chip_and_handler_name(irq, &intc_dev,
106                                                 handle_level_irq, "level");
107                 irq_set_status_flags(irq, IRQ_LEVEL);
108         }
109         return 0;
110 }
111
112 static const struct irq_domain_ops xintc_irq_domain_ops = {
113         .xlate = irq_domain_xlate_onetwocell,
114         .map = xintc_map,
115 };
116
117 void __init init_IRQ(void)
118 {
119         u32 nr_irq, intr_mask;
120         struct device_node *intc = NULL;
121
122         intc = of_find_compatible_node(NULL, NULL, "xlnx,xps-intc-1.00.a");
123         BUG_ON(!intc);
124
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));
129
130         intr_mask =
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");
134
135         pr_info("%s #0 at 0x%08x, num_irq=%d, edge=0x%x\n",
136                 intc->name, intc_baseaddr, nr_irq, intr_mask);
137
138         /*
139          * Disable all external interrupts until they are
140          * explicity requested.
141          */
142         out_be32(intc_baseaddr + IER, 0);
143
144         /* Acknowledge any pending interrupts just in case. */
145         out_be32(intc_baseaddr + IAR, 0xffffffff);
146
147         /* Turn on the Master Enable. */
148         out_be32(intc_baseaddr + MER, MER_HIE | MER_ME);
149
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,
154                                                         (void *)intr_mask);
155
156         irq_set_default_host(root_domain);
157 }