Merge branch 'master' of ../mmc
[pandora-kernel.git] / arch / m68k / mac / oss.c
1 /*
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.
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.
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>
24 #include <asm/macintosh.h>
25 #include <asm/macints.h>
26 #include <asm/mac_via.h>
27 #include <asm/mac_oss.h>
28
29 int oss_present;
30 volatile struct mac_oss *oss;
31
32 static irqreturn_t oss_irq(int, void *);
33 static irqreturn_t oss_nubus_irq(int, void *);
34
35 extern irqreturn_t via1_irq(int, void *);
36 extern irqreturn_t mac_scc_dispatch(int, void *);
37
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
45 void __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
67 void __init oss_register_interrupts(void)
68 {
69         request_irq(OSS_IRQLEV_SCSI, oss_irq, IRQ_FLG_LOCK,
70                         "scsi", (void *) oss);
71         request_irq(OSS_IRQLEV_IOPSCC, mac_scc_dispatch, IRQ_FLG_LOCK,
72                         "scc", mac_scc_dispatch);
73         request_irq(OSS_IRQLEV_NUBUS, oss_nubus_irq, IRQ_FLG_LOCK,
74                         "nubus", (void *) oss);
75         request_irq(OSS_IRQLEV_SOUND, oss_irq, IRQ_FLG_LOCK,
76                         "sound", (void *) oss);
77         request_irq(OSS_IRQLEV_VIA1, via1_irq, IRQ_FLG_LOCK,
78                         "via1", (void *) via1);
79 }
80
81 /*
82  * Initialize OSS for Nubus access
83  */
84
85 void __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
94 static irqreturn_t oss_irq(int irq, void *dev_id)
95 {
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) {
111                 oss->irq_pending &= ~OSS_IP_SOUND;
112                 /* FIXME: call sound handler */
113         } else if (events & OSS_IP_SCSI) {
114                 oss->irq_pending &= ~OSS_IP_SCSI;
115                 m68k_handle_int(IRQ_MAC_SCSI);
116         } 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
128 static irqreturn_t oss_nubus_irq(int irq, void *dev_id)
129 {
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
143         i = 6;
144         irq_bit = 0x40;
145         do {
146                 --i;
147                 irq_bit >>= 1;
148                 if (events & irq_bit) {
149                         oss->irq_pending &= ~irq_bit;
150                         m68k_handle_int(NUBUS_SOURCE_BASE + i);
151                 }
152         } while(events & (irq_bit - 1));
153         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
165 void 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:
192                         printk("%s unknown irq %d\n", __func__, irq);
193                         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
205 void 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:
232                         printk("%s unknown irq %d\n", __func__, irq);
233                         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
245 void 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
275 int 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 }