2 * Atheros AR71xx/AR724x/AR913x specific interrupt handling
4 * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
5 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
6 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
8 * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
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.
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/interrupt.h>
18 #include <linux/irq.h>
20 #include <asm/irq_cpu.h>
21 #include <asm/mipsregs.h>
23 #include <asm/mach-ath79/ath79.h>
24 #include <asm/mach-ath79/ar71xx_regs.h>
27 static void (*ath79_ip2_handler
)(void);
28 static void (*ath79_ip3_handler
)(void);
30 static void ath79_misc_irq_handler(unsigned int irq
, struct irq_desc
*desc
)
32 void __iomem
*base
= ath79_reset_base
;
35 pending
= __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_STATUS
) &
36 __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
44 int bit
= __ffs(pending
);
46 generic_handle_irq(ATH79_MISC_IRQ(bit
));
51 static void ar71xx_misc_irq_unmask(struct irq_data
*d
)
53 unsigned int irq
= d
->irq
- ATH79_MISC_IRQ_BASE
;
54 void __iomem
*base
= ath79_reset_base
;
57 t
= __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
58 __raw_writel(t
| (1 << irq
), base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
61 __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
64 static void ar71xx_misc_irq_mask(struct irq_data
*d
)
66 unsigned int irq
= d
->irq
- ATH79_MISC_IRQ_BASE
;
67 void __iomem
*base
= ath79_reset_base
;
70 t
= __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
71 __raw_writel(t
& ~(1 << irq
), base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
74 __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
77 static void ar724x_misc_irq_ack(struct irq_data
*d
)
79 unsigned int irq
= d
->irq
- ATH79_MISC_IRQ_BASE
;
80 void __iomem
*base
= ath79_reset_base
;
83 t
= __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_STATUS
);
84 __raw_writel(t
& ~(1 << irq
), base
+ AR71XX_RESET_REG_MISC_INT_STATUS
);
87 __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_STATUS
);
90 static struct irq_chip ath79_misc_irq_chip
= {
92 .irq_unmask
= ar71xx_misc_irq_unmask
,
93 .irq_mask
= ar71xx_misc_irq_mask
,
96 static void __init
ath79_misc_irq_init(void)
98 void __iomem
*base
= ath79_reset_base
;
101 __raw_writel(0, base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
102 __raw_writel(0, base
+ AR71XX_RESET_REG_MISC_INT_STATUS
);
104 if (soc_is_ar71xx() || soc_is_ar913x())
105 ath79_misc_irq_chip
.irq_mask_ack
= ar71xx_misc_irq_mask
;
106 else if (soc_is_ar724x() ||
110 ath79_misc_irq_chip
.irq_ack
= ar724x_misc_irq_ack
;
114 for (i
= ATH79_MISC_IRQ_BASE
;
115 i
< ATH79_MISC_IRQ_BASE
+ ATH79_MISC_IRQ_COUNT
; i
++) {
116 irq_set_chip_and_handler(i
, &ath79_misc_irq_chip
,
120 irq_set_chained_handler(ATH79_CPU_IRQ(6), ath79_misc_irq_handler
);
123 static void ar934x_ip2_irq_dispatch(unsigned int irq
, struct irq_desc
*desc
)
127 disable_irq_nosync(irq
);
129 status
= ath79_reset_rr(AR934X_RESET_REG_PCIE_WMAC_INT_STATUS
);
131 if (status
& AR934X_PCIE_WMAC_INT_PCIE_ALL
) {
132 ath79_ddr_wb_flush(AR934X_DDR_REG_FLUSH_PCIE
);
133 generic_handle_irq(ATH79_IP2_IRQ(0));
134 } else if (status
& AR934X_PCIE_WMAC_INT_WMAC_ALL
) {
135 ath79_ddr_wb_flush(AR934X_DDR_REG_FLUSH_WMAC
);
136 generic_handle_irq(ATH79_IP2_IRQ(1));
138 spurious_interrupt();
144 static void ar934x_ip2_irq_init(void)
148 for (i
= ATH79_IP2_IRQ_BASE
;
149 i
< ATH79_IP2_IRQ_BASE
+ ATH79_IP2_IRQ_COUNT
; i
++)
150 irq_set_chip_and_handler(i
, &dummy_irq_chip
,
153 irq_set_chained_handler(ATH79_CPU_IRQ(2), ar934x_ip2_irq_dispatch
);
156 static void qca955x_ip2_irq_dispatch(unsigned int irq
, struct irq_desc
*desc
)
160 disable_irq_nosync(irq
);
162 status
= ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS
);
163 status
&= QCA955X_EXT_INT_PCIE_RC1_ALL
| QCA955X_EXT_INT_WMAC_ALL
;
166 spurious_interrupt();
170 if (status
& QCA955X_EXT_INT_PCIE_RC1_ALL
) {
171 /* TODO: flush DDR? */
172 generic_handle_irq(ATH79_IP2_IRQ(0));
175 if (status
& QCA955X_EXT_INT_WMAC_ALL
) {
176 /* TODO: flush DDR? */
177 generic_handle_irq(ATH79_IP2_IRQ(1));
184 static void qca955x_ip3_irq_dispatch(unsigned int irq
, struct irq_desc
*desc
)
188 disable_irq_nosync(irq
);
190 status
= ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS
);
191 status
&= QCA955X_EXT_INT_PCIE_RC2_ALL
|
192 QCA955X_EXT_INT_USB1
|
193 QCA955X_EXT_INT_USB2
;
196 spurious_interrupt();
200 if (status
& QCA955X_EXT_INT_USB1
) {
201 /* TODO: flush DDR? */
202 generic_handle_irq(ATH79_IP3_IRQ(0));
205 if (status
& QCA955X_EXT_INT_USB2
) {
206 /* TODO: flush DDR? */
207 generic_handle_irq(ATH79_IP3_IRQ(1));
210 if (status
& QCA955X_EXT_INT_PCIE_RC2_ALL
) {
211 /* TODO: flush DDR? */
212 generic_handle_irq(ATH79_IP3_IRQ(2));
219 static void qca955x_irq_init(void)
223 for (i
= ATH79_IP2_IRQ_BASE
;
224 i
< ATH79_IP2_IRQ_BASE
+ ATH79_IP2_IRQ_COUNT
; i
++)
225 irq_set_chip_and_handler(i
, &dummy_irq_chip
,
228 irq_set_chained_handler(ATH79_CPU_IRQ(2), qca955x_ip2_irq_dispatch
);
230 for (i
= ATH79_IP3_IRQ_BASE
;
231 i
< ATH79_IP3_IRQ_BASE
+ ATH79_IP3_IRQ_COUNT
; i
++)
232 irq_set_chip_and_handler(i
, &dummy_irq_chip
,
235 irq_set_chained_handler(ATH79_CPU_IRQ(3), qca955x_ip3_irq_dispatch
);
238 asmlinkage
void plat_irq_dispatch(void)
240 unsigned long pending
;
242 pending
= read_c0_status() & read_c0_cause() & ST0_IM
;
244 if (pending
& STATUSF_IP7
)
245 do_IRQ(ATH79_CPU_IRQ(7));
247 else if (pending
& STATUSF_IP2
)
250 else if (pending
& STATUSF_IP4
)
251 do_IRQ(ATH79_CPU_IRQ(4));
253 else if (pending
& STATUSF_IP5
)
254 do_IRQ(ATH79_CPU_IRQ(5));
256 else if (pending
& STATUSF_IP3
)
259 else if (pending
& STATUSF_IP6
)
260 do_IRQ(ATH79_CPU_IRQ(6));
263 spurious_interrupt();
267 * The IP2/IP3 lines are tied to a PCI/WMAC/USB device. Drivers for
268 * these devices typically allocate coherent DMA memory, however the
269 * DMA controller may still have some unsynchronized data in the FIFO.
270 * Issue a flush in the handlers to ensure that the driver sees
274 static void ath79_default_ip2_handler(void)
276 do_IRQ(ATH79_CPU_IRQ(2));
279 static void ath79_default_ip3_handler(void)
281 do_IRQ(ATH79_CPU_IRQ(3));
284 static void ar71xx_ip2_handler(void)
286 ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_PCI
);
287 do_IRQ(ATH79_CPU_IRQ(2));
290 static void ar724x_ip2_handler(void)
292 ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_PCIE
);
293 do_IRQ(ATH79_CPU_IRQ(2));
296 static void ar913x_ip2_handler(void)
298 ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_WMAC
);
299 do_IRQ(ATH79_CPU_IRQ(2));
302 static void ar933x_ip2_handler(void)
304 ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_WMAC
);
305 do_IRQ(ATH79_CPU_IRQ(2));
308 static void ar71xx_ip3_handler(void)
310 ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_USB
);
311 do_IRQ(ATH79_CPU_IRQ(3));
314 static void ar724x_ip3_handler(void)
316 ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_USB
);
317 do_IRQ(ATH79_CPU_IRQ(3));
320 static void ar913x_ip3_handler(void)
322 ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_USB
);
323 do_IRQ(ATH79_CPU_IRQ(3));
326 static void ar933x_ip3_handler(void)
328 ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_USB
);
329 do_IRQ(ATH79_CPU_IRQ(3));
332 static void ar934x_ip3_handler(void)
334 ath79_ddr_wb_flush(AR934X_DDR_REG_FLUSH_USB
);
335 do_IRQ(ATH79_CPU_IRQ(3));
338 void __init
arch_init_irq(void)
340 if (soc_is_ar71xx()) {
341 ath79_ip2_handler
= ar71xx_ip2_handler
;
342 ath79_ip3_handler
= ar71xx_ip3_handler
;
343 } else if (soc_is_ar724x()) {
344 ath79_ip2_handler
= ar724x_ip2_handler
;
345 ath79_ip3_handler
= ar724x_ip3_handler
;
346 } else if (soc_is_ar913x()) {
347 ath79_ip2_handler
= ar913x_ip2_handler
;
348 ath79_ip3_handler
= ar913x_ip3_handler
;
349 } else if (soc_is_ar933x()) {
350 ath79_ip2_handler
= ar933x_ip2_handler
;
351 ath79_ip3_handler
= ar933x_ip3_handler
;
352 } else if (soc_is_ar934x()) {
353 ath79_ip2_handler
= ath79_default_ip2_handler
;
354 ath79_ip3_handler
= ar934x_ip3_handler
;
355 } else if (soc_is_qca955x()) {
356 ath79_ip2_handler
= ath79_default_ip2_handler
;
357 ath79_ip3_handler
= ath79_default_ip3_handler
;
363 ath79_misc_irq_init();
366 ar934x_ip2_irq_init();
367 else if (soc_is_qca955x())