wss.c revision 1.67.6.1 1 /* $NetBSD: wss.c,v 1.67.6.1 2007/02/27 14:16:12 ad 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.67.6.1 2007/02/27 14:16:12 ad 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 NULL, /* powerstate */
116 ad1848_get_locks,
117 };
118
119 /*
120 * Attach hardware to driver, attach hardware driver to audio
121 * pseudo-device driver .
122 */
123 void
124 wssattach(struct wss_softc *sc)
125 {
126 struct ad1848_softc *ac;
127 #if 0 /* loses on CS423X chips */
128 int version;
129 #endif
130
131 ac = &sc->sc_ad1848.sc_ad1848;
132
133 mutex_init(&ac->sc_lock, MUTEX_DRIVER, IPL_NONE);
134 mutex_init(&ac->sc_intr_lock, MUTEX_DRIVER, IPL_AUDIO);
135
136 madattach(sc);
137
138 sc->sc_ad1848.sc_ih = isa_intr_establish(sc->wss_ic, sc->wss_irq,
139 IST_EDGE, IPL_AUDIO, ad1848_isa_intr, &sc->sc_ad1848);
140
141 ad1848_isa_attach(&sc->sc_ad1848);
142
143 #if 0 /* loses on CS423X chips */
144 version = bus_space_read_1(sc->sc_iot, sc->sc_ioh, WSS_STATUS)
145 & WSS_VERSMASK;
146 printf(" (vers %d)", version);
147 #endif
148
149 switch(sc->mad_chip_type) {
150 case MAD_82C928:
151 printf(", 82C928");
152 break;
153 case MAD_OTI601D:
154 printf(", OTI-601D");
155 break;
156 case MAD_82C929:
157 printf(", 82C929");
158 break;
159 case MAD_82C931:
160 printf(", 82C931");
161 break;
162 default:
163 break;
164 }
165 printf("\n");
166
167 ac->parent = sc;
168
169 audio_attach_mi(&wss_hw_if, &sc->sc_ad1848, &ac->sc_dev);
170
171 if (sc->mad_chip_type != MAD_NONE) {
172 struct audio_attach_args arg;
173 arg.type = AUDIODEV_TYPE_OPL;
174 arg.hwif = 0;
175 arg.hdl = 0;
176 (void)config_found(&ac->sc_dev, &arg, audioprint);
177 }
178 }
179
180 int
181 wss_getdev(void *addr, struct audio_device *retp)
182 {
183
184 *retp = wss_device;
185 return 0;
186 }
187
188 static ad1848_devmap_t mappings[] = {
189 { WSS_MIC_IN_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
190 { WSS_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
191 { WSS_DAC_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
192 { WSS_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONO_CHANNEL },
193 { WSS_MIC_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
194 { WSS_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
195 { WSS_DAC_MUTE, AD1848_KIND_MUTE, AD1848_DAC_CHANNEL },
196 { WSS_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONO_CHANNEL },
197 { WSS_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
198 { WSS_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1}
199 };
200
201 static int nummap = sizeof(mappings) / sizeof(mappings[0]);
202
203 int
204 wss_mixer_set_port(void *addr, mixer_ctrl_t *cp)
205 {
206 struct ad1848_softc *ac;
207
208 ac = addr;
209 return ad1848_mixer_set_port(ac, mappings, nummap, cp);
210 }
211
212 int
213 wss_mixer_get_port(void *addr, mixer_ctrl_t *cp)
214 {
215 struct ad1848_softc *ac;
216
217 ac = addr;
218 return ad1848_mixer_get_port(ac, mappings, nummap, cp);
219 }
220
221 int
222 wss_query_devinfo(void *addr, mixer_devinfo_t *dip)
223 {
224
225 DPRINTF(("wss_query_devinfo: index=%d\n", dip->index));
226 switch(dip->index) {
227 case WSS_MIC_IN_LVL: /* Microphone */
228 dip->type = AUDIO_MIXER_VALUE;
229 dip->mixer_class = WSS_INPUT_CLASS;
230 dip->prev = AUDIO_MIXER_LAST;
231 dip->next = WSS_MIC_IN_MUTE;
232 strcpy(dip->label.name, AudioNmicrophone);
233 dip->un.v.num_channels = 2;
234 strcpy(dip->un.v.units.name, AudioNvolume);
235 break;
236
237 case WSS_LINE_IN_LVL: /* line/CD */
238 dip->type = AUDIO_MIXER_VALUE;
239 dip->mixer_class = WSS_INPUT_CLASS;
240 dip->prev = AUDIO_MIXER_LAST;
241 dip->next = WSS_LINE_IN_MUTE;
242 strcpy(dip->label.name, AudioNcd);
243 dip->un.v.num_channels = 2;
244 strcpy(dip->un.v.units.name, AudioNvolume);
245 break;
246
247 case WSS_DAC_LVL: /* dacout */
248 dip->type = AUDIO_MIXER_VALUE;
249 dip->mixer_class = WSS_INPUT_CLASS;
250 dip->prev = AUDIO_MIXER_LAST;
251 dip->next = WSS_DAC_MUTE;
252 strcpy(dip->label.name, AudioNdac);
253 dip->un.v.num_channels = 2;
254 strcpy(dip->un.v.units.name, AudioNvolume);
255 break;
256
257 case WSS_REC_LVL: /* record level */
258 dip->type = AUDIO_MIXER_VALUE;
259 dip->mixer_class = WSS_RECORD_CLASS;
260 dip->prev = AUDIO_MIXER_LAST;
261 dip->next = WSS_RECORD_SOURCE;
262 strcpy(dip->label.name, AudioNrecord);
263 dip->un.v.num_channels = 2;
264 strcpy(dip->un.v.units.name, AudioNvolume);
265 break;
266
267 case WSS_MONITOR_LVL: /* monitor level */
268 dip->type = AUDIO_MIXER_VALUE;
269 dip->mixer_class = WSS_MONITOR_CLASS;
270 dip->prev = AUDIO_MIXER_LAST;
271 dip->next = WSS_MONITOR_MUTE;
272 strcpy(dip->label.name, AudioNmonitor);
273 dip->un.v.num_channels = 1;
274 strcpy(dip->un.v.units.name, AudioNvolume);
275 break;
276
277 case WSS_INPUT_CLASS: /* input class descriptor */
278 dip->type = AUDIO_MIXER_CLASS;
279 dip->mixer_class = WSS_INPUT_CLASS;
280 dip->next = dip->prev = AUDIO_MIXER_LAST;
281 strcpy(dip->label.name, AudioCinputs);
282 break;
283
284 case WSS_MONITOR_CLASS: /* monitor class descriptor */
285 dip->type = AUDIO_MIXER_CLASS;
286 dip->mixer_class = WSS_MONITOR_CLASS;
287 dip->next = dip->prev = AUDIO_MIXER_LAST;
288 strcpy(dip->label.name, AudioCmonitor);
289 break;
290
291 case WSS_RECORD_CLASS: /* record source class */
292 dip->type = AUDIO_MIXER_CLASS;
293 dip->mixer_class = WSS_RECORD_CLASS;
294 dip->next = dip->prev = AUDIO_MIXER_LAST;
295 strcpy(dip->label.name, AudioCrecord);
296 break;
297
298 case WSS_MIC_IN_MUTE:
299 dip->mixer_class = WSS_INPUT_CLASS;
300 dip->type = AUDIO_MIXER_ENUM;
301 dip->prev = WSS_MIC_IN_LVL;
302 dip->next = AUDIO_MIXER_LAST;
303 goto mute;
304
305 case WSS_LINE_IN_MUTE:
306 dip->mixer_class = WSS_INPUT_CLASS;
307 dip->type = AUDIO_MIXER_ENUM;
308 dip->prev = WSS_LINE_IN_LVL;
309 dip->next = AUDIO_MIXER_LAST;
310 goto mute;
311
312 case WSS_DAC_MUTE:
313 dip->mixer_class = WSS_INPUT_CLASS;
314 dip->type = AUDIO_MIXER_ENUM;
315 dip->prev = WSS_DAC_LVL;
316 dip->next = AUDIO_MIXER_LAST;
317 goto mute;
318
319 case WSS_MONITOR_MUTE:
320 dip->mixer_class = WSS_MONITOR_CLASS;
321 dip->type = AUDIO_MIXER_ENUM;
322 dip->prev = WSS_MONITOR_LVL;
323 dip->next = AUDIO_MIXER_LAST;
324 mute:
325 strcpy(dip->label.name, AudioNmute);
326 dip->un.e.num_mem = 2;
327 strcpy(dip->un.e.member[0].label.name, AudioNoff);
328 dip->un.e.member[0].ord = 0;
329 strcpy(dip->un.e.member[1].label.name, AudioNon);
330 dip->un.e.member[1].ord = 1;
331 break;
332
333 case WSS_RECORD_SOURCE:
334 dip->mixer_class = WSS_RECORD_CLASS;
335 dip->type = AUDIO_MIXER_ENUM;
336 dip->prev = WSS_REC_LVL;
337 dip->next = AUDIO_MIXER_LAST;
338 strcpy(dip->label.name, AudioNsource);
339 dip->un.e.num_mem = 3;
340 strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
341 dip->un.e.member[0].ord = WSS_MIC_IN_LVL;
342 strcpy(dip->un.e.member[1].label.name, AudioNcd);
343 dip->un.e.member[1].ord = WSS_LINE_IN_LVL;
344 strcpy(dip->un.e.member[2].label.name, AudioNdac);
345 dip->un.e.member[2].ord = WSS_DAC_LVL;
346 break;
347
348 default:
349 return ENXIO;
350 /*NOTREACHED*/
351 }
352 DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
353
354 return 0;
355 }
356
357
358 /*
359 * Copyright by Hannu Savolainen 1994
360 *
361 * Redistribution and use in source and binary forms, with or without
362 * modification, are permitted provided that the following conditions are
363 * met: 1. Redistributions of source code must retain the above copyright
364 * notice, this list of conditions and the following disclaimer. 2.
365 * Redistributions in binary form must reproduce the above copyright notice,
366 * this list of conditions and the following disclaimer in the documentation
367 * and/or other materials provided with the distribution.
368 *
369 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
370 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
371 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
372 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
373 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
374 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
375 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
376 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
377 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
378 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
379 * SUCH DAMAGE.
380 *
381 */
382 /*
383 * Initialization code for OPTi MAD16 compatible audio chips. Including
384 *
385 * OPTi 82C928 MAD16 (replaced by C929)
386 * OAK OTI-601D Mozart
387 * OPTi 82C929 MAD16 Pro
388 *
389 */
390
391 u_int
392 mad_read(struct wss_softc *sc, int port)
393 {
394 u_int tmp;
395 int pwd;
396
397 switch (sc->mad_chip_type) { /* Output password */
398 case MAD_82C928:
399 case MAD_OTI601D:
400 pwd = M_PASSWD_928;
401 break;
402 case MAD_82C929:
403 pwd = M_PASSWD_929;
404 break;
405 case MAD_82C931:
406 pwd = M_PASSWD_931;
407 break;
408 default:
409 panic("mad_read: Bad chip type=%d", sc->mad_chip_type);
410 }
411 bus_space_write_1(sc->sc_iot, sc->mad_ioh, MC_PASSWD_REG, pwd);
412 tmp = bus_space_read_1(sc->sc_iot, sc->mad_ioh, port);
413 return tmp;
414 }
415
416 void
417 mad_write(struct wss_softc *sc, int port, int value)
418 {
419 int pwd;
420
421 switch (sc->mad_chip_type) { /* Output password */
422 case MAD_82C928:
423 case MAD_OTI601D:
424 pwd = M_PASSWD_928;
425 break;
426 case MAD_82C929:
427 pwd = M_PASSWD_929;
428 break;
429 case MAD_82C931:
430 pwd = M_PASSWD_931;
431 break;
432 default:
433 panic("mad_write: Bad chip type=%d", sc->mad_chip_type);
434 }
435 bus_space_write_1(sc->sc_iot, sc->mad_ioh, MC_PASSWD_REG, pwd);
436 bus_space_write_1(sc->sc_iot, sc->mad_ioh, port, value & 0xff);
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 = device_cfdata(&ac->sc_dev)->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