interrupts.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. * Rob Taylor, Flying Pig Systems. robt@flyingpig.com
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <mpc824x.h>
  26. #include <asm/processor.h>
  27. #include <asm/pci_io.h>
  28. #include <commproc.h>
  29. #include <watchdog.h>
  30. #include "drivers/epic.h"
  31. /****************************************************************************/
  32. unsigned decrementer_count; /* count val for 1e6/HZ microseconds */
  33. static __inline__ unsigned long get_msr (void)
  34. {
  35. unsigned long msr;
  36. asm volatile ("mfmsr %0":"=r" (msr):);
  37. return msr;
  38. }
  39. static __inline__ void set_msr (unsigned long msr)
  40. {
  41. asm volatile ("mtmsr %0"::"r" (msr));
  42. }
  43. static __inline__ unsigned long get_dec (void)
  44. {
  45. unsigned long val;
  46. asm volatile ("mfdec %0":"=r" (val):);
  47. return val;
  48. }
  49. static __inline__ void set_dec (unsigned long val)
  50. {
  51. asm volatile ("mtdec %0"::"r" (val));
  52. }
  53. void enable_interrupts (void)
  54. {
  55. set_msr (get_msr () | MSR_EE);
  56. }
  57. /* returns flag if MSR_EE was set before */
  58. int disable_interrupts (void)
  59. {
  60. ulong msr = get_msr ();
  61. set_msr (msr & ~MSR_EE);
  62. return ((msr & MSR_EE) != 0);
  63. }
  64. /****************************************************************************/
  65. int interrupt_init (void)
  66. {
  67. decrementer_count = (get_bus_freq (0) / 4) / CFG_HZ;
  68. /*
  69. * It's all broken at the moment and I currently don't need
  70. * interrupts. If you want to fix it, have a look at the epic
  71. * drivers in dink32 v12. They do everthing and Motorola said
  72. * I could use the dink source in this project as long as
  73. * copyright notices remain intact.
  74. */
  75. epicInit (EPIC_DIRECT_IRQ, 0);
  76. /* EPIC won't generate INT unless Current Task Pri < 15 */
  77. epicCurTaskPrioSet(0);
  78. set_dec (decrementer_count);
  79. set_msr (get_msr () | MSR_EE);
  80. return (0);
  81. }
  82. /****************************************************************************/
  83. /*
  84. * Handle external interrupts
  85. */
  86. void external_interrupt (struct pt_regs *regs)
  87. {
  88. register unsigned long temp;
  89. pci_readl (CFG_EUMB_ADDR + EPIC_PROC_INT_ACK_REG, temp);
  90. sync (); /* i'm not convinced this is needed, but dink source has it */
  91. temp &= 0xff; /*get vector */
  92. /*TODO: handle them -... */
  93. epicEOI ();
  94. }
  95. /****************************************************************************/
  96. /*
  97. * blank int handlers.
  98. */
  99. void
  100. irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
  101. {
  102. }
  103. void irq_free_handler (int vec)
  104. {
  105. }
  106. /*TODO: some handlers for winbond and 87308 interrupts
  107. and what about generic pci inteerupts?
  108. vga?
  109. */
  110. volatile ulong timestamp = 0;
  111. void timer_interrupt (struct pt_regs *regs)
  112. {
  113. /* Restore Decrementer Count */
  114. set_dec (decrementer_count);
  115. timestamp++;
  116. #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
  117. if ((timestamp % (CFG_HZ / 2)) == 0) {
  118. WATCHDOG_RESET ();
  119. }
  120. #endif /* CONFIG_WATCHDOG */
  121. #if defined(CONFIG_SHOW_ACTIVITY) && defined(CONFIG_OXC)
  122. if ((timestamp % (CFG_HZ / 10)) == 0) {
  123. {
  124. extern void oxc_toggle_activeled (void);
  125. oxc_toggle_activeled ();
  126. }
  127. }
  128. #endif
  129. }
  130. void reset_timer (void)
  131. {
  132. timestamp = 0;
  133. }
  134. ulong get_timer (ulong base)
  135. {
  136. return (timestamp - base);
  137. }
  138. void set_timer (ulong t)
  139. {
  140. timestamp = t;
  141. }