blob: 0a34b7afc376450fbe94865f0535798814858d55 [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>
Geert Uytterhoevenddc7fd22011-07-13 21:48:30 +020021#ifdef CONFIG_GENERIC_HARDIRQS
22#include <linux/irq.h>
23#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
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>
30
31#define DEBUG_PSC
32
33int psc_present;
34volatile __u8 *psc;
35
Al Viro2850bc22006-10-07 14:16:45 +010036irqreturn_t psc_irq(int, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38/*
39 * Debugging dump, used in various places to see what's going on.
40 */
41
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020042static void psc_debug_dump(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 int i;
45
46 if (!psc_present) return;
47 for (i = 0x30 ; i < 0x70 ; i += 0x10) {
48 printk("PSC #%d: IFR = 0x%02X IER = 0x%02X\n",
49 i >> 4,
50 (int) psc_read_byte(pIFRbase + i),
51 (int) psc_read_byte(pIERbase + i));
52 }
53}
54
55/*
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.
59 */
60
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020061static void psc_dma_die_die_die(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
63 int i;
64
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);
71 }
72 printk("done!\n");
73}
74
75/*
76 * Initialize the PSC. For now this just involves shutting down all
77 * interrupt sources using the IERs.
78 */
79
80void __init psc_init(void)
81{
82 int i;
83
84 if (macintosh_config->ident != MAC_MODEL_C660
85 && macintosh_config->ident != MAC_MODEL_Q840)
86 {
87 psc = NULL;
88 psc_present = 0;
89 return;
90 }
91
92 /*
93 * The PSC is always at the same spot, but using psc
Uwe Kleine-Königa34f0b32010-12-10 14:55:42 +010094 * keeps things consistent with the psc_xxxx functions.
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 */
96
97 psc = (void *) PSC_BASE;
98 psc_present = 1;
99
100 printk("PSC detected at %p\n", psc);
101
102 psc_dma_die_die_die();
103
104#ifdef DEBUG_PSC
105 psc_debug_dump();
106#endif
107 /*
108 * Mask and clear all possible interrupts
109 */
110
111 for (i = 0x30 ; i < 0x70 ; i += 0x10) {
112 psc_write_byte(pIERbase + i, 0x0F);
113 psc_write_byte(pIFRbase + i, 0x0F);
114 }
115}
116
117/*
118 * Register the PSC interrupt dispatchers for autovector interrupts 3-6.
119 */
120
121void __init psc_register_interrupts(void)
122{
Geert Uytterhoeven92c3dd12008-12-30 14:02:27 +0100123 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133/*
134 * PSC interrupt handler. It's a lot like the VIA interrupt handler.
135 */
136
Al Viro2850bc22006-10-07 14:16:45 +0100137irqreturn_t psc_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 int pIFR = pIFRbase + ((int) dev_id);
140 int pIER = pIERbase + ((int) dev_id);
Finn Thain67dfb152007-05-01 22:32:56 +0200141 int irq_num;
142 unsigned char irq_bit, events;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144#ifdef DEBUG_IRQS
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));
147#endif
148
149 events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF;
150 if (!events)
151 return IRQ_NONE;
152
Finn Thain67dfb152007-05-01 22:32:56 +0200153 irq_num = irq << 3;
154 irq_bit = 1;
155 do {
156 if (events & irq_bit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 psc_write_byte(pIFR, irq_bit);
Geert Uytterhoeven1425df82011-07-01 20:39:19 +0200158 generic_handle_irq(irq_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
Finn Thain67dfb152007-05-01 22:32:56 +0200160 irq_num++;
161 irq_bit <<= 1;
162 } while (events >= irq_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return IRQ_HANDLED;
164}
165
166void 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);
170
171#ifdef DEBUG_IRQUSE
172 printk("psc_irq_enable(%d)\n", irq);
173#endif
174 psc_write_byte(pIER, (1 << irq_idx) | 0x80);
175}
176
177void 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);
181
182#ifdef DEBUG_IRQUSE
183 printk("psc_irq_disable(%d)\n", irq);
184#endif
185 psc_write_byte(pIER, 1 << irq_idx);
186}
187
188void 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);
192
193 psc_write_byte(pIFR, 1 << irq_idx);
194}
195
196int psc_irq_pending(int irq)
197{
198 int irq_src = IRQ_SRC(irq);
199 int irq_idx = IRQ_IDX(irq);
200 int pIFR = pIERbase + (irq_src << 4);
201
202 return psc_read_byte(pIFR) & (1 << irq_idx);
203}