interrupts.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_M5271
  29. #include <asm/m5271.h>
  30. #include <asm/immap_5271.h>
  31. #endif
  32. #ifdef CONFIG_M5272
  33. #include <asm/m5272.h>
  34. #include <asm/immap_5272.h>
  35. #endif
  36. #ifdef CONFIG_M5282
  37. #include <asm/m5282.h>
  38. #include <asm/immap_5282.h>
  39. #endif
  40. #ifdef CONFIG_M5249
  41. #include <asm/m5249.h>
  42. #endif
  43. #define NR_IRQS 31
  44. /*
  45. * Interrupt vector functions.
  46. */
  47. struct interrupt_action {
  48. interrupt_handler_t *handler;
  49. void *arg;
  50. };
  51. static struct interrupt_action irq_vecs[NR_IRQS];
  52. static __inline__ unsigned short get_sr (void)
  53. {
  54. unsigned short sr;
  55. asm volatile ("move.w %%sr,%0":"=r" (sr):);
  56. return sr;
  57. }
  58. static __inline__ void set_sr (unsigned short sr)
  59. {
  60. asm volatile ("move.w %0,%%sr"::"r" (sr));
  61. }
  62. /************************************************************************/
  63. /*
  64. * Install and free an interrupt handler
  65. */
  66. void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
  67. {
  68. #ifdef CONFIG_M5272
  69. volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
  70. #endif
  71. int vec_base = 0;
  72. #ifdef CONFIG_M5272
  73. vec_base = intp->int_pivr & 0xe0;
  74. #endif
  75. if ((vec < vec_base) || (vec > vec_base + NR_IRQS)) {
  76. printf ("irq_install_handler: wrong interrupt vector %d\n",
  77. vec);
  78. return;
  79. }
  80. irq_vecs[vec - vec_base].handler = handler;
  81. irq_vecs[vec - vec_base].arg = arg;
  82. }
  83. void irq_free_handler (int vec)
  84. {
  85. #ifdef CONFIG_M5272
  86. volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
  87. #endif
  88. int vec_base = 0;
  89. #ifdef CONFIG_M5272
  90. vec_base = intp->int_pivr & 0xe0;
  91. #endif
  92. if ((vec < vec_base) || (vec > vec_base + NR_IRQS)) {
  93. return;
  94. }
  95. irq_vecs[vec - vec_base].handler = NULL;
  96. irq_vecs[vec - vec_base].arg = NULL;
  97. }
  98. void enable_interrupts (void)
  99. {
  100. unsigned short sr;
  101. sr = get_sr ();
  102. set_sr (sr & ~0x0700);
  103. }
  104. int disable_interrupts (void)
  105. {
  106. unsigned short sr;
  107. sr = get_sr ();
  108. set_sr (sr | 0x0700);
  109. return ((sr & 0x0700) == 0); /* return TRUE, if interrupts were enabled before */
  110. }
  111. void int_handler (struct pt_regs *fp)
  112. {
  113. #ifdef CONFIG_M5272
  114. volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
  115. #endif
  116. int vec, vec_base = 0;
  117. vec = (fp->vector >> 2) & 0xff;
  118. #ifdef CONFIG_M5272
  119. vec_base = intp->int_pivr & 0xe0;
  120. #endif
  121. if (irq_vecs[vec - vec_base].handler != NULL) {
  122. irq_vecs[vec -
  123. vec_base].handler (irq_vecs[vec - vec_base].arg);
  124. } else {
  125. printf ("\nBogus External Interrupt Vector %d\n", vec);
  126. }
  127. }
  128. #ifdef CONFIG_M5272
  129. int interrupt_init (void)
  130. {
  131. volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
  132. /* disable all external interrupts */
  133. intp->int_icr1 = 0x88888888;
  134. intp->int_icr2 = 0x88888888;
  135. intp->int_icr3 = 0x88888888;
  136. intp->int_icr4 = 0x88888888;
  137. intp->int_pitr = 0x00000000;
  138. /* initialize vector register */
  139. intp->int_pivr = 0x40;
  140. enable_interrupts ();
  141. return 0;
  142. }
  143. #endif
  144. #if defined(CONFIG_M5282) || defined(CONFIG_M5271)
  145. int interrupt_init (void)
  146. {
  147. return 0;
  148. }
  149. #endif
  150. #ifdef CONFIG_M5249
  151. int interrupt_init (void)
  152. {
  153. enable_interrupts ();
  154. return 0;
  155. }
  156. #endif