1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Universal Interface for Intel High Definition Audio Codec
5 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
7 * (C) 2006-2009 VIA Technology, Inc.
8 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
11 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
13 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
14 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
15 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
16 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
17 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
18 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
19 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
20 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
21 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
22 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
23 /* 2008-04-09 Lydia Wang Add Independent HP feature */
24 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
25 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
26 /* 2009-02-16 Logan Li Add support for VT1718S */
27 /* 2009-03-13 Logan Li Add support for VT1716S */
28 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
29 /* 2009-07-08 Lydia Wang Add support for VT2002P */
30 /* 2009-07-21 Lydia Wang Add support for VT1812 */
31 /* 2009-09-19 Lydia Wang Add support for VT1818S */
33 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
36 #include <linux/init.h>
37 #include <linux/delay.h>
38 #include <linux/slab.h>
39 #include <linux/module.h>
40 #include <sound/core.h>
41 #include <sound/asoundef.h>
42 #include <sound/hda_codec.h>
43 #include "hda_local.h"
44 #include "hda_auto_parser.h"
46 #include "hda_generic.h"
49 #define VT1708_HP_PIN_NID 0x20
50 #define VT1708_CD_PIN_NID 0x24
72 #define VT2002P_COMPATIBLE(spec) \
73 ((spec)->codec_type == VT2002P ||\
74 (spec)->codec_type == VT1812 ||\
75 (spec)->codec_type == VT1802)
78 struct hda_gen_spec gen;
81 unsigned int dmic_enabled;
82 enum VIA_HDA_CODEC codec_type;
84 /* analog low-power control */
87 /* work to check hp jack state */
89 int vt1708_jack_detect;
92 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
93 static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
94 struct hda_codec *codec,
95 struct snd_pcm_substream *substream,
98 static const struct hda_codec_ops via_patch_ops; /* defined below */
100 static struct via_spec *via_new_spec(struct hda_codec *codec)
102 struct via_spec *spec;
104 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
109 snd_hda_gen_spec_init(&spec->gen);
110 spec->codec_type = get_codec_type(codec);
111 /* VT1708BCE & VT1708S are almost same */
112 if (spec->codec_type == VT1708BCE)
113 spec->codec_type = VT1708S;
114 spec->gen.indep_hp = 1;
115 spec->gen.keep_eapd_on = 1;
116 spec->gen.pcm_playback_hook = via_playback_pcm_hook;
117 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
118 codec->power_save_node = 1;
119 spec->gen.power_down_unused = 1;
120 codec->patch_ops = via_patch_ops;
124 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
126 u32 vendor_id = codec->core.vendor_id;
127 u16 ven_id = vendor_id >> 16;
128 u16 dev_id = vendor_id & 0xffff;
129 enum VIA_HDA_CODEC codec_type;
132 if (ven_id != 0x1106)
133 codec_type = UNKNOWN;
134 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
136 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
137 codec_type = VT1709_10CH;
138 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
139 codec_type = VT1709_6CH;
140 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
141 codec_type = VT1708B_8CH;
142 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
143 codec_type = VT1708BCE;
144 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
145 codec_type = VT1708B_4CH;
146 else if ((dev_id & 0xfff) == 0x397
147 && (dev_id >> 12) < 8)
148 codec_type = VT1708S;
149 else if ((dev_id & 0xfff) == 0x398
150 && (dev_id >> 12) < 8)
152 else if ((dev_id & 0xfff) == 0x428
153 && (dev_id >> 12) < 8)
154 codec_type = VT1718S;
155 else if (dev_id == 0x0433 || dev_id == 0xa721)
156 codec_type = VT1716S;
157 else if (dev_id == 0x0441 || dev_id == 0x4441)
158 codec_type = VT1718S;
159 else if (dev_id == 0x0438 || dev_id == 0x4438)
160 codec_type = VT2002P;
161 else if (dev_id == 0x0448)
163 else if (dev_id == 0x0440)
164 codec_type = VT1708S;
165 else if ((dev_id & 0xfff) == 0x446)
167 else if (dev_id == 0x4760)
168 codec_type = VT1705CF;
169 else if (dev_id == 0x4761 || dev_id == 0x4762)
172 codec_type = UNKNOWN;
176 static void analog_low_current_mode(struct hda_codec *codec);
177 static bool is_aa_path_mute(struct hda_codec *codec);
179 #define hp_detect_with_aa(codec) \
180 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
181 !is_aa_path_mute(codec))
183 static void vt1708_stop_hp_work(struct hda_codec *codec)
185 struct via_spec *spec = codec->spec;
186 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
188 if (spec->hp_work_active) {
189 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
190 codec->jackpoll_interval = 0;
191 cancel_delayed_work_sync(&codec->jackpoll_work);
192 spec->hp_work_active = false;
196 static void vt1708_update_hp_work(struct hda_codec *codec)
198 struct via_spec *spec = codec->spec;
199 if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
201 if (spec->vt1708_jack_detect) {
202 if (!spec->hp_work_active) {
203 codec->jackpoll_interval = msecs_to_jiffies(100);
204 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
205 schedule_delayed_work(&codec->jackpoll_work, 0);
206 spec->hp_work_active = true;
208 } else if (!hp_detect_with_aa(codec))
209 vt1708_stop_hp_work(codec);
212 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
213 struct snd_ctl_elem_info *uinfo)
215 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
218 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
219 struct snd_ctl_elem_value *ucontrol)
221 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
222 struct via_spec *spec = codec->spec;
224 ucontrol->value.enumerated.item[0] = spec->gen.power_down_unused;
228 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
229 struct snd_ctl_elem_value *ucontrol)
231 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
232 struct via_spec *spec = codec->spec;
233 bool val = !!ucontrol->value.enumerated.item[0];
235 if (val == spec->gen.power_down_unused)
237 /* codec->power_save_node = val; */ /* widget PM seems yet broken */
238 spec->gen.power_down_unused = val;
239 analog_low_current_mode(codec);
243 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
245 .name = "Dynamic Power-Control",
246 .info = via_pin_power_ctl_info,
247 .get = via_pin_power_ctl_get,
248 .put = via_pin_power_ctl_put,
251 #ifdef CONFIG_SND_HDA_INPUT_BEEP
252 /* additional beep mixers; the actual parameters are overwritten at build */
253 static const struct snd_kcontrol_new via_beep_mixer[] = {
254 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
255 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
258 static int set_beep_amp(struct via_spec *spec, hda_nid_t nid,
261 struct snd_kcontrol_new *knew;
262 unsigned int beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
265 spec->gen.beep_nid = nid;
266 for (i = 0; i < ARRAY_SIZE(via_beep_mixer); i++) {
267 knew = snd_hda_gen_add_kctl(&spec->gen, NULL,
271 knew->private_value = beep_amp;
276 static int auto_parse_beep(struct hda_codec *codec)
278 struct via_spec *spec = codec->spec;
281 for_each_hda_codec_node(nid, codec)
282 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP)
283 return set_beep_amp(spec, nid, 0, HDA_OUTPUT);
287 #define auto_parse_beep(codec) 0
290 /* check AA path's mute status */
291 static bool is_aa_path_mute(struct hda_codec *codec)
293 struct via_spec *spec = codec->spec;
294 const struct hda_amp_list *p;
297 p = spec->gen.loopback.amplist;
300 for (; p->nid; p++) {
301 for (ch = 0; ch < 2; ch++) {
302 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
304 if (!(v & HDA_AMP_MUTE) && v > 0)
311 /* enter/exit analog low-current mode */
312 static void __analog_low_current_mode(struct hda_codec *codec, bool force)
314 struct via_spec *spec = codec->spec;
316 unsigned int verb, parm;
318 if (!codec->power_save_node)
321 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
322 if (enable == spec->alc_mode && !force)
324 spec->alc_mode = enable;
326 /* decide low current mode's verb & parameter */
327 switch (spec->codec_type) {
331 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
337 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
341 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
347 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
352 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
355 return; /* other codecs are not supported */
358 snd_hda_codec_write(codec, codec->core.afg, 0, verb, parm);
361 static void analog_low_current_mode(struct hda_codec *codec)
363 return __analog_low_current_mode(codec, false);
366 static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
367 struct hda_codec *codec,
368 struct snd_pcm_substream *substream,
371 analog_low_current_mode(codec);
372 vt1708_update_hp_work(codec);
375 static void via_free(struct hda_codec *codec)
377 vt1708_stop_hp_work(codec);
378 snd_hda_gen_free(codec);
382 static int via_suspend(struct hda_codec *codec)
384 struct via_spec *spec = codec->spec;
385 vt1708_stop_hp_work(codec);
387 /* Fix pop noise on headphones */
388 if (spec->codec_type == VT1802)
389 snd_hda_shutup_pins(codec);
394 static int via_resume(struct hda_codec *codec)
396 /* some delay here to make jack detection working (bko#98921) */
398 codec->patch_ops.init(codec);
399 snd_hda_regmap_sync(codec);
405 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
407 struct via_spec *spec = codec->spec;
408 analog_low_current_mode(codec);
409 vt1708_update_hp_work(codec);
410 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
417 static int via_init(struct hda_codec *codec);
419 static const struct hda_codec_ops via_patch_ops = {
420 .build_controls = snd_hda_gen_build_controls,
421 .build_pcms = snd_hda_gen_build_pcms,
424 .unsol_event = snd_hda_jack_unsol_event,
426 .suspend = via_suspend,
427 .resume = via_resume,
428 .check_power_status = via_check_power_status,
433 static const struct hda_verb vt1708_init_verbs[] = {
434 /* power down jack detect function */
438 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
440 unsigned int def_conf;
441 unsigned char seqassoc;
443 def_conf = snd_hda_codec_get_pincfg(codec, nid);
444 seqassoc = (unsigned char) get_defcfg_association(def_conf);
445 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
446 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
447 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
448 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
449 snd_hda_codec_set_pincfg(codec, nid, def_conf);
455 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_value *ucontrol)
458 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
459 struct via_spec *spec = codec->spec;
461 if (spec->codec_type != VT1708)
463 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
467 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
468 struct snd_ctl_elem_value *ucontrol)
470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
471 struct via_spec *spec = codec->spec;
474 if (spec->codec_type != VT1708)
476 val = !!ucontrol->value.integer.value[0];
477 if (spec->vt1708_jack_detect == val)
479 spec->vt1708_jack_detect = val;
480 vt1708_update_hp_work(codec);
484 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
486 .name = "Jack Detect",
488 .info = snd_ctl_boolean_mono_info,
489 .get = vt1708_jack_detect_get,
490 .put = vt1708_jack_detect_put,
493 static const struct badness_table via_main_out_badness = {
494 .no_primary_dac = 0x10000,
496 .shared_primary = 0x10000,
499 .shared_surr_main = 0x20,
501 static const struct badness_table via_extra_out_badness = {
502 .no_primary_dac = 0x4000,
504 .shared_primary = 0x12,
507 .shared_surr_main = 0x10,
510 static int via_parse_auto_config(struct hda_codec *codec)
512 struct via_spec *spec = codec->spec;
515 spec->gen.main_out_badness = &via_main_out_badness;
516 spec->gen.extra_out_badness = &via_extra_out_badness;
518 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
522 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
526 err = auto_parse_beep(codec);
530 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &via_pin_power_ctl_enum))
533 /* disable widget PM at start for compatibility */
534 codec->power_save_node = 0;
535 spec->gen.power_down_unused = 0;
539 static int via_init(struct hda_codec *codec)
541 /* init power states */
542 __analog_low_current_mode(codec, true);
544 snd_hda_gen_init(codec);
546 vt1708_update_hp_work(codec);
551 static int vt1708_build_controls(struct hda_codec *codec)
553 /* In order not to create "Phantom Jack" controls,
554 temporary enable jackpoll */
556 int old_interval = codec->jackpoll_interval;
557 codec->jackpoll_interval = msecs_to_jiffies(100);
558 err = snd_hda_gen_build_controls(codec);
559 codec->jackpoll_interval = old_interval;
563 static int vt1708_build_pcms(struct hda_codec *codec)
565 struct via_spec *spec = codec->spec;
568 err = snd_hda_gen_build_pcms(codec);
569 if (err < 0 || codec->core.vendor_id != 0x11061708)
572 /* We got noisy outputs on the right channel on VT1708 when
573 * 24bit samples are used. Until any workaround is found,
574 * disable the 24bit format, so far.
576 for (i = 0; i < ARRAY_SIZE(spec->gen.pcm_rec); i++) {
577 struct hda_pcm *info = spec->gen.pcm_rec[i];
580 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
581 info->pcm_type != HDA_PCM_TYPE_AUDIO)
583 info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
584 SNDRV_PCM_FMTBIT_S16_LE;
590 static int patch_vt1708(struct hda_codec *codec)
592 struct via_spec *spec;
595 /* create a codec specific record */
596 spec = via_new_spec(codec);
600 /* override some patch_ops */
601 codec->patch_ops.build_controls = vt1708_build_controls;
602 codec->patch_ops.build_pcms = vt1708_build_pcms;
603 spec->gen.mixer_nid = 0x17;
605 /* set jackpoll_interval while parsing the codec */
606 codec->jackpoll_interval = msecs_to_jiffies(100);
607 spec->vt1708_jack_detect = 1;
609 /* don't support the input jack switching due to lack of unsol event */
610 /* (it may work with polling, though, but it needs testing) */
611 spec->gen.suppress_auto_mic = 1;
612 /* Some machines show the broken speaker mute */
613 spec->gen.auto_mute_via_amp = 1;
615 /* Add HP and CD pin config connect bit re-config action */
616 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
617 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
619 err = snd_hda_add_verbs(codec, vt1708_init_verbs);
623 /* automatic parse from the BIOS config */
624 err = via_parse_auto_config(codec);
628 /* add jack detect on/off control */
629 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1708_jack_detect_ctl)) {
634 /* clear jackpoll_interval again; it's set dynamically */
635 codec->jackpoll_interval = 0;
644 static int patch_vt1709(struct hda_codec *codec)
646 struct via_spec *spec;
649 /* create a codec specific record */
650 spec = via_new_spec(codec);
654 spec->gen.mixer_nid = 0x18;
656 err = via_parse_auto_config(codec);
667 static int patch_vt1708S(struct hda_codec *codec);
668 static int patch_vt1708B(struct hda_codec *codec)
670 struct via_spec *spec;
673 if (get_codec_type(codec) == VT1708BCE)
674 return patch_vt1708S(codec);
676 /* create a codec specific record */
677 spec = via_new_spec(codec);
681 spec->gen.mixer_nid = 0x16;
683 /* automatic parse from the BIOS config */
684 err = via_parse_auto_config(codec);
695 /* Patch for VT1708S */
696 static const struct hda_verb vt1708S_init_verbs[] = {
697 /* Enable Mic Boost Volume backdoor */
699 /* don't bybass mixer */
704 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
705 int offset, int num_steps, int step_size)
707 snd_hda_override_wcaps(codec, pin,
708 get_wcaps(codec, pin) | AC_WCAP_IN_AMP);
709 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
710 (offset << AC_AMPCAP_OFFSET_SHIFT) |
711 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
712 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
713 (0 << AC_AMPCAP_MUTE_SHIFT));
716 static int patch_vt1708S(struct hda_codec *codec)
718 struct via_spec *spec;
721 /* create a codec specific record */
722 spec = via_new_spec(codec);
726 spec->gen.mixer_nid = 0x16;
727 override_mic_boost(codec, 0x1a, 0, 3, 40);
728 override_mic_boost(codec, 0x1e, 0, 3, 40);
730 /* correct names for VT1708BCE */
731 if (get_codec_type(codec) == VT1708BCE)
732 snd_hda_codec_set_name(codec, "VT1708BCE");
733 /* correct names for VT1705 */
734 if (codec->core.vendor_id == 0x11064397)
735 snd_hda_codec_set_name(codec, "VT1705");
737 err = snd_hda_add_verbs(codec, vt1708S_init_verbs);
741 /* automatic parse from the BIOS config */
742 err = via_parse_auto_config(codec);
753 /* Patch for VT1702 */
755 static const struct hda_verb vt1702_init_verbs[] = {
763 static int patch_vt1702(struct hda_codec *codec)
765 struct via_spec *spec;
768 /* create a codec specific record */
769 spec = via_new_spec(codec);
773 spec->gen.mixer_nid = 0x1a;
775 /* limit AA path volume to 0 dB */
776 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
777 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
778 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
779 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
780 (1 << AC_AMPCAP_MUTE_SHIFT));
782 err = snd_hda_add_verbs(codec, vt1702_init_verbs);
786 /* automatic parse from the BIOS config */
787 err = via_parse_auto_config(codec);
798 /* Patch for VT1718S */
800 static const struct hda_verb vt1718S_init_verbs[] = {
801 /* Enable MW0 adjust Gain 5 */
803 /* Enable Boost Volume backdoor */
809 /* Add a connection to the primary DAC from AA-mixer for some codecs
810 * This isn't listed from the raw info, but the chip has a secret connection.
812 static int add_secret_dac_path(struct hda_codec *codec)
814 struct via_spec *spec = codec->spec;
819 if (!spec->gen.mixer_nid)
821 nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
822 ARRAY_SIZE(conn) - 1);
823 for (i = 0; i < nums; i++) {
824 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
828 /* find the primary DAC and add to the connection list */
829 for_each_hda_codec_node(nid, codec) {
830 unsigned int caps = get_wcaps(codec, nid);
831 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
832 !(caps & AC_WCAP_DIGITAL)) {
834 return snd_hda_override_conn_list(codec,
843 static int patch_vt1718S(struct hda_codec *codec)
845 struct via_spec *spec;
848 /* create a codec specific record */
849 spec = via_new_spec(codec);
853 spec->gen.mixer_nid = 0x21;
854 override_mic_boost(codec, 0x2b, 0, 3, 40);
855 override_mic_boost(codec, 0x29, 0, 3, 40);
856 add_secret_dac_path(codec);
858 err = snd_hda_add_verbs(codec, vt1718S_init_verbs);
862 /* automatic parse from the BIOS config */
863 err = via_parse_auto_config(codec);
874 /* Patch for VT1716S */
876 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
877 struct snd_ctl_elem_info *uinfo)
879 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
881 uinfo->value.integer.min = 0;
882 uinfo->value.integer.max = 1;
886 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
887 struct snd_ctl_elem_value *ucontrol)
889 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
892 index = snd_hda_codec_read(codec, 0x26, 0,
893 AC_VERB_GET_CONNECT_SEL, 0);
895 *ucontrol->value.integer.value = index;
900 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
901 struct snd_ctl_elem_value *ucontrol)
903 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
904 struct via_spec *spec = codec->spec;
905 int index = *ucontrol->value.integer.value;
907 snd_hda_codec_write(codec, 0x26, 0,
908 AC_VERB_SET_CONNECT_SEL, index);
909 spec->dmic_enabled = index;
913 static const struct snd_kcontrol_new vt1716s_dmic_mixer_vol =
914 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT);
915 static const struct snd_kcontrol_new vt1716s_dmic_mixer_sw = {
916 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
917 .name = "Digital Mic Capture Switch",
918 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
920 .info = vt1716s_dmic_info,
921 .get = vt1716s_dmic_get,
922 .put = vt1716s_dmic_put,
926 /* mono-out mixer elements */
927 static const struct snd_kcontrol_new vt1716S_mono_out_mixer =
928 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT);
930 static const struct hda_verb vt1716S_init_verbs[] = {
931 /* Enable Boost Volume backdoor */
933 /* don't bybass mixer */
935 /* Enable mono output */
940 static int patch_vt1716S(struct hda_codec *codec)
942 struct via_spec *spec;
945 /* create a codec specific record */
946 spec = via_new_spec(codec);
950 spec->gen.mixer_nid = 0x16;
951 override_mic_boost(codec, 0x1a, 0, 3, 40);
952 override_mic_boost(codec, 0x1e, 0, 3, 40);
954 err = snd_hda_add_verbs(codec, vt1716S_init_verbs);
958 /* automatic parse from the BIOS config */
959 err = via_parse_auto_config(codec);
963 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1716s_dmic_mixer_vol) ||
964 !snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1716s_dmic_mixer_sw) ||
965 !snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1716S_mono_out_mixer)) {
979 static const struct hda_verb vt2002P_init_verbs[] = {
980 /* Class-D speaker related verbs */
984 /* Enable Boost Volume backdoor */
986 /* Enable AOW0 to MW9 */
991 static const struct hda_verb vt1802_init_verbs[] = {
992 /* Enable Boost Volume backdoor */
994 /* Enable AOW0 to MW9 */
1003 VIA_FIXUP_INTMIC_BOOST,
1005 VIA_FIXUP_POWER_SAVE,
1008 static void via_fixup_intmic_boost(struct hda_codec *codec,
1009 const struct hda_fixup *fix, int action)
1011 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1012 override_mic_boost(codec, 0x30, 0, 2, 40);
1015 static void via_fixup_power_save(struct hda_codec *codec,
1016 const struct hda_fixup *fix, int action)
1018 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1019 codec->power_save_node = 0;
1022 static const struct hda_fixup via_fixups[] = {
1023 [VIA_FIXUP_INTMIC_BOOST] = {
1024 .type = HDA_FIXUP_FUNC,
1025 .v.func = via_fixup_intmic_boost,
1027 [VIA_FIXUP_ASUS_G75] = {
1028 .type = HDA_FIXUP_PINS,
1029 .v.pins = (const struct hda_pintbl[]) {
1030 /* set 0x24 and 0x33 as speakers */
1031 { 0x24, 0x991301f0 },
1032 { 0x33, 0x991301f1 }, /* subwoofer */
1036 [VIA_FIXUP_POWER_SAVE] = {
1037 .type = HDA_FIXUP_FUNC,
1038 .v.func = via_fixup_power_save,
1042 static const struct snd_pci_quirk vt2002p_fixups[] = {
1043 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
1044 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
1045 SND_PCI_QUIRK(0x1558, 0x3501, "Clevo W35xSS_370SS", VIA_FIXUP_POWER_SAVE),
1049 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
1050 * Replace this with mixer NID 0x1c
1052 static void fix_vt1802_connections(struct hda_codec *codec)
1054 static const hda_nid_t conn_24[] = { 0x14, 0x1c };
1055 static const hda_nid_t conn_33[] = { 0x1c };
1057 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
1058 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
1061 /* patch for vt2002P */
1062 static int patch_vt2002P(struct hda_codec *codec)
1064 struct via_spec *spec;
1067 /* create a codec specific record */
1068 spec = via_new_spec(codec);
1072 spec->gen.mixer_nid = 0x21;
1073 override_mic_boost(codec, 0x2b, 0, 3, 40);
1074 override_mic_boost(codec, 0x29, 0, 3, 40);
1075 if (spec->codec_type == VT1802)
1076 fix_vt1802_connections(codec);
1077 add_secret_dac_path(codec);
1079 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
1080 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1082 if (spec->codec_type == VT1802)
1083 err = snd_hda_add_verbs(codec, vt1802_init_verbs);
1085 err = snd_hda_add_verbs(codec, vt2002P_init_verbs);
1089 /* automatic parse from the BIOS config */
1090 err = via_parse_auto_config(codec);
1103 static const struct hda_verb vt1812_init_verbs[] = {
1104 /* Enable Boost Volume backdoor */
1106 /* Enable AOW0 to MW9 */
1111 /* patch for vt1812 */
1112 static int patch_vt1812(struct hda_codec *codec)
1114 struct via_spec *spec;
1117 /* create a codec specific record */
1118 spec = via_new_spec(codec);
1122 spec->gen.mixer_nid = 0x21;
1123 override_mic_boost(codec, 0x2b, 0, 3, 40);
1124 override_mic_boost(codec, 0x29, 0, 3, 40);
1125 add_secret_dac_path(codec);
1127 err = snd_hda_add_verbs(codec, vt1812_init_verbs);
1131 /* automatic parse from the BIOS config */
1132 err = via_parse_auto_config(codec);
1143 /* patch for vt3476 */
1145 static const struct hda_verb vt3476_init_verbs[] = {
1146 /* Enable DMic 8/16/32K */
1148 /* Enable Boost Volume backdoor */
1150 /* Enable AOW-MW9 path */
1155 static int patch_vt3476(struct hda_codec *codec)
1157 struct via_spec *spec;
1160 /* create a codec specific record */
1161 spec = via_new_spec(codec);
1165 spec->gen.mixer_nid = 0x3f;
1166 add_secret_dac_path(codec);
1168 err = snd_hda_add_verbs(codec, vt3476_init_verbs);
1172 /* automatic parse from the BIOS config */
1173 err = via_parse_auto_config(codec);
1187 static const struct hda_device_id snd_hda_id_via[] = {
1188 HDA_CODEC_ENTRY(0x11061708, "VT1708", patch_vt1708),
1189 HDA_CODEC_ENTRY(0x11061709, "VT1708", patch_vt1708),
1190 HDA_CODEC_ENTRY(0x1106170a, "VT1708", patch_vt1708),
1191 HDA_CODEC_ENTRY(0x1106170b, "VT1708", patch_vt1708),
1192 HDA_CODEC_ENTRY(0x1106e710, "VT1709 10-Ch", patch_vt1709),
1193 HDA_CODEC_ENTRY(0x1106e711, "VT1709 10-Ch", patch_vt1709),
1194 HDA_CODEC_ENTRY(0x1106e712, "VT1709 10-Ch", patch_vt1709),
1195 HDA_CODEC_ENTRY(0x1106e713, "VT1709 10-Ch", patch_vt1709),
1196 HDA_CODEC_ENTRY(0x1106e714, "VT1709 6-Ch", patch_vt1709),
1197 HDA_CODEC_ENTRY(0x1106e715, "VT1709 6-Ch", patch_vt1709),
1198 HDA_CODEC_ENTRY(0x1106e716, "VT1709 6-Ch", patch_vt1709),
1199 HDA_CODEC_ENTRY(0x1106e717, "VT1709 6-Ch", patch_vt1709),
1200 HDA_CODEC_ENTRY(0x1106e720, "VT1708B 8-Ch", patch_vt1708B),
1201 HDA_CODEC_ENTRY(0x1106e721, "VT1708B 8-Ch", patch_vt1708B),
1202 HDA_CODEC_ENTRY(0x1106e722, "VT1708B 8-Ch", patch_vt1708B),
1203 HDA_CODEC_ENTRY(0x1106e723, "VT1708B 8-Ch", patch_vt1708B),
1204 HDA_CODEC_ENTRY(0x1106e724, "VT1708B 4-Ch", patch_vt1708B),
1205 HDA_CODEC_ENTRY(0x1106e725, "VT1708B 4-Ch", patch_vt1708B),
1206 HDA_CODEC_ENTRY(0x1106e726, "VT1708B 4-Ch", patch_vt1708B),
1207 HDA_CODEC_ENTRY(0x1106e727, "VT1708B 4-Ch", patch_vt1708B),
1208 HDA_CODEC_ENTRY(0x11060397, "VT1708S", patch_vt1708S),
1209 HDA_CODEC_ENTRY(0x11061397, "VT1708S", patch_vt1708S),
1210 HDA_CODEC_ENTRY(0x11062397, "VT1708S", patch_vt1708S),
1211 HDA_CODEC_ENTRY(0x11063397, "VT1708S", patch_vt1708S),
1212 HDA_CODEC_ENTRY(0x11064397, "VT1705", patch_vt1708S),
1213 HDA_CODEC_ENTRY(0x11065397, "VT1708S", patch_vt1708S),
1214 HDA_CODEC_ENTRY(0x11066397, "VT1708S", patch_vt1708S),
1215 HDA_CODEC_ENTRY(0x11067397, "VT1708S", patch_vt1708S),
1216 HDA_CODEC_ENTRY(0x11060398, "VT1702", patch_vt1702),
1217 HDA_CODEC_ENTRY(0x11061398, "VT1702", patch_vt1702),
1218 HDA_CODEC_ENTRY(0x11062398, "VT1702", patch_vt1702),
1219 HDA_CODEC_ENTRY(0x11063398, "VT1702", patch_vt1702),
1220 HDA_CODEC_ENTRY(0x11064398, "VT1702", patch_vt1702),
1221 HDA_CODEC_ENTRY(0x11065398, "VT1702", patch_vt1702),
1222 HDA_CODEC_ENTRY(0x11066398, "VT1702", patch_vt1702),
1223 HDA_CODEC_ENTRY(0x11067398, "VT1702", patch_vt1702),
1224 HDA_CODEC_ENTRY(0x11060428, "VT1718S", patch_vt1718S),
1225 HDA_CODEC_ENTRY(0x11064428, "VT1718S", patch_vt1718S),
1226 HDA_CODEC_ENTRY(0x11060441, "VT2020", patch_vt1718S),
1227 HDA_CODEC_ENTRY(0x11064441, "VT1828S", patch_vt1718S),
1228 HDA_CODEC_ENTRY(0x11060433, "VT1716S", patch_vt1716S),
1229 HDA_CODEC_ENTRY(0x1106a721, "VT1716S", patch_vt1716S),
1230 HDA_CODEC_ENTRY(0x11060438, "VT2002P", patch_vt2002P),
1231 HDA_CODEC_ENTRY(0x11064438, "VT2002P", patch_vt2002P),
1232 HDA_CODEC_ENTRY(0x11060448, "VT1812", patch_vt1812),
1233 HDA_CODEC_ENTRY(0x11060440, "VT1818S", patch_vt1708S),
1234 HDA_CODEC_ENTRY(0x11060446, "VT1802", patch_vt2002P),
1235 HDA_CODEC_ENTRY(0x11068446, "VT1802", patch_vt2002P),
1236 HDA_CODEC_ENTRY(0x11064760, "VT1705CF", patch_vt3476),
1237 HDA_CODEC_ENTRY(0x11064761, "VT1708SCE", patch_vt3476),
1238 HDA_CODEC_ENTRY(0x11064762, "VT1808", patch_vt3476),
1241 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_via);
1243 static struct hda_codec_driver via_driver = {
1244 .id = snd_hda_id_via,
1247 MODULE_LICENSE("GPL");
1248 MODULE_DESCRIPTION("VIA HD-audio codec");
1250 module_hda_codec_driver(via_driver);