irq.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_PERFCNT_IRQ (MIPS_CPU_IRQ_BASE + 6) /* cpu perf counter */
  19. #define LOONGSON_NORTH_BRIDGE_IRQ (MIPS_CPU_IRQ_BASE + 6) /* bonito */
  20. #define LOONGSON_UART_IRQ (MIPS_CPU_IRQ_BASE + 3) /* cpu serial port */
  21. #define LOONGSON_SOUTH_BRIDGE_IRQ (MIPS_CPU_IRQ_BASE + 2) /* i8259 */
  22. #define LOONGSON_INT_BIT_INT0 (1 << 11)
  23. #define LOONGSON_INT_BIT_INT1 (1 << 12)
  24. /*
  25. * The generic i8259_irq() make the kernel hang on booting. Since we cannot
  26. * get the irq via the IRR directly, we access the ISR instead.
  27. */
  28. int mach_i8259_irq(void)
  29. {
  30. int irq, isr;
  31. irq = -1;
  32. if ((LOONGSON_INTISR & LOONGSON_INTEN) & LOONGSON_INT_BIT_INT0) {
  33. spin_lock(&i8259A_lock);
  34. isr = inb(PIC_MASTER_CMD) &
  35. ~inb(PIC_MASTER_IMR) & ~(1 << PIC_CASCADE_IR);
  36. if (!isr)
  37. isr = (inb(PIC_SLAVE_CMD) & ~inb(PIC_SLAVE_IMR)) << 8;
  38. irq = ffs(isr) - 1;
  39. if (unlikely(irq == 7)) {
  40. /*
  41. * This may be a spurious interrupt.
  42. *
  43. * Read the interrupt status register (ISR). If the most
  44. * significant bit is not set then there is no valid
  45. * interrupt.
  46. */
  47. outb(0x0B, PIC_MASTER_ISR); /* ISR register */
  48. if (~inb(PIC_MASTER_ISR) & 0x80)
  49. irq = -1;
  50. }
  51. spin_unlock(&i8259A_lock);
  52. }
  53. return irq;
  54. }
  55. EXPORT_SYMBOL(mach_i8259_irq);
  56. static void i8259_irqdispatch(void)
  57. {
  58. int irq;
  59. irq = mach_i8259_irq();
  60. if (irq >= 0)
  61. do_IRQ(irq);
  62. else
  63. spurious_interrupt();
  64. }
  65. void mach_irq_dispatch(unsigned int pending)
  66. {
  67. if (pending & CAUSEF_IP7)
  68. do_IRQ(LOONGSON_TIMER_IRQ);
  69. else if (pending & CAUSEF_IP6) { /* North Bridge, Perf counter */
  70. #ifdef CONFIG_OPROFILE
  71. do_IRQ(LOONGSON2_PERFCNT_IRQ);
  72. #endif
  73. bonito_irqdispatch();
  74. } else if (pending & CAUSEF_IP3) /* CPU UART */
  75. do_IRQ(LOONGSON_UART_IRQ);
  76. else if (pending & CAUSEF_IP2) /* South Bridge */
  77. i8259_irqdispatch();
  78. else
  79. spurious_interrupt();
  80. }
  81. void __init set_irq_trigger_mode(void)
  82. {
  83. /* setup cs5536 as high level trigger */
  84. LOONGSON_INTPOL = LOONGSON_INT_BIT_INT0 | LOONGSON_INT_BIT_INT1;
  85. LOONGSON_INTEDGE &= ~(LOONGSON_INT_BIT_INT0 | LOONGSON_INT_BIT_INT1);
  86. }
  87. static irqreturn_t ip6_action(int cpl, void *dev_id)
  88. {
  89. return IRQ_HANDLED;
  90. }
  91. struct irqaction ip6_irqaction = {
  92. .handler = ip6_action,
  93. .name = "cascade",
  94. .flags = IRQF_SHARED,
  95. };
  96. struct irqaction cascade_irqaction = {
  97. .handler = no_action,
  98. .name = "cascade",
  99. };
  100. void __init mach_init_irq(void)
  101. {
  102. /* init all controller
  103. * 0-15 ------> i8259 interrupt
  104. * 16-23 ------> mips cpu interrupt
  105. * 32-63 ------> bonito irq
  106. */
  107. /* Sets the first-level interrupt dispatcher. */
  108. mips_cpu_irq_init();
  109. init_i8259_irqs();
  110. bonito_irq_init();
  111. /* setup north bridge irq (bonito) */
  112. setup_irq(LOONGSON_NORTH_BRIDGE_IRQ, &ip6_irqaction);
  113. /* setup source bridge irq (i8259) */
  114. setup_irq(LOONGSON_SOUTH_BRIDGE_IRQ, &cascade_irqaction);
  115. }