[CIFS] Fix minor checkpatch warning and update cifs version
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / sound / oss / pas2_mixer.c
bloba0bcb85c39046a8c4878b6367e6bd2cc938e2140
2 /*
3 * sound/oss/pas2_mixer.c
5 * Mixer routines for the Pro Audio Spectrum cards.
6 */
8 /*
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
13 * for more info.
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"
22 #include "pas2.h"
24 #ifndef DEB
25 #define DEB(what) /* (what) */
26 #endif
28 extern int pas_translate_code;
29 extern char pas_model;
30 extern int *pas_osp;
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)
43 static int *levels;
45 static int default_levels[32] =
47 0x3232, /* Master Volume */
48 0x3232, /* Bass */
49 0x3232, /* Treble */
50 0x5050, /* FM */
51 0x4b4b, /* PCM */
52 0x3232, /* PC Speaker */
53 0x4b4b, /* Ext Line */
54 0x4b4b, /* Mic */
55 0x4b4b, /* CD */
56 0x6464, /* Recording monitor */
57 0x4b4b, /* SB PCM */
58 0x6464 /* Recording level */
61 void
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
69 * sequence problem.
72 if (pas_model == 4)
74 outw(data | (data << 8), (ioaddr + pas_translate_code) - 1);
75 outb((0x80), 0);
76 } else
77 pas_write(data, ioaddr);
80 static int
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;
88 if (bits & 0x10)
90 left |= mixer;
91 right |= mixer;
93 if (bits == 0x03 || bits == 0x04)
95 mix_write(0x80 | bits, 0x078B);
96 mix_write(left, 0x078B);
97 right_vol = left_vol;
98 } else
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));
109 static void
110 set_mode(int new_mode)
112 mix_write(0x80 | 0x05, 0x078B);
113 mix_write(new_mode, 0x078B);
115 mode_control = new_mode;
118 static int
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));
125 left = level & 0x7f;
126 right = (level & 0x7f00) >> 8;
128 if (whichDev < SOUND_MIXER_NRDEVICES) {
129 if ((1 << whichDev) & rec_devices)
130 mixer = 0x20;
131 else
132 mixer = 0x00;
135 switch (whichDev)
137 case SOUND_MIXER_VOLUME: /* Master volume (0-63) */
138 levels[whichDev] = mixer_output(right, left, 63, 0x01, 0);
139 break;
142 * Note! Bass and Treble are mono devices. Will use just the left
143 * channel.
145 case SOUND_MIXER_BASS: /* Bass (0-12) */
146 levels[whichDev] = mixer_output(right, left, 12, 0x03, 0);
147 break;
148 case SOUND_MIXER_TREBLE: /* Treble (0-12) */
149 levels[whichDev] = mixer_output(right, left, 12, 0x04, 0);
150 break;
152 case SOUND_MIXER_SYNTH: /* Internal synthesizer (0-31) */
153 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x00, mixer);
154 break;
155 case SOUND_MIXER_PCM: /* PAS PCM (0-31) */
156 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x05, mixer);
157 break;
158 case SOUND_MIXER_ALTPCM: /* SB PCM (0-31) */
159 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x07, mixer);
160 break;
161 case SOUND_MIXER_SPEAKER: /* PC speaker (0-31) */
162 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x06, mixer);
163 break;
164 case SOUND_MIXER_LINE: /* External line (0-31) */
165 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x02, mixer);
166 break;
167 case SOUND_MIXER_CD: /* CD (0-31) */
168 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x03, mixer);
169 break;
170 case SOUND_MIXER_MIC: /* External microphone (0-31) */
171 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x04, mixer);
172 break;
173 case SOUND_MIXER_IMIX: /* Recording monitor (0-31) (Output mixer only) */
174 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x01,
175 0x00);
176 break;
177 case SOUND_MIXER_RECLEV: /* Recording level (0-15) */
178 levels[whichDev] = mixer_output(right, left, 15, 0x02, 0);
179 break;
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]);
193 return rec_devices;
194 break;
196 default:
197 return -EINVAL;
200 return (levels[whichDev]);
203 /*****/
205 static void
206 pas_mixer_reset(void)
208 int foo;
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)
220 int level,v ;
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))
226 return -EFAULT;
227 if (level == -1) /* Return current settings */
228 level = (mode_control & 0x04);
229 else {
230 mode_control &= ~0x04;
231 if (level)
232 mode_control |= 0x04;
233 set_mode(mode_control);
235 level = !!level;
236 return put_user(level, p);
238 if (cmd == SOUND_MIXER_PRIVATE2) { /* Set enhance bit */
239 if (get_user(level, p))
240 return -EFAULT;
241 if (level == -1) { /* Return current settings */
242 if (!(mode_control & 0x03))
243 level = 0;
244 else
245 level = ((mode_control & 0x03) + 1) * 20;
246 } else {
247 int i = 0;
249 level &= 0x7f;
250 if (level)
251 i = (level / 20) - 1;
252 mode_control &= ~0x03;
253 mode_control |= i & 0x03;
254 set_mode(mode_control);
255 if (i)
256 i = (i + 1) * 20;
257 level = i;
259 return put_user(level, p);
261 if (cmd == SOUND_MIXER_PRIVATE3) { /* Set mute bit */
262 if (get_user(level, p))
263 return -EFAULT;
264 if (level == -1) /* Return current settings */
265 level = !(pas_read(0x0B8A) & 0x20);
266 else {
267 if (level)
268 pas_write(pas_read(0x0B8A) & (~0x20), 0x0B8A);
269 else
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') {
277 if (get_user(v, p))
278 return -EFAULT;
279 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
280 v = pas_mixer_set(cmd & 0xff, v);
281 } else {
282 switch (cmd & 0xff) {
283 case SOUND_MIXER_RECSRC:
284 v = rec_devices;
285 break;
287 case SOUND_MIXER_STEREODEVS:
288 v = SUPPORTED_MIXER_DEVICES & ~(SOUND_MASK_BASS | SOUND_MASK_TREBLE);
289 break;
291 case SOUND_MIXER_DEVMASK:
292 v = SUPPORTED_MIXER_DEVICES;
293 break;
295 case SOUND_MIXER_RECMASK:
296 v = POSSIBLE_RECORDING_DEVICES & SUPPORTED_MIXER_DEVICES;
297 break;
299 case SOUND_MIXER_CAPS:
300 v = 0; /* No special capabilities */
301 break;
303 default:
304 v = levels[cmd & 0xff];
305 break;
308 return put_user(v, p);
310 return -EINVAL;
313 static struct mixer_operations pas_mixer_operations =
315 .owner = THIS_MODULE,
316 .id = "PAS16",
317 .name = "Pro Audio Spectrum 16",
318 .ioctl = pas_mixer_ioctl
321 int __init
322 pas_init_mixer(void)
324 int d;
326 levels = load_mixer_volumes("PAS16_1", default_levels, 1);
328 pas_mixer_reset();
330 if ((d = sound_alloc_mixerdev()) != -1)
332 audio_devs[pas_audiodev]->mixer_dev = d;
333 mixer_devs[d] = &pas_mixer_operations;
335 return 1;