]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/microblaze/interrupts.c
fix: clean interrupt
[karo-tx-uboot.git] / cpu / microblaze / interrupts.c
1 /*
2  * (C) Copyright 2007 Michal Simek
3  * (C) Copyright 2004 Atmark Techno, Inc.
4  *
5  * Michal  SIMEK <monstr@monstr.eu>
6  * Yasushi SHOJI <yashi@atmark-techno.com>
7  *
8  * See file CREDITS for list of people who contributed to this
9  * project.
10  *
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.
15  *
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.
20  *
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,
24  * MA 02111-1307 USA
25  */
26
27 #include <common.h>
28 #include <command.h>
29 #include <asm/microblaze_intc.h>
30 #include <asm/asm.h>
31
32 #undef DEBUG_INT
33
34 extern void microblaze_disable_interrupts (void);
35 extern void microblaze_enable_interrupts (void);
36
37 void enable_interrupts (void)
38 {
39         __asm__ __volatile__ ("msrset r0, 0x2");
40         //microblaze_enable_interrupts ();
41 }
42
43 int disable_interrupts (void)
44 {
45         __asm__ __volatile__ ("msrclr r0, 0x2");
46         //microblaze_disable_interrupts ();
47         return 0;
48 }
49
50 #ifdef CFG_INTC_0
51 #ifdef CFG_TIMER_0
52 extern void timer_init (void);
53 #endif
54 #ifdef CFG_FSL_2
55 extern void fsl_init2 (void);
56 #endif
57
58
59 static struct irq_action vecs[CFG_INTC_0_NUM];
60
61 /* mapping structure to interrupt controller */
62 microblaze_intc_t *intc = (microblaze_intc_t *) (CFG_INTC_0_ADDR);
63
64 /* default handler */
65 void def_hdlr (void)
66 {
67         puts ("def_hdlr\n");
68 }
69
70 void enable_one_interrupt (int irq)
71 {
72         int mask;
73         int offset = 1;
74         offset <<= irq;
75         mask = intc->ier;
76         intc->ier = (mask | offset);
77 #ifdef DEBUG_INT
78         printf ("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
79                 intc->ier);
80         printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
81                 intc->iar, intc->mer);
82 #endif
83 }
84
85 void disable_one_interrupt (int irq)
86 {
87         int mask;
88         int offset = 1;
89         offset <<= irq;
90         mask = intc->ier;
91         intc->ier = (mask & ~offset);
92 #ifdef DEBUG_INT
93         printf ("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
94                 intc->ier);
95         printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
96                 intc->iar, intc->mer);
97 #endif
98 }
99
100 /* adding new handler for interrupt */
101 void install_interrupt_handler (int irq, interrupt_handler_t * hdlr, void *arg)
102 {
103         struct irq_action *act;
104         /* irq out of range */
105         if ((irq < 0) || (irq > CFG_INTC_0_NUM)) {
106                 puts ("IRQ out of range\n");
107                 return;
108         }
109         act = &vecs[irq];
110         if (hdlr) {             /* enable */
111                 act->handler = hdlr;
112                 act->arg = arg;
113                 act->count = 0;
114                 enable_one_interrupt (irq);
115         } else {                /* disable */
116                 act->handler = (interrupt_handler_t *) def_hdlr;
117                 act->arg = (void *)irq;
118                 disable_one_interrupt (irq);
119         }
120 }
121
122 /* initialization interrupt controller - hardware */
123 void intc_init (void)
124 {
125         intc->mer = 0;
126         intc->ier = 0;
127         intc->iar = 0xFFFFFFFF;
128         /* XIntc_Start - hw_interrupt enable and all interrupt enable */
129         intc->mer = 0x3;
130 #ifdef DEBUG_INT
131         printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
132                 intc->iar, intc->mer);
133 #endif
134 }
135
136 int interrupts_init (void)
137 {
138         int i;
139         /* initialize irq list */
140         for (i = 0; i < CFG_INTC_0_NUM; i++) {
141                 vecs[i].handler = (interrupt_handler_t *) def_hdlr;
142                 vecs[i].arg = (void *)i;
143                 vecs[i].count = 0;
144         }
145         /* initialize intc controller */
146         intc_init ();
147 #ifdef CFG_TIMER_0
148         timer_init ();
149 #endif
150 #ifdef CFG_FSL_2
151         fsl_init2 ();
152 #endif
153         enable_interrupts ();
154         return 0;
155 }
156
157 void interrupt_handler (void)
158 {
159         int irqs = (intc->isr & intc->ier);     /* find active interrupt */
160         int i = 1;
161 #ifdef DEBUG_INT
162         int value;
163         printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
164                 intc->iar, intc->mer);
165         R14(value);
166         printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
167 #endif
168         struct irq_action *act = vecs;
169         while (irqs) {
170                 if (irqs & 1) {
171 #ifdef DEBUG_INT
172                         printf
173                             ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
174                              act->handler, act->count, act->arg);
175 #endif
176                         act->handler (act->arg);
177                         act->count++;
178                         intc->iar = i;
179                         return;
180                 }
181                 irqs >>= 1;
182                 act++;
183                 i <<= 1;
184         }
185
186 #ifdef DEBUG_INT
187         printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
188                 intc->ier, intc->iar, intc->mer);
189         R14(value);
190         printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
191 #endif
192 }
193 #endif
194
195 #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
196 #ifdef CFG_INTC_0
197 int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
198 {
199         int i;
200         struct irq_action *act = vecs;
201
202         puts ("\nInterrupt-Information:\n\n"
203               "Nr  Routine   Arg       Count\n"
204               "-----------------------------\n");
205
206         for (i = 0; i < CFG_INTC_0_NUM; i++) {
207                 if (act->handler != (interrupt_handler_t*) def_hdlr) {
208                         printf ("%02d  %08lx  %08lx  %d\n", i,
209                                 (int)act->handler, (int)act->arg, act->count);
210                 }
211                 act++;
212         }
213         puts ("\n");
214         return (0);
215 }
216 #else
217 int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
218 {
219         puts ("Undefined interrupt controller\n");
220 }
221 #endif
222 #endif                          /* CONFIG_COMMANDS & CFG_CMD_IRQ */