kvm tools, setup: Create private directory
[linux-2.6/next.git] / arch / mips / ath79 / irq.c
blobac610d5fe3bab415ef649872072bacce58718c19
1 /*
2 * Atheros AR71xx/AR724x/AR913x specific interrupt handling
4 * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 * Parts of this file are based on Atheros' 2.6.15 BSP
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/irq.h>
19 #include <asm/irq_cpu.h>
20 #include <asm/mipsregs.h>
22 #include <asm/mach-ath79/ath79.h>
23 #include <asm/mach-ath79/ar71xx_regs.h>
24 #include "common.h"
26 static unsigned int ath79_ip2_flush_reg;
27 static unsigned int ath79_ip3_flush_reg;
29 static void ath79_misc_irq_handler(unsigned int irq, struct irq_desc *desc)
31 void __iomem *base = ath79_reset_base;
32 u32 pending;
34 pending = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS) &
35 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
37 if (pending & MISC_INT_UART)
38 generic_handle_irq(ATH79_MISC_IRQ_UART);
40 else if (pending & MISC_INT_DMA)
41 generic_handle_irq(ATH79_MISC_IRQ_DMA);
43 else if (pending & MISC_INT_PERFC)
44 generic_handle_irq(ATH79_MISC_IRQ_PERFC);
46 else if (pending & MISC_INT_TIMER)
47 generic_handle_irq(ATH79_MISC_IRQ_TIMER);
49 else if (pending & MISC_INT_OHCI)
50 generic_handle_irq(ATH79_MISC_IRQ_OHCI);
52 else if (pending & MISC_INT_ERROR)
53 generic_handle_irq(ATH79_MISC_IRQ_ERROR);
55 else if (pending & MISC_INT_GPIO)
56 generic_handle_irq(ATH79_MISC_IRQ_GPIO);
58 else if (pending & MISC_INT_WDOG)
59 generic_handle_irq(ATH79_MISC_IRQ_WDOG);
61 else
62 spurious_interrupt();
65 static void ar71xx_misc_irq_unmask(struct irq_data *d)
67 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
68 void __iomem *base = ath79_reset_base;
69 u32 t;
71 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
72 __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
74 /* flush write */
75 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
78 static void ar71xx_misc_irq_mask(struct irq_data *d)
80 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
81 void __iomem *base = ath79_reset_base;
82 u32 t;
84 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
85 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
87 /* flush write */
88 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
91 static void ar724x_misc_irq_ack(struct irq_data *d)
93 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
94 void __iomem *base = ath79_reset_base;
95 u32 t;
97 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
98 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_STATUS);
100 /* flush write */
101 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
104 static struct irq_chip ath79_misc_irq_chip = {
105 .name = "MISC",
106 .irq_unmask = ar71xx_misc_irq_unmask,
107 .irq_mask = ar71xx_misc_irq_mask,
110 static void __init ath79_misc_irq_init(void)
112 void __iomem *base = ath79_reset_base;
113 int i;
115 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
116 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
118 if (soc_is_ar71xx() || soc_is_ar913x())
119 ath79_misc_irq_chip.irq_mask_ack = ar71xx_misc_irq_mask;
120 else if (soc_is_ar724x())
121 ath79_misc_irq_chip.irq_ack = ar724x_misc_irq_ack;
122 else
123 BUG();
125 for (i = ATH79_MISC_IRQ_BASE;
126 i < ATH79_MISC_IRQ_BASE + ATH79_MISC_IRQ_COUNT; i++) {
127 irq_set_chip_and_handler(i, &ath79_misc_irq_chip,
128 handle_level_irq);
131 irq_set_chained_handler(ATH79_CPU_IRQ_MISC, ath79_misc_irq_handler);
134 asmlinkage void plat_irq_dispatch(void)
136 unsigned long pending;
138 pending = read_c0_status() & read_c0_cause() & ST0_IM;
140 if (pending & STATUSF_IP7)
141 do_IRQ(ATH79_CPU_IRQ_TIMER);
143 else if (pending & STATUSF_IP2) {
144 ath79_ddr_wb_flush(ath79_ip2_flush_reg);
145 do_IRQ(ATH79_CPU_IRQ_IP2);
148 else if (pending & STATUSF_IP4)
149 do_IRQ(ATH79_CPU_IRQ_GE0);
151 else if (pending & STATUSF_IP5)
152 do_IRQ(ATH79_CPU_IRQ_GE1);
154 else if (pending & STATUSF_IP3) {
155 ath79_ddr_wb_flush(ath79_ip3_flush_reg);
156 do_IRQ(ATH79_CPU_IRQ_USB);
159 else if (pending & STATUSF_IP6)
160 do_IRQ(ATH79_CPU_IRQ_MISC);
162 else
163 spurious_interrupt();
166 void __init arch_init_irq(void)
168 if (soc_is_ar71xx()) {
169 ath79_ip2_flush_reg = AR71XX_DDR_REG_FLUSH_PCI;
170 ath79_ip3_flush_reg = AR71XX_DDR_REG_FLUSH_USB;
171 } else if (soc_is_ar724x()) {
172 ath79_ip2_flush_reg = AR724X_DDR_REG_FLUSH_PCIE;
173 ath79_ip3_flush_reg = AR724X_DDR_REG_FLUSH_USB;
174 } else if (soc_is_ar913x()) {
175 ath79_ip2_flush_reg = AR913X_DDR_REG_FLUSH_WMAC;
176 ath79_ip3_flush_reg = AR913X_DDR_REG_FLUSH_USB;
177 } else
178 BUG();
180 cp0_perfcount_irq = ATH79_MISC_IRQ_PERFC;
181 mips_cpu_irq_init();
182 ath79_misc_irq_init();