Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 1 | /* |
| 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 Leroy | 10ff63a | 2018-03-16 17:20:43 +0100 | [diff] [blame] | 11 | #include <asm/cpm_8xx.h> |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 12 | #include <asm/processor.h> |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 13 | #include <asm/io.h> |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 14 | |
| 15 | /************************************************************************/ |
| 16 | |
| 17 | /* |
| 18 | * CPM interrupt vector functions. |
| 19 | */ |
| 20 | struct interrupt_action { |
| 21 | interrupt_handler_t *handler; |
| 22 | void *arg; |
| 23 | }; |
| 24 | |
| 25 | static struct interrupt_action cpm_vecs[CPMVEC_NR]; |
| 26 | static struct interrupt_action irq_vecs[NR_IRQS]; |
| 27 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 28 | static void cpm_interrupt_init(void); |
| 29 | static void cpm_interrupt(void *regs); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 30 | |
| 31 | /************************************************************************/ |
| 32 | |
Tom Rini | ce10398 | 2017-08-13 22:44:37 -0400 | [diff] [blame] | 33 | void interrupt_init_cpu(unsigned *decrementer_count) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 34 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 35 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 36 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 37 | *decrementer_count = get_tbclk() / CONFIG_SYS_HZ; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 38 | |
| 39 | /* disable all interrupts */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 40 | out_be32(&immr->im_siu_conf.sc_simask, 0); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 41 | |
| 42 | /* Configure CPM interrupts */ |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 43 | cpm_interrupt_init(); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | /************************************************************************/ |
| 47 | |
| 48 | /* |
| 49 | * Handle external interrupts |
| 50 | */ |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 51 | void external_interrupt(struct pt_regs *regs) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 52 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 53 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 54 | int irq; |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 55 | ulong simask; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 56 | ulong vec, v_bit; |
| 57 | |
| 58 | /* |
| 59 | * read the SIVEC register and shift the bits down |
| 60 | * to get the irq number |
| 61 | */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 62 | vec = in_be32(&immr->im_siu_conf.sc_sivec); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 63 | irq = vec >> 26; |
| 64 | v_bit = 0x80000000UL >> irq; |
| 65 | |
| 66 | /* |
| 67 | * Read Interrupt Mask Register and Mask Interrupts |
| 68 | */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 69 | simask = in_be32(&immr->im_siu_conf.sc_simask); |
| 70 | clrbits_be32(&immr->im_siu_conf.sc_simask, 0xFFFF0000 >> irq); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 71 | |
| 72 | if (!(irq & 0x1)) { /* External Interrupt ? */ |
| 73 | ulong siel; |
| 74 | |
| 75 | /* |
| 76 | * Read Interrupt Edge/Level Register |
| 77 | */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 78 | siel = in_be32(&immr->im_siu_conf.sc_siel); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 79 | |
| 80 | if (siel & v_bit) { /* edge triggered interrupt ? */ |
| 81 | /* |
| 82 | * Rewrite SIPEND Register to clear interrupt |
| 83 | */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 84 | out_be32(&immr->im_siu_conf.sc_sipend, v_bit); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | if (irq_vecs[irq].handler != NULL) { |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 89 | irq_vecs[irq].handler(irq_vecs[irq].arg); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 90 | } else { |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 91 | printf("\nBogus External Interrupt IRQ %d Vector %ld\n", |
| 92 | irq, vec); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 93 | /* turn off the bogus interrupt to avoid it from now */ |
| 94 | simask &= ~v_bit; |
| 95 | } |
| 96 | /* |
| 97 | * Re-Enable old Interrupt Mask |
| 98 | */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 99 | out_be32(&immr->im_siu_conf.sc_simask, simask); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /************************************************************************/ |
| 103 | |
| 104 | /* |
| 105 | * CPM interrupt handler |
| 106 | */ |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 107 | static void cpm_interrupt(void *regs) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 108 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 109 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 110 | uint vec; |
| 111 | |
| 112 | /* |
| 113 | * Get the vector by setting the ACK bit |
| 114 | * and then reading the register. |
| 115 | */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 116 | out_be16(&immr->im_cpic.cpic_civr, 1); |
| 117 | vec = in_be16(&immr->im_cpic.cpic_civr); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 118 | vec >>= 11; |
| 119 | |
| 120 | if (cpm_vecs[vec].handler != NULL) { |
| 121 | (*cpm_vecs[vec].handler) (cpm_vecs[vec].arg); |
| 122 | } else { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 123 | clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec); |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 124 | printf("Masking bogus CPM interrupt vector 0x%x\n", vec); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 125 | } |
| 126 | /* |
| 127 | * After servicing the interrupt, |
| 128 | * we have to remove the status indicator. |
| 129 | */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 130 | setbits_be32(&immr->im_cpic.cpic_cisr, 1 << vec); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 131 | } |
| 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 Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 139 | static void cpm_error_interrupt(void *dummy) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 140 | { |
| 141 | } |
| 142 | |
| 143 | /************************************************************************/ |
| 144 | /* |
| 145 | * Install and free an interrupt handler |
| 146 | */ |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 147 | void irq_install_handler(int vec, interrupt_handler_t *handler, void *arg) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 148 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 149 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 150 | |
| 151 | if ((vec & CPMVEC_OFFSET) != 0) { |
| 152 | /* CPM interrupt */ |
| 153 | vec &= 0xffff; |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 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); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 157 | cpm_vecs[vec].handler = handler; |
| 158 | cpm_vecs[vec].arg = arg; |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 159 | setbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 160 | } else { |
| 161 | /* SIU interrupt */ |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 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); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 165 | irq_vecs[vec].handler = handler; |
| 166 | irq_vecs[vec].arg = arg; |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 167 | setbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 171 | void irq_free_handler(int vec) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 172 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 173 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 174 | |
| 175 | if ((vec & CPMVEC_OFFSET) != 0) { |
| 176 | /* CPM interrupt */ |
| 177 | vec &= 0xffff; |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 178 | clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 179 | cpm_vecs[vec].handler = NULL; |
| 180 | cpm_vecs[vec].arg = NULL; |
| 181 | } else { |
| 182 | /* SIU interrupt */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 183 | clrbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 184 | irq_vecs[vec].handler = NULL; |
| 185 | irq_vecs[vec].arg = NULL; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /************************************************************************/ |
| 190 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 191 | static void cpm_interrupt_init(void) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 192 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 193 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 194 | uint cicr; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 195 | |
| 196 | /* |
| 197 | * Initialize the CPM interrupt controller. |
| 198 | */ |
| 199 | |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 200 | cicr = CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1 | |
| 201 | ((CPM_INTERRUPT / 2) << 13) | CICR_HP_MASK; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 202 | |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 203 | out_be32(&immr->im_cpic.cpic_cicr, cicr); |
| 204 | out_be32(&immr->im_cpic.cpic_cimr, 0); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 205 | |
| 206 | /* |
| 207 | * Install the error handler. |
| 208 | */ |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 209 | irq_install_handler(CPMVEC_ERROR, cpm_error_interrupt, NULL); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 210 | |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 211 | setbits_be32(&immr->im_cpic.cpic_cicr, CICR_IEN); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 212 | |
| 213 | /* |
| 214 | * Install the cpm interrupt handler |
| 215 | */ |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 216 | irq_install_handler(CPM_INTERRUPT, cpm_interrupt, NULL); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 217 | } |
| 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 Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 226 | void timer_interrupt_cpu(struct pt_regs *regs) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 227 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 228 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 229 | |
| 230 | /* Reset Timer Expired and Timers Interrupt Status */ |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 231 | out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 232 | __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 Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 247 | setbits_be32(&immr->im_clkrst.car_plprcr, 0); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /************************************************************************/ |