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