xref: /linux/sound/pci/emu10k1/emumixer.c (revision eb4698f347ec908c365504c4edddadd1acd406ea)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>,
31da177e4SLinus Torvalds  *                   Takashi Iwai <tiwai@suse.de>
41da177e4SLinus Torvalds  *                   Creative Labs, Inc.
51da177e4SLinus Torvalds  *  Routines for control of EMU10K1 chips / mixer routines
61da177e4SLinus Torvalds  *  Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  *  BUGS:
91da177e4SLinus Torvalds  *    --
101da177e4SLinus Torvalds  *
111da177e4SLinus Torvalds  *  TODO:
121da177e4SLinus Torvalds  *    --
131da177e4SLinus Torvalds  *
141da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
151da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
161da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
171da177e4SLinus Torvalds  *   (at your option) any later version.
181da177e4SLinus Torvalds  *
191da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
201da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
211da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
221da177e4SLinus Torvalds  *   GNU General Public License for more details.
231da177e4SLinus Torvalds  *
241da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
251da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
261da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
271da177e4SLinus Torvalds  *
281da177e4SLinus Torvalds  */
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds #include <sound/driver.h>
311da177e4SLinus Torvalds #include <linux/time.h>
321da177e4SLinus Torvalds #include <linux/init.h>
331da177e4SLinus Torvalds #include <sound/core.h>
341da177e4SLinus Torvalds #include <sound/emu10k1.h>
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds #define AC97_ID_STAC9758	0x83847658
371da177e4SLinus Torvalds 
38*eb4698f3STakashi Iwai static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
391da177e4SLinus Torvalds {
401da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
411da177e4SLinus Torvalds 	uinfo->count = 1;
421da177e4SLinus Torvalds 	return 0;
431da177e4SLinus Torvalds }
441da177e4SLinus Torvalds 
45*eb4698f3STakashi Iwai static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol,
46*eb4698f3STakashi Iwai                                  struct snd_ctl_elem_value *ucontrol)
471da177e4SLinus Torvalds {
48*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
491da177e4SLinus Torvalds 	unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
501da177e4SLinus Torvalds 	unsigned long flags;
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
531da177e4SLinus Torvalds 	ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
541da177e4SLinus Torvalds 	ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
551da177e4SLinus Torvalds 	ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
561da177e4SLinus Torvalds 	ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
571da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
581da177e4SLinus Torvalds 	return 0;
591da177e4SLinus Torvalds }
601da177e4SLinus Torvalds 
61*eb4698f3STakashi Iwai static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
62*eb4698f3STakashi Iwai 				      struct snd_ctl_elem_value *ucontrol)
631da177e4SLinus Torvalds {
641da177e4SLinus Torvalds 	ucontrol->value.iec958.status[0] = 0xff;
651da177e4SLinus Torvalds 	ucontrol->value.iec958.status[1] = 0xff;
661da177e4SLinus Torvalds 	ucontrol->value.iec958.status[2] = 0xff;
671da177e4SLinus Torvalds 	ucontrol->value.iec958.status[3] = 0xff;
681da177e4SLinus Torvalds 	return 0;
691da177e4SLinus Torvalds }
701da177e4SLinus Torvalds 
710af68e5eSTakashi Iwai #if 0
72*eb4698f3STakashi Iwai static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
731da177e4SLinus Torvalds {
741da177e4SLinus Torvalds 	static char *texts[] = {"44100", "48000", "96000"};
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
771da177e4SLinus Torvalds 	uinfo->count = 1;
781da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 3;
791da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
801da177e4SLinus Torvalds 		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
811da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
821da177e4SLinus Torvalds 	return 0;
831da177e4SLinus Torvalds }
841da177e4SLinus Torvalds 
85*eb4698f3STakashi Iwai static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
86*eb4698f3STakashi Iwai                                  struct snd_ctl_elem_value *ucontrol)
871da177e4SLinus Torvalds {
88*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
891da177e4SLinus Torvalds 	unsigned int tmp;
901da177e4SLinus Torvalds 	unsigned long flags;
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
941da177e4SLinus Torvalds 	tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
951da177e4SLinus Torvalds 	switch (tmp & A_SPDIF_RATE_MASK) {
961da177e4SLinus Torvalds 	case A_SPDIF_44100:
971da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 0;
981da177e4SLinus Torvalds 		break;
991da177e4SLinus Torvalds 	case A_SPDIF_48000:
1001da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1;
1011da177e4SLinus Torvalds 		break;
1021da177e4SLinus Torvalds 	case A_SPDIF_96000:
1031da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 2;
1041da177e4SLinus Torvalds 		break;
1051da177e4SLinus Torvalds 	default:
1061da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1;
1071da177e4SLinus Torvalds 	}
1081da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
1091da177e4SLinus Torvalds 	return 0;
1101da177e4SLinus Torvalds }
1111da177e4SLinus Torvalds 
112*eb4698f3STakashi Iwai static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol,
113*eb4698f3STakashi Iwai                                  struct snd_ctl_elem_value *ucontrol)
1141da177e4SLinus Torvalds {
115*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1161da177e4SLinus Torvalds 	int change;
1171da177e4SLinus Torvalds 	unsigned int reg, val, tmp;
1181da177e4SLinus Torvalds 	unsigned long flags;
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds 	switch(ucontrol->value.enumerated.item[0]) {
1211da177e4SLinus Torvalds 	case 0:
1221da177e4SLinus Torvalds 		val = A_SPDIF_44100;
1231da177e4SLinus Torvalds 		break;
1241da177e4SLinus Torvalds 	case 1:
1251da177e4SLinus Torvalds 		val = A_SPDIF_48000;
1261da177e4SLinus Torvalds 		break;
1271da177e4SLinus Torvalds 	case 2:
1281da177e4SLinus Torvalds 		val = A_SPDIF_96000;
1291da177e4SLinus Torvalds 		break;
1301da177e4SLinus Torvalds 	default:
1311da177e4SLinus Torvalds 		val = A_SPDIF_48000;
1321da177e4SLinus Torvalds 		break;
1331da177e4SLinus Torvalds 	}
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
1371da177e4SLinus Torvalds 	reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
1381da177e4SLinus Torvalds 	tmp = reg & ~A_SPDIF_RATE_MASK;
1391da177e4SLinus Torvalds 	tmp |= val;
1401da177e4SLinus Torvalds 	if ((change = (tmp != reg)))
1411da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
1421da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
1431da177e4SLinus Torvalds 	return change;
1441da177e4SLinus Torvalds }
1451da177e4SLinus Torvalds 
146*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_audigy_spdif_output_rate =
1471da177e4SLinus Torvalds {
1481da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE,
1491da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
1501da177e4SLinus Torvalds 	.name =         "Audigy SPDIF Output Sample Rate",
1511da177e4SLinus Torvalds 	.count =	1,
1521da177e4SLinus Torvalds 	.info =         snd_audigy_spdif_output_rate_info,
1531da177e4SLinus Torvalds 	.get =          snd_audigy_spdif_output_rate_get,
1541da177e4SLinus Torvalds 	.put =          snd_audigy_spdif_output_rate_put
1551da177e4SLinus Torvalds };
1560af68e5eSTakashi Iwai #endif
1571da177e4SLinus Torvalds 
158*eb4698f3STakashi Iwai static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol,
159*eb4698f3STakashi Iwai                                  struct snd_ctl_elem_value *ucontrol)
1601da177e4SLinus Torvalds {
161*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1621da177e4SLinus Torvalds 	unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1631da177e4SLinus Torvalds 	int change;
1641da177e4SLinus Torvalds 	unsigned int val;
1651da177e4SLinus Torvalds 	unsigned long flags;
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds 	val = (ucontrol->value.iec958.status[0] << 0) |
1681da177e4SLinus Torvalds 	      (ucontrol->value.iec958.status[1] << 8) |
1691da177e4SLinus Torvalds 	      (ucontrol->value.iec958.status[2] << 16) |
1701da177e4SLinus Torvalds 	      (ucontrol->value.iec958.status[3] << 24);
1711da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
1721da177e4SLinus Torvalds 	change = val != emu->spdif_bits[idx];
1731da177e4SLinus Torvalds 	if (change) {
1741da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val);
1751da177e4SLinus Torvalds 		emu->spdif_bits[idx] = val;
1761da177e4SLinus Torvalds 	}
1771da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
1781da177e4SLinus Torvalds 	return change;
1791da177e4SLinus Torvalds }
1801da177e4SLinus Torvalds 
181*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
1821da177e4SLinus Torvalds {
1831da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
1845549d549SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
1851da177e4SLinus Torvalds 	.name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
1861da177e4SLinus Torvalds 	.count =	4,
1871da177e4SLinus Torvalds 	.info =         snd_emu10k1_spdif_info,
1881da177e4SLinus Torvalds 	.get =          snd_emu10k1_spdif_get_mask
1891da177e4SLinus Torvalds };
1901da177e4SLinus Torvalds 
191*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_emu10k1_spdif_control =
1921da177e4SLinus Torvalds {
1935549d549SClemens Ladisch 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
1941da177e4SLinus Torvalds 	.name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1951da177e4SLinus Torvalds 	.count =	4,
1961da177e4SLinus Torvalds 	.info =         snd_emu10k1_spdif_info,
1971da177e4SLinus Torvalds 	.get =          snd_emu10k1_spdif_get,
1981da177e4SLinus Torvalds 	.put =          snd_emu10k1_spdif_put
1991da177e4SLinus Torvalds };
2001da177e4SLinus Torvalds 
2011da177e4SLinus Torvalds 
202*eb4698f3STakashi Iwai static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route)
2031da177e4SLinus Torvalds {
2041da177e4SLinus Torvalds 	if (emu->audigy) {
2051da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, A_FXRT1, voice,
2061da177e4SLinus Torvalds 				      snd_emu10k1_compose_audigy_fxrt1(route));
2071da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, A_FXRT2, voice,
2081da177e4SLinus Torvalds 				      snd_emu10k1_compose_audigy_fxrt2(route));
2091da177e4SLinus Torvalds 	} else {
2101da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, FXRT, voice,
2111da177e4SLinus Torvalds 				      snd_emu10k1_compose_send_routing(route));
2121da177e4SLinus Torvalds 	}
2131da177e4SLinus Torvalds }
2141da177e4SLinus Torvalds 
215*eb4698f3STakashi Iwai static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume)
2161da177e4SLinus Torvalds {
2171da177e4SLinus Torvalds 	snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]);
2181da177e4SLinus Torvalds 	snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]);
2191da177e4SLinus Torvalds 	snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]);
2201da177e4SLinus Torvalds 	snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]);
2211da177e4SLinus Torvalds 	if (emu->audigy) {
2221da177e4SLinus Torvalds 		unsigned int val = ((unsigned int)volume[4] << 24) |
2231da177e4SLinus Torvalds 			((unsigned int)volume[5] << 16) |
2241da177e4SLinus Torvalds 			((unsigned int)volume[6] << 8) |
2251da177e4SLinus Torvalds 			(unsigned int)volume[7];
2261da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice, val);
2271da177e4SLinus Torvalds 	}
2281da177e4SLinus Torvalds }
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds /* PCM stream controls */
2311da177e4SLinus Torvalds 
232*eb4698f3STakashi Iwai static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2331da177e4SLinus Torvalds {
234*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
2351da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2361da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 3*8 : 3*4;
2371da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
2381da177e4SLinus Torvalds 	uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
2391da177e4SLinus Torvalds 	return 0;
2401da177e4SLinus Torvalds }
2411da177e4SLinus Torvalds 
242*eb4698f3STakashi Iwai static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol,
243*eb4698f3STakashi Iwai                                         struct snd_ctl_elem_value *ucontrol)
2441da177e4SLinus Torvalds {
2451da177e4SLinus Torvalds 	unsigned long flags;
246*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
247*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
248*eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
2491da177e4SLinus Torvalds 	int voice, idx;
2501da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
2511da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
2521da177e4SLinus Torvalds 
2531da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
2541da177e4SLinus Torvalds 	for (voice = 0; voice < 3; voice++)
2551da177e4SLinus Torvalds 		for (idx = 0; idx < num_efx; idx++)
2561da177e4SLinus Torvalds 			ucontrol->value.integer.value[(voice * num_efx) + idx] =
2571da177e4SLinus Torvalds 				mix->send_routing[voice][idx] & mask;
2581da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
2591da177e4SLinus Torvalds 	return 0;
2601da177e4SLinus Torvalds }
2611da177e4SLinus Torvalds 
262*eb4698f3STakashi Iwai static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol,
263*eb4698f3STakashi Iwai                                         struct snd_ctl_elem_value *ucontrol)
2641da177e4SLinus Torvalds {
2651da177e4SLinus Torvalds 	unsigned long flags;
266*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
267*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
268*eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
2691da177e4SLinus Torvalds 	int change = 0, voice, idx, val;
2701da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
2711da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
2721da177e4SLinus Torvalds 
2731da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
2741da177e4SLinus Torvalds 	for (voice = 0; voice < 3; voice++)
2751da177e4SLinus Torvalds 		for (idx = 0; idx < num_efx; idx++) {
2761da177e4SLinus Torvalds 			val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask;
2771da177e4SLinus Torvalds 			if (mix->send_routing[voice][idx] != val) {
2781da177e4SLinus Torvalds 				mix->send_routing[voice][idx] = val;
2791da177e4SLinus Torvalds 				change = 1;
2801da177e4SLinus Torvalds 			}
2811da177e4SLinus Torvalds 		}
2821da177e4SLinus Torvalds 	if (change && mix->epcm) {
2831da177e4SLinus Torvalds 		if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
2841da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
2851da177e4SLinus Torvalds 					    &mix->send_routing[1][0]);
2861da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[1]->number,
2871da177e4SLinus Torvalds 					    &mix->send_routing[2][0]);
2881da177e4SLinus Torvalds 		} else if (mix->epcm->voices[0]) {
2891da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
2901da177e4SLinus Torvalds 					    &mix->send_routing[0][0]);
2911da177e4SLinus Torvalds 		}
2921da177e4SLinus Torvalds 	}
2931da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
2941da177e4SLinus Torvalds 	return change;
2951da177e4SLinus Torvalds }
2961da177e4SLinus Torvalds 
297*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_emu10k1_send_routing_control =
2981da177e4SLinus Torvalds {
2991da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
30067ed4161SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
3011da177e4SLinus Torvalds 	.name =         "EMU10K1 PCM Send Routing",
3021da177e4SLinus Torvalds 	.count =	32,
3031da177e4SLinus Torvalds 	.info =         snd_emu10k1_send_routing_info,
3041da177e4SLinus Torvalds 	.get =          snd_emu10k1_send_routing_get,
3051da177e4SLinus Torvalds 	.put =          snd_emu10k1_send_routing_put
3061da177e4SLinus Torvalds };
3071da177e4SLinus Torvalds 
308*eb4698f3STakashi Iwai static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3091da177e4SLinus Torvalds {
310*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
3111da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3121da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 3*8 : 3*4;
3131da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
3141da177e4SLinus Torvalds 	uinfo->value.integer.max = 255;
3151da177e4SLinus Torvalds 	return 0;
3161da177e4SLinus Torvalds }
3171da177e4SLinus Torvalds 
318*eb4698f3STakashi Iwai static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol,
319*eb4698f3STakashi Iwai                                        struct snd_ctl_elem_value *ucontrol)
3201da177e4SLinus Torvalds {
3211da177e4SLinus Torvalds 	unsigned long flags;
322*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
323*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
324*eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
3251da177e4SLinus Torvalds 	int idx;
3261da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
3271da177e4SLinus Torvalds 
3281da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
3291da177e4SLinus Torvalds 	for (idx = 0; idx < 3*num_efx; idx++)
3301da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx];
3311da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
3321da177e4SLinus Torvalds 	return 0;
3331da177e4SLinus Torvalds }
3341da177e4SLinus Torvalds 
335*eb4698f3STakashi Iwai static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol,
336*eb4698f3STakashi Iwai                                        struct snd_ctl_elem_value *ucontrol)
3371da177e4SLinus Torvalds {
3381da177e4SLinus Torvalds 	unsigned long flags;
339*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
340*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
341*eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
3421da177e4SLinus Torvalds 	int change = 0, idx, val;
3431da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
3441da177e4SLinus Torvalds 
3451da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
3461da177e4SLinus Torvalds 	for (idx = 0; idx < 3*num_efx; idx++) {
3471da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & 255;
3481da177e4SLinus Torvalds 		if (mix->send_volume[idx/num_efx][idx%num_efx] != val) {
3491da177e4SLinus Torvalds 			mix->send_volume[idx/num_efx][idx%num_efx] = val;
3501da177e4SLinus Torvalds 			change = 1;
3511da177e4SLinus Torvalds 		}
3521da177e4SLinus Torvalds 	}
3531da177e4SLinus Torvalds 	if (change && mix->epcm) {
3541da177e4SLinus Torvalds 		if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
3551da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
3561da177e4SLinus Torvalds 						   &mix->send_volume[1][0]);
3571da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[1]->number,
3581da177e4SLinus Torvalds 						   &mix->send_volume[2][0]);
3591da177e4SLinus Torvalds 		} else if (mix->epcm->voices[0]) {
3601da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
3611da177e4SLinus Torvalds 						   &mix->send_volume[0][0]);
3621da177e4SLinus Torvalds 		}
3631da177e4SLinus Torvalds 	}
3641da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
3651da177e4SLinus Torvalds 	return change;
3661da177e4SLinus Torvalds }
3671da177e4SLinus Torvalds 
368*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_emu10k1_send_volume_control =
3691da177e4SLinus Torvalds {
3701da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
37167ed4161SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
3721da177e4SLinus Torvalds 	.name =         "EMU10K1 PCM Send Volume",
3731da177e4SLinus Torvalds 	.count =	32,
3741da177e4SLinus Torvalds 	.info =         snd_emu10k1_send_volume_info,
3751da177e4SLinus Torvalds 	.get =          snd_emu10k1_send_volume_get,
3761da177e4SLinus Torvalds 	.put =          snd_emu10k1_send_volume_put
3771da177e4SLinus Torvalds };
3781da177e4SLinus Torvalds 
379*eb4698f3STakashi Iwai static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3801da177e4SLinus Torvalds {
3811da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3821da177e4SLinus Torvalds 	uinfo->count = 3;
3831da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
3841da177e4SLinus Torvalds 	uinfo->value.integer.max = 0xffff;
3851da177e4SLinus Torvalds 	return 0;
3861da177e4SLinus Torvalds }
3871da177e4SLinus Torvalds 
388*eb4698f3STakashi Iwai static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,
389*eb4698f3STakashi Iwai                                 struct snd_ctl_elem_value *ucontrol)
3901da177e4SLinus Torvalds {
391*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
392*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
393*eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
3941da177e4SLinus Torvalds 	unsigned long flags;
3951da177e4SLinus Torvalds 	int idx;
3961da177e4SLinus Torvalds 
3971da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
3981da177e4SLinus Torvalds 	for (idx = 0; idx < 3; idx++)
3991da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] = mix->attn[idx];
4001da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
4011da177e4SLinus Torvalds 	return 0;
4021da177e4SLinus Torvalds }
4031da177e4SLinus Torvalds 
404*eb4698f3STakashi Iwai static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,
405*eb4698f3STakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
4061da177e4SLinus Torvalds {
4071da177e4SLinus Torvalds 	unsigned long flags;
408*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
409*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
410*eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
4111da177e4SLinus Torvalds 	int change = 0, idx, val;
4121da177e4SLinus Torvalds 
4131da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
4141da177e4SLinus Torvalds 	for (idx = 0; idx < 3; idx++) {
4151da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & 0xffff;
4161da177e4SLinus Torvalds 		if (mix->attn[idx] != val) {
4171da177e4SLinus Torvalds 			mix->attn[idx] = val;
4181da177e4SLinus Torvalds 			change = 1;
4191da177e4SLinus Torvalds 		}
4201da177e4SLinus Torvalds 	}
4211da177e4SLinus Torvalds 	if (change && mix->epcm) {
4221da177e4SLinus Torvalds 		if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
4231da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]);
4241da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[1]->number, mix->attn[2]);
4251da177e4SLinus Torvalds 		} else if (mix->epcm->voices[0]) {
4261da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]);
4271da177e4SLinus Torvalds 		}
4281da177e4SLinus Torvalds 	}
4291da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
4301da177e4SLinus Torvalds 	return change;
4311da177e4SLinus Torvalds }
4321da177e4SLinus Torvalds 
433*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_emu10k1_attn_control =
4341da177e4SLinus Torvalds {
4351da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
43667ed4161SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
4371da177e4SLinus Torvalds 	.name =         "EMU10K1 PCM Volume",
4381da177e4SLinus Torvalds 	.count =	32,
4391da177e4SLinus Torvalds 	.info =         snd_emu10k1_attn_info,
4401da177e4SLinus Torvalds 	.get =          snd_emu10k1_attn_get,
4411da177e4SLinus Torvalds 	.put =          snd_emu10k1_attn_put
4421da177e4SLinus Torvalds };
4431da177e4SLinus Torvalds 
4441da177e4SLinus Torvalds /* Mutichannel PCM stream controls */
4451da177e4SLinus Torvalds 
446*eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
4471da177e4SLinus Torvalds {
448*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
4491da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4501da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 8 : 4;
4511da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
4521da177e4SLinus Torvalds 	uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
4531da177e4SLinus Torvalds 	return 0;
4541da177e4SLinus Torvalds }
4551da177e4SLinus Torvalds 
456*eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol,
457*eb4698f3STakashi Iwai                                         struct snd_ctl_elem_value *ucontrol)
4581da177e4SLinus Torvalds {
4591da177e4SLinus Torvalds 	unsigned long flags;
460*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
461*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
462*eb4698f3STakashi Iwai 		&emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
4631da177e4SLinus Torvalds 	int idx;
4641da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
4651da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
4661da177e4SLinus Torvalds 
4671da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
4681da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++)
4691da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] =
4701da177e4SLinus Torvalds 			mix->send_routing[0][idx] & mask;
4711da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
4721da177e4SLinus Torvalds 	return 0;
4731da177e4SLinus Torvalds }
4741da177e4SLinus Torvalds 
475*eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol,
476*eb4698f3STakashi Iwai                                         struct snd_ctl_elem_value *ucontrol)
4771da177e4SLinus Torvalds {
4781da177e4SLinus Torvalds 	unsigned long flags;
479*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
4801da177e4SLinus Torvalds 	int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
481*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
4821da177e4SLinus Torvalds 	int change = 0, idx, val;
4831da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
4841da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
4851da177e4SLinus Torvalds 
4861da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
4871da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++) {
4881da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & mask;
4891da177e4SLinus Torvalds 		if (mix->send_routing[0][idx] != val) {
4901da177e4SLinus Torvalds 			mix->send_routing[0][idx] = val;
4911da177e4SLinus Torvalds 			change = 1;
4921da177e4SLinus Torvalds 		}
4931da177e4SLinus Torvalds 	}
4941da177e4SLinus Torvalds 
4951da177e4SLinus Torvalds 	if (change && mix->epcm) {
4961da177e4SLinus Torvalds 		if (mix->epcm->voices[ch]) {
4971da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number,
4981da177e4SLinus Torvalds 					&mix->send_routing[0][0]);
4991da177e4SLinus Torvalds 		}
5001da177e4SLinus Torvalds 	}
5011da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
5021da177e4SLinus Torvalds 	return change;
5031da177e4SLinus Torvalds }
5041da177e4SLinus Torvalds 
505*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
5061da177e4SLinus Torvalds {
5071da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
5081da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
5091da177e4SLinus Torvalds 	.name =         "Multichannel PCM Send Routing",
5101da177e4SLinus Torvalds 	.count =	16,
5111da177e4SLinus Torvalds 	.info =         snd_emu10k1_efx_send_routing_info,
5121da177e4SLinus Torvalds 	.get =          snd_emu10k1_efx_send_routing_get,
5131da177e4SLinus Torvalds 	.put =          snd_emu10k1_efx_send_routing_put
5141da177e4SLinus Torvalds };
5151da177e4SLinus Torvalds 
516*eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
5171da177e4SLinus Torvalds {
518*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
5191da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5201da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 8 : 4;
5211da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
5221da177e4SLinus Torvalds 	uinfo->value.integer.max = 255;
5231da177e4SLinus Torvalds 	return 0;
5241da177e4SLinus Torvalds }
5251da177e4SLinus Torvalds 
526*eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol,
527*eb4698f3STakashi Iwai                                        struct snd_ctl_elem_value *ucontrol)
5281da177e4SLinus Torvalds {
5291da177e4SLinus Torvalds 	unsigned long flags;
530*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
531*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
532*eb4698f3STakashi Iwai 		&emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
5331da177e4SLinus Torvalds 	int idx;
5341da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
5351da177e4SLinus Torvalds 
5361da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
5371da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++)
5381da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] = mix->send_volume[0][idx];
5391da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
5401da177e4SLinus Torvalds 	return 0;
5411da177e4SLinus Torvalds }
5421da177e4SLinus Torvalds 
543*eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol,
544*eb4698f3STakashi Iwai                                        struct snd_ctl_elem_value *ucontrol)
5451da177e4SLinus Torvalds {
5461da177e4SLinus Torvalds 	unsigned long flags;
547*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
5481da177e4SLinus Torvalds 	int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
549*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
5501da177e4SLinus Torvalds 	int change = 0, idx, val;
5511da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
5521da177e4SLinus Torvalds 
5531da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
5541da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++) {
5551da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & 255;
5561da177e4SLinus Torvalds 		if (mix->send_volume[0][idx] != val) {
5571da177e4SLinus Torvalds 			mix->send_volume[0][idx] = val;
5581da177e4SLinus Torvalds 			change = 1;
5591da177e4SLinus Torvalds 		}
5601da177e4SLinus Torvalds 	}
5611da177e4SLinus Torvalds 	if (change && mix->epcm) {
5621da177e4SLinus Torvalds 		if (mix->epcm->voices[ch]) {
5631da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number,
5641da177e4SLinus Torvalds 						   &mix->send_volume[0][0]);
5651da177e4SLinus Torvalds 		}
5661da177e4SLinus Torvalds 	}
5671da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
5681da177e4SLinus Torvalds 	return change;
5691da177e4SLinus Torvalds }
5701da177e4SLinus Torvalds 
5711da177e4SLinus Torvalds 
572*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
5731da177e4SLinus Torvalds {
5741da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
5751da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
5761da177e4SLinus Torvalds 	.name =         "Multichannel PCM Send Volume",
5771da177e4SLinus Torvalds 	.count =	16,
5781da177e4SLinus Torvalds 	.info =         snd_emu10k1_efx_send_volume_info,
5791da177e4SLinus Torvalds 	.get =          snd_emu10k1_efx_send_volume_get,
5801da177e4SLinus Torvalds 	.put =          snd_emu10k1_efx_send_volume_put
5811da177e4SLinus Torvalds };
5821da177e4SLinus Torvalds 
583*eb4698f3STakashi Iwai static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
5841da177e4SLinus Torvalds {
5851da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5861da177e4SLinus Torvalds 	uinfo->count = 1;
5871da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
5881da177e4SLinus Torvalds 	uinfo->value.integer.max = 0xffff;
5891da177e4SLinus Torvalds 	return 0;
5901da177e4SLinus Torvalds }
5911da177e4SLinus Torvalds 
592*eb4698f3STakashi Iwai static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol,
593*eb4698f3STakashi Iwai                                 struct snd_ctl_elem_value *ucontrol)
5941da177e4SLinus Torvalds {
595*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
596*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
597*eb4698f3STakashi Iwai 		&emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
5981da177e4SLinus Torvalds 	unsigned long flags;
5991da177e4SLinus Torvalds 
6001da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
6011da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = mix->attn[0];
6021da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
6031da177e4SLinus Torvalds 	return 0;
6041da177e4SLinus Torvalds }
6051da177e4SLinus Torvalds 
606*eb4698f3STakashi Iwai static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol,
607*eb4698f3STakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
6081da177e4SLinus Torvalds {
6091da177e4SLinus Torvalds 	unsigned long flags;
610*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
6111da177e4SLinus Torvalds 	int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
612*eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
6131da177e4SLinus Torvalds 	int change = 0, val;
6141da177e4SLinus Torvalds 
6151da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
6161da177e4SLinus Torvalds 	val = ucontrol->value.integer.value[0] & 0xffff;
6171da177e4SLinus Torvalds 	if (mix->attn[0] != val) {
6181da177e4SLinus Torvalds 		mix->attn[0] = val;
6191da177e4SLinus Torvalds 		change = 1;
6201da177e4SLinus Torvalds 	}
6211da177e4SLinus Torvalds 	if (change && mix->epcm) {
6221da177e4SLinus Torvalds 		if (mix->epcm->voices[ch]) {
6231da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]);
6241da177e4SLinus Torvalds 		}
6251da177e4SLinus Torvalds 	}
6261da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
6271da177e4SLinus Torvalds 	return change;
6281da177e4SLinus Torvalds }
6291da177e4SLinus Torvalds 
630*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
6311da177e4SLinus Torvalds {
6321da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
6331da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
6341da177e4SLinus Torvalds 	.name =         "Multichannel PCM Volume",
6351da177e4SLinus Torvalds 	.count =	16,
6361da177e4SLinus Torvalds 	.info =         snd_emu10k1_efx_attn_info,
6371da177e4SLinus Torvalds 	.get =          snd_emu10k1_efx_attn_get,
6381da177e4SLinus Torvalds 	.put =          snd_emu10k1_efx_attn_put
6391da177e4SLinus Torvalds };
6401da177e4SLinus Torvalds 
641*eb4698f3STakashi Iwai static int snd_emu10k1_shared_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
6421da177e4SLinus Torvalds {
6431da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
6441da177e4SLinus Torvalds 	uinfo->count = 1;
6451da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
6461da177e4SLinus Torvalds 	uinfo->value.integer.max = 1;
6471da177e4SLinus Torvalds 	return 0;
6481da177e4SLinus Torvalds }
6491da177e4SLinus Torvalds 
650*eb4698f3STakashi Iwai static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
651*eb4698f3STakashi Iwai 					struct snd_ctl_elem_value *ucontrol)
6521da177e4SLinus Torvalds {
653*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
6541da177e4SLinus Torvalds 
6551da177e4SLinus Torvalds 	if (emu->audigy)
6561da177e4SLinus Torvalds 		ucontrol->value.integer.value[0] = inl(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
6571da177e4SLinus Torvalds 	else
6581da177e4SLinus Torvalds 		ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
6591da177e4SLinus Torvalds 	return 0;
6601da177e4SLinus Torvalds }
6611da177e4SLinus Torvalds 
662*eb4698f3STakashi Iwai static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
663*eb4698f3STakashi Iwai 					struct snd_ctl_elem_value *ucontrol)
6641da177e4SLinus Torvalds {
6651da177e4SLinus Torvalds 	unsigned long flags;
666*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
6671da177e4SLinus Torvalds 	unsigned int reg, val;
6681da177e4SLinus Torvalds 	int change = 0;
6691da177e4SLinus Torvalds 
6701da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
6711da177e4SLinus Torvalds 	if (emu->audigy) {
6721da177e4SLinus Torvalds 		reg = inl(emu->port + A_IOCFG);
6731da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[0] ? A_IOCFG_GPOUT0 : 0;
6741da177e4SLinus Torvalds 		change = (reg & A_IOCFG_GPOUT0) != val;
6751da177e4SLinus Torvalds 		if (change) {
6761da177e4SLinus Torvalds 			reg &= ~A_IOCFG_GPOUT0;
6771da177e4SLinus Torvalds 			reg |= val;
6781da177e4SLinus Torvalds 			outl(reg | val, emu->port + A_IOCFG);
6791da177e4SLinus Torvalds 		}
6801da177e4SLinus Torvalds 	}
6811da177e4SLinus Torvalds 	reg = inl(emu->port + HCFG);
6821da177e4SLinus Torvalds 	val = ucontrol->value.integer.value[0] ? HCFG_GPOUT0 : 0;
6831da177e4SLinus Torvalds 	change |= (reg & HCFG_GPOUT0) != val;
6841da177e4SLinus Torvalds 	if (change) {
6851da177e4SLinus Torvalds 		reg &= ~HCFG_GPOUT0;
6861da177e4SLinus Torvalds 		reg |= val;
6871da177e4SLinus Torvalds 		outl(reg | val, emu->port + HCFG);
6881da177e4SLinus Torvalds 	}
6891da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
6901da177e4SLinus Torvalds 	return change;
6911da177e4SLinus Torvalds }
6921da177e4SLinus Torvalds 
693*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_emu10k1_shared_spdif __devinitdata =
6941da177e4SLinus Torvalds {
6951da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
6961da177e4SLinus Torvalds 	.name =		"SB Live Analog/Digital Output Jack",
6971da177e4SLinus Torvalds 	.info =		snd_emu10k1_shared_spdif_info,
6981da177e4SLinus Torvalds 	.get =		snd_emu10k1_shared_spdif_get,
6991da177e4SLinus Torvalds 	.put =		snd_emu10k1_shared_spdif_put
7001da177e4SLinus Torvalds };
7011da177e4SLinus Torvalds 
702*eb4698f3STakashi Iwai static struct snd_kcontrol_new snd_audigy_shared_spdif __devinitdata =
7031da177e4SLinus Torvalds {
7041da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
7051da177e4SLinus Torvalds 	.name =		"Audigy Analog/Digital Output Jack",
7061da177e4SLinus Torvalds 	.info =		snd_emu10k1_shared_spdif_info,
7071da177e4SLinus Torvalds 	.get =		snd_emu10k1_shared_spdif_get,
7081da177e4SLinus Torvalds 	.put =		snd_emu10k1_shared_spdif_put
7091da177e4SLinus Torvalds };
7101da177e4SLinus Torvalds 
7111da177e4SLinus Torvalds /*
7121da177e4SLinus Torvalds  */
713*eb4698f3STakashi Iwai static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
7141da177e4SLinus Torvalds {
715*eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = ac97->private_data;
7161da177e4SLinus Torvalds 	emu->ac97 = NULL;
7171da177e4SLinus Torvalds }
7181da177e4SLinus Torvalds 
7191da177e4SLinus Torvalds /*
7201da177e4SLinus Torvalds  */
721*eb4698f3STakashi Iwai static int remove_ctl(struct snd_card *card, const char *name)
7221da177e4SLinus Torvalds {
723*eb4698f3STakashi Iwai 	struct snd_ctl_elem_id id;
7241da177e4SLinus Torvalds 	memset(&id, 0, sizeof(id));
7251da177e4SLinus Torvalds 	strcpy(id.name, name);
7261da177e4SLinus Torvalds 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
7271da177e4SLinus Torvalds 	return snd_ctl_remove_id(card, &id);
7281da177e4SLinus Torvalds }
7291da177e4SLinus Torvalds 
730*eb4698f3STakashi Iwai static struct snd_kcontrol *ctl_find(struct snd_card *card, const char *name)
7311da177e4SLinus Torvalds {
732*eb4698f3STakashi Iwai 	struct snd_ctl_elem_id sid;
7331da177e4SLinus Torvalds 	memset(&sid, 0, sizeof(sid));
7341da177e4SLinus Torvalds 	strcpy(sid.name, name);
7351da177e4SLinus Torvalds 	sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
7361da177e4SLinus Torvalds 	return snd_ctl_find_id(card, &sid);
7371da177e4SLinus Torvalds }
7381da177e4SLinus Torvalds 
739*eb4698f3STakashi Iwai static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
7401da177e4SLinus Torvalds {
741*eb4698f3STakashi Iwai 	struct snd_kcontrol *kctl = ctl_find(card, src);
7421da177e4SLinus Torvalds 	if (kctl) {
7431da177e4SLinus Torvalds 		strcpy(kctl->id.name, dst);
7441da177e4SLinus Torvalds 		return 0;
7451da177e4SLinus Torvalds 	}
7461da177e4SLinus Torvalds 	return -ENOENT;
7471da177e4SLinus Torvalds }
7481da177e4SLinus Torvalds 
749*eb4698f3STakashi Iwai int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
75067ed4161SClemens Ladisch 				int pcm_device, int multi_device)
7511da177e4SLinus Torvalds {
7521da177e4SLinus Torvalds 	int err, pcm;
753*eb4698f3STakashi Iwai 	struct snd_kcontrol *kctl;
754*eb4698f3STakashi Iwai 	struct snd_card *card = emu->card;
7551da177e4SLinus Torvalds 	char **c;
7561da177e4SLinus Torvalds 	static char *emu10k1_remove_ctls[] = {
7571da177e4SLinus Torvalds 		/* no AC97 mono, surround, center/lfe */
7581da177e4SLinus Torvalds 		"Master Mono Playback Switch",
7591da177e4SLinus Torvalds 		"Master Mono Playback Volume",
7601da177e4SLinus Torvalds 		"PCM Out Path & Mute",
7611da177e4SLinus Torvalds 		"Mono Output Select",
7621da177e4SLinus Torvalds 		"Surround Playback Switch",
7631da177e4SLinus Torvalds 		"Surround Playback Volume",
7641da177e4SLinus Torvalds 		"Center Playback Switch",
7651da177e4SLinus Torvalds 		"Center Playback Volume",
7661da177e4SLinus Torvalds 		"LFE Playback Switch",
7671da177e4SLinus Torvalds 		"LFE Playback Volume",
7681da177e4SLinus Torvalds 		NULL
7691da177e4SLinus Torvalds 	};
7701da177e4SLinus Torvalds 	static char *emu10k1_rename_ctls[] = {
7711da177e4SLinus Torvalds 		"Surround Digital Playback Volume", "Surround Playback Volume",
7721da177e4SLinus Torvalds 		"Center Digital Playback Volume", "Center Playback Volume",
7731da177e4SLinus Torvalds 		"LFE Digital Playback Volume", "LFE Playback Volume",
7741da177e4SLinus Torvalds 		NULL
7751da177e4SLinus Torvalds 	};
7761da177e4SLinus Torvalds 	static char *audigy_remove_ctls[] = {
7771da177e4SLinus Torvalds 		/* Master/PCM controls on ac97 of Audigy has no effect */
7781da177e4SLinus Torvalds 		"PCM Playback Switch",
7791da177e4SLinus Torvalds 		"PCM Playback Volume",
7801da177e4SLinus Torvalds 		"Master Mono Playback Switch",
7811da177e4SLinus Torvalds 		"Master Mono Playback Volume",
7821da177e4SLinus Torvalds 		"Master Playback Switch",
7831da177e4SLinus Torvalds 		"Master Playback Volume",
7841da177e4SLinus Torvalds 		"PCM Out Path & Mute",
7851da177e4SLinus Torvalds 		"Mono Output Select",
7861da177e4SLinus Torvalds 		/* remove unused AC97 capture controls */
7871da177e4SLinus Torvalds 		"Capture Source",
7881da177e4SLinus Torvalds 		"Capture Switch",
7891da177e4SLinus Torvalds 		"Capture Volume",
7901da177e4SLinus Torvalds 		"Mic Select",
7911da177e4SLinus Torvalds 		"Video Playback Switch",
7921da177e4SLinus Torvalds 		"Video Playback Volume",
7931da177e4SLinus Torvalds 		"Mic Playback Switch",
7941da177e4SLinus Torvalds 		"Mic Playback Volume",
7951da177e4SLinus Torvalds 		NULL
7961da177e4SLinus Torvalds 	};
7971da177e4SLinus Torvalds 	static char *audigy_rename_ctls[] = {
7981da177e4SLinus Torvalds 		/* use conventional names */
7991da177e4SLinus Torvalds 		"Wave Playback Volume", "PCM Playback Volume",
8001da177e4SLinus Torvalds 		/* "Wave Capture Volume", "PCM Capture Volume", */
8011da177e4SLinus Torvalds 		"Wave Master Playback Volume", "Master Playback Volume",
8021da177e4SLinus Torvalds 		"AMic Playback Volume", "Mic Playback Volume",
8031da177e4SLinus Torvalds 		NULL
8041da177e4SLinus Torvalds 	};
8051da177e4SLinus Torvalds 
8062b637da5SLee Revell 	if (emu->card_capabilities->ac97_chip) {
807*eb4698f3STakashi Iwai 		struct snd_ac97_bus *pbus;
808*eb4698f3STakashi Iwai 		struct snd_ac97_template ac97;
809*eb4698f3STakashi Iwai 		static struct snd_ac97_bus_ops ops = {
8101da177e4SLinus Torvalds 			.write = snd_emu10k1_ac97_write,
8111da177e4SLinus Torvalds 			.read = snd_emu10k1_ac97_read,
8121da177e4SLinus Torvalds 		};
8131da177e4SLinus Torvalds 
814b1508693STakashi Iwai 		if ((err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus)) < 0)
8151da177e4SLinus Torvalds 			return err;
8161da177e4SLinus Torvalds 		pbus->no_vra = 1; /* we don't need VRA */
8171da177e4SLinus Torvalds 
8181da177e4SLinus Torvalds 		memset(&ac97, 0, sizeof(ac97));
8191da177e4SLinus Torvalds 		ac97.private_data = emu;
8201da177e4SLinus Torvalds 		ac97.private_free = snd_emu10k1_mixer_free_ac97;
8211da177e4SLinus Torvalds 		ac97.scaps = AC97_SCAP_NO_SPDIF;
822b1508693STakashi Iwai 		if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0) {
823b1508693STakashi Iwai 			if (emu->card_capabilities->ac97_chip == 1)
8241da177e4SLinus Torvalds 				return err;
825b1508693STakashi Iwai 			snd_printd(KERN_INFO "emu10k1: AC97 is optional on this board\n");
826b1508693STakashi Iwai 			snd_printd(KERN_INFO"          Proceeding without ac97 mixers...\n");
827b1508693STakashi Iwai 			snd_device_free(emu->card, pbus);
828b1508693STakashi Iwai 			goto no_ac97; /* FIXME: get rid of ugly gotos.. */
829b1508693STakashi Iwai 		}
8301da177e4SLinus Torvalds 		if (emu->audigy) {
8311da177e4SLinus Torvalds 			/* set master volume to 0 dB */
8321da177e4SLinus Torvalds 			snd_ac97_write(emu->ac97, AC97_MASTER, 0x0000);
8331da177e4SLinus Torvalds 			/* set capture source to mic */
8341da177e4SLinus Torvalds 			snd_ac97_write(emu->ac97, AC97_REC_SEL, 0x0000);
8351da177e4SLinus Torvalds 			c = audigy_remove_ctls;
8361da177e4SLinus Torvalds 		} else {
8371da177e4SLinus Torvalds 			/*
8381da177e4SLinus Torvalds 			 * Credits for cards based on STAC9758:
8391da177e4SLinus Torvalds 			 *   James Courtier-Dutton <James@superbug.demon.co.uk>
8401da177e4SLinus Torvalds 			 *   Voluspa <voluspa@comhem.se>
8411da177e4SLinus Torvalds 			 */
8421da177e4SLinus Torvalds 			if (emu->ac97->id == AC97_ID_STAC9758) {
8431da177e4SLinus Torvalds 				emu->rear_ac97 = 1;
8441da177e4SLinus Torvalds 				snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
8451da177e4SLinus Torvalds 			}
8461da177e4SLinus Torvalds 			/* remove unused AC97 controls */
8471da177e4SLinus Torvalds 			snd_ac97_write(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
8481da177e4SLinus Torvalds 			snd_ac97_write(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
8491da177e4SLinus Torvalds 			c = emu10k1_remove_ctls;
8501da177e4SLinus Torvalds 		}
8511da177e4SLinus Torvalds 		for (; *c; c++)
8521da177e4SLinus Torvalds 			remove_ctl(card, *c);
8531da177e4SLinus Torvalds 	} else {
854f12aa40cSTakashi Iwai 	no_ac97:
8552b637da5SLee Revell 		if (emu->card_capabilities->ecard)
8561da177e4SLinus Torvalds 			strcpy(emu->card->mixername, "EMU APS");
8571da177e4SLinus Torvalds 		else if (emu->audigy)
8581da177e4SLinus Torvalds 			strcpy(emu->card->mixername, "SB Audigy");
8591da177e4SLinus Torvalds 		else
8601da177e4SLinus Torvalds 			strcpy(emu->card->mixername, "Emu10k1");
8611da177e4SLinus Torvalds 	}
8621da177e4SLinus Torvalds 
8631da177e4SLinus Torvalds 	if (emu->audigy)
8641da177e4SLinus Torvalds 		c = audigy_rename_ctls;
8651da177e4SLinus Torvalds 	else
8661da177e4SLinus Torvalds 		c = emu10k1_rename_ctls;
8671da177e4SLinus Torvalds 	for (; *c; c += 2)
8681da177e4SLinus Torvalds 		rename_ctl(card, c[0], c[1]);
8691da177e4SLinus Torvalds 
8701da177e4SLinus Torvalds 	if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL)
8711da177e4SLinus Torvalds 		return -ENOMEM;
87267ed4161SClemens Ladisch 	kctl->id.device = pcm_device;
8731da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8741da177e4SLinus Torvalds 		return err;
8751da177e4SLinus Torvalds 	if ((kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu)) == NULL)
8761da177e4SLinus Torvalds 		return -ENOMEM;
87767ed4161SClemens Ladisch 	kctl->id.device = pcm_device;
8781da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8791da177e4SLinus Torvalds 		return err;
8801da177e4SLinus Torvalds 	if ((kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu)) == NULL)
8811da177e4SLinus Torvalds 		return -ENOMEM;
88267ed4161SClemens Ladisch 	kctl->id.device = pcm_device;
8831da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8841da177e4SLinus Torvalds 		return err;
8851da177e4SLinus Torvalds 
8861da177e4SLinus Torvalds 	if ((kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu)) == NULL)
8871da177e4SLinus Torvalds 		return -ENOMEM;
88867ed4161SClemens Ladisch 	kctl->id.device = multi_device;
8891da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8901da177e4SLinus Torvalds 		return err;
8911da177e4SLinus Torvalds 
8921da177e4SLinus Torvalds 	if ((kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu)) == NULL)
8931da177e4SLinus Torvalds 		return -ENOMEM;
89467ed4161SClemens Ladisch 	kctl->id.device = multi_device;
8951da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8961da177e4SLinus Torvalds 		return err;
8971da177e4SLinus Torvalds 
8981da177e4SLinus Torvalds 	if ((kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu)) == NULL)
8991da177e4SLinus Torvalds 		return -ENOMEM;
90067ed4161SClemens Ladisch 	kctl->id.device = multi_device;
9011da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
9021da177e4SLinus Torvalds 		return err;
9031da177e4SLinus Torvalds 
9041da177e4SLinus Torvalds 	/* initialize the routing and volume table for each pcm playback stream */
9051da177e4SLinus Torvalds 	for (pcm = 0; pcm < 32; pcm++) {
906*eb4698f3STakashi Iwai 		struct snd_emu10k1_pcm_mixer *mix;
9071da177e4SLinus Torvalds 		int v;
9081da177e4SLinus Torvalds 
9091da177e4SLinus Torvalds 		mix = &emu->pcm_mixer[pcm];
9101da177e4SLinus Torvalds 		mix->epcm = NULL;
9111da177e4SLinus Torvalds 
9121da177e4SLinus Torvalds 		for (v = 0; v < 4; v++)
9131da177e4SLinus Torvalds 			mix->send_routing[0][v] =
9141da177e4SLinus Torvalds 				mix->send_routing[1][v] =
9151da177e4SLinus Torvalds 				mix->send_routing[2][v] = v;
9161da177e4SLinus Torvalds 
9171da177e4SLinus Torvalds 		memset(&mix->send_volume, 0, sizeof(mix->send_volume));
9181da177e4SLinus Torvalds 		mix->send_volume[0][0] = mix->send_volume[0][1] =
9191da177e4SLinus Torvalds 		mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
9201da177e4SLinus Torvalds 
9211da177e4SLinus Torvalds 		mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
9221da177e4SLinus Torvalds 	}
9231da177e4SLinus Torvalds 
9241da177e4SLinus Torvalds 	/* initialize the routing and volume table for the multichannel playback stream */
9251da177e4SLinus Torvalds 	for (pcm = 0; pcm < NUM_EFX_PLAYBACK; pcm++) {
926*eb4698f3STakashi Iwai 		struct snd_emu10k1_pcm_mixer *mix;
9271da177e4SLinus Torvalds 		int v;
9281da177e4SLinus Torvalds 
9291da177e4SLinus Torvalds 		mix = &emu->efx_pcm_mixer[pcm];
9301da177e4SLinus Torvalds 		mix->epcm = NULL;
9311da177e4SLinus Torvalds 
9321da177e4SLinus Torvalds 		mix->send_routing[0][0] = pcm;
9331da177e4SLinus Torvalds 		mix->send_routing[0][1] = (pcm == 0) ? 1 : 0;
9341da177e4SLinus Torvalds 		for (v = 0; v < 2; v++)
9351da177e4SLinus Torvalds 			mix->send_routing[0][2+v] = 13+v;
9361da177e4SLinus Torvalds 		if (emu->audigy)
9371da177e4SLinus Torvalds 			for (v = 0; v < 4; v++)
9381da177e4SLinus Torvalds 				mix->send_routing[0][4+v] = 60+v;
9391da177e4SLinus Torvalds 
9401da177e4SLinus Torvalds 		memset(&mix->send_volume, 0, sizeof(mix->send_volume));
9411da177e4SLinus Torvalds 		mix->send_volume[0][0]  = 255;
9421da177e4SLinus Torvalds 
9431da177e4SLinus Torvalds 		mix->attn[0] = 0xffff;
9441da177e4SLinus Torvalds 	}
9451da177e4SLinus Torvalds 
9462b637da5SLee Revell 	if (! emu->card_capabilities->ecard) { /* FIXME: APS has these controls? */
9471da177e4SLinus Torvalds 		/* sb live! and audigy */
9481da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu)) == NULL)
9491da177e4SLinus Torvalds 			return -ENOMEM;
9505549d549SClemens Ladisch 		if (!emu->audigy)
9515549d549SClemens Ladisch 			kctl->id.device = emu->pcm_efx->device;
9521da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9531da177e4SLinus Torvalds 			return err;
9541da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu)) == NULL)
9551da177e4SLinus Torvalds 			return -ENOMEM;
9565549d549SClemens Ladisch 		if (!emu->audigy)
9575549d549SClemens Ladisch 			kctl->id.device = emu->pcm_efx->device;
9581da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9591da177e4SLinus Torvalds 			return err;
9601da177e4SLinus Torvalds 	}
9611da177e4SLinus Torvalds 
9621da177e4SLinus Torvalds 	if (emu->audigy) {
9631da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu)) == NULL)
9641da177e4SLinus Torvalds 			return -ENOMEM;
9651da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9661da177e4SLinus Torvalds 			return err;
967001f7589SJames Courtier-Dutton #if 0
9681da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu)) == NULL)
9691da177e4SLinus Torvalds 			return -ENOMEM;
9701da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9711da177e4SLinus Torvalds 			return err;
972001f7589SJames Courtier-Dutton #endif
9732b637da5SLee Revell 	} else if (! emu->card_capabilities->ecard) {
9741da177e4SLinus Torvalds 		/* sb live! */
9751da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu)) == NULL)
9761da177e4SLinus Torvalds 			return -ENOMEM;
9771da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9781da177e4SLinus Torvalds 			return err;
9791da177e4SLinus Torvalds 	}
9802b637da5SLee Revell 	if (emu->card_capabilities->ca0151_chip) { /* P16V */
9811da177e4SLinus Torvalds 		if ((err = snd_p16v_mixer(emu)))
9821da177e4SLinus Torvalds 			return err;
9831da177e4SLinus Torvalds 	}
9841da177e4SLinus Torvalds 
9851da177e4SLinus Torvalds 	return 0;
9861da177e4SLinus Torvalds }
987