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>
26 #include <asm/pgtable.h>
30 #include "interrupt.h"
32 /* register layout taken from Spider spec, table 7.4-4 */
34 TIR_DEN = 0x004, /* Detection Enable Register */
35 TIR_MSK = 0x084, /* Mask Level Register */
36 TIR_EDC = 0x0c0, /* Edge Detection Clear Register */
37 TIR_PNDA = 0x100, /* Pending Register A */
38 TIR_PNDB = 0x104, /* Pending Register B */
39 TIR_CS = 0x144, /* Current Status Register */
40 TIR_LCSA = 0x150, /* Level Current Status Register A */
41 TIR_LCSB = 0x154, /* Level Current Status Register B */
42 TIR_LCSC = 0x158, /* Level Current Status Register C */
43 TIR_LCSD = 0x15c, /* Level Current Status Register D */
44 TIR_CFGA = 0x200, /* Setting Register A0 */
45 TIR_CFGB = 0x204, /* Setting Register B0 */
46 /* 0x208 ... 0x3ff Setting Register An/Bn */
47 TIR_PPNDA = 0x400, /* Packet Pending Register A */
48 TIR_PPNDB = 0x404, /* Packet Pending Register B */
49 TIR_PIERA = 0x408, /* Packet Output Error Register A */
50 TIR_PIERB = 0x40c, /* Packet Output Error Register B */
51 TIR_PIEN = 0x444, /* Packet Output Enable Register */
52 TIR_PIPND = 0x454, /* Packet Output Pending Register */
53 TIRDID = 0x484, /* Spider Device ID Register */
54 REISTIM = 0x500, /* Reissue Command Timeout Time Setting */
55 REISTIMEN = 0x504, /* Reissue Command Timeout Setting */
56 REISWAITEN = 0x508, /* Reissue Wait Control*/
59 static void __iomem *spider_pics[4];
61 static void __iomem *spider_get_pic(int irq)
63 int node = irq / IIC_NODE_STRIDE;
64 irq %= IIC_NODE_STRIDE;
66 if (irq >= IIC_EXT_OFFSET &&
67 irq < IIC_EXT_OFFSET + IIC_NUM_EXT &&
69 return spider_pics[node];
73 static int spider_get_nr(unsigned int irq)
75 return (irq % IIC_NODE_STRIDE) - IIC_EXT_OFFSET;
78 static void __iomem *spider_get_irq_config(int irq)
81 pic = spider_get_pic(irq);
82 return pic + TIR_CFGA + 8 * spider_get_nr(irq);
85 static void spider_unmask_irq(unsigned int irq)
87 int nodeid = (irq / IIC_NODE_STRIDE) * 0x10;
88 void __iomem *cfg = spider_get_irq_config(irq);
89 irq = spider_get_nr(irq);
91 /* FIXME: Most of that is configuration and has nothing to do with enabling/disable,
92 * besides, it's also partially bogus.
94 out_be32(cfg, (in_be32(cfg) & ~0xf0)| 0x3107000eu | nodeid);
95 out_be32(cfg + 4, in_be32(cfg + 4) | 0x00020000u | irq);
98 static void spider_mask_irq(unsigned int irq)
100 void __iomem *cfg = spider_get_irq_config(irq);
101 irq = spider_get_nr(irq);
103 out_be32(cfg, in_be32(cfg) & ~0x30000000u);
106 static void spider_ack_irq(unsigned int irq)
108 /* Should reset edge detection logic but we don't configure any edge interrupt
113 static struct irq_chip spider_pic = {
114 .typename = " SPIDER ",
115 .unmask = spider_unmask_irq,
116 .mask = spider_mask_irq,
117 .ack = spider_ack_irq,
120 static int spider_get_irq(int node)
123 void __iomem *regs = spider_pics[node];
125 cs = in_be32(regs + TIR_CS) >> 24;
133 static void spider_irq_cascade(unsigned int irq, struct irq_desc *desc,
134 struct pt_regs *regs)
136 int node = (int)(long)desc->handler_data;
139 cascade_irq = spider_get_irq(node);
140 generic_handle_irq(cascade_irq, regs);
141 desc->chip->eoi(irq);
144 /* hardcoded part to be compatible with older firmware */
146 static void __init spider_init_one(int node, unsigned long addr)
150 spider_pics[node] = ioremap(addr, 0x800);
151 if (spider_pics[node] == NULL)
152 panic("spider_pic: can't map registers !");
154 printk(KERN_INFO "spider_pic: mapped for node %d, addr: 0x%lx mapped to %p\n",
155 node, addr, spider_pics[node]);
157 for (n = 0; n < IIC_NUM_EXT; n++) {
158 if (n == IIC_EXT_CASCADE)
160 irq = n + IIC_EXT_OFFSET + node * IIC_NODE_STRIDE;
161 set_irq_chip_and_handler(irq, &spider_pic, handle_level_irq);
162 get_irq_desc(irq)->status |= IRQ_LEVEL;
165 /* do not mask any interrupts because of level */
166 out_be32(spider_pics[node] + TIR_MSK, 0x0);
168 /* disable edge detection clear */
169 /* out_be32(spider_pics[node] + TIR_EDC, 0x0); */
171 /* enable interrupt packets to be output */
172 out_be32(spider_pics[node] + TIR_PIEN,
173 in_be32(spider_pics[node] + TIR_PIEN) | 0x1);
175 /* Hook up cascade */
176 irq = IIC_EXT_CASCADE + node * IIC_NODE_STRIDE;
177 set_irq_data(irq, (void *)(long)node);
178 set_irq_chained_handler(irq, spider_irq_cascade);
180 /* Enable the interrupt detection enable bit. Do this last! */
181 out_be32(spider_pics[node] + TIR_DEN,
182 in_be32(spider_pics[node] + TIR_DEN) | 0x1);
185 void __init spider_init_IRQ(void)
187 unsigned long *spider_reg;
188 struct device_node *dn;
192 /* XXX node numbers are totally bogus. We _hope_ we get the device nodes in the right
193 * order here but that's definitely not guaranteed, we need to get the node from the
194 * device tree instead. There is currently no proper property for it (but our whole
195 * device-tree is bogus anyway) so all we can do is pray or maybe test the address
196 * and deduce the node-id
198 for (dn = NULL; (dn = of_find_node_by_name(dn, "interrupt-controller"));) {
199 compatible = (char *)get_property(dn, "compatible", NULL);
204 if (strstr(compatible, "CBEA,platform-spider-pic"))
205 spider_reg = (unsigned long *)get_property(dn, "reg", NULL);
206 else if (strstr(compatible, "sti,platform-spider-pic") && (node < 2)) {
207 static long hard_coded_pics[] = { 0x24000008000, 0x34000008000 };
208 spider_reg = &hard_coded_pics[node];
212 if (spider_reg == NULL)
213 printk(KERN_ERR "spider_pic: No address for node %d\n", node);
215 spider_init_one(node, *spider_reg);