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/processor.h>
14 /************************************************************************/
17 * CPM interrupt vector functions.
19 struct interrupt_action
{
20 interrupt_handler_t
*handler
;
24 static struct interrupt_action cpm_vecs
[CPMVEC_NR
];
25 static struct interrupt_action irq_vecs
[NR_IRQS
];
27 static void cpm_interrupt_init (void);
28 static void cpm_interrupt (void *regs
);
30 /************************************************************************/
32 int interrupt_init_cpu (unsigned *decrementer_count
)
34 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
36 *decrementer_count
= get_tbclk () / CONFIG_SYS_HZ
;
38 /* disable all interrupts */
39 immr
->im_siu_conf
.sc_simask
= 0;
41 /* Configure CPM interrupts */
42 cpm_interrupt_init ();
47 /************************************************************************/
50 * Handle external interrupts
52 void external_interrupt (struct pt_regs
*regs
)
54 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
56 ulong simask
, newmask
;
60 * read the SIVEC register and shift the bits down
61 * to get the irq number
63 vec
= immr
->im_siu_conf
.sc_sivec
;
65 v_bit
= 0x80000000UL
>> irq
;
68 * Read Interrupt Mask Register and Mask Interrupts
70 simask
= immr
->im_siu_conf
.sc_simask
;
71 newmask
= simask
& (~(0xFFFF0000 >> irq
));
72 immr
->im_siu_conf
.sc_simask
= newmask
;
74 if (!(irq
& 0x1)) { /* External Interrupt ? */
78 * Read Interrupt Edge/Level Register
80 siel
= immr
->im_siu_conf
.sc_siel
;
82 if (siel
& v_bit
) { /* edge triggered interrupt ? */
84 * Rewrite SIPEND Register to clear interrupt
86 immr
->im_siu_conf
.sc_sipend
= v_bit
;
90 if (irq_vecs
[irq
].handler
!= NULL
) {
91 irq_vecs
[irq
].handler (irq_vecs
[irq
].arg
);
93 printf ("\nBogus External Interrupt IRQ %d Vector %ld\n",
95 /* turn off the bogus interrupt to avoid it from now */
99 * Re-Enable old Interrupt Mask
101 immr
->im_siu_conf
.sc_simask
= simask
;
104 /************************************************************************/
107 * CPM interrupt handler
109 static void cpm_interrupt (void *regs
)
111 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
115 * Get the vector by setting the ACK bit
116 * and then reading the register.
118 immr
->im_cpic
.cpic_civr
= 1;
119 vec
= immr
->im_cpic
.cpic_civr
;
122 if (cpm_vecs
[vec
].handler
!= NULL
) {
123 (*cpm_vecs
[vec
].handler
) (cpm_vecs
[vec
].arg
);
125 immr
->im_cpic
.cpic_cimr
&= ~(1 << vec
);
126 printf ("Masking bogus CPM interrupt vector 0x%x\n", vec
);
129 * After servicing the interrupt,
130 * we have to remove the status indicator.
132 immr
->im_cpic
.cpic_cisr
|= (1 << vec
);
136 * The CPM can generate the error interrupt when there is a race
137 * condition between generating and masking interrupts. All we have
138 * to do is ACK it and return. This is a no-op function so we don't
139 * need any special tests in the interrupt handler.
141 static void cpm_error_interrupt (void *dummy
)
145 /************************************************************************/
147 * Install and free an interrupt handler
149 void irq_install_handler (int vec
, interrupt_handler_t
* handler
,
152 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
154 if ((vec
& CPMVEC_OFFSET
) != 0) {
157 if (cpm_vecs
[vec
].handler
!= NULL
) {
158 printf ("CPM interrupt 0x%x replacing 0x%x\n",
160 (uint
) cpm_vecs
[vec
].handler
);
162 cpm_vecs
[vec
].handler
= handler
;
163 cpm_vecs
[vec
].arg
= arg
;
164 immr
->im_cpic
.cpic_cimr
|= (1 << vec
);
167 if (irq_vecs
[vec
].handler
!= NULL
) {
168 printf ("SIU interrupt %d 0x%x replacing 0x%x\n",
171 (uint
) cpm_vecs
[vec
].handler
);
173 irq_vecs
[vec
].handler
= handler
;
174 irq_vecs
[vec
].arg
= arg
;
175 immr
->im_siu_conf
.sc_simask
|= 1 << (31 - vec
);
179 void irq_free_handler (int vec
)
181 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
183 if ((vec
& CPMVEC_OFFSET
) != 0) {
186 immr
->im_cpic
.cpic_cimr
&= ~(1 << vec
);
187 cpm_vecs
[vec
].handler
= NULL
;
188 cpm_vecs
[vec
].arg
= NULL
;
191 immr
->im_siu_conf
.sc_simask
&= ~(1 << (31 - vec
));
192 irq_vecs
[vec
].handler
= NULL
;
193 irq_vecs
[vec
].arg
= NULL
;
197 /************************************************************************/
199 static void cpm_interrupt_init (void)
201 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
204 * Initialize the CPM interrupt controller.
207 immr
->im_cpic
.cpic_cicr
=
211 CICR_SCA_SCC1
) | ((CPM_INTERRUPT
/ 2) << 13) | CICR_HP_MASK
;
213 immr
->im_cpic
.cpic_cimr
= 0;
216 * Install the error handler.
218 irq_install_handler (CPMVEC_ERROR
, cpm_error_interrupt
, NULL
);
220 immr
->im_cpic
.cpic_cicr
|= CICR_IEN
;
223 * Install the cpm interrupt handler
225 irq_install_handler (CPM_INTERRUPT
, cpm_interrupt
, NULL
);
228 /************************************************************************/
231 * timer_interrupt - gets called when the decrementer overflows,
232 * with interrupts disabled.
233 * Trivial implementation - no need to be really accurate.
235 void timer_interrupt_cpu (struct pt_regs
*regs
)
237 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
239 /* Reset Timer Expired and Timers Interrupt Status */
240 immr
->im_clkrstk
.cark_plprcrk
= KAPWR_KEY
;
243 Clear TEXPS (and TMIST on older chips). SPLSS (on older
244 chips) is cleared too.
246 Bitwise OR is a read-modify-write operation so ALL bits
247 which are cleared by writing `1' would be cleared by
250 immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS;
252 The same can be achieved by simple writing of the PLPRCR
253 to itself. If a bit value should be preserved, read the
254 register, ZERO the bit and write, not OR, the result back.
256 immr
->im_clkrst
.car_plprcr
= immr
->im_clkrst
.car_plprcr
;
259 /************************************************************************/