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