blob: 26aa7a56455ca46d882f30acc42ce6de157157d5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Leroy069fa832017-07-06 10:23:22 +02002/*
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Christophe Leroy069fa832017-07-06 10:23:22 +02005 */
6
7#include <common.h>
8#include <mpc8xx.h>
9#include <mpc8xx_irq.h>
Christophe Leroy10ff63a2018-03-16 17:20:43 +010010#include <asm/cpm_8xx.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020011#include <asm/processor.h>
Christophe Leroy394f9b32017-07-06 10:33:13 +020012#include <asm/io.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020013
14/************************************************************************/
15
16/*
17 * CPM interrupt vector functions.
18 */
19struct interrupt_action {
20 interrupt_handler_t *handler;
21 void *arg;
22};
23
24static struct interrupt_action cpm_vecs[CPMVEC_NR];
25static struct interrupt_action irq_vecs[NR_IRQS];
26
Christophe Leroy48f896d2017-07-06 10:33:17 +020027static void cpm_interrupt_init(void);
28static void cpm_interrupt(void *regs);
Christophe Leroy069fa832017-07-06 10:23:22 +020029
30/************************************************************************/
31
Tom Rinice103982017-08-13 22:44:37 -040032void interrupt_init_cpu(unsigned *decrementer_count)
Christophe Leroy069fa832017-07-06 10:23:22 +020033{
Christophe Leroy394f9b32017-07-06 10:33:13 +020034 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +020035
Christophe Leroy48f896d2017-07-06 10:33:17 +020036 *decrementer_count = get_tbclk() / CONFIG_SYS_HZ;
Christophe Leroy069fa832017-07-06 10:23:22 +020037
38 /* disable all interrupts */
Christophe Leroy394f9b32017-07-06 10:33:13 +020039 out_be32(&immr->im_siu_conf.sc_simask, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +020040
41 /* Configure CPM interrupts */
Christophe Leroy48f896d2017-07-06 10:33:17 +020042 cpm_interrupt_init();
Christophe Leroy069fa832017-07-06 10:23:22 +020043}
44
45/************************************************************************/
46
47/*
48 * Handle external interrupts
49 */
Christophe Leroy48f896d2017-07-06 10:33:17 +020050void external_interrupt(struct pt_regs *regs)
Christophe Leroy069fa832017-07-06 10:23:22 +020051{
Christophe Leroy394f9b32017-07-06 10:33:13 +020052 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +020053 int irq;
Christophe Leroy394f9b32017-07-06 10:33:13 +020054 ulong simask;
Christophe Leroy069fa832017-07-06 10:23:22 +020055 ulong vec, v_bit;
56
57 /*
58 * read the SIVEC register and shift the bits down
59 * to get the irq number
60 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020061 vec = in_be32(&immr->im_siu_conf.sc_sivec);
Christophe Leroy069fa832017-07-06 10:23:22 +020062 irq = vec >> 26;
63 v_bit = 0x80000000UL >> irq;
64
65 /*
66 * Read Interrupt Mask Register and Mask Interrupts
67 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020068 simask = in_be32(&immr->im_siu_conf.sc_simask);
69 clrbits_be32(&immr->im_siu_conf.sc_simask, 0xFFFF0000 >> irq);
Christophe Leroy069fa832017-07-06 10:23:22 +020070
71 if (!(irq & 0x1)) { /* External Interrupt ? */
72 ulong siel;
73
74 /*
75 * Read Interrupt Edge/Level Register
76 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020077 siel = in_be32(&immr->im_siu_conf.sc_siel);
Christophe Leroy069fa832017-07-06 10:23:22 +020078
79 if (siel & v_bit) { /* edge triggered interrupt ? */
80 /*
81 * Rewrite SIPEND Register to clear interrupt
82 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020083 out_be32(&immr->im_siu_conf.sc_sipend, v_bit);
Christophe Leroy069fa832017-07-06 10:23:22 +020084 }
85 }
86
87 if (irq_vecs[irq].handler != NULL) {
Christophe Leroy48f896d2017-07-06 10:33:17 +020088 irq_vecs[irq].handler(irq_vecs[irq].arg);
Christophe Leroy069fa832017-07-06 10:23:22 +020089 } else {
Christophe Leroy48f896d2017-07-06 10:33:17 +020090 printf("\nBogus External Interrupt IRQ %d Vector %ld\n",
91 irq, vec);
Christophe Leroy069fa832017-07-06 10:23:22 +020092 /* turn off the bogus interrupt to avoid it from now */
93 simask &= ~v_bit;
94 }
95 /*
96 * Re-Enable old Interrupt Mask
97 */
Christophe Leroy394f9b32017-07-06 10:33:13 +020098 out_be32(&immr->im_siu_conf.sc_simask, simask);
Christophe Leroy069fa832017-07-06 10:23:22 +020099}
100
101/************************************************************************/
102
103/*
104 * CPM interrupt handler
105 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200106static void cpm_interrupt(void *regs)
Christophe Leroy069fa832017-07-06 10:23:22 +0200107{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200108 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200109 uint vec;
110
111 /*
112 * Get the vector by setting the ACK bit
113 * and then reading the register.
114 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200115 out_be16(&immr->im_cpic.cpic_civr, 1);
116 vec = in_be16(&immr->im_cpic.cpic_civr);
Christophe Leroy069fa832017-07-06 10:23:22 +0200117 vec >>= 11;
118
119 if (cpm_vecs[vec].handler != NULL) {
120 (*cpm_vecs[vec].handler) (cpm_vecs[vec].arg);
121 } else {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200122 clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
Christophe Leroy48f896d2017-07-06 10:33:17 +0200123 printf("Masking bogus CPM interrupt vector 0x%x\n", vec);
Christophe Leroy069fa832017-07-06 10:23:22 +0200124 }
125 /*
126 * After servicing the interrupt,
127 * we have to remove the status indicator.
128 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200129 setbits_be32(&immr->im_cpic.cpic_cisr, 1 << vec);
Christophe Leroy069fa832017-07-06 10:23:22 +0200130}
131
132/*
133 * The CPM can generate the error interrupt when there is a race
134 * condition between generating and masking interrupts. All we have
135 * to do is ACK it and return. This is a no-op function so we don't
136 * need any special tests in the interrupt handler.
137 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200138static void cpm_error_interrupt(void *dummy)
Christophe Leroy069fa832017-07-06 10:23:22 +0200139{
140}
141
142/************************************************************************/
143/*
144 * Install and free an interrupt handler
145 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200146void irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
Christophe Leroy069fa832017-07-06 10:23:22 +0200147{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200148 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200149
150 if ((vec & CPMVEC_OFFSET) != 0) {
151 /* CPM interrupt */
152 vec &= 0xffff;
Christophe Leroy48f896d2017-07-06 10:33:17 +0200153 if (cpm_vecs[vec].handler != NULL)
154 printf("CPM interrupt 0x%x replacing 0x%x\n",
155 (uint)handler, (uint)cpm_vecs[vec].handler);
Christophe Leroy069fa832017-07-06 10:23:22 +0200156 cpm_vecs[vec].handler = handler;
157 cpm_vecs[vec].arg = arg;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200158 setbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
Christophe Leroy069fa832017-07-06 10:23:22 +0200159 } else {
160 /* SIU interrupt */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200161 if (irq_vecs[vec].handler != NULL)
162 printf("SIU interrupt %d 0x%x replacing 0x%x\n",
163 vec, (uint)handler, (uint)cpm_vecs[vec].handler);
Christophe Leroy069fa832017-07-06 10:23:22 +0200164 irq_vecs[vec].handler = handler;
165 irq_vecs[vec].arg = arg;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200166 setbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec));
Christophe Leroy069fa832017-07-06 10:23:22 +0200167 }
168}
169
Christophe Leroy48f896d2017-07-06 10:33:17 +0200170void irq_free_handler(int vec)
Christophe Leroy069fa832017-07-06 10:23:22 +0200171{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200172 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200173
174 if ((vec & CPMVEC_OFFSET) != 0) {
175 /* CPM interrupt */
176 vec &= 0xffff;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200177 clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
Christophe Leroy069fa832017-07-06 10:23:22 +0200178 cpm_vecs[vec].handler = NULL;
179 cpm_vecs[vec].arg = NULL;
180 } else {
181 /* SIU interrupt */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200182 clrbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec));
Christophe Leroy069fa832017-07-06 10:23:22 +0200183 irq_vecs[vec].handler = NULL;
184 irq_vecs[vec].arg = NULL;
185 }
186}
187
188/************************************************************************/
189
Christophe Leroy48f896d2017-07-06 10:33:17 +0200190static void cpm_interrupt_init(void)
Christophe Leroy069fa832017-07-06 10:23:22 +0200191{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200192 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
193 uint cicr;
Christophe Leroy069fa832017-07-06 10:23:22 +0200194
195 /*
196 * Initialize the CPM interrupt controller.
197 */
198
Christophe Leroy394f9b32017-07-06 10:33:13 +0200199 cicr = CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1 |
200 ((CPM_INTERRUPT / 2) << 13) | CICR_HP_MASK;
Christophe Leroy069fa832017-07-06 10:23:22 +0200201
Christophe Leroy394f9b32017-07-06 10:33:13 +0200202 out_be32(&immr->im_cpic.cpic_cicr, cicr);
203 out_be32(&immr->im_cpic.cpic_cimr, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200204
205 /*
206 * Install the error handler.
207 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200208 irq_install_handler(CPMVEC_ERROR, cpm_error_interrupt, NULL);
Christophe Leroy069fa832017-07-06 10:23:22 +0200209
Christophe Leroy394f9b32017-07-06 10:33:13 +0200210 setbits_be32(&immr->im_cpic.cpic_cicr, CICR_IEN);
Christophe Leroy069fa832017-07-06 10:23:22 +0200211
212 /*
213 * Install the cpm interrupt handler
214 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200215 irq_install_handler(CPM_INTERRUPT, cpm_interrupt, NULL);
Christophe Leroy069fa832017-07-06 10:23:22 +0200216}
217
218/************************************************************************/
219
220/*
221 * timer_interrupt - gets called when the decrementer overflows,
222 * with interrupts disabled.
223 * Trivial implementation - no need to be really accurate.
224 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200225void timer_interrupt_cpu(struct pt_regs *regs)
Christophe Leroy069fa832017-07-06 10:23:22 +0200226{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200227 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200228
229 /* Reset Timer Expired and Timers Interrupt Status */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200230 out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY);
Christophe Leroy069fa832017-07-06 10:23:22 +0200231 __asm__ ("nop");
232 /*
233 Clear TEXPS (and TMIST on older chips). SPLSS (on older
234 chips) is cleared too.
235
236 Bitwise OR is a read-modify-write operation so ALL bits
237 which are cleared by writing `1' would be cleared by
238 operations like
239
240 immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS;
241
242 The same can be achieved by simple writing of the PLPRCR
243 to itself. If a bit value should be preserved, read the
244 register, ZERO the bit and write, not OR, the result back.
245 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200246 setbits_be32(&immr->im_clkrst.car_plprcr, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200247}
248
249/************************************************************************/