2 * External Interrupt Controller on Spider South Bridge
4 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
6 * Author: Arnd Bergmann <arndb@de.ibm.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/interrupt.h>
24 #include <linux/irq.h>
25 #include <linux/ioport.h>
27 #include <asm/pgtable.h>
31 #include "interrupt.h"
33 /* register layout taken from Spider spec, table 7.4-4 */
35 TIR_DEN = 0x004, /* Detection Enable Register */
36 TIR_MSK = 0x084, /* Mask Level Register */
37 TIR_EDC = 0x0c0, /* Edge Detection Clear Register */
38 TIR_PNDA = 0x100, /* Pending Register A */
39 TIR_PNDB = 0x104, /* Pending Register B */
40 TIR_CS = 0x144, /* Current Status Register */
41 TIR_LCSA = 0x150, /* Level Current Status Register A */
42 TIR_LCSB = 0x154, /* Level Current Status Register B */
43 TIR_LCSC = 0x158, /* Level Current Status Register C */
44 TIR_LCSD = 0x15c, /* Level Current Status Register D */
45 TIR_CFGA = 0x200, /* Setting Register A0 */
46 TIR_CFGB = 0x204, /* Setting Register B0 */
47 /* 0x208 ... 0x3ff Setting Register An/Bn */
48 TIR_PPNDA = 0x400, /* Packet Pending Register A */
49 TIR_PPNDB = 0x404, /* Packet Pending Register B */
50 TIR_PIERA = 0x408, /* Packet Output Error Register A */
51 TIR_PIERB = 0x40c, /* Packet Output Error Register B */
52 TIR_PIEN = 0x444, /* Packet Output Enable Register */
53 TIR_PIPND = 0x454, /* Packet Output Pending Register */
54 TIRDID = 0x484, /* Spider Device ID Register */
55 REISTIM = 0x500, /* Reissue Command Timeout Time Setting */
56 REISTIMEN = 0x504, /* Reissue Command Timeout Setting */
57 REISWAITEN = 0x508, /* Reissue Wait Control*/
60 #define SPIDER_CHIP_COUNT 4
61 #define SPIDER_SRC_COUNT 64
62 #define SPIDER_IRQ_INVALID 63
65 struct irq_host *host;
66 struct device_node *of_node;
70 static struct spider_pic spider_pics[SPIDER_CHIP_COUNT];
72 static struct spider_pic *spider_virq_to_pic(unsigned int virq)
74 return irq_map[virq].host->host_data;
77 static void __iomem *spider_get_irq_config(struct spider_pic *pic,
80 return pic->regs + TIR_CFGA + 8 * src;
83 static void spider_unmask_irq(unsigned int virq)
85 struct spider_pic *pic = spider_virq_to_pic(virq);
86 void __iomem *cfg = spider_get_irq_config(pic, irq_map[virq].hwirq);
88 /* We use no locking as we should be covered by the descriptor lock
89 * for access to invidual source configuration registers
91 out_be32(cfg, in_be32(cfg) | 0x30000000u);
94 static void spider_mask_irq(unsigned int virq)
96 struct spider_pic *pic = spider_virq_to_pic(virq);
97 void __iomem *cfg = spider_get_irq_config(pic, irq_map[virq].hwirq);
99 /* We use no locking as we should be covered by the descriptor lock
100 * for access to invidual source configuration registers
102 out_be32(cfg, in_be32(cfg) & ~0x30000000u);
105 static void spider_ack_irq(unsigned int virq)
107 struct spider_pic *pic = spider_virq_to_pic(virq);
108 unsigned int src = irq_map[virq].hwirq;
110 /* Reset edge detection logic if necessary
112 if (get_irq_desc(virq)->status & IRQ_LEVEL)
115 /* Only interrupts 47 to 50 can be set to edge */
116 if (src < 47 || src > 50)
119 /* Perform the clear of the edge logic */
120 out_be32(pic->regs + TIR_EDC, 0x100 | (src & 0xf));
123 static struct irq_chip spider_pic = {
124 .typename = " SPIDER ",
125 .unmask = spider_unmask_irq,
126 .mask = spider_mask_irq,
127 .ack = spider_ack_irq,
130 static int spider_host_match(struct irq_host *h, struct device_node *node)
132 struct spider_pic *pic = h->host_data;
133 return node == pic->of_node;
136 static int spider_host_map(struct irq_host *h, unsigned int virq,
137 irq_hw_number_t hw, unsigned int flags)
139 unsigned int sense = flags & IRQ_TYPE_SENSE_MASK;
140 struct spider_pic *pic = h->host_data;
141 void __iomem *cfg = spider_get_irq_config(pic, hw);
145 /* Note that only level high is supported for most interrupts */
146 if (sense != IRQ_TYPE_NONE && sense != IRQ_TYPE_LEVEL_HIGH &&
147 (hw < 47 || hw > 50))
150 /* Decode sense type */
152 case IRQ_TYPE_EDGE_RISING:
155 case IRQ_TYPE_EDGE_FALLING:
158 case IRQ_TYPE_LEVEL_LOW:
162 case IRQ_TYPE_LEVEL_HIGH:
171 /* Configure the source. One gross hack that was there before and
172 * that I've kept around is the priority to the BE which I set to
173 * be the same as the interrupt source number. I don't know wether
174 * that's supposed to make any kind of sense however, we'll have to
175 * decide that, but for now, I'm not changing the behaviour.
177 out_be32(cfg, (ic << 24) | (0x7 << 16) | (pic->node_id << 4) | 0xe);
178 out_be32(cfg + 4, (0x2 << 16) | (hw & 0xff));
181 get_irq_desc(virq)->status |= IRQ_LEVEL;
182 set_irq_chip_and_handler(virq, &spider_pic, handle_level_irq);
186 static int spider_host_xlate(struct irq_host *h, struct device_node *ct,
187 u32 *intspec, unsigned int intsize,
188 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
191 /* Spider interrupts have 2 cells, first is the interrupt source,
192 * second, well, I don't know for sure yet ... We mask the top bits
193 * because old device-trees encode a node number in there
195 *out_hwirq = intspec[0] & 0x3f;
196 *out_flags = IRQ_TYPE_LEVEL_HIGH;
200 static struct irq_host_ops spider_host_ops = {
201 .match = spider_host_match,
202 .map = spider_host_map,
203 .xlate = spider_host_xlate,
206 static void spider_irq_cascade(unsigned int irq, struct irq_desc *desc,
207 struct pt_regs *regs)
209 struct spider_pic *pic = desc->handler_data;
210 unsigned int cs, virq;
212 cs = in_be32(pic->regs + TIR_CS) >> 24;
213 if (cs == SPIDER_IRQ_INVALID)
216 virq = irq_linear_revmap(pic->host, cs);
218 generic_handle_irq(virq, regs);
219 desc->chip->eoi(irq);
222 /* For hooking up the cascace we have a problem. Our device-tree is
223 * crap and we don't know on which BE iic interrupt we are hooked on at
224 * least not the "standard" way. We can reconstitute it based on two
225 * informations though: which BE node we are connected to and wether
226 * we are connected to IOIF0 or IOIF1. Right now, we really only care
227 * about the IBM cell blade and we know that its firmware gives us an
228 * interrupt-map property which is pretty strange.
230 static unsigned int __init spider_find_cascade_and_node(struct spider_pic *pic)
234 int imaplen, intsize, unit;
235 struct device_node *iic;
236 struct irq_host *iic_host;
238 #if 0 /* Enable that when we have a way to retreive the node as well */
239 /* First, we check wether we have a real "interrupts" in the device
240 * tree in case the device-tree is ever fixed
243 if (of_irq_map_one(pic->of_node, 0, &oirq) == 0) {
244 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
250 /* Now do the horrible hacks */
251 tmp = (u32 *)get_property(pic->of_node, "#interrupt-cells", NULL);
255 imap = (u32 *)get_property(pic->of_node, "interrupt-map", &imaplen);
256 if (imap == NULL || imaplen < (intsize + 1))
258 iic = of_find_node_by_phandle(imap[intsize]);
262 tmp = (u32 *)get_property(iic, "#interrupt-cells", NULL);
266 /* Assume unit is last entry of interrupt specifier */
267 unit = imap[intsize - 1];
268 /* Ok, we have a unit, now let's try to get the node */
269 tmp = (u32 *)get_property(iic, "ibm,interrupt-server-ranges", NULL);
274 /* ugly as hell but works for now */
275 pic->node_id = (*tmp) >> 1;
278 /* Ok, now let's get cracking. You may ask me why I just didn't match
279 * the iic host from the iic OF node, but that way I'm still compatible
280 * with really really old old firmwares for which we don't have a node
282 iic_host = iic_get_irq_host(pic->node_id);
283 if (iic_host == NULL)
285 /* Manufacture an IIC interrupt number of class 2 */
286 virq = irq_create_mapping(iic_host, 0x20 | unit, 0);
288 printk(KERN_ERR "spider_pic: failed to map cascade !");
293 static void __init spider_init_one(struct device_node *of_node, int chip,
296 struct spider_pic *pic = &spider_pics[chip];
300 pic->regs = ioremap(addr, 0x1000);
301 if (pic->regs == NULL)
302 panic("spider_pic: can't map registers !");
304 /* Allocate a host */
305 pic->host = irq_alloc_host(IRQ_HOST_MAP_LINEAR, SPIDER_SRC_COUNT,
306 &spider_host_ops, SPIDER_IRQ_INVALID);
307 if (pic->host == NULL)
308 panic("spider_pic: can't allocate irq host !");
309 pic->host->host_data = pic;
311 /* Fill out other bits */
312 pic->of_node = of_node_get(of_node);
314 /* Go through all sources and disable them */
315 for (i = 0; i < SPIDER_SRC_COUNT; i++) {
316 void __iomem *cfg = pic->regs + TIR_CFGA + 8 * i;
317 out_be32(cfg, in_be32(cfg) & ~0x30000000u);
320 /* do not mask any interrupts because of level */
321 out_be32(pic->regs + TIR_MSK, 0x0);
323 /* enable interrupt packets to be output */
324 out_be32(pic->regs + TIR_PIEN, in_be32(pic->regs + TIR_PIEN) | 0x1);
326 /* Hook up the cascade interrupt to the iic and nodeid */
327 virq = spider_find_cascade_and_node(pic);
330 set_irq_data(virq, pic);
331 set_irq_chained_handler(virq, spider_irq_cascade);
333 printk(KERN_INFO "spider_pic: node %d, addr: 0x%lx %s\n",
334 pic->node_id, addr, of_node->full_name);
336 /* Enable the interrupt detection enable bit. Do this last! */
337 out_be32(pic->regs + TIR_DEN, in_be32(pic->regs + TIR_DEN) | 0x1);
340 void __init spider_init_IRQ(void)
343 struct device_node *dn;
346 /* XXX node numbers are totally bogus. We _hope_ we get the device
347 * nodes in the right order here but that's definitely not guaranteed,
348 * we need to get the node from the device tree instead.
349 * There is currently no proper property for it (but our whole
350 * device-tree is bogus anyway) so all we can do is pray or maybe test
351 * the address and deduce the node-id
354 (dn = of_find_node_by_name(dn, "interrupt-controller"));) {
355 if (device_is_compatible(dn, "CBEA,platform-spider-pic")) {
356 if (of_address_to_resource(dn, 0, &r)) {
357 printk(KERN_WARNING "spider-pic: Failed\n");
360 } else if (device_is_compatible(dn, "sti,platform-spider-pic")
362 static long hard_coded_pics[] =
363 { 0x24000008000, 0x34000008000 };
364 r.start = hard_coded_pics[chip];
367 spider_init_one(dn, chip++, r.start);