Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Christophe Leroy | 907208c | 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 | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | c30b7ad | 2019-11-14 12:57:41 -0700 | [diff] [blame] | 8 | #include <irq_func.h> |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 9 | #include <mpc8xx.h> |
| 10 | #include <mpc8xx_irq.h> |
Simon Glass | 049f8d6 | 2019-12-28 10:44:59 -0700 | [diff] [blame^] | 11 | #include <time.h> |
Christophe Leroy | 18f8d4c | 2018-03-16 17:20:43 +0100 | [diff] [blame] | 12 | #include <asm/cpm_8xx.h> |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 13 | #include <asm/processor.h> |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 14 | #include <asm/io.h> |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 15 | |
| 16 | /************************************************************************/ |
| 17 | |
| 18 | /* |
| 19 | * CPM interrupt vector functions. |
| 20 | */ |
| 21 | struct interrupt_action { |
| 22 | interrupt_handler_t *handler; |
| 23 | void *arg; |
| 24 | }; |
| 25 | |
| 26 | static struct interrupt_action cpm_vecs[CPMVEC_NR]; |
| 27 | static struct interrupt_action irq_vecs[NR_IRQS]; |
| 28 | |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 29 | static void cpm_interrupt_init(void); |
| 30 | static void cpm_interrupt(void *regs); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 31 | |
| 32 | /************************************************************************/ |
| 33 | |
Tom Rini | deff9b1 | 2017-08-13 22:44:37 -0400 | [diff] [blame] | 34 | void interrupt_init_cpu(unsigned *decrementer_count) |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 35 | { |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 36 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 37 | |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 38 | *decrementer_count = get_tbclk() / CONFIG_SYS_HZ; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 39 | |
| 40 | /* disable all interrupts */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 41 | out_be32(&immr->im_siu_conf.sc_simask, 0); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 42 | |
| 43 | /* Configure CPM interrupts */ |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 44 | cpm_interrupt_init(); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /************************************************************************/ |
| 48 | |
| 49 | /* |
| 50 | * Handle external interrupts |
| 51 | */ |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 52 | void external_interrupt(struct pt_regs *regs) |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 53 | { |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 54 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 55 | int irq; |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 56 | ulong simask; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 57 | ulong vec, v_bit; |
| 58 | |
| 59 | /* |
| 60 | * read the SIVEC register and shift the bits down |
| 61 | * to get the irq number |
| 62 | */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 63 | vec = in_be32(&immr->im_siu_conf.sc_sivec); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 64 | irq = vec >> 26; |
| 65 | v_bit = 0x80000000UL >> irq; |
| 66 | |
| 67 | /* |
| 68 | * Read Interrupt Mask Register and Mask Interrupts |
| 69 | */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 70 | simask = in_be32(&immr->im_siu_conf.sc_simask); |
| 71 | clrbits_be32(&immr->im_siu_conf.sc_simask, 0xFFFF0000 >> irq); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 72 | |
| 73 | if (!(irq & 0x1)) { /* External Interrupt ? */ |
| 74 | ulong siel; |
| 75 | |
| 76 | /* |
| 77 | * Read Interrupt Edge/Level Register |
| 78 | */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 79 | siel = in_be32(&immr->im_siu_conf.sc_siel); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 80 | |
| 81 | if (siel & v_bit) { /* edge triggered interrupt ? */ |
| 82 | /* |
| 83 | * Rewrite SIPEND Register to clear interrupt |
| 84 | */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 85 | out_be32(&immr->im_siu_conf.sc_sipend, v_bit); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | if (irq_vecs[irq].handler != NULL) { |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 90 | irq_vecs[irq].handler(irq_vecs[irq].arg); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 91 | } else { |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 92 | printf("\nBogus External Interrupt IRQ %d Vector %ld\n", |
| 93 | irq, vec); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 94 | /* turn off the bogus interrupt to avoid it from now */ |
| 95 | simask &= ~v_bit; |
| 96 | } |
| 97 | /* |
| 98 | * Re-Enable old Interrupt Mask |
| 99 | */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 100 | out_be32(&immr->im_siu_conf.sc_simask, simask); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /************************************************************************/ |
| 104 | |
| 105 | /* |
| 106 | * CPM interrupt handler |
| 107 | */ |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 108 | static void cpm_interrupt(void *regs) |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 109 | { |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 110 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 111 | uint vec; |
| 112 | |
| 113 | /* |
| 114 | * Get the vector by setting the ACK bit |
| 115 | * and then reading the register. |
| 116 | */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 117 | out_be16(&immr->im_cpic.cpic_civr, 1); |
| 118 | vec = in_be16(&immr->im_cpic.cpic_civr); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 119 | vec >>= 11; |
| 120 | |
| 121 | if (cpm_vecs[vec].handler != NULL) { |
| 122 | (*cpm_vecs[vec].handler) (cpm_vecs[vec].arg); |
| 123 | } else { |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 124 | clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec); |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 125 | printf("Masking bogus CPM interrupt vector 0x%x\n", vec); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 126 | } |
| 127 | /* |
| 128 | * After servicing the interrupt, |
| 129 | * we have to remove the status indicator. |
| 130 | */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 131 | setbits_be32(&immr->im_cpic.cpic_cisr, 1 << vec); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* |
| 135 | * The CPM can generate the error interrupt when there is a race |
| 136 | * condition between generating and masking interrupts. All we have |
| 137 | * to do is ACK it and return. This is a no-op function so we don't |
| 138 | * need any special tests in the interrupt handler. |
| 139 | */ |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 140 | static void cpm_error_interrupt(void *dummy) |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 141 | { |
| 142 | } |
| 143 | |
| 144 | /************************************************************************/ |
| 145 | /* |
| 146 | * Install and free an interrupt handler |
| 147 | */ |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 148 | void irq_install_handler(int vec, interrupt_handler_t *handler, void *arg) |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 149 | { |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 150 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 151 | |
| 152 | if ((vec & CPMVEC_OFFSET) != 0) { |
| 153 | /* CPM interrupt */ |
| 154 | vec &= 0xffff; |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 155 | if (cpm_vecs[vec].handler != NULL) |
| 156 | printf("CPM interrupt 0x%x replacing 0x%x\n", |
| 157 | (uint)handler, (uint)cpm_vecs[vec].handler); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 158 | cpm_vecs[vec].handler = handler; |
| 159 | cpm_vecs[vec].arg = arg; |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 160 | setbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 161 | } else { |
| 162 | /* SIU interrupt */ |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 163 | if (irq_vecs[vec].handler != NULL) |
| 164 | printf("SIU interrupt %d 0x%x replacing 0x%x\n", |
| 165 | vec, (uint)handler, (uint)cpm_vecs[vec].handler); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 166 | irq_vecs[vec].handler = handler; |
| 167 | irq_vecs[vec].arg = arg; |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 168 | setbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec)); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 172 | void irq_free_handler(int vec) |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 173 | { |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 174 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 175 | |
| 176 | if ((vec & CPMVEC_OFFSET) != 0) { |
| 177 | /* CPM interrupt */ |
| 178 | vec &= 0xffff; |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 179 | clrbits_be32(&immr->im_cpic.cpic_cimr, 1 << vec); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 180 | cpm_vecs[vec].handler = NULL; |
| 181 | cpm_vecs[vec].arg = NULL; |
| 182 | } else { |
| 183 | /* SIU interrupt */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 184 | clrbits_be32(&immr->im_siu_conf.sc_simask, 1 << (31 - vec)); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 185 | irq_vecs[vec].handler = NULL; |
| 186 | irq_vecs[vec].arg = NULL; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /************************************************************************/ |
| 191 | |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 192 | static void cpm_interrupt_init(void) |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 193 | { |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 194 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 195 | uint cicr; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 196 | |
| 197 | /* |
| 198 | * Initialize the CPM interrupt controller. |
| 199 | */ |
| 200 | |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 201 | cicr = CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1 | |
| 202 | ((CPM_INTERRUPT / 2) << 13) | CICR_HP_MASK; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 203 | |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 204 | out_be32(&immr->im_cpic.cpic_cicr, cicr); |
| 205 | out_be32(&immr->im_cpic.cpic_cimr, 0); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 206 | |
| 207 | /* |
| 208 | * Install the error handler. |
| 209 | */ |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 210 | irq_install_handler(CPMVEC_ERROR, cpm_error_interrupt, NULL); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 211 | |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 212 | setbits_be32(&immr->im_cpic.cpic_cicr, CICR_IEN); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Install the cpm interrupt handler |
| 216 | */ |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 217 | irq_install_handler(CPM_INTERRUPT, cpm_interrupt, NULL); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /************************************************************************/ |
| 221 | |
| 222 | /* |
| 223 | * timer_interrupt - gets called when the decrementer overflows, |
| 224 | * with interrupts disabled. |
| 225 | * Trivial implementation - no need to be really accurate. |
| 226 | */ |
Christophe Leroy | 70fd071 | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 227 | void timer_interrupt_cpu(struct pt_regs *regs) |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 228 | { |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 229 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 230 | |
| 231 | /* Reset Timer Expired and Timers Interrupt Status */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 232 | out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 233 | __asm__ ("nop"); |
| 234 | /* |
| 235 | Clear TEXPS (and TMIST on older chips). SPLSS (on older |
| 236 | chips) is cleared too. |
| 237 | |
| 238 | Bitwise OR is a read-modify-write operation so ALL bits |
| 239 | which are cleared by writing `1' would be cleared by |
| 240 | operations like |
| 241 | |
| 242 | immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS; |
| 243 | |
| 244 | The same can be achieved by simple writing of the PLPRCR |
| 245 | to itself. If a bit value should be preserved, read the |
| 246 | register, ZERO the bit and write, not OR, the result back. |
| 247 | */ |
Christophe Leroy | ba3da73 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 248 | setbits_be32(&immr->im_clkrst.car_plprcr, 0); |
Christophe Leroy | 907208c | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /************************************************************************/ |