blob: f97b3a9abd1e48137da4cc0a6eeb6a5d7a2a862d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/ppc/syslib/gt64260_pic.c
3 *
4 * Interrupt controller support for Galileo's GT64260.
5 *
6 * Author: Chris Zankel <source@mvista.com>
7 * Modified by: Mark A. Greer <mgreer@mvista.com>
8 *
9 * Based on sources from Rabeeh Khoury / Galileo Technology
10 *
11 * 2001 (c) MontaVista, Software, Inc. This file is licensed under
12 * the terms of the GNU General Public License version 2. This program
13 * is licensed "as is" without any warranty of any kind, whether express
14 * or implied.
15 */
16
17/*
18 * This file contains the specific functions to support the GT64260
19 * interrupt controller.
20 *
21 * The GT64260 has two main interrupt registers (high and low) that
22 * summarizes the interrupts generated by the units of the GT64260.
23 * Each bit is assigned to an interrupt number, where the low register
24 * are assigned from IRQ0 to IRQ31 and the high cause register
25 * from IRQ32 to IRQ63
26 * The GPP (General Purpose Port) interrupts are assigned from IRQ64 (GPP0)
27 * to IRQ95 (GPP31).
28 * get_irq() returns the lowest interrupt number that is currently asserted.
29 *
30 * Note:
31 * - This driver does not initialize the GPP when used as an interrupt
32 * input.
33 */
34
35#include <linux/stddef.h>
36#include <linux/init.h>
37#include <linux/interrupt.h>
38#include <linux/sched.h>
39#include <linux/signal.h>
40#include <linux/stddef.h>
41#include <linux/delay.h>
42#include <linux/irq.h>
43
44#include <asm/io.h>
45#include <asm/system.h>
46#include <asm/irq.h>
47#include <asm/mv64x60.h>
Paul Mackerrasfd582ec2005-10-11 22:08:12 +100048#include <asm/machdep.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define CPU_INTR_STR "gt64260 cpu interface error"
51#define PCI0_INTR_STR "gt64260 pci 0 error"
52#define PCI1_INTR_STR "gt64260 pci 1 error"
53
54/* ========================== forward declaration ========================== */
55
56static void gt64260_unmask_irq(unsigned int);
57static void gt64260_mask_irq(unsigned int);
58
59/* ========================== local declarations =========================== */
60
61struct hw_interrupt_type gt64260_pic = {
62 .typename = " gt64260_pic ",
63 .enable = gt64260_unmask_irq,
64 .disable = gt64260_mask_irq,
65 .ack = gt64260_mask_irq,
66 .end = gt64260_unmask_irq,
67};
68
69u32 gt64260_irq_base = 0; /* GT64260 handles the next 96 IRQs from here */
70
71static struct mv64x60_handle bh;
72
73/* gt64260_init_irq()
74 *
75 * This function initializes the interrupt controller. It assigns
76 * all interrupts from IRQ0 to IRQ95 to the gt64260 interrupt controller.
77 *
78 * Note:
79 * We register all GPP inputs as interrupt source, but disable them.
80 */
81void __init
82gt64260_init_irq(void)
83{
84 int i;
85
86 if (ppc_md.progress)
87 ppc_md.progress("gt64260_init_irq: enter", 0x0);
88
89 bh.v_base = mv64x60_get_bridge_vbase();
90
91 ppc_cached_irq_mask[0] = 0;
92 ppc_cached_irq_mask[1] = 0x0f000000; /* Enable GPP intrs */
93 ppc_cached_irq_mask[2] = 0;
94
95 /* disable all interrupts and clear current interrupts */
96 mv64x60_write(&bh, MV64x60_GPP_INTR_MASK, ppc_cached_irq_mask[2]);
97 mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, 0);
98 mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_LO, ppc_cached_irq_mask[0]);
99 mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_HI, ppc_cached_irq_mask[1]);
100
101 /* use the gt64260 for all (possible) interrupt sources */
102 for (i = gt64260_irq_base; i < (gt64260_irq_base + 96); i++)
103 irq_desc[i].handler = &gt64260_pic;
104
105 if (ppc_md.progress)
106 ppc_md.progress("gt64260_init_irq: exit", 0x0);
107}
108
109/*
110 * gt64260_get_irq()
111 *
112 * This function returns the lowest interrupt number of all interrupts that
113 * are currently asserted.
114 *
115 * Input Variable(s):
116 * struct pt_regs* not used
117 *
118 * Output Variable(s):
119 * None.
120 *
121 * Returns:
122 * int <interrupt number> or -2 (bogus interrupt)
123 */
124int
125gt64260_get_irq(struct pt_regs *regs)
126{
127 int irq;
128 int irq_gpp;
129
130 irq = mv64x60_read(&bh, GT64260_IC_MAIN_CAUSE_LO);
131 irq = __ilog2((irq & 0x3dfffffe) & ppc_cached_irq_mask[0]);
132
133 if (irq == -1) {
134 irq = mv64x60_read(&bh, GT64260_IC_MAIN_CAUSE_HI);
135 irq = __ilog2((irq & 0x0f000db7) & ppc_cached_irq_mask[1]);
136
137 if (irq == -1)
138 irq = -2; /* bogus interrupt, should never happen */
139 else {
140 if (irq >= 24) {
141 irq_gpp = mv64x60_read(&bh,
142 MV64x60_GPP_INTR_CAUSE);
143 irq_gpp = __ilog2(irq_gpp &
144 ppc_cached_irq_mask[2]);
145
146 if (irq_gpp == -1)
147 irq = -2;
148 else {
149 irq = irq_gpp + 64;
150 mv64x60_write(&bh,
151 MV64x60_GPP_INTR_CAUSE,
152 ~(1 << (irq - 64)));
153 }
154 } else
155 irq += 32;
156 }
157 }
158
159 (void)mv64x60_read(&bh, MV64x60_GPP_INTR_CAUSE);
160
161 if (irq < 0)
162 return (irq);
163 else
164 return (gt64260_irq_base + irq);
165}
166
167/* gt64260_unmask_irq()
168 *
169 * This function enables an interrupt.
170 *
171 * Input Variable(s):
172 * unsigned int interrupt number (IRQ0...IRQ95).
173 *
174 * Output Variable(s):
175 * None.
176 *
177 * Returns:
178 * void
179 */
180static void
181gt64260_unmask_irq(unsigned int irq)
182{
183 irq -= gt64260_irq_base;
184
185 if (irq > 31)
186 if (irq > 63) /* unmask GPP irq */
187 mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
188 ppc_cached_irq_mask[2] |= (1 << (irq - 64)));
189 else /* mask high interrupt register */
190 mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_HI,
191 ppc_cached_irq_mask[1] |= (1 << (irq - 32)));
192 else /* mask low interrupt register */
193 mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_LO,
194 ppc_cached_irq_mask[0] |= (1 << irq));
195
196 (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
197 return;
198}
199
200/* gt64260_mask_irq()
201 *
202 * This function disables the requested interrupt.
203 *
204 * Input Variable(s):
205 * unsigned int interrupt number (IRQ0...IRQ95).
206 *
207 * Output Variable(s):
208 * None.
209 *
210 * Returns:
211 * void
212 */
213static void
214gt64260_mask_irq(unsigned int irq)
215{
216 irq -= gt64260_irq_base;
217
218 if (irq > 31)
219 if (irq > 63) /* mask GPP irq */
220 mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
221 ppc_cached_irq_mask[2] &= ~(1 << (irq - 64)));
222 else /* mask high interrupt register */
223 mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_HI,
224 ppc_cached_irq_mask[1] &= ~(1 << (irq - 32)));
225 else /* mask low interrupt register */
226 mv64x60_write(&bh, GT64260_IC_CPU_INTR_MASK_LO,
227 ppc_cached_irq_mask[0] &= ~(1 << irq));
228
229 (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
230 return;
231}
232
233static irqreturn_t
234gt64260_cpu_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
235{
236 printk(KERN_ERR "gt64260_cpu_error_int_handler: %s 0x%08x\n",
237 "Error on CPU interface - Cause regiser",
238 mv64x60_read(&bh, MV64x60_CPU_ERR_CAUSE));
239 printk(KERN_ERR "\tCPU error register dump:\n");
240 printk(KERN_ERR "\tAddress low 0x%08x\n",
241 mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_LO));
242 printk(KERN_ERR "\tAddress high 0x%08x\n",
243 mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_HI));
244 printk(KERN_ERR "\tData low 0x%08x\n",
245 mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_LO));
246 printk(KERN_ERR "\tData high 0x%08x\n",
247 mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_HI));
248 printk(KERN_ERR "\tParity 0x%08x\n",
249 mv64x60_read(&bh, MV64x60_CPU_ERR_PARITY));
250 mv64x60_write(&bh, MV64x60_CPU_ERR_CAUSE, 0);
251 return IRQ_HANDLED;
252}
253
254static irqreturn_t
255gt64260_pci_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
256{
257 u32 val;
258 unsigned int pci_bus = (unsigned int)dev_id;
259
260 if (pci_bus == 0) { /* Error on PCI 0 */
261 val = mv64x60_read(&bh, MV64x60_PCI0_ERR_CAUSE);
262 printk(KERN_ERR "%s: Error in PCI %d Interface\n",
263 "gt64260_pci_error_int_handler", pci_bus);
264 printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
265 printk(KERN_ERR "\tCause register 0x%08x\n", val);
266 printk(KERN_ERR "\tAddress Low 0x%08x\n",
267 mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_LO));
268 printk(KERN_ERR "\tAddress High 0x%08x\n",
269 mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_HI));
270 printk(KERN_ERR "\tAttribute 0x%08x\n",
271 mv64x60_read(&bh, MV64x60_PCI0_ERR_DATA_LO));
272 printk(KERN_ERR "\tCommand 0x%08x\n",
273 mv64x60_read(&bh, MV64x60_PCI0_ERR_CMD));
274 mv64x60_write(&bh, MV64x60_PCI0_ERR_CAUSE, ~val);
275 }
276 if (pci_bus == 1) { /* Error on PCI 1 */
277 val = mv64x60_read(&bh, MV64x60_PCI1_ERR_CAUSE);
278 printk(KERN_ERR "%s: Error in PCI %d Interface\n",
279 "gt64260_pci_error_int_handler", pci_bus);
280 printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
281 printk(KERN_ERR "\tCause register 0x%08x\n", val);
282 printk(KERN_ERR "\tAddress Low 0x%08x\n",
283 mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_LO));
284 printk(KERN_ERR "\tAddress High 0x%08x\n",
285 mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_HI));
286 printk(KERN_ERR "\tAttribute 0x%08x\n",
287 mv64x60_read(&bh, MV64x60_PCI1_ERR_DATA_LO));
288 printk(KERN_ERR "\tCommand 0x%08x\n",
289 mv64x60_read(&bh, MV64x60_PCI1_ERR_CMD));
290 mv64x60_write(&bh, MV64x60_PCI1_ERR_CAUSE, ~val);
291 }
292 return IRQ_HANDLED;
293}
294
295static int __init
296gt64260_register_hdlrs(void)
297{
298 int rc;
299
300 /* Register CPU interface error interrupt handler */
301 if ((rc = request_irq(MV64x60_IRQ_CPU_ERR,
302 gt64260_cpu_error_int_handler, SA_INTERRUPT, CPU_INTR_STR, 0)))
303 printk(KERN_WARNING "Can't register cpu error handler: %d", rc);
304
305 mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0);
306 mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0x000000fe);
307
308 /* Register PCI 0 error interrupt handler */
309 if ((rc = request_irq(MV64360_IRQ_PCI0, gt64260_pci_error_int_handler,
310 SA_INTERRUPT, PCI0_INTR_STR, (void *)0)))
311 printk(KERN_WARNING "Can't register pci 0 error handler: %d",
312 rc);
313
314 mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, 0);
315 mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, 0x003c0c24);
316
317 /* Register PCI 1 error interrupt handler */
318 if ((rc = request_irq(MV64360_IRQ_PCI1, gt64260_pci_error_int_handler,
319 SA_INTERRUPT, PCI1_INTR_STR, (void *)1)))
320 printk(KERN_WARNING "Can't register pci 1 error handler: %d",
321 rc);
322
323 mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, 0);
324 mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, 0x003c0c24);
325
326 return 0;
327}
328
329arch_initcall(gt64260_register_hdlrs);