intc-2.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. * (C) Copyright 2009, Greg Ungerer <gerg@snapgear.com>
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file COPYING in the main directory of this archive
  14. * for more details.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/irq.h>
  21. #include <linux/io.h>
  22. #include <asm/coldfire.h>
  23. #include <asm/mcfsim.h>
  24. #include <asm/traps.h>
  25. /*
  26. * Bit definitions for the ICR family of registers.
  27. */
  28. #define MCFSIM_ICR_LEVEL(l) ((l)<<3) /* Level l intr */
  29. #define MCFSIM_ICR_PRI(p) (p) /* Priority p intr */
  30. /*
  31. * Each vector needs a unique priority and level associated with it.
  32. * We don't really care so much what they are, we don't rely on the
  33. * traditional priority interrupt scheme of the m68k/ColdFire.
  34. */
  35. static u8 intc_intpri = MCFSIM_ICR_LEVEL(6) | MCFSIM_ICR_PRI(6);
  36. #ifdef MCFICM_INTC1
  37. #define NR_VECS 128
  38. #else
  39. #define NR_VECS 64
  40. #endif
  41. static void intc_irq_mask(unsigned int irq)
  42. {
  43. if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECBASE + NR_VECS)) {
  44. unsigned long imraddr;
  45. u32 val, imrbit;
  46. irq -= MCFINT_VECBASE;
  47. imraddr = MCF_IPSBAR;
  48. #ifdef MCFICM_INTC1
  49. imraddr += (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
  50. #else
  51. imraddr += MCFICM_INTC0;
  52. #endif
  53. imraddr += (irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL;
  54. imrbit = 0x1 << (irq & 0x1f);
  55. val = __raw_readl(imraddr);
  56. __raw_writel(val | imrbit, imraddr);
  57. }
  58. }
  59. static void intc_irq_unmask(unsigned int irq)
  60. {
  61. if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECBASE + NR_VECS)) {
  62. unsigned long intaddr, imraddr, icraddr;
  63. u32 val, imrbit;
  64. irq -= MCFINT_VECBASE;
  65. intaddr = MCF_IPSBAR;
  66. #ifdef MCFICM_INTC1
  67. intaddr += (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
  68. #else
  69. intaddr += MCFICM_INTC0;
  70. #endif
  71. imraddr = intaddr + ((irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL);
  72. icraddr = intaddr + MCFINTC_ICR0 + (irq & 0x3f);
  73. imrbit = 0x1 << (irq & 0x1f);
  74. /* Don't set the "maskall" bit! */
  75. if ((irq & 0x20) == 0)
  76. imrbit |= 0x1;
  77. if (__raw_readb(icraddr) == 0)
  78. __raw_writeb(intc_intpri--, icraddr);
  79. val = __raw_readl(imraddr);
  80. __raw_writel(val & ~imrbit, imraddr);
  81. }
  82. }
  83. static struct irq_chip intc_irq_chip = {
  84. .name = "CF-INTC",
  85. .mask = intc_irq_mask,
  86. .unmask = intc_irq_unmask,
  87. };
  88. void __init init_IRQ(void)
  89. {
  90. int irq;
  91. init_vectors();
  92. /* Mask all interrupt sources */
  93. __raw_writel(0x1, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRL);
  94. #ifdef MCFICM_INTC1
  95. __raw_writel(0x1, MCF_IPSBAR + MCFICM_INTC1 + MCFINTC_IMRL);
  96. #endif
  97. for (irq = 0; (irq < NR_IRQS); irq++) {
  98. irq_desc[irq].status = IRQ_DISABLED;
  99. irq_desc[irq].action = NULL;
  100. irq_desc[irq].depth = 1;
  101. irq_desc[irq].chip = &intc_irq_chip;
  102. }
  103. }