2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <linux/module.h>
53 #include <sound/core.h>
54 #include <sound/asoundef.h>
55 #include "hda_codec.h"
56 #include "hda_local.h"
57 #include "hda_auto_parser.h"
59 #include "hda_generic.h"
62 #define VT1708_HP_PIN_NID 0x20
63 #define VT1708_CD_PIN_NID 0x24
85 #define VT2002P_COMPATIBLE(spec) \
86 ((spec)->codec_type == VT2002P ||\
87 (spec)->codec_type == VT1812 ||\
88 (spec)->codec_type == VT1802)
91 struct hda_gen_spec gen;
93 /* codec parameterization */
94 const struct snd_kcontrol_new *mixers[6];
95 unsigned int num_mixers;
97 const struct hda_verb *init_verbs[5];
98 unsigned int num_iverbs;
101 unsigned int dmic_enabled;
102 unsigned int no_pin_power_ctl;
103 enum VIA_HDA_CODEC codec_type;
105 /* analog low-power control */
108 /* work to check hp jack state */
110 int vt1708_jack_detect;
112 void (*set_widgets_power_state)(struct hda_codec *codec);
113 unsigned int dac_stream_tag[4];
116 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
117 static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
118 struct hda_codec *codec,
119 struct snd_pcm_substream *substream,
121 static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl);
123 static struct via_spec *via_new_spec(struct hda_codec *codec)
125 struct via_spec *spec;
127 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
132 snd_hda_gen_spec_init(&spec->gen);
133 spec->codec_type = get_codec_type(codec);
134 /* VT1708BCE & VT1708S are almost same */
135 if (spec->codec_type == VT1708BCE)
136 spec->codec_type = VT1708S;
137 spec->no_pin_power_ctl = 1;
138 spec->gen.indep_hp = 1;
139 spec->gen.pcm_playback_hook = via_playback_pcm_hook;
143 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
145 u32 vendor_id = codec->vendor_id;
146 u16 ven_id = vendor_id >> 16;
147 u16 dev_id = vendor_id & 0xffff;
148 enum VIA_HDA_CODEC codec_type;
151 if (ven_id != 0x1106)
152 codec_type = UNKNOWN;
153 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
155 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
156 codec_type = VT1709_10CH;
157 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
158 codec_type = VT1709_6CH;
159 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
160 codec_type = VT1708B_8CH;
161 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
162 codec_type = VT1708BCE;
163 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
164 codec_type = VT1708B_4CH;
165 else if ((dev_id & 0xfff) == 0x397
166 && (dev_id >> 12) < 8)
167 codec_type = VT1708S;
168 else if ((dev_id & 0xfff) == 0x398
169 && (dev_id >> 12) < 8)
171 else if ((dev_id & 0xfff) == 0x428
172 && (dev_id >> 12) < 8)
173 codec_type = VT1718S;
174 else if (dev_id == 0x0433 || dev_id == 0xa721)
175 codec_type = VT1716S;
176 else if (dev_id == 0x0441 || dev_id == 0x4441)
177 codec_type = VT1718S;
178 else if (dev_id == 0x0438 || dev_id == 0x4438)
179 codec_type = VT2002P;
180 else if (dev_id == 0x0448)
182 else if (dev_id == 0x0440)
183 codec_type = VT1708S;
184 else if ((dev_id & 0xfff) == 0x446)
186 else if (dev_id == 0x4760)
187 codec_type = VT1705CF;
188 else if (dev_id == 0x4761 || dev_id == 0x4762)
191 codec_type = UNKNOWN;
195 static void analog_low_current_mode(struct hda_codec *codec);
196 static bool is_aa_path_mute(struct hda_codec *codec);
198 #define hp_detect_with_aa(codec) \
199 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
200 !is_aa_path_mute(codec))
202 static void vt1708_stop_hp_work(struct hda_codec *codec)
204 struct via_spec *spec = codec->spec;
205 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
207 if (spec->hp_work_active) {
208 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
209 cancel_delayed_work_sync(&codec->jackpoll_work);
210 spec->hp_work_active = false;
211 codec->jackpoll_interval = 0;
215 static void vt1708_update_hp_work(struct hda_codec *codec)
217 struct via_spec *spec = codec->spec;
218 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
220 if (spec->vt1708_jack_detect &&
221 (spec->gen.active_streams || hp_detect_with_aa(codec))) {
222 if (!spec->hp_work_active) {
223 codec->jackpoll_interval = msecs_to_jiffies(100);
224 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
225 queue_delayed_work(codec->bus->workq,
226 &codec->jackpoll_work, 0);
227 spec->hp_work_active = true;
229 } else if (!hp_detect_with_aa(codec))
230 vt1708_stop_hp_work(codec);
233 static void set_widgets_power_state(struct hda_codec *codec)
235 struct via_spec *spec = codec->spec;
236 if (spec->set_widgets_power_state)
237 spec->set_widgets_power_state(codec);
240 static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
243 unsigned int state = snd_hda_codec_read(codec, nid, 0,
244 AC_VERB_GET_POWER_STATE, 0);
245 state = (state >> 4) & 0x0f;
248 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
251 static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
252 unsigned int parm, unsigned int index)
254 struct via_spec *spec = codec->spec;
256 unsigned int state = snd_hda_codec_read(codec, nid, 0,
257 AC_VERB_GET_POWER_STATE, 0);
258 state = (state >> 4) & 0x0f;
261 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
262 if (format && (spec->dac_stream_tag[index] != format))
263 spec->dac_stream_tag[index] = format;
265 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
266 if (parm == AC_PWRST_D0) {
267 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
268 if (!format && (spec->dac_stream_tag[index] != format))
269 snd_hda_codec_write(codec, nid, 0,
270 AC_VERB_SET_CHANNEL_STREAMID,
271 spec->dac_stream_tag[index]);
275 static bool smart51_enabled(struct hda_codec *codec)
277 struct via_spec *spec = codec->spec;
278 return spec->gen.ext_channel_count > 2;
281 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
283 struct via_spec *spec = codec->spec;
286 for (i = 0; i < spec->gen.multi_ios; i++)
287 if (spec->gen.multi_io[i].pin == pin)
292 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
293 unsigned int *affected_parm)
296 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
297 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
298 >> AC_DEFCFG_MISC_SHIFT
299 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
300 struct via_spec *spec = codec->spec;
301 unsigned present = 0;
303 no_presence |= spec->no_pin_power_ctl;
305 present = snd_hda_jack_detect(codec, nid);
306 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
307 || ((no_presence || present)
308 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
309 *affected_parm = AC_PWRST_D0; /* if it's connected */
314 update_power_state(codec, nid, parm);
317 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
318 struct snd_ctl_elem_info *uinfo)
320 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
323 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_value *ucontrol)
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct via_spec *spec = codec->spec;
328 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
332 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
333 struct snd_ctl_elem_value *ucontrol)
335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 struct via_spec *spec = codec->spec;
337 unsigned int val = !ucontrol->value.enumerated.item[0];
339 if (val == spec->no_pin_power_ctl)
341 spec->no_pin_power_ctl = val;
342 set_widgets_power_state(codec);
343 analog_low_current_mode(codec);
347 static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
349 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
350 .name = "Dynamic Power-Control",
351 .info = via_pin_power_ctl_info,
352 .get = via_pin_power_ctl_get,
353 .put = via_pin_power_ctl_put,
359 /* check AA path's mute status */
360 static bool is_aa_path_mute(struct hda_codec *codec)
362 struct via_spec *spec = codec->spec;
363 const struct hda_amp_list *p;
366 for (i = 0; i < spec->gen.num_loopbacks; i++) {
367 p = &spec->gen.loopback_list[i];
368 for (ch = 0; ch < 2; ch++) {
369 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
371 if (!(v & HDA_AMP_MUTE) && v > 0)
378 /* enter/exit analog low-current mode */
379 static void __analog_low_current_mode(struct hda_codec *codec, bool force)
381 struct via_spec *spec = codec->spec;
383 unsigned int verb, parm;
385 if (spec->no_pin_power_ctl)
388 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
389 if (enable == spec->alc_mode && !force)
391 spec->alc_mode = enable;
393 /* decide low current mode's verb & parameter */
394 switch (spec->codec_type) {
398 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
404 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
408 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
414 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
419 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
422 return; /* other codecs are not supported */
425 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
428 static void analog_low_current_mode(struct hda_codec *codec)
430 return __analog_low_current_mode(codec, false);
433 static int via_build_controls(struct hda_codec *codec)
435 struct via_spec *spec = codec->spec;
438 err = snd_hda_gen_build_controls(codec);
442 if (spec->set_widgets_power_state)
443 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
445 for (i = 0; i < spec->num_mixers; i++) {
446 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
454 static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
455 struct hda_codec *codec,
456 struct snd_pcm_substream *substream,
459 analog_low_current_mode(codec);
460 vt1708_update_hp_work(codec);
463 static void via_free(struct hda_codec *codec)
465 struct via_spec *spec = codec->spec;
470 vt1708_stop_hp_work(codec);
471 snd_hda_gen_spec_free(&spec->gen);
476 static int via_suspend(struct hda_codec *codec)
478 struct via_spec *spec = codec->spec;
479 vt1708_stop_hp_work(codec);
481 if (spec->codec_type == VT1802) {
482 /* Fix pop noise on headphones */
484 for (i = 0; i < spec->gen.autocfg.hp_outs; i++)
485 snd_hda_set_pin_ctl(codec, spec->gen.autocfg.hp_pins[i], 0);
493 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
495 struct via_spec *spec = codec->spec;
496 set_widgets_power_state(codec);
497 analog_low_current_mode(codec);
498 vt1708_update_hp_work(codec);
499 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
506 static int via_init(struct hda_codec *codec);
508 static const struct hda_codec_ops via_patch_ops = {
509 .build_controls = via_build_controls,
510 .build_pcms = snd_hda_gen_build_pcms,
513 .unsol_event = snd_hda_jack_unsol_event,
515 .suspend = via_suspend,
516 .check_power_status = via_check_power_status,
521 static const struct hda_verb vt1708_init_verbs[] = {
522 /* power down jack detect function */
526 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
528 unsigned int def_conf;
529 unsigned char seqassoc;
531 def_conf = snd_hda_codec_get_pincfg(codec, nid);
532 seqassoc = (unsigned char) get_defcfg_association(def_conf);
533 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
534 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
535 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
536 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
537 snd_hda_codec_set_pincfg(codec, nid, def_conf);
543 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
544 struct snd_ctl_elem_value *ucontrol)
546 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
547 struct via_spec *spec = codec->spec;
549 if (spec->codec_type != VT1708)
551 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
555 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
556 struct snd_ctl_elem_value *ucontrol)
558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
559 struct via_spec *spec = codec->spec;
562 if (spec->codec_type != VT1708)
564 val = !!ucontrol->value.integer.value[0];
565 if (spec->vt1708_jack_detect == val)
567 spec->vt1708_jack_detect = val;
568 vt1708_update_hp_work(codec);
572 static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
574 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
575 .name = "Jack Detect",
577 .info = snd_ctl_boolean_mono_info,
578 .get = vt1708_jack_detect_get,
579 .put = vt1708_jack_detect_put,
584 static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
586 set_widgets_power_state(codec);
587 snd_hda_gen_hp_automute(codec, tbl);
590 static void via_line_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
592 set_widgets_power_state(codec);
593 snd_hda_gen_line_automute(codec, tbl);
596 static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
598 set_widgets_power_state(codec);
601 #define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1)
603 static void via_set_jack_unsol_events(struct hda_codec *codec)
605 struct via_spec *spec = codec->spec;
606 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
610 spec->gen.hp_automute_hook = via_hp_automute;
611 if (cfg->speaker_pins[0])
612 spec->gen.line_automute_hook = via_line_automute;
614 for (i = 0; i < cfg->line_outs; i++) {
615 pin = cfg->line_out_pins[i];
616 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
617 is_jack_detectable(codec, pin))
618 snd_hda_jack_detect_enable_callback(codec, pin,
620 via_jack_powerstate_event);
623 for (i = 0; i < cfg->num_inputs; i++) {
624 pin = cfg->line_out_pins[i];
625 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
626 is_jack_detectable(codec, pin))
627 snd_hda_jack_detect_enable_callback(codec, pin,
629 via_jack_powerstate_event);
633 static int via_parse_auto_config(struct hda_codec *codec)
635 struct via_spec *spec = codec->spec;
638 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
642 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
646 via_set_jack_unsol_events(codec);
650 static int via_init(struct hda_codec *codec)
652 struct via_spec *spec = codec->spec;
655 for (i = 0; i < spec->num_iverbs; i++)
656 snd_hda_sequence_write(codec, spec->init_verbs[i]);
658 /* init power states */
659 set_widgets_power_state(codec);
660 __analog_low_current_mode(codec, true);
662 snd_hda_gen_init(codec);
664 vt1708_update_hp_work(codec);
669 static int vt1708_build_pcms(struct hda_codec *codec)
671 struct via_spec *spec = codec->spec;
674 err = snd_hda_gen_build_pcms(codec);
675 if (err < 0 || codec->vendor_id != 0x11061708)
678 /* We got noisy outputs on the right channel on VT1708 when
679 * 24bit samples are used. Until any workaround is found,
680 * disable the 24bit format, so far.
682 for (i = 0; i < codec->num_pcms; i++) {
683 struct hda_pcm *info = &spec->gen.pcm_rec[i];
684 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
685 info->pcm_type != HDA_PCM_TYPE_AUDIO)
687 info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
688 SNDRV_PCM_FMTBIT_S16_LE;
694 static int patch_vt1708(struct hda_codec *codec)
696 struct via_spec *spec;
699 /* create a codec specific record */
700 spec = via_new_spec(codec);
704 spec->gen.mixer_nid = 0x17;
706 /* set jackpoll_interval while parsing the codec */
707 codec->jackpoll_interval = msecs_to_jiffies(100);
708 spec->vt1708_jack_detect = 1;
710 /* don't support the input jack switching due to lack of unsol event */
711 /* (it may work with polling, though, but it needs testing) */
712 spec->gen.suppress_auto_mic = 1;
714 /* Add HP and CD pin config connect bit re-config action */
715 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
716 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
718 /* automatic parse from the BIOS config */
719 err = via_parse_auto_config(codec);
725 /* add jack detect on/off control */
726 spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
728 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
730 codec->patch_ops = via_patch_ops;
731 codec->patch_ops.build_pcms = vt1708_build_pcms;
733 /* clear jackpoll_interval again; it's set dynamically */
734 codec->jackpoll_interval = 0;
739 static int patch_vt1709(struct hda_codec *codec)
741 struct via_spec *spec;
744 /* create a codec specific record */
745 spec = via_new_spec(codec);
749 spec->gen.mixer_nid = 0x18;
751 err = via_parse_auto_config(codec);
757 codec->patch_ops = via_patch_ops;
762 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
764 struct via_spec *spec = codec->spec;
768 if ((spec->codec_type != VT1708B_4CH) &&
769 (codec->vendor_id != 0x11064397))
772 /* SW0 (17h) = stereo mixer */
774 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
775 == ((spec->codec_type == VT1708S) ? 5 : 0));
777 /* PW 1/2/5 (1ah/1bh/1eh) */
779 set_pin_power_state(codec, 0x1a, &parm);
780 set_pin_power_state(codec, 0x1b, &parm);
781 set_pin_power_state(codec, 0x1e, &parm);
784 /* SW0 (17h), AIW 0/1 (13h/14h) */
785 update_power_state(codec, 0x17, parm);
786 update_power_state(codec, 0x13, parm);
787 update_power_state(codec, 0x14, parm);
790 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
792 set_pin_power_state(codec, 0x19, &parm);
793 if (smart51_enabled(codec))
794 set_pin_power_state(codec, 0x1b, &parm);
795 update_power_state(codec, 0x18, parm);
796 update_power_state(codec, 0x11, parm);
798 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
801 set_pin_power_state(codec, 0x22, &parm);
802 if (smart51_enabled(codec))
803 set_pin_power_state(codec, 0x1a, &parm);
804 update_power_state(codec, 0x26, parm);
805 update_power_state(codec, 0x24, parm);
806 } else if (codec->vendor_id == 0x11064397) {
807 /* PW7(23h), SW2(27h), AOW2(25h) */
809 set_pin_power_state(codec, 0x23, &parm);
810 if (smart51_enabled(codec))
811 set_pin_power_state(codec, 0x1a, &parm);
812 update_power_state(codec, 0x27, parm);
813 update_power_state(codec, 0x25, parm);
816 /* PW 3/4/7 (1ch/1dh/23h) */
818 /* force to D0 for internal Speaker */
819 set_pin_power_state(codec, 0x1c, &parm);
820 set_pin_power_state(codec, 0x1d, &parm);
822 set_pin_power_state(codec, 0x23, &parm);
824 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
825 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
826 update_power_state(codec, 0x10, parm);
828 update_power_state(codec, 0x25, parm);
829 update_power_state(codec, 0x27, parm);
830 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
831 update_power_state(codec, 0x25, parm);
834 static int patch_vt1708S(struct hda_codec *codec);
835 static int patch_vt1708B(struct hda_codec *codec)
837 struct via_spec *spec;
840 if (get_codec_type(codec) == VT1708BCE)
841 return patch_vt1708S(codec);
843 /* create a codec specific record */
844 spec = via_new_spec(codec);
848 spec->gen.mixer_nid = 0x16;
850 /* automatic parse from the BIOS config */
851 err = via_parse_auto_config(codec);
857 codec->patch_ops = via_patch_ops;
859 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
864 /* Patch for VT1708S */
865 static const struct hda_verb vt1708S_init_verbs[] = {
866 /* Enable Mic Boost Volume backdoor */
868 /* don't bybass mixer */
873 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
874 int offset, int num_steps, int step_size)
876 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
877 (offset << AC_AMPCAP_OFFSET_SHIFT) |
878 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
879 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
880 (0 << AC_AMPCAP_MUTE_SHIFT));
883 static int patch_vt1708S(struct hda_codec *codec)
885 struct via_spec *spec;
888 /* create a codec specific record */
889 spec = via_new_spec(codec);
893 spec->gen.mixer_nid = 0x16;
894 override_mic_boost(codec, 0x1a, 0, 3, 40);
895 override_mic_boost(codec, 0x1e, 0, 3, 40);
897 /* correct names for VT1708BCE */
898 if (get_codec_type(codec) == VT1708BCE) {
899 kfree(codec->chip_name);
900 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
901 snprintf(codec->bus->card->mixername,
902 sizeof(codec->bus->card->mixername),
903 "%s %s", codec->vendor_name, codec->chip_name);
905 /* correct names for VT1705 */
906 if (codec->vendor_id == 0x11064397) {
907 kfree(codec->chip_name);
908 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
909 snprintf(codec->bus->card->mixername,
910 sizeof(codec->bus->card->mixername),
911 "%s %s", codec->vendor_name, codec->chip_name);
914 /* automatic parse from the BIOS config */
915 err = via_parse_auto_config(codec);
921 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
923 codec->patch_ops = via_patch_ops;
925 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
929 /* Patch for VT1702 */
931 static const struct hda_verb vt1702_init_verbs[] = {
939 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
942 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
945 /* PW 1/2/5 (14h/15h/18h) */
947 set_pin_power_state(codec, 0x14, &parm);
948 set_pin_power_state(codec, 0x15, &parm);
949 set_pin_power_state(codec, 0x18, &parm);
951 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
952 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
953 update_power_state(codec, 0x13, parm);
954 update_power_state(codec, 0x12, parm);
955 update_power_state(codec, 0x1f, parm);
956 update_power_state(codec, 0x20, parm);
959 /* PW 3/4 (16h/17h) */
961 set_pin_power_state(codec, 0x17, &parm);
962 set_pin_power_state(codec, 0x16, &parm);
963 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
964 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
965 update_power_state(codec, 0x10, parm);
966 update_power_state(codec, 0x1d, parm);
969 static int patch_vt1702(struct hda_codec *codec)
971 struct via_spec *spec;
974 /* create a codec specific record */
975 spec = via_new_spec(codec);
979 spec->gen.mixer_nid = 0x1a;
981 /* limit AA path volume to 0 dB */
982 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
983 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
984 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
985 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
986 (1 << AC_AMPCAP_MUTE_SHIFT));
988 /* automatic parse from the BIOS config */
989 err = via_parse_auto_config(codec);
995 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
997 codec->patch_ops = via_patch_ops;
999 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
1003 /* Patch for VT1718S */
1005 static const struct hda_verb vt1718S_init_verbs[] = {
1006 /* Enable MW0 adjust Gain 5 */
1008 /* Enable Boost Volume backdoor */
1014 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1016 struct via_spec *spec = codec->spec;
1018 unsigned int parm, parm2;
1019 /* MUX6 (1eh) = stereo mixer */
1021 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1023 /* PW 5/6/7 (29h/2ah/2bh) */
1025 set_pin_power_state(codec, 0x29, &parm);
1026 set_pin_power_state(codec, 0x2a, &parm);
1027 set_pin_power_state(codec, 0x2b, &parm);
1030 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1031 update_power_state(codec, 0x1e, parm);
1032 update_power_state(codec, 0x1f, parm);
1033 update_power_state(codec, 0x10, parm);
1034 update_power_state(codec, 0x11, parm);
1037 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1039 set_pin_power_state(codec, 0x27, &parm);
1040 update_power_state(codec, 0x1a, parm);
1041 parm2 = parm; /* for pin 0x0b */
1043 /* PW2 (26h), AOW2 (ah) */
1045 set_pin_power_state(codec, 0x26, &parm);
1046 if (smart51_enabled(codec))
1047 set_pin_power_state(codec, 0x2b, &parm);
1048 update_power_state(codec, 0xa, parm);
1050 /* PW0 (24h), AOW0 (8h) */
1052 set_pin_power_state(codec, 0x24, &parm);
1053 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
1054 set_pin_power_state(codec, 0x28, &parm);
1055 update_power_state(codec, 0x8, parm);
1056 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1058 update_power_state(codec, 0xb, parm);
1059 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1060 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
1062 /* PW1 (25h), AOW1 (9h) */
1064 set_pin_power_state(codec, 0x25, &parm);
1065 if (smart51_enabled(codec))
1066 set_pin_power_state(codec, 0x2a, &parm);
1067 update_power_state(codec, 0x9, parm);
1069 if (spec->gen.indep_hp_enabled) {
1070 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1072 set_pin_power_state(codec, 0x28, &parm);
1073 update_power_state(codec, 0x1b, parm);
1074 update_power_state(codec, 0x34, parm);
1075 update_power_state(codec, 0xc, parm);
1079 /* Add a connection to the primary DAC from AA-mixer for some codecs
1080 * This isn't listed from the raw info, but the chip has a secret connection.
1082 static int add_secret_dac_path(struct hda_codec *codec)
1084 struct via_spec *spec = codec->spec;
1089 if (!spec->gen.mixer_nid)
1091 nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
1092 ARRAY_SIZE(conn) - 1);
1093 for (i = 0; i < nums; i++) {
1094 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
1098 /* find the primary DAC and add to the connection list */
1099 nid = codec->start_nid;
1100 for (i = 0; i < codec->num_nodes; i++, nid++) {
1101 unsigned int caps = get_wcaps(codec, nid);
1102 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
1103 !(caps & AC_WCAP_DIGITAL)) {
1105 return snd_hda_override_conn_list(codec,
1106 spec->gen.mixer_nid,
1114 static int patch_vt1718S(struct hda_codec *codec)
1116 struct via_spec *spec;
1119 /* create a codec specific record */
1120 spec = via_new_spec(codec);
1124 spec->gen.mixer_nid = 0x21;
1125 override_mic_boost(codec, 0x2b, 0, 3, 40);
1126 override_mic_boost(codec, 0x29, 0, 3, 40);
1127 add_secret_dac_path(codec);
1129 /* automatic parse from the BIOS config */
1130 err = via_parse_auto_config(codec);
1136 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
1138 codec->patch_ops = via_patch_ops;
1140 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
1145 /* Patch for VT1716S */
1147 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
1148 struct snd_ctl_elem_info *uinfo)
1150 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1152 uinfo->value.integer.min = 0;
1153 uinfo->value.integer.max = 1;
1157 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
1158 struct snd_ctl_elem_value *ucontrol)
1160 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1163 index = snd_hda_codec_read(codec, 0x26, 0,
1164 AC_VERB_GET_CONNECT_SEL, 0);
1166 *ucontrol->value.integer.value = index;
1171 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1172 struct snd_ctl_elem_value *ucontrol)
1174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1175 struct via_spec *spec = codec->spec;
1176 int index = *ucontrol->value.integer.value;
1178 snd_hda_codec_write(codec, 0x26, 0,
1179 AC_VERB_SET_CONNECT_SEL, index);
1180 spec->dmic_enabled = index;
1181 set_widgets_power_state(codec);
1185 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
1186 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
1188 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1189 .name = "Digital Mic Capture Switch",
1190 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
1192 .info = vt1716s_dmic_info,
1193 .get = vt1716s_dmic_get,
1194 .put = vt1716s_dmic_put,
1200 /* mono-out mixer elements */
1201 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
1202 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
1206 static const struct hda_verb vt1716S_init_verbs[] = {
1207 /* Enable Boost Volume backdoor */
1209 /* don't bybass mixer */
1211 /* Enable mono output */
1216 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1218 struct via_spec *spec = codec->spec;
1221 unsigned int mono_out, present;
1222 /* SW0 (17h) = stereo mixer */
1224 (snd_hda_codec_read(codec, 0x17, 0,
1225 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
1227 /* PW 1/2/5 (1ah/1bh/1eh) */
1229 set_pin_power_state(codec, 0x1a, &parm);
1230 set_pin_power_state(codec, 0x1b, &parm);
1231 set_pin_power_state(codec, 0x1e, &parm);
1234 /* SW0 (17h), AIW0(13h) */
1235 update_power_state(codec, 0x17, parm);
1236 update_power_state(codec, 0x13, parm);
1239 set_pin_power_state(codec, 0x1e, &parm);
1241 if (spec->dmic_enabled)
1242 set_pin_power_state(codec, 0x22, &parm);
1244 update_power_state(codec, 0x22, AC_PWRST_D3);
1246 /* SW2(26h), AIW1(14h) */
1247 update_power_state(codec, 0x26, parm);
1248 update_power_state(codec, 0x14, parm);
1251 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1253 set_pin_power_state(codec, 0x19, &parm);
1254 /* Smart 5.1 PW2(1bh) */
1255 if (smart51_enabled(codec))
1256 set_pin_power_state(codec, 0x1b, &parm);
1257 update_power_state(codec, 0x18, parm);
1258 update_power_state(codec, 0x11, parm);
1260 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1262 set_pin_power_state(codec, 0x23, &parm);
1263 /* Smart 5.1 PW1(1ah) */
1264 if (smart51_enabled(codec))
1265 set_pin_power_state(codec, 0x1a, &parm);
1266 update_power_state(codec, 0x27, parm);
1268 /* Smart 5.1 PW5(1eh) */
1269 if (smart51_enabled(codec))
1270 set_pin_power_state(codec, 0x1e, &parm);
1271 update_power_state(codec, 0x25, parm);
1274 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1275 present = snd_hda_jack_detect(codec, 0x1c);
1280 present = snd_hda_jack_detect(codec, 0x1d);
1281 if (!spec->gen.indep_hp_enabled && present)
1286 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
1287 update_power_state(codec, 0x28, parm);
1288 update_power_state(codec, 0x29, parm);
1289 update_power_state(codec, 0x2a, parm);
1291 /* PW 3/4 (1ch/1dh) */
1293 set_pin_power_state(codec, 0x1c, &parm);
1294 set_pin_power_state(codec, 0x1d, &parm);
1295 /* HP Independent Mode, power on AOW3 */
1296 if (spec->gen.indep_hp_enabled)
1297 update_power_state(codec, 0x25, parm);
1299 /* force to D0 for internal Speaker */
1300 /* MW0 (16h), AOW0 (10h) */
1301 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1302 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
1305 static int patch_vt1716S(struct hda_codec *codec)
1307 struct via_spec *spec;
1310 /* create a codec specific record */
1311 spec = via_new_spec(codec);
1315 spec->gen.mixer_nid = 0x16;
1316 override_mic_boost(codec, 0x1a, 0, 3, 40);
1317 override_mic_boost(codec, 0x1e, 0, 3, 40);
1319 /* automatic parse from the BIOS config */
1320 err = via_parse_auto_config(codec);
1326 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
1328 spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
1329 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1331 codec->patch_ops = via_patch_ops;
1333 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
1339 static const struct hda_verb vt2002P_init_verbs[] = {
1340 /* Class-D speaker related verbs */
1344 /* Enable Boost Volume backdoor */
1346 /* Enable AOW0 to MW9 */
1351 static const struct hda_verb vt1802_init_verbs[] = {
1352 /* Enable Boost Volume backdoor */
1354 /* Enable AOW0 to MW9 */
1359 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1361 struct via_spec *spec = codec->spec;
1364 unsigned int present;
1365 /* MUX9 (1eh) = stereo mixer */
1367 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1369 /* PW 5/6/7 (29h/2ah/2bh) */
1371 set_pin_power_state(codec, 0x29, &parm);
1372 set_pin_power_state(codec, 0x2a, &parm);
1373 set_pin_power_state(codec, 0x2b, &parm);
1375 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1376 update_power_state(codec, 0x1e, parm);
1377 update_power_state(codec, 0x1f, parm);
1378 update_power_state(codec, 0x10, parm);
1379 update_power_state(codec, 0x11, parm);
1383 update_power_state(codec, 0x8, parm);
1385 if (spec->codec_type == VT1802) {
1386 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1388 set_pin_power_state(codec, 0x28, &parm);
1389 update_power_state(codec, 0x18, parm);
1390 update_power_state(codec, 0x38, parm);
1392 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1394 set_pin_power_state(codec, 0x26, &parm);
1395 update_power_state(codec, 0x1c, parm);
1396 update_power_state(codec, 0x37, parm);
1399 if (spec->codec_type == VT1802) {
1400 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1402 set_pin_power_state(codec, 0x25, &parm);
1403 update_power_state(codec, 0x15, parm);
1404 update_power_state(codec, 0x35, parm);
1406 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1408 set_pin_power_state(codec, 0x25, &parm);
1409 update_power_state(codec, 0x19, parm);
1410 update_power_state(codec, 0x35, parm);
1413 if (spec->gen.indep_hp_enabled)
1414 update_power_state(codec, 0x9, AC_PWRST_D0);
1417 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1418 present = snd_hda_jack_detect(codec, 0x25);
1421 set_pin_power_state(codec, 0x24, &parm);
1422 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1423 if (spec->codec_type == VT1802)
1424 update_power_state(codec, 0x14, parm);
1426 update_power_state(codec, 0x18, parm);
1427 update_power_state(codec, 0x34, parm);
1430 present = snd_hda_jack_detect(codec, 0x26);
1432 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1433 if (spec->codec_type == VT1802) {
1434 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
1435 update_power_state(codec, 0x33, parm);
1436 update_power_state(codec, 0x1c, parm);
1437 update_power_state(codec, 0x3c, parm);
1439 /* PW15 (31h), MW8(17h), MUX8(3bh) */
1440 update_power_state(codec, 0x31, parm);
1441 update_power_state(codec, 0x17, parm);
1442 update_power_state(codec, 0x3b, parm);
1445 if (imux_is_smixer || !is_aa_path_mute(codec))
1446 update_power_state(codec, 0x21, AC_PWRST_D0);
1448 update_power_state(codec, 0x21, AC_PWRST_D3);
1455 VIA_FIXUP_INTMIC_BOOST,
1459 static void via_fixup_intmic_boost(struct hda_codec *codec,
1460 const struct hda_fixup *fix, int action)
1462 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1463 override_mic_boost(codec, 0x30, 0, 2, 40);
1466 static const struct hda_fixup via_fixups[] = {
1467 [VIA_FIXUP_INTMIC_BOOST] = {
1468 .type = HDA_FIXUP_FUNC,
1469 .v.func = via_fixup_intmic_boost,
1471 [VIA_FIXUP_ASUS_G75] = {
1472 .type = HDA_FIXUP_PINS,
1473 .v.pins = (const struct hda_pintbl[]) {
1474 /* set 0x24 and 0x33 as speakers */
1475 { 0x24, 0x991301f0 },
1476 { 0x33, 0x991301f1 }, /* subwoofer */
1482 static const struct snd_pci_quirk vt2002p_fixups[] = {
1483 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
1484 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
1488 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
1489 * Replace this with mixer NID 0x1c
1491 static void fix_vt1802_connections(struct hda_codec *codec)
1493 static hda_nid_t conn_24[] = { 0x14, 0x1c };
1494 static hda_nid_t conn_33[] = { 0x1c };
1496 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
1497 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
1500 /* patch for vt2002P */
1501 static int patch_vt2002P(struct hda_codec *codec)
1503 struct via_spec *spec;
1506 /* create a codec specific record */
1507 spec = via_new_spec(codec);
1511 spec->gen.mixer_nid = 0x21;
1512 override_mic_boost(codec, 0x2b, 0, 3, 40);
1513 override_mic_boost(codec, 0x29, 0, 3, 40);
1514 if (spec->codec_type == VT1802)
1515 fix_vt1802_connections(codec);
1516 add_secret_dac_path(codec);
1518 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
1519 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1521 /* automatic parse from the BIOS config */
1522 err = via_parse_auto_config(codec);
1528 if (spec->codec_type == VT1802)
1529 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
1531 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
1533 codec->patch_ops = via_patch_ops;
1535 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
1541 static const struct hda_verb vt1812_init_verbs[] = {
1542 /* Enable Boost Volume backdoor */
1544 /* Enable AOW0 to MW9 */
1549 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1551 struct via_spec *spec = codec->spec;
1553 unsigned int present;
1555 /* PW 5/6/7 (29h/2ah/2bh) */
1557 set_pin_power_state(codec, 0x29, &parm);
1558 set_pin_power_state(codec, 0x2a, &parm);
1559 set_pin_power_state(codec, 0x2b, &parm);
1561 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1562 update_power_state(codec, 0x1e, parm);
1563 update_power_state(codec, 0x1f, parm);
1564 update_power_state(codec, 0x10, parm);
1565 update_power_state(codec, 0x11, parm);
1569 update_power_state(codec, 0x8, AC_PWRST_D0);
1571 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1573 set_pin_power_state(codec, 0x28, &parm);
1574 update_power_state(codec, 0x18, parm);
1575 update_power_state(codec, 0x38, parm);
1577 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1579 set_pin_power_state(codec, 0x25, &parm);
1580 update_power_state(codec, 0x15, parm);
1581 update_power_state(codec, 0x35, parm);
1582 if (spec->gen.indep_hp_enabled)
1583 update_power_state(codec, 0x9, AC_PWRST_D0);
1585 /* Internal Speaker */
1586 /* PW0 (24h), MW0(14h), MUX0(34h) */
1587 present = snd_hda_jack_detect(codec, 0x25);
1590 set_pin_power_state(codec, 0x24, &parm);
1592 update_power_state(codec, 0x14, AC_PWRST_D3);
1593 update_power_state(codec, 0x34, AC_PWRST_D3);
1595 update_power_state(codec, 0x14, AC_PWRST_D0);
1596 update_power_state(codec, 0x34, AC_PWRST_D0);
1601 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1602 present = snd_hda_jack_detect(codec, 0x28);
1605 set_pin_power_state(codec, 0x31, &parm);
1607 update_power_state(codec, 0x1c, AC_PWRST_D3);
1608 update_power_state(codec, 0x3c, AC_PWRST_D3);
1609 update_power_state(codec, 0x3e, AC_PWRST_D3);
1611 update_power_state(codec, 0x1c, AC_PWRST_D0);
1612 update_power_state(codec, 0x3c, AC_PWRST_D0);
1613 update_power_state(codec, 0x3e, AC_PWRST_D0);
1616 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1618 set_pin_power_state(codec, 0x33, &parm);
1619 update_power_state(codec, 0x1d, parm);
1620 update_power_state(codec, 0x3d, parm);
1624 /* patch for vt1812 */
1625 static int patch_vt1812(struct hda_codec *codec)
1627 struct via_spec *spec;
1630 /* create a codec specific record */
1631 spec = via_new_spec(codec);
1635 spec->gen.mixer_nid = 0x21;
1636 override_mic_boost(codec, 0x2b, 0, 3, 40);
1637 override_mic_boost(codec, 0x29, 0, 3, 40);
1638 add_secret_dac_path(codec);
1640 /* automatic parse from the BIOS config */
1641 err = via_parse_auto_config(codec);
1647 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
1649 codec->patch_ops = via_patch_ops;
1651 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
1655 /* patch for vt3476 */
1657 static const struct hda_verb vt3476_init_verbs[] = {
1658 /* Enable DMic 8/16/32K */
1660 /* Enable Boost Volume backdoor */
1662 /* Enable AOW-MW9 path */
1667 static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1669 struct via_spec *spec = codec->spec;
1671 unsigned int parm, parm2;
1672 /* MUX10 (1eh) = stereo mixer */
1674 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1676 /* PW 5/6/7 (29h/2ah/2bh) */
1678 set_pin_power_state(codec, 0x29, &parm);
1679 set_pin_power_state(codec, 0x2a, &parm);
1680 set_pin_power_state(codec, 0x2b, &parm);
1683 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1684 update_power_state(codec, 0x1e, parm);
1685 update_power_state(codec, 0x1f, parm);
1686 update_power_state(codec, 0x10, parm);
1687 update_power_state(codec, 0x11, parm);
1690 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1691 if (spec->codec_type == VT1705CF) {
1693 update_power_state(codec, 0x27, parm);
1694 update_power_state(codec, 0x37, parm);
1697 set_pin_power_state(codec, 0x27, &parm);
1698 update_power_state(codec, 0x37, parm);
1701 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1703 set_pin_power_state(codec, 0x26, &parm);
1704 update_power_state(codec, 0x36, parm);
1705 if (smart51_enabled(codec)) {
1706 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1707 set_pin_power_state(codec, 0x2b, &parm);
1708 update_power_state(codec, 0x3b, parm);
1709 update_power_state(codec, 0x1b, parm);
1711 update_conv_power_state(codec, 0xa, parm, 2);
1713 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1715 set_pin_power_state(codec, 0x25, &parm);
1716 update_power_state(codec, 0x35, parm);
1717 if (smart51_enabled(codec)) {
1718 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1719 set_pin_power_state(codec, 0x2a, &parm);
1720 update_power_state(codec, 0x3a, parm);
1721 update_power_state(codec, 0x1a, parm);
1723 update_conv_power_state(codec, 0x9, parm, 1);
1725 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1727 set_pin_power_state(codec, 0x28, &parm);
1728 update_power_state(codec, 0x38, parm);
1729 update_power_state(codec, 0x18, parm);
1730 if (spec->gen.indep_hp_enabled)
1731 update_conv_power_state(codec, 0xb, parm, 3);
1732 parm2 = parm; /* for pin 0x0b */
1734 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1736 set_pin_power_state(codec, 0x24, &parm);
1737 update_power_state(codec, 0x34, parm);
1738 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1740 update_conv_power_state(codec, 0x8, parm, 0);
1741 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1742 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1745 static int patch_vt3476(struct hda_codec *codec)
1747 struct via_spec *spec;
1750 /* create a codec specific record */
1751 spec = via_new_spec(codec);
1755 spec->gen.mixer_nid = 0x3f;
1756 add_secret_dac_path(codec);
1758 /* automatic parse from the BIOS config */
1759 err = via_parse_auto_config(codec);
1765 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1767 codec->patch_ops = via_patch_ops;
1769 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1777 static const struct hda_codec_preset snd_hda_preset_via[] = {
1778 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
1779 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
1780 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
1781 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
1782 { .id = 0x1106e710, .name = "VT1709 10-Ch",
1783 .patch = patch_vt1709},
1784 { .id = 0x1106e711, .name = "VT1709 10-Ch",
1785 .patch = patch_vt1709},
1786 { .id = 0x1106e712, .name = "VT1709 10-Ch",
1787 .patch = patch_vt1709},
1788 { .id = 0x1106e713, .name = "VT1709 10-Ch",
1789 .patch = patch_vt1709},
1790 { .id = 0x1106e714, .name = "VT1709 6-Ch",
1791 .patch = patch_vt1709},
1792 { .id = 0x1106e715, .name = "VT1709 6-Ch",
1793 .patch = patch_vt1709},
1794 { .id = 0x1106e716, .name = "VT1709 6-Ch",
1795 .patch = patch_vt1709},
1796 { .id = 0x1106e717, .name = "VT1709 6-Ch",
1797 .patch = patch_vt1709},
1798 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
1799 .patch = patch_vt1708B},
1800 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
1801 .patch = patch_vt1708B},
1802 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
1803 .patch = patch_vt1708B},
1804 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
1805 .patch = patch_vt1708B},
1806 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
1807 .patch = patch_vt1708B},
1808 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
1809 .patch = patch_vt1708B},
1810 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
1811 .patch = patch_vt1708B},
1812 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
1813 .patch = patch_vt1708B},
1814 { .id = 0x11060397, .name = "VT1708S",
1815 .patch = patch_vt1708S},
1816 { .id = 0x11061397, .name = "VT1708S",
1817 .patch = patch_vt1708S},
1818 { .id = 0x11062397, .name = "VT1708S",
1819 .patch = patch_vt1708S},
1820 { .id = 0x11063397, .name = "VT1708S",
1821 .patch = patch_vt1708S},
1822 { .id = 0x11064397, .name = "VT1705",
1823 .patch = patch_vt1708S},
1824 { .id = 0x11065397, .name = "VT1708S",
1825 .patch = patch_vt1708S},
1826 { .id = 0x11066397, .name = "VT1708S",
1827 .patch = patch_vt1708S},
1828 { .id = 0x11067397, .name = "VT1708S",
1829 .patch = patch_vt1708S},
1830 { .id = 0x11060398, .name = "VT1702",
1831 .patch = patch_vt1702},
1832 { .id = 0x11061398, .name = "VT1702",
1833 .patch = patch_vt1702},
1834 { .id = 0x11062398, .name = "VT1702",
1835 .patch = patch_vt1702},
1836 { .id = 0x11063398, .name = "VT1702",
1837 .patch = patch_vt1702},
1838 { .id = 0x11064398, .name = "VT1702",
1839 .patch = patch_vt1702},
1840 { .id = 0x11065398, .name = "VT1702",
1841 .patch = patch_vt1702},
1842 { .id = 0x11066398, .name = "VT1702",
1843 .patch = patch_vt1702},
1844 { .id = 0x11067398, .name = "VT1702",
1845 .patch = patch_vt1702},
1846 { .id = 0x11060428, .name = "VT1718S",
1847 .patch = patch_vt1718S},
1848 { .id = 0x11064428, .name = "VT1718S",
1849 .patch = patch_vt1718S},
1850 { .id = 0x11060441, .name = "VT2020",
1851 .patch = patch_vt1718S},
1852 { .id = 0x11064441, .name = "VT1828S",
1853 .patch = patch_vt1718S},
1854 { .id = 0x11060433, .name = "VT1716S",
1855 .patch = patch_vt1716S},
1856 { .id = 0x1106a721, .name = "VT1716S",
1857 .patch = patch_vt1716S},
1858 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
1859 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
1860 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
1861 { .id = 0x11060440, .name = "VT1818S",
1862 .patch = patch_vt1708S},
1863 { .id = 0x11060446, .name = "VT1802",
1864 .patch = patch_vt2002P},
1865 { .id = 0x11068446, .name = "VT1802",
1866 .patch = patch_vt2002P},
1867 { .id = 0x11064760, .name = "VT1705CF",
1868 .patch = patch_vt3476},
1869 { .id = 0x11064761, .name = "VT1708SCE",
1870 .patch = patch_vt3476},
1871 { .id = 0x11064762, .name = "VT1808",
1872 .patch = patch_vt3476},
1876 MODULE_ALIAS("snd-hda-codec-id:1106*");
1878 static struct hda_codec_preset_list via_list = {
1879 .preset = snd_hda_preset_via,
1880 .owner = THIS_MODULE,
1883 MODULE_LICENSE("GPL");
1884 MODULE_DESCRIPTION("VIA HD-audio codec");
1886 static int __init patch_via_init(void)
1888 return snd_hda_add_codec_preset(&via_list);
1891 static void __exit patch_via_exit(void)
1893 snd_hda_delete_codec_preset(&via_list);
1896 module_init(patch_via_init)
1897 module_exit(patch_via_exit)