1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
4 * Takashi Iwai <tiwai@suse.de>
5 * Lee Revell <rlrevell@joe-job.com>
6 * James Courtier-Dutton <James@superbug.co.uk>
7 * Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
8 * Creative Labs, Inc.
9 *
10 * Routines for control of EMU10K1 chips / mixer routines
11 */
12
13 #include <linux/time.h>
14 #include <linux/init.h>
15 #include <linux/string.h>
16 #include <sound/core.h>
17 #include <sound/emu10k1.h>
18 #include <linux/delay.h>
19 #include <sound/tlv.h>
20
21 #include "p17v.h"
22
23 #define AC97_ID_STAC9758 0x83847658
24
25 static const DECLARE_TLV_DB_SCALE(snd_audigy_db_scale2, -10350, 50, 1); /* WM8775 gain scale */
26
27
add_ctls(struct snd_emu10k1 * emu,const struct snd_kcontrol_new * tpl,const char * const * ctls,unsigned nctls)28 static int add_ctls(struct snd_emu10k1 *emu, const struct snd_kcontrol_new *tpl,
29 const char * const *ctls, unsigned nctls)
30 {
31 struct snd_kcontrol_new kctl = *tpl;
32 int err;
33
34 for (unsigned i = 0; i < nctls; i++) {
35 kctl.name = ctls[i];
36 kctl.private_value = i;
37 err = snd_ctl_add(emu->card, snd_ctl_new1(&kctl, emu));
38 if (err < 0)
39 return err;
40 }
41 return 0;
42 }
43
44
snd_emu10k1_spdif_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)45 static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
46 {
47 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
48 uinfo->count = 1;
49 return 0;
50 }
51
snd_emu10k1_spdif_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)52 static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol,
53 struct snd_ctl_elem_value *ucontrol)
54 {
55 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
56 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
57
58 /* Limit: emu->spdif_bits */
59 if (idx >= 3)
60 return -EINVAL;
61 ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
62 ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
63 ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
64 ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
65 return 0;
66 }
67
snd_emu10k1_spdif_get_mask(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)68 static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
69 struct snd_ctl_elem_value *ucontrol)
70 {
71 ucontrol->value.iec958.status[0] = 0xff;
72 ucontrol->value.iec958.status[1] = 0xff;
73 ucontrol->value.iec958.status[2] = 0xff;
74 ucontrol->value.iec958.status[3] = 0xff;
75 return 0;
76 }
77
78 #define PAIR_PS(base, one, two, sfx) base " " one sfx, base " " two sfx
79 #define LR_PS(base, sfx) PAIR_PS(base, "Left", "Right", sfx)
80
81 #define ADAT_PS(pfx, sfx) \
82 pfx "ADAT 0" sfx, pfx "ADAT 1" sfx, pfx "ADAT 2" sfx, pfx "ADAT 3" sfx, \
83 pfx "ADAT 4" sfx, pfx "ADAT 5" sfx, pfx "ADAT 6" sfx, pfx "ADAT 7" sfx
84
85 #define PAIR_REGS(base, one, two) \
86 base ## one ## 1, \
87 base ## two ## 1
88
89 #define LR_REGS(base) PAIR_REGS(base, _LEFT, _RIGHT)
90
91 #define ADAT_REGS(base) \
92 base+0, base+1, base+2, base+3, base+4, base+5, base+6, base+7
93
94 /*
95 * List of data sources available for each destination
96 */
97
98 #define DSP_TEXTS \
99 "DSP 0", "DSP 1", "DSP 2", "DSP 3", "DSP 4", "DSP 5", "DSP 6", "DSP 7", \
100 "DSP 8", "DSP 9", "DSP 10", "DSP 11", "DSP 12", "DSP 13", "DSP 14", "DSP 15", \
101 "DSP 16", "DSP 17", "DSP 18", "DSP 19", "DSP 20", "DSP 21", "DSP 22", "DSP 23", \
102 "DSP 24", "DSP 25", "DSP 26", "DSP 27", "DSP 28", "DSP 29", "DSP 30", "DSP 31"
103
104 #define PAIR_TEXTS(base, one, two) PAIR_PS(base, one, two, "")
105 #define LR_TEXTS(base) LR_PS(base, "")
106 #define ADAT_TEXTS(pfx) ADAT_PS(pfx, "")
107
108 #define EMU32_SRC_REGS \
109 EMU_SRC_ALICE_EMU32A, \
110 EMU_SRC_ALICE_EMU32A+1, \
111 EMU_SRC_ALICE_EMU32A+2, \
112 EMU_SRC_ALICE_EMU32A+3, \
113 EMU_SRC_ALICE_EMU32A+4, \
114 EMU_SRC_ALICE_EMU32A+5, \
115 EMU_SRC_ALICE_EMU32A+6, \
116 EMU_SRC_ALICE_EMU32A+7, \
117 EMU_SRC_ALICE_EMU32A+8, \
118 EMU_SRC_ALICE_EMU32A+9, \
119 EMU_SRC_ALICE_EMU32A+0xa, \
120 EMU_SRC_ALICE_EMU32A+0xb, \
121 EMU_SRC_ALICE_EMU32A+0xc, \
122 EMU_SRC_ALICE_EMU32A+0xd, \
123 EMU_SRC_ALICE_EMU32A+0xe, \
124 EMU_SRC_ALICE_EMU32A+0xf, \
125 EMU_SRC_ALICE_EMU32B, \
126 EMU_SRC_ALICE_EMU32B+1, \
127 EMU_SRC_ALICE_EMU32B+2, \
128 EMU_SRC_ALICE_EMU32B+3, \
129 EMU_SRC_ALICE_EMU32B+4, \
130 EMU_SRC_ALICE_EMU32B+5, \
131 EMU_SRC_ALICE_EMU32B+6, \
132 EMU_SRC_ALICE_EMU32B+7, \
133 EMU_SRC_ALICE_EMU32B+8, \
134 EMU_SRC_ALICE_EMU32B+9, \
135 EMU_SRC_ALICE_EMU32B+0xa, \
136 EMU_SRC_ALICE_EMU32B+0xb, \
137 EMU_SRC_ALICE_EMU32B+0xc, \
138 EMU_SRC_ALICE_EMU32B+0xd, \
139 EMU_SRC_ALICE_EMU32B+0xe, \
140 EMU_SRC_ALICE_EMU32B+0xf
141
142 /* 1010 rev1 */
143
144 #define EMU1010_COMMON_TEXTS \
145 "Silence", \
146 PAIR_TEXTS("Dock Mic", "A", "B"), \
147 LR_TEXTS("Dock ADC1"), \
148 LR_TEXTS("Dock ADC2"), \
149 LR_TEXTS("Dock ADC3"), \
150 LR_TEXTS("0202 ADC"), \
151 LR_TEXTS("1010 SPDIF"), \
152 ADAT_TEXTS("1010 ")
153
154 static const char * const emu1010_src_texts[] = {
155 EMU1010_COMMON_TEXTS,
156 DSP_TEXTS,
157 };
158
159 static const unsigned short emu1010_src_regs[] = {
160 EMU_SRC_SILENCE,
161 PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
162 LR_REGS(EMU_SRC_DOCK_ADC1),
163 LR_REGS(EMU_SRC_DOCK_ADC2),
164 LR_REGS(EMU_SRC_DOCK_ADC3),
165 LR_REGS(EMU_SRC_HAMOA_ADC),
166 LR_REGS(EMU_SRC_HANA_SPDIF),
167 ADAT_REGS(EMU_SRC_HANA_ADAT),
168 EMU32_SRC_REGS,
169 };
170 static_assert(ARRAY_SIZE(emu1010_src_regs) == ARRAY_SIZE(emu1010_src_texts));
171
172 /* 1010 rev2 */
173
174 #define EMU1010b_COMMON_TEXTS \
175 "Silence", \
176 PAIR_TEXTS("Dock Mic", "A", "B"), \
177 LR_TEXTS("Dock ADC1"), \
178 LR_TEXTS("Dock ADC2"), \
179 LR_TEXTS("0202 ADC"), \
180 LR_TEXTS("Dock SPDIF"), \
181 LR_TEXTS("1010 SPDIF"), \
182 ADAT_TEXTS("Dock "), \
183 ADAT_TEXTS("1010 ")
184
185 static const char * const emu1010b_src_texts[] = {
186 EMU1010b_COMMON_TEXTS,
187 DSP_TEXTS,
188 };
189
190 static const unsigned short emu1010b_src_regs[] = {
191 EMU_SRC_SILENCE,
192 PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
193 LR_REGS(EMU_SRC_DOCK_ADC1),
194 LR_REGS(EMU_SRC_DOCK_ADC2),
195 LR_REGS(EMU_SRC_HAMOA_ADC),
196 LR_REGS(EMU_SRC_MDOCK_SPDIF),
197 LR_REGS(EMU_SRC_HANA_SPDIF),
198 ADAT_REGS(EMU_SRC_MDOCK_ADAT),
199 ADAT_REGS(EMU_SRC_HANA_ADAT),
200 EMU32_SRC_REGS,
201 };
202 static_assert(ARRAY_SIZE(emu1010b_src_regs) == ARRAY_SIZE(emu1010b_src_texts));
203
204 /* 1616(m) cardbus */
205
206 #define EMU1616_COMMON_TEXTS \
207 "Silence", \
208 PAIR_TEXTS("Mic", "A", "B"), \
209 LR_TEXTS("ADC1"), \
210 LR_TEXTS("ADC2"), \
211 LR_TEXTS("SPDIF"), \
212 ADAT_TEXTS("")
213
214 static const char * const emu1616_src_texts[] = {
215 EMU1616_COMMON_TEXTS,
216 DSP_TEXTS,
217 };
218
219 static const unsigned short emu1616_src_regs[] = {
220 EMU_SRC_SILENCE,
221 PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
222 LR_REGS(EMU_SRC_DOCK_ADC1),
223 LR_REGS(EMU_SRC_DOCK_ADC2),
224 LR_REGS(EMU_SRC_MDOCK_SPDIF),
225 ADAT_REGS(EMU_SRC_MDOCK_ADAT),
226 EMU32_SRC_REGS,
227 };
228 static_assert(ARRAY_SIZE(emu1616_src_regs) == ARRAY_SIZE(emu1616_src_texts));
229
230 /* 0404 rev1 & rev2 */
231
232 #define EMU0404_COMMON_TEXTS \
233 "Silence", \
234 LR_TEXTS("ADC"), \
235 LR_TEXTS("SPDIF")
236
237 static const char * const emu0404_src_texts[] = {
238 EMU0404_COMMON_TEXTS,
239 DSP_TEXTS,
240 };
241
242 static const unsigned short emu0404_src_regs[] = {
243 EMU_SRC_SILENCE,
244 LR_REGS(EMU_SRC_HAMOA_ADC),
245 LR_REGS(EMU_SRC_HANA_SPDIF),
246 EMU32_SRC_REGS,
247 };
248 static_assert(ARRAY_SIZE(emu0404_src_regs) == ARRAY_SIZE(emu0404_src_texts));
249
250 /*
251 * Data destinations - physical EMU outputs.
252 * Each destination has an enum mixer control to choose a data source
253 */
254
255 #define LR_CTLS(base) LR_PS(base, " Playback Enum")
256 #define ADAT_CTLS(pfx) ADAT_PS(pfx, " Playback Enum")
257
258 /* 1010 rev1 */
259
260 static const char * const emu1010_output_texts[] = {
261 LR_CTLS("Dock DAC1"),
262 LR_CTLS("Dock DAC2"),
263 LR_CTLS("Dock DAC3"),
264 LR_CTLS("Dock DAC4"),
265 LR_CTLS("Dock Phones"),
266 LR_CTLS("Dock SPDIF"),
267 LR_CTLS("0202 DAC"),
268 LR_CTLS("1010 SPDIF"),
269 ADAT_CTLS("1010 "),
270 };
271 static_assert(ARRAY_SIZE(emu1010_output_texts) <= NUM_OUTPUT_DESTS);
272
273 static const unsigned short emu1010_output_dst[] = {
274 LR_REGS(EMU_DST_DOCK_DAC1),
275 LR_REGS(EMU_DST_DOCK_DAC2),
276 LR_REGS(EMU_DST_DOCK_DAC3),
277 LR_REGS(EMU_DST_DOCK_DAC4),
278 LR_REGS(EMU_DST_DOCK_PHONES),
279 LR_REGS(EMU_DST_DOCK_SPDIF),
280 LR_REGS(EMU_DST_HAMOA_DAC),
281 LR_REGS(EMU_DST_HANA_SPDIF),
282 ADAT_REGS(EMU_DST_HANA_ADAT),
283 };
284 static_assert(ARRAY_SIZE(emu1010_output_dst) == ARRAY_SIZE(emu1010_output_texts));
285
286 static const unsigned short emu1010_output_dflt[] = {
287 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
288 EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
289 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5,
290 EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
291 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
292 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
293 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
294 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
295 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
296 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
297 };
298 static_assert(ARRAY_SIZE(emu1010_output_dflt) == ARRAY_SIZE(emu1010_output_dst));
299
300 /* 1010 rev2 */
301
302 static const char * const snd_emu1010b_output_texts[] = {
303 LR_CTLS("Dock DAC1"),
304 LR_CTLS("Dock DAC2"),
305 LR_CTLS("Dock DAC3"),
306 LR_CTLS("Dock SPDIF"),
307 ADAT_CTLS("Dock "),
308 LR_CTLS("0202 DAC"),
309 LR_CTLS("1010 SPDIF"),
310 ADAT_CTLS("1010 "),
311 };
312 static_assert(ARRAY_SIZE(snd_emu1010b_output_texts) <= NUM_OUTPUT_DESTS);
313
314 static const unsigned short emu1010b_output_dst[] = {
315 LR_REGS(EMU_DST_DOCK_DAC1),
316 LR_REGS(EMU_DST_DOCK_DAC2),
317 LR_REGS(EMU_DST_DOCK_DAC3),
318 LR_REGS(EMU_DST_MDOCK_SPDIF),
319 ADAT_REGS(EMU_DST_MDOCK_ADAT),
320 LR_REGS(EMU_DST_HAMOA_DAC),
321 LR_REGS(EMU_DST_HANA_SPDIF),
322 ADAT_REGS(EMU_DST_HANA_ADAT),
323 };
324 static_assert(ARRAY_SIZE(emu1010b_output_dst) == ARRAY_SIZE(snd_emu1010b_output_texts));
325
326 static const unsigned short emu1010b_output_dflt[] = {
327 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
328 EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
329 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5,
330 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
331 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
332 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
333 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
334 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
335 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
336 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
337 };
338
339 /* 1616(m) cardbus */
340
341 static const char * const snd_emu1616_output_texts[] = {
342 LR_CTLS("Dock DAC1"),
343 LR_CTLS("Dock DAC2"),
344 LR_CTLS("Dock DAC3"),
345 LR_CTLS("Dock SPDIF"),
346 ADAT_CTLS("Dock "),
347 LR_CTLS("Mana DAC"),
348 };
349 static_assert(ARRAY_SIZE(snd_emu1616_output_texts) <= NUM_OUTPUT_DESTS);
350
351 static const unsigned short emu1616_output_dst[] = {
352 LR_REGS(EMU_DST_DOCK_DAC1),
353 LR_REGS(EMU_DST_DOCK_DAC2),
354 LR_REGS(EMU_DST_DOCK_DAC3),
355 LR_REGS(EMU_DST_MDOCK_SPDIF),
356 ADAT_REGS(EMU_DST_MDOCK_ADAT),
357 EMU_DST_MANA_DAC_LEFT, EMU_DST_MANA_DAC_RIGHT,
358 };
359 static_assert(ARRAY_SIZE(emu1616_output_dst) == ARRAY_SIZE(snd_emu1616_output_texts));
360
361 static const unsigned short emu1616_output_dflt[] = {
362 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
363 EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
364 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5,
365 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
366 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
367 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
368 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
369 };
370 static_assert(ARRAY_SIZE(emu1616_output_dflt) == ARRAY_SIZE(emu1616_output_dst));
371
372 /* 0404 rev1 & rev2 */
373
374 static const char * const snd_emu0404_output_texts[] = {
375 LR_CTLS("DAC"),
376 LR_CTLS("SPDIF"),
377 };
378 static_assert(ARRAY_SIZE(snd_emu0404_output_texts) <= NUM_OUTPUT_DESTS);
379
380 static const unsigned short emu0404_output_dst[] = {
381 LR_REGS(EMU_DST_HAMOA_DAC),
382 LR_REGS(EMU_DST_HANA_SPDIF),
383 };
384 static_assert(ARRAY_SIZE(emu0404_output_dst) == ARRAY_SIZE(snd_emu0404_output_texts));
385
386 static const unsigned short emu0404_output_dflt[] = {
387 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
388 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
389 };
390 static_assert(ARRAY_SIZE(emu0404_output_dflt) == ARRAY_SIZE(emu0404_output_dst));
391
392 /*
393 * Data destinations - FPGA outputs going to Alice2 (Audigy) for
394 * capture (EMU32 + I2S links)
395 * Each destination has an enum mixer control to choose a data source
396 */
397
398 static const char * const emu1010_input_texts[] = {
399 "DSP 0 Capture Enum",
400 "DSP 1 Capture Enum",
401 "DSP 2 Capture Enum",
402 "DSP 3 Capture Enum",
403 "DSP 4 Capture Enum",
404 "DSP 5 Capture Enum",
405 "DSP 6 Capture Enum",
406 "DSP 7 Capture Enum",
407 "DSP 8 Capture Enum",
408 "DSP 9 Capture Enum",
409 "DSP A Capture Enum",
410 "DSP B Capture Enum",
411 "DSP C Capture Enum",
412 "DSP D Capture Enum",
413 "DSP E Capture Enum",
414 "DSP F Capture Enum",
415 /* These exist only on rev1 EMU1010 cards. */
416 "DSP 10 Capture Enum",
417 "DSP 11 Capture Enum",
418 "DSP 12 Capture Enum",
419 "DSP 13 Capture Enum",
420 "DSP 14 Capture Enum",
421 "DSP 15 Capture Enum",
422 };
423 static_assert(ARRAY_SIZE(emu1010_input_texts) <= NUM_INPUT_DESTS);
424
425 static const unsigned short emu1010_input_dst[] = {
426 EMU_DST_ALICE2_EMU32_0,
427 EMU_DST_ALICE2_EMU32_1,
428 EMU_DST_ALICE2_EMU32_2,
429 EMU_DST_ALICE2_EMU32_3,
430 EMU_DST_ALICE2_EMU32_4,
431 EMU_DST_ALICE2_EMU32_5,
432 EMU_DST_ALICE2_EMU32_6,
433 EMU_DST_ALICE2_EMU32_7,
434 EMU_DST_ALICE2_EMU32_8,
435 EMU_DST_ALICE2_EMU32_9,
436 EMU_DST_ALICE2_EMU32_A,
437 EMU_DST_ALICE2_EMU32_B,
438 EMU_DST_ALICE2_EMU32_C,
439 EMU_DST_ALICE2_EMU32_D,
440 EMU_DST_ALICE2_EMU32_E,
441 EMU_DST_ALICE2_EMU32_F,
442 /* These exist only on rev1 EMU1010 cards. */
443 EMU_DST_ALICE_I2S0_LEFT,
444 EMU_DST_ALICE_I2S0_RIGHT,
445 EMU_DST_ALICE_I2S1_LEFT,
446 EMU_DST_ALICE_I2S1_RIGHT,
447 EMU_DST_ALICE_I2S2_LEFT,
448 EMU_DST_ALICE_I2S2_RIGHT,
449 };
450 static_assert(ARRAY_SIZE(emu1010_input_dst) == ARRAY_SIZE(emu1010_input_texts));
451
452 static const unsigned short emu1010_input_dflt[] = {
453 EMU_SRC_DOCK_MIC_A1,
454 EMU_SRC_DOCK_MIC_B1,
455 EMU_SRC_HAMOA_ADC_LEFT1,
456 EMU_SRC_HAMOA_ADC_RIGHT1,
457 EMU_SRC_DOCK_ADC1_LEFT1,
458 EMU_SRC_DOCK_ADC1_RIGHT1,
459 EMU_SRC_DOCK_ADC2_LEFT1,
460 EMU_SRC_DOCK_ADC2_RIGHT1,
461 /* Pavel Hofman - setting defaults for all capture channels.
462 * Defaults only, users will set their own values anyways, let's
463 * just copy/paste. */
464 EMU_SRC_DOCK_MIC_A1,
465 EMU_SRC_DOCK_MIC_B1,
466 EMU_SRC_HAMOA_ADC_LEFT1,
467 EMU_SRC_HAMOA_ADC_RIGHT1,
468 EMU_SRC_DOCK_ADC1_LEFT1,
469 EMU_SRC_DOCK_ADC1_RIGHT1,
470 EMU_SRC_DOCK_ADC2_LEFT1,
471 EMU_SRC_DOCK_ADC2_RIGHT1,
472
473 EMU_SRC_DOCK_ADC1_LEFT1,
474 EMU_SRC_DOCK_ADC1_RIGHT1,
475 EMU_SRC_DOCK_ADC2_LEFT1,
476 EMU_SRC_DOCK_ADC2_RIGHT1,
477 EMU_SRC_DOCK_ADC3_LEFT1,
478 EMU_SRC_DOCK_ADC3_RIGHT1,
479 };
480 static_assert(ARRAY_SIZE(emu1010_input_dflt) == ARRAY_SIZE(emu1010_input_dst));
481
482 static const unsigned short emu0404_input_dflt[] = {
483 EMU_SRC_HAMOA_ADC_LEFT1,
484 EMU_SRC_HAMOA_ADC_RIGHT1,
485 EMU_SRC_SILENCE,
486 EMU_SRC_SILENCE,
487 EMU_SRC_SILENCE,
488 EMU_SRC_SILENCE,
489 EMU_SRC_SILENCE,
490 EMU_SRC_SILENCE,
491 EMU_SRC_HANA_SPDIF_LEFT1,
492 EMU_SRC_HANA_SPDIF_RIGHT1,
493 EMU_SRC_SILENCE,
494 EMU_SRC_SILENCE,
495 EMU_SRC_SILENCE,
496 EMU_SRC_SILENCE,
497 EMU_SRC_SILENCE,
498 EMU_SRC_SILENCE,
499 };
500
501 struct snd_emu1010_routing_info {
502 const char * const *src_texts;
503 const char * const *out_texts;
504 const unsigned short *src_regs;
505 const unsigned short *out_regs;
506 const unsigned short *in_regs;
507 const unsigned short *out_dflts;
508 const unsigned short *in_dflts;
509 unsigned n_srcs;
510 unsigned n_outs;
511 unsigned n_ins;
512 };
513
514 static const struct snd_emu1010_routing_info emu1010_routing_info[] = {
515 {
516 /* rev1 1010 */
517 .src_regs = emu1010_src_regs,
518 .src_texts = emu1010_src_texts,
519 .n_srcs = ARRAY_SIZE(emu1010_src_texts),
520
521 .out_dflts = emu1010_output_dflt,
522 .out_regs = emu1010_output_dst,
523 .out_texts = emu1010_output_texts,
524 .n_outs = ARRAY_SIZE(emu1010_output_dst),
525
526 .in_dflts = emu1010_input_dflt,
527 .in_regs = emu1010_input_dst,
528 .n_ins = ARRAY_SIZE(emu1010_input_dst),
529 },
530 {
531 /* rev2 1010 */
532 .src_regs = emu1010b_src_regs,
533 .src_texts = emu1010b_src_texts,
534 .n_srcs = ARRAY_SIZE(emu1010b_src_texts),
535
536 .out_dflts = emu1010b_output_dflt,
537 .out_regs = emu1010b_output_dst,
538 .out_texts = snd_emu1010b_output_texts,
539 .n_outs = ARRAY_SIZE(emu1010b_output_dst),
540
541 .in_dflts = emu1010_input_dflt,
542 .in_regs = emu1010_input_dst,
543 .n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
544 },
545 {
546 /* 1616(m) cardbus */
547 .src_regs = emu1616_src_regs,
548 .src_texts = emu1616_src_texts,
549 .n_srcs = ARRAY_SIZE(emu1616_src_texts),
550
551 .out_dflts = emu1616_output_dflt,
552 .out_regs = emu1616_output_dst,
553 .out_texts = snd_emu1616_output_texts,
554 .n_outs = ARRAY_SIZE(emu1616_output_dst),
555
556 .in_dflts = emu1010_input_dflt,
557 .in_regs = emu1010_input_dst,
558 .n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
559 },
560 {
561 /* 0404 */
562 .src_regs = emu0404_src_regs,
563 .src_texts = emu0404_src_texts,
564 .n_srcs = ARRAY_SIZE(emu0404_src_texts),
565
566 .out_dflts = emu0404_output_dflt,
567 .out_regs = emu0404_output_dst,
568 .out_texts = snd_emu0404_output_texts,
569 .n_outs = ARRAY_SIZE(emu0404_output_dflt),
570
571 .in_dflts = emu0404_input_dflt,
572 .in_regs = emu1010_input_dst,
573 .n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
574 },
575 };
576
emu1010_idx(struct snd_emu10k1 * emu)577 static unsigned emu1010_idx(struct snd_emu10k1 *emu)
578 {
579 return emu->card_capabilities->emu_model - 1;
580 }
581
snd_emu1010_output_source_apply(struct snd_emu10k1 * emu,int channel,int src)582 static void snd_emu1010_output_source_apply(struct snd_emu10k1 *emu,
583 int channel, int src)
584 {
585 const struct snd_emu1010_routing_info *emu_ri =
586 &emu1010_routing_info[emu1010_idx(emu)];
587
588 snd_emu1010_fpga_link_dst_src_write(emu,
589 emu_ri->out_regs[channel], emu_ri->src_regs[src]);
590 }
591
snd_emu1010_input_source_apply(struct snd_emu10k1 * emu,int channel,int src)592 static void snd_emu1010_input_source_apply(struct snd_emu10k1 *emu,
593 int channel, int src)
594 {
595 const struct snd_emu1010_routing_info *emu_ri =
596 &emu1010_routing_info[emu1010_idx(emu)];
597
598 snd_emu1010_fpga_link_dst_src_write(emu,
599 emu_ri->in_regs[channel], emu_ri->src_regs[src]);
600 }
601
snd_emu1010_apply_sources(struct snd_emu10k1 * emu)602 static void snd_emu1010_apply_sources(struct snd_emu10k1 *emu)
603 {
604 const struct snd_emu1010_routing_info *emu_ri =
605 &emu1010_routing_info[emu1010_idx(emu)];
606
607 for (unsigned i = 0; i < emu_ri->n_outs; i++)
608 snd_emu1010_output_source_apply(
609 emu, i, emu->emu1010.output_source[i]);
610 for (unsigned i = 0; i < emu_ri->n_ins; i++)
611 snd_emu1010_input_source_apply(
612 emu, i, emu->emu1010.input_source[i]);
613 }
614
emu1010_map_source(const struct snd_emu1010_routing_info * emu_ri,unsigned val)615 static u8 emu1010_map_source(const struct snd_emu1010_routing_info *emu_ri,
616 unsigned val)
617 {
618 for (unsigned i = 0; i < emu_ri->n_srcs; i++)
619 if (val == emu_ri->src_regs[i])
620 return i;
621 return 0;
622 }
623
snd_emu1010_input_output_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)624 static int snd_emu1010_input_output_source_info(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_info *uinfo)
626 {
627 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
628 const struct snd_emu1010_routing_info *emu_ri =
629 &emu1010_routing_info[emu1010_idx(emu)];
630
631 return snd_ctl_enum_info(uinfo, 1, emu_ri->n_srcs, emu_ri->src_texts);
632 }
633
snd_emu1010_output_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)634 static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_value *ucontrol)
636 {
637 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
638 const struct snd_emu1010_routing_info *emu_ri =
639 &emu1010_routing_info[emu1010_idx(emu)];
640 unsigned channel = kcontrol->private_value;
641
642 if (channel >= emu_ri->n_outs)
643 return -EINVAL;
644 ucontrol->value.enumerated.item[0] = emu->emu1010.output_source[channel];
645 return 0;
646 }
647
snd_emu1010_output_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)648 static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650 {
651 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
652 const struct snd_emu1010_routing_info *emu_ri =
653 &emu1010_routing_info[emu1010_idx(emu)];
654 unsigned val = ucontrol->value.enumerated.item[0];
655 unsigned channel = kcontrol->private_value;
656 int change;
657
658 if (val >= emu_ri->n_srcs)
659 return -EINVAL;
660 if (channel >= emu_ri->n_outs)
661 return -EINVAL;
662 change = (emu->emu1010.output_source[channel] != val);
663 if (change) {
664 emu->emu1010.output_source[channel] = val;
665 snd_emu1010_fpga_lock(emu);
666 snd_emu1010_output_source_apply(emu, channel, val);
667 snd_emu1010_fpga_unlock(emu);
668 }
669 return change;
670 }
671
672 static const struct snd_kcontrol_new emu1010_output_source_ctl = {
673 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
674 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
675 .info = snd_emu1010_input_output_source_info,
676 .get = snd_emu1010_output_source_get,
677 .put = snd_emu1010_output_source_put
678 };
679
snd_emu1010_input_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)680 static int snd_emu1010_input_source_get(struct snd_kcontrol *kcontrol,
681 struct snd_ctl_elem_value *ucontrol)
682 {
683 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
684 const struct snd_emu1010_routing_info *emu_ri =
685 &emu1010_routing_info[emu1010_idx(emu)];
686 unsigned channel = kcontrol->private_value;
687
688 if (channel >= emu_ri->n_ins)
689 return -EINVAL;
690 ucontrol->value.enumerated.item[0] = emu->emu1010.input_source[channel];
691 return 0;
692 }
693
snd_emu1010_input_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)694 static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol,
695 struct snd_ctl_elem_value *ucontrol)
696 {
697 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
698 const struct snd_emu1010_routing_info *emu_ri =
699 &emu1010_routing_info[emu1010_idx(emu)];
700 unsigned val = ucontrol->value.enumerated.item[0];
701 unsigned channel = kcontrol->private_value;
702 int change;
703
704 if (val >= emu_ri->n_srcs)
705 return -EINVAL;
706 if (channel >= emu_ri->n_ins)
707 return -EINVAL;
708 change = (emu->emu1010.input_source[channel] != val);
709 if (change) {
710 emu->emu1010.input_source[channel] = val;
711 snd_emu1010_fpga_lock(emu);
712 snd_emu1010_input_source_apply(emu, channel, val);
713 snd_emu1010_fpga_unlock(emu);
714 }
715 return change;
716 }
717
718 static const struct snd_kcontrol_new emu1010_input_source_ctl = {
719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
720 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
721 .info = snd_emu1010_input_output_source_info,
722 .get = snd_emu1010_input_source_get,
723 .put = snd_emu1010_input_source_put
724 };
725
add_emu1010_source_mixers(struct snd_emu10k1 * emu)726 static int add_emu1010_source_mixers(struct snd_emu10k1 *emu)
727 {
728 const struct snd_emu1010_routing_info *emu_ri =
729 &emu1010_routing_info[emu1010_idx(emu)];
730 int err;
731
732 err = add_ctls(emu, &emu1010_output_source_ctl,
733 emu_ri->out_texts, emu_ri->n_outs);
734 if (err < 0)
735 return err;
736 err = add_ctls(emu, &emu1010_input_source_ctl,
737 emu1010_input_texts, emu_ri->n_ins);
738 return err;
739 }
740
741
742 static const char * const snd_emu1010_adc_pads[] = {
743 "ADC1 14dB PAD 0202 Capture Switch",
744 "ADC1 14dB PAD Audio Dock Capture Switch",
745 "ADC2 14dB PAD Audio Dock Capture Switch",
746 "ADC3 14dB PAD Audio Dock Capture Switch",
747 };
748
749 static const unsigned short snd_emu1010_adc_pad_regs[] = {
750 EMU_HANA_0202_ADC_PAD1,
751 EMU_HANA_DOCK_ADC_PAD1,
752 EMU_HANA_DOCK_ADC_PAD2,
753 EMU_HANA_DOCK_ADC_PAD3,
754 };
755
756 #define snd_emu1010_adc_pads_info snd_ctl_boolean_mono_info
757
snd_emu1010_adc_pads_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)758 static int snd_emu1010_adc_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
759 {
760 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
761 unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value];
762
763 ucontrol->value.integer.value[0] = (emu->emu1010.adc_pads & mask) ? 1 : 0;
764 return 0;
765 }
766
snd_emu1010_adc_pads_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)767 static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
768 {
769 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
770 unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value];
771 unsigned int val, cache;
772 int change;
773
774 val = ucontrol->value.integer.value[0];
775 cache = emu->emu1010.adc_pads;
776 if (val == 1)
777 cache = cache | mask;
778 else
779 cache = cache & ~mask;
780 change = (cache != emu->emu1010.adc_pads);
781 if (change) {
782 snd_emu1010_fpga_write_lock(emu, EMU_HANA_ADC_PADS, cache );
783 emu->emu1010.adc_pads = cache;
784 }
785
786 return change;
787 }
788
789 static const struct snd_kcontrol_new emu1010_adc_pads_ctl = {
790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
791 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
792 .info = snd_emu1010_adc_pads_info,
793 .get = snd_emu1010_adc_pads_get,
794 .put = snd_emu1010_adc_pads_put
795 };
796
797
798 static const char * const snd_emu1010_dac_pads[] = {
799 "DAC1 0202 14dB PAD Playback Switch",
800 "DAC1 Audio Dock 14dB PAD Playback Switch",
801 "DAC2 Audio Dock 14dB PAD Playback Switch",
802 "DAC3 Audio Dock 14dB PAD Playback Switch",
803 "DAC4 Audio Dock 14dB PAD Playback Switch",
804 };
805
806 static const unsigned short snd_emu1010_dac_regs[] = {
807 EMU_HANA_0202_DAC_PAD1,
808 EMU_HANA_DOCK_DAC_PAD1,
809 EMU_HANA_DOCK_DAC_PAD2,
810 EMU_HANA_DOCK_DAC_PAD3,
811 EMU_HANA_DOCK_DAC_PAD4,
812 };
813
814 #define snd_emu1010_dac_pads_info snd_ctl_boolean_mono_info
815
snd_emu1010_dac_pads_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)816 static int snd_emu1010_dac_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
817 {
818 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
819 unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value];
820
821 ucontrol->value.integer.value[0] = (emu->emu1010.dac_pads & mask) ? 1 : 0;
822 return 0;
823 }
824
snd_emu1010_dac_pads_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)825 static int snd_emu1010_dac_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
826 {
827 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
828 unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value];
829 unsigned int val, cache;
830 int change;
831
832 val = ucontrol->value.integer.value[0];
833 cache = emu->emu1010.dac_pads;
834 if (val == 1)
835 cache = cache | mask;
836 else
837 cache = cache & ~mask;
838 change = (cache != emu->emu1010.dac_pads);
839 if (change) {
840 snd_emu1010_fpga_write_lock(emu, EMU_HANA_DAC_PADS, cache );
841 emu->emu1010.dac_pads = cache;
842 }
843
844 return change;
845 }
846
847 static const struct snd_kcontrol_new emu1010_dac_pads_ctl = {
848 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
849 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
850 .info = snd_emu1010_dac_pads_info,
851 .get = snd_emu1010_dac_pads_get,
852 .put = snd_emu1010_dac_pads_put
853 };
854
855
856 struct snd_emu1010_pads_info {
857 const char * const *adc_ctls, * const *dac_ctls;
858 unsigned n_adc_ctls, n_dac_ctls;
859 };
860
861 static const struct snd_emu1010_pads_info emu1010_pads_info[] = {
862 {
863 /* rev1 1010 */
864 .adc_ctls = snd_emu1010_adc_pads,
865 .n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads),
866 .dac_ctls = snd_emu1010_dac_pads,
867 .n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads),
868 },
869 {
870 /* rev2 1010 */
871 .adc_ctls = snd_emu1010_adc_pads,
872 .n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads) - 1,
873 .dac_ctls = snd_emu1010_dac_pads,
874 .n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads) - 1,
875 },
876 {
877 /* 1616(m) cardbus */
878 .adc_ctls = snd_emu1010_adc_pads + 1,
879 .n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads) - 2,
880 .dac_ctls = snd_emu1010_dac_pads + 1,
881 .n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads) - 2,
882 },
883 {
884 /* 0404 */
885 .adc_ctls = NULL,
886 .n_adc_ctls = 0,
887 .dac_ctls = NULL,
888 .n_dac_ctls = 0,
889 },
890 };
891
892 static const char * const emu1010_clock_texts[] = {
893 "44100", "48000", "SPDIF", "ADAT", "Dock", "BNC"
894 };
895
896 static const u8 emu1010_clock_vals[] = {
897 EMU_HANA_WCLOCK_INT_44_1K,
898 EMU_HANA_WCLOCK_INT_48K,
899 EMU_HANA_WCLOCK_HANA_SPDIF_IN,
900 EMU_HANA_WCLOCK_HANA_ADAT_IN,
901 EMU_HANA_WCLOCK_2ND_HANA,
902 EMU_HANA_WCLOCK_SYNC_BNC,
903 };
904
905 static const char * const emu0404_clock_texts[] = {
906 "44100", "48000", "SPDIF", "BNC"
907 };
908
909 static const u8 emu0404_clock_vals[] = {
910 EMU_HANA_WCLOCK_INT_44_1K,
911 EMU_HANA_WCLOCK_INT_48K,
912 EMU_HANA_WCLOCK_HANA_SPDIF_IN,
913 EMU_HANA_WCLOCK_SYNC_BNC,
914 };
915
916 struct snd_emu1010_clock_info {
917 const char * const *texts;
918 const u8 *vals;
919 unsigned num;
920 };
921
922 static const struct snd_emu1010_clock_info emu1010_clock_info[] = {
923 {
924 // rev1 1010
925 .texts = emu1010_clock_texts,
926 .vals = emu1010_clock_vals,
927 .num = ARRAY_SIZE(emu1010_clock_vals),
928 },
929 {
930 // rev2 1010
931 .texts = emu1010_clock_texts,
932 .vals = emu1010_clock_vals,
933 .num = ARRAY_SIZE(emu1010_clock_vals) - 1,
934 },
935 {
936 // 1616(m) CardBus
937 .texts = emu1010_clock_texts,
938 // TODO: determine what is actually available.
939 // Pedantically, *every* source comes from the 2nd FPGA, as the
940 // card itself has no own (digital) audio ports. The user manual
941 // claims that ADAT and S/PDIF clock sources are separate, which
942 // can mean two things: either E-MU mapped the dock's sources to
943 // the primary ones, or they determine the meaning of the "Dock"
944 // source depending on how the ports are actually configured
945 // (which the 2nd FPGA must be doing anyway).
946 .vals = emu1010_clock_vals,
947 .num = ARRAY_SIZE(emu1010_clock_vals),
948 },
949 {
950 // 0404
951 .texts = emu0404_clock_texts,
952 .vals = emu0404_clock_vals,
953 .num = ARRAY_SIZE(emu0404_clock_vals),
954 },
955 };
956
snd_emu1010_clock_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)957 static int snd_emu1010_clock_source_info(struct snd_kcontrol *kcontrol,
958 struct snd_ctl_elem_info *uinfo)
959 {
960 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
961 const struct snd_emu1010_clock_info *emu_ci =
962 &emu1010_clock_info[emu1010_idx(emu)];
963
964 return snd_ctl_enum_info(uinfo, 1, emu_ci->num, emu_ci->texts);
965 }
966
snd_emu1010_clock_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)967 static int snd_emu1010_clock_source_get(struct snd_kcontrol *kcontrol,
968 struct snd_ctl_elem_value *ucontrol)
969 {
970 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
971
972 ucontrol->value.enumerated.item[0] = emu->emu1010.clock_source;
973 return 0;
974 }
975
snd_emu1010_clock_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)976 static int snd_emu1010_clock_source_put(struct snd_kcontrol *kcontrol,
977 struct snd_ctl_elem_value *ucontrol)
978 {
979 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
980 const struct snd_emu1010_clock_info *emu_ci =
981 &emu1010_clock_info[emu1010_idx(emu)];
982 unsigned int val;
983 int change = 0;
984
985 val = ucontrol->value.enumerated.item[0] ;
986 if (val >= emu_ci->num)
987 return -EINVAL;
988 snd_emu1010_fpga_lock(emu);
989 spin_lock_irq(&emu->reg_lock);
990 change = (emu->emu1010.clock_source != val);
991 if (change) {
992 emu->emu1010.clock_source = val;
993 emu->emu1010.wclock = emu_ci->vals[val];
994 snd_emu1010_update_clock(emu);
995
996 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE);
997 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, emu->emu1010.wclock);
998 spin_unlock_irq(&emu->reg_lock);
999
1000 msleep(10); // Allow DLL to settle
1001 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
1002 } else {
1003 spin_unlock_irq(&emu->reg_lock);
1004 }
1005 snd_emu1010_fpga_unlock(emu);
1006 return change;
1007 }
1008
1009 static const struct snd_kcontrol_new snd_emu1010_clock_source =
1010 {
1011 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1012 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1013 .name = "Clock Source",
1014 .count = 1,
1015 .info = snd_emu1010_clock_source_info,
1016 .get = snd_emu1010_clock_source_get,
1017 .put = snd_emu1010_clock_source_put
1018 };
1019
snd_emu1010_clock_fallback_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1020 static int snd_emu1010_clock_fallback_info(struct snd_kcontrol *kcontrol,
1021 struct snd_ctl_elem_info *uinfo)
1022 {
1023 static const char * const texts[2] = {
1024 "44100", "48000"
1025 };
1026
1027 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1028 }
1029
snd_emu1010_clock_fallback_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1030 static int snd_emu1010_clock_fallback_get(struct snd_kcontrol *kcontrol,
1031 struct snd_ctl_elem_value *ucontrol)
1032 {
1033 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1034
1035 ucontrol->value.enumerated.item[0] = emu->emu1010.clock_fallback;
1036 return 0;
1037 }
1038
snd_emu1010_clock_fallback_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1039 static int snd_emu1010_clock_fallback_put(struct snd_kcontrol *kcontrol,
1040 struct snd_ctl_elem_value *ucontrol)
1041 {
1042 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1043 unsigned int val = ucontrol->value.enumerated.item[0];
1044 int change;
1045
1046 if (val >= 2)
1047 return -EINVAL;
1048 change = (emu->emu1010.clock_fallback != val);
1049 if (change) {
1050 emu->emu1010.clock_fallback = val;
1051 snd_emu1010_fpga_write_lock(emu, EMU_HANA_DEFCLOCK, 1 - val);
1052 }
1053 return change;
1054 }
1055
1056 static const struct snd_kcontrol_new snd_emu1010_clock_fallback =
1057 {
1058 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1059 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1060 .name = "Clock Fallback",
1061 .count = 1,
1062 .info = snd_emu1010_clock_fallback_info,
1063 .get = snd_emu1010_clock_fallback_get,
1064 .put = snd_emu1010_clock_fallback_put
1065 };
1066
snd_emu1010_optical_out_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1067 static int snd_emu1010_optical_out_info(struct snd_kcontrol *kcontrol,
1068 struct snd_ctl_elem_info *uinfo)
1069 {
1070 static const char * const texts[2] = {
1071 "SPDIF", "ADAT"
1072 };
1073
1074 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1075 }
1076
snd_emu1010_optical_out_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1077 static int snd_emu1010_optical_out_get(struct snd_kcontrol *kcontrol,
1078 struct snd_ctl_elem_value *ucontrol)
1079 {
1080 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1081
1082 ucontrol->value.enumerated.item[0] = emu->emu1010.optical_out;
1083 return 0;
1084 }
1085
snd_emu1010_optical_out_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1086 static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol,
1087 struct snd_ctl_elem_value *ucontrol)
1088 {
1089 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1090 unsigned int val;
1091 u32 tmp;
1092 int change = 0;
1093
1094 val = ucontrol->value.enumerated.item[0];
1095 /* Limit: uinfo->value.enumerated.items = 2; */
1096 if (val >= 2)
1097 return -EINVAL;
1098 change = (emu->emu1010.optical_out != val);
1099 if (change) {
1100 emu->emu1010.optical_out = val;
1101 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) |
1102 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF);
1103 snd_emu1010_fpga_write_lock(emu, EMU_HANA_OPTICAL_TYPE, tmp);
1104 }
1105 return change;
1106 }
1107
1108 static const struct snd_kcontrol_new snd_emu1010_optical_out = {
1109 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1110 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1111 .name = "Optical Output Mode",
1112 .count = 1,
1113 .info = snd_emu1010_optical_out_info,
1114 .get = snd_emu1010_optical_out_get,
1115 .put = snd_emu1010_optical_out_put
1116 };
1117
snd_emu1010_optical_in_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1118 static int snd_emu1010_optical_in_info(struct snd_kcontrol *kcontrol,
1119 struct snd_ctl_elem_info *uinfo)
1120 {
1121 static const char * const texts[2] = {
1122 "SPDIF", "ADAT"
1123 };
1124
1125 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1126 }
1127
snd_emu1010_optical_in_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1128 static int snd_emu1010_optical_in_get(struct snd_kcontrol *kcontrol,
1129 struct snd_ctl_elem_value *ucontrol)
1130 {
1131 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1132
1133 ucontrol->value.enumerated.item[0] = emu->emu1010.optical_in;
1134 return 0;
1135 }
1136
snd_emu1010_optical_in_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1137 static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol,
1138 struct snd_ctl_elem_value *ucontrol)
1139 {
1140 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1141 unsigned int val;
1142 u32 tmp;
1143 int change = 0;
1144
1145 val = ucontrol->value.enumerated.item[0];
1146 /* Limit: uinfo->value.enumerated.items = 2; */
1147 if (val >= 2)
1148 return -EINVAL;
1149 change = (emu->emu1010.optical_in != val);
1150 if (change) {
1151 emu->emu1010.optical_in = val;
1152 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) |
1153 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF);
1154 snd_emu1010_fpga_write_lock(emu, EMU_HANA_OPTICAL_TYPE, tmp);
1155 }
1156 return change;
1157 }
1158
1159 static const struct snd_kcontrol_new snd_emu1010_optical_in = {
1160 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1161 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1162 .name = "Optical Input Mode",
1163 .count = 1,
1164 .info = snd_emu1010_optical_in_info,
1165 .get = snd_emu1010_optical_in_get,
1166 .put = snd_emu1010_optical_in_put
1167 };
1168
snd_audigy_i2c_capture_source_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1169 static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
1170 struct snd_ctl_elem_info *uinfo)
1171 {
1172 #if 0
1173 static const char * const texts[4] = {
1174 "Unknown1", "Unknown2", "Mic", "Line"
1175 };
1176 #endif
1177 static const char * const texts[2] = {
1178 "Mic", "Line"
1179 };
1180
1181 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1182 }
1183
snd_audigy_i2c_capture_source_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1184 static int snd_audigy_i2c_capture_source_get(struct snd_kcontrol *kcontrol,
1185 struct snd_ctl_elem_value *ucontrol)
1186 {
1187 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1188
1189 ucontrol->value.enumerated.item[0] = emu->i2c_capture_source;
1190 return 0;
1191 }
1192
snd_audigy_i2c_capture_source_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1193 static int snd_audigy_i2c_capture_source_put(struct snd_kcontrol *kcontrol,
1194 struct snd_ctl_elem_value *ucontrol)
1195 {
1196 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1197 unsigned int source_id;
1198 unsigned int ngain, ogain;
1199 u16 gpio;
1200 int change = 0;
1201 u32 source;
1202 /* If the capture source has changed,
1203 * update the capture volume from the cached value
1204 * for the particular source.
1205 */
1206 source_id = ucontrol->value.enumerated.item[0];
1207 /* Limit: uinfo->value.enumerated.items = 2; */
1208 /* emu->i2c_capture_volume */
1209 if (source_id >= 2)
1210 return -EINVAL;
1211 change = (emu->i2c_capture_source != source_id);
1212 if (change) {
1213 snd_emu10k1_i2c_write(emu, ADC_MUX, 0); /* Mute input */
1214 spin_lock_irq(&emu->emu_lock);
1215 gpio = inw(emu->port + A_IOCFG);
1216 if (source_id==0)
1217 outw(gpio | 0x4, emu->port + A_IOCFG);
1218 else
1219 outw(gpio & ~0x4, emu->port + A_IOCFG);
1220 spin_unlock_irq(&emu->emu_lock);
1221
1222 ngain = emu->i2c_capture_volume[source_id][0]; /* Left */
1223 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */
1224 if (ngain != ogain)
1225 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff));
1226 ngain = emu->i2c_capture_volume[source_id][1]; /* Right */
1227 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */
1228 if (ngain != ogain)
1229 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));
1230
1231 source = 1 << (source_id + 2);
1232 snd_emu10k1_i2c_write(emu, ADC_MUX, source); /* Set source */
1233 emu->i2c_capture_source = source_id;
1234 }
1235 return change;
1236 }
1237
1238 static const struct snd_kcontrol_new snd_audigy_i2c_capture_source =
1239 {
1240 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1241 .name = "Capture Source",
1242 .info = snd_audigy_i2c_capture_source_info,
1243 .get = snd_audigy_i2c_capture_source_get,
1244 .put = snd_audigy_i2c_capture_source_put
1245 };
1246
snd_audigy_i2c_volume_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1247 static int snd_audigy_i2c_volume_info(struct snd_kcontrol *kcontrol,
1248 struct snd_ctl_elem_info *uinfo)
1249 {
1250 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1251 uinfo->count = 2;
1252 uinfo->value.integer.min = 0;
1253 uinfo->value.integer.max = 255;
1254 return 0;
1255 }
1256
snd_audigy_i2c_volume_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1257 static int snd_audigy_i2c_volume_get(struct snd_kcontrol *kcontrol,
1258 struct snd_ctl_elem_value *ucontrol)
1259 {
1260 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1261 unsigned int source_id;
1262
1263 source_id = kcontrol->private_value;
1264 /* Limit: emu->i2c_capture_volume */
1265 /* capture_source: uinfo->value.enumerated.items = 2 */
1266 if (source_id >= 2)
1267 return -EINVAL;
1268
1269 ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0];
1270 ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1];
1271 return 0;
1272 }
1273
snd_audigy_i2c_volume_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1274 static int snd_audigy_i2c_volume_put(struct snd_kcontrol *kcontrol,
1275 struct snd_ctl_elem_value *ucontrol)
1276 {
1277 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1278 unsigned int ogain;
1279 unsigned int ngain0, ngain1;
1280 unsigned int source_id;
1281 int change = 0;
1282
1283 source_id = kcontrol->private_value;
1284 /* Limit: emu->i2c_capture_volume */
1285 /* capture_source: uinfo->value.enumerated.items = 2 */
1286 if (source_id >= 2)
1287 return -EINVAL;
1288 ngain0 = ucontrol->value.integer.value[0];
1289 ngain1 = ucontrol->value.integer.value[1];
1290 if (ngain0 > 0xff)
1291 return -EINVAL;
1292 if (ngain1 > 0xff)
1293 return -EINVAL;
1294 ogain = emu->i2c_capture_volume[source_id][0]; /* Left */
1295 if (ogain != ngain0) {
1296 if (emu->i2c_capture_source == source_id)
1297 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ngain0);
1298 emu->i2c_capture_volume[source_id][0] = ngain0;
1299 change = 1;
1300 }
1301 ogain = emu->i2c_capture_volume[source_id][1]; /* Right */
1302 if (ogain != ngain1) {
1303 if (emu->i2c_capture_source == source_id)
1304 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ngain1);
1305 emu->i2c_capture_volume[source_id][1] = ngain1;
1306 change = 1;
1307 }
1308
1309 return change;
1310 }
1311
1312 static const struct snd_kcontrol_new i2c_volume_ctl = {
1313 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1314 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1315 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1316 .info = snd_audigy_i2c_volume_info,
1317 .get = snd_audigy_i2c_volume_get,
1318 .put = snd_audigy_i2c_volume_put,
1319 .tlv = { .p = snd_audigy_db_scale2 }
1320 };
1321
1322 static const char * const snd_audigy_i2c_volume_ctls[] = {
1323 "Mic Capture Volume",
1324 "Line Capture Volume",
1325 };
1326
1327 #if 0
1328 static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1329 {
1330 static const char * const texts[] = {"44100", "48000", "96000"};
1331
1332 return snd_ctl_enum_info(uinfo, 1, 3, texts);
1333 }
1334
1335 static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
1336 struct snd_ctl_elem_value *ucontrol)
1337 {
1338 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1339 unsigned int tmp;
1340
1341 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
1342 switch (tmp & A_SPDIF_RATE_MASK) {
1343 case A_SPDIF_44100:
1344 ucontrol->value.enumerated.item[0] = 0;
1345 break;
1346 case A_SPDIF_48000:
1347 ucontrol->value.enumerated.item[0] = 1;
1348 break;
1349 case A_SPDIF_96000:
1350 ucontrol->value.enumerated.item[0] = 2;
1351 break;
1352 default:
1353 ucontrol->value.enumerated.item[0] = 1;
1354 }
1355 return 0;
1356 }
1357
1358 static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol,
1359 struct snd_ctl_elem_value *ucontrol)
1360 {
1361 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1362 int change;
1363 unsigned int reg, val, tmp;
1364
1365 switch(ucontrol->value.enumerated.item[0]) {
1366 case 0:
1367 val = A_SPDIF_44100;
1368 break;
1369 case 1:
1370 val = A_SPDIF_48000;
1371 break;
1372 case 2:
1373 val = A_SPDIF_96000;
1374 break;
1375 default:
1376 val = A_SPDIF_48000;
1377 break;
1378 }
1379
1380
1381 spin_lock_irq(&emu->reg_lock);
1382 reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
1383 tmp = reg & ~A_SPDIF_RATE_MASK;
1384 tmp |= val;
1385 change = (tmp != reg);
1386 if (change)
1387 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
1388 spin_unlock_irq(&emu->reg_lock);
1389 return change;
1390 }
1391
1392 static const struct snd_kcontrol_new snd_audigy_spdif_output_rate =
1393 {
1394 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1395 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1396 .name = "Audigy SPDIF Output Sample Rate",
1397 .count = 1,
1398 .info = snd_audigy_spdif_output_rate_info,
1399 .get = snd_audigy_spdif_output_rate_get,
1400 .put = snd_audigy_spdif_output_rate_put
1401 };
1402 #endif
1403
snd_emu10k1_spdif_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1404 static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol,
1405 struct snd_ctl_elem_value *ucontrol)
1406 {
1407 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1408 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1409 int change;
1410 unsigned int val;
1411
1412 /* Limit: emu->spdif_bits */
1413 if (idx >= 3)
1414 return -EINVAL;
1415 val = (ucontrol->value.iec958.status[0] << 0) |
1416 (ucontrol->value.iec958.status[1] << 8) |
1417 (ucontrol->value.iec958.status[2] << 16) |
1418 (ucontrol->value.iec958.status[3] << 24);
1419 change = val != emu->spdif_bits[idx];
1420 if (change) {
1421 snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val);
1422 emu->spdif_bits[idx] = val;
1423 }
1424 return change;
1425 }
1426
1427 static const struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
1428 {
1429 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1430 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1431 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
1432 .count = 3,
1433 .info = snd_emu10k1_spdif_info,
1434 .get = snd_emu10k1_spdif_get_mask
1435 };
1436
1437 static const struct snd_kcontrol_new snd_emu10k1_spdif_control =
1438 {
1439 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1440 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1441 .count = 3,
1442 .info = snd_emu10k1_spdif_info,
1443 .get = snd_emu10k1_spdif_get,
1444 .put = snd_emu10k1_spdif_put
1445 };
1446
1447
update_emu10k1_fxrt(struct snd_emu10k1 * emu,int voice,unsigned char * route)1448 static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route)
1449 {
1450 if (emu->audigy) {
1451 snd_emu10k1_ptr_write_multiple(emu, voice,
1452 A_FXRT1, snd_emu10k1_compose_audigy_fxrt1(route),
1453 A_FXRT2, snd_emu10k1_compose_audigy_fxrt2(route),
1454 REGLIST_END);
1455 } else {
1456 snd_emu10k1_ptr_write(emu, FXRT, voice,
1457 snd_emu10k1_compose_send_routing(route));
1458 }
1459 }
1460
update_emu10k1_send_volume(struct snd_emu10k1 * emu,int voice,unsigned char * volume)1461 static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume)
1462 {
1463 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]);
1464 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]);
1465 snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]);
1466 snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]);
1467 if (emu->audigy) {
1468 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice,
1469 snd_emu10k1_compose_audigy_sendamounts(volume));
1470 }
1471 }
1472
1473 /* PCM stream controls */
1474
snd_emu10k1_send_routing_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1475 static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1476 {
1477 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1478 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1479 uinfo->count = emu->audigy ? 3*8 : 3*4;
1480 uinfo->value.integer.min = 0;
1481 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
1482 return 0;
1483 }
1484
snd_emu10k1_send_routing_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1485 static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol,
1486 struct snd_ctl_elem_value *ucontrol)
1487 {
1488 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1489 struct snd_emu10k1_pcm_mixer *mix =
1490 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1491 int voice, idx;
1492 int num_efx = emu->audigy ? 8 : 4;
1493 int mask = emu->audigy ? 0x3f : 0x0f;
1494
1495 for (voice = 0; voice < 3; voice++)
1496 for (idx = 0; idx < num_efx; idx++)
1497 ucontrol->value.integer.value[(voice * num_efx) + idx] =
1498 mix->send_routing[voice][idx] & mask;
1499 return 0;
1500 }
1501
snd_emu10k1_send_routing_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1502 static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol,
1503 struct snd_ctl_elem_value *ucontrol)
1504 {
1505 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1506 struct snd_emu10k1_pcm_mixer *mix =
1507 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1508 int change = 0, voice, idx, val;
1509 int num_efx = emu->audigy ? 8 : 4;
1510 int mask = emu->audigy ? 0x3f : 0x0f;
1511
1512 spin_lock_irq(&emu->reg_lock);
1513 for (voice = 0; voice < 3; voice++)
1514 for (idx = 0; idx < num_efx; idx++) {
1515 val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask;
1516 if (mix->send_routing[voice][idx] != val) {
1517 mix->send_routing[voice][idx] = val;
1518 change = 1;
1519 }
1520 }
1521 if (change && mix->epcm && mix->epcm->voices[0]) {
1522 if (!mix->epcm->voices[0]->last) {
1523 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
1524 &mix->send_routing[1][0]);
1525 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number + 1,
1526 &mix->send_routing[2][0]);
1527 } else {
1528 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
1529 &mix->send_routing[0][0]);
1530 }
1531 }
1532 spin_unlock_irq(&emu->reg_lock);
1533 return change;
1534 }
1535
1536 static const struct snd_kcontrol_new snd_emu10k1_send_routing_control =
1537 {
1538 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1539 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1540 .name = "EMU10K1 PCM Send Routing",
1541 .count = 32,
1542 .info = snd_emu10k1_send_routing_info,
1543 .get = snd_emu10k1_send_routing_get,
1544 .put = snd_emu10k1_send_routing_put
1545 };
1546
snd_emu10k1_send_volume_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1547 static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1548 {
1549 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1550 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1551 uinfo->count = emu->audigy ? 3*8 : 3*4;
1552 uinfo->value.integer.min = 0;
1553 uinfo->value.integer.max = 255;
1554 return 0;
1555 }
1556
snd_emu10k1_send_volume_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1557 static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol,
1558 struct snd_ctl_elem_value *ucontrol)
1559 {
1560 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1561 struct snd_emu10k1_pcm_mixer *mix =
1562 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1563 int idx;
1564 int num_efx = emu->audigy ? 8 : 4;
1565
1566 for (idx = 0; idx < 3*num_efx; idx++)
1567 ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx];
1568 return 0;
1569 }
1570
snd_emu10k1_send_volume_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1571 static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol,
1572 struct snd_ctl_elem_value *ucontrol)
1573 {
1574 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1575 struct snd_emu10k1_pcm_mixer *mix =
1576 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1577 int change = 0, idx, val;
1578 int num_efx = emu->audigy ? 8 : 4;
1579
1580 spin_lock_irq(&emu->reg_lock);
1581 for (idx = 0; idx < 3*num_efx; idx++) {
1582 val = ucontrol->value.integer.value[idx] & 255;
1583 if (mix->send_volume[idx/num_efx][idx%num_efx] != val) {
1584 mix->send_volume[idx/num_efx][idx%num_efx] = val;
1585 change = 1;
1586 }
1587 }
1588 if (change && mix->epcm && mix->epcm->voices[0]) {
1589 if (!mix->epcm->voices[0]->last) {
1590 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
1591 &mix->send_volume[1][0]);
1592 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number + 1,
1593 &mix->send_volume[2][0]);
1594 } else {
1595 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
1596 &mix->send_volume[0][0]);
1597 }
1598 }
1599 spin_unlock_irq(&emu->reg_lock);
1600 return change;
1601 }
1602
1603 static const struct snd_kcontrol_new snd_emu10k1_send_volume_control =
1604 {
1605 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1606 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1607 .name = "EMU10K1 PCM Send Volume",
1608 .count = 32,
1609 .info = snd_emu10k1_send_volume_info,
1610 .get = snd_emu10k1_send_volume_get,
1611 .put = snd_emu10k1_send_volume_put
1612 };
1613
snd_emu10k1_attn_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1614 static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1615 {
1616 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1617 uinfo->count = 3;
1618 uinfo->value.integer.min = 0;
1619 uinfo->value.integer.max = 0x1fffd;
1620 return 0;
1621 }
1622
snd_emu10k1_attn_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1623 static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_value *ucontrol)
1625 {
1626 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1627 struct snd_emu10k1_pcm_mixer *mix =
1628 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1629 int idx;
1630
1631 for (idx = 0; idx < 3; idx++)
1632 ucontrol->value.integer.value[idx] = mix->attn[idx] * 0xffffU / 0x8000U;
1633 return 0;
1634 }
1635
snd_emu10k1_attn_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1636 static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,
1637 struct snd_ctl_elem_value *ucontrol)
1638 {
1639 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1640 struct snd_emu10k1_pcm_mixer *mix =
1641 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1642 int change = 0, idx, val;
1643
1644 spin_lock_irq(&emu->reg_lock);
1645 for (idx = 0; idx < 3; idx++) {
1646 unsigned uval = ucontrol->value.integer.value[idx] & 0x1ffff;
1647 val = uval * 0x8000U / 0xffffU;
1648 if (mix->attn[idx] != val) {
1649 mix->attn[idx] = val;
1650 change = 1;
1651 }
1652 }
1653 if (change && mix->epcm && mix->epcm->voices[0]) {
1654 if (!mix->epcm->voices[0]->last) {
1655 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]);
1656 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number + 1, mix->attn[2]);
1657 } else {
1658 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]);
1659 }
1660 }
1661 spin_unlock_irq(&emu->reg_lock);
1662 return change;
1663 }
1664
1665 static const struct snd_kcontrol_new snd_emu10k1_attn_control =
1666 {
1667 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1668 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1669 .name = "EMU10K1 PCM Volume",
1670 .count = 32,
1671 .info = snd_emu10k1_attn_info,
1672 .get = snd_emu10k1_attn_get,
1673 .put = snd_emu10k1_attn_put
1674 };
1675
1676 /* Mutichannel PCM stream controls */
1677
snd_emu10k1_efx_send_routing_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1678 static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1679 {
1680 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1681 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1682 uinfo->count = emu->audigy ? 8 : 4;
1683 uinfo->value.integer.min = 0;
1684 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
1685 return 0;
1686 }
1687
snd_emu10k1_efx_send_routing_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1688 static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol,
1689 struct snd_ctl_elem_value *ucontrol)
1690 {
1691 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1692 struct snd_emu10k1_pcm_mixer *mix =
1693 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1694 int idx;
1695 int num_efx = emu->audigy ? 8 : 4;
1696 int mask = emu->audigy ? 0x3f : 0x0f;
1697
1698 for (idx = 0; idx < num_efx; idx++)
1699 ucontrol->value.integer.value[idx] =
1700 mix->send_routing[0][idx] & mask;
1701 return 0;
1702 }
1703
snd_emu10k1_efx_send_routing_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1704 static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol,
1705 struct snd_ctl_elem_value *ucontrol)
1706 {
1707 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1708 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1709 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1710 int change = 0, idx, val;
1711 int num_efx = emu->audigy ? 8 : 4;
1712 int mask = emu->audigy ? 0x3f : 0x0f;
1713
1714 spin_lock_irq(&emu->reg_lock);
1715 for (idx = 0; idx < num_efx; idx++) {
1716 val = ucontrol->value.integer.value[idx] & mask;
1717 if (mix->send_routing[0][idx] != val) {
1718 mix->send_routing[0][idx] = val;
1719 change = 1;
1720 }
1721 }
1722
1723 if (change && mix->epcm) {
1724 if (mix->epcm->voices[ch]) {
1725 update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number,
1726 &mix->send_routing[0][0]);
1727 }
1728 }
1729 spin_unlock_irq(&emu->reg_lock);
1730 return change;
1731 }
1732
1733 static const struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
1734 {
1735 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1736 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1737 .name = "Multichannel PCM Send Routing",
1738 .count = 16,
1739 .info = snd_emu10k1_efx_send_routing_info,
1740 .get = snd_emu10k1_efx_send_routing_get,
1741 .put = snd_emu10k1_efx_send_routing_put
1742 };
1743
snd_emu10k1_efx_send_volume_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1744 static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1745 {
1746 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1747 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1748 uinfo->count = emu->audigy ? 8 : 4;
1749 uinfo->value.integer.min = 0;
1750 uinfo->value.integer.max = 255;
1751 return 0;
1752 }
1753
snd_emu10k1_efx_send_volume_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1754 static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol,
1755 struct snd_ctl_elem_value *ucontrol)
1756 {
1757 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1758 struct snd_emu10k1_pcm_mixer *mix =
1759 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1760 int idx;
1761 int num_efx = emu->audigy ? 8 : 4;
1762
1763 for (idx = 0; idx < num_efx; idx++)
1764 ucontrol->value.integer.value[idx] = mix->send_volume[0][idx];
1765 return 0;
1766 }
1767
snd_emu10k1_efx_send_volume_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1768 static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol,
1769 struct snd_ctl_elem_value *ucontrol)
1770 {
1771 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1772 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1773 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1774 int change = 0, idx, val;
1775 int num_efx = emu->audigy ? 8 : 4;
1776
1777 spin_lock_irq(&emu->reg_lock);
1778 for (idx = 0; idx < num_efx; idx++) {
1779 val = ucontrol->value.integer.value[idx] & 255;
1780 if (mix->send_volume[0][idx] != val) {
1781 mix->send_volume[0][idx] = val;
1782 change = 1;
1783 }
1784 }
1785 if (change && mix->epcm) {
1786 if (mix->epcm->voices[ch]) {
1787 update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number,
1788 &mix->send_volume[0][0]);
1789 }
1790 }
1791 spin_unlock_irq(&emu->reg_lock);
1792 return change;
1793 }
1794
1795
1796 static const struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
1797 {
1798 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1799 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1800 .name = "Multichannel PCM Send Volume",
1801 .count = 16,
1802 .info = snd_emu10k1_efx_send_volume_info,
1803 .get = snd_emu10k1_efx_send_volume_get,
1804 .put = snd_emu10k1_efx_send_volume_put
1805 };
1806
snd_emu10k1_efx_attn_info(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_info * uinfo)1807 static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1808 {
1809 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1810 uinfo->count = 1;
1811 uinfo->value.integer.min = 0;
1812 uinfo->value.integer.max = 0x1fffd;
1813 return 0;
1814 }
1815
snd_emu10k1_efx_attn_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1816 static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol,
1817 struct snd_ctl_elem_value *ucontrol)
1818 {
1819 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1820 struct snd_emu10k1_pcm_mixer *mix =
1821 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1822
1823 ucontrol->value.integer.value[0] = mix->attn[0] * 0xffffU / 0x8000U;
1824 return 0;
1825 }
1826
snd_emu10k1_efx_attn_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1827 static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol,
1828 struct snd_ctl_elem_value *ucontrol)
1829 {
1830 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1831 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1832 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1833 int change = 0, val;
1834 unsigned uval;
1835
1836 spin_lock_irq(&emu->reg_lock);
1837 uval = ucontrol->value.integer.value[0] & 0x1ffff;
1838 val = uval * 0x8000U / 0xffffU;
1839 if (mix->attn[0] != val) {
1840 mix->attn[0] = val;
1841 change = 1;
1842 }
1843 if (change && mix->epcm) {
1844 if (mix->epcm->voices[ch]) {
1845 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]);
1846 }
1847 }
1848 spin_unlock_irq(&emu->reg_lock);
1849 return change;
1850 }
1851
1852 static const struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
1853 {
1854 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1855 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1856 .name = "Multichannel PCM Volume",
1857 .count = 16,
1858 .info = snd_emu10k1_efx_attn_info,
1859 .get = snd_emu10k1_efx_attn_get,
1860 .put = snd_emu10k1_efx_attn_put
1861 };
1862
1863 #define snd_emu10k1_shared_spdif_info snd_ctl_boolean_mono_info
1864
snd_emu10k1_shared_spdif_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1865 static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
1866 struct snd_ctl_elem_value *ucontrol)
1867 {
1868 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1869
1870 if (emu->audigy)
1871 ucontrol->value.integer.value[0] = inw(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
1872 else
1873 ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
1874 if (emu->card_capabilities->invert_shared_spdif)
1875 ucontrol->value.integer.value[0] =
1876 !ucontrol->value.integer.value[0];
1877
1878 return 0;
1879 }
1880
snd_emu10k1_shared_spdif_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1881 static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
1882 struct snd_ctl_elem_value *ucontrol)
1883 {
1884 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1885 unsigned int reg, val, sw;
1886 int change = 0;
1887
1888 sw = ucontrol->value.integer.value[0];
1889 if (emu->card_capabilities->invert_shared_spdif)
1890 sw = !sw;
1891 spin_lock_irq(&emu->emu_lock);
1892 if ( emu->card_capabilities->i2c_adc) {
1893 /* Do nothing for Audigy 2 ZS Notebook */
1894 } else if (emu->audigy) {
1895 reg = inw(emu->port + A_IOCFG);
1896 val = sw ? A_IOCFG_GPOUT0 : 0;
1897 change = (reg & A_IOCFG_GPOUT0) != val;
1898 if (change) {
1899 reg &= ~A_IOCFG_GPOUT0;
1900 reg |= val;
1901 outw(reg | val, emu->port + A_IOCFG);
1902 }
1903 }
1904 reg = inl(emu->port + HCFG);
1905 val = sw ? HCFG_GPOUT0 : 0;
1906 change |= (reg & HCFG_GPOUT0) != val;
1907 if (change) {
1908 reg &= ~HCFG_GPOUT0;
1909 reg |= val;
1910 outl(reg | val, emu->port + HCFG);
1911 }
1912 spin_unlock_irq(&emu->emu_lock);
1913 return change;
1914 }
1915
1916 static const struct snd_kcontrol_new snd_emu10k1_shared_spdif =
1917 {
1918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1919 .name = "SB Live Analog/Digital Output Jack",
1920 .info = snd_emu10k1_shared_spdif_info,
1921 .get = snd_emu10k1_shared_spdif_get,
1922 .put = snd_emu10k1_shared_spdif_put
1923 };
1924
1925 static const struct snd_kcontrol_new snd_audigy_shared_spdif =
1926 {
1927 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1928 .name = "Audigy Analog/Digital Output Jack",
1929 .info = snd_emu10k1_shared_spdif_info,
1930 .get = snd_emu10k1_shared_spdif_get,
1931 .put = snd_emu10k1_shared_spdif_put
1932 };
1933
1934 /* workaround for too low volume on Audigy due to 16bit/24bit conversion */
1935
1936 #define snd_audigy_capture_boost_info snd_ctl_boolean_mono_info
1937
snd_audigy_capture_boost_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1938 static int snd_audigy_capture_boost_get(struct snd_kcontrol *kcontrol,
1939 struct snd_ctl_elem_value *ucontrol)
1940 {
1941 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1942 unsigned int val;
1943
1944 /* FIXME: better to use a cached version */
1945 val = snd_ac97_read(emu->ac97, AC97_REC_GAIN);
1946 ucontrol->value.integer.value[0] = !!val;
1947 return 0;
1948 }
1949
snd_audigy_capture_boost_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1950 static int snd_audigy_capture_boost_put(struct snd_kcontrol *kcontrol,
1951 struct snd_ctl_elem_value *ucontrol)
1952 {
1953 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1954 unsigned int val;
1955
1956 if (ucontrol->value.integer.value[0])
1957 val = 0x0f0f;
1958 else
1959 val = 0;
1960 return snd_ac97_update(emu->ac97, AC97_REC_GAIN, val);
1961 }
1962
1963 static const struct snd_kcontrol_new snd_audigy_capture_boost =
1964 {
1965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1966 .name = "Mic Extra Boost",
1967 .info = snd_audigy_capture_boost_info,
1968 .get = snd_audigy_capture_boost_get,
1969 .put = snd_audigy_capture_boost_put
1970 };
1971
1972
1973 /*
1974 */
snd_emu10k1_mixer_free_ac97(struct snd_ac97 * ac97)1975 static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
1976 {
1977 struct snd_emu10k1 *emu = ac97->private_data;
1978 emu->ac97 = NULL;
1979 }
1980
1981 /*
1982 */
remove_ctl(struct snd_card * card,const char * name)1983 static int remove_ctl(struct snd_card *card, const char *name)
1984 {
1985 struct snd_ctl_elem_id id;
1986 memset(&id, 0, sizeof(id));
1987 strscpy(id.name, name);
1988 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1989 return snd_ctl_remove_id(card, &id);
1990 }
1991
rename_ctl(struct snd_card * card,const char * src,const char * dst)1992 static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
1993 {
1994 struct snd_kcontrol *kctl = snd_ctl_find_id_mixer(card, src);
1995 if (kctl) {
1996 snd_ctl_rename(card, kctl, dst);
1997 return 0;
1998 }
1999 return -ENOENT;
2000 }
2001
snd_emu10k1_mixer(struct snd_emu10k1 * emu,int pcm_device,int multi_device)2002 int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
2003 int pcm_device, int multi_device)
2004 {
2005 int err;
2006 struct snd_kcontrol *kctl;
2007 struct snd_card *card = emu->card;
2008 const char * const *c;
2009 static const char * const emu10k1_remove_ctls[] = {
2010 /* no AC97 mono, surround, center/lfe */
2011 "Master Mono Playback Switch",
2012 "Master Mono Playback Volume",
2013 "PCM Out Path & Mute",
2014 "Mono Output Select",
2015 "Surround Playback Switch",
2016 "Surround Playback Volume",
2017 "Center Playback Switch",
2018 "Center Playback Volume",
2019 "LFE Playback Switch",
2020 "LFE Playback Volume",
2021 NULL
2022 };
2023 static const char * const emu10k1_rename_ctls[] = {
2024 "Surround Digital Playback Volume", "Surround Playback Volume",
2025 "Center Digital Playback Volume", "Center Playback Volume",
2026 "LFE Digital Playback Volume", "LFE Playback Volume",
2027 NULL
2028 };
2029 static const char * const audigy_remove_ctls[] = {
2030 /* Master/PCM controls on ac97 of Audigy has no effect */
2031 /* On the Audigy2 the AC97 playback is piped into
2032 * the Philips ADC for 24bit capture */
2033 "PCM Playback Switch",
2034 "PCM Playback Volume",
2035 "Master Playback Switch",
2036 "Master Playback Volume",
2037 "PCM Out Path & Mute",
2038 "Mono Output Select",
2039 /* remove unused AC97 capture controls */
2040 "Capture Source",
2041 "Capture Switch",
2042 "Capture Volume",
2043 "Mic Select",
2044 "Headphone Playback Switch",
2045 "Headphone Playback Volume",
2046 "3D Control - Center",
2047 "3D Control - Depth",
2048 "3D Control - Switch",
2049 "Video Playback Switch",
2050 "Video Playback Volume",
2051 "Mic Playback Switch",
2052 "Mic Playback Volume",
2053 "External Amplifier",
2054 NULL
2055 };
2056 static const char * const audigy_rename_ctls[] = {
2057 /* use conventional names */
2058 "Wave Playback Volume", "PCM Playback Volume",
2059 /* "Wave Capture Volume", "PCM Capture Volume", */
2060 "Wave Master Playback Volume", "Master Playback Volume",
2061 "AMic Playback Volume", "Mic Playback Volume",
2062 "Master Mono Playback Switch", "Phone Output Playback Switch",
2063 "Master Mono Playback Volume", "Phone Output Playback Volume",
2064 NULL
2065 };
2066 static const char * const audigy_rename_ctls_i2c_adc[] = {
2067 //"Analog Mix Capture Volume","OLD Analog Mix Capture Volume",
2068 "Line Capture Volume", "Analog Mix Capture Volume",
2069 "Wave Playback Volume", "OLD PCM Playback Volume",
2070 "Wave Master Playback Volume", "Master Playback Volume",
2071 "AMic Playback Volume", "Old Mic Playback Volume",
2072 "CD Capture Volume", "IEC958 Optical Capture Volume",
2073 NULL
2074 };
2075 static const char * const audigy_remove_ctls_i2c_adc[] = {
2076 /* On the Audigy2 ZS Notebook
2077 * Capture via WM8775 */
2078 "Mic Capture Volume",
2079 "Analog Mix Capture Volume",
2080 "Aux Capture Volume",
2081 "IEC958 Optical Capture Volume",
2082 NULL
2083 };
2084 static const char * const audigy_remove_ctls_1361t_adc[] = {
2085 /* On the Audigy2 the AC97 playback is piped into
2086 * the Philips ADC for 24bit capture */
2087 "PCM Playback Switch",
2088 "PCM Playback Volume",
2089 "Capture Source",
2090 "Capture Switch",
2091 "Capture Volume",
2092 "Mic Capture Volume",
2093 "Headphone Playback Switch",
2094 "Headphone Playback Volume",
2095 "3D Control - Center",
2096 "3D Control - Depth",
2097 "3D Control - Switch",
2098 "Line2 Playback Volume",
2099 "Line2 Capture Volume",
2100 NULL
2101 };
2102 static const char * const audigy_rename_ctls_1361t_adc[] = {
2103 "Master Playback Switch", "Master Capture Switch",
2104 "Master Playback Volume", "Master Capture Volume",
2105 "Wave Master Playback Volume", "Master Playback Volume",
2106 "Beep Playback Switch", "Beep Capture Switch",
2107 "Beep Playback Volume", "Beep Capture Volume",
2108 "Phone Playback Switch", "Phone Capture Switch",
2109 "Phone Playback Volume", "Phone Capture Volume",
2110 "Mic Playback Switch", "Mic Capture Switch",
2111 "Mic Playback Volume", "Mic Capture Volume",
2112 "Line Playback Switch", "Line Capture Switch",
2113 "Line Playback Volume", "Line Capture Volume",
2114 "CD Playback Switch", "CD Capture Switch",
2115 "CD Playback Volume", "CD Capture Volume",
2116 "Aux Playback Switch", "Aux Capture Switch",
2117 "Aux Playback Volume", "Aux Capture Volume",
2118 "Video Playback Switch", "Video Capture Switch",
2119 "Video Playback Volume", "Video Capture Volume",
2120 "Master Mono Playback Switch", "Phone Output Playback Switch",
2121 "Master Mono Playback Volume", "Phone Output Playback Volume",
2122 NULL
2123 };
2124
2125 if (emu->card_capabilities->ac97_chip) {
2126 struct snd_ac97_bus *pbus;
2127 struct snd_ac97_template ac97;
2128 static const struct snd_ac97_bus_ops ops = {
2129 .write = snd_emu10k1_ac97_write,
2130 .read = snd_emu10k1_ac97_read,
2131 };
2132
2133 err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus);
2134 if (err < 0)
2135 return err;
2136 pbus->no_vra = 1; /* we don't need VRA */
2137
2138 memset(&ac97, 0, sizeof(ac97));
2139 ac97.private_data = emu;
2140 ac97.private_free = snd_emu10k1_mixer_free_ac97;
2141 ac97.scaps = AC97_SCAP_NO_SPDIF;
2142 err = snd_ac97_mixer(pbus, &ac97, &emu->ac97);
2143 if (err < 0) {
2144 if (emu->card_capabilities->ac97_chip == 1)
2145 return err;
2146 dev_info(emu->card->dev,
2147 "AC97 is optional on this board\n");
2148 dev_info(emu->card->dev,
2149 "Proceeding without ac97 mixers...\n");
2150 snd_device_free(emu->card, pbus);
2151 goto no_ac97; /* FIXME: get rid of ugly gotos.. */
2152 }
2153 if (emu->audigy) {
2154 /* set master volume to 0 dB */
2155 snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000);
2156 /* set capture source to mic */
2157 snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
2158 /* set mono output (TAD) to mic */
2159 snd_ac97_update_bits(emu->ac97, AC97_GENERAL_PURPOSE,
2160 0x0200, 0x0200);
2161 if (emu->card_capabilities->adc_1361t)
2162 c = audigy_remove_ctls_1361t_adc;
2163 else
2164 c = audigy_remove_ctls;
2165 } else {
2166 /*
2167 * Credits for cards based on STAC9758:
2168 * James Courtier-Dutton <James@superbug.demon.co.uk>
2169 * Voluspa <voluspa@comhem.se>
2170 */
2171 if (emu->ac97->id == AC97_ID_STAC9758) {
2172 emu->rear_ac97 = 1;
2173 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
2174 snd_ac97_write_cache(emu->ac97, AC97_HEADPHONE, 0x0202);
2175 remove_ctl(card,"Front Playback Volume");
2176 remove_ctl(card,"Front Playback Switch");
2177 }
2178 /* remove unused AC97 controls */
2179 snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
2180 snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
2181 c = emu10k1_remove_ctls;
2182 }
2183 for (; *c; c++)
2184 remove_ctl(card, *c);
2185 } else if (emu->card_capabilities->i2c_adc) {
2186 c = audigy_remove_ctls_i2c_adc;
2187 for (; *c; c++)
2188 remove_ctl(card, *c);
2189 } else {
2190 no_ac97:
2191 if (emu->card_capabilities->ecard)
2192 strscpy(emu->card->mixername, "EMU APS");
2193 else if (emu->audigy)
2194 strscpy(emu->card->mixername, "SB Audigy");
2195 else
2196 strscpy(emu->card->mixername, "Emu10k1");
2197 }
2198
2199 if (emu->audigy)
2200 if (emu->card_capabilities->adc_1361t)
2201 c = audigy_rename_ctls_1361t_adc;
2202 else if (emu->card_capabilities->i2c_adc)
2203 c = audigy_rename_ctls_i2c_adc;
2204 else
2205 c = audigy_rename_ctls;
2206 else
2207 c = emu10k1_rename_ctls;
2208 for (; *c; c += 2)
2209 rename_ctl(card, c[0], c[1]);
2210
2211 if (emu->card_capabilities->subsystem == 0x80401102) { /* SB Live! Platinum CT4760P */
2212 remove_ctl(card, "Center Playback Volume");
2213 remove_ctl(card, "LFE Playback Volume");
2214 remove_ctl(card, "Wave Center Playback Volume");
2215 remove_ctl(card, "Wave LFE Playback Volume");
2216 }
2217 if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */
2218 rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
2219 rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
2220 rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
2221 rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
2222 }
2223 kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu);
2224 if (!kctl)
2225 return -ENOMEM;
2226 kctl->id.device = pcm_device;
2227 err = snd_ctl_add(card, kctl);
2228 if (err)
2229 return err;
2230 kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu);
2231 if (!kctl)
2232 return -ENOMEM;
2233 kctl->id.device = pcm_device;
2234 err = snd_ctl_add(card, kctl);
2235 if (err)
2236 return err;
2237 kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu);
2238 if (!kctl)
2239 return -ENOMEM;
2240 kctl->id.device = pcm_device;
2241 err = snd_ctl_add(card, kctl);
2242 if (err)
2243 return err;
2244
2245 kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu);
2246 if (!kctl)
2247 return -ENOMEM;
2248 kctl->id.device = multi_device;
2249 err = snd_ctl_add(card, kctl);
2250 if (err)
2251 return err;
2252
2253 kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu);
2254 if (!kctl)
2255 return -ENOMEM;
2256 kctl->id.device = multi_device;
2257 err = snd_ctl_add(card, kctl);
2258 if (err)
2259 return err;
2260
2261 kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu);
2262 if (!kctl)
2263 return -ENOMEM;
2264 kctl->id.device = multi_device;
2265 err = snd_ctl_add(card, kctl);
2266 if (err)
2267 return err;
2268
2269 if (!emu->card_capabilities->ecard && !emu->card_capabilities->emu_model) {
2270 /* sb live! and audigy */
2271 kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu);
2272 if (!kctl)
2273 return -ENOMEM;
2274 if (!emu->audigy)
2275 kctl->id.device = emu->pcm_efx->device;
2276 err = snd_ctl_add(card, kctl);
2277 if (err)
2278 return err;
2279 kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu);
2280 if (!kctl)
2281 return -ENOMEM;
2282 if (!emu->audigy)
2283 kctl->id.device = emu->pcm_efx->device;
2284 err = snd_ctl_add(card, kctl);
2285 if (err)
2286 return err;
2287 }
2288
2289 if (emu->card_capabilities->emu_model) {
2290 ; /* Disable the snd_audigy_spdif_shared_spdif */
2291 } else if (emu->audigy) {
2292 kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu);
2293 if (!kctl)
2294 return -ENOMEM;
2295 err = snd_ctl_add(card, kctl);
2296 if (err)
2297 return err;
2298 #if 0
2299 kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu);
2300 if (!kctl)
2301 return -ENOMEM;
2302 err = snd_ctl_add(card, kctl);
2303 if (err)
2304 return err;
2305 #endif
2306 } else if (! emu->card_capabilities->ecard) {
2307 /* sb live! */
2308 kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu);
2309 if (!kctl)
2310 return -ENOMEM;
2311 err = snd_ctl_add(card, kctl);
2312 if (err)
2313 return err;
2314 }
2315 if (emu->card_capabilities->ca0151_chip) { /* P16V */
2316 err = snd_p16v_mixer(emu);
2317 if (err)
2318 return err;
2319 }
2320
2321 if (emu->card_capabilities->emu_model) {
2322 unsigned i, emu_idx = emu1010_idx(emu);
2323 const struct snd_emu1010_routing_info *emu_ri =
2324 &emu1010_routing_info[emu_idx];
2325 const struct snd_emu1010_pads_info *emu_pi = &emu1010_pads_info[emu_idx];
2326
2327 for (i = 0; i < emu_ri->n_ins; i++)
2328 emu->emu1010.input_source[i] =
2329 emu1010_map_source(emu_ri, emu_ri->in_dflts[i]);
2330 for (i = 0; i < emu_ri->n_outs; i++)
2331 emu->emu1010.output_source[i] =
2332 emu1010_map_source(emu_ri, emu_ri->out_dflts[i]);
2333 snd_emu1010_fpga_lock(emu);
2334 snd_emu1010_apply_sources(emu);
2335 snd_emu1010_fpga_unlock(emu);
2336
2337 kctl = emu->ctl_clock_source = snd_ctl_new1(&snd_emu1010_clock_source, emu);
2338 err = snd_ctl_add(card, kctl);
2339 if (err < 0)
2340 return err;
2341 err = snd_ctl_add(card,
2342 snd_ctl_new1(&snd_emu1010_clock_fallback, emu));
2343 if (err < 0)
2344 return err;
2345
2346 err = add_ctls(emu, &emu1010_adc_pads_ctl,
2347 emu_pi->adc_ctls, emu_pi->n_adc_ctls);
2348 if (err < 0)
2349 return err;
2350 err = add_ctls(emu, &emu1010_dac_pads_ctl,
2351 emu_pi->dac_ctls, emu_pi->n_dac_ctls);
2352 if (err < 0)
2353 return err;
2354
2355 if (!emu->card_capabilities->no_adat) {
2356 err = snd_ctl_add(card,
2357 snd_ctl_new1(&snd_emu1010_optical_out, emu));
2358 if (err < 0)
2359 return err;
2360 err = snd_ctl_add(card,
2361 snd_ctl_new1(&snd_emu1010_optical_in, emu));
2362 if (err < 0)
2363 return err;
2364 }
2365
2366 err = add_emu1010_source_mixers(emu);
2367 if (err < 0)
2368 return err;
2369 }
2370
2371 if ( emu->card_capabilities->i2c_adc) {
2372 err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_i2c_capture_source, emu));
2373 if (err < 0)
2374 return err;
2375
2376 err = add_ctls(emu, &i2c_volume_ctl,
2377 snd_audigy_i2c_volume_ctls,
2378 ARRAY_SIZE(snd_audigy_i2c_volume_ctls));
2379 if (err < 0)
2380 return err;
2381 }
2382
2383 if (emu->card_capabilities->ac97_chip && emu->audigy) {
2384 err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_capture_boost,
2385 emu));
2386 if (err < 0)
2387 return err;
2388 }
2389
2390 return 0;
2391 }
2392