irq.c 21.4 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3
 * Copyright 2001, 2007-2008 MontaVista Software Inc.
 * Author: MontaVista Software, Inc. <source@mvista.com>
L
Linus Torvalds 已提交
4
 *
5 6
 * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
 *
L
Linus Torvalds 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *  This program is free software; you can redistribute	 it and/or modify it
 *  under  the terms of	 the GNU General  Public License as published by the
 *  Free Software Foundation;  either version 2 of the	License, or (at your
 *  option) any later version.
 *
 *  THIS  SOFTWARE  IS PROVIDED	  ``AS	IS'' AND   ANY	EXPRESS OR IMPLIED
 *  WARRANTIES,	  INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
 *  NO	EVENT  SHALL   THE AUTHOR  BE	 LIABLE FOR ANY	  DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 *  NOT LIMITED	  TO, PROCUREMENT OF  SUBSTITUTE GOODS	OR SERVICES; LOSS OF
 *  USE, DATA,	OR PROFITS; OR	BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 *  ANY THEORY OF LIABILITY, WHETHER IN	 CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *  You should have received a copy of the  GNU General Public License along
 *  with this program; if not, write  to the Free Software Foundation, Inc.,
 *  675 Mass Ave, Cambridge, MA 02139, USA.
 */
27

28
#include <linux/bitops.h>
L
Linus Torvalds 已提交
29 30
#include <linux/init.h>
#include <linux/interrupt.h>
31
#include <linux/irq.h>
32 33
#include <linux/slab.h>
#include <linux/sysdev.h>
L
Linus Torvalds 已提交
34

35
#include <asm/irq_cpu.h>
L
Linus Torvalds 已提交
36 37 38 39 40 41
#include <asm/mipsregs.h>
#include <asm/mach-au1x00/au1000.h>
#ifdef CONFIG_MIPS_PB1000
#include <asm/mach-pb1x00/pb1000.h>
#endif

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/* Interrupt Controller register offsets */
#define IC_CFG0RD	0x40
#define IC_CFG0SET	0x40
#define IC_CFG0CLR	0x44
#define IC_CFG1RD	0x48
#define IC_CFG1SET	0x48
#define IC_CFG1CLR	0x4C
#define IC_CFG2RD	0x50
#define IC_CFG2SET	0x50
#define IC_CFG2CLR	0x54
#define IC_REQ0INT	0x54
#define IC_SRCRD	0x58
#define IC_SRCSET	0x58
#define IC_SRCCLR	0x5C
#define IC_REQ1INT	0x5C
#define IC_ASSIGNRD	0x60
#define IC_ASSIGNSET	0x60
#define IC_ASSIGNCLR	0x64
#define IC_WAKERD	0x68
#define IC_WAKESET	0x68
#define IC_WAKECLR	0x6C
#define IC_MASKRD	0x70
#define IC_MASKSET	0x70
#define IC_MASKCLR	0x74
#define IC_RISINGRD	0x78
#define IC_RISINGCLR	0x78
#define IC_FALLINGRD	0x7C
#define IC_FALLINGCLR	0x7C
#define IC_TESTBIT	0x80

72
static int au1x_ic_settype(struct irq_data *d, unsigned int flow_type);
73

74 75 76 77 78 79 80
/* NOTE on interrupt priorities: The original writers of this code said:
 *
 * Because of the tight timing of SETUP token to reply transactions,
 * the USB devices-side packet complete interrupt (USB_DEV_REQ_INT)
 * needs the highest priority.
 */

81
/* per-processor fixed function irqs */
82 83 84
struct au1xxx_irqmap {
	int im_irq;
	int im_type;
85
	int im_request;		/* set 1 to get higher priority */
86 87 88
};

struct au1xxx_irqmap au1000_irqmap[] __initdata = {
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
	{ AU1000_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_UART2_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_SSI0_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_SSI1_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_DMA_INT_BASE,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_DMA_INT_BASE+1,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_DMA_INT_BASE+2,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_DMA_INT_BASE+3,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_DMA_INT_BASE+4,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_DMA_INT_BASE+5,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_DMA_INT_BASE+6,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_DMA_INT_BASE+7,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1000_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1000_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1000_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1000_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1000_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1000_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1000_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1 },
	{ AU1000_IRDA_TX_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_IRDA_RX_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,  1 },
114
	{ AU1000_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 0 },
115 116 117 118 119
	{ AU1000_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1000_ACSYNC_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1000_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_MAC1_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1000_AC97C_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
120 121
	{ -1, },
};
122

123
struct au1xxx_irqmap au1500_irqmap[] __initdata = {
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
	{ AU1500_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_PCI_INTA,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1500_PCI_INTB,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1500_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_PCI_INTC,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1500_PCI_INTD,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1500_DMA_INT_BASE,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_DMA_INT_BASE+1,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_DMA_INT_BASE+2,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_DMA_INT_BASE+3,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_DMA_INT_BASE+4,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_DMA_INT_BASE+5,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_DMA_INT_BASE+6,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_DMA_INT_BASE+7,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1500_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1500_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1500_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1500_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1500_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1500_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1500_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1 },
	{ AU1500_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,  1 },
	{ AU1500_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1500_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1500_ACSYNC_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1500_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_MAC1_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1500_AC97C_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
153 154
	{ -1, },
};
155

156
struct au1xxx_irqmap au1100_irqmap[] __initdata = {
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
	{ AU1100_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_SD_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_SSI0_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_SSI1_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_DMA_INT_BASE,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_DMA_INT_BASE+1,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_DMA_INT_BASE+2,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_DMA_INT_BASE+3,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_DMA_INT_BASE+4,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_DMA_INT_BASE+5,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_DMA_INT_BASE+6,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_DMA_INT_BASE+7,  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1100_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1100_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1100_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1100_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1100_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1100_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1100_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1 },
	{ AU1100_IRDA_TX_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_IRDA_RX_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,  1 },
	{ AU1100_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1100_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1100_ACSYNC_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1100_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_LCD_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1100_AC97C_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
188 189
	{ -1, },
};
190

191
struct au1xxx_irqmap au1550_irqmap[] __initdata = {
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
	{ AU1550_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_PCI_INTA,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1550_PCI_INTB,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1550_DDMA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_CRYPTO_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_PCI_INTC,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1550_PCI_INTD,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1550_PCI_RST_INT,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1550_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_PSC0_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_PSC1_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_PSC2_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_PSC3_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1550_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1550_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1550_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1550_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1550_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1550_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1550_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1 },
	{ AU1550_NAND_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1550_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,  1 },
216
	{ AU1550_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 0 },
217 218 219
	{ AU1550_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,   0 },
	{ AU1550_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1550_MAC1_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
220 221
	{ -1, },
};
222

223
struct au1xxx_irqmap au1200_irqmap[] __initdata = {
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
	{ AU1200_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_SWT_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1200_SD_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_DDMA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_MAE_BE_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_MAE_FE_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_PSC0_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_PSC1_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_AES_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_CAMERA_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1200_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1200_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1200_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1200_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1200_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1200_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1200_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1 },
	{ AU1200_NAND_INT,	  IRQ_TYPE_EDGE_RISING, 0 },
	{ AU1200_USB_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_LCD_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
	{ AU1200_MAE_BOTH_INT,	  IRQ_TYPE_LEVEL_HIGH,  0 },
247
	{ -1, },
248
};
L
Linus Torvalds 已提交
249 250


251
static void au1x_ic0_unmask(struct irq_data *d)
L
Linus Torvalds 已提交
252
{
253
	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
254 255 256 257 258
	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);

	__raw_writel(1 << bit, base + IC_MASKSET);
	__raw_writel(1 << bit, base + IC_WAKESET);
	wmb();
L
Linus Torvalds 已提交
259 260
}

261
static void au1x_ic1_unmask(struct irq_data *d)
L
Linus Torvalds 已提交
262
{
263
	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
264 265 266 267
	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);

	__raw_writel(1 << bit, base + IC_MASKSET);
	__raw_writel(1 << bit, base + IC_WAKESET);
268

269 270 271 272
/* very hacky. does the pb1000 cpld auto-disable this int?
 * nowhere in the current kernel sources is it disabled.	--mlau
 */
#if defined(CONFIG_MIPS_PB1000)
273
	if (d->irq == AU1000_GPIO15_INT)
274
		__raw_writel(0x4000, (void __iomem *)PB1000_MDR); /* enable int */
275
#endif
276
	wmb();
L
Linus Torvalds 已提交
277 278
}

279
static void au1x_ic0_mask(struct irq_data *d)
L
Linus Torvalds 已提交
280
{
281
	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
282 283 284 285 286
	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);

	__raw_writel(1 << bit, base + IC_MASKCLR);
	__raw_writel(1 << bit, base + IC_WAKECLR);
	wmb();
L
Linus Torvalds 已提交
287 288
}

289
static void au1x_ic1_mask(struct irq_data *d)
L
Linus Torvalds 已提交
290
{
291
	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
292 293 294 295 296
	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);

	__raw_writel(1 << bit, base + IC_MASKCLR);
	__raw_writel(1 << bit, base + IC_WAKECLR);
	wmb();
L
Linus Torvalds 已提交
297 298
}

299
static void au1x_ic0_ack(struct irq_data *d)
L
Linus Torvalds 已提交
300
{
301
	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
302
	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
303 304 305

	/*
	 * This may assume that we don't get interrupts from
L
Linus Torvalds 已提交
306 307
	 * both edges at once, or if we do, that we don't care.
	 */
308 309 310
	__raw_writel(1 << bit, base + IC_FALLINGCLR);
	__raw_writel(1 << bit, base + IC_RISINGCLR);
	wmb();
L
Linus Torvalds 已提交
311 312
}

313
static void au1x_ic1_ack(struct irq_data *d)
L
Linus Torvalds 已提交
314
{
315
	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
316
	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
L
Linus Torvalds 已提交
317

318 319 320 321
	/*
	 * This may assume that we don't get interrupts from
	 * both edges at once, or if we do, that we don't care.
	 */
322 323 324
	__raw_writel(1 << bit, base + IC_FALLINGCLR);
	__raw_writel(1 << bit, base + IC_RISINGCLR);
	wmb();
L
Linus Torvalds 已提交
325 326
}

327
static void au1x_ic0_maskack(struct irq_data *d)
328
{
329
	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
330
	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
331

332 333 334 335 336
	__raw_writel(1 << bit, base + IC_WAKECLR);
	__raw_writel(1 << bit, base + IC_MASKCLR);
	__raw_writel(1 << bit, base + IC_RISINGCLR);
	__raw_writel(1 << bit, base + IC_FALLINGCLR);
	wmb();
337 338
}

339
static void au1x_ic1_maskack(struct irq_data *d)
340
{
341
	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
342
	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
343

344 345 346 347 348
	__raw_writel(1 << bit, base + IC_WAKECLR);
	__raw_writel(1 << bit, base + IC_MASKCLR);
	__raw_writel(1 << bit, base + IC_RISINGCLR);
	__raw_writel(1 << bit, base + IC_FALLINGCLR);
	wmb();
349 350
}

351
static int au1x_ic1_setwake(struct irq_data *d, unsigned int on)
L
Linus Torvalds 已提交
352
{
353
	int bit = d->irq - AU1000_INTC1_INT_BASE;
354
	unsigned long wakemsk, flags;
L
Linus Torvalds 已提交
355

356 357 358 359
	/* only GPIO 0-7 can act as wakeup source.  Fortunately these
	 * are wired up identically on all supported variants.
	 */
	if ((bit < 0) || (bit > 7))
360
		return -EINVAL;
361

362
	local_irq_save(flags);
363
	wakemsk = __raw_readl((void __iomem *)SYS_WAKEMSK);
364 365
	if (on)
		wakemsk |= 1 << bit;
L
Linus Torvalds 已提交
366
	else
367
		wakemsk &= ~(1 << bit);
368 369
	__raw_writel(wakemsk, (void __iomem *)SYS_WAKEMSK);
	wmb();
370
	local_irq_restore(flags);
L
Linus Torvalds 已提交
371

372
	return 0;
L
Linus Torvalds 已提交
373 374
}

375 376 377 378 379 380
/*
 * irq_chips for both ICs; this way the mask handlers can be
 * as short as possible.
 */
static struct irq_chip au1x_ic0_chip = {
	.name		= "Alchemy-IC0",
381 382 383 384 385
	.irq_ack	= au1x_ic0_ack,
	.irq_mask	= au1x_ic0_mask,
	.irq_mask_ack	= au1x_ic0_maskack,
	.irq_unmask	= au1x_ic0_unmask,
	.irq_set_type	= au1x_ic_settype,
L
Linus Torvalds 已提交
386 387
};

388 389
static struct irq_chip au1x_ic1_chip = {
	.name		= "Alchemy-IC1",
390 391 392 393 394 395
	.irq_ack	= au1x_ic1_ack,
	.irq_mask	= au1x_ic1_mask,
	.irq_mask_ack	= au1x_ic1_maskack,
	.irq_unmask	= au1x_ic1_unmask,
	.irq_set_type	= au1x_ic_settype,
	.irq_set_wake	= au1x_ic1_setwake,
L
Linus Torvalds 已提交
396 397
};

398
static int au1x_ic_settype(struct irq_data *d, unsigned int flow_type)
L
Linus Torvalds 已提交
399
{
400
	struct irq_chip *chip;
401
	unsigned int bit, irq = d->irq;
402 403
	irq_flow_handler_t handler = NULL;
	unsigned char *name = NULL;
404
	void __iomem *base;
405 406 407 408 409
	int ret;

	if (irq >= AU1000_INTC1_INT_BASE) {
		bit = irq - AU1000_INTC1_INT_BASE;
		chip = &au1x_ic1_chip;
410
		base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
411
	} else {
412 413
		bit = irq - AU1000_INTC0_INT_BASE;
		chip = &au1x_ic0_chip;
414
		base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
415 416 417 418 419 420 421 422 423
	}

	if (bit > 31)
		return -EINVAL;

	ret = 0;

	switch (flow_type) {	/* cfgregs 2:1:0 */
	case IRQ_TYPE_EDGE_RISING:	/* 0:0:1 */
424 425 426
		__raw_writel(1 << bit, base + IC_CFG2CLR);
		__raw_writel(1 << bit, base + IC_CFG1CLR);
		__raw_writel(1 << bit, base + IC_CFG0SET);
427 428
		handler = handle_edge_irq;
		name = "riseedge";
429 430
		break;
	case IRQ_TYPE_EDGE_FALLING:	/* 0:1:0 */
431 432 433
		__raw_writel(1 << bit, base + IC_CFG2CLR);
		__raw_writel(1 << bit, base + IC_CFG1SET);
		__raw_writel(1 << bit, base + IC_CFG0CLR);
434 435
		handler = handle_edge_irq;
		name = "falledge";
436 437
		break;
	case IRQ_TYPE_EDGE_BOTH:	/* 0:1:1 */
438 439 440
		__raw_writel(1 << bit, base + IC_CFG2CLR);
		__raw_writel(1 << bit, base + IC_CFG1SET);
		__raw_writel(1 << bit, base + IC_CFG0SET);
441 442
		handler = handle_edge_irq;
		name = "bothedge";
443 444
		break;
	case IRQ_TYPE_LEVEL_HIGH:	/* 1:0:1 */
445 446 447
		__raw_writel(1 << bit, base + IC_CFG2SET);
		__raw_writel(1 << bit, base + IC_CFG1CLR);
		__raw_writel(1 << bit, base + IC_CFG0SET);
448 449
		handler = handle_level_irq;
		name = "hilevel";
450 451
		break;
	case IRQ_TYPE_LEVEL_LOW:	/* 1:1:0 */
452 453 454
		__raw_writel(1 << bit, base + IC_CFG2SET);
		__raw_writel(1 << bit, base + IC_CFG1SET);
		__raw_writel(1 << bit, base + IC_CFG0CLR);
455 456
		handler = handle_level_irq;
		name = "lowlevel";
457 458
		break;
	case IRQ_TYPE_NONE:		/* 0:0:0 */
459 460 461
		__raw_writel(1 << bit, base + IC_CFG2CLR);
		__raw_writel(1 << bit, base + IC_CFG1CLR);
		__raw_writel(1 << bit, base + IC_CFG0CLR);
462 463 464
		break;
	default:
		ret = -EINVAL;
L
Linus Torvalds 已提交
465
	}
466 467
	__irq_set_chip_handler_name_locked(d->irq, chip, handler, name);

468
	wmb();
L
Linus Torvalds 已提交
469

470 471
	return ret;
}
L
Linus Torvalds 已提交
472

473
asmlinkage void plat_irq_dispatch(void)
L
Linus Torvalds 已提交
474
{
475
	unsigned int pending = read_c0_status() & read_c0_cause();
476
	unsigned long s, off;
L
Linus Torvalds 已提交
477

478
	if (pending & CAUSEF_IP7) {
479 480
		off = MIPS_CPU_IRQ_BASE + 7;
		goto handle;
481
	} else if (pending & CAUSEF_IP2) {
482
		s = KSEG1ADDR(AU1000_IC0_PHYS_ADDR) + IC_REQ0INT;
483 484
		off = AU1000_INTC0_INT_BASE;
	} else if (pending & CAUSEF_IP3) {
485
		s = KSEG1ADDR(AU1000_IC0_PHYS_ADDR) + IC_REQ1INT;
486 487
		off = AU1000_INTC0_INT_BASE;
	} else if (pending & CAUSEF_IP4) {
488
		s = KSEG1ADDR(AU1000_IC1_PHYS_ADDR) + IC_REQ0INT;
489 490
		off = AU1000_INTC1_INT_BASE;
	} else if (pending & CAUSEF_IP5) {
491
		s = KSEG1ADDR(AU1000_IC1_PHYS_ADDR) + IC_REQ1INT;
492 493 494 495
		off = AU1000_INTC1_INT_BASE;
	} else
		goto spurious;

496
	s = __raw_readl((void __iomem *)s);
497 498 499 500 501
	if (unlikely(!s)) {
spurious:
		spurious_interrupt();
		return;
	}
502 503 504
	off += __ffs(s);
handle:
	do_IRQ(off);
L
Linus Torvalds 已提交
505 506
}

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523

static inline void ic_init(void __iomem *base)
{
	/* initialize interrupt controller to a safe state */
	__raw_writel(0xffffffff, base + IC_CFG0CLR);
	__raw_writel(0xffffffff, base + IC_CFG1CLR);
	__raw_writel(0xffffffff, base + IC_CFG2CLR);
	__raw_writel(0xffffffff, base + IC_MASKCLR);
	__raw_writel(0xffffffff, base + IC_ASSIGNCLR);
	__raw_writel(0xffffffff, base + IC_WAKECLR);
	__raw_writel(0xffffffff, base + IC_SRCSET);
	__raw_writel(0xffffffff, base + IC_FALLINGCLR);
	__raw_writel(0xffffffff, base + IC_RISINGCLR);
	__raw_writel(0x00000000, base + IC_TESTBIT);
	wmb();
}

524
static void __init au1000_init_irq(struct au1xxx_irqmap *map)
L
Linus Torvalds 已提交
525
{
526
	unsigned int bit, irq_nr;
527
	void __iomem *base;
528

529 530
	ic_init((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR));
	ic_init((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR));
531 532
	mips_cpu_irq_init();

533 534
	/* register all 64 possible IC0+IC1 irq sources as type "none".
	 * Use set_irq_type() to set edge/level behaviour at runtime.
535
	 */
536 537 538
	for (irq_nr = AU1000_INTC0_INT_BASE;
	     (irq_nr < AU1000_INTC0_INT_BASE + 32); irq_nr++)
		au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE);
539

540 541 542
	for (irq_nr = AU1000_INTC1_INT_BASE;
	     (irq_nr < AU1000_INTC1_INT_BASE + 32); irq_nr++)
		au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE);
543

544
	/*
545
	 * Initialize IC0, which is fixed per processor.
546
	 */
547 548 549 550 551
	while (map->im_irq != -1) {
		irq_nr = map->im_irq;

		if (irq_nr >= AU1000_INTC1_INT_BASE) {
			bit = irq_nr - AU1000_INTC1_INT_BASE;
552
			base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
553 554
		} else {
			bit = irq_nr - AU1000_INTC0_INT_BASE;
555
			base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
556
		}
557 558
		if (map->im_request)
			__raw_writel(1 << bit, base + IC_ASSIGNSET);
559

560
		au1x_ic_settype(irq_get_irq_data(irq_nr), map->im_type);
561 562
		++map;
	}
563 564 565

	set_c0_status(IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3);
}
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586

void __init arch_init_irq(void)
{
	switch (alchemy_get_cputype()) {
	case ALCHEMY_CPU_AU1000:
		au1000_init_irq(au1000_irqmap);
		break;
	case ALCHEMY_CPU_AU1500:
		au1000_init_irq(au1500_irqmap);
		break;
	case ALCHEMY_CPU_AU1100:
		au1000_init_irq(au1100_irqmap);
		break;
	case ALCHEMY_CPU_AU1550:
		au1000_init_irq(au1550_irqmap);
		break;
	case ALCHEMY_CPU_AU1200:
		au1000_init_irq(au1200_irqmap);
		break;
	}
}
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614

struct alchemy_ic_sysdev {
	struct sys_device sysdev;
	void __iomem *base;
	unsigned long pmdata[7];
};

static int alchemy_ic_suspend(struct sys_device *dev, pm_message_t state)
{
	struct alchemy_ic_sysdev *icdev =
			container_of(dev, struct alchemy_ic_sysdev, sysdev);

	icdev->pmdata[0] = __raw_readl(icdev->base + IC_CFG0RD);
	icdev->pmdata[1] = __raw_readl(icdev->base + IC_CFG1RD);
	icdev->pmdata[2] = __raw_readl(icdev->base + IC_CFG2RD);
	icdev->pmdata[3] = __raw_readl(icdev->base + IC_SRCRD);
	icdev->pmdata[4] = __raw_readl(icdev->base + IC_ASSIGNRD);
	icdev->pmdata[5] = __raw_readl(icdev->base + IC_WAKERD);
	icdev->pmdata[6] = __raw_readl(icdev->base + IC_MASKRD);

	return 0;
}

static int alchemy_ic_resume(struct sys_device *dev)
{
	struct alchemy_ic_sysdev *icdev =
			container_of(dev, struct alchemy_ic_sysdev, sysdev);

615 616
	ic_init(icdev->base);

617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
	__raw_writel(icdev->pmdata[0], icdev->base + IC_CFG0SET);
	__raw_writel(icdev->pmdata[1], icdev->base + IC_CFG1SET);
	__raw_writel(icdev->pmdata[2], icdev->base + IC_CFG2SET);
	__raw_writel(icdev->pmdata[3], icdev->base + IC_SRCSET);
	__raw_writel(icdev->pmdata[4], icdev->base + IC_ASSIGNSET);
	__raw_writel(icdev->pmdata[5], icdev->base + IC_WAKESET);
	wmb();

	__raw_writel(icdev->pmdata[6], icdev->base + IC_MASKSET);
	wmb();

	return 0;
}

static struct sysdev_class alchemy_ic_sysdev_class = {
	.name		= "ic",
	.suspend	= alchemy_ic_suspend,
	.resume		= alchemy_ic_resume,
};

static int __init alchemy_ic_sysdev_init(void)
{
	struct alchemy_ic_sysdev *icdev;
640
	unsigned long icbase[2] = { AU1000_IC0_PHYS_ADDR, AU1000_IC1_PHYS_ADDR };
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
	int err, i;

	err = sysdev_class_register(&alchemy_ic_sysdev_class);
	if (err)
		return err;

	for (i = 0; i < 2; i++) {
		icdev = kzalloc(sizeof(struct alchemy_ic_sysdev), GFP_KERNEL);
		if (!icdev)
			return -ENOMEM;

		icdev->base = ioremap(icbase[i], 0x1000);

		icdev->sysdev.id = i;
		icdev->sysdev.cls = &alchemy_ic_sysdev_class;
		err = sysdev_register(&icdev->sysdev);
		if (err) {
			kfree(icdev);
			return err;
		}
	}

	return 0;
}
device_initcall(alchemy_ic_sysdev_init);