irq.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (C) 2007 Lemote Inc.
  3. * Author: Fuxin Zhang, zhangfx@lemote.com
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/interrupt.h>
  11. #include <linux/module.h>
  12. #include <asm/irq_cpu.h>
  13. #include <asm/i8259.h>
  14. #include <asm/mipsregs.h>
  15. #include <loongson.h>
  16. #include <machine.h>
  17. #define LOONGSON_TIMER_IRQ (MIPS_CPU_IRQ_BASE + 7) /* cpu timer */
  18. #define LOONGSON_NORTH_BRIDGE_IRQ (MIPS_CPU_IRQ_BASE + 6) /* bonito */
  19. #define LOONGSON_UART_IRQ (MIPS_CPU_IRQ_BASE + 3) /* cpu serial port */
  20. #define LOONGSON_SOUTH_BRIDGE_IRQ (MIPS_CPU_IRQ_BASE + 2) /* i8259 */
  21. #define LOONGSON_INT_BIT_INT0 (1 << 11)
  22. #define LOONGSON_INT_BIT_INT1 (1 << 12)
  23. /*
  24. * The generic i8259_irq() make the kernel hang on booting. Since we cannot
  25. * get the irq via the IRR directly, we access the ISR instead.
  26. */
  27. int mach_i8259_irq(void)
  28. {
  29. int irq, isr;
  30. irq = -1;
  31. if ((LOONGSON_INTISR & LOONGSON_INTEN) & LOONGSON_INT_BIT_INT0) {
  32. raw_spin_lock(&i8259A_lock);
  33. isr = inb(PIC_MASTER_CMD) &
  34. ~inb(PIC_MASTER_IMR) & ~(1 << PIC_CASCADE_IR);
  35. if (!isr)
  36. isr = (inb(PIC_SLAVE_CMD) & ~inb(PIC_SLAVE_IMR)) << 8;
  37. irq = ffs(isr) - 1;
  38. if (unlikely(irq == 7)) {
  39. /*
  40. * This may be a spurious interrupt.
  41. *
  42. * Read the interrupt status register (ISR). If the most
  43. * significant bit is not set then there is no valid
  44. * interrupt.
  45. */
  46. outb(0x0B, PIC_MASTER_ISR); /* ISR register */
  47. if (~inb(PIC_MASTER_ISR) & 0x80)
  48. irq = -1;
  49. }
  50. raw_spin_unlock(&i8259A_lock);
  51. }
  52. return irq;
  53. }
  54. EXPORT_SYMBOL(mach_i8259_irq);
  55. static void i8259_irqdispatch(void)
  56. {
  57. int irq;
  58. irq = mach_i8259_irq();
  59. if (irq >= 0)
  60. do_IRQ(irq);
  61. else
  62. spurious_interrupt();
  63. }
  64. void mach_irq_dispatch(unsigned int pending)
  65. {
  66. if (pending & CAUSEF_IP7)
  67. do_IRQ(LOONGSON_TIMER_IRQ);
  68. else if (pending & CAUSEF_IP6) { /* North Bridge, Perf counter */
  69. do_perfcnt_IRQ();
  70. bonito_irqdispatch();
  71. } else if (pending & CAUSEF_IP3) /* CPU UART */
  72. do_IRQ(LOONGSON_UART_IRQ);
  73. else if (pending & CAUSEF_IP2) /* South Bridge */
  74. i8259_irqdispatch();
  75. else
  76. spurious_interrupt();
  77. }
  78. static irqreturn_t ip6_action(int cpl, void *dev_id)
  79. {
  80. return IRQ_HANDLED;
  81. }
  82. static struct irqaction ip6_irqaction = {
  83. .handler = ip6_action,
  84. .name = "cascade",
  85. .flags = IRQF_SHARED | IRQF_NO_THREAD,
  86. };
  87. static struct irqaction cascade_irqaction = {
  88. .handler = no_action,
  89. .name = "cascade",
  90. .flags = IRQF_NO_THREAD,
  91. };
  92. void __init mach_init_irq(void)
  93. {
  94. /* init all controller
  95. * 0-15 ------> i8259 interrupt
  96. * 16-23 ------> mips cpu interrupt
  97. * 32-63 ------> bonito irq
  98. */
  99. /* setup cs5536 as high level trigger */
  100. LOONGSON_INTPOL = LOONGSON_INT_BIT_INT0 | LOONGSON_INT_BIT_INT1;
  101. LOONGSON_INTEDGE &= ~(LOONGSON_INT_BIT_INT0 | LOONGSON_INT_BIT_INT1);
  102. /* Sets the first-level interrupt dispatcher. */
  103. mips_cpu_irq_init();
  104. init_i8259_irqs();
  105. bonito_irq_init();
  106. /* setup north bridge irq (bonito) */
  107. setup_irq(LOONGSON_NORTH_BRIDGE_IRQ, &ip6_irqaction);
  108. /* setup source bridge irq (i8259) */
  109. setup_irq(LOONGSON_SOUTH_BRIDGE_IRQ, &cascade_irqaction);
  110. }