irq.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <asm/irq_cpu.h>
  12. #include <asm/i8259.h>
  13. #include <asm/mipsregs.h>
  14. #include <loongson.h>
  15. #include <machine.h>
  16. #define LOONGSON_TIMER_IRQ (MIPS_CPU_IRQ_BASE + 7) /* cpu timer */
  17. #define LOONGSON_PERFCNT_IRQ (MIPS_CPU_IRQ_BASE + 6) /* cpu perf counter */
  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. static inline int mach_i8259_irq(void)
  28. {
  29. int irq, isr;
  30. irq = -1;
  31. if ((LOONGSON_INTISR & LOONGSON_INTEN) & LOONGSON_INT_BIT_INT0) {
  32. 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. spin_unlock(&i8259A_lock);
  51. }
  52. return irq;
  53. }
  54. static void i8259_irqdispatch(void)
  55. {
  56. int irq;
  57. irq = mach_i8259_irq();
  58. if (irq >= 0)
  59. do_IRQ(irq);
  60. else
  61. spurious_interrupt();
  62. }
  63. void mach_irq_dispatch(unsigned int pending)
  64. {
  65. if (pending & CAUSEF_IP7)
  66. do_IRQ(LOONGSON_TIMER_IRQ);
  67. else if (pending & CAUSEF_IP6) { /* North Bridge, Perf counter */
  68. #ifdef CONFIG_OPROFILE
  69. do_IRQ(LOONGSON2_PERFCNT_IRQ);
  70. #endif
  71. bonito_irqdispatch();
  72. } else if (pending & CAUSEF_IP3) /* CPU UART */
  73. do_IRQ(LOONGSON_UART_IRQ);
  74. else if (pending & CAUSEF_IP2) /* South Bridge */
  75. i8259_irqdispatch();
  76. else
  77. spurious_interrupt();
  78. }
  79. void __init set_irq_trigger_mode(void)
  80. {
  81. /* setup cs5536 as high level trigger */
  82. LOONGSON_INTPOL = LOONGSON_INT_BIT_INT0 | LOONGSON_INT_BIT_INT1;
  83. LOONGSON_INTEDGE &= ~(LOONGSON_INT_BIT_INT0 | LOONGSON_INT_BIT_INT1);
  84. }
  85. static irqreturn_t ip6_action(int cpl, void *dev_id)
  86. {
  87. return IRQ_HANDLED;
  88. }
  89. struct irqaction ip6_irqaction = {
  90. .handler = ip6_action,
  91. .name = "cascade",
  92. .flags = IRQF_SHARED,
  93. };
  94. struct irqaction cascade_irqaction = {
  95. .handler = no_action,
  96. .name = "cascade",
  97. };
  98. void __init mach_init_irq(void)
  99. {
  100. /* init all controller
  101. * 0-15 ------> i8259 interrupt
  102. * 16-23 ------> mips cpu interrupt
  103. * 32-63 ------> bonito irq
  104. */
  105. /* Sets the first-level interrupt dispatcher. */
  106. mips_cpu_irq_init();
  107. init_i8259_irqs();
  108. bonito_irq_init();
  109. /* setup north bridge irq (bonito) */
  110. setup_irq(LOONGSON_NORTH_BRIDGE_IRQ, &ip6_irqaction);
  111. /* setup source bridge irq (i8259) */
  112. setup_irq(LOONGSON_SOUTH_BRIDGE_IRQ, &cascade_irqaction);
  113. }