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 if (snd_hda_codec_read(codec, nid, 0,
244 AC_VERB_GET_POWER_STATE, 0) == parm)
246 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
249 static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
250 unsigned int parm, unsigned int index)
252 struct via_spec *spec = codec->spec;
254 if (snd_hda_codec_read(codec, nid, 0,
255 AC_VERB_GET_POWER_STATE, 0) == parm)
257 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
258 if (format && (spec->dac_stream_tag[index] != format))
259 spec->dac_stream_tag[index] = format;
261 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
262 if (parm == AC_PWRST_D0) {
263 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
264 if (!format && (spec->dac_stream_tag[index] != format))
265 snd_hda_codec_write(codec, nid, 0,
266 AC_VERB_SET_CHANNEL_STREAMID,
267 spec->dac_stream_tag[index]);
271 static bool smart51_enabled(struct hda_codec *codec)
273 struct via_spec *spec = codec->spec;
274 return spec->gen.ext_channel_count > 2;
277 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
279 struct via_spec *spec = codec->spec;
282 for (i = 0; i < spec->gen.multi_ios; i++)
283 if (spec->gen.multi_io[i].pin == pin)
288 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
289 unsigned int *affected_parm)
292 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
293 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
294 >> AC_DEFCFG_MISC_SHIFT
295 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
296 struct via_spec *spec = codec->spec;
297 unsigned present = 0;
299 no_presence |= spec->no_pin_power_ctl;
301 present = snd_hda_jack_detect(codec, nid);
302 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
303 || ((no_presence || present)
304 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
305 *affected_parm = AC_PWRST_D0; /* if it's connected */
310 update_power_state(codec, nid, parm);
313 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
314 struct snd_ctl_elem_info *uinfo)
316 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
319 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
320 struct snd_ctl_elem_value *ucontrol)
322 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
323 struct via_spec *spec = codec->spec;
324 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
328 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
329 struct snd_ctl_elem_value *ucontrol)
331 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332 struct via_spec *spec = codec->spec;
333 unsigned int val = !ucontrol->value.enumerated.item[0];
335 if (val == spec->no_pin_power_ctl)
337 spec->no_pin_power_ctl = val;
338 set_widgets_power_state(codec);
339 analog_low_current_mode(codec);
343 static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
345 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
346 .name = "Dynamic Power-Control",
347 .info = via_pin_power_ctl_info,
348 .get = via_pin_power_ctl_get,
349 .put = via_pin_power_ctl_put,
355 /* check AA path's mute status */
356 static bool is_aa_path_mute(struct hda_codec *codec)
358 struct via_spec *spec = codec->spec;
359 const struct hda_amp_list *p;
362 for (i = 0; i < spec->gen.num_loopbacks; i++) {
363 p = &spec->gen.loopback_list[i];
364 for (ch = 0; ch < 2; ch++) {
365 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
367 if (!(v & HDA_AMP_MUTE) && v > 0)
374 /* enter/exit analog low-current mode */
375 static void __analog_low_current_mode(struct hda_codec *codec, bool force)
377 struct via_spec *spec = codec->spec;
379 unsigned int verb, parm;
381 if (spec->no_pin_power_ctl)
384 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
385 if (enable == spec->alc_mode && !force)
387 spec->alc_mode = enable;
389 /* decide low current mode's verb & parameter */
390 switch (spec->codec_type) {
394 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
400 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
404 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
410 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
415 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
418 return; /* other codecs are not supported */
421 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
424 static void analog_low_current_mode(struct hda_codec *codec)
426 return __analog_low_current_mode(codec, false);
429 static int via_build_controls(struct hda_codec *codec)
431 struct via_spec *spec = codec->spec;
434 err = snd_hda_gen_build_controls(codec);
438 if (spec->set_widgets_power_state)
439 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
441 for (i = 0; i < spec->num_mixers; i++) {
442 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
450 static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
451 struct hda_codec *codec,
452 struct snd_pcm_substream *substream,
455 analog_low_current_mode(codec);
456 vt1708_update_hp_work(codec);
459 static void via_free(struct hda_codec *codec)
461 struct via_spec *spec = codec->spec;
466 vt1708_stop_hp_work(codec);
467 snd_hda_gen_spec_free(&spec->gen);
472 static int via_suspend(struct hda_codec *codec)
474 struct via_spec *spec = codec->spec;
475 vt1708_stop_hp_work(codec);
477 if (spec->codec_type == VT1802) {
478 /* Fix pop noise on headphones */
480 for (i = 0; i < spec->gen.autocfg.hp_outs; i++)
481 snd_hda_set_pin_ctl(codec, spec->gen.autocfg.hp_pins[i], 0);
489 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
491 struct via_spec *spec = codec->spec;
492 set_widgets_power_state(codec);
493 analog_low_current_mode(codec);
494 vt1708_update_hp_work(codec);
495 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
502 static int via_init(struct hda_codec *codec);
504 static const struct hda_codec_ops via_patch_ops = {
505 .build_controls = via_build_controls,
506 .build_pcms = snd_hda_gen_build_pcms,
509 .unsol_event = snd_hda_jack_unsol_event,
511 .suspend = via_suspend,
512 .check_power_status = via_check_power_status,
517 static const struct hda_verb vt1708_init_verbs[] = {
518 /* power down jack detect function */
522 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
524 unsigned int def_conf;
525 unsigned char seqassoc;
527 def_conf = snd_hda_codec_get_pincfg(codec, nid);
528 seqassoc = (unsigned char) get_defcfg_association(def_conf);
529 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
530 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
531 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
532 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
533 snd_hda_codec_set_pincfg(codec, nid, def_conf);
539 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
540 struct snd_ctl_elem_value *ucontrol)
542 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
543 struct via_spec *spec = codec->spec;
545 if (spec->codec_type != VT1708)
547 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
551 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_value *ucontrol)
554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
555 struct via_spec *spec = codec->spec;
558 if (spec->codec_type != VT1708)
560 val = !!ucontrol->value.integer.value[0];
561 if (spec->vt1708_jack_detect == val)
563 spec->vt1708_jack_detect = val;
564 vt1708_update_hp_work(codec);
568 static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
570 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
571 .name = "Jack Detect",
573 .info = snd_ctl_boolean_mono_info,
574 .get = vt1708_jack_detect_get,
575 .put = vt1708_jack_detect_put,
580 static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
582 set_widgets_power_state(codec);
583 snd_hda_gen_hp_automute(codec, tbl);
586 static void via_line_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl)
588 set_widgets_power_state(codec);
589 snd_hda_gen_line_automute(codec, tbl);
592 static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
594 set_widgets_power_state(codec);
597 #define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1)
599 static void via_set_jack_unsol_events(struct hda_codec *codec)
601 struct via_spec *spec = codec->spec;
602 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
606 spec->gen.hp_automute_hook = via_hp_automute;
607 if (cfg->speaker_pins[0])
608 spec->gen.line_automute_hook = via_line_automute;
610 for (i = 0; i < cfg->line_outs; i++) {
611 pin = cfg->line_out_pins[i];
612 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
613 is_jack_detectable(codec, pin))
614 snd_hda_jack_detect_enable_callback(codec, pin,
616 via_jack_powerstate_event);
619 for (i = 0; i < cfg->num_inputs; i++) {
620 pin = cfg->line_out_pins[i];
621 if (pin && !snd_hda_jack_tbl_get(codec, pin) &&
622 is_jack_detectable(codec, pin))
623 snd_hda_jack_detect_enable_callback(codec, pin,
625 via_jack_powerstate_event);
629 static int via_parse_auto_config(struct hda_codec *codec)
631 struct via_spec *spec = codec->spec;
634 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
638 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
642 via_set_jack_unsol_events(codec);
646 static int via_init(struct hda_codec *codec)
648 struct via_spec *spec = codec->spec;
651 for (i = 0; i < spec->num_iverbs; i++)
652 snd_hda_sequence_write(codec, spec->init_verbs[i]);
654 /* init power states */
655 set_widgets_power_state(codec);
656 __analog_low_current_mode(codec, true);
658 snd_hda_gen_init(codec);
660 vt1708_update_hp_work(codec);
665 static int vt1708_build_pcms(struct hda_codec *codec)
667 struct via_spec *spec = codec->spec;
670 err = snd_hda_gen_build_pcms(codec);
671 if (err < 0 || codec->vendor_id != 0x11061708)
674 /* We got noisy outputs on the right channel on VT1708 when
675 * 24bit samples are used. Until any workaround is found,
676 * disable the 24bit format, so far.
678 for (i = 0; i < codec->num_pcms; i++) {
679 struct hda_pcm *info = &spec->gen.pcm_rec[i];
680 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
681 info->pcm_type != HDA_PCM_TYPE_AUDIO)
683 info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
684 SNDRV_PCM_FMTBIT_S16_LE;
690 static int patch_vt1708(struct hda_codec *codec)
692 struct via_spec *spec;
695 /* create a codec specific record */
696 spec = via_new_spec(codec);
700 spec->gen.mixer_nid = 0x17;
702 /* set jackpoll_interval while parsing the codec */
703 codec->jackpoll_interval = msecs_to_jiffies(100);
704 spec->vt1708_jack_detect = 1;
706 /* don't support the input jack switching due to lack of unsol event */
707 /* (it may work with polling, though, but it needs testing) */
708 spec->gen.suppress_auto_mic = 1;
710 /* Add HP and CD pin config connect bit re-config action */
711 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
712 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
714 /* automatic parse from the BIOS config */
715 err = via_parse_auto_config(codec);
721 /* add jack detect on/off control */
722 spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
724 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
726 codec->patch_ops = via_patch_ops;
727 codec->patch_ops.build_pcms = vt1708_build_pcms;
729 /* clear jackpoll_interval again; it's set dynamically */
730 codec->jackpoll_interval = 0;
735 static int patch_vt1709(struct hda_codec *codec)
737 struct via_spec *spec;
740 /* create a codec specific record */
741 spec = via_new_spec(codec);
745 spec->gen.mixer_nid = 0x18;
747 err = via_parse_auto_config(codec);
753 codec->patch_ops = via_patch_ops;
758 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
760 struct via_spec *spec = codec->spec;
764 if ((spec->codec_type != VT1708B_4CH) &&
765 (codec->vendor_id != 0x11064397))
768 /* SW0 (17h) = stereo mixer */
770 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
771 == ((spec->codec_type == VT1708S) ? 5 : 0));
773 /* PW 1/2/5 (1ah/1bh/1eh) */
775 set_pin_power_state(codec, 0x1a, &parm);
776 set_pin_power_state(codec, 0x1b, &parm);
777 set_pin_power_state(codec, 0x1e, &parm);
780 /* SW0 (17h), AIW 0/1 (13h/14h) */
781 update_power_state(codec, 0x17, parm);
782 update_power_state(codec, 0x13, parm);
783 update_power_state(codec, 0x14, parm);
786 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
788 set_pin_power_state(codec, 0x19, &parm);
789 if (smart51_enabled(codec))
790 set_pin_power_state(codec, 0x1b, &parm);
791 update_power_state(codec, 0x18, parm);
792 update_power_state(codec, 0x11, parm);
794 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
797 set_pin_power_state(codec, 0x22, &parm);
798 if (smart51_enabled(codec))
799 set_pin_power_state(codec, 0x1a, &parm);
800 update_power_state(codec, 0x26, parm);
801 update_power_state(codec, 0x24, parm);
802 } else if (codec->vendor_id == 0x11064397) {
803 /* PW7(23h), SW2(27h), AOW2(25h) */
805 set_pin_power_state(codec, 0x23, &parm);
806 if (smart51_enabled(codec))
807 set_pin_power_state(codec, 0x1a, &parm);
808 update_power_state(codec, 0x27, parm);
809 update_power_state(codec, 0x25, parm);
812 /* PW 3/4/7 (1ch/1dh/23h) */
814 /* force to D0 for internal Speaker */
815 set_pin_power_state(codec, 0x1c, &parm);
816 set_pin_power_state(codec, 0x1d, &parm);
818 set_pin_power_state(codec, 0x23, &parm);
820 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
821 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
822 update_power_state(codec, 0x10, parm);
824 update_power_state(codec, 0x25, parm);
825 update_power_state(codec, 0x27, parm);
826 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
827 update_power_state(codec, 0x25, parm);
830 static int patch_vt1708S(struct hda_codec *codec);
831 static int patch_vt1708B(struct hda_codec *codec)
833 struct via_spec *spec;
836 if (get_codec_type(codec) == VT1708BCE)
837 return patch_vt1708S(codec);
839 /* create a codec specific record */
840 spec = via_new_spec(codec);
844 spec->gen.mixer_nid = 0x16;
846 /* automatic parse from the BIOS config */
847 err = via_parse_auto_config(codec);
853 codec->patch_ops = via_patch_ops;
855 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
860 /* Patch for VT1708S */
861 static const struct hda_verb vt1708S_init_verbs[] = {
862 /* Enable Mic Boost Volume backdoor */
864 /* don't bybass mixer */
869 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
870 int offset, int num_steps, int step_size)
872 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
873 (offset << AC_AMPCAP_OFFSET_SHIFT) |
874 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
875 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
876 (0 << AC_AMPCAP_MUTE_SHIFT));
879 static int patch_vt1708S(struct hda_codec *codec)
881 struct via_spec *spec;
884 /* create a codec specific record */
885 spec = via_new_spec(codec);
889 spec->gen.mixer_nid = 0x16;
890 override_mic_boost(codec, 0x1a, 0, 3, 40);
891 override_mic_boost(codec, 0x1e, 0, 3, 40);
893 /* correct names for VT1708BCE */
894 if (get_codec_type(codec) == VT1708BCE) {
895 kfree(codec->chip_name);
896 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
897 snprintf(codec->bus->card->mixername,
898 sizeof(codec->bus->card->mixername),
899 "%s %s", codec->vendor_name, codec->chip_name);
901 /* correct names for VT1705 */
902 if (codec->vendor_id == 0x11064397) {
903 kfree(codec->chip_name);
904 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
905 snprintf(codec->bus->card->mixername,
906 sizeof(codec->bus->card->mixername),
907 "%s %s", codec->vendor_name, codec->chip_name);
910 /* automatic parse from the BIOS config */
911 err = via_parse_auto_config(codec);
917 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
919 codec->patch_ops = via_patch_ops;
921 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
925 /* Patch for VT1702 */
927 static const struct hda_verb vt1702_init_verbs[] = {
935 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
938 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
941 /* PW 1/2/5 (14h/15h/18h) */
943 set_pin_power_state(codec, 0x14, &parm);
944 set_pin_power_state(codec, 0x15, &parm);
945 set_pin_power_state(codec, 0x18, &parm);
947 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
948 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
949 update_power_state(codec, 0x13, parm);
950 update_power_state(codec, 0x12, parm);
951 update_power_state(codec, 0x1f, parm);
952 update_power_state(codec, 0x20, parm);
955 /* PW 3/4 (16h/17h) */
957 set_pin_power_state(codec, 0x17, &parm);
958 set_pin_power_state(codec, 0x16, &parm);
959 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
960 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
961 update_power_state(codec, 0x10, parm);
962 update_power_state(codec, 0x1d, parm);
965 static int patch_vt1702(struct hda_codec *codec)
967 struct via_spec *spec;
970 /* create a codec specific record */
971 spec = via_new_spec(codec);
975 spec->gen.mixer_nid = 0x1a;
977 /* limit AA path volume to 0 dB */
978 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
979 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
980 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
981 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
982 (1 << AC_AMPCAP_MUTE_SHIFT));
984 /* automatic parse from the BIOS config */
985 err = via_parse_auto_config(codec);
991 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
993 codec->patch_ops = via_patch_ops;
995 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
999 /* Patch for VT1718S */
1001 static const struct hda_verb vt1718S_init_verbs[] = {
1002 /* Enable MW0 adjust Gain 5 */
1004 /* Enable Boost Volume backdoor */
1010 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1012 struct via_spec *spec = codec->spec;
1014 unsigned int parm, parm2;
1015 /* MUX6 (1eh) = stereo mixer */
1017 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1019 /* PW 5/6/7 (29h/2ah/2bh) */
1021 set_pin_power_state(codec, 0x29, &parm);
1022 set_pin_power_state(codec, 0x2a, &parm);
1023 set_pin_power_state(codec, 0x2b, &parm);
1026 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1027 update_power_state(codec, 0x1e, parm);
1028 update_power_state(codec, 0x1f, parm);
1029 update_power_state(codec, 0x10, parm);
1030 update_power_state(codec, 0x11, parm);
1033 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1035 set_pin_power_state(codec, 0x27, &parm);
1036 update_power_state(codec, 0x1a, parm);
1037 parm2 = parm; /* for pin 0x0b */
1039 /* PW2 (26h), AOW2 (ah) */
1041 set_pin_power_state(codec, 0x26, &parm);
1042 if (smart51_enabled(codec))
1043 set_pin_power_state(codec, 0x2b, &parm);
1044 update_power_state(codec, 0xa, parm);
1046 /* PW0 (24h), AOW0 (8h) */
1048 set_pin_power_state(codec, 0x24, &parm);
1049 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
1050 set_pin_power_state(codec, 0x28, &parm);
1051 update_power_state(codec, 0x8, parm);
1052 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1054 update_power_state(codec, 0xb, parm);
1055 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1056 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
1058 /* PW1 (25h), AOW1 (9h) */
1060 set_pin_power_state(codec, 0x25, &parm);
1061 if (smart51_enabled(codec))
1062 set_pin_power_state(codec, 0x2a, &parm);
1063 update_power_state(codec, 0x9, parm);
1065 if (spec->gen.indep_hp_enabled) {
1066 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1068 set_pin_power_state(codec, 0x28, &parm);
1069 update_power_state(codec, 0x1b, parm);
1070 update_power_state(codec, 0x34, parm);
1071 update_power_state(codec, 0xc, parm);
1075 /* Add a connection to the primary DAC from AA-mixer for some codecs
1076 * This isn't listed from the raw info, but the chip has a secret connection.
1078 static int add_secret_dac_path(struct hda_codec *codec)
1080 struct via_spec *spec = codec->spec;
1085 if (!spec->gen.mixer_nid)
1087 nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
1088 ARRAY_SIZE(conn) - 1);
1089 for (i = 0; i < nums; i++) {
1090 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
1094 /* find the primary DAC and add to the connection list */
1095 nid = codec->start_nid;
1096 for (i = 0; i < codec->num_nodes; i++, nid++) {
1097 unsigned int caps = get_wcaps(codec, nid);
1098 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
1099 !(caps & AC_WCAP_DIGITAL)) {
1101 return snd_hda_override_conn_list(codec,
1102 spec->gen.mixer_nid,
1110 static int patch_vt1718S(struct hda_codec *codec)
1112 struct via_spec *spec;
1115 /* create a codec specific record */
1116 spec = via_new_spec(codec);
1120 spec->gen.mixer_nid = 0x21;
1121 override_mic_boost(codec, 0x2b, 0, 3, 40);
1122 override_mic_boost(codec, 0x29, 0, 3, 40);
1123 add_secret_dac_path(codec);
1125 /* automatic parse from the BIOS config */
1126 err = via_parse_auto_config(codec);
1132 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
1134 codec->patch_ops = via_patch_ops;
1136 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
1141 /* Patch for VT1716S */
1143 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
1144 struct snd_ctl_elem_info *uinfo)
1146 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1148 uinfo->value.integer.min = 0;
1149 uinfo->value.integer.max = 1;
1153 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
1154 struct snd_ctl_elem_value *ucontrol)
1156 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1159 index = snd_hda_codec_read(codec, 0x26, 0,
1160 AC_VERB_GET_CONNECT_SEL, 0);
1162 *ucontrol->value.integer.value = index;
1167 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1168 struct snd_ctl_elem_value *ucontrol)
1170 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1171 struct via_spec *spec = codec->spec;
1172 int index = *ucontrol->value.integer.value;
1174 snd_hda_codec_write(codec, 0x26, 0,
1175 AC_VERB_SET_CONNECT_SEL, index);
1176 spec->dmic_enabled = index;
1177 set_widgets_power_state(codec);
1181 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
1182 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
1184 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1185 .name = "Digital Mic Capture Switch",
1186 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
1188 .info = vt1716s_dmic_info,
1189 .get = vt1716s_dmic_get,
1190 .put = vt1716s_dmic_put,
1196 /* mono-out mixer elements */
1197 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
1198 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
1202 static const struct hda_verb vt1716S_init_verbs[] = {
1203 /* Enable Boost Volume backdoor */
1205 /* don't bybass mixer */
1207 /* Enable mono output */
1212 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1214 struct via_spec *spec = codec->spec;
1217 unsigned int mono_out, present;
1218 /* SW0 (17h) = stereo mixer */
1220 (snd_hda_codec_read(codec, 0x17, 0,
1221 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
1223 /* PW 1/2/5 (1ah/1bh/1eh) */
1225 set_pin_power_state(codec, 0x1a, &parm);
1226 set_pin_power_state(codec, 0x1b, &parm);
1227 set_pin_power_state(codec, 0x1e, &parm);
1230 /* SW0 (17h), AIW0(13h) */
1231 update_power_state(codec, 0x17, parm);
1232 update_power_state(codec, 0x13, parm);
1235 set_pin_power_state(codec, 0x1e, &parm);
1237 if (spec->dmic_enabled)
1238 set_pin_power_state(codec, 0x22, &parm);
1240 update_power_state(codec, 0x22, AC_PWRST_D3);
1242 /* SW2(26h), AIW1(14h) */
1243 update_power_state(codec, 0x26, parm);
1244 update_power_state(codec, 0x14, parm);
1247 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1249 set_pin_power_state(codec, 0x19, &parm);
1250 /* Smart 5.1 PW2(1bh) */
1251 if (smart51_enabled(codec))
1252 set_pin_power_state(codec, 0x1b, &parm);
1253 update_power_state(codec, 0x18, parm);
1254 update_power_state(codec, 0x11, parm);
1256 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1258 set_pin_power_state(codec, 0x23, &parm);
1259 /* Smart 5.1 PW1(1ah) */
1260 if (smart51_enabled(codec))
1261 set_pin_power_state(codec, 0x1a, &parm);
1262 update_power_state(codec, 0x27, parm);
1264 /* Smart 5.1 PW5(1eh) */
1265 if (smart51_enabled(codec))
1266 set_pin_power_state(codec, 0x1e, &parm);
1267 update_power_state(codec, 0x25, parm);
1270 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1271 present = snd_hda_jack_detect(codec, 0x1c);
1276 present = snd_hda_jack_detect(codec, 0x1d);
1277 if (!spec->gen.indep_hp_enabled && present)
1282 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
1283 update_power_state(codec, 0x28, parm);
1284 update_power_state(codec, 0x29, parm);
1285 update_power_state(codec, 0x2a, parm);
1287 /* PW 3/4 (1ch/1dh) */
1289 set_pin_power_state(codec, 0x1c, &parm);
1290 set_pin_power_state(codec, 0x1d, &parm);
1291 /* HP Independent Mode, power on AOW3 */
1292 if (spec->gen.indep_hp_enabled)
1293 update_power_state(codec, 0x25, parm);
1295 /* force to D0 for internal Speaker */
1296 /* MW0 (16h), AOW0 (10h) */
1297 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1298 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
1301 static int patch_vt1716S(struct hda_codec *codec)
1303 struct via_spec *spec;
1306 /* create a codec specific record */
1307 spec = via_new_spec(codec);
1311 spec->gen.mixer_nid = 0x16;
1312 override_mic_boost(codec, 0x1a, 0, 3, 40);
1313 override_mic_boost(codec, 0x1e, 0, 3, 40);
1315 /* automatic parse from the BIOS config */
1316 err = via_parse_auto_config(codec);
1322 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
1324 spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
1325 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1327 codec->patch_ops = via_patch_ops;
1329 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
1335 static const struct hda_verb vt2002P_init_verbs[] = {
1336 /* Class-D speaker related verbs */
1340 /* Enable Boost Volume backdoor */
1342 /* Enable AOW0 to MW9 */
1347 static const struct hda_verb vt1802_init_verbs[] = {
1348 /* Enable Boost Volume backdoor */
1350 /* Enable AOW0 to MW9 */
1355 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1357 struct via_spec *spec = codec->spec;
1360 unsigned int present;
1361 /* MUX9 (1eh) = stereo mixer */
1363 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1365 /* PW 5/6/7 (29h/2ah/2bh) */
1367 set_pin_power_state(codec, 0x29, &parm);
1368 set_pin_power_state(codec, 0x2a, &parm);
1369 set_pin_power_state(codec, 0x2b, &parm);
1371 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1372 update_power_state(codec, 0x1e, parm);
1373 update_power_state(codec, 0x1f, parm);
1374 update_power_state(codec, 0x10, parm);
1375 update_power_state(codec, 0x11, parm);
1379 update_power_state(codec, 0x8, parm);
1381 if (spec->codec_type == VT1802) {
1382 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1384 set_pin_power_state(codec, 0x28, &parm);
1385 update_power_state(codec, 0x18, parm);
1386 update_power_state(codec, 0x38, parm);
1388 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1390 set_pin_power_state(codec, 0x26, &parm);
1391 update_power_state(codec, 0x1c, parm);
1392 update_power_state(codec, 0x37, parm);
1395 if (spec->codec_type == VT1802) {
1396 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1398 set_pin_power_state(codec, 0x25, &parm);
1399 update_power_state(codec, 0x15, parm);
1400 update_power_state(codec, 0x35, parm);
1402 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1404 set_pin_power_state(codec, 0x25, &parm);
1405 update_power_state(codec, 0x19, parm);
1406 update_power_state(codec, 0x35, parm);
1409 if (spec->gen.indep_hp_enabled)
1410 update_power_state(codec, 0x9, AC_PWRST_D0);
1413 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1414 present = snd_hda_jack_detect(codec, 0x25);
1417 set_pin_power_state(codec, 0x24, &parm);
1418 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1419 if (spec->codec_type == VT1802)
1420 update_power_state(codec, 0x14, parm);
1422 update_power_state(codec, 0x18, parm);
1423 update_power_state(codec, 0x34, parm);
1426 present = snd_hda_jack_detect(codec, 0x26);
1428 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1429 if (spec->codec_type == VT1802) {
1430 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
1431 update_power_state(codec, 0x33, parm);
1432 update_power_state(codec, 0x1c, parm);
1433 update_power_state(codec, 0x3c, parm);
1435 /* PW15 (31h), MW8(17h), MUX8(3bh) */
1436 update_power_state(codec, 0x31, parm);
1437 update_power_state(codec, 0x17, parm);
1438 update_power_state(codec, 0x3b, parm);
1441 if (imux_is_smixer || !is_aa_path_mute(codec))
1442 update_power_state(codec, 0x21, AC_PWRST_D0);
1444 update_power_state(codec, 0x21, AC_PWRST_D3);
1451 VIA_FIXUP_INTMIC_BOOST,
1455 static void via_fixup_intmic_boost(struct hda_codec *codec,
1456 const struct hda_fixup *fix, int action)
1458 if (action == HDA_FIXUP_ACT_PRE_PROBE)
1459 override_mic_boost(codec, 0x30, 0, 2, 40);
1462 static const struct hda_fixup via_fixups[] = {
1463 [VIA_FIXUP_INTMIC_BOOST] = {
1464 .type = HDA_FIXUP_FUNC,
1465 .v.func = via_fixup_intmic_boost,
1467 [VIA_FIXUP_ASUS_G75] = {
1468 .type = HDA_FIXUP_PINS,
1469 .v.pins = (const struct hda_pintbl[]) {
1470 /* set 0x24 and 0x33 as speakers */
1471 { 0x24, 0x991301f0 },
1472 { 0x33, 0x991301f1 }, /* subwoofer */
1478 static const struct snd_pci_quirk vt2002p_fixups[] = {
1479 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
1480 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
1484 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
1485 * Replace this with mixer NID 0x1c
1487 static void fix_vt1802_connections(struct hda_codec *codec)
1489 static hda_nid_t conn_24[] = { 0x14, 0x1c };
1490 static hda_nid_t conn_33[] = { 0x1c };
1492 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
1493 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
1496 /* patch for vt2002P */
1497 static int patch_vt2002P(struct hda_codec *codec)
1499 struct via_spec *spec;
1502 /* create a codec specific record */
1503 spec = via_new_spec(codec);
1507 spec->gen.mixer_nid = 0x21;
1508 override_mic_boost(codec, 0x2b, 0, 3, 40);
1509 override_mic_boost(codec, 0x29, 0, 3, 40);
1510 if (spec->codec_type == VT1802)
1511 fix_vt1802_connections(codec);
1512 add_secret_dac_path(codec);
1514 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
1515 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1517 /* automatic parse from the BIOS config */
1518 err = via_parse_auto_config(codec);
1524 if (spec->codec_type == VT1802)
1525 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
1527 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
1529 codec->patch_ops = via_patch_ops;
1531 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
1537 static const struct hda_verb vt1812_init_verbs[] = {
1538 /* Enable Boost Volume backdoor */
1540 /* Enable AOW0 to MW9 */
1545 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1547 struct via_spec *spec = codec->spec;
1549 unsigned int present;
1551 /* PW 5/6/7 (29h/2ah/2bh) */
1553 set_pin_power_state(codec, 0x29, &parm);
1554 set_pin_power_state(codec, 0x2a, &parm);
1555 set_pin_power_state(codec, 0x2b, &parm);
1557 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1558 update_power_state(codec, 0x1e, parm);
1559 update_power_state(codec, 0x1f, parm);
1560 update_power_state(codec, 0x10, parm);
1561 update_power_state(codec, 0x11, parm);
1565 update_power_state(codec, 0x8, AC_PWRST_D0);
1567 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1569 set_pin_power_state(codec, 0x28, &parm);
1570 update_power_state(codec, 0x18, parm);
1571 update_power_state(codec, 0x38, parm);
1573 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1575 set_pin_power_state(codec, 0x25, &parm);
1576 update_power_state(codec, 0x15, parm);
1577 update_power_state(codec, 0x35, parm);
1578 if (spec->gen.indep_hp_enabled)
1579 update_power_state(codec, 0x9, AC_PWRST_D0);
1581 /* Internal Speaker */
1582 /* PW0 (24h), MW0(14h), MUX0(34h) */
1583 present = snd_hda_jack_detect(codec, 0x25);
1586 set_pin_power_state(codec, 0x24, &parm);
1588 update_power_state(codec, 0x14, AC_PWRST_D3);
1589 update_power_state(codec, 0x34, AC_PWRST_D3);
1591 update_power_state(codec, 0x14, AC_PWRST_D0);
1592 update_power_state(codec, 0x34, AC_PWRST_D0);
1597 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1598 present = snd_hda_jack_detect(codec, 0x28);
1601 set_pin_power_state(codec, 0x31, &parm);
1603 update_power_state(codec, 0x1c, AC_PWRST_D3);
1604 update_power_state(codec, 0x3c, AC_PWRST_D3);
1605 update_power_state(codec, 0x3e, AC_PWRST_D3);
1607 update_power_state(codec, 0x1c, AC_PWRST_D0);
1608 update_power_state(codec, 0x3c, AC_PWRST_D0);
1609 update_power_state(codec, 0x3e, AC_PWRST_D0);
1612 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1614 set_pin_power_state(codec, 0x33, &parm);
1615 update_power_state(codec, 0x1d, parm);
1616 update_power_state(codec, 0x3d, parm);
1620 /* patch for vt1812 */
1621 static int patch_vt1812(struct hda_codec *codec)
1623 struct via_spec *spec;
1626 /* create a codec specific record */
1627 spec = via_new_spec(codec);
1631 spec->gen.mixer_nid = 0x21;
1632 override_mic_boost(codec, 0x2b, 0, 3, 40);
1633 override_mic_boost(codec, 0x29, 0, 3, 40);
1634 add_secret_dac_path(codec);
1636 /* automatic parse from the BIOS config */
1637 err = via_parse_auto_config(codec);
1643 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
1645 codec->patch_ops = via_patch_ops;
1647 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
1651 /* patch for vt3476 */
1653 static const struct hda_verb vt3476_init_verbs[] = {
1654 /* Enable DMic 8/16/32K */
1656 /* Enable Boost Volume backdoor */
1658 /* Enable AOW-MW9 path */
1663 static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1665 struct via_spec *spec = codec->spec;
1667 unsigned int parm, parm2;
1668 /* MUX10 (1eh) = stereo mixer */
1670 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1672 /* PW 5/6/7 (29h/2ah/2bh) */
1674 set_pin_power_state(codec, 0x29, &parm);
1675 set_pin_power_state(codec, 0x2a, &parm);
1676 set_pin_power_state(codec, 0x2b, &parm);
1679 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1680 update_power_state(codec, 0x1e, parm);
1681 update_power_state(codec, 0x1f, parm);
1682 update_power_state(codec, 0x10, parm);
1683 update_power_state(codec, 0x11, parm);
1686 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1687 if (spec->codec_type == VT1705CF) {
1689 update_power_state(codec, 0x27, parm);
1690 update_power_state(codec, 0x37, parm);
1693 set_pin_power_state(codec, 0x27, &parm);
1694 update_power_state(codec, 0x37, parm);
1697 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1699 set_pin_power_state(codec, 0x26, &parm);
1700 update_power_state(codec, 0x36, parm);
1701 if (smart51_enabled(codec)) {
1702 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1703 set_pin_power_state(codec, 0x2b, &parm);
1704 update_power_state(codec, 0x3b, parm);
1705 update_power_state(codec, 0x1b, parm);
1707 update_conv_power_state(codec, 0xa, parm, 2);
1709 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1711 set_pin_power_state(codec, 0x25, &parm);
1712 update_power_state(codec, 0x35, parm);
1713 if (smart51_enabled(codec)) {
1714 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1715 set_pin_power_state(codec, 0x2a, &parm);
1716 update_power_state(codec, 0x3a, parm);
1717 update_power_state(codec, 0x1a, parm);
1719 update_conv_power_state(codec, 0x9, parm, 1);
1721 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1723 set_pin_power_state(codec, 0x28, &parm);
1724 update_power_state(codec, 0x38, parm);
1725 update_power_state(codec, 0x18, parm);
1726 if (spec->gen.indep_hp_enabled)
1727 update_conv_power_state(codec, 0xb, parm, 3);
1728 parm2 = parm; /* for pin 0x0b */
1730 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1732 set_pin_power_state(codec, 0x24, &parm);
1733 update_power_state(codec, 0x34, parm);
1734 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1736 update_conv_power_state(codec, 0x8, parm, 0);
1737 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1738 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1741 static int patch_vt3476(struct hda_codec *codec)
1743 struct via_spec *spec;
1746 /* create a codec specific record */
1747 spec = via_new_spec(codec);
1751 spec->gen.mixer_nid = 0x3f;
1752 add_secret_dac_path(codec);
1754 /* automatic parse from the BIOS config */
1755 err = via_parse_auto_config(codec);
1761 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1763 codec->patch_ops = via_patch_ops;
1765 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1773 static const struct hda_codec_preset snd_hda_preset_via[] = {
1774 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
1775 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
1776 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
1777 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
1778 { .id = 0x1106e710, .name = "VT1709 10-Ch",
1779 .patch = patch_vt1709},
1780 { .id = 0x1106e711, .name = "VT1709 10-Ch",
1781 .patch = patch_vt1709},
1782 { .id = 0x1106e712, .name = "VT1709 10-Ch",
1783 .patch = patch_vt1709},
1784 { .id = 0x1106e713, .name = "VT1709 10-Ch",
1785 .patch = patch_vt1709},
1786 { .id = 0x1106e714, .name = "VT1709 6-Ch",
1787 .patch = patch_vt1709},
1788 { .id = 0x1106e715, .name = "VT1709 6-Ch",
1789 .patch = patch_vt1709},
1790 { .id = 0x1106e716, .name = "VT1709 6-Ch",
1791 .patch = patch_vt1709},
1792 { .id = 0x1106e717, .name = "VT1709 6-Ch",
1793 .patch = patch_vt1709},
1794 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
1795 .patch = patch_vt1708B},
1796 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
1797 .patch = patch_vt1708B},
1798 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
1799 .patch = patch_vt1708B},
1800 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
1801 .patch = patch_vt1708B},
1802 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
1803 .patch = patch_vt1708B},
1804 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
1805 .patch = patch_vt1708B},
1806 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
1807 .patch = patch_vt1708B},
1808 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
1809 .patch = patch_vt1708B},
1810 { .id = 0x11060397, .name = "VT1708S",
1811 .patch = patch_vt1708S},
1812 { .id = 0x11061397, .name = "VT1708S",
1813 .patch = patch_vt1708S},
1814 { .id = 0x11062397, .name = "VT1708S",
1815 .patch = patch_vt1708S},
1816 { .id = 0x11063397, .name = "VT1708S",
1817 .patch = patch_vt1708S},
1818 { .id = 0x11064397, .name = "VT1705",
1819 .patch = patch_vt1708S},
1820 { .id = 0x11065397, .name = "VT1708S",
1821 .patch = patch_vt1708S},
1822 { .id = 0x11066397, .name = "VT1708S",
1823 .patch = patch_vt1708S},
1824 { .id = 0x11067397, .name = "VT1708S",
1825 .patch = patch_vt1708S},
1826 { .id = 0x11060398, .name = "VT1702",
1827 .patch = patch_vt1702},
1828 { .id = 0x11061398, .name = "VT1702",
1829 .patch = patch_vt1702},
1830 { .id = 0x11062398, .name = "VT1702",
1831 .patch = patch_vt1702},
1832 { .id = 0x11063398, .name = "VT1702",
1833 .patch = patch_vt1702},
1834 { .id = 0x11064398, .name = "VT1702",
1835 .patch = patch_vt1702},
1836 { .id = 0x11065398, .name = "VT1702",
1837 .patch = patch_vt1702},
1838 { .id = 0x11066398, .name = "VT1702",
1839 .patch = patch_vt1702},
1840 { .id = 0x11067398, .name = "VT1702",
1841 .patch = patch_vt1702},
1842 { .id = 0x11060428, .name = "VT1718S",
1843 .patch = patch_vt1718S},
1844 { .id = 0x11064428, .name = "VT1718S",
1845 .patch = patch_vt1718S},
1846 { .id = 0x11060441, .name = "VT2020",
1847 .patch = patch_vt1718S},
1848 { .id = 0x11064441, .name = "VT1828S",
1849 .patch = patch_vt1718S},
1850 { .id = 0x11060433, .name = "VT1716S",
1851 .patch = patch_vt1716S},
1852 { .id = 0x1106a721, .name = "VT1716S",
1853 .patch = patch_vt1716S},
1854 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
1855 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
1856 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
1857 { .id = 0x11060440, .name = "VT1818S",
1858 .patch = patch_vt1708S},
1859 { .id = 0x11060446, .name = "VT1802",
1860 .patch = patch_vt2002P},
1861 { .id = 0x11068446, .name = "VT1802",
1862 .patch = patch_vt2002P},
1863 { .id = 0x11064760, .name = "VT1705CF",
1864 .patch = patch_vt3476},
1865 { .id = 0x11064761, .name = "VT1708SCE",
1866 .patch = patch_vt3476},
1867 { .id = 0x11064762, .name = "VT1808",
1868 .patch = patch_vt3476},
1872 MODULE_ALIAS("snd-hda-codec-id:1106*");
1874 static struct hda_codec_preset_list via_list = {
1875 .preset = snd_hda_preset_via,
1876 .owner = THIS_MODULE,
1879 MODULE_LICENSE("GPL");
1880 MODULE_DESCRIPTION("VIA HD-audio codec");
1882 static int __init patch_via_init(void)
1884 return snd_hda_add_codec_preset(&via_list);
1887 static void __exit patch_via_exit(void)
1889 snd_hda_delete_codec_preset(&via_list);
1892 module_init(patch_via_init)
1893 module_exit(patch_via_exit)