blob: 115e58d7f08e36aaec041a5210d007024c375343 [file] [log] [blame]
wdenk12490652004-04-18 21:13:41 +00001/*
Michal Simek922ce202007-03-11 13:48:24 +01002 * (C) Copyright 2007 Michal Simek
wdenk12490652004-04-18 21:13:41 +00003 * (C) Copyright 2004 Atmark Techno, Inc.
4 *
Michal Simek922ce202007-03-11 13:48:24 +01005 * Michal SIMEK <monstr@monstr.eu>
wdenk12490652004-04-18 21:13:41 +00006 * 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
Michal Simek922ce202007-03-11 13:48:24 +010018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk12490652004-04-18 21:13:41 +000019 * 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
Michal Simek922ce202007-03-11 13:48:24 +010027#include <common.h>
28#include <command.h>
29#include <asm/microblaze_intc.h>
Michal Simek77a1e242007-05-07 17:22:25 +020030#include <asm/asm.h>
Michal Simek922ce202007-03-11 13:48:24 +010031
32#undef DEBUG_INT
33
34extern void microblaze_disable_interrupts (void);
35extern void microblaze_enable_interrupts (void);
36
37void enable_interrupts (void)
wdenk12490652004-04-18 21:13:41 +000038{
Michal Simek922ce202007-03-11 13:48:24 +010039 microblaze_enable_interrupts ();
wdenk12490652004-04-18 21:13:41 +000040}
41
Michal Simek922ce202007-03-11 13:48:24 +010042int disable_interrupts (void)
wdenk12490652004-04-18 21:13:41 +000043{
Michal Simek922ce202007-03-11 13:48:24 +010044 microblaze_disable_interrupts ();
wdenk12490652004-04-18 21:13:41 +000045 return 0;
46}
Michal Simek922ce202007-03-11 13:48:24 +010047
48#ifdef CFG_INTC_0
49#ifdef CFG_TIMER_0
50extern void timer_init (void);
51#endif
52
53static struct irq_action vecs[CFG_INTC_0_NUM];
54
55/* mapping structure to interrupt controller */
56microblaze_intc_t *intc = (microblaze_intc_t *) (CFG_INTC_0_ADDR);
57
58/* default handler */
59void def_hdlr (void)
60{
61 puts ("def_hdlr\n");
62}
63
64void enable_one_interrupt (int irq)
65{
66 int mask;
67 int offset = 1;
68 offset <<= irq;
69 mask = intc->ier;
70 intc->ier = (mask | offset);
71#ifdef DEBUG_INT
72 printf ("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
73 intc->ier);
74 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
75 intc->iar, intc->mer);
76#endif
77}
78
79void disable_one_interrupt (int irq)
80{
81 int mask;
82 int offset = 1;
83 offset <<= irq;
84 mask = intc->ier;
85 intc->ier = (mask & ~offset);
86#ifdef DEBUG_INT
87 printf ("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
88 intc->ier);
89 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
90 intc->iar, intc->mer);
91#endif
92}
93
94/* adding new handler for interrupt */
95void install_interrupt_handler (int irq, interrupt_handler_t * hdlr, void *arg)
96{
97 struct irq_action *act;
98 /* irq out of range */
Michal Simek1f0c40c2007-03-26 01:39:07 +020099 if ((irq < 0) || (irq > CFG_INTC_0_NUM)) {
Michal Simek922ce202007-03-11 13:48:24 +0100100 puts ("IRQ out of range\n");
101 return;
102 }
103 act = &vecs[irq];
104 if (hdlr) { /* enable */
105 act->handler = hdlr;
106 act->arg = arg;
107 act->count = 0;
108 enable_one_interrupt (irq);
109 } else { /* disable */
Michal Simek922ce202007-03-11 13:48:24 +0100110 act->handler = (interrupt_handler_t *) def_hdlr;
111 act->arg = (void *)irq;
112 disable_one_interrupt (irq);
113 }
114}
115
116/* initialization interrupt controller - hardware */
117void intc_init (void)
118{
119 intc->mer = 0;
120 intc->ier = 0;
121 intc->iar = 0xFFFFFFFF;
122 /* XIntc_Start - hw_interrupt enable and all interrupt enable */
123 intc->mer = 0x3;
124#ifdef DEBUG_INT
125 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
126 intc->iar, intc->mer);
127#endif
128}
129
130int interrupts_init (void)
131{
132 int i;
133 /* initialize irq list */
Michal Simek1f0c40c2007-03-26 01:39:07 +0200134 for (i = 0; i < CFG_INTC_0_NUM; i++) {
Michal Simek922ce202007-03-11 13:48:24 +0100135 vecs[i].handler = (interrupt_handler_t *) def_hdlr;
136 vecs[i].arg = (void *)i;
137 vecs[i].count = 0;
138 }
139 /* initialize intc controller */
140 intc_init ();
141#ifdef CFG_TIMER_0
142 timer_init ();
143#endif
144 enable_interrupts ();
145 return 0;
146}
147
148void interrupt_handler (void)
149{
Michal Simek77a1e242007-05-07 17:22:25 +0200150 int irqs = (intc->isr & intc->ier); /* find active interrupt */
151 int i = 1;
Michal Simek922ce202007-03-11 13:48:24 +0100152#ifdef DEBUG_INT
Michal Simek77a1e242007-05-07 17:22:25 +0200153 int value;
Michal Simek922ce202007-03-11 13:48:24 +0100154 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
155 intc->iar, intc->mer);
Michal Simek77a1e242007-05-07 17:22:25 +0200156 R14(value);
Michal Simek922ce202007-03-11 13:48:24 +0100157 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
158#endif
159 struct irq_action *act = vecs;
160 while (irqs) {
161 if (irqs & 1) {
162#ifdef DEBUG_INT
163 printf
164 ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
165 act->handler, act->count, act->arg);
166#endif
167 act->handler (act->arg);
168 act->count++;
Michal Simek77a1e242007-05-07 17:22:25 +0200169 intc->iar = i;
170 return;
Michal Simek922ce202007-03-11 13:48:24 +0100171 }
172 irqs >>= 1;
173 act++;
Michal Simek77a1e242007-05-07 17:22:25 +0200174 i <<= 1;
Michal Simek922ce202007-03-11 13:48:24 +0100175 }
Michal Simek77a1e242007-05-07 17:22:25 +0200176
177#ifdef DEBUG_INT
Michal Simek922ce202007-03-11 13:48:24 +0100178 printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
179 intc->ier, intc->iar, intc->mer);
Michal Simek77a1e242007-05-07 17:22:25 +0200180 R14(value);
181 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
Michal Simek922ce202007-03-11 13:48:24 +0100182#endif
183}
184#endif
185
186#if (CONFIG_COMMANDS & CFG_CMD_IRQ)
187#ifdef CFG_INTC_0
188int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
189{
190 int i;
191 struct irq_action *act = vecs;
192
193 puts ("\nInterrupt-Information:\n\n"
194 "Nr Routine Arg Count\n"
195 "-----------------------------\n");
196
Michal Simek1f0c40c2007-03-26 01:39:07 +0200197 for (i = 0; i < CFG_INTC_0_NUM; i++) {
Michal Simek922ce202007-03-11 13:48:24 +0100198 if (act->handler != (interrupt_handler_t*) def_hdlr) {
199 printf ("%02d %08lx %08lx %d\n", i,
200 (int)act->handler, (int)act->arg, act->count);
201 }
202 act++;
203 }
204 puts ("\n");
205 return (0);
206}
207#else
208int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
209{
210 puts ("Undefined interrupt controller\n");
211}
212#endif
213#endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */