xref: /linux/arch/m68k/mac/psc.c (revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2)
1*1da177e4SLinus Torvalds /*
2*1da177e4SLinus Torvalds  *	Apple Peripheral System Controller (PSC)
3*1da177e4SLinus Torvalds  *
4*1da177e4SLinus Torvalds  *	The PSC is used on the AV Macs to control IO functions not handled
5*1da177e4SLinus Torvalds  *	by the VIAs (Ethernet, DSP, SCC).
6*1da177e4SLinus Torvalds  *
7*1da177e4SLinus Torvalds  * TO DO:
8*1da177e4SLinus Torvalds  *
9*1da177e4SLinus Torvalds  * Try to figure out what's going on in pIFR5 and pIFR6. There seem to be
10*1da177e4SLinus Torvalds  * persisant interrupt conditions in those registers and I have no idea what
11*1da177e4SLinus Torvalds  * they are. Granted it doesn't affect since we're not enabling any interrupts
12*1da177e4SLinus Torvalds  * on those levels at the moment, but it would be nice to know. I have a feeling
13*1da177e4SLinus Torvalds  * they aren't actually interrupt lines but data lines (to the DSP?)
14*1da177e4SLinus Torvalds  */
15*1da177e4SLinus Torvalds 
16*1da177e4SLinus Torvalds #include <linux/types.h>
17*1da177e4SLinus Torvalds #include <linux/kernel.h>
18*1da177e4SLinus Torvalds #include <linux/mm.h>
19*1da177e4SLinus Torvalds #include <linux/delay.h>
20*1da177e4SLinus Torvalds #include <linux/init.h>
21*1da177e4SLinus Torvalds 
22*1da177e4SLinus Torvalds #include <asm/traps.h>
23*1da177e4SLinus Torvalds #include <asm/bootinfo.h>
24*1da177e4SLinus Torvalds #include <asm/macintosh.h>
25*1da177e4SLinus Torvalds #include <asm/macints.h>
26*1da177e4SLinus Torvalds #include <asm/mac_psc.h>
27*1da177e4SLinus Torvalds 
28*1da177e4SLinus Torvalds #define DEBUG_PSC
29*1da177e4SLinus Torvalds 
30*1da177e4SLinus Torvalds int psc_present;
31*1da177e4SLinus Torvalds volatile __u8 *psc;
32*1da177e4SLinus Torvalds 
33*1da177e4SLinus Torvalds irqreturn_t psc_irq(int, void *, struct pt_regs *);
34*1da177e4SLinus Torvalds 
35*1da177e4SLinus Torvalds /*
36*1da177e4SLinus Torvalds  * Debugging dump, used in various places to see what's going on.
37*1da177e4SLinus Torvalds  */
38*1da177e4SLinus Torvalds 
39*1da177e4SLinus Torvalds void psc_debug_dump(void)
40*1da177e4SLinus Torvalds {
41*1da177e4SLinus Torvalds 	int	i;
42*1da177e4SLinus Torvalds 
43*1da177e4SLinus Torvalds 	if (!psc_present) return;
44*1da177e4SLinus Torvalds 	for (i = 0x30 ; i < 0x70 ; i += 0x10) {
45*1da177e4SLinus Torvalds 		printk("PSC #%d:  IFR = 0x%02X IER = 0x%02X\n",
46*1da177e4SLinus Torvalds 			i >> 4,
47*1da177e4SLinus Torvalds 			(int) psc_read_byte(pIFRbase + i),
48*1da177e4SLinus Torvalds 			(int) psc_read_byte(pIERbase + i));
49*1da177e4SLinus Torvalds 	}
50*1da177e4SLinus Torvalds }
51*1da177e4SLinus Torvalds 
52*1da177e4SLinus Torvalds /*
53*1da177e4SLinus Torvalds  * Try to kill all DMA channels on the PSC. Not sure how this his
54*1da177e4SLinus Torvalds  * supposed to work; this is code lifted from macmace.c and then
55*1da177e4SLinus Torvalds  * expanded to cover what I think are the other 7 channels.
56*1da177e4SLinus Torvalds  */
57*1da177e4SLinus Torvalds 
58*1da177e4SLinus Torvalds void psc_dma_die_die_die(void)
59*1da177e4SLinus Torvalds {
60*1da177e4SLinus Torvalds 	int i;
61*1da177e4SLinus Torvalds 
62*1da177e4SLinus Torvalds 	printk("Killing all PSC DMA channels...");
63*1da177e4SLinus Torvalds 	for (i = 0 ; i < 9 ; i++) {
64*1da177e4SLinus Torvalds 		psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800);
65*1da177e4SLinus Torvalds 		psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000);
66*1da177e4SLinus Torvalds 		psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100);
67*1da177e4SLinus Torvalds 		psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100);
68*1da177e4SLinus Torvalds 	}
69*1da177e4SLinus Torvalds 	printk("done!\n");
70*1da177e4SLinus Torvalds }
71*1da177e4SLinus Torvalds 
72*1da177e4SLinus Torvalds /*
73*1da177e4SLinus Torvalds  * Initialize the PSC. For now this just involves shutting down all
74*1da177e4SLinus Torvalds  * interrupt sources using the IERs.
75*1da177e4SLinus Torvalds  */
76*1da177e4SLinus Torvalds 
77*1da177e4SLinus Torvalds void __init psc_init(void)
78*1da177e4SLinus Torvalds {
79*1da177e4SLinus Torvalds 	int i;
80*1da177e4SLinus Torvalds 
81*1da177e4SLinus Torvalds 	if (macintosh_config->ident != MAC_MODEL_C660
82*1da177e4SLinus Torvalds 	 && macintosh_config->ident != MAC_MODEL_Q840)
83*1da177e4SLinus Torvalds 	{
84*1da177e4SLinus Torvalds 		psc = NULL;
85*1da177e4SLinus Torvalds 		psc_present = 0;
86*1da177e4SLinus Torvalds 		return;
87*1da177e4SLinus Torvalds 	}
88*1da177e4SLinus Torvalds 
89*1da177e4SLinus Torvalds 	/*
90*1da177e4SLinus Torvalds 	 * The PSC is always at the same spot, but using psc
91*1da177e4SLinus Torvalds 	 * keeps things consisant with the psc_xxxx functions.
92*1da177e4SLinus Torvalds 	 */
93*1da177e4SLinus Torvalds 
94*1da177e4SLinus Torvalds 	psc = (void *) PSC_BASE;
95*1da177e4SLinus Torvalds 	psc_present = 1;
96*1da177e4SLinus Torvalds 
97*1da177e4SLinus Torvalds 	printk("PSC detected at %p\n", psc);
98*1da177e4SLinus Torvalds 
99*1da177e4SLinus Torvalds 	psc_dma_die_die_die();
100*1da177e4SLinus Torvalds 
101*1da177e4SLinus Torvalds #ifdef DEBUG_PSC
102*1da177e4SLinus Torvalds 	psc_debug_dump();
103*1da177e4SLinus Torvalds #endif
104*1da177e4SLinus Torvalds 	/*
105*1da177e4SLinus Torvalds 	 * Mask and clear all possible interrupts
106*1da177e4SLinus Torvalds 	 */
107*1da177e4SLinus Torvalds 
108*1da177e4SLinus Torvalds 	for (i = 0x30 ; i < 0x70 ; i += 0x10) {
109*1da177e4SLinus Torvalds 		psc_write_byte(pIERbase + i, 0x0F);
110*1da177e4SLinus Torvalds 		psc_write_byte(pIFRbase + i, 0x0F);
111*1da177e4SLinus Torvalds 	}
112*1da177e4SLinus Torvalds }
113*1da177e4SLinus Torvalds 
114*1da177e4SLinus Torvalds /*
115*1da177e4SLinus Torvalds  * Register the PSC interrupt dispatchers for autovector interrupts 3-6.
116*1da177e4SLinus Torvalds  */
117*1da177e4SLinus Torvalds 
118*1da177e4SLinus Torvalds void __init psc_register_interrupts(void)
119*1da177e4SLinus Torvalds {
120*1da177e4SLinus Torvalds 	cpu_request_irq(3, psc_irq, IRQ_FLG_LOCK, "psc3", (void *) 0x30);
121*1da177e4SLinus Torvalds 	cpu_request_irq(4, psc_irq, IRQ_FLG_LOCK, "psc4", (void *) 0x40);
122*1da177e4SLinus Torvalds 	cpu_request_irq(5, psc_irq, IRQ_FLG_LOCK, "psc5", (void *) 0x50);
123*1da177e4SLinus Torvalds 	cpu_request_irq(6, psc_irq, IRQ_FLG_LOCK, "psc6", (void *) 0x60);
124*1da177e4SLinus Torvalds }
125*1da177e4SLinus Torvalds 
126*1da177e4SLinus Torvalds /*
127*1da177e4SLinus Torvalds  * PSC interrupt handler. It's a lot like the VIA interrupt handler.
128*1da177e4SLinus Torvalds  */
129*1da177e4SLinus Torvalds 
130*1da177e4SLinus Torvalds irqreturn_t psc_irq(int irq, void *dev_id, struct pt_regs *regs)
131*1da177e4SLinus Torvalds {
132*1da177e4SLinus Torvalds 	int pIFR	= pIFRbase + ((int) dev_id);
133*1da177e4SLinus Torvalds 	int pIER	= pIERbase + ((int) dev_id);
134*1da177e4SLinus Torvalds 	int base_irq;
135*1da177e4SLinus Torvalds 	int irq_bit,i;
136*1da177e4SLinus Torvalds 	unsigned char events;
137*1da177e4SLinus Torvalds 
138*1da177e4SLinus Torvalds 	base_irq = irq << 3;
139*1da177e4SLinus Torvalds 
140*1da177e4SLinus Torvalds #ifdef DEBUG_IRQS
141*1da177e4SLinus Torvalds 	printk("psc_irq: irq %d pIFR = 0x%02X pIER = 0x%02X\n",
142*1da177e4SLinus Torvalds 		irq, (int) psc_read_byte(pIFR), (int) psc_read_byte(pIER));
143*1da177e4SLinus Torvalds #endif
144*1da177e4SLinus Torvalds 
145*1da177e4SLinus Torvalds 	events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF;
146*1da177e4SLinus Torvalds 	if (!events)
147*1da177e4SLinus Torvalds 		return IRQ_NONE;
148*1da177e4SLinus Torvalds 
149*1da177e4SLinus Torvalds 	for (i = 0, irq_bit = 1 ; i < 4 ; i++, irq_bit <<= 1) {
150*1da177e4SLinus Torvalds 	        if (events & irq_bit) {
151*1da177e4SLinus Torvalds 			psc_write_byte(pIER, irq_bit);
152*1da177e4SLinus Torvalds 			mac_do_irq_list(base_irq + i, regs);
153*1da177e4SLinus Torvalds 			psc_write_byte(pIFR, irq_bit);
154*1da177e4SLinus Torvalds 			psc_write_byte(pIER, irq_bit | 0x80);
155*1da177e4SLinus Torvalds 		}
156*1da177e4SLinus Torvalds 	}
157*1da177e4SLinus Torvalds 	return IRQ_HANDLED;
158*1da177e4SLinus Torvalds }
159*1da177e4SLinus Torvalds 
160*1da177e4SLinus Torvalds void psc_irq_enable(int irq) {
161*1da177e4SLinus Torvalds 	int irq_src	= IRQ_SRC(irq);
162*1da177e4SLinus Torvalds 	int irq_idx	= IRQ_IDX(irq);
163*1da177e4SLinus Torvalds 	int pIER	= pIERbase + (irq_src << 4);
164*1da177e4SLinus Torvalds 
165*1da177e4SLinus Torvalds #ifdef DEBUG_IRQUSE
166*1da177e4SLinus Torvalds 	printk("psc_irq_enable(%d)\n", irq);
167*1da177e4SLinus Torvalds #endif
168*1da177e4SLinus Torvalds 	psc_write_byte(pIER, (1 << irq_idx) | 0x80);
169*1da177e4SLinus Torvalds }
170*1da177e4SLinus Torvalds 
171*1da177e4SLinus Torvalds void psc_irq_disable(int irq) {
172*1da177e4SLinus Torvalds 	int irq_src	= IRQ_SRC(irq);
173*1da177e4SLinus Torvalds 	int irq_idx	= IRQ_IDX(irq);
174*1da177e4SLinus Torvalds 	int pIER	= pIERbase + (irq_src << 4);
175*1da177e4SLinus Torvalds 
176*1da177e4SLinus Torvalds #ifdef DEBUG_IRQUSE
177*1da177e4SLinus Torvalds 	printk("psc_irq_disable(%d)\n", irq);
178*1da177e4SLinus Torvalds #endif
179*1da177e4SLinus Torvalds 	psc_write_byte(pIER, 1 << irq_idx);
180*1da177e4SLinus Torvalds }
181*1da177e4SLinus Torvalds 
182*1da177e4SLinus Torvalds void psc_irq_clear(int irq) {
183*1da177e4SLinus Torvalds 	int irq_src	= IRQ_SRC(irq);
184*1da177e4SLinus Torvalds 	int irq_idx	= IRQ_IDX(irq);
185*1da177e4SLinus Torvalds 	int pIFR	= pIERbase + (irq_src << 4);
186*1da177e4SLinus Torvalds 
187*1da177e4SLinus Torvalds 	psc_write_byte(pIFR, 1 << irq_idx);
188*1da177e4SLinus Torvalds }
189*1da177e4SLinus Torvalds 
190*1da177e4SLinus Torvalds int psc_irq_pending(int irq)
191*1da177e4SLinus Torvalds {
192*1da177e4SLinus Torvalds 	int irq_src	= IRQ_SRC(irq);
193*1da177e4SLinus Torvalds 	int irq_idx	= IRQ_IDX(irq);
194*1da177e4SLinus Torvalds 	int pIFR	= pIERbase + (irq_src << 4);
195*1da177e4SLinus Torvalds 
196*1da177e4SLinus Torvalds 	return psc_read_byte(pIFR) & (1 << irq_idx);
197*1da177e4SLinus Torvalds }
198