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"
60 #define VT1708_HP_PIN_NID 0x20
61 #define VT1708_CD_PIN_NID 0x24
81 #define VT2002P_COMPATIBLE(spec) \
82 ((spec)->codec_type == VT2002P ||\
83 (spec)->codec_type == VT1812 ||\
84 (spec)->codec_type == VT1802)
86 #define MAX_NID_PATH_DEPTH 5
88 /* output-path: DAC -> ... -> pin
89 * idx[] contains the source index number of the next widget;
90 * e.g. idx[0] is the index of the DAC selected by path[1] widget
91 * multi[] indicates whether it's a selector widget with multi-connectors
92 * (i.e. the connection selection is mandatory)
93 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
97 hda_nid_t path[MAX_NID_PATH_DEPTH];
98 unsigned char idx[MAX_NID_PATH_DEPTH];
99 unsigned char multi[MAX_NID_PATH_DEPTH];
100 unsigned int vol_ctl;
101 unsigned int mute_ctl;
106 hda_nid_t pin; /* input-pin or aa-mix */
107 int adc_idx; /* ADC index to be used */
108 int mux_idx; /* MUX index (if any) */
109 const char *label; /* input-source label */
112 #define VIA_MAX_ADCS 3
115 STREAM_MULTI_OUT = (1 << 0),
116 STREAM_INDEP_HP = (1 << 1),
120 /* codec parameterization */
121 const struct snd_kcontrol_new *mixers[6];
122 unsigned int num_mixers;
124 const struct hda_verb *init_verbs[5];
125 unsigned int num_iverbs;
127 char stream_name_analog[32];
128 char stream_name_hp[32];
129 const struct hda_pcm_stream *stream_analog_playback;
130 const struct hda_pcm_stream *stream_analog_capture;
132 char stream_name_digital[32];
133 const struct hda_pcm_stream *stream_digital_playback;
134 const struct hda_pcm_stream *stream_digital_capture;
137 struct hda_multi_out multiout;
138 hda_nid_t slave_dig_outs[2];
139 hda_nid_t hp_dac_nid;
140 hda_nid_t speaker_dac_nid;
141 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
142 int opened_streams; /* STREAM_* bits */
143 int active_streams; /* STREAM_* bits */
144 int aamix_mode; /* loopback is enabled for output-path? */
147 * There are different output-paths depending on the setup.
148 * out_path, hp_path and speaker_path are primary paths. If both
149 * direct DAC and aa-loopback routes are available, these contain
150 * the former paths. Meanwhile *_mix_path contain the paths with
151 * loopback mixer. (Since the loopback is only for front channel,
152 * no out_mix_path for surround channels.)
153 * The HP output has another path, hp_indep_path, which is used in
154 * the independent-HP mode.
156 struct nid_path out_path[HDA_SIDE + 1];
157 struct nid_path out_mix_path;
158 struct nid_path hp_path;
159 struct nid_path hp_mix_path;
160 struct nid_path hp_indep_path;
161 struct nid_path speaker_path;
162 struct nid_path speaker_mix_path;
165 unsigned int num_adc_nids;
166 hda_nid_t adc_nids[VIA_MAX_ADCS];
167 hda_nid_t mux_nids[VIA_MAX_ADCS];
168 hda_nid_t aa_mix_nid;
169 hda_nid_t dig_in_nid;
174 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
175 unsigned int cur_mux[VIA_MAX_ADCS];
177 /* dynamic DAC switching */
178 unsigned int cur_dac_stream_tag;
179 unsigned int cur_dac_format;
180 unsigned int cur_hp_stream_tag;
181 unsigned int cur_hp_format;
183 /* dynamic ADC switching */
185 unsigned int cur_adc_stream_tag;
186 unsigned int cur_adc_format;
188 /* PCM information */
189 struct hda_pcm pcm_rec[3];
191 /* dynamic controls, init_verbs and input_mux */
192 struct auto_pin_cfg autocfg;
193 struct snd_array kctls;
194 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
197 unsigned int hp_independent_mode;
198 unsigned int dmic_enabled;
199 unsigned int no_pin_power_ctl;
200 enum VIA_HDA_CODEC codec_type;
203 unsigned int smart51_nums;
204 hda_nid_t smart51_pins[2];
206 const char *smart51_labels[2];
207 unsigned int smart51_enabled;
209 /* work to check hp jack state */
210 struct hda_codec *codec;
211 struct delayed_work vt1708_hp_work;
212 int vt1708_jack_detect;
213 int vt1708_hp_present;
215 void (*set_widgets_power_state)(struct hda_codec *codec);
217 struct hda_loopback_check loopback;
219 struct hda_amp_list loopback_list[8];
221 /* bind capture-volume */
222 struct hda_bind_ctls *bind_cap_vol;
223 struct hda_bind_ctls *bind_cap_sw;
225 struct mutex config_mutex;
228 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
229 static struct via_spec * via_new_spec(struct hda_codec *codec)
231 struct via_spec *spec;
233 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
237 mutex_init(&spec->config_mutex);
240 spec->codec_type = get_codec_type(codec);
241 /* VT1708BCE & VT1708S are almost same */
242 if (spec->codec_type == VT1708BCE)
243 spec->codec_type = VT1708S;
247 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
249 u32 vendor_id = codec->vendor_id;
250 u16 ven_id = vendor_id >> 16;
251 u16 dev_id = vendor_id & 0xffff;
252 enum VIA_HDA_CODEC codec_type;
255 if (ven_id != 0x1106)
256 codec_type = UNKNOWN;
257 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
259 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
260 codec_type = VT1709_10CH;
261 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
262 codec_type = VT1709_6CH;
263 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
264 codec_type = VT1708B_8CH;
265 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
266 codec_type = VT1708BCE;
267 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
268 codec_type = VT1708B_4CH;
269 else if ((dev_id & 0xfff) == 0x397
270 && (dev_id >> 12) < 8)
271 codec_type = VT1708S;
272 else if ((dev_id & 0xfff) == 0x398
273 && (dev_id >> 12) < 8)
275 else if ((dev_id & 0xfff) == 0x428
276 && (dev_id >> 12) < 8)
277 codec_type = VT1718S;
278 else if (dev_id == 0x0433 || dev_id == 0xa721)
279 codec_type = VT1716S;
280 else if (dev_id == 0x0441 || dev_id == 0x4441)
281 codec_type = VT1718S;
282 else if (dev_id == 0x0438 || dev_id == 0x4438)
283 codec_type = VT2002P;
284 else if (dev_id == 0x0448)
286 else if (dev_id == 0x0440)
287 codec_type = VT1708S;
288 else if ((dev_id & 0xfff) == 0x446)
291 codec_type = UNKNOWN;
295 #define VIA_JACK_EVENT 0x20
296 #define VIA_HP_EVENT 0x01
297 #define VIA_GPIO_EVENT 0x02
298 #define VIA_LINE_EVENT 0x03
303 VIA_CTL_WIDGET_ANALOG_MUTE,
306 static void analog_low_current_mode(struct hda_codec *codec);
307 static bool is_aa_path_mute(struct hda_codec *codec);
309 static void vt1708_start_hp_work(struct via_spec *spec)
311 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
313 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
314 !spec->vt1708_jack_detect);
315 if (!delayed_work_pending(&spec->vt1708_hp_work))
316 schedule_delayed_work(&spec->vt1708_hp_work,
317 msecs_to_jiffies(100));
320 static void vt1708_stop_hp_work(struct via_spec *spec)
322 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
324 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
325 && !is_aa_path_mute(spec->codec))
327 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
328 !spec->vt1708_jack_detect);
329 cancel_delayed_work_sync(&spec->vt1708_hp_work);
332 static void set_widgets_power_state(struct hda_codec *codec)
334 struct via_spec *spec = codec->spec;
335 if (spec->set_widgets_power_state)
336 spec->set_widgets_power_state(codec);
339 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
340 struct snd_ctl_elem_value *ucontrol)
342 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
343 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
345 set_widgets_power_state(codec);
346 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
347 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
348 if (is_aa_path_mute(codec))
349 vt1708_start_hp_work(codec->spec);
351 vt1708_stop_hp_work(codec->spec);
356 /* modify .put = snd_hda_mixer_amp_switch_put */
357 #define ANALOG_INPUT_MUTE \
358 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
361 .info = snd_hda_mixer_amp_switch_info, \
362 .get = snd_hda_mixer_amp_switch_get, \
363 .put = analog_input_switch_put, \
364 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
366 static const struct snd_kcontrol_new via_control_templates[] = {
367 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
368 HDA_CODEC_MUTE(NULL, 0, 0, 0),
373 /* add dynamic controls */
374 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
375 const struct snd_kcontrol_new *tmpl,
378 struct snd_kcontrol_new *knew;
380 snd_array_init(&spec->kctls, sizeof(*knew), 32);
381 knew = snd_array_new(&spec->kctls);
388 knew->name = kstrdup(name, GFP_KERNEL);
395 static int __via_add_control(struct via_spec *spec, int type, const char *name,
396 int idx, unsigned long val)
398 struct snd_kcontrol_new *knew;
400 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
404 if (get_amp_nid_(val))
405 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
406 knew->private_value = val;
410 #define via_add_control(spec, type, name, val) \
411 __via_add_control(spec, type, name, 0, val)
413 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
415 static void via_free_kctls(struct hda_codec *codec)
417 struct via_spec *spec = codec->spec;
419 if (spec->kctls.list) {
420 struct snd_kcontrol_new *kctl = spec->kctls.list;
422 for (i = 0; i < spec->kctls.used; i++)
425 snd_array_free(&spec->kctls);
428 /* create input playback/capture controls for the given pin */
429 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
430 int type_idx, int idx, int mix_nid)
435 sprintf(name, "%s Playback Volume", ctlname);
436 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
437 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
440 sprintf(name, "%s Playback Switch", ctlname);
441 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
442 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
448 #define get_connection_index(codec, mux, nid) \
449 snd_hda_get_conn_index(codec, mux, nid, 0)
451 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
457 caps = get_wcaps(codec, nid);
458 if (dir == HDA_INPUT)
459 caps &= AC_WCAP_IN_AMP;
461 caps &= AC_WCAP_OUT_AMP;
464 if (query_amp_caps(codec, nid, dir) & mask)
469 #define have_mute(codec, nid, dir) \
470 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
472 /* enable/disable the output-route mixers */
473 static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
474 hda_nid_t mix_nid, int idx, bool enable)
480 num = snd_hda_get_conn_list(codec, mix_nid, NULL);
481 for (i = 0; i < num; i++) {
483 val = AMP_IN_UNMUTE(i);
485 val = AMP_IN_MUTE(i);
486 snd_hda_codec_write(codec, mix_nid, 0,
487 AC_VERB_SET_AMP_GAIN_MUTE, val);
491 /* enable/disable the output-route */
492 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
493 bool enable, bool force)
495 struct via_spec *spec = codec->spec;
497 for (i = 0; i < path->depth; i++) {
499 int idx = path->idx[i];
501 if (i < path->depth - 1)
502 dst = path->path[i + 1];
505 if (enable && path->multi[i])
506 snd_hda_codec_write(codec, dst, 0,
507 AC_VERB_SET_CONNECT_SEL, idx);
508 if (!force && (dst == spec->aa_mix_nid))
510 if (have_mute(codec, dst, HDA_INPUT))
511 activate_output_mix(codec, path, dst, idx, enable);
512 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
514 if (have_mute(codec, src, HDA_OUTPUT)) {
515 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
516 snd_hda_codec_write(codec, src, 0,
517 AC_VERB_SET_AMP_GAIN_MUTE, val);
522 /* set the given pin as output */
523 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
528 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
530 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
531 snd_hda_codec_write(codec, pin, 0,
532 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
535 static void via_auto_init_output(struct hda_codec *codec,
536 struct nid_path *path, int pin_type)
543 pin = path->path[path->depth - 1];
545 init_output_pin(codec, pin, pin_type);
546 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
547 if (caps & AC_AMPCAP_MUTE) {
549 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
550 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
553 activate_output_path(codec, path, true, true); /* force on */
556 static void via_auto_init_multi_out(struct hda_codec *codec)
558 struct via_spec *spec = codec->spec;
559 struct nid_path *path;
562 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
563 path = &spec->out_path[i];
564 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
565 path = &spec->out_mix_path;
566 via_auto_init_output(codec, path, PIN_OUT);
570 /* deactivate the inactive headphone-paths */
571 static void deactivate_hp_paths(struct hda_codec *codec)
573 struct via_spec *spec = codec->spec;
574 int shared = spec->hp_indep_shared;
576 if (spec->hp_independent_mode) {
577 activate_output_path(codec, &spec->hp_path, false, false);
578 activate_output_path(codec, &spec->hp_mix_path, false, false);
580 activate_output_path(codec, &spec->out_path[shared],
582 } else if (spec->aamix_mode || !spec->hp_path.depth) {
583 activate_output_path(codec, &spec->hp_indep_path, false, false);
584 activate_output_path(codec, &spec->hp_path, false, false);
586 activate_output_path(codec, &spec->hp_indep_path, false, false);
587 activate_output_path(codec, &spec->hp_mix_path, false, false);
591 static void via_auto_init_hp_out(struct hda_codec *codec)
593 struct via_spec *spec = codec->spec;
595 if (!spec->hp_path.depth) {
596 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
599 deactivate_hp_paths(codec);
600 if (spec->hp_independent_mode)
601 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
602 else if (spec->aamix_mode)
603 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
605 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
608 static void via_auto_init_speaker_out(struct hda_codec *codec)
610 struct via_spec *spec = codec->spec;
612 if (!spec->autocfg.speaker_outs)
614 if (!spec->speaker_path.depth) {
615 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
618 if (!spec->aamix_mode) {
619 activate_output_path(codec, &spec->speaker_mix_path,
621 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
623 activate_output_path(codec, &spec->speaker_path, false, false);
624 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
628 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
629 static void via_hp_automute(struct hda_codec *codec);
631 static void via_auto_init_analog_input(struct hda_codec *codec)
633 struct via_spec *spec = codec->spec;
634 const struct auto_pin_cfg *cfg = &spec->autocfg;
635 hda_nid_t conn[HDA_MAX_CONNECTIONS];
640 for (i = 0; i < spec->num_adc_nids; i++) {
641 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
642 AC_VERB_SET_AMP_GAIN_MUTE,
647 for (i = 0; i < cfg->num_inputs; i++) {
648 hda_nid_t nid = cfg->inputs[i].pin;
649 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
651 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
655 snd_hda_codec_write(codec, nid, 0,
656 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
660 for (i = 0; i < spec->num_adc_nids; i++) {
661 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
662 if (spec->mux_nids[adc_idx]) {
663 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
664 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
665 AC_VERB_SET_CONNECT_SEL,
668 if (spec->dyn_adc_switch)
669 break; /* only one input-src */
673 if (!spec->aa_mix_nid)
675 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
677 for (i = 0; i < num_conns; i++) {
678 unsigned int caps = get_wcaps(codec, conn[i]);
679 if (get_wcaps_type(caps) == AC_WID_PIN)
680 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
681 AC_VERB_SET_AMP_GAIN_MUTE,
686 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
687 unsigned int *affected_parm)
690 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
691 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
692 >> AC_DEFCFG_MISC_SHIFT
693 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
694 struct via_spec *spec = codec->spec;
695 unsigned present = 0;
697 no_presence |= spec->no_pin_power_ctl;
699 present = snd_hda_jack_detect(codec, nid);
700 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
701 || ((no_presence || present)
702 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
703 *affected_parm = AC_PWRST_D0; /* if it's connected */
708 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
711 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
712 struct snd_ctl_elem_info *uinfo)
714 static const char * const texts[] = {
715 "Disabled", "Enabled"
718 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
720 uinfo->value.enumerated.items = 2;
721 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
722 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
723 strcpy(uinfo->value.enumerated.name,
724 texts[uinfo->value.enumerated.item]);
728 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732 struct via_spec *spec = codec->spec;
733 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
737 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
738 struct snd_ctl_elem_value *ucontrol)
740 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
741 struct via_spec *spec = codec->spec;
742 unsigned int val = !ucontrol->value.enumerated.item[0];
744 if (val == spec->no_pin_power_ctl)
746 spec->no_pin_power_ctl = val;
747 set_widgets_power_state(codec);
751 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
753 .name = "Dynamic Power-Control",
754 .info = via_pin_power_ctl_info,
755 .get = via_pin_power_ctl_get,
756 .put = via_pin_power_ctl_put,
760 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
761 struct snd_ctl_elem_info *uinfo)
763 static const char * const texts[] = { "OFF", "ON" };
765 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
767 uinfo->value.enumerated.items = 2;
768 if (uinfo->value.enumerated.item >= 2)
769 uinfo->value.enumerated.item = 1;
770 strcpy(uinfo->value.enumerated.name,
771 texts[uinfo->value.enumerated.item]);
775 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
776 struct snd_ctl_elem_value *ucontrol)
778 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
779 struct via_spec *spec = codec->spec;
781 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
785 /* adjust spec->multiout setup according to the current flags */
786 static void setup_playback_multi_pcm(struct via_spec *spec)
788 const struct auto_pin_cfg *cfg = &spec->autocfg;
789 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
790 spec->multiout.hp_nid = 0;
791 if (!spec->hp_independent_mode) {
792 if (!spec->hp_indep_shared)
793 spec->multiout.hp_nid = spec->hp_dac_nid;
795 if (spec->hp_indep_shared)
796 spec->multiout.num_dacs = cfg->line_outs - 1;
800 /* update DAC setups according to indep-HP switch;
801 * this function is called only when indep-HP is modified
803 static void switch_indep_hp_dacs(struct hda_codec *codec)
805 struct via_spec *spec = codec->spec;
806 int shared = spec->hp_indep_shared;
807 hda_nid_t shared_dac, hp_dac;
809 if (!spec->opened_streams)
812 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
813 hp_dac = spec->hp_dac_nid;
814 if (spec->hp_independent_mode) {
815 /* switch to indep-HP mode */
816 if (spec->active_streams & STREAM_MULTI_OUT) {
817 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
818 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
820 if (spec->active_streams & STREAM_INDEP_HP)
821 snd_hda_codec_setup_stream(codec, hp_dac,
822 spec->cur_hp_stream_tag, 0,
823 spec->cur_hp_format);
825 /* back to HP or shared-DAC */
826 if (spec->active_streams & STREAM_INDEP_HP)
827 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
828 if (spec->active_streams & STREAM_MULTI_OUT) {
831 if (shared_dac) { /* reset mutli-ch DAC */
834 } else { /* reset HP DAC */
838 snd_hda_codec_setup_stream(codec, dac,
839 spec->cur_dac_stream_tag, ch,
840 spec->cur_dac_format);
843 setup_playback_multi_pcm(spec);
846 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
847 struct snd_ctl_elem_value *ucontrol)
849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
850 struct via_spec *spec = codec->spec;
853 mutex_lock(&spec->config_mutex);
854 cur = !!ucontrol->value.enumerated.item[0];
855 if (spec->hp_independent_mode == cur) {
856 mutex_unlock(&spec->config_mutex);
859 spec->hp_independent_mode = cur;
860 shared = spec->hp_indep_shared;
861 deactivate_hp_paths(codec);
863 activate_output_path(codec, &spec->hp_indep_path, true, false);
866 activate_output_path(codec, &spec->out_path[shared],
868 if (spec->aamix_mode || !spec->hp_path.depth)
869 activate_output_path(codec, &spec->hp_mix_path,
872 activate_output_path(codec, &spec->hp_path,
876 switch_indep_hp_dacs(codec);
877 mutex_unlock(&spec->config_mutex);
879 /* update jack power state */
880 set_widgets_power_state(codec);
881 via_hp_automute(codec);
885 static const struct snd_kcontrol_new via_hp_mixer = {
886 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
887 .name = "Independent HP",
888 .info = via_independent_hp_info,
889 .get = via_independent_hp_get,
890 .put = via_independent_hp_put,
893 static int via_hp_build(struct hda_codec *codec)
895 struct via_spec *spec = codec->spec;
896 struct snd_kcontrol_new *knew;
899 nid = spec->autocfg.hp_pins[0];
900 knew = via_clone_control(spec, &via_hp_mixer);
904 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
909 static void notify_aa_path_ctls(struct hda_codec *codec)
911 struct via_spec *spec = codec->spec;
914 for (i = 0; i < spec->smart51_nums; i++) {
915 struct snd_kcontrol *ctl;
916 struct snd_ctl_elem_id id;
917 memset(&id, 0, sizeof(id));
918 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
919 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
920 ctl = snd_hda_find_mixer_ctl(codec, id.name);
922 snd_ctl_notify(codec->bus->card,
923 SNDRV_CTL_EVENT_MASK_VALUE,
928 static void mute_aa_path(struct hda_codec *codec, int mute)
930 struct via_spec *spec = codec->spec;
931 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
934 /* check AA path's mute status */
935 for (i = 0; i < spec->smart51_nums; i++) {
936 if (spec->smart51_idxs[i] < 0)
938 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
939 HDA_INPUT, spec->smart51_idxs[i],
944 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
946 struct via_spec *spec = codec->spec;
949 for (i = 0; i < spec->smart51_nums; i++)
950 if (spec->smart51_pins[i] == pin)
955 static int via_smart51_get(struct snd_kcontrol *kcontrol,
956 struct snd_ctl_elem_value *ucontrol)
958 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
959 struct via_spec *spec = codec->spec;
961 *ucontrol->value.integer.value = spec->smart51_enabled;
965 static int via_smart51_put(struct snd_kcontrol *kcontrol,
966 struct snd_ctl_elem_value *ucontrol)
968 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
969 struct via_spec *spec = codec->spec;
970 int out_in = *ucontrol->value.integer.value
971 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
974 for (i = 0; i < spec->smart51_nums; i++) {
975 hda_nid_t nid = spec->smart51_pins[i];
978 parm = snd_hda_codec_read(codec, nid, 0,
979 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
980 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
982 snd_hda_codec_write(codec, nid, 0,
983 AC_VERB_SET_PIN_WIDGET_CONTROL,
985 if (out_in == AC_PINCTL_OUT_EN) {
986 mute_aa_path(codec, 1);
987 notify_aa_path_ctls(codec);
990 spec->smart51_enabled = *ucontrol->value.integer.value;
991 set_widgets_power_state(codec);
995 static const struct snd_kcontrol_new via_smart51_mixer = {
996 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
999 .info = snd_ctl_boolean_mono_info,
1000 .get = via_smart51_get,
1001 .put = via_smart51_put,
1004 static int via_smart51_build(struct hda_codec *codec)
1006 struct via_spec *spec = codec->spec;
1008 if (!spec->smart51_nums)
1010 if (!via_clone_control(spec, &via_smart51_mixer))
1015 /* check AA path's mute status */
1016 static bool is_aa_path_mute(struct hda_codec *codec)
1018 struct via_spec *spec = codec->spec;
1019 const struct hda_amp_list *p;
1022 for (i = 0; i < spec->num_loopbacks; i++) {
1023 p = &spec->loopback_list[i];
1024 for (ch = 0; ch < 2; ch++) {
1025 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1027 if (!(v & HDA_AMP_MUTE) && v > 0)
1034 /* enter/exit analog low-current mode */
1035 static void analog_low_current_mode(struct hda_codec *codec)
1037 struct via_spec *spec = codec->spec;
1039 unsigned int verb, parm;
1041 enable = is_aa_path_mute(codec) && (spec->opened_streams != 0);
1043 /* decide low current mode's verb & parameter */
1044 switch (spec->codec_type) {
1048 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1054 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1058 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1064 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1067 return; /* other codecs are not supported */
1070 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1074 * generic initialization of ADC, input mixers and output mixers
1076 static const struct hda_verb vt1708_init_verbs[] = {
1077 /* power down jack detect function */
1082 static void set_stream_open(struct hda_codec *codec, int bit, bool active)
1084 struct via_spec *spec = codec->spec;
1087 spec->opened_streams |= bit;
1089 spec->opened_streams &= ~bit;
1090 analog_low_current_mode(codec);
1093 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1094 struct hda_codec *codec,
1095 struct snd_pcm_substream *substream)
1097 struct via_spec *spec = codec->spec;
1098 const struct auto_pin_cfg *cfg = &spec->autocfg;
1101 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1102 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1103 set_stream_open(codec, STREAM_MULTI_OUT, true);
1104 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1107 set_stream_open(codec, STREAM_MULTI_OUT, false);
1113 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1114 struct hda_codec *codec,
1115 struct snd_pcm_substream *substream)
1117 set_stream_open(codec, STREAM_MULTI_OUT, false);
1121 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1122 struct hda_codec *codec,
1123 struct snd_pcm_substream *substream)
1125 struct via_spec *spec = codec->spec;
1127 if (snd_BUG_ON(!spec->hp_dac_nid))
1129 set_stream_open(codec, STREAM_INDEP_HP, true);
1133 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1134 struct hda_codec *codec,
1135 struct snd_pcm_substream *substream)
1137 set_stream_open(codec, STREAM_INDEP_HP, false);
1141 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1142 struct hda_codec *codec,
1143 unsigned int stream_tag,
1144 unsigned int format,
1145 struct snd_pcm_substream *substream)
1147 struct via_spec *spec = codec->spec;
1149 mutex_lock(&spec->config_mutex);
1150 setup_playback_multi_pcm(spec);
1151 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1153 /* remember for dynamic DAC switch with indep-HP */
1154 spec->active_streams |= STREAM_MULTI_OUT;
1155 spec->cur_dac_stream_tag = stream_tag;
1156 spec->cur_dac_format = format;
1157 mutex_unlock(&spec->config_mutex);
1158 vt1708_start_hp_work(spec);
1162 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1163 struct hda_codec *codec,
1164 unsigned int stream_tag,
1165 unsigned int format,
1166 struct snd_pcm_substream *substream)
1168 struct via_spec *spec = codec->spec;
1170 mutex_lock(&spec->config_mutex);
1171 if (spec->hp_independent_mode)
1172 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1173 stream_tag, 0, format);
1174 spec->active_streams |= STREAM_INDEP_HP;
1175 spec->cur_hp_stream_tag = stream_tag;
1176 spec->cur_hp_format = format;
1177 mutex_unlock(&spec->config_mutex);
1178 vt1708_start_hp_work(spec);
1182 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1183 struct hda_codec *codec,
1184 struct snd_pcm_substream *substream)
1186 struct via_spec *spec = codec->spec;
1188 mutex_lock(&spec->config_mutex);
1189 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1190 spec->active_streams &= ~STREAM_MULTI_OUT;
1191 mutex_unlock(&spec->config_mutex);
1192 vt1708_stop_hp_work(spec);
1196 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1197 struct hda_codec *codec,
1198 struct snd_pcm_substream *substream)
1200 struct via_spec *spec = codec->spec;
1202 mutex_lock(&spec->config_mutex);
1203 if (spec->hp_independent_mode)
1204 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1205 spec->active_streams &= ~STREAM_INDEP_HP;
1206 mutex_unlock(&spec->config_mutex);
1207 vt1708_stop_hp_work(spec);
1214 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1215 struct hda_codec *codec,
1216 struct snd_pcm_substream *substream)
1218 struct via_spec *spec = codec->spec;
1219 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1222 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1223 struct hda_codec *codec,
1224 struct snd_pcm_substream *substream)
1226 struct via_spec *spec = codec->spec;
1227 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1230 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1231 struct hda_codec *codec,
1232 unsigned int stream_tag,
1233 unsigned int format,
1234 struct snd_pcm_substream *substream)
1236 struct via_spec *spec = codec->spec;
1237 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1238 stream_tag, format, substream);
1241 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1242 struct hda_codec *codec,
1243 struct snd_pcm_substream *substream)
1245 struct via_spec *spec = codec->spec;
1246 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1253 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1254 struct hda_codec *codec,
1255 unsigned int stream_tag,
1256 unsigned int format,
1257 struct snd_pcm_substream *substream)
1259 struct via_spec *spec = codec->spec;
1261 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1262 stream_tag, 0, format);
1266 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1267 struct hda_codec *codec,
1268 struct snd_pcm_substream *substream)
1270 struct via_spec *spec = codec->spec;
1271 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1275 /* analog capture with dynamic ADC switching */
1276 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1277 struct hda_codec *codec,
1278 unsigned int stream_tag,
1279 unsigned int format,
1280 struct snd_pcm_substream *substream)
1282 struct via_spec *spec = codec->spec;
1283 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1285 mutex_lock(&spec->config_mutex);
1286 spec->cur_adc = spec->adc_nids[adc_idx];
1287 spec->cur_adc_stream_tag = stream_tag;
1288 spec->cur_adc_format = format;
1289 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1290 mutex_unlock(&spec->config_mutex);
1294 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1295 struct hda_codec *codec,
1296 struct snd_pcm_substream *substream)
1298 struct via_spec *spec = codec->spec;
1300 mutex_lock(&spec->config_mutex);
1301 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1303 mutex_unlock(&spec->config_mutex);
1307 /* re-setup the stream if running; called from input-src put */
1308 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1310 struct via_spec *spec = codec->spec;
1311 int adc_idx = spec->inputs[cur].adc_idx;
1312 hda_nid_t adc = spec->adc_nids[adc_idx];
1315 mutex_lock(&spec->config_mutex);
1316 if (spec->cur_adc && spec->cur_adc != adc) {
1317 /* stream is running, let's swap the current ADC */
1318 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1319 spec->cur_adc = adc;
1320 snd_hda_codec_setup_stream(codec, adc,
1321 spec->cur_adc_stream_tag, 0,
1322 spec->cur_adc_format);
1325 mutex_unlock(&spec->config_mutex);
1329 static const struct hda_pcm_stream via_pcm_analog_playback = {
1333 /* NID is set in via_build_pcms */
1335 .open = via_playback_multi_pcm_open,
1336 .close = via_playback_multi_pcm_close,
1337 .prepare = via_playback_multi_pcm_prepare,
1338 .cleanup = via_playback_multi_pcm_cleanup
1342 static const struct hda_pcm_stream via_pcm_hp_playback = {
1346 /* NID is set in via_build_pcms */
1348 .open = via_playback_hp_pcm_open,
1349 .close = via_playback_hp_pcm_close,
1350 .prepare = via_playback_hp_pcm_prepare,
1351 .cleanup = via_playback_hp_pcm_cleanup
1355 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1359 /* NID is set in via_build_pcms */
1360 /* We got noisy outputs on the right channel on VT1708 when
1361 * 24bit samples are used. Until any workaround is found,
1362 * disable the 24bit format, so far.
1364 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1366 .open = via_playback_multi_pcm_open,
1367 .close = via_playback_multi_pcm_close,
1368 .prepare = via_playback_multi_pcm_prepare,
1369 .cleanup = via_playback_multi_pcm_cleanup
1373 static const struct hda_pcm_stream via_pcm_analog_capture = {
1374 .substreams = 1, /* will be changed in via_build_pcms() */
1377 /* NID is set in via_build_pcms */
1379 .prepare = via_capture_pcm_prepare,
1380 .cleanup = via_capture_pcm_cleanup
1384 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1388 /* NID is set in via_build_pcms */
1390 .prepare = via_dyn_adc_capture_pcm_prepare,
1391 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1395 static const struct hda_pcm_stream via_pcm_digital_playback = {
1399 /* NID is set in via_build_pcms */
1401 .open = via_dig_playback_pcm_open,
1402 .close = via_dig_playback_pcm_close,
1403 .prepare = via_dig_playback_pcm_prepare,
1404 .cleanup = via_dig_playback_pcm_cleanup
1408 static const struct hda_pcm_stream via_pcm_digital_capture = {
1415 * slave controls for virtual master
1417 static const char * const via_slave_vols[] = {
1418 "Front Playback Volume",
1419 "Surround Playback Volume",
1420 "Center Playback Volume",
1421 "LFE Playback Volume",
1422 "Side Playback Volume",
1423 "Headphone Playback Volume",
1424 "Speaker Playback Volume",
1428 static const char * const via_slave_sws[] = {
1429 "Front Playback Switch",
1430 "Surround Playback Switch",
1431 "Center Playback Switch",
1432 "LFE Playback Switch",
1433 "Side Playback Switch",
1434 "Headphone Playback Switch",
1435 "Speaker Playback Switch",
1439 static int via_build_controls(struct hda_codec *codec)
1441 struct via_spec *spec = codec->spec;
1442 struct snd_kcontrol *kctl;
1445 if (spec->set_widgets_power_state)
1446 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1449 for (i = 0; i < spec->num_mixers; i++) {
1450 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1455 if (spec->multiout.dig_out_nid) {
1456 err = snd_hda_create_spdif_out_ctls(codec,
1457 spec->multiout.dig_out_nid,
1458 spec->multiout.dig_out_nid);
1461 err = snd_hda_create_spdif_share_sw(codec,
1465 spec->multiout.share_spdif = 1;
1467 if (spec->dig_in_nid) {
1468 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1473 /* if we have no master control, let's create it */
1474 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1475 unsigned int vmaster_tlv[4];
1476 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1477 HDA_OUTPUT, vmaster_tlv);
1478 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1479 vmaster_tlv, via_slave_vols);
1483 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1484 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1485 NULL, via_slave_sws);
1490 /* assign Capture Source enums to NID */
1491 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1492 for (i = 0; kctl && i < kctl->count; i++) {
1493 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1498 /* init power states */
1499 set_widgets_power_state(codec);
1500 analog_low_current_mode(codec);
1502 via_free_kctls(codec); /* no longer needed */
1504 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1511 static int via_build_pcms(struct hda_codec *codec)
1513 struct via_spec *spec = codec->spec;
1514 struct hda_pcm *info = spec->pcm_rec;
1516 codec->num_pcms = 0;
1517 codec->pcm_info = info;
1519 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1520 snprintf(spec->stream_name_analog,
1521 sizeof(spec->stream_name_analog),
1522 "%s Analog", codec->chip_name);
1523 info->name = spec->stream_name_analog;
1525 if (spec->multiout.num_dacs) {
1526 if (!spec->stream_analog_playback)
1527 spec->stream_analog_playback =
1528 &via_pcm_analog_playback;
1529 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1530 *spec->stream_analog_playback;
1531 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1532 spec->multiout.dac_nids[0];
1533 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1534 spec->multiout.max_channels;
1537 if (!spec->stream_analog_capture) {
1538 if (spec->dyn_adc_switch)
1539 spec->stream_analog_capture =
1540 &via_pcm_dyn_adc_analog_capture;
1542 spec->stream_analog_capture =
1543 &via_pcm_analog_capture;
1545 if (spec->num_adc_nids) {
1546 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1547 *spec->stream_analog_capture;
1548 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1550 if (!spec->dyn_adc_switch)
1551 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1558 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1559 snprintf(spec->stream_name_digital,
1560 sizeof(spec->stream_name_digital),
1561 "%s Digital", codec->chip_name);
1562 info->name = spec->stream_name_digital;
1563 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1564 if (spec->multiout.dig_out_nid) {
1565 if (!spec->stream_digital_playback)
1566 spec->stream_digital_playback =
1567 &via_pcm_digital_playback;
1568 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1569 *spec->stream_digital_playback;
1570 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1571 spec->multiout.dig_out_nid;
1573 if (spec->dig_in_nid) {
1574 if (!spec->stream_digital_capture)
1575 spec->stream_digital_capture =
1576 &via_pcm_digital_capture;
1577 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1578 *spec->stream_digital_capture;
1579 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1586 if (spec->hp_dac_nid) {
1587 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1588 "%s HP", codec->chip_name);
1589 info->name = spec->stream_name_hp;
1590 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1591 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1599 static void via_free(struct hda_codec *codec)
1601 struct via_spec *spec = codec->spec;
1606 via_free_kctls(codec);
1607 vt1708_stop_hp_work(spec);
1608 kfree(spec->bind_cap_vol);
1609 kfree(spec->bind_cap_sw);
1613 /* mute/unmute outputs */
1614 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1615 hda_nid_t *pins, bool mute)
1618 for (i = 0; i < num_pins; i++) {
1619 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1620 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1621 if (parm & AC_PINCTL_IN_EN)
1624 parm &= ~AC_PINCTL_OUT_EN;
1626 parm |= AC_PINCTL_OUT_EN;
1627 snd_hda_codec_write(codec, pins[i], 0,
1628 AC_VERB_SET_PIN_WIDGET_CONTROL, parm);
1632 /* mute internal speaker if line-out is plugged */
1633 static void via_line_automute(struct hda_codec *codec, int present)
1635 struct via_spec *spec = codec->spec;
1637 if (!spec->autocfg.speaker_outs)
1640 present = snd_hda_jack_detect(codec,
1641 spec->autocfg.line_out_pins[0]);
1642 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1643 spec->autocfg.speaker_pins,
1647 /* mute internal speaker if HP is plugged */
1648 static void via_hp_automute(struct hda_codec *codec)
1652 struct via_spec *spec = codec->spec;
1654 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0])
1655 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1657 if (spec->smart51_enabled)
1658 nums = spec->autocfg.line_outs + spec->smart51_nums;
1660 nums = spec->autocfg.line_outs;
1661 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1663 via_line_automute(codec, present);
1666 static void via_gpio_control(struct hda_codec *codec)
1668 unsigned int gpio_data;
1669 unsigned int vol_counter;
1671 unsigned int master_vol;
1673 struct via_spec *spec = codec->spec;
1675 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1676 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1678 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1679 0xF84, 0) & 0x3F0000) >> 16;
1681 vol = vol_counter & 0x1F;
1682 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1683 AC_VERB_GET_AMP_GAIN_MUTE,
1686 if (gpio_data == 0x02) {
1687 /* unmute line out */
1688 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1689 AC_VERB_SET_PIN_WIDGET_CONTROL,
1691 if (vol_counter & 0x20) {
1692 /* decrease volume */
1693 if (vol > master_vol)
1695 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1699 /* increase volume */
1700 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1702 ((master_vol+vol) > 0x2A) ? 0x2A :
1705 } else if (!(gpio_data & 0x02)) {
1707 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1708 AC_VERB_SET_PIN_WIDGET_CONTROL,
1713 /* unsolicited event for jack sensing */
1714 static void via_unsol_event(struct hda_codec *codec,
1718 res = snd_hda_jack_get_action(codec, res);
1720 if (res & VIA_JACK_EVENT)
1721 set_widgets_power_state(codec);
1723 res &= ~VIA_JACK_EVENT;
1725 if (res == VIA_HP_EVENT || res == VIA_LINE_EVENT)
1726 via_hp_automute(codec);
1727 else if (res == VIA_GPIO_EVENT)
1728 via_gpio_control(codec);
1729 snd_hda_jack_report_sync(codec);
1733 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1735 struct via_spec *spec = codec->spec;
1736 vt1708_stop_hp_work(spec);
1741 #ifdef CONFIG_SND_HDA_POWER_SAVE
1742 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1744 struct via_spec *spec = codec->spec;
1745 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1752 static int via_init(struct hda_codec *codec);
1754 static const struct hda_codec_ops via_patch_ops = {
1755 .build_controls = via_build_controls,
1756 .build_pcms = via_build_pcms,
1759 .unsol_event = via_unsol_event,
1761 .suspend = via_suspend,
1763 #ifdef CONFIG_SND_HDA_POWER_SAVE
1764 .check_power_status = via_check_power_status,
1768 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1770 struct via_spec *spec = codec->spec;
1773 for (i = 0; i < spec->multiout.num_dacs; i++) {
1774 if (spec->multiout.dac_nids[i] == dac)
1777 if (spec->hp_dac_nid == dac)
1782 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1783 hda_nid_t target_dac, int with_aa_mix,
1784 struct nid_path *path, int depth)
1786 struct via_spec *spec = codec->spec;
1790 if (nid == spec->aa_mix_nid) {
1793 with_aa_mix = 2; /* mark aa-mix is included */
1796 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1797 for (i = 0; i < nums; i++) {
1798 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1800 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1801 /* aa-mix is requested but not included? */
1802 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1806 if (depth >= MAX_NID_PATH_DEPTH)
1808 for (i = 0; i < nums; i++) {
1810 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1811 if (type == AC_WID_AUD_OUT)
1813 if (__parse_output_path(codec, conn[i], target_dac,
1814 with_aa_mix, path, depth + 1))
1820 path->path[path->depth] = conn[i];
1821 path->idx[path->depth] = i;
1822 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1823 path->multi[path->depth] = 1;
1828 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1829 hda_nid_t target_dac, int with_aa_mix,
1830 struct nid_path *path)
1832 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
1833 path->path[path->depth] = nid;
1835 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1836 path->depth, path->path[0], path->path[1],
1837 path->path[2], path->path[3], path->path[4]);
1843 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1845 struct via_spec *spec = codec->spec;
1846 const struct auto_pin_cfg *cfg = &spec->autocfg;
1850 spec->multiout.dac_nids = spec->private_dac_nids;
1852 for (i = 0; i < cfg->line_outs; i++) {
1854 nid = cfg->line_out_pins[i];
1857 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1858 dac = spec->out_path[i].path[0];
1859 if (!i && parse_output_path(codec, nid, dac, 1,
1860 &spec->out_mix_path))
1861 dac = spec->out_mix_path.path[0];
1863 spec->private_dac_nids[i] = dac;
1867 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1868 spec->out_path[0] = spec->out_mix_path;
1869 spec->out_mix_path.depth = 0;
1871 spec->multiout.num_dacs = dac_num;
1875 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1876 int chs, bool check_dac, struct nid_path *path)
1878 struct via_spec *spec = codec->spec;
1880 hda_nid_t dac, pin, sel, nid;
1883 dac = check_dac ? path->path[0] : 0;
1884 pin = path->path[path->depth - 1];
1885 sel = path->depth > 1 ? path->path[1] : 0;
1887 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1889 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1891 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1896 sprintf(name, "%s Playback Volume", pfx);
1897 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1898 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1901 path->vol_ctl = nid;
1904 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1906 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1908 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1913 sprintf(name, "%s Playback Switch", pfx);
1914 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1915 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1918 path->mute_ctl = nid;
1923 static void mangle_smart51(struct hda_codec *codec)
1925 struct via_spec *spec = codec->spec;
1926 struct auto_pin_cfg *cfg = &spec->autocfg;
1927 struct auto_pin_cfg_item *ins = cfg->inputs;
1928 int i, j, nums, attr;
1929 int pins[AUTO_CFG_MAX_INS];
1931 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1933 for (i = 0; i < cfg->num_inputs; i++) {
1935 if (ins[i].type > AUTO_PIN_LINE_IN)
1937 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1938 if (snd_hda_get_input_pin_attr(def) != attr)
1940 for (j = 0; j < nums; j++)
1941 if (ins[pins[j]].type < ins[i].type) {
1942 memmove(pins + j + 1, pins + j,
1943 (nums - j) * sizeof(int));
1949 if (cfg->line_outs + nums < 3)
1951 for (i = 0; i < nums; i++) {
1952 hda_nid_t pin = ins[pins[i]].pin;
1953 spec->smart51_pins[spec->smart51_nums++] = pin;
1954 cfg->line_out_pins[cfg->line_outs++] = pin;
1955 if (cfg->line_outs == 3)
1962 static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1964 dst->vol_ctl = src->vol_ctl;
1965 dst->mute_ctl = src->mute_ctl;
1968 /* add playback controls from the parsed DAC table */
1969 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1971 struct via_spec *spec = codec->spec;
1972 struct auto_pin_cfg *cfg = &spec->autocfg;
1973 struct nid_path *path;
1974 static const char * const chname[4] = {
1975 "Front", "Surround", "C/LFE", "Side"
1981 old_line_outs = cfg->line_outs;
1982 if (cfg->line_outs == 1)
1983 mangle_smart51(codec);
1985 err = via_auto_fill_dac_nids(codec);
1989 if (spec->multiout.num_dacs < 3) {
1990 spec->smart51_nums = 0;
1991 cfg->line_outs = old_line_outs;
1993 for (i = 0; i < cfg->line_outs; i++) {
1995 pin = cfg->line_out_pins[i];
1996 dac = spec->multiout.dac_nids[i];
1999 path = spec->out_path + i;
2000 if (i == HDA_CLFE) {
2001 err = create_ch_ctls(codec, "Center", 1, true, path);
2004 err = create_ch_ctls(codec, "LFE", 2, true, path);
2008 const char *pfx = chname[i];
2009 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
2010 cfg->line_outs == 1)
2012 err = create_ch_ctls(codec, pfx, 3, true, path);
2016 if (path != spec->out_path + i)
2017 copy_path_mixer_ctls(&spec->out_path[i], path);
2018 if (path == spec->out_path && spec->out_mix_path.depth)
2019 copy_path_mixer_ctls(&spec->out_mix_path, path);
2022 idx = get_connection_index(codec, spec->aa_mix_nid,
2023 spec->multiout.dac_nids[0]);
2025 /* add control to mixer */
2027 name = spec->out_mix_path.depth ?
2028 "PCM Loopback Playback Volume" : "PCM Playback Volume";
2029 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2030 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2034 name = spec->out_mix_path.depth ?
2035 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2036 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2037 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2043 cfg->line_outs = old_line_outs;
2048 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
2050 struct via_spec *spec = codec->spec;
2051 struct nid_path *path;
2058 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2059 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2060 if (i < spec->multiout.num_dacs &&
2061 parse_output_path(codec, pin,
2062 spec->multiout.dac_nids[i], 0,
2063 &spec->hp_indep_path)) {
2064 spec->hp_indep_shared = i;
2069 if (spec->hp_indep_path.depth) {
2070 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2071 if (!spec->hp_indep_shared)
2072 spec->hp_path = spec->hp_indep_path;
2074 /* optionally check front-path w/o AA-mix */
2075 if (!spec->hp_path.depth)
2076 parse_output_path(codec, pin,
2077 spec->multiout.dac_nids[HDA_FRONT], 0,
2080 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2081 1, &spec->hp_mix_path) && !spec->hp_path.depth)
2084 if (spec->hp_path.depth) {
2085 path = &spec->hp_path;
2088 path = &spec->hp_mix_path;
2091 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
2095 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2097 copy_path_mixer_ctls(&spec->hp_path, path);
2098 if (spec->hp_indep_path.depth)
2099 copy_path_mixer_ctls(&spec->hp_indep_path, path);
2103 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2105 struct via_spec *spec = codec->spec;
2106 struct nid_path *path;
2108 hda_nid_t pin, dac = 0;
2111 pin = spec->autocfg.speaker_pins[0];
2112 if (!spec->autocfg.speaker_outs || !pin)
2115 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
2116 dac = spec->speaker_path.path[0];
2118 parse_output_path(codec, pin,
2119 spec->multiout.dac_nids[HDA_FRONT], 0,
2120 &spec->speaker_path);
2121 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2122 1, &spec->speaker_mix_path) && !dac)
2125 /* no AA-path for front? */
2126 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2129 spec->speaker_dac_nid = dac;
2130 spec->multiout.extra_out_nid[0] = dac;
2132 path = &spec->speaker_path;
2135 path = &spec->speaker_mix_path;
2138 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2142 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2144 copy_path_mixer_ctls(&spec->speaker_path, path);
2148 #define via_aamix_ctl_info via_pin_power_ctl_info
2150 static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2151 struct snd_ctl_elem_value *ucontrol)
2153 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2154 struct via_spec *spec = codec->spec;
2155 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2159 static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2160 struct nid_path *nomix, struct nid_path *mix)
2163 activate_output_path(codec, nomix, false, false);
2164 activate_output_path(codec, mix, true, false);
2166 activate_output_path(codec, mix, false, false);
2167 activate_output_path(codec, nomix, true, false);
2171 static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2172 struct snd_ctl_elem_value *ucontrol)
2174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2175 struct via_spec *spec = codec->spec;
2176 unsigned int val = ucontrol->value.enumerated.item[0];
2178 if (val == spec->aamix_mode)
2180 spec->aamix_mode = val;
2181 /* update front path */
2182 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2183 /* update HP path */
2184 if (!spec->hp_independent_mode) {
2185 update_aamix_paths(codec, val, &spec->hp_path,
2186 &spec->hp_mix_path);
2188 /* update speaker path */
2189 update_aamix_paths(codec, val, &spec->speaker_path,
2190 &spec->speaker_mix_path);
2194 static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2195 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2196 .name = "Loopback Mixing",
2197 .info = via_aamix_ctl_info,
2198 .get = via_aamix_ctl_get,
2199 .put = via_aamix_ctl_put,
2202 static int via_auto_create_loopback_switch(struct hda_codec *codec)
2204 struct via_spec *spec = codec->spec;
2206 if (!spec->aa_mix_nid || !spec->out_mix_path.depth)
2207 return 0; /* no loopback switching available */
2208 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2214 static int via_fill_adcs(struct hda_codec *codec)
2216 struct via_spec *spec = codec->spec;
2217 hda_nid_t nid = codec->start_nid;
2220 for (i = 0; i < codec->num_nodes; i++, nid++) {
2221 unsigned int wcaps = get_wcaps(codec, nid);
2222 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2224 if (wcaps & AC_WCAP_DIGITAL)
2226 if (!(wcaps & AC_WCAP_CONN_LIST))
2228 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2230 spec->adc_nids[spec->num_adc_nids++] = nid;
2235 /* input-src control */
2236 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2237 struct snd_ctl_elem_info *uinfo)
2239 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2240 struct via_spec *spec = codec->spec;
2242 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2244 uinfo->value.enumerated.items = spec->num_inputs;
2245 if (uinfo->value.enumerated.item >= spec->num_inputs)
2246 uinfo->value.enumerated.item = spec->num_inputs - 1;
2247 strcpy(uinfo->value.enumerated.name,
2248 spec->inputs[uinfo->value.enumerated.item].label);
2252 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2253 struct snd_ctl_elem_value *ucontrol)
2255 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2256 struct via_spec *spec = codec->spec;
2257 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2259 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2263 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2264 struct snd_ctl_elem_value *ucontrol)
2266 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2267 struct via_spec *spec = codec->spec;
2268 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2272 cur = ucontrol->value.enumerated.item[0];
2273 if (cur < 0 || cur >= spec->num_inputs)
2275 if (spec->cur_mux[idx] == cur)
2277 spec->cur_mux[idx] = cur;
2278 if (spec->dyn_adc_switch) {
2279 int adc_idx = spec->inputs[cur].adc_idx;
2280 mux = spec->mux_nids[adc_idx];
2281 via_dyn_adc_pcm_resetup(codec, cur);
2283 mux = spec->mux_nids[idx];
2284 if (snd_BUG_ON(!mux))
2289 /* switch to D0 beofre change index */
2290 if (snd_hda_codec_read(codec, mux, 0,
2291 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
2292 snd_hda_codec_write(codec, mux, 0,
2293 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2294 snd_hda_codec_write(codec, mux, 0,
2295 AC_VERB_SET_CONNECT_SEL,
2296 spec->inputs[cur].mux_idx);
2299 /* update jack power state */
2300 set_widgets_power_state(codec);
2304 static const struct snd_kcontrol_new via_input_src_ctl = {
2305 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2306 /* The multiple "Capture Source" controls confuse alsamixer
2307 * So call somewhat different..
2309 /* .name = "Capture Source", */
2310 .name = "Input Source",
2311 .info = via_mux_enum_info,
2312 .get = via_mux_enum_get,
2313 .put = via_mux_enum_put,
2316 static int create_input_src_ctls(struct hda_codec *codec, int count)
2318 struct via_spec *spec = codec->spec;
2319 struct snd_kcontrol_new *knew;
2321 if (spec->num_inputs <= 1 || !count)
2322 return 0; /* no need for single src */
2324 knew = via_clone_control(spec, &via_input_src_ctl);
2327 knew->count = count;
2331 /* add the powersave loopback-list entry */
2332 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2334 struct hda_amp_list *list;
2336 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2338 list = spec->loopback_list + spec->num_loopbacks;
2340 list->dir = HDA_INPUT;
2342 spec->num_loopbacks++;
2343 spec->loopback.amplist = spec->loopback_list;
2346 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2349 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2352 /* add the input-route to the given pin */
2353 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2355 struct via_spec *spec = codec->spec;
2358 spec->inputs[spec->num_inputs].adc_idx = -1;
2359 spec->inputs[spec->num_inputs].pin = pin;
2360 for (c = 0; c < spec->num_adc_nids; c++) {
2361 if (spec->mux_nids[c]) {
2362 idx = get_connection_index(codec, spec->mux_nids[c],
2366 spec->inputs[spec->num_inputs].mux_idx = idx;
2368 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2371 spec->inputs[spec->num_inputs].adc_idx = c;
2372 /* Can primary ADC satisfy all inputs? */
2373 if (!spec->dyn_adc_switch &&
2374 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2375 snd_printd(KERN_INFO
2376 "via: dynamic ADC switching enabled\n");
2377 spec->dyn_adc_switch = 1;
2384 static int get_mux_nids(struct hda_codec *codec);
2386 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2387 static int parse_analog_inputs(struct hda_codec *codec)
2389 struct via_spec *spec = codec->spec;
2390 const struct auto_pin_cfg *cfg = &spec->autocfg;
2393 err = via_fill_adcs(codec);
2396 err = get_mux_nids(codec);
2400 /* fill all input-routes */
2401 for (i = 0; i < cfg->num_inputs; i++) {
2402 if (add_input_route(codec, cfg->inputs[i].pin))
2403 spec->inputs[spec->num_inputs++].label =
2404 hda_get_autocfg_input_label(codec, cfg, i);
2407 /* check for internal loopback recording */
2408 if (spec->aa_mix_nid &&
2409 add_input_route(codec, spec->aa_mix_nid))
2410 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2415 /* create analog-loopback volume/switch controls */
2416 static int create_loopback_ctls(struct hda_codec *codec)
2418 struct via_spec *spec = codec->spec;
2419 const struct auto_pin_cfg *cfg = &spec->autocfg;
2420 const char *prev_label = NULL;
2424 if (!spec->aa_mix_nid)
2427 for (i = 0; i < cfg->num_inputs; i++) {
2428 hda_nid_t pin = cfg->inputs[i].pin;
2429 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2431 if (prev_label && !strcmp(label, prev_label))
2436 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2438 err = via_new_analog_input(spec, label, type_idx,
2439 idx, spec->aa_mix_nid);
2442 add_loopback_list(spec, spec->aa_mix_nid, idx);
2445 /* remember the label for smart51 control */
2446 for (j = 0; j < spec->smart51_nums; j++) {
2447 if (spec->smart51_pins[j] == pin) {
2448 spec->smart51_idxs[j] = idx;
2449 spec->smart51_labels[j] = label;
2457 /* create mic-boost controls (if present) */
2458 static int create_mic_boost_ctls(struct hda_codec *codec)
2460 struct via_spec *spec = codec->spec;
2461 const struct auto_pin_cfg *cfg = &spec->autocfg;
2464 for (i = 0; i < cfg->num_inputs; i++) {
2465 hda_nid_t pin = cfg->inputs[i].pin;
2470 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2472 caps = query_amp_caps(codec, pin, HDA_INPUT);
2473 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2475 label = hda_get_autocfg_input_label(codec, cfg, i);
2476 snprintf(name, sizeof(name), "%s Boost Volume", label);
2477 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2478 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2485 /* create capture and input-src controls for multiple streams */
2486 static int create_multi_adc_ctls(struct hda_codec *codec)
2488 struct via_spec *spec = codec->spec;
2491 /* create capture mixer elements */
2492 for (i = 0; i < spec->num_adc_nids; i++) {
2493 hda_nid_t adc = spec->adc_nids[i];
2494 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2495 "Capture Volume", i,
2496 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2500 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2501 "Capture Switch", i,
2502 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2508 /* input-source control */
2509 for (i = 0; i < spec->num_adc_nids; i++)
2510 if (!spec->mux_nids[i])
2512 err = create_input_src_ctls(codec, i);
2518 /* bind capture volume/switch */
2519 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2520 HDA_BIND_VOL("Capture Volume", 0);
2521 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2522 HDA_BIND_SW("Capture Switch", 0);
2524 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2525 struct hda_ctl_ops *ops)
2527 struct hda_bind_ctls *ctl;
2530 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2534 for (i = 0; i < spec->num_adc_nids; i++)
2536 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2541 /* create capture and input-src controls for dynamic ADC-switch case */
2542 static int create_dyn_adc_ctls(struct hda_codec *codec)
2544 struct via_spec *spec = codec->spec;
2545 struct snd_kcontrol_new *knew;
2548 /* set up the bind capture ctls */
2549 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2552 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2556 /* create capture mixer elements */
2557 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2560 knew->private_value = (long)spec->bind_cap_vol;
2562 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2565 knew->private_value = (long)spec->bind_cap_sw;
2567 /* input-source control */
2568 err = create_input_src_ctls(codec, 1);
2574 /* parse and create capture-related stuff */
2575 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2577 struct via_spec *spec = codec->spec;
2580 err = parse_analog_inputs(codec);
2583 if (spec->dyn_adc_switch)
2584 err = create_dyn_adc_ctls(codec);
2586 err = create_multi_adc_ctls(codec);
2589 err = create_loopback_ctls(codec);
2592 err = create_mic_boost_ctls(codec);
2598 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2600 unsigned int def_conf;
2601 unsigned char seqassoc;
2603 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2604 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2605 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2606 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2607 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2608 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2609 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2615 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2616 struct snd_ctl_elem_value *ucontrol)
2618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2619 struct via_spec *spec = codec->spec;
2621 if (spec->codec_type != VT1708)
2623 spec->vt1708_jack_detect =
2624 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2625 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2629 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2630 struct snd_ctl_elem_value *ucontrol)
2632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2633 struct via_spec *spec = codec->spec;
2636 if (spec->codec_type != VT1708)
2638 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2639 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2640 == !spec->vt1708_jack_detect;
2641 if (spec->vt1708_jack_detect) {
2642 mute_aa_path(codec, 1);
2643 notify_aa_path_ctls(codec);
2648 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2649 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2650 .name = "Jack Detect",
2652 .info = snd_ctl_boolean_mono_info,
2653 .get = vt1708_jack_detect_get,
2654 .put = vt1708_jack_detect_put,
2657 static void fill_dig_outs(struct hda_codec *codec);
2658 static void fill_dig_in(struct hda_codec *codec);
2660 static int via_parse_auto_config(struct hda_codec *codec)
2662 struct via_spec *spec = codec->spec;
2665 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2668 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2671 err = via_auto_create_multi_out_ctls(codec);
2674 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2677 err = via_auto_create_speaker_ctls(codec);
2680 err = via_auto_create_loopback_switch(codec);
2683 err = via_auto_create_analog_input_ctls(codec);
2687 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2689 fill_dig_outs(codec);
2692 if (spec->kctls.list)
2693 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2696 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
2697 err = via_hp_build(codec);
2702 err = via_smart51_build(codec);
2706 /* assign slave outs */
2707 if (spec->slave_dig_outs[0])
2708 codec->slave_dig_outs = spec->slave_dig_outs;
2713 static void via_auto_init_dig_outs(struct hda_codec *codec)
2715 struct via_spec *spec = codec->spec;
2716 if (spec->multiout.dig_out_nid)
2717 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2718 if (spec->slave_dig_outs[0])
2719 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2722 static void via_auto_init_dig_in(struct hda_codec *codec)
2724 struct via_spec *spec = codec->spec;
2725 if (!spec->dig_in_nid)
2727 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2728 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2731 /* initialize the unsolicited events */
2732 static void via_auto_init_unsol_event(struct hda_codec *codec)
2734 struct via_spec *spec = codec->spec;
2735 struct auto_pin_cfg *cfg = &spec->autocfg;
2739 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2740 snd_hda_jack_detect_enable(codec, cfg->hp_pins[0],
2741 VIA_HP_EVENT | VIA_JACK_EVENT);
2743 if (cfg->speaker_pins[0])
2744 ev = VIA_LINE_EVENT;
2747 for (i = 0; i < cfg->line_outs; i++) {
2748 if (cfg->line_out_pins[i] &&
2749 is_jack_detectable(codec, cfg->line_out_pins[i]))
2750 snd_hda_jack_detect_enable(codec, cfg->line_out_pins[i],
2751 ev | VIA_JACK_EVENT);
2754 for (i = 0; i < cfg->num_inputs; i++) {
2755 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2756 snd_hda_jack_detect_enable(codec, cfg->inputs[i].pin,
2761 static int via_init(struct hda_codec *codec)
2763 struct via_spec *spec = codec->spec;
2766 for (i = 0; i < spec->num_iverbs; i++)
2767 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2769 via_auto_init_multi_out(codec);
2770 via_auto_init_hp_out(codec);
2771 via_auto_init_speaker_out(codec);
2772 via_auto_init_analog_input(codec);
2773 via_auto_init_dig_outs(codec);
2774 via_auto_init_dig_in(codec);
2776 via_auto_init_unsol_event(codec);
2778 via_hp_automute(codec);
2779 snd_hda_jack_report_sync(codec);
2784 static void vt1708_update_hp_jack_state(struct work_struct *work)
2786 struct via_spec *spec = container_of(work, struct via_spec,
2787 vt1708_hp_work.work);
2788 if (spec->codec_type != VT1708)
2790 snd_hda_jack_set_dirty_all(spec->codec);
2791 /* if jack state toggled */
2792 if (spec->vt1708_hp_present
2793 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2794 spec->vt1708_hp_present ^= 1;
2795 via_hp_automute(spec->codec);
2797 vt1708_start_hp_work(spec);
2800 static int get_mux_nids(struct hda_codec *codec)
2802 struct via_spec *spec = codec->spec;
2803 hda_nid_t nid, conn[8];
2807 for (i = 0; i < spec->num_adc_nids; i++) {
2808 nid = spec->adc_nids[i];
2810 type = get_wcaps_type(get_wcaps(codec, nid));
2811 if (type == AC_WID_PIN)
2813 n = snd_hda_get_connections(codec, nid, conn,
2818 spec->mux_nids[i] = nid;
2827 static int patch_vt1708(struct hda_codec *codec)
2829 struct via_spec *spec;
2832 /* create a codec specific record */
2833 spec = via_new_spec(codec);
2837 spec->aa_mix_nid = 0x17;
2839 /* Add HP and CD pin config connect bit re-config action */
2840 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2841 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2843 /* automatic parse from the BIOS config */
2844 err = via_parse_auto_config(codec);
2850 /* add jack detect on/off control */
2851 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2854 /* disable 32bit format on VT1708 */
2855 if (codec->vendor_id == 0x11061708)
2856 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2858 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2860 codec->patch_ops = via_patch_ops;
2862 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2866 static int patch_vt1709(struct hda_codec *codec)
2868 struct via_spec *spec;
2871 /* create a codec specific record */
2872 spec = via_new_spec(codec);
2876 spec->aa_mix_nid = 0x18;
2878 err = via_parse_auto_config(codec);
2884 codec->patch_ops = via_patch_ops;
2889 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2891 struct via_spec *spec = codec->spec;
2895 if ((spec->codec_type != VT1708B_4CH) &&
2896 (codec->vendor_id != 0x11064397))
2899 /* SW0 (17h) = stereo mixer */
2901 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2902 == ((spec->codec_type == VT1708S) ? 5 : 0));
2904 /* PW 1/2/5 (1ah/1bh/1eh) */
2906 set_pin_power_state(codec, 0x1a, &parm);
2907 set_pin_power_state(codec, 0x1b, &parm);
2908 set_pin_power_state(codec, 0x1e, &parm);
2911 /* SW0 (17h), AIW 0/1 (13h/14h) */
2912 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2913 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2914 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2917 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2919 set_pin_power_state(codec, 0x19, &parm);
2920 if (spec->smart51_enabled)
2921 set_pin_power_state(codec, 0x1b, &parm);
2922 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2923 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2925 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2928 set_pin_power_state(codec, 0x22, &parm);
2929 if (spec->smart51_enabled)
2930 set_pin_power_state(codec, 0x1a, &parm);
2931 snd_hda_codec_write(codec, 0x26, 0,
2932 AC_VERB_SET_POWER_STATE, parm);
2933 snd_hda_codec_write(codec, 0x24, 0,
2934 AC_VERB_SET_POWER_STATE, parm);
2935 } else if (codec->vendor_id == 0x11064397) {
2936 /* PW7(23h), SW2(27h), AOW2(25h) */
2938 set_pin_power_state(codec, 0x23, &parm);
2939 if (spec->smart51_enabled)
2940 set_pin_power_state(codec, 0x1a, &parm);
2941 snd_hda_codec_write(codec, 0x27, 0,
2942 AC_VERB_SET_POWER_STATE, parm);
2943 snd_hda_codec_write(codec, 0x25, 0,
2944 AC_VERB_SET_POWER_STATE, parm);
2947 /* PW 3/4/7 (1ch/1dh/23h) */
2949 /* force to D0 for internal Speaker */
2950 set_pin_power_state(codec, 0x1c, &parm);
2951 set_pin_power_state(codec, 0x1d, &parm);
2953 set_pin_power_state(codec, 0x23, &parm);
2955 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2956 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2957 imux_is_smixer ? AC_PWRST_D0 : parm);
2958 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2960 snd_hda_codec_write(codec, 0x25, 0,
2961 AC_VERB_SET_POWER_STATE, parm);
2962 snd_hda_codec_write(codec, 0x27, 0,
2963 AC_VERB_SET_POWER_STATE, parm);
2964 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2965 snd_hda_codec_write(codec, 0x25, 0,
2966 AC_VERB_SET_POWER_STATE, parm);
2969 static int patch_vt1708S(struct hda_codec *codec);
2970 static int patch_vt1708B(struct hda_codec *codec)
2972 struct via_spec *spec;
2975 if (get_codec_type(codec) == VT1708BCE)
2976 return patch_vt1708S(codec);
2978 /* create a codec specific record */
2979 spec = via_new_spec(codec);
2983 spec->aa_mix_nid = 0x16;
2985 /* automatic parse from the BIOS config */
2986 err = via_parse_auto_config(codec);
2992 codec->patch_ops = via_patch_ops;
2994 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2999 /* Patch for VT1708S */
3000 static const struct hda_verb vt1708S_init_verbs[] = {
3001 /* Enable Mic Boost Volume backdoor */
3003 /* don't bybass mixer */
3008 /* fill out digital output widgets; one for master and one for slave outputs */
3009 static void fill_dig_outs(struct hda_codec *codec)
3011 struct via_spec *spec = codec->spec;
3014 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3018 nid = spec->autocfg.dig_out_pins[i];
3021 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3024 if (!spec->multiout.dig_out_nid)
3025 spec->multiout.dig_out_nid = nid;
3027 spec->slave_dig_outs[0] = nid;
3028 break; /* at most two dig outs */
3033 static void fill_dig_in(struct hda_codec *codec)
3035 struct via_spec *spec = codec->spec;
3039 if (!spec->autocfg.dig_in_pin)
3042 dig_nid = codec->start_nid;
3043 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3044 unsigned int wcaps = get_wcaps(codec, dig_nid);
3045 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3047 if (!(wcaps & AC_WCAP_DIGITAL))
3049 if (!(wcaps & AC_WCAP_CONN_LIST))
3051 err = get_connection_index(codec, dig_nid,
3052 spec->autocfg.dig_in_pin);
3054 spec->dig_in_nid = dig_nid;
3060 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3061 int offset, int num_steps, int step_size)
3063 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3064 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3065 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3066 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3067 (0 << AC_AMPCAP_MUTE_SHIFT));
3070 static int patch_vt1708S(struct hda_codec *codec)
3072 struct via_spec *spec;
3075 /* create a codec specific record */
3076 spec = via_new_spec(codec);
3080 spec->aa_mix_nid = 0x16;
3081 override_mic_boost(codec, 0x1a, 0, 3, 40);
3082 override_mic_boost(codec, 0x1e, 0, 3, 40);
3084 /* automatic parse from the BIOS config */
3085 err = via_parse_auto_config(codec);
3091 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
3093 codec->patch_ops = via_patch_ops;
3095 /* correct names for VT1708BCE */
3096 if (get_codec_type(codec) == VT1708BCE) {
3097 kfree(codec->chip_name);
3098 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3099 snprintf(codec->bus->card->mixername,
3100 sizeof(codec->bus->card->mixername),
3101 "%s %s", codec->vendor_name, codec->chip_name);
3103 /* correct names for VT1705 */
3104 if (codec->vendor_id == 0x11064397) {
3105 kfree(codec->chip_name);
3106 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3107 snprintf(codec->bus->card->mixername,
3108 sizeof(codec->bus->card->mixername),
3109 "%s %s", codec->vendor_name, codec->chip_name);
3111 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3115 /* Patch for VT1702 */
3117 static const struct hda_verb vt1702_init_verbs[] = {
3125 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3127 int imux_is_smixer =
3128 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3131 /* PW 1/2/5 (14h/15h/18h) */
3133 set_pin_power_state(codec, 0x14, &parm);
3134 set_pin_power_state(codec, 0x15, &parm);
3135 set_pin_power_state(codec, 0x18, &parm);
3137 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3138 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3139 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3140 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
3141 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3142 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
3145 /* PW 3/4 (16h/17h) */
3147 set_pin_power_state(codec, 0x17, &parm);
3148 set_pin_power_state(codec, 0x16, &parm);
3149 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3150 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
3151 imux_is_smixer ? AC_PWRST_D0 : parm);
3152 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3153 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3156 static int patch_vt1702(struct hda_codec *codec)
3158 struct via_spec *spec;
3161 /* create a codec specific record */
3162 spec = via_new_spec(codec);
3166 spec->aa_mix_nid = 0x1a;
3168 /* limit AA path volume to 0 dB */
3169 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3170 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3171 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3172 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3173 (1 << AC_AMPCAP_MUTE_SHIFT));
3175 /* automatic parse from the BIOS config */
3176 err = via_parse_auto_config(codec);
3182 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
3184 codec->patch_ops = via_patch_ops;
3186 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
3190 /* Patch for VT1718S */
3192 static const struct hda_verb vt1718S_init_verbs[] = {
3193 /* Enable MW0 adjust Gain 5 */
3195 /* Enable Boost Volume backdoor */
3201 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3203 struct via_spec *spec = codec->spec;
3206 /* MUX6 (1eh) = stereo mixer */
3208 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3210 /* PW 5/6/7 (29h/2ah/2bh) */
3212 set_pin_power_state(codec, 0x29, &parm);
3213 set_pin_power_state(codec, 0x2a, &parm);
3214 set_pin_power_state(codec, 0x2b, &parm);
3217 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3218 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3219 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3220 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3221 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3224 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3226 set_pin_power_state(codec, 0x27, &parm);
3227 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
3228 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
3230 /* PW2 (26h), AOW2 (ah) */
3232 set_pin_power_state(codec, 0x26, &parm);
3233 if (spec->smart51_enabled)
3234 set_pin_power_state(codec, 0x2b, &parm);
3235 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
3237 /* PW0 (24h), AOW0 (8h) */
3239 set_pin_power_state(codec, 0x24, &parm);
3240 if (!spec->hp_independent_mode) /* check for redirected HP */
3241 set_pin_power_state(codec, 0x28, &parm);
3242 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3243 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3244 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3245 imux_is_smixer ? AC_PWRST_D0 : parm);
3247 /* PW1 (25h), AOW1 (9h) */
3249 set_pin_power_state(codec, 0x25, &parm);
3250 if (spec->smart51_enabled)
3251 set_pin_power_state(codec, 0x2a, &parm);
3252 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3254 if (spec->hp_independent_mode) {
3255 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3257 set_pin_power_state(codec, 0x28, &parm);
3258 snd_hda_codec_write(codec, 0x1b, 0,
3259 AC_VERB_SET_POWER_STATE, parm);
3260 snd_hda_codec_write(codec, 0x34, 0,
3261 AC_VERB_SET_POWER_STATE, parm);
3262 snd_hda_codec_write(codec, 0xc, 0,
3263 AC_VERB_SET_POWER_STATE, parm);
3267 /* Add a connection to the primary DAC from AA-mixer for some codecs
3268 * This isn't listed from the raw info, but the chip has a secret connection.
3270 static int add_secret_dac_path(struct hda_codec *codec)
3272 struct via_spec *spec = codec->spec;
3277 if (!spec->aa_mix_nid)
3279 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3280 ARRAY_SIZE(conn) - 1);
3281 for (i = 0; i < nums; i++) {
3282 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3286 /* find the primary DAC and add to the connection list */
3287 nid = codec->start_nid;
3288 for (i = 0; i < codec->num_nodes; i++, nid++) {
3289 unsigned int caps = get_wcaps(codec, nid);
3290 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3291 !(caps & AC_WCAP_DIGITAL)) {
3293 return snd_hda_override_conn_list(codec,
3302 static int patch_vt1718S(struct hda_codec *codec)
3304 struct via_spec *spec;
3307 /* create a codec specific record */
3308 spec = via_new_spec(codec);
3312 spec->aa_mix_nid = 0x21;
3313 override_mic_boost(codec, 0x2b, 0, 3, 40);
3314 override_mic_boost(codec, 0x29, 0, 3, 40);
3315 add_secret_dac_path(codec);
3317 /* automatic parse from the BIOS config */
3318 err = via_parse_auto_config(codec);
3324 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3326 codec->patch_ops = via_patch_ops;
3328 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3333 /* Patch for VT1716S */
3335 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3336 struct snd_ctl_elem_info *uinfo)
3338 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3340 uinfo->value.integer.min = 0;
3341 uinfo->value.integer.max = 1;
3345 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3346 struct snd_ctl_elem_value *ucontrol)
3348 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3351 index = snd_hda_codec_read(codec, 0x26, 0,
3352 AC_VERB_GET_CONNECT_SEL, 0);
3354 *ucontrol->value.integer.value = index;
3359 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3360 struct snd_ctl_elem_value *ucontrol)
3362 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3363 struct via_spec *spec = codec->spec;
3364 int index = *ucontrol->value.integer.value;
3366 snd_hda_codec_write(codec, 0x26, 0,
3367 AC_VERB_SET_CONNECT_SEL, index);
3368 spec->dmic_enabled = index;
3369 set_widgets_power_state(codec);
3373 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3374 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3376 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3377 .name = "Digital Mic Capture Switch",
3378 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3380 .info = vt1716s_dmic_info,
3381 .get = vt1716s_dmic_get,
3382 .put = vt1716s_dmic_put,
3388 /* mono-out mixer elements */
3389 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3390 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3394 static const struct hda_verb vt1716S_init_verbs[] = {
3395 /* Enable Boost Volume backdoor */
3397 /* don't bybass mixer */
3399 /* Enable mono output */
3404 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3406 struct via_spec *spec = codec->spec;
3409 unsigned int mono_out, present;
3410 /* SW0 (17h) = stereo mixer */
3412 (snd_hda_codec_read(codec, 0x17, 0,
3413 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3415 /* PW 1/2/5 (1ah/1bh/1eh) */
3417 set_pin_power_state(codec, 0x1a, &parm);
3418 set_pin_power_state(codec, 0x1b, &parm);
3419 set_pin_power_state(codec, 0x1e, &parm);
3422 /* SW0 (17h), AIW0(13h) */
3423 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3424 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3427 set_pin_power_state(codec, 0x1e, &parm);
3429 if (spec->dmic_enabled)
3430 set_pin_power_state(codec, 0x22, &parm);
3432 snd_hda_codec_write(codec, 0x22, 0,
3433 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3435 /* SW2(26h), AIW1(14h) */
3436 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3437 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3440 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3442 set_pin_power_state(codec, 0x19, &parm);
3443 /* Smart 5.1 PW2(1bh) */
3444 if (spec->smart51_enabled)
3445 set_pin_power_state(codec, 0x1b, &parm);
3446 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3447 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3449 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3451 set_pin_power_state(codec, 0x23, &parm);
3452 /* Smart 5.1 PW1(1ah) */
3453 if (spec->smart51_enabled)
3454 set_pin_power_state(codec, 0x1a, &parm);
3455 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3457 /* Smart 5.1 PW5(1eh) */
3458 if (spec->smart51_enabled)
3459 set_pin_power_state(codec, 0x1e, &parm);
3460 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3463 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3464 present = snd_hda_jack_detect(codec, 0x1c);
3469 present = snd_hda_jack_detect(codec, 0x1d);
3470 if (!spec->hp_independent_mode && present)
3475 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3476 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3477 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3478 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3480 /* PW 3/4 (1ch/1dh) */
3482 set_pin_power_state(codec, 0x1c, &parm);
3483 set_pin_power_state(codec, 0x1d, &parm);
3484 /* HP Independent Mode, power on AOW3 */
3485 if (spec->hp_independent_mode)
3486 snd_hda_codec_write(codec, 0x25, 0,
3487 AC_VERB_SET_POWER_STATE, parm);
3489 /* force to D0 for internal Speaker */
3490 /* MW0 (16h), AOW0 (10h) */
3491 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3492 imux_is_smixer ? AC_PWRST_D0 : parm);
3493 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3494 mono_out ? AC_PWRST_D0 : parm);
3497 static int patch_vt1716S(struct hda_codec *codec)
3499 struct via_spec *spec;
3502 /* create a codec specific record */
3503 spec = via_new_spec(codec);
3507 spec->aa_mix_nid = 0x16;
3508 override_mic_boost(codec, 0x1a, 0, 3, 40);
3509 override_mic_boost(codec, 0x1e, 0, 3, 40);
3511 /* automatic parse from the BIOS config */
3512 err = via_parse_auto_config(codec);
3518 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3520 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3523 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3525 codec->patch_ops = via_patch_ops;
3527 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3533 static const struct hda_verb vt2002P_init_verbs[] = {
3534 /* Class-D speaker related verbs */
3538 /* Enable Boost Volume backdoor */
3540 /* Enable AOW0 to MW9 */
3545 static const struct hda_verb vt1802_init_verbs[] = {
3546 /* Enable Boost Volume backdoor */
3548 /* Enable AOW0 to MW9 */
3553 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3555 struct via_spec *spec = codec->spec;
3558 unsigned int present;
3559 /* MUX9 (1eh) = stereo mixer */
3561 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3563 /* PW 5/6/7 (29h/2ah/2bh) */
3565 set_pin_power_state(codec, 0x29, &parm);
3566 set_pin_power_state(codec, 0x2a, &parm);
3567 set_pin_power_state(codec, 0x2b, &parm);
3569 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3570 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3571 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3572 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3573 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3577 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3579 if (spec->codec_type == VT1802) {
3580 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3582 set_pin_power_state(codec, 0x28, &parm);
3583 snd_hda_codec_write(codec, 0x18, 0,
3584 AC_VERB_SET_POWER_STATE, parm);
3585 snd_hda_codec_write(codec, 0x38, 0,
3586 AC_VERB_SET_POWER_STATE, parm);
3588 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3590 set_pin_power_state(codec, 0x26, &parm);
3591 snd_hda_codec_write(codec, 0x1c, 0,
3592 AC_VERB_SET_POWER_STATE, parm);
3593 snd_hda_codec_write(codec, 0x37, 0,
3594 AC_VERB_SET_POWER_STATE, parm);
3597 if (spec->codec_type == VT1802) {
3598 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3600 set_pin_power_state(codec, 0x25, &parm);
3601 snd_hda_codec_write(codec, 0x15, 0,
3602 AC_VERB_SET_POWER_STATE, parm);
3603 snd_hda_codec_write(codec, 0x35, 0,
3604 AC_VERB_SET_POWER_STATE, parm);
3606 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3608 set_pin_power_state(codec, 0x25, &parm);
3609 snd_hda_codec_write(codec, 0x19, 0,
3610 AC_VERB_SET_POWER_STATE, parm);
3611 snd_hda_codec_write(codec, 0x35, 0,
3612 AC_VERB_SET_POWER_STATE, parm);
3615 if (spec->hp_independent_mode)
3616 snd_hda_codec_write(codec, 0x9, 0,
3617 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3620 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3621 present = snd_hda_jack_detect(codec, 0x25);
3624 set_pin_power_state(codec, 0x24, &parm);
3625 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3626 if (spec->codec_type == VT1802)
3627 snd_hda_codec_write(codec, 0x14, 0,
3628 AC_VERB_SET_POWER_STATE, parm);
3630 snd_hda_codec_write(codec, 0x18, 0,
3631 AC_VERB_SET_POWER_STATE, parm);
3632 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3635 present = snd_hda_jack_detect(codec, 0x26);
3637 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3638 if (spec->codec_type == VT1802) {
3639 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3640 snd_hda_codec_write(codec, 0x33, 0,
3641 AC_VERB_SET_POWER_STATE, parm);
3642 snd_hda_codec_write(codec, 0x1c, 0,
3643 AC_VERB_SET_POWER_STATE, parm);
3644 snd_hda_codec_write(codec, 0x3c, 0,
3645 AC_VERB_SET_POWER_STATE, parm);
3647 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3648 snd_hda_codec_write(codec, 0x31, 0,
3649 AC_VERB_SET_POWER_STATE, parm);
3650 snd_hda_codec_write(codec, 0x17, 0,
3651 AC_VERB_SET_POWER_STATE, parm);
3652 snd_hda_codec_write(codec, 0x3b, 0,
3653 AC_VERB_SET_POWER_STATE, parm);
3656 if (imux_is_smixer || !is_aa_path_mute(codec))
3657 snd_hda_codec_write(codec, 0x21, 0,
3658 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3660 snd_hda_codec_write(codec, 0x21, 0,
3661 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3664 /* patch for vt2002P */
3665 static int patch_vt2002P(struct hda_codec *codec)
3667 struct via_spec *spec;
3670 /* create a codec specific record */
3671 spec = via_new_spec(codec);
3675 spec->aa_mix_nid = 0x21;
3676 override_mic_boost(codec, 0x2b, 0, 3, 40);
3677 override_mic_boost(codec, 0x29, 0, 3, 40);
3678 add_secret_dac_path(codec);
3680 /* automatic parse from the BIOS config */
3681 err = via_parse_auto_config(codec);
3687 if (spec->codec_type == VT1802)
3688 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3690 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3692 codec->patch_ops = via_patch_ops;
3694 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3700 static const struct hda_verb vt1812_init_verbs[] = {
3701 /* Enable Boost Volume backdoor */
3703 /* Enable AOW0 to MW9 */
3708 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3710 struct via_spec *spec = codec->spec;
3712 unsigned int present;
3714 /* PW 5/6/7 (29h/2ah/2bh) */
3716 set_pin_power_state(codec, 0x29, &parm);
3717 set_pin_power_state(codec, 0x2a, &parm);
3718 set_pin_power_state(codec, 0x2b, &parm);
3720 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3721 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3722 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3723 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3724 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3728 snd_hda_codec_write(codec, 0x8, 0,
3729 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3731 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3733 set_pin_power_state(codec, 0x28, &parm);
3734 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3735 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3737 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3739 set_pin_power_state(codec, 0x25, &parm);
3740 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3741 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3742 if (spec->hp_independent_mode)
3743 snd_hda_codec_write(codec, 0x9, 0,
3744 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3746 /* Internal Speaker */
3747 /* PW0 (24h), MW0(14h), MUX0(34h) */
3748 present = snd_hda_jack_detect(codec, 0x25);
3751 set_pin_power_state(codec, 0x24, &parm);
3753 snd_hda_codec_write(codec, 0x14, 0,
3754 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3755 snd_hda_codec_write(codec, 0x34, 0,
3756 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3758 snd_hda_codec_write(codec, 0x14, 0,
3759 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3760 snd_hda_codec_write(codec, 0x34, 0,
3761 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3766 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3767 present = snd_hda_jack_detect(codec, 0x28);
3770 set_pin_power_state(codec, 0x31, &parm);
3772 snd_hda_codec_write(codec, 0x1c, 0,
3773 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3774 snd_hda_codec_write(codec, 0x3c, 0,
3775 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3776 snd_hda_codec_write(codec, 0x3e, 0,
3777 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3779 snd_hda_codec_write(codec, 0x1c, 0,
3780 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3781 snd_hda_codec_write(codec, 0x3c, 0,
3782 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3783 snd_hda_codec_write(codec, 0x3e, 0,
3784 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3787 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3789 set_pin_power_state(codec, 0x33, &parm);
3790 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3791 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3795 /* patch for vt1812 */
3796 static int patch_vt1812(struct hda_codec *codec)
3798 struct via_spec *spec;
3801 /* create a codec specific record */
3802 spec = via_new_spec(codec);
3806 spec->aa_mix_nid = 0x21;
3807 override_mic_boost(codec, 0x2b, 0, 3, 40);
3808 override_mic_boost(codec, 0x29, 0, 3, 40);
3809 add_secret_dac_path(codec);
3811 /* automatic parse from the BIOS config */
3812 err = via_parse_auto_config(codec);
3818 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3820 codec->patch_ops = via_patch_ops;
3822 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3829 static const struct hda_codec_preset snd_hda_preset_via[] = {
3830 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3831 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3832 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3833 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3834 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3835 .patch = patch_vt1709},
3836 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3837 .patch = patch_vt1709},
3838 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3839 .patch = patch_vt1709},
3840 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3841 .patch = patch_vt1709},
3842 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3843 .patch = patch_vt1709},
3844 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3845 .patch = patch_vt1709},
3846 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3847 .patch = patch_vt1709},
3848 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3849 .patch = patch_vt1709},
3850 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3851 .patch = patch_vt1708B},
3852 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3853 .patch = patch_vt1708B},
3854 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3855 .patch = patch_vt1708B},
3856 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3857 .patch = patch_vt1708B},
3858 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3859 .patch = patch_vt1708B},
3860 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3861 .patch = patch_vt1708B},
3862 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3863 .patch = patch_vt1708B},
3864 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3865 .patch = patch_vt1708B},
3866 { .id = 0x11060397, .name = "VT1708S",
3867 .patch = patch_vt1708S},
3868 { .id = 0x11061397, .name = "VT1708S",
3869 .patch = patch_vt1708S},
3870 { .id = 0x11062397, .name = "VT1708S",
3871 .patch = patch_vt1708S},
3872 { .id = 0x11063397, .name = "VT1708S",
3873 .patch = patch_vt1708S},
3874 { .id = 0x11064397, .name = "VT1705",
3875 .patch = patch_vt1708S},
3876 { .id = 0x11065397, .name = "VT1708S",
3877 .patch = patch_vt1708S},
3878 { .id = 0x11066397, .name = "VT1708S",
3879 .patch = patch_vt1708S},
3880 { .id = 0x11067397, .name = "VT1708S",
3881 .patch = patch_vt1708S},
3882 { .id = 0x11060398, .name = "VT1702",
3883 .patch = patch_vt1702},
3884 { .id = 0x11061398, .name = "VT1702",
3885 .patch = patch_vt1702},
3886 { .id = 0x11062398, .name = "VT1702",
3887 .patch = patch_vt1702},
3888 { .id = 0x11063398, .name = "VT1702",
3889 .patch = patch_vt1702},
3890 { .id = 0x11064398, .name = "VT1702",
3891 .patch = patch_vt1702},
3892 { .id = 0x11065398, .name = "VT1702",
3893 .patch = patch_vt1702},
3894 { .id = 0x11066398, .name = "VT1702",
3895 .patch = patch_vt1702},
3896 { .id = 0x11067398, .name = "VT1702",
3897 .patch = patch_vt1702},
3898 { .id = 0x11060428, .name = "VT1718S",
3899 .patch = patch_vt1718S},
3900 { .id = 0x11064428, .name = "VT1718S",
3901 .patch = patch_vt1718S},
3902 { .id = 0x11060441, .name = "VT2020",
3903 .patch = patch_vt1718S},
3904 { .id = 0x11064441, .name = "VT1828S",
3905 .patch = patch_vt1718S},
3906 { .id = 0x11060433, .name = "VT1716S",
3907 .patch = patch_vt1716S},
3908 { .id = 0x1106a721, .name = "VT1716S",
3909 .patch = patch_vt1716S},
3910 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3911 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3912 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3913 { .id = 0x11060440, .name = "VT1818S",
3914 .patch = patch_vt1708S},
3915 { .id = 0x11060446, .name = "VT1802",
3916 .patch = patch_vt2002P},
3917 { .id = 0x11068446, .name = "VT1802",
3918 .patch = patch_vt2002P},
3922 MODULE_ALIAS("snd-hda-codec-id:1106*");
3924 static struct hda_codec_preset_list via_list = {
3925 .preset = snd_hda_preset_via,
3926 .owner = THIS_MODULE,
3929 MODULE_LICENSE("GPL");
3930 MODULE_DESCRIPTION("VIA HD-audio codec");
3932 static int __init patch_via_init(void)
3934 return snd_hda_add_codec_preset(&via_list);
3937 static void __exit patch_via_exit(void)
3939 snd_hda_delete_codec_preset(&via_list);
3942 module_init(patch_via_init)
3943 module_exit(patch_via_exit)