xref: /openbmc/linux/arch/mips/jazz/irq.c (revision 94bd83e4)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * This file is subject to the terms and conditions of the GNU General Public
31da177e4SLinus Torvalds  * License.  See the file "COPYING" in the main directory of this archive
41da177e4SLinus Torvalds  * for more details.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * Copyright (C) 1992 Linus Torvalds
789742e53SRalf Baechle  * Copyright (C) 1994 - 2001, 2003, 07 Ralf Baechle
81da177e4SLinus Torvalds  */
9584d98beSRalf Baechle #include <linux/clockchips.h>
10334955efSRalf Baechle #include <linux/i8253.h>
111da177e4SLinus Torvalds #include <linux/init.h>
121da177e4SLinus Torvalds #include <linux/interrupt.h>
131da177e4SLinus Torvalds #include <linux/kernel.h>
14631330f5SRalf Baechle #include <linux/smp.h>
151da177e4SLinus Torvalds #include <linux/spinlock.h>
16ca4d3e67SDavid Howells #include <linux/irq.h>
1765fddcfcSMike Rapoport #include <linux/pgtable.h>
181da177e4SLinus Torvalds 
19ea202c63SThomas Bogendoerfer #include <asm/irq_cpu.h>
201da177e4SLinus Torvalds #include <asm/i8259.h>
211da177e4SLinus Torvalds #include <asm/io.h>
221da177e4SLinus Torvalds #include <asm/jazz.h>
233d18c983SRalf Baechle #include <asm/tlbmisc.h>
241da177e4SLinus Torvalds 
254a41abe5SRalf Baechle static DEFINE_RAW_SPINLOCK(r4030_lock);
261da177e4SLinus Torvalds 
enable_r4030_irq(struct irq_data * d)27db00bed4SThomas Gleixner static void enable_r4030_irq(struct irq_data *d)
281da177e4SLinus Torvalds {
29db00bed4SThomas Gleixner 	unsigned int mask = 1 << (d->irq - JAZZ_IRQ_START);
301da177e4SLinus Torvalds 	unsigned long flags;
311da177e4SLinus Torvalds 
324a41abe5SRalf Baechle 	raw_spin_lock_irqsave(&r4030_lock, flags);
331da177e4SLinus Torvalds 	mask |= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
341da177e4SLinus Torvalds 	r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
354a41abe5SRalf Baechle 	raw_spin_unlock_irqrestore(&r4030_lock, flags);
361da177e4SLinus Torvalds }
371da177e4SLinus Torvalds 
disable_r4030_irq(struct irq_data * d)38db00bed4SThomas Gleixner void disable_r4030_irq(struct irq_data *d)
391da177e4SLinus Torvalds {
40db00bed4SThomas Gleixner 	unsigned int mask = ~(1 << (d->irq - JAZZ_IRQ_START));
411da177e4SLinus Torvalds 	unsigned long flags;
421da177e4SLinus Torvalds 
434a41abe5SRalf Baechle 	raw_spin_lock_irqsave(&r4030_lock, flags);
441da177e4SLinus Torvalds 	mask &= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
451da177e4SLinus Torvalds 	r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
464a41abe5SRalf Baechle 	raw_spin_unlock_irqrestore(&r4030_lock, flags);
471da177e4SLinus Torvalds }
481da177e4SLinus Torvalds 
4994dee171SRalf Baechle static struct irq_chip r4030_irq_type = {
5070d21cdeSAtsushi Nemoto 	.name = "R4030",
51db00bed4SThomas Gleixner 	.irq_mask = disable_r4030_irq,
52db00bed4SThomas Gleixner 	.irq_unmask = enable_r4030_irq,
531da177e4SLinus Torvalds };
541da177e4SLinus Torvalds 
init_r4030_ints(void)551da177e4SLinus Torvalds void __init init_r4030_ints(void)
561da177e4SLinus Torvalds {
571da177e4SLinus Torvalds 	int i;
581da177e4SLinus Torvalds 
59ea202c63SThomas Bogendoerfer 	for (i = JAZZ_IRQ_START; i <= JAZZ_IRQ_END; i++)
60e4ec7989SThomas Gleixner 		irq_set_chip_and_handler(i, &r4030_irq_type, handle_level_irq);
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds 	r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0);
631da177e4SLinus Torvalds 	r4030_read_reg16(JAZZ_IO_IRQ_SOURCE);		/* clear pending IRQs */
641da177e4SLinus Torvalds 	r4030_read_reg32(JAZZ_R4030_INVAL_ADDR);	/* clear error bits */
651da177e4SLinus Torvalds }
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds /*
681da177e4SLinus Torvalds  * On systems with i8259-style interrupt controllers we assume for
691da177e4SLinus Torvalds  * driver compatibility reasons interrupts 0 - 15 to be the i8259
701da177e4SLinus Torvalds  * interrupts even if the hardware uses a different interrupt numbering.
711da177e4SLinus Torvalds  */
arch_init_irq(void)721da177e4SLinus Torvalds void __init arch_init_irq(void)
731da177e4SLinus Torvalds {
74ea202c63SThomas Bogendoerfer 	/*
75ea202c63SThomas Bogendoerfer 	 * this is a hack to get back the still needed wired mapping
76ea202c63SThomas Bogendoerfer 	 * killed by init_mm()
77ea202c63SThomas Bogendoerfer 	 */
78ea202c63SThomas Bogendoerfer 
79ea202c63SThomas Bogendoerfer 	/* Map 0xe0000000 -> 0x0:800005C0, 0xe0010000 -> 0x1:30000580 */
80ea202c63SThomas Bogendoerfer 	add_wired_entry(0x02000017, 0x03c00017, 0xe0000000, PM_64K);
81ea202c63SThomas Bogendoerfer 	/* Map 0xe2000000 -> 0x0:900005C0, 0xe3010000 -> 0x0:910005C0 */
82ea202c63SThomas Bogendoerfer 	add_wired_entry(0x02400017, 0x02440017, 0xe2000000, PM_16M);
83ea202c63SThomas Bogendoerfer 	/* Map 0xe4000000 -> 0x0:600005C0, 0xe4100000 -> 400005C0 */
84ea202c63SThomas Bogendoerfer 	add_wired_entry(0x01800017, 0x01000017, 0xe4000000, PM_4M);
85ea202c63SThomas Bogendoerfer 
861da177e4SLinus Torvalds 	init_i8259_irqs();			/* Integrated i8259  */
87ea202c63SThomas Bogendoerfer 	mips_cpu_irq_init();
881da177e4SLinus Torvalds 	init_r4030_ints();
891da177e4SLinus Torvalds 
90ea202c63SThomas Bogendoerfer 	change_c0_status(ST0_IM, IE_IRQ2 | IE_IRQ1);
91e4ac58afSRalf Baechle }
92e4ac58afSRalf Baechle 
plat_irq_dispatch(void)93937a8015SRalf Baechle asmlinkage void plat_irq_dispatch(void)
94e4ac58afSRalf Baechle {
95119537c0SThiemo Seufer 	unsigned int pending = read_c0_cause() & read_c0_status();
96ea202c63SThomas Bogendoerfer 	unsigned int irq;
97e4ac58afSRalf Baechle 
98ea202c63SThomas Bogendoerfer 	if (pending & IE_IRQ4) {
99e4ac58afSRalf Baechle 		r4030_read_reg32(JAZZ_TIMER_REGISTER);
100937a8015SRalf Baechle 		do_IRQ(JAZZ_TIMER_IRQ);
1013be51f70SThomas Bogendoerfer 	} else if (pending & IE_IRQ2) {
1023be51f70SThomas Bogendoerfer 		irq = *(volatile u8 *)JAZZ_EISA_IRQ_ACK;
1033be51f70SThomas Bogendoerfer 		do_IRQ(irq);
1043be51f70SThomas Bogendoerfer 	} else if (pending & IE_IRQ1) {
105ea202c63SThomas Bogendoerfer 		irq = *(volatile u8 *)JAZZ_IO_IRQ_SOURCE >> 2;
106ea202c63SThomas Bogendoerfer 		if (likely(irq > 0))
107ea202c63SThomas Bogendoerfer 			do_IRQ(irq + JAZZ_IRQ_START - 1);
108ea202c63SThomas Bogendoerfer 		else
109ea202c63SThomas Bogendoerfer 			panic("Unimplemented loc_no_irq handler");
110e4ac58afSRalf Baechle 	}
111e4ac58afSRalf Baechle }
112584d98beSRalf Baechle 
113584d98beSRalf Baechle struct clock_event_device r4030_clockevent = {
114584d98beSRalf Baechle 	.name		= "r4030",
115584d98beSRalf Baechle 	.features	= CLOCK_EVT_FEAT_PERIODIC,
1163be51f70SThomas Bogendoerfer 	.rating		= 300,
117584d98beSRalf Baechle 	.irq		= JAZZ_TIMER_IRQ,
118584d98beSRalf Baechle };
119584d98beSRalf Baechle 
r4030_timer_interrupt(int irq,void * dev_id)120584d98beSRalf Baechle static irqreturn_t r4030_timer_interrupt(int irq, void *dev_id)
121584d98beSRalf Baechle {
1223be51f70SThomas Bogendoerfer 	struct clock_event_device *cd = dev_id;
123584d98beSRalf Baechle 
1243be51f70SThomas Bogendoerfer 	cd->event_handler(cd);
125584d98beSRalf Baechle 	return IRQ_HANDLED;
126584d98beSRalf Baechle }
127584d98beSRalf Baechle 
plat_time_init(void)12889742e53SRalf Baechle void __init plat_time_init(void)
129584d98beSRalf Baechle {
1303be51f70SThomas Bogendoerfer 	struct clock_event_device *cd = &r4030_clockevent;
1313be51f70SThomas Bogendoerfer 	unsigned int cpu = smp_processor_id();
132584d98beSRalf Baechle 
133584d98beSRalf Baechle 	BUG_ON(HZ != 100);
134584d98beSRalf Baechle 
135320ab2b0SRusty Russell 	cd->cpumask		= cpumask_of(cpu);
1363be51f70SThomas Bogendoerfer 	clockevents_register_device(cd);
137ac8fd122Safzal mohammed 	if (request_irq(JAZZ_TIMER_IRQ, r4030_timer_interrupt, IRQF_TIMER,
138ac8fd122Safzal mohammed 			"R4030 timer", cd))
139ac8fd122Safzal mohammed 		pr_err("Failed to register R4030 timer interrupt\n");
1403be51f70SThomas Bogendoerfer 
141584d98beSRalf Baechle 	/*
142584d98beSRalf Baechle 	 * Set clock to 100Hz.
143584d98beSRalf Baechle 	 *
144*94bd83e4SJulia Lawall 	 * The R4030 timer receives an input clock of 1kHz which is divided by
145584d98beSRalf Baechle 	 * a programmable 4-bit divider.  This makes it fairly inflexible.
146584d98beSRalf Baechle 	 */
147584d98beSRalf Baechle 	r4030_write_reg32(JAZZ_TIMER_INTERVAL, 9);
14889742e53SRalf Baechle 	setup_pit_timer();
149584d98beSRalf Baechle }
150