Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 1 | /* |
| 2 | * External Interrupt Controller on Spider South Bridge |
| 3 | * |
| 4 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 |
| 5 | * |
| 6 | * Author: Arnd Bergmann <arndb@de.ibm.com> |
| 7 | * |
| 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) |
| 11 | * any later version. |
| 12 | * |
| 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. |
| 17 | * |
| 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. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/irq.h> |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 25 | #include <linux/ioport.h> |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 26 | |
| 27 | #include <asm/pgtable.h> |
| 28 | #include <asm/prom.h> |
| 29 | #include <asm/io.h> |
| 30 | |
Arnd Bergmann | f3f66f5 | 2005-10-31 20:08:37 -0500 | [diff] [blame] | 31 | #include "interrupt.h" |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 32 | |
| 33 | /* register layout taken from Spider spec, table 7.4-4 */ |
| 34 | enum { |
| 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*/ |
| 58 | }; |
| 59 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 60 | #define SPIDER_CHIP_COUNT 4 |
| 61 | #define SPIDER_SRC_COUNT 64 |
| 62 | #define SPIDER_IRQ_INVALID 63 |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 63 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 64 | struct spider_pic { |
| 65 | struct irq_host *host; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 66 | void __iomem *regs; |
| 67 | unsigned int node_id; |
| 68 | }; |
| 69 | static struct spider_pic spider_pics[SPIDER_CHIP_COUNT]; |
| 70 | |
| 71 | static struct spider_pic *spider_virq_to_pic(unsigned int virq) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 72 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 73 | return irq_map[virq].host->host_data; |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 74 | } |
| 75 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 76 | static void __iomem *spider_get_irq_config(struct spider_pic *pic, |
| 77 | unsigned int src) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 78 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 79 | return pic->regs + TIR_CFGA + 8 * src; |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 80 | } |
| 81 | |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 82 | static void spider_unmask_irq(struct irq_data *d) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 83 | { |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 84 | struct spider_pic *pic = spider_virq_to_pic(d->irq); |
| 85 | void __iomem *cfg = spider_get_irq_config(pic, irq_map[d->irq].hwirq); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 86 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 87 | out_be32(cfg, in_be32(cfg) | 0x30000000u); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 88 | } |
| 89 | |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 90 | static void spider_mask_irq(struct irq_data *d) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 91 | { |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 92 | struct spider_pic *pic = spider_virq_to_pic(d->irq); |
| 93 | void __iomem *cfg = spider_get_irq_config(pic, irq_map[d->irq].hwirq); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 94 | |
| 95 | out_be32(cfg, in_be32(cfg) & ~0x30000000u); |
| 96 | } |
| 97 | |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 98 | static void spider_ack_irq(struct irq_data *d) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 99 | { |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 100 | struct spider_pic *pic = spider_virq_to_pic(d->irq); |
| 101 | unsigned int src = irq_map[d->irq].hwirq; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 102 | |
| 103 | /* Reset edge detection logic if necessary |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 104 | */ |
Thomas Gleixner | 00e70ba | 2011-03-25 16:04:41 +0100 | [diff] [blame] | 105 | if (irqd_is_level_type(d)) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 106 | return; |
| 107 | |
| 108 | /* Only interrupts 47 to 50 can be set to edge */ |
| 109 | if (src < 47 || src > 50) |
| 110 | return; |
| 111 | |
| 112 | /* Perform the clear of the edge logic */ |
| 113 | out_be32(pic->regs + TIR_EDC, 0x100 | (src & 0xf)); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 114 | } |
| 115 | |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 116 | static int spider_set_irq_type(struct irq_data *d, unsigned int type) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 117 | { |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 118 | unsigned int sense = type & IRQ_TYPE_SENSE_MASK; |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 119 | struct spider_pic *pic = spider_virq_to_pic(d->irq); |
| 120 | unsigned int hw = irq_map[d->irq].hwirq; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 121 | void __iomem *cfg = spider_get_irq_config(pic, hw); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 122 | u32 old_mask; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 123 | u32 ic; |
| 124 | |
| 125 | /* Note that only level high is supported for most interrupts */ |
| 126 | if (sense != IRQ_TYPE_NONE && sense != IRQ_TYPE_LEVEL_HIGH && |
| 127 | (hw < 47 || hw > 50)) |
| 128 | return -EINVAL; |
| 129 | |
| 130 | /* Decode sense type */ |
| 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; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 140 | break; |
| 141 | case IRQ_TYPE_LEVEL_HIGH: |
| 142 | case IRQ_TYPE_NONE: |
| 143 | ic = 0x1; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 144 | break; |
| 145 | default: |
| 146 | return -EINVAL; |
| 147 | } |
| 148 | |
| 149 | /* Configure the source. One gross hack that was there before and |
| 150 | * that I've kept around is the priority to the BE which I set to |
| 151 | * be the same as the interrupt source number. I don't know wether |
| 152 | * that's supposed to make any kind of sense however, we'll have to |
| 153 | * decide that, but for now, I'm not changing the behaviour. |
| 154 | */ |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 155 | old_mask = in_be32(cfg) & 0x30000000u; |
| 156 | out_be32(cfg, old_mask | (ic << 24) | (0x7 << 16) | |
| 157 | (pic->node_id << 4) | 0xe); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 158 | out_be32(cfg + 4, (0x2 << 16) | (hw & 0xff)); |
| 159 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static struct irq_chip spider_pic = { |
Anton Blanchard | fc380c0 | 2010-01-31 20:33:41 +0000 | [diff] [blame] | 164 | .name = "SPIDER", |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 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, |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 171 | static int spider_host_map(struct irq_host *h, unsigned int virq, |
| 172 | irq_hw_number_t hw) |
| 173 | { |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 174 | irq_set_chip_and_handler(virq, &spider_pic, handle_level_irq); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 175 | |
| 176 | /* Set default irq type */ |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 177 | irq_set_irq_type(virq, IRQ_TYPE_NONE); |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 178 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | static int spider_host_xlate(struct irq_host *h, struct device_node *ct, |
Roman Fietze | 40d50cf | 2009-12-08 02:39:50 +0000 | [diff] [blame] | 183 | const u32 *intspec, unsigned int intsize, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 184 | irq_hw_number_t *out_hwirq, unsigned int *out_flags) |
| 185 | |
| 186 | { |
| 187 | /* Spider interrupts have 2 cells, first is the interrupt source, |
| 188 | * second, well, I don't know for sure yet ... We mask the top bits |
| 189 | * because old device-trees encode a node number in there |
| 190 | */ |
| 191 | *out_hwirq = intspec[0] & 0x3f; |
| 192 | *out_flags = IRQ_TYPE_LEVEL_HIGH; |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static struct irq_host_ops spider_host_ops = { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 197 | .map = spider_host_map, |
| 198 | .xlate = spider_host_xlate, |
| 199 | }; |
| 200 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 201 | static void spider_irq_cascade(unsigned int irq, struct irq_desc *desc) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 202 | { |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 203 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 204 | struct spider_pic *pic = irq_desc_get_handler_data(desc); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 205 | unsigned int cs, virq; |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 206 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 207 | cs = in_be32(pic->regs + TIR_CS) >> 24; |
| 208 | if (cs == SPIDER_IRQ_INVALID) |
| 209 | virq = NO_IRQ; |
| 210 | else |
| 211 | virq = irq_linear_revmap(pic->host, cs); |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 212 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 213 | if (virq != NO_IRQ) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 214 | generic_handle_irq(virq); |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame] | 215 | |
| 216 | chip->irq_eoi(&desc->irq_data); |
Jens Osterkamp | d0e57c6 | 2006-03-23 00:00:06 +0100 | [diff] [blame] | 217 | } |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 218 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 219 | /* For hooking up the cascace we have a problem. Our device-tree is |
| 220 | * crap and we don't know on which BE iic interrupt we are hooked on at |
| 221 | * least not the "standard" way. We can reconstitute it based on two |
| 222 | * informations though: which BE node we are connected to and wether |
| 223 | * we are connected to IOIF0 or IOIF1. Right now, we really only care |
| 224 | * about the IBM cell blade and we know that its firmware gives us an |
| 225 | * interrupt-map property which is pretty strange. |
| 226 | */ |
| 227 | static unsigned int __init spider_find_cascade_and_node(struct spider_pic *pic) |
Jens Osterkamp | d0e57c6 | 2006-03-23 00:00:06 +0100 | [diff] [blame] | 228 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 229 | unsigned int virq; |
Jeremy Kerr | c61c27d | 2006-07-12 15:39:54 +1000 | [diff] [blame] | 230 | const u32 *imap, *tmp; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 231 | int imaplen, intsize, unit; |
| 232 | struct device_node *iic; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 233 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 234 | /* First, we check wether we have a real "interrupts" in the device |
| 235 | * tree in case the device-tree is ever fixed |
| 236 | */ |
| 237 | struct of_irq oirq; |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 238 | if (of_irq_map_one(pic->host->of_node, 0, &oirq) == 0) { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 239 | virq = irq_create_of_mapping(oirq.controller, oirq.specifier, |
| 240 | oirq.size); |
Arnd Bergmann | f7e2ce7 | 2006-10-04 17:26:23 +0200 | [diff] [blame] | 241 | return virq; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 242 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 243 | |
| 244 | /* Now do the horrible hacks */ |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 245 | tmp = of_get_property(pic->host->of_node, "#interrupt-cells", NULL); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 246 | if (tmp == NULL) |
| 247 | return NO_IRQ; |
| 248 | intsize = *tmp; |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 249 | imap = of_get_property(pic->host->of_node, "interrupt-map", &imaplen); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 250 | if (imap == NULL || imaplen < (intsize + 1)) |
| 251 | return NO_IRQ; |
| 252 | iic = of_find_node_by_phandle(imap[intsize]); |
| 253 | if (iic == NULL) |
| 254 | return NO_IRQ; |
| 255 | imap += intsize + 1; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 256 | tmp = of_get_property(iic, "#interrupt-cells", NULL); |
Julia Lawall | 182f30e | 2010-08-28 23:52:46 +0000 | [diff] [blame] | 257 | if (tmp == NULL) { |
| 258 | of_node_put(iic); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 259 | return NO_IRQ; |
Julia Lawall | 182f30e | 2010-08-28 23:52:46 +0000 | [diff] [blame] | 260 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 261 | intsize = *tmp; |
| 262 | /* Assume unit is last entry of interrupt specifier */ |
| 263 | unit = imap[intsize - 1]; |
| 264 | /* Ok, we have a unit, now let's try to get the node */ |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 265 | tmp = of_get_property(iic, "ibm,interrupt-server-ranges", NULL); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 266 | if (tmp == NULL) { |
| 267 | of_node_put(iic); |
| 268 | return NO_IRQ; |
| 269 | } |
| 270 | /* ugly as hell but works for now */ |
| 271 | pic->node_id = (*tmp) >> 1; |
| 272 | of_node_put(iic); |
| 273 | |
| 274 | /* Ok, now let's get cracking. You may ask me why I just didn't match |
| 275 | * the iic host from the iic OF node, but that way I'm still compatible |
| 276 | * with really really old old firmwares for which we don't have a node |
| 277 | */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 278 | /* Manufacture an IIC interrupt number of class 2 */ |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 279 | virq = irq_create_mapping(NULL, |
| 280 | (pic->node_id << IIC_IRQ_NODE_SHIFT) | |
| 281 | (2 << IIC_IRQ_CLASS_SHIFT) | |
| 282 | unit); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 283 | if (virq == NO_IRQ) |
| 284 | printk(KERN_ERR "spider_pic: failed to map cascade !"); |
| 285 | return virq; |
| 286 | } |
| 287 | |
| 288 | |
| 289 | static void __init spider_init_one(struct device_node *of_node, int chip, |
| 290 | unsigned long addr) |
| 291 | { |
| 292 | struct spider_pic *pic = &spider_pics[chip]; |
| 293 | int i, virq; |
| 294 | |
| 295 | /* Map registers */ |
| 296 | pic->regs = ioremap(addr, 0x1000); |
| 297 | if (pic->regs == NULL) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 298 | panic("spider_pic: can't map registers !"); |
| 299 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 300 | /* Allocate a host */ |
Michael Ellerman | 19fc65b | 2008-05-26 12:12:32 +1000 | [diff] [blame] | 301 | pic->host = irq_alloc_host(of_node, IRQ_HOST_MAP_LINEAR, |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 302 | SPIDER_SRC_COUNT, &spider_host_ops, |
| 303 | SPIDER_IRQ_INVALID); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 304 | if (pic->host == NULL) |
| 305 | panic("spider_pic: can't allocate irq host !"); |
| 306 | pic->host->host_data = pic; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 307 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 308 | /* Go through all sources and disable them */ |
| 309 | for (i = 0; i < SPIDER_SRC_COUNT; i++) { |
| 310 | void __iomem *cfg = pic->regs + TIR_CFGA + 8 * i; |
| 311 | out_be32(cfg, in_be32(cfg) & ~0x30000000u); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /* do not mask any interrupts because of level */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 315 | out_be32(pic->regs + TIR_MSK, 0x0); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 316 | |
| 317 | /* enable interrupt packets to be output */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 318 | out_be32(pic->regs + TIR_PIEN, in_be32(pic->regs + TIR_PIEN) | 0x1); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 319 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 320 | /* Hook up the cascade interrupt to the iic and nodeid */ |
| 321 | virq = spider_find_cascade_and_node(pic); |
| 322 | if (virq == NO_IRQ) |
| 323 | return; |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 324 | irq_set_handler_data(virq, pic); |
| 325 | irq_set_chained_handler(virq, spider_irq_cascade); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 326 | |
| 327 | printk(KERN_INFO "spider_pic: node %d, addr: 0x%lx %s\n", |
| 328 | pic->node_id, addr, of_node->full_name); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 329 | |
| 330 | /* Enable the interrupt detection enable bit. Do this last! */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 331 | out_be32(pic->regs + TIR_DEN, in_be32(pic->regs + TIR_DEN) | 0x1); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void __init spider_init_IRQ(void) |
| 335 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 336 | struct resource r; |
Jens Osterkamp | d0e57c6 | 2006-03-23 00:00:06 +0100 | [diff] [blame] | 337 | struct device_node *dn; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 338 | int chip = 0; |
Jens Osterkamp | d0e57c6 | 2006-03-23 00:00:06 +0100 | [diff] [blame] | 339 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 340 | /* XXX node numbers are totally bogus. We _hope_ we get the device |
| 341 | * nodes in the right order here but that's definitely not guaranteed, |
| 342 | * we need to get the node from the device tree instead. |
| 343 | * There is currently no proper property for it (but our whole |
| 344 | * device-tree is bogus anyway) so all we can do is pray or maybe test |
| 345 | * the address and deduce the node-id |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 346 | */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 347 | for (dn = NULL; |
| 348 | (dn = of_find_node_by_name(dn, "interrupt-controller"));) { |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 349 | if (of_device_is_compatible(dn, "CBEA,platform-spider-pic")) { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 350 | if (of_address_to_resource(dn, 0, &r)) { |
| 351 | printk(KERN_WARNING "spider-pic: Failed\n"); |
| 352 | continue; |
| 353 | } |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 354 | } else if (of_device_is_compatible(dn, "sti,platform-spider-pic") |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 355 | && (chip < 2)) { |
| 356 | static long hard_coded_pics[] = |
Arnd Bergmann | 43b4f40 | 2006-10-04 17:26:24 +0200 | [diff] [blame] | 357 | { 0x24000008000ul, 0x34000008000ul}; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 358 | r.start = hard_coded_pics[chip]; |
Jens Osterkamp | d0e57c6 | 2006-03-23 00:00:06 +0100 | [diff] [blame] | 359 | } else |
| 360 | continue; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 361 | spider_init_one(dn, chip++, r.start); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 362 | } |
| 363 | } |