interrupts.c 3.7 KB

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