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 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
245 mutex_init(&spec->config_mutex);
248 spec->codec_type = get_codec_type(codec);
249 /* VT1708BCE & VT1708S are almost same */
250 if (spec->codec_type == VT1708BCE)
251 spec->codec_type = VT1708S;
252 snd_hda_gen_init(&spec->gen);
256 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
258 u32 vendor_id = codec->vendor_id;
259 u16 ven_id = vendor_id >> 16;
260 u16 dev_id = vendor_id & 0xffff;
261 enum VIA_HDA_CODEC codec_type;
264 if (ven_id != 0x1106)
265 codec_type = UNKNOWN;
266 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
268 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
269 codec_type = VT1709_10CH;
270 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
271 codec_type = VT1709_6CH;
272 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
273 codec_type = VT1708B_8CH;
274 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
275 codec_type = VT1708BCE;
276 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
277 codec_type = VT1708B_4CH;
278 else if ((dev_id & 0xfff) == 0x397
279 && (dev_id >> 12) < 8)
280 codec_type = VT1708S;
281 else if ((dev_id & 0xfff) == 0x398
282 && (dev_id >> 12) < 8)
284 else if ((dev_id & 0xfff) == 0x428
285 && (dev_id >> 12) < 8)
286 codec_type = VT1718S;
287 else if (dev_id == 0x0433 || dev_id == 0xa721)
288 codec_type = VT1716S;
289 else if (dev_id == 0x0441 || dev_id == 0x4441)
290 codec_type = VT1718S;
291 else if (dev_id == 0x0438 || dev_id == 0x4438)
292 codec_type = VT2002P;
293 else if (dev_id == 0x0448)
295 else if (dev_id == 0x0440)
296 codec_type = VT1708S;
297 else if ((dev_id & 0xfff) == 0x446)
300 codec_type = UNKNOWN;
304 #define VIA_JACK_EVENT 0x20
305 #define VIA_HP_EVENT 0x01
306 #define VIA_LINE_EVENT 0x03
311 VIA_CTL_WIDGET_ANALOG_MUTE,
314 static void analog_low_current_mode(struct hda_codec *codec);
315 static bool is_aa_path_mute(struct hda_codec *codec);
317 #define hp_detect_with_aa(codec) \
318 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
319 !is_aa_path_mute(codec))
321 static void vt1708_stop_hp_work(struct via_spec *spec)
323 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
325 if (spec->hp_work_active) {
326 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
327 cancel_delayed_work_sync(&spec->vt1708_hp_work);
328 spec->hp_work_active = 0;
332 static void vt1708_update_hp_work(struct via_spec *spec)
334 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
336 if (spec->vt1708_jack_detect &&
337 (spec->active_streams || hp_detect_with_aa(spec->codec))) {
338 if (!spec->hp_work_active) {
339 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
340 schedule_delayed_work(&spec->vt1708_hp_work,
341 msecs_to_jiffies(100));
342 spec->hp_work_active = 1;
344 } else if (!hp_detect_with_aa(spec->codec))
345 vt1708_stop_hp_work(spec);
348 static void set_widgets_power_state(struct hda_codec *codec)
350 struct via_spec *spec = codec->spec;
351 if (spec->set_widgets_power_state)
352 spec->set_widgets_power_state(codec);
355 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
356 struct snd_ctl_elem_value *ucontrol)
358 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
359 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
361 set_widgets_power_state(codec);
362 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
363 vt1708_update_hp_work(codec->spec);
367 /* modify .put = snd_hda_mixer_amp_switch_put */
368 #define ANALOG_INPUT_MUTE \
369 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
372 .info = snd_hda_mixer_amp_switch_info, \
373 .get = snd_hda_mixer_amp_switch_get, \
374 .put = analog_input_switch_put, \
375 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
377 static const struct snd_kcontrol_new via_control_templates[] = {
378 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
379 HDA_CODEC_MUTE(NULL, 0, 0, 0),
384 /* add dynamic controls */
385 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
386 const struct snd_kcontrol_new *tmpl,
389 struct snd_kcontrol_new *knew;
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 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
745 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
746 struct snd_ctl_elem_value *ucontrol)
748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
749 struct via_spec *spec = codec->spec;
750 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
754 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
755 struct snd_ctl_elem_value *ucontrol)
757 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
758 struct via_spec *spec = codec->spec;
759 unsigned int val = !ucontrol->value.enumerated.item[0];
761 if (val == spec->no_pin_power_ctl)
763 spec->no_pin_power_ctl = val;
764 set_widgets_power_state(codec);
765 analog_low_current_mode(codec);
769 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
770 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
771 .name = "Dynamic Power-Control",
772 .info = via_pin_power_ctl_info,
773 .get = via_pin_power_ctl_get,
774 .put = via_pin_power_ctl_put,
778 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
779 struct snd_ctl_elem_info *uinfo)
781 static const char * const texts[] = { "OFF", "ON" };
783 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
785 uinfo->value.enumerated.items = 2;
786 if (uinfo->value.enumerated.item >= 2)
787 uinfo->value.enumerated.item = 1;
788 strcpy(uinfo->value.enumerated.name,
789 texts[uinfo->value.enumerated.item]);
793 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
794 struct snd_ctl_elem_value *ucontrol)
796 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
797 struct via_spec *spec = codec->spec;
799 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
803 /* adjust spec->multiout setup according to the current flags */
804 static void setup_playback_multi_pcm(struct via_spec *spec)
806 const struct auto_pin_cfg *cfg = &spec->autocfg;
807 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
808 spec->multiout.hp_nid = 0;
809 if (!spec->hp_independent_mode) {
810 if (!spec->hp_indep_shared)
811 spec->multiout.hp_nid = spec->hp_dac_nid;
813 if (spec->hp_indep_shared)
814 spec->multiout.num_dacs = cfg->line_outs - 1;
818 /* update DAC setups according to indep-HP switch;
819 * this function is called only when indep-HP is modified
821 static void switch_indep_hp_dacs(struct hda_codec *codec)
823 struct via_spec *spec = codec->spec;
824 int shared = spec->hp_indep_shared;
825 hda_nid_t shared_dac, hp_dac;
827 if (!spec->opened_streams)
830 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
831 hp_dac = spec->hp_dac_nid;
832 if (spec->hp_independent_mode) {
833 /* switch to indep-HP mode */
834 if (spec->active_streams & STREAM_MULTI_OUT) {
835 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
836 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
838 if (spec->active_streams & STREAM_INDEP_HP)
839 snd_hda_codec_setup_stream(codec, hp_dac,
840 spec->cur_hp_stream_tag, 0,
841 spec->cur_hp_format);
843 /* back to HP or shared-DAC */
844 if (spec->active_streams & STREAM_INDEP_HP)
845 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
846 if (spec->active_streams & STREAM_MULTI_OUT) {
849 if (shared_dac) { /* reset mutli-ch DAC */
852 } else { /* reset HP DAC */
856 snd_hda_codec_setup_stream(codec, dac,
857 spec->cur_dac_stream_tag, ch,
858 spec->cur_dac_format);
861 setup_playback_multi_pcm(spec);
864 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
865 struct snd_ctl_elem_value *ucontrol)
867 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
868 struct via_spec *spec = codec->spec;
871 mutex_lock(&spec->config_mutex);
872 cur = !!ucontrol->value.enumerated.item[0];
873 if (spec->hp_independent_mode == cur) {
874 mutex_unlock(&spec->config_mutex);
877 spec->hp_independent_mode = cur;
878 shared = spec->hp_indep_shared;
879 deactivate_hp_paths(codec);
881 activate_output_path(codec, &spec->hp_indep_path, true, false);
884 activate_output_path(codec, &spec->out_path[shared],
886 if (spec->aamix_mode || !spec->hp_path.depth)
887 activate_output_path(codec, &spec->hp_mix_path,
890 activate_output_path(codec, &spec->hp_path,
894 switch_indep_hp_dacs(codec);
895 mutex_unlock(&spec->config_mutex);
897 /* update jack power state */
898 set_widgets_power_state(codec);
899 via_hp_automute(codec);
903 static const struct snd_kcontrol_new via_hp_mixer = {
904 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
905 .name = "Independent HP",
906 .info = via_independent_hp_info,
907 .get = via_independent_hp_get,
908 .put = via_independent_hp_put,
911 static int via_hp_build(struct hda_codec *codec)
913 struct via_spec *spec = codec->spec;
914 struct snd_kcontrol_new *knew;
917 nid = spec->autocfg.hp_pins[0];
918 knew = via_clone_control(spec, &via_hp_mixer);
922 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
927 static void notify_aa_path_ctls(struct hda_codec *codec)
929 struct via_spec *spec = codec->spec;
932 for (i = 0; i < spec->smart51_nums; i++) {
933 struct snd_kcontrol *ctl;
934 struct snd_ctl_elem_id id;
935 memset(&id, 0, sizeof(id));
936 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
937 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
938 ctl = snd_hda_find_mixer_ctl(codec, id.name);
940 snd_ctl_notify(codec->bus->card,
941 SNDRV_CTL_EVENT_MASK_VALUE,
946 static void mute_aa_path(struct hda_codec *codec, int mute)
948 struct via_spec *spec = codec->spec;
949 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
952 /* check AA path's mute status */
953 for (i = 0; i < spec->smart51_nums; i++) {
954 if (spec->smart51_idxs[i] < 0)
956 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
957 HDA_INPUT, spec->smart51_idxs[i],
962 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
964 struct via_spec *spec = codec->spec;
967 for (i = 0; i < spec->smart51_nums; i++)
968 if (spec->smart51_pins[i] == pin)
973 static int via_smart51_get(struct snd_kcontrol *kcontrol,
974 struct snd_ctl_elem_value *ucontrol)
976 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
977 struct via_spec *spec = codec->spec;
979 *ucontrol->value.integer.value = spec->smart51_enabled;
983 static int via_smart51_put(struct snd_kcontrol *kcontrol,
984 struct snd_ctl_elem_value *ucontrol)
986 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
987 struct via_spec *spec = codec->spec;
988 int out_in = *ucontrol->value.integer.value
989 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
992 for (i = 0; i < spec->smart51_nums; i++) {
993 hda_nid_t nid = spec->smart51_pins[i];
996 parm = snd_hda_codec_read(codec, nid, 0,
997 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
998 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1000 snd_hda_set_pin_ctl(codec, nid, parm);
1001 if (out_in == AC_PINCTL_OUT_EN) {
1002 mute_aa_path(codec, 1);
1003 notify_aa_path_ctls(codec);
1006 spec->smart51_enabled = *ucontrol->value.integer.value;
1007 set_widgets_power_state(codec);
1011 static const struct snd_kcontrol_new via_smart51_mixer = {
1012 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1013 .name = "Smart 5.1",
1015 .info = snd_ctl_boolean_mono_info,
1016 .get = via_smart51_get,
1017 .put = via_smart51_put,
1020 static int via_smart51_build(struct hda_codec *codec)
1022 struct via_spec *spec = codec->spec;
1024 if (!spec->smart51_nums)
1026 if (!via_clone_control(spec, &via_smart51_mixer))
1031 /* check AA path's mute status */
1032 static bool is_aa_path_mute(struct hda_codec *codec)
1034 struct via_spec *spec = codec->spec;
1035 const struct hda_amp_list *p;
1038 for (i = 0; i < spec->num_loopbacks; i++) {
1039 p = &spec->loopback_list[i];
1040 for (ch = 0; ch < 2; ch++) {
1041 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1043 if (!(v & HDA_AMP_MUTE) && v > 0)
1050 /* enter/exit analog low-current mode */
1051 static void __analog_low_current_mode(struct hda_codec *codec, bool force)
1053 struct via_spec *spec = codec->spec;
1055 unsigned int verb, parm;
1057 if (spec->no_pin_power_ctl)
1060 enable = is_aa_path_mute(codec) && !spec->opened_streams;
1061 if (enable == spec->alc_mode && !force)
1063 spec->alc_mode = enable;
1065 /* decide low current mode's verb & parameter */
1066 switch (spec->codec_type) {
1070 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1076 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1080 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1086 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1089 return; /* other codecs are not supported */
1092 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1095 static void analog_low_current_mode(struct hda_codec *codec)
1097 return __analog_low_current_mode(codec, false);
1101 * generic initialization of ADC, input mixers and output mixers
1103 static const struct hda_verb vt1708_init_verbs[] = {
1104 /* power down jack detect function */
1109 static void set_stream_open(struct hda_codec *codec, int bit, bool active)
1111 struct via_spec *spec = codec->spec;
1114 spec->opened_streams |= bit;
1116 spec->opened_streams &= ~bit;
1117 analog_low_current_mode(codec);
1120 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1121 struct hda_codec *codec,
1122 struct snd_pcm_substream *substream)
1124 struct via_spec *spec = codec->spec;
1125 const struct auto_pin_cfg *cfg = &spec->autocfg;
1128 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1129 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1130 set_stream_open(codec, STREAM_MULTI_OUT, true);
1131 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1134 set_stream_open(codec, STREAM_MULTI_OUT, false);
1140 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1141 struct hda_codec *codec,
1142 struct snd_pcm_substream *substream)
1144 set_stream_open(codec, STREAM_MULTI_OUT, false);
1148 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1149 struct hda_codec *codec,
1150 struct snd_pcm_substream *substream)
1152 struct via_spec *spec = codec->spec;
1154 if (snd_BUG_ON(!spec->hp_dac_nid))
1156 set_stream_open(codec, STREAM_INDEP_HP, true);
1160 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1161 struct hda_codec *codec,
1162 struct snd_pcm_substream *substream)
1164 set_stream_open(codec, STREAM_INDEP_HP, false);
1168 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1169 struct hda_codec *codec,
1170 unsigned int stream_tag,
1171 unsigned int format,
1172 struct snd_pcm_substream *substream)
1174 struct via_spec *spec = codec->spec;
1176 mutex_lock(&spec->config_mutex);
1177 setup_playback_multi_pcm(spec);
1178 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1180 /* remember for dynamic DAC switch with indep-HP */
1181 spec->active_streams |= STREAM_MULTI_OUT;
1182 spec->cur_dac_stream_tag = stream_tag;
1183 spec->cur_dac_format = format;
1184 mutex_unlock(&spec->config_mutex);
1185 vt1708_update_hp_work(spec);
1189 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1190 struct hda_codec *codec,
1191 unsigned int stream_tag,
1192 unsigned int format,
1193 struct snd_pcm_substream *substream)
1195 struct via_spec *spec = codec->spec;
1197 mutex_lock(&spec->config_mutex);
1198 if (spec->hp_independent_mode)
1199 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1200 stream_tag, 0, format);
1201 spec->active_streams |= STREAM_INDEP_HP;
1202 spec->cur_hp_stream_tag = stream_tag;
1203 spec->cur_hp_format = format;
1204 mutex_unlock(&spec->config_mutex);
1205 vt1708_update_hp_work(spec);
1209 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1210 struct hda_codec *codec,
1211 struct snd_pcm_substream *substream)
1213 struct via_spec *spec = codec->spec;
1215 mutex_lock(&spec->config_mutex);
1216 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1217 spec->active_streams &= ~STREAM_MULTI_OUT;
1218 mutex_unlock(&spec->config_mutex);
1219 vt1708_update_hp_work(spec);
1223 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1224 struct hda_codec *codec,
1225 struct snd_pcm_substream *substream)
1227 struct via_spec *spec = codec->spec;
1229 mutex_lock(&spec->config_mutex);
1230 if (spec->hp_independent_mode)
1231 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1232 spec->active_streams &= ~STREAM_INDEP_HP;
1233 mutex_unlock(&spec->config_mutex);
1234 vt1708_update_hp_work(spec);
1241 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1242 struct hda_codec *codec,
1243 struct snd_pcm_substream *substream)
1245 struct via_spec *spec = codec->spec;
1246 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1249 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1250 struct hda_codec *codec,
1251 struct snd_pcm_substream *substream)
1253 struct via_spec *spec = codec->spec;
1254 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1257 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1258 struct hda_codec *codec,
1259 unsigned int stream_tag,
1260 unsigned int format,
1261 struct snd_pcm_substream *substream)
1263 struct via_spec *spec = codec->spec;
1264 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1265 stream_tag, format, substream);
1268 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1269 struct hda_codec *codec,
1270 struct snd_pcm_substream *substream)
1272 struct via_spec *spec = codec->spec;
1273 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1280 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1281 struct hda_codec *codec,
1282 unsigned int stream_tag,
1283 unsigned int format,
1284 struct snd_pcm_substream *substream)
1286 struct via_spec *spec = codec->spec;
1288 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1289 stream_tag, 0, format);
1293 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1294 struct hda_codec *codec,
1295 struct snd_pcm_substream *substream)
1297 struct via_spec *spec = codec->spec;
1298 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1302 /* analog capture with dynamic ADC switching */
1303 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1304 struct hda_codec *codec,
1305 unsigned int stream_tag,
1306 unsigned int format,
1307 struct snd_pcm_substream *substream)
1309 struct via_spec *spec = codec->spec;
1310 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1312 mutex_lock(&spec->config_mutex);
1313 spec->cur_adc = spec->adc_nids[adc_idx];
1314 spec->cur_adc_stream_tag = stream_tag;
1315 spec->cur_adc_format = format;
1316 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1317 mutex_unlock(&spec->config_mutex);
1321 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1322 struct hda_codec *codec,
1323 struct snd_pcm_substream *substream)
1325 struct via_spec *spec = codec->spec;
1327 mutex_lock(&spec->config_mutex);
1328 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1330 mutex_unlock(&spec->config_mutex);
1334 /* re-setup the stream if running; called from input-src put */
1335 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1337 struct via_spec *spec = codec->spec;
1338 int adc_idx = spec->inputs[cur].adc_idx;
1339 hda_nid_t adc = spec->adc_nids[adc_idx];
1342 mutex_lock(&spec->config_mutex);
1343 if (spec->cur_adc && spec->cur_adc != adc) {
1344 /* stream is running, let's swap the current ADC */
1345 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1346 spec->cur_adc = adc;
1347 snd_hda_codec_setup_stream(codec, adc,
1348 spec->cur_adc_stream_tag, 0,
1349 spec->cur_adc_format);
1352 mutex_unlock(&spec->config_mutex);
1356 static const struct hda_pcm_stream via_pcm_analog_playback = {
1360 /* NID is set in via_build_pcms */
1362 .open = via_playback_multi_pcm_open,
1363 .close = via_playback_multi_pcm_close,
1364 .prepare = via_playback_multi_pcm_prepare,
1365 .cleanup = via_playback_multi_pcm_cleanup
1369 static const struct hda_pcm_stream via_pcm_hp_playback = {
1373 /* NID is set in via_build_pcms */
1375 .open = via_playback_hp_pcm_open,
1376 .close = via_playback_hp_pcm_close,
1377 .prepare = via_playback_hp_pcm_prepare,
1378 .cleanup = via_playback_hp_pcm_cleanup
1382 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1386 /* NID is set in via_build_pcms */
1387 /* We got noisy outputs on the right channel on VT1708 when
1388 * 24bit samples are used. Until any workaround is found,
1389 * disable the 24bit format, so far.
1391 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1393 .open = via_playback_multi_pcm_open,
1394 .close = via_playback_multi_pcm_close,
1395 .prepare = via_playback_multi_pcm_prepare,
1396 .cleanup = via_playback_multi_pcm_cleanup
1400 static const struct hda_pcm_stream via_pcm_analog_capture = {
1401 .substreams = 1, /* will be changed in via_build_pcms() */
1404 /* NID is set in via_build_pcms */
1406 .prepare = via_capture_pcm_prepare,
1407 .cleanup = via_capture_pcm_cleanup
1411 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1415 /* NID is set in via_build_pcms */
1417 .prepare = via_dyn_adc_capture_pcm_prepare,
1418 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1422 static const struct hda_pcm_stream via_pcm_digital_playback = {
1426 /* NID is set in via_build_pcms */
1428 .open = via_dig_playback_pcm_open,
1429 .close = via_dig_playback_pcm_close,
1430 .prepare = via_dig_playback_pcm_prepare,
1431 .cleanup = via_dig_playback_pcm_cleanup
1435 static const struct hda_pcm_stream via_pcm_digital_capture = {
1442 * slave controls for virtual master
1444 static const char * const via_slave_pfxs[] = {
1445 "Front", "Surround", "Center", "LFE", "Side",
1446 "Headphone", "Speaker", "Bass Speaker",
1450 static int via_build_controls(struct hda_codec *codec)
1452 struct via_spec *spec = codec->spec;
1453 struct snd_kcontrol *kctl;
1456 spec->no_pin_power_ctl = 1;
1457 if (spec->set_widgets_power_state)
1458 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1461 for (i = 0; i < spec->num_mixers; i++) {
1462 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1467 if (spec->multiout.dig_out_nid) {
1468 err = snd_hda_create_spdif_out_ctls(codec,
1469 spec->multiout.dig_out_nid,
1470 spec->multiout.dig_out_nid);
1473 err = snd_hda_create_spdif_share_sw(codec,
1477 spec->multiout.share_spdif = 1;
1479 if (spec->dig_in_nid) {
1480 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1485 /* if we have no master control, let's create it */
1486 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1487 unsigned int vmaster_tlv[4];
1488 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1489 HDA_OUTPUT, vmaster_tlv);
1490 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1491 vmaster_tlv, via_slave_pfxs,
1496 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1497 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1498 NULL, via_slave_pfxs,
1504 /* assign Capture Source enums to NID */
1505 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1506 for (i = 0; kctl && i < kctl->count; i++) {
1507 if (!spec->mux_nids[i])
1509 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1514 via_free_kctls(codec); /* no longer needed */
1516 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1523 static int via_build_pcms(struct hda_codec *codec)
1525 struct via_spec *spec = codec->spec;
1526 struct hda_pcm *info = spec->pcm_rec;
1528 codec->num_pcms = 0;
1529 codec->pcm_info = info;
1531 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1532 snprintf(spec->stream_name_analog,
1533 sizeof(spec->stream_name_analog),
1534 "%s Analog", codec->chip_name);
1535 info->name = spec->stream_name_analog;
1537 if (spec->multiout.num_dacs) {
1538 if (!spec->stream_analog_playback)
1539 spec->stream_analog_playback =
1540 &via_pcm_analog_playback;
1541 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1542 *spec->stream_analog_playback;
1543 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1544 spec->multiout.dac_nids[0];
1545 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1546 spec->multiout.max_channels;
1547 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT
1548 && spec->autocfg.line_outs == 2)
1549 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1553 if (!spec->stream_analog_capture) {
1554 if (spec->dyn_adc_switch)
1555 spec->stream_analog_capture =
1556 &via_pcm_dyn_adc_analog_capture;
1558 spec->stream_analog_capture =
1559 &via_pcm_analog_capture;
1561 if (spec->num_adc_nids) {
1562 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1563 *spec->stream_analog_capture;
1564 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1566 if (!spec->dyn_adc_switch)
1567 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1574 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1575 snprintf(spec->stream_name_digital,
1576 sizeof(spec->stream_name_digital),
1577 "%s Digital", codec->chip_name);
1578 info->name = spec->stream_name_digital;
1579 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1580 if (spec->multiout.dig_out_nid) {
1581 if (!spec->stream_digital_playback)
1582 spec->stream_digital_playback =
1583 &via_pcm_digital_playback;
1584 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1585 *spec->stream_digital_playback;
1586 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1587 spec->multiout.dig_out_nid;
1589 if (spec->dig_in_nid) {
1590 if (!spec->stream_digital_capture)
1591 spec->stream_digital_capture =
1592 &via_pcm_digital_capture;
1593 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1594 *spec->stream_digital_capture;
1595 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1602 if (spec->hp_dac_nid) {
1603 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1604 "%s HP", codec->chip_name);
1605 info->name = spec->stream_name_hp;
1606 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1607 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1615 static void via_free(struct hda_codec *codec)
1617 struct via_spec *spec = codec->spec;
1622 via_free_kctls(codec);
1623 vt1708_stop_hp_work(spec);
1624 kfree(spec->bind_cap_vol);
1625 kfree(spec->bind_cap_sw);
1626 snd_hda_gen_free(&spec->gen);
1630 /* mute/unmute outputs */
1631 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1632 hda_nid_t *pins, bool mute)
1635 for (i = 0; i < num_pins; i++) {
1636 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1637 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1638 if (parm & AC_PINCTL_IN_EN)
1641 parm &= ~AC_PINCTL_OUT_EN;
1643 parm |= AC_PINCTL_OUT_EN;
1644 snd_hda_set_pin_ctl(codec, pins[i], parm);
1648 /* mute internal speaker if line-out is plugged */
1649 static void via_line_automute(struct hda_codec *codec, int present)
1651 struct via_spec *spec = codec->spec;
1653 if (!spec->autocfg.speaker_outs)
1656 present = snd_hda_jack_detect(codec,
1657 spec->autocfg.line_out_pins[0]);
1658 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1659 spec->autocfg.speaker_pins,
1663 /* mute internal speaker if HP is plugged */
1664 static void via_hp_automute(struct hda_codec *codec)
1668 struct via_spec *spec = codec->spec;
1670 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
1671 (spec->codec_type != VT1708 || spec->vt1708_jack_detect) &&
1672 is_jack_detectable(codec, spec->autocfg.hp_pins[0]))
1673 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1675 if (spec->smart51_enabled)
1676 nums = spec->autocfg.line_outs + spec->smart51_nums;
1678 nums = spec->autocfg.line_outs;
1679 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1681 via_line_automute(codec, present);
1685 static int via_suspend(struct hda_codec *codec)
1687 struct via_spec *spec = codec->spec;
1688 vt1708_stop_hp_work(spec);
1690 if (spec->codec_type == VT1802) {
1691 /* Fix pop noise on headphones */
1693 for (i = 0; i < spec->autocfg.hp_outs; i++)
1694 snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0);
1702 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1704 struct via_spec *spec = codec->spec;
1705 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1712 static int via_init(struct hda_codec *codec);
1714 static const struct hda_codec_ops via_patch_ops = {
1715 .build_controls = via_build_controls,
1716 .build_pcms = via_build_pcms,
1719 .unsol_event = snd_hda_jack_unsol_event,
1721 .suspend = via_suspend,
1722 .check_power_status = via_check_power_status,
1726 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1728 struct via_spec *spec = codec->spec;
1731 for (i = 0; i < spec->multiout.num_dacs; i++) {
1732 if (spec->multiout.dac_nids[i] == dac)
1735 if (spec->hp_dac_nid == dac)
1740 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1741 hda_nid_t target_dac, int with_aa_mix,
1742 struct nid_path *path, int depth)
1744 struct via_spec *spec = codec->spec;
1748 if (nid == spec->aa_mix_nid) {
1751 with_aa_mix = 2; /* mark aa-mix is included */
1754 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1755 for (i = 0; i < nums; i++) {
1756 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1758 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1759 /* aa-mix is requested but not included? */
1760 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1764 if (depth >= MAX_NID_PATH_DEPTH)
1766 for (i = 0; i < nums; i++) {
1768 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1769 if (type == AC_WID_AUD_OUT)
1771 if (__parse_output_path(codec, conn[i], target_dac,
1772 with_aa_mix, path, depth + 1))
1778 path->path[path->depth] = conn[i];
1779 path->idx[path->depth] = i;
1780 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1781 path->multi[path->depth] = 1;
1786 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1787 hda_nid_t target_dac, int with_aa_mix,
1788 struct nid_path *path)
1790 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
1791 path->path[path->depth] = nid;
1793 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1794 path->depth, path->path[0], path->path[1],
1795 path->path[2], path->path[3], path->path[4]);
1801 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1803 struct via_spec *spec = codec->spec;
1804 const struct auto_pin_cfg *cfg = &spec->autocfg;
1808 spec->multiout.num_dacs = 0;
1809 spec->multiout.dac_nids = spec->private_dac_nids;
1810 for (i = 0; i < cfg->line_outs; i++) {
1812 nid = cfg->line_out_pins[i];
1815 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1816 dac = spec->out_path[i].path[0];
1817 if (!i && parse_output_path(codec, nid, dac, 1,
1818 &spec->out_mix_path))
1819 dac = spec->out_mix_path.path[0];
1821 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
1823 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1824 spec->out_path[0] = spec->out_mix_path;
1825 spec->out_mix_path.depth = 0;
1830 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1831 int chs, bool check_dac, struct nid_path *path)
1833 struct via_spec *spec = codec->spec;
1835 hda_nid_t dac, pin, sel, nid;
1838 dac = check_dac ? path->path[0] : 0;
1839 pin = path->path[path->depth - 1];
1840 sel = path->depth > 1 ? path->path[1] : 0;
1842 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1844 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1846 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1851 sprintf(name, "%s Playback Volume", pfx);
1852 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1853 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1856 path->vol_ctl = nid;
1859 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1861 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1863 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1868 sprintf(name, "%s Playback Switch", pfx);
1869 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1870 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1873 path->mute_ctl = nid;
1878 static void mangle_smart51(struct hda_codec *codec)
1880 struct via_spec *spec = codec->spec;
1881 struct auto_pin_cfg *cfg = &spec->autocfg;
1882 struct auto_pin_cfg_item *ins = cfg->inputs;
1883 int i, j, nums, attr;
1884 int pins[AUTO_CFG_MAX_INS];
1886 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1888 for (i = 0; i < cfg->num_inputs; i++) {
1890 if (ins[i].type > AUTO_PIN_LINE_IN)
1892 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1893 if (snd_hda_get_input_pin_attr(def) != attr)
1895 for (j = 0; j < nums; j++)
1896 if (ins[pins[j]].type < ins[i].type) {
1897 memmove(pins + j + 1, pins + j,
1898 (nums - j) * sizeof(int));
1904 if (cfg->line_outs + nums < 3)
1906 for (i = 0; i < nums; i++) {
1907 hda_nid_t pin = ins[pins[i]].pin;
1908 spec->smart51_pins[spec->smart51_nums++] = pin;
1909 cfg->line_out_pins[cfg->line_outs++] = pin;
1910 if (cfg->line_outs == 3)
1917 static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1919 dst->vol_ctl = src->vol_ctl;
1920 dst->mute_ctl = src->mute_ctl;
1923 /* add playback controls from the parsed DAC table */
1924 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1926 struct via_spec *spec = codec->spec;
1927 struct auto_pin_cfg *cfg = &spec->autocfg;
1928 struct nid_path *path;
1929 static const char * const chname[4] = {
1930 "Front", "Surround", NULL /* "CLFE" */, "Side"
1936 old_line_outs = cfg->line_outs;
1937 if (cfg->line_outs == 1)
1938 mangle_smart51(codec);
1940 err = via_auto_fill_dac_nids(codec);
1944 if (spec->multiout.num_dacs < 3) {
1945 spec->smart51_nums = 0;
1946 cfg->line_outs = old_line_outs;
1948 for (i = 0; i < cfg->line_outs; i++) {
1950 pin = cfg->line_out_pins[i];
1951 dac = spec->multiout.dac_nids[i];
1954 path = spec->out_path + i;
1955 if (i == HDA_CLFE) {
1956 err = create_ch_ctls(codec, "Center", 1, true, path);
1959 err = create_ch_ctls(codec, "LFE", 2, true, path);
1963 const char *pfx = chname[i];
1964 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1965 cfg->line_outs <= 2)
1966 pfx = i ? "Bass Speaker" : "Speaker";
1967 err = create_ch_ctls(codec, pfx, 3, true, path);
1971 if (path != spec->out_path + i)
1972 copy_path_mixer_ctls(&spec->out_path[i], path);
1973 if (path == spec->out_path && spec->out_mix_path.depth)
1974 copy_path_mixer_ctls(&spec->out_mix_path, path);
1977 idx = get_connection_index(codec, spec->aa_mix_nid,
1978 spec->multiout.dac_nids[0]);
1980 /* add control to mixer */
1982 name = spec->out_mix_path.depth ?
1983 "PCM Loopback Playback Volume" : "PCM Playback Volume";
1984 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1985 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1989 name = spec->out_mix_path.depth ?
1990 "PCM Loopback Playback Switch" : "PCM Playback Switch";
1991 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1992 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1998 cfg->line_outs = old_line_outs;
2003 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
2005 struct via_spec *spec = codec->spec;
2006 struct nid_path *path;
2013 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2014 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2015 if (i < spec->multiout.num_dacs &&
2016 parse_output_path(codec, pin,
2017 spec->multiout.dac_nids[i], 0,
2018 &spec->hp_indep_path)) {
2019 spec->hp_indep_shared = i;
2024 if (spec->hp_indep_path.depth) {
2025 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2026 if (!spec->hp_indep_shared)
2027 spec->hp_path = spec->hp_indep_path;
2029 /* optionally check front-path w/o AA-mix */
2030 if (!spec->hp_path.depth)
2031 parse_output_path(codec, pin,
2032 spec->multiout.dac_nids[HDA_FRONT], 0,
2035 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2036 1, &spec->hp_mix_path) && !spec->hp_path.depth)
2039 if (spec->hp_path.depth) {
2040 path = &spec->hp_path;
2043 path = &spec->hp_mix_path;
2046 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
2050 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2052 copy_path_mixer_ctls(&spec->hp_path, path);
2053 if (spec->hp_indep_path.depth)
2054 copy_path_mixer_ctls(&spec->hp_indep_path, path);
2058 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2060 struct via_spec *spec = codec->spec;
2061 struct nid_path *path;
2063 hda_nid_t pin, dac = 0;
2066 pin = spec->autocfg.speaker_pins[0];
2067 if (!spec->autocfg.speaker_outs || !pin)
2070 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
2071 dac = spec->speaker_path.path[0];
2073 parse_output_path(codec, pin,
2074 spec->multiout.dac_nids[HDA_FRONT], 0,
2075 &spec->speaker_path);
2076 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2077 1, &spec->speaker_mix_path) && !dac)
2080 /* no AA-path for front? */
2081 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2084 spec->speaker_dac_nid = dac;
2085 spec->multiout.extra_out_nid[0] = dac;
2087 path = &spec->speaker_path;
2090 path = &spec->speaker_mix_path;
2093 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2097 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2099 copy_path_mixer_ctls(&spec->speaker_path, path);
2103 #define via_aamix_ctl_info via_pin_power_ctl_info
2105 static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2106 struct snd_ctl_elem_value *ucontrol)
2108 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2109 struct via_spec *spec = codec->spec;
2110 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2114 static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2115 struct nid_path *nomix, struct nid_path *mix)
2118 activate_output_path(codec, nomix, false, false);
2119 activate_output_path(codec, mix, true, false);
2121 activate_output_path(codec, mix, false, false);
2122 activate_output_path(codec, nomix, true, false);
2126 static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2127 struct snd_ctl_elem_value *ucontrol)
2129 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2130 struct via_spec *spec = codec->spec;
2131 unsigned int val = ucontrol->value.enumerated.item[0];
2133 if (val == spec->aamix_mode)
2135 spec->aamix_mode = val;
2136 /* update front path */
2137 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2138 /* update HP path */
2139 if (!spec->hp_independent_mode) {
2140 update_aamix_paths(codec, val, &spec->hp_path,
2141 &spec->hp_mix_path);
2143 /* update speaker path */
2144 update_aamix_paths(codec, val, &spec->speaker_path,
2145 &spec->speaker_mix_path);
2149 static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2150 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2151 .name = "Loopback Mixing",
2152 .info = via_aamix_ctl_info,
2153 .get = via_aamix_ctl_get,
2154 .put = via_aamix_ctl_put,
2157 static int via_auto_create_loopback_switch(struct hda_codec *codec)
2159 struct via_spec *spec = codec->spec;
2161 if (!spec->aa_mix_nid)
2162 return 0; /* no loopback switching available */
2163 if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
2164 spec->speaker_path.depth))
2165 return 0; /* no loopback switching available */
2166 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2172 static int via_fill_adcs(struct hda_codec *codec)
2174 struct via_spec *spec = codec->spec;
2175 hda_nid_t nid = codec->start_nid;
2178 for (i = 0; i < codec->num_nodes; i++, nid++) {
2179 unsigned int wcaps = get_wcaps(codec, nid);
2180 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2182 if (wcaps & AC_WCAP_DIGITAL)
2184 if (!(wcaps & AC_WCAP_CONN_LIST))
2186 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2188 spec->adc_nids[spec->num_adc_nids++] = nid;
2193 /* input-src control */
2194 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2195 struct snd_ctl_elem_info *uinfo)
2197 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2198 struct via_spec *spec = codec->spec;
2200 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2202 uinfo->value.enumerated.items = spec->num_inputs;
2203 if (uinfo->value.enumerated.item >= spec->num_inputs)
2204 uinfo->value.enumerated.item = spec->num_inputs - 1;
2205 strcpy(uinfo->value.enumerated.name,
2206 spec->inputs[uinfo->value.enumerated.item].label);
2210 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2211 struct snd_ctl_elem_value *ucontrol)
2213 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2214 struct via_spec *spec = codec->spec;
2215 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2217 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2221 static int via_mux_enum_put(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);
2230 cur = ucontrol->value.enumerated.item[0];
2231 if (cur < 0 || cur >= spec->num_inputs)
2233 if (spec->cur_mux[idx] == cur)
2235 spec->cur_mux[idx] = cur;
2236 if (spec->dyn_adc_switch) {
2237 int adc_idx = spec->inputs[cur].adc_idx;
2238 mux = spec->mux_nids[adc_idx];
2239 via_dyn_adc_pcm_resetup(codec, cur);
2241 mux = spec->mux_nids[idx];
2242 if (snd_BUG_ON(!mux))
2247 /* switch to D0 beofre change index */
2248 update_power_state(codec, mux, AC_PWRST_D0);
2249 snd_hda_codec_write(codec, mux, 0,
2250 AC_VERB_SET_CONNECT_SEL,
2251 spec->inputs[cur].mux_idx);
2254 /* update jack power state */
2255 set_widgets_power_state(codec);
2259 static const struct snd_kcontrol_new via_input_src_ctl = {
2260 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2261 /* The multiple "Capture Source" controls confuse alsamixer
2262 * So call somewhat different..
2264 /* .name = "Capture Source", */
2265 .name = "Input Source",
2266 .info = via_mux_enum_info,
2267 .get = via_mux_enum_get,
2268 .put = via_mux_enum_put,
2271 static int create_input_src_ctls(struct hda_codec *codec, int count)
2273 struct via_spec *spec = codec->spec;
2274 struct snd_kcontrol_new *knew;
2276 if (spec->num_inputs <= 1 || !count)
2277 return 0; /* no need for single src */
2279 knew = via_clone_control(spec, &via_input_src_ctl);
2282 knew->count = count;
2286 /* add the powersave loopback-list entry */
2287 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2289 struct hda_amp_list *list;
2291 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2293 list = spec->loopback_list + spec->num_loopbacks;
2295 list->dir = HDA_INPUT;
2297 spec->num_loopbacks++;
2298 spec->loopback.amplist = spec->loopback_list;
2301 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2304 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2307 /* add the input-route to the given pin */
2308 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2310 struct via_spec *spec = codec->spec;
2313 spec->inputs[spec->num_inputs].adc_idx = -1;
2314 spec->inputs[spec->num_inputs].pin = pin;
2315 for (c = 0; c < spec->num_adc_nids; c++) {
2316 if (spec->mux_nids[c]) {
2317 idx = get_connection_index(codec, spec->mux_nids[c],
2321 spec->inputs[spec->num_inputs].mux_idx = idx;
2323 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2326 spec->inputs[spec->num_inputs].adc_idx = c;
2327 /* Can primary ADC satisfy all inputs? */
2328 if (!spec->dyn_adc_switch &&
2329 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2330 snd_printd(KERN_INFO
2331 "via: dynamic ADC switching enabled\n");
2332 spec->dyn_adc_switch = 1;
2339 static int get_mux_nids(struct hda_codec *codec);
2341 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2342 static int parse_analog_inputs(struct hda_codec *codec)
2344 struct via_spec *spec = codec->spec;
2345 const struct auto_pin_cfg *cfg = &spec->autocfg;
2348 err = via_fill_adcs(codec);
2351 err = get_mux_nids(codec);
2355 /* fill all input-routes */
2356 for (i = 0; i < cfg->num_inputs; i++) {
2357 if (add_input_route(codec, cfg->inputs[i].pin))
2358 spec->inputs[spec->num_inputs++].label =
2359 hda_get_autocfg_input_label(codec, cfg, i);
2362 /* check for internal loopback recording */
2363 if (spec->aa_mix_nid &&
2364 add_input_route(codec, spec->aa_mix_nid))
2365 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2370 /* create analog-loopback volume/switch controls */
2371 static int create_loopback_ctls(struct hda_codec *codec)
2373 struct via_spec *spec = codec->spec;
2374 const struct auto_pin_cfg *cfg = &spec->autocfg;
2375 const char *prev_label = NULL;
2379 if (!spec->aa_mix_nid)
2382 for (i = 0; i < cfg->num_inputs; i++) {
2383 hda_nid_t pin = cfg->inputs[i].pin;
2384 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2386 if (prev_label && !strcmp(label, prev_label))
2391 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2393 err = via_new_analog_input(spec, label, type_idx,
2394 idx, spec->aa_mix_nid);
2397 add_loopback_list(spec, spec->aa_mix_nid, idx);
2400 /* remember the label for smart51 control */
2401 for (j = 0; j < spec->smart51_nums; j++) {
2402 if (spec->smart51_pins[j] == pin) {
2403 spec->smart51_idxs[j] = idx;
2404 spec->smart51_labels[j] = label;
2412 /* create mic-boost controls (if present) */
2413 static int create_mic_boost_ctls(struct hda_codec *codec)
2415 struct via_spec *spec = codec->spec;
2416 const struct auto_pin_cfg *cfg = &spec->autocfg;
2417 const char *prev_label = NULL;
2421 for (i = 0; i < cfg->num_inputs; i++) {
2422 hda_nid_t pin = cfg->inputs[i].pin;
2427 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2429 caps = query_amp_caps(codec, pin, HDA_INPUT);
2430 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2432 label = hda_get_autocfg_input_label(codec, cfg, i);
2433 if (prev_label && !strcmp(label, prev_label))
2438 snprintf(name, sizeof(name), "%s Boost Volume", label);
2439 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
2440 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2447 /* create capture and input-src controls for multiple streams */
2448 static int create_multi_adc_ctls(struct hda_codec *codec)
2450 struct via_spec *spec = codec->spec;
2453 /* create capture mixer elements */
2454 for (i = 0; i < spec->num_adc_nids; i++) {
2455 hda_nid_t adc = spec->adc_nids[i];
2456 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2457 "Capture Volume", i,
2458 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2462 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2463 "Capture Switch", i,
2464 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2470 /* input-source control */
2471 for (i = 0; i < spec->num_adc_nids; i++)
2472 if (!spec->mux_nids[i])
2474 err = create_input_src_ctls(codec, i);
2480 /* bind capture volume/switch */
2481 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2482 HDA_BIND_VOL("Capture Volume", 0);
2483 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2484 HDA_BIND_SW("Capture Switch", 0);
2486 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2487 struct hda_ctl_ops *ops)
2489 struct hda_bind_ctls *ctl;
2492 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2496 for (i = 0; i < spec->num_adc_nids; i++)
2498 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2503 /* create capture and input-src controls for dynamic ADC-switch case */
2504 static int create_dyn_adc_ctls(struct hda_codec *codec)
2506 struct via_spec *spec = codec->spec;
2507 struct snd_kcontrol_new *knew;
2510 /* set up the bind capture ctls */
2511 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2514 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2518 /* create capture mixer elements */
2519 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2522 knew->private_value = (long)spec->bind_cap_vol;
2524 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2527 knew->private_value = (long)spec->bind_cap_sw;
2529 /* input-source control */
2530 err = create_input_src_ctls(codec, 1);
2536 /* parse and create capture-related stuff */
2537 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2539 struct via_spec *spec = codec->spec;
2542 err = parse_analog_inputs(codec);
2545 if (spec->dyn_adc_switch)
2546 err = create_dyn_adc_ctls(codec);
2548 err = create_multi_adc_ctls(codec);
2551 err = create_loopback_ctls(codec);
2554 err = create_mic_boost_ctls(codec);
2560 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2562 unsigned int def_conf;
2563 unsigned char seqassoc;
2565 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2566 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2567 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2568 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2569 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2570 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2571 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2577 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2578 struct snd_ctl_elem_value *ucontrol)
2580 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2581 struct via_spec *spec = codec->spec;
2583 if (spec->codec_type != VT1708)
2585 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2589 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2590 struct snd_ctl_elem_value *ucontrol)
2592 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2593 struct via_spec *spec = codec->spec;
2596 if (spec->codec_type != VT1708)
2598 val = !!ucontrol->value.integer.value[0];
2599 if (spec->vt1708_jack_detect == val)
2601 spec->vt1708_jack_detect = val;
2602 if (spec->vt1708_jack_detect &&
2603 snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
2604 mute_aa_path(codec, 1);
2605 notify_aa_path_ctls(codec);
2607 via_hp_automute(codec);
2608 vt1708_update_hp_work(spec);
2612 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2613 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2614 .name = "Jack Detect",
2616 .info = snd_ctl_boolean_mono_info,
2617 .get = vt1708_jack_detect_get,
2618 .put = vt1708_jack_detect_put,
2621 static void fill_dig_outs(struct hda_codec *codec);
2622 static void fill_dig_in(struct hda_codec *codec);
2624 static int via_parse_auto_config(struct hda_codec *codec)
2626 struct via_spec *spec = codec->spec;
2629 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2632 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2635 err = via_auto_create_multi_out_ctls(codec);
2638 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2641 err = via_auto_create_speaker_ctls(codec);
2644 err = via_auto_create_loopback_switch(codec);
2647 err = via_auto_create_analog_input_ctls(codec);
2651 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2653 fill_dig_outs(codec);
2656 if (spec->kctls.list)
2657 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2660 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
2661 err = via_hp_build(codec);
2666 err = via_smart51_build(codec);
2670 /* assign slave outs */
2671 if (spec->slave_dig_outs[0])
2672 codec->slave_dig_outs = spec->slave_dig_outs;
2677 static void via_auto_init_dig_outs(struct hda_codec *codec)
2679 struct via_spec *spec = codec->spec;
2680 if (spec->multiout.dig_out_nid)
2681 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2682 if (spec->slave_dig_outs[0])
2683 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2686 static void via_auto_init_dig_in(struct hda_codec *codec)
2688 struct via_spec *spec = codec->spec;
2689 if (!spec->dig_in_nid)
2691 snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
2694 static void via_jack_output_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2696 set_widgets_power_state(codec);
2697 via_hp_automute(codec);
2700 static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2702 set_widgets_power_state(codec);
2705 /* initialize the unsolicited events */
2706 static void via_auto_init_unsol_event(struct hda_codec *codec)
2708 struct via_spec *spec = codec->spec;
2709 struct auto_pin_cfg *cfg = &spec->autocfg;
2712 hda_jack_callback cb;
2714 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2715 snd_hda_jack_detect_enable_callback(codec, cfg->hp_pins[0],
2716 VIA_HP_EVENT | VIA_JACK_EVENT,
2717 via_jack_output_event);
2719 if (cfg->speaker_pins[0])
2720 ev = VIA_LINE_EVENT;
2723 cb = ev ? via_jack_output_event : via_jack_powerstate_event;
2725 for (i = 0; i < cfg->line_outs; i++) {
2726 if (cfg->line_out_pins[i] &&
2727 is_jack_detectable(codec, cfg->line_out_pins[i]))
2728 snd_hda_jack_detect_enable_callback(codec, cfg->line_out_pins[i],
2729 ev | VIA_JACK_EVENT, cb);
2732 for (i = 0; i < cfg->num_inputs; i++) {
2733 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2734 snd_hda_jack_detect_enable_callback(codec, cfg->inputs[i].pin,
2736 via_jack_powerstate_event);
2740 static int via_init(struct hda_codec *codec)
2742 struct via_spec *spec = codec->spec;
2745 for (i = 0; i < spec->num_iverbs; i++)
2746 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2748 /* init power states */
2749 set_widgets_power_state(codec);
2750 __analog_low_current_mode(codec, true);
2752 via_auto_init_multi_out(codec);
2753 via_auto_init_hp_out(codec);
2754 via_auto_init_speaker_out(codec);
2755 via_auto_init_analog_input(codec);
2756 via_auto_init_dig_outs(codec);
2757 via_auto_init_dig_in(codec);
2759 via_auto_init_unsol_event(codec);
2761 via_hp_automute(codec);
2762 vt1708_update_hp_work(spec);
2767 static void vt1708_update_hp_jack_state(struct work_struct *work)
2769 struct via_spec *spec = container_of(work, struct via_spec,
2770 vt1708_hp_work.work);
2771 if (spec->codec_type != VT1708)
2773 snd_hda_jack_set_dirty_all(spec->codec);
2774 /* if jack state toggled */
2775 if (spec->vt1708_hp_present
2776 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2777 spec->vt1708_hp_present ^= 1;
2778 via_hp_automute(spec->codec);
2780 if (spec->vt1708_jack_detect)
2781 schedule_delayed_work(&spec->vt1708_hp_work,
2782 msecs_to_jiffies(100));
2785 static int get_mux_nids(struct hda_codec *codec)
2787 struct via_spec *spec = codec->spec;
2788 hda_nid_t nid, conn[8];
2792 for (i = 0; i < spec->num_adc_nids; i++) {
2793 nid = spec->adc_nids[i];
2795 type = get_wcaps_type(get_wcaps(codec, nid));
2796 if (type == AC_WID_PIN)
2798 n = snd_hda_get_connections(codec, nid, conn,
2803 spec->mux_nids[i] = nid;
2812 static int patch_vt1708(struct hda_codec *codec)
2814 struct via_spec *spec;
2817 /* create a codec specific record */
2818 spec = via_new_spec(codec);
2822 spec->aa_mix_nid = 0x17;
2824 /* Add HP and CD pin config connect bit re-config action */
2825 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2826 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2828 /* automatic parse from the BIOS config */
2829 err = via_parse_auto_config(codec);
2835 /* add jack detect on/off control */
2836 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2839 /* disable 32bit format on VT1708 */
2840 if (codec->vendor_id == 0x11061708)
2841 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2843 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2845 codec->patch_ops = via_patch_ops;
2847 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2851 static int patch_vt1709(struct hda_codec *codec)
2853 struct via_spec *spec;
2856 /* create a codec specific record */
2857 spec = via_new_spec(codec);
2861 spec->aa_mix_nid = 0x18;
2863 err = via_parse_auto_config(codec);
2869 codec->patch_ops = via_patch_ops;
2874 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2876 struct via_spec *spec = codec->spec;
2880 if ((spec->codec_type != VT1708B_4CH) &&
2881 (codec->vendor_id != 0x11064397))
2884 /* SW0 (17h) = stereo mixer */
2886 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2887 == ((spec->codec_type == VT1708S) ? 5 : 0));
2889 /* PW 1/2/5 (1ah/1bh/1eh) */
2891 set_pin_power_state(codec, 0x1a, &parm);
2892 set_pin_power_state(codec, 0x1b, &parm);
2893 set_pin_power_state(codec, 0x1e, &parm);
2896 /* SW0 (17h), AIW 0/1 (13h/14h) */
2897 update_power_state(codec, 0x17, parm);
2898 update_power_state(codec, 0x13, parm);
2899 update_power_state(codec, 0x14, parm);
2902 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2904 set_pin_power_state(codec, 0x19, &parm);
2905 if (spec->smart51_enabled)
2906 set_pin_power_state(codec, 0x1b, &parm);
2907 update_power_state(codec, 0x18, parm);
2908 update_power_state(codec, 0x11, parm);
2910 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2913 set_pin_power_state(codec, 0x22, &parm);
2914 if (spec->smart51_enabled)
2915 set_pin_power_state(codec, 0x1a, &parm);
2916 update_power_state(codec, 0x26, parm);
2917 update_power_state(codec, 0x24, parm);
2918 } else if (codec->vendor_id == 0x11064397) {
2919 /* PW7(23h), SW2(27h), AOW2(25h) */
2921 set_pin_power_state(codec, 0x23, &parm);
2922 if (spec->smart51_enabled)
2923 set_pin_power_state(codec, 0x1a, &parm);
2924 update_power_state(codec, 0x27, parm);
2925 update_power_state(codec, 0x25, parm);
2928 /* PW 3/4/7 (1ch/1dh/23h) */
2930 /* force to D0 for internal Speaker */
2931 set_pin_power_state(codec, 0x1c, &parm);
2932 set_pin_power_state(codec, 0x1d, &parm);
2934 set_pin_power_state(codec, 0x23, &parm);
2936 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2937 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
2938 update_power_state(codec, 0x10, parm);
2940 update_power_state(codec, 0x25, parm);
2941 update_power_state(codec, 0x27, parm);
2942 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2943 update_power_state(codec, 0x25, parm);
2946 static int patch_vt1708S(struct hda_codec *codec);
2947 static int patch_vt1708B(struct hda_codec *codec)
2949 struct via_spec *spec;
2952 if (get_codec_type(codec) == VT1708BCE)
2953 return patch_vt1708S(codec);
2955 /* create a codec specific record */
2956 spec = via_new_spec(codec);
2960 spec->aa_mix_nid = 0x16;
2962 /* automatic parse from the BIOS config */
2963 err = via_parse_auto_config(codec);
2969 codec->patch_ops = via_patch_ops;
2971 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2976 /* Patch for VT1708S */
2977 static const struct hda_verb vt1708S_init_verbs[] = {
2978 /* Enable Mic Boost Volume backdoor */
2980 /* don't bybass mixer */
2985 /* fill out digital output widgets; one for master and one for slave outputs */
2986 static void fill_dig_outs(struct hda_codec *codec)
2988 struct via_spec *spec = codec->spec;
2991 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2995 nid = spec->autocfg.dig_out_pins[i];
2998 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3001 if (!spec->multiout.dig_out_nid)
3002 spec->multiout.dig_out_nid = nid;
3004 spec->slave_dig_outs[0] = nid;
3005 break; /* at most two dig outs */
3010 static void fill_dig_in(struct hda_codec *codec)
3012 struct via_spec *spec = codec->spec;
3016 if (!spec->autocfg.dig_in_pin)
3019 dig_nid = codec->start_nid;
3020 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3021 unsigned int wcaps = get_wcaps(codec, dig_nid);
3022 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3024 if (!(wcaps & AC_WCAP_DIGITAL))
3026 if (!(wcaps & AC_WCAP_CONN_LIST))
3028 err = get_connection_index(codec, dig_nid,
3029 spec->autocfg.dig_in_pin);
3031 spec->dig_in_nid = dig_nid;
3037 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3038 int offset, int num_steps, int step_size)
3040 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3041 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3042 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3043 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3044 (0 << AC_AMPCAP_MUTE_SHIFT));
3047 static int patch_vt1708S(struct hda_codec *codec)
3049 struct via_spec *spec;
3052 /* create a codec specific record */
3053 spec = via_new_spec(codec);
3057 spec->aa_mix_nid = 0x16;
3058 override_mic_boost(codec, 0x1a, 0, 3, 40);
3059 override_mic_boost(codec, 0x1e, 0, 3, 40);
3061 /* automatic parse from the BIOS config */
3062 err = via_parse_auto_config(codec);
3068 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
3070 codec->patch_ops = via_patch_ops;
3072 /* correct names for VT1708BCE */
3073 if (get_codec_type(codec) == VT1708BCE) {
3074 kfree(codec->chip_name);
3075 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3076 snprintf(codec->bus->card->mixername,
3077 sizeof(codec->bus->card->mixername),
3078 "%s %s", codec->vendor_name, codec->chip_name);
3080 /* correct names for VT1705 */
3081 if (codec->vendor_id == 0x11064397) {
3082 kfree(codec->chip_name);
3083 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3084 snprintf(codec->bus->card->mixername,
3085 sizeof(codec->bus->card->mixername),
3086 "%s %s", codec->vendor_name, codec->chip_name);
3088 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3092 /* Patch for VT1702 */
3094 static const struct hda_verb vt1702_init_verbs[] = {
3102 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3104 int imux_is_smixer =
3105 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3108 /* PW 1/2/5 (14h/15h/18h) */
3110 set_pin_power_state(codec, 0x14, &parm);
3111 set_pin_power_state(codec, 0x15, &parm);
3112 set_pin_power_state(codec, 0x18, &parm);
3114 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3115 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3116 update_power_state(codec, 0x13, parm);
3117 update_power_state(codec, 0x12, parm);
3118 update_power_state(codec, 0x1f, parm);
3119 update_power_state(codec, 0x20, parm);
3122 /* PW 3/4 (16h/17h) */
3124 set_pin_power_state(codec, 0x17, &parm);
3125 set_pin_power_state(codec, 0x16, &parm);
3126 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3127 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
3128 update_power_state(codec, 0x10, parm);
3129 update_power_state(codec, 0x1d, parm);
3132 static int patch_vt1702(struct hda_codec *codec)
3134 struct via_spec *spec;
3137 /* create a codec specific record */
3138 spec = via_new_spec(codec);
3142 spec->aa_mix_nid = 0x1a;
3144 /* limit AA path volume to 0 dB */
3145 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3146 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3147 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3148 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3149 (1 << AC_AMPCAP_MUTE_SHIFT));
3151 /* automatic parse from the BIOS config */
3152 err = via_parse_auto_config(codec);
3158 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
3160 codec->patch_ops = via_patch_ops;
3162 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
3166 /* Patch for VT1718S */
3168 static const struct hda_verb vt1718S_init_verbs[] = {
3169 /* Enable MW0 adjust Gain 5 */
3171 /* Enable Boost Volume backdoor */
3177 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3179 struct via_spec *spec = codec->spec;
3181 unsigned int parm, parm2;
3182 /* MUX6 (1eh) = stereo mixer */
3184 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3186 /* PW 5/6/7 (29h/2ah/2bh) */
3188 set_pin_power_state(codec, 0x29, &parm);
3189 set_pin_power_state(codec, 0x2a, &parm);
3190 set_pin_power_state(codec, 0x2b, &parm);
3193 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3194 update_power_state(codec, 0x1e, parm);
3195 update_power_state(codec, 0x1f, parm);
3196 update_power_state(codec, 0x10, parm);
3197 update_power_state(codec, 0x11, parm);
3200 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3202 set_pin_power_state(codec, 0x27, &parm);
3203 update_power_state(codec, 0x1a, parm);
3204 parm2 = parm; /* for pin 0x0b */
3206 /* PW2 (26h), AOW2 (ah) */
3208 set_pin_power_state(codec, 0x26, &parm);
3209 if (spec->smart51_enabled)
3210 set_pin_power_state(codec, 0x2b, &parm);
3211 update_power_state(codec, 0xa, parm);
3213 /* PW0 (24h), AOW0 (8h) */
3215 set_pin_power_state(codec, 0x24, &parm);
3216 if (!spec->hp_independent_mode) /* check for redirected HP */
3217 set_pin_power_state(codec, 0x28, &parm);
3218 update_power_state(codec, 0x8, parm);
3219 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
3221 update_power_state(codec, 0xb, parm);
3222 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3223 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
3225 /* PW1 (25h), AOW1 (9h) */
3227 set_pin_power_state(codec, 0x25, &parm);
3228 if (spec->smart51_enabled)
3229 set_pin_power_state(codec, 0x2a, &parm);
3230 update_power_state(codec, 0x9, parm);
3232 if (spec->hp_independent_mode) {
3233 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3235 set_pin_power_state(codec, 0x28, &parm);
3236 update_power_state(codec, 0x1b, parm);
3237 update_power_state(codec, 0x34, parm);
3238 update_power_state(codec, 0xc, parm);
3242 /* Add a connection to the primary DAC from AA-mixer for some codecs
3243 * This isn't listed from the raw info, but the chip has a secret connection.
3245 static int add_secret_dac_path(struct hda_codec *codec)
3247 struct via_spec *spec = codec->spec;
3252 if (!spec->aa_mix_nid)
3254 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3255 ARRAY_SIZE(conn) - 1);
3256 for (i = 0; i < nums; i++) {
3257 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3261 /* find the primary DAC and add to the connection list */
3262 nid = codec->start_nid;
3263 for (i = 0; i < codec->num_nodes; i++, nid++) {
3264 unsigned int caps = get_wcaps(codec, nid);
3265 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3266 !(caps & AC_WCAP_DIGITAL)) {
3268 return snd_hda_override_conn_list(codec,
3277 static int patch_vt1718S(struct hda_codec *codec)
3279 struct via_spec *spec;
3282 /* create a codec specific record */
3283 spec = via_new_spec(codec);
3287 spec->aa_mix_nid = 0x21;
3288 override_mic_boost(codec, 0x2b, 0, 3, 40);
3289 override_mic_boost(codec, 0x29, 0, 3, 40);
3290 add_secret_dac_path(codec);
3292 /* automatic parse from the BIOS config */
3293 err = via_parse_auto_config(codec);
3299 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3301 codec->patch_ops = via_patch_ops;
3303 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3308 /* Patch for VT1716S */
3310 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3311 struct snd_ctl_elem_info *uinfo)
3313 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3315 uinfo->value.integer.min = 0;
3316 uinfo->value.integer.max = 1;
3320 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3321 struct snd_ctl_elem_value *ucontrol)
3323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3326 index = snd_hda_codec_read(codec, 0x26, 0,
3327 AC_VERB_GET_CONNECT_SEL, 0);
3329 *ucontrol->value.integer.value = index;
3334 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3335 struct snd_ctl_elem_value *ucontrol)
3337 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3338 struct via_spec *spec = codec->spec;
3339 int index = *ucontrol->value.integer.value;
3341 snd_hda_codec_write(codec, 0x26, 0,
3342 AC_VERB_SET_CONNECT_SEL, index);
3343 spec->dmic_enabled = index;
3344 set_widgets_power_state(codec);
3348 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3349 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3351 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3352 .name = "Digital Mic Capture Switch",
3353 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3355 .info = vt1716s_dmic_info,
3356 .get = vt1716s_dmic_get,
3357 .put = vt1716s_dmic_put,
3363 /* mono-out mixer elements */
3364 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3365 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3369 static const struct hda_verb vt1716S_init_verbs[] = {
3370 /* Enable Boost Volume backdoor */
3372 /* don't bybass mixer */
3374 /* Enable mono output */
3379 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3381 struct via_spec *spec = codec->spec;
3384 unsigned int mono_out, present;
3385 /* SW0 (17h) = stereo mixer */
3387 (snd_hda_codec_read(codec, 0x17, 0,
3388 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3390 /* PW 1/2/5 (1ah/1bh/1eh) */
3392 set_pin_power_state(codec, 0x1a, &parm);
3393 set_pin_power_state(codec, 0x1b, &parm);
3394 set_pin_power_state(codec, 0x1e, &parm);
3397 /* SW0 (17h), AIW0(13h) */
3398 update_power_state(codec, 0x17, parm);
3399 update_power_state(codec, 0x13, parm);
3402 set_pin_power_state(codec, 0x1e, &parm);
3404 if (spec->dmic_enabled)
3405 set_pin_power_state(codec, 0x22, &parm);
3407 update_power_state(codec, 0x22, AC_PWRST_D3);
3409 /* SW2(26h), AIW1(14h) */
3410 update_power_state(codec, 0x26, parm);
3411 update_power_state(codec, 0x14, parm);
3414 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3416 set_pin_power_state(codec, 0x19, &parm);
3417 /* Smart 5.1 PW2(1bh) */
3418 if (spec->smart51_enabled)
3419 set_pin_power_state(codec, 0x1b, &parm);
3420 update_power_state(codec, 0x18, parm);
3421 update_power_state(codec, 0x11, parm);
3423 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3425 set_pin_power_state(codec, 0x23, &parm);
3426 /* Smart 5.1 PW1(1ah) */
3427 if (spec->smart51_enabled)
3428 set_pin_power_state(codec, 0x1a, &parm);
3429 update_power_state(codec, 0x27, parm);
3431 /* Smart 5.1 PW5(1eh) */
3432 if (spec->smart51_enabled)
3433 set_pin_power_state(codec, 0x1e, &parm);
3434 update_power_state(codec, 0x25, parm);
3437 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3438 present = snd_hda_jack_detect(codec, 0x1c);
3443 present = snd_hda_jack_detect(codec, 0x1d);
3444 if (!spec->hp_independent_mode && present)
3449 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3450 update_power_state(codec, 0x28, parm);
3451 update_power_state(codec, 0x29, parm);
3452 update_power_state(codec, 0x2a, parm);
3454 /* PW 3/4 (1ch/1dh) */
3456 set_pin_power_state(codec, 0x1c, &parm);
3457 set_pin_power_state(codec, 0x1d, &parm);
3458 /* HP Independent Mode, power on AOW3 */
3459 if (spec->hp_independent_mode)
3460 update_power_state(codec, 0x25, parm);
3462 /* force to D0 for internal Speaker */
3463 /* MW0 (16h), AOW0 (10h) */
3464 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
3465 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
3468 static int patch_vt1716S(struct hda_codec *codec)
3470 struct via_spec *spec;
3473 /* create a codec specific record */
3474 spec = via_new_spec(codec);
3478 spec->aa_mix_nid = 0x16;
3479 override_mic_boost(codec, 0x1a, 0, 3, 40);
3480 override_mic_boost(codec, 0x1e, 0, 3, 40);
3482 /* automatic parse from the BIOS config */
3483 err = via_parse_auto_config(codec);
3489 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3491 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3494 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3496 codec->patch_ops = via_patch_ops;
3498 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3504 static const struct hda_verb vt2002P_init_verbs[] = {
3505 /* Class-D speaker related verbs */
3509 /* Enable Boost Volume backdoor */
3511 /* Enable AOW0 to MW9 */
3516 static const struct hda_verb vt1802_init_verbs[] = {
3517 /* Enable Boost Volume backdoor */
3519 /* Enable AOW0 to MW9 */
3524 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3526 struct via_spec *spec = codec->spec;
3529 unsigned int present;
3530 /* MUX9 (1eh) = stereo mixer */
3532 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3534 /* PW 5/6/7 (29h/2ah/2bh) */
3536 set_pin_power_state(codec, 0x29, &parm);
3537 set_pin_power_state(codec, 0x2a, &parm);
3538 set_pin_power_state(codec, 0x2b, &parm);
3540 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3541 update_power_state(codec, 0x1e, parm);
3542 update_power_state(codec, 0x1f, parm);
3543 update_power_state(codec, 0x10, parm);
3544 update_power_state(codec, 0x11, parm);
3548 update_power_state(codec, 0x8, parm);
3550 if (spec->codec_type == VT1802) {
3551 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3553 set_pin_power_state(codec, 0x28, &parm);
3554 update_power_state(codec, 0x18, parm);
3555 update_power_state(codec, 0x38, parm);
3557 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3559 set_pin_power_state(codec, 0x26, &parm);
3560 update_power_state(codec, 0x1c, parm);
3561 update_power_state(codec, 0x37, parm);
3564 if (spec->codec_type == VT1802) {
3565 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3567 set_pin_power_state(codec, 0x25, &parm);
3568 update_power_state(codec, 0x15, parm);
3569 update_power_state(codec, 0x35, parm);
3571 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3573 set_pin_power_state(codec, 0x25, &parm);
3574 update_power_state(codec, 0x19, parm);
3575 update_power_state(codec, 0x35, parm);
3578 if (spec->hp_independent_mode)
3579 update_power_state(codec, 0x9, AC_PWRST_D0);
3582 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3583 present = snd_hda_jack_detect(codec, 0x25);
3586 set_pin_power_state(codec, 0x24, &parm);
3587 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3588 if (spec->codec_type == VT1802)
3589 update_power_state(codec, 0x14, parm);
3591 update_power_state(codec, 0x18, parm);
3592 update_power_state(codec, 0x34, parm);
3595 present = snd_hda_jack_detect(codec, 0x26);
3597 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3598 if (spec->codec_type == VT1802) {
3599 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3600 update_power_state(codec, 0x33, parm);
3601 update_power_state(codec, 0x1c, parm);
3602 update_power_state(codec, 0x3c, parm);
3604 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3605 update_power_state(codec, 0x31, parm);
3606 update_power_state(codec, 0x17, parm);
3607 update_power_state(codec, 0x3b, parm);
3610 if (imux_is_smixer || !is_aa_path_mute(codec))
3611 update_power_state(codec, 0x21, AC_PWRST_D0);
3613 update_power_state(codec, 0x21, AC_PWRST_D3);
3620 VIA_FIXUP_INTMIC_BOOST,
3624 static void via_fixup_intmic_boost(struct hda_codec *codec,
3625 const struct hda_fixup *fix, int action)
3627 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3628 override_mic_boost(codec, 0x30, 0, 2, 40);
3631 static const struct hda_fixup via_fixups[] = {
3632 [VIA_FIXUP_INTMIC_BOOST] = {
3633 .type = HDA_FIXUP_FUNC,
3634 .v.func = via_fixup_intmic_boost,
3636 [VIA_FIXUP_ASUS_G75] = {
3637 .type = HDA_FIXUP_PINS,
3638 .v.pins = (const struct hda_pintbl[]) {
3639 /* set 0x24 and 0x33 as speakers */
3640 { 0x24, 0x991301f0 },
3641 { 0x33, 0x991301f1 }, /* subwoofer */
3647 static const struct snd_pci_quirk vt2002p_fixups[] = {
3648 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
3649 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
3653 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
3654 * Replace this with mixer NID 0x1c
3656 static void fix_vt1802_connections(struct hda_codec *codec)
3658 static hda_nid_t conn_24[] = { 0x14, 0x1c };
3659 static hda_nid_t conn_33[] = { 0x1c };
3661 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
3662 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
3665 /* patch for vt2002P */
3666 static int patch_vt2002P(struct hda_codec *codec)
3668 struct via_spec *spec;
3671 /* create a codec specific record */
3672 spec = via_new_spec(codec);
3676 spec->aa_mix_nid = 0x21;
3677 override_mic_boost(codec, 0x2b, 0, 3, 40);
3678 override_mic_boost(codec, 0x29, 0, 3, 40);
3679 if (spec->codec_type == VT1802)
3680 fix_vt1802_connections(codec);
3681 add_secret_dac_path(codec);
3683 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
3684 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3686 /* automatic parse from the BIOS config */
3687 err = via_parse_auto_config(codec);
3693 if (spec->codec_type == VT1802)
3694 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3696 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3698 codec->patch_ops = via_patch_ops;
3700 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3706 static const struct hda_verb vt1812_init_verbs[] = {
3707 /* Enable Boost Volume backdoor */
3709 /* Enable AOW0 to MW9 */
3714 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3716 struct via_spec *spec = codec->spec;
3718 unsigned int present;
3720 /* PW 5/6/7 (29h/2ah/2bh) */
3722 set_pin_power_state(codec, 0x29, &parm);
3723 set_pin_power_state(codec, 0x2a, &parm);
3724 set_pin_power_state(codec, 0x2b, &parm);
3726 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3727 update_power_state(codec, 0x1e, parm);
3728 update_power_state(codec, 0x1f, parm);
3729 update_power_state(codec, 0x10, parm);
3730 update_power_state(codec, 0x11, parm);
3734 update_power_state(codec, 0x8, AC_PWRST_D0);
3736 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3738 set_pin_power_state(codec, 0x28, &parm);
3739 update_power_state(codec, 0x18, parm);
3740 update_power_state(codec, 0x38, parm);
3742 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3744 set_pin_power_state(codec, 0x25, &parm);
3745 update_power_state(codec, 0x15, parm);
3746 update_power_state(codec, 0x35, parm);
3747 if (spec->hp_independent_mode)
3748 update_power_state(codec, 0x9, AC_PWRST_D0);
3750 /* Internal Speaker */
3751 /* PW0 (24h), MW0(14h), MUX0(34h) */
3752 present = snd_hda_jack_detect(codec, 0x25);
3755 set_pin_power_state(codec, 0x24, &parm);
3757 update_power_state(codec, 0x14, AC_PWRST_D3);
3758 update_power_state(codec, 0x34, AC_PWRST_D3);
3760 update_power_state(codec, 0x14, AC_PWRST_D0);
3761 update_power_state(codec, 0x34, AC_PWRST_D0);
3766 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3767 present = snd_hda_jack_detect(codec, 0x28);
3770 set_pin_power_state(codec, 0x31, &parm);
3772 update_power_state(codec, 0x1c, AC_PWRST_D3);
3773 update_power_state(codec, 0x3c, AC_PWRST_D3);
3774 update_power_state(codec, 0x3e, AC_PWRST_D3);
3776 update_power_state(codec, 0x1c, AC_PWRST_D0);
3777 update_power_state(codec, 0x3c, AC_PWRST_D0);
3778 update_power_state(codec, 0x3e, AC_PWRST_D0);
3781 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3783 set_pin_power_state(codec, 0x33, &parm);
3784 update_power_state(codec, 0x1d, parm);
3785 update_power_state(codec, 0x3d, parm);
3789 /* patch for vt1812 */
3790 static int patch_vt1812(struct hda_codec *codec)
3792 struct via_spec *spec;
3795 /* create a codec specific record */
3796 spec = via_new_spec(codec);
3800 spec->aa_mix_nid = 0x21;
3801 override_mic_boost(codec, 0x2b, 0, 3, 40);
3802 override_mic_boost(codec, 0x29, 0, 3, 40);
3803 add_secret_dac_path(codec);
3805 /* automatic parse from the BIOS config */
3806 err = via_parse_auto_config(codec);
3812 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3814 codec->patch_ops = via_patch_ops;
3816 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3823 static const struct hda_codec_preset snd_hda_preset_via[] = {
3824 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3825 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3826 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3827 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3828 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3829 .patch = patch_vt1709},
3830 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3831 .patch = patch_vt1709},
3832 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3833 .patch = patch_vt1709},
3834 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3835 .patch = patch_vt1709},
3836 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3837 .patch = patch_vt1709},
3838 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3839 .patch = patch_vt1709},
3840 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3841 .patch = patch_vt1709},
3842 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3843 .patch = patch_vt1709},
3844 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3845 .patch = patch_vt1708B},
3846 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3847 .patch = patch_vt1708B},
3848 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3849 .patch = patch_vt1708B},
3850 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3851 .patch = patch_vt1708B},
3852 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3853 .patch = patch_vt1708B},
3854 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3855 .patch = patch_vt1708B},
3856 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3857 .patch = patch_vt1708B},
3858 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3859 .patch = patch_vt1708B},
3860 { .id = 0x11060397, .name = "VT1708S",
3861 .patch = patch_vt1708S},
3862 { .id = 0x11061397, .name = "VT1708S",
3863 .patch = patch_vt1708S},
3864 { .id = 0x11062397, .name = "VT1708S",
3865 .patch = patch_vt1708S},
3866 { .id = 0x11063397, .name = "VT1708S",
3867 .patch = patch_vt1708S},
3868 { .id = 0x11064397, .name = "VT1705",
3869 .patch = patch_vt1708S},
3870 { .id = 0x11065397, .name = "VT1708S",
3871 .patch = patch_vt1708S},
3872 { .id = 0x11066397, .name = "VT1708S",
3873 .patch = patch_vt1708S},
3874 { .id = 0x11067397, .name = "VT1708S",
3875 .patch = patch_vt1708S},
3876 { .id = 0x11060398, .name = "VT1702",
3877 .patch = patch_vt1702},
3878 { .id = 0x11061398, .name = "VT1702",
3879 .patch = patch_vt1702},
3880 { .id = 0x11062398, .name = "VT1702",
3881 .patch = patch_vt1702},
3882 { .id = 0x11063398, .name = "VT1702",
3883 .patch = patch_vt1702},
3884 { .id = 0x11064398, .name = "VT1702",
3885 .patch = patch_vt1702},
3886 { .id = 0x11065398, .name = "VT1702",
3887 .patch = patch_vt1702},
3888 { .id = 0x11066398, .name = "VT1702",
3889 .patch = patch_vt1702},
3890 { .id = 0x11067398, .name = "VT1702",
3891 .patch = patch_vt1702},
3892 { .id = 0x11060428, .name = "VT1718S",
3893 .patch = patch_vt1718S},
3894 { .id = 0x11064428, .name = "VT1718S",
3895 .patch = patch_vt1718S},
3896 { .id = 0x11060441, .name = "VT2020",
3897 .patch = patch_vt1718S},
3898 { .id = 0x11064441, .name = "VT1828S",
3899 .patch = patch_vt1718S},
3900 { .id = 0x11060433, .name = "VT1716S",
3901 .patch = patch_vt1716S},
3902 { .id = 0x1106a721, .name = "VT1716S",
3903 .patch = patch_vt1716S},
3904 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3905 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3906 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3907 { .id = 0x11060440, .name = "VT1818S",
3908 .patch = patch_vt1708S},
3909 { .id = 0x11060446, .name = "VT1802",
3910 .patch = patch_vt2002P},
3911 { .id = 0x11068446, .name = "VT1802",
3912 .patch = patch_vt2002P},
3916 MODULE_ALIAS("snd-hda-codec-id:1106*");
3918 static struct hda_codec_preset_list via_list = {
3919 .preset = snd_hda_preset_via,
3920 .owner = THIS_MODULE,
3923 MODULE_LICENSE("GPL");
3924 MODULE_DESCRIPTION("VIA HD-audio codec");
3926 static int __init patch_via_init(void)
3928 return snd_hda_add_codec_preset(&via_list);
3931 static void __exit patch_via_exit(void)
3933 snd_hda_delete_codec_preset(&via_list);
3936 module_init(patch_via_init)
3937 module_exit(patch_via_exit)