blob: 29348956d15d621026fd3a19fe89d7b77976c9fc [file] [log] [blame]
Gabor Juhosd4a67d92011-01-04 21:28:14 +01001/*
2 * Atheros AR71xx/AR724x/AR913x specific interrupt handling
3 *
Gabor Juhosfce5cc62012-03-14 10:45:25 +01004 * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +01005 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
Gabor Juhosd4a67d92011-01-04 21:28:14 +01006 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 *
Gabor Juhosfce5cc62012-03-14 10:45:25 +01008 * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
Gabor Juhosd4a67d92011-01-04 21:28:14 +01009 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/interrupt.h>
18#include <linux/irq.h>
19
20#include <asm/irq_cpu.h>
21#include <asm/mipsregs.h>
22
23#include <asm/mach-ath79/ath79.h>
24#include <asm/mach-ath79/ar71xx_regs.h>
25#include "common.h"
26
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +010027static void (*ath79_ip2_handler)(void);
28static void (*ath79_ip3_handler)(void);
Gabor Juhosd4a67d92011-01-04 21:28:14 +010029
30static void ath79_misc_irq_handler(unsigned int irq, struct irq_desc *desc)
31{
32 void __iomem *base = ath79_reset_base;
33 u32 pending;
34
35 pending = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS) &
36 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
37
Gabor Juhos9c099c42013-01-29 16:13:17 +000038 if (!pending) {
Gabor Juhosd4a67d92011-01-04 21:28:14 +010039 spurious_interrupt();
Gabor Juhos9c099c42013-01-29 16:13:17 +000040 return;
41 }
42
43 while (pending) {
44 int bit = __ffs(pending);
45
46 generic_handle_irq(ATH79_MISC_IRQ(bit));
47 pending &= ~BIT(bit);
48 }
Gabor Juhosd4a67d92011-01-04 21:28:14 +010049}
50
Thomas Gleixner3fb88182011-03-23 21:08:47 +000051static void ar71xx_misc_irq_unmask(struct irq_data *d)
Gabor Juhosd4a67d92011-01-04 21:28:14 +010052{
Thomas Gleixner3fb88182011-03-23 21:08:47 +000053 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
Gabor Juhosd4a67d92011-01-04 21:28:14 +010054 void __iomem *base = ath79_reset_base;
55 u32 t;
56
Gabor Juhosd4a67d92011-01-04 21:28:14 +010057 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
58 __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
59
60 /* flush write */
61 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
62}
63
Thomas Gleixner3fb88182011-03-23 21:08:47 +000064static void ar71xx_misc_irq_mask(struct irq_data *d)
Gabor Juhosd4a67d92011-01-04 21:28:14 +010065{
Thomas Gleixner3fb88182011-03-23 21:08:47 +000066 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
Gabor Juhosd4a67d92011-01-04 21:28:14 +010067 void __iomem *base = ath79_reset_base;
68 u32 t;
69
Gabor Juhosd4a67d92011-01-04 21:28:14 +010070 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
71 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
72
73 /* flush write */
74 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
75}
76
Thomas Gleixner3fb88182011-03-23 21:08:47 +000077static void ar724x_misc_irq_ack(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_STATUS);
84 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_STATUS);
85
86 /* flush write */
87 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
88}
89
90static struct irq_chip ath79_misc_irq_chip = {
91 .name = "MISC",
Thomas Gleixner3fb88182011-03-23 21:08:47 +000092 .irq_unmask = ar71xx_misc_irq_unmask,
93 .irq_mask = ar71xx_misc_irq_mask,
Gabor Juhosd4a67d92011-01-04 21:28:14 +010094};
95
96static void __init ath79_misc_irq_init(void)
97{
98 void __iomem *base = ath79_reset_base;
99 int i;
100
101 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
102 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
103
104 if (soc_is_ar71xx() || soc_is_ar913x())
Thomas Gleixner3fb88182011-03-23 21:08:47 +0000105 ath79_misc_irq_chip.irq_mask_ack = ar71xx_misc_irq_mask;
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100106 else if (soc_is_ar724x() || soc_is_ar933x() || soc_is_ar934x())
Thomas Gleixner3fb88182011-03-23 21:08:47 +0000107 ath79_misc_irq_chip.irq_ack = ar724x_misc_irq_ack;
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100108 else
109 BUG();
110
111 for (i = ATH79_MISC_IRQ_BASE;
112 i < ATH79_MISC_IRQ_BASE + ATH79_MISC_IRQ_COUNT; i++) {
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200113 irq_set_chip_and_handler(i, &ath79_misc_irq_chip,
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100114 handle_level_irq);
115 }
116
Gabor Juhos7e69c102013-02-07 19:32:23 +0000117 irq_set_chained_handler(ATH79_CPU_IRQ(6), ath79_misc_irq_handler);
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100118}
119
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100120static void ar934x_ip2_irq_dispatch(unsigned int irq, struct irq_desc *desc)
121{
122 u32 status;
123
124 disable_irq_nosync(irq);
125
126 status = ath79_reset_rr(AR934X_RESET_REG_PCIE_WMAC_INT_STATUS);
127
128 if (status & AR934X_PCIE_WMAC_INT_PCIE_ALL) {
129 ath79_ddr_wb_flush(AR934X_DDR_REG_FLUSH_PCIE);
130 generic_handle_irq(ATH79_IP2_IRQ(0));
131 } else if (status & AR934X_PCIE_WMAC_INT_WMAC_ALL) {
132 ath79_ddr_wb_flush(AR934X_DDR_REG_FLUSH_WMAC);
133 generic_handle_irq(ATH79_IP2_IRQ(1));
134 } else {
135 spurious_interrupt();
136 }
137
138 enable_irq(irq);
139}
140
141static void ar934x_ip2_irq_init(void)
142{
143 int i;
144
145 for (i = ATH79_IP2_IRQ_BASE;
146 i < ATH79_IP2_IRQ_BASE + ATH79_IP2_IRQ_COUNT; i++)
147 irq_set_chip_and_handler(i, &dummy_irq_chip,
148 handle_level_irq);
149
Gabor Juhos7e69c102013-02-07 19:32:23 +0000150 irq_set_chained_handler(ATH79_CPU_IRQ(2), ar934x_ip2_irq_dispatch);
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100151}
152
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100153asmlinkage void plat_irq_dispatch(void)
154{
155 unsigned long pending;
156
157 pending = read_c0_status() & read_c0_cause() & ST0_IM;
158
159 if (pending & STATUSF_IP7)
Gabor Juhos7e69c102013-02-07 19:32:23 +0000160 do_IRQ(ATH79_CPU_IRQ(7));
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100161
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100162 else if (pending & STATUSF_IP2)
163 ath79_ip2_handler();
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100164
165 else if (pending & STATUSF_IP4)
Gabor Juhos7e69c102013-02-07 19:32:23 +0000166 do_IRQ(ATH79_CPU_IRQ(4));
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100167
168 else if (pending & STATUSF_IP5)
Gabor Juhos7e69c102013-02-07 19:32:23 +0000169 do_IRQ(ATH79_CPU_IRQ(5));
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100170
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100171 else if (pending & STATUSF_IP3)
172 ath79_ip3_handler();
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100173
174 else if (pending & STATUSF_IP6)
Gabor Juhos7e69c102013-02-07 19:32:23 +0000175 do_IRQ(ATH79_CPU_IRQ(6));
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100176
177 else
178 spurious_interrupt();
179}
180
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100181/*
182 * The IP2/IP3 lines are tied to a PCI/WMAC/USB device. Drivers for
183 * these devices typically allocate coherent DMA memory, however the
184 * DMA controller may still have some unsynchronized data in the FIFO.
185 * Issue a flush in the handlers to ensure that the driver sees
186 * the update.
187 */
188static void ar71xx_ip2_handler(void)
189{
190 ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_PCI);
Gabor Juhos7e69c102013-02-07 19:32:23 +0000191 do_IRQ(ATH79_CPU_IRQ(2));
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100192}
193
194static void ar724x_ip2_handler(void)
195{
196 ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_PCIE);
Gabor Juhos7e69c102013-02-07 19:32:23 +0000197 do_IRQ(ATH79_CPU_IRQ(2));
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100198}
199
200static void ar913x_ip2_handler(void)
201{
202 ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_WMAC);
Gabor Juhos7e69c102013-02-07 19:32:23 +0000203 do_IRQ(ATH79_CPU_IRQ(2));
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100204}
205
206static void ar933x_ip2_handler(void)
207{
208 ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_WMAC);
Gabor Juhos7e69c102013-02-07 19:32:23 +0000209 do_IRQ(ATH79_CPU_IRQ(2));
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100210}
211
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100212static void ar934x_ip2_handler(void)
213{
Gabor Juhos7e69c102013-02-07 19:32:23 +0000214 do_IRQ(ATH79_CPU_IRQ(2));
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100215}
216
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100217static void ar71xx_ip3_handler(void)
218{
219 ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_USB);
Gabor Juhos7e69c102013-02-07 19:32:23 +0000220 do_IRQ(ATH79_CPU_IRQ(3));
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100221}
222
223static void ar724x_ip3_handler(void)
224{
225 ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_USB);
Gabor Juhos7e69c102013-02-07 19:32:23 +0000226 do_IRQ(ATH79_CPU_IRQ(3));
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100227}
228
229static void ar913x_ip3_handler(void)
230{
231 ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_USB);
Gabor Juhos7e69c102013-02-07 19:32:23 +0000232 do_IRQ(ATH79_CPU_IRQ(3));
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100233}
234
235static void ar933x_ip3_handler(void)
236{
237 ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_USB);
Gabor Juhos7e69c102013-02-07 19:32:23 +0000238 do_IRQ(ATH79_CPU_IRQ(3));
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100239}
240
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100241static void ar934x_ip3_handler(void)
242{
243 ath79_ddr_wb_flush(AR934X_DDR_REG_FLUSH_USB);
Gabor Juhos7e69c102013-02-07 19:32:23 +0000244 do_IRQ(ATH79_CPU_IRQ(3));
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100245}
246
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100247void __init arch_init_irq(void)
248{
249 if (soc_is_ar71xx()) {
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100250 ath79_ip2_handler = ar71xx_ip2_handler;
251 ath79_ip3_handler = ar71xx_ip3_handler;
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100252 } else if (soc_is_ar724x()) {
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100253 ath79_ip2_handler = ar724x_ip2_handler;
254 ath79_ip3_handler = ar724x_ip3_handler;
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100255 } else if (soc_is_ar913x()) {
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100256 ath79_ip2_handler = ar913x_ip2_handler;
257 ath79_ip3_handler = ar913x_ip3_handler;
Gabor Juhos54eed4c2011-06-20 21:26:06 +0200258 } else if (soc_is_ar933x()) {
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100259 ath79_ip2_handler = ar933x_ip2_handler;
260 ath79_ip3_handler = ar933x_ip3_handler;
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100261 } else if (soc_is_ar934x()) {
262 ath79_ip2_handler = ar934x_ip2_handler;
263 ath79_ip3_handler = ar934x_ip3_handler;
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100264 } else {
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100265 BUG();
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100266 }
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100267
268 cp0_perfcount_irq = ATH79_MISC_IRQ_PERFC;
269 mips_cpu_irq_init();
270 ath79_misc_irq_init();
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100271
272 if (soc_is_ar934x())
273 ar934x_ip2_irq_init();
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100274}