interrupts.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * (C) Copyright 2003 Josef Baumgartner <josef.baumgartner@telex.de>
  3. *
  4. * (C) Copyright 2000-2004
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <watchdog.h>
  27. #include <asm/processor.h>
  28. #ifdef CONFIG_M5272
  29. #include <asm/m5272.h>
  30. #include <asm/immap_5272.h>
  31. #endif
  32. #ifdef CONFIG_M5282
  33. #include <asm/m5282.h>
  34. #include <asm/immap_5282.h>
  35. #endif
  36. #ifdef CONFIG_M5249
  37. #include <asm/m5249.h>
  38. #endif
  39. #define NR_IRQS 31
  40. /*
  41. * Interrupt vector functions.
  42. */
  43. struct interrupt_action {
  44. interrupt_handler_t *handler;
  45. void *arg;
  46. };
  47. static struct interrupt_action irq_vecs[NR_IRQS];
  48. static __inline__ unsigned short get_sr (void)
  49. {
  50. unsigned short sr;
  51. asm volatile ("move.w %%sr,%0":"=r" (sr):);
  52. return sr;
  53. }
  54. static __inline__ void set_sr (unsigned short sr)
  55. {
  56. asm volatile ("move.w %0,%%sr"::"r" (sr));
  57. }
  58. /************************************************************************/
  59. /*
  60. * Install and free an interrupt handler
  61. */
  62. void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
  63. {
  64. #ifdef CONFIG_M5272
  65. volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
  66. #endif
  67. int vec_base = 0;
  68. #ifdef CONFIG_M5272
  69. vec_base = intp->int_pivr & 0xe0;
  70. #endif
  71. if ((vec < vec_base) || (vec > vec_base + NR_IRQS)) {
  72. printf ("irq_install_handler: wrong interrupt vector %d\n",
  73. vec);
  74. return;
  75. }
  76. irq_vecs[vec - vec_base].handler = handler;
  77. irq_vecs[vec - vec_base].arg = arg;
  78. }
  79. void irq_free_handler (int vec)
  80. {
  81. #ifdef CONFIG_M5272
  82. volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
  83. #endif
  84. int vec_base = 0;
  85. #ifdef CONFIG_M5272
  86. vec_base = intp->int_pivr & 0xe0;
  87. #endif
  88. if ((vec < vec_base) || (vec > vec_base + NR_IRQS)) {
  89. return;
  90. }
  91. irq_vecs[vec - vec_base].handler = NULL;
  92. irq_vecs[vec - vec_base].arg = NULL;
  93. }
  94. void enable_interrupts (void)
  95. {
  96. unsigned short sr;
  97. sr = get_sr ();
  98. set_sr (sr & ~0x0700);
  99. }
  100. int disable_interrupts (void)
  101. {
  102. unsigned short sr;
  103. sr = get_sr ();
  104. set_sr (sr | 0x0700);
  105. return ((sr & 0x0700) == 0); /* return TRUE, if interrupts were enabled before */
  106. }
  107. void int_handler (struct pt_regs *fp)
  108. {
  109. #ifdef CONFIG_M5272
  110. volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
  111. #endif
  112. int vec, vec_base = 0;
  113. vec = (fp->vector >> 2) & 0xff;
  114. #ifdef CONFIG_M5272
  115. vec_base = intp->int_pivr & 0xe0;
  116. #endif
  117. if (irq_vecs[vec - vec_base].handler != NULL) {
  118. irq_vecs[vec -
  119. vec_base].handler (irq_vecs[vec - vec_base].arg);
  120. } else {
  121. printf ("\nBogus External Interrupt Vector %d\n", vec);
  122. }
  123. }
  124. #ifdef CONFIG_M5272
  125. int interrupt_init (void)
  126. {
  127. volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
  128. /* disable all external interrupts */
  129. intp->int_icr1 = 0x88888888;
  130. intp->int_icr2 = 0x88888888;
  131. intp->int_icr3 = 0x88888888;
  132. intp->int_icr4 = 0x88888888;
  133. intp->int_pitr = 0x00000000;
  134. /* initialize vector register */
  135. intp->int_pivr = 0x40;
  136. enable_interrupts ();
  137. return 0;
  138. }
  139. #endif
  140. #ifdef CONFIG_M5282
  141. int interrupt_init (void)
  142. {
  143. return 0;
  144. }
  145. #endif
  146. #ifdef CONFIG_M5249
  147. int interrupt_init (void)
  148. {
  149. enable_interrupts ();
  150. return 0;
  151. }
  152. #endif