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