2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
58 #define VT1708_HP_PIN_NID 0x20
59 #define VT1708_CD_PIN_NID 0x24
79 #define VT2002P_COMPATIBLE(spec) \
80 ((spec)->codec_type == VT2002P ||\
81 (spec)->codec_type == VT1812 ||\
82 (spec)->codec_type == VT1802)
84 #define MAX_NID_PATH_DEPTH 5
86 /* output-path: DAC -> ... -> pin
87 * idx[] contains the source index number of the next widget;
88 * e.g. idx[0] is the index of the DAC selected by path[1] widget
89 * multi[] indicates whether it's a selector widget with multi-connectors
90 * (i.e. the connection selection is mandatory)
91 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
95 hda_nid_t path[MAX_NID_PATH_DEPTH];
96 unsigned char idx[MAX_NID_PATH_DEPTH];
97 unsigned char multi[MAX_NID_PATH_DEPTH];
99 unsigned int mute_ctl;
104 hda_nid_t pin; /* input-pin or aa-mix */
105 int adc_idx; /* ADC index to be used */
106 int mux_idx; /* MUX index (if any) */
107 const char *label; /* input-source label */
110 #define VIA_MAX_ADCS 3
113 STREAM_MULTI_OUT = (1 << 0),
114 STREAM_INDEP_HP = (1 << 1),
118 /* codec parameterization */
119 const struct snd_kcontrol_new *mixers[6];
120 unsigned int num_mixers;
122 const struct hda_verb *init_verbs[5];
123 unsigned int num_iverbs;
125 char stream_name_analog[32];
126 char stream_name_hp[32];
127 const struct hda_pcm_stream *stream_analog_playback;
128 const struct hda_pcm_stream *stream_analog_capture;
130 char stream_name_digital[32];
131 const struct hda_pcm_stream *stream_digital_playback;
132 const struct hda_pcm_stream *stream_digital_capture;
135 struct hda_multi_out multiout;
136 hda_nid_t slave_dig_outs[2];
137 hda_nid_t hp_dac_nid;
138 hda_nid_t speaker_dac_nid;
139 int hp_indep_shared; /* indep HP-DAC is shared with side ch */
140 int opened_streams; /* STREAM_* bits */
141 int active_streams; /* STREAM_* bits */
142 int aamix_mode; /* loopback is enabled for output-path? */
145 * There are different output-paths depending on the setup.
146 * out_path, hp_path and speaker_path are primary paths. If both
147 * direct DAC and aa-loopback routes are available, these contain
148 * the former paths. Meanwhile *_mix_path contain the paths with
149 * loopback mixer. (Since the loopback is only for front channel,
150 * no out_mix_path for surround channels.)
151 * The HP output has another path, hp_indep_path, which is used in
152 * the independent-HP mode.
154 struct nid_path out_path[HDA_SIDE + 1];
155 struct nid_path out_mix_path;
156 struct nid_path hp_path;
157 struct nid_path hp_mix_path;
158 struct nid_path hp_indep_path;
159 struct nid_path speaker_path;
160 struct nid_path speaker_mix_path;
163 unsigned int num_adc_nids;
164 hda_nid_t adc_nids[VIA_MAX_ADCS];
165 hda_nid_t mux_nids[VIA_MAX_ADCS];
166 hda_nid_t aa_mix_nid;
167 hda_nid_t dig_in_nid;
172 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
173 unsigned int cur_mux[VIA_MAX_ADCS];
175 /* dynamic DAC switching */
176 unsigned int cur_dac_stream_tag;
177 unsigned int cur_dac_format;
178 unsigned int cur_hp_stream_tag;
179 unsigned int cur_hp_format;
181 /* dynamic ADC switching */
183 unsigned int cur_adc_stream_tag;
184 unsigned int cur_adc_format;
186 /* PCM information */
187 struct hda_pcm pcm_rec[3];
189 /* dynamic controls, init_verbs and input_mux */
190 struct auto_pin_cfg autocfg;
191 struct snd_array kctls;
192 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
195 unsigned int hp_independent_mode;
196 unsigned int dmic_enabled;
197 unsigned int no_pin_power_ctl;
198 enum VIA_HDA_CODEC codec_type;
201 unsigned int smart51_nums;
202 hda_nid_t smart51_pins[2];
204 const char *smart51_labels[2];
205 unsigned int smart51_enabled;
207 /* work to check hp jack state */
208 struct hda_codec *codec;
209 struct delayed_work vt1708_hp_work;
210 int vt1708_jack_detect;
211 int vt1708_hp_present;
213 void (*set_widgets_power_state)(struct hda_codec *codec);
215 struct hda_loopback_check loopback;
217 struct hda_amp_list loopback_list[8];
219 /* bind capture-volume */
220 struct hda_bind_ctls *bind_cap_vol;
221 struct hda_bind_ctls *bind_cap_sw;
223 struct mutex config_mutex;
226 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
227 static struct via_spec * via_new_spec(struct hda_codec *codec)
229 struct via_spec *spec;
231 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
235 mutex_init(&spec->config_mutex);
238 spec->codec_type = get_codec_type(codec);
239 /* VT1708BCE & VT1708S are almost same */
240 if (spec->codec_type == VT1708BCE)
241 spec->codec_type = VT1708S;
245 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
247 u32 vendor_id = codec->vendor_id;
248 u16 ven_id = vendor_id >> 16;
249 u16 dev_id = vendor_id & 0xffff;
250 enum VIA_HDA_CODEC codec_type;
253 if (ven_id != 0x1106)
254 codec_type = UNKNOWN;
255 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
257 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
258 codec_type = VT1709_10CH;
259 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
260 codec_type = VT1709_6CH;
261 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
262 codec_type = VT1708B_8CH;
263 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
264 codec_type = VT1708BCE;
265 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
266 codec_type = VT1708B_4CH;
267 else if ((dev_id & 0xfff) == 0x397
268 && (dev_id >> 12) < 8)
269 codec_type = VT1708S;
270 else if ((dev_id & 0xfff) == 0x398
271 && (dev_id >> 12) < 8)
273 else if ((dev_id & 0xfff) == 0x428
274 && (dev_id >> 12) < 8)
275 codec_type = VT1718S;
276 else if (dev_id == 0x0433 || dev_id == 0xa721)
277 codec_type = VT1716S;
278 else if (dev_id == 0x0441 || dev_id == 0x4441)
279 codec_type = VT1718S;
280 else if (dev_id == 0x0438 || dev_id == 0x4438)
281 codec_type = VT2002P;
282 else if (dev_id == 0x0448)
284 else if (dev_id == 0x0440)
285 codec_type = VT1708S;
286 else if ((dev_id & 0xfff) == 0x446)
289 codec_type = UNKNOWN;
293 #define VIA_JACK_EVENT 0x20
294 #define VIA_HP_EVENT 0x01
295 #define VIA_GPIO_EVENT 0x02
296 #define VIA_LINE_EVENT 0x03
301 VIA_CTL_WIDGET_ANALOG_MUTE,
304 static void analog_low_current_mode(struct hda_codec *codec);
305 static bool is_aa_path_mute(struct hda_codec *codec);
307 static void vt1708_start_hp_work(struct via_spec *spec)
309 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
311 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
312 !spec->vt1708_jack_detect);
313 if (!delayed_work_pending(&spec->vt1708_hp_work))
314 schedule_delayed_work(&spec->vt1708_hp_work,
315 msecs_to_jiffies(100));
318 static void vt1708_stop_hp_work(struct via_spec *spec)
320 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
322 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
323 && !is_aa_path_mute(spec->codec))
325 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
326 !spec->vt1708_jack_detect);
327 cancel_delayed_work_sync(&spec->vt1708_hp_work);
330 static void set_widgets_power_state(struct hda_codec *codec)
332 struct via_spec *spec = codec->spec;
333 if (spec->set_widgets_power_state)
334 spec->set_widgets_power_state(codec);
337 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
338 struct snd_ctl_elem_value *ucontrol)
340 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
341 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
343 set_widgets_power_state(codec);
344 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
345 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
346 if (is_aa_path_mute(codec))
347 vt1708_start_hp_work(codec->spec);
349 vt1708_stop_hp_work(codec->spec);
354 /* modify .put = snd_hda_mixer_amp_switch_put */
355 #define ANALOG_INPUT_MUTE \
356 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
359 .info = snd_hda_mixer_amp_switch_info, \
360 .get = snd_hda_mixer_amp_switch_get, \
361 .put = analog_input_switch_put, \
362 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
364 static const struct snd_kcontrol_new via_control_templates[] = {
365 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
366 HDA_CODEC_MUTE(NULL, 0, 0, 0),
371 /* add dynamic controls */
372 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
373 const struct snd_kcontrol_new *tmpl,
376 struct snd_kcontrol_new *knew;
378 snd_array_init(&spec->kctls, sizeof(*knew), 32);
379 knew = snd_array_new(&spec->kctls);
386 knew->name = kstrdup(name, GFP_KERNEL);
393 static int __via_add_control(struct via_spec *spec, int type, const char *name,
394 int idx, unsigned long val)
396 struct snd_kcontrol_new *knew;
398 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
402 if (get_amp_nid_(val))
403 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
404 knew->private_value = val;
408 #define via_add_control(spec, type, name, val) \
409 __via_add_control(spec, type, name, 0, val)
411 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
413 static void via_free_kctls(struct hda_codec *codec)
415 struct via_spec *spec = codec->spec;
417 if (spec->kctls.list) {
418 struct snd_kcontrol_new *kctl = spec->kctls.list;
420 for (i = 0; i < spec->kctls.used; i++)
423 snd_array_free(&spec->kctls);
426 /* create input playback/capture controls for the given pin */
427 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
428 int type_idx, int idx, int mix_nid)
433 sprintf(name, "%s Playback Volume", ctlname);
434 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
435 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
438 sprintf(name, "%s Playback Switch", ctlname);
439 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
440 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
446 #define get_connection_index(codec, mux, nid) \
447 snd_hda_get_conn_index(codec, mux, nid, 0)
449 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
455 caps = get_wcaps(codec, nid);
456 if (dir == HDA_INPUT)
457 caps &= AC_WCAP_IN_AMP;
459 caps &= AC_WCAP_OUT_AMP;
462 if (query_amp_caps(codec, nid, dir) & mask)
467 #define have_mute(codec, nid, dir) \
468 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
470 /* enable/disable the output-route mixers */
471 static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
472 hda_nid_t mix_nid, int idx, bool enable)
478 num = snd_hda_get_conn_list(codec, mix_nid, NULL);
479 for (i = 0; i < num; i++) {
481 val = AMP_IN_UNMUTE(i);
483 val = AMP_IN_MUTE(i);
484 snd_hda_codec_write(codec, mix_nid, 0,
485 AC_VERB_SET_AMP_GAIN_MUTE, val);
489 /* enable/disable the output-route */
490 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
491 bool enable, bool force)
493 struct via_spec *spec = codec->spec;
495 for (i = 0; i < path->depth; i++) {
497 int idx = path->idx[i];
499 if (i < path->depth - 1)
500 dst = path->path[i + 1];
503 if (enable && path->multi[i])
504 snd_hda_codec_write(codec, dst, 0,
505 AC_VERB_SET_CONNECT_SEL, idx);
506 if (!force && (dst == spec->aa_mix_nid))
508 if (have_mute(codec, dst, HDA_INPUT))
509 activate_output_mix(codec, path, dst, idx, enable);
510 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
512 if (have_mute(codec, src, HDA_OUTPUT)) {
513 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
514 snd_hda_codec_write(codec, src, 0,
515 AC_VERB_SET_AMP_GAIN_MUTE, val);
520 /* set the given pin as output */
521 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
526 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
528 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
529 snd_hda_codec_write(codec, pin, 0,
530 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
533 static void via_auto_init_output(struct hda_codec *codec,
534 struct nid_path *path, int pin_type)
541 pin = path->path[path->depth - 1];
543 init_output_pin(codec, pin, pin_type);
544 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
545 if (caps & AC_AMPCAP_MUTE) {
547 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
548 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
551 activate_output_path(codec, path, true, true); /* force on */
554 static void via_auto_init_multi_out(struct hda_codec *codec)
556 struct via_spec *spec = codec->spec;
557 struct nid_path *path;
560 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
561 path = &spec->out_path[i];
562 if (!i && spec->aamix_mode && spec->out_mix_path.depth)
563 path = &spec->out_mix_path;
564 via_auto_init_output(codec, path, PIN_OUT);
568 /* deactivate the inactive headphone-paths */
569 static void deactivate_hp_paths(struct hda_codec *codec)
571 struct via_spec *spec = codec->spec;
572 int shared = spec->hp_indep_shared;
574 if (spec->hp_independent_mode) {
575 activate_output_path(codec, &spec->hp_path, false, false);
576 activate_output_path(codec, &spec->hp_mix_path, false, false);
578 activate_output_path(codec, &spec->out_path[shared],
580 } else if (spec->aamix_mode || !spec->hp_path.depth) {
581 activate_output_path(codec, &spec->hp_indep_path, false, false);
582 activate_output_path(codec, &spec->hp_path, false, false);
584 activate_output_path(codec, &spec->hp_indep_path, false, false);
585 activate_output_path(codec, &spec->hp_mix_path, false, false);
589 static void via_auto_init_hp_out(struct hda_codec *codec)
591 struct via_spec *spec = codec->spec;
593 if (!spec->hp_path.depth) {
594 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
597 deactivate_hp_paths(codec);
598 if (spec->hp_independent_mode)
599 via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
600 else if (spec->aamix_mode)
601 via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
603 via_auto_init_output(codec, &spec->hp_path, PIN_HP);
606 static void via_auto_init_speaker_out(struct hda_codec *codec)
608 struct via_spec *spec = codec->spec;
610 if (!spec->autocfg.speaker_outs)
612 if (!spec->speaker_path.depth) {
613 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
616 if (!spec->aamix_mode) {
617 activate_output_path(codec, &spec->speaker_mix_path,
619 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
621 activate_output_path(codec, &spec->speaker_path, false, false);
622 via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
626 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
627 static void via_hp_automute(struct hda_codec *codec);
629 static void via_auto_init_analog_input(struct hda_codec *codec)
631 struct via_spec *spec = codec->spec;
632 const struct auto_pin_cfg *cfg = &spec->autocfg;
633 hda_nid_t conn[HDA_MAX_CONNECTIONS];
638 for (i = 0; i < spec->num_adc_nids; i++) {
639 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
640 AC_VERB_SET_AMP_GAIN_MUTE,
645 for (i = 0; i < cfg->num_inputs; i++) {
646 hda_nid_t nid = cfg->inputs[i].pin;
647 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
649 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
653 snd_hda_codec_write(codec, nid, 0,
654 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
658 for (i = 0; i < spec->num_adc_nids; i++) {
659 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
660 if (spec->mux_nids[adc_idx]) {
661 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
662 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
663 AC_VERB_SET_CONNECT_SEL,
666 if (spec->dyn_adc_switch)
667 break; /* only one input-src */
671 if (!spec->aa_mix_nid)
673 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
675 for (i = 0; i < num_conns; i++) {
676 unsigned int caps = get_wcaps(codec, conn[i]);
677 if (get_wcaps_type(caps) == AC_WID_PIN)
678 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
679 AC_VERB_SET_AMP_GAIN_MUTE,
684 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
685 unsigned int *affected_parm)
688 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
689 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
690 >> AC_DEFCFG_MISC_SHIFT
691 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
692 struct via_spec *spec = codec->spec;
693 unsigned present = 0;
695 no_presence |= spec->no_pin_power_ctl;
697 present = snd_hda_jack_detect(codec, nid);
698 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
699 || ((no_presence || present)
700 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
701 *affected_parm = AC_PWRST_D0; /* if it's connected */
706 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
709 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
710 struct snd_ctl_elem_info *uinfo)
712 static const char * const texts[] = {
713 "Disabled", "Enabled"
716 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
718 uinfo->value.enumerated.items = 2;
719 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
720 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
721 strcpy(uinfo->value.enumerated.name,
722 texts[uinfo->value.enumerated.item]);
726 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
727 struct snd_ctl_elem_value *ucontrol)
729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
730 struct via_spec *spec = codec->spec;
731 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
735 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
736 struct snd_ctl_elem_value *ucontrol)
738 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
739 struct via_spec *spec = codec->spec;
740 unsigned int val = !ucontrol->value.enumerated.item[0];
742 if (val == spec->no_pin_power_ctl)
744 spec->no_pin_power_ctl = val;
745 set_widgets_power_state(codec);
749 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
751 .name = "Dynamic Power-Control",
752 .info = via_pin_power_ctl_info,
753 .get = via_pin_power_ctl_get,
754 .put = via_pin_power_ctl_put,
758 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
759 struct snd_ctl_elem_info *uinfo)
761 static const char * const texts[] = { "OFF", "ON" };
763 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
765 uinfo->value.enumerated.items = 2;
766 if (uinfo->value.enumerated.item >= 2)
767 uinfo->value.enumerated.item = 1;
768 strcpy(uinfo->value.enumerated.name,
769 texts[uinfo->value.enumerated.item]);
773 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
774 struct snd_ctl_elem_value *ucontrol)
776 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
777 struct via_spec *spec = codec->spec;
779 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
783 /* adjust spec->multiout setup according to the current flags */
784 static void setup_playback_multi_pcm(struct via_spec *spec)
786 const struct auto_pin_cfg *cfg = &spec->autocfg;
787 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
788 spec->multiout.hp_nid = 0;
789 if (!spec->hp_independent_mode) {
790 if (!spec->hp_indep_shared)
791 spec->multiout.hp_nid = spec->hp_dac_nid;
793 if (spec->hp_indep_shared)
794 spec->multiout.num_dacs = cfg->line_outs - 1;
798 /* update DAC setups according to indep-HP switch;
799 * this function is called only when indep-HP is modified
801 static void switch_indep_hp_dacs(struct hda_codec *codec)
803 struct via_spec *spec = codec->spec;
804 int shared = spec->hp_indep_shared;
805 hda_nid_t shared_dac, hp_dac;
807 if (!spec->opened_streams)
810 shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
811 hp_dac = spec->hp_dac_nid;
812 if (spec->hp_independent_mode) {
813 /* switch to indep-HP mode */
814 if (spec->active_streams & STREAM_MULTI_OUT) {
815 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
816 __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
818 if (spec->active_streams & STREAM_INDEP_HP)
819 snd_hda_codec_setup_stream(codec, hp_dac,
820 spec->cur_hp_stream_tag, 0,
821 spec->cur_hp_format);
823 /* back to HP or shared-DAC */
824 if (spec->active_streams & STREAM_INDEP_HP)
825 __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
826 if (spec->active_streams & STREAM_MULTI_OUT) {
829 if (shared_dac) { /* reset mutli-ch DAC */
832 } else { /* reset HP DAC */
836 snd_hda_codec_setup_stream(codec, dac,
837 spec->cur_dac_stream_tag, ch,
838 spec->cur_dac_format);
841 setup_playback_multi_pcm(spec);
844 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
845 struct snd_ctl_elem_value *ucontrol)
847 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
848 struct via_spec *spec = codec->spec;
851 mutex_lock(&spec->config_mutex);
852 cur = !!ucontrol->value.enumerated.item[0];
853 if (spec->hp_independent_mode == cur) {
854 mutex_unlock(&spec->config_mutex);
857 spec->hp_independent_mode = cur;
858 shared = spec->hp_indep_shared;
859 deactivate_hp_paths(codec);
861 activate_output_path(codec, &spec->hp_indep_path, true, false);
864 activate_output_path(codec, &spec->out_path[shared],
866 if (spec->aamix_mode || !spec->hp_path.depth)
867 activate_output_path(codec, &spec->hp_mix_path,
870 activate_output_path(codec, &spec->hp_path,
874 switch_indep_hp_dacs(codec);
875 mutex_unlock(&spec->config_mutex);
877 /* update jack power state */
878 set_widgets_power_state(codec);
879 via_hp_automute(codec);
883 static const struct snd_kcontrol_new via_hp_mixer = {
884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
885 .name = "Independent HP",
886 .info = via_independent_hp_info,
887 .get = via_independent_hp_get,
888 .put = via_independent_hp_put,
891 static int via_hp_build(struct hda_codec *codec)
893 struct via_spec *spec = codec->spec;
894 struct snd_kcontrol_new *knew;
897 nid = spec->autocfg.hp_pins[0];
898 knew = via_clone_control(spec, &via_hp_mixer);
902 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
907 static void notify_aa_path_ctls(struct hda_codec *codec)
909 struct via_spec *spec = codec->spec;
912 for (i = 0; i < spec->smart51_nums; i++) {
913 struct snd_kcontrol *ctl;
914 struct snd_ctl_elem_id id;
915 memset(&id, 0, sizeof(id));
916 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
917 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
918 ctl = snd_hda_find_mixer_ctl(codec, id.name);
920 snd_ctl_notify(codec->bus->card,
921 SNDRV_CTL_EVENT_MASK_VALUE,
926 static void mute_aa_path(struct hda_codec *codec, int mute)
928 struct via_spec *spec = codec->spec;
929 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
932 /* check AA path's mute status */
933 for (i = 0; i < spec->smart51_nums; i++) {
934 if (spec->smart51_idxs[i] < 0)
936 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
937 HDA_INPUT, spec->smart51_idxs[i],
942 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
944 struct via_spec *spec = codec->spec;
947 for (i = 0; i < spec->smart51_nums; i++)
948 if (spec->smart51_pins[i] == pin)
953 static int via_smart51_get(struct snd_kcontrol *kcontrol,
954 struct snd_ctl_elem_value *ucontrol)
956 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
957 struct via_spec *spec = codec->spec;
959 *ucontrol->value.integer.value = spec->smart51_enabled;
963 static int via_smart51_put(struct snd_kcontrol *kcontrol,
964 struct snd_ctl_elem_value *ucontrol)
966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
967 struct via_spec *spec = codec->spec;
968 int out_in = *ucontrol->value.integer.value
969 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
972 for (i = 0; i < spec->smart51_nums; i++) {
973 hda_nid_t nid = spec->smart51_pins[i];
976 parm = snd_hda_codec_read(codec, nid, 0,
977 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
978 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
980 snd_hda_codec_write(codec, nid, 0,
981 AC_VERB_SET_PIN_WIDGET_CONTROL,
983 if (out_in == AC_PINCTL_OUT_EN) {
984 mute_aa_path(codec, 1);
985 notify_aa_path_ctls(codec);
988 spec->smart51_enabled = *ucontrol->value.integer.value;
989 set_widgets_power_state(codec);
993 static const struct snd_kcontrol_new via_smart51_mixer = {
994 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
997 .info = snd_ctl_boolean_mono_info,
998 .get = via_smart51_get,
999 .put = via_smart51_put,
1002 static int via_smart51_build(struct hda_codec *codec)
1004 struct via_spec *spec = codec->spec;
1006 if (!spec->smart51_nums)
1008 if (!via_clone_control(spec, &via_smart51_mixer))
1013 /* check AA path's mute status */
1014 static bool is_aa_path_mute(struct hda_codec *codec)
1016 struct via_spec *spec = codec->spec;
1017 const struct hda_amp_list *p;
1020 for (i = 0; i < spec->num_loopbacks; i++) {
1021 p = &spec->loopback_list[i];
1022 for (ch = 0; ch < 2; ch++) {
1023 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
1025 if (!(v & HDA_AMP_MUTE) && v > 0)
1032 /* enter/exit analog low-current mode */
1033 static void analog_low_current_mode(struct hda_codec *codec)
1035 struct via_spec *spec = codec->spec;
1037 unsigned int verb, parm;
1039 enable = is_aa_path_mute(codec) && (spec->opened_streams != 0);
1041 /* decide low current mode's verb & parameter */
1042 switch (spec->codec_type) {
1046 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1052 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1056 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1062 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1065 return; /* other codecs are not supported */
1068 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1072 * generic initialization of ADC, input mixers and output mixers
1074 static const struct hda_verb vt1708_init_verbs[] = {
1075 /* power down jack detect function */
1080 static void set_stream_open(struct hda_codec *codec, int bit, bool active)
1082 struct via_spec *spec = codec->spec;
1085 spec->opened_streams |= bit;
1087 spec->opened_streams &= ~bit;
1088 analog_low_current_mode(codec);
1091 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1092 struct hda_codec *codec,
1093 struct snd_pcm_substream *substream)
1095 struct via_spec *spec = codec->spec;
1096 const struct auto_pin_cfg *cfg = &spec->autocfg;
1099 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1100 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1101 set_stream_open(codec, STREAM_MULTI_OUT, true);
1102 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1105 set_stream_open(codec, STREAM_MULTI_OUT, false);
1111 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1112 struct hda_codec *codec,
1113 struct snd_pcm_substream *substream)
1115 set_stream_open(codec, STREAM_MULTI_OUT, false);
1119 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1120 struct hda_codec *codec,
1121 struct snd_pcm_substream *substream)
1123 struct via_spec *spec = codec->spec;
1125 if (snd_BUG_ON(!spec->hp_dac_nid))
1127 set_stream_open(codec, STREAM_INDEP_HP, true);
1131 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1132 struct hda_codec *codec,
1133 struct snd_pcm_substream *substream)
1135 set_stream_open(codec, STREAM_INDEP_HP, false);
1139 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1140 struct hda_codec *codec,
1141 unsigned int stream_tag,
1142 unsigned int format,
1143 struct snd_pcm_substream *substream)
1145 struct via_spec *spec = codec->spec;
1147 mutex_lock(&spec->config_mutex);
1148 setup_playback_multi_pcm(spec);
1149 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1151 /* remember for dynamic DAC switch with indep-HP */
1152 spec->active_streams |= STREAM_MULTI_OUT;
1153 spec->cur_dac_stream_tag = stream_tag;
1154 spec->cur_dac_format = format;
1155 mutex_unlock(&spec->config_mutex);
1156 vt1708_start_hp_work(spec);
1160 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1161 struct hda_codec *codec,
1162 unsigned int stream_tag,
1163 unsigned int format,
1164 struct snd_pcm_substream *substream)
1166 struct via_spec *spec = codec->spec;
1168 mutex_lock(&spec->config_mutex);
1169 if (spec->hp_independent_mode)
1170 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1171 stream_tag, 0, format);
1172 spec->active_streams |= STREAM_INDEP_HP;
1173 spec->cur_hp_stream_tag = stream_tag;
1174 spec->cur_hp_format = format;
1175 mutex_unlock(&spec->config_mutex);
1176 vt1708_start_hp_work(spec);
1180 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1181 struct hda_codec *codec,
1182 struct snd_pcm_substream *substream)
1184 struct via_spec *spec = codec->spec;
1186 mutex_lock(&spec->config_mutex);
1187 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1188 spec->active_streams &= ~STREAM_MULTI_OUT;
1189 mutex_unlock(&spec->config_mutex);
1190 vt1708_stop_hp_work(spec);
1194 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1195 struct hda_codec *codec,
1196 struct snd_pcm_substream *substream)
1198 struct via_spec *spec = codec->spec;
1200 mutex_lock(&spec->config_mutex);
1201 if (spec->hp_independent_mode)
1202 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1203 spec->active_streams &= ~STREAM_INDEP_HP;
1204 mutex_unlock(&spec->config_mutex);
1205 vt1708_stop_hp_work(spec);
1212 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1213 struct hda_codec *codec,
1214 struct snd_pcm_substream *substream)
1216 struct via_spec *spec = codec->spec;
1217 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1220 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1221 struct hda_codec *codec,
1222 struct snd_pcm_substream *substream)
1224 struct via_spec *spec = codec->spec;
1225 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1228 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1229 struct hda_codec *codec,
1230 unsigned int stream_tag,
1231 unsigned int format,
1232 struct snd_pcm_substream *substream)
1234 struct via_spec *spec = codec->spec;
1235 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1236 stream_tag, format, substream);
1239 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1240 struct hda_codec *codec,
1241 struct snd_pcm_substream *substream)
1243 struct via_spec *spec = codec->spec;
1244 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1251 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1252 struct hda_codec *codec,
1253 unsigned int stream_tag,
1254 unsigned int format,
1255 struct snd_pcm_substream *substream)
1257 struct via_spec *spec = codec->spec;
1259 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1260 stream_tag, 0, format);
1264 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1265 struct hda_codec *codec,
1266 struct snd_pcm_substream *substream)
1268 struct via_spec *spec = codec->spec;
1269 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1273 /* analog capture with dynamic ADC switching */
1274 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1275 struct hda_codec *codec,
1276 unsigned int stream_tag,
1277 unsigned int format,
1278 struct snd_pcm_substream *substream)
1280 struct via_spec *spec = codec->spec;
1281 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1283 mutex_lock(&spec->config_mutex);
1284 spec->cur_adc = spec->adc_nids[adc_idx];
1285 spec->cur_adc_stream_tag = stream_tag;
1286 spec->cur_adc_format = format;
1287 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1288 mutex_unlock(&spec->config_mutex);
1292 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1293 struct hda_codec *codec,
1294 struct snd_pcm_substream *substream)
1296 struct via_spec *spec = codec->spec;
1298 mutex_lock(&spec->config_mutex);
1299 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1301 mutex_unlock(&spec->config_mutex);
1305 /* re-setup the stream if running; called from input-src put */
1306 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1308 struct via_spec *spec = codec->spec;
1309 int adc_idx = spec->inputs[cur].adc_idx;
1310 hda_nid_t adc = spec->adc_nids[adc_idx];
1313 mutex_lock(&spec->config_mutex);
1314 if (spec->cur_adc && spec->cur_adc != adc) {
1315 /* stream is running, let's swap the current ADC */
1316 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1317 spec->cur_adc = adc;
1318 snd_hda_codec_setup_stream(codec, adc,
1319 spec->cur_adc_stream_tag, 0,
1320 spec->cur_adc_format);
1323 mutex_unlock(&spec->config_mutex);
1327 static const struct hda_pcm_stream via_pcm_analog_playback = {
1331 /* NID is set in via_build_pcms */
1333 .open = via_playback_multi_pcm_open,
1334 .close = via_playback_multi_pcm_close,
1335 .prepare = via_playback_multi_pcm_prepare,
1336 .cleanup = via_playback_multi_pcm_cleanup
1340 static const struct hda_pcm_stream via_pcm_hp_playback = {
1344 /* NID is set in via_build_pcms */
1346 .open = via_playback_hp_pcm_open,
1347 .close = via_playback_hp_pcm_close,
1348 .prepare = via_playback_hp_pcm_prepare,
1349 .cleanup = via_playback_hp_pcm_cleanup
1353 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1357 /* NID is set in via_build_pcms */
1358 /* We got noisy outputs on the right channel on VT1708 when
1359 * 24bit samples are used. Until any workaround is found,
1360 * disable the 24bit format, so far.
1362 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1364 .open = via_playback_multi_pcm_open,
1365 .close = via_playback_multi_pcm_close,
1366 .prepare = via_playback_multi_pcm_prepare,
1367 .cleanup = via_playback_multi_pcm_cleanup
1371 static const struct hda_pcm_stream via_pcm_analog_capture = {
1372 .substreams = 1, /* will be changed in via_build_pcms() */
1375 /* NID is set in via_build_pcms */
1377 .prepare = via_capture_pcm_prepare,
1378 .cleanup = via_capture_pcm_cleanup
1382 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1386 /* NID is set in via_build_pcms */
1388 .prepare = via_dyn_adc_capture_pcm_prepare,
1389 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1393 static const struct hda_pcm_stream via_pcm_digital_playback = {
1397 /* NID is set in via_build_pcms */
1399 .open = via_dig_playback_pcm_open,
1400 .close = via_dig_playback_pcm_close,
1401 .prepare = via_dig_playback_pcm_prepare,
1402 .cleanup = via_dig_playback_pcm_cleanup
1406 static const struct hda_pcm_stream via_pcm_digital_capture = {
1413 * slave controls for virtual master
1415 static const char * const via_slave_vols[] = {
1416 "Front Playback Volume",
1417 "Surround Playback Volume",
1418 "Center Playback Volume",
1419 "LFE Playback Volume",
1420 "Side Playback Volume",
1421 "Headphone Playback Volume",
1422 "Speaker Playback Volume",
1426 static const char * const via_slave_sws[] = {
1427 "Front Playback Switch",
1428 "Surround Playback Switch",
1429 "Center Playback Switch",
1430 "LFE Playback Switch",
1431 "Side Playback Switch",
1432 "Headphone Playback Switch",
1433 "Speaker Playback Switch",
1437 static int via_build_controls(struct hda_codec *codec)
1439 struct via_spec *spec = codec->spec;
1440 struct snd_kcontrol *kctl;
1443 if (spec->set_widgets_power_state)
1444 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1447 for (i = 0; i < spec->num_mixers; i++) {
1448 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1453 if (spec->multiout.dig_out_nid) {
1454 err = snd_hda_create_spdif_out_ctls(codec,
1455 spec->multiout.dig_out_nid,
1456 spec->multiout.dig_out_nid);
1459 err = snd_hda_create_spdif_share_sw(codec,
1463 spec->multiout.share_spdif = 1;
1465 if (spec->dig_in_nid) {
1466 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1471 /* if we have no master control, let's create it */
1472 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1473 unsigned int vmaster_tlv[4];
1474 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1475 HDA_OUTPUT, vmaster_tlv);
1476 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1477 vmaster_tlv, via_slave_vols);
1481 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1482 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1483 NULL, via_slave_sws);
1488 /* assign Capture Source enums to NID */
1489 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1490 for (i = 0; kctl && i < kctl->count; i++) {
1491 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1496 /* init power states */
1497 set_widgets_power_state(codec);
1498 analog_low_current_mode(codec);
1500 via_free_kctls(codec); /* no longer needed */
1504 static int via_build_pcms(struct hda_codec *codec)
1506 struct via_spec *spec = codec->spec;
1507 struct hda_pcm *info = spec->pcm_rec;
1509 codec->num_pcms = 0;
1510 codec->pcm_info = info;
1512 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1513 snprintf(spec->stream_name_analog,
1514 sizeof(spec->stream_name_analog),
1515 "%s Analog", codec->chip_name);
1516 info->name = spec->stream_name_analog;
1518 if (spec->multiout.num_dacs) {
1519 if (!spec->stream_analog_playback)
1520 spec->stream_analog_playback =
1521 &via_pcm_analog_playback;
1522 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1523 *spec->stream_analog_playback;
1524 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1525 spec->multiout.dac_nids[0];
1526 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1527 spec->multiout.max_channels;
1530 if (!spec->stream_analog_capture) {
1531 if (spec->dyn_adc_switch)
1532 spec->stream_analog_capture =
1533 &via_pcm_dyn_adc_analog_capture;
1535 spec->stream_analog_capture =
1536 &via_pcm_analog_capture;
1538 if (spec->num_adc_nids) {
1539 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1540 *spec->stream_analog_capture;
1541 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1543 if (!spec->dyn_adc_switch)
1544 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1551 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1552 snprintf(spec->stream_name_digital,
1553 sizeof(spec->stream_name_digital),
1554 "%s Digital", codec->chip_name);
1555 info->name = spec->stream_name_digital;
1556 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1557 if (spec->multiout.dig_out_nid) {
1558 if (!spec->stream_digital_playback)
1559 spec->stream_digital_playback =
1560 &via_pcm_digital_playback;
1561 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1562 *spec->stream_digital_playback;
1563 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1564 spec->multiout.dig_out_nid;
1566 if (spec->dig_in_nid) {
1567 if (!spec->stream_digital_capture)
1568 spec->stream_digital_capture =
1569 &via_pcm_digital_capture;
1570 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1571 *spec->stream_digital_capture;
1572 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1579 if (spec->hp_dac_nid) {
1580 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1581 "%s HP", codec->chip_name);
1582 info->name = spec->stream_name_hp;
1583 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1584 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1592 static void via_free(struct hda_codec *codec)
1594 struct via_spec *spec = codec->spec;
1599 via_free_kctls(codec);
1600 vt1708_stop_hp_work(spec);
1601 kfree(spec->bind_cap_vol);
1602 kfree(spec->bind_cap_sw);
1606 /* mute/unmute outputs */
1607 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1608 hda_nid_t *pins, bool mute)
1611 for (i = 0; i < num_pins; i++) {
1612 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1613 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1614 if (parm & AC_PINCTL_IN_EN)
1617 parm &= ~AC_PINCTL_OUT_EN;
1619 parm |= AC_PINCTL_OUT_EN;
1620 snd_hda_codec_write(codec, pins[i], 0,
1621 AC_VERB_SET_PIN_WIDGET_CONTROL, parm);
1625 /* mute internal speaker if line-out is plugged */
1626 static void via_line_automute(struct hda_codec *codec, int present)
1628 struct via_spec *spec = codec->spec;
1630 if (!spec->autocfg.speaker_outs)
1633 present = snd_hda_jack_detect(codec,
1634 spec->autocfg.line_out_pins[0]);
1635 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1636 spec->autocfg.speaker_pins,
1640 /* mute internal speaker if HP is plugged */
1641 static void via_hp_automute(struct hda_codec *codec)
1645 struct via_spec *spec = codec->spec;
1647 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0])
1648 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1650 if (spec->smart51_enabled)
1651 nums = spec->autocfg.line_outs + spec->smart51_nums;
1653 nums = spec->autocfg.line_outs;
1654 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1656 via_line_automute(codec, present);
1659 static void via_gpio_control(struct hda_codec *codec)
1661 unsigned int gpio_data;
1662 unsigned int vol_counter;
1664 unsigned int master_vol;
1666 struct via_spec *spec = codec->spec;
1668 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1669 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1671 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1672 0xF84, 0) & 0x3F0000) >> 16;
1674 vol = vol_counter & 0x1F;
1675 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1676 AC_VERB_GET_AMP_GAIN_MUTE,
1679 if (gpio_data == 0x02) {
1680 /* unmute line out */
1681 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1682 AC_VERB_SET_PIN_WIDGET_CONTROL,
1684 if (vol_counter & 0x20) {
1685 /* decrease volume */
1686 if (vol > master_vol)
1688 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1692 /* increase volume */
1693 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1695 ((master_vol+vol) > 0x2A) ? 0x2A :
1698 } else if (!(gpio_data & 0x02)) {
1700 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1701 AC_VERB_SET_PIN_WIDGET_CONTROL,
1706 /* unsolicited event for jack sensing */
1707 static void via_unsol_event(struct hda_codec *codec,
1712 if (res & VIA_JACK_EVENT)
1713 set_widgets_power_state(codec);
1715 res &= ~VIA_JACK_EVENT;
1717 if (res == VIA_HP_EVENT || res == VIA_LINE_EVENT)
1718 via_hp_automute(codec);
1719 else if (res == VIA_GPIO_EVENT)
1720 via_gpio_control(codec);
1724 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1726 struct via_spec *spec = codec->spec;
1727 vt1708_stop_hp_work(spec);
1732 #ifdef CONFIG_SND_HDA_POWER_SAVE
1733 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1735 struct via_spec *spec = codec->spec;
1736 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1743 static int via_init(struct hda_codec *codec);
1745 static const struct hda_codec_ops via_patch_ops = {
1746 .build_controls = via_build_controls,
1747 .build_pcms = via_build_pcms,
1750 .unsol_event = via_unsol_event,
1752 .suspend = via_suspend,
1754 #ifdef CONFIG_SND_HDA_POWER_SAVE
1755 .check_power_status = via_check_power_status,
1759 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1761 struct via_spec *spec = codec->spec;
1764 for (i = 0; i < spec->multiout.num_dacs; i++) {
1765 if (spec->multiout.dac_nids[i] == dac)
1768 if (spec->hp_dac_nid == dac)
1773 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1774 hda_nid_t target_dac, int with_aa_mix,
1775 struct nid_path *path, int depth)
1777 struct via_spec *spec = codec->spec;
1781 if (nid == spec->aa_mix_nid) {
1784 with_aa_mix = 2; /* mark aa-mix is included */
1787 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1788 for (i = 0; i < nums; i++) {
1789 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1791 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1792 /* aa-mix is requested but not included? */
1793 if (!(spec->aa_mix_nid && with_aa_mix == 1))
1797 if (depth >= MAX_NID_PATH_DEPTH)
1799 for (i = 0; i < nums; i++) {
1801 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1802 if (type == AC_WID_AUD_OUT)
1804 if (__parse_output_path(codec, conn[i], target_dac,
1805 with_aa_mix, path, depth + 1))
1811 path->path[path->depth] = conn[i];
1812 path->idx[path->depth] = i;
1813 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1814 path->multi[path->depth] = 1;
1819 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1820 hda_nid_t target_dac, int with_aa_mix,
1821 struct nid_path *path)
1823 if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
1824 path->path[path->depth] = nid;
1826 snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
1827 path->depth, path->path[0], path->path[1],
1828 path->path[2], path->path[3], path->path[4]);
1834 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1836 struct via_spec *spec = codec->spec;
1837 const struct auto_pin_cfg *cfg = &spec->autocfg;
1841 spec->multiout.dac_nids = spec->private_dac_nids;
1843 for (i = 0; i < cfg->line_outs; i++) {
1845 nid = cfg->line_out_pins[i];
1848 if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
1849 dac = spec->out_path[i].path[0];
1850 if (!i && parse_output_path(codec, nid, dac, 1,
1851 &spec->out_mix_path))
1852 dac = spec->out_mix_path.path[0];
1854 spec->private_dac_nids[i] = dac;
1858 if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
1859 spec->out_path[0] = spec->out_mix_path;
1860 spec->out_mix_path.depth = 0;
1862 spec->multiout.num_dacs = dac_num;
1866 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1867 int chs, bool check_dac, struct nid_path *path)
1869 struct via_spec *spec = codec->spec;
1871 hda_nid_t dac, pin, sel, nid;
1874 dac = check_dac ? path->path[0] : 0;
1875 pin = path->path[path->depth - 1];
1876 sel = path->depth > 1 ? path->path[1] : 0;
1878 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1880 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1882 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1887 sprintf(name, "%s Playback Volume", pfx);
1888 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1889 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1892 path->vol_ctl = nid;
1895 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1897 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1899 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1904 sprintf(name, "%s Playback Switch", pfx);
1905 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1906 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1909 path->mute_ctl = nid;
1914 static void mangle_smart51(struct hda_codec *codec)
1916 struct via_spec *spec = codec->spec;
1917 struct auto_pin_cfg *cfg = &spec->autocfg;
1918 struct auto_pin_cfg_item *ins = cfg->inputs;
1919 int i, j, nums, attr;
1920 int pins[AUTO_CFG_MAX_INS];
1922 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1924 for (i = 0; i < cfg->num_inputs; i++) {
1926 if (ins[i].type > AUTO_PIN_LINE_IN)
1928 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1929 if (snd_hda_get_input_pin_attr(def) != attr)
1931 for (j = 0; j < nums; j++)
1932 if (ins[pins[j]].type < ins[i].type) {
1933 memmove(pins + j + 1, pins + j,
1934 (nums - j) * sizeof(int));
1940 if (cfg->line_outs + nums < 3)
1942 for (i = 0; i < nums; i++) {
1943 hda_nid_t pin = ins[pins[i]].pin;
1944 spec->smart51_pins[spec->smart51_nums++] = pin;
1945 cfg->line_out_pins[cfg->line_outs++] = pin;
1946 if (cfg->line_outs == 3)
1953 static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
1955 dst->vol_ctl = src->vol_ctl;
1956 dst->mute_ctl = src->mute_ctl;
1959 /* add playback controls from the parsed DAC table */
1960 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1962 struct via_spec *spec = codec->spec;
1963 struct auto_pin_cfg *cfg = &spec->autocfg;
1964 struct nid_path *path;
1965 static const char * const chname[4] = {
1966 "Front", "Surround", "C/LFE", "Side"
1972 old_line_outs = cfg->line_outs;
1973 if (cfg->line_outs == 1)
1974 mangle_smart51(codec);
1976 err = via_auto_fill_dac_nids(codec);
1980 if (spec->multiout.num_dacs < 3) {
1981 spec->smart51_nums = 0;
1982 cfg->line_outs = old_line_outs;
1984 for (i = 0; i < cfg->line_outs; i++) {
1986 pin = cfg->line_out_pins[i];
1987 dac = spec->multiout.dac_nids[i];
1990 path = spec->out_path + i;
1991 if (i == HDA_CLFE) {
1992 err = create_ch_ctls(codec, "Center", 1, true, path);
1995 err = create_ch_ctls(codec, "LFE", 2, true, path);
1999 const char *pfx = chname[i];
2000 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
2001 cfg->line_outs == 1)
2003 err = create_ch_ctls(codec, pfx, 3, true, path);
2007 if (path != spec->out_path + i)
2008 copy_path_mixer_ctls(&spec->out_path[i], path);
2009 if (path == spec->out_path && spec->out_mix_path.depth)
2010 copy_path_mixer_ctls(&spec->out_mix_path, path);
2013 idx = get_connection_index(codec, spec->aa_mix_nid,
2014 spec->multiout.dac_nids[0]);
2016 /* add control to mixer */
2018 name = spec->out_mix_path.depth ?
2019 "PCM Loopback Playback Volume" : "PCM Playback Volume";
2020 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2021 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2025 name = spec->out_mix_path.depth ?
2026 "PCM Loopback Playback Switch" : "PCM Playback Switch";
2027 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2028 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
2034 cfg->line_outs = old_line_outs;
2039 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
2041 struct via_spec *spec = codec->spec;
2042 struct nid_path *path;
2049 if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
2050 for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
2051 if (i < spec->multiout.num_dacs &&
2052 parse_output_path(codec, pin,
2053 spec->multiout.dac_nids[i], 0,
2054 &spec->hp_indep_path)) {
2055 spec->hp_indep_shared = i;
2060 if (spec->hp_indep_path.depth) {
2061 spec->hp_dac_nid = spec->hp_indep_path.path[0];
2062 if (!spec->hp_indep_shared)
2063 spec->hp_path = spec->hp_indep_path;
2065 /* optionally check front-path w/o AA-mix */
2066 if (!spec->hp_path.depth)
2067 parse_output_path(codec, pin,
2068 spec->multiout.dac_nids[HDA_FRONT], 0,
2071 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2072 1, &spec->hp_mix_path) && !spec->hp_path.depth)
2075 if (spec->hp_path.depth) {
2076 path = &spec->hp_path;
2079 path = &spec->hp_mix_path;
2082 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
2086 copy_path_mixer_ctls(&spec->hp_mix_path, path);
2088 copy_path_mixer_ctls(&spec->hp_path, path);
2089 if (spec->hp_indep_path.depth)
2090 copy_path_mixer_ctls(&spec->hp_indep_path, path);
2094 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2096 struct via_spec *spec = codec->spec;
2097 struct nid_path *path;
2099 hda_nid_t pin, dac = 0;
2102 pin = spec->autocfg.speaker_pins[0];
2103 if (!spec->autocfg.speaker_outs || !pin)
2106 if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
2107 dac = spec->speaker_path.path[0];
2109 parse_output_path(codec, pin,
2110 spec->multiout.dac_nids[HDA_FRONT], 0,
2111 &spec->speaker_path);
2112 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
2113 1, &spec->speaker_mix_path) && !dac)
2116 /* no AA-path for front? */
2117 if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
2120 spec->speaker_dac_nid = dac;
2121 spec->multiout.extra_out_nid[0] = dac;
2123 path = &spec->speaker_path;
2126 path = &spec->speaker_mix_path;
2129 err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
2133 copy_path_mixer_ctls(&spec->speaker_mix_path, path);
2135 copy_path_mixer_ctls(&spec->speaker_path, path);
2139 #define via_aamix_ctl_info via_pin_power_ctl_info
2141 static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
2142 struct snd_ctl_elem_value *ucontrol)
2144 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2145 struct via_spec *spec = codec->spec;
2146 ucontrol->value.enumerated.item[0] = spec->aamix_mode;
2150 static void update_aamix_paths(struct hda_codec *codec, int do_mix,
2151 struct nid_path *nomix, struct nid_path *mix)
2154 activate_output_path(codec, nomix, false, false);
2155 activate_output_path(codec, mix, true, false);
2157 activate_output_path(codec, mix, false, false);
2158 activate_output_path(codec, nomix, true, false);
2162 static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
2163 struct snd_ctl_elem_value *ucontrol)
2165 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2166 struct via_spec *spec = codec->spec;
2167 unsigned int val = ucontrol->value.enumerated.item[0];
2169 if (val == spec->aamix_mode)
2171 spec->aamix_mode = val;
2172 /* update front path */
2173 update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
2174 /* update HP path */
2175 if (!spec->hp_independent_mode) {
2176 update_aamix_paths(codec, val, &spec->hp_path,
2177 &spec->hp_mix_path);
2179 /* update speaker path */
2180 update_aamix_paths(codec, val, &spec->speaker_path,
2181 &spec->speaker_mix_path);
2185 static const struct snd_kcontrol_new via_aamix_ctl_enum = {
2186 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2187 .name = "Loopback Mixing",
2188 .info = via_aamix_ctl_info,
2189 .get = via_aamix_ctl_get,
2190 .put = via_aamix_ctl_put,
2193 static int via_auto_create_loopback_switch(struct hda_codec *codec)
2195 struct via_spec *spec = codec->spec;
2197 if (!spec->aa_mix_nid || !spec->out_mix_path.depth)
2198 return 0; /* no loopback switching available */
2199 if (!via_clone_control(spec, &via_aamix_ctl_enum))
2205 static int via_fill_adcs(struct hda_codec *codec)
2207 struct via_spec *spec = codec->spec;
2208 hda_nid_t nid = codec->start_nid;
2211 for (i = 0; i < codec->num_nodes; i++, nid++) {
2212 unsigned int wcaps = get_wcaps(codec, nid);
2213 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2215 if (wcaps & AC_WCAP_DIGITAL)
2217 if (!(wcaps & AC_WCAP_CONN_LIST))
2219 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2221 spec->adc_nids[spec->num_adc_nids++] = nid;
2226 /* input-src control */
2227 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2228 struct snd_ctl_elem_info *uinfo)
2230 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2231 struct via_spec *spec = codec->spec;
2233 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2235 uinfo->value.enumerated.items = spec->num_inputs;
2236 if (uinfo->value.enumerated.item >= spec->num_inputs)
2237 uinfo->value.enumerated.item = spec->num_inputs - 1;
2238 strcpy(uinfo->value.enumerated.name,
2239 spec->inputs[uinfo->value.enumerated.item].label);
2243 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2244 struct snd_ctl_elem_value *ucontrol)
2246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2247 struct via_spec *spec = codec->spec;
2248 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2250 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2254 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2255 struct snd_ctl_elem_value *ucontrol)
2257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2258 struct via_spec *spec = codec->spec;
2259 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2263 cur = ucontrol->value.enumerated.item[0];
2264 if (cur < 0 || cur >= spec->num_inputs)
2266 if (spec->cur_mux[idx] == cur)
2268 spec->cur_mux[idx] = cur;
2269 if (spec->dyn_adc_switch) {
2270 int adc_idx = spec->inputs[cur].adc_idx;
2271 mux = spec->mux_nids[adc_idx];
2272 via_dyn_adc_pcm_resetup(codec, cur);
2274 mux = spec->mux_nids[idx];
2275 if (snd_BUG_ON(!mux))
2280 /* switch to D0 beofre change index */
2281 if (snd_hda_codec_read(codec, mux, 0,
2282 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
2283 snd_hda_codec_write(codec, mux, 0,
2284 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2285 snd_hda_codec_write(codec, mux, 0,
2286 AC_VERB_SET_CONNECT_SEL,
2287 spec->inputs[cur].mux_idx);
2290 /* update jack power state */
2291 set_widgets_power_state(codec);
2295 static const struct snd_kcontrol_new via_input_src_ctl = {
2296 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2297 /* The multiple "Capture Source" controls confuse alsamixer
2298 * So call somewhat different..
2300 /* .name = "Capture Source", */
2301 .name = "Input Source",
2302 .info = via_mux_enum_info,
2303 .get = via_mux_enum_get,
2304 .put = via_mux_enum_put,
2307 static int create_input_src_ctls(struct hda_codec *codec, int count)
2309 struct via_spec *spec = codec->spec;
2310 struct snd_kcontrol_new *knew;
2312 if (spec->num_inputs <= 1 || !count)
2313 return 0; /* no need for single src */
2315 knew = via_clone_control(spec, &via_input_src_ctl);
2318 knew->count = count;
2322 /* add the powersave loopback-list entry */
2323 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2325 struct hda_amp_list *list;
2327 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2329 list = spec->loopback_list + spec->num_loopbacks;
2331 list->dir = HDA_INPUT;
2333 spec->num_loopbacks++;
2334 spec->loopback.amplist = spec->loopback_list;
2337 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2340 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2343 /* add the input-route to the given pin */
2344 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2346 struct via_spec *spec = codec->spec;
2349 spec->inputs[spec->num_inputs].adc_idx = -1;
2350 spec->inputs[spec->num_inputs].pin = pin;
2351 for (c = 0; c < spec->num_adc_nids; c++) {
2352 if (spec->mux_nids[c]) {
2353 idx = get_connection_index(codec, spec->mux_nids[c],
2357 spec->inputs[spec->num_inputs].mux_idx = idx;
2359 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2362 spec->inputs[spec->num_inputs].adc_idx = c;
2363 /* Can primary ADC satisfy all inputs? */
2364 if (!spec->dyn_adc_switch &&
2365 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2366 snd_printd(KERN_INFO
2367 "via: dynamic ADC switching enabled\n");
2368 spec->dyn_adc_switch = 1;
2375 static int get_mux_nids(struct hda_codec *codec);
2377 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2378 static int parse_analog_inputs(struct hda_codec *codec)
2380 struct via_spec *spec = codec->spec;
2381 const struct auto_pin_cfg *cfg = &spec->autocfg;
2384 err = via_fill_adcs(codec);
2387 err = get_mux_nids(codec);
2391 /* fill all input-routes */
2392 for (i = 0; i < cfg->num_inputs; i++) {
2393 if (add_input_route(codec, cfg->inputs[i].pin))
2394 spec->inputs[spec->num_inputs++].label =
2395 hda_get_autocfg_input_label(codec, cfg, i);
2398 /* check for internal loopback recording */
2399 if (spec->aa_mix_nid &&
2400 add_input_route(codec, spec->aa_mix_nid))
2401 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2406 /* create analog-loopback volume/switch controls */
2407 static int create_loopback_ctls(struct hda_codec *codec)
2409 struct via_spec *spec = codec->spec;
2410 const struct auto_pin_cfg *cfg = &spec->autocfg;
2411 const char *prev_label = NULL;
2415 if (!spec->aa_mix_nid)
2418 for (i = 0; i < cfg->num_inputs; i++) {
2419 hda_nid_t pin = cfg->inputs[i].pin;
2420 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2422 if (prev_label && !strcmp(label, prev_label))
2427 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2429 err = via_new_analog_input(spec, label, type_idx,
2430 idx, spec->aa_mix_nid);
2433 add_loopback_list(spec, spec->aa_mix_nid, idx);
2436 /* remember the label for smart51 control */
2437 for (j = 0; j < spec->smart51_nums; j++) {
2438 if (spec->smart51_pins[j] == pin) {
2439 spec->smart51_idxs[j] = idx;
2440 spec->smart51_labels[j] = label;
2448 /* create mic-boost controls (if present) */
2449 static int create_mic_boost_ctls(struct hda_codec *codec)
2451 struct via_spec *spec = codec->spec;
2452 const struct auto_pin_cfg *cfg = &spec->autocfg;
2455 for (i = 0; i < cfg->num_inputs; i++) {
2456 hda_nid_t pin = cfg->inputs[i].pin;
2461 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2463 caps = query_amp_caps(codec, pin, HDA_INPUT);
2464 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2466 label = hda_get_autocfg_input_label(codec, cfg, i);
2467 snprintf(name, sizeof(name), "%s Boost Volume", label);
2468 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2469 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2476 /* create capture and input-src controls for multiple streams */
2477 static int create_multi_adc_ctls(struct hda_codec *codec)
2479 struct via_spec *spec = codec->spec;
2482 /* create capture mixer elements */
2483 for (i = 0; i < spec->num_adc_nids; i++) {
2484 hda_nid_t adc = spec->adc_nids[i];
2485 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2486 "Capture Volume", i,
2487 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2491 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2492 "Capture Switch", i,
2493 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2499 /* input-source control */
2500 for (i = 0; i < spec->num_adc_nids; i++)
2501 if (!spec->mux_nids[i])
2503 err = create_input_src_ctls(codec, i);
2509 /* bind capture volume/switch */
2510 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2511 HDA_BIND_VOL("Capture Volume", 0);
2512 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2513 HDA_BIND_SW("Capture Switch", 0);
2515 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2516 struct hda_ctl_ops *ops)
2518 struct hda_bind_ctls *ctl;
2521 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2525 for (i = 0; i < spec->num_adc_nids; i++)
2527 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2532 /* create capture and input-src controls for dynamic ADC-switch case */
2533 static int create_dyn_adc_ctls(struct hda_codec *codec)
2535 struct via_spec *spec = codec->spec;
2536 struct snd_kcontrol_new *knew;
2539 /* set up the bind capture ctls */
2540 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2543 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2547 /* create capture mixer elements */
2548 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2551 knew->private_value = (long)spec->bind_cap_vol;
2553 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2556 knew->private_value = (long)spec->bind_cap_sw;
2558 /* input-source control */
2559 err = create_input_src_ctls(codec, 1);
2565 /* parse and create capture-related stuff */
2566 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2568 struct via_spec *spec = codec->spec;
2571 err = parse_analog_inputs(codec);
2574 if (spec->dyn_adc_switch)
2575 err = create_dyn_adc_ctls(codec);
2577 err = create_multi_adc_ctls(codec);
2580 err = create_loopback_ctls(codec);
2583 err = create_mic_boost_ctls(codec);
2589 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2591 unsigned int def_conf;
2592 unsigned char seqassoc;
2594 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2595 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2596 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2597 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2598 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2599 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2600 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2606 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2607 struct snd_ctl_elem_value *ucontrol)
2609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2610 struct via_spec *spec = codec->spec;
2612 if (spec->codec_type != VT1708)
2614 spec->vt1708_jack_detect =
2615 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2616 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2620 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2621 struct snd_ctl_elem_value *ucontrol)
2623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2624 struct via_spec *spec = codec->spec;
2627 if (spec->codec_type != VT1708)
2629 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2630 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2631 == !spec->vt1708_jack_detect;
2632 if (spec->vt1708_jack_detect) {
2633 mute_aa_path(codec, 1);
2634 notify_aa_path_ctls(codec);
2639 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2640 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2641 .name = "Jack Detect",
2643 .info = snd_ctl_boolean_mono_info,
2644 .get = vt1708_jack_detect_get,
2645 .put = vt1708_jack_detect_put,
2648 static void fill_dig_outs(struct hda_codec *codec);
2649 static void fill_dig_in(struct hda_codec *codec);
2651 static int via_parse_auto_config(struct hda_codec *codec)
2653 struct via_spec *spec = codec->spec;
2656 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2659 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2662 err = via_auto_create_multi_out_ctls(codec);
2665 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2668 err = via_auto_create_speaker_ctls(codec);
2671 err = via_auto_create_loopback_switch(codec);
2674 err = via_auto_create_analog_input_ctls(codec);
2678 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2680 fill_dig_outs(codec);
2683 if (spec->kctls.list)
2684 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2687 if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
2688 err = via_hp_build(codec);
2693 err = via_smart51_build(codec);
2697 /* assign slave outs */
2698 if (spec->slave_dig_outs[0])
2699 codec->slave_dig_outs = spec->slave_dig_outs;
2704 static void via_auto_init_dig_outs(struct hda_codec *codec)
2706 struct via_spec *spec = codec->spec;
2707 if (spec->multiout.dig_out_nid)
2708 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2709 if (spec->slave_dig_outs[0])
2710 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2713 static void via_auto_init_dig_in(struct hda_codec *codec)
2715 struct via_spec *spec = codec->spec;
2716 if (!spec->dig_in_nid)
2718 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2719 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2722 /* initialize the unsolicited events */
2723 static void via_auto_init_unsol_event(struct hda_codec *codec)
2725 struct via_spec *spec = codec->spec;
2726 struct auto_pin_cfg *cfg = &spec->autocfg;
2730 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2731 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2732 AC_VERB_SET_UNSOLICITED_ENABLE,
2733 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2735 if (cfg->speaker_pins[0])
2736 ev = VIA_LINE_EVENT;
2739 for (i = 0; i < cfg->line_outs; i++) {
2740 if (cfg->line_out_pins[i] &&
2741 is_jack_detectable(codec, cfg->line_out_pins[i]))
2742 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
2743 AC_VERB_SET_UNSOLICITED_ENABLE,
2744 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2747 for (i = 0; i < cfg->num_inputs; i++) {
2748 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2749 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2750 AC_VERB_SET_UNSOLICITED_ENABLE,
2751 AC_USRSP_EN | VIA_JACK_EVENT);
2755 static int via_init(struct hda_codec *codec)
2757 struct via_spec *spec = codec->spec;
2760 for (i = 0; i < spec->num_iverbs; i++)
2761 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2763 via_auto_init_multi_out(codec);
2764 via_auto_init_hp_out(codec);
2765 via_auto_init_speaker_out(codec);
2766 via_auto_init_analog_input(codec);
2767 via_auto_init_dig_outs(codec);
2768 via_auto_init_dig_in(codec);
2770 via_auto_init_unsol_event(codec);
2772 via_hp_automute(codec);
2777 static void vt1708_update_hp_jack_state(struct work_struct *work)
2779 struct via_spec *spec = container_of(work, struct via_spec,
2780 vt1708_hp_work.work);
2781 if (spec->codec_type != VT1708)
2783 /* if jack state toggled */
2784 if (spec->vt1708_hp_present
2785 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2786 spec->vt1708_hp_present ^= 1;
2787 via_hp_automute(spec->codec);
2789 vt1708_start_hp_work(spec);
2792 static int get_mux_nids(struct hda_codec *codec)
2794 struct via_spec *spec = codec->spec;
2795 hda_nid_t nid, conn[8];
2799 for (i = 0; i < spec->num_adc_nids; i++) {
2800 nid = spec->adc_nids[i];
2802 type = get_wcaps_type(get_wcaps(codec, nid));
2803 if (type == AC_WID_PIN)
2805 n = snd_hda_get_connections(codec, nid, conn,
2810 spec->mux_nids[i] = nid;
2819 static int patch_vt1708(struct hda_codec *codec)
2821 struct via_spec *spec;
2824 /* create a codec specific record */
2825 spec = via_new_spec(codec);
2829 spec->aa_mix_nid = 0x17;
2831 /* Add HP and CD pin config connect bit re-config action */
2832 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2833 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2835 /* automatic parse from the BIOS config */
2836 err = via_parse_auto_config(codec);
2842 /* add jack detect on/off control */
2843 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2846 /* disable 32bit format on VT1708 */
2847 if (codec->vendor_id == 0x11061708)
2848 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2850 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2852 codec->patch_ops = via_patch_ops;
2854 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2858 static int patch_vt1709(struct hda_codec *codec)
2860 struct via_spec *spec;
2863 /* create a codec specific record */
2864 spec = via_new_spec(codec);
2868 spec->aa_mix_nid = 0x18;
2870 err = via_parse_auto_config(codec);
2876 codec->patch_ops = via_patch_ops;
2881 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2883 struct via_spec *spec = codec->spec;
2887 if ((spec->codec_type != VT1708B_4CH) &&
2888 (codec->vendor_id != 0x11064397))
2891 /* SW0 (17h) = stereo mixer */
2893 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2894 == ((spec->codec_type == VT1708S) ? 5 : 0));
2896 /* PW 1/2/5 (1ah/1bh/1eh) */
2898 set_pin_power_state(codec, 0x1a, &parm);
2899 set_pin_power_state(codec, 0x1b, &parm);
2900 set_pin_power_state(codec, 0x1e, &parm);
2903 /* SW0 (17h), AIW 0/1 (13h/14h) */
2904 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2905 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2906 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2909 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2911 set_pin_power_state(codec, 0x19, &parm);
2912 if (spec->smart51_enabled)
2913 set_pin_power_state(codec, 0x1b, &parm);
2914 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2915 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2917 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2920 set_pin_power_state(codec, 0x22, &parm);
2921 if (spec->smart51_enabled)
2922 set_pin_power_state(codec, 0x1a, &parm);
2923 snd_hda_codec_write(codec, 0x26, 0,
2924 AC_VERB_SET_POWER_STATE, parm);
2925 snd_hda_codec_write(codec, 0x24, 0,
2926 AC_VERB_SET_POWER_STATE, parm);
2927 } else if (codec->vendor_id == 0x11064397) {
2928 /* PW7(23h), SW2(27h), AOW2(25h) */
2930 set_pin_power_state(codec, 0x23, &parm);
2931 if (spec->smart51_enabled)
2932 set_pin_power_state(codec, 0x1a, &parm);
2933 snd_hda_codec_write(codec, 0x27, 0,
2934 AC_VERB_SET_POWER_STATE, parm);
2935 snd_hda_codec_write(codec, 0x25, 0,
2936 AC_VERB_SET_POWER_STATE, parm);
2939 /* PW 3/4/7 (1ch/1dh/23h) */
2941 /* force to D0 for internal Speaker */
2942 set_pin_power_state(codec, 0x1c, &parm);
2943 set_pin_power_state(codec, 0x1d, &parm);
2945 set_pin_power_state(codec, 0x23, &parm);
2947 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2948 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2949 imux_is_smixer ? AC_PWRST_D0 : parm);
2950 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2952 snd_hda_codec_write(codec, 0x25, 0,
2953 AC_VERB_SET_POWER_STATE, parm);
2954 snd_hda_codec_write(codec, 0x27, 0,
2955 AC_VERB_SET_POWER_STATE, parm);
2956 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2957 snd_hda_codec_write(codec, 0x25, 0,
2958 AC_VERB_SET_POWER_STATE, parm);
2961 static int patch_vt1708S(struct hda_codec *codec);
2962 static int patch_vt1708B(struct hda_codec *codec)
2964 struct via_spec *spec;
2967 if (get_codec_type(codec) == VT1708BCE)
2968 return patch_vt1708S(codec);
2970 /* create a codec specific record */
2971 spec = via_new_spec(codec);
2975 spec->aa_mix_nid = 0x16;
2977 /* automatic parse from the BIOS config */
2978 err = via_parse_auto_config(codec);
2984 codec->patch_ops = via_patch_ops;
2986 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2991 /* Patch for VT1708S */
2992 static const struct hda_verb vt1708S_init_verbs[] = {
2993 /* Enable Mic Boost Volume backdoor */
2995 /* don't bybass mixer */
3000 /* fill out digital output widgets; one for master and one for slave outputs */
3001 static void fill_dig_outs(struct hda_codec *codec)
3003 struct via_spec *spec = codec->spec;
3006 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3010 nid = spec->autocfg.dig_out_pins[i];
3013 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3016 if (!spec->multiout.dig_out_nid)
3017 spec->multiout.dig_out_nid = nid;
3019 spec->slave_dig_outs[0] = nid;
3020 break; /* at most two dig outs */
3025 static void fill_dig_in(struct hda_codec *codec)
3027 struct via_spec *spec = codec->spec;
3031 if (!spec->autocfg.dig_in_pin)
3034 dig_nid = codec->start_nid;
3035 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
3036 unsigned int wcaps = get_wcaps(codec, dig_nid);
3037 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
3039 if (!(wcaps & AC_WCAP_DIGITAL))
3041 if (!(wcaps & AC_WCAP_CONN_LIST))
3043 err = get_connection_index(codec, dig_nid,
3044 spec->autocfg.dig_in_pin);
3046 spec->dig_in_nid = dig_nid;
3052 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3053 int offset, int num_steps, int step_size)
3055 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3056 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3057 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3058 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3059 (0 << AC_AMPCAP_MUTE_SHIFT));
3062 static int patch_vt1708S(struct hda_codec *codec)
3064 struct via_spec *spec;
3067 /* create a codec specific record */
3068 spec = via_new_spec(codec);
3072 spec->aa_mix_nid = 0x16;
3073 override_mic_boost(codec, 0x1a, 0, 3, 40);
3074 override_mic_boost(codec, 0x1e, 0, 3, 40);
3076 /* automatic parse from the BIOS config */
3077 err = via_parse_auto_config(codec);
3083 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
3085 codec->patch_ops = via_patch_ops;
3087 /* correct names for VT1708BCE */
3088 if (get_codec_type(codec) == VT1708BCE) {
3089 kfree(codec->chip_name);
3090 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3091 snprintf(codec->bus->card->mixername,
3092 sizeof(codec->bus->card->mixername),
3093 "%s %s", codec->vendor_name, codec->chip_name);
3095 /* correct names for VT1705 */
3096 if (codec->vendor_id == 0x11064397) {
3097 kfree(codec->chip_name);
3098 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3099 snprintf(codec->bus->card->mixername,
3100 sizeof(codec->bus->card->mixername),
3101 "%s %s", codec->vendor_name, codec->chip_name);
3103 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3107 /* Patch for VT1702 */
3109 static const struct hda_verb vt1702_init_verbs[] = {
3117 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
3119 int imux_is_smixer =
3120 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3123 /* PW 1/2/5 (14h/15h/18h) */
3125 set_pin_power_state(codec, 0x14, &parm);
3126 set_pin_power_state(codec, 0x15, &parm);
3127 set_pin_power_state(codec, 0x18, &parm);
3129 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
3130 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
3131 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3132 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
3133 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3134 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
3137 /* PW 3/4 (16h/17h) */
3139 set_pin_power_state(codec, 0x17, &parm);
3140 set_pin_power_state(codec, 0x16, &parm);
3141 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
3142 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
3143 imux_is_smixer ? AC_PWRST_D0 : parm);
3144 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3145 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3148 static int patch_vt1702(struct hda_codec *codec)
3150 struct via_spec *spec;
3153 /* create a codec specific record */
3154 spec = via_new_spec(codec);
3158 spec->aa_mix_nid = 0x1a;
3160 /* limit AA path volume to 0 dB */
3161 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3162 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3163 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3164 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3165 (1 << AC_AMPCAP_MUTE_SHIFT));
3167 /* automatic parse from the BIOS config */
3168 err = via_parse_auto_config(codec);
3174 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
3176 codec->patch_ops = via_patch_ops;
3178 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
3182 /* Patch for VT1718S */
3184 static const struct hda_verb vt1718S_init_verbs[] = {
3185 /* Enable MW0 adjust Gain 5 */
3187 /* Enable Boost Volume backdoor */
3193 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
3195 struct via_spec *spec = codec->spec;
3198 /* MUX6 (1eh) = stereo mixer */
3200 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3202 /* PW 5/6/7 (29h/2ah/2bh) */
3204 set_pin_power_state(codec, 0x29, &parm);
3205 set_pin_power_state(codec, 0x2a, &parm);
3206 set_pin_power_state(codec, 0x2b, &parm);
3209 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
3210 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3211 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3212 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3213 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3216 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
3218 set_pin_power_state(codec, 0x27, &parm);
3219 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
3220 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
3222 /* PW2 (26h), AOW2 (ah) */
3224 set_pin_power_state(codec, 0x26, &parm);
3225 if (spec->smart51_enabled)
3226 set_pin_power_state(codec, 0x2b, &parm);
3227 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
3229 /* PW0 (24h), AOW0 (8h) */
3231 set_pin_power_state(codec, 0x24, &parm);
3232 if (!spec->hp_independent_mode) /* check for redirected HP */
3233 set_pin_power_state(codec, 0x28, &parm);
3234 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3235 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3236 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3237 imux_is_smixer ? AC_PWRST_D0 : parm);
3239 /* PW1 (25h), AOW1 (9h) */
3241 set_pin_power_state(codec, 0x25, &parm);
3242 if (spec->smart51_enabled)
3243 set_pin_power_state(codec, 0x2a, &parm);
3244 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3246 if (spec->hp_independent_mode) {
3247 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3249 set_pin_power_state(codec, 0x28, &parm);
3250 snd_hda_codec_write(codec, 0x1b, 0,
3251 AC_VERB_SET_POWER_STATE, parm);
3252 snd_hda_codec_write(codec, 0x34, 0,
3253 AC_VERB_SET_POWER_STATE, parm);
3254 snd_hda_codec_write(codec, 0xc, 0,
3255 AC_VERB_SET_POWER_STATE, parm);
3259 /* Add a connection to the primary DAC from AA-mixer for some codecs
3260 * This isn't listed from the raw info, but the chip has a secret connection.
3262 static int add_secret_dac_path(struct hda_codec *codec)
3264 struct via_spec *spec = codec->spec;
3269 if (!spec->aa_mix_nid)
3271 nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
3272 ARRAY_SIZE(conn) - 1);
3273 for (i = 0; i < nums; i++) {
3274 if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
3278 /* find the primary DAC and add to the connection list */
3279 nid = codec->start_nid;
3280 for (i = 0; i < codec->num_nodes; i++, nid++) {
3281 unsigned int caps = get_wcaps(codec, nid);
3282 if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
3283 !(caps & AC_WCAP_DIGITAL)) {
3285 return snd_hda_override_conn_list(codec,
3294 static int patch_vt1718S(struct hda_codec *codec)
3296 struct via_spec *spec;
3299 /* create a codec specific record */
3300 spec = via_new_spec(codec);
3304 spec->aa_mix_nid = 0x21;
3305 override_mic_boost(codec, 0x2b, 0, 3, 40);
3306 override_mic_boost(codec, 0x29, 0, 3, 40);
3307 add_secret_dac_path(codec);
3309 /* automatic parse from the BIOS config */
3310 err = via_parse_auto_config(codec);
3316 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3318 codec->patch_ops = via_patch_ops;
3320 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3325 /* Patch for VT1716S */
3327 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3328 struct snd_ctl_elem_info *uinfo)
3330 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3332 uinfo->value.integer.min = 0;
3333 uinfo->value.integer.max = 1;
3337 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3338 struct snd_ctl_elem_value *ucontrol)
3340 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3343 index = snd_hda_codec_read(codec, 0x26, 0,
3344 AC_VERB_GET_CONNECT_SEL, 0);
3346 *ucontrol->value.integer.value = index;
3351 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3352 struct snd_ctl_elem_value *ucontrol)
3354 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3355 struct via_spec *spec = codec->spec;
3356 int index = *ucontrol->value.integer.value;
3358 snd_hda_codec_write(codec, 0x26, 0,
3359 AC_VERB_SET_CONNECT_SEL, index);
3360 spec->dmic_enabled = index;
3361 set_widgets_power_state(codec);
3365 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3366 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3368 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3369 .name = "Digital Mic Capture Switch",
3370 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3372 .info = vt1716s_dmic_info,
3373 .get = vt1716s_dmic_get,
3374 .put = vt1716s_dmic_put,
3380 /* mono-out mixer elements */
3381 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3382 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3386 static const struct hda_verb vt1716S_init_verbs[] = {
3387 /* Enable Boost Volume backdoor */
3389 /* don't bybass mixer */
3391 /* Enable mono output */
3396 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3398 struct via_spec *spec = codec->spec;
3401 unsigned int mono_out, present;
3402 /* SW0 (17h) = stereo mixer */
3404 (snd_hda_codec_read(codec, 0x17, 0,
3405 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3407 /* PW 1/2/5 (1ah/1bh/1eh) */
3409 set_pin_power_state(codec, 0x1a, &parm);
3410 set_pin_power_state(codec, 0x1b, &parm);
3411 set_pin_power_state(codec, 0x1e, &parm);
3414 /* SW0 (17h), AIW0(13h) */
3415 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3416 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3419 set_pin_power_state(codec, 0x1e, &parm);
3421 if (spec->dmic_enabled)
3422 set_pin_power_state(codec, 0x22, &parm);
3424 snd_hda_codec_write(codec, 0x22, 0,
3425 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3427 /* SW2(26h), AIW1(14h) */
3428 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3429 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3432 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3434 set_pin_power_state(codec, 0x19, &parm);
3435 /* Smart 5.1 PW2(1bh) */
3436 if (spec->smart51_enabled)
3437 set_pin_power_state(codec, 0x1b, &parm);
3438 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3439 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3441 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3443 set_pin_power_state(codec, 0x23, &parm);
3444 /* Smart 5.1 PW1(1ah) */
3445 if (spec->smart51_enabled)
3446 set_pin_power_state(codec, 0x1a, &parm);
3447 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3449 /* Smart 5.1 PW5(1eh) */
3450 if (spec->smart51_enabled)
3451 set_pin_power_state(codec, 0x1e, &parm);
3452 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3455 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3456 present = snd_hda_jack_detect(codec, 0x1c);
3461 present = snd_hda_jack_detect(codec, 0x1d);
3462 if (!spec->hp_independent_mode && present)
3467 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3468 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3469 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3470 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3472 /* PW 3/4 (1ch/1dh) */
3474 set_pin_power_state(codec, 0x1c, &parm);
3475 set_pin_power_state(codec, 0x1d, &parm);
3476 /* HP Independent Mode, power on AOW3 */
3477 if (spec->hp_independent_mode)
3478 snd_hda_codec_write(codec, 0x25, 0,
3479 AC_VERB_SET_POWER_STATE, parm);
3481 /* force to D0 for internal Speaker */
3482 /* MW0 (16h), AOW0 (10h) */
3483 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3484 imux_is_smixer ? AC_PWRST_D0 : parm);
3485 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3486 mono_out ? AC_PWRST_D0 : parm);
3489 static int patch_vt1716S(struct hda_codec *codec)
3491 struct via_spec *spec;
3494 /* create a codec specific record */
3495 spec = via_new_spec(codec);
3499 spec->aa_mix_nid = 0x16;
3500 override_mic_boost(codec, 0x1a, 0, 3, 40);
3501 override_mic_boost(codec, 0x1e, 0, 3, 40);
3503 /* automatic parse from the BIOS config */
3504 err = via_parse_auto_config(codec);
3510 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3512 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3515 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3517 codec->patch_ops = via_patch_ops;
3519 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3525 static const struct hda_verb vt2002P_init_verbs[] = {
3526 /* Class-D speaker related verbs */
3530 /* Enable Boost Volume backdoor */
3532 /* Enable AOW0 to MW9 */
3537 static const struct hda_verb vt1802_init_verbs[] = {
3538 /* Enable Boost Volume backdoor */
3540 /* Enable AOW0 to MW9 */
3545 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3547 struct via_spec *spec = codec->spec;
3550 unsigned int present;
3551 /* MUX9 (1eh) = stereo mixer */
3553 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3555 /* PW 5/6/7 (29h/2ah/2bh) */
3557 set_pin_power_state(codec, 0x29, &parm);
3558 set_pin_power_state(codec, 0x2a, &parm);
3559 set_pin_power_state(codec, 0x2b, &parm);
3561 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3562 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3563 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3564 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3565 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3569 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3571 if (spec->codec_type == VT1802) {
3572 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3574 set_pin_power_state(codec, 0x28, &parm);
3575 snd_hda_codec_write(codec, 0x18, 0,
3576 AC_VERB_SET_POWER_STATE, parm);
3577 snd_hda_codec_write(codec, 0x38, 0,
3578 AC_VERB_SET_POWER_STATE, parm);
3580 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3582 set_pin_power_state(codec, 0x26, &parm);
3583 snd_hda_codec_write(codec, 0x1c, 0,
3584 AC_VERB_SET_POWER_STATE, parm);
3585 snd_hda_codec_write(codec, 0x37, 0,
3586 AC_VERB_SET_POWER_STATE, parm);
3589 if (spec->codec_type == VT1802) {
3590 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3592 set_pin_power_state(codec, 0x25, &parm);
3593 snd_hda_codec_write(codec, 0x15, 0,
3594 AC_VERB_SET_POWER_STATE, parm);
3595 snd_hda_codec_write(codec, 0x35, 0,
3596 AC_VERB_SET_POWER_STATE, parm);
3598 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3600 set_pin_power_state(codec, 0x25, &parm);
3601 snd_hda_codec_write(codec, 0x19, 0,
3602 AC_VERB_SET_POWER_STATE, parm);
3603 snd_hda_codec_write(codec, 0x35, 0,
3604 AC_VERB_SET_POWER_STATE, parm);
3607 if (spec->hp_independent_mode)
3608 snd_hda_codec_write(codec, 0x9, 0,
3609 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3612 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3613 present = snd_hda_jack_detect(codec, 0x25);
3616 set_pin_power_state(codec, 0x24, &parm);
3617 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3618 if (spec->codec_type == VT1802)
3619 snd_hda_codec_write(codec, 0x14, 0,
3620 AC_VERB_SET_POWER_STATE, parm);
3622 snd_hda_codec_write(codec, 0x18, 0,
3623 AC_VERB_SET_POWER_STATE, parm);
3624 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3627 present = snd_hda_jack_detect(codec, 0x26);
3629 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3630 if (spec->codec_type == VT1802) {
3631 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3632 snd_hda_codec_write(codec, 0x33, 0,
3633 AC_VERB_SET_POWER_STATE, parm);
3634 snd_hda_codec_write(codec, 0x1c, 0,
3635 AC_VERB_SET_POWER_STATE, parm);
3636 snd_hda_codec_write(codec, 0x3c, 0,
3637 AC_VERB_SET_POWER_STATE, parm);
3639 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3640 snd_hda_codec_write(codec, 0x31, 0,
3641 AC_VERB_SET_POWER_STATE, parm);
3642 snd_hda_codec_write(codec, 0x17, 0,
3643 AC_VERB_SET_POWER_STATE, parm);
3644 snd_hda_codec_write(codec, 0x3b, 0,
3645 AC_VERB_SET_POWER_STATE, parm);
3648 if (imux_is_smixer || !is_aa_path_mute(codec))
3649 snd_hda_codec_write(codec, 0x21, 0,
3650 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3652 snd_hda_codec_write(codec, 0x21, 0,
3653 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3656 /* patch for vt2002P */
3657 static int patch_vt2002P(struct hda_codec *codec)
3659 struct via_spec *spec;
3662 /* create a codec specific record */
3663 spec = via_new_spec(codec);
3667 spec->aa_mix_nid = 0x21;
3668 override_mic_boost(codec, 0x2b, 0, 3, 40);
3669 override_mic_boost(codec, 0x29, 0, 3, 40);
3670 add_secret_dac_path(codec);
3672 /* automatic parse from the BIOS config */
3673 err = via_parse_auto_config(codec);
3679 if (spec->codec_type == VT1802)
3680 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3682 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3684 codec->patch_ops = via_patch_ops;
3686 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3692 static const struct hda_verb vt1812_init_verbs[] = {
3693 /* Enable Boost Volume backdoor */
3695 /* Enable AOW0 to MW9 */
3700 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3702 struct via_spec *spec = codec->spec;
3704 unsigned int present;
3706 /* PW 5/6/7 (29h/2ah/2bh) */
3708 set_pin_power_state(codec, 0x29, &parm);
3709 set_pin_power_state(codec, 0x2a, &parm);
3710 set_pin_power_state(codec, 0x2b, &parm);
3712 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3713 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3714 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3715 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3716 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3720 snd_hda_codec_write(codec, 0x8, 0,
3721 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3723 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3725 set_pin_power_state(codec, 0x28, &parm);
3726 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3727 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3729 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3731 set_pin_power_state(codec, 0x25, &parm);
3732 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3733 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3734 if (spec->hp_independent_mode)
3735 snd_hda_codec_write(codec, 0x9, 0,
3736 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3738 /* Internal Speaker */
3739 /* PW0 (24h), MW0(14h), MUX0(34h) */
3740 present = snd_hda_jack_detect(codec, 0x25);
3743 set_pin_power_state(codec, 0x24, &parm);
3745 snd_hda_codec_write(codec, 0x14, 0,
3746 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3747 snd_hda_codec_write(codec, 0x34, 0,
3748 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3750 snd_hda_codec_write(codec, 0x14, 0,
3751 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3752 snd_hda_codec_write(codec, 0x34, 0,
3753 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3758 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3759 present = snd_hda_jack_detect(codec, 0x28);
3762 set_pin_power_state(codec, 0x31, &parm);
3764 snd_hda_codec_write(codec, 0x1c, 0,
3765 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3766 snd_hda_codec_write(codec, 0x3c, 0,
3767 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3768 snd_hda_codec_write(codec, 0x3e, 0,
3769 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3771 snd_hda_codec_write(codec, 0x1c, 0,
3772 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3773 snd_hda_codec_write(codec, 0x3c, 0,
3774 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3775 snd_hda_codec_write(codec, 0x3e, 0,
3776 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3779 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3781 set_pin_power_state(codec, 0x33, &parm);
3782 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3783 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3787 /* patch for vt1812 */
3788 static int patch_vt1812(struct hda_codec *codec)
3790 struct via_spec *spec;
3793 /* create a codec specific record */
3794 spec = via_new_spec(codec);
3798 spec->aa_mix_nid = 0x21;
3799 override_mic_boost(codec, 0x2b, 0, 3, 40);
3800 override_mic_boost(codec, 0x29, 0, 3, 40);
3801 add_secret_dac_path(codec);
3803 /* automatic parse from the BIOS config */
3804 err = via_parse_auto_config(codec);
3810 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3812 codec->patch_ops = via_patch_ops;
3814 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3821 static const struct hda_codec_preset snd_hda_preset_via[] = {
3822 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3823 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3824 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3825 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3826 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3827 .patch = patch_vt1709},
3828 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3829 .patch = patch_vt1709},
3830 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3831 .patch = patch_vt1709},
3832 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3833 .patch = patch_vt1709},
3834 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3835 .patch = patch_vt1709},
3836 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3837 .patch = patch_vt1709},
3838 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3839 .patch = patch_vt1709},
3840 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3841 .patch = patch_vt1709},
3842 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3843 .patch = patch_vt1708B},
3844 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3845 .patch = patch_vt1708B},
3846 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3847 .patch = patch_vt1708B},
3848 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3849 .patch = patch_vt1708B},
3850 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3851 .patch = patch_vt1708B},
3852 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3853 .patch = patch_vt1708B},
3854 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3855 .patch = patch_vt1708B},
3856 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3857 .patch = patch_vt1708B},
3858 { .id = 0x11060397, .name = "VT1708S",
3859 .patch = patch_vt1708S},
3860 { .id = 0x11061397, .name = "VT1708S",
3861 .patch = patch_vt1708S},
3862 { .id = 0x11062397, .name = "VT1708S",
3863 .patch = patch_vt1708S},
3864 { .id = 0x11063397, .name = "VT1708S",
3865 .patch = patch_vt1708S},
3866 { .id = 0x11064397, .name = "VT1705",
3867 .patch = patch_vt1708S},
3868 { .id = 0x11065397, .name = "VT1708S",
3869 .patch = patch_vt1708S},
3870 { .id = 0x11066397, .name = "VT1708S",
3871 .patch = patch_vt1708S},
3872 { .id = 0x11067397, .name = "VT1708S",
3873 .patch = patch_vt1708S},
3874 { .id = 0x11060398, .name = "VT1702",
3875 .patch = patch_vt1702},
3876 { .id = 0x11061398, .name = "VT1702",
3877 .patch = patch_vt1702},
3878 { .id = 0x11062398, .name = "VT1702",
3879 .patch = patch_vt1702},
3880 { .id = 0x11063398, .name = "VT1702",
3881 .patch = patch_vt1702},
3882 { .id = 0x11064398, .name = "VT1702",
3883 .patch = patch_vt1702},
3884 { .id = 0x11065398, .name = "VT1702",
3885 .patch = patch_vt1702},
3886 { .id = 0x11066398, .name = "VT1702",
3887 .patch = patch_vt1702},
3888 { .id = 0x11067398, .name = "VT1702",
3889 .patch = patch_vt1702},
3890 { .id = 0x11060428, .name = "VT1718S",
3891 .patch = patch_vt1718S},
3892 { .id = 0x11064428, .name = "VT1718S",
3893 .patch = patch_vt1718S},
3894 { .id = 0x11060441, .name = "VT2020",
3895 .patch = patch_vt1718S},
3896 { .id = 0x11064441, .name = "VT1828S",
3897 .patch = patch_vt1718S},
3898 { .id = 0x11060433, .name = "VT1716S",
3899 .patch = patch_vt1716S},
3900 { .id = 0x1106a721, .name = "VT1716S",
3901 .patch = patch_vt1716S},
3902 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3903 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3904 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3905 { .id = 0x11060440, .name = "VT1818S",
3906 .patch = patch_vt1708S},
3907 { .id = 0x11060446, .name = "VT1802",
3908 .patch = patch_vt2002P},
3909 { .id = 0x11068446, .name = "VT1802",
3910 .patch = patch_vt2002P},
3914 MODULE_ALIAS("snd-hda-codec-id:1106*");
3916 static struct hda_codec_preset_list via_list = {
3917 .preset = snd_hda_preset_via,
3918 .owner = THIS_MODULE,
3921 MODULE_LICENSE("GPL");
3922 MODULE_DESCRIPTION("VIA HD-audio codec");
3924 static int __init patch_via_init(void)
3926 return snd_hda_add_codec_preset(&via_list);
3929 static void __exit patch_via_exit(void)
3931 snd_hda_delete_codec_preset(&via_list);
3934 module_init(patch_via_init)
3935 module_exit(patch_via_exit)