3 * Written by Joshua M. Thompson (funaho@jurai.org)
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.
9 * 990502 (jmt) - Major rewrite for new interrupt architecture as well as some
10 * recent insights into OSS operational details.
11 * 990610 (jmt) - Now taking full advantage of the OSS. Interrupts are mapped
12 * 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.
17 #include <linux/types.h>
18 #include <linux/kernel.h>
20 #include <linux/delay.h>
21 #include <linux/init.h>
22 #ifdef CONFIG_GENERIC_HARDIRQS
23 #include <linux/irq.h>
26 #include <asm/bootinfo.h>
27 #include <asm/macintosh.h>
28 #include <asm/macints.h>
29 #include <asm/mac_via.h>
30 #include <asm/mac_oss.h>
33 volatile struct mac_oss *oss;
35 #ifdef CONFIG_GENERIC_HARDIRQS
36 extern void via1_irq(unsigned int irq, struct irq_desc *desc);
38 extern irqreturn_t via1_irq(int, void *);
44 * The OSS "detection" code is actually in via_init() which is always called
45 * before us. Thus we can count on oss_present being valid on entry.
48 void __init oss_init(void)
52 if (!oss_present) return;
54 oss = (struct mac_oss *) OSS_BASE;
56 /* Disable all interrupts. Unlike a VIA it looks like we */
57 /* do this by setting the source's interrupt level to zero. */
59 for (i = 0; i <= OSS_NUM_SOURCES; i++) {
60 oss->irq_level[i] = OSS_IRQLEV_DISABLED;
62 /* If we disable VIA1 here, we never really handle it... */
63 oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1;
67 * Initialize OSS for Nubus access
70 void __init oss_nubus_init(void)
75 * Handle miscellaneous OSS interrupts. Right now that's just sound
76 * and SCSI; everything else is routed to its own autovector IRQ.
79 #ifdef CONFIG_GENERIC_HARDIRQS
80 static void oss_irq(unsigned int irq, struct irq_desc *desc)
84 events = oss->irq_pending & (OSS_IP_SOUND|OSS_IP_SCSI);
89 if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) {
90 printk("oss_irq: irq %u events = 0x%04X\n", irq,
91 (int) oss->irq_pending);
94 /* FIXME: how do you clear a pending IRQ? */
96 if (events & OSS_IP_SOUND) {
97 oss->irq_pending &= ~OSS_IP_SOUND;
98 /* FIXME: call sound handler */
99 } else if (events & OSS_IP_SCSI) {
100 oss->irq_pending &= ~OSS_IP_SCSI;
101 generic_handle_irq(IRQ_MAC_SCSI);
103 /* FIXME: error check here? */
107 static irqreturn_t oss_irq(int irq, void *dev_id)
111 events = oss->irq_pending & (OSS_IP_SOUND|OSS_IP_SCSI);
116 if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) {
117 printk("oss_irq: irq %d events = 0x%04X\n", irq,
118 (int) oss->irq_pending);
121 /* FIXME: how do you clear a pending IRQ? */
123 if (events & OSS_IP_SOUND) {
124 oss->irq_pending &= ~OSS_IP_SOUND;
125 /* FIXME: call sound handler */
126 } else if (events & OSS_IP_SCSI) {
127 oss->irq_pending &= ~OSS_IP_SCSI;
128 generic_handle_irq(IRQ_MAC_SCSI);
130 /* FIXME: error check here? */
137 * Nubus IRQ handler, OSS style
139 * Unlike the VIA/RBV this is on its own autovector interrupt level.
142 #ifdef CONFIG_GENERIC_HARDIRQS
143 static void oss_nubus_irq(unsigned int irq, struct irq_desc *desc)
145 int events, irq_bit, i;
147 events = oss->irq_pending & OSS_IP_NUBUS;
151 #ifdef DEBUG_NUBUS_INT
152 if (console_loglevel > 7) {
153 printk("oss_nubus_irq: events = 0x%04X\n", events);
156 /* There are only six slots on the OSS, not seven */
163 if (events & irq_bit) {
164 oss->irq_pending &= ~irq_bit;
165 generic_handle_irq(NUBUS_SOURCE_BASE + i);
167 } while(events & (irq_bit - 1));
170 static irqreturn_t oss_nubus_irq(int irq, void *dev_id)
172 int events, irq_bit, i;
174 events = oss->irq_pending & OSS_IP_NUBUS;
178 #ifdef DEBUG_NUBUS_INT
179 if (console_loglevel > 7) {
180 printk("oss_nubus_irq: events = 0x%04X\n", events);
183 /* There are only six slots on the OSS, not seven */
190 if (events & irq_bit) {
191 oss->irq_pending &= ~irq_bit;
192 generic_handle_irq(NUBUS_SOURCE_BASE + i);
194 } while(events & (irq_bit - 1));
200 * Register the OSS and NuBus interrupt dispatchers.
203 void __init oss_register_interrupts(void)
205 #ifdef CONFIG_GENERIC_HARDIRQS
206 irq_set_chained_handler(OSS_IRQLEV_SCSI, oss_irq);
207 irq_set_chained_handler(OSS_IRQLEV_NUBUS, oss_nubus_irq);
208 irq_set_chained_handler(OSS_IRQLEV_SOUND, oss_irq);
209 irq_set_chained_handler(OSS_IRQLEV_VIA1, via1_irq);
210 #else /* !CONFIG_GENERIC_HARDIRQS */
211 if (request_irq(OSS_IRQLEV_SCSI, oss_irq, 0, "scsi", (void *)oss))
212 pr_err("Couldn't register %s interrupt\n", "scsi");
213 if (request_irq(OSS_IRQLEV_NUBUS, oss_nubus_irq, 0, "nubus",
215 pr_err("Couldn't register %s interrupt\n", "nubus");
216 if (request_irq(OSS_IRQLEV_SOUND, oss_irq, 0, "sound", (void *)oss))
217 pr_err("Couldn't register %s interrupt\n", "sound");
218 if (request_irq(OSS_IRQLEV_VIA1, via1_irq, 0, "via1", (void *)via1))
219 pr_err("Couldn't register %s interrupt\n", "via1");
220 #endif /* !CONFIG_GENERIC_HARDIRQS */
224 * Enable an OSS interrupt
226 * It looks messy but it's rather straightforward. The switch() statement
227 * just maps the machspec interrupt numbers to the right OSS interrupt
228 * source (if the OSS handles that interrupt) and then sets the interrupt
229 * level for that source to nonzero, thus enabling the interrupt.
232 void oss_irq_enable(int irq) {
234 printk("oss_irq_enable(%d)\n", irq);
238 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
241 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
244 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
252 irq -= NUBUS_SOURCE_BASE;
253 oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
257 printk("%s unknown irq %d\n", __func__, irq);
264 * Disable an OSS interrupt
266 * Same as above except we set the source's interrupt level to zero,
267 * to disable the interrupt.
270 void oss_irq_disable(int irq) {
272 printk("oss_irq_disable(%d)\n", irq);
276 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_DISABLED;
279 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_DISABLED;
282 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_DISABLED;
290 irq -= NUBUS_SOURCE_BASE;
291 oss->irq_level[irq] = OSS_IRQLEV_DISABLED;
295 printk("%s unknown irq %d\n", __func__, irq);
302 * Clear an OSS interrupt
304 * Not sure if this works or not but it's the only method I could
305 * think of based on the contents of the mac_oss structure.
308 void oss_irq_clear(int irq) {
309 /* FIXME: how to do this on OSS? */
312 oss->irq_pending &= ~OSS_IP_IOPSCC;
315 oss->irq_pending &= ~OSS_IP_IOPISM;
318 oss->irq_pending &= ~OSS_IP_SCSI;
326 irq -= NUBUS_SOURCE_BASE;
327 oss->irq_pending &= ~(1 << irq);
333 * Check to see if a specific OSS interrupt is pending
336 int oss_irq_pending(int irq)
340 return oss->irq_pending & OSS_IP_IOPSCC;
343 return oss->irq_pending & OSS_IP_IOPISM;
346 return oss->irq_pending & OSS_IP_SCSI;
354 irq -= NUBUS_SOURCE_BASE;
355 return oss->irq_pending & (1 << irq);