blob: 37ed16dfe150d00a9fbee9f14e392de40ba31ef6 [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>
30
31#undef DEBUG_INT
32
33extern void microblaze_disable_interrupts (void);
34extern void microblaze_enable_interrupts (void);
35
36void enable_interrupts (void)
wdenk12490652004-04-18 21:13:41 +000037{
Michal Simek922ce202007-03-11 13:48:24 +010038 microblaze_enable_interrupts ();
wdenk12490652004-04-18 21:13:41 +000039}
40
Michal Simek922ce202007-03-11 13:48:24 +010041int disable_interrupts (void)
wdenk12490652004-04-18 21:13:41 +000042{
Michal Simek922ce202007-03-11 13:48:24 +010043 microblaze_disable_interrupts ();
wdenk12490652004-04-18 21:13:41 +000044 return 0;
45}
Michal Simek922ce202007-03-11 13:48:24 +010046
47#ifdef CFG_INTC_0
48#ifdef CFG_TIMER_0
49extern void timer_init (void);
50#endif
51
52static struct irq_action vecs[CFG_INTC_0_NUM];
53
54/* mapping structure to interrupt controller */
55microblaze_intc_t *intc = (microblaze_intc_t *) (CFG_INTC_0_ADDR);
56
57/* default handler */
58void def_hdlr (void)
59{
60 puts ("def_hdlr\n");
61}
62
63void enable_one_interrupt (int irq)
64{
65 int mask;
66 int offset = 1;
67 offset <<= irq;
68 mask = intc->ier;
69 intc->ier = (mask | offset);
70#ifdef DEBUG_INT
71 printf ("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
72 intc->ier);
73 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
74 intc->iar, intc->mer);
75#endif
76}
77
78void disable_one_interrupt (int irq)
79{
80 int mask;
81 int offset = 1;
82 offset <<= irq;
83 mask = intc->ier;
84 intc->ier = (mask & ~offset);
85#ifdef DEBUG_INT
86 printf ("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
87 intc->ier);
88 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
89 intc->iar, intc->mer);
90#endif
91}
92
93/* adding new handler for interrupt */
94void install_interrupt_handler (int irq, interrupt_handler_t * hdlr, void *arg)
95{
96 struct irq_action *act;
97 /* irq out of range */
98 if ((irq < 0) || (irq > CONFIG_XILINX_INTC_0_NUM_INTR_INPUTS)) {
99 puts ("IRQ out of range\n");
100 return;
101 }
102 act = &vecs[irq];
103 if (hdlr) { /* enable */
104 act->handler = hdlr;
105 act->arg = arg;
106 act->count = 0;
107 enable_one_interrupt (irq);
108 } else { /* disable */
109
110 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 */
134 for (i = 0; i < CONFIG_XILINX_INTC_0_NUM_INTR_INPUTS; i++) {
135 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{
150 int irqs;
151 irqs = (intc->isr & intc->ier); /* find active interrupt */
152
153#ifdef DEBUG_INT
154 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
155 intc->iar, intc->mer);
156 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
157#endif
158 struct irq_action *act = vecs;
159 while (irqs) {
160 if (irqs & 1) {
161#ifdef DEBUG_INT
162 printf
163 ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
164 act->handler, act->count, act->arg);
165#endif
166 act->handler (act->arg);
167 act->count++;
168 }
169 irqs >>= 1;
170 act++;
171 }
172 intc->iar = 0xFFFFFFFF; /* erase all events */
173#ifdef DEBUG
174 printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
175 intc->ier, intc->iar, intc->mer);
176 printf ("Interrupt handler on %x line, r14\n", irqs);
177#endif
178}
179#endif
180
181#if (CONFIG_COMMANDS & CFG_CMD_IRQ)
182#ifdef CFG_INTC_0
183int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
184{
185 int i;
186 struct irq_action *act = vecs;
187
188 puts ("\nInterrupt-Information:\n\n"
189 "Nr Routine Arg Count\n"
190 "-----------------------------\n");
191
192 for (i = 0; i < CONFIG_XILINX_INTC_0_NUM_INTR_INPUTS; i++) {
193 if (act->handler != (interrupt_handler_t*) def_hdlr) {
194 printf ("%02d %08lx %08lx %d\n", i,
195 (int)act->handler, (int)act->arg, act->count);
196 }
197 act++;
198 }
199 puts ("\n");
200 return (0);
201}
202#else
203int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
204{
205 puts ("Undefined interrupt controller\n");
206}
207#endif
208#endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */