1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/interrupt.h>
18#include <linux/init.h>
19#include <linux/of.h>
20#include <linux/ftrace.h>
21#include <linux/irq.h>
22#include <linux/export.h>
23#include <linux/irqdomain.h>
24#include <linux/irqflags.h>
25
26
27unsigned long arch_local_save_flags(void)
28{
29 return mfspr(SPR_SR) & (SPR_SR_IEE|SPR_SR_TEE);
30}
31EXPORT_SYMBOL(arch_local_save_flags);
32
33
34void arch_local_irq_restore(unsigned long flags)
35{
36 mtspr(SPR_SR, ((mfspr(SPR_SR) & ~(SPR_SR_IEE|SPR_SR_TEE)) | flags));
37}
38EXPORT_SYMBOL(arch_local_irq_restore);
39
40
41
42
43
44
45
46
47static void or1k_pic_mask(struct irq_data *data)
48{
49 mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(1UL << data->hwirq));
50}
51
52static void or1k_pic_unmask(struct irq_data *data)
53{
54 mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (1UL << data->hwirq));
55}
56
57static void or1k_pic_ack(struct irq_data *data)
58{
59
60
61
62
63
64
65
66
67
68
69
70
71#ifdef CONFIG_OR1K_1200
72
73
74
75
76
77
78 mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->hwirq));
79#else
80 WARN(1, "Interrupt handling possibly broken\n");
81 mtspr(SPR_PICSR, (1UL << data->hwirq));
82#endif
83}
84
85static void or1k_pic_mask_ack(struct irq_data *data)
86{
87
88
89#ifdef CONFIG_OR1K_1200
90 mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(1UL << data->hwirq));
91 mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->hwirq));
92#else
93 WARN(1, "Interrupt handling possibly broken\n");
94 mtspr(SPR_PICMR, (1UL << data->hwirq));
95 mtspr(SPR_PICSR, (1UL << data->hwirq));
96#endif
97}
98
99#if 0
100static int or1k_pic_set_type(struct irq_data *data, unsigned int flow_type)
101{
102
103
104
105
106
107 return irq_setup_alt_chip(data, flow_type);
108}
109#endif
110
111static struct irq_chip or1k_dev = {
112 .name = "or1k-PIC",
113 .irq_unmask = or1k_pic_unmask,
114 .irq_mask = or1k_pic_mask,
115 .irq_ack = or1k_pic_ack,
116 .irq_mask_ack = or1k_pic_mask_ack,
117};
118
119static struct irq_domain *root_domain;
120
121static inline int pic_get_irq(int first)
122{
123 int hwirq;
124
125 hwirq = ffs(mfspr(SPR_PICSR) >> first);
126 if (!hwirq)
127 return NO_IRQ;
128 else
129 hwirq = hwirq + first -1;
130
131 return irq_find_mapping(root_domain, hwirq);
132}
133
134
135static int or1k_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
136{
137 irq_set_chip_and_handler_name(irq, &or1k_dev,
138 handle_level_irq, "level");
139 irq_set_status_flags(irq, IRQ_LEVEL | IRQ_NOPROBE);
140
141 return 0;
142}
143
144static const struct irq_domain_ops or1k_irq_domain_ops = {
145 .xlate = irq_domain_xlate_onecell,
146 .map = or1k_map,
147};
148
149
150
151
152
153
154static void __init or1k_irq_init(void)
155{
156 struct device_node *intc = NULL;
157
158
159 intc = of_find_compatible_node(NULL, NULL, "opencores,or1k-pic");
160 BUG_ON(!intc);
161
162
163 mtspr(SPR_PICMR, (0UL));
164
165 root_domain = irq_domain_add_linear(intc, 32,
166 &or1k_irq_domain_ops, NULL);
167}
168
169void __init init_IRQ(void)
170{
171 or1k_irq_init();
172}
173
174void __irq_entry do_IRQ(struct pt_regs *regs)
175{
176 int irq = -1;
177 struct pt_regs *old_regs = set_irq_regs(regs);
178
179 irq_enter();
180
181 while ((irq = pic_get_irq(irq + 1)) != NO_IRQ)
182 generic_handle_irq(irq);
183
184 irq_exit();
185 set_irq_regs(old_regs);
186}
187