Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | /* * (C) Copyright 2000-2002 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 22-Oct-00 */ #include <common.h> #include <watchdog.h> #include <command.h> #include <mpc8260.h> #include <mpc8260_irq.h> #include <asm/processor.h> #ifdef CONFIG_STATUS_LED #include <status_led.h> #endif /****************************************************************************/ unsigned decrementer_count; /* count val for 1e6/HZ microseconds */ struct irq_action { interrupt_handler_t *handler; void *arg; ulong count; }; static struct irq_action irq_handlers[NR_IRQS]; static ulong ppc_cached_irq_mask[NR_MASK_WORDS]; /****************************************************************************/ /* this section was ripped out of arch/ppc/kernel/ppc8260_pic.c in the */ /* Linux/PPC 2.4.x source. There was no copyright notice in that file. */ /* The 8260 internal interrupt controller. It is usually * the only interrupt controller. * There are two 32-bit registers (high/low) for up to 64 * possible interrupts. * * Now, the fun starts.....Interrupt Numbers DO NOT MAP * in a simple arithmetic fashion to mask or pending registers. * That is, interrupt 4 does not map to bit position 4. * We create two tables, indexed by vector number, to indicate * which register to use and which bit in the register to use. */ static u_char irq_to_siureg[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static u_char irq_to_siubit[] = { 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 29, 30, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; static void m8260_mask_irq (unsigned int irq_nr) { volatile immap_t *immr = (immap_t *) CFG_IMMR; int bit, word; volatile uint *simr; bit = irq_to_siubit[irq_nr]; word = irq_to_siureg[irq_nr]; simr = &(immr->im_intctl.ic_simrh); ppc_cached_irq_mask[word] &= ~(1 << (31 - bit)); simr[word] = ppc_cached_irq_mask[word]; } static void m8260_unmask_irq (unsigned int irq_nr) { volatile immap_t *immr = (immap_t *) CFG_IMMR; int bit, word; volatile uint *simr; bit = irq_to_siubit[irq_nr]; word = irq_to_siureg[irq_nr]; simr = &(immr->im_intctl.ic_simrh); ppc_cached_irq_mask[word] |= (1 << (31 - bit)); simr[word] = ppc_cached_irq_mask[word]; } static void m8260_mask_and_ack (unsigned int irq_nr) { volatile immap_t *immr = (immap_t *) CFG_IMMR; int bit, word; volatile uint *simr, *sipnr; bit = irq_to_siubit[irq_nr]; word = irq_to_siureg[irq_nr]; simr = &(immr->im_intctl.ic_simrh); sipnr = &(immr->im_intctl.ic_sipnrh); ppc_cached_irq_mask[word] &= ~(1 << (31 - bit)); simr[word] = ppc_cached_irq_mask[word]; sipnr[word] = 1 << (31 - bit); } static int m8260_get_irq (struct pt_regs *regs) { volatile immap_t *immr = (immap_t *) CFG_IMMR; int irq; unsigned long bits; /* For MPC8260, read the SIVEC register and shift the bits down * to get the irq number. */ bits = immr->im_intctl.ic_sivec; irq = bits >> 26; return irq; } /* end of code ripped out of arch/ppc/kernel/ppc8260_pic.c */ /****************************************************************************/ static __inline__ unsigned long get_msr (void) { unsigned long msr; __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); return msr; } static __inline__ void set_msr (unsigned long msr) { __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); } static __inline__ unsigned long get_dec (void) { unsigned long val; __asm__ __volatile__ ("mfdec %0":"=r" (val):); return val; } static __inline__ void set_dec (unsigned long val) { __asm__ __volatile__ ("mtdec %0"::"r" (val)); } void enable_interrupts (void) { set_msr (get_msr () | MSR_EE); } /* returns flag if MSR_EE was set before */ int disable_interrupts (void) { ulong msr = get_msr (); set_msr (msr & ~MSR_EE); return ((msr & MSR_EE) != 0); } /****************************************************************************/ int interrupt_init (void) { DECLARE_GLOBAL_DATA_PTR; volatile immap_t *immr = (immap_t *) CFG_IMMR; decrementer_count = (gd->bus_clk / 4) / CFG_HZ; /* Initialize the default interrupt mapping priorities */ immr->im_intctl.ic_sicr = 0; immr->im_intctl.ic_siprr = 0x05309770; immr->im_intctl.ic_scprrh = 0x05309770; immr->im_intctl.ic_scprrl = 0x05309770; /* disable all interrupts and clear all pending bits */ immr->im_intctl.ic_simrh = ppc_cached_irq_mask[0] = 0; immr->im_intctl.ic_simrl = ppc_cached_irq_mask[1] = 0; immr->im_intctl.ic_sipnrh = 0xffffffff; immr->im_intctl.ic_sipnrl = 0xffffffff; set_dec (decrementer_count); set_msr (get_msr () | MSR_EE); return (0); } /****************************************************************************/ /* * Handle external interrupts */ void external_interrupt (struct pt_regs *regs) { int irq, unmask = 1; irq = m8260_get_irq (regs); m8260_mask_and_ack (irq); set_msr (get_msr () | MSR_EE); if (irq_handlers[irq].handler != NULL) (*irq_handlers[irq].handler) (irq_handlers[irq].arg); else { printf ("\nBogus External Interrupt IRQ %d\n", irq); /* * turn off the bogus interrupt, otherwise it * might repeat forever */ unmask = 0; } if (unmask) m8260_unmask_irq (irq); } /****************************************************************************/ /* * Install and free an interrupt handler. */ void irq_install_handler (int irq, interrupt_handler_t * handler, void *arg) { if (irq < 0 || irq >= NR_IRQS) { printf ("irq_install_handler: bad irq number %d\n", irq); return; } if (irq_handlers[irq].handler != NULL) printf ("irq_install_handler: 0x%08lx replacing 0x%08lx\n", (ulong) handler, (ulong) irq_handlers[irq].handler); irq_handlers[irq].handler = handler; irq_handlers[irq].arg = arg; m8260_unmask_irq (irq); } void irq_free_handler (int irq) { if (irq < 0 || irq >= NR_IRQS) { printf ("irq_free_handler: bad irq number %d\n", irq); return; } m8260_mask_irq (irq); irq_handlers[irq].handler = NULL; irq_handlers[irq].arg = NULL; } /****************************************************************************/ volatile ulong timestamp = 0; /* * timer_interrupt - gets called when the decrementer overflows, * with interrupts disabled. * Trivial implementation - no need to be really accurate. */ void timer_interrupt (struct pt_regs *regs) { #if defined(CONFIG_WATCHDOG) || defined(CFG_HYMOD_DBLEDS) volatile immap_t *immr = (immap_t *) CFG_IMMR; #endif /* CONFIG_WATCHDOG */ /* Restore Decrementer Count */ set_dec (decrementer_count); timestamp++; #if defined(CONFIG_WATCHDOG) || \ defined(CFG_CMA_LCD_HEARTBEAT) || \ defined(CFG_HYMOD_DBLEDS) if ((timestamp % CFG_HZ) == 0) { #if defined(CFG_CMA_LCD_HEARTBEAT) extern void lcd_heartbeat (void); #endif /* CFG_CMA_LCD_HEARTBEAT */ #if defined(CFG_HYMOD_DBLEDS) volatile iop8260_t *iop = &immr->im_ioport; static int shift = 0; #endif /* CFG_HYMOD_DBLEDS */ #if defined(CFG_CMA_LCD_HEARTBEAT) lcd_heartbeat (); #endif /* CFG_CMA_LCD_HEARTBEAT */ #if defined(CONFIG_WATCHDOG) reset_8260_watchdog (immr); #endif /* CONFIG_WATCHDOG */ #if defined(CFG_HYMOD_DBLEDS) /* hymod daughter board LEDs */ if (++shift > 3) shift = 0; iop->iop_pdatd = (iop->iop_pdatd & ~0x0f000000) | (1 << (24 + shift)); #endif /* CFG_HYMOD_DBLEDS */ } #endif /* CONFIG_WATCHDOG || CFG_CMA_LCD_HEARTBEAT */ #ifdef CONFIG_STATUS_LED status_led_tick (timestamp); #endif /* CONFIG_STATUS_LED */ } /****************************************************************************/ void reset_timer (void) { timestamp = 0; } ulong get_timer (ulong base) { return (timestamp - base); } void set_timer (ulong t) { timestamp = t; } /****************************************************************************/ #if (CONFIG_COMMANDS & CFG_CMD_IRQ) /* ripped this out of ppc4xx/interrupts.c */ /******************************************************************************* * * irqinfo - print information about PCI devices * */ void do_irqinfo (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[]) { int irq, re_enable; re_enable = disable_interrupts (); printf ("\nInterrupt-Information:\n"); printf ("Nr Routine Arg Count\n"); for (irq = 0; irq < 32; irq++) if (irq_handlers[irq].handler != NULL) printf ("%02d %08lx %08lx %ld\n", irq, (ulong) irq_handlers[irq].handler, (ulong) irq_handlers[irq].arg, irq_handlers[irq].count); if (re_enable) enable_interrupts (); } #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */ |