blob: a4c3eb60706ebc8266fe4eeb377c36b30f0b8ba9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Apple Peripheral System Controller (PSC)
3 *
4 * The PSC is used on the AV Macs to control IO functions not handled
5 * by the VIAs (Ethernet, DSP, SCC).
6 *
7 * TO DO:
8 *
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?)
14 */
15
16#include <linux/types.h>
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/delay.h>
20#include <linux/init.h>
21
22#include <asm/traps.h>
23#include <asm/bootinfo.h>
24#include <asm/macintosh.h>
25#include <asm/macints.h>
26#include <asm/mac_psc.h>
27
28#define DEBUG_PSC
29
30int psc_present;
31volatile __u8 *psc;
32
Al Viro2850bc22006-10-07 14:16:45 +010033irqreturn_t psc_irq(int, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/*
36 * Debugging dump, used in various places to see what's going on.
37 */
38
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020039static void psc_debug_dump(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
41 int i;
42
43 if (!psc_present) return;
44 for (i = 0x30 ; i < 0x70 ; i += 0x10) {
45 printk("PSC #%d: IFR = 0x%02X IER = 0x%02X\n",
46 i >> 4,
47 (int) psc_read_byte(pIFRbase + i),
48 (int) psc_read_byte(pIERbase + i));
49 }
50}
51
52/*
53 * Try to kill all DMA channels on the PSC. Not sure how this his
54 * supposed to work; this is code lifted from macmace.c and then
55 * expanded to cover what I think are the other 7 channels.
56 */
57
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020058static void psc_dma_die_die_die(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 int i;
61
62 printk("Killing all PSC DMA channels...");
63 for (i = 0 ; i < 9 ; i++) {
64 psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800);
65 psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000);
66 psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100);
67 psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100);
68 }
69 printk("done!\n");
70}
71
72/*
73 * Initialize the PSC. For now this just involves shutting down all
74 * interrupt sources using the IERs.
75 */
76
77void __init psc_init(void)
78{
79 int i;
80
81 if (macintosh_config->ident != MAC_MODEL_C660
82 && macintosh_config->ident != MAC_MODEL_Q840)
83 {
84 psc = NULL;
85 psc_present = 0;
86 return;
87 }
88
89 /*
90 * The PSC is always at the same spot, but using psc
Uwe Kleine-Königa34f0b32010-12-10 14:55:42 +010091 * keeps things consistent with the psc_xxxx functions.
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 */
93
94 psc = (void *) PSC_BASE;
95 psc_present = 1;
96
97 printk("PSC detected at %p\n", psc);
98
99 psc_dma_die_die_die();
100
101#ifdef DEBUG_PSC
102 psc_debug_dump();
103#endif
104 /*
105 * Mask and clear all possible interrupts
106 */
107
108 for (i = 0x30 ; i < 0x70 ; i += 0x10) {
109 psc_write_byte(pIERbase + i, 0x0F);
110 psc_write_byte(pIFRbase + i, 0x0F);
111 }
112}
113
114/*
115 * Register the PSC interrupt dispatchers for autovector interrupts 3-6.
116 */
117
118void __init psc_register_interrupts(void)
119{
Geert Uytterhoeven92c3dd12008-12-30 14:02:27 +0100120 if (request_irq(IRQ_AUTO_3, psc_irq, 0, "psc3", (void *) 0x30))
121 pr_err("Couldn't register psc%d interrupt\n", 3);
122 if (request_irq(IRQ_AUTO_4, psc_irq, 0, "psc4", (void *) 0x40))
123 pr_err("Couldn't register psc%d interrupt\n", 4);
124 if (request_irq(IRQ_AUTO_5, psc_irq, 0, "psc5", (void *) 0x50))
125 pr_err("Couldn't register psc%d interrupt\n", 5);
126 if (request_irq(IRQ_AUTO_6, psc_irq, 0, "psc6", (void *) 0x60))
127 pr_err("Couldn't register psc%d interrupt\n", 6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
130/*
131 * PSC interrupt handler. It's a lot like the VIA interrupt handler.
132 */
133
Al Viro2850bc22006-10-07 14:16:45 +0100134irqreturn_t psc_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 int pIFR = pIFRbase + ((int) dev_id);
137 int pIER = pIERbase + ((int) dev_id);
Finn Thain67dfb152007-05-01 22:32:56 +0200138 int irq_num;
139 unsigned char irq_bit, events;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141#ifdef DEBUG_IRQS
142 printk("psc_irq: irq %d pIFR = 0x%02X pIER = 0x%02X\n",
143 irq, (int) psc_read_byte(pIFR), (int) psc_read_byte(pIER));
144#endif
145
146 events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF;
147 if (!events)
148 return IRQ_NONE;
149
Finn Thain67dfb152007-05-01 22:32:56 +0200150 irq_num = irq << 3;
151 irq_bit = 1;
152 do {
153 if (events & irq_bit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 psc_write_byte(pIFR, irq_bit);
Finn Thain67dfb152007-05-01 22:32:56 +0200155 m68k_handle_int(irq_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
Finn Thain67dfb152007-05-01 22:32:56 +0200157 irq_num++;
158 irq_bit <<= 1;
159 } while (events >= irq_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return IRQ_HANDLED;
161}
162
163void psc_irq_enable(int irq) {
164 int irq_src = IRQ_SRC(irq);
165 int irq_idx = IRQ_IDX(irq);
166 int pIER = pIERbase + (irq_src << 4);
167
168#ifdef DEBUG_IRQUSE
169 printk("psc_irq_enable(%d)\n", irq);
170#endif
171 psc_write_byte(pIER, (1 << irq_idx) | 0x80);
172}
173
174void psc_irq_disable(int irq) {
175 int irq_src = IRQ_SRC(irq);
176 int irq_idx = IRQ_IDX(irq);
177 int pIER = pIERbase + (irq_src << 4);
178
179#ifdef DEBUG_IRQUSE
180 printk("psc_irq_disable(%d)\n", irq);
181#endif
182 psc_write_byte(pIER, 1 << irq_idx);
183}
184
185void psc_irq_clear(int irq) {
186 int irq_src = IRQ_SRC(irq);
187 int irq_idx = IRQ_IDX(irq);
188 int pIFR = pIERbase + (irq_src << 4);
189
190 psc_write_byte(pIFR, 1 << irq_idx);
191}
192
193int psc_irq_pending(int irq)
194{
195 int irq_src = IRQ_SRC(irq);
196 int irq_idx = IRQ_IDX(irq);
197 int pIFR = pIERbase + (irq_src << 4);
198
199 return psc_read_byte(pIFR) & (1 << irq_idx);
200}