intc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * intc.c -- support for the old ColdFire interrupt controller
  3. *
  4. * (C) Copyright 2009, Greg Ungerer <gerg@snapgear.com>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/types.h>
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/irq.h>
  15. #include <linux/io.h>
  16. #include <asm/traps.h>
  17. #include <asm/coldfire.h>
  18. #include <asm/mcfsim.h>
  19. /*
  20. * Define the vector numbers for the basic 7 interrupt sources.
  21. * These are often referred to as the "external" interrupts in
  22. * the ColdFire documentation (for the early ColdFire cores at least).
  23. */
  24. #define EIRQ1 25
  25. #define EIRQ7 31
  26. /*
  27. * In the early version 2 core ColdFire parts the IMR register was 16 bits
  28. * in size. Version 3 (and later version 2) core parts have a 32 bit
  29. * sized IMR register. Provide some size independant methods to access the
  30. * IMR register.
  31. */
  32. #ifdef MCFSIM_IMR_IS_16BITS
  33. void mcf_setimr(int index)
  34. {
  35. u16 imr;
  36. imr = __raw_readw(MCF_MBAR + MCFSIM_IMR);
  37. __raw_writew(imr | (0x1 << index), MCF_MBAR + MCFSIM_IMR);
  38. }
  39. void mcf_clrimr(int index)
  40. {
  41. u16 imr;
  42. imr = __raw_readw(MCF_MBAR + MCFSIM_IMR);
  43. __raw_writew(imr & ~(0x1 << index), MCF_MBAR + MCFSIM_IMR);
  44. }
  45. void mcf_maskimr(unsigned int mask)
  46. {
  47. u16 imr;
  48. imr = __raw_readw(MCF_MBAR + MCFSIM_IMR);
  49. imr |= mask;
  50. __raw_writew(imr, MCF_MBAR + MCFSIM_IMR);
  51. }
  52. #else
  53. void mcf_setimr(int index)
  54. {
  55. u32 imr;
  56. imr = __raw_readl(MCF_MBAR + MCFSIM_IMR);
  57. __raw_writel(imr | (0x1 << index), MCF_MBAR + MCFSIM_IMR);
  58. }
  59. void mcf_clrimr(int index)
  60. {
  61. u32 imr;
  62. imr = __raw_readl(MCF_MBAR + MCFSIM_IMR);
  63. __raw_writel(imr & ~(0x1 << index), MCF_MBAR + MCFSIM_IMR);
  64. }
  65. void mcf_maskimr(unsigned int mask)
  66. {
  67. u32 imr;
  68. imr = __raw_readl(MCF_MBAR + MCFSIM_IMR);
  69. imr |= mask;
  70. __raw_writel(imr, MCF_MBAR + MCFSIM_IMR);
  71. }
  72. #endif
  73. /*
  74. * Interrupts can be "vectored" on the ColdFire cores that support this old
  75. * interrupt controller. That is, the device raising the interrupt can also
  76. * supply the vector number to interrupt through. The AVR register of the
  77. * interrupt controller enables or disables this for each external interrupt,
  78. * so provide generic support for this. Setting this up is out-of-band for
  79. * the interrupt system API's, and needs to be done by the driver that
  80. * supports this device. Very few devices actually use this.
  81. */
  82. void mcf_autovector(int irq)
  83. {
  84. if ((irq >= EIRQ1) && (irq <= EIRQ7)) {
  85. u8 avec;
  86. avec = __raw_readb(MCF_MBAR + MCFSIM_AVR);
  87. avec |= (0x1 << (irq - EIRQ1 + 1));
  88. __raw_writeb(avec, MCF_MBAR + MCFSIM_AVR);
  89. }
  90. }
  91. static void intc_irq_mask(unsigned int irq)
  92. {
  93. if ((irq >= EIRQ1) && (irq <= EIRQ7))
  94. mcf_setimr(irq - EIRQ1 + 1);
  95. }
  96. static void intc_irq_unmask(unsigned int irq)
  97. {
  98. if ((irq >= EIRQ1) && (irq <= EIRQ7))
  99. mcf_clrimr(irq - EIRQ1 + 1);
  100. }
  101. static int intc_irq_set_type(unsigned int irq, unsigned int type)
  102. {
  103. return 0;
  104. }
  105. static struct irq_chip intc_irq_chip = {
  106. .name = "CF-INTC",
  107. .mask = intc_irq_mask,
  108. .unmask = intc_irq_unmask,
  109. .set_type = intc_irq_set_type,
  110. };
  111. void __init init_IRQ(void)
  112. {
  113. int irq;
  114. init_vectors();
  115. mcf_maskimr(0xffffffff);
  116. for (irq = 0; (irq < NR_IRQS); irq++) {
  117. irq_desc[irq].status = IRQ_DISABLED;
  118. irq_desc[irq].action = NULL;
  119. irq_desc[irq].depth = 1;
  120. irq_desc[irq].chip = &intc_irq_chip;
  121. intc_irq_set_type(irq, 0);
  122. }
  123. }