irq.c 17.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * BRIEF MODULE DESCRIPTION
 *	Au1000 interrupt routines.
 *
 * Copyright 2001 MontaVista Software Inc.
 * Author: MontaVista Software, Inc.
 *		ppopov@mvista.com or source@mvista.com
 *
 *  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.
 */
29
#include <linux/bitops.h>
L
Linus Torvalds 已提交
30
#include <linux/init.h>
31
#include <linux/io.h>
L
Linus Torvalds 已提交
32
#include <linux/interrupt.h>
33
#include <linux/irq.h>
L
Linus Torvalds 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

#include <asm/mipsregs.h>
#include <asm/mach-au1x00/au1000.h>
#ifdef CONFIG_MIPS_PB1000
#include <asm/mach-pb1x00/pb1000.h>
#endif

#define EXT_INTC0_REQ0 2 /* IP 2 */
#define EXT_INTC0_REQ1 3 /* IP 3 */
#define EXT_INTC1_REQ0 4 /* IP 4 */
#define EXT_INTC1_REQ1 5 /* IP 5 */
#define MIPS_TIMER_IP  7 /* IP 7 */

void	(*board_init_irq)(void);

static DEFINE_SPINLOCK(irq_lock);

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
#ifdef CONFIG_PM

/*
 * Save/restore the interrupt controller state.
 * Called from the save/restore core registers as part of the
 * au_sleep function in power.c.....maybe I should just pm_register()
 * them instead?
 */
static unsigned int	sleep_intctl_config0[2];
static unsigned int	sleep_intctl_config1[2];
static unsigned int	sleep_intctl_config2[2];
static unsigned int	sleep_intctl_src[2];
static unsigned int	sleep_intctl_assign[2];
static unsigned int	sleep_intctl_wake[2];
static unsigned int	sleep_intctl_mask[2];

void save_au1xxx_intctl(void)
{
	sleep_intctl_config0[0] = au_readl(IC0_CFG0RD);
	sleep_intctl_config1[0] = au_readl(IC0_CFG1RD);
	sleep_intctl_config2[0] = au_readl(IC0_CFG2RD);
	sleep_intctl_src[0] = au_readl(IC0_SRCRD);
	sleep_intctl_assign[0] = au_readl(IC0_ASSIGNRD);
	sleep_intctl_wake[0] = au_readl(IC0_WAKERD);
	sleep_intctl_mask[0] = au_readl(IC0_MASKRD);

	sleep_intctl_config0[1] = au_readl(IC1_CFG0RD);
	sleep_intctl_config1[1] = au_readl(IC1_CFG1RD);
	sleep_intctl_config2[1] = au_readl(IC1_CFG2RD);
	sleep_intctl_src[1] = au_readl(IC1_SRCRD);
	sleep_intctl_assign[1] = au_readl(IC1_ASSIGNRD);
	sleep_intctl_wake[1] = au_readl(IC1_WAKERD);
	sleep_intctl_mask[1] = au_readl(IC1_MASKRD);
}

/*
 * For most restore operations, we clear the entire register and
 * then set the bits we found during the save.
 */
void restore_au1xxx_intctl(void)
{
	au_writel(0xffffffff, IC0_MASKCLR); au_sync();

	au_writel(0xffffffff, IC0_CFG0CLR); au_sync();
	au_writel(sleep_intctl_config0[0], IC0_CFG0SET); au_sync();
	au_writel(0xffffffff, IC0_CFG1CLR); au_sync();
	au_writel(sleep_intctl_config1[0], IC0_CFG1SET); au_sync();
	au_writel(0xffffffff, IC0_CFG2CLR); au_sync();
	au_writel(sleep_intctl_config2[0], IC0_CFG2SET); au_sync();
	au_writel(0xffffffff, IC0_SRCCLR); au_sync();
	au_writel(sleep_intctl_src[0], IC0_SRCSET); au_sync();
	au_writel(0xffffffff, IC0_ASSIGNCLR); au_sync();
	au_writel(sleep_intctl_assign[0], IC0_ASSIGNSET); au_sync();
	au_writel(0xffffffff, IC0_WAKECLR); au_sync();
	au_writel(sleep_intctl_wake[0], IC0_WAKESET); au_sync();
	au_writel(0xffffffff, IC0_RISINGCLR); au_sync();
	au_writel(0xffffffff, IC0_FALLINGCLR); au_sync();
	au_writel(0x00000000, IC0_TESTBIT); au_sync();

	au_writel(0xffffffff, IC1_MASKCLR); au_sync();

	au_writel(0xffffffff, IC1_CFG0CLR); au_sync();
	au_writel(sleep_intctl_config0[1], IC1_CFG0SET); au_sync();
	au_writel(0xffffffff, IC1_CFG1CLR); au_sync();
	au_writel(sleep_intctl_config1[1], IC1_CFG1SET); au_sync();
	au_writel(0xffffffff, IC1_CFG2CLR); au_sync();
	au_writel(sleep_intctl_config2[1], IC1_CFG2SET); au_sync();
	au_writel(0xffffffff, IC1_SRCCLR); au_sync();
	au_writel(sleep_intctl_src[1], IC1_SRCSET); au_sync();
	au_writel(0xffffffff, IC1_ASSIGNCLR); au_sync();
	au_writel(sleep_intctl_assign[1], IC1_ASSIGNSET); au_sync();
	au_writel(0xffffffff, IC1_WAKECLR); au_sync();
	au_writel(sleep_intctl_wake[1], IC1_WAKESET); au_sync();
	au_writel(0xffffffff, IC1_RISINGCLR); au_sync();
	au_writel(0xffffffff, IC1_FALLINGCLR); au_sync();
	au_writel(0x00000000, IC1_TESTBIT); au_sync();

	au_writel(sleep_intctl_mask[1], IC1_MASKSET); au_sync();

	au_writel(sleep_intctl_mask[0], IC0_MASKSET); au_sync();
}
#endif /* CONFIG_PM */

L
Linus Torvalds 已提交
134 135 136 137

inline void local_enable_irq(unsigned int irq_nr)
{
	if (irq_nr > AU1000_LAST_INTC0_INT) {
138 139 140 141 142
		au_writel(1 << (irq_nr - 32), IC1_MASKSET);
		au_writel(1 << (irq_nr - 32), IC1_WAKESET);
	} else {
		au_writel(1 << irq_nr, IC0_MASKSET);
		au_writel(1 << irq_nr, IC0_WAKESET);
L
Linus Torvalds 已提交
143 144 145 146 147 148 149 150
	}
	au_sync();
}


inline void local_disable_irq(unsigned int irq_nr)
{
	if (irq_nr > AU1000_LAST_INTC0_INT) {
151 152 153 154 155
		au_writel(1 << (irq_nr - 32), IC1_MASKCLR);
		au_writel(1 << (irq_nr - 32), IC1_WAKECLR);
	} else {
		au_writel(1 << irq_nr, IC0_MASKCLR);
		au_writel(1 << irq_nr, IC0_WAKECLR);
L
Linus Torvalds 已提交
156 157 158 159 160 161 162 163
	}
	au_sync();
}


static inline void mask_and_ack_rise_edge_irq(unsigned int irq_nr)
{
	if (irq_nr > AU1000_LAST_INTC0_INT) {
164 165 166 167 168
		au_writel(1 << (irq_nr - 32), IC1_RISINGCLR);
		au_writel(1 << (irq_nr - 32), IC1_MASKCLR);
	} else {
		au_writel(1 << irq_nr, IC0_RISINGCLR);
		au_writel(1 << irq_nr, IC0_MASKCLR);
L
Linus Torvalds 已提交
169 170 171 172 173 174 175 176
	}
	au_sync();
}


static inline void mask_and_ack_fall_edge_irq(unsigned int irq_nr)
{
	if (irq_nr > AU1000_LAST_INTC0_INT) {
177 178 179 180 181
		au_writel(1 << (irq_nr - 32), IC1_FALLINGCLR);
		au_writel(1 << (irq_nr - 32), IC1_MASKCLR);
	} else {
		au_writel(1 << irq_nr, IC0_FALLINGCLR);
		au_writel(1 << irq_nr, IC0_MASKCLR);
L
Linus Torvalds 已提交
182 183 184 185 186 187 188 189 190 191 192
	}
	au_sync();
}


static inline void mask_and_ack_either_edge_irq(unsigned int irq_nr)
{
	/* This may assume that we don't get interrupts from
	 * both edges at once, or if we do, that we don't care.
	 */
	if (irq_nr > AU1000_LAST_INTC0_INT) {
193 194 195 196 197 198 199
		au_writel(1 << (irq_nr - 32), IC1_FALLINGCLR);
		au_writel(1 << (irq_nr - 32), IC1_RISINGCLR);
		au_writel(1 << (irq_nr - 32), IC1_MASKCLR);
	} else {
		au_writel(1 << irq_nr, IC0_FALLINGCLR);
		au_writel(1 << irq_nr, IC0_RISINGCLR);
		au_writel(1 << irq_nr, IC0_MASKCLR);
L
Linus Torvalds 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
	}
	au_sync();
}


static inline void mask_and_ack_level_irq(unsigned int irq_nr)
{

	local_disable_irq(irq_nr);
	au_sync();
#if defined(CONFIG_MIPS_PB1000)
	if (irq_nr == AU1000_GPIO_15) {
		au_writel(0x8000, PB1000_MDR); /* ack int */
		au_sync();
	}
#endif
	return;
}


static void end_irq(unsigned int irq_nr)
{
222
	if (!(irq_desc[irq_nr].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
L
Linus Torvalds 已提交
223
		local_enable_irq(irq_nr);
224

L
Linus Torvalds 已提交
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
#if defined(CONFIG_MIPS_PB1000)
	if (irq_nr == AU1000_GPIO_15) {
		au_writel(0x4000, PB1000_MDR); /* enable int */
		au_sync();
	}
#endif
}

unsigned long save_local_and_disable(int controller)
{
	int i;
	unsigned long flags, mask;

	spin_lock_irqsave(&irq_lock, flags);
	if (controller) {
		mask = au_readl(IC1_MASKSET);
241
		for (i = 32; i < 64; i++)
L
Linus Torvalds 已提交
242
			local_disable_irq(i);
243
	} else {
L
Linus Torvalds 已提交
244
		mask = au_readl(IC0_MASKSET);
245
		for (i = 0; i < 32; i++)
L
Linus Torvalds 已提交
246 247 248 249 250 251 252 253 254 255 256 257 258
			local_disable_irq(i);
	}
	spin_unlock_irqrestore(&irq_lock, flags);

	return mask;
}

void restore_local_and_enable(int controller, unsigned long mask)
{
	int i;
	unsigned long flags, new_mask;

	spin_lock_irqsave(&irq_lock, flags);
259 260
	for (i = 0; i < 32; i++) {
		if (mask & (1 << i)) {
L
Linus Torvalds 已提交
261
			if (controller)
262
				local_enable_irq(i + 32);
L
Linus Torvalds 已提交
263 264 265 266 267 268 269 270 271 272 273 274 275
			else
				local_enable_irq(i);
		}
	}
	if (controller)
		new_mask = au_readl(IC1_MASKSET);
	else
		new_mask = au_readl(IC0_MASKSET);

	spin_unlock_irqrestore(&irq_lock, flags);
}


276
static struct irq_chip rise_edge_irq_type = {
277 278 279 280 281 282
	.name		= "Au1000 Rise Edge",
	.ack		= mask_and_ack_rise_edge_irq,
	.mask		= local_disable_irq,
	.mask_ack	= mask_and_ack_rise_edge_irq,
	.unmask		= local_enable_irq,
	.end		= end_irq,
L
Linus Torvalds 已提交
283 284
};

285
static struct irq_chip fall_edge_irq_type = {
286 287 288 289 290 291
	.name		= "Au1000 Fall Edge",
	.ack		= mask_and_ack_fall_edge_irq,
	.mask		= local_disable_irq,
	.mask_ack	= mask_and_ack_fall_edge_irq,
	.unmask		= local_enable_irq,
	.end		= end_irq,
L
Linus Torvalds 已提交
292 293
};

294
static struct irq_chip either_edge_irq_type = {
295 296 297 298 299 300
	.name		= "Au1000 Rise or Fall Edge",
	.ack		= mask_and_ack_either_edge_irq,
	.mask		= local_disable_irq,
	.mask_ack	= mask_and_ack_either_edge_irq,
	.unmask		= local_enable_irq,
	.end		= end_irq,
L
Linus Torvalds 已提交
301 302
};

303
static struct irq_chip level_irq_type = {
304 305 306 307 308 309
	.name		= "Au1000 Level",
	.ack		= mask_and_ack_level_irq,
	.mask		= local_disable_irq,
	.mask_ack	= mask_and_ack_level_irq,
	.unmask		= local_enable_irq,
	.end		= end_irq,
L
Linus Torvalds 已提交
310 311 312
};

#ifdef CONFIG_PM
313
void startup_match20_interrupt(irq_handler_t handler)
L
Linus Torvalds 已提交
314
{
P
Pete Popov 已提交
315
	struct irq_desc *desc = &irq_desc[AU1000_TOY_MATCH2_INT];
316

P
Pete Popov 已提交
317 318
	static struct irqaction action;
	memset(&action, 0, sizeof(struct irqaction));
319

320 321
	/*
	 * This is a big problem.... since we didn't use request_irq
P
Pete Popov 已提交
322 323 324 325 326 327 328
	 * when kernel/irq.c calls probe_irq_xxx this interrupt will
	 * be probed for usage. This will end up disabling the device :(
	 * Give it a bogus "action" pointer -- this will keep it from
	 * getting auto-probed!
	 *
	 * By setting the status to match that of request_irq() we
	 * can avoid it.  --cgray
329 330
	*/
	action.dev_id = handler;
331
	action.flags = IRQF_DISABLED;
P
Pete Popov 已提交
332
	cpus_clear(action.mask);
333 334 335 336
	action.name = "Au1xxx TOY";
	action.handler = handler;
	action.next = NULL;

P
Pete Popov 已提交
337 338
	desc->action = &action;
	desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT | IRQ_WAITING | IRQ_INPROGRESS);
339

L
Linus Torvalds 已提交
340 341 342 343 344 345 346 347 348 349
	local_enable_irq(AU1000_TOY_MATCH2_INT);
}
#endif

static void setup_local_irq(unsigned int irq_nr, int type, int int_req)
{
	if (irq_nr > AU1000_MAX_INTR) return;
	/* Config2[n], Config1[n], Config0[n] */
	if (irq_nr > AU1000_LAST_INTC0_INT) {
		switch (type) {
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
		case INTC_INT_RISE_EDGE: /* 0:0:1 */
			au_writel(1 << (irq_nr - 32), IC1_CFG2CLR);
			au_writel(1 << (irq_nr - 32), IC1_CFG1CLR);
			au_writel(1 << (irq_nr - 32), IC1_CFG0SET);
			set_irq_chip(irq_nr, &rise_edge_irq_type);
			break;
		case INTC_INT_FALL_EDGE: /* 0:1:0 */
			au_writel(1 << (irq_nr - 32), IC1_CFG2CLR);
			au_writel(1 << (irq_nr - 32), IC1_CFG1SET);
			au_writel(1 << (irq_nr - 32), IC1_CFG0CLR);
			set_irq_chip(irq_nr, &fall_edge_irq_type);
			break;
		case INTC_INT_RISE_AND_FALL_EDGE: /* 0:1:1 */
			au_writel(1 << (irq_nr - 32), IC1_CFG2CLR);
			au_writel(1 << (irq_nr - 32), IC1_CFG1SET);
			au_writel(1 << (irq_nr - 32), IC1_CFG0SET);
			set_irq_chip(irq_nr, &either_edge_irq_type);
			break;
		case INTC_INT_HIGH_LEVEL: /* 1:0:1 */
			au_writel(1 << (irq_nr - 32), IC1_CFG2SET);
			au_writel(1 << (irq_nr - 32), IC1_CFG1CLR);
			au_writel(1 << (irq_nr - 32), IC1_CFG0SET);
			set_irq_chip(irq_nr, &level_irq_type);
			break;
		case INTC_INT_LOW_LEVEL: /* 1:1:0 */
			au_writel(1 << (irq_nr - 32), IC1_CFG2SET);
			au_writel(1 << (irq_nr - 32), IC1_CFG1SET);
			au_writel(1 << (irq_nr - 32), IC1_CFG0CLR);
			set_irq_chip(irq_nr, &level_irq_type);
			break;
		case INTC_INT_DISABLED: /* 0:0:0 */
			au_writel(1 << (irq_nr - 32), IC1_CFG0CLR);
			au_writel(1 << (irq_nr - 32), IC1_CFG1CLR);
			au_writel(1 << (irq_nr - 32), IC1_CFG2CLR);
			break;
		default: /* disable the interrupt */
			printk(KERN_WARNING "unexpected int type %d (irq %d)\n",
			       type, irq_nr);
			au_writel(1 << (irq_nr - 32), IC1_CFG0CLR);
			au_writel(1 << (irq_nr - 32), IC1_CFG1CLR);
			au_writel(1 << (irq_nr - 32), IC1_CFG2CLR);
			return;
L
Linus Torvalds 已提交
392 393
		}
		if (int_req) /* assign to interrupt request 1 */
394
			au_writel(1 << (irq_nr - 32), IC1_ASSIGNCLR);
L
Linus Torvalds 已提交
395
		else	     /* assign to interrupt request 0 */
396 397 398 399 400
			au_writel(1 << (irq_nr - 32), IC1_ASSIGNSET);
		au_writel(1 << (irq_nr - 32), IC1_SRCSET);
		au_writel(1 << (irq_nr - 32), IC1_MASKCLR);
		au_writel(1 << (irq_nr - 32), IC1_WAKECLR);
	} else {
L
Linus Torvalds 已提交
401
		switch (type) {
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
		case INTC_INT_RISE_EDGE: /* 0:0:1 */
			au_writel(1 << irq_nr, IC0_CFG2CLR);
			au_writel(1 << irq_nr, IC0_CFG1CLR);
			au_writel(1 << irq_nr, IC0_CFG0SET);
			set_irq_chip(irq_nr, &rise_edge_irq_type);
			break;
		case INTC_INT_FALL_EDGE: /* 0:1:0 */
			au_writel(1 << irq_nr, IC0_CFG2CLR);
			au_writel(1 << irq_nr, IC0_CFG1SET);
			au_writel(1 << irq_nr, IC0_CFG0CLR);
			set_irq_chip(irq_nr, &fall_edge_irq_type);
			break;
		case INTC_INT_RISE_AND_FALL_EDGE: /* 0:1:1 */
			au_writel(1 << irq_nr, IC0_CFG2CLR);
			au_writel(1 << irq_nr, IC0_CFG1SET);
			au_writel(1 << irq_nr, IC0_CFG0SET);
			set_irq_chip(irq_nr, &either_edge_irq_type);
			break;
		case INTC_INT_HIGH_LEVEL: /* 1:0:1 */
			au_writel(1 << irq_nr, IC0_CFG2SET);
			au_writel(1 << irq_nr, IC0_CFG1CLR);
			au_writel(1 << irq_nr, IC0_CFG0SET);
			set_irq_chip(irq_nr, &level_irq_type);
			break;
		case INTC_INT_LOW_LEVEL: /* 1:1:0 */
			au_writel(1 << irq_nr, IC0_CFG2SET);
			au_writel(1 << irq_nr, IC0_CFG1SET);
			au_writel(1 << irq_nr, IC0_CFG0CLR);
			set_irq_chip(irq_nr, &level_irq_type);
			break;
		case INTC_INT_DISABLED: /* 0:0:0 */
			au_writel(1 << irq_nr, IC0_CFG0CLR);
			au_writel(1 << irq_nr, IC0_CFG1CLR);
			au_writel(1 << irq_nr, IC0_CFG2CLR);
			break;
		default: /* disable the interrupt */
			printk(KERN_WARNING "unexpected int type %d (irq %d)\n",
			       type, irq_nr);
			au_writel(1 << irq_nr, IC0_CFG0CLR);
			au_writel(1 << irq_nr, IC0_CFG1CLR);
			au_writel(1 << irq_nr, IC0_CFG2CLR);
			return;
L
Linus Torvalds 已提交
444 445
		}
		if (int_req) /* assign to interrupt request 1 */
446
			au_writel(1 << irq_nr, IC0_ASSIGNCLR);
L
Linus Torvalds 已提交
447
		else	     /* assign to interrupt request 0 */
448 449 450 451
			au_writel(1 << irq_nr, IC0_ASSIGNSET);
		au_writel(1 << irq_nr, IC0_SRCSET);
		au_writel(1 << irq_nr, IC0_MASKCLR);
		au_writel(1 << irq_nr, IC0_WAKECLR);
L
Linus Torvalds 已提交
452 453 454 455 456 457 458 459 460 461
	}
	au_sync();
}

/*
 * Interrupts are nested. Even if an interrupt handler is registered
 * as "fast", we might get another interrupt before we return from
 * intcX_reqX_irqdispatch().
 */

462
static void intc0_req0_irqdispatch(void)
L
Linus Torvalds 已提交
463 464
{
	int irq = 0;
465
	static unsigned long intc0_req0;
L
Linus Torvalds 已提交
466 467 468

	intc0_req0 |= au_readl(IC0_REQ0INT);

469 470
	if (!intc0_req0)
		return;
471

P
Pete Popov 已提交
472
#ifdef AU1000_USB_DEV_REQ_INT
L
Linus Torvalds 已提交
473 474 475 476 477
	/*
	 * Because of the tight timing of SETUP token to reply
	 * transactions, the USB devices-side packet complete
	 * interrupt needs the highest priority.
	 */
478 479
	if ((intc0_req0 & (1 << AU1000_USB_DEV_REQ_INT))) {
		intc0_req0 &= ~(1 << AU1000_USB_DEV_REQ_INT);
480
		do_IRQ(AU1000_USB_DEV_REQ_INT);
L
Linus Torvalds 已提交
481 482
		return;
	}
P
Pete Popov 已提交
483
#endif
484
	irq = ffs(intc0_req0);
485
	intc0_req0 &= ~(1 << irq);
486
	do_IRQ(irq);
L
Linus Torvalds 已提交
487 488 489
}


490
static void intc0_req1_irqdispatch(void)
L
Linus Torvalds 已提交
491 492
{
	int irq = 0;
493
	static unsigned long intc0_req1;
L
Linus Torvalds 已提交
494 495 496

	intc0_req1 |= au_readl(IC0_REQ1INT);

497 498
	if (!intc0_req1)
		return;
L
Linus Torvalds 已提交
499

500
	irq = ffs(intc0_req1);
501
	intc0_req1 &= ~(1 << irq);
502
	do_IRQ(irq);
L
Linus Torvalds 已提交
503 504 505 506 507 508 509
}


/*
 * Interrupt Controller 1:
 * interrupts 32 - 63
 */
510
static void intc1_req0_irqdispatch(void)
L
Linus Torvalds 已提交
511 512
{
	int irq = 0;
513
	static unsigned long intc1_req0;
L
Linus Torvalds 已提交
514 515 516

	intc1_req0 |= au_readl(IC1_REQ0INT);

517 518
	if (!intc1_req0)
		return;
L
Linus Torvalds 已提交
519

520
	irq = ffs(intc1_req0);
521
	intc1_req0 &= ~(1 << irq);
L
Linus Torvalds 已提交
522
	irq += 32;
523
	do_IRQ(irq);
L
Linus Torvalds 已提交
524 525 526
}


527
static void intc1_req1_irqdispatch(void)
L
Linus Torvalds 已提交
528 529
{
	int irq = 0;
530
	static unsigned long intc1_req1;
L
Linus Torvalds 已提交
531 532 533

	intc1_req1 |= au_readl(IC1_REQ1INT);

534 535
	if (!intc1_req1)
		return;
L
Linus Torvalds 已提交
536

537
	irq = ffs(intc1_req1);
538
	intc1_req1 &= ~(1 << irq);
L
Linus Torvalds 已提交
539
	irq += 32;
540
	do_IRQ(irq);
L
Linus Torvalds 已提交
541 542
}

543
asmlinkage void plat_irq_dispatch(void)
544 545 546 547
{
	unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;

	if (pending & CAUSEF_IP7)
548
		do_IRQ(63);
549
	else if (pending & CAUSEF_IP2)
550
		intc0_req0_irqdispatch();
551
	else if (pending & CAUSEF_IP3)
552
		intc0_req1_irqdispatch();
553
	else if (pending & CAUSEF_IP4)
554
		intc1_req0_irqdispatch();
555
	else if (pending  & CAUSEF_IP5)
556
		intc1_req1_irqdispatch();
557
	else
558
		spurious_interrupt();
559
}
560 561 562 563 564

void __init arch_init_irq(void)
{
	int i;
	unsigned long cp0_status;
565 566 567
	struct au1xxx_irqmap *imp;
	extern struct au1xxx_irqmap au1xxx_irq_map[];
	extern struct au1xxx_irqmap au1xxx_ic0_map[];
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 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 615 616 617 618 619
	extern int au1xxx_nr_irqs;
	extern int au1xxx_ic0_nr_irqs;

	cp0_status = read_c0_status();

	/* Initialize interrupt controllers to a safe state.
	*/
	au_writel(0xffffffff, IC0_CFG0CLR);
	au_writel(0xffffffff, IC0_CFG1CLR);
	au_writel(0xffffffff, IC0_CFG2CLR);
	au_writel(0xffffffff, IC0_MASKCLR);
	au_writel(0xffffffff, IC0_ASSIGNSET);
	au_writel(0xffffffff, IC0_WAKECLR);
	au_writel(0xffffffff, IC0_SRCSET);
	au_writel(0xffffffff, IC0_FALLINGCLR);
	au_writel(0xffffffff, IC0_RISINGCLR);
	au_writel(0x00000000, IC0_TESTBIT);

	au_writel(0xffffffff, IC1_CFG0CLR);
	au_writel(0xffffffff, IC1_CFG1CLR);
	au_writel(0xffffffff, IC1_CFG2CLR);
	au_writel(0xffffffff, IC1_MASKCLR);
	au_writel(0xffffffff, IC1_ASSIGNSET);
	au_writel(0xffffffff, IC1_WAKECLR);
	au_writel(0xffffffff, IC1_SRCSET);
	au_writel(0xffffffff, IC1_FALLINGCLR);
	au_writel(0xffffffff, IC1_RISINGCLR);
	au_writel(0x00000000, IC1_TESTBIT);

	/* Initialize IC0, which is fixed per processor.
	*/
	imp = au1xxx_ic0_map;
	for (i = 0; i < au1xxx_ic0_nr_irqs; i++) {
		setup_local_irq(imp->im_irq, imp->im_type, imp->im_request);
		imp++;
	}

	/* Now set up the irq mapping for the board.
	*/
	imp = au1xxx_irq_map;
	for (i = 0; i < au1xxx_nr_irqs; i++) {
		setup_local_irq(imp->im_irq, imp->im_type, imp->im_request);
		imp++;
	}

	set_c0_status(ALLINTS);

	/* Board specific IRQ initialization.
	*/
	if (board_init_irq)
		(*board_init_irq)();
}