intc-2.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * intc-2.c
  3. *
  4. * General interrupt controller code for the many ColdFire cores that use
  5. * interrupt controllers with 63 interrupt sources, organized as 56 fully-
  6. * programmable + 7 fixed-level interrupt sources. This includes the 523x
  7. * family, the 5270, 5271, 5274, 5275, and the 528x family which have two such
  8. * controllers, and the 547x and 548x families which have only one of them.
  9. *
  10. * The external 7 fixed interrupts are part the the Edge Port unit of these
  11. * ColdFire parts. They can be configured as level or edge triggered.
  12. *
  13. * (C) Copyright 2009-2011, Greg Ungerer <gerg@snapgear.com>
  14. *
  15. * This file is subject to the terms and conditions of the GNU General Public
  16. * License. See the file COPYING in the main directory of this archive
  17. * for more details.
  18. */
  19. #include <linux/types.h>
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/io.h>
  25. #include <asm/coldfire.h>
  26. #include <asm/mcfsim.h>
  27. #include <asm/traps.h>
  28. /*
  29. * Bit definitions for the ICR family of registers.
  30. */
  31. #define MCFSIM_ICR_LEVEL(l) ((l)<<3) /* Level l intr */
  32. #define MCFSIM_ICR_PRI(p) (p) /* Priority p intr */
  33. /*
  34. * The EDGE Port interrupts are the fixed 7 external interrupts.
  35. * They need some special treatment, for example they need to be acked.
  36. */
  37. #define EINT0 64 /* Is not actually used, but spot reserved for it */
  38. #define EINT1 65 /* EDGE Port interrupt 1 */
  39. #define EINT7 71 /* EDGE Port interrupt 7 */
  40. #ifdef MCFICM_INTC1
  41. #define NR_VECS 128
  42. #else
  43. #define NR_VECS 64
  44. #endif
  45. static void intc_irq_mask(struct irq_data *d)
  46. {
  47. unsigned int irq = d->irq - MCFINT_VECBASE;
  48. unsigned long imraddr;
  49. u32 val, imrbit;
  50. #ifdef MCFICM_INTC1
  51. imraddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
  52. #else
  53. imraddr = MCFICM_INTC0;
  54. #endif
  55. imraddr += (irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL;
  56. imrbit = 0x1 << (irq & 0x1f);
  57. val = __raw_readl(imraddr);
  58. __raw_writel(val | imrbit, imraddr);
  59. }
  60. static void intc_irq_unmask(struct irq_data *d)
  61. {
  62. unsigned int irq = d->irq - MCFINT_VECBASE;
  63. unsigned long imraddr;
  64. u32 val, imrbit;
  65. #ifdef MCFICM_INTC1
  66. imraddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
  67. #else
  68. imraddr = MCFICM_INTC0;
  69. #endif
  70. imraddr += ((irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL);
  71. imrbit = 0x1 << (irq & 0x1f);
  72. /* Don't set the "maskall" bit! */
  73. if ((irq & 0x20) == 0)
  74. imrbit |= 0x1;
  75. val = __raw_readl(imraddr);
  76. __raw_writel(val & ~imrbit, imraddr);
  77. }
  78. /*
  79. * Only the external (or EDGE Port) interrupts need to be acknowledged
  80. * here, as part of the IRQ handler. They only really need to be ack'ed
  81. * if they are in edge triggered mode, but there is no harm in doing it
  82. * for all types.
  83. */
  84. static void intc_irq_ack(struct irq_data *d)
  85. {
  86. unsigned int irq = d->irq;
  87. __raw_writeb(0x1 << (irq - EINT0), MCFEPORT_EPFR);
  88. }
  89. /*
  90. * Each vector needs a unique priority and level associated with it.
  91. * We don't really care so much what they are, we don't rely on the
  92. * traditional priority interrupt scheme of the m68k/ColdFire. This
  93. * only needs to be set once for an interrupt, and we will never change
  94. * these values once we have set them.
  95. */
  96. static u8 intc_intpri = MCFSIM_ICR_LEVEL(6) | MCFSIM_ICR_PRI(6);
  97. static unsigned int intc_irq_startup(struct irq_data *d)
  98. {
  99. unsigned int irq = d->irq - MCFINT_VECBASE;
  100. unsigned long icraddr;
  101. #ifdef MCFICM_INTC1
  102. icraddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
  103. #else
  104. icraddr = MCFICM_INTC0;
  105. #endif
  106. icraddr += MCFINTC_ICR0 + (irq & 0x3f);
  107. if (__raw_readb(icraddr) == 0)
  108. __raw_writeb(intc_intpri--, icraddr);
  109. irq = d->irq;
  110. if ((irq >= EINT1) && (irq <= EINT7)) {
  111. u8 v;
  112. irq -= EINT0;
  113. /* Set EPORT line as input */
  114. v = __raw_readb(MCFEPORT_EPDDR);
  115. __raw_writeb(v & ~(0x1 << irq), MCFEPORT_EPDDR);
  116. /* Set EPORT line as interrupt source */
  117. v = __raw_readb(MCFEPORT_EPIER);
  118. __raw_writeb(v | (0x1 << irq), MCFEPORT_EPIER);
  119. }
  120. intc_irq_unmask(d);
  121. return 0;
  122. }
  123. static int intc_irq_set_type(struct irq_data *d, unsigned int type)
  124. {
  125. unsigned int irq = d->irq;
  126. u16 pa, tb;
  127. switch (type) {
  128. case IRQ_TYPE_EDGE_RISING:
  129. tb = 0x1;
  130. break;
  131. case IRQ_TYPE_EDGE_FALLING:
  132. tb = 0x2;
  133. break;
  134. case IRQ_TYPE_EDGE_BOTH:
  135. tb = 0x3;
  136. break;
  137. default:
  138. /* Level triggered */
  139. tb = 0;
  140. break;
  141. }
  142. if (tb)
  143. irq_set_handler(irq, handle_edge_irq);
  144. irq -= EINT0;
  145. pa = __raw_readw(MCFEPORT_EPPAR);
  146. pa = (pa & ~(0x3 << (irq * 2))) | (tb << (irq * 2));
  147. __raw_writew(pa, MCFEPORT_EPPAR);
  148. return 0;
  149. }
  150. static struct irq_chip intc_irq_chip = {
  151. .name = "CF-INTC",
  152. .irq_startup = intc_irq_startup,
  153. .irq_mask = intc_irq_mask,
  154. .irq_unmask = intc_irq_unmask,
  155. };
  156. static struct irq_chip intc_irq_chip_edge_port = {
  157. .name = "CF-INTC-EP",
  158. .irq_startup = intc_irq_startup,
  159. .irq_mask = intc_irq_mask,
  160. .irq_unmask = intc_irq_unmask,
  161. .irq_ack = intc_irq_ack,
  162. .irq_set_type = intc_irq_set_type,
  163. };
  164. void __init init_IRQ(void)
  165. {
  166. int irq;
  167. /* Mask all interrupt sources */
  168. __raw_writel(0x1, MCFICM_INTC0 + MCFINTC_IMRL);
  169. #ifdef MCFICM_INTC1
  170. __raw_writel(0x1, MCFICM_INTC1 + MCFINTC_IMRL);
  171. #endif
  172. for (irq = MCFINT_VECBASE; (irq < MCFINT_VECBASE + NR_VECS); irq++) {
  173. if ((irq >= EINT1) && (irq <=EINT7))
  174. irq_set_chip(irq, &intc_irq_chip_edge_port);
  175. else
  176. irq_set_chip(irq, &intc_irq_chip);
  177. irq_set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
  178. irq_set_handler(irq, handle_level_irq);
  179. }
  180. }