interrupts.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 "drivers/epic.h"
  30. /****************************************************************************/
  31. unsigned decrementer_count; /* count val for 1e6/HZ microseconds */
  32. static __inline__ unsigned long get_msr (void)
  33. {
  34. unsigned long msr;
  35. asm volatile ("mfmsr %0":"=r" (msr):);
  36. return msr;
  37. }
  38. static __inline__ void set_msr (unsigned long msr)
  39. {
  40. asm volatile ("mtmsr %0"::"r" (msr));
  41. }
  42. static __inline__ unsigned long get_dec (void)
  43. {
  44. unsigned long val;
  45. asm volatile ("mfdec %0":"=r" (val):);
  46. return val;
  47. }
  48. static __inline__ void set_dec (unsigned long val)
  49. {
  50. asm volatile ("mtdec %0"::"r" (val));
  51. }
  52. void enable_interrupts (void)
  53. {
  54. set_msr (get_msr () | MSR_EE);
  55. }
  56. /* returns flag if MSR_EE was set before */
  57. int disable_interrupts (void)
  58. {
  59. ulong msr = get_msr ();
  60. set_msr (msr & ~MSR_EE);
  61. return ((msr & MSR_EE) != 0);
  62. }
  63. /****************************************************************************/
  64. int interrupt_init (void)
  65. {
  66. decrementer_count = (get_bus_freq (0) / 4) / CFG_HZ;
  67. /*
  68. * It's all broken at the moment and I currently don't need
  69. * interrupts. If you want to fix it, have a look at the epic
  70. * drivers in dink32 v12. They do everthing and Motorola said
  71. * I could use the dink source in this project as long as
  72. * copyright notices remain intact.
  73. */
  74. epicInit (EPIC_DIRECT_IRQ, 0);
  75. set_dec (decrementer_count);
  76. set_msr (get_msr () | MSR_EE);
  77. return (0);
  78. }
  79. /****************************************************************************/
  80. /*
  81. * Handle external interrupts
  82. */
  83. void external_interrupt (struct pt_regs *regs)
  84. {
  85. register unsigned long temp;
  86. pci_readl (CFG_EUMB_ADDR + EPIC_PROC_INT_ACK_REG, temp);
  87. sync (); /* i'm not convinced this is needed, but dink source has it */
  88. temp &= 0xff; /*get vector */
  89. /*TODO: handle them -... */
  90. epicEOI ();
  91. }
  92. /****************************************************************************/
  93. /*
  94. * blank int handlers.
  95. */
  96. void
  97. irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
  98. {
  99. }
  100. void irq_free_handler (int vec)
  101. {
  102. }
  103. /*TODO: some handlers for winbond and 87308 interrupts
  104. and what about generic pci inteerupts?
  105. vga?
  106. */
  107. volatile ulong timestamp = 0;
  108. void timer_interrupt (struct pt_regs *regs)
  109. {
  110. /* Restore Decrementer Count */
  111. set_dec (decrementer_count);
  112. timestamp++;
  113. #if defined(CONFIG_WATCHDOG)
  114. if ((timestamp % (CFG_HZ / 2)) == 0) {
  115. #if defined(CONFIG_OXC)
  116. {
  117. extern void oxc_wdt_reset (void);
  118. oxc_wdt_reset ();
  119. }
  120. #endif
  121. }
  122. #endif /* CONFIG_WATCHDOG */
  123. #if defined(CONFIG_SHOW_ACTIVITY) && defined(CONFIG_OXC)
  124. if ((timestamp % (CFG_HZ / 10)) == 0) {
  125. {
  126. extern void oxc_toggle_activeled (void);
  127. oxc_toggle_activeled ();
  128. }
  129. }
  130. #endif
  131. }
  132. void reset_timer (void)
  133. {
  134. timestamp = 0;
  135. }
  136. ulong get_timer (ulong base)
  137. {
  138. return (timestamp - base);
  139. }
  140. void set_timer (ulong t)
  141. {
  142. timestamp = t;
  143. }