wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <watchdog.h> |
| 26 | #include <mpc8xx.h> |
| 27 | #include <mpc8xx_irq.h> |
| 28 | #include <asm/processor.h> |
| 29 | #include <commproc.h> |
| 30 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 31 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 32 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 33 | unsigned decrementer_count; /* count value for 1e6/HZ microseconds */ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 34 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 35 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * CPM interrupt vector functions. |
| 39 | */ |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 40 | struct interrupt_action { |
| 41 | interrupt_handler_t *handler; |
| 42 | void *arg; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 45 | static struct interrupt_action cpm_vecs[CPMVEC_NR]; |
| 46 | static struct interrupt_action irq_vecs[NR_IRQS]; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 47 | |
| 48 | static void cpm_interrupt_init (void); |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 49 | static void cpm_interrupt (void *regs); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 50 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 51 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 52 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 53 | static __inline__ unsigned long get_msr (void) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 54 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 55 | unsigned long msr; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 56 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 57 | asm volatile ("mfmsr %0":"=r" (msr):); |
| 58 | |
| 59 | return msr; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 60 | } |
| 61 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 62 | static __inline__ void set_msr (unsigned long msr) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 63 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 64 | asm volatile ("mtmsr %0"::"r" (msr)); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 65 | } |
| 66 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 67 | static __inline__ unsigned long get_dec (void) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 68 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 69 | unsigned long val; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 70 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 71 | asm volatile ("mfdec %0":"=r" (val):); |
| 72 | |
| 73 | return val; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 77 | static __inline__ void set_dec (unsigned long val) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 78 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 79 | asm volatile ("mtdec %0"::"r" (val)); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
| 83 | void enable_interrupts (void) |
| 84 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 85 | set_msr (get_msr () | MSR_EE); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* returns flag if MSR_EE was set before */ |
| 89 | int disable_interrupts (void) |
| 90 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 91 | ulong msr = get_msr (); |
| 92 | |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 93 | set_msr (msr & ~MSR_EE); |
| 94 | return ((msr & MSR_EE) != 0); |
| 95 | } |
| 96 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 97 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 98 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 99 | int interrupt_init (void) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 100 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 101 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 102 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 103 | decrementer_count = get_tbclk () / CFG_HZ; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 104 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 105 | /* disable all interrupts */ |
| 106 | immr->im_siu_conf.sc_simask = 0; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 107 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 108 | /* Configure CPM interrupts */ |
| 109 | cpm_interrupt_init (); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 110 | |
| 111 | set_dec (decrementer_count); |
| 112 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 113 | set_msr (get_msr () | MSR_EE); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 114 | |
| 115 | return (0); |
| 116 | } |
| 117 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 118 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * Handle external interrupts |
| 122 | */ |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 123 | void external_interrupt (struct pt_regs *regs) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 124 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 125 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 126 | int irq; |
| 127 | ulong simask, newmask; |
| 128 | ulong vec, v_bit; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * read the SIVEC register and shift the bits down |
| 132 | * to get the irq number |
| 133 | */ |
| 134 | vec = immr->im_siu_conf.sc_sivec; |
| 135 | irq = vec >> 26; |
| 136 | v_bit = 0x80000000UL >> irq; |
| 137 | |
| 138 | /* |
| 139 | * Read Interrupt Mask Register and Mask Interrupts |
| 140 | */ |
| 141 | simask = immr->im_siu_conf.sc_simask; |
| 142 | newmask = simask & (~(0xFFFF0000 >> irq)); |
| 143 | immr->im_siu_conf.sc_simask = newmask; |
| 144 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 145 | if (!(irq & 0x1)) { /* External Interrupt ? */ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 146 | ulong siel; |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 147 | |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 148 | /* |
| 149 | * Read Interrupt Edge/Level Register |
| 150 | */ |
| 151 | siel = immr->im_siu_conf.sc_siel; |
| 152 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 153 | if (siel & v_bit) { /* edge triggered interrupt ? */ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 154 | /* |
| 155 | * Rewrite SIPEND Register to clear interrupt |
| 156 | */ |
| 157 | immr->im_siu_conf.sc_sipend = v_bit; |
| 158 | } |
| 159 | } |
| 160 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 161 | if (irq_vecs[irq].handler != NULL) { |
| 162 | irq_vecs[irq].handler (irq_vecs[irq].arg); |
| 163 | } else { |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 164 | printf ("\nBogus External Interrupt IRQ %d Vector %ld\n", |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 165 | irq, vec); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 166 | /* turn off the bogus interrupt to avoid it from now */ |
| 167 | simask &= ~v_bit; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 168 | } |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 169 | /* |
| 170 | * Re-Enable old Interrupt Mask |
| 171 | */ |
| 172 | immr->im_siu_conf.sc_simask = simask; |
| 173 | } |
| 174 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 175 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * CPM interrupt handler |
| 179 | */ |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 180 | static void cpm_interrupt (void *regs) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 181 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 182 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 183 | uint vec; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * Get the vector by setting the ACK bit |
| 187 | * and then reading the register. |
| 188 | */ |
| 189 | immr->im_cpic.cpic_civr = 1; |
| 190 | vec = immr->im_cpic.cpic_civr; |
| 191 | vec >>= 11; |
| 192 | |
| 193 | if (cpm_vecs[vec].handler != NULL) { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 194 | (*cpm_vecs[vec].handler) (cpm_vecs[vec].arg); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 195 | } else { |
| 196 | immr->im_cpic.cpic_cimr &= ~(1 << vec); |
| 197 | printf ("Masking bogus CPM interrupt vector 0x%x\n", vec); |
| 198 | } |
| 199 | /* |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 200 | * After servicing the interrupt, |
| 201 | * we have to remove the status indicator. |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 202 | */ |
| 203 | immr->im_cpic.cpic_cisr |= (1 << vec); |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * The CPM can generate the error interrupt when there is a race |
| 208 | * condition between generating and masking interrupts. All we have |
| 209 | * to do is ACK it and return. This is a no-op function so we don't |
| 210 | * need any special tests in the interrupt handler. |
| 211 | */ |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 212 | static void cpm_error_interrupt (void *dummy) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 213 | { |
| 214 | } |
| 215 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 216 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 217 | /* |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 218 | * Install and free an interrupt handler |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 219 | */ |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 220 | void irq_install_handler (int vec, interrupt_handler_t * handler, |
| 221 | void *arg) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 222 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 223 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 224 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 225 | if ((vec & CPMVEC_OFFSET) != 0) { |
| 226 | /* CPM interrupt */ |
| 227 | vec &= 0xffff; |
| 228 | if (cpm_vecs[vec].handler != NULL) { |
| 229 | printf ("CPM interrupt 0x%x replacing 0x%x\n", |
| 230 | (uint) handler, |
| 231 | (uint) cpm_vecs[vec].handler); |
| 232 | } |
| 233 | cpm_vecs[vec].handler = handler; |
| 234 | cpm_vecs[vec].arg = arg; |
| 235 | immr->im_cpic.cpic_cimr |= (1 << vec); |
| 236 | #if 0 |
| 237 | printf ("Install CPM interrupt for vector %d ==> %p\n", |
| 238 | vec, handler); |
| 239 | #endif |
| 240 | } else { |
| 241 | /* SIU interrupt */ |
| 242 | if (irq_vecs[vec].handler != NULL) { |
| 243 | printf ("SIU interrupt %d 0x%x replacing 0x%x\n", |
| 244 | vec, |
| 245 | (uint) handler, |
| 246 | (uint) cpm_vecs[vec].handler); |
| 247 | } |
| 248 | irq_vecs[vec].handler = handler; |
| 249 | irq_vecs[vec].arg = arg; |
| 250 | immr->im_siu_conf.sc_simask |= 1 << (31 - vec); |
| 251 | #if 0 |
| 252 | printf ("Install SIU interrupt for vector %d ==> %p\n", |
| 253 | vec, handler); |
| 254 | #endif |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 255 | } |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 256 | } |
| 257 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 258 | void irq_free_handler (int vec) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 259 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 260 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 261 | |
| 262 | if ((vec & CPMVEC_OFFSET) != 0) { |
| 263 | /* CPM interrupt */ |
| 264 | vec &= 0xffff; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 265 | #if 0 |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 266 | printf ("Free CPM interrupt for vector %d ==> %p\n", |
| 267 | vec, cpm_vecs[vec].handler); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 268 | #endif |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 269 | immr->im_cpic.cpic_cimr &= ~(1 << vec); |
| 270 | cpm_vecs[vec].handler = NULL; |
| 271 | cpm_vecs[vec].arg = NULL; |
| 272 | } else { |
| 273 | /* SIU interrupt */ |
| 274 | #if 0 |
| 275 | printf ("Free CPM interrupt for vector %d ==> %p\n", |
| 276 | vec, cpm_vecs[vec].handler); |
| 277 | #endif |
| 278 | immr->im_siu_conf.sc_simask &= ~(1 << (31 - vec)); |
| 279 | irq_vecs[vec].handler = NULL; |
| 280 | irq_vecs[vec].arg = NULL; |
| 281 | } |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 282 | } |
| 283 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 284 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 285 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 286 | static void cpm_interrupt_init (void) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 287 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 288 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 289 | |
| 290 | /* |
| 291 | * Initialize the CPM interrupt controller. |
| 292 | */ |
| 293 | |
| 294 | immr->im_cpic.cpic_cicr = |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 295 | (CICR_SCD_SCC4 | |
| 296 | CICR_SCC_SCC3 | |
| 297 | CICR_SCB_SCC2 | |
| 298 | CICR_SCA_SCC1) | ((CPM_INTERRUPT / 2) << 13) | CICR_HP_MASK; |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 299 | |
| 300 | immr->im_cpic.cpic_cimr = 0; |
| 301 | |
| 302 | /* |
| 303 | * Install the error handler. |
| 304 | */ |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 305 | irq_install_handler (CPMVEC_ERROR, cpm_error_interrupt, NULL); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 306 | |
| 307 | immr->im_cpic.cpic_cicr |= CICR_IEN; |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 308 | |
| 309 | /* |
| 310 | * Install the cpm interrupt handler |
| 311 | */ |
| 312 | irq_install_handler (CPM_INTERRUPT, cpm_interrupt, NULL); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 313 | } |
| 314 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 315 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 316 | |
| 317 | volatile ulong timestamp = 0; |
| 318 | |
| 319 | /* |
| 320 | * timer_interrupt - gets called when the decrementer overflows, |
| 321 | * with interrupts disabled. |
| 322 | * Trivial implementation - no need to be really accurate. |
| 323 | */ |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 324 | void timer_interrupt (struct pt_regs *regs) |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 325 | { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 326 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
| 327 | |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 328 | #ifdef CONFIG_STATUS_LED |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 329 | extern void status_led_tick (ulong); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 330 | #endif |
| 331 | #if 0 |
| 332 | printf ("*** Timer Interrupt *** "); |
| 333 | #endif |
| 334 | /* Reset Timer Expired and Timers Interrupt Status */ |
| 335 | immr->im_clkrstk.cark_plprcrk = KAPWR_KEY; |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 336 | __asm__ ("nop"); |
wdenk | 2535d60 | 2003-07-17 23:16:40 +0000 | [diff] [blame^] | 337 | #ifdef CONFIG_MPC866_et_al |
| 338 | immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS; |
| 339 | #else |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 340 | immr->im_clkrst.car_plprcr |= PLPRCR_TEXPS | PLPRCR_TMIST; |
wdenk | 2535d60 | 2003-07-17 23:16:40 +0000 | [diff] [blame^] | 341 | #endif |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 342 | /* Restore Decrementer Count */ |
| 343 | set_dec (decrementer_count); |
| 344 | |
| 345 | timestamp++; |
| 346 | |
| 347 | #ifdef CONFIG_STATUS_LED |
| 348 | status_led_tick (timestamp); |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 349 | #endif /* CONFIG_STATUS_LED */ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 350 | |
| 351 | #if defined(CONFIG_WATCHDOG) || defined(CFG_CMA_LCD_HEARTBEAT) |
| 352 | |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 353 | /* |
| 354 | * The shortest watchdog period of all boards (except LWMON) |
| 355 | * is approx. 1 sec, thus re-trigger watchdog at least |
| 356 | * every 500 ms = CFG_HZ / 2 |
| 357 | */ |
| 358 | #ifndef CONFIG_LWMON |
| 359 | if ((timestamp % (CFG_HZ / 2)) == 0) { |
| 360 | #else |
| 361 | if ((timestamp % (CFG_HZ / 20)) == 0) { |
| 362 | #endif |
| 363 | |
| 364 | #if defined(CFG_CMA_LCD_HEARTBEAT) |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 365 | extern void lcd_heartbeat (void); |
| 366 | |
| 367 | lcd_heartbeat (); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 368 | #endif /* CFG_CMA_LCD_HEARTBEAT */ |
| 369 | |
| 370 | #if defined(CONFIG_WATCHDOG) |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 371 | reset_8xx_watchdog (immr); |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 372 | #endif /* CONFIG_WATCHDOG */ |
| 373 | |
| 374 | } |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 375 | #endif /* CONFIG_WATCHDOG || CFG_CMA_LCD_HEARTBEAT */ |
| 376 | } |
| 377 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 378 | /************************************************************************/ |
wdenk | 0de1ffc | 2002-10-25 20:52:57 +0000 | [diff] [blame] | 379 | |
| 380 | void reset_timer (void) |
| 381 | { |
| 382 | timestamp = 0; |
| 383 | } |
| 384 | |
| 385 | ulong get_timer (ulong base) |
| 386 | { |
| 387 | return (timestamp - base); |
| 388 | } |
| 389 | |
| 390 | void set_timer (ulong t) |
| 391 | { |
| 392 | timestamp = t; |
| 393 | } |
| 394 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 395 | /************************************************************************/ |