2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2002 (440 port)
6 * Scott McNutt, Artesyn Communication Producs, smcnutt@artsyncp.com
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <asm/processor.h>
32 #include <ppc_asm.tmpl>
36 /****************************************************************************/
39 * CPM interrupt vector functions.
42 interrupt_handler_t *handler;
47 static struct irq_action irq_vecs[32];
49 #if defined(CONFIG_440)
50 static struct irq_action irq_vecs1[32]; /* For UIC1 */
52 void uic1_interrupt( void * parms); /* UIC1 handler */
55 /****************************************************************************/
56 #if defined(CONFIG_440)
58 /* SPRN changed in 440 */
59 static __inline__ void set_evpr(unsigned long val)
61 asm volatile("mtspr 0x03f,%0" : : "r" (val));
64 #else /* !defined(CONFIG_440) */
66 static __inline__ void set_pit(unsigned long val)
68 asm volatile("mtpit %0" : : "r" (val));
72 static __inline__ void set_tcr(unsigned long val)
74 asm volatile("mttcr %0" : : "r" (val));
78 static __inline__ void set_evpr(unsigned long val)
80 asm volatile("mtevpr %0" : : "r" (val));
82 #endif /* defined(CONFIG_440 */
84 /****************************************************************************/
86 int interrupt_init_cpu (unsigned *decrementer_count)
88 DECLARE_GLOBAL_DATA_PTR;
93 /* decrementer is automatically reloaded */
94 *decrementer_count = 0;
97 * Mark all irqs as free
99 for (vec=0; vec<32; vec++) {
100 irq_vecs[vec].handler = NULL;
101 irq_vecs[vec].arg = NULL;
102 irq_vecs[vec].count = 0;
103 #if defined(CONFIG_440)
104 irq_vecs1[vec].handler = NULL;
105 irq_vecs1[vec].arg = NULL;
106 irq_vecs1[vec].count = 0;
114 #if defined(CONFIG_440)
116 val &= (~0x04400000); /* clear DIS & ARE */
118 mtspr( dec, 0 ); /* Prevent exception after TSR clear*/
119 mtspr( decar, 0 ); /* clear reload */
120 mtspr( tsr, 0x08000000 ); /* clear DEC status */
121 val = gd->bd->bi_intfreq/100; /* 10 msec */
122 mtspr( decar, val ); /* Set auto-reload value */
123 mtspr( dec, val ); /* Set inital val */
125 set_pit(gd->bd->bi_intfreq / 1000);
127 #endif /* CONFIG_4xx */
146 set_evpr(0x00000000);
148 #if defined(CONFIG_440)
149 /* Install the UIC1 handlers */
150 irq_install_handler(VECNUM_UIC1NC, uic1_interrupt, 0);
151 irq_install_handler(VECNUM_UIC1C, uic1_interrupt, 0);
157 /****************************************************************************/
160 * Handle external interrupts
162 void external_interrupt(struct pt_regs *regs)
169 * Read masked interrupt status register to determine interrupt source
171 uic_msr = mfdcr(uicmsr);
175 while (msr_shift != 0) {
176 if (msr_shift & 0x80000000) {
178 * Increment irq counter (for debug purpose only)
180 irq_vecs[vec].count++;
182 if (irq_vecs[vec].handler != NULL) {
184 (*irq_vecs[vec].handler)(irq_vecs[vec].arg);
186 mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> vec));
187 printf ("Masking bogus interrupt vector 0x%x\n", vec);
191 * After servicing the interrupt, we have to remove the status indicator.
193 mtdcr(uicsr, (0x80000000 >> vec));
197 * Shift msr to next position and increment vector
204 #if defined(CONFIG_440)
205 /* Handler for UIC1 interrupt */
206 void uic1_interrupt( void * parms)
213 * Read masked interrupt status register to determine interrupt source
215 uic1_msr = mfdcr(uic1msr);
216 msr_shift = uic1_msr;
219 while (msr_shift != 0) {
220 if (msr_shift & 0x80000000) {
222 * Increment irq counter (for debug purpose only)
224 irq_vecs1[vec].count++;
226 if (irq_vecs1[vec].handler != NULL) {
228 (*irq_vecs1[vec].handler)(irq_vecs1[vec].arg);
230 mtdcr(uic1er, mfdcr(uic1er) & ~(0x80000000 >> vec));
231 printf ("Masking bogus interrupt vector (uic1) 0x%x\n", vec);
235 * After servicing the interrupt, we have to remove the status indicator.
237 mtdcr(uic1sr, (0x80000000 >> vec));
241 * Shift msr to next position and increment vector
247 #endif /* defined(CONFIG_440) */
249 /****************************************************************************/
252 * Install and free a interrupt handler.
256 irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
258 struct irq_action *irqa = irq_vecs;
261 #if defined(CONFIG_440)
268 if (irqa[i].handler != NULL) {
269 printf ("Interrupt vector %d: handler 0x%x replacing 0x%x\n",
270 vec, (uint)handler, (uint)irqa[i].handler);
272 irqa[i].handler = handler;
275 #if defined(CONFIG_440)
277 mtdcr(uic1er, mfdcr(uic1er) | (0x80000000 >> i));
280 mtdcr(uicer, mfdcr(uicer) | (0x80000000 >> i));
282 printf ("Install interrupt for vector %d ==> %p\n", vec, handler);
287 irq_free_handler(int vec)
289 struct irq_action *irqa = irq_vecs;
292 #if defined(CONFIG_440)
300 printf ("Free interrupt for vector %d ==> %p\n",
301 vec, irq_vecs[vec].handler);
304 #if defined(CONFIG_440)
306 mtdcr(uic1er, mfdcr(uic1er) & ~(0x80000000 >> i));
309 mtdcr(uicer, mfdcr(uicer) & ~(0x80000000 >> i));
311 irqa[i].handler = NULL;
315 /****************************************************************************/
317 void timer_interrupt_cpu (struct pt_regs *regs)
319 /* nothing to do here */
323 /****************************************************************************/
325 #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
327 /*******************************************************************************
329 * irqinfo - print information about PCI devices
333 do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
337 printf ("\nInterrupt-Information:\n");
338 #if defined(CONFIG_440)
339 printf ("\nUIC 0\n");
341 printf ("Nr Routine Arg Count\n");
343 for (vec=0; vec<32; vec++) {
344 if (irq_vecs[vec].handler != NULL) {
345 printf ("%02d %08lx %08lx %d\n",
347 (ulong)irq_vecs[vec].handler,
348 (ulong)irq_vecs[vec].arg,
349 irq_vecs[vec].count);
353 #if defined(CONFIG_440)
354 printf ("\nUIC 1\n");
355 printf ("Nr Routine Arg Count\n");
357 for (vec=0; vec<32; vec++)
359 if (irq_vecs1[vec].handler != NULL)
360 printf ("%02d %08lx %08lx %d\n",
361 vec+31, (ulong)irq_vecs1[vec].handler,
362 (ulong)irq_vecs1[vec].arg, irq_vecs1[vec].count);
370 #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */