5 * Mixer routines for the Pro Audio Spectrum cards.
9 * Copyright (C) by Hannu Savolainen 1993-1997
11 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
12 * Version 2 (June 1991). See the "COPYING" file distributed with this software
16 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
18 #include "sound_config.h"
21 #define DEB(what) /* (what) */
24 extern int translate_code
;
25 extern char pas_model
;
27 extern int pas_audiodev
;
29 static int rec_devices
= (SOUND_MASK_MIC
); /* Default recording source */
30 static int mode_control
= 0;
32 #define POSSIBLE_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
33 SOUND_MASK_CD | SOUND_MASK_ALTPCM)
35 #define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
36 SOUND_MASK_CD | SOUND_MASK_ALTPCM | SOUND_MASK_IMIX | \
37 SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_RECLEV)
41 static int default_levels
[32] =
43 0x3232, /* Master Volume */
48 0x3232, /* PC Speaker */
49 0x4b4b, /* Ext Line */
52 0x6464, /* Recording monitor */
54 0x6464 /* Recording level */
58 mix_write(unsigned char data
, int ioaddr
)
61 * The Revision D cards have a problem with their MVA508 interface. The
62 * kludge-o-rama fix is to make a 16-bit quantity with identical LSB and
63 * MSBs out of the output byte and to do a 16-bit out to the mixer port -
64 * 1. We need to do this because it isn't timing problem but chip access
70 outw(data
| (data
<< 8), (ioaddr
^ translate_code
) - 1);
73 pas_write(data
, ioaddr
);
77 mixer_output(int right_vol
, int left_vol
, int div
, int bits
,
78 int mixer
) /* Input or output mixer */
80 int left
= left_vol
* div
/ 100;
81 int right
= right_vol
* div
/ 100;
89 if (bits
== 0x03 || bits
== 0x04)
91 mix_write(0x80 | bits
, 0x078B);
92 mix_write(left
, 0x078B);
96 mix_write(0x80 | 0x20 | bits
, 0x078B);
97 mix_write(left
, 0x078B);
98 mix_write(0x80 | 0x40 | bits
, 0x078B);
99 mix_write(right
, 0x078B);
102 return (left_vol
| (right_vol
<< 8));
106 set_mode(int new_mode
)
108 mix_write(0x80 | 0x05, 0x078B);
109 mix_write(new_mode
, 0x078B);
111 mode_control
= new_mode
;
115 pas_mixer_set(int whichDev
, unsigned int level
)
117 int left
, right
, devmask
, changed
, i
, mixer
= 0;
119 DEB(printk("static int pas_mixer_set(int whichDev = %d, unsigned int level = %X)\n", whichDev
, level
));
122 right
= (level
& 0x7f00) >> 8;
124 if (whichDev
< SOUND_MIXER_NRDEVICES
) {
125 if ((1 << whichDev
) & rec_devices
)
133 case SOUND_MIXER_VOLUME
: /* Master volume (0-63) */
134 levels
[whichDev
] = mixer_output(right
, left
, 63, 0x01, 0);
138 * Note! Bass and Treble are mono devices. Will use just the left
141 case SOUND_MIXER_BASS
: /* Bass (0-12) */
142 levels
[whichDev
] = mixer_output(right
, left
, 12, 0x03, 0);
144 case SOUND_MIXER_TREBLE
: /* Treble (0-12) */
145 levels
[whichDev
] = mixer_output(right
, left
, 12, 0x04, 0);
148 case SOUND_MIXER_SYNTH
: /* Internal synthesizer (0-31) */
149 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x00, mixer
);
151 case SOUND_MIXER_PCM
: /* PAS PCM (0-31) */
152 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x05, mixer
);
154 case SOUND_MIXER_ALTPCM
: /* SB PCM (0-31) */
155 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x07, mixer
);
157 case SOUND_MIXER_SPEAKER
: /* PC speaker (0-31) */
158 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x06, mixer
);
160 case SOUND_MIXER_LINE
: /* External line (0-31) */
161 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x02, mixer
);
163 case SOUND_MIXER_CD
: /* CD (0-31) */
164 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x03, mixer
);
166 case SOUND_MIXER_MIC
: /* External microphone (0-31) */
167 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x04, mixer
);
169 case SOUND_MIXER_IMIX
: /* Recording monitor (0-31) (Output mixer only) */
170 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x01,
173 case SOUND_MIXER_RECLEV
: /* Recording level (0-15) */
174 levels
[whichDev
] = mixer_output(right
, left
, 15, 0x02, 0);
178 case SOUND_MIXER_RECSRC
:
179 devmask
= level
& POSSIBLE_RECORDING_DEVICES
;
181 changed
= devmask
^ rec_devices
;
182 rec_devices
= devmask
;
184 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
185 if (changed
& (1 << i
))
187 pas_mixer_set(i
, levels
[i
]);
196 return (levels
[whichDev
]);
202 pas_mixer_reset(void)
206 DEB(printk("pas2_mixer.c: void pas_mixer_reset(void)\n"));
208 for (foo
= 0; foo
< SOUND_MIXER_NRDEVICES
; foo
++)
209 pas_mixer_set(foo
, levels
[foo
]);
211 set_mode(0x04 | 0x01);
214 static int pas_mixer_ioctl(int dev
, unsigned int cmd
, caddr_t arg
)
218 DEB(printk("pas2_mixer.c: int pas_mixer_ioctl(unsigned int cmd = %X, unsigned int arg = %X)\n", cmd
, arg
));
219 if (cmd
== SOUND_MIXER_PRIVATE1
) { /* Set loudness bit */
220 if (get_user(level
, (int *)arg
))
222 if (level
== -1) /* Return current settings */
223 level
= (mode_control
& 0x04);
225 mode_control
&= ~0x04;
227 mode_control
|= 0x04;
228 set_mode(mode_control
);
231 return put_user(level
, (int *)arg
);
233 if (cmd
== SOUND_MIXER_PRIVATE2
) { /* Set enhance bit */
234 if (get_user(level
, (int *)arg
))
236 if (level
== -1) { /* Return current settings */
237 if (!(mode_control
& 0x03))
240 level
= ((mode_control
& 0x03) + 1) * 20;
246 i
= (level
/ 20) - 1;
247 mode_control
&= ~0x03;
248 mode_control
|= i
& 0x03;
249 set_mode(mode_control
);
254 return put_user(level
, (int *)arg
);
256 if (cmd
== SOUND_MIXER_PRIVATE3
) { /* Set mute bit */
257 if (get_user(level
, (int *)arg
))
259 if (level
== -1) /* Return current settings */
260 level
= !(pas_read(0x0B8A) & 0x20);
263 pas_write(pas_read(0x0B8A) & (~0x20), 0x0B8A);
265 pas_write(pas_read(0x0B8A) | 0x20, 0x0B8A);
267 level
= !(pas_read(0x0B8A) & 0x20);
269 return put_user(level
, (int *)arg
);
271 if (((cmd
>> 8) & 0xff) == 'M') {
272 if (get_user(v
, (int *)arg
))
274 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
) {
275 v
= pas_mixer_set(cmd
& 0xff, v
);
277 switch (cmd
& 0xff) {
278 case SOUND_MIXER_RECSRC
:
282 case SOUND_MIXER_STEREODEVS
:
283 v
= SUPPORTED_MIXER_DEVICES
& ~(SOUND_MASK_BASS
| SOUND_MASK_TREBLE
);
286 case SOUND_MIXER_DEVMASK
:
287 v
= SUPPORTED_MIXER_DEVICES
;
290 case SOUND_MIXER_RECMASK
:
291 v
= POSSIBLE_RECORDING_DEVICES
& SUPPORTED_MIXER_DEVICES
;
294 case SOUND_MIXER_CAPS
:
295 v
= 0; /* No special capabilities */
299 v
= levels
[cmd
& 0xff];
303 return put_user(v
, (int *)arg
);
308 static struct mixer_operations pas_mixer_operations
=
311 "Pro Audio Spectrum 16",
320 levels
= load_mixer_volumes("PAS16_1", default_levels
, 1);
324 if ((d
= sound_alloc_mixerdev()) != -1)
326 audio_devs
[pas_audiodev
]->mixer_dev
= d
;
327 mixer_devs
[d
] = &pas_mixer_operations
;