blob: d0bca92f990633b6dc5736928a7475cf680de70a [file] [log] [blame]
wdenkf780aa22002-09-18 19:21:21 +00001/*
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 *
wdenkba56f622004-02-06 23:19:44 +00008 * (C) Copyright 2003 (440GX port)
9 * Travis B. Sawyer, Sandburst Corporation, tsawyer@sandburst.com
10 *
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +020011 * (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 *
wdenkf780aa22002-09-18 19:21:21 +000015 * 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>
wdenkf780aa22002-09-18 19:21:21 +000037#include <asm/processor.h>
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +020038#include <asm/interrupt.h>
Stefan Roeseb36df562010-09-09 19:18:00 +020039#include <asm/ppc4xx.h>
wdenkf780aa22002-09-18 19:21:21 +000040#include <ppc_asm.tmpl>
41#include <commproc.h>
wdenkf780aa22002-09-18 19:21:21 +000042
Stefan Roesed1631fe2008-06-26 13:40:57 +020043DECLARE_GLOBAL_DATA_PTR;
wdenkf780aa22002-09-18 19:21:21 +000044
wdenkf780aa22002-09-18 19:21:21 +000045/*
46 * CPM interrupt vector functions.
47 */
48struct irq_action {
49 interrupt_handler_t *handler;
50 void *arg;
51 int count;
52};
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +020053static struct irq_action irq_vecs[IRQ_MAX];
wdenkf780aa22002-09-18 19:21:21 +000054
wdenkf780aa22002-09-18 19:21:21 +000055#if defined(CONFIG_440)
56
57/* SPRN changed in 440 */
58static __inline__ void set_evpr(unsigned long val)
59{
60 asm volatile("mtspr 0x03f,%0" : : "r" (val));
61}
62
63#else /* !defined(CONFIG_440) */
64
wdenkf780aa22002-09-18 19:21:21 +000065static __inline__ void set_pit(unsigned long val)
66{
67 asm volatile("mtpit %0" : : "r" (val));
68}
69
wdenkf780aa22002-09-18 19:21:21 +000070static __inline__ void set_evpr(unsigned long val)
71{
72 asm volatile("mtevpr %0" : : "r" (val));
73}
74#endif /* defined(CONFIG_440 */
75
wdenka8c7c702003-12-06 19:49:23 +000076int interrupt_init_cpu (unsigned *decrementer_count)
wdenkf780aa22002-09-18 19:21:21 +000077{
wdenkf780aa22002-09-18 19:21:21 +000078 int vec;
79 unsigned long val;
80
wdenka8c7c702003-12-06 19:49:23 +000081 /* decrementer is automatically reloaded */
82 *decrementer_count = 0;
wdenkd4ca31c2004-01-02 14:00:00 +000083
wdenkf780aa22002-09-18 19:21:21 +000084 /*
85 * Mark all irqs as free
86 */
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +020087 for (vec = 0; vec < IRQ_MAX; vec++) {
wdenkf780aa22002-09-18 19:21:21 +000088 irq_vecs[vec].handler = NULL;
89 irq_vecs[vec].arg = NULL;
90 irq_vecs[vec].count = 0;
wdenkf780aa22002-09-18 19:21:21 +000091 }
92
93#ifdef CONFIG_4xx
94 /*
95 * Init PIT
96 */
97#if defined(CONFIG_440)
Matthias Fuchs58ea1422009-07-22 17:27:56 +020098 val = mfspr( SPRN_TCR );
wdenkf780aa22002-09-18 19:21:21 +000099 val &= (~0x04400000); /* clear DIS & ARE */
Matthias Fuchs58ea1422009-07-22 17:27:56 +0200100 mtspr( SPRN_TCR, val );
101 mtspr( SPRN_DEC, 0 ); /* Prevent exception after TSR clear*/
102 mtspr( SPRN_DECAR, 0 ); /* clear reload */
103 mtspr( SPRN_TSR, 0x08000000 ); /* clear DEC status */
stroese68e02362005-04-07 05:32:44 +0000104 val = gd->bd->bi_intfreq/1000; /* 1 msec */
Matthias Fuchs58ea1422009-07-22 17:27:56 +0200105 mtspr( SPRN_DECAR, val ); /* Set auto-reload value */
106 mtspr( SPRN_DEC, val ); /* Set inital val */
wdenkf780aa22002-09-18 19:21:21 +0000107#else
108 set_pit(gd->bd->bi_intfreq / 1000);
109#endif
110#endif /* CONFIG_4xx */
111
112#ifdef CONFIG_ADCIOP
113 /*
114 * Init PIT
115 */
116 set_pit(66000);
117#endif
118
119 /*
120 * Enable PIT
121 */
Matthias Fuchs58ea1422009-07-22 17:27:56 +0200122 val = mfspr(SPRN_TCR);
wdenkf780aa22002-09-18 19:21:21 +0000123 val |= 0x04400000;
Matthias Fuchs58ea1422009-07-22 17:27:56 +0200124 mtspr(SPRN_TCR, val);
wdenkf780aa22002-09-18 19:21:21 +0000125
126 /*
127 * Set EVPR to 0
128 */
129 set_evpr(0x00000000);
130
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200131 /*
Stefan Roese60204d02008-07-18 12:24:41 +0200132 * Call uic or xilinx_irq pic_enable
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200133 */
134 pic_enable();
wdenkf780aa22002-09-18 19:21:21 +0000135
136 return (0);
137}
138
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200139void timer_interrupt_cpu(struct pt_regs *regs)
Stefan Roese56e41012008-02-19 22:07:57 +0100140{
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200141 /* nothing to do here */
Stefan Roese56e41012008-02-19 22:07:57 +0100142 return;
wdenkba56f622004-02-06 23:19:44 +0000143}
144
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200145void interrupt_run_handler(int vec)
146{
147 irq_vecs[vec].count++;
148
149 if (irq_vecs[vec].handler != NULL) {
150 /* call isr */
151 (*irq_vecs[vec].handler) (irq_vecs[vec].arg);
152 } else {
153 pic_irq_disable(vec);
154 printf("Masking bogus interrupt vector %d\n", vec);
155 }
156
157 pic_irq_ack(vec);
158 return;
159}
160
Stefan Roese56e41012008-02-19 22:07:57 +0100161void irq_install_handler(int vec, interrupt_handler_t * handler, void *arg)
wdenkf780aa22002-09-18 19:21:21 +0000162{
Stefan Roesec157d8e2005-08-01 16:41:48 +0200163 /*
Stefan Roese56e41012008-02-19 22:07:57 +0100164 * Print warning when replacing with a different irq vector
Stefan Roesec157d8e2005-08-01 16:41:48 +0200165 */
Stefan Roese56e41012008-02-19 22:07:57 +0100166 if ((irq_vecs[vec].handler != NULL) && (irq_vecs[vec].handler != handler)) {
167 printf("Interrupt vector %d: handler 0x%x replacing 0x%x\n",
168 vec, (uint) handler, (uint) irq_vecs[vec].handler);
wdenkf780aa22002-09-18 19:21:21 +0000169 }
Stefan Roese56e41012008-02-19 22:07:57 +0100170 irq_vecs[vec].handler = handler;
171 irq_vecs[vec].arg = arg;
wdenkf780aa22002-09-18 19:21:21 +0000172
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200173 pic_irq_enable(vec);
174 return;
wdenkf780aa22002-09-18 19:21:21 +0000175}
176
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200177void irq_free_handler(int vec)
wdenkf780aa22002-09-18 19:21:21 +0000178{
Stefan Roese56e41012008-02-19 22:07:57 +0100179 debug("Free interrupt for vector %d ==> %p\n",
180 vec, irq_vecs[vec].handler);
181
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200182 pic_irq_disable(vec);
wdenkf780aa22002-09-18 19:21:21 +0000183
Stefan Roese56e41012008-02-19 22:07:57 +0100184 irq_vecs[vec].handler = NULL;
185 irq_vecs[vec].arg = NULL;
wdenka8c7c702003-12-06 19:49:23 +0000186 return;
wdenkf780aa22002-09-18 19:21:21 +0000187}
188
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500189#if defined(CONFIG_CMD_IRQ)
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200190int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkf780aa22002-09-18 19:21:21 +0000191{
192 int vec;
193
Stefan Roese56e41012008-02-19 22:07:57 +0100194 printf ("Interrupt-Information:\n");
wdenkf780aa22002-09-18 19:21:21 +0000195 printf ("Nr Routine Arg Count\n");
196
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200197 for (vec = 0; vec < IRQ_MAX; vec++) {
wdenkf780aa22002-09-18 19:21:21 +0000198 if (irq_vecs[vec].handler != NULL) {
199 printf ("%02d %08lx %08lx %d\n",
200 vec,
201 (ulong)irq_vecs[vec].handler,
202 (ulong)irq_vecs[vec].arg,
203 irq_vecs[vec].count);
204 }
205 }
206
wdenkf780aa22002-09-18 19:21:21 +0000207 return 0;
208}
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500209#endif