2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>,
3 * Takashi Iwai <tiwai@suse.de>
5 * Routines for control of EMU10K1 chips / mixer routines
6 * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <sound/driver.h>
31 #include <linux/time.h>
32 #include <linux/init.h>
33 #include <sound/core.h>
34 #include <sound/emu10k1.h>
36 #define AC97_ID_STAC9758 0x83847658
38 static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
40 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
45 static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol,
46 struct snd_ctl_elem_value *ucontrol)
48 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
49 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
52 spin_lock_irqsave(&emu->reg_lock, flags);
53 ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
54 ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
55 ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
56 ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
57 spin_unlock_irqrestore(&emu->reg_lock, flags);
61 static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
62 struct snd_ctl_elem_value *ucontrol)
64 ucontrol->value.iec958.status[0] = 0xff;
65 ucontrol->value.iec958.status[1] = 0xff;
66 ucontrol->value.iec958.status[2] = 0xff;
67 ucontrol->value.iec958.status[3] = 0xff;
72 static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
74 static char *texts[] = {"44100", "48000", "96000"};
76 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
78 uinfo->value.enumerated.items = 3;
79 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
80 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
81 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
85 static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
86 struct snd_ctl_elem_value *ucontrol)
88 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
93 spin_lock_irqsave(&emu->reg_lock, flags);
94 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
95 switch (tmp & A_SPDIF_RATE_MASK) {
97 ucontrol->value.enumerated.item[0] = 0;
100 ucontrol->value.enumerated.item[0] = 1;
103 ucontrol->value.enumerated.item[0] = 2;
106 ucontrol->value.enumerated.item[0] = 1;
108 spin_unlock_irqrestore(&emu->reg_lock, flags);
112 static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol,
113 struct snd_ctl_elem_value *ucontrol)
115 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
117 unsigned int reg, val, tmp;
120 switch(ucontrol->value.enumerated.item[0]) {
136 spin_lock_irqsave(&emu->reg_lock, flags);
137 reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
138 tmp = reg & ~A_SPDIF_RATE_MASK;
140 if ((change = (tmp != reg)))
141 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
142 spin_unlock_irqrestore(&emu->reg_lock, flags);
146 static struct snd_kcontrol_new snd_audigy_spdif_output_rate =
148 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
149 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
150 .name = "Audigy SPDIF Output Sample Rate",
152 .info = snd_audigy_spdif_output_rate_info,
153 .get = snd_audigy_spdif_output_rate_get,
154 .put = snd_audigy_spdif_output_rate_put
158 static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol,
159 struct snd_ctl_elem_value *ucontrol)
161 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
162 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
167 val = (ucontrol->value.iec958.status[0] << 0) |
168 (ucontrol->value.iec958.status[1] << 8) |
169 (ucontrol->value.iec958.status[2] << 16) |
170 (ucontrol->value.iec958.status[3] << 24);
171 spin_lock_irqsave(&emu->reg_lock, flags);
172 change = val != emu->spdif_bits[idx];
174 snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val);
175 emu->spdif_bits[idx] = val;
177 spin_unlock_irqrestore(&emu->reg_lock, flags);
181 static struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
183 .access = SNDRV_CTL_ELEM_ACCESS_READ,
184 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
185 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
187 .info = snd_emu10k1_spdif_info,
188 .get = snd_emu10k1_spdif_get_mask
191 static struct snd_kcontrol_new snd_emu10k1_spdif_control =
193 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
194 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
196 .info = snd_emu10k1_spdif_info,
197 .get = snd_emu10k1_spdif_get,
198 .put = snd_emu10k1_spdif_put
202 static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route)
205 snd_emu10k1_ptr_write(emu, A_FXRT1, voice,
206 snd_emu10k1_compose_audigy_fxrt1(route));
207 snd_emu10k1_ptr_write(emu, A_FXRT2, voice,
208 snd_emu10k1_compose_audigy_fxrt2(route));
210 snd_emu10k1_ptr_write(emu, FXRT, voice,
211 snd_emu10k1_compose_send_routing(route));
215 static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume)
217 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]);
218 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]);
219 snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]);
220 snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]);
222 unsigned int val = ((unsigned int)volume[4] << 24) |
223 ((unsigned int)volume[5] << 16) |
224 ((unsigned int)volume[6] << 8) |
225 (unsigned int)volume[7];
226 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice, val);
230 /* PCM stream controls */
232 static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
234 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
235 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
236 uinfo->count = emu->audigy ? 3*8 : 3*4;
237 uinfo->value.integer.min = 0;
238 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
242 static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_value *ucontrol)
246 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
247 struct snd_emu10k1_pcm_mixer *mix =
248 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
250 int num_efx = emu->audigy ? 8 : 4;
251 int mask = emu->audigy ? 0x3f : 0x0f;
253 spin_lock_irqsave(&emu->reg_lock, flags);
254 for (voice = 0; voice < 3; voice++)
255 for (idx = 0; idx < num_efx; idx++)
256 ucontrol->value.integer.value[(voice * num_efx) + idx] =
257 mix->send_routing[voice][idx] & mask;
258 spin_unlock_irqrestore(&emu->reg_lock, flags);
262 static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol,
263 struct snd_ctl_elem_value *ucontrol)
266 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
267 struct snd_emu10k1_pcm_mixer *mix =
268 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
269 int change = 0, voice, idx, val;
270 int num_efx = emu->audigy ? 8 : 4;
271 int mask = emu->audigy ? 0x3f : 0x0f;
273 spin_lock_irqsave(&emu->reg_lock, flags);
274 for (voice = 0; voice < 3; voice++)
275 for (idx = 0; idx < num_efx; idx++) {
276 val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask;
277 if (mix->send_routing[voice][idx] != val) {
278 mix->send_routing[voice][idx] = val;
282 if (change && mix->epcm) {
283 if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
284 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
285 &mix->send_routing[1][0]);
286 update_emu10k1_fxrt(emu, mix->epcm->voices[1]->number,
287 &mix->send_routing[2][0]);
288 } else if (mix->epcm->voices[0]) {
289 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
290 &mix->send_routing[0][0]);
293 spin_unlock_irqrestore(&emu->reg_lock, flags);
297 static struct snd_kcontrol_new snd_emu10k1_send_routing_control =
299 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
300 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
301 .name = "EMU10K1 PCM Send Routing",
303 .info = snd_emu10k1_send_routing_info,
304 .get = snd_emu10k1_send_routing_get,
305 .put = snd_emu10k1_send_routing_put
308 static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
310 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
311 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
312 uinfo->count = emu->audigy ? 3*8 : 3*4;
313 uinfo->value.integer.min = 0;
314 uinfo->value.integer.max = 255;
318 static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol,
319 struct snd_ctl_elem_value *ucontrol)
322 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
323 struct snd_emu10k1_pcm_mixer *mix =
324 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
326 int num_efx = emu->audigy ? 8 : 4;
328 spin_lock_irqsave(&emu->reg_lock, flags);
329 for (idx = 0; idx < 3*num_efx; idx++)
330 ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx];
331 spin_unlock_irqrestore(&emu->reg_lock, flags);
335 static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol,
336 struct snd_ctl_elem_value *ucontrol)
339 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
340 struct snd_emu10k1_pcm_mixer *mix =
341 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
342 int change = 0, idx, val;
343 int num_efx = emu->audigy ? 8 : 4;
345 spin_lock_irqsave(&emu->reg_lock, flags);
346 for (idx = 0; idx < 3*num_efx; idx++) {
347 val = ucontrol->value.integer.value[idx] & 255;
348 if (mix->send_volume[idx/num_efx][idx%num_efx] != val) {
349 mix->send_volume[idx/num_efx][idx%num_efx] = val;
353 if (change && mix->epcm) {
354 if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
355 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
356 &mix->send_volume[1][0]);
357 update_emu10k1_send_volume(emu, mix->epcm->voices[1]->number,
358 &mix->send_volume[2][0]);
359 } else if (mix->epcm->voices[0]) {
360 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
361 &mix->send_volume[0][0]);
364 spin_unlock_irqrestore(&emu->reg_lock, flags);
368 static struct snd_kcontrol_new snd_emu10k1_send_volume_control =
370 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
371 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
372 .name = "EMU10K1 PCM Send Volume",
374 .info = snd_emu10k1_send_volume_info,
375 .get = snd_emu10k1_send_volume_get,
376 .put = snd_emu10k1_send_volume_put
379 static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
381 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
383 uinfo->value.integer.min = 0;
384 uinfo->value.integer.max = 0xffff;
388 static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,
389 struct snd_ctl_elem_value *ucontrol)
391 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
392 struct snd_emu10k1_pcm_mixer *mix =
393 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
397 spin_lock_irqsave(&emu->reg_lock, flags);
398 for (idx = 0; idx < 3; idx++)
399 ucontrol->value.integer.value[idx] = mix->attn[idx];
400 spin_unlock_irqrestore(&emu->reg_lock, flags);
404 static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,
405 struct snd_ctl_elem_value *ucontrol)
408 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
409 struct snd_emu10k1_pcm_mixer *mix =
410 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
411 int change = 0, idx, val;
413 spin_lock_irqsave(&emu->reg_lock, flags);
414 for (idx = 0; idx < 3; idx++) {
415 val = ucontrol->value.integer.value[idx] & 0xffff;
416 if (mix->attn[idx] != val) {
417 mix->attn[idx] = val;
421 if (change && mix->epcm) {
422 if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
423 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]);
424 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[1]->number, mix->attn[2]);
425 } else if (mix->epcm->voices[0]) {
426 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]);
429 spin_unlock_irqrestore(&emu->reg_lock, flags);
433 static struct snd_kcontrol_new snd_emu10k1_attn_control =
435 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
436 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
437 .name = "EMU10K1 PCM Volume",
439 .info = snd_emu10k1_attn_info,
440 .get = snd_emu10k1_attn_get,
441 .put = snd_emu10k1_attn_put
444 /* Mutichannel PCM stream controls */
446 static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
448 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
449 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
450 uinfo->count = emu->audigy ? 8 : 4;
451 uinfo->value.integer.min = 0;
452 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
456 static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol,
457 struct snd_ctl_elem_value *ucontrol)
460 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
461 struct snd_emu10k1_pcm_mixer *mix =
462 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
464 int num_efx = emu->audigy ? 8 : 4;
465 int mask = emu->audigy ? 0x3f : 0x0f;
467 spin_lock_irqsave(&emu->reg_lock, flags);
468 for (idx = 0; idx < num_efx; idx++)
469 ucontrol->value.integer.value[idx] =
470 mix->send_routing[0][idx] & mask;
471 spin_unlock_irqrestore(&emu->reg_lock, flags);
475 static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol,
476 struct snd_ctl_elem_value *ucontrol)
479 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
480 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
481 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
482 int change = 0, idx, val;
483 int num_efx = emu->audigy ? 8 : 4;
484 int mask = emu->audigy ? 0x3f : 0x0f;
486 spin_lock_irqsave(&emu->reg_lock, flags);
487 for (idx = 0; idx < num_efx; idx++) {
488 val = ucontrol->value.integer.value[idx] & mask;
489 if (mix->send_routing[0][idx] != val) {
490 mix->send_routing[0][idx] = val;
495 if (change && mix->epcm) {
496 if (mix->epcm->voices[ch]) {
497 update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number,
498 &mix->send_routing[0][0]);
501 spin_unlock_irqrestore(&emu->reg_lock, flags);
505 static struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
507 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
508 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
509 .name = "Multichannel PCM Send Routing",
511 .info = snd_emu10k1_efx_send_routing_info,
512 .get = snd_emu10k1_efx_send_routing_get,
513 .put = snd_emu10k1_efx_send_routing_put
516 static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
518 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
519 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
520 uinfo->count = emu->audigy ? 8 : 4;
521 uinfo->value.integer.min = 0;
522 uinfo->value.integer.max = 255;
526 static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol,
527 struct snd_ctl_elem_value *ucontrol)
530 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
531 struct snd_emu10k1_pcm_mixer *mix =
532 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
534 int num_efx = emu->audigy ? 8 : 4;
536 spin_lock_irqsave(&emu->reg_lock, flags);
537 for (idx = 0; idx < num_efx; idx++)
538 ucontrol->value.integer.value[idx] = mix->send_volume[0][idx];
539 spin_unlock_irqrestore(&emu->reg_lock, flags);
543 static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol,
544 struct snd_ctl_elem_value *ucontrol)
547 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
548 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
549 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
550 int change = 0, idx, val;
551 int num_efx = emu->audigy ? 8 : 4;
553 spin_lock_irqsave(&emu->reg_lock, flags);
554 for (idx = 0; idx < num_efx; idx++) {
555 val = ucontrol->value.integer.value[idx] & 255;
556 if (mix->send_volume[0][idx] != val) {
557 mix->send_volume[0][idx] = val;
561 if (change && mix->epcm) {
562 if (mix->epcm->voices[ch]) {
563 update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number,
564 &mix->send_volume[0][0]);
567 spin_unlock_irqrestore(&emu->reg_lock, flags);
572 static struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
574 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
575 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
576 .name = "Multichannel PCM Send Volume",
578 .info = snd_emu10k1_efx_send_volume_info,
579 .get = snd_emu10k1_efx_send_volume_get,
580 .put = snd_emu10k1_efx_send_volume_put
583 static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
585 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
587 uinfo->value.integer.min = 0;
588 uinfo->value.integer.max = 0xffff;
592 static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol,
593 struct snd_ctl_elem_value *ucontrol)
595 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
596 struct snd_emu10k1_pcm_mixer *mix =
597 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
600 spin_lock_irqsave(&emu->reg_lock, flags);
601 ucontrol->value.integer.value[0] = mix->attn[0];
602 spin_unlock_irqrestore(&emu->reg_lock, flags);
606 static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol,
607 struct snd_ctl_elem_value *ucontrol)
610 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
611 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
612 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
615 spin_lock_irqsave(&emu->reg_lock, flags);
616 val = ucontrol->value.integer.value[0] & 0xffff;
617 if (mix->attn[0] != val) {
621 if (change && mix->epcm) {
622 if (mix->epcm->voices[ch]) {
623 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]);
626 spin_unlock_irqrestore(&emu->reg_lock, flags);
630 static struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
632 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
633 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
634 .name = "Multichannel PCM Volume",
636 .info = snd_emu10k1_efx_attn_info,
637 .get = snd_emu10k1_efx_attn_get,
638 .put = snd_emu10k1_efx_attn_put
641 static int snd_emu10k1_shared_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
643 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
645 uinfo->value.integer.min = 0;
646 uinfo->value.integer.max = 1;
650 static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_value *ucontrol)
653 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
656 ucontrol->value.integer.value[0] = inl(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
658 ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
662 static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
663 struct snd_ctl_elem_value *ucontrol)
666 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
667 unsigned int reg, val;
670 spin_lock_irqsave(&emu->reg_lock, flags);
672 reg = inl(emu->port + A_IOCFG);
673 val = ucontrol->value.integer.value[0] ? A_IOCFG_GPOUT0 : 0;
674 change = (reg & A_IOCFG_GPOUT0) != val;
676 reg &= ~A_IOCFG_GPOUT0;
678 outl(reg | val, emu->port + A_IOCFG);
681 reg = inl(emu->port + HCFG);
682 val = ucontrol->value.integer.value[0] ? HCFG_GPOUT0 : 0;
683 change |= (reg & HCFG_GPOUT0) != val;
687 outl(reg | val, emu->port + HCFG);
689 spin_unlock_irqrestore(&emu->reg_lock, flags);
693 static struct snd_kcontrol_new snd_emu10k1_shared_spdif __devinitdata =
695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
696 .name = "SB Live Analog/Digital Output Jack",
697 .info = snd_emu10k1_shared_spdif_info,
698 .get = snd_emu10k1_shared_spdif_get,
699 .put = snd_emu10k1_shared_spdif_put
702 static struct snd_kcontrol_new snd_audigy_shared_spdif __devinitdata =
704 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
705 .name = "Audigy Analog/Digital Output Jack",
706 .info = snd_emu10k1_shared_spdif_info,
707 .get = snd_emu10k1_shared_spdif_get,
708 .put = snd_emu10k1_shared_spdif_put
713 static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
715 struct snd_emu10k1 *emu = ac97->private_data;
721 static int remove_ctl(struct snd_card *card, const char *name)
723 struct snd_ctl_elem_id id;
724 memset(&id, 0, sizeof(id));
725 strcpy(id.name, name);
726 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
727 return snd_ctl_remove_id(card, &id);
730 static struct snd_kcontrol *ctl_find(struct snd_card *card, const char *name)
732 struct snd_ctl_elem_id sid;
733 memset(&sid, 0, sizeof(sid));
734 strcpy(sid.name, name);
735 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
736 return snd_ctl_find_id(card, &sid);
739 static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
741 struct snd_kcontrol *kctl = ctl_find(card, src);
743 strcpy(kctl->id.name, dst);
749 int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
750 int pcm_device, int multi_device)
753 struct snd_kcontrol *kctl;
754 struct snd_card *card = emu->card;
756 static char *emu10k1_remove_ctls[] = {
757 /* no AC97 mono, surround, center/lfe */
758 "Master Mono Playback Switch",
759 "Master Mono Playback Volume",
760 "PCM Out Path & Mute",
761 "Mono Output Select",
762 "Front Playback Switch",
763 "Front Playback Volume",
764 "Surround Playback Switch",
765 "Surround Playback Volume",
766 "Center Playback Switch",
767 "Center Playback Volume",
768 "LFE Playback Switch",
769 "LFE Playback Volume",
772 static char *emu10k1_rename_ctls[] = {
773 "Surround Digital Playback Volume", "Surround Playback Volume",
774 "Center Digital Playback Volume", "Center Playback Volume",
775 "LFE Digital Playback Volume", "LFE Playback Volume",
778 static char *audigy_remove_ctls[] = {
779 /* Master/PCM controls on ac97 of Audigy has no effect */
780 /* On the Audigy2 the AC97 playback is piped into
781 * the Philips ADC for 24bit capture */
782 "PCM Playback Switch",
783 "PCM Playback Volume",
784 "Master Mono Playback Switch",
785 "Master Mono Playback Volume",
786 "Master Playback Switch",
787 "Master Playback Volume",
788 "PCM Out Path & Mute",
789 "Mono Output Select",
790 /* remove unused AC97 capture controls */
795 "Video Playback Switch",
796 "Video Playback Volume",
797 "Mic Playback Switch",
798 "Mic Playback Volume",
801 static char *audigy_rename_ctls[] = {
802 /* use conventional names */
803 "Wave Playback Volume", "PCM Playback Volume",
804 /* "Wave Capture Volume", "PCM Capture Volume", */
805 "Wave Master Playback Volume", "Master Playback Volume",
806 "AMic Playback Volume", "Mic Playback Volume",
809 static char *audigy_remove_ctls_1361t_adc[] = {
810 /* On the Audigy2 the AC97 playback is piped into
811 * the Philips ADC for 24bit capture */
812 "PCM Playback Switch",
813 "PCM Playback Volume",
814 "Master Mono Playback Switch",
815 "Master Mono Playback Volume",
819 "Mic Capture Volume",
820 "Headphone Playback Switch",
821 "Headphone Playback Volume",
822 "3D Control - Center",
823 "3D Control - Depth",
824 "3D Control - Switch",
825 "Line2 Playback Volume",
826 "Line2 Capture Volume",
829 static char *audigy_rename_ctls_1361t_adc[] = {
830 "Master Playback Switch", "Master Capture Switch",
831 "Master Playback Volume", "Master Capture Volume",
832 "Wave Master Playback Volume", "Master Playback Volume",
833 "PC Speaker Playback Switch", "PC Speaker Capture Switch",
834 "PC Speaker Playback Volume", "PC Speaker Capture Volume",
835 "Phone Playback Switch", "Phone Capture Switch",
836 "Phone Playback Volume", "Phone Capture Volume",
837 "Mic Playback Switch", "Mic Capture Switch",
838 "Mic Playback Volume", "Mic Capture Volume",
839 "Line Playback Switch", "Line Capture Switch",
840 "Line Playback Volume", "Line Capture Volume",
841 "CD Playback Switch", "CD Capture Switch",
842 "CD Playback Volume", "CD Capture Volume",
843 "Aux Playback Switch", "Aux Capture Switch",
844 "Aux Playback Volume", "Aux Capture Volume",
845 "Video Playback Switch", "Video Capture Switch",
846 "Video Playback Volume", "Video Capture Volume",
851 if (emu->card_capabilities->ac97_chip) {
852 struct snd_ac97_bus *pbus;
853 struct snd_ac97_template ac97;
854 static struct snd_ac97_bus_ops ops = {
855 .write = snd_emu10k1_ac97_write,
856 .read = snd_emu10k1_ac97_read,
859 if ((err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus)) < 0)
861 pbus->no_vra = 1; /* we don't need VRA */
863 memset(&ac97, 0, sizeof(ac97));
864 ac97.private_data = emu;
865 ac97.private_free = snd_emu10k1_mixer_free_ac97;
866 ac97.scaps = AC97_SCAP_NO_SPDIF;
867 if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0) {
868 if (emu->card_capabilities->ac97_chip == 1)
870 snd_printd(KERN_INFO "emu10k1: AC97 is optional on this board\n");
871 snd_printd(KERN_INFO" Proceeding without ac97 mixers...\n");
872 snd_device_free(emu->card, pbus);
873 goto no_ac97; /* FIXME: get rid of ugly gotos.. */
876 /* set master volume to 0 dB */
877 snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000);
878 /* set capture source to mic */
879 snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
880 if (emu->card_capabilities->adc_1361t)
881 c = audigy_remove_ctls_1361t_adc;
883 c = audigy_remove_ctls;
886 * Credits for cards based on STAC9758:
887 * James Courtier-Dutton <James@superbug.demon.co.uk>
888 * Voluspa <voluspa@comhem.se>
890 if (emu->ac97->id == AC97_ID_STAC9758) {
892 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
894 /* remove unused AC97 controls */
895 snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
896 snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
897 c = emu10k1_remove_ctls;
900 remove_ctl(card, *c);
903 if (emu->card_capabilities->ecard)
904 strcpy(emu->card->mixername, "EMU APS");
905 else if (emu->audigy)
906 strcpy(emu->card->mixername, "SB Audigy");
908 strcpy(emu->card->mixername, "Emu10k1");
912 if (emu->card_capabilities->adc_1361t)
913 c = audigy_rename_ctls_1361t_adc;
915 c = audigy_rename_ctls;
917 c = emu10k1_rename_ctls;
919 rename_ctl(card, c[0], c[1]);
921 if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */
922 rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
923 rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
924 rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
925 rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
926 remove_ctl(card, "Headphone Playback Switch");
927 remove_ctl(card, "Headphone Playback Volume");
928 remove_ctl(card, "3D Control - Center");
929 remove_ctl(card, "3D Control - Depth");
930 remove_ctl(card, "3D Control - Switch");
932 if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL)
934 kctl->id.device = pcm_device;
935 if ((err = snd_ctl_add(card, kctl)))
937 if ((kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu)) == NULL)
939 kctl->id.device = pcm_device;
940 if ((err = snd_ctl_add(card, kctl)))
942 if ((kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu)) == NULL)
944 kctl->id.device = pcm_device;
945 if ((err = snd_ctl_add(card, kctl)))
948 if ((kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu)) == NULL)
950 kctl->id.device = multi_device;
951 if ((err = snd_ctl_add(card, kctl)))
954 if ((kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu)) == NULL)
956 kctl->id.device = multi_device;
957 if ((err = snd_ctl_add(card, kctl)))
960 if ((kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu)) == NULL)
962 kctl->id.device = multi_device;
963 if ((err = snd_ctl_add(card, kctl)))
966 /* initialize the routing and volume table for each pcm playback stream */
967 for (pcm = 0; pcm < 32; pcm++) {
968 struct snd_emu10k1_pcm_mixer *mix;
971 mix = &emu->pcm_mixer[pcm];
974 for (v = 0; v < 4; v++)
975 mix->send_routing[0][v] =
976 mix->send_routing[1][v] =
977 mix->send_routing[2][v] = v;
979 memset(&mix->send_volume, 0, sizeof(mix->send_volume));
980 mix->send_volume[0][0] = mix->send_volume[0][1] =
981 mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
983 mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
986 /* initialize the routing and volume table for the multichannel playback stream */
987 for (pcm = 0; pcm < NUM_EFX_PLAYBACK; pcm++) {
988 struct snd_emu10k1_pcm_mixer *mix;
991 mix = &emu->efx_pcm_mixer[pcm];
994 mix->send_routing[0][0] = pcm;
995 mix->send_routing[0][1] = (pcm == 0) ? 1 : 0;
996 for (v = 0; v < 2; v++)
997 mix->send_routing[0][2+v] = 13+v;
999 for (v = 0; v < 4; v++)
1000 mix->send_routing[0][4+v] = 60+v;
1002 memset(&mix->send_volume, 0, sizeof(mix->send_volume));
1003 mix->send_volume[0][0] = 255;
1005 mix->attn[0] = 0xffff;
1008 if (! emu->card_capabilities->ecard) { /* FIXME: APS has these controls? */
1009 /* sb live! and audigy */
1010 if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu)) == NULL)
1013 kctl->id.device = emu->pcm_efx->device;
1014 if ((err = snd_ctl_add(card, kctl)))
1016 if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu)) == NULL)
1019 kctl->id.device = emu->pcm_efx->device;
1020 if ((err = snd_ctl_add(card, kctl)))
1024 if ( emu->card_capabilities->emu1212m) {
1025 ; /* Disable the snd_audigy_spdif_shared_spdif */
1026 } else if (emu->audigy) {
1027 if ((kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu)) == NULL)
1029 if ((err = snd_ctl_add(card, kctl)))
1032 if ((kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu)) == NULL)
1034 if ((err = snd_ctl_add(card, kctl)))
1037 } else if (! emu->card_capabilities->ecard) {
1039 if ((kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu)) == NULL)
1041 if ((err = snd_ctl_add(card, kctl)))
1044 if (emu->card_capabilities->ca0151_chip) { /* P16V */
1045 if ((err = snd_p16v_mixer(emu)))