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 static int snd_ac97_stac9758_output_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
452 static char *texts[5] = { "Input/Disabled", "Front Output",
453 "Rear Output", "Center/LFE Output", "Mixer Output" };
455 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
457 uinfo->value.enumerated.items = 5;
458 if (uinfo->value.enumerated.item > 4)
459 uinfo->value.enumerated.item = 4;
460 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
464 static int snd_ac97_stac9758_output_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
466 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
467 int shift = kcontrol->private_value;
470 val = ac97->regs[AC97_SIGMATEL_OUTSEL];
471 if (!((val >> shift) & 4))
472 ucontrol->value.enumerated.item[0] = 0;
474 ucontrol->value.enumerated.item[0] = 1 + ((val >> shift) & 3);
478 static int snd_ac97_stac9758_output_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
480 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
481 int shift = kcontrol->private_value;
484 if (ucontrol->value.enumerated.item[0] > 4)
486 if (ucontrol->value.enumerated.item[0] == 0)
489 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
490 return snd_ac97_update_bits(ac97, AC97_SIGMATEL_OUTSEL,
491 7 << shift, val << shift);
494 static int snd_ac97_stac9758_input_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
496 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
497 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
499 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
501 uinfo->value.enumerated.items = 7;
502 if (uinfo->value.enumerated.item > 6)
503 uinfo->value.enumerated.item = 6;
504 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
508 static int snd_ac97_stac9758_input_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
510 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
511 int shift = kcontrol->private_value;
514 val = ac97->regs[AC97_SIGMATEL_INSEL];
515 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
519 static int snd_ac97_stac9758_input_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
521 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
522 int shift = kcontrol->private_value;
524 return snd_ac97_update_bits(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
525 ucontrol->value.enumerated.item[0] << shift);
528 static int snd_ac97_stac9758_phonesel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
530 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
532 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
534 uinfo->value.enumerated.items = 3;
535 if (uinfo->value.enumerated.item > 2)
536 uinfo->value.enumerated.item = 2;
537 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
541 static int snd_ac97_stac9758_phonesel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
543 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
545 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
549 static int snd_ac97_stac9758_phonesel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
551 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
553 return snd_ac97_update_bits(ac97, AC97_SIGMATEL_IOMISC, 3,
554 ucontrol->value.enumerated.item[0]);
557 #define STAC9758_OUTPUT_JACK(xname, shift) \
558 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
559 .info = snd_ac97_stac9758_output_jack_info, \
560 .get = snd_ac97_stac9758_output_jack_get, \
561 .put = snd_ac97_stac9758_output_jack_put, \
562 .private_value = shift }
563 #define STAC9758_INPUT_JACK(xname, shift) \
564 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
565 .info = snd_ac97_stac9758_input_jack_info, \
566 .get = snd_ac97_stac9758_input_jack_get, \
567 .put = snd_ac97_stac9758_input_jack_put, \
568 .private_value = shift }
569 static const snd_kcontrol_new_t snd_ac97_sigmatel_stac9758_controls[] = {
570 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
571 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
572 STAC9758_OUTPUT_JACK("Front Jack", 7),
573 STAC9758_OUTPUT_JACK("Rear Jack", 10),
574 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
575 STAC9758_INPUT_JACK("Mic Input Source", 0),
576 STAC9758_INPUT_JACK("Line Input Source", 8),
578 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
579 .name = "Headphone Amp",
580 .info = snd_ac97_stac9758_phonesel_info,
581 .get = snd_ac97_stac9758_phonesel_get,
582 .put = snd_ac97_stac9758_phonesel_put
584 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
585 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
588 static int patch_sigmatel_stac9758_specific(ac97_t *ac97)
592 err = patch_sigmatel_stac97xx_specific(ac97);
595 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
596 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
602 static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
603 .build_3d = patch_sigmatel_stac9700_3d,
604 .build_specific = patch_sigmatel_stac9758_specific
607 int patch_sigmatel_stac9758(ac97_t * ac97)
609 static unsigned short regs[4] = {
610 AC97_SIGMATEL_OUTSEL,
611 AC97_SIGMATEL_IOMISC,
613 AC97_SIGMATEL_VARIOUS
615 static unsigned short def_regs[4] = {
621 static unsigned short m675_regs[4] = {
627 unsigned short *pregs = def_regs;
630 /* Gateway M675 notebook */
632 ac97->subsystem_vendor == 0x107b &&
633 ac97->subsystem_device == 0x0601)
636 // patch for SigmaTel
637 ac97->build_ops = &patch_sigmatel_stac9758_ops;
638 for (i = 0; i < 4; i++)
639 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
641 ac97->flags |= AC97_STEREO_MUTES;
646 * Cirrus Logic CS42xx codecs
648 static const snd_kcontrol_new_t snd_ac97_cirrus_controls_spdif[2] = {
649 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
650 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
653 static int patch_cirrus_build_spdif(ac97_t * ac97)
657 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
659 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
661 switch (ac97->id & AC97_ID_CS_MASK) {
663 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
667 /* set default PCM S/PDIF params */
668 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
669 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
673 static struct snd_ac97_build_ops patch_cirrus_ops = {
674 .build_spdif = patch_cirrus_build_spdif
677 int patch_cirrus_spdif(ac97_t * ac97)
679 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
680 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
681 - sp/dif EA ID is not set, but sp/dif is always present.
682 - enable/disable is spdif register bit 15.
683 - sp/dif control register is 0x68. differs from AC97:
684 - valid is bit 14 (vs 15)
686 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
687 - sp/dif ssource select is in 0x5e bits 0,1.
690 ac97->build_ops = &patch_cirrus_ops;
691 ac97->flags |= AC97_CS_SPDIF;
692 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
693 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
694 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
698 int patch_cirrus_cs4299(ac97_t * ac97)
700 /* force the detection of PC Beep */
701 ac97->flags |= AC97_HAS_PC_BEEP;
703 return patch_cirrus_spdif(ac97);
709 static const snd_kcontrol_new_t snd_ac97_conexant_controls_spdif[1] = {
710 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
713 static int patch_conexant_build_spdif(ac97_t * ac97)
717 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
719 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
721 /* set default PCM S/PDIF params */
722 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
723 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
724 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
728 static struct snd_ac97_build_ops patch_conexant_ops = {
729 .build_spdif = patch_conexant_build_spdif
732 int patch_conexant(ac97_t * ac97)
734 ac97->build_ops = &patch_conexant_ops;
735 ac97->flags |= AC97_CX_SPDIF;
736 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
741 * Analog Device AD18xx, AD19xx codecs
743 int patch_ad1819(ac97_t * ac97)
747 // patch for Analog Devices
748 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
749 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
753 static unsigned short patch_ad1881_unchained(ac97_t * ac97, int idx, unsigned short mask)
757 // test for unchained codec
758 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
759 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
760 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
761 if ((val & 0xff40) != 0x5340)
763 ac97->spec.ad18xx.unchained[idx] = mask;
764 ac97->spec.ad18xx.id[idx] = val;
765 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
769 static int patch_ad1881_chained1(ac97_t * ac97, int idx, unsigned short codec_bits)
771 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
774 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
775 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
776 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
777 if ((val & 0xff40) != 0x5340)
780 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
781 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
782 ac97->spec.ad18xx.id[idx] = val;
783 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
787 static void patch_ad1881_chained(ac97_t * ac97, int unchained_idx, int cidx1, int cidx2)
790 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
792 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
794 if (cidx1 < 0 && cidx2 < 0)
796 // test for chained codecs
797 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
798 ac97->spec.ad18xx.unchained[unchained_idx]);
799 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
800 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
802 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
803 patch_ad1881_chained1(ac97, cidx2, 0);
804 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
805 patch_ad1881_chained1(ac97, cidx1, 0);
806 } else if (cidx2 >= 0) {
807 patch_ad1881_chained1(ac97, cidx2, 0);
811 int patch_ad1881(ac97_t * ac97)
813 static const char cfg_idxs[3][2] = {
819 // patch for Analog Devices
820 unsigned short codecs[3];
824 init_MUTEX(&ac97->spec.ad18xx.mutex);
826 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
827 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
828 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
829 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
830 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
832 snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end);
834 for (idx = 0; idx < 3; idx++)
835 if (ac97->spec.ad18xx.unchained[idx])
836 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
838 if (ac97->spec.ad18xx.id[1]) {
839 ac97->flags |= AC97_AD_MULTI;
840 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
842 if (ac97->spec.ad18xx.id[2]) {
843 ac97->flags |= AC97_AD_MULTI;
844 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
848 /* select all codecs */
849 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
850 /* check if only one codec is present */
851 for (idx = num = 0; idx < 3; idx++)
852 if (ac97->spec.ad18xx.id[idx])
855 /* ok, deselect all ID bits */
856 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
857 ac97->spec.ad18xx.codec_cfg[0] =
858 ac97->spec.ad18xx.codec_cfg[1] =
859 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
861 /* required for AD1886/AD1885 combination */
862 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
863 if (ac97->spec.ad18xx.id[0]) {
864 ac97->id &= 0xffff0000;
865 ac97->id |= ac97->spec.ad18xx.id[0];
870 static const snd_kcontrol_new_t snd_ac97_controls_ad1885[] = {
871 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
872 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
873 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
874 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
877 static int patch_ad1885_specific(ac97_t * ac97)
881 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
886 static struct snd_ac97_build_ops patch_ad1885_build_ops = {
887 .build_specific = &patch_ad1885_specific
890 int patch_ad1885(ac97_t * ac97)
895 /* This is required to deal with the Intel D815EEAL2 */
896 /* i.e. Line out is actually headphone out from codec */
898 /* turn off jack sense bits D8 & D9 */
899 jack = snd_ac97_read(ac97, AC97_AD_JACK_SPDIF);
900 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, jack | 0x0300);
903 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
905 ac97->build_ops = &patch_ad1885_build_ops;
909 int patch_ad1886(ac97_t * ac97)
912 /* Presario700 workaround */
913 /* for Jack Sense/SPDIF Register misetting causing */
914 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
919 #define AC97_AD198X_MBC 0x0003 /* mic boost */
920 #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
921 #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
922 #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
923 #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
924 #define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
925 #define AC97_AD198X_VREF_0 0x000c /* 0V */
926 #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
927 #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
928 #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
929 #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
930 #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
931 #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
932 #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
933 #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
934 #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
935 #define AC97_AD198X_MSPLT 0x2000 /* mute split */
936 #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
937 #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
940 static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
942 static char *texts[2] = { "AC-Link", "A/D Converter" };
944 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
946 uinfo->value.enumerated.items = 2;
947 if (uinfo->value.enumerated.item > 1)
948 uinfo->value.enumerated.item = 1;
949 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
953 static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
955 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
958 val = ac97->regs[AC97_AD_SERIAL_CFG];
959 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
963 static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
965 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
968 if (ucontrol->value.enumerated.item[0] > 1)
970 val = ucontrol->value.enumerated.item[0] << 2;
971 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
974 static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source = {
975 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
976 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
977 .info = snd_ac97_ad198x_spdif_source_info,
978 .get = snd_ac97_ad198x_spdif_source_get,
979 .put = snd_ac97_ad198x_spdif_source_put,
982 static int patch_ad198x_post_spdif(ac97_t * ac97)
984 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
987 static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
988 .build_post_spdif = patch_ad198x_post_spdif
991 int patch_ad1981a(ac97_t *ac97)
994 ac97->build_ops = &patch_ad1981a_build_ops;
995 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
996 ac97->flags |= AC97_STEREO_MUTES;
1000 static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic =
1001 AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1003 static int patch_ad1981b_specific(ac97_t *ac97)
1005 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1008 static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1009 .build_post_spdif = patch_ad198x_post_spdif,
1010 .build_specific = patch_ad1981b_specific
1013 int patch_ad1981b(ac97_t *ac97)
1016 ac97->build_ops = &patch_ad1981b_build_ops;
1017 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1018 ac97->flags |= AC97_STEREO_MUTES;
1022 static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1024 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1026 uinfo->value.integer.min = 0;
1027 uinfo->value.integer.max = 1;
1031 static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1033 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1036 val = ac97->regs[AC97_AD_MISC];
1037 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1041 static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1043 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1046 val = !ucontrol->value.integer.value[0]
1047 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1048 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1049 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1052 static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1054 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1056 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1058 uinfo->value.enumerated.items = 3;
1059 if (uinfo->value.enumerated.item > 2)
1060 uinfo->value.enumerated.item = 2;
1061 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1065 static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1067 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1070 val = ac97->regs[AC97_AD_MISC];
1071 if (!(val & AC97_AD198X_DMIX1))
1072 ucontrol->value.enumerated.item[0] = 0;
1074 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1078 static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1080 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1083 if (ucontrol->value.enumerated.item[0] > 2)
1085 if (ucontrol->value.enumerated.item[0] == 0)
1088 val = AC97_AD198X_DMIX1 |
1089 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1090 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1091 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1094 static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = {
1096 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1097 .name = "Exchange Front/Surround",
1098 .info = snd_ac97_ad1888_lohpsel_info,
1099 .get = snd_ac97_ad1888_lohpsel_get,
1100 .put = snd_ac97_ad1888_lohpsel_put
1102 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1104 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1106 .info = snd_ac97_ad1888_downmix_info,
1107 .get = snd_ac97_ad1888_downmix_get,
1108 .put = snd_ac97_ad1888_downmix_put
1110 AC97_SINGLE("Surround Jack as Input", AC97_AD_MISC, 12, 1, 0),
1111 AC97_SINGLE("Center/LFE Jack as Input", AC97_AD_MISC, 11, 1, 0),
1114 static int patch_ad1888_specific(ac97_t *ac97)
1116 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1117 snd_ac97_rename_ctl(ac97, "Master Playback Switch", "Master Surround Playback Switch");
1118 snd_ac97_rename_ctl(ac97, "Master Playback Volume", "Master Surround Playback Volume");
1119 snd_ac97_rename_ctl(ac97, "Headphone Playback Switch", "Master Playback Switch");
1120 snd_ac97_rename_ctl(ac97, "Headphone Playback Volume", "Master Playback Volume");
1121 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1124 static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1125 .build_post_spdif = patch_ad198x_post_spdif,
1126 .build_specific = patch_ad1888_specific
1129 int patch_ad1888(ac97_t * ac97)
1131 unsigned short misc;
1134 ac97->build_ops = &patch_ad1888_build_ops;
1135 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1136 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1137 /* AD-compatible mode */
1138 /* Stereo mutes enabled */
1139 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1140 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1144 AC97_AD198X_AC97NC);
1145 ac97->flags |= AC97_STEREO_MUTES;
1149 static int patch_ad1980_specific(ac97_t *ac97)
1153 if ((err = patch_ad1888_specific(ac97)) < 0)
1155 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1158 static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1159 .build_post_spdif = patch_ad198x_post_spdif,
1160 .build_specific = patch_ad1980_specific
1163 int patch_ad1980(ac97_t * ac97)
1166 ac97->build_ops = &patch_ad1980_build_ops;
1170 static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = {
1171 AC97_SINGLE("Center/LFE Jack as Mic", AC97_AD_SERIAL_CFG, 9, 1, 0),
1172 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1175 static int patch_ad1985_specific(ac97_t *ac97)
1179 if ((err = patch_ad1980_specific(ac97)) < 0)
1181 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1184 static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1185 .build_post_spdif = patch_ad198x_post_spdif,
1186 .build_specific = patch_ad1985_specific
1189 int patch_ad1985(ac97_t * ac97)
1191 unsigned short misc;
1194 ac97->build_ops = &patch_ad1985_build_ops;
1195 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1196 /* switch front/surround line-out/hp-out */
1197 /* center/LFE, mic in 3.75V mode */
1198 /* AD-compatible mode */
1199 /* Stereo mutes enabled */
1200 /* in accordance with ADI driver: misc | 0x5c28 */
1201 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1208 AC97_AD198X_AC97NC);
1209 ac97->flags |= AC97_STEREO_MUTES;
1210 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1211 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
1216 * realtek ALC65x codecs
1218 static int snd_ac97_alc650_mic_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1220 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1221 ucontrol->value.integer.value[0] = (ac97->regs[AC97_ALC650_MULTICH] >> 10) & 1;
1225 static int snd_ac97_alc650_mic_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1227 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1229 val = !!(snd_ac97_read(ac97, AC97_ALC650_MULTICH) & (1 << 10));
1230 change = (ucontrol->value.integer.value[0] != val);
1232 /* disable/enable vref */
1233 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1234 ucontrol->value.integer.value[0] ? (1 << 12) : 0);
1235 /* turn on/off center-on-mic */
1236 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1237 ucontrol->value.integer.value[0] ? (1 << 10) : 0);
1238 /* GPIO0 high for mic */
1239 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1240 ucontrol->value.integer.value[0] ? 0 : 0x100);
1245 static const snd_kcontrol_new_t snd_ac97_controls_alc650[] = {
1246 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1247 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
1248 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
1249 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
1250 /* 4: Analog Input To Surround */
1251 /* 5: Analog Input To Center/LFE */
1252 /* 6: Independent Master Volume Right */
1253 /* 7: Independent Master Volume Left */
1255 AC97_SINGLE("Line-In As Surround", AC97_ALC650_MULTICH, 9, 1, 0),
1256 /* 10: mic, see below */
1257 /* 11-13: in IEC958 controls */
1258 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
1259 #if 0 /* always set in patch_alc650 */
1260 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
1261 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
1262 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
1263 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
1264 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
1265 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
1268 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1269 .name = "Mic As Center/LFE",
1270 .info = snd_ac97_info_single,
1271 .get = snd_ac97_alc650_mic_get,
1272 .put = snd_ac97_alc650_mic_put,
1273 .private_value = AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
1277 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc650[] = {
1278 AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0),
1279 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
1280 AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0),
1283 static int patch_alc650_specific(ac97_t * ac97)
1287 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
1289 if (ac97->ext_id & AC97_EI_SPDIF) {
1290 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
1296 static struct snd_ac97_build_ops patch_alc650_ops = {
1297 .build_specific = patch_alc650_specific
1300 int patch_alc650(ac97_t * ac97)
1304 ac97->build_ops = &patch_alc650_ops;
1306 /* revision E or F */
1307 /* FIXME: what about revision D ? */
1308 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
1309 ac97->id == 0x414c4723);
1311 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
1312 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
1313 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
1315 /* Enable SPDIF-IN only on Rev.E and above */
1316 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
1317 /* SPDIF IN with pin 47 */
1318 if (ac97->spec.dev_flags)
1319 val |= 0x03; /* enable */
1321 val &= ~0x03; /* disable */
1322 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
1324 /* set default: slot 3,4,7,8,6,9
1325 spdif-in monitor off, analog-spdif off, spdif-in off
1326 center on mic off, surround on line-in off
1327 downmix off, duplicate front off
1329 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
1331 /* set GPIO0 for mic bias */
1332 /* GPIO0 pin output, no interrupt, high */
1333 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
1334 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
1335 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
1336 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
1338 /* full DAC volume */
1339 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1340 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1344 static int snd_ac97_alc655_mic_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1346 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1347 ucontrol->value.integer.value[0] = (ac97->regs[AC97_ALC650_MULTICH] >> 10) & 1;
1351 static int snd_ac97_alc655_mic_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t * ucontrol)
1353 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1356 /* misc control; vrefout disable */
1357 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1358 ucontrol->value.integer.value[0] ? (1 << 12) : 0);
1359 change = snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1360 ucontrol->value.integer.value[0] ? (1 << 10) : 0);
1365 static const snd_kcontrol_new_t snd_ac97_controls_alc655[] = {
1366 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1367 AC97_SINGLE("Line-In As Surround", AC97_ALC650_MULTICH, 9, 1, 0),
1369 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1370 .name = "Mic As Center/LFE",
1371 .info = snd_ac97_info_single,
1372 .get = snd_ac97_alc655_mic_get,
1373 .put = snd_ac97_alc655_mic_put,
1374 .private_value = AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
1378 static int alc655_iec958_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1380 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
1381 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
1382 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1384 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1386 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
1387 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1388 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1389 strcpy(uinfo->value.enumerated.name,
1390 ac97->spec.dev_flags ?
1391 texts_658[uinfo->value.enumerated.item] :
1392 texts_655[uinfo->value.enumerated.item]);
1397 static int alc655_iec958_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1399 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1402 val = ac97->regs[AC97_ALC650_MULTICH];
1403 val = (val >> 12) & 3;
1404 if (ac97->spec.dev_flags && val == 3)
1406 ucontrol->value.enumerated.item[0] = val;
1410 static int alc655_iec958_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1412 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1413 return snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 3 << 12,
1414 (unsigned short)ucontrol->value.enumerated.item[0]);
1417 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655[] = {
1418 AC97_SINGLE("IEC958 Capture Switch", AC97_ALC650_MULTICH, 11, 1, 0),
1419 AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0),
1421 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1422 .name = "IEC958 Playback Route",
1423 .info = alc655_iec958_route_info,
1424 .get = alc655_iec958_route_get,
1425 .put = alc655_iec958_route_put,
1429 static int patch_alc655_specific(ac97_t * ac97)
1433 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
1435 if (ac97->ext_id & AC97_EI_SPDIF) {
1436 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
1442 static struct snd_ac97_build_ops patch_alc655_ops = {
1443 .build_specific = patch_alc655_specific
1446 int patch_alc655(ac97_t * ac97)
1450 ac97->spec.dev_flags = (ac97->id == 0x414c4780); /* ALC658 */
1452 ac97->build_ops = &patch_alc655_ops;
1454 /* adjust default values */
1455 val = snd_ac97_read(ac97, 0x7a); /* misc control */
1456 val |= (1 << 1); /* spdif input pin */
1457 val &= ~(1 << 12); /* vref enable */
1458 snd_ac97_write_cache(ac97, 0x7a, val);
1459 /* set default: spdif-in enabled,
1460 spdif-in monitor off, spdif-in PCM off
1461 center on mic off, surround on line-in off
1464 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
1466 /* full DAC volume */
1467 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
1468 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
1473 * C-Media CM97xx codecs
1475 static const snd_kcontrol_new_t snd_ac97_cm9738_controls[] = {
1476 AC97_SINGLE("Line-In As Surround", AC97_CM9738_VENDOR_CTRL, 10, 1, 0),
1477 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
1480 static int patch_cm9738_specific(ac97_t * ac97)
1482 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
1485 static struct snd_ac97_build_ops patch_cm9738_ops = {
1486 .build_specific = patch_cm9738_specific
1489 int patch_cm9738(ac97_t * ac97)
1491 ac97->build_ops = &patch_cm9738_ops;
1495 static int snd_ac97_cmedia_spdif_playback_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1497 static char *texts[] = { "Analog", "Digital" };
1499 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1501 uinfo->value.enumerated.items = 2;
1502 if (uinfo->value.enumerated.item > 1)
1503 uinfo->value.enumerated.item = 1;
1504 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1508 static int snd_ac97_cmedia_spdif_playback_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1510 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1513 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
1514 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
1518 static int snd_ac97_cmedia_spdif_playback_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1520 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1522 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
1524 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
1527 static const snd_kcontrol_new_t snd_ac97_cm9739_controls_spdif[] = {
1528 /* BIT 0: SPDI_EN - always true */
1529 { /* BIT 1: SPDIFS */
1530 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1531 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1532 .info = snd_ac97_cmedia_spdif_playback_source_info,
1533 .get = snd_ac97_cmedia_spdif_playback_source_get,
1534 .put = snd_ac97_cmedia_spdif_playback_source_put,
1536 /* BIT 2: IG_SPIV */
1537 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
1539 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
1540 /* BIT 4: SPI2SDI */
1541 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
1542 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
1545 static int snd_ac97_cm9739_center_mic_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1547 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1548 if (ac97->regs[AC97_CM9739_MULTI_CHAN] & 0x1000)
1549 ucontrol->value.integer.value[0] = 1;
1551 ucontrol->value.integer.value[0] = 0;
1555 static int snd_ac97_cm9739_center_mic_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1557 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1558 return snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
1559 ucontrol->value.integer.value[0] ?
1563 static const snd_kcontrol_new_t snd_ac97_cm9739_controls[] = {
1564 AC97_SINGLE("Line-In As Surround", AC97_CM9739_MULTI_CHAN, 10, 1, 0),
1566 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1567 .name = "Mic As Center/LFE",
1568 .info = snd_ac97_info_single,
1569 .get = snd_ac97_cm9739_center_mic_get,
1570 .put = snd_ac97_cm9739_center_mic_put,
1571 .private_value = AC97_SINGLE_VALUE(0, 0, 1, 0) /* only mask needed */
1575 static int patch_cm9739_specific(ac97_t * ac97)
1577 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
1580 static int patch_cm9739_post_spdif(ac97_t * ac97)
1582 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
1585 static struct snd_ac97_build_ops patch_cm9739_ops = {
1586 .build_specific = patch_cm9739_specific,
1587 .build_post_spdif = patch_cm9739_post_spdif
1590 int patch_cm9739(ac97_t * ac97)
1594 ac97->build_ops = &patch_cm9739_ops;
1597 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
1598 if (val & AC97_EA_SPCV) {
1599 /* enable spdif in */
1600 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
1601 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
1603 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
1606 /* set-up multi channel */
1607 /* bit 14: 0 = SPDIF, 1 = EAPD */
1608 /* bit 13: enable internal vref output for mic */
1609 /* bit 12: disable center/lfe (swithable) */
1610 /* bit 10: disable surround/line (switchable) */
1611 /* bit 9: mix 2 surround off */
1614 if (! (ac97->ext_id & AC97_EI_SPDIF))
1616 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
1618 /* FIXME: set up GPIO */
1619 snd_ac97_write_cache(ac97, 0x70, 0x0100);
1620 snd_ac97_write_cache(ac97, 0x72, 0x0020);
1628 static const snd_kcontrol_new_t snd_ac97_controls_vt1616[] = {
1629 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
1630 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
1631 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
1632 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
1635 static int patch_vt1616_specific(ac97_t * ac97)
1639 if (snd_ac97_try_bit(ac97, 0x5a, 9))
1640 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
1642 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
1647 static struct snd_ac97_build_ops patch_vt1616_ops = {
1648 .build_specific = patch_vt1616_specific
1651 int patch_vt1616(ac97_t * ac97)
1653 ac97->build_ops = &patch_vt1616_ops;
1657 static const snd_kcontrol_new_t snd_ac97_controls_it2646[] = {
1658 AC97_SINGLE("Line-In As Surround", 0x76, 9, 1, 0),
1659 AC97_SINGLE("Mic As Center/LFE", 0x76, 10, 1, 0),
1662 static const snd_kcontrol_new_t snd_ac97_spdif_controls_it2646[] = {
1663 AC97_SINGLE("IEC958 Capture Switch", 0x76, 11, 1, 0),
1664 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
1665 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
1668 static int patch_it2646_specific(ac97_t * ac97)
1671 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
1673 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
1678 static struct snd_ac97_build_ops patch_it2646_ops = {
1679 .build_specific = patch_it2646_specific
1682 int patch_it2646(ac97_t * ac97)
1684 ac97->build_ops = &patch_it2646_ops;
1685 /* full DAC volume */
1686 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
1687 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
1691 /* Si3036/8 specific registers */
1692 #define AC97_SI3036_CHIP_ID 0x5a
1694 int mpatch_si3036(ac97_t * ac97)
1696 //printk("mpatch_si3036: chip id = %x\n", snd_ac97_read(ac97, 0x5a));
1697 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
1698 snd_ac97_write_cache(ac97, 0x68, 0);