intc-2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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(struct irq_data *d)
  42. {
  43. unsigned int irq = d->irq;
  44. if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECBASE + NR_VECS)) {
  45. unsigned long imraddr;
  46. u32 val, imrbit;
  47. irq -= MCFINT_VECBASE;
  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(struct irq_data *d)
  60. {
  61. unsigned int irq = d->irq;
  62. if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECBASE + NR_VECS)) {
  63. unsigned long intaddr, imraddr, icraddr;
  64. u32 val, imrbit;
  65. irq -= MCFINT_VECBASE;
  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 int intc_irq_set_type(struct irq_data *d, unsigned int type)
  84. {
  85. return 0;
  86. }
  87. static struct irq_chip intc_irq_chip = {
  88. .name = "CF-INTC",
  89. .irq_mask = intc_irq_mask,
  90. .irq_unmask = intc_irq_unmask,
  91. .irq_set_type = intc_irq_set_type,
  92. };
  93. void __init init_IRQ(void)
  94. {
  95. int irq;
  96. init_vectors();
  97. /* Mask all interrupt sources */
  98. __raw_writel(0x1, MCFICM_INTC0 + MCFINTC_IMRL);
  99. #ifdef MCFICM_INTC1
  100. __raw_writel(0x1, MCFICM_INTC1 + MCFINTC_IMRL);
  101. #endif
  102. for (irq = 0; (irq < NR_IRQS); irq++) {
  103. set_irq_chip(irq, &intc_irq_chip);
  104. set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
  105. set_irq_handler(irq, handle_level_irq);
  106. }
  107. }