intc-simr.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 or two interrupt control units, each has 64
  55. * interrupts. If there is no second unit then MCFINTC1_* defines
  56. * 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 (MCFINTC1_SIMR && (irq > 64))
  62. __raw_writeb(irq - 64, MCFINTC1_SIMR);
  63. else
  64. __raw_writeb(irq, MCFINTC0_SIMR);
  65. }
  66. static void intc_irq_unmask(struct irq_data *d)
  67. {
  68. unsigned int irq = d->irq - MCFINT_VECBASE;
  69. if (MCFINTC1_CIMR && (irq > 64))
  70. __raw_writeb(irq - 64, MCFINTC1_CIMR);
  71. else
  72. __raw_writeb(irq, MCFINTC0_CIMR);
  73. }
  74. static void intc_irq_ack(struct irq_data *d)
  75. {
  76. unsigned int ebit = irq2ebit(d->irq);
  77. __raw_writeb(0x1 << ebit, MCFEPORT_EPFR);
  78. }
  79. static unsigned int intc_irq_startup(struct irq_data *d)
  80. {
  81. unsigned int irq = d->irq;
  82. if ((irq >= EINT1) && (irq <= EINT7)) {
  83. unsigned int ebit = irq2ebit(irq);
  84. u8 v;
  85. /* Set EPORT line as input */
  86. v = __raw_readb(MCFEPORT_EPDDR);
  87. __raw_writeb(v & ~(0x1 << ebit), MCFEPORT_EPDDR);
  88. /* Set EPORT line as interrupt source */
  89. v = __raw_readb(MCFEPORT_EPIER);
  90. __raw_writeb(v | (0x1 << ebit), MCFEPORT_EPIER);
  91. }
  92. irq -= MCFINT_VECBASE;
  93. if (MCFINTC1_ICR0 && (irq > 64))
  94. __raw_writeb(5, MCFINTC1_ICR0 + irq - 64);
  95. else
  96. __raw_writeb(5, MCFINTC0_ICR0 + irq);
  97. intc_irq_unmask(d);
  98. return 0;
  99. }
  100. static int intc_irq_set_type(struct irq_data *d, unsigned int type)
  101. {
  102. unsigned int ebit, irq = d->irq;
  103. u16 pa, tb;
  104. switch (type) {
  105. case IRQ_TYPE_EDGE_RISING:
  106. tb = 0x1;
  107. break;
  108. case IRQ_TYPE_EDGE_FALLING:
  109. tb = 0x2;
  110. break;
  111. case IRQ_TYPE_EDGE_BOTH:
  112. tb = 0x3;
  113. break;
  114. default:
  115. /* Level triggered */
  116. tb = 0;
  117. break;
  118. }
  119. if (tb)
  120. irq_set_handler(irq, handle_edge_irq);
  121. ebit = irq2ebit(irq) * 2;
  122. pa = __raw_readw(MCFEPORT_EPPAR);
  123. pa = (pa & ~(0x3 << ebit)) | (tb << ebit);
  124. __raw_writew(pa, MCFEPORT_EPPAR);
  125. return 0;
  126. }
  127. static struct irq_chip intc_irq_chip = {
  128. .name = "CF-INTC",
  129. .irq_startup = intc_irq_startup,
  130. .irq_mask = intc_irq_mask,
  131. .irq_unmask = intc_irq_unmask,
  132. };
  133. static struct irq_chip intc_irq_chip_edge_port = {
  134. .name = "CF-INTC-EP",
  135. .irq_startup = intc_irq_startup,
  136. .irq_mask = intc_irq_mask,
  137. .irq_unmask = intc_irq_unmask,
  138. .irq_ack = intc_irq_ack,
  139. .irq_set_type = intc_irq_set_type,
  140. };
  141. void __init init_IRQ(void)
  142. {
  143. int irq, eirq;
  144. /* Mask all interrupt sources */
  145. __raw_writeb(0xff, MCFINTC0_SIMR);
  146. if (MCFINTC1_SIMR)
  147. __raw_writeb(0xff, MCFINTC1_SIMR);
  148. eirq = MCFINT_VECBASE + 64 + (MCFINTC1_ICR0 ? 64 : 0);
  149. for (irq = MCFINT_VECBASE; (irq < eirq); irq++) {
  150. if ((irq >= EINT1) && (irq <= EINT7))
  151. irq_set_chip(irq, &intc_irq_chip_edge_port);
  152. else
  153. irq_set_chip(irq, &intc_irq_chip);
  154. irq_set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
  155. irq_set_handler(irq, handle_level_irq);
  156. }
  157. }