2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <linux/module.h>
53 #include <sound/core.h>
54 #include <sound/asoundef.h>
55 #include "hda_codec.h"
56 #include "hda_local.h"
57 #include "hda_auto_parser.h"
61 #define VT1708_HP_PIN_NID 0x20
62 #define VT1708_CD_PIN_NID 0x24
82 #define VT2002P_COMPATIBLE(spec) \
83 ((spec)->codec_type == VT2002P ||\
84 (spec)->codec_type == VT1812 ||\
85 (spec)->codec_type == VT1802)
87 #define MAX_NID_PATH_DEPTH 5
89 /* output-path: DAC -> ... -> pin
90 * idx[] contains the source index number of the next widget;
91 * e.g. idx[0] is the index of the DAC selected by path[1] widget
92 * multi[] indicates whether it's a selector widget with multi-connectors
93 * (i.e. the connection selection is mandatory)
94 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
98 hda_nid_t path[MAX_NID_PATH_DEPTH];
99 unsigned char idx[MAX_NID_PATH_DEPTH];
100 unsigned char multi[MAX_NID_PATH_DEPTH];
101 unsigned int vol_ctl;
102 unsigned int mute_ctl;
107 hda_nid_t pin; /* input-pin or aa-mix */
108 int adc_idx; /* ADC index to be used */
109 int mux_idx; /* MUX index (if any) */
110 const char *label; /* input-source label */
113 #define VIA_MAX_ADCS 3
116 STREAM_MULTI_OUT = (1 << 0),
117 STREAM_INDEP_HP = (1 << 1),
121 struct hda_gen_spec gen;
123 /* codec parameterization */
124 const struct snd_kcontrol_new *mixers[6];
125 unsigned int num_mixers;
127 const struct hda_verb *init_verbs[5];
128 unsigned int num_iverbs;
130 char stream_name_analog[32];
131 char stream_name_hp[32];
132 const struct hda_pcm_stream *stream_analog_playback;
133 const struct hda_pcm_stream *stream_analog_capture;
135 char stream_name_digital[32];
136 const struct hda_pcm_stream *stream_digital_playback;
137 const struct hda_pcm_stream *stream_digital_capture;
140 struct hda_multi_out multiout;
141 hda_nid_t slave_dig_outs[2];
142 hda_nid_t hp_dac_nid;
143 hda_nid_t speaker_dac_nid;
144 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
145 int opened_streams; /* STREAM_* bits */
146 int active_streams; /* STREAM_* bits */
147 int aamix_mode; /* loopback is enabled for output-path? */
150 * There are different output-paths depending on the setup.
151 * out_path, hp_path and speaker_path are primary paths. If both
152 * direct DAC and aa-loopback routes are available, these contain
153 * the former paths. Meanwhile *_mix_path contain the paths with
154 * loopback mixer. (Since the loopback is only for front channel,
155 * no out_mix_path for surround channels.)
156 * The HP output has another path, hp_indep_path, which is used in
157 * the independent-HP mode.
159 struct nid_path out_path[HDA_SIDE + 1];
160 struct nid_path out_mix_path;
161 struct nid_path hp_path;
162 struct nid_path hp_mix_path;
163 struct nid_path hp_indep_path;
164 struct nid_path speaker_path;
165 struct nid_path speaker_mix_path;
168 unsigned int num_adc_nids;
169 hda_nid_t adc_nids[VIA_MAX_ADCS];
170 hda_nid_t mux_nids[VIA_MAX_ADCS];
171 hda_nid_t aa_mix_nid;
172 hda_nid_t dig_in_nid;
177 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
178 unsigned int cur_mux[VIA_MAX_ADCS];
180 /* dynamic DAC switching */
181 unsigned int cur_dac_stream_tag;
182 unsigned int cur_dac_format;
183 unsigned int cur_hp_stream_tag;
184 unsigned int cur_hp_format;
186 /* dynamic ADC switching */
188 unsigned int cur_adc_stream_tag;
189 unsigned int cur_adc_format;
191 /* PCM information */
192 struct hda_pcm pcm_rec[3];
194 /* dynamic controls, init_verbs and input_mux */
195 struct auto_pin_cfg autocfg;
196 struct snd_array kctls;
197 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
200 unsigned int hp_independent_mode;
201 unsigned int dmic_enabled;
202 unsigned int no_pin_power_ctl;
203 enum VIA_HDA_CODEC codec_type;
205 /* analog low-power control */
209 unsigned int smart51_nums;
210 hda_nid_t smart51_pins[2];
212 const char *smart51_labels[2];
213 unsigned int smart51_enabled;
215 /* work to check hp jack state */
216 struct hda_codec *codec;
217 struct delayed_work vt1708_hp_work;
219 int vt1708_jack_detect;
220 int vt1708_hp_present;
222 void (*set_widgets_power_state)(struct hda_codec *codec);
224 struct hda_loopback_check loopback;
226 struct hda_amp_list loopback_list[8];
228 /* bind capture-volume */
229 struct hda_bind_ctls *bind_cap_vol;
230 struct hda_bind_ctls *bind_cap_sw;
232 struct mutex config_mutex;
235 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
236 static struct via_spec * via_new_spec(struct hda_codec *codec)
238 struct via_spec *spec;
240 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
244 mutex_init(&spec->config_mutex);
247 spec->codec_type = get_codec_type(codec);
248 /* VT1708BCE & VT1708S are almost same */
249 if (spec->codec_type == VT1708BCE)
250 spec->codec_type = VT1708S;
251 snd_hda_gen_init(&spec->gen);
255 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
257 u32 vendor_id = codec->vendor_id;
258 u16 ven_id = vendor_id >> 16;
259 u16 dev_id = vendor_id & 0xffff;
260 enum VIA_HDA_CODEC codec_type;
263 if (ven_id != 0x1106)
264 codec_type = UNKNOWN;
265 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
267 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
268 codec_type = VT1709_10CH;
269 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
270 codec_type = VT1709_6CH;
271 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
272 codec_type = VT1708B_8CH;
273 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
274 codec_type = VT1708BCE;
275 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
276 codec_type = VT1708B_4CH;
277 else if ((dev_id & 0xfff) == 0x397
278 && (dev_id >> 12) < 8)
279 codec_type = VT1708S;
280 else if ((dev_id & 0xfff) == 0x398
281 && (dev_id >> 12) < 8)
283 else if ((dev_id & 0xfff) == 0x428
284 && (dev_id >> 12) < 8)
285 codec_type = VT1718S;
286 else if (dev_id == 0x0433 || dev_id == 0xa721)
287 codec_type = VT1716S;
288 else if (dev_id == 0x0441 || dev_id == 0x4441)
289 codec_type = VT1718S;
290 else if (dev_id == 0x0438 || dev_id == 0x4438)
291 codec_type = VT2002P;
292 else if (dev_id == 0x0448)
294 else if (dev_id == 0x0440)
295 codec_type = VT1708S;
296 else if ((dev_id & 0xfff) == 0x446)
299 codec_type = UNKNOWN;
303 #define VIA_JACK_EVENT 0x20
304 #define VIA_HP_EVENT 0x01
305 #define VIA_LINE_EVENT 0x03
310 VIA_CTL_WIDGET_ANALOG_MUTE,
313 static void analog_low_current_mode(struct hda_codec *codec);
314 static bool is_aa_path_mute(struct hda_codec *codec);
316 #define hp_detect_with_aa(codec) \
317 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
318 !is_aa_path_mute(codec))
320 static void vt1708_stop_hp_work(struct via_spec *spec)
322 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
324 if (spec->hp_work_active) {
325 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
326 cancel_delayed_work_sync(&spec->vt1708_hp_work);
327 spec->hp_work_active = 0;
331 static void vt1708_update_hp_work(struct via_spec *spec)
333 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
335 if (spec->vt1708_jack_detect &&
336 (spec->active_streams || hp_detect_with_aa(spec->codec))) {
337 if (!spec->hp_work_active) {
338 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
339 schedule_delayed_work(&spec->vt1708_hp_work,
340 msecs_to_jiffies(100));
341 spec->hp_work_active = 1;
343 } else if (!hp_detect_with_aa(spec->codec))
344 vt1708_stop_hp_work(spec);
347 static void set_widgets_power_state(struct hda_codec *codec)
349 struct via_spec *spec = codec->spec;
350 if (spec->set_widgets_power_state)
351 spec->set_widgets_power_state(codec);
354 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
355 struct snd_ctl_elem_value *ucontrol)
357 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
358 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
360 set_widgets_power_state(codec);
361 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
362 vt1708_update_hp_work(codec->spec);
366 /* modify .put = snd_hda_mixer_amp_switch_put */
367 #define ANALOG_INPUT_MUTE \
368 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
371 .info = snd_hda_mixer_amp_switch_info, \
372 .get = snd_hda_mixer_amp_switch_get, \
373 .put = analog_input_switch_put, \
374 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
376 static const struct snd_kcontrol_new via_control_templates[] = {
377 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
378 HDA_CODEC_MUTE(NULL, 0, 0, 0),
383 /* add dynamic controls */
384 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
385 const struct snd_kcontrol_new *tmpl,
388 struct snd_kcontrol_new *knew;
390 snd_array_init(&spec->kctls, sizeof(*knew), 32);
391 knew = snd_array_new(&spec->kctls);
398 knew->name = kstrdup(name, GFP_KERNEL);
405 static int __via_add_control(struct via_spec *spec, int type, const char *name,
406 int idx, unsigned long val)
408 struct snd_kcontrol_new *knew;
410 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
414 if (get_amp_nid_(val))
415 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
416 knew->private_value = val;
420 #define via_add_control(spec, type, name, val) \
421 __via_add_control(spec, type, name, 0, val)
423 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
425 static void via_free_kctls(struct hda_codec *codec)
427 struct via_spec *spec = codec->spec;
429 if (spec->kctls.list) {
430 struct snd_kcontrol_new *kctl = spec->kctls.list;
432 for (i = 0; i < spec->kctls.used; i++)
435 snd_array_free(&spec->kctls);
438 /* create input playback/capture controls for the given pin */
439 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
440 int type_idx, int idx, int mix_nid)
445 sprintf(name, "%s Playback Volume", ctlname);
446 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
447 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
450 sprintf(name, "%s Playback Switch", ctlname);
451 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
452 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
458 #define get_connection_index(codec, mux, nid) \
459 snd_hda_get_conn_index(codec, mux, nid, 0)
461 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
467 caps = get_wcaps(codec, nid);
468 if (dir == HDA_INPUT)
469 caps &= AC_WCAP_IN_AMP;
471 caps &= AC_WCAP_OUT_AMP;
474 if (query_amp_caps(codec, nid, dir) & mask)
479 #define have_mute(codec, nid, dir) \
480 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
482 /* enable/disable the output-route mixers */
483 static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
484 hda_nid_t mix_nid, int idx, bool enable)
490 num = snd_hda_get_num_conns(codec, mix_nid);
491 for (i = 0; i < num; i++) {
493 val = AMP_IN_UNMUTE(i);
495 val = AMP_IN_MUTE(i);
496 snd_hda_codec_write(codec, mix_nid, 0,
497 AC_VERB_SET_AMP_GAIN_MUTE, val);
501 /* enable/disable the output-route */
502 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
503 bool enable, bool force)
505 struct via_spec *spec = codec->spec;
507 for (i = 0; i < path->depth; i++) {
509 int idx = path->idx[i];
511 if (i < path->depth - 1)
512 dst = path->path[i + 1];
515 if (enable && path->multi[i])
516 snd_hda_codec_write(codec, dst, 0,
517 AC_VERB_SET_CONNECT_SEL, idx);
518 if (!force && (dst == spec->aa_mix_nid))
520 if (have_mute(codec, dst, HDA_INPUT))
521 activate_output_mix(codec, path, dst, idx, enable);
522 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
524 if (have_mute(codec, src, HDA_OUTPUT)) {
525 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
526 snd_hda_codec_write(codec, src, 0,
527 AC_VERB_SET_AMP_GAIN_MUTE, val);
532 /* set the given pin as output */
533 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
538 snd_hda_set_pin_ctl(codec, pin, pin_type);
539 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
540 snd_hda_codec_write(codec, pin, 0,
541 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
544 static void via_auto_init_output(struct hda_codec *codec,
545 struct nid_path *path, int pin_type)
552 pin = path->path[path->depth - 1];
554 init_output_pin(codec, pin, pin_type);
555 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
556 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
559 if (caps & AC_AMPCAP_MUTE) {
561 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
562 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
565 activate_output_path(codec, path, true, true); /* force on */
568 static void via_auto_init_multi_out(struct hda_codec *codec)
570 struct via_spec *spec = codec->spec;
571 struct nid_path *path;
574 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
575 path = &spec->out_path[i];
576 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
577 path = &spec->out_mix_path;
578 via_auto_init_output(codec, path, PIN_OUT);
582 /* deactivate the inactive headphone-paths */
583 static void deactivate_hp_paths(struct hda_codec *codec)
585 struct via_spec *spec = codec->spec;
586 int shared = spec->hp_indep_shared;
588 if (spec->hp_independent_mode) {
589 activate_output_path(codec, &spec->hp_path, false, false);
590 activate_output_path(codec, &spec->hp_mix_path, false, false);
592 activate_output_path(codec, &spec->out_path[shared],
594 } else if (spec->aamix_mode || !spec->hp_path.depth) {
595 activate_output_path(codec, &spec->hp_indep_path, false, false);
596 activate_output_path(codec, &spec->hp_path, false, false);
598 activate_output_path(codec, &spec->hp_indep_path, false, false);
599 activate_output_path(codec, &spec->hp_mix_path, false, false);
603 static void via_auto_init_hp_out(struct hda_codec *codec)
605 struct via_spec *spec = codec->spec;
607 if (!spec->hp_path.depth) {
608 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
611 deactivate_hp_paths(codec);
612 if (spec->hp_independent_mode)
613 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
614 else if (spec->aamix_mode)
615 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
617 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
620 static void via_auto_init_speaker_out(struct hda_codec *codec)
622 struct via_spec *spec = codec->spec;
624 if (!spec->autocfg.speaker_outs)
626 if (!spec->speaker_path.depth) {
627 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
630 if (!spec->aamix_mode) {
631 activate_output_path(codec, &spec->speaker_mix_path,
633 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
635 activate_output_path(codec, &spec->speaker_path, false, false);
636 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
640 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
641 static void via_hp_automute(struct hda_codec *codec);
643 static void via_auto_init_analog_input(struct hda_codec *codec)
645 struct via_spec *spec = codec->spec;
646 const struct auto_pin_cfg *cfg = &spec->autocfg;
647 hda_nid_t conn[HDA_MAX_CONNECTIONS];
652 for (i = 0; i < spec->num_adc_nids; i++) {
653 hda_nid_t nid = spec->adc_nids[i];
654 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP) ||
655 !(query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE))
657 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
658 AC_VERB_SET_AMP_GAIN_MUTE,
663 for (i = 0; i < cfg->num_inputs; i++) {
664 hda_nid_t nid = cfg->inputs[i].pin;
665 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
669 if (cfg->inputs[i].type == AUTO_PIN_MIC)
670 ctl |= snd_hda_get_default_vref(codec, nid);
672 snd_hda_set_pin_ctl(codec, nid, ctl);
676 for (i = 0; i < spec->num_adc_nids; i++) {
677 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
678 /* secondary ADCs must have the unique MUX */
679 if (i > 0 && !spec->mux_nids[i])
681 if (spec->mux_nids[adc_idx]) {
682 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
683 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
684 AC_VERB_SET_CONNECT_SEL,
687 if (spec->dyn_adc_switch)
688 break; /* only one input-src */
692 if (!spec->aa_mix_nid)
694 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
696 for (i = 0; i < num_conns; i++) {
697 unsigned int caps = get_wcaps(codec, conn[i]);
698 if (get_wcaps_type(caps) == AC_WID_PIN)
699 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
700 AC_VERB_SET_AMP_GAIN_MUTE,
705 static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
708 if (snd_hda_codec_read(codec, nid, 0,
709 AC_VERB_GET_POWER_STATE, 0) == parm)
711 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
714 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
715 unsigned int *affected_parm)
718 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
719 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
720 >> AC_DEFCFG_MISC_SHIFT
721 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
722 struct via_spec *spec = codec->spec;
723 unsigned present = 0;
725 no_presence |= spec->no_pin_power_ctl;
727 present = snd_hda_jack_detect(codec, nid);
728 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
729 || ((no_presence || present)
730 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
731 *affected_parm = AC_PWRST_D0; /* if it's connected */
736 update_power_state(codec, nid, parm);
739 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
740 struct snd_ctl_elem_info *uinfo)
742 static const char * const texts[] = {
743 "Disabled", "Enabled"
746 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
748 uinfo->value.enumerated.items = 2;
749 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
750 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
751 strcpy(uinfo->value.enumerated.name,
752 texts[uinfo->value.enumerated.item]);
756 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
757 struct snd_ctl_elem_value *ucontrol)
759 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
760 struct via_spec *spec = codec->spec;
761 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
765 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
766 struct snd_ctl_elem_value *ucontrol)
768 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
769 struct via_spec *spec = codec->spec;
770 unsigned int val = !ucontrol->value.enumerated.item[0];
772 if (val == spec->no_pin_power_ctl)
774 spec->no_pin_power_ctl = val;
775 set_widgets_power_state(codec);
776 analog_low_current_mode(codec);
780 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
782 .name = "Dynamic Power-Control",
783 .info = via_pin_power_ctl_info,
784 .get = via_pin_power_ctl_get,
785 .put = via_pin_power_ctl_put,
789 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
790 struct snd_ctl_elem_info *uinfo)
792 static const char * const texts[] = { "OFF", "ON" };
794 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
796 uinfo->value.enumerated.items = 2;
797 if (uinfo->value.enumerated.item >= 2)
798 uinfo->value.enumerated.item = 1;
799 strcpy(uinfo->value.enumerated.name,
800 texts[uinfo->value.enumerated.item]);
804 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
805 struct snd_ctl_elem_value *ucontrol)
807 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
808 struct via_spec *spec = codec->spec;
810 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
814 /* adjust spec->multiout setup according to the current flags */
815 static void setup_playback_multi_pcm(struct via_spec *spec)
817 const struct auto_pin_cfg *cfg = &spec->autocfg;
818 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
819 spec->multiout.hp_nid = 0;
820 if (!spec->hp_independent_mode) {
821 if (!spec->hp_indep_shared)
822 spec->multiout.hp_nid = spec->hp_dac_nid;
824 if (spec->hp_indep_shared)
825 spec->multiout.num_dacs = cfg->line_outs - 1;
829 /* update DAC setups according to indep-HP switch;
830 * this function is called only when indep-HP is modified
832 static void switch_indep_hp_dacs(struct hda_codec *codec)
834 struct via_spec *spec = codec->spec;
835 int shared = spec->hp_indep_shared;
836 hda_nid_t shared_dac, hp_dac;
838 if (!spec->opened_streams)
841 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
842 hp_dac = spec->hp_dac_nid;
843 if (spec->hp_independent_mode) {
844 /* switch to indep-HP mode */
845 if (spec->active_streams & STREAM_MULTI_OUT) {
846 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
847 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
849 if (spec->active_streams & STREAM_INDEP_HP)
850 snd_hda_codec_setup_stream(codec, hp_dac,
851 spec->cur_hp_stream_tag, 0,
852 spec->cur_hp_format);
854 /* back to HP or shared-DAC */
855 if (spec->active_streams & STREAM_INDEP_HP)
856 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
857 if (spec->active_streams & STREAM_MULTI_OUT) {
860 if (shared_dac) { /* reset mutli-ch DAC */
863 } else { /* reset HP DAC */
867 snd_hda_codec_setup_stream(codec, dac,
868 spec->cur_dac_stream_tag, ch,
869 spec->cur_dac_format);
872 setup_playback_multi_pcm(spec);
875 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
876 struct snd_ctl_elem_value *ucontrol)
878 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
879 struct via_spec *spec = codec->spec;
882 mutex_lock(&spec->config_mutex);
883 cur = !!ucontrol->value.enumerated.item[0];
884 if (spec->hp_independent_mode == cur) {
885 mutex_unlock(&spec->config_mutex);
888 spec->hp_independent_mode = cur;
889 shared = spec->hp_indep_shared;
890 deactivate_hp_paths(codec);
892 activate_output_path(codec, &spec->hp_indep_path, true, false);
895 activate_output_path(codec, &spec->out_path[shared],
897 if (spec->aamix_mode || !spec->hp_path.depth)
898 activate_output_path(codec, &spec->hp_mix_path,
901 activate_output_path(codec, &spec->hp_path,
905 switch_indep_hp_dacs(codec);
906 mutex_unlock(&spec->config_mutex);
908 /* update jack power state */
909 set_widgets_power_state(codec);
910 via_hp_automute(codec);
914 static const struct snd_kcontrol_new via_hp_mixer = {
915 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
916 .name = "Independent HP",
917 .info = via_independent_hp_info,
918 .get = via_independent_hp_get,
919 .put = via_independent_hp_put,
922 static int via_hp_build(struct hda_codec *codec)
924 struct via_spec *spec = codec->spec;
925 struct snd_kcontrol_new *knew;
928 nid = spec->autocfg.hp_pins[0];
929 knew = via_clone_control(spec, &via_hp_mixer);
933 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
938 static void notify_aa_path_ctls(struct hda_codec *codec)
940 struct via_spec *spec = codec->spec;
943 for (i = 0; i < spec->smart51_nums; i++) {
944 struct snd_kcontrol *ctl;
945 struct snd_ctl_elem_id id;
946 memset(&id, 0, sizeof(id));
947 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
948 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
949 ctl = snd_hda_find_mixer_ctl(codec, id.name);
951 snd_ctl_notify(codec->bus->card,
952 SNDRV_CTL_EVENT_MASK_VALUE,
957 static void mute_aa_path(struct hda_codec *codec, int mute)
959 struct via_spec *spec = codec->spec;
960 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
963 /* check AA path's mute status */
964 for (i = 0; i < spec->smart51_nums; i++) {
965 if (spec->smart51_idxs[i] < 0)
967 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
968 HDA_INPUT, spec->smart51_idxs[i],
973 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
975 struct via_spec *spec = codec->spec;
978 for (i = 0; i < spec->smart51_nums; i++)
979 if (spec->smart51_pins[i] == pin)
984 static int via_smart51_get(struct snd_kcontrol *kcontrol,
985 struct snd_ctl_elem_value *ucontrol)
987 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
988 struct via_spec *spec = codec->spec;
990 *ucontrol->value.integer.value = spec->smart51_enabled;
994 static int via_smart51_put(struct snd_kcontrol *kcontrol,
995 struct snd_ctl_elem_value *ucontrol)
997 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
998 struct via_spec *spec = codec->spec;
999 int out_in = *ucontrol->value.integer.value
1000 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1003 for (i = 0; i < spec->smart51_nums; i++) {
1004 hda_nid_t nid = spec->smart51_pins[i];
1007 parm = snd_hda_codec_read(codec, nid, 0,
1008 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1009 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1011 snd_hda_set_pin_ctl(codec, nid, parm);
1012 if (out_in == AC_PINCTL_OUT_EN) {
1013 mute_aa_path(codec, 1);
1014 notify_aa_path_ctls(codec);
1017 spec->smart51_enabled = *ucontrol->value.integer.value;
1018 set_widgets_power_state(codec);
1022 static const struct snd_kcontrol_new via_smart51_mixer = {
1023 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1024 .name = "Smart 5.1",
1026 .info = snd_ctl_boolean_mono_info,
1027 .get = via_smart51_get,
1028 .put = via_smart51_put,
1031 static int via_smart51_build(struct hda_codec *codec)
1033 struct via_spec *spec = codec->spec;
1035 if (!spec->smart51_nums)
1037 if (!via_clone_control(spec, &via_smart51_mixer))
1042 /* check AA path's mute status */
1043 static bool is_aa_path_mute(struct hda_codec *codec)
1045 struct via_spec *spec = codec->spec;
1046 const struct hda_amp_list *p;
1049 for (i = 0; i < spec->num_loopbacks; i++) {
1050 p = &spec->loopback_list[i];
1051 for (ch = 0; ch < 2; ch++) {
1052 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1054 if (!(v & HDA_AMP_MUTE) && v > 0)
1061 /* enter/exit analog low-current mode */
1062 static void __analog_low_current_mode(struct hda_codec *codec, bool force)
1064 struct via_spec *spec = codec->spec;
1066 unsigned int verb, parm;
1068 if (spec->no_pin_power_ctl)
1071 enable = is_aa_path_mute(codec) && !spec->opened_streams;
1072 if (enable == spec->alc_mode && !force)
1074 spec->alc_mode = enable;
1076 /* decide low current mode's verb & parameter */
1077 switch (spec->codec_type) {
1081 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1087 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1091 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1097 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1100 return; /* other codecs are not supported */
1103 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1106 static void analog_low_current_mode(struct hda_codec *codec)
1108 return __analog_low_current_mode(codec, false);
1112 * generic initialization of ADC, input mixers and output mixers
1114 static const struct hda_verb vt1708_init_verbs[] = {
1115 /* power down jack detect function */
1120 static void set_stream_open(struct hda_codec *codec, int bit, bool active)
1122 struct via_spec *spec = codec->spec;
1125 spec->opened_streams |= bit;
1127 spec->opened_streams &= ~bit;
1128 analog_low_current_mode(codec);
1131 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1132 struct hda_codec *codec,
1133 struct snd_pcm_substream *substream)
1135 struct via_spec *spec = codec->spec;
1136 const struct auto_pin_cfg *cfg = &spec->autocfg;
1139 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1140 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1141 set_stream_open(codec, STREAM_MULTI_OUT, true);
1142 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1145 set_stream_open(codec, STREAM_MULTI_OUT, false);
1151 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1152 struct hda_codec *codec,
1153 struct snd_pcm_substream *substream)
1155 set_stream_open(codec, STREAM_MULTI_OUT, false);
1159 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1160 struct hda_codec *codec,
1161 struct snd_pcm_substream *substream)
1163 struct via_spec *spec = codec->spec;
1165 if (snd_BUG_ON(!spec->hp_dac_nid))
1167 set_stream_open(codec, STREAM_INDEP_HP, true);
1171 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1172 struct hda_codec *codec,
1173 struct snd_pcm_substream *substream)
1175 set_stream_open(codec, STREAM_INDEP_HP, false);
1179 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1180 struct hda_codec *codec,
1181 unsigned int stream_tag,
1182 unsigned int format,
1183 struct snd_pcm_substream *substream)
1185 struct via_spec *spec = codec->spec;
1187 mutex_lock(&spec->config_mutex);
1188 setup_playback_multi_pcm(spec);
1189 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1191 /* remember for dynamic DAC switch with indep-HP */
1192 spec->active_streams |= STREAM_MULTI_OUT;
1193 spec->cur_dac_stream_tag = stream_tag;
1194 spec->cur_dac_format = format;
1195 mutex_unlock(&spec->config_mutex);
1196 vt1708_update_hp_work(spec);
1200 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1201 struct hda_codec *codec,
1202 unsigned int stream_tag,
1203 unsigned int format,
1204 struct snd_pcm_substream *substream)
1206 struct via_spec *spec = codec->spec;
1208 mutex_lock(&spec->config_mutex);
1209 if (spec->hp_independent_mode)
1210 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1211 stream_tag, 0, format);
1212 spec->active_streams |= STREAM_INDEP_HP;
1213 spec->cur_hp_stream_tag = stream_tag;
1214 spec->cur_hp_format = format;
1215 mutex_unlock(&spec->config_mutex);
1216 vt1708_update_hp_work(spec);
1220 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1221 struct hda_codec *codec,
1222 struct snd_pcm_substream *substream)
1224 struct via_spec *spec = codec->spec;
1226 mutex_lock(&spec->config_mutex);
1227 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1228 spec->active_streams &= ~STREAM_MULTI_OUT;
1229 mutex_unlock(&spec->config_mutex);
1230 vt1708_update_hp_work(spec);
1234 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1235 struct hda_codec *codec,
1236 struct snd_pcm_substream *substream)
1238 struct via_spec *spec = codec->spec;
1240 mutex_lock(&spec->config_mutex);
1241 if (spec->hp_independent_mode)
1242 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1243 spec->active_streams &= ~STREAM_INDEP_HP;
1244 mutex_unlock(&spec->config_mutex);
1245 vt1708_update_hp_work(spec);
1252 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1253 struct hda_codec *codec,
1254 struct snd_pcm_substream *substream)
1256 struct via_spec *spec = codec->spec;
1257 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1260 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1261 struct hda_codec *codec,
1262 struct snd_pcm_substream *substream)
1264 struct via_spec *spec = codec->spec;
1265 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1268 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1269 struct hda_codec *codec,
1270 unsigned int stream_tag,
1271 unsigned int format,
1272 struct snd_pcm_substream *substream)
1274 struct via_spec *spec = codec->spec;
1275 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1276 stream_tag, format, substream);
1279 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1280 struct hda_codec *codec,
1281 struct snd_pcm_substream *substream)
1283 struct via_spec *spec = codec->spec;
1284 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1291 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1292 struct hda_codec *codec,
1293 unsigned int stream_tag,
1294 unsigned int format,
1295 struct snd_pcm_substream *substream)
1297 struct via_spec *spec = codec->spec;
1299 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1300 stream_tag, 0, format);
1304 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1305 struct hda_codec *codec,
1306 struct snd_pcm_substream *substream)
1308 struct via_spec *spec = codec->spec;
1309 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1313 /* analog capture with dynamic ADC switching */
1314 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1315 struct hda_codec *codec,
1316 unsigned int stream_tag,
1317 unsigned int format,
1318 struct snd_pcm_substream *substream)
1320 struct via_spec *spec = codec->spec;
1321 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1323 mutex_lock(&spec->config_mutex);
1324 spec->cur_adc = spec->adc_nids[adc_idx];
1325 spec->cur_adc_stream_tag = stream_tag;
1326 spec->cur_adc_format = format;
1327 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1328 mutex_unlock(&spec->config_mutex);
1332 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1333 struct hda_codec *codec,
1334 struct snd_pcm_substream *substream)
1336 struct via_spec *spec = codec->spec;
1338 mutex_lock(&spec->config_mutex);
1339 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1341 mutex_unlock(&spec->config_mutex);
1345 /* re-setup the stream if running; called from input-src put */
1346 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1348 struct via_spec *spec = codec->spec;
1349 int adc_idx = spec->inputs[cur].adc_idx;
1350 hda_nid_t adc = spec->adc_nids[adc_idx];
1353 mutex_lock(&spec->config_mutex);
1354 if (spec->cur_adc && spec->cur_adc != adc) {
1355 /* stream is running, let's swap the current ADC */
1356 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1357 spec->cur_adc = adc;
1358 snd_hda_codec_setup_stream(codec, adc,
1359 spec->cur_adc_stream_tag, 0,
1360 spec->cur_adc_format);
1363 mutex_unlock(&spec->config_mutex);
1367 static const struct hda_pcm_stream via_pcm_analog_playback = {
1371 /* NID is set in via_build_pcms */
1373 .open = via_playback_multi_pcm_open,
1374 .close = via_playback_multi_pcm_close,
1375 .prepare = via_playback_multi_pcm_prepare,
1376 .cleanup = via_playback_multi_pcm_cleanup
1380 static const struct hda_pcm_stream via_pcm_hp_playback = {
1384 /* NID is set in via_build_pcms */
1386 .open = via_playback_hp_pcm_open,
1387 .close = via_playback_hp_pcm_close,
1388 .prepare = via_playback_hp_pcm_prepare,
1389 .cleanup = via_playback_hp_pcm_cleanup
1393 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1397 /* NID is set in via_build_pcms */
1398 /* We got noisy outputs on the right channel on VT1708 when
1399 * 24bit samples are used. Until any workaround is found,
1400 * disable the 24bit format, so far.
1402 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1404 .open = via_playback_multi_pcm_open,
1405 .close = via_playback_multi_pcm_close,
1406 .prepare = via_playback_multi_pcm_prepare,
1407 .cleanup = via_playback_multi_pcm_cleanup
1411 static const struct hda_pcm_stream via_pcm_analog_capture = {
1412 .substreams = 1, /* will be changed in via_build_pcms() */
1415 /* NID is set in via_build_pcms */
1417 .prepare = via_capture_pcm_prepare,
1418 .cleanup = via_capture_pcm_cleanup
1422 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1426 /* NID is set in via_build_pcms */
1428 .prepare = via_dyn_adc_capture_pcm_prepare,
1429 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1433 static const struct hda_pcm_stream via_pcm_digital_playback = {
1437 /* NID is set in via_build_pcms */
1439 .open = via_dig_playback_pcm_open,
1440 .close = via_dig_playback_pcm_close,
1441 .prepare = via_dig_playback_pcm_prepare,
1442 .cleanup = via_dig_playback_pcm_cleanup
1446 static const struct hda_pcm_stream via_pcm_digital_capture = {
1453 * slave controls for virtual master
1455 static const char * const via_slave_pfxs[] = {
1456 "Front", "Surround", "Center", "LFE", "Side",
1457 "Headphone", "Speaker", "Bass Speaker",
1461 static int via_build_controls(struct hda_codec *codec)
1463 struct via_spec *spec = codec->spec;
1464 struct snd_kcontrol *kctl;
1467 spec->no_pin_power_ctl = 1;
1468 if (spec->set_widgets_power_state)
1469 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1472 for (i = 0; i < spec->num_mixers; i++) {
1473 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1478 if (spec->multiout.dig_out_nid) {
1479 err = snd_hda_create_spdif_out_ctls(codec,
1480 spec->multiout.dig_out_nid,
1481 spec->multiout.dig_out_nid);
1484 err = snd_hda_create_spdif_share_sw(codec,
1488 spec->multiout.share_spdif = 1;
1490 if (spec->dig_in_nid) {
1491 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1496 /* if we have no master control, let's create it */
1497 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1498 unsigned int vmaster_tlv[4];
1499 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1500 HDA_OUTPUT, vmaster_tlv);
1501 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1502 vmaster_tlv, via_slave_pfxs,
1507 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1508 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1509 NULL, via_slave_pfxs,
1515 /* assign Capture Source enums to NID */
1516 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1517 for (i = 0; kctl && i < kctl->count; i++) {
1518 if (!spec->mux_nids[i])
1520 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1525 via_free_kctls(codec); /* no longer needed */
1527 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1534 static int via_build_pcms(struct hda_codec *codec)
1536 struct via_spec *spec = codec->spec;
1537 struct hda_pcm *info = spec->pcm_rec;
1539 codec->num_pcms = 0;
1540 codec->pcm_info = info;
1542 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1543 snprintf(spec->stream_name_analog,
1544 sizeof(spec->stream_name_analog),
1545 "%s Analog", codec->chip_name);
1546 info->name = spec->stream_name_analog;
1548 if (spec->multiout.num_dacs) {
1549 if (!spec->stream_analog_playback)
1550 spec->stream_analog_playback =
1551 &via_pcm_analog_playback;
1552 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1553 *spec->stream_analog_playback;
1554 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1555 spec->multiout.dac_nids[0];
1556 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1557 spec->multiout.max_channels;
1558 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT
1559 && spec->autocfg.line_outs == 2)
1560 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1564 if (!spec->stream_analog_capture) {
1565 if (spec->dyn_adc_switch)
1566 spec->stream_analog_capture =
1567 &via_pcm_dyn_adc_analog_capture;
1569 spec->stream_analog_capture =
1570 &via_pcm_analog_capture;
1572 if (spec->num_adc_nids) {
1573 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1574 *spec->stream_analog_capture;
1575 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1577 if (!spec->dyn_adc_switch)
1578 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1585 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1586 snprintf(spec->stream_name_digital,
1587 sizeof(spec->stream_name_digital),
1588 "%s Digital", codec->chip_name);
1589 info->name = spec->stream_name_digital;
1590 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1591 if (spec->multiout.dig_out_nid) {
1592 if (!spec->stream_digital_playback)
1593 spec->stream_digital_playback =
1594 &via_pcm_digital_playback;
1595 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1596 *spec->stream_digital_playback;
1597 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1598 spec->multiout.dig_out_nid;
1600 if (spec->dig_in_nid) {
1601 if (!spec->stream_digital_capture)
1602 spec->stream_digital_capture =
1603 &via_pcm_digital_capture;
1604 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1605 *spec->stream_digital_capture;
1606 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1613 if (spec->hp_dac_nid) {
1614 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1615 "%s HP", codec->chip_name);
1616 info->name = spec->stream_name_hp;
1617 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1618 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1626 static void via_free(struct hda_codec *codec)
1628 struct via_spec *spec = codec->spec;
1633 via_free_kctls(codec);
1634 vt1708_stop_hp_work(spec);
1635 kfree(spec->bind_cap_vol);
1636 kfree(spec->bind_cap_sw);
1637 snd_hda_gen_free(&spec->gen);
1641 /* mute/unmute outputs */
1642 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1643 hda_nid_t *pins, bool mute)
1646 for (i = 0; i < num_pins; i++) {
1647 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1648 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1649 if (parm & AC_PINCTL_IN_EN)
1652 parm &= ~AC_PINCTL_OUT_EN;
1654 parm |= AC_PINCTL_OUT_EN;
1655 snd_hda_set_pin_ctl(codec, pins[i], parm);
1659 /* mute internal speaker if line-out is plugged */
1660 static void via_line_automute(struct hda_codec *codec, int present)
1662 struct via_spec *spec = codec->spec;
1664 if (!spec->autocfg.speaker_outs)
1667 present = snd_hda_jack_detect(codec,
1668 spec->autocfg.line_out_pins[0]);
1669 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1670 spec->autocfg.speaker_pins,
1674 /* mute internal speaker if HP is plugged */
1675 static void via_hp_automute(struct hda_codec *codec)
1679 struct via_spec *spec = codec->spec;
1681 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
1682 (spec->codec_type != VT1708 || spec->vt1708_jack_detect) &&
1683 is_jack_detectable(codec, spec->autocfg.hp_pins[0]))
1684 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1686 if (spec->smart51_enabled)
1687 nums = spec->autocfg.line_outs + spec->smart51_nums;
1689 nums = spec->autocfg.line_outs;
1690 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1692 via_line_automute(codec, present);
1696 static int via_suspend(struct hda_codec *codec)
1698 struct via_spec *spec = codec->spec;
1699 vt1708_stop_hp_work(spec);
1701 if (spec->codec_type == VT1802) {
1702 /* Fix pop noise on headphones */
1704 for (i = 0; i < spec->autocfg.hp_outs; i++)
1705 snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0);
1713 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1715 struct via_spec *spec = codec->spec;
1716 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1723 static int via_init(struct hda_codec *codec);
1725 static const struct hda_codec_ops via_patch_ops = {
1726 .build_controls = via_build_controls,
1727 .build_pcms = via_build_pcms,
1730 .unsol_event = snd_hda_jack_unsol_event,
1732 .suspend = via_suspend,
1733 .check_power_status = via_check_power_status,
1737 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1739 struct via_spec *spec = codec->spec;
1742 for (i = 0; i < spec->multiout.num_dacs; i++) {
1743 if (spec->multiout.dac_nids[i] == dac)
1746 if (spec->hp_dac_nid == dac)
1751 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1752 hda_nid_t target_dac, int with_aa_mix,
1753 struct nid_path *path, int depth)
1755 struct via_spec *spec = codec->spec;
1759 if (nid == spec->aa_mix_nid) {
1762 with_aa_mix = 2; /* mark aa-mix is included */
1765 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1766 for (i = 0; i < nums; i++) {
1767 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1769 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1770 /* aa-mix is requested but not included? */
1771 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1775 if (depth >= MAX_NID_PATH_DEPTH)
1777 for (i = 0; i < nums; i++) {
1779 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1780 if (type == AC_WID_AUD_OUT)
1782 if (__parse_output_path(codec, conn[i], target_dac,
1783 with_aa_mix, path, depth + 1))
1789 path->path[path->depth] = conn[i];
1790 path->idx[path->depth] = i;
1791 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1792 path->multi[path->depth] = 1;
1797 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1798 hda_nid_t target_dac, int with_aa_mix,
1799 struct nid_path *path)
1801 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
1802 path->path[path->depth] = nid;
1804 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1805 path->depth, path->path[0], path->path[1],
1806 path->path[2], path->path[3], path->path[4]);
1812 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1814 struct via_spec *spec = codec->spec;
1815 const struct auto_pin_cfg *cfg = &spec->autocfg;
1819 spec->multiout.num_dacs = 0;
1820 spec->multiout.dac_nids = spec->private_dac_nids;
1821 for (i = 0; i < cfg->line_outs; i++) {
1823 nid = cfg->line_out_pins[i];
1826 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1827 dac = spec->out_path[i].path[0];
1828 if (!i && parse_output_path(codec, nid, dac, 1,
1829 &spec->out_mix_path))
1830 dac = spec->out_mix_path.path[0];
1832 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
1834 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1835 spec->out_path[0] = spec->out_mix_path;
1836 spec->out_mix_path.depth = 0;
1841 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1842 int chs, bool check_dac, struct nid_path *path)
1844 struct via_spec *spec = codec->spec;
1846 hda_nid_t dac, pin, sel, nid;
1849 dac = check_dac ? path->path[0] : 0;
1850 pin = path->path[path->depth - 1];
1851 sel = path->depth > 1 ? path->path[1] : 0;
1853 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1855 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1857 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1862 sprintf(name, "%s Playback Volume", pfx);
1863 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1864 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1867 path->vol_ctl = nid;
1870 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1872 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1874 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1879 sprintf(name, "%s Playback Switch", pfx);
1880 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1881 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1884 path->mute_ctl = nid;
1889 static void mangle_smart51(struct hda_codec *codec)
1891 struct via_spec *spec = codec->spec;
1892 struct auto_pin_cfg *cfg = &spec->autocfg;
1893 struct auto_pin_cfg_item *ins = cfg->inputs;
1894 int i, j, nums, attr;
1895 int pins[AUTO_CFG_MAX_INS];
1897 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1899 for (i = 0; i < cfg->num_inputs; i++) {
1901 if (ins[i].type > AUTO_PIN_LINE_IN)
1903 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1904 if (snd_hda_get_input_pin_attr(def) != attr)
1906 for (j = 0; j < nums; j++)
1907 if (ins[pins[j]].type < ins[i].type) {
1908 memmove(pins + j + 1, pins + j,
1909 (nums - j) * sizeof(int));
1915 if (cfg->line_outs + nums < 3)
1917 for (i = 0; i < nums; i++) {
1918 hda_nid_t pin = ins[pins[i]].pin;
1919 spec->smart51_pins[spec->smart51_nums++] = pin;
1920 cfg->line_out_pins[cfg->line_outs++] = pin;
1921 if (cfg->line_outs == 3)
1928 static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1930 dst->vol_ctl = src->vol_ctl;
1931 dst->mute_ctl = src->mute_ctl;
1934 /* add playback controls from the parsed DAC table */
1935 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1937 struct via_spec *spec = codec->spec;
1938 struct auto_pin_cfg *cfg = &spec->autocfg;
1939 struct nid_path *path;
1940 static const char * const chname[4] = {
1941 "Front", "Surround", "C/LFE", "Side"
1947 old_line_outs = cfg->line_outs;
1948 if (cfg->line_outs == 1)
1949 mangle_smart51(codec);
1951 err = via_auto_fill_dac_nids(codec);
1955 if (spec->multiout.num_dacs < 3) {
1956 spec->smart51_nums = 0;
1957 cfg->line_outs = old_line_outs;
1959 for (i = 0; i < cfg->line_outs; i++) {
1961 pin = cfg->line_out_pins[i];
1962 dac = spec->multiout.dac_nids[i];
1965 path = spec->out_path + i;
1966 if (i == HDA_CLFE) {
1967 err = create_ch_ctls(codec, "Center", 1, true, path);
1970 err = create_ch_ctls(codec, "LFE", 2, true, path);
1974 const char *pfx = chname[i];
1975 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1976 cfg->line_outs <= 2)
1977 pfx = i ? "Bass Speaker" : "Speaker";
1978 err = create_ch_ctls(codec, pfx, 3, true, path);
1982 if (path != spec->out_path + i)
1983 copy_path_mixer_ctls(&spec->out_path[i], path);
1984 if (path == spec->out_path && spec->out_mix_path.depth)
1985 copy_path_mixer_ctls(&spec->out_mix_path, path);
1988 idx = get_connection_index(codec, spec->aa_mix_nid,
1989 spec->multiout.dac_nids[0]);
1991 /* add control to mixer */
1993 name = spec->out_mix_path.depth ?
1994 "PCM Loopback Playback Volume" : "PCM Playback Volume";
1995 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1996 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2000 name = spec->out_mix_path.depth ?
2001 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2002 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2003 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2009 cfg->line_outs = old_line_outs;
2014 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
2016 struct via_spec *spec = codec->spec;
2017 struct nid_path *path;
2024 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2025 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2026 if (i < spec->multiout.num_dacs &&
2027 parse_output_path(codec, pin,
2028 spec->multiout.dac_nids[i], 0,
2029 &spec->hp_indep_path)) {
2030 spec->hp_indep_shared = i;
2035 if (spec->hp_indep_path.depth) {
2036 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2037 if (!spec->hp_indep_shared)
2038 spec->hp_path = spec->hp_indep_path;
2040 /* optionally check front-path w/o AA-mix */
2041 if (!spec->hp_path.depth)
2042 parse_output_path(codec, pin,
2043 spec->multiout.dac_nids[HDA_FRONT], 0,
2046 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2047 1, &spec->hp_mix_path) && !spec->hp_path.depth)
2050 if (spec->hp_path.depth) {
2051 path = &spec->hp_path;
2054 path = &spec->hp_mix_path;
2057 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
2061 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2063 copy_path_mixer_ctls(&spec->hp_path, path);
2064 if (spec->hp_indep_path.depth)
2065 copy_path_mixer_ctls(&spec->hp_indep_path, path);
2069 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2071 struct via_spec *spec = codec->spec;
2072 struct nid_path *path;
2074 hda_nid_t pin, dac = 0;
2077 pin = spec->autocfg.speaker_pins[0];
2078 if (!spec->autocfg.speaker_outs || !pin)
2081 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
2082 dac = spec->speaker_path.path[0];
2084 parse_output_path(codec, pin,
2085 spec->multiout.dac_nids[HDA_FRONT], 0,
2086 &spec->speaker_path);
2087 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2088 1, &spec->speaker_mix_path) && !dac)
2091 /* no AA-path for front? */
2092 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2095 spec->speaker_dac_nid = dac;
2096 spec->multiout.extra_out_nid[0] = dac;
2098 path = &spec->speaker_path;
2101 path = &spec->speaker_mix_path;
2104 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2108 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2110 copy_path_mixer_ctls(&spec->speaker_path, path);
2114 #define via_aamix_ctl_info via_pin_power_ctl_info
2116 static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2117 struct snd_ctl_elem_value *ucontrol)
2119 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2120 struct via_spec *spec = codec->spec;
2121 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2125 static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2126 struct nid_path *nomix, struct nid_path *mix)
2129 activate_output_path(codec, nomix, false, false);
2130 activate_output_path(codec, mix, true, false);
2132 activate_output_path(codec, mix, false, false);
2133 activate_output_path(codec, nomix, true, false);
2137 static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2138 struct snd_ctl_elem_value *ucontrol)
2140 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2141 struct via_spec *spec = codec->spec;
2142 unsigned int val = ucontrol->value.enumerated.item[0];
2144 if (val == spec->aamix_mode)
2146 spec->aamix_mode = val;
2147 /* update front path */
2148 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2149 /* update HP path */
2150 if (!spec->hp_independent_mode) {
2151 update_aamix_paths(codec, val, &spec->hp_path,
2152 &spec->hp_mix_path);
2154 /* update speaker path */
2155 update_aamix_paths(codec, val, &spec->speaker_path,
2156 &spec->speaker_mix_path);
2160 static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2161 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2162 .name = "Loopback Mixing",
2163 .info = via_aamix_ctl_info,
2164 .get = via_aamix_ctl_get,
2165 .put = via_aamix_ctl_put,
2168 static int via_auto_create_loopback_switch(struct hda_codec *codec)
2170 struct via_spec *spec = codec->spec;
2172 if (!spec->aa_mix_nid)
2173 return 0; /* no loopback switching available */
2174 if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
2175 spec->speaker_path.depth))
2176 return 0; /* no loopback switching available */
2177 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2183 static int via_fill_adcs(struct hda_codec *codec)
2185 struct via_spec *spec = codec->spec;
2186 hda_nid_t nid = codec->start_nid;
2189 for (i = 0; i < codec->num_nodes; i++, nid++) {
2190 unsigned int wcaps = get_wcaps(codec, nid);
2191 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2193 if (wcaps & AC_WCAP_DIGITAL)
2195 if (!(wcaps & AC_WCAP_CONN_LIST))
2197 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2199 spec->adc_nids[spec->num_adc_nids++] = nid;
2204 /* input-src control */
2205 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2206 struct snd_ctl_elem_info *uinfo)
2208 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2209 struct via_spec *spec = codec->spec;
2211 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2213 uinfo->value.enumerated.items = spec->num_inputs;
2214 if (uinfo->value.enumerated.item >= spec->num_inputs)
2215 uinfo->value.enumerated.item = spec->num_inputs - 1;
2216 strcpy(uinfo->value.enumerated.name,
2217 spec->inputs[uinfo->value.enumerated.item].label);
2221 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2222 struct snd_ctl_elem_value *ucontrol)
2224 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2225 struct via_spec *spec = codec->spec;
2226 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2228 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2232 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2233 struct snd_ctl_elem_value *ucontrol)
2235 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2236 struct via_spec *spec = codec->spec;
2237 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2241 cur = ucontrol->value.enumerated.item[0];
2242 if (cur < 0 || cur >= spec->num_inputs)
2244 if (spec->cur_mux[idx] == cur)
2246 spec->cur_mux[idx] = cur;
2247 if (spec->dyn_adc_switch) {
2248 int adc_idx = spec->inputs[cur].adc_idx;
2249 mux = spec->mux_nids[adc_idx];
2250 via_dyn_adc_pcm_resetup(codec, cur);
2252 mux = spec->mux_nids[idx];
2253 if (snd_BUG_ON(!mux))
2258 /* switch to D0 beofre change index */
2259 update_power_state(codec, mux, AC_PWRST_D0);
2260 snd_hda_codec_write(codec, mux, 0,
2261 AC_VERB_SET_CONNECT_SEL,
2262 spec->inputs[cur].mux_idx);
2265 /* update jack power state */
2266 set_widgets_power_state(codec);
2270 static const struct snd_kcontrol_new via_input_src_ctl = {
2271 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2272 /* The multiple "Capture Source" controls confuse alsamixer
2273 * So call somewhat different..
2275 /* .name = "Capture Source", */
2276 .name = "Input Source",
2277 .info = via_mux_enum_info,
2278 .get = via_mux_enum_get,
2279 .put = via_mux_enum_put,
2282 static int create_input_src_ctls(struct hda_codec *codec, int count)
2284 struct via_spec *spec = codec->spec;
2285 struct snd_kcontrol_new *knew;
2287 if (spec->num_inputs <= 1 || !count)
2288 return 0; /* no need for single src */
2290 knew = via_clone_control(spec, &via_input_src_ctl);
2293 knew->count = count;
2297 /* add the powersave loopback-list entry */
2298 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2300 struct hda_amp_list *list;
2302 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2304 list = spec->loopback_list + spec->num_loopbacks;
2306 list->dir = HDA_INPUT;
2308 spec->num_loopbacks++;
2309 spec->loopback.amplist = spec->loopback_list;
2312 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2315 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2318 /* add the input-route to the given pin */
2319 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2321 struct via_spec *spec = codec->spec;
2324 spec->inputs[spec->num_inputs].adc_idx = -1;
2325 spec->inputs[spec->num_inputs].pin = pin;
2326 for (c = 0; c < spec->num_adc_nids; c++) {
2327 if (spec->mux_nids[c]) {
2328 idx = get_connection_index(codec, spec->mux_nids[c],
2332 spec->inputs[spec->num_inputs].mux_idx = idx;
2334 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2337 spec->inputs[spec->num_inputs].adc_idx = c;
2338 /* Can primary ADC satisfy all inputs? */
2339 if (!spec->dyn_adc_switch &&
2340 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2341 snd_printd(KERN_INFO
2342 "via: dynamic ADC switching enabled\n");
2343 spec->dyn_adc_switch = 1;
2350 static int get_mux_nids(struct hda_codec *codec);
2352 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2353 static int parse_analog_inputs(struct hda_codec *codec)
2355 struct via_spec *spec = codec->spec;
2356 const struct auto_pin_cfg *cfg = &spec->autocfg;
2359 err = via_fill_adcs(codec);
2362 err = get_mux_nids(codec);
2366 /* fill all input-routes */
2367 for (i = 0; i < cfg->num_inputs; i++) {
2368 if (add_input_route(codec, cfg->inputs[i].pin))
2369 spec->inputs[spec->num_inputs++].label =
2370 hda_get_autocfg_input_label(codec, cfg, i);
2373 /* check for internal loopback recording */
2374 if (spec->aa_mix_nid &&
2375 add_input_route(codec, spec->aa_mix_nid))
2376 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2381 /* create analog-loopback volume/switch controls */
2382 static int create_loopback_ctls(struct hda_codec *codec)
2384 struct via_spec *spec = codec->spec;
2385 const struct auto_pin_cfg *cfg = &spec->autocfg;
2386 const char *prev_label = NULL;
2390 if (!spec->aa_mix_nid)
2393 for (i = 0; i < cfg->num_inputs; i++) {
2394 hda_nid_t pin = cfg->inputs[i].pin;
2395 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2397 if (prev_label && !strcmp(label, prev_label))
2402 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2404 err = via_new_analog_input(spec, label, type_idx,
2405 idx, spec->aa_mix_nid);
2408 add_loopback_list(spec, spec->aa_mix_nid, idx);
2411 /* remember the label for smart51 control */
2412 for (j = 0; j < spec->smart51_nums; j++) {
2413 if (spec->smart51_pins[j] == pin) {
2414 spec->smart51_idxs[j] = idx;
2415 spec->smart51_labels[j] = label;
2423 /* create mic-boost controls (if present) */
2424 static int create_mic_boost_ctls(struct hda_codec *codec)
2426 struct via_spec *spec = codec->spec;
2427 const struct auto_pin_cfg *cfg = &spec->autocfg;
2428 const char *prev_label = NULL;
2432 for (i = 0; i < cfg->num_inputs; i++) {
2433 hda_nid_t pin = cfg->inputs[i].pin;
2438 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2440 caps = query_amp_caps(codec, pin, HDA_INPUT);
2441 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2443 label = hda_get_autocfg_input_label(codec, cfg, i);
2444 if (prev_label && !strcmp(label, prev_label))
2449 snprintf(name, sizeof(name), "%s Boost Volume", label);
2450 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
2451 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2458 /* create capture and input-src controls for multiple streams */
2459 static int create_multi_adc_ctls(struct hda_codec *codec)
2461 struct via_spec *spec = codec->spec;
2464 /* create capture mixer elements */
2465 for (i = 0; i < spec->num_adc_nids; i++) {
2466 hda_nid_t adc = spec->adc_nids[i];
2467 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2468 "Capture Volume", i,
2469 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2473 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2474 "Capture Switch", i,
2475 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2481 /* input-source control */
2482 for (i = 0; i < spec->num_adc_nids; i++)
2483 if (!spec->mux_nids[i])
2485 err = create_input_src_ctls(codec, i);
2491 /* bind capture volume/switch */
2492 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2493 HDA_BIND_VOL("Capture Volume", 0);
2494 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2495 HDA_BIND_SW("Capture Switch", 0);
2497 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2498 struct hda_ctl_ops *ops)
2500 struct hda_bind_ctls *ctl;
2503 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2507 for (i = 0; i < spec->num_adc_nids; i++)
2509 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2514 /* create capture and input-src controls for dynamic ADC-switch case */
2515 static int create_dyn_adc_ctls(struct hda_codec *codec)
2517 struct via_spec *spec = codec->spec;
2518 struct snd_kcontrol_new *knew;
2521 /* set up the bind capture ctls */
2522 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2525 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2529 /* create capture mixer elements */
2530 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2533 knew->private_value = (long)spec->bind_cap_vol;
2535 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2538 knew->private_value = (long)spec->bind_cap_sw;
2540 /* input-source control */
2541 err = create_input_src_ctls(codec, 1);
2547 /* parse and create capture-related stuff */
2548 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2550 struct via_spec *spec = codec->spec;
2553 err = parse_analog_inputs(codec);
2556 if (spec->dyn_adc_switch)
2557 err = create_dyn_adc_ctls(codec);
2559 err = create_multi_adc_ctls(codec);
2562 err = create_loopback_ctls(codec);
2565 err = create_mic_boost_ctls(codec);
2571 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2573 unsigned int def_conf;
2574 unsigned char seqassoc;
2576 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2577 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2578 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2579 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2580 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2581 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2582 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2588 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2589 struct snd_ctl_elem_value *ucontrol)
2591 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2592 struct via_spec *spec = codec->spec;
2594 if (spec->codec_type != VT1708)
2596 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2600 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2601 struct snd_ctl_elem_value *ucontrol)
2603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2604 struct via_spec *spec = codec->spec;
2607 if (spec->codec_type != VT1708)
2609 val = !!ucontrol->value.integer.value[0];
2610 if (spec->vt1708_jack_detect == val)
2612 spec->vt1708_jack_detect = val;
2613 if (spec->vt1708_jack_detect &&
2614 snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
2615 mute_aa_path(codec, 1);
2616 notify_aa_path_ctls(codec);
2618 via_hp_automute(codec);
2619 vt1708_update_hp_work(spec);
2623 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2625 .name = "Jack Detect",
2627 .info = snd_ctl_boolean_mono_info,
2628 .get = vt1708_jack_detect_get,
2629 .put = vt1708_jack_detect_put,
2632 static void fill_dig_outs(struct hda_codec *codec);
2633 static void fill_dig_in(struct hda_codec *codec);
2635 static int via_parse_auto_config(struct hda_codec *codec)
2637 struct via_spec *spec = codec->spec;
2640 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2643 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2646 err = via_auto_create_multi_out_ctls(codec);
2649 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2652 err = via_auto_create_speaker_ctls(codec);
2655 err = via_auto_create_loopback_switch(codec);
2658 err = via_auto_create_analog_input_ctls(codec);
2662 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2664 fill_dig_outs(codec);
2667 if (spec->kctls.list)
2668 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2671 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
2672 err = via_hp_build(codec);
2677 err = via_smart51_build(codec);
2681 /* assign slave outs */
2682 if (spec->slave_dig_outs[0])
2683 codec->slave_dig_outs = spec->slave_dig_outs;
2688 static void via_auto_init_dig_outs(struct hda_codec *codec)
2690 struct via_spec *spec = codec->spec;
2691 if (spec->multiout.dig_out_nid)
2692 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2693 if (spec->slave_dig_outs[0])
2694 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2697 static void via_auto_init_dig_in(struct hda_codec *codec)
2699 struct via_spec *spec = codec->spec;
2700 if (!spec->dig_in_nid)
2702 snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
2705 static void via_jack_output_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2707 set_widgets_power_state(codec);
2708 via_hp_automute(codec);
2711 static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2713 set_widgets_power_state(codec);
2716 /* initialize the unsolicited events */
2717 static void via_auto_init_unsol_event(struct hda_codec *codec)
2719 struct via_spec *spec = codec->spec;
2720 struct auto_pin_cfg *cfg = &spec->autocfg;
2723 hda_jack_callback cb;
2725 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2726 snd_hda_jack_detect_enable_callback(codec, cfg->hp_pins[0],
2727 VIA_HP_EVENT | VIA_JACK_EVENT,
2728 via_jack_output_event);
2730 if (cfg->speaker_pins[0])
2731 ev = VIA_LINE_EVENT;
2734 cb = ev ? via_jack_output_event : via_jack_powerstate_event;
2736 for (i = 0; i < cfg->line_outs; i++) {
2737 if (cfg->line_out_pins[i] &&
2738 is_jack_detectable(codec, cfg->line_out_pins[i]))
2739 snd_hda_jack_detect_enable_callback(codec, cfg->line_out_pins[i],
2740 ev | VIA_JACK_EVENT, cb);
2743 for (i = 0; i < cfg->num_inputs; i++) {
2744 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2745 snd_hda_jack_detect_enable_callback(codec, cfg->inputs[i].pin,
2747 via_jack_powerstate_event);
2751 static int via_init(struct hda_codec *codec)
2753 struct via_spec *spec = codec->spec;
2756 for (i = 0; i < spec->num_iverbs; i++)
2757 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2759 /* init power states */
2760 set_widgets_power_state(codec);
2761 __analog_low_current_mode(codec, true);
2763 via_auto_init_multi_out(codec);
2764 via_auto_init_hp_out(codec);
2765 via_auto_init_speaker_out(codec);
2766 via_auto_init_analog_input(codec);
2767 via_auto_init_dig_outs(codec);
2768 via_auto_init_dig_in(codec);
2770 via_auto_init_unsol_event(codec);
2772 via_hp_automute(codec);
2773 vt1708_update_hp_work(spec);
2778 static void vt1708_update_hp_jack_state(struct work_struct *work)
2780 struct via_spec *spec = container_of(work, struct via_spec,
2781 vt1708_hp_work.work);
2782 if (spec->codec_type != VT1708)
2784 snd_hda_jack_set_dirty_all(spec->codec);
2785 /* if jack state toggled */
2786 if (spec->vt1708_hp_present
2787 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2788 spec->vt1708_hp_present ^= 1;
2789 via_hp_automute(spec->codec);
2791 if (spec->vt1708_jack_detect)
2792 schedule_delayed_work(&spec->vt1708_hp_work,
2793 msecs_to_jiffies(100));
2796 static int get_mux_nids(struct hda_codec *codec)
2798 struct via_spec *spec = codec->spec;
2799 hda_nid_t nid, conn[8];
2803 for (i = 0; i < spec->num_adc_nids; i++) {
2804 nid = spec->adc_nids[i];
2806 type = get_wcaps_type(get_wcaps(codec, nid));
2807 if (type == AC_WID_PIN)
2809 n = snd_hda_get_connections(codec, nid, conn,
2814 spec->mux_nids[i] = nid;
2823 static int patch_vt1708(struct hda_codec *codec)
2825 struct via_spec *spec;
2828 /* create a codec specific record */
2829 spec = via_new_spec(codec);
2833 spec->aa_mix_nid = 0x17;
2835 /* Add HP and CD pin config connect bit re-config action */
2836 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2837 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2839 /* automatic parse from the BIOS config */
2840 err = via_parse_auto_config(codec);
2846 /* add jack detect on/off control */
2847 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2850 /* disable 32bit format on VT1708 */
2851 if (codec->vendor_id == 0x11061708)
2852 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2854 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2856 codec->patch_ops = via_patch_ops;
2858 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2862 static int patch_vt1709(struct hda_codec *codec)
2864 struct via_spec *spec;
2867 /* create a codec specific record */
2868 spec = via_new_spec(codec);
2872 spec->aa_mix_nid = 0x18;
2874 err = via_parse_auto_config(codec);
2880 codec->patch_ops = via_patch_ops;
2885 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2887 struct via_spec *spec = codec->spec;
2891 if ((spec->codec_type != VT1708B_4CH) &&
2892 (codec->vendor_id != 0x11064397))
2895 /* SW0 (17h) = stereo mixer */
2897 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2898 == ((spec->codec_type == VT1708S) ? 5 : 0));
2900 /* PW 1/2/5 (1ah/1bh/1eh) */
2902 set_pin_power_state(codec, 0x1a, &parm);
2903 set_pin_power_state(codec, 0x1b, &parm);
2904 set_pin_power_state(codec, 0x1e, &parm);
2907 /* SW0 (17h), AIW 0/1 (13h/14h) */
2908 update_power_state(codec, 0x17, parm);
2909 update_power_state(codec, 0x13, parm);
2910 update_power_state(codec, 0x14, parm);
2913 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2915 set_pin_power_state(codec, 0x19, &parm);
2916 if (spec->smart51_enabled)
2917 set_pin_power_state(codec, 0x1b, &parm);
2918 update_power_state(codec, 0x18, parm);
2919 update_power_state(codec, 0x11, parm);
2921 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2924 set_pin_power_state(codec, 0x22, &parm);
2925 if (spec->smart51_enabled)
2926 set_pin_power_state(codec, 0x1a, &parm);
2927 update_power_state(codec, 0x26, parm);
2928 update_power_state(codec, 0x24, parm);
2929 } else if (codec->vendor_id == 0x11064397) {
2930 /* PW7(23h), SW2(27h), AOW2(25h) */
2932 set_pin_power_state(codec, 0x23, &parm);
2933 if (spec->smart51_enabled)
2934 set_pin_power_state(codec, 0x1a, &parm);
2935 update_power_state(codec, 0x27, parm);
2936 update_power_state(codec, 0x25, parm);
2939 /* PW 3/4/7 (1ch/1dh/23h) */
2941 /* force to D0 for internal Speaker */
2942 set_pin_power_state(codec, 0x1c, &parm);
2943 set_pin_power_state(codec, 0x1d, &parm);
2945 set_pin_power_state(codec, 0x23, &parm);
2947 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2948 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
2949 update_power_state(codec, 0x10, parm);
2951 update_power_state(codec, 0x25, parm);
2952 update_power_state(codec, 0x27, parm);
2953 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2954 update_power_state(codec, 0x25, parm);
2957 static int patch_vt1708S(struct hda_codec *codec);
2958 static int patch_vt1708B(struct hda_codec *codec)
2960 struct via_spec *spec;
2963 if (get_codec_type(codec) == VT1708BCE)
2964 return patch_vt1708S(codec);
2966 /* create a codec specific record */
2967 spec = via_new_spec(codec);
2971 spec->aa_mix_nid = 0x16;
2973 /* automatic parse from the BIOS config */
2974 err = via_parse_auto_config(codec);
2980 codec->patch_ops = via_patch_ops;
2982 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2987 /* Patch for VT1708S */
2988 static const struct hda_verb vt1708S_init_verbs[] = {
2989 /* Enable Mic Boost Volume backdoor */
2991 /* don't bybass mixer */
2996 /* fill out digital output widgets; one for master and one for slave outputs */
2997 static void fill_dig_outs(struct hda_codec *codec)
2999 struct via_spec *spec = codec->spec;
3002 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3006 nid = spec->autocfg.dig_out_pins[i];
3009 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3012 if (!spec->multiout.dig_out_nid)
3013 spec->multiout.dig_out_nid = nid;
3015 spec->slave_dig_outs[0] = nid;
3016 break; /* at most two dig outs */
3021 static void fill_dig_in(struct hda_codec *codec)
3023 struct via_spec *spec = codec->spec;
3027 if (!spec->autocfg.dig_in_pin)
3030 dig_nid = codec->start_nid;
3031 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3032 unsigned int wcaps = get_wcaps(codec, dig_nid);
3033 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3035 if (!(wcaps & AC_WCAP_DIGITAL))
3037 if (!(wcaps & AC_WCAP_CONN_LIST))
3039 err = get_connection_index(codec, dig_nid,
3040 spec->autocfg.dig_in_pin);
3042 spec->dig_in_nid = dig_nid;
3048 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3049 int offset, int num_steps, int step_size)
3051 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3052 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3053 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3054 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3055 (0 << AC_AMPCAP_MUTE_SHIFT));
3058 static int patch_vt1708S(struct hda_codec *codec)
3060 struct via_spec *spec;
3063 /* create a codec specific record */
3064 spec = via_new_spec(codec);
3068 spec->aa_mix_nid = 0x16;
3069 override_mic_boost(codec, 0x1a, 0, 3, 40);
3070 override_mic_boost(codec, 0x1e, 0, 3, 40);
3072 /* automatic parse from the BIOS config */
3073 err = via_parse_auto_config(codec);
3079 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
3081 codec->patch_ops = via_patch_ops;
3083 /* correct names for VT1708BCE */
3084 if (get_codec_type(codec) == VT1708BCE) {
3085 kfree(codec->chip_name);
3086 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3087 snprintf(codec->bus->card->mixername,
3088 sizeof(codec->bus->card->mixername),
3089 "%s %s", codec->vendor_name, codec->chip_name);
3091 /* correct names for VT1705 */
3092 if (codec->vendor_id == 0x11064397) {
3093 kfree(codec->chip_name);
3094 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3095 snprintf(codec->bus->card->mixername,
3096 sizeof(codec->bus->card->mixername),
3097 "%s %s", codec->vendor_name, codec->chip_name);
3099 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3103 /* Patch for VT1702 */
3105 static const struct hda_verb vt1702_init_verbs[] = {
3113 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3115 int imux_is_smixer =
3116 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3119 /* PW 1/2/5 (14h/15h/18h) */
3121 set_pin_power_state(codec, 0x14, &parm);
3122 set_pin_power_state(codec, 0x15, &parm);
3123 set_pin_power_state(codec, 0x18, &parm);
3125 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3126 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3127 update_power_state(codec, 0x13, parm);
3128 update_power_state(codec, 0x12, parm);
3129 update_power_state(codec, 0x1f, parm);
3130 update_power_state(codec, 0x20, parm);
3133 /* PW 3/4 (16h/17h) */
3135 set_pin_power_state(codec, 0x17, &parm);
3136 set_pin_power_state(codec, 0x16, &parm);
3137 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3138 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
3139 update_power_state(codec, 0x10, parm);
3140 update_power_state(codec, 0x1d, parm);
3143 static int patch_vt1702(struct hda_codec *codec)
3145 struct via_spec *spec;
3148 /* create a codec specific record */
3149 spec = via_new_spec(codec);
3153 spec->aa_mix_nid = 0x1a;
3155 /* limit AA path volume to 0 dB */
3156 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3157 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3158 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3159 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3160 (1 << AC_AMPCAP_MUTE_SHIFT));
3162 /* automatic parse from the BIOS config */
3163 err = via_parse_auto_config(codec);
3169 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
3171 codec->patch_ops = via_patch_ops;
3173 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
3177 /* Patch for VT1718S */
3179 static const struct hda_verb vt1718S_init_verbs[] = {
3180 /* Enable MW0 adjust Gain 5 */
3182 /* Enable Boost Volume backdoor */
3188 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3190 struct via_spec *spec = codec->spec;
3192 unsigned int parm, parm2;
3193 /* MUX6 (1eh) = stereo mixer */
3195 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3197 /* PW 5/6/7 (29h/2ah/2bh) */
3199 set_pin_power_state(codec, 0x29, &parm);
3200 set_pin_power_state(codec, 0x2a, &parm);
3201 set_pin_power_state(codec, 0x2b, &parm);
3204 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3205 update_power_state(codec, 0x1e, parm);
3206 update_power_state(codec, 0x1f, parm);
3207 update_power_state(codec, 0x10, parm);
3208 update_power_state(codec, 0x11, parm);
3211 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3213 set_pin_power_state(codec, 0x27, &parm);
3214 update_power_state(codec, 0x1a, parm);
3215 parm2 = parm; /* for pin 0x0b */
3217 /* PW2 (26h), AOW2 (ah) */
3219 set_pin_power_state(codec, 0x26, &parm);
3220 if (spec->smart51_enabled)
3221 set_pin_power_state(codec, 0x2b, &parm);
3222 update_power_state(codec, 0xa, parm);
3224 /* PW0 (24h), AOW0 (8h) */
3226 set_pin_power_state(codec, 0x24, &parm);
3227 if (!spec->hp_independent_mode) /* check for redirected HP */
3228 set_pin_power_state(codec, 0x28, &parm);
3229 update_power_state(codec, 0x8, parm);
3230 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
3232 update_power_state(codec, 0xb, parm);
3233 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3234 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
3236 /* PW1 (25h), AOW1 (9h) */
3238 set_pin_power_state(codec, 0x25, &parm);
3239 if (spec->smart51_enabled)
3240 set_pin_power_state(codec, 0x2a, &parm);
3241 update_power_state(codec, 0x9, parm);
3243 if (spec->hp_independent_mode) {
3244 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3246 set_pin_power_state(codec, 0x28, &parm);
3247 update_power_state(codec, 0x1b, parm);
3248 update_power_state(codec, 0x34, parm);
3249 update_power_state(codec, 0xc, parm);
3253 /* Add a connection to the primary DAC from AA-mixer for some codecs
3254 * This isn't listed from the raw info, but the chip has a secret connection.
3256 static int add_secret_dac_path(struct hda_codec *codec)
3258 struct via_spec *spec = codec->spec;
3263 if (!spec->aa_mix_nid)
3265 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3266 ARRAY_SIZE(conn) - 1);
3267 for (i = 0; i < nums; i++) {
3268 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3272 /* find the primary DAC and add to the connection list */
3273 nid = codec->start_nid;
3274 for (i = 0; i < codec->num_nodes; i++, nid++) {
3275 unsigned int caps = get_wcaps(codec, nid);
3276 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3277 !(caps & AC_WCAP_DIGITAL)) {
3279 return snd_hda_override_conn_list(codec,
3288 static int patch_vt1718S(struct hda_codec *codec)
3290 struct via_spec *spec;
3293 /* create a codec specific record */
3294 spec = via_new_spec(codec);
3298 spec->aa_mix_nid = 0x21;
3299 override_mic_boost(codec, 0x2b, 0, 3, 40);
3300 override_mic_boost(codec, 0x29, 0, 3, 40);
3301 add_secret_dac_path(codec);
3303 /* automatic parse from the BIOS config */
3304 err = via_parse_auto_config(codec);
3310 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3312 codec->patch_ops = via_patch_ops;
3314 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3319 /* Patch for VT1716S */
3321 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3322 struct snd_ctl_elem_info *uinfo)
3324 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3326 uinfo->value.integer.min = 0;
3327 uinfo->value.integer.max = 1;
3331 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3332 struct snd_ctl_elem_value *ucontrol)
3334 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3337 index = snd_hda_codec_read(codec, 0x26, 0,
3338 AC_VERB_GET_CONNECT_SEL, 0);
3340 *ucontrol->value.integer.value = index;
3345 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3346 struct snd_ctl_elem_value *ucontrol)
3348 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3349 struct via_spec *spec = codec->spec;
3350 int index = *ucontrol->value.integer.value;
3352 snd_hda_codec_write(codec, 0x26, 0,
3353 AC_VERB_SET_CONNECT_SEL, index);
3354 spec->dmic_enabled = index;
3355 set_widgets_power_state(codec);
3359 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3360 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3362 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3363 .name = "Digital Mic Capture Switch",
3364 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3366 .info = vt1716s_dmic_info,
3367 .get = vt1716s_dmic_get,
3368 .put = vt1716s_dmic_put,
3374 /* mono-out mixer elements */
3375 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3376 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3380 static const struct hda_verb vt1716S_init_verbs[] = {
3381 /* Enable Boost Volume backdoor */
3383 /* don't bybass mixer */
3385 /* Enable mono output */
3390 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3392 struct via_spec *spec = codec->spec;
3395 unsigned int mono_out, present;
3396 /* SW0 (17h) = stereo mixer */
3398 (snd_hda_codec_read(codec, 0x17, 0,
3399 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3401 /* PW 1/2/5 (1ah/1bh/1eh) */
3403 set_pin_power_state(codec, 0x1a, &parm);
3404 set_pin_power_state(codec, 0x1b, &parm);
3405 set_pin_power_state(codec, 0x1e, &parm);
3408 /* SW0 (17h), AIW0(13h) */
3409 update_power_state(codec, 0x17, parm);
3410 update_power_state(codec, 0x13, parm);
3413 set_pin_power_state(codec, 0x1e, &parm);
3415 if (spec->dmic_enabled)
3416 set_pin_power_state(codec, 0x22, &parm);
3418 update_power_state(codec, 0x22, AC_PWRST_D3);
3420 /* SW2(26h), AIW1(14h) */
3421 update_power_state(codec, 0x26, parm);
3422 update_power_state(codec, 0x14, parm);
3425 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3427 set_pin_power_state(codec, 0x19, &parm);
3428 /* Smart 5.1 PW2(1bh) */
3429 if (spec->smart51_enabled)
3430 set_pin_power_state(codec, 0x1b, &parm);
3431 update_power_state(codec, 0x18, parm);
3432 update_power_state(codec, 0x11, parm);
3434 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3436 set_pin_power_state(codec, 0x23, &parm);
3437 /* Smart 5.1 PW1(1ah) */
3438 if (spec->smart51_enabled)
3439 set_pin_power_state(codec, 0x1a, &parm);
3440 update_power_state(codec, 0x27, parm);
3442 /* Smart 5.1 PW5(1eh) */
3443 if (spec->smart51_enabled)
3444 set_pin_power_state(codec, 0x1e, &parm);
3445 update_power_state(codec, 0x25, parm);
3448 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3449 present = snd_hda_jack_detect(codec, 0x1c);
3454 present = snd_hda_jack_detect(codec, 0x1d);
3455 if (!spec->hp_independent_mode && present)
3460 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3461 update_power_state(codec, 0x28, parm);
3462 update_power_state(codec, 0x29, parm);
3463 update_power_state(codec, 0x2a, parm);
3465 /* PW 3/4 (1ch/1dh) */
3467 set_pin_power_state(codec, 0x1c, &parm);
3468 set_pin_power_state(codec, 0x1d, &parm);
3469 /* HP Independent Mode, power on AOW3 */
3470 if (spec->hp_independent_mode)
3471 update_power_state(codec, 0x25, parm);
3473 /* force to D0 for internal Speaker */
3474 /* MW0 (16h), AOW0 (10h) */
3475 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
3476 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
3479 static int patch_vt1716S(struct hda_codec *codec)
3481 struct via_spec *spec;
3484 /* create a codec specific record */
3485 spec = via_new_spec(codec);
3489 spec->aa_mix_nid = 0x16;
3490 override_mic_boost(codec, 0x1a, 0, 3, 40);
3491 override_mic_boost(codec, 0x1e, 0, 3, 40);
3493 /* automatic parse from the BIOS config */
3494 err = via_parse_auto_config(codec);
3500 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3502 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3505 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3507 codec->patch_ops = via_patch_ops;
3509 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3515 static const struct hda_verb vt2002P_init_verbs[] = {
3516 /* Class-D speaker related verbs */
3520 /* Enable Boost Volume backdoor */
3522 /* Enable AOW0 to MW9 */
3527 static const struct hda_verb vt1802_init_verbs[] = {
3528 /* Enable Boost Volume backdoor */
3530 /* Enable AOW0 to MW9 */
3535 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3537 struct via_spec *spec = codec->spec;
3540 unsigned int present;
3541 /* MUX9 (1eh) = stereo mixer */
3543 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3545 /* PW 5/6/7 (29h/2ah/2bh) */
3547 set_pin_power_state(codec, 0x29, &parm);
3548 set_pin_power_state(codec, 0x2a, &parm);
3549 set_pin_power_state(codec, 0x2b, &parm);
3551 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3552 update_power_state(codec, 0x1e, parm);
3553 update_power_state(codec, 0x1f, parm);
3554 update_power_state(codec, 0x10, parm);
3555 update_power_state(codec, 0x11, parm);
3559 update_power_state(codec, 0x8, parm);
3561 if (spec->codec_type == VT1802) {
3562 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3564 set_pin_power_state(codec, 0x28, &parm);
3565 update_power_state(codec, 0x18, parm);
3566 update_power_state(codec, 0x38, parm);
3568 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3570 set_pin_power_state(codec, 0x26, &parm);
3571 update_power_state(codec, 0x1c, parm);
3572 update_power_state(codec, 0x37, parm);
3575 if (spec->codec_type == VT1802) {
3576 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3578 set_pin_power_state(codec, 0x25, &parm);
3579 update_power_state(codec, 0x15, parm);
3580 update_power_state(codec, 0x35, parm);
3582 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3584 set_pin_power_state(codec, 0x25, &parm);
3585 update_power_state(codec, 0x19, parm);
3586 update_power_state(codec, 0x35, parm);
3589 if (spec->hp_independent_mode)
3590 update_power_state(codec, 0x9, AC_PWRST_D0);
3593 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3594 present = snd_hda_jack_detect(codec, 0x25);
3597 set_pin_power_state(codec, 0x24, &parm);
3598 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3599 if (spec->codec_type == VT1802)
3600 update_power_state(codec, 0x14, parm);
3602 update_power_state(codec, 0x18, parm);
3603 update_power_state(codec, 0x34, parm);
3606 present = snd_hda_jack_detect(codec, 0x26);
3608 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3609 if (spec->codec_type == VT1802) {
3610 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3611 update_power_state(codec, 0x33, parm);
3612 update_power_state(codec, 0x1c, parm);
3613 update_power_state(codec, 0x3c, parm);
3615 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3616 update_power_state(codec, 0x31, parm);
3617 update_power_state(codec, 0x17, parm);
3618 update_power_state(codec, 0x3b, parm);
3621 if (imux_is_smixer || !is_aa_path_mute(codec))
3622 update_power_state(codec, 0x21, AC_PWRST_D0);
3624 update_power_state(codec, 0x21, AC_PWRST_D3);
3631 VIA_FIXUP_INTMIC_BOOST,
3635 static void via_fixup_intmic_boost(struct hda_codec *codec,
3636 const struct hda_fixup *fix, int action)
3638 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3639 override_mic_boost(codec, 0x30, 0, 2, 40);
3642 static const struct hda_fixup via_fixups[] = {
3643 [VIA_FIXUP_INTMIC_BOOST] = {
3644 .type = HDA_FIXUP_FUNC,
3645 .v.func = via_fixup_intmic_boost,
3647 [VIA_FIXUP_ASUS_G75] = {
3648 .type = HDA_FIXUP_PINS,
3649 .v.pins = (const struct hda_pintbl[]) {
3650 /* set 0x24 and 0x33 as speakers */
3651 { 0x24, 0x991301f0 },
3652 { 0x33, 0x991301f1 }, /* subwoofer */
3658 static const struct snd_pci_quirk vt2002p_fixups[] = {
3659 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
3660 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
3664 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
3665 * Replace this with mixer NID 0x1c
3667 static void fix_vt1802_connections(struct hda_codec *codec)
3669 static hda_nid_t conn_24[] = { 0x14, 0x1c };
3670 static hda_nid_t conn_33[] = { 0x1c };
3672 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
3673 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
3676 /* patch for vt2002P */
3677 static int patch_vt2002P(struct hda_codec *codec)
3679 struct via_spec *spec;
3682 /* create a codec specific record */
3683 spec = via_new_spec(codec);
3687 spec->aa_mix_nid = 0x21;
3688 override_mic_boost(codec, 0x2b, 0, 3, 40);
3689 override_mic_boost(codec, 0x29, 0, 3, 40);
3690 if (spec->codec_type == VT1802)
3691 fix_vt1802_connections(codec);
3692 add_secret_dac_path(codec);
3694 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
3695 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3697 /* automatic parse from the BIOS config */
3698 err = via_parse_auto_config(codec);
3704 if (spec->codec_type == VT1802)
3705 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3707 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3709 codec->patch_ops = via_patch_ops;
3711 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3717 static const struct hda_verb vt1812_init_verbs[] = {
3718 /* Enable Boost Volume backdoor */
3720 /* Enable AOW0 to MW9 */
3725 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3727 struct via_spec *spec = codec->spec;
3729 unsigned int present;
3731 /* PW 5/6/7 (29h/2ah/2bh) */
3733 set_pin_power_state(codec, 0x29, &parm);
3734 set_pin_power_state(codec, 0x2a, &parm);
3735 set_pin_power_state(codec, 0x2b, &parm);
3737 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3738 update_power_state(codec, 0x1e, parm);
3739 update_power_state(codec, 0x1f, parm);
3740 update_power_state(codec, 0x10, parm);
3741 update_power_state(codec, 0x11, parm);
3745 update_power_state(codec, 0x8, AC_PWRST_D0);
3747 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3749 set_pin_power_state(codec, 0x28, &parm);
3750 update_power_state(codec, 0x18, parm);
3751 update_power_state(codec, 0x38, parm);
3753 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3755 set_pin_power_state(codec, 0x25, &parm);
3756 update_power_state(codec, 0x15, parm);
3757 update_power_state(codec, 0x35, parm);
3758 if (spec->hp_independent_mode)
3759 update_power_state(codec, 0x9, AC_PWRST_D0);
3761 /* Internal Speaker */
3762 /* PW0 (24h), MW0(14h), MUX0(34h) */
3763 present = snd_hda_jack_detect(codec, 0x25);
3766 set_pin_power_state(codec, 0x24, &parm);
3768 update_power_state(codec, 0x14, AC_PWRST_D3);
3769 update_power_state(codec, 0x34, AC_PWRST_D3);
3771 update_power_state(codec, 0x14, AC_PWRST_D0);
3772 update_power_state(codec, 0x34, AC_PWRST_D0);
3777 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3778 present = snd_hda_jack_detect(codec, 0x28);
3781 set_pin_power_state(codec, 0x31, &parm);
3783 update_power_state(codec, 0x1c, AC_PWRST_D3);
3784 update_power_state(codec, 0x3c, AC_PWRST_D3);
3785 update_power_state(codec, 0x3e, AC_PWRST_D3);
3787 update_power_state(codec, 0x1c, AC_PWRST_D0);
3788 update_power_state(codec, 0x3c, AC_PWRST_D0);
3789 update_power_state(codec, 0x3e, AC_PWRST_D0);
3792 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3794 set_pin_power_state(codec, 0x33, &parm);
3795 update_power_state(codec, 0x1d, parm);
3796 update_power_state(codec, 0x3d, parm);
3800 /* patch for vt1812 */
3801 static int patch_vt1812(struct hda_codec *codec)
3803 struct via_spec *spec;
3806 /* create a codec specific record */
3807 spec = via_new_spec(codec);
3811 spec->aa_mix_nid = 0x21;
3812 override_mic_boost(codec, 0x2b, 0, 3, 40);
3813 override_mic_boost(codec, 0x29, 0, 3, 40);
3814 add_secret_dac_path(codec);
3816 /* automatic parse from the BIOS config */
3817 err = via_parse_auto_config(codec);
3823 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3825 codec->patch_ops = via_patch_ops;
3827 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3834 static const struct hda_codec_preset snd_hda_preset_via[] = {
3835 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3836 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3837 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3838 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3839 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3840 .patch = patch_vt1709},
3841 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3842 .patch = patch_vt1709},
3843 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3844 .patch = patch_vt1709},
3845 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3846 .patch = patch_vt1709},
3847 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3848 .patch = patch_vt1709},
3849 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3850 .patch = patch_vt1709},
3851 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3852 .patch = patch_vt1709},
3853 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3854 .patch = patch_vt1709},
3855 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3856 .patch = patch_vt1708B},
3857 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3858 .patch = patch_vt1708B},
3859 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3860 .patch = patch_vt1708B},
3861 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3862 .patch = patch_vt1708B},
3863 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3864 .patch = patch_vt1708B},
3865 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3866 .patch = patch_vt1708B},
3867 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3868 .patch = patch_vt1708B},
3869 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3870 .patch = patch_vt1708B},
3871 { .id = 0x11060397, .name = "VT1708S",
3872 .patch = patch_vt1708S},
3873 { .id = 0x11061397, .name = "VT1708S",
3874 .patch = patch_vt1708S},
3875 { .id = 0x11062397, .name = "VT1708S",
3876 .patch = patch_vt1708S},
3877 { .id = 0x11063397, .name = "VT1708S",
3878 .patch = patch_vt1708S},
3879 { .id = 0x11064397, .name = "VT1705",
3880 .patch = patch_vt1708S},
3881 { .id = 0x11065397, .name = "VT1708S",
3882 .patch = patch_vt1708S},
3883 { .id = 0x11066397, .name = "VT1708S",
3884 .patch = patch_vt1708S},
3885 { .id = 0x11067397, .name = "VT1708S",
3886 .patch = patch_vt1708S},
3887 { .id = 0x11060398, .name = "VT1702",
3888 .patch = patch_vt1702},
3889 { .id = 0x11061398, .name = "VT1702",
3890 .patch = patch_vt1702},
3891 { .id = 0x11062398, .name = "VT1702",
3892 .patch = patch_vt1702},
3893 { .id = 0x11063398, .name = "VT1702",
3894 .patch = patch_vt1702},
3895 { .id = 0x11064398, .name = "VT1702",
3896 .patch = patch_vt1702},
3897 { .id = 0x11065398, .name = "VT1702",
3898 .patch = patch_vt1702},
3899 { .id = 0x11066398, .name = "VT1702",
3900 .patch = patch_vt1702},
3901 { .id = 0x11067398, .name = "VT1702",
3902 .patch = patch_vt1702},
3903 { .id = 0x11060428, .name = "VT1718S",
3904 .patch = patch_vt1718S},
3905 { .id = 0x11064428, .name = "VT1718S",
3906 .patch = patch_vt1718S},
3907 { .id = 0x11060441, .name = "VT2020",
3908 .patch = patch_vt1718S},
3909 { .id = 0x11064441, .name = "VT1828S",
3910 .patch = patch_vt1718S},
3911 { .id = 0x11060433, .name = "VT1716S",
3912 .patch = patch_vt1716S},
3913 { .id = 0x1106a721, .name = "VT1716S",
3914 .patch = patch_vt1716S},
3915 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3916 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3917 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3918 { .id = 0x11060440, .name = "VT1818S",
3919 .patch = patch_vt1708S},
3920 { .id = 0x11060446, .name = "VT1802",
3921 .patch = patch_vt2002P},
3922 { .id = 0x11068446, .name = "VT1802",
3923 .patch = patch_vt2002P},
3927 MODULE_ALIAS("snd-hda-codec-id:1106*");
3929 static struct hda_codec_preset_list via_list = {
3930 .preset = snd_hda_preset_via,
3931 .owner = THIS_MODULE,
3934 MODULE_LICENSE("GPL");
3935 MODULE_DESCRIPTION("VIA HD-audio codec");
3937 static int __init patch_via_init(void)
3939 return snd_hda_add_codec_preset(&via_list);
3942 static void __exit patch_via_exit(void)
3944 snd_hda_delete_codec_preset(&via_list);
3947 module_init(patch_via_init)
3948 module_exit(patch_via_exit)