blob: 20f9664f060f56740c3dea81c284ac71484c007c [file] [log] [blame]
Christophe Leroy069fa832017-07-06 10:23:22 +02001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <mpc8xx.h>
10#include <mpc8xx_irq.h>
Christophe Leroy10ff63a2018-03-16 17:20:43 +010011#include <asm/cpm_8xx.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020012#include <asm/processor.h>
Christophe Leroy394f9b32017-07-06 10:33:13 +020013#include <asm/io.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020014
15/************************************************************************/
16
17/*
18 * CPM interrupt vector functions.
19 */
20struct interrupt_action {
21 interrupt_handler_t *handler;
22 void *arg;
23};
24
25static struct interrupt_action cpm_vecs[CPMVEC_NR];
26static struct interrupt_action irq_vecs[NR_IRQS];
27
Christophe Leroy48f896d2017-07-06 10:33:17 +020028static void cpm_interrupt_init(void);
29static void cpm_interrupt(void *regs);
Christophe Leroy069fa832017-07-06 10:23:22 +020030
31/************************************************************************/
32
Tom Rinice103982017-08-13 22:44:37 -040033void interrupt_init_cpu(unsigned *decrementer_count)
Christophe Leroy069fa832017-07-06 10:23:22 +020034{
Christophe Leroy394f9b32017-07-06 10:33:13 +020035 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +020036
Christophe Leroy48f896d2017-07-06 10:33:17 +020037 *decrementer_count = get_tbclk() / CONFIG_SYS_HZ;
Christophe Leroy069fa832017-07-06 10:23:22 +020038
39 /* disable all interrupts */
Christophe Leroy394f9b32017-07-06 10:33:13 +020040 out_be32(&immr->im_siu_conf.sc_simask, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +020041
42 /* Configure CPM interrupts */
Christophe Leroy48f896d2017-07-06 10:33:17 +020043 cpm_interrupt_init();
Christophe Leroy069fa832017-07-06 10:23:22 +020044}
45
46/************************************************************************/
47
48/*
49 * Handle external interrupts
50 */
Christophe Leroy48f896d2017-07-06 10:33:17 +020051void external_interrupt(struct pt_regs *regs)
Christophe Leroy069fa832017-07-06 10:23:22 +020052{
Christophe Leroy394f9b32017-07-06 10:33:13 +020053 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +020054 int irq;
Christophe Leroy394f9b32017-07-06 10:33:13 +020055 ulong simask;
Christophe Leroy069fa832017-07-06 10:23:22 +020056 ulong vec, v_bit;
57
58 /*
59 * read the SIVEC register and shift the bits down
60 * to get the irq number
61 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020062 vec = in_be32(&immr->im_siu_conf.sc_sivec);
Christophe Leroy069fa832017-07-06 10:23:22 +020063 irq = vec >> 26;
64 v_bit = 0x80000000UL >> irq;
65
66 /*
67 * Read Interrupt Mask Register and Mask Interrupts
68 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020069 simask = in_be32(&immr->im_siu_conf.sc_simask);
70 clrbits_be32(&immr->im_siu_conf.sc_simask, 0xFFFF0000 >> irq);
Christophe Leroy069fa832017-07-06 10:23:22 +020071
72 if (!(irq & 0x1)) { /* External Interrupt ? */
73 ulong siel;
74
75 /*
76 * Read Interrupt Edge/Level Register
77 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020078 siel = in_be32(&immr->im_siu_conf.sc_siel);
Christophe Leroy069fa832017-07-06 10:23:22 +020079
80 if (siel & v_bit) { /* edge triggered interrupt ? */
81 /*
82 * Rewrite SIPEND Register to clear interrupt
83 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020084 out_be32(&immr->im_siu_conf.sc_sipend, v_bit);
Christophe Leroy069fa832017-07-06 10:23:22 +020085 }
86 }
87
88 if (irq_vecs[irq].handler != NULL) {
Christophe Leroy48f896d2017-07-06 10:33:17 +020089 irq_vecs[irq].handler(irq_vecs[irq].arg);
Christophe Leroy069fa832017-07-06 10:23:22 +020090 } else {
Christophe Leroy48f896d2017-07-06 10:33:17 +020091 printf("\nBogus External Interrupt IRQ %d Vector %ld\n",
92 irq, vec);
Christophe Leroy069fa832017-07-06 10:23:22 +020093 /* turn off the bogus interrupt to avoid it from now */
94 simask &= ~v_bit;
95 }
96 /*
97 * Re-Enable old Interrupt Mask
98 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020099 out_be32(&immr->im_siu_conf.sc_simask, simask);
Christophe Leroy069fa832017-07-06 10:23:22 +0200100}
101
102/************************************************************************/
103
104/*
105 * CPM interrupt handler
106 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200107static void cpm_interrupt(void *regs)
Christophe Leroy069fa832017-07-06 10:23:22 +0200108{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200109 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200110 uint vec;
111
112 /*
113 * Get the vector by setting the ACK bit
114 * and then reading the register.
115 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200116 out_be16(&immr->im_cpic.cpic_civr, 1);
117 vec = in_be16(&immr->im_cpic.cpic_civr);
Christophe Leroy069fa832017-07-06 10:23:22 +0200118 vec >>= 11;
119
120 if (cpm_vecs[vec].handler != NULL) {
121 (*cpm_vecs[vec].handler) (cpm_vecs[vec].arg);
122 } else {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200123 clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
Christophe Leroy48f896d2017-07-06 10:33:17 +0200124 printf("Masking bogus CPM interrupt vector 0x%x\n", vec);
Christophe Leroy069fa832017-07-06 10:23:22 +0200125 }
126 /*
127 * After servicing the interrupt,
128 * we have to remove the status indicator.
129 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200130 setbits_be32(&immr->im_cpic.cpic_cisr, 1 << vec);
Christophe Leroy069fa832017-07-06 10:23:22 +0200131}
132
133/*
134 * The CPM can generate the error interrupt when there is a race
135 * condition between generating and masking interrupts. All we have
136 * to do is ACK it and return. This is a no-op function so we don't
137 * need any special tests in the interrupt handler.
138 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200139static void cpm_error_interrupt(void *dummy)
Christophe Leroy069fa832017-07-06 10:23:22 +0200140{
141}
142
143/************************************************************************/
144/*
145 * Install and free an interrupt handler
146 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200147void irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
Christophe Leroy069fa832017-07-06 10:23:22 +0200148{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200149 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200150
151 if ((vec & CPMVEC_OFFSET) != 0) {
152 /* CPM interrupt */
153 vec &= 0xffff;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200154 if (cpm_vecs[vec].handler != NULL)
155 printf("CPM interrupt 0x%x replacing 0x%x\n",
156 (uint)handler, (uint)cpm_vecs[vec].handler);
Christophe Leroy069fa832017-07-06 10:23:22 +0200157 cpm_vecs[vec].handler = handler;
158 cpm_vecs[vec].arg = arg;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200159 setbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
Christophe Leroy069fa832017-07-06 10:23:22 +0200160 } else {
161 /* SIU interrupt */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200162 if (irq_vecs[vec].handler != NULL)
163 printf("SIU interrupt %d 0x%x replacing 0x%x\n",
164 vec, (uint)handler, (uint)cpm_vecs[vec].handler);
Christophe Leroy069fa832017-07-06 10:23:22 +0200165 irq_vecs[vec].handler = handler;
166 irq_vecs[vec].arg = arg;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200167 setbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec));
Christophe Leroy069fa832017-07-06 10:23:22 +0200168 }
169}
170
Christophe Leroy48f896d2017-07-06 10:33:17 +0200171void irq_free_handler(int vec)
Christophe Leroy069fa832017-07-06 10:23:22 +0200172{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200173 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200174
175 if ((vec & CPMVEC_OFFSET) != 0) {
176 /* CPM interrupt */
177 vec &= 0xffff;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200178 clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
Christophe Leroy069fa832017-07-06 10:23:22 +0200179 cpm_vecs[vec].handler = NULL;
180 cpm_vecs[vec].arg = NULL;
181 } else {
182 /* SIU interrupt */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200183 clrbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec));
Christophe Leroy069fa832017-07-06 10:23:22 +0200184 irq_vecs[vec].handler = NULL;
185 irq_vecs[vec].arg = NULL;
186 }
187}
188
189/************************************************************************/
190
Christophe Leroy48f896d2017-07-06 10:33:17 +0200191static void cpm_interrupt_init(void)
Christophe Leroy069fa832017-07-06 10:23:22 +0200192{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200193 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
194 uint cicr;
Christophe Leroy069fa832017-07-06 10:23:22 +0200195
196 /*
197 * Initialize the CPM interrupt controller.
198 */
199
Christophe Leroy394f9b32017-07-06 10:33:13 +0200200 cicr = CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1 |
201 ((CPM_INTERRUPT / 2) << 13) | CICR_HP_MASK;
Christophe Leroy069fa832017-07-06 10:23:22 +0200202
Christophe Leroy394f9b32017-07-06 10:33:13 +0200203 out_be32(&immr->im_cpic.cpic_cicr, cicr);
204 out_be32(&immr->im_cpic.cpic_cimr, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200205
206 /*
207 * Install the error handler.
208 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200209 irq_install_handler(CPMVEC_ERROR, cpm_error_interrupt, NULL);
Christophe Leroy069fa832017-07-06 10:23:22 +0200210
Christophe Leroy394f9b32017-07-06 10:33:13 +0200211 setbits_be32(&immr->im_cpic.cpic_cicr, CICR_IEN);
Christophe Leroy069fa832017-07-06 10:23:22 +0200212
213 /*
214 * Install the cpm interrupt handler
215 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200216 irq_install_handler(CPM_INTERRUPT, cpm_interrupt, NULL);
Christophe Leroy069fa832017-07-06 10:23:22 +0200217}
218
219/************************************************************************/
220
221/*
222 * timer_interrupt - gets called when the decrementer overflows,
223 * with interrupts disabled.
224 * Trivial implementation - no need to be really accurate.
225 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200226void timer_interrupt_cpu(struct pt_regs *regs)
Christophe Leroy069fa832017-07-06 10:23:22 +0200227{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200228 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200229
230 /* Reset Timer Expired and Timers Interrupt Status */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200231 out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY);
Christophe Leroy069fa832017-07-06 10:23:22 +0200232 __asm__ ("nop");
233 /*
234 Clear TEXPS (and TMIST on older chips). SPLSS (on older
235 chips) is cleared too.
236
237 Bitwise OR is a read-modify-write operation so ALL bits
238 which are cleared by writing `1' would be cleared by
239 operations like
240
241 immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS;
242
243 The same can be achieved by simple writing of the PLPRCR
244 to itself. If a bit value should be preserved, read the
245 register, ZERO the bit and write, not OR, the result back.
246 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200247 setbits_be32(&immr->im_clkrst.car_plprcr, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200248}
249
250/************************************************************************/