blob: 1b073de44680ea0fdba8c95f84cf6f214f394448 [file] [log] [blame]
Gabor Juhosd4a67d92011-01-04 21:28:14 +01001/*
2 * Atheros AR71xx/AR724x/AR913x specific interrupt handling
3 *
4 * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * Parts of this file are based on Atheros' 2.6.15 BSP
8 *
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.
12 */
13
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/interrupt.h>
17#include <linux/irq.h>
18
19#include <asm/irq_cpu.h>
20#include <asm/mipsregs.h>
21
22#include <asm/mach-ath79/ath79.h>
23#include <asm/mach-ath79/ar71xx_regs.h>
24#include "common.h"
25
26static unsigned int ath79_ip2_flush_reg;
27static unsigned int ath79_ip3_flush_reg;
28
29static void ath79_misc_irq_handler(unsigned int irq, struct irq_desc *desc)
30{
31 void __iomem *base = ath79_reset_base;
32 u32 pending;
33
34 pending = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS) &
35 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
36
37 if (pending & MISC_INT_UART)
38 generic_handle_irq(ATH79_MISC_IRQ_UART);
39
40 else if (pending & MISC_INT_DMA)
41 generic_handle_irq(ATH79_MISC_IRQ_DMA);
42
43 else if (pending & MISC_INT_PERFC)
44 generic_handle_irq(ATH79_MISC_IRQ_PERFC);
45
46 else if (pending & MISC_INT_TIMER)
47 generic_handle_irq(ATH79_MISC_IRQ_TIMER);
48
Gabor Juhosd2b4ac12011-06-05 23:38:45 +020049 else if (pending & MISC_INT_TIMER2)
50 generic_handle_irq(ATH79_MISC_IRQ_TIMER2);
51
52 else if (pending & MISC_INT_TIMER3)
53 generic_handle_irq(ATH79_MISC_IRQ_TIMER3);
54
55 else if (pending & MISC_INT_TIMER4)
56 generic_handle_irq(ATH79_MISC_IRQ_TIMER4);
57
Gabor Juhosd4a67d92011-01-04 21:28:14 +010058 else if (pending & MISC_INT_OHCI)
59 generic_handle_irq(ATH79_MISC_IRQ_OHCI);
60
61 else if (pending & MISC_INT_ERROR)
62 generic_handle_irq(ATH79_MISC_IRQ_ERROR);
63
64 else if (pending & MISC_INT_GPIO)
65 generic_handle_irq(ATH79_MISC_IRQ_GPIO);
66
67 else if (pending & MISC_INT_WDOG)
68 generic_handle_irq(ATH79_MISC_IRQ_WDOG);
69
Gabor Juhosd2b4ac12011-06-05 23:38:45 +020070 else if (pending & MISC_INT_ETHSW)
71 generic_handle_irq(ATH79_MISC_IRQ_ETHSW);
72
Gabor Juhosd4a67d92011-01-04 21:28:14 +010073 else
74 spurious_interrupt();
75}
76
Thomas Gleixner3fb88182011-03-23 21:08:47 +000077static void ar71xx_misc_irq_unmask(struct irq_data *d)
Gabor Juhosd4a67d92011-01-04 21:28:14 +010078{
Thomas Gleixner3fb88182011-03-23 21:08:47 +000079 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
Gabor Juhosd4a67d92011-01-04 21:28:14 +010080 void __iomem *base = ath79_reset_base;
81 u32 t;
82
Gabor Juhosd4a67d92011-01-04 21:28:14 +010083 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
84 __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
85
86 /* flush write */
87 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
88}
89
Thomas Gleixner3fb88182011-03-23 21:08:47 +000090static void ar71xx_misc_irq_mask(struct irq_data *d)
Gabor Juhosd4a67d92011-01-04 21:28:14 +010091{
Thomas Gleixner3fb88182011-03-23 21:08:47 +000092 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
Gabor Juhosd4a67d92011-01-04 21:28:14 +010093 void __iomem *base = ath79_reset_base;
94 u32 t;
95
Gabor Juhosd4a67d92011-01-04 21:28:14 +010096 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
97 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
98
99 /* flush write */
100 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
101}
102
Thomas Gleixner3fb88182011-03-23 21:08:47 +0000103static void ar724x_misc_irq_ack(struct irq_data *d)
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100104{
Thomas Gleixner3fb88182011-03-23 21:08:47 +0000105 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100106 void __iomem *base = ath79_reset_base;
107 u32 t;
108
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100109 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
110 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_STATUS);
111
112 /* flush write */
113 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
114}
115
116static struct irq_chip ath79_misc_irq_chip = {
117 .name = "MISC",
Thomas Gleixner3fb88182011-03-23 21:08:47 +0000118 .irq_unmask = ar71xx_misc_irq_unmask,
119 .irq_mask = ar71xx_misc_irq_mask,
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100120};
121
122static void __init ath79_misc_irq_init(void)
123{
124 void __iomem *base = ath79_reset_base;
125 int i;
126
127 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
128 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
129
130 if (soc_is_ar71xx() || soc_is_ar913x())
Thomas Gleixner3fb88182011-03-23 21:08:47 +0000131 ath79_misc_irq_chip.irq_mask_ack = ar71xx_misc_irq_mask;
Gabor Juhos54eed4c2011-06-20 21:26:06 +0200132 else if (soc_is_ar724x() || soc_is_ar933x())
Thomas Gleixner3fb88182011-03-23 21:08:47 +0000133 ath79_misc_irq_chip.irq_ack = ar724x_misc_irq_ack;
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100134 else
135 BUG();
136
137 for (i = ATH79_MISC_IRQ_BASE;
138 i < ATH79_MISC_IRQ_BASE + ATH79_MISC_IRQ_COUNT; i++) {
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200139 irq_set_chip_and_handler(i, &ath79_misc_irq_chip,
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100140 handle_level_irq);
141 }
142
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200143 irq_set_chained_handler(ATH79_CPU_IRQ_MISC, ath79_misc_irq_handler);
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100144}
145
146asmlinkage void plat_irq_dispatch(void)
147{
148 unsigned long pending;
149
150 pending = read_c0_status() & read_c0_cause() & ST0_IM;
151
152 if (pending & STATUSF_IP7)
153 do_IRQ(ATH79_CPU_IRQ_TIMER);
154
155 else if (pending & STATUSF_IP2) {
156 ath79_ddr_wb_flush(ath79_ip2_flush_reg);
157 do_IRQ(ATH79_CPU_IRQ_IP2);
158 }
159
160 else if (pending & STATUSF_IP4)
161 do_IRQ(ATH79_CPU_IRQ_GE0);
162
163 else if (pending & STATUSF_IP5)
164 do_IRQ(ATH79_CPU_IRQ_GE1);
165
166 else if (pending & STATUSF_IP3) {
167 ath79_ddr_wb_flush(ath79_ip3_flush_reg);
168 do_IRQ(ATH79_CPU_IRQ_USB);
169 }
170
171 else if (pending & STATUSF_IP6)
172 do_IRQ(ATH79_CPU_IRQ_MISC);
173
174 else
175 spurious_interrupt();
176}
177
178void __init arch_init_irq(void)
179{
180 if (soc_is_ar71xx()) {
181 ath79_ip2_flush_reg = AR71XX_DDR_REG_FLUSH_PCI;
182 ath79_ip3_flush_reg = AR71XX_DDR_REG_FLUSH_USB;
183 } else if (soc_is_ar724x()) {
184 ath79_ip2_flush_reg = AR724X_DDR_REG_FLUSH_PCIE;
185 ath79_ip3_flush_reg = AR724X_DDR_REG_FLUSH_USB;
186 } else if (soc_is_ar913x()) {
187 ath79_ip2_flush_reg = AR913X_DDR_REG_FLUSH_WMAC;
188 ath79_ip3_flush_reg = AR913X_DDR_REG_FLUSH_USB;
Gabor Juhos54eed4c2011-06-20 21:26:06 +0200189 } else if (soc_is_ar933x()) {
190 ath79_ip2_flush_reg = AR933X_DDR_REG_FLUSH_WMAC;
191 ath79_ip3_flush_reg = AR933X_DDR_REG_FLUSH_USB;
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100192 } else
193 BUG();
194
195 cp0_perfcount_irq = ATH79_MISC_IRQ_PERFC;
196 mips_cpu_irq_init();
197 ath79_misc_irq_init();
198}