2 * Apple Peripheral System Controller (PSC)
4 * The PSC is used on the AV Macs to control IO functions not handled
5 * by the VIAs (Ethernet, DSP, SCC).
9 * Try to figure out what's going on in pIFR5 and pIFR6. There seem to be
10 * persisant interrupt conditions in those registers and I have no idea what
11 * they are. Granted it doesn't affect since we're not enabling any interrupts
12 * on those levels at the moment, but it would be nice to know. I have a feeling
13 * they aren't actually interrupt lines but data lines (to the DSP?)
16 #include <linux/types.h>
17 #include <linux/kernel.h>
19 #include <linux/delay.h>
20 #include <linux/init.h>
21 #ifdef CONFIG_GENERIC_HARDIRQS
22 #include <linux/irq.h>
25 #include <asm/traps.h>
26 #include <asm/bootinfo.h>
27 #include <asm/macintosh.h>
28 #include <asm/macints.h>
29 #include <asm/mac_psc.h>
36 irqreturn_t psc_irq(int, void *);
39 * Debugging dump, used in various places to see what's going on.
42 static void psc_debug_dump(void)
46 if (!psc_present) return;
47 for (i = 0x30 ; i < 0x70 ; i += 0x10) {
48 printk("PSC #%d: IFR = 0x%02X IER = 0x%02X\n",
50 (int) psc_read_byte(pIFRbase + i),
51 (int) psc_read_byte(pIERbase + i));
56 * Try to kill all DMA channels on the PSC. Not sure how this his
57 * supposed to work; this is code lifted from macmace.c and then
58 * expanded to cover what I think are the other 7 channels.
61 static void psc_dma_die_die_die(void)
65 printk("Killing all PSC DMA channels...");
66 for (i = 0 ; i < 9 ; i++) {
67 psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800);
68 psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000);
69 psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100);
70 psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100);
76 * Initialize the PSC. For now this just involves shutting down all
77 * interrupt sources using the IERs.
80 void __init psc_init(void)
84 if (macintosh_config->ident != MAC_MODEL_C660
85 && macintosh_config->ident != MAC_MODEL_Q840)
93 * The PSC is always at the same spot, but using psc
94 * keeps things consistent with the psc_xxxx functions.
97 psc = (void *) PSC_BASE;
100 printk("PSC detected at %p\n", psc);
102 psc_dma_die_die_die();
108 * Mask and clear all possible interrupts
111 for (i = 0x30 ; i < 0x70 ; i += 0x10) {
112 psc_write_byte(pIERbase + i, 0x0F);
113 psc_write_byte(pIFRbase + i, 0x0F);
118 * Register the PSC interrupt dispatchers for autovector interrupts 3-6.
121 void __init psc_register_interrupts(void)
123 if (request_irq(IRQ_AUTO_3, psc_irq, 0, "psc3", (void *) 0x30))
124 pr_err("Couldn't register psc%d interrupt\n", 3);
125 if (request_irq(IRQ_AUTO_4, psc_irq, 0, "psc4", (void *) 0x40))
126 pr_err("Couldn't register psc%d interrupt\n", 4);
127 if (request_irq(IRQ_AUTO_5, psc_irq, 0, "psc5", (void *) 0x50))
128 pr_err("Couldn't register psc%d interrupt\n", 5);
129 if (request_irq(IRQ_AUTO_6, psc_irq, 0, "psc6", (void *) 0x60))
130 pr_err("Couldn't register psc%d interrupt\n", 6);
134 * PSC interrupt handler. It's a lot like the VIA interrupt handler.
137 irqreturn_t psc_irq(int irq, void *dev_id)
139 int pIFR = pIFRbase + ((int) dev_id);
140 int pIER = pIERbase + ((int) dev_id);
142 unsigned char irq_bit, events;
145 printk("psc_irq: irq %d pIFR = 0x%02X pIER = 0x%02X\n",
146 irq, (int) psc_read_byte(pIFR), (int) psc_read_byte(pIER));
149 events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF;
156 if (events & irq_bit) {
157 psc_write_byte(pIFR, irq_bit);
158 generic_handle_irq(irq_num);
162 } while (events >= irq_bit);
166 void psc_irq_enable(int irq) {
167 int irq_src = IRQ_SRC(irq);
168 int irq_idx = IRQ_IDX(irq);
169 int pIER = pIERbase + (irq_src << 4);
172 printk("psc_irq_enable(%d)\n", irq);
174 psc_write_byte(pIER, (1 << irq_idx) | 0x80);
177 void psc_irq_disable(int irq) {
178 int irq_src = IRQ_SRC(irq);
179 int irq_idx = IRQ_IDX(irq);
180 int pIER = pIERbase + (irq_src << 4);
183 printk("psc_irq_disable(%d)\n", irq);
185 psc_write_byte(pIER, 1 << irq_idx);
188 void psc_irq_clear(int irq) {
189 int irq_src = IRQ_SRC(irq);
190 int irq_idx = IRQ_IDX(irq);
191 int pIFR = pIERbase + (irq_src << 4);
193 psc_write_byte(pIFR, 1 << irq_idx);
196 int psc_irq_pending(int irq)
198 int irq_src = IRQ_SRC(irq);
199 int irq_idx = IRQ_IDX(irq);
200 int pIFR = pIERbase + (irq_src << 4);
202 return psc_read_byte(pIFR) & (1 << irq_idx);