Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/sound/pci/emu10k1/emumixer.c
29266 views
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/*
3
* Copyright (c) by Jaroslav Kysela <[email protected]>,
4
* Takashi Iwai <[email protected]>
5
* Lee Revell <[email protected]>
6
* James Courtier-Dutton <[email protected]>
7
* Oswald Buddenhagen <[email protected]>
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
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
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
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
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
577
static unsigned emu1010_idx(struct snd_emu10k1 *emu)
578
{
579
return emu->card_capabilities->emu_model - 1;
580
}
581
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
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
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
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
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
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
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
guard(snd_emu1010_fpga_lock)(emu);
666
snd_emu1010_output_source_apply(emu, channel, val);
667
}
668
return change;
669
}
670
671
static const struct snd_kcontrol_new emu1010_output_source_ctl = {
672
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
673
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
674
.info = snd_emu1010_input_output_source_info,
675
.get = snd_emu1010_output_source_get,
676
.put = snd_emu1010_output_source_put
677
};
678
679
static int snd_emu1010_input_source_get(struct snd_kcontrol *kcontrol,
680
struct snd_ctl_elem_value *ucontrol)
681
{
682
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
683
const struct snd_emu1010_routing_info *emu_ri =
684
&emu1010_routing_info[emu1010_idx(emu)];
685
unsigned channel = kcontrol->private_value;
686
687
if (channel >= emu_ri->n_ins)
688
return -EINVAL;
689
ucontrol->value.enumerated.item[0] = emu->emu1010.input_source[channel];
690
return 0;
691
}
692
693
static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol,
694
struct snd_ctl_elem_value *ucontrol)
695
{
696
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
697
const struct snd_emu1010_routing_info *emu_ri =
698
&emu1010_routing_info[emu1010_idx(emu)];
699
unsigned val = ucontrol->value.enumerated.item[0];
700
unsigned channel = kcontrol->private_value;
701
int change;
702
703
if (val >= emu_ri->n_srcs)
704
return -EINVAL;
705
if (channel >= emu_ri->n_ins)
706
return -EINVAL;
707
change = (emu->emu1010.input_source[channel] != val);
708
if (change) {
709
emu->emu1010.input_source[channel] = val;
710
guard(snd_emu1010_fpga_lock)(emu);
711
snd_emu1010_input_source_apply(emu, channel, val);
712
}
713
return change;
714
}
715
716
static const struct snd_kcontrol_new emu1010_input_source_ctl = {
717
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
718
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
719
.info = snd_emu1010_input_output_source_info,
720
.get = snd_emu1010_input_source_get,
721
.put = snd_emu1010_input_source_put
722
};
723
724
static int add_emu1010_source_mixers(struct snd_emu10k1 *emu)
725
{
726
const struct snd_emu1010_routing_info *emu_ri =
727
&emu1010_routing_info[emu1010_idx(emu)];
728
int err;
729
730
err = add_ctls(emu, &emu1010_output_source_ctl,
731
emu_ri->out_texts, emu_ri->n_outs);
732
if (err < 0)
733
return err;
734
err = add_ctls(emu, &emu1010_input_source_ctl,
735
emu1010_input_texts, emu_ri->n_ins);
736
return err;
737
}
738
739
740
static const char * const snd_emu1010_adc_pads[] = {
741
"ADC1 14dB PAD 0202 Capture Switch",
742
"ADC1 14dB PAD Audio Dock Capture Switch",
743
"ADC2 14dB PAD Audio Dock Capture Switch",
744
"ADC3 14dB PAD Audio Dock Capture Switch",
745
};
746
747
static const unsigned short snd_emu1010_adc_pad_regs[] = {
748
EMU_HANA_0202_ADC_PAD1,
749
EMU_HANA_DOCK_ADC_PAD1,
750
EMU_HANA_DOCK_ADC_PAD2,
751
EMU_HANA_DOCK_ADC_PAD3,
752
};
753
754
#define snd_emu1010_adc_pads_info snd_ctl_boolean_mono_info
755
756
static int snd_emu1010_adc_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
757
{
758
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
759
unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value];
760
761
ucontrol->value.integer.value[0] = (emu->emu1010.adc_pads & mask) ? 1 : 0;
762
return 0;
763
}
764
765
static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
766
{
767
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
768
unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value];
769
unsigned int val, cache;
770
int change;
771
772
val = ucontrol->value.integer.value[0];
773
cache = emu->emu1010.adc_pads;
774
if (val == 1)
775
cache = cache | mask;
776
else
777
cache = cache & ~mask;
778
change = (cache != emu->emu1010.adc_pads);
779
if (change) {
780
snd_emu1010_fpga_write_lock(emu, EMU_HANA_ADC_PADS, cache );
781
emu->emu1010.adc_pads = cache;
782
}
783
784
return change;
785
}
786
787
static const struct snd_kcontrol_new emu1010_adc_pads_ctl = {
788
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
789
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
790
.info = snd_emu1010_adc_pads_info,
791
.get = snd_emu1010_adc_pads_get,
792
.put = snd_emu1010_adc_pads_put
793
};
794
795
796
static const char * const snd_emu1010_dac_pads[] = {
797
"DAC1 0202 14dB PAD Playback Switch",
798
"DAC1 Audio Dock 14dB PAD Playback Switch",
799
"DAC2 Audio Dock 14dB PAD Playback Switch",
800
"DAC3 Audio Dock 14dB PAD Playback Switch",
801
"DAC4 Audio Dock 14dB PAD Playback Switch",
802
};
803
804
static const unsigned short snd_emu1010_dac_regs[] = {
805
EMU_HANA_0202_DAC_PAD1,
806
EMU_HANA_DOCK_DAC_PAD1,
807
EMU_HANA_DOCK_DAC_PAD2,
808
EMU_HANA_DOCK_DAC_PAD3,
809
EMU_HANA_DOCK_DAC_PAD4,
810
};
811
812
#define snd_emu1010_dac_pads_info snd_ctl_boolean_mono_info
813
814
static int snd_emu1010_dac_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
815
{
816
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
817
unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value];
818
819
ucontrol->value.integer.value[0] = (emu->emu1010.dac_pads & mask) ? 1 : 0;
820
return 0;
821
}
822
823
static int snd_emu1010_dac_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
824
{
825
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
826
unsigned int mask = snd_emu1010_dac_regs[kcontrol->private_value];
827
unsigned int val, cache;
828
int change;
829
830
val = ucontrol->value.integer.value[0];
831
cache = emu->emu1010.dac_pads;
832
if (val == 1)
833
cache = cache | mask;
834
else
835
cache = cache & ~mask;
836
change = (cache != emu->emu1010.dac_pads);
837
if (change) {
838
snd_emu1010_fpga_write_lock(emu, EMU_HANA_DAC_PADS, cache );
839
emu->emu1010.dac_pads = cache;
840
}
841
842
return change;
843
}
844
845
static const struct snd_kcontrol_new emu1010_dac_pads_ctl = {
846
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
847
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
848
.info = snd_emu1010_dac_pads_info,
849
.get = snd_emu1010_dac_pads_get,
850
.put = snd_emu1010_dac_pads_put
851
};
852
853
854
struct snd_emu1010_pads_info {
855
const char * const *adc_ctls, * const *dac_ctls;
856
unsigned n_adc_ctls, n_dac_ctls;
857
};
858
859
static const struct snd_emu1010_pads_info emu1010_pads_info[] = {
860
{
861
/* rev1 1010 */
862
.adc_ctls = snd_emu1010_adc_pads,
863
.n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads),
864
.dac_ctls = snd_emu1010_dac_pads,
865
.n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads),
866
},
867
{
868
/* rev2 1010 */
869
.adc_ctls = snd_emu1010_adc_pads,
870
.n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads) - 1,
871
.dac_ctls = snd_emu1010_dac_pads,
872
.n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads) - 1,
873
},
874
{
875
/* 1616(m) cardbus */
876
.adc_ctls = snd_emu1010_adc_pads + 1,
877
.n_adc_ctls = ARRAY_SIZE(snd_emu1010_adc_pads) - 2,
878
.dac_ctls = snd_emu1010_dac_pads + 1,
879
.n_dac_ctls = ARRAY_SIZE(snd_emu1010_dac_pads) - 2,
880
},
881
{
882
/* 0404 */
883
.adc_ctls = NULL,
884
.n_adc_ctls = 0,
885
.dac_ctls = NULL,
886
.n_dac_ctls = 0,
887
},
888
};
889
890
static const char * const emu1010_clock_texts[] = {
891
"44100", "48000", "SPDIF", "ADAT", "Dock", "BNC"
892
};
893
894
static const u8 emu1010_clock_vals[] = {
895
EMU_HANA_WCLOCK_INT_44_1K,
896
EMU_HANA_WCLOCK_INT_48K,
897
EMU_HANA_WCLOCK_HANA_SPDIF_IN,
898
EMU_HANA_WCLOCK_HANA_ADAT_IN,
899
EMU_HANA_WCLOCK_2ND_HANA,
900
EMU_HANA_WCLOCK_SYNC_BNC,
901
};
902
903
static const char * const emu0404_clock_texts[] = {
904
"44100", "48000", "SPDIF", "BNC"
905
};
906
907
static const u8 emu0404_clock_vals[] = {
908
EMU_HANA_WCLOCK_INT_44_1K,
909
EMU_HANA_WCLOCK_INT_48K,
910
EMU_HANA_WCLOCK_HANA_SPDIF_IN,
911
EMU_HANA_WCLOCK_SYNC_BNC,
912
};
913
914
struct snd_emu1010_clock_info {
915
const char * const *texts;
916
const u8 *vals;
917
unsigned num;
918
};
919
920
static const struct snd_emu1010_clock_info emu1010_clock_info[] = {
921
{
922
// rev1 1010
923
.texts = emu1010_clock_texts,
924
.vals = emu1010_clock_vals,
925
.num = ARRAY_SIZE(emu1010_clock_vals),
926
},
927
{
928
// rev2 1010
929
.texts = emu1010_clock_texts,
930
.vals = emu1010_clock_vals,
931
.num = ARRAY_SIZE(emu1010_clock_vals) - 1,
932
},
933
{
934
// 1616(m) CardBus
935
.texts = emu1010_clock_texts,
936
// TODO: determine what is actually available.
937
// Pedantically, *every* source comes from the 2nd FPGA, as the
938
// card itself has no own (digital) audio ports. The user manual
939
// claims that ADAT and S/PDIF clock sources are separate, which
940
// can mean two things: either E-MU mapped the dock's sources to
941
// the primary ones, or they determine the meaning of the "Dock"
942
// source depending on how the ports are actually configured
943
// (which the 2nd FPGA must be doing anyway).
944
.vals = emu1010_clock_vals,
945
.num = ARRAY_SIZE(emu1010_clock_vals),
946
},
947
{
948
// 0404
949
.texts = emu0404_clock_texts,
950
.vals = emu0404_clock_vals,
951
.num = ARRAY_SIZE(emu0404_clock_vals),
952
},
953
};
954
955
static int snd_emu1010_clock_source_info(struct snd_kcontrol *kcontrol,
956
struct snd_ctl_elem_info *uinfo)
957
{
958
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
959
const struct snd_emu1010_clock_info *emu_ci =
960
&emu1010_clock_info[emu1010_idx(emu)];
961
962
return snd_ctl_enum_info(uinfo, 1, emu_ci->num, emu_ci->texts);
963
}
964
965
static int snd_emu1010_clock_source_get(struct snd_kcontrol *kcontrol,
966
struct snd_ctl_elem_value *ucontrol)
967
{
968
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
969
970
ucontrol->value.enumerated.item[0] = emu->emu1010.clock_source;
971
return 0;
972
}
973
974
static int snd_emu1010_clock_source_put(struct snd_kcontrol *kcontrol,
975
struct snd_ctl_elem_value *ucontrol)
976
{
977
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
978
const struct snd_emu1010_clock_info *emu_ci =
979
&emu1010_clock_info[emu1010_idx(emu)];
980
unsigned int val;
981
982
val = ucontrol->value.enumerated.item[0] ;
983
if (val >= emu_ci->num)
984
return -EINVAL;
985
guard(snd_emu1010_fpga_lock)(emu);
986
scoped_guard(spinlock_irq, &emu->reg_lock) {
987
if (emu->emu1010.clock_source == val)
988
return 0;
989
emu->emu1010.clock_source = val;
990
emu->emu1010.wclock = emu_ci->vals[val];
991
snd_emu1010_update_clock(emu);
992
993
snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE);
994
snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, emu->emu1010.wclock);
995
}
996
997
msleep(10); // Allow DLL to settle
998
snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
999
return 1;
1000
}
1001
1002
static const struct snd_kcontrol_new snd_emu1010_clock_source =
1003
{
1004
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1005
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1006
.name = "Clock Source",
1007
.count = 1,
1008
.info = snd_emu1010_clock_source_info,
1009
.get = snd_emu1010_clock_source_get,
1010
.put = snd_emu1010_clock_source_put
1011
};
1012
1013
static int snd_emu1010_clock_fallback_info(struct snd_kcontrol *kcontrol,
1014
struct snd_ctl_elem_info *uinfo)
1015
{
1016
static const char * const texts[2] = {
1017
"44100", "48000"
1018
};
1019
1020
return snd_ctl_enum_info(uinfo, 1, 2, texts);
1021
}
1022
1023
static int snd_emu1010_clock_fallback_get(struct snd_kcontrol *kcontrol,
1024
struct snd_ctl_elem_value *ucontrol)
1025
{
1026
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1027
1028
ucontrol->value.enumerated.item[0] = emu->emu1010.clock_fallback;
1029
return 0;
1030
}
1031
1032
static int snd_emu1010_clock_fallback_put(struct snd_kcontrol *kcontrol,
1033
struct snd_ctl_elem_value *ucontrol)
1034
{
1035
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1036
unsigned int val = ucontrol->value.enumerated.item[0];
1037
int change;
1038
1039
if (val >= 2)
1040
return -EINVAL;
1041
change = (emu->emu1010.clock_fallback != val);
1042
if (change) {
1043
emu->emu1010.clock_fallback = val;
1044
snd_emu1010_fpga_write_lock(emu, EMU_HANA_DEFCLOCK, 1 - val);
1045
}
1046
return change;
1047
}
1048
1049
static const struct snd_kcontrol_new snd_emu1010_clock_fallback =
1050
{
1051
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1052
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1053
.name = "Clock Fallback",
1054
.count = 1,
1055
.info = snd_emu1010_clock_fallback_info,
1056
.get = snd_emu1010_clock_fallback_get,
1057
.put = snd_emu1010_clock_fallback_put
1058
};
1059
1060
static int snd_emu1010_optical_out_info(struct snd_kcontrol *kcontrol,
1061
struct snd_ctl_elem_info *uinfo)
1062
{
1063
static const char * const texts[2] = {
1064
"SPDIF", "ADAT"
1065
};
1066
1067
return snd_ctl_enum_info(uinfo, 1, 2, texts);
1068
}
1069
1070
static int snd_emu1010_optical_out_get(struct snd_kcontrol *kcontrol,
1071
struct snd_ctl_elem_value *ucontrol)
1072
{
1073
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1074
1075
ucontrol->value.enumerated.item[0] = emu->emu1010.optical_out;
1076
return 0;
1077
}
1078
1079
static int snd_emu1010_optical_out_put(struct snd_kcontrol *kcontrol,
1080
struct snd_ctl_elem_value *ucontrol)
1081
{
1082
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1083
unsigned int val;
1084
u32 tmp;
1085
int change = 0;
1086
1087
val = ucontrol->value.enumerated.item[0];
1088
/* Limit: uinfo->value.enumerated.items = 2; */
1089
if (val >= 2)
1090
return -EINVAL;
1091
change = (emu->emu1010.optical_out != val);
1092
if (change) {
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_lock(emu, EMU_HANA_OPTICAL_TYPE, tmp);
1097
}
1098
return change;
1099
}
1100
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",
1105
.count = 1,
1106
.info = snd_emu1010_optical_out_info,
1107
.get = snd_emu1010_optical_out_get,
1108
.put = snd_emu1010_optical_out_put
1109
};
1110
1111
static int snd_emu1010_optical_in_info(struct snd_kcontrol *kcontrol,
1112
struct snd_ctl_elem_info *uinfo)
1113
{
1114
static const char * const texts[2] = {
1115
"SPDIF", "ADAT"
1116
};
1117
1118
return snd_ctl_enum_info(uinfo, 1, 2, texts);
1119
}
1120
1121
static int snd_emu1010_optical_in_get(struct snd_kcontrol *kcontrol,
1122
struct snd_ctl_elem_value *ucontrol)
1123
{
1124
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1125
1126
ucontrol->value.enumerated.item[0] = emu->emu1010.optical_in;
1127
return 0;
1128
}
1129
1130
static int snd_emu1010_optical_in_put(struct snd_kcontrol *kcontrol,
1131
struct snd_ctl_elem_value *ucontrol)
1132
{
1133
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1134
unsigned int val;
1135
u32 tmp;
1136
int change = 0;
1137
1138
val = ucontrol->value.enumerated.item[0];
1139
/* Limit: uinfo->value.enumerated.items = 2; */
1140
if (val >= 2)
1141
return -EINVAL;
1142
change = (emu->emu1010.optical_in != val);
1143
if (change) {
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_lock(emu, EMU_HANA_OPTICAL_TYPE, tmp);
1148
}
1149
return change;
1150
}
1151
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",
1156
.count = 1,
1157
.info = snd_emu1010_optical_in_info,
1158
.get = snd_emu1010_optical_in_get,
1159
.put = snd_emu1010_optical_in_put
1160
};
1161
1162
static int snd_audigy_i2c_capture_source_info(struct snd_kcontrol *kcontrol,
1163
struct snd_ctl_elem_info *uinfo)
1164
{
1165
#if 0
1166
static const char * const texts[4] = {
1167
"Unknown1", "Unknown2", "Mic", "Line"
1168
};
1169
#endif
1170
static const char * const texts[2] = {
1171
"Mic", "Line"
1172
};
1173
1174
return snd_ctl_enum_info(uinfo, 1, 2, texts);
1175
}
1176
1177
static int snd_audigy_i2c_capture_source_get(struct snd_kcontrol *kcontrol,
1178
struct snd_ctl_elem_value *ucontrol)
1179
{
1180
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1181
1182
ucontrol->value.enumerated.item[0] = emu->i2c_capture_source;
1183
return 0;
1184
}
1185
1186
static int snd_audigy_i2c_capture_source_put(struct snd_kcontrol *kcontrol,
1187
struct snd_ctl_elem_value *ucontrol)
1188
{
1189
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1190
unsigned int source_id;
1191
unsigned int ngain, ogain;
1192
u16 gpio;
1193
int change = 0;
1194
u32 source;
1195
/* If the capture source has changed,
1196
* update the capture volume from the cached value
1197
* for the particular source.
1198
*/
1199
source_id = ucontrol->value.enumerated.item[0];
1200
/* Limit: uinfo->value.enumerated.items = 2; */
1201
/* emu->i2c_capture_volume */
1202
if (source_id >= 2)
1203
return -EINVAL;
1204
change = (emu->i2c_capture_source != source_id);
1205
if (change) {
1206
snd_emu10k1_i2c_write(emu, ADC_MUX, 0); /* Mute input */
1207
scoped_guard(spinlock_irq, &emu->emu_lock) {
1208
gpio = inw(emu->port + A_IOCFG);
1209
if (source_id == 0)
1210
outw(gpio | 0x4, emu->port + A_IOCFG);
1211
else
1212
outw(gpio & ~0x4, emu->port + A_IOCFG);
1213
}
1214
1215
ngain = emu->i2c_capture_volume[source_id][0]; /* Left */
1216
ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */
1217
if (ngain != ogain)
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 */
1221
if (ngain != ogain)
1222
snd_emu10k1_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff));
1223
1224
source = 1 << (source_id + 2);
1225
snd_emu10k1_i2c_write(emu, ADC_MUX, source); /* Set source */
1226
emu->i2c_capture_source = source_id;
1227
}
1228
return change;
1229
}
1230
1231
static const struct snd_kcontrol_new snd_audigy_i2c_capture_source =
1232
{
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
1238
};
1239
1240
static int snd_audigy_i2c_volume_info(struct snd_kcontrol *kcontrol,
1241
struct snd_ctl_elem_info *uinfo)
1242
{
1243
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1244
uinfo->count = 2;
1245
uinfo->value.integer.min = 0;
1246
uinfo->value.integer.max = 255;
1247
return 0;
1248
}
1249
1250
static int snd_audigy_i2c_volume_get(struct snd_kcontrol *kcontrol,
1251
struct snd_ctl_elem_value *ucontrol)
1252
{
1253
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1254
unsigned int source_id;
1255
1256
source_id = kcontrol->private_value;
1257
/* Limit: emu->i2c_capture_volume */
1258
/* capture_source: uinfo->value.enumerated.items = 2 */
1259
if (source_id >= 2)
1260
return -EINVAL;
1261
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];
1264
return 0;
1265
}
1266
1267
static int snd_audigy_i2c_volume_put(struct snd_kcontrol *kcontrol,
1268
struct snd_ctl_elem_value *ucontrol)
1269
{
1270
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1271
unsigned int ogain;
1272
unsigned int ngain0, ngain1;
1273
unsigned int source_id;
1274
int change = 0;
1275
1276
source_id = kcontrol->private_value;
1277
/* Limit: emu->i2c_capture_volume */
1278
/* capture_source: uinfo->value.enumerated.items = 2 */
1279
if (source_id >= 2)
1280
return -EINVAL;
1281
ngain0 = ucontrol->value.integer.value[0];
1282
ngain1 = ucontrol->value.integer.value[1];
1283
if (ngain0 > 0xff)
1284
return -EINVAL;
1285
if (ngain1 > 0xff)
1286
return -EINVAL;
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;
1292
change = 1;
1293
}
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;
1299
change = 1;
1300
}
1301
1302
return change;
1303
}
1304
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 }
1313
};
1314
1315
static const char * const snd_audigy_i2c_volume_ctls[] = {
1316
"Mic Capture Volume",
1317
"Line Capture Volume",
1318
};
1319
1320
#if 0
1321
static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1322
{
1323
static const char * const texts[] = {"44100", "48000", "96000"};
1324
1325
return snd_ctl_enum_info(uinfo, 1, 3, texts);
1326
}
1327
1328
static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
1329
struct snd_ctl_elem_value *ucontrol)
1330
{
1331
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1332
unsigned int tmp;
1333
1334
tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
1335
switch (tmp & A_SPDIF_RATE_MASK) {
1336
case A_SPDIF_44100:
1337
ucontrol->value.enumerated.item[0] = 0;
1338
break;
1339
case A_SPDIF_48000:
1340
ucontrol->value.enumerated.item[0] = 1;
1341
break;
1342
case A_SPDIF_96000:
1343
ucontrol->value.enumerated.item[0] = 2;
1344
break;
1345
default:
1346
ucontrol->value.enumerated.item[0] = 1;
1347
}
1348
return 0;
1349
}
1350
1351
static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol,
1352
struct snd_ctl_elem_value *ucontrol)
1353
{
1354
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1355
int change;
1356
unsigned int reg, val, tmp;
1357
1358
switch(ucontrol->value.enumerated.item[0]) {
1359
case 0:
1360
val = A_SPDIF_44100;
1361
break;
1362
case 1:
1363
val = A_SPDIF_48000;
1364
break;
1365
case 2:
1366
val = A_SPDIF_96000;
1367
break;
1368
default:
1369
val = A_SPDIF_48000;
1370
break;
1371
}
1372
1373
1374
guard(spinlock_irq)(&emu->reg_lock);
1375
reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
1376
tmp = reg & ~A_SPDIF_RATE_MASK;
1377
tmp |= val;
1378
change = (tmp != reg);
1379
if (change)
1380
snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
1381
return change;
1382
}
1383
1384
static const struct snd_kcontrol_new snd_audigy_spdif_output_rate =
1385
{
1386
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
1387
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1388
.name = "Audigy SPDIF Output Sample Rate",
1389
.count = 1,
1390
.info = snd_audigy_spdif_output_rate_info,
1391
.get = snd_audigy_spdif_output_rate_get,
1392
.put = snd_audigy_spdif_output_rate_put
1393
};
1394
#endif
1395
1396
static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol,
1397
struct snd_ctl_elem_value *ucontrol)
1398
{
1399
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1400
unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1401
int change;
1402
unsigned int val;
1403
1404
/* Limit: emu->spdif_bits */
1405
if (idx >= 3)
1406
return -EINVAL;
1407
val = (ucontrol->value.iec958.status[0] << 0) |
1408
(ucontrol->value.iec958.status[1] << 8) |
1409
(ucontrol->value.iec958.status[2] << 16) |
1410
(ucontrol->value.iec958.status[3] << 24);
1411
change = val != emu->spdif_bits[idx];
1412
if (change) {
1413
snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val);
1414
emu->spdif_bits[idx] = val;
1415
}
1416
return change;
1417
}
1418
1419
static const struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
1420
{
1421
.access = SNDRV_CTL_ELEM_ACCESS_READ,
1422
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1423
.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
1424
.count = 3,
1425
.info = snd_emu10k1_spdif_info,
1426
.get = snd_emu10k1_spdif_get_mask
1427
};
1428
1429
static const struct snd_kcontrol_new snd_emu10k1_spdif_control =
1430
{
1431
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1432
.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
1433
.count = 3,
1434
.info = snd_emu10k1_spdif_info,
1435
.get = snd_emu10k1_spdif_get,
1436
.put = snd_emu10k1_spdif_put
1437
};
1438
1439
1440
static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route)
1441
{
1442
if (emu->audigy) {
1443
snd_emu10k1_ptr_write_multiple(emu, voice,
1444
A_FXRT1, snd_emu10k1_compose_audigy_fxrt1(route),
1445
A_FXRT2, snd_emu10k1_compose_audigy_fxrt2(route),
1446
REGLIST_END);
1447
} else {
1448
snd_emu10k1_ptr_write(emu, FXRT, voice,
1449
snd_emu10k1_compose_send_routing(route));
1450
}
1451
}
1452
1453
static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume)
1454
{
1455
snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]);
1456
snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]);
1457
snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]);
1458
snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]);
1459
if (emu->audigy) {
1460
snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice,
1461
snd_emu10k1_compose_audigy_sendamounts(volume));
1462
}
1463
}
1464
1465
/* PCM stream controls */
1466
1467
static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1468
{
1469
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1470
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1471
uinfo->count = emu->audigy ? 3*8 : 3*4;
1472
uinfo->value.integer.min = 0;
1473
uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
1474
return 0;
1475
}
1476
1477
static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol,
1478
struct snd_ctl_elem_value *ucontrol)
1479
{
1480
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1481
struct snd_emu10k1_pcm_mixer *mix =
1482
&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1483
int voice, idx;
1484
int num_efx = emu->audigy ? 8 : 4;
1485
int mask = emu->audigy ? 0x3f : 0x0f;
1486
1487
for (voice = 0; voice < 3; voice++)
1488
for (idx = 0; idx < num_efx; idx++)
1489
ucontrol->value.integer.value[(voice * num_efx) + idx] =
1490
mix->send_routing[voice][idx] & mask;
1491
return 0;
1492
}
1493
1494
static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol,
1495
struct snd_ctl_elem_value *ucontrol)
1496
{
1497
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1498
struct snd_emu10k1_pcm_mixer *mix =
1499
&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1500
int change = 0, voice, idx, val;
1501
int num_efx = emu->audigy ? 8 : 4;
1502
int mask = emu->audigy ? 0x3f : 0x0f;
1503
1504
guard(spinlock_irq)(&emu->reg_lock);
1505
for (voice = 0; voice < 3; voice++)
1506
for (idx = 0; idx < num_efx; idx++) {
1507
val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask;
1508
if (mix->send_routing[voice][idx] != val) {
1509
mix->send_routing[voice][idx] = val;
1510
change = 1;
1511
}
1512
}
1513
if (change && mix->epcm && mix->epcm->voices[0]) {
1514
if (!mix->epcm->voices[0]->last) {
1515
update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
1516
&mix->send_routing[1][0]);
1517
update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number + 1,
1518
&mix->send_routing[2][0]);
1519
} else {
1520
update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
1521
&mix->send_routing[0][0]);
1522
}
1523
}
1524
return change;
1525
}
1526
1527
static const struct snd_kcontrol_new snd_emu10k1_send_routing_control =
1528
{
1529
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1530
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1531
.name = "EMU10K1 PCM Send Routing",
1532
.count = 32,
1533
.info = snd_emu10k1_send_routing_info,
1534
.get = snd_emu10k1_send_routing_get,
1535
.put = snd_emu10k1_send_routing_put
1536
};
1537
1538
static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1539
{
1540
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1541
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1542
uinfo->count = emu->audigy ? 3*8 : 3*4;
1543
uinfo->value.integer.min = 0;
1544
uinfo->value.integer.max = 255;
1545
return 0;
1546
}
1547
1548
static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol,
1549
struct snd_ctl_elem_value *ucontrol)
1550
{
1551
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1552
struct snd_emu10k1_pcm_mixer *mix =
1553
&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1554
int idx;
1555
int num_efx = emu->audigy ? 8 : 4;
1556
1557
for (idx = 0; idx < 3*num_efx; idx++)
1558
ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx];
1559
return 0;
1560
}
1561
1562
static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol,
1563
struct snd_ctl_elem_value *ucontrol)
1564
{
1565
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1566
struct snd_emu10k1_pcm_mixer *mix =
1567
&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1568
int change = 0, idx, val;
1569
int num_efx = emu->audigy ? 8 : 4;
1570
1571
guard(spinlock_irq)(&emu->reg_lock);
1572
for (idx = 0; idx < 3*num_efx; idx++) {
1573
val = ucontrol->value.integer.value[idx] & 255;
1574
if (mix->send_volume[idx/num_efx][idx%num_efx] != val) {
1575
mix->send_volume[idx/num_efx][idx%num_efx] = val;
1576
change = 1;
1577
}
1578
}
1579
if (change && mix->epcm && mix->epcm->voices[0]) {
1580
if (!mix->epcm->voices[0]->last) {
1581
update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
1582
&mix->send_volume[1][0]);
1583
update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number + 1,
1584
&mix->send_volume[2][0]);
1585
} else {
1586
update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
1587
&mix->send_volume[0][0]);
1588
}
1589
}
1590
return change;
1591
}
1592
1593
static const struct snd_kcontrol_new snd_emu10k1_send_volume_control =
1594
{
1595
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1596
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1597
.name = "EMU10K1 PCM Send Volume",
1598
.count = 32,
1599
.info = snd_emu10k1_send_volume_info,
1600
.get = snd_emu10k1_send_volume_get,
1601
.put = snd_emu10k1_send_volume_put
1602
};
1603
1604
static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1605
{
1606
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1607
uinfo->count = 3;
1608
uinfo->value.integer.min = 0;
1609
uinfo->value.integer.max = 0x1fffd;
1610
return 0;
1611
}
1612
1613
static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,
1614
struct snd_ctl_elem_value *ucontrol)
1615
{
1616
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1617
struct snd_emu10k1_pcm_mixer *mix =
1618
&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1619
int idx;
1620
1621
for (idx = 0; idx < 3; idx++)
1622
ucontrol->value.integer.value[idx] = mix->attn[idx] * 0xffffU / 0x8000U;
1623
return 0;
1624
}
1625
1626
static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,
1627
struct snd_ctl_elem_value *ucontrol)
1628
{
1629
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1630
struct snd_emu10k1_pcm_mixer *mix =
1631
&emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1632
int change = 0, idx, val;
1633
1634
guard(spinlock_irq)(&emu->reg_lock);
1635
for (idx = 0; idx < 3; idx++) {
1636
unsigned uval = ucontrol->value.integer.value[idx] & 0x1ffff;
1637
val = uval * 0x8000U / 0xffffU;
1638
if (mix->attn[idx] != val) {
1639
mix->attn[idx] = val;
1640
change = 1;
1641
}
1642
}
1643
if (change && mix->epcm && mix->epcm->voices[0]) {
1644
if (!mix->epcm->voices[0]->last) {
1645
snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]);
1646
snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number + 1, mix->attn[2]);
1647
} else {
1648
snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]);
1649
}
1650
}
1651
return change;
1652
}
1653
1654
static const struct snd_kcontrol_new snd_emu10k1_attn_control =
1655
{
1656
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1657
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1658
.name = "EMU10K1 PCM Volume",
1659
.count = 32,
1660
.info = snd_emu10k1_attn_info,
1661
.get = snd_emu10k1_attn_get,
1662
.put = snd_emu10k1_attn_put
1663
};
1664
1665
/* Mutichannel PCM stream controls */
1666
1667
static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1668
{
1669
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1670
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1671
uinfo->count = emu->audigy ? 8 : 4;
1672
uinfo->value.integer.min = 0;
1673
uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
1674
return 0;
1675
}
1676
1677
static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol,
1678
struct snd_ctl_elem_value *ucontrol)
1679
{
1680
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1681
struct snd_emu10k1_pcm_mixer *mix =
1682
&emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1683
int idx;
1684
int num_efx = emu->audigy ? 8 : 4;
1685
int mask = emu->audigy ? 0x3f : 0x0f;
1686
1687
for (idx = 0; idx < num_efx; idx++)
1688
ucontrol->value.integer.value[idx] =
1689
mix->send_routing[0][idx] & mask;
1690
return 0;
1691
}
1692
1693
static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol,
1694
struct snd_ctl_elem_value *ucontrol)
1695
{
1696
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1697
int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1698
struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1699
int change = 0, idx, val;
1700
int num_efx = emu->audigy ? 8 : 4;
1701
int mask = emu->audigy ? 0x3f : 0x0f;
1702
1703
guard(spinlock_irq)(&emu->reg_lock);
1704
for (idx = 0; idx < num_efx; idx++) {
1705
val = ucontrol->value.integer.value[idx] & mask;
1706
if (mix->send_routing[0][idx] != val) {
1707
mix->send_routing[0][idx] = val;
1708
change = 1;
1709
}
1710
}
1711
1712
if (change && mix->epcm) {
1713
if (mix->epcm->voices[ch]) {
1714
update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number,
1715
&mix->send_routing[0][0]);
1716
}
1717
}
1718
return change;
1719
}
1720
1721
static const struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
1722
{
1723
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1724
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1725
.name = "Multichannel PCM Send Routing",
1726
.count = 16,
1727
.info = snd_emu10k1_efx_send_routing_info,
1728
.get = snd_emu10k1_efx_send_routing_get,
1729
.put = snd_emu10k1_efx_send_routing_put
1730
};
1731
1732
static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1733
{
1734
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1735
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1736
uinfo->count = emu->audigy ? 8 : 4;
1737
uinfo->value.integer.min = 0;
1738
uinfo->value.integer.max = 255;
1739
return 0;
1740
}
1741
1742
static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol,
1743
struct snd_ctl_elem_value *ucontrol)
1744
{
1745
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1746
struct snd_emu10k1_pcm_mixer *mix =
1747
&emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1748
int idx;
1749
int num_efx = emu->audigy ? 8 : 4;
1750
1751
for (idx = 0; idx < num_efx; idx++)
1752
ucontrol->value.integer.value[idx] = mix->send_volume[0][idx];
1753
return 0;
1754
}
1755
1756
static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol,
1757
struct snd_ctl_elem_value *ucontrol)
1758
{
1759
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1760
int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1761
struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1762
int change = 0, idx, val;
1763
int num_efx = emu->audigy ? 8 : 4;
1764
1765
guard(spinlock_irq)(&emu->reg_lock);
1766
for (idx = 0; idx < num_efx; idx++) {
1767
val = ucontrol->value.integer.value[idx] & 255;
1768
if (mix->send_volume[0][idx] != val) {
1769
mix->send_volume[0][idx] = val;
1770
change = 1;
1771
}
1772
}
1773
if (change && mix->epcm) {
1774
if (mix->epcm->voices[ch]) {
1775
update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number,
1776
&mix->send_volume[0][0]);
1777
}
1778
}
1779
return change;
1780
}
1781
1782
1783
static const struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
1784
{
1785
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1786
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1787
.name = "Multichannel PCM Send Volume",
1788
.count = 16,
1789
.info = snd_emu10k1_efx_send_volume_info,
1790
.get = snd_emu10k1_efx_send_volume_get,
1791
.put = snd_emu10k1_efx_send_volume_put
1792
};
1793
1794
static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1795
{
1796
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1797
uinfo->count = 1;
1798
uinfo->value.integer.min = 0;
1799
uinfo->value.integer.max = 0x1fffd;
1800
return 0;
1801
}
1802
1803
static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol,
1804
struct snd_ctl_elem_value *ucontrol)
1805
{
1806
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1807
struct snd_emu10k1_pcm_mixer *mix =
1808
&emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1809
1810
ucontrol->value.integer.value[0] = mix->attn[0] * 0xffffU / 0x8000U;
1811
return 0;
1812
}
1813
1814
static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol,
1815
struct snd_ctl_elem_value *ucontrol)
1816
{
1817
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1818
int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1819
struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1820
int change = 0, val;
1821
unsigned uval;
1822
1823
guard(spinlock_irq)(&emu->reg_lock);
1824
uval = ucontrol->value.integer.value[0] & 0x1ffff;
1825
val = uval * 0x8000U / 0xffffU;
1826
if (mix->attn[0] != val) {
1827
mix->attn[0] = val;
1828
change = 1;
1829
}
1830
if (change && mix->epcm) {
1831
if (mix->epcm->voices[ch]) {
1832
snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]);
1833
}
1834
}
1835
return change;
1836
}
1837
1838
static const struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
1839
{
1840
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1841
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1842
.name = "Multichannel PCM Volume",
1843
.count = 16,
1844
.info = snd_emu10k1_efx_attn_info,
1845
.get = snd_emu10k1_efx_attn_get,
1846
.put = snd_emu10k1_efx_attn_put
1847
};
1848
1849
#define snd_emu10k1_shared_spdif_info snd_ctl_boolean_mono_info
1850
1851
static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
1852
struct snd_ctl_elem_value *ucontrol)
1853
{
1854
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1855
1856
if (emu->audigy)
1857
ucontrol->value.integer.value[0] = inw(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
1858
else
1859
ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
1860
if (emu->card_capabilities->invert_shared_spdif)
1861
ucontrol->value.integer.value[0] =
1862
!ucontrol->value.integer.value[0];
1863
1864
return 0;
1865
}
1866
1867
static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
1868
struct snd_ctl_elem_value *ucontrol)
1869
{
1870
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1871
unsigned int reg, val, sw;
1872
int change = 0;
1873
1874
sw = ucontrol->value.integer.value[0];
1875
if (emu->card_capabilities->invert_shared_spdif)
1876
sw = !sw;
1877
guard(spinlock_irq)(&emu->emu_lock);
1878
if ( emu->card_capabilities->i2c_adc) {
1879
/* Do nothing for Audigy 2 ZS Notebook */
1880
} else if (emu->audigy) {
1881
reg = inw(emu->port + A_IOCFG);
1882
val = sw ? A_IOCFG_GPOUT0 : 0;
1883
change = (reg & A_IOCFG_GPOUT0) != val;
1884
if (change) {
1885
reg &= ~A_IOCFG_GPOUT0;
1886
reg |= val;
1887
outw(reg | val, emu->port + A_IOCFG);
1888
}
1889
}
1890
reg = inl(emu->port + HCFG);
1891
val = sw ? HCFG_GPOUT0 : 0;
1892
change |= (reg & HCFG_GPOUT0) != val;
1893
if (change) {
1894
reg &= ~HCFG_GPOUT0;
1895
reg |= val;
1896
outl(reg | val, emu->port + HCFG);
1897
}
1898
return change;
1899
}
1900
1901
static const struct snd_kcontrol_new snd_emu10k1_shared_spdif =
1902
{
1903
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1904
.name = "SB Live Analog/Digital Output Jack",
1905
.info = snd_emu10k1_shared_spdif_info,
1906
.get = snd_emu10k1_shared_spdif_get,
1907
.put = snd_emu10k1_shared_spdif_put
1908
};
1909
1910
static const struct snd_kcontrol_new snd_audigy_shared_spdif =
1911
{
1912
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1913
.name = "Audigy Analog/Digital Output Jack",
1914
.info = snd_emu10k1_shared_spdif_info,
1915
.get = snd_emu10k1_shared_spdif_get,
1916
.put = snd_emu10k1_shared_spdif_put
1917
};
1918
1919
/* workaround for too low volume on Audigy due to 16bit/24bit conversion */
1920
1921
#define snd_audigy_capture_boost_info snd_ctl_boolean_mono_info
1922
1923
static int snd_audigy_capture_boost_get(struct snd_kcontrol *kcontrol,
1924
struct snd_ctl_elem_value *ucontrol)
1925
{
1926
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1927
unsigned int val;
1928
1929
/* FIXME: better to use a cached version */
1930
val = snd_ac97_read(emu->ac97, AC97_REC_GAIN);
1931
ucontrol->value.integer.value[0] = !!val;
1932
return 0;
1933
}
1934
1935
static int snd_audigy_capture_boost_put(struct snd_kcontrol *kcontrol,
1936
struct snd_ctl_elem_value *ucontrol)
1937
{
1938
struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1939
unsigned int val;
1940
1941
if (ucontrol->value.integer.value[0])
1942
val = 0x0f0f;
1943
else
1944
val = 0;
1945
return snd_ac97_update(emu->ac97, AC97_REC_GAIN, val);
1946
}
1947
1948
static const struct snd_kcontrol_new snd_audigy_capture_boost =
1949
{
1950
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1951
.name = "Mic Extra Boost",
1952
.info = snd_audigy_capture_boost_info,
1953
.get = snd_audigy_capture_boost_get,
1954
.put = snd_audigy_capture_boost_put
1955
};
1956
1957
1958
/*
1959
*/
1960
static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
1961
{
1962
struct snd_emu10k1 *emu = ac97->private_data;
1963
emu->ac97 = NULL;
1964
}
1965
1966
/*
1967
*/
1968
static int remove_ctl(struct snd_card *card, const char *name)
1969
{
1970
struct snd_ctl_elem_id id;
1971
memset(&id, 0, sizeof(id));
1972
strscpy(id.name, name);
1973
id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1974
return snd_ctl_remove_id(card, &id);
1975
}
1976
1977
static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
1978
{
1979
struct snd_kcontrol *kctl = snd_ctl_find_id_mixer(card, src);
1980
if (kctl) {
1981
snd_ctl_rename(card, kctl, dst);
1982
return 0;
1983
}
1984
return -ENOENT;
1985
}
1986
1987
int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1988
int pcm_device, int multi_device)
1989
{
1990
int err;
1991
struct snd_kcontrol *kctl;
1992
struct snd_card *card = emu->card;
1993
const char * const *c;
1994
static const char * const emu10k1_remove_ctls[] = {
1995
/* no AC97 mono, surround, center/lfe */
1996
"Master Mono Playback Switch",
1997
"Master Mono Playback Volume",
1998
"PCM Out Path & Mute",
1999
"Mono Output Select",
2000
"Surround Playback Switch",
2001
"Surround Playback Volume",
2002
"Center Playback Switch",
2003
"Center Playback Volume",
2004
"LFE Playback Switch",
2005
"LFE Playback Volume",
2006
NULL
2007
};
2008
static const char * const emu10k1_rename_ctls[] = {
2009
"Surround Digital Playback Volume", "Surround Playback Volume",
2010
"Center Digital Playback Volume", "Center Playback Volume",
2011
"LFE Digital Playback Volume", "LFE Playback Volume",
2012
NULL
2013
};
2014
static const char * const audigy_remove_ctls[] = {
2015
/* Master/PCM controls on ac97 of Audigy has no effect */
2016
/* On the Audigy2 the AC97 playback is piped into
2017
* the Philips ADC for 24bit capture */
2018
"PCM Playback Switch",
2019
"PCM Playback Volume",
2020
"Master Playback Switch",
2021
"Master Playback Volume",
2022
"PCM Out Path & Mute",
2023
"Mono Output Select",
2024
/* remove unused AC97 capture controls */
2025
"Capture Source",
2026
"Capture Switch",
2027
"Capture Volume",
2028
"Mic Select",
2029
"Headphone Playback Switch",
2030
"Headphone Playback Volume",
2031
"3D Control - Center",
2032
"3D Control - Depth",
2033
"3D Control - Switch",
2034
"Video Playback Switch",
2035
"Video Playback Volume",
2036
"Mic Playback Switch",
2037
"Mic Playback Volume",
2038
"External Amplifier",
2039
NULL
2040
};
2041
static const char * const audigy_rename_ctls[] = {
2042
/* use conventional names */
2043
"Wave Playback Volume", "PCM Playback Volume",
2044
/* "Wave Capture Volume", "PCM Capture Volume", */
2045
"Wave Master Playback Volume", "Master Playback Volume",
2046
"AMic Playback Volume", "Mic Playback Volume",
2047
"Master Mono Playback Switch", "Phone Output Playback Switch",
2048
"Master Mono Playback Volume", "Phone Output Playback Volume",
2049
NULL
2050
};
2051
static const char * const audigy_rename_ctls_i2c_adc[] = {
2052
//"Analog Mix Capture Volume","OLD Analog Mix Capture Volume",
2053
"Line Capture Volume", "Analog Mix Capture Volume",
2054
"Wave Playback Volume", "OLD PCM Playback Volume",
2055
"Wave Master Playback Volume", "Master Playback Volume",
2056
"AMic Playback Volume", "Old Mic Playback Volume",
2057
"CD Capture Volume", "IEC958 Optical Capture Volume",
2058
NULL
2059
};
2060
static const char * const audigy_remove_ctls_i2c_adc[] = {
2061
/* On the Audigy2 ZS Notebook
2062
* Capture via WM8775 */
2063
"Mic Capture Volume",
2064
"Analog Mix Capture Volume",
2065
"Aux Capture Volume",
2066
"IEC958 Optical Capture Volume",
2067
NULL
2068
};
2069
static const char * const audigy_remove_ctls_1361t_adc[] = {
2070
/* On the Audigy2 the AC97 playback is piped into
2071
* the Philips ADC for 24bit capture */
2072
"PCM Playback Switch",
2073
"PCM Playback Volume",
2074
"Capture Source",
2075
"Capture Switch",
2076
"Capture Volume",
2077
"Mic Capture Volume",
2078
"Headphone Playback Switch",
2079
"Headphone Playback Volume",
2080
"3D Control - Center",
2081
"3D Control - Depth",
2082
"3D Control - Switch",
2083
"Line2 Playback Volume",
2084
"Line2 Capture Volume",
2085
NULL
2086
};
2087
static const char * const audigy_rename_ctls_1361t_adc[] = {
2088
"Master Playback Switch", "Master Capture Switch",
2089
"Master Playback Volume", "Master Capture Volume",
2090
"Wave Master Playback Volume", "Master Playback Volume",
2091
"Beep Playback Switch", "Beep Capture Switch",
2092
"Beep Playback Volume", "Beep Capture Volume",
2093
"Phone Playback Switch", "Phone Capture Switch",
2094
"Phone Playback Volume", "Phone Capture Volume",
2095
"Mic Playback Switch", "Mic Capture Switch",
2096
"Mic Playback Volume", "Mic Capture Volume",
2097
"Line Playback Switch", "Line Capture Switch",
2098
"Line Playback Volume", "Line Capture Volume",
2099
"CD Playback Switch", "CD Capture Switch",
2100
"CD Playback Volume", "CD Capture Volume",
2101
"Aux Playback Switch", "Aux Capture Switch",
2102
"Aux Playback Volume", "Aux Capture Volume",
2103
"Video Playback Switch", "Video Capture Switch",
2104
"Video Playback Volume", "Video Capture Volume",
2105
"Master Mono Playback Switch", "Phone Output Playback Switch",
2106
"Master Mono Playback Volume", "Phone Output Playback Volume",
2107
NULL
2108
};
2109
2110
if (emu->card_capabilities->ac97_chip) {
2111
struct snd_ac97_bus *pbus;
2112
struct snd_ac97_template ac97;
2113
static const struct snd_ac97_bus_ops ops = {
2114
.write = snd_emu10k1_ac97_write,
2115
.read = snd_emu10k1_ac97_read,
2116
};
2117
2118
err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus);
2119
if (err < 0)
2120
return err;
2121
pbus->no_vra = 1; /* we don't need VRA */
2122
2123
memset(&ac97, 0, sizeof(ac97));
2124
ac97.private_data = emu;
2125
ac97.private_free = snd_emu10k1_mixer_free_ac97;
2126
ac97.scaps = AC97_SCAP_NO_SPDIF;
2127
err = snd_ac97_mixer(pbus, &ac97, &emu->ac97);
2128
if (err < 0) {
2129
if (emu->card_capabilities->ac97_chip == 1)
2130
return err;
2131
dev_info(emu->card->dev,
2132
"AC97 is optional on this board\n");
2133
dev_info(emu->card->dev,
2134
"Proceeding without ac97 mixers...\n");
2135
snd_device_free(emu->card, pbus);
2136
goto no_ac97; /* FIXME: get rid of ugly gotos.. */
2137
}
2138
if (emu->audigy) {
2139
/* set master volume to 0 dB */
2140
snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000);
2141
/* set capture source to mic */
2142
snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
2143
/* set mono output (TAD) to mic */
2144
snd_ac97_update_bits(emu->ac97, AC97_GENERAL_PURPOSE,
2145
0x0200, 0x0200);
2146
if (emu->card_capabilities->adc_1361t)
2147
c = audigy_remove_ctls_1361t_adc;
2148
else
2149
c = audigy_remove_ctls;
2150
} else {
2151
/*
2152
* Credits for cards based on STAC9758:
2153
* James Courtier-Dutton <[email protected]>
2154
* Voluspa <[email protected]>
2155
*/
2156
if (emu->ac97->id == AC97_ID_STAC9758) {
2157
emu->rear_ac97 = 1;
2158
snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
2159
snd_ac97_write_cache(emu->ac97, AC97_HEADPHONE, 0x0202);
2160
remove_ctl(card,"Front Playback Volume");
2161
remove_ctl(card,"Front Playback Switch");
2162
}
2163
/* remove unused AC97 controls */
2164
snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
2165
snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
2166
c = emu10k1_remove_ctls;
2167
}
2168
for (; *c; c++)
2169
remove_ctl(card, *c);
2170
} else if (emu->card_capabilities->i2c_adc) {
2171
c = audigy_remove_ctls_i2c_adc;
2172
for (; *c; c++)
2173
remove_ctl(card, *c);
2174
} else {
2175
no_ac97:
2176
if (emu->card_capabilities->ecard)
2177
strscpy(emu->card->mixername, "EMU APS");
2178
else if (emu->audigy)
2179
strscpy(emu->card->mixername, "SB Audigy");
2180
else
2181
strscpy(emu->card->mixername, "Emu10k1");
2182
}
2183
2184
if (emu->audigy)
2185
if (emu->card_capabilities->adc_1361t)
2186
c = audigy_rename_ctls_1361t_adc;
2187
else if (emu->card_capabilities->i2c_adc)
2188
c = audigy_rename_ctls_i2c_adc;
2189
else
2190
c = audigy_rename_ctls;
2191
else
2192
c = emu10k1_rename_ctls;
2193
for (; *c; c += 2)
2194
rename_ctl(card, c[0], c[1]);
2195
2196
if (emu->card_capabilities->subsystem == 0x80401102) { /* SB Live! Platinum CT4760P */
2197
remove_ctl(card, "Center Playback Volume");
2198
remove_ctl(card, "LFE Playback Volume");
2199
remove_ctl(card, "Wave Center Playback Volume");
2200
remove_ctl(card, "Wave LFE Playback Volume");
2201
}
2202
if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */
2203
rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
2204
rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
2205
rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
2206
rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
2207
}
2208
kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu);
2209
if (!kctl)
2210
return -ENOMEM;
2211
kctl->id.device = pcm_device;
2212
err = snd_ctl_add(card, kctl);
2213
if (err)
2214
return err;
2215
kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu);
2216
if (!kctl)
2217
return -ENOMEM;
2218
kctl->id.device = pcm_device;
2219
err = snd_ctl_add(card, kctl);
2220
if (err)
2221
return err;
2222
kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu);
2223
if (!kctl)
2224
return -ENOMEM;
2225
kctl->id.device = pcm_device;
2226
err = snd_ctl_add(card, kctl);
2227
if (err)
2228
return err;
2229
2230
kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu);
2231
if (!kctl)
2232
return -ENOMEM;
2233
kctl->id.device = multi_device;
2234
err = snd_ctl_add(card, kctl);
2235
if (err)
2236
return err;
2237
2238
kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu);
2239
if (!kctl)
2240
return -ENOMEM;
2241
kctl->id.device = multi_device;
2242
err = snd_ctl_add(card, kctl);
2243
if (err)
2244
return err;
2245
2246
kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu);
2247
if (!kctl)
2248
return -ENOMEM;
2249
kctl->id.device = multi_device;
2250
err = snd_ctl_add(card, kctl);
2251
if (err)
2252
return err;
2253
2254
if (!emu->card_capabilities->ecard && !emu->card_capabilities->emu_model) {
2255
/* sb live! and audigy */
2256
kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu);
2257
if (!kctl)
2258
return -ENOMEM;
2259
if (!emu->audigy)
2260
kctl->id.device = emu->pcm_efx->device;
2261
err = snd_ctl_add(card, kctl);
2262
if (err)
2263
return err;
2264
kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu);
2265
if (!kctl)
2266
return -ENOMEM;
2267
if (!emu->audigy)
2268
kctl->id.device = emu->pcm_efx->device;
2269
err = snd_ctl_add(card, kctl);
2270
if (err)
2271
return err;
2272
}
2273
2274
if (emu->card_capabilities->emu_model) {
2275
; /* Disable the snd_audigy_spdif_shared_spdif */
2276
} else if (emu->audigy) {
2277
kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu);
2278
if (!kctl)
2279
return -ENOMEM;
2280
err = snd_ctl_add(card, kctl);
2281
if (err)
2282
return err;
2283
#if 0
2284
kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu);
2285
if (!kctl)
2286
return -ENOMEM;
2287
err = snd_ctl_add(card, kctl);
2288
if (err)
2289
return err;
2290
#endif
2291
} else if (! emu->card_capabilities->ecard) {
2292
/* sb live! */
2293
kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu);
2294
if (!kctl)
2295
return -ENOMEM;
2296
err = snd_ctl_add(card, kctl);
2297
if (err)
2298
return err;
2299
}
2300
if (emu->card_capabilities->ca0151_chip) { /* P16V */
2301
err = snd_p16v_mixer(emu);
2302
if (err)
2303
return err;
2304
}
2305
2306
if (emu->card_capabilities->emu_model) {
2307
unsigned i, emu_idx = emu1010_idx(emu);
2308
const struct snd_emu1010_routing_info *emu_ri =
2309
&emu1010_routing_info[emu_idx];
2310
const struct snd_emu1010_pads_info *emu_pi = &emu1010_pads_info[emu_idx];
2311
2312
for (i = 0; i < emu_ri->n_ins; i++)
2313
emu->emu1010.input_source[i] =
2314
emu1010_map_source(emu_ri, emu_ri->in_dflts[i]);
2315
for (i = 0; i < emu_ri->n_outs; i++)
2316
emu->emu1010.output_source[i] =
2317
emu1010_map_source(emu_ri, emu_ri->out_dflts[i]);
2318
scoped_guard(snd_emu1010_fpga_lock, emu) {
2319
snd_emu1010_apply_sources(emu);
2320
}
2321
2322
kctl = emu->ctl_clock_source = snd_ctl_new1(&snd_emu1010_clock_source, emu);
2323
err = snd_ctl_add(card, kctl);
2324
if (err < 0)
2325
return err;
2326
err = snd_ctl_add(card,
2327
snd_ctl_new1(&snd_emu1010_clock_fallback, emu));
2328
if (err < 0)
2329
return err;
2330
2331
err = add_ctls(emu, &emu1010_adc_pads_ctl,
2332
emu_pi->adc_ctls, emu_pi->n_adc_ctls);
2333
if (err < 0)
2334
return err;
2335
err = add_ctls(emu, &emu1010_dac_pads_ctl,
2336
emu_pi->dac_ctls, emu_pi->n_dac_ctls);
2337
if (err < 0)
2338
return err;
2339
2340
if (!emu->card_capabilities->no_adat) {
2341
err = snd_ctl_add(card,
2342
snd_ctl_new1(&snd_emu1010_optical_out, emu));
2343
if (err < 0)
2344
return err;
2345
err = snd_ctl_add(card,
2346
snd_ctl_new1(&snd_emu1010_optical_in, emu));
2347
if (err < 0)
2348
return err;
2349
}
2350
2351
err = add_emu1010_source_mixers(emu);
2352
if (err < 0)
2353
return err;
2354
}
2355
2356
if ( emu->card_capabilities->i2c_adc) {
2357
err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_i2c_capture_source, emu));
2358
if (err < 0)
2359
return err;
2360
2361
err = add_ctls(emu, &i2c_volume_ctl,
2362
snd_audigy_i2c_volume_ctls,
2363
ARRAY_SIZE(snd_audigy_i2c_volume_ctls));
2364
if (err < 0)
2365
return err;
2366
}
2367
2368
if (emu->card_capabilities->ac97_chip && emu->audigy) {
2369
err = snd_ctl_add(card, snd_ctl_new1(&snd_audigy_capture_boost,
2370
emu));
2371
if (err < 0)
2372
return err;
2373
}
2374
2375
return 0;
2376
}
2377
2378