xref: /linux/sound/pci/emu10k1/emumixer.c (revision 5549d54992391d81a8cbfbaac45a958876fbc9cb)
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 
381da177e4SLinus Torvalds static int snd_emu10k1_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * 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 
451da177e4SLinus Torvalds static int snd_emu10k1_spdif_get(snd_kcontrol_t * kcontrol,
461da177e4SLinus Torvalds                                  snd_ctl_elem_value_t * ucontrol)
471da177e4SLinus Torvalds {
481da177e4SLinus Torvalds 	emu10k1_t *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 
611da177e4SLinus Torvalds static int snd_emu10k1_spdif_get_mask(snd_kcontrol_t * kcontrol,
621da177e4SLinus Torvalds 				      snd_ctl_elem_value_t * 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
721da177e4SLinus Torvalds static int snd_audigy_spdif_output_rate_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * 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 
851da177e4SLinus Torvalds static int snd_audigy_spdif_output_rate_get(snd_kcontrol_t * kcontrol,
861da177e4SLinus Torvalds                                  snd_ctl_elem_value_t * ucontrol)
871da177e4SLinus Torvalds {
881da177e4SLinus Torvalds 	emu10k1_t *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 
1121da177e4SLinus Torvalds static int snd_audigy_spdif_output_rate_put(snd_kcontrol_t * kcontrol,
1131da177e4SLinus Torvalds                                  snd_ctl_elem_value_t * ucontrol)
1141da177e4SLinus Torvalds {
1151da177e4SLinus Torvalds 	emu10k1_t *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 
1461da177e4SLinus Torvalds static snd_kcontrol_new_t 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 
1581da177e4SLinus Torvalds static int snd_emu10k1_spdif_put(snd_kcontrol_t * kcontrol,
1591da177e4SLinus Torvalds                                  snd_ctl_elem_value_t * ucontrol)
1601da177e4SLinus Torvalds {
1611da177e4SLinus Torvalds 	emu10k1_t *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 
1811da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_spdif_mask_control =
1821da177e4SLinus Torvalds {
1831da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
184*5549d549SClemens 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 
1911da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_spdif_control =
1921da177e4SLinus Torvalds {
193*5549d549SClemens 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 
2021da177e4SLinus Torvalds static void update_emu10k1_fxrt(emu10k1_t *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 
2151da177e4SLinus Torvalds static void update_emu10k1_send_volume(emu10k1_t *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 
2321da177e4SLinus Torvalds static int snd_emu10k1_send_routing_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2331da177e4SLinus Torvalds {
2341da177e4SLinus Torvalds 	emu10k1_t *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 
2421da177e4SLinus Torvalds static int snd_emu10k1_send_routing_get(snd_kcontrol_t * kcontrol,
2431da177e4SLinus Torvalds                                         snd_ctl_elem_value_t * ucontrol)
2441da177e4SLinus Torvalds {
2451da177e4SLinus Torvalds 	unsigned long flags;
2461da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
2471da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
2481da177e4SLinus Torvalds 	int voice, idx;
2491da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
2501da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
2531da177e4SLinus Torvalds 	for (voice = 0; voice < 3; voice++)
2541da177e4SLinus Torvalds 		for (idx = 0; idx < num_efx; idx++)
2551da177e4SLinus Torvalds 			ucontrol->value.integer.value[(voice * num_efx) + idx] =
2561da177e4SLinus Torvalds 				mix->send_routing[voice][idx] & mask;
2571da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
2581da177e4SLinus Torvalds 	return 0;
2591da177e4SLinus Torvalds }
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds static int snd_emu10k1_send_routing_put(snd_kcontrol_t * kcontrol,
2621da177e4SLinus Torvalds                                         snd_ctl_elem_value_t * ucontrol)
2631da177e4SLinus Torvalds {
2641da177e4SLinus Torvalds 	unsigned long flags;
2651da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
2661da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
2671da177e4SLinus Torvalds 	int change = 0, voice, idx, val;
2681da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
2691da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
2701da177e4SLinus Torvalds 
2711da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
2721da177e4SLinus Torvalds 	for (voice = 0; voice < 3; voice++)
2731da177e4SLinus Torvalds 		for (idx = 0; idx < num_efx; idx++) {
2741da177e4SLinus Torvalds 			val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask;
2751da177e4SLinus Torvalds 			if (mix->send_routing[voice][idx] != val) {
2761da177e4SLinus Torvalds 				mix->send_routing[voice][idx] = val;
2771da177e4SLinus Torvalds 				change = 1;
2781da177e4SLinus Torvalds 			}
2791da177e4SLinus Torvalds 		}
2801da177e4SLinus Torvalds 	if (change && mix->epcm) {
2811da177e4SLinus Torvalds 		if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
2821da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
2831da177e4SLinus Torvalds 					    &mix->send_routing[1][0]);
2841da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[1]->number,
2851da177e4SLinus Torvalds 					    &mix->send_routing[2][0]);
2861da177e4SLinus Torvalds 		} else if (mix->epcm->voices[0]) {
2871da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
2881da177e4SLinus Torvalds 					    &mix->send_routing[0][0]);
2891da177e4SLinus Torvalds 		}
2901da177e4SLinus Torvalds 	}
2911da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
2921da177e4SLinus Torvalds 	return change;
2931da177e4SLinus Torvalds }
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_send_routing_control =
2961da177e4SLinus Torvalds {
2971da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
29867ed4161SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
2991da177e4SLinus Torvalds 	.name =         "EMU10K1 PCM Send Routing",
3001da177e4SLinus Torvalds 	.count =	32,
3011da177e4SLinus Torvalds 	.info =         snd_emu10k1_send_routing_info,
3021da177e4SLinus Torvalds 	.get =          snd_emu10k1_send_routing_get,
3031da177e4SLinus Torvalds 	.put =          snd_emu10k1_send_routing_put
3041da177e4SLinus Torvalds };
3051da177e4SLinus Torvalds 
3061da177e4SLinus Torvalds static int snd_emu10k1_send_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
3071da177e4SLinus Torvalds {
3081da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
3091da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3101da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 3*8 : 3*4;
3111da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
3121da177e4SLinus Torvalds 	uinfo->value.integer.max = 255;
3131da177e4SLinus Torvalds 	return 0;
3141da177e4SLinus Torvalds }
3151da177e4SLinus Torvalds 
3161da177e4SLinus Torvalds static int snd_emu10k1_send_volume_get(snd_kcontrol_t * kcontrol,
3171da177e4SLinus Torvalds                                        snd_ctl_elem_value_t * ucontrol)
3181da177e4SLinus Torvalds {
3191da177e4SLinus Torvalds 	unsigned long flags;
3201da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
3211da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
3221da177e4SLinus Torvalds 	int idx;
3231da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
3241da177e4SLinus Torvalds 
3251da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
3261da177e4SLinus Torvalds 	for (idx = 0; idx < 3*num_efx; idx++)
3271da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx];
3281da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
3291da177e4SLinus Torvalds 	return 0;
3301da177e4SLinus Torvalds }
3311da177e4SLinus Torvalds 
3321da177e4SLinus Torvalds static int snd_emu10k1_send_volume_put(snd_kcontrol_t * kcontrol,
3331da177e4SLinus Torvalds                                        snd_ctl_elem_value_t * ucontrol)
3341da177e4SLinus Torvalds {
3351da177e4SLinus Torvalds 	unsigned long flags;
3361da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
3371da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
3381da177e4SLinus Torvalds 	int change = 0, idx, val;
3391da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
3421da177e4SLinus Torvalds 	for (idx = 0; idx < 3*num_efx; idx++) {
3431da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & 255;
3441da177e4SLinus Torvalds 		if (mix->send_volume[idx/num_efx][idx%num_efx] != val) {
3451da177e4SLinus Torvalds 			mix->send_volume[idx/num_efx][idx%num_efx] = val;
3461da177e4SLinus Torvalds 			change = 1;
3471da177e4SLinus Torvalds 		}
3481da177e4SLinus Torvalds 	}
3491da177e4SLinus Torvalds 	if (change && mix->epcm) {
3501da177e4SLinus Torvalds 		if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
3511da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
3521da177e4SLinus Torvalds 						   &mix->send_volume[1][0]);
3531da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[1]->number,
3541da177e4SLinus Torvalds 						   &mix->send_volume[2][0]);
3551da177e4SLinus Torvalds 		} else if (mix->epcm->voices[0]) {
3561da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
3571da177e4SLinus Torvalds 						   &mix->send_volume[0][0]);
3581da177e4SLinus Torvalds 		}
3591da177e4SLinus Torvalds 	}
3601da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
3611da177e4SLinus Torvalds 	return change;
3621da177e4SLinus Torvalds }
3631da177e4SLinus Torvalds 
3641da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_send_volume_control =
3651da177e4SLinus Torvalds {
3661da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
36767ed4161SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
3681da177e4SLinus Torvalds 	.name =         "EMU10K1 PCM Send Volume",
3691da177e4SLinus Torvalds 	.count =	32,
3701da177e4SLinus Torvalds 	.info =         snd_emu10k1_send_volume_info,
3711da177e4SLinus Torvalds 	.get =          snd_emu10k1_send_volume_get,
3721da177e4SLinus Torvalds 	.put =          snd_emu10k1_send_volume_put
3731da177e4SLinus Torvalds };
3741da177e4SLinus Torvalds 
3751da177e4SLinus Torvalds static int snd_emu10k1_attn_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
3761da177e4SLinus Torvalds {
3771da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3781da177e4SLinus Torvalds 	uinfo->count = 3;
3791da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
3801da177e4SLinus Torvalds 	uinfo->value.integer.max = 0xffff;
3811da177e4SLinus Torvalds 	return 0;
3821da177e4SLinus Torvalds }
3831da177e4SLinus Torvalds 
3841da177e4SLinus Torvalds static int snd_emu10k1_attn_get(snd_kcontrol_t * kcontrol,
3851da177e4SLinus Torvalds                                 snd_ctl_elem_value_t * ucontrol)
3861da177e4SLinus Torvalds {
3871da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
3881da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
3891da177e4SLinus Torvalds 	unsigned long flags;
3901da177e4SLinus Torvalds 	int idx;
3911da177e4SLinus Torvalds 
3921da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
3931da177e4SLinus Torvalds 	for (idx = 0; idx < 3; idx++)
3941da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] = mix->attn[idx];
3951da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
3961da177e4SLinus Torvalds 	return 0;
3971da177e4SLinus Torvalds }
3981da177e4SLinus Torvalds 
3991da177e4SLinus Torvalds static int snd_emu10k1_attn_put(snd_kcontrol_t * kcontrol,
4001da177e4SLinus Torvalds 				snd_ctl_elem_value_t * ucontrol)
4011da177e4SLinus Torvalds {
4021da177e4SLinus Torvalds 	unsigned long flags;
4031da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
4041da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
4051da177e4SLinus Torvalds 	int change = 0, idx, val;
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
4081da177e4SLinus Torvalds 	for (idx = 0; idx < 3; idx++) {
4091da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & 0xffff;
4101da177e4SLinus Torvalds 		if (mix->attn[idx] != val) {
4111da177e4SLinus Torvalds 			mix->attn[idx] = val;
4121da177e4SLinus Torvalds 			change = 1;
4131da177e4SLinus Torvalds 		}
4141da177e4SLinus Torvalds 	}
4151da177e4SLinus Torvalds 	if (change && mix->epcm) {
4161da177e4SLinus Torvalds 		if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
4171da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]);
4181da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[1]->number, mix->attn[2]);
4191da177e4SLinus Torvalds 		} else if (mix->epcm->voices[0]) {
4201da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]);
4211da177e4SLinus Torvalds 		}
4221da177e4SLinus Torvalds 	}
4231da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
4241da177e4SLinus Torvalds 	return change;
4251da177e4SLinus Torvalds }
4261da177e4SLinus Torvalds 
4271da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_attn_control =
4281da177e4SLinus Torvalds {
4291da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
43067ed4161SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
4311da177e4SLinus Torvalds 	.name =         "EMU10K1 PCM Volume",
4321da177e4SLinus Torvalds 	.count =	32,
4331da177e4SLinus Torvalds 	.info =         snd_emu10k1_attn_info,
4341da177e4SLinus Torvalds 	.get =          snd_emu10k1_attn_get,
4351da177e4SLinus Torvalds 	.put =          snd_emu10k1_attn_put
4361da177e4SLinus Torvalds };
4371da177e4SLinus Torvalds 
4381da177e4SLinus Torvalds /* Mutichannel PCM stream controls */
4391da177e4SLinus Torvalds 
4401da177e4SLinus Torvalds static int snd_emu10k1_efx_send_routing_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
4411da177e4SLinus Torvalds {
4421da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
4431da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4441da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 8 : 4;
4451da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
4461da177e4SLinus Torvalds 	uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
4471da177e4SLinus Torvalds 	return 0;
4481da177e4SLinus Torvalds }
4491da177e4SLinus Torvalds 
4501da177e4SLinus Torvalds static int snd_emu10k1_efx_send_routing_get(snd_kcontrol_t * kcontrol,
4511da177e4SLinus Torvalds                                         snd_ctl_elem_value_t * ucontrol)
4521da177e4SLinus Torvalds {
4531da177e4SLinus Torvalds 	unsigned long flags;
4541da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
4551da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
4561da177e4SLinus Torvalds 	int idx;
4571da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
4581da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
4591da177e4SLinus Torvalds 
4601da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
4611da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++)
4621da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] =
4631da177e4SLinus Torvalds 			mix->send_routing[0][idx] & mask;
4641da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
4651da177e4SLinus Torvalds 	return 0;
4661da177e4SLinus Torvalds }
4671da177e4SLinus Torvalds 
4681da177e4SLinus Torvalds static int snd_emu10k1_efx_send_routing_put(snd_kcontrol_t * kcontrol,
4691da177e4SLinus Torvalds                                         snd_ctl_elem_value_t * ucontrol)
4701da177e4SLinus Torvalds {
4711da177e4SLinus Torvalds 	unsigned long flags;
4721da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
4731da177e4SLinus Torvalds 	int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4741da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[ch];
4751da177e4SLinus Torvalds 	int change = 0, idx, val;
4761da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
4771da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
4781da177e4SLinus Torvalds 
4791da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
4801da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++) {
4811da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & mask;
4821da177e4SLinus Torvalds 		if (mix->send_routing[0][idx] != val) {
4831da177e4SLinus Torvalds 			mix->send_routing[0][idx] = val;
4841da177e4SLinus Torvalds 			change = 1;
4851da177e4SLinus Torvalds 		}
4861da177e4SLinus Torvalds 	}
4871da177e4SLinus Torvalds 
4881da177e4SLinus Torvalds 	if (change && mix->epcm) {
4891da177e4SLinus Torvalds 		if (mix->epcm->voices[ch]) {
4901da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number,
4911da177e4SLinus Torvalds 					&mix->send_routing[0][0]);
4921da177e4SLinus Torvalds 		}
4931da177e4SLinus Torvalds 	}
4941da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
4951da177e4SLinus Torvalds 	return change;
4961da177e4SLinus Torvalds }
4971da177e4SLinus Torvalds 
4981da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_efx_send_routing_control =
4991da177e4SLinus Torvalds {
5001da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
5011da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
5021da177e4SLinus Torvalds 	.name =         "Multichannel PCM Send Routing",
5031da177e4SLinus Torvalds 	.count =	16,
5041da177e4SLinus Torvalds 	.info =         snd_emu10k1_efx_send_routing_info,
5051da177e4SLinus Torvalds 	.get =          snd_emu10k1_efx_send_routing_get,
5061da177e4SLinus Torvalds 	.put =          snd_emu10k1_efx_send_routing_put
5071da177e4SLinus Torvalds };
5081da177e4SLinus Torvalds 
5091da177e4SLinus Torvalds static int snd_emu10k1_efx_send_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
5101da177e4SLinus Torvalds {
5111da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
5121da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5131da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 8 : 4;
5141da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
5151da177e4SLinus Torvalds 	uinfo->value.integer.max = 255;
5161da177e4SLinus Torvalds 	return 0;
5171da177e4SLinus Torvalds }
5181da177e4SLinus Torvalds 
5191da177e4SLinus Torvalds static int snd_emu10k1_efx_send_volume_get(snd_kcontrol_t * kcontrol,
5201da177e4SLinus Torvalds                                        snd_ctl_elem_value_t * ucontrol)
5211da177e4SLinus Torvalds {
5221da177e4SLinus Torvalds 	unsigned long flags;
5231da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
5241da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
5251da177e4SLinus Torvalds 	int idx;
5261da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
5271da177e4SLinus Torvalds 
5281da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
5291da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++)
5301da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] = mix->send_volume[0][idx];
5311da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
5321da177e4SLinus Torvalds 	return 0;
5331da177e4SLinus Torvalds }
5341da177e4SLinus Torvalds 
5351da177e4SLinus Torvalds static int snd_emu10k1_efx_send_volume_put(snd_kcontrol_t * kcontrol,
5361da177e4SLinus Torvalds                                        snd_ctl_elem_value_t * ucontrol)
5371da177e4SLinus Torvalds {
5381da177e4SLinus Torvalds 	unsigned long flags;
5391da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
5401da177e4SLinus Torvalds 	int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5411da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[ch];
5421da177e4SLinus Torvalds 	int change = 0, idx, val;
5431da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
5441da177e4SLinus Torvalds 
5451da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
5461da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++) {
5471da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & 255;
5481da177e4SLinus Torvalds 		if (mix->send_volume[0][idx] != val) {
5491da177e4SLinus Torvalds 			mix->send_volume[0][idx] = val;
5501da177e4SLinus Torvalds 			change = 1;
5511da177e4SLinus Torvalds 		}
5521da177e4SLinus Torvalds 	}
5531da177e4SLinus Torvalds 	if (change && mix->epcm) {
5541da177e4SLinus Torvalds 		if (mix->epcm->voices[ch]) {
5551da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number,
5561da177e4SLinus Torvalds 						   &mix->send_volume[0][0]);
5571da177e4SLinus Torvalds 		}
5581da177e4SLinus Torvalds 	}
5591da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
5601da177e4SLinus Torvalds 	return change;
5611da177e4SLinus Torvalds }
5621da177e4SLinus Torvalds 
5631da177e4SLinus Torvalds 
5641da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_efx_send_volume_control =
5651da177e4SLinus Torvalds {
5661da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
5671da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
5681da177e4SLinus Torvalds 	.name =         "Multichannel PCM Send Volume",
5691da177e4SLinus Torvalds 	.count =	16,
5701da177e4SLinus Torvalds 	.info =         snd_emu10k1_efx_send_volume_info,
5711da177e4SLinus Torvalds 	.get =          snd_emu10k1_efx_send_volume_get,
5721da177e4SLinus Torvalds 	.put =          snd_emu10k1_efx_send_volume_put
5731da177e4SLinus Torvalds };
5741da177e4SLinus Torvalds 
5751da177e4SLinus Torvalds static int snd_emu10k1_efx_attn_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
5761da177e4SLinus Torvalds {
5771da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
5781da177e4SLinus Torvalds 	uinfo->count = 1;
5791da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
5801da177e4SLinus Torvalds 	uinfo->value.integer.max = 0xffff;
5811da177e4SLinus Torvalds 	return 0;
5821da177e4SLinus Torvalds }
5831da177e4SLinus Torvalds 
5841da177e4SLinus Torvalds static int snd_emu10k1_efx_attn_get(snd_kcontrol_t * kcontrol,
5851da177e4SLinus Torvalds                                 snd_ctl_elem_value_t * ucontrol)
5861da177e4SLinus Torvalds {
5871da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
5881da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
5891da177e4SLinus Torvalds 	unsigned long flags;
5901da177e4SLinus Torvalds 
5911da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
5921da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = mix->attn[0];
5931da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
5941da177e4SLinus Torvalds 	return 0;
5951da177e4SLinus Torvalds }
5961da177e4SLinus Torvalds 
5971da177e4SLinus Torvalds static int snd_emu10k1_efx_attn_put(snd_kcontrol_t * kcontrol,
5981da177e4SLinus Torvalds 				snd_ctl_elem_value_t * ucontrol)
5991da177e4SLinus Torvalds {
6001da177e4SLinus Torvalds 	unsigned long flags;
6011da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
6021da177e4SLinus Torvalds 	int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6031da177e4SLinus Torvalds 	emu10k1_pcm_mixer_t *mix = &emu->efx_pcm_mixer[ch];
6041da177e4SLinus Torvalds 	int change = 0, val;
6051da177e4SLinus Torvalds 
6061da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
6071da177e4SLinus Torvalds 	val = ucontrol->value.integer.value[0] & 0xffff;
6081da177e4SLinus Torvalds 	if (mix->attn[0] != val) {
6091da177e4SLinus Torvalds 		mix->attn[0] = val;
6101da177e4SLinus Torvalds 		change = 1;
6111da177e4SLinus Torvalds 	}
6121da177e4SLinus Torvalds 	if (change && mix->epcm) {
6131da177e4SLinus Torvalds 		if (mix->epcm->voices[ch]) {
6141da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]);
6151da177e4SLinus Torvalds 		}
6161da177e4SLinus Torvalds 	}
6171da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
6181da177e4SLinus Torvalds 	return change;
6191da177e4SLinus Torvalds }
6201da177e4SLinus Torvalds 
6211da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_efx_attn_control =
6221da177e4SLinus Torvalds {
6231da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
6241da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
6251da177e4SLinus Torvalds 	.name =         "Multichannel PCM Volume",
6261da177e4SLinus Torvalds 	.count =	16,
6271da177e4SLinus Torvalds 	.info =         snd_emu10k1_efx_attn_info,
6281da177e4SLinus Torvalds 	.get =          snd_emu10k1_efx_attn_get,
6291da177e4SLinus Torvalds 	.put =          snd_emu10k1_efx_attn_put
6301da177e4SLinus Torvalds };
6311da177e4SLinus Torvalds 
6321da177e4SLinus Torvalds static int snd_emu10k1_shared_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
6331da177e4SLinus Torvalds {
6341da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
6351da177e4SLinus Torvalds 	uinfo->count = 1;
6361da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
6371da177e4SLinus Torvalds 	uinfo->value.integer.max = 1;
6381da177e4SLinus Torvalds 	return 0;
6391da177e4SLinus Torvalds }
6401da177e4SLinus Torvalds 
6411da177e4SLinus Torvalds static int snd_emu10k1_shared_spdif_get(snd_kcontrol_t * kcontrol,
6421da177e4SLinus Torvalds 					snd_ctl_elem_value_t * ucontrol)
6431da177e4SLinus Torvalds {
6441da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
6451da177e4SLinus Torvalds 
6461da177e4SLinus Torvalds 	if (emu->audigy)
6471da177e4SLinus Torvalds 		ucontrol->value.integer.value[0] = inl(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
6481da177e4SLinus Torvalds 	else
6491da177e4SLinus Torvalds 		ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
6501da177e4SLinus Torvalds 	return 0;
6511da177e4SLinus Torvalds }
6521da177e4SLinus Torvalds 
6531da177e4SLinus Torvalds static int snd_emu10k1_shared_spdif_put(snd_kcontrol_t * kcontrol,
6541da177e4SLinus Torvalds 					snd_ctl_elem_value_t * ucontrol)
6551da177e4SLinus Torvalds {
6561da177e4SLinus Torvalds 	unsigned long flags;
6571da177e4SLinus Torvalds 	emu10k1_t *emu = snd_kcontrol_chip(kcontrol);
6581da177e4SLinus Torvalds 	unsigned int reg, val;
6591da177e4SLinus Torvalds 	int change = 0;
6601da177e4SLinus Torvalds 
6611da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
6621da177e4SLinus Torvalds 	if (emu->audigy) {
6631da177e4SLinus Torvalds 		reg = inl(emu->port + A_IOCFG);
6641da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[0] ? A_IOCFG_GPOUT0 : 0;
6651da177e4SLinus Torvalds 		change = (reg & A_IOCFG_GPOUT0) != val;
6661da177e4SLinus Torvalds 		if (change) {
6671da177e4SLinus Torvalds 			reg &= ~A_IOCFG_GPOUT0;
6681da177e4SLinus Torvalds 			reg |= val;
6691da177e4SLinus Torvalds 			outl(reg | val, emu->port + A_IOCFG);
6701da177e4SLinus Torvalds 		}
6711da177e4SLinus Torvalds 	}
6721da177e4SLinus Torvalds 	reg = inl(emu->port + HCFG);
6731da177e4SLinus Torvalds 	val = ucontrol->value.integer.value[0] ? HCFG_GPOUT0 : 0;
6741da177e4SLinus Torvalds 	change |= (reg & HCFG_GPOUT0) != val;
6751da177e4SLinus Torvalds 	if (change) {
6761da177e4SLinus Torvalds 		reg &= ~HCFG_GPOUT0;
6771da177e4SLinus Torvalds 		reg |= val;
6781da177e4SLinus Torvalds 		outl(reg | val, emu->port + HCFG);
6791da177e4SLinus Torvalds 	}
6801da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
6811da177e4SLinus Torvalds 	return change;
6821da177e4SLinus Torvalds }
6831da177e4SLinus Torvalds 
6841da177e4SLinus Torvalds static snd_kcontrol_new_t snd_emu10k1_shared_spdif __devinitdata =
6851da177e4SLinus Torvalds {
6861da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
6871da177e4SLinus Torvalds 	.name =		"SB Live Analog/Digital Output Jack",
6881da177e4SLinus Torvalds 	.info =		snd_emu10k1_shared_spdif_info,
6891da177e4SLinus Torvalds 	.get =		snd_emu10k1_shared_spdif_get,
6901da177e4SLinus Torvalds 	.put =		snd_emu10k1_shared_spdif_put
6911da177e4SLinus Torvalds };
6921da177e4SLinus Torvalds 
6931da177e4SLinus Torvalds static snd_kcontrol_new_t snd_audigy_shared_spdif __devinitdata =
6941da177e4SLinus Torvalds {
6951da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
6961da177e4SLinus Torvalds 	.name =		"Audigy 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 
7021da177e4SLinus Torvalds /*
7031da177e4SLinus Torvalds  */
7041da177e4SLinus Torvalds static void snd_emu10k1_mixer_free_ac97(ac97_t *ac97)
7051da177e4SLinus Torvalds {
7061da177e4SLinus Torvalds 	emu10k1_t *emu = ac97->private_data;
7071da177e4SLinus Torvalds 	emu->ac97 = NULL;
7081da177e4SLinus Torvalds }
7091da177e4SLinus Torvalds 
7101da177e4SLinus Torvalds /*
7111da177e4SLinus Torvalds  */
7121da177e4SLinus Torvalds static int remove_ctl(snd_card_t *card, const char *name)
7131da177e4SLinus Torvalds {
7141da177e4SLinus Torvalds 	snd_ctl_elem_id_t id;
7151da177e4SLinus Torvalds 	memset(&id, 0, sizeof(id));
7161da177e4SLinus Torvalds 	strcpy(id.name, name);
7171da177e4SLinus Torvalds 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
7181da177e4SLinus Torvalds 	return snd_ctl_remove_id(card, &id);
7191da177e4SLinus Torvalds }
7201da177e4SLinus Torvalds 
7211da177e4SLinus Torvalds static snd_kcontrol_t *ctl_find(snd_card_t *card, const char *name)
7221da177e4SLinus Torvalds {
7231da177e4SLinus Torvalds 	snd_ctl_elem_id_t sid;
7241da177e4SLinus Torvalds 	memset(&sid, 0, sizeof(sid));
7251da177e4SLinus Torvalds 	strcpy(sid.name, name);
7261da177e4SLinus Torvalds 	sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
7271da177e4SLinus Torvalds 	return snd_ctl_find_id(card, &sid);
7281da177e4SLinus Torvalds }
7291da177e4SLinus Torvalds 
7301da177e4SLinus Torvalds static int rename_ctl(snd_card_t *card, const char *src, const char *dst)
7311da177e4SLinus Torvalds {
7321da177e4SLinus Torvalds 	snd_kcontrol_t *kctl = ctl_find(card, src);
7331da177e4SLinus Torvalds 	if (kctl) {
7341da177e4SLinus Torvalds 		strcpy(kctl->id.name, dst);
7351da177e4SLinus Torvalds 		return 0;
7361da177e4SLinus Torvalds 	}
7371da177e4SLinus Torvalds 	return -ENOENT;
7381da177e4SLinus Torvalds }
7391da177e4SLinus Torvalds 
74067ed4161SClemens Ladisch int __devinit snd_emu10k1_mixer(emu10k1_t *emu,
74167ed4161SClemens Ladisch 				int pcm_device, int multi_device)
7421da177e4SLinus Torvalds {
7431da177e4SLinus Torvalds 	int err, pcm;
7441da177e4SLinus Torvalds 	snd_kcontrol_t *kctl;
7451da177e4SLinus Torvalds 	snd_card_t *card = emu->card;
7461da177e4SLinus Torvalds 	char **c;
7471da177e4SLinus Torvalds 	static char *emu10k1_remove_ctls[] = {
7481da177e4SLinus Torvalds 		/* no AC97 mono, surround, center/lfe */
7491da177e4SLinus Torvalds 		"Master Mono Playback Switch",
7501da177e4SLinus Torvalds 		"Master Mono Playback Volume",
7511da177e4SLinus Torvalds 		"PCM Out Path & Mute",
7521da177e4SLinus Torvalds 		"Mono Output Select",
7531da177e4SLinus Torvalds 		"Surround Playback Switch",
7541da177e4SLinus Torvalds 		"Surround Playback Volume",
7551da177e4SLinus Torvalds 		"Center Playback Switch",
7561da177e4SLinus Torvalds 		"Center Playback Volume",
7571da177e4SLinus Torvalds 		"LFE Playback Switch",
7581da177e4SLinus Torvalds 		"LFE Playback Volume",
7591da177e4SLinus Torvalds 		NULL
7601da177e4SLinus Torvalds 	};
7611da177e4SLinus Torvalds 	static char *emu10k1_rename_ctls[] = {
7621da177e4SLinus Torvalds 		"Surround Digital Playback Volume", "Surround Playback Volume",
7631da177e4SLinus Torvalds 		"Center Digital Playback Volume", "Center Playback Volume",
7641da177e4SLinus Torvalds 		"LFE Digital Playback Volume", "LFE Playback Volume",
7651da177e4SLinus Torvalds 		NULL
7661da177e4SLinus Torvalds 	};
7671da177e4SLinus Torvalds 	static char *audigy_remove_ctls[] = {
7681da177e4SLinus Torvalds 		/* Master/PCM controls on ac97 of Audigy has no effect */
7691da177e4SLinus Torvalds 		"PCM Playback Switch",
7701da177e4SLinus Torvalds 		"PCM Playback Volume",
7711da177e4SLinus Torvalds 		"Master Mono Playback Switch",
7721da177e4SLinus Torvalds 		"Master Mono Playback Volume",
7731da177e4SLinus Torvalds 		"Master Playback Switch",
7741da177e4SLinus Torvalds 		"Master Playback Volume",
7751da177e4SLinus Torvalds 		"PCM Out Path & Mute",
7761da177e4SLinus Torvalds 		"Mono Output Select",
7771da177e4SLinus Torvalds 		/* remove unused AC97 capture controls */
7781da177e4SLinus Torvalds 		"Capture Source",
7791da177e4SLinus Torvalds 		"Capture Switch",
7801da177e4SLinus Torvalds 		"Capture Volume",
7811da177e4SLinus Torvalds 		"Mic Select",
7821da177e4SLinus Torvalds 		"Video Playback Switch",
7831da177e4SLinus Torvalds 		"Video Playback Volume",
7841da177e4SLinus Torvalds 		"Mic Playback Switch",
7851da177e4SLinus Torvalds 		"Mic Playback Volume",
7861da177e4SLinus Torvalds 		NULL
7871da177e4SLinus Torvalds 	};
7881da177e4SLinus Torvalds 	static char *audigy_rename_ctls[] = {
7891da177e4SLinus Torvalds 		/* use conventional names */
7901da177e4SLinus Torvalds 		"Wave Playback Volume", "PCM Playback Volume",
7911da177e4SLinus Torvalds 		/* "Wave Capture Volume", "PCM Capture Volume", */
7921da177e4SLinus Torvalds 		"Wave Master Playback Volume", "Master Playback Volume",
7931da177e4SLinus Torvalds 		"AMic Playback Volume", "Mic Playback Volume",
7941da177e4SLinus Torvalds 		NULL
7951da177e4SLinus Torvalds 	};
7961da177e4SLinus Torvalds 
7972b637da5SLee Revell 	if (emu->card_capabilities->ac97_chip) {
7981da177e4SLinus Torvalds 		ac97_bus_t *pbus;
7991da177e4SLinus Torvalds 		ac97_template_t ac97;
8001da177e4SLinus Torvalds 		static ac97_bus_ops_t ops = {
8011da177e4SLinus Torvalds 			.write = snd_emu10k1_ac97_write,
8021da177e4SLinus Torvalds 			.read = snd_emu10k1_ac97_read,
8031da177e4SLinus Torvalds 		};
8041da177e4SLinus Torvalds 
8051da177e4SLinus Torvalds 		if ((err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus)) < 0)
8061da177e4SLinus Torvalds 			return err;
8071da177e4SLinus Torvalds 		pbus->no_vra = 1; /* we don't need VRA */
8081da177e4SLinus Torvalds 
8091da177e4SLinus Torvalds 		memset(&ac97, 0, sizeof(ac97));
8101da177e4SLinus Torvalds 		ac97.private_data = emu;
8111da177e4SLinus Torvalds 		ac97.private_free = snd_emu10k1_mixer_free_ac97;
8121da177e4SLinus Torvalds 		ac97.scaps = AC97_SCAP_NO_SPDIF;
8131da177e4SLinus Torvalds 		if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0)
8141da177e4SLinus Torvalds 			return err;
8151da177e4SLinus Torvalds 		if (emu->audigy) {
8161da177e4SLinus Torvalds 			/* set master volume to 0 dB */
8171da177e4SLinus Torvalds 			snd_ac97_write(emu->ac97, AC97_MASTER, 0x0000);
8181da177e4SLinus Torvalds 			/* set capture source to mic */
8191da177e4SLinus Torvalds 			snd_ac97_write(emu->ac97, AC97_REC_SEL, 0x0000);
8201da177e4SLinus Torvalds 			c = audigy_remove_ctls;
8211da177e4SLinus Torvalds 		} else {
8221da177e4SLinus Torvalds 			/*
8231da177e4SLinus Torvalds 			 * Credits for cards based on STAC9758:
8241da177e4SLinus Torvalds 			 *   James Courtier-Dutton <James@superbug.demon.co.uk>
8251da177e4SLinus Torvalds 			 *   Voluspa <voluspa@comhem.se>
8261da177e4SLinus Torvalds 			 */
8271da177e4SLinus Torvalds 			if (emu->ac97->id == AC97_ID_STAC9758) {
8281da177e4SLinus Torvalds 				emu->rear_ac97 = 1;
8291da177e4SLinus Torvalds 				snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
8301da177e4SLinus Torvalds 			}
8311da177e4SLinus Torvalds 			/* remove unused AC97 controls */
8321da177e4SLinus Torvalds 			snd_ac97_write(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
8331da177e4SLinus Torvalds 			snd_ac97_write(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
8341da177e4SLinus Torvalds 			c = emu10k1_remove_ctls;
8351da177e4SLinus Torvalds 		}
8361da177e4SLinus Torvalds 		for (; *c; c++)
8371da177e4SLinus Torvalds 			remove_ctl(card, *c);
8381da177e4SLinus Torvalds 	} else {
8392b637da5SLee Revell 		if (emu->card_capabilities->ecard)
8401da177e4SLinus Torvalds 			strcpy(emu->card->mixername, "EMU APS");
8411da177e4SLinus Torvalds 		else if (emu->audigy)
8421da177e4SLinus Torvalds 			strcpy(emu->card->mixername, "SB Audigy");
8431da177e4SLinus Torvalds 		else
8441da177e4SLinus Torvalds 			strcpy(emu->card->mixername, "Emu10k1");
8451da177e4SLinus Torvalds 	}
8461da177e4SLinus Torvalds 
8471da177e4SLinus Torvalds 	if (emu->audigy)
8481da177e4SLinus Torvalds 		c = audigy_rename_ctls;
8491da177e4SLinus Torvalds 	else
8501da177e4SLinus Torvalds 		c = emu10k1_rename_ctls;
8511da177e4SLinus Torvalds 	for (; *c; c += 2)
8521da177e4SLinus Torvalds 		rename_ctl(card, c[0], c[1]);
8531da177e4SLinus Torvalds 
8541da177e4SLinus Torvalds 	if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL)
8551da177e4SLinus Torvalds 		return -ENOMEM;
85667ed4161SClemens Ladisch 	kctl->id.device = pcm_device;
8571da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8581da177e4SLinus Torvalds 		return err;
8591da177e4SLinus Torvalds 	if ((kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu)) == NULL)
8601da177e4SLinus Torvalds 		return -ENOMEM;
86167ed4161SClemens Ladisch 	kctl->id.device = pcm_device;
8621da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8631da177e4SLinus Torvalds 		return err;
8641da177e4SLinus Torvalds 	if ((kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu)) == NULL)
8651da177e4SLinus Torvalds 		return -ENOMEM;
86667ed4161SClemens Ladisch 	kctl->id.device = pcm_device;
8671da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8681da177e4SLinus Torvalds 		return err;
8691da177e4SLinus Torvalds 
8701da177e4SLinus Torvalds 	if ((kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu)) == NULL)
8711da177e4SLinus Torvalds 		return -ENOMEM;
87267ed4161SClemens Ladisch 	kctl->id.device = multi_device;
8731da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8741da177e4SLinus Torvalds 		return err;
8751da177e4SLinus Torvalds 
8761da177e4SLinus Torvalds 	if ((kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu)) == NULL)
8771da177e4SLinus Torvalds 		return -ENOMEM;
87867ed4161SClemens Ladisch 	kctl->id.device = multi_device;
8791da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8801da177e4SLinus Torvalds 		return err;
8811da177e4SLinus Torvalds 
8821da177e4SLinus Torvalds 	if ((kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu)) == NULL)
8831da177e4SLinus Torvalds 		return -ENOMEM;
88467ed4161SClemens Ladisch 	kctl->id.device = multi_device;
8851da177e4SLinus Torvalds 	if ((err = snd_ctl_add(card, kctl)))
8861da177e4SLinus Torvalds 		return err;
8871da177e4SLinus Torvalds 
8881da177e4SLinus Torvalds 	/* initialize the routing and volume table for each pcm playback stream */
8891da177e4SLinus Torvalds 	for (pcm = 0; pcm < 32; pcm++) {
8901da177e4SLinus Torvalds 		emu10k1_pcm_mixer_t *mix;
8911da177e4SLinus Torvalds 		int v;
8921da177e4SLinus Torvalds 
8931da177e4SLinus Torvalds 		mix = &emu->pcm_mixer[pcm];
8941da177e4SLinus Torvalds 		mix->epcm = NULL;
8951da177e4SLinus Torvalds 
8961da177e4SLinus Torvalds 		for (v = 0; v < 4; v++)
8971da177e4SLinus Torvalds 			mix->send_routing[0][v] =
8981da177e4SLinus Torvalds 				mix->send_routing[1][v] =
8991da177e4SLinus Torvalds 				mix->send_routing[2][v] = v;
9001da177e4SLinus Torvalds 
9011da177e4SLinus Torvalds 		memset(&mix->send_volume, 0, sizeof(mix->send_volume));
9021da177e4SLinus Torvalds 		mix->send_volume[0][0] = mix->send_volume[0][1] =
9031da177e4SLinus Torvalds 		mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
9041da177e4SLinus Torvalds 
9051da177e4SLinus Torvalds 		mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
9061da177e4SLinus Torvalds 	}
9071da177e4SLinus Torvalds 
9081da177e4SLinus Torvalds 	/* initialize the routing and volume table for the multichannel playback stream */
9091da177e4SLinus Torvalds 	for (pcm = 0; pcm < NUM_EFX_PLAYBACK; pcm++) {
9101da177e4SLinus Torvalds 		emu10k1_pcm_mixer_t *mix;
9111da177e4SLinus Torvalds 		int v;
9121da177e4SLinus Torvalds 
9131da177e4SLinus Torvalds 		mix = &emu->efx_pcm_mixer[pcm];
9141da177e4SLinus Torvalds 		mix->epcm = NULL;
9151da177e4SLinus Torvalds 
9161da177e4SLinus Torvalds 		mix->send_routing[0][0] = pcm;
9171da177e4SLinus Torvalds 		mix->send_routing[0][1] = (pcm == 0) ? 1 : 0;
9181da177e4SLinus Torvalds 		for (v = 0; v < 2; v++)
9191da177e4SLinus Torvalds 			mix->send_routing[0][2+v] = 13+v;
9201da177e4SLinus Torvalds 		if (emu->audigy)
9211da177e4SLinus Torvalds 			for (v = 0; v < 4; v++)
9221da177e4SLinus Torvalds 				mix->send_routing[0][4+v] = 60+v;
9231da177e4SLinus Torvalds 
9241da177e4SLinus Torvalds 		memset(&mix->send_volume, 0, sizeof(mix->send_volume));
9251da177e4SLinus Torvalds 		mix->send_volume[0][0]  = 255;
9261da177e4SLinus Torvalds 
9271da177e4SLinus Torvalds 		mix->attn[0] = 0xffff;
9281da177e4SLinus Torvalds 	}
9291da177e4SLinus Torvalds 
9302b637da5SLee Revell 	if (! emu->card_capabilities->ecard) { /* FIXME: APS has these controls? */
9311da177e4SLinus Torvalds 		/* sb live! and audigy */
9321da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu)) == NULL)
9331da177e4SLinus Torvalds 			return -ENOMEM;
934*5549d549SClemens Ladisch 		if (!emu->audigy)
935*5549d549SClemens Ladisch 			kctl->id.device = emu->pcm_efx->device;
9361da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9371da177e4SLinus Torvalds 			return err;
9381da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu)) == NULL)
9391da177e4SLinus Torvalds 			return -ENOMEM;
940*5549d549SClemens Ladisch 		if (!emu->audigy)
941*5549d549SClemens Ladisch 			kctl->id.device = emu->pcm_efx->device;
9421da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9431da177e4SLinus Torvalds 			return err;
9441da177e4SLinus Torvalds 	}
9451da177e4SLinus Torvalds 
9461da177e4SLinus Torvalds 	if (emu->audigy) {
9471da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu)) == NULL)
9481da177e4SLinus Torvalds 			return -ENOMEM;
9491da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9501da177e4SLinus Torvalds 			return err;
951001f7589SJames Courtier-Dutton #if 0
9521da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu)) == NULL)
9531da177e4SLinus Torvalds 			return -ENOMEM;
9541da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9551da177e4SLinus Torvalds 			return err;
956001f7589SJames Courtier-Dutton #endif
9572b637da5SLee Revell 	} else if (! emu->card_capabilities->ecard) {
9581da177e4SLinus Torvalds 		/* sb live! */
9591da177e4SLinus Torvalds 		if ((kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu)) == NULL)
9601da177e4SLinus Torvalds 			return -ENOMEM;
9611da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl)))
9621da177e4SLinus Torvalds 			return err;
9631da177e4SLinus Torvalds 	}
9642b637da5SLee Revell 	if (emu->card_capabilities->ca0151_chip) { /* P16V */
9651da177e4SLinus Torvalds 		if ((err = snd_p16v_mixer(emu)))
9661da177e4SLinus Torvalds 			return err;
9671da177e4SLinus Torvalds 	}
9681da177e4SLinus Torvalds 
9691da177e4SLinus Torvalds 	return 0;
9701da177e4SLinus Torvalds }
971