1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/interrupt.h>
24#include <linux/irq.h>
25#include <linux/ioport.h>
26
27#include <asm/pgtable.h>
28#include <asm/prom.h>
29#include <asm/io.h>
30
31#include "interrupt.h"
32
33
34enum {
35 TIR_DEN = 0x004,
36 TIR_MSK = 0x084,
37 TIR_EDC = 0x0c0,
38 TIR_PNDA = 0x100,
39 TIR_PNDB = 0x104,
40 TIR_CS = 0x144,
41 TIR_LCSA = 0x150,
42 TIR_LCSB = 0x154,
43 TIR_LCSC = 0x158,
44 TIR_LCSD = 0x15c,
45 TIR_CFGA = 0x200,
46 TIR_CFGB = 0x204,
47
48 TIR_PPNDA = 0x400,
49 TIR_PPNDB = 0x404,
50 TIR_PIERA = 0x408,
51 TIR_PIERB = 0x40c,
52 TIR_PIEN = 0x444,
53 TIR_PIPND = 0x454,
54 TIRDID = 0x484,
55 REISTIM = 0x500,
56 REISTIMEN = 0x504,
57 REISWAITEN = 0x508,
58};
59
60#define SPIDER_CHIP_COUNT 4
61#define SPIDER_SRC_COUNT 64
62#define SPIDER_IRQ_INVALID 63
63
64struct spider_pic {
65 struct irq_host *host;
66 void __iomem *regs;
67 unsigned int node_id;
68};
69static struct spider_pic spider_pics[SPIDER_CHIP_COUNT];
70
71static struct spider_pic *spider_irq_data_to_pic(struct irq_data *d)
72{
73 return irq_data_get_irq_chip_data(d);
74}
75
76static void __iomem *spider_get_irq_config(struct spider_pic *pic,
77 unsigned int src)
78{
79 return pic->regs + TIR_CFGA + 8 * src;
80}
81
82static void spider_unmask_irq(struct irq_data *d)
83{
84 struct spider_pic *pic = spider_irq_data_to_pic(d);
85 void __iomem *cfg = spider_get_irq_config(pic, irqd_to_hwirq(d));
86
87 out_be32(cfg, in_be32(cfg) | 0x30000000u);
88}
89
90static void spider_mask_irq(struct irq_data *d)
91{
92 struct spider_pic *pic = spider_irq_data_to_pic(d);
93 void __iomem *cfg = spider_get_irq_config(pic, irqd_to_hwirq(d));
94
95 out_be32(cfg, in_be32(cfg) & ~0x30000000u);
96}
97
98static void spider_ack_irq(struct irq_data *d)
99{
100 struct spider_pic *pic = spider_irq_data_to_pic(d);
101 unsigned int src = irqd_to_hwirq(d);
102
103
104
105 if (irqd_is_level_type(d))
106 return;
107
108
109 if (src < 47 || src > 50)
110 return;
111
112
113 out_be32(pic->regs + TIR_EDC, 0x100 | (src & 0xf));
114}
115
116static int spider_set_irq_type(struct irq_data *d, unsigned int type)
117{
118 unsigned int sense = type & IRQ_TYPE_SENSE_MASK;
119 struct spider_pic *pic = spider_irq_data_to_pic(d);
120 unsigned int hw = irqd_to_hwirq(d);
121 void __iomem *cfg = spider_get_irq_config(pic, hw);
122 u32 old_mask;
123 u32 ic;
124
125
126 if (sense != IRQ_TYPE_NONE && sense != IRQ_TYPE_LEVEL_HIGH &&
127 (hw < 47 || hw > 50))
128 return -EINVAL;
129
130
131 switch(sense) {
132 case IRQ_TYPE_EDGE_RISING:
133 ic = 0x3;
134 break;
135 case IRQ_TYPE_EDGE_FALLING:
136 ic = 0x2;
137 break;
138 case IRQ_TYPE_LEVEL_LOW:
139 ic = 0x0;
140 break;
141 case IRQ_TYPE_LEVEL_HIGH:
142 case IRQ_TYPE_NONE:
143 ic = 0x1;
144 break;
145 default:
146 return -EINVAL;
147 }
148
149
150
151
152
153
154
155 old_mask = in_be32(cfg) & 0x30000000u;
156 out_be32(cfg, old_mask | (ic << 24) | (0x7 << 16) |
157 (pic->node_id << 4) | 0xe);
158 out_be32(cfg + 4, (0x2 << 16) | (hw & 0xff));
159
160 return 0;
161}
162
163static struct irq_chip spider_pic = {
164 .name = "SPIDER",
165 .irq_unmask = spider_unmask_irq,
166 .irq_mask = spider_mask_irq,
167 .irq_ack = spider_ack_irq,
168 .irq_set_type = spider_set_irq_type,
169};
170
171static int spider_host_map(struct irq_host *h, unsigned int virq,
172 irq_hw_number_t hw)
173{
174 irq_set_chip_data(virq, h->host_data);
175 irq_set_chip_and_handler(virq, &spider_pic, handle_level_irq);
176
177
178 irq_set_irq_type(virq, IRQ_TYPE_NONE);
179
180 return 0;
181}
182
183static int spider_host_xlate(struct irq_host *h, struct device_node *ct,
184 const u32 *intspec, unsigned int intsize,
185 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
186
187{
188
189
190
191
192 *out_hwirq = intspec[0] & 0x3f;
193 *out_flags = IRQ_TYPE_LEVEL_HIGH;
194 return 0;
195}
196
197static struct irq_host_ops spider_host_ops = {
198 .map = spider_host_map,
199 .xlate = spider_host_xlate,
200};
201
202static void spider_irq_cascade(unsigned int irq, struct irq_desc *desc)
203{
204 struct irq_chip *chip = irq_desc_get_chip(desc);
205 struct spider_pic *pic = irq_desc_get_handler_data(desc);
206 unsigned int cs, virq;
207
208 cs = in_be32(pic->regs + TIR_CS) >> 24;
209 if (cs == SPIDER_IRQ_INVALID)
210 virq = NO_IRQ;
211 else
212 virq = irq_linear_revmap(pic->host, cs);
213
214 if (virq != NO_IRQ)
215 generic_handle_irq(virq);
216
217 chip->irq_eoi(&desc->irq_data);
218}
219
220
221
222
223
224
225
226
227
228static unsigned int __init spider_find_cascade_and_node(struct spider_pic *pic)
229{
230 unsigned int virq;
231 const u32 *imap, *tmp;
232 int imaplen, intsize, unit;
233 struct device_node *iic;
234
235
236
237
238 struct of_irq oirq;
239 if (of_irq_map_one(pic->host->of_node, 0, &oirq) == 0) {
240 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
241 oirq.size);
242 return virq;
243 }
244
245
246 tmp = of_get_property(pic->host->of_node, "#interrupt-cells", NULL);
247 if (tmp == NULL)
248 return NO_IRQ;
249 intsize = *tmp;
250 imap = of_get_property(pic->host->of_node, "interrupt-map", &imaplen);
251 if (imap == NULL || imaplen < (intsize + 1))
252 return NO_IRQ;
253 iic = of_find_node_by_phandle(imap[intsize]);
254 if (iic == NULL)
255 return NO_IRQ;
256 imap += intsize + 1;
257 tmp = of_get_property(iic, "#interrupt-cells", NULL);
258 if (tmp == NULL) {
259 of_node_put(iic);
260 return NO_IRQ;
261 }
262 intsize = *tmp;
263
264 unit = imap[intsize - 1];
265
266 tmp = of_get_property(iic, "ibm,interrupt-server-ranges", NULL);
267 if (tmp == NULL) {
268 of_node_put(iic);
269 return NO_IRQ;
270 }
271
272 pic->node_id = (*tmp) >> 1;
273 of_node_put(iic);
274
275
276
277
278
279
280 virq = irq_create_mapping(NULL,
281 (pic->node_id << IIC_IRQ_NODE_SHIFT) |
282 (2 << IIC_IRQ_CLASS_SHIFT) |
283 unit);
284 if (virq == NO_IRQ)
285 printk(KERN_ERR "spider_pic: failed to map cascade !");
286 return virq;
287}
288
289
290static void __init spider_init_one(struct device_node *of_node, int chip,
291 unsigned long addr)
292{
293 struct spider_pic *pic = &spider_pics[chip];
294 int i, virq;
295
296
297 pic->regs = ioremap(addr, 0x1000);
298 if (pic->regs == NULL)
299 panic("spider_pic: can't map registers !");
300
301
302 pic->host = irq_alloc_host(of_node, IRQ_HOST_MAP_LINEAR,
303 SPIDER_SRC_COUNT, &spider_host_ops,
304 SPIDER_IRQ_INVALID);
305 if (pic->host == NULL)
306 panic("spider_pic: can't allocate irq host !");
307 pic->host->host_data = pic;
308
309
310 for (i = 0; i < SPIDER_SRC_COUNT; i++) {
311 void __iomem *cfg = pic->regs + TIR_CFGA + 8 * i;
312 out_be32(cfg, in_be32(cfg) & ~0x30000000u);
313 }
314
315
316 out_be32(pic->regs + TIR_MSK, 0x0);
317
318
319 out_be32(pic->regs + TIR_PIEN, in_be32(pic->regs + TIR_PIEN) | 0x1);
320
321
322 virq = spider_find_cascade_and_node(pic);
323 if (virq == NO_IRQ)
324 return;
325 irq_set_handler_data(virq, pic);
326 irq_set_chained_handler(virq, spider_irq_cascade);
327
328 printk(KERN_INFO "spider_pic: node %d, addr: 0x%lx %s\n",
329 pic->node_id, addr, of_node->full_name);
330
331
332 out_be32(pic->regs + TIR_DEN, in_be32(pic->regs + TIR_DEN) | 0x1);
333}
334
335void __init spider_init_IRQ(void)
336{
337 struct resource r;
338 struct device_node *dn;
339 int chip = 0;
340
341
342
343
344
345
346
347
348 for (dn = NULL;
349 (dn = of_find_node_by_name(dn, "interrupt-controller"));) {
350 if (of_device_is_compatible(dn, "CBEA,platform-spider-pic")) {
351 if (of_address_to_resource(dn, 0, &r)) {
352 printk(KERN_WARNING "spider-pic: Failed\n");
353 continue;
354 }
355 } else if (of_device_is_compatible(dn, "sti,platform-spider-pic")
356 && (chip < 2)) {
357 static long hard_coded_pics[] =
358 { 0x24000008000ul, 0x34000008000ul};
359 r.start = hard_coded_pics[chip];
360 } else
361 continue;
362 spider_init_one(dn, chip++, r.start);
363 }
364}
365