ints-priority.c 33.7 KB
Newer Older
B
Bryan Wu 已提交
1
/*
2
 * Set up the interrupt priorities
B
Bryan Wu 已提交
3
 *
4 5 6 7 8 9
 * Copyright  2004-2009 Analog Devices Inc.
 *                 2003 Bas Vermeulen <bas@buyways.nl>
 *                 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
 *            2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
 *                 1999 D. Jeff Dionne <jeff@uclinux.org>
 *                 1996 Roman Zippel
B
Bryan Wu 已提交
10
 *
11
 * Licensed under the GPL-2
B
Bryan Wu 已提交
12 13 14 15 16 17
 */

#include <linux/module.h>
#include <linux/kernel_stat.h>
#include <linux/seq_file.h>
#include <linux/irq.h>
18 19 20
#ifdef CONFIG_IPIPE
#include <linux/ipipe.h>
#endif
B
Bryan Wu 已提交
21 22 23 24 25 26 27
#ifdef CONFIG_KGDB
#include <linux/kgdb.h>
#endif
#include <asm/traps.h>
#include <asm/blackfin.h>
#include <asm/gpio.h>
#include <asm/irq_handler.h>
28
#include <asm/dpmc.h>
29 30
#include <asm/bfin5xx_spi.h>
#include <asm/bfin_sport.h>
31
#include <asm/bfin_can.h>
B
Bryan Wu 已提交
32

33 34
#define SIC_SYSIRQ(irq)	(irq - (IRQ_CORETMR + 1))

B
Bryan Wu 已提交
35 36
#ifdef BF537_FAMILY
# define BF537_GENERIC_ERROR_INT_DEMUX
37 38 39 40 41 42
# define SPI_ERR_MASK   (BIT_STAT_TXCOL | BIT_STAT_RBSY | BIT_STAT_MODF | BIT_STAT_TXE)	/* SPI_STAT */
# define SPORT_ERR_MASK (ROVF | RUVF | TOVF | TUVF)	/* SPORT_STAT */
# define PPI_ERR_MASK   (0xFFFF & ~FLD)	/* PPI_STATUS */
# define EMAC_ERR_MASK  (PHYINT | MMCINT | RXFSINT | TXFSINT | WAKEDET | RXDMAERR | TXDMAERR | STMDONE)	/* EMAC_SYSTAT */
# define UART_ERR_MASK  (0x6)	/* UART_IIR */
# define CAN_ERR_MASK   (EWTIF | EWRIF | EPIF | BOIF | WUIF | UIAIF | AAIF | RMLIF | UCEIF | EXTIF | ADIF)	/* CAN_GIF */
B
Bryan Wu 已提交
43 44 45 46 47 48 49 50 51 52 53
#else
# undef BF537_GENERIC_ERROR_INT_DEMUX
#endif

/*
 * NOTES:
 * - we have separated the physical Hardware interrupt from the
 * levels that the LINUX kernel sees (see the description in irq.h)
 * -
 */

54
#ifndef CONFIG_SMP
55 56 57 58 59 60
/* Initialize this to an actual value to force it into the .data
 * section so that we know it is properly initialized at entry into
 * the kernel but before bss is initialized to zero (which is where
 * it would live otherwise).  The 0x1f magic represents the IRQs we
 * cannot actually mask out in hardware.
 */
61 62
unsigned long bfin_irq_flags = 0x1f;
EXPORT_SYMBOL(bfin_irq_flags);
63
#endif
B
Bryan Wu 已提交
64 65 66 67

/* The number of spurious interrupts */
atomic_t num_spurious;

68 69
#ifdef CONFIG_PM
unsigned long bfin_sic_iwr[3];	/* Up to 3 SIC_IWRx registers */
70
unsigned vr_wakeup;
71 72
#endif

B
Bryan Wu 已提交
73
struct ivgx {
74
	/* irq number for request_irq, available in mach-bf5xx/irq.h */
75
	unsigned int irqno;
B
Bryan Wu 已提交
76
	/* corresponding bit in the SIC_ISR register */
77
	unsigned int isrflag;
B
Bryan Wu 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
} ivg_table[NR_PERI_INTS];

struct ivg_slice {
	/* position of first irq in ivg_table for given ivg */
	struct ivgx *ifirst;
	struct ivgx *istop;
} ivg7_13[IVG13 - IVG7 + 1];


/*
 * Search SIC_IAR and fill tables with the irqvalues
 * and their positions in the SIC_ISR register.
 */
static void __init search_IAR(void)
{
	unsigned ivg, irq_pos = 0;
	for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
95
		int irqN;
B
Bryan Wu 已提交
96

97
		ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
B
Bryan Wu 已提交
98

99 100 101 102 103 104
		for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
			int irqn;
			u32 iar = bfin_read32((unsigned long *)SIC_IAR0 +
#if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
	defined(CONFIG_BF538) || defined(CONFIG_BF539)
				((irqN % 32) >> 3) + ((irqN / 32) * ((SIC_IAR4 - SIC_IAR0) / 4))
105
#else
106
				(irqN >> 3)
107
#endif
108 109 110 111 112 113 114 115 116 117
				);

			for (irqn = irqN; irqn < irqN + 4; ++irqn) {
				int iar_shift = (irqn & 7) * 4;
				if (ivg == (0xf & (iar >> iar_shift))) {
					ivg_table[irq_pos].irqno = IVG7 + irqn;
					ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
					ivg7_13[ivg].istop++;
					irq_pos++;
				}
B
Bryan Wu 已提交
118 119 120 121 122 123
			}
		}
	}
}

/*
124
 * This is for core internal IRQs
B
Bryan Wu 已提交
125 126
 */

127
static void bfin_ack_noop(struct irq_data *d)
B
Bryan Wu 已提交
128 129 130 131
{
	/* Dummy function.  */
}

132
static void bfin_core_mask_irq(struct irq_data *d)
B
Bryan Wu 已提交
133
{
134
	bfin_irq_flags &= ~(1 << d->irq);
135 136
	if (!hard_irqs_disabled())
		hard_local_irq_enable();
B
Bryan Wu 已提交
137 138
}

139
static void bfin_core_unmask_irq(struct irq_data *d)
B
Bryan Wu 已提交
140
{
141
	bfin_irq_flags |= 1 << d->irq;
B
Bryan Wu 已提交
142 143
	/*
	 * If interrupts are enabled, IMASK must contain the same value
144
	 * as bfin_irq_flags.  Make sure that invariant holds.  If interrupts
B
Bryan Wu 已提交
145 146 147
	 * are currently disabled we need not do anything; one of the
	 * callers will take care of setting IMASK to the proper value
	 * when reenabling interrupts.
148
	 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
B
Bryan Wu 已提交
149 150
	 * what we need.
	 */
151 152
	if (!hard_irqs_disabled())
		hard_local_irq_enable();
B
Bryan Wu 已提交
153 154 155 156 157
	return;
}

static void bfin_internal_mask_irq(unsigned int irq)
{
158 159
	unsigned long flags;

160
#ifdef CONFIG_BF53x
161
	flags = hard_local_irq_save();
B
Bryan Wu 已提交
162
	bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
163
			     ~(1 << SIC_SYSIRQ(irq)));
164 165
#else
	unsigned mask_bank, mask_bit;
166
	flags = hard_local_irq_save();
167 168
	mask_bank = SIC_SYSIRQ(irq) / 32;
	mask_bit = SIC_SYSIRQ(irq) % 32;
169 170
	bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
			     ~(1 << mask_bit));
171 172 173 174
#ifdef CONFIG_SMP
	bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
			     ~(1 << mask_bit));
#endif
175
#endif
176
	hard_local_irq_restore(flags);
B
Bryan Wu 已提交
177 178
}

179 180 181 182 183
static void bfin_internal_mask_irq_chip(struct irq_data *d)
{
	bfin_internal_mask_irq(d->irq);
}

184 185 186 187
#ifdef CONFIG_SMP
static void bfin_internal_unmask_irq_affinity(unsigned int irq,
		const struct cpumask *affinity)
#else
B
Bryan Wu 已提交
188
static void bfin_internal_unmask_irq(unsigned int irq)
189
#endif
B
Bryan Wu 已提交
190
{
191 192
	unsigned long flags;

193
#ifdef CONFIG_BF53x
194
	flags = hard_local_irq_save();
B
Bryan Wu 已提交
195
	bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
196
			     (1 << SIC_SYSIRQ(irq)));
197 198
#else
	unsigned mask_bank, mask_bit;
199
	flags = hard_local_irq_save();
200 201
	mask_bank = SIC_SYSIRQ(irq) / 32;
	mask_bit = SIC_SYSIRQ(irq) % 32;
202
#ifdef CONFIG_SMP
203 204 205 206 207 208 209 210 211 212
	if (cpumask_test_cpu(0, affinity))
#endif
		bfin_write_SIC_IMASK(mask_bank,
			bfin_read_SIC_IMASK(mask_bank) |
			(1 << mask_bit));
#ifdef CONFIG_SMP
	if (cpumask_test_cpu(1, affinity))
		bfin_write_SICB_IMASK(mask_bank,
			bfin_read_SICB_IMASK(mask_bank) |
			(1 << mask_bit));
213
#endif
214
#endif
215
	hard_local_irq_restore(flags);
B
Bryan Wu 已提交
216 217
}

218
#ifdef CONFIG_SMP
219
static void bfin_internal_unmask_irq_chip(struct irq_data *d)
220
{
221
	bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
222 223
}

224 225
static int bfin_internal_set_affinity(struct irq_data *d,
				      const struct cpumask *mask, bool force)
226
{
227 228
	bfin_internal_mask_irq(d->irq);
	bfin_internal_unmask_irq_affinity(d->irq, mask);
229 230 231

	return 0;
}
232 233 234 235 236
#else
static void bfin_internal_unmask_irq_chip(struct irq_data *d)
{
	bfin_internal_unmask_irq(d->irq);
}
237 238
#endif

239 240 241
#ifdef CONFIG_PM
int bfin_internal_set_wake(unsigned int irq, unsigned int state)
{
242
	u32 bank, bit, wakeup = 0;
243
	unsigned long flags;
244 245
	bank = SIC_SYSIRQ(irq) / 32;
	bit = SIC_SYSIRQ(irq) % 32;
246

247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
	switch (irq) {
#ifdef IRQ_RTC
	case IRQ_RTC:
	wakeup |= WAKE;
	break;
#endif
#ifdef IRQ_CAN0_RX
	case IRQ_CAN0_RX:
	wakeup |= CANWE;
	break;
#endif
#ifdef IRQ_CAN1_RX
	case IRQ_CAN1_RX:
	wakeup |= CANWE;
	break;
#endif
#ifdef IRQ_USB_INT0
	case IRQ_USB_INT0:
	wakeup |= USBWE;
	break;
#endif
268
#ifdef CONFIG_BF54x
269 270 271 272 273 274 275 276
	case IRQ_CNT:
	wakeup |= ROTWE;
	break;
#endif
	default:
	break;
	}

277
	flags = hard_local_irq_save();
278

279
	if (state) {
280
		bfin_sic_iwr[bank] |= (1 << bit);
281 282 283
		vr_wakeup  |= wakeup;

	} else {
284
		bfin_sic_iwr[bank] &= ~(1 << bit);
285 286
		vr_wakeup  &= ~wakeup;
	}
287

288
	hard_local_irq_restore(flags);
289 290 291

	return 0;
}
292 293 294 295 296

static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
{
	return bfin_internal_set_wake(d->irq, state);
}
297 298
#endif

B
Bryan Wu 已提交
299
static struct irq_chip bfin_core_irqchip = {
300
	.name = "CORE",
301 302 303
	.irq_ack = bfin_ack_noop,
	.irq_mask = bfin_core_mask_irq,
	.irq_unmask = bfin_core_unmask_irq,
B
Bryan Wu 已提交
304 305 306
};

static struct irq_chip bfin_internal_irqchip = {
307
	.name = "INTN",
308
	.irq_ack = bfin_ack_noop,
309 310 311 312 313
	.irq_mask = bfin_internal_mask_irq_chip,
	.irq_unmask = bfin_internal_unmask_irq_chip,
	.irq_mask_ack = bfin_internal_mask_irq_chip,
	.irq_disable = bfin_internal_mask_irq_chip,
	.irq_enable = bfin_internal_unmask_irq_chip,
314
#ifdef CONFIG_SMP
315
	.irq_set_affinity = bfin_internal_set_affinity,
316
#endif
317
#ifdef CONFIG_PM
318
	.irq_set_wake = bfin_internal_set_wake_chip,
319
#endif
B
Bryan Wu 已提交
320 321
};

322 323 324 325 326 327 328 329
static void bfin_handle_irq(unsigned irq)
{
#ifdef CONFIG_IPIPE
	struct pt_regs regs;    /* Contents not used. */
	ipipe_trace_irq_entry(irq);
	__ipipe_handle_irq(irq, &regs);
	ipipe_trace_irq_exit(irq);
#else /* !CONFIG_IPIPE */
330
	generic_handle_irq(irq);
331 332 333
#endif  /* !CONFIG_IPIPE */
}

B
Bryan Wu 已提交
334 335 336
#ifdef BF537_GENERIC_ERROR_INT_DEMUX
static int error_int_mask;

337
static void bfin_generic_error_mask_irq(struct irq_data *d)
B
Bryan Wu 已提交
338
{
339
	error_int_mask &= ~(1L << (d->irq - IRQ_PPI_ERROR));
340 341
	if (!error_int_mask)
		bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
B
Bryan Wu 已提交
342 343
}

344
static void bfin_generic_error_unmask_irq(struct irq_data *d)
B
Bryan Wu 已提交
345
{
346
	bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
347
	error_int_mask |= 1L << (d->irq - IRQ_PPI_ERROR);
B
Bryan Wu 已提交
348 349 350
}

static struct irq_chip bfin_generic_error_irqchip = {
351
	.name = "ERROR",
352
	.irq_ack = bfin_ack_noop,
353 354 355
	.irq_mask_ack = bfin_generic_error_mask_irq,
	.irq_mask = bfin_generic_error_mask_irq,
	.irq_unmask = bfin_generic_error_unmask_irq,
B
Bryan Wu 已提交
356 357 358
};

static void bfin_demux_error_irq(unsigned int int_err_irq,
359
				 struct irq_desc *inta_desc)
B
Bryan Wu 已提交
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
{
	int irq = 0;

#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
	if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
		irq = IRQ_MAC_ERROR;
	else
#endif
	if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
		irq = IRQ_SPORT0_ERROR;
	else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
		irq = IRQ_SPORT1_ERROR;
	else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
		irq = IRQ_PPI_ERROR;
	else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
		irq = IRQ_CAN_ERROR;
	else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
		irq = IRQ_SPI_ERROR;
378
	else if ((bfin_read_UART0_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
B
Bryan Wu 已提交
379
		irq = IRQ_UART0_ERROR;
380
	else if ((bfin_read_UART1_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
B
Bryan Wu 已提交
381 382 383
		irq = IRQ_UART1_ERROR;

	if (irq) {
384 385 386
		if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
			bfin_handle_irq(irq);
		else {
B
Bryan Wu 已提交
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417

			switch (irq) {
			case IRQ_PPI_ERROR:
				bfin_write_PPI_STATUS(PPI_ERR_MASK);
				break;
#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
			case IRQ_MAC_ERROR:
				bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
				break;
#endif
			case IRQ_SPORT0_ERROR:
				bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
				break;

			case IRQ_SPORT1_ERROR:
				bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
				break;

			case IRQ_CAN_ERROR:
				bfin_write_CAN_GIS(CAN_ERR_MASK);
				break;

			case IRQ_SPI_ERROR:
				bfin_write_SPI_STAT(SPI_ERR_MASK);
				break;

			default:
				break;
			}

			pr_debug("IRQ %d:"
418 419
				 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
				 irq);
B
Bryan Wu 已提交
420 421 422 423 424
		}
	} else
		printk(KERN_ERR
		       "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
		       " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
425
		       __func__, __FILE__, __LINE__);
B
Bryan Wu 已提交
426 427 428 429

}
#endif				/* BF537_GENERIC_ERROR_INT_DEMUX */

430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
static int mac_stat_int_mask;

static void bfin_mac_status_ack_irq(unsigned int irq)
{
	switch (irq) {
	case IRQ_MAC_MMCINT:
		bfin_write_EMAC_MMC_TIRQS(
			bfin_read_EMAC_MMC_TIRQE() &
			bfin_read_EMAC_MMC_TIRQS());
		bfin_write_EMAC_MMC_RIRQS(
			bfin_read_EMAC_MMC_RIRQE() &
			bfin_read_EMAC_MMC_RIRQS());
		break;
	case IRQ_MAC_RXFSINT:
		bfin_write_EMAC_RX_STKY(
			bfin_read_EMAC_RX_IRQE() &
			bfin_read_EMAC_RX_STKY());
		break;
	case IRQ_MAC_TXFSINT:
		bfin_write_EMAC_TX_STKY(
			bfin_read_EMAC_TX_IRQE() &
			bfin_read_EMAC_TX_STKY());
		break;
	case IRQ_MAC_WAKEDET:
		 bfin_write_EMAC_WKUP_CTL(
			bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
		break;
	default:
		/* These bits are W1C */
		bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
		break;
	}
}

465
static void bfin_mac_status_mask_irq(struct irq_data *d)
466
{
467 468
	unsigned int irq = d->irq;

469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
	mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
#ifdef BF537_GENERIC_ERROR_INT_DEMUX
	switch (irq) {
	case IRQ_MAC_PHYINT:
		bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
		break;
	default:
		break;
	}
#else
	if (!mac_stat_int_mask)
		bfin_internal_mask_irq(IRQ_MAC_ERROR);
#endif
	bfin_mac_status_ack_irq(irq);
}

485
static void bfin_mac_status_unmask_irq(struct irq_data *d)
486
{
487 488
	unsigned int irq = d->irq;

489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
#ifdef BF537_GENERIC_ERROR_INT_DEMUX
	switch (irq) {
	case IRQ_MAC_PHYINT:
		bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
		break;
	default:
		break;
	}
#else
	if (!mac_stat_int_mask)
		bfin_internal_unmask_irq(IRQ_MAC_ERROR);
#endif
	mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
}

#ifdef CONFIG_PM
505
int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
506 507 508 509 510 511 512 513 514 515 516
{
#ifdef BF537_GENERIC_ERROR_INT_DEMUX
	return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
#else
	return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
#endif
}
#endif

static struct irq_chip bfin_mac_status_irqchip = {
	.name = "MACST",
517
	.irq_ack = bfin_ack_noop,
518 519 520
	.irq_mask_ack = bfin_mac_status_mask_irq,
	.irq_mask = bfin_mac_status_mask_irq,
	.irq_unmask = bfin_mac_status_unmask_irq,
521
#ifdef CONFIG_PM
522
	.irq_set_wake = bfin_mac_status_set_wake,
523 524 525 526 527 528 529 530 531
#endif
};

static void bfin_demux_mac_status_irq(unsigned int int_err_irq,
				 struct irq_desc *inta_desc)
{
	int i, irq = 0;
	u32 status = bfin_read_EMAC_SYSTAT();

532
	for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
		if (status & (1L << i)) {
			irq = IRQ_MAC_PHYINT + i;
			break;
		}

	if (irq) {
		if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
			bfin_handle_irq(irq);
		} else {
			bfin_mac_status_ack_irq(irq);
			pr_debug("IRQ %d:"
				 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
				 irq);
		}
	} else
		printk(KERN_ERR
		       "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
550 551 552
		       " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
		       "(EMAC_SYSTAT=0x%X)\n",
		       __func__, __FILE__, __LINE__, status);
553 554 555
}
#endif

556 557
static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
{
558
#ifdef CONFIG_IPIPE
559
	_set_irq_handler(irq, handle_level_irq);
560
#else
561
	__set_irq_handler_unlocked(irq, handle);
562
#endif
563 564
}

565
static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
566
extern void bfin_gpio_irq_prepare(unsigned gpio);
567

568 569
#if !defined(CONFIG_BF54x)

B
Bryan Wu 已提交
570 571
static void bfin_gpio_ack_irq(unsigned int irq)
{
572 573 574 575
	/* AFAIK ack_irq in case mask_ack is provided
	 * get's only called for edge sense irqs
	 */
	set_gpio_data(irq_to_gpio(irq), 0);
B
Bryan Wu 已提交
576 577 578 579
}

static void bfin_gpio_mask_ack_irq(unsigned int irq)
{
580
	struct irq_desc *desc = irq_to_desc(irq);
581
	u32 gpionr = irq_to_gpio(irq);
B
Bryan Wu 已提交
582

583
	if (desc->handle_irq == handle_edge_irq)
B
Bryan Wu 已提交
584 585 586 587 588 589 590
		set_gpio_data(gpionr, 0);

	set_gpio_maska(gpionr, 0);
}

static void bfin_gpio_mask_irq(unsigned int irq)
{
591
	set_gpio_maska(irq_to_gpio(irq), 0);
B
Bryan Wu 已提交
592 593 594 595
}

static void bfin_gpio_unmask_irq(unsigned int irq)
{
596
	set_gpio_maska(irq_to_gpio(irq), 1);
B
Bryan Wu 已提交
597 598 599 600
}

static unsigned int bfin_gpio_irq_startup(unsigned int irq)
{
601
	u32 gpionr = irq_to_gpio(irq);
B
Bryan Wu 已提交
602

603
	if (__test_and_set_bit(gpionr, gpio_enabled))
604
		bfin_gpio_irq_prepare(gpionr);
B
Bryan Wu 已提交
605 606 607

	bfin_gpio_unmask_irq(irq);

608
	return 0;
B
Bryan Wu 已提交
609 610 611 612
}

static void bfin_gpio_irq_shutdown(unsigned int irq)
{
613 614
	u32 gpionr = irq_to_gpio(irq);

B
Bryan Wu 已提交
615
	bfin_gpio_mask_irq(irq);
616
	__clear_bit(gpionr, gpio_enabled);
617
	bfin_gpio_irq_free(gpionr);
B
Bryan Wu 已提交
618 619 620 621
}

static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
{
622 623
	int ret;
	char buf[16];
624
	u32 gpionr = irq_to_gpio(irq);
B
Bryan Wu 已提交
625 626 627

	if (type == IRQ_TYPE_PROBE) {
		/* only probe unenabled GPIO interrupt lines */
628
		if (test_bit(gpionr, gpio_enabled))
B
Bryan Wu 已提交
629 630 631 632 633
			return 0;
		type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
	}

	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
634
		    IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
635

636 637 638 639 640
		snprintf(buf, 16, "gpio-irq%d", irq);
		ret = bfin_gpio_irq_request(gpionr, buf);
		if (ret)
			return ret;

641
		if (__test_and_set_bit(gpionr, gpio_enabled))
642
			bfin_gpio_irq_prepare(gpionr);
B
Bryan Wu 已提交
643 644

	} else {
645
		__clear_bit(gpionr, gpio_enabled);
B
Bryan Wu 已提交
646 647 648
		return 0;
	}

649
	set_gpio_inen(gpionr, 0);
B
Bryan Wu 已提交
650 651 652 653 654 655 656 657 658 659 660 661 662
	set_gpio_dir(gpionr, 0);

	if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
	    == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
		set_gpio_both(gpionr, 1);
	else
		set_gpio_both(gpionr, 0);

	if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
		set_gpio_polar(gpionr, 1);	/* low or falling edge denoted by one */
	else
		set_gpio_polar(gpionr, 0);	/* high or rising edge denoted by zero */

663 664 665 666 667 668 669 670 671 672
	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
		set_gpio_edge(gpionr, 1);
		set_gpio_inen(gpionr, 1);
		set_gpio_data(gpionr, 0);

	} else {
		set_gpio_edge(gpionr, 0);
		set_gpio_inen(gpionr, 1);
	}

B
Bryan Wu 已提交
673
	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
674
		bfin_set_irq_handler(irq, handle_edge_irq);
B
Bryan Wu 已提交
675
	else
676
		bfin_set_irq_handler(irq, handle_level_irq);
B
Bryan Wu 已提交
677 678 679 680

	return 0;
}

681 682 683
#ifdef CONFIG_PM
int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
{
684
	return gpio_pm_wakeup_ctrl(irq_to_gpio(irq), state);
685 686 687
}
#endif

688 689
static void bfin_demux_gpio_irq(unsigned int inta_irq,
				struct irq_desc *desc)
B
Bryan Wu 已提交
690
{
691 692 693 694 695 696 697 698 699 700 701 702 703
	unsigned int i, gpio, mask, irq, search = 0;

	switch (inta_irq) {
#if defined(CONFIG_BF53x)
	case IRQ_PROG_INTA:
		irq = IRQ_PF0;
		search = 1;
		break;
# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
	case IRQ_MAC_RX:
		irq = IRQ_PH0;
		break;
# endif
704 705 706 707
#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
	case IRQ_PORTF_INTA:
		irq = IRQ_PF0;
		break;
708
#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
	case IRQ_PORTF_INTA:
		irq = IRQ_PF0;
		break;
	case IRQ_PORTG_INTA:
		irq = IRQ_PG0;
		break;
	case IRQ_PORTH_INTA:
		irq = IRQ_PH0;
		break;
#elif defined(CONFIG_BF561)
	case IRQ_PROG0_INTA:
		irq = IRQ_PF0;
		break;
	case IRQ_PROG1_INTA:
		irq = IRQ_PF16;
		break;
	case IRQ_PROG2_INTA:
		irq = IRQ_PF32;
		break;
#endif
	default:
		BUG();
		return;
	}

	if (search) {
735
		for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
736 737
			irq += i;

738
			mask = get_gpiop_data(i) & get_gpiop_maska(i);
739 740

			while (mask) {
741 742
				if (mask & 1)
					bfin_handle_irq(irq);
743 744
				irq++;
				mask >>= 1;
B
Bryan Wu 已提交
745 746
			}
		}
747 748
	} else {
			gpio = irq_to_gpio(irq);
749
			mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
750 751

			do {
752 753
				if (mask & 1)
					bfin_handle_irq(irq);
754 755 756
				irq++;
				mask >>= 1;
			} while (mask);
B
Bryan Wu 已提交
757
	}
758

B
Bryan Wu 已提交
759 760
}

761
#else				/* CONFIG_BF54x */
762 763 764 765 766 767 768 769 770 771 772

#define NR_PINT_SYS_IRQS	4
#define NR_PINT_BITS		32
#define NR_PINTS		160
#define IRQ_NOT_AVAIL		0xFF

#define PINT_2_BANK(x)		((x) >> 5)
#define PINT_2_BIT(x)		((x) & 0x1F)
#define PINT_BIT(x)		(1 << (PINT_2_BIT(x)))

static unsigned char irq2pint_lut[NR_PINTS];
773
static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794

struct pin_int_t {
	unsigned int mask_set;
	unsigned int mask_clear;
	unsigned int request;
	unsigned int assign;
	unsigned int edge_set;
	unsigned int edge_clear;
	unsigned int invert_set;
	unsigned int invert_clear;
	unsigned int pinstate;
	unsigned int latch;
};

static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
	(struct pin_int_t *)PINT0_MASK_SET,
	(struct pin_int_t *)PINT1_MASK_SET,
	(struct pin_int_t *)PINT2_MASK_SET,
	(struct pin_int_t *)PINT3_MASK_SET,
};

795
inline unsigned int get_irq_base(u32 bank, u8 bmap)
796
{
797
	unsigned int irq_base;
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829

	if (bank < 2) {		/*PA-PB */
		irq_base = IRQ_PA0 + bmap * 16;
	} else {		/*PC-PJ */
		irq_base = IRQ_PC0 + bmap * 16;
	}

	return irq_base;
}

	/* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
void init_pint_lut(void)
{
	u16 bank, bit, irq_base, bit_pos;
	u32 pint_assign;
	u8 bmap;

	memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));

	for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {

		pint_assign = pint[bank]->assign;

		for (bit = 0; bit < NR_PINT_BITS; bit++) {

			bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;

			irq_base = get_irq_base(bank, bmap);

			irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
			bit_pos = bit + bank * NR_PINT_BITS;

830
			pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
831 832 833 834 835 836 837
			irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
		}
	}
}

static void bfin_gpio_ack_irq(unsigned int irq)
{
838
	struct irq_desc *desc = irq_to_desc(irq);
839
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
840
	u32 pintbit = PINT_BIT(pint_val);
841
	u32 bank = PINT_2_BANK(pint_val);
842

843
	if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
844 845 846 847 848 849
		if (pint[bank]->invert_set & pintbit)
			pint[bank]->invert_clear = pintbit;
		else
			pint[bank]->invert_set = pintbit;
	}
	pint[bank]->request = pintbit;
850 851 852 853 854

}

static void bfin_gpio_mask_ack_irq(unsigned int irq)
{
855
	struct irq_desc *desc = irq_to_desc(irq);
856
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
857
	u32 pintbit = PINT_BIT(pint_val);
858
	u32 bank = PINT_2_BANK(pint_val);
859

860
	if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
861 862 863 864 865 866
		if (pint[bank]->invert_set & pintbit)
			pint[bank]->invert_clear = pintbit;
		else
			pint[bank]->invert_set = pintbit;
	}

867 868
	pint[bank]->request = pintbit;
	pint[bank]->mask_clear = pintbit;
869 870 871 872
}

static void bfin_gpio_mask_irq(unsigned int irq)
{
873
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
874 875 876 877 878 879

	pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
}

static void bfin_gpio_unmask_irq(unsigned int irq)
{
880
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
881
	u32 pintbit = PINT_BIT(pint_val);
882
	u32 bank = PINT_2_BANK(pint_val);
883

884
	pint[bank]->mask_set = pintbit;
885 886 887 888
}

static unsigned int bfin_gpio_irq_startup(unsigned int irq)
{
889 890
	u32 gpionr = irq_to_gpio(irq);
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
891

892 893 894 895
	if (pint_val == IRQ_NOT_AVAIL) {
		printk(KERN_ERR
		"GPIO IRQ %d :Not in PINT Assign table "
		"Reconfigure Interrupt to Port Assignemt\n", irq);
896
		return -ENODEV;
897
	}
898

899
	if (__test_and_set_bit(gpionr, gpio_enabled))
900
		bfin_gpio_irq_prepare(gpionr);
901 902 903

	bfin_gpio_unmask_irq(irq);

904
	return 0;
905 906 907 908
}

static void bfin_gpio_irq_shutdown(unsigned int irq)
{
909
	u32 gpionr = irq_to_gpio(irq);
910

911
	bfin_gpio_mask_irq(irq);
912
	__clear_bit(gpionr, gpio_enabled);
913
	bfin_gpio_irq_free(gpionr);
914 915 916 917
}

static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
{
918 919
	int ret;
	char buf[16];
920 921
	u32 gpionr = irq_to_gpio(irq);
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
922
	u32 pintbit = PINT_BIT(pint_val);
923
	u32 bank = PINT_2_BANK(pint_val);
924 925 926 927 928 929

	if (pint_val == IRQ_NOT_AVAIL)
		return -ENODEV;

	if (type == IRQ_TYPE_PROBE) {
		/* only probe unenabled GPIO interrupt lines */
930
		if (test_bit(gpionr, gpio_enabled))
931 932 933 934 935 936
			return 0;
		type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
	}

	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
		    IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
937 938 939 940 941 942

		snprintf(buf, 16, "gpio-irq%d", irq);
		ret = bfin_gpio_irq_request(gpionr, buf);
		if (ret)
			return ret;

943
		if (__test_and_set_bit(gpionr, gpio_enabled))
944
			bfin_gpio_irq_prepare(gpionr);
945 946

	} else {
947
		__clear_bit(gpionr, gpio_enabled);
948 949 950 951
		return 0;
	}

	if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
952
		pint[bank]->invert_set = pintbit;	/* low or falling edge denoted by one */
953
	else
954
		pint[bank]->invert_clear = pintbit;	/* high or rising edge denoted by zero */
955

956 957 958 959 960 961 962 963 964 965
	if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
	    == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
		if (gpio_get_value(gpionr))
			pint[bank]->invert_set = pintbit;
		else
			pint[bank]->invert_clear = pintbit;
	}

	if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
		pint[bank]->edge_set = pintbit;
966
		bfin_set_irq_handler(irq, handle_edge_irq);
967 968
	} else {
		pint[bank]->edge_clear = pintbit;
969
		bfin_set_irq_handler(irq, handle_level_irq);
970 971
	}

972 973 974
	return 0;
}

975 976 977 978 979 980 981
#ifdef CONFIG_PM
u32 pint_saved_masks[NR_PINT_SYS_IRQS];
u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];

int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
{
	u32 pint_irq;
982
	u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
	u32 bank = PINT_2_BANK(pint_val);
	u32 pintbit = PINT_BIT(pint_val);

	switch (bank) {
	case 0:
		pint_irq = IRQ_PINT0;
		break;
	case 2:
		pint_irq = IRQ_PINT2;
		break;
	case 3:
		pint_irq = IRQ_PINT3;
		break;
	case 1:
		pint_irq = IRQ_PINT1;
		break;
	default:
		return -EINVAL;
	}

	bfin_internal_set_wake(pint_irq, state);

	if (state)
		pint_wakeup_masks[bank] |= pintbit;
	else
		pint_wakeup_masks[bank] &= ~pintbit;

	return 0;
}

u32 bfin_pm_setup(void)
{
	u32 val, i;

	for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
		val = pint[i]->mask_clear;
		pint_saved_masks[i] = val;
		if (val ^ pint_wakeup_masks[i]) {
			pint[i]->mask_clear = val;
			pint[i]->mask_set = pint_wakeup_masks[i];
		}
	}

	return 0;
}

void bfin_pm_restore(void)
{
	u32 i, val;

	for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
		val = pint_saved_masks[i];
		if (val ^ pint_wakeup_masks[i]) {
			pint[i]->mask_clear = pint[i]->mask_clear;
			pint[i]->mask_set = val;
		}
	}
}
#endif

1043 1044
static void bfin_demux_gpio_irq(unsigned int inta_irq,
				struct irq_desc *desc)
1045
{
1046
	u32 bank, pint_val;
1047 1048
	u32 request, irq;

1049
	switch (inta_irq) {
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
	case IRQ_PINT0:
		bank = 0;
		break;
	case IRQ_PINT2:
		bank = 2;
		break;
	case IRQ_PINT3:
		bank = 3;
		break;
	case IRQ_PINT1:
		bank = 1;
		break;
1062 1063
	default:
		return;
1064 1065 1066 1067 1068 1069 1070 1071
	}

	pint_val = bank * NR_PINT_BITS;

	request = pint[bank]->request;

	while (request) {
		if (request & 1) {
1072
			irq = pint2irq_lut[pint_val] + SYS_IRQS;
1073
			bfin_handle_irq(irq);
1074 1075 1076 1077 1078 1079
		}
		pint_val++;
		request >>= 1;
	}

}
1080
#endif
B
Bryan Wu 已提交
1081

1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
static struct irq_chip bfin_gpio_irqchip = {
	.name = "GPIO",
	.ack = bfin_gpio_ack_irq,
	.mask = bfin_gpio_mask_irq,
	.mask_ack = bfin_gpio_mask_ack_irq,
	.unmask = bfin_gpio_unmask_irq,
	.disable = bfin_gpio_mask_irq,
	.enable = bfin_gpio_unmask_irq,
	.set_type = bfin_gpio_irq_type,
	.startup = bfin_gpio_irq_startup,
	.shutdown = bfin_gpio_irq_shutdown,
#ifdef CONFIG_PM
	.set_wake = bfin_gpio_set_wake,
#endif
};

1098
void __cpuinit init_exception_vectors(void)
1099
{
1100 1101 1102 1103 1104
	/* cannot program in software:
	 * evt0 - emulation (jtag)
	 * evt1 - reset
	 */
	bfin_write_EVT2(evt_nmi);
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
	bfin_write_EVT3(trap);
	bfin_write_EVT5(evt_ivhw);
	bfin_write_EVT6(evt_timer);
	bfin_write_EVT7(evt_evt7);
	bfin_write_EVT8(evt_evt8);
	bfin_write_EVT9(evt_evt9);
	bfin_write_EVT10(evt_evt10);
	bfin_write_EVT11(evt_evt11);
	bfin_write_EVT12(evt_evt12);
	bfin_write_EVT13(evt_evt13);
1115
	bfin_write_EVT14(evt_evt14);
1116 1117 1118 1119
	bfin_write_EVT15(evt_system_call);
	CSYNC();
}

B
Bryan Wu 已提交
1120 1121 1122 1123
/*
 * This function should be called during kernel startup to initialize
 * the BFin IRQ handling routines.
 */
1124

B
Bryan Wu 已提交
1125 1126 1127 1128 1129
int __init init_arch_irq(void)
{
	int irq;
	unsigned long ilat = 0;
	/*  Disable all the peripheral intrs  - page 4-29 HW Ref manual */
1130 1131
#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
	|| defined(BF538_FAMILY) || defined(CONFIG_BF51x)
1132 1133
	bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
	bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
1134
# ifdef CONFIG_BF54x
1135
	bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
1136
# endif
1137 1138 1139 1140
# ifdef CONFIG_SMP
	bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
	bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
# endif
1141
#else
B
Bryan Wu 已提交
1142
	bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
1143
#endif
B
Bryan Wu 已提交
1144 1145 1146

	local_irq_disable();

1147
#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
1148 1149 1150 1151
	/* Clear EMAC Interrupt Status bits so we can demux it later */
	bfin_write_EMAC_SYSTAT(-1);
#endif

1152 1153
#ifdef CONFIG_BF54x
# ifdef CONFIG_PINTx_REASSIGN
1154 1155 1156 1157
	pint[0]->assign = CONFIG_PINT0_ASSIGN;
	pint[1]->assign = CONFIG_PINT1_ASSIGN;
	pint[2]->assign = CONFIG_PINT2_ASSIGN;
	pint[3]->assign = CONFIG_PINT3_ASSIGN;
1158
# endif
1159 1160 1161 1162 1163
	/* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
	init_pint_lut();
#endif

	for (irq = 0; irq <= SYS_IRQS; irq++) {
B
Bryan Wu 已提交
1164 1165 1166 1167 1168
		if (irq <= IRQ_CORETMR)
			set_irq_chip(irq, &bfin_core_irqchip);
		else
			set_irq_chip(irq, &bfin_internal_irqchip);

1169
		switch (irq) {
1170
#if defined(CONFIG_BF53x)
1171
		case IRQ_PROG_INTA:
1172
# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
1173
		case IRQ_MAC_RX:
1174
# endif
1175
#elif defined(CONFIG_BF54x)
1176 1177 1178 1179
		case IRQ_PINT0:
		case IRQ_PINT1:
		case IRQ_PINT2:
		case IRQ_PINT3:
1180
#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1181 1182 1183
		case IRQ_PORTF_INTA:
		case IRQ_PORTG_INTA:
		case IRQ_PORTH_INTA:
1184
#elif defined(CONFIG_BF561)
1185 1186 1187
		case IRQ_PROG0_INTA:
		case IRQ_PROG1_INTA:
		case IRQ_PROG2_INTA:
1188 1189
#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
		case IRQ_PORTF_INTA:
B
Bryan Wu 已提交
1190
#endif
1191 1192 1193
			set_irq_chained_handler(irq,
						bfin_demux_gpio_irq);
			break;
B
Bryan Wu 已提交
1194
#ifdef BF537_GENERIC_ERROR_INT_DEMUX
1195
		case IRQ_GENERIC_ERROR:
1196
			set_irq_chained_handler(irq, bfin_demux_error_irq);
1197
			break;
B
Bryan Wu 已提交
1198
#endif
1199 1200 1201 1202 1203
#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
		case IRQ_MAC_ERROR:
			set_irq_chained_handler(irq, bfin_demux_mac_status_irq);
			break;
#endif
1204 1205 1206 1207 1208 1209
#ifdef CONFIG_SMP
		case IRQ_SUPPLE_0:
		case IRQ_SUPPLE_1:
			set_irq_handler(irq, handle_percpu_irq);
			break;
#endif
1210

1211 1212 1213 1214 1215 1216
#ifdef CONFIG_TICKSOURCE_CORETMR
		case IRQ_CORETMR:
# ifdef CONFIG_SMP
			set_irq_handler(irq, handle_percpu_irq);
			break;
# else
1217 1218
			set_irq_handler(irq, handle_simple_irq);
			break;
1219
# endif
1220
#endif
1221 1222 1223

#ifdef CONFIG_TICKSOURCE_GPTMR0
		case IRQ_TIMER0:
1224 1225
			set_irq_handler(irq, handle_simple_irq);
			break;
1226 1227 1228
#endif

#ifdef CONFIG_IPIPE
1229 1230 1231
		default:
			set_irq_handler(irq, handle_level_irq);
			break;
1232
#else /* !CONFIG_IPIPE */
1233
		default:
1234 1235
			set_irq_handler(irq, handle_simple_irq);
			break;
1236
#endif /* !CONFIG_IPIPE */
1237
		}
B
Bryan Wu 已提交
1238
	}
1239

B
Bryan Wu 已提交
1240
#ifdef BF537_GENERIC_ERROR_INT_DEMUX
1241 1242 1243
	for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
		set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
					 handle_level_irq);
1244 1245 1246
#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
	set_irq_chained_handler(IRQ_MAC_ERROR, bfin_demux_mac_status_irq);
#endif
B
Bryan Wu 已提交
1247 1248
#endif

1249 1250 1251 1252 1253
#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
	for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
		set_irq_chip_and_handler(irq, &bfin_mac_status_irqchip,
					 handle_level_irq);
#endif
1254
	/* if configured as edge, then will be changed to do_edge_IRQ */
1255 1256
	for (irq = GPIO_IRQ_BASE;
		irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
1257 1258
		set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
					 handle_level_irq);
1259

B
Bryan Wu 已提交
1260 1261 1262 1263 1264 1265 1266
	bfin_write_IMASK(0);
	CSYNC();
	ilat = bfin_read_ILAT();
	CSYNC();
	bfin_write_ILAT(ilat);
	CSYNC();

1267
	printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1268
	/* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
B
Bryan Wu 已提交
1269 1270 1271 1272 1273 1274 1275
	 * local_irq_enable()
	 */
	program_IAR();
	/* Therefore it's better to setup IARs before interrupts enabled */
	search_IAR();

	/* Enable interrupts IVG7-15 */
1276
	bfin_irq_flags |= IMASK_IVG15 |
B
Bryan Wu 已提交
1277
	    IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1278
	    IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
B
Bryan Wu 已提交
1279

1280 1281 1282
	/* This implicitly covers ANOMALY_05000171
	 * Boot-ROM code modifies SICA_IWRx wakeup registers
	 */
1283
#ifdef SIC_IWR0
1284
	bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
1285
# ifdef SIC_IWR1
1286
	/* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
1287 1288 1289 1290
	 * will screw up the bootrom as it relies on MDMA0/1 waking it
	 * up from IDLE instructions.  See this report for more info:
	 * http://blackfin.uclinux.org/gf/tracker/4323
	 */
1291 1292 1293 1294
	if (ANOMALY_05000435)
		bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
	else
		bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
1295 1296
# endif
# ifdef SIC_IWR2
1297
	bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
1298 1299
# endif
#else
1300
	bfin_write_SIC_IWR(IWR_DISABLE_ALL);
1301 1302
#endif

B
Bryan Wu 已提交
1303 1304 1305 1306
	return 0;
}

#ifdef CONFIG_DO_IRQ_L1
1307
__attribute__((l1_text))
B
Bryan Wu 已提交
1308 1309 1310 1311 1312 1313 1314 1315
#endif
void do_irq(int vec, struct pt_regs *fp)
{
	if (vec == EVT_IVTMR_P) {
		vec = IRQ_CORETMR;
	} else {
		struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
		struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1316
#if defined(SIC_ISR0)
1317
		unsigned long sic_status[3];
B
Bryan Wu 已提交
1318

1319
		if (smp_processor_id()) {
1320
# ifdef SICB_ISR0
1321 1322 1323
			/* This will be optimized out in UP mode. */
			sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
			sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1324
# endif
1325 1326 1327 1328
		} else {
			sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
			sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
		}
1329
# ifdef SIC_ISR2
1330
		sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1331
# endif
1332
		for (;; ivg++) {
1333 1334 1335 1336
			if (ivg >= ivg_stop) {
				atomic_inc(&num_spurious);
				return;
			}
1337
			if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1338 1339 1340 1341
				break;
		}
#else
		unsigned long sic_status;
1342

B
Bryan Wu 已提交
1343 1344 1345 1346 1347 1348 1349 1350 1351
		sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();

		for (;; ivg++) {
			if (ivg >= ivg_stop) {
				atomic_inc(&num_spurious);
				return;
			} else if (sic_status & ivg->isrflag)
				break;
		}
1352
#endif
B
Bryan Wu 已提交
1353 1354 1355 1356
		vec = ivg->irqno;
	}
	asm_do_IRQ(vec, fp);
}
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386

#ifdef CONFIG_IPIPE

int __ipipe_get_irq_priority(unsigned irq)
{
	int ient, prio;

	if (irq <= IRQ_CORETMR)
		return irq;

	for (ient = 0; ient < NR_PERI_INTS; ient++) {
		struct ivgx *ivg = ivg_table + ient;
		if (ivg->irqno == irq) {
			for (prio = 0; prio <= IVG13-IVG7; prio++) {
				if (ivg7_13[prio].ifirst <= ivg &&
				    ivg7_13[prio].istop > ivg)
					return IVG7 + prio;
			}
		}
	}

	return IVG15;
}

/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
#ifdef CONFIG_DO_IRQ_L1
__attribute__((l1_text))
#endif
asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
{
1387
	struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
1388
	struct ipipe_domain *this_domain = __ipipe_current_domain;
1389 1390
	struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
	struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
1391
	int irq, s;
1392

1393
	if (likely(vec == EVT_IVTMR_P))
1394
		irq = IRQ_CORETMR;
1395
	else {
1396
#if defined(SIC_ISR0)
1397 1398 1399 1400
		unsigned long sic_status[3];

		sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
		sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1401
# ifdef SIC_ISR2
1402
		sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1403
# endif
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424
		for (;; ivg++) {
			if (ivg >= ivg_stop) {
				atomic_inc(&num_spurious);
				return 0;
			}
			if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
				break;
		}
#else
		unsigned long sic_status;

		sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();

		for (;; ivg++) {
			if (ivg >= ivg_stop) {
				atomic_inc(&num_spurious);
				return 0;
			} else if (sic_status & ivg->isrflag)
				break;
		}
#endif
1425 1426
		irq = ivg->irqno;
	}
1427 1428

	if (irq == IRQ_SYSTMR) {
1429
#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
1430
		bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
1431
#endif
1432 1433 1434
		/* This is basically what we need from the register frame. */
		__raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
		__raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
1435
		if (this_domain != ipipe_root_domain)
1436
			__raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
1437 1438
		else
			__raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
1439 1440
	}

1441 1442 1443 1444
	if (this_domain == ipipe_root_domain) {
		s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
		barrier();
	}
1445 1446 1447

	ipipe_trace_irq_entry(irq);
	__ipipe_handle_irq(irq, regs);
1448
	ipipe_trace_irq_exit(irq);
1449

1450 1451 1452 1453 1454 1455 1456
	if (this_domain == ipipe_root_domain) {
		set_thread_flag(TIF_IRQ_SYNC);
		if (!s) {
			__clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
			return !test_bit(IPIPE_STALL_FLAG, &p->status);
		}
	}
1457

1458
	return 0;
1459 1460 1461
}

#endif /* CONFIG_IPIPE */