xref: /linux/sound/pci/emu10k1/emumixer.c (revision 216abe45cf4addba4e4c1eb2fae24762ffdefe9e)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
3c1017a4cSJaroslav Kysela  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
41da177e4SLinus Torvalds  *                   Takashi Iwai <tiwai@suse.de>
51da177e4SLinus Torvalds  *                   Creative Labs, Inc.
61da177e4SLinus Torvalds  *  Routines for control of EMU10K1 chips / mixer routines
71da177e4SLinus Torvalds  *  Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
81da177e4SLinus Torvalds  *
99f4bd5ddSJames Courtier-Dutton  *  Copyright (c) by James Courtier-Dutton <James@superbug.co.uk>
109f4bd5ddSJames Courtier-Dutton  *  	Added EMU 1010 support.
119f4bd5ddSJames Courtier-Dutton  *
121da177e4SLinus Torvalds  *  BUGS:
131da177e4SLinus Torvalds  *    --
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  *  TODO:
161da177e4SLinus Torvalds  *    --
171da177e4SLinus Torvalds  */
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #include <linux/time.h>
201da177e4SLinus Torvalds #include <linux/init.h>
211da177e4SLinus Torvalds #include <sound/core.h>
221da177e4SLinus Torvalds #include <sound/emu10k1.h>
23b0dbdaeaSJames Courtier-Dutton #include <linux/delay.h>
24184c1e2cSJames Courtier-Dutton #include <sound/tlv.h>
25184c1e2cSJames Courtier-Dutton 
26184c1e2cSJames Courtier-Dutton #include "p17v.h"
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #define AC97_ID_STAC9758	0x83847658
291da177e4SLinus Torvalds 
300cb29ea0STakashi Iwai static const DECLARE_TLV_DB_SCALE(snd_audigy_db_scale2, -10350, 50, 1); /* WM8775 gain scale */
31184c1e2cSJames Courtier-Dutton 
32536438f1SOswald Buddenhagen 
33536438f1SOswald Buddenhagen static int add_ctls(struct snd_emu10k1 *emu, const struct snd_kcontrol_new *tpl,
34536438f1SOswald Buddenhagen 		    const char * const *ctls, unsigned nctls)
35536438f1SOswald Buddenhagen {
36536438f1SOswald Buddenhagen 	struct snd_kcontrol_new kctl = *tpl;
37536438f1SOswald Buddenhagen 	int err;
38536438f1SOswald Buddenhagen 
39536438f1SOswald Buddenhagen 	for (unsigned i = 0; i < nctls; i++) {
40536438f1SOswald Buddenhagen 		kctl.name = ctls[i];
41536438f1SOswald Buddenhagen 		kctl.private_value = i;
42536438f1SOswald Buddenhagen 		err = snd_ctl_add(emu->card, snd_ctl_new1(&kctl, emu));
43536438f1SOswald Buddenhagen 		if (err < 0)
44536438f1SOswald Buddenhagen 			return err;
45536438f1SOswald Buddenhagen 	}
46536438f1SOswald Buddenhagen 	return 0;
47536438f1SOswald Buddenhagen }
48536438f1SOswald Buddenhagen 
49536438f1SOswald Buddenhagen 
50eb4698f3STakashi Iwai static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
511da177e4SLinus Torvalds {
521da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
531da177e4SLinus Torvalds 	uinfo->count = 1;
541da177e4SLinus Torvalds 	return 0;
551da177e4SLinus Torvalds }
561da177e4SLinus Torvalds 
57eb4698f3STakashi Iwai static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol,
58eb4698f3STakashi Iwai                                  struct snd_ctl_elem_value *ucontrol)
591da177e4SLinus Torvalds {
60eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
611da177e4SLinus Torvalds 	unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
621da177e4SLinus Torvalds 
6374415a36SJames Courtier-Dutton 	/* Limit: emu->spdif_bits */
6474415a36SJames Courtier-Dutton 	if (idx >= 3)
6574415a36SJames Courtier-Dutton 		return -EINVAL;
661da177e4SLinus Torvalds 	ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
671da177e4SLinus Torvalds 	ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
681da177e4SLinus Torvalds 	ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
691da177e4SLinus Torvalds 	ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
701da177e4SLinus Torvalds 	return 0;
711da177e4SLinus Torvalds }
721da177e4SLinus Torvalds 
73eb4698f3STakashi Iwai static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
74eb4698f3STakashi Iwai 				      struct snd_ctl_elem_value *ucontrol)
751da177e4SLinus Torvalds {
761da177e4SLinus Torvalds 	ucontrol->value.iec958.status[0] = 0xff;
771da177e4SLinus Torvalds 	ucontrol->value.iec958.status[1] = 0xff;
781da177e4SLinus Torvalds 	ucontrol->value.iec958.status[2] = 0xff;
791da177e4SLinus Torvalds 	ucontrol->value.iec958.status[3] = 0xff;
801da177e4SLinus Torvalds 	return 0;
811da177e4SLinus Torvalds }
821da177e4SLinus Torvalds 
83dc39bb3eSOswald Buddenhagen #define PAIR_PS(base, one, two, sfx) base " " one sfx, base " " two sfx
84dc39bb3eSOswald Buddenhagen #define LR_PS(base, sfx) PAIR_PS(base, "Left", "Right", sfx)
859f4bd5ddSJames Courtier-Dutton 
86dc39bb3eSOswald Buddenhagen #define ADAT_PS(pfx, sfx) \
87dc39bb3eSOswald Buddenhagen 	pfx "ADAT 0" sfx, pfx "ADAT 1" sfx, pfx "ADAT 2" sfx, pfx "ADAT 3" sfx, \
88dc39bb3eSOswald Buddenhagen 	pfx "ADAT 4" sfx, pfx "ADAT 5" sfx, pfx "ADAT 6" sfx, pfx "ADAT 7" sfx
891c02e366SCtirad Fertr 
90dc39bb3eSOswald Buddenhagen #define PAIR_REGS(base, one, two) \
91dc39bb3eSOswald Buddenhagen 	base ## one ## 1, \
92dc39bb3eSOswald Buddenhagen 	base ## two ## 1
931c02e366SCtirad Fertr 
94dc39bb3eSOswald Buddenhagen #define LR_REGS(base) PAIR_REGS(base, _LEFT, _RIGHT)
95dc39bb3eSOswald Buddenhagen 
96dc39bb3eSOswald Buddenhagen #define ADAT_REGS(base) \
97dc39bb3eSOswald Buddenhagen 	base+0, base+1, base+2, base+3, base+4, base+5, base+6, base+7
981c02e366SCtirad Fertr 
9913d45709SPavel Hofman /*
10013d45709SPavel Hofman  * List of data sources available for each destination
10113d45709SPavel Hofman  */
102dc39bb3eSOswald Buddenhagen 
103dc39bb3eSOswald Buddenhagen #define DSP_TEXTS \
104dc39bb3eSOswald Buddenhagen 	"DSP 0", "DSP 1", "DSP 2", "DSP 3", "DSP 4", "DSP 5", "DSP 6", "DSP 7", \
105dc39bb3eSOswald Buddenhagen 	"DSP 8", "DSP 9", "DSP 10", "DSP 11", "DSP 12", "DSP 13", "DSP 14", "DSP 15", \
106dc39bb3eSOswald Buddenhagen 	"DSP 16", "DSP 17", "DSP 18", "DSP 19", "DSP 20", "DSP 21", "DSP 22", "DSP 23", \
107dc39bb3eSOswald Buddenhagen 	"DSP 24", "DSP 25", "DSP 26", "DSP 27", "DSP 28", "DSP 29", "DSP 30", "DSP 31"
108dc39bb3eSOswald Buddenhagen 
109dc39bb3eSOswald Buddenhagen #define PAIR_TEXTS(base, one, two) PAIR_PS(base, one, two, "")
110dc39bb3eSOswald Buddenhagen #define LR_TEXTS(base) LR_PS(base, "")
111dc39bb3eSOswald Buddenhagen #define ADAT_TEXTS(pfx) ADAT_PS(pfx, "")
112dc39bb3eSOswald Buddenhagen 
113dc39bb3eSOswald Buddenhagen #define EMU32_SRC_REGS \
114dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A, \
115dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+1, \
116dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+2, \
117dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+3, \
118dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+4, \
119dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+5, \
120dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+6, \
121dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+7, \
122dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+8, \
123dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+9, \
124dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0xa, \
125dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0xb, \
126dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0xc, \
127dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0xd, \
128dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0xe, \
129dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0xf, \
130dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B, \
131dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+1, \
132dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+2, \
133dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+3, \
134dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+4, \
135dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+5, \
136dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+6, \
137dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+7, \
138dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+8, \
139dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+9, \
140dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+0xa, \
141dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+0xb, \
142dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+0xc, \
143dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+0xd, \
144dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+0xe, \
145dc39bb3eSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32B+0xf
146dc39bb3eSOswald Buddenhagen 
1476f3609f8SOswald Buddenhagen /* 1010 rev1 */
1486f3609f8SOswald Buddenhagen 
149dc39bb3eSOswald Buddenhagen #define EMU1010_COMMON_TEXTS \
150dc39bb3eSOswald Buddenhagen 	"Silence", \
151dc39bb3eSOswald Buddenhagen 	PAIR_TEXTS("Dock Mic", "A", "B"), \
152dc39bb3eSOswald Buddenhagen 	LR_TEXTS("Dock ADC1"), \
153dc39bb3eSOswald Buddenhagen 	LR_TEXTS("Dock ADC2"), \
154dc39bb3eSOswald Buddenhagen 	LR_TEXTS("Dock ADC3"), \
155dc39bb3eSOswald Buddenhagen 	LR_TEXTS("0202 ADC"), \
156dc39bb3eSOswald Buddenhagen 	LR_TEXTS("1010 SPDIF"), \
157dc39bb3eSOswald Buddenhagen 	ADAT_TEXTS("1010 ")
158dc39bb3eSOswald Buddenhagen 
159dc39bb3eSOswald Buddenhagen static const char * const emu1010_src_texts[] = {
160dc39bb3eSOswald Buddenhagen 	EMU1010_COMMON_TEXTS,
161dc39bb3eSOswald Buddenhagen 	DSP_TEXTS,
1629f4bd5ddSJames Courtier-Dutton };
1639f4bd5ddSJames Courtier-Dutton 
164dc39bb3eSOswald Buddenhagen static const unsigned short emu1010_src_regs[] = {
165dc39bb3eSOswald Buddenhagen 	EMU_SRC_SILENCE,
166dc39bb3eSOswald Buddenhagen 	PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
167dc39bb3eSOswald Buddenhagen 	LR_REGS(EMU_SRC_DOCK_ADC1),
168dc39bb3eSOswald Buddenhagen 	LR_REGS(EMU_SRC_DOCK_ADC2),
169dc39bb3eSOswald Buddenhagen 	LR_REGS(EMU_SRC_DOCK_ADC3),
170dc39bb3eSOswald Buddenhagen 	LR_REGS(EMU_SRC_HAMOA_ADC),
171dc39bb3eSOswald Buddenhagen 	LR_REGS(EMU_SRC_HANA_SPDIF),
172dc39bb3eSOswald Buddenhagen 	ADAT_REGS(EMU_SRC_HANA_ADAT),
173dc39bb3eSOswald Buddenhagen 	EMU32_SRC_REGS,
174dc39bb3eSOswald Buddenhagen };
175dc39bb3eSOswald Buddenhagen static_assert(ARRAY_SIZE(emu1010_src_regs) == ARRAY_SIZE(emu1010_src_texts));
176dc39bb3eSOswald Buddenhagen 
177f69d705dSOswald Buddenhagen /* 1010 rev2 */
178f69d705dSOswald Buddenhagen 
179f69d705dSOswald Buddenhagen #define EMU1010b_COMMON_TEXTS \
180f69d705dSOswald Buddenhagen 	"Silence", \
181f69d705dSOswald Buddenhagen 	PAIR_TEXTS("Dock Mic", "A", "B"), \
182f69d705dSOswald Buddenhagen 	LR_TEXTS("Dock ADC1"), \
183f69d705dSOswald Buddenhagen 	LR_TEXTS("Dock ADC2"), \
184f69d705dSOswald Buddenhagen 	LR_TEXTS("0202 ADC"), \
185f69d705dSOswald Buddenhagen 	LR_TEXTS("Dock SPDIF"), \
186f69d705dSOswald Buddenhagen 	LR_TEXTS("1010 SPDIF"), \
187f69d705dSOswald Buddenhagen 	ADAT_TEXTS("Dock "), \
188f69d705dSOswald Buddenhagen 	ADAT_TEXTS("1010 ")
189f69d705dSOswald Buddenhagen 
190f69d705dSOswald Buddenhagen static const char * const emu1010b_src_texts[] = {
191f69d705dSOswald Buddenhagen 	EMU1010b_COMMON_TEXTS,
192f69d705dSOswald Buddenhagen 	DSP_TEXTS,
193f69d705dSOswald Buddenhagen };
194f69d705dSOswald Buddenhagen 
195f69d705dSOswald Buddenhagen static const unsigned short emu1010b_src_regs[] = {
196f69d705dSOswald Buddenhagen 	EMU_SRC_SILENCE,
197f69d705dSOswald Buddenhagen 	PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
198f69d705dSOswald Buddenhagen 	LR_REGS(EMU_SRC_DOCK_ADC1),
199f69d705dSOswald Buddenhagen 	LR_REGS(EMU_SRC_DOCK_ADC2),
200f69d705dSOswald Buddenhagen 	LR_REGS(EMU_SRC_HAMOA_ADC),
201f69d705dSOswald Buddenhagen 	LR_REGS(EMU_SRC_MDOCK_SPDIF),
202f69d705dSOswald Buddenhagen 	LR_REGS(EMU_SRC_HANA_SPDIF),
203f69d705dSOswald Buddenhagen 	ADAT_REGS(EMU_SRC_MDOCK_ADAT),
204f69d705dSOswald Buddenhagen 	ADAT_REGS(EMU_SRC_HANA_ADAT),
205f69d705dSOswald Buddenhagen 	EMU32_SRC_REGS,
206f69d705dSOswald Buddenhagen };
207f69d705dSOswald Buddenhagen static_assert(ARRAY_SIZE(emu1010b_src_regs) == ARRAY_SIZE(emu1010b_src_texts));
208f69d705dSOswald Buddenhagen 
2091c02e366SCtirad Fertr /* 1616(m) cardbus */
210dc39bb3eSOswald Buddenhagen 
211dc39bb3eSOswald Buddenhagen #define EMU1616_COMMON_TEXTS \
212dc39bb3eSOswald Buddenhagen 	"Silence", \
213dc39bb3eSOswald Buddenhagen 	PAIR_TEXTS("Mic", "A", "B"), \
214dc39bb3eSOswald Buddenhagen 	LR_TEXTS("ADC1"), \
215dc39bb3eSOswald Buddenhagen 	LR_TEXTS("ADC2"), \
216dc39bb3eSOswald Buddenhagen 	LR_TEXTS("SPDIF"), \
217dc39bb3eSOswald Buddenhagen 	ADAT_TEXTS("")
218dc39bb3eSOswald Buddenhagen 
219dc39bb3eSOswald Buddenhagen static const char * const emu1616_src_texts[] = {
220dc39bb3eSOswald Buddenhagen 	EMU1616_COMMON_TEXTS,
221dc39bb3eSOswald Buddenhagen 	DSP_TEXTS,
222dc39bb3eSOswald Buddenhagen };
223dc39bb3eSOswald Buddenhagen 
2249b00a1e9SOswald Buddenhagen static const unsigned short emu1616_src_regs[] = {
2251c02e366SCtirad Fertr 	EMU_SRC_SILENCE,
226dc39bb3eSOswald Buddenhagen 	PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
227dc39bb3eSOswald Buddenhagen 	LR_REGS(EMU_SRC_DOCK_ADC1),
228dc39bb3eSOswald Buddenhagen 	LR_REGS(EMU_SRC_DOCK_ADC2),
229dc39bb3eSOswald Buddenhagen 	LR_REGS(EMU_SRC_MDOCK_SPDIF),
230dc39bb3eSOswald Buddenhagen 	ADAT_REGS(EMU_SRC_MDOCK_ADAT),
231dc39bb3eSOswald Buddenhagen 	EMU32_SRC_REGS,
2321c02e366SCtirad Fertr };
233dc39bb3eSOswald Buddenhagen static_assert(ARRAY_SIZE(emu1616_src_regs) == ARRAY_SIZE(emu1616_src_texts));
2341c02e366SCtirad Fertr 
2356f3609f8SOswald Buddenhagen /* 0404 rev1 & rev2 */
2366f3609f8SOswald Buddenhagen 
2376f3609f8SOswald Buddenhagen #define EMU0404_COMMON_TEXTS \
2386f3609f8SOswald Buddenhagen 	"Silence", \
2396f3609f8SOswald Buddenhagen 	LR_TEXTS("ADC"), \
2406f3609f8SOswald Buddenhagen 	LR_TEXTS("SPDIF")
2416f3609f8SOswald Buddenhagen 
2426f3609f8SOswald Buddenhagen static const char * const emu0404_src_texts[] = {
2436f3609f8SOswald Buddenhagen 	EMU0404_COMMON_TEXTS,
2446f3609f8SOswald Buddenhagen 	DSP_TEXTS,
2456f3609f8SOswald Buddenhagen };
2466f3609f8SOswald Buddenhagen 
2476f3609f8SOswald Buddenhagen static const unsigned short emu0404_src_regs[] = {
2486f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
2496f3609f8SOswald Buddenhagen 	LR_REGS(EMU_SRC_HAMOA_ADC),
2506f3609f8SOswald Buddenhagen 	LR_REGS(EMU_SRC_HANA_SPDIF),
2516f3609f8SOswald Buddenhagen 	EMU32_SRC_REGS,
2526f3609f8SOswald Buddenhagen };
2536f3609f8SOswald Buddenhagen static_assert(ARRAY_SIZE(emu0404_src_regs) == ARRAY_SIZE(emu0404_src_texts));
2546f3609f8SOswald Buddenhagen 
25513d45709SPavel Hofman /*
25613d45709SPavel Hofman  * Data destinations - physical EMU outputs.
25713d45709SPavel Hofman  * Each destination has an enum mixer control to choose a data source
25813d45709SPavel Hofman  */
259536438f1SOswald Buddenhagen 
260536438f1SOswald Buddenhagen #define LR_CTLS(base) LR_PS(base, " Playback Enum")
261536438f1SOswald Buddenhagen #define ADAT_CTLS(pfx) ADAT_PS(pfx, " Playback Enum")
262536438f1SOswald Buddenhagen 
2636f3609f8SOswald Buddenhagen /* 1010 rev1 */
2646f3609f8SOswald Buddenhagen 
265536438f1SOswald Buddenhagen static const char * const emu1010_output_texts[] = {
266536438f1SOswald Buddenhagen 	LR_CTLS("Dock DAC1"),
267536438f1SOswald Buddenhagen 	LR_CTLS("Dock DAC2"),
268536438f1SOswald Buddenhagen 	LR_CTLS("Dock DAC3"),
269536438f1SOswald Buddenhagen 	LR_CTLS("Dock DAC4"),
270536438f1SOswald Buddenhagen 	LR_CTLS("Dock Phones"),
271536438f1SOswald Buddenhagen 	LR_CTLS("Dock SPDIF"),
272536438f1SOswald Buddenhagen 	LR_CTLS("0202 DAC"),
273536438f1SOswald Buddenhagen 	LR_CTLS("1010 SPDIF"),
274536438f1SOswald Buddenhagen 	ADAT_CTLS("1010 "),
2759f4bd5ddSJames Courtier-Dutton };
276*216abe45SOswald Buddenhagen static_assert(ARRAY_SIZE(emu1010_output_texts) <= NUM_OUTPUT_DESTS);
2779f4bd5ddSJames Courtier-Dutton 
278536438f1SOswald Buddenhagen static const unsigned short emu1010_output_dst[] = {
279536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC1),
280536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC2),
281536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC3),
282536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC4),
283536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_PHONES),
284536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_SPDIF),
285536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_HAMOA_DAC),
286536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_HANA_SPDIF),
287536438f1SOswald Buddenhagen 	ADAT_REGS(EMU_DST_HANA_ADAT),
2881c02e366SCtirad Fertr };
289536438f1SOswald Buddenhagen static_assert(ARRAY_SIZE(emu1010_output_dst) == ARRAY_SIZE(emu1010_output_texts));
290536438f1SOswald Buddenhagen 
2911fc710f0SOswald Buddenhagen static const unsigned short emu1010_output_dflt[] = {
2921fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
2931fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
2941fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5,
2951fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
2961fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
2971fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
2981fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
2991fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
3001fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
3011fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
3021fc710f0SOswald Buddenhagen };
3031fc710f0SOswald Buddenhagen static_assert(ARRAY_SIZE(emu1010_output_dflt) == ARRAY_SIZE(emu1010_output_dst));
3041fc710f0SOswald Buddenhagen 
305f69d705dSOswald Buddenhagen /* 1010 rev2 */
306f69d705dSOswald Buddenhagen 
307f69d705dSOswald Buddenhagen static const char * const snd_emu1010b_output_texts[] = {
308f69d705dSOswald Buddenhagen 	LR_CTLS("Dock DAC1"),
309f69d705dSOswald Buddenhagen 	LR_CTLS("Dock DAC2"),
310f69d705dSOswald Buddenhagen 	LR_CTLS("Dock DAC3"),
311f69d705dSOswald Buddenhagen 	LR_CTLS("Dock SPDIF"),
312f69d705dSOswald Buddenhagen 	ADAT_CTLS("Dock "),
313f69d705dSOswald Buddenhagen 	LR_CTLS("0202 DAC"),
314f69d705dSOswald Buddenhagen 	LR_CTLS("1010 SPDIF"),
315f69d705dSOswald Buddenhagen 	ADAT_CTLS("1010 "),
316f69d705dSOswald Buddenhagen };
317*216abe45SOswald Buddenhagen static_assert(ARRAY_SIZE(snd_emu1010b_output_texts) <= NUM_OUTPUT_DESTS);
318f69d705dSOswald Buddenhagen 
319f69d705dSOswald Buddenhagen static const unsigned short emu1010b_output_dst[] = {
320f69d705dSOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC1),
321f69d705dSOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC2),
322f69d705dSOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC3),
323f69d705dSOswald Buddenhagen 	LR_REGS(EMU_DST_MDOCK_SPDIF),
324f69d705dSOswald Buddenhagen 	ADAT_REGS(EMU_DST_MDOCK_ADAT),
325f69d705dSOswald Buddenhagen 	LR_REGS(EMU_DST_HAMOA_DAC),
326f69d705dSOswald Buddenhagen 	LR_REGS(EMU_DST_HANA_SPDIF),
327f69d705dSOswald Buddenhagen 	ADAT_REGS(EMU_DST_HANA_ADAT),
328f69d705dSOswald Buddenhagen };
329f69d705dSOswald Buddenhagen static_assert(ARRAY_SIZE(emu1010b_output_dst) == ARRAY_SIZE(snd_emu1010b_output_texts));
330f69d705dSOswald Buddenhagen 
331f69d705dSOswald Buddenhagen static const unsigned short emu1010b_output_dflt[] = {
332f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
333f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
334f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5,
335f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
336f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
337f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
338f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
339f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
340f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
341f69d705dSOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
342f69d705dSOswald Buddenhagen };
343f69d705dSOswald Buddenhagen 
344536438f1SOswald Buddenhagen /* 1616(m) cardbus */
345536438f1SOswald Buddenhagen 
346536438f1SOswald Buddenhagen static const char * const snd_emu1616_output_texts[] = {
347536438f1SOswald Buddenhagen 	LR_CTLS("Dock DAC1"),
348536438f1SOswald Buddenhagen 	LR_CTLS("Dock DAC2"),
349536438f1SOswald Buddenhagen 	LR_CTLS("Dock DAC3"),
350536438f1SOswald Buddenhagen 	LR_CTLS("Dock SPDIF"),
351536438f1SOswald Buddenhagen 	ADAT_CTLS("Dock "),
352536438f1SOswald Buddenhagen 	LR_CTLS("Mana DAC"),
353536438f1SOswald Buddenhagen };
354*216abe45SOswald Buddenhagen static_assert(ARRAY_SIZE(snd_emu1616_output_texts) <= NUM_OUTPUT_DESTS);
355536438f1SOswald Buddenhagen 
356536438f1SOswald Buddenhagen static const unsigned short emu1616_output_dst[] = {
357536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC1),
358536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC2),
359536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_DOCK_DAC3),
360536438f1SOswald Buddenhagen 	LR_REGS(EMU_DST_MDOCK_SPDIF),
361536438f1SOswald Buddenhagen 	ADAT_REGS(EMU_DST_MDOCK_ADAT),
362536438f1SOswald Buddenhagen 	EMU_DST_MANA_DAC_LEFT, EMU_DST_MANA_DAC_RIGHT,
363536438f1SOswald Buddenhagen };
364536438f1SOswald Buddenhagen static_assert(ARRAY_SIZE(emu1616_output_dst) == ARRAY_SIZE(snd_emu1616_output_texts));
3651c02e366SCtirad Fertr 
3661fc710f0SOswald Buddenhagen static const unsigned short emu1616_output_dflt[] = {
3671fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
3681fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
3691fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5,
3701fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
3711fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
3721fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
3731fc710f0SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
3741fc710f0SOswald Buddenhagen };
3751fc710f0SOswald Buddenhagen static_assert(ARRAY_SIZE(emu1616_output_dflt) == ARRAY_SIZE(emu1616_output_dst));
3761fc710f0SOswald Buddenhagen 
3776f3609f8SOswald Buddenhagen /* 0404 rev1 & rev2 */
3786f3609f8SOswald Buddenhagen 
3796f3609f8SOswald Buddenhagen static const char * const snd_emu0404_output_texts[] = {
3806f3609f8SOswald Buddenhagen 	LR_CTLS("DAC"),
3816f3609f8SOswald Buddenhagen 	LR_CTLS("SPDIF"),
3826f3609f8SOswald Buddenhagen };
383*216abe45SOswald Buddenhagen static_assert(ARRAY_SIZE(snd_emu0404_output_texts) <= NUM_OUTPUT_DESTS);
3846f3609f8SOswald Buddenhagen 
3856f3609f8SOswald Buddenhagen static const unsigned short emu0404_output_dst[] = {
3866f3609f8SOswald Buddenhagen 	LR_REGS(EMU_DST_HAMOA_DAC),
3876f3609f8SOswald Buddenhagen 	LR_REGS(EMU_DST_HANA_SPDIF),
3886f3609f8SOswald Buddenhagen };
3896f3609f8SOswald Buddenhagen static_assert(ARRAY_SIZE(emu0404_output_dst) == ARRAY_SIZE(snd_emu0404_output_texts));
3906f3609f8SOswald Buddenhagen 
3916f3609f8SOswald Buddenhagen static const unsigned short emu0404_output_dflt[] = {
3926f3609f8SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
3936f3609f8SOswald Buddenhagen 	EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
3946f3609f8SOswald Buddenhagen };
3956f3609f8SOswald Buddenhagen static_assert(ARRAY_SIZE(emu0404_output_dflt) == ARRAY_SIZE(emu0404_output_dst));
3966f3609f8SOswald Buddenhagen 
39713d45709SPavel Hofman /*
398a869057cSOswald Buddenhagen  * Data destinations - FPGA outputs going to Alice2 (Audigy) for
39913d45709SPavel Hofman  *   capture (EMU32 + I2S links)
40013d45709SPavel Hofman  * Each destination has an enum mixer control to choose a data source
40113d45709SPavel Hofman  */
402536438f1SOswald Buddenhagen 
403536438f1SOswald Buddenhagen static const char * const emu1010_input_texts[] = {
404536438f1SOswald Buddenhagen 	"DSP 0 Capture Enum",
405536438f1SOswald Buddenhagen 	"DSP 1 Capture Enum",
406536438f1SOswald Buddenhagen 	"DSP 2 Capture Enum",
407536438f1SOswald Buddenhagen 	"DSP 3 Capture Enum",
408536438f1SOswald Buddenhagen 	"DSP 4 Capture Enum",
409536438f1SOswald Buddenhagen 	"DSP 5 Capture Enum",
410536438f1SOswald Buddenhagen 	"DSP 6 Capture Enum",
411536438f1SOswald Buddenhagen 	"DSP 7 Capture Enum",
412536438f1SOswald Buddenhagen 	"DSP 8 Capture Enum",
413536438f1SOswald Buddenhagen 	"DSP 9 Capture Enum",
414536438f1SOswald Buddenhagen 	"DSP A Capture Enum",
415536438f1SOswald Buddenhagen 	"DSP B Capture Enum",
416536438f1SOswald Buddenhagen 	"DSP C Capture Enum",
417536438f1SOswald Buddenhagen 	"DSP D Capture Enum",
418536438f1SOswald Buddenhagen 	"DSP E Capture Enum",
419536438f1SOswald Buddenhagen 	"DSP F Capture Enum",
420536438f1SOswald Buddenhagen 	/* These exist only on rev1 EMU1010 cards. */
421536438f1SOswald Buddenhagen 	"DSP 10 Capture Enum",
422536438f1SOswald Buddenhagen 	"DSP 11 Capture Enum",
423536438f1SOswald Buddenhagen 	"DSP 12 Capture Enum",
424536438f1SOswald Buddenhagen 	"DSP 13 Capture Enum",
425536438f1SOswald Buddenhagen 	"DSP 14 Capture Enum",
426536438f1SOswald Buddenhagen 	"DSP 15 Capture Enum",
427536438f1SOswald Buddenhagen };
428*216abe45SOswald Buddenhagen static_assert(ARRAY_SIZE(emu1010_input_texts) <= NUM_INPUT_DESTS);
429536438f1SOswald Buddenhagen 
4309b00a1e9SOswald Buddenhagen static const unsigned short emu1010_input_dst[] = {
4319f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_0,
4329f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_1,
4339f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_2,
4349f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_3,
4359f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_4,
4369f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_5,
4379f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_6,
4389f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_7,
4399f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_8,
4409f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_9,
4419f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_A,
4429f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_B,
4439f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_C,
4449f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_D,
4459f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_E,
4469f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE2_EMU32_F,
447a869057cSOswald Buddenhagen 	/* These exist only on rev1 EMU1010 cards. */
4489f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE_I2S0_LEFT,
4499f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE_I2S0_RIGHT,
4509f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE_I2S1_LEFT,
4519f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE_I2S1_RIGHT,
4529f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE_I2S2_LEFT,
4539f4bd5ddSJames Courtier-Dutton 	EMU_DST_ALICE_I2S2_RIGHT,
4549f4bd5ddSJames Courtier-Dutton };
455536438f1SOswald Buddenhagen static_assert(ARRAY_SIZE(emu1010_input_dst) == ARRAY_SIZE(emu1010_input_texts));
4569f4bd5ddSJames Courtier-Dutton 
4571fc710f0SOswald Buddenhagen static const unsigned short emu1010_input_dflt[] = {
4581fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_MIC_A1,
4591fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_MIC_B1,
4601fc710f0SOswald Buddenhagen 	EMU_SRC_HAMOA_ADC_LEFT1,
4611fc710f0SOswald Buddenhagen 	EMU_SRC_HAMOA_ADC_RIGHT1,
4621fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC1_LEFT1,
4631fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC1_RIGHT1,
4641fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC2_LEFT1,
4651fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC2_RIGHT1,
4661fc710f0SOswald Buddenhagen 	/* Pavel Hofman - setting defaults for all capture channels.
4671fc710f0SOswald Buddenhagen 	 * Defaults only, users will set their own values anyways, let's
4681fc710f0SOswald Buddenhagen 	 * just copy/paste. */
4691fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_MIC_A1,
4701fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_MIC_B1,
4711fc710f0SOswald Buddenhagen 	EMU_SRC_HAMOA_ADC_LEFT1,
4721fc710f0SOswald Buddenhagen 	EMU_SRC_HAMOA_ADC_RIGHT1,
4731fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC1_LEFT1,
4741fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC1_RIGHT1,
4751fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC2_LEFT1,
4761fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC2_RIGHT1,
4771fc710f0SOswald Buddenhagen 
4781fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC1_LEFT1,
4791fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC1_RIGHT1,
4801fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC2_LEFT1,
4811fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC2_RIGHT1,
4821fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC3_LEFT1,
4831fc710f0SOswald Buddenhagen 	EMU_SRC_DOCK_ADC3_RIGHT1,
4841fc710f0SOswald Buddenhagen };
4851fc710f0SOswald Buddenhagen static_assert(ARRAY_SIZE(emu1010_input_dflt) == ARRAY_SIZE(emu1010_input_dst));
4861fc710f0SOswald Buddenhagen 
4876f3609f8SOswald Buddenhagen static const unsigned short emu0404_input_dflt[] = {
4886f3609f8SOswald Buddenhagen 	EMU_SRC_HAMOA_ADC_LEFT1,
4896f3609f8SOswald Buddenhagen 	EMU_SRC_HAMOA_ADC_RIGHT1,
4906f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
4916f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
4926f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
4936f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
4946f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
4956f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
4966f3609f8SOswald Buddenhagen 	EMU_SRC_HANA_SPDIF_LEFT1,
4976f3609f8SOswald Buddenhagen 	EMU_SRC_HANA_SPDIF_RIGHT1,
4986f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
4996f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
5006f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
5016f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
5026f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
5036f3609f8SOswald Buddenhagen 	EMU_SRC_SILENCE,
5046f3609f8SOswald Buddenhagen };
5056f3609f8SOswald Buddenhagen 
506511cbe8fSOswald Buddenhagen struct snd_emu1010_routing_info {
507511cbe8fSOswald Buddenhagen 	const char * const *src_texts;
50897f1582eSOswald Buddenhagen 	const char * const *out_texts;
509511cbe8fSOswald Buddenhagen 	const unsigned short *src_regs;
510511cbe8fSOswald Buddenhagen 	const unsigned short *out_regs;
511511cbe8fSOswald Buddenhagen 	const unsigned short *in_regs;
5121fc710f0SOswald Buddenhagen 	const unsigned short *out_dflts;
5131fc710f0SOswald Buddenhagen 	const unsigned short *in_dflts;
514511cbe8fSOswald Buddenhagen 	unsigned n_srcs;
515511cbe8fSOswald Buddenhagen 	unsigned n_outs;
516511cbe8fSOswald Buddenhagen 	unsigned n_ins;
517511cbe8fSOswald Buddenhagen };
518511cbe8fSOswald Buddenhagen 
519511cbe8fSOswald Buddenhagen const struct snd_emu1010_routing_info emu1010_routing_info[] = {
520511cbe8fSOswald Buddenhagen 	{
5216f3609f8SOswald Buddenhagen 		/* rev1 1010 */
522511cbe8fSOswald Buddenhagen 		.src_regs = emu1010_src_regs,
523511cbe8fSOswald Buddenhagen 		.src_texts = emu1010_src_texts,
524511cbe8fSOswald Buddenhagen 		.n_srcs = ARRAY_SIZE(emu1010_src_texts),
525511cbe8fSOswald Buddenhagen 
5261fc710f0SOswald Buddenhagen 		.out_dflts = emu1010_output_dflt,
527511cbe8fSOswald Buddenhagen 		.out_regs = emu1010_output_dst,
52897f1582eSOswald Buddenhagen 		.out_texts = emu1010_output_texts,
529511cbe8fSOswald Buddenhagen 		.n_outs = ARRAY_SIZE(emu1010_output_dst),
530511cbe8fSOswald Buddenhagen 
5311fc710f0SOswald Buddenhagen 		.in_dflts = emu1010_input_dflt,
532511cbe8fSOswald Buddenhagen 		.in_regs = emu1010_input_dst,
533511cbe8fSOswald Buddenhagen 		.n_ins = ARRAY_SIZE(emu1010_input_dst),
534511cbe8fSOswald Buddenhagen 	},
535511cbe8fSOswald Buddenhagen 	{
536f69d705dSOswald Buddenhagen 		/* rev2 1010 */
537f69d705dSOswald Buddenhagen 		.src_regs = emu1010b_src_regs,
538f69d705dSOswald Buddenhagen 		.src_texts = emu1010b_src_texts,
539f69d705dSOswald Buddenhagen 		.n_srcs = ARRAY_SIZE(emu1010b_src_texts),
540f69d705dSOswald Buddenhagen 
541f69d705dSOswald Buddenhagen 		.out_dflts = emu1010b_output_dflt,
542f69d705dSOswald Buddenhagen 		.out_regs = emu1010b_output_dst,
543f69d705dSOswald Buddenhagen 		.out_texts = snd_emu1010b_output_texts,
544f69d705dSOswald Buddenhagen 		.n_outs = ARRAY_SIZE(emu1010b_output_dst),
545f69d705dSOswald Buddenhagen 
546f69d705dSOswald Buddenhagen 		.in_dflts = emu1010_input_dflt,
547f69d705dSOswald Buddenhagen 		.in_regs = emu1010_input_dst,
548f69d705dSOswald Buddenhagen 		.n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
549f69d705dSOswald Buddenhagen 	},
550f69d705dSOswald Buddenhagen 	{
551511cbe8fSOswald Buddenhagen 		/* 1616(m) cardbus */
552511cbe8fSOswald Buddenhagen 		.src_regs = emu1616_src_regs,
553511cbe8fSOswald Buddenhagen 		.src_texts = emu1616_src_texts,
554511cbe8fSOswald Buddenhagen 		.n_srcs = ARRAY_SIZE(emu1616_src_texts),
555511cbe8fSOswald Buddenhagen 
5561fc710f0SOswald Buddenhagen 		.out_dflts = emu1616_output_dflt,
557511cbe8fSOswald Buddenhagen 		.out_regs = emu1616_output_dst,
55897f1582eSOswald Buddenhagen 		.out_texts = snd_emu1616_output_texts,
559511cbe8fSOswald Buddenhagen 		.n_outs = ARRAY_SIZE(emu1616_output_dst),
560511cbe8fSOswald Buddenhagen 
5611fc710f0SOswald Buddenhagen 		.in_dflts = emu1010_input_dflt,
562511cbe8fSOswald Buddenhagen 		.in_regs = emu1010_input_dst,
563511cbe8fSOswald Buddenhagen 		.n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
564511cbe8fSOswald Buddenhagen 	},
5656f3609f8SOswald Buddenhagen 	{
5666f3609f8SOswald Buddenhagen 		/* 0404 */
5676f3609f8SOswald Buddenhagen 		.src_regs = emu0404_src_regs,
5686f3609f8SOswald Buddenhagen 		.src_texts = emu0404_src_texts,
5696f3609f8SOswald Buddenhagen 		.n_srcs = ARRAY_SIZE(emu0404_src_texts),
5706f3609f8SOswald Buddenhagen 
5716f3609f8SOswald Buddenhagen 		.out_dflts = emu0404_output_dflt,
5726f3609f8SOswald Buddenhagen 		.out_regs = emu0404_output_dst,
5736f3609f8SOswald Buddenhagen 		.out_texts = snd_emu0404_output_texts,
5746f3609f8SOswald Buddenhagen 		.n_outs = ARRAY_SIZE(emu0404_output_dflt),
5756f3609f8SOswald Buddenhagen 
5766f3609f8SOswald Buddenhagen 		.in_dflts = emu0404_input_dflt,
5776f3609f8SOswald Buddenhagen 		.in_regs = emu1010_input_dst,
5786f3609f8SOswald Buddenhagen 		.n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
5796f3609f8SOswald Buddenhagen 	},
580511cbe8fSOswald Buddenhagen };
581511cbe8fSOswald Buddenhagen 
582511cbe8fSOswald Buddenhagen static unsigned emu1010_idx(struct snd_emu10k1 *emu)
583511cbe8fSOswald Buddenhagen {
5846f3609f8SOswald Buddenhagen 	return emu->card_capabilities->emu_model - 1;
585511cbe8fSOswald Buddenhagen }
586511cbe8fSOswald Buddenhagen 
587511cbe8fSOswald Buddenhagen static void snd_emu1010_output_source_apply(struct snd_emu10k1 *emu,
588511cbe8fSOswald Buddenhagen 					    int channel, int src)
589511cbe8fSOswald Buddenhagen {
590511cbe8fSOswald Buddenhagen 	const struct snd_emu1010_routing_info *emu_ri =
591511cbe8fSOswald Buddenhagen 		&emu1010_routing_info[emu1010_idx(emu)];
592511cbe8fSOswald Buddenhagen 
593511cbe8fSOswald Buddenhagen 	snd_emu1010_fpga_link_dst_src_write(emu,
594511cbe8fSOswald Buddenhagen 		emu_ri->out_regs[channel], emu_ri->src_regs[src]);
595511cbe8fSOswald Buddenhagen }
596511cbe8fSOswald Buddenhagen 
597511cbe8fSOswald Buddenhagen static void snd_emu1010_input_source_apply(struct snd_emu10k1 *emu,
598511cbe8fSOswald Buddenhagen 					   int channel, int src)
599511cbe8fSOswald Buddenhagen {
600511cbe8fSOswald Buddenhagen 	const struct snd_emu1010_routing_info *emu_ri =
601511cbe8fSOswald Buddenhagen 		&emu1010_routing_info[emu1010_idx(emu)];
602511cbe8fSOswald Buddenhagen 
603511cbe8fSOswald Buddenhagen 	snd_emu1010_fpga_link_dst_src_write(emu,
604511cbe8fSOswald Buddenhagen 		emu_ri->in_regs[channel], emu_ri->src_regs[src]);
605511cbe8fSOswald Buddenhagen }
606511cbe8fSOswald Buddenhagen 
6071fc710f0SOswald Buddenhagen static void snd_emu1010_apply_sources(struct snd_emu10k1 *emu)
6081fc710f0SOswald Buddenhagen {
6091fc710f0SOswald Buddenhagen 	const struct snd_emu1010_routing_info *emu_ri =
6101fc710f0SOswald Buddenhagen 		&emu1010_routing_info[emu1010_idx(emu)];
6111fc710f0SOswald Buddenhagen 
6121fc710f0SOswald Buddenhagen 	for (unsigned i = 0; i < emu_ri->n_outs; i++)
6131fc710f0SOswald Buddenhagen 		snd_emu1010_output_source_apply(
6141fc710f0SOswald Buddenhagen 			emu, i, emu->emu1010.output_source[i]);
6151fc710f0SOswald Buddenhagen 	for (unsigned i = 0; i < emu_ri->n_ins; i++)
6161fc710f0SOswald Buddenhagen 		snd_emu1010_input_source_apply(
6171fc710f0SOswald Buddenhagen 			emu, i, emu->emu1010.input_source[i]);
6181fc710f0SOswald Buddenhagen }
6191fc710f0SOswald Buddenhagen 
6201fc710f0SOswald Buddenhagen static u8 emu1010_map_source(const struct snd_emu1010_routing_info *emu_ri,
6211fc710f0SOswald Buddenhagen 			     unsigned val)
6221fc710f0SOswald Buddenhagen {
6231fc710f0SOswald Buddenhagen 	for (unsigned i = 0; i < emu_ri->n_srcs; i++)
6241fc710f0SOswald Buddenhagen 		if (val == emu_ri->src_regs[i])
6251fc710f0SOswald Buddenhagen 			return i;
6261fc710f0SOswald Buddenhagen 	return 0;
6271fc710f0SOswald Buddenhagen }
6281fc710f0SOswald Buddenhagen 
6291c02e366SCtirad Fertr static int snd_emu1010_input_output_source_info(struct snd_kcontrol *kcontrol,
6301c02e366SCtirad Fertr 						struct snd_ctl_elem_info *uinfo)
6319f4bd5ddSJames Courtier-Dutton {
6321c02e366SCtirad Fertr 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
633511cbe8fSOswald Buddenhagen 	const struct snd_emu1010_routing_info *emu_ri =
634511cbe8fSOswald Buddenhagen 		&emu1010_routing_info[emu1010_idx(emu)];
6351c02e366SCtirad Fertr 
636511cbe8fSOswald Buddenhagen 	return snd_ctl_enum_info(uinfo, 1, emu_ri->n_srcs, emu_ri->src_texts);
6379f4bd5ddSJames Courtier-Dutton }
6389f4bd5ddSJames Courtier-Dutton 
6399f4bd5ddSJames Courtier-Dutton static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol,
6409f4bd5ddSJames Courtier-Dutton                                  struct snd_ctl_elem_value *ucontrol)
6419f4bd5ddSJames Courtier-Dutton {
6429f4bd5ddSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
643511cbe8fSOswald Buddenhagen 	const struct snd_emu1010_routing_info *emu_ri =
644511cbe8fSOswald Buddenhagen 		&emu1010_routing_info[emu1010_idx(emu)];
645511cbe8fSOswald Buddenhagen 	unsigned channel = kcontrol->private_value;
6469f4bd5ddSJames Courtier-Dutton 
647511cbe8fSOswald Buddenhagen 	if (channel >= emu_ri->n_outs)
64874415a36SJames Courtier-Dutton 		return -EINVAL;
6499f4bd5ddSJames Courtier-Dutton 	ucontrol->value.enumerated.item[0] = emu->emu1010.output_source[channel];
6509f4bd5ddSJames Courtier-Dutton 	return 0;
6519f4bd5ddSJames Courtier-Dutton }
6529f4bd5ddSJames Courtier-Dutton 
6539f4bd5ddSJames Courtier-Dutton static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol,
6549f4bd5ddSJames Courtier-Dutton                                  struct snd_ctl_elem_value *ucontrol)
6559f4bd5ddSJames Courtier-Dutton {
6569f4bd5ddSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
657511cbe8fSOswald Buddenhagen 	const struct snd_emu1010_routing_info *emu_ri =
658511cbe8fSOswald Buddenhagen 		&emu1010_routing_info[emu1010_idx(emu)];
659511cbe8fSOswald Buddenhagen 	unsigned val = ucontrol->value.enumerated.item[0];
660511cbe8fSOswald Buddenhagen 	unsigned channel = kcontrol->private_value;
661511cbe8fSOswald Buddenhagen 	int change;
6629f4bd5ddSJames Courtier-Dutton 
663511cbe8fSOswald Buddenhagen 	if (val >= emu_ri->n_srcs)
664aa299d01STakashi Iwai 		return -EINVAL;
665511cbe8fSOswald Buddenhagen 	if (channel >= emu_ri->n_outs)
66674415a36SJames Courtier-Dutton 		return -EINVAL;
667511cbe8fSOswald Buddenhagen 	change = (emu->emu1010.output_source[channel] != val);
668511cbe8fSOswald Buddenhagen 	if (change) {
669aa299d01STakashi Iwai 		emu->emu1010.output_source[channel] = val;
670511cbe8fSOswald Buddenhagen 		snd_emu1010_output_source_apply(emu, channel, val);
671511cbe8fSOswald Buddenhagen 	}
672511cbe8fSOswald Buddenhagen 	return change;
6739f4bd5ddSJames Courtier-Dutton }
6749f4bd5ddSJames Courtier-Dutton 
675536438f1SOswald Buddenhagen static const struct snd_kcontrol_new emu1010_output_source_ctl = {
676536438f1SOswald Buddenhagen 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
677536438f1SOswald Buddenhagen 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
678536438f1SOswald Buddenhagen 	.info = snd_emu1010_input_output_source_info,
679536438f1SOswald Buddenhagen 	.get = snd_emu1010_output_source_get,
680536438f1SOswald Buddenhagen 	.put = snd_emu1010_output_source_put
681536438f1SOswald Buddenhagen };
682536438f1SOswald Buddenhagen 
6839f4bd5ddSJames Courtier-Dutton static int snd_emu1010_input_source_get(struct snd_kcontrol *kcontrol,
6849f4bd5ddSJames Courtier-Dutton                                  struct snd_ctl_elem_value *ucontrol)
6859f4bd5ddSJames Courtier-Dutton {
6869f4bd5ddSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
687511cbe8fSOswald Buddenhagen 	const struct snd_emu1010_routing_info *emu_ri =
688511cbe8fSOswald Buddenhagen 		&emu1010_routing_info[emu1010_idx(emu)];
689511cbe8fSOswald Buddenhagen 	unsigned channel = kcontrol->private_value;
6909f4bd5ddSJames Courtier-Dutton 
691511cbe8fSOswald Buddenhagen 	if (channel >= emu_ri->n_ins)
69274415a36SJames Courtier-Dutton 		return -EINVAL;
6939f4bd5ddSJames Courtier-Dutton 	ucontrol->value.enumerated.item[0] = emu->emu1010.input_source[channel];
6949f4bd5ddSJames Courtier-Dutton 	return 0;
6959f4bd5ddSJames Courtier-Dutton }
6969f4bd5ddSJames Courtier-Dutton 
6979f4bd5ddSJames Courtier-Dutton static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol,
6989f4bd5ddSJames Courtier-Dutton                                  struct snd_ctl_elem_value *ucontrol)
6999f4bd5ddSJames Courtier-Dutton {
7009f4bd5ddSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
701511cbe8fSOswald Buddenhagen 	const struct snd_emu1010_routing_info *emu_ri =
702511cbe8fSOswald Buddenhagen 		&emu1010_routing_info[emu1010_idx(emu)];
703511cbe8fSOswald Buddenhagen 	unsigned val = ucontrol->value.enumerated.item[0];
704511cbe8fSOswald Buddenhagen 	unsigned channel = kcontrol->private_value;
705511cbe8fSOswald Buddenhagen 	int change;
7069f4bd5ddSJames Courtier-Dutton 
707511cbe8fSOswald Buddenhagen 	if (val >= emu_ri->n_srcs)
708aa299d01STakashi Iwai 		return -EINVAL;
709511cbe8fSOswald Buddenhagen 	if (channel >= emu_ri->n_ins)
71074415a36SJames Courtier-Dutton 		return -EINVAL;
711511cbe8fSOswald Buddenhagen 	change = (emu->emu1010.input_source[channel] != val);
712511cbe8fSOswald Buddenhagen 	if (change) {
713aa299d01STakashi Iwai 		emu->emu1010.input_source[channel] = val;
714511cbe8fSOswald Buddenhagen 		snd_emu1010_input_source_apply(emu, channel, val);
715511cbe8fSOswald Buddenhagen 	}
716511cbe8fSOswald Buddenhagen 	return change;
7179f4bd5ddSJames Courtier-Dutton }
7189f4bd5ddSJames Courtier-Dutton 
719536438f1SOswald Buddenhagen static const struct snd_kcontrol_new emu1010_input_source_ctl = {
720536438f1SOswald Buddenhagen 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
721536438f1SOswald Buddenhagen 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
722536438f1SOswald Buddenhagen 	.info = snd_emu1010_input_output_source_info,
723536438f1SOswald Buddenhagen 	.get = snd_emu1010_input_source_get,
724536438f1SOswald Buddenhagen 	.put = snd_emu1010_input_source_put
7259f4bd5ddSJames Courtier-Dutton };
7269f4bd5ddSJames Courtier-Dutton 
72797f1582eSOswald Buddenhagen static int add_emu1010_source_mixers(struct snd_emu10k1 *emu)
72897f1582eSOswald Buddenhagen {
72997f1582eSOswald Buddenhagen 	const struct snd_emu1010_routing_info *emu_ri =
73097f1582eSOswald Buddenhagen 		&emu1010_routing_info[emu1010_idx(emu)];
73197f1582eSOswald Buddenhagen 	int err;
73297f1582eSOswald Buddenhagen 
73397f1582eSOswald Buddenhagen 	err = add_ctls(emu, &emu1010_output_source_ctl,
73497f1582eSOswald Buddenhagen 		       emu_ri->out_texts, emu_ri->n_outs);
73597f1582eSOswald Buddenhagen 	if (err < 0)
73697f1582eSOswald Buddenhagen 		return err;
73797f1582eSOswald Buddenhagen 	err = add_ctls(emu, &emu1010_input_source_ctl,
73897f1582eSOswald Buddenhagen 		       emu1010_input_texts, emu_ri->n_ins);
73997f1582eSOswald Buddenhagen 	return err;
74097f1582eSOswald Buddenhagen }
74197f1582eSOswald Buddenhagen 
7421c02e366SCtirad Fertr 
743536438f1SOswald Buddenhagen static const char * const snd_emu1010_adc_pads[] = {
744f69d705dSOswald Buddenhagen 	"ADC1 14dB PAD 0202 Capture Switch",
745536438f1SOswald Buddenhagen 	"ADC1 14dB PAD Audio Dock Capture Switch",
746536438f1SOswald Buddenhagen 	"ADC2 14dB PAD Audio Dock Capture Switch",
747536438f1SOswald Buddenhagen 	"ADC3 14dB PAD Audio Dock Capture Switch",
7481c02e366SCtirad Fertr };
7491c02e366SCtirad Fertr 
750536438f1SOswald Buddenhagen static const unsigned short snd_emu1010_adc_pad_regs[] = {
751f69d705dSOswald Buddenhagen 	EMU_HANA_0202_ADC_PAD1,
752536438f1SOswald Buddenhagen 	EMU_HANA_DOCK_ADC_PAD1,
753536438f1SOswald Buddenhagen 	EMU_HANA_DOCK_ADC_PAD2,
754536438f1SOswald Buddenhagen 	EMU_HANA_DOCK_ADC_PAD3,
7559148cc50SJames Courtier-Dutton };
7569148cc50SJames Courtier-Dutton 
757a5ce8890STakashi Iwai #define snd_emu1010_adc_pads_info	snd_ctl_boolean_mono_info
7589148cc50SJames Courtier-Dutton 
7599148cc50SJames Courtier-Dutton static int snd_emu1010_adc_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
7609148cc50SJames Courtier-Dutton {
7619148cc50SJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
762536438f1SOswald Buddenhagen 	unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value];
763536438f1SOswald Buddenhagen 
7649148cc50SJames Courtier-Dutton 	ucontrol->value.integer.value[0] = (emu->emu1010.adc_pads & mask) ? 1 : 0;
7659148cc50SJames Courtier-Dutton 	return 0;
7669148cc50SJames Courtier-Dutton }
7679148cc50SJames Courtier-Dutton 
7689148cc50SJames Courtier-Dutton static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
7699148cc50SJames Courtier-Dutton {
7709148cc50SJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
771536438f1SOswald Buddenhagen 	unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value];
7729148cc50SJames Courtier-Dutton 	unsigned int val, cache;
7739148cc50SJames Courtier-Dutton 	val = ucontrol->value.integer.value[0];
7749148cc50SJames Courtier-Dutton 	cache = emu->emu1010.adc_pads;
7759148cc50SJames Courtier-Dutton 	if (val == 1)
7769148cc50SJames Courtier-Dutton 		cache = cache | mask;
7779148cc50SJames Courtier-Dutton 	else
7789148cc50SJames Courtier-Dutton 		cache = cache & ~mask;
7799148cc50SJames Courtier-Dutton 	if (cache != emu->emu1010.adc_pads) {
7809148cc50SJames Courtier-Dutton 		snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, cache );
7819148cc50SJames Courtier-Dutton 	        emu->emu1010.adc_pads = cache;
7829148cc50SJames Courtier-Dutton 	}
7839148cc50SJames Courtier-Dutton 
7849148cc50SJames Courtier-Dutton 	return 0;
7859148cc50SJames Courtier-Dutton }
7869148cc50SJames Courtier-Dutton 
787536438f1SOswald Buddenhagen static const struct snd_kcontrol_new emu1010_adc_pads_ctl = {
788536438f1SOswald Buddenhagen 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
789536438f1SOswald Buddenhagen 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
790536438f1SOswald Buddenhagen 	.info = snd_emu1010_adc_pads_info,
791536438f1SOswald Buddenhagen 	.get = snd_emu1010_adc_pads_get,
792536438f1SOswald Buddenhagen 	.put = snd_emu1010_adc_pads_put
793536438f1SOswald Buddenhagen };
7949148cc50SJames Courtier-Dutton 
7959148cc50SJames Courtier-Dutton 
796536438f1SOswald Buddenhagen static const char * const snd_emu1010_dac_pads[] = {
797f69d705dSOswald Buddenhagen 	"DAC1 0202 14dB PAD Playback Switch",
798536438f1SOswald Buddenhagen 	"DAC1 Audio Dock 14dB PAD Playback Switch",
799536438f1SOswald Buddenhagen 	"DAC2 Audio Dock 14dB PAD Playback Switch",
800536438f1SOswald Buddenhagen 	"DAC3 Audio Dock 14dB PAD Playback Switch",
801536438f1SOswald Buddenhagen 	"DAC4 Audio Dock 14dB PAD Playback Switch",
802536438f1SOswald Buddenhagen };
8039148cc50SJames Courtier-Dutton 
804536438f1SOswald Buddenhagen static const unsigned short snd_emu1010_dac_regs[] = {
805f69d705dSOswald Buddenhagen 	EMU_HANA_0202_DAC_PAD1,
806536438f1SOswald Buddenhagen 	EMU_HANA_DOCK_DAC_PAD1,
807536438f1SOswald Buddenhagen 	EMU_HANA_DOCK_DAC_PAD2,
808536438f1SOswald Buddenhagen 	EMU_HANA_DOCK_DAC_PAD3,
809536438f1SOswald Buddenhagen 	EMU_HANA_DOCK_DAC_PAD4,
8109148cc50SJames Courtier-Dutton };
8119148cc50SJames Courtier-Dutton 
812a5ce8890STakashi Iwai #define snd_emu1010_dac_pads_info	snd_ctl_boolean_mono_info
8139148cc50SJames Courtier-Dutton 
8149148cc50SJames Courtier-Dutton static int snd_emu1010_dac_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
8159148cc50SJames Courtier-Dutton {
8169148cc50SJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
817536438f1SOswald Buddenhagen 	unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value];
818536438f1SOswald Buddenhagen 
8199148cc50SJames Courtier-Dutton 	ucontrol->value.integer.value[0] = (emu->emu1010.dac_pads & mask) ? 1 : 0;
8209148cc50SJames Courtier-Dutton 	return 0;
8219148cc50SJames Courtier-Dutton }
8229148cc50SJames Courtier-Dutton 
8239148cc50SJames Courtier-Dutton static int snd_emu1010_dac_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
8249148cc50SJames Courtier-Dutton {
8259148cc50SJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
826536438f1SOswald Buddenhagen 	unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value];
8279148cc50SJames Courtier-Dutton 	unsigned int val, cache;
828cc766807SOswald Buddenhagen 	int change;
829cc766807SOswald Buddenhagen 
8309148cc50SJames Courtier-Dutton 	val = ucontrol->value.integer.value[0];
8319148cc50SJames Courtier-Dutton 	cache = emu->emu1010.dac_pads;
8329148cc50SJames Courtier-Dutton 	if (val == 1)
8339148cc50SJames Courtier-Dutton 		cache = cache | mask;
8349148cc50SJames Courtier-Dutton 	else
8359148cc50SJames Courtier-Dutton 		cache = cache & ~mask;
836cc766807SOswald Buddenhagen 	change = (cache != emu->emu1010.dac_pads);
837cc766807SOswald Buddenhagen 	if (change) {
8389148cc50SJames Courtier-Dutton 		snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, cache );
8399148cc50SJames Courtier-Dutton 	        emu->emu1010.dac_pads = cache;
8409148cc50SJames Courtier-Dutton 	}
8419148cc50SJames Courtier-Dutton 
842cc766807SOswald Buddenhagen 	return change;
8439148cc50SJames Courtier-Dutton }
8449148cc50SJames Courtier-Dutton 
845536438f1SOswald Buddenhagen static const struct snd_kcontrol_new emu1010_dac_pads_ctl = {
846536438f1SOswald Buddenhagen 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
847536438f1SOswald Buddenhagen 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
848536438f1SOswald Buddenhagen 	.info = snd_emu1010_dac_pads_info,
849536438f1SOswald Buddenhagen 	.get = snd_emu1010_dac_pads_get,
850536438f1SOswald Buddenhagen 	.put = snd_emu1010_dac_pads_put
8519f4bd5ddSJames Courtier-Dutton };
8529f4bd5ddSJames Courtier-Dutton 
853b0dbdaeaSJames Courtier-Dutton 
85497f1582eSOswald Buddenhagen struct snd_emu1010_pads_info {
85597f1582eSOswald Buddenhagen 	const char * const *adc_ctls, * const *dac_ctls;
85697f1582eSOswald Buddenhagen 	unsigned n_adc_ctls, n_dac_ctls;
85797f1582eSOswald Buddenhagen };
85897f1582eSOswald Buddenhagen 
85997f1582eSOswald Buddenhagen const struct snd_emu1010_pads_info emu1010_pads_info[] = {
86097f1582eSOswald Buddenhagen 	{
8616f3609f8SOswald Buddenhagen 		/* rev1 1010 */
86297f1582eSOswald Buddenhagen 		.adc_ctls = snd_emu1010_adc_pads,
86397f1582eSOswald Buddenhagen 		.n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads),
86497f1582eSOswald Buddenhagen 		.dac_ctls = snd_emu1010_dac_pads,
86597f1582eSOswald Buddenhagen 		.n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads),
86697f1582eSOswald Buddenhagen 	},
86797f1582eSOswald Buddenhagen 	{
868f69d705dSOswald Buddenhagen 		/* rev2 1010 */
86997f1582eSOswald Buddenhagen 		.adc_ctls = snd_emu1010_adc_pads,
870f69d705dSOswald Buddenhagen 		.n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads) - 1,
87197f1582eSOswald Buddenhagen 		.dac_ctls = snd_emu1010_dac_pads,
872f69d705dSOswald Buddenhagen 		.n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads) - 1,
873f69d705dSOswald Buddenhagen 	},
874f69d705dSOswald Buddenhagen 	{
875f69d705dSOswald Buddenhagen 		/* 1616(m) cardbus */
876f69d705dSOswald Buddenhagen 		.adc_ctls = snd_emu1010_adc_pads + 1,
877f69d705dSOswald Buddenhagen 		.n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads) - 2,
878f69d705dSOswald Buddenhagen 		.dac_ctls = snd_emu1010_dac_pads + 1,
87997f1582eSOswald Buddenhagen 		.n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads) - 2,
88097f1582eSOswald Buddenhagen 	},
8816f3609f8SOswald Buddenhagen 	{
8826f3609f8SOswald Buddenhagen 		/* 0404 */
8836f3609f8SOswald Buddenhagen 		.adc_ctls = NULL,
8846f3609f8SOswald Buddenhagen 		.n_adc_ctls = 0,
8856f3609f8SOswald Buddenhagen 		.dac_ctls = NULL,
8866f3609f8SOswald Buddenhagen 		.n_dac_ctls = 0,
8876f3609f8SOswald Buddenhagen 	},
88897f1582eSOswald Buddenhagen };
88997f1582eSOswald Buddenhagen 
89097f1582eSOswald Buddenhagen 
891b0dbdaeaSJames Courtier-Dutton static int snd_emu1010_internal_clock_info(struct snd_kcontrol *kcontrol,
892b0dbdaeaSJames Courtier-Dutton 					  struct snd_ctl_elem_info *uinfo)
893b0dbdaeaSJames Courtier-Dutton {
8941541c66dSTakashi Iwai 	static const char * const texts[4] = {
895edec7bbbSJames Courtier-Dutton 		"44100", "48000", "SPDIF", "ADAT"
896b0dbdaeaSJames Courtier-Dutton 	};
897b0dbdaeaSJames Courtier-Dutton 
8981541c66dSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 4, texts);
899b0dbdaeaSJames Courtier-Dutton }
900b0dbdaeaSJames Courtier-Dutton 
901b0dbdaeaSJames Courtier-Dutton static int snd_emu1010_internal_clock_get(struct snd_kcontrol *kcontrol,
902b0dbdaeaSJames Courtier-Dutton 					struct snd_ctl_elem_value *ucontrol)
903b0dbdaeaSJames Courtier-Dutton {
904b0dbdaeaSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
905b0dbdaeaSJames Courtier-Dutton 
906b0dbdaeaSJames Courtier-Dutton 	ucontrol->value.enumerated.item[0] = emu->emu1010.internal_clock;
907b0dbdaeaSJames Courtier-Dutton 	return 0;
908b0dbdaeaSJames Courtier-Dutton }
909b0dbdaeaSJames Courtier-Dutton 
910b0dbdaeaSJames Courtier-Dutton static int snd_emu1010_internal_clock_put(struct snd_kcontrol *kcontrol,
911b0dbdaeaSJames Courtier-Dutton 					struct snd_ctl_elem_value *ucontrol)
912b0dbdaeaSJames Courtier-Dutton {
913b0dbdaeaSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
914b0dbdaeaSJames Courtier-Dutton 	unsigned int val;
915b0dbdaeaSJames Courtier-Dutton 	int change = 0;
916b0dbdaeaSJames Courtier-Dutton 
917b0dbdaeaSJames Courtier-Dutton 	val = ucontrol->value.enumerated.item[0] ;
91874415a36SJames Courtier-Dutton 	/* Limit: uinfo->value.enumerated.items = 4; */
91974415a36SJames Courtier-Dutton 	if (val >= 4)
92074415a36SJames Courtier-Dutton 		return -EINVAL;
921b0dbdaeaSJames Courtier-Dutton 	change = (emu->emu1010.internal_clock != val);
922b0dbdaeaSJames Courtier-Dutton 	if (change) {
923b0dbdaeaSJames Courtier-Dutton 		emu->emu1010.internal_clock = val;
924b0dbdaeaSJames Courtier-Dutton 		switch (val) {
925b0dbdaeaSJames Courtier-Dutton 		case 0:
926b0dbdaeaSJames Courtier-Dutton 			/* 44100 */
927b0dbdaeaSJames Courtier-Dutton 			/* Mute all */
928b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE );
929a869057cSOswald Buddenhagen 			/* Default fallback clock 44.1kHz */
930b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_44_1K );
931b0dbdaeaSJames Courtier-Dutton 			/* Word Clock source, Internal 44.1kHz x1 */
932b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK,
933b0dbdaeaSJames Courtier-Dutton 			EMU_HANA_WCLOCK_INT_44_1K | EMU_HANA_WCLOCK_1X );
934b0dbdaeaSJames Courtier-Dutton 			/* Set LEDs on Audio Dock */
935b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2,
936b0dbdaeaSJames Courtier-Dutton 				EMU_HANA_DOCK_LEDS_2_44K | EMU_HANA_DOCK_LEDS_2_LOCK );
937b0dbdaeaSJames Courtier-Dutton 			/* Allow DLL to settle */
938e40a0b2eSJames Courtier-Dutton 			msleep(10);
939b0dbdaeaSJames Courtier-Dutton 			/* Unmute all */
940b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE );
941b0dbdaeaSJames Courtier-Dutton 			break;
942b0dbdaeaSJames Courtier-Dutton 		case 1:
943b0dbdaeaSJames Courtier-Dutton 			/* 48000 */
944b0dbdaeaSJames Courtier-Dutton 			/* Mute all */
945b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE );
946b0dbdaeaSJames Courtier-Dutton 			/* Default fallback clock 48kHz */
947b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K );
948b0dbdaeaSJames Courtier-Dutton 			/* Word Clock source, Internal 48kHz x1 */
949b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK,
950b0dbdaeaSJames Courtier-Dutton 				EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_1X );
951b0dbdaeaSJames Courtier-Dutton 			/* Set LEDs on Audio Dock */
952b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2,
953b0dbdaeaSJames Courtier-Dutton 				EMU_HANA_DOCK_LEDS_2_48K | EMU_HANA_DOCK_LEDS_2_LOCK );
954b0dbdaeaSJames Courtier-Dutton 			/* Allow DLL to settle */
955e40a0b2eSJames Courtier-Dutton 			msleep(10);
956b0dbdaeaSJames Courtier-Dutton 			/* Unmute all */
957b0dbdaeaSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE );
958b0dbdaeaSJames Courtier-Dutton 			break;
959edec7bbbSJames Courtier-Dutton 
960edec7bbbSJames Courtier-Dutton 		case 2: /* Take clock from S/PDIF IN */
961edec7bbbSJames Courtier-Dutton 			/* Mute all */
962edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE );
963edec7bbbSJames Courtier-Dutton 			/* Default fallback clock 48kHz */
964edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K );
965edec7bbbSJames Courtier-Dutton 			/* Word Clock source, sync to S/PDIF input */
966edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK,
967edec7bbbSJames Courtier-Dutton 				EMU_HANA_WCLOCK_HANA_SPDIF_IN | EMU_HANA_WCLOCK_1X );
968edec7bbbSJames Courtier-Dutton 			/* Set LEDs on Audio Dock */
969edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2,
970edec7bbbSJames Courtier-Dutton 				EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_LOCK );
971edec7bbbSJames Courtier-Dutton 			/* FIXME: We should set EMU_HANA_DOCK_LEDS_2_LOCK only when clock signal is present and valid */
972edec7bbbSJames Courtier-Dutton 			/* Allow DLL to settle */
973edec7bbbSJames Courtier-Dutton 			msleep(10);
974edec7bbbSJames Courtier-Dutton 			/* Unmute all */
975edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE );
976edec7bbbSJames Courtier-Dutton 			break;
977edec7bbbSJames Courtier-Dutton 
978edec7bbbSJames Courtier-Dutton 		case 3:
979edec7bbbSJames Courtier-Dutton 			/* Take clock from ADAT IN */
980edec7bbbSJames Courtier-Dutton 			/* Mute all */
981edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE );
982edec7bbbSJames Courtier-Dutton 			/* Default fallback clock 48kHz */
983edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K );
984edec7bbbSJames Courtier-Dutton 			/* Word Clock source, sync to ADAT input */
985edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK,
986edec7bbbSJames Courtier-Dutton 				EMU_HANA_WCLOCK_HANA_ADAT_IN | EMU_HANA_WCLOCK_1X );
987edec7bbbSJames Courtier-Dutton 			/* Set LEDs on Audio Dock */
988edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, EMU_HANA_DOCK_LEDS_2_EXT | EMU_HANA_DOCK_LEDS_2_LOCK );
989edec7bbbSJames Courtier-Dutton 			/* FIXME: We should set EMU_HANA_DOCK_LEDS_2_LOCK only when clock signal is present and valid */
990edec7bbbSJames Courtier-Dutton 			/* Allow DLL to settle */
991edec7bbbSJames Courtier-Dutton 			msleep(10);
992edec7bbbSJames Courtier-Dutton 			/*   Unmute all */
993edec7bbbSJames Courtier-Dutton 			snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE );
994edec7bbbSJames Courtier-Dutton 
995edec7bbbSJames Courtier-Dutton 
996edec7bbbSJames Courtier-Dutton 			break;
997b0dbdaeaSJames Courtier-Dutton 		}
998b0dbdaeaSJames Courtier-Dutton 	}
999b0dbdaeaSJames Courtier-Dutton         return change;
1000b0dbdaeaSJames Courtier-Dutton }
1001b0dbdaeaSJames Courtier-Dutton 
1002f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu1010_internal_clock =
1003b0dbdaeaSJames Courtier-Dutton {
1004b0dbdaeaSJames Courtier-Dutton 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE,
1005b0dbdaeaSJames Courtier-Dutton 	.iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
1006b0dbdaeaSJames Courtier-Dutton 	.name =         "Clock Internal Rate",
1007b0dbdaeaSJames Courtier-Dutton 	.count =	1,
1008b0dbdaeaSJames Courtier-Dutton 	.info =         snd_emu1010_internal_clock_info,
1009b0dbdaeaSJames Courtier-Dutton 	.get =          snd_emu1010_internal_clock_get,
1010b0dbdaeaSJames Courtier-Dutton 	.put =          snd_emu1010_internal_clock_put
1011b0dbdaeaSJames Courtier-Dutton };
1012b0dbdaeaSJames Courtier-Dutton 
101399dcab46SMichael Gernoth static int snd_emu1010_optical_out_info(struct snd_kcontrol *kcontrol,
101499dcab46SMichael Gernoth 					  struct snd_ctl_elem_info *uinfo)
101599dcab46SMichael Gernoth {
101699dcab46SMichael Gernoth 	static const char * const texts[2] = {
101799dcab46SMichael Gernoth 		"SPDIF", "ADAT"
101899dcab46SMichael Gernoth 	};
101999dcab46SMichael Gernoth 
102099dcab46SMichael Gernoth 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
102199dcab46SMichael Gernoth }
102299dcab46SMichael Gernoth 
102399dcab46SMichael Gernoth static int snd_emu1010_optical_out_get(struct snd_kcontrol *kcontrol,
102499dcab46SMichael Gernoth 					struct snd_ctl_elem_value *ucontrol)
102599dcab46SMichael Gernoth {
102699dcab46SMichael Gernoth 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
102799dcab46SMichael Gernoth 
102899dcab46SMichael Gernoth 	ucontrol->value.enumerated.item[0] = emu->emu1010.optical_out;
102999dcab46SMichael Gernoth 	return 0;
103099dcab46SMichael Gernoth }
103199dcab46SMichael Gernoth 
103299dcab46SMichael Gernoth static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol,
103399dcab46SMichael Gernoth 					struct snd_ctl_elem_value *ucontrol)
103499dcab46SMichael Gernoth {
103599dcab46SMichael Gernoth 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
103699dcab46SMichael Gernoth 	unsigned int val;
103799dcab46SMichael Gernoth 	u32 tmp;
103899dcab46SMichael Gernoth 	int change = 0;
103999dcab46SMichael Gernoth 
104099dcab46SMichael Gernoth 	val = ucontrol->value.enumerated.item[0];
104199dcab46SMichael Gernoth 	/* Limit: uinfo->value.enumerated.items = 2; */
104299dcab46SMichael Gernoth 	if (val >= 2)
104399dcab46SMichael Gernoth 		return -EINVAL;
104499dcab46SMichael Gernoth 	change = (emu->emu1010.optical_out != val);
104599dcab46SMichael Gernoth 	if (change) {
104699dcab46SMichael Gernoth 		emu->emu1010.optical_out = val;
10479d2f3863SOswald Buddenhagen 		tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) |
10489d2f3863SOswald Buddenhagen 			(emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF);
104999dcab46SMichael Gernoth 		snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
105099dcab46SMichael Gernoth 	}
105199dcab46SMichael Gernoth 	return change;
105299dcab46SMichael Gernoth }
105399dcab46SMichael Gernoth 
1054f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu1010_optical_out = {
105599dcab46SMichael Gernoth 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE,
105699dcab46SMichael Gernoth 	.iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
105799dcab46SMichael Gernoth 	.name =         "Optical Output Mode",
105899dcab46SMichael Gernoth 	.count =	1,
105999dcab46SMichael Gernoth 	.info =         snd_emu1010_optical_out_info,
106099dcab46SMichael Gernoth 	.get =          snd_emu1010_optical_out_get,
106199dcab46SMichael Gernoth 	.put =          snd_emu1010_optical_out_put
106299dcab46SMichael Gernoth };
106399dcab46SMichael Gernoth 
106499dcab46SMichael Gernoth static int snd_emu1010_optical_in_info(struct snd_kcontrol *kcontrol,
106599dcab46SMichael Gernoth 					  struct snd_ctl_elem_info *uinfo)
106699dcab46SMichael Gernoth {
106799dcab46SMichael Gernoth 	static const char * const texts[2] = {
106899dcab46SMichael Gernoth 		"SPDIF", "ADAT"
106999dcab46SMichael Gernoth 	};
107099dcab46SMichael Gernoth 
107199dcab46SMichael Gernoth 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
107299dcab46SMichael Gernoth }
107399dcab46SMichael Gernoth 
107499dcab46SMichael Gernoth static int snd_emu1010_optical_in_get(struct snd_kcontrol *kcontrol,
107599dcab46SMichael Gernoth 					struct snd_ctl_elem_value *ucontrol)
107699dcab46SMichael Gernoth {
107799dcab46SMichael Gernoth 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
107899dcab46SMichael Gernoth 
107999dcab46SMichael Gernoth 	ucontrol->value.enumerated.item[0] = emu->emu1010.optical_in;
108099dcab46SMichael Gernoth 	return 0;
108199dcab46SMichael Gernoth }
108299dcab46SMichael Gernoth 
108399dcab46SMichael Gernoth static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol,
108499dcab46SMichael Gernoth 					struct snd_ctl_elem_value *ucontrol)
108599dcab46SMichael Gernoth {
108699dcab46SMichael Gernoth 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
108799dcab46SMichael Gernoth 	unsigned int val;
108899dcab46SMichael Gernoth 	u32 tmp;
108999dcab46SMichael Gernoth 	int change = 0;
109099dcab46SMichael Gernoth 
109199dcab46SMichael Gernoth 	val = ucontrol->value.enumerated.item[0];
109299dcab46SMichael Gernoth 	/* Limit: uinfo->value.enumerated.items = 2; */
109399dcab46SMichael Gernoth 	if (val >= 2)
109499dcab46SMichael Gernoth 		return -EINVAL;
109599dcab46SMichael Gernoth 	change = (emu->emu1010.optical_in != val);
109699dcab46SMichael Gernoth 	if (change) {
109799dcab46SMichael Gernoth 		emu->emu1010.optical_in = val;
10989d2f3863SOswald Buddenhagen 		tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) |
10999d2f3863SOswald Buddenhagen 			(emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF);
110099dcab46SMichael Gernoth 		snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
110199dcab46SMichael Gernoth 	}
110299dcab46SMichael Gernoth 	return change;
110399dcab46SMichael Gernoth }
110499dcab46SMichael Gernoth 
1105f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu1010_optical_in = {
110699dcab46SMichael Gernoth 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE,
110799dcab46SMichael Gernoth 	.iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
110899dcab46SMichael Gernoth 	.name =         "Optical Input Mode",
110999dcab46SMichael Gernoth 	.count =	1,
111099dcab46SMichael Gernoth 	.info =         snd_emu1010_optical_in_info,
111199dcab46SMichael Gernoth 	.get =          snd_emu1010_optical_in_get,
111299dcab46SMichael Gernoth 	.put =          snd_emu1010_optical_in_put
111399dcab46SMichael Gernoth };
111499dcab46SMichael Gernoth 
1115184c1e2cSJames Courtier-Dutton static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
1116184c1e2cSJames Courtier-Dutton 					  struct snd_ctl_elem_info *uinfo)
1117184c1e2cSJames Courtier-Dutton {
1118184c1e2cSJames Courtier-Dutton #if 0
11191541c66dSTakashi Iwai 	static const char * const texts[4] = {
1120184c1e2cSJames Courtier-Dutton 		"Unknown1", "Unknown2", "Mic", "Line"
1121184c1e2cSJames Courtier-Dutton 	};
1122184c1e2cSJames Courtier-Dutton #endif
11231541c66dSTakashi Iwai 	static const char * const texts[2] = {
1124184c1e2cSJames Courtier-Dutton 		"Mic", "Line"
1125184c1e2cSJames Courtier-Dutton 	};
1126184c1e2cSJames Courtier-Dutton 
11271541c66dSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 2, texts);
1128184c1e2cSJames Courtier-Dutton }
1129184c1e2cSJames Courtier-Dutton 
1130184c1e2cSJames Courtier-Dutton static int snd_audigy_i2c_capture_source_get(struct snd_kcontrol *kcontrol,
1131184c1e2cSJames Courtier-Dutton 					struct snd_ctl_elem_value *ucontrol)
1132184c1e2cSJames Courtier-Dutton {
1133184c1e2cSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1134184c1e2cSJames Courtier-Dutton 
1135184c1e2cSJames Courtier-Dutton 	ucontrol->value.enumerated.item[0] = emu->i2c_capture_source;
1136184c1e2cSJames Courtier-Dutton 	return 0;
1137184c1e2cSJames Courtier-Dutton }
1138184c1e2cSJames Courtier-Dutton 
1139184c1e2cSJames Courtier-Dutton static int snd_audigy_i2c_capture_source_put(struct snd_kcontrol *kcontrol,
1140184c1e2cSJames Courtier-Dutton 					struct snd_ctl_elem_value *ucontrol)
1141184c1e2cSJames Courtier-Dutton {
1142184c1e2cSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1143184c1e2cSJames Courtier-Dutton 	unsigned int source_id;
1144184c1e2cSJames Courtier-Dutton 	unsigned int ngain, ogain;
1145a1c87c0bSOswald Buddenhagen 	u16 gpio;
1146184c1e2cSJames Courtier-Dutton 	int change = 0;
1147184c1e2cSJames Courtier-Dutton 	unsigned long flags;
1148184c1e2cSJames Courtier-Dutton 	u32 source;
1149184c1e2cSJames Courtier-Dutton 	/* If the capture source has changed,
1150184c1e2cSJames Courtier-Dutton 	 * update the capture volume from the cached value
1151184c1e2cSJames Courtier-Dutton 	 * for the particular source.
1152184c1e2cSJames Courtier-Dutton 	 */
115374415a36SJames Courtier-Dutton 	source_id = ucontrol->value.enumerated.item[0];
115474415a36SJames Courtier-Dutton 	/* Limit: uinfo->value.enumerated.items = 2; */
115574415a36SJames Courtier-Dutton 	/*        emu->i2c_capture_volume */
115674415a36SJames Courtier-Dutton 	if (source_id >= 2)
115774415a36SJames Courtier-Dutton 		return -EINVAL;
1158184c1e2cSJames Courtier-Dutton 	change = (emu->i2c_capture_source != source_id);
1159184c1e2cSJames Courtier-Dutton 	if (change) {
1160184c1e2cSJames Courtier-Dutton 		snd_emu10k1_i2c_write(emu, ADC_MUX, 0); /* Mute input */
1161184c1e2cSJames Courtier-Dutton 		spin_lock_irqsave(&emu->emu_lock, flags);
1162a1c87c0bSOswald Buddenhagen 		gpio = inw(emu->port + A_IOCFG);
1163184c1e2cSJames Courtier-Dutton 		if (source_id==0)
1164a1c87c0bSOswald Buddenhagen 			outw(gpio | 0x4, emu->port + A_IOCFG);
1165184c1e2cSJames Courtier-Dutton 		else
1166a1c87c0bSOswald Buddenhagen 			outw(gpio & ~0x4, emu->port + A_IOCFG);
1167184c1e2cSJames Courtier-Dutton 		spin_unlock_irqrestore(&emu->emu_lock, flags);
1168184c1e2cSJames Courtier-Dutton 
1169184c1e2cSJames Courtier-Dutton 		ngain = emu->i2c_capture_volume[source_id][0]; /* Left */
1170184c1e2cSJames Courtier-Dutton 		ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */
1171184c1e2cSJames Courtier-Dutton 		if (ngain != ogain)
1172184c1e2cSJames Courtier-Dutton 			snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff));
1173184c1e2cSJames Courtier-Dutton 		ngain = emu->i2c_capture_volume[source_id][1]; /* Right */
1174184c1e2cSJames Courtier-Dutton 		ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */
1175184c1e2cSJames Courtier-Dutton 		if (ngain != ogain)
1176184c1e2cSJames Courtier-Dutton 			snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));
1177184c1e2cSJames Courtier-Dutton 
1178184c1e2cSJames Courtier-Dutton 		source = 1 << (source_id + 2);
1179184c1e2cSJames Courtier-Dutton 		snd_emu10k1_i2c_write(emu, ADC_MUX, source); /* Set source */
1180184c1e2cSJames Courtier-Dutton 		emu->i2c_capture_source = source_id;
1181184c1e2cSJames Courtier-Dutton 	}
1182184c1e2cSJames Courtier-Dutton         return change;
1183184c1e2cSJames Courtier-Dutton }
1184184c1e2cSJames Courtier-Dutton 
1185f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_audigy_i2c_capture_source =
1186184c1e2cSJames Courtier-Dutton {
1187184c1e2cSJames Courtier-Dutton 		.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
1188184c1e2cSJames Courtier-Dutton 		.name =		"Capture Source",
1189184c1e2cSJames Courtier-Dutton 		.info =		snd_audigy_i2c_capture_source_info,
1190184c1e2cSJames Courtier-Dutton 		.get =		snd_audigy_i2c_capture_source_get,
1191184c1e2cSJames Courtier-Dutton 		.put =		snd_audigy_i2c_capture_source_put
1192184c1e2cSJames Courtier-Dutton };
1193184c1e2cSJames Courtier-Dutton 
1194184c1e2cSJames Courtier-Dutton static int snd_audigy_i2c_volume_info(struct snd_kcontrol *kcontrol,
1195184c1e2cSJames Courtier-Dutton 				  struct snd_ctl_elem_info *uinfo)
1196184c1e2cSJames Courtier-Dutton {
1197184c1e2cSJames Courtier-Dutton 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1198184c1e2cSJames Courtier-Dutton 	uinfo->count = 2;
1199184c1e2cSJames Courtier-Dutton 	uinfo->value.integer.min = 0;
1200184c1e2cSJames Courtier-Dutton 	uinfo->value.integer.max = 255;
1201184c1e2cSJames Courtier-Dutton 	return 0;
1202184c1e2cSJames Courtier-Dutton }
1203184c1e2cSJames Courtier-Dutton 
1204184c1e2cSJames Courtier-Dutton static int snd_audigy_i2c_volume_get(struct snd_kcontrol *kcontrol,
1205184c1e2cSJames Courtier-Dutton 				 struct snd_ctl_elem_value *ucontrol)
1206184c1e2cSJames Courtier-Dutton {
1207184c1e2cSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
120874415a36SJames Courtier-Dutton 	unsigned int source_id;
1209184c1e2cSJames Courtier-Dutton 
1210184c1e2cSJames Courtier-Dutton 	source_id = kcontrol->private_value;
121174415a36SJames Courtier-Dutton 	/* Limit: emu->i2c_capture_volume */
121274415a36SJames Courtier-Dutton         /*        capture_source: uinfo->value.enumerated.items = 2 */
121374415a36SJames Courtier-Dutton 	if (source_id >= 2)
121474415a36SJames Courtier-Dutton 		return -EINVAL;
1215184c1e2cSJames Courtier-Dutton 
1216184c1e2cSJames Courtier-Dutton 	ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0];
1217184c1e2cSJames Courtier-Dutton 	ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1];
1218184c1e2cSJames Courtier-Dutton 	return 0;
1219184c1e2cSJames Courtier-Dutton }
1220184c1e2cSJames Courtier-Dutton 
1221184c1e2cSJames Courtier-Dutton static int snd_audigy_i2c_volume_put(struct snd_kcontrol *kcontrol,
1222184c1e2cSJames Courtier-Dutton 				 struct snd_ctl_elem_value *ucontrol)
1223184c1e2cSJames Courtier-Dutton {
1224184c1e2cSJames Courtier-Dutton 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1225184c1e2cSJames Courtier-Dutton 	unsigned int ogain;
122614a29565SOswald Buddenhagen 	unsigned int ngain0, ngain1;
122774415a36SJames Courtier-Dutton 	unsigned int source_id;
1228184c1e2cSJames Courtier-Dutton 	int change = 0;
1229184c1e2cSJames Courtier-Dutton 
1230184c1e2cSJames Courtier-Dutton 	source_id = kcontrol->private_value;
123174415a36SJames Courtier-Dutton 	/* Limit: emu->i2c_capture_volume */
123274415a36SJames Courtier-Dutton         /*        capture_source: uinfo->value.enumerated.items = 2 */
123374415a36SJames Courtier-Dutton 	if (source_id >= 2)
123474415a36SJames Courtier-Dutton 		return -EINVAL;
123514a29565SOswald Buddenhagen 	ngain0 = ucontrol->value.integer.value[0];
123614a29565SOswald Buddenhagen 	ngain1 = ucontrol->value.integer.value[1];
123714a29565SOswald Buddenhagen 	if (ngain0 > 0xff)
123814a29565SOswald Buddenhagen 		return -EINVAL;
123914a29565SOswald Buddenhagen 	if (ngain1 > 0xff)
124014a29565SOswald Buddenhagen 		return -EINVAL;
1241184c1e2cSJames Courtier-Dutton 	ogain = emu->i2c_capture_volume[source_id][0]; /* Left */
124214a29565SOswald Buddenhagen 	if (ogain != ngain0) {
1243184c1e2cSJames Courtier-Dutton 		if (emu->i2c_capture_source == source_id)
124414a29565SOswald Buddenhagen 			snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ngain0);
124514a29565SOswald Buddenhagen 		emu->i2c_capture_volume[source_id][0] = ngain0;
1246184c1e2cSJames Courtier-Dutton 		change = 1;
1247184c1e2cSJames Courtier-Dutton 	}
1248184c1e2cSJames Courtier-Dutton 	ogain = emu->i2c_capture_volume[source_id][1]; /* Right */
124914a29565SOswald Buddenhagen 	if (ogain != ngain1) {
1250184c1e2cSJames Courtier-Dutton 		if (emu->i2c_capture_source == source_id)
125114a29565SOswald Buddenhagen 			snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ngain1);
125214a29565SOswald Buddenhagen 		emu->i2c_capture_volume[source_id][1] = ngain1;
1253184c1e2cSJames Courtier-Dutton 		change = 1;
1254184c1e2cSJames Courtier-Dutton 	}
1255184c1e2cSJames Courtier-Dutton 
1256184c1e2cSJames Courtier-Dutton 	return change;
1257184c1e2cSJames Courtier-Dutton }
1258184c1e2cSJames Courtier-Dutton 
1259536438f1SOswald Buddenhagen static const struct snd_kcontrol_new i2c_volume_ctl = {
1260536438f1SOswald Buddenhagen 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1261536438f1SOswald Buddenhagen 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1262536438f1SOswald Buddenhagen 	          SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1263536438f1SOswald Buddenhagen 	.info = snd_audigy_i2c_volume_info,
1264536438f1SOswald Buddenhagen 	.get = snd_audigy_i2c_volume_get,
1265536438f1SOswald Buddenhagen 	.put = snd_audigy_i2c_volume_put,
1266536438f1SOswald Buddenhagen 	.tlv = { .p = snd_audigy_db_scale2 }
1267536438f1SOswald Buddenhagen };
1268184c1e2cSJames Courtier-Dutton 
1269536438f1SOswald Buddenhagen static const char * const snd_audigy_i2c_volume_ctls[] = {
1270536438f1SOswald Buddenhagen 	"Mic Capture Volume",
1271536438f1SOswald Buddenhagen 	"Line Capture Volume",
1272184c1e2cSJames Courtier-Dutton };
1273184c1e2cSJames Courtier-Dutton 
12740af68e5eSTakashi Iwai #if 0
1275eb4698f3STakashi Iwai static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
12761da177e4SLinus Torvalds {
12771541c66dSTakashi Iwai 	static const char * const texts[] = {"44100", "48000", "96000"};
12781da177e4SLinus Torvalds 
12791541c66dSTakashi Iwai 	return snd_ctl_enum_info(uinfo, 1, 3, texts);
12801da177e4SLinus Torvalds }
12811da177e4SLinus Torvalds 
1282eb4698f3STakashi Iwai static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
1283eb4698f3STakashi Iwai                                  struct snd_ctl_elem_value *ucontrol)
12841da177e4SLinus Torvalds {
1285eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
12861da177e4SLinus Torvalds 	unsigned int tmp;
12871da177e4SLinus Torvalds 
12881da177e4SLinus Torvalds 	tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
12891da177e4SLinus Torvalds 	switch (tmp & A_SPDIF_RATE_MASK) {
12901da177e4SLinus Torvalds 	case A_SPDIF_44100:
12911da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 0;
12921da177e4SLinus Torvalds 		break;
12931da177e4SLinus Torvalds 	case A_SPDIF_48000:
12941da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1;
12951da177e4SLinus Torvalds 		break;
12961da177e4SLinus Torvalds 	case A_SPDIF_96000:
12971da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 2;
12981da177e4SLinus Torvalds 		break;
12991da177e4SLinus Torvalds 	default:
13001da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = 1;
13011da177e4SLinus Torvalds 	}
13021da177e4SLinus Torvalds 	return 0;
13031da177e4SLinus Torvalds }
13041da177e4SLinus Torvalds 
1305eb4698f3STakashi Iwai static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol,
1306eb4698f3STakashi Iwai                                  struct snd_ctl_elem_value *ucontrol)
13071da177e4SLinus Torvalds {
1308eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
13091da177e4SLinus Torvalds 	int change;
13101da177e4SLinus Torvalds 	unsigned int reg, val, tmp;
13111da177e4SLinus Torvalds 	unsigned long flags;
13121da177e4SLinus Torvalds 
13131da177e4SLinus Torvalds 	switch(ucontrol->value.enumerated.item[0]) {
13141da177e4SLinus Torvalds 	case 0:
13151da177e4SLinus Torvalds 		val = A_SPDIF_44100;
13161da177e4SLinus Torvalds 		break;
13171da177e4SLinus Torvalds 	case 1:
13181da177e4SLinus Torvalds 		val = A_SPDIF_48000;
13191da177e4SLinus Torvalds 		break;
13201da177e4SLinus Torvalds 	case 2:
13211da177e4SLinus Torvalds 		val = A_SPDIF_96000;
13221da177e4SLinus Torvalds 		break;
13231da177e4SLinus Torvalds 	default:
13241da177e4SLinus Torvalds 		val = A_SPDIF_48000;
13251da177e4SLinus Torvalds 		break;
13261da177e4SLinus Torvalds 	}
13271da177e4SLinus Torvalds 
13281da177e4SLinus Torvalds 
13291da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
13301da177e4SLinus Torvalds 	reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
13311da177e4SLinus Torvalds 	tmp = reg & ~A_SPDIF_RATE_MASK;
13321da177e4SLinus Torvalds 	tmp |= val;
133312bda107STakashi Iwai 	change = (tmp != reg);
133412bda107STakashi Iwai 	if (change)
13351da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
13361da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
13371da177e4SLinus Torvalds 	return change;
13381da177e4SLinus Torvalds }
13391da177e4SLinus Torvalds 
1340b4e5e707STakashi Iwai static const struct snd_kcontrol_new snd_audigy_spdif_output_rate =
13411da177e4SLinus Torvalds {
13421da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE,
13431da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
13441da177e4SLinus Torvalds 	.name =         "Audigy SPDIF Output Sample Rate",
13451da177e4SLinus Torvalds 	.count =	1,
13461da177e4SLinus Torvalds 	.info =         snd_audigy_spdif_output_rate_info,
13471da177e4SLinus Torvalds 	.get =          snd_audigy_spdif_output_rate_get,
13481da177e4SLinus Torvalds 	.put =          snd_audigy_spdif_output_rate_put
13491da177e4SLinus Torvalds };
13500af68e5eSTakashi Iwai #endif
13511da177e4SLinus Torvalds 
1352eb4698f3STakashi Iwai static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol,
1353eb4698f3STakashi Iwai                                  struct snd_ctl_elem_value *ucontrol)
13541da177e4SLinus Torvalds {
1355eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
13561da177e4SLinus Torvalds 	unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
13571da177e4SLinus Torvalds 	int change;
13581da177e4SLinus Torvalds 	unsigned int val;
13591da177e4SLinus Torvalds 
136074415a36SJames Courtier-Dutton 	/* Limit: emu->spdif_bits */
136174415a36SJames Courtier-Dutton 	if (idx >= 3)
136274415a36SJames Courtier-Dutton 		return -EINVAL;
13631da177e4SLinus Torvalds 	val = (ucontrol->value.iec958.status[0] << 0) |
13641da177e4SLinus Torvalds 	      (ucontrol->value.iec958.status[1] << 8) |
13651da177e4SLinus Torvalds 	      (ucontrol->value.iec958.status[2] << 16) |
13661da177e4SLinus Torvalds 	      (ucontrol->value.iec958.status[3] << 24);
13671da177e4SLinus Torvalds 	change = val != emu->spdif_bits[idx];
13681da177e4SLinus Torvalds 	if (change) {
13691da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val);
13701da177e4SLinus Torvalds 		emu->spdif_bits[idx] = val;
13711da177e4SLinus Torvalds 	}
13721da177e4SLinus Torvalds 	return change;
13731da177e4SLinus Torvalds }
13741da177e4SLinus Torvalds 
1375f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
13761da177e4SLinus Torvalds {
13771da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
13785549d549SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
13791da177e4SLinus Torvalds 	.name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
13807583cb51STakashi Iwai 	.count =	3,
13811da177e4SLinus Torvalds 	.info =         snd_emu10k1_spdif_info,
13821da177e4SLinus Torvalds 	.get =          snd_emu10k1_spdif_get_mask
13831da177e4SLinus Torvalds };
13841da177e4SLinus Torvalds 
1385f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu10k1_spdif_control =
13861da177e4SLinus Torvalds {
13875549d549SClemens Ladisch 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
13881da177e4SLinus Torvalds 	.name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
13897583cb51STakashi Iwai 	.count =	3,
13901da177e4SLinus Torvalds 	.info =         snd_emu10k1_spdif_info,
13911da177e4SLinus Torvalds 	.get =          snd_emu10k1_spdif_get,
13921da177e4SLinus Torvalds 	.put =          snd_emu10k1_spdif_put
13931da177e4SLinus Torvalds };
13941da177e4SLinus Torvalds 
13951da177e4SLinus Torvalds 
1396eb4698f3STakashi Iwai static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route)
13971da177e4SLinus Torvalds {
13981da177e4SLinus Torvalds 	if (emu->audigy) {
13991da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, A_FXRT1, voice,
14001da177e4SLinus Torvalds 				      snd_emu10k1_compose_audigy_fxrt1(route));
14011da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, A_FXRT2, voice,
14021da177e4SLinus Torvalds 				      snd_emu10k1_compose_audigy_fxrt2(route));
14031da177e4SLinus Torvalds 	} else {
14041da177e4SLinus Torvalds 		snd_emu10k1_ptr_write(emu, FXRT, voice,
14051da177e4SLinus Torvalds 				      snd_emu10k1_compose_send_routing(route));
14061da177e4SLinus Torvalds 	}
14071da177e4SLinus Torvalds }
14081da177e4SLinus Torvalds 
1409eb4698f3STakashi Iwai static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume)
14101da177e4SLinus Torvalds {
14111da177e4SLinus Torvalds 	snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]);
14121da177e4SLinus Torvalds 	snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]);
14131da177e4SLinus Torvalds 	snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]);
14141da177e4SLinus Torvalds 	snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]);
14151da177e4SLinus Torvalds 	if (emu->audigy) {
141651d652f4SOswald Buddenhagen 		snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice,
141751d652f4SOswald Buddenhagen 				      snd_emu10k1_compose_audigy_sendamounts(volume));
14181da177e4SLinus Torvalds 	}
14191da177e4SLinus Torvalds }
14201da177e4SLinus Torvalds 
14211da177e4SLinus Torvalds /* PCM stream controls */
14221da177e4SLinus Torvalds 
1423eb4698f3STakashi Iwai static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
14241da177e4SLinus Torvalds {
1425eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
14261da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
14271da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 3*8 : 3*4;
14281da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
14291da177e4SLinus Torvalds 	uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
14301da177e4SLinus Torvalds 	return 0;
14311da177e4SLinus Torvalds }
14321da177e4SLinus Torvalds 
1433eb4698f3STakashi Iwai static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol,
1434eb4698f3STakashi Iwai                                         struct snd_ctl_elem_value *ucontrol)
14351da177e4SLinus Torvalds {
1436eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1437eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
1438eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
14391da177e4SLinus Torvalds 	int voice, idx;
14401da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
14411da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
14421da177e4SLinus Torvalds 
14431da177e4SLinus Torvalds 	for (voice = 0; voice < 3; voice++)
14441da177e4SLinus Torvalds 		for (idx = 0; idx < num_efx; idx++)
14451da177e4SLinus Torvalds 			ucontrol->value.integer.value[(voice * num_efx) + idx] =
14461da177e4SLinus Torvalds 				mix->send_routing[voice][idx] & mask;
14471da177e4SLinus Torvalds 	return 0;
14481da177e4SLinus Torvalds }
14491da177e4SLinus Torvalds 
1450eb4698f3STakashi Iwai static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol,
1451eb4698f3STakashi Iwai                                         struct snd_ctl_elem_value *ucontrol)
14521da177e4SLinus Torvalds {
14531da177e4SLinus Torvalds 	unsigned long flags;
1454eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1455eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
1456eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
14571da177e4SLinus Torvalds 	int change = 0, voice, idx, val;
14581da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
14591da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
14601da177e4SLinus Torvalds 
14611da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
14621da177e4SLinus Torvalds 	for (voice = 0; voice < 3; voice++)
14631da177e4SLinus Torvalds 		for (idx = 0; idx < num_efx; idx++) {
14641da177e4SLinus Torvalds 			val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask;
14651da177e4SLinus Torvalds 			if (mix->send_routing[voice][idx] != val) {
14661da177e4SLinus Torvalds 				mix->send_routing[voice][idx] = val;
14671da177e4SLinus Torvalds 				change = 1;
14681da177e4SLinus Torvalds 			}
14691da177e4SLinus Torvalds 		}
14701da177e4SLinus Torvalds 	if (change && mix->epcm) {
14711da177e4SLinus Torvalds 		if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
14721da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
14731da177e4SLinus Torvalds 					    &mix->send_routing[1][0]);
14741da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[1]->number,
14751da177e4SLinus Torvalds 					    &mix->send_routing[2][0]);
14761da177e4SLinus Torvalds 		} else if (mix->epcm->voices[0]) {
14771da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
14781da177e4SLinus Torvalds 					    &mix->send_routing[0][0]);
14791da177e4SLinus Torvalds 		}
14801da177e4SLinus Torvalds 	}
14811da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
14821da177e4SLinus Torvalds 	return change;
14831da177e4SLinus Torvalds }
14841da177e4SLinus Torvalds 
1485f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu10k1_send_routing_control =
14861da177e4SLinus Torvalds {
14871da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
148867ed4161SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
14891da177e4SLinus Torvalds 	.name =         "EMU10K1 PCM Send Routing",
14901da177e4SLinus Torvalds 	.count =	32,
14911da177e4SLinus Torvalds 	.info =         snd_emu10k1_send_routing_info,
14921da177e4SLinus Torvalds 	.get =          snd_emu10k1_send_routing_get,
14931da177e4SLinus Torvalds 	.put =          snd_emu10k1_send_routing_put
14941da177e4SLinus Torvalds };
14951da177e4SLinus Torvalds 
1496eb4698f3STakashi Iwai static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
14971da177e4SLinus Torvalds {
1498eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
14991da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
15001da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 3*8 : 3*4;
15011da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
15021da177e4SLinus Torvalds 	uinfo->value.integer.max = 255;
15031da177e4SLinus Torvalds 	return 0;
15041da177e4SLinus Torvalds }
15051da177e4SLinus Torvalds 
1506eb4698f3STakashi Iwai static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol,
1507eb4698f3STakashi Iwai                                        struct snd_ctl_elem_value *ucontrol)
15081da177e4SLinus Torvalds {
1509eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1510eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
1511eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
15121da177e4SLinus Torvalds 	int idx;
15131da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
15141da177e4SLinus Torvalds 
15151da177e4SLinus Torvalds 	for (idx = 0; idx < 3*num_efx; idx++)
15161da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx];
15171da177e4SLinus Torvalds 	return 0;
15181da177e4SLinus Torvalds }
15191da177e4SLinus Torvalds 
1520eb4698f3STakashi Iwai static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol,
1521eb4698f3STakashi Iwai                                        struct snd_ctl_elem_value *ucontrol)
15221da177e4SLinus Torvalds {
15231da177e4SLinus Torvalds 	unsigned long flags;
1524eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1525eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
1526eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
15271da177e4SLinus Torvalds 	int change = 0, idx, val;
15281da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
15291da177e4SLinus Torvalds 
15301da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
15311da177e4SLinus Torvalds 	for (idx = 0; idx < 3*num_efx; idx++) {
15321da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & 255;
15331da177e4SLinus Torvalds 		if (mix->send_volume[idx/num_efx][idx%num_efx] != val) {
15341da177e4SLinus Torvalds 			mix->send_volume[idx/num_efx][idx%num_efx] = val;
15351da177e4SLinus Torvalds 			change = 1;
15361da177e4SLinus Torvalds 		}
15371da177e4SLinus Torvalds 	}
15381da177e4SLinus Torvalds 	if (change && mix->epcm) {
15391da177e4SLinus Torvalds 		if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
15401da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
15411da177e4SLinus Torvalds 						   &mix->send_volume[1][0]);
15421da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[1]->number,
15431da177e4SLinus Torvalds 						   &mix->send_volume[2][0]);
15441da177e4SLinus Torvalds 		} else if (mix->epcm->voices[0]) {
15451da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
15461da177e4SLinus Torvalds 						   &mix->send_volume[0][0]);
15471da177e4SLinus Torvalds 		}
15481da177e4SLinus Torvalds 	}
15491da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
15501da177e4SLinus Torvalds 	return change;
15511da177e4SLinus Torvalds }
15521da177e4SLinus Torvalds 
1553f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu10k1_send_volume_control =
15541da177e4SLinus Torvalds {
15551da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
155667ed4161SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
15571da177e4SLinus Torvalds 	.name =         "EMU10K1 PCM Send Volume",
15581da177e4SLinus Torvalds 	.count =	32,
15591da177e4SLinus Torvalds 	.info =         snd_emu10k1_send_volume_info,
15601da177e4SLinus Torvalds 	.get =          snd_emu10k1_send_volume_get,
15611da177e4SLinus Torvalds 	.put =          snd_emu10k1_send_volume_put
15621da177e4SLinus Torvalds };
15631da177e4SLinus Torvalds 
1564eb4698f3STakashi Iwai static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
15651da177e4SLinus Torvalds {
15661da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
15671da177e4SLinus Torvalds 	uinfo->count = 3;
15681da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
1569bcdbd3b7SOswald Buddenhagen 	uinfo->value.integer.max = 0x1fffd;
15701da177e4SLinus Torvalds 	return 0;
15711da177e4SLinus Torvalds }
15721da177e4SLinus Torvalds 
1573eb4698f3STakashi Iwai static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,
1574eb4698f3STakashi Iwai                                 struct snd_ctl_elem_value *ucontrol)
15751da177e4SLinus Torvalds {
1576eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1577eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
1578eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
15791da177e4SLinus Torvalds 	int idx;
15801da177e4SLinus Torvalds 
15811da177e4SLinus Torvalds 	for (idx = 0; idx < 3; idx++)
1582bcdbd3b7SOswald Buddenhagen 		ucontrol->value.integer.value[idx] = mix->attn[idx] * 0xffffU / 0x8000U;
15831da177e4SLinus Torvalds 	return 0;
15841da177e4SLinus Torvalds }
15851da177e4SLinus Torvalds 
1586eb4698f3STakashi Iwai static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,
1587eb4698f3STakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
15881da177e4SLinus Torvalds {
15891da177e4SLinus Torvalds 	unsigned long flags;
1590eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1591eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
1592eb4698f3STakashi Iwai 		&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
15931da177e4SLinus Torvalds 	int change = 0, idx, val;
15941da177e4SLinus Torvalds 
15951da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
15961da177e4SLinus Torvalds 	for (idx = 0; idx < 3; idx++) {
1597bcdbd3b7SOswald Buddenhagen 		unsigned uval = ucontrol->value.integer.value[idx] & 0x1ffff;
1598bcdbd3b7SOswald Buddenhagen 		val = uval * 0x8000U / 0xffffU;
15991da177e4SLinus Torvalds 		if (mix->attn[idx] != val) {
16001da177e4SLinus Torvalds 			mix->attn[idx] = val;
16011da177e4SLinus Torvalds 			change = 1;
16021da177e4SLinus Torvalds 		}
16031da177e4SLinus Torvalds 	}
16041da177e4SLinus Torvalds 	if (change && mix->epcm) {
16051da177e4SLinus Torvalds 		if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
16061da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]);
16071da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[1]->number, mix->attn[2]);
16081da177e4SLinus Torvalds 		} else if (mix->epcm->voices[0]) {
16091da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]);
16101da177e4SLinus Torvalds 		}
16111da177e4SLinus Torvalds 	}
16121da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
16131da177e4SLinus Torvalds 	return change;
16141da177e4SLinus Torvalds }
16151da177e4SLinus Torvalds 
1616f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu10k1_attn_control =
16171da177e4SLinus Torvalds {
16181da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
161967ed4161SClemens Ladisch 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
16201da177e4SLinus Torvalds 	.name =         "EMU10K1 PCM Volume",
16211da177e4SLinus Torvalds 	.count =	32,
16221da177e4SLinus Torvalds 	.info =         snd_emu10k1_attn_info,
16231da177e4SLinus Torvalds 	.get =          snd_emu10k1_attn_get,
16241da177e4SLinus Torvalds 	.put =          snd_emu10k1_attn_put
16251da177e4SLinus Torvalds };
16261da177e4SLinus Torvalds 
16271da177e4SLinus Torvalds /* Mutichannel PCM stream controls */
16281da177e4SLinus Torvalds 
1629eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
16301da177e4SLinus Torvalds {
1631eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
16321da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
16331da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 8 : 4;
16341da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
16351da177e4SLinus Torvalds 	uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
16361da177e4SLinus Torvalds 	return 0;
16371da177e4SLinus Torvalds }
16381da177e4SLinus Torvalds 
1639eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol,
1640eb4698f3STakashi Iwai                                         struct snd_ctl_elem_value *ucontrol)
16411da177e4SLinus Torvalds {
1642eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1643eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
1644eb4698f3STakashi Iwai 		&emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
16451da177e4SLinus Torvalds 	int idx;
16461da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
16471da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
16481da177e4SLinus Torvalds 
16491da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++)
16501da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] =
16511da177e4SLinus Torvalds 			mix->send_routing[0][idx] & mask;
16521da177e4SLinus Torvalds 	return 0;
16531da177e4SLinus Torvalds }
16541da177e4SLinus Torvalds 
1655eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol,
1656eb4698f3STakashi Iwai                                         struct snd_ctl_elem_value *ucontrol)
16571da177e4SLinus Torvalds {
16581da177e4SLinus Torvalds 	unsigned long flags;
1659eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
16601da177e4SLinus Torvalds 	int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1661eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
16621da177e4SLinus Torvalds 	int change = 0, idx, val;
16631da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
16641da177e4SLinus Torvalds 	int mask = emu->audigy ? 0x3f : 0x0f;
16651da177e4SLinus Torvalds 
16661da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
16671da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++) {
16681da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & mask;
16691da177e4SLinus Torvalds 		if (mix->send_routing[0][idx] != val) {
16701da177e4SLinus Torvalds 			mix->send_routing[0][idx] = val;
16711da177e4SLinus Torvalds 			change = 1;
16721da177e4SLinus Torvalds 		}
16731da177e4SLinus Torvalds 	}
16741da177e4SLinus Torvalds 
16751da177e4SLinus Torvalds 	if (change && mix->epcm) {
16761da177e4SLinus Torvalds 		if (mix->epcm->voices[ch]) {
16771da177e4SLinus Torvalds 			update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number,
16781da177e4SLinus Torvalds 					&mix->send_routing[0][0]);
16791da177e4SLinus Torvalds 		}
16801da177e4SLinus Torvalds 	}
16811da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
16821da177e4SLinus Torvalds 	return change;
16831da177e4SLinus Torvalds }
16841da177e4SLinus Torvalds 
1685f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
16861da177e4SLinus Torvalds {
16871da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
16881da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
16891da177e4SLinus Torvalds 	.name =         "Multichannel PCM Send Routing",
16901da177e4SLinus Torvalds 	.count =	16,
16911da177e4SLinus Torvalds 	.info =         snd_emu10k1_efx_send_routing_info,
16921da177e4SLinus Torvalds 	.get =          snd_emu10k1_efx_send_routing_get,
16931da177e4SLinus Torvalds 	.put =          snd_emu10k1_efx_send_routing_put
16941da177e4SLinus Torvalds };
16951da177e4SLinus Torvalds 
1696eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
16971da177e4SLinus Torvalds {
1698eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
16991da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
17001da177e4SLinus Torvalds 	uinfo->count = emu->audigy ? 8 : 4;
17011da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
17021da177e4SLinus Torvalds 	uinfo->value.integer.max = 255;
17031da177e4SLinus Torvalds 	return 0;
17041da177e4SLinus Torvalds }
17051da177e4SLinus Torvalds 
1706eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol,
1707eb4698f3STakashi Iwai                                        struct snd_ctl_elem_value *ucontrol)
17081da177e4SLinus Torvalds {
1709eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1710eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
1711eb4698f3STakashi Iwai 		&emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
17121da177e4SLinus Torvalds 	int idx;
17131da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
17141da177e4SLinus Torvalds 
17151da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++)
17161da177e4SLinus Torvalds 		ucontrol->value.integer.value[idx] = mix->send_volume[0][idx];
17171da177e4SLinus Torvalds 	return 0;
17181da177e4SLinus Torvalds }
17191da177e4SLinus Torvalds 
1720eb4698f3STakashi Iwai static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol,
1721eb4698f3STakashi Iwai                                        struct snd_ctl_elem_value *ucontrol)
17221da177e4SLinus Torvalds {
17231da177e4SLinus Torvalds 	unsigned long flags;
1724eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
17251da177e4SLinus Torvalds 	int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1726eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
17271da177e4SLinus Torvalds 	int change = 0, idx, val;
17281da177e4SLinus Torvalds 	int num_efx = emu->audigy ? 8 : 4;
17291da177e4SLinus Torvalds 
17301da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
17311da177e4SLinus Torvalds 	for (idx = 0; idx < num_efx; idx++) {
17321da177e4SLinus Torvalds 		val = ucontrol->value.integer.value[idx] & 255;
17331da177e4SLinus Torvalds 		if (mix->send_volume[0][idx] != val) {
17341da177e4SLinus Torvalds 			mix->send_volume[0][idx] = val;
17351da177e4SLinus Torvalds 			change = 1;
17361da177e4SLinus Torvalds 		}
17371da177e4SLinus Torvalds 	}
17381da177e4SLinus Torvalds 	if (change && mix->epcm) {
17391da177e4SLinus Torvalds 		if (mix->epcm->voices[ch]) {
17401da177e4SLinus Torvalds 			update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number,
17411da177e4SLinus Torvalds 						   &mix->send_volume[0][0]);
17421da177e4SLinus Torvalds 		}
17431da177e4SLinus Torvalds 	}
17441da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
17451da177e4SLinus Torvalds 	return change;
17461da177e4SLinus Torvalds }
17471da177e4SLinus Torvalds 
17481da177e4SLinus Torvalds 
1749f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
17501da177e4SLinus Torvalds {
17511da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
17521da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
17531da177e4SLinus Torvalds 	.name =         "Multichannel PCM Send Volume",
17541da177e4SLinus Torvalds 	.count =	16,
17551da177e4SLinus Torvalds 	.info =         snd_emu10k1_efx_send_volume_info,
17561da177e4SLinus Torvalds 	.get =          snd_emu10k1_efx_send_volume_get,
17571da177e4SLinus Torvalds 	.put =          snd_emu10k1_efx_send_volume_put
17581da177e4SLinus Torvalds };
17591da177e4SLinus Torvalds 
1760eb4698f3STakashi Iwai static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
17611da177e4SLinus Torvalds {
17621da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
17631da177e4SLinus Torvalds 	uinfo->count = 1;
17641da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
1765bcdbd3b7SOswald Buddenhagen 	uinfo->value.integer.max = 0x1fffd;
17661da177e4SLinus Torvalds 	return 0;
17671da177e4SLinus Torvalds }
17681da177e4SLinus Torvalds 
1769eb4698f3STakashi Iwai static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol,
1770eb4698f3STakashi Iwai                                 struct snd_ctl_elem_value *ucontrol)
17711da177e4SLinus Torvalds {
1772eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1773eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix =
1774eb4698f3STakashi Iwai 		&emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
17751da177e4SLinus Torvalds 
1776bcdbd3b7SOswald Buddenhagen 	ucontrol->value.integer.value[0] = mix->attn[0] * 0xffffU / 0x8000U;
17771da177e4SLinus Torvalds 	return 0;
17781da177e4SLinus Torvalds }
17791da177e4SLinus Torvalds 
1780eb4698f3STakashi Iwai static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol,
1781eb4698f3STakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
17821da177e4SLinus Torvalds {
17831da177e4SLinus Torvalds 	unsigned long flags;
1784eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
17851da177e4SLinus Torvalds 	int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1786eb4698f3STakashi Iwai 	struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
17871da177e4SLinus Torvalds 	int change = 0, val;
1788bcdbd3b7SOswald Buddenhagen 	unsigned uval;
17891da177e4SLinus Torvalds 
17901da177e4SLinus Torvalds 	spin_lock_irqsave(&emu->reg_lock, flags);
1791bcdbd3b7SOswald Buddenhagen 	uval = ucontrol->value.integer.value[0] & 0x1ffff;
1792bcdbd3b7SOswald Buddenhagen 	val = uval * 0x8000U / 0xffffU;
17931da177e4SLinus Torvalds 	if (mix->attn[0] != val) {
17941da177e4SLinus Torvalds 		mix->attn[0] = val;
17951da177e4SLinus Torvalds 		change = 1;
17961da177e4SLinus Torvalds 	}
17971da177e4SLinus Torvalds 	if (change && mix->epcm) {
17981da177e4SLinus Torvalds 		if (mix->epcm->voices[ch]) {
17991da177e4SLinus Torvalds 			snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]);
18001da177e4SLinus Torvalds 		}
18011da177e4SLinus Torvalds 	}
18021da177e4SLinus Torvalds 	spin_unlock_irqrestore(&emu->reg_lock, flags);
18031da177e4SLinus Torvalds 	return change;
18041da177e4SLinus Torvalds }
18051da177e4SLinus Torvalds 
1806f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
18071da177e4SLinus Torvalds {
18081da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
18091da177e4SLinus Torvalds 	.iface =        SNDRV_CTL_ELEM_IFACE_PCM,
18101da177e4SLinus Torvalds 	.name =         "Multichannel PCM Volume",
18111da177e4SLinus Torvalds 	.count =	16,
18121da177e4SLinus Torvalds 	.info =         snd_emu10k1_efx_attn_info,
18131da177e4SLinus Torvalds 	.get =          snd_emu10k1_efx_attn_get,
18141da177e4SLinus Torvalds 	.put =          snd_emu10k1_efx_attn_put
18151da177e4SLinus Torvalds };
18161da177e4SLinus Torvalds 
1817a5ce8890STakashi Iwai #define snd_emu10k1_shared_spdif_info	snd_ctl_boolean_mono_info
18181da177e4SLinus Torvalds 
1819eb4698f3STakashi Iwai static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
1820eb4698f3STakashi Iwai 					struct snd_ctl_elem_value *ucontrol)
18211da177e4SLinus Torvalds {
1822eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
18231da177e4SLinus Torvalds 
18241da177e4SLinus Torvalds 	if (emu->audigy)
1825a1c87c0bSOswald Buddenhagen 		ucontrol->value.integer.value[0] = inw(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
18261da177e4SLinus Torvalds 	else
18271da177e4SLinus Torvalds 		ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
1828d2cd74b1STakashi Iwai 	if (emu->card_capabilities->invert_shared_spdif)
1829d2cd74b1STakashi Iwai 		ucontrol->value.integer.value[0] =
1830d2cd74b1STakashi Iwai 			!ucontrol->value.integer.value[0];
1831d2cd74b1STakashi Iwai 
18321da177e4SLinus Torvalds 	return 0;
18331da177e4SLinus Torvalds }
18341da177e4SLinus Torvalds 
1835eb4698f3STakashi Iwai static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
1836eb4698f3STakashi Iwai 					struct snd_ctl_elem_value *ucontrol)
18371da177e4SLinus Torvalds {
18381da177e4SLinus Torvalds 	unsigned long flags;
1839eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1840d2cd74b1STakashi Iwai 	unsigned int reg, val, sw;
18411da177e4SLinus Torvalds 	int change = 0;
18421da177e4SLinus Torvalds 
1843d2cd74b1STakashi Iwai 	sw = ucontrol->value.integer.value[0];
1844d2cd74b1STakashi Iwai 	if (emu->card_capabilities->invert_shared_spdif)
1845d2cd74b1STakashi Iwai 		sw = !sw;
184650164f69SOswald Buddenhagen 	spin_lock_irqsave(&emu->emu_lock, flags);
1847184c1e2cSJames Courtier-Dutton 	if ( emu->card_capabilities->i2c_adc) {
1848184c1e2cSJames Courtier-Dutton 		/* Do nothing for Audigy 2 ZS Notebook */
1849184c1e2cSJames Courtier-Dutton 	} else if (emu->audigy) {
1850a1c87c0bSOswald Buddenhagen 		reg = inw(emu->port + A_IOCFG);
1851d2cd74b1STakashi Iwai 		val = sw ? A_IOCFG_GPOUT0 : 0;
18521da177e4SLinus Torvalds 		change = (reg & A_IOCFG_GPOUT0) != val;
18531da177e4SLinus Torvalds 		if (change) {
18541da177e4SLinus Torvalds 			reg &= ~A_IOCFG_GPOUT0;
18551da177e4SLinus Torvalds 			reg |= val;
1856a1c87c0bSOswald Buddenhagen 			outw(reg | val, emu->port + A_IOCFG);
18571da177e4SLinus Torvalds 		}
18581da177e4SLinus Torvalds 	}
18591da177e4SLinus Torvalds 	reg = inl(emu->port + HCFG);
1860d2cd74b1STakashi Iwai 	val = sw ? HCFG_GPOUT0 : 0;
18611da177e4SLinus Torvalds 	change |= (reg & HCFG_GPOUT0) != val;
18621da177e4SLinus Torvalds 	if (change) {
18631da177e4SLinus Torvalds 		reg &= ~HCFG_GPOUT0;
18641da177e4SLinus Torvalds 		reg |= val;
18651da177e4SLinus Torvalds 		outl(reg | val, emu->port + HCFG);
18661da177e4SLinus Torvalds 	}
186750164f69SOswald Buddenhagen 	spin_unlock_irqrestore(&emu->emu_lock, flags);
18681da177e4SLinus Torvalds 	return change;
18691da177e4SLinus Torvalds }
18701da177e4SLinus Torvalds 
1871f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_emu10k1_shared_spdif =
18721da177e4SLinus Torvalds {
18731da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
18741da177e4SLinus Torvalds 	.name =		"SB Live Analog/Digital Output Jack",
18751da177e4SLinus Torvalds 	.info =		snd_emu10k1_shared_spdif_info,
18761da177e4SLinus Torvalds 	.get =		snd_emu10k1_shared_spdif_get,
18771da177e4SLinus Torvalds 	.put =		snd_emu10k1_shared_spdif_put
18781da177e4SLinus Torvalds };
18791da177e4SLinus Torvalds 
1880f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_audigy_shared_spdif =
18811da177e4SLinus Torvalds {
18821da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
18831da177e4SLinus Torvalds 	.name =		"Audigy Analog/Digital Output Jack",
18841da177e4SLinus Torvalds 	.info =		snd_emu10k1_shared_spdif_info,
18851da177e4SLinus Torvalds 	.get =		snd_emu10k1_shared_spdif_get,
18861da177e4SLinus Torvalds 	.put =		snd_emu10k1_shared_spdif_put
18871da177e4SLinus Torvalds };
18881da177e4SLinus Torvalds 
188916950e09STakashi Iwai /* workaround for too low volume on Audigy due to 16bit/24bit conversion */
189016950e09STakashi Iwai 
189116950e09STakashi Iwai #define snd_audigy_capture_boost_info	snd_ctl_boolean_mono_info
189216950e09STakashi Iwai 
189316950e09STakashi Iwai static int snd_audigy_capture_boost_get(struct snd_kcontrol *kcontrol,
189416950e09STakashi Iwai 					struct snd_ctl_elem_value *ucontrol)
189516950e09STakashi Iwai {
189616950e09STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
189716950e09STakashi Iwai 	unsigned int val;
189816950e09STakashi Iwai 
189916950e09STakashi Iwai 	/* FIXME: better to use a cached version */
190016950e09STakashi Iwai 	val = snd_ac97_read(emu->ac97, AC97_REC_GAIN);
190116950e09STakashi Iwai 	ucontrol->value.integer.value[0] = !!val;
190216950e09STakashi Iwai 	return 0;
190316950e09STakashi Iwai }
190416950e09STakashi Iwai 
190516950e09STakashi Iwai static int snd_audigy_capture_boost_put(struct snd_kcontrol *kcontrol,
190616950e09STakashi Iwai 					struct snd_ctl_elem_value *ucontrol)
190716950e09STakashi Iwai {
190816950e09STakashi Iwai 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
190916950e09STakashi Iwai 	unsigned int val;
191016950e09STakashi Iwai 
191116950e09STakashi Iwai 	if (ucontrol->value.integer.value[0])
191216950e09STakashi Iwai 		val = 0x0f0f;
191316950e09STakashi Iwai 	else
191416950e09STakashi Iwai 		val = 0;
191516950e09STakashi Iwai 	return snd_ac97_update(emu->ac97, AC97_REC_GAIN, val);
191616950e09STakashi Iwai }
191716950e09STakashi Iwai 
1918f3b827e0SBhumika Goyal static const struct snd_kcontrol_new snd_audigy_capture_boost =
191916950e09STakashi Iwai {
192016950e09STakashi Iwai 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
19212a52feb1SMaciej S. Szmigiero 	.name =		"Mic Extra Boost",
192216950e09STakashi Iwai 	.info =		snd_audigy_capture_boost_info,
192316950e09STakashi Iwai 	.get =		snd_audigy_capture_boost_get,
192416950e09STakashi Iwai 	.put =		snd_audigy_capture_boost_put
192516950e09STakashi Iwai };
192616950e09STakashi Iwai 
192716950e09STakashi Iwai 
19281da177e4SLinus Torvalds /*
19291da177e4SLinus Torvalds  */
1930eb4698f3STakashi Iwai static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
19311da177e4SLinus Torvalds {
1932eb4698f3STakashi Iwai 	struct snd_emu10k1 *emu = ac97->private_data;
19331da177e4SLinus Torvalds 	emu->ac97 = NULL;
19341da177e4SLinus Torvalds }
19351da177e4SLinus Torvalds 
19361da177e4SLinus Torvalds /*
19371da177e4SLinus Torvalds  */
1938eb4698f3STakashi Iwai static int remove_ctl(struct snd_card *card, const char *name)
19391da177e4SLinus Torvalds {
1940eb4698f3STakashi Iwai 	struct snd_ctl_elem_id id;
19411da177e4SLinus Torvalds 	memset(&id, 0, sizeof(id));
19421da177e4SLinus Torvalds 	strcpy(id.name, name);
19431da177e4SLinus Torvalds 	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
19441da177e4SLinus Torvalds 	return snd_ctl_remove_id(card, &id);
19451da177e4SLinus Torvalds }
19461da177e4SLinus Torvalds 
1947eb4698f3STakashi Iwai static struct snd_kcontrol *ctl_find(struct snd_card *card, const char *name)
19481da177e4SLinus Torvalds {
1949eb4698f3STakashi Iwai 	struct snd_ctl_elem_id sid;
19501da177e4SLinus Torvalds 	memset(&sid, 0, sizeof(sid));
19511da177e4SLinus Torvalds 	strcpy(sid.name, name);
19521da177e4SLinus Torvalds 	sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
19531da177e4SLinus Torvalds 	return snd_ctl_find_id(card, &sid);
19541da177e4SLinus Torvalds }
19551da177e4SLinus Torvalds 
1956eb4698f3STakashi Iwai static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
19571da177e4SLinus Torvalds {
1958eb4698f3STakashi Iwai 	struct snd_kcontrol *kctl = ctl_find(card, src);
19591da177e4SLinus Torvalds 	if (kctl) {
196036476b81SMaciej S. Szmigiero 		snd_ctl_rename(card, kctl, dst);
19611da177e4SLinus Torvalds 		return 0;
19621da177e4SLinus Torvalds 	}
19631da177e4SLinus Torvalds 	return -ENOENT;
19641da177e4SLinus Torvalds }
19651da177e4SLinus Torvalds 
1966e23e7a14SBill Pemberton int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
196767ed4161SClemens Ladisch 		      int pcm_device, int multi_device)
19681da177e4SLinus Torvalds {
1969155e3d3bSOswald Buddenhagen 	int err;
1970eb4698f3STakashi Iwai 	struct snd_kcontrol *kctl;
1971eb4698f3STakashi Iwai 	struct snd_card *card = emu->card;
19726fddce26STakashi Iwai 	const char * const *c;
19736fddce26STakashi Iwai 	static const char * const emu10k1_remove_ctls[] = {
19741da177e4SLinus Torvalds 		/* no AC97 mono, surround, center/lfe */
19751da177e4SLinus Torvalds 		"Master Mono Playback Switch",
19761da177e4SLinus Torvalds 		"Master Mono Playback Volume",
19771da177e4SLinus Torvalds 		"PCM Out Path & Mute",
19781da177e4SLinus Torvalds 		"Mono Output Select",
19791da177e4SLinus Torvalds 		"Surround Playback Switch",
19801da177e4SLinus Torvalds 		"Surround Playback Volume",
19811da177e4SLinus Torvalds 		"Center Playback Switch",
19821da177e4SLinus Torvalds 		"Center Playback Volume",
19831da177e4SLinus Torvalds 		"LFE Playback Switch",
19841da177e4SLinus Torvalds 		"LFE Playback Volume",
19851da177e4SLinus Torvalds 		NULL
19861da177e4SLinus Torvalds 	};
19876fddce26STakashi Iwai 	static const char * const emu10k1_rename_ctls[] = {
19881da177e4SLinus Torvalds 		"Surround Digital Playback Volume", "Surround Playback Volume",
19891da177e4SLinus Torvalds 		"Center Digital Playback Volume", "Center Playback Volume",
19901da177e4SLinus Torvalds 		"LFE Digital Playback Volume", "LFE Playback Volume",
19911da177e4SLinus Torvalds 		NULL
19921da177e4SLinus Torvalds 	};
19936fddce26STakashi Iwai 	static const char * const audigy_remove_ctls[] = {
19941da177e4SLinus Torvalds 		/* Master/PCM controls on ac97 of Audigy has no effect */
199521fdddeaSJames Courtier-Dutton 		/* On the Audigy2 the AC97 playback is piped into
199621fdddeaSJames Courtier-Dutton 		 * the Philips ADC for 24bit capture */
19971da177e4SLinus Torvalds 		"PCM Playback Switch",
19981da177e4SLinus Torvalds 		"PCM Playback Volume",
19991da177e4SLinus Torvalds 		"Master Playback Switch",
20001da177e4SLinus Torvalds 		"Master Playback Volume",
20011da177e4SLinus Torvalds 		"PCM Out Path & Mute",
20021da177e4SLinus Torvalds 		"Mono Output Select",
20031da177e4SLinus Torvalds 		/* remove unused AC97 capture controls */
20041da177e4SLinus Torvalds 		"Capture Source",
20051da177e4SLinus Torvalds 		"Capture Switch",
20061da177e4SLinus Torvalds 		"Capture Volume",
20071da177e4SLinus Torvalds 		"Mic Select",
2008274b2000SMaciej S. Szmigiero 		"Headphone Playback Switch",
2009274b2000SMaciej S. Szmigiero 		"Headphone Playback Volume",
2010274b2000SMaciej S. Szmigiero 		"3D Control - Center",
2011274b2000SMaciej S. Szmigiero 		"3D Control - Depth",
2012274b2000SMaciej S. Szmigiero 		"3D Control - Switch",
20131da177e4SLinus Torvalds 		"Video Playback Switch",
20141da177e4SLinus Torvalds 		"Video Playback Volume",
20151da177e4SLinus Torvalds 		"Mic Playback Switch",
20161da177e4SLinus Torvalds 		"Mic Playback Volume",
2017274b2000SMaciej S. Szmigiero 		"External Amplifier",
20181da177e4SLinus Torvalds 		NULL
20191da177e4SLinus Torvalds 	};
20206fddce26STakashi Iwai 	static const char * const audigy_rename_ctls[] = {
20211da177e4SLinus Torvalds 		/* use conventional names */
20221da177e4SLinus Torvalds 		"Wave Playback Volume", "PCM Playback Volume",
20231da177e4SLinus Torvalds 		/* "Wave Capture Volume", "PCM Capture Volume", */
20241da177e4SLinus Torvalds 		"Wave Master Playback Volume", "Master Playback Volume",
20251da177e4SLinus Torvalds 		"AMic Playback Volume", "Mic Playback Volume",
202652051942SMaciej S. Szmigiero 		"Master Mono Playback Switch", "Phone Output Playback Switch",
202752051942SMaciej S. Szmigiero 		"Master Mono Playback Volume", "Phone Output Playback Volume",
20281da177e4SLinus Torvalds 		NULL
20291da177e4SLinus Torvalds 	};
20306fddce26STakashi Iwai 	static const char * const audigy_rename_ctls_i2c_adc[] = {
2031184c1e2cSJames Courtier-Dutton 		//"Analog Mix Capture Volume","OLD Analog Mix Capture Volume",
2032184c1e2cSJames Courtier-Dutton 		"Line Capture Volume", "Analog Mix Capture Volume",
2033184c1e2cSJames Courtier-Dutton 		"Wave Playback Volume", "OLD PCM Playback Volume",
2034184c1e2cSJames Courtier-Dutton 		"Wave Master Playback Volume", "Master Playback Volume",
2035184c1e2cSJames Courtier-Dutton 		"AMic Playback Volume", "Old Mic Playback Volume",
2036eb41dab6SJames Courtier-Dutton 		"CD Capture Volume", "IEC958 Optical Capture Volume",
2037184c1e2cSJames Courtier-Dutton 		NULL
2038184c1e2cSJames Courtier-Dutton 	};
20396fddce26STakashi Iwai 	static const char * const audigy_remove_ctls_i2c_adc[] = {
2040184c1e2cSJames Courtier-Dutton 		/* On the Audigy2 ZS Notebook
2041184c1e2cSJames Courtier-Dutton 		 * Capture via WM8775  */
2042184c1e2cSJames Courtier-Dutton 		"Mic Capture Volume",
2043184c1e2cSJames Courtier-Dutton 		"Analog Mix Capture Volume",
2044184c1e2cSJames Courtier-Dutton 		"Aux Capture Volume",
2045eb41dab6SJames Courtier-Dutton 		"IEC958 Optical Capture Volume",
2046184c1e2cSJames Courtier-Dutton 		NULL
2047184c1e2cSJames Courtier-Dutton 	};
20486fddce26STakashi Iwai 	static const char * const audigy_remove_ctls_1361t_adc[] = {
204921fdddeaSJames Courtier-Dutton 		/* On the Audigy2 the AC97 playback is piped into
205021fdddeaSJames Courtier-Dutton 		 * the Philips ADC for 24bit capture */
205121fdddeaSJames Courtier-Dutton 		"PCM Playback Switch",
205221fdddeaSJames Courtier-Dutton 		"PCM Playback Volume",
205321fdddeaSJames Courtier-Dutton 		"Capture Source",
205421fdddeaSJames Courtier-Dutton 		"Capture Switch",
205521fdddeaSJames Courtier-Dutton 		"Capture Volume",
205621fdddeaSJames Courtier-Dutton 		"Mic Capture Volume",
205721fdddeaSJames Courtier-Dutton 		"Headphone Playback Switch",
205821fdddeaSJames Courtier-Dutton 		"Headphone Playback Volume",
205921fdddeaSJames Courtier-Dutton 		"3D Control - Center",
206021fdddeaSJames Courtier-Dutton 		"3D Control - Depth",
206121fdddeaSJames Courtier-Dutton 		"3D Control - Switch",
206221fdddeaSJames Courtier-Dutton 		"Line2 Playback Volume",
206321fdddeaSJames Courtier-Dutton 		"Line2 Capture Volume",
206421fdddeaSJames Courtier-Dutton 		NULL
206521fdddeaSJames Courtier-Dutton 	};
20666fddce26STakashi Iwai 	static const char * const audigy_rename_ctls_1361t_adc[] = {
206721fdddeaSJames Courtier-Dutton 		"Master Playback Switch", "Master Capture Switch",
206821fdddeaSJames Courtier-Dutton 		"Master Playback Volume", "Master Capture Volume",
206921fdddeaSJames Courtier-Dutton 		"Wave Master Playback Volume", "Master Playback Volume",
2070d355c82aSJaroslav Kysela 		"Beep Playback Switch", "Beep Capture Switch",
2071d355c82aSJaroslav Kysela 		"Beep Playback Volume", "Beep Capture Volume",
207221fdddeaSJames Courtier-Dutton 		"Phone Playback Switch", "Phone Capture Switch",
207321fdddeaSJames Courtier-Dutton 		"Phone Playback Volume", "Phone Capture Volume",
207421fdddeaSJames Courtier-Dutton 		"Mic Playback Switch", "Mic Capture Switch",
207521fdddeaSJames Courtier-Dutton 		"Mic Playback Volume", "Mic Capture Volume",
207621fdddeaSJames Courtier-Dutton 		"Line Playback Switch", "Line Capture Switch",
207721fdddeaSJames Courtier-Dutton 		"Line Playback Volume", "Line Capture Volume",
207821fdddeaSJames Courtier-Dutton 		"CD Playback Switch", "CD Capture Switch",
207921fdddeaSJames Courtier-Dutton 		"CD Playback Volume", "CD Capture Volume",
208021fdddeaSJames Courtier-Dutton 		"Aux Playback Switch", "Aux Capture Switch",
208121fdddeaSJames Courtier-Dutton 		"Aux Playback Volume", "Aux Capture Volume",
208221fdddeaSJames Courtier-Dutton 		"Video Playback Switch", "Video Capture Switch",
208321fdddeaSJames Courtier-Dutton 		"Video Playback Volume", "Video Capture Volume",
208452051942SMaciej S. Szmigiero 		"Master Mono Playback Switch", "Phone Output Playback Switch",
208552051942SMaciej S. Szmigiero 		"Master Mono Playback Volume", "Phone Output Playback Volume",
208621fdddeaSJames Courtier-Dutton 		NULL
208721fdddeaSJames Courtier-Dutton 	};
20881da177e4SLinus Torvalds 
20892b637da5SLee Revell 	if (emu->card_capabilities->ac97_chip) {
2090eb4698f3STakashi Iwai 		struct snd_ac97_bus *pbus;
2091eb4698f3STakashi Iwai 		struct snd_ac97_template ac97;
209251055da5STakashi Iwai 		static const struct snd_ac97_bus_ops ops = {
20931da177e4SLinus Torvalds 			.write = snd_emu10k1_ac97_write,
20941da177e4SLinus Torvalds 			.read = snd_emu10k1_ac97_read,
20951da177e4SLinus Torvalds 		};
20961da177e4SLinus Torvalds 
209712bda107STakashi Iwai 		err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus);
209812bda107STakashi Iwai 		if (err < 0)
20991da177e4SLinus Torvalds 			return err;
21001da177e4SLinus Torvalds 		pbus->no_vra = 1; /* we don't need VRA */
21011da177e4SLinus Torvalds 
21021da177e4SLinus Torvalds 		memset(&ac97, 0, sizeof(ac97));
21031da177e4SLinus Torvalds 		ac97.private_data = emu;
21041da177e4SLinus Torvalds 		ac97.private_free = snd_emu10k1_mixer_free_ac97;
21051da177e4SLinus Torvalds 		ac97.scaps = AC97_SCAP_NO_SPDIF;
210612bda107STakashi Iwai 		err = snd_ac97_mixer(pbus, &ac97, &emu->ac97);
210712bda107STakashi Iwai 		if (err < 0) {
2108b1508693STakashi Iwai 			if (emu->card_capabilities->ac97_chip == 1)
21091da177e4SLinus Torvalds 				return err;
21106f002b02STakashi Iwai 			dev_info(emu->card->dev,
21116f002b02STakashi Iwai 				 "AC97 is optional on this board\n");
21126f002b02STakashi Iwai 			dev_info(emu->card->dev,
21136f002b02STakashi Iwai 				 "Proceeding without ac97 mixers...\n");
2114b1508693STakashi Iwai 			snd_device_free(emu->card, pbus);
2115b1508693STakashi Iwai 			goto no_ac97; /* FIXME: get rid of ugly gotos.. */
2116b1508693STakashi Iwai 		}
21171da177e4SLinus Torvalds 		if (emu->audigy) {
21181da177e4SLinus Torvalds 			/* set master volume to 0 dB */
21194d7d7596STakashi Iwai 			snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000);
21201da177e4SLinus Torvalds 			/* set capture source to mic */
21214d7d7596STakashi Iwai 			snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
212252051942SMaciej S. Szmigiero 			/* set mono output (TAD) to mic */
212352051942SMaciej S. Szmigiero 			snd_ac97_update_bits(emu->ac97, AC97_GENERAL_PURPOSE,
212452051942SMaciej S. Szmigiero 				0x0200, 0x0200);
212521fdddeaSJames Courtier-Dutton 			if (emu->card_capabilities->adc_1361t)
212621fdddeaSJames Courtier-Dutton 				c = audigy_remove_ctls_1361t_adc;
212721fdddeaSJames Courtier-Dutton 			else
21281da177e4SLinus Torvalds 				c = audigy_remove_ctls;
21291da177e4SLinus Torvalds 		} else {
21301da177e4SLinus Torvalds 			/*
21311da177e4SLinus Torvalds 			 * Credits for cards based on STAC9758:
21321da177e4SLinus Torvalds 			 *   James Courtier-Dutton <James@superbug.demon.co.uk>
21331da177e4SLinus Torvalds 			 *   Voluspa <voluspa@comhem.se>
21341da177e4SLinus Torvalds 			 */
21351da177e4SLinus Torvalds 			if (emu->ac97->id == AC97_ID_STAC9758) {
21361da177e4SLinus Torvalds 				emu->rear_ac97 = 1;
21371da177e4SLinus Torvalds 				snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
21382594d960SRolf Stefan Wilke 				snd_ac97_write_cache(emu->ac97, AC97_HEADPHONE, 0x0202);
2139b6a48404SRaymond Yau 				remove_ctl(card,"Front Playback Volume");
2140b6a48404SRaymond Yau 				remove_ctl(card,"Front Playback Switch");
21411da177e4SLinus Torvalds 			}
21421da177e4SLinus Torvalds 			/* remove unused AC97 controls */
21434d7d7596STakashi Iwai 			snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
21444d7d7596STakashi Iwai 			snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
21451da177e4SLinus Torvalds 			c = emu10k1_remove_ctls;
21461da177e4SLinus Torvalds 		}
21471da177e4SLinus Torvalds 		for (; *c; c++)
21481da177e4SLinus Torvalds 			remove_ctl(card, *c);
2149184c1e2cSJames Courtier-Dutton 	} else if (emu->card_capabilities->i2c_adc) {
2150184c1e2cSJames Courtier-Dutton 		c = audigy_remove_ctls_i2c_adc;
2151184c1e2cSJames Courtier-Dutton 		for (; *c; c++)
2152184c1e2cSJames Courtier-Dutton 			remove_ctl(card, *c);
21531da177e4SLinus Torvalds 	} else {
2154f12aa40cSTakashi Iwai 	no_ac97:
21552b637da5SLee Revell 		if (emu->card_capabilities->ecard)
21561da177e4SLinus Torvalds 			strcpy(emu->card->mixername, "EMU APS");
21571da177e4SLinus Torvalds 		else if (emu->audigy)
21581da177e4SLinus Torvalds 			strcpy(emu->card->mixername, "SB Audigy");
21591da177e4SLinus Torvalds 		else
21601da177e4SLinus Torvalds 			strcpy(emu->card->mixername, "Emu10k1");
21611da177e4SLinus Torvalds 	}
21621da177e4SLinus Torvalds 
21631da177e4SLinus Torvalds 	if (emu->audigy)
216421fdddeaSJames Courtier-Dutton 		if (emu->card_capabilities->adc_1361t)
216521fdddeaSJames Courtier-Dutton 			c = audigy_rename_ctls_1361t_adc;
2166184c1e2cSJames Courtier-Dutton 		else if (emu->card_capabilities->i2c_adc)
2167184c1e2cSJames Courtier-Dutton 			c = audigy_rename_ctls_i2c_adc;
216821fdddeaSJames Courtier-Dutton 		else
21691da177e4SLinus Torvalds 			c = audigy_rename_ctls;
21701da177e4SLinus Torvalds 	else
21711da177e4SLinus Torvalds 		c = emu10k1_rename_ctls;
21721da177e4SLinus Torvalds 	for (; *c; c += 2)
21731da177e4SLinus Torvalds 		rename_ctl(card, c[0], c[1]);
217421fdddeaSJames Courtier-Dutton 
2175e217b960SRaymond Yau 	if (emu->card_capabilities->subsystem == 0x80401102) { /* SB Live! Platinum CT4760P */
2176e217b960SRaymond Yau 		remove_ctl(card, "Center Playback Volume");
2177e217b960SRaymond Yau 		remove_ctl(card, "LFE Playback Volume");
2178e217b960SRaymond Yau 		remove_ctl(card, "Wave Center Playback Volume");
2179e217b960SRaymond Yau 		remove_ctl(card, "Wave LFE Playback Volume");
2180e217b960SRaymond Yau 	}
2181e3b9bc0eSJames Courtier-Dutton 	if (emu->card_capabilities->subsystem == 0x20071102) {  /* Audigy 4 Pro */
2182e3b9bc0eSJames Courtier-Dutton 		rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
2183e3b9bc0eSJames Courtier-Dutton 		rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
2184e3b9bc0eSJames Courtier-Dutton 		rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
2185e3b9bc0eSJames Courtier-Dutton 		rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
2186e3b9bc0eSJames Courtier-Dutton 	}
218712bda107STakashi Iwai 	kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu);
218812bda107STakashi Iwai 	if (!kctl)
21891da177e4SLinus Torvalds 		return -ENOMEM;
219067ed4161SClemens Ladisch 	kctl->id.device = pcm_device;
219112bda107STakashi Iwai 	err = snd_ctl_add(card, kctl);
219212bda107STakashi Iwai 	if (err)
21931da177e4SLinus Torvalds 		return err;
219412bda107STakashi Iwai 	kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu);
219512bda107STakashi Iwai 	if (!kctl)
21961da177e4SLinus Torvalds 		return -ENOMEM;
219767ed4161SClemens Ladisch 	kctl->id.device = pcm_device;
219812bda107STakashi Iwai 	err = snd_ctl_add(card, kctl);
219912bda107STakashi Iwai 	if (err)
22001da177e4SLinus Torvalds 		return err;
220112bda107STakashi Iwai 	kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu);
220212bda107STakashi Iwai 	if (!kctl)
22031da177e4SLinus Torvalds 		return -ENOMEM;
220467ed4161SClemens Ladisch 	kctl->id.device = pcm_device;
220512bda107STakashi Iwai 	err = snd_ctl_add(card, kctl);
220612bda107STakashi Iwai 	if (err)
22071da177e4SLinus Torvalds 		return err;
22081da177e4SLinus Torvalds 
220912bda107STakashi Iwai 	kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu);
221012bda107STakashi Iwai 	if (!kctl)
22111da177e4SLinus Torvalds 		return -ENOMEM;
221267ed4161SClemens Ladisch 	kctl->id.device = multi_device;
221312bda107STakashi Iwai 	err = snd_ctl_add(card, kctl);
221412bda107STakashi Iwai 	if (err)
22151da177e4SLinus Torvalds 		return err;
22161da177e4SLinus Torvalds 
221712bda107STakashi Iwai 	kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu);
221812bda107STakashi Iwai 	if (!kctl)
22191da177e4SLinus Torvalds 		return -ENOMEM;
222067ed4161SClemens Ladisch 	kctl->id.device = multi_device;
222112bda107STakashi Iwai 	err = snd_ctl_add(card, kctl);
222212bda107STakashi Iwai 	if (err)
22231da177e4SLinus Torvalds 		return err;
22241da177e4SLinus Torvalds 
222512bda107STakashi Iwai 	kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu);
222612bda107STakashi Iwai 	if (!kctl)
22271da177e4SLinus Torvalds 		return -ENOMEM;
222867ed4161SClemens Ladisch 	kctl->id.device = multi_device;
222912bda107STakashi Iwai 	err = snd_ctl_add(card, kctl);
223012bda107STakashi Iwai 	if (err)
22311da177e4SLinus Torvalds 		return err;
22321da177e4SLinus Torvalds 
2233a8661af5SOswald Buddenhagen 	if (!emu->card_capabilities->ecard && !emu->card_capabilities->emu_model) {
22341da177e4SLinus Torvalds 		/* sb live! and audigy */
223512bda107STakashi Iwai 		kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu);
223612bda107STakashi Iwai 		if (!kctl)
22371da177e4SLinus Torvalds 			return -ENOMEM;
22385549d549SClemens Ladisch 		if (!emu->audigy)
22395549d549SClemens Ladisch 			kctl->id.device = emu->pcm_efx->device;
224012bda107STakashi Iwai 		err = snd_ctl_add(card, kctl);
224112bda107STakashi Iwai 		if (err)
22421da177e4SLinus Torvalds 			return err;
224312bda107STakashi Iwai 		kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu);
224412bda107STakashi Iwai 		if (!kctl)
22451da177e4SLinus Torvalds 			return -ENOMEM;
22465549d549SClemens Ladisch 		if (!emu->audigy)
22475549d549SClemens Ladisch 			kctl->id.device = emu->pcm_efx->device;
224812bda107STakashi Iwai 		err = snd_ctl_add(card, kctl);
224912bda107STakashi Iwai 		if (err)
22501da177e4SLinus Torvalds 			return err;
22511da177e4SLinus Torvalds 	}
22521da177e4SLinus Torvalds 
2253190d2c46SJames Courtier-Dutton 	if (emu->card_capabilities->emu_model) {
225419b99fbaSJames Courtier-Dutton 		;  /* Disable the snd_audigy_spdif_shared_spdif */
225519b99fbaSJames Courtier-Dutton 	} else if (emu->audigy) {
225612bda107STakashi Iwai 		kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu);
225712bda107STakashi Iwai 		if (!kctl)
22581da177e4SLinus Torvalds 			return -ENOMEM;
225912bda107STakashi Iwai 		err = snd_ctl_add(card, kctl);
226012bda107STakashi Iwai 		if (err)
22611da177e4SLinus Torvalds 			return err;
2262001f7589SJames Courtier-Dutton #if 0
226312bda107STakashi Iwai 		kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu);
226412bda107STakashi Iwai 		if (!kctl)
22651da177e4SLinus Torvalds 			return -ENOMEM;
226612bda107STakashi Iwai 		err = snd_ctl_add(card, kctl);
226712bda107STakashi Iwai 		if (err)
22681da177e4SLinus Torvalds 			return err;
2269001f7589SJames Courtier-Dutton #endif
22702b637da5SLee Revell 	} else if (! emu->card_capabilities->ecard) {
22711da177e4SLinus Torvalds 		/* sb live! */
227212bda107STakashi Iwai 		kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu);
227312bda107STakashi Iwai 		if (!kctl)
22741da177e4SLinus Torvalds 			return -ENOMEM;
227512bda107STakashi Iwai 		err = snd_ctl_add(card, kctl);
227612bda107STakashi Iwai 		if (err)
22771da177e4SLinus Torvalds 			return err;
22781da177e4SLinus Torvalds 	}
22792b637da5SLee Revell 	if (emu->card_capabilities->ca0151_chip) { /* P16V */
228012bda107STakashi Iwai 		err = snd_p16v_mixer(emu);
228112bda107STakashi Iwai 		if (err)
22821da177e4SLinus Torvalds 			return err;
22831da177e4SLinus Torvalds 	}
22841da177e4SLinus Torvalds 
22851fc710f0SOswald Buddenhagen 	if (emu->card_capabilities->emu_model) {
22861fc710f0SOswald Buddenhagen 		unsigned i, emu_idx = emu1010_idx(emu);
22871fc710f0SOswald Buddenhagen 		const struct snd_emu1010_routing_info *emu_ri =
22881fc710f0SOswald Buddenhagen 			&emu1010_routing_info[emu_idx];
228997f1582eSOswald Buddenhagen 		const struct snd_emu1010_pads_info *emu_pi = &emu1010_pads_info[emu_idx];
22901fc710f0SOswald Buddenhagen 
22911fc710f0SOswald Buddenhagen 		for (i = 0; i < emu_ri->n_ins; i++)
22921fc710f0SOswald Buddenhagen 			emu->emu1010.input_source[i] =
22931fc710f0SOswald Buddenhagen 				emu1010_map_source(emu_ri, emu_ri->in_dflts[i]);
22941fc710f0SOswald Buddenhagen 		for (i = 0; i < emu_ri->n_outs; i++)
22951fc710f0SOswald Buddenhagen 			emu->emu1010.output_source[i] =
22961fc710f0SOswald Buddenhagen 				emu1010_map_source(emu_ri, emu_ri->out_dflts[i]);
22971fc710f0SOswald Buddenhagen 		snd_emu1010_apply_sources(emu);
22981fc710f0SOswald Buddenhagen 
22991c02e366SCtirad Fertr 		err = snd_ctl_add(card,
23001c02e366SCtirad Fertr 			snd_ctl_new1(&snd_emu1010_internal_clock, emu));
23011c02e366SCtirad Fertr 		if (err < 0)
23021c02e366SCtirad Fertr 			return err;
230397f1582eSOswald Buddenhagen 
230497f1582eSOswald Buddenhagen 		err = add_ctls(emu, &emu1010_adc_pads_ctl,
230597f1582eSOswald Buddenhagen 			       emu_pi->adc_ctls, emu_pi->n_adc_ctls);
230697f1582eSOswald Buddenhagen 		if (err < 0)
230797f1582eSOswald Buddenhagen 			return err;
230897f1582eSOswald Buddenhagen 		err = add_ctls(emu, &emu1010_dac_pads_ctl,
230997f1582eSOswald Buddenhagen 			       emu_pi->dac_ctls, emu_pi->n_dac_ctls);
231097f1582eSOswald Buddenhagen 		if (err < 0)
231197f1582eSOswald Buddenhagen 			return err;
231297f1582eSOswald Buddenhagen 
23136f3609f8SOswald Buddenhagen 		if (!emu->card_capabilities->no_adat) {
231499dcab46SMichael Gernoth 			err = snd_ctl_add(card,
231599dcab46SMichael Gernoth 				snd_ctl_new1(&snd_emu1010_optical_out, emu));
231699dcab46SMichael Gernoth 			if (err < 0)
231799dcab46SMichael Gernoth 				return err;
231899dcab46SMichael Gernoth 			err = snd_ctl_add(card,
231999dcab46SMichael Gernoth 				snd_ctl_new1(&snd_emu1010_optical_in, emu));
232099dcab46SMichael Gernoth 			if (err < 0)
232199dcab46SMichael Gernoth 				return err;
23226f3609f8SOswald Buddenhagen 		}
23231c02e366SCtirad Fertr 
232497f1582eSOswald Buddenhagen 		err = add_emu1010_source_mixers(emu);
232599dcab46SMichael Gernoth 		if (err < 0)
232699dcab46SMichael Gernoth 			return err;
23279f4bd5ddSJames Courtier-Dutton 	}
23289f4bd5ddSJames Courtier-Dutton 
2329184c1e2cSJames Courtier-Dutton 	if ( emu->card_capabilities->i2c_adc) {
2330184c1e2cSJames Courtier-Dutton 		err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_i2c_capture_source, emu));
2331184c1e2cSJames Courtier-Dutton 		if (err < 0)
2332184c1e2cSJames Courtier-Dutton 			return err;
2333184c1e2cSJames Courtier-Dutton 
2334536438f1SOswald Buddenhagen 		err = add_ctls(emu, &i2c_volume_ctl,
2335536438f1SOswald Buddenhagen 			       snd_audigy_i2c_volume_ctls,
2336536438f1SOswald Buddenhagen 			       ARRAY_SIZE(snd_audigy_i2c_volume_ctls));
2337184c1e2cSJames Courtier-Dutton 		if (err < 0)
2338184c1e2cSJames Courtier-Dutton 			return err;
2339184c1e2cSJames Courtier-Dutton 	}
2340184c1e2cSJames Courtier-Dutton 
234116950e09STakashi Iwai 	if (emu->card_capabilities->ac97_chip && emu->audigy) {
234216950e09STakashi Iwai 		err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_capture_boost,
234316950e09STakashi Iwai 						     emu));
234416950e09STakashi Iwai 		if (err < 0)
234516950e09STakashi Iwai 			return err;
234616950e09STakashi Iwai 	}
234716950e09STakashi Iwai 
23481da177e4SLinus Torvalds 	return 0;
23491da177e4SLinus Torvalds }
2350