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