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 /* codec parameterization */
114 const struct snd_kcontrol_new *mixers[6];
115 unsigned int num_mixers;
117 const struct hda_verb *init_verbs[5];
118 unsigned int num_iverbs;
120 char stream_name_analog[32];
121 char stream_name_hp[32];
122 const struct hda_pcm_stream *stream_analog_playback;
123 const struct hda_pcm_stream *stream_analog_capture;
125 char stream_name_digital[32];
126 const struct hda_pcm_stream *stream_digital_playback;
127 const struct hda_pcm_stream *stream_digital_capture;
130 struct hda_multi_out multiout;
131 hda_nid_t slave_dig_outs[2];
132 hda_nid_t hp_dac_nid;
133 bool hp_indep_shared; /* indep HP-DAC is shared with side ch */
134 int num_active_streams;
137 struct nid_path out_path[HDA_SIDE + 1];
138 struct nid_path hp_path;
139 struct nid_path hp_dep_path;
140 struct nid_path speaker_path;
143 unsigned int num_adc_nids;
144 hda_nid_t adc_nids[VIA_MAX_ADCS];
145 hda_nid_t mux_nids[VIA_MAX_ADCS];
146 hda_nid_t aa_mix_nid;
147 hda_nid_t dig_in_nid;
152 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
153 unsigned int cur_mux[VIA_MAX_ADCS];
155 /* dynamic ADC switching */
157 unsigned int cur_adc_stream_tag;
158 unsigned int cur_adc_format;
160 /* PCM information */
161 struct hda_pcm pcm_rec[3];
163 /* dynamic controls, init_verbs and input_mux */
164 struct auto_pin_cfg autocfg;
165 struct snd_array kctls;
166 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
169 unsigned int hp_independent_mode;
170 unsigned int dmic_enabled;
171 unsigned int no_pin_power_ctl;
172 enum VIA_HDA_CODEC codec_type;
175 unsigned int smart51_nums;
176 hda_nid_t smart51_pins[2];
178 const char *smart51_labels[2];
179 unsigned int smart51_enabled;
181 /* work to check hp jack state */
182 struct hda_codec *codec;
183 struct delayed_work vt1708_hp_work;
184 int vt1708_jack_detect;
185 int vt1708_hp_present;
187 void (*set_widgets_power_state)(struct hda_codec *codec);
189 struct hda_loopback_check loopback;
191 struct hda_amp_list loopback_list[8];
193 /* bind capture-volume */
194 struct hda_bind_ctls *bind_cap_vol;
195 struct hda_bind_ctls *bind_cap_sw;
198 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
199 static struct via_spec * via_new_spec(struct hda_codec *codec)
201 struct via_spec *spec;
203 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
209 spec->codec_type = get_codec_type(codec);
210 /* VT1708BCE & VT1708S are almost same */
211 if (spec->codec_type == VT1708BCE)
212 spec->codec_type = VT1708S;
216 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
218 u32 vendor_id = codec->vendor_id;
219 u16 ven_id = vendor_id >> 16;
220 u16 dev_id = vendor_id & 0xffff;
221 enum VIA_HDA_CODEC codec_type;
224 if (ven_id != 0x1106)
225 codec_type = UNKNOWN;
226 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
228 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
229 codec_type = VT1709_10CH;
230 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
231 codec_type = VT1709_6CH;
232 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
233 codec_type = VT1708B_8CH;
234 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
235 codec_type = VT1708BCE;
236 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
237 codec_type = VT1708B_4CH;
238 else if ((dev_id & 0xfff) == 0x397
239 && (dev_id >> 12) < 8)
240 codec_type = VT1708S;
241 else if ((dev_id & 0xfff) == 0x398
242 && (dev_id >> 12) < 8)
244 else if ((dev_id & 0xfff) == 0x428
245 && (dev_id >> 12) < 8)
246 codec_type = VT1718S;
247 else if (dev_id == 0x0433 || dev_id == 0xa721)
248 codec_type = VT1716S;
249 else if (dev_id == 0x0441 || dev_id == 0x4441)
250 codec_type = VT1718S;
251 else if (dev_id == 0x0438 || dev_id == 0x4438)
252 codec_type = VT2002P;
253 else if (dev_id == 0x0448)
255 else if (dev_id == 0x0440)
256 codec_type = VT1708S;
257 else if ((dev_id & 0xfff) == 0x446)
260 codec_type = UNKNOWN;
264 #define VIA_JACK_EVENT 0x20
265 #define VIA_HP_EVENT 0x01
266 #define VIA_GPIO_EVENT 0x02
267 #define VIA_LINE_EVENT 0x03
272 VIA_CTL_WIDGET_ANALOG_MUTE,
275 static void analog_low_current_mode(struct hda_codec *codec);
276 static bool is_aa_path_mute(struct hda_codec *codec);
278 static void vt1708_start_hp_work(struct via_spec *spec)
280 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
282 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
283 !spec->vt1708_jack_detect);
284 if (!delayed_work_pending(&spec->vt1708_hp_work))
285 schedule_delayed_work(&spec->vt1708_hp_work,
286 msecs_to_jiffies(100));
289 static void vt1708_stop_hp_work(struct via_spec *spec)
291 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
293 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
294 && !is_aa_path_mute(spec->codec))
296 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
297 !spec->vt1708_jack_detect);
298 cancel_delayed_work_sync(&spec->vt1708_hp_work);
301 static void set_widgets_power_state(struct hda_codec *codec)
303 struct via_spec *spec = codec->spec;
304 if (spec->set_widgets_power_state)
305 spec->set_widgets_power_state(codec);
308 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
309 struct snd_ctl_elem_value *ucontrol)
311 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
312 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
314 set_widgets_power_state(codec);
315 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
316 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
317 if (is_aa_path_mute(codec))
318 vt1708_start_hp_work(codec->spec);
320 vt1708_stop_hp_work(codec->spec);
325 /* modify .put = snd_hda_mixer_amp_switch_put */
326 #define ANALOG_INPUT_MUTE \
327 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
330 .info = snd_hda_mixer_amp_switch_info, \
331 .get = snd_hda_mixer_amp_switch_get, \
332 .put = analog_input_switch_put, \
333 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
335 static const struct snd_kcontrol_new via_control_templates[] = {
336 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
337 HDA_CODEC_MUTE(NULL, 0, 0, 0),
342 /* add dynamic controls */
343 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
344 const struct snd_kcontrol_new *tmpl,
347 struct snd_kcontrol_new *knew;
349 snd_array_init(&spec->kctls, sizeof(*knew), 32);
350 knew = snd_array_new(&spec->kctls);
357 knew->name = kstrdup(name, GFP_KERNEL);
364 static int __via_add_control(struct via_spec *spec, int type, const char *name,
365 int idx, unsigned long val)
367 struct snd_kcontrol_new *knew;
369 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
373 if (get_amp_nid_(val))
374 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
375 knew->private_value = val;
379 #define via_add_control(spec, type, name, val) \
380 __via_add_control(spec, type, name, 0, val)
382 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
384 static void via_free_kctls(struct hda_codec *codec)
386 struct via_spec *spec = codec->spec;
388 if (spec->kctls.list) {
389 struct snd_kcontrol_new *kctl = spec->kctls.list;
391 for (i = 0; i < spec->kctls.used; i++)
394 snd_array_free(&spec->kctls);
397 /* create input playback/capture controls for the given pin */
398 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
399 int type_idx, int idx, int mix_nid)
404 sprintf(name, "%s Playback Volume", ctlname);
405 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
406 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
409 sprintf(name, "%s Playback Switch", ctlname);
410 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
411 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
417 #define get_connection_index(codec, mux, nid) \
418 snd_hda_get_conn_index(codec, mux, nid, 0)
420 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
426 caps = get_wcaps(codec, nid);
427 if (dir == HDA_INPUT)
428 caps &= AC_WCAP_IN_AMP;
430 caps &= AC_WCAP_OUT_AMP;
433 if (query_amp_caps(codec, nid, dir) & mask)
438 #define have_mute(codec, nid, dir) \
439 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
441 static bool is_node_in_path(struct nid_path *path, hda_nid_t nid)
446 for (i = 0; i < path->depth; i++) {
447 if (path->path[i] == nid)
453 /* enable/disable the output-route mixers */
454 static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
455 hda_nid_t mix_nid, int aa_mix_idx, bool enable)
458 bool hp_path, front_path;
459 struct via_spec *spec = codec->spec;
463 num = snd_hda_get_conn_list(codec, mix_nid, NULL);
464 hp_path = is_node_in_path(path, spec->hp_dac_nid);
465 front_path = is_node_in_path(path, spec->multiout.dac_nids[0]);
467 for (i = 0; i < num; i++) {
468 if (i == aa_mix_idx) {
470 val = enable ? AMP_IN_MUTE(i) :
473 val = AMP_IN_UNMUTE(i);
475 val = AMP_IN_MUTE(i);
478 val = enable ? AMP_IN_UNMUTE(i) :
481 val = AMP_IN_MUTE(i);
483 val = AMP_IN_UNMUTE(i);
485 snd_hda_codec_write(codec, mix_nid, 0,
486 AC_VERB_SET_AMP_GAIN_MUTE, val);
490 /* enable/disable the output-route */
491 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
492 bool enable, bool force)
495 struct via_spec *spec = codec->spec;
496 hda_nid_t aa_mix_nid = spec->aa_mix_nid;
497 for (i = 0; i < path->depth; i++) {
499 int idx = path->idx[i];
501 if (i < path->depth - 1)
502 dst = path->path[i + 1];
505 if (enable && path->multi[i])
506 snd_hda_codec_write(codec, dst, 0,
507 AC_VERB_SET_CONNECT_SEL, idx);
509 && get_wcaps_type(get_wcaps(codec, src)) == AC_WID_AUD_OUT
510 && get_wcaps_type(get_wcaps(codec, dst)) == AC_WID_AUD_MIX)
512 if (have_mute(codec, dst, HDA_INPUT)) {
513 if (dst == aa_mix_nid) {
514 val = enable ? AMP_IN_UNMUTE(idx) :
516 snd_hda_codec_write(codec, dst, 0,
517 AC_VERB_SET_AMP_GAIN_MUTE, val);
519 idx = get_connection_index(codec, dst,
522 activate_output_mix(codec, path,
527 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
529 if (have_mute(codec, src, HDA_OUTPUT)) {
530 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
531 snd_hda_codec_write(codec, src, 0,
532 AC_VERB_SET_AMP_GAIN_MUTE, val);
537 /* set the given pin as output */
538 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
543 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
545 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
546 snd_hda_codec_write(codec, pin, 0,
547 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
550 static void via_auto_init_output(struct hda_codec *codec,
551 struct nid_path *path, int pin_type,
552 bool with_aa_mix, bool force)
554 struct via_spec *spec = codec->spec;
560 pin = path->path[path->depth - 1];
562 init_output_pin(codec, pin, pin_type);
563 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
564 if (caps & AC_AMPCAP_MUTE) {
566 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
567 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
571 /* initialize the AA-path */
572 if (!spec->aa_mix_nid)
574 activate_output_path(codec, path, true, force);
577 static void via_auto_init_multi_out(struct hda_codec *codec)
579 struct via_spec *spec = codec->spec;
582 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++)
583 /* enable aa-mute only for the front channel */
584 via_auto_init_output(codec, &spec->out_path[i], PIN_OUT,
588 static void via_auto_init_hp_out(struct hda_codec *codec)
590 struct via_spec *spec = codec->spec;
592 if (!spec->hp_dac_nid) {
593 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP,
597 if (spec->hp_independent_mode) {
598 activate_output_path(codec, &spec->hp_dep_path, false, false);
599 via_auto_init_output(codec, &spec->hp_path, PIN_HP,
602 activate_output_path(codec, &spec->hp_path, false, false);
603 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP,
608 static void via_auto_init_speaker_out(struct hda_codec *codec)
610 struct via_spec *spec = codec->spec;
612 if (spec->autocfg.speaker_outs)
613 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT,
617 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
618 static void via_hp_automute(struct hda_codec *codec);
620 static void via_auto_init_analog_input(struct hda_codec *codec)
622 struct via_spec *spec = codec->spec;
623 const struct auto_pin_cfg *cfg = &spec->autocfg;
624 hda_nid_t conn[HDA_MAX_CONNECTIONS];
629 for (i = 0; i < spec->num_adc_nids; i++) {
630 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
631 AC_VERB_SET_AMP_GAIN_MUTE,
636 for (i = 0; i < cfg->num_inputs; i++) {
637 hda_nid_t nid = cfg->inputs[i].pin;
638 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
640 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
644 snd_hda_codec_write(codec, nid, 0,
645 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
649 for (i = 0; i < spec->num_adc_nids; i++) {
650 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
651 if (spec->mux_nids[adc_idx]) {
652 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
653 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
654 AC_VERB_SET_CONNECT_SEL,
657 if (spec->dyn_adc_switch)
658 break; /* only one input-src */
662 if (!spec->aa_mix_nid)
664 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
666 for (i = 0; i < num_conns; i++) {
667 unsigned int caps = get_wcaps(codec, conn[i]);
668 if (get_wcaps_type(caps) == AC_WID_PIN)
669 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
670 AC_VERB_SET_AMP_GAIN_MUTE,
675 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
676 unsigned int *affected_parm)
679 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
680 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
681 >> AC_DEFCFG_MISC_SHIFT
682 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
683 struct via_spec *spec = codec->spec;
684 unsigned present = 0;
686 no_presence |= spec->no_pin_power_ctl;
688 present = snd_hda_jack_detect(codec, nid);
689 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
690 || ((no_presence || present)
691 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
692 *affected_parm = AC_PWRST_D0; /* if it's connected */
697 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
700 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
701 struct snd_ctl_elem_info *uinfo)
703 static const char * const texts[] = {
704 "Disabled", "Enabled"
707 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
709 uinfo->value.enumerated.items = 2;
710 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
711 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
712 strcpy(uinfo->value.enumerated.name,
713 texts[uinfo->value.enumerated.item]);
717 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
718 struct snd_ctl_elem_value *ucontrol)
720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
721 struct via_spec *spec = codec->spec;
722 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
726 static int via_pin_power_ctl_put(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 unsigned int val = !ucontrol->value.enumerated.item[0];
733 if (val == spec->no_pin_power_ctl)
735 spec->no_pin_power_ctl = val;
736 set_widgets_power_state(codec);
740 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
742 .name = "Dynamic Power-Control",
743 .info = via_pin_power_ctl_info,
744 .get = via_pin_power_ctl_get,
745 .put = via_pin_power_ctl_put,
749 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
750 struct snd_ctl_elem_info *uinfo)
752 static const char * const texts[] = { "OFF", "ON" };
754 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
756 uinfo->value.enumerated.items = 2;
757 if (uinfo->value.enumerated.item >= 2)
758 uinfo->value.enumerated.item = 1;
759 strcpy(uinfo->value.enumerated.name,
760 texts[uinfo->value.enumerated.item]);
764 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
765 struct snd_ctl_elem_value *ucontrol)
767 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
768 struct via_spec *spec = codec->spec;
770 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
774 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
775 struct snd_ctl_elem_value *ucontrol)
777 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
778 struct via_spec *spec = codec->spec;
781 /* no independent-hp status change during PCM playback is running */
782 if (spec->num_active_streams)
785 cur = !!ucontrol->value.enumerated.item[0];
786 if (spec->hp_independent_mode == cur)
788 spec->hp_independent_mode = cur;
790 activate_output_path(codec, &spec->hp_dep_path, false, false);
791 activate_output_path(codec, &spec->hp_path, true, false);
792 if (spec->hp_indep_shared)
793 activate_output_path(codec, &spec->out_path[HDA_SIDE],
796 activate_output_path(codec, &spec->hp_path, false, false);
797 activate_output_path(codec, &spec->hp_dep_path, true, false);
798 if (spec->hp_indep_shared)
799 activate_output_path(codec, &spec->out_path[HDA_SIDE],
803 /* update jack power state */
804 set_widgets_power_state(codec);
805 via_hp_automute(codec);
809 static const struct snd_kcontrol_new via_hp_mixer = {
810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
811 .name = "Independent HP",
812 .info = via_independent_hp_info,
813 .get = via_independent_hp_get,
814 .put = via_independent_hp_put,
817 static int via_hp_build(struct hda_codec *codec)
819 struct via_spec *spec = codec->spec;
820 struct snd_kcontrol_new *knew;
823 nid = spec->autocfg.hp_pins[0];
824 knew = via_clone_control(spec, &via_hp_mixer);
828 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
833 static void notify_aa_path_ctls(struct hda_codec *codec)
835 struct via_spec *spec = codec->spec;
838 for (i = 0; i < spec->smart51_nums; i++) {
839 struct snd_kcontrol *ctl;
840 struct snd_ctl_elem_id id;
841 memset(&id, 0, sizeof(id));
842 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
843 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
844 ctl = snd_hda_find_mixer_ctl(codec, id.name);
846 snd_ctl_notify(codec->bus->card,
847 SNDRV_CTL_EVENT_MASK_VALUE,
852 static void mute_aa_path(struct hda_codec *codec, int mute)
854 struct via_spec *spec = codec->spec;
855 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
858 /* check AA path's mute status */
859 for (i = 0; i < spec->smart51_nums; i++) {
860 if (spec->smart51_idxs[i] < 0)
862 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
863 HDA_INPUT, spec->smart51_idxs[i],
868 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
870 struct via_spec *spec = codec->spec;
873 for (i = 0; i < spec->smart51_nums; i++)
874 if (spec->smart51_pins[i] == pin)
879 static int via_smart51_get(struct snd_kcontrol *kcontrol,
880 struct snd_ctl_elem_value *ucontrol)
882 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
883 struct via_spec *spec = codec->spec;
885 *ucontrol->value.integer.value = spec->smart51_enabled;
889 static int via_smart51_put(struct snd_kcontrol *kcontrol,
890 struct snd_ctl_elem_value *ucontrol)
892 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
893 struct via_spec *spec = codec->spec;
894 int out_in = *ucontrol->value.integer.value
895 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
898 for (i = 0; i < spec->smart51_nums; i++) {
899 hda_nid_t nid = spec->smart51_pins[i];
902 parm = snd_hda_codec_read(codec, nid, 0,
903 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
904 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
906 snd_hda_codec_write(codec, nid, 0,
907 AC_VERB_SET_PIN_WIDGET_CONTROL,
909 if (out_in == AC_PINCTL_OUT_EN) {
910 mute_aa_path(codec, 1);
911 notify_aa_path_ctls(codec);
914 spec->smart51_enabled = *ucontrol->value.integer.value;
915 set_widgets_power_state(codec);
919 static const struct snd_kcontrol_new via_smart51_mixer = {
920 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
923 .info = snd_ctl_boolean_mono_info,
924 .get = via_smart51_get,
925 .put = via_smart51_put,
928 static int via_smart51_build(struct hda_codec *codec)
930 struct via_spec *spec = codec->spec;
932 if (!spec->smart51_nums)
934 if (!via_clone_control(spec, &via_smart51_mixer))
939 /* check AA path's mute status */
940 static bool is_aa_path_mute(struct hda_codec *codec)
942 struct via_spec *spec = codec->spec;
943 const struct hda_amp_list *p;
946 for (i = 0; i < spec->num_loopbacks; i++) {
947 p = &spec->loopback_list[i];
948 for (ch = 0; ch < 2; ch++) {
949 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
951 if (!(v & HDA_AMP_MUTE) && v > 0)
958 /* enter/exit analog low-current mode */
959 static void analog_low_current_mode(struct hda_codec *codec)
961 struct via_spec *spec = codec->spec;
963 unsigned int verb, parm;
965 enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0);
967 /* decide low current mode's verb & parameter */
968 switch (spec->codec_type) {
972 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
978 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
982 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
988 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
991 return; /* other codecs are not supported */
994 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
998 * generic initialization of ADC, input mixers and output mixers
1000 static const struct hda_verb vt1708_init_verbs[] = {
1001 /* power down jack detect function */
1006 static void set_stream_active(struct hda_codec *codec, bool active)
1008 struct via_spec *spec = codec->spec;
1011 spec->num_active_streams++;
1013 spec->num_active_streams--;
1014 analog_low_current_mode(codec);
1017 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1018 struct hda_codec *codec,
1019 struct snd_pcm_substream *substream)
1021 struct via_spec *spec = codec->spec;
1022 const struct auto_pin_cfg *cfg = &spec->autocfg;
1025 spec->multiout.hp_nid = 0;
1026 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1027 if (!spec->hp_independent_mode) {
1028 if (!spec->hp_indep_shared)
1029 spec->multiout.hp_nid = spec->hp_dac_nid;
1031 if (spec->hp_indep_shared)
1032 spec->multiout.num_dacs = cfg->line_outs - 1;
1034 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1035 set_stream_active(codec, true);
1036 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1039 spec->multiout.hp_nid = 0;
1040 set_stream_active(codec, false);
1046 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1047 struct hda_codec *codec,
1048 struct snd_pcm_substream *substream)
1050 struct via_spec *spec = codec->spec;
1052 spec->multiout.hp_nid = 0;
1053 set_stream_active(codec, false);
1057 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1058 struct hda_codec *codec,
1059 struct snd_pcm_substream *substream)
1061 struct via_spec *spec = codec->spec;
1063 if (snd_BUG_ON(!spec->hp_dac_nid))
1065 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1067 set_stream_active(codec, true);
1071 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1072 struct hda_codec *codec,
1073 struct snd_pcm_substream *substream)
1075 set_stream_active(codec, false);
1079 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1080 struct hda_codec *codec,
1081 unsigned int stream_tag,
1082 unsigned int format,
1083 struct snd_pcm_substream *substream)
1085 struct via_spec *spec = codec->spec;
1087 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1089 vt1708_start_hp_work(spec);
1093 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1094 struct hda_codec *codec,
1095 unsigned int stream_tag,
1096 unsigned int format,
1097 struct snd_pcm_substream *substream)
1099 struct via_spec *spec = codec->spec;
1101 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1102 stream_tag, 0, format);
1103 vt1708_start_hp_work(spec);
1107 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1108 struct hda_codec *codec,
1109 struct snd_pcm_substream *substream)
1111 struct via_spec *spec = codec->spec;
1113 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1114 vt1708_stop_hp_work(spec);
1118 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1119 struct hda_codec *codec,
1120 struct snd_pcm_substream *substream)
1122 struct via_spec *spec = codec->spec;
1124 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1125 vt1708_stop_hp_work(spec);
1132 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1133 struct hda_codec *codec,
1134 struct snd_pcm_substream *substream)
1136 struct via_spec *spec = codec->spec;
1137 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1140 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1141 struct hda_codec *codec,
1142 struct snd_pcm_substream *substream)
1144 struct via_spec *spec = codec->spec;
1145 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1148 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1149 struct hda_codec *codec,
1150 unsigned int stream_tag,
1151 unsigned int format,
1152 struct snd_pcm_substream *substream)
1154 struct via_spec *spec = codec->spec;
1155 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1156 stream_tag, format, substream);
1159 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1160 struct hda_codec *codec,
1161 struct snd_pcm_substream *substream)
1163 struct via_spec *spec = codec->spec;
1164 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1171 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1172 struct hda_codec *codec,
1173 unsigned int stream_tag,
1174 unsigned int format,
1175 struct snd_pcm_substream *substream)
1177 struct via_spec *spec = codec->spec;
1179 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1180 stream_tag, 0, format);
1184 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1185 struct hda_codec *codec,
1186 struct snd_pcm_substream *substream)
1188 struct via_spec *spec = codec->spec;
1189 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1193 /* analog capture with dynamic ADC switching */
1194 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1195 struct hda_codec *codec,
1196 unsigned int stream_tag,
1197 unsigned int format,
1198 struct snd_pcm_substream *substream)
1200 struct via_spec *spec = codec->spec;
1201 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1203 spec->cur_adc = spec->adc_nids[adc_idx];
1204 spec->cur_adc_stream_tag = stream_tag;
1205 spec->cur_adc_format = format;
1206 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1210 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1211 struct hda_codec *codec,
1212 struct snd_pcm_substream *substream)
1214 struct via_spec *spec = codec->spec;
1216 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1221 /* re-setup the stream if running; called from input-src put */
1222 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1224 struct via_spec *spec = codec->spec;
1225 int adc_idx = spec->inputs[cur].adc_idx;
1226 hda_nid_t adc = spec->adc_nids[adc_idx];
1228 if (spec->cur_adc && spec->cur_adc != adc) {
1229 /* stream is running, let's swap the current ADC */
1230 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1231 spec->cur_adc = adc;
1232 snd_hda_codec_setup_stream(codec, adc,
1233 spec->cur_adc_stream_tag, 0,
1234 spec->cur_adc_format);
1240 static const struct hda_pcm_stream via_pcm_analog_playback = {
1244 /* NID is set in via_build_pcms */
1246 .open = via_playback_multi_pcm_open,
1247 .close = via_playback_multi_pcm_close,
1248 .prepare = via_playback_multi_pcm_prepare,
1249 .cleanup = via_playback_multi_pcm_cleanup
1253 static const struct hda_pcm_stream via_pcm_hp_playback = {
1257 /* NID is set in via_build_pcms */
1259 .open = via_playback_hp_pcm_open,
1260 .close = via_playback_hp_pcm_close,
1261 .prepare = via_playback_hp_pcm_prepare,
1262 .cleanup = via_playback_hp_pcm_cleanup
1266 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1270 /* NID is set in via_build_pcms */
1271 /* We got noisy outputs on the right channel on VT1708 when
1272 * 24bit samples are used. Until any workaround is found,
1273 * disable the 24bit format, so far.
1275 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1277 .open = via_playback_multi_pcm_open,
1278 .close = via_playback_multi_pcm_close,
1279 .prepare = via_playback_multi_pcm_prepare,
1280 .cleanup = via_playback_multi_pcm_cleanup
1284 static const struct hda_pcm_stream via_pcm_analog_capture = {
1285 .substreams = 1, /* will be changed in via_build_pcms() */
1288 /* NID is set in via_build_pcms */
1290 .prepare = via_capture_pcm_prepare,
1291 .cleanup = via_capture_pcm_cleanup
1295 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1299 /* NID is set in via_build_pcms */
1301 .prepare = via_dyn_adc_capture_pcm_prepare,
1302 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1306 static const struct hda_pcm_stream via_pcm_digital_playback = {
1310 /* NID is set in via_build_pcms */
1312 .open = via_dig_playback_pcm_open,
1313 .close = via_dig_playback_pcm_close,
1314 .prepare = via_dig_playback_pcm_prepare,
1315 .cleanup = via_dig_playback_pcm_cleanup
1319 static const struct hda_pcm_stream via_pcm_digital_capture = {
1326 * slave controls for virtual master
1328 static const char * const via_slave_vols[] = {
1329 "Front Playback Volume",
1330 "Surround Playback Volume",
1331 "Center Playback Volume",
1332 "LFE Playback Volume",
1333 "Side Playback Volume",
1334 "Headphone Playback Volume",
1335 "Speaker Playback Volume",
1339 static const char * const via_slave_sws[] = {
1340 "Front Playback Switch",
1341 "Surround Playback Switch",
1342 "Center Playback Switch",
1343 "LFE Playback Switch",
1344 "Side Playback Switch",
1345 "Headphone Playback Switch",
1346 "Speaker Playback Switch",
1350 static int via_build_controls(struct hda_codec *codec)
1352 struct via_spec *spec = codec->spec;
1353 struct snd_kcontrol *kctl;
1356 if (spec->set_widgets_power_state)
1357 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1360 for (i = 0; i < spec->num_mixers; i++) {
1361 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1366 if (spec->multiout.dig_out_nid) {
1367 err = snd_hda_create_spdif_out_ctls(codec,
1368 spec->multiout.dig_out_nid,
1369 spec->multiout.dig_out_nid);
1372 err = snd_hda_create_spdif_share_sw(codec,
1376 spec->multiout.share_spdif = 1;
1378 if (spec->dig_in_nid) {
1379 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1384 /* if we have no master control, let's create it */
1385 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1386 unsigned int vmaster_tlv[4];
1387 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1388 HDA_OUTPUT, vmaster_tlv);
1389 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1390 vmaster_tlv, via_slave_vols);
1394 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1395 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1396 NULL, via_slave_sws);
1401 /* assign Capture Source enums to NID */
1402 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1403 for (i = 0; kctl && i < kctl->count; i++) {
1404 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1409 /* init power states */
1410 set_widgets_power_state(codec);
1411 analog_low_current_mode(codec);
1413 via_free_kctls(codec); /* no longer needed */
1417 static int via_build_pcms(struct hda_codec *codec)
1419 struct via_spec *spec = codec->spec;
1420 struct hda_pcm *info = spec->pcm_rec;
1422 codec->num_pcms = 1;
1423 codec->pcm_info = info;
1425 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1426 "%s Analog", codec->chip_name);
1427 info->name = spec->stream_name_analog;
1429 if (!spec->stream_analog_playback)
1430 spec->stream_analog_playback = &via_pcm_analog_playback;
1431 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1432 *spec->stream_analog_playback;
1433 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1434 spec->multiout.dac_nids[0];
1435 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1436 spec->multiout.max_channels;
1438 if (!spec->stream_analog_capture) {
1439 if (spec->dyn_adc_switch)
1440 spec->stream_analog_capture =
1441 &via_pcm_dyn_adc_analog_capture;
1443 spec->stream_analog_capture = &via_pcm_analog_capture;
1445 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1446 *spec->stream_analog_capture;
1447 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1448 if (!spec->dyn_adc_switch)
1449 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1452 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1455 snprintf(spec->stream_name_digital,
1456 sizeof(spec->stream_name_digital),
1457 "%s Digital", codec->chip_name);
1458 info->name = spec->stream_name_digital;
1459 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1460 if (spec->multiout.dig_out_nid) {
1461 if (!spec->stream_digital_playback)
1462 spec->stream_digital_playback =
1463 &via_pcm_digital_playback;
1464 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1465 *spec->stream_digital_playback;
1466 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1467 spec->multiout.dig_out_nid;
1469 if (spec->dig_in_nid) {
1470 if (!spec->stream_digital_capture)
1471 spec->stream_digital_capture =
1472 &via_pcm_digital_capture;
1473 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1474 *spec->stream_digital_capture;
1475 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1480 if (spec->hp_dac_nid) {
1483 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1484 "%s HP", codec->chip_name);
1485 info->name = spec->stream_name_hp;
1486 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1487 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1493 static void via_free(struct hda_codec *codec)
1495 struct via_spec *spec = codec->spec;
1500 via_free_kctls(codec);
1501 vt1708_stop_hp_work(spec);
1502 kfree(spec->bind_cap_vol);
1503 kfree(spec->bind_cap_sw);
1507 /* mute/unmute outputs */
1508 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1509 hda_nid_t *pins, bool mute)
1512 for (i = 0; i < num_pins; i++) {
1513 unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
1514 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1515 if (parm & AC_PINCTL_IN_EN)
1518 parm &= ~AC_PINCTL_OUT_EN;
1520 parm |= AC_PINCTL_OUT_EN;
1521 snd_hda_codec_write(codec, pins[i], 0,
1522 AC_VERB_SET_PIN_WIDGET_CONTROL, parm);
1526 /* mute internal speaker if line-out is plugged */
1527 static void via_line_automute(struct hda_codec *codec, int present)
1529 struct via_spec *spec = codec->spec;
1531 if (!spec->autocfg.speaker_outs)
1534 present = snd_hda_jack_detect(codec,
1535 spec->autocfg.line_out_pins[0]);
1536 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1537 spec->autocfg.speaker_pins,
1541 /* mute internal speaker if HP is plugged */
1542 static void via_hp_automute(struct hda_codec *codec)
1546 struct via_spec *spec = codec->spec;
1548 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0])
1549 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1551 if (spec->smart51_enabled)
1552 nums = spec->autocfg.line_outs + spec->smart51_nums;
1554 nums = spec->autocfg.line_outs;
1555 toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
1557 via_line_automute(codec, present);
1560 static void via_gpio_control(struct hda_codec *codec)
1562 unsigned int gpio_data;
1563 unsigned int vol_counter;
1565 unsigned int master_vol;
1567 struct via_spec *spec = codec->spec;
1569 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1570 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1572 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1573 0xF84, 0) & 0x3F0000) >> 16;
1575 vol = vol_counter & 0x1F;
1576 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1577 AC_VERB_GET_AMP_GAIN_MUTE,
1580 if (gpio_data == 0x02) {
1581 /* unmute line out */
1582 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1583 AC_VERB_SET_PIN_WIDGET_CONTROL,
1585 if (vol_counter & 0x20) {
1586 /* decrease volume */
1587 if (vol > master_vol)
1589 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1593 /* increase volume */
1594 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1596 ((master_vol+vol) > 0x2A) ? 0x2A :
1599 } else if (!(gpio_data & 0x02)) {
1601 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1602 AC_VERB_SET_PIN_WIDGET_CONTROL,
1607 /* unsolicited event for jack sensing */
1608 static void via_unsol_event(struct hda_codec *codec,
1613 if (res & VIA_JACK_EVENT)
1614 set_widgets_power_state(codec);
1616 res &= ~VIA_JACK_EVENT;
1618 if (res == VIA_HP_EVENT || res == VIA_LINE_EVENT)
1619 via_hp_automute(codec);
1620 else if (res == VIA_GPIO_EVENT)
1621 via_gpio_control(codec);
1624 #ifdef SND_HDA_NEEDS_RESUME
1625 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1627 struct via_spec *spec = codec->spec;
1628 vt1708_stop_hp_work(spec);
1633 #ifdef CONFIG_SND_HDA_POWER_SAVE
1634 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1636 struct via_spec *spec = codec->spec;
1637 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1644 static int via_init(struct hda_codec *codec);
1646 static const struct hda_codec_ops via_patch_ops = {
1647 .build_controls = via_build_controls,
1648 .build_pcms = via_build_pcms,
1651 .unsol_event = via_unsol_event,
1652 #ifdef SND_HDA_NEEDS_RESUME
1653 .suspend = via_suspend,
1655 #ifdef CONFIG_SND_HDA_POWER_SAVE
1656 .check_power_status = via_check_power_status,
1660 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1662 struct via_spec *spec = codec->spec;
1665 for (i = 0; i < spec->multiout.num_dacs; i++) {
1666 if (spec->multiout.dac_nids[i] == dac)
1669 if (spec->hp_dac_nid == dac)
1674 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1675 hda_nid_t target_dac, struct nid_path *path,
1676 int depth, int wid_type)
1681 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1682 for (i = 0; i < nums; i++) {
1683 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1685 if (conn[i] == target_dac || is_empty_dac(codec, conn[i]))
1688 if (depth >= MAX_NID_PATH_DEPTH)
1690 for (i = 0; i < nums; i++) {
1692 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1693 if (type == AC_WID_AUD_OUT ||
1694 (wid_type != -1 && type != wid_type))
1696 if (__parse_output_path(codec, conn[i], target_dac,
1697 path, depth + 1, AC_WID_AUD_SEL))
1703 path->path[path->depth] = conn[i];
1704 path->idx[path->depth] = i;
1705 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1706 path->multi[path->depth] = 1;
1711 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1712 hda_nid_t target_dac, struct nid_path *path)
1714 if (__parse_output_path(codec, nid, target_dac, path, 1, -1)) {
1715 path->path[path->depth] = nid;
1722 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1724 struct via_spec *spec = codec->spec;
1725 const struct auto_pin_cfg *cfg = &spec->autocfg;
1729 spec->multiout.dac_nids = spec->private_dac_nids;
1731 for (i = 0; i < cfg->line_outs; i++) {
1732 nid = cfg->line_out_pins[i];
1735 if (parse_output_path(codec, nid, 0, &spec->out_path[i])) {
1736 spec->private_dac_nids[i] = spec->out_path[i].path[0];
1740 spec->multiout.num_dacs = dac_num;
1744 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1745 int chs, bool check_dac, struct nid_path *path)
1747 struct via_spec *spec = codec->spec;
1749 hda_nid_t dac, pin, sel, nid;
1752 dac = check_dac ? path->path[0] : 0;
1753 pin = path->path[path->depth - 1];
1754 sel = path->depth > 1 ? path->path[1] : 0;
1756 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1758 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1760 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1765 sprintf(name, "%s Playback Volume", pfx);
1766 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1767 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1770 path->vol_ctl = nid;
1773 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1775 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1777 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1782 sprintf(name, "%s Playback Switch", pfx);
1783 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1784 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1787 path->mute_ctl = nid;
1792 static void mangle_smart51(struct hda_codec *codec)
1794 struct via_spec *spec = codec->spec;
1795 struct auto_pin_cfg *cfg = &spec->autocfg;
1796 struct auto_pin_cfg_item *ins = cfg->inputs;
1797 int i, j, nums, attr;
1798 int pins[AUTO_CFG_MAX_INS];
1800 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1802 for (i = 0; i < cfg->num_inputs; i++) {
1804 if (ins[i].type > AUTO_PIN_LINE_IN)
1806 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1807 if (snd_hda_get_input_pin_attr(def) != attr)
1809 for (j = 0; j < nums; j++)
1810 if (ins[pins[j]].type < ins[i].type) {
1811 memmove(pins + j + 1, pins + j,
1812 (nums - j) * sizeof(int));
1818 if (cfg->line_outs + nums < 3)
1820 for (i = 0; i < nums; i++) {
1821 hda_nid_t pin = ins[pins[i]].pin;
1822 spec->smart51_pins[spec->smart51_nums++] = pin;
1823 cfg->line_out_pins[cfg->line_outs++] = pin;
1824 if (cfg->line_outs == 3)
1831 /* add playback controls from the parsed DAC table */
1832 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1834 struct via_spec *spec = codec->spec;
1835 struct auto_pin_cfg *cfg = &spec->autocfg;
1836 static const char * const chname[4] = {
1837 "Front", "Surround", "C/LFE", "Side"
1843 old_line_outs = cfg->line_outs;
1844 if (cfg->line_outs == 1)
1845 mangle_smart51(codec);
1847 err = via_auto_fill_dac_nids(codec);
1851 if (spec->multiout.num_dacs < 3) {
1852 spec->smart51_nums = 0;
1853 cfg->line_outs = old_line_outs;
1855 for (i = 0; i < cfg->line_outs; i++) {
1857 pin = cfg->line_out_pins[i];
1858 dac = spec->multiout.dac_nids[i];
1861 if (i == HDA_CLFE) {
1862 err = create_ch_ctls(codec, "Center", 1, true,
1863 &spec->out_path[i]);
1866 err = create_ch_ctls(codec, "LFE", 2, true,
1867 &spec->out_path[i]);
1871 const char *pfx = chname[i];
1872 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1873 cfg->line_outs == 1)
1875 err = create_ch_ctls(codec, pfx, 3, true,
1876 &spec->out_path[i]);
1882 idx = get_connection_index(codec, spec->aa_mix_nid,
1883 spec->multiout.dac_nids[0]);
1884 if (idx < 0 && spec->dac_mixer_idx)
1885 idx = spec->dac_mixer_idx;
1887 /* add control to mixer */
1888 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1889 "PCM Playback Volume",
1890 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1894 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1895 "PCM Playback Switch",
1896 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1902 cfg->line_outs = old_line_outs;
1907 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1909 struct via_spec *spec = codec->spec;
1910 struct nid_path *path;
1917 if (parse_output_path(codec, pin, 0, &spec->hp_path))
1918 spec->hp_dac_nid = spec->hp_path.path[0];
1919 else if (spec->multiout.dac_nids[HDA_SIDE] &&
1920 parse_output_path(codec, pin,
1921 spec->multiout.dac_nids[HDA_SIDE],
1923 spec->hp_dac_nid = spec->hp_path.path[0];
1924 spec->hp_indep_shared = true;
1925 } else if (spec->multiout.dac_nids[HDA_CLFE] &&
1926 parse_output_path(codec, pin,
1927 spec->multiout.dac_nids[HDA_CLFE],
1929 spec->hp_dac_nid = spec->hp_path.path[0];
1930 spec->hp_indep_shared = true;
1933 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1934 &spec->hp_dep_path) &&
1938 if (spec->hp_dac_nid && !spec->hp_indep_shared) {
1939 path = &spec->hp_path;
1942 path = &spec->hp_dep_path;
1945 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
1948 if (spec->hp_dac_nid) {
1949 spec->hp_dep_path.vol_ctl = spec->hp_path.vol_ctl;
1950 spec->hp_dep_path.mute_ctl = spec->hp_path.mute_ctl;
1956 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1958 struct via_spec *spec = codec->spec;
1961 pin = spec->autocfg.speaker_pins[0];
1962 if (!spec->autocfg.speaker_outs || !pin)
1965 if (parse_output_path(codec, pin, 0, &spec->speaker_path)) {
1966 dac = spec->speaker_path.path[0];
1967 spec->multiout.extra_out_nid[0] = dac;
1968 return create_ch_ctls(codec, "Speaker", 3, true,
1969 &spec->speaker_path);
1971 if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1972 &spec->speaker_path))
1973 return create_ch_ctls(codec, "Speaker", 3, false,
1974 &spec->speaker_path);
1980 static int via_fill_adcs(struct hda_codec *codec)
1982 struct via_spec *spec = codec->spec;
1983 hda_nid_t nid = codec->start_nid;
1986 for (i = 0; i < codec->num_nodes; i++, nid++) {
1987 unsigned int wcaps = get_wcaps(codec, nid);
1988 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1990 if (wcaps & AC_WCAP_DIGITAL)
1992 if (!(wcaps & AC_WCAP_CONN_LIST))
1994 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1996 spec->adc_nids[spec->num_adc_nids++] = nid;
2001 /* input-src control */
2002 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
2003 struct snd_ctl_elem_info *uinfo)
2005 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2006 struct via_spec *spec = codec->spec;
2008 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2010 uinfo->value.enumerated.items = spec->num_inputs;
2011 if (uinfo->value.enumerated.item >= spec->num_inputs)
2012 uinfo->value.enumerated.item = spec->num_inputs - 1;
2013 strcpy(uinfo->value.enumerated.name,
2014 spec->inputs[uinfo->value.enumerated.item].label);
2018 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2019 struct snd_ctl_elem_value *ucontrol)
2021 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2022 struct via_spec *spec = codec->spec;
2023 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2025 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2029 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2030 struct snd_ctl_elem_value *ucontrol)
2032 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2033 struct via_spec *spec = codec->spec;
2034 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2038 cur = ucontrol->value.enumerated.item[0];
2039 if (cur < 0 || cur >= spec->num_inputs)
2041 if (spec->cur_mux[idx] == cur)
2043 spec->cur_mux[idx] = cur;
2044 if (spec->dyn_adc_switch) {
2045 int adc_idx = spec->inputs[cur].adc_idx;
2046 mux = spec->mux_nids[adc_idx];
2047 via_dyn_adc_pcm_resetup(codec, cur);
2049 mux = spec->mux_nids[idx];
2050 if (snd_BUG_ON(!mux))
2055 /* switch to D0 beofre change index */
2056 if (snd_hda_codec_read(codec, mux, 0,
2057 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
2058 snd_hda_codec_write(codec, mux, 0,
2059 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2060 snd_hda_codec_write(codec, mux, 0,
2061 AC_VERB_SET_CONNECT_SEL,
2062 spec->inputs[cur].mux_idx);
2065 /* update jack power state */
2066 set_widgets_power_state(codec);
2070 static const struct snd_kcontrol_new via_input_src_ctl = {
2071 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2072 /* The multiple "Capture Source" controls confuse alsamixer
2073 * So call somewhat different..
2075 /* .name = "Capture Source", */
2076 .name = "Input Source",
2077 .info = via_mux_enum_info,
2078 .get = via_mux_enum_get,
2079 .put = via_mux_enum_put,
2082 static int create_input_src_ctls(struct hda_codec *codec, int count)
2084 struct via_spec *spec = codec->spec;
2085 struct snd_kcontrol_new *knew;
2087 if (spec->num_inputs <= 1 || !count)
2088 return 0; /* no need for single src */
2090 knew = via_clone_control(spec, &via_input_src_ctl);
2093 knew->count = count;
2097 /* add the powersave loopback-list entry */
2098 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2100 struct hda_amp_list *list;
2102 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2104 list = spec->loopback_list + spec->num_loopbacks;
2106 list->dir = HDA_INPUT;
2108 spec->num_loopbacks++;
2109 spec->loopback.amplist = spec->loopback_list;
2112 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2115 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2118 /* add the input-route to the given pin */
2119 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2121 struct via_spec *spec = codec->spec;
2124 spec->inputs[spec->num_inputs].adc_idx = -1;
2125 spec->inputs[spec->num_inputs].pin = pin;
2126 for (c = 0; c < spec->num_adc_nids; c++) {
2127 if (spec->mux_nids[c]) {
2128 idx = get_connection_index(codec, spec->mux_nids[c],
2132 spec->inputs[spec->num_inputs].mux_idx = idx;
2134 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2137 spec->inputs[spec->num_inputs].adc_idx = c;
2138 /* Can primary ADC satisfy all inputs? */
2139 if (!spec->dyn_adc_switch &&
2140 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2141 snd_printd(KERN_INFO
2142 "via: dynamic ADC switching enabled\n");
2143 spec->dyn_adc_switch = 1;
2150 static int get_mux_nids(struct hda_codec *codec);
2152 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2153 static int parse_analog_inputs(struct hda_codec *codec)
2155 struct via_spec *spec = codec->spec;
2156 const struct auto_pin_cfg *cfg = &spec->autocfg;
2159 err = via_fill_adcs(codec);
2162 err = get_mux_nids(codec);
2166 /* fill all input-routes */
2167 for (i = 0; i < cfg->num_inputs; i++) {
2168 if (add_input_route(codec, cfg->inputs[i].pin))
2169 spec->inputs[spec->num_inputs++].label =
2170 hda_get_autocfg_input_label(codec, cfg, i);
2173 /* check for internal loopback recording */
2174 if (spec->aa_mix_nid &&
2175 add_input_route(codec, spec->aa_mix_nid))
2176 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2181 /* create analog-loopback volume/switch controls */
2182 static int create_loopback_ctls(struct hda_codec *codec)
2184 struct via_spec *spec = codec->spec;
2185 const struct auto_pin_cfg *cfg = &spec->autocfg;
2186 const char *prev_label = NULL;
2190 if (!spec->aa_mix_nid)
2193 for (i = 0; i < cfg->num_inputs; i++) {
2194 hda_nid_t pin = cfg->inputs[i].pin;
2195 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2197 if (prev_label && !strcmp(label, prev_label))
2202 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2204 err = via_new_analog_input(spec, label, type_idx,
2205 idx, spec->aa_mix_nid);
2208 add_loopback_list(spec, spec->aa_mix_nid, idx);
2211 /* remember the label for smart51 control */
2212 for (j = 0; j < spec->smart51_nums; j++) {
2213 if (spec->smart51_pins[j] == pin) {
2214 spec->smart51_idxs[j] = idx;
2215 spec->smart51_labels[j] = label;
2223 /* create mic-boost controls (if present) */
2224 static int create_mic_boost_ctls(struct hda_codec *codec)
2226 struct via_spec *spec = codec->spec;
2227 const struct auto_pin_cfg *cfg = &spec->autocfg;
2230 for (i = 0; i < cfg->num_inputs; i++) {
2231 hda_nid_t pin = cfg->inputs[i].pin;
2236 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2238 caps = query_amp_caps(codec, pin, HDA_INPUT);
2239 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2241 label = hda_get_autocfg_input_label(codec, cfg, i);
2242 snprintf(name, sizeof(name), "%s Boost Volume", label);
2243 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2244 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2251 /* create capture and input-src controls for multiple streams */
2252 static int create_multi_adc_ctls(struct hda_codec *codec)
2254 struct via_spec *spec = codec->spec;
2257 /* create capture mixer elements */
2258 for (i = 0; i < spec->num_adc_nids; i++) {
2259 hda_nid_t adc = spec->adc_nids[i];
2260 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2261 "Capture Volume", i,
2262 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2266 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2267 "Capture Switch", i,
2268 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2274 /* input-source control */
2275 for (i = 0; i < spec->num_adc_nids; i++)
2276 if (!spec->mux_nids[i])
2278 err = create_input_src_ctls(codec, i);
2284 /* bind capture volume/switch */
2285 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2286 HDA_BIND_VOL("Capture Volume", 0);
2287 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2288 HDA_BIND_SW("Capture Switch", 0);
2290 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2291 struct hda_ctl_ops *ops)
2293 struct hda_bind_ctls *ctl;
2296 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2300 for (i = 0; i < spec->num_adc_nids; i++)
2302 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2307 /* create capture and input-src controls for dynamic ADC-switch case */
2308 static int create_dyn_adc_ctls(struct hda_codec *codec)
2310 struct via_spec *spec = codec->spec;
2311 struct snd_kcontrol_new *knew;
2314 /* set up the bind capture ctls */
2315 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2318 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2322 /* create capture mixer elements */
2323 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2326 knew->private_value = (long)spec->bind_cap_vol;
2328 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2331 knew->private_value = (long)spec->bind_cap_sw;
2333 /* input-source control */
2334 err = create_input_src_ctls(codec, 1);
2340 /* parse and create capture-related stuff */
2341 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2343 struct via_spec *spec = codec->spec;
2346 err = parse_analog_inputs(codec);
2349 if (spec->dyn_adc_switch)
2350 err = create_dyn_adc_ctls(codec);
2352 err = create_multi_adc_ctls(codec);
2355 err = create_loopback_ctls(codec);
2358 err = create_mic_boost_ctls(codec);
2364 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2366 unsigned int def_conf;
2367 unsigned char seqassoc;
2369 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2370 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2371 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2372 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2373 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2374 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2375 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2381 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2382 struct snd_ctl_elem_value *ucontrol)
2384 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2385 struct via_spec *spec = codec->spec;
2387 if (spec->codec_type != VT1708)
2389 spec->vt1708_jack_detect =
2390 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2391 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2395 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2396 struct snd_ctl_elem_value *ucontrol)
2398 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2399 struct via_spec *spec = codec->spec;
2402 if (spec->codec_type != VT1708)
2404 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2405 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2406 == !spec->vt1708_jack_detect;
2407 if (spec->vt1708_jack_detect) {
2408 mute_aa_path(codec, 1);
2409 notify_aa_path_ctls(codec);
2414 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2415 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2416 .name = "Jack Detect",
2418 .info = snd_ctl_boolean_mono_info,
2419 .get = vt1708_jack_detect_get,
2420 .put = vt1708_jack_detect_put,
2423 static void fill_dig_outs(struct hda_codec *codec);
2424 static void fill_dig_in(struct hda_codec *codec);
2426 static int via_parse_auto_config(struct hda_codec *codec)
2428 struct via_spec *spec = codec->spec;
2431 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2434 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2437 err = via_auto_create_multi_out_ctls(codec);
2440 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2443 err = via_auto_create_speaker_ctls(codec);
2446 err = via_auto_create_analog_input_ctls(codec);
2450 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2452 fill_dig_outs(codec);
2455 if (spec->kctls.list)
2456 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2459 if (spec->hp_dac_nid && spec->hp_dep_path.depth) {
2460 err = via_hp_build(codec);
2465 err = via_smart51_build(codec);
2469 /* assign slave outs */
2470 if (spec->slave_dig_outs[0])
2471 codec->slave_dig_outs = spec->slave_dig_outs;
2476 static void via_auto_init_dig_outs(struct hda_codec *codec)
2478 struct via_spec *spec = codec->spec;
2479 if (spec->multiout.dig_out_nid)
2480 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2481 if (spec->slave_dig_outs[0])
2482 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2485 static void via_auto_init_dig_in(struct hda_codec *codec)
2487 struct via_spec *spec = codec->spec;
2488 if (!spec->dig_in_nid)
2490 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2491 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2494 /* initialize the unsolicited events */
2495 static void via_auto_init_unsol_event(struct hda_codec *codec)
2497 struct via_spec *spec = codec->spec;
2498 struct auto_pin_cfg *cfg = &spec->autocfg;
2502 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2503 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2504 AC_VERB_SET_UNSOLICITED_ENABLE,
2505 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2507 if (cfg->speaker_pins[0])
2508 ev = VIA_LINE_EVENT;
2511 for (i = 0; i < cfg->line_outs; i++) {
2512 if (cfg->line_out_pins[i] &&
2513 is_jack_detectable(codec, cfg->line_out_pins[i]))
2514 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
2515 AC_VERB_SET_UNSOLICITED_ENABLE,
2516 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2519 for (i = 0; i < cfg->num_inputs; i++) {
2520 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2521 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2522 AC_VERB_SET_UNSOLICITED_ENABLE,
2523 AC_USRSP_EN | VIA_JACK_EVENT);
2527 static int via_init(struct hda_codec *codec)
2529 struct via_spec *spec = codec->spec;
2532 for (i = 0; i < spec->num_iverbs; i++)
2533 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2535 via_auto_init_multi_out(codec);
2536 via_auto_init_hp_out(codec);
2537 via_auto_init_speaker_out(codec);
2538 via_auto_init_analog_input(codec);
2539 via_auto_init_dig_outs(codec);
2540 via_auto_init_dig_in(codec);
2542 via_auto_init_unsol_event(codec);
2544 via_hp_automute(codec);
2549 static void vt1708_update_hp_jack_state(struct work_struct *work)
2551 struct via_spec *spec = container_of(work, struct via_spec,
2552 vt1708_hp_work.work);
2553 if (spec->codec_type != VT1708)
2555 /* if jack state toggled */
2556 if (spec->vt1708_hp_present
2557 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2558 spec->vt1708_hp_present ^= 1;
2559 via_hp_automute(spec->codec);
2561 vt1708_start_hp_work(spec);
2564 static int get_mux_nids(struct hda_codec *codec)
2566 struct via_spec *spec = codec->spec;
2567 hda_nid_t nid, conn[8];
2571 for (i = 0; i < spec->num_adc_nids; i++) {
2572 nid = spec->adc_nids[i];
2574 type = get_wcaps_type(get_wcaps(codec, nid));
2575 if (type == AC_WID_PIN)
2577 n = snd_hda_get_connections(codec, nid, conn,
2582 spec->mux_nids[i] = nid;
2591 static int patch_vt1708(struct hda_codec *codec)
2593 struct via_spec *spec;
2596 /* create a codec specific record */
2597 spec = via_new_spec(codec);
2601 spec->aa_mix_nid = 0x17;
2603 /* Add HP and CD pin config connect bit re-config action */
2604 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2605 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2607 /* automatic parse from the BIOS config */
2608 err = via_parse_auto_config(codec);
2614 /* add jack detect on/off control */
2615 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2618 /* disable 32bit format on VT1708 */
2619 if (codec->vendor_id == 0x11061708)
2620 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2622 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2624 codec->patch_ops = via_patch_ops;
2626 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2630 static int patch_vt1709(struct hda_codec *codec)
2632 struct via_spec *spec;
2635 /* create a codec specific record */
2636 spec = via_new_spec(codec);
2640 spec->aa_mix_nid = 0x18;
2642 err = via_parse_auto_config(codec);
2648 codec->patch_ops = via_patch_ops;
2653 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2655 struct via_spec *spec = codec->spec;
2659 if ((spec->codec_type != VT1708B_4CH) &&
2660 (codec->vendor_id != 0x11064397))
2663 /* SW0 (17h) = stereo mixer */
2665 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2666 == ((spec->codec_type == VT1708S) ? 5 : 0));
2668 /* PW 1/2/5 (1ah/1bh/1eh) */
2670 set_pin_power_state(codec, 0x1a, &parm);
2671 set_pin_power_state(codec, 0x1b, &parm);
2672 set_pin_power_state(codec, 0x1e, &parm);
2675 /* SW0 (17h), AIW 0/1 (13h/14h) */
2676 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2677 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2678 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2681 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2683 set_pin_power_state(codec, 0x19, &parm);
2684 if (spec->smart51_enabled)
2685 set_pin_power_state(codec, 0x1b, &parm);
2686 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2687 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2689 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2692 set_pin_power_state(codec, 0x22, &parm);
2693 if (spec->smart51_enabled)
2694 set_pin_power_state(codec, 0x1a, &parm);
2695 snd_hda_codec_write(codec, 0x26, 0,
2696 AC_VERB_SET_POWER_STATE, parm);
2697 snd_hda_codec_write(codec, 0x24, 0,
2698 AC_VERB_SET_POWER_STATE, parm);
2699 } else if (codec->vendor_id == 0x11064397) {
2700 /* PW7(23h), SW2(27h), AOW2(25h) */
2702 set_pin_power_state(codec, 0x23, &parm);
2703 if (spec->smart51_enabled)
2704 set_pin_power_state(codec, 0x1a, &parm);
2705 snd_hda_codec_write(codec, 0x27, 0,
2706 AC_VERB_SET_POWER_STATE, parm);
2707 snd_hda_codec_write(codec, 0x25, 0,
2708 AC_VERB_SET_POWER_STATE, parm);
2711 /* PW 3/4/7 (1ch/1dh/23h) */
2713 /* force to D0 for internal Speaker */
2714 set_pin_power_state(codec, 0x1c, &parm);
2715 set_pin_power_state(codec, 0x1d, &parm);
2717 set_pin_power_state(codec, 0x23, &parm);
2719 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2720 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2721 imux_is_smixer ? AC_PWRST_D0 : parm);
2722 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2724 snd_hda_codec_write(codec, 0x25, 0,
2725 AC_VERB_SET_POWER_STATE, parm);
2726 snd_hda_codec_write(codec, 0x27, 0,
2727 AC_VERB_SET_POWER_STATE, parm);
2728 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2729 snd_hda_codec_write(codec, 0x25, 0,
2730 AC_VERB_SET_POWER_STATE, parm);
2733 static int patch_vt1708S(struct hda_codec *codec);
2734 static int patch_vt1708B(struct hda_codec *codec)
2736 struct via_spec *spec;
2739 if (get_codec_type(codec) == VT1708BCE)
2740 return patch_vt1708S(codec);
2742 /* create a codec specific record */
2743 spec = via_new_spec(codec);
2747 spec->aa_mix_nid = 0x16;
2749 /* automatic parse from the BIOS config */
2750 err = via_parse_auto_config(codec);
2756 codec->patch_ops = via_patch_ops;
2758 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2763 /* Patch for VT1708S */
2764 static const struct hda_verb vt1708S_init_verbs[] = {
2765 /* Enable Mic Boost Volume backdoor */
2767 /* don't bybass mixer */
2772 /* fill out digital output widgets; one for master and one for slave outputs */
2773 static void fill_dig_outs(struct hda_codec *codec)
2775 struct via_spec *spec = codec->spec;
2778 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2782 nid = spec->autocfg.dig_out_pins[i];
2785 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2788 if (!spec->multiout.dig_out_nid)
2789 spec->multiout.dig_out_nid = nid;
2791 spec->slave_dig_outs[0] = nid;
2792 break; /* at most two dig outs */
2797 static void fill_dig_in(struct hda_codec *codec)
2799 struct via_spec *spec = codec->spec;
2803 if (!spec->autocfg.dig_in_pin)
2806 dig_nid = codec->start_nid;
2807 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2808 unsigned int wcaps = get_wcaps(codec, dig_nid);
2809 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2811 if (!(wcaps & AC_WCAP_DIGITAL))
2813 if (!(wcaps & AC_WCAP_CONN_LIST))
2815 err = get_connection_index(codec, dig_nid,
2816 spec->autocfg.dig_in_pin);
2818 spec->dig_in_nid = dig_nid;
2824 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2825 int offset, int num_steps, int step_size)
2827 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2828 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2829 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2830 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2831 (0 << AC_AMPCAP_MUTE_SHIFT));
2834 static int patch_vt1708S(struct hda_codec *codec)
2836 struct via_spec *spec;
2839 /* create a codec specific record */
2840 spec = via_new_spec(codec);
2844 spec->aa_mix_nid = 0x16;
2845 override_mic_boost(codec, 0x1a, 0, 3, 40);
2846 override_mic_boost(codec, 0x1e, 0, 3, 40);
2848 /* automatic parse from the BIOS config */
2849 err = via_parse_auto_config(codec);
2855 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2857 codec->patch_ops = via_patch_ops;
2859 /* correct names for VT1708BCE */
2860 if (get_codec_type(codec) == VT1708BCE) {
2861 kfree(codec->chip_name);
2862 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2863 snprintf(codec->bus->card->mixername,
2864 sizeof(codec->bus->card->mixername),
2865 "%s %s", codec->vendor_name, codec->chip_name);
2867 /* correct names for VT1705 */
2868 if (codec->vendor_id == 0x11064397) {
2869 kfree(codec->chip_name);
2870 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2871 snprintf(codec->bus->card->mixername,
2872 sizeof(codec->bus->card->mixername),
2873 "%s %s", codec->vendor_name, codec->chip_name);
2875 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2879 /* Patch for VT1702 */
2881 static const struct hda_verb vt1702_init_verbs[] = {
2889 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2891 int imux_is_smixer =
2892 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2895 /* PW 1/2/5 (14h/15h/18h) */
2897 set_pin_power_state(codec, 0x14, &parm);
2898 set_pin_power_state(codec, 0x15, &parm);
2899 set_pin_power_state(codec, 0x18, &parm);
2901 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2902 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2903 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2904 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2905 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2906 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2909 /* PW 3/4 (16h/17h) */
2911 set_pin_power_state(codec, 0x17, &parm);
2912 set_pin_power_state(codec, 0x16, &parm);
2913 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2914 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2915 imux_is_smixer ? AC_PWRST_D0 : parm);
2916 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2917 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2920 static int patch_vt1702(struct hda_codec *codec)
2922 struct via_spec *spec;
2925 /* create a codec specific record */
2926 spec = via_new_spec(codec);
2930 spec->aa_mix_nid = 0x1a;
2932 /* limit AA path volume to 0 dB */
2933 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2934 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2935 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2936 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2937 (1 << AC_AMPCAP_MUTE_SHIFT));
2939 /* automatic parse from the BIOS config */
2940 err = via_parse_auto_config(codec);
2946 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
2948 codec->patch_ops = via_patch_ops;
2950 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
2954 /* Patch for VT1718S */
2956 static const struct hda_verb vt1718S_init_verbs[] = {
2957 /* Enable MW0 adjust Gain 5 */
2959 /* Enable Boost Volume backdoor */
2965 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2967 struct via_spec *spec = codec->spec;
2970 /* MUX6 (1eh) = stereo mixer */
2972 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2974 /* PW 5/6/7 (29h/2ah/2bh) */
2976 set_pin_power_state(codec, 0x29, &parm);
2977 set_pin_power_state(codec, 0x2a, &parm);
2978 set_pin_power_state(codec, 0x2b, &parm);
2981 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2982 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2983 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2984 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2985 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2988 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2990 set_pin_power_state(codec, 0x27, &parm);
2991 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2992 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2994 /* PW2 (26h), AOW2 (ah) */
2996 set_pin_power_state(codec, 0x26, &parm);
2997 if (spec->smart51_enabled)
2998 set_pin_power_state(codec, 0x2b, &parm);
2999 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
3001 /* PW0 (24h), AOW0 (8h) */
3003 set_pin_power_state(codec, 0x24, &parm);
3004 if (!spec->hp_independent_mode) /* check for redirected HP */
3005 set_pin_power_state(codec, 0x28, &parm);
3006 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3007 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3008 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3009 imux_is_smixer ? AC_PWRST_D0 : parm);
3011 /* PW1 (25h), AOW1 (9h) */
3013 set_pin_power_state(codec, 0x25, &parm);
3014 if (spec->smart51_enabled)
3015 set_pin_power_state(codec, 0x2a, &parm);
3016 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3018 if (spec->hp_independent_mode) {
3019 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3021 set_pin_power_state(codec, 0x28, &parm);
3022 snd_hda_codec_write(codec, 0x1b, 0,
3023 AC_VERB_SET_POWER_STATE, parm);
3024 snd_hda_codec_write(codec, 0x34, 0,
3025 AC_VERB_SET_POWER_STATE, parm);
3026 snd_hda_codec_write(codec, 0xc, 0,
3027 AC_VERB_SET_POWER_STATE, parm);
3031 static int patch_vt1718S(struct hda_codec *codec)
3033 struct via_spec *spec;
3036 /* create a codec specific record */
3037 spec = via_new_spec(codec);
3041 spec->aa_mix_nid = 0x21;
3042 override_mic_boost(codec, 0x2b, 0, 3, 40);
3043 override_mic_boost(codec, 0x29, 0, 3, 40);
3044 spec->dac_mixer_idx = 5;
3046 /* automatic parse from the BIOS config */
3047 err = via_parse_auto_config(codec);
3053 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3055 codec->patch_ops = via_patch_ops;
3057 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3062 /* Patch for VT1716S */
3064 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3065 struct snd_ctl_elem_info *uinfo)
3067 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3069 uinfo->value.integer.min = 0;
3070 uinfo->value.integer.max = 1;
3074 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3075 struct snd_ctl_elem_value *ucontrol)
3077 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3080 index = snd_hda_codec_read(codec, 0x26, 0,
3081 AC_VERB_GET_CONNECT_SEL, 0);
3083 *ucontrol->value.integer.value = index;
3088 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3089 struct snd_ctl_elem_value *ucontrol)
3091 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3092 struct via_spec *spec = codec->spec;
3093 int index = *ucontrol->value.integer.value;
3095 snd_hda_codec_write(codec, 0x26, 0,
3096 AC_VERB_SET_CONNECT_SEL, index);
3097 spec->dmic_enabled = index;
3098 set_widgets_power_state(codec);
3102 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3103 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3105 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3106 .name = "Digital Mic Capture Switch",
3107 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3109 .info = vt1716s_dmic_info,
3110 .get = vt1716s_dmic_get,
3111 .put = vt1716s_dmic_put,
3117 /* mono-out mixer elements */
3118 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3119 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3123 static const struct hda_verb vt1716S_init_verbs[] = {
3124 /* Enable Boost Volume backdoor */
3126 /* don't bybass mixer */
3128 /* Enable mono output */
3133 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3135 struct via_spec *spec = codec->spec;
3138 unsigned int mono_out, present;
3139 /* SW0 (17h) = stereo mixer */
3141 (snd_hda_codec_read(codec, 0x17, 0,
3142 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3144 /* PW 1/2/5 (1ah/1bh/1eh) */
3146 set_pin_power_state(codec, 0x1a, &parm);
3147 set_pin_power_state(codec, 0x1b, &parm);
3148 set_pin_power_state(codec, 0x1e, &parm);
3151 /* SW0 (17h), AIW0(13h) */
3152 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3153 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3156 set_pin_power_state(codec, 0x1e, &parm);
3158 if (spec->dmic_enabled)
3159 set_pin_power_state(codec, 0x22, &parm);
3161 snd_hda_codec_write(codec, 0x22, 0,
3162 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3164 /* SW2(26h), AIW1(14h) */
3165 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3166 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3169 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3171 set_pin_power_state(codec, 0x19, &parm);
3172 /* Smart 5.1 PW2(1bh) */
3173 if (spec->smart51_enabled)
3174 set_pin_power_state(codec, 0x1b, &parm);
3175 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3176 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3178 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3180 set_pin_power_state(codec, 0x23, &parm);
3181 /* Smart 5.1 PW1(1ah) */
3182 if (spec->smart51_enabled)
3183 set_pin_power_state(codec, 0x1a, &parm);
3184 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3186 /* Smart 5.1 PW5(1eh) */
3187 if (spec->smart51_enabled)
3188 set_pin_power_state(codec, 0x1e, &parm);
3189 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3192 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3193 present = snd_hda_jack_detect(codec, 0x1c);
3198 present = snd_hda_jack_detect(codec, 0x1d);
3199 if (!spec->hp_independent_mode && present)
3204 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3205 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3206 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3207 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3209 /* PW 3/4 (1ch/1dh) */
3211 set_pin_power_state(codec, 0x1c, &parm);
3212 set_pin_power_state(codec, 0x1d, &parm);
3213 /* HP Independent Mode, power on AOW3 */
3214 if (spec->hp_independent_mode)
3215 snd_hda_codec_write(codec, 0x25, 0,
3216 AC_VERB_SET_POWER_STATE, parm);
3218 /* force to D0 for internal Speaker */
3219 /* MW0 (16h), AOW0 (10h) */
3220 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3221 imux_is_smixer ? AC_PWRST_D0 : parm);
3222 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3223 mono_out ? AC_PWRST_D0 : parm);
3226 static int patch_vt1716S(struct hda_codec *codec)
3228 struct via_spec *spec;
3231 /* create a codec specific record */
3232 spec = via_new_spec(codec);
3236 spec->aa_mix_nid = 0x16;
3237 override_mic_boost(codec, 0x1a, 0, 3, 40);
3238 override_mic_boost(codec, 0x1e, 0, 3, 40);
3240 /* automatic parse from the BIOS config */
3241 err = via_parse_auto_config(codec);
3247 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3249 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3252 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3254 codec->patch_ops = via_patch_ops;
3256 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3262 static const struct hda_verb vt2002P_init_verbs[] = {
3263 /* Class-D speaker related verbs */
3267 /* Enable Boost Volume backdoor */
3269 /* Enable AOW0 to MW9 */
3274 static const struct hda_verb vt1802_init_verbs[] = {
3275 /* Enable Boost Volume backdoor */
3277 /* Enable AOW0 to MW9 */
3282 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3284 struct via_spec *spec = codec->spec;
3287 unsigned int present;
3288 /* MUX9 (1eh) = stereo mixer */
3290 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3292 /* PW 5/6/7 (29h/2ah/2bh) */
3294 set_pin_power_state(codec, 0x29, &parm);
3295 set_pin_power_state(codec, 0x2a, &parm);
3296 set_pin_power_state(codec, 0x2b, &parm);
3298 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3299 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3300 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3301 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3302 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3306 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3308 if (spec->codec_type == VT1802) {
3309 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3311 set_pin_power_state(codec, 0x28, &parm);
3312 snd_hda_codec_write(codec, 0x18, 0,
3313 AC_VERB_SET_POWER_STATE, parm);
3314 snd_hda_codec_write(codec, 0x38, 0,
3315 AC_VERB_SET_POWER_STATE, parm);
3317 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3319 set_pin_power_state(codec, 0x26, &parm);
3320 snd_hda_codec_write(codec, 0x1c, 0,
3321 AC_VERB_SET_POWER_STATE, parm);
3322 snd_hda_codec_write(codec, 0x37, 0,
3323 AC_VERB_SET_POWER_STATE, parm);
3326 if (spec->codec_type == VT1802) {
3327 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3329 set_pin_power_state(codec, 0x25, &parm);
3330 snd_hda_codec_write(codec, 0x15, 0,
3331 AC_VERB_SET_POWER_STATE, parm);
3332 snd_hda_codec_write(codec, 0x35, 0,
3333 AC_VERB_SET_POWER_STATE, parm);
3335 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3337 set_pin_power_state(codec, 0x25, &parm);
3338 snd_hda_codec_write(codec, 0x19, 0,
3339 AC_VERB_SET_POWER_STATE, parm);
3340 snd_hda_codec_write(codec, 0x35, 0,
3341 AC_VERB_SET_POWER_STATE, parm);
3344 if (spec->hp_independent_mode)
3345 snd_hda_codec_write(codec, 0x9, 0,
3346 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3349 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3350 present = snd_hda_jack_detect(codec, 0x25);
3353 set_pin_power_state(codec, 0x24, &parm);
3354 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3355 if (spec->codec_type == VT1802)
3356 snd_hda_codec_write(codec, 0x14, 0,
3357 AC_VERB_SET_POWER_STATE, parm);
3359 snd_hda_codec_write(codec, 0x18, 0,
3360 AC_VERB_SET_POWER_STATE, parm);
3361 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3364 present = snd_hda_jack_detect(codec, 0x26);
3366 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3367 if (spec->codec_type == VT1802) {
3368 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3369 snd_hda_codec_write(codec, 0x33, 0,
3370 AC_VERB_SET_POWER_STATE, parm);
3371 snd_hda_codec_write(codec, 0x1c, 0,
3372 AC_VERB_SET_POWER_STATE, parm);
3373 snd_hda_codec_write(codec, 0x3c, 0,
3374 AC_VERB_SET_POWER_STATE, parm);
3376 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3377 snd_hda_codec_write(codec, 0x31, 0,
3378 AC_VERB_SET_POWER_STATE, parm);
3379 snd_hda_codec_write(codec, 0x17, 0,
3380 AC_VERB_SET_POWER_STATE, parm);
3381 snd_hda_codec_write(codec, 0x3b, 0,
3382 AC_VERB_SET_POWER_STATE, parm);
3385 if (imux_is_smixer || !is_aa_path_mute(codec))
3386 snd_hda_codec_write(codec, 0x21, 0,
3387 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3389 snd_hda_codec_write(codec, 0x21, 0,
3390 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3393 /* patch for vt2002P */
3394 static int patch_vt2002P(struct hda_codec *codec)
3396 struct via_spec *spec;
3399 /* create a codec specific record */
3400 spec = via_new_spec(codec);
3404 spec->aa_mix_nid = 0x21;
3405 spec->dac_mixer_idx = 3;
3406 override_mic_boost(codec, 0x2b, 0, 3, 40);
3407 override_mic_boost(codec, 0x29, 0, 3, 40);
3409 /* automatic parse from the BIOS config */
3410 err = via_parse_auto_config(codec);
3416 if (spec->codec_type == VT1802)
3417 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3419 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3421 codec->patch_ops = via_patch_ops;
3423 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3429 static const struct hda_verb vt1812_init_verbs[] = {
3430 /* Enable Boost Volume backdoor */
3432 /* Enable AOW0 to MW9 */
3437 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3439 struct via_spec *spec = codec->spec;
3440 int imux_is_smixer =
3441 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3443 unsigned int present;
3444 /* MUX10 (1eh) = stereo mixer */
3446 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3448 /* PW 5/6/7 (29h/2ah/2bh) */
3450 set_pin_power_state(codec, 0x29, &parm);
3451 set_pin_power_state(codec, 0x2a, &parm);
3452 set_pin_power_state(codec, 0x2b, &parm);
3454 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3455 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3456 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3457 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3458 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3462 snd_hda_codec_write(codec, 0x8, 0,
3463 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3465 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3467 set_pin_power_state(codec, 0x28, &parm);
3468 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3469 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3471 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3473 set_pin_power_state(codec, 0x25, &parm);
3474 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3475 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3476 if (spec->hp_independent_mode)
3477 snd_hda_codec_write(codec, 0x9, 0,
3478 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3480 /* Internal Speaker */
3481 /* PW0 (24h), MW0(14h), MUX0(34h) */
3482 present = snd_hda_jack_detect(codec, 0x25);
3485 set_pin_power_state(codec, 0x24, &parm);
3487 snd_hda_codec_write(codec, 0x14, 0,
3488 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3489 snd_hda_codec_write(codec, 0x34, 0,
3490 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3492 snd_hda_codec_write(codec, 0x14, 0,
3493 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3494 snd_hda_codec_write(codec, 0x34, 0,
3495 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3500 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3501 present = snd_hda_jack_detect(codec, 0x28);
3504 set_pin_power_state(codec, 0x31, &parm);
3506 snd_hda_codec_write(codec, 0x1c, 0,
3507 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3508 snd_hda_codec_write(codec, 0x3c, 0,
3509 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3510 snd_hda_codec_write(codec, 0x3e, 0,
3511 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3513 snd_hda_codec_write(codec, 0x1c, 0,
3514 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3515 snd_hda_codec_write(codec, 0x3c, 0,
3516 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3517 snd_hda_codec_write(codec, 0x3e, 0,
3518 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3521 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3523 set_pin_power_state(codec, 0x33, &parm);
3524 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3525 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3529 /* patch for vt1812 */
3530 static int patch_vt1812(struct hda_codec *codec)
3532 struct via_spec *spec;
3535 /* create a codec specific record */
3536 spec = via_new_spec(codec);
3540 spec->aa_mix_nid = 0x21;
3541 override_mic_boost(codec, 0x2b, 0, 3, 40);
3542 override_mic_boost(codec, 0x29, 0, 3, 40);
3543 spec->dac_mixer_idx = 5;
3545 /* automatic parse from the BIOS config */
3546 err = via_parse_auto_config(codec);
3552 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3554 codec->patch_ops = via_patch_ops;
3556 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3563 static const struct hda_codec_preset snd_hda_preset_via[] = {
3564 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3565 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3566 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3567 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3568 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3569 .patch = patch_vt1709},
3570 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3571 .patch = patch_vt1709},
3572 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3573 .patch = patch_vt1709},
3574 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3575 .patch = patch_vt1709},
3576 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3577 .patch = patch_vt1709},
3578 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3579 .patch = patch_vt1709},
3580 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3581 .patch = patch_vt1709},
3582 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3583 .patch = patch_vt1709},
3584 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3585 .patch = patch_vt1708B},
3586 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3587 .patch = patch_vt1708B},
3588 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3589 .patch = patch_vt1708B},
3590 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3591 .patch = patch_vt1708B},
3592 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3593 .patch = patch_vt1708B},
3594 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3595 .patch = patch_vt1708B},
3596 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3597 .patch = patch_vt1708B},
3598 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3599 .patch = patch_vt1708B},
3600 { .id = 0x11060397, .name = "VT1708S",
3601 .patch = patch_vt1708S},
3602 { .id = 0x11061397, .name = "VT1708S",
3603 .patch = patch_vt1708S},
3604 { .id = 0x11062397, .name = "VT1708S",
3605 .patch = patch_vt1708S},
3606 { .id = 0x11063397, .name = "VT1708S",
3607 .patch = patch_vt1708S},
3608 { .id = 0x11064397, .name = "VT1705",
3609 .patch = patch_vt1708S},
3610 { .id = 0x11065397, .name = "VT1708S",
3611 .patch = patch_vt1708S},
3612 { .id = 0x11066397, .name = "VT1708S",
3613 .patch = patch_vt1708S},
3614 { .id = 0x11067397, .name = "VT1708S",
3615 .patch = patch_vt1708S},
3616 { .id = 0x11060398, .name = "VT1702",
3617 .patch = patch_vt1702},
3618 { .id = 0x11061398, .name = "VT1702",
3619 .patch = patch_vt1702},
3620 { .id = 0x11062398, .name = "VT1702",
3621 .patch = patch_vt1702},
3622 { .id = 0x11063398, .name = "VT1702",
3623 .patch = patch_vt1702},
3624 { .id = 0x11064398, .name = "VT1702",
3625 .patch = patch_vt1702},
3626 { .id = 0x11065398, .name = "VT1702",
3627 .patch = patch_vt1702},
3628 { .id = 0x11066398, .name = "VT1702",
3629 .patch = patch_vt1702},
3630 { .id = 0x11067398, .name = "VT1702",
3631 .patch = patch_vt1702},
3632 { .id = 0x11060428, .name = "VT1718S",
3633 .patch = patch_vt1718S},
3634 { .id = 0x11064428, .name = "VT1718S",
3635 .patch = patch_vt1718S},
3636 { .id = 0x11060441, .name = "VT2020",
3637 .patch = patch_vt1718S},
3638 { .id = 0x11064441, .name = "VT1828S",
3639 .patch = patch_vt1718S},
3640 { .id = 0x11060433, .name = "VT1716S",
3641 .patch = patch_vt1716S},
3642 { .id = 0x1106a721, .name = "VT1716S",
3643 .patch = patch_vt1716S},
3644 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3645 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3646 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3647 { .id = 0x11060440, .name = "VT1818S",
3648 .patch = patch_vt1708S},
3649 { .id = 0x11060446, .name = "VT1802",
3650 .patch = patch_vt2002P},
3651 { .id = 0x11068446, .name = "VT1802",
3652 .patch = patch_vt2002P},
3656 MODULE_ALIAS("snd-hda-codec-id:1106*");
3658 static struct hda_codec_preset_list via_list = {
3659 .preset = snd_hda_preset_via,
3660 .owner = THIS_MODULE,
3663 MODULE_LICENSE("GPL");
3664 MODULE_DESCRIPTION("VIA HD-audio codec");
3666 static int __init patch_via_init(void)
3668 return snd_hda_add_codec_preset(&via_list);
3671 static void __exit patch_via_exit(void)
3673 snd_hda_delete_codec_preset(&via_list);
3676 module_init(patch_via_init)
3677 module_exit(patch_via_exit)