2 * Atheros AR71xx SoC specific interrupt handling
4 * Copyright (C) 2008 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-ar71xx/ar71xx.h>
25 static void ar71xx_pci_irq_dispatch(void)
29 pending
= ar71xx_reset_rr(AR71XX_RESET_REG_PCI_INT_STATUS
) &
30 ar71xx_reset_rr(AR71XX_RESET_REG_PCI_INT_ENABLE
);
32 if (pending
& PCI_INT_DEV0
)
33 do_IRQ(AR71XX_PCI_IRQ_DEV0
);
35 else if (pending
& PCI_INT_DEV1
)
36 do_IRQ(AR71XX_PCI_IRQ_DEV1
);
38 else if (pending
& PCI_INT_DEV2
)
39 do_IRQ(AR71XX_PCI_IRQ_DEV2
);
45 static void ar71xx_pci_irq_unmask(unsigned int irq
)
47 irq
-= AR71XX_PCI_IRQ_BASE
;
48 ar71xx_reset_wr(AR71XX_RESET_REG_PCI_INT_ENABLE
,
49 ar71xx_reset_rr(AR71XX_RESET_REG_PCI_INT_ENABLE
) | (1 << irq
));
52 static void ar71xx_pci_irq_mask(unsigned int irq
)
54 irq
-= AR71XX_PCI_IRQ_BASE
;
55 ar71xx_reset_wr(AR71XX_RESET_REG_PCI_INT_ENABLE
,
56 ar71xx_reset_rr(AR71XX_RESET_REG_PCI_INT_ENABLE
) & ~(1 << irq
));
59 static struct irq_chip ar71xx_pci_irq_chip
= {
60 .name
= "AR71XX PCI ",
61 .mask
= ar71xx_pci_irq_mask
,
62 .unmask
= ar71xx_pci_irq_unmask
,
63 .mask_ack
= ar71xx_pci_irq_mask
,
66 static struct irqaction ar71xx_pci_irqaction
= {
68 .name
= "cascade [AR71XX PCI]",
71 static void __init
ar71xx_pci_irq_init(void)
75 ar71xx_reset_wr(AR71XX_RESET_REG_PCI_INT_ENABLE
, 0);
76 ar71xx_reset_wr(AR71XX_RESET_REG_PCI_INT_STATUS
, 0);
78 for (i
= AR71XX_PCI_IRQ_BASE
;
79 i
< AR71XX_PCI_IRQ_BASE
+ AR71XX_PCI_IRQ_COUNT
; i
++) {
80 irq_desc
[i
].status
= IRQ_DISABLED
;
81 set_irq_chip_and_handler(i
, &ar71xx_pci_irq_chip
,
85 setup_irq(AR71XX_CPU_IRQ_PCI
, &ar71xx_pci_irqaction
);
87 #endif /* CONFIG_PCI */
89 static void ar71xx_gpio_irq_dispatch(void)
93 pending
= ar71xx_gpio_rr(GPIO_REG_INT_PENDING
)
94 & ar71xx_gpio_rr(GPIO_REG_INT_ENABLE
);
97 do_IRQ(AR71XX_GPIO_IRQ_BASE
+ fls(pending
) - 1);
102 static void ar71xx_gpio_irq_unmask(unsigned int irq
)
104 irq
-= AR71XX_GPIO_IRQ_BASE
;
105 ar71xx_gpio_wr(GPIO_REG_INT_ENABLE
,
106 ar71xx_gpio_rr(GPIO_REG_INT_ENABLE
) | (1 << irq
));
109 static void ar71xx_gpio_irq_mask(unsigned int irq
)
111 irq
-= AR71XX_GPIO_IRQ_BASE
;
112 ar71xx_gpio_wr(GPIO_REG_INT_ENABLE
,
113 ar71xx_gpio_rr(GPIO_REG_INT_ENABLE
) & ~(1 << irq
));
117 static int ar71xx_gpio_irq_set_type(unsigned int irq
, unsigned int flow_type
)
119 /* TODO: implement */
123 #define ar71xx_gpio_irq_set_type NULL
126 struct irq_chip ar71xx_gpio_irq_chip
= {
127 .name
= "AR71XX GPIO",
128 .unmask
= ar71xx_gpio_irq_unmask
,
129 .mask
= ar71xx_gpio_irq_mask
,
130 .mask_ack
= ar71xx_gpio_irq_mask
,
131 .set_type
= ar71xx_gpio_irq_set_type
,
134 static struct irqaction ar71xx_gpio_irqaction
= {
135 .handler
= no_action
,
136 .name
= "cascade [AR71XX GPIO]",
139 #define GPIO_IRQ_INIT_STATUS (IRQ_LEVEL | IRQ_TYPE_LEVEL_HIGH | IRQ_DISABLED)
140 #define GPIO_INT_ALL 0xffff
142 static void __init
ar71xx_gpio_irq_init(void)
146 ar71xx_gpio_wr(GPIO_REG_INT_ENABLE
, 0);
147 ar71xx_gpio_wr(GPIO_REG_INT_PENDING
, 0);
149 /* setup type of all GPIO interrupts to level sensitive */
150 ar71xx_gpio_wr(GPIO_REG_INT_TYPE
, GPIO_INT_ALL
);
152 /* setup polarity of all GPIO interrupts to active high */
153 ar71xx_gpio_wr(GPIO_REG_INT_POLARITY
, GPIO_INT_ALL
);
155 for (i
= AR71XX_GPIO_IRQ_BASE
;
156 i
< AR71XX_GPIO_IRQ_BASE
+ AR71XX_GPIO_IRQ_COUNT
; i
++) {
157 irq_desc
[i
].status
= GPIO_IRQ_INIT_STATUS
;
158 set_irq_chip_and_handler(i
, &ar71xx_gpio_irq_chip
,
162 setup_irq(AR71XX_MISC_IRQ_GPIO
, &ar71xx_gpio_irqaction
);
165 static void ar71xx_misc_irq_dispatch(void)
169 pending
= ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_STATUS
)
170 & ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_ENABLE
);
172 if (pending
& MISC_INT_UART
)
173 do_IRQ(AR71XX_MISC_IRQ_UART
);
175 else if (pending
& MISC_INT_DMA
)
176 do_IRQ(AR71XX_MISC_IRQ_DMA
);
178 else if (pending
& MISC_INT_PERFC
)
179 do_IRQ(AR71XX_MISC_IRQ_PERFC
);
181 else if (pending
& MISC_INT_TIMER
)
182 do_IRQ(AR71XX_MISC_IRQ_TIMER
);
184 else if (pending
& MISC_INT_OHCI
)
185 do_IRQ(AR71XX_MISC_IRQ_OHCI
);
187 else if (pending
& MISC_INT_ERROR
)
188 do_IRQ(AR71XX_MISC_IRQ_ERROR
);
190 else if (pending
& MISC_INT_GPIO
)
191 ar71xx_gpio_irq_dispatch();
193 else if (pending
& MISC_INT_WDOG
)
194 do_IRQ(AR71XX_MISC_IRQ_WDOG
);
197 spurious_interrupt();
200 static void ar71xx_misc_irq_unmask(unsigned int irq
)
202 irq
-= AR71XX_MISC_IRQ_BASE
;
203 ar71xx_reset_wr(AR71XX_RESET_REG_MISC_INT_ENABLE
,
204 ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_ENABLE
) | (1 << irq
));
207 static void ar71xx_misc_irq_mask(unsigned int irq
)
209 irq
-= AR71XX_MISC_IRQ_BASE
;
210 ar71xx_reset_wr(AR71XX_RESET_REG_MISC_INT_ENABLE
,
211 ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_ENABLE
) & ~(1 << irq
));
214 struct irq_chip ar71xx_misc_irq_chip
= {
215 .name
= "AR71XX MISC",
216 .unmask
= ar71xx_misc_irq_unmask
,
217 .mask
= ar71xx_misc_irq_mask
,
218 .mask_ack
= ar71xx_misc_irq_mask
,
221 static struct irqaction ar71xx_misc_irqaction
= {
222 .handler
= no_action
,
223 .name
= "cascade [AR71XX MISC]",
226 static void __init
ar71xx_misc_irq_init(void)
230 ar71xx_reset_wr(AR71XX_RESET_REG_MISC_INT_ENABLE
, 0);
231 ar71xx_reset_wr(AR71XX_RESET_REG_MISC_INT_STATUS
, 0);
233 for (i
= AR71XX_MISC_IRQ_BASE
;
234 i
< AR71XX_MISC_IRQ_BASE
+ AR71XX_MISC_IRQ_COUNT
; i
++) {
235 irq_desc
[i
].status
= IRQ_DISABLED
;
236 set_irq_chip_and_handler(i
, &ar71xx_misc_irq_chip
,
240 setup_irq(AR71XX_CPU_IRQ_MISC
, &ar71xx_misc_irqaction
);
243 static void ar913x_wmac_irq_dispatch(void)
245 do_IRQ(AR71XX_CPU_IRQ_WMAC
);
248 static void (* ar71xx_ip2_irq_handler
)(void) = spurious_interrupt
;
250 asmlinkage
void plat_irq_dispatch(void)
252 unsigned long pending
;
254 pending
= read_c0_status() & read_c0_cause() & ST0_IM
;
256 if (pending
& STATUSF_IP7
)
257 do_IRQ(AR71XX_CPU_IRQ_TIMER
);
259 else if (pending
& STATUSF_IP2
)
260 ar71xx_ip2_irq_handler();
262 else if (pending
& STATUSF_IP4
)
263 do_IRQ(AR71XX_CPU_IRQ_GE0
);
265 else if (pending
& STATUSF_IP5
)
266 do_IRQ(AR71XX_CPU_IRQ_GE1
);
268 else if (pending
& STATUSF_IP3
)
269 do_IRQ(AR71XX_CPU_IRQ_USB
);
271 else if (pending
& STATUSF_IP6
)
272 ar71xx_misc_irq_dispatch();
275 spurious_interrupt();
278 void __init
arch_init_irq(void)
282 ar71xx_misc_irq_init();
284 switch (ar71xx_soc
) {
285 case AR71XX_SOC_AR7130
:
286 case AR71XX_SOC_AR7141
:
287 case AR71XX_SOC_AR7161
:
289 ar71xx_pci_irq_init();
290 ar71xx_ip2_irq_handler
= ar71xx_pci_irq_dispatch
;
293 case AR71XX_SOC_AR9130
:
294 case AR71XX_SOC_AR9132
:
295 ar71xx_ip2_irq_handler
= ar913x_wmac_irq_dispatch
;
301 ar71xx_gpio_irq_init();