2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
58 #define VT1708_HP_PIN_NID 0x20
59 #define VT1708_CD_PIN_NID 0x24
79 #define VT2002P_COMPATIBLE(spec) \
80 ((spec)->codec_type == VT2002P ||\
81 (spec)->codec_type == VT1812 ||\
82 (spec)->codec_type == VT1802)
84 #define MAX_NID_PATH_DEPTH 5
86 /* output-path: DAC -> ... -> pin
87 * idx[] contains the source index number of the next widget;
88 * e.g. idx[0] is the index of the DAC selected by path[1] widget
89 * multi[] indicates whether it's a selector widget with multi-connectors
90 * (i.e. the connection selection is mandatory)
91 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
95 hda_nid_t path[MAX_NID_PATH_DEPTH];
96 unsigned char idx[MAX_NID_PATH_DEPTH];
97 unsigned char multi[MAX_NID_PATH_DEPTH];
99 unsigned int mute_ctl;
104 hda_nid_t pin; /* input-pin or aa-mix */
105 int adc_idx; /* ADC index to be used */
106 int mux_idx; /* MUX index (if any) */
107 const char *label; /* input-source label */
110 #define VIA_MAX_ADCS 3
113 /* codec parameterization */
114 const struct snd_kcontrol_new *mixers[6];
115 unsigned int num_mixers;
117 const struct hda_verb *init_verbs[5];
118 unsigned int num_iverbs;
120 char stream_name_analog[32];
121 char stream_name_hp[32];
122 const struct hda_pcm_stream *stream_analog_playback;
123 const struct hda_pcm_stream *stream_analog_capture;
125 char stream_name_digital[32];
126 const struct hda_pcm_stream *stream_digital_playback;
127 const struct hda_pcm_stream *stream_digital_capture;
130 struct hda_multi_out multiout;
131 hda_nid_t slave_dig_outs[2];
132 hda_nid_t hp_dac_nid;
133 hda_nid_t speaker_dac_nid;
134 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
135 int num_active_streams;
136 int aamix_mode; /* loopback is enabled for output-path? */
139 * There are different output-paths depending on the setup.
140 * out_path, hp_path and speaker_path are primary paths. If both
141 * direct DAC and aa-loopback routes are available, these contain
142 * the former paths. Meanwhile *_mix_path contain the paths with
143 * loopback mixer. (Since the loopback is only for front channel,
144 * no out_mix_path for surround channels.)
145 * The HP output has another path, hp_indep_path, which is used in
146 * the independent-HP mode.
148 struct nid_path out_path[HDA_SIDE + 1];
149 struct nid_path out_mix_path;
150 struct nid_path hp_path;
151 struct nid_path hp_mix_path;
152 struct nid_path hp_indep_path;
153 struct nid_path speaker_path;
154 struct nid_path speaker_mix_path;
157 unsigned int num_adc_nids;
158 hda_nid_t adc_nids[VIA_MAX_ADCS];
159 hda_nid_t mux_nids[VIA_MAX_ADCS];
160 hda_nid_t aa_mix_nid;
161 hda_nid_t dig_in_nid;
166 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
167 unsigned int cur_mux[VIA_MAX_ADCS];
169 /* dynamic ADC switching */
171 unsigned int cur_adc_stream_tag;
172 unsigned int cur_adc_format;
174 /* PCM information */
175 struct hda_pcm pcm_rec[3];
177 /* dynamic controls, init_verbs and input_mux */
178 struct auto_pin_cfg autocfg;
179 struct snd_array kctls;
180 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
183 unsigned int hp_independent_mode;
184 unsigned int dmic_enabled;
185 unsigned int no_pin_power_ctl;
186 enum VIA_HDA_CODEC codec_type;
189 unsigned int smart51_nums;
190 hda_nid_t smart51_pins[2];
192 const char *smart51_labels[2];
193 unsigned int smart51_enabled;
195 /* work to check hp jack state */
196 struct hda_codec *codec;
197 struct delayed_work vt1708_hp_work;
198 int vt1708_jack_detect;
199 int vt1708_hp_present;
201 void (*set_widgets_power_state)(struct hda_codec *codec);
203 struct hda_loopback_check loopback;
205 struct hda_amp_list loopback_list[8];
207 /* bind capture-volume */
208 struct hda_bind_ctls *bind_cap_vol;
209 struct hda_bind_ctls *bind_cap_sw;
212 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
213 static struct via_spec * via_new_spec(struct hda_codec *codec)
215 struct via_spec *spec;
217 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
223 spec->codec_type = get_codec_type(codec);
224 /* VT1708BCE & VT1708S are almost same */
225 if (spec->codec_type == VT1708BCE)
226 spec->codec_type = VT1708S;
230 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
232 u32 vendor_id = codec->vendor_id;
233 u16 ven_id = vendor_id >> 16;
234 u16 dev_id = vendor_id & 0xffff;
235 enum VIA_HDA_CODEC codec_type;
238 if (ven_id != 0x1106)
239 codec_type = UNKNOWN;
240 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
242 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
243 codec_type = VT1709_10CH;
244 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
245 codec_type = VT1709_6CH;
246 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
247 codec_type = VT1708B_8CH;
248 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
249 codec_type = VT1708BCE;
250 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
251 codec_type = VT1708B_4CH;
252 else if ((dev_id & 0xfff) == 0x397
253 && (dev_id >> 12) < 8)
254 codec_type = VT1708S;
255 else if ((dev_id & 0xfff) == 0x398
256 && (dev_id >> 12) < 8)
258 else if ((dev_id & 0xfff) == 0x428
259 && (dev_id >> 12) < 8)
260 codec_type = VT1718S;
261 else if (dev_id == 0x0433 || dev_id == 0xa721)
262 codec_type = VT1716S;
263 else if (dev_id == 0x0441 || dev_id == 0x4441)
264 codec_type = VT1718S;
265 else if (dev_id == 0x0438 || dev_id == 0x4438)
266 codec_type = VT2002P;
267 else if (dev_id == 0x0448)
269 else if (dev_id == 0x0440)
270 codec_type = VT1708S;
271 else if ((dev_id & 0xfff) == 0x446)
274 codec_type = UNKNOWN;
278 #define VIA_JACK_EVENT 0x20
279 #define VIA_HP_EVENT 0x01
280 #define VIA_GPIO_EVENT 0x02
281 #define VIA_LINE_EVENT 0x03
286 VIA_CTL_WIDGET_ANALOG_MUTE,
289 static void analog_low_current_mode(struct hda_codec *codec);
290 static bool is_aa_path_mute(struct hda_codec *codec);
292 static void vt1708_start_hp_work(struct via_spec *spec)
294 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
296 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
297 !spec->vt1708_jack_detect);
298 if (!delayed_work_pending(&spec->vt1708_hp_work))
299 schedule_delayed_work(&spec->vt1708_hp_work,
300 msecs_to_jiffies(100));
303 static void vt1708_stop_hp_work(struct via_spec *spec)
305 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
307 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
308 && !is_aa_path_mute(spec->codec))
310 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
311 !spec->vt1708_jack_detect);
312 cancel_delayed_work_sync(&spec->vt1708_hp_work);
315 static void set_widgets_power_state(struct hda_codec *codec)
317 struct via_spec *spec = codec->spec;
318 if (spec->set_widgets_power_state)
319 spec->set_widgets_power_state(codec);
322 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
323 struct snd_ctl_elem_value *ucontrol)
325 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
328 set_widgets_power_state(codec);
329 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
330 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
331 if (is_aa_path_mute(codec))
332 vt1708_start_hp_work(codec->spec);
334 vt1708_stop_hp_work(codec->spec);
339 /* modify .put = snd_hda_mixer_amp_switch_put */
340 #define ANALOG_INPUT_MUTE \
341 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
344 .info = snd_hda_mixer_amp_switch_info, \
345 .get = snd_hda_mixer_amp_switch_get, \
346 .put = analog_input_switch_put, \
347 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
349 static const struct snd_kcontrol_new via_control_templates[] = {
350 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
351 HDA_CODEC_MUTE(NULL, 0, 0, 0),
356 /* add dynamic controls */
357 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
358 const struct snd_kcontrol_new *tmpl,
361 struct snd_kcontrol_new *knew;
363 snd_array_init(&spec->kctls, sizeof(*knew), 32);
364 knew = snd_array_new(&spec->kctls);
371 knew->name = kstrdup(name, GFP_KERNEL);
378 static int __via_add_control(struct via_spec *spec, int type, const char *name,
379 int idx, unsigned long val)
381 struct snd_kcontrol_new *knew;
383 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
387 if (get_amp_nid_(val))
388 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
389 knew->private_value = val;
393 #define via_add_control(spec, type, name, val) \
394 __via_add_control(spec, type, name, 0, val)
396 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
398 static void via_free_kctls(struct hda_codec *codec)
400 struct via_spec *spec = codec->spec;
402 if (spec->kctls.list) {
403 struct snd_kcontrol_new *kctl = spec->kctls.list;
405 for (i = 0; i < spec->kctls.used; i++)
408 snd_array_free(&spec->kctls);
411 /* create input playback/capture controls for the given pin */
412 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
413 int type_idx, int idx, int mix_nid)
418 sprintf(name, "%s Playback Volume", ctlname);
419 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
420 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
423 sprintf(name, "%s Playback Switch", ctlname);
424 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
425 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
431 #define get_connection_index(codec, mux, nid) \
432 snd_hda_get_conn_index(codec, mux, nid, 0)
434 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
440 caps = get_wcaps(codec, nid);
441 if (dir == HDA_INPUT)
442 caps &= AC_WCAP_IN_AMP;
444 caps &= AC_WCAP_OUT_AMP;
447 if (query_amp_caps(codec, nid, dir) & mask)
452 #define have_mute(codec, nid, dir) \
453 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
455 /* enable/disable the output-route mixers */
456 static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
457 hda_nid_t mix_nid, int idx, bool enable)
463 num = snd_hda_get_conn_list(codec, mix_nid, NULL);
464 for (i = 0; i < num; i++) {
466 val = AMP_IN_UNMUTE(i);
468 val = AMP_IN_MUTE(i);
469 snd_hda_codec_write(codec, mix_nid, 0,
470 AC_VERB_SET_AMP_GAIN_MUTE, val);
474 /* enable/disable the output-route */
475 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
476 bool enable, bool force)
478 struct via_spec *spec = codec->spec;
480 for (i = 0; i < path->depth; i++) {
482 int idx = path->idx[i];
484 if (i < path->depth - 1)
485 dst = path->path[i + 1];
488 if (enable && path->multi[i])
489 snd_hda_codec_write(codec, dst, 0,
490 AC_VERB_SET_CONNECT_SEL, idx);
491 if (!force && (dst == spec->aa_mix_nid))
493 if (have_mute(codec, dst, HDA_INPUT))
494 activate_output_mix(codec, path, dst, idx, enable);
495 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
497 if (have_mute(codec, src, HDA_OUTPUT)) {
498 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
499 snd_hda_codec_write(codec, src, 0,
500 AC_VERB_SET_AMP_GAIN_MUTE, val);
505 /* set the given pin as output */
506 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
511 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
513 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
514 snd_hda_codec_write(codec, pin, 0,
515 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
518 static void via_auto_init_output(struct hda_codec *codec,
519 struct nid_path *path, int pin_type,
527 pin = path->path[path->depth - 1];
529 init_output_pin(codec, pin, pin_type);
530 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
531 if (caps & AC_AMPCAP_MUTE) {
533 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
534 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
537 activate_output_path(codec, path, true, force);
540 static void via_auto_init_multi_out(struct hda_codec *codec)
542 struct via_spec *spec = codec->spec;
543 struct nid_path *path;
546 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
547 path = &spec->out_path[i];
548 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
549 path = &spec->out_mix_path;
550 via_auto_init_output(codec, path, PIN_OUT, true);
554 static void via_auto_init_hp_out(struct hda_codec *codec)
556 struct via_spec *spec = codec->spec;
557 int shared = spec->hp_indep_shared;
559 if (!spec->hp_path.depth) {
560 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP, true);
563 if (spec->hp_independent_mode) {
564 activate_output_path(codec, &spec->hp_path, false, false);
565 activate_output_path(codec, &spec->hp_mix_path, false, false);
567 activate_output_path(codec, &spec->out_path[shared],
569 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP, true);
570 } else if (spec->aamix_mode) {
571 activate_output_path(codec, &spec->hp_path, false, false);
572 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP, true);
574 activate_output_path(codec, &spec->hp_mix_path, false, false);
575 via_auto_init_output(codec, &spec->hp_path, PIN_HP, true);
579 static void via_auto_init_speaker_out(struct hda_codec *codec)
581 struct via_spec *spec = codec->spec;
583 if (!spec->autocfg.speaker_outs)
585 if (!spec->speaker_path.depth) {
586 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT,
590 if (!spec->aamix_mode) {
591 activate_output_path(codec, &spec->speaker_mix_path,
593 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT,
596 activate_output_path(codec, &spec->speaker_path, false, false);
597 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT,
602 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
603 static void via_hp_automute(struct hda_codec *codec);
605 static void via_auto_init_analog_input(struct hda_codec *codec)
607 struct via_spec *spec = codec->spec;
608 const struct auto_pin_cfg *cfg = &spec->autocfg;
609 hda_nid_t conn[HDA_MAX_CONNECTIONS];
614 for (i = 0; i < spec->num_adc_nids; i++) {
615 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
616 AC_VERB_SET_AMP_GAIN_MUTE,
621 for (i = 0; i < cfg->num_inputs; i++) {
622 hda_nid_t nid = cfg->inputs[i].pin;
623 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
625 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
629 snd_hda_codec_write(codec, nid, 0,
630 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
634 for (i = 0; i < spec->num_adc_nids; i++) {
635 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
636 if (spec->mux_nids[adc_idx]) {
637 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
638 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
639 AC_VERB_SET_CONNECT_SEL,
642 if (spec->dyn_adc_switch)
643 break; /* only one input-src */
647 if (!spec->aa_mix_nid)
649 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
651 for (i = 0; i < num_conns; i++) {
652 unsigned int caps = get_wcaps(codec, conn[i]);
653 if (get_wcaps_type(caps) == AC_WID_PIN)
654 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
655 AC_VERB_SET_AMP_GAIN_MUTE,
660 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
661 unsigned int *affected_parm)
664 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
665 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
666 >> AC_DEFCFG_MISC_SHIFT
667 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
668 struct via_spec *spec = codec->spec;
669 unsigned present = 0;
671 no_presence |= spec->no_pin_power_ctl;
673 present = snd_hda_jack_detect(codec, nid);
674 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
675 || ((no_presence || present)
676 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
677 *affected_parm = AC_PWRST_D0; /* if it's connected */
682 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
685 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_info *uinfo)
688 static const char * const texts[] = {
689 "Disabled", "Enabled"
692 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
694 uinfo->value.enumerated.items = 2;
695 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
696 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
697 strcpy(uinfo->value.enumerated.name,
698 texts[uinfo->value.enumerated.item]);
702 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_value *ucontrol)
705 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
706 struct via_spec *spec = codec->spec;
707 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
711 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
712 struct snd_ctl_elem_value *ucontrol)
714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
715 struct via_spec *spec = codec->spec;
716 unsigned int val = !ucontrol->value.enumerated.item[0];
718 if (val == spec->no_pin_power_ctl)
720 spec->no_pin_power_ctl = val;
721 set_widgets_power_state(codec);
725 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
726 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
727 .name = "Dynamic Power-Control",
728 .info = via_pin_power_ctl_info,
729 .get = via_pin_power_ctl_get,
730 .put = via_pin_power_ctl_put,
734 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
735 struct snd_ctl_elem_info *uinfo)
737 static const char * const texts[] = { "OFF", "ON" };
739 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
741 uinfo->value.enumerated.items = 2;
742 if (uinfo->value.enumerated.item >= 2)
743 uinfo->value.enumerated.item = 1;
744 strcpy(uinfo->value.enumerated.name,
745 texts[uinfo->value.enumerated.item]);
749 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
750 struct snd_ctl_elem_value *ucontrol)
752 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
753 struct via_spec *spec = codec->spec;
755 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
759 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
760 struct snd_ctl_elem_value *ucontrol)
762 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
763 struct via_spec *spec = codec->spec;
766 /* no independent-hp status change during PCM playback is running */
767 if (spec->num_active_streams)
770 cur = !!ucontrol->value.enumerated.item[0];
771 if (spec->hp_independent_mode == cur)
773 spec->hp_independent_mode = cur;
774 shared = spec->hp_indep_shared;
776 activate_output_path(codec, &spec->hp_mix_path, false, false);
778 activate_output_path(codec, &spec->out_path[shared],
780 activate_output_path(codec, &spec->hp_path, true, false);
782 activate_output_path(codec, &spec->hp_path, false, false);
784 activate_output_path(codec, &spec->out_path[shared],
786 activate_output_path(codec, &spec->hp_mix_path, true, false);
789 /* update jack power state */
790 set_widgets_power_state(codec);
791 via_hp_automute(codec);
795 static const struct snd_kcontrol_new via_hp_mixer = {
796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
797 .name = "Independent HP",
798 .info = via_independent_hp_info,
799 .get = via_independent_hp_get,
800 .put = via_independent_hp_put,
803 static int via_hp_build(struct hda_codec *codec)
805 struct via_spec *spec = codec->spec;
806 struct snd_kcontrol_new *knew;
809 nid = spec->autocfg.hp_pins[0];
810 knew = via_clone_control(spec, &via_hp_mixer);
814 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
819 static void notify_aa_path_ctls(struct hda_codec *codec)
821 struct via_spec *spec = codec->spec;
824 for (i = 0; i < spec->smart51_nums; i++) {
825 struct snd_kcontrol *ctl;
826 struct snd_ctl_elem_id id;
827 memset(&id, 0, sizeof(id));
828 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
829 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
830 ctl = snd_hda_find_mixer_ctl(codec, id.name);
832 snd_ctl_notify(codec->bus->card,
833 SNDRV_CTL_EVENT_MASK_VALUE,
838 static void mute_aa_path(struct hda_codec *codec, int mute)
840 struct via_spec *spec = codec->spec;
841 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
844 /* check AA path's mute status */
845 for (i = 0; i < spec->smart51_nums; i++) {
846 if (spec->smart51_idxs[i] < 0)
848 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
849 HDA_INPUT, spec->smart51_idxs[i],
854 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
856 struct via_spec *spec = codec->spec;
859 for (i = 0; i < spec->smart51_nums; i++)
860 if (spec->smart51_pins[i] == pin)
865 static int via_smart51_get(struct snd_kcontrol *kcontrol,
866 struct snd_ctl_elem_value *ucontrol)
868 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
869 struct via_spec *spec = codec->spec;
871 *ucontrol->value.integer.value = spec->smart51_enabled;
875 static int via_smart51_put(struct snd_kcontrol *kcontrol,
876 struct snd_ctl_elem_value *ucontrol)
878 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
879 struct via_spec *spec = codec->spec;
880 int out_in = *ucontrol->value.integer.value
881 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
884 for (i = 0; i < spec->smart51_nums; i++) {
885 hda_nid_t nid = spec->smart51_pins[i];
888 parm = snd_hda_codec_read(codec, nid, 0,
889 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
890 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
892 snd_hda_codec_write(codec, nid, 0,
893 AC_VERB_SET_PIN_WIDGET_CONTROL,
895 if (out_in == AC_PINCTL_OUT_EN) {
896 mute_aa_path(codec, 1);
897 notify_aa_path_ctls(codec);
900 spec->smart51_enabled = *ucontrol->value.integer.value;
901 set_widgets_power_state(codec);
905 static const struct snd_kcontrol_new via_smart51_mixer = {
906 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
909 .info = snd_ctl_boolean_mono_info,
910 .get = via_smart51_get,
911 .put = via_smart51_put,
914 static int via_smart51_build(struct hda_codec *codec)
916 struct via_spec *spec = codec->spec;
918 if (!spec->smart51_nums)
920 if (!via_clone_control(spec, &via_smart51_mixer))
925 /* check AA path's mute status */
926 static bool is_aa_path_mute(struct hda_codec *codec)
928 struct via_spec *spec = codec->spec;
929 const struct hda_amp_list *p;
932 for (i = 0; i < spec->num_loopbacks; i++) {
933 p = &spec->loopback_list[i];
934 for (ch = 0; ch < 2; ch++) {
935 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
937 if (!(v & HDA_AMP_MUTE) && v > 0)
944 /* enter/exit analog low-current mode */
945 static void analog_low_current_mode(struct hda_codec *codec)
947 struct via_spec *spec = codec->spec;
949 unsigned int verb, parm;
951 enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0);
953 /* decide low current mode's verb & parameter */
954 switch (spec->codec_type) {
958 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
964 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
968 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
974 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
977 return; /* other codecs are not supported */
980 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
984 * generic initialization of ADC, input mixers and output mixers
986 static const struct hda_verb vt1708_init_verbs[] = {
987 /* power down jack detect function */
992 static void set_stream_active(struct hda_codec *codec, bool active)
994 struct via_spec *spec = codec->spec;
997 spec->num_active_streams++;
999 spec->num_active_streams--;
1000 analog_low_current_mode(codec);
1003 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1004 struct hda_codec *codec,
1005 struct snd_pcm_substream *substream)
1007 struct via_spec *spec = codec->spec;
1008 const struct auto_pin_cfg *cfg = &spec->autocfg;
1011 spec->multiout.hp_nid = 0;
1012 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1013 if (!spec->hp_independent_mode) {
1014 if (!spec->hp_indep_shared)
1015 spec->multiout.hp_nid = spec->hp_dac_nid;
1017 if (spec->hp_indep_shared)
1018 spec->multiout.num_dacs = cfg->line_outs - 1;
1020 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1021 set_stream_active(codec, true);
1022 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1025 spec->multiout.hp_nid = 0;
1026 set_stream_active(codec, false);
1032 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1033 struct hda_codec *codec,
1034 struct snd_pcm_substream *substream)
1036 struct via_spec *spec = codec->spec;
1038 spec->multiout.hp_nid = 0;
1039 set_stream_active(codec, false);
1043 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1044 struct hda_codec *codec,
1045 struct snd_pcm_substream *substream)
1047 struct via_spec *spec = codec->spec;
1049 if (snd_BUG_ON(!spec->hp_dac_nid))
1051 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1053 set_stream_active(codec, true);
1057 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1058 struct hda_codec *codec,
1059 struct snd_pcm_substream *substream)
1061 set_stream_active(codec, false);
1065 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1066 struct hda_codec *codec,
1067 unsigned int stream_tag,
1068 unsigned int format,
1069 struct snd_pcm_substream *substream)
1071 struct via_spec *spec = codec->spec;
1073 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1075 vt1708_start_hp_work(spec);
1079 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1080 struct hda_codec *codec,
1081 unsigned int stream_tag,
1082 unsigned int format,
1083 struct snd_pcm_substream *substream)
1085 struct via_spec *spec = codec->spec;
1087 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1088 stream_tag, 0, format);
1089 vt1708_start_hp_work(spec);
1093 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1094 struct hda_codec *codec,
1095 struct snd_pcm_substream *substream)
1097 struct via_spec *spec = codec->spec;
1099 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1100 vt1708_stop_hp_work(spec);
1104 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1105 struct hda_codec *codec,
1106 struct snd_pcm_substream *substream)
1108 struct via_spec *spec = codec->spec;
1110 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1111 vt1708_stop_hp_work(spec);
1118 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1119 struct hda_codec *codec,
1120 struct snd_pcm_substream *substream)
1122 struct via_spec *spec = codec->spec;
1123 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1126 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1127 struct hda_codec *codec,
1128 struct snd_pcm_substream *substream)
1130 struct via_spec *spec = codec->spec;
1131 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1134 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1135 struct hda_codec *codec,
1136 unsigned int stream_tag,
1137 unsigned int format,
1138 struct snd_pcm_substream *substream)
1140 struct via_spec *spec = codec->spec;
1141 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1142 stream_tag, format, substream);
1145 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1146 struct hda_codec *codec,
1147 struct snd_pcm_substream *substream)
1149 struct via_spec *spec = codec->spec;
1150 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1157 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1158 struct hda_codec *codec,
1159 unsigned int stream_tag,
1160 unsigned int format,
1161 struct snd_pcm_substream *substream)
1163 struct via_spec *spec = codec->spec;
1165 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1166 stream_tag, 0, format);
1170 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1171 struct hda_codec *codec,
1172 struct snd_pcm_substream *substream)
1174 struct via_spec *spec = codec->spec;
1175 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1179 /* analog capture with dynamic ADC switching */
1180 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1181 struct hda_codec *codec,
1182 unsigned int stream_tag,
1183 unsigned int format,
1184 struct snd_pcm_substream *substream)
1186 struct via_spec *spec = codec->spec;
1187 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1189 spec->cur_adc = spec->adc_nids[adc_idx];
1190 spec->cur_adc_stream_tag = stream_tag;
1191 spec->cur_adc_format = format;
1192 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1196 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1197 struct hda_codec *codec,
1198 struct snd_pcm_substream *substream)
1200 struct via_spec *spec = codec->spec;
1202 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1207 /* re-setup the stream if running; called from input-src put */
1208 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1210 struct via_spec *spec = codec->spec;
1211 int adc_idx = spec->inputs[cur].adc_idx;
1212 hda_nid_t adc = spec->adc_nids[adc_idx];
1214 if (spec->cur_adc && spec->cur_adc != adc) {
1215 /* stream is running, let's swap the current ADC */
1216 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1217 spec->cur_adc = adc;
1218 snd_hda_codec_setup_stream(codec, adc,
1219 spec->cur_adc_stream_tag, 0,
1220 spec->cur_adc_format);
1226 static const struct hda_pcm_stream via_pcm_analog_playback = {
1230 /* NID is set in via_build_pcms */
1232 .open = via_playback_multi_pcm_open,
1233 .close = via_playback_multi_pcm_close,
1234 .prepare = via_playback_multi_pcm_prepare,
1235 .cleanup = via_playback_multi_pcm_cleanup
1239 static const struct hda_pcm_stream via_pcm_hp_playback = {
1243 /* NID is set in via_build_pcms */
1245 .open = via_playback_hp_pcm_open,
1246 .close = via_playback_hp_pcm_close,
1247 .prepare = via_playback_hp_pcm_prepare,
1248 .cleanup = via_playback_hp_pcm_cleanup
1252 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1256 /* NID is set in via_build_pcms */
1257 /* We got noisy outputs on the right channel on VT1708 when
1258 * 24bit samples are used. Until any workaround is found,
1259 * disable the 24bit format, so far.
1261 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1263 .open = via_playback_multi_pcm_open,
1264 .close = via_playback_multi_pcm_close,
1265 .prepare = via_playback_multi_pcm_prepare,
1266 .cleanup = via_playback_multi_pcm_cleanup
1270 static const struct hda_pcm_stream via_pcm_analog_capture = {
1271 .substreams = 1, /* will be changed in via_build_pcms() */
1274 /* NID is set in via_build_pcms */
1276 .prepare = via_capture_pcm_prepare,
1277 .cleanup = via_capture_pcm_cleanup
1281 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1285 /* NID is set in via_build_pcms */
1287 .prepare = via_dyn_adc_capture_pcm_prepare,
1288 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1292 static const struct hda_pcm_stream via_pcm_digital_playback = {
1296 /* NID is set in via_build_pcms */
1298 .open = via_dig_playback_pcm_open,
1299 .close = via_dig_playback_pcm_close,
1300 .prepare = via_dig_playback_pcm_prepare,
1301 .cleanup = via_dig_playback_pcm_cleanup
1305 static const struct hda_pcm_stream via_pcm_digital_capture = {
1312 * slave controls for virtual master
1314 static const char * const via_slave_vols[] = {
1315 "Front Playback Volume",
1316 "Surround Playback Volume",
1317 "Center Playback Volume",
1318 "LFE Playback Volume",
1319 "Side Playback Volume",
1320 "Headphone Playback Volume",
1321 "Speaker Playback Volume",
1325 static const char * const via_slave_sws[] = {
1326 "Front Playback Switch",
1327 "Surround Playback Switch",
1328 "Center Playback Switch",
1329 "LFE Playback Switch",
1330 "Side Playback Switch",
1331 "Headphone Playback Switch",
1332 "Speaker Playback Switch",
1336 static int via_build_controls(struct hda_codec *codec)
1338 struct via_spec *spec = codec->spec;
1339 struct snd_kcontrol *kctl;
1342 if (spec->set_widgets_power_state)
1343 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1346 for (i = 0; i < spec->num_mixers; i++) {
1347 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1352 if (spec->multiout.dig_out_nid) {
1353 err = snd_hda_create_spdif_out_ctls(codec,
1354 spec->multiout.dig_out_nid,
1355 spec->multiout.dig_out_nid);
1358 err = snd_hda_create_spdif_share_sw(codec,
1362 spec->multiout.share_spdif = 1;
1364 if (spec->dig_in_nid) {
1365 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1370 /* if we have no master control, let's create it */
1371 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1372 unsigned int vmaster_tlv[4];
1373 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1374 HDA_OUTPUT, vmaster_tlv);
1375 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1376 vmaster_tlv, via_slave_vols);
1380 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1381 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1382 NULL, via_slave_sws);
1387 /* assign Capture Source enums to NID */
1388 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1389 for (i = 0; kctl && i < kctl->count; i++) {
1390 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1395 /* init power states */
1396 set_widgets_power_state(codec);
1397 analog_low_current_mode(codec);
1399 via_free_kctls(codec); /* no longer needed */
1403 static int via_build_pcms(struct hda_codec *codec)
1405 struct via_spec *spec = codec->spec;
1406 struct hda_pcm *info = spec->pcm_rec;
1408 codec->num_pcms = 1;
1409 codec->pcm_info = info;
1411 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1412 "%s Analog", codec->chip_name);
1413 info->name = spec->stream_name_analog;
1415 if (!spec->stream_analog_playback)
1416 spec->stream_analog_playback = &via_pcm_analog_playback;
1417 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1418 *spec->stream_analog_playback;
1419 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1420 spec->multiout.dac_nids[0];
1421 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1422 spec->multiout.max_channels;
1424 if (!spec->stream_analog_capture) {
1425 if (spec->dyn_adc_switch)
1426 spec->stream_analog_capture =
1427 &via_pcm_dyn_adc_analog_capture;
1429 spec->stream_analog_capture = &via_pcm_analog_capture;
1431 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1432 *spec->stream_analog_capture;
1433 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1434 if (!spec->dyn_adc_switch)
1435 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1438 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1441 snprintf(spec->stream_name_digital,
1442 sizeof(spec->stream_name_digital),
1443 "%s Digital", codec->chip_name);
1444 info->name = spec->stream_name_digital;
1445 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1446 if (spec->multiout.dig_out_nid) {
1447 if (!spec->stream_digital_playback)
1448 spec->stream_digital_playback =
1449 &via_pcm_digital_playback;
1450 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1451 *spec->stream_digital_playback;
1452 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1453 spec->multiout.dig_out_nid;
1455 if (spec->dig_in_nid) {
1456 if (!spec->stream_digital_capture)
1457 spec->stream_digital_capture =
1458 &via_pcm_digital_capture;
1459 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1460 *spec->stream_digital_capture;
1461 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1466 if (spec->hp_dac_nid) {
1469 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1470 "%s HP", codec->chip_name);
1471 info->name = spec->stream_name_hp;
1472 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1473 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1479 static void via_free(struct hda_codec *codec)
1481 struct via_spec *spec = codec->spec;
1486 via_free_kctls(codec);
1487 vt1708_stop_hp_work(spec);
1488 kfree(spec->bind_cap_vol);
1489 kfree(spec->bind_cap_sw);
1493 /* mute/unmute outputs */
1494 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1495 hda_nid_t *pins, bool mute)
1498 for (i = 0; i < num_pins; i++) {
1499 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1500 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1501 if (parm & AC_PINCTL_IN_EN)
1504 parm &= ~AC_PINCTL_OUT_EN;
1506 parm |= AC_PINCTL_OUT_EN;
1507 snd_hda_codec_write(codec, pins[i], 0,
1508 AC_VERB_SET_PIN_WIDGET_CONTROL, parm);
1512 /* mute internal speaker if line-out is plugged */
1513 static void via_line_automute(struct hda_codec *codec, int present)
1515 struct via_spec *spec = codec->spec;
1517 if (!spec->autocfg.speaker_outs)
1520 present = snd_hda_jack_detect(codec,
1521 spec->autocfg.line_out_pins[0]);
1522 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1523 spec->autocfg.speaker_pins,
1527 /* mute internal speaker if HP is plugged */
1528 static void via_hp_automute(struct hda_codec *codec)
1532 struct via_spec *spec = codec->spec;
1534 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0])
1535 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1537 if (spec->smart51_enabled)
1538 nums = spec->autocfg.line_outs + spec->smart51_nums;
1540 nums = spec->autocfg.line_outs;
1541 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1543 via_line_automute(codec, present);
1546 static void via_gpio_control(struct hda_codec *codec)
1548 unsigned int gpio_data;
1549 unsigned int vol_counter;
1551 unsigned int master_vol;
1553 struct via_spec *spec = codec->spec;
1555 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1556 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1558 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1559 0xF84, 0) & 0x3F0000) >> 16;
1561 vol = vol_counter & 0x1F;
1562 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1563 AC_VERB_GET_AMP_GAIN_MUTE,
1566 if (gpio_data == 0x02) {
1567 /* unmute line out */
1568 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1569 AC_VERB_SET_PIN_WIDGET_CONTROL,
1571 if (vol_counter & 0x20) {
1572 /* decrease volume */
1573 if (vol > master_vol)
1575 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1579 /* increase volume */
1580 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1582 ((master_vol+vol) > 0x2A) ? 0x2A :
1585 } else if (!(gpio_data & 0x02)) {
1587 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1588 AC_VERB_SET_PIN_WIDGET_CONTROL,
1593 /* unsolicited event for jack sensing */
1594 static void via_unsol_event(struct hda_codec *codec,
1599 if (res & VIA_JACK_EVENT)
1600 set_widgets_power_state(codec);
1602 res &= ~VIA_JACK_EVENT;
1604 if (res == VIA_HP_EVENT || res == VIA_LINE_EVENT)
1605 via_hp_automute(codec);
1606 else if (res == VIA_GPIO_EVENT)
1607 via_gpio_control(codec);
1610 #ifdef SND_HDA_NEEDS_RESUME
1611 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1613 struct via_spec *spec = codec->spec;
1614 vt1708_stop_hp_work(spec);
1619 #ifdef CONFIG_SND_HDA_POWER_SAVE
1620 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1622 struct via_spec *spec = codec->spec;
1623 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1630 static int via_init(struct hda_codec *codec);
1632 static const struct hda_codec_ops via_patch_ops = {
1633 .build_controls = via_build_controls,
1634 .build_pcms = via_build_pcms,
1637 .unsol_event = via_unsol_event,
1638 #ifdef SND_HDA_NEEDS_RESUME
1639 .suspend = via_suspend,
1641 #ifdef CONFIG_SND_HDA_POWER_SAVE
1642 .check_power_status = via_check_power_status,
1646 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1648 struct via_spec *spec = codec->spec;
1651 for (i = 0; i < spec->multiout.num_dacs; i++) {
1652 if (spec->multiout.dac_nids[i] == dac)
1655 if (spec->hp_dac_nid == dac)
1660 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1661 hda_nid_t target_dac, int with_aa_mix,
1662 struct nid_path *path, int depth)
1664 struct via_spec *spec = codec->spec;
1668 if (nid == spec->aa_mix_nid) {
1671 with_aa_mix = 2; /* mark aa-mix is included */
1674 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1675 for (i = 0; i < nums; i++) {
1676 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1678 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1679 /* aa-mix is requested but not included? */
1680 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1684 if (depth >= MAX_NID_PATH_DEPTH)
1686 for (i = 0; i < nums; i++) {
1688 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1689 if (type == AC_WID_AUD_OUT)
1691 if (__parse_output_path(codec, conn[i], target_dac,
1692 with_aa_mix, path, depth + 1))
1698 path->path[path->depth] = conn[i];
1699 path->idx[path->depth] = i;
1700 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1701 path->multi[path->depth] = 1;
1706 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1707 hda_nid_t target_dac, int with_aa_mix,
1708 struct nid_path *path)
1710 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
1711 path->path[path->depth] = nid;
1713 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1714 path->depth, path->path[0], path->path[1],
1715 path->path[2], path->path[3], path->path[4]);
1721 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1723 struct via_spec *spec = codec->spec;
1724 const struct auto_pin_cfg *cfg = &spec->autocfg;
1728 spec->multiout.dac_nids = spec->private_dac_nids;
1730 for (i = 0; i < cfg->line_outs; i++) {
1732 nid = cfg->line_out_pins[i];
1735 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1736 dac = spec->out_path[i].path[0];
1737 if (!i && parse_output_path(codec, nid, dac, 1,
1738 &spec->out_mix_path))
1739 dac = spec->out_mix_path.path[0];
1741 spec->private_dac_nids[i] = dac;
1745 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1746 spec->out_path[0] = spec->out_mix_path;
1747 spec->out_mix_path.depth = 0;
1749 spec->multiout.num_dacs = dac_num;
1753 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1754 int chs, bool check_dac, struct nid_path *path)
1756 struct via_spec *spec = codec->spec;
1758 hda_nid_t dac, pin, sel, nid;
1761 dac = check_dac ? path->path[0] : 0;
1762 pin = path->path[path->depth - 1];
1763 sel = path->depth > 1 ? path->path[1] : 0;
1765 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1767 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1769 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1774 sprintf(name, "%s Playback Volume", pfx);
1775 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1776 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1779 path->vol_ctl = nid;
1782 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1784 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1786 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1791 sprintf(name, "%s Playback Switch", pfx);
1792 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1793 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1796 path->mute_ctl = nid;
1801 static void mangle_smart51(struct hda_codec *codec)
1803 struct via_spec *spec = codec->spec;
1804 struct auto_pin_cfg *cfg = &spec->autocfg;
1805 struct auto_pin_cfg_item *ins = cfg->inputs;
1806 int i, j, nums, attr;
1807 int pins[AUTO_CFG_MAX_INS];
1809 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1811 for (i = 0; i < cfg->num_inputs; i++) {
1813 if (ins[i].type > AUTO_PIN_LINE_IN)
1815 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1816 if (snd_hda_get_input_pin_attr(def) != attr)
1818 for (j = 0; j < nums; j++)
1819 if (ins[pins[j]].type < ins[i].type) {
1820 memmove(pins + j + 1, pins + j,
1821 (nums - j) * sizeof(int));
1827 if (cfg->line_outs + nums < 3)
1829 for (i = 0; i < nums; i++) {
1830 hda_nid_t pin = ins[pins[i]].pin;
1831 spec->smart51_pins[spec->smart51_nums++] = pin;
1832 cfg->line_out_pins[cfg->line_outs++] = pin;
1833 if (cfg->line_outs == 3)
1840 /* add playback controls from the parsed DAC table */
1841 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1843 struct via_spec *spec = codec->spec;
1844 struct auto_pin_cfg *cfg = &spec->autocfg;
1845 struct nid_path *path;
1846 static const char * const chname[4] = {
1847 "Front", "Surround", "C/LFE", "Side"
1853 old_line_outs = cfg->line_outs;
1854 if (cfg->line_outs == 1)
1855 mangle_smart51(codec);
1857 err = via_auto_fill_dac_nids(codec);
1861 if (spec->multiout.num_dacs < 3) {
1862 spec->smart51_nums = 0;
1863 cfg->line_outs = old_line_outs;
1865 for (i = 0; i < cfg->line_outs; i++) {
1867 pin = cfg->line_out_pins[i];
1868 dac = spec->multiout.dac_nids[i];
1871 path = spec->out_path + i;
1872 if (i == HDA_CLFE) {
1873 err = create_ch_ctls(codec, "Center", 1, true, path);
1876 err = create_ch_ctls(codec, "LFE", 2, true, path);
1880 const char *pfx = chname[i];
1881 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1882 cfg->line_outs == 1)
1884 err = create_ch_ctls(codec, pfx, 3, true, path);
1888 if (path != spec->out_path + i) {
1889 spec->out_path[i].vol_ctl = path->vol_ctl;
1890 spec->out_path[i].mute_ctl = path->mute_ctl;
1892 if (path == spec->out_path && spec->out_mix_path.depth) {
1893 spec->out_mix_path.vol_ctl = path->vol_ctl;
1894 spec->out_mix_path.mute_ctl = path->mute_ctl;
1898 idx = get_connection_index(codec, spec->aa_mix_nid,
1899 spec->multiout.dac_nids[0]);
1901 /* add control to mixer */
1903 name = spec->out_mix_path.depth ?
1904 "PCM Loopback Playback Volume" : "PCM Playback Volume";
1905 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1906 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1910 name = spec->out_mix_path.depth ?
1911 "PCM Loopback Playback Switch" : "PCM Playback Switch";
1912 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1913 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1919 cfg->line_outs = old_line_outs;
1924 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1926 struct via_spec *spec = codec->spec;
1927 struct nid_path *path;
1934 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
1935 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
1936 if (i < spec->multiout.num_dacs &&
1937 parse_output_path(codec, pin,
1938 spec->multiout.dac_nids[i], 0,
1939 &spec->hp_indep_path)) {
1940 spec->hp_indep_shared = i;
1945 if (spec->hp_indep_path.depth) {
1946 spec->hp_dac_nid = spec->hp_indep_path.path[0];
1947 if (!spec->hp_indep_shared)
1948 spec->hp_path = spec->hp_indep_path;
1950 /* optionally check front-path w/o AA-mix */
1951 if (!spec->hp_path.depth)
1952 parse_output_path(codec, pin,
1953 spec->multiout.dac_nids[HDA_FRONT], 0,
1956 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1957 1, &spec->hp_mix_path) && !spec->hp_path.depth)
1960 if (spec->hp_path.depth) {
1961 path = &spec->hp_path;
1964 path = &spec->hp_mix_path;
1967 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
1971 spec->hp_mix_path.vol_ctl = path->vol_ctl;
1972 spec->hp_mix_path.mute_ctl = path->mute_ctl;
1974 spec->hp_path.vol_ctl = path->vol_ctl;
1975 spec->hp_path.mute_ctl = path->mute_ctl;
1980 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1982 struct via_spec *spec = codec->spec;
1983 struct nid_path *path;
1988 pin = spec->autocfg.speaker_pins[0];
1989 if (!spec->autocfg.speaker_outs || !pin)
1992 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
1993 dac = spec->speaker_path.path[0];
1995 parse_output_path(codec, pin,
1996 spec->multiout.dac_nids[HDA_FRONT], 0,
1997 &spec->speaker_path);
1998 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1999 1, &spec->speaker_mix_path) && !dac)
2002 /* no AA-path for front? */
2003 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2006 spec->speaker_dac_nid = dac;
2007 spec->multiout.extra_out_nid[0] = dac;
2009 path = &spec->speaker_path;
2012 path = &spec->speaker_mix_path;
2015 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2019 spec->speaker_mix_path.vol_ctl = path->vol_ctl;
2020 spec->speaker_mix_path.mute_ctl = path->mute_ctl;
2022 spec->speaker_path.vol_ctl = path->vol_ctl;
2023 spec->speaker_path.mute_ctl = path->mute_ctl;
2028 #define via_aamix_ctl_info via_pin_power_ctl_info
2030 static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2031 struct snd_ctl_elem_value *ucontrol)
2033 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2034 struct via_spec *spec = codec->spec;
2035 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2039 static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2040 struct nid_path *nomix, struct nid_path *mix)
2043 activate_output_path(codec, nomix, false, false);
2044 activate_output_path(codec, mix, true, false);
2046 activate_output_path(codec, mix, false, false);
2047 activate_output_path(codec, nomix, true, false);
2051 static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2052 struct snd_ctl_elem_value *ucontrol)
2054 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2055 struct via_spec *spec = codec->spec;
2056 unsigned int val = ucontrol->value.enumerated.item[0];
2058 if (val == spec->aamix_mode)
2060 spec->aamix_mode = val;
2061 /* update front path */
2062 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2063 /* update HP path */
2064 if (!spec->hp_independent_mode) {
2065 update_aamix_paths(codec, val, &spec->hp_path,
2066 &spec->hp_mix_path);
2068 /* update speaker path */
2069 update_aamix_paths(codec, val, &spec->speaker_path,
2070 &spec->speaker_mix_path);
2074 static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2075 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2076 .name = "Loopback Mixing",
2077 .info = via_aamix_ctl_info,
2078 .get = via_aamix_ctl_get,
2079 .put = via_aamix_ctl_put,
2082 static int via_auto_create_loopback_switch(struct hda_codec *codec)
2084 struct via_spec *spec = codec->spec;
2086 if (!spec->aa_mix_nid || !spec->out_mix_path.depth)
2087 return 0; /* no loopback switching available */
2088 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2094 static int via_fill_adcs(struct hda_codec *codec)
2096 struct via_spec *spec = codec->spec;
2097 hda_nid_t nid = codec->start_nid;
2100 for (i = 0; i < codec->num_nodes; i++, nid++) {
2101 unsigned int wcaps = get_wcaps(codec, nid);
2102 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2104 if (wcaps & AC_WCAP_DIGITAL)
2106 if (!(wcaps & AC_WCAP_CONN_LIST))
2108 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2110 spec->adc_nids[spec->num_adc_nids++] = nid;
2115 /* input-src control */
2116 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2117 struct snd_ctl_elem_info *uinfo)
2119 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2120 struct via_spec *spec = codec->spec;
2122 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2124 uinfo->value.enumerated.items = spec->num_inputs;
2125 if (uinfo->value.enumerated.item >= spec->num_inputs)
2126 uinfo->value.enumerated.item = spec->num_inputs - 1;
2127 strcpy(uinfo->value.enumerated.name,
2128 spec->inputs[uinfo->value.enumerated.item].label);
2132 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2133 struct snd_ctl_elem_value *ucontrol)
2135 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2136 struct via_spec *spec = codec->spec;
2137 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2139 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2143 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2144 struct snd_ctl_elem_value *ucontrol)
2146 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2147 struct via_spec *spec = codec->spec;
2148 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2152 cur = ucontrol->value.enumerated.item[0];
2153 if (cur < 0 || cur >= spec->num_inputs)
2155 if (spec->cur_mux[idx] == cur)
2157 spec->cur_mux[idx] = cur;
2158 if (spec->dyn_adc_switch) {
2159 int adc_idx = spec->inputs[cur].adc_idx;
2160 mux = spec->mux_nids[adc_idx];
2161 via_dyn_adc_pcm_resetup(codec, cur);
2163 mux = spec->mux_nids[idx];
2164 if (snd_BUG_ON(!mux))
2169 /* switch to D0 beofre change index */
2170 if (snd_hda_codec_read(codec, mux, 0,
2171 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
2172 snd_hda_codec_write(codec, mux, 0,
2173 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2174 snd_hda_codec_write(codec, mux, 0,
2175 AC_VERB_SET_CONNECT_SEL,
2176 spec->inputs[cur].mux_idx);
2179 /* update jack power state */
2180 set_widgets_power_state(codec);
2184 static const struct snd_kcontrol_new via_input_src_ctl = {
2185 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2186 /* The multiple "Capture Source" controls confuse alsamixer
2187 * So call somewhat different..
2189 /* .name = "Capture Source", */
2190 .name = "Input Source",
2191 .info = via_mux_enum_info,
2192 .get = via_mux_enum_get,
2193 .put = via_mux_enum_put,
2196 static int create_input_src_ctls(struct hda_codec *codec, int count)
2198 struct via_spec *spec = codec->spec;
2199 struct snd_kcontrol_new *knew;
2201 if (spec->num_inputs <= 1 || !count)
2202 return 0; /* no need for single src */
2204 knew = via_clone_control(spec, &via_input_src_ctl);
2207 knew->count = count;
2211 /* add the powersave loopback-list entry */
2212 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2214 struct hda_amp_list *list;
2216 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2218 list = spec->loopback_list + spec->num_loopbacks;
2220 list->dir = HDA_INPUT;
2222 spec->num_loopbacks++;
2223 spec->loopback.amplist = spec->loopback_list;
2226 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2229 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2232 /* add the input-route to the given pin */
2233 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2235 struct via_spec *spec = codec->spec;
2238 spec->inputs[spec->num_inputs].adc_idx = -1;
2239 spec->inputs[spec->num_inputs].pin = pin;
2240 for (c = 0; c < spec->num_adc_nids; c++) {
2241 if (spec->mux_nids[c]) {
2242 idx = get_connection_index(codec, spec->mux_nids[c],
2246 spec->inputs[spec->num_inputs].mux_idx = idx;
2248 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2251 spec->inputs[spec->num_inputs].adc_idx = c;
2252 /* Can primary ADC satisfy all inputs? */
2253 if (!spec->dyn_adc_switch &&
2254 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2255 snd_printd(KERN_INFO
2256 "via: dynamic ADC switching enabled\n");
2257 spec->dyn_adc_switch = 1;
2264 static int get_mux_nids(struct hda_codec *codec);
2266 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2267 static int parse_analog_inputs(struct hda_codec *codec)
2269 struct via_spec *spec = codec->spec;
2270 const struct auto_pin_cfg *cfg = &spec->autocfg;
2273 err = via_fill_adcs(codec);
2276 err = get_mux_nids(codec);
2280 /* fill all input-routes */
2281 for (i = 0; i < cfg->num_inputs; i++) {
2282 if (add_input_route(codec, cfg->inputs[i].pin))
2283 spec->inputs[spec->num_inputs++].label =
2284 hda_get_autocfg_input_label(codec, cfg, i);
2287 /* check for internal loopback recording */
2288 if (spec->aa_mix_nid &&
2289 add_input_route(codec, spec->aa_mix_nid))
2290 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2295 /* create analog-loopback volume/switch controls */
2296 static int create_loopback_ctls(struct hda_codec *codec)
2298 struct via_spec *spec = codec->spec;
2299 const struct auto_pin_cfg *cfg = &spec->autocfg;
2300 const char *prev_label = NULL;
2304 if (!spec->aa_mix_nid)
2307 for (i = 0; i < cfg->num_inputs; i++) {
2308 hda_nid_t pin = cfg->inputs[i].pin;
2309 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2311 if (prev_label && !strcmp(label, prev_label))
2316 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2318 err = via_new_analog_input(spec, label, type_idx,
2319 idx, spec->aa_mix_nid);
2322 add_loopback_list(spec, spec->aa_mix_nid, idx);
2325 /* remember the label for smart51 control */
2326 for (j = 0; j < spec->smart51_nums; j++) {
2327 if (spec->smart51_pins[j] == pin) {
2328 spec->smart51_idxs[j] = idx;
2329 spec->smart51_labels[j] = label;
2337 /* create mic-boost controls (if present) */
2338 static int create_mic_boost_ctls(struct hda_codec *codec)
2340 struct via_spec *spec = codec->spec;
2341 const struct auto_pin_cfg *cfg = &spec->autocfg;
2344 for (i = 0; i < cfg->num_inputs; i++) {
2345 hda_nid_t pin = cfg->inputs[i].pin;
2350 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2352 caps = query_amp_caps(codec, pin, HDA_INPUT);
2353 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2355 label = hda_get_autocfg_input_label(codec, cfg, i);
2356 snprintf(name, sizeof(name), "%s Boost Volume", label);
2357 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2358 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2365 /* create capture and input-src controls for multiple streams */
2366 static int create_multi_adc_ctls(struct hda_codec *codec)
2368 struct via_spec *spec = codec->spec;
2371 /* create capture mixer elements */
2372 for (i = 0; i < spec->num_adc_nids; i++) {
2373 hda_nid_t adc = spec->adc_nids[i];
2374 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2375 "Capture Volume", i,
2376 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2380 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2381 "Capture Switch", i,
2382 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2388 /* input-source control */
2389 for (i = 0; i < spec->num_adc_nids; i++)
2390 if (!spec->mux_nids[i])
2392 err = create_input_src_ctls(codec, i);
2398 /* bind capture volume/switch */
2399 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2400 HDA_BIND_VOL("Capture Volume", 0);
2401 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2402 HDA_BIND_SW("Capture Switch", 0);
2404 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2405 struct hda_ctl_ops *ops)
2407 struct hda_bind_ctls *ctl;
2410 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2414 for (i = 0; i < spec->num_adc_nids; i++)
2416 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2421 /* create capture and input-src controls for dynamic ADC-switch case */
2422 static int create_dyn_adc_ctls(struct hda_codec *codec)
2424 struct via_spec *spec = codec->spec;
2425 struct snd_kcontrol_new *knew;
2428 /* set up the bind capture ctls */
2429 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2432 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2436 /* create capture mixer elements */
2437 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2440 knew->private_value = (long)spec->bind_cap_vol;
2442 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2445 knew->private_value = (long)spec->bind_cap_sw;
2447 /* input-source control */
2448 err = create_input_src_ctls(codec, 1);
2454 /* parse and create capture-related stuff */
2455 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2457 struct via_spec *spec = codec->spec;
2460 err = parse_analog_inputs(codec);
2463 if (spec->dyn_adc_switch)
2464 err = create_dyn_adc_ctls(codec);
2466 err = create_multi_adc_ctls(codec);
2469 err = create_loopback_ctls(codec);
2472 err = create_mic_boost_ctls(codec);
2478 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2480 unsigned int def_conf;
2481 unsigned char seqassoc;
2483 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2484 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2485 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2486 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2487 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2488 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2489 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2495 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2496 struct snd_ctl_elem_value *ucontrol)
2498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2499 struct via_spec *spec = codec->spec;
2501 if (spec->codec_type != VT1708)
2503 spec->vt1708_jack_detect =
2504 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2505 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2509 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2510 struct snd_ctl_elem_value *ucontrol)
2512 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2513 struct via_spec *spec = codec->spec;
2516 if (spec->codec_type != VT1708)
2518 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2519 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2520 == !spec->vt1708_jack_detect;
2521 if (spec->vt1708_jack_detect) {
2522 mute_aa_path(codec, 1);
2523 notify_aa_path_ctls(codec);
2528 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2529 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2530 .name = "Jack Detect",
2532 .info = snd_ctl_boolean_mono_info,
2533 .get = vt1708_jack_detect_get,
2534 .put = vt1708_jack_detect_put,
2537 static void fill_dig_outs(struct hda_codec *codec);
2538 static void fill_dig_in(struct hda_codec *codec);
2540 static int via_parse_auto_config(struct hda_codec *codec)
2542 struct via_spec *spec = codec->spec;
2545 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2548 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2551 err = via_auto_create_multi_out_ctls(codec);
2554 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2557 err = via_auto_create_speaker_ctls(codec);
2560 err = via_auto_create_loopback_switch(codec);
2563 err = via_auto_create_analog_input_ctls(codec);
2567 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2569 fill_dig_outs(codec);
2572 if (spec->kctls.list)
2573 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2576 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
2577 err = via_hp_build(codec);
2582 err = via_smart51_build(codec);
2586 /* assign slave outs */
2587 if (spec->slave_dig_outs[0])
2588 codec->slave_dig_outs = spec->slave_dig_outs;
2593 static void via_auto_init_dig_outs(struct hda_codec *codec)
2595 struct via_spec *spec = codec->spec;
2596 if (spec->multiout.dig_out_nid)
2597 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2598 if (spec->slave_dig_outs[0])
2599 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2602 static void via_auto_init_dig_in(struct hda_codec *codec)
2604 struct via_spec *spec = codec->spec;
2605 if (!spec->dig_in_nid)
2607 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2608 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2611 /* initialize the unsolicited events */
2612 static void via_auto_init_unsol_event(struct hda_codec *codec)
2614 struct via_spec *spec = codec->spec;
2615 struct auto_pin_cfg *cfg = &spec->autocfg;
2619 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2620 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2621 AC_VERB_SET_UNSOLICITED_ENABLE,
2622 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2624 if (cfg->speaker_pins[0])
2625 ev = VIA_LINE_EVENT;
2628 for (i = 0; i < cfg->line_outs; i++) {
2629 if (cfg->line_out_pins[i] &&
2630 is_jack_detectable(codec, cfg->line_out_pins[i]))
2631 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
2632 AC_VERB_SET_UNSOLICITED_ENABLE,
2633 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2636 for (i = 0; i < cfg->num_inputs; i++) {
2637 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2638 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2639 AC_VERB_SET_UNSOLICITED_ENABLE,
2640 AC_USRSP_EN | VIA_JACK_EVENT);
2644 static int via_init(struct hda_codec *codec)
2646 struct via_spec *spec = codec->spec;
2649 for (i = 0; i < spec->num_iverbs; i++)
2650 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2652 via_auto_init_multi_out(codec);
2653 via_auto_init_hp_out(codec);
2654 via_auto_init_speaker_out(codec);
2655 via_auto_init_analog_input(codec);
2656 via_auto_init_dig_outs(codec);
2657 via_auto_init_dig_in(codec);
2659 via_auto_init_unsol_event(codec);
2661 via_hp_automute(codec);
2666 static void vt1708_update_hp_jack_state(struct work_struct *work)
2668 struct via_spec *spec = container_of(work, struct via_spec,
2669 vt1708_hp_work.work);
2670 if (spec->codec_type != VT1708)
2672 /* if jack state toggled */
2673 if (spec->vt1708_hp_present
2674 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2675 spec->vt1708_hp_present ^= 1;
2676 via_hp_automute(spec->codec);
2678 vt1708_start_hp_work(spec);
2681 static int get_mux_nids(struct hda_codec *codec)
2683 struct via_spec *spec = codec->spec;
2684 hda_nid_t nid, conn[8];
2688 for (i = 0; i < spec->num_adc_nids; i++) {
2689 nid = spec->adc_nids[i];
2691 type = get_wcaps_type(get_wcaps(codec, nid));
2692 if (type == AC_WID_PIN)
2694 n = snd_hda_get_connections(codec, nid, conn,
2699 spec->mux_nids[i] = nid;
2708 static int patch_vt1708(struct hda_codec *codec)
2710 struct via_spec *spec;
2713 /* create a codec specific record */
2714 spec = via_new_spec(codec);
2718 spec->aa_mix_nid = 0x17;
2720 /* Add HP and CD pin config connect bit re-config action */
2721 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2722 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2724 /* automatic parse from the BIOS config */
2725 err = via_parse_auto_config(codec);
2731 /* add jack detect on/off control */
2732 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2735 /* disable 32bit format on VT1708 */
2736 if (codec->vendor_id == 0x11061708)
2737 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2739 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2741 codec->patch_ops = via_patch_ops;
2743 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2747 static int patch_vt1709(struct hda_codec *codec)
2749 struct via_spec *spec;
2752 /* create a codec specific record */
2753 spec = via_new_spec(codec);
2757 spec->aa_mix_nid = 0x18;
2759 err = via_parse_auto_config(codec);
2765 codec->patch_ops = via_patch_ops;
2770 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2772 struct via_spec *spec = codec->spec;
2776 if ((spec->codec_type != VT1708B_4CH) &&
2777 (codec->vendor_id != 0x11064397))
2780 /* SW0 (17h) = stereo mixer */
2782 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2783 == ((spec->codec_type == VT1708S) ? 5 : 0));
2785 /* PW 1/2/5 (1ah/1bh/1eh) */
2787 set_pin_power_state(codec, 0x1a, &parm);
2788 set_pin_power_state(codec, 0x1b, &parm);
2789 set_pin_power_state(codec, 0x1e, &parm);
2792 /* SW0 (17h), AIW 0/1 (13h/14h) */
2793 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2794 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2795 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2798 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2800 set_pin_power_state(codec, 0x19, &parm);
2801 if (spec->smart51_enabled)
2802 set_pin_power_state(codec, 0x1b, &parm);
2803 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2804 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2806 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2809 set_pin_power_state(codec, 0x22, &parm);
2810 if (spec->smart51_enabled)
2811 set_pin_power_state(codec, 0x1a, &parm);
2812 snd_hda_codec_write(codec, 0x26, 0,
2813 AC_VERB_SET_POWER_STATE, parm);
2814 snd_hda_codec_write(codec, 0x24, 0,
2815 AC_VERB_SET_POWER_STATE, parm);
2816 } else if (codec->vendor_id == 0x11064397) {
2817 /* PW7(23h), SW2(27h), AOW2(25h) */
2819 set_pin_power_state(codec, 0x23, &parm);
2820 if (spec->smart51_enabled)
2821 set_pin_power_state(codec, 0x1a, &parm);
2822 snd_hda_codec_write(codec, 0x27, 0,
2823 AC_VERB_SET_POWER_STATE, parm);
2824 snd_hda_codec_write(codec, 0x25, 0,
2825 AC_VERB_SET_POWER_STATE, parm);
2828 /* PW 3/4/7 (1ch/1dh/23h) */
2830 /* force to D0 for internal Speaker */
2831 set_pin_power_state(codec, 0x1c, &parm);
2832 set_pin_power_state(codec, 0x1d, &parm);
2834 set_pin_power_state(codec, 0x23, &parm);
2836 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2837 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2838 imux_is_smixer ? AC_PWRST_D0 : parm);
2839 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2841 snd_hda_codec_write(codec, 0x25, 0,
2842 AC_VERB_SET_POWER_STATE, parm);
2843 snd_hda_codec_write(codec, 0x27, 0,
2844 AC_VERB_SET_POWER_STATE, parm);
2845 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2846 snd_hda_codec_write(codec, 0x25, 0,
2847 AC_VERB_SET_POWER_STATE, parm);
2850 static int patch_vt1708S(struct hda_codec *codec);
2851 static int patch_vt1708B(struct hda_codec *codec)
2853 struct via_spec *spec;
2856 if (get_codec_type(codec) == VT1708BCE)
2857 return patch_vt1708S(codec);
2859 /* create a codec specific record */
2860 spec = via_new_spec(codec);
2864 spec->aa_mix_nid = 0x16;
2866 /* automatic parse from the BIOS config */
2867 err = via_parse_auto_config(codec);
2873 codec->patch_ops = via_patch_ops;
2875 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2880 /* Patch for VT1708S */
2881 static const struct hda_verb vt1708S_init_verbs[] = {
2882 /* Enable Mic Boost Volume backdoor */
2884 /* don't bybass mixer */
2889 /* fill out digital output widgets; one for master and one for slave outputs */
2890 static void fill_dig_outs(struct hda_codec *codec)
2892 struct via_spec *spec = codec->spec;
2895 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2899 nid = spec->autocfg.dig_out_pins[i];
2902 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2905 if (!spec->multiout.dig_out_nid)
2906 spec->multiout.dig_out_nid = nid;
2908 spec->slave_dig_outs[0] = nid;
2909 break; /* at most two dig outs */
2914 static void fill_dig_in(struct hda_codec *codec)
2916 struct via_spec *spec = codec->spec;
2920 if (!spec->autocfg.dig_in_pin)
2923 dig_nid = codec->start_nid;
2924 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2925 unsigned int wcaps = get_wcaps(codec, dig_nid);
2926 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2928 if (!(wcaps & AC_WCAP_DIGITAL))
2930 if (!(wcaps & AC_WCAP_CONN_LIST))
2932 err = get_connection_index(codec, dig_nid,
2933 spec->autocfg.dig_in_pin);
2935 spec->dig_in_nid = dig_nid;
2941 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2942 int offset, int num_steps, int step_size)
2944 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2945 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2946 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2947 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2948 (0 << AC_AMPCAP_MUTE_SHIFT));
2951 static int patch_vt1708S(struct hda_codec *codec)
2953 struct via_spec *spec;
2956 /* create a codec specific record */
2957 spec = via_new_spec(codec);
2961 spec->aa_mix_nid = 0x16;
2962 override_mic_boost(codec, 0x1a, 0, 3, 40);
2963 override_mic_boost(codec, 0x1e, 0, 3, 40);
2965 /* automatic parse from the BIOS config */
2966 err = via_parse_auto_config(codec);
2972 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2974 codec->patch_ops = via_patch_ops;
2976 /* correct names for VT1708BCE */
2977 if (get_codec_type(codec) == VT1708BCE) {
2978 kfree(codec->chip_name);
2979 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2980 snprintf(codec->bus->card->mixername,
2981 sizeof(codec->bus->card->mixername),
2982 "%s %s", codec->vendor_name, codec->chip_name);
2984 /* correct names for VT1705 */
2985 if (codec->vendor_id == 0x11064397) {
2986 kfree(codec->chip_name);
2987 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2988 snprintf(codec->bus->card->mixername,
2989 sizeof(codec->bus->card->mixername),
2990 "%s %s", codec->vendor_name, codec->chip_name);
2992 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2996 /* Patch for VT1702 */
2998 static const struct hda_verb vt1702_init_verbs[] = {
3006 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3008 int imux_is_smixer =
3009 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3012 /* PW 1/2/5 (14h/15h/18h) */
3014 set_pin_power_state(codec, 0x14, &parm);
3015 set_pin_power_state(codec, 0x15, &parm);
3016 set_pin_power_state(codec, 0x18, &parm);
3018 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3019 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3020 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3021 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
3022 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3023 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
3026 /* PW 3/4 (16h/17h) */
3028 set_pin_power_state(codec, 0x17, &parm);
3029 set_pin_power_state(codec, 0x16, &parm);
3030 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3031 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
3032 imux_is_smixer ? AC_PWRST_D0 : parm);
3033 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3034 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3037 static int patch_vt1702(struct hda_codec *codec)
3039 struct via_spec *spec;
3042 /* create a codec specific record */
3043 spec = via_new_spec(codec);
3047 spec->aa_mix_nid = 0x1a;
3049 /* limit AA path volume to 0 dB */
3050 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3051 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3052 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3053 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3054 (1 << AC_AMPCAP_MUTE_SHIFT));
3056 /* automatic parse from the BIOS config */
3057 err = via_parse_auto_config(codec);
3063 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
3065 codec->patch_ops = via_patch_ops;
3067 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
3071 /* Patch for VT1718S */
3073 static const struct hda_verb vt1718S_init_verbs[] = {
3074 /* Enable MW0 adjust Gain 5 */
3076 /* Enable Boost Volume backdoor */
3082 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3084 struct via_spec *spec = codec->spec;
3087 /* MUX6 (1eh) = stereo mixer */
3089 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3091 /* PW 5/6/7 (29h/2ah/2bh) */
3093 set_pin_power_state(codec, 0x29, &parm);
3094 set_pin_power_state(codec, 0x2a, &parm);
3095 set_pin_power_state(codec, 0x2b, &parm);
3098 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3099 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3100 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3101 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3102 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3105 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3107 set_pin_power_state(codec, 0x27, &parm);
3108 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
3109 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
3111 /* PW2 (26h), AOW2 (ah) */
3113 set_pin_power_state(codec, 0x26, &parm);
3114 if (spec->smart51_enabled)
3115 set_pin_power_state(codec, 0x2b, &parm);
3116 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
3118 /* PW0 (24h), AOW0 (8h) */
3120 set_pin_power_state(codec, 0x24, &parm);
3121 if (!spec->hp_independent_mode) /* check for redirected HP */
3122 set_pin_power_state(codec, 0x28, &parm);
3123 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3124 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3125 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3126 imux_is_smixer ? AC_PWRST_D0 : parm);
3128 /* PW1 (25h), AOW1 (9h) */
3130 set_pin_power_state(codec, 0x25, &parm);
3131 if (spec->smart51_enabled)
3132 set_pin_power_state(codec, 0x2a, &parm);
3133 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3135 if (spec->hp_independent_mode) {
3136 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3138 set_pin_power_state(codec, 0x28, &parm);
3139 snd_hda_codec_write(codec, 0x1b, 0,
3140 AC_VERB_SET_POWER_STATE, parm);
3141 snd_hda_codec_write(codec, 0x34, 0,
3142 AC_VERB_SET_POWER_STATE, parm);
3143 snd_hda_codec_write(codec, 0xc, 0,
3144 AC_VERB_SET_POWER_STATE, parm);
3148 /* Add a connection to the primary DAC from AA-mixer for some codecs
3149 * This isn't listed from the raw info, but the chip has a secret connection.
3151 static int add_secret_dac_path(struct hda_codec *codec)
3153 struct via_spec *spec = codec->spec;
3158 if (!spec->aa_mix_nid)
3160 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3161 ARRAY_SIZE(conn) - 1);
3162 for (i = 0; i < nums; i++) {
3163 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3167 /* find the primary DAC and add to the connection list */
3168 nid = codec->start_nid;
3169 for (i = 0; i < codec->num_nodes; i++, nid++) {
3170 unsigned int caps = get_wcaps(codec, nid);
3171 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3172 !(caps & AC_WCAP_DIGITAL)) {
3174 return snd_hda_override_conn_list(codec,
3183 static int patch_vt1718S(struct hda_codec *codec)
3185 struct via_spec *spec;
3188 /* create a codec specific record */
3189 spec = via_new_spec(codec);
3193 spec->aa_mix_nid = 0x21;
3194 override_mic_boost(codec, 0x2b, 0, 3, 40);
3195 override_mic_boost(codec, 0x29, 0, 3, 40);
3196 add_secret_dac_path(codec);
3198 /* automatic parse from the BIOS config */
3199 err = via_parse_auto_config(codec);
3205 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3207 codec->patch_ops = via_patch_ops;
3209 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3214 /* Patch for VT1716S */
3216 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3217 struct snd_ctl_elem_info *uinfo)
3219 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3221 uinfo->value.integer.min = 0;
3222 uinfo->value.integer.max = 1;
3226 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3227 struct snd_ctl_elem_value *ucontrol)
3229 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3232 index = snd_hda_codec_read(codec, 0x26, 0,
3233 AC_VERB_GET_CONNECT_SEL, 0);
3235 *ucontrol->value.integer.value = index;
3240 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3241 struct snd_ctl_elem_value *ucontrol)
3243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3244 struct via_spec *spec = codec->spec;
3245 int index = *ucontrol->value.integer.value;
3247 snd_hda_codec_write(codec, 0x26, 0,
3248 AC_VERB_SET_CONNECT_SEL, index);
3249 spec->dmic_enabled = index;
3250 set_widgets_power_state(codec);
3254 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3255 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3257 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3258 .name = "Digital Mic Capture Switch",
3259 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3261 .info = vt1716s_dmic_info,
3262 .get = vt1716s_dmic_get,
3263 .put = vt1716s_dmic_put,
3269 /* mono-out mixer elements */
3270 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3271 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3275 static const struct hda_verb vt1716S_init_verbs[] = {
3276 /* Enable Boost Volume backdoor */
3278 /* don't bybass mixer */
3280 /* Enable mono output */
3285 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3287 struct via_spec *spec = codec->spec;
3290 unsigned int mono_out, present;
3291 /* SW0 (17h) = stereo mixer */
3293 (snd_hda_codec_read(codec, 0x17, 0,
3294 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3296 /* PW 1/2/5 (1ah/1bh/1eh) */
3298 set_pin_power_state(codec, 0x1a, &parm);
3299 set_pin_power_state(codec, 0x1b, &parm);
3300 set_pin_power_state(codec, 0x1e, &parm);
3303 /* SW0 (17h), AIW0(13h) */
3304 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3305 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3308 set_pin_power_state(codec, 0x1e, &parm);
3310 if (spec->dmic_enabled)
3311 set_pin_power_state(codec, 0x22, &parm);
3313 snd_hda_codec_write(codec, 0x22, 0,
3314 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3316 /* SW2(26h), AIW1(14h) */
3317 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3318 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3321 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3323 set_pin_power_state(codec, 0x19, &parm);
3324 /* Smart 5.1 PW2(1bh) */
3325 if (spec->smart51_enabled)
3326 set_pin_power_state(codec, 0x1b, &parm);
3327 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3328 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3330 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3332 set_pin_power_state(codec, 0x23, &parm);
3333 /* Smart 5.1 PW1(1ah) */
3334 if (spec->smart51_enabled)
3335 set_pin_power_state(codec, 0x1a, &parm);
3336 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3338 /* Smart 5.1 PW5(1eh) */
3339 if (spec->smart51_enabled)
3340 set_pin_power_state(codec, 0x1e, &parm);
3341 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3344 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3345 present = snd_hda_jack_detect(codec, 0x1c);
3350 present = snd_hda_jack_detect(codec, 0x1d);
3351 if (!spec->hp_independent_mode && present)
3356 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3357 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3358 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3359 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3361 /* PW 3/4 (1ch/1dh) */
3363 set_pin_power_state(codec, 0x1c, &parm);
3364 set_pin_power_state(codec, 0x1d, &parm);
3365 /* HP Independent Mode, power on AOW3 */
3366 if (spec->hp_independent_mode)
3367 snd_hda_codec_write(codec, 0x25, 0,
3368 AC_VERB_SET_POWER_STATE, parm);
3370 /* force to D0 for internal Speaker */
3371 /* MW0 (16h), AOW0 (10h) */
3372 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3373 imux_is_smixer ? AC_PWRST_D0 : parm);
3374 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3375 mono_out ? AC_PWRST_D0 : parm);
3378 static int patch_vt1716S(struct hda_codec *codec)
3380 struct via_spec *spec;
3383 /* create a codec specific record */
3384 spec = via_new_spec(codec);
3388 spec->aa_mix_nid = 0x16;
3389 override_mic_boost(codec, 0x1a, 0, 3, 40);
3390 override_mic_boost(codec, 0x1e, 0, 3, 40);
3392 /* automatic parse from the BIOS config */
3393 err = via_parse_auto_config(codec);
3399 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3401 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3404 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3406 codec->patch_ops = via_patch_ops;
3408 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3414 static const struct hda_verb vt2002P_init_verbs[] = {
3415 /* Class-D speaker related verbs */
3419 /* Enable Boost Volume backdoor */
3421 /* Enable AOW0 to MW9 */
3426 static const struct hda_verb vt1802_init_verbs[] = {
3427 /* Enable Boost Volume backdoor */
3429 /* Enable AOW0 to MW9 */
3434 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3436 struct via_spec *spec = codec->spec;
3439 unsigned int present;
3440 /* MUX9 (1eh) = stereo mixer */
3442 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3444 /* PW 5/6/7 (29h/2ah/2bh) */
3446 set_pin_power_state(codec, 0x29, &parm);
3447 set_pin_power_state(codec, 0x2a, &parm);
3448 set_pin_power_state(codec, 0x2b, &parm);
3450 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3451 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3452 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3453 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3454 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3458 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3460 if (spec->codec_type == VT1802) {
3461 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3463 set_pin_power_state(codec, 0x28, &parm);
3464 snd_hda_codec_write(codec, 0x18, 0,
3465 AC_VERB_SET_POWER_STATE, parm);
3466 snd_hda_codec_write(codec, 0x38, 0,
3467 AC_VERB_SET_POWER_STATE, parm);
3469 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3471 set_pin_power_state(codec, 0x26, &parm);
3472 snd_hda_codec_write(codec, 0x1c, 0,
3473 AC_VERB_SET_POWER_STATE, parm);
3474 snd_hda_codec_write(codec, 0x37, 0,
3475 AC_VERB_SET_POWER_STATE, parm);
3478 if (spec->codec_type == VT1802) {
3479 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3481 set_pin_power_state(codec, 0x25, &parm);
3482 snd_hda_codec_write(codec, 0x15, 0,
3483 AC_VERB_SET_POWER_STATE, parm);
3484 snd_hda_codec_write(codec, 0x35, 0,
3485 AC_VERB_SET_POWER_STATE, parm);
3487 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3489 set_pin_power_state(codec, 0x25, &parm);
3490 snd_hda_codec_write(codec, 0x19, 0,
3491 AC_VERB_SET_POWER_STATE, parm);
3492 snd_hda_codec_write(codec, 0x35, 0,
3493 AC_VERB_SET_POWER_STATE, parm);
3496 if (spec->hp_independent_mode)
3497 snd_hda_codec_write(codec, 0x9, 0,
3498 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3501 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3502 present = snd_hda_jack_detect(codec, 0x25);
3505 set_pin_power_state(codec, 0x24, &parm);
3506 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3507 if (spec->codec_type == VT1802)
3508 snd_hda_codec_write(codec, 0x14, 0,
3509 AC_VERB_SET_POWER_STATE, parm);
3511 snd_hda_codec_write(codec, 0x18, 0,
3512 AC_VERB_SET_POWER_STATE, parm);
3513 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3516 present = snd_hda_jack_detect(codec, 0x26);
3518 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3519 if (spec->codec_type == VT1802) {
3520 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3521 snd_hda_codec_write(codec, 0x33, 0,
3522 AC_VERB_SET_POWER_STATE, parm);
3523 snd_hda_codec_write(codec, 0x1c, 0,
3524 AC_VERB_SET_POWER_STATE, parm);
3525 snd_hda_codec_write(codec, 0x3c, 0,
3526 AC_VERB_SET_POWER_STATE, parm);
3528 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3529 snd_hda_codec_write(codec, 0x31, 0,
3530 AC_VERB_SET_POWER_STATE, parm);
3531 snd_hda_codec_write(codec, 0x17, 0,
3532 AC_VERB_SET_POWER_STATE, parm);
3533 snd_hda_codec_write(codec, 0x3b, 0,
3534 AC_VERB_SET_POWER_STATE, parm);
3537 if (imux_is_smixer || !is_aa_path_mute(codec))
3538 snd_hda_codec_write(codec, 0x21, 0,
3539 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3541 snd_hda_codec_write(codec, 0x21, 0,
3542 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3545 /* patch for vt2002P */
3546 static int patch_vt2002P(struct hda_codec *codec)
3548 struct via_spec *spec;
3551 /* create a codec specific record */
3552 spec = via_new_spec(codec);
3556 spec->aa_mix_nid = 0x21;
3557 override_mic_boost(codec, 0x2b, 0, 3, 40);
3558 override_mic_boost(codec, 0x29, 0, 3, 40);
3559 add_secret_dac_path(codec);
3561 /* automatic parse from the BIOS config */
3562 err = via_parse_auto_config(codec);
3568 if (spec->codec_type == VT1802)
3569 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3571 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3573 codec->patch_ops = via_patch_ops;
3575 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3581 static const struct hda_verb vt1812_init_verbs[] = {
3582 /* Enable Boost Volume backdoor */
3584 /* Enable AOW0 to MW9 */
3589 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3591 struct via_spec *spec = codec->spec;
3592 int imux_is_smixer =
3593 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3595 unsigned int present;
3596 /* MUX10 (1eh) = stereo mixer */
3598 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3600 /* PW 5/6/7 (29h/2ah/2bh) */
3602 set_pin_power_state(codec, 0x29, &parm);
3603 set_pin_power_state(codec, 0x2a, &parm);
3604 set_pin_power_state(codec, 0x2b, &parm);
3606 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3607 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3608 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3609 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3610 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3614 snd_hda_codec_write(codec, 0x8, 0,
3615 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3617 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3619 set_pin_power_state(codec, 0x28, &parm);
3620 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3621 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3623 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3625 set_pin_power_state(codec, 0x25, &parm);
3626 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3627 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3628 if (spec->hp_independent_mode)
3629 snd_hda_codec_write(codec, 0x9, 0,
3630 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3632 /* Internal Speaker */
3633 /* PW0 (24h), MW0(14h), MUX0(34h) */
3634 present = snd_hda_jack_detect(codec, 0x25);
3637 set_pin_power_state(codec, 0x24, &parm);
3639 snd_hda_codec_write(codec, 0x14, 0,
3640 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3641 snd_hda_codec_write(codec, 0x34, 0,
3642 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3644 snd_hda_codec_write(codec, 0x14, 0,
3645 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3646 snd_hda_codec_write(codec, 0x34, 0,
3647 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3652 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3653 present = snd_hda_jack_detect(codec, 0x28);
3656 set_pin_power_state(codec, 0x31, &parm);
3658 snd_hda_codec_write(codec, 0x1c, 0,
3659 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3660 snd_hda_codec_write(codec, 0x3c, 0,
3661 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3662 snd_hda_codec_write(codec, 0x3e, 0,
3663 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3665 snd_hda_codec_write(codec, 0x1c, 0,
3666 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3667 snd_hda_codec_write(codec, 0x3c, 0,
3668 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3669 snd_hda_codec_write(codec, 0x3e, 0,
3670 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3673 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3675 set_pin_power_state(codec, 0x33, &parm);
3676 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3677 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3681 /* patch for vt1812 */
3682 static int patch_vt1812(struct hda_codec *codec)
3684 struct via_spec *spec;
3687 /* create a codec specific record */
3688 spec = via_new_spec(codec);
3692 spec->aa_mix_nid = 0x21;
3693 override_mic_boost(codec, 0x2b, 0, 3, 40);
3694 override_mic_boost(codec, 0x29, 0, 3, 40);
3695 add_secret_dac_path(codec);
3697 /* automatic parse from the BIOS config */
3698 err = via_parse_auto_config(codec);
3704 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3706 codec->patch_ops = via_patch_ops;
3708 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3715 static const struct hda_codec_preset snd_hda_preset_via[] = {
3716 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3717 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3718 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3719 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3720 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3721 .patch = patch_vt1709},
3722 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3723 .patch = patch_vt1709},
3724 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3725 .patch = patch_vt1709},
3726 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3727 .patch = patch_vt1709},
3728 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3729 .patch = patch_vt1709},
3730 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3731 .patch = patch_vt1709},
3732 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3733 .patch = patch_vt1709},
3734 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3735 .patch = patch_vt1709},
3736 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3737 .patch = patch_vt1708B},
3738 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3739 .patch = patch_vt1708B},
3740 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3741 .patch = patch_vt1708B},
3742 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3743 .patch = patch_vt1708B},
3744 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3745 .patch = patch_vt1708B},
3746 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3747 .patch = patch_vt1708B},
3748 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3749 .patch = patch_vt1708B},
3750 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3751 .patch = patch_vt1708B},
3752 { .id = 0x11060397, .name = "VT1708S",
3753 .patch = patch_vt1708S},
3754 { .id = 0x11061397, .name = "VT1708S",
3755 .patch = patch_vt1708S},
3756 { .id = 0x11062397, .name = "VT1708S",
3757 .patch = patch_vt1708S},
3758 { .id = 0x11063397, .name = "VT1708S",
3759 .patch = patch_vt1708S},
3760 { .id = 0x11064397, .name = "VT1705",
3761 .patch = patch_vt1708S},
3762 { .id = 0x11065397, .name = "VT1708S",
3763 .patch = patch_vt1708S},
3764 { .id = 0x11066397, .name = "VT1708S",
3765 .patch = patch_vt1708S},
3766 { .id = 0x11067397, .name = "VT1708S",
3767 .patch = patch_vt1708S},
3768 { .id = 0x11060398, .name = "VT1702",
3769 .patch = patch_vt1702},
3770 { .id = 0x11061398, .name = "VT1702",
3771 .patch = patch_vt1702},
3772 { .id = 0x11062398, .name = "VT1702",
3773 .patch = patch_vt1702},
3774 { .id = 0x11063398, .name = "VT1702",
3775 .patch = patch_vt1702},
3776 { .id = 0x11064398, .name = "VT1702",
3777 .patch = patch_vt1702},
3778 { .id = 0x11065398, .name = "VT1702",
3779 .patch = patch_vt1702},
3780 { .id = 0x11066398, .name = "VT1702",
3781 .patch = patch_vt1702},
3782 { .id = 0x11067398, .name = "VT1702",
3783 .patch = patch_vt1702},
3784 { .id = 0x11060428, .name = "VT1718S",
3785 .patch = patch_vt1718S},
3786 { .id = 0x11064428, .name = "VT1718S",
3787 .patch = patch_vt1718S},
3788 { .id = 0x11060441, .name = "VT2020",
3789 .patch = patch_vt1718S},
3790 { .id = 0x11064441, .name = "VT1828S",
3791 .patch = patch_vt1718S},
3792 { .id = 0x11060433, .name = "VT1716S",
3793 .patch = patch_vt1716S},
3794 { .id = 0x1106a721, .name = "VT1716S",
3795 .patch = patch_vt1716S},
3796 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3797 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3798 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3799 { .id = 0x11060440, .name = "VT1818S",
3800 .patch = patch_vt1708S},
3801 { .id = 0x11060446, .name = "VT1802",
3802 .patch = patch_vt2002P},
3803 { .id = 0x11068446, .name = "VT1802",
3804 .patch = patch_vt2002P},
3808 MODULE_ALIAS("snd-hda-codec-id:1106*");
3810 static struct hda_codec_preset_list via_list = {
3811 .preset = snd_hda_preset_via,
3812 .owner = THIS_MODULE,
3815 MODULE_LICENSE("GPL");
3816 MODULE_DESCRIPTION("VIA HD-audio codec");
3818 static int __init patch_via_init(void)
3820 return snd_hda_add_codec_preset(&via_list);
3823 static void __exit patch_via_exit(void)
3825 snd_hda_delete_codec_preset(&via_list);
3828 module_init(patch_via_init)
3829 module_exit(patch_via_exit)