blob: 35dddf598466e13884f183c02538443e24b424f5 [file] [log] [blame]
wdenk359733b2003-03-31 17:27:09 +00001/*
2 * (C) Copyright 2000-2002 Wolfgang Denk, DENX Software Engineering, wd@denx.de.
3 * (C) Copyright 2003 Martin Winistoerfer, martinwinistoerfer@gmx.ch.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk359733b2003-03-31 17:27:09 +00006 */
7
8/*
9 * File: interrupt.c
wdenk57b2d802003-06-27 21:31:46 +000010 *
wdenk359733b2003-03-31 17:27:09 +000011 * Discription: Contains interrupt routines needed by U-Boot
12 *
13 */
14
15#include <common.h>
wdenkbc01dd52004-01-02 16:05:07 +000016#include <command.h>
wdenk359733b2003-03-31 17:27:09 +000017#include <mpc5xx.h>
18#include <asm/processor.h>
19
wdenkbc01dd52004-01-02 16:05:07 +000020#if defined(CONFIG_PATI)
21/* PATI uses IRQs for PCI doorbell */
22#undef NR_IRQS
23#define NR_IRQS 16
24#endif
25
wdenk359733b2003-03-31 17:27:09 +000026struct interrupt_action {
27 interrupt_handler_t *handler;
28 void *arg;
wdenkbc01dd52004-01-02 16:05:07 +000029 int count;
wdenk359733b2003-03-31 17:27:09 +000030};
31
32static struct interrupt_action irq_vecs[NR_IRQS];
33
34/*
wdenk57b2d802003-06-27 21:31:46 +000035 * Initialise interrupts
wdenk359733b2003-03-31 17:27:09 +000036 */
37
wdenkc0aa5c52003-12-06 19:49:23 +000038int interrupt_init_cpu (ulong *decrementer_count)
wdenk359733b2003-03-31 17:27:09 +000039{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020040 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenkbc01dd52004-01-02 16:05:07 +000041 int vec;
wdenk359733b2003-03-31 17:27:09 +000042
43 /* Decrementer used here for status led */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044 *decrementer_count = get_tbclk () / CONFIG_SYS_HZ;
wdenk359733b2003-03-31 17:27:09 +000045
46 /* Disable all interrupts */
47 immr->im_siu_conf.sc_simask = 0;
wdenkbc01dd52004-01-02 16:05:07 +000048 for (vec=0; vec<NR_IRQS; vec++) {
49 irq_vecs[vec].handler = NULL;
50 irq_vecs[vec].arg = NULL;
51 irq_vecs[vec].count = 0;
52 }
wdenk359733b2003-03-31 17:27:09 +000053
wdenk359733b2003-03-31 17:27:09 +000054 return (0);
55}
56
57/*
58 * Handle external interrupts
59 */
60void external_interrupt (struct pt_regs *regs)
61{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020062 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenk359733b2003-03-31 17:27:09 +000063 int irq;
64 ulong simask, newmask;
65 ulong vec, v_bit;
66
67 /*
68 * read the SIVEC register and shift the bits down
69 * to get the irq number
70 */
71 vec = immr->im_siu_conf.sc_sivec;
72 irq = vec >> 26;
73 v_bit = 0x80000000UL >> irq;
74
75 /*
76 * Read Interrupt Mask Register and Mask Interrupts
77 */
78 simask = immr->im_siu_conf.sc_simask;
79 newmask = simask & (~(0xFFFF0000 >> irq));
80 immr->im_siu_conf.sc_simask = newmask;
81
82 if (!(irq & 0x1)) { /* External Interrupt ? */
83 ulong siel;
84
85 /*
86 * Read Interrupt Edge/Level Register
87 */
88 siel = immr->im_siu_conf.sc_siel;
89
90 if (siel & v_bit) { /* edge triggered interrupt ? */
91 /*
92 * Rewrite SIPEND Register to clear interrupt
93 */
94 immr->im_siu_conf.sc_sipend = v_bit;
95 }
96 }
97
98 if (irq_vecs[irq].handler != NULL) {
99 irq_vecs[irq].handler (irq_vecs[irq].arg);
100 } else {
101 printf ("\nBogus External Interrupt IRQ %d Vector %ld\n",
102 irq, vec);
103 /* turn off the bogus interrupt to avoid it from now */
104 simask &= ~v_bit;
105 }
106 /*
107 * Re-Enable old Interrupt Mask
108 */
109 immr->im_siu_conf.sc_simask = simask;
110}
111
112/*
113 * Install and free an interrupt handler
114 */
115void irq_install_handler (int vec, interrupt_handler_t * handler,
116 void *arg)
117{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenk359733b2003-03-31 17:27:09 +0000119 /* SIU interrupt */
120 if (irq_vecs[vec].handler != NULL) {
121 printf ("SIU interrupt %d 0x%x\n",
122 vec,
123 (uint) handler);
124 }
125 irq_vecs[vec].handler = handler;
126 irq_vecs[vec].arg = arg;
127 immr->im_siu_conf.sc_simask |= 1 << (31 - vec);
128#if 0
129 printf ("Install SIU interrupt for vector %d ==> %p\n",
130 vec, handler);
131#endif
132}
133
134void irq_free_handler (int vec)
135{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenk359733b2003-03-31 17:27:09 +0000137 /* SIU interrupt */
138#if 0
139 printf ("Free CPM interrupt for vector %d\n",
140 vec);
141#endif
142 immr->im_siu_conf.sc_simask &= ~(1 << (31 - vec));
143 irq_vecs[vec].handler = NULL;
144 irq_vecs[vec].arg = NULL;
145}
146
wdenk359733b2003-03-31 17:27:09 +0000147/*
wdenk57b2d802003-06-27 21:31:46 +0000148 * Timer interrupt - gets called when bit 0 of DEC changes from
wdenk359733b2003-03-31 17:27:09 +0000149 * 0. Decrementer is enabled with bit TBE in TBSCR.
150 */
wdenkc0aa5c52003-12-06 19:49:23 +0000151void timer_interrupt_cpu (struct pt_regs *regs)
wdenk359733b2003-03-31 17:27:09 +0000152{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenk359733b2003-03-31 17:27:09 +0000154
wdenk359733b2003-03-31 17:27:09 +0000155#if 0
156 printf ("*** Timer Interrupt *** ");
157#endif
158 /* Reset Timer Status Bit and Timers Interrupt Status */
159 immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
160 __asm__ ("nop");
161 immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS | PLPRCR_TMIST;
wdenk57b2d802003-06-27 21:31:46 +0000162
wdenkc0aa5c52003-12-06 19:49:23 +0000163 return;
wdenk359733b2003-03-31 17:27:09 +0000164}
wdenkbc01dd52004-01-02 16:05:07 +0000165
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500166#if defined(CONFIG_CMD_IRQ)
wdenkbc01dd52004-01-02 16:05:07 +0000167/*******************************************************************************
168 *
169 * irqinfo - print information about IRQs
170 *
171 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200172int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkbc01dd52004-01-02 16:05:07 +0000173{
174 int vec;
175
176 printf ("\nInterrupt-Information:\n");
177 printf ("Nr Routine Arg Count\n");
178
179 for (vec=0; vec<NR_IRQS; vec++) {
180 if (irq_vecs[vec].handler != NULL) {
181 printf ("%02d %08lx %08lx %d\n",
182 vec,
183 (ulong)irq_vecs[vec].handler,
184 (ulong)irq_vecs[vec].arg,
185 irq_vecs[vec].count);
186 }
187 }
188 return 0;
189}
190
191
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500192#endif