2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Universal interface for Audio Codec '97
5 * For more details look to AC '97 component specification revision 2.2
6 * by Intel Corporation (http://developer.intel.com) and to datasheets
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sound/driver.h>
27 #include <linux/delay.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <sound/core.h>
31 #include <sound/pcm.h>
32 #include <sound/control.h>
33 #include <sound/ac97_codec.h>
34 #include "ac97_patch.h"
36 #include "ac97_local.h"
41 * Chip specific initialization
44 static int patch_build_controls(ac97_t * ac97, const snd_kcontrol_new_t *controls, int count)
48 for (idx = 0; idx < count; idx++)
49 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
54 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
56 /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
57 static int snd_ac97_ymf753_info_speaker(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
59 static char *texts[3] = {
60 "Standard", "Small", "Smaller"
63 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
65 uinfo->value.enumerated.items = 3;
66 if (uinfo->value.enumerated.item > 2)
67 uinfo->value.enumerated.item = 2;
68 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
72 static int snd_ac97_ymf753_get_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
74 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
77 val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
78 val = (val >> 10) & 3;
79 if (val > 0) /* 0 = invalid */
81 ucontrol->value.enumerated.item[0] = val;
85 static int snd_ac97_ymf753_put_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
87 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
90 if (ucontrol->value.enumerated.item[0] > 2)
92 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
93 return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
96 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_speaker =
98 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
99 .name = "3D Control - Speaker",
100 .info = snd_ac97_ymf753_info_speaker,
101 .get = snd_ac97_ymf753_get_speaker,
102 .put = snd_ac97_ymf753_put_speaker,
105 /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
106 static int snd_ac97_ymf753_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
108 static char *texts[2] = { "AC-Link", "A/D Converter" };
110 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
112 uinfo->value.enumerated.items = 2;
113 if (uinfo->value.enumerated.item > 1)
114 uinfo->value.enumerated.item = 1;
115 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
119 static int snd_ac97_ymf753_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
121 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
124 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
125 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
129 static int snd_ac97_ymf753_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
131 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
134 if (ucontrol->value.enumerated.item[0] > 1)
136 val = ucontrol->value.enumerated.item[0] << 1;
137 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
140 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
141 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
142 By default, no output pin is selected, and the S/PDIF signal is not output.
143 There is also a bit to mute S/PDIF output in a vendor-specific register. */
144 static int snd_ac97_ymf753_spdif_output_pin_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
146 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
148 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
150 uinfo->value.enumerated.items = 3;
151 if (uinfo->value.enumerated.item > 2)
152 uinfo->value.enumerated.item = 2;
153 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
157 static int snd_ac97_ymf753_spdif_output_pin_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
159 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
162 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
163 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
167 static int snd_ac97_ymf753_spdif_output_pin_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
169 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
172 if (ucontrol->value.enumerated.item[0] > 2)
174 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
175 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
176 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
177 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
178 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
181 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_spdif[3] = {
183 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
184 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
185 .info = snd_ac97_ymf753_spdif_source_info,
186 .get = snd_ac97_ymf753_spdif_source_get,
187 .put = snd_ac97_ymf753_spdif_source_put,
190 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
191 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
192 .info = snd_ac97_ymf753_spdif_output_pin_info,
193 .get = snd_ac97_ymf753_spdif_output_pin_get,
194 .put = snd_ac97_ymf753_spdif_output_pin_put,
196 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
199 static int patch_yamaha_ymf753_3d(ac97_t * ac97)
201 snd_kcontrol_t *kctl;
204 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
206 strcpy(kctl->id.name, "3D Control - Wide");
207 kctl->private_value = AC97_3D_CONTROL | (9 << 8) | (7 << 16);
208 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
209 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
211 snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
215 static int patch_yamaha_ymf753_post_spdif(ac97_t * ac97)
219 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
224 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
225 .build_3d = patch_yamaha_ymf753_3d,
226 .build_post_spdif = patch_yamaha_ymf753_post_spdif
229 int patch_yamaha_ymf753(ac97_t * ac97)
231 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
232 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
233 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
234 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
235 By default, no output pin is selected, and the S/PDIF signal is not output.
236 There is also a bit to mute S/PDIF output in a vendor-specific register.
238 ac97->build_ops = &patch_yamaha_ymf753_ops;
239 ac97->caps |= AC97_BC_BASS_TREBLE;
240 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
245 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
246 * removed broken wolfson00 patch.
247 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
250 int patch_wolfson03(ac97_t * ac97)
252 /* This is known to work for the ViewSonic ViewPad 1000
253 Randolph Bentson <bentson@holmsjoen.com> */
255 // WM9703/9707/9708/9717
256 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
257 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0x8000);
261 int patch_wolfson04(ac97_t * ac97)
264 // set front and rear mixer volume
265 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
266 snd_ac97_write_cache(ac97, AC97_WM9704_RMIXER_VOL, 0x0808);
268 // patch for DVD noise
269 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
272 snd_ac97_write_cache(ac97, AC97_WM9704_RPCM_VOL, 0x0808);
274 // set rear surround volume
275 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
279 int patch_wolfson05(ac97_t * ac97)
282 // set front mixer volume
283 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
287 int patch_wolfson11(ac97_t * ac97)
291 snd_ac97_write_cache(ac97, AC97_WM9711_OUT3VOL, 0x0808);
298 int patch_tritech_tr28028(ac97_t * ac97)
300 snd_ac97_write_cache(ac97, 0x26, 0x0300);
301 snd_ac97_write_cache(ac97, 0x26, 0x0000);
302 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
303 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
308 * Sigmatel STAC97xx codecs
310 static int patch_sigmatel_stac9700_3d(ac97_t * ac97)
312 snd_kcontrol_t *kctl;
315 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
317 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
318 kctl->private_value = AC97_3D_CONTROL | (3 << 16);
319 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
323 static int patch_sigmatel_stac9708_3d(ac97_t * ac97)
325 snd_kcontrol_t *kctl;
328 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
330 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
331 kctl->private_value = AC97_3D_CONTROL | (3 << 16);
332 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
334 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
335 kctl->private_value = AC97_3D_CONTROL | (2 << 8) | (3 << 16);
336 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
340 static const snd_kcontrol_new_t snd_ac97_sigmatel_4speaker =
341 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
343 static const snd_kcontrol_new_t snd_ac97_sigmatel_phaseinvert =
344 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
346 static const snd_kcontrol_new_t snd_ac97_sigmatel_controls[] = {
347 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
348 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
351 static int patch_sigmatel_stac97xx_specific(ac97_t * ac97)
355 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
356 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
357 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
359 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
360 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
362 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
363 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
365 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
366 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
371 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
372 .build_3d = patch_sigmatel_stac9700_3d,
373 .build_specific = patch_sigmatel_stac97xx_specific
376 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
377 .build_3d = patch_sigmatel_stac9708_3d,
378 .build_specific = patch_sigmatel_stac97xx_specific
381 int patch_sigmatel_stac9700(ac97_t * ac97)
383 ac97->build_ops = &patch_sigmatel_stac9700_ops;
387 int patch_sigmatel_stac9708(ac97_t * ac97)
389 unsigned int codec72, codec6c;
391 ac97->build_ops = &patch_sigmatel_stac9708_ops;
393 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
394 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
396 if ((codec72==0) && (codec6c==0)) {
397 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
398 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
399 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
400 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
401 } else if ((codec72==0x8000) && (codec6c==0)) {
402 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
403 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
404 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
405 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
408 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
412 int patch_sigmatel_stac9721(ac97_t * ac97)
414 ac97->build_ops = &patch_sigmatel_stac9700_ops;
415 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
416 // patch for SigmaTel
417 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
418 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
419 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
420 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
422 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
426 int patch_sigmatel_stac9744(ac97_t * ac97)
428 // patch for SigmaTel
429 ac97->build_ops = &patch_sigmatel_stac9700_ops;
430 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
431 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
432 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
433 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
434 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
438 int patch_sigmatel_stac9756(ac97_t * ac97)
440 // patch for SigmaTel
441 ac97->build_ops = &patch_sigmatel_stac9700_ops;
442 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
443 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
444 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
445 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
446 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
450 int patch_sigmatel_stac9758(ac97_t * ac97)
452 // patch for SigmaTel
453 ac97->build_ops = &patch_sigmatel_stac9700_ops;
454 // turn on stereo speaker, headphone and line-out
455 snd_ac97_write_cache(ac97, AC97_SIGMATEL_OUTSEL, 0x9040);
456 // headphone select and boost
457 snd_ac97_write_cache(ac97, AC97_SIGMATEL_IOMISC, 0x2102);
459 snd_ac97_write_cache(ac97, AC97_SIGMATEL_INSEL, 0x0203);
461 snd_ac97_write_cache(ac97, AC97_SIGMATEL_VARIOUS, 0x0001);
466 * Cirrus Logic CS42xx codecs
468 static const snd_kcontrol_new_t snd_ac97_cirrus_controls_spdif[2] = {
469 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
470 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
473 static int patch_cirrus_build_spdif(ac97_t * ac97)
477 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
479 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
481 switch (ac97->id & AC97_ID_CS_MASK) {
483 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
487 /* set default PCM S/PDIF params */
488 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
489 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
493 static struct snd_ac97_build_ops patch_cirrus_ops = {
494 .build_spdif = patch_cirrus_build_spdif
497 int patch_cirrus_spdif(ac97_t * ac97)
499 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
500 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
501 - sp/dif EA ID is not set, but sp/dif is always present.
502 - enable/disable is spdif register bit 15.
503 - sp/dif control register is 0x68. differs from AC97:
504 - valid is bit 14 (vs 15)
506 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
507 - sp/dif ssource select is in 0x5e bits 0,1.
510 ac97->build_ops = &patch_cirrus_ops;
511 ac97->flags |= AC97_CS_SPDIF;
512 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
513 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
514 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
518 int patch_cirrus_cs4299(ac97_t * ac97)
520 /* force the detection of PC Beep */
521 ac97->flags |= AC97_HAS_PC_BEEP;
523 return patch_cirrus_spdif(ac97);
529 static const snd_kcontrol_new_t snd_ac97_conexant_controls_spdif[1] = {
530 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
533 static int patch_conexant_build_spdif(ac97_t * ac97)
537 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
539 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
541 /* set default PCM S/PDIF params */
542 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
543 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
544 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
548 static struct snd_ac97_build_ops patch_conexant_ops = {
549 .build_spdif = patch_conexant_build_spdif
552 int patch_conexant(ac97_t * ac97)
554 ac97->build_ops = &patch_conexant_ops;
555 ac97->flags |= AC97_CX_SPDIF;
556 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
561 * Analog Device AD18xx, AD19xx codecs
563 int patch_ad1819(ac97_t * ac97)
567 // patch for Analog Devices
568 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
569 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
573 static unsigned short patch_ad1881_unchained(ac97_t * ac97, int idx, unsigned short mask)
577 // test for unchained codec
578 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
579 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
580 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
581 if ((val & 0xff40) != 0x5340)
583 ac97->spec.ad18xx.unchained[idx] = mask;
584 ac97->spec.ad18xx.id[idx] = val;
585 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
589 static int patch_ad1881_chained1(ac97_t * ac97, int idx, unsigned short codec_bits)
591 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
594 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
595 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
596 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
597 if ((val & 0xff40) != 0x5340)
600 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
601 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
602 ac97->spec.ad18xx.id[idx] = val;
603 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
607 static void patch_ad1881_chained(ac97_t * ac97, int unchained_idx, int cidx1, int cidx2)
610 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
612 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
614 if (cidx1 < 0 && cidx2 < 0)
616 // test for chained codecs
617 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
618 ac97->spec.ad18xx.unchained[unchained_idx]);
619 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
620 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
622 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
623 patch_ad1881_chained1(ac97, cidx2, 0);
624 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
625 patch_ad1881_chained1(ac97, cidx1, 0);
626 } else if (cidx2 >= 0) {
627 patch_ad1881_chained1(ac97, cidx2, 0);
631 int patch_ad1881(ac97_t * ac97)
633 static const char cfg_idxs[3][2] = {
639 // patch for Analog Devices
640 unsigned short codecs[3];
644 init_MUTEX(&ac97->spec.ad18xx.mutex);
646 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
647 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
648 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
649 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
650 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
652 snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end);
654 for (idx = 0; idx < 3; idx++)
655 if (ac97->spec.ad18xx.unchained[idx])
656 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
658 if (ac97->spec.ad18xx.id[1]) {
659 ac97->flags |= AC97_AD_MULTI;
660 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
662 if (ac97->spec.ad18xx.id[2]) {
663 ac97->flags |= AC97_AD_MULTI;
664 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
668 /* select all codecs */
669 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
670 /* check if only one codec is present */
671 for (idx = num = 0; idx < 3; idx++)
672 if (ac97->spec.ad18xx.id[idx])
675 /* ok, deselect all ID bits */
676 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
677 ac97->spec.ad18xx.codec_cfg[0] =
678 ac97->spec.ad18xx.codec_cfg[1] =
679 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
681 /* required for AD1886/AD1885 combination */
682 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
683 if (ac97->spec.ad18xx.id[0]) {
684 ac97->id &= 0xffff0000;
685 ac97->id |= ac97->spec.ad18xx.id[0];
690 static const snd_kcontrol_new_t snd_ac97_controls_ad1885[] = {
691 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
692 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
693 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
694 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
697 static int patch_ad1885_specific(ac97_t * ac97)
701 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
706 static struct snd_ac97_build_ops patch_ad1885_build_ops = {
707 .build_specific = &patch_ad1885_specific
710 int patch_ad1885(ac97_t * ac97)
715 /* This is required to deal with the Intel D815EEAL2 */
716 /* i.e. Line out is actually headphone out from codec */
718 /* turn off jack sense bits D8 & D9 */
719 jack = snd_ac97_read(ac97, AC97_AD_JACK_SPDIF);
720 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, jack | 0x0300);
723 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
725 ac97->build_ops = &patch_ad1885_build_ops;
729 int patch_ad1886(ac97_t * ac97)
732 /* Presario700 workaround */
733 /* for Jack Sense/SPDIF Register misetting causing */
734 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
739 #define AC97_AD198X_MBC 0x0003 /* mic boost */
740 #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
741 #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
742 #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
743 #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
744 #define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
745 #define AC97_AD198X_VREF_0 0x000c /* 0V */
746 #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
747 #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
748 #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
749 #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
750 #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
751 #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
752 #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
753 #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
754 #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
755 #define AC97_AD198X_MSPLT 0x2000 /* mute split */
756 #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
757 #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
760 static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
762 static char *texts[2] = { "AC-Link", "A/D Converter" };
764 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
766 uinfo->value.enumerated.items = 2;
767 if (uinfo->value.enumerated.item > 1)
768 uinfo->value.enumerated.item = 1;
769 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
773 static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
775 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
778 val = ac97->regs[AC97_AD_SERIAL_CFG];
779 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
783 static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
785 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
788 if (ucontrol->value.enumerated.item[0] > 1)
790 val = ucontrol->value.enumerated.item[0] << 2;
791 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
794 static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source = {
795 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
796 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
797 .info = snd_ac97_ad198x_spdif_source_info,
798 .get = snd_ac97_ad198x_spdif_source_get,
799 .put = snd_ac97_ad198x_spdif_source_put,
802 static int patch_ad198x_post_spdif(ac97_t * ac97)
804 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
807 static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
808 .build_post_spdif = patch_ad198x_post_spdif
811 int patch_ad1981a(ac97_t *ac97)
814 ac97->build_ops = &patch_ad1981a_build_ops;
815 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
816 ac97->flags |= AC97_STEREO_MUTES;
820 static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic =
821 AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
823 static int patch_ad1981b_specific(ac97_t *ac97)
825 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
828 static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
829 .build_post_spdif = patch_ad198x_post_spdif,
830 .build_specific = patch_ad1981b_specific
833 int patch_ad1981b(ac97_t *ac97)
836 ac97->build_ops = &patch_ad1981b_build_ops;
837 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
838 ac97->flags |= AC97_STEREO_MUTES;
842 static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
844 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
846 uinfo->value.integer.min = 0;
847 uinfo->value.integer.max = 1;
851 static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
853 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
856 val = ac97->regs[AC97_AD_MISC];
857 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
861 static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
863 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
866 val = !ucontrol->value.integer.value[0]
867 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
868 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
869 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
872 static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
874 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
876 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
878 uinfo->value.enumerated.items = 3;
879 if (uinfo->value.enumerated.item > 2)
880 uinfo->value.enumerated.item = 2;
881 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
885 static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
887 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
890 val = ac97->regs[AC97_AD_MISC];
891 if (!(val & AC97_AD198X_DMIX1))
892 ucontrol->value.enumerated.item[0] = 0;
894 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
898 static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
900 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
903 if (ucontrol->value.enumerated.item[0] > 2)
905 if (ucontrol->value.enumerated.item[0] == 0)
908 val = AC97_AD198X_DMIX1 |
909 ((ucontrol->value.enumerated.item[0] - 1) << 8);
910 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
911 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
914 static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = {
916 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
917 .name = "Exchange Front/Surround",
918 .info = snd_ac97_ad1888_lohpsel_info,
919 .get = snd_ac97_ad1888_lohpsel_get,
920 .put = snd_ac97_ad1888_lohpsel_put
922 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
924 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
926 .info = snd_ac97_ad1888_downmix_info,
927 .get = snd_ac97_ad1888_downmix_get,
928 .put = snd_ac97_ad1888_downmix_put
930 AC97_SINGLE("Surround Jack as Input", AC97_AD_MISC, 12, 1, 0),
931 AC97_SINGLE("Center/LFE Jack as Input", AC97_AD_MISC, 11, 1, 0),
934 static int patch_ad1888_specific(ac97_t *ac97)
936 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
937 snd_ac97_rename_ctl(ac97, "Master Playback Switch", "Master Surround Playback Switch");
938 snd_ac97_rename_ctl(ac97, "Master Playback Volume", "Master Surround Playback Volume");
939 snd_ac97_rename_ctl(ac97, "Headphone Playback Switch", "Master Playback Switch");
940 snd_ac97_rename_ctl(ac97, "Headphone Playback Volume", "Master Playback Volume");
941 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
944 static struct snd_ac97_build_ops patch_ad1888_build_ops = {
945 .build_post_spdif = patch_ad198x_post_spdif,
946 .build_specific = patch_ad1888_specific
949 int patch_ad1888(ac97_t * ac97)
954 ac97->build_ops = &patch_ad1888_build_ops;
955 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
956 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
957 /* AD-compatible mode */
958 /* Stereo mutes enabled */
959 misc = snd_ac97_read(ac97, AC97_AD_MISC);
960 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
965 ac97->flags |= AC97_STEREO_MUTES;
969 static int patch_ad1980_specific(ac97_t *ac97)
973 if ((err = patch_ad1888_specific(ac97)) < 0)
975 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
978 static struct snd_ac97_build_ops patch_ad1980_build_ops = {
979 .build_post_spdif = patch_ad198x_post_spdif,
980 .build_specific = patch_ad1980_specific
983 int patch_ad1980(ac97_t * ac97)
986 ac97->build_ops = &patch_ad1980_build_ops;
990 static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = {
991 AC97_SINGLE("Center/LFE Jack as Mic", AC97_AD_SERIAL_CFG, 9, 1, 0),
992 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
995 static int patch_ad1985_specific(ac97_t *ac97)
999 if ((err = patch_ad1980_specific(ac97)) < 0)
1001 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1004 static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1005 .build_post_spdif = patch_ad198x_post_spdif,
1006 .build_specific = patch_ad1985_specific
1009 int patch_ad1985(ac97_t * ac97)
1011 unsigned short misc;
1014 ac97->build_ops = &patch_ad1985_build_ops;
1015 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1016 /* switch front/surround line-out/hp-out */
1017 /* center/LFE, mic in 3.75V mode */
1018 /* AD-compatible mode */
1019 /* Stereo mutes enabled */
1020 /* in accordance with ADI driver: misc | 0x5c28 */
1021 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1028 AC97_AD198X_AC97NC);
1029 ac97->flags |= AC97_STEREO_MUTES;
1034 * realtek ALC65x codecs
1036 static int snd_ac97_alc650_mic_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1038 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1039 ucontrol->value.integer.value[0] = (ac97->regs[AC97_ALC650_MULTICH] >> 10) & 1;
1043 static int snd_ac97_alc650_mic_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1045 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1047 val = !!(snd_ac97_read(ac97, AC97_ALC650_MULTICH) & (1 << 10));
1048 change = (ucontrol->value.integer.value[0] != val);
1050 /* disable/enable vref */
1051 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1052 ucontrol->value.integer.value[0] ? (1 << 12) : 0);
1053 /* turn on/off center-on-mic */
1054 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1055 ucontrol->value.integer.value[0] ? (1 << 10) : 0);
1056 /* GPIO0 high for mic */
1057 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1058 ucontrol->value.integer.value[0] ? 0 : 0x100);
1063 static const snd_kcontrol_new_t snd_ac97_controls_alc650[] = {
1064 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1065 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
1066 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
1067 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
1068 /* 4: Analog Input To Surround */
1069 /* 5: Analog Input To Center/LFE */
1070 /* 6: Independent Master Volume Right */
1071 /* 7: Independent Master Volume Left */
1073 AC97_SINGLE("Line-In As Surround", AC97_ALC650_MULTICH, 9, 1, 0),
1074 /* 10: mic, see below */
1075 /* 11-13: in IEC958 controls */
1076 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
1077 #if 0 /* always set in patch_alc650 */
1078 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
1079 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
1080 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
1081 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
1082 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
1083 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
1086 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1087 .name = "Mic As Center/LFE",
1088 .info = snd_ac97_info_single,
1089 .get = snd_ac97_alc650_mic_get,
1090 .put = snd_ac97_alc650_mic_put,
1094 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc650[] = {
1095 AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0),
1096 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
1097 AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0),
1100 static int patch_alc650_specific(ac97_t * ac97)
1104 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
1106 if (ac97->ext_id & AC97_EI_SPDIF) {
1107 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
1113 static struct snd_ac97_build_ops patch_alc650_ops = {
1114 .build_specific = patch_alc650_specific
1117 int patch_alc650(ac97_t * ac97)
1121 ac97->build_ops = &patch_alc650_ops;
1123 /* revision E or F */
1124 /* FIXME: what about revision D ? */
1125 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
1126 ac97->id == 0x414c4723);
1128 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
1129 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
1130 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
1132 /* Enable SPDIF-IN only on Rev.E and above */
1133 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
1134 /* SPDIF IN with pin 47 */
1135 if (ac97->spec.dev_flags)
1136 val |= 0x03; /* enable */
1138 val &= ~0x03; /* disable */
1139 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
1141 /* set default: slot 3,4,7,8,6,9
1142 spdif-in monitor off, analog-spdif off, spdif-in off
1143 center on mic off, surround on line-in off
1144 downmix off, duplicate front off
1146 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
1148 /* set GPIO0 for mic bias */
1149 /* GPIO0 pin output, no interrupt, high */
1150 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
1151 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
1152 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
1153 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
1155 /* full DAC volume */
1156 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1157 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1161 static int snd_ac97_alc655_mic_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1163 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1164 ucontrol->value.integer.value[0] = (ac97->regs[AC97_ALC650_MULTICH] >> 10) & 1;
1168 static int snd_ac97_alc655_mic_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1170 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1173 /* misc control; vrefout disable */
1174 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1175 ucontrol->value.integer.value[0] ? (1 << 12) : 0);
1176 change = snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1177 ucontrol->value.integer.value[0] ? (1 << 10) : 0);
1182 static const snd_kcontrol_new_t snd_ac97_controls_alc655[] = {
1183 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1184 AC97_SINGLE("Line-In As Surround", AC97_ALC650_MULTICH, 9, 1, 0),
1186 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1187 .name = "Mic As Center/LFE",
1188 .info = snd_ac97_info_single,
1189 .get = snd_ac97_alc655_mic_get,
1190 .put = snd_ac97_alc655_mic_put,
1194 static int alc655_iec958_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1196 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
1197 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
1198 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1200 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1202 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
1203 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1204 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1205 strcpy(uinfo->value.enumerated.name,
1206 ac97->spec.dev_flags ?
1207 texts_658[uinfo->value.enumerated.item] :
1208 texts_655[uinfo->value.enumerated.item]);
1213 static int alc655_iec958_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1215 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1218 val = ac97->regs[AC97_ALC650_MULTICH];
1219 val = (val >> 12) & 3;
1220 if (ac97->spec.dev_flags && val == 3)
1222 ucontrol->value.enumerated.item[0] = val;
1226 static int alc655_iec958_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1228 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1229 return snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 3 << 12,
1230 (unsigned short)ucontrol->value.enumerated.item[0]);
1233 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655[] = {
1234 AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0),
1235 AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0),
1237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1238 .name = "IEC958 Playback Route",
1239 .info = alc655_iec958_route_info,
1240 .get = alc655_iec958_route_get,
1241 .put = alc655_iec958_route_put,
1245 static int patch_alc655_specific(ac97_t * ac97)
1249 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
1251 if (ac97->ext_id & AC97_EI_SPDIF) {
1252 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
1258 static struct snd_ac97_build_ops patch_alc655_ops = {
1259 .build_specific = patch_alc655_specific
1262 int patch_alc655(ac97_t * ac97)
1266 ac97->spec.dev_flags = (ac97->id == 0x414c4780); /* ALC658 */
1268 ac97->build_ops = &patch_alc655_ops;
1270 /* adjust default values */
1271 val = snd_ac97_read(ac97, 0x7a); /* misc control */
1272 val |= (1 << 1); /* spdif input pin */
1273 val &= ~(1 << 12); /* vref enable */
1274 snd_ac97_write_cache(ac97, 0x7a, val);
1275 /* set default: spdif-in enabled,
1276 spdif-in monitor off, spdif-in PCM off
1277 center on mic off, surround on line-in off
1280 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
1282 /* full DAC volume */
1283 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1284 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1289 * C-Media CM97xx codecs
1291 static const snd_kcontrol_new_t snd_ac97_cm9738_controls[] = {
1292 AC97_SINGLE("Line-In As Surround", AC97_CM9738_VENDOR_CTRL, 10, 1, 0),
1293 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
1296 static int patch_cm9738_specific(ac97_t * ac97)
1298 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
1301 static struct snd_ac97_build_ops patch_cm9738_ops = {
1302 .build_specific = patch_cm9738_specific
1305 int patch_cm9738(ac97_t * ac97)
1307 ac97->build_ops = &patch_cm9738_ops;
1311 static int snd_ac97_cmedia_spdif_playback_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1313 static char *texts[] = { "Analog", "Digital" };
1315 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1317 uinfo->value.enumerated.items = 2;
1318 if (uinfo->value.enumerated.item > 1)
1319 uinfo->value.enumerated.item = 1;
1320 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1324 static int snd_ac97_cmedia_spdif_playback_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1326 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1329 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
1330 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
1334 static int snd_ac97_cmedia_spdif_playback_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1336 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1338 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
1340 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
1343 static const snd_kcontrol_new_t snd_ac97_cm9739_controls_spdif[] = {
1344 /* BIT 0: SPDI_EN - always true */
1345 { /* BIT 1: SPDIFS */
1346 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1347 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1348 .info = snd_ac97_cmedia_spdif_playback_source_info,
1349 .get = snd_ac97_cmedia_spdif_playback_source_get,
1350 .put = snd_ac97_cmedia_spdif_playback_source_put,
1352 /* BIT 2: IG_SPIV */
1353 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
1355 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
1356 /* BIT 4: SPI2SDI */
1357 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
1358 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
1361 static const snd_kcontrol_new_t snd_ac97_cm9739_controls[] = {
1362 AC97_SINGLE("Line-In As Surround", AC97_CM9739_MULTI_CHAN, 10, 1, 0),
1365 static int patch_cm9739_specific(ac97_t * ac97)
1367 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
1370 static int patch_cm9739_post_spdif(ac97_t * ac97)
1372 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
1375 static struct snd_ac97_build_ops patch_cm9739_ops = {
1376 .build_specific = patch_cm9739_specific,
1377 .build_post_spdif = patch_cm9739_post_spdif
1380 int patch_cm9739(ac97_t * ac97)
1384 ac97->build_ops = &patch_cm9739_ops;
1387 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
1388 if (val & AC97_EA_SPCV) {
1389 /* enable spdif in */
1390 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
1391 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
1393 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
1396 /* set-up multi channel */
1397 /* bit 13: enable internal vref output for mic */
1398 /* bit 12: enable center/lfe */
1399 /* bit 14: 0 = SPDIF, 1 = EAPD */
1400 val = (1 << 12) | (1 << 13);
1401 if (! (ac97->ext_id & AC97_EI_SPDIF))
1403 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
1405 /* FIXME: set up GPIO */
1406 snd_ac97_write_cache(ac97, 0x70, 0x0100);
1407 snd_ac97_write_cache(ac97, 0x72, 0x0020);
1415 static const snd_kcontrol_new_t snd_ac97_controls_vt1616[] = {
1416 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
1417 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
1418 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
1419 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
1422 static int patch_vt1616_specific(ac97_t * ac97)
1426 if (snd_ac97_try_bit(ac97, 0x5a, 9))
1427 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
1429 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
1434 static struct snd_ac97_build_ops patch_vt1616_ops = {
1435 .build_specific = patch_vt1616_specific
1438 int patch_vt1616(ac97_t * ac97)
1440 ac97->build_ops = &patch_vt1616_ops;
1444 static const snd_kcontrol_new_t snd_ac97_controls_it2646[] = {
1445 AC97_SINGLE("Line-In As Surround", 0x76, 9, 1, 0),
1446 AC97_SINGLE("Mic As Center/LFE", 0x76, 10, 1, 0),
1449 static const snd_kcontrol_new_t snd_ac97_spdif_controls_it2646[] = {
1450 AC97_SINGLE("IEC958 Capture Switch", 0x76, 11, 1, 0),
1451 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
1452 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
1455 static int patch_it2646_specific(ac97_t * ac97)
1458 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
1460 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
1465 static struct snd_ac97_build_ops patch_it2646_ops = {
1466 .build_specific = patch_it2646_specific
1469 int patch_it2646(ac97_t * ac97)
1471 ac97->build_ops = &patch_it2646_ops;
1472 /* full DAC volume */
1473 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
1474 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
1478 /* Si3036/8 specific registers */
1479 #define AC97_SI3036_CHIP_ID 0x5a
1481 int mpatch_si3036(ac97_t * ac97)
1483 //printk("mpatch_si3036: chip id = %x\n", snd_ac97_read(ac97, 0x5a));
1484 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
1485 snd_ac97_write_cache(ac97, 0x68, 0);