wss.c revision 1.52 1 /* $NetBSD: wss.c,v 1.52 1998/08/25 22:34:31 pk Exp $ */
2
3 /*
4 * Copyright (c) 1994 John Brezak
5 * Copyright (c) 1991-1993 Regents of the University of California.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the Computer Systems
19 * Engineering Group at Lawrence Berkeley Laboratory.
20 * 4. Neither the name of the University nor of the Laboratory may be used
21 * to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41 #include <sys/errno.h>
42
43 #include <machine/cpu.h>
44 #include <machine/intr.h>
45 #include <machine/bus.h>
46
47 #include <sys/audioio.h>
48 #include <dev/audio_if.h>
49
50 #include <dev/isa/isavar.h>
51 #include <dev/isa/isadmavar.h>
52
53 #include <dev/ic/ad1848reg.h>
54 #include <dev/ic/cs4231reg.h>
55 #include <dev/isa/ad1848var.h>
56 #include <dev/isa/cs4231var.h>
57 #include <dev/isa/wssreg.h>
58 #include <dev/isa/wssvar.h>
59 #include <dev/isa/madreg.h>
60
61 #ifdef AUDIO_DEBUG
62 #define DPRINTF(x) if (wssdebug) printf x
63 int wssdebug = 0;
64 #else
65 #define DPRINTF(x)
66 #endif
67
68 struct audio_device wss_device = {
69 "wss,ad1848",
70 "",
71 "WSS"
72 };
73
74 int wss_getdev __P((void *, struct audio_device *));
75
76 int wss_mixer_set_port __P((void *, mixer_ctrl_t *));
77 int wss_mixer_get_port __P((void *, mixer_ctrl_t *));
78 int wss_query_devinfo __P((void *, mixer_devinfo_t *));
79
80 /*
81 * Define our interface to the higher level audio driver.
82 */
83
84 struct audio_hw_if wss_hw_if = {
85 ad1848_open,
86 ad1848_close,
87 NULL,
88 ad1848_query_encoding,
89 ad1848_set_params,
90 ad1848_round_blocksize,
91 ad1848_commit_settings,
92 ad1848_isa_dma_init_output,
93 ad1848_isa_dma_init_input,
94 ad1848_isa_dma_output,
95 ad1848_isa_dma_input,
96 ad1848_halt_out,
97 ad1848_halt_in,
98 NULL,
99 wss_getdev,
100 NULL,
101 wss_mixer_set_port,
102 wss_mixer_get_port,
103 wss_query_devinfo,
104 ad1848_isa_malloc,
105 ad1848_isa_free,
106 ad1848_isa_round,
107 ad1848_isa_mappage,
108 ad1848_isa_get_props,
109 };
110
111 /*
112 * Attach hardware to driver, attach hardware driver to audio
113 * pseudo-device driver .
114 */
115 void
116 wssattach(sc)
117 struct wss_softc *sc;
118 {
119 struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
120
121 #if 0 /* loses on CS423X chips */
122 int version;
123 #endif
124
125 madattach(sc);
126
127 sc->sc_ad1848.sc_ih = isa_intr_establish(sc->wss_ic, sc->wss_irq,
128 IST_EDGE,
129 IPL_AUDIO, ad1848_isa_intr,
130 &sc->sc_ad1848);
131
132 ad1848_isa_attach(&sc->sc_ad1848);
133
134 #if 0 /* loses on CS423X chips */
135 version = bus_space_read_1(sc->sc_iot, sc->sc_ioh, WSS_STATUS)
136 & WSS_VERSMASK;
137 printf(" (vers %d)", version);
138 #endif
139
140 switch(sc->mad_chip_type) {
141 case MAD_82C928:
142 printf(", 82C928");
143 break;
144 case MAD_OTI601D:
145 printf(", OTI-601D");
146 break;
147 case MAD_82C929:
148 printf(", 82C929");
149 break;
150 case MAD_82C931:
151 printf(", 82C931");
152 break;
153 default:
154 break;
155 }
156 printf("\n");
157
158 ac->parent = sc;
159
160 audio_attach_mi(&wss_hw_if, &sc->sc_ad1848, &ac->sc_dev);
161 }
162
163 int
164 wss_getdev(addr, retp)
165 void *addr;
166 struct audio_device *retp;
167 {
168 *retp = wss_device;
169 return 0;
170 }
171
172 static ad1848_devmap_t mappings[] = {
173 { WSS_MIC_IN_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
174 { WSS_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
175 { WSS_DAC_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
176 { WSS_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONO_CHANNEL },
177 { WSS_MIC_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
178 { WSS_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
179 { WSS_DAC_MUTE, AD1848_KIND_MUTE, AD1848_DAC_CHANNEL },
180 { WSS_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONO_CHANNEL },
181 { WSS_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
182 { WSS_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1}
183 };
184
185 static int nummap = sizeof(mappings) / sizeof(mappings[0]);
186
187 int
188 wss_mixer_set_port(addr, cp)
189 void *addr;
190 mixer_ctrl_t *cp;
191 {
192 struct ad1848_softc *ac = addr;
193
194 return (ad1848_mixer_set_port(ac, mappings, nummap, cp));
195 }
196
197 int
198 wss_mixer_get_port(addr, cp)
199 void *addr;
200 mixer_ctrl_t *cp;
201 {
202 struct ad1848_softc *ac = addr;
203
204 return (ad1848_mixer_get_port(ac, mappings, nummap, cp));
205 }
206
207 int
208 wss_query_devinfo(addr, dip)
209 void *addr;
210 mixer_devinfo_t *dip;
211 {
212 DPRINTF(("wss_query_devinfo: index=%d\n", dip->index));
213
214 switch(dip->index) {
215 case WSS_MIC_IN_LVL: /* Microphone */
216 dip->type = AUDIO_MIXER_VALUE;
217 dip->mixer_class = WSS_INPUT_CLASS;
218 dip->prev = AUDIO_MIXER_LAST;
219 dip->next = WSS_MIC_IN_MUTE;
220 strcpy(dip->label.name, AudioNmicrophone);
221 dip->un.v.num_channels = 2;
222 strcpy(dip->un.v.units.name, AudioNvolume);
223 break;
224
225 case WSS_LINE_IN_LVL: /* line/CD */
226 dip->type = AUDIO_MIXER_VALUE;
227 dip->mixer_class = WSS_INPUT_CLASS;
228 dip->prev = AUDIO_MIXER_LAST;
229 dip->next = WSS_LINE_IN_MUTE;
230 strcpy(dip->label.name, AudioNcd);
231 dip->un.v.num_channels = 2;
232 strcpy(dip->un.v.units.name, AudioNvolume);
233 break;
234
235 case WSS_DAC_LVL: /* dacout */
236 dip->type = AUDIO_MIXER_VALUE;
237 dip->mixer_class = WSS_INPUT_CLASS;
238 dip->prev = AUDIO_MIXER_LAST;
239 dip->next = WSS_DAC_MUTE;
240 strcpy(dip->label.name, AudioNdac);
241 dip->un.v.num_channels = 2;
242 strcpy(dip->un.v.units.name, AudioNvolume);
243 break;
244
245 case WSS_REC_LVL: /* record level */
246 dip->type = AUDIO_MIXER_VALUE;
247 dip->mixer_class = WSS_RECORD_CLASS;
248 dip->prev = AUDIO_MIXER_LAST;
249 dip->next = WSS_RECORD_SOURCE;
250 strcpy(dip->label.name, AudioNrecord);
251 dip->un.v.num_channels = 2;
252 strcpy(dip->un.v.units.name, AudioNvolume);
253 break;
254
255 case WSS_MONITOR_LVL: /* monitor level */
256 dip->type = AUDIO_MIXER_VALUE;
257 dip->mixer_class = WSS_MONITOR_CLASS;
258 dip->prev = AUDIO_MIXER_LAST;
259 dip->next = WSS_MONITOR_MUTE;
260 strcpy(dip->label.name, AudioNmonitor);
261 dip->un.v.num_channels = 1;
262 strcpy(dip->un.v.units.name, AudioNvolume);
263 break;
264
265 case WSS_INPUT_CLASS: /* input class descriptor */
266 dip->type = AUDIO_MIXER_CLASS;
267 dip->mixer_class = WSS_INPUT_CLASS;
268 dip->next = dip->prev = AUDIO_MIXER_LAST;
269 strcpy(dip->label.name, AudioCinputs);
270 break;
271
272 case WSS_MONITOR_CLASS: /* monitor class descriptor */
273 dip->type = AUDIO_MIXER_CLASS;
274 dip->mixer_class = WSS_MONITOR_CLASS;
275 dip->next = dip->prev = AUDIO_MIXER_LAST;
276 strcpy(dip->label.name, AudioCmonitor);
277 break;
278
279 case WSS_RECORD_CLASS: /* record source class */
280 dip->type = AUDIO_MIXER_CLASS;
281 dip->mixer_class = WSS_RECORD_CLASS;
282 dip->next = dip->prev = AUDIO_MIXER_LAST;
283 strcpy(dip->label.name, AudioCrecord);
284 break;
285
286 case WSS_MIC_IN_MUTE:
287 dip->mixer_class = WSS_INPUT_CLASS;
288 dip->type = AUDIO_MIXER_ENUM;
289 dip->prev = WSS_MIC_IN_LVL;
290 dip->next = AUDIO_MIXER_LAST;
291 goto mute;
292
293 case WSS_LINE_IN_MUTE:
294 dip->mixer_class = WSS_INPUT_CLASS;
295 dip->type = AUDIO_MIXER_ENUM;
296 dip->prev = WSS_LINE_IN_LVL;
297 dip->next = AUDIO_MIXER_LAST;
298 goto mute;
299
300 case WSS_DAC_MUTE:
301 dip->mixer_class = WSS_INPUT_CLASS;
302 dip->type = AUDIO_MIXER_ENUM;
303 dip->prev = WSS_DAC_LVL;
304 dip->next = AUDIO_MIXER_LAST;
305 goto mute;
306
307 case WSS_MONITOR_MUTE:
308 dip->mixer_class = WSS_MONITOR_CLASS;
309 dip->type = AUDIO_MIXER_ENUM;
310 dip->prev = WSS_MONITOR_LVL;
311 dip->next = AUDIO_MIXER_LAST;
312 mute:
313 strcpy(dip->label.name, AudioNmute);
314 dip->un.e.num_mem = 2;
315 strcpy(dip->un.e.member[0].label.name, AudioNoff);
316 dip->un.e.member[0].ord = 0;
317 strcpy(dip->un.e.member[1].label.name, AudioNon);
318 dip->un.e.member[1].ord = 1;
319 break;
320
321 case WSS_RECORD_SOURCE:
322 dip->mixer_class = WSS_RECORD_CLASS;
323 dip->type = AUDIO_MIXER_ENUM;
324 dip->prev = WSS_REC_LVL;
325 dip->next = AUDIO_MIXER_LAST;
326 strcpy(dip->label.name, AudioNsource);
327 dip->un.e.num_mem = 3;
328 strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
329 dip->un.e.member[0].ord = WSS_MIC_IN_LVL;
330 strcpy(dip->un.e.member[1].label.name, AudioNcd);
331 dip->un.e.member[1].ord = WSS_LINE_IN_LVL;
332 strcpy(dip->un.e.member[2].label.name, AudioNdac);
333 dip->un.e.member[2].ord = WSS_DAC_LVL;
334 break;
335
336 default:
337 return ENXIO;
338 /*NOTREACHED*/
339 }
340 DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
341
342 return 0;
343 }
344
345
346 /*
347 * Copyright by Hannu Savolainen 1994
348 *
349 * Redistribution and use in source and binary forms, with or without
350 * modification, are permitted provided that the following conditions are
351 * met: 1. Redistributions of source code must retain the above copyright
352 * notice, this list of conditions and the following disclaimer. 2.
353 * Redistributions in binary form must reproduce the above copyright notice,
354 * this list of conditions and the following disclaimer in the documentation
355 * and/or other materials provided with the distribution.
356 *
357 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
358 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
359 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
360 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
361 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
362 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
363 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
364 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
365 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
366 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
367 * SUCH DAMAGE.
368 *
369 */
370 /*
371 * Initialization code for OPTi MAD16 compatible audio chips. Including
372 *
373 * OPTi 82C928 MAD16 (replaced by C929)
374 * OAK OTI-601D Mozart
375 * OPTi 82C929 MAD16 Pro
376 *
377 */
378
379 u_int
380 mad_read(sc, port)
381 struct wss_softc *sc;
382 int port;
383 {
384 u_int tmp;
385 int pwd;
386 int s;
387
388 switch (sc->mad_chip_type) { /* Output password */
389 case MAD_82C928:
390 case MAD_OTI601D:
391 pwd = M_PASSWD_928;
392 break;
393 case MAD_82C929:
394 pwd = M_PASSWD_929;
395 break;
396 case MAD_82C931:
397 pwd = M_PASSWD_931;
398 break;
399 default:
400 panic("mad_read: Bad chip type=%d\n", sc->mad_chip_type);
401 }
402 s = splaudio(); /* don't want an interrupt between outb&inb */
403 bus_space_write_1(sc->sc_iot, sc->mad_ioh, MC_PASSWD_REG, pwd);
404 tmp = bus_space_read_1(sc->sc_iot, sc->mad_ioh, port);
405 splx(s);
406 return tmp;
407 }
408
409 void
410 mad_write(sc, port, value)
411 struct wss_softc *sc;
412 int port;
413 int value;
414 {
415 int pwd;
416 int s;
417
418 switch (sc->mad_chip_type) { /* Output password */
419 case MAD_82C928:
420 case MAD_OTI601D:
421 pwd = M_PASSWD_928;
422 break;
423 case MAD_82C929:
424 pwd = M_PASSWD_929;
425 break;
426 case MAD_82C931:
427 pwd = M_PASSWD_931;
428 break;
429 default:
430 panic("mad_write: Bad chip type=%d\n", sc->mad_chip_type);
431 }
432 s = splaudio();
433 bus_space_write_1(sc->sc_iot, sc->mad_ioh, MC_PASSWD_REG, pwd);
434 bus_space_write_1(sc->sc_iot, sc->mad_ioh, port, value & 0xff);
435 splx(s);
436 }
437
438 void
439 madattach(sc)
440 struct wss_softc *sc;
441 {
442 struct ad1848_softc *ac = (struct ad1848_softc *)&sc->sc_ad1848;
443 unsigned char cs4231_mode;
444 int joy;
445
446 if (sc->mad_chip_type == MAD_NONE)
447 return;
448
449 /* Do we want the joystick disabled? */
450 joy = ac->sc_dev.dv_cfdata->cf_flags & 2 ? MC1_JOYDISABLE : 0;
451
452 /* enable WSS emulation at the I/O port */
453 mad_write(sc, MC1_PORT, M_WSS_PORT_SELECT(sc->mad_ioindex) | joy);
454 mad_write(sc, MC2_PORT, 0x03); /* ? */
455 mad_write(sc, MC3_PORT, 0xf0); /* Disable SB */
456
457 cs4231_mode =
458 strncmp(ac->chip_name, "CS4248", 6) == 0 ||
459 strncmp(ac->chip_name, "CS4231", 6) == 0 ? 0x02 : 0;
460
461 if (sc->mad_chip_type == MAD_82C929) {
462 mad_write(sc, MC4_PORT, 0x92);
463 mad_write(sc, MC5_PORT, 0xA5 | cs4231_mode);
464 mad_write(sc, MC6_PORT, 0x03); /* Disable MPU401 */
465 } else {
466 mad_write(sc, MC4_PORT, 0x02);
467 mad_write(sc, MC5_PORT, 0x30 | cs4231_mode);
468 }
469
470 #ifdef AUDIO_DEBUG
471 if (wssdebug) {
472 int i;
473 for (i = MC1_PORT; i <= MC7_PORT; i++)
474 DPRINTF(("port %03x after init = %02x\n",
475 i, mad_read(sc, i)));
476 }
477 #endif
478 }
479