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 "ac97_local.h"
27 #include "ac97_patch.h"
30 * Chip specific initialization
33 static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count)
37 for (idx = 0; idx < count; idx++)
38 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0)
43 /* replace with a new TLV */
44 static void reset_tlv(struct snd_ac97 *ac97, const char *name,
45 const unsigned int *tlv)
47 struct snd_ctl_elem_id sid;
48 struct snd_kcontrol *kctl;
49 memset(&sid, 0, sizeof(sid));
50 strcpy(sid.name, name);
51 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
52 kctl = snd_ctl_find_id(ac97->bus->card, &sid);
53 if (kctl && kctl->tlv.p)
57 /* set to the page, update bits and restore the page */
58 static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page)
60 unsigned short page_save;
63 mutex_lock(&ac97->page_mutex);
64 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
65 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
66 ret = snd_ac97_update_bits(ac97, reg, mask, value);
67 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
68 mutex_unlock(&ac97->page_mutex); /* unlock paging */
73 * shared line-in/mic controls
75 static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo,
76 const char **texts, unsigned int nums)
78 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
80 uinfo->value.enumerated.items = nums;
81 if (uinfo->value.enumerated.item > nums - 1)
82 uinfo->value.enumerated.item = nums - 1;
83 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
87 static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
89 static const char *texts[] = { "Shared", "Independent" };
90 return ac97_enum_text_info(kcontrol, uinfo, texts, 2);
93 static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
95 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
97 ucontrol->value.enumerated.item[0] = ac97->indep_surround;
101 static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
103 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
104 unsigned char indep = !!ucontrol->value.enumerated.item[0];
106 if (indep != ac97->indep_surround) {
107 ac97->indep_surround = indep;
108 if (ac97->build_ops->update_jacks)
109 ac97->build_ops->update_jacks(ac97);
115 static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
117 static const char *texts[] = { "2ch", "4ch", "6ch" };
118 if (kcontrol->private_value)
119 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
120 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
123 static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
125 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
127 ucontrol->value.enumerated.item[0] = ac97->channel_mode;
131 static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
133 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
134 unsigned char mode = ucontrol->value.enumerated.item[0];
136 if (mode != ac97->channel_mode) {
137 ac97->channel_mode = mode;
138 if (ac97->build_ops->update_jacks)
139 ac97->build_ops->update_jacks(ac97);
145 #define AC97_SURROUND_JACK_MODE_CTL \
147 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
148 .name = "Surround Jack Mode", \
149 .info = ac97_surround_jack_mode_info, \
150 .get = ac97_surround_jack_mode_get, \
151 .put = ac97_surround_jack_mode_put, \
153 #define AC97_CHANNEL_MODE_CTL \
155 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
156 .name = "Channel Mode", \
157 .info = ac97_channel_mode_info, \
158 .get = ac97_channel_mode_get, \
159 .put = ac97_channel_mode_put, \
161 #define AC97_CHANNEL_MODE_4CH_CTL \
163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
164 .name = "Channel Mode", \
165 .info = ac97_channel_mode_info, \
166 .get = ac97_channel_mode_get, \
167 .put = ac97_channel_mode_put, \
168 .private_value = 1, \
171 static inline int is_surround_on(struct snd_ac97 *ac97)
173 return ac97->channel_mode >= 1;
176 static inline int is_clfe_on(struct snd_ac97 *ac97)
178 return ac97->channel_mode >= 2;
181 /* system has shared jacks with surround out enabled */
182 static inline int is_shared_surrout(struct snd_ac97 *ac97)
184 return !ac97->indep_surround && is_surround_on(ac97);
187 /* system has shared jacks with center/lfe out enabled */
188 static inline int is_shared_clfeout(struct snd_ac97 *ac97)
190 return !ac97->indep_surround && is_clfe_on(ac97);
193 /* system has shared jacks with line in enabled */
194 static inline int is_shared_linein(struct snd_ac97 *ac97)
196 return !ac97->indep_surround && !is_surround_on(ac97);
199 /* system has shared jacks with mic in enabled */
200 static inline int is_shared_micin(struct snd_ac97 *ac97)
202 return !ac97->indep_surround && !is_clfe_on(ac97);
206 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
208 /* It is possible to indicate to the Yamaha YMF7x3 the type of
209 speakers being used. */
211 static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
212 struct snd_ctl_elem_info *uinfo)
214 static char *texts[3] = {
215 "Standard", "Small", "Smaller"
218 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
220 uinfo->value.enumerated.items = 3;
221 if (uinfo->value.enumerated.item > 2)
222 uinfo->value.enumerated.item = 2;
223 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
227 static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol)
230 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
233 val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL];
234 val = (val >> 10) & 3;
235 if (val > 0) /* 0 = invalid */
237 ucontrol->value.enumerated.item[0] = val;
241 static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol,
242 struct snd_ctl_elem_value *ucontrol)
244 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
247 if (ucontrol->value.enumerated.item[0] > 2)
249 val = (ucontrol->value.enumerated.item[0] + 1) << 10;
250 return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);
253 static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
256 .name = "3D Control - Speaker",
257 .info = snd_ac97_ymf7x3_info_speaker,
258 .get = snd_ac97_ymf7x3_get_speaker,
259 .put = snd_ac97_ymf7x3_put_speaker,
262 /* It is possible to indicate to the Yamaha YMF7x3 the source to
263 direct to the S/PDIF output. */
264 static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_info *uinfo)
267 static char *texts[2] = { "AC-Link", "A/D Converter" };
269 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
271 uinfo->value.enumerated.items = 2;
272 if (uinfo->value.enumerated.item > 1)
273 uinfo->value.enumerated.item = 1;
274 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
278 static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
279 struct snd_ctl_elem_value *ucontrol)
281 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
284 val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
285 ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
289 static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol,
290 struct snd_ctl_elem_value *ucontrol)
292 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
295 if (ucontrol->value.enumerated.item[0] > 1)
297 val = ucontrol->value.enumerated.item[0] << 1;
298 return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);
301 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
302 The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48.
303 By default, no output pin is selected, and the S/PDIF signal is not output.
304 There is also a bit to mute S/PDIF output in a vendor-specific register. */
305 static int snd_ac97_ymf753_spdif_output_pin_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
307 static char *texts[3] = { "Disabled", "Pin 43", "Pin 48" };
309 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
311 uinfo->value.enumerated.items = 3;
312 if (uinfo->value.enumerated.item > 2)
313 uinfo->value.enumerated.item = 2;
314 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
318 static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
320 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
323 val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
324 ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
328 static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
330 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
333 if (ucontrol->value.enumerated.item[0] > 2)
335 val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
336 (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
337 return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val);
338 /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
339 snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
342 static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
344 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
345 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
346 .info = snd_ac97_ymf7x3_spdif_source_info,
347 .get = snd_ac97_ymf7x3_spdif_source_get,
348 .put = snd_ac97_ymf7x3_spdif_source_put,
351 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
352 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Output Pin",
353 .info = snd_ac97_ymf753_spdif_output_pin_info,
354 .get = snd_ac97_ymf753_spdif_output_pin_get,
355 .put = snd_ac97_ymf753_spdif_output_pin_put,
357 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
358 AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
361 static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97)
363 struct snd_kcontrol *kctl;
366 kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
367 err = snd_ctl_add(ac97->bus->card, kctl);
370 strcpy(kctl->id.name, "3D Control - Wide");
371 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
372 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
374 err = snd_ctl_add(ac97->bus->card,
375 snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker,
379 snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00);
383 static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
387 if ((err = patch_build_controls(ac97, snd_ac97_ymf753_controls_spdif, ARRAY_SIZE(snd_ac97_ymf753_controls_spdif))) < 0)
392 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
393 .build_3d = patch_yamaha_ymf7x3_3d,
394 .build_post_spdif = patch_yamaha_ymf753_post_spdif
397 static int patch_yamaha_ymf753(struct snd_ac97 * ac97)
399 /* Patch for Yamaha YMF753, Copyright (c) by David Shust, dshust@shustring.com.
400 This chip has nonstandard and extended behaviour with regard to its S/PDIF output.
401 The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
402 The YMF753 will ouput the S/PDIF signal to pin 43, 47 (EAPD), or 48.
403 By default, no output pin is selected, and the S/PDIF signal is not output.
404 There is also a bit to mute S/PDIF output in a vendor-specific register.
406 ac97->build_ops = &patch_yamaha_ymf753_ops;
407 ac97->caps |= AC97_BC_BASS_TREBLE;
408 ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
413 * May 2, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
414 * removed broken wolfson00 patch.
415 * added support for WM9705,WM9708,WM9709,WM9710,WM9711,WM9712 and WM9717.
418 static const struct snd_kcontrol_new wm97xx_snd_ac97_controls[] = {
419 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
420 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
423 static int patch_wolfson_wm9703_specific(struct snd_ac97 * ac97)
425 /* This is known to work for the ViewSonic ViewPad 1000
426 * Randolph Bentson <bentson@holmsjoen.com>
427 * WM9703/9707/9708/9717
431 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
432 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
435 snd_ac97_write_cache(ac97, AC97_WM97XX_FMIXER_VOL, 0x0808);
439 static struct snd_ac97_build_ops patch_wolfson_wm9703_ops = {
440 .build_specific = patch_wolfson_wm9703_specific,
443 static int patch_wolfson03(struct snd_ac97 * ac97)
445 ac97->build_ops = &patch_wolfson_wm9703_ops;
449 static const struct snd_kcontrol_new wm9704_snd_ac97_controls[] = {
450 AC97_DOUBLE("Front Playback Volume", AC97_WM97XX_FMIXER_VOL, 8, 0, 31, 1),
451 AC97_SINGLE("Front Playback Switch", AC97_WM97XX_FMIXER_VOL, 15, 1, 1),
452 AC97_DOUBLE("Rear Playback Volume", AC97_WM9704_RMIXER_VOL, 8, 0, 31, 1),
453 AC97_SINGLE("Rear Playback Switch", AC97_WM9704_RMIXER_VOL, 15, 1, 1),
454 AC97_DOUBLE("Rear DAC Volume", AC97_WM9704_RPCM_VOL, 8, 0, 31, 1),
455 AC97_DOUBLE("Surround Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
458 static int patch_wolfson_wm9704_specific(struct snd_ac97 * ac97)
461 for (i = 0; i < ARRAY_SIZE(wm9704_snd_ac97_controls); i++) {
462 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9704_snd_ac97_controls[i], ac97))) < 0)
465 /* patch for DVD noise */
466 snd_ac97_write_cache(ac97, AC97_WM9704_TEST, 0x0200);
470 static struct snd_ac97_build_ops patch_wolfson_wm9704_ops = {
471 .build_specific = patch_wolfson_wm9704_specific,
474 static int patch_wolfson04(struct snd_ac97 * ac97)
477 ac97->build_ops = &patch_wolfson_wm9704_ops;
481 static int patch_wolfson_wm9705_specific(struct snd_ac97 * ac97)
484 for (i = 0; i < ARRAY_SIZE(wm97xx_snd_ac97_controls); i++) {
485 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm97xx_snd_ac97_controls[i], ac97))) < 0)
488 snd_ac97_write_cache(ac97, 0x72, 0x0808);
492 static struct snd_ac97_build_ops patch_wolfson_wm9705_ops = {
493 .build_specific = patch_wolfson_wm9705_specific,
496 static int patch_wolfson05(struct snd_ac97 * ac97)
499 ac97->build_ops = &patch_wolfson_wm9705_ops;
500 #ifdef CONFIG_TOUCHSCREEN_WM9705
501 /* WM9705 touchscreen uses AUX and VIDEO for touch */
502 ac97->flags |= AC97_HAS_NO_VIDEO | AC97_HAS_NO_AUX;
507 static const char* wm9711_alc_select[] = {"None", "Left", "Right", "Stereo"};
508 static const char* wm9711_alc_mix[] = {"Stereo", "Right", "Left", "None"};
509 static const char* wm9711_out3_src[] = {"Left", "VREF", "Left + Right", "Mono"};
510 static const char* wm9711_out3_lrsrc[] = {"Master Mix", "Headphone Mix"};
511 static const char* wm9711_rec_adc[] = {"Stereo", "Left", "Right", "Mute"};
512 static const char* wm9711_base[] = {"Linear Control", "Adaptive Boost"};
513 static const char* wm9711_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
514 static const char* wm9711_mic[] = {"Mic 1", "Differential", "Mic 2", "Stereo"};
515 static const char* wm9711_rec_sel[] =
516 {"Mic 1", "NC", "NC", "Master Mix", "Line", "Headphone Mix", "Phone Mix", "Phone"};
517 static const char* wm9711_ng_type[] = {"Constant Gain", "Mute"};
519 static const struct ac97_enum wm9711_enum[] = {
520 AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9711_alc_select),
521 AC97_ENUM_SINGLE(AC97_VIDEO, 10, 4, wm9711_alc_mix),
522 AC97_ENUM_SINGLE(AC97_AUX, 9, 4, wm9711_out3_src),
523 AC97_ENUM_SINGLE(AC97_AUX, 8, 2, wm9711_out3_lrsrc),
524 AC97_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9711_rec_adc),
525 AC97_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9711_base),
526 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9711_rec_gain),
527 AC97_ENUM_SINGLE(AC97_MIC, 5, 4, wm9711_mic),
528 AC97_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, wm9711_rec_sel),
529 AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9711_ng_type),
532 static const struct snd_kcontrol_new wm9711_snd_ac97_controls[] = {
533 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
534 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
535 AC97_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0),
536 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
537 AC97_ENUM("ALC Function", wm9711_enum[0]),
538 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 1),
539 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1),
540 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
541 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
542 AC97_ENUM("ALC NG Type", wm9711_enum[9]),
543 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1),
545 AC97_SINGLE("Side Tone Switch", AC97_VIDEO, 15, 1, 1),
546 AC97_SINGLE("Side Tone Volume", AC97_VIDEO, 12, 7, 1),
547 AC97_ENUM("ALC Headphone Mux", wm9711_enum[1]),
548 AC97_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1),
550 AC97_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1),
551 AC97_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 0),
552 AC97_ENUM("Out3 Mux", wm9711_enum[2]),
553 AC97_ENUM("Out3 LR Mux", wm9711_enum[3]),
554 AC97_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1),
556 AC97_SINGLE("Beep to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
557 AC97_SINGLE("Beep to Headphone Volume", AC97_PC_BEEP, 12, 7, 1),
558 AC97_SINGLE("Beep to Side Tone Switch", AC97_PC_BEEP, 11, 1, 1),
559 AC97_SINGLE("Beep to Side Tone Volume", AC97_PC_BEEP, 8, 7, 1),
560 AC97_SINGLE("Beep to Phone Switch", AC97_PC_BEEP, 7, 1, 1),
561 AC97_SINGLE("Beep to Phone Volume", AC97_PC_BEEP, 4, 7, 1),
563 AC97_SINGLE("Aux to Headphone Switch", AC97_CD, 15, 1, 1),
564 AC97_SINGLE("Aux to Headphone Volume", AC97_CD, 12, 7, 1),
565 AC97_SINGLE("Aux to Side Tone Switch", AC97_CD, 11, 1, 1),
566 AC97_SINGLE("Aux to Side Tone Volume", AC97_CD, 8, 7, 1),
567 AC97_SINGLE("Aux to Phone Switch", AC97_CD, 7, 1, 1),
568 AC97_SINGLE("Aux to Phone Volume", AC97_CD, 4, 7, 1),
570 AC97_SINGLE("Phone to Headphone Switch", AC97_PHONE, 15, 1, 1),
571 AC97_SINGLE("Phone to Master Switch", AC97_PHONE, 14, 1, 1),
573 AC97_SINGLE("Line to Headphone Switch", AC97_LINE, 15, 1, 1),
574 AC97_SINGLE("Line to Master Switch", AC97_LINE, 14, 1, 1),
575 AC97_SINGLE("Line to Phone Switch", AC97_LINE, 13, 1, 1),
577 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PCM, 15, 1, 1),
578 AC97_SINGLE("PCM Playback to Master Switch", AC97_PCM, 14, 1, 1),
579 AC97_SINGLE("PCM Playback to Phone Switch", AC97_PCM, 13, 1, 1),
581 AC97_SINGLE("Capture 20dB Boost Switch", AC97_REC_SEL, 14, 1, 0),
582 AC97_ENUM("Capture to Phone Mux", wm9711_enum[4]),
583 AC97_SINGLE("Capture to Phone 20dB Boost Switch", AC97_REC_SEL, 11, 1, 1),
584 AC97_ENUM("Capture Select", wm9711_enum[8]),
586 AC97_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1),
587 AC97_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1),
589 AC97_ENUM("Bass Control", wm9711_enum[5]),
590 AC97_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1),
591 AC97_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1),
592 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0),
594 AC97_SINGLE("ADC Switch", AC97_REC_GAIN, 15, 1, 1),
595 AC97_ENUM("Capture Volume Steps", wm9711_enum[6]),
596 AC97_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 1),
597 AC97_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0),
599 AC97_SINGLE("Mic 1 to Phone Switch", AC97_MIC, 14, 1, 1),
600 AC97_SINGLE("Mic 2 to Phone Switch", AC97_MIC, 13, 1, 1),
601 AC97_ENUM("Mic Select Source", wm9711_enum[7]),
602 AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
603 AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
604 AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
606 AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
607 AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
608 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
611 static int patch_wolfson_wm9711_specific(struct snd_ac97 * ac97)
615 for (i = 0; i < ARRAY_SIZE(wm9711_snd_ac97_controls); i++) {
616 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm9711_snd_ac97_controls[i], ac97))) < 0)
619 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x0808);
620 snd_ac97_write_cache(ac97, AC97_PCI_SVID, 0x0808);
621 snd_ac97_write_cache(ac97, AC97_VIDEO, 0x0808);
622 snd_ac97_write_cache(ac97, AC97_AUX, 0x0808);
623 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
624 snd_ac97_write_cache(ac97, AC97_CD, 0x0000);
628 static struct snd_ac97_build_ops patch_wolfson_wm9711_ops = {
629 .build_specific = patch_wolfson_wm9711_specific,
632 static int patch_wolfson11(struct snd_ac97 * ac97)
635 ac97->build_ops = &patch_wolfson_wm9711_ops;
637 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_MIC |
638 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD;
643 static const char* wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
644 static const char* wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
645 static const char* wm9713_rec_src[] =
646 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone Mix", "Master Mix",
648 static const char* wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
649 static const char* wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
650 static const char* wm9713_mono_pga[] = {"Vmid", "Zh", "Mono Mix", "Inv 1"};
651 static const char* wm9713_spk_pga[] =
652 {"Vmid", "Zh", "Headphone Mix", "Master Mix", "Inv", "NC", "NC", "NC"};
653 static const char* wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone Mix", "NC"};
654 static const char* wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "NC"};
655 static const char* wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "NC"};
656 static const char* wm9713_dac_inv[] =
657 {"Off", "Mono Mix", "Master Mix", "Headphone Mix L", "Headphone Mix R",
658 "Headphone Mix Mono", "NC", "Vmid"};
659 static const char* wm9713_base[] = {"Linear Control", "Adaptive Boost"};
660 static const char* wm9713_ng_type[] = {"Constant Gain", "Mute"};
662 static const struct ac97_enum wm9713_enum[] = {
663 AC97_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer),
664 AC97_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux),
665 AC97_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux),
666 AC97_ENUM_DOUBLE(AC97_VIDEO, 3, 0, 8, wm9713_rec_src),
667 AC97_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain),
668 AC97_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select),
669 AC97_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga),
670 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 11, 8, 8, wm9713_spk_pga),
671 AC97_ENUM_DOUBLE(AC97_REC_GAIN, 6, 4, 4, wm9713_hp_pga),
672 AC97_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga),
673 AC97_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga),
674 AC97_ENUM_DOUBLE(AC97_REC_GAIN_MIC, 13, 10, 8, wm9713_dac_inv),
675 AC97_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_base),
676 AC97_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type),
679 static const struct snd_kcontrol_new wm13_snd_ac97_controls[] = {
680 AC97_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
681 AC97_SINGLE("Line In to Headphone Switch", AC97_PC_BEEP, 15, 1, 1),
682 AC97_SINGLE("Line In to Master Switch", AC97_PC_BEEP, 14, 1, 1),
683 AC97_SINGLE("Line In to Mono Switch", AC97_PC_BEEP, 13, 1, 1),
685 AC97_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
686 AC97_SINGLE("PCM Playback to Headphone Switch", AC97_PHONE, 15, 1, 1),
687 AC97_SINGLE("PCM Playback to Master Switch", AC97_PHONE, 14, 1, 1),
688 AC97_SINGLE("PCM Playback to Mono Switch", AC97_PHONE, 13, 1, 1),
690 AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
691 AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
692 AC97_SINGLE("Mic 1 to Mono Switch", AC97_LINE, 7, 1, 1),
693 AC97_SINGLE("Mic 2 to Mono Switch", AC97_LINE, 6, 1, 1),
694 AC97_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
695 AC97_ENUM("Mic to Headphone Mux", wm9713_enum[0]),
696 AC97_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
698 AC97_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
699 AC97_ENUM("Capture Volume Steps", wm9713_enum[4]),
700 AC97_DOUBLE("Capture Volume", AC97_CD, 8, 0, 15, 0),
701 AC97_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
703 AC97_ENUM("Capture to Headphone Mux", wm9713_enum[1]),
704 AC97_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
705 AC97_ENUM("Capture to Mono Mux", wm9713_enum[2]),
706 AC97_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
707 AC97_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
708 AC97_ENUM("Capture Select", wm9713_enum[3]),
710 AC97_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
711 AC97_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
712 AC97_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
713 AC97_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
714 AC97_ENUM("ALC Function", wm9713_enum[5]),
715 AC97_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
716 AC97_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
717 AC97_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
718 AC97_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
719 AC97_ENUM("ALC NG Type", wm9713_enum[13]),
720 AC97_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
722 AC97_DOUBLE("Master ZC Switch", AC97_MASTER, 14, 6, 1, 0),
723 AC97_DOUBLE("Headphone ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
724 AC97_DOUBLE("Out3/4 ZC Switch", AC97_MASTER_MONO, 14, 6, 1, 0),
725 AC97_SINGLE("Master Right Switch", AC97_MASTER, 7, 1, 1),
726 AC97_SINGLE("Headphone Right Switch", AC97_HEADPHONE, 7, 1, 1),
727 AC97_SINGLE("Out3/4 Right Switch", AC97_MASTER_MONO, 7, 1, 1),
729 AC97_SINGLE("Mono In to Headphone Switch", AC97_MASTER_TONE, 15, 1, 1),
730 AC97_SINGLE("Mono In to Master Switch", AC97_MASTER_TONE, 14, 1, 1),
731 AC97_SINGLE("Mono In Volume", AC97_MASTER_TONE, 8, 31, 1),
732 AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
733 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
734 AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
736 AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
737 AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
738 AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1),
739 AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1),
740 AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1),
741 AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1),
743 AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
744 AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
745 AC97_SINGLE("Voice to Master Switch", AC97_PCM, 11, 1, 1),
746 AC97_SINGLE("Voice to Master Volume", AC97_PCM, 8, 7, 1),
747 AC97_SINGLE("Voice to Mono Switch", AC97_PCM, 7, 1, 1),
748 AC97_SINGLE("Voice to Mono Volume", AC97_PCM, 4, 7, 1),
750 AC97_SINGLE("Aux to Headphone Switch", AC97_REC_SEL, 15, 1, 1),
751 AC97_SINGLE("Aux to Headphone Volume", AC97_REC_SEL, 12, 7, 1),
752 AC97_SINGLE("Aux to Master Switch", AC97_REC_SEL, 11, 1, 1),
753 AC97_SINGLE("Aux to Master Volume", AC97_REC_SEL, 8, 7, 1),
754 AC97_SINGLE("Aux to Mono Switch", AC97_REC_SEL, 7, 1, 1),
755 AC97_SINGLE("Aux to Mono Volume", AC97_REC_SEL, 4, 7, 1),
757 AC97_ENUM("Mono Input Mux", wm9713_enum[6]),
758 AC97_ENUM("Master Input Mux", wm9713_enum[7]),
759 AC97_ENUM("Headphone Input Mux", wm9713_enum[8]),
760 AC97_ENUM("Out 3 Input Mux", wm9713_enum[9]),
761 AC97_ENUM("Out 4 Input Mux", wm9713_enum[10]),
763 AC97_ENUM("Bass Control", wm9713_enum[12]),
764 AC97_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
765 AC97_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
766 AC97_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
767 AC97_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
768 AC97_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
771 static const struct snd_kcontrol_new wm13_snd_ac97_controls_3d[] = {
772 AC97_ENUM("Inv Input Mux", wm9713_enum[11]),
773 AC97_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
774 AC97_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
775 AC97_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
778 static int patch_wolfson_wm9713_3d (struct snd_ac97 * ac97)
782 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls_3d); i++) {
783 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls_3d[i], ac97))) < 0)
789 static int patch_wolfson_wm9713_specific(struct snd_ac97 * ac97)
793 for (i = 0; i < ARRAY_SIZE(wm13_snd_ac97_controls); i++) {
794 if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&wm13_snd_ac97_controls[i], ac97))) < 0)
797 snd_ac97_write_cache(ac97, AC97_PC_BEEP, 0x0808);
798 snd_ac97_write_cache(ac97, AC97_PHONE, 0x0808);
799 snd_ac97_write_cache(ac97, AC97_MIC, 0x0808);
800 snd_ac97_write_cache(ac97, AC97_LINE, 0x00da);
801 snd_ac97_write_cache(ac97, AC97_CD, 0x0808);
802 snd_ac97_write_cache(ac97, AC97_VIDEO, 0xd612);
803 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x1ba0);
808 static void patch_wolfson_wm9713_suspend (struct snd_ac97 * ac97)
810 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xfeff);
811 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0xffff);
814 static void patch_wolfson_wm9713_resume (struct snd_ac97 * ac97)
816 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
817 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
818 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
822 static struct snd_ac97_build_ops patch_wolfson_wm9713_ops = {
823 .build_specific = patch_wolfson_wm9713_specific,
824 .build_3d = patch_wolfson_wm9713_3d,
826 .suspend = patch_wolfson_wm9713_suspend,
827 .resume = patch_wolfson_wm9713_resume
831 static int patch_wolfson13(struct snd_ac97 * ac97)
834 ac97->build_ops = &patch_wolfson_wm9713_ops;
836 ac97->flags |= AC97_HAS_NO_REC_GAIN | AC97_STEREO_MUTES | AC97_HAS_NO_PHONE |
837 AC97_HAS_NO_PC_BEEP | AC97_HAS_NO_VIDEO | AC97_HAS_NO_CD | AC97_HAS_NO_TONE |
839 ac97->scaps &= ~AC97_SCAP_MODEM;
841 snd_ac97_write_cache(ac97, AC97_EXTENDED_MID, 0xda00);
842 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0x3810);
843 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0x0);
851 static int patch_tritech_tr28028(struct snd_ac97 * ac97)
853 snd_ac97_write_cache(ac97, 0x26, 0x0300);
854 snd_ac97_write_cache(ac97, 0x26, 0x0000);
855 snd_ac97_write_cache(ac97, AC97_SURROUND_MASTER, 0x0000);
856 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x0000);
861 * Sigmatel STAC97xx codecs
863 static int patch_sigmatel_stac9700_3d(struct snd_ac97 * ac97)
865 struct snd_kcontrol *kctl;
868 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
870 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
871 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
872 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
876 static int patch_sigmatel_stac9708_3d(struct snd_ac97 * ac97)
878 struct snd_kcontrol *kctl;
881 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
883 strcpy(kctl->id.name, "3D Control Sigmatel - Depth");
884 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 0, 3, 0);
885 if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
887 strcpy(kctl->id.name, "3D Control Sigmatel - Rear Depth");
888 kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 2, 3, 0);
889 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
893 static const struct snd_kcontrol_new snd_ac97_sigmatel_4speaker =
894 AC97_SINGLE("Sigmatel 4-Speaker Stereo Playback Switch", AC97_SIGMATEL_DAC2INVERT, 2, 1, 0);
896 static const struct snd_kcontrol_new snd_ac97_sigmatel_phaseinvert =
897 AC97_SINGLE("Sigmatel Surround Phase Inversion Playback Switch", AC97_SIGMATEL_DAC2INVERT, 3, 1, 0);
899 static const struct snd_kcontrol_new snd_ac97_sigmatel_controls[] = {
900 AC97_SINGLE("Sigmatel DAC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 1, 1, 0),
901 AC97_SINGLE("Sigmatel ADC 6dB Attenuate", AC97_SIGMATEL_ANALOG, 0, 1, 0)
904 static int patch_sigmatel_stac97xx_specific(struct snd_ac97 * ac97)
908 snd_ac97_write_cache(ac97, AC97_SIGMATEL_ANALOG, snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) & ~0x0003);
909 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 1))
910 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[0], 1)) < 0)
912 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_ANALOG, 0))
913 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_controls[1], 1)) < 0)
915 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 2))
916 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_4speaker, 1)) < 0)
918 if (snd_ac97_try_bit(ac97, AC97_SIGMATEL_DAC2INVERT, 3))
919 if ((err = patch_build_controls(ac97, &snd_ac97_sigmatel_phaseinvert, 1)) < 0)
924 static struct snd_ac97_build_ops patch_sigmatel_stac9700_ops = {
925 .build_3d = patch_sigmatel_stac9700_3d,
926 .build_specific = patch_sigmatel_stac97xx_specific
929 static int patch_sigmatel_stac9700(struct snd_ac97 * ac97)
931 ac97->build_ops = &patch_sigmatel_stac9700_ops;
935 static int snd_ac97_stac9708_put_bias(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
937 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
940 mutex_lock(&ac97->page_mutex);
941 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
942 err = snd_ac97_update_bits(ac97, AC97_SIGMATEL_BIAS2, 0x0010,
943 (ucontrol->value.integer.value[0] & 1) << 4);
944 snd_ac97_write(ac97, AC97_SIGMATEL_BIAS1, 0);
945 mutex_unlock(&ac97->page_mutex);
949 static const struct snd_kcontrol_new snd_ac97_stac9708_bias_control = {
950 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
951 .name = "Sigmatel Output Bias Switch",
952 .info = snd_ac97_info_volsw,
953 .get = snd_ac97_get_volsw,
954 .put = snd_ac97_stac9708_put_bias,
955 .private_value = AC97_SINGLE_VALUE(AC97_SIGMATEL_BIAS2, 4, 1, 0),
958 static int patch_sigmatel_stac9708_specific(struct snd_ac97 *ac97)
962 /* the register bit is writable, but the function is not implemented: */
963 snd_ac97_remove_ctl(ac97, "PCM Out Path & Mute", NULL);
965 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Sigmatel Surround Playback");
966 if ((err = patch_build_controls(ac97, &snd_ac97_stac9708_bias_control, 1)) < 0)
968 return patch_sigmatel_stac97xx_specific(ac97);
971 static struct snd_ac97_build_ops patch_sigmatel_stac9708_ops = {
972 .build_3d = patch_sigmatel_stac9708_3d,
973 .build_specific = patch_sigmatel_stac9708_specific
976 static int patch_sigmatel_stac9708(struct snd_ac97 * ac97)
978 unsigned int codec72, codec6c;
980 ac97->build_ops = &patch_sigmatel_stac9708_ops;
981 ac97->caps |= 0x10; /* HP (sigmatel surround) support */
983 codec72 = snd_ac97_read(ac97, AC97_SIGMATEL_BIAS2) & 0x8000;
984 codec6c = snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG);
986 if ((codec72==0) && (codec6c==0)) {
987 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
988 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1000);
989 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
990 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0007);
991 } else if ((codec72==0x8000) && (codec6c==0)) {
992 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
993 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x1001);
994 snd_ac97_write_cache(ac97, AC97_SIGMATEL_DAC2INVERT, 0x0008);
995 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
998 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1002 static int patch_sigmatel_stac9721(struct snd_ac97 * ac97)
1004 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1005 if (snd_ac97_read(ac97, AC97_SIGMATEL_ANALOG) == 0) {
1006 // patch for SigmaTel
1007 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1008 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x4000);
1009 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1010 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1012 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1016 static int patch_sigmatel_stac9744(struct snd_ac97 * ac97)
1018 // patch for SigmaTel
1019 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1020 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1021 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1022 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1023 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1024 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1028 static int patch_sigmatel_stac9756(struct snd_ac97 * ac97)
1030 // patch for SigmaTel
1031 ac97->build_ops = &patch_sigmatel_stac9700_ops;
1032 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC1, 0xabba);
1033 snd_ac97_write_cache(ac97, AC97_SIGMATEL_CIC2, 0x0000); /* is this correct? --jk */
1034 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS1, 0xabba);
1035 snd_ac97_write_cache(ac97, AC97_SIGMATEL_BIAS2, 0x0002);
1036 snd_ac97_write_cache(ac97, AC97_SIGMATEL_MULTICHN, 0x0000);
1040 static int snd_ac97_stac9758_output_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1042 static char *texts[5] = { "Input/Disabled", "Front Output",
1043 "Rear Output", "Center/LFE Output", "Mixer Output" };
1045 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1047 uinfo->value.enumerated.items = 5;
1048 if (uinfo->value.enumerated.item > 4)
1049 uinfo->value.enumerated.item = 4;
1050 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1054 static int snd_ac97_stac9758_output_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1056 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1057 int shift = kcontrol->private_value;
1060 val = ac97->regs[AC97_SIGMATEL_OUTSEL] >> shift;
1062 ucontrol->value.enumerated.item[0] = 0;
1064 ucontrol->value.enumerated.item[0] = 1 + (val & 3);
1068 static int snd_ac97_stac9758_output_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1070 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1071 int shift = kcontrol->private_value;
1074 if (ucontrol->value.enumerated.item[0] > 4)
1076 if (ucontrol->value.enumerated.item[0] == 0)
1079 val = 4 | (ucontrol->value.enumerated.item[0] - 1);
1080 return ac97_update_bits_page(ac97, AC97_SIGMATEL_OUTSEL,
1081 7 << shift, val << shift, 0);
1084 static int snd_ac97_stac9758_input_jack_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1086 static char *texts[7] = { "Mic2 Jack", "Mic1 Jack", "Line In Jack",
1087 "Front Jack", "Rear Jack", "Center/LFE Jack", "Mute" };
1089 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1091 uinfo->value.enumerated.items = 7;
1092 if (uinfo->value.enumerated.item > 6)
1093 uinfo->value.enumerated.item = 6;
1094 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1098 static int snd_ac97_stac9758_input_jack_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1100 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1101 int shift = kcontrol->private_value;
1104 val = ac97->regs[AC97_SIGMATEL_INSEL];
1105 ucontrol->value.enumerated.item[0] = (val >> shift) & 7;
1109 static int snd_ac97_stac9758_input_jack_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1111 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1112 int shift = kcontrol->private_value;
1114 return ac97_update_bits_page(ac97, AC97_SIGMATEL_INSEL, 7 << shift,
1115 ucontrol->value.enumerated.item[0] << shift, 0);
1118 static int snd_ac97_stac9758_phonesel_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1120 static char *texts[3] = { "None", "Front Jack", "Rear Jack" };
1122 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1124 uinfo->value.enumerated.items = 3;
1125 if (uinfo->value.enumerated.item > 2)
1126 uinfo->value.enumerated.item = 2;
1127 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1131 static int snd_ac97_stac9758_phonesel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1133 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1135 ucontrol->value.enumerated.item[0] = ac97->regs[AC97_SIGMATEL_IOMISC] & 3;
1139 static int snd_ac97_stac9758_phonesel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1141 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1143 return ac97_update_bits_page(ac97, AC97_SIGMATEL_IOMISC, 3,
1144 ucontrol->value.enumerated.item[0], 0);
1147 #define STAC9758_OUTPUT_JACK(xname, shift) \
1148 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1149 .info = snd_ac97_stac9758_output_jack_info, \
1150 .get = snd_ac97_stac9758_output_jack_get, \
1151 .put = snd_ac97_stac9758_output_jack_put, \
1152 .private_value = shift }
1153 #define STAC9758_INPUT_JACK(xname, shift) \
1154 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1155 .info = snd_ac97_stac9758_input_jack_info, \
1156 .get = snd_ac97_stac9758_input_jack_get, \
1157 .put = snd_ac97_stac9758_input_jack_put, \
1158 .private_value = shift }
1159 static const struct snd_kcontrol_new snd_ac97_sigmatel_stac9758_controls[] = {
1160 STAC9758_OUTPUT_JACK("Mic1 Jack", 1),
1161 STAC9758_OUTPUT_JACK("LineIn Jack", 4),
1162 STAC9758_OUTPUT_JACK("Front Jack", 7),
1163 STAC9758_OUTPUT_JACK("Rear Jack", 10),
1164 STAC9758_OUTPUT_JACK("Center/LFE Jack", 13),
1165 STAC9758_INPUT_JACK("Mic Input Source", 0),
1166 STAC9758_INPUT_JACK("Line Input Source", 8),
1168 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1169 .name = "Headphone Amp",
1170 .info = snd_ac97_stac9758_phonesel_info,
1171 .get = snd_ac97_stac9758_phonesel_get,
1172 .put = snd_ac97_stac9758_phonesel_put
1174 AC97_SINGLE("Exchange Center/LFE", AC97_SIGMATEL_IOMISC, 4, 1, 0),
1175 AC97_SINGLE("Headphone +3dB Boost", AC97_SIGMATEL_IOMISC, 8, 1, 0)
1178 static int patch_sigmatel_stac9758_specific(struct snd_ac97 *ac97)
1182 err = patch_sigmatel_stac97xx_specific(ac97);
1185 err = patch_build_controls(ac97, snd_ac97_sigmatel_stac9758_controls,
1186 ARRAY_SIZE(snd_ac97_sigmatel_stac9758_controls));
1190 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Front Playback");
1191 /* DAC-A to Mix = PCM */
1192 /* DAC-B direct = Surround */
1194 snd_ac97_rename_vol_ctl(ac97, "Video Playback", "Surround Mix Playback");
1195 /* DAC-C direct = Center/LFE */
1200 static struct snd_ac97_build_ops patch_sigmatel_stac9758_ops = {
1201 .build_3d = patch_sigmatel_stac9700_3d,
1202 .build_specific = patch_sigmatel_stac9758_specific
1205 static int patch_sigmatel_stac9758(struct snd_ac97 * ac97)
1207 static unsigned short regs[4] = {
1208 AC97_SIGMATEL_OUTSEL,
1209 AC97_SIGMATEL_IOMISC,
1210 AC97_SIGMATEL_INSEL,
1211 AC97_SIGMATEL_VARIOUS
1213 static unsigned short def_regs[4] = {
1214 /* OUTSEL */ 0xd794, /* CL:CL, SR:SR, LO:MX, LI:DS, MI:DS */
1215 /* IOMISC */ 0x2001,
1216 /* INSEL */ 0x0201, /* LI:LI, MI:M1 */
1217 /* VARIOUS */ 0x0040
1219 static unsigned short m675_regs[4] = {
1220 /* OUTSEL */ 0xfc70, /* CL:MX, SR:MX, LO:DS, LI:MX, MI:DS */
1221 /* IOMISC */ 0x2102, /* HP amp on */
1222 /* INSEL */ 0x0203, /* LI:LI, MI:FR */
1223 /* VARIOUS */ 0x0041 /* stereo mic */
1225 unsigned short *pregs = def_regs;
1228 /* Gateway M675 notebook */
1230 ac97->subsystem_vendor == 0x107b &&
1231 ac97->subsystem_device == 0x0601)
1234 // patch for SigmaTel
1235 ac97->build_ops = &patch_sigmatel_stac9758_ops;
1236 /* FIXME: assume only page 0 for writing cache */
1237 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
1238 for (i = 0; i < 4; i++)
1239 snd_ac97_write_cache(ac97, regs[i], pregs[i]);
1241 ac97->flags |= AC97_STEREO_MUTES;
1246 * Cirrus Logic CS42xx codecs
1248 static const struct snd_kcontrol_new snd_ac97_cirrus_controls_spdif[2] = {
1249 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CSR_SPDIF, 15, 1, 0),
1250 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA", AC97_CSR_ACMODE, 0, 3, 0)
1253 static int patch_cirrus_build_spdif(struct snd_ac97 * ac97)
1257 /* con mask, pro mask, default */
1258 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1261 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[0], 1)) < 0)
1263 switch (ac97->id & AC97_ID_CS_MASK) {
1264 case AC97_ID_CS4205:
1265 if ((err = patch_build_controls(ac97, &snd_ac97_cirrus_controls_spdif[1], 1)) < 0)
1269 /* set default PCM S/PDIF params */
1270 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1271 snd_ac97_write_cache(ac97, AC97_CSR_SPDIF, 0x0a20);
1275 static struct snd_ac97_build_ops patch_cirrus_ops = {
1276 .build_spdif = patch_cirrus_build_spdif
1279 static int patch_cirrus_spdif(struct snd_ac97 * ac97)
1281 /* Basically, the cs4201/cs4205/cs4297a has non-standard sp/dif registers.
1282 WHY CAN'T ANYONE FOLLOW THE BLOODY SPEC? *sigh*
1283 - sp/dif EA ID is not set, but sp/dif is always present.
1284 - enable/disable is spdif register bit 15.
1285 - sp/dif control register is 0x68. differs from AC97:
1286 - valid is bit 14 (vs 15)
1288 - only 44.1/48k [00 = 48, 01=44,1] (AC97 is 00=44.1, 10=48)
1289 - sp/dif ssource select is in 0x5e bits 0,1.
1292 ac97->build_ops = &patch_cirrus_ops;
1293 ac97->flags |= AC97_CS_SPDIF;
1294 ac97->rates[AC97_RATES_SPDIF] &= ~SNDRV_PCM_RATE_32000;
1295 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1296 snd_ac97_write_cache(ac97, AC97_CSR_ACMODE, 0x0080);
1300 static int patch_cirrus_cs4299(struct snd_ac97 * ac97)
1302 /* force the detection of PC Beep */
1303 ac97->flags |= AC97_HAS_PC_BEEP;
1305 return patch_cirrus_spdif(ac97);
1311 static const struct snd_kcontrol_new snd_ac97_conexant_controls_spdif[1] = {
1312 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), AC97_CXR_AUDIO_MISC, 3, 1, 0),
1315 static int patch_conexant_build_spdif(struct snd_ac97 * ac97)
1319 /* con mask, pro mask, default */
1320 if ((err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3)) < 0)
1323 if ((err = patch_build_controls(ac97, &snd_ac97_conexant_controls_spdif[0], 1)) < 0)
1325 /* set default PCM S/PDIF params */
1326 /* consumer,PCM audio,no copyright,no preemphasis,PCM coder,original,48000Hz */
1327 snd_ac97_write_cache(ac97, AC97_CXR_AUDIO_MISC,
1328 snd_ac97_read(ac97, AC97_CXR_AUDIO_MISC) & ~(AC97_CXR_SPDIFEN|AC97_CXR_COPYRGT|AC97_CXR_SPDIF_MASK));
1332 static struct snd_ac97_build_ops patch_conexant_ops = {
1333 .build_spdif = patch_conexant_build_spdif
1336 static int patch_conexant(struct snd_ac97 * ac97)
1338 ac97->build_ops = &patch_conexant_ops;
1339 ac97->flags |= AC97_CX_SPDIF;
1340 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
1341 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
1345 static int patch_cx20551(struct snd_ac97 *ac97)
1347 snd_ac97_update_bits(ac97, 0x5c, 0x01, 0x01);
1352 * Analog Device AD18xx, AD19xx codecs
1355 static void ad18xx_resume(struct snd_ac97 *ac97)
1357 static unsigned short setup_regs[] = {
1358 AC97_AD_MISC, AC97_AD_SERIAL_CFG, AC97_AD_JACK_SPDIF,
1362 for (i = 0; i < (int)ARRAY_SIZE(setup_regs); i++) {
1363 unsigned short reg = setup_regs[i];
1364 if (test_bit(reg, ac97->reg_accessed)) {
1365 snd_ac97_write(ac97, reg, ac97->regs[reg]);
1366 snd_ac97_read(ac97, reg);
1370 if (! (ac97->flags & AC97_AD_MULTI))
1371 /* normal restore */
1372 snd_ac97_restore_status(ac97);
1374 /* restore the AD18xx codec configurations */
1375 for (codec = 0; codec < 3; codec++) {
1376 if (! ac97->spec.ad18xx.id[codec])
1378 /* select single codec */
1379 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1380 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1381 ac97->bus->ops->write(ac97, AC97_AD_CODEC_CFG, ac97->spec.ad18xx.codec_cfg[codec]);
1383 /* select all codecs */
1384 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1386 /* restore status */
1387 for (i = 2; i < 0x7c ; i += 2) {
1388 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_ID)
1390 if (test_bit(i, ac97->reg_accessed)) {
1391 /* handle multi codecs for AD18xx */
1392 if (i == AC97_PCM) {
1393 for (codec = 0; codec < 3; codec++) {
1394 if (! ac97->spec.ad18xx.id[codec])
1396 /* select single codec */
1397 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1398 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
1399 /* update PCM bits */
1400 ac97->bus->ops->write(ac97, AC97_PCM, ac97->spec.ad18xx.pcmreg[codec]);
1402 /* select all codecs */
1403 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1405 } else if (i == AC97_AD_TEST ||
1406 i == AC97_AD_CODEC_CFG ||
1407 i == AC97_AD_SERIAL_CFG)
1408 continue; /* ignore */
1410 snd_ac97_write(ac97, i, ac97->regs[i]);
1411 snd_ac97_read(ac97, i);
1415 snd_ac97_restore_iec958(ac97);
1418 static void ad1888_resume(struct snd_ac97 *ac97)
1420 ad18xx_resume(ac97);
1421 snd_ac97_write_cache(ac97, AC97_CODEC_CLASS_REV, 0x8080);
1426 static const struct snd_ac97_res_table ad1819_restbl[] = {
1427 { AC97_PHONE, 0x9f1f },
1428 { AC97_MIC, 0x9f1f },
1429 { AC97_LINE, 0x9f1f },
1430 { AC97_CD, 0x9f1f },
1431 { AC97_VIDEO, 0x9f1f },
1432 { AC97_AUX, 0x9f1f },
1433 { AC97_PCM, 0x9f1f },
1434 { } /* terminator */
1437 static int patch_ad1819(struct snd_ac97 * ac97)
1439 unsigned short scfg;
1441 // patch for Analog Devices
1442 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1443 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x7000); /* select all codecs */
1444 ac97->res_table = ad1819_restbl;
1448 static unsigned short patch_ad1881_unchained(struct snd_ac97 * ac97, int idx, unsigned short mask)
1452 // test for unchained codec
1453 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, mask);
1454 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000); /* ID0C, ID1C, SDIE = off */
1455 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1456 if ((val & 0xff40) != 0x5340)
1458 ac97->spec.ad18xx.unchained[idx] = mask;
1459 ac97->spec.ad18xx.id[idx] = val;
1460 ac97->spec.ad18xx.codec_cfg[idx] = 0x0000;
1464 static int patch_ad1881_chained1(struct snd_ac97 * ac97, int idx, unsigned short codec_bits)
1466 static int cfg_bits[3] = { 1<<12, 1<<14, 1<<13 };
1469 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, cfg_bits[idx]);
1470 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0004); // SDIE
1471 val = snd_ac97_read(ac97, AC97_VENDOR_ID2);
1472 if ((val & 0xff40) != 0x5340)
1475 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, codec_bits);
1476 ac97->spec.ad18xx.chained[idx] = cfg_bits[idx];
1477 ac97->spec.ad18xx.id[idx] = val;
1478 ac97->spec.ad18xx.codec_cfg[idx] = codec_bits ? codec_bits : 0x0004;
1482 static void patch_ad1881_chained(struct snd_ac97 * ac97, int unchained_idx, int cidx1, int cidx2)
1484 // already detected?
1485 if (ac97->spec.ad18xx.unchained[cidx1] || ac97->spec.ad18xx.chained[cidx1])
1487 if (ac97->spec.ad18xx.unchained[cidx2] || ac97->spec.ad18xx.chained[cidx2])
1489 if (cidx1 < 0 && cidx2 < 0)
1491 // test for chained codecs
1492 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
1493 ac97->spec.ad18xx.unchained[unchained_idx]);
1494 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0002); // ID1C
1495 ac97->spec.ad18xx.codec_cfg[unchained_idx] = 0x0002;
1498 patch_ad1881_chained1(ac97, cidx1, 0);
1499 else if (patch_ad1881_chained1(ac97, cidx1, 0x0006)) // SDIE | ID1C
1500 patch_ad1881_chained1(ac97, cidx2, 0);
1501 else if (patch_ad1881_chained1(ac97, cidx2, 0x0006)) // SDIE | ID1C
1502 patch_ad1881_chained1(ac97, cidx1, 0);
1503 } else if (cidx2 >= 0) {
1504 patch_ad1881_chained1(ac97, cidx2, 0);
1508 static struct snd_ac97_build_ops patch_ad1881_build_ops = {
1510 .resume = ad18xx_resume
1514 static int patch_ad1881(struct snd_ac97 * ac97)
1516 static const char cfg_idxs[3][2] = {
1522 // patch for Analog Devices
1523 unsigned short codecs[3];
1527 val = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
1528 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, val);
1529 codecs[0] = patch_ad1881_unchained(ac97, 0, (1<<12));
1530 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1531 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1533 if (! (codecs[0] || codecs[1] || codecs[2]))
1536 for (idx = 0; idx < 3; idx++)
1537 if (ac97->spec.ad18xx.unchained[idx])
1538 patch_ad1881_chained(ac97, idx, cfg_idxs[idx][0], cfg_idxs[idx][1]);
1540 if (ac97->spec.ad18xx.id[1]) {
1541 ac97->flags |= AC97_AD_MULTI;
1542 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
1544 if (ac97->spec.ad18xx.id[2]) {
1545 ac97->flags |= AC97_AD_MULTI;
1546 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
1550 /* select all codecs */
1551 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
1552 /* check if only one codec is present */
1553 for (idx = num = 0; idx < 3; idx++)
1554 if (ac97->spec.ad18xx.id[idx])
1557 /* ok, deselect all ID bits */
1558 snd_ac97_write_cache(ac97, AC97_AD_CODEC_CFG, 0x0000);
1559 ac97->spec.ad18xx.codec_cfg[0] =
1560 ac97->spec.ad18xx.codec_cfg[1] =
1561 ac97->spec.ad18xx.codec_cfg[2] = 0x0000;
1563 /* required for AD1886/AD1885 combination */
1564 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
1565 if (ac97->spec.ad18xx.id[0]) {
1566 ac97->id &= 0xffff0000;
1567 ac97->id |= ac97->spec.ad18xx.id[0];
1569 ac97->build_ops = &patch_ad1881_build_ops;
1573 static const struct snd_kcontrol_new snd_ac97_controls_ad1885[] = {
1574 AC97_SINGLE("Digital Mono Direct", AC97_AD_MISC, 11, 1, 0),
1575 /* AC97_SINGLE("Digital Audio Mode", AC97_AD_MISC, 12, 1, 0), */ /* seems problematic */
1576 AC97_SINGLE("Low Power Mixer", AC97_AD_MISC, 14, 1, 0),
1577 AC97_SINGLE("Zero Fill DAC", AC97_AD_MISC, 15, 1, 0),
1578 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 9, 1, 1), /* inverted */
1579 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 8, 1, 1), /* inverted */
1582 static const DECLARE_TLV_DB_SCALE(db_scale_6bit_6db_max, -8850, 150, 0);
1584 static int patch_ad1885_specific(struct snd_ac97 * ac97)
1588 if ((err = patch_build_controls(ac97, snd_ac97_controls_ad1885, ARRAY_SIZE(snd_ac97_controls_ad1885))) < 0)
1590 reset_tlv(ac97, "Headphone Playback Volume",
1591 db_scale_6bit_6db_max);
1595 static struct snd_ac97_build_ops patch_ad1885_build_ops = {
1596 .build_specific = &patch_ad1885_specific,
1598 .resume = ad18xx_resume
1602 static int patch_ad1885(struct snd_ac97 * ac97)
1605 /* This is required to deal with the Intel D815EEAL2 */
1606 /* i.e. Line out is actually headphone out from codec */
1609 snd_ac97_write_cache(ac97, AC97_AD_MISC, 0x0404);
1611 ac97->build_ops = &patch_ad1885_build_ops;
1615 static int patch_ad1886_specific(struct snd_ac97 * ac97)
1617 reset_tlv(ac97, "Headphone Playback Volume",
1618 db_scale_6bit_6db_max);
1622 static struct snd_ac97_build_ops patch_ad1886_build_ops = {
1623 .build_specific = &patch_ad1886_specific,
1625 .resume = ad18xx_resume
1629 static int patch_ad1886(struct snd_ac97 * ac97)
1632 /* Presario700 workaround */
1633 /* for Jack Sense/SPDIF Register misetting causing */
1634 snd_ac97_write_cache(ac97, AC97_AD_JACK_SPDIF, 0x0010);
1635 ac97->build_ops = &patch_ad1886_build_ops;
1639 /* MISC bits (AD1888/AD1980/AD1985 register 0x76) */
1640 #define AC97_AD198X_MBC 0x0003 /* mic boost */
1641 #define AC97_AD198X_MBC_20 0x0000 /* +20dB */
1642 #define AC97_AD198X_MBC_10 0x0001 /* +10dB */
1643 #define AC97_AD198X_MBC_30 0x0002 /* +30dB */
1644 #define AC97_AD198X_VREFD 0x0004 /* VREF high-Z */
1645 #define AC97_AD198X_VREFH 0x0008 /* 0=2.25V, 1=3.7V */
1646 #define AC97_AD198X_VREF_0 0x000c /* 0V (AD1985 only) */
1647 #define AC97_AD198X_VREF_MASK (AC97_AD198X_VREFH | AC97_AD198X_VREFD)
1648 #define AC97_AD198X_VREF_SHIFT 2
1649 #define AC97_AD198X_SRU 0x0010 /* sample rate unlock */
1650 #define AC97_AD198X_LOSEL 0x0020 /* LINE_OUT amplifiers input select */
1651 #define AC97_AD198X_2MIC 0x0040 /* 2-channel mic select */
1652 #define AC97_AD198X_SPRD 0x0080 /* SPREAD enable */
1653 #define AC97_AD198X_DMIX0 0x0100 /* downmix mode: */
1654 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
1655 #define AC97_AD198X_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1656 #define AC97_AD198X_HPSEL 0x0400 /* headphone amplifier input select */
1657 #define AC97_AD198X_CLDIS 0x0800 /* center/lfe disable */
1658 #define AC97_AD198X_LODIS 0x1000 /* LINE_OUT disable */
1659 #define AC97_AD198X_MSPLT 0x2000 /* mute split */
1660 #define AC97_AD198X_AC97NC 0x4000 /* AC97 no compatible mode */
1661 #define AC97_AD198X_DACZ 0x8000 /* DAC zero-fill mode */
1663 /* MISC 1 bits (AD1986 register 0x76) */
1664 #define AC97_AD1986_MBC 0x0003 /* mic boost */
1665 #define AC97_AD1986_MBC_20 0x0000 /* +20dB */
1666 #define AC97_AD1986_MBC_10 0x0001 /* +10dB */
1667 #define AC97_AD1986_MBC_30 0x0002 /* +30dB */
1668 #define AC97_AD1986_LISEL0 0x0004 /* LINE_IN select bit 0 */
1669 #define AC97_AD1986_LISEL1 0x0008 /* LINE_IN select bit 1 */
1670 #define AC97_AD1986_LISEL_MASK (AC97_AD1986_LISEL1 | AC97_AD1986_LISEL0)
1671 #define AC97_AD1986_LISEL_LI 0x0000 /* LINE_IN pins as LINE_IN source */
1672 #define AC97_AD1986_LISEL_SURR 0x0004 /* SURROUND pins as LINE_IN source */
1673 #define AC97_AD1986_LISEL_MIC 0x0008 /* MIC_1/2 pins as LINE_IN source */
1674 #define AC97_AD1986_SRU 0x0010 /* sample rate unlock */
1675 #define AC97_AD1986_SOSEL 0x0020 /* SURROUND_OUT amplifiers input sel */
1676 #define AC97_AD1986_2MIC 0x0040 /* 2-channel mic select */
1677 #define AC97_AD1986_SPRD 0x0080 /* SPREAD enable */
1678 #define AC97_AD1986_DMIX0 0x0100 /* downmix mode: */
1679 /* 0 = 6-to-4, 1 = 6-to-2 downmix */
1680 #define AC97_AD1986_DMIX1 0x0200 /* downmix mode: 1 = enabled */
1681 #define AC97_AD1986_CLDIS 0x0800 /* center/lfe disable */
1682 #define AC97_AD1986_SODIS 0x1000 /* SURROUND_OUT disable */
1683 #define AC97_AD1986_MSPLT 0x2000 /* mute split (read only 1) */
1684 #define AC97_AD1986_AC97NC 0x4000 /* AC97 no compatible mode (r/o 1) */
1685 #define AC97_AD1986_DACZ 0x8000 /* DAC zero-fill mode */
1687 /* MISC 2 bits (AD1986 register 0x70) */
1688 #define AC97_AD_MISC2 0x70 /* Misc Control Bits 2 (AD1986) */
1690 #define AC97_AD1986_CVREF0 0x0004 /* C/LFE VREF_OUT 2.25V */
1691 #define AC97_AD1986_CVREF1 0x0008 /* C/LFE VREF_OUT 0V */
1692 #define AC97_AD1986_CVREF2 0x0010 /* C/LFE VREF_OUT 3.7V */
1693 #define AC97_AD1986_CVREF_MASK \
1694 (AC97_AD1986_CVREF2 | AC97_AD1986_CVREF1 | AC97_AD1986_CVREF0)
1695 #define AC97_AD1986_JSMAP 0x0020 /* Jack Sense Mapping 1 = alternate */
1696 #define AC97_AD1986_MMDIS 0x0080 /* Mono Mute Disable */
1697 #define AC97_AD1986_MVREF0 0x0400 /* MIC VREF_OUT 2.25V */
1698 #define AC97_AD1986_MVREF1 0x0800 /* MIC VREF_OUT 0V */
1699 #define AC97_AD1986_MVREF2 0x1000 /* MIC VREF_OUT 3.7V */
1700 #define AC97_AD1986_MVREF_MASK \
1701 (AC97_AD1986_MVREF2 | AC97_AD1986_MVREF1 | AC97_AD1986_MVREF0)
1703 /* MISC 3 bits (AD1986 register 0x7a) */
1704 #define AC97_AD_MISC3 0x7a /* Misc Control Bits 3 (AD1986) */
1706 #define AC97_AD1986_MMIX 0x0004 /* Mic Mix, left/right */
1707 #define AC97_AD1986_GPO 0x0008 /* General Purpose Out */
1708 #define AC97_AD1986_LOHPEN 0x0010 /* LINE_OUT headphone drive */
1709 #define AC97_AD1986_LVREF0 0x0100 /* LINE_OUT VREF_OUT 2.25V */
1710 #define AC97_AD1986_LVREF1 0x0200 /* LINE_OUT VREF_OUT 0V */
1711 #define AC97_AD1986_LVREF2 0x0400 /* LINE_OUT VREF_OUT 3.7V */
1712 #define AC97_AD1986_LVREF_MASK \
1713 (AC97_AD1986_LVREF2 | AC97_AD1986_LVREF1 | AC97_AD1986_LVREF0)
1714 #define AC97_AD1986_JSINVA 0x0800 /* Jack Sense Invert SENSE_A */
1715 #define AC97_AD1986_LOSEL 0x1000 /* LINE_OUT amplifiers input select */
1716 #define AC97_AD1986_HPSEL0 0x2000 /* Headphone amplifiers */
1717 /* input select Surround DACs */
1718 #define AC97_AD1986_HPSEL1 0x4000 /* Headphone amplifiers input */
1719 /* select C/LFE DACs */
1720 #define AC97_AD1986_JSINVB 0x8000 /* Jack Sense Invert SENSE_B */
1722 /* Serial Config bits (AD1986 register 0x74) (incomplete) */
1723 #define AC97_AD1986_OMS0 0x0100 /* Optional Mic Selector bit 0 */
1724 #define AC97_AD1986_OMS1 0x0200 /* Optional Mic Selector bit 1 */
1725 #define AC97_AD1986_OMS2 0x0400 /* Optional Mic Selector bit 2 */
1726 #define AC97_AD1986_OMS_MASK \
1727 (AC97_AD1986_OMS2 | AC97_AD1986_OMS1 | AC97_AD1986_OMS0)
1728 #define AC97_AD1986_OMS_M 0x0000 /* MIC_1/2 pins are MIC sources */
1729 #define AC97_AD1986_OMS_L 0x0100 /* LINE_IN pins are MIC sources */
1730 #define AC97_AD1986_OMS_C 0x0200 /* Center/LFE pins are MCI sources */
1731 #define AC97_AD1986_OMS_MC 0x0400 /* Mix of MIC and C/LFE pins */
1732 /* are MIC sources */
1733 #define AC97_AD1986_OMS_ML 0x0500 /* MIX of MIC and LINE_IN pins */
1734 /* are MIC sources */
1735 #define AC97_AD1986_OMS_LC 0x0600 /* MIX of LINE_IN and C/LFE pins */
1736 /* are MIC sources */
1737 #define AC97_AD1986_OMS_MLC 0x0700 /* MIX of MIC, LINE_IN, C/LFE pins */
1738 /* are MIC sources */
1741 static int snd_ac97_ad198x_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1743 static char *texts[2] = { "AC-Link", "A/D Converter" };
1745 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1747 uinfo->value.enumerated.items = 2;
1748 if (uinfo->value.enumerated.item > 1)
1749 uinfo->value.enumerated.item = 1;
1750 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1754 static int snd_ac97_ad198x_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1756 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1759 val = ac97->regs[AC97_AD_SERIAL_CFG];
1760 ucontrol->value.enumerated.item[0] = (val >> 2) & 1;
1764 static int snd_ac97_ad198x_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1766 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1769 if (ucontrol->value.enumerated.item[0] > 1)
1771 val = ucontrol->value.enumerated.item[0] << 2;
1772 return snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x0004, val);
1775 static const struct snd_kcontrol_new snd_ac97_ad198x_spdif_source = {
1776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1777 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1778 .info = snd_ac97_ad198x_spdif_source_info,
1779 .get = snd_ac97_ad198x_spdif_source_get,
1780 .put = snd_ac97_ad198x_spdif_source_put,
1783 static int patch_ad198x_post_spdif(struct snd_ac97 * ac97)
1785 return patch_build_controls(ac97, &snd_ac97_ad198x_spdif_source, 1);
1788 static const struct snd_kcontrol_new snd_ac97_ad1981x_jack_sense[] = {
1789 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 11, 1, 0),
1790 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
1793 /* black list to avoid HP/Line jack-sense controls
1794 * (SS vendor << 16 | device)
1796 static unsigned int ad1981_jacks_blacklist[] = {
1797 0x10140523, /* Thinkpad R40 */
1798 0x10140534, /* Thinkpad X31 */
1799 0x10140537, /* Thinkpad T41p */
1800 0x10140554, /* Thinkpad T42p/R50p */
1801 0x10140567, /* Thinkpad T43p 2668-G7U */
1802 0x10140581, /* Thinkpad X41-2527 */
1803 0x104380b0, /* Asus A7V8X-MX */
1804 0x11790241, /* Toshiba Satellite A-15 S127 */
1805 0x144dc01a, /* Samsung NP-X20C004/SEG */
1809 static int check_list(struct snd_ac97 *ac97, const unsigned int *list)
1811 u32 subid = ((u32)ac97->subsystem_vendor << 16) | ac97->subsystem_device;
1812 for (; *list; list++)
1818 static int patch_ad1981a_specific(struct snd_ac97 * ac97)
1820 if (check_list(ac97, ad1981_jacks_blacklist))
1822 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1823 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1826 static struct snd_ac97_build_ops patch_ad1981a_build_ops = {
1827 .build_post_spdif = patch_ad198x_post_spdif,
1828 .build_specific = patch_ad1981a_specific,
1830 .resume = ad18xx_resume
1834 /* white list to enable HP jack-sense bits
1835 * (SS vendor << 16 | device)
1837 static unsigned int ad1981_jacks_whitelist[] = {
1838 0x0e11005a, /* HP nc4000/4010 */
1839 0x103c0890, /* HP nc6000 */
1840 0x103c0938, /* HP nc4220 */
1841 0x103c099c, /* HP nx6110 */
1842 0x103c0944, /* HP nc6220 */
1843 0x103c0934, /* HP nc8220 */
1844 0x103c006d, /* HP nx9105 */
1845 0x17340088, /* FSC Scenic-W */
1849 static void check_ad1981_hp_jack_sense(struct snd_ac97 *ac97)
1851 if (check_list(ac97, ad1981_jacks_whitelist))
1852 /* enable headphone jack sense */
1853 snd_ac97_update_bits(ac97, AC97_AD_JACK_SPDIF, 1<<11, 1<<11);
1856 static int patch_ad1981a(struct snd_ac97 *ac97)
1859 ac97->build_ops = &patch_ad1981a_build_ops;
1860 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1861 ac97->flags |= AC97_STEREO_MUTES;
1862 check_ad1981_hp_jack_sense(ac97);
1866 static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
1867 AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);
1869 static int patch_ad1981b_specific(struct snd_ac97 *ac97)
1873 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
1875 if (check_list(ac97, ad1981_jacks_blacklist))
1877 return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
1878 ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
1881 static struct snd_ac97_build_ops patch_ad1981b_build_ops = {
1882 .build_post_spdif = patch_ad198x_post_spdif,
1883 .build_specific = patch_ad1981b_specific,
1885 .resume = ad18xx_resume
1889 static int patch_ad1981b(struct snd_ac97 *ac97)
1892 ac97->build_ops = &patch_ad1981b_build_ops;
1893 snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD198X_MSPLT, AC97_AD198X_MSPLT);
1894 ac97->flags |= AC97_STEREO_MUTES;
1895 check_ad1981_hp_jack_sense(ac97);
1899 #define snd_ac97_ad1888_lohpsel_info snd_ctl_boolean_mono_info
1901 static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1903 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1906 val = ac97->regs[AC97_AD_MISC];
1907 ucontrol->value.integer.value[0] = !(val & AC97_AD198X_LOSEL);
1911 static int snd_ac97_ad1888_lohpsel_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1913 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1916 val = !ucontrol->value.integer.value[0]
1917 ? (AC97_AD198X_LOSEL | AC97_AD198X_HPSEL) : 0;
1918 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1919 AC97_AD198X_LOSEL | AC97_AD198X_HPSEL, val);
1922 static int snd_ac97_ad1888_downmix_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1924 static char *texts[3] = {"Off", "6 -> 4", "6 -> 2"};
1926 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1928 uinfo->value.enumerated.items = 3;
1929 if (uinfo->value.enumerated.item > 2)
1930 uinfo->value.enumerated.item = 2;
1931 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1935 static int snd_ac97_ad1888_downmix_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1937 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1940 val = ac97->regs[AC97_AD_MISC];
1941 if (!(val & AC97_AD198X_DMIX1))
1942 ucontrol->value.enumerated.item[0] = 0;
1944 ucontrol->value.enumerated.item[0] = 1 + ((val >> 8) & 1);
1948 static int snd_ac97_ad1888_downmix_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1950 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
1953 if (ucontrol->value.enumerated.item[0] > 2)
1955 if (ucontrol->value.enumerated.item[0] == 0)
1958 val = AC97_AD198X_DMIX1 |
1959 ((ucontrol->value.enumerated.item[0] - 1) << 8);
1960 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
1961 AC97_AD198X_DMIX0 | AC97_AD198X_DMIX1, val);
1964 static void ad1888_update_jacks(struct snd_ac97 *ac97)
1966 unsigned short val = 0;
1967 /* clear LODIS if shared jack is to be used for Surround out */
1968 if (is_shared_linein(ac97))
1970 /* clear CLDIS if shared jack is to be used for C/LFE out */
1971 if (is_shared_micin(ac97))
1973 /* shared Line-In */
1974 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
1977 static const struct snd_kcontrol_new snd_ac97_ad1888_controls[] = {
1979 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1980 .name = "Exchange Front/Surround",
1981 .info = snd_ac97_ad1888_lohpsel_info,
1982 .get = snd_ac97_ad1888_lohpsel_get,
1983 .put = snd_ac97_ad1888_lohpsel_put
1985 AC97_SINGLE("V_REFOUT Enable", AC97_AD_MISC, 2, 1, 1),
1986 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
1987 AC97_SINGLE("Spread Front to Surround and Center/LFE", AC97_AD_MISC, 7, 1, 0),
1989 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1991 .info = snd_ac97_ad1888_downmix_info,
1992 .get = snd_ac97_ad1888_downmix_get,
1993 .put = snd_ac97_ad1888_downmix_put
1995 AC97_SURROUND_JACK_MODE_CTL,
1996 AC97_CHANNEL_MODE_CTL,
1998 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
1999 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
2002 static int patch_ad1888_specific(struct snd_ac97 *ac97)
2004 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2005 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Master Surround Playback");
2006 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2007 return patch_build_controls(ac97, snd_ac97_ad1888_controls, ARRAY_SIZE(snd_ac97_ad1888_controls));
2010 static struct snd_ac97_build_ops patch_ad1888_build_ops = {
2011 .build_post_spdif = patch_ad198x_post_spdif,
2012 .build_specific = patch_ad1888_specific,
2014 .resume = ad1888_resume,
2016 .update_jacks = ad1888_update_jacks,
2019 static int patch_ad1888(struct snd_ac97 * ac97)
2021 unsigned short misc;
2024 ac97->build_ops = &patch_ad1888_build_ops;
2025 /* Switch FRONT/SURROUND LINE-OUT/HP-OUT default connection */
2026 /* it seems that most vendors connect line-out connector to headphone out of AC'97 */
2027 /* AD-compatible mode */
2028 /* Stereo mutes enabled */
2029 misc = snd_ac97_read(ac97, AC97_AD_MISC);
2030 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
2034 AC97_AD198X_AC97NC);
2035 ac97->flags |= AC97_STEREO_MUTES;
2039 static int patch_ad1980_specific(struct snd_ac97 *ac97)
2043 if ((err = patch_ad1888_specific(ac97)) < 0)
2045 return patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1);
2048 static struct snd_ac97_build_ops patch_ad1980_build_ops = {
2049 .build_post_spdif = patch_ad198x_post_spdif,
2050 .build_specific = patch_ad1980_specific,
2052 .resume = ad18xx_resume,
2054 .update_jacks = ad1888_update_jacks,
2057 static int patch_ad1980(struct snd_ac97 * ac97)
2060 ac97->build_ops = &patch_ad1980_build_ops;
2064 static int snd_ac97_ad1985_vrefout_info(struct snd_kcontrol *kcontrol,
2065 struct snd_ctl_elem_info *uinfo)
2067 static char *texts[4] = {"High-Z", "3.7 V", "2.25 V", "0 V"};
2069 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2071 uinfo->value.enumerated.items = 4;
2072 if (uinfo->value.enumerated.item > 3)
2073 uinfo->value.enumerated.item = 3;
2074 strcpy(uinfo->value.enumerated.name,
2075 texts[uinfo->value.enumerated.item]);
2079 static int snd_ac97_ad1985_vrefout_get(struct snd_kcontrol *kcontrol,
2080 struct snd_ctl_elem_value *ucontrol)
2082 static const int reg2ctrl[4] = {2, 0, 1, 3};
2083 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2085 val = (ac97->regs[AC97_AD_MISC] & AC97_AD198X_VREF_MASK)
2086 >> AC97_AD198X_VREF_SHIFT;
2087 ucontrol->value.enumerated.item[0] = reg2ctrl[val];
2091 static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol,
2092 struct snd_ctl_elem_value *ucontrol)
2094 static const int ctrl2reg[4] = {1, 2, 0, 3};
2095 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2098 if (ucontrol->value.enumerated.item[0] > 3
2099 || ucontrol->value.enumerated.item[0] < 0)
2101 val = ctrl2reg[ucontrol->value.enumerated.item[0]]
2102 << AC97_AD198X_VREF_SHIFT;
2103 return snd_ac97_update_bits(ac97, AC97_AD_MISC,
2104 AC97_AD198X_VREF_MASK, val);
2107 static const struct snd_kcontrol_new snd_ac97_ad1985_controls[] = {
2108 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2110 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2111 .name = "Exchange Front/Surround",
2112 .info = snd_ac97_ad1888_lohpsel_info,
2113 .get = snd_ac97_ad1888_lohpsel_get,
2114 .put = snd_ac97_ad1888_lohpsel_put
2116 AC97_SINGLE("High Pass Filter Enable", AC97_AD_TEST2, 12, 1, 1),
2117 AC97_SINGLE("Spread Front to Surround and Center/LFE",
2118 AC97_AD_MISC, 7, 1, 0),
2120 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2122 .info = snd_ac97_ad1888_downmix_info,
2123 .get = snd_ac97_ad1888_downmix_get,
2124 .put = snd_ac97_ad1888_downmix_put
2127 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2129 .info = snd_ac97_ad1985_vrefout_info,
2130 .get = snd_ac97_ad1985_vrefout_get,
2131 .put = snd_ac97_ad1985_vrefout_put
2133 AC97_SURROUND_JACK_MODE_CTL,
2134 AC97_CHANNEL_MODE_CTL,
2136 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2137 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0),
2140 static void ad1985_update_jacks(struct snd_ac97 *ac97)
2142 ad1888_update_jacks(ac97);
2143 /* clear OMS if shared jack is to be used for C/LFE out */
2144 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
2145 is_shared_micin(ac97) ? 1 << 9 : 0);
2148 static int patch_ad1985_specific(struct snd_ac97 *ac97)
2152 /* rename 0x04 as "Master" and 0x02 as "Master Surround" */
2153 snd_ac97_rename_vol_ctl(ac97, "Master Playback",
2154 "Master Surround Playback");
2155 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2157 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
2160 return patch_build_controls(ac97, snd_ac97_ad1985_controls,
2161 ARRAY_SIZE(snd_ac97_ad1985_controls));
2164 static struct snd_ac97_build_ops patch_ad1985_build_ops = {
2165 .build_post_spdif = patch_ad198x_post_spdif,
2166 .build_specific = patch_ad1985_specific,
2168 .resume = ad18xx_resume,
2170 .update_jacks = ad1985_update_jacks,
2173 static int patch_ad1985(struct snd_ac97 * ac97)
2175 unsigned short misc;
2178 ac97->build_ops = &patch_ad1985_build_ops;
2179 misc = snd_ac97_read(ac97, AC97_AD_MISC);
2180 /* switch front/surround line-out/hp-out */
2181 /* AD-compatible mode */
2182 /* Stereo mutes enabled */
2183 snd_ac97_write_cache(ac97, AC97_AD_MISC, misc |
2187 AC97_AD198X_AC97NC);
2188 ac97->flags |= AC97_STEREO_MUTES;
2190 /* update current jack configuration */
2191 ad1985_update_jacks(ac97);
2193 /* on AD1985 rev. 3, AC'97 revision bits are zero */
2194 ac97->ext_id = (ac97->ext_id & ~AC97_EI_REV_MASK) | AC97_EI_REV_23;
2198 #define snd_ac97_ad1986_bool_info snd_ctl_boolean_mono_info
2200 static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol,
2201 struct snd_ctl_elem_value *ucontrol)
2203 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2206 val = ac97->regs[AC97_AD_MISC3];
2207 ucontrol->value.integer.value[0] = (val & AC97_AD1986_LOSEL) != 0;
2211 static int snd_ac97_ad1986_lososel_put(struct snd_kcontrol *kcontrol,
2212 struct snd_ctl_elem_value *ucontrol)
2214 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2217 int sprd = (ac97->regs[AC97_AD_MISC] & AC97_AD1986_SPRD) != 0;
2219 ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC3, AC97_AD1986_LOSEL,
2220 ucontrol->value.integer.value[0] != 0
2221 ? AC97_AD1986_LOSEL : 0);
2225 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2226 ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2227 (ucontrol->value.integer.value[0] != 0
2229 ? AC97_AD1986_SOSEL : 0);
2233 return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2236 static int snd_ac97_ad1986_spread_get(struct snd_kcontrol *kcontrol,
2237 struct snd_ctl_elem_value *ucontrol)
2239 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2242 val = ac97->regs[AC97_AD_MISC];
2243 ucontrol->value.integer.value[0] = (val & AC97_AD1986_SPRD) != 0;
2247 static int snd_ac97_ad1986_spread_put(struct snd_kcontrol *kcontrol,
2248 struct snd_ctl_elem_value *ucontrol)
2250 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2253 int sprd = (ac97->regs[AC97_AD_MISC3] & AC97_AD1986_LOSEL) != 0;
2255 ret0 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SPRD,
2256 ucontrol->value.integer.value[0] != 0
2257 ? AC97_AD1986_SPRD : 0);
2261 /* SOSEL is set to values of "Spread" or "Exchange F/S" controls */
2262 ret1 = snd_ac97_update_bits(ac97, AC97_AD_MISC, AC97_AD1986_SOSEL,
2263 (ucontrol->value.integer.value[0] != 0
2265 ? AC97_AD1986_SOSEL : 0);
2269 return (ret0 > 0 || ret1 > 0) ? 1 : 0;
2272 static int snd_ac97_ad1986_miclisel_get(struct snd_kcontrol *kcontrol,
2273 struct snd_ctl_elem_value *ucontrol)
2275 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2277 ucontrol->value.integer.value[0] = ac97->spec.ad18xx.swap_mic_linein;
2281 static int snd_ac97_ad1986_miclisel_put(struct snd_kcontrol *kcontrol,
2282 struct snd_ctl_elem_value *ucontrol)
2284 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2285 unsigned char swap = ucontrol->value.integer.value[0] != 0;
2287 if (swap != ac97->spec.ad18xx.swap_mic_linein) {
2288 ac97->spec.ad18xx.swap_mic_linein = swap;
2289 if (ac97->build_ops->update_jacks)
2290 ac97->build_ops->update_jacks(ac97);
2296 static int snd_ac97_ad1986_vrefout_get(struct snd_kcontrol *kcontrol,
2297 struct snd_ctl_elem_value *ucontrol)
2299 /* Use MIC_1/2 V_REFOUT as the "get" value */
2300 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2302 unsigned short reg = ac97->regs[AC97_AD_MISC2];
2303 if ((reg & AC97_AD1986_MVREF0) != 0)
2305 else if ((reg & AC97_AD1986_MVREF1) != 0)
2307 else if ((reg & AC97_AD1986_MVREF2) != 0)
2311 ucontrol->value.enumerated.item[0] = val;
2315 static int snd_ac97_ad1986_vrefout_put(struct snd_kcontrol *kcontrol,
2316 struct snd_ctl_elem_value *ucontrol)
2318 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2319 unsigned short cval;
2320 unsigned short lval;
2321 unsigned short mval;
2326 switch (ucontrol->value.enumerated.item[0])
2328 case 0: /* High-Z */
2334 cval = AC97_AD1986_CVREF2;
2335 lval = AC97_AD1986_LVREF2;
2336 mval = AC97_AD1986_MVREF2;
2338 case 2: /* 2.25 V */
2339 cval = AC97_AD1986_CVREF0;
2340 lval = AC97_AD1986_LVREF0;
2341 mval = AC97_AD1986_MVREF0;
2344 cval = AC97_AD1986_CVREF1;
2345 lval = AC97_AD1986_LVREF1;
2346 mval = AC97_AD1986_MVREF1;
2352 cret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2353 AC97_AD1986_CVREF_MASK, cval);
2356 lret = snd_ac97_update_bits(ac97, AC97_AD_MISC3,
2357 AC97_AD1986_LVREF_MASK, lval);
2360 mret = snd_ac97_update_bits(ac97, AC97_AD_MISC2,
2361 AC97_AD1986_MVREF_MASK, mval);
2365 return (cret > 0 || lret > 0 || mret > 0) ? 1 : 0;
2368 static const struct snd_kcontrol_new snd_ac97_ad1986_controls[] = {
2369 AC97_SINGLE("Exchange Center/LFE", AC97_AD_SERIAL_CFG, 3, 1, 0),
2371 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2372 .name = "Exchange Front/Surround",
2373 .info = snd_ac97_ad1986_bool_info,
2374 .get = snd_ac97_ad1986_lososel_get,
2375 .put = snd_ac97_ad1986_lososel_put
2378 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2379 .name = "Exchange Mic/Line In",
2380 .info = snd_ac97_ad1986_bool_info,
2381 .get = snd_ac97_ad1986_miclisel_get,
2382 .put = snd_ac97_ad1986_miclisel_put
2385 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2386 .name = "Spread Front to Surround and Center/LFE",
2387 .info = snd_ac97_ad1986_bool_info,
2388 .get = snd_ac97_ad1986_spread_get,
2389 .put = snd_ac97_ad1986_spread_put
2392 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2394 .info = snd_ac97_ad1888_downmix_info,
2395 .get = snd_ac97_ad1888_downmix_get,
2396 .put = snd_ac97_ad1888_downmix_put
2399 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2401 .info = snd_ac97_ad1985_vrefout_info,
2402 .get = snd_ac97_ad1986_vrefout_get,
2403 .put = snd_ac97_ad1986_vrefout_put
2405 AC97_SURROUND_JACK_MODE_CTL,
2406 AC97_CHANNEL_MODE_CTL,
2408 AC97_SINGLE("Headphone Jack Sense", AC97_AD_JACK_SPDIF, 10, 1, 0),
2409 AC97_SINGLE("Line Jack Sense", AC97_AD_JACK_SPDIF, 12, 1, 0)
2412 static void ad1986_update_jacks(struct snd_ac97 *ac97)
2414 unsigned short misc_val = 0;
2415 unsigned short ser_val;
2417 /* disable SURROUND and CENTER/LFE if not surround mode */
2418 if (!is_surround_on(ac97))
2419 misc_val |= AC97_AD1986_SODIS;
2420 if (!is_clfe_on(ac97))
2421 misc_val |= AC97_AD1986_CLDIS;
2423 /* select line input (default=LINE_IN, SURROUND or MIC_1/2) */
2424 if (is_shared_linein(ac97))
2425 misc_val |= AC97_AD1986_LISEL_SURR;
2426 else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2427 misc_val |= AC97_AD1986_LISEL_MIC;
2428 snd_ac97_update_bits(ac97, AC97_AD_MISC,
2429 AC97_AD1986_SODIS | AC97_AD1986_CLDIS |
2430 AC97_AD1986_LISEL_MASK,
2433 /* select microphone input (MIC_1/2, Center/LFE or LINE_IN) */
2434 if (is_shared_micin(ac97))
2435 ser_val = AC97_AD1986_OMS_C;
2436 else if (ac97->spec.ad18xx.swap_mic_linein != 0)
2437 ser_val = AC97_AD1986_OMS_L;
2439 ser_val = AC97_AD1986_OMS_M;
2440 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG,
2441 AC97_AD1986_OMS_MASK,
2445 static int patch_ad1986_specific(struct snd_ac97 *ac97)
2449 if ((err = patch_build_controls(ac97, &snd_ac97_ad198x_2cmic, 1)) < 0)
2452 return patch_build_controls(ac97, snd_ac97_ad1986_controls,
2453 ARRAY_SIZE(snd_ac97_ad1985_controls));
2456 static struct snd_ac97_build_ops patch_ad1986_build_ops = {
2457 .build_post_spdif = patch_ad198x_post_spdif,
2458 .build_specific = patch_ad1986_specific,
2460 .resume = ad18xx_resume,
2462 .update_jacks = ad1986_update_jacks,
2465 static int patch_ad1986(struct snd_ac97 * ac97)
2468 ac97->build_ops = &patch_ad1986_build_ops;
2469 ac97->flags |= AC97_STEREO_MUTES;
2471 /* update current jack configuration */
2472 ad1986_update_jacks(ac97);
2479 * realtek ALC65x/850 codecs
2481 static void alc650_update_jacks(struct snd_ac97 *ac97)
2485 /* shared Line-In / Surround Out */
2486 shared = is_shared_surrout(ac97);
2487 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 9,
2488 shared ? (1 << 9) : 0);
2489 /* update shared Mic In / Center/LFE Out */
2490 shared = is_shared_clfeout(ac97);
2491 /* disable/enable vref */
2492 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2493 shared ? (1 << 12) : 0);
2494 /* turn on/off center-on-mic */
2495 snd_ac97_update_bits(ac97, AC97_ALC650_MULTICH, 1 << 10,
2496 shared ? (1 << 10) : 0);
2497 /* GPIO0 high for mic */
2498 snd_ac97_update_bits(ac97, AC97_ALC650_GPIO_STATUS, 0x100,
2499 shared ? 0 : 0x100);
2502 static const struct snd_kcontrol_new snd_ac97_controls_alc650[] = {
2503 AC97_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0),
2504 AC97_SINGLE("Surround Down Mix", AC97_ALC650_MULTICH, 1, 1, 0),
2505 AC97_SINGLE("Center/LFE Down Mix", AC97_ALC650_MULTICH, 2, 1, 0),
2506 AC97_SINGLE("Exchange Center/LFE", AC97_ALC650_MULTICH, 3, 1, 0),
2507 /* 4: Analog Input To Surround */
2508 /* 5: Analog Input To Center/LFE */
2509 /* 6: Independent Master Volume Right */
2510 /* 7: Independent Master Volume Left */
2512 /* 9: Line-In/Surround share */
2513 /* 10: Mic/CLFE share */
2514 /* 11-13: in IEC958 controls */
2515 AC97_SINGLE("Swap Surround Slot", AC97_ALC650_MULTICH, 14, 1, 0),
2516 #if 0 /* always set in patch_alc650 */
2517 AC97_SINGLE("IEC958 Input Clock Enable", AC97_ALC650_CLOCK, 0, 1, 0),
2518 AC97_SINGLE("IEC958 Input Pin Enable", AC97_ALC650_CLOCK, 1, 1, 0),
2519 AC97_SINGLE("Surround DAC Switch", AC97_ALC650_SURR_DAC_VOL, 15, 1, 1),
2520 AC97_DOUBLE("Surround DAC Volume", AC97_ALC650_SURR_DAC_VOL, 8, 0, 31, 1),
2521 AC97_SINGLE("Center/LFE DAC Switch", AC97_ALC650_LFE_DAC_VOL, 15, 1, 1),
2522 AC97_DOUBLE("Center/LFE DAC Volume", AC97_ALC650_LFE_DAC_VOL, 8, 0, 31, 1),
2524 AC97_SURROUND_JACK_MODE_CTL,
2525 AC97_CHANNEL_MODE_CTL,
2528 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc650[] = {
2529 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0),
2530 AC97_SINGLE("Analog to IEC958 Output", AC97_ALC650_MULTICH, 12, 1, 0),
2531 /* disable this controls since it doesn't work as expected */
2532 /* AC97_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 13, 1, 0), */
2535 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_max, -4350, 150, 0);
2537 static int patch_alc650_specific(struct snd_ac97 * ac97)
2541 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc650, ARRAY_SIZE(snd_ac97_controls_alc650))) < 0)
2543 if (ac97->ext_id & AC97_EI_SPDIF) {
2544 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc650, ARRAY_SIZE(snd_ac97_spdif_controls_alc650))) < 0)
2547 if (ac97->id != AC97_ID_ALC650F)
2548 reset_tlv(ac97, "Master Playback Volume",
2549 db_scale_5bit_3db_max);
2553 static struct snd_ac97_build_ops patch_alc650_ops = {
2554 .build_specific = patch_alc650_specific,
2555 .update_jacks = alc650_update_jacks
2558 static int patch_alc650(struct snd_ac97 * ac97)
2562 ac97->build_ops = &patch_alc650_ops;
2564 /* determine the revision */
2565 val = snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f;
2567 ac97->id = 0x414c4720; /* Old version */
2568 else if (val < 0x10)
2569 ac97->id = 0x414c4721; /* D version */
2570 else if (val < 0x20)
2571 ac97->id = 0x414c4722; /* E version */
2572 else if (val < 0x30)
2573 ac97->id = 0x414c4723; /* F version */
2575 /* revision E or F */
2576 /* FIXME: what about revision D ? */
2577 ac97->spec.dev_flags = (ac97->id == 0x414c4722 ||
2578 ac97->id == 0x414c4723);
2580 /* enable AC97_ALC650_GPIO_SETUP, AC97_ALC650_CLOCK for R/W */
2581 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2582 snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x8000);
2584 /* Enable SPDIF-IN only on Rev.E and above */
2585 val = snd_ac97_read(ac97, AC97_ALC650_CLOCK);
2586 /* SPDIF IN with pin 47 */
2587 if (ac97->spec.dev_flags &&
2588 /* ASUS A6KM requires EAPD */
2589 ! (ac97->subsystem_vendor == 0x1043 &&
2590 ac97->subsystem_device == 0x1103))
2591 val |= 0x03; /* enable */
2593 val &= ~0x03; /* disable */
2594 snd_ac97_write_cache(ac97, AC97_ALC650_CLOCK, val);
2596 /* set default: slot 3,4,7,8,6,9
2597 spdif-in monitor off, analog-spdif off, spdif-in off
2598 center on mic off, surround on line-in off
2599 downmix off, duplicate front off
2601 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 0);
2603 /* set GPIO0 for mic bias */
2604 /* GPIO0 pin output, no interrupt, high */
2605 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_SETUP,
2606 snd_ac97_read(ac97, AC97_ALC650_GPIO_SETUP) | 0x01);
2607 snd_ac97_write_cache(ac97, AC97_ALC650_GPIO_STATUS,
2608 (snd_ac97_read(ac97, AC97_ALC650_GPIO_STATUS) | 0x100) & ~0x10);
2610 /* full DAC volume */
2611 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2612 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2616 static void alc655_update_jacks(struct snd_ac97 *ac97)
2620 /* shared Line-In / Surround Out */
2621 shared = is_shared_surrout(ac97);
2622 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 9,
2623 shared ? (1 << 9) : 0, 0);
2624 /* update shared Mic In / Center/LFE Out */
2625 shared = is_shared_clfeout(ac97);
2626 /* misc control; vrefout disable */
2627 snd_ac97_update_bits(ac97, AC97_ALC650_CLOCK, 1 << 12,
2628 shared ? (1 << 12) : 0);
2629 ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 1 << 10,
2630 shared ? (1 << 10) : 0, 0);
2633 static const struct snd_kcontrol_new snd_ac97_controls_alc655[] = {
2634 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2635 AC97_SURROUND_JACK_MODE_CTL,
2636 AC97_CHANNEL_MODE_CTL,
2639 static int alc655_iec958_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2641 static char *texts_655[3] = { "PCM", "Analog In", "IEC958 In" };
2642 static char *texts_658[4] = { "PCM", "Analog1 In", "Analog2 In", "IEC958 In" };
2643 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2645 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2647 uinfo->value.enumerated.items = ac97->spec.dev_flags ? 4 : 3;
2648 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2649 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2650 strcpy(uinfo->value.enumerated.name,
2651 ac97->spec.dev_flags ?
2652 texts_658[uinfo->value.enumerated.item] :
2653 texts_655[uinfo->value.enumerated.item]);
2657 static int alc655_iec958_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2659 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2662 val = ac97->regs[AC97_ALC650_MULTICH];
2663 val = (val >> 12) & 3;
2664 if (ac97->spec.dev_flags && val == 3)
2666 ucontrol->value.enumerated.item[0] = val;
2670 static int alc655_iec958_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2672 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2674 return ac97_update_bits_page(ac97, AC97_ALC650_MULTICH, 3 << 12,
2675 (unsigned short)ucontrol->value.enumerated.item[0] << 12,
2679 static const struct snd_kcontrol_new snd_ac97_spdif_controls_alc655[] = {
2680 AC97_PAGE_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_ALC650_MULTICH, 11, 1, 0, 0),
2681 /* disable this controls since it doesn't work as expected */
2682 /* AC97_PAGE_SINGLE("IEC958 Input Monitor", AC97_ALC650_MULTICH, 14, 1, 0, 0), */
2684 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2685 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2686 .info = alc655_iec958_route_info,
2687 .get = alc655_iec958_route_get,
2688 .put = alc655_iec958_route_put,
2692 static int patch_alc655_specific(struct snd_ac97 * ac97)
2696 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc655, ARRAY_SIZE(snd_ac97_controls_alc655))) < 0)
2698 if (ac97->ext_id & AC97_EI_SPDIF) {
2699 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2705 static struct snd_ac97_build_ops patch_alc655_ops = {
2706 .build_specific = patch_alc655_specific,
2707 .update_jacks = alc655_update_jacks
2710 static int patch_alc655(struct snd_ac97 * ac97)
2714 if (ac97->id == AC97_ID_ALC658) {
2715 ac97->spec.dev_flags = 1; /* ALC658 */
2716 if ((snd_ac97_read(ac97, AC97_ALC650_REVISION) & 0x3f) == 2) {
2717 ac97->id = AC97_ID_ALC658D;
2718 ac97->spec.dev_flags = 2;
2722 ac97->build_ops = &patch_alc655_ops;
2724 /* assume only page 0 for writing cache */
2725 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2727 /* adjust default values */
2728 val = snd_ac97_read(ac97, 0x7a); /* misc control */
2729 if (ac97->spec.dev_flags) /* ALC658 */
2730 val &= ~(1 << 1); /* Pin 47 is spdif input pin */
2732 if (ac97->subsystem_vendor == 0x1462 &&
2733 (ac97->subsystem_device == 0x0131 || /* MSI S270 laptop */
2734 ac97->subsystem_device == 0x0161 || /* LG K1 Express */
2735 ac97->subsystem_device == 0x0351 || /* MSI L725 laptop */
2736 ac97->subsystem_device == 0x0471 || /* MSI L720 laptop */
2737 ac97->subsystem_device == 0x0061)) /* MSI S250 laptop */
2738 val &= ~(1 << 1); /* Pin 47 is EAPD (for internal speaker) */
2740 val |= (1 << 1); /* Pin 47 is spdif input pin */
2742 val &= ~(1 << 12); /* vref enable */
2743 snd_ac97_write_cache(ac97, 0x7a, val);
2744 /* set default: spdif-in enabled,
2745 spdif-in monitor off, spdif-in PCM off
2746 center on mic off, surround on line-in off
2749 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2751 /* full DAC volume */
2752 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2753 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2755 /* update undocumented bit... */
2756 if (ac97->id == AC97_ID_ALC658D)
2757 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2763 #define AC97_ALC850_JACK_SELECT 0x76
2764 #define AC97_ALC850_MISC1 0x7a
2766 static void alc850_update_jacks(struct snd_ac97 *ac97)
2770 /* shared Line-In / Surround Out */
2771 shared = is_shared_surrout(ac97);
2772 /* SURR 1kOhm (bit4), Amp (bit5) */
2773 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<4)|(1<<5),
2774 shared ? (1<<5) : (1<<4));
2775 /* LINE-IN = 0, SURROUND = 2 */
2776 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 12,
2777 shared ? (2<<12) : (0<<12));
2778 /* update shared Mic In / Center/LFE Out */
2779 shared = is_shared_clfeout(ac97);
2780 /* Vref disable (bit12), 1kOhm (bit13) */
2781 snd_ac97_update_bits(ac97, AC97_ALC850_MISC1, (1<<12)|(1<<13),
2782 shared ? (1<<12) : (1<<13));
2783 /* MIC-IN = 1, CENTER-LFE = 5 */
2784 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2785 shared ? (5<<4) : (1<<4));
2788 static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
2789 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2790 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2791 AC97_SURROUND_JACK_MODE_CTL,
2792 AC97_CHANNEL_MODE_CTL,
2795 static int patch_alc850_specific(struct snd_ac97 *ac97)
2799 if ((err = patch_build_controls(ac97, snd_ac97_controls_alc850, ARRAY_SIZE(snd_ac97_controls_alc850))) < 0)
2801 if (ac97->ext_id & AC97_EI_SPDIF) {
2802 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_alc655, ARRAY_SIZE(snd_ac97_spdif_controls_alc655))) < 0)
2808 static struct snd_ac97_build_ops patch_alc850_ops = {
2809 .build_specific = patch_alc850_specific,
2810 .update_jacks = alc850_update_jacks
2813 static int patch_alc850(struct snd_ac97 *ac97)
2815 ac97->build_ops = &patch_alc850_ops;
2817 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2819 /* assume only page 0 for writing cache */
2820 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
2822 /* adjust default values */
2823 /* set default: spdif-in enabled,
2824 spdif-in monitor off, spdif-in PCM off
2825 center on mic off, surround on line-in off
2828 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2829 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
2830 * Front Amp: on, Vref: enable, Center 1kOhm: on, Mix: on
2832 snd_ac97_write_cache(ac97, 0x7a, (1<<1)|(1<<4)|(0<<5)|(1<<6)|
2833 (1<<7)|(0<<12)|(1<<13)|(0<<14));
2834 /* detection UIO2,3: all path floating, UIO3: MIC, Vref2: disable,
2835 * UIO1: FRONT, Vref3: disable, UIO3: LINE, Front-Mic: mute
2837 snd_ac97_write_cache(ac97, 0x76, (0<<0)|(0<<2)|(1<<4)|(1<<7)|(2<<8)|
2838 (1<<11)|(0<<12)|(1<<15));
2840 /* full DAC volume */
2841 snd_ac97_write_cache(ac97, AC97_ALC650_SURR_DAC_VOL, 0x0808);
2842 snd_ac97_write_cache(ac97, AC97_ALC650_LFE_DAC_VOL, 0x0808);
2848 * C-Media CM97xx codecs
2850 static void cm9738_update_jacks(struct snd_ac97 *ac97)
2852 /* shared Line-In / Surround Out */
2853 snd_ac97_update_bits(ac97, AC97_CM9738_VENDOR_CTRL, 1 << 10,
2854 is_shared_surrout(ac97) ? (1 << 10) : 0);
2857 static const struct snd_kcontrol_new snd_ac97_cm9738_controls[] = {
2858 AC97_SINGLE("Duplicate Front", AC97_CM9738_VENDOR_CTRL, 13, 1, 0),
2859 AC97_SURROUND_JACK_MODE_CTL,
2860 AC97_CHANNEL_MODE_4CH_CTL,
2863 static int patch_cm9738_specific(struct snd_ac97 * ac97)
2865 return patch_build_controls(ac97, snd_ac97_cm9738_controls, ARRAY_SIZE(snd_ac97_cm9738_controls));
2868 static struct snd_ac97_build_ops patch_cm9738_ops = {
2869 .build_specific = patch_cm9738_specific,
2870 .update_jacks = cm9738_update_jacks
2873 static int patch_cm9738(struct snd_ac97 * ac97)
2875 ac97->build_ops = &patch_cm9738_ops;
2876 /* FIXME: can anyone confirm below? */
2877 /* CM9738 has no PCM volume although the register reacts */
2878 ac97->flags |= AC97_HAS_NO_PCM_VOL;
2879 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2884 static int snd_ac97_cmedia_spdif_playback_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2886 static char *texts[] = { "Analog", "Digital" };
2888 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2890 uinfo->value.enumerated.items = 2;
2891 if (uinfo->value.enumerated.item > 1)
2892 uinfo->value.enumerated.item = 1;
2893 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2897 static int snd_ac97_cmedia_spdif_playback_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2899 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2902 val = ac97->regs[AC97_CM9739_SPDIF_CTRL];
2903 ucontrol->value.enumerated.item[0] = (val >> 1) & 0x01;
2907 static int snd_ac97_cmedia_spdif_playback_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2909 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2911 return snd_ac97_update_bits(ac97, AC97_CM9739_SPDIF_CTRL,
2913 (ucontrol->value.enumerated.item[0] & 0x01) << 1);
2916 static const struct snd_kcontrol_new snd_ac97_cm9739_controls_spdif[] = {
2917 /* BIT 0: SPDI_EN - always true */
2918 { /* BIT 1: SPDIFS */
2919 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2920 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2921 .info = snd_ac97_cmedia_spdif_playback_source_info,
2922 .get = snd_ac97_cmedia_spdif_playback_source_get,
2923 .put = snd_ac97_cmedia_spdif_playback_source_put,
2925 /* BIT 2: IG_SPIV */
2926 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9739_SPDIF_CTRL, 2, 1, 0),
2928 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9739_SPDIF_CTRL, 3, 1, 0),
2929 /* BIT 4: SPI2SDI */
2930 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9739_SPDIF_CTRL, 4, 1, 0),
2931 /* BIT 8: SPD32 - 32bit SPDIF - not supported yet */
2934 static void cm9739_update_jacks(struct snd_ac97 *ac97)
2936 /* shared Line-In / Surround Out */
2937 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 1 << 10,
2938 is_shared_surrout(ac97) ? (1 << 10) : 0);
2939 /* shared Mic In / Center/LFE Out **/
2940 snd_ac97_update_bits(ac97, AC97_CM9739_MULTI_CHAN, 0x3000,
2941 is_shared_clfeout(ac97) ? 0x1000 : 0x2000);
2944 static const struct snd_kcontrol_new snd_ac97_cm9739_controls[] = {
2945 AC97_SURROUND_JACK_MODE_CTL,
2946 AC97_CHANNEL_MODE_CTL,
2949 static int patch_cm9739_specific(struct snd_ac97 * ac97)
2951 return patch_build_controls(ac97, snd_ac97_cm9739_controls, ARRAY_SIZE(snd_ac97_cm9739_controls));
2954 static int patch_cm9739_post_spdif(struct snd_ac97 * ac97)
2956 return patch_build_controls(ac97, snd_ac97_cm9739_controls_spdif, ARRAY_SIZE(snd_ac97_cm9739_controls_spdif));
2959 static struct snd_ac97_build_ops patch_cm9739_ops = {
2960 .build_specific = patch_cm9739_specific,
2961 .build_post_spdif = patch_cm9739_post_spdif,
2962 .update_jacks = cm9739_update_jacks
2965 static int patch_cm9739(struct snd_ac97 * ac97)
2969 ac97->build_ops = &patch_cm9739_ops;
2971 /* CM9739/A has no Master and PCM volume although the register reacts */
2972 ac97->flags |= AC97_HAS_NO_MASTER_VOL | AC97_HAS_NO_PCM_VOL;
2973 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8000);
2974 snd_ac97_write_cache(ac97, AC97_PCM, 0x8000);
2977 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2978 if (val & AC97_EA_SPCV) {
2979 /* enable spdif in */
2980 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
2981 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) | 0x01);
2982 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
2984 ac97->ext_id &= ~AC97_EI_SPDIF; /* disable extended-id */
2985 ac97->rates[AC97_RATES_SPDIF] = 0;
2988 /* set-up multi channel */
2989 /* bit 14: 0 = SPDIF, 1 = EAPD */
2990 /* bit 13: enable internal vref output for mic */
2991 /* bit 12: disable center/lfe (swithable) */
2992 /* bit 10: disable surround/line (switchable) */
2993 /* bit 9: mix 2 surround off */
2994 /* bit 4: undocumented; 0 mutes the CM9739A, which defaults to 1 */
2995 /* bit 3: undocumented; surround? */
2997 val = snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) & (1 << 4);
3000 if (! (ac97->ext_id & AC97_EI_SPDIF))
3002 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN, val);
3004 /* FIXME: set up GPIO */
3005 snd_ac97_write_cache(ac97, 0x70, 0x0100);
3006 snd_ac97_write_cache(ac97, 0x72, 0x0020);
3007 /* Special exception for ASUS W1000/CMI9739. It does not have an SPDIF in. */
3009 ac97->subsystem_vendor == 0x1043 &&
3010 ac97->subsystem_device == 0x1843) {
3011 snd_ac97_write_cache(ac97, AC97_CM9739_SPDIF_CTRL,
3012 snd_ac97_read(ac97, AC97_CM9739_SPDIF_CTRL) & ~0x01);
3013 snd_ac97_write_cache(ac97, AC97_CM9739_MULTI_CHAN,
3014 snd_ac97_read(ac97, AC97_CM9739_MULTI_CHAN) | (1 << 14));
3020 #define AC97_CM9761_MULTI_CHAN 0x64
3021 #define AC97_CM9761_FUNC 0x66
3022 #define AC97_CM9761_SPDIF_CTRL 0x6c
3024 static void cm9761_update_jacks(struct snd_ac97 *ac97)
3026 /* FIXME: check the bits for each model
3027 * model 83 is confirmed to work
3029 static unsigned short surr_on[3][2] = {
3030 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
3031 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
3032 { 0x0000, 0x0008 }, /* 9761-83 */
3034 static unsigned short clfe_on[3][2] = {
3035 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
3036 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
3037 { 0x0000, 0x1000 }, /* 9761-83 */
3039 static unsigned short surr_shared[3][2] = {
3040 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
3041 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
3042 { 0x0000, 0x0400 }, /* 9761-83 */
3044 static unsigned short clfe_shared[3][2] = {
3045 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
3046 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
3047 { 0x2000, 0x0800 }, /* 9761-83 */
3049 unsigned short val = 0;
3051 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
3052 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
3053 val |= surr_shared[ac97->spec.dev_flags][is_shared_surrout(ac97)];
3054 val |= clfe_shared[ac97->spec.dev_flags][is_shared_clfeout(ac97)];
3056 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
3059 static const struct snd_kcontrol_new snd_ac97_cm9761_controls[] = {
3060 AC97_SURROUND_JACK_MODE_CTL,
3061 AC97_CHANNEL_MODE_CTL,
3064 static int cm9761_spdif_out_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3066 static char *texts[] = { "AC-Link", "ADC", "SPDIF-In" };
3068 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3070 uinfo->value.enumerated.items = 3;
3071 if (uinfo->value.enumerated.item > 2)
3072 uinfo->value.enumerated.item = 2;
3073 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3077 static int cm9761_spdif_out_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3079 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3081 if (ac97->regs[AC97_CM9761_FUNC] & 0x1)
3082 ucontrol->value.enumerated.item[0] = 2; /* SPDIF-loopback */
3083 else if (ac97->regs[AC97_CM9761_SPDIF_CTRL] & 0x2)
3084 ucontrol->value.enumerated.item[0] = 1; /* ADC loopback */
3086 ucontrol->value.enumerated.item[0] = 0; /* AC-link */
3090 static int cm9761_spdif_out_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3092 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
3094 if (ucontrol->value.enumerated.item[0] == 2)
3095 return snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0x1);
3096 snd_ac97_update_bits(ac97, AC97_CM9761_FUNC, 0x1, 0);
3097 return snd_ac97_update_bits(ac97, AC97_CM9761_SPDIF_CTRL, 0x2,
3098 ucontrol->value.enumerated.item[0] == 1 ? 0x2 : 0);
3101 static const char *cm9761_dac_clock[] = { "AC-Link", "SPDIF-In", "Both" };
3102 static const struct ac97_enum cm9761_dac_clock_enum =
3103 AC97_ENUM_SINGLE(AC97_CM9761_SPDIF_CTRL, 9, 3, cm9761_dac_clock);
3105 static const struct snd_kcontrol_new snd_ac97_cm9761_controls_spdif[] = {
3106 { /* BIT 1: SPDIFS */
3107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3108 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3109 .info = cm9761_spdif_out_source_info,
3110 .get = cm9761_spdif_out_source_get,
3111 .put = cm9761_spdif_out_source_put,
3113 /* BIT 2: IG_SPIV */
3114 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Valid Switch", AC97_CM9761_SPDIF_CTRL, 2, 1, 0),
3116 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,NONE) "Monitor", AC97_CM9761_SPDIF_CTRL, 3, 1, 0),
3117 /* BIT 4: SPI2SDI */
3118 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), AC97_CM9761_SPDIF_CTRL, 4, 1, 0),
3119 /* BIT 9-10: DAC_CTL */
3120 AC97_ENUM("DAC Clock Source", cm9761_dac_clock_enum),
3123 static int patch_cm9761_post_spdif(struct snd_ac97 * ac97)
3125 return patch_build_controls(ac97, snd_ac97_cm9761_controls_spdif, ARRAY_SIZE(snd_ac97_cm9761_controls_spdif));
3128 static int patch_cm9761_specific(struct snd_ac97 * ac97)
3130 return patch_build_controls(ac97, snd_ac97_cm9761_controls, ARRAY_SIZE(snd_ac97_cm9761_controls));
3133 static struct snd_ac97_build_ops patch_cm9761_ops = {
3134 .build_specific = patch_cm9761_specific,
3135 .build_post_spdif = patch_cm9761_post_spdif,
3136 .update_jacks = cm9761_update_jacks
3139 static int patch_cm9761(struct snd_ac97 *ac97)
3143 /* CM9761 has no PCM volume although the register reacts */
3144 /* Master volume seems to have _some_ influence on the analog
3147 ac97->flags |= /*AC97_HAS_NO_MASTER_VOL |*/ AC97_HAS_NO_PCM_VOL;
3148 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
3149 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
3151 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
3152 if (ac97->id == AC97_ID_CM9761_82) {
3154 /* check page 1, reg 0x60 */
3155 val = snd_ac97_read(ac97, AC97_INT_PAGING);
3156 snd_ac97_write_cache(ac97, AC97_INT_PAGING, (val & ~0x0f) | 0x01);
3157 tmp = snd_ac97_read(ac97, 0x60);
3158 ac97->spec.dev_flags = tmp & 1; /* revision B? */
3159 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
3160 } else if (ac97->id == AC97_ID_CM9761_83)
3161 ac97->spec.dev_flags = 2;
3163 ac97->build_ops = &patch_cm9761_ops;
3166 /* force the SPDIF bit in ext_id - codec doesn't set this bit! */
3167 ac97->ext_id |= AC97_EI_SPDIF;
3168 /* to be sure: we overwrite the ext status bits */
3169 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, 0x05c0);
3170 /* Don't set 0x0200 here. This results in the silent analog output */
3171 snd_ac97_write_cache(ac97, AC97_CM9761_SPDIF_CTRL, 0x0001); /* enable spdif-in */
3172 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3174 /* set-up multi channel */
3175 /* bit 15: pc master beep off
3176 * bit 14: pin47 = EAPD/SPDIF
3177 * bit 13: vref ctl [= cm9739]
3178 * bit 12: CLFE control (reverted on rev B)
3179 * bit 11: Mic/center share (reverted on rev B)
3180 * bit 10: suddound/line share
3181 * bit 9: Analog-in mix -> surround
3182 * bit 8: Analog-in mix -> CLFE
3183 * bit 7: Mic/LFE share (mic/center/lfe)
3184 * bit 5: vref select (9761A)
3185 * bit 4: front control
3186 * bit 3: surround control (revereted with rev B)
3189 * bit 0: mic boost level (0=20dB, 1=30dB)
3193 if (ac97->spec.dev_flags)
3198 val = snd_ac97_read(ac97, AC97_CM9761_MULTI_CHAN);
3199 val |= (1 << 4); /* front on */
3200 snd_ac97_write_cache(ac97, AC97_CM9761_MULTI_CHAN, val);
3202 /* FIXME: set up GPIO */
3203 snd_ac97_write_cache(ac97, 0x70, 0x0100);
3204 snd_ac97_write_cache(ac97, 0x72, 0x0020);
3209 #define AC97_CM9780_SIDE 0x60
3210 #define AC97_CM9780_JACK 0x62
3211 #define AC97_CM9780_MIXER 0x64
3212 #define AC97_CM9780_MULTI_CHAN 0x66
3213 #define AC97_CM9780_SPDIF 0x6c
3215 static const char *cm9780_ch_select[] = { "Front", "Side", "Center/LFE", "Rear" };
3216 static const struct ac97_enum cm9780_ch_select_enum =
3217 AC97_ENUM_SINGLE(AC97_CM9780_MULTI_CHAN, 6, 4, cm9780_ch_select);
3218 static const struct snd_kcontrol_new cm9780_controls[] = {
3219 AC97_DOUBLE("Side Playback Switch", AC97_CM9780_SIDE, 15, 7, 1, 1),
3220 AC97_DOUBLE("Side Playback Volume", AC97_CM9780_SIDE, 8, 0, 31, 0),
3221 AC97_ENUM("Side Playback Route", cm9780_ch_select_enum),
3224 static int patch_cm9780_specific(struct snd_ac97 *ac97)
3226 return patch_build_controls(ac97, cm9780_controls, ARRAY_SIZE(cm9780_controls));
3229 static struct snd_ac97_build_ops patch_cm9780_ops = {
3230 .build_specific = patch_cm9780_specific,
3231 .build_post_spdif = patch_cm9761_post_spdif /* identical with CM9761 */
3234 static int patch_cm9780(struct snd_ac97 *ac97)
3238 ac97->build_ops = &patch_cm9780_ops;
3241 if (ac97->ext_id & AC97_EI_SPDIF) {
3242 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
3243 val = snd_ac97_read(ac97, AC97_CM9780_SPDIF);
3244 val |= 0x1; /* SPDI_EN */
3245 snd_ac97_write_cache(ac97, AC97_CM9780_SPDIF, val);
3254 static const struct snd_kcontrol_new snd_ac97_controls_vt1616[] = {
3255 AC97_SINGLE("DC Offset removal", 0x5a, 10, 1, 0),
3256 AC97_SINGLE("Alternate Level to Surround Out", 0x5a, 15, 1, 0),
3257 AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
3258 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
3261 static int patch_vt1616_specific(struct snd_ac97 * ac97)
3265 if (snd_ac97_try_bit(ac97, 0x5a, 9))
3266 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[0], 1)) < 0)
3268 if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
3273 static struct snd_ac97_build_ops patch_vt1616_ops = {
3274 .build_specific = patch_vt1616_specific
3277 static int patch_vt1616(struct snd_ac97 * ac97)
3279 ac97->build_ops = &patch_vt1616_ops;
3288 * unfortunately, the vt1617a stashes the twiddlers required for
3289 * nooding the i/o jacks on 2 different regs. * thameans that we cant
3290 * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
3293 * NB: this is absolutely and utterly different from the vt1618. dunno
3297 /* copied from ac97_surround_jack_mode_info() */
3298 static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
3299 struct snd_ctl_elem_info *uinfo)
3301 /* ordering in this list reflects vt1617a docs for Reg 20 and
3302 * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51
3303 * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
3304 * counter-intuitive */
3306 static const char* texts[] = { "LineIn Mic1", "LineIn Mic1 Mic3",
3307 "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
3308 "LineIn Mic2", "LineIn Mic2 Mic1",
3309 "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
3310 return ac97_enum_text_info(kcontrol, uinfo, texts, 8);
3313 static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
3314 struct snd_ctl_elem_value *ucontrol)
3316 ushort usSM51, usMS;
3318 struct snd_ac97 *pac97;
3320 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3322 /* grab our desirec bits, then mash them together in a manner
3323 * consistent with Table 6 on page 17 in the 1617a docs */
3325 usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
3326 usMS = snd_ac97_read(pac97, 0x20) >> 8;
3328 ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS;
3333 static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol,
3334 struct snd_ctl_elem_value *ucontrol)
3336 ushort usSM51, usMS, usReg;
3338 struct snd_ac97 *pac97;
3340 pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
3342 usSM51 = ucontrol->value.enumerated.item[0] >> 1;
3343 usMS = ucontrol->value.enumerated.item[0] & 1;
3345 /* push our values into the register - consider that things will be left
3346 * in a funky state if the write fails */
3348 usReg = snd_ac97_read(pac97, 0x7a);
3349 snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14));
3350 usReg = snd_ac97_read(pac97, 0x20);
3351 snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS << 8));
3356 static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
3358 AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0),
3360 * These are used to enable/disable surround sound on motherboards
3361 * that have 3 bidirectional analog jacks
3364 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3365 .name = "Smart 5.1 Select",
3366 .info = snd_ac97_vt1617a_smart51_info,
3367 .get = snd_ac97_vt1617a_smart51_get,
3368 .put = snd_ac97_vt1617a_smart51_put,
3372 int patch_vt1617a(struct snd_ac97 * ac97)
3376 /* we choose to not fail out at this point, but we tell the
3377 caller when we return */
3379 err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0],
3380 ARRAY_SIZE(snd_ac97_controls_vt1617a));
3382 /* bring analog power consumption to normal by turning off the
3383 * headphone amplifier, like WinXP driver for EPIA SP
3385 snd_ac97_write_cache(ac97, 0x5c, 0x20);
3386 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
3387 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
3388 ac97->build_ops = &patch_vt1616_ops;
3395 static void it2646_update_jacks(struct snd_ac97 *ac97)
3397 /* shared Line-In / Surround Out */
3398 snd_ac97_update_bits(ac97, 0x76, 1 << 9,
3399 is_shared_surrout(ac97) ? (1<<9) : 0);
3400 /* shared Mic / Center/LFE Out */
3401 snd_ac97_update_bits(ac97, 0x76, 1 << 10,
3402 is_shared_clfeout(ac97) ? (1<<10) : 0);
3405 static const struct snd_kcontrol_new snd_ac97_controls_it2646[] = {
3406 AC97_SURROUND_JACK_MODE_CTL,
3407 AC97_CHANNEL_MODE_CTL,
3410 static const struct snd_kcontrol_new snd_ac97_spdif_controls_it2646[] = {
3411 AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0x76, 11, 1, 0),
3412 AC97_SINGLE("Analog to IEC958 Output", 0x76, 12, 1, 0),
3413 AC97_SINGLE("IEC958 Input Monitor", 0x76, 13, 1, 0),
3416 static int patch_it2646_specific(struct snd_ac97 * ac97)
3419 if ((err = patch_build_controls(ac97, snd_ac97_controls_it2646, ARRAY_SIZE(snd_ac97_controls_it2646))) < 0)
3421 if ((err = patch_build_controls(ac97, snd_ac97_spdif_controls_it2646, ARRAY_SIZE(snd_ac97_spdif_controls_it2646))) < 0)
3426 static struct snd_ac97_build_ops patch_it2646_ops = {
3427 .build_specific = patch_it2646_specific,
3428 .update_jacks = it2646_update_jacks
3431 static int patch_it2646(struct snd_ac97 * ac97)
3433 ac97->build_ops = &patch_it2646_ops;
3434 /* full DAC volume */
3435 snd_ac97_write_cache(ac97, 0x5E, 0x0808);
3436 snd_ac97_write_cache(ac97, 0x7A, 0x0808);
3444 #define AC97_SI3036_CHIP_ID 0x5a
3445 #define AC97_SI3036_LINE_CFG 0x5c
3447 static const struct snd_kcontrol_new snd_ac97_controls_si3036[] = {
3448 AC97_DOUBLE("Modem Speaker Volume", 0x5c, 14, 12, 3, 1)
3451 static int patch_si3036_specific(struct snd_ac97 * ac97)
3454 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_si3036); idx++)
3455 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_si3036[idx], ac97))) < 0)
3460 static struct snd_ac97_build_ops patch_si3036_ops = {
3461 .build_specific = patch_si3036_specific,
3464 static int mpatch_si3036(struct snd_ac97 * ac97)
3466 ac97->build_ops = &patch_si3036_ops;
3467 snd_ac97_write_cache(ac97, 0x5c, 0xf210 );
3468 snd_ac97_write_cache(ac97, 0x68, 0);
3475 * We use a static resolution table since LM4550 codec cannot be
3476 * properly autoprobed to determine the resolution via
3477 * check_volume_resolution().
3480 static struct snd_ac97_res_table lm4550_restbl[] = {
3481 { AC97_MASTER, 0x1f1f },
3482 { AC97_HEADPHONE, 0x1f1f },
3483 { AC97_MASTER_MONO, 0x001f },
3484 { AC97_PC_BEEP, 0x001f }, /* LSB is ignored */
3485 { AC97_PHONE, 0x001f },
3486 { AC97_MIC, 0x001f },
3487 { AC97_LINE, 0x1f1f },
3488 { AC97_CD, 0x1f1f },
3489 { AC97_VIDEO, 0x1f1f },
3490 { AC97_AUX, 0x1f1f },
3491 { AC97_PCM, 0x1f1f },
3492 { AC97_REC_GAIN, 0x0f0f },
3493 { } /* terminator */
3496 static int patch_lm4550(struct snd_ac97 *ac97)
3498 ac97->res_table = lm4550_restbl;
3503 * UCB1400 codec (http://www.semiconductors.philips.com/acrobat_download/datasheets/UCB1400-02.pdf)
3505 static const struct snd_kcontrol_new snd_ac97_controls_ucb1400[] = {
3506 /* enable/disable headphone driver which allows direct connection to
3507 stereo headphone without the use of external DC blocking
3509 AC97_SINGLE("Headphone Driver", 0x6a, 6, 1, 0),
3510 /* Filter used to compensate the DC offset is added in the ADC to remove idle
3511 tones from the audio band. */
3512 AC97_SINGLE("DC Filter", 0x6a, 4, 1, 0),
3513 /* Control smart-low-power mode feature. Allows automatic power down
3514 of unused blocks in the ADC analog front end and the PLL. */
3515 AC97_SINGLE("Smart Low Power Mode", 0x6c, 4, 3, 0),
3518 static int patch_ucb1400_specific(struct snd_ac97 * ac97)
3521 for (idx = 0; idx < ARRAY_SIZE(snd_ac97_controls_ucb1400); idx++)
3522 if ((err = snd_ctl_add(ac97->bus->card, snd_ctl_new1(&snd_ac97_controls_ucb1400[idx], ac97))) < 0)
3527 static struct snd_ac97_build_ops patch_ucb1400_ops = {
3528 .build_specific = patch_ucb1400_specific,
3531 static int patch_ucb1400(struct snd_ac97 * ac97)
3533 ac97->build_ops = &patch_ucb1400_ops;
3534 /* enable headphone driver and smart low power mode by default */
3535 snd_ac97_write(ac97, 0x6a, 0x0050);
3536 snd_ac97_write(ac97, 0x6c, 0x0030);