2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <linux/module.h>
53 #include <sound/core.h>
54 #include <sound/asoundef.h>
55 #include "hda_codec.h"
56 #include "hda_local.h"
57 #include "hda_auto_parser.h"
61 #define VT1708_HP_PIN_NID 0x20
62 #define VT1708_CD_PIN_NID 0x24
82 #define VT2002P_COMPATIBLE(spec) \
83 ((spec)->codec_type == VT2002P ||\
84 (spec)->codec_type == VT1812 ||\
85 (spec)->codec_type == VT1802)
87 #define MAX_NID_PATH_DEPTH 5
89 /* output-path: DAC -> ... -> pin
90 * idx[] contains the source index number of the next widget;
91 * e.g. idx[0] is the index of the DAC selected by path[1] widget
92 * multi[] indicates whether it's a selector widget with multi-connectors
93 * (i.e. the connection selection is mandatory)
94 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
98 hda_nid_t path[MAX_NID_PATH_DEPTH];
99 unsigned char idx[MAX_NID_PATH_DEPTH];
100 unsigned char multi[MAX_NID_PATH_DEPTH];
101 unsigned int vol_ctl;
102 unsigned int mute_ctl;
107 hda_nid_t pin; /* input-pin or aa-mix */
108 int adc_idx; /* ADC index to be used */
109 int mux_idx; /* MUX index (if any) */
110 const char *label; /* input-source label */
113 #define VIA_MAX_ADCS 3
116 STREAM_MULTI_OUT = (1 << 0),
117 STREAM_INDEP_HP = (1 << 1),
121 /* codec parameterization */
122 const struct snd_kcontrol_new *mixers[6];
123 unsigned int num_mixers;
125 const struct hda_verb *init_verbs[5];
126 unsigned int num_iverbs;
128 char stream_name_analog[32];
129 char stream_name_hp[32];
130 const struct hda_pcm_stream *stream_analog_playback;
131 const struct hda_pcm_stream *stream_analog_capture;
133 char stream_name_digital[32];
134 const struct hda_pcm_stream *stream_digital_playback;
135 const struct hda_pcm_stream *stream_digital_capture;
138 struct hda_multi_out multiout;
139 hda_nid_t slave_dig_outs[2];
140 hda_nid_t hp_dac_nid;
141 hda_nid_t speaker_dac_nid;
142 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
143 int opened_streams; /* STREAM_* bits */
144 int active_streams; /* STREAM_* bits */
145 int aamix_mode; /* loopback is enabled for output-path? */
148 * There are different output-paths depending on the setup.
149 * out_path, hp_path and speaker_path are primary paths. If both
150 * direct DAC and aa-loopback routes are available, these contain
151 * the former paths. Meanwhile *_mix_path contain the paths with
152 * loopback mixer. (Since the loopback is only for front channel,
153 * no out_mix_path for surround channels.)
154 * The HP output has another path, hp_indep_path, which is used in
155 * the independent-HP mode.
157 struct nid_path out_path[HDA_SIDE + 1];
158 struct nid_path out_mix_path;
159 struct nid_path hp_path;
160 struct nid_path hp_mix_path;
161 struct nid_path hp_indep_path;
162 struct nid_path speaker_path;
163 struct nid_path speaker_mix_path;
166 unsigned int num_adc_nids;
167 hda_nid_t adc_nids[VIA_MAX_ADCS];
168 hda_nid_t mux_nids[VIA_MAX_ADCS];
169 hda_nid_t aa_mix_nid;
170 hda_nid_t dig_in_nid;
175 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
176 unsigned int cur_mux[VIA_MAX_ADCS];
178 /* dynamic DAC switching */
179 unsigned int cur_dac_stream_tag;
180 unsigned int cur_dac_format;
181 unsigned int cur_hp_stream_tag;
182 unsigned int cur_hp_format;
184 /* dynamic ADC switching */
186 unsigned int cur_adc_stream_tag;
187 unsigned int cur_adc_format;
189 /* PCM information */
190 struct hda_pcm pcm_rec[3];
192 /* dynamic controls, init_verbs and input_mux */
193 struct auto_pin_cfg autocfg;
194 struct snd_array kctls;
195 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
198 unsigned int hp_independent_mode;
199 unsigned int dmic_enabled;
200 unsigned int no_pin_power_ctl;
201 enum VIA_HDA_CODEC codec_type;
203 /* analog low-power control */
207 unsigned int smart51_nums;
208 hda_nid_t smart51_pins[2];
210 const char *smart51_labels[2];
211 unsigned int smart51_enabled;
213 /* work to check hp jack state */
214 struct hda_codec *codec;
215 struct delayed_work vt1708_hp_work;
217 int vt1708_jack_detect;
218 int vt1708_hp_present;
220 void (*set_widgets_power_state)(struct hda_codec *codec);
222 struct hda_loopback_check loopback;
224 struct hda_amp_list loopback_list[8];
226 /* bind capture-volume */
227 struct hda_bind_ctls *bind_cap_vol;
228 struct hda_bind_ctls *bind_cap_sw;
230 struct mutex config_mutex;
233 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
234 static struct via_spec * via_new_spec(struct hda_codec *codec)
236 struct via_spec *spec;
238 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
242 mutex_init(&spec->config_mutex);
245 spec->codec_type = get_codec_type(codec);
246 /* VT1708BCE & VT1708S are almost same */
247 if (spec->codec_type == VT1708BCE)
248 spec->codec_type = VT1708S;
252 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
254 u32 vendor_id = codec->vendor_id;
255 u16 ven_id = vendor_id >> 16;
256 u16 dev_id = vendor_id & 0xffff;
257 enum VIA_HDA_CODEC codec_type;
260 if (ven_id != 0x1106)
261 codec_type = UNKNOWN;
262 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
264 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
265 codec_type = VT1709_10CH;
266 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
267 codec_type = VT1709_6CH;
268 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
269 codec_type = VT1708B_8CH;
270 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
271 codec_type = VT1708BCE;
272 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
273 codec_type = VT1708B_4CH;
274 else if ((dev_id & 0xfff) == 0x397
275 && (dev_id >> 12) < 8)
276 codec_type = VT1708S;
277 else if ((dev_id & 0xfff) == 0x398
278 && (dev_id >> 12) < 8)
280 else if ((dev_id & 0xfff) == 0x428
281 && (dev_id >> 12) < 8)
282 codec_type = VT1718S;
283 else if (dev_id == 0x0433 || dev_id == 0xa721)
284 codec_type = VT1716S;
285 else if (dev_id == 0x0441 || dev_id == 0x4441)
286 codec_type = VT1718S;
287 else if (dev_id == 0x0438 || dev_id == 0x4438)
288 codec_type = VT2002P;
289 else if (dev_id == 0x0448)
291 else if (dev_id == 0x0440)
292 codec_type = VT1708S;
293 else if ((dev_id & 0xfff) == 0x446)
296 codec_type = UNKNOWN;
300 #define VIA_JACK_EVENT 0x20
301 #define VIA_HP_EVENT 0x01
302 #define VIA_GPIO_EVENT 0x02
303 #define VIA_LINE_EVENT 0x03
308 VIA_CTL_WIDGET_ANALOG_MUTE,
311 static void analog_low_current_mode(struct hda_codec *codec);
312 static bool is_aa_path_mute(struct hda_codec *codec);
314 #define hp_detect_with_aa(codec) \
315 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
316 !is_aa_path_mute(codec))
318 static void vt1708_stop_hp_work(struct via_spec *spec)
320 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
322 if (spec->hp_work_active) {
323 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
324 cancel_delayed_work_sync(&spec->vt1708_hp_work);
325 spec->hp_work_active = 0;
329 static void vt1708_update_hp_work(struct via_spec *spec)
331 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
333 if (spec->vt1708_jack_detect &&
334 (spec->active_streams || hp_detect_with_aa(spec->codec))) {
335 if (!spec->hp_work_active) {
336 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
337 schedule_delayed_work(&spec->vt1708_hp_work,
338 msecs_to_jiffies(100));
339 spec->hp_work_active = 1;
341 } else if (!hp_detect_with_aa(spec->codec))
342 vt1708_stop_hp_work(spec);
345 static void set_widgets_power_state(struct hda_codec *codec)
347 struct via_spec *spec = codec->spec;
348 if (spec->set_widgets_power_state)
349 spec->set_widgets_power_state(codec);
352 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
353 struct snd_ctl_elem_value *ucontrol)
355 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
356 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
358 set_widgets_power_state(codec);
359 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
360 vt1708_update_hp_work(codec->spec);
364 /* modify .put = snd_hda_mixer_amp_switch_put */
365 #define ANALOG_INPUT_MUTE \
366 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
369 .info = snd_hda_mixer_amp_switch_info, \
370 .get = snd_hda_mixer_amp_switch_get, \
371 .put = analog_input_switch_put, \
372 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
374 static const struct snd_kcontrol_new via_control_templates[] = {
375 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
376 HDA_CODEC_MUTE(NULL, 0, 0, 0),
381 /* add dynamic controls */
382 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
383 const struct snd_kcontrol_new *tmpl,
386 struct snd_kcontrol_new *knew;
388 snd_array_init(&spec->kctls, sizeof(*knew), 32);
389 knew = snd_array_new(&spec->kctls);
396 knew->name = kstrdup(name, GFP_KERNEL);
403 static int __via_add_control(struct via_spec *spec, int type, const char *name,
404 int idx, unsigned long val)
406 struct snd_kcontrol_new *knew;
408 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
412 if (get_amp_nid_(val))
413 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
414 knew->private_value = val;
418 #define via_add_control(spec, type, name, val) \
419 __via_add_control(spec, type, name, 0, val)
421 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
423 static void via_free_kctls(struct hda_codec *codec)
425 struct via_spec *spec = codec->spec;
427 if (spec->kctls.list) {
428 struct snd_kcontrol_new *kctl = spec->kctls.list;
430 for (i = 0; i < spec->kctls.used; i++)
433 snd_array_free(&spec->kctls);
436 /* create input playback/capture controls for the given pin */
437 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
438 int type_idx, int idx, int mix_nid)
443 sprintf(name, "%s Playback Volume", ctlname);
444 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
445 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
448 sprintf(name, "%s Playback Switch", ctlname);
449 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
450 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
456 #define get_connection_index(codec, mux, nid) \
457 snd_hda_get_conn_index(codec, mux, nid, 0)
459 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
465 caps = get_wcaps(codec, nid);
466 if (dir == HDA_INPUT)
467 caps &= AC_WCAP_IN_AMP;
469 caps &= AC_WCAP_OUT_AMP;
472 if (query_amp_caps(codec, nid, dir) & mask)
477 #define have_mute(codec, nid, dir) \
478 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
480 /* enable/disable the output-route mixers */
481 static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
482 hda_nid_t mix_nid, int idx, bool enable)
488 num = snd_hda_get_num_conns(codec, mix_nid);
489 for (i = 0; i < num; i++) {
491 val = AMP_IN_UNMUTE(i);
493 val = AMP_IN_MUTE(i);
494 snd_hda_codec_write(codec, mix_nid, 0,
495 AC_VERB_SET_AMP_GAIN_MUTE, val);
499 /* enable/disable the output-route */
500 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
501 bool enable, bool force)
503 struct via_spec *spec = codec->spec;
505 for (i = 0; i < path->depth; i++) {
507 int idx = path->idx[i];
509 if (i < path->depth - 1)
510 dst = path->path[i + 1];
513 if (enable && path->multi[i])
514 snd_hda_codec_write(codec, dst, 0,
515 AC_VERB_SET_CONNECT_SEL, idx);
516 if (!force && (dst == spec->aa_mix_nid))
518 if (have_mute(codec, dst, HDA_INPUT))
519 activate_output_mix(codec, path, dst, idx, enable);
520 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
522 if (have_mute(codec, src, HDA_OUTPUT)) {
523 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
524 snd_hda_codec_write(codec, src, 0,
525 AC_VERB_SET_AMP_GAIN_MUTE, val);
530 /* set the given pin as output */
531 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
536 snd_hda_set_pin_ctl(codec, pin, pin_type);
537 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
538 snd_hda_codec_write(codec, pin, 0,
539 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
542 static void via_auto_init_output(struct hda_codec *codec,
543 struct nid_path *path, int pin_type)
550 pin = path->path[path->depth - 1];
552 init_output_pin(codec, pin, pin_type);
553 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
554 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
557 if (caps & AC_AMPCAP_MUTE) {
559 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
560 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
563 activate_output_path(codec, path, true, true); /* force on */
566 static void via_auto_init_multi_out(struct hda_codec *codec)
568 struct via_spec *spec = codec->spec;
569 struct nid_path *path;
572 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
573 path = &spec->out_path[i];
574 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
575 path = &spec->out_mix_path;
576 via_auto_init_output(codec, path, PIN_OUT);
580 /* deactivate the inactive headphone-paths */
581 static void deactivate_hp_paths(struct hda_codec *codec)
583 struct via_spec *spec = codec->spec;
584 int shared = spec->hp_indep_shared;
586 if (spec->hp_independent_mode) {
587 activate_output_path(codec, &spec->hp_path, false, false);
588 activate_output_path(codec, &spec->hp_mix_path, false, false);
590 activate_output_path(codec, &spec->out_path[shared],
592 } else if (spec->aamix_mode || !spec->hp_path.depth) {
593 activate_output_path(codec, &spec->hp_indep_path, false, false);
594 activate_output_path(codec, &spec->hp_path, false, false);
596 activate_output_path(codec, &spec->hp_indep_path, false, false);
597 activate_output_path(codec, &spec->hp_mix_path, false, false);
601 static void via_auto_init_hp_out(struct hda_codec *codec)
603 struct via_spec *spec = codec->spec;
605 if (!spec->hp_path.depth) {
606 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
609 deactivate_hp_paths(codec);
610 if (spec->hp_independent_mode)
611 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
612 else if (spec->aamix_mode)
613 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
615 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
618 static void via_auto_init_speaker_out(struct hda_codec *codec)
620 struct via_spec *spec = codec->spec;
622 if (!spec->autocfg.speaker_outs)
624 if (!spec->speaker_path.depth) {
625 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
628 if (!spec->aamix_mode) {
629 activate_output_path(codec, &spec->speaker_mix_path,
631 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
633 activate_output_path(codec, &spec->speaker_path, false, false);
634 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
638 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
639 static void via_hp_automute(struct hda_codec *codec);
641 static void via_auto_init_analog_input(struct hda_codec *codec)
643 struct via_spec *spec = codec->spec;
644 const struct auto_pin_cfg *cfg = &spec->autocfg;
645 hda_nid_t conn[HDA_MAX_CONNECTIONS];
650 for (i = 0; i < spec->num_adc_nids; i++) {
651 hda_nid_t nid = spec->adc_nids[i];
652 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP) ||
653 !(query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE))
655 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
656 AC_VERB_SET_AMP_GAIN_MUTE,
661 for (i = 0; i < cfg->num_inputs; i++) {
662 hda_nid_t nid = cfg->inputs[i].pin;
663 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
667 if (cfg->inputs[i].type == AUTO_PIN_MIC)
668 ctl |= snd_hda_get_default_vref(codec, nid);
670 snd_hda_set_pin_ctl(codec, nid, ctl);
674 for (i = 0; i < spec->num_adc_nids; i++) {
675 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
676 /* secondary ADCs must have the unique MUX */
677 if (i > 0 && !spec->mux_nids[i])
679 if (spec->mux_nids[adc_idx]) {
680 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
681 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
682 AC_VERB_SET_CONNECT_SEL,
685 if (spec->dyn_adc_switch)
686 break; /* only one input-src */
690 if (!spec->aa_mix_nid)
692 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
694 for (i = 0; i < num_conns; i++) {
695 unsigned int caps = get_wcaps(codec, conn[i]);
696 if (get_wcaps_type(caps) == AC_WID_PIN)
697 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
698 AC_VERB_SET_AMP_GAIN_MUTE,
703 static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
706 if (snd_hda_codec_read(codec, nid, 0,
707 AC_VERB_GET_POWER_STATE, 0) == parm)
709 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
712 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
713 unsigned int *affected_parm)
716 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
717 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
718 >> AC_DEFCFG_MISC_SHIFT
719 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
720 struct via_spec *spec = codec->spec;
721 unsigned present = 0;
723 no_presence |= spec->no_pin_power_ctl;
725 present = snd_hda_jack_detect(codec, nid);
726 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
727 || ((no_presence || present)
728 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
729 *affected_parm = AC_PWRST_D0; /* if it's connected */
734 update_power_state(codec, nid, parm);
737 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
738 struct snd_ctl_elem_info *uinfo)
740 static const char * const texts[] = {
741 "Disabled", "Enabled"
744 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
746 uinfo->value.enumerated.items = 2;
747 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
748 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
749 strcpy(uinfo->value.enumerated.name,
750 texts[uinfo->value.enumerated.item]);
754 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
755 struct snd_ctl_elem_value *ucontrol)
757 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
758 struct via_spec *spec = codec->spec;
759 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
763 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
764 struct snd_ctl_elem_value *ucontrol)
766 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
767 struct via_spec *spec = codec->spec;
768 unsigned int val = !ucontrol->value.enumerated.item[0];
770 if (val == spec->no_pin_power_ctl)
772 spec->no_pin_power_ctl = val;
773 set_widgets_power_state(codec);
774 analog_low_current_mode(codec);
778 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
779 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
780 .name = "Dynamic Power-Control",
781 .info = via_pin_power_ctl_info,
782 .get = via_pin_power_ctl_get,
783 .put = via_pin_power_ctl_put,
787 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
788 struct snd_ctl_elem_info *uinfo)
790 static const char * const texts[] = { "OFF", "ON" };
792 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
794 uinfo->value.enumerated.items = 2;
795 if (uinfo->value.enumerated.item >= 2)
796 uinfo->value.enumerated.item = 1;
797 strcpy(uinfo->value.enumerated.name,
798 texts[uinfo->value.enumerated.item]);
802 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
803 struct snd_ctl_elem_value *ucontrol)
805 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
806 struct via_spec *spec = codec->spec;
808 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
812 /* adjust spec->multiout setup according to the current flags */
813 static void setup_playback_multi_pcm(struct via_spec *spec)
815 const struct auto_pin_cfg *cfg = &spec->autocfg;
816 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
817 spec->multiout.hp_nid = 0;
818 if (!spec->hp_independent_mode) {
819 if (!spec->hp_indep_shared)
820 spec->multiout.hp_nid = spec->hp_dac_nid;
822 if (spec->hp_indep_shared)
823 spec->multiout.num_dacs = cfg->line_outs - 1;
827 /* update DAC setups according to indep-HP switch;
828 * this function is called only when indep-HP is modified
830 static void switch_indep_hp_dacs(struct hda_codec *codec)
832 struct via_spec *spec = codec->spec;
833 int shared = spec->hp_indep_shared;
834 hda_nid_t shared_dac, hp_dac;
836 if (!spec->opened_streams)
839 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
840 hp_dac = spec->hp_dac_nid;
841 if (spec->hp_independent_mode) {
842 /* switch to indep-HP mode */
843 if (spec->active_streams & STREAM_MULTI_OUT) {
844 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
845 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
847 if (spec->active_streams & STREAM_INDEP_HP)
848 snd_hda_codec_setup_stream(codec, hp_dac,
849 spec->cur_hp_stream_tag, 0,
850 spec->cur_hp_format);
852 /* back to HP or shared-DAC */
853 if (spec->active_streams & STREAM_INDEP_HP)
854 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
855 if (spec->active_streams & STREAM_MULTI_OUT) {
858 if (shared_dac) { /* reset mutli-ch DAC */
861 } else { /* reset HP DAC */
865 snd_hda_codec_setup_stream(codec, dac,
866 spec->cur_dac_stream_tag, ch,
867 spec->cur_dac_format);
870 setup_playback_multi_pcm(spec);
873 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
874 struct snd_ctl_elem_value *ucontrol)
876 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
877 struct via_spec *spec = codec->spec;
880 mutex_lock(&spec->config_mutex);
881 cur = !!ucontrol->value.enumerated.item[0];
882 if (spec->hp_independent_mode == cur) {
883 mutex_unlock(&spec->config_mutex);
886 spec->hp_independent_mode = cur;
887 shared = spec->hp_indep_shared;
888 deactivate_hp_paths(codec);
890 activate_output_path(codec, &spec->hp_indep_path, true, false);
893 activate_output_path(codec, &spec->out_path[shared],
895 if (spec->aamix_mode || !spec->hp_path.depth)
896 activate_output_path(codec, &spec->hp_mix_path,
899 activate_output_path(codec, &spec->hp_path,
903 switch_indep_hp_dacs(codec);
904 mutex_unlock(&spec->config_mutex);
906 /* update jack power state */
907 set_widgets_power_state(codec);
908 via_hp_automute(codec);
912 static const struct snd_kcontrol_new via_hp_mixer = {
913 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
914 .name = "Independent HP",
915 .info = via_independent_hp_info,
916 .get = via_independent_hp_get,
917 .put = via_independent_hp_put,
920 static int via_hp_build(struct hda_codec *codec)
922 struct via_spec *spec = codec->spec;
923 struct snd_kcontrol_new *knew;
926 nid = spec->autocfg.hp_pins[0];
927 knew = via_clone_control(spec, &via_hp_mixer);
931 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
936 static void notify_aa_path_ctls(struct hda_codec *codec)
938 struct via_spec *spec = codec->spec;
941 for (i = 0; i < spec->smart51_nums; i++) {
942 struct snd_kcontrol *ctl;
943 struct snd_ctl_elem_id id;
944 memset(&id, 0, sizeof(id));
945 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
946 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
947 ctl = snd_hda_find_mixer_ctl(codec, id.name);
949 snd_ctl_notify(codec->bus->card,
950 SNDRV_CTL_EVENT_MASK_VALUE,
955 static void mute_aa_path(struct hda_codec *codec, int mute)
957 struct via_spec *spec = codec->spec;
958 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
961 /* check AA path's mute status */
962 for (i = 0; i < spec->smart51_nums; i++) {
963 if (spec->smart51_idxs[i] < 0)
965 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
966 HDA_INPUT, spec->smart51_idxs[i],
971 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
973 struct via_spec *spec = codec->spec;
976 for (i = 0; i < spec->smart51_nums; i++)
977 if (spec->smart51_pins[i] == pin)
982 static int via_smart51_get(struct snd_kcontrol *kcontrol,
983 struct snd_ctl_elem_value *ucontrol)
985 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
986 struct via_spec *spec = codec->spec;
988 *ucontrol->value.integer.value = spec->smart51_enabled;
992 static int via_smart51_put(struct snd_kcontrol *kcontrol,
993 struct snd_ctl_elem_value *ucontrol)
995 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
996 struct via_spec *spec = codec->spec;
997 int out_in = *ucontrol->value.integer.value
998 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1001 for (i = 0; i < spec->smart51_nums; i++) {
1002 hda_nid_t nid = spec->smart51_pins[i];
1005 parm = snd_hda_codec_read(codec, nid, 0,
1006 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1007 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1009 snd_hda_set_pin_ctl(codec, nid, parm);
1010 if (out_in == AC_PINCTL_OUT_EN) {
1011 mute_aa_path(codec, 1);
1012 notify_aa_path_ctls(codec);
1015 spec->smart51_enabled = *ucontrol->value.integer.value;
1016 set_widgets_power_state(codec);
1020 static const struct snd_kcontrol_new via_smart51_mixer = {
1021 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1022 .name = "Smart 5.1",
1024 .info = snd_ctl_boolean_mono_info,
1025 .get = via_smart51_get,
1026 .put = via_smart51_put,
1029 static int via_smart51_build(struct hda_codec *codec)
1031 struct via_spec *spec = codec->spec;
1033 if (!spec->smart51_nums)
1035 if (!via_clone_control(spec, &via_smart51_mixer))
1040 /* check AA path's mute status */
1041 static bool is_aa_path_mute(struct hda_codec *codec)
1043 struct via_spec *spec = codec->spec;
1044 const struct hda_amp_list *p;
1047 for (i = 0; i < spec->num_loopbacks; i++) {
1048 p = &spec->loopback_list[i];
1049 for (ch = 0; ch < 2; ch++) {
1050 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1052 if (!(v & HDA_AMP_MUTE) && v > 0)
1059 /* enter/exit analog low-current mode */
1060 static void __analog_low_current_mode(struct hda_codec *codec, bool force)
1062 struct via_spec *spec = codec->spec;
1064 unsigned int verb, parm;
1066 if (spec->no_pin_power_ctl)
1069 enable = is_aa_path_mute(codec) && !spec->opened_streams;
1070 if (enable == spec->alc_mode && !force)
1072 spec->alc_mode = enable;
1074 /* decide low current mode's verb & parameter */
1075 switch (spec->codec_type) {
1079 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1085 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1089 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1095 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1098 return; /* other codecs are not supported */
1101 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1104 static void analog_low_current_mode(struct hda_codec *codec)
1106 return __analog_low_current_mode(codec, false);
1110 * generic initialization of ADC, input mixers and output mixers
1112 static const struct hda_verb vt1708_init_verbs[] = {
1113 /* power down jack detect function */
1118 static void set_stream_open(struct hda_codec *codec, int bit, bool active)
1120 struct via_spec *spec = codec->spec;
1123 spec->opened_streams |= bit;
1125 spec->opened_streams &= ~bit;
1126 analog_low_current_mode(codec);
1129 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1130 struct hda_codec *codec,
1131 struct snd_pcm_substream *substream)
1133 struct via_spec *spec = codec->spec;
1134 const struct auto_pin_cfg *cfg = &spec->autocfg;
1137 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1138 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1139 set_stream_open(codec, STREAM_MULTI_OUT, true);
1140 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1143 set_stream_open(codec, STREAM_MULTI_OUT, false);
1149 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1150 struct hda_codec *codec,
1151 struct snd_pcm_substream *substream)
1153 set_stream_open(codec, STREAM_MULTI_OUT, false);
1157 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1158 struct hda_codec *codec,
1159 struct snd_pcm_substream *substream)
1161 struct via_spec *spec = codec->spec;
1163 if (snd_BUG_ON(!spec->hp_dac_nid))
1165 set_stream_open(codec, STREAM_INDEP_HP, true);
1169 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1170 struct hda_codec *codec,
1171 struct snd_pcm_substream *substream)
1173 set_stream_open(codec, STREAM_INDEP_HP, false);
1177 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1178 struct hda_codec *codec,
1179 unsigned int stream_tag,
1180 unsigned int format,
1181 struct snd_pcm_substream *substream)
1183 struct via_spec *spec = codec->spec;
1185 mutex_lock(&spec->config_mutex);
1186 setup_playback_multi_pcm(spec);
1187 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1189 /* remember for dynamic DAC switch with indep-HP */
1190 spec->active_streams |= STREAM_MULTI_OUT;
1191 spec->cur_dac_stream_tag = stream_tag;
1192 spec->cur_dac_format = format;
1193 mutex_unlock(&spec->config_mutex);
1194 vt1708_update_hp_work(spec);
1198 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1199 struct hda_codec *codec,
1200 unsigned int stream_tag,
1201 unsigned int format,
1202 struct snd_pcm_substream *substream)
1204 struct via_spec *spec = codec->spec;
1206 mutex_lock(&spec->config_mutex);
1207 if (spec->hp_independent_mode)
1208 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1209 stream_tag, 0, format);
1210 spec->active_streams |= STREAM_INDEP_HP;
1211 spec->cur_hp_stream_tag = stream_tag;
1212 spec->cur_hp_format = format;
1213 mutex_unlock(&spec->config_mutex);
1214 vt1708_update_hp_work(spec);
1218 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1219 struct hda_codec *codec,
1220 struct snd_pcm_substream *substream)
1222 struct via_spec *spec = codec->spec;
1224 mutex_lock(&spec->config_mutex);
1225 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1226 spec->active_streams &= ~STREAM_MULTI_OUT;
1227 mutex_unlock(&spec->config_mutex);
1228 vt1708_update_hp_work(spec);
1232 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1233 struct hda_codec *codec,
1234 struct snd_pcm_substream *substream)
1236 struct via_spec *spec = codec->spec;
1238 mutex_lock(&spec->config_mutex);
1239 if (spec->hp_independent_mode)
1240 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1241 spec->active_streams &= ~STREAM_INDEP_HP;
1242 mutex_unlock(&spec->config_mutex);
1243 vt1708_update_hp_work(spec);
1250 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1251 struct hda_codec *codec,
1252 struct snd_pcm_substream *substream)
1254 struct via_spec *spec = codec->spec;
1255 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1258 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1259 struct hda_codec *codec,
1260 struct snd_pcm_substream *substream)
1262 struct via_spec *spec = codec->spec;
1263 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1266 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1267 struct hda_codec *codec,
1268 unsigned int stream_tag,
1269 unsigned int format,
1270 struct snd_pcm_substream *substream)
1272 struct via_spec *spec = codec->spec;
1273 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1274 stream_tag, format, substream);
1277 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1278 struct hda_codec *codec,
1279 struct snd_pcm_substream *substream)
1281 struct via_spec *spec = codec->spec;
1282 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1289 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1290 struct hda_codec *codec,
1291 unsigned int stream_tag,
1292 unsigned int format,
1293 struct snd_pcm_substream *substream)
1295 struct via_spec *spec = codec->spec;
1297 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1298 stream_tag, 0, format);
1302 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1303 struct hda_codec *codec,
1304 struct snd_pcm_substream *substream)
1306 struct via_spec *spec = codec->spec;
1307 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1311 /* analog capture with dynamic ADC switching */
1312 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1313 struct hda_codec *codec,
1314 unsigned int stream_tag,
1315 unsigned int format,
1316 struct snd_pcm_substream *substream)
1318 struct via_spec *spec = codec->spec;
1319 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1321 mutex_lock(&spec->config_mutex);
1322 spec->cur_adc = spec->adc_nids[adc_idx];
1323 spec->cur_adc_stream_tag = stream_tag;
1324 spec->cur_adc_format = format;
1325 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1326 mutex_unlock(&spec->config_mutex);
1330 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1331 struct hda_codec *codec,
1332 struct snd_pcm_substream *substream)
1334 struct via_spec *spec = codec->spec;
1336 mutex_lock(&spec->config_mutex);
1337 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1339 mutex_unlock(&spec->config_mutex);
1343 /* re-setup the stream if running; called from input-src put */
1344 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1346 struct via_spec *spec = codec->spec;
1347 int adc_idx = spec->inputs[cur].adc_idx;
1348 hda_nid_t adc = spec->adc_nids[adc_idx];
1351 mutex_lock(&spec->config_mutex);
1352 if (spec->cur_adc && spec->cur_adc != adc) {
1353 /* stream is running, let's swap the current ADC */
1354 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1355 spec->cur_adc = adc;
1356 snd_hda_codec_setup_stream(codec, adc,
1357 spec->cur_adc_stream_tag, 0,
1358 spec->cur_adc_format);
1361 mutex_unlock(&spec->config_mutex);
1365 static const struct hda_pcm_stream via_pcm_analog_playback = {
1369 /* NID is set in via_build_pcms */
1371 .open = via_playback_multi_pcm_open,
1372 .close = via_playback_multi_pcm_close,
1373 .prepare = via_playback_multi_pcm_prepare,
1374 .cleanup = via_playback_multi_pcm_cleanup
1378 static const struct hda_pcm_stream via_pcm_hp_playback = {
1382 /* NID is set in via_build_pcms */
1384 .open = via_playback_hp_pcm_open,
1385 .close = via_playback_hp_pcm_close,
1386 .prepare = via_playback_hp_pcm_prepare,
1387 .cleanup = via_playback_hp_pcm_cleanup
1391 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1395 /* NID is set in via_build_pcms */
1396 /* We got noisy outputs on the right channel on VT1708 when
1397 * 24bit samples are used. Until any workaround is found,
1398 * disable the 24bit format, so far.
1400 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1402 .open = via_playback_multi_pcm_open,
1403 .close = via_playback_multi_pcm_close,
1404 .prepare = via_playback_multi_pcm_prepare,
1405 .cleanup = via_playback_multi_pcm_cleanup
1409 static const struct hda_pcm_stream via_pcm_analog_capture = {
1410 .substreams = 1, /* will be changed in via_build_pcms() */
1413 /* NID is set in via_build_pcms */
1415 .prepare = via_capture_pcm_prepare,
1416 .cleanup = via_capture_pcm_cleanup
1420 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1424 /* NID is set in via_build_pcms */
1426 .prepare = via_dyn_adc_capture_pcm_prepare,
1427 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1431 static const struct hda_pcm_stream via_pcm_digital_playback = {
1435 /* NID is set in via_build_pcms */
1437 .open = via_dig_playback_pcm_open,
1438 .close = via_dig_playback_pcm_close,
1439 .prepare = via_dig_playback_pcm_prepare,
1440 .cleanup = via_dig_playback_pcm_cleanup
1444 static const struct hda_pcm_stream via_pcm_digital_capture = {
1451 * slave controls for virtual master
1453 static const char * const via_slave_pfxs[] = {
1454 "Front", "Surround", "Center", "LFE", "Side",
1455 "Headphone", "Speaker",
1459 static int via_build_controls(struct hda_codec *codec)
1461 struct via_spec *spec = codec->spec;
1462 struct snd_kcontrol *kctl;
1465 spec->no_pin_power_ctl = 1;
1466 if (spec->set_widgets_power_state)
1467 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1470 for (i = 0; i < spec->num_mixers; i++) {
1471 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1476 if (spec->multiout.dig_out_nid) {
1477 err = snd_hda_create_spdif_out_ctls(codec,
1478 spec->multiout.dig_out_nid,
1479 spec->multiout.dig_out_nid);
1482 err = snd_hda_create_spdif_share_sw(codec,
1486 spec->multiout.share_spdif = 1;
1488 if (spec->dig_in_nid) {
1489 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1494 /* if we have no master control, let's create it */
1495 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1496 unsigned int vmaster_tlv[4];
1497 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1498 HDA_OUTPUT, vmaster_tlv);
1499 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1500 vmaster_tlv, via_slave_pfxs,
1505 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1506 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1507 NULL, via_slave_pfxs,
1513 /* assign Capture Source enums to NID */
1514 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1515 for (i = 0; kctl && i < kctl->count; i++) {
1516 if (!spec->mux_nids[i])
1518 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1523 via_free_kctls(codec); /* no longer needed */
1525 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1532 static int via_build_pcms(struct hda_codec *codec)
1534 struct via_spec *spec = codec->spec;
1535 struct hda_pcm *info = spec->pcm_rec;
1537 codec->num_pcms = 0;
1538 codec->pcm_info = info;
1540 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1541 snprintf(spec->stream_name_analog,
1542 sizeof(spec->stream_name_analog),
1543 "%s Analog", codec->chip_name);
1544 info->name = spec->stream_name_analog;
1546 if (spec->multiout.num_dacs) {
1547 if (!spec->stream_analog_playback)
1548 spec->stream_analog_playback =
1549 &via_pcm_analog_playback;
1550 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1551 *spec->stream_analog_playback;
1552 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1553 spec->multiout.dac_nids[0];
1554 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1555 spec->multiout.max_channels;
1558 if (!spec->stream_analog_capture) {
1559 if (spec->dyn_adc_switch)
1560 spec->stream_analog_capture =
1561 &via_pcm_dyn_adc_analog_capture;
1563 spec->stream_analog_capture =
1564 &via_pcm_analog_capture;
1566 if (spec->num_adc_nids) {
1567 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1568 *spec->stream_analog_capture;
1569 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1571 if (!spec->dyn_adc_switch)
1572 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1579 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1580 snprintf(spec->stream_name_digital,
1581 sizeof(spec->stream_name_digital),
1582 "%s Digital", codec->chip_name);
1583 info->name = spec->stream_name_digital;
1584 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1585 if (spec->multiout.dig_out_nid) {
1586 if (!spec->stream_digital_playback)
1587 spec->stream_digital_playback =
1588 &via_pcm_digital_playback;
1589 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1590 *spec->stream_digital_playback;
1591 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1592 spec->multiout.dig_out_nid;
1594 if (spec->dig_in_nid) {
1595 if (!spec->stream_digital_capture)
1596 spec->stream_digital_capture =
1597 &via_pcm_digital_capture;
1598 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1599 *spec->stream_digital_capture;
1600 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1607 if (spec->hp_dac_nid) {
1608 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1609 "%s HP", codec->chip_name);
1610 info->name = spec->stream_name_hp;
1611 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1612 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1620 static void via_free(struct hda_codec *codec)
1622 struct via_spec *spec = codec->spec;
1627 via_free_kctls(codec);
1628 vt1708_stop_hp_work(spec);
1629 kfree(spec->bind_cap_vol);
1630 kfree(spec->bind_cap_sw);
1634 /* mute/unmute outputs */
1635 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1636 hda_nid_t *pins, bool mute)
1639 for (i = 0; i < num_pins; i++) {
1640 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1641 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1642 if (parm & AC_PINCTL_IN_EN)
1645 parm &= ~AC_PINCTL_OUT_EN;
1647 parm |= AC_PINCTL_OUT_EN;
1648 snd_hda_set_pin_ctl(codec, pins[i], parm);
1652 /* mute internal speaker if line-out is plugged */
1653 static void via_line_automute(struct hda_codec *codec, int present)
1655 struct via_spec *spec = codec->spec;
1657 if (!spec->autocfg.speaker_outs)
1660 present = snd_hda_jack_detect(codec,
1661 spec->autocfg.line_out_pins[0]);
1662 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1663 spec->autocfg.speaker_pins,
1667 /* mute internal speaker if HP is plugged */
1668 static void via_hp_automute(struct hda_codec *codec)
1672 struct via_spec *spec = codec->spec;
1674 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
1675 (spec->codec_type != VT1708 || spec->vt1708_jack_detect) &&
1676 is_jack_detectable(codec, spec->autocfg.hp_pins[0]))
1677 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1679 if (spec->smart51_enabled)
1680 nums = spec->autocfg.line_outs + spec->smart51_nums;
1682 nums = spec->autocfg.line_outs;
1683 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1685 via_line_automute(codec, present);
1688 static void via_gpio_control(struct hda_codec *codec)
1690 unsigned int gpio_data;
1691 unsigned int vol_counter;
1693 unsigned int master_vol;
1695 struct via_spec *spec = codec->spec;
1697 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1698 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1700 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1701 0xF84, 0) & 0x3F0000) >> 16;
1703 vol = vol_counter & 0x1F;
1704 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1705 AC_VERB_GET_AMP_GAIN_MUTE,
1708 if (gpio_data == 0x02) {
1709 /* unmute line out */
1710 snd_hda_set_pin_ctl(codec, spec->autocfg.line_out_pins[0],
1712 if (vol_counter & 0x20) {
1713 /* decrease volume */
1714 if (vol > master_vol)
1716 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1720 /* increase volume */
1721 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1723 ((master_vol+vol) > 0x2A) ? 0x2A :
1726 } else if (!(gpio_data & 0x02)) {
1728 snd_hda_set_pin_ctl(codec, spec->autocfg.line_out_pins[0], 0);
1732 /* unsolicited event for jack sensing */
1733 static void via_unsol_event(struct hda_codec *codec,
1737 res = snd_hda_jack_get_action(codec, res);
1739 if (res & VIA_JACK_EVENT)
1740 set_widgets_power_state(codec);
1742 res &= ~VIA_JACK_EVENT;
1744 if (res == VIA_HP_EVENT || res == VIA_LINE_EVENT)
1745 via_hp_automute(codec);
1746 else if (res == VIA_GPIO_EVENT)
1747 via_gpio_control(codec);
1748 snd_hda_jack_report_sync(codec);
1752 static int via_suspend(struct hda_codec *codec)
1754 struct via_spec *spec = codec->spec;
1755 vt1708_stop_hp_work(spec);
1757 if (spec->codec_type == VT1802) {
1758 /* Fix pop noise on headphones */
1760 for (i = 0; i < spec->autocfg.hp_outs; i++)
1761 snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0);
1769 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1771 struct via_spec *spec = codec->spec;
1772 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1779 static int via_init(struct hda_codec *codec);
1781 static const struct hda_codec_ops via_patch_ops = {
1782 .build_controls = via_build_controls,
1783 .build_pcms = via_build_pcms,
1786 .unsol_event = via_unsol_event,
1788 .suspend = via_suspend,
1789 .check_power_status = via_check_power_status,
1793 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1795 struct via_spec *spec = codec->spec;
1798 for (i = 0; i < spec->multiout.num_dacs; i++) {
1799 if (spec->multiout.dac_nids[i] == dac)
1802 if (spec->hp_dac_nid == dac)
1807 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1808 hda_nid_t target_dac, int with_aa_mix,
1809 struct nid_path *path, int depth)
1811 struct via_spec *spec = codec->spec;
1815 if (nid == spec->aa_mix_nid) {
1818 with_aa_mix = 2; /* mark aa-mix is included */
1821 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1822 for (i = 0; i < nums; i++) {
1823 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1825 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1826 /* aa-mix is requested but not included? */
1827 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1831 if (depth >= MAX_NID_PATH_DEPTH)
1833 for (i = 0; i < nums; i++) {
1835 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1836 if (type == AC_WID_AUD_OUT)
1838 if (__parse_output_path(codec, conn[i], target_dac,
1839 with_aa_mix, path, depth + 1))
1845 path->path[path->depth] = conn[i];
1846 path->idx[path->depth] = i;
1847 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1848 path->multi[path->depth] = 1;
1853 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1854 hda_nid_t target_dac, int with_aa_mix,
1855 struct nid_path *path)
1857 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
1858 path->path[path->depth] = nid;
1860 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1861 path->depth, path->path[0], path->path[1],
1862 path->path[2], path->path[3], path->path[4]);
1868 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1870 struct via_spec *spec = codec->spec;
1871 const struct auto_pin_cfg *cfg = &spec->autocfg;
1875 spec->multiout.dac_nids = spec->private_dac_nids;
1877 for (i = 0; i < cfg->line_outs; i++) {
1879 nid = cfg->line_out_pins[i];
1882 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1883 dac = spec->out_path[i].path[0];
1884 if (!i && parse_output_path(codec, nid, dac, 1,
1885 &spec->out_mix_path))
1886 dac = spec->out_mix_path.path[0];
1888 spec->private_dac_nids[i] = dac;
1892 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1893 spec->out_path[0] = spec->out_mix_path;
1894 spec->out_mix_path.depth = 0;
1896 spec->multiout.num_dacs = dac_num;
1900 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1901 int chs, bool check_dac, struct nid_path *path)
1903 struct via_spec *spec = codec->spec;
1905 hda_nid_t dac, pin, sel, nid;
1908 dac = check_dac ? path->path[0] : 0;
1909 pin = path->path[path->depth - 1];
1910 sel = path->depth > 1 ? path->path[1] : 0;
1912 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1914 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1916 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1921 sprintf(name, "%s Playback Volume", pfx);
1922 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1923 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1926 path->vol_ctl = nid;
1929 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1931 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1933 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1938 sprintf(name, "%s Playback Switch", pfx);
1939 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1940 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1943 path->mute_ctl = nid;
1948 static void mangle_smart51(struct hda_codec *codec)
1950 struct via_spec *spec = codec->spec;
1951 struct auto_pin_cfg *cfg = &spec->autocfg;
1952 struct auto_pin_cfg_item *ins = cfg->inputs;
1953 int i, j, nums, attr;
1954 int pins[AUTO_CFG_MAX_INS];
1956 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1958 for (i = 0; i < cfg->num_inputs; i++) {
1960 if (ins[i].type > AUTO_PIN_LINE_IN)
1962 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1963 if (snd_hda_get_input_pin_attr(def) != attr)
1965 for (j = 0; j < nums; j++)
1966 if (ins[pins[j]].type < ins[i].type) {
1967 memmove(pins + j + 1, pins + j,
1968 (nums - j) * sizeof(int));
1974 if (cfg->line_outs + nums < 3)
1976 for (i = 0; i < nums; i++) {
1977 hda_nid_t pin = ins[pins[i]].pin;
1978 spec->smart51_pins[spec->smart51_nums++] = pin;
1979 cfg->line_out_pins[cfg->line_outs++] = pin;
1980 if (cfg->line_outs == 3)
1987 static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1989 dst->vol_ctl = src->vol_ctl;
1990 dst->mute_ctl = src->mute_ctl;
1993 /* add playback controls from the parsed DAC table */
1994 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1996 struct via_spec *spec = codec->spec;
1997 struct auto_pin_cfg *cfg = &spec->autocfg;
1998 struct nid_path *path;
1999 static const char * const chname[4] = {
2000 "Front", "Surround", "C/LFE", "Side"
2006 old_line_outs = cfg->line_outs;
2007 if (cfg->line_outs == 1)
2008 mangle_smart51(codec);
2010 err = via_auto_fill_dac_nids(codec);
2014 if (spec->multiout.num_dacs < 3) {
2015 spec->smart51_nums = 0;
2016 cfg->line_outs = old_line_outs;
2018 for (i = 0; i < cfg->line_outs; i++) {
2020 pin = cfg->line_out_pins[i];
2021 dac = spec->multiout.dac_nids[i];
2024 path = spec->out_path + i;
2025 if (i == HDA_CLFE) {
2026 err = create_ch_ctls(codec, "Center", 1, true, path);
2029 err = create_ch_ctls(codec, "LFE", 2, true, path);
2033 const char *pfx = chname[i];
2034 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
2035 cfg->line_outs == 1)
2037 err = create_ch_ctls(codec, pfx, 3, true, path);
2041 if (path != spec->out_path + i)
2042 copy_path_mixer_ctls(&spec->out_path[i], path);
2043 if (path == spec->out_path && spec->out_mix_path.depth)
2044 copy_path_mixer_ctls(&spec->out_mix_path, path);
2047 idx = get_connection_index(codec, spec->aa_mix_nid,
2048 spec->multiout.dac_nids[0]);
2050 /* add control to mixer */
2052 name = spec->out_mix_path.depth ?
2053 "PCM Loopback Playback Volume" : "PCM Playback Volume";
2054 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2055 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2059 name = spec->out_mix_path.depth ?
2060 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2061 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2062 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2068 cfg->line_outs = old_line_outs;
2073 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
2075 struct via_spec *spec = codec->spec;
2076 struct nid_path *path;
2083 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2084 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2085 if (i < spec->multiout.num_dacs &&
2086 parse_output_path(codec, pin,
2087 spec->multiout.dac_nids[i], 0,
2088 &spec->hp_indep_path)) {
2089 spec->hp_indep_shared = i;
2094 if (spec->hp_indep_path.depth) {
2095 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2096 if (!spec->hp_indep_shared)
2097 spec->hp_path = spec->hp_indep_path;
2099 /* optionally check front-path w/o AA-mix */
2100 if (!spec->hp_path.depth)
2101 parse_output_path(codec, pin,
2102 spec->multiout.dac_nids[HDA_FRONT], 0,
2105 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2106 1, &spec->hp_mix_path) && !spec->hp_path.depth)
2109 if (spec->hp_path.depth) {
2110 path = &spec->hp_path;
2113 path = &spec->hp_mix_path;
2116 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
2120 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2122 copy_path_mixer_ctls(&spec->hp_path, path);
2123 if (spec->hp_indep_path.depth)
2124 copy_path_mixer_ctls(&spec->hp_indep_path, path);
2128 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2130 struct via_spec *spec = codec->spec;
2131 struct nid_path *path;
2133 hda_nid_t pin, dac = 0;
2136 pin = spec->autocfg.speaker_pins[0];
2137 if (!spec->autocfg.speaker_outs || !pin)
2140 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
2141 dac = spec->speaker_path.path[0];
2143 parse_output_path(codec, pin,
2144 spec->multiout.dac_nids[HDA_FRONT], 0,
2145 &spec->speaker_path);
2146 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2147 1, &spec->speaker_mix_path) && !dac)
2150 /* no AA-path for front? */
2151 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2154 spec->speaker_dac_nid = dac;
2155 spec->multiout.extra_out_nid[0] = dac;
2157 path = &spec->speaker_path;
2160 path = &spec->speaker_mix_path;
2163 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2167 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2169 copy_path_mixer_ctls(&spec->speaker_path, path);
2173 #define via_aamix_ctl_info via_pin_power_ctl_info
2175 static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2176 struct snd_ctl_elem_value *ucontrol)
2178 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2179 struct via_spec *spec = codec->spec;
2180 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2184 static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2185 struct nid_path *nomix, struct nid_path *mix)
2188 activate_output_path(codec, nomix, false, false);
2189 activate_output_path(codec, mix, true, false);
2191 activate_output_path(codec, mix, false, false);
2192 activate_output_path(codec, nomix, true, false);
2196 static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2197 struct snd_ctl_elem_value *ucontrol)
2199 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2200 struct via_spec *spec = codec->spec;
2201 unsigned int val = ucontrol->value.enumerated.item[0];
2203 if (val == spec->aamix_mode)
2205 spec->aamix_mode = val;
2206 /* update front path */
2207 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2208 /* update HP path */
2209 if (!spec->hp_independent_mode) {
2210 update_aamix_paths(codec, val, &spec->hp_path,
2211 &spec->hp_mix_path);
2213 /* update speaker path */
2214 update_aamix_paths(codec, val, &spec->speaker_path,
2215 &spec->speaker_mix_path);
2219 static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2220 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2221 .name = "Loopback Mixing",
2222 .info = via_aamix_ctl_info,
2223 .get = via_aamix_ctl_get,
2224 .put = via_aamix_ctl_put,
2227 static int via_auto_create_loopback_switch(struct hda_codec *codec)
2229 struct via_spec *spec = codec->spec;
2231 if (!spec->aa_mix_nid)
2232 return 0; /* no loopback switching available */
2233 if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
2234 spec->speaker_path.depth))
2235 return 0; /* no loopback switching available */
2236 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2242 static int via_fill_adcs(struct hda_codec *codec)
2244 struct via_spec *spec = codec->spec;
2245 hda_nid_t nid = codec->start_nid;
2248 for (i = 0; i < codec->num_nodes; i++, nid++) {
2249 unsigned int wcaps = get_wcaps(codec, nid);
2250 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2252 if (wcaps & AC_WCAP_DIGITAL)
2254 if (!(wcaps & AC_WCAP_CONN_LIST))
2256 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2258 spec->adc_nids[spec->num_adc_nids++] = nid;
2263 /* input-src control */
2264 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2265 struct snd_ctl_elem_info *uinfo)
2267 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2268 struct via_spec *spec = codec->spec;
2270 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2272 uinfo->value.enumerated.items = spec->num_inputs;
2273 if (uinfo->value.enumerated.item >= spec->num_inputs)
2274 uinfo->value.enumerated.item = spec->num_inputs - 1;
2275 strcpy(uinfo->value.enumerated.name,
2276 spec->inputs[uinfo->value.enumerated.item].label);
2280 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2281 struct snd_ctl_elem_value *ucontrol)
2283 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2284 struct via_spec *spec = codec->spec;
2285 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2287 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2291 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2292 struct snd_ctl_elem_value *ucontrol)
2294 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2295 struct via_spec *spec = codec->spec;
2296 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2300 cur = ucontrol->value.enumerated.item[0];
2301 if (cur < 0 || cur >= spec->num_inputs)
2303 if (spec->cur_mux[idx] == cur)
2305 spec->cur_mux[idx] = cur;
2306 if (spec->dyn_adc_switch) {
2307 int adc_idx = spec->inputs[cur].adc_idx;
2308 mux = spec->mux_nids[adc_idx];
2309 via_dyn_adc_pcm_resetup(codec, cur);
2311 mux = spec->mux_nids[idx];
2312 if (snd_BUG_ON(!mux))
2317 /* switch to D0 beofre change index */
2318 update_power_state(codec, mux, AC_PWRST_D0);
2319 snd_hda_codec_write(codec, mux, 0,
2320 AC_VERB_SET_CONNECT_SEL,
2321 spec->inputs[cur].mux_idx);
2324 /* update jack power state */
2325 set_widgets_power_state(codec);
2329 static const struct snd_kcontrol_new via_input_src_ctl = {
2330 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2331 /* The multiple "Capture Source" controls confuse alsamixer
2332 * So call somewhat different..
2334 /* .name = "Capture Source", */
2335 .name = "Input Source",
2336 .info = via_mux_enum_info,
2337 .get = via_mux_enum_get,
2338 .put = via_mux_enum_put,
2341 static int create_input_src_ctls(struct hda_codec *codec, int count)
2343 struct via_spec *spec = codec->spec;
2344 struct snd_kcontrol_new *knew;
2346 if (spec->num_inputs <= 1 || !count)
2347 return 0; /* no need for single src */
2349 knew = via_clone_control(spec, &via_input_src_ctl);
2352 knew->count = count;
2356 /* add the powersave loopback-list entry */
2357 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2359 struct hda_amp_list *list;
2361 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2363 list = spec->loopback_list + spec->num_loopbacks;
2365 list->dir = HDA_INPUT;
2367 spec->num_loopbacks++;
2368 spec->loopback.amplist = spec->loopback_list;
2371 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2374 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2377 /* add the input-route to the given pin */
2378 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2380 struct via_spec *spec = codec->spec;
2383 spec->inputs[spec->num_inputs].adc_idx = -1;
2384 spec->inputs[spec->num_inputs].pin = pin;
2385 for (c = 0; c < spec->num_adc_nids; c++) {
2386 if (spec->mux_nids[c]) {
2387 idx = get_connection_index(codec, spec->mux_nids[c],
2391 spec->inputs[spec->num_inputs].mux_idx = idx;
2393 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2396 spec->inputs[spec->num_inputs].adc_idx = c;
2397 /* Can primary ADC satisfy all inputs? */
2398 if (!spec->dyn_adc_switch &&
2399 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2400 snd_printd(KERN_INFO
2401 "via: dynamic ADC switching enabled\n");
2402 spec->dyn_adc_switch = 1;
2409 static int get_mux_nids(struct hda_codec *codec);
2411 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2412 static int parse_analog_inputs(struct hda_codec *codec)
2414 struct via_spec *spec = codec->spec;
2415 const struct auto_pin_cfg *cfg = &spec->autocfg;
2418 err = via_fill_adcs(codec);
2421 err = get_mux_nids(codec);
2425 /* fill all input-routes */
2426 for (i = 0; i < cfg->num_inputs; i++) {
2427 if (add_input_route(codec, cfg->inputs[i].pin))
2428 spec->inputs[spec->num_inputs++].label =
2429 hda_get_autocfg_input_label(codec, cfg, i);
2432 /* check for internal loopback recording */
2433 if (spec->aa_mix_nid &&
2434 add_input_route(codec, spec->aa_mix_nid))
2435 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2440 /* create analog-loopback volume/switch controls */
2441 static int create_loopback_ctls(struct hda_codec *codec)
2443 struct via_spec *spec = codec->spec;
2444 const struct auto_pin_cfg *cfg = &spec->autocfg;
2445 const char *prev_label = NULL;
2449 if (!spec->aa_mix_nid)
2452 for (i = 0; i < cfg->num_inputs; i++) {
2453 hda_nid_t pin = cfg->inputs[i].pin;
2454 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2456 if (prev_label && !strcmp(label, prev_label))
2461 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2463 err = via_new_analog_input(spec, label, type_idx,
2464 idx, spec->aa_mix_nid);
2467 add_loopback_list(spec, spec->aa_mix_nid, idx);
2470 /* remember the label for smart51 control */
2471 for (j = 0; j < spec->smart51_nums; j++) {
2472 if (spec->smart51_pins[j] == pin) {
2473 spec->smart51_idxs[j] = idx;
2474 spec->smart51_labels[j] = label;
2482 /* create mic-boost controls (if present) */
2483 static int create_mic_boost_ctls(struct hda_codec *codec)
2485 struct via_spec *spec = codec->spec;
2486 const struct auto_pin_cfg *cfg = &spec->autocfg;
2487 const char *prev_label = NULL;
2491 for (i = 0; i < cfg->num_inputs; i++) {
2492 hda_nid_t pin = cfg->inputs[i].pin;
2497 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2499 caps = query_amp_caps(codec, pin, HDA_INPUT);
2500 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2502 label = hda_get_autocfg_input_label(codec, cfg, i);
2503 if (prev_label && !strcmp(label, prev_label))
2508 snprintf(name, sizeof(name), "%s Boost Volume", label);
2509 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
2510 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2517 /* create capture and input-src controls for multiple streams */
2518 static int create_multi_adc_ctls(struct hda_codec *codec)
2520 struct via_spec *spec = codec->spec;
2523 /* create capture mixer elements */
2524 for (i = 0; i < spec->num_adc_nids; i++) {
2525 hda_nid_t adc = spec->adc_nids[i];
2526 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2527 "Capture Volume", i,
2528 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2532 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2533 "Capture Switch", i,
2534 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2540 /* input-source control */
2541 for (i = 0; i < spec->num_adc_nids; i++)
2542 if (!spec->mux_nids[i])
2544 err = create_input_src_ctls(codec, i);
2550 /* bind capture volume/switch */
2551 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2552 HDA_BIND_VOL("Capture Volume", 0);
2553 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2554 HDA_BIND_SW("Capture Switch", 0);
2556 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2557 struct hda_ctl_ops *ops)
2559 struct hda_bind_ctls *ctl;
2562 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2566 for (i = 0; i < spec->num_adc_nids; i++)
2568 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2573 /* create capture and input-src controls for dynamic ADC-switch case */
2574 static int create_dyn_adc_ctls(struct hda_codec *codec)
2576 struct via_spec *spec = codec->spec;
2577 struct snd_kcontrol_new *knew;
2580 /* set up the bind capture ctls */
2581 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2584 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2588 /* create capture mixer elements */
2589 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2592 knew->private_value = (long)spec->bind_cap_vol;
2594 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2597 knew->private_value = (long)spec->bind_cap_sw;
2599 /* input-source control */
2600 err = create_input_src_ctls(codec, 1);
2606 /* parse and create capture-related stuff */
2607 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2609 struct via_spec *spec = codec->spec;
2612 err = parse_analog_inputs(codec);
2615 if (spec->dyn_adc_switch)
2616 err = create_dyn_adc_ctls(codec);
2618 err = create_multi_adc_ctls(codec);
2621 err = create_loopback_ctls(codec);
2624 err = create_mic_boost_ctls(codec);
2630 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2632 unsigned int def_conf;
2633 unsigned char seqassoc;
2635 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2636 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2637 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2638 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2639 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2640 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2641 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2647 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2648 struct snd_ctl_elem_value *ucontrol)
2650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2651 struct via_spec *spec = codec->spec;
2653 if (spec->codec_type != VT1708)
2655 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2659 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2660 struct snd_ctl_elem_value *ucontrol)
2662 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2663 struct via_spec *spec = codec->spec;
2666 if (spec->codec_type != VT1708)
2668 val = !!ucontrol->value.integer.value[0];
2669 if (spec->vt1708_jack_detect == val)
2671 spec->vt1708_jack_detect = val;
2672 if (spec->vt1708_jack_detect &&
2673 snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
2674 mute_aa_path(codec, 1);
2675 notify_aa_path_ctls(codec);
2677 via_hp_automute(codec);
2678 vt1708_update_hp_work(spec);
2682 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2683 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2684 .name = "Jack Detect",
2686 .info = snd_ctl_boolean_mono_info,
2687 .get = vt1708_jack_detect_get,
2688 .put = vt1708_jack_detect_put,
2691 static void fill_dig_outs(struct hda_codec *codec);
2692 static void fill_dig_in(struct hda_codec *codec);
2694 static int via_parse_auto_config(struct hda_codec *codec)
2696 struct via_spec *spec = codec->spec;
2699 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2702 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2705 err = via_auto_create_multi_out_ctls(codec);
2708 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2711 err = via_auto_create_speaker_ctls(codec);
2714 err = via_auto_create_loopback_switch(codec);
2717 err = via_auto_create_analog_input_ctls(codec);
2721 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2723 fill_dig_outs(codec);
2726 if (spec->kctls.list)
2727 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2730 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
2731 err = via_hp_build(codec);
2736 err = via_smart51_build(codec);
2740 /* assign slave outs */
2741 if (spec->slave_dig_outs[0])
2742 codec->slave_dig_outs = spec->slave_dig_outs;
2747 static void via_auto_init_dig_outs(struct hda_codec *codec)
2749 struct via_spec *spec = codec->spec;
2750 if (spec->multiout.dig_out_nid)
2751 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2752 if (spec->slave_dig_outs[0])
2753 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2756 static void via_auto_init_dig_in(struct hda_codec *codec)
2758 struct via_spec *spec = codec->spec;
2759 if (!spec->dig_in_nid)
2761 snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
2764 /* initialize the unsolicited events */
2765 static void via_auto_init_unsol_event(struct hda_codec *codec)
2767 struct via_spec *spec = codec->spec;
2768 struct auto_pin_cfg *cfg = &spec->autocfg;
2772 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2773 snd_hda_jack_detect_enable(codec, cfg->hp_pins[0],
2774 VIA_HP_EVENT | VIA_JACK_EVENT);
2776 if (cfg->speaker_pins[0])
2777 ev = VIA_LINE_EVENT;
2780 for (i = 0; i < cfg->line_outs; i++) {
2781 if (cfg->line_out_pins[i] &&
2782 is_jack_detectable(codec, cfg->line_out_pins[i]))
2783 snd_hda_jack_detect_enable(codec, cfg->line_out_pins[i],
2784 ev | VIA_JACK_EVENT);
2787 for (i = 0; i < cfg->num_inputs; i++) {
2788 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2789 snd_hda_jack_detect_enable(codec, cfg->inputs[i].pin,
2794 static int via_init(struct hda_codec *codec)
2796 struct via_spec *spec = codec->spec;
2799 for (i = 0; i < spec->num_iverbs; i++)
2800 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2802 /* init power states */
2803 set_widgets_power_state(codec);
2804 __analog_low_current_mode(codec, true);
2806 via_auto_init_multi_out(codec);
2807 via_auto_init_hp_out(codec);
2808 via_auto_init_speaker_out(codec);
2809 via_auto_init_analog_input(codec);
2810 via_auto_init_dig_outs(codec);
2811 via_auto_init_dig_in(codec);
2813 via_auto_init_unsol_event(codec);
2815 via_hp_automute(codec);
2816 vt1708_update_hp_work(spec);
2821 static void vt1708_update_hp_jack_state(struct work_struct *work)
2823 struct via_spec *spec = container_of(work, struct via_spec,
2824 vt1708_hp_work.work);
2825 if (spec->codec_type != VT1708)
2827 snd_hda_jack_set_dirty_all(spec->codec);
2828 /* if jack state toggled */
2829 if (spec->vt1708_hp_present
2830 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2831 spec->vt1708_hp_present ^= 1;
2832 via_hp_automute(spec->codec);
2834 if (spec->vt1708_jack_detect)
2835 schedule_delayed_work(&spec->vt1708_hp_work,
2836 msecs_to_jiffies(100));
2839 static int get_mux_nids(struct hda_codec *codec)
2841 struct via_spec *spec = codec->spec;
2842 hda_nid_t nid, conn[8];
2846 for (i = 0; i < spec->num_adc_nids; i++) {
2847 nid = spec->adc_nids[i];
2849 type = get_wcaps_type(get_wcaps(codec, nid));
2850 if (type == AC_WID_PIN)
2852 n = snd_hda_get_connections(codec, nid, conn,
2857 spec->mux_nids[i] = nid;
2866 static int patch_vt1708(struct hda_codec *codec)
2868 struct via_spec *spec;
2871 /* create a codec specific record */
2872 spec = via_new_spec(codec);
2876 spec->aa_mix_nid = 0x17;
2878 /* Add HP and CD pin config connect bit re-config action */
2879 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2880 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2882 /* automatic parse from the BIOS config */
2883 err = via_parse_auto_config(codec);
2889 /* add jack detect on/off control */
2890 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2893 /* disable 32bit format on VT1708 */
2894 if (codec->vendor_id == 0x11061708)
2895 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2897 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2899 codec->patch_ops = via_patch_ops;
2901 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2905 static int patch_vt1709(struct hda_codec *codec)
2907 struct via_spec *spec;
2910 /* create a codec specific record */
2911 spec = via_new_spec(codec);
2915 spec->aa_mix_nid = 0x18;
2917 err = via_parse_auto_config(codec);
2923 codec->patch_ops = via_patch_ops;
2928 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2930 struct via_spec *spec = codec->spec;
2934 if ((spec->codec_type != VT1708B_4CH) &&
2935 (codec->vendor_id != 0x11064397))
2938 /* SW0 (17h) = stereo mixer */
2940 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2941 == ((spec->codec_type == VT1708S) ? 5 : 0));
2943 /* PW 1/2/5 (1ah/1bh/1eh) */
2945 set_pin_power_state(codec, 0x1a, &parm);
2946 set_pin_power_state(codec, 0x1b, &parm);
2947 set_pin_power_state(codec, 0x1e, &parm);
2950 /* SW0 (17h), AIW 0/1 (13h/14h) */
2951 update_power_state(codec, 0x17, parm);
2952 update_power_state(codec, 0x13, parm);
2953 update_power_state(codec, 0x14, parm);
2956 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2958 set_pin_power_state(codec, 0x19, &parm);
2959 if (spec->smart51_enabled)
2960 set_pin_power_state(codec, 0x1b, &parm);
2961 update_power_state(codec, 0x18, parm);
2962 update_power_state(codec, 0x11, parm);
2964 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2967 set_pin_power_state(codec, 0x22, &parm);
2968 if (spec->smart51_enabled)
2969 set_pin_power_state(codec, 0x1a, &parm);
2970 update_power_state(codec, 0x26, parm);
2971 update_power_state(codec, 0x24, parm);
2972 } else if (codec->vendor_id == 0x11064397) {
2973 /* PW7(23h), SW2(27h), AOW2(25h) */
2975 set_pin_power_state(codec, 0x23, &parm);
2976 if (spec->smart51_enabled)
2977 set_pin_power_state(codec, 0x1a, &parm);
2978 update_power_state(codec, 0x27, parm);
2979 update_power_state(codec, 0x25, parm);
2982 /* PW 3/4/7 (1ch/1dh/23h) */
2984 /* force to D0 for internal Speaker */
2985 set_pin_power_state(codec, 0x1c, &parm);
2986 set_pin_power_state(codec, 0x1d, &parm);
2988 set_pin_power_state(codec, 0x23, &parm);
2990 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2991 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
2992 update_power_state(codec, 0x10, parm);
2994 update_power_state(codec, 0x25, parm);
2995 update_power_state(codec, 0x27, parm);
2996 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2997 update_power_state(codec, 0x25, parm);
3000 static int patch_vt1708S(struct hda_codec *codec);
3001 static int patch_vt1708B(struct hda_codec *codec)
3003 struct via_spec *spec;
3006 if (get_codec_type(codec) == VT1708BCE)
3007 return patch_vt1708S(codec);
3009 /* create a codec specific record */
3010 spec = via_new_spec(codec);
3014 spec->aa_mix_nid = 0x16;
3016 /* automatic parse from the BIOS config */
3017 err = via_parse_auto_config(codec);
3023 codec->patch_ops = via_patch_ops;
3025 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3030 /* Patch for VT1708S */
3031 static const struct hda_verb vt1708S_init_verbs[] = {
3032 /* Enable Mic Boost Volume backdoor */
3034 /* don't bybass mixer */
3039 /* fill out digital output widgets; one for master and one for slave outputs */
3040 static void fill_dig_outs(struct hda_codec *codec)
3042 struct via_spec *spec = codec->spec;
3045 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3049 nid = spec->autocfg.dig_out_pins[i];
3052 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3055 if (!spec->multiout.dig_out_nid)
3056 spec->multiout.dig_out_nid = nid;
3058 spec->slave_dig_outs[0] = nid;
3059 break; /* at most two dig outs */
3064 static void fill_dig_in(struct hda_codec *codec)
3066 struct via_spec *spec = codec->spec;
3070 if (!spec->autocfg.dig_in_pin)
3073 dig_nid = codec->start_nid;
3074 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3075 unsigned int wcaps = get_wcaps(codec, dig_nid);
3076 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3078 if (!(wcaps & AC_WCAP_DIGITAL))
3080 if (!(wcaps & AC_WCAP_CONN_LIST))
3082 err = get_connection_index(codec, dig_nid,
3083 spec->autocfg.dig_in_pin);
3085 spec->dig_in_nid = dig_nid;
3091 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3092 int offset, int num_steps, int step_size)
3094 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3095 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3096 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3097 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3098 (0 << AC_AMPCAP_MUTE_SHIFT));
3101 static int patch_vt1708S(struct hda_codec *codec)
3103 struct via_spec *spec;
3106 /* create a codec specific record */
3107 spec = via_new_spec(codec);
3111 spec->aa_mix_nid = 0x16;
3112 override_mic_boost(codec, 0x1a, 0, 3, 40);
3113 override_mic_boost(codec, 0x1e, 0, 3, 40);
3115 /* automatic parse from the BIOS config */
3116 err = via_parse_auto_config(codec);
3122 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
3124 codec->patch_ops = via_patch_ops;
3126 /* correct names for VT1708BCE */
3127 if (get_codec_type(codec) == VT1708BCE) {
3128 kfree(codec->chip_name);
3129 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3130 snprintf(codec->bus->card->mixername,
3131 sizeof(codec->bus->card->mixername),
3132 "%s %s", codec->vendor_name, codec->chip_name);
3134 /* correct names for VT1705 */
3135 if (codec->vendor_id == 0x11064397) {
3136 kfree(codec->chip_name);
3137 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3138 snprintf(codec->bus->card->mixername,
3139 sizeof(codec->bus->card->mixername),
3140 "%s %s", codec->vendor_name, codec->chip_name);
3142 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3146 /* Patch for VT1702 */
3148 static const struct hda_verb vt1702_init_verbs[] = {
3156 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3158 int imux_is_smixer =
3159 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3162 /* PW 1/2/5 (14h/15h/18h) */
3164 set_pin_power_state(codec, 0x14, &parm);
3165 set_pin_power_state(codec, 0x15, &parm);
3166 set_pin_power_state(codec, 0x18, &parm);
3168 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3169 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3170 update_power_state(codec, 0x13, parm);
3171 update_power_state(codec, 0x12, parm);
3172 update_power_state(codec, 0x1f, parm);
3173 update_power_state(codec, 0x20, parm);
3176 /* PW 3/4 (16h/17h) */
3178 set_pin_power_state(codec, 0x17, &parm);
3179 set_pin_power_state(codec, 0x16, &parm);
3180 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3181 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
3182 update_power_state(codec, 0x10, parm);
3183 update_power_state(codec, 0x1d, parm);
3186 static int patch_vt1702(struct hda_codec *codec)
3188 struct via_spec *spec;
3191 /* create a codec specific record */
3192 spec = via_new_spec(codec);
3196 spec->aa_mix_nid = 0x1a;
3198 /* limit AA path volume to 0 dB */
3199 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3200 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3201 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3202 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3203 (1 << AC_AMPCAP_MUTE_SHIFT));
3205 /* automatic parse from the BIOS config */
3206 err = via_parse_auto_config(codec);
3212 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
3214 codec->patch_ops = via_patch_ops;
3216 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
3220 /* Patch for VT1718S */
3222 static const struct hda_verb vt1718S_init_verbs[] = {
3223 /* Enable MW0 adjust Gain 5 */
3225 /* Enable Boost Volume backdoor */
3231 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3233 struct via_spec *spec = codec->spec;
3235 unsigned int parm, parm2;
3236 /* MUX6 (1eh) = stereo mixer */
3238 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3240 /* PW 5/6/7 (29h/2ah/2bh) */
3242 set_pin_power_state(codec, 0x29, &parm);
3243 set_pin_power_state(codec, 0x2a, &parm);
3244 set_pin_power_state(codec, 0x2b, &parm);
3247 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3248 update_power_state(codec, 0x1e, parm);
3249 update_power_state(codec, 0x1f, parm);
3250 update_power_state(codec, 0x10, parm);
3251 update_power_state(codec, 0x11, parm);
3254 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3256 set_pin_power_state(codec, 0x27, &parm);
3257 update_power_state(codec, 0x1a, parm);
3258 parm2 = parm; /* for pin 0x0b */
3260 /* PW2 (26h), AOW2 (ah) */
3262 set_pin_power_state(codec, 0x26, &parm);
3263 if (spec->smart51_enabled)
3264 set_pin_power_state(codec, 0x2b, &parm);
3265 update_power_state(codec, 0xa, parm);
3267 /* PW0 (24h), AOW0 (8h) */
3269 set_pin_power_state(codec, 0x24, &parm);
3270 if (!spec->hp_independent_mode) /* check for redirected HP */
3271 set_pin_power_state(codec, 0x28, &parm);
3272 update_power_state(codec, 0x8, parm);
3273 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
3275 update_power_state(codec, 0xb, parm);
3276 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3277 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
3279 /* PW1 (25h), AOW1 (9h) */
3281 set_pin_power_state(codec, 0x25, &parm);
3282 if (spec->smart51_enabled)
3283 set_pin_power_state(codec, 0x2a, &parm);
3284 update_power_state(codec, 0x9, parm);
3286 if (spec->hp_independent_mode) {
3287 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3289 set_pin_power_state(codec, 0x28, &parm);
3290 update_power_state(codec, 0x1b, parm);
3291 update_power_state(codec, 0x34, parm);
3292 update_power_state(codec, 0xc, parm);
3296 /* Add a connection to the primary DAC from AA-mixer for some codecs
3297 * This isn't listed from the raw info, but the chip has a secret connection.
3299 static int add_secret_dac_path(struct hda_codec *codec)
3301 struct via_spec *spec = codec->spec;
3306 if (!spec->aa_mix_nid)
3308 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3309 ARRAY_SIZE(conn) - 1);
3310 for (i = 0; i < nums; i++) {
3311 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3315 /* find the primary DAC and add to the connection list */
3316 nid = codec->start_nid;
3317 for (i = 0; i < codec->num_nodes; i++, nid++) {
3318 unsigned int caps = get_wcaps(codec, nid);
3319 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3320 !(caps & AC_WCAP_DIGITAL)) {
3322 return snd_hda_override_conn_list(codec,
3331 static int patch_vt1718S(struct hda_codec *codec)
3333 struct via_spec *spec;
3336 /* create a codec specific record */
3337 spec = via_new_spec(codec);
3341 spec->aa_mix_nid = 0x21;
3342 override_mic_boost(codec, 0x2b, 0, 3, 40);
3343 override_mic_boost(codec, 0x29, 0, 3, 40);
3344 add_secret_dac_path(codec);
3346 /* automatic parse from the BIOS config */
3347 err = via_parse_auto_config(codec);
3353 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3355 codec->patch_ops = via_patch_ops;
3357 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3362 /* Patch for VT1716S */
3364 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3365 struct snd_ctl_elem_info *uinfo)
3367 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3369 uinfo->value.integer.min = 0;
3370 uinfo->value.integer.max = 1;
3374 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3375 struct snd_ctl_elem_value *ucontrol)
3377 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3380 index = snd_hda_codec_read(codec, 0x26, 0,
3381 AC_VERB_GET_CONNECT_SEL, 0);
3383 *ucontrol->value.integer.value = index;
3388 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3389 struct snd_ctl_elem_value *ucontrol)
3391 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3392 struct via_spec *spec = codec->spec;
3393 int index = *ucontrol->value.integer.value;
3395 snd_hda_codec_write(codec, 0x26, 0,
3396 AC_VERB_SET_CONNECT_SEL, index);
3397 spec->dmic_enabled = index;
3398 set_widgets_power_state(codec);
3402 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3403 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3405 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3406 .name = "Digital Mic Capture Switch",
3407 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3409 .info = vt1716s_dmic_info,
3410 .get = vt1716s_dmic_get,
3411 .put = vt1716s_dmic_put,
3417 /* mono-out mixer elements */
3418 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3419 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3423 static const struct hda_verb vt1716S_init_verbs[] = {
3424 /* Enable Boost Volume backdoor */
3426 /* don't bybass mixer */
3428 /* Enable mono output */
3433 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3435 struct via_spec *spec = codec->spec;
3438 unsigned int mono_out, present;
3439 /* SW0 (17h) = stereo mixer */
3441 (snd_hda_codec_read(codec, 0x17, 0,
3442 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3444 /* PW 1/2/5 (1ah/1bh/1eh) */
3446 set_pin_power_state(codec, 0x1a, &parm);
3447 set_pin_power_state(codec, 0x1b, &parm);
3448 set_pin_power_state(codec, 0x1e, &parm);
3451 /* SW0 (17h), AIW0(13h) */
3452 update_power_state(codec, 0x17, parm);
3453 update_power_state(codec, 0x13, parm);
3456 set_pin_power_state(codec, 0x1e, &parm);
3458 if (spec->dmic_enabled)
3459 set_pin_power_state(codec, 0x22, &parm);
3461 update_power_state(codec, 0x22, AC_PWRST_D3);
3463 /* SW2(26h), AIW1(14h) */
3464 update_power_state(codec, 0x26, parm);
3465 update_power_state(codec, 0x14, parm);
3468 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3470 set_pin_power_state(codec, 0x19, &parm);
3471 /* Smart 5.1 PW2(1bh) */
3472 if (spec->smart51_enabled)
3473 set_pin_power_state(codec, 0x1b, &parm);
3474 update_power_state(codec, 0x18, parm);
3475 update_power_state(codec, 0x11, parm);
3477 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3479 set_pin_power_state(codec, 0x23, &parm);
3480 /* Smart 5.1 PW1(1ah) */
3481 if (spec->smart51_enabled)
3482 set_pin_power_state(codec, 0x1a, &parm);
3483 update_power_state(codec, 0x27, parm);
3485 /* Smart 5.1 PW5(1eh) */
3486 if (spec->smart51_enabled)
3487 set_pin_power_state(codec, 0x1e, &parm);
3488 update_power_state(codec, 0x25, parm);
3491 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3492 present = snd_hda_jack_detect(codec, 0x1c);
3497 present = snd_hda_jack_detect(codec, 0x1d);
3498 if (!spec->hp_independent_mode && present)
3503 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3504 update_power_state(codec, 0x28, parm);
3505 update_power_state(codec, 0x29, parm);
3506 update_power_state(codec, 0x2a, parm);
3508 /* PW 3/4 (1ch/1dh) */
3510 set_pin_power_state(codec, 0x1c, &parm);
3511 set_pin_power_state(codec, 0x1d, &parm);
3512 /* HP Independent Mode, power on AOW3 */
3513 if (spec->hp_independent_mode)
3514 update_power_state(codec, 0x25, parm);
3516 /* force to D0 for internal Speaker */
3517 /* MW0 (16h), AOW0 (10h) */
3518 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
3519 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
3522 static int patch_vt1716S(struct hda_codec *codec)
3524 struct via_spec *spec;
3527 /* create a codec specific record */
3528 spec = via_new_spec(codec);
3532 spec->aa_mix_nid = 0x16;
3533 override_mic_boost(codec, 0x1a, 0, 3, 40);
3534 override_mic_boost(codec, 0x1e, 0, 3, 40);
3536 /* automatic parse from the BIOS config */
3537 err = via_parse_auto_config(codec);
3543 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3545 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3548 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3550 codec->patch_ops = via_patch_ops;
3552 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3558 static const struct hda_verb vt2002P_init_verbs[] = {
3559 /* Class-D speaker related verbs */
3563 /* Enable Boost Volume backdoor */
3565 /* Enable AOW0 to MW9 */
3570 static const struct hda_verb vt1802_init_verbs[] = {
3571 /* Enable Boost Volume backdoor */
3573 /* Enable AOW0 to MW9 */
3578 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3580 struct via_spec *spec = codec->spec;
3583 unsigned int present;
3584 /* MUX9 (1eh) = stereo mixer */
3586 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3588 /* PW 5/6/7 (29h/2ah/2bh) */
3590 set_pin_power_state(codec, 0x29, &parm);
3591 set_pin_power_state(codec, 0x2a, &parm);
3592 set_pin_power_state(codec, 0x2b, &parm);
3594 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3595 update_power_state(codec, 0x1e, parm);
3596 update_power_state(codec, 0x1f, parm);
3597 update_power_state(codec, 0x10, parm);
3598 update_power_state(codec, 0x11, parm);
3602 update_power_state(codec, 0x8, parm);
3604 if (spec->codec_type == VT1802) {
3605 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3607 set_pin_power_state(codec, 0x28, &parm);
3608 update_power_state(codec, 0x18, parm);
3609 update_power_state(codec, 0x38, parm);
3611 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3613 set_pin_power_state(codec, 0x26, &parm);
3614 update_power_state(codec, 0x1c, parm);
3615 update_power_state(codec, 0x37, parm);
3618 if (spec->codec_type == VT1802) {
3619 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3621 set_pin_power_state(codec, 0x25, &parm);
3622 update_power_state(codec, 0x15, parm);
3623 update_power_state(codec, 0x35, parm);
3625 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3627 set_pin_power_state(codec, 0x25, &parm);
3628 update_power_state(codec, 0x19, parm);
3629 update_power_state(codec, 0x35, parm);
3632 if (spec->hp_independent_mode)
3633 update_power_state(codec, 0x9, AC_PWRST_D0);
3636 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3637 present = snd_hda_jack_detect(codec, 0x25);
3640 set_pin_power_state(codec, 0x24, &parm);
3641 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3642 if (spec->codec_type == VT1802)
3643 update_power_state(codec, 0x14, parm);
3645 update_power_state(codec, 0x18, parm);
3646 update_power_state(codec, 0x34, parm);
3649 present = snd_hda_jack_detect(codec, 0x26);
3651 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3652 if (spec->codec_type == VT1802) {
3653 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3654 update_power_state(codec, 0x33, parm);
3655 update_power_state(codec, 0x1c, parm);
3656 update_power_state(codec, 0x3c, parm);
3658 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3659 update_power_state(codec, 0x31, parm);
3660 update_power_state(codec, 0x17, parm);
3661 update_power_state(codec, 0x3b, parm);
3664 if (imux_is_smixer || !is_aa_path_mute(codec))
3665 update_power_state(codec, 0x21, AC_PWRST_D0);
3667 update_power_state(codec, 0x21, AC_PWRST_D3);
3674 VIA_FIXUP_INTMIC_BOOST,
3677 static void via_fixup_intmic_boost(struct hda_codec *codec,
3678 const struct hda_fixup *fix, int action)
3680 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3681 override_mic_boost(codec, 0x30, 0, 2, 40);
3684 static const struct hda_fixup via_fixups[] = {
3685 [VIA_FIXUP_INTMIC_BOOST] = {
3686 .type = HDA_FIXUP_FUNC,
3687 .v.func = via_fixup_intmic_boost,
3691 static const struct snd_pci_quirk vt2002p_fixups[] = {
3692 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
3696 /* patch for vt2002P */
3697 static int patch_vt2002P(struct hda_codec *codec)
3699 struct via_spec *spec;
3702 /* create a codec specific record */
3703 spec = via_new_spec(codec);
3707 spec->aa_mix_nid = 0x21;
3708 override_mic_boost(codec, 0x2b, 0, 3, 40);
3709 override_mic_boost(codec, 0x29, 0, 3, 40);
3710 add_secret_dac_path(codec);
3712 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
3713 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3715 /* automatic parse from the BIOS config */
3716 err = via_parse_auto_config(codec);
3722 if (spec->codec_type == VT1802)
3723 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3725 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3727 codec->patch_ops = via_patch_ops;
3729 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3735 static const struct hda_verb vt1812_init_verbs[] = {
3736 /* Enable Boost Volume backdoor */
3738 /* Enable AOW0 to MW9 */
3743 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3745 struct via_spec *spec = codec->spec;
3747 unsigned int present;
3749 /* PW 5/6/7 (29h/2ah/2bh) */
3751 set_pin_power_state(codec, 0x29, &parm);
3752 set_pin_power_state(codec, 0x2a, &parm);
3753 set_pin_power_state(codec, 0x2b, &parm);
3755 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3756 update_power_state(codec, 0x1e, parm);
3757 update_power_state(codec, 0x1f, parm);
3758 update_power_state(codec, 0x10, parm);
3759 update_power_state(codec, 0x11, parm);
3763 update_power_state(codec, 0x8, AC_PWRST_D0);
3765 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3767 set_pin_power_state(codec, 0x28, &parm);
3768 update_power_state(codec, 0x18, parm);
3769 update_power_state(codec, 0x38, parm);
3771 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3773 set_pin_power_state(codec, 0x25, &parm);
3774 update_power_state(codec, 0x15, parm);
3775 update_power_state(codec, 0x35, parm);
3776 if (spec->hp_independent_mode)
3777 update_power_state(codec, 0x9, AC_PWRST_D0);
3779 /* Internal Speaker */
3780 /* PW0 (24h), MW0(14h), MUX0(34h) */
3781 present = snd_hda_jack_detect(codec, 0x25);
3784 set_pin_power_state(codec, 0x24, &parm);
3786 update_power_state(codec, 0x14, AC_PWRST_D3);
3787 update_power_state(codec, 0x34, AC_PWRST_D3);
3789 update_power_state(codec, 0x14, AC_PWRST_D0);
3790 update_power_state(codec, 0x34, AC_PWRST_D0);
3795 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3796 present = snd_hda_jack_detect(codec, 0x28);
3799 set_pin_power_state(codec, 0x31, &parm);
3801 update_power_state(codec, 0x1c, AC_PWRST_D3);
3802 update_power_state(codec, 0x3c, AC_PWRST_D3);
3803 update_power_state(codec, 0x3e, AC_PWRST_D3);
3805 update_power_state(codec, 0x1c, AC_PWRST_D0);
3806 update_power_state(codec, 0x3c, AC_PWRST_D0);
3807 update_power_state(codec, 0x3e, AC_PWRST_D0);
3810 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3812 set_pin_power_state(codec, 0x33, &parm);
3813 update_power_state(codec, 0x1d, parm);
3814 update_power_state(codec, 0x3d, parm);
3818 /* patch for vt1812 */
3819 static int patch_vt1812(struct hda_codec *codec)
3821 struct via_spec *spec;
3824 /* create a codec specific record */
3825 spec = via_new_spec(codec);
3829 spec->aa_mix_nid = 0x21;
3830 override_mic_boost(codec, 0x2b, 0, 3, 40);
3831 override_mic_boost(codec, 0x29, 0, 3, 40);
3832 add_secret_dac_path(codec);
3834 /* automatic parse from the BIOS config */
3835 err = via_parse_auto_config(codec);
3841 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3843 codec->patch_ops = via_patch_ops;
3845 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3852 static const struct hda_codec_preset snd_hda_preset_via[] = {
3853 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3854 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3855 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3856 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3857 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3858 .patch = patch_vt1709},
3859 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3860 .patch = patch_vt1709},
3861 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3862 .patch = patch_vt1709},
3863 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3864 .patch = patch_vt1709},
3865 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3866 .patch = patch_vt1709},
3867 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3868 .patch = patch_vt1709},
3869 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3870 .patch = patch_vt1709},
3871 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3872 .patch = patch_vt1709},
3873 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3874 .patch = patch_vt1708B},
3875 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3876 .patch = patch_vt1708B},
3877 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3878 .patch = patch_vt1708B},
3879 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3880 .patch = patch_vt1708B},
3881 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3882 .patch = patch_vt1708B},
3883 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3884 .patch = patch_vt1708B},
3885 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3886 .patch = patch_vt1708B},
3887 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3888 .patch = patch_vt1708B},
3889 { .id = 0x11060397, .name = "VT1708S",
3890 .patch = patch_vt1708S},
3891 { .id = 0x11061397, .name = "VT1708S",
3892 .patch = patch_vt1708S},
3893 { .id = 0x11062397, .name = "VT1708S",
3894 .patch = patch_vt1708S},
3895 { .id = 0x11063397, .name = "VT1708S",
3896 .patch = patch_vt1708S},
3897 { .id = 0x11064397, .name = "VT1705",
3898 .patch = patch_vt1708S},
3899 { .id = 0x11065397, .name = "VT1708S",
3900 .patch = patch_vt1708S},
3901 { .id = 0x11066397, .name = "VT1708S",
3902 .patch = patch_vt1708S},
3903 { .id = 0x11067397, .name = "VT1708S",
3904 .patch = patch_vt1708S},
3905 { .id = 0x11060398, .name = "VT1702",
3906 .patch = patch_vt1702},
3907 { .id = 0x11061398, .name = "VT1702",
3908 .patch = patch_vt1702},
3909 { .id = 0x11062398, .name = "VT1702",
3910 .patch = patch_vt1702},
3911 { .id = 0x11063398, .name = "VT1702",
3912 .patch = patch_vt1702},
3913 { .id = 0x11064398, .name = "VT1702",
3914 .patch = patch_vt1702},
3915 { .id = 0x11065398, .name = "VT1702",
3916 .patch = patch_vt1702},
3917 { .id = 0x11066398, .name = "VT1702",
3918 .patch = patch_vt1702},
3919 { .id = 0x11067398, .name = "VT1702",
3920 .patch = patch_vt1702},
3921 { .id = 0x11060428, .name = "VT1718S",
3922 .patch = patch_vt1718S},
3923 { .id = 0x11064428, .name = "VT1718S",
3924 .patch = patch_vt1718S},
3925 { .id = 0x11060441, .name = "VT2020",
3926 .patch = patch_vt1718S},
3927 { .id = 0x11064441, .name = "VT1828S",
3928 .patch = patch_vt1718S},
3929 { .id = 0x11060433, .name = "VT1716S",
3930 .patch = patch_vt1716S},
3931 { .id = 0x1106a721, .name = "VT1716S",
3932 .patch = patch_vt1716S},
3933 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3934 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3935 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3936 { .id = 0x11060440, .name = "VT1818S",
3937 .patch = patch_vt1708S},
3938 { .id = 0x11060446, .name = "VT1802",
3939 .patch = patch_vt2002P},
3940 { .id = 0x11068446, .name = "VT1802",
3941 .patch = patch_vt2002P},
3945 MODULE_ALIAS("snd-hda-codec-id:1106*");
3947 static struct hda_codec_preset_list via_list = {
3948 .preset = snd_hda_preset_via,
3949 .owner = THIS_MODULE,
3952 MODULE_LICENSE("GPL");
3953 MODULE_DESCRIPTION("VIA HD-audio codec");
3955 static int __init patch_via_init(void)
3957 return snd_hda_add_codec_preset(&via_list);
3960 static void __exit patch_via_exit(void)
3962 snd_hda_delete_codec_preset(&via_list);
3965 module_init(patch_via_init)
3966 module_exit(patch_via_exit)