irq.c 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 * arch/arm/mach-ns9xxx/irq.c
 *
 * Copyright (C) 2006,2007 by Digi International Inc.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 */
#include <linux/interrupt.h>
12
#include <linux/kernel_stat.h>
13
#include <linux/io.h>
14
#include <asm/mach/irq.h>
15 16 17
#include <mach/regs-sys-common.h>
#include <mach/irqs.h>
#include <mach/board.h>
18 19 20

#include "generic.h"

21 22 23 24
/* simple interrupt prio table: prio(x) < prio(y) <=> x < y */
#define irq2prio(i) (i)
#define prio2irq(p) (p)

25 26 27
static void ns9xxx_mask_irq(unsigned int irq)
{
	/* XXX: better use cpp symbols */
28 29 30 31
	int prio = irq2prio(irq);
	u32 ic = __raw_readl(SYS_IC(prio / 4));
	ic &= ~(1 << (7 + 8 * (3 - (prio & 3))));
	__raw_writel(ic, SYS_IC(prio / 4));
32 33 34 35
}

static void ns9xxx_ack_irq(unsigned int irq)
{
36
	__raw_writel(0, SYS_ISRADDR);
37 38 39 40 41 42 43 44 45 46 47
}

static void ns9xxx_maskack_irq(unsigned int irq)
{
	ns9xxx_mask_irq(irq);
	ns9xxx_ack_irq(irq);
}

static void ns9xxx_unmask_irq(unsigned int irq)
{
	/* XXX: better use cpp symbols */
48 49 50 51
	int prio = irq2prio(irq);
	u32 ic = __raw_readl(SYS_IC(prio / 4));
	ic |= 1 << (7 + 8 * (3 - (prio & 3)));
	__raw_writel(ic, SYS_IC(prio / 4));
52 53 54 55 56 57 58 59 60
}

static struct irq_chip ns9xxx_chip = {
	.ack		= ns9xxx_ack_irq,
	.mask		= ns9xxx_mask_irq,
	.mask_ack	= ns9xxx_maskack_irq,
	.unmask		= ns9xxx_unmask_irq,
};

61 62 63
#if 0
#define handle_irq handle_level_irq
#else
U
Uwe Kleine-König 已提交
64
static void handle_prio_irq(unsigned int irq, struct irq_desc *desc)
65 66 67 68
{
	struct irqaction *action;
	irqreturn_t action_ret;

69
	raw_spin_lock(&desc->lock);
70

71
	BUG_ON(desc->status & IRQ_INPROGRESS);
72 73

	desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
74
	kstat_incr_irqs_this_cpu(irq, desc);
75 76 77

	action = desc->action;
	if (unlikely(!action || (desc->status & IRQ_DISABLED)))
78
		goto out_mask;
79 80

	desc->status |= IRQ_INPROGRESS;
81
	raw_spin_unlock(&desc->lock);
82 83 84

	action_ret = handle_IRQ_event(irq, action);

85 86 87 88 89
	/* XXX: There is no direct way to access noirqdebug, so check
	 * unconditionally for spurious irqs...
	 * Maybe this function should go to kernel/irq/chip.c? */
	note_interrupt(irq, desc, action_ret);

90
	raw_spin_lock(&desc->lock);
91 92
	desc->status &= ~IRQ_INPROGRESS;

93 94 95 96 97 98 99
	if (desc->status & IRQ_DISABLED)
out_mask:
		desc->chip->mask(irq);

	/* ack unconditionally to unmask lower prio irqs */
	desc->chip->ack(irq);

100
	raw_spin_unlock(&desc->lock);
101 102 103 104
}
#define handle_irq handle_prio_irq
#endif

105 106 107 108 109 110
void __init ns9xxx_init_irq(void)
{
	int i;

	/* disable all IRQs */
	for (i = 0; i < 8; ++i)
111 112 113 114 115
		__raw_writel(prio2irq(4 * i) << 24 |
				prio2irq(4 * i + 1) << 16 |
				prio2irq(4 * i + 2) << 8 |
				prio2irq(4 * i + 3),
				SYS_IC(i));
116 117

	for (i = 0; i < 32; ++i)
118
		__raw_writel(prio2irq(i), SYS_IVA(i));
119

120
	for (i = 0; i <= 31; ++i) {
121
		set_irq_chip(i, &ns9xxx_chip);
122
		set_irq_handler(i, handle_irq);
123 124 125
		set_irq_flags(i, IRQF_VALID);
	}
}