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