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->irq));
50}
51
52static void or1k_pic_unmask(struct irq_data *data)
53{
54 mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (1UL << data->irq));
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->irq));
79#else
80 WARN(1, "Interrupt handling possibily broken\n");
81 mtspr(SPR_PICSR, (1UL << irq));
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_PICSR, mfspr(SPR_PICSR) & ~(1UL << data->irq));
91#else
92 WARN(1, "Interrupt handling possibily broken\n");
93 mtspr(SPR_PICSR, (1UL << irq));
94#endif
95}
96
97#if 0
98static int or1k_pic_set_type(struct irq_data *data, unsigned int flow_type)
99{
100
101
102
103
104
105 return irq_setup_alt_chip(data, flow_type);
106}
107#endif
108
109static struct irq_chip or1k_dev = {
110 .name = "or1k-PIC",
111 .irq_unmask = or1k_pic_unmask,
112 .irq_mask = or1k_pic_mask,
113 .irq_ack = or1k_pic_ack,
114 .irq_mask_ack = or1k_pic_mask_ack,
115};
116
117static struct irq_domain *root_domain;
118
119static inline int pic_get_irq(int first)
120{
121 int hwirq;
122
123 hwirq = ffs(mfspr(SPR_PICSR) >> first);
124 if (!hwirq)
125 return NO_IRQ;
126 else
127 hwirq = hwirq + first -1;
128
129 return irq_find_mapping(root_domain, hwirq);
130}
131
132
133static int or1k_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
134{
135 irq_set_chip_and_handler_name(irq, &or1k_dev,
136 handle_level_irq, "level");
137 irq_set_status_flags(irq, IRQ_LEVEL | IRQ_NOPROBE);
138
139 return 0;
140}
141
142static const struct irq_domain_ops or1k_irq_domain_ops = {
143 .xlate = irq_domain_xlate_onecell,
144 .map = or1k_map,
145};
146
147
148
149
150
151
152static void __init or1k_irq_init(void)
153{
154 struct device_node *intc = NULL;
155
156
157 intc = of_find_compatible_node(NULL, NULL, "opencores,or1k-pic");
158 BUG_ON(!intc);
159
160
161 mtspr(SPR_PICMR, (0UL));
162
163 root_domain = irq_domain_add_linear(intc, 32,
164 &or1k_irq_domain_ops, NULL);
165}
166
167void __init init_IRQ(void)
168{
169 or1k_irq_init();
170}
171
172void __irq_entry do_IRQ(struct pt_regs *regs)
173{
174 int irq = -1;
175 struct pt_regs *old_regs = set_irq_regs(regs);
176
177 irq_enter();
178
179 while ((irq = pic_get_irq(irq + 1)) != NO_IRQ)
180 generic_handle_irq(irq);
181
182 irq_exit();
183 set_irq_regs(old_regs);
184}
185