2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
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
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <mpc8xx_irq.h>
28 #include <asm/processor.h>
31 /************************************************************************/
33 unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
35 /************************************************************************/
38 * CPM interrupt vector functions.
40 struct interrupt_action {
41 interrupt_handler_t *handler;
45 static struct interrupt_action cpm_vecs[CPMVEC_NR];
46 static struct interrupt_action irq_vecs[NR_IRQS];
48 static void cpm_interrupt_init (void);
49 static void cpm_interrupt (void *regs);
51 /************************************************************************/
53 static __inline__ unsigned long get_msr (void)
57 asm volatile ("mfmsr %0":"=r" (msr):);
62 static __inline__ void set_msr (unsigned long msr)
64 asm volatile ("mtmsr %0"::"r" (msr));
67 static __inline__ unsigned long get_dec (void)
71 asm volatile ("mfdec %0":"=r" (val):);
77 static __inline__ void set_dec (unsigned long val)
79 asm volatile ("mtdec %0"::"r" (val));
83 void enable_interrupts (void)
85 set_msr (get_msr () | MSR_EE);
88 /* returns flag if MSR_EE was set before */
89 int disable_interrupts (void)
91 ulong msr = get_msr ();
93 set_msr (msr & ~MSR_EE);
94 return ((msr & MSR_EE) != 0);
97 /************************************************************************/
99 int interrupt_init (void)
101 volatile immap_t *immr = (immap_t *) CFG_IMMR;
103 decrementer_count = get_tbclk () / CFG_HZ;
105 /* disable all interrupts */
106 immr->im_siu_conf.sc_simask = 0;
108 /* Configure CPM interrupts */
109 cpm_interrupt_init ();
111 set_dec (decrementer_count);
113 set_msr (get_msr () | MSR_EE);
118 /************************************************************************/
121 * Handle external interrupts
123 void external_interrupt (struct pt_regs *regs)
125 volatile immap_t *immr = (immap_t *) CFG_IMMR;
127 ulong simask, newmask;
131 * read the SIVEC register and shift the bits down
132 * to get the irq number
134 vec = immr->im_siu_conf.sc_sivec;
136 v_bit = 0x80000000UL >> irq;
139 * Read Interrupt Mask Register and Mask Interrupts
141 simask = immr->im_siu_conf.sc_simask;
142 newmask = simask & (~(0xFFFF0000 >> irq));
143 immr->im_siu_conf.sc_simask = newmask;
145 if (!(irq & 0x1)) { /* External Interrupt ? */
149 * Read Interrupt Edge/Level Register
151 siel = immr->im_siu_conf.sc_siel;
153 if (siel & v_bit) { /* edge triggered interrupt ? */
155 * Rewrite SIPEND Register to clear interrupt
157 immr->im_siu_conf.sc_sipend = v_bit;
161 if (irq_vecs[irq].handler != NULL) {
162 irq_vecs[irq].handler (irq_vecs[irq].arg);
164 printf ("\nBogus External Interrupt IRQ %d Vector %ld\n",
166 /* turn off the bogus interrupt to avoid it from now */
170 * Re-Enable old Interrupt Mask
172 immr->im_siu_conf.sc_simask = simask;
175 /************************************************************************/
178 * CPM interrupt handler
180 static void cpm_interrupt (void *regs)
182 volatile immap_t *immr = (immap_t *) CFG_IMMR;
186 * Get the vector by setting the ACK bit
187 * and then reading the register.
189 immr->im_cpic.cpic_civr = 1;
190 vec = immr->im_cpic.cpic_civr;
193 if (cpm_vecs[vec].handler != NULL) {
194 (*cpm_vecs[vec].handler) (cpm_vecs[vec].arg);
196 immr->im_cpic.cpic_cimr &= ~(1 << vec);
197 printf ("Masking bogus CPM interrupt vector 0x%x\n", vec);
200 * After servicing the interrupt,
201 * we have to remove the status indicator.
203 immr->im_cpic.cpic_cisr |= (1 << vec);
207 * The CPM can generate the error interrupt when there is a race
208 * condition between generating and masking interrupts. All we have
209 * to do is ACK it and return. This is a no-op function so we don't
210 * need any special tests in the interrupt handler.
212 static void cpm_error_interrupt (void *dummy)
216 /************************************************************************/
218 * Install and free an interrupt handler
220 void irq_install_handler (int vec, interrupt_handler_t * handler,
223 volatile immap_t *immr = (immap_t *) CFG_IMMR;
225 if ((vec & CPMVEC_OFFSET) != 0) {
228 if (cpm_vecs[vec].handler != NULL) {
229 printf ("CPM interrupt 0x%x replacing 0x%x\n",
231 (uint) cpm_vecs[vec].handler);
233 cpm_vecs[vec].handler = handler;
234 cpm_vecs[vec].arg = arg;
235 immr->im_cpic.cpic_cimr |= (1 << vec);
237 printf ("Install CPM interrupt for vector %d ==> %p\n",
242 if (irq_vecs[vec].handler != NULL) {
243 printf ("SIU interrupt %d 0x%x replacing 0x%x\n",
246 (uint) cpm_vecs[vec].handler);
248 irq_vecs[vec].handler = handler;
249 irq_vecs[vec].arg = arg;
250 immr->im_siu_conf.sc_simask |= 1 << (31 - vec);
252 printf ("Install SIU interrupt for vector %d ==> %p\n",
258 void irq_free_handler (int vec)
260 volatile immap_t *immr = (immap_t *) CFG_IMMR;
262 if ((vec & CPMVEC_OFFSET) != 0) {
266 printf ("Free CPM interrupt for vector %d ==> %p\n",
267 vec, cpm_vecs[vec].handler);
269 immr->im_cpic.cpic_cimr &= ~(1 << vec);
270 cpm_vecs[vec].handler = NULL;
271 cpm_vecs[vec].arg = NULL;
275 printf ("Free CPM interrupt for vector %d ==> %p\n",
276 vec, cpm_vecs[vec].handler);
278 immr->im_siu_conf.sc_simask &= ~(1 << (31 - vec));
279 irq_vecs[vec].handler = NULL;
280 irq_vecs[vec].arg = NULL;
284 /************************************************************************/
286 static void cpm_interrupt_init (void)
288 volatile immap_t *immr = (immap_t *) CFG_IMMR;
291 * Initialize the CPM interrupt controller.
294 immr->im_cpic.cpic_cicr =
298 CICR_SCA_SCC1) | ((CPM_INTERRUPT / 2) << 13) | CICR_HP_MASK;
300 immr->im_cpic.cpic_cimr = 0;
303 * Install the error handler.
305 irq_install_handler (CPMVEC_ERROR, cpm_error_interrupt, NULL);
307 immr->im_cpic.cpic_cicr |= CICR_IEN;
310 * Install the cpm interrupt handler
312 irq_install_handler (CPM_INTERRUPT, cpm_interrupt, NULL);
315 /************************************************************************/
317 volatile ulong timestamp = 0;
320 * timer_interrupt - gets called when the decrementer overflows,
321 * with interrupts disabled.
322 * Trivial implementation - no need to be really accurate.
324 void timer_interrupt (struct pt_regs *regs)
326 volatile immap_t *immr = (immap_t *) CFG_IMMR;
328 #ifdef CONFIG_STATUS_LED
329 extern void status_led_tick (ulong);
332 printf ("*** Timer Interrupt *** ");
334 /* Reset Timer Expired and Timers Interrupt Status */
335 immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
337 immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS | PLPRCR_TMIST;
338 /* Restore Decrementer Count */
339 set_dec (decrementer_count);
343 #ifdef CONFIG_STATUS_LED
344 status_led_tick (timestamp);
345 #endif /* CONFIG_STATUS_LED */
347 #if defined(CONFIG_WATCHDOG) || defined(CFG_CMA_LCD_HEARTBEAT)
350 * The shortest watchdog period of all boards (except LWMON)
351 * is approx. 1 sec, thus re-trigger watchdog at least
352 * every 500 ms = CFG_HZ / 2
355 if ((timestamp % (CFG_HZ / 2)) == 0) {
357 if ((timestamp % (CFG_HZ / 20)) == 0) {
360 #if defined(CFG_CMA_LCD_HEARTBEAT)
361 extern void lcd_heartbeat (void);
364 #endif /* CFG_CMA_LCD_HEARTBEAT */
366 #if defined(CONFIG_WATCHDOG)
367 reset_8xx_watchdog (immr);
368 #endif /* CONFIG_WATCHDOG */
371 #endif /* CONFIG_WATCHDOG || CFG_CMA_LCD_HEARTBEAT */
374 /************************************************************************/
376 void reset_timer (void)
381 ulong get_timer (ulong base)
383 return (timestamp - base);
386 void set_timer (ulong t)
391 /************************************************************************/