intc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. * The mapping of irq number to a mask register bit is not one-to-one.
  21. * The irq numbers are either based on "level" of interrupt or fixed
  22. * for an autovector-able interrupt. So we keep a local data structure
  23. * that maps from irq to mask register. Not all interrupts will have
  24. * an IMR bit.
  25. */
  26. unsigned char mcf_irq2imr[NR_IRQS];
  27. /*
  28. * Define the miniumun and maximum external interrupt numbers.
  29. * This is also used as the "level" interrupt numbers.
  30. */
  31. #define EIRQ1 25
  32. #define EIRQ7 31
  33. /*
  34. * In the early version 2 core ColdFire parts the IMR register was 16 bits
  35. * in size. Version 3 (and later version 2) core parts have a 32 bit
  36. * sized IMR register. Provide some size independent methods to access the
  37. * IMR register.
  38. */
  39. #ifdef MCFSIM_IMR_IS_16BITS
  40. void mcf_setimr(int index)
  41. {
  42. u16 imr;
  43. imr = __raw_readw(MCFSIM_IMR);
  44. __raw_writew(imr | (0x1 << index), MCFSIM_IMR);
  45. }
  46. void mcf_clrimr(int index)
  47. {
  48. u16 imr;
  49. imr = __raw_readw(MCFSIM_IMR);
  50. __raw_writew(imr & ~(0x1 << index), MCFSIM_IMR);
  51. }
  52. void mcf_maskimr(unsigned int mask)
  53. {
  54. u16 imr;
  55. imr = __raw_readw(MCFSIM_IMR);
  56. imr |= mask;
  57. __raw_writew(imr, MCFSIM_IMR);
  58. }
  59. #else
  60. void mcf_setimr(int index)
  61. {
  62. u32 imr;
  63. imr = __raw_readl(MCFSIM_IMR);
  64. __raw_writel(imr | (0x1 << index), MCFSIM_IMR);
  65. }
  66. void mcf_clrimr(int index)
  67. {
  68. u32 imr;
  69. imr = __raw_readl(MCFSIM_IMR);
  70. __raw_writel(imr & ~(0x1 << index), MCFSIM_IMR);
  71. }
  72. void mcf_maskimr(unsigned int mask)
  73. {
  74. u32 imr;
  75. imr = __raw_readl(MCFSIM_IMR);
  76. imr |= mask;
  77. __raw_writel(imr, MCFSIM_IMR);
  78. }
  79. #endif
  80. /*
  81. * Interrupts can be "vectored" on the ColdFire cores that support this old
  82. * interrupt controller. That is, the device raising the interrupt can also
  83. * supply the vector number to interrupt through. The AVR register of the
  84. * interrupt controller enables or disables this for each external interrupt,
  85. * so provide generic support for this. Setting this up is out-of-band for
  86. * the interrupt system API's, and needs to be done by the driver that
  87. * supports this device. Very few devices actually use this.
  88. */
  89. void mcf_autovector(int irq)
  90. {
  91. #ifdef MCFSIM_AVR
  92. if ((irq >= EIRQ1) && (irq <= EIRQ7)) {
  93. u8 avec;
  94. avec = __raw_readb(MCFSIM_AVR);
  95. avec |= (0x1 << (irq - EIRQ1 + 1));
  96. __raw_writeb(avec, MCFSIM_AVR);
  97. }
  98. #endif
  99. }
  100. static void intc_irq_mask(struct irq_data *d)
  101. {
  102. if (mcf_irq2imr[d->irq])
  103. mcf_setimr(mcf_irq2imr[d->irq]);
  104. }
  105. static void intc_irq_unmask(struct irq_data *d)
  106. {
  107. if (mcf_irq2imr[d->irq])
  108. mcf_clrimr(mcf_irq2imr[d->irq]);
  109. }
  110. static int intc_irq_set_type(struct irq_data *d, unsigned int type)
  111. {
  112. return 0;
  113. }
  114. static struct irq_chip intc_irq_chip = {
  115. .name = "CF-INTC",
  116. .irq_mask = intc_irq_mask,
  117. .irq_unmask = intc_irq_unmask,
  118. .irq_set_type = intc_irq_set_type,
  119. };
  120. void __init init_IRQ(void)
  121. {
  122. int irq;
  123. mcf_maskimr(0xffffffff);
  124. for (irq = 0; (irq < NR_IRQS); irq++) {
  125. irq_set_chip(irq, &intc_irq_chip);
  126. irq_set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
  127. irq_set_handler(irq, handle_level_irq);
  128. }
  129. }