3 * sound/oss/pas2_mixer.c
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)
17 * Bartlomiej Zolnierkiewicz : added __init to pas_init_mixer()
19 #include <linux/init.h>
20 #include "sound_config.h"
25 #define DEB(what) /* (what) */
28 extern int pas_translate_code
;
29 extern char pas_model
;
31 extern int pas_audiodev
;
33 static int rec_devices
= (SOUND_MASK_MIC
); /* Default recording source */
34 static int mode_control
;
36 #define POSSIBLE_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
37 SOUND_MASK_CD | SOUND_MASK_ALTPCM)
39 #define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
40 SOUND_MASK_CD | SOUND_MASK_ALTPCM | SOUND_MASK_IMIX | \
41 SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_RECLEV)
45 static int default_levels
[32] =
47 0x3232, /* Master Volume */
52 0x3232, /* PC Speaker */
53 0x4b4b, /* Ext Line */
56 0x6464, /* Recording monitor */
58 0x6464 /* Recording level */
62 mix_write(unsigned char data
, int ioaddr
)
65 * The Revision D cards have a problem with their MVA508 interface. The
66 * kludge-o-rama fix is to make a 16-bit quantity with identical LSB and
67 * MSBs out of the output byte and to do a 16-bit out to the mixer port -
68 * 1. We need to do this because it isn't timing problem but chip access
74 outw(data
| (data
<< 8), (ioaddr
+ pas_translate_code
) - 1);
77 pas_write(data
, ioaddr
);
81 mixer_output(int right_vol
, int left_vol
, int div
, int bits
,
82 int mixer
) /* Input or output mixer */
84 int left
= left_vol
* div
/ 100;
85 int right
= right_vol
* div
/ 100;
93 if (bits
== 0x03 || bits
== 0x04)
95 mix_write(0x80 | bits
, 0x078B);
96 mix_write(left
, 0x078B);
100 mix_write(0x80 | 0x20 | bits
, 0x078B);
101 mix_write(left
, 0x078B);
102 mix_write(0x80 | 0x40 | bits
, 0x078B);
103 mix_write(right
, 0x078B);
106 return (left_vol
| (right_vol
<< 8));
110 set_mode(int new_mode
)
112 mix_write(0x80 | 0x05, 0x078B);
113 mix_write(new_mode
, 0x078B);
115 mode_control
= new_mode
;
119 pas_mixer_set(int whichDev
, unsigned int level
)
121 int left
, right
, devmask
, changed
, i
, mixer
= 0;
123 DEB(printk("static int pas_mixer_set(int whichDev = %d, unsigned int level = %X)\n", whichDev
, level
));
126 right
= (level
& 0x7f00) >> 8;
128 if (whichDev
< SOUND_MIXER_NRDEVICES
) {
129 if ((1 << whichDev
) & rec_devices
)
137 case SOUND_MIXER_VOLUME
: /* Master volume (0-63) */
138 levels
[whichDev
] = mixer_output(right
, left
, 63, 0x01, 0);
142 * Note! Bass and Treble are mono devices. Will use just the left
145 case SOUND_MIXER_BASS
: /* Bass (0-12) */
146 levels
[whichDev
] = mixer_output(right
, left
, 12, 0x03, 0);
148 case SOUND_MIXER_TREBLE
: /* Treble (0-12) */
149 levels
[whichDev
] = mixer_output(right
, left
, 12, 0x04, 0);
152 case SOUND_MIXER_SYNTH
: /* Internal synthesizer (0-31) */
153 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x00, mixer
);
155 case SOUND_MIXER_PCM
: /* PAS PCM (0-31) */
156 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x05, mixer
);
158 case SOUND_MIXER_ALTPCM
: /* SB PCM (0-31) */
159 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x07, mixer
);
161 case SOUND_MIXER_SPEAKER
: /* PC speaker (0-31) */
162 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x06, mixer
);
164 case SOUND_MIXER_LINE
: /* External line (0-31) */
165 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x02, mixer
);
167 case SOUND_MIXER_CD
: /* CD (0-31) */
168 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x03, mixer
);
170 case SOUND_MIXER_MIC
: /* External microphone (0-31) */
171 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x04, mixer
);
173 case SOUND_MIXER_IMIX
: /* Recording monitor (0-31) (Output mixer only) */
174 levels
[whichDev
] = mixer_output(right
, left
, 31, 0x10 | 0x01,
177 case SOUND_MIXER_RECLEV
: /* Recording level (0-15) */
178 levels
[whichDev
] = mixer_output(right
, left
, 15, 0x02, 0);
182 case SOUND_MIXER_RECSRC
:
183 devmask
= level
& POSSIBLE_RECORDING_DEVICES
;
185 changed
= devmask
^ rec_devices
;
186 rec_devices
= devmask
;
188 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
189 if (changed
& (1 << i
))
191 pas_mixer_set(i
, levels
[i
]);
200 return (levels
[whichDev
]);
206 pas_mixer_reset(void)
210 DEB(printk("pas2_mixer.c: void pas_mixer_reset(void)\n"));
212 for (foo
= 0; foo
< SOUND_MIXER_NRDEVICES
; foo
++)
213 pas_mixer_set(foo
, levels
[foo
]);
215 set_mode(0x04 | 0x01);
218 static int pas_mixer_ioctl(int dev
, unsigned int cmd
, void __user
*arg
)
221 int __user
*p
= (int __user
*)arg
;
223 DEB(printk("pas2_mixer.c: int pas_mixer_ioctl(unsigned int cmd = %X, unsigned int arg = %X)\n", cmd
, arg
));
224 if (cmd
== SOUND_MIXER_PRIVATE1
) { /* Set loudness bit */
225 if (get_user(level
, p
))
227 if (level
== -1) /* Return current settings */
228 level
= (mode_control
& 0x04);
230 mode_control
&= ~0x04;
232 mode_control
|= 0x04;
233 set_mode(mode_control
);
236 return put_user(level
, p
);
238 if (cmd
== SOUND_MIXER_PRIVATE2
) { /* Set enhance bit */
239 if (get_user(level
, p
))
241 if (level
== -1) { /* Return current settings */
242 if (!(mode_control
& 0x03))
245 level
= ((mode_control
& 0x03) + 1) * 20;
251 i
= (level
/ 20) - 1;
252 mode_control
&= ~0x03;
253 mode_control
|= i
& 0x03;
254 set_mode(mode_control
);
259 return put_user(level
, p
);
261 if (cmd
== SOUND_MIXER_PRIVATE3
) { /* Set mute bit */
262 if (get_user(level
, p
))
264 if (level
== -1) /* Return current settings */
265 level
= !(pas_read(0x0B8A) & 0x20);
268 pas_write(pas_read(0x0B8A) & (~0x20), 0x0B8A);
270 pas_write(pas_read(0x0B8A) | 0x20, 0x0B8A);
272 level
= !(pas_read(0x0B8A) & 0x20);
274 return put_user(level
, p
);
276 if (((cmd
>> 8) & 0xff) == 'M') {
279 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
) {
280 v
= pas_mixer_set(cmd
& 0xff, v
);
282 switch (cmd
& 0xff) {
283 case SOUND_MIXER_RECSRC
:
287 case SOUND_MIXER_STEREODEVS
:
288 v
= SUPPORTED_MIXER_DEVICES
& ~(SOUND_MASK_BASS
| SOUND_MASK_TREBLE
);
291 case SOUND_MIXER_DEVMASK
:
292 v
= SUPPORTED_MIXER_DEVICES
;
295 case SOUND_MIXER_RECMASK
:
296 v
= POSSIBLE_RECORDING_DEVICES
& SUPPORTED_MIXER_DEVICES
;
299 case SOUND_MIXER_CAPS
:
300 v
= 0; /* No special capabilities */
304 v
= levels
[cmd
& 0xff];
308 return put_user(v
, p
);
313 static struct mixer_operations pas_mixer_operations
=
315 .owner
= THIS_MODULE
,
317 .name
= "Pro Audio Spectrum 16",
318 .ioctl
= pas_mixer_ioctl
326 levels
= load_mixer_volumes("PAS16_1", default_levels
, 1);
330 if ((d
= sound_alloc_mixerdev()) != -1)
332 audio_devs
[pas_audiodev
]->mixer_dev
= d
;
333 mixer_devs
[d
] = &pas_mixer_operations
;