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