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
84 #define VT2002P_COMPATIBLE(spec) \
85 ((spec)->codec_type == VT2002P ||\
86 (spec)->codec_type == VT1812 ||\
87 (spec)->codec_type == VT1802)
89 #define MAX_NID_PATH_DEPTH 5
91 /* output-path: DAC -> ... -> pin
92 * idx[] contains the source index number of the next widget;
93 * e.g. idx[0] is the index of the DAC selected by path[1] widget
94 * multi[] indicates whether it's a selector widget with multi-connectors
95 * (i.e. the connection selection is mandatory)
96 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
100 hda_nid_t path[MAX_NID_PATH_DEPTH];
101 unsigned char idx[MAX_NID_PATH_DEPTH];
102 unsigned char multi[MAX_NID_PATH_DEPTH];
103 unsigned int vol_ctl;
104 unsigned int mute_ctl;
109 hda_nid_t pin; /* input-pin or aa-mix */
110 int adc_idx; /* ADC index to be used */
111 int mux_idx; /* MUX index (if any) */
112 const char *label; /* input-source label */
115 #define VIA_MAX_ADCS 3
118 STREAM_MULTI_OUT = (1 << 0),
119 STREAM_INDEP_HP = (1 << 1),
123 /* codec parameterization */
124 const struct snd_kcontrol_new *mixers[6];
125 unsigned int num_mixers;
127 const struct hda_verb *init_verbs[5];
128 unsigned int num_iverbs;
130 char stream_name_analog[32];
131 char stream_name_hp[32];
132 const struct hda_pcm_stream *stream_analog_playback;
133 const struct hda_pcm_stream *stream_analog_capture;
135 char stream_name_digital[32];
136 const struct hda_pcm_stream *stream_digital_playback;
137 const struct hda_pcm_stream *stream_digital_capture;
140 struct hda_multi_out multiout;
141 hda_nid_t slave_dig_outs[2];
142 hda_nid_t hp_dac_nid;
143 hda_nid_t speaker_dac_nid;
144 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
145 int opened_streams; /* STREAM_* bits */
146 int active_streams; /* STREAM_* bits */
147 int aamix_mode; /* loopback is enabled for output-path? */
150 * There are different output-paths depending on the setup.
151 * out_path, hp_path and speaker_path are primary paths. If both
152 * direct DAC and aa-loopback routes are available, these contain
153 * the former paths. Meanwhile *_mix_path contain the paths with
154 * loopback mixer. (Since the loopback is only for front channel,
155 * no out_mix_path for surround channels.)
156 * The HP output has another path, hp_indep_path, which is used in
157 * the independent-HP mode.
159 struct nid_path out_path[HDA_SIDE + 1];
160 struct nid_path out_mix_path;
161 struct nid_path hp_path;
162 struct nid_path hp_mix_path;
163 struct nid_path hp_indep_path;
164 struct nid_path speaker_path;
165 struct nid_path speaker_mix_path;
168 unsigned int num_adc_nids;
169 hda_nid_t adc_nids[VIA_MAX_ADCS];
170 hda_nid_t mux_nids[VIA_MAX_ADCS];
171 hda_nid_t aa_mix_nid;
172 hda_nid_t dig_in_nid;
177 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
178 unsigned int cur_mux[VIA_MAX_ADCS];
180 /* dynamic DAC switching */
181 unsigned int cur_dac_stream_tag;
182 unsigned int cur_dac_format;
183 unsigned int cur_hp_stream_tag;
184 unsigned int cur_hp_format;
186 /* dynamic ADC switching */
188 unsigned int cur_adc_stream_tag;
189 unsigned int cur_adc_format;
191 /* PCM information */
192 struct hda_pcm pcm_rec[3];
194 /* dynamic controls, init_verbs and input_mux */
195 struct auto_pin_cfg autocfg;
196 struct snd_array kctls;
197 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
200 unsigned int hp_independent_mode;
201 unsigned int dmic_enabled;
202 unsigned int no_pin_power_ctl;
203 enum VIA_HDA_CODEC codec_type;
205 /* analog low-power control */
209 unsigned int smart51_nums;
210 hda_nid_t smart51_pins[2];
212 const char *smart51_labels[2];
213 unsigned int smart51_enabled;
215 /* work to check hp jack state */
216 struct hda_codec *codec;
217 struct delayed_work vt1708_hp_work;
219 int vt1708_jack_detect;
220 int vt1708_hp_present;
222 void (*set_widgets_power_state)(struct hda_codec *codec);
223 unsigned int dac_stream_tag[4];
225 struct hda_loopback_check loopback;
227 struct hda_amp_list loopback_list[8];
229 /* bind capture-volume */
230 struct hda_bind_ctls *bind_cap_vol;
231 struct hda_bind_ctls *bind_cap_sw;
233 struct mutex config_mutex;
236 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
237 static struct via_spec * via_new_spec(struct hda_codec *codec)
239 struct via_spec *spec;
241 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
245 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
246 mutex_init(&spec->config_mutex);
249 spec->codec_type = get_codec_type(codec);
250 /* VT1708BCE & VT1708S are almost same */
251 if (spec->codec_type == VT1708BCE)
252 spec->codec_type = VT1708S;
256 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
258 u32 vendor_id = codec->vendor_id;
259 u16 ven_id = vendor_id >> 16;
260 u16 dev_id = vendor_id & 0xffff;
261 enum VIA_HDA_CODEC codec_type;
264 if (ven_id != 0x1106)
265 codec_type = UNKNOWN;
266 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
268 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
269 codec_type = VT1709_10CH;
270 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
271 codec_type = VT1709_6CH;
272 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
273 codec_type = VT1708B_8CH;
274 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
275 codec_type = VT1708BCE;
276 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
277 codec_type = VT1708B_4CH;
278 else if ((dev_id & 0xfff) == 0x397
279 && (dev_id >> 12) < 8)
280 codec_type = VT1708S;
281 else if ((dev_id & 0xfff) == 0x398
282 && (dev_id >> 12) < 8)
284 else if ((dev_id & 0xfff) == 0x428
285 && (dev_id >> 12) < 8)
286 codec_type = VT1718S;
287 else if (dev_id == 0x0433 || dev_id == 0xa721)
288 codec_type = VT1716S;
289 else if (dev_id == 0x0441 || dev_id == 0x4441)
290 codec_type = VT1718S;
291 else if (dev_id == 0x0438 || dev_id == 0x4438)
292 codec_type = VT2002P;
293 else if (dev_id == 0x0448)
295 else if (dev_id == 0x0440)
296 codec_type = VT1708S;
297 else if ((dev_id & 0xfff) == 0x446)
299 else if (dev_id == 0x4760)
300 codec_type = VT1705CF;
301 else if (dev_id == 0x4761 || dev_id == 0x4762)
304 codec_type = UNKNOWN;
308 #define VIA_JACK_EVENT 0x20
309 #define VIA_HP_EVENT 0x01
310 #define VIA_LINE_EVENT 0x03
315 VIA_CTL_WIDGET_ANALOG_MUTE,
318 static void analog_low_current_mode(struct hda_codec *codec);
319 static bool is_aa_path_mute(struct hda_codec *codec);
321 #define hp_detect_with_aa(codec) \
322 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
323 !is_aa_path_mute(codec))
325 static void vt1708_stop_hp_work(struct via_spec *spec)
327 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
329 if (spec->hp_work_active) {
330 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
331 cancel_delayed_work_sync(&spec->vt1708_hp_work);
332 spec->hp_work_active = 0;
336 static void vt1708_update_hp_work(struct via_spec *spec)
338 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
340 if (spec->vt1708_jack_detect &&
341 (spec->active_streams || hp_detect_with_aa(spec->codec))) {
342 if (!spec->hp_work_active) {
343 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
344 schedule_delayed_work(&spec->vt1708_hp_work,
345 msecs_to_jiffies(100));
346 spec->hp_work_active = 1;
348 } else if (!hp_detect_with_aa(spec->codec))
349 vt1708_stop_hp_work(spec);
352 static void set_widgets_power_state(struct hda_codec *codec)
354 struct via_spec *spec = codec->spec;
355 if (spec->set_widgets_power_state)
356 spec->set_widgets_power_state(codec);
359 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_value *ucontrol)
362 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
363 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
365 set_widgets_power_state(codec);
366 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
367 vt1708_update_hp_work(codec->spec);
371 /* modify .put = snd_hda_mixer_amp_switch_put */
372 #define ANALOG_INPUT_MUTE \
373 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
376 .info = snd_hda_mixer_amp_switch_info, \
377 .get = snd_hda_mixer_amp_switch_get, \
378 .put = analog_input_switch_put, \
379 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
381 static const struct snd_kcontrol_new via_control_templates[] = {
382 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
383 HDA_CODEC_MUTE(NULL, 0, 0, 0),
388 /* add dynamic controls */
389 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
390 const struct snd_kcontrol_new *tmpl,
393 struct snd_kcontrol_new *knew;
395 knew = snd_array_new(&spec->kctls);
402 knew->name = kstrdup(name, GFP_KERNEL);
409 static int __via_add_control(struct via_spec *spec, int type, const char *name,
410 int idx, unsigned long val)
412 struct snd_kcontrol_new *knew;
414 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
418 if (get_amp_nid_(val))
419 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
420 knew->private_value = val;
424 #define via_add_control(spec, type, name, val) \
425 __via_add_control(spec, type, name, 0, val)
427 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
429 static void via_free_kctls(struct hda_codec *codec)
431 struct via_spec *spec = codec->spec;
433 if (spec->kctls.list) {
434 struct snd_kcontrol_new *kctl = spec->kctls.list;
436 for (i = 0; i < spec->kctls.used; i++)
439 snd_array_free(&spec->kctls);
442 /* create input playback/capture controls for the given pin */
443 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
444 int type_idx, int idx, int mix_nid)
449 sprintf(name, "%s Playback Volume", ctlname);
450 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
451 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
454 sprintf(name, "%s Playback Switch", ctlname);
455 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
456 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
462 #define get_connection_index(codec, mux, nid) \
463 snd_hda_get_conn_index(codec, mux, nid, 0)
465 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
471 caps = get_wcaps(codec, nid);
472 if (dir == HDA_INPUT)
473 caps &= AC_WCAP_IN_AMP;
475 caps &= AC_WCAP_OUT_AMP;
478 if (query_amp_caps(codec, nid, dir) & mask)
483 #define have_mute(codec, nid, dir) \
484 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
486 /* enable/disable the output-route mixers */
487 static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
488 hda_nid_t mix_nid, int idx, bool enable)
494 num = snd_hda_get_num_conns(codec, mix_nid);
495 for (i = 0; i < num; i++) {
497 val = AMP_IN_UNMUTE(i);
499 val = AMP_IN_MUTE(i);
500 snd_hda_codec_write(codec, mix_nid, 0,
501 AC_VERB_SET_AMP_GAIN_MUTE, val);
505 /* enable/disable the output-route */
506 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
507 bool enable, bool force)
509 struct via_spec *spec = codec->spec;
511 for (i = 0; i < path->depth; i++) {
513 int idx = path->idx[i];
515 if (i < path->depth - 1)
516 dst = path->path[i + 1];
519 if (enable && path->multi[i])
520 snd_hda_codec_write(codec, dst, 0,
521 AC_VERB_SET_CONNECT_SEL, idx);
522 if (!force && (dst == spec->aa_mix_nid))
524 if (have_mute(codec, dst, HDA_INPUT))
525 activate_output_mix(codec, path, dst, idx, enable);
526 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
528 if (have_mute(codec, src, HDA_OUTPUT)) {
529 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
530 snd_hda_codec_write(codec, src, 0,
531 AC_VERB_SET_AMP_GAIN_MUTE, val);
536 /* set the given pin as output */
537 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
542 snd_hda_set_pin_ctl(codec, pin, pin_type);
543 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
544 snd_hda_codec_write(codec, pin, 0,
545 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
548 static void via_auto_init_output(struct hda_codec *codec,
549 struct nid_path *path, int pin_type)
556 pin = path->path[path->depth - 1];
558 init_output_pin(codec, pin, pin_type);
559 if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
560 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
563 if (caps & AC_AMPCAP_MUTE) {
565 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
566 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
569 activate_output_path(codec, path, true, true); /* force on */
572 static void via_auto_init_multi_out(struct hda_codec *codec)
574 struct via_spec *spec = codec->spec;
575 struct nid_path *path;
578 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
579 path = &spec->out_path[i];
580 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
581 path = &spec->out_mix_path;
582 via_auto_init_output(codec, path, PIN_OUT);
586 /* deactivate the inactive headphone-paths */
587 static void deactivate_hp_paths(struct hda_codec *codec)
589 struct via_spec *spec = codec->spec;
590 int shared = spec->hp_indep_shared;
592 if (spec->hp_independent_mode) {
593 activate_output_path(codec, &spec->hp_path, false, false);
594 activate_output_path(codec, &spec->hp_mix_path, false, false);
596 activate_output_path(codec, &spec->out_path[shared],
598 } else if (spec->aamix_mode || !spec->hp_path.depth) {
599 activate_output_path(codec, &spec->hp_indep_path, false, false);
600 activate_output_path(codec, &spec->hp_path, false, false);
602 activate_output_path(codec, &spec->hp_indep_path, false, false);
603 activate_output_path(codec, &spec->hp_mix_path, false, false);
607 static void via_auto_init_hp_out(struct hda_codec *codec)
609 struct via_spec *spec = codec->spec;
611 if (!spec->hp_path.depth) {
612 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
615 deactivate_hp_paths(codec);
616 if (spec->hp_independent_mode)
617 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
618 else if (spec->aamix_mode)
619 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
621 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
624 static void via_auto_init_speaker_out(struct hda_codec *codec)
626 struct via_spec *spec = codec->spec;
628 if (!spec->autocfg.speaker_outs)
630 if (!spec->speaker_path.depth) {
631 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
634 if (!spec->aamix_mode) {
635 activate_output_path(codec, &spec->speaker_mix_path,
637 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
639 activate_output_path(codec, &spec->speaker_path, false, false);
640 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
644 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
645 static void via_hp_automute(struct hda_codec *codec);
647 static void via_auto_init_analog_input(struct hda_codec *codec)
649 struct via_spec *spec = codec->spec;
650 const struct auto_pin_cfg *cfg = &spec->autocfg;
651 hda_nid_t conn[HDA_MAX_CONNECTIONS];
656 for (i = 0; i < spec->num_adc_nids; i++) {
657 hda_nid_t nid = spec->adc_nids[i];
658 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP) ||
659 !(query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE))
661 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
662 AC_VERB_SET_AMP_GAIN_MUTE,
667 for (i = 0; i < cfg->num_inputs; i++) {
668 hda_nid_t nid = cfg->inputs[i].pin;
669 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
673 if (cfg->inputs[i].type == AUTO_PIN_MIC)
674 ctl |= snd_hda_get_default_vref(codec, nid);
676 snd_hda_set_pin_ctl(codec, nid, ctl);
680 for (i = 0; i < spec->num_adc_nids; i++) {
681 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
682 /* secondary ADCs must have the unique MUX */
683 if (i > 0 && !spec->mux_nids[i])
685 if (spec->mux_nids[adc_idx]) {
686 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
687 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
688 AC_VERB_SET_CONNECT_SEL,
691 if (spec->dyn_adc_switch)
692 break; /* only one input-src */
696 if (!spec->aa_mix_nid)
698 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
700 for (i = 0; i < num_conns; i++) {
701 unsigned int caps = get_wcaps(codec, conn[i]);
702 if (get_wcaps_type(caps) == AC_WID_PIN)
703 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
704 AC_VERB_SET_AMP_GAIN_MUTE,
709 static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
712 if (snd_hda_codec_read(codec, nid, 0,
713 AC_VERB_GET_POWER_STATE, 0) == parm)
715 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
718 static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
719 unsigned int parm, unsigned int index)
721 struct via_spec *spec = codec->spec;
723 if (snd_hda_codec_read(codec, nid, 0,
724 AC_VERB_GET_POWER_STATE, 0) == parm)
726 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
727 if (format && (spec->dac_stream_tag[index] != format))
728 spec->dac_stream_tag[index] = format;
730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
731 if (parm == AC_PWRST_D0) {
732 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
733 if (!format && (spec->dac_stream_tag[index] != format))
734 snd_hda_codec_write(codec, nid, 0,
735 AC_VERB_SET_CHANNEL_STREAMID,
736 spec->dac_stream_tag[index]);
740 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
741 unsigned int *affected_parm)
744 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
745 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
746 >> AC_DEFCFG_MISC_SHIFT
747 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
748 struct via_spec *spec = codec->spec;
749 unsigned present = 0;
751 no_presence |= spec->no_pin_power_ctl;
753 present = snd_hda_jack_detect(codec, nid);
754 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
755 || ((no_presence || present)
756 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
757 *affected_parm = AC_PWRST_D0; /* if it's connected */
762 update_power_state(codec, nid, parm);
765 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
766 struct snd_ctl_elem_info *uinfo)
768 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
771 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
772 struct snd_ctl_elem_value *ucontrol)
774 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
775 struct via_spec *spec = codec->spec;
776 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
780 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
781 struct snd_ctl_elem_value *ucontrol)
783 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
784 struct via_spec *spec = codec->spec;
785 unsigned int val = !ucontrol->value.enumerated.item[0];
787 if (val == spec->no_pin_power_ctl)
789 spec->no_pin_power_ctl = val;
790 set_widgets_power_state(codec);
791 analog_low_current_mode(codec);
795 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
797 .name = "Dynamic Power-Control",
798 .info = via_pin_power_ctl_info,
799 .get = via_pin_power_ctl_get,
800 .put = via_pin_power_ctl_put,
804 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
805 struct snd_ctl_elem_info *uinfo)
807 static const char * const texts[] = { "OFF", "ON" };
809 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
811 uinfo->value.enumerated.items = 2;
812 if (uinfo->value.enumerated.item >= 2)
813 uinfo->value.enumerated.item = 1;
814 strcpy(uinfo->value.enumerated.name,
815 texts[uinfo->value.enumerated.item]);
819 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
820 struct snd_ctl_elem_value *ucontrol)
822 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
823 struct via_spec *spec = codec->spec;
825 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
829 /* adjust spec->multiout setup according to the current flags */
830 static void setup_playback_multi_pcm(struct via_spec *spec)
832 const struct auto_pin_cfg *cfg = &spec->autocfg;
833 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
834 spec->multiout.hp_nid = 0;
835 if (!spec->hp_independent_mode) {
836 if (!spec->hp_indep_shared)
837 spec->multiout.hp_nid = spec->hp_dac_nid;
839 if (spec->hp_indep_shared)
840 spec->multiout.num_dacs = cfg->line_outs - 1;
844 /* update DAC setups according to indep-HP switch;
845 * this function is called only when indep-HP is modified
847 static void switch_indep_hp_dacs(struct hda_codec *codec)
849 struct via_spec *spec = codec->spec;
850 int shared = spec->hp_indep_shared;
851 hda_nid_t shared_dac, hp_dac;
853 if (!spec->opened_streams)
856 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
857 hp_dac = spec->hp_dac_nid;
858 if (spec->hp_independent_mode) {
859 /* switch to indep-HP mode */
860 if (spec->active_streams & STREAM_MULTI_OUT) {
861 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
862 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
864 if (spec->active_streams & STREAM_INDEP_HP)
865 snd_hda_codec_setup_stream(codec, hp_dac,
866 spec->cur_hp_stream_tag, 0,
867 spec->cur_hp_format);
869 /* back to HP or shared-DAC */
870 if (spec->active_streams & STREAM_INDEP_HP)
871 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
872 if (spec->active_streams & STREAM_MULTI_OUT) {
875 if (shared_dac) { /* reset mutli-ch DAC */
878 } else { /* reset HP DAC */
882 snd_hda_codec_setup_stream(codec, dac,
883 spec->cur_dac_stream_tag, ch,
884 spec->cur_dac_format);
887 setup_playback_multi_pcm(spec);
890 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
891 struct snd_ctl_elem_value *ucontrol)
893 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
894 struct via_spec *spec = codec->spec;
897 mutex_lock(&spec->config_mutex);
898 cur = !!ucontrol->value.enumerated.item[0];
899 if (spec->hp_independent_mode == cur) {
900 mutex_unlock(&spec->config_mutex);
903 spec->hp_independent_mode = cur;
904 shared = spec->hp_indep_shared;
905 deactivate_hp_paths(codec);
907 activate_output_path(codec, &spec->hp_indep_path, true, false);
910 activate_output_path(codec, &spec->out_path[shared],
912 if (spec->aamix_mode || !spec->hp_path.depth)
913 activate_output_path(codec, &spec->hp_mix_path,
916 activate_output_path(codec, &spec->hp_path,
920 switch_indep_hp_dacs(codec);
921 mutex_unlock(&spec->config_mutex);
923 /* update jack power state */
924 set_widgets_power_state(codec);
925 via_hp_automute(codec);
929 static const struct snd_kcontrol_new via_hp_mixer = {
930 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
931 .name = "Independent HP",
932 .info = via_independent_hp_info,
933 .get = via_independent_hp_get,
934 .put = via_independent_hp_put,
937 static int via_hp_build(struct hda_codec *codec)
939 struct via_spec *spec = codec->spec;
940 struct snd_kcontrol_new *knew;
943 nid = spec->autocfg.hp_pins[0];
944 knew = via_clone_control(spec, &via_hp_mixer);
948 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
953 static void notify_aa_path_ctls(struct hda_codec *codec)
955 struct via_spec *spec = codec->spec;
958 for (i = 0; i < spec->smart51_nums; i++) {
959 struct snd_kcontrol *ctl;
960 struct snd_ctl_elem_id id;
961 memset(&id, 0, sizeof(id));
962 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
963 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
964 ctl = snd_hda_find_mixer_ctl(codec, id.name);
966 snd_ctl_notify(codec->bus->card,
967 SNDRV_CTL_EVENT_MASK_VALUE,
972 static void mute_aa_path(struct hda_codec *codec, int mute)
974 struct via_spec *spec = codec->spec;
975 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
978 /* check AA path's mute status */
979 for (i = 0; i < spec->smart51_nums; i++) {
980 if (spec->smart51_idxs[i] < 0)
982 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
983 HDA_INPUT, spec->smart51_idxs[i],
988 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
990 struct via_spec *spec = codec->spec;
993 for (i = 0; i < spec->smart51_nums; i++)
994 if (spec->smart51_pins[i] == pin)
999 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1000 struct snd_ctl_elem_value *ucontrol)
1002 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1003 struct via_spec *spec = codec->spec;
1005 *ucontrol->value.integer.value = spec->smart51_enabled;
1009 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1010 struct snd_ctl_elem_value *ucontrol)
1012 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1013 struct via_spec *spec = codec->spec;
1014 int out_in = *ucontrol->value.integer.value
1015 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1018 for (i = 0; i < spec->smart51_nums; i++) {
1019 hda_nid_t nid = spec->smart51_pins[i];
1022 parm = snd_hda_codec_read(codec, nid, 0,
1023 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1024 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1026 snd_hda_set_pin_ctl(codec, nid, parm);
1027 if (out_in == AC_PINCTL_OUT_EN) {
1028 mute_aa_path(codec, 1);
1029 notify_aa_path_ctls(codec);
1032 spec->smart51_enabled = *ucontrol->value.integer.value;
1033 set_widgets_power_state(codec);
1037 static const struct snd_kcontrol_new via_smart51_mixer = {
1038 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1039 .name = "Smart 5.1",
1041 .info = snd_ctl_boolean_mono_info,
1042 .get = via_smart51_get,
1043 .put = via_smart51_put,
1046 static int via_smart51_build(struct hda_codec *codec)
1048 struct via_spec *spec = codec->spec;
1050 if (!spec->smart51_nums)
1052 if (!via_clone_control(spec, &via_smart51_mixer))
1057 /* check AA path's mute status */
1058 static bool is_aa_path_mute(struct hda_codec *codec)
1060 struct via_spec *spec = codec->spec;
1061 const struct hda_amp_list *p;
1064 for (i = 0; i < spec->num_loopbacks; i++) {
1065 p = &spec->loopback_list[i];
1066 for (ch = 0; ch < 2; ch++) {
1067 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1069 if (!(v & HDA_AMP_MUTE) && v > 0)
1076 /* enter/exit analog low-current mode */
1077 static void __analog_low_current_mode(struct hda_codec *codec, bool force)
1079 struct via_spec *spec = codec->spec;
1081 unsigned int verb, parm;
1083 if (spec->no_pin_power_ctl)
1086 enable = is_aa_path_mute(codec) && !spec->opened_streams;
1087 if (enable == spec->alc_mode && !force)
1089 spec->alc_mode = enable;
1091 /* decide low current mode's verb & parameter */
1092 switch (spec->codec_type) {
1096 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1102 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1106 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1112 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1117 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1120 return; /* other codecs are not supported */
1123 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1126 static void analog_low_current_mode(struct hda_codec *codec)
1128 return __analog_low_current_mode(codec, false);
1132 * generic initialization of ADC, input mixers and output mixers
1134 static const struct hda_verb vt1708_init_verbs[] = {
1135 /* power down jack detect function */
1140 static void set_stream_open(struct hda_codec *codec, int bit, bool active)
1142 struct via_spec *spec = codec->spec;
1145 spec->opened_streams |= bit;
1147 spec->opened_streams &= ~bit;
1148 analog_low_current_mode(codec);
1151 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1152 struct hda_codec *codec,
1153 struct snd_pcm_substream *substream)
1155 struct via_spec *spec = codec->spec;
1156 const struct auto_pin_cfg *cfg = &spec->autocfg;
1159 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1160 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1161 set_stream_open(codec, STREAM_MULTI_OUT, true);
1162 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1165 set_stream_open(codec, STREAM_MULTI_OUT, false);
1171 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1172 struct hda_codec *codec,
1173 struct snd_pcm_substream *substream)
1175 set_stream_open(codec, STREAM_MULTI_OUT, false);
1179 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1180 struct hda_codec *codec,
1181 struct snd_pcm_substream *substream)
1183 struct via_spec *spec = codec->spec;
1185 if (snd_BUG_ON(!spec->hp_dac_nid))
1187 set_stream_open(codec, STREAM_INDEP_HP, true);
1191 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1192 struct hda_codec *codec,
1193 struct snd_pcm_substream *substream)
1195 set_stream_open(codec, STREAM_INDEP_HP, false);
1199 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1200 struct hda_codec *codec,
1201 unsigned int stream_tag,
1202 unsigned int format,
1203 struct snd_pcm_substream *substream)
1205 struct via_spec *spec = codec->spec;
1207 mutex_lock(&spec->config_mutex);
1208 setup_playback_multi_pcm(spec);
1209 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1211 /* remember for dynamic DAC switch with indep-HP */
1212 spec->active_streams |= STREAM_MULTI_OUT;
1213 spec->cur_dac_stream_tag = stream_tag;
1214 spec->cur_dac_format = format;
1215 mutex_unlock(&spec->config_mutex);
1216 vt1708_update_hp_work(spec);
1220 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1221 struct hda_codec *codec,
1222 unsigned int stream_tag,
1223 unsigned int format,
1224 struct snd_pcm_substream *substream)
1226 struct via_spec *spec = codec->spec;
1228 mutex_lock(&spec->config_mutex);
1229 if (spec->hp_independent_mode)
1230 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1231 stream_tag, 0, format);
1232 spec->active_streams |= STREAM_INDEP_HP;
1233 spec->cur_hp_stream_tag = stream_tag;
1234 spec->cur_hp_format = format;
1235 mutex_unlock(&spec->config_mutex);
1236 vt1708_update_hp_work(spec);
1240 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1241 struct hda_codec *codec,
1242 struct snd_pcm_substream *substream)
1244 struct via_spec *spec = codec->spec;
1246 mutex_lock(&spec->config_mutex);
1247 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1248 spec->active_streams &= ~STREAM_MULTI_OUT;
1249 mutex_unlock(&spec->config_mutex);
1250 vt1708_update_hp_work(spec);
1254 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1255 struct hda_codec *codec,
1256 struct snd_pcm_substream *substream)
1258 struct via_spec *spec = codec->spec;
1260 mutex_lock(&spec->config_mutex);
1261 if (spec->hp_independent_mode)
1262 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1263 spec->active_streams &= ~STREAM_INDEP_HP;
1264 mutex_unlock(&spec->config_mutex);
1265 vt1708_update_hp_work(spec);
1272 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1273 struct hda_codec *codec,
1274 struct snd_pcm_substream *substream)
1276 struct via_spec *spec = codec->spec;
1277 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1280 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1281 struct hda_codec *codec,
1282 struct snd_pcm_substream *substream)
1284 struct via_spec *spec = codec->spec;
1285 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1288 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1289 struct hda_codec *codec,
1290 unsigned int stream_tag,
1291 unsigned int format,
1292 struct snd_pcm_substream *substream)
1294 struct via_spec *spec = codec->spec;
1295 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1296 stream_tag, format, substream);
1299 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1300 struct hda_codec *codec,
1301 struct snd_pcm_substream *substream)
1303 struct via_spec *spec = codec->spec;
1304 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1311 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1312 struct hda_codec *codec,
1313 unsigned int stream_tag,
1314 unsigned int format,
1315 struct snd_pcm_substream *substream)
1317 struct via_spec *spec = codec->spec;
1319 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1320 stream_tag, 0, format);
1324 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1325 struct hda_codec *codec,
1326 struct snd_pcm_substream *substream)
1328 struct via_spec *spec = codec->spec;
1329 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1333 /* analog capture with dynamic ADC switching */
1334 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1335 struct hda_codec *codec,
1336 unsigned int stream_tag,
1337 unsigned int format,
1338 struct snd_pcm_substream *substream)
1340 struct via_spec *spec = codec->spec;
1341 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1343 mutex_lock(&spec->config_mutex);
1344 spec->cur_adc = spec->adc_nids[adc_idx];
1345 spec->cur_adc_stream_tag = stream_tag;
1346 spec->cur_adc_format = format;
1347 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1348 mutex_unlock(&spec->config_mutex);
1352 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1353 struct hda_codec *codec,
1354 struct snd_pcm_substream *substream)
1356 struct via_spec *spec = codec->spec;
1358 mutex_lock(&spec->config_mutex);
1359 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1361 mutex_unlock(&spec->config_mutex);
1365 /* re-setup the stream if running; called from input-src put */
1366 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1368 struct via_spec *spec = codec->spec;
1369 int adc_idx = spec->inputs[cur].adc_idx;
1370 hda_nid_t adc = spec->adc_nids[adc_idx];
1373 mutex_lock(&spec->config_mutex);
1374 if (spec->cur_adc && spec->cur_adc != adc) {
1375 /* stream is running, let's swap the current ADC */
1376 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1377 spec->cur_adc = adc;
1378 snd_hda_codec_setup_stream(codec, adc,
1379 spec->cur_adc_stream_tag, 0,
1380 spec->cur_adc_format);
1383 mutex_unlock(&spec->config_mutex);
1387 static const struct hda_pcm_stream via_pcm_analog_playback = {
1391 /* NID is set in via_build_pcms */
1393 .open = via_playback_multi_pcm_open,
1394 .close = via_playback_multi_pcm_close,
1395 .prepare = via_playback_multi_pcm_prepare,
1396 .cleanup = via_playback_multi_pcm_cleanup
1400 static const struct hda_pcm_stream via_pcm_hp_playback = {
1404 /* NID is set in via_build_pcms */
1406 .open = via_playback_hp_pcm_open,
1407 .close = via_playback_hp_pcm_close,
1408 .prepare = via_playback_hp_pcm_prepare,
1409 .cleanup = via_playback_hp_pcm_cleanup
1413 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1417 /* NID is set in via_build_pcms */
1418 /* We got noisy outputs on the right channel on VT1708 when
1419 * 24bit samples are used. Until any workaround is found,
1420 * disable the 24bit format, so far.
1422 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1424 .open = via_playback_multi_pcm_open,
1425 .close = via_playback_multi_pcm_close,
1426 .prepare = via_playback_multi_pcm_prepare,
1427 .cleanup = via_playback_multi_pcm_cleanup
1431 static const struct hda_pcm_stream via_pcm_analog_capture = {
1432 .substreams = 1, /* will be changed in via_build_pcms() */
1435 /* NID is set in via_build_pcms */
1437 .prepare = via_capture_pcm_prepare,
1438 .cleanup = via_capture_pcm_cleanup
1442 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1446 /* NID is set in via_build_pcms */
1448 .prepare = via_dyn_adc_capture_pcm_prepare,
1449 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1453 static const struct hda_pcm_stream via_pcm_digital_playback = {
1457 /* NID is set in via_build_pcms */
1459 .open = via_dig_playback_pcm_open,
1460 .close = via_dig_playback_pcm_close,
1461 .prepare = via_dig_playback_pcm_prepare,
1462 .cleanup = via_dig_playback_pcm_cleanup
1466 static const struct hda_pcm_stream via_pcm_digital_capture = {
1473 * slave controls for virtual master
1475 static const char * const via_slave_pfxs[] = {
1476 "Front", "Surround", "Center", "LFE", "Side",
1477 "Headphone", "Speaker", "Bass Speaker",
1481 static int via_build_controls(struct hda_codec *codec)
1483 struct via_spec *spec = codec->spec;
1484 struct snd_kcontrol *kctl;
1487 spec->no_pin_power_ctl = 1;
1488 if (spec->set_widgets_power_state)
1489 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1492 for (i = 0; i < spec->num_mixers; i++) {
1493 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1498 if (spec->multiout.dig_out_nid) {
1499 err = snd_hda_create_spdif_out_ctls(codec,
1500 spec->multiout.dig_out_nid,
1501 spec->multiout.dig_out_nid);
1504 err = snd_hda_create_spdif_share_sw(codec,
1508 spec->multiout.share_spdif = 1;
1510 if (spec->dig_in_nid) {
1511 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1516 /* if we have no master control, let's create it */
1517 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1518 unsigned int vmaster_tlv[4];
1519 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1520 HDA_OUTPUT, vmaster_tlv);
1521 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1522 vmaster_tlv, via_slave_pfxs,
1527 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1528 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1529 NULL, via_slave_pfxs,
1535 /* assign Capture Source enums to NID */
1536 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1537 for (i = 0; kctl && i < kctl->count; i++) {
1538 if (!spec->mux_nids[i])
1540 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1545 via_free_kctls(codec); /* no longer needed */
1547 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1554 static int via_build_pcms(struct hda_codec *codec)
1556 struct via_spec *spec = codec->spec;
1557 struct hda_pcm *info = spec->pcm_rec;
1559 codec->num_pcms = 0;
1560 codec->pcm_info = info;
1562 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1563 snprintf(spec->stream_name_analog,
1564 sizeof(spec->stream_name_analog),
1565 "%s Analog", codec->chip_name);
1566 info->name = spec->stream_name_analog;
1568 if (spec->multiout.num_dacs) {
1569 if (!spec->stream_analog_playback)
1570 spec->stream_analog_playback =
1571 &via_pcm_analog_playback;
1572 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1573 *spec->stream_analog_playback;
1574 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1575 spec->multiout.dac_nids[0];
1576 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1577 spec->multiout.max_channels;
1578 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT
1579 && spec->autocfg.line_outs == 2)
1580 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
1584 if (!spec->stream_analog_capture) {
1585 if (spec->dyn_adc_switch)
1586 spec->stream_analog_capture =
1587 &via_pcm_dyn_adc_analog_capture;
1589 spec->stream_analog_capture =
1590 &via_pcm_analog_capture;
1592 if (spec->num_adc_nids) {
1593 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1594 *spec->stream_analog_capture;
1595 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1597 if (!spec->dyn_adc_switch)
1598 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1605 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1606 snprintf(spec->stream_name_digital,
1607 sizeof(spec->stream_name_digital),
1608 "%s Digital", codec->chip_name);
1609 info->name = spec->stream_name_digital;
1610 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1611 if (spec->multiout.dig_out_nid) {
1612 if (!spec->stream_digital_playback)
1613 spec->stream_digital_playback =
1614 &via_pcm_digital_playback;
1615 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1616 *spec->stream_digital_playback;
1617 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1618 spec->multiout.dig_out_nid;
1620 if (spec->dig_in_nid) {
1621 if (!spec->stream_digital_capture)
1622 spec->stream_digital_capture =
1623 &via_pcm_digital_capture;
1624 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1625 *spec->stream_digital_capture;
1626 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1633 if (spec->hp_dac_nid) {
1634 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1635 "%s HP", codec->chip_name);
1636 info->name = spec->stream_name_hp;
1637 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1638 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1646 static void via_free(struct hda_codec *codec)
1648 struct via_spec *spec = codec->spec;
1653 via_free_kctls(codec);
1654 vt1708_stop_hp_work(spec);
1655 kfree(spec->bind_cap_vol);
1656 kfree(spec->bind_cap_sw);
1660 /* mute/unmute outputs */
1661 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1662 hda_nid_t *pins, bool mute)
1665 for (i = 0; i < num_pins; i++) {
1666 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1667 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1668 if (parm & AC_PINCTL_IN_EN)
1671 parm &= ~AC_PINCTL_OUT_EN;
1673 parm |= AC_PINCTL_OUT_EN;
1674 snd_hda_set_pin_ctl(codec, pins[i], parm);
1678 /* mute internal speaker if line-out is plugged */
1679 static void via_line_automute(struct hda_codec *codec, int present)
1681 struct via_spec *spec = codec->spec;
1683 if (!spec->autocfg.speaker_outs)
1686 present = snd_hda_jack_detect(codec,
1687 spec->autocfg.line_out_pins[0]);
1688 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1689 spec->autocfg.speaker_pins,
1693 /* mute internal speaker if HP is plugged */
1694 static void via_hp_automute(struct hda_codec *codec)
1698 struct via_spec *spec = codec->spec;
1700 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
1701 (spec->codec_type != VT1708 || spec->vt1708_jack_detect) &&
1702 is_jack_detectable(codec, spec->autocfg.hp_pins[0]))
1703 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1705 if (spec->smart51_enabled)
1706 nums = spec->autocfg.line_outs + spec->smart51_nums;
1708 nums = spec->autocfg.line_outs;
1709 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1711 via_line_automute(codec, present);
1715 static int via_suspend(struct hda_codec *codec)
1717 struct via_spec *spec = codec->spec;
1718 vt1708_stop_hp_work(spec);
1720 if (spec->codec_type == VT1802) {
1721 /* Fix pop noise on headphones */
1723 for (i = 0; i < spec->autocfg.hp_outs; i++)
1724 snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0);
1732 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1734 struct via_spec *spec = codec->spec;
1735 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1742 static int via_init(struct hda_codec *codec);
1744 static const struct hda_codec_ops via_patch_ops = {
1745 .build_controls = via_build_controls,
1746 .build_pcms = via_build_pcms,
1749 .unsol_event = snd_hda_jack_unsol_event,
1751 .suspend = via_suspend,
1752 .check_power_status = via_check_power_status,
1756 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1758 struct via_spec *spec = codec->spec;
1761 for (i = 0; i < spec->multiout.num_dacs; i++) {
1762 if (spec->multiout.dac_nids[i] == dac)
1765 if (spec->hp_dac_nid == dac)
1770 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1771 hda_nid_t target_dac, int with_aa_mix,
1772 struct nid_path *path, int depth)
1774 struct via_spec *spec = codec->spec;
1778 if (nid == spec->aa_mix_nid) {
1781 with_aa_mix = 2; /* mark aa-mix is included */
1784 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1785 for (i = 0; i < nums; i++) {
1786 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1788 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1789 /* aa-mix is requested but not included? */
1790 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1794 if (depth >= MAX_NID_PATH_DEPTH)
1796 for (i = 0; i < nums; i++) {
1798 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1799 if (type == AC_WID_AUD_OUT)
1801 if (__parse_output_path(codec, conn[i], target_dac,
1802 with_aa_mix, path, depth + 1))
1808 path->path[path->depth] = conn[i];
1809 path->idx[path->depth] = i;
1810 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1811 path->multi[path->depth] = 1;
1816 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1817 hda_nid_t target_dac, int with_aa_mix,
1818 struct nid_path *path)
1820 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
1821 path->path[path->depth] = nid;
1823 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1824 path->depth, path->path[0], path->path[1],
1825 path->path[2], path->path[3], path->path[4]);
1831 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1833 struct via_spec *spec = codec->spec;
1834 const struct auto_pin_cfg *cfg = &spec->autocfg;
1838 spec->multiout.num_dacs = 0;
1839 spec->multiout.dac_nids = spec->private_dac_nids;
1840 for (i = 0; i < cfg->line_outs; i++) {
1842 nid = cfg->line_out_pins[i];
1845 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1846 dac = spec->out_path[i].path[0];
1847 if (!i && parse_output_path(codec, nid, dac, 1,
1848 &spec->out_mix_path))
1849 dac = spec->out_mix_path.path[0];
1851 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
1853 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1854 spec->out_path[0] = spec->out_mix_path;
1855 spec->out_mix_path.depth = 0;
1860 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1861 int chs, bool check_dac, struct nid_path *path)
1863 struct via_spec *spec = codec->spec;
1865 hda_nid_t dac, pin, sel, nid;
1868 dac = check_dac ? path->path[0] : 0;
1869 pin = path->path[path->depth - 1];
1870 sel = path->depth > 1 ? path->path[1] : 0;
1872 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1874 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1876 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1881 sprintf(name, "%s Playback Volume", pfx);
1882 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1883 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1886 path->vol_ctl = nid;
1889 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1891 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1893 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1898 sprintf(name, "%s Playback Switch", pfx);
1899 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1900 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1903 path->mute_ctl = nid;
1908 static void mangle_smart51(struct hda_codec *codec)
1910 struct via_spec *spec = codec->spec;
1911 struct auto_pin_cfg *cfg = &spec->autocfg;
1912 struct auto_pin_cfg_item *ins = cfg->inputs;
1913 int i, j, nums, attr;
1914 int pins[AUTO_CFG_MAX_INS];
1916 for (attr = INPUT_PIN_ATTR_LAST; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1918 for (i = 0; i < cfg->num_inputs; i++) {
1920 if (ins[i].type > AUTO_PIN_LINE_IN)
1922 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1923 if (snd_hda_get_input_pin_attr(def) != attr)
1925 for (j = 0; j < nums; j++)
1926 if (ins[pins[j]].type < ins[i].type) {
1927 memmove(pins + j + 1, pins + j,
1928 (nums - j) * sizeof(int));
1934 if (cfg->line_outs + nums < 3)
1936 for (i = 0; i < nums; i++) {
1937 hda_nid_t pin = ins[pins[i]].pin;
1938 spec->smart51_pins[spec->smart51_nums++] = pin;
1939 cfg->line_out_pins[cfg->line_outs++] = pin;
1940 if (cfg->line_outs == 3)
1947 static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1949 dst->vol_ctl = src->vol_ctl;
1950 dst->mute_ctl = src->mute_ctl;
1953 /* add playback controls from the parsed DAC table */
1954 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1956 struct via_spec *spec = codec->spec;
1957 struct auto_pin_cfg *cfg = &spec->autocfg;
1958 struct nid_path *path;
1959 static const char * const chname[4] = {
1960 "Front", "Surround", NULL /* "CLFE" */, "Side"
1966 old_line_outs = cfg->line_outs;
1967 if (cfg->line_outs == 1)
1968 mangle_smart51(codec);
1970 err = via_auto_fill_dac_nids(codec);
1974 if (spec->multiout.num_dacs < 3) {
1975 spec->smart51_nums = 0;
1976 cfg->line_outs = old_line_outs;
1978 for (i = 0; i < cfg->line_outs; i++) {
1980 pin = cfg->line_out_pins[i];
1981 dac = spec->multiout.dac_nids[i];
1984 path = spec->out_path + i;
1985 if (i == HDA_CLFE) {
1986 err = create_ch_ctls(codec, "Center", 1, true, path);
1989 err = create_ch_ctls(codec, "LFE", 2, true, path);
1993 const char *pfx = chname[i];
1994 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1995 cfg->line_outs <= 2)
1996 pfx = i ? "Bass Speaker" : "Speaker";
1997 err = create_ch_ctls(codec, pfx, 3, true, path);
2001 if (path != spec->out_path + i)
2002 copy_path_mixer_ctls(&spec->out_path[i], path);
2003 if (path == spec->out_path && spec->out_mix_path.depth)
2004 copy_path_mixer_ctls(&spec->out_mix_path, path);
2007 idx = get_connection_index(codec, spec->aa_mix_nid,
2008 spec->multiout.dac_nids[0]);
2010 /* add control to mixer */
2012 name = spec->out_mix_path.depth ?
2013 "PCM Loopback Playback Volume" : "PCM Playback Volume";
2014 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2015 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2019 name = spec->out_mix_path.depth ?
2020 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2021 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2022 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2028 cfg->line_outs = old_line_outs;
2033 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
2035 struct via_spec *spec = codec->spec;
2036 struct nid_path *path;
2043 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2044 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2045 if (i < spec->multiout.num_dacs &&
2046 parse_output_path(codec, pin,
2047 spec->multiout.dac_nids[i], 0,
2048 &spec->hp_indep_path)) {
2049 spec->hp_indep_shared = i;
2054 if (spec->hp_indep_path.depth) {
2055 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2056 if (!spec->hp_indep_shared)
2057 spec->hp_path = spec->hp_indep_path;
2059 /* optionally check front-path w/o AA-mix */
2060 if (!spec->hp_path.depth)
2061 parse_output_path(codec, pin,
2062 spec->multiout.dac_nids[HDA_FRONT], 0,
2065 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2066 1, &spec->hp_mix_path) && !spec->hp_path.depth)
2069 if (spec->hp_path.depth) {
2070 path = &spec->hp_path;
2073 path = &spec->hp_mix_path;
2076 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
2080 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2082 copy_path_mixer_ctls(&spec->hp_path, path);
2083 if (spec->hp_indep_path.depth)
2084 copy_path_mixer_ctls(&spec->hp_indep_path, path);
2088 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2090 struct via_spec *spec = codec->spec;
2091 struct nid_path *path;
2093 hda_nid_t pin, dac = 0;
2096 pin = spec->autocfg.speaker_pins[0];
2097 if (!spec->autocfg.speaker_outs || !pin)
2100 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
2101 dac = spec->speaker_path.path[0];
2103 parse_output_path(codec, pin,
2104 spec->multiout.dac_nids[HDA_FRONT], 0,
2105 &spec->speaker_path);
2106 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2107 1, &spec->speaker_mix_path) && !dac)
2110 /* no AA-path for front? */
2111 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2114 spec->speaker_dac_nid = dac;
2115 spec->multiout.extra_out_nid[0] = dac;
2117 path = &spec->speaker_path;
2120 path = &spec->speaker_mix_path;
2123 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2127 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2129 copy_path_mixer_ctls(&spec->speaker_path, path);
2133 #define via_aamix_ctl_info via_pin_power_ctl_info
2135 static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2136 struct snd_ctl_elem_value *ucontrol)
2138 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2139 struct via_spec *spec = codec->spec;
2140 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2144 static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2145 struct nid_path *nomix, struct nid_path *mix)
2148 activate_output_path(codec, nomix, false, false);
2149 activate_output_path(codec, mix, true, false);
2151 activate_output_path(codec, mix, false, false);
2152 activate_output_path(codec, nomix, true, false);
2156 static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2157 struct snd_ctl_elem_value *ucontrol)
2159 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2160 struct via_spec *spec = codec->spec;
2161 unsigned int val = ucontrol->value.enumerated.item[0];
2163 if (val == spec->aamix_mode)
2165 spec->aamix_mode = val;
2166 /* update front path */
2167 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2168 /* update HP path */
2169 if (!spec->hp_independent_mode) {
2170 update_aamix_paths(codec, val, &spec->hp_path,
2171 &spec->hp_mix_path);
2173 /* update speaker path */
2174 update_aamix_paths(codec, val, &spec->speaker_path,
2175 &spec->speaker_mix_path);
2179 static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2180 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2181 .name = "Loopback Mixing",
2182 .info = via_aamix_ctl_info,
2183 .get = via_aamix_ctl_get,
2184 .put = via_aamix_ctl_put,
2187 static int via_auto_create_loopback_switch(struct hda_codec *codec)
2189 struct via_spec *spec = codec->spec;
2191 if (!spec->aa_mix_nid)
2192 return 0; /* no loopback switching available */
2193 if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
2194 spec->speaker_path.depth))
2195 return 0; /* no loopback switching available */
2196 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2202 static int via_fill_adcs(struct hda_codec *codec)
2204 struct via_spec *spec = codec->spec;
2205 hda_nid_t nid = codec->start_nid;
2208 for (i = 0; i < codec->num_nodes; i++, nid++) {
2209 unsigned int wcaps = get_wcaps(codec, nid);
2210 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2212 if (wcaps & AC_WCAP_DIGITAL)
2214 if (!(wcaps & AC_WCAP_CONN_LIST))
2216 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2218 spec->adc_nids[spec->num_adc_nids++] = nid;
2223 /* input-src control */
2224 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2225 struct snd_ctl_elem_info *uinfo)
2227 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2228 struct via_spec *spec = codec->spec;
2230 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2232 uinfo->value.enumerated.items = spec->num_inputs;
2233 if (uinfo->value.enumerated.item >= spec->num_inputs)
2234 uinfo->value.enumerated.item = spec->num_inputs - 1;
2235 strcpy(uinfo->value.enumerated.name,
2236 spec->inputs[uinfo->value.enumerated.item].label);
2240 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2241 struct snd_ctl_elem_value *ucontrol)
2243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2244 struct via_spec *spec = codec->spec;
2245 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2247 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2251 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2252 struct snd_ctl_elem_value *ucontrol)
2254 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2255 struct via_spec *spec = codec->spec;
2256 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2260 cur = ucontrol->value.enumerated.item[0];
2261 if (cur < 0 || cur >= spec->num_inputs)
2263 if (spec->cur_mux[idx] == cur)
2265 spec->cur_mux[idx] = cur;
2266 if (spec->dyn_adc_switch) {
2267 int adc_idx = spec->inputs[cur].adc_idx;
2268 mux = spec->mux_nids[adc_idx];
2269 via_dyn_adc_pcm_resetup(codec, cur);
2271 mux = spec->mux_nids[idx];
2272 if (snd_BUG_ON(!mux))
2277 /* switch to D0 beofre change index */
2278 update_power_state(codec, mux, AC_PWRST_D0);
2279 snd_hda_codec_write(codec, mux, 0,
2280 AC_VERB_SET_CONNECT_SEL,
2281 spec->inputs[cur].mux_idx);
2284 /* update jack power state */
2285 set_widgets_power_state(codec);
2289 static const struct snd_kcontrol_new via_input_src_ctl = {
2290 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2291 /* The multiple "Capture Source" controls confuse alsamixer
2292 * So call somewhat different..
2294 /* .name = "Capture Source", */
2295 .name = "Input Source",
2296 .info = via_mux_enum_info,
2297 .get = via_mux_enum_get,
2298 .put = via_mux_enum_put,
2301 static int create_input_src_ctls(struct hda_codec *codec, int count)
2303 struct via_spec *spec = codec->spec;
2304 struct snd_kcontrol_new *knew;
2306 if (spec->num_inputs <= 1 || !count)
2307 return 0; /* no need for single src */
2309 knew = via_clone_control(spec, &via_input_src_ctl);
2312 knew->count = count;
2316 /* add the powersave loopback-list entry */
2317 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2319 struct hda_amp_list *list;
2321 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2323 list = spec->loopback_list + spec->num_loopbacks;
2325 list->dir = HDA_INPUT;
2327 spec->num_loopbacks++;
2328 spec->loopback.amplist = spec->loopback_list;
2331 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2334 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2337 /* add the input-route to the given pin */
2338 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2340 struct via_spec *spec = codec->spec;
2343 spec->inputs[spec->num_inputs].adc_idx = -1;
2344 spec->inputs[spec->num_inputs].pin = pin;
2345 for (c = 0; c < spec->num_adc_nids; c++) {
2346 if (spec->mux_nids[c]) {
2347 idx = get_connection_index(codec, spec->mux_nids[c],
2351 spec->inputs[spec->num_inputs].mux_idx = idx;
2353 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2356 spec->inputs[spec->num_inputs].adc_idx = c;
2357 /* Can primary ADC satisfy all inputs? */
2358 if (!spec->dyn_adc_switch &&
2359 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2360 snd_printd(KERN_INFO
2361 "via: dynamic ADC switching enabled\n");
2362 spec->dyn_adc_switch = 1;
2369 static int get_mux_nids(struct hda_codec *codec);
2371 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2372 static int parse_analog_inputs(struct hda_codec *codec)
2374 struct via_spec *spec = codec->spec;
2375 const struct auto_pin_cfg *cfg = &spec->autocfg;
2378 err = via_fill_adcs(codec);
2381 err = get_mux_nids(codec);
2385 /* fill all input-routes */
2386 for (i = 0; i < cfg->num_inputs; i++) {
2387 if (add_input_route(codec, cfg->inputs[i].pin))
2388 spec->inputs[spec->num_inputs++].label =
2389 hda_get_autocfg_input_label(codec, cfg, i);
2392 /* check for internal loopback recording */
2393 if (spec->aa_mix_nid &&
2394 add_input_route(codec, spec->aa_mix_nid))
2395 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2400 /* create analog-loopback volume/switch controls */
2401 static int create_loopback_ctls(struct hda_codec *codec)
2403 struct via_spec *spec = codec->spec;
2404 const struct auto_pin_cfg *cfg = &spec->autocfg;
2405 const char *prev_label = NULL;
2409 if (!spec->aa_mix_nid)
2412 for (i = 0; i < cfg->num_inputs; i++) {
2413 hda_nid_t pin = cfg->inputs[i].pin;
2414 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2416 if (prev_label && !strcmp(label, prev_label))
2421 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2423 err = via_new_analog_input(spec, label, type_idx,
2424 idx, spec->aa_mix_nid);
2427 add_loopback_list(spec, spec->aa_mix_nid, idx);
2430 /* remember the label for smart51 control */
2431 for (j = 0; j < spec->smart51_nums; j++) {
2432 if (spec->smart51_pins[j] == pin) {
2433 spec->smart51_idxs[j] = idx;
2434 spec->smart51_labels[j] = label;
2442 /* create mic-boost controls (if present) */
2443 static int create_mic_boost_ctls(struct hda_codec *codec)
2445 struct via_spec *spec = codec->spec;
2446 const struct auto_pin_cfg *cfg = &spec->autocfg;
2447 const char *prev_label = NULL;
2451 for (i = 0; i < cfg->num_inputs; i++) {
2452 hda_nid_t pin = cfg->inputs[i].pin;
2457 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2459 caps = query_amp_caps(codec, pin, HDA_INPUT);
2460 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2462 label = hda_get_autocfg_input_label(codec, cfg, i);
2463 if (prev_label && !strcmp(label, prev_label))
2468 snprintf(name, sizeof(name), "%s Boost Volume", label);
2469 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
2470 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2477 /* create capture and input-src controls for multiple streams */
2478 static int create_multi_adc_ctls(struct hda_codec *codec)
2480 struct via_spec *spec = codec->spec;
2483 /* create capture mixer elements */
2484 for (i = 0; i < spec->num_adc_nids; i++) {
2485 hda_nid_t adc = spec->adc_nids[i];
2486 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2487 "Capture Volume", i,
2488 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2492 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2493 "Capture Switch", i,
2494 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2500 /* input-source control */
2501 for (i = 0; i < spec->num_adc_nids; i++)
2502 if (!spec->mux_nids[i])
2504 err = create_input_src_ctls(codec, i);
2510 /* bind capture volume/switch */
2511 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2512 HDA_BIND_VOL("Capture Volume", 0);
2513 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2514 HDA_BIND_SW("Capture Switch", 0);
2516 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2517 struct hda_ctl_ops *ops)
2519 struct hda_bind_ctls *ctl;
2522 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2526 for (i = 0; i < spec->num_adc_nids; i++)
2528 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2533 /* create capture and input-src controls for dynamic ADC-switch case */
2534 static int create_dyn_adc_ctls(struct hda_codec *codec)
2536 struct via_spec *spec = codec->spec;
2537 struct snd_kcontrol_new *knew;
2540 /* set up the bind capture ctls */
2541 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2544 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2548 /* create capture mixer elements */
2549 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2552 knew->private_value = (long)spec->bind_cap_vol;
2554 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2557 knew->private_value = (long)spec->bind_cap_sw;
2559 /* input-source control */
2560 err = create_input_src_ctls(codec, 1);
2566 /* parse and create capture-related stuff */
2567 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2569 struct via_spec *spec = codec->spec;
2572 err = parse_analog_inputs(codec);
2575 if (spec->dyn_adc_switch)
2576 err = create_dyn_adc_ctls(codec);
2578 err = create_multi_adc_ctls(codec);
2581 err = create_loopback_ctls(codec);
2584 err = create_mic_boost_ctls(codec);
2590 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2592 unsigned int def_conf;
2593 unsigned char seqassoc;
2595 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2596 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2597 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2598 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2599 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2600 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2601 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2607 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2608 struct snd_ctl_elem_value *ucontrol)
2610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2611 struct via_spec *spec = codec->spec;
2613 if (spec->codec_type != VT1708)
2615 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2619 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2620 struct snd_ctl_elem_value *ucontrol)
2622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2623 struct via_spec *spec = codec->spec;
2626 if (spec->codec_type != VT1708)
2628 val = !!ucontrol->value.integer.value[0];
2629 if (spec->vt1708_jack_detect == val)
2631 spec->vt1708_jack_detect = val;
2632 if (spec->vt1708_jack_detect &&
2633 snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
2634 mute_aa_path(codec, 1);
2635 notify_aa_path_ctls(codec);
2637 via_hp_automute(codec);
2638 vt1708_update_hp_work(spec);
2642 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2643 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2644 .name = "Jack Detect",
2646 .info = snd_ctl_boolean_mono_info,
2647 .get = vt1708_jack_detect_get,
2648 .put = vt1708_jack_detect_put,
2651 static void fill_dig_outs(struct hda_codec *codec);
2652 static void fill_dig_in(struct hda_codec *codec);
2654 static int via_parse_auto_config(struct hda_codec *codec)
2656 struct via_spec *spec = codec->spec;
2659 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2662 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2665 err = via_auto_create_multi_out_ctls(codec);
2668 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2671 err = via_auto_create_speaker_ctls(codec);
2674 err = via_auto_create_loopback_switch(codec);
2677 err = via_auto_create_analog_input_ctls(codec);
2681 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2683 fill_dig_outs(codec);
2686 if (spec->kctls.list)
2687 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2690 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
2691 err = via_hp_build(codec);
2696 err = via_smart51_build(codec);
2700 /* assign slave outs */
2701 if (spec->slave_dig_outs[0])
2702 codec->slave_dig_outs = spec->slave_dig_outs;
2707 static void via_auto_init_dig_outs(struct hda_codec *codec)
2709 struct via_spec *spec = codec->spec;
2710 if (spec->multiout.dig_out_nid)
2711 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2712 if (spec->slave_dig_outs[0])
2713 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2716 static void via_auto_init_dig_in(struct hda_codec *codec)
2718 struct via_spec *spec = codec->spec;
2719 if (!spec->dig_in_nid)
2721 snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN);
2724 static void via_jack_output_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2726 set_widgets_power_state(codec);
2727 via_hp_automute(codec);
2730 static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl)
2732 set_widgets_power_state(codec);
2735 /* initialize the unsolicited events */
2736 static void via_auto_init_unsol_event(struct hda_codec *codec)
2738 struct via_spec *spec = codec->spec;
2739 struct auto_pin_cfg *cfg = &spec->autocfg;
2742 hda_jack_callback cb;
2744 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2745 snd_hda_jack_detect_enable_callback(codec, cfg->hp_pins[0],
2746 VIA_HP_EVENT | VIA_JACK_EVENT,
2747 via_jack_output_event);
2749 if (cfg->speaker_pins[0])
2750 ev = VIA_LINE_EVENT;
2753 cb = ev ? via_jack_output_event : via_jack_powerstate_event;
2755 for (i = 0; i < cfg->line_outs; i++) {
2756 if (cfg->line_out_pins[i] &&
2757 is_jack_detectable(codec, cfg->line_out_pins[i]))
2758 snd_hda_jack_detect_enable_callback(codec, cfg->line_out_pins[i],
2759 ev | VIA_JACK_EVENT, cb);
2762 for (i = 0; i < cfg->num_inputs; i++) {
2763 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2764 snd_hda_jack_detect_enable_callback(codec, cfg->inputs[i].pin,
2766 via_jack_powerstate_event);
2770 static int via_init(struct hda_codec *codec)
2772 struct via_spec *spec = codec->spec;
2775 for (i = 0; i < spec->num_iverbs; i++)
2776 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2778 /* init power states */
2779 set_widgets_power_state(codec);
2780 __analog_low_current_mode(codec, true);
2782 via_auto_init_multi_out(codec);
2783 via_auto_init_hp_out(codec);
2784 via_auto_init_speaker_out(codec);
2785 via_auto_init_analog_input(codec);
2786 via_auto_init_dig_outs(codec);
2787 via_auto_init_dig_in(codec);
2789 via_auto_init_unsol_event(codec);
2791 via_hp_automute(codec);
2792 vt1708_update_hp_work(spec);
2797 static void vt1708_update_hp_jack_state(struct work_struct *work)
2799 struct via_spec *spec = container_of(work, struct via_spec,
2800 vt1708_hp_work.work);
2801 if (spec->codec_type != VT1708)
2803 snd_hda_jack_set_dirty_all(spec->codec);
2804 /* if jack state toggled */
2805 if (spec->vt1708_hp_present
2806 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2807 spec->vt1708_hp_present ^= 1;
2808 via_hp_automute(spec->codec);
2810 if (spec->vt1708_jack_detect)
2811 schedule_delayed_work(&spec->vt1708_hp_work,
2812 msecs_to_jiffies(100));
2815 static int get_mux_nids(struct hda_codec *codec)
2817 struct via_spec *spec = codec->spec;
2818 hda_nid_t nid, conn[8];
2822 for (i = 0; i < spec->num_adc_nids; i++) {
2823 nid = spec->adc_nids[i];
2825 type = get_wcaps_type(get_wcaps(codec, nid));
2826 if (type == AC_WID_PIN)
2828 n = snd_hda_get_connections(codec, nid, conn,
2833 spec->mux_nids[i] = nid;
2842 static int patch_vt1708(struct hda_codec *codec)
2844 struct via_spec *spec;
2847 /* create a codec specific record */
2848 spec = via_new_spec(codec);
2852 spec->aa_mix_nid = 0x17;
2854 /* Add HP and CD pin config connect bit re-config action */
2855 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2856 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2858 /* automatic parse from the BIOS config */
2859 err = via_parse_auto_config(codec);
2865 /* add jack detect on/off control */
2866 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2869 /* disable 32bit format on VT1708 */
2870 if (codec->vendor_id == 0x11061708)
2871 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2873 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2875 codec->patch_ops = via_patch_ops;
2877 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2881 static int patch_vt1709(struct hda_codec *codec)
2883 struct via_spec *spec;
2886 /* create a codec specific record */
2887 spec = via_new_spec(codec);
2891 spec->aa_mix_nid = 0x18;
2893 err = via_parse_auto_config(codec);
2899 codec->patch_ops = via_patch_ops;
2904 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2906 struct via_spec *spec = codec->spec;
2910 if ((spec->codec_type != VT1708B_4CH) &&
2911 (codec->vendor_id != 0x11064397))
2914 /* SW0 (17h) = stereo mixer */
2916 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2917 == ((spec->codec_type == VT1708S) ? 5 : 0));
2919 /* PW 1/2/5 (1ah/1bh/1eh) */
2921 set_pin_power_state(codec, 0x1a, &parm);
2922 set_pin_power_state(codec, 0x1b, &parm);
2923 set_pin_power_state(codec, 0x1e, &parm);
2926 /* SW0 (17h), AIW 0/1 (13h/14h) */
2927 update_power_state(codec, 0x17, parm);
2928 update_power_state(codec, 0x13, parm);
2929 update_power_state(codec, 0x14, parm);
2932 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2934 set_pin_power_state(codec, 0x19, &parm);
2935 if (spec->smart51_enabled)
2936 set_pin_power_state(codec, 0x1b, &parm);
2937 update_power_state(codec, 0x18, parm);
2938 update_power_state(codec, 0x11, parm);
2940 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2943 set_pin_power_state(codec, 0x22, &parm);
2944 if (spec->smart51_enabled)
2945 set_pin_power_state(codec, 0x1a, &parm);
2946 update_power_state(codec, 0x26, parm);
2947 update_power_state(codec, 0x24, parm);
2948 } else if (codec->vendor_id == 0x11064397) {
2949 /* PW7(23h), SW2(27h), AOW2(25h) */
2951 set_pin_power_state(codec, 0x23, &parm);
2952 if (spec->smart51_enabled)
2953 set_pin_power_state(codec, 0x1a, &parm);
2954 update_power_state(codec, 0x27, parm);
2955 update_power_state(codec, 0x25, parm);
2958 /* PW 3/4/7 (1ch/1dh/23h) */
2960 /* force to D0 for internal Speaker */
2961 set_pin_power_state(codec, 0x1c, &parm);
2962 set_pin_power_state(codec, 0x1d, &parm);
2964 set_pin_power_state(codec, 0x23, &parm);
2966 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2967 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
2968 update_power_state(codec, 0x10, parm);
2970 update_power_state(codec, 0x25, parm);
2971 update_power_state(codec, 0x27, parm);
2972 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2973 update_power_state(codec, 0x25, parm);
2976 static int patch_vt1708S(struct hda_codec *codec);
2977 static int patch_vt1708B(struct hda_codec *codec)
2979 struct via_spec *spec;
2982 if (get_codec_type(codec) == VT1708BCE)
2983 return patch_vt1708S(codec);
2985 /* create a codec specific record */
2986 spec = via_new_spec(codec);
2990 spec->aa_mix_nid = 0x16;
2992 /* automatic parse from the BIOS config */
2993 err = via_parse_auto_config(codec);
2999 codec->patch_ops = via_patch_ops;
3001 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3006 /* Patch for VT1708S */
3007 static const struct hda_verb vt1708S_init_verbs[] = {
3008 /* Enable Mic Boost Volume backdoor */
3010 /* don't bybass mixer */
3015 /* fill out digital output widgets; one for master and one for slave outputs */
3016 static void fill_dig_outs(struct hda_codec *codec)
3018 struct via_spec *spec = codec->spec;
3021 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3025 nid = spec->autocfg.dig_out_pins[i];
3028 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3031 if (!spec->multiout.dig_out_nid)
3032 spec->multiout.dig_out_nid = nid;
3034 spec->slave_dig_outs[0] = nid;
3035 break; /* at most two dig outs */
3040 static void fill_dig_in(struct hda_codec *codec)
3042 struct via_spec *spec = codec->spec;
3046 if (!spec->autocfg.dig_in_pin)
3049 dig_nid = codec->start_nid;
3050 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3051 unsigned int wcaps = get_wcaps(codec, dig_nid);
3052 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3054 if (!(wcaps & AC_WCAP_DIGITAL))
3056 if (!(wcaps & AC_WCAP_CONN_LIST))
3058 err = get_connection_index(codec, dig_nid,
3059 spec->autocfg.dig_in_pin);
3061 spec->dig_in_nid = dig_nid;
3067 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3068 int offset, int num_steps, int step_size)
3070 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3071 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3072 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3073 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3074 (0 << AC_AMPCAP_MUTE_SHIFT));
3077 static int patch_vt1708S(struct hda_codec *codec)
3079 struct via_spec *spec;
3082 /* create a codec specific record */
3083 spec = via_new_spec(codec);
3087 spec->aa_mix_nid = 0x16;
3088 override_mic_boost(codec, 0x1a, 0, 3, 40);
3089 override_mic_boost(codec, 0x1e, 0, 3, 40);
3091 /* automatic parse from the BIOS config */
3092 err = via_parse_auto_config(codec);
3098 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
3100 codec->patch_ops = via_patch_ops;
3102 /* correct names for VT1708BCE */
3103 if (get_codec_type(codec) == VT1708BCE) {
3104 kfree(codec->chip_name);
3105 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3106 snprintf(codec->bus->card->mixername,
3107 sizeof(codec->bus->card->mixername),
3108 "%s %s", codec->vendor_name, codec->chip_name);
3110 /* correct names for VT1705 */
3111 if (codec->vendor_id == 0x11064397) {
3112 kfree(codec->chip_name);
3113 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3114 snprintf(codec->bus->card->mixername,
3115 sizeof(codec->bus->card->mixername),
3116 "%s %s", codec->vendor_name, codec->chip_name);
3118 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3122 /* Patch for VT1702 */
3124 static const struct hda_verb vt1702_init_verbs[] = {
3132 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3134 int imux_is_smixer =
3135 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3138 /* PW 1/2/5 (14h/15h/18h) */
3140 set_pin_power_state(codec, 0x14, &parm);
3141 set_pin_power_state(codec, 0x15, &parm);
3142 set_pin_power_state(codec, 0x18, &parm);
3144 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3145 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3146 update_power_state(codec, 0x13, parm);
3147 update_power_state(codec, 0x12, parm);
3148 update_power_state(codec, 0x1f, parm);
3149 update_power_state(codec, 0x20, parm);
3152 /* PW 3/4 (16h/17h) */
3154 set_pin_power_state(codec, 0x17, &parm);
3155 set_pin_power_state(codec, 0x16, &parm);
3156 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3157 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
3158 update_power_state(codec, 0x10, parm);
3159 update_power_state(codec, 0x1d, parm);
3162 static int patch_vt1702(struct hda_codec *codec)
3164 struct via_spec *spec;
3167 /* create a codec specific record */
3168 spec = via_new_spec(codec);
3172 spec->aa_mix_nid = 0x1a;
3174 /* limit AA path volume to 0 dB */
3175 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3176 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3177 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3178 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3179 (1 << AC_AMPCAP_MUTE_SHIFT));
3181 /* automatic parse from the BIOS config */
3182 err = via_parse_auto_config(codec);
3188 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
3190 codec->patch_ops = via_patch_ops;
3192 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
3196 /* Patch for VT1718S */
3198 static const struct hda_verb vt1718S_init_verbs[] = {
3199 /* Enable MW0 adjust Gain 5 */
3201 /* Enable Boost Volume backdoor */
3207 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3209 struct via_spec *spec = codec->spec;
3211 unsigned int parm, parm2;
3212 /* MUX6 (1eh) = stereo mixer */
3214 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3216 /* PW 5/6/7 (29h/2ah/2bh) */
3218 set_pin_power_state(codec, 0x29, &parm);
3219 set_pin_power_state(codec, 0x2a, &parm);
3220 set_pin_power_state(codec, 0x2b, &parm);
3223 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3224 update_power_state(codec, 0x1e, parm);
3225 update_power_state(codec, 0x1f, parm);
3226 update_power_state(codec, 0x10, parm);
3227 update_power_state(codec, 0x11, parm);
3230 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3232 set_pin_power_state(codec, 0x27, &parm);
3233 update_power_state(codec, 0x1a, parm);
3234 parm2 = parm; /* for pin 0x0b */
3236 /* PW2 (26h), AOW2 (ah) */
3238 set_pin_power_state(codec, 0x26, &parm);
3239 if (spec->smart51_enabled)
3240 set_pin_power_state(codec, 0x2b, &parm);
3241 update_power_state(codec, 0xa, parm);
3243 /* PW0 (24h), AOW0 (8h) */
3245 set_pin_power_state(codec, 0x24, &parm);
3246 if (!spec->hp_independent_mode) /* check for redirected HP */
3247 set_pin_power_state(codec, 0x28, &parm);
3248 update_power_state(codec, 0x8, parm);
3249 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
3251 update_power_state(codec, 0xb, parm);
3252 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3253 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
3255 /* PW1 (25h), AOW1 (9h) */
3257 set_pin_power_state(codec, 0x25, &parm);
3258 if (spec->smart51_enabled)
3259 set_pin_power_state(codec, 0x2a, &parm);
3260 update_power_state(codec, 0x9, parm);
3262 if (spec->hp_independent_mode) {
3263 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3265 set_pin_power_state(codec, 0x28, &parm);
3266 update_power_state(codec, 0x1b, parm);
3267 update_power_state(codec, 0x34, parm);
3268 update_power_state(codec, 0xc, parm);
3272 /* Add a connection to the primary DAC from AA-mixer for some codecs
3273 * This isn't listed from the raw info, but the chip has a secret connection.
3275 static int add_secret_dac_path(struct hda_codec *codec)
3277 struct via_spec *spec = codec->spec;
3282 if (!spec->aa_mix_nid)
3284 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3285 ARRAY_SIZE(conn) - 1);
3286 for (i = 0; i < nums; i++) {
3287 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3291 /* find the primary DAC and add to the connection list */
3292 nid = codec->start_nid;
3293 for (i = 0; i < codec->num_nodes; i++, nid++) {
3294 unsigned int caps = get_wcaps(codec, nid);
3295 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3296 !(caps & AC_WCAP_DIGITAL)) {
3298 return snd_hda_override_conn_list(codec,
3307 static int patch_vt1718S(struct hda_codec *codec)
3309 struct via_spec *spec;
3312 /* create a codec specific record */
3313 spec = via_new_spec(codec);
3317 spec->aa_mix_nid = 0x21;
3318 override_mic_boost(codec, 0x2b, 0, 3, 40);
3319 override_mic_boost(codec, 0x29, 0, 3, 40);
3320 add_secret_dac_path(codec);
3322 /* automatic parse from the BIOS config */
3323 err = via_parse_auto_config(codec);
3329 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3331 codec->patch_ops = via_patch_ops;
3333 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3338 /* Patch for VT1716S */
3340 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3341 struct snd_ctl_elem_info *uinfo)
3343 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3345 uinfo->value.integer.min = 0;
3346 uinfo->value.integer.max = 1;
3350 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3351 struct snd_ctl_elem_value *ucontrol)
3353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3356 index = snd_hda_codec_read(codec, 0x26, 0,
3357 AC_VERB_GET_CONNECT_SEL, 0);
3359 *ucontrol->value.integer.value = index;
3364 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3365 struct snd_ctl_elem_value *ucontrol)
3367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3368 struct via_spec *spec = codec->spec;
3369 int index = *ucontrol->value.integer.value;
3371 snd_hda_codec_write(codec, 0x26, 0,
3372 AC_VERB_SET_CONNECT_SEL, index);
3373 spec->dmic_enabled = index;
3374 set_widgets_power_state(codec);
3378 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3379 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3381 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3382 .name = "Digital Mic Capture Switch",
3383 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3385 .info = vt1716s_dmic_info,
3386 .get = vt1716s_dmic_get,
3387 .put = vt1716s_dmic_put,
3393 /* mono-out mixer elements */
3394 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3395 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3399 static const struct hda_verb vt1716S_init_verbs[] = {
3400 /* Enable Boost Volume backdoor */
3402 /* don't bybass mixer */
3404 /* Enable mono output */
3409 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3411 struct via_spec *spec = codec->spec;
3414 unsigned int mono_out, present;
3415 /* SW0 (17h) = stereo mixer */
3417 (snd_hda_codec_read(codec, 0x17, 0,
3418 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3420 /* PW 1/2/5 (1ah/1bh/1eh) */
3422 set_pin_power_state(codec, 0x1a, &parm);
3423 set_pin_power_state(codec, 0x1b, &parm);
3424 set_pin_power_state(codec, 0x1e, &parm);
3427 /* SW0 (17h), AIW0(13h) */
3428 update_power_state(codec, 0x17, parm);
3429 update_power_state(codec, 0x13, parm);
3432 set_pin_power_state(codec, 0x1e, &parm);
3434 if (spec->dmic_enabled)
3435 set_pin_power_state(codec, 0x22, &parm);
3437 update_power_state(codec, 0x22, AC_PWRST_D3);
3439 /* SW2(26h), AIW1(14h) */
3440 update_power_state(codec, 0x26, parm);
3441 update_power_state(codec, 0x14, parm);
3444 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3446 set_pin_power_state(codec, 0x19, &parm);
3447 /* Smart 5.1 PW2(1bh) */
3448 if (spec->smart51_enabled)
3449 set_pin_power_state(codec, 0x1b, &parm);
3450 update_power_state(codec, 0x18, parm);
3451 update_power_state(codec, 0x11, parm);
3453 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3455 set_pin_power_state(codec, 0x23, &parm);
3456 /* Smart 5.1 PW1(1ah) */
3457 if (spec->smart51_enabled)
3458 set_pin_power_state(codec, 0x1a, &parm);
3459 update_power_state(codec, 0x27, parm);
3461 /* Smart 5.1 PW5(1eh) */
3462 if (spec->smart51_enabled)
3463 set_pin_power_state(codec, 0x1e, &parm);
3464 update_power_state(codec, 0x25, parm);
3467 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3468 present = snd_hda_jack_detect(codec, 0x1c);
3473 present = snd_hda_jack_detect(codec, 0x1d);
3474 if (!spec->hp_independent_mode && present)
3479 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3480 update_power_state(codec, 0x28, parm);
3481 update_power_state(codec, 0x29, parm);
3482 update_power_state(codec, 0x2a, parm);
3484 /* PW 3/4 (1ch/1dh) */
3486 set_pin_power_state(codec, 0x1c, &parm);
3487 set_pin_power_state(codec, 0x1d, &parm);
3488 /* HP Independent Mode, power on AOW3 */
3489 if (spec->hp_independent_mode)
3490 update_power_state(codec, 0x25, parm);
3492 /* force to D0 for internal Speaker */
3493 /* MW0 (16h), AOW0 (10h) */
3494 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
3495 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
3498 static int patch_vt1716S(struct hda_codec *codec)
3500 struct via_spec *spec;
3503 /* create a codec specific record */
3504 spec = via_new_spec(codec);
3508 spec->aa_mix_nid = 0x16;
3509 override_mic_boost(codec, 0x1a, 0, 3, 40);
3510 override_mic_boost(codec, 0x1e, 0, 3, 40);
3512 /* automatic parse from the BIOS config */
3513 err = via_parse_auto_config(codec);
3519 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3521 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3524 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3526 codec->patch_ops = via_patch_ops;
3528 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3534 static const struct hda_verb vt2002P_init_verbs[] = {
3535 /* Class-D speaker related verbs */
3539 /* Enable Boost Volume backdoor */
3541 /* Enable AOW0 to MW9 */
3546 static const struct hda_verb vt1802_init_verbs[] = {
3547 /* Enable Boost Volume backdoor */
3549 /* Enable AOW0 to MW9 */
3554 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3556 struct via_spec *spec = codec->spec;
3559 unsigned int present;
3560 /* MUX9 (1eh) = stereo mixer */
3562 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3564 /* PW 5/6/7 (29h/2ah/2bh) */
3566 set_pin_power_state(codec, 0x29, &parm);
3567 set_pin_power_state(codec, 0x2a, &parm);
3568 set_pin_power_state(codec, 0x2b, &parm);
3570 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3571 update_power_state(codec, 0x1e, parm);
3572 update_power_state(codec, 0x1f, parm);
3573 update_power_state(codec, 0x10, parm);
3574 update_power_state(codec, 0x11, parm);
3578 update_power_state(codec, 0x8, parm);
3580 if (spec->codec_type == VT1802) {
3581 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3583 set_pin_power_state(codec, 0x28, &parm);
3584 update_power_state(codec, 0x18, parm);
3585 update_power_state(codec, 0x38, parm);
3587 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3589 set_pin_power_state(codec, 0x26, &parm);
3590 update_power_state(codec, 0x1c, parm);
3591 update_power_state(codec, 0x37, parm);
3594 if (spec->codec_type == VT1802) {
3595 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3597 set_pin_power_state(codec, 0x25, &parm);
3598 update_power_state(codec, 0x15, parm);
3599 update_power_state(codec, 0x35, parm);
3601 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3603 set_pin_power_state(codec, 0x25, &parm);
3604 update_power_state(codec, 0x19, parm);
3605 update_power_state(codec, 0x35, parm);
3608 if (spec->hp_independent_mode)
3609 update_power_state(codec, 0x9, AC_PWRST_D0);
3612 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3613 present = snd_hda_jack_detect(codec, 0x25);
3616 set_pin_power_state(codec, 0x24, &parm);
3617 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3618 if (spec->codec_type == VT1802)
3619 update_power_state(codec, 0x14, parm);
3621 update_power_state(codec, 0x18, parm);
3622 update_power_state(codec, 0x34, parm);
3625 present = snd_hda_jack_detect(codec, 0x26);
3627 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3628 if (spec->codec_type == VT1802) {
3629 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3630 update_power_state(codec, 0x33, parm);
3631 update_power_state(codec, 0x1c, parm);
3632 update_power_state(codec, 0x3c, parm);
3634 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3635 update_power_state(codec, 0x31, parm);
3636 update_power_state(codec, 0x17, parm);
3637 update_power_state(codec, 0x3b, parm);
3640 if (imux_is_smixer || !is_aa_path_mute(codec))
3641 update_power_state(codec, 0x21, AC_PWRST_D0);
3643 update_power_state(codec, 0x21, AC_PWRST_D3);
3650 VIA_FIXUP_INTMIC_BOOST,
3654 static void via_fixup_intmic_boost(struct hda_codec *codec,
3655 const struct hda_fixup *fix, int action)
3657 if (action == HDA_FIXUP_ACT_PRE_PROBE)
3658 override_mic_boost(codec, 0x30, 0, 2, 40);
3661 static const struct hda_fixup via_fixups[] = {
3662 [VIA_FIXUP_INTMIC_BOOST] = {
3663 .type = HDA_FIXUP_FUNC,
3664 .v.func = via_fixup_intmic_boost,
3666 [VIA_FIXUP_ASUS_G75] = {
3667 .type = HDA_FIXUP_PINS,
3668 .v.pins = (const struct hda_pintbl[]) {
3669 /* set 0x24 and 0x33 as speakers */
3670 { 0x24, 0x991301f0 },
3671 { 0x33, 0x991301f1 }, /* subwoofer */
3677 static const struct snd_pci_quirk vt2002p_fixups[] = {
3678 SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
3679 SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
3683 /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
3684 * Replace this with mixer NID 0x1c
3686 static void fix_vt1802_connections(struct hda_codec *codec)
3688 static hda_nid_t conn_24[] = { 0x14, 0x1c };
3689 static hda_nid_t conn_33[] = { 0x1c };
3691 snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
3692 snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
3695 /* patch for vt2002P */
3696 static int patch_vt2002P(struct hda_codec *codec)
3698 struct via_spec *spec;
3701 /* create a codec specific record */
3702 spec = via_new_spec(codec);
3706 spec->aa_mix_nid = 0x21;
3707 override_mic_boost(codec, 0x2b, 0, 3, 40);
3708 override_mic_boost(codec, 0x29, 0, 3, 40);
3709 if (spec->codec_type == VT1802)
3710 fix_vt1802_connections(codec);
3711 add_secret_dac_path(codec);
3713 snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
3714 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3716 /* automatic parse from the BIOS config */
3717 err = via_parse_auto_config(codec);
3723 if (spec->codec_type == VT1802)
3724 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3726 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3728 codec->patch_ops = via_patch_ops;
3730 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3736 static const struct hda_verb vt1812_init_verbs[] = {
3737 /* Enable Boost Volume backdoor */
3739 /* Enable AOW0 to MW9 */
3744 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3746 struct via_spec *spec = codec->spec;
3748 unsigned int present;
3750 /* PW 5/6/7 (29h/2ah/2bh) */
3752 set_pin_power_state(codec, 0x29, &parm);
3753 set_pin_power_state(codec, 0x2a, &parm);
3754 set_pin_power_state(codec, 0x2b, &parm);
3756 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3757 update_power_state(codec, 0x1e, parm);
3758 update_power_state(codec, 0x1f, parm);
3759 update_power_state(codec, 0x10, parm);
3760 update_power_state(codec, 0x11, parm);
3764 update_power_state(codec, 0x8, AC_PWRST_D0);
3766 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3768 set_pin_power_state(codec, 0x28, &parm);
3769 update_power_state(codec, 0x18, parm);
3770 update_power_state(codec, 0x38, parm);
3772 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3774 set_pin_power_state(codec, 0x25, &parm);
3775 update_power_state(codec, 0x15, parm);
3776 update_power_state(codec, 0x35, parm);
3777 if (spec->hp_independent_mode)
3778 update_power_state(codec, 0x9, AC_PWRST_D0);
3780 /* Internal Speaker */
3781 /* PW0 (24h), MW0(14h), MUX0(34h) */
3782 present = snd_hda_jack_detect(codec, 0x25);
3785 set_pin_power_state(codec, 0x24, &parm);
3787 update_power_state(codec, 0x14, AC_PWRST_D3);
3788 update_power_state(codec, 0x34, AC_PWRST_D3);
3790 update_power_state(codec, 0x14, AC_PWRST_D0);
3791 update_power_state(codec, 0x34, AC_PWRST_D0);
3796 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3797 present = snd_hda_jack_detect(codec, 0x28);
3800 set_pin_power_state(codec, 0x31, &parm);
3802 update_power_state(codec, 0x1c, AC_PWRST_D3);
3803 update_power_state(codec, 0x3c, AC_PWRST_D3);
3804 update_power_state(codec, 0x3e, AC_PWRST_D3);
3806 update_power_state(codec, 0x1c, AC_PWRST_D0);
3807 update_power_state(codec, 0x3c, AC_PWRST_D0);
3808 update_power_state(codec, 0x3e, AC_PWRST_D0);
3811 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3813 set_pin_power_state(codec, 0x33, &parm);
3814 update_power_state(codec, 0x1d, parm);
3815 update_power_state(codec, 0x3d, parm);
3819 /* patch for vt1812 */
3820 static int patch_vt1812(struct hda_codec *codec)
3822 struct via_spec *spec;
3825 /* create a codec specific record */
3826 spec = via_new_spec(codec);
3830 spec->aa_mix_nid = 0x21;
3831 override_mic_boost(codec, 0x2b, 0, 3, 40);
3832 override_mic_boost(codec, 0x29, 0, 3, 40);
3833 add_secret_dac_path(codec);
3835 /* automatic parse from the BIOS config */
3836 err = via_parse_auto_config(codec);
3842 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3844 codec->patch_ops = via_patch_ops;
3846 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3850 /* patch for vt3476 */
3852 static const struct hda_verb vt3476_init_verbs[] = {
3853 /* Enable DMic 8/16/32K */
3855 /* Enable Boost Volume backdoor */
3857 /* Enable AOW-MW9 path */
3862 static void set_widgets_power_state_vt3476(struct hda_codec *codec)
3864 struct via_spec *spec = codec->spec;
3866 unsigned int parm, parm2;
3867 /* MUX10 (1eh) = stereo mixer */
3869 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
3871 /* PW 5/6/7 (29h/2ah/2bh) */
3873 set_pin_power_state(codec, 0x29, &parm);
3874 set_pin_power_state(codec, 0x2a, &parm);
3875 set_pin_power_state(codec, 0x2b, &parm);
3878 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3879 update_power_state(codec, 0x1e, parm);
3880 update_power_state(codec, 0x1f, parm);
3881 update_power_state(codec, 0x10, parm);
3882 update_power_state(codec, 0x11, parm);
3885 /* PW3 (27h), MW3(37h), AOW3 (bh) */
3886 if (spec->codec_type == VT1705CF) {
3888 update_power_state(codec, 0x27, parm);
3889 update_power_state(codec, 0x37, parm);
3892 set_pin_power_state(codec, 0x27, &parm);
3893 update_power_state(codec, 0x37, parm);
3896 /* PW2 (26h), MW2(36h), AOW2 (ah) */
3898 set_pin_power_state(codec, 0x26, &parm);
3899 update_power_state(codec, 0x36, parm);
3900 if (spec->smart51_enabled) {
3901 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
3902 set_pin_power_state(codec, 0x2b, &parm);
3903 update_power_state(codec, 0x3b, parm);
3904 update_power_state(codec, 0x1b, parm);
3906 update_conv_power_state(codec, 0xa, parm, 2);
3908 /* PW1 (25h), MW1(35h), AOW1 (9h) */
3910 set_pin_power_state(codec, 0x25, &parm);
3911 update_power_state(codec, 0x35, parm);
3912 if (spec->smart51_enabled) {
3913 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
3914 set_pin_power_state(codec, 0x2a, &parm);
3915 update_power_state(codec, 0x3a, parm);
3916 update_power_state(codec, 0x1a, parm);
3918 update_conv_power_state(codec, 0x9, parm, 1);
3920 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
3922 set_pin_power_state(codec, 0x28, &parm);
3923 update_power_state(codec, 0x38, parm);
3924 update_power_state(codec, 0x18, parm);
3925 if (spec->hp_independent_mode)
3926 update_conv_power_state(codec, 0xb, parm, 3);
3927 parm2 = parm; /* for pin 0x0b */
3929 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
3931 set_pin_power_state(codec, 0x24, &parm);
3932 update_power_state(codec, 0x34, parm);
3933 if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3)
3935 update_conv_power_state(codec, 0x8, parm, 0);
3936 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3937 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
3940 static int patch_vt3476(struct hda_codec *codec)
3942 struct via_spec *spec;
3945 /* create a codec specific record */
3946 spec = via_new_spec(codec);
3950 spec->aa_mix_nid = 0x3f;
3951 add_secret_dac_path(codec);
3953 /* automatic parse from the BIOS config */
3954 err = via_parse_auto_config(codec);
3960 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
3962 codec->patch_ops = via_patch_ops;
3964 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
3972 static const struct hda_codec_preset snd_hda_preset_via[] = {
3973 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3974 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3975 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3976 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3977 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3978 .patch = patch_vt1709},
3979 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3980 .patch = patch_vt1709},
3981 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3982 .patch = patch_vt1709},
3983 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3984 .patch = patch_vt1709},
3985 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3986 .patch = patch_vt1709},
3987 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3988 .patch = patch_vt1709},
3989 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3990 .patch = patch_vt1709},
3991 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3992 .patch = patch_vt1709},
3993 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3994 .patch = patch_vt1708B},
3995 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3996 .patch = patch_vt1708B},
3997 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3998 .patch = patch_vt1708B},
3999 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
4000 .patch = patch_vt1708B},
4001 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
4002 .patch = patch_vt1708B},
4003 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
4004 .patch = patch_vt1708B},
4005 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
4006 .patch = patch_vt1708B},
4007 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
4008 .patch = patch_vt1708B},
4009 { .id = 0x11060397, .name = "VT1708S",
4010 .patch = patch_vt1708S},
4011 { .id = 0x11061397, .name = "VT1708S",
4012 .patch = patch_vt1708S},
4013 { .id = 0x11062397, .name = "VT1708S",
4014 .patch = patch_vt1708S},
4015 { .id = 0x11063397, .name = "VT1708S",
4016 .patch = patch_vt1708S},
4017 { .id = 0x11064397, .name = "VT1705",
4018 .patch = patch_vt1708S},
4019 { .id = 0x11065397, .name = "VT1708S",
4020 .patch = patch_vt1708S},
4021 { .id = 0x11066397, .name = "VT1708S",
4022 .patch = patch_vt1708S},
4023 { .id = 0x11067397, .name = "VT1708S",
4024 .patch = patch_vt1708S},
4025 { .id = 0x11060398, .name = "VT1702",
4026 .patch = patch_vt1702},
4027 { .id = 0x11061398, .name = "VT1702",
4028 .patch = patch_vt1702},
4029 { .id = 0x11062398, .name = "VT1702",
4030 .patch = patch_vt1702},
4031 { .id = 0x11063398, .name = "VT1702",
4032 .patch = patch_vt1702},
4033 { .id = 0x11064398, .name = "VT1702",
4034 .patch = patch_vt1702},
4035 { .id = 0x11065398, .name = "VT1702",
4036 .patch = patch_vt1702},
4037 { .id = 0x11066398, .name = "VT1702",
4038 .patch = patch_vt1702},
4039 { .id = 0x11067398, .name = "VT1702",
4040 .patch = patch_vt1702},
4041 { .id = 0x11060428, .name = "VT1718S",
4042 .patch = patch_vt1718S},
4043 { .id = 0x11064428, .name = "VT1718S",
4044 .patch = patch_vt1718S},
4045 { .id = 0x11060441, .name = "VT2020",
4046 .patch = patch_vt1718S},
4047 { .id = 0x11064441, .name = "VT1828S",
4048 .patch = patch_vt1718S},
4049 { .id = 0x11060433, .name = "VT1716S",
4050 .patch = patch_vt1716S},
4051 { .id = 0x1106a721, .name = "VT1716S",
4052 .patch = patch_vt1716S},
4053 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
4054 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
4055 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
4056 { .id = 0x11060440, .name = "VT1818S",
4057 .patch = patch_vt1708S},
4058 { .id = 0x11060446, .name = "VT1802",
4059 .patch = patch_vt2002P},
4060 { .id = 0x11068446, .name = "VT1802",
4061 .patch = patch_vt2002P},
4062 { .id = 0x11064760, .name = "VT1705CF",
4063 .patch = patch_vt3476},
4064 { .id = 0x11064761, .name = "VT1708SCE",
4065 .patch = patch_vt3476},
4066 { .id = 0x11064762, .name = "VT1808",
4067 .patch = patch_vt3476},
4071 MODULE_ALIAS("snd-hda-codec-id:1106*");
4073 static struct hda_codec_preset_list via_list = {
4074 .preset = snd_hda_preset_via,
4075 .owner = THIS_MODULE,
4078 MODULE_LICENSE("GPL");
4079 MODULE_DESCRIPTION("VIA HD-audio codec");
4081 static int __init patch_via_init(void)
4083 return snd_hda_add_codec_preset(&via_list);
4086 static void __exit patch_via_exit(void)
4088 snd_hda_delete_codec_preset(&via_list);
4091 module_init(patch_via_init)
4092 module_exit(patch_via_exit)