blob: 45997d6eae0640dee7e36cffdcf1460afd336379 [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 *
wdenk544e9732004-02-06 23:19:44 +00008 * (C) Copyright 2003 (440GX port)
9 * Travis B. Sawyer, Sandburst Corporation, tsawyer@sandburst.com
10 *
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020011 * (C) Copyright 2008 (PPC440X05 port for Virtex 5 FX)
Ricardo Ribalda Delgado5712d042016-01-26 11:24:08 +010012 * Ricardo Ribalda-Universidad Autonoma de Madrid-ricardo.ribalda@gmail.com
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020013 * Work supported by Qtechnology (htpp://qtec.com)
14 *
Wolfgang Denkd79de1d2013-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 Delgado95c50202008-07-17 11:44:12 +020022#include <asm/interrupt.h>
Stefan Roese247e9d72010-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 Roese01edcea2008-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 Delgado95c50202008-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
wdenkc0aa5c52003-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
wdenkc0aa5c52003-12-06 19:49:23 +000065 /* decrementer is automatically reloaded */
66 *decrementer_count = 0;
wdenk1ebf41e2004-01-02 14:00:00 +000067
wdenkf780aa22002-09-18 19:21:21 +000068 /*
69 * Mark all irqs as free
70 */
Ricardo Ribalda Delgado95c50202008-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 Fuchs730b2d22009-07-22 17:27:56 +020082 val = mfspr( SPRN_TCR );
wdenkf780aa22002-09-18 19:21:21 +000083 val &= (~0x04400000); /* clear DIS & ARE */
Matthias Fuchs730b2d22009-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 */
stroese4b31de82005-04-07 05:32:44 +000088 val = gd->bd->bi_intfreq/1000; /* 1 msec */
Matthias Fuchs730b2d22009-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 Fuchs730b2d22009-07-22 17:27:56 +0200106 val = mfspr(SPRN_TCR);
wdenkf780aa22002-09-18 19:21:21 +0000107 val |= 0x04400000;
Matthias Fuchs730b2d22009-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 Delgado95c50202008-07-17 11:44:12 +0200115 /*
Stefan Roese1fbbe602008-07-18 12:24:41 +0200116 * Call uic or xilinx_irq pic_enable
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200117 */
118 pic_enable();
wdenkf780aa22002-09-18 19:21:21 +0000119
120 return (0);
121}
122
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200123void timer_interrupt_cpu(struct pt_regs *regs)
wdenk544e9732004-02-06 23:19:44 +0000124{
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200125 /* nothing to do here */
126 return;
wdenkf780aa22002-09-18 19:21:21 +0000127}
wdenkf780aa22002-09-18 19:21:21 +0000128
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200129void interrupt_run_handler(int vec)
wdenk544e9732004-02-06 23:19:44 +0000130{
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200131 irq_vecs[vec].count++;
wdenk544e9732004-02-06 23:19:44 +0000132
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200133 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 }
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200140
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200141 pic_irq_ack(vec);
Stefan Roesee4790122008-02-19 22:07:57 +0100142 return;
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200143}
wdenkf780aa22002-09-18 19:21:21 +0000144
Stefan Roesee4790122008-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 Roese326c9712005-08-01 16:41:48 +0200147 /*
Stefan Roesee4790122008-02-19 22:07:57 +0100148 * Print warning when replacing with a different irq vector
Stefan Roese326c9712005-08-01 16:41:48 +0200149 */
Stefan Roesee4790122008-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 Roesee4790122008-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 Delgado95c50202008-07-17 11:44:12 +0200157 pic_irq_enable(vec);
158 return;
wdenkf780aa22002-09-18 19:21:21 +0000159}
160
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200161void irq_free_handler(int vec)
wdenkf780aa22002-09-18 19:21:21 +0000162{
Stefan Roesee4790122008-02-19 22:07:57 +0100163 debug("Free interrupt for vector %d ==> %p\n",
164 vec, irq_vecs[vec].handler);
wdenkf780aa22002-09-18 19:21:21 +0000165
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200166 pic_irq_disable(vec);
wdenkf780aa22002-09-18 19:21:21 +0000167
Stefan Roesee4790122008-02-19 22:07:57 +0100168 irq_vecs[vec].handler = NULL;
169 irq_vecs[vec].arg = NULL;
wdenkc0aa5c52003-12-06 19:49:23 +0000170 return;
wdenkf780aa22002-09-18 19:21:21 +0000171}
172
Jon Loeligera5217742007-07-09 18:57:22 -0500173#if defined(CONFIG_CMD_IRQ)
Wolfgang Denk6262d0212010-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 Roesee4790122008-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 Delgado95c50202008-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
wdenk544e9732004-02-06 23:19:44 +0000191 return 0;
192}
Jon Loeligera5217742007-07-09 18:57:22 -0500193#endif