xref: /openbmc/linux/arch/m68k/mac/oss.c (revision 552c69b36ebd966186573b9c7a286b390935cce1)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
3da3fb3c9SFinn Thain  *	Operating System Services (OSS) chip handling
41da177e4SLinus Torvalds  *	Written by Joshua M. Thompson (funaho@jurai.org)
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *	This chip is used in the IIfx in place of VIA #2. It acts like a fancy
81da177e4SLinus Torvalds  *	VIA chip with prorammable interrupt levels.
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * 990502 (jmt) - Major rewrite for new interrupt architecture as well as some
111da177e4SLinus Torvalds  *		  recent insights into OSS operational details.
120c79cf6aSSimon Arlott  * 990610 (jmt) - Now taking full advantage of the OSS. Interrupts are mapped
131da177e4SLinus Torvalds  *		  to mostly match the A/UX interrupt scheme supported on the
141da177e4SLinus Torvalds  *		  VIA side. Also added support for enabling the ISM irq again
151da177e4SLinus Torvalds  *		  since we now have a functional IOP manager.
161da177e4SLinus Torvalds  */
171da177e4SLinus Torvalds 
181da177e4SLinus Torvalds #include <linux/types.h>
191da177e4SLinus Torvalds #include <linux/kernel.h>
201da177e4SLinus Torvalds #include <linux/mm.h>
211da177e4SLinus Torvalds #include <linux/delay.h>
221da177e4SLinus Torvalds #include <linux/init.h>
23ddc7fd25SGeert Uytterhoeven #include <linux/irq.h>
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #include <asm/macintosh.h>
261da177e4SLinus Torvalds #include <asm/macints.h>
271da177e4SLinus Torvalds #include <asm/mac_via.h>
281da177e4SLinus Torvalds #include <asm/mac_oss.h>
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds int oss_present;
311da177e4SLinus Torvalds volatile struct mac_oss *oss;
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds /*
341da177e4SLinus Torvalds  * Initialize the OSS
351da177e4SLinus Torvalds  */
361da177e4SLinus Torvalds 
oss_init(void)371da177e4SLinus Torvalds void __init oss_init(void)
381da177e4SLinus Torvalds {
391da177e4SLinus Torvalds 	int i;
401da177e4SLinus Torvalds 
417a0bb442SFinn Thain 	if (macintosh_config->ident != MAC_MODEL_IIFX)
427a0bb442SFinn Thain 		return;
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds 	oss = (struct mac_oss *) OSS_BASE;
457a0bb442SFinn Thain 	pr_debug("OSS detected at %p", oss);
467a0bb442SFinn Thain 	oss_present = 1;
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds 	/* Disable all interrupts. Unlike a VIA it looks like we    */
491da177e4SLinus Torvalds 	/* do this by setting the source's interrupt level to zero. */
501da177e4SLinus Torvalds 
51b24f670bSFinn Thain 	for (i = 0; i < OSS_NUM_SOURCES; i++)
52da3fb3c9SFinn Thain 		oss->irq_level[i] = 0;
531da177e4SLinus Torvalds }
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds /*
56*317b749eSFinn Thain  * Handle OSS interrupts.
57*317b749eSFinn Thain  * XXX how do you clear a pending IRQ? is it even necessary?
581da177e4SLinus Torvalds  */
591da177e4SLinus Torvalds 
oss_iopism_irq(struct irq_desc * desc)60*317b749eSFinn Thain static void oss_iopism_irq(struct irq_desc *desc)
619145db56SGeert Uytterhoeven {
62*317b749eSFinn Thain 	generic_handle_irq(IRQ_MAC_ADB);
63da3fb3c9SFinn Thain }
64da3fb3c9SFinn Thain 
oss_scsi_irq(struct irq_desc * desc)65*317b749eSFinn Thain static void oss_scsi_irq(struct irq_desc *desc)
66*317b749eSFinn Thain {
679145db56SGeert Uytterhoeven 	generic_handle_irq(IRQ_MAC_SCSI);
68da3fb3c9SFinn Thain }
69da3fb3c9SFinn Thain 
oss_nubus_irq(struct irq_desc * desc)70bd0b9ac4SThomas Gleixner static void oss_nubus_irq(struct irq_desc *desc)
719145db56SGeert Uytterhoeven {
72*317b749eSFinn Thain 	u16 events, irq_bit;
73*317b749eSFinn Thain 	int irq_num;
749145db56SGeert Uytterhoeven 
759145db56SGeert Uytterhoeven 	events = oss->irq_pending & OSS_IP_NUBUS;
76*317b749eSFinn Thain 	irq_num = NUBUS_SOURCE_BASE + 5;
77*317b749eSFinn Thain 	irq_bit = OSS_IP_NUBUS5;
789145db56SGeert Uytterhoeven 	do {
799145db56SGeert Uytterhoeven 		if (events & irq_bit) {
80*317b749eSFinn Thain 			events &= ~irq_bit;
81*317b749eSFinn Thain 			generic_handle_irq(irq_num);
829145db56SGeert Uytterhoeven 		}
83*317b749eSFinn Thain 		--irq_num;
84*317b749eSFinn Thain 		irq_bit >>= 1;
85*317b749eSFinn Thain 	} while (events);
86*317b749eSFinn Thain }
87*317b749eSFinn Thain 
oss_iopscc_irq(struct irq_desc * desc)88*317b749eSFinn Thain static void oss_iopscc_irq(struct irq_desc *desc)
89*317b749eSFinn Thain {
90*317b749eSFinn Thain 	generic_handle_irq(IRQ_MAC_SCC);
919145db56SGeert Uytterhoeven }
929145db56SGeert Uytterhoeven 
939145db56SGeert Uytterhoeven /*
949145db56SGeert Uytterhoeven  * Register the OSS and NuBus interrupt dispatchers.
95da3fb3c9SFinn Thain  *
96da3fb3c9SFinn Thain  * This IRQ mapping is laid out with two things in mind: first, we try to keep
97da3fb3c9SFinn Thain  * things on their own levels to avoid having to do double-dispatches. Second,
98da3fb3c9SFinn Thain  * the levels match as closely as possible the alternate IRQ mapping mode (aka
99da3fb3c9SFinn Thain  * "A/UX mode") available on some VIA machines.
1009145db56SGeert Uytterhoeven  */
1019145db56SGeert Uytterhoeven 
102da3fb3c9SFinn Thain #define OSS_IRQLEV_IOPISM    IRQ_AUTO_1
103da3fb3c9SFinn Thain #define OSS_IRQLEV_SCSI      IRQ_AUTO_2
104da3fb3c9SFinn Thain #define OSS_IRQLEV_NUBUS     IRQ_AUTO_3
105da3fb3c9SFinn Thain #define OSS_IRQLEV_IOPSCC    IRQ_AUTO_4
106da3fb3c9SFinn Thain #define OSS_IRQLEV_VIA1      IRQ_AUTO_6
107da3fb3c9SFinn Thain 
oss_register_interrupts(void)1089145db56SGeert Uytterhoeven void __init oss_register_interrupts(void)
1099145db56SGeert Uytterhoeven {
110*317b749eSFinn Thain 	irq_set_chained_handler(OSS_IRQLEV_IOPISM, oss_iopism_irq);
111*317b749eSFinn Thain 	irq_set_chained_handler(OSS_IRQLEV_SCSI,   oss_scsi_irq);
1129145db56SGeert Uytterhoeven 	irq_set_chained_handler(OSS_IRQLEV_NUBUS,  oss_nubus_irq);
113*317b749eSFinn Thain 	irq_set_chained_handler(OSS_IRQLEV_IOPSCC, oss_iopscc_irq);
1149145db56SGeert Uytterhoeven 	irq_set_chained_handler(OSS_IRQLEV_VIA1,   via1_irq);
115da3fb3c9SFinn Thain 
116da3fb3c9SFinn Thain 	/* OSS_VIA1 gets enabled here because it has no machspec interrupt. */
117*317b749eSFinn Thain 	oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1;
1189145db56SGeert Uytterhoeven }
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds /*
1211da177e4SLinus Torvalds  * Enable an OSS interrupt
1221da177e4SLinus Torvalds  *
1231da177e4SLinus Torvalds  * It looks messy but it's rather straightforward. The switch() statement
1241da177e4SLinus Torvalds  * just maps the machspec interrupt numbers to the right OSS interrupt
1251da177e4SLinus Torvalds  * source (if the OSS handles that interrupt) and then sets the interrupt
1261da177e4SLinus Torvalds  * level for that source to nonzero, thus enabling the interrupt.
1271da177e4SLinus Torvalds  */
1281da177e4SLinus Torvalds 
oss_irq_enable(int irq)1291da177e4SLinus Torvalds void oss_irq_enable(int irq) {
1301da177e4SLinus Torvalds 	switch(irq) {
13180614e5aSFinn Thain 		case IRQ_MAC_SCC:
1321da177e4SLinus Torvalds 			oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
133da3fb3c9SFinn Thain 			return;
1341da177e4SLinus Torvalds 		case IRQ_MAC_ADB:
1351da177e4SLinus Torvalds 			oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
136da3fb3c9SFinn Thain 			return;
1371da177e4SLinus Torvalds 		case IRQ_MAC_SCSI:
1381da177e4SLinus Torvalds 			oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
139da3fb3c9SFinn Thain 			return;
1401da177e4SLinus Torvalds 		case IRQ_NUBUS_9:
1411da177e4SLinus Torvalds 		case IRQ_NUBUS_A:
1421da177e4SLinus Torvalds 		case IRQ_NUBUS_B:
1431da177e4SLinus Torvalds 		case IRQ_NUBUS_C:
1441da177e4SLinus Torvalds 		case IRQ_NUBUS_D:
1451da177e4SLinus Torvalds 		case IRQ_NUBUS_E:
1461da177e4SLinus Torvalds 			irq -= NUBUS_SOURCE_BASE;
1471da177e4SLinus Torvalds 			oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
148da3fb3c9SFinn Thain 			return;
1491da177e4SLinus Torvalds 	}
150da3fb3c9SFinn Thain 
151da3fb3c9SFinn Thain 	if (IRQ_SRC(irq) == 1)
152da3fb3c9SFinn Thain 		via_irq_enable(irq);
1531da177e4SLinus Torvalds }
1541da177e4SLinus Torvalds 
1551da177e4SLinus Torvalds /*
1561da177e4SLinus Torvalds  * Disable an OSS interrupt
1571da177e4SLinus Torvalds  *
1581da177e4SLinus Torvalds  * Same as above except we set the source's interrupt level to zero,
1591da177e4SLinus Torvalds  * to disable the interrupt.
1601da177e4SLinus Torvalds  */
1611da177e4SLinus Torvalds 
oss_irq_disable(int irq)1621da177e4SLinus Torvalds void oss_irq_disable(int irq) {
1631da177e4SLinus Torvalds 	switch(irq) {
16480614e5aSFinn Thain 		case IRQ_MAC_SCC:
165da3fb3c9SFinn Thain 			oss->irq_level[OSS_IOPSCC] = 0;
166da3fb3c9SFinn Thain 			return;
1671da177e4SLinus Torvalds 		case IRQ_MAC_ADB:
168da3fb3c9SFinn Thain 			oss->irq_level[OSS_IOPISM] = 0;
169da3fb3c9SFinn Thain 			return;
1701da177e4SLinus Torvalds 		case IRQ_MAC_SCSI:
171da3fb3c9SFinn Thain 			oss->irq_level[OSS_SCSI] = 0;
172da3fb3c9SFinn Thain 			return;
1731da177e4SLinus Torvalds 		case IRQ_NUBUS_9:
1741da177e4SLinus Torvalds 		case IRQ_NUBUS_A:
1751da177e4SLinus Torvalds 		case IRQ_NUBUS_B:
1761da177e4SLinus Torvalds 		case IRQ_NUBUS_C:
1771da177e4SLinus Torvalds 		case IRQ_NUBUS_D:
1781da177e4SLinus Torvalds 		case IRQ_NUBUS_E:
1791da177e4SLinus Torvalds 			irq -= NUBUS_SOURCE_BASE;
180da3fb3c9SFinn Thain 			oss->irq_level[irq] = 0;
181da3fb3c9SFinn Thain 			return;
1821da177e4SLinus Torvalds 	}
183da3fb3c9SFinn Thain 
184da3fb3c9SFinn Thain 	if (IRQ_SRC(irq) == 1)
185da3fb3c9SFinn Thain 		via_irq_disable(irq);
1861da177e4SLinus Torvalds }
187