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"
59 #define VT1708_HP_PIN_NID 0x20
60 #define VT1708_CD_PIN_NID 0x24
80 #define VT2002P_COMPATIBLE(spec) \
81 ((spec)->codec_type == VT2002P ||\
82 (spec)->codec_type == VT1812 ||\
83 (spec)->codec_type == VT1802)
85 #define MAX_NID_PATH_DEPTH 5
87 /* output-path: DAC -> ... -> pin
88 * idx[] contains the source index number of the next widget;
89 * e.g. idx[0] is the index of the DAC selected by path[1] widget
90 * multi[] indicates whether it's a selector widget with multi-connectors
91 * (i.e. the connection selection is mandatory)
92 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
96 hda_nid_t path[MAX_NID_PATH_DEPTH];
97 unsigned char idx[MAX_NID_PATH_DEPTH];
98 unsigned char multi[MAX_NID_PATH_DEPTH];
100 unsigned int mute_ctl;
105 hda_nid_t pin; /* input-pin or aa-mix */
106 int adc_idx; /* ADC index to be used */
107 int mux_idx; /* MUX index (if any) */
108 const char *label; /* input-source label */
111 #define VIA_MAX_ADCS 3
114 STREAM_MULTI_OUT = (1 << 0),
115 STREAM_INDEP_HP = (1 << 1),
119 /* codec parameterization */
120 const struct snd_kcontrol_new *mixers[6];
121 unsigned int num_mixers;
123 const struct hda_verb *init_verbs[5];
124 unsigned int num_iverbs;
126 char stream_name_analog[32];
127 char stream_name_hp[32];
128 const struct hda_pcm_stream *stream_analog_playback;
129 const struct hda_pcm_stream *stream_analog_capture;
131 char stream_name_digital[32];
132 const struct hda_pcm_stream *stream_digital_playback;
133 const struct hda_pcm_stream *stream_digital_capture;
136 struct hda_multi_out multiout;
137 hda_nid_t slave_dig_outs[2];
138 hda_nid_t hp_dac_nid;
139 hda_nid_t speaker_dac_nid;
140 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
141 int opened_streams; /* STREAM_* bits */
142 int active_streams; /* STREAM_* bits */
143 int aamix_mode; /* loopback is enabled for output-path? */
146 * There are different output-paths depending on the setup.
147 * out_path, hp_path and speaker_path are primary paths. If both
148 * direct DAC and aa-loopback routes are available, these contain
149 * the former paths. Meanwhile *_mix_path contain the paths with
150 * loopback mixer. (Since the loopback is only for front channel,
151 * no out_mix_path for surround channels.)
152 * The HP output has another path, hp_indep_path, which is used in
153 * the independent-HP mode.
155 struct nid_path out_path[HDA_SIDE + 1];
156 struct nid_path out_mix_path;
157 struct nid_path hp_path;
158 struct nid_path hp_mix_path;
159 struct nid_path hp_indep_path;
160 struct nid_path speaker_path;
161 struct nid_path speaker_mix_path;
164 unsigned int num_adc_nids;
165 hda_nid_t adc_nids[VIA_MAX_ADCS];
166 hda_nid_t mux_nids[VIA_MAX_ADCS];
167 hda_nid_t aa_mix_nid;
168 hda_nid_t dig_in_nid;
173 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
174 unsigned int cur_mux[VIA_MAX_ADCS];
176 /* dynamic DAC switching */
177 unsigned int cur_dac_stream_tag;
178 unsigned int cur_dac_format;
179 unsigned int cur_hp_stream_tag;
180 unsigned int cur_hp_format;
182 /* dynamic ADC switching */
184 unsigned int cur_adc_stream_tag;
185 unsigned int cur_adc_format;
187 /* PCM information */
188 struct hda_pcm pcm_rec[3];
190 /* dynamic controls, init_verbs and input_mux */
191 struct auto_pin_cfg autocfg;
192 struct snd_array kctls;
193 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
196 unsigned int hp_independent_mode;
197 unsigned int dmic_enabled;
198 unsigned int no_pin_power_ctl;
199 enum VIA_HDA_CODEC codec_type;
202 unsigned int smart51_nums;
203 hda_nid_t smart51_pins[2];
205 const char *smart51_labels[2];
206 unsigned int smart51_enabled;
208 /* work to check hp jack state */
209 struct hda_codec *codec;
210 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 #define hp_detect_with_aa(codec) \
310 (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
311 !is_aa_path_mute(codec))
313 static void vt1708_stop_hp_work(struct via_spec *spec)
315 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
317 if (spec->hp_work_active) {
318 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
319 cancel_delayed_work_sync(&spec->vt1708_hp_work);
320 spec->hp_work_active = 0;
324 static void vt1708_update_hp_work(struct via_spec *spec)
326 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
328 if (spec->vt1708_jack_detect &&
329 (spec->active_streams || hp_detect_with_aa(spec->codec))) {
330 if (!spec->hp_work_active) {
331 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
332 schedule_delayed_work(&spec->vt1708_hp_work,
333 msecs_to_jiffies(100));
334 spec->hp_work_active = 1;
336 } else if (!hp_detect_with_aa(spec->codec))
337 vt1708_stop_hp_work(spec);
340 static void set_widgets_power_state(struct hda_codec *codec)
342 struct via_spec *spec = codec->spec;
343 if (spec->set_widgets_power_state)
344 spec->set_widgets_power_state(codec);
347 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
348 struct snd_ctl_elem_value *ucontrol)
350 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
351 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
353 set_widgets_power_state(codec);
354 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
355 vt1708_update_hp_work(codec->spec);
359 /* modify .put = snd_hda_mixer_amp_switch_put */
360 #define ANALOG_INPUT_MUTE \
361 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
364 .info = snd_hda_mixer_amp_switch_info, \
365 .get = snd_hda_mixer_amp_switch_get, \
366 .put = analog_input_switch_put, \
367 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
369 static const struct snd_kcontrol_new via_control_templates[] = {
370 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
371 HDA_CODEC_MUTE(NULL, 0, 0, 0),
376 /* add dynamic controls */
377 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
378 const struct snd_kcontrol_new *tmpl,
381 struct snd_kcontrol_new *knew;
383 snd_array_init(&spec->kctls, sizeof(*knew), 32);
384 knew = snd_array_new(&spec->kctls);
391 knew->name = kstrdup(name, GFP_KERNEL);
398 static int __via_add_control(struct via_spec *spec, int type, const char *name,
399 int idx, unsigned long val)
401 struct snd_kcontrol_new *knew;
403 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
407 if (get_amp_nid_(val))
408 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
409 knew->private_value = val;
413 #define via_add_control(spec, type, name, val) \
414 __via_add_control(spec, type, name, 0, val)
416 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
418 static void via_free_kctls(struct hda_codec *codec)
420 struct via_spec *spec = codec->spec;
422 if (spec->kctls.list) {
423 struct snd_kcontrol_new *kctl = spec->kctls.list;
425 for (i = 0; i < spec->kctls.used; i++)
428 snd_array_free(&spec->kctls);
431 /* create input playback/capture controls for the given pin */
432 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
433 int type_idx, int idx, int mix_nid)
438 sprintf(name, "%s Playback Volume", ctlname);
439 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
440 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
443 sprintf(name, "%s Playback Switch", ctlname);
444 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
445 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
451 #define get_connection_index(codec, mux, nid) \
452 snd_hda_get_conn_index(codec, mux, nid, 0)
454 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
460 caps = get_wcaps(codec, nid);
461 if (dir == HDA_INPUT)
462 caps &= AC_WCAP_IN_AMP;
464 caps &= AC_WCAP_OUT_AMP;
467 if (query_amp_caps(codec, nid, dir) & mask)
472 #define have_mute(codec, nid, dir) \
473 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
475 /* enable/disable the output-route mixers */
476 static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
477 hda_nid_t mix_nid, int idx, bool enable)
483 num = snd_hda_get_conn_list(codec, mix_nid, NULL);
484 for (i = 0; i < num; i++) {
486 val = AMP_IN_UNMUTE(i);
488 val = AMP_IN_MUTE(i);
489 snd_hda_codec_write(codec, mix_nid, 0,
490 AC_VERB_SET_AMP_GAIN_MUTE, val);
494 /* enable/disable the output-route */
495 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
496 bool enable, bool force)
498 struct via_spec *spec = codec->spec;
500 for (i = 0; i < path->depth; i++) {
502 int idx = path->idx[i];
504 if (i < path->depth - 1)
505 dst = path->path[i + 1];
508 if (enable && path->multi[i])
509 snd_hda_codec_write(codec, dst, 0,
510 AC_VERB_SET_CONNECT_SEL, idx);
511 if (!force && (dst == spec->aa_mix_nid))
513 if (have_mute(codec, dst, HDA_INPUT))
514 activate_output_mix(codec, path, dst, idx, enable);
515 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
517 if (have_mute(codec, src, HDA_OUTPUT)) {
518 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
519 snd_hda_codec_write(codec, src, 0,
520 AC_VERB_SET_AMP_GAIN_MUTE, val);
525 /* set the given pin as output */
526 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
531 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
533 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
534 snd_hda_codec_write(codec, pin, 0,
535 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
538 static void via_auto_init_output(struct hda_codec *codec,
539 struct nid_path *path, int pin_type)
546 pin = path->path[path->depth - 1];
548 init_output_pin(codec, pin, pin_type);
549 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
550 if (caps & AC_AMPCAP_MUTE) {
552 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
553 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
556 activate_output_path(codec, path, true, true); /* force on */
559 static void via_auto_init_multi_out(struct hda_codec *codec)
561 struct via_spec *spec = codec->spec;
562 struct nid_path *path;
565 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
566 path = &spec->out_path[i];
567 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
568 path = &spec->out_mix_path;
569 via_auto_init_output(codec, path, PIN_OUT);
573 /* deactivate the inactive headphone-paths */
574 static void deactivate_hp_paths(struct hda_codec *codec)
576 struct via_spec *spec = codec->spec;
577 int shared = spec->hp_indep_shared;
579 if (spec->hp_independent_mode) {
580 activate_output_path(codec, &spec->hp_path, false, false);
581 activate_output_path(codec, &spec->hp_mix_path, false, false);
583 activate_output_path(codec, &spec->out_path[shared],
585 } else if (spec->aamix_mode || !spec->hp_path.depth) {
586 activate_output_path(codec, &spec->hp_indep_path, false, false);
587 activate_output_path(codec, &spec->hp_path, false, false);
589 activate_output_path(codec, &spec->hp_indep_path, false, false);
590 activate_output_path(codec, &spec->hp_mix_path, false, false);
594 static void via_auto_init_hp_out(struct hda_codec *codec)
596 struct via_spec *spec = codec->spec;
598 if (!spec->hp_path.depth) {
599 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
602 deactivate_hp_paths(codec);
603 if (spec->hp_independent_mode)
604 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
605 else if (spec->aamix_mode)
606 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
608 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
611 static void via_auto_init_speaker_out(struct hda_codec *codec)
613 struct via_spec *spec = codec->spec;
615 if (!spec->autocfg.speaker_outs)
617 if (!spec->speaker_path.depth) {
618 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
621 if (!spec->aamix_mode) {
622 activate_output_path(codec, &spec->speaker_mix_path,
624 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
626 activate_output_path(codec, &spec->speaker_path, false, false);
627 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
631 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
632 static void via_hp_automute(struct hda_codec *codec);
634 static void via_auto_init_analog_input(struct hda_codec *codec)
636 struct via_spec *spec = codec->spec;
637 const struct auto_pin_cfg *cfg = &spec->autocfg;
638 hda_nid_t conn[HDA_MAX_CONNECTIONS];
643 for (i = 0; i < spec->num_adc_nids; i++) {
644 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
645 AC_VERB_SET_AMP_GAIN_MUTE,
650 for (i = 0; i < cfg->num_inputs; i++) {
651 hda_nid_t nid = cfg->inputs[i].pin;
652 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
654 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
658 snd_hda_codec_write(codec, nid, 0,
659 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
663 for (i = 0; i < spec->num_adc_nids; i++) {
664 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
665 if (spec->mux_nids[adc_idx]) {
666 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
667 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
668 AC_VERB_SET_CONNECT_SEL,
671 if (spec->dyn_adc_switch)
672 break; /* only one input-src */
676 if (!spec->aa_mix_nid)
678 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
680 for (i = 0; i < num_conns; i++) {
681 unsigned int caps = get_wcaps(codec, conn[i]);
682 if (get_wcaps_type(caps) == AC_WID_PIN)
683 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
684 AC_VERB_SET_AMP_GAIN_MUTE,
689 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
690 unsigned int *affected_parm)
693 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
694 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
695 >> AC_DEFCFG_MISC_SHIFT
696 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
697 struct via_spec *spec = codec->spec;
698 unsigned present = 0;
700 no_presence |= spec->no_pin_power_ctl;
702 present = snd_hda_jack_detect(codec, nid);
703 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
704 || ((no_presence || present)
705 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
706 *affected_parm = AC_PWRST_D0; /* if it's connected */
711 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
714 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_info *uinfo)
717 static const char * const texts[] = {
718 "Disabled", "Enabled"
721 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
723 uinfo->value.enumerated.items = 2;
724 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
725 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
726 strcpy(uinfo->value.enumerated.name,
727 texts[uinfo->value.enumerated.item]);
731 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
732 struct snd_ctl_elem_value *ucontrol)
734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
735 struct via_spec *spec = codec->spec;
736 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
740 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
741 struct snd_ctl_elem_value *ucontrol)
743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
744 struct via_spec *spec = codec->spec;
745 unsigned int val = !ucontrol->value.enumerated.item[0];
747 if (val == spec->no_pin_power_ctl)
749 spec->no_pin_power_ctl = val;
750 set_widgets_power_state(codec);
754 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
756 .name = "Dynamic Power-Control",
757 .info = via_pin_power_ctl_info,
758 .get = via_pin_power_ctl_get,
759 .put = via_pin_power_ctl_put,
763 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
764 struct snd_ctl_elem_info *uinfo)
766 static const char * const texts[] = { "OFF", "ON" };
768 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
770 uinfo->value.enumerated.items = 2;
771 if (uinfo->value.enumerated.item >= 2)
772 uinfo->value.enumerated.item = 1;
773 strcpy(uinfo->value.enumerated.name,
774 texts[uinfo->value.enumerated.item]);
778 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
779 struct snd_ctl_elem_value *ucontrol)
781 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
782 struct via_spec *spec = codec->spec;
784 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
788 /* adjust spec->multiout setup according to the current flags */
789 static void setup_playback_multi_pcm(struct via_spec *spec)
791 const struct auto_pin_cfg *cfg = &spec->autocfg;
792 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
793 spec->multiout.hp_nid = 0;
794 if (!spec->hp_independent_mode) {
795 if (!spec->hp_indep_shared)
796 spec->multiout.hp_nid = spec->hp_dac_nid;
798 if (spec->hp_indep_shared)
799 spec->multiout.num_dacs = cfg->line_outs - 1;
803 /* update DAC setups according to indep-HP switch;
804 * this function is called only when indep-HP is modified
806 static void switch_indep_hp_dacs(struct hda_codec *codec)
808 struct via_spec *spec = codec->spec;
809 int shared = spec->hp_indep_shared;
810 hda_nid_t shared_dac, hp_dac;
812 if (!spec->opened_streams)
815 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
816 hp_dac = spec->hp_dac_nid;
817 if (spec->hp_independent_mode) {
818 /* switch to indep-HP mode */
819 if (spec->active_streams & STREAM_MULTI_OUT) {
820 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
821 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
823 if (spec->active_streams & STREAM_INDEP_HP)
824 snd_hda_codec_setup_stream(codec, hp_dac,
825 spec->cur_hp_stream_tag, 0,
826 spec->cur_hp_format);
828 /* back to HP or shared-DAC */
829 if (spec->active_streams & STREAM_INDEP_HP)
830 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
831 if (spec->active_streams & STREAM_MULTI_OUT) {
834 if (shared_dac) { /* reset mutli-ch DAC */
837 } else { /* reset HP DAC */
841 snd_hda_codec_setup_stream(codec, dac,
842 spec->cur_dac_stream_tag, ch,
843 spec->cur_dac_format);
846 setup_playback_multi_pcm(spec);
849 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
850 struct snd_ctl_elem_value *ucontrol)
852 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
853 struct via_spec *spec = codec->spec;
856 mutex_lock(&spec->config_mutex);
857 cur = !!ucontrol->value.enumerated.item[0];
858 if (spec->hp_independent_mode == cur) {
859 mutex_unlock(&spec->config_mutex);
862 spec->hp_independent_mode = cur;
863 shared = spec->hp_indep_shared;
864 deactivate_hp_paths(codec);
866 activate_output_path(codec, &spec->hp_indep_path, true, false);
869 activate_output_path(codec, &spec->out_path[shared],
871 if (spec->aamix_mode || !spec->hp_path.depth)
872 activate_output_path(codec, &spec->hp_mix_path,
875 activate_output_path(codec, &spec->hp_path,
879 switch_indep_hp_dacs(codec);
880 mutex_unlock(&spec->config_mutex);
882 /* update jack power state */
883 set_widgets_power_state(codec);
884 via_hp_automute(codec);
888 static const struct snd_kcontrol_new via_hp_mixer = {
889 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
890 .name = "Independent HP",
891 .info = via_independent_hp_info,
892 .get = via_independent_hp_get,
893 .put = via_independent_hp_put,
896 static int via_hp_build(struct hda_codec *codec)
898 struct via_spec *spec = codec->spec;
899 struct snd_kcontrol_new *knew;
902 nid = spec->autocfg.hp_pins[0];
903 knew = via_clone_control(spec, &via_hp_mixer);
907 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
912 static void notify_aa_path_ctls(struct hda_codec *codec)
914 struct via_spec *spec = codec->spec;
917 for (i = 0; i < spec->smart51_nums; i++) {
918 struct snd_kcontrol *ctl;
919 struct snd_ctl_elem_id id;
920 memset(&id, 0, sizeof(id));
921 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
922 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
923 ctl = snd_hda_find_mixer_ctl(codec, id.name);
925 snd_ctl_notify(codec->bus->card,
926 SNDRV_CTL_EVENT_MASK_VALUE,
931 static void mute_aa_path(struct hda_codec *codec, int mute)
933 struct via_spec *spec = codec->spec;
934 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
937 /* check AA path's mute status */
938 for (i = 0; i < spec->smart51_nums; i++) {
939 if (spec->smart51_idxs[i] < 0)
941 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
942 HDA_INPUT, spec->smart51_idxs[i],
947 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
949 struct via_spec *spec = codec->spec;
952 for (i = 0; i < spec->smart51_nums; i++)
953 if (spec->smart51_pins[i] == pin)
958 static int via_smart51_get(struct snd_kcontrol *kcontrol,
959 struct snd_ctl_elem_value *ucontrol)
961 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
962 struct via_spec *spec = codec->spec;
964 *ucontrol->value.integer.value = spec->smart51_enabled;
968 static int via_smart51_put(struct snd_kcontrol *kcontrol,
969 struct snd_ctl_elem_value *ucontrol)
971 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
972 struct via_spec *spec = codec->spec;
973 int out_in = *ucontrol->value.integer.value
974 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
977 for (i = 0; i < spec->smart51_nums; i++) {
978 hda_nid_t nid = spec->smart51_pins[i];
981 parm = snd_hda_codec_read(codec, nid, 0,
982 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
983 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
985 snd_hda_codec_write(codec, nid, 0,
986 AC_VERB_SET_PIN_WIDGET_CONTROL,
988 if (out_in == AC_PINCTL_OUT_EN) {
989 mute_aa_path(codec, 1);
990 notify_aa_path_ctls(codec);
993 spec->smart51_enabled = *ucontrol->value.integer.value;
994 set_widgets_power_state(codec);
998 static const struct snd_kcontrol_new via_smart51_mixer = {
999 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1000 .name = "Smart 5.1",
1002 .info = snd_ctl_boolean_mono_info,
1003 .get = via_smart51_get,
1004 .put = via_smart51_put,
1007 static int via_smart51_build(struct hda_codec *codec)
1009 struct via_spec *spec = codec->spec;
1011 if (!spec->smart51_nums)
1013 if (!via_clone_control(spec, &via_smart51_mixer))
1018 /* check AA path's mute status */
1019 static bool is_aa_path_mute(struct hda_codec *codec)
1021 struct via_spec *spec = codec->spec;
1022 const struct hda_amp_list *p;
1025 for (i = 0; i < spec->num_loopbacks; i++) {
1026 p = &spec->loopback_list[i];
1027 for (ch = 0; ch < 2; ch++) {
1028 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1030 if (!(v & HDA_AMP_MUTE) && v > 0)
1037 /* enter/exit analog low-current mode */
1038 static void analog_low_current_mode(struct hda_codec *codec)
1040 struct via_spec *spec = codec->spec;
1042 unsigned int verb, parm;
1044 enable = is_aa_path_mute(codec) && (spec->opened_streams != 0);
1046 /* decide low current mode's verb & parameter */
1047 switch (spec->codec_type) {
1051 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1057 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1061 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1067 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1070 return; /* other codecs are not supported */
1073 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1077 * generic initialization of ADC, input mixers and output mixers
1079 static const struct hda_verb vt1708_init_verbs[] = {
1080 /* power down jack detect function */
1085 static void set_stream_open(struct hda_codec *codec, int bit, bool active)
1087 struct via_spec *spec = codec->spec;
1090 spec->opened_streams |= bit;
1092 spec->opened_streams &= ~bit;
1093 analog_low_current_mode(codec);
1096 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1097 struct hda_codec *codec,
1098 struct snd_pcm_substream *substream)
1100 struct via_spec *spec = codec->spec;
1101 const struct auto_pin_cfg *cfg = &spec->autocfg;
1104 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1105 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1106 set_stream_open(codec, STREAM_MULTI_OUT, true);
1107 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1110 set_stream_open(codec, STREAM_MULTI_OUT, false);
1116 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1117 struct hda_codec *codec,
1118 struct snd_pcm_substream *substream)
1120 set_stream_open(codec, STREAM_MULTI_OUT, false);
1124 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1125 struct hda_codec *codec,
1126 struct snd_pcm_substream *substream)
1128 struct via_spec *spec = codec->spec;
1130 if (snd_BUG_ON(!spec->hp_dac_nid))
1132 set_stream_open(codec, STREAM_INDEP_HP, true);
1136 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1137 struct hda_codec *codec,
1138 struct snd_pcm_substream *substream)
1140 set_stream_open(codec, STREAM_INDEP_HP, false);
1144 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1145 struct hda_codec *codec,
1146 unsigned int stream_tag,
1147 unsigned int format,
1148 struct snd_pcm_substream *substream)
1150 struct via_spec *spec = codec->spec;
1152 mutex_lock(&spec->config_mutex);
1153 setup_playback_multi_pcm(spec);
1154 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1156 /* remember for dynamic DAC switch with indep-HP */
1157 spec->active_streams |= STREAM_MULTI_OUT;
1158 spec->cur_dac_stream_tag = stream_tag;
1159 spec->cur_dac_format = format;
1160 mutex_unlock(&spec->config_mutex);
1161 vt1708_update_hp_work(spec);
1165 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1166 struct hda_codec *codec,
1167 unsigned int stream_tag,
1168 unsigned int format,
1169 struct snd_pcm_substream *substream)
1171 struct via_spec *spec = codec->spec;
1173 mutex_lock(&spec->config_mutex);
1174 if (spec->hp_independent_mode)
1175 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1176 stream_tag, 0, format);
1177 spec->active_streams |= STREAM_INDEP_HP;
1178 spec->cur_hp_stream_tag = stream_tag;
1179 spec->cur_hp_format = format;
1180 mutex_unlock(&spec->config_mutex);
1181 vt1708_update_hp_work(spec);
1185 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1186 struct hda_codec *codec,
1187 struct snd_pcm_substream *substream)
1189 struct via_spec *spec = codec->spec;
1191 mutex_lock(&spec->config_mutex);
1192 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1193 spec->active_streams &= ~STREAM_MULTI_OUT;
1194 mutex_unlock(&spec->config_mutex);
1195 vt1708_update_hp_work(spec);
1199 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1200 struct hda_codec *codec,
1201 struct snd_pcm_substream *substream)
1203 struct via_spec *spec = codec->spec;
1205 mutex_lock(&spec->config_mutex);
1206 if (spec->hp_independent_mode)
1207 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1208 spec->active_streams &= ~STREAM_INDEP_HP;
1209 mutex_unlock(&spec->config_mutex);
1210 vt1708_update_hp_work(spec);
1217 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1218 struct hda_codec *codec,
1219 struct snd_pcm_substream *substream)
1221 struct via_spec *spec = codec->spec;
1222 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1225 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1226 struct hda_codec *codec,
1227 struct snd_pcm_substream *substream)
1229 struct via_spec *spec = codec->spec;
1230 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1233 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1234 struct hda_codec *codec,
1235 unsigned int stream_tag,
1236 unsigned int format,
1237 struct snd_pcm_substream *substream)
1239 struct via_spec *spec = codec->spec;
1240 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1241 stream_tag, format, substream);
1244 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1245 struct hda_codec *codec,
1246 struct snd_pcm_substream *substream)
1248 struct via_spec *spec = codec->spec;
1249 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1256 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1257 struct hda_codec *codec,
1258 unsigned int stream_tag,
1259 unsigned int format,
1260 struct snd_pcm_substream *substream)
1262 struct via_spec *spec = codec->spec;
1264 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1265 stream_tag, 0, format);
1269 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1270 struct hda_codec *codec,
1271 struct snd_pcm_substream *substream)
1273 struct via_spec *spec = codec->spec;
1274 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1278 /* analog capture with dynamic ADC switching */
1279 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1280 struct hda_codec *codec,
1281 unsigned int stream_tag,
1282 unsigned int format,
1283 struct snd_pcm_substream *substream)
1285 struct via_spec *spec = codec->spec;
1286 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1288 mutex_lock(&spec->config_mutex);
1289 spec->cur_adc = spec->adc_nids[adc_idx];
1290 spec->cur_adc_stream_tag = stream_tag;
1291 spec->cur_adc_format = format;
1292 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1293 mutex_unlock(&spec->config_mutex);
1297 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1298 struct hda_codec *codec,
1299 struct snd_pcm_substream *substream)
1301 struct via_spec *spec = codec->spec;
1303 mutex_lock(&spec->config_mutex);
1304 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1306 mutex_unlock(&spec->config_mutex);
1310 /* re-setup the stream if running; called from input-src put */
1311 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1313 struct via_spec *spec = codec->spec;
1314 int adc_idx = spec->inputs[cur].adc_idx;
1315 hda_nid_t adc = spec->adc_nids[adc_idx];
1318 mutex_lock(&spec->config_mutex);
1319 if (spec->cur_adc && spec->cur_adc != adc) {
1320 /* stream is running, let's swap the current ADC */
1321 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1322 spec->cur_adc = adc;
1323 snd_hda_codec_setup_stream(codec, adc,
1324 spec->cur_adc_stream_tag, 0,
1325 spec->cur_adc_format);
1328 mutex_unlock(&spec->config_mutex);
1332 static const struct hda_pcm_stream via_pcm_analog_playback = {
1336 /* NID is set in via_build_pcms */
1338 .open = via_playback_multi_pcm_open,
1339 .close = via_playback_multi_pcm_close,
1340 .prepare = via_playback_multi_pcm_prepare,
1341 .cleanup = via_playback_multi_pcm_cleanup
1345 static const struct hda_pcm_stream via_pcm_hp_playback = {
1349 /* NID is set in via_build_pcms */
1351 .open = via_playback_hp_pcm_open,
1352 .close = via_playback_hp_pcm_close,
1353 .prepare = via_playback_hp_pcm_prepare,
1354 .cleanup = via_playback_hp_pcm_cleanup
1358 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1362 /* NID is set in via_build_pcms */
1363 /* We got noisy outputs on the right channel on VT1708 when
1364 * 24bit samples are used. Until any workaround is found,
1365 * disable the 24bit format, so far.
1367 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1369 .open = via_playback_multi_pcm_open,
1370 .close = via_playback_multi_pcm_close,
1371 .prepare = via_playback_multi_pcm_prepare,
1372 .cleanup = via_playback_multi_pcm_cleanup
1376 static const struct hda_pcm_stream via_pcm_analog_capture = {
1377 .substreams = 1, /* will be changed in via_build_pcms() */
1380 /* NID is set in via_build_pcms */
1382 .prepare = via_capture_pcm_prepare,
1383 .cleanup = via_capture_pcm_cleanup
1387 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1391 /* NID is set in via_build_pcms */
1393 .prepare = via_dyn_adc_capture_pcm_prepare,
1394 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1398 static const struct hda_pcm_stream via_pcm_digital_playback = {
1402 /* NID is set in via_build_pcms */
1404 .open = via_dig_playback_pcm_open,
1405 .close = via_dig_playback_pcm_close,
1406 .prepare = via_dig_playback_pcm_prepare,
1407 .cleanup = via_dig_playback_pcm_cleanup
1411 static const struct hda_pcm_stream via_pcm_digital_capture = {
1418 * slave controls for virtual master
1420 static const char * const via_slave_vols[] = {
1421 "Front Playback Volume",
1422 "Surround Playback Volume",
1423 "Center Playback Volume",
1424 "LFE Playback Volume",
1425 "Side Playback Volume",
1426 "Headphone Playback Volume",
1427 "Speaker Playback Volume",
1431 static const char * const via_slave_sws[] = {
1432 "Front Playback Switch",
1433 "Surround Playback Switch",
1434 "Center Playback Switch",
1435 "LFE Playback Switch",
1436 "Side Playback Switch",
1437 "Headphone Playback Switch",
1438 "Speaker Playback Switch",
1442 static int via_build_controls(struct hda_codec *codec)
1444 struct via_spec *spec = codec->spec;
1445 struct snd_kcontrol *kctl;
1448 if (spec->set_widgets_power_state)
1449 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1452 for (i = 0; i < spec->num_mixers; i++) {
1453 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1458 if (spec->multiout.dig_out_nid) {
1459 err = snd_hda_create_spdif_out_ctls(codec,
1460 spec->multiout.dig_out_nid,
1461 spec->multiout.dig_out_nid);
1464 err = snd_hda_create_spdif_share_sw(codec,
1468 spec->multiout.share_spdif = 1;
1470 if (spec->dig_in_nid) {
1471 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1476 /* if we have no master control, let's create it */
1477 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1478 unsigned int vmaster_tlv[4];
1479 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1480 HDA_OUTPUT, vmaster_tlv);
1481 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1482 vmaster_tlv, via_slave_vols);
1486 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1487 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1488 NULL, via_slave_sws);
1493 /* assign Capture Source enums to NID */
1494 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1495 for (i = 0; kctl && i < kctl->count; i++) {
1496 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1501 /* init power states */
1502 set_widgets_power_state(codec);
1503 analog_low_current_mode(codec);
1505 via_free_kctls(codec); /* no longer needed */
1509 static int via_build_pcms(struct hda_codec *codec)
1511 struct via_spec *spec = codec->spec;
1512 struct hda_pcm *info = spec->pcm_rec;
1514 codec->num_pcms = 0;
1515 codec->pcm_info = info;
1517 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1518 snprintf(spec->stream_name_analog,
1519 sizeof(spec->stream_name_analog),
1520 "%s Analog", codec->chip_name);
1521 info->name = spec->stream_name_analog;
1523 if (spec->multiout.num_dacs) {
1524 if (!spec->stream_analog_playback)
1525 spec->stream_analog_playback =
1526 &via_pcm_analog_playback;
1527 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1528 *spec->stream_analog_playback;
1529 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1530 spec->multiout.dac_nids[0];
1531 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1532 spec->multiout.max_channels;
1535 if (!spec->stream_analog_capture) {
1536 if (spec->dyn_adc_switch)
1537 spec->stream_analog_capture =
1538 &via_pcm_dyn_adc_analog_capture;
1540 spec->stream_analog_capture =
1541 &via_pcm_analog_capture;
1543 if (spec->num_adc_nids) {
1544 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1545 *spec->stream_analog_capture;
1546 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1548 if (!spec->dyn_adc_switch)
1549 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1556 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1557 snprintf(spec->stream_name_digital,
1558 sizeof(spec->stream_name_digital),
1559 "%s Digital", codec->chip_name);
1560 info->name = spec->stream_name_digital;
1561 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1562 if (spec->multiout.dig_out_nid) {
1563 if (!spec->stream_digital_playback)
1564 spec->stream_digital_playback =
1565 &via_pcm_digital_playback;
1566 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1567 *spec->stream_digital_playback;
1568 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1569 spec->multiout.dig_out_nid;
1571 if (spec->dig_in_nid) {
1572 if (!spec->stream_digital_capture)
1573 spec->stream_digital_capture =
1574 &via_pcm_digital_capture;
1575 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1576 *spec->stream_digital_capture;
1577 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1584 if (spec->hp_dac_nid) {
1585 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1586 "%s HP", codec->chip_name);
1587 info->name = spec->stream_name_hp;
1588 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1589 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1597 static void via_free(struct hda_codec *codec)
1599 struct via_spec *spec = codec->spec;
1604 via_free_kctls(codec);
1605 vt1708_stop_hp_work(spec);
1606 kfree(spec->bind_cap_vol);
1607 kfree(spec->bind_cap_sw);
1611 /* mute/unmute outputs */
1612 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1613 hda_nid_t *pins, bool mute)
1616 for (i = 0; i < num_pins; i++) {
1617 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1618 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1619 if (parm & AC_PINCTL_IN_EN)
1622 parm &= ~AC_PINCTL_OUT_EN;
1624 parm |= AC_PINCTL_OUT_EN;
1625 snd_hda_codec_write(codec, pins[i], 0,
1626 AC_VERB_SET_PIN_WIDGET_CONTROL, parm);
1630 /* mute internal speaker if line-out is plugged */
1631 static void via_line_automute(struct hda_codec *codec, int present)
1633 struct via_spec *spec = codec->spec;
1635 if (!spec->autocfg.speaker_outs)
1638 present = snd_hda_jack_detect(codec,
1639 spec->autocfg.line_out_pins[0]);
1640 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1641 spec->autocfg.speaker_pins,
1645 /* mute internal speaker if HP is plugged */
1646 static void via_hp_automute(struct hda_codec *codec)
1650 struct via_spec *spec = codec->spec;
1652 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
1653 (spec->codec_type != VT1708 || spec->vt1708_jack_detect))
1654 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1656 if (spec->smart51_enabled)
1657 nums = spec->autocfg.line_outs + spec->smart51_nums;
1659 nums = spec->autocfg.line_outs;
1660 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1662 via_line_automute(codec, present);
1665 static void via_gpio_control(struct hda_codec *codec)
1667 unsigned int gpio_data;
1668 unsigned int vol_counter;
1670 unsigned int master_vol;
1672 struct via_spec *spec = codec->spec;
1674 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1675 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1677 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1678 0xF84, 0) & 0x3F0000) >> 16;
1680 vol = vol_counter & 0x1F;
1681 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1682 AC_VERB_GET_AMP_GAIN_MUTE,
1685 if (gpio_data == 0x02) {
1686 /* unmute line out */
1687 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1688 AC_VERB_SET_PIN_WIDGET_CONTROL,
1690 if (vol_counter & 0x20) {
1691 /* decrease volume */
1692 if (vol > master_vol)
1694 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1698 /* increase volume */
1699 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1701 ((master_vol+vol) > 0x2A) ? 0x2A :
1704 } else if (!(gpio_data & 0x02)) {
1706 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1707 AC_VERB_SET_PIN_WIDGET_CONTROL,
1712 /* unsolicited event for jack sensing */
1713 static void via_unsol_event(struct hda_codec *codec,
1718 if (res & VIA_JACK_EVENT)
1719 set_widgets_power_state(codec);
1721 res &= ~VIA_JACK_EVENT;
1723 if (res == VIA_HP_EVENT || res == VIA_LINE_EVENT)
1724 via_hp_automute(codec);
1725 else if (res == VIA_GPIO_EVENT)
1726 via_gpio_control(codec);
1730 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1732 struct via_spec *spec = codec->spec;
1733 vt1708_stop_hp_work(spec);
1738 #ifdef CONFIG_SND_HDA_POWER_SAVE
1739 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1741 struct via_spec *spec = codec->spec;
1742 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1749 static int via_init(struct hda_codec *codec);
1751 static const struct hda_codec_ops via_patch_ops = {
1752 .build_controls = via_build_controls,
1753 .build_pcms = via_build_pcms,
1756 .unsol_event = via_unsol_event,
1758 .suspend = via_suspend,
1760 #ifdef CONFIG_SND_HDA_POWER_SAVE
1761 .check_power_status = via_check_power_status,
1765 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1767 struct via_spec *spec = codec->spec;
1770 for (i = 0; i < spec->multiout.num_dacs; i++) {
1771 if (spec->multiout.dac_nids[i] == dac)
1774 if (spec->hp_dac_nid == dac)
1779 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1780 hda_nid_t target_dac, int with_aa_mix,
1781 struct nid_path *path, int depth)
1783 struct via_spec *spec = codec->spec;
1787 if (nid == spec->aa_mix_nid) {
1790 with_aa_mix = 2; /* mark aa-mix is included */
1793 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1794 for (i = 0; i < nums; i++) {
1795 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1797 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1798 /* aa-mix is requested but not included? */
1799 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1803 if (depth >= MAX_NID_PATH_DEPTH)
1805 for (i = 0; i < nums; i++) {
1807 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1808 if (type == AC_WID_AUD_OUT)
1810 if (__parse_output_path(codec, conn[i], target_dac,
1811 with_aa_mix, path, depth + 1))
1817 path->path[path->depth] = conn[i];
1818 path->idx[path->depth] = i;
1819 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1820 path->multi[path->depth] = 1;
1825 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1826 hda_nid_t target_dac, int with_aa_mix,
1827 struct nid_path *path)
1829 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
1830 path->path[path->depth] = nid;
1832 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1833 path->depth, path->path[0], path->path[1],
1834 path->path[2], path->path[3], path->path[4]);
1840 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1842 struct via_spec *spec = codec->spec;
1843 const struct auto_pin_cfg *cfg = &spec->autocfg;
1847 spec->multiout.dac_nids = spec->private_dac_nids;
1849 for (i = 0; i < cfg->line_outs; i++) {
1851 nid = cfg->line_out_pins[i];
1854 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1855 dac = spec->out_path[i].path[0];
1856 if (!i && parse_output_path(codec, nid, dac, 1,
1857 &spec->out_mix_path))
1858 dac = spec->out_mix_path.path[0];
1860 spec->private_dac_nids[i] = dac;
1864 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1865 spec->out_path[0] = spec->out_mix_path;
1866 spec->out_mix_path.depth = 0;
1868 spec->multiout.num_dacs = dac_num;
1872 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1873 int chs, bool check_dac, struct nid_path *path)
1875 struct via_spec *spec = codec->spec;
1877 hda_nid_t dac, pin, sel, nid;
1880 dac = check_dac ? path->path[0] : 0;
1881 pin = path->path[path->depth - 1];
1882 sel = path->depth > 1 ? path->path[1] : 0;
1884 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1886 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1888 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1893 sprintf(name, "%s Playback Volume", pfx);
1894 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1895 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1898 path->vol_ctl = nid;
1901 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1903 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1905 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1910 sprintf(name, "%s Playback Switch", pfx);
1911 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1912 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1915 path->mute_ctl = nid;
1920 static void mangle_smart51(struct hda_codec *codec)
1922 struct via_spec *spec = codec->spec;
1923 struct auto_pin_cfg *cfg = &spec->autocfg;
1924 struct auto_pin_cfg_item *ins = cfg->inputs;
1925 int i, j, nums, attr;
1926 int pins[AUTO_CFG_MAX_INS];
1928 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1930 for (i = 0; i < cfg->num_inputs; i++) {
1932 if (ins[i].type > AUTO_PIN_LINE_IN)
1934 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1935 if (snd_hda_get_input_pin_attr(def) != attr)
1937 for (j = 0; j < nums; j++)
1938 if (ins[pins[j]].type < ins[i].type) {
1939 memmove(pins + j + 1, pins + j,
1940 (nums - j) * sizeof(int));
1946 if (cfg->line_outs + nums < 3)
1948 for (i = 0; i < nums; i++) {
1949 hda_nid_t pin = ins[pins[i]].pin;
1950 spec->smart51_pins[spec->smart51_nums++] = pin;
1951 cfg->line_out_pins[cfg->line_outs++] = pin;
1952 if (cfg->line_outs == 3)
1959 static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1961 dst->vol_ctl = src->vol_ctl;
1962 dst->mute_ctl = src->mute_ctl;
1965 /* add playback controls from the parsed DAC table */
1966 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1968 struct via_spec *spec = codec->spec;
1969 struct auto_pin_cfg *cfg = &spec->autocfg;
1970 struct nid_path *path;
1971 static const char * const chname[4] = {
1972 "Front", "Surround", "C/LFE", "Side"
1978 old_line_outs = cfg->line_outs;
1979 if (cfg->line_outs == 1)
1980 mangle_smart51(codec);
1982 err = via_auto_fill_dac_nids(codec);
1986 if (spec->multiout.num_dacs < 3) {
1987 spec->smart51_nums = 0;
1988 cfg->line_outs = old_line_outs;
1990 for (i = 0; i < cfg->line_outs; i++) {
1992 pin = cfg->line_out_pins[i];
1993 dac = spec->multiout.dac_nids[i];
1996 path = spec->out_path + i;
1997 if (i == HDA_CLFE) {
1998 err = create_ch_ctls(codec, "Center", 1, true, path);
2001 err = create_ch_ctls(codec, "LFE", 2, true, path);
2005 const char *pfx = chname[i];
2006 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
2007 cfg->line_outs == 1)
2009 err = create_ch_ctls(codec, pfx, 3, true, path);
2013 if (path != spec->out_path + i)
2014 copy_path_mixer_ctls(&spec->out_path[i], path);
2015 if (path == spec->out_path && spec->out_mix_path.depth)
2016 copy_path_mixer_ctls(&spec->out_mix_path, path);
2019 idx = get_connection_index(codec, spec->aa_mix_nid,
2020 spec->multiout.dac_nids[0]);
2022 /* add control to mixer */
2024 name = spec->out_mix_path.depth ?
2025 "PCM Loopback Playback Volume" : "PCM Playback Volume";
2026 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2027 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2031 name = spec->out_mix_path.depth ?
2032 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2033 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2034 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2040 cfg->line_outs = old_line_outs;
2045 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
2047 struct via_spec *spec = codec->spec;
2048 struct nid_path *path;
2055 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2056 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2057 if (i < spec->multiout.num_dacs &&
2058 parse_output_path(codec, pin,
2059 spec->multiout.dac_nids[i], 0,
2060 &spec->hp_indep_path)) {
2061 spec->hp_indep_shared = i;
2066 if (spec->hp_indep_path.depth) {
2067 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2068 if (!spec->hp_indep_shared)
2069 spec->hp_path = spec->hp_indep_path;
2071 /* optionally check front-path w/o AA-mix */
2072 if (!spec->hp_path.depth)
2073 parse_output_path(codec, pin,
2074 spec->multiout.dac_nids[HDA_FRONT], 0,
2077 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2078 1, &spec->hp_mix_path) && !spec->hp_path.depth)
2081 if (spec->hp_path.depth) {
2082 path = &spec->hp_path;
2085 path = &spec->hp_mix_path;
2088 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
2092 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2094 copy_path_mixer_ctls(&spec->hp_path, path);
2095 if (spec->hp_indep_path.depth)
2096 copy_path_mixer_ctls(&spec->hp_indep_path, path);
2100 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2102 struct via_spec *spec = codec->spec;
2103 struct nid_path *path;
2105 hda_nid_t pin, dac = 0;
2108 pin = spec->autocfg.speaker_pins[0];
2109 if (!spec->autocfg.speaker_outs || !pin)
2112 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
2113 dac = spec->speaker_path.path[0];
2115 parse_output_path(codec, pin,
2116 spec->multiout.dac_nids[HDA_FRONT], 0,
2117 &spec->speaker_path);
2118 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2119 1, &spec->speaker_mix_path) && !dac)
2122 /* no AA-path for front? */
2123 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2126 spec->speaker_dac_nid = dac;
2127 spec->multiout.extra_out_nid[0] = dac;
2129 path = &spec->speaker_path;
2132 path = &spec->speaker_mix_path;
2135 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2139 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2141 copy_path_mixer_ctls(&spec->speaker_path, path);
2145 #define via_aamix_ctl_info via_pin_power_ctl_info
2147 static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2148 struct snd_ctl_elem_value *ucontrol)
2150 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2151 struct via_spec *spec = codec->spec;
2152 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2156 static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2157 struct nid_path *nomix, struct nid_path *mix)
2160 activate_output_path(codec, nomix, false, false);
2161 activate_output_path(codec, mix, true, false);
2163 activate_output_path(codec, mix, false, false);
2164 activate_output_path(codec, nomix, true, false);
2168 static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2169 struct snd_ctl_elem_value *ucontrol)
2171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2172 struct via_spec *spec = codec->spec;
2173 unsigned int val = ucontrol->value.enumerated.item[0];
2175 if (val == spec->aamix_mode)
2177 spec->aamix_mode = val;
2178 /* update front path */
2179 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2180 /* update HP path */
2181 if (!spec->hp_independent_mode) {
2182 update_aamix_paths(codec, val, &spec->hp_path,
2183 &spec->hp_mix_path);
2185 /* update speaker path */
2186 update_aamix_paths(codec, val, &spec->speaker_path,
2187 &spec->speaker_mix_path);
2191 static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2192 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2193 .name = "Loopback Mixing",
2194 .info = via_aamix_ctl_info,
2195 .get = via_aamix_ctl_get,
2196 .put = via_aamix_ctl_put,
2199 static int via_auto_create_loopback_switch(struct hda_codec *codec)
2201 struct via_spec *spec = codec->spec;
2203 if (!spec->aa_mix_nid)
2204 return 0; /* no loopback switching available */
2205 if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth ||
2206 spec->speaker_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 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2627 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2628 struct snd_ctl_elem_value *ucontrol)
2630 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2631 struct via_spec *spec = codec->spec;
2634 if (spec->codec_type != VT1708)
2636 val = !!ucontrol->value.integer.value[0];
2637 if (spec->vt1708_jack_detect == val)
2639 spec->vt1708_jack_detect = val;
2640 if (spec->vt1708_jack_detect &&
2641 snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
2642 mute_aa_path(codec, 1);
2643 notify_aa_path_ctls(codec);
2645 via_hp_automute(codec);
2646 vt1708_update_hp_work(spec);
2650 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2651 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2652 .name = "Jack Detect",
2654 .info = snd_ctl_boolean_mono_info,
2655 .get = vt1708_jack_detect_get,
2656 .put = vt1708_jack_detect_put,
2659 static void fill_dig_outs(struct hda_codec *codec);
2660 static void fill_dig_in(struct hda_codec *codec);
2662 static int via_parse_auto_config(struct hda_codec *codec)
2664 struct via_spec *spec = codec->spec;
2667 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2670 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2673 err = via_auto_create_multi_out_ctls(codec);
2676 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2679 err = via_auto_create_speaker_ctls(codec);
2682 err = via_auto_create_loopback_switch(codec);
2685 err = via_auto_create_analog_input_ctls(codec);
2689 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2691 fill_dig_outs(codec);
2694 if (spec->kctls.list)
2695 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2698 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
2699 err = via_hp_build(codec);
2704 err = via_smart51_build(codec);
2708 /* assign slave outs */
2709 if (spec->slave_dig_outs[0])
2710 codec->slave_dig_outs = spec->slave_dig_outs;
2715 static void via_auto_init_dig_outs(struct hda_codec *codec)
2717 struct via_spec *spec = codec->spec;
2718 if (spec->multiout.dig_out_nid)
2719 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2720 if (spec->slave_dig_outs[0])
2721 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2724 static void via_auto_init_dig_in(struct hda_codec *codec)
2726 struct via_spec *spec = codec->spec;
2727 if (!spec->dig_in_nid)
2729 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2730 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2733 /* initialize the unsolicited events */
2734 static void via_auto_init_unsol_event(struct hda_codec *codec)
2736 struct via_spec *spec = codec->spec;
2737 struct auto_pin_cfg *cfg = &spec->autocfg;
2741 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2742 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2743 AC_VERB_SET_UNSOLICITED_ENABLE,
2744 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2746 if (cfg->speaker_pins[0])
2747 ev = VIA_LINE_EVENT;
2750 for (i = 0; i < cfg->line_outs; i++) {
2751 if (cfg->line_out_pins[i] &&
2752 is_jack_detectable(codec, cfg->line_out_pins[i]))
2753 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
2754 AC_VERB_SET_UNSOLICITED_ENABLE,
2755 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2758 for (i = 0; i < cfg->num_inputs; i++) {
2759 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2760 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2761 AC_VERB_SET_UNSOLICITED_ENABLE,
2762 AC_USRSP_EN | VIA_JACK_EVENT);
2766 static int via_init(struct hda_codec *codec)
2768 struct via_spec *spec = codec->spec;
2771 for (i = 0; i < spec->num_iverbs; i++)
2772 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2774 via_auto_init_multi_out(codec);
2775 via_auto_init_hp_out(codec);
2776 via_auto_init_speaker_out(codec);
2777 via_auto_init_analog_input(codec);
2778 via_auto_init_dig_outs(codec);
2779 via_auto_init_dig_in(codec);
2781 via_auto_init_unsol_event(codec);
2783 via_hp_automute(codec);
2784 vt1708_update_hp_work(spec);
2789 static void vt1708_update_hp_jack_state(struct work_struct *work)
2791 struct via_spec *spec = container_of(work, struct via_spec,
2792 vt1708_hp_work.work);
2793 if (spec->codec_type != VT1708)
2795 /* if jack state toggled */
2796 if (spec->vt1708_hp_present
2797 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2798 spec->vt1708_hp_present ^= 1;
2799 via_hp_automute(spec->codec);
2801 if (spec->vt1708_jack_detect)
2802 schedule_delayed_work(&spec->vt1708_hp_work,
2803 msecs_to_jiffies(100));
2806 static int get_mux_nids(struct hda_codec *codec)
2808 struct via_spec *spec = codec->spec;
2809 hda_nid_t nid, conn[8];
2813 for (i = 0; i < spec->num_adc_nids; i++) {
2814 nid = spec->adc_nids[i];
2816 type = get_wcaps_type(get_wcaps(codec, nid));
2817 if (type == AC_WID_PIN)
2819 n = snd_hda_get_connections(codec, nid, conn,
2824 spec->mux_nids[i] = nid;
2833 static int patch_vt1708(struct hda_codec *codec)
2835 struct via_spec *spec;
2838 /* create a codec specific record */
2839 spec = via_new_spec(codec);
2843 spec->aa_mix_nid = 0x17;
2845 /* Add HP and CD pin config connect bit re-config action */
2846 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2847 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2849 /* automatic parse from the BIOS config */
2850 err = via_parse_auto_config(codec);
2856 /* add jack detect on/off control */
2857 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2860 /* disable 32bit format on VT1708 */
2861 if (codec->vendor_id == 0x11061708)
2862 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2864 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2866 codec->patch_ops = via_patch_ops;
2868 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2872 static int patch_vt1709(struct hda_codec *codec)
2874 struct via_spec *spec;
2877 /* create a codec specific record */
2878 spec = via_new_spec(codec);
2882 spec->aa_mix_nid = 0x18;
2884 err = via_parse_auto_config(codec);
2890 codec->patch_ops = via_patch_ops;
2895 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2897 struct via_spec *spec = codec->spec;
2901 if ((spec->codec_type != VT1708B_4CH) &&
2902 (codec->vendor_id != 0x11064397))
2905 /* SW0 (17h) = stereo mixer */
2907 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2908 == ((spec->codec_type == VT1708S) ? 5 : 0));
2910 /* PW 1/2/5 (1ah/1bh/1eh) */
2912 set_pin_power_state(codec, 0x1a, &parm);
2913 set_pin_power_state(codec, 0x1b, &parm);
2914 set_pin_power_state(codec, 0x1e, &parm);
2917 /* SW0 (17h), AIW 0/1 (13h/14h) */
2918 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2919 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2920 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2923 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2925 set_pin_power_state(codec, 0x19, &parm);
2926 if (spec->smart51_enabled)
2927 set_pin_power_state(codec, 0x1b, &parm);
2928 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2929 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2931 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2934 set_pin_power_state(codec, 0x22, &parm);
2935 if (spec->smart51_enabled)
2936 set_pin_power_state(codec, 0x1a, &parm);
2937 snd_hda_codec_write(codec, 0x26, 0,
2938 AC_VERB_SET_POWER_STATE, parm);
2939 snd_hda_codec_write(codec, 0x24, 0,
2940 AC_VERB_SET_POWER_STATE, parm);
2941 } else if (codec->vendor_id == 0x11064397) {
2942 /* PW7(23h), SW2(27h), AOW2(25h) */
2944 set_pin_power_state(codec, 0x23, &parm);
2945 if (spec->smart51_enabled)
2946 set_pin_power_state(codec, 0x1a, &parm);
2947 snd_hda_codec_write(codec, 0x27, 0,
2948 AC_VERB_SET_POWER_STATE, parm);
2949 snd_hda_codec_write(codec, 0x25, 0,
2950 AC_VERB_SET_POWER_STATE, parm);
2953 /* PW 3/4/7 (1ch/1dh/23h) */
2955 /* force to D0 for internal Speaker */
2956 set_pin_power_state(codec, 0x1c, &parm);
2957 set_pin_power_state(codec, 0x1d, &parm);
2959 set_pin_power_state(codec, 0x23, &parm);
2961 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2962 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2963 imux_is_smixer ? AC_PWRST_D0 : parm);
2964 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2966 snd_hda_codec_write(codec, 0x25, 0,
2967 AC_VERB_SET_POWER_STATE, parm);
2968 snd_hda_codec_write(codec, 0x27, 0,
2969 AC_VERB_SET_POWER_STATE, parm);
2970 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2971 snd_hda_codec_write(codec, 0x25, 0,
2972 AC_VERB_SET_POWER_STATE, parm);
2975 static int patch_vt1708S(struct hda_codec *codec);
2976 static int patch_vt1708B(struct hda_codec *codec)
2978 struct via_spec *spec;
2981 if (get_codec_type(codec) == VT1708BCE)
2982 return patch_vt1708S(codec);
2984 /* create a codec specific record */
2985 spec = via_new_spec(codec);
2989 spec->aa_mix_nid = 0x16;
2991 /* automatic parse from the BIOS config */
2992 err = via_parse_auto_config(codec);
2998 codec->patch_ops = via_patch_ops;
3000 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3005 /* Patch for VT1708S */
3006 static const struct hda_verb vt1708S_init_verbs[] = {
3007 /* Enable Mic Boost Volume backdoor */
3009 /* don't bybass mixer */
3014 /* fill out digital output widgets; one for master and one for slave outputs */
3015 static void fill_dig_outs(struct hda_codec *codec)
3017 struct via_spec *spec = codec->spec;
3020 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3024 nid = spec->autocfg.dig_out_pins[i];
3027 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3030 if (!spec->multiout.dig_out_nid)
3031 spec->multiout.dig_out_nid = nid;
3033 spec->slave_dig_outs[0] = nid;
3034 break; /* at most two dig outs */
3039 static void fill_dig_in(struct hda_codec *codec)
3041 struct via_spec *spec = codec->spec;
3045 if (!spec->autocfg.dig_in_pin)
3048 dig_nid = codec->start_nid;
3049 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3050 unsigned int wcaps = get_wcaps(codec, dig_nid);
3051 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3053 if (!(wcaps & AC_WCAP_DIGITAL))
3055 if (!(wcaps & AC_WCAP_CONN_LIST))
3057 err = get_connection_index(codec, dig_nid,
3058 spec->autocfg.dig_in_pin);
3060 spec->dig_in_nid = dig_nid;
3066 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3067 int offset, int num_steps, int step_size)
3069 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3070 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3071 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3072 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3073 (0 << AC_AMPCAP_MUTE_SHIFT));
3076 static int patch_vt1708S(struct hda_codec *codec)
3078 struct via_spec *spec;
3081 /* create a codec specific record */
3082 spec = via_new_spec(codec);
3086 spec->aa_mix_nid = 0x16;
3087 override_mic_boost(codec, 0x1a, 0, 3, 40);
3088 override_mic_boost(codec, 0x1e, 0, 3, 40);
3090 /* automatic parse from the BIOS config */
3091 err = via_parse_auto_config(codec);
3097 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
3099 codec->patch_ops = via_patch_ops;
3101 /* correct names for VT1708BCE */
3102 if (get_codec_type(codec) == VT1708BCE) {
3103 kfree(codec->chip_name);
3104 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3105 snprintf(codec->bus->card->mixername,
3106 sizeof(codec->bus->card->mixername),
3107 "%s %s", codec->vendor_name, codec->chip_name);
3109 /* correct names for VT1705 */
3110 if (codec->vendor_id == 0x11064397) {
3111 kfree(codec->chip_name);
3112 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3113 snprintf(codec->bus->card->mixername,
3114 sizeof(codec->bus->card->mixername),
3115 "%s %s", codec->vendor_name, codec->chip_name);
3117 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3121 /* Patch for VT1702 */
3123 static const struct hda_verb vt1702_init_verbs[] = {
3131 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3133 int imux_is_smixer =
3134 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3137 /* PW 1/2/5 (14h/15h/18h) */
3139 set_pin_power_state(codec, 0x14, &parm);
3140 set_pin_power_state(codec, 0x15, &parm);
3141 set_pin_power_state(codec, 0x18, &parm);
3143 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3144 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3145 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3146 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
3147 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3148 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
3151 /* PW 3/4 (16h/17h) */
3153 set_pin_power_state(codec, 0x17, &parm);
3154 set_pin_power_state(codec, 0x16, &parm);
3155 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3156 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
3157 imux_is_smixer ? AC_PWRST_D0 : parm);
3158 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3159 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3162 static int patch_vt1702(struct hda_codec *codec)
3164 struct via_spec *spec;
3167 /* create a codec specific record */
3168 spec = via_new_spec(codec);
3172 spec->aa_mix_nid = 0x1a;
3174 /* limit AA path volume to 0 dB */
3175 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3176 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3177 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3178 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3179 (1 << AC_AMPCAP_MUTE_SHIFT));
3181 /* automatic parse from the BIOS config */
3182 err = via_parse_auto_config(codec);
3188 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
3190 codec->patch_ops = via_patch_ops;
3192 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
3196 /* Patch for VT1718S */
3198 static const struct hda_verb vt1718S_init_verbs[] = {
3199 /* Enable MW0 adjust Gain 5 */
3201 /* Enable Boost Volume backdoor */
3207 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3209 struct via_spec *spec = codec->spec;
3212 /* MUX6 (1eh) = stereo mixer */
3214 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3216 /* PW 5/6/7 (29h/2ah/2bh) */
3218 set_pin_power_state(codec, 0x29, &parm);
3219 set_pin_power_state(codec, 0x2a, &parm);
3220 set_pin_power_state(codec, 0x2b, &parm);
3223 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3224 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3225 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3226 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3227 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3230 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3232 set_pin_power_state(codec, 0x27, &parm);
3233 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
3234 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
3236 /* PW2 (26h), AOW2 (ah) */
3238 set_pin_power_state(codec, 0x26, &parm);
3239 if (spec->smart51_enabled)
3240 set_pin_power_state(codec, 0x2b, &parm);
3241 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
3243 /* PW0 (24h), AOW0 (8h) */
3245 set_pin_power_state(codec, 0x24, &parm);
3246 if (!spec->hp_independent_mode) /* check for redirected HP */
3247 set_pin_power_state(codec, 0x28, &parm);
3248 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3249 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3250 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3251 imux_is_smixer ? AC_PWRST_D0 : parm);
3253 /* PW1 (25h), AOW1 (9h) */
3255 set_pin_power_state(codec, 0x25, &parm);
3256 if (spec->smart51_enabled)
3257 set_pin_power_state(codec, 0x2a, &parm);
3258 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3260 if (spec->hp_independent_mode) {
3261 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3263 set_pin_power_state(codec, 0x28, &parm);
3264 snd_hda_codec_write(codec, 0x1b, 0,
3265 AC_VERB_SET_POWER_STATE, parm);
3266 snd_hda_codec_write(codec, 0x34, 0,
3267 AC_VERB_SET_POWER_STATE, parm);
3268 snd_hda_codec_write(codec, 0xc, 0,
3269 AC_VERB_SET_POWER_STATE, parm);
3273 /* Add a connection to the primary DAC from AA-mixer for some codecs
3274 * This isn't listed from the raw info, but the chip has a secret connection.
3276 static int add_secret_dac_path(struct hda_codec *codec)
3278 struct via_spec *spec = codec->spec;
3283 if (!spec->aa_mix_nid)
3285 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3286 ARRAY_SIZE(conn) - 1);
3287 for (i = 0; i < nums; i++) {
3288 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3292 /* find the primary DAC and add to the connection list */
3293 nid = codec->start_nid;
3294 for (i = 0; i < codec->num_nodes; i++, nid++) {
3295 unsigned int caps = get_wcaps(codec, nid);
3296 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3297 !(caps & AC_WCAP_DIGITAL)) {
3299 return snd_hda_override_conn_list(codec,
3308 static int patch_vt1718S(struct hda_codec *codec)
3310 struct via_spec *spec;
3313 /* create a codec specific record */
3314 spec = via_new_spec(codec);
3318 spec->aa_mix_nid = 0x21;
3319 override_mic_boost(codec, 0x2b, 0, 3, 40);
3320 override_mic_boost(codec, 0x29, 0, 3, 40);
3321 add_secret_dac_path(codec);
3323 /* automatic parse from the BIOS config */
3324 err = via_parse_auto_config(codec);
3330 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3332 codec->patch_ops = via_patch_ops;
3334 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3339 /* Patch for VT1716S */
3341 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3342 struct snd_ctl_elem_info *uinfo)
3344 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3346 uinfo->value.integer.min = 0;
3347 uinfo->value.integer.max = 1;
3351 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3352 struct snd_ctl_elem_value *ucontrol)
3354 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3357 index = snd_hda_codec_read(codec, 0x26, 0,
3358 AC_VERB_GET_CONNECT_SEL, 0);
3360 *ucontrol->value.integer.value = index;
3365 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3366 struct snd_ctl_elem_value *ucontrol)
3368 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3369 struct via_spec *spec = codec->spec;
3370 int index = *ucontrol->value.integer.value;
3372 snd_hda_codec_write(codec, 0x26, 0,
3373 AC_VERB_SET_CONNECT_SEL, index);
3374 spec->dmic_enabled = index;
3375 set_widgets_power_state(codec);
3379 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3380 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3382 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3383 .name = "Digital Mic Capture Switch",
3384 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3386 .info = vt1716s_dmic_info,
3387 .get = vt1716s_dmic_get,
3388 .put = vt1716s_dmic_put,
3394 /* mono-out mixer elements */
3395 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3396 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3400 static const struct hda_verb vt1716S_init_verbs[] = {
3401 /* Enable Boost Volume backdoor */
3403 /* don't bybass mixer */
3405 /* Enable mono output */
3410 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3412 struct via_spec *spec = codec->spec;
3415 unsigned int mono_out, present;
3416 /* SW0 (17h) = stereo mixer */
3418 (snd_hda_codec_read(codec, 0x17, 0,
3419 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3421 /* PW 1/2/5 (1ah/1bh/1eh) */
3423 set_pin_power_state(codec, 0x1a, &parm);
3424 set_pin_power_state(codec, 0x1b, &parm);
3425 set_pin_power_state(codec, 0x1e, &parm);
3428 /* SW0 (17h), AIW0(13h) */
3429 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3430 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3433 set_pin_power_state(codec, 0x1e, &parm);
3435 if (spec->dmic_enabled)
3436 set_pin_power_state(codec, 0x22, &parm);
3438 snd_hda_codec_write(codec, 0x22, 0,
3439 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3441 /* SW2(26h), AIW1(14h) */
3442 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3443 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3446 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3448 set_pin_power_state(codec, 0x19, &parm);
3449 /* Smart 5.1 PW2(1bh) */
3450 if (spec->smart51_enabled)
3451 set_pin_power_state(codec, 0x1b, &parm);
3452 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3453 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3455 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3457 set_pin_power_state(codec, 0x23, &parm);
3458 /* Smart 5.1 PW1(1ah) */
3459 if (spec->smart51_enabled)
3460 set_pin_power_state(codec, 0x1a, &parm);
3461 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3463 /* Smart 5.1 PW5(1eh) */
3464 if (spec->smart51_enabled)
3465 set_pin_power_state(codec, 0x1e, &parm);
3466 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3469 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3470 present = snd_hda_jack_detect(codec, 0x1c);
3475 present = snd_hda_jack_detect(codec, 0x1d);
3476 if (!spec->hp_independent_mode && present)
3481 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3482 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3483 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3484 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3486 /* PW 3/4 (1ch/1dh) */
3488 set_pin_power_state(codec, 0x1c, &parm);
3489 set_pin_power_state(codec, 0x1d, &parm);
3490 /* HP Independent Mode, power on AOW3 */
3491 if (spec->hp_independent_mode)
3492 snd_hda_codec_write(codec, 0x25, 0,
3493 AC_VERB_SET_POWER_STATE, parm);
3495 /* force to D0 for internal Speaker */
3496 /* MW0 (16h), AOW0 (10h) */
3497 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3498 imux_is_smixer ? AC_PWRST_D0 : parm);
3499 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3500 mono_out ? AC_PWRST_D0 : parm);
3503 static int patch_vt1716S(struct hda_codec *codec)
3505 struct via_spec *spec;
3508 /* create a codec specific record */
3509 spec = via_new_spec(codec);
3513 spec->aa_mix_nid = 0x16;
3514 override_mic_boost(codec, 0x1a, 0, 3, 40);
3515 override_mic_boost(codec, 0x1e, 0, 3, 40);
3517 /* automatic parse from the BIOS config */
3518 err = via_parse_auto_config(codec);
3524 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3526 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3529 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3531 codec->patch_ops = via_patch_ops;
3533 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3539 static const struct hda_verb vt2002P_init_verbs[] = {
3540 /* Class-D speaker related verbs */
3544 /* Enable Boost Volume backdoor */
3546 /* Enable AOW0 to MW9 */
3551 static const struct hda_verb vt1802_init_verbs[] = {
3552 /* Enable Boost Volume backdoor */
3554 /* Enable AOW0 to MW9 */
3559 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3561 struct via_spec *spec = codec->spec;
3564 unsigned int present;
3565 /* MUX9 (1eh) = stereo mixer */
3567 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3569 /* PW 5/6/7 (29h/2ah/2bh) */
3571 set_pin_power_state(codec, 0x29, &parm);
3572 set_pin_power_state(codec, 0x2a, &parm);
3573 set_pin_power_state(codec, 0x2b, &parm);
3575 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3576 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3577 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3578 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3579 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3583 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3585 if (spec->codec_type == VT1802) {
3586 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3588 set_pin_power_state(codec, 0x28, &parm);
3589 snd_hda_codec_write(codec, 0x18, 0,
3590 AC_VERB_SET_POWER_STATE, parm);
3591 snd_hda_codec_write(codec, 0x38, 0,
3592 AC_VERB_SET_POWER_STATE, parm);
3594 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3596 set_pin_power_state(codec, 0x26, &parm);
3597 snd_hda_codec_write(codec, 0x1c, 0,
3598 AC_VERB_SET_POWER_STATE, parm);
3599 snd_hda_codec_write(codec, 0x37, 0,
3600 AC_VERB_SET_POWER_STATE, parm);
3603 if (spec->codec_type == VT1802) {
3604 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3606 set_pin_power_state(codec, 0x25, &parm);
3607 snd_hda_codec_write(codec, 0x15, 0,
3608 AC_VERB_SET_POWER_STATE, parm);
3609 snd_hda_codec_write(codec, 0x35, 0,
3610 AC_VERB_SET_POWER_STATE, parm);
3612 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3614 set_pin_power_state(codec, 0x25, &parm);
3615 snd_hda_codec_write(codec, 0x19, 0,
3616 AC_VERB_SET_POWER_STATE, parm);
3617 snd_hda_codec_write(codec, 0x35, 0,
3618 AC_VERB_SET_POWER_STATE, parm);
3621 if (spec->hp_independent_mode)
3622 snd_hda_codec_write(codec, 0x9, 0,
3623 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3626 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3627 present = snd_hda_jack_detect(codec, 0x25);
3630 set_pin_power_state(codec, 0x24, &parm);
3631 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3632 if (spec->codec_type == VT1802)
3633 snd_hda_codec_write(codec, 0x14, 0,
3634 AC_VERB_SET_POWER_STATE, parm);
3636 snd_hda_codec_write(codec, 0x18, 0,
3637 AC_VERB_SET_POWER_STATE, parm);
3638 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3641 present = snd_hda_jack_detect(codec, 0x26);
3643 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3644 if (spec->codec_type == VT1802) {
3645 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3646 snd_hda_codec_write(codec, 0x33, 0,
3647 AC_VERB_SET_POWER_STATE, parm);
3648 snd_hda_codec_write(codec, 0x1c, 0,
3649 AC_VERB_SET_POWER_STATE, parm);
3650 snd_hda_codec_write(codec, 0x3c, 0,
3651 AC_VERB_SET_POWER_STATE, parm);
3653 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3654 snd_hda_codec_write(codec, 0x31, 0,
3655 AC_VERB_SET_POWER_STATE, parm);
3656 snd_hda_codec_write(codec, 0x17, 0,
3657 AC_VERB_SET_POWER_STATE, parm);
3658 snd_hda_codec_write(codec, 0x3b, 0,
3659 AC_VERB_SET_POWER_STATE, parm);
3662 if (imux_is_smixer || !is_aa_path_mute(codec))
3663 snd_hda_codec_write(codec, 0x21, 0,
3664 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3666 snd_hda_codec_write(codec, 0x21, 0,
3667 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3670 /* patch for vt2002P */
3671 static int patch_vt2002P(struct hda_codec *codec)
3673 struct via_spec *spec;
3676 /* create a codec specific record */
3677 spec = via_new_spec(codec);
3681 spec->aa_mix_nid = 0x21;
3682 override_mic_boost(codec, 0x2b, 0, 3, 40);
3683 override_mic_boost(codec, 0x29, 0, 3, 40);
3684 add_secret_dac_path(codec);
3686 /* automatic parse from the BIOS config */
3687 err = via_parse_auto_config(codec);
3693 if (spec->codec_type == VT1802)
3694 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3696 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3698 codec->patch_ops = via_patch_ops;
3700 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3706 static const struct hda_verb vt1812_init_verbs[] = {
3707 /* Enable Boost Volume backdoor */
3709 /* Enable AOW0 to MW9 */
3714 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3716 struct via_spec *spec = codec->spec;
3718 unsigned int present;
3720 /* PW 5/6/7 (29h/2ah/2bh) */
3722 set_pin_power_state(codec, 0x29, &parm);
3723 set_pin_power_state(codec, 0x2a, &parm);
3724 set_pin_power_state(codec, 0x2b, &parm);
3726 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3727 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3728 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3729 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3730 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3734 snd_hda_codec_write(codec, 0x8, 0,
3735 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3737 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3739 set_pin_power_state(codec, 0x28, &parm);
3740 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3741 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3743 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3745 set_pin_power_state(codec, 0x25, &parm);
3746 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3747 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3748 if (spec->hp_independent_mode)
3749 snd_hda_codec_write(codec, 0x9, 0,
3750 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3752 /* Internal Speaker */
3753 /* PW0 (24h), MW0(14h), MUX0(34h) */
3754 present = snd_hda_jack_detect(codec, 0x25);
3757 set_pin_power_state(codec, 0x24, &parm);
3759 snd_hda_codec_write(codec, 0x14, 0,
3760 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3761 snd_hda_codec_write(codec, 0x34, 0,
3762 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3764 snd_hda_codec_write(codec, 0x14, 0,
3765 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3766 snd_hda_codec_write(codec, 0x34, 0,
3767 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3772 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3773 present = snd_hda_jack_detect(codec, 0x28);
3776 set_pin_power_state(codec, 0x31, &parm);
3778 snd_hda_codec_write(codec, 0x1c, 0,
3779 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3780 snd_hda_codec_write(codec, 0x3c, 0,
3781 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3782 snd_hda_codec_write(codec, 0x3e, 0,
3783 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3785 snd_hda_codec_write(codec, 0x1c, 0,
3786 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3787 snd_hda_codec_write(codec, 0x3c, 0,
3788 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3789 snd_hda_codec_write(codec, 0x3e, 0,
3790 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3793 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3795 set_pin_power_state(codec, 0x33, &parm);
3796 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3797 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3801 /* patch for vt1812 */
3802 static int patch_vt1812(struct hda_codec *codec)
3804 struct via_spec *spec;
3807 /* create a codec specific record */
3808 spec = via_new_spec(codec);
3812 spec->aa_mix_nid = 0x21;
3813 override_mic_boost(codec, 0x2b, 0, 3, 40);
3814 override_mic_boost(codec, 0x29, 0, 3, 40);
3815 add_secret_dac_path(codec);
3817 /* automatic parse from the BIOS config */
3818 err = via_parse_auto_config(codec);
3824 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3826 codec->patch_ops = via_patch_ops;
3828 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3835 static const struct hda_codec_preset snd_hda_preset_via[] = {
3836 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3837 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3838 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3839 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3840 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3841 .patch = patch_vt1709},
3842 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3843 .patch = patch_vt1709},
3844 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3845 .patch = patch_vt1709},
3846 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3847 .patch = patch_vt1709},
3848 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3849 .patch = patch_vt1709},
3850 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3851 .patch = patch_vt1709},
3852 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3853 .patch = patch_vt1709},
3854 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3855 .patch = patch_vt1709},
3856 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3857 .patch = patch_vt1708B},
3858 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3859 .patch = patch_vt1708B},
3860 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3861 .patch = patch_vt1708B},
3862 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3863 .patch = patch_vt1708B},
3864 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3865 .patch = patch_vt1708B},
3866 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3867 .patch = patch_vt1708B},
3868 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3869 .patch = patch_vt1708B},
3870 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3871 .patch = patch_vt1708B},
3872 { .id = 0x11060397, .name = "VT1708S",
3873 .patch = patch_vt1708S},
3874 { .id = 0x11061397, .name = "VT1708S",
3875 .patch = patch_vt1708S},
3876 { .id = 0x11062397, .name = "VT1708S",
3877 .patch = patch_vt1708S},
3878 { .id = 0x11063397, .name = "VT1708S",
3879 .patch = patch_vt1708S},
3880 { .id = 0x11064397, .name = "VT1705",
3881 .patch = patch_vt1708S},
3882 { .id = 0x11065397, .name = "VT1708S",
3883 .patch = patch_vt1708S},
3884 { .id = 0x11066397, .name = "VT1708S",
3885 .patch = patch_vt1708S},
3886 { .id = 0x11067397, .name = "VT1708S",
3887 .patch = patch_vt1708S},
3888 { .id = 0x11060398, .name = "VT1702",
3889 .patch = patch_vt1702},
3890 { .id = 0x11061398, .name = "VT1702",
3891 .patch = patch_vt1702},
3892 { .id = 0x11062398, .name = "VT1702",
3893 .patch = patch_vt1702},
3894 { .id = 0x11063398, .name = "VT1702",
3895 .patch = patch_vt1702},
3896 { .id = 0x11064398, .name = "VT1702",
3897 .patch = patch_vt1702},
3898 { .id = 0x11065398, .name = "VT1702",
3899 .patch = patch_vt1702},
3900 { .id = 0x11066398, .name = "VT1702",
3901 .patch = patch_vt1702},
3902 { .id = 0x11067398, .name = "VT1702",
3903 .patch = patch_vt1702},
3904 { .id = 0x11060428, .name = "VT1718S",
3905 .patch = patch_vt1718S},
3906 { .id = 0x11064428, .name = "VT1718S",
3907 .patch = patch_vt1718S},
3908 { .id = 0x11060441, .name = "VT2020",
3909 .patch = patch_vt1718S},
3910 { .id = 0x11064441, .name = "VT1828S",
3911 .patch = patch_vt1718S},
3912 { .id = 0x11060433, .name = "VT1716S",
3913 .patch = patch_vt1716S},
3914 { .id = 0x1106a721, .name = "VT1716S",
3915 .patch = patch_vt1716S},
3916 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3917 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3918 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3919 { .id = 0x11060440, .name = "VT1818S",
3920 .patch = patch_vt1708S},
3921 { .id = 0x11060446, .name = "VT1802",
3922 .patch = patch_vt2002P},
3923 { .id = 0x11068446, .name = "VT1802",
3924 .patch = patch_vt2002P},
3928 MODULE_ALIAS("snd-hda-codec-id:1106*");
3930 static struct hda_codec_preset_list via_list = {
3931 .preset = snd_hda_preset_via,
3932 .owner = THIS_MODULE,
3935 MODULE_LICENSE("GPL");
3936 MODULE_DESCRIPTION("VIA HD-audio codec");
3938 static int __init patch_via_init(void)
3940 return snd_hda_add_codec_preset(&via_list);
3943 static void __exit patch_via_exit(void)
3945 snd_hda_delete_codec_preset(&via_list);
3948 module_init(patch_via_init)
3949 module_exit(patch_via_exit)