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"
39 * Chip specific initialization
42 static int patch_build_controls(ac97_t * ac97, const snd_kcontrol_new_t *controls, int count)
46 for (idx = 0; idx < count; idx++)
47 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
52 /* set to the page, update bits and restore the page */
53 static int ac97_update_bits_page(ac97_t *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
55 unsigned short page_save;
58 down(&ac97->page_mutex);
59 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
60 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
61 ret = snd_ac97_update_bits(ac97, reg, mask, value);
62 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
63 up(&ac97->page_mutex); /* unlock paging */
68 * shared line-in/mic controls
70 static int ac97_enum_text_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo,
71 const char **texts, unsigned int nums)
73 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
75 uinfo->value.enumerated.items = nums;
76 if (uinfo->value.enumerated.item > nums - 1)
77 uinfo->value.enumerated.item = nums - 1;
78 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
82 static int ac97_surround_jack_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
84 static const char *texts[] = { "Shared", "Independent" };
85 return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
88 static int ac97_surround_jack_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
90 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
92 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
96 static int ac97_surround_jack_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
98 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
99 unsigned char indep = !!ucontrol->value.enumerated.item[0];
101 if (indep != ac97->indep_surround) {
102 ac97->indep_surround = indep;
103 if (ac97->build_ops->update_jacks)
104 ac97->build_ops->update_jacks(ac97);
110 static int ac97_channel_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
112 static const char *texts[] = { "2ch", "4ch", "6ch" };
113 if (kcontrol->private_value)
114 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
115 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
118 static int ac97_channel_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
120 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
122 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
126 static int ac97_channel_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
128 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
129 unsigned char mode = ucontrol->value.enumerated.item[0];
131 if (mode != ac97->channel_mode) {
132 ac97->channel_mode = mode;
133 if (ac97->build_ops->update_jacks)
134 ac97->build_ops->update_jacks(ac97);
140 #define AC97_SURROUND_JACK_MODE_CTL \
142 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
143 .name = "Surround Jack Mode", \
144 .info = ac97_surround_jack_mode_info, \
145 .get = ac97_surround_jack_mode_get, \
146 .put = ac97_surround_jack_mode_put, \
148 #define AC97_CHANNEL_MODE_CTL \
150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
151 .name = "Channel Mode", \
152 .info = ac97_channel_mode_info, \
153 .get = ac97_channel_mode_get, \
154 .put = ac97_channel_mode_put, \
156 #define AC97_CHANNEL_MODE_4CH_CTL \
158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
159 .name = "Channel Mode", \
160 .info = ac97_channel_mode_info, \
161 .get = ac97_channel_mode_get, \
162 .put = ac97_channel_mode_put, \
163 .private_value = 1, \
166 static inline int is_shared_linein(ac97_t *ac97)
168 return ! ac97->indep_surround && ac97->channel_mode >= 1;
171 static inline int is_shared_micin(ac97_t *ac97)
173 return ! ac97->indep_surround && ac97->channel_mode >= 2;
177 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
179 /* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
180 static int snd_ac97_ymf753_info_speaker(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
182 static char *texts[3] = {
183 "Standard", "Small", "Smaller"
186 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
188 uinfo->value.enumerated.items = 3;
189 if (uinfo->value.enumerated.item > 2)
190 uinfo->value.enumerated.item = 2;
191 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
195 static int snd_ac97_ymf753_get_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
197 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
200 val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
201 val = (val >> 10) & 3;
202 if (val > 0) /* 0 = invalid */
204 ucontrol->value.enumerated.item[0] = val;
208 static int snd_ac97_ymf753_put_speaker(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
210 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
213 if (ucontrol->value.enumerated.item[0] > 2)
215 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
216 return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
219 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_speaker =
221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
222 .name = "3D Control - Speaker",
223 .info = snd_ac97_ymf753_info_speaker,
224 .get = snd_ac97_ymf753_get_speaker,
225 .put = snd_ac97_ymf753_put_speaker,
228 /* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
229 static int snd_ac97_ymf753_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
231 static char *texts[2] = { "AC-Link", "A/D Converter" };
233 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
235 uinfo->value.enumerated.items = 2;
236 if (uinfo->value.enumerated.item > 1)
237 uinfo->value.enumerated.item = 1;
238 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
242 static int snd_ac97_ymf753_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
244 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
247 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
248 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
252 static int snd_ac97_ymf753_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
254 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
257 if (ucontrol->value.enumerated.item[0] > 1)
259 val = ucontrol->value.enumerated.item[0] << 1;
260 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
263 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
264 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
265 By default, no output pin is selected, and the S/PDIF signal is not output.
266 There is also a bit to mute S/PDIF output in a vendor-specific register. */
267 static int snd_ac97_ymf753_spdif_output_pin_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
269 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
271 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
273 uinfo->value.enumerated.items = 3;
274 if (uinfo->value.enumerated.item > 2)
275 uinfo->value.enumerated.item = 2;
276 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
280 static int snd_ac97_ymf753_spdif_output_pin_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
282 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
285 val = ac97->regs[AC97_YMF753_DIT_CTRL2];
286 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
290 static int snd_ac97_ymf753_spdif_output_pin_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
292 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
295 if (ucontrol->value.enumerated.item[0] > 2)
297 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
298 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
299 return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
300 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
301 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
304 static const snd_kcontrol_new_t snd_ac97_ymf753_controls_spdif[3] = {
306 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
307 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
308 .info = snd_ac97_ymf753_spdif_source_info,
309 .get = snd_ac97_ymf753_spdif_source_get,
310 .put = snd_ac97_ymf753_spdif_source_put,
313 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
314 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
315 .info = snd_ac97_ymf753_spdif_output_pin_info,
316 .get = snd_ac97_ymf753_spdif_output_pin_get,
317 .put = snd_ac97_ymf753_spdif_output_pin_put,
319 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
322 static int patch_yamaha_ymf753_3d(ac97_t * ac97)
324 snd_kcontrol_t *kctl;
327 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
329 strcpy(kctl->id.name, "3D Control - Wide");
330 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
331 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
332 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
334 snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
338 static int patch_yamaha_ymf753_post_spdif(ac97_t * ac97)
342 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
347 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
348 .build_3d = patch_yamaha_ymf753_3d,
349 .build_post_spdif = patch_yamaha_ymf753_post_spdif
352 int patch_yamaha_ymf753(ac97_t * ac97)
354 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
355 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
356 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
357 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
358 By default, no output pin is selected, and the S/PDIF signal is not output.
359 There is also a bit to mute S/PDIF output in a vendor-specific register.
361 ac97->build_ops = &patch_yamaha_ymf753_ops;
362 ac97->caps |= AC97_BC_BASS_TREBLE;
363 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
368 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
369 * removed broken wolfson00 patch.
370 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
373 static const snd_kcontrol_new_t wm97xx_snd_ac97_controls[] = {
374 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
375 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
378 static int patch_wolfson_wm9703_specific(ac97_t * ac97)
380 /* This is known to work for the ViewSonic ViewPad 1000
381 * Randolph Bentson <bentson@holmsjoen.com>
382 * WM9703/9707/9708/9717
386 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
387 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
390 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
394 static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
395 .build_specific = patch_wolfson_wm9703_specific,
398 int patch_wolfson03(ac97_t * ac97)
400 ac97->build_ops = &patch_wolfson_wm9703_ops;
404 static const snd_kcontrol_new_t wm9704_snd_ac97_controls[] = {
405 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
406 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
407 AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
408 AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
409 AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
410 AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
413 static int patch_wolfson_wm9704_specific(ac97_t * ac97)
416 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
417 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
420 /* patch for DVD noise */
421 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
425 static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
426 .build_specific = patch_wolfson_wm9704_specific,
429 int patch_wolfson04(ac97_t * ac97)
432 ac97->build_ops = &patch_wolfson_wm9704_ops;
436 static int patch_wolfson_wm9705_specific(ac97_t * ac97)
439 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
440 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
443 snd_ac97_write_cache(ac97, 0x72, 0x0808);
447 static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
448 .build_specific = patch_wolfson_wm9705_specific,
451 int patch_wolfson05(ac97_t * ac97)
454 ac97->build_ops = &patch_wolfson_wm9705_ops;
458 static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
459 static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
460 static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
461 static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
462 static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
463 static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
464 static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
465 static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
466 static const char* wm9711_rec_sel[] =
467 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
468 static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
470 static const struct ac97_enum wm9711_enum[] = {
471 AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
472 AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
473 AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
474 AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
475 AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
476 AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
477 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
478 AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
479 AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
480 AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
483 static const snd_kcontrol_new_t wm9711_snd_ac97_controls[] = {
484 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
485 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
486 AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
487 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
488 AC97_ENUM("ALC Function", wm9711_enum[0]),
489 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
490 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
491 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
492 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
493 AC97_ENUM("ALC NG Type", wm9711_enum[9]),
494 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
496 AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
497 AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
498 AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
499 AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
501 AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
502 AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1),
503 AC97_ENUM("Out3 Mux", wm9711_enum[2]),
504 AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
505 AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
507 AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
508 AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
509 AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
510 AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
511 AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
512 AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
514 AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
515 AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
516 AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
517 AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
518 AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
519 AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
521 AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
522 AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
524 AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
525 AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
526 AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
528 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
529 AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
530 AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
532 AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
533 AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
534 AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
535 AC97_ENUM("Capture Select", wm9711_enum[8]),
537 AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
538 AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
540 AC97_ENUM("Bass Control", wm9711_enum[5]),
541 AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
542 AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
543 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
545 AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
546 AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
547 AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 1),
548 AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
550 AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
551 AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
552 AC97_ENUM("Mic Select Source", wm9711_enum[7]),
553 AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 32, 1),
554 AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
556 AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
557 AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
558 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
561 static int patch_wolfson_wm9711_specific(ac97_t * ac97)
565 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
566 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
569 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
570 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
571 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
572 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
573 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
574 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
578 static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
579 .build_specific = patch_wolfson_wm9711_specific,
582 int patch_wolfson11(ac97_t * ac97)
585 ac97->build_ops = &patch_wolfson_wm9711_ops;
587 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
588 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
593 static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
594 static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
595 static const char* wm9713_rec_src[] =
596 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
598 static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
599 static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
600 static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
601 static const char* wm9713_spk_pga[] =
602 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
603 static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
604 static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
605 static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
606 static const char* wm9713_dac_inv[] =
607 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
608 "Headphone Mix Mono", "NC", "Vmid"};
609 static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
610 static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
612 static const struct ac97_enum wm9713_enum[] = {
613 AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
614 AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
615 AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
616 AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
617 AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
618 AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
619 AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
620 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
621 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
622 AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
623 AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
624 AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
625 AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
626 AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
629 static const snd_kcontrol_new_t wm13_snd_ac97_controls[] = {
630 AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
631 AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
632 AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
633 AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
635 AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
636 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
637 AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
638 AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
640 AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
641 AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
642 AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
643 AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
644 AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
645 AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
646 AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
648 AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
649 AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
650 AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
651 AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
653 AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
654 AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
655 AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
656 AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
657 AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
658 AC97_ENUM("Capture Select", wm9713_enum[3]),
660 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
661 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
662 AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
663 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
664 AC97_ENUM("ALC Function", wm9713_enum[5]),
665 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
666 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
667 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
668 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
669 AC97_ENUM("ALC NG Type", wm9713_enum[13]),
670 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
672 AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
673 AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
674 AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
675 AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
676 AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
677 AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
679 AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
680 AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
681 AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
682 AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
683 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
684 AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
686 AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
687 AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
688 AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
689 AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
690 AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
691 AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
693 AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
694 AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
695 AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
696 AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
697 AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
698 AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
700 AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
701 AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
702 AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
703 AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
704 AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
705 AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
707 AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
708 AC97_ENUM("Master Input Mux", wm9713_enum[7]),
709 AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
710 AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
711 AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
713 AC97_ENUM("Bass Control", wm9713_enum[12]),
714 AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
715 AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
716 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
717 AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
718 AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
721 static const snd_kcontrol_new_t wm13_snd_ac97_controls_3d[] = {
722 AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
723 AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
724 AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
725 AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
728 static int patch_wolfson_wm9713_3d (ac97_t * ac97)
732 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
733 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
739 static int patch_wolfson_wm9713_specific(ac97_t * ac97)
743 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
744 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
747 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
748 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
749 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
750 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
751 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
752 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
753 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
758 static void patch_wolfson_wm9713_suspend (ac97_t * ac97)
760 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
761 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
764 static void patch_wolfson_wm9713_resume (ac97_t * ac97)
766 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
767 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
768 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
772 static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
773 .build_specific = patch_wolfson_wm9713_specific,
774 .build_3d = patch_wolfson_wm9713_3d,
776 .suspend = patch_wolfson_wm9713_suspend,
777 .resume = patch_wolfson_wm9713_resume
781 int patch_wolfson13(ac97_t * ac97)
784 ac97->build_ops = &patch_wolfson_wm9713_ops;
786 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
787 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
789 ac97->scaps &= ~AC97_SCAP_MODEM;
791 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
792 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
793 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
801 int patch_tritech_tr28028(ac97_t * ac97)
803 snd_ac97_write_cache(ac97, 0x26, 0x0300);
804 snd_ac97_write_cache(ac97, 0x26, 0x0000);
805 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
806 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
811 * Sigmatel STAC97xx codecs
813 static int patch_sigmatel_stac9700_3d(ac97_t * ac97)
815 snd_kcontrol_t *kctl;
818 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
820 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
821 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
822 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
826 static int patch_sigmatel_stac9708_3d(ac97_t * ac97)
828 snd_kcontrol_t *kctl;
831 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
833 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
834 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
835 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
837 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
838 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
839 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
843 static const snd_kcontrol_new_t snd_ac97_sigmatel_4speaker =
844 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
846 static const snd_kcontrol_new_t snd_ac97_sigmatel_phaseinvert =
847 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
849 static const snd_kcontrol_new_t snd_ac97_sigmatel_controls[] = {
850 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
851 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
854 static int patch_sigmatel_stac97xx_specific(ac97_t * ac97)
858 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
859 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
860 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
862 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
863 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
865 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
866 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
868 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
869 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
874 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
875 .build_3d = patch_sigmatel_stac9700_3d,
876 .build_specific = patch_sigmatel_stac97xx_specific
879 int patch_sigmatel_stac9700(ac97_t * ac97)
881 ac97->build_ops = &patch_sigmatel_stac9700_ops;
885 static int snd_ac97_stac9708_put_bias(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
887 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
890 down(&ac97->page_mutex);
891 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
892 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
893 (ucontrol->value.integer.value[0] & 1) << 4);
894 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
895 up(&ac97->page_mutex);
899 static const snd_kcontrol_new_t snd_ac97_stac9708_bias_control = {
900 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
901 .name = "Sigmatel Output Bias Switch",
902 .info = snd_ac97_info_volsw,
903 .get = snd_ac97_get_volsw,
904 .put = snd_ac97_stac9708_put_bias,
905 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
908 static int patch_sigmatel_stac9708_specific(ac97_t *ac97)
912 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
913 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
915 return patch_sigmatel_stac97xx_specific(ac97);
918 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
919 .build_3d = patch_sigmatel_stac9708_3d,
920 .build_specific = patch_sigmatel_stac9708_specific
923 int patch_sigmatel_stac9708(ac97_t * ac97)
925 unsigned int codec72, codec6c;
927 ac97->build_ops = &patch_sigmatel_stac9708_ops;
928 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
930 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
931 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
933 if ((codec72==0) && (codec6c==0)) {
934 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
935 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
936 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
937 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
938 } else if ((codec72==0x8000) && (codec6c==0)) {
939 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
940 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
941 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
942 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
945 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
949 int patch_sigmatel_stac9721(ac97_t * ac97)
951 ac97->build_ops = &patch_sigmatel_stac9700_ops;
952 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
953 // patch for SigmaTel
954 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
955 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
956 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
957 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
959 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
963 int patch_sigmatel_stac9744(ac97_t * ac97)
965 // patch for SigmaTel
966 ac97->build_ops = &patch_sigmatel_stac9700_ops;
967 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
968 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
969 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
970 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
971 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
975 int patch_sigmatel_stac9756(ac97_t * ac97)
977 // patch for SigmaTel
978 ac97->build_ops = &patch_sigmatel_stac9700_ops;
979 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
980 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
981 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
982 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
983 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
987 static int snd_ac97_stac9758_output_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
989 static char *texts[5] = { "Input/Disabled", "Front Output",
990 "Rear Output", "Center/LFE Output", "Mixer Output" };
992 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
994 uinfo->value.enumerated.items = 5;
995 if (uinfo->value.enumerated.item > 4)
996 uinfo->value.enumerated.item = 4;
997 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1001 static int snd_ac97_stac9758_output_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1003 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1004 int shift = kcontrol->private_value;
1007 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1009 ucontrol->value.enumerated.item[0] = 0;
1011 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1015 static int snd_ac97_stac9758_output_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1017 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1018 int shift = kcontrol->private_value;
1021 if (ucontrol->value.enumerated.item[0] > 4)
1023 if (ucontrol->value.enumerated.item[0] == 0)
1026 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1027 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1028 7 << shift, val << shift, 0);
1031 static int snd_ac97_stac9758_input_jack_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1033 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1034 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1036 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1038 uinfo->value.enumerated.items = 7;
1039 if (uinfo->value.enumerated.item > 6)
1040 uinfo->value.enumerated.item = 6;
1041 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1045 static int snd_ac97_stac9758_input_jack_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1047 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1048 int shift = kcontrol->private_value;
1051 val = ac97->regs[AC97_SIGMATEL_INSEL];
1052 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1056 static int snd_ac97_stac9758_input_jack_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1058 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1059 int shift = kcontrol->private_value;
1061 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1062 ucontrol->value.enumerated.item[0] << shift, 0);
1065 static int snd_ac97_stac9758_phonesel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1067 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
1069 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1071 uinfo->value.enumerated.items = 3;
1072 if (uinfo->value.enumerated.item > 2)
1073 uinfo->value.enumerated.item = 2;
1074 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1078 static int snd_ac97_stac9758_phonesel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1080 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1082 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1086 static int snd_ac97_stac9758_phonesel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1088 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1090 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1091 ucontrol->value.enumerated.item[0], 0);
1094 #define STAC9758_OUTPUT_JACK(xname, shift) \
1095 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1096 .info = snd_ac97_stac9758_output_jack_info, \
1097 .get = snd_ac97_stac9758_output_jack_get, \
1098 .put = snd_ac97_stac9758_output_jack_put, \
1099 .private_value = shift }
1100 #define STAC9758_INPUT_JACK(xname, shift) \
1101 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1102 .info = snd_ac97_stac9758_input_jack_info, \
1103 .get = snd_ac97_stac9758_input_jack_get, \
1104 .put = snd_ac97_stac9758_input_jack_put, \
1105 .private_value = shift }
1106 static const snd_kcontrol_new_t snd_ac97_sigmatel_stac9758_controls[] = {
1107 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1108 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1109 STAC9758_OUTPUT_JACK("Front Jack", 7),
1110 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1111 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1112 STAC9758_INPUT_JACK("Mic Input Source", 0),
1113 STAC9758_INPUT_JACK("Line Input Source", 8),
1115 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1116 .name = "Headphone Amp",
1117 .info = snd_ac97_stac9758_phonesel_info,
1118 .get = snd_ac97_stac9758_phonesel_get,
1119 .put = snd_ac97_stac9758_phonesel_put
1121 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1122 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1125 static int patch_sigmatel_stac9758_specific(ac97_t *ac97)
1129 err = patch_sigmatel_stac97xx_specific(ac97);
1132 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1133 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1137 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1138 /* DAC-A to Mix = PCM */
1139 /* DAC-B direct = Surround */
1141 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1142 /* DAC-C direct = Center/LFE */
1147 static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1148 .build_3d = patch_sigmatel_stac9700_3d,
1149 .build_specific = patch_sigmatel_stac9758_specific
1152 int patch_sigmatel_stac9758(ac97_t * ac97)
1154 static unsigned short regs[4] = {
1155 AC97_SIGMATEL_OUTSEL,
1156 AC97_SIGMATEL_IOMISC,
1157 AC97_SIGMATEL_INSEL,
1158 AC97_SIGMATEL_VARIOUS
1160 static unsigned short def_regs[4] = {
1161 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1162 /* IOMISC */ 0x2001,
1163 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1164 /* VARIOUS */ 0x0040
1166 static unsigned short m675_regs[4] = {
1167 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1168 /* IOMISC */ 0x2102, /* HP amp on */
1169 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1170 /* VARIOUS */ 0x0041 /* stereo mic */
1172 unsigned short *pregs = def_regs;
1175 /* Gateway M675 notebook */
1177 ac97->subsystem_vendor == 0x107b &&
1178 ac97->subsystem_device == 0x0601)
1181 // patch for SigmaTel
1182 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1183 /* FIXME: assume only page 0 for writing cache */
1184 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1185 for (i = 0; i < 4; i++)
1186 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1188 ac97->flags |= AC97_STEREO_MUTES;
1193 * Cirrus Logic CS42xx codecs
1195 static const snd_kcontrol_new_t snd_ac97_cirrus_controls_spdif[2] = {
1196 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1197 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1200 static int patch_cirrus_build_spdif(ac97_t * ac97)
1204 /* con mask, pro mask, default */
1205 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1208 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1210 switch (ac97->id & AC97_ID_CS_MASK) {
1211 case AC97_ID_CS4205:
1212 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1216 /* set default PCM S/PDIF params */
1217 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1218 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1222 static struct snd_ac97_build_ops patch_cirrus_ops = {
1223 .build_spdif = patch_cirrus_build_spdif
1226 int patch_cirrus_spdif(ac97_t * ac97)
1228 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1229 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1230 - sp/dif EA ID is not set, but sp/dif is always present.
1231 - enable/disable is spdif register bit 15.
1232 - sp/dif control register is 0x68. differs from AC97:
1233 - valid is bit 14 (vs 15)
1235 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1236 - sp/dif ssource select is in 0x5e bits 0,1.
1239 ac97->build_ops = &patch_cirrus_ops;
1240 ac97->flags |= AC97_CS_SPDIF;
1241 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1242 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1243 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1247 int patch_cirrus_cs4299(ac97_t * ac97)
1249 /* force the detection of PC Beep */
1250 ac97->flags |= AC97_HAS_PC_BEEP;
1252 return patch_cirrus_spdif(ac97);
1258 static const snd_kcontrol_new_t snd_ac97_conexant_controls_spdif[1] = {
1259 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1262 static int patch_conexant_build_spdif(ac97_t * ac97)
1266 /* con mask, pro mask, default */
1267 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1270 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1272 /* set default PCM S/PDIF params */
1273 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1274 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1275 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1279 static struct snd_ac97_build_ops patch_conexant_ops = {
1280 .build_spdif = patch_conexant_build_spdif
1283 int patch_conexant(ac97_t * ac97)
1285 ac97->build_ops = &patch_conexant_ops;
1286 ac97->flags |= AC97_CX_SPDIF;
1287 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1288 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1293 * Analog Device AD18xx, AD19xx codecs
1296 static void ad18xx_resume(ac97_t *ac97)
1298 static unsigned short setup_regs[] = {
1299 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1303 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1304 unsigned short reg = setup_regs[i];
1305 if (test_bit(reg, ac97->reg_accessed)) {
1306 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1307 snd_ac97_read(ac97, reg);
1311 if (! (ac97->flags & AC97_AD_MULTI))
1312 /* normal restore */
1313 snd_ac97_restore_status(ac97);
1315 /* restore the AD18xx codec configurations */
1316 for (codec = 0; codec < 3; codec++) {
1317 if (! ac97->spec.ad18xx.id[codec])
1319 /* select single codec */
1320 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1321 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1322 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1324 /* select all codecs */
1325 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1327 /* restore status */
1328 for (i = 2; i < 0x7c ; i += 2) {
1329 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1331 if (test_bit(i, ac97->reg_accessed)) {
1332 /* handle multi codecs for AD18xx */
1333 if (i == AC97_PCM) {
1334 for (codec = 0; codec < 3; codec++) {
1335 if (! ac97->spec.ad18xx.id[codec])
1337 /* select single codec */
1338 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1339 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1340 /* update PCM bits */
1341 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1343 /* select all codecs */
1344 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1346 } else if (i == AC97_AD_TEST ||
1347 i == AC97_AD_CODEC_CFG ||
1348 i == AC97_AD_SERIAL_CFG)
1349 continue; /* ignore */
1351 snd_ac97_write(ac97, i, ac97->regs[i]);
1352 snd_ac97_read(ac97, i);
1356 snd_ac97_restore_iec958(ac97);
1360 int patch_ad1819(ac97_t * ac97)
1362 unsigned short scfg;
1364 // patch for Analog Devices
1365 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1366 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1370 static unsigned short patch_ad1881_unchained(ac97_t * ac97, int idx, unsigned short mask)
1374 // test for unchained codec
1375 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1376 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1377 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1378 if ((val & 0xff40) != 0x5340)
1380 ac97->spec.ad18xx.unchained[idx] = mask;
1381 ac97->spec.ad18xx.id[idx] = val;
1382 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1386 static int patch_ad1881_chained1(ac97_t * ac97, int idx, unsigned short codec_bits)
1388 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1391 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1392 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1393 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1394 if ((val & 0xff40) != 0x5340)
1397 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1398 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1399 ac97->spec.ad18xx.id[idx] = val;
1400 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1404 static void patch_ad1881_chained(ac97_t * ac97, int unchained_idx, int cidx1, int cidx2)
1406 // already detected?
1407 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1409 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1411 if (cidx1 < 0 && cidx2 < 0)
1413 // test for chained codecs
1414 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1415 ac97->spec.ad18xx.unchained[unchained_idx]);
1416 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1417 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1419 if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1420 patch_ad1881_chained1(ac97, cidx2, 0);
1421 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1422 patch_ad1881_chained1(ac97, cidx1, 0);
1423 } else if (cidx2 >= 0) {
1424 patch_ad1881_chained1(ac97, cidx2, 0);
1428 static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1430 .resume = ad18xx_resume
1434 int patch_ad1881(ac97_t * ac97)
1436 static const char cfg_idxs[3][2] = {
1442 // patch for Analog Devices
1443 unsigned short codecs[3];
1447 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1448 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1449 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1450 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1451 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1453 snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end);
1455 for (idx = 0; idx < 3; idx++)
1456 if (ac97->spec.ad18xx.unchained[idx])
1457 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1459 if (ac97->spec.ad18xx.id[1]) {
1460 ac97->flags |= AC97_AD_MULTI;
1461 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1463 if (ac97->spec.ad18xx.id[2]) {
1464 ac97->flags |= AC97_AD_MULTI;
1465 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1469 /* select all codecs */
1470 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1471 /* check if only one codec is present */
1472 for (idx = num = 0; idx < 3; idx++)
1473 if (ac97->spec.ad18xx.id[idx])
1476 /* ok, deselect all ID bits */
1477 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1478 ac97->spec.ad18xx.codec_cfg[0] =
1479 ac97->spec.ad18xx.codec_cfg[1] =
1480 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1482 /* required for AD1886/AD1885 combination */
1483 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1484 if (ac97->spec.ad18xx.id[0]) {
1485 ac97->id &= 0xffff0000;
1486 ac97->id |= ac97->spec.ad18xx.id[0];
1488 ac97->build_ops = &patch_ad1881_build_ops;
1492 static const snd_kcontrol_new_t snd_ac97_controls_ad1885[] = {
1493 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1494 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1495 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1496 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1497 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1498 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1501 static int patch_ad1885_specific(ac97_t * ac97)
1505 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1510 static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1511 .build_specific = &patch_ad1885_specific,
1513 .resume = ad18xx_resume
1517 int patch_ad1885(ac97_t * ac97)
1520 /* This is required to deal with the Intel D815EEAL2 */
1521 /* i.e. Line out is actually headphone out from codec */
1524 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1526 ac97->build_ops = &patch_ad1885_build_ops;
1530 int patch_ad1886(ac97_t * ac97)
1533 /* Presario700 workaround */
1534 /* for Jack Sense/SPDIF Register misetting causing */
1535 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
1540 #define AC97_AD198X_MBC 0x0003 /* mic boost */
1541 #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1542 #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1543 #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1544 #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1545 #define AC97_AD198X_VREFH 0x0008 /* 2.25V, 3.7V */
1546 #define AC97_AD198X_VREF_0 0x000c /* 0V */
1547 #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1548 #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1549 #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1550 #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1551 #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: 0 = 6-to-4, 1 = 6-to-2 downmix */
1552 #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1553 #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1554 #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1555 #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1556 #define AC97_AD198X_MSPLT 0x2000 /* mute split */
1557 #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1558 #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1561 static int snd_ac97_ad198x_spdif_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1563 static char *texts[2] = { "AC-Link", "A/D Converter" };
1565 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1567 uinfo->value.enumerated.items = 2;
1568 if (uinfo->value.enumerated.item > 1)
1569 uinfo->value.enumerated.item = 1;
1570 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1574 static int snd_ac97_ad198x_spdif_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1576 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1579 val = ac97->regs[AC97_AD_SERIAL_CFG];
1580 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1584 static int snd_ac97_ad198x_spdif_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1586 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1589 if (ucontrol->value.enumerated.item[0] > 1)
1591 val = ucontrol->value.enumerated.item[0] << 2;
1592 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1595 static const snd_kcontrol_new_t snd_ac97_ad198x_spdif_source = {
1596 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1597 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1598 .info = snd_ac97_ad198x_spdif_source_info,
1599 .get = snd_ac97_ad198x_spdif_source_get,
1600 .put = snd_ac97_ad198x_spdif_source_put,
1603 static int patch_ad198x_post_spdif(ac97_t * ac97)
1605 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1608 static const snd_kcontrol_new_t snd_ac97_ad1981x_jack_sense[] = {
1609 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1610 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1613 static int patch_ad1981a_specific(ac97_t * ac97)
1615 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1616 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1619 static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1620 .build_post_spdif = patch_ad198x_post_spdif,
1621 .build_specific = patch_ad1981a_specific,
1623 .resume = ad18xx_resume
1627 static void check_ad1981_hp_jack_sense(ac97_t *ac97)
1629 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1631 case 0x103c0890: /* HP nc6000 */
1632 case 0x103c099c: /* HP nx6110 */
1633 case 0x103c006d: /* HP nx9105 */
1634 case 0x17340088: /* FSC Scenic-W */
1635 /* enable headphone jack sense */
1636 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
1641 int patch_ad1981a(ac97_t *ac97)
1644 ac97->build_ops = &patch_ad1981a_build_ops;
1645 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1646 ac97->flags |= AC97_STEREO_MUTES;
1647 check_ad1981_hp_jack_sense(ac97);
1651 static const snd_kcontrol_new_t snd_ac97_ad198x_2cmic =
1652 AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1654 static int patch_ad1981b_specific(ac97_t *ac97)
1658 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1660 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1661 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1664 static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1665 .build_post_spdif = patch_ad198x_post_spdif,
1666 .build_specific = patch_ad1981b_specific,
1668 .resume = ad18xx_resume
1672 int patch_ad1981b(ac97_t *ac97)
1675 ac97->build_ops = &patch_ad1981b_build_ops;
1676 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1677 ac97->flags |= AC97_STEREO_MUTES;
1678 check_ad1981_hp_jack_sense(ac97);
1682 static int snd_ac97_ad1888_lohpsel_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1684 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1686 uinfo->value.integer.min = 0;
1687 uinfo->value.integer.max = 1;
1691 static int snd_ac97_ad1888_lohpsel_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1693 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1696 val = ac97->regs[AC97_AD_MISC];
1697 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1701 static int snd_ac97_ad1888_lohpsel_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1703 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1706 val = !ucontrol->value.integer.value[0]
1707 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1708 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1709 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1712 static int snd_ac97_ad1888_downmix_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
1714 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1716 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1718 uinfo->value.enumerated.items = 3;
1719 if (uinfo->value.enumerated.item > 2)
1720 uinfo->value.enumerated.item = 2;
1721 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1725 static int snd_ac97_ad1888_downmix_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t* ucontrol)
1727 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1730 val = ac97->regs[AC97_AD_MISC];
1731 if (!(val & AC97_AD198X_DMIX1))
1732 ucontrol->value.enumerated.item[0] = 0;
1734 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1738 static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1740 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
1743 if (ucontrol->value.enumerated.item[0] > 2)
1745 if (ucontrol->value.enumerated.item[0] == 0)
1748 val = AC97_AD198X_DMIX1 |
1749 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1750 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1751 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1754 static void ad1888_update_jacks(ac97_t *ac97)
1756 /* shared Line-In */
1757 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12,
1758 is_shared_linein(ac97) ? 0 : 1 << 12);
1760 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
1761 is_shared_micin(ac97) ? 0 : 1 << 11);
1764 static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = {
1766 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1767 .name = "Exchange Front/Surround",
1768 .info = snd_ac97_ad1888_lohpsel_info,
1769 .get = snd_ac97_ad1888_lohpsel_get,
1770 .put = snd_ac97_ad1888_lohpsel_put
1772 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1774 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1776 .info = snd_ac97_ad1888_downmix_info,
1777 .get = snd_ac97_ad1888_downmix_get,
1778 .put = snd_ac97_ad1888_downmix_put
1780 AC97_SURROUND_JACK_MODE_CTL,
1781 AC97_CHANNEL_MODE_CTL,
1783 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1784 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1787 static int patch_ad1888_specific(ac97_t *ac97)
1789 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
1790 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
1791 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
1792 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
1795 static struct snd_ac97_build_ops patch_ad1888_build_ops = {
1796 .build_post_spdif = patch_ad198x_post_spdif,
1797 .build_specific = patch_ad1888_specific,
1799 .resume = ad18xx_resume,
1801 .update_jacks = ad1888_update_jacks,
1804 int patch_ad1888(ac97_t * ac97)
1806 unsigned short misc;
1809 ac97->build_ops = &patch_ad1888_build_ops;
1810 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
1811 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
1812 /* AD-compatible mode */
1813 /* Stereo mutes enabled */
1814 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1815 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1819 AC97_AD198X_AC97NC);
1820 ac97->flags |= AC97_STEREO_MUTES;
1824 static int patch_ad1980_specific(ac97_t *ac97)
1828 if ((err = patch_ad1888_specific(ac97)) < 0)
1830 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
1833 static struct snd_ac97_build_ops patch_ad1980_build_ops = {
1834 .build_post_spdif = patch_ad198x_post_spdif,
1835 .build_specific = patch_ad1980_specific,
1837 .resume = ad18xx_resume,
1839 .update_jacks = ad1888_update_jacks,
1842 int patch_ad1980(ac97_t * ac97)
1845 ac97->build_ops = &patch_ad1980_build_ops;
1849 static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = {
1850 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0)
1853 static void ad1985_update_jacks(ac97_t *ac97)
1855 /* shared Line-In */
1856 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12,
1857 is_shared_linein(ac97) ? 0 : 1 << 12);
1859 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
1860 is_shared_micin(ac97) ? 0 : 1 << 11);
1861 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1862 is_shared_micin(ac97) ? 0 : 1 << 9);
1865 static int patch_ad1985_specific(ac97_t *ac97)
1869 if ((err = patch_ad1980_specific(ac97)) < 0)
1871 return patch_build_controls(ac97, snd_ac97_ad1985_controls, ARRAY_SIZE(snd_ac97_ad1985_controls));
1874 static struct snd_ac97_build_ops patch_ad1985_build_ops = {
1875 .build_post_spdif = patch_ad198x_post_spdif,
1876 .build_specific = patch_ad1985_specific,
1878 .resume = ad18xx_resume,
1880 .update_jacks = ad1985_update_jacks,
1883 int patch_ad1985(ac97_t * ac97)
1885 unsigned short misc;
1888 ac97->build_ops = &patch_ad1985_build_ops;
1889 misc = snd_ac97_read(ac97, AC97_AD_MISC);
1890 /* switch front/surround line-out/hp-out */
1891 /* center/LFE, mic in 3.75V mode */
1892 /* AD-compatible mode */
1893 /* Stereo mutes enabled */
1894 /* in accordance with ADI driver: misc | 0x5c28 */
1895 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
1902 AC97_AD198X_AC97NC);
1903 ac97->flags |= AC97_STEREO_MUTES;
1904 /* on AD1985 rev. 3, AC'97 revision bits are zero */
1905 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
1910 * realtek ALC65x/850 codecs
1912 static void alc650_update_jacks(ac97_t *ac97)
1916 /* shared Line-In */
1917 shared = is_shared_linein(ac97);
1918 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
1919 shared ? (1 << 9) : 0);
1920 /* update shared Mic */
1921 shared = is_shared_micin(ac97);
1922 /* disable/enable vref */
1923 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
1924 shared ? (1 << 12) : 0);
1925 /* turn on/off center-on-mic */
1926 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
1927 shared ? (1 << 10) : 0);
1928 /* GPIO0 high for mic */
1929 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
1930 shared ? 0 : 0x100);
1933 static const snd_kcontrol_new_t snd_ac97_controls_alc650[] = {
1934 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
1935 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
1936 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
1937 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
1938 /* 4: Analog Input To Surround */
1939 /* 5: Analog Input To Center/LFE */
1940 /* 6: Independent Master Volume Right */
1941 /* 7: Independent Master Volume Left */
1943 /* 9: Line-In/Surround share */
1944 /* 10: Mic/CLFE share */
1945 /* 11-13: in IEC958 controls */
1946 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
1947 #if 0 /* always set in patch_alc650 */
1948 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
1949 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
1950 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
1951 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
1952 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
1953 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
1955 AC97_SURROUND_JACK_MODE_CTL,
1956 AC97_CHANNEL_MODE_CTL,
1959 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc650[] = {
1960 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
1961 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
1962 /* disable this controls since it doesn't work as expected */
1963 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
1966 static int patch_alc650_specific(ac97_t * ac97)
1970 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
1972 if (ac97->ext_id & AC97_EI_SPDIF) {
1973 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
1979 static struct snd_ac97_build_ops patch_alc650_ops = {
1980 .build_specific = patch_alc650_specific,
1981 .update_jacks = alc650_update_jacks
1984 int patch_alc650(ac97_t * ac97)
1988 ac97->build_ops = &patch_alc650_ops;
1990 /* determine the revision */
1991 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
1993 ac97->id = 0x414c4720; /* Old version */
1994 else if (val < 0x10)
1995 ac97->id = 0x414c4721; /* D version */
1996 else if (val < 0x20)
1997 ac97->id = 0x414c4722; /* E version */
1998 else if (val < 0x30)
1999 ac97->id = 0x414c4723; /* F version */
2001 /* revision E or F */
2002 /* FIXME: what about revision D ? */
2003 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2004 ac97->id == 0x414c4723);
2006 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2007 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2008 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2010 /* Enable SPDIF-IN only on Rev.E and above */
2011 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2012 /* SPDIF IN with pin 47 */
2013 if (ac97->spec.dev_flags)
2014 val |= 0x03; /* enable */
2016 val &= ~0x03; /* disable */
2017 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2019 /* set default: slot 3,4,7,8,6,9
2020 spdif-in monitor off, analog-spdif off, spdif-in off
2021 center on mic off, surround on line-in off
2022 downmix off, duplicate front off
2024 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2026 /* set GPIO0 for mic bias */
2027 /* GPIO0 pin output, no interrupt, high */
2028 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2029 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2030 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2031 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2033 /* full DAC volume */
2034 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2035 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2039 static void alc655_update_jacks(ac97_t *ac97)
2043 /* shared Line-In */
2044 shared = is_shared_linein(ac97);
2045 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2046 shared ? (1 << 9) : 0, 0);
2047 /* update shared mic */
2048 shared = is_shared_micin(ac97);
2049 /* misc control; vrefout disable */
2050 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2051 shared ? (1 << 12) : 0);
2052 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2053 shared ? (1 << 10) : 0, 0);
2056 static const snd_kcontrol_new_t snd_ac97_controls_alc655[] = {
2057 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2058 AC97_SURROUND_JACK_MODE_CTL,
2059 AC97_CHANNEL_MODE_CTL,
2062 static int alc655_iec958_route_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
2064 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2065 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
2066 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2068 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2070 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2071 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2072 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2073 strcpy(uinfo->value.enumerated.name,
2074 ac97->spec.dev_flags ?
2075 texts_658[uinfo->value.enumerated.item] :
2076 texts_655[uinfo->value.enumerated.item]);
2080 static int alc655_iec958_route_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2082 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2085 val = ac97->regs[AC97_ALC650_MULTICH];
2086 val = (val >> 12) & 3;
2087 if (ac97->spec.dev_flags && val == 3)
2089 ucontrol->value.enumerated.item[0] = val;
2093 static int alc655_iec958_route_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2095 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2097 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2098 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2102 static const snd_kcontrol_new_t snd_ac97_spdif_controls_alc655[] = {
2103 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
2104 /* disable this controls since it doesn't work as expected */
2105 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2108 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
2109 .info = alc655_iec958_route_info,
2110 .get = alc655_iec958_route_get,
2111 .put = alc655_iec958_route_put,
2115 static int patch_alc655_specific(ac97_t * ac97)
2119 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2121 if (ac97->ext_id & AC97_EI_SPDIF) {
2122 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2128 static struct snd_ac97_build_ops patch_alc655_ops = {
2129 .build_specific = patch_alc655_specific,
2130 .update_jacks = alc655_update_jacks
2133 int patch_alc655(ac97_t * ac97)
2137 if (ac97->id == AC97_ID_ALC658) {
2138 ac97->spec.dev_flags = 1; /* ALC658 */
2139 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2140 ac97->id = AC97_ID_ALC658D;
2141 ac97->spec.dev_flags = 2;
2145 ac97->build_ops = &patch_alc655_ops;
2147 /* assume only page 0 for writing cache */
2148 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2150 /* adjust default values */
2151 val = snd_ac97_read(ac97, 0x7a); /* misc control */
2152 if (ac97->spec.dev_flags) /* ALC658 */
2153 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
2155 if (ac97->subsystem_vendor == 0x1462 &&
2156 ac97->subsystem_device == 0x0131) /* MSI S270 laptop */
2157 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2159 val |= (1 << 1); /* Pin 47 is spdif input pin */
2161 val &= ~(1 << 12); /* vref enable */
2162 snd_ac97_write_cache(ac97, 0x7a, val);
2163 /* set default: spdif-in enabled,
2164 spdif-in monitor off, spdif-in PCM off
2165 center on mic off, surround on line-in off
2168 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2170 /* full DAC volume */
2171 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2172 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2174 /* update undocumented bit... */
2175 if (ac97->id == AC97_ID_ALC658D)
2176 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2182 #define AC97_ALC850_JACK_SELECT 0x76
2183 #define AC97_ALC850_MISC1 0x7a
2185 static void alc850_update_jacks(ac97_t *ac97)
2189 /* shared Line-In */
2190 shared = is_shared_linein(ac97);
2191 /* SURR 1kOhm (bit4), Amp (bit5) */
2192 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
2193 shared ? (1<<5) : (1<<4));
2194 /* LINE-IN = 0, SURROUND = 2 */
2195 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2196 shared ? (2<<12) : (0<<12));
2197 /* update shared mic */
2198 shared = is_shared_micin(ac97);
2199 /* Vref disable (bit12), 1kOhm (bit13) */
2200 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
2201 shared ? (1<<12) : (1<<13));
2202 /* MIC-IN = 1, CENTER-LFE = 2 */
2203 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2204 shared ? (2<<4) : (1<<4));
2207 static const snd_kcontrol_new_t snd_ac97_controls_alc850[] = {
2208 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2209 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2210 AC97_SURROUND_JACK_MODE_CTL,
2211 AC97_CHANNEL_MODE_CTL,
2214 static int patch_alc850_specific(ac97_t *ac97)
2218 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2220 if (ac97->ext_id & AC97_EI_SPDIF) {
2221 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2227 static struct snd_ac97_build_ops patch_alc850_ops = {
2228 .build_specific = patch_alc850_specific,
2229 .update_jacks = alc850_update_jacks
2232 int patch_alc850(ac97_t *ac97)
2234 ac97->build_ops = &patch_alc850_ops;
2236 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2238 /* assume only page 0 for writing cache */
2239 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2241 /* adjust default values */
2242 /* set default: spdif-in enabled,
2243 spdif-in monitor off, spdif-in PCM off
2244 center on mic off, surround on line-in off
2247 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2248 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2249 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2251 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2252 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2253 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2254 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2256 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2257 (1<<11)|(0<<12)|(1<<15));
2259 /* full DAC volume */
2260 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2261 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2267 * C-Media CM97xx codecs
2269 static void cm9738_update_jacks(ac97_t *ac97)
2271 /* shared Line-In */
2272 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2273 is_shared_linein(ac97) ? (1 << 10) : 0);
2276 static const snd_kcontrol_new_t snd_ac97_cm9738_controls[] = {
2277 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
2278 AC97_SURROUND_JACK_MODE_CTL,
2279 AC97_CHANNEL_MODE_4CH_CTL,
2282 static int patch_cm9738_specific(ac97_t * ac97)
2284 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2287 static struct snd_ac97_build_ops patch_cm9738_ops = {
2288 .build_specific = patch_cm9738_specific,
2289 .update_jacks = cm9738_update_jacks
2292 int patch_cm9738(ac97_t * ac97)
2294 ac97->build_ops = &patch_cm9738_ops;
2295 /* FIXME: can anyone confirm below? */
2296 /* CM9738 has no PCM volume although the register reacts */
2297 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2298 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2303 static int snd_ac97_cmedia_spdif_playback_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2305 static char *texts[] = { "Analog", "Digital" };
2307 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2309 uinfo->value.enumerated.items = 2;
2310 if (uinfo->value.enumerated.item > 1)
2311 uinfo->value.enumerated.item = 1;
2312 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2316 static int snd_ac97_cmedia_spdif_playback_source_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2318 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2321 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2322 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2326 static int snd_ac97_cmedia_spdif_playback_source_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2328 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2330 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2332 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2335 static const snd_kcontrol_new_t snd_ac97_cm9739_controls_spdif[] = {
2336 /* BIT 0: SPDI_EN - always true */
2337 { /* BIT 1: SPDIFS */
2338 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2339 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2340 .info = snd_ac97_cmedia_spdif_playback_source_info,
2341 .get = snd_ac97_cmedia_spdif_playback_source_get,
2342 .put = snd_ac97_cmedia_spdif_playback_source_put,
2344 /* BIT 2: IG_SPIV */
2345 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2347 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2348 /* BIT 4: SPI2SDI */
2349 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2350 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2353 static void cm9739_update_jacks(ac97_t *ac97)
2355 /* shared Line-In */
2356 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2357 is_shared_linein(ac97) ? (1 << 10) : 0);
2359 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2360 is_shared_micin(ac97) ? 0x1000 : 0x2000);
2363 static const snd_kcontrol_new_t snd_ac97_cm9739_controls[] = {
2364 AC97_SURROUND_JACK_MODE_CTL,
2365 AC97_CHANNEL_MODE_CTL,
2368 static int patch_cm9739_specific(ac97_t * ac97)
2370 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2373 static int patch_cm9739_post_spdif(ac97_t * ac97)
2375 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2378 static struct snd_ac97_build_ops patch_cm9739_ops = {
2379 .build_specific = patch_cm9739_specific,
2380 .build_post_spdif = patch_cm9739_post_spdif,
2381 .update_jacks = cm9739_update_jacks
2384 int patch_cm9739(ac97_t * ac97)
2388 ac97->build_ops = &patch_cm9739_ops;
2390 /* CM9739/A has no Master and PCM volume although the register reacts */
2391 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2392 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2393 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2396 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2397 if (val & AC97_EA_SPCV) {
2398 /* enable spdif in */
2399 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2400 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2401 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2403 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2404 ac97->rates[AC97_RATES_SPDIF] = 0;
2407 /* set-up multi channel */
2408 /* bit 14: 0 = SPDIF, 1 = EAPD */
2409 /* bit 13: enable internal vref output for mic */
2410 /* bit 12: disable center/lfe (swithable) */
2411 /* bit 10: disable surround/line (switchable) */
2412 /* bit 9: mix 2 surround off */
2413 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2414 /* bit 3: undocumented; surround? */
2416 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
2419 if (! (ac97->ext_id & AC97_EI_SPDIF))
2421 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
2423 /* FIXME: set up GPIO */
2424 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2425 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2426 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
2428 ac97->subsystem_vendor == 0x1043 &&
2429 ac97->subsystem_device == 0x1843) {
2430 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2431 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
2432 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
2433 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
2439 #define AC97_CM9761_MULTI_CHAN 0x64
2440 #define AC97_CM9761_FUNC 0x66
2441 #define AC97_CM9761_SPDIF_CTRL 0x6c
2443 static void cm9761_update_jacks(ac97_t *ac97)
2445 unsigned short surr_vals[2][2] = {
2446 { 0x0008, 0x0400 }, /* off, on */
2447 { 0x0000, 0x0408 }, /* off, on (9761-82 rev.B) */
2449 unsigned short clfe_vals[2][2] = {
2450 { 0x2000, 0x1880 }, /* off, on */
2451 { 0x1000, 0x2880 }, /* off, on (9761-82 rev.B) */
2454 /* shared Line-In */
2455 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x0408,
2456 surr_vals[ac97->spec.dev_flags][is_shared_linein(ac97)]);
2458 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3880,
2459 clfe_vals[ac97->spec.dev_flags][is_shared_micin(ac97)]);
2462 static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = {
2463 AC97_SURROUND_JACK_MODE_CTL,
2464 AC97_CHANNEL_MODE_CTL,
2467 static int cm9761_spdif_out_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
2469 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
2471 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2473 uinfo->value.enumerated.items = 3;
2474 if (uinfo->value.enumerated.item > 2)
2475 uinfo->value.enumerated.item = 2;
2476 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2480 static int cm9761_spdif_out_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2482 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2484 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
2485 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
2486 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
2487 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
2489 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
2493 static int cm9761_spdif_out_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
2495 ac97_t *ac97 = snd_kcontrol_chip(kcontrol);
2497 if (ucontrol->value.enumerated.item[0] == 2)
2498 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
2499 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
2500 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
2501 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
2504 static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
2505 static const struct ac97_enum cm9761_dac_clock_enum =
2506 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
2508 static const snd_kcontrol_new_t snd_ac97_cm9761_controls_spdif[] = {
2509 { /* BIT 1: SPDIFS */
2510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2511 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2512 .info = cm9761_spdif_out_source_info,
2513 .get = cm9761_spdif_out_source_get,
2514 .put = cm9761_spdif_out_source_put,
2516 /* BIT 2: IG_SPIV */
2517 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
2519 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
2520 /* BIT 4: SPI2SDI */
2521 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
2522 /* BIT 9-10: DAC_CTL */
2523 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
2526 static int patch_cm9761_post_spdif(ac97_t * ac97)
2528 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
2531 static int patch_cm9761_specific(ac97_t * ac97)
2533 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
2536 static struct snd_ac97_build_ops patch_cm9761_ops = {
2537 .build_specific = patch_cm9761_specific,
2538 .build_post_spdif = patch_cm9761_post_spdif,
2539 .update_jacks = cm9761_update_jacks
2542 int patch_cm9761(ac97_t *ac97)
2546 /* CM9761 has no PCM volume although the register reacts */
2547 /* Master volume seems to have _some_ influence on the analog
2550 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
2551 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2552 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2554 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B */
2555 if (ac97->id == AC97_ID_CM9761_82) {
2557 /* check page 1, reg 0x60 */
2558 val = snd_ac97_read(ac97, AC97_INT_PAGING);
2559 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
2560 tmp = snd_ac97_read(ac97, 0x60);
2561 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2562 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
2565 ac97->build_ops = &patch_cm9761_ops;
2568 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
2569 ac97->ext_id |= AC97_EI_SPDIF;
2570 /* to be sure: we overwrite the ext status bits */
2571 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
2572 /* Don't set 0x0200 here. This results in the silent analog output */
2573 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
2574 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2576 /* set-up multi channel */
2577 /* bit 15: pc master beep off
2578 * bit 14: pin47 = EAPD/SPDIF
2579 * bit 13: vref ctl [= cm9739]
2580 * bit 12: CLFE control (reverted on rev B)
2581 * bit 11: Mic/center share (reverted on rev B)
2582 * bit 10: suddound/line share
2583 * bit 9: Analog-in mix -> surround
2584 * bit 8: Analog-in mix -> CLFE
2585 * bit 7: Mic/LFE share (mic/center/lfe)
2586 * bit 5: vref select (9761A)
2587 * bit 4: front control
2588 * bit 3: surround control (revereted with rev B)
2591 * bit 0: mic boost level (0=20dB, 1=30dB)
2595 if (ac97->spec.dev_flags)
2600 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
2601 val |= (1 << 4); /* front on */
2602 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
2604 /* FIXME: set up GPIO */
2605 snd_ac97_write_cache(ac97, 0x70, 0x0100);
2606 snd_ac97_write_cache(ac97, 0x72, 0x0020);
2611 #define AC97_CM9780_SIDE 0x60
2612 #define AC97_CM9780_JACK 0x62
2613 #define AC97_CM9780_MIXER 0x64
2614 #define AC97_CM9780_MULTI_CHAN 0x66
2615 #define AC97_CM9780_SPDIF 0x6c
2617 static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
2618 static const struct ac97_enum cm9780_ch_select_enum =
2619 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
2620 static const snd_kcontrol_new_t cm9780_controls[] = {
2621 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
2622 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
2623 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
2626 static int patch_cm9780_specific(ac97_t *ac97)
2628 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
2631 static struct snd_ac97_build_ops patch_cm9780_ops = {
2632 .build_specific = patch_cm9780_specific,
2633 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
2636 int patch_cm9780(ac97_t *ac97)
2640 ac97->build_ops = &patch_cm9780_ops;
2643 if (ac97->ext_id & AC97_EI_SPDIF) {
2644 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2645 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
2646 val |= 0x1; /* SPDI_EN */
2647 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
2656 static const snd_kcontrol_new_t snd_ac97_controls_vt1616[] = {
2657 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
2658 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
2659 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
2660 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
2663 static int patch_vt1616_specific(ac97_t * ac97)
2667 if (snd_ac97_try_bit(ac97, 0x5a, 9))
2668 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
2670 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
2675 static struct snd_ac97_build_ops patch_vt1616_ops = {
2676 .build_specific = patch_vt1616_specific
2679 int patch_vt1616(ac97_t * ac97)
2681 ac97->build_ops = &patch_vt1616_ops;
2688 int patch_vt1617a(ac97_t * ac97)
2690 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
2691 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
2697 static void it2646_update_jacks(ac97_t *ac97)
2699 /* shared Line-In */
2700 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
2701 is_shared_linein(ac97) ? (1<<9) : 0);
2703 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
2704 is_shared_micin(ac97) ? (1<<10) : 0);
2707 static const snd_kcontrol_new_t snd_ac97_controls_it2646[] = {
2708 AC97_SURROUND_JACK_MODE_CTL,
2709 AC97_CHANNEL_MODE_CTL,
2712 static const snd_kcontrol_new_t snd_ac97_spdif_controls_it2646[] = {
2713 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
2714 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
2715 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
2718 static int patch_it2646_specific(ac97_t * ac97)
2721 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
2723 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
2728 static struct snd_ac97_build_ops patch_it2646_ops = {
2729 .build_specific = patch_it2646_specific,
2730 .update_jacks = it2646_update_jacks
2733 int patch_it2646(ac97_t * ac97)
2735 ac97->build_ops = &patch_it2646_ops;
2736 /* full DAC volume */
2737 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
2738 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
2746 #define AC97_SI3036_CHIP_ID 0x5a
2747 #define AC97_SI3036_LINE_CFG 0x5c
2749 static const snd_kcontrol_new_t snd_ac97_controls_si3036[] = {
2750 AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
2753 static int patch_si3036_specific(ac97_t * ac97)
2756 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
2757 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
2762 static struct snd_ac97_build_ops patch_si3036_ops = {
2763 .build_specific = patch_si3036_specific,
2766 int mpatch_si3036(ac97_t * ac97)
2768 ac97->build_ops = &patch_si3036_ops;
2769 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
2770 snd_ac97_write_cache(ac97, 0x68, 0);