irq.c 4.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1992 Linus Torvalds
7
 * Copyright (C) 1994 - 2001, 2003, 07 Ralf Baechle
L
Linus Torvalds 已提交
8
 */
R
Ralf Baechle 已提交
9
#include <linux/clockchips.h>
L
Linus Torvalds 已提交
10 11 12
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
13
#include <linux/smp.h>
L
Linus Torvalds 已提交
14 15
#include <linux/spinlock.h>

T
Thomas Bogendoerfer 已提交
16
#include <asm/irq_cpu.h>
17
#include <asm/i8253.h>
L
Linus Torvalds 已提交
18 19 20
#include <asm/i8259.h>
#include <asm/io.h>
#include <asm/jazz.h>
T
Thomas Bogendoerfer 已提交
21
#include <asm/pgtable.h>
L
Linus Torvalds 已提交
22 23 24 25 26

static DEFINE_SPINLOCK(r4030_lock);

static void enable_r4030_irq(unsigned int irq)
{
T
Thomas Bogendoerfer 已提交
27
	unsigned int mask = 1 << (irq - JAZZ_IRQ_START);
L
Linus Torvalds 已提交
28 29 30 31 32 33 34 35 36 37
	unsigned long flags;

	spin_lock_irqsave(&r4030_lock, flags);
	mask |= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
	r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
	spin_unlock_irqrestore(&r4030_lock, flags);
}

void disable_r4030_irq(unsigned int irq)
{
T
Thomas Bogendoerfer 已提交
38
	unsigned int mask = ~(1 << (irq - JAZZ_IRQ_START));
L
Linus Torvalds 已提交
39 40 41 42 43 44 45 46
	unsigned long flags;

	spin_lock_irqsave(&r4030_lock, flags);
	mask &= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
	r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
	spin_unlock_irqrestore(&r4030_lock, flags);
}

47
static struct irq_chip r4030_irq_type = {
48
	.name = "R4030",
A
Atsushi Nemoto 已提交
49 50 51 52
	.ack = disable_r4030_irq,
	.mask = disable_r4030_irq,
	.mask_ack = disable_r4030_irq,
	.unmask = enable_r4030_irq,
L
Linus Torvalds 已提交
53 54 55 56 57 58
};

void __init init_r4030_ints(void)
{
	int i;

T
Thomas Bogendoerfer 已提交
59
	for (i = JAZZ_IRQ_START; i <= JAZZ_IRQ_END; i++)
60
		set_irq_chip_and_handler(i, &r4030_irq_type, handle_level_irq);
L
Linus Torvalds 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73

	r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0);
	r4030_read_reg16(JAZZ_IO_IRQ_SOURCE);		/* clear pending IRQs */
	r4030_read_reg32(JAZZ_R4030_INVAL_ADDR);	/* clear error bits */
}

/*
 * On systems with i8259-style interrupt controllers we assume for
 * driver compatibility reasons interrupts 0 - 15 to be the i8259
 * interrupts even if the hardware uses a different interrupt numbering.
 */
void __init arch_init_irq(void)
{
T
Thomas Bogendoerfer 已提交
74 75 76 77 78 79 80 81 82 83 84 85
	/*
	 * this is a hack to get back the still needed wired mapping
	 * killed by init_mm()
	 */

	/* Map 0xe0000000 -> 0x0:800005C0, 0xe0010000 -> 0x1:30000580 */
	add_wired_entry(0x02000017, 0x03c00017, 0xe0000000, PM_64K);
	/* Map 0xe2000000 -> 0x0:900005C0, 0xe3010000 -> 0x0:910005C0 */
	add_wired_entry(0x02400017, 0x02440017, 0xe2000000, PM_16M);
	/* Map 0xe4000000 -> 0x0:600005C0, 0xe4100000 -> 400005C0 */
	add_wired_entry(0x01800017, 0x01000017, 0xe4000000, PM_4M);

L
Linus Torvalds 已提交
86
	init_i8259_irqs();			/* Integrated i8259  */
T
Thomas Bogendoerfer 已提交
87
	mips_cpu_irq_init();
L
Linus Torvalds 已提交
88 89
	init_r4030_ints();

T
Thomas Bogendoerfer 已提交
90
	change_c0_status(ST0_IM, IE_IRQ2 | IE_IRQ1);
91 92
}

93
asmlinkage void plat_irq_dispatch(void)
94
{
95
	unsigned int pending = read_c0_cause() & read_c0_status();
T
Thomas Bogendoerfer 已提交
96
	unsigned int irq;
97

T
Thomas Bogendoerfer 已提交
98
	if (pending & IE_IRQ4) {
99
		r4030_read_reg32(JAZZ_TIMER_REGISTER);
100
		do_IRQ(JAZZ_TIMER_IRQ);
101 102 103 104
	} else if (pending & IE_IRQ2) {
		irq = *(volatile u8 *)JAZZ_EISA_IRQ_ACK;
		do_IRQ(irq);
	} else if (pending & IE_IRQ1) {
T
Thomas Bogendoerfer 已提交
105 106 107 108 109
		irq = *(volatile u8 *)JAZZ_IO_IRQ_SOURCE >> 2;
		if (likely(irq > 0))
			do_IRQ(irq + JAZZ_IRQ_START - 1);
		else
			panic("Unimplemented loc_no_irq handler");
110 111
	}
}
R
Ralf Baechle 已提交
112 113 114 115 116 117 118 119 120 121

static void r4030_set_mode(enum clock_event_mode mode,
                           struct clock_event_device *evt)
{
	/* Nothing to do ...  */
}

struct clock_event_device r4030_clockevent = {
	.name		= "r4030",
	.features	= CLOCK_EVT_FEAT_PERIODIC,
122
	.rating		= 300,
R
Ralf Baechle 已提交
123 124 125 126 127 128
	.irq		= JAZZ_TIMER_IRQ,
	.set_mode	= r4030_set_mode,
};

static irqreturn_t r4030_timer_interrupt(int irq, void *dev_id)
{
129
	struct clock_event_device *cd = dev_id;
R
Ralf Baechle 已提交
130

131
	cd->event_handler(cd);
R
Ralf Baechle 已提交
132 133 134 135 136 137
	return IRQ_HANDLED;
}

static struct irqaction r4030_timer_irqaction = {
	.handler	= r4030_timer_interrupt,
	.flags		= IRQF_DISABLED,
138
	.name		= "R4030 timer",
R
Ralf Baechle 已提交
139 140
};

141
void __init plat_time_init(void)
R
Ralf Baechle 已提交
142
{
143 144 145
	struct clock_event_device *cd = &r4030_clockevent;
	struct irqaction *action = &r4030_timer_irqaction;
	unsigned int cpu = smp_processor_id();
R
Ralf Baechle 已提交
146 147 148

	BUG_ON(HZ != 100);

149
	cd->cpumask             = cpumask_of(cpu);
150 151 152 153
	clockevents_register_device(cd);
	action->dev_id = cd;
	setup_irq(JAZZ_TIMER_IRQ, action);

R
Ralf Baechle 已提交
154 155 156 157 158 159 160
	/*
	 * Set clock to 100Hz.
	 *
	 * The R4030 timer receives an input clock of 1kHz which is divieded by
	 * a programmable 4-bit divider.  This makes it fairly inflexible.
	 */
	r4030_write_reg32(JAZZ_TIMER_INTERVAL, 9);
161
	setup_pit_timer();
R
Ralf Baechle 已提交
162
}