2 * (C) Copyright 2000-2002 Wolfgang Denk, DENX Software Engineering, wd@denx.de.
3 * (C) Copyright 2003 Martin Winistoerfer, martinwinistoerfer@gmx.ch.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
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
26 * Discription: Contains interrupt routines needed by U-Boot
33 #include <asm/processor.h>
35 #if defined(CONFIG_PATI)
36 /* PATI uses IRQs for PCI doorbell */
41 struct interrupt_action {
42 interrupt_handler_t *handler;
47 static struct interrupt_action irq_vecs[NR_IRQS];
50 * Initialise interrupts
53 int interrupt_init_cpu (ulong *decrementer_count)
55 volatile immap_t *immr = (immap_t *) CFG_IMMR;
58 /* Decrementer used here for status led */
59 *decrementer_count = get_tbclk () / CFG_HZ;
61 /* Disable all interrupts */
62 immr->im_siu_conf.sc_simask = 0;
63 for (vec=0; vec<NR_IRQS; vec++) {
64 irq_vecs[vec].handler = NULL;
65 irq_vecs[vec].arg = NULL;
66 irq_vecs[vec].count = 0;
73 * Handle external interrupts
75 void external_interrupt (struct pt_regs *regs)
77 volatile immap_t *immr = (immap_t *) CFG_IMMR;
79 ulong simask, newmask;
83 * read the SIVEC register and shift the bits down
84 * to get the irq number
86 vec = immr->im_siu_conf.sc_sivec;
88 v_bit = 0x80000000UL >> irq;
91 * Read Interrupt Mask Register and Mask Interrupts
93 simask = immr->im_siu_conf.sc_simask;
94 newmask = simask & (~(0xFFFF0000 >> irq));
95 immr->im_siu_conf.sc_simask = newmask;
97 if (!(irq & 0x1)) { /* External Interrupt ? */
101 * Read Interrupt Edge/Level Register
103 siel = immr->im_siu_conf.sc_siel;
105 if (siel & v_bit) { /* edge triggered interrupt ? */
107 * Rewrite SIPEND Register to clear interrupt
109 immr->im_siu_conf.sc_sipend = v_bit;
113 if (irq_vecs[irq].handler != NULL) {
114 irq_vecs[irq].handler (irq_vecs[irq].arg);
116 printf ("\nBogus External Interrupt IRQ %d Vector %ld\n",
118 /* turn off the bogus interrupt to avoid it from now */
122 * Re-Enable old Interrupt Mask
124 immr->im_siu_conf.sc_simask = simask;
128 * Install and free an interrupt handler
130 void irq_install_handler (int vec, interrupt_handler_t * handler,
133 volatile immap_t *immr = (immap_t *) CFG_IMMR;
135 if (irq_vecs[vec].handler != NULL) {
136 printf ("SIU interrupt %d 0x%x\n",
140 irq_vecs[vec].handler = handler;
141 irq_vecs[vec].arg = arg;
142 immr->im_siu_conf.sc_simask |= 1 << (31 - vec);
144 printf ("Install SIU interrupt for vector %d ==> %p\n",
149 void irq_free_handler (int vec)
151 volatile immap_t *immr = (immap_t *) CFG_IMMR;
154 printf ("Free CPM interrupt for vector %d\n",
157 immr->im_siu_conf.sc_simask &= ~(1 << (31 - vec));
158 irq_vecs[vec].handler = NULL;
159 irq_vecs[vec].arg = NULL;
163 * Timer interrupt - gets called when bit 0 of DEC changes from
164 * 0. Decrementer is enabled with bit TBE in TBSCR.
166 void timer_interrupt_cpu (struct pt_regs *regs)
168 volatile immap_t *immr = (immap_t *) CFG_IMMR;
171 printf ("*** Timer Interrupt *** ");
173 /* Reset Timer Status Bit and Timers Interrupt Status */
174 immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
176 immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS | PLPRCR_TMIST;
181 #if defined(CONFIG_CMD_IRQ)
182 /*******************************************************************************
184 * irqinfo - print information about IRQs
187 int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
191 printf ("\nInterrupt-Information:\n");
192 printf ("Nr Routine Arg Count\n");
194 for (vec=0; vec<NR_IRQS; vec++) {
195 if (irq_vecs[vec].handler != NULL) {
196 printf ("%02d %08lx %08lx %d\n",
198 (ulong)irq_vecs[vec].handler,
199 (ulong)irq_vecs[vec].arg,
200 irq_vecs[vec].count);