blob: fbf0c2b6ba914afb96241c3a71e2edda16e277d5 [file] [log] [blame]
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +02001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2002 (440 port)
6 * Scott McNutt, Artesyn Communication Producs, smcnutt@artsyncp.com
7 *
8 * (C) Copyright 2003 (440GX port)
9 * Travis B. Sawyer, Sandburst Corporation, tsawyer@sandburst.com
10 *
11 * (C) Copyright 2008 (PPC440X05 port for Virtex 5 FX)
12 * Ricardo Ribalda-Universidad Autonoma de Madrid-ricardo.ribalda@uam.es
13 * Work supported by Qtechnology (htpp://qtec.com)
14 *
15 * See file CREDITS for list of people who contributed to this
16 * project.
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of
21 * the License, or (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * MA 02111-1307 USA
32 */
33
34#include <common.h>
35#include <watchdog.h>
36#include <command.h>
37#include <asm/processor.h>
38#include <asm/interrupt.h>
39#include <ppc4xx.h>
40#include <ppc_asm.tmpl>
41#include <commproc.h>
42
43#if (UIC_MAX > 3)
44#define UICB0_ALL (UIC_MASK(VECNUM_UIC1CI) | UIC_MASK(VECNUM_UIC1NCI) | \
45 UIC_MASK(VECNUM_UIC2CI) | UIC_MASK(VECNUM_UIC2NCI) | \
46 UIC_MASK(VECNUM_UIC3CI) | UIC_MASK(VECNUM_UIC3NCI))
47#elif (UIC_MAX > 2)
48#define UICB0_ALL (UIC_MASK(VECNUM_UIC1CI) | UIC_MASK(VECNUM_UIC1NCI) | \
49 UIC_MASK(VECNUM_UIC2CI) | UIC_MASK(VECNUM_UIC2NCI))
50#elif (UIC_MAX > 1)
51#define UICB0_ALL (UIC_MASK(VECNUM_UIC1CI) | UIC_MASK(VECNUM_UIC1NCI))
52#else
53#define UICB0_ALL 0
54#endif
55
56u32 get_dcr(u16);
57
58DECLARE_GLOBAL_DATA_PTR;
59
60void pic_enable(void)
61{
62
63#if (UIC_MAX > 1)
64 /* Install the UIC1 handlers */
65 irq_install_handler(VECNUM_UIC1NCI, (void *)(void *)external_interrupt,
66 0);
67 irq_install_handler(VECNUM_UIC1CI, (void *)(void *)external_interrupt,
68 0);
69#endif
70#if (UIC_MAX > 2)
71 irq_install_handler(VECNUM_UIC2NCI, (void *)(void *)external_interrupt,
72 0);
73 irq_install_handler(VECNUM_UIC2CI, (void *)(void *)external_interrupt,
74 0);
75#endif
76#if (UIC_MAX > 3)
77 irq_install_handler(VECNUM_UIC3NCI, (void *)(void *)external_interrupt,
78 0);
79 irq_install_handler(VECNUM_UIC3CI, (void *)(void *)external_interrupt,
80 0);
81#endif
82
83}
84
85/* Handler for UIC interrupt */
86static void uic_interrupt(u32 uic_base, int vec_base)
87{
88 u32 uic_msr;
89 u32 msr_shift;
90 int vec;
91
92 /*
93 * Read masked interrupt status register to determine interrupt source
94 */
95 uic_msr = get_dcr(uic_base + UIC_MSR);
96 msr_shift = uic_msr;
97 vec = vec_base;
98
99 while (msr_shift != 0) {
100 if (msr_shift & 0x80000000)
101 interrupt_run_handler(vec);
102 /*
103 * Shift msr to next position and increment vector
104 */
105 msr_shift <<= 1;
106 vec++;
107 }
108}
109
110/*
111 * Handle external interrupts
112 */
113void external_interrupt(struct pt_regs *regs)
114{
115 u32 uic_msr;
116
117 /*
118 * Read masked interrupt status register to determine interrupt source
119 */
120 uic_msr = mfdcr(uic0msr);
121
122#if (UIC_MAX > 1)
123 if ((UIC_MASK(VECNUM_UIC1CI) & uic_msr) ||
124 (UIC_MASK(VECNUM_UIC1NCI) & uic_msr))
125 uic_interrupt(UIC1_DCR_BASE, 32);
126#endif
127
128#if (UIC_MAX > 2)
129 if ((UIC_MASK(VECNUM_UIC2CI) & uic_msr) ||
130 (UIC_MASK(VECNUM_UIC2NCI) & uic_msr))
131 uic_interrupt(UIC2_DCR_BASE, 64);
132#endif
133
134#if (UIC_MAX > 3)
135 if ((UIC_MASK(VECNUM_UIC3CI) & uic_msr) ||
136 (UIC_MASK(VECNUM_UIC3NCI) & uic_msr))
137 uic_interrupt(UIC3_DCR_BASE, 96);
138#endif
139
140 if (uic_msr & ~(UICB0_ALL))
141 uic_interrupt(UIC0_DCR_BASE, 0);
142
143 mtdcr(uic0sr, uic_msr);
144
145 return;
146}
147
148void pic_irq_ack(unsigned int vec)
149{
150
151 if ((vec >= 0) && (vec < 32))
152 mtdcr(uicsr, UIC_MASK(vec));
153#if (UIC_MAX > 1)
154 else if ((vec >= 32) && (vec < 64))
155 mtdcr(uic1sr, UIC_MASK(vec));
156#endif
157#if (UIC_MAX > 2)
158 else if ((vec >= 64) && (vec < 96))
159 mtdcr(uic2sr, UIC_MASK(vec));
160#endif
161#if (UIC_MAX > 3)
162 else if (vec >= 96)
163 mtdcr(uic3sr, UIC_MASK(vec));
164#endif
165}
166
167/*
168 * Install and free a interrupt handler.
169 */
170void pic_irq_enable(unsigned int vec)
171{
172
173 if ((vec >= 0) && (vec < 32))
174 mtdcr(uicer, mfdcr(uicer) | UIC_MASK(vec));
175#if (UIC_MAX > 1)
176 else if ((vec >= 32) && (vec < 64))
177 mtdcr(uic1er, mfdcr(uic1er) | UIC_MASK(vec));
178#endif
179#if (UIC_MAX > 2)
180 else if ((vec >= 64) && (vec < 96))
181 mtdcr(uic2er, mfdcr(uic2er) | UIC_MASK(vec));
182#endif
183#if (UIC_MAX > 3)
184 else if (vec >= 96)
185 mtdcr(uic3er, mfdcr(uic3er) | UIC_MASK(vec));
186#endif
187
188 debug("Install interrupt for vector %d ==> %p\n", vec, handler);
189}
190
191void pic_irq_disable(unsigned int vec)
192{
193
194 if ((vec >= 0) && (vec < 32))
195 mtdcr(uicer, mfdcr(uicer) & ~UIC_MASK(vec));
196#if (UIC_MAX > 1)
197 else if ((vec >= 32) && (vec < 64))
198 mtdcr(uic1er, mfdcr(uic1er) & ~UIC_MASK(vec));
199#endif
200#if (UIC_MAX > 2)
201 else if ((vec >= 64) && (vec < 96))
202 mtdcr(uic2er, mfdcr(uic2er) & ~UIC_MASK(vec));
203#endif
204#if (UIC_MAX > 3)
205 else if (vec >= 96)
206 mtdcr(uic3er, mfdcr(uic3er) & ~UIC_MASK(vec));
207#endif
208
209}