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"
58 #define VT1708_HP_PIN_NID 0x20
59 #define VT1708_CD_PIN_NID 0x24
79 #define VT2002P_COMPATIBLE(spec) \
80 ((spec)->codec_type == VT2002P ||\
81 (spec)->codec_type == VT1812 ||\
82 (spec)->codec_type == VT1802)
84 #define MAX_NID_PATH_DEPTH 5
86 /* output-path: DAC -> ... -> pin
87 * idx[] contains the source index number of the next widget;
88 * e.g. idx[0] is the index of the DAC selected by path[1] widget
89 * multi[] indicates whether it's a selector widget with multi-connectors
90 * (i.e. the connection selection is mandatory)
91 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
95 hda_nid_t path[MAX_NID_PATH_DEPTH];
96 unsigned char idx[MAX_NID_PATH_DEPTH];
97 unsigned char multi[MAX_NID_PATH_DEPTH];
99 unsigned int mute_ctl;
104 hda_nid_t pin; /* input-pin or aa-mix */
105 int adc_idx; /* ADC index to be used */
106 int mux_idx; /* MUX index (if any) */
107 const char *label; /* input-source label */
111 /* codec parameterization */
112 const struct snd_kcontrol_new *mixers[6];
113 unsigned int num_mixers;
115 const struct hda_verb *init_verbs[5];
116 unsigned int num_iverbs;
118 char stream_name_analog[32];
119 char stream_name_hp[32];
120 const struct hda_pcm_stream *stream_analog_playback;
121 const struct hda_pcm_stream *stream_analog_capture;
123 char stream_name_digital[32];
124 const struct hda_pcm_stream *stream_digital_playback;
125 const struct hda_pcm_stream *stream_digital_capture;
128 struct hda_multi_out multiout;
129 hda_nid_t slave_dig_outs[2];
130 hda_nid_t hp_dac_nid;
131 bool hp_indep_shared; /* indep HP-DAC is shared with side ch */
132 int num_active_streams;
135 struct nid_path out_path[4];
136 struct nid_path hp_path;
137 struct nid_path hp_dep_path;
138 struct nid_path speaker_path;
141 unsigned int num_adc_nids;
142 hda_nid_t adc_nids[3];
143 hda_nid_t mux_nids[3];
144 hda_nid_t aa_mix_nid;
145 hda_nid_t dig_in_nid;
150 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
151 unsigned int cur_mux[3];
153 /* dynamic ADC switching */
155 unsigned int cur_adc_stream_tag;
156 unsigned int cur_adc_format;
158 /* PCM information */
159 struct hda_pcm pcm_rec[3];
161 /* dynamic controls, init_verbs and input_mux */
162 struct auto_pin_cfg autocfg;
163 struct snd_array kctls;
164 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
167 unsigned int hp_independent_mode;
168 unsigned int dmic_enabled;
169 unsigned int no_pin_power_ctl;
170 enum VIA_HDA_CODEC codec_type;
173 unsigned int smart51_nums;
174 hda_nid_t smart51_pins[2];
176 const char *smart51_labels[2];
177 unsigned int smart51_enabled;
179 /* work to check hp jack state */
180 struct hda_codec *codec;
181 struct delayed_work vt1708_hp_work;
182 int vt1708_jack_detect;
183 int vt1708_hp_present;
185 void (*set_widgets_power_state)(struct hda_codec *codec);
187 struct hda_loopback_check loopback;
189 struct hda_amp_list loopback_list[8];
191 /* bind capture-volume */
192 struct hda_bind_ctls *bind_cap_vol;
193 struct hda_bind_ctls *bind_cap_sw;
196 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
197 static struct via_spec * via_new_spec(struct hda_codec *codec)
199 struct via_spec *spec;
201 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
207 spec->codec_type = get_codec_type(codec);
208 /* VT1708BCE & VT1708S are almost same */
209 if (spec->codec_type == VT1708BCE)
210 spec->codec_type = VT1708S;
214 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
216 u32 vendor_id = codec->vendor_id;
217 u16 ven_id = vendor_id >> 16;
218 u16 dev_id = vendor_id & 0xffff;
219 enum VIA_HDA_CODEC codec_type;
222 if (ven_id != 0x1106)
223 codec_type = UNKNOWN;
224 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
226 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
227 codec_type = VT1709_10CH;
228 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
229 codec_type = VT1709_6CH;
230 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
231 codec_type = VT1708B_8CH;
232 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
233 codec_type = VT1708BCE;
234 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
235 codec_type = VT1708B_4CH;
236 else if ((dev_id & 0xfff) == 0x397
237 && (dev_id >> 12) < 8)
238 codec_type = VT1708S;
239 else if ((dev_id & 0xfff) == 0x398
240 && (dev_id >> 12) < 8)
242 else if ((dev_id & 0xfff) == 0x428
243 && (dev_id >> 12) < 8)
244 codec_type = VT1718S;
245 else if (dev_id == 0x0433 || dev_id == 0xa721)
246 codec_type = VT1716S;
247 else if (dev_id == 0x0441 || dev_id == 0x4441)
248 codec_type = VT1718S;
249 else if (dev_id == 0x0438 || dev_id == 0x4438)
250 codec_type = VT2002P;
251 else if (dev_id == 0x0448)
253 else if (dev_id == 0x0440)
254 codec_type = VT1708S;
255 else if ((dev_id & 0xfff) == 0x446)
258 codec_type = UNKNOWN;
262 #define VIA_JACK_EVENT 0x20
263 #define VIA_HP_EVENT 0x01
264 #define VIA_GPIO_EVENT 0x02
265 #define VIA_LINE_EVENT 0x03
270 VIA_CTL_WIDGET_ANALOG_MUTE,
273 static void analog_low_current_mode(struct hda_codec *codec);
274 static bool is_aa_path_mute(struct hda_codec *codec);
276 static void vt1708_start_hp_work(struct via_spec *spec)
278 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
280 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
281 !spec->vt1708_jack_detect);
282 if (!delayed_work_pending(&spec->vt1708_hp_work))
283 schedule_delayed_work(&spec->vt1708_hp_work,
284 msecs_to_jiffies(100));
287 static void vt1708_stop_hp_work(struct via_spec *spec)
289 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
291 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
292 && !is_aa_path_mute(spec->codec))
294 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
295 !spec->vt1708_jack_detect);
296 cancel_delayed_work_sync(&spec->vt1708_hp_work);
299 static void set_widgets_power_state(struct hda_codec *codec)
301 struct via_spec *spec = codec->spec;
302 if (spec->set_widgets_power_state)
303 spec->set_widgets_power_state(codec);
306 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
307 struct snd_ctl_elem_value *ucontrol)
309 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
310 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
312 set_widgets_power_state(codec);
313 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
314 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
315 if (is_aa_path_mute(codec))
316 vt1708_start_hp_work(codec->spec);
318 vt1708_stop_hp_work(codec->spec);
323 /* modify .put = snd_hda_mixer_amp_switch_put */
324 #define ANALOG_INPUT_MUTE \
325 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
328 .info = snd_hda_mixer_amp_switch_info, \
329 .get = snd_hda_mixer_amp_switch_get, \
330 .put = analog_input_switch_put, \
331 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
333 static const struct snd_kcontrol_new via_control_templates[] = {
334 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
335 HDA_CODEC_MUTE(NULL, 0, 0, 0),
340 /* add dynamic controls */
341 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
342 const struct snd_kcontrol_new *tmpl,
345 struct snd_kcontrol_new *knew;
347 snd_array_init(&spec->kctls, sizeof(*knew), 32);
348 knew = snd_array_new(&spec->kctls);
355 knew->name = kstrdup(name, GFP_KERNEL);
362 static int __via_add_control(struct via_spec *spec, int type, const char *name,
363 int idx, unsigned long val)
365 struct snd_kcontrol_new *knew;
367 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
371 if (get_amp_nid_(val))
372 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
373 knew->private_value = val;
377 #define via_add_control(spec, type, name, val) \
378 __via_add_control(spec, type, name, 0, val)
380 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
382 static void via_free_kctls(struct hda_codec *codec)
384 struct via_spec *spec = codec->spec;
386 if (spec->kctls.list) {
387 struct snd_kcontrol_new *kctl = spec->kctls.list;
389 for (i = 0; i < spec->kctls.used; i++)
392 snd_array_free(&spec->kctls);
395 /* create input playback/capture controls for the given pin */
396 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
397 int type_idx, int idx, int mix_nid)
402 sprintf(name, "%s Playback Volume", ctlname);
403 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
404 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
407 sprintf(name, "%s Playback Switch", ctlname);
408 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
409 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
415 #define get_connection_index(codec, mux, nid) \
416 snd_hda_get_conn_index(codec, mux, nid, 0)
418 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
424 caps = get_wcaps(codec, nid);
425 if (dir == HDA_INPUT)
426 caps &= AC_WCAP_IN_AMP;
428 caps &= AC_WCAP_OUT_AMP;
431 if (query_amp_caps(codec, nid, dir) & mask)
436 #define have_mute(codec, nid, dir) \
437 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
439 /* enable/disable the output-route */
440 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
441 bool enable, bool force)
444 for (i = 0; i < path->depth; i++) {
446 int idx = path->idx[i];
448 if (i < path->depth - 1)
449 dst = path->path[i + 1];
452 if (enable && path->multi[i])
453 snd_hda_codec_write(codec, dst, 0,
454 AC_VERB_SET_CONNECT_SEL, idx);
456 && get_wcaps_type(get_wcaps(codec, src)) == AC_WID_AUD_OUT
457 && get_wcaps_type(get_wcaps(codec, dst)) == AC_WID_AUD_MIX)
459 if (have_mute(codec, dst, HDA_INPUT)) {
460 int val = enable ? AMP_IN_UNMUTE(idx) :
462 snd_hda_codec_write(codec, dst, 0,
463 AC_VERB_SET_AMP_GAIN_MUTE, val);
465 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
467 if (have_mute(codec, src, HDA_OUTPUT)) {
468 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
469 snd_hda_codec_write(codec, src, 0,
470 AC_VERB_SET_AMP_GAIN_MUTE, val);
475 /* set the given pin as output */
476 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
481 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
483 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
484 snd_hda_codec_write(codec, pin, 0,
485 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
488 static void via_auto_init_output(struct hda_codec *codec,
489 struct nid_path *path, int pin_type,
492 struct via_spec *spec = codec->spec;
494 hda_nid_t pin, nid, pre_nid;
499 pin = path->path[path->depth - 1];
501 init_output_pin(codec, pin, pin_type);
502 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
503 if (caps & AC_AMPCAP_MUTE) {
505 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
506 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
510 activate_output_path(codec, path, true, force);
512 /* initialize the AA-path */
513 if (!spec->aa_mix_nid)
515 for (i = path->depth - 1; i > 0; i--) {
517 pre_nid = path->path[i - 1];
518 idx = get_connection_index(codec, nid, spec->aa_mix_nid);
520 if (have_mute(codec, nid, HDA_INPUT)) {
521 snd_hda_codec_write(codec, nid, 0,
522 AC_VERB_SET_AMP_GAIN_MUTE,
524 if (pre_nid == spec->multiout.dac_nids[0]) {
525 num = snd_hda_get_conn_list(codec, nid,
527 for (j = 0; j < num; j++) {
530 snd_hda_codec_write(codec,
532 AC_VERB_SET_AMP_GAIN_MUTE,
542 static void via_auto_init_multi_out(struct hda_codec *codec)
544 struct via_spec *spec = codec->spec;
547 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++)
548 via_auto_init_output(codec, &spec->out_path[i], PIN_OUT, true);
551 static void via_auto_init_hp_out(struct hda_codec *codec)
553 struct via_spec *spec = codec->spec;
555 if (!spec->hp_dac_nid) {
556 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true);
559 if (spec->hp_independent_mode) {
560 activate_output_path(codec, &spec->hp_dep_path, false, false);
561 via_auto_init_output(codec, &spec->hp_path, PIN_HP, true);
563 activate_output_path(codec, &spec->hp_path, false, false);
564 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true);
568 static void via_auto_init_speaker_out(struct hda_codec *codec)
570 struct via_spec *spec = codec->spec;
572 if (spec->autocfg.speaker_outs)
573 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT, true);
576 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
578 static void via_auto_init_analog_input(struct hda_codec *codec)
580 struct via_spec *spec = codec->spec;
581 const struct auto_pin_cfg *cfg = &spec->autocfg;
582 hda_nid_t conn[HDA_MAX_CONNECTIONS];
587 for (i = 0; i < spec->num_adc_nids; i++) {
588 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
589 AC_VERB_SET_AMP_GAIN_MUTE,
594 for (i = 0; i < cfg->num_inputs; i++) {
595 hda_nid_t nid = cfg->inputs[i].pin;
596 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
598 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
602 snd_hda_codec_write(codec, nid, 0,
603 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
607 for (i = 0; i < spec->num_adc_nids; i++) {
608 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
609 if (spec->mux_nids[adc_idx]) {
610 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
611 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
612 AC_VERB_SET_CONNECT_SEL,
615 if (spec->dyn_adc_switch)
616 break; /* only one input-src */
620 if (!spec->aa_mix_nid)
622 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
624 for (i = 0; i < num_conns; i++) {
625 unsigned int caps = get_wcaps(codec, conn[i]);
626 if (get_wcaps_type(caps) == AC_WID_PIN)
627 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
628 AC_VERB_SET_AMP_GAIN_MUTE,
633 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
634 unsigned int *affected_parm)
637 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
638 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
639 >> AC_DEFCFG_MISC_SHIFT
640 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
641 struct via_spec *spec = codec->spec;
642 unsigned present = 0;
644 no_presence |= spec->no_pin_power_ctl;
646 present = snd_hda_jack_detect(codec, nid);
647 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
648 || ((no_presence || present)
649 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
650 *affected_parm = AC_PWRST_D0; /* if it's connected */
655 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
658 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_info *uinfo)
661 static const char * const texts[] = {
662 "Disabled", "Enabled"
665 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
667 uinfo->value.enumerated.items = 2;
668 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
669 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
670 strcpy(uinfo->value.enumerated.name,
671 texts[uinfo->value.enumerated.item]);
675 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_value *ucontrol)
678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679 struct via_spec *spec = codec->spec;
680 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
684 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
685 struct snd_ctl_elem_value *ucontrol)
687 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
688 struct via_spec *spec = codec->spec;
689 unsigned int val = !ucontrol->value.enumerated.item[0];
691 if (val == spec->no_pin_power_ctl)
693 spec->no_pin_power_ctl = val;
694 set_widgets_power_state(codec);
698 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
699 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
700 .name = "Dynamic Power-Control",
701 .info = via_pin_power_ctl_info,
702 .get = via_pin_power_ctl_get,
703 .put = via_pin_power_ctl_put,
707 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
708 struct snd_ctl_elem_info *uinfo)
710 static const char * const texts[] = { "OFF", "ON" };
712 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
714 uinfo->value.enumerated.items = 2;
715 if (uinfo->value.enumerated.item >= 2)
716 uinfo->value.enumerated.item = 1;
717 strcpy(uinfo->value.enumerated.name,
718 texts[uinfo->value.enumerated.item]);
722 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
723 struct snd_ctl_elem_value *ucontrol)
725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726 struct via_spec *spec = codec->spec;
728 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
732 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
733 struct snd_ctl_elem_value *ucontrol)
735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
736 struct via_spec *spec = codec->spec;
739 /* no independent-hp status change during PCM playback is running */
740 if (spec->num_active_streams)
743 cur = !!ucontrol->value.enumerated.item[0];
744 if (spec->hp_independent_mode == cur)
746 spec->hp_independent_mode = cur;
748 activate_output_path(codec, &spec->hp_dep_path, false, false);
749 activate_output_path(codec, &spec->hp_path, true, false);
750 if (spec->hp_indep_shared)
751 activate_output_path(codec, &spec->out_path[HDA_SIDE],
754 activate_output_path(codec, &spec->hp_path, false, false);
755 activate_output_path(codec, &spec->hp_dep_path, true, false);
756 if (spec->hp_indep_shared)
757 activate_output_path(codec, &spec->out_path[HDA_SIDE],
761 /* update jack power state */
762 set_widgets_power_state(codec);
766 static const struct snd_kcontrol_new via_hp_mixer = {
767 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
768 .name = "Independent HP",
769 .info = via_independent_hp_info,
770 .get = via_independent_hp_get,
771 .put = via_independent_hp_put,
774 static int via_hp_build(struct hda_codec *codec)
776 struct via_spec *spec = codec->spec;
777 struct snd_kcontrol_new *knew;
780 nid = spec->autocfg.hp_pins[0];
781 knew = via_clone_control(spec, &via_hp_mixer);
785 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
790 static void notify_aa_path_ctls(struct hda_codec *codec)
792 struct via_spec *spec = codec->spec;
795 for (i = 0; i < spec->smart51_nums; i++) {
796 struct snd_kcontrol *ctl;
797 struct snd_ctl_elem_id id;
798 memset(&id, 0, sizeof(id));
799 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
800 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
801 ctl = snd_hda_find_mixer_ctl(codec, id.name);
803 snd_ctl_notify(codec->bus->card,
804 SNDRV_CTL_EVENT_MASK_VALUE,
809 static void mute_aa_path(struct hda_codec *codec, int mute)
811 struct via_spec *spec = codec->spec;
812 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
815 /* check AA path's mute status */
816 for (i = 0; i < spec->smart51_nums; i++) {
817 if (spec->smart51_idxs[i] < 0)
819 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
820 HDA_INPUT, spec->smart51_idxs[i],
825 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
827 struct via_spec *spec = codec->spec;
830 for (i = 0; i < spec->smart51_nums; i++)
831 if (spec->smart51_pins[i] == pin)
836 static int via_smart51_get(struct snd_kcontrol *kcontrol,
837 struct snd_ctl_elem_value *ucontrol)
839 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
840 struct via_spec *spec = codec->spec;
842 *ucontrol->value.integer.value = spec->smart51_enabled;
846 static int via_smart51_put(struct snd_kcontrol *kcontrol,
847 struct snd_ctl_elem_value *ucontrol)
849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
850 struct via_spec *spec = codec->spec;
851 int out_in = *ucontrol->value.integer.value
852 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
855 for (i = 0; i < spec->smart51_nums; i++) {
856 hda_nid_t nid = spec->smart51_pins[i];
859 parm = snd_hda_codec_read(codec, nid, 0,
860 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
861 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
863 snd_hda_codec_write(codec, nid, 0,
864 AC_VERB_SET_PIN_WIDGET_CONTROL,
866 if (out_in == AC_PINCTL_OUT_EN) {
867 mute_aa_path(codec, 1);
868 notify_aa_path_ctls(codec);
871 spec->smart51_enabled = *ucontrol->value.integer.value;
872 set_widgets_power_state(codec);
876 static const struct snd_kcontrol_new via_smart51_mixer = {
877 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
880 .info = snd_ctl_boolean_mono_info,
881 .get = via_smart51_get,
882 .put = via_smart51_put,
885 static int via_smart51_build(struct hda_codec *codec)
887 struct via_spec *spec = codec->spec;
889 if (!spec->smart51_nums)
891 if (!via_clone_control(spec, &via_smart51_mixer))
896 /* check AA path's mute status */
897 static bool is_aa_path_mute(struct hda_codec *codec)
899 struct via_spec *spec = codec->spec;
900 const struct hda_amp_list *p;
903 for (i = 0; i < spec->num_loopbacks; i++) {
904 p = &spec->loopback_list[i];
905 for (ch = 0; ch < 2; ch++) {
906 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
908 if (!(v & HDA_AMP_MUTE) && v > 0)
915 /* enter/exit analog low-current mode */
916 static void analog_low_current_mode(struct hda_codec *codec)
918 struct via_spec *spec = codec->spec;
920 unsigned int verb, parm;
922 enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0);
924 /* decide low current mode's verb & parameter */
925 switch (spec->codec_type) {
929 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
935 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
939 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
945 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
948 return; /* other codecs are not supported */
951 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
955 * generic initialization of ADC, input mixers and output mixers
957 static const struct hda_verb vt1708_init_verbs[] = {
958 /* power down jack detect function */
963 static void set_stream_active(struct hda_codec *codec, bool active)
965 struct via_spec *spec = codec->spec;
968 spec->num_active_streams++;
970 spec->num_active_streams--;
971 analog_low_current_mode(codec);
974 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
975 struct hda_codec *codec,
976 struct snd_pcm_substream *substream)
978 struct via_spec *spec = codec->spec;
979 const struct auto_pin_cfg *cfg = &spec->autocfg;
982 spec->multiout.hp_nid = 0;
983 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
984 if (!spec->hp_independent_mode) {
985 if (!spec->hp_indep_shared)
986 spec->multiout.hp_nid = spec->hp_dac_nid;
988 if (spec->hp_indep_shared)
989 spec->multiout.num_dacs = cfg->line_outs - 1;
991 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
992 set_stream_active(codec, true);
993 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
996 spec->multiout.hp_nid = 0;
997 set_stream_active(codec, false);
1003 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1004 struct hda_codec *codec,
1005 struct snd_pcm_substream *substream)
1007 struct via_spec *spec = codec->spec;
1009 spec->multiout.hp_nid = 0;
1010 set_stream_active(codec, false);
1014 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1015 struct hda_codec *codec,
1016 struct snd_pcm_substream *substream)
1018 struct via_spec *spec = codec->spec;
1020 if (snd_BUG_ON(!spec->hp_dac_nid))
1022 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1024 set_stream_active(codec, true);
1028 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1029 struct hda_codec *codec,
1030 struct snd_pcm_substream *substream)
1032 set_stream_active(codec, false);
1036 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1037 struct hda_codec *codec,
1038 unsigned int stream_tag,
1039 unsigned int format,
1040 struct snd_pcm_substream *substream)
1042 struct via_spec *spec = codec->spec;
1044 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1046 vt1708_start_hp_work(spec);
1050 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1051 struct hda_codec *codec,
1052 unsigned int stream_tag,
1053 unsigned int format,
1054 struct snd_pcm_substream *substream)
1056 struct via_spec *spec = codec->spec;
1058 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1059 stream_tag, 0, format);
1060 vt1708_start_hp_work(spec);
1064 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1065 struct hda_codec *codec,
1066 struct snd_pcm_substream *substream)
1068 struct via_spec *spec = codec->spec;
1070 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1071 vt1708_stop_hp_work(spec);
1075 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1076 struct hda_codec *codec,
1077 struct snd_pcm_substream *substream)
1079 struct via_spec *spec = codec->spec;
1081 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1082 vt1708_stop_hp_work(spec);
1089 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1090 struct hda_codec *codec,
1091 struct snd_pcm_substream *substream)
1093 struct via_spec *spec = codec->spec;
1094 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1097 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1098 struct hda_codec *codec,
1099 struct snd_pcm_substream *substream)
1101 struct via_spec *spec = codec->spec;
1102 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1105 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1106 struct hda_codec *codec,
1107 unsigned int stream_tag,
1108 unsigned int format,
1109 struct snd_pcm_substream *substream)
1111 struct via_spec *spec = codec->spec;
1112 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1113 stream_tag, format, substream);
1116 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1117 struct hda_codec *codec,
1118 struct snd_pcm_substream *substream)
1120 struct via_spec *spec = codec->spec;
1121 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1128 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1129 struct hda_codec *codec,
1130 unsigned int stream_tag,
1131 unsigned int format,
1132 struct snd_pcm_substream *substream)
1134 struct via_spec *spec = codec->spec;
1136 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1137 stream_tag, 0, format);
1141 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1142 struct hda_codec *codec,
1143 struct snd_pcm_substream *substream)
1145 struct via_spec *spec = codec->spec;
1146 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1150 /* analog capture with dynamic ADC switching */
1151 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1152 struct hda_codec *codec,
1153 unsigned int stream_tag,
1154 unsigned int format,
1155 struct snd_pcm_substream *substream)
1157 struct via_spec *spec = codec->spec;
1158 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1160 spec->cur_adc = spec->adc_nids[adc_idx];
1161 spec->cur_adc_stream_tag = stream_tag;
1162 spec->cur_adc_format = format;
1163 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1167 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1168 struct hda_codec *codec,
1169 struct snd_pcm_substream *substream)
1171 struct via_spec *spec = codec->spec;
1173 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1178 /* re-setup the stream if running; called from input-src put */
1179 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1181 struct via_spec *spec = codec->spec;
1182 int adc_idx = spec->inputs[cur].adc_idx;
1183 hda_nid_t adc = spec->adc_nids[adc_idx];
1185 if (spec->cur_adc && spec->cur_adc != adc) {
1186 /* stream is running, let's swap the current ADC */
1187 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1188 spec->cur_adc = adc;
1189 snd_hda_codec_setup_stream(codec, adc,
1190 spec->cur_adc_stream_tag, 0,
1191 spec->cur_adc_format);
1197 static const struct hda_pcm_stream via_pcm_analog_playback = {
1201 /* NID is set in via_build_pcms */
1203 .open = via_playback_multi_pcm_open,
1204 .close = via_playback_multi_pcm_close,
1205 .prepare = via_playback_multi_pcm_prepare,
1206 .cleanup = via_playback_multi_pcm_cleanup
1210 static const struct hda_pcm_stream via_pcm_hp_playback = {
1214 /* NID is set in via_build_pcms */
1216 .open = via_playback_hp_pcm_open,
1217 .close = via_playback_hp_pcm_close,
1218 .prepare = via_playback_hp_pcm_prepare,
1219 .cleanup = via_playback_hp_pcm_cleanup
1223 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1227 /* NID is set in via_build_pcms */
1228 /* We got noisy outputs on the right channel on VT1708 when
1229 * 24bit samples are used. Until any workaround is found,
1230 * disable the 24bit format, so far.
1232 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1234 .open = via_playback_multi_pcm_open,
1235 .close = via_playback_multi_pcm_close,
1236 .prepare = via_playback_multi_pcm_prepare,
1237 .cleanup = via_playback_multi_pcm_cleanup
1241 static const struct hda_pcm_stream via_pcm_analog_capture = {
1242 .substreams = 1, /* will be changed in via_build_pcms() */
1245 /* NID is set in via_build_pcms */
1247 .prepare = via_capture_pcm_prepare,
1248 .cleanup = via_capture_pcm_cleanup
1252 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1256 /* NID is set in via_build_pcms */
1258 .prepare = via_dyn_adc_capture_pcm_prepare,
1259 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1263 static const struct hda_pcm_stream via_pcm_digital_playback = {
1267 /* NID is set in via_build_pcms */
1269 .open = via_dig_playback_pcm_open,
1270 .close = via_dig_playback_pcm_close,
1271 .prepare = via_dig_playback_pcm_prepare,
1272 .cleanup = via_dig_playback_pcm_cleanup
1276 static const struct hda_pcm_stream via_pcm_digital_capture = {
1283 * slave controls for virtual master
1285 static const char * const via_slave_vols[] = {
1286 "Front Playback Volume",
1287 "Surround Playback Volume",
1288 "Center Playback Volume",
1289 "LFE Playback Volume",
1290 "Side Playback Volume",
1291 "Headphone Playback Volume",
1292 "Speaker Playback Volume",
1296 static const char * const via_slave_sws[] = {
1297 "Front Playback Switch",
1298 "Surround Playback Switch",
1299 "Center Playback Switch",
1300 "LFE Playback Switch",
1301 "Side Playback Switch",
1302 "Headphone Playback Switch",
1303 "Speaker Playback Switch",
1307 static int via_build_controls(struct hda_codec *codec)
1309 struct via_spec *spec = codec->spec;
1310 struct snd_kcontrol *kctl;
1313 if (spec->set_widgets_power_state)
1314 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1317 for (i = 0; i < spec->num_mixers; i++) {
1318 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1323 if (spec->multiout.dig_out_nid) {
1324 err = snd_hda_create_spdif_out_ctls(codec,
1325 spec->multiout.dig_out_nid,
1326 spec->multiout.dig_out_nid);
1329 err = snd_hda_create_spdif_share_sw(codec,
1333 spec->multiout.share_spdif = 1;
1335 if (spec->dig_in_nid) {
1336 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1341 /* if we have no master control, let's create it */
1342 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1343 unsigned int vmaster_tlv[4];
1344 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1345 HDA_OUTPUT, vmaster_tlv);
1346 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1347 vmaster_tlv, via_slave_vols);
1351 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1352 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1353 NULL, via_slave_sws);
1358 /* assign Capture Source enums to NID */
1359 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1360 for (i = 0; kctl && i < kctl->count; i++) {
1361 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1366 /* init power states */
1367 set_widgets_power_state(codec);
1368 analog_low_current_mode(codec);
1370 via_free_kctls(codec); /* no longer needed */
1374 static int via_build_pcms(struct hda_codec *codec)
1376 struct via_spec *spec = codec->spec;
1377 struct hda_pcm *info = spec->pcm_rec;
1379 codec->num_pcms = 1;
1380 codec->pcm_info = info;
1382 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1383 "%s Analog", codec->chip_name);
1384 info->name = spec->stream_name_analog;
1386 if (!spec->stream_analog_playback)
1387 spec->stream_analog_playback = &via_pcm_analog_playback;
1388 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1389 *spec->stream_analog_playback;
1390 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1391 spec->multiout.dac_nids[0];
1392 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1393 spec->multiout.max_channels;
1395 if (!spec->stream_analog_capture) {
1396 if (spec->dyn_adc_switch)
1397 spec->stream_analog_capture =
1398 &via_pcm_dyn_adc_analog_capture;
1400 spec->stream_analog_capture = &via_pcm_analog_capture;
1402 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1403 *spec->stream_analog_capture;
1404 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1405 if (!spec->dyn_adc_switch)
1406 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1409 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1412 snprintf(spec->stream_name_digital,
1413 sizeof(spec->stream_name_digital),
1414 "%s Digital", codec->chip_name);
1415 info->name = spec->stream_name_digital;
1416 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1417 if (spec->multiout.dig_out_nid) {
1418 if (!spec->stream_digital_playback)
1419 spec->stream_digital_playback =
1420 &via_pcm_digital_playback;
1421 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1422 *spec->stream_digital_playback;
1423 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1424 spec->multiout.dig_out_nid;
1426 if (spec->dig_in_nid) {
1427 if (!spec->stream_digital_capture)
1428 spec->stream_digital_capture =
1429 &via_pcm_digital_capture;
1430 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1431 *spec->stream_digital_capture;
1432 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1437 if (spec->hp_dac_nid) {
1440 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1441 "%s HP", codec->chip_name);
1442 info->name = spec->stream_name_hp;
1443 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1444 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1450 static void via_free(struct hda_codec *codec)
1452 struct via_spec *spec = codec->spec;
1457 via_free_kctls(codec);
1458 vt1708_stop_hp_work(spec);
1459 kfree(spec->bind_cap_vol);
1460 kfree(spec->bind_cap_sw);
1464 /* mute/unmute outputs */
1465 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1466 hda_nid_t *pins, bool mute)
1469 for (i = 0; i < num_pins; i++)
1470 snd_hda_codec_write(codec, pins[i], 0,
1471 AC_VERB_SET_PIN_WIDGET_CONTROL,
1472 mute ? 0 : PIN_OUT);
1475 /* mute internal speaker if line-out is plugged */
1476 static void via_line_automute(struct hda_codec *codec, int present)
1478 struct via_spec *spec = codec->spec;
1480 if (!spec->autocfg.speaker_outs)
1483 present = snd_hda_jack_detect(codec,
1484 spec->autocfg.line_out_pins[0]);
1485 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1486 spec->autocfg.speaker_pins,
1490 /* mute internal speaker if HP is plugged */
1491 static void via_hp_automute(struct hda_codec *codec)
1494 struct via_spec *spec = codec->spec;
1496 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) {
1498 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1499 if (spec->smart51_enabled)
1500 nums = spec->autocfg.line_outs + spec->smart51_nums;
1502 nums = spec->autocfg.line_outs;
1503 toggle_output_mutes(codec, nums,
1504 spec->autocfg.line_out_pins,
1507 via_line_automute(codec, present);
1510 static void via_gpio_control(struct hda_codec *codec)
1512 unsigned int gpio_data;
1513 unsigned int vol_counter;
1515 unsigned int master_vol;
1517 struct via_spec *spec = codec->spec;
1519 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1520 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1522 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1523 0xF84, 0) & 0x3F0000) >> 16;
1525 vol = vol_counter & 0x1F;
1526 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1527 AC_VERB_GET_AMP_GAIN_MUTE,
1530 if (gpio_data == 0x02) {
1531 /* unmute line out */
1532 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1533 AC_VERB_SET_PIN_WIDGET_CONTROL,
1535 if (vol_counter & 0x20) {
1536 /* decrease volume */
1537 if (vol > master_vol)
1539 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1543 /* increase volume */
1544 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1546 ((master_vol+vol) > 0x2A) ? 0x2A :
1549 } else if (!(gpio_data & 0x02)) {
1551 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1552 AC_VERB_SET_PIN_WIDGET_CONTROL,
1557 /* unsolicited event for jack sensing */
1558 static void via_unsol_event(struct hda_codec *codec,
1563 if (res & VIA_JACK_EVENT)
1564 set_widgets_power_state(codec);
1566 res &= ~VIA_JACK_EVENT;
1568 if (res == VIA_HP_EVENT)
1569 via_hp_automute(codec);
1570 else if (res == VIA_GPIO_EVENT)
1571 via_gpio_control(codec);
1572 else if (res == VIA_LINE_EVENT)
1573 via_line_automute(codec, false);
1576 #ifdef SND_HDA_NEEDS_RESUME
1577 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1579 struct via_spec *spec = codec->spec;
1580 vt1708_stop_hp_work(spec);
1585 #ifdef CONFIG_SND_HDA_POWER_SAVE
1586 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1588 struct via_spec *spec = codec->spec;
1589 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1596 static int via_init(struct hda_codec *codec);
1598 static const struct hda_codec_ops via_patch_ops = {
1599 .build_controls = via_build_controls,
1600 .build_pcms = via_build_pcms,
1603 .unsol_event = via_unsol_event,
1604 #ifdef SND_HDA_NEEDS_RESUME
1605 .suspend = via_suspend,
1607 #ifdef CONFIG_SND_HDA_POWER_SAVE
1608 .check_power_status = via_check_power_status,
1612 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1614 struct via_spec *spec = codec->spec;
1617 for (i = 0; i < spec->multiout.num_dacs; i++) {
1618 if (spec->multiout.dac_nids[i] == dac)
1621 if (spec->hp_dac_nid == dac)
1626 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1627 hda_nid_t target_dac, struct nid_path *path,
1628 int depth, int wid_type)
1633 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1634 for (i = 0; i < nums; i++) {
1635 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1637 if (conn[i] == target_dac || is_empty_dac(codec, conn[i]))
1640 if (depth >= MAX_NID_PATH_DEPTH)
1642 for (i = 0; i < nums; i++) {
1644 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1645 if (type == AC_WID_AUD_OUT ||
1646 (wid_type != -1 && type != wid_type))
1648 if (__parse_output_path(codec, conn[i], target_dac,
1649 path, depth + 1, AC_WID_AUD_SEL))
1655 path->path[path->depth] = conn[i];
1656 path->idx[path->depth] = i;
1657 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1658 path->multi[path->depth] = 1;
1663 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1664 hda_nid_t target_dac, struct nid_path *path)
1666 if (__parse_output_path(codec, nid, target_dac, path, 1, -1)) {
1667 path->path[path->depth] = nid;
1674 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1676 struct via_spec *spec = codec->spec;
1677 const struct auto_pin_cfg *cfg = &spec->autocfg;
1681 spec->multiout.dac_nids = spec->private_dac_nids;
1682 spec->multiout.num_dacs = cfg->line_outs;
1683 for (i = 0; i < cfg->line_outs; i++) {
1684 nid = cfg->line_out_pins[i];
1687 if (parse_output_path(codec, nid, 0, &spec->out_path[i]))
1688 spec->private_dac_nids[i] = spec->out_path[i].path[0];
1693 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1694 int chs, bool check_dac, struct nid_path *path)
1696 struct via_spec *spec = codec->spec;
1698 hda_nid_t dac, pin, sel, nid;
1701 dac = check_dac ? path->path[0] : 0;
1702 pin = path->path[path->depth - 1];
1703 sel = path->depth > 1 ? path->path[1] : 0;
1705 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1707 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1709 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1714 sprintf(name, "%s Playback Volume", pfx);
1715 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1716 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1719 path->vol_ctl = nid;
1722 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1724 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1726 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1731 sprintf(name, "%s Playback Switch", pfx);
1732 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1733 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1736 path->mute_ctl = nid;
1741 static void mangle_smart51(struct hda_codec *codec)
1743 struct via_spec *spec = codec->spec;
1744 struct auto_pin_cfg *cfg = &spec->autocfg;
1745 struct auto_pin_cfg_item *ins = cfg->inputs;
1746 int i, j, nums, attr;
1747 int pins[AUTO_CFG_MAX_INS];
1749 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1751 for (i = 0; i < cfg->num_inputs; i++) {
1753 if (ins[i].type > AUTO_PIN_LINE_IN)
1755 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1756 if (snd_hda_get_input_pin_attr(def) != attr)
1758 for (j = 0; j < nums; j++)
1759 if (ins[pins[j]].type < ins[i].type) {
1760 memmove(pins + j + 1, pins + j,
1761 (nums - j - 1) * sizeof(int));
1767 if (cfg->line_outs + nums < 3)
1769 for (i = 0; i < nums; i++) {
1770 hda_nid_t pin = ins[pins[i]].pin;
1771 spec->smart51_pins[spec->smart51_nums++] = pin;
1772 cfg->line_out_pins[cfg->line_outs++] = pin;
1773 if (cfg->line_outs == 3)
1780 /* add playback controls from the parsed DAC table */
1781 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1783 struct via_spec *spec = codec->spec;
1784 struct auto_pin_cfg *cfg = &spec->autocfg;
1785 static const char * const chname[4] = {
1786 "Front", "Surround", "C/LFE", "Side"
1792 old_line_outs = cfg->line_outs;
1793 if (cfg->line_outs == 1)
1794 mangle_smart51(codec);
1796 err = via_auto_fill_dac_nids(codec);
1800 for (i = 0; i < cfg->line_outs; i++) {
1802 pin = cfg->line_out_pins[i];
1803 dac = spec->multiout.dac_nids[i];
1806 if (i == HDA_CLFE) {
1807 err = create_ch_ctls(codec, "Center", 1, true,
1808 &spec->out_path[i]);
1811 err = create_ch_ctls(codec, "LFE", 2, true,
1812 &spec->out_path[i]);
1816 const char *pfx = chname[i];
1817 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1818 cfg->line_outs == 1)
1820 err = create_ch_ctls(codec, pfx, 3, true,
1821 &spec->out_path[i]);
1827 idx = get_connection_index(codec, spec->aa_mix_nid,
1828 spec->multiout.dac_nids[0]);
1829 if (idx < 0 && spec->dac_mixer_idx)
1830 idx = spec->dac_mixer_idx;
1832 /* add control to mixer */
1833 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1834 "PCM Playback Volume",
1835 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1839 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1840 "PCM Playback Switch",
1841 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1847 cfg->line_outs = old_line_outs;
1852 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1854 struct via_spec *spec = codec->spec;
1855 struct nid_path *path;
1861 if (parse_output_path(codec, pin, 0, &spec->hp_path))
1862 spec->hp_dac_nid = spec->hp_path.path[0];
1863 else if (spec->multiout.dac_nids[HDA_SIDE] &&
1864 parse_output_path(codec, pin,
1865 spec->multiout.dac_nids[HDA_SIDE],
1867 spec->hp_dac_nid = spec->hp_path.path[0];
1868 spec->hp_indep_shared = true;
1871 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1872 &spec->hp_dep_path) &&
1876 if (spec->hp_dac_nid && !spec->hp_indep_shared)
1877 path = &spec->hp_path;
1879 path = &spec->hp_dep_path;
1880 err = create_ch_ctls(codec, "Headphone", 3, false, path);
1883 if (spec->hp_dac_nid) {
1884 spec->hp_dep_path.vol_ctl = spec->hp_path.vol_ctl;
1885 spec->hp_dep_path.mute_ctl = spec->hp_path.mute_ctl;
1891 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1893 struct via_spec *spec = codec->spec;
1896 pin = spec->autocfg.speaker_pins[0];
1897 if (!spec->autocfg.speaker_outs || !pin)
1900 if (parse_output_path(codec, pin, 0, &spec->speaker_path)) {
1901 dac = spec->speaker_path.path[0];
1902 spec->multiout.extra_out_nid[0] = dac;
1903 return create_ch_ctls(codec, "Speaker", 3, true,
1904 &spec->speaker_path);
1906 if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1907 &spec->speaker_path))
1908 return create_ch_ctls(codec, "Speaker", 3, false,
1909 &spec->speaker_path);
1915 static int via_fill_adcs(struct hda_codec *codec)
1917 struct via_spec *spec = codec->spec;
1918 hda_nid_t nid = codec->start_nid;
1921 for (i = 0; i < codec->num_nodes; i++, nid++) {
1922 unsigned int wcaps = get_wcaps(codec, nid);
1923 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1925 if (wcaps & AC_WCAP_DIGITAL)
1927 if (!(wcaps & AC_WCAP_CONN_LIST))
1929 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1931 spec->adc_nids[spec->num_adc_nids++] = nid;
1936 /* input-src control */
1937 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1938 struct snd_ctl_elem_info *uinfo)
1940 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1941 struct via_spec *spec = codec->spec;
1943 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1945 uinfo->value.enumerated.items = spec->num_inputs;
1946 if (uinfo->value.enumerated.item >= spec->num_inputs)
1947 uinfo->value.enumerated.item = spec->num_inputs - 1;
1948 strcpy(uinfo->value.enumerated.name,
1949 spec->inputs[uinfo->value.enumerated.item].label);
1953 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1954 struct snd_ctl_elem_value *ucontrol)
1956 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1957 struct via_spec *spec = codec->spec;
1958 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1960 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
1964 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1965 struct snd_ctl_elem_value *ucontrol)
1967 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1968 struct via_spec *spec = codec->spec;
1969 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1973 cur = ucontrol->value.enumerated.item[0];
1974 if (cur < 0 || cur >= spec->num_inputs)
1976 if (spec->cur_mux[idx] == cur)
1978 spec->cur_mux[idx] = cur;
1979 if (spec->dyn_adc_switch) {
1980 int adc_idx = spec->inputs[cur].adc_idx;
1981 mux = spec->mux_nids[adc_idx];
1982 via_dyn_adc_pcm_resetup(codec, cur);
1984 mux = spec->mux_nids[idx];
1985 if (snd_BUG_ON(!mux))
1990 /* switch to D0 beofre change index */
1991 if (snd_hda_codec_read(codec, mux, 0,
1992 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1993 snd_hda_codec_write(codec, mux, 0,
1994 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1995 snd_hda_codec_write(codec, mux, 0,
1996 AC_VERB_SET_CONNECT_SEL,
1997 spec->inputs[cur].mux_idx);
2000 /* update jack power state */
2001 set_widgets_power_state(codec);
2005 static const struct snd_kcontrol_new via_input_src_ctl = {
2006 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2007 /* The multiple "Capture Source" controls confuse alsamixer
2008 * So call somewhat different..
2010 /* .name = "Capture Source", */
2011 .name = "Input Source",
2012 .info = via_mux_enum_info,
2013 .get = via_mux_enum_get,
2014 .put = via_mux_enum_put,
2017 static int create_input_src_ctls(struct hda_codec *codec, int count)
2019 struct via_spec *spec = codec->spec;
2020 struct snd_kcontrol_new *knew;
2022 if (spec->num_inputs <= 1 || !count)
2023 return 0; /* no need for single src */
2025 knew = via_clone_control(spec, &via_input_src_ctl);
2028 knew->count = count;
2032 /* add the powersave loopback-list entry */
2033 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2035 struct hda_amp_list *list;
2037 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2039 list = spec->loopback_list + spec->num_loopbacks;
2041 list->dir = HDA_INPUT;
2043 spec->num_loopbacks++;
2044 spec->loopback.amplist = spec->loopback_list;
2047 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2050 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2053 /* add the input-route to the given pin */
2054 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2056 struct via_spec *spec = codec->spec;
2059 spec->inputs[spec->num_inputs].adc_idx = -1;
2060 spec->inputs[spec->num_inputs].pin = pin;
2061 for (c = 0; c < spec->num_adc_nids; c++) {
2062 if (spec->mux_nids[c]) {
2063 idx = get_connection_index(codec, spec->mux_nids[c],
2067 spec->inputs[spec->num_inputs].mux_idx = idx;
2069 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2072 spec->inputs[spec->num_inputs].adc_idx = c;
2073 /* Can primary ADC satisfy all inputs? */
2074 if (!spec->dyn_adc_switch &&
2075 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2076 snd_printd(KERN_INFO
2077 "via: dynamic ADC switching enabled\n");
2078 spec->dyn_adc_switch = 1;
2085 static int get_mux_nids(struct hda_codec *codec);
2087 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2088 static int parse_analog_inputs(struct hda_codec *codec)
2090 struct via_spec *spec = codec->spec;
2091 const struct auto_pin_cfg *cfg = &spec->autocfg;
2094 err = via_fill_adcs(codec);
2097 err = get_mux_nids(codec);
2101 /* fill all input-routes */
2102 for (i = 0; i < cfg->num_inputs; i++) {
2103 if (add_input_route(codec, cfg->inputs[i].pin))
2104 spec->inputs[spec->num_inputs++].label =
2105 hda_get_autocfg_input_label(codec, cfg, i);
2108 /* check for internal loopback recording */
2109 if (spec->aa_mix_nid &&
2110 add_input_route(codec, spec->aa_mix_nid))
2111 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2116 /* create analog-loopback volume/switch controls */
2117 static int create_loopback_ctls(struct hda_codec *codec)
2119 struct via_spec *spec = codec->spec;
2120 const struct auto_pin_cfg *cfg = &spec->autocfg;
2121 const char *prev_label = NULL;
2125 if (!spec->aa_mix_nid)
2128 for (i = 0; i < cfg->num_inputs; i++) {
2129 hda_nid_t pin = cfg->inputs[i].pin;
2130 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2132 if (prev_label && !strcmp(label, prev_label))
2137 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2139 err = via_new_analog_input(spec, label, type_idx,
2140 idx, spec->aa_mix_nid);
2143 add_loopback_list(spec, spec->aa_mix_nid, idx);
2146 /* remember the label for smart51 control */
2147 for (j = 0; j < spec->smart51_nums; j++) {
2148 if (spec->smart51_pins[j] == pin) {
2149 spec->smart51_idxs[j] = idx;
2150 spec->smart51_labels[j] = label;
2158 /* create mic-boost controls (if present) */
2159 static int create_mic_boost_ctls(struct hda_codec *codec)
2161 struct via_spec *spec = codec->spec;
2162 const struct auto_pin_cfg *cfg = &spec->autocfg;
2165 for (i = 0; i < cfg->num_inputs; i++) {
2166 hda_nid_t pin = cfg->inputs[i].pin;
2171 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2173 caps = query_amp_caps(codec, pin, HDA_INPUT);
2174 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2176 label = hda_get_autocfg_input_label(codec, cfg, i);
2177 snprintf(name, sizeof(name), "%s Boost Volume", label);
2178 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2179 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2186 /* create capture and input-src controls for multiple streams */
2187 static int create_multi_adc_ctls(struct hda_codec *codec)
2189 struct via_spec *spec = codec->spec;
2192 /* create capture mixer elements */
2193 for (i = 0; i < spec->num_adc_nids; i++) {
2194 hda_nid_t adc = spec->adc_nids[i];
2195 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2196 "Capture Volume", i,
2197 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2201 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2202 "Capture Switch", i,
2203 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2209 /* input-source control */
2210 for (i = 0; i < spec->num_adc_nids; i++)
2211 if (!spec->mux_nids[i])
2213 err = create_input_src_ctls(codec, i);
2219 /* bind capture volume/switch */
2220 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2221 HDA_BIND_VOL("Capture Volume", 0);
2222 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2223 HDA_BIND_SW("Capture Switch", 0);
2225 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2226 struct hda_ctl_ops *ops)
2228 struct hda_bind_ctls *ctl;
2231 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2235 for (i = 0; i < spec->num_adc_nids; i++)
2237 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2242 /* create capture and input-src controls for dynamic ADC-switch case */
2243 static int create_dyn_adc_ctls(struct hda_codec *codec)
2245 struct via_spec *spec = codec->spec;
2246 struct snd_kcontrol_new *knew;
2249 /* set up the bind capture ctls */
2250 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2253 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2257 /* create capture mixer elements */
2258 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2261 knew->private_value = (long)spec->bind_cap_vol;
2263 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2266 knew->private_value = (long)spec->bind_cap_sw;
2268 /* input-source control */
2269 err = create_input_src_ctls(codec, 1);
2275 /* parse and create capture-related stuff */
2276 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2278 struct via_spec *spec = codec->spec;
2281 err = parse_analog_inputs(codec);
2284 if (spec->dyn_adc_switch)
2285 err = create_dyn_adc_ctls(codec);
2287 err = create_multi_adc_ctls(codec);
2290 err = create_loopback_ctls(codec);
2293 err = create_mic_boost_ctls(codec);
2299 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2301 unsigned int def_conf;
2302 unsigned char seqassoc;
2304 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2305 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2306 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2307 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2308 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2309 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2310 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2316 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2317 struct snd_ctl_elem_value *ucontrol)
2319 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2320 struct via_spec *spec = codec->spec;
2322 if (spec->codec_type != VT1708)
2324 spec->vt1708_jack_detect =
2325 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2326 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2330 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2331 struct snd_ctl_elem_value *ucontrol)
2333 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2334 struct via_spec *spec = codec->spec;
2337 if (spec->codec_type != VT1708)
2339 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2340 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2341 == !spec->vt1708_jack_detect;
2342 if (spec->vt1708_jack_detect) {
2343 mute_aa_path(codec, 1);
2344 notify_aa_path_ctls(codec);
2349 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2350 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2351 .name = "Jack Detect",
2353 .info = snd_ctl_boolean_mono_info,
2354 .get = vt1708_jack_detect_get,
2355 .put = vt1708_jack_detect_put,
2358 static void fill_dig_outs(struct hda_codec *codec);
2359 static void fill_dig_in(struct hda_codec *codec);
2361 static int via_parse_auto_config(struct hda_codec *codec)
2363 struct via_spec *spec = codec->spec;
2366 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2369 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2372 err = via_auto_create_multi_out_ctls(codec);
2375 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2378 err = via_auto_create_speaker_ctls(codec);
2381 err = via_auto_create_analog_input_ctls(codec);
2385 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2387 fill_dig_outs(codec);
2390 if (spec->kctls.list)
2391 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2394 if (spec->hp_dac_nid && spec->hp_dep_path.depth) {
2395 err = via_hp_build(codec);
2400 err = via_smart51_build(codec);
2404 /* assign slave outs */
2405 if (spec->slave_dig_outs[0])
2406 codec->slave_dig_outs = spec->slave_dig_outs;
2411 static void via_auto_init_dig_outs(struct hda_codec *codec)
2413 struct via_spec *spec = codec->spec;
2414 if (spec->multiout.dig_out_nid)
2415 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2416 if (spec->slave_dig_outs[0])
2417 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2420 static void via_auto_init_dig_in(struct hda_codec *codec)
2422 struct via_spec *spec = codec->spec;
2423 if (!spec->dig_in_nid)
2425 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2426 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2429 /* initialize the unsolicited events */
2430 static void via_auto_init_unsol_event(struct hda_codec *codec)
2432 struct via_spec *spec = codec->spec;
2433 struct auto_pin_cfg *cfg = &spec->autocfg;
2437 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2438 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2439 AC_VERB_SET_UNSOLICITED_ENABLE,
2440 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2442 if (cfg->speaker_pins[0])
2443 ev = VIA_LINE_EVENT;
2446 for (i = 0; i < cfg->line_outs; i++) {
2447 if (cfg->line_out_pins[i] &&
2448 is_jack_detectable(codec, cfg->line_out_pins[i]))
2449 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
2450 AC_VERB_SET_UNSOLICITED_ENABLE,
2451 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2454 for (i = 0; i < cfg->num_inputs; i++) {
2455 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2456 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2457 AC_VERB_SET_UNSOLICITED_ENABLE,
2458 AC_USRSP_EN | VIA_JACK_EVENT);
2462 static int via_init(struct hda_codec *codec)
2464 struct via_spec *spec = codec->spec;
2467 for (i = 0; i < spec->num_iverbs; i++)
2468 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2470 via_auto_init_multi_out(codec);
2471 via_auto_init_hp_out(codec);
2472 via_auto_init_speaker_out(codec);
2473 via_auto_init_analog_input(codec);
2474 via_auto_init_dig_outs(codec);
2475 via_auto_init_dig_in(codec);
2477 via_auto_init_unsol_event(codec);
2479 via_hp_automute(codec);
2480 via_line_automute(codec, false);
2485 static void vt1708_update_hp_jack_state(struct work_struct *work)
2487 struct via_spec *spec = container_of(work, struct via_spec,
2488 vt1708_hp_work.work);
2489 if (spec->codec_type != VT1708)
2491 /* if jack state toggled */
2492 if (spec->vt1708_hp_present
2493 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2494 spec->vt1708_hp_present ^= 1;
2495 via_hp_automute(spec->codec);
2497 vt1708_start_hp_work(spec);
2500 static int get_mux_nids(struct hda_codec *codec)
2502 struct via_spec *spec = codec->spec;
2503 hda_nid_t nid, conn[8];
2507 for (i = 0; i < spec->num_adc_nids; i++) {
2508 nid = spec->adc_nids[i];
2510 type = get_wcaps_type(get_wcaps(codec, nid));
2511 if (type == AC_WID_PIN)
2513 n = snd_hda_get_connections(codec, nid, conn,
2518 spec->mux_nids[i] = nid;
2527 static int patch_vt1708(struct hda_codec *codec)
2529 struct via_spec *spec;
2532 /* create a codec specific record */
2533 spec = via_new_spec(codec);
2537 spec->aa_mix_nid = 0x17;
2539 /* Add HP and CD pin config connect bit re-config action */
2540 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2541 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2543 /* automatic parse from the BIOS config */
2544 err = via_parse_auto_config(codec);
2550 /* add jack detect on/off control */
2551 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2554 /* disable 32bit format on VT1708 */
2555 if (codec->vendor_id == 0x11061708)
2556 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2558 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2560 codec->patch_ops = via_patch_ops;
2562 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2566 static int patch_vt1709(struct hda_codec *codec)
2568 struct via_spec *spec;
2571 /* create a codec specific record */
2572 spec = via_new_spec(codec);
2576 spec->aa_mix_nid = 0x18;
2578 err = via_parse_auto_config(codec);
2584 codec->patch_ops = via_patch_ops;
2589 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2591 struct via_spec *spec = codec->spec;
2595 if ((spec->codec_type != VT1708B_4CH) &&
2596 (codec->vendor_id != 0x11064397))
2599 /* SW0 (17h) = stereo mixer */
2601 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2602 == ((spec->codec_type == VT1708S) ? 5 : 0));
2604 /* PW 1/2/5 (1ah/1bh/1eh) */
2606 set_pin_power_state(codec, 0x1a, &parm);
2607 set_pin_power_state(codec, 0x1b, &parm);
2608 set_pin_power_state(codec, 0x1e, &parm);
2611 /* SW0 (17h), AIW 0/1 (13h/14h) */
2612 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2613 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2614 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2617 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2619 set_pin_power_state(codec, 0x19, &parm);
2620 if (spec->smart51_enabled)
2621 set_pin_power_state(codec, 0x1b, &parm);
2622 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2623 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2625 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2628 set_pin_power_state(codec, 0x22, &parm);
2629 if (spec->smart51_enabled)
2630 set_pin_power_state(codec, 0x1a, &parm);
2631 snd_hda_codec_write(codec, 0x26, 0,
2632 AC_VERB_SET_POWER_STATE, parm);
2633 snd_hda_codec_write(codec, 0x24, 0,
2634 AC_VERB_SET_POWER_STATE, parm);
2635 } else if (codec->vendor_id == 0x11064397) {
2636 /* PW7(23h), SW2(27h), AOW2(25h) */
2638 set_pin_power_state(codec, 0x23, &parm);
2639 if (spec->smart51_enabled)
2640 set_pin_power_state(codec, 0x1a, &parm);
2641 snd_hda_codec_write(codec, 0x27, 0,
2642 AC_VERB_SET_POWER_STATE, parm);
2643 snd_hda_codec_write(codec, 0x25, 0,
2644 AC_VERB_SET_POWER_STATE, parm);
2647 /* PW 3/4/7 (1ch/1dh/23h) */
2649 /* force to D0 for internal Speaker */
2650 set_pin_power_state(codec, 0x1c, &parm);
2651 set_pin_power_state(codec, 0x1d, &parm);
2653 set_pin_power_state(codec, 0x23, &parm);
2655 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2656 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2657 imux_is_smixer ? AC_PWRST_D0 : parm);
2658 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2660 snd_hda_codec_write(codec, 0x25, 0,
2661 AC_VERB_SET_POWER_STATE, parm);
2662 snd_hda_codec_write(codec, 0x27, 0,
2663 AC_VERB_SET_POWER_STATE, parm);
2664 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2665 snd_hda_codec_write(codec, 0x25, 0,
2666 AC_VERB_SET_POWER_STATE, parm);
2669 static int patch_vt1708S(struct hda_codec *codec);
2670 static int patch_vt1708B(struct hda_codec *codec)
2672 struct via_spec *spec;
2675 if (get_codec_type(codec) == VT1708BCE)
2676 return patch_vt1708S(codec);
2678 /* create a codec specific record */
2679 spec = via_new_spec(codec);
2683 spec->aa_mix_nid = 0x16;
2685 /* automatic parse from the BIOS config */
2686 err = via_parse_auto_config(codec);
2692 codec->patch_ops = via_patch_ops;
2694 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2699 /* Patch for VT1708S */
2700 static const struct hda_verb vt1708S_init_verbs[] = {
2701 /* Enable Mic Boost Volume backdoor */
2703 /* don't bybass mixer */
2708 /* fill out digital output widgets; one for master and one for slave outputs */
2709 static void fill_dig_outs(struct hda_codec *codec)
2711 struct via_spec *spec = codec->spec;
2714 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2718 nid = spec->autocfg.dig_out_pins[i];
2721 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2724 if (!spec->multiout.dig_out_nid)
2725 spec->multiout.dig_out_nid = nid;
2727 spec->slave_dig_outs[0] = nid;
2728 break; /* at most two dig outs */
2733 static void fill_dig_in(struct hda_codec *codec)
2735 struct via_spec *spec = codec->spec;
2739 if (!spec->autocfg.dig_in_pin)
2742 dig_nid = codec->start_nid;
2743 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2744 unsigned int wcaps = get_wcaps(codec, dig_nid);
2745 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2747 if (!(wcaps & AC_WCAP_DIGITAL))
2749 if (!(wcaps & AC_WCAP_CONN_LIST))
2751 err = get_connection_index(codec, dig_nid,
2752 spec->autocfg.dig_in_pin);
2754 spec->dig_in_nid = dig_nid;
2760 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2761 int offset, int num_steps, int step_size)
2763 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2764 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2765 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2766 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2767 (0 << AC_AMPCAP_MUTE_SHIFT));
2770 static int patch_vt1708S(struct hda_codec *codec)
2772 struct via_spec *spec;
2775 /* create a codec specific record */
2776 spec = via_new_spec(codec);
2780 spec->aa_mix_nid = 0x16;
2781 override_mic_boost(codec, 0x1a, 0, 3, 40);
2782 override_mic_boost(codec, 0x1e, 0, 3, 40);
2784 /* automatic parse from the BIOS config */
2785 err = via_parse_auto_config(codec);
2791 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2793 codec->patch_ops = via_patch_ops;
2795 /* correct names for VT1708BCE */
2796 if (get_codec_type(codec) == VT1708BCE) {
2797 kfree(codec->chip_name);
2798 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2799 snprintf(codec->bus->card->mixername,
2800 sizeof(codec->bus->card->mixername),
2801 "%s %s", codec->vendor_name, codec->chip_name);
2803 /* correct names for VT1705 */
2804 if (codec->vendor_id == 0x11064397) {
2805 kfree(codec->chip_name);
2806 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2807 snprintf(codec->bus->card->mixername,
2808 sizeof(codec->bus->card->mixername),
2809 "%s %s", codec->vendor_name, codec->chip_name);
2811 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2815 /* Patch for VT1702 */
2817 static const struct hda_verb vt1702_init_verbs[] = {
2825 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2827 int imux_is_smixer =
2828 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2831 /* PW 1/2/5 (14h/15h/18h) */
2833 set_pin_power_state(codec, 0x14, &parm);
2834 set_pin_power_state(codec, 0x15, &parm);
2835 set_pin_power_state(codec, 0x18, &parm);
2837 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2838 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2839 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2840 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2841 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2842 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2845 /* PW 3/4 (16h/17h) */
2847 set_pin_power_state(codec, 0x17, &parm);
2848 set_pin_power_state(codec, 0x16, &parm);
2849 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2850 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2851 imux_is_smixer ? AC_PWRST_D0 : parm);
2852 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2853 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2856 static int patch_vt1702(struct hda_codec *codec)
2858 struct via_spec *spec;
2861 /* create a codec specific record */
2862 spec = via_new_spec(codec);
2866 spec->aa_mix_nid = 0x1a;
2868 /* limit AA path volume to 0 dB */
2869 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2870 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2871 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2872 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2873 (1 << AC_AMPCAP_MUTE_SHIFT));
2875 /* automatic parse from the BIOS config */
2876 err = via_parse_auto_config(codec);
2882 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
2884 codec->patch_ops = via_patch_ops;
2886 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
2890 /* Patch for VT1718S */
2892 static const struct hda_verb vt1718S_init_verbs[] = {
2893 /* Enable MW0 adjust Gain 5 */
2895 /* Enable Boost Volume backdoor */
2901 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2903 struct via_spec *spec = codec->spec;
2906 /* MUX6 (1eh) = stereo mixer */
2908 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2910 /* PW 5/6/7 (29h/2ah/2bh) */
2912 set_pin_power_state(codec, 0x29, &parm);
2913 set_pin_power_state(codec, 0x2a, &parm);
2914 set_pin_power_state(codec, 0x2b, &parm);
2917 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2918 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2919 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2920 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2921 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2924 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2926 set_pin_power_state(codec, 0x27, &parm);
2927 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2928 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2930 /* PW2 (26h), AOW2 (ah) */
2932 set_pin_power_state(codec, 0x26, &parm);
2933 if (spec->smart51_enabled)
2934 set_pin_power_state(codec, 0x2b, &parm);
2935 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
2937 /* PW0 (24h), AOW0 (8h) */
2939 set_pin_power_state(codec, 0x24, &parm);
2940 if (!spec->hp_independent_mode) /* check for redirected HP */
2941 set_pin_power_state(codec, 0x28, &parm);
2942 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2943 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
2944 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
2945 imux_is_smixer ? AC_PWRST_D0 : parm);
2947 /* PW1 (25h), AOW1 (9h) */
2949 set_pin_power_state(codec, 0x25, &parm);
2950 if (spec->smart51_enabled)
2951 set_pin_power_state(codec, 0x2a, &parm);
2952 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
2954 if (spec->hp_independent_mode) {
2955 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
2957 set_pin_power_state(codec, 0x28, &parm);
2958 snd_hda_codec_write(codec, 0x1b, 0,
2959 AC_VERB_SET_POWER_STATE, parm);
2960 snd_hda_codec_write(codec, 0x34, 0,
2961 AC_VERB_SET_POWER_STATE, parm);
2962 snd_hda_codec_write(codec, 0xc, 0,
2963 AC_VERB_SET_POWER_STATE, parm);
2967 static int patch_vt1718S(struct hda_codec *codec)
2969 struct via_spec *spec;
2972 /* create a codec specific record */
2973 spec = via_new_spec(codec);
2977 spec->aa_mix_nid = 0x21;
2978 override_mic_boost(codec, 0x2b, 0, 3, 40);
2979 override_mic_boost(codec, 0x29, 0, 3, 40);
2980 spec->dac_mixer_idx = 5;
2982 /* automatic parse from the BIOS config */
2983 err = via_parse_auto_config(codec);
2989 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
2991 codec->patch_ops = via_patch_ops;
2993 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
2998 /* Patch for VT1716S */
3000 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3001 struct snd_ctl_elem_info *uinfo)
3003 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3005 uinfo->value.integer.min = 0;
3006 uinfo->value.integer.max = 1;
3010 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3011 struct snd_ctl_elem_value *ucontrol)
3013 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3016 index = snd_hda_codec_read(codec, 0x26, 0,
3017 AC_VERB_GET_CONNECT_SEL, 0);
3019 *ucontrol->value.integer.value = index;
3024 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3025 struct snd_ctl_elem_value *ucontrol)
3027 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3028 struct via_spec *spec = codec->spec;
3029 int index = *ucontrol->value.integer.value;
3031 snd_hda_codec_write(codec, 0x26, 0,
3032 AC_VERB_SET_CONNECT_SEL, index);
3033 spec->dmic_enabled = index;
3034 set_widgets_power_state(codec);
3038 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3039 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3041 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3042 .name = "Digital Mic Capture Switch",
3043 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3045 .info = vt1716s_dmic_info,
3046 .get = vt1716s_dmic_get,
3047 .put = vt1716s_dmic_put,
3053 /* mono-out mixer elements */
3054 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3055 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3059 static const struct hda_verb vt1716S_init_verbs[] = {
3060 /* Enable Boost Volume backdoor */
3062 /* don't bybass mixer */
3064 /* Enable mono output */
3069 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3071 struct via_spec *spec = codec->spec;
3074 unsigned int mono_out, present;
3075 /* SW0 (17h) = stereo mixer */
3077 (snd_hda_codec_read(codec, 0x17, 0,
3078 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3080 /* PW 1/2/5 (1ah/1bh/1eh) */
3082 set_pin_power_state(codec, 0x1a, &parm);
3083 set_pin_power_state(codec, 0x1b, &parm);
3084 set_pin_power_state(codec, 0x1e, &parm);
3087 /* SW0 (17h), AIW0(13h) */
3088 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3089 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3092 set_pin_power_state(codec, 0x1e, &parm);
3094 if (spec->dmic_enabled)
3095 set_pin_power_state(codec, 0x22, &parm);
3097 snd_hda_codec_write(codec, 0x22, 0,
3098 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3100 /* SW2(26h), AIW1(14h) */
3101 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3102 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3105 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3107 set_pin_power_state(codec, 0x19, &parm);
3108 /* Smart 5.1 PW2(1bh) */
3109 if (spec->smart51_enabled)
3110 set_pin_power_state(codec, 0x1b, &parm);
3111 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3112 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3114 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3116 set_pin_power_state(codec, 0x23, &parm);
3117 /* Smart 5.1 PW1(1ah) */
3118 if (spec->smart51_enabled)
3119 set_pin_power_state(codec, 0x1a, &parm);
3120 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3122 /* Smart 5.1 PW5(1eh) */
3123 if (spec->smart51_enabled)
3124 set_pin_power_state(codec, 0x1e, &parm);
3125 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3128 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3129 present = snd_hda_jack_detect(codec, 0x1c);
3134 present = snd_hda_jack_detect(codec, 0x1d);
3135 if (!spec->hp_independent_mode && present)
3140 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3141 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3142 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3143 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3145 /* PW 3/4 (1ch/1dh) */
3147 set_pin_power_state(codec, 0x1c, &parm);
3148 set_pin_power_state(codec, 0x1d, &parm);
3149 /* HP Independent Mode, power on AOW3 */
3150 if (spec->hp_independent_mode)
3151 snd_hda_codec_write(codec, 0x25, 0,
3152 AC_VERB_SET_POWER_STATE, parm);
3154 /* force to D0 for internal Speaker */
3155 /* MW0 (16h), AOW0 (10h) */
3156 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3157 imux_is_smixer ? AC_PWRST_D0 : parm);
3158 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3159 mono_out ? AC_PWRST_D0 : parm);
3162 static int patch_vt1716S(struct hda_codec *codec)
3164 struct via_spec *spec;
3167 /* create a codec specific record */
3168 spec = via_new_spec(codec);
3172 spec->aa_mix_nid = 0x16;
3173 override_mic_boost(codec, 0x1a, 0, 3, 40);
3174 override_mic_boost(codec, 0x1e, 0, 3, 40);
3176 /* automatic parse from the BIOS config */
3177 err = via_parse_auto_config(codec);
3183 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3185 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3188 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3190 codec->patch_ops = via_patch_ops;
3192 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3198 static const struct hda_verb vt2002P_init_verbs[] = {
3199 /* Class-D speaker related verbs */
3203 /* Enable Boost Volume backdoor */
3205 /* Enable AOW0 to MW9 */
3210 static const struct hda_verb vt1802_init_verbs[] = {
3211 /* Enable Boost Volume backdoor */
3213 /* Enable AOW0 to MW9 */
3218 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3220 struct via_spec *spec = codec->spec;
3223 unsigned int present;
3224 /* MUX9 (1eh) = stereo mixer */
3226 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3228 /* PW 5/6/7 (29h/2ah/2bh) */
3230 set_pin_power_state(codec, 0x29, &parm);
3231 set_pin_power_state(codec, 0x2a, &parm);
3232 set_pin_power_state(codec, 0x2b, &parm);
3234 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3235 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3236 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3237 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3238 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3242 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3244 if (spec->codec_type == VT1802) {
3245 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3247 set_pin_power_state(codec, 0x28, &parm);
3248 snd_hda_codec_write(codec, 0x18, 0,
3249 AC_VERB_SET_POWER_STATE, parm);
3250 snd_hda_codec_write(codec, 0x38, 0,
3251 AC_VERB_SET_POWER_STATE, parm);
3253 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3255 set_pin_power_state(codec, 0x26, &parm);
3256 snd_hda_codec_write(codec, 0x1c, 0,
3257 AC_VERB_SET_POWER_STATE, parm);
3258 snd_hda_codec_write(codec, 0x37, 0,
3259 AC_VERB_SET_POWER_STATE, parm);
3262 if (spec->codec_type == VT1802) {
3263 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3265 set_pin_power_state(codec, 0x25, &parm);
3266 snd_hda_codec_write(codec, 0x15, 0,
3267 AC_VERB_SET_POWER_STATE, parm);
3268 snd_hda_codec_write(codec, 0x35, 0,
3269 AC_VERB_SET_POWER_STATE, parm);
3271 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3273 set_pin_power_state(codec, 0x25, &parm);
3274 snd_hda_codec_write(codec, 0x19, 0,
3275 AC_VERB_SET_POWER_STATE, parm);
3276 snd_hda_codec_write(codec, 0x35, 0,
3277 AC_VERB_SET_POWER_STATE, parm);
3280 if (spec->hp_independent_mode)
3281 snd_hda_codec_write(codec, 0x9, 0,
3282 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3285 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3286 present = snd_hda_jack_detect(codec, 0x25);
3289 set_pin_power_state(codec, 0x24, &parm);
3290 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3291 if (spec->codec_type == VT1802)
3292 snd_hda_codec_write(codec, 0x14, 0,
3293 AC_VERB_SET_POWER_STATE, parm);
3295 snd_hda_codec_write(codec, 0x18, 0,
3296 AC_VERB_SET_POWER_STATE, parm);
3297 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3300 present = snd_hda_jack_detect(codec, 0x26);
3302 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3303 if (spec->codec_type == VT1802) {
3304 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3305 snd_hda_codec_write(codec, 0x33, 0,
3306 AC_VERB_SET_POWER_STATE, parm);
3307 snd_hda_codec_write(codec, 0x1c, 0,
3308 AC_VERB_SET_POWER_STATE, parm);
3309 snd_hda_codec_write(codec, 0x3c, 0,
3310 AC_VERB_SET_POWER_STATE, parm);
3312 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3313 snd_hda_codec_write(codec, 0x31, 0,
3314 AC_VERB_SET_POWER_STATE, parm);
3315 snd_hda_codec_write(codec, 0x17, 0,
3316 AC_VERB_SET_POWER_STATE, parm);
3317 snd_hda_codec_write(codec, 0x3b, 0,
3318 AC_VERB_SET_POWER_STATE, parm);
3321 if (imux_is_smixer || !is_aa_path_mute(codec))
3322 snd_hda_codec_write(codec, 0x21, 0,
3323 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3325 snd_hda_codec_write(codec, 0x21, 0,
3326 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3329 /* patch for vt2002P */
3330 static int patch_vt2002P(struct hda_codec *codec)
3332 struct via_spec *spec;
3335 /* create a codec specific record */
3336 spec = via_new_spec(codec);
3340 spec->aa_mix_nid = 0x21;
3341 override_mic_boost(codec, 0x2b, 0, 3, 40);
3342 override_mic_boost(codec, 0x29, 0, 3, 40);
3344 /* automatic parse from the BIOS config */
3345 err = via_parse_auto_config(codec);
3351 if (spec->codec_type == VT1802)
3352 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3354 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3356 codec->patch_ops = via_patch_ops;
3358 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3364 static const struct hda_verb vt1812_init_verbs[] = {
3365 /* Enable Boost Volume backdoor */
3367 /* Enable AOW0 to MW9 */
3372 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3374 struct via_spec *spec = codec->spec;
3375 int imux_is_smixer =
3376 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3378 unsigned int present;
3379 /* MUX10 (1eh) = stereo mixer */
3381 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3383 /* PW 5/6/7 (29h/2ah/2bh) */
3385 set_pin_power_state(codec, 0x29, &parm);
3386 set_pin_power_state(codec, 0x2a, &parm);
3387 set_pin_power_state(codec, 0x2b, &parm);
3389 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3390 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3391 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3392 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3393 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3397 snd_hda_codec_write(codec, 0x8, 0,
3398 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3400 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3402 set_pin_power_state(codec, 0x28, &parm);
3403 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3404 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3406 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3408 set_pin_power_state(codec, 0x25, &parm);
3409 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3410 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3411 if (spec->hp_independent_mode)
3412 snd_hda_codec_write(codec, 0x9, 0,
3413 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3415 /* Internal Speaker */
3416 /* PW0 (24h), MW0(14h), MUX0(34h) */
3417 present = snd_hda_jack_detect(codec, 0x25);
3420 set_pin_power_state(codec, 0x24, &parm);
3422 snd_hda_codec_write(codec, 0x14, 0,
3423 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3424 snd_hda_codec_write(codec, 0x34, 0,
3425 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3427 snd_hda_codec_write(codec, 0x14, 0,
3428 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3429 snd_hda_codec_write(codec, 0x34, 0,
3430 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3435 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3436 present = snd_hda_jack_detect(codec, 0x28);
3439 set_pin_power_state(codec, 0x31, &parm);
3441 snd_hda_codec_write(codec, 0x1c, 0,
3442 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3443 snd_hda_codec_write(codec, 0x3c, 0,
3444 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3445 snd_hda_codec_write(codec, 0x3e, 0,
3446 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3448 snd_hda_codec_write(codec, 0x1c, 0,
3449 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3450 snd_hda_codec_write(codec, 0x3c, 0,
3451 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3452 snd_hda_codec_write(codec, 0x3e, 0,
3453 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3456 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3458 set_pin_power_state(codec, 0x33, &parm);
3459 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3460 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3464 /* patch for vt1812 */
3465 static int patch_vt1812(struct hda_codec *codec)
3467 struct via_spec *spec;
3470 /* create a codec specific record */
3471 spec = via_new_spec(codec);
3475 spec->aa_mix_nid = 0x21;
3476 override_mic_boost(codec, 0x2b, 0, 3, 40);
3477 override_mic_boost(codec, 0x29, 0, 3, 40);
3479 /* automatic parse from the BIOS config */
3480 err = via_parse_auto_config(codec);
3486 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3488 codec->patch_ops = via_patch_ops;
3490 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3497 static const struct hda_codec_preset snd_hda_preset_via[] = {
3498 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3499 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3500 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3501 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3502 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3503 .patch = patch_vt1709},
3504 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3505 .patch = patch_vt1709},
3506 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3507 .patch = patch_vt1709},
3508 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3509 .patch = patch_vt1709},
3510 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3511 .patch = patch_vt1709},
3512 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3513 .patch = patch_vt1709},
3514 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3515 .patch = patch_vt1709},
3516 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3517 .patch = patch_vt1709},
3518 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3519 .patch = patch_vt1708B},
3520 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3521 .patch = patch_vt1708B},
3522 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3523 .patch = patch_vt1708B},
3524 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3525 .patch = patch_vt1708B},
3526 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3527 .patch = patch_vt1708B},
3528 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3529 .patch = patch_vt1708B},
3530 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3531 .patch = patch_vt1708B},
3532 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3533 .patch = patch_vt1708B},
3534 { .id = 0x11060397, .name = "VT1708S",
3535 .patch = patch_vt1708S},
3536 { .id = 0x11061397, .name = "VT1708S",
3537 .patch = patch_vt1708S},
3538 { .id = 0x11062397, .name = "VT1708S",
3539 .patch = patch_vt1708S},
3540 { .id = 0x11063397, .name = "VT1708S",
3541 .patch = patch_vt1708S},
3542 { .id = 0x11064397, .name = "VT1705",
3543 .patch = patch_vt1708S},
3544 { .id = 0x11065397, .name = "VT1708S",
3545 .patch = patch_vt1708S},
3546 { .id = 0x11066397, .name = "VT1708S",
3547 .patch = patch_vt1708S},
3548 { .id = 0x11067397, .name = "VT1708S",
3549 .patch = patch_vt1708S},
3550 { .id = 0x11060398, .name = "VT1702",
3551 .patch = patch_vt1702},
3552 { .id = 0x11061398, .name = "VT1702",
3553 .patch = patch_vt1702},
3554 { .id = 0x11062398, .name = "VT1702",
3555 .patch = patch_vt1702},
3556 { .id = 0x11063398, .name = "VT1702",
3557 .patch = patch_vt1702},
3558 { .id = 0x11064398, .name = "VT1702",
3559 .patch = patch_vt1702},
3560 { .id = 0x11065398, .name = "VT1702",
3561 .patch = patch_vt1702},
3562 { .id = 0x11066398, .name = "VT1702",
3563 .patch = patch_vt1702},
3564 { .id = 0x11067398, .name = "VT1702",
3565 .patch = patch_vt1702},
3566 { .id = 0x11060428, .name = "VT1718S",
3567 .patch = patch_vt1718S},
3568 { .id = 0x11064428, .name = "VT1718S",
3569 .patch = patch_vt1718S},
3570 { .id = 0x11060441, .name = "VT2020",
3571 .patch = patch_vt1718S},
3572 { .id = 0x11064441, .name = "VT1828S",
3573 .patch = patch_vt1718S},
3574 { .id = 0x11060433, .name = "VT1716S",
3575 .patch = patch_vt1716S},
3576 { .id = 0x1106a721, .name = "VT1716S",
3577 .patch = patch_vt1716S},
3578 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3579 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3580 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3581 { .id = 0x11060440, .name = "VT1818S",
3582 .patch = patch_vt1708S},
3583 { .id = 0x11060446, .name = "VT1802",
3584 .patch = patch_vt2002P},
3585 { .id = 0x11068446, .name = "VT1802",
3586 .patch = patch_vt2002P},
3590 MODULE_ALIAS("snd-hda-codec-id:1106*");
3592 static struct hda_codec_preset_list via_list = {
3593 .preset = snd_hda_preset_via,
3594 .owner = THIS_MODULE,
3597 MODULE_LICENSE("GPL");
3598 MODULE_DESCRIPTION("VIA HD-audio codec");
3600 static int __init patch_via_init(void)
3602 return snd_hda_add_codec_preset(&via_list);
3605 static void __exit patch_via_exit(void)
3607 snd_hda_delete_codec_preset(&via_list);
3610 module_init(patch_via_init)
3611 module_exit(patch_via_exit)