blob: c6db7e7df963bec8688ef27ce9b0b37ee5ae2267 [file] [log] [blame]
Wu Zhangjin6616db72009-11-10 00:06:14 +08001/*
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
11#include <linux/interrupt.h>
Wu Zhangjincb1ed9e2009-11-21 19:05:24 +080012#include <linux/module.h>
Wu Zhangjin6616db72009-11-10 00:06:14 +080013
14#include <asm/irq_cpu.h>
15#include <asm/i8259.h>
16#include <asm/mipsregs.h>
17
18#include <loongson.h>
19#include <machine.h>
20
21#define LOONGSON_TIMER_IRQ (MIPS_CPU_IRQ_BASE + 7) /* cpu timer */
22#define LOONGSON_PERFCNT_IRQ (MIPS_CPU_IRQ_BASE + 6) /* cpu perf counter */
23#define LOONGSON_NORTH_BRIDGE_IRQ (MIPS_CPU_IRQ_BASE + 6) /* bonito */
24#define LOONGSON_UART_IRQ (MIPS_CPU_IRQ_BASE + 3) /* cpu serial port */
25#define LOONGSON_SOUTH_BRIDGE_IRQ (MIPS_CPU_IRQ_BASE + 2) /* i8259 */
26
27#define LOONGSON_INT_BIT_INT0 (1 << 11)
28#define LOONGSON_INT_BIT_INT1 (1 << 12)
29
30/*
31 * The generic i8259_irq() make the kernel hang on booting. Since we cannot
32 * get the irq via the IRR directly, we access the ISR instead.
33 */
Wu Zhangjincb1ed9e2009-11-21 19:05:24 +080034int mach_i8259_irq(void)
Wu Zhangjin6616db72009-11-10 00:06:14 +080035{
36 int irq, isr;
37
38 irq = -1;
39
40 if ((LOONGSON_INTISR & LOONGSON_INTEN) & LOONGSON_INT_BIT_INT0) {
Ralf Baechle89650872010-02-27 12:53:38 +010041 raw_spin_lock(&i8259A_lock);
Wu Zhangjin6616db72009-11-10 00:06:14 +080042 isr = inb(PIC_MASTER_CMD) &
43 ~inb(PIC_MASTER_IMR) & ~(1 << PIC_CASCADE_IR);
44 if (!isr)
45 isr = (inb(PIC_SLAVE_CMD) & ~inb(PIC_SLAVE_IMR)) << 8;
46 irq = ffs(isr) - 1;
47 if (unlikely(irq == 7)) {
48 /*
49 * This may be a spurious interrupt.
50 *
51 * Read the interrupt status register (ISR). If the most
52 * significant bit is not set then there is no valid
53 * interrupt.
54 */
55 outb(0x0B, PIC_MASTER_ISR); /* ISR register */
56 if (~inb(PIC_MASTER_ISR) & 0x80)
57 irq = -1;
58 }
Ralf Baechle89650872010-02-27 12:53:38 +010059 raw_spin_unlock(&i8259A_lock);
Wu Zhangjin6616db72009-11-10 00:06:14 +080060 }
61
62 return irq;
63}
Wu Zhangjincb1ed9e2009-11-21 19:05:24 +080064EXPORT_SYMBOL(mach_i8259_irq);
Wu Zhangjin6616db72009-11-10 00:06:14 +080065
66static void i8259_irqdispatch(void)
67{
68 int irq;
69
70 irq = mach_i8259_irq();
71 if (irq >= 0)
72 do_IRQ(irq);
73 else
74 spurious_interrupt();
75}
76
77void mach_irq_dispatch(unsigned int pending)
78{
79 if (pending & CAUSEF_IP7)
80 do_IRQ(LOONGSON_TIMER_IRQ);
81 else if (pending & CAUSEF_IP6) { /* North Bridge, Perf counter */
Wu Zhangjin922010f2010-04-26 20:01:54 +080082#if defined(CONFIG_OPROFILE) || defined(CONFIG_OPROFILE_MODULE)
Wu Zhangjin6616db72009-11-10 00:06:14 +080083 do_IRQ(LOONGSON2_PERFCNT_IRQ);
84#endif
85 bonito_irqdispatch();
86 } else if (pending & CAUSEF_IP3) /* CPU UART */
87 do_IRQ(LOONGSON_UART_IRQ);
88 else if (pending & CAUSEF_IP2) /* South Bridge */
89 i8259_irqdispatch();
90 else
91 spurious_interrupt();
92}
93
Wu Zhangjin6616db72009-11-10 00:06:14 +080094static irqreturn_t ip6_action(int cpl, void *dev_id)
95{
96 return IRQ_HANDLED;
97}
98
99struct irqaction ip6_irqaction = {
100 .handler = ip6_action,
101 .name = "cascade",
102 .flags = IRQF_SHARED,
103};
104
105struct irqaction cascade_irqaction = {
106 .handler = no_action,
107 .name = "cascade",
108};
109
110void __init mach_init_irq(void)
111{
112 /* init all controller
113 * 0-15 ------> i8259 interrupt
114 * 16-23 ------> mips cpu interrupt
115 * 32-63 ------> bonito irq
116 */
117
Wu Zhangjinb8c74282010-07-24 09:22:13 +0800118 /* setup cs5536 as high level trigger */
119 LOONGSON_INTPOL = LOONGSON_INT_BIT_INT0 | LOONGSON_INT_BIT_INT1;
120 LOONGSON_INTEDGE &= ~(LOONGSON_INT_BIT_INT0 | LOONGSON_INT_BIT_INT1);
121
Wu Zhangjin6616db72009-11-10 00:06:14 +0800122 /* Sets the first-level interrupt dispatcher. */
123 mips_cpu_irq_init();
124 init_i8259_irqs();
125 bonito_irq_init();
126
127 /* setup north bridge irq (bonito) */
128 setup_irq(LOONGSON_NORTH_BRIDGE_IRQ, &ip6_irqaction);
129 /* setup source bridge irq (i8259) */
130 setup_irq(LOONGSON_SOUTH_BRIDGE_IRQ, &cascade_irqaction);
131}