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 <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
57 #define NID_MAPPING (-1)
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
64 #define VT1708_HP_NID 0x13
65 #define VT1708_DIGOUT_NID 0x14
66 #define VT1708_DIGIN_NID 0x16
67 #define VT1708_DIGIN_PIN 0x26
68 #define VT1708_HP_PIN_NID 0x20
69 #define VT1708_CD_PIN_NID 0x24
71 #define VT1709_HP_DAC_NID 0x28
72 #define VT1709_DIGOUT_NID 0x13
73 #define VT1709_DIGIN_NID 0x17
74 #define VT1709_DIGIN_PIN 0x25
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
105 #define VT2002P_COMPATIBLE(spec) \
106 ((spec)->codec_type == VT2002P ||\
107 (spec)->codec_type == VT1812 ||\
108 (spec)->codec_type == VT1802)
117 /* codec parameterization */
118 const struct snd_kcontrol_new *mixers[6];
119 unsigned int num_mixers;
121 const struct hda_verb *init_verbs[5];
122 unsigned int num_iverbs;
124 char stream_name_analog[32];
125 char stream_name_hp[32];
126 const struct hda_pcm_stream *stream_analog_playback;
127 const struct hda_pcm_stream *stream_analog_capture;
129 char stream_name_digital[32];
130 const struct hda_pcm_stream *stream_digital_playback;
131 const struct hda_pcm_stream *stream_digital_capture;
134 struct hda_multi_out multiout;
135 hda_nid_t slave_dig_outs[2];
137 struct nid_path out_path[4];
138 struct nid_path hp_path;
139 struct nid_path hp_dep_path;
142 unsigned int num_adc_nids;
143 hda_nid_t adc_nids[3];
144 hda_nid_t mux_nids[3];
145 hda_nid_t aa_mix_nid;
146 hda_nid_t dig_in_nid;
147 hda_nid_t dig_in_pin;
150 const struct hda_input_mux *input_mux;
151 unsigned int cur_mux[3];
153 /* PCM information */
154 struct hda_pcm pcm_rec[3];
156 /* dynamic controls, init_verbs and input_mux */
157 struct auto_pin_cfg autocfg;
158 struct snd_array kctls;
159 struct hda_input_mux private_imux[2];
160 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
163 const struct hda_input_mux *hp_mux;
164 unsigned int hp_independent_mode;
165 unsigned int hp_independent_mode_index;
166 unsigned int can_smart51;
167 unsigned int smart51_enabled;
168 unsigned int dmic_enabled;
169 unsigned int no_pin_power_ctl;
170 enum VIA_HDA_CODEC codec_type;
172 /* work to check hp jack state */
173 struct hda_codec *codec;
174 struct delayed_work vt1708_hp_work;
175 int vt1708_jack_detect;
176 int vt1708_hp_present;
178 void (*set_widgets_power_state)(struct hda_codec *codec);
180 #ifdef CONFIG_SND_HDA_POWER_SAVE
181 struct hda_loopback_check loopback;
185 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
186 static struct via_spec * via_new_spec(struct hda_codec *codec)
188 struct via_spec *spec;
190 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
196 spec->codec_type = get_codec_type(codec);
197 /* VT1708BCE & VT1708S are almost same */
198 if (spec->codec_type == VT1708BCE)
199 spec->codec_type = VT1708S;
203 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
205 u32 vendor_id = codec->vendor_id;
206 u16 ven_id = vendor_id >> 16;
207 u16 dev_id = vendor_id & 0xffff;
208 enum VIA_HDA_CODEC codec_type;
211 if (ven_id != 0x1106)
212 codec_type = UNKNOWN;
213 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
215 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
216 codec_type = VT1709_10CH;
217 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
218 codec_type = VT1709_6CH;
219 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
220 codec_type = VT1708B_8CH;
221 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
222 codec_type = VT1708BCE;
223 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
224 codec_type = VT1708B_4CH;
225 else if ((dev_id & 0xfff) == 0x397
226 && (dev_id >> 12) < 8)
227 codec_type = VT1708S;
228 else if ((dev_id & 0xfff) == 0x398
229 && (dev_id >> 12) < 8)
231 else if ((dev_id & 0xfff) == 0x428
232 && (dev_id >> 12) < 8)
233 codec_type = VT1718S;
234 else if (dev_id == 0x0433 || dev_id == 0xa721)
235 codec_type = VT1716S;
236 else if (dev_id == 0x0441 || dev_id == 0x4441)
237 codec_type = VT1718S;
238 else if (dev_id == 0x0438 || dev_id == 0x4438)
239 codec_type = VT2002P;
240 else if (dev_id == 0x0448)
242 else if (dev_id == 0x0440)
243 codec_type = VT1708S;
244 else if ((dev_id & 0xfff) == 0x446)
247 codec_type = UNKNOWN;
251 #define VIA_JACK_EVENT 0x20
252 #define VIA_HP_EVENT 0x01
253 #define VIA_GPIO_EVENT 0x02
254 #define VIA_MONO_EVENT 0x03
255 #define VIA_SPEAKER_EVENT 0x04
256 #define VIA_BIND_HP_EVENT 0x05
261 VIA_CTL_WIDGET_ANALOG_MUTE,
262 VIA_CTL_WIDGET_BIND_PIN_MUTE,
272 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
273 static int is_aa_path_mute(struct hda_codec *codec);
275 static void vt1708_start_hp_work(struct via_spec *spec)
277 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
279 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
280 !spec->vt1708_jack_detect);
281 if (!delayed_work_pending(&spec->vt1708_hp_work))
282 schedule_delayed_work(&spec->vt1708_hp_work,
283 msecs_to_jiffies(100));
286 static void vt1708_stop_hp_work(struct via_spec *spec)
288 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
290 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
291 && !is_aa_path_mute(spec->codec))
293 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
294 !spec->vt1708_jack_detect);
295 cancel_delayed_work_sync(&spec->vt1708_hp_work);
298 static void set_widgets_power_state(struct hda_codec *codec)
300 struct via_spec *spec = codec->spec;
301 if (spec->set_widgets_power_state)
302 spec->set_widgets_power_state(codec);
305 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
306 struct snd_ctl_elem_value *ucontrol)
308 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
309 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
311 set_widgets_power_state(codec);
312 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
313 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
314 if (is_aa_path_mute(codec))
315 vt1708_start_hp_work(codec->spec);
317 vt1708_stop_hp_work(codec->spec);
322 /* modify .put = snd_hda_mixer_amp_switch_put */
323 #define ANALOG_INPUT_MUTE \
324 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
327 .info = snd_hda_mixer_amp_switch_info, \
328 .get = snd_hda_mixer_amp_switch_get, \
329 .put = analog_input_switch_put, \
330 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
332 static void via_hp_bind_automute(struct hda_codec *codec);
334 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
335 struct snd_ctl_elem_value *ucontrol)
337 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
338 struct via_spec *spec = codec->spec;
342 long *valp = ucontrol->value.integer.value;
344 if (strstr(kcontrol->id.name, "Switch") == NULL) {
345 snd_printd("Invalid control!\n");
348 change = snd_hda_mixer_amp_switch_put(kcontrol,
351 lmute = *valp ? 0 : HDA_AMP_MUTE;
353 rmute = *valp ? 0 : HDA_AMP_MUTE;
356 if (!spec->hp_independent_mode) {
357 for (i = 0; i < spec->autocfg.hp_outs; i++) {
358 snd_hda_codec_amp_update(
359 codec, spec->autocfg.hp_pins[i],
360 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
362 snd_hda_codec_amp_update(
363 codec, spec->autocfg.hp_pins[i],
364 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
369 if (!lmute && !rmute) {
371 for (i = 0; i < spec->autocfg.line_outs; i++)
372 snd_hda_codec_amp_stereo(
373 codec, spec->autocfg.line_out_pins[i],
374 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
376 for (i = 0; i < spec->autocfg.speaker_outs; i++)
377 snd_hda_codec_amp_stereo(
378 codec, spec->autocfg.speaker_pins[i],
379 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
381 via_hp_bind_automute(codec);
385 /* Mute all left channels */
386 for (i = 1; i < spec->autocfg.line_outs; i++)
387 snd_hda_codec_amp_update(
389 spec->autocfg.line_out_pins[i],
390 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
392 for (i = 0; i < spec->autocfg.speaker_outs; i++)
393 snd_hda_codec_amp_update(
395 spec->autocfg.speaker_pins[i],
396 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
400 /* mute all right channels */
401 for (i = 1; i < spec->autocfg.line_outs; i++)
402 snd_hda_codec_amp_update(
404 spec->autocfg.line_out_pins[i],
405 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
407 for (i = 0; i < spec->autocfg.speaker_outs; i++)
408 snd_hda_codec_amp_update(
410 spec->autocfg.speaker_pins[i],
411 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
418 #define BIND_PIN_MUTE \
419 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
422 .info = snd_hda_mixer_amp_switch_info, \
423 .get = snd_hda_mixer_amp_switch_get, \
424 .put = bind_pin_switch_put, \
425 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
427 static const struct snd_kcontrol_new via_control_templates[] = {
428 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
429 HDA_CODEC_MUTE(NULL, 0, 0, 0),
435 /* add dynamic controls */
436 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
437 const struct snd_kcontrol_new *tmpl,
440 struct snd_kcontrol_new *knew;
442 snd_array_init(&spec->kctls, sizeof(*knew), 32);
443 knew = snd_array_new(&spec->kctls);
450 knew->name = kstrdup(name, GFP_KERNEL);
457 static int __via_add_control(struct via_spec *spec, int type, const char *name,
458 int idx, unsigned long val)
460 struct snd_kcontrol_new *knew;
462 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
466 if (get_amp_nid_(val))
467 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
468 knew->private_value = val;
472 #define via_add_control(spec, type, name, val) \
473 __via_add_control(spec, type, name, 0, val)
475 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
477 static void via_free_kctls(struct hda_codec *codec)
479 struct via_spec *spec = codec->spec;
481 if (spec->kctls.list) {
482 struct snd_kcontrol_new *kctl = spec->kctls.list;
484 for (i = 0; i < spec->kctls.used; i++)
487 snd_array_free(&spec->kctls);
490 /* create input playback/capture controls for the given pin */
491 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
492 int type_idx, int idx, int mix_nid)
497 sprintf(name, "%s Playback Volume", ctlname);
498 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
499 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
502 sprintf(name, "%s Playback Switch", ctlname);
503 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
504 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
510 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
511 hda_nid_t nid, int pin_type,
515 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
517 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
519 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
520 snd_hda_codec_write(codec, nid, 0,
521 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
525 static void via_auto_init_multi_out(struct hda_codec *codec)
527 struct via_spec *spec = codec->spec;
530 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
531 hda_nid_t nid = spec->autocfg.line_out_pins[i];
533 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
537 static void via_auto_init_hp_out(struct hda_codec *codec)
539 struct via_spec *spec = codec->spec;
543 for (i = 0; i < spec->autocfg.hp_outs; i++) {
544 pin = spec->autocfg.hp_pins[i];
545 if (pin) /* connect to front */
546 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
550 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
552 static void via_auto_init_analog_input(struct hda_codec *codec)
554 struct via_spec *spec = codec->spec;
555 const struct auto_pin_cfg *cfg = &spec->autocfg;
559 for (i = 0; i < cfg->num_inputs; i++) {
560 hda_nid_t nid = cfg->inputs[i].pin;
561 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
563 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
567 snd_hda_codec_write(codec, nid, 0,
568 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
572 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
573 unsigned int *affected_parm)
576 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
577 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
578 >> AC_DEFCFG_MISC_SHIFT
579 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
580 struct via_spec *spec = codec->spec;
581 unsigned present = 0;
583 no_presence |= spec->no_pin_power_ctl;
585 present = snd_hda_jack_detect(codec, nid);
586 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
587 || ((no_presence || present)
588 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
589 *affected_parm = AC_PWRST_D0; /* if it's connected */
594 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
597 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
598 struct snd_ctl_elem_info *uinfo)
600 static const char * const texts[] = {
601 "Disabled", "Enabled"
604 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
606 uinfo->value.enumerated.items = 2;
607 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
608 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
609 strcpy(uinfo->value.enumerated.name,
610 texts[uinfo->value.enumerated.item]);
614 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_value *ucontrol)
617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618 struct via_spec *spec = codec->spec;
619 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
623 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_value *ucontrol)
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 struct via_spec *spec = codec->spec;
628 unsigned int val = !ucontrol->value.enumerated.item[0];
630 if (val == spec->no_pin_power_ctl)
632 spec->no_pin_power_ctl = val;
633 set_widgets_power_state(codec);
637 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
638 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
639 .name = "Dynamic Power-Control",
640 .info = via_pin_power_ctl_info,
641 .get = via_pin_power_ctl_get,
642 .put = via_pin_power_ctl_put,
649 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_info *uinfo)
652 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
653 struct via_spec *spec = codec->spec;
654 return snd_hda_input_mux_info(spec->input_mux, uinfo);
657 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
658 struct snd_ctl_elem_value *ucontrol)
660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661 struct via_spec *spec = codec->spec;
662 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
664 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
668 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
669 struct snd_ctl_elem_value *ucontrol)
671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
672 struct via_spec *spec = codec->spec;
673 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
676 if (!spec->mux_nids[adc_idx])
678 /* switch to D0 beofre change index */
679 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
680 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
681 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
682 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
684 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
685 spec->mux_nids[adc_idx],
686 &spec->cur_mux[adc_idx]);
687 /* update jack power state */
688 set_widgets_power_state(codec);
693 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
694 struct snd_ctl_elem_info *uinfo)
696 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
697 struct via_spec *spec = codec->spec;
698 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
701 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
702 struct snd_ctl_elem_value *ucontrol)
704 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
705 hda_nid_t nid = kcontrol->private_value;
708 /* use !! to translate conn sel 2 for VT1718S */
709 pinsel = !!snd_hda_codec_read(codec, nid, 0,
710 AC_VERB_GET_CONNECT_SEL,
712 ucontrol->value.enumerated.item[0] = pinsel;
717 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
719 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
721 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
722 ctl->vd[0].access |= active
723 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
724 snd_ctl_notify(codec->bus->card,
725 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
729 static hda_nid_t side_mute_channel(struct via_spec *spec)
731 switch (spec->codec_type) {
732 case VT1708: return 0x1b;
733 case VT1709_10CH: return 0x29;
734 case VT1708B_8CH: /* fall thru */
735 case VT1708S: return 0x27;
736 case VT2002P: return 0x19;
737 case VT1802: return 0x15;
738 case VT1812: return 0x15;
743 static int update_side_mute_status(struct hda_codec *codec)
745 /* mute side channel */
746 struct via_spec *spec = codec->spec;
748 hda_nid_t sw3 = side_mute_channel(spec);
751 if (VT2002P_COMPATIBLE(spec))
752 parm = spec->hp_independent_mode ?
753 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
755 parm = spec->hp_independent_mode ?
756 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
757 snd_hda_codec_write(codec, sw3, 0,
758 AC_VERB_SET_AMP_GAIN_MUTE, parm);
759 if (spec->codec_type == VT1812)
760 snd_hda_codec_write(codec, 0x1d, 0,
761 AC_VERB_SET_AMP_GAIN_MUTE, parm);
766 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
767 struct snd_ctl_elem_value *ucontrol)
769 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
770 struct via_spec *spec = codec->spec;
771 hda_nid_t nid = kcontrol->private_value;
772 unsigned int pinsel = ucontrol->value.enumerated.item[0];
773 /* Get Independent Mode index of headphone pin widget */
774 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
776 if (spec->codec_type == VT1718S)
777 snd_hda_codec_write(codec, nid, 0,
778 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
780 snd_hda_codec_write(codec, nid, 0,
781 AC_VERB_SET_CONNECT_SEL, pinsel);
783 if (spec->codec_type == VT1812)
784 snd_hda_codec_write(codec, 0x35, 0,
785 AC_VERB_SET_CONNECT_SEL, pinsel);
786 if (spec->multiout.hp_nid && spec->multiout.hp_nid
787 != spec->multiout.dac_nids[HDA_FRONT])
788 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
791 update_side_mute_status(codec);
792 /* update HP volume/swtich active state */
793 if (spec->codec_type == VT1708S
794 || spec->codec_type == VT1702
795 || spec->codec_type == VT1718S
796 || spec->codec_type == VT1716S
797 || VT2002P_COMPATIBLE(spec)) {
798 activate_ctl(codec, "Headphone Playback Volume",
799 spec->hp_independent_mode);
800 activate_ctl(codec, "Headphone Playback Switch",
801 spec->hp_independent_mode);
803 /* update jack power state */
804 set_widgets_power_state(codec);
808 static const struct snd_kcontrol_new via_hp_mixer[2] = {
810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
811 .name = "Independent HP",
812 .info = via_independent_hp_info,
813 .get = via_independent_hp_get,
814 .put = via_independent_hp_put,
817 .iface = NID_MAPPING,
818 .name = "Independent HP",
822 static int via_hp_build(struct hda_codec *codec)
824 struct via_spec *spec = codec->spec;
825 struct snd_kcontrol_new *knew;
828 hda_nid_t conn[HDA_MAX_CONNECTIONS];
830 switch (spec->codec_type) {
842 nid = spec->autocfg.hp_pins[0];
846 if (spec->codec_type != VT1708) {
847 nums = snd_hda_get_connections(codec, nid,
848 conn, HDA_MAX_CONNECTIONS);
853 knew = via_clone_control(spec, &via_hp_mixer[0]);
857 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
858 knew->private_value = nid;
860 knew = via_clone_control(spec, &via_hp_mixer[1]);
863 knew->subdevice = side_mute_channel(spec);
868 static void notify_aa_path_ctls(struct hda_codec *codec)
871 struct snd_ctl_elem_id id;
872 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
873 struct snd_kcontrol *ctl;
875 memset(&id, 0, sizeof(id));
876 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
877 for (i = 0; i < ARRAY_SIZE(labels); i++) {
878 sprintf(id.name, "%s Playback Volume", labels[i]);
879 ctl = snd_hda_find_mixer_ctl(codec, id.name);
881 snd_ctl_notify(codec->bus->card,
882 SNDRV_CTL_EVENT_MASK_VALUE,
887 static void mute_aa_path(struct hda_codec *codec, int mute)
889 struct via_spec *spec = codec->spec;
893 /* get nid of MW0 and start & end index */
894 switch (spec->codec_type) {
918 /* check AA path's mute status */
919 for (i = start_idx; i <= end_idx; i++) {
920 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
921 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, HDA_INPUT, i,
926 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
928 struct via_spec *spec = codec->spec;
929 const struct auto_pin_cfg *cfg = &spec->autocfg;
932 for (i = 0; i < cfg->num_inputs; i++) {
934 if (pin != cfg->inputs[i].pin)
936 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
938 defcfg = snd_hda_codec_get_pincfg(codec, pin);
939 if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL)
946 static int via_smart51_info(struct snd_kcontrol *kcontrol,
947 struct snd_ctl_elem_info *uinfo)
949 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
951 uinfo->value.integer.min = 0;
952 uinfo->value.integer.max = 1;
956 static int via_smart51_get(struct snd_kcontrol *kcontrol,
957 struct snd_ctl_elem_value *ucontrol)
959 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
960 struct via_spec *spec = codec->spec;
961 const struct auto_pin_cfg *cfg = &spec->autocfg;
965 for (i = 0; i < cfg->num_inputs; i++) {
966 hda_nid_t nid = cfg->inputs[i].pin;
968 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
969 spec->hp_independent_mode && spec->codec_type != VT1718S)
970 continue; /* ignore FMic for independent HP */
971 if (!is_smart51_pins(codec, nid))
973 ctl = snd_hda_codec_read(codec, nid, 0,
974 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
975 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
978 *ucontrol->value.integer.value = on;
982 static int via_smart51_put(struct snd_kcontrol *kcontrol,
983 struct snd_ctl_elem_value *ucontrol)
985 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
986 struct via_spec *spec = codec->spec;
987 const struct auto_pin_cfg *cfg = &spec->autocfg;
988 int out_in = *ucontrol->value.integer.value
989 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
992 for (i = 0; i < cfg->num_inputs; i++) {
993 hda_nid_t nid = cfg->inputs[i].pin;
996 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
997 spec->hp_independent_mode && spec->codec_type != VT1718S)
998 continue; /* don't retask FMic for independent HP */
999 if (!is_smart51_pins(codec, nid))
1002 parm = snd_hda_codec_read(codec, nid, 0,
1003 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1004 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1006 snd_hda_codec_write(codec, nid, 0,
1007 AC_VERB_SET_PIN_WIDGET_CONTROL,
1009 if (out_in == AC_PINCTL_OUT_EN) {
1010 mute_aa_path(codec, 1);
1011 notify_aa_path_ctls(codec);
1014 spec->smart51_enabled = *ucontrol->value.integer.value;
1015 set_widgets_power_state(codec);
1019 static const struct snd_kcontrol_new via_smart51_mixer = {
1020 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1021 .name = "Smart 5.1",
1023 .info = via_smart51_info,
1024 .get = via_smart51_get,
1025 .put = via_smart51_put,
1028 static int via_smart51_build(struct hda_codec *codec)
1030 struct via_spec *spec = codec->spec;
1031 struct snd_kcontrol_new *knew;
1032 const struct auto_pin_cfg *cfg = &spec->autocfg;
1036 if (!spec->can_smart51)
1039 knew = via_clone_control(spec, &via_smart51_mixer);
1043 for (i = 0; i < cfg->num_inputs; i++) {
1044 nid = cfg->inputs[i].pin;
1045 if (is_smart51_pins(codec, nid)) {
1046 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1054 /* check AA path's mute statue */
1055 static int is_aa_path_mute(struct hda_codec *codec)
1061 struct via_spec *spec = codec->spec;
1062 /* get nid of MW0 and start & end index */
1063 switch (spec->codec_type) {
1088 /* check AA path's mute status */
1089 for (i = start_idx; i <= end_idx; i++) {
1090 unsigned int con_list = snd_hda_codec_read(
1091 codec, spec->aa_mix_nid, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1092 int shift = 8 * (i % 4);
1093 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1094 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1095 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1096 /* check mute status while the pin is connected */
1097 int mute_l = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 0,
1099 int mute_r = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 1,
1101 if (!mute_l || !mute_r) {
1110 /* enter/exit analog low-current mode */
1111 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1113 struct via_spec *spec = codec->spec;
1114 static int saved_stream_idle = 1; /* saved stream idle status */
1115 int enable = is_aa_path_mute(codec);
1116 unsigned int verb = 0;
1117 unsigned int parm = 0;
1119 if (stream_idle == -1) /* stream status did not change */
1120 enable = enable && saved_stream_idle;
1122 enable = enable && stream_idle;
1123 saved_stream_idle = stream_idle;
1126 /* decide low current mode's verb & parameter */
1127 switch (spec->codec_type) {
1131 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1137 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1141 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1147 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1150 return; /* other codecs are not supported */
1153 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1157 * generic initialization of ADC, input mixers and output mixers
1159 static const struct hda_verb vt1708_volume_init_verbs[] = {
1161 * Unmute ADC0-1 and set the default input to mic-in
1163 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1164 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1167 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1170 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1171 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1172 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1173 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1174 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1175 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1178 * Set up output mixers (0x19 - 0x1b)
1180 /* set vol=0 to output mixers */
1181 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1182 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1183 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1185 /* Setup default input MW0 to PW4 */
1186 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1187 /* PW9 Output enable */
1188 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1189 /* power down jack detect function */
1194 static void substream_set_idle(struct hda_codec *codec,
1195 struct snd_pcm_substream *substream)
1197 int idle = substream->pstr->substream_opened == 1
1198 && substream->ref_count == 0;
1199 analog_low_current_mode(codec, idle);
1202 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1203 struct hda_codec *codec,
1204 struct snd_pcm_substream *substream)
1206 struct via_spec *spec = codec->spec;
1207 substream_set_idle(codec, substream);
1208 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1212 static int via_playback_pcm_close(struct hda_pcm_stream *hinfo,
1213 struct hda_codec *codec,
1214 struct snd_pcm_substream *substream)
1216 substream_set_idle(codec, substream);
1220 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1221 struct hda_codec *codec,
1222 struct snd_pcm_substream *substream)
1224 struct via_spec *spec = codec->spec;
1225 struct hda_multi_out *mout = &spec->multiout;
1227 if (!mout->hp_nid || mout->hp_nid == mout->dac_nids[HDA_FRONT] ||
1228 !spec->hp_independent_mode)
1230 substream_set_idle(codec, substream);
1234 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1235 struct hda_codec *codec,
1236 unsigned int stream_tag,
1237 unsigned int format,
1238 struct snd_pcm_substream *substream)
1240 struct via_spec *spec = codec->spec;
1241 struct hda_multi_out *mout = &spec->multiout;
1242 const hda_nid_t *nids = mout->dac_nids;
1243 int chs = substream->runtime->channels;
1245 struct hda_spdif_out *spdif =
1246 snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid);
1248 mutex_lock(&codec->spdif_mutex);
1249 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1251 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1253 !(spdif->status & IEC958_AES0_NONAUDIO)) {
1254 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1255 /* turn off SPDIF once; otherwise the IEC958 bits won't
1257 if (spdif->ctls & AC_DIG1_ENABLE)
1258 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1259 AC_VERB_SET_DIGI_CONVERT_1,
1261 ~AC_DIG1_ENABLE & 0xff);
1262 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1263 stream_tag, 0, format);
1264 /* turn on again (if needed) */
1265 if (spdif->ctls & AC_DIG1_ENABLE)
1266 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1267 AC_VERB_SET_DIGI_CONVERT_1,
1268 spdif->ctls & 0xff);
1270 mout->dig_out_used = 0;
1271 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1275 mutex_unlock(&codec->spdif_mutex);
1278 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1281 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1282 && !spec->hp_independent_mode)
1283 /* headphone out will just decode front left/right (stereo) */
1284 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1287 /* extra outputs copied from front */
1288 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1289 if (mout->extra_out_nid[i])
1290 snd_hda_codec_setup_stream(codec,
1291 mout->extra_out_nid[i],
1292 stream_tag, 0, format);
1295 for (i = 1; i < mout->num_dacs; i++) {
1296 if (chs >= (i + 1) * 2) /* independent out */
1297 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1299 else /* copy front */
1300 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1303 vt1708_start_hp_work(spec);
1307 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1308 struct hda_codec *codec,
1309 unsigned int stream_tag,
1310 unsigned int format,
1311 struct snd_pcm_substream *substream)
1313 struct via_spec *spec = codec->spec;
1314 struct hda_multi_out *mout = &spec->multiout;
1316 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format);
1317 vt1708_start_hp_work(spec);
1321 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1322 struct hda_codec *codec,
1323 struct snd_pcm_substream *substream)
1325 struct via_spec *spec = codec->spec;
1326 struct hda_multi_out *mout = &spec->multiout;
1327 const hda_nid_t *nids = mout->dac_nids;
1330 for (i = 0; i < mout->num_dacs; i++)
1331 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1333 if (mout->hp_nid && !spec->hp_independent_mode)
1334 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1337 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1338 if (mout->extra_out_nid[i])
1339 snd_hda_codec_setup_stream(codec,
1340 mout->extra_out_nid[i],
1342 mutex_lock(&codec->spdif_mutex);
1343 if (mout->dig_out_nid &&
1344 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1345 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1347 mout->dig_out_used = 0;
1349 mutex_unlock(&codec->spdif_mutex);
1350 vt1708_stop_hp_work(spec);
1354 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1355 struct hda_codec *codec,
1356 struct snd_pcm_substream *substream)
1358 struct via_spec *spec = codec->spec;
1359 struct hda_multi_out *mout = &spec->multiout;
1361 snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0);
1362 vt1708_stop_hp_work(spec);
1369 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1370 struct hda_codec *codec,
1371 struct snd_pcm_substream *substream)
1373 struct via_spec *spec = codec->spec;
1374 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1377 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1378 struct hda_codec *codec,
1379 struct snd_pcm_substream *substream)
1381 struct via_spec *spec = codec->spec;
1382 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1385 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1386 struct hda_codec *codec,
1387 unsigned int stream_tag,
1388 unsigned int format,
1389 struct snd_pcm_substream *substream)
1391 struct via_spec *spec = codec->spec;
1392 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1393 stream_tag, format, substream);
1396 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1397 struct hda_codec *codec,
1398 struct snd_pcm_substream *substream)
1400 struct via_spec *spec = codec->spec;
1401 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1408 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1409 struct hda_codec *codec,
1410 unsigned int stream_tag,
1411 unsigned int format,
1412 struct snd_pcm_substream *substream)
1414 struct via_spec *spec = codec->spec;
1416 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1417 stream_tag, 0, format);
1421 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1422 struct hda_codec *codec,
1423 struct snd_pcm_substream *substream)
1425 struct via_spec *spec = codec->spec;
1426 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1430 static const struct hda_pcm_stream via_pcm_analog_playback = {
1434 /* NID is set in via_build_pcms */
1436 .open = via_playback_pcm_open,
1437 .close = via_playback_pcm_close,
1438 .prepare = via_playback_multi_pcm_prepare,
1439 .cleanup = via_playback_multi_pcm_cleanup
1443 static const struct hda_pcm_stream via_pcm_hp_playback = {
1447 /* NID is set in via_build_pcms */
1449 .open = via_playback_hp_pcm_open,
1450 .close = via_playback_pcm_close,
1451 .prepare = via_playback_hp_pcm_prepare,
1452 .cleanup = via_playback_hp_pcm_cleanup
1456 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1460 /* NID is set in via_build_pcms */
1461 /* We got noisy outputs on the right channel on VT1708 when
1462 * 24bit samples are used. Until any workaround is found,
1463 * disable the 24bit format, so far.
1465 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1467 .open = via_playback_pcm_open,
1468 .close = via_playback_pcm_close,
1469 .prepare = via_playback_multi_pcm_prepare,
1470 .cleanup = via_playback_multi_pcm_cleanup
1474 static const struct hda_pcm_stream via_pcm_analog_capture = {
1475 .substreams = 1, /* will be changed in via_build_pcms() */
1478 /* NID is set in via_build_pcms */
1480 .open = via_playback_pcm_open,
1481 .close = via_playback_pcm_close,
1482 .prepare = via_capture_pcm_prepare,
1483 .cleanup = via_capture_pcm_cleanup
1487 static const struct hda_pcm_stream via_pcm_digital_playback = {
1491 /* NID is set in via_build_pcms */
1493 .open = via_dig_playback_pcm_open,
1494 .close = via_dig_playback_pcm_close,
1495 .prepare = via_dig_playback_pcm_prepare,
1496 .cleanup = via_dig_playback_pcm_cleanup
1500 static const struct hda_pcm_stream via_pcm_digital_capture = {
1506 static int via_build_controls(struct hda_codec *codec)
1508 struct via_spec *spec = codec->spec;
1509 struct snd_kcontrol *kctl;
1510 const struct snd_kcontrol_new *knew;
1513 if (spec->set_widgets_power_state)
1514 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1517 for (i = 0; i < spec->num_mixers; i++) {
1518 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1523 if (spec->multiout.dig_out_nid) {
1524 err = snd_hda_create_spdif_out_ctls(codec,
1525 spec->multiout.dig_out_nid,
1526 spec->multiout.dig_out_nid);
1529 err = snd_hda_create_spdif_share_sw(codec,
1533 spec->multiout.share_spdif = 1;
1535 if (spec->dig_in_nid) {
1536 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1541 /* assign Capture Source enums to NID */
1542 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1543 for (i = 0; kctl && i < kctl->count; i++) {
1544 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1549 /* other nid->control mapping */
1550 for (i = 0; i < spec->num_mixers; i++) {
1551 for (knew = spec->mixers[i]; knew->name; knew++) {
1552 if (knew->iface != NID_MAPPING)
1554 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1557 err = snd_hda_add_nid(codec, kctl, 0,
1562 /* init power states */
1563 set_widgets_power_state(codec);
1564 analog_low_current_mode(codec, 1);
1566 via_free_kctls(codec); /* no longer needed */
1570 static int via_build_pcms(struct hda_codec *codec)
1572 struct via_spec *spec = codec->spec;
1573 struct hda_pcm *info = spec->pcm_rec;
1575 codec->num_pcms = 1;
1576 codec->pcm_info = info;
1578 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1579 "%s Analog", codec->chip_name);
1580 info->name = spec->stream_name_analog;
1582 if (!spec->stream_analog_playback)
1583 spec->stream_analog_playback = &via_pcm_analog_playback;
1584 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1585 *spec->stream_analog_playback;
1586 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1587 spec->multiout.dac_nids[0];
1588 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1589 spec->multiout.max_channels;
1591 if (!spec->stream_analog_capture)
1592 spec->stream_analog_capture = &via_pcm_analog_capture;
1593 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1594 *spec->stream_analog_capture;
1595 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1596 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1599 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1602 snprintf(spec->stream_name_digital,
1603 sizeof(spec->stream_name_digital),
1604 "%s Digital", codec->chip_name);
1605 info->name = spec->stream_name_digital;
1606 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1607 if (spec->multiout.dig_out_nid) {
1608 if (!spec->stream_digital_playback)
1609 spec->stream_digital_playback =
1610 &via_pcm_digital_playback;
1611 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1612 *spec->stream_digital_playback;
1613 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1614 spec->multiout.dig_out_nid;
1616 if (spec->dig_in_nid) {
1617 if (!spec->stream_digital_capture)
1618 spec->stream_digital_capture =
1619 &via_pcm_digital_capture;
1620 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1621 *spec->stream_digital_capture;
1622 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1627 if (spec->multiout.hp_nid) {
1630 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1631 "%s HP", codec->chip_name);
1632 info->name = spec->stream_name_hp;
1633 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1634 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1635 spec->multiout.hp_nid;
1640 static void via_free(struct hda_codec *codec)
1642 struct via_spec *spec = codec->spec;
1647 via_free_kctls(codec);
1648 vt1708_stop_hp_work(spec);
1652 /* mute/unmute outputs */
1653 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1654 hda_nid_t *pins, bool mute)
1657 for (i = 0; i < num_pins; i++)
1658 snd_hda_codec_write(codec, pins[i], 0,
1659 AC_VERB_SET_PIN_WIDGET_CONTROL,
1660 mute ? 0 : PIN_OUT);
1663 /* mute internal speaker if HP is plugged */
1664 static void via_hp_automute(struct hda_codec *codec)
1666 unsigned int present = 0;
1667 struct via_spec *spec = codec->spec;
1669 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1671 if (!spec->hp_independent_mode)
1672 toggle_output_mutes(codec, spec->autocfg.line_outs,
1673 spec->autocfg.line_out_pins,
1677 /* mute mono out if HP or Line out is plugged */
1678 static void via_mono_automute(struct hda_codec *codec)
1680 unsigned int hp_present, lineout_present;
1681 struct via_spec *spec = codec->spec;
1683 if (spec->codec_type != VT1716S)
1686 lineout_present = snd_hda_jack_detect(codec,
1687 spec->autocfg.line_out_pins[0]);
1689 /* Mute Mono Out if Line Out is plugged */
1690 if (lineout_present) {
1691 snd_hda_codec_write(codec, 0x2A, 0,
1692 AC_VERB_SET_PIN_WIDGET_CONTROL,
1693 lineout_present ? 0 : PIN_OUT);
1697 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1699 if (!spec->hp_independent_mode)
1700 snd_hda_codec_write(codec, 0x2A, 0,
1701 AC_VERB_SET_PIN_WIDGET_CONTROL,
1702 hp_present ? 0 : PIN_OUT);
1705 static void via_gpio_control(struct hda_codec *codec)
1707 unsigned int gpio_data;
1708 unsigned int vol_counter;
1710 unsigned int master_vol;
1712 struct via_spec *spec = codec->spec;
1714 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1715 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1717 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1718 0xF84, 0) & 0x3F0000) >> 16;
1720 vol = vol_counter & 0x1F;
1721 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1722 AC_VERB_GET_AMP_GAIN_MUTE,
1725 if (gpio_data == 0x02) {
1726 /* unmute line out */
1727 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1728 AC_VERB_SET_PIN_WIDGET_CONTROL,
1730 if (vol_counter & 0x20) {
1731 /* decrease volume */
1732 if (vol > master_vol)
1734 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1738 /* increase volume */
1739 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1741 ((master_vol+vol) > 0x2A) ? 0x2A :
1744 } else if (!(gpio_data & 0x02)) {
1746 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1747 AC_VERB_SET_PIN_WIDGET_CONTROL,
1752 /* mute Internal-Speaker if HP is plugged */
1753 static void via_speaker_automute(struct hda_codec *codec)
1755 unsigned int hp_present;
1756 struct via_spec *spec = codec->spec;
1758 if (!VT2002P_COMPATIBLE(spec))
1761 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1763 if (!spec->hp_independent_mode)
1764 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1765 spec->autocfg.speaker_pins,
1769 /* mute line-out and internal speaker if HP is plugged */
1770 static void via_hp_bind_automute(struct hda_codec *codec)
1773 struct via_spec *spec = codec->spec;
1775 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1778 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1779 if (!spec->hp_independent_mode)
1780 toggle_output_mutes(codec, spec->autocfg.line_outs,
1781 spec->autocfg.line_out_pins,
1785 present = snd_hda_jack_detect(codec,
1786 spec->autocfg.line_out_pins[0]);
1789 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1790 spec->autocfg.speaker_pins,
1795 /* unsolicited event for jack sensing */
1796 static void via_unsol_event(struct hda_codec *codec,
1801 if (res & VIA_JACK_EVENT)
1802 set_widgets_power_state(codec);
1804 res &= ~VIA_JACK_EVENT;
1806 if (res == VIA_HP_EVENT)
1807 via_hp_automute(codec);
1808 else if (res == VIA_GPIO_EVENT)
1809 via_gpio_control(codec);
1810 else if (res == VIA_MONO_EVENT)
1811 via_mono_automute(codec);
1812 else if (res == VIA_SPEAKER_EVENT)
1813 via_speaker_automute(codec);
1814 else if (res == VIA_BIND_HP_EVENT)
1815 via_hp_bind_automute(codec);
1818 static int via_init(struct hda_codec *codec)
1820 struct via_spec *spec = codec->spec;
1822 for (i = 0; i < spec->num_iverbs; i++)
1823 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1825 /* Lydia Add for EAPD enable */
1826 if (!spec->dig_in_nid) { /* No Digital In connection */
1827 if (spec->dig_in_pin) {
1828 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1829 AC_VERB_SET_PIN_WIDGET_CONTROL,
1831 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1832 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1834 } else /* enable SPDIF-input pin */
1835 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1836 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1838 /* assign slave outs */
1839 if (spec->slave_dig_outs[0])
1840 codec->slave_dig_outs = spec->slave_dig_outs;
1845 #ifdef SND_HDA_NEEDS_RESUME
1846 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1848 struct via_spec *spec = codec->spec;
1849 vt1708_stop_hp_work(spec);
1854 #ifdef CONFIG_SND_HDA_POWER_SAVE
1855 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1857 struct via_spec *spec = codec->spec;
1858 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1864 static const struct hda_codec_ops via_patch_ops = {
1865 .build_controls = via_build_controls,
1866 .build_pcms = via_build_pcms,
1869 #ifdef SND_HDA_NEEDS_RESUME
1870 .suspend = via_suspend,
1872 #ifdef CONFIG_SND_HDA_POWER_SAVE
1873 .check_power_status = via_check_power_status,
1877 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1879 struct via_spec *spec = codec->spec;
1882 for (i = 0; i < spec->multiout.num_dacs; i++) {
1883 if (spec->multiout.dac_nids[i] == dac)
1886 if (spec->multiout.hp_nid == dac)
1891 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1892 hda_nid_t target_dac, struct nid_path *path,
1893 int depth, int wid_type)
1898 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1899 for (i = 0; i < nums; i++) {
1900 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1902 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1903 path->path[depth] = conn[i];
1904 path->idx[depth] = i;
1905 path->depth = ++depth;
1911 for (i = 0; i < nums; i++) {
1913 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1914 if (type == AC_WID_AUD_OUT ||
1915 (wid_type != -1 && type != wid_type))
1917 if (parse_output_path(codec, conn[i], target_dac,
1918 path, depth + 1, AC_WID_AUD_SEL)) {
1919 path->path[depth] = conn[i];
1920 path->idx[depth] = i;
1927 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1929 struct via_spec *spec = codec->spec;
1930 const struct auto_pin_cfg *cfg = &spec->autocfg;
1934 spec->multiout.dac_nids = spec->private_dac_nids;
1935 spec->multiout.num_dacs = cfg->line_outs;
1936 for (i = 0; i < cfg->line_outs; i++) {
1937 nid = cfg->line_out_pins[i];
1940 if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1))
1941 spec->private_dac_nids[i] =
1942 spec->out_path[i].path[spec->out_path[i].depth - 1];
1947 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1948 hda_nid_t pin, hda_nid_t dac, int chs)
1950 struct via_spec *spec = codec->spec;
1955 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1957 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1962 sprintf(name, "%s Playback Volume", pfx);
1963 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1964 HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT));
1969 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1971 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1976 sprintf(name, "%s Playback Switch", pfx);
1977 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1978 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1985 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
1988 static void mangle_smart51(struct hda_codec *codec)
1990 struct via_spec *spec = codec->spec;
1991 struct auto_pin_cfg *cfg = &spec->autocfg;
1994 for (i = 0; i < cfg->num_inputs; i++) {
1995 if (!is_smart51_pins(codec, cfg->inputs[i].pin))
1997 spec->can_smart51 = 1;
1998 cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin;
1999 if (cfg->line_outs == 3)
2004 /* add playback controls from the parsed DAC table */
2005 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
2007 struct via_spec *spec = codec->spec;
2008 struct auto_pin_cfg *cfg = &spec->autocfg;
2009 static const char * const chname[4] = {
2010 "Front", "Surround", "C/LFE", "Side"
2016 old_line_outs = cfg->line_outs;
2017 if (cfg->line_outs == 1)
2018 mangle_smart51(codec);
2020 for (i = 0; i < cfg->line_outs; i++) {
2022 pin = cfg->line_out_pins[i];
2023 dac = spec->multiout.dac_nids[i];
2026 if (i == AUTO_SEQ_CENLFE) {
2027 err = create_ch_ctls(codec, "Center", pin, dac, 1);
2030 err = create_ch_ctls(codec, "LFE", pin, dac, 2);
2034 err = create_ch_ctls(codec, chname[i], pin, dac, 3);
2040 idx = get_connection_index(codec, spec->aa_mix_nid,
2041 spec->multiout.dac_nids[0]);
2043 /* add control to mixer */
2044 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2045 "PCM Playback Volume",
2046 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2050 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2051 "PCM Playback Switch",
2052 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2058 cfg->line_outs = old_line_outs;
2063 static void create_hp_imux(struct via_spec *spec)
2066 struct hda_input_mux *imux = &spec->private_imux[1];
2067 static const char * const texts[] = { "OFF", "ON", NULL};
2069 /* for hp mode select */
2070 for (i = 0; texts[i]; i++)
2071 snd_hda_add_imux_item(imux, texts[i], i, NULL);
2073 spec->hp_mux = &spec->private_imux[1];
2076 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
2078 struct via_spec *spec = codec->spec;
2085 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2086 &spec->hp_dep_path, 0, -1))
2088 if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) {
2089 dac = spec->hp_path.path[spec->hp_path.depth - 1];
2090 spec->multiout.hp_nid = dac;
2091 spec->hp_independent_mode_index =
2092 spec->hp_path.idx[spec->hp_path.depth - 1];
2093 create_hp_imux(spec);
2096 err = create_ch_ctls(codec, "Headphone", pin, dac, 3);
2103 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
2106 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
2109 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
2110 for (i = 0; i < nums; i++)
2117 static int via_fill_adcs(struct hda_codec *codec)
2119 struct via_spec *spec = codec->spec;
2120 hda_nid_t nid = codec->start_nid;
2123 for (i = 0; i < codec->num_nodes; i++, nid++) {
2124 unsigned int wcaps = get_wcaps(codec, nid);
2125 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2127 if (wcaps & AC_WCAP_DIGITAL)
2129 if (!(wcaps & AC_WCAP_CONN_LIST))
2131 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2133 spec->adc_nids[spec->num_adc_nids++] = nid;
2138 static int get_mux_nids(struct hda_codec *codec);
2140 static const struct snd_kcontrol_new via_input_src_ctl = {
2141 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2142 /* The multiple "Capture Source" controls confuse alsamixer
2143 * So call somewhat different..
2145 /* .name = "Capture Source", */
2146 .name = "Input Source",
2147 .info = via_mux_enum_info,
2148 .get = via_mux_enum_get,
2149 .put = via_mux_enum_put,
2152 /* create playback/capture controls for input pins */
2153 static int via_auto_create_analog_input_ctls(struct hda_codec *codec,
2154 const struct auto_pin_cfg *cfg)
2156 struct via_spec *spec = codec->spec;
2157 struct hda_input_mux *imux = &spec->private_imux[0];
2158 int i, err, idx, idx2, type, type_idx = 0;
2160 hda_nid_t pin_idxs[8];
2163 err = via_fill_adcs(codec);
2166 err = get_mux_nids(codec);
2169 cap_nid = spec->mux_nids[0];
2171 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2172 ARRAY_SIZE(pin_idxs));
2176 /* for internal loopback recording select */
2177 for (idx = 0; idx < num_idxs; idx++) {
2178 if (pin_idxs[idx] == spec->aa_mix_nid) {
2179 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2184 for (i = 0; i < cfg->num_inputs; i++) {
2186 type = cfg->inputs[i].type;
2187 for (idx = 0; idx < num_idxs; idx++)
2188 if (pin_idxs[idx] == cfg->inputs[i].pin)
2190 if (idx >= num_idxs)
2192 if (i > 0 && type == cfg->inputs[i - 1].type)
2196 label = hda_get_autocfg_input_label(codec, cfg, i);
2197 idx2 = get_connection_index(codec, spec->aa_mix_nid,
2200 err = via_new_analog_input(spec, label, type_idx,
2201 idx2, spec->aa_mix_nid);
2204 snd_hda_add_imux_item(imux, label, idx, NULL);
2207 /* create capture mixer elements */
2208 for (i = 0; i < spec->num_adc_nids; i++) {
2209 hda_nid_t adc = spec->adc_nids[i];
2210 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2211 "Capture Volume", i,
2212 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2216 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2217 "Capture Switch", i,
2218 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2224 /* input-source control */
2225 for (i = 0; i < spec->num_adc_nids; i++)
2226 if (!spec->mux_nids[i])
2229 struct snd_kcontrol_new *knew;
2230 knew = via_clone_control(spec, &via_input_src_ctl);
2237 for (i = 0; i < cfg->num_inputs; i++) {
2238 hda_nid_t pin = cfg->inputs[i].pin;
2243 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2245 caps = query_amp_caps(codec, pin, HDA_INPUT);
2246 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2248 label = hda_get_autocfg_input_label(codec, cfg, i);
2249 snprintf(name, sizeof(name), "%s Boost Capture Volume", label);
2250 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2251 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2259 #ifdef CONFIG_SND_HDA_POWER_SAVE
2260 static const struct hda_amp_list vt1708_loopbacks[] = {
2261 { 0x17, HDA_INPUT, 1 },
2262 { 0x17, HDA_INPUT, 2 },
2263 { 0x17, HDA_INPUT, 3 },
2264 { 0x17, HDA_INPUT, 4 },
2269 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2271 unsigned int def_conf;
2272 unsigned char seqassoc;
2274 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2275 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2276 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2277 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2278 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2279 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2280 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2286 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2287 struct snd_ctl_elem_value *ucontrol)
2289 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2290 struct via_spec *spec = codec->spec;
2292 if (spec->codec_type != VT1708)
2294 spec->vt1708_jack_detect =
2295 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2296 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2300 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2301 struct snd_ctl_elem_value *ucontrol)
2303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2304 struct via_spec *spec = codec->spec;
2307 if (spec->codec_type != VT1708)
2309 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2310 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2311 == !spec->vt1708_jack_detect;
2312 if (spec->vt1708_jack_detect) {
2313 mute_aa_path(codec, 1);
2314 notify_aa_path_ctls(codec);
2319 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2320 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2321 .name = "Jack Detect",
2323 .info = snd_ctl_boolean_mono_info,
2324 .get = vt1708_jack_detect_get,
2325 .put = vt1708_jack_detect_put,
2328 static int vt1708_parse_auto_config(struct hda_codec *codec)
2330 struct via_spec *spec = codec->spec;
2333 /* Add HP and CD pin config connect bit re-config action */
2334 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2335 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2337 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2340 err = via_auto_fill_dac_nids(codec);
2343 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2346 err = via_auto_create_multi_out_ctls(codec);
2349 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2352 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
2355 /* add jack detect on/off control */
2356 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2359 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2361 if (spec->autocfg.dig_outs)
2362 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2363 spec->dig_in_pin = VT1708_DIGIN_PIN;
2364 if (spec->autocfg.dig_in_pin)
2365 spec->dig_in_nid = VT1708_DIGIN_NID;
2367 if (spec->kctls.list)
2368 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2370 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2372 spec->input_mux = &spec->private_imux[0];
2375 via_hp_build(codec);
2377 err = via_smart51_build(codec);
2384 /* init callback for auto-configuration model -- overriding the default init */
2385 static int via_auto_init(struct hda_codec *codec)
2387 struct via_spec *spec = codec->spec;
2390 via_auto_init_multi_out(codec);
2391 via_auto_init_hp_out(codec);
2392 via_auto_init_analog_input(codec);
2394 if (VT2002P_COMPATIBLE(spec)) {
2395 via_hp_bind_automute(codec);
2397 via_hp_automute(codec);
2398 via_speaker_automute(codec);
2404 static void vt1708_update_hp_jack_state(struct work_struct *work)
2406 struct via_spec *spec = container_of(work, struct via_spec,
2407 vt1708_hp_work.work);
2408 if (spec->codec_type != VT1708)
2410 /* if jack state toggled */
2411 if (spec->vt1708_hp_present
2412 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2413 spec->vt1708_hp_present ^= 1;
2414 via_hp_automute(spec->codec);
2416 vt1708_start_hp_work(spec);
2419 static int get_mux_nids(struct hda_codec *codec)
2421 struct via_spec *spec = codec->spec;
2422 hda_nid_t nid, conn[8];
2426 for (i = 0; i < spec->num_adc_nids; i++) {
2427 nid = spec->adc_nids[i];
2429 type = get_wcaps_type(get_wcaps(codec, nid));
2430 if (type == AC_WID_PIN)
2432 n = snd_hda_get_connections(codec, nid, conn,
2437 spec->mux_nids[i] = nid;
2446 static int patch_vt1708(struct hda_codec *codec)
2448 struct via_spec *spec;
2451 /* create a codec specific record */
2452 spec = via_new_spec(codec);
2456 spec->aa_mix_nid = 0x17;
2458 /* automatic parse from the BIOS config */
2459 err = vt1708_parse_auto_config(codec);
2465 /* disable 32bit format on VT1708 */
2466 if (codec->vendor_id == 0x11061708)
2467 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2469 codec->patch_ops = via_patch_ops;
2471 codec->patch_ops.init = via_auto_init;
2472 #ifdef CONFIG_SND_HDA_POWER_SAVE
2473 spec->loopback.amplist = vt1708_loopbacks;
2475 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2479 static const struct hda_verb vt1709_uniwill_init_verbs[] = {
2480 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2481 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2486 * generic initialization of ADC, input mixers and output mixers
2488 static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2490 * Unmute ADC0-2 and set the default input to mic-in
2492 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2493 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2494 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2497 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2500 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2501 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2502 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2503 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2504 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2505 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2508 * Set up output selector (0x1a, 0x1b, 0x29)
2510 /* set vol=0 to output mixers */
2511 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2512 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2513 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2516 * Unmute PW3 and PW4
2518 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2519 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2521 /* Set input of PW4 as MW0 */
2522 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2523 /* PW9 Output enable */
2524 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2528 static int vt1709_parse_auto_config(struct hda_codec *codec)
2530 struct via_spec *spec = codec->spec;
2533 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2536 err = via_auto_fill_dac_nids(codec);
2539 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2542 err = via_auto_create_multi_out_ctls(codec);
2545 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2548 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
2552 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2554 if (spec->autocfg.dig_outs)
2555 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2556 spec->dig_in_pin = VT1709_DIGIN_PIN;
2557 if (spec->autocfg.dig_in_pin)
2558 spec->dig_in_nid = VT1709_DIGIN_NID;
2560 if (spec->kctls.list)
2561 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2563 spec->input_mux = &spec->private_imux[0];
2566 via_hp_build(codec);
2568 err = via_smart51_build(codec);
2575 #ifdef CONFIG_SND_HDA_POWER_SAVE
2576 static const struct hda_amp_list vt1709_loopbacks[] = {
2577 { 0x18, HDA_INPUT, 1 },
2578 { 0x18, HDA_INPUT, 2 },
2579 { 0x18, HDA_INPUT, 3 },
2580 { 0x18, HDA_INPUT, 4 },
2585 static int patch_vt1709_10ch(struct hda_codec *codec)
2587 struct via_spec *spec;
2590 /* create a codec specific record */
2591 spec = via_new_spec(codec);
2595 spec->aa_mix_nid = 0x18;
2597 err = vt1709_parse_auto_config(codec);
2603 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2604 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2606 codec->patch_ops = via_patch_ops;
2608 codec->patch_ops.init = via_auto_init;
2609 codec->patch_ops.unsol_event = via_unsol_event;
2610 #ifdef CONFIG_SND_HDA_POWER_SAVE
2611 spec->loopback.amplist = vt1709_loopbacks;
2617 * generic initialization of ADC, input mixers and output mixers
2619 static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2621 * Unmute ADC0-2 and set the default input to mic-in
2623 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2624 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2625 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2628 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2631 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2632 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2633 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2634 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2635 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2636 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2639 * Set up output selector (0x1a, 0x1b, 0x29)
2641 /* set vol=0 to output mixers */
2642 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2643 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2644 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2647 * Unmute PW3 and PW4
2649 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2650 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2652 /* Set input of PW4 as MW0 */
2653 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2654 /* PW9 Output enable */
2655 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2659 static int patch_vt1709_6ch(struct hda_codec *codec)
2661 struct via_spec *spec;
2664 /* create a codec specific record */
2665 spec = via_new_spec(codec);
2669 spec->aa_mix_nid = 0x18;
2671 err = vt1709_parse_auto_config(codec);
2677 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2678 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2680 codec->patch_ops = via_patch_ops;
2682 codec->patch_ops.init = via_auto_init;
2683 codec->patch_ops.unsol_event = via_unsol_event;
2684 #ifdef CONFIG_SND_HDA_POWER_SAVE
2685 spec->loopback.amplist = vt1709_loopbacks;
2691 * generic initialization of ADC, input mixers and output mixers
2693 static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2695 * Unmute ADC0-1 and set the default input to mic-in
2697 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2698 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2701 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2704 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2705 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2706 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2707 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2708 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2709 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2712 * Set up output mixers
2714 /* set vol=0 to output mixers */
2715 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2716 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2717 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2719 /* Setup default input to PW4 */
2720 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2721 /* PW9 Output enable */
2722 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2723 /* PW10 Input enable */
2724 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2728 static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2730 * Unmute ADC0-1 and set the default input to mic-in
2732 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2733 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2736 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2739 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2740 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2741 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2742 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2743 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2744 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2747 * Set up output mixers
2749 /* set vol=0 to output mixers */
2750 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2751 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2752 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2754 /* Setup default input of PW4 to MW0 */
2755 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2756 /* PW9 Output enable */
2757 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2758 /* PW10 Input enable */
2759 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2763 static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
2764 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2765 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2766 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2767 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2768 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2769 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2770 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2771 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2772 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2776 static int vt1708B_parse_auto_config(struct hda_codec *codec)
2778 struct via_spec *spec = codec->spec;
2781 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2784 err = via_auto_fill_dac_nids(codec);
2787 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2790 err = via_auto_create_multi_out_ctls(codec);
2793 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2796 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
2800 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2802 if (spec->autocfg.dig_outs)
2803 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2804 spec->dig_in_pin = VT1708B_DIGIN_PIN;
2805 if (spec->autocfg.dig_in_pin)
2806 spec->dig_in_nid = VT1708B_DIGIN_NID;
2808 if (spec->kctls.list)
2809 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2811 spec->input_mux = &spec->private_imux[0];
2814 via_hp_build(codec);
2816 err = via_smart51_build(codec);
2823 #ifdef CONFIG_SND_HDA_POWER_SAVE
2824 static const struct hda_amp_list vt1708B_loopbacks[] = {
2825 { 0x16, HDA_INPUT, 1 },
2826 { 0x16, HDA_INPUT, 2 },
2827 { 0x16, HDA_INPUT, 3 },
2828 { 0x16, HDA_INPUT, 4 },
2833 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2835 struct via_spec *spec = codec->spec;
2839 if ((spec->codec_type != VT1708B_4CH) &&
2840 (codec->vendor_id != 0x11064397))
2843 /* SW0 (17h) = stereo mixer */
2845 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2846 == ((spec->codec_type == VT1708S) ? 5 : 0));
2848 /* PW 1/2/5 (1ah/1bh/1eh) */
2850 set_pin_power_state(codec, 0x1a, &parm);
2851 set_pin_power_state(codec, 0x1b, &parm);
2852 set_pin_power_state(codec, 0x1e, &parm);
2855 /* SW0 (17h), AIW 0/1 (13h/14h) */
2856 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2857 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2858 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2861 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2863 set_pin_power_state(codec, 0x19, &parm);
2864 if (spec->smart51_enabled)
2865 set_pin_power_state(codec, 0x1b, &parm);
2866 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2867 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2869 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2872 set_pin_power_state(codec, 0x22, &parm);
2873 if (spec->smart51_enabled)
2874 set_pin_power_state(codec, 0x1a, &parm);
2875 snd_hda_codec_write(codec, 0x26, 0,
2876 AC_VERB_SET_POWER_STATE, parm);
2877 snd_hda_codec_write(codec, 0x24, 0,
2878 AC_VERB_SET_POWER_STATE, parm);
2879 } else if (codec->vendor_id == 0x11064397) {
2880 /* PW7(23h), SW2(27h), AOW2(25h) */
2882 set_pin_power_state(codec, 0x23, &parm);
2883 if (spec->smart51_enabled)
2884 set_pin_power_state(codec, 0x1a, &parm);
2885 snd_hda_codec_write(codec, 0x27, 0,
2886 AC_VERB_SET_POWER_STATE, parm);
2887 snd_hda_codec_write(codec, 0x25, 0,
2888 AC_VERB_SET_POWER_STATE, parm);
2891 /* PW 3/4/7 (1ch/1dh/23h) */
2893 /* force to D0 for internal Speaker */
2894 set_pin_power_state(codec, 0x1c, &parm);
2895 set_pin_power_state(codec, 0x1d, &parm);
2897 set_pin_power_state(codec, 0x23, &parm);
2899 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2900 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2901 imux_is_smixer ? AC_PWRST_D0 : parm);
2902 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2904 snd_hda_codec_write(codec, 0x25, 0,
2905 AC_VERB_SET_POWER_STATE, parm);
2906 snd_hda_codec_write(codec, 0x27, 0,
2907 AC_VERB_SET_POWER_STATE, parm);
2908 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2909 snd_hda_codec_write(codec, 0x25, 0,
2910 AC_VERB_SET_POWER_STATE, parm);
2913 static int patch_vt1708S(struct hda_codec *codec);
2914 static int patch_vt1708B_8ch(struct hda_codec *codec)
2916 struct via_spec *spec;
2919 if (get_codec_type(codec) == VT1708BCE)
2920 return patch_vt1708S(codec);
2921 /* create a codec specific record */
2922 spec = via_new_spec(codec);
2926 spec->aa_mix_nid = 0x16;
2928 /* automatic parse from the BIOS config */
2929 err = vt1708B_parse_auto_config(codec);
2935 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2936 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2938 codec->patch_ops = via_patch_ops;
2940 codec->patch_ops.init = via_auto_init;
2941 codec->patch_ops.unsol_event = via_unsol_event;
2942 #ifdef CONFIG_SND_HDA_POWER_SAVE
2943 spec->loopback.amplist = vt1708B_loopbacks;
2946 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2951 static int patch_vt1708B_4ch(struct hda_codec *codec)
2953 struct via_spec *spec;
2956 /* create a codec specific record */
2957 spec = via_new_spec(codec);
2961 /* automatic parse from the BIOS config */
2962 err = vt1708B_parse_auto_config(codec);
2968 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2969 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2971 codec->patch_ops = via_patch_ops;
2973 codec->patch_ops.init = via_auto_init;
2974 codec->patch_ops.unsol_event = via_unsol_event;
2975 #ifdef CONFIG_SND_HDA_POWER_SAVE
2976 spec->loopback.amplist = vt1708B_loopbacks;
2979 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2984 /* Patch for VT1708S */
2986 static const struct hda_verb vt1708S_volume_init_verbs[] = {
2987 /* Unmute ADC0-1 and set the default input to mic-in */
2988 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2989 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2991 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2992 * analog-loopback mixer widget */
2993 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2994 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2995 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2996 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2997 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2998 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3000 /* Setup default input of PW4 to MW0 */
3001 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3002 /* PW9, PW10 Output enable */
3003 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3004 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3005 /* Enable Mic Boost Volume backdoor */
3007 /* don't bybass mixer */
3012 static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
3013 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3014 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3015 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3016 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3017 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3018 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3019 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3020 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3021 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3025 static const struct hda_verb vt1705_uniwill_init_verbs[] = {
3026 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3027 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3028 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3029 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3030 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3031 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3032 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3033 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3037 /* fill out digital output widgets; one for master and one for slave outputs */
3038 static void fill_dig_outs(struct hda_codec *codec)
3040 struct via_spec *spec = codec->spec;
3043 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3047 nid = spec->autocfg.dig_out_pins[i];
3050 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3053 if (!spec->multiout.dig_out_nid)
3054 spec->multiout.dig_out_nid = nid;
3056 spec->slave_dig_outs[0] = nid;
3057 break; /* at most two dig outs */
3062 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3064 struct via_spec *spec = codec->spec;
3067 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3070 err = via_auto_fill_dac_nids(codec);
3073 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3076 err = via_auto_create_multi_out_ctls(codec);
3079 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
3082 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
3086 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3088 fill_dig_outs(codec);
3090 if (spec->kctls.list)
3091 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3093 spec->input_mux = &spec->private_imux[0];
3096 via_hp_build(codec);
3098 err = via_smart51_build(codec);
3105 #ifdef CONFIG_SND_HDA_POWER_SAVE
3106 static const struct hda_amp_list vt1708S_loopbacks[] = {
3107 { 0x16, HDA_INPUT, 1 },
3108 { 0x16, HDA_INPUT, 2 },
3109 { 0x16, HDA_INPUT, 3 },
3110 { 0x16, HDA_INPUT, 4 },
3115 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3116 int offset, int num_steps, int step_size)
3118 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3119 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3120 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3121 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3122 (0 << AC_AMPCAP_MUTE_SHIFT));
3125 static int patch_vt1708S(struct hda_codec *codec)
3127 struct via_spec *spec;
3130 /* create a codec specific record */
3131 spec = via_new_spec(codec);
3135 spec->aa_mix_nid = 0x16;
3136 override_mic_boost(codec, 0x1a, 0, 3, 40);
3137 override_mic_boost(codec, 0x1e, 0, 3, 40);
3139 /* automatic parse from the BIOS config */
3140 err = vt1708S_parse_auto_config(codec);
3146 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3147 if (codec->vendor_id == 0x11064397)
3148 spec->init_verbs[spec->num_iverbs++] =
3149 vt1705_uniwill_init_verbs;
3151 spec->init_verbs[spec->num_iverbs++] =
3152 vt1708S_uniwill_init_verbs;
3154 codec->patch_ops = via_patch_ops;
3156 codec->patch_ops.init = via_auto_init;
3157 codec->patch_ops.unsol_event = via_unsol_event;
3158 #ifdef CONFIG_SND_HDA_POWER_SAVE
3159 spec->loopback.amplist = vt1708S_loopbacks;
3162 /* correct names for VT1708BCE */
3163 if (get_codec_type(codec) == VT1708BCE) {
3164 kfree(codec->chip_name);
3165 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3166 snprintf(codec->bus->card->mixername,
3167 sizeof(codec->bus->card->mixername),
3168 "%s %s", codec->vendor_name, codec->chip_name);
3170 /* correct names for VT1705 */
3171 if (codec->vendor_id == 0x11064397) {
3172 kfree(codec->chip_name);
3173 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3174 snprintf(codec->bus->card->mixername,
3175 sizeof(codec->bus->card->mixername),
3176 "%s %s", codec->vendor_name, codec->chip_name);
3178 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3182 /* Patch for VT1702 */
3184 static const struct hda_verb vt1702_volume_init_verbs[] = {
3186 * Unmute ADC0-1 and set the default input to mic-in
3188 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3189 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3190 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3193 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3196 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3197 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3198 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3199 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3200 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3201 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3203 /* Setup default input of PW4 to MW0 */
3204 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3205 /* PW6 PW7 Output enable */
3206 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3207 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3215 static const struct hda_verb vt1702_uniwill_init_verbs[] = {
3216 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3217 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3218 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3219 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3220 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3221 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3225 static int vt1702_parse_auto_config(struct hda_codec *codec)
3227 struct via_spec *spec = codec->spec;
3230 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3233 err = via_auto_fill_dac_nids(codec);
3236 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3239 err = via_auto_create_multi_out_ctls(codec);
3242 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
3245 /* limit AA path volume to 0 dB */
3246 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3247 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3248 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3249 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3250 (1 << AC_AMPCAP_MUTE_SHIFT));
3251 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
3255 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3257 fill_dig_outs(codec);
3259 if (spec->kctls.list)
3260 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3262 spec->input_mux = &spec->private_imux[0];
3265 via_hp_build(codec);
3270 #ifdef CONFIG_SND_HDA_POWER_SAVE
3271 static const struct hda_amp_list vt1702_loopbacks[] = {
3272 { 0x1A, HDA_INPUT, 1 },
3273 { 0x1A, HDA_INPUT, 2 },
3274 { 0x1A, HDA_INPUT, 3 },
3275 { 0x1A, HDA_INPUT, 4 },
3280 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3282 int imux_is_smixer =
3283 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3286 /* PW 1/2/5 (14h/15h/18h) */
3288 set_pin_power_state(codec, 0x14, &parm);
3289 set_pin_power_state(codec, 0x15, &parm);
3290 set_pin_power_state(codec, 0x18, &parm);
3292 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3293 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3294 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3295 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
3296 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3297 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
3300 /* PW 3/4 (16h/17h) */
3302 set_pin_power_state(codec, 0x17, &parm);
3303 set_pin_power_state(codec, 0x16, &parm);
3304 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3305 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
3306 imux_is_smixer ? AC_PWRST_D0 : parm);
3307 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3308 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3311 static int patch_vt1702(struct hda_codec *codec)
3313 struct via_spec *spec;
3316 /* create a codec specific record */
3317 spec = via_new_spec(codec);
3321 spec->aa_mix_nid = 0x1a;
3323 /* automatic parse from the BIOS config */
3324 err = vt1702_parse_auto_config(codec);
3330 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3331 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
3333 codec->patch_ops = via_patch_ops;
3335 codec->patch_ops.init = via_auto_init;
3336 codec->patch_ops.unsol_event = via_unsol_event;
3337 #ifdef CONFIG_SND_HDA_POWER_SAVE
3338 spec->loopback.amplist = vt1702_loopbacks;
3341 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
3345 /* Patch for VT1718S */
3347 static const struct hda_verb vt1718S_volume_init_verbs[] = {
3349 * Unmute ADC0-1 and set the default input to mic-in
3351 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3352 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3354 /* Enable MW0 adjust Gain 5 */
3356 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3359 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3360 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3361 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3362 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3363 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3364 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3366 /* Setup default input of Front HP to MW9 */
3367 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
3368 /* PW9 PW10 Output enable */
3369 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
3370 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
3371 /* PW11 Input enable */
3372 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
3373 /* Enable Boost Volume backdoor */
3375 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
3376 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3377 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3378 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3379 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3380 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3381 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3382 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3383 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3384 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3385 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3386 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
3387 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
3388 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
3389 /* Unmute MW4's index 0 */
3390 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3395 static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
3396 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
3397 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3398 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3399 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3400 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3401 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3402 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3403 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3404 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3408 static int vt1718S_parse_auto_config(struct hda_codec *codec)
3410 struct via_spec *spec = codec->spec;
3413 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3417 err = via_auto_fill_dac_nids(codec);
3420 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3423 err = via_auto_create_multi_out_ctls(codec);
3426 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
3429 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
3433 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3435 fill_dig_outs(codec);
3437 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
3438 spec->dig_in_nid = 0x13;
3440 if (spec->kctls.list)
3441 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3443 spec->input_mux = &spec->private_imux[0];
3446 via_hp_build(codec);
3448 err = via_smart51_build(codec);
3455 #ifdef CONFIG_SND_HDA_POWER_SAVE
3456 static const struct hda_amp_list vt1718S_loopbacks[] = {
3457 { 0x21, HDA_INPUT, 1 },
3458 { 0x21, HDA_INPUT, 2 },
3459 { 0x21, HDA_INPUT, 3 },
3460 { 0x21, HDA_INPUT, 4 },
3465 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3467 struct via_spec *spec = codec->spec;
3470 /* MUX6 (1eh) = stereo mixer */
3472 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3474 /* PW 5/6/7 (29h/2ah/2bh) */
3476 set_pin_power_state(codec, 0x29, &parm);
3477 set_pin_power_state(codec, 0x2a, &parm);
3478 set_pin_power_state(codec, 0x2b, &parm);
3481 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3482 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3483 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3484 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3485 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3488 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3490 set_pin_power_state(codec, 0x27, &parm);
3491 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
3492 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
3494 /* PW2 (26h), AOW2 (ah) */
3496 set_pin_power_state(codec, 0x26, &parm);
3497 if (spec->smart51_enabled)
3498 set_pin_power_state(codec, 0x2b, &parm);
3499 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
3501 /* PW0 (24h), AOW0 (8h) */
3503 set_pin_power_state(codec, 0x24, &parm);
3504 if (!spec->hp_independent_mode) /* check for redirected HP */
3505 set_pin_power_state(codec, 0x28, &parm);
3506 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3507 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3508 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3509 imux_is_smixer ? AC_PWRST_D0 : parm);
3511 /* PW1 (25h), AOW1 (9h) */
3513 set_pin_power_state(codec, 0x25, &parm);
3514 if (spec->smart51_enabled)
3515 set_pin_power_state(codec, 0x2a, &parm);
3516 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3518 if (spec->hp_independent_mode) {
3519 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3521 set_pin_power_state(codec, 0x28, &parm);
3522 snd_hda_codec_write(codec, 0x1b, 0,
3523 AC_VERB_SET_POWER_STATE, parm);
3524 snd_hda_codec_write(codec, 0x34, 0,
3525 AC_VERB_SET_POWER_STATE, parm);
3526 snd_hda_codec_write(codec, 0xc, 0,
3527 AC_VERB_SET_POWER_STATE, parm);
3531 static int patch_vt1718S(struct hda_codec *codec)
3533 struct via_spec *spec;
3536 /* create a codec specific record */
3537 spec = via_new_spec(codec);
3541 spec->aa_mix_nid = 0x21;
3542 override_mic_boost(codec, 0x2b, 0, 3, 40);
3543 override_mic_boost(codec, 0x29, 0, 3, 40);
3545 /* automatic parse from the BIOS config */
3546 err = vt1718S_parse_auto_config(codec);
3552 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
3553 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
3555 codec->patch_ops = via_patch_ops;
3557 codec->patch_ops.init = via_auto_init;
3558 codec->patch_ops.unsol_event = via_unsol_event;
3560 #ifdef CONFIG_SND_HDA_POWER_SAVE
3561 spec->loopback.amplist = vt1718S_loopbacks;
3564 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3569 /* Patch for VT1716S */
3571 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3572 struct snd_ctl_elem_info *uinfo)
3574 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3576 uinfo->value.integer.min = 0;
3577 uinfo->value.integer.max = 1;
3581 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3582 struct snd_ctl_elem_value *ucontrol)
3584 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3587 index = snd_hda_codec_read(codec, 0x26, 0,
3588 AC_VERB_GET_CONNECT_SEL, 0);
3590 *ucontrol->value.integer.value = index;
3595 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3596 struct snd_ctl_elem_value *ucontrol)
3598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3599 struct via_spec *spec = codec->spec;
3600 int index = *ucontrol->value.integer.value;
3602 snd_hda_codec_write(codec, 0x26, 0,
3603 AC_VERB_SET_CONNECT_SEL, index);
3604 spec->dmic_enabled = index;
3605 set_widgets_power_state(codec);
3609 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3610 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3613 .name = "Digital Mic Capture Switch",
3614 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3616 .info = vt1716s_dmic_info,
3617 .get = vt1716s_dmic_get,
3618 .put = vt1716s_dmic_put,
3624 /* mono-out mixer elements */
3625 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3626 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3630 static const struct hda_verb vt1716S_volume_init_verbs[] = {
3632 * Unmute ADC0-1 and set the default input to mic-in
3634 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3635 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3638 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3641 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3642 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3643 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3644 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3645 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3646 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3648 /* MUX Indices: Stereo Mixer = 5 */
3649 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
3651 /* Setup default input of PW4 to MW0 */
3652 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3654 /* Setup default input of SW1 as MW0 */
3655 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
3657 /* Setup default input of SW4 as AOW0 */
3658 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
3660 /* PW9 PW10 Output enable */
3661 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3662 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3664 /* Unmute SW1, PW12 */
3665 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3666 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3667 /* PW12 Output enable */
3668 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3669 /* Enable Boost Volume backdoor */
3671 /* don't bybass mixer */
3673 /* Enable mono output */
3679 static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
3680 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3681 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3682 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3683 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3684 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3685 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
3686 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
3687 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3688 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3692 static int vt1716S_parse_auto_config(struct hda_codec *codec)
3694 struct via_spec *spec = codec->spec;
3697 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3700 err = via_auto_fill_dac_nids(codec);
3703 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3706 err = via_auto_create_multi_out_ctls(codec);
3709 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
3712 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
3716 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3718 fill_dig_outs(codec);
3720 if (spec->kctls.list)
3721 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3723 spec->input_mux = &spec->private_imux[0];
3726 via_hp_build(codec);
3728 err = via_smart51_build(codec);
3735 #ifdef CONFIG_SND_HDA_POWER_SAVE
3736 static const struct hda_amp_list vt1716S_loopbacks[] = {
3737 { 0x16, HDA_INPUT, 1 },
3738 { 0x16, HDA_INPUT, 2 },
3739 { 0x16, HDA_INPUT, 3 },
3740 { 0x16, HDA_INPUT, 4 },
3745 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3747 struct via_spec *spec = codec->spec;
3750 unsigned int mono_out, present;
3751 /* SW0 (17h) = stereo mixer */
3753 (snd_hda_codec_read(codec, 0x17, 0,
3754 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3756 /* PW 1/2/5 (1ah/1bh/1eh) */
3758 set_pin_power_state(codec, 0x1a, &parm);
3759 set_pin_power_state(codec, 0x1b, &parm);
3760 set_pin_power_state(codec, 0x1e, &parm);
3763 /* SW0 (17h), AIW0(13h) */
3764 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3765 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3768 set_pin_power_state(codec, 0x1e, &parm);
3770 if (spec->dmic_enabled)
3771 set_pin_power_state(codec, 0x22, &parm);
3773 snd_hda_codec_write(codec, 0x22, 0,
3774 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3776 /* SW2(26h), AIW1(14h) */
3777 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3778 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3781 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3783 set_pin_power_state(codec, 0x19, &parm);
3784 /* Smart 5.1 PW2(1bh) */
3785 if (spec->smart51_enabled)
3786 set_pin_power_state(codec, 0x1b, &parm);
3787 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3788 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3790 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3792 set_pin_power_state(codec, 0x23, &parm);
3793 /* Smart 5.1 PW1(1ah) */
3794 if (spec->smart51_enabled)
3795 set_pin_power_state(codec, 0x1a, &parm);
3796 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3798 /* Smart 5.1 PW5(1eh) */
3799 if (spec->smart51_enabled)
3800 set_pin_power_state(codec, 0x1e, &parm);
3801 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3804 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3805 present = snd_hda_jack_detect(codec, 0x1c);
3810 present = snd_hda_jack_detect(codec, 0x1d);
3811 if (!spec->hp_independent_mode && present)
3816 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3817 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3818 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3819 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3821 /* PW 3/4 (1ch/1dh) */
3823 set_pin_power_state(codec, 0x1c, &parm);
3824 set_pin_power_state(codec, 0x1d, &parm);
3825 /* HP Independent Mode, power on AOW3 */
3826 if (spec->hp_independent_mode)
3827 snd_hda_codec_write(codec, 0x25, 0,
3828 AC_VERB_SET_POWER_STATE, parm);
3830 /* force to D0 for internal Speaker */
3831 /* MW0 (16h), AOW0 (10h) */
3832 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3833 imux_is_smixer ? AC_PWRST_D0 : parm);
3834 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3835 mono_out ? AC_PWRST_D0 : parm);
3838 static int patch_vt1716S(struct hda_codec *codec)
3840 struct via_spec *spec;
3843 /* create a codec specific record */
3844 spec = via_new_spec(codec);
3848 spec->aa_mix_nid = 0x16;
3849 override_mic_boost(codec, 0x1a, 0, 3, 40);
3850 override_mic_boost(codec, 0x1e, 0, 3, 40);
3852 /* automatic parse from the BIOS config */
3853 err = vt1716S_parse_auto_config(codec);
3859 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
3860 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
3862 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3865 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3867 codec->patch_ops = via_patch_ops;
3869 codec->patch_ops.init = via_auto_init;
3870 codec->patch_ops.unsol_event = via_unsol_event;
3872 #ifdef CONFIG_SND_HDA_POWER_SAVE
3873 spec->loopback.amplist = vt1716S_loopbacks;
3876 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3882 static const struct hda_verb vt2002P_volume_init_verbs[] = {
3883 /* Class-D speaker related verbs */
3888 * Unmute ADC0-1 and set the default input to mic-in
3890 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3891 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3894 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3897 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3898 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3899 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3900 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3901 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3902 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3904 /* MUX Indices: Mic = 0 */
3905 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
3906 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
3908 /* PW9 Output enable */
3909 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
3911 /* Enable Boost Volume backdoor */
3914 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
3915 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3916 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3917 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3918 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3919 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3920 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3921 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3922 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3924 /* set MUX0/1/4/8 = 0 (AOW0) */
3925 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
3926 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
3927 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
3928 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
3930 /* set PW0 index=0 (MW0) */
3931 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
3933 /* Enable AOW0 to MW9 */
3937 static const struct hda_verb vt1802_volume_init_verbs[] = {
3939 * Unmute ADC0-1 and set the default input to mic-in
3941 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3942 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3945 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3948 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3949 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3950 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3951 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3952 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3953 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3955 /* MUX Indices: Mic = 0 */
3956 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
3957 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
3959 /* PW9 Output enable */
3960 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
3962 /* Enable Boost Volume backdoor */
3965 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
3966 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3967 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3968 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3969 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3970 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3971 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3972 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3973 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3975 /* set MUX0/1/4/8 = 0 (AOW0) */
3976 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
3977 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
3978 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
3979 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
3981 /* set PW0 index=0 (MW0) */
3982 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
3984 /* Enable AOW0 to MW9 */
3990 static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
3991 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
3992 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
3993 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
3994 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
3995 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3996 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3997 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4000 static const struct hda_verb vt1802_uniwill_init_verbs[] = {
4001 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
4002 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4003 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4004 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4005 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4006 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4007 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4011 static int vt2002P_parse_auto_config(struct hda_codec *codec)
4013 struct via_spec *spec = codec->spec;
4017 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4021 err = via_auto_fill_dac_nids(codec);
4025 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4028 err = via_auto_create_multi_out_ctls(codec);
4031 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
4034 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
4038 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4040 fill_dig_outs(codec);
4042 if (spec->kctls.list)
4043 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4045 spec->input_mux = &spec->private_imux[0];
4048 via_hp_build(codec);
4053 #ifdef CONFIG_SND_HDA_POWER_SAVE
4054 static const struct hda_amp_list vt2002P_loopbacks[] = {
4055 { 0x21, HDA_INPUT, 0 },
4056 { 0x21, HDA_INPUT, 1 },
4057 { 0x21, HDA_INPUT, 2 },
4062 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
4064 struct via_spec *spec = codec->spec;
4067 unsigned int present;
4068 /* MUX9 (1eh) = stereo mixer */
4070 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4072 /* PW 5/6/7 (29h/2ah/2bh) */
4074 set_pin_power_state(codec, 0x29, &parm);
4075 set_pin_power_state(codec, 0x2a, &parm);
4076 set_pin_power_state(codec, 0x2b, &parm);
4078 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
4079 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4080 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4081 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4082 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4086 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4088 if (spec->codec_type == VT1802) {
4089 /* PW4 (28h), MW4 (18h), MUX4(38h) */
4091 set_pin_power_state(codec, 0x28, &parm);
4092 snd_hda_codec_write(codec, 0x18, 0,
4093 AC_VERB_SET_POWER_STATE, parm);
4094 snd_hda_codec_write(codec, 0x38, 0,
4095 AC_VERB_SET_POWER_STATE, parm);
4097 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
4099 set_pin_power_state(codec, 0x26, &parm);
4100 snd_hda_codec_write(codec, 0x1c, 0,
4101 AC_VERB_SET_POWER_STATE, parm);
4102 snd_hda_codec_write(codec, 0x37, 0,
4103 AC_VERB_SET_POWER_STATE, parm);
4106 if (spec->codec_type == VT1802) {
4107 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
4109 set_pin_power_state(codec, 0x25, &parm);
4110 snd_hda_codec_write(codec, 0x15, 0,
4111 AC_VERB_SET_POWER_STATE, parm);
4112 snd_hda_codec_write(codec, 0x35, 0,
4113 AC_VERB_SET_POWER_STATE, parm);
4115 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
4117 set_pin_power_state(codec, 0x25, &parm);
4118 snd_hda_codec_write(codec, 0x19, 0,
4119 AC_VERB_SET_POWER_STATE, parm);
4120 snd_hda_codec_write(codec, 0x35, 0,
4121 AC_VERB_SET_POWER_STATE, parm);
4124 if (spec->hp_independent_mode)
4125 snd_hda_codec_write(codec, 0x9, 0,
4126 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4129 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
4130 present = snd_hda_jack_detect(codec, 0x25);
4133 set_pin_power_state(codec, 0x24, &parm);
4134 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
4135 if (spec->codec_type == VT1802)
4136 snd_hda_codec_write(codec, 0x14, 0,
4137 AC_VERB_SET_POWER_STATE, parm);
4139 snd_hda_codec_write(codec, 0x18, 0,
4140 AC_VERB_SET_POWER_STATE, parm);
4141 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
4144 present = snd_hda_jack_detect(codec, 0x26);
4146 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
4147 if (spec->codec_type == VT1802) {
4148 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
4149 snd_hda_codec_write(codec, 0x33, 0,
4150 AC_VERB_SET_POWER_STATE, parm);
4151 snd_hda_codec_write(codec, 0x1c, 0,
4152 AC_VERB_SET_POWER_STATE, parm);
4153 snd_hda_codec_write(codec, 0x3c, 0,
4154 AC_VERB_SET_POWER_STATE, parm);
4156 /* PW15 (31h), MW8(17h), MUX8(3bh) */
4157 snd_hda_codec_write(codec, 0x31, 0,
4158 AC_VERB_SET_POWER_STATE, parm);
4159 snd_hda_codec_write(codec, 0x17, 0,
4160 AC_VERB_SET_POWER_STATE, parm);
4161 snd_hda_codec_write(codec, 0x3b, 0,
4162 AC_VERB_SET_POWER_STATE, parm);
4165 if (imux_is_smixer || !is_aa_path_mute(codec))
4166 snd_hda_codec_write(codec, 0x21, 0,
4167 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4169 snd_hda_codec_write(codec, 0x21, 0,
4170 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4173 /* patch for vt2002P */
4174 static int patch_vt2002P(struct hda_codec *codec)
4176 struct via_spec *spec;
4179 /* create a codec specific record */
4180 spec = via_new_spec(codec);
4184 spec->aa_mix_nid = 0x21;
4185 override_mic_boost(codec, 0x2b, 0, 3, 40);
4186 override_mic_boost(codec, 0x29, 0, 3, 40);
4188 /* automatic parse from the BIOS config */
4189 err = vt2002P_parse_auto_config(codec);
4195 if (spec->codec_type == VT1802)
4196 spec->init_verbs[spec->num_iverbs++] =
4197 vt1802_volume_init_verbs;
4199 spec->init_verbs[spec->num_iverbs++] =
4200 vt2002P_volume_init_verbs;
4202 if (spec->codec_type == VT1802)
4203 spec->init_verbs[spec->num_iverbs++] =
4204 vt1802_uniwill_init_verbs;
4206 spec->init_verbs[spec->num_iverbs++] =
4207 vt2002P_uniwill_init_verbs;
4209 codec->patch_ops = via_patch_ops;
4211 codec->patch_ops.init = via_auto_init;
4212 codec->patch_ops.unsol_event = via_unsol_event;
4214 #ifdef CONFIG_SND_HDA_POWER_SAVE
4215 spec->loopback.amplist = vt2002P_loopbacks;
4218 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
4224 static const struct hda_verb vt1812_volume_init_verbs[] = {
4226 * Unmute ADC0-1 and set the default input to mic-in
4228 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4229 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4232 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4235 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4236 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4237 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4238 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4239 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4240 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4242 /* MUX Indices: Mic = 0 */
4243 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
4244 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
4246 /* PW9 Output enable */
4247 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4249 /* Enable Boost Volume backdoor */
4252 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
4253 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4254 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4255 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4256 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4257 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4258 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4259 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4260 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4261 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4262 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4264 /* set MUX0/1/4/13/15 = 0 (AOW0) */
4265 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
4266 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
4267 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
4268 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
4269 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
4271 /* Enable AOW0 to MW9 */
4277 static const struct hda_verb vt1812_uniwill_init_verbs[] = {
4278 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
4279 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4280 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
4281 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4282 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
4283 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4284 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4285 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4289 static int vt1812_parse_auto_config(struct hda_codec *codec)
4291 struct via_spec *spec = codec->spec;
4295 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4298 fill_dig_outs(codec);
4299 err = via_auto_fill_dac_nids(codec);
4303 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
4306 err = via_auto_create_multi_out_ctls(codec);
4309 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
4312 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
4316 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4318 fill_dig_outs(codec);
4320 if (spec->kctls.list)
4321 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4323 spec->input_mux = &spec->private_imux[0];
4326 via_hp_build(codec);
4331 #ifdef CONFIG_SND_HDA_POWER_SAVE
4332 static const struct hda_amp_list vt1812_loopbacks[] = {
4333 { 0x21, HDA_INPUT, 0 },
4334 { 0x21, HDA_INPUT, 1 },
4335 { 0x21, HDA_INPUT, 2 },
4340 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
4342 struct via_spec *spec = codec->spec;
4343 int imux_is_smixer =
4344 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4346 unsigned int present;
4347 /* MUX10 (1eh) = stereo mixer */
4349 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4351 /* PW 5/6/7 (29h/2ah/2bh) */
4353 set_pin_power_state(codec, 0x29, &parm);
4354 set_pin_power_state(codec, 0x2a, &parm);
4355 set_pin_power_state(codec, 0x2b, &parm);
4357 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
4358 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4359 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4360 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4361 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4365 snd_hda_codec_write(codec, 0x8, 0,
4366 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4368 /* PW4 (28h), MW4 (18h), MUX4(38h) */
4370 set_pin_power_state(codec, 0x28, &parm);
4371 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
4372 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
4374 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
4376 set_pin_power_state(codec, 0x25, &parm);
4377 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
4378 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
4379 if (spec->hp_independent_mode)
4380 snd_hda_codec_write(codec, 0x9, 0,
4381 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4383 /* Internal Speaker */
4384 /* PW0 (24h), MW0(14h), MUX0(34h) */
4385 present = snd_hda_jack_detect(codec, 0x25);
4388 set_pin_power_state(codec, 0x24, &parm);
4390 snd_hda_codec_write(codec, 0x14, 0,
4391 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4392 snd_hda_codec_write(codec, 0x34, 0,
4393 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4395 snd_hda_codec_write(codec, 0x14, 0,
4396 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4397 snd_hda_codec_write(codec, 0x34, 0,
4398 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4403 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
4404 present = snd_hda_jack_detect(codec, 0x28);
4407 set_pin_power_state(codec, 0x31, &parm);
4409 snd_hda_codec_write(codec, 0x1c, 0,
4410 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4411 snd_hda_codec_write(codec, 0x3c, 0,
4412 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4413 snd_hda_codec_write(codec, 0x3e, 0,
4414 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4416 snd_hda_codec_write(codec, 0x1c, 0,
4417 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4418 snd_hda_codec_write(codec, 0x3c, 0,
4419 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4420 snd_hda_codec_write(codec, 0x3e, 0,
4421 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
4424 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
4426 set_pin_power_state(codec, 0x33, &parm);
4427 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4428 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
4432 /* patch for vt1812 */
4433 static int patch_vt1812(struct hda_codec *codec)
4435 struct via_spec *spec;
4438 /* create a codec specific record */
4439 spec = via_new_spec(codec);
4443 spec->aa_mix_nid = 0x21;
4444 override_mic_boost(codec, 0x2b, 0, 3, 40);
4445 override_mic_boost(codec, 0x29, 0, 3, 40);
4447 /* automatic parse from the BIOS config */
4448 err = vt1812_parse_auto_config(codec);
4454 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
4455 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
4457 codec->patch_ops = via_patch_ops;
4459 codec->patch_ops.init = via_auto_init;
4460 codec->patch_ops.unsol_event = via_unsol_event;
4462 #ifdef CONFIG_SND_HDA_POWER_SAVE
4463 spec->loopback.amplist = vt1812_loopbacks;
4466 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
4473 static const struct hda_codec_preset snd_hda_preset_via[] = {
4474 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
4475 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
4476 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
4477 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
4478 { .id = 0x1106e710, .name = "VT1709 10-Ch",
4479 .patch = patch_vt1709_10ch},
4480 { .id = 0x1106e711, .name = "VT1709 10-Ch",
4481 .patch = patch_vt1709_10ch},
4482 { .id = 0x1106e712, .name = "VT1709 10-Ch",
4483 .patch = patch_vt1709_10ch},
4484 { .id = 0x1106e713, .name = "VT1709 10-Ch",
4485 .patch = patch_vt1709_10ch},
4486 { .id = 0x1106e714, .name = "VT1709 6-Ch",
4487 .patch = patch_vt1709_6ch},
4488 { .id = 0x1106e715, .name = "VT1709 6-Ch",
4489 .patch = patch_vt1709_6ch},
4490 { .id = 0x1106e716, .name = "VT1709 6-Ch",
4491 .patch = patch_vt1709_6ch},
4492 { .id = 0x1106e717, .name = "VT1709 6-Ch",
4493 .patch = patch_vt1709_6ch},
4494 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
4495 .patch = patch_vt1708B_8ch},
4496 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
4497 .patch = patch_vt1708B_8ch},
4498 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
4499 .patch = patch_vt1708B_8ch},
4500 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
4501 .patch = patch_vt1708B_8ch},
4502 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
4503 .patch = patch_vt1708B_4ch},
4504 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
4505 .patch = patch_vt1708B_4ch},
4506 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
4507 .patch = patch_vt1708B_4ch},
4508 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
4509 .patch = patch_vt1708B_4ch},
4510 { .id = 0x11060397, .name = "VT1708S",
4511 .patch = patch_vt1708S},
4512 { .id = 0x11061397, .name = "VT1708S",
4513 .patch = patch_vt1708S},
4514 { .id = 0x11062397, .name = "VT1708S",
4515 .patch = patch_vt1708S},
4516 { .id = 0x11063397, .name = "VT1708S",
4517 .patch = patch_vt1708S},
4518 { .id = 0x11064397, .name = "VT1705",
4519 .patch = patch_vt1708S},
4520 { .id = 0x11065397, .name = "VT1708S",
4521 .patch = patch_vt1708S},
4522 { .id = 0x11066397, .name = "VT1708S",
4523 .patch = patch_vt1708S},
4524 { .id = 0x11067397, .name = "VT1708S",
4525 .patch = patch_vt1708S},
4526 { .id = 0x11060398, .name = "VT1702",
4527 .patch = patch_vt1702},
4528 { .id = 0x11061398, .name = "VT1702",
4529 .patch = patch_vt1702},
4530 { .id = 0x11062398, .name = "VT1702",
4531 .patch = patch_vt1702},
4532 { .id = 0x11063398, .name = "VT1702",
4533 .patch = patch_vt1702},
4534 { .id = 0x11064398, .name = "VT1702",
4535 .patch = patch_vt1702},
4536 { .id = 0x11065398, .name = "VT1702",
4537 .patch = patch_vt1702},
4538 { .id = 0x11066398, .name = "VT1702",
4539 .patch = patch_vt1702},
4540 { .id = 0x11067398, .name = "VT1702",
4541 .patch = patch_vt1702},
4542 { .id = 0x11060428, .name = "VT1718S",
4543 .patch = patch_vt1718S},
4544 { .id = 0x11064428, .name = "VT1718S",
4545 .patch = patch_vt1718S},
4546 { .id = 0x11060441, .name = "VT2020",
4547 .patch = patch_vt1718S},
4548 { .id = 0x11064441, .name = "VT1828S",
4549 .patch = patch_vt1718S},
4550 { .id = 0x11060433, .name = "VT1716S",
4551 .patch = patch_vt1716S},
4552 { .id = 0x1106a721, .name = "VT1716S",
4553 .patch = patch_vt1716S},
4554 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
4555 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
4556 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
4557 { .id = 0x11060440, .name = "VT1818S",
4558 .patch = patch_vt1708S},
4559 { .id = 0x11060446, .name = "VT1802",
4560 .patch = patch_vt2002P},
4561 { .id = 0x11068446, .name = "VT1802",
4562 .patch = patch_vt2002P},
4566 MODULE_ALIAS("snd-hda-codec-id:1106*");
4568 static struct hda_codec_preset_list via_list = {
4569 .preset = snd_hda_preset_via,
4570 .owner = THIS_MODULE,
4573 MODULE_LICENSE("GPL");
4574 MODULE_DESCRIPTION("VIA HD-audio codec");
4576 static int __init patch_via_init(void)
4578 return snd_hda_add_codec_preset(&via_list);
4581 static void __exit patch_via_exit(void)
4583 snd_hda_delete_codec_preset(&via_list);
4586 module_init(patch_via_init)
4587 module_exit(patch_via_exit)