irq.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/boards/superh/microdev/irq.c
  4. *
  5. * Copyright (C) 2003 Sean McGoogan ([email protected])
  6. *
  7. * SuperH SH4-202 MicroDev board support.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/irq.h>
  11. #include <linux/interrupt.h>
  12. #include <asm/io.h>
  13. #include <mach/microdev.h>
  14. #define NUM_EXTERNAL_IRQS 16 /* IRL0 .. IRL15 */
  15. static const struct {
  16. unsigned char fpgaIrq;
  17. unsigned char mapped;
  18. const char *name;
  19. } fpgaIrqTable[NUM_EXTERNAL_IRQS] = {
  20. { 0, 0, "unused" }, /* IRQ #0 IRL=15 0x200 */
  21. { MICRODEV_FPGA_IRQ_KEYBOARD, 1, "keyboard" }, /* IRQ #1 IRL=14 0x220 */
  22. { MICRODEV_FPGA_IRQ_SERIAL1, 1, "Serial #1"}, /* IRQ #2 IRL=13 0x240 */
  23. { MICRODEV_FPGA_IRQ_ETHERNET, 1, "Ethernet" }, /* IRQ #3 IRL=12 0x260 */
  24. { MICRODEV_FPGA_IRQ_SERIAL2, 0, "Serial #2"}, /* IRQ #4 IRL=11 0x280 */
  25. { 0, 0, "unused" }, /* IRQ #5 IRL=10 0x2a0 */
  26. { 0, 0, "unused" }, /* IRQ #6 IRL=9 0x2c0 */
  27. { MICRODEV_FPGA_IRQ_USB_HC, 1, "USB" }, /* IRQ #7 IRL=8 0x2e0 */
  28. { MICRODEV_IRQ_PCI_INTA, 1, "PCI INTA" }, /* IRQ #8 IRL=7 0x300 */
  29. { MICRODEV_IRQ_PCI_INTB, 1, "PCI INTB" }, /* IRQ #9 IRL=6 0x320 */
  30. { MICRODEV_IRQ_PCI_INTC, 1, "PCI INTC" }, /* IRQ #10 IRL=5 0x340 */
  31. { MICRODEV_IRQ_PCI_INTD, 1, "PCI INTD" }, /* IRQ #11 IRL=4 0x360 */
  32. { MICRODEV_FPGA_IRQ_MOUSE, 1, "mouse" }, /* IRQ #12 IRL=3 0x380 */
  33. { MICRODEV_FPGA_IRQ_IDE2, 1, "IDE #2" }, /* IRQ #13 IRL=2 0x3a0 */
  34. { MICRODEV_FPGA_IRQ_IDE1, 1, "IDE #1" }, /* IRQ #14 IRL=1 0x3c0 */
  35. { 0, 0, "unused" }, /* IRQ #15 IRL=0 0x3e0 */
  36. };
  37. #if (MICRODEV_LINUX_IRQ_KEYBOARD != 1)
  38. # error Inconsistancy in defining the IRQ# for Keyboard!
  39. #endif
  40. #if (MICRODEV_LINUX_IRQ_ETHERNET != 3)
  41. # error Inconsistancy in defining the IRQ# for Ethernet!
  42. #endif
  43. #if (MICRODEV_LINUX_IRQ_USB_HC != 7)
  44. # error Inconsistancy in defining the IRQ# for USB!
  45. #endif
  46. #if (MICRODEV_LINUX_IRQ_MOUSE != 12)
  47. # error Inconsistancy in defining the IRQ# for PS/2 Mouse!
  48. #endif
  49. #if (MICRODEV_LINUX_IRQ_IDE2 != 13)
  50. # error Inconsistancy in defining the IRQ# for secondary IDE!
  51. #endif
  52. #if (MICRODEV_LINUX_IRQ_IDE1 != 14)
  53. # error Inconsistancy in defining the IRQ# for primary IDE!
  54. #endif
  55. static void disable_microdev_irq(struct irq_data *data)
  56. {
  57. unsigned int irq = data->irq;
  58. unsigned int fpgaIrq;
  59. if (irq >= NUM_EXTERNAL_IRQS)
  60. return;
  61. if (!fpgaIrqTable[irq].mapped)
  62. return;
  63. fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
  64. /* disable interrupts on the FPGA INTC register */
  65. __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG);
  66. }
  67. static void enable_microdev_irq(struct irq_data *data)
  68. {
  69. unsigned int irq = data->irq;
  70. unsigned long priorityReg, priorities, pri;
  71. unsigned int fpgaIrq;
  72. if (unlikely(irq >= NUM_EXTERNAL_IRQS))
  73. return;
  74. if (unlikely(!fpgaIrqTable[irq].mapped))
  75. return;
  76. pri = 15 - irq;
  77. fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
  78. priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq);
  79. /* set priority for the interrupt */
  80. priorities = __raw_readl(priorityReg);
  81. priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq);
  82. priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri);
  83. __raw_writel(priorities, priorityReg);
  84. /* enable interrupts on the FPGA INTC register */
  85. __raw_writel(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG);
  86. }
  87. static struct irq_chip microdev_irq_type = {
  88. .name = "MicroDev-IRQ",
  89. .irq_unmask = enable_microdev_irq,
  90. .irq_mask = disable_microdev_irq,
  91. };
  92. /* This function sets the desired irq handler to be a MicroDev type */
  93. static void __init make_microdev_irq(unsigned int irq)
  94. {
  95. disable_irq_nosync(irq);
  96. irq_set_chip_and_handler(irq, &microdev_irq_type, handle_level_irq);
  97. disable_microdev_irq(irq_get_irq_data(irq));
  98. }
  99. extern void __init init_microdev_irq(void)
  100. {
  101. int i;
  102. /* disable interrupts on the FPGA INTC register */
  103. __raw_writel(~0ul, MICRODEV_FPGA_INTDSB_REG);
  104. for (i = 0; i < NUM_EXTERNAL_IRQS; i++)
  105. make_microdev_irq(i);
  106. }
  107. extern void microdev_print_fpga_intc_status(void)
  108. {
  109. volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG;
  110. volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG;
  111. volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0);
  112. volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8);
  113. volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16);
  114. volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24);
  115. volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG;
  116. volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG;
  117. printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n");
  118. printk("FPGA_INTENB = 0x%08x\n", *intenb);
  119. printk("FPGA_INTDSB = 0x%08x\n", *intdsb);
  120. printk("FPGA_INTSRC = 0x%08x\n", *intsrc);
  121. printk("FPGA_INTREQ = 0x%08x\n", *intreq);
  122. printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria);
  123. printk("-------------------------------------------------------------------------------\n");
  124. }