xref: /kernel/linux/linux-5.10/arch/mips/jazz/irq.c (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
38c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
48c2ecf20Sopenharmony_ci * for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 1992 Linus Torvalds
78c2ecf20Sopenharmony_ci * Copyright (C) 1994 - 2001, 2003, 07 Ralf Baechle
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#include <linux/clockchips.h>
108c2ecf20Sopenharmony_ci#include <linux/i8253.h>
118c2ecf20Sopenharmony_ci#include <linux/init.h>
128c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/smp.h>
158c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
168c2ecf20Sopenharmony_ci#include <linux/irq.h>
178c2ecf20Sopenharmony_ci#include <linux/pgtable.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <asm/irq_cpu.h>
208c2ecf20Sopenharmony_ci#include <asm/i8259.h>
218c2ecf20Sopenharmony_ci#include <asm/io.h>
228c2ecf20Sopenharmony_ci#include <asm/jazz.h>
238c2ecf20Sopenharmony_ci#include <asm/tlbmisc.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic DEFINE_RAW_SPINLOCK(r4030_lock);
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic void enable_r4030_irq(struct irq_data *d)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	unsigned int mask = 1 << (d->irq - JAZZ_IRQ_START);
308c2ecf20Sopenharmony_ci	unsigned long flags;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&r4030_lock, flags);
338c2ecf20Sopenharmony_ci	mask |= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
348c2ecf20Sopenharmony_ci	r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
358c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&r4030_lock, flags);
368c2ecf20Sopenharmony_ci}
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_civoid disable_r4030_irq(struct irq_data *d)
398c2ecf20Sopenharmony_ci{
408c2ecf20Sopenharmony_ci	unsigned int mask = ~(1 << (d->irq - JAZZ_IRQ_START));
418c2ecf20Sopenharmony_ci	unsigned long flags;
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&r4030_lock, flags);
448c2ecf20Sopenharmony_ci	mask &= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
458c2ecf20Sopenharmony_ci	r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
468c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&r4030_lock, flags);
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic struct irq_chip r4030_irq_type = {
508c2ecf20Sopenharmony_ci	.name = "R4030",
518c2ecf20Sopenharmony_ci	.irq_mask = disable_r4030_irq,
528c2ecf20Sopenharmony_ci	.irq_unmask = enable_r4030_irq,
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_civoid __init init_r4030_ints(void)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	int i;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	for (i = JAZZ_IRQ_START; i <= JAZZ_IRQ_END; i++)
608c2ecf20Sopenharmony_ci		irq_set_chip_and_handler(i, &r4030_irq_type, handle_level_irq);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0);
638c2ecf20Sopenharmony_ci	r4030_read_reg16(JAZZ_IO_IRQ_SOURCE);		/* clear pending IRQs */
648c2ecf20Sopenharmony_ci	r4030_read_reg32(JAZZ_R4030_INVAL_ADDR);	/* clear error bits */
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/*
688c2ecf20Sopenharmony_ci * On systems with i8259-style interrupt controllers we assume for
698c2ecf20Sopenharmony_ci * driver compatibility reasons interrupts 0 - 15 to be the i8259
708c2ecf20Sopenharmony_ci * interrupts even if the hardware uses a different interrupt numbering.
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_civoid __init arch_init_irq(void)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci	/*
758c2ecf20Sopenharmony_ci	 * this is a hack to get back the still needed wired mapping
768c2ecf20Sopenharmony_ci	 * killed by init_mm()
778c2ecf20Sopenharmony_ci	 */
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	/* Map 0xe0000000 -> 0x0:800005C0, 0xe0010000 -> 0x1:30000580 */
808c2ecf20Sopenharmony_ci	add_wired_entry(0x02000017, 0x03c00017, 0xe0000000, PM_64K);
818c2ecf20Sopenharmony_ci	/* Map 0xe2000000 -> 0x0:900005C0, 0xe3010000 -> 0x0:910005C0 */
828c2ecf20Sopenharmony_ci	add_wired_entry(0x02400017, 0x02440017, 0xe2000000, PM_16M);
838c2ecf20Sopenharmony_ci	/* Map 0xe4000000 -> 0x0:600005C0, 0xe4100000 -> 400005C0 */
848c2ecf20Sopenharmony_ci	add_wired_entry(0x01800017, 0x01000017, 0xe4000000, PM_4M);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	init_i8259_irqs();			/* Integrated i8259  */
878c2ecf20Sopenharmony_ci	mips_cpu_irq_init();
888c2ecf20Sopenharmony_ci	init_r4030_ints();
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	change_c0_status(ST0_IM, IE_IRQ2 | IE_IRQ1);
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ciasmlinkage void plat_irq_dispatch(void)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	unsigned int pending = read_c0_cause() & read_c0_status();
968c2ecf20Sopenharmony_ci	unsigned int irq;
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	if (pending & IE_IRQ4) {
998c2ecf20Sopenharmony_ci		r4030_read_reg32(JAZZ_TIMER_REGISTER);
1008c2ecf20Sopenharmony_ci		do_IRQ(JAZZ_TIMER_IRQ);
1018c2ecf20Sopenharmony_ci	} else if (pending & IE_IRQ2) {
1028c2ecf20Sopenharmony_ci		irq = *(volatile u8 *)JAZZ_EISA_IRQ_ACK;
1038c2ecf20Sopenharmony_ci		do_IRQ(irq);
1048c2ecf20Sopenharmony_ci	} else if (pending & IE_IRQ1) {
1058c2ecf20Sopenharmony_ci		irq = *(volatile u8 *)JAZZ_IO_IRQ_SOURCE >> 2;
1068c2ecf20Sopenharmony_ci		if (likely(irq > 0))
1078c2ecf20Sopenharmony_ci			do_IRQ(irq + JAZZ_IRQ_START - 1);
1088c2ecf20Sopenharmony_ci		else
1098c2ecf20Sopenharmony_ci			panic("Unimplemented loc_no_irq handler");
1108c2ecf20Sopenharmony_ci	}
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistruct clock_event_device r4030_clockevent = {
1148c2ecf20Sopenharmony_ci	.name		= "r4030",
1158c2ecf20Sopenharmony_ci	.features	= CLOCK_EVT_FEAT_PERIODIC,
1168c2ecf20Sopenharmony_ci	.rating		= 300,
1178c2ecf20Sopenharmony_ci	.irq		= JAZZ_TIMER_IRQ,
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic irqreturn_t r4030_timer_interrupt(int irq, void *dev_id)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	struct clock_event_device *cd = dev_id;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	cd->event_handler(cd);
1258c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
1268c2ecf20Sopenharmony_ci}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_civoid __init plat_time_init(void)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci	struct clock_event_device *cd = &r4030_clockevent;
1318c2ecf20Sopenharmony_ci	unsigned int cpu = smp_processor_id();
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci	BUG_ON(HZ != 100);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	cd->cpumask		= cpumask_of(cpu);
1368c2ecf20Sopenharmony_ci	clockevents_register_device(cd);
1378c2ecf20Sopenharmony_ci	if (request_irq(JAZZ_TIMER_IRQ, r4030_timer_interrupt, IRQF_TIMER,
1388c2ecf20Sopenharmony_ci			"R4030 timer", cd))
1398c2ecf20Sopenharmony_ci		pr_err("Failed to register R4030 timer interrupt\n");
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	/*
1428c2ecf20Sopenharmony_ci	 * Set clock to 100Hz.
1438c2ecf20Sopenharmony_ci	 *
1448c2ecf20Sopenharmony_ci	 * The R4030 timer receives an input clock of 1kHz which is divieded by
1458c2ecf20Sopenharmony_ci	 * a programmable 4-bit divider.  This makes it fairly inflexible.
1468c2ecf20Sopenharmony_ci	 */
1478c2ecf20Sopenharmony_ci	r4030_write_reg32(JAZZ_TIMER_INTERVAL, 9);
1488c2ecf20Sopenharmony_ci	setup_pit_timer();
1498c2ecf20Sopenharmony_ci}
150