1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/stddef.h>
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/irq.h>
17#include <linux/interrupt.h>
18#include <linux/spinlock.h>
19
20#include <asm/byteorder.h>
21#include <asm/io.h>
22#include <asm/prom.h>
23#include <asm/irq.h>
24
25#include "ge_pic.h"
26
27#define DEBUG
28#undef DEBUG
29
30#ifdef DEBUG
31#define DBG(fmt...) do { printk(KERN_DEBUG "gef_pic: " fmt); } while (0)
32#else
33#define DBG(fmt...) do { } while (0)
34#endif
35
36#define GEF_PIC_NUM_IRQS 32
37
38
39#define GEF_PIC_INTR_STATUS 0x0000
40
41#define GEF_PIC_INTR_MASK(cpu) (0x0010 + (0x4 * cpu))
42#define GEF_PIC_CPU0_INTR_MASK GEF_PIC_INTR_MASK(0)
43#define GEF_PIC_CPU1_INTR_MASK GEF_PIC_INTR_MASK(1)
44
45#define GEF_PIC_MCP_MASK(cpu) (0x0018 + (0x4 * cpu))
46#define GEF_PIC_CPU0_MCP_MASK GEF_PIC_MCP_MASK(0)
47#define GEF_PIC_CPU1_MCP_MASK GEF_PIC_MCP_MASK(1)
48
49
50static DEFINE_RAW_SPINLOCK(gef_pic_lock);
51
52static void __iomem *gef_pic_irq_reg_base;
53static struct irq_domain *gef_pic_irq_host;
54static int gef_pic_cascade_irq;
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94static void gef_pic_cascade(struct irq_desc *desc)
95{
96 struct irq_chip *chip = irq_desc_get_chip(desc);
97 unsigned int cascade_irq;
98
99
100
101
102
103 cascade_irq = gef_pic_get_irq();
104
105 if (cascade_irq)
106 generic_handle_irq(cascade_irq);
107
108 chip->irq_eoi(&desc->irq_data);
109}
110
111static void gef_pic_mask(struct irq_data *d)
112{
113 unsigned long flags;
114 unsigned int hwirq = irqd_to_hwirq(d);
115 u32 mask;
116
117 raw_spin_lock_irqsave(&gef_pic_lock, flags);
118 mask = in_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0));
119 mask &= ~(1 << hwirq);
120 out_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0), mask);
121 raw_spin_unlock_irqrestore(&gef_pic_lock, flags);
122}
123
124static void gef_pic_mask_ack(struct irq_data *d)
125{
126
127
128
129 gef_pic_mask(d);
130}
131
132static void gef_pic_unmask(struct irq_data *d)
133{
134 unsigned long flags;
135 unsigned int hwirq = irqd_to_hwirq(d);
136 u32 mask;
137
138 raw_spin_lock_irqsave(&gef_pic_lock, flags);
139 mask = in_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0));
140 mask |= (1 << hwirq);
141 out_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0), mask);
142 raw_spin_unlock_irqrestore(&gef_pic_lock, flags);
143}
144
145static struct irq_chip gef_pic_chip = {
146 .name = "gefp",
147 .irq_mask = gef_pic_mask,
148 .irq_mask_ack = gef_pic_mask_ack,
149 .irq_unmask = gef_pic_unmask,
150};
151
152
153
154
155
156static int gef_pic_host_map(struct irq_domain *h, unsigned int virq,
157 irq_hw_number_t hwirq)
158{
159
160 irq_set_status_flags(virq, IRQ_LEVEL);
161 irq_set_chip_and_handler(virq, &gef_pic_chip, handle_level_irq);
162
163 return 0;
164}
165
166static int gef_pic_host_xlate(struct irq_domain *h, struct device_node *ct,
167 const u32 *intspec, unsigned int intsize,
168 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
169{
170
171 *out_hwirq = intspec[0];
172 if (intsize > 1)
173 *out_flags = intspec[1];
174 else
175 *out_flags = IRQ_TYPE_LEVEL_HIGH;
176
177 return 0;
178}
179
180static const struct irq_domain_ops gef_pic_host_ops = {
181 .map = gef_pic_host_map,
182 .xlate = gef_pic_host_xlate,
183};
184
185
186
187
188
189void __init gef_pic_init(struct device_node *np)
190{
191 unsigned long flags;
192
193
194 gef_pic_irq_reg_base = of_iomap(np, 0);
195
196 raw_spin_lock_irqsave(&gef_pic_lock, flags);
197
198
199 out_be32(gef_pic_irq_reg_base + GEF_PIC_CPU0_INTR_MASK, 0);
200 out_be32(gef_pic_irq_reg_base + GEF_PIC_CPU1_INTR_MASK, 0);
201
202 out_be32(gef_pic_irq_reg_base + GEF_PIC_CPU0_MCP_MASK, 0);
203 out_be32(gef_pic_irq_reg_base + GEF_PIC_CPU1_MCP_MASK, 0);
204
205 raw_spin_unlock_irqrestore(&gef_pic_lock, flags);
206
207
208 gef_pic_cascade_irq = irq_of_parse_and_map(np, 0);
209 if (!gef_pic_cascade_irq) {
210 printk(KERN_ERR "SBC610: failed to map cascade interrupt");
211 return;
212 }
213
214
215 gef_pic_irq_host = irq_domain_add_linear(np, GEF_PIC_NUM_IRQS,
216 &gef_pic_host_ops, NULL);
217 if (gef_pic_irq_host == NULL)
218 return;
219
220
221 irq_set_chained_handler(gef_pic_cascade_irq, gef_pic_cascade);
222}
223
224
225
226
227
228unsigned int gef_pic_get_irq(void)
229{
230 u32 cause, mask, active;
231 unsigned int virq = 0;
232 int hwirq;
233
234 cause = in_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_STATUS);
235
236 mask = in_be32(gef_pic_irq_reg_base + GEF_PIC_INTR_MASK(0));
237
238 active = cause & mask;
239
240 if (active) {
241 for (hwirq = GEF_PIC_NUM_IRQS - 1; hwirq > -1; hwirq--) {
242 if (active & (0x1 << hwirq))
243 break;
244 }
245 virq = irq_linear_revmap(gef_pic_irq_host,
246 (irq_hw_number_t)hwirq);
247 }
248
249 return virq;
250}
251
252