2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <mpc8xx_irq.h>
11 #include <asm/cpm_8xx.h>
12 #include <asm/processor.h>
15 /************************************************************************/
18 * CPM interrupt vector functions.
20 struct interrupt_action {
21 interrupt_handler_t *handler;
25 static struct interrupt_action cpm_vecs[CPMVEC_NR];
26 static struct interrupt_action irq_vecs[NR_IRQS];
28 static void cpm_interrupt_init(void);
29 static void cpm_interrupt(void *regs);
31 /************************************************************************/
33 void interrupt_init_cpu(unsigned *decrementer_count)
35 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
37 *decrementer_count = get_tbclk() / CONFIG_SYS_HZ;
39 /* disable all interrupts */
40 out_be32(&immr->im_siu_conf.sc_simask, 0);
42 /* Configure CPM interrupts */
46 /************************************************************************/
49 * Handle external interrupts
51 void external_interrupt(struct pt_regs *regs)
53 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
59 * read the SIVEC register and shift the bits down
60 * to get the irq number
62 vec = in_be32(&immr->im_siu_conf.sc_sivec);
64 v_bit = 0x80000000UL >> irq;
67 * Read Interrupt Mask Register and Mask Interrupts
69 simask = in_be32(&immr->im_siu_conf.sc_simask);
70 clrbits_be32(&immr->im_siu_conf.sc_simask, 0xFFFF0000 >> irq);
72 if (!(irq & 0x1)) { /* External Interrupt ? */
76 * Read Interrupt Edge/Level Register
78 siel = in_be32(&immr->im_siu_conf.sc_siel);
80 if (siel & v_bit) { /* edge triggered interrupt ? */
82 * Rewrite SIPEND Register to clear interrupt
84 out_be32(&immr->im_siu_conf.sc_sipend, v_bit);
88 if (irq_vecs[irq].handler != NULL) {
89 irq_vecs[irq].handler(irq_vecs[irq].arg);
91 printf("\nBogus External Interrupt IRQ %d Vector %ld\n",
93 /* turn off the bogus interrupt to avoid it from now */
97 * Re-Enable old Interrupt Mask
99 out_be32(&immr->im_siu_conf.sc_simask, simask);
102 /************************************************************************/
105 * CPM interrupt handler
107 static void cpm_interrupt(void *regs)
109 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
113 * Get the vector by setting the ACK bit
114 * and then reading the register.
116 out_be16(&immr->im_cpic.cpic_civr, 1);
117 vec = in_be16(&immr->im_cpic.cpic_civr);
120 if (cpm_vecs[vec].handler != NULL) {
121 (*cpm_vecs[vec].handler) (cpm_vecs[vec].arg);
123 clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
124 printf("Masking bogus CPM interrupt vector 0x%x\n", vec);
127 * After servicing the interrupt,
128 * we have to remove the status indicator.
130 setbits_be32(&immr->im_cpic.cpic_cisr, 1 << vec);
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.
139 static void cpm_error_interrupt(void *dummy)
143 /************************************************************************/
145 * Install and free an interrupt handler
147 void irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
149 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
151 if ((vec & CPMVEC_OFFSET) != 0) {
154 if (cpm_vecs[vec].handler != NULL)
155 printf("CPM interrupt 0x%x replacing 0x%x\n",
156 (uint)handler, (uint)cpm_vecs[vec].handler);
157 cpm_vecs[vec].handler = handler;
158 cpm_vecs[vec].arg = arg;
159 setbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
162 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);
165 irq_vecs[vec].handler = handler;
166 irq_vecs[vec].arg = arg;
167 setbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec));
171 void irq_free_handler(int vec)
173 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
175 if ((vec & CPMVEC_OFFSET) != 0) {
178 clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec);
179 cpm_vecs[vec].handler = NULL;
180 cpm_vecs[vec].arg = NULL;
183 clrbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec));
184 irq_vecs[vec].handler = NULL;
185 irq_vecs[vec].arg = NULL;
189 /************************************************************************/
191 static void cpm_interrupt_init(void)
193 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
197 * Initialize the CPM interrupt controller.
200 cicr = CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1 |
201 ((CPM_INTERRUPT / 2) << 13) | CICR_HP_MASK;
203 out_be32(&immr->im_cpic.cpic_cicr, cicr);
204 out_be32(&immr->im_cpic.cpic_cimr, 0);
207 * Install the error handler.
209 irq_install_handler(CPMVEC_ERROR, cpm_error_interrupt, NULL);
211 setbits_be32(&immr->im_cpic.cpic_cicr, CICR_IEN);
214 * Install the cpm interrupt handler
216 irq_install_handler(CPM_INTERRUPT, cpm_interrupt, NULL);
219 /************************************************************************/
222 * timer_interrupt - gets called when the decrementer overflows,
223 * with interrupts disabled.
224 * Trivial implementation - no need to be really accurate.
226 void timer_interrupt_cpu(struct pt_regs *regs)
228 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
230 /* Reset Timer Expired and Timers Interrupt Status */
231 out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY);
234 Clear TEXPS (and TMIST on older chips). SPLSS (on older
235 chips) is cleared too.
237 Bitwise OR is a read-modify-write operation so ALL bits
238 which are cleared by writing `1' would be cleared by
241 immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS;
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.
247 setbits_be32(&immr->im_clkrst.car_plprcr, 0);
250 /************************************************************************/