blob: 8426501119ca82bf641b3098c4a726d696cc26bb [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 *);
36extern irqreturn_t mac_scc_dispatch(int, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38/*
39 * Initialize the OSS
40 *
41 * The OSS "detection" code is actually in via_init() which is always called
42 * before us. Thus we can count on oss_present being valid on entry.
43 */
44
45void __init oss_init(void)
46{
47 int i;
48
49 if (!oss_present) return;
50
51 oss = (struct mac_oss *) OSS_BASE;
52
53 /* Disable all interrupts. Unlike a VIA it looks like we */
54 /* do this by setting the source's interrupt level to zero. */
55
56 for (i = 0; i <= OSS_NUM_SOURCES; i++) {
57 oss->irq_level[i] = OSS_IRQLEV_DISABLED;
58 }
59 /* If we disable VIA1 here, we never really handle it... */
60 oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1;
61}
62
63/*
64 * Register the OSS and NuBus interrupt dispatchers.
65 */
66
67void __init oss_register_interrupts(void)
68{
Roman Zippel9c5f4af2006-06-25 05:47:04 -070069 request_irq(OSS_IRQLEV_SCSI, oss_irq, IRQ_FLG_LOCK,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 "scsi", (void *) oss);
Roman Zippel9c5f4af2006-06-25 05:47:04 -070071 request_irq(OSS_IRQLEV_IOPSCC, mac_scc_dispatch, IRQ_FLG_LOCK,
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 "scc", mac_scc_dispatch);
Roman Zippel9c5f4af2006-06-25 05:47:04 -070073 request_irq(OSS_IRQLEV_NUBUS, oss_nubus_irq, IRQ_FLG_LOCK,
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 "nubus", (void *) oss);
Roman Zippel9c5f4af2006-06-25 05:47:04 -070075 request_irq(OSS_IRQLEV_SOUND, oss_irq, IRQ_FLG_LOCK,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 "sound", (void *) oss);
Roman Zippel9c5f4af2006-06-25 05:47:04 -070077 request_irq(OSS_IRQLEV_VIA1, via1_irq, IRQ_FLG_LOCK,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 "via1", (void *) via1);
79}
80
81/*
82 * Initialize OSS for Nubus access
83 */
84
85void __init oss_nubus_init(void)
86{
87}
88
89/*
90 * Handle miscellaneous OSS interrupts. Right now that's just sound
91 * and SCSI; everything else is routed to its own autovector IRQ.
92 */
93
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020094static irqreturn_t oss_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
96 int events;
97
98 events = oss->irq_pending & (OSS_IP_SOUND|OSS_IP_SCSI);
99 if (!events)
100 return IRQ_NONE;
101
102#ifdef DEBUG_IRQS
103 if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) {
104 printk("oss_irq: irq %d events = 0x%04X\n", irq,
105 (int) oss->irq_pending);
106 }
107#endif
108 /* FIXME: how do you clear a pending IRQ? */
109
110 if (events & OSS_IP_SOUND) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 oss->irq_pending &= ~OSS_IP_SOUND;
Finn Thain647b8042007-05-01 22:32:55 +0200112 /* FIXME: call sound handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 } else if (events & OSS_IP_SCSI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 oss->irq_pending &= ~OSS_IP_SCSI;
Finn Thain647b8042007-05-01 22:32:55 +0200115 m68k_handle_int(IRQ_MAC_SCSI);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 } else {
117 /* FIXME: error check here? */
118 }
119 return IRQ_HANDLED;
120}
121
122/*
123 * Nubus IRQ handler, OSS style
124 *
125 * Unlike the VIA/RBV this is on its own autovector interrupt level.
126 */
127
Adrian Bunk8dfbdf42008-07-17 21:16:25 +0200128static irqreturn_t oss_nubus_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 int events, irq_bit, i;
131
132 events = oss->irq_pending & OSS_IP_NUBUS;
133 if (!events)
134 return IRQ_NONE;
135
136#ifdef DEBUG_NUBUS_INT
137 if (console_loglevel > 7) {
138 printk("oss_nubus_irq: events = 0x%04X\n", events);
139 }
140#endif
141 /* There are only six slots on the OSS, not seven */
142
Finn Thain67dfb152007-05-01 22:32:56 +0200143 i = 6;
144 irq_bit = 0x40;
145 do {
146 --i;
147 irq_bit >>= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 if (events & irq_bit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 oss->irq_pending &= ~irq_bit;
Finn Thain647b8042007-05-01 22:32:55 +0200150 m68k_handle_int(NUBUS_SOURCE_BASE + i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
Finn Thain67dfb152007-05-01 22:32:56 +0200152 } while(events & (irq_bit - 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return IRQ_HANDLED;
154}
155
156/*
157 * Enable an OSS interrupt
158 *
159 * It looks messy but it's rather straightforward. The switch() statement
160 * just maps the machspec interrupt numbers to the right OSS interrupt
161 * source (if the OSS handles that interrupt) and then sets the interrupt
162 * level for that source to nonzero, thus enabling the interrupt.
163 */
164
165void oss_irq_enable(int irq) {
166#ifdef DEBUG_IRQUSE
167 printk("oss_irq_enable(%d)\n", irq);
168#endif
169 switch(irq) {
170 case IRQ_SCC:
171 case IRQ_SCCA:
172 case IRQ_SCCB:
173 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
174 break;
175 case IRQ_MAC_ADB:
176 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
177 break;
178 case IRQ_MAC_SCSI:
179 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
180 break;
181 case IRQ_NUBUS_9:
182 case IRQ_NUBUS_A:
183 case IRQ_NUBUS_B:
184 case IRQ_NUBUS_C:
185 case IRQ_NUBUS_D:
186 case IRQ_NUBUS_E:
187 irq -= NUBUS_SOURCE_BASE;
188 oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
189 break;
190#ifdef DEBUG_IRQUSE
191 default:
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700192 printk("%s unknown irq %d\n", __func__, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 break;
194#endif
195 }
196}
197
198/*
199 * Disable an OSS interrupt
200 *
201 * Same as above except we set the source's interrupt level to zero,
202 * to disable the interrupt.
203 */
204
205void oss_irq_disable(int irq) {
206#ifdef DEBUG_IRQUSE
207 printk("oss_irq_disable(%d)\n", irq);
208#endif
209 switch(irq) {
210 case IRQ_SCC:
211 case IRQ_SCCA:
212 case IRQ_SCCB:
213 oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_DISABLED;
214 break;
215 case IRQ_MAC_ADB:
216 oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_DISABLED;
217 break;
218 case IRQ_MAC_SCSI:
219 oss->irq_level[OSS_SCSI] = OSS_IRQLEV_DISABLED;
220 break;
221 case IRQ_NUBUS_9:
222 case IRQ_NUBUS_A:
223 case IRQ_NUBUS_B:
224 case IRQ_NUBUS_C:
225 case IRQ_NUBUS_D:
226 case IRQ_NUBUS_E:
227 irq -= NUBUS_SOURCE_BASE;
228 oss->irq_level[irq] = OSS_IRQLEV_DISABLED;
229 break;
230#ifdef DEBUG_IRQUSE
231 default:
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -0700232 printk("%s unknown irq %d\n", __func__, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 break;
234#endif
235 }
236}
237
238/*
239 * Clear an OSS interrupt
240 *
241 * Not sure if this works or not but it's the only method I could
242 * think of based on the contents of the mac_oss structure.
243 */
244
245void oss_irq_clear(int irq) {
246 /* FIXME: how to do this on OSS? */
247 switch(irq) {
248 case IRQ_SCC:
249 case IRQ_SCCA:
250 case IRQ_SCCB:
251 oss->irq_pending &= ~OSS_IP_IOPSCC;
252 break;
253 case IRQ_MAC_ADB:
254 oss->irq_pending &= ~OSS_IP_IOPISM;
255 break;
256 case IRQ_MAC_SCSI:
257 oss->irq_pending &= ~OSS_IP_SCSI;
258 break;
259 case IRQ_NUBUS_9:
260 case IRQ_NUBUS_A:
261 case IRQ_NUBUS_B:
262 case IRQ_NUBUS_C:
263 case IRQ_NUBUS_D:
264 case IRQ_NUBUS_E:
265 irq -= NUBUS_SOURCE_BASE;
266 oss->irq_pending &= ~(1 << irq);
267 break;
268 }
269}
270
271/*
272 * Check to see if a specific OSS interrupt is pending
273 */
274
275int oss_irq_pending(int irq)
276{
277 switch(irq) {
278 case IRQ_SCC:
279 case IRQ_SCCA:
280 case IRQ_SCCB:
281 return oss->irq_pending & OSS_IP_IOPSCC;
282 break;
283 case IRQ_MAC_ADB:
284 return oss->irq_pending & OSS_IP_IOPISM;
285 break;
286 case IRQ_MAC_SCSI:
287 return oss->irq_pending & OSS_IP_SCSI;
288 break;
289 case IRQ_NUBUS_9:
290 case IRQ_NUBUS_A:
291 case IRQ_NUBUS_B:
292 case IRQ_NUBUS_C:
293 case IRQ_NUBUS_D:
294 case IRQ_NUBUS_E:
295 irq -= NUBUS_SOURCE_BASE;
296 return oss->irq_pending & (1 << irq);
297 break;
298 }
299 return 0;
300}