xref: /linux/arch/m68k/mac/psc.c (revision c43278f073c920a18af9721fb620c05f6826ff13)
1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  *	Apple Peripheral System Controller (PSC)
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *	The PSC is used on the AV Macs to control IO functions not handled
61da177e4SLinus Torvalds  *	by the VIAs (Ethernet, DSP, SCC).
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * TO DO:
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * Try to figure out what's going on in pIFR5 and pIFR6. There seem to be
111da177e4SLinus Torvalds  * persisant interrupt conditions in those registers and I have no idea what
121da177e4SLinus Torvalds  * they are. Granted it doesn't affect since we're not enabling any interrupts
131da177e4SLinus Torvalds  * on those levels at the moment, but it would be nice to know. I have a feeling
141da177e4SLinus Torvalds  * they aren't actually interrupt lines but data lines (to the DSP?)
151da177e4SLinus Torvalds  */
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds #include <linux/types.h>
181da177e4SLinus Torvalds #include <linux/kernel.h>
191da177e4SLinus Torvalds #include <linux/mm.h>
201da177e4SLinus Torvalds #include <linux/delay.h>
211da177e4SLinus Torvalds #include <linux/init.h>
22ddc7fd25SGeert Uytterhoeven #include <linux/irq.h>
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds #include <asm/traps.h>
251da177e4SLinus Torvalds #include <asm/macintosh.h>
261da177e4SLinus Torvalds #include <asm/macints.h>
271da177e4SLinus Torvalds #include <asm/mac_psc.h>
281da177e4SLinus Torvalds 
29*c43278f0SGeert Uytterhoeven #include "mac.h"
30*c43278f0SGeert Uytterhoeven 
311da177e4SLinus Torvalds #define DEBUG_PSC
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds volatile __u8 *psc;
34a77cdaafSGeert Uytterhoeven EXPORT_SYMBOL_GPL(psc);
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds /*
371da177e4SLinus Torvalds  * Debugging dump, used in various places to see what's going on.
381da177e4SLinus Torvalds  */
391da177e4SLinus Torvalds 
408dfbdf4aSAdrian Bunk static void psc_debug_dump(void)
411da177e4SLinus Torvalds {
421da177e4SLinus Torvalds 	int	i;
431da177e4SLinus Torvalds 
4470bc53b4SGeert Uytterhoeven 	if (!psc)
4570bc53b4SGeert Uytterhoeven 		return;
4670bc53b4SGeert Uytterhoeven 
471da177e4SLinus Torvalds 	for (i = 0x30 ; i < 0x70 ; i += 0x10) {
480e37a23eSFinn Thain 		printk(KERN_DEBUG "PSC #%d:  IFR = 0x%02X IER = 0x%02X\n",
491da177e4SLinus Torvalds 			i >> 4,
501da177e4SLinus Torvalds 			(int) psc_read_byte(pIFRbase + i),
511da177e4SLinus Torvalds 			(int) psc_read_byte(pIERbase + i));
521da177e4SLinus Torvalds 	}
531da177e4SLinus Torvalds }
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds /*
561da177e4SLinus Torvalds  * Try to kill all DMA channels on the PSC. Not sure how this his
571da177e4SLinus Torvalds  * supposed to work; this is code lifted from macmace.c and then
581da177e4SLinus Torvalds  * expanded to cover what I think are the other 7 channels.
591da177e4SLinus Torvalds  */
601da177e4SLinus Torvalds 
61a4df02a2SGeert Uytterhoeven static __init void psc_dma_die_die_die(void)
621da177e4SLinus Torvalds {
631da177e4SLinus Torvalds 	int i;
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds 	for (i = 0 ; i < 9 ; i++) {
661da177e4SLinus Torvalds 		psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800);
671da177e4SLinus Torvalds 		psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000);
681da177e4SLinus Torvalds 		psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100);
691da177e4SLinus Torvalds 		psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100);
701da177e4SLinus Torvalds 	}
711da177e4SLinus Torvalds }
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds /*
741da177e4SLinus Torvalds  * Initialize the PSC. For now this just involves shutting down all
751da177e4SLinus Torvalds  * interrupt sources using the IERs.
761da177e4SLinus Torvalds  */
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds void __init psc_init(void)
791da177e4SLinus Torvalds {
801da177e4SLinus Torvalds 	int i;
811da177e4SLinus Torvalds 
821da177e4SLinus Torvalds 	if (macintosh_config->ident != MAC_MODEL_C660
831da177e4SLinus Torvalds 	 && macintosh_config->ident != MAC_MODEL_Q840)
841da177e4SLinus Torvalds 	{
851da177e4SLinus Torvalds 		psc = NULL;
861da177e4SLinus Torvalds 		return;
871da177e4SLinus Torvalds 	}
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds 	/*
901da177e4SLinus Torvalds 	 * The PSC is always at the same spot, but using psc
91a34f0b31SUwe Kleine-König 	 * keeps things consistent with the psc_xxxx functions.
921da177e4SLinus Torvalds 	 */
931da177e4SLinus Torvalds 
941da177e4SLinus Torvalds 	psc = (void *) PSC_BASE;
951da177e4SLinus Torvalds 
960e37a23eSFinn Thain 	pr_debug("PSC detected at %p\n", psc);
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds 	psc_dma_die_die_die();
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds #ifdef DEBUG_PSC
1011da177e4SLinus Torvalds 	psc_debug_dump();
1021da177e4SLinus Torvalds #endif
1031da177e4SLinus Torvalds 	/*
1041da177e4SLinus Torvalds 	 * Mask and clear all possible interrupts
1051da177e4SLinus Torvalds 	 */
1061da177e4SLinus Torvalds 
1071da177e4SLinus Torvalds 	for (i = 0x30 ; i < 0x70 ; i += 0x10) {
1081da177e4SLinus Torvalds 		psc_write_byte(pIERbase + i, 0x0F);
1091da177e4SLinus Torvalds 		psc_write_byte(pIFRbase + i, 0x0F);
1101da177e4SLinus Torvalds 	}
1111da177e4SLinus Torvalds }
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds /*
1141da177e4SLinus Torvalds  * PSC interrupt handler. It's a lot like the VIA interrupt handler.
1151da177e4SLinus Torvalds  */
1161da177e4SLinus Torvalds 
117bd0b9ac4SThomas Gleixner static void psc_irq(struct irq_desc *desc)
1189145db56SGeert Uytterhoeven {
1199145db56SGeert Uytterhoeven 	unsigned int offset = (unsigned int)irq_desc_get_handler_data(desc);
120625b86adSThomas Gleixner 	unsigned int irq = irq_desc_get_irq(desc);
1219145db56SGeert Uytterhoeven 	int pIFR	= pIFRbase + offset;
1229145db56SGeert Uytterhoeven 	int pIER	= pIERbase + offset;
1239145db56SGeert Uytterhoeven 	int irq_num;
1249145db56SGeert Uytterhoeven 	unsigned char irq_bit, events;
1259145db56SGeert Uytterhoeven 
1269145db56SGeert Uytterhoeven 	events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF;
1279145db56SGeert Uytterhoeven 	if (!events)
1289145db56SGeert Uytterhoeven 		return;
1299145db56SGeert Uytterhoeven 
1309145db56SGeert Uytterhoeven 	irq_num = irq << 3;
1319145db56SGeert Uytterhoeven 	irq_bit = 1;
1329145db56SGeert Uytterhoeven 	do {
1339145db56SGeert Uytterhoeven 		if (events & irq_bit) {
1349145db56SGeert Uytterhoeven 			psc_write_byte(pIFR, irq_bit);
1359145db56SGeert Uytterhoeven 			generic_handle_irq(irq_num);
1369145db56SGeert Uytterhoeven 		}
1379145db56SGeert Uytterhoeven 		irq_num++;
1389145db56SGeert Uytterhoeven 		irq_bit <<= 1;
1399145db56SGeert Uytterhoeven 	} while (events >= irq_bit);
1409145db56SGeert Uytterhoeven }
1419145db56SGeert Uytterhoeven 
1429145db56SGeert Uytterhoeven /*
1439145db56SGeert Uytterhoeven  * Register the PSC interrupt dispatchers for autovector interrupts 3-6.
1449145db56SGeert Uytterhoeven  */
1459145db56SGeert Uytterhoeven 
1469145db56SGeert Uytterhoeven void __init psc_register_interrupts(void)
1479145db56SGeert Uytterhoeven {
14809c5cb94SThomas Gleixner 	irq_set_chained_handler_and_data(IRQ_AUTO_3, psc_irq, (void *)0x30);
14909c5cb94SThomas Gleixner 	irq_set_chained_handler_and_data(IRQ_AUTO_4, psc_irq, (void *)0x40);
15009c5cb94SThomas Gleixner 	irq_set_chained_handler_and_data(IRQ_AUTO_5, psc_irq, (void *)0x50);
15109c5cb94SThomas Gleixner 	irq_set_chained_handler_and_data(IRQ_AUTO_6, psc_irq, (void *)0x60);
1529145db56SGeert Uytterhoeven }
1531da177e4SLinus Torvalds 
1541da177e4SLinus Torvalds void psc_irq_enable(int irq) {
1551da177e4SLinus Torvalds 	int irq_src	= IRQ_SRC(irq);
1561da177e4SLinus Torvalds 	int irq_idx	= IRQ_IDX(irq);
1571da177e4SLinus Torvalds 	int pIER	= pIERbase + (irq_src << 4);
1581da177e4SLinus Torvalds 
1591da177e4SLinus Torvalds 	psc_write_byte(pIER, (1 << irq_idx) | 0x80);
1601da177e4SLinus Torvalds }
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds void psc_irq_disable(int irq) {
1631da177e4SLinus Torvalds 	int irq_src	= IRQ_SRC(irq);
1641da177e4SLinus Torvalds 	int irq_idx	= IRQ_IDX(irq);
1651da177e4SLinus Torvalds 	int pIER	= pIERbase + (irq_src << 4);
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds 	psc_write_byte(pIER, 1 << irq_idx);
1681da177e4SLinus Torvalds }
169