intc-2.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 - MCFINT_VECBASE;
  44. unsigned long imraddr;
  45. u32 val, imrbit;
  46. #ifdef MCFICM_INTC1
  47. imraddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
  48. #else
  49. imraddr = MCFICM_INTC0;
  50. #endif
  51. imraddr += (irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL;
  52. imrbit = 0x1 << (irq & 0x1f);
  53. val = __raw_readl(imraddr);
  54. __raw_writel(val | imrbit, imraddr);
  55. }
  56. static void intc_irq_unmask(struct irq_data *d)
  57. {
  58. unsigned int irq = d->irq - MCFINT_VECBASE;
  59. unsigned long intaddr, imraddr, icraddr;
  60. u32 val, imrbit;
  61. #ifdef MCFICM_INTC1
  62. intaddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
  63. #else
  64. intaddr = MCFICM_INTC0;
  65. #endif
  66. imraddr = intaddr + ((irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL);
  67. icraddr = intaddr + MCFINTC_ICR0 + (irq & 0x3f);
  68. imrbit = 0x1 << (irq & 0x1f);
  69. /* Don't set the "maskall" bit! */
  70. if ((irq & 0x20) == 0)
  71. imrbit |= 0x1;
  72. if (__raw_readb(icraddr) == 0)
  73. __raw_writeb(intc_intpri--, icraddr);
  74. val = __raw_readl(imraddr);
  75. __raw_writel(val & ~imrbit, imraddr);
  76. }
  77. static int intc_irq_set_type(struct irq_data *d, unsigned int type)
  78. {
  79. return 0;
  80. }
  81. static struct irq_chip intc_irq_chip = {
  82. .name = "CF-INTC",
  83. .irq_mask = intc_irq_mask,
  84. .irq_unmask = intc_irq_unmask,
  85. .irq_set_type = intc_irq_set_type,
  86. };
  87. void __init init_IRQ(void)
  88. {
  89. int irq;
  90. init_vectors();
  91. /* Mask all interrupt sources */
  92. __raw_writel(0x1, MCFICM_INTC0 + MCFINTC_IMRL);
  93. #ifdef MCFICM_INTC1
  94. __raw_writel(0x1, MCFICM_INTC1 + MCFINTC_IMRL);
  95. #endif
  96. for (irq = MCFINT_VECBASE; (irq < MCFINT_VECBASE + NR_VECS); irq++) {
  97. set_irq_chip(irq, &intc_irq_chip);
  98. set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
  99. set_irq_handler(irq, handle_level_irq);
  100. }
  101. }