2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>,
3 * Takashi Iwai <tiwai@suse.de>
5 * Routines for control of EMU10K1 chips / mixer routines
6 * Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
8 * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk>
9 * Added EMU 1010 support.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include <sound/driver.h>
34 #include <linux/time.h>
35 #include <linux/init.h>
36 #include <sound/core.h>
37 #include <sound/emu10k1.h>
38 #include <linux/delay.h>
40 #define AC97_ID_STAC9758 0x83847658
42 static int snd_emu10k1_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
44 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
49 static int snd_emu10k1_spdif_get(struct snd_kcontrol *kcontrol,
50 struct snd_ctl_elem_value *ucontrol)
52 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
53 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
56 spin_lock_irqsave(&emu->reg_lock, flags);
57 ucontrol->value.iec958.status[0] = (emu->spdif_bits[idx] >> 0) & 0xff;
58 ucontrol->value.iec958.status[1] = (emu->spdif_bits[idx] >> 8) & 0xff;
59 ucontrol->value.iec958.status[2] = (emu->spdif_bits[idx] >> 16) & 0xff;
60 ucontrol->value.iec958.status[3] = (emu->spdif_bits[idx] >> 24) & 0xff;
61 spin_unlock_irqrestore(&emu->reg_lock, flags);
65 static int snd_emu10k1_spdif_get_mask(struct snd_kcontrol *kcontrol,
66 struct snd_ctl_elem_value *ucontrol)
68 ucontrol->value.iec958.status[0] = 0xff;
69 ucontrol->value.iec958.status[1] = 0xff;
70 ucontrol->value.iec958.status[2] = 0xff;
71 ucontrol->value.iec958.status[3] = 0xff;
75 static char *emu1010_src_texts[] = {
131 static unsigned int emu1010_src_regs[] = {
132 EMU_SRC_SILENCE,/* 0 */
133 EMU_SRC_DOCK_MIC_A1, /* 1 */
134 EMU_SRC_DOCK_MIC_B1, /* 2 */
135 EMU_SRC_DOCK_ADC1_LEFT1, /* 3 */
136 EMU_SRC_DOCK_ADC1_RIGHT1, /* 4 */
137 EMU_SRC_DOCK_ADC2_LEFT1, /* 5 */
138 EMU_SRC_DOCK_ADC2_RIGHT1, /* 6 */
139 EMU_SRC_DOCK_ADC3_LEFT1, /* 7 */
140 EMU_SRC_DOCK_ADC3_RIGHT1, /* 8 */
141 EMU_SRC_HAMOA_ADC_LEFT1, /* 9 */
142 EMU_SRC_HAMOA_ADC_RIGHT1, /* 10 */
143 EMU_SRC_HANA_SPDIF_LEFT1, /* 11 */
144 EMU_SRC_HANA_SPDIF_RIGHT1, /* 12 */
145 EMU_SRC_HANA_ADAT, /* 13 */
146 EMU_SRC_HANA_ADAT+1, /* 14 */
147 EMU_SRC_HANA_ADAT+2, /* 15 */
148 EMU_SRC_HANA_ADAT+3, /* 16 */
149 EMU_SRC_HANA_ADAT+4, /* 17 */
150 EMU_SRC_HANA_ADAT+5, /* 18 */
151 EMU_SRC_HANA_ADAT+6, /* 19 */
152 EMU_SRC_HANA_ADAT+7, /* 20 */
153 EMU_SRC_ALICE_EMU32A, /* 21 */
154 EMU_SRC_ALICE_EMU32A+1, /* 22 */
155 EMU_SRC_ALICE_EMU32A+2, /* 23 */
156 EMU_SRC_ALICE_EMU32A+3, /* 24 */
157 EMU_SRC_ALICE_EMU32A+4, /* 25 */
158 EMU_SRC_ALICE_EMU32A+5, /* 26 */
159 EMU_SRC_ALICE_EMU32A+6, /* 27 */
160 EMU_SRC_ALICE_EMU32A+7, /* 28 */
161 EMU_SRC_ALICE_EMU32A+8, /* 29 */
162 EMU_SRC_ALICE_EMU32A+9, /* 30 */
163 EMU_SRC_ALICE_EMU32A+0xa, /* 31 */
164 EMU_SRC_ALICE_EMU32A+0xb, /* 32 */
165 EMU_SRC_ALICE_EMU32A+0xc, /* 33 */
166 EMU_SRC_ALICE_EMU32A+0xd, /* 34 */
167 EMU_SRC_ALICE_EMU32A+0xe, /* 35 */
168 EMU_SRC_ALICE_EMU32A+0xf, /* 36 */
169 EMU_SRC_ALICE_EMU32B, /* 37 */
170 EMU_SRC_ALICE_EMU32B+1, /* 38 */
171 EMU_SRC_ALICE_EMU32B+2, /* 39 */
172 EMU_SRC_ALICE_EMU32B+3, /* 40 */
173 EMU_SRC_ALICE_EMU32B+4, /* 41 */
174 EMU_SRC_ALICE_EMU32B+5, /* 42 */
175 EMU_SRC_ALICE_EMU32B+6, /* 43 */
176 EMU_SRC_ALICE_EMU32B+7, /* 44 */
177 EMU_SRC_ALICE_EMU32B+8, /* 45 */
178 EMU_SRC_ALICE_EMU32B+9, /* 46 */
179 EMU_SRC_ALICE_EMU32B+0xa, /* 47 */
180 EMU_SRC_ALICE_EMU32B+0xb, /* 48 */
181 EMU_SRC_ALICE_EMU32B+0xc, /* 49 */
182 EMU_SRC_ALICE_EMU32B+0xd, /* 50 */
183 EMU_SRC_ALICE_EMU32B+0xe, /* 51 */
184 EMU_SRC_ALICE_EMU32B+0xf, /* 52 */
187 static unsigned int emu1010_output_dst[] = {
188 EMU_DST_DOCK_DAC1_LEFT1, /* 0 */
189 EMU_DST_DOCK_DAC1_RIGHT1, /* 1 */
190 EMU_DST_DOCK_DAC2_LEFT1, /* 2 */
191 EMU_DST_DOCK_DAC2_RIGHT1, /* 3 */
192 EMU_DST_DOCK_DAC3_LEFT1, /* 4 */
193 EMU_DST_DOCK_DAC3_RIGHT1, /* 5 */
194 EMU_DST_DOCK_DAC4_LEFT1, /* 6 */
195 EMU_DST_DOCK_DAC4_RIGHT1, /* 7 */
196 EMU_DST_DOCK_PHONES_LEFT1, /* 8 */
197 EMU_DST_DOCK_PHONES_RIGHT1, /* 9 */
198 EMU_DST_DOCK_SPDIF_LEFT1, /* 10 */
199 EMU_DST_DOCK_SPDIF_RIGHT1, /* 11 */
200 EMU_DST_HANA_SPDIF_LEFT1, /* 12 */
201 EMU_DST_HANA_SPDIF_RIGHT1, /* 13 */
202 EMU_DST_HAMOA_DAC_LEFT1, /* 14 */
203 EMU_DST_HAMOA_DAC_RIGHT1, /* 15 */
204 EMU_DST_HANA_ADAT, /* 16 */
205 EMU_DST_HANA_ADAT+1, /* 17 */
206 EMU_DST_HANA_ADAT+2, /* 18 */
207 EMU_DST_HANA_ADAT+3, /* 19 */
208 EMU_DST_HANA_ADAT+4, /* 20 */
209 EMU_DST_HANA_ADAT+5, /* 21 */
210 EMU_DST_HANA_ADAT+6, /* 22 */
211 EMU_DST_HANA_ADAT+7, /* 23 */
214 static unsigned int emu1010_input_dst[] = {
215 EMU_DST_ALICE2_EMU32_0,
216 EMU_DST_ALICE2_EMU32_1,
217 EMU_DST_ALICE2_EMU32_2,
218 EMU_DST_ALICE2_EMU32_3,
219 EMU_DST_ALICE2_EMU32_4,
220 EMU_DST_ALICE2_EMU32_5,
221 EMU_DST_ALICE2_EMU32_6,
222 EMU_DST_ALICE2_EMU32_7,
223 EMU_DST_ALICE2_EMU32_8,
224 EMU_DST_ALICE2_EMU32_9,
225 EMU_DST_ALICE2_EMU32_A,
226 EMU_DST_ALICE2_EMU32_B,
227 EMU_DST_ALICE2_EMU32_C,
228 EMU_DST_ALICE2_EMU32_D,
229 EMU_DST_ALICE2_EMU32_E,
230 EMU_DST_ALICE2_EMU32_F,
231 EMU_DST_ALICE_I2S0_LEFT,
232 EMU_DST_ALICE_I2S0_RIGHT,
233 EMU_DST_ALICE_I2S1_LEFT,
234 EMU_DST_ALICE_I2S1_RIGHT,
235 EMU_DST_ALICE_I2S2_LEFT,
236 EMU_DST_ALICE_I2S2_RIGHT,
239 static int snd_emu1010_input_output_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
241 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
243 uinfo->value.enumerated.items = 53;
244 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
245 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
246 strcpy(uinfo->value.enumerated.name, emu1010_src_texts[uinfo->value.enumerated.item]);
250 static int snd_emu1010_output_source_get(struct snd_kcontrol *kcontrol,
251 struct snd_ctl_elem_value *ucontrol)
253 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
256 channel = (kcontrol->private_value) & 0xff;
257 ucontrol->value.enumerated.item[0] = emu->emu1010.output_source[channel];
261 static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol,
262 struct snd_ctl_elem_value *ucontrol)
264 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
269 channel = (kcontrol->private_value) & 0xff;
270 if (emu->emu1010.output_source[channel] != ucontrol->value.enumerated.item[0]) {
271 val = emu->emu1010.output_source[channel] = ucontrol->value.enumerated.item[0];
273 snd_emu1010_fpga_link_dst_src_write(emu,
274 emu1010_output_dst[channel], emu1010_src_regs[val]);
279 static int snd_emu1010_input_source_get(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_value *ucontrol)
282 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
285 channel = (kcontrol->private_value) & 0xff;
286 ucontrol->value.enumerated.item[0] = emu->emu1010.input_source[channel];
290 static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol,
291 struct snd_ctl_elem_value *ucontrol)
293 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
298 channel = (kcontrol->private_value) & 0xff;
299 if (emu->emu1010.input_source[channel] != ucontrol->value.enumerated.item[0]) {
300 val = emu->emu1010.input_source[channel] = ucontrol->value.enumerated.item[0];
302 snd_emu1010_fpga_link_dst_src_write(emu,
303 emu1010_input_dst[channel], emu1010_src_regs[val]);
308 #define EMU1010_SOURCE_OUTPUT(xname,chid) \
310 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
311 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
312 .info = snd_emu1010_input_output_source_info, \
313 .get = snd_emu1010_output_source_get, \
314 .put = snd_emu1010_output_source_put, \
315 .private_value = chid \
318 static struct snd_kcontrol_new snd_emu1010_output_enum_ctls[] __devinitdata = {
319 EMU1010_SOURCE_OUTPUT("Dock DAC1 Left Playback Switch", 0),
320 EMU1010_SOURCE_OUTPUT("Dock DAC1 Right Playback Switch", 1),
321 EMU1010_SOURCE_OUTPUT("Dock DAC2 Left Playback Switch", 2),
322 EMU1010_SOURCE_OUTPUT("Dock DAC2 Right Playback Switch", 3),
323 EMU1010_SOURCE_OUTPUT("Dock DAC3 Left Playback Switch", 4),
324 EMU1010_SOURCE_OUTPUT("Dock DAC3 Right Playback Switch", 5),
325 EMU1010_SOURCE_OUTPUT("Dock DAC4 Left Playback Switch", 6),
326 EMU1010_SOURCE_OUTPUT("Dock DAC4 Right Playback Switch", 7),
327 EMU1010_SOURCE_OUTPUT("Dock Phones Left Playback Switch", 8),
328 EMU1010_SOURCE_OUTPUT("Dock Phones Right Playback Switch", 9),
329 EMU1010_SOURCE_OUTPUT("Dock SPDIF Left Playback Switch", 0xa),
330 EMU1010_SOURCE_OUTPUT("Dock SPDIF Right Playback Switch", 0xb),
331 EMU1010_SOURCE_OUTPUT("1010 SPDIF Left Playback Switch", 0xc),
332 EMU1010_SOURCE_OUTPUT("1010 SPDIF Right Playback Switch", 0xd),
333 EMU1010_SOURCE_OUTPUT("0202 DAC Left Playback Switch", 0xe),
334 EMU1010_SOURCE_OUTPUT("0202 DAC Right Playback Switch", 0xf),
335 EMU1010_SOURCE_OUTPUT("1010 ADAT 0 Playback Switch", 0x10),
336 EMU1010_SOURCE_OUTPUT("1010 ADAT 1 Playback Switch", 0x11),
337 EMU1010_SOURCE_OUTPUT("1010 ADAT 2 Playback Switch", 0x12),
338 EMU1010_SOURCE_OUTPUT("1010 ADAT 3 Playback Switch", 0x13),
339 EMU1010_SOURCE_OUTPUT("1010 ADAT 4 Playback Switch", 0x14),
340 EMU1010_SOURCE_OUTPUT("1010 ADAT 5 Playback Switch", 0x15),
341 EMU1010_SOURCE_OUTPUT("1010 ADAT 6 Playback Switch", 0x16),
342 EMU1010_SOURCE_OUTPUT("1010 ADAT 7 Playback Switch", 0x17),
345 #define EMU1010_SOURCE_INPUT(xname,chid) \
347 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
348 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
349 .info = snd_emu1010_input_output_source_info, \
350 .get = snd_emu1010_input_source_get, \
351 .put = snd_emu1010_input_source_put, \
352 .private_value = chid \
355 static struct snd_kcontrol_new snd_emu1010_input_enum_ctls[] __devinitdata = {
356 EMU1010_SOURCE_INPUT("DSP 0 Capture Switch", 0),
357 EMU1010_SOURCE_INPUT("DSP 1 Capture Switch", 1),
358 EMU1010_SOURCE_INPUT("DSP 2 Capture Switch", 2),
359 EMU1010_SOURCE_INPUT("DSP 3 Capture Switch", 3),
360 EMU1010_SOURCE_INPUT("DSP 4 Capture Switch", 4),
361 EMU1010_SOURCE_INPUT("DSP 5 Capture Switch", 5),
362 EMU1010_SOURCE_INPUT("DSP 6 Capture Switch", 6),
363 EMU1010_SOURCE_INPUT("DSP 7 Capture Switch", 7),
364 EMU1010_SOURCE_INPUT("DSP 8 Capture Switch", 8),
365 EMU1010_SOURCE_INPUT("DSP 9 Capture Switch", 9),
366 EMU1010_SOURCE_INPUT("DSP A Capture Switch", 0xa),
367 EMU1010_SOURCE_INPUT("DSP B Capture Switch", 0xb),
368 EMU1010_SOURCE_INPUT("DSP C Capture Switch", 0xc),
369 EMU1010_SOURCE_INPUT("DSP D Capture Switch", 0xd),
370 EMU1010_SOURCE_INPUT("DSP E Capture Switch", 0xe),
371 EMU1010_SOURCE_INPUT("DSP F Capture Switch", 0xf),
372 EMU1010_SOURCE_INPUT("DSP 10 Capture Switch", 0x10),
373 EMU1010_SOURCE_INPUT("DSP 11 Capture Switch", 0x11),
374 EMU1010_SOURCE_INPUT("DSP 12 Capture Switch", 0x12),
375 EMU1010_SOURCE_INPUT("DSP 13 Capture Switch", 0x13),
376 EMU1010_SOURCE_INPUT("DSP 14 Capture Switch", 0x14),
377 EMU1010_SOURCE_INPUT("DSP 15 Capture Switch", 0x15),
383 static int snd_emu1010_adc_pads_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
385 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
387 uinfo->value.integer.min = 0;
388 uinfo->value.integer.max = 1;
392 static int snd_emu1010_adc_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
394 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
395 unsigned int mask = kcontrol->private_value & 0xff;
396 ucontrol->value.integer.value[0] = (emu->emu1010.adc_pads & mask) ? 1 : 0;
400 static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
402 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
403 unsigned int mask = kcontrol->private_value & 0xff;
404 unsigned int val, cache;
405 val = ucontrol->value.integer.value[0];
406 cache = emu->emu1010.adc_pads;
408 cache = cache | mask;
410 cache = cache & ~mask;
411 if (cache != emu->emu1010.adc_pads) {
412 snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, cache );
413 emu->emu1010.adc_pads = cache;
421 #define EMU1010_ADC_PADS(xname,chid) \
423 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
424 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
425 .info = snd_emu1010_adc_pads_info, \
426 .get = snd_emu1010_adc_pads_get, \
427 .put = snd_emu1010_adc_pads_put, \
428 .private_value = chid \
431 static struct snd_kcontrol_new snd_emu1010_adc_pads[] __devinitdata = {
432 EMU1010_ADC_PADS("ADC1 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD1),
433 EMU1010_ADC_PADS("ADC2 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD2),
434 EMU1010_ADC_PADS("ADC3 14dB PAD Audio Dock Capture Switch", EMU_HANA_DOCK_ADC_PAD3),
435 EMU1010_ADC_PADS("ADC1 14dB PAD 0202 Capture Switch", EMU_HANA_0202_ADC_PAD1),
438 static int snd_emu1010_dac_pads_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
440 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
442 uinfo->value.integer.min = 0;
443 uinfo->value.integer.max = 1;
447 static int snd_emu1010_dac_pads_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
449 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
450 unsigned int mask = kcontrol->private_value & 0xff;
451 ucontrol->value.integer.value[0] = (emu->emu1010.dac_pads & mask) ? 1 : 0;
455 static int snd_emu1010_dac_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
457 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
458 unsigned int mask = kcontrol->private_value & 0xff;
459 unsigned int val, cache;
460 val = ucontrol->value.integer.value[0];
461 cache = emu->emu1010.dac_pads;
463 cache = cache | mask;
465 cache = cache & ~mask;
466 if (cache != emu->emu1010.dac_pads) {
467 snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, cache );
468 emu->emu1010.dac_pads = cache;
476 #define EMU1010_DAC_PADS(xname,chid) \
478 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
479 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
480 .info = snd_emu1010_dac_pads_info, \
481 .get = snd_emu1010_dac_pads_get, \
482 .put = snd_emu1010_dac_pads_put, \
483 .private_value = chid \
486 static struct snd_kcontrol_new snd_emu1010_dac_pads[] __devinitdata = {
487 EMU1010_DAC_PADS("DAC1 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD1),
488 EMU1010_DAC_PADS("DAC2 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD2),
489 EMU1010_DAC_PADS("DAC3 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD3),
490 EMU1010_DAC_PADS("DAC4 Audio Dock 14dB PAD Playback Switch", EMU_HANA_DOCK_DAC_PAD4),
491 EMU1010_DAC_PADS("DAC1 0202 14dB PAD Playback Switch", EMU_HANA_0202_DAC_PAD1),
495 static int snd_emu1010_internal_clock_info(struct snd_kcontrol *kcontrol,
496 struct snd_ctl_elem_info *uinfo)
498 static char *texts[2] = {
502 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
504 uinfo->value.enumerated.items = 2;
505 if (uinfo->value.enumerated.item > 1)
506 uinfo->value.enumerated.item = 1;
507 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
511 static int snd_emu1010_internal_clock_get(struct snd_kcontrol *kcontrol,
512 struct snd_ctl_elem_value *ucontrol)
514 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
516 ucontrol->value.enumerated.item[0] = emu->emu1010.internal_clock;
520 static int snd_emu1010_internal_clock_put(struct snd_kcontrol *kcontrol,
521 struct snd_ctl_elem_value *ucontrol)
523 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
527 val = ucontrol->value.enumerated.item[0] ;
528 change = (emu->emu1010.internal_clock != val);
530 emu->emu1010.internal_clock = val;
535 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE );
536 /* Default fallback clock 48kHz */
537 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_44_1K );
538 /* Word Clock source, Internal 44.1kHz x1 */
539 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK,
540 EMU_HANA_WCLOCK_INT_44_1K | EMU_HANA_WCLOCK_1X );
541 /* Set LEDs on Audio Dock */
542 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2,
543 EMU_HANA_DOCK_LEDS_2_44K | EMU_HANA_DOCK_LEDS_2_LOCK );
544 /* Allow DLL to settle */
547 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE );
552 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_MUTE );
553 /* Default fallback clock 48kHz */
554 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, EMU_HANA_DEFCLOCK_48K );
555 /* Word Clock source, Internal 48kHz x1 */
556 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK,
557 EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_1X );
558 /* Set LEDs on Audio Dock */
559 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2,
560 EMU_HANA_DOCK_LEDS_2_48K | EMU_HANA_DOCK_LEDS_2_LOCK );
561 /* Allow DLL to settle */
564 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE );
571 static struct snd_kcontrol_new snd_emu1010_internal_clock =
573 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
574 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
575 .name = "Clock Internal Rate",
577 .info = snd_emu1010_internal_clock_info,
578 .get = snd_emu1010_internal_clock_get,
579 .put = snd_emu1010_internal_clock_put
583 static int snd_audigy_spdif_output_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
585 static char *texts[] = {"44100", "48000", "96000"};
587 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
589 uinfo->value.enumerated.items = 3;
590 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
591 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
592 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
596 static int snd_audigy_spdif_output_rate_get(struct snd_kcontrol *kcontrol,
597 struct snd_ctl_elem_value *ucontrol)
599 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
604 spin_lock_irqsave(&emu->reg_lock, flags);
605 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
606 switch (tmp & A_SPDIF_RATE_MASK) {
608 ucontrol->value.enumerated.item[0] = 0;
611 ucontrol->value.enumerated.item[0] = 1;
614 ucontrol->value.enumerated.item[0] = 2;
617 ucontrol->value.enumerated.item[0] = 1;
619 spin_unlock_irqrestore(&emu->reg_lock, flags);
623 static int snd_audigy_spdif_output_rate_put(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_value *ucontrol)
626 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
628 unsigned int reg, val, tmp;
631 switch(ucontrol->value.enumerated.item[0]) {
647 spin_lock_irqsave(&emu->reg_lock, flags);
648 reg = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
649 tmp = reg & ~A_SPDIF_RATE_MASK;
651 if ((change = (tmp != reg)))
652 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
653 spin_unlock_irqrestore(&emu->reg_lock, flags);
657 static struct snd_kcontrol_new snd_audigy_spdif_output_rate =
659 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
660 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
661 .name = "Audigy SPDIF Output Sample Rate",
663 .info = snd_audigy_spdif_output_rate_info,
664 .get = snd_audigy_spdif_output_rate_get,
665 .put = snd_audigy_spdif_output_rate_put
669 static int snd_emu10k1_spdif_put(struct snd_kcontrol *kcontrol,
670 struct snd_ctl_elem_value *ucontrol)
672 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
673 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
678 val = (ucontrol->value.iec958.status[0] << 0) |
679 (ucontrol->value.iec958.status[1] << 8) |
680 (ucontrol->value.iec958.status[2] << 16) |
681 (ucontrol->value.iec958.status[3] << 24);
682 spin_lock_irqsave(&emu->reg_lock, flags);
683 change = val != emu->spdif_bits[idx];
685 snd_emu10k1_ptr_write(emu, SPCS0 + idx, 0, val);
686 emu->spdif_bits[idx] = val;
688 spin_unlock_irqrestore(&emu->reg_lock, flags);
692 static struct snd_kcontrol_new snd_emu10k1_spdif_mask_control =
694 .access = SNDRV_CTL_ELEM_ACCESS_READ,
695 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
696 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
698 .info = snd_emu10k1_spdif_info,
699 .get = snd_emu10k1_spdif_get_mask
702 static struct snd_kcontrol_new snd_emu10k1_spdif_control =
704 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
705 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
707 .info = snd_emu10k1_spdif_info,
708 .get = snd_emu10k1_spdif_get,
709 .put = snd_emu10k1_spdif_put
713 static void update_emu10k1_fxrt(struct snd_emu10k1 *emu, int voice, unsigned char *route)
716 snd_emu10k1_ptr_write(emu, A_FXRT1, voice,
717 snd_emu10k1_compose_audigy_fxrt1(route));
718 snd_emu10k1_ptr_write(emu, A_FXRT2, voice,
719 snd_emu10k1_compose_audigy_fxrt2(route));
721 snd_emu10k1_ptr_write(emu, FXRT, voice,
722 snd_emu10k1_compose_send_routing(route));
726 static void update_emu10k1_send_volume(struct snd_emu10k1 *emu, int voice, unsigned char *volume)
728 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_A, voice, volume[0]);
729 snd_emu10k1_ptr_write(emu, PTRX_FXSENDAMOUNT_B, voice, volume[1]);
730 snd_emu10k1_ptr_write(emu, PSST_FXSENDAMOUNT_C, voice, volume[2]);
731 snd_emu10k1_ptr_write(emu, DSL_FXSENDAMOUNT_D, voice, volume[3]);
733 unsigned int val = ((unsigned int)volume[4] << 24) |
734 ((unsigned int)volume[5] << 16) |
735 ((unsigned int)volume[6] << 8) |
736 (unsigned int)volume[7];
737 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice, val);
741 /* PCM stream controls */
743 static int snd_emu10k1_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
745 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
746 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
747 uinfo->count = emu->audigy ? 3*8 : 3*4;
748 uinfo->value.integer.min = 0;
749 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
753 static int snd_emu10k1_send_routing_get(struct snd_kcontrol *kcontrol,
754 struct snd_ctl_elem_value *ucontrol)
757 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
758 struct snd_emu10k1_pcm_mixer *mix =
759 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
761 int num_efx = emu->audigy ? 8 : 4;
762 int mask = emu->audigy ? 0x3f : 0x0f;
764 spin_lock_irqsave(&emu->reg_lock, flags);
765 for (voice = 0; voice < 3; voice++)
766 for (idx = 0; idx < num_efx; idx++)
767 ucontrol->value.integer.value[(voice * num_efx) + idx] =
768 mix->send_routing[voice][idx] & mask;
769 spin_unlock_irqrestore(&emu->reg_lock, flags);
773 static int snd_emu10k1_send_routing_put(struct snd_kcontrol *kcontrol,
774 struct snd_ctl_elem_value *ucontrol)
777 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
778 struct snd_emu10k1_pcm_mixer *mix =
779 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
780 int change = 0, voice, idx, val;
781 int num_efx = emu->audigy ? 8 : 4;
782 int mask = emu->audigy ? 0x3f : 0x0f;
784 spin_lock_irqsave(&emu->reg_lock, flags);
785 for (voice = 0; voice < 3; voice++)
786 for (idx = 0; idx < num_efx; idx++) {
787 val = ucontrol->value.integer.value[(voice * num_efx) + idx] & mask;
788 if (mix->send_routing[voice][idx] != val) {
789 mix->send_routing[voice][idx] = val;
793 if (change && mix->epcm) {
794 if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
795 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
796 &mix->send_routing[1][0]);
797 update_emu10k1_fxrt(emu, mix->epcm->voices[1]->number,
798 &mix->send_routing[2][0]);
799 } else if (mix->epcm->voices[0]) {
800 update_emu10k1_fxrt(emu, mix->epcm->voices[0]->number,
801 &mix->send_routing[0][0]);
804 spin_unlock_irqrestore(&emu->reg_lock, flags);
808 static struct snd_kcontrol_new snd_emu10k1_send_routing_control =
810 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
811 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
812 .name = "EMU10K1 PCM Send Routing",
814 .info = snd_emu10k1_send_routing_info,
815 .get = snd_emu10k1_send_routing_get,
816 .put = snd_emu10k1_send_routing_put
819 static int snd_emu10k1_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
821 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
822 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
823 uinfo->count = emu->audigy ? 3*8 : 3*4;
824 uinfo->value.integer.min = 0;
825 uinfo->value.integer.max = 255;
829 static int snd_emu10k1_send_volume_get(struct snd_kcontrol *kcontrol,
830 struct snd_ctl_elem_value *ucontrol)
833 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
834 struct snd_emu10k1_pcm_mixer *mix =
835 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
837 int num_efx = emu->audigy ? 8 : 4;
839 spin_lock_irqsave(&emu->reg_lock, flags);
840 for (idx = 0; idx < 3*num_efx; idx++)
841 ucontrol->value.integer.value[idx] = mix->send_volume[idx/num_efx][idx%num_efx];
842 spin_unlock_irqrestore(&emu->reg_lock, flags);
846 static int snd_emu10k1_send_volume_put(struct snd_kcontrol *kcontrol,
847 struct snd_ctl_elem_value *ucontrol)
850 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
851 struct snd_emu10k1_pcm_mixer *mix =
852 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
853 int change = 0, idx, val;
854 int num_efx = emu->audigy ? 8 : 4;
856 spin_lock_irqsave(&emu->reg_lock, flags);
857 for (idx = 0; idx < 3*num_efx; idx++) {
858 val = ucontrol->value.integer.value[idx] & 255;
859 if (mix->send_volume[idx/num_efx][idx%num_efx] != val) {
860 mix->send_volume[idx/num_efx][idx%num_efx] = val;
864 if (change && mix->epcm) {
865 if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
866 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
867 &mix->send_volume[1][0]);
868 update_emu10k1_send_volume(emu, mix->epcm->voices[1]->number,
869 &mix->send_volume[2][0]);
870 } else if (mix->epcm->voices[0]) {
871 update_emu10k1_send_volume(emu, mix->epcm->voices[0]->number,
872 &mix->send_volume[0][0]);
875 spin_unlock_irqrestore(&emu->reg_lock, flags);
879 static struct snd_kcontrol_new snd_emu10k1_send_volume_control =
881 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
882 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
883 .name = "EMU10K1 PCM Send Volume",
885 .info = snd_emu10k1_send_volume_info,
886 .get = snd_emu10k1_send_volume_get,
887 .put = snd_emu10k1_send_volume_put
890 static int snd_emu10k1_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
892 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
894 uinfo->value.integer.min = 0;
895 uinfo->value.integer.max = 0xffff;
899 static int snd_emu10k1_attn_get(struct snd_kcontrol *kcontrol,
900 struct snd_ctl_elem_value *ucontrol)
902 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
903 struct snd_emu10k1_pcm_mixer *mix =
904 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
908 spin_lock_irqsave(&emu->reg_lock, flags);
909 for (idx = 0; idx < 3; idx++)
910 ucontrol->value.integer.value[idx] = mix->attn[idx];
911 spin_unlock_irqrestore(&emu->reg_lock, flags);
915 static int snd_emu10k1_attn_put(struct snd_kcontrol *kcontrol,
916 struct snd_ctl_elem_value *ucontrol)
919 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
920 struct snd_emu10k1_pcm_mixer *mix =
921 &emu->pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
922 int change = 0, idx, val;
924 spin_lock_irqsave(&emu->reg_lock, flags);
925 for (idx = 0; idx < 3; idx++) {
926 val = ucontrol->value.integer.value[idx] & 0xffff;
927 if (mix->attn[idx] != val) {
928 mix->attn[idx] = val;
932 if (change && mix->epcm) {
933 if (mix->epcm->voices[0] && mix->epcm->voices[1]) {
934 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[1]);
935 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[1]->number, mix->attn[2]);
936 } else if (mix->epcm->voices[0]) {
937 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[0]->number, mix->attn[0]);
940 spin_unlock_irqrestore(&emu->reg_lock, flags);
944 static struct snd_kcontrol_new snd_emu10k1_attn_control =
946 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
947 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
948 .name = "EMU10K1 PCM Volume",
950 .info = snd_emu10k1_attn_info,
951 .get = snd_emu10k1_attn_get,
952 .put = snd_emu10k1_attn_put
955 /* Mutichannel PCM stream controls */
957 static int snd_emu10k1_efx_send_routing_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
959 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
960 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
961 uinfo->count = emu->audigy ? 8 : 4;
962 uinfo->value.integer.min = 0;
963 uinfo->value.integer.max = emu->audigy ? 0x3f : 0x0f;
967 static int snd_emu10k1_efx_send_routing_get(struct snd_kcontrol *kcontrol,
968 struct snd_ctl_elem_value *ucontrol)
971 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
972 struct snd_emu10k1_pcm_mixer *mix =
973 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
975 int num_efx = emu->audigy ? 8 : 4;
976 int mask = emu->audigy ? 0x3f : 0x0f;
978 spin_lock_irqsave(&emu->reg_lock, flags);
979 for (idx = 0; idx < num_efx; idx++)
980 ucontrol->value.integer.value[idx] =
981 mix->send_routing[0][idx] & mask;
982 spin_unlock_irqrestore(&emu->reg_lock, flags);
986 static int snd_emu10k1_efx_send_routing_put(struct snd_kcontrol *kcontrol,
987 struct snd_ctl_elem_value *ucontrol)
990 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
991 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
992 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
993 int change = 0, idx, val;
994 int num_efx = emu->audigy ? 8 : 4;
995 int mask = emu->audigy ? 0x3f : 0x0f;
997 spin_lock_irqsave(&emu->reg_lock, flags);
998 for (idx = 0; idx < num_efx; idx++) {
999 val = ucontrol->value.integer.value[idx] & mask;
1000 if (mix->send_routing[0][idx] != val) {
1001 mix->send_routing[0][idx] = val;
1006 if (change && mix->epcm) {
1007 if (mix->epcm->voices[ch]) {
1008 update_emu10k1_fxrt(emu, mix->epcm->voices[ch]->number,
1009 &mix->send_routing[0][0]);
1012 spin_unlock_irqrestore(&emu->reg_lock, flags);
1016 static struct snd_kcontrol_new snd_emu10k1_efx_send_routing_control =
1018 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1019 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1020 .name = "Multichannel PCM Send Routing",
1022 .info = snd_emu10k1_efx_send_routing_info,
1023 .get = snd_emu10k1_efx_send_routing_get,
1024 .put = snd_emu10k1_efx_send_routing_put
1027 static int snd_emu10k1_efx_send_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1029 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1030 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1031 uinfo->count = emu->audigy ? 8 : 4;
1032 uinfo->value.integer.min = 0;
1033 uinfo->value.integer.max = 255;
1037 static int snd_emu10k1_efx_send_volume_get(struct snd_kcontrol *kcontrol,
1038 struct snd_ctl_elem_value *ucontrol)
1040 unsigned long flags;
1041 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1042 struct snd_emu10k1_pcm_mixer *mix =
1043 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1045 int num_efx = emu->audigy ? 8 : 4;
1047 spin_lock_irqsave(&emu->reg_lock, flags);
1048 for (idx = 0; idx < num_efx; idx++)
1049 ucontrol->value.integer.value[idx] = mix->send_volume[0][idx];
1050 spin_unlock_irqrestore(&emu->reg_lock, flags);
1054 static int snd_emu10k1_efx_send_volume_put(struct snd_kcontrol *kcontrol,
1055 struct snd_ctl_elem_value *ucontrol)
1057 unsigned long flags;
1058 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1059 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1060 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1061 int change = 0, idx, val;
1062 int num_efx = emu->audigy ? 8 : 4;
1064 spin_lock_irqsave(&emu->reg_lock, flags);
1065 for (idx = 0; idx < num_efx; idx++) {
1066 val = ucontrol->value.integer.value[idx] & 255;
1067 if (mix->send_volume[0][idx] != val) {
1068 mix->send_volume[0][idx] = val;
1072 if (change && mix->epcm) {
1073 if (mix->epcm->voices[ch]) {
1074 update_emu10k1_send_volume(emu, mix->epcm->voices[ch]->number,
1075 &mix->send_volume[0][0]);
1078 spin_unlock_irqrestore(&emu->reg_lock, flags);
1083 static struct snd_kcontrol_new snd_emu10k1_efx_send_volume_control =
1085 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1086 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1087 .name = "Multichannel PCM Send Volume",
1089 .info = snd_emu10k1_efx_send_volume_info,
1090 .get = snd_emu10k1_efx_send_volume_get,
1091 .put = snd_emu10k1_efx_send_volume_put
1094 static int snd_emu10k1_efx_attn_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1096 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1098 uinfo->value.integer.min = 0;
1099 uinfo->value.integer.max = 0xffff;
1103 static int snd_emu10k1_efx_attn_get(struct snd_kcontrol *kcontrol,
1104 struct snd_ctl_elem_value *ucontrol)
1106 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1107 struct snd_emu10k1_pcm_mixer *mix =
1108 &emu->efx_pcm_mixer[snd_ctl_get_ioffidx(kcontrol, &ucontrol->id)];
1109 unsigned long flags;
1111 spin_lock_irqsave(&emu->reg_lock, flags);
1112 ucontrol->value.integer.value[0] = mix->attn[0];
1113 spin_unlock_irqrestore(&emu->reg_lock, flags);
1117 static int snd_emu10k1_efx_attn_put(struct snd_kcontrol *kcontrol,
1118 struct snd_ctl_elem_value *ucontrol)
1120 unsigned long flags;
1121 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1122 int ch = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1123 struct snd_emu10k1_pcm_mixer *mix = &emu->efx_pcm_mixer[ch];
1124 int change = 0, val;
1126 spin_lock_irqsave(&emu->reg_lock, flags);
1127 val = ucontrol->value.integer.value[0] & 0xffff;
1128 if (mix->attn[0] != val) {
1132 if (change && mix->epcm) {
1133 if (mix->epcm->voices[ch]) {
1134 snd_emu10k1_ptr_write(emu, VTFT_VOLUMETARGET, mix->epcm->voices[ch]->number, mix->attn[0]);
1137 spin_unlock_irqrestore(&emu->reg_lock, flags);
1141 static struct snd_kcontrol_new snd_emu10k1_efx_attn_control =
1143 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1144 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1145 .name = "Multichannel PCM Volume",
1147 .info = snd_emu10k1_efx_attn_info,
1148 .get = snd_emu10k1_efx_attn_get,
1149 .put = snd_emu10k1_efx_attn_put
1152 static int snd_emu10k1_shared_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1154 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1156 uinfo->value.integer.min = 0;
1157 uinfo->value.integer.max = 1;
1161 static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
1162 struct snd_ctl_elem_value *ucontrol)
1164 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1167 ucontrol->value.integer.value[0] = inl(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
1169 ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
1173 static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
1174 struct snd_ctl_elem_value *ucontrol)
1176 unsigned long flags;
1177 struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
1178 unsigned int reg, val;
1181 spin_lock_irqsave(&emu->reg_lock, flags);
1183 reg = inl(emu->port + A_IOCFG);
1184 val = ucontrol->value.integer.value[0] ? A_IOCFG_GPOUT0 : 0;
1185 change = (reg & A_IOCFG_GPOUT0) != val;
1187 reg &= ~A_IOCFG_GPOUT0;
1189 outl(reg | val, emu->port + A_IOCFG);
1192 reg = inl(emu->port + HCFG);
1193 val = ucontrol->value.integer.value[0] ? HCFG_GPOUT0 : 0;
1194 change |= (reg & HCFG_GPOUT0) != val;
1196 reg &= ~HCFG_GPOUT0;
1198 outl(reg | val, emu->port + HCFG);
1200 spin_unlock_irqrestore(&emu->reg_lock, flags);
1204 static struct snd_kcontrol_new snd_emu10k1_shared_spdif __devinitdata =
1206 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1207 .name = "SB Live Analog/Digital Output Jack",
1208 .info = snd_emu10k1_shared_spdif_info,
1209 .get = snd_emu10k1_shared_spdif_get,
1210 .put = snd_emu10k1_shared_spdif_put
1213 static struct snd_kcontrol_new snd_audigy_shared_spdif __devinitdata =
1215 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1216 .name = "Audigy Analog/Digital Output Jack",
1217 .info = snd_emu10k1_shared_spdif_info,
1218 .get = snd_emu10k1_shared_spdif_get,
1219 .put = snd_emu10k1_shared_spdif_put
1224 static void snd_emu10k1_mixer_free_ac97(struct snd_ac97 *ac97)
1226 struct snd_emu10k1 *emu = ac97->private_data;
1232 static int remove_ctl(struct snd_card *card, const char *name)
1234 struct snd_ctl_elem_id id;
1235 memset(&id, 0, sizeof(id));
1236 strcpy(id.name, name);
1237 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1238 return snd_ctl_remove_id(card, &id);
1241 static struct snd_kcontrol *ctl_find(struct snd_card *card, const char *name)
1243 struct snd_ctl_elem_id sid;
1244 memset(&sid, 0, sizeof(sid));
1245 strcpy(sid.name, name);
1246 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1247 return snd_ctl_find_id(card, &sid);
1250 static int rename_ctl(struct snd_card *card, const char *src, const char *dst)
1252 struct snd_kcontrol *kctl = ctl_find(card, src);
1254 strcpy(kctl->id.name, dst);
1260 int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1261 int pcm_device, int multi_device)
1264 struct snd_kcontrol *kctl;
1265 struct snd_card *card = emu->card;
1267 static char *emu10k1_remove_ctls[] = {
1268 /* no AC97 mono, surround, center/lfe */
1269 "Master Mono Playback Switch",
1270 "Master Mono Playback Volume",
1271 "PCM Out Path & Mute",
1272 "Mono Output Select",
1273 "Front Playback Switch",
1274 "Front Playback Volume",
1275 "Surround Playback Switch",
1276 "Surround Playback Volume",
1277 "Center Playback Switch",
1278 "Center Playback Volume",
1279 "LFE Playback Switch",
1280 "LFE Playback Volume",
1283 static char *emu10k1_rename_ctls[] = {
1284 "Surround Digital Playback Volume", "Surround Playback Volume",
1285 "Center Digital Playback Volume", "Center Playback Volume",
1286 "LFE Digital Playback Volume", "LFE Playback Volume",
1289 static char *audigy_remove_ctls[] = {
1290 /* Master/PCM controls on ac97 of Audigy has no effect */
1291 /* On the Audigy2 the AC97 playback is piped into
1292 * the Philips ADC for 24bit capture */
1293 "PCM Playback Switch",
1294 "PCM Playback Volume",
1295 "Master Mono Playback Switch",
1296 "Master Mono Playback Volume",
1297 "Master Playback Switch",
1298 "Master Playback Volume",
1299 "PCM Out Path & Mute",
1300 "Mono Output Select",
1301 /* remove unused AC97 capture controls */
1306 "Video Playback Switch",
1307 "Video Playback Volume",
1308 "Mic Playback Switch",
1309 "Mic Playback Volume",
1312 static char *audigy_rename_ctls[] = {
1313 /* use conventional names */
1314 "Wave Playback Volume", "PCM Playback Volume",
1315 /* "Wave Capture Volume", "PCM Capture Volume", */
1316 "Wave Master Playback Volume", "Master Playback Volume",
1317 "AMic Playback Volume", "Mic Playback Volume",
1320 static char *audigy_remove_ctls_1361t_adc[] = {
1321 /* On the Audigy2 the AC97 playback is piped into
1322 * the Philips ADC for 24bit capture */
1323 "PCM Playback Switch",
1324 "PCM Playback Volume",
1325 "Master Mono Playback Switch",
1326 "Master Mono Playback Volume",
1330 "Mic Capture Volume",
1331 "Headphone Playback Switch",
1332 "Headphone Playback Volume",
1333 "3D Control - Center",
1334 "3D Control - Depth",
1335 "3D Control - Switch",
1336 "Line2 Playback Volume",
1337 "Line2 Capture Volume",
1340 static char *audigy_rename_ctls_1361t_adc[] = {
1341 "Master Playback Switch", "Master Capture Switch",
1342 "Master Playback Volume", "Master Capture Volume",
1343 "Wave Master Playback Volume", "Master Playback Volume",
1344 "PC Speaker Playback Switch", "PC Speaker Capture Switch",
1345 "PC Speaker Playback Volume", "PC Speaker Capture Volume",
1346 "Phone Playback Switch", "Phone Capture Switch",
1347 "Phone Playback Volume", "Phone Capture Volume",
1348 "Mic Playback Switch", "Mic Capture Switch",
1349 "Mic Playback Volume", "Mic Capture Volume",
1350 "Line Playback Switch", "Line Capture Switch",
1351 "Line Playback Volume", "Line Capture Volume",
1352 "CD Playback Switch", "CD Capture Switch",
1353 "CD Playback Volume", "CD Capture Volume",
1354 "Aux Playback Switch", "Aux Capture Switch",
1355 "Aux Playback Volume", "Aux Capture Volume",
1356 "Video Playback Switch", "Video Capture Switch",
1357 "Video Playback Volume", "Video Capture Volume",
1362 if (emu->card_capabilities->ac97_chip) {
1363 struct snd_ac97_bus *pbus;
1364 struct snd_ac97_template ac97;
1365 static struct snd_ac97_bus_ops ops = {
1366 .write = snd_emu10k1_ac97_write,
1367 .read = snd_emu10k1_ac97_read,
1370 if ((err = snd_ac97_bus(emu->card, 0, &ops, NULL, &pbus)) < 0)
1372 pbus->no_vra = 1; /* we don't need VRA */
1374 memset(&ac97, 0, sizeof(ac97));
1375 ac97.private_data = emu;
1376 ac97.private_free = snd_emu10k1_mixer_free_ac97;
1377 ac97.scaps = AC97_SCAP_NO_SPDIF;
1378 if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0) {
1379 if (emu->card_capabilities->ac97_chip == 1)
1381 snd_printd(KERN_INFO "emu10k1: AC97 is optional on this board\n");
1382 snd_printd(KERN_INFO" Proceeding without ac97 mixers...\n");
1383 snd_device_free(emu->card, pbus);
1384 goto no_ac97; /* FIXME: get rid of ugly gotos.. */
1387 /* set master volume to 0 dB */
1388 snd_ac97_write_cache(emu->ac97, AC97_MASTER, 0x0000);
1389 /* set capture source to mic */
1390 snd_ac97_write_cache(emu->ac97, AC97_REC_SEL, 0x0000);
1391 if (emu->card_capabilities->adc_1361t)
1392 c = audigy_remove_ctls_1361t_adc;
1394 c = audigy_remove_ctls;
1397 * Credits for cards based on STAC9758:
1398 * James Courtier-Dutton <James@superbug.demon.co.uk>
1399 * Voluspa <voluspa@comhem.se>
1401 if (emu->ac97->id == AC97_ID_STAC9758) {
1403 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE|AC97SLOT_REAR_LEFT|AC97SLOT_REAR_RIGHT);
1405 /* remove unused AC97 controls */
1406 snd_ac97_write_cache(emu->ac97, AC97_SURROUND_MASTER, 0x0202);
1407 snd_ac97_write_cache(emu->ac97, AC97_CENTER_LFE_MASTER, 0x0202);
1408 c = emu10k1_remove_ctls;
1411 remove_ctl(card, *c);
1414 if (emu->card_capabilities->ecard)
1415 strcpy(emu->card->mixername, "EMU APS");
1416 else if (emu->audigy)
1417 strcpy(emu->card->mixername, "SB Audigy");
1419 strcpy(emu->card->mixername, "Emu10k1");
1423 if (emu->card_capabilities->adc_1361t)
1424 c = audigy_rename_ctls_1361t_adc;
1426 c = audigy_rename_ctls;
1428 c = emu10k1_rename_ctls;
1430 rename_ctl(card, c[0], c[1]);
1432 if (emu->card_capabilities->subsystem == 0x20071102) { /* Audigy 4 Pro */
1433 rename_ctl(card, "Line2 Capture Volume", "Line1/Mic Capture Volume");
1434 rename_ctl(card, "Analog Mix Capture Volume", "Line2 Capture Volume");
1435 rename_ctl(card, "Aux2 Capture Volume", "Line3 Capture Volume");
1436 rename_ctl(card, "Mic Capture Volume", "Unknown1 Capture Volume");
1437 remove_ctl(card, "Headphone Playback Switch");
1438 remove_ctl(card, "Headphone Playback Volume");
1439 remove_ctl(card, "3D Control - Center");
1440 remove_ctl(card, "3D Control - Depth");
1441 remove_ctl(card, "3D Control - Switch");
1443 if ((kctl = emu->ctl_send_routing = snd_ctl_new1(&snd_emu10k1_send_routing_control, emu)) == NULL)
1445 kctl->id.device = pcm_device;
1446 if ((err = snd_ctl_add(card, kctl)))
1448 if ((kctl = emu->ctl_send_volume = snd_ctl_new1(&snd_emu10k1_send_volume_control, emu)) == NULL)
1450 kctl->id.device = pcm_device;
1451 if ((err = snd_ctl_add(card, kctl)))
1453 if ((kctl = emu->ctl_attn = snd_ctl_new1(&snd_emu10k1_attn_control, emu)) == NULL)
1455 kctl->id.device = pcm_device;
1456 if ((err = snd_ctl_add(card, kctl)))
1459 if ((kctl = emu->ctl_efx_send_routing = snd_ctl_new1(&snd_emu10k1_efx_send_routing_control, emu)) == NULL)
1461 kctl->id.device = multi_device;
1462 if ((err = snd_ctl_add(card, kctl)))
1465 if ((kctl = emu->ctl_efx_send_volume = snd_ctl_new1(&snd_emu10k1_efx_send_volume_control, emu)) == NULL)
1467 kctl->id.device = multi_device;
1468 if ((err = snd_ctl_add(card, kctl)))
1471 if ((kctl = emu->ctl_efx_attn = snd_ctl_new1(&snd_emu10k1_efx_attn_control, emu)) == NULL)
1473 kctl->id.device = multi_device;
1474 if ((err = snd_ctl_add(card, kctl)))
1477 /* initialize the routing and volume table for each pcm playback stream */
1478 for (pcm = 0; pcm < 32; pcm++) {
1479 struct snd_emu10k1_pcm_mixer *mix;
1482 mix = &emu->pcm_mixer[pcm];
1485 for (v = 0; v < 4; v++)
1486 mix->send_routing[0][v] =
1487 mix->send_routing[1][v] =
1488 mix->send_routing[2][v] = v;
1490 memset(&mix->send_volume, 0, sizeof(mix->send_volume));
1491 mix->send_volume[0][0] = mix->send_volume[0][1] =
1492 mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
1494 mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
1497 /* initialize the routing and volume table for the multichannel playback stream */
1498 for (pcm = 0; pcm < NUM_EFX_PLAYBACK; pcm++) {
1499 struct snd_emu10k1_pcm_mixer *mix;
1502 mix = &emu->efx_pcm_mixer[pcm];
1505 mix->send_routing[0][0] = pcm;
1506 mix->send_routing[0][1] = (pcm == 0) ? 1 : 0;
1507 for (v = 0; v < 2; v++)
1508 mix->send_routing[0][2+v] = 13+v;
1510 for (v = 0; v < 4; v++)
1511 mix->send_routing[0][4+v] = 60+v;
1513 memset(&mix->send_volume, 0, sizeof(mix->send_volume));
1514 mix->send_volume[0][0] = 255;
1516 mix->attn[0] = 0xffff;
1519 if (! emu->card_capabilities->ecard) { /* FIXME: APS has these controls? */
1520 /* sb live! and audigy */
1521 if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_mask_control, emu)) == NULL)
1524 kctl->id.device = emu->pcm_efx->device;
1525 if ((err = snd_ctl_add(card, kctl)))
1527 if ((kctl = snd_ctl_new1(&snd_emu10k1_spdif_control, emu)) == NULL)
1530 kctl->id.device = emu->pcm_efx->device;
1531 if ((err = snd_ctl_add(card, kctl)))
1535 if ( emu->card_capabilities->emu1010) {
1536 ; /* Disable the snd_audigy_spdif_shared_spdif */
1537 } else if (emu->audigy) {
1538 if ((kctl = snd_ctl_new1(&snd_audigy_shared_spdif, emu)) == NULL)
1540 if ((err = snd_ctl_add(card, kctl)))
1543 if ((kctl = snd_ctl_new1(&snd_audigy_spdif_output_rate, emu)) == NULL)
1545 if ((err = snd_ctl_add(card, kctl)))
1548 } else if (! emu->card_capabilities->ecard) {
1550 if ((kctl = snd_ctl_new1(&snd_emu10k1_shared_spdif, emu)) == NULL)
1552 if ((err = snd_ctl_add(card, kctl)))
1555 if (emu->card_capabilities->ca0151_chip) { /* P16V */
1556 if ((err = snd_p16v_mixer(emu)))
1560 if ( emu->card_capabilities->emu1010) {
1563 for (i = 0; i < ARRAY_SIZE(snd_emu1010_output_enum_ctls); i++) {
1564 err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_output_enum_ctls[i], emu));
1568 for (i = 0; i < ARRAY_SIZE(snd_emu1010_input_enum_ctls); i++) {
1569 err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_input_enum_ctls[i], emu));
1573 for (i = 0; i < ARRAY_SIZE(snd_emu1010_adc_pads); i++) {
1574 err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_adc_pads[i], emu));
1578 for (i = 0; i < ARRAY_SIZE(snd_emu1010_dac_pads); i++) {
1579 err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_dac_pads[i], emu));
1583 err = snd_ctl_add(card, snd_ctl_new1(&snd_emu1010_internal_clock, emu));