4 * The low level mixer driver for the SoundBlaster Pro and SB16 cards.
6 * Copyright by Hannu Savolainen 1994
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 2.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Modified: Hunyue Yau Jan 6 1994 Added code to support the Sound Galaxy
31 * $DragonFly: src/sys/dev/sound/isa/i386/sb/Attic/sb_mixer.c,v 1.2 2003/08/07 21:17:12 dillon Exp $
34 #include <i386/isa/sound/sound_config.h>
36 #if (NSB > 0) && defined(CONFIG_SBPRO)
37 #define __SB_MIXER_C__
39 #include <i386/isa/sound/sbcard.h>
44 extern int Jazz16_detected;
45 extern sound_os_info *sb_osp;
47 static int mixer_initialized = 0;
49 static int supported_rec_devices;
50 static int supported_devices;
51 static int recmask = 0;
52 static int mixer_model;
53 static int mixer_caps;
54 static mixer_tab *iomap;
57 sb_setmixer(u_int port, u_int value)
61 flags = splhigh(); /* XXX ouch... */
62 outb(MIXER_ADDR, (u_char) (port & 0xff)); /* Select register */
64 outb(MIXER_DATA, (u_char) (value & 0xff));
70 sb_getmixer(u_int port)
76 outb(MIXER_ADDR, (u_char) (port & 0xff)); /* Select register */
78 val = inb(MIXER_DATA);
86 sb_mixer_set_stereo(int mode)
88 if (!mixer_initialized)
91 sb_setmixer(OUT_FILTER, ((sb_getmixer(OUT_FILTER) & ~STEREO_DAC)
92 | (mode ? STEREO_DAC : MONO_DAC)));
97 * 0 No mixer detected.
98 * 1 Only a plain Sound Blaster Pro style mixer detected.
99 * 2 The Sound Galaxy NX Pro mixer detected.
106 int oldbass, oldtreble;
107 extern int sbc_major;
112 * Detect the mixer by changing parameters of two volume channels. If
113 * the values read back match with the values written, the mixer is
116 sb_setmixer(FM_VOL, 0xff);
117 sb_setmixer(VOC_VOL, 0x33);
119 if (sb_getmixer(FM_VOL) != 0xff)
120 return 0; /* No match */
121 if (sb_getmixer(VOC_VOL) != 0x33)
126 * Attempt to detect the SG NX Pro by check for valid bass/treble
129 oldbass = sb_getmixer(BASS_LVL);
130 oldtreble = sb_getmixer(TREBLE_LVL);
132 sb_setmixer(BASS_LVL, 0xaa);
133 sb_setmixer(TREBLE_LVL, 0x55);
135 if ((sb_getmixer(BASS_LVL) != 0xaa) ||
136 (sb_getmixer(TREBLE_LVL) != 0x55)) {
137 retcode = 1; /* 1 == Only SB Pro detected */
139 retcode = 2; /* 2 == SG NX Pro detected */
141 * Restore register in either case since SG NX Pro has EEPROM with
142 * 'preferred' values stored.
144 sb_setmixer(BASS_LVL, oldbass);
145 sb_setmixer(TREBLE_LVL, oldtreble);
148 * If the SB version is 3.X (SB Pro), assume we have a SG NX Pro 16.
149 * In this case it's good idea to disable the Disney Sound Source
150 * compatibility mode. It's useless and just causes noise every time
151 * the LPT-port is accessed.
153 * Also place the card into WSS mode.
155 if (sbc_major == 3) {
156 outb(sbc_base + 0x1c, 0x01);
157 outb(sbc_base + 0x1a, 0x00);
164 change_bits(u_char *regval, int dev, int chn, int newval)
169 mask = (1 << (*iomap)[dev][chn].nbits) - 1;
170 newval = (int) ((newval * mask) + 50) / 100; /* Scale it */
172 shift = (*iomap)[dev][chn].bitoffs - (*iomap)[dev][LEFT_CHN].nbits + 1;
174 *regval &= ~(mask << shift); /* Filter out the previous value */
175 *regval |= (newval & mask) << shift; /* Set the new value */
179 sb_mixer_get(int dev)
181 if (!((1 << dev) & supported_devices))
188 static char smw_mix_regs[] =/* Left mixer registers */
190 0x0b, /* SOUND_MIXER_VOLUME */
191 0x0d, /* SOUND_MIXER_BASS */
192 0x0d, /* SOUND_MIXER_TREBLE */
193 0x05, /* SOUND_MIXER_SYNTH */
194 0x09, /* SOUND_MIXER_PCM */
195 0x00, /* SOUND_MIXER_SPEAKER */
196 0x03, /* SOUND_MIXER_LINE */
197 0x01, /* SOUND_MIXER_MIC */
198 0x07, /* SOUND_MIXER_CD */
199 0x00, /* SOUND_MIXER_IMIX */
200 0x00, /* SOUND_MIXER_ALTPCM */
201 0x00, /* SOUND_MIXER_RECLEV */
202 0x00, /* SOUND_MIXER_IGAIN */
203 0x00, /* SOUND_MIXER_OGAIN */
204 0x00, /* SOUND_MIXER_LINE1 */
205 0x00, /* SOUND_MIXER_LINE2 */
206 0x00 /* SOUND_MIXER_LINE3 */
214 sb_setmixer(0x00, 0x18);/* Mute unused (Telephone) line */
215 sb_setmixer(0x10, 0x38);/* Config register 2 */
217 supported_devices = 0;
218 for (i = 0; i < sizeof(smw_mix_regs); i++)
219 if (smw_mix_regs[i] != 0)
220 supported_devices |= (1 << i);
222 supported_rec_devices = supported_devices &
223 ~(SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_PCM |
228 smw_mixer_set(int dev, int value)
230 int left = value & 0x000000ff;
231 int right = (value & 0x0000ff00) >> 8;
242 if (!(supported_devices & (1 << dev))) /* Not supported */
246 case SOUND_MIXER_VOLUME:
247 sb_setmixer(0x0b, 96 - (96 * left / 100)); /* 96=mute, 0=max */
248 sb_setmixer(0x0c, 96 - (96 * right / 100));
251 case SOUND_MIXER_BASS:
252 case SOUND_MIXER_TREBLE:
253 levels[dev] = left | (right << 8);
255 /* Set left bass and treble values */
256 val = ((levels[SOUND_MIXER_TREBLE] & 0xff) * 16 / 100) << 4;
257 val |= ((levels[SOUND_MIXER_BASS] & 0xff) * 16 / 100) & 0x0f;
258 sb_setmixer(0x0d, val);
260 /* Set right bass and treble values */
261 val = (((levels[SOUND_MIXER_TREBLE] >> 8) & 0xff) * 16 / 100) << 4;
262 val |= (((levels[SOUND_MIXER_BASS] >> 8) & 0xff) * 16 / 100) & 0x0f;
263 sb_setmixer(0x0e, val);
267 reg = smw_mix_regs[dev];
270 sb_setmixer(reg, (24 - (24 * left / 100)) | 0x20); /* 24=mute, 0=max */
271 sb_setmixer(reg + 1, (24 - (24 * right / 100)) | 0x40);
274 levels[dev] = left | (right << 8);
275 return left | (right << 8);
281 sb_mixer_set(int dev, int value)
283 int left = value & 0x000000ff;
284 int right = (value & 0x0000ff00) >> 8;
290 if (Jazz16_detected == 2)
291 return smw_mixer_set(dev, value);
302 if (!(supported_devices & (1 << dev))) /* Not supported */
305 regoffs = (*iomap)[dev][LEFT_CHN].regno;
310 val = sb_getmixer(regoffs);
311 change_bits(&val, dev, LEFT_CHN, left);
313 levels[dev] = left | (left << 8);
315 if ((*iomap)[dev][RIGHT_CHN].regno != regoffs) { /* Change register */
316 sb_setmixer(regoffs, val); /* Save the old one */
317 regoffs = (*iomap)[dev][RIGHT_CHN].regno;
320 return left | (left << 8); /* Just left channel present */
322 val = sb_getmixer(regoffs); /* Read the new one */
324 change_bits(&val, dev, RIGHT_CHN, right);
326 sb_setmixer(regoffs, val);
328 levels[dev] = left | (right << 8);
329 return left | (right << 8);
335 sb_setmixer(RECORD_SRC, (sb_getmixer(RECORD_SRC) & ~7) | (src & 0x7));
339 set_recmask(int mask)
342 u_char regimageL, regimageR;
344 devmask = mask & supported_rec_devices;
346 switch (mixer_model) {
349 if (devmask != SOUND_MASK_MIC && devmask != SOUND_MASK_LINE &&
350 devmask != SOUND_MASK_CD) {
352 * More than one devices selected. Drop the previous
357 if (devmask != SOUND_MASK_MIC && devmask != SOUND_MASK_LINE &&
358 devmask != SOUND_MASK_CD) {
359 /* More than one devices selected. Default to mic */
360 devmask = SOUND_MASK_MIC;
362 if (devmask ^ recmask) { /* Input source changed */
369 case SOUND_MASK_LINE:
370 set_recsrc(SRC_LINE);
385 devmask = SOUND_MASK_MIC;
387 regimageL = regimageR = 0;
388 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
389 if ((1 << i) & devmask) {
390 regimageL |= sb16_recmasks_L[i];
391 regimageR |= sb16_recmasks_R[i];
393 sb_setmixer(SB16_IMASK_L, regimageL);
394 sb_setmixer(SB16_IMASK_R, regimageR);
403 sb_mixer_ioctl(int dev, u_int cmd, ioctl_arg arg)
405 if (((cmd >> 8) & 0xff) == 'M') {
407 switch (cmd & 0xff) {
408 case SOUND_MIXER_RECSRC:
409 return *(int *) arg = set_recmask((*(int *) arg));
413 return *(int *) arg = sb_mixer_set(cmd & 0xff, (*(int *) arg));
416 switch (cmd & 0xff) { /* Return parameters */
418 case SOUND_MIXER_RECSRC:
419 return *(int *) arg = recmask;
422 case SOUND_MIXER_DEVMASK:
423 return *(int *) arg = supported_devices;
426 case SOUND_MIXER_STEREODEVS:
428 return *(int *) arg = supported_devices;
430 return *(int *) arg = supported_devices & ~(SOUND_MASK_MIC | SOUND_MASK_SPEAKER);
433 case SOUND_MIXER_RECMASK:
434 return *(int *) arg = supported_rec_devices;
437 case SOUND_MIXER_CAPS:
438 return *(int *) arg = mixer_caps;
442 return *(int *) arg = sb_mixer_get(cmd & 0xff);
448 static struct mixer_operations sb_mixer_operations =
459 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
460 sb_mixer_set(i, levels[i]);
461 set_recmask(SOUND_MASK_MIC);
465 * Returns a code depending on whether a SG NX Pro was detected. 1 == Plain
466 * SB Pro 2 == SG NX Pro detected. 3 == SB16
468 * Used to update message.
471 sb_mixer_init(int major_model)
475 sb_setmixer(0x00, 0); /* Reset mixer */
477 if (!(mixer_type = detect_mixer()))
478 return 0; /* No mixer. Why? */
480 mixer_initialized = 1;
481 mixer_model = major_model;
483 switch (major_model) {
485 mixer_caps = SOUND_CAP_EXCL_INPUT;
488 if (Jazz16_detected == 2) { /* SM Wave */
489 supported_devices = 0;
490 supported_rec_devices = 0;
497 if (mixer_type == 2) { /* A SGNXPRO was detected */
498 supported_devices = SGNXPRO_MIXER_DEVICES;
499 supported_rec_devices = SGNXPRO_RECORDING_DEVICES;
500 iomap = &sgnxpro_mix;
504 supported_devices = SBPRO_MIXER_DEVICES;
505 supported_rec_devices = SBPRO_RECORDING_DEVICES;
513 supported_devices = SB16_MIXER_DEVICES;
514 supported_rec_devices = SB16_RECORDING_DEVICES;
520 printf("SB Warning: Unsupported mixer type\n");
524 if (num_mixers < MAX_MIXER_DEV)
525 mixer_devs[num_mixers++] = &sb_mixer_operations;