intc-simr.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * intc-simr.c
  3. *
  4. * Interrupt controller code for the ColdFire 5208, 5207 & 532x parts.
  5. *
  6. * (C) Copyright 2009-2011, Greg Ungerer <gerg@snapgear.com>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file COPYING in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/types.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/irq.h>
  17. #include <linux/io.h>
  18. #include <asm/coldfire.h>
  19. #include <asm/mcfsim.h>
  20. #include <asm/traps.h>
  21. /*
  22. * The EDGE Port interrupts are the fixed 7 external interrupts.
  23. * They need some special treatment, for example they need to be acked.
  24. */
  25. #ifdef CONFIG_M520x
  26. /*
  27. * The 520x parts only support a limited range of these external
  28. * interrupts, only 1, 4 and 7 (as interrupts 65, 66 and 67).
  29. */
  30. #define EINT0 64 /* Is not actually used, but spot reserved for it */
  31. #define EINT1 65 /* EDGE Port interrupt 1 */
  32. #define EINT4 66 /* EDGE Port interrupt 4 */
  33. #define EINT7 67 /* EDGE Port interrupt 7 */
  34. static unsigned int irqebitmap[] = { 0, 1, 4, 7 };
  35. static unsigned int inline irq2ebit(unsigned int irq)
  36. {
  37. return irqebitmap[irq - EINT0];
  38. }
  39. #else
  40. /*
  41. * Most of the ColdFire parts with the EDGE Port module just have
  42. * a strait direct mapping of the 7 external interrupts. Although
  43. * there is a bit reserved for 0, it is not used.
  44. */
  45. #define EINT0 64 /* Is not actually used, but spot reserved for it */
  46. #define EINT1 65 /* EDGE Port interrupt 1 */
  47. #define EINT7 71 /* EDGE Port interrupt 7 */
  48. static unsigned int inline irq2ebit(unsigned int irq)
  49. {
  50. return irq - EINT0;
  51. }
  52. #endif
  53. /*
  54. * There maybe one, two or three interrupt control units, each has 64
  55. * interrupts. If there is no second or third unit then MCFINTC1_* or
  56. * MCFINTC2_* defines will be 0 (and code for them optimized away).
  57. */
  58. static void intc_irq_mask(struct irq_data *d)
  59. {
  60. unsigned int irq = d->irq - MCFINT_VECBASE;
  61. if (MCFINTC2_SIMR && (irq > 128))
  62. __raw_writeb(irq - 128, MCFINTC2_SIMR);
  63. else if (MCFINTC1_SIMR && (irq > 64))
  64. __raw_writeb(irq - 64, MCFINTC1_SIMR);
  65. else
  66. __raw_writeb(irq, MCFINTC0_SIMR);
  67. }
  68. static void intc_irq_unmask(struct irq_data *d)
  69. {
  70. unsigned int irq = d->irq - MCFINT_VECBASE;
  71. if (MCFINTC2_CIMR && (irq > 128))
  72. __raw_writeb(irq - 128, MCFINTC2_CIMR);
  73. else if (MCFINTC1_CIMR && (irq > 64))
  74. __raw_writeb(irq - 64, MCFINTC1_CIMR);
  75. else
  76. __raw_writeb(irq, MCFINTC0_CIMR);
  77. }
  78. static void intc_irq_ack(struct irq_data *d)
  79. {
  80. unsigned int ebit = irq2ebit(d->irq);
  81. __raw_writeb(0x1 << ebit, MCFEPORT_EPFR);
  82. }
  83. static unsigned int intc_irq_startup(struct irq_data *d)
  84. {
  85. unsigned int irq = d->irq;
  86. if ((irq >= EINT1) && (irq <= EINT7)) {
  87. unsigned int ebit = irq2ebit(irq);
  88. u8 v;
  89. #if defined(MCFEPORT_EPDDR)
  90. /* Set EPORT line as input */
  91. v = __raw_readb(MCFEPORT_EPDDR);
  92. __raw_writeb(v & ~(0x1 << ebit), MCFEPORT_EPDDR);
  93. #endif
  94. /* Set EPORT line as interrupt source */
  95. v = __raw_readb(MCFEPORT_EPIER);
  96. __raw_writeb(v | (0x1 << ebit), MCFEPORT_EPIER);
  97. }
  98. irq -= MCFINT_VECBASE;
  99. if (MCFINTC2_ICR0 && (irq > 128))
  100. __raw_writeb(5, MCFINTC2_ICR0 + irq - 128);
  101. else if (MCFINTC1_ICR0 && (irq > 64))
  102. __raw_writeb(5, MCFINTC1_ICR0 + irq - 64);
  103. else
  104. __raw_writeb(5, MCFINTC0_ICR0 + irq);
  105. intc_irq_unmask(d);
  106. return 0;
  107. }
  108. static int intc_irq_set_type(struct irq_data *d, unsigned int type)
  109. {
  110. unsigned int ebit, irq = d->irq;
  111. u16 pa, tb;
  112. switch (type) {
  113. case IRQ_TYPE_EDGE_RISING:
  114. tb = 0x1;
  115. break;
  116. case IRQ_TYPE_EDGE_FALLING:
  117. tb = 0x2;
  118. break;
  119. case IRQ_TYPE_EDGE_BOTH:
  120. tb = 0x3;
  121. break;
  122. default:
  123. /* Level triggered */
  124. tb = 0;
  125. break;
  126. }
  127. if (tb)
  128. irq_set_handler(irq, handle_edge_irq);
  129. ebit = irq2ebit(irq) * 2;
  130. pa = __raw_readw(MCFEPORT_EPPAR);
  131. pa = (pa & ~(0x3 << ebit)) | (tb << ebit);
  132. __raw_writew(pa, MCFEPORT_EPPAR);
  133. return 0;
  134. }
  135. static struct irq_chip intc_irq_chip = {
  136. .name = "CF-INTC",
  137. .irq_startup = intc_irq_startup,
  138. .irq_mask = intc_irq_mask,
  139. .irq_unmask = intc_irq_unmask,
  140. };
  141. static struct irq_chip intc_irq_chip_edge_port = {
  142. .name = "CF-INTC-EP",
  143. .irq_startup = intc_irq_startup,
  144. .irq_mask = intc_irq_mask,
  145. .irq_unmask = intc_irq_unmask,
  146. .irq_ack = intc_irq_ack,
  147. .irq_set_type = intc_irq_set_type,
  148. };
  149. void __init init_IRQ(void)
  150. {
  151. int irq, eirq;
  152. /* Mask all interrupt sources */
  153. __raw_writeb(0xff, MCFINTC0_SIMR);
  154. if (MCFINTC1_SIMR)
  155. __raw_writeb(0xff, MCFINTC1_SIMR);
  156. if (MCFINTC2_SIMR)
  157. __raw_writeb(0xff, MCFINTC2_SIMR);
  158. eirq = MCFINT_VECBASE + 64 + (MCFINTC1_ICR0 ? 64 : 0) +
  159. (MCFINTC2_ICR0 ? 64 : 0);
  160. for (irq = MCFINT_VECBASE; (irq < eirq); irq++) {
  161. if ((irq >= EINT1) && (irq <= EINT7))
  162. irq_set_chip(irq, &intc_irq_chip_edge_port);
  163. else
  164. irq_set_chip(irq, &intc_irq_chip);
  165. irq_set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
  166. irq_set_handler(irq, handle_level_irq);
  167. }
  168. }