blob: d9b565468b609869bbd10c38fd09c1cd3b84f183 [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020015 * SPDX-License-Identifier: GPL-2.0+
wdenkf780aa22002-09-18 19:21:21 +000016 */
17
18#include <common.h>
19#include <watchdog.h>
20#include <command.h>
wdenkf780aa22002-09-18 19:21:21 +000021#include <asm/processor.h>
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +020022#include <asm/interrupt.h>
Stefan Roeseb36df562010-09-09 19:18:00 +020023#include <asm/ppc4xx.h>
wdenkf780aa22002-09-18 19:21:21 +000024#include <ppc_asm.tmpl>
25#include <commproc.h>
wdenkf780aa22002-09-18 19:21:21 +000026
Stefan Roesed1631fe2008-06-26 13:40:57 +020027DECLARE_GLOBAL_DATA_PTR;
wdenkf780aa22002-09-18 19:21:21 +000028
wdenkf780aa22002-09-18 19:21:21 +000029/*
30 * CPM interrupt vector functions.
31 */
32struct irq_action {
33 interrupt_handler_t *handler;
34 void *arg;
35 int count;
36};
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +020037static struct irq_action irq_vecs[IRQ_MAX];
wdenkf780aa22002-09-18 19:21:21 +000038
wdenkf780aa22002-09-18 19:21:21 +000039#if defined(CONFIG_440)
40
41/* SPRN changed in 440 */
42static __inline__ void set_evpr(unsigned long val)
43{
44 asm volatile("mtspr 0x03f,%0" : : "r" (val));
45}
46
47#else /* !defined(CONFIG_440) */
48
wdenkf780aa22002-09-18 19:21:21 +000049static __inline__ void set_pit(unsigned long val)
50{
51 asm volatile("mtpit %0" : : "r" (val));
52}
53
wdenkf780aa22002-09-18 19:21:21 +000054static __inline__ void set_evpr(unsigned long val)
55{
56 asm volatile("mtevpr %0" : : "r" (val));
57}
58#endif /* defined(CONFIG_440 */
59
wdenka8c7c702003-12-06 19:49:23 +000060int interrupt_init_cpu (unsigned *decrementer_count)
wdenkf780aa22002-09-18 19:21:21 +000061{
wdenkf780aa22002-09-18 19:21:21 +000062 int vec;
63 unsigned long val;
64
wdenka8c7c702003-12-06 19:49:23 +000065 /* decrementer is automatically reloaded */
66 *decrementer_count = 0;
wdenkd4ca31c2004-01-02 14:00:00 +000067
wdenkf780aa22002-09-18 19:21:21 +000068 /*
69 * Mark all irqs as free
70 */
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +020071 for (vec = 0; vec < IRQ_MAX; vec++) {
wdenkf780aa22002-09-18 19:21:21 +000072 irq_vecs[vec].handler = NULL;
73 irq_vecs[vec].arg = NULL;
74 irq_vecs[vec].count = 0;
wdenkf780aa22002-09-18 19:21:21 +000075 }
76
77#ifdef CONFIG_4xx
78 /*
79 * Init PIT
80 */
81#if defined(CONFIG_440)
Matthias Fuchs58ea1422009-07-22 17:27:56 +020082 val = mfspr( SPRN_TCR );
wdenkf780aa22002-09-18 19:21:21 +000083 val &= (~0x04400000); /* clear DIS & ARE */
Matthias Fuchs58ea1422009-07-22 17:27:56 +020084 mtspr( SPRN_TCR, val );
85 mtspr( SPRN_DEC, 0 ); /* Prevent exception after TSR clear*/
86 mtspr( SPRN_DECAR, 0 ); /* clear reload */
87 mtspr( SPRN_TSR, 0x08000000 ); /* clear DEC status */
stroese68e02362005-04-07 05:32:44 +000088 val = gd->bd->bi_intfreq/1000; /* 1 msec */
Matthias Fuchs58ea1422009-07-22 17:27:56 +020089 mtspr( SPRN_DECAR, val ); /* Set auto-reload value */
90 mtspr( SPRN_DEC, val ); /* Set inital val */
wdenkf780aa22002-09-18 19:21:21 +000091#else
92 set_pit(gd->bd->bi_intfreq / 1000);
93#endif
94#endif /* CONFIG_4xx */
95
96#ifdef CONFIG_ADCIOP
97 /*
98 * Init PIT
99 */
100 set_pit(66000);
101#endif
102
103 /*
104 * Enable PIT
105 */
Matthias Fuchs58ea1422009-07-22 17:27:56 +0200106 val = mfspr(SPRN_TCR);
wdenkf780aa22002-09-18 19:21:21 +0000107 val |= 0x04400000;
Matthias Fuchs58ea1422009-07-22 17:27:56 +0200108 mtspr(SPRN_TCR, val);
wdenkf780aa22002-09-18 19:21:21 +0000109
110 /*
111 * Set EVPR to 0
112 */
113 set_evpr(0x00000000);
114
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200115 /*
Stefan Roese60204d02008-07-18 12:24:41 +0200116 * Call uic or xilinx_irq pic_enable
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200117 */
118 pic_enable();
wdenkf780aa22002-09-18 19:21:21 +0000119
120 return (0);
121}
122
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200123void timer_interrupt_cpu(struct pt_regs *regs)
Stefan Roese56e41012008-02-19 22:07:57 +0100124{
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200125 /* nothing to do here */
Stefan Roese56e41012008-02-19 22:07:57 +0100126 return;
wdenkba56f622004-02-06 23:19:44 +0000127}
128
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200129void interrupt_run_handler(int vec)
130{
131 irq_vecs[vec].count++;
132
133 if (irq_vecs[vec].handler != NULL) {
134 /* call isr */
135 (*irq_vecs[vec].handler) (irq_vecs[vec].arg);
136 } else {
137 pic_irq_disable(vec);
138 printf("Masking bogus interrupt vector %d\n", vec);
139 }
140
141 pic_irq_ack(vec);
142 return;
143}
144
Stefan Roese56e41012008-02-19 22:07:57 +0100145void irq_install_handler(int vec, interrupt_handler_t * handler, void *arg)
wdenkf780aa22002-09-18 19:21:21 +0000146{
Stefan Roesec157d8e2005-08-01 16:41:48 +0200147 /*
Stefan Roese56e41012008-02-19 22:07:57 +0100148 * Print warning when replacing with a different irq vector
Stefan Roesec157d8e2005-08-01 16:41:48 +0200149 */
Stefan Roese56e41012008-02-19 22:07:57 +0100150 if ((irq_vecs[vec].handler != NULL) && (irq_vecs[vec].handler != handler)) {
151 printf("Interrupt vector %d: handler 0x%x replacing 0x%x\n",
152 vec, (uint) handler, (uint) irq_vecs[vec].handler);
wdenkf780aa22002-09-18 19:21:21 +0000153 }
Stefan Roese56e41012008-02-19 22:07:57 +0100154 irq_vecs[vec].handler = handler;
155 irq_vecs[vec].arg = arg;
wdenkf780aa22002-09-18 19:21:21 +0000156
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200157 pic_irq_enable(vec);
158 return;
wdenkf780aa22002-09-18 19:21:21 +0000159}
160
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200161void irq_free_handler(int vec)
wdenkf780aa22002-09-18 19:21:21 +0000162{
Stefan Roese56e41012008-02-19 22:07:57 +0100163 debug("Free interrupt for vector %d ==> %p\n",
164 vec, irq_vecs[vec].handler);
165
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200166 pic_irq_disable(vec);
wdenkf780aa22002-09-18 19:21:21 +0000167
Stefan Roese56e41012008-02-19 22:07:57 +0100168 irq_vecs[vec].handler = NULL;
169 irq_vecs[vec].arg = NULL;
wdenka8c7c702003-12-06 19:49:23 +0000170 return;
wdenkf780aa22002-09-18 19:21:21 +0000171}
172
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500173#if defined(CONFIG_CMD_IRQ)
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200174int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkf780aa22002-09-18 19:21:21 +0000175{
176 int vec;
177
Stefan Roese56e41012008-02-19 22:07:57 +0100178 printf ("Interrupt-Information:\n");
wdenkf780aa22002-09-18 19:21:21 +0000179 printf ("Nr Routine Arg Count\n");
180
Ricardo Ribalda Delgadod865fd02008-07-17 11:44:12 +0200181 for (vec = 0; vec < IRQ_MAX; vec++) {
wdenkf780aa22002-09-18 19:21:21 +0000182 if (irq_vecs[vec].handler != NULL) {
183 printf ("%02d %08lx %08lx %d\n",
184 vec,
185 (ulong)irq_vecs[vec].handler,
186 (ulong)irq_vecs[vec].arg,
187 irq_vecs[vec].count);
188 }
189 }
190
wdenkf780aa22002-09-18 19:21:21 +0000191 return 0;
192}
Jon Loeliger3a1ed1e2007-07-09 18:57:22 -0500193#endif