blob: 3efe8956ec57883823eb316925e59b685e309088 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Leroy907208c2017-07-06 10:23:22 +02002/*
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Christophe Leroy907208c2017-07-06 10:23:22 +02005 */
6
7#include <common.h>
Simon Glassc30b7ad2019-11-14 12:57:41 -07008#include <irq_func.h>
Christophe Leroy907208c2017-07-06 10:23:22 +02009#include <mpc8xx.h>
10#include <mpc8xx_irq.h>
Simon Glass049f8d62019-12-28 10:44:59 -070011#include <time.h>
Christophe Leroy18f8d4c2018-03-16 17:20:43 +010012#include <asm/cpm_8xx.h>
Christophe Leroy907208c2017-07-06 10:23:22 +020013#include <asm/processor.h>
Christophe Leroyba3da732017-07-06 10:33:13 +020014#include <asm/io.h>
Christophe Leroy907208c2017-07-06 10:23:22 +020015
16/************************************************************************/
17
18/*
19 * CPM interrupt vector functions.
20 */
21struct interrupt_action {
22 interrupt_handler_t *handler;
23 void *arg;
24};
25
26static struct interrupt_action cpm_vecs[CPMVEC_NR];
27static struct interrupt_action irq_vecs[NR_IRQS];
28
Christophe Leroy70fd0712017-07-06 10:33:17 +020029static void cpm_interrupt_init(void);
30static void cpm_interrupt(void *regs);
Christophe Leroy907208c2017-07-06 10:23:22 +020031
32/************************************************************************/
33
Tom Rinideff9b12017-08-13 22:44:37 -040034void interrupt_init_cpu(unsigned *decrementer_count)
Christophe Leroy907208c2017-07-06 10:23:22 +020035{
Christophe Leroyba3da732017-07-06 10:33:13 +020036 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy907208c2017-07-06 10:23:22 +020037
Christophe Leroy70fd0712017-07-06 10:33:17 +020038 *decrementer_count = get_tbclk() / CONFIG_SYS_HZ;
Christophe Leroy907208c2017-07-06 10:23:22 +020039
40 /* disable all interrupts */
Christophe Leroyba3da732017-07-06 10:33:13 +020041 out_be32(&immr->im_siu_conf.sc_simask, 0);
Christophe Leroy907208c2017-07-06 10:23:22 +020042
43 /* Configure CPM interrupts */
Christophe Leroy70fd0712017-07-06 10:33:17 +020044 cpm_interrupt_init();
Christophe Leroy907208c2017-07-06 10:23:22 +020045}
46
47/************************************************************************/
48
49/*
50 * Handle external interrupts
51 */
Christophe Leroy70fd0712017-07-06 10:33:17 +020052void external_interrupt(struct pt_regs *regs)
Christophe Leroy907208c2017-07-06 10:23:22 +020053{
Christophe Leroyba3da732017-07-06 10:33:13 +020054 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy907208c2017-07-06 10:23:22 +020055 int irq;
Christophe Leroyba3da732017-07-06 10:33:13 +020056 ulong simask;
Christophe Leroy907208c2017-07-06 10:23:22 +020057 ulong vec, v_bit;
58
59 /*
60 * read the SIVEC register and shift the bits down
61 * to get the irq number
62 */
Christophe Leroyba3da732017-07-06 10:33:13 +020063 vec = in_be32(&immr->im_siu_conf.sc_sivec);
Christophe Leroy907208c2017-07-06 10:23:22 +020064 irq = vec >> 26;
65 v_bit = 0x80000000UL >> irq;
66
67 /*
68 * Read Interrupt Mask Register and Mask Interrupts
69 */
Christophe Leroyba3da732017-07-06 10:33:13 +020070 simask = in_be32(&immr->im_siu_conf.sc_simask);
71 clrbits_be32(&immr->im_siu_conf.sc_simask, 0xFFFF0000 >> irq);
Christophe Leroy907208c2017-07-06 10:23:22 +020072
73 if (!(irq & 0x1)) { /* External Interrupt ? */
74 ulong siel;
75
76 /*
77 * Read Interrupt Edge/Level Register
78 */
Christophe Leroyba3da732017-07-06 10:33:13 +020079 siel = in_be32(&immr->im_siu_conf.sc_siel);
Christophe Leroy907208c2017-07-06 10:23:22 +020080
81 if (siel & v_bit) { /* edge triggered interrupt ? */
82 /*
83 * Rewrite SIPEND Register to clear interrupt
84 */
Christophe Leroyba3da732017-07-06 10:33:13 +020085 out_be32(&immr->im_siu_conf.sc_sipend, v_bit);
Christophe Leroy907208c2017-07-06 10:23:22 +020086 }
87 }
88
89 if (irq_vecs[irq].handler != NULL) {
Christophe Leroy70fd0712017-07-06 10:33:17 +020090 irq_vecs[irq].handler(irq_vecs[irq].arg);
Christophe Leroy907208c2017-07-06 10:23:22 +020091 } else {
Christophe Leroy70fd0712017-07-06 10:33:17 +020092 printf("\nBogus External Interrupt IRQ %d Vector %ld\n",
93 irq, vec);
Christophe Leroy907208c2017-07-06 10:23:22 +020094 /* turn off the bogus interrupt to avoid it from now */
95 simask &= ~v_bit;
96 }
97 /*
98 * Re-Enable old Interrupt Mask
99 */
Christophe Leroyba3da732017-07-06 10:33:13 +0200100 out_be32(&immr->im_siu_conf.sc_simask, simask);
Christophe Leroy907208c2017-07-06 10:23:22 +0200101}
102
103/************************************************************************/
104
105/*
106 * CPM interrupt handler
107 */
Christophe Leroy70fd0712017-07-06 10:33:17 +0200108static void cpm_interrupt(void *regs)
Christophe Leroy907208c2017-07-06 10:23:22 +0200109{
Christophe Leroyba3da732017-07-06 10:33:13 +0200110 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy907208c2017-07-06 10:23:22 +0200111 uint vec;
112
113 /*
114 * Get the vector by setting the ACK bit
115 * and then reading the register.
116 */
Christophe Leroyba3da732017-07-06 10:33:13 +0200117 out_be16(&immr->im_cpic.cpic_civr, 1);
118 vec = in_be16(&immr->im_cpic.cpic_civr);
Christophe Leroy907208c2017-07-06 10:23:22 +0200119 vec >>= 11;
120
121 if (cpm_vecs[vec].handler != NULL) {
122 (*cpm_vecs[vec].handler) (cpm_vecs[vec].arg);
123 } else {
Christophe Leroyba3da732017-07-06 10:33:13 +0200124 clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
Christophe Leroy70fd0712017-07-06 10:33:17 +0200125 printf("Masking bogus CPM interrupt vector 0x%x\n", vec);
Christophe Leroy907208c2017-07-06 10:23:22 +0200126 }
127 /*
128 * After servicing the interrupt,
129 * we have to remove the status indicator.
130 */
Christophe Leroyba3da732017-07-06 10:33:13 +0200131 setbits_be32(&immr->im_cpic.cpic_cisr, 1 << vec);
Christophe Leroy907208c2017-07-06 10:23:22 +0200132}
133
134/*
135 * The CPM can generate the error interrupt when there is a race
136 * condition between generating and masking interrupts. All we have
137 * to do is ACK it and return. This is a no-op function so we don't
138 * need any special tests in the interrupt handler.
139 */
Christophe Leroy70fd0712017-07-06 10:33:17 +0200140static void cpm_error_interrupt(void *dummy)
Christophe Leroy907208c2017-07-06 10:23:22 +0200141{
142}
143
144/************************************************************************/
145/*
146 * Install and free an interrupt handler
147 */
Christophe Leroy70fd0712017-07-06 10:33:17 +0200148void irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
Christophe Leroy907208c2017-07-06 10:23:22 +0200149{
Christophe Leroyba3da732017-07-06 10:33:13 +0200150 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy907208c2017-07-06 10:23:22 +0200151
152 if ((vec & CPMVEC_OFFSET) != 0) {
153 /* CPM interrupt */
154 vec &= 0xffff;
Christophe Leroy70fd0712017-07-06 10:33:17 +0200155 if (cpm_vecs[vec].handler != NULL)
156 printf("CPM interrupt 0x%x replacing 0x%x\n",
157 (uint)handler, (uint)cpm_vecs[vec].handler);
Christophe Leroy907208c2017-07-06 10:23:22 +0200158 cpm_vecs[vec].handler = handler;
159 cpm_vecs[vec].arg = arg;
Christophe Leroyba3da732017-07-06 10:33:13 +0200160 setbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
Christophe Leroy907208c2017-07-06 10:23:22 +0200161 } else {
162 /* SIU interrupt */
Christophe Leroy70fd0712017-07-06 10:33:17 +0200163 if (irq_vecs[vec].handler != NULL)
164 printf("SIU interrupt %d 0x%x replacing 0x%x\n",
165 vec, (uint)handler, (uint)cpm_vecs[vec].handler);
Christophe Leroy907208c2017-07-06 10:23:22 +0200166 irq_vecs[vec].handler = handler;
167 irq_vecs[vec].arg = arg;
Christophe Leroyba3da732017-07-06 10:33:13 +0200168 setbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec));
Christophe Leroy907208c2017-07-06 10:23:22 +0200169 }
170}
171
Christophe Leroy70fd0712017-07-06 10:33:17 +0200172void irq_free_handler(int vec)
Christophe Leroy907208c2017-07-06 10:23:22 +0200173{
Christophe Leroyba3da732017-07-06 10:33:13 +0200174 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy907208c2017-07-06 10:23:22 +0200175
176 if ((vec & CPMVEC_OFFSET) != 0) {
177 /* CPM interrupt */
178 vec &= 0xffff;
Christophe Leroyba3da732017-07-06 10:33:13 +0200179 clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
Christophe Leroy907208c2017-07-06 10:23:22 +0200180 cpm_vecs[vec].handler = NULL;
181 cpm_vecs[vec].arg = NULL;
182 } else {
183 /* SIU interrupt */
Christophe Leroyba3da732017-07-06 10:33:13 +0200184 clrbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec));
Christophe Leroy907208c2017-07-06 10:23:22 +0200185 irq_vecs[vec].handler = NULL;
186 irq_vecs[vec].arg = NULL;
187 }
188}
189
190/************************************************************************/
191
Christophe Leroy70fd0712017-07-06 10:33:17 +0200192static void cpm_interrupt_init(void)
Christophe Leroy907208c2017-07-06 10:23:22 +0200193{
Christophe Leroyba3da732017-07-06 10:33:13 +0200194 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
195 uint cicr;
Christophe Leroy907208c2017-07-06 10:23:22 +0200196
197 /*
198 * Initialize the CPM interrupt controller.
199 */
200
Christophe Leroyba3da732017-07-06 10:33:13 +0200201 cicr = CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1 |
202 ((CPM_INTERRUPT / 2) << 13) | CICR_HP_MASK;
Christophe Leroy907208c2017-07-06 10:23:22 +0200203
Christophe Leroyba3da732017-07-06 10:33:13 +0200204 out_be32(&immr->im_cpic.cpic_cicr, cicr);
205 out_be32(&immr->im_cpic.cpic_cimr, 0);
Christophe Leroy907208c2017-07-06 10:23:22 +0200206
207 /*
208 * Install the error handler.
209 */
Christophe Leroy70fd0712017-07-06 10:33:17 +0200210 irq_install_handler(CPMVEC_ERROR, cpm_error_interrupt, NULL);
Christophe Leroy907208c2017-07-06 10:23:22 +0200211
Christophe Leroyba3da732017-07-06 10:33:13 +0200212 setbits_be32(&immr->im_cpic.cpic_cicr, CICR_IEN);
Christophe Leroy907208c2017-07-06 10:23:22 +0200213
214 /*
215 * Install the cpm interrupt handler
216 */
Christophe Leroy70fd0712017-07-06 10:33:17 +0200217 irq_install_handler(CPM_INTERRUPT, cpm_interrupt, NULL);
Christophe Leroy907208c2017-07-06 10:23:22 +0200218}
219
220/************************************************************************/
221
222/*
223 * timer_interrupt - gets called when the decrementer overflows,
224 * with interrupts disabled.
225 * Trivial implementation - no need to be really accurate.
226 */
Christophe Leroy70fd0712017-07-06 10:33:17 +0200227void timer_interrupt_cpu(struct pt_regs *regs)
Christophe Leroy907208c2017-07-06 10:23:22 +0200228{
Christophe Leroyba3da732017-07-06 10:33:13 +0200229 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy907208c2017-07-06 10:23:22 +0200230
231 /* Reset Timer Expired and Timers Interrupt Status */
Christophe Leroyba3da732017-07-06 10:33:13 +0200232 out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY);
Christophe Leroy907208c2017-07-06 10:23:22 +0200233 __asm__ ("nop");
234 /*
235 Clear TEXPS (and TMIST on older chips). SPLSS (on older
236 chips) is cleared too.
237
238 Bitwise OR is a read-modify-write operation so ALL bits
239 which are cleared by writing `1' would be cleared by
240 operations like
241
242 immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS;
243
244 The same can be achieved by simple writing of the PLPRCR
245 to itself. If a bit value should be preserved, read the
246 register, ZERO the bit and write, not OR, the result back.
247 */
Christophe Leroyba3da732017-07-06 10:33:13 +0200248 setbits_be32(&immr->im_clkrst.car_plprcr, 0);
Christophe Leroy907208c2017-07-06 10:23:22 +0200249}
250
251/************************************************************************/