blob: f5b148af8b8c4e90c059abd289665881824d7fe4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Sergei Shtylyov01675092008-03-24 23:15:50 +03002 * Copyright 2001, 2007-2008 MontaVista Software Inc.
3 * Author: MontaVista Software, Inc. <source@mvista.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +01005 * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
Manuel Lauss785e3262008-12-21 09:26:17 +010027
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/bitops.h>
Ralf Baechle41bd61a2007-10-15 00:51:34 +010029#include <linux/init.h>
Ralf Baechle41bd61a2007-10-15 00:51:34 +010030#include <linux/interrupt.h>
31#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +010033#include <asm/irq_cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/mipsregs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/mach-au1x00/au1000.h>
36#ifdef CONFIG_MIPS_PB1000
37#include <asm/mach-pb1x00/pb1000.h>
38#endif
39
Manuel Lauss785e3262008-12-21 09:26:17 +010040static int au1x_ic_settype(unsigned int irq, unsigned int flow_type);
41
Manuel Lauss50472012009-10-07 20:15:12 +020042/* NOTE on interrupt priorities: The original writers of this code said:
43 *
44 * Because of the tight timing of SETUP token to reply transactions,
45 * the USB devices-side packet complete interrupt (USB_DEV_REQ_INT)
46 * needs the highest priority.
47 */
48
Manuel Lauss785e3262008-12-21 09:26:17 +010049/* per-processor fixed function irqs */
Manuel Lauss7e50b2b2009-10-04 14:55:26 +020050struct au1xxx_irqmap {
51 int im_irq;
52 int im_type;
Manuel Lauss50472012009-10-07 20:15:12 +020053 int im_request; /* set 1 to get higher priority */
Manuel Lauss7e50b2b2009-10-04 14:55:26 +020054} au1xxx_ic0_map[] __initdata = {
Manuel Lauss785e3262008-12-21 09:26:17 +010055#if defined(CONFIG_SOC_AU1000)
Manuel Lauss78814462009-10-07 20:15:15 +020056 { AU1000_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
57 { AU1000_UART1_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
58 { AU1000_UART2_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
59 { AU1000_UART3_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
60 { AU1000_SSI0_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
61 { AU1000_SSI1_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
62 { AU1000_DMA_INT_BASE, IRQ_TYPE_LEVEL_HIGH, 0 },
63 { AU1000_DMA_INT_BASE+1, IRQ_TYPE_LEVEL_HIGH, 0 },
64 { AU1000_DMA_INT_BASE+2, IRQ_TYPE_LEVEL_HIGH, 0 },
65 { AU1000_DMA_INT_BASE+3, IRQ_TYPE_LEVEL_HIGH, 0 },
66 { AU1000_DMA_INT_BASE+4, IRQ_TYPE_LEVEL_HIGH, 0 },
67 { AU1000_DMA_INT_BASE+5, IRQ_TYPE_LEVEL_HIGH, 0 },
68 { AU1000_DMA_INT_BASE+6, IRQ_TYPE_LEVEL_HIGH, 0 },
69 { AU1000_DMA_INT_BASE+7, IRQ_TYPE_LEVEL_HIGH, 0 },
70 { AU1000_TOY_INT, IRQ_TYPE_EDGE_RISING, 0 },
71 { AU1000_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
72 { AU1000_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
73 { AU1000_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0 },
74 { AU1000_RTC_INT, IRQ_TYPE_EDGE_RISING, 0 },
75 { AU1000_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
76 { AU1000_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
77 { AU1000_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1 },
78 { AU1000_IRDA_TX_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
79 { AU1000_IRDA_RX_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
80 { AU1000_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH, 1 },
Manuel Lauss785e3262008-12-21 09:26:17 +010081 { AU1000_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 0 },
Manuel Lauss78814462009-10-07 20:15:15 +020082 { AU1000_USB_HOST_INT, IRQ_TYPE_LEVEL_LOW, 0 },
83 { AU1000_ACSYNC_INT, IRQ_TYPE_EDGE_RISING, 0 },
84 { AU1000_MAC0_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
85 { AU1000_MAC1_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
86 { AU1000_AC97C_INT, IRQ_TYPE_EDGE_RISING, 0 },
Manuel Lauss785e3262008-12-21 09:26:17 +010087
88#elif defined(CONFIG_SOC_AU1500)
89
Manuel Lauss78814462009-10-07 20:15:15 +020090 { AU1500_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
91 { AU1500_PCI_INTA, IRQ_TYPE_LEVEL_LOW, 0 },
92 { AU1500_PCI_INTB, IRQ_TYPE_LEVEL_LOW, 0 },
93 { AU1500_UART3_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
94 { AU1500_PCI_INTC, IRQ_TYPE_LEVEL_LOW, 0 },
95 { AU1500_PCI_INTD, IRQ_TYPE_LEVEL_LOW, 0 },
96 { AU1500_DMA_INT_BASE, IRQ_TYPE_LEVEL_HIGH, 0 },
97 { AU1500_DMA_INT_BASE+1, IRQ_TYPE_LEVEL_HIGH, 0 },
98 { AU1500_DMA_INT_BASE+2, IRQ_TYPE_LEVEL_HIGH, 0 },
99 { AU1500_DMA_INT_BASE+3, IRQ_TYPE_LEVEL_HIGH, 0 },
100 { AU1500_DMA_INT_BASE+4, IRQ_TYPE_LEVEL_HIGH, 0 },
101 { AU1500_DMA_INT_BASE+5, IRQ_TYPE_LEVEL_HIGH, 0 },
102 { AU1500_DMA_INT_BASE+6, IRQ_TYPE_LEVEL_HIGH, 0 },
103 { AU1500_DMA_INT_BASE+7, IRQ_TYPE_LEVEL_HIGH, 0 },
104 { AU1500_TOY_INT, IRQ_TYPE_EDGE_RISING, 0 },
105 { AU1500_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
106 { AU1500_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
107 { AU1500_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0 },
108 { AU1500_RTC_INT, IRQ_TYPE_EDGE_RISING, 0 },
109 { AU1500_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
110 { AU1500_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
111 { AU1500_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1 },
112 { AU1500_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH, 1 },
113 { AU1500_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 0 },
114 { AU1500_USB_HOST_INT, IRQ_TYPE_LEVEL_LOW, 0 },
115 { AU1500_ACSYNC_INT, IRQ_TYPE_EDGE_RISING, 0 },
116 { AU1500_MAC0_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
117 { AU1500_MAC1_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
118 { AU1500_AC97C_INT, IRQ_TYPE_EDGE_RISING, 0 },
Manuel Lauss785e3262008-12-21 09:26:17 +0100119
120#elif defined(CONFIG_SOC_AU1100)
121
Manuel Lauss78814462009-10-07 20:15:15 +0200122 { AU1100_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
123 { AU1100_UART1_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
124 { AU1100_SD_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
125 { AU1100_UART3_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
126 { AU1100_SSI0_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
127 { AU1100_SSI1_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
128 { AU1100_DMA_INT_BASE, IRQ_TYPE_LEVEL_HIGH, 0 },
129 { AU1100_DMA_INT_BASE+1, IRQ_TYPE_LEVEL_HIGH, 0 },
130 { AU1100_DMA_INT_BASE+2, IRQ_TYPE_LEVEL_HIGH, 0 },
131 { AU1100_DMA_INT_BASE+3, IRQ_TYPE_LEVEL_HIGH, 0 },
132 { AU1100_DMA_INT_BASE+4, IRQ_TYPE_LEVEL_HIGH, 0 },
133 { AU1100_DMA_INT_BASE+5, IRQ_TYPE_LEVEL_HIGH, 0 },
134 { AU1100_DMA_INT_BASE+6, IRQ_TYPE_LEVEL_HIGH, 0 },
135 { AU1100_DMA_INT_BASE+7, IRQ_TYPE_LEVEL_HIGH, 0 },
136 { AU1100_TOY_INT, IRQ_TYPE_EDGE_RISING, 0 },
137 { AU1100_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
138 { AU1100_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
139 { AU1100_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0 },
140 { AU1100_RTC_INT, IRQ_TYPE_EDGE_RISING, 0 },
141 { AU1100_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
142 { AU1100_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
143 { AU1100_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1 },
144 { AU1100_IRDA_TX_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
145 { AU1100_IRDA_RX_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
146 { AU1100_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH, 1 },
147 { AU1100_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 0 },
148 { AU1100_USB_HOST_INT, IRQ_TYPE_LEVEL_LOW, 0 },
149 { AU1100_ACSYNC_INT, IRQ_TYPE_EDGE_RISING, 0 },
150 { AU1100_MAC0_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
151 { AU1100_LCD_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
152 { AU1100_AC97C_INT, IRQ_TYPE_EDGE_RISING, 0 },
Manuel Lauss785e3262008-12-21 09:26:17 +0100153
154#elif defined(CONFIG_SOC_AU1550)
155
Manuel Lauss78814462009-10-07 20:15:15 +0200156 { AU1550_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
157 { AU1550_PCI_INTA, IRQ_TYPE_LEVEL_LOW, 0 },
158 { AU1550_PCI_INTB, IRQ_TYPE_LEVEL_LOW, 0 },
159 { AU1550_DDMA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
160 { AU1550_CRYPTO_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
161 { AU1550_PCI_INTC, IRQ_TYPE_LEVEL_LOW, 0 },
162 { AU1550_PCI_INTD, IRQ_TYPE_LEVEL_LOW, 0 },
163 { AU1550_PCI_RST_INT, IRQ_TYPE_LEVEL_LOW, 0 },
164 { AU1550_UART1_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
165 { AU1550_UART3_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
166 { AU1550_PSC0_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
167 { AU1550_PSC1_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
168 { AU1550_PSC2_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
169 { AU1550_PSC3_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
170 { AU1550_TOY_INT, IRQ_TYPE_EDGE_RISING, 0 },
171 { AU1550_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
172 { AU1550_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
173 { AU1550_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0 },
174 { AU1550_RTC_INT, IRQ_TYPE_EDGE_RISING, 0 },
175 { AU1550_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
176 { AU1550_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
177 { AU1550_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1 },
178 { AU1550_NAND_INT, IRQ_TYPE_EDGE_RISING, 0 },
179 { AU1550_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH, 1 },
Manuel Lauss785e3262008-12-21 09:26:17 +0100180 { AU1550_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 0 },
Manuel Lauss78814462009-10-07 20:15:15 +0200181 { AU1550_USB_HOST_INT, IRQ_TYPE_LEVEL_LOW, 0 },
182 { AU1550_MAC0_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
183 { AU1550_MAC1_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
Manuel Lauss785e3262008-12-21 09:26:17 +0100184
185#elif defined(CONFIG_SOC_AU1200)
186
Manuel Lauss78814462009-10-07 20:15:15 +0200187 { AU1200_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
188 { AU1200_SWT_INT, IRQ_TYPE_EDGE_RISING, 0 },
189 { AU1200_SD_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
190 { AU1200_DDMA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
191 { AU1200_MAE_BE_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
192 { AU1200_UART1_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
193 { AU1200_MAE_FE_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
194 { AU1200_PSC0_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
195 { AU1200_PSC1_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
196 { AU1200_AES_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
197 { AU1200_CAMERA_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
198 { AU1200_TOY_INT, IRQ_TYPE_EDGE_RISING, 0 },
199 { AU1200_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
200 { AU1200_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
201 { AU1200_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0 },
202 { AU1200_RTC_INT, IRQ_TYPE_EDGE_RISING, 0 },
203 { AU1200_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 0 },
204 { AU1200_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 0 },
205 { AU1200_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1 },
206 { AU1200_NAND_INT, IRQ_TYPE_EDGE_RISING, 0 },
207 { AU1200_USB_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
208 { AU1200_LCD_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
209 { AU1200_MAE_BOTH_INT, IRQ_TYPE_LEVEL_HIGH, 0 },
Manuel Lauss785e3262008-12-21 09:26:17 +0100210
211#else
212#error "Error: Unknown Alchemy SOC"
213#endif
214};
215
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217#ifdef CONFIG_PM
218
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100219/*
220 * Save/restore the interrupt controller state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 * Called from the save/restore core registers as part of the
222 * au_sleep function in power.c.....maybe I should just pm_register()
223 * them instead?
224 */
Ralf Baechlefc103342006-06-28 11:24:12 +0100225static unsigned int sleep_intctl_config0[2];
226static unsigned int sleep_intctl_config1[2];
227static unsigned int sleep_intctl_config2[2];
228static unsigned int sleep_intctl_src[2];
229static unsigned int sleep_intctl_assign[2];
230static unsigned int sleep_intctl_wake[2];
231static unsigned int sleep_intctl_mask[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100233void save_au1xxx_intctl(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
235 sleep_intctl_config0[0] = au_readl(IC0_CFG0RD);
236 sleep_intctl_config1[0] = au_readl(IC0_CFG1RD);
237 sleep_intctl_config2[0] = au_readl(IC0_CFG2RD);
238 sleep_intctl_src[0] = au_readl(IC0_SRCRD);
239 sleep_intctl_assign[0] = au_readl(IC0_ASSIGNRD);
240 sleep_intctl_wake[0] = au_readl(IC0_WAKERD);
241 sleep_intctl_mask[0] = au_readl(IC0_MASKRD);
242
243 sleep_intctl_config0[1] = au_readl(IC1_CFG0RD);
244 sleep_intctl_config1[1] = au_readl(IC1_CFG1RD);
245 sleep_intctl_config2[1] = au_readl(IC1_CFG2RD);
246 sleep_intctl_src[1] = au_readl(IC1_SRCRD);
247 sleep_intctl_assign[1] = au_readl(IC1_ASSIGNRD);
248 sleep_intctl_wake[1] = au_readl(IC1_WAKERD);
249 sleep_intctl_mask[1] = au_readl(IC1_MASKRD);
250}
251
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100252/*
253 * For most restore operations, we clear the entire register and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 * then set the bits we found during the save.
255 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100256void restore_au1xxx_intctl(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 au_writel(0xffffffff, IC0_MASKCLR); au_sync();
259
260 au_writel(0xffffffff, IC0_CFG0CLR); au_sync();
261 au_writel(sleep_intctl_config0[0], IC0_CFG0SET); au_sync();
262 au_writel(0xffffffff, IC0_CFG1CLR); au_sync();
263 au_writel(sleep_intctl_config1[0], IC0_CFG1SET); au_sync();
264 au_writel(0xffffffff, IC0_CFG2CLR); au_sync();
265 au_writel(sleep_intctl_config2[0], IC0_CFG2SET); au_sync();
266 au_writel(0xffffffff, IC0_SRCCLR); au_sync();
267 au_writel(sleep_intctl_src[0], IC0_SRCSET); au_sync();
268 au_writel(0xffffffff, IC0_ASSIGNCLR); au_sync();
269 au_writel(sleep_intctl_assign[0], IC0_ASSIGNSET); au_sync();
270 au_writel(0xffffffff, IC0_WAKECLR); au_sync();
271 au_writel(sleep_intctl_wake[0], IC0_WAKESET); au_sync();
272 au_writel(0xffffffff, IC0_RISINGCLR); au_sync();
273 au_writel(0xffffffff, IC0_FALLINGCLR); au_sync();
274 au_writel(0x00000000, IC0_TESTBIT); au_sync();
275
276 au_writel(0xffffffff, IC1_MASKCLR); au_sync();
277
278 au_writel(0xffffffff, IC1_CFG0CLR); au_sync();
279 au_writel(sleep_intctl_config0[1], IC1_CFG0SET); au_sync();
280 au_writel(0xffffffff, IC1_CFG1CLR); au_sync();
281 au_writel(sleep_intctl_config1[1], IC1_CFG1SET); au_sync();
282 au_writel(0xffffffff, IC1_CFG2CLR); au_sync();
283 au_writel(sleep_intctl_config2[1], IC1_CFG2SET); au_sync();
284 au_writel(0xffffffff, IC1_SRCCLR); au_sync();
285 au_writel(sleep_intctl_src[1], IC1_SRCSET); au_sync();
286 au_writel(0xffffffff, IC1_ASSIGNCLR); au_sync();
287 au_writel(sleep_intctl_assign[1], IC1_ASSIGNSET); au_sync();
288 au_writel(0xffffffff, IC1_WAKECLR); au_sync();
289 au_writel(sleep_intctl_wake[1], IC1_WAKESET); au_sync();
290 au_writel(0xffffffff, IC1_RISINGCLR); au_sync();
291 au_writel(0xffffffff, IC1_FALLINGCLR); au_sync();
292 au_writel(0x00000000, IC1_TESTBIT); au_sync();
293
294 au_writel(sleep_intctl_mask[1], IC1_MASKSET); au_sync();
295
296 au_writel(sleep_intctl_mask[0], IC0_MASKSET); au_sync();
297}
298#endif /* CONFIG_PM */
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100299
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100300
Manuel Lauss785e3262008-12-21 09:26:17 +0100301static void au1x_ic0_unmask(unsigned int irq_nr)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100302{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100303 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
Manuel Lauss785e3262008-12-21 09:26:17 +0100304 au_writel(1 << bit, IC0_MASKSET);
305 au_writel(1 << bit, IC0_WAKESET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100306 au_sync();
307}
308
Manuel Lauss785e3262008-12-21 09:26:17 +0100309static void au1x_ic1_unmask(unsigned int irq_nr)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100310{
Manuel Lauss785e3262008-12-21 09:26:17 +0100311 unsigned int bit = irq_nr - AU1000_INTC1_INT_BASE;
312 au_writel(1 << bit, IC1_MASKSET);
313 au_writel(1 << bit, IC1_WAKESET);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100314
Manuel Lauss785e3262008-12-21 09:26:17 +0100315/* very hacky. does the pb1000 cpld auto-disable this int?
316 * nowhere in the current kernel sources is it disabled. --mlau
317 */
318#if defined(CONFIG_MIPS_PB1000)
Manuel Lauss78814462009-10-07 20:15:15 +0200319 if (irq_nr == AU1000_GPIO15_INT)
Manuel Lauss785e3262008-12-21 09:26:17 +0100320 au_writel(0x4000, PB1000_MDR); /* enable int */
321#endif
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100322 au_sync();
323}
324
Manuel Lauss785e3262008-12-21 09:26:17 +0100325static void au1x_ic0_mask(unsigned int irq_nr)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100326{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100327 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
Manuel Lauss785e3262008-12-21 09:26:17 +0100328 au_writel(1 << bit, IC0_MASKCLR);
329 au_writel(1 << bit, IC0_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100330 au_sync();
331}
332
Manuel Lauss785e3262008-12-21 09:26:17 +0100333static void au1x_ic1_mask(unsigned int irq_nr)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100334{
Manuel Lauss785e3262008-12-21 09:26:17 +0100335 unsigned int bit = irq_nr - AU1000_INTC1_INT_BASE;
336 au_writel(1 << bit, IC1_MASKCLR);
337 au_writel(1 << bit, IC1_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100338 au_sync();
339}
340
Manuel Lauss785e3262008-12-21 09:26:17 +0100341static void au1x_ic0_ack(unsigned int irq_nr)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100342{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100343 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
344
345 /*
346 * This may assume that we don't get interrupts from
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100347 * both edges at once, or if we do, that we don't care.
348 */
Manuel Lauss785e3262008-12-21 09:26:17 +0100349 au_writel(1 << bit, IC0_FALLINGCLR);
350 au_writel(1 << bit, IC0_RISINGCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100351 au_sync();
352}
353
Manuel Lauss785e3262008-12-21 09:26:17 +0100354static void au1x_ic1_ack(unsigned int irq_nr)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100355{
Manuel Lauss785e3262008-12-21 09:26:17 +0100356 unsigned int bit = irq_nr - AU1000_INTC1_INT_BASE;
357
358 /*
359 * This may assume that we don't get interrupts from
360 * both edges at once, or if we do, that we don't care.
361 */
362 au_writel(1 << bit, IC1_FALLINGCLR);
363 au_writel(1 << bit, IC1_RISINGCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100364 au_sync();
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100365}
366
Manuel Lauss44f2c582009-10-14 12:22:20 +0200367static void au1x_ic0_maskack(unsigned int irq_nr)
368{
369 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
370
371 au_writel(1 << bit, IC0_WAKECLR);
372 au_writel(1 << bit, IC0_MASKCLR);
373 au_writel(1 << bit, IC0_RISINGCLR);
374 au_writel(1 << bit, IC0_FALLINGCLR);
375 au_sync();
376}
377
378static void au1x_ic1_maskack(unsigned int irq_nr)
379{
380 unsigned int bit = irq_nr - AU1000_INTC1_INT_BASE;
381
382 au_writel(1 << bit, IC1_WAKECLR);
383 au_writel(1 << bit, IC1_MASKCLR);
384 au_writel(1 << bit, IC1_RISINGCLR);
385 au_writel(1 << bit, IC1_FALLINGCLR);
386 au_sync();
387}
388
Manuel Lauss785e3262008-12-21 09:26:17 +0100389static int au1x_ic1_setwake(unsigned int irq, unsigned int on)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100390{
Manuel Lauss78814462009-10-07 20:15:15 +0200391 int bit = irq - AU1000_INTC1_INT_BASE;
Manuel Lauss785e3262008-12-21 09:26:17 +0100392 unsigned long wakemsk, flags;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100393
Manuel Lauss78814462009-10-07 20:15:15 +0200394 /* only GPIO 0-7 can act as wakeup source. Fortunately these
395 * are wired up identically on all supported variants.
396 */
397 if ((bit < 0) || (bit > 7))
Manuel Lauss785e3262008-12-21 09:26:17 +0100398 return -EINVAL;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100399
Manuel Lauss785e3262008-12-21 09:26:17 +0100400 local_irq_save(flags);
401 wakemsk = au_readl(SYS_WAKEMSK);
402 if (on)
403 wakemsk |= 1 << bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100404 else
Manuel Lauss785e3262008-12-21 09:26:17 +0100405 wakemsk &= ~(1 << bit);
406 au_writel(wakemsk, SYS_WAKEMSK);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100407 au_sync();
Manuel Lauss785e3262008-12-21 09:26:17 +0100408 local_irq_restore(flags);
409
410 return 0;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100411}
412
413/*
Manuel Lauss785e3262008-12-21 09:26:17 +0100414 * irq_chips for both ICs; this way the mask handlers can be
415 * as short as possible.
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100416 */
Manuel Lauss785e3262008-12-21 09:26:17 +0100417static struct irq_chip au1x_ic0_chip = {
418 .name = "Alchemy-IC0",
Manuel Lauss44f2c582009-10-14 12:22:20 +0200419 .ack = au1x_ic0_ack,
Manuel Lauss785e3262008-12-21 09:26:17 +0100420 .mask = au1x_ic0_mask,
Manuel Lauss44f2c582009-10-14 12:22:20 +0200421 .mask_ack = au1x_ic0_maskack,
Manuel Lauss785e3262008-12-21 09:26:17 +0100422 .unmask = au1x_ic0_unmask,
423 .set_type = au1x_ic_settype,
424};
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100425
Manuel Lauss785e3262008-12-21 09:26:17 +0100426static struct irq_chip au1x_ic1_chip = {
427 .name = "Alchemy-IC1",
Manuel Lauss44f2c582009-10-14 12:22:20 +0200428 .ack = au1x_ic1_ack,
Manuel Lauss785e3262008-12-21 09:26:17 +0100429 .mask = au1x_ic1_mask,
Manuel Lauss44f2c582009-10-14 12:22:20 +0200430 .mask_ack = au1x_ic1_maskack,
Manuel Lauss785e3262008-12-21 09:26:17 +0100431 .unmask = au1x_ic1_unmask,
432 .set_type = au1x_ic_settype,
433 .set_wake = au1x_ic1_setwake,
434};
435
436static int au1x_ic_settype(unsigned int irq, unsigned int flow_type)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100437{
Manuel Lauss785e3262008-12-21 09:26:17 +0100438 struct irq_chip *chip;
439 unsigned long icr[6];
440 unsigned int bit, ic;
441 int ret;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100442
Manuel Lauss785e3262008-12-21 09:26:17 +0100443 if (irq >= AU1000_INTC1_INT_BASE) {
444 bit = irq - AU1000_INTC1_INT_BASE;
445 chip = &au1x_ic1_chip;
446 ic = 1;
447 } else {
448 bit = irq - AU1000_INTC0_INT_BASE;
449 chip = &au1x_ic0_chip;
450 ic = 0;
451 }
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100452
Manuel Lauss785e3262008-12-21 09:26:17 +0100453 if (bit > 31)
454 return -EINVAL;
455
456 icr[0] = ic ? IC1_CFG0SET : IC0_CFG0SET;
457 icr[1] = ic ? IC1_CFG1SET : IC0_CFG1SET;
458 icr[2] = ic ? IC1_CFG2SET : IC0_CFG2SET;
459 icr[3] = ic ? IC1_CFG0CLR : IC0_CFG0CLR;
460 icr[4] = ic ? IC1_CFG1CLR : IC0_CFG1CLR;
461 icr[5] = ic ? IC1_CFG2CLR : IC0_CFG2CLR;
462
463 ret = 0;
464
465 switch (flow_type) { /* cfgregs 2:1:0 */
466 case IRQ_TYPE_EDGE_RISING: /* 0:0:1 */
467 au_writel(1 << bit, icr[5]);
468 au_writel(1 << bit, icr[4]);
469 au_writel(1 << bit, icr[0]);
470 set_irq_chip_and_handler_name(irq, chip,
471 handle_edge_irq, "riseedge");
472 break;
473 case IRQ_TYPE_EDGE_FALLING: /* 0:1:0 */
474 au_writel(1 << bit, icr[5]);
475 au_writel(1 << bit, icr[1]);
476 au_writel(1 << bit, icr[3]);
477 set_irq_chip_and_handler_name(irq, chip,
478 handle_edge_irq, "falledge");
479 break;
480 case IRQ_TYPE_EDGE_BOTH: /* 0:1:1 */
481 au_writel(1 << bit, icr[5]);
482 au_writel(1 << bit, icr[1]);
483 au_writel(1 << bit, icr[0]);
484 set_irq_chip_and_handler_name(irq, chip,
485 handle_edge_irq, "bothedge");
486 break;
487 case IRQ_TYPE_LEVEL_HIGH: /* 1:0:1 */
488 au_writel(1 << bit, icr[2]);
489 au_writel(1 << bit, icr[4]);
490 au_writel(1 << bit, icr[0]);
491 set_irq_chip_and_handler_name(irq, chip,
492 handle_level_irq, "hilevel");
493 break;
494 case IRQ_TYPE_LEVEL_LOW: /* 1:1:0 */
495 au_writel(1 << bit, icr[2]);
496 au_writel(1 << bit, icr[1]);
497 au_writel(1 << bit, icr[3]);
498 set_irq_chip_and_handler_name(irq, chip,
499 handle_level_irq, "lowlevel");
500 break;
501 case IRQ_TYPE_NONE: /* 0:0:0 */
502 au_writel(1 << bit, icr[5]);
503 au_writel(1 << bit, icr[4]);
504 au_writel(1 << bit, icr[3]);
505 /* set at least chip so we can call set_irq_type() on it */
506 set_irq_chip(irq, chip);
507 break;
508 default:
509 ret = -EINVAL;
510 }
511 au_sync();
512
513 return ret;
514}
515
516asmlinkage void plat_irq_dispatch(void)
517{
518 unsigned int pending = read_c0_status() & read_c0_cause();
Manuel Lauss50472012009-10-07 20:15:12 +0200519 unsigned long s, off;
Manuel Lauss785e3262008-12-21 09:26:17 +0100520
521 if (pending & CAUSEF_IP7) {
522 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100523 return;
Manuel Lauss785e3262008-12-21 09:26:17 +0100524 } else if (pending & CAUSEF_IP2) {
525 s = IC0_REQ0INT;
526 off = AU1000_INTC0_INT_BASE;
527 } else if (pending & CAUSEF_IP3) {
528 s = IC0_REQ1INT;
529 off = AU1000_INTC0_INT_BASE;
530 } else if (pending & CAUSEF_IP4) {
531 s = IC1_REQ0INT;
532 off = AU1000_INTC1_INT_BASE;
533 } else if (pending & CAUSEF_IP5) {
534 s = IC1_REQ1INT;
535 off = AU1000_INTC1_INT_BASE;
536 } else
537 goto spurious;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100538
Manuel Lauss785e3262008-12-21 09:26:17 +0100539 s = au_readl(s);
540 if (unlikely(!s)) {
541spurious:
542 spurious_interrupt();
543 return;
544 }
Manuel Lauss785e3262008-12-21 09:26:17 +0100545 do_IRQ(__ffs(s) + off);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100546}
547
Manuel Lauss785e3262008-12-21 09:26:17 +0100548/* setup edge/level and assign request 0/1 */
Manuel Lauss7e50b2b2009-10-04 14:55:26 +0200549static void __init setup_irqmap(struct au1xxx_irqmap *map, int count)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100550{
Manuel Lauss785e3262008-12-21 09:26:17 +0100551 unsigned int bit, irq_nr;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100552
Manuel Lauss785e3262008-12-21 09:26:17 +0100553 while (count--) {
554 irq_nr = map[count].im_irq;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100555
Manuel Lauss785e3262008-12-21 09:26:17 +0100556 if (((irq_nr < AU1000_INTC0_INT_BASE) ||
557 (irq_nr >= AU1000_INTC0_INT_BASE + 32)) &&
558 ((irq_nr < AU1000_INTC1_INT_BASE) ||
559 (irq_nr >= AU1000_INTC1_INT_BASE + 32)))
560 continue;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100561
Manuel Lauss785e3262008-12-21 09:26:17 +0100562 if (irq_nr >= AU1000_INTC1_INT_BASE) {
563 bit = irq_nr - AU1000_INTC1_INT_BASE;
564 if (map[count].im_request)
Manuel Lauss50472012009-10-07 20:15:12 +0200565 au_writel(1 << bit, IC1_ASSIGNSET);
Manuel Lauss785e3262008-12-21 09:26:17 +0100566 } else {
567 bit = irq_nr - AU1000_INTC0_INT_BASE;
568 if (map[count].im_request)
Manuel Lauss50472012009-10-07 20:15:12 +0200569 au_writel(1 << bit, IC0_ASSIGNSET);
Manuel Lauss785e3262008-12-21 09:26:17 +0100570 }
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100571
Manuel Lauss785e3262008-12-21 09:26:17 +0100572 au1x_ic_settype(irq_nr, map[count].im_type);
573 }
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100574}
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100575
576void __init arch_init_irq(void)
577{
578 int i;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100579
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100580 /*
581 * Initialize interrupt controllers to a safe state.
582 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100583 au_writel(0xffffffff, IC0_CFG0CLR);
584 au_writel(0xffffffff, IC0_CFG1CLR);
585 au_writel(0xffffffff, IC0_CFG2CLR);
586 au_writel(0xffffffff, IC0_MASKCLR);
Manuel Lauss50472012009-10-07 20:15:12 +0200587 au_writel(0xffffffff, IC0_ASSIGNCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100588 au_writel(0xffffffff, IC0_WAKECLR);
589 au_writel(0xffffffff, IC0_SRCSET);
590 au_writel(0xffffffff, IC0_FALLINGCLR);
591 au_writel(0xffffffff, IC0_RISINGCLR);
592 au_writel(0x00000000, IC0_TESTBIT);
593
594 au_writel(0xffffffff, IC1_CFG0CLR);
595 au_writel(0xffffffff, IC1_CFG1CLR);
596 au_writel(0xffffffff, IC1_CFG2CLR);
597 au_writel(0xffffffff, IC1_MASKCLR);
Manuel Lauss50472012009-10-07 20:15:12 +0200598 au_writel(0xffffffff, IC1_ASSIGNCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100599 au_writel(0xffffffff, IC1_WAKECLR);
600 au_writel(0xffffffff, IC1_SRCSET);
601 au_writel(0xffffffff, IC1_FALLINGCLR);
602 au_writel(0xffffffff, IC1_RISINGCLR);
603 au_writel(0x00000000, IC1_TESTBIT);
604
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100605 mips_cpu_irq_init();
606
Manuel Lauss785e3262008-12-21 09:26:17 +0100607 /* register all 64 possible IC0+IC1 irq sources as type "none".
608 * Use set_irq_type() to set edge/level behaviour at runtime.
609 */
610 for (i = AU1000_INTC0_INT_BASE;
611 (i < AU1000_INTC0_INT_BASE + 32); i++)
612 au1x_ic_settype(i, IRQ_TYPE_NONE);
613
614 for (i = AU1000_INTC1_INT_BASE;
615 (i < AU1000_INTC1_INT_BASE + 32); i++)
616 au1x_ic_settype(i, IRQ_TYPE_NONE);
617
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100618 /*
619 * Initialize IC0, which is fixed per processor.
620 */
Manuel Lauss7e50b2b2009-10-04 14:55:26 +0200621 setup_irqmap(au1xxx_ic0_map, ARRAY_SIZE(au1xxx_ic0_map));
Manuel Lauss785e3262008-12-21 09:26:17 +0100622
623 set_c0_status(IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3);
624}