1 // SPDX-License-Identifier: GPL-2.0-or-later
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>
10 * Routines for control of EMU10K1 chips / mixer routines
13 #include <linux/time.h>
14 #include <linux/init.h>
15 #include <sound/core.h>
16 #include <sound/emu10k1.h>
17 #include <linux/delay.h>
18 #include <sound/tlv.h>
22 #define AC97_ID_STAC9758 0x83847658
24 static const DECLARE_TLV_DB_SCALE(snd_audigy_db_scale2, -10350, 50, 1); /* WM8775 gain scale */
27 static int add_ctls(struct snd_emu10k1 *emu, const struct snd_kcontrol_new *tpl,
28 const char * const *ctls, unsigned nctls)
30 struct snd_kcontrol_new kctl = *tpl;
33 for (unsigned i = 0; i < nctls; i++) {
35 kctl.private_value = i;
36 err = snd_ctl_add(emu->card, snd_ctl_new1(&kctl, emu));
44 static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
46 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
51 static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol,
52 struct snd_ctl_elem_value *ucontrol)
54 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
55 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
57 /* Limit: emu->spdif_bits */
60 ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
61 ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
62 ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
63 ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
67 static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
68 struct snd_ctl_elem_value *ucontrol)
70 ucontrol->value.iec958.status[0] = 0xff;
71 ucontrol->value.iec958.status[1] = 0xff;
72 ucontrol->value.iec958.status[2] = 0xff;
73 ucontrol->value.iec958.status[3] = 0xff;
77 #define PAIR_PS(base, one, two, sfx) base " " one sfx, base " " two sfx
78 #define LR_PS(base, sfx) PAIR_PS(base, "Left", "Right", sfx)
80 #define ADAT_PS(pfx, sfx) \
81 pfx "ADAT 0" sfx, pfx "ADAT 1" sfx, pfx "ADAT 2" sfx, pfx "ADAT 3" sfx, \
82 pfx "ADAT 4" sfx, pfx "ADAT 5" sfx, pfx "ADAT 6" sfx, pfx "ADAT 7" sfx
84 #define PAIR_REGS(base, one, two) \
88 #define LR_REGS(base) PAIR_REGS(base, _LEFT, _RIGHT)
90 #define ADAT_REGS(base) \
91 base+0, base+1, base+2, base+3, base+4, base+5, base+6, base+7
94 * List of data sources available for each destination
98 "DSP 0", "DSP 1", "DSP 2", "DSP 3", "DSP 4", "DSP 5", "DSP 6", "DSP 7", \
99 "DSP 8", "DSP 9", "DSP 10", "DSP 11", "DSP 12", "DSP 13", "DSP 14", "DSP 15", \
100 "DSP 16", "DSP 17", "DSP 18", "DSP 19", "DSP 20", "DSP 21", "DSP 22", "DSP 23", \
101 "DSP 24", "DSP 25", "DSP 26", "DSP 27", "DSP 28", "DSP 29", "DSP 30", "DSP 31"
103 #define PAIR_TEXTS(base, one, two) PAIR_PS(base, one, two, "")
104 #define LR_TEXTS(base) LR_PS(base, "")
105 #define ADAT_TEXTS(pfx) ADAT_PS(pfx, "")
107 #define EMU32_SRC_REGS \
108 EMU_SRC_ALICE_EMU32A, \
109 EMU_SRC_ALICE_EMU32A+1, \
110 EMU_SRC_ALICE_EMU32A+2, \
111 EMU_SRC_ALICE_EMU32A+3, \
112 EMU_SRC_ALICE_EMU32A+4, \
113 EMU_SRC_ALICE_EMU32A+5, \
114 EMU_SRC_ALICE_EMU32A+6, \
115 EMU_SRC_ALICE_EMU32A+7, \
116 EMU_SRC_ALICE_EMU32A+8, \
117 EMU_SRC_ALICE_EMU32A+9, \
118 EMU_SRC_ALICE_EMU32A+0xa, \
119 EMU_SRC_ALICE_EMU32A+0xb, \
120 EMU_SRC_ALICE_EMU32A+0xc, \
121 EMU_SRC_ALICE_EMU32A+0xd, \
122 EMU_SRC_ALICE_EMU32A+0xe, \
123 EMU_SRC_ALICE_EMU32A+0xf, \
124 EMU_SRC_ALICE_EMU32B, \
125 EMU_SRC_ALICE_EMU32B+1, \
126 EMU_SRC_ALICE_EMU32B+2, \
127 EMU_SRC_ALICE_EMU32B+3, \
128 EMU_SRC_ALICE_EMU32B+4, \
129 EMU_SRC_ALICE_EMU32B+5, \
130 EMU_SRC_ALICE_EMU32B+6, \
131 EMU_SRC_ALICE_EMU32B+7, \
132 EMU_SRC_ALICE_EMU32B+8, \
133 EMU_SRC_ALICE_EMU32B+9, \
134 EMU_SRC_ALICE_EMU32B+0xa, \
135 EMU_SRC_ALICE_EMU32B+0xb, \
136 EMU_SRC_ALICE_EMU32B+0xc, \
137 EMU_SRC_ALICE_EMU32B+0xd, \
138 EMU_SRC_ALICE_EMU32B+0xe, \
139 EMU_SRC_ALICE_EMU32B+0xf
143 #define EMU1010_COMMON_TEXTS \
145 PAIR_TEXTS("Dock Mic", "A", "B"), \
146 LR_TEXTS("Dock ADC1"), \
147 LR_TEXTS("Dock ADC2"), \
148 LR_TEXTS("Dock ADC3"), \
149 LR_TEXTS("0202 ADC"), \
150 LR_TEXTS("1010 SPDIF"), \
153 static const char * const emu1010_src_texts[] = {
154 EMU1010_COMMON_TEXTS,
158 static const unsigned short emu1010_src_regs[] = {
160 PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
161 LR_REGS(EMU_SRC_DOCK_ADC1),
162 LR_REGS(EMU_SRC_DOCK_ADC2),
163 LR_REGS(EMU_SRC_DOCK_ADC3),
164 LR_REGS(EMU_SRC_HAMOA_ADC),
165 LR_REGS(EMU_SRC_HANA_SPDIF),
166 ADAT_REGS(EMU_SRC_HANA_ADAT),
169 static_assert(ARRAY_SIZE(emu1010_src_regs) == ARRAY_SIZE(emu1010_src_texts));
173 #define EMU1010b_COMMON_TEXTS \
175 PAIR_TEXTS("Dock Mic", "A", "B"), \
176 LR_TEXTS("Dock ADC1"), \
177 LR_TEXTS("Dock ADC2"), \
178 LR_TEXTS("0202 ADC"), \
179 LR_TEXTS("Dock SPDIF"), \
180 LR_TEXTS("1010 SPDIF"), \
181 ADAT_TEXTS("Dock "), \
184 static const char * const emu1010b_src_texts[] = {
185 EMU1010b_COMMON_TEXTS,
189 static const unsigned short emu1010b_src_regs[] = {
191 PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
192 LR_REGS(EMU_SRC_DOCK_ADC1),
193 LR_REGS(EMU_SRC_DOCK_ADC2),
194 LR_REGS(EMU_SRC_HAMOA_ADC),
195 LR_REGS(EMU_SRC_MDOCK_SPDIF),
196 LR_REGS(EMU_SRC_HANA_SPDIF),
197 ADAT_REGS(EMU_SRC_MDOCK_ADAT),
198 ADAT_REGS(EMU_SRC_HANA_ADAT),
201 static_assert(ARRAY_SIZE(emu1010b_src_regs) == ARRAY_SIZE(emu1010b_src_texts));
203 /* 1616(m) cardbus */
205 #define EMU1616_COMMON_TEXTS \
207 PAIR_TEXTS("Mic", "A", "B"), \
213 static const char * const emu1616_src_texts[] = {
214 EMU1616_COMMON_TEXTS,
218 static const unsigned short emu1616_src_regs[] = {
220 PAIR_REGS(EMU_SRC_DOCK_MIC, _A, _B),
221 LR_REGS(EMU_SRC_DOCK_ADC1),
222 LR_REGS(EMU_SRC_DOCK_ADC2),
223 LR_REGS(EMU_SRC_MDOCK_SPDIF),
224 ADAT_REGS(EMU_SRC_MDOCK_ADAT),
227 static_assert(ARRAY_SIZE(emu1616_src_regs) == ARRAY_SIZE(emu1616_src_texts));
229 /* 0404 rev1 & rev2 */
231 #define EMU0404_COMMON_TEXTS \
236 static const char * const emu0404_src_texts[] = {
237 EMU0404_COMMON_TEXTS,
241 static const unsigned short emu0404_src_regs[] = {
243 LR_REGS(EMU_SRC_HAMOA_ADC),
244 LR_REGS(EMU_SRC_HANA_SPDIF),
247 static_assert(ARRAY_SIZE(emu0404_src_regs) == ARRAY_SIZE(emu0404_src_texts));
250 * Data destinations - physical EMU outputs.
251 * Each destination has an enum mixer control to choose a data source
254 #define LR_CTLS(base) LR_PS(base, " Playback Enum")
255 #define ADAT_CTLS(pfx) ADAT_PS(pfx, " Playback Enum")
259 static const char * const emu1010_output_texts[] = {
260 LR_CTLS("Dock DAC1"),
261 LR_CTLS("Dock DAC2"),
262 LR_CTLS("Dock DAC3"),
263 LR_CTLS("Dock DAC4"),
264 LR_CTLS("Dock Phones"),
265 LR_CTLS("Dock SPDIF"),
267 LR_CTLS("1010 SPDIF"),
270 static_assert(ARRAY_SIZE(emu1010_output_texts) <= NUM_OUTPUT_DESTS);
272 static const unsigned short emu1010_output_dst[] = {
273 LR_REGS(EMU_DST_DOCK_DAC1),
274 LR_REGS(EMU_DST_DOCK_DAC2),
275 LR_REGS(EMU_DST_DOCK_DAC3),
276 LR_REGS(EMU_DST_DOCK_DAC4),
277 LR_REGS(EMU_DST_DOCK_PHONES),
278 LR_REGS(EMU_DST_DOCK_SPDIF),
279 LR_REGS(EMU_DST_HAMOA_DAC),
280 LR_REGS(EMU_DST_HANA_SPDIF),
281 ADAT_REGS(EMU_DST_HANA_ADAT),
283 static_assert(ARRAY_SIZE(emu1010_output_dst) == ARRAY_SIZE(emu1010_output_texts));
285 static const unsigned short emu1010_output_dflt[] = {
286 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
287 EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
288 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5,
289 EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
290 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
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, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
295 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
297 static_assert(ARRAY_SIZE(emu1010_output_dflt) == ARRAY_SIZE(emu1010_output_dst));
301 static const char * const snd_emu1010b_output_texts[] = {
302 LR_CTLS("Dock DAC1"),
303 LR_CTLS("Dock DAC2"),
304 LR_CTLS("Dock DAC3"),
305 LR_CTLS("Dock SPDIF"),
308 LR_CTLS("1010 SPDIF"),
311 static_assert(ARRAY_SIZE(snd_emu1010b_output_texts) <= NUM_OUTPUT_DESTS);
313 static const unsigned short emu1010b_output_dst[] = {
314 LR_REGS(EMU_DST_DOCK_DAC1),
315 LR_REGS(EMU_DST_DOCK_DAC2),
316 LR_REGS(EMU_DST_DOCK_DAC3),
317 LR_REGS(EMU_DST_MDOCK_SPDIF),
318 ADAT_REGS(EMU_DST_MDOCK_ADAT),
319 LR_REGS(EMU_DST_HAMOA_DAC),
320 LR_REGS(EMU_DST_HANA_SPDIF),
321 ADAT_REGS(EMU_DST_HANA_ADAT),
323 static_assert(ARRAY_SIZE(emu1010b_output_dst) == ARRAY_SIZE(snd_emu1010b_output_texts));
325 static const unsigned short emu1010b_output_dflt[] = {
326 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
327 EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
328 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5,
329 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
330 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
331 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
332 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
333 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
334 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
335 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
338 /* 1616(m) cardbus */
340 static const char * const snd_emu1616_output_texts[] = {
341 LR_CTLS("Dock DAC1"),
342 LR_CTLS("Dock DAC2"),
343 LR_CTLS("Dock DAC3"),
344 LR_CTLS("Dock SPDIF"),
348 static_assert(ARRAY_SIZE(snd_emu1616_output_texts) <= NUM_OUTPUT_DESTS);
350 static const unsigned short emu1616_output_dst[] = {
351 LR_REGS(EMU_DST_DOCK_DAC1),
352 LR_REGS(EMU_DST_DOCK_DAC2),
353 LR_REGS(EMU_DST_DOCK_DAC3),
354 LR_REGS(EMU_DST_MDOCK_SPDIF),
355 ADAT_REGS(EMU_DST_MDOCK_ADAT),
356 EMU_DST_MANA_DAC_LEFT, EMU_DST_MANA_DAC_RIGHT,
358 static_assert(ARRAY_SIZE(emu1616_output_dst) == ARRAY_SIZE(snd_emu1616_output_texts));
360 static const unsigned short emu1616_output_dflt[] = {
361 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
362 EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
363 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5,
364 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
365 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1, EMU_SRC_ALICE_EMU32A+2, EMU_SRC_ALICE_EMU32A+3,
366 EMU_SRC_ALICE_EMU32A+4, EMU_SRC_ALICE_EMU32A+5, EMU_SRC_ALICE_EMU32A+6, EMU_SRC_ALICE_EMU32A+7,
367 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
369 static_assert(ARRAY_SIZE(emu1616_output_dflt) == ARRAY_SIZE(emu1616_output_dst));
371 /* 0404 rev1 & rev2 */
373 static const char * const snd_emu0404_output_texts[] = {
377 static_assert(ARRAY_SIZE(snd_emu0404_output_texts) <= NUM_OUTPUT_DESTS);
379 static const unsigned short emu0404_output_dst[] = {
380 LR_REGS(EMU_DST_HAMOA_DAC),
381 LR_REGS(EMU_DST_HANA_SPDIF),
383 static_assert(ARRAY_SIZE(emu0404_output_dst) == ARRAY_SIZE(snd_emu0404_output_texts));
385 static const unsigned short emu0404_output_dflt[] = {
386 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
387 EMU_SRC_ALICE_EMU32A+0, EMU_SRC_ALICE_EMU32A+1,
389 static_assert(ARRAY_SIZE(emu0404_output_dflt) == ARRAY_SIZE(emu0404_output_dst));
392 * Data destinations - FPGA outputs going to Alice2 (Audigy) for
393 * capture (EMU32 + I2S links)
394 * Each destination has an enum mixer control to choose a data source
397 static const char * const emu1010_input_texts[] = {
398 "DSP 0 Capture Enum",
399 "DSP 1 Capture Enum",
400 "DSP 2 Capture Enum",
401 "DSP 3 Capture Enum",
402 "DSP 4 Capture Enum",
403 "DSP 5 Capture Enum",
404 "DSP 6 Capture Enum",
405 "DSP 7 Capture Enum",
406 "DSP 8 Capture Enum",
407 "DSP 9 Capture Enum",
408 "DSP A Capture Enum",
409 "DSP B Capture Enum",
410 "DSP C Capture Enum",
411 "DSP D Capture Enum",
412 "DSP E Capture Enum",
413 "DSP F Capture Enum",
414 /* These exist only on rev1 EMU1010 cards. */
415 "DSP 10 Capture Enum",
416 "DSP 11 Capture Enum",
417 "DSP 12 Capture Enum",
418 "DSP 13 Capture Enum",
419 "DSP 14 Capture Enum",
420 "DSP 15 Capture Enum",
422 static_assert(ARRAY_SIZE(emu1010_input_texts) <= NUM_INPUT_DESTS);
424 static const unsigned short emu1010_input_dst[] = {
425 EMU_DST_ALICE2_EMU32_0,
426 EMU_DST_ALICE2_EMU32_1,
427 EMU_DST_ALICE2_EMU32_2,
428 EMU_DST_ALICE2_EMU32_3,
429 EMU_DST_ALICE2_EMU32_4,
430 EMU_DST_ALICE2_EMU32_5,
431 EMU_DST_ALICE2_EMU32_6,
432 EMU_DST_ALICE2_EMU32_7,
433 EMU_DST_ALICE2_EMU32_8,
434 EMU_DST_ALICE2_EMU32_9,
435 EMU_DST_ALICE2_EMU32_A,
436 EMU_DST_ALICE2_EMU32_B,
437 EMU_DST_ALICE2_EMU32_C,
438 EMU_DST_ALICE2_EMU32_D,
439 EMU_DST_ALICE2_EMU32_E,
440 EMU_DST_ALICE2_EMU32_F,
441 /* These exist only on rev1 EMU1010 cards. */
442 EMU_DST_ALICE_I2S0_LEFT,
443 EMU_DST_ALICE_I2S0_RIGHT,
444 EMU_DST_ALICE_I2S1_LEFT,
445 EMU_DST_ALICE_I2S1_RIGHT,
446 EMU_DST_ALICE_I2S2_LEFT,
447 EMU_DST_ALICE_I2S2_RIGHT,
449 static_assert(ARRAY_SIZE(emu1010_input_dst) == ARRAY_SIZE(emu1010_input_texts));
451 static const unsigned short emu1010_input_dflt[] = {
454 EMU_SRC_HAMOA_ADC_LEFT1,
455 EMU_SRC_HAMOA_ADC_RIGHT1,
456 EMU_SRC_DOCK_ADC1_LEFT1,
457 EMU_SRC_DOCK_ADC1_RIGHT1,
458 EMU_SRC_DOCK_ADC2_LEFT1,
459 EMU_SRC_DOCK_ADC2_RIGHT1,
460 /* Pavel Hofman - setting defaults for all capture channels.
461 * Defaults only, users will set their own values anyways, let's
462 * just copy/paste. */
465 EMU_SRC_HAMOA_ADC_LEFT1,
466 EMU_SRC_HAMOA_ADC_RIGHT1,
467 EMU_SRC_DOCK_ADC1_LEFT1,
468 EMU_SRC_DOCK_ADC1_RIGHT1,
469 EMU_SRC_DOCK_ADC2_LEFT1,
470 EMU_SRC_DOCK_ADC2_RIGHT1,
472 EMU_SRC_DOCK_ADC1_LEFT1,
473 EMU_SRC_DOCK_ADC1_RIGHT1,
474 EMU_SRC_DOCK_ADC2_LEFT1,
475 EMU_SRC_DOCK_ADC2_RIGHT1,
476 EMU_SRC_DOCK_ADC3_LEFT1,
477 EMU_SRC_DOCK_ADC3_RIGHT1,
479 static_assert(ARRAY_SIZE(emu1010_input_dflt) == ARRAY_SIZE(emu1010_input_dst));
481 static const unsigned short emu0404_input_dflt[] = {
482 EMU_SRC_HAMOA_ADC_LEFT1,
483 EMU_SRC_HAMOA_ADC_RIGHT1,
490 EMU_SRC_HANA_SPDIF_LEFT1,
491 EMU_SRC_HANA_SPDIF_RIGHT1,
500 struct snd_emu1010_routing_info {
501 const char * const *src_texts;
502 const char * const *out_texts;
503 const unsigned short *src_regs;
504 const unsigned short *out_regs;
505 const unsigned short *in_regs;
506 const unsigned short *out_dflts;
507 const unsigned short *in_dflts;
513 static const struct snd_emu1010_routing_info emu1010_routing_info[] = {
516 .src_regs = emu1010_src_regs,
517 .src_texts = emu1010_src_texts,
518 .n_srcs = ARRAY_SIZE(emu1010_src_texts),
520 .out_dflts = emu1010_output_dflt,
521 .out_regs = emu1010_output_dst,
522 .out_texts = emu1010_output_texts,
523 .n_outs = ARRAY_SIZE(emu1010_output_dst),
525 .in_dflts = emu1010_input_dflt,
526 .in_regs = emu1010_input_dst,
527 .n_ins = ARRAY_SIZE(emu1010_input_dst),
531 .src_regs = emu1010b_src_regs,
532 .src_texts = emu1010b_src_texts,
533 .n_srcs = ARRAY_SIZE(emu1010b_src_texts),
535 .out_dflts = emu1010b_output_dflt,
536 .out_regs = emu1010b_output_dst,
537 .out_texts = snd_emu1010b_output_texts,
538 .n_outs = ARRAY_SIZE(emu1010b_output_dst),
540 .in_dflts = emu1010_input_dflt,
541 .in_regs = emu1010_input_dst,
542 .n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
545 /* 1616(m) cardbus */
546 .src_regs = emu1616_src_regs,
547 .src_texts = emu1616_src_texts,
548 .n_srcs = ARRAY_SIZE(emu1616_src_texts),
550 .out_dflts = emu1616_output_dflt,
551 .out_regs = emu1616_output_dst,
552 .out_texts = snd_emu1616_output_texts,
553 .n_outs = ARRAY_SIZE(emu1616_output_dst),
555 .in_dflts = emu1010_input_dflt,
556 .in_regs = emu1010_input_dst,
557 .n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
561 .src_regs = emu0404_src_regs,
562 .src_texts = emu0404_src_texts,
563 .n_srcs = ARRAY_SIZE(emu0404_src_texts),
565 .out_dflts = emu0404_output_dflt,
566 .out_regs = emu0404_output_dst,
567 .out_texts = snd_emu0404_output_texts,
568 .n_outs = ARRAY_SIZE(emu0404_output_dflt),
570 .in_dflts = emu0404_input_dflt,
571 .in_regs = emu1010_input_dst,
572 .n_ins = ARRAY_SIZE(emu1010_input_dst) - 6,
576 static unsigned emu1010_idx(struct snd_emu10k1 *emu)
578 return emu->card_capabilities->emu_model - 1;
581 static void snd_emu1010_output_source_apply(struct snd_emu10k1 *emu,
582 int channel, int src)
584 const struct snd_emu1010_routing_info *emu_ri =
585 &emu1010_routing_info[emu1010_idx(emu)];
587 snd_emu1010_fpga_link_dst_src_write(emu,
588 emu_ri->out_regs[channel], emu_ri->src_regs[src]);
591 static void snd_emu1010_input_source_apply(struct snd_emu10k1 *emu,
592 int channel, int src)
594 const struct snd_emu1010_routing_info *emu_ri =
595 &emu1010_routing_info[emu1010_idx(emu)];
597 snd_emu1010_fpga_link_dst_src_write(emu,
598 emu_ri->in_regs[channel], emu_ri->src_regs[src]);
601 static void snd_emu1010_apply_sources(struct snd_emu10k1 *emu)
603 const struct snd_emu1010_routing_info *emu_ri =
604 &emu1010_routing_info[emu1010_idx(emu)];
606 for (unsigned i = 0; i < emu_ri->n_outs; i++)
607 snd_emu1010_output_source_apply(
608 emu, i, emu->emu1010.output_source[i]);
609 for (unsigned i = 0; i < emu_ri->n_ins; i++)
610 snd_emu1010_input_source_apply(
611 emu, i, emu->emu1010.input_source[i]);
614 static u8 emu1010_map_source(const struct snd_emu1010_routing_info *emu_ri,
617 for (unsigned i = 0; i < emu_ri->n_srcs; i++)
618 if (val == emu_ri->src_regs[i])
623 static int snd_emu1010_input_output_source_info(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_info *uinfo)
626 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
627 const struct snd_emu1010_routing_info *emu_ri =
628 &emu1010_routing_info[emu1010_idx(emu)];
630 return snd_ctl_enum_info(uinfo, 1, emu_ri->n_srcs, emu_ri->src_texts);
633 static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol,
634 struct snd_ctl_elem_value *ucontrol)
636 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
637 const struct snd_emu1010_routing_info *emu_ri =
638 &emu1010_routing_info[emu1010_idx(emu)];
639 unsigned channel = kcontrol->private_value;
641 if (channel >= emu_ri->n_outs)
643 ucontrol->value.enumerated.item[0] = emu->emu1010.output_source[channel];
647 static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_value *ucontrol)
650 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
651 const struct snd_emu1010_routing_info *emu_ri =
652 &emu1010_routing_info[emu1010_idx(emu)];
653 unsigned val = ucontrol->value.enumerated.item[0];
654 unsigned channel = kcontrol->private_value;
657 if (val >= emu_ri->n_srcs)
659 if (channel >= emu_ri->n_outs)
661 change = (emu->emu1010.output_source[channel] != val);
663 emu->emu1010.output_source[channel] = val;
664 snd_emu1010_output_source_apply(emu, channel, val);
669 static const struct snd_kcontrol_new emu1010_output_source_ctl = {
670 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
671 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
672 .info = snd_emu1010_input_output_source_info,
673 .get = snd_emu1010_output_source_get,
674 .put = snd_emu1010_output_source_put
677 static int snd_emu1010_input_source_get(struct snd_kcontrol *kcontrol,
678 struct snd_ctl_elem_value *ucontrol)
680 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
681 const struct snd_emu1010_routing_info *emu_ri =
682 &emu1010_routing_info[emu1010_idx(emu)];
683 unsigned channel = kcontrol->private_value;
685 if (channel >= emu_ri->n_ins)
687 ucontrol->value.enumerated.item[0] = emu->emu1010.input_source[channel];
691 static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_value *ucontrol)
694 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
695 const struct snd_emu1010_routing_info *emu_ri =
696 &emu1010_routing_info[emu1010_idx(emu)];
697 unsigned val = ucontrol->value.enumerated.item[0];
698 unsigned channel = kcontrol->private_value;
701 if (val >= emu_ri->n_srcs)
703 if (channel >= emu_ri->n_ins)
705 change = (emu->emu1010.input_source[channel] != val);
707 emu->emu1010.input_source[channel] = val;
708 snd_emu1010_input_source_apply(emu, channel, val);
713 static const struct snd_kcontrol_new emu1010_input_source_ctl = {
714 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
715 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
716 .info = snd_emu1010_input_output_source_info,
717 .get = snd_emu1010_input_source_get,
718 .put = snd_emu1010_input_source_put
721 static int add_emu1010_source_mixers(struct snd_emu10k1 *emu)
723 const struct snd_emu1010_routing_info *emu_ri =
724 &emu1010_routing_info[emu1010_idx(emu)];
727 err = add_ctls(emu, &emu1010_output_source_ctl,
728 emu_ri->out_texts, emu_ri->n_outs);
731 err = add_ctls(emu, &emu1010_input_source_ctl,
732 emu1010_input_texts, emu_ri->n_ins);
737 static const char * const snd_emu1010_adc_pads[] = {
738 "ADC1 14dB PAD 0202 Capture Switch",
739 "ADC1 14dB PAD Audio Dock Capture Switch",
740 "ADC2 14dB PAD Audio Dock Capture Switch",
741 "ADC3 14dB PAD Audio Dock Capture Switch",
744 static const unsigned short snd_emu1010_adc_pad_regs[] = {
745 EMU_HANA_0202_ADC_PAD1,
746 EMU_HANA_DOCK_ADC_PAD1,
747 EMU_HANA_DOCK_ADC_PAD2,
748 EMU_HANA_DOCK_ADC_PAD3,
751 #define snd_emu1010_adc_pads_info snd_ctl_boolean_mono_info
753 static int snd_emu1010_adc_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
755 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
756 unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value];
758 ucontrol->value.integer.value[0] = (emu->emu1010.adc_pads & mask) ? 1 : 0;
762 static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
764 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
765 unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value];
766 unsigned int val, cache;
769 val = ucontrol->value.integer.value[0];
770 cache = emu->emu1010.adc_pads;
772 cache = cache | mask;
774 cache = cache & ~mask;
775 change = (cache != emu->emu1010.adc_pads);
777 snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, cache );
778 emu->emu1010.adc_pads = cache;
784 static const struct snd_kcontrol_new emu1010_adc_pads_ctl = {
785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
786 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
787 .info = snd_emu1010_adc_pads_info,
788 .get = snd_emu1010_adc_pads_get,
789 .put = snd_emu1010_adc_pads_put
793 static const char * const snd_emu1010_dac_pads[] = {
794 "DAC1 0202 14dB PAD Playback Switch",
795 "DAC1 Audio Dock 14dB PAD Playback Switch",
796 "DAC2 Audio Dock 14dB PAD Playback Switch",
797 "DAC3 Audio Dock 14dB PAD Playback Switch",
798 "DAC4 Audio Dock 14dB PAD Playback Switch",
801 static const unsigned short snd_emu1010_dac_regs[] = {
802 EMU_HANA_0202_DAC_PAD1,
803 EMU_HANA_DOCK_DAC_PAD1,
804 EMU_HANA_DOCK_DAC_PAD2,
805 EMU_HANA_DOCK_DAC_PAD3,
806 EMU_HANA_DOCK_DAC_PAD4,
809 #define snd_emu1010_dac_pads_info snd_ctl_boolean_mono_info
811 static int snd_emu1010_dac_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
813 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
814 unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value];
816 ucontrol->value.integer.value[0] = (emu->emu1010.dac_pads & mask) ? 1 : 0;
820 static int snd_emu1010_dac_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
822 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
823 unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value];
824 unsigned int val, cache;
827 val = ucontrol->value.integer.value[0];
828 cache = emu->emu1010.dac_pads;
830 cache = cache | mask;
832 cache = cache & ~mask;
833 change = (cache != emu->emu1010.dac_pads);
835 snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, cache );
836 emu->emu1010.dac_pads = cache;
842 static const struct snd_kcontrol_new emu1010_dac_pads_ctl = {
843 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
844 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
845 .info = snd_emu1010_dac_pads_info,
846 .get = snd_emu1010_dac_pads_get,
847 .put = snd_emu1010_dac_pads_put
851 struct snd_emu1010_pads_info {
852 const char * const *adc_ctls, * const *dac_ctls;
853 unsigned n_adc_ctls, n_dac_ctls;
856 static const struct snd_emu1010_pads_info emu1010_pads_info[] = {
859 .adc_ctls = snd_emu1010_adc_pads,
860 .n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads),
861 .dac_ctls = snd_emu1010_dac_pads,
862 .n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads),
866 .adc_ctls = snd_emu1010_adc_pads,
867 .n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads) - 1,
868 .dac_ctls = snd_emu1010_dac_pads,
869 .n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads) - 1,
872 /* 1616(m) cardbus */
873 .adc_ctls = snd_emu1010_adc_pads + 1,
874 .n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads) - 2,
875 .dac_ctls = snd_emu1010_dac_pads + 1,
876 .n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads) - 2,
887 static const char * const emu1010_clock_texts[] = {
888 "44100", "48000", "SPDIF", "ADAT", "Dock", "BNC"
891 static const u8 emu1010_clock_vals[] = {
892 EMU_HANA_WCLOCK_INT_44_1K,
893 EMU_HANA_WCLOCK_INT_48K,
894 EMU_HANA_WCLOCK_HANA_SPDIF_IN,
895 EMU_HANA_WCLOCK_HANA_ADAT_IN,
896 EMU_HANA_WCLOCK_2ND_HANA,
897 EMU_HANA_WCLOCK_SYNC_BNC,
900 static const char * const emu0404_clock_texts[] = {
901 "44100", "48000", "SPDIF", "BNC"
904 static const u8 emu0404_clock_vals[] = {
905 EMU_HANA_WCLOCK_INT_44_1K,
906 EMU_HANA_WCLOCK_INT_48K,
907 EMU_HANA_WCLOCK_HANA_SPDIF_IN,
908 EMU_HANA_WCLOCK_SYNC_BNC,
911 struct snd_emu1010_clock_info {
912 const char * const *texts;
917 static const struct snd_emu1010_clock_info emu1010_clock_info[] = {
920 .texts = emu1010_clock_texts,
921 .vals = emu1010_clock_vals,
922 .num = ARRAY_SIZE(emu1010_clock_vals),
926 .texts = emu1010_clock_texts,
927 .vals = emu1010_clock_vals,
928 .num = ARRAY_SIZE(emu1010_clock_vals) - 1,
932 .texts = emu1010_clock_texts,
933 // TODO: determine what is actually available.
934 // Pedantically, *every* source comes from the 2nd FPGA, as the
935 // card itself has no own (digital) audio ports. The user manual
936 // claims that ADAT and S/PDIF clock sources are separate, which
937 // can mean two things: either E-MU mapped the dock's sources to
938 // the primary ones, or they determine the meaning of the "Dock"
939 // source depending on how the ports are actually configured
940 // (which the 2nd FPGA must be doing anyway).
941 .vals = emu1010_clock_vals,
942 .num = ARRAY_SIZE(emu1010_clock_vals),
946 .texts = emu0404_clock_texts,
947 .vals = emu0404_clock_vals,
948 .num = ARRAY_SIZE(emu0404_clock_vals),
952 static int snd_emu1010_clock_source_info(struct snd_kcontrol *kcontrol,
953 struct snd_ctl_elem_info *uinfo)
955 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
956 const struct snd_emu1010_clock_info *emu_ci =
957 &emu1010_clock_info[emu1010_idx(emu)];
959 return snd_ctl_enum_info(uinfo, 1, emu_ci->num, emu_ci->texts);
962 static int snd_emu1010_clock_source_get(struct snd_kcontrol *kcontrol,
963 struct snd_ctl_elem_value *ucontrol)
965 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
967 ucontrol->value.enumerated.item[0] = emu->emu1010.clock_source;
971 static int snd_emu1010_clock_source_put(struct snd_kcontrol *kcontrol,
972 struct snd_ctl_elem_value *ucontrol)
974 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
975 const struct snd_emu1010_clock_info *emu_ci =
976 &emu1010_clock_info[emu1010_idx(emu)];
980 val = ucontrol->value.enumerated.item[0] ;
981 if (val >= emu_ci->num)
983 spin_lock_irq(&emu->reg_lock);
984 change = (emu->emu1010.clock_source != val);
986 emu->emu1010.clock_source = val;
987 emu->emu1010.wclock = emu_ci->vals[val];
988 snd_emu1010_update_clock(emu);
990 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE);
991 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, emu->emu1010.wclock);
992 spin_unlock_irq(&emu->reg_lock);
994 msleep(10); // Allow DLL to settle
995 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
997 spin_unlock_irq(&emu->reg_lock);
1002 static const struct snd_kcontrol_new snd_emu1010_clock_source =
1004 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1005 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1006 .name = "Clock Source",
1008 .info = snd_emu1010_clock_source_info,
1009 .get = snd_emu1010_clock_source_get,
1010 .put = snd_emu1010_clock_source_put
1013 static int snd_emu1010_clock_fallback_info(struct snd_kcontrol *kcontrol,
1014 struct snd_ctl_elem_info *uinfo)
1016 static const char * const texts[2] = {
1020 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1023 static int snd_emu1010_clock_fallback_get(struct snd_kcontrol *kcontrol,
1024 struct snd_ctl_elem_value *ucontrol)
1026 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1028 ucontrol->value.enumerated.item[0] = emu->emu1010.clock_fallback;
1032 static int snd_emu1010_clock_fallback_put(struct snd_kcontrol *kcontrol,
1033 struct snd_ctl_elem_value *ucontrol)
1035 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1036 unsigned int val = ucontrol->value.enumerated.item[0];
1041 change = (emu->emu1010.clock_fallback != val);
1043 emu->emu1010.clock_fallback = val;
1044 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 1 - val);
1049 static const struct snd_kcontrol_new snd_emu1010_clock_fallback =
1051 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1052 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1053 .name = "Clock Fallback",
1055 .info = snd_emu1010_clock_fallback_info,
1056 .get = snd_emu1010_clock_fallback_get,
1057 .put = snd_emu1010_clock_fallback_put
1060 static int snd_emu1010_optical_out_info(struct snd_kcontrol *kcontrol,
1061 struct snd_ctl_elem_info *uinfo)
1063 static const char * const texts[2] = {
1067 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1070 static int snd_emu1010_optical_out_get(struct snd_kcontrol *kcontrol,
1071 struct snd_ctl_elem_value *ucontrol)
1073 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1075 ucontrol->value.enumerated.item[0] = emu->emu1010.optical_out;
1079 static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol,
1080 struct snd_ctl_elem_value *ucontrol)
1082 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1087 val = ucontrol->value.enumerated.item[0];
1088 /* Limit: uinfo->value.enumerated.items = 2; */
1091 change = (emu->emu1010.optical_out != val);
1093 emu->emu1010.optical_out = val;
1094 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) |
1095 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF);
1096 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
1101 static const struct snd_kcontrol_new snd_emu1010_optical_out = {
1102 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1103 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1104 .name = "Optical Output Mode",
1106 .info = snd_emu1010_optical_out_info,
1107 .get = snd_emu1010_optical_out_get,
1108 .put = snd_emu1010_optical_out_put
1111 static int snd_emu1010_optical_in_info(struct snd_kcontrol *kcontrol,
1112 struct snd_ctl_elem_info *uinfo)
1114 static const char * const texts[2] = {
1118 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1121 static int snd_emu1010_optical_in_get(struct snd_kcontrol *kcontrol,
1122 struct snd_ctl_elem_value *ucontrol)
1124 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1126 ucontrol->value.enumerated.item[0] = emu->emu1010.optical_in;
1130 static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol,
1131 struct snd_ctl_elem_value *ucontrol)
1133 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1138 val = ucontrol->value.enumerated.item[0];
1139 /* Limit: uinfo->value.enumerated.items = 2; */
1142 change = (emu->emu1010.optical_in != val);
1144 emu->emu1010.optical_in = val;
1145 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : EMU_HANA_OPTICAL_IN_SPDIF) |
1146 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : EMU_HANA_OPTICAL_OUT_SPDIF);
1147 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
1152 static const struct snd_kcontrol_new snd_emu1010_optical_in = {
1153 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1154 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1155 .name = "Optical Input Mode",
1157 .info = snd_emu1010_optical_in_info,
1158 .get = snd_emu1010_optical_in_get,
1159 .put = snd_emu1010_optical_in_put
1162 static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
1163 struct snd_ctl_elem_info *uinfo)
1166 static const char * const texts[4] = {
1167 "Unknown1", "Unknown2", "Mic", "Line"
1170 static const char * const texts[2] = {
1174 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1177 static int snd_audigy_i2c_capture_source_get(struct snd_kcontrol *kcontrol,
1178 struct snd_ctl_elem_value *ucontrol)
1180 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1182 ucontrol->value.enumerated.item[0] = emu->i2c_capture_source;
1186 static int snd_audigy_i2c_capture_source_put(struct snd_kcontrol *kcontrol,
1187 struct snd_ctl_elem_value *ucontrol)
1189 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1190 unsigned int source_id;
1191 unsigned int ngain, ogain;
1195 /* If the capture source has changed,
1196 * update the capture volume from the cached value
1197 * for the particular source.
1199 source_id = ucontrol->value.enumerated.item[0];
1200 /* Limit: uinfo->value.enumerated.items = 2; */
1201 /* emu->i2c_capture_volume */
1204 change = (emu->i2c_capture_source != source_id);
1206 snd_emu10k1_i2c_write(emu, ADC_MUX, 0); /* Mute input */
1207 spin_lock_irq(&emu->emu_lock);
1208 gpio = inw(emu->port + A_IOCFG);
1210 outw(gpio | 0x4, emu->port + A_IOCFG);
1212 outw(gpio & ~0x4, emu->port + A_IOCFG);
1213 spin_unlock_irq(&emu->emu_lock);
1215 ngain = emu->i2c_capture_volume[source_id][0]; /* Left */
1216 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */
1218 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff));
1219 ngain = emu->i2c_capture_volume[source_id][1]; /* Right */
1220 ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */
1222 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));
1224 source = 1 << (source_id + 2);
1225 snd_emu10k1_i2c_write(emu, ADC_MUX, source); /* Set source */
1226 emu->i2c_capture_source = source_id;
1231 static const struct snd_kcontrol_new snd_audigy_i2c_capture_source =
1233 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1234 .name = "Capture Source",
1235 .info = snd_audigy_i2c_capture_source_info,
1236 .get = snd_audigy_i2c_capture_source_get,
1237 .put = snd_audigy_i2c_capture_source_put
1240 static int snd_audigy_i2c_volume_info(struct snd_kcontrol *kcontrol,
1241 struct snd_ctl_elem_info *uinfo)
1243 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1245 uinfo->value.integer.min = 0;
1246 uinfo->value.integer.max = 255;
1250 static int snd_audigy_i2c_volume_get(struct snd_kcontrol *kcontrol,
1251 struct snd_ctl_elem_value *ucontrol)
1253 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1254 unsigned int source_id;
1256 source_id = kcontrol->private_value;
1257 /* Limit: emu->i2c_capture_volume */
1258 /* capture_source: uinfo->value.enumerated.items = 2 */
1262 ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0];
1263 ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1];
1267 static int snd_audigy_i2c_volume_put(struct snd_kcontrol *kcontrol,
1268 struct snd_ctl_elem_value *ucontrol)
1270 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1272 unsigned int ngain0, ngain1;
1273 unsigned int source_id;
1276 source_id = kcontrol->private_value;
1277 /* Limit: emu->i2c_capture_volume */
1278 /* capture_source: uinfo->value.enumerated.items = 2 */
1281 ngain0 = ucontrol->value.integer.value[0];
1282 ngain1 = ucontrol->value.integer.value[1];
1287 ogain = emu->i2c_capture_volume[source_id][0]; /* Left */
1288 if (ogain != ngain0) {
1289 if (emu->i2c_capture_source == source_id)
1290 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCL, ngain0);
1291 emu->i2c_capture_volume[source_id][0] = ngain0;
1294 ogain = emu->i2c_capture_volume[source_id][1]; /* Right */
1295 if (ogain != ngain1) {
1296 if (emu->i2c_capture_source == source_id)
1297 snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ngain1);
1298 emu->i2c_capture_volume[source_id][1] = ngain1;
1305 static const struct snd_kcontrol_new i2c_volume_ctl = {
1306 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1307 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1308 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1309 .info = snd_audigy_i2c_volume_info,
1310 .get = snd_audigy_i2c_volume_get,
1311 .put = snd_audigy_i2c_volume_put,
1312 .tlv = { .p = snd_audigy_db_scale2 }
1315 static const char * const snd_audigy_i2c_volume_ctls[] = {
1316 "Mic Capture Volume",
1317 "Line Capture Volume",
1321 static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1323 static const char * const texts[] = {"44100", "48000", "96000"};
1325 return snd_ctl_enum_info(uinfo, 1, 3, texts);
1328 static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
1329 struct snd_ctl_elem_value *ucontrol)
1331 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1334 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
1335 switch (tmp & A_SPDIF_RATE_MASK) {
1337 ucontrol->value.enumerated.item[0] = 0;
1340 ucontrol->value.enumerated.item[0] = 1;
1343 ucontrol->value.enumerated.item[0] = 2;
1346 ucontrol->value.enumerated.item[0] = 1;
1351 static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol,
1352 struct snd_ctl_elem_value *ucontrol)
1354 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1356 unsigned int reg, val, tmp;
1358 switch(ucontrol->value.enumerated.item[0]) {
1360 val = A_SPDIF_44100;
1363 val = A_SPDIF_48000;
1366 val = A_SPDIF_96000;
1369 val = A_SPDIF_48000;
1374 spin_lock_irq(&emu->reg_lock);
1375 reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
1376 tmp = reg & ~A_SPDIF_RATE_MASK;
1378 change = (tmp != reg);
1380 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
1381 spin_unlock_irq(&emu->reg_lock);
1385 static const struct snd_kcontrol_new snd_audigy_spdif_output_rate =
1387 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1388 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1389 .name = "Audigy SPDIF Output Sample Rate",
1391 .info = snd_audigy_spdif_output_rate_info,
1392 .get = snd_audigy_spdif_output_rate_get,
1393 .put = snd_audigy_spdif_output_rate_put
1397 static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol,
1398 struct snd_ctl_elem_value *ucontrol)
1400 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1401 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1405 /* Limit: emu->spdif_bits */
1408 val = (ucontrol->value.iec958.status[0] << 0) |
1409 (ucontrol->value.iec958.status[1] << 8) |
1410 (ucontrol->value.iec958.status[2] << 16) |
1411 (ucontrol->value.iec958.status[3] << 24);
1412 change = val != emu->spdif_bits[idx];
1414 snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val);
1415 emu->spdif_bits[idx] = val;
1420 static const struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
1422 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1423 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1424 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
1426 .info = snd_emu10k1_spdif_info,
1427 .get = snd_emu10k1_spdif_get_mask
1430 static const struct snd_kcontrol_new snd_emu10k1_spdif_control =
1432 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1433 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1435 .info = snd_emu10k1_spdif_info,
1436 .get = snd_emu10k1_spdif_get,
1437 .put = snd_emu10k1_spdif_put
1441 static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route)
1444 snd_emu10k1_ptr_write_multiple(emu, voice,
1445 A_FXRT1, snd_emu10k1_compose_audigy_fxrt1(route),
1446 A_FXRT2, snd_emu10k1_compose_audigy_fxrt2(route),
1449 snd_emu10k1_ptr_write(emu, FXRT, voice,
1450 snd_emu10k1_compose_send_routing(route));
1454 static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume)
1456 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]);
1457 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]);
1458 snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]);
1459 snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]);
1461 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice,
1462 snd_emu10k1_compose_audigy_sendamounts(volume));
1466 /* PCM stream controls */
1468 static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1470 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1471 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1472 uinfo->count = emu->audigy ? 3*8 : 3*4;
1473 uinfo->value.integer.min = 0;
1474 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
1478 static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol,
1479 struct snd_ctl_elem_value *ucontrol)
1481 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1482 struct snd_emu10k1_pcm_mixer *mix =
1483 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1485 int num_efx = emu->audigy ? 8 : 4;
1486 int mask = emu->audigy ? 0x3f : 0x0f;
1488 for (voice = 0; voice < 3; voice++)
1489 for (idx = 0; idx < num_efx; idx++)
1490 ucontrol->value.integer.value[(voice * num_efx) + idx] =
1491 mix->send_routing[voice][idx] & mask;
1495 static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol,
1496 struct snd_ctl_elem_value *ucontrol)
1498 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1499 struct snd_emu10k1_pcm_mixer *mix =
1500 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1501 int change = 0, voice, idx, val;
1502 int num_efx = emu->audigy ? 8 : 4;
1503 int mask = emu->audigy ? 0x3f : 0x0f;
1505 spin_lock_irq(&emu->reg_lock);
1506 for (voice = 0; voice < 3; voice++)
1507 for (idx = 0; idx < num_efx; idx++) {
1508 val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask;
1509 if (mix->send_routing[voice][idx] != val) {
1510 mix->send_routing[voice][idx] = val;
1514 if (change && mix->epcm && mix->epcm->voices[0]) {
1515 if (!mix->epcm->voices[0]->last) {
1516 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
1517 &mix->send_routing[1][0]);
1518 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number + 1,
1519 &mix->send_routing[2][0]);
1521 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
1522 &mix->send_routing[0][0]);
1525 spin_unlock_irq(&emu->reg_lock);
1529 static const struct snd_kcontrol_new snd_emu10k1_send_routing_control =
1531 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1532 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1533 .name = "EMU10K1 PCM Send Routing",
1535 .info = snd_emu10k1_send_routing_info,
1536 .get = snd_emu10k1_send_routing_get,
1537 .put = snd_emu10k1_send_routing_put
1540 static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1542 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1543 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1544 uinfo->count = emu->audigy ? 3*8 : 3*4;
1545 uinfo->value.integer.min = 0;
1546 uinfo->value.integer.max = 255;
1550 static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol,
1551 struct snd_ctl_elem_value *ucontrol)
1553 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1554 struct snd_emu10k1_pcm_mixer *mix =
1555 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1557 int num_efx = emu->audigy ? 8 : 4;
1559 for (idx = 0; idx < 3*num_efx; idx++)
1560 ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx];
1564 static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol,
1565 struct snd_ctl_elem_value *ucontrol)
1567 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1568 struct snd_emu10k1_pcm_mixer *mix =
1569 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1570 int change = 0, idx, val;
1571 int num_efx = emu->audigy ? 8 : 4;
1573 spin_lock_irq(&emu->reg_lock);
1574 for (idx = 0; idx < 3*num_efx; idx++) {
1575 val = ucontrol->value.integer.value[idx] & 255;
1576 if (mix->send_volume[idx/num_efx][idx%num_efx] != val) {
1577 mix->send_volume[idx/num_efx][idx%num_efx] = val;
1581 if (change && mix->epcm && mix->epcm->voices[0]) {
1582 if (!mix->epcm->voices[0]->last) {
1583 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
1584 &mix->send_volume[1][0]);
1585 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number + 1,
1586 &mix->send_volume[2][0]);
1588 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
1589 &mix->send_volume[0][0]);
1592 spin_unlock_irq(&emu->reg_lock);
1596 static const struct snd_kcontrol_new snd_emu10k1_send_volume_control =
1598 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1599 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1600 .name = "EMU10K1 PCM Send Volume",
1602 .info = snd_emu10k1_send_volume_info,
1603 .get = snd_emu10k1_send_volume_get,
1604 .put = snd_emu10k1_send_volume_put
1607 static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1609 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1611 uinfo->value.integer.min = 0;
1612 uinfo->value.integer.max = 0x1fffd;
1616 static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1619 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1620 struct snd_emu10k1_pcm_mixer *mix =
1621 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1624 for (idx = 0; idx < 3; idx++)
1625 ucontrol->value.integer.value[idx] = mix->attn[idx] * 0xffffU / 0x8000U;
1629 static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,
1630 struct snd_ctl_elem_value *ucontrol)
1632 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1633 struct snd_emu10k1_pcm_mixer *mix =
1634 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1635 int change = 0, idx, val;
1637 spin_lock_irq(&emu->reg_lock);
1638 for (idx = 0; idx < 3; idx++) {
1639 unsigned uval = ucontrol->value.integer.value[idx] & 0x1ffff;
1640 val = uval * 0x8000U / 0xffffU;
1641 if (mix->attn[idx] != val) {
1642 mix->attn[idx] = val;
1646 if (change && mix->epcm && mix->epcm->voices[0]) {
1647 if (!mix->epcm->voices[0]->last) {
1648 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]);
1649 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number + 1, mix->attn[2]);
1651 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]);
1654 spin_unlock_irq(&emu->reg_lock);
1658 static const struct snd_kcontrol_new snd_emu10k1_attn_control =
1660 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1661 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1662 .name = "EMU10K1 PCM Volume",
1664 .info = snd_emu10k1_attn_info,
1665 .get = snd_emu10k1_attn_get,
1666 .put = snd_emu10k1_attn_put
1669 /* Mutichannel PCM stream controls */
1671 static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1673 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1674 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1675 uinfo->count = emu->audigy ? 8 : 4;
1676 uinfo->value.integer.min = 0;
1677 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
1681 static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol,
1682 struct snd_ctl_elem_value *ucontrol)
1684 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1685 struct snd_emu10k1_pcm_mixer *mix =
1686 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1688 int num_efx = emu->audigy ? 8 : 4;
1689 int mask = emu->audigy ? 0x3f : 0x0f;
1691 for (idx = 0; idx < num_efx; idx++)
1692 ucontrol->value.integer.value[idx] =
1693 mix->send_routing[0][idx] & mask;
1697 static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol,
1698 struct snd_ctl_elem_value *ucontrol)
1700 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1701 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1702 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1703 int change = 0, idx, val;
1704 int num_efx = emu->audigy ? 8 : 4;
1705 int mask = emu->audigy ? 0x3f : 0x0f;
1707 spin_lock_irq(&emu->reg_lock);
1708 for (idx = 0; idx < num_efx; idx++) {
1709 val = ucontrol->value.integer.value[idx] & mask;
1710 if (mix->send_routing[0][idx] != val) {
1711 mix->send_routing[0][idx] = val;
1716 if (change && mix->epcm) {
1717 if (mix->epcm->voices[ch]) {
1718 update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number,
1719 &mix->send_routing[0][0]);
1722 spin_unlock_irq(&emu->reg_lock);
1726 static const struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
1728 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1729 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1730 .name = "Multichannel PCM Send Routing",
1732 .info = snd_emu10k1_efx_send_routing_info,
1733 .get = snd_emu10k1_efx_send_routing_get,
1734 .put = snd_emu10k1_efx_send_routing_put
1737 static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1739 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1740 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1741 uinfo->count = emu->audigy ? 8 : 4;
1742 uinfo->value.integer.min = 0;
1743 uinfo->value.integer.max = 255;
1747 static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol,
1748 struct snd_ctl_elem_value *ucontrol)
1750 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1751 struct snd_emu10k1_pcm_mixer *mix =
1752 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1754 int num_efx = emu->audigy ? 8 : 4;
1756 for (idx = 0; idx < num_efx; idx++)
1757 ucontrol->value.integer.value[idx] = mix->send_volume[0][idx];
1761 static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol,
1762 struct snd_ctl_elem_value *ucontrol)
1764 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1765 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1766 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1767 int change = 0, idx, val;
1768 int num_efx = emu->audigy ? 8 : 4;
1770 spin_lock_irq(&emu->reg_lock);
1771 for (idx = 0; idx < num_efx; idx++) {
1772 val = ucontrol->value.integer.value[idx] & 255;
1773 if (mix->send_volume[0][idx] != val) {
1774 mix->send_volume[0][idx] = val;
1778 if (change && mix->epcm) {
1779 if (mix->epcm->voices[ch]) {
1780 update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number,
1781 &mix->send_volume[0][0]);
1784 spin_unlock_irq(&emu->reg_lock);
1789 static const struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
1791 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1792 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1793 .name = "Multichannel PCM Send Volume",
1795 .info = snd_emu10k1_efx_send_volume_info,
1796 .get = snd_emu10k1_efx_send_volume_get,
1797 .put = snd_emu10k1_efx_send_volume_put
1800 static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1802 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1804 uinfo->value.integer.min = 0;
1805 uinfo->value.integer.max = 0x1fffd;
1809 static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol,
1810 struct snd_ctl_elem_value *ucontrol)
1812 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1813 struct snd_emu10k1_pcm_mixer *mix =
1814 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1816 ucontrol->value.integer.value[0] = mix->attn[0] * 0xffffU / 0x8000U;
1820 static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol,
1821 struct snd_ctl_elem_value *ucontrol)
1823 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1824 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1825 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1826 int change = 0, val;
1829 spin_lock_irq(&emu->reg_lock);
1830 uval = ucontrol->value.integer.value[0] & 0x1ffff;
1831 val = uval * 0x8000U / 0xffffU;
1832 if (mix->attn[0] != val) {
1836 if (change && mix->epcm) {
1837 if (mix->epcm->voices[ch]) {
1838 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]);
1841 spin_unlock_irq(&emu->reg_lock);
1845 static const struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
1847 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1848 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1849 .name = "Multichannel PCM Volume",
1851 .info = snd_emu10k1_efx_attn_info,
1852 .get = snd_emu10k1_efx_attn_get,
1853 .put = snd_emu10k1_efx_attn_put
1856 #define snd_emu10k1_shared_spdif_info snd_ctl_boolean_mono_info
1858 static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
1859 struct snd_ctl_elem_value *ucontrol)
1861 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1864 ucontrol->value.integer.value[0] = inw(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
1866 ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
1867 if (emu->card_capabilities->invert_shared_spdif)
1868 ucontrol->value.integer.value[0] =
1869 !ucontrol->value.integer.value[0];
1874 static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
1875 struct snd_ctl_elem_value *ucontrol)
1877 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1878 unsigned int reg, val, sw;
1881 sw = ucontrol->value.integer.value[0];
1882 if (emu->card_capabilities->invert_shared_spdif)
1884 spin_lock_irq(&emu->emu_lock);
1885 if ( emu->card_capabilities->i2c_adc) {
1886 /* Do nothing for Audigy 2 ZS Notebook */
1887 } else if (emu->audigy) {
1888 reg = inw(emu->port + A_IOCFG);
1889 val = sw ? A_IOCFG_GPOUT0 : 0;
1890 change = (reg & A_IOCFG_GPOUT0) != val;
1892 reg &= ~A_IOCFG_GPOUT0;
1894 outw(reg | val, emu->port + A_IOCFG);
1897 reg = inl(emu->port + HCFG);
1898 val = sw ? HCFG_GPOUT0 : 0;
1899 change |= (reg & HCFG_GPOUT0) != val;
1901 reg &= ~HCFG_GPOUT0;
1903 outl(reg | val, emu->port + HCFG);
1905 spin_unlock_irq(&emu->emu_lock);
1909 static const struct snd_kcontrol_new snd_emu10k1_shared_spdif =
1911 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1912 .name = "SB Live Analog/Digital Output Jack",
1913 .info = snd_emu10k1_shared_spdif_info,
1914 .get = snd_emu10k1_shared_spdif_get,
1915 .put = snd_emu10k1_shared_spdif_put
1918 static const struct snd_kcontrol_new snd_audigy_shared_spdif =
1920 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1921 .name = "Audigy Analog/Digital Output Jack",
1922 .info = snd_emu10k1_shared_spdif_info,
1923 .get = snd_emu10k1_shared_spdif_get,
1924 .put = snd_emu10k1_shared_spdif_put
1927 /* workaround for too low volume on Audigy due to 16bit/24bit conversion */
1929 #define snd_audigy_capture_boost_info snd_ctl_boolean_mono_info
1931 static int snd_audigy_capture_boost_get(struct snd_kcontrol *kcontrol,
1932 struct snd_ctl_elem_value *ucontrol)
1934 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1937 /* FIXME: better to use a cached version */
1938 val = snd_ac97_read(emu->ac97, AC97_REC_GAIN);
1939 ucontrol->value.integer.value[0] = !!val;
1943 static int snd_audigy_capture_boost_put(struct snd_kcontrol *kcontrol,
1944 struct snd_ctl_elem_value *ucontrol)
1946 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1949 if (ucontrol->value.integer.value[0])
1953 return snd_ac97_update(emu->ac97, AC97_REC_GAIN, val);
1956 static const struct snd_kcontrol_new snd_audigy_capture_boost =
1958 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1959 .name = "Mic Extra Boost",
1960 .info = snd_audigy_capture_boost_info,
1961 .get = snd_audigy_capture_boost_get,
1962 .put = snd_audigy_capture_boost_put
1968 static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
1970 struct snd_emu10k1 *emu = ac97->private_data;
1976 static int remove_ctl(struct snd_card *card, const char *name)
1978 struct snd_ctl_elem_id id;
1979 memset(&id, 0, sizeof(id));
1980 strcpy(id.name, name);
1981 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1982 return snd_ctl_remove_id(card, &id);
1985 static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
1987 struct snd_kcontrol *kctl = snd_ctl_find_id_mixer(card, src);
1989 snd_ctl_rename(card, kctl, dst);
1995 int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1996 int pcm_device, int multi_device)
1999 struct snd_kcontrol *kctl;
2000 struct snd_card *card = emu->card;
2001 const char * const *c;
2002 static const char * const emu10k1_remove_ctls[] = {
2003 /* no AC97 mono, surround, center/lfe */
2004 "Master Mono Playback Switch",
2005 "Master Mono Playback Volume",
2006 "PCM Out Path & Mute",
2007 "Mono Output Select",
2008 "Surround Playback Switch",
2009 "Surround Playback Volume",
2010 "Center Playback Switch",
2011 "Center Playback Volume",
2012 "LFE Playback Switch",
2013 "LFE Playback Volume",
2016 static const char * const emu10k1_rename_ctls[] = {
2017 "Surround Digital Playback Volume", "Surround Playback Volume",
2018 "Center Digital Playback Volume", "Center Playback Volume",
2019 "LFE Digital Playback Volume", "LFE Playback Volume",
2022 static const char * const audigy_remove_ctls[] = {
2023 /* Master/PCM controls on ac97 of Audigy has no effect */
2024 /* On the Audigy2 the AC97 playback is piped into
2025 * the Philips ADC for 24bit capture */
2026 "PCM Playback Switch",
2027 "PCM Playback Volume",
2028 "Master Playback Switch",
2029 "Master Playback Volume",
2030 "PCM Out Path & Mute",
2031 "Mono Output Select",
2032 /* remove unused AC97 capture controls */
2037 "Headphone Playback Switch",
2038 "Headphone Playback Volume",
2039 "3D Control - Center",
2040 "3D Control - Depth",
2041 "3D Control - Switch",
2042 "Video Playback Switch",
2043 "Video Playback Volume",
2044 "Mic Playback Switch",
2045 "Mic Playback Volume",
2046 "External Amplifier",
2049 static const char * const audigy_rename_ctls[] = {
2050 /* use conventional names */
2051 "Wave Playback Volume", "PCM Playback Volume",
2052 /* "Wave Capture Volume", "PCM Capture Volume", */
2053 "Wave Master Playback Volume", "Master Playback Volume",
2054 "AMic Playback Volume", "Mic Playback Volume",
2055 "Master Mono Playback Switch", "Phone Output Playback Switch",
2056 "Master Mono Playback Volume", "Phone Output Playback Volume",
2059 static const char * const audigy_rename_ctls_i2c_adc[] = {
2060 //"Analog Mix Capture Volume","OLD Analog Mix Capture Volume",
2061 "Line Capture Volume", "Analog Mix Capture Volume",
2062 "Wave Playback Volume", "OLD PCM Playback Volume",
2063 "Wave Master Playback Volume", "Master Playback Volume",
2064 "AMic Playback Volume", "Old Mic Playback Volume",
2065 "CD Capture Volume", "IEC958 Optical Capture Volume",
2068 static const char * const audigy_remove_ctls_i2c_adc[] = {
2069 /* On the Audigy2 ZS Notebook
2070 * Capture via WM8775 */
2071 "Mic Capture Volume",
2072 "Analog Mix Capture Volume",
2073 "Aux Capture Volume",
2074 "IEC958 Optical Capture Volume",
2077 static const char * const audigy_remove_ctls_1361t_adc[] = {
2078 /* On the Audigy2 the AC97 playback is piped into
2079 * the Philips ADC for 24bit capture */
2080 "PCM Playback Switch",
2081 "PCM Playback Volume",
2085 "Mic Capture Volume",
2086 "Headphone Playback Switch",
2087 "Headphone Playback Volume",
2088 "3D Control - Center",
2089 "3D Control - Depth",
2090 "3D Control - Switch",
2091 "Line2 Playback Volume",
2092 "Line2 Capture Volume",
2095 static const char * const audigy_rename_ctls_1361t_adc[] = {
2096 "Master Playback Switch", "Master Capture Switch",
2097 "Master Playback Volume", "Master Capture Volume",
2098 "Wave Master Playback Volume", "Master Playback Volume",
2099 "Beep Playback Switch", "Beep Capture Switch",
2100 "Beep Playback Volume", "Beep Capture Volume",
2101 "Phone Playback Switch", "Phone Capture Switch",
2102 "Phone Playback Volume", "Phone Capture Volume",
2103 "Mic Playback Switch", "Mic Capture Switch",
2104 "Mic Playback Volume", "Mic Capture Volume",
2105 "Line Playback Switch", "Line Capture Switch",
2106 "Line Playback Volume", "Line Capture Volume",
2107 "CD Playback Switch", "CD Capture Switch",
2108 "CD Playback Volume", "CD Capture Volume",
2109 "Aux Playback Switch", "Aux Capture Switch",
2110 "Aux Playback Volume", "Aux Capture Volume",
2111 "Video Playback Switch", "Video Capture Switch",
2112 "Video Playback Volume", "Video Capture Volume",
2113 "Master Mono Playback Switch", "Phone Output Playback Switch",
2114 "Master Mono Playback Volume", "Phone Output Playback Volume",
2118 if (emu->card_capabilities->ac97_chip) {
2119 struct snd_ac97_bus *pbus;
2120 struct snd_ac97_template ac97;
2121 static const struct snd_ac97_bus_ops ops = {
2122 .write = snd_emu10k1_ac97_write,
2123 .read = snd_emu10k1_ac97_read,
2126 err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus);
2129 pbus->no_vra = 1; /* we don't need VRA */
2131 memset(&ac97, 0, sizeof(ac97));
2132 ac97.private_data = emu;
2133 ac97.private_free = snd_emu10k1_mixer_free_ac97;
2134 ac97.scaps = AC97_SCAP_NO_SPDIF;
2135 err = snd_ac97_mixer(pbus, &ac97, &emu->ac97);
2137 if (emu->card_capabilities->ac97_chip == 1)
2139 dev_info(emu->card->dev,
2140 "AC97 is optional on this board\n");
2141 dev_info(emu->card->dev,
2142 "Proceeding without ac97 mixers...\n");
2143 snd_device_free(emu->card, pbus);
2144 goto no_ac97; /* FIXME: get rid of ugly gotos.. */
2147 /* set master volume to 0 dB */
2148 snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000);
2149 /* set capture source to mic */
2150 snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
2151 /* set mono output (TAD) to mic */
2152 snd_ac97_update_bits(emu->ac97, AC97_GENERAL_PURPOSE,
2154 if (emu->card_capabilities->adc_1361t)
2155 c = audigy_remove_ctls_1361t_adc;
2157 c = audigy_remove_ctls;
2160 * Credits for cards based on STAC9758:
2161 * James Courtier-Dutton <James@superbug.demon.co.uk>
2162 * Voluspa <voluspa@comhem.se>
2164 if (emu->ac97->id == AC97_ID_STAC9758) {
2166 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
2167 snd_ac97_write_cache(emu->ac97, AC97_HEADPHONE, 0x0202);
2168 remove_ctl(card,"Front Playback Volume");
2169 remove_ctl(card,"Front Playback Switch");
2171 /* remove unused AC97 controls */
2172 snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
2173 snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
2174 c = emu10k1_remove_ctls;
2177 remove_ctl(card, *c);
2178 } else if (emu->card_capabilities->i2c_adc) {
2179 c = audigy_remove_ctls_i2c_adc;
2181 remove_ctl(card, *c);
2184 if (emu->card_capabilities->ecard)
2185 strcpy(emu->card->mixername, "EMU APS");
2186 else if (emu->audigy)
2187 strcpy(emu->card->mixername, "SB Audigy");
2189 strcpy(emu->card->mixername, "Emu10k1");
2193 if (emu->card_capabilities->adc_1361t)
2194 c = audigy_rename_ctls_1361t_adc;
2195 else if (emu->card_capabilities->i2c_adc)
2196 c = audigy_rename_ctls_i2c_adc;
2198 c = audigy_rename_ctls;
2200 c = emu10k1_rename_ctls;
2202 rename_ctl(card, c[0], c[1]);
2204 if (emu->card_capabilities->subsystem == 0x80401102) { /* SB Live! Platinum CT4760P */
2205 remove_ctl(card, "Center Playback Volume");
2206 remove_ctl(card, "LFE Playback Volume");
2207 remove_ctl(card, "Wave Center Playback Volume");
2208 remove_ctl(card, "Wave LFE Playback Volume");
2210 if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */
2211 rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
2212 rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
2213 rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
2214 rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
2216 kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu);
2219 kctl->id.device = pcm_device;
2220 err = snd_ctl_add(card, kctl);
2223 kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu);
2226 kctl->id.device = pcm_device;
2227 err = snd_ctl_add(card, kctl);
2230 kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu);
2233 kctl->id.device = pcm_device;
2234 err = snd_ctl_add(card, kctl);
2238 kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu);
2241 kctl->id.device = multi_device;
2242 err = snd_ctl_add(card, kctl);
2246 kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu);
2249 kctl->id.device = multi_device;
2250 err = snd_ctl_add(card, kctl);
2254 kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu);
2257 kctl->id.device = multi_device;
2258 err = snd_ctl_add(card, kctl);
2262 if (!emu->card_capabilities->ecard && !emu->card_capabilities->emu_model) {
2263 /* sb live! and audigy */
2264 kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu);
2268 kctl->id.device = emu->pcm_efx->device;
2269 err = snd_ctl_add(card, kctl);
2272 kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu);
2276 kctl->id.device = emu->pcm_efx->device;
2277 err = snd_ctl_add(card, kctl);
2282 if (emu->card_capabilities->emu_model) {
2283 ; /* Disable the snd_audigy_spdif_shared_spdif */
2284 } else if (emu->audigy) {
2285 kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu);
2288 err = snd_ctl_add(card, kctl);
2292 kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu);
2295 err = snd_ctl_add(card, kctl);
2299 } else if (! emu->card_capabilities->ecard) {
2301 kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu);
2304 err = snd_ctl_add(card, kctl);
2308 if (emu->card_capabilities->ca0151_chip) { /* P16V */
2309 err = snd_p16v_mixer(emu);
2314 if (emu->card_capabilities->emu_model) {
2315 unsigned i, emu_idx = emu1010_idx(emu);
2316 const struct snd_emu1010_routing_info *emu_ri =
2317 &emu1010_routing_info[emu_idx];
2318 const struct snd_emu1010_pads_info *emu_pi = &emu1010_pads_info[emu_idx];
2320 for (i = 0; i < emu_ri->n_ins; i++)
2321 emu->emu1010.input_source[i] =
2322 emu1010_map_source(emu_ri, emu_ri->in_dflts[i]);
2323 for (i = 0; i < emu_ri->n_outs; i++)
2324 emu->emu1010.output_source[i] =
2325 emu1010_map_source(emu_ri, emu_ri->out_dflts[i]);
2326 snd_emu1010_apply_sources(emu);
2328 kctl = emu->ctl_clock_source = snd_ctl_new1(&snd_emu1010_clock_source, emu);
2329 err = snd_ctl_add(card, kctl);
2332 err = snd_ctl_add(card,
2333 snd_ctl_new1(&snd_emu1010_clock_fallback, emu));
2337 err = add_ctls(emu, &emu1010_adc_pads_ctl,
2338 emu_pi->adc_ctls, emu_pi->n_adc_ctls);
2341 err = add_ctls(emu, &emu1010_dac_pads_ctl,
2342 emu_pi->dac_ctls, emu_pi->n_dac_ctls);
2346 if (!emu->card_capabilities->no_adat) {
2347 err = snd_ctl_add(card,
2348 snd_ctl_new1(&snd_emu1010_optical_out, emu));
2351 err = snd_ctl_add(card,
2352 snd_ctl_new1(&snd_emu1010_optical_in, emu));
2357 err = add_emu1010_source_mixers(emu);
2362 if ( emu->card_capabilities->i2c_adc) {
2363 err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_i2c_capture_source, emu));
2367 err = add_ctls(emu, &i2c_volume_ctl,
2368 snd_audigy_i2c_volume_ctls,
2369 ARRAY_SIZE(snd_audigy_i2c_volume_ctls));
2374 if (emu->card_capabilities->ac97_chip && emu->audigy) {
2375 err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_capture_boost,