blob: 1eb60f071007836eedae38304af9067a4b3e6b15 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * OSS handling
3 * Written by Joshua M. Thompson (funaho@jurai.org)
4 *
5 *
6 * This chip is used in the IIfx in place of VIA #2. It acts like a fancy
7 * VIA chip with prorammable interrupt levels.
8 *
9 * 990502 (jmt) - Major rewrite for new interrupt architecture as well as some
10 * recent insights into OSS operational details.
Simon Arlott0c79cf62007-10-20 01:20:32 +020011 * 990610 (jmt) - Now taking full advantage of the OSS. Interrupts are mapped
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * to mostly match the A/UX interrupt scheme supported on the
13 * VIA side. Also added support for enabling the ISM irq again
14 * since we now have a functional IOP manager.
15 */
16
17#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/mm.h>
20#include <linux/delay.h>
21#include <linux/init.h>
22
23#include <asm/bootinfo.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/macintosh.h>
25#include <asm/macints.h>
26#include <asm/mac_via.h>
27#include <asm/mac_oss.h>
28
29int oss_present;
30volatile struct mac_oss *oss;
31
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020032static irqreturn_t oss_irq(int, void *);
33static irqreturn_t oss_nubus_irq(int, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Al Viro2850bc22006-10-07 14:16:45 +010035extern irqreturn_t via1_irq(int, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/*
38 * Initialize the OSS
39 *
40 * The OSS "detection" code is actually in via_init() which is always called
41 * before us. Thus we can count on oss_present being valid on entry.
42 */
43
44void __init oss_init(void)
45{
46 int i;
47
48 if (!oss_present) return;
49
50 oss = (struct mac_oss *) OSS_BASE;
51
52 /* Disable all interrupts. Unlike a VIA it looks like we */
53 /* do this by setting the source's interrupt level to zero. */
54
55 for (i = 0; i <= OSS_NUM_SOURCES; i++) {
56 oss->irq_level[i] = OSS_IRQLEV_DISABLED;
57 }
58 /* If we disable VIA1 here, we never really handle it... */
59 oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1;
60}
61
62/*
63 * Register the OSS and NuBus interrupt dispatchers.
64 */
65
66void __init oss_register_interrupts(void)
67{
Geert Uytterhoeven5a239452011-07-13 22:33:13 +020068 if (request_irq(OSS_IRQLEV_SCSI, oss_irq, 0, "scsi", (void *)oss))
Geert Uytterhoeven92c3dd12008-12-30 14:02:27 +010069 pr_err("Couldn't register %s interrupt\n", "scsi");
Geert Uytterhoeven5a239452011-07-13 22:33:13 +020070 if (request_irq(OSS_IRQLEV_NUBUS, oss_nubus_irq, 0, "nubus",
71 (void *)oss))
Geert Uytterhoeven92c3dd12008-12-30 14:02:27 +010072 pr_err("Couldn't register %s interrupt\n", "nubus");
Geert Uytterhoeven5a239452011-07-13 22:33:13 +020073 if (request_irq(OSS_IRQLEV_SOUND, oss_irq, 0, "sound", (void *)oss))
Geert Uytterhoeven92c3dd12008-12-30 14:02:27 +010074 pr_err("Couldn't register %s interrupt\n", "sound");
Geert Uytterhoeven5a239452011-07-13 22:33:13 +020075 if (request_irq(OSS_IRQLEV_VIA1, via1_irq, 0, "via1", (void *)via1))
Geert Uytterhoeven92c3dd12008-12-30 14:02:27 +010076 pr_err("Couldn't register %s interrupt\n", "via1");
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
79/*
80 * Initialize OSS for Nubus access
81 */
82
83void __init oss_nubus_init(void)
84{
85}
86
87/*
88 * Handle miscellaneous OSS interrupts. Right now that's just sound
89 * and SCSI; everything else is routed to its own autovector IRQ.
90 */
91
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020092static irqreturn_t oss_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 int events;
95
96 events = oss->irq_pending & (OSS_IP_SOUND|OSS_IP_SCSI);
97 if (!events)
98 return IRQ_NONE;
99
100#ifdef DEBUG_IRQS
101 if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) {
102 printk("oss_irq: irq %d events = 0x%04X\n", irq,
103 (int) oss->irq_pending);
104 }
105#endif
106 /* FIXME: how do you clear a pending IRQ? */
107
108 if (events & OSS_IP_SOUND) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 oss->irq_pending &= ~OSS_IP_SOUND;
Finn Thain647b8042007-05-01 22:32:55 +0200110 /* FIXME: call sound handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 } else if (events & OSS_IP_SCSI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 oss->irq_pending &= ~OSS_IP_SCSI;
Geert Uytterhoeven1425df82011-07-01 20:39:19 +0200113 generic_handle_irq(IRQ_MAC_SCSI);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 } else {
115 /* FIXME: error check here? */
116 }
117 return IRQ_HANDLED;
118}
119
120/*
121 * Nubus IRQ handler, OSS style
122 *
123 * Unlike the VIA/RBV this is on its own autovector interrupt level.
124 */
125
Adrian Bunk8dfbdf42008-07-17 21:16:25 +0200126static irqreturn_t oss_nubus_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
128 int events, irq_bit, i;
129
130 events = oss->irq_pending & OSS_IP_NUBUS;
131 if (!events)
132 return IRQ_NONE;
133
134#ifdef DEBUG_NUBUS_INT
135 if (console_loglevel > 7) {
136 printk("oss_nubus_irq: events = 0x%04X\n", events);
137 }
138#endif
139 /* There are only six slots on the OSS, not seven */
140
Finn Thain67dfb152007-05-01 22:32:56 +0200141 i = 6;
142 irq_bit = 0x40;
143 do {
144 --i;
145 irq_bit >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 if (events & irq_bit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 oss->irq_pending &= ~irq_bit;
Geert Uytterhoeven1425df82011-07-01 20:39:19 +0200148 generic_handle_irq(NUBUS_SOURCE_BASE + i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 }
Finn Thain67dfb152007-05-01 22:32:56 +0200150 } while(events & (irq_bit - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 return IRQ_HANDLED;
152}
153
154/*
155 * Enable an OSS interrupt
156 *
157 * It looks messy but it's rather straightforward. The switch() statement
158 * just maps the machspec interrupt numbers to the right OSS interrupt
159 * source (if the OSS handles that interrupt) and then sets the interrupt
160 * level for that source to nonzero, thus enabling the interrupt.
161 */
162
163void oss_irq_enable(int irq) {
164#ifdef DEBUG_IRQUSE
165 printk("oss_irq_enable(%d)\n", irq);
166#endif
167 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100168 case IRQ_MAC_SCC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
170 break;
171 case IRQ_MAC_ADB:
172 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
173 break;
174 case IRQ_MAC_SCSI:
175 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
176 break;
177 case IRQ_NUBUS_9:
178 case IRQ_NUBUS_A:
179 case IRQ_NUBUS_B:
180 case IRQ_NUBUS_C:
181 case IRQ_NUBUS_D:
182 case IRQ_NUBUS_E:
183 irq -= NUBUS_SOURCE_BASE;
184 oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
185 break;
186#ifdef DEBUG_IRQUSE
187 default:
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700188 printk("%s unknown irq %d\n", __func__, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 break;
190#endif
191 }
192}
193
194/*
195 * Disable an OSS interrupt
196 *
197 * Same as above except we set the source's interrupt level to zero,
198 * to disable the interrupt.
199 */
200
201void oss_irq_disable(int irq) {
202#ifdef DEBUG_IRQUSE
203 printk("oss_irq_disable(%d)\n", irq);
204#endif
205 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100206 case IRQ_MAC_SCC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_DISABLED;
208 break;
209 case IRQ_MAC_ADB:
210 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_DISABLED;
211 break;
212 case IRQ_MAC_SCSI:
213 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_DISABLED;
214 break;
215 case IRQ_NUBUS_9:
216 case IRQ_NUBUS_A:
217 case IRQ_NUBUS_B:
218 case IRQ_NUBUS_C:
219 case IRQ_NUBUS_D:
220 case IRQ_NUBUS_E:
221 irq -= NUBUS_SOURCE_BASE;
222 oss->irq_level[irq] = OSS_IRQLEV_DISABLED;
223 break;
224#ifdef DEBUG_IRQUSE
225 default:
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700226 printk("%s unknown irq %d\n", __func__, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 break;
228#endif
229 }
230}
231
232/*
233 * Clear an OSS interrupt
234 *
235 * Not sure if this works or not but it's the only method I could
236 * think of based on the contents of the mac_oss structure.
237 */
238
239void oss_irq_clear(int irq) {
240 /* FIXME: how to do this on OSS? */
241 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100242 case IRQ_MAC_SCC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 oss->irq_pending &= ~OSS_IP_IOPSCC;
244 break;
245 case IRQ_MAC_ADB:
246 oss->irq_pending &= ~OSS_IP_IOPISM;
247 break;
248 case IRQ_MAC_SCSI:
249 oss->irq_pending &= ~OSS_IP_SCSI;
250 break;
251 case IRQ_NUBUS_9:
252 case IRQ_NUBUS_A:
253 case IRQ_NUBUS_B:
254 case IRQ_NUBUS_C:
255 case IRQ_NUBUS_D:
256 case IRQ_NUBUS_E:
257 irq -= NUBUS_SOURCE_BASE;
258 oss->irq_pending &= ~(1 << irq);
259 break;
260 }
261}
262
263/*
264 * Check to see if a specific OSS interrupt is pending
265 */
266
267int oss_irq_pending(int irq)
268{
269 switch(irq) {
Finn Thain80614e52009-11-17 20:06:48 +1100270 case IRQ_MAC_SCC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 return oss->irq_pending & OSS_IP_IOPSCC;
272 break;
273 case IRQ_MAC_ADB:
274 return oss->irq_pending & OSS_IP_IOPISM;
275 break;
276 case IRQ_MAC_SCSI:
277 return oss->irq_pending & OSS_IP_SCSI;
278 break;
279 case IRQ_NUBUS_9:
280 case IRQ_NUBUS_A:
281 case IRQ_NUBUS_B:
282 case IRQ_NUBUS_C:
283 case IRQ_NUBUS_D:
284 case IRQ_NUBUS_E:
285 irq -= NUBUS_SOURCE_BASE;
286 return oss->irq_pending & (1 << irq);
287 break;
288 }
289 return 0;
290}