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);
619 static void via_auto_init_analog_input(struct hda_codec *codec)
621 struct via_spec *spec = codec->spec;
622 const struct auto_pin_cfg *cfg = &spec->autocfg;
623 hda_nid_t conn[HDA_MAX_CONNECTIONS];
628 for (i = 0; i < spec->num_adc_nids; i++) {
629 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
630 AC_VERB_SET_AMP_GAIN_MUTE,
635 for (i = 0; i < cfg->num_inputs; i++) {
636 hda_nid_t nid = cfg->inputs[i].pin;
637 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
639 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
643 snd_hda_codec_write(codec, nid, 0,
644 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
648 for (i = 0; i < spec->num_adc_nids; i++) {
649 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
650 if (spec->mux_nids[adc_idx]) {
651 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
652 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
653 AC_VERB_SET_CONNECT_SEL,
656 if (spec->dyn_adc_switch)
657 break; /* only one input-src */
661 if (!spec->aa_mix_nid)
663 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
665 for (i = 0; i < num_conns; i++) {
666 unsigned int caps = get_wcaps(codec, conn[i]);
667 if (get_wcaps_type(caps) == AC_WID_PIN)
668 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
669 AC_VERB_SET_AMP_GAIN_MUTE,
674 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
675 unsigned int *affected_parm)
678 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
679 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
680 >> AC_DEFCFG_MISC_SHIFT
681 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
682 struct via_spec *spec = codec->spec;
683 unsigned present = 0;
685 no_presence |= spec->no_pin_power_ctl;
687 present = snd_hda_jack_detect(codec, nid);
688 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
689 || ((no_presence || present)
690 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
691 *affected_parm = AC_PWRST_D0; /* if it's connected */
696 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
699 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_info *uinfo)
702 static const char * const texts[] = {
703 "Disabled", "Enabled"
706 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
708 uinfo->value.enumerated.items = 2;
709 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
710 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
711 strcpy(uinfo->value.enumerated.name,
712 texts[uinfo->value.enumerated.item]);
716 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
717 struct snd_ctl_elem_value *ucontrol)
719 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
720 struct via_spec *spec = codec->spec;
721 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
725 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
726 struct snd_ctl_elem_value *ucontrol)
728 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
729 struct via_spec *spec = codec->spec;
730 unsigned int val = !ucontrol->value.enumerated.item[0];
732 if (val == spec->no_pin_power_ctl)
734 spec->no_pin_power_ctl = val;
735 set_widgets_power_state(codec);
739 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
741 .name = "Dynamic Power-Control",
742 .info = via_pin_power_ctl_info,
743 .get = via_pin_power_ctl_get,
744 .put = via_pin_power_ctl_put,
748 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
749 struct snd_ctl_elem_info *uinfo)
751 static const char * const texts[] = { "OFF", "ON" };
753 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
755 uinfo->value.enumerated.items = 2;
756 if (uinfo->value.enumerated.item >= 2)
757 uinfo->value.enumerated.item = 1;
758 strcpy(uinfo->value.enumerated.name,
759 texts[uinfo->value.enumerated.item]);
763 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
764 struct snd_ctl_elem_value *ucontrol)
766 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
767 struct via_spec *spec = codec->spec;
769 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
773 static int via_independent_hp_put(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;
780 /* no independent-hp status change during PCM playback is running */
781 if (spec->num_active_streams)
784 cur = !!ucontrol->value.enumerated.item[0];
785 if (spec->hp_independent_mode == cur)
787 spec->hp_independent_mode = cur;
789 activate_output_path(codec, &spec->hp_dep_path, false, false);
790 activate_output_path(codec, &spec->hp_path, true, false);
791 if (spec->hp_indep_shared)
792 activate_output_path(codec, &spec->out_path[HDA_SIDE],
795 activate_output_path(codec, &spec->hp_path, false, false);
796 activate_output_path(codec, &spec->hp_dep_path, true, false);
797 if (spec->hp_indep_shared)
798 activate_output_path(codec, &spec->out_path[HDA_SIDE],
802 /* update jack power state */
803 set_widgets_power_state(codec);
807 static const struct snd_kcontrol_new via_hp_mixer = {
808 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
809 .name = "Independent HP",
810 .info = via_independent_hp_info,
811 .get = via_independent_hp_get,
812 .put = via_independent_hp_put,
815 static int via_hp_build(struct hda_codec *codec)
817 struct via_spec *spec = codec->spec;
818 struct snd_kcontrol_new *knew;
821 nid = spec->autocfg.hp_pins[0];
822 knew = via_clone_control(spec, &via_hp_mixer);
826 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
831 static void notify_aa_path_ctls(struct hda_codec *codec)
833 struct via_spec *spec = codec->spec;
836 for (i = 0; i < spec->smart51_nums; i++) {
837 struct snd_kcontrol *ctl;
838 struct snd_ctl_elem_id id;
839 memset(&id, 0, sizeof(id));
840 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
841 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
842 ctl = snd_hda_find_mixer_ctl(codec, id.name);
844 snd_ctl_notify(codec->bus->card,
845 SNDRV_CTL_EVENT_MASK_VALUE,
850 static void mute_aa_path(struct hda_codec *codec, int mute)
852 struct via_spec *spec = codec->spec;
853 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
856 /* check AA path's mute status */
857 for (i = 0; i < spec->smart51_nums; i++) {
858 if (spec->smart51_idxs[i] < 0)
860 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
861 HDA_INPUT, spec->smart51_idxs[i],
866 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
868 struct via_spec *spec = codec->spec;
871 for (i = 0; i < spec->smart51_nums; i++)
872 if (spec->smart51_pins[i] == pin)
877 static int via_smart51_get(struct snd_kcontrol *kcontrol,
878 struct snd_ctl_elem_value *ucontrol)
880 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
881 struct via_spec *spec = codec->spec;
883 *ucontrol->value.integer.value = spec->smart51_enabled;
887 static int via_smart51_put(struct snd_kcontrol *kcontrol,
888 struct snd_ctl_elem_value *ucontrol)
890 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
891 struct via_spec *spec = codec->spec;
892 int out_in = *ucontrol->value.integer.value
893 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
896 for (i = 0; i < spec->smart51_nums; i++) {
897 hda_nid_t nid = spec->smart51_pins[i];
900 parm = snd_hda_codec_read(codec, nid, 0,
901 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
902 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
904 snd_hda_codec_write(codec, nid, 0,
905 AC_VERB_SET_PIN_WIDGET_CONTROL,
907 if (out_in == AC_PINCTL_OUT_EN) {
908 mute_aa_path(codec, 1);
909 notify_aa_path_ctls(codec);
912 spec->smart51_enabled = *ucontrol->value.integer.value;
913 set_widgets_power_state(codec);
917 static const struct snd_kcontrol_new via_smart51_mixer = {
918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
921 .info = snd_ctl_boolean_mono_info,
922 .get = via_smart51_get,
923 .put = via_smart51_put,
926 static int via_smart51_build(struct hda_codec *codec)
928 struct via_spec *spec = codec->spec;
930 if (!spec->smart51_nums)
932 if (!via_clone_control(spec, &via_smart51_mixer))
937 /* check AA path's mute status */
938 static bool is_aa_path_mute(struct hda_codec *codec)
940 struct via_spec *spec = codec->spec;
941 const struct hda_amp_list *p;
944 for (i = 0; i < spec->num_loopbacks; i++) {
945 p = &spec->loopback_list[i];
946 for (ch = 0; ch < 2; ch++) {
947 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
949 if (!(v & HDA_AMP_MUTE) && v > 0)
956 /* enter/exit analog low-current mode */
957 static void analog_low_current_mode(struct hda_codec *codec)
959 struct via_spec *spec = codec->spec;
961 unsigned int verb, parm;
963 enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0);
965 /* decide low current mode's verb & parameter */
966 switch (spec->codec_type) {
970 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
976 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
980 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
986 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
989 return; /* other codecs are not supported */
992 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
996 * generic initialization of ADC, input mixers and output mixers
998 static const struct hda_verb vt1708_init_verbs[] = {
999 /* power down jack detect function */
1004 static void set_stream_active(struct hda_codec *codec, bool active)
1006 struct via_spec *spec = codec->spec;
1009 spec->num_active_streams++;
1011 spec->num_active_streams--;
1012 analog_low_current_mode(codec);
1015 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
1016 struct hda_codec *codec,
1017 struct snd_pcm_substream *substream)
1019 struct via_spec *spec = codec->spec;
1020 const struct auto_pin_cfg *cfg = &spec->autocfg;
1023 spec->multiout.hp_nid = 0;
1024 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
1025 if (!spec->hp_independent_mode) {
1026 if (!spec->hp_indep_shared)
1027 spec->multiout.hp_nid = spec->hp_dac_nid;
1029 if (spec->hp_indep_shared)
1030 spec->multiout.num_dacs = cfg->line_outs - 1;
1032 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1033 set_stream_active(codec, true);
1034 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1037 spec->multiout.hp_nid = 0;
1038 set_stream_active(codec, false);
1044 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1045 struct hda_codec *codec,
1046 struct snd_pcm_substream *substream)
1048 struct via_spec *spec = codec->spec;
1050 spec->multiout.hp_nid = 0;
1051 set_stream_active(codec, false);
1055 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1056 struct hda_codec *codec,
1057 struct snd_pcm_substream *substream)
1059 struct via_spec *spec = codec->spec;
1061 if (snd_BUG_ON(!spec->hp_dac_nid))
1063 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1065 set_stream_active(codec, true);
1069 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1070 struct hda_codec *codec,
1071 struct snd_pcm_substream *substream)
1073 set_stream_active(codec, false);
1077 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1078 struct hda_codec *codec,
1079 unsigned int stream_tag,
1080 unsigned int format,
1081 struct snd_pcm_substream *substream)
1083 struct via_spec *spec = codec->spec;
1085 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1087 vt1708_start_hp_work(spec);
1091 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1092 struct hda_codec *codec,
1093 unsigned int stream_tag,
1094 unsigned int format,
1095 struct snd_pcm_substream *substream)
1097 struct via_spec *spec = codec->spec;
1099 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1100 stream_tag, 0, format);
1101 vt1708_start_hp_work(spec);
1105 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1106 struct hda_codec *codec,
1107 struct snd_pcm_substream *substream)
1109 struct via_spec *spec = codec->spec;
1111 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1112 vt1708_stop_hp_work(spec);
1116 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1117 struct hda_codec *codec,
1118 struct snd_pcm_substream *substream)
1120 struct via_spec *spec = codec->spec;
1122 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1123 vt1708_stop_hp_work(spec);
1130 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1131 struct hda_codec *codec,
1132 struct snd_pcm_substream *substream)
1134 struct via_spec *spec = codec->spec;
1135 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1138 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1139 struct hda_codec *codec,
1140 struct snd_pcm_substream *substream)
1142 struct via_spec *spec = codec->spec;
1143 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1146 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1147 struct hda_codec *codec,
1148 unsigned int stream_tag,
1149 unsigned int format,
1150 struct snd_pcm_substream *substream)
1152 struct via_spec *spec = codec->spec;
1153 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1154 stream_tag, format, substream);
1157 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1158 struct hda_codec *codec,
1159 struct snd_pcm_substream *substream)
1161 struct via_spec *spec = codec->spec;
1162 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1169 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1170 struct hda_codec *codec,
1171 unsigned int stream_tag,
1172 unsigned int format,
1173 struct snd_pcm_substream *substream)
1175 struct via_spec *spec = codec->spec;
1177 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1178 stream_tag, 0, format);
1182 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1183 struct hda_codec *codec,
1184 struct snd_pcm_substream *substream)
1186 struct via_spec *spec = codec->spec;
1187 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1191 /* analog capture with dynamic ADC switching */
1192 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1193 struct hda_codec *codec,
1194 unsigned int stream_tag,
1195 unsigned int format,
1196 struct snd_pcm_substream *substream)
1198 struct via_spec *spec = codec->spec;
1199 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1201 spec->cur_adc = spec->adc_nids[adc_idx];
1202 spec->cur_adc_stream_tag = stream_tag;
1203 spec->cur_adc_format = format;
1204 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1208 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1209 struct hda_codec *codec,
1210 struct snd_pcm_substream *substream)
1212 struct via_spec *spec = codec->spec;
1214 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1219 /* re-setup the stream if running; called from input-src put */
1220 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1222 struct via_spec *spec = codec->spec;
1223 int adc_idx = spec->inputs[cur].adc_idx;
1224 hda_nid_t adc = spec->adc_nids[adc_idx];
1226 if (spec->cur_adc && spec->cur_adc != adc) {
1227 /* stream is running, let's swap the current ADC */
1228 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1229 spec->cur_adc = adc;
1230 snd_hda_codec_setup_stream(codec, adc,
1231 spec->cur_adc_stream_tag, 0,
1232 spec->cur_adc_format);
1238 static const struct hda_pcm_stream via_pcm_analog_playback = {
1242 /* NID is set in via_build_pcms */
1244 .open = via_playback_multi_pcm_open,
1245 .close = via_playback_multi_pcm_close,
1246 .prepare = via_playback_multi_pcm_prepare,
1247 .cleanup = via_playback_multi_pcm_cleanup
1251 static const struct hda_pcm_stream via_pcm_hp_playback = {
1255 /* NID is set in via_build_pcms */
1257 .open = via_playback_hp_pcm_open,
1258 .close = via_playback_hp_pcm_close,
1259 .prepare = via_playback_hp_pcm_prepare,
1260 .cleanup = via_playback_hp_pcm_cleanup
1264 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1268 /* NID is set in via_build_pcms */
1269 /* We got noisy outputs on the right channel on VT1708 when
1270 * 24bit samples are used. Until any workaround is found,
1271 * disable the 24bit format, so far.
1273 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1275 .open = via_playback_multi_pcm_open,
1276 .close = via_playback_multi_pcm_close,
1277 .prepare = via_playback_multi_pcm_prepare,
1278 .cleanup = via_playback_multi_pcm_cleanup
1282 static const struct hda_pcm_stream via_pcm_analog_capture = {
1283 .substreams = 1, /* will be changed in via_build_pcms() */
1286 /* NID is set in via_build_pcms */
1288 .prepare = via_capture_pcm_prepare,
1289 .cleanup = via_capture_pcm_cleanup
1293 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1297 /* NID is set in via_build_pcms */
1299 .prepare = via_dyn_adc_capture_pcm_prepare,
1300 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1304 static const struct hda_pcm_stream via_pcm_digital_playback = {
1308 /* NID is set in via_build_pcms */
1310 .open = via_dig_playback_pcm_open,
1311 .close = via_dig_playback_pcm_close,
1312 .prepare = via_dig_playback_pcm_prepare,
1313 .cleanup = via_dig_playback_pcm_cleanup
1317 static const struct hda_pcm_stream via_pcm_digital_capture = {
1324 * slave controls for virtual master
1326 static const char * const via_slave_vols[] = {
1327 "Front Playback Volume",
1328 "Surround Playback Volume",
1329 "Center Playback Volume",
1330 "LFE Playback Volume",
1331 "Side Playback Volume",
1332 "Headphone Playback Volume",
1333 "Speaker Playback Volume",
1337 static const char * const via_slave_sws[] = {
1338 "Front Playback Switch",
1339 "Surround Playback Switch",
1340 "Center Playback Switch",
1341 "LFE Playback Switch",
1342 "Side Playback Switch",
1343 "Headphone Playback Switch",
1344 "Speaker Playback Switch",
1348 static int via_build_controls(struct hda_codec *codec)
1350 struct via_spec *spec = codec->spec;
1351 struct snd_kcontrol *kctl;
1354 if (spec->set_widgets_power_state)
1355 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1358 for (i = 0; i < spec->num_mixers; i++) {
1359 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1364 if (spec->multiout.dig_out_nid) {
1365 err = snd_hda_create_spdif_out_ctls(codec,
1366 spec->multiout.dig_out_nid,
1367 spec->multiout.dig_out_nid);
1370 err = snd_hda_create_spdif_share_sw(codec,
1374 spec->multiout.share_spdif = 1;
1376 if (spec->dig_in_nid) {
1377 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1382 /* if we have no master control, let's create it */
1383 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1384 unsigned int vmaster_tlv[4];
1385 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1386 HDA_OUTPUT, vmaster_tlv);
1387 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1388 vmaster_tlv, via_slave_vols);
1392 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1393 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1394 NULL, via_slave_sws);
1399 /* assign Capture Source enums to NID */
1400 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1401 for (i = 0; kctl && i < kctl->count; i++) {
1402 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1407 /* init power states */
1408 set_widgets_power_state(codec);
1409 analog_low_current_mode(codec);
1411 via_free_kctls(codec); /* no longer needed */
1415 static int via_build_pcms(struct hda_codec *codec)
1417 struct via_spec *spec = codec->spec;
1418 struct hda_pcm *info = spec->pcm_rec;
1420 codec->num_pcms = 1;
1421 codec->pcm_info = info;
1423 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1424 "%s Analog", codec->chip_name);
1425 info->name = spec->stream_name_analog;
1427 if (!spec->stream_analog_playback)
1428 spec->stream_analog_playback = &via_pcm_analog_playback;
1429 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1430 *spec->stream_analog_playback;
1431 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1432 spec->multiout.dac_nids[0];
1433 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1434 spec->multiout.max_channels;
1436 if (!spec->stream_analog_capture) {
1437 if (spec->dyn_adc_switch)
1438 spec->stream_analog_capture =
1439 &via_pcm_dyn_adc_analog_capture;
1441 spec->stream_analog_capture = &via_pcm_analog_capture;
1443 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1444 *spec->stream_analog_capture;
1445 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1446 if (!spec->dyn_adc_switch)
1447 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1450 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1453 snprintf(spec->stream_name_digital,
1454 sizeof(spec->stream_name_digital),
1455 "%s Digital", codec->chip_name);
1456 info->name = spec->stream_name_digital;
1457 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1458 if (spec->multiout.dig_out_nid) {
1459 if (!spec->stream_digital_playback)
1460 spec->stream_digital_playback =
1461 &via_pcm_digital_playback;
1462 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1463 *spec->stream_digital_playback;
1464 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1465 spec->multiout.dig_out_nid;
1467 if (spec->dig_in_nid) {
1468 if (!spec->stream_digital_capture)
1469 spec->stream_digital_capture =
1470 &via_pcm_digital_capture;
1471 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1472 *spec->stream_digital_capture;
1473 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1478 if (spec->hp_dac_nid) {
1481 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1482 "%s HP", codec->chip_name);
1483 info->name = spec->stream_name_hp;
1484 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1485 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1491 static void via_free(struct hda_codec *codec)
1493 struct via_spec *spec = codec->spec;
1498 via_free_kctls(codec);
1499 vt1708_stop_hp_work(spec);
1500 kfree(spec->bind_cap_vol);
1501 kfree(spec->bind_cap_sw);
1505 /* mute/unmute outputs */
1506 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1507 hda_nid_t *pins, bool mute)
1510 for (i = 0; i < num_pins; i++)
1511 snd_hda_codec_write(codec, pins[i], 0,
1512 AC_VERB_SET_PIN_WIDGET_CONTROL,
1513 mute ? 0 : PIN_OUT);
1516 /* mute internal speaker if line-out is plugged */
1517 static void via_line_automute(struct hda_codec *codec, int present)
1519 struct via_spec *spec = codec->spec;
1521 if (!spec->autocfg.speaker_outs)
1524 present = snd_hda_jack_detect(codec,
1525 spec->autocfg.line_out_pins[0]);
1526 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1527 spec->autocfg.speaker_pins,
1531 /* mute internal speaker if HP is plugged */
1532 static void via_hp_automute(struct hda_codec *codec)
1535 struct via_spec *spec = codec->spec;
1537 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) {
1539 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1540 if (spec->smart51_enabled)
1541 nums = spec->autocfg.line_outs + spec->smart51_nums;
1543 nums = spec->autocfg.line_outs;
1544 toggle_output_mutes(codec, nums,
1545 spec->autocfg.line_out_pins,
1548 via_line_automute(codec, present);
1551 static void via_gpio_control(struct hda_codec *codec)
1553 unsigned int gpio_data;
1554 unsigned int vol_counter;
1556 unsigned int master_vol;
1558 struct via_spec *spec = codec->spec;
1560 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1561 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1563 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1564 0xF84, 0) & 0x3F0000) >> 16;
1566 vol = vol_counter & 0x1F;
1567 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1568 AC_VERB_GET_AMP_GAIN_MUTE,
1571 if (gpio_data == 0x02) {
1572 /* unmute line out */
1573 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1574 AC_VERB_SET_PIN_WIDGET_CONTROL,
1576 if (vol_counter & 0x20) {
1577 /* decrease volume */
1578 if (vol > master_vol)
1580 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1584 /* increase volume */
1585 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1587 ((master_vol+vol) > 0x2A) ? 0x2A :
1590 } else if (!(gpio_data & 0x02)) {
1592 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1593 AC_VERB_SET_PIN_WIDGET_CONTROL,
1598 /* unsolicited event for jack sensing */
1599 static void via_unsol_event(struct hda_codec *codec,
1604 if (res & VIA_JACK_EVENT)
1605 set_widgets_power_state(codec);
1607 res &= ~VIA_JACK_EVENT;
1609 if (res == VIA_HP_EVENT)
1610 via_hp_automute(codec);
1611 else if (res == VIA_GPIO_EVENT)
1612 via_gpio_control(codec);
1613 else if (res == VIA_LINE_EVENT)
1614 via_line_automute(codec, false);
1617 #ifdef SND_HDA_NEEDS_RESUME
1618 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1620 struct via_spec *spec = codec->spec;
1621 vt1708_stop_hp_work(spec);
1626 #ifdef CONFIG_SND_HDA_POWER_SAVE
1627 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1629 struct via_spec *spec = codec->spec;
1630 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1637 static int via_init(struct hda_codec *codec);
1639 static const struct hda_codec_ops via_patch_ops = {
1640 .build_controls = via_build_controls,
1641 .build_pcms = via_build_pcms,
1644 .unsol_event = via_unsol_event,
1645 #ifdef SND_HDA_NEEDS_RESUME
1646 .suspend = via_suspend,
1648 #ifdef CONFIG_SND_HDA_POWER_SAVE
1649 .check_power_status = via_check_power_status,
1653 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1655 struct via_spec *spec = codec->spec;
1658 for (i = 0; i < spec->multiout.num_dacs; i++) {
1659 if (spec->multiout.dac_nids[i] == dac)
1662 if (spec->hp_dac_nid == dac)
1667 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1668 hda_nid_t target_dac, struct nid_path *path,
1669 int depth, int wid_type)
1674 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1675 for (i = 0; i < nums; i++) {
1676 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1678 if (conn[i] == target_dac || is_empty_dac(codec, conn[i]))
1681 if (depth >= MAX_NID_PATH_DEPTH)
1683 for (i = 0; i < nums; i++) {
1685 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1686 if (type == AC_WID_AUD_OUT ||
1687 (wid_type != -1 && type != wid_type))
1689 if (__parse_output_path(codec, conn[i], target_dac,
1690 path, depth + 1, AC_WID_AUD_SEL))
1696 path->path[path->depth] = conn[i];
1697 path->idx[path->depth] = i;
1698 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1699 path->multi[path->depth] = 1;
1704 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1705 hda_nid_t target_dac, struct nid_path *path)
1707 if (__parse_output_path(codec, nid, target_dac, path, 1, -1)) {
1708 path->path[path->depth] = nid;
1715 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1717 struct via_spec *spec = codec->spec;
1718 const struct auto_pin_cfg *cfg = &spec->autocfg;
1722 spec->multiout.dac_nids = spec->private_dac_nids;
1724 for (i = 0; i < cfg->line_outs; i++) {
1725 nid = cfg->line_out_pins[i];
1728 if (parse_output_path(codec, nid, 0, &spec->out_path[i])) {
1729 spec->private_dac_nids[i] = spec->out_path[i].path[0];
1733 spec->multiout.num_dacs = dac_num;
1737 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1738 int chs, bool check_dac, struct nid_path *path)
1740 struct via_spec *spec = codec->spec;
1742 hda_nid_t dac, pin, sel, nid;
1745 dac = check_dac ? path->path[0] : 0;
1746 pin = path->path[path->depth - 1];
1747 sel = path->depth > 1 ? path->path[1] : 0;
1749 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1751 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1753 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1758 sprintf(name, "%s Playback Volume", pfx);
1759 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1760 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1763 path->vol_ctl = nid;
1766 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1768 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1770 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1775 sprintf(name, "%s Playback Switch", pfx);
1776 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1777 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1780 path->mute_ctl = nid;
1785 static void mangle_smart51(struct hda_codec *codec)
1787 struct via_spec *spec = codec->spec;
1788 struct auto_pin_cfg *cfg = &spec->autocfg;
1789 struct auto_pin_cfg_item *ins = cfg->inputs;
1790 int i, j, nums, attr;
1791 int pins[AUTO_CFG_MAX_INS];
1793 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1795 for (i = 0; i < cfg->num_inputs; i++) {
1797 if (ins[i].type > AUTO_PIN_LINE_IN)
1799 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1800 if (snd_hda_get_input_pin_attr(def) != attr)
1802 for (j = 0; j < nums; j++)
1803 if (ins[pins[j]].type < ins[i].type) {
1804 memmove(pins + j + 1, pins + j,
1805 (nums - j) * sizeof(int));
1811 if (cfg->line_outs + nums < 3)
1813 for (i = 0; i < nums; i++) {
1814 hda_nid_t pin = ins[pins[i]].pin;
1815 spec->smart51_pins[spec->smart51_nums++] = pin;
1816 cfg->line_out_pins[cfg->line_outs++] = pin;
1817 if (cfg->line_outs == 3)
1824 /* add playback controls from the parsed DAC table */
1825 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1827 struct via_spec *spec = codec->spec;
1828 struct auto_pin_cfg *cfg = &spec->autocfg;
1829 static const char * const chname[4] = {
1830 "Front", "Surround", "C/LFE", "Side"
1836 old_line_outs = cfg->line_outs;
1837 if (cfg->line_outs == 1)
1838 mangle_smart51(codec);
1840 err = via_auto_fill_dac_nids(codec);
1844 if (spec->multiout.num_dacs < 3) {
1845 spec->smart51_nums = 0;
1846 cfg->line_outs = old_line_outs;
1848 for (i = 0; i < cfg->line_outs; i++) {
1850 pin = cfg->line_out_pins[i];
1851 dac = spec->multiout.dac_nids[i];
1854 if (i == HDA_CLFE) {
1855 err = create_ch_ctls(codec, "Center", 1, true,
1856 &spec->out_path[i]);
1859 err = create_ch_ctls(codec, "LFE", 2, true,
1860 &spec->out_path[i]);
1864 const char *pfx = chname[i];
1865 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1866 cfg->line_outs == 1)
1868 err = create_ch_ctls(codec, pfx, 3, true,
1869 &spec->out_path[i]);
1875 idx = get_connection_index(codec, spec->aa_mix_nid,
1876 spec->multiout.dac_nids[0]);
1877 if (idx < 0 && spec->dac_mixer_idx)
1878 idx = spec->dac_mixer_idx;
1880 /* add control to mixer */
1881 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1882 "PCM Playback Volume",
1883 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1887 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1888 "PCM Playback Switch",
1889 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1895 cfg->line_outs = old_line_outs;
1900 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1902 struct via_spec *spec = codec->spec;
1903 struct nid_path *path;
1910 if (parse_output_path(codec, pin, 0, &spec->hp_path))
1911 spec->hp_dac_nid = spec->hp_path.path[0];
1912 else if (spec->multiout.dac_nids[HDA_SIDE] &&
1913 parse_output_path(codec, pin,
1914 spec->multiout.dac_nids[HDA_SIDE],
1916 spec->hp_dac_nid = spec->hp_path.path[0];
1917 spec->hp_indep_shared = true;
1918 } else if (spec->multiout.dac_nids[HDA_CLFE] &&
1919 parse_output_path(codec, pin,
1920 spec->multiout.dac_nids[HDA_CLFE],
1922 spec->hp_dac_nid = spec->hp_path.path[0];
1923 spec->hp_indep_shared = true;
1926 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1927 &spec->hp_dep_path) &&
1931 if (spec->hp_dac_nid && !spec->hp_indep_shared) {
1932 path = &spec->hp_path;
1935 path = &spec->hp_dep_path;
1938 err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
1941 if (spec->hp_dac_nid) {
1942 spec->hp_dep_path.vol_ctl = spec->hp_path.vol_ctl;
1943 spec->hp_dep_path.mute_ctl = spec->hp_path.mute_ctl;
1949 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1951 struct via_spec *spec = codec->spec;
1954 pin = spec->autocfg.speaker_pins[0];
1955 if (!spec->autocfg.speaker_outs || !pin)
1958 if (parse_output_path(codec, pin, 0, &spec->speaker_path)) {
1959 dac = spec->speaker_path.path[0];
1960 spec->multiout.extra_out_nid[0] = dac;
1961 return create_ch_ctls(codec, "Speaker", 3, true,
1962 &spec->speaker_path);
1964 if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1965 &spec->speaker_path))
1966 return create_ch_ctls(codec, "Speaker", 3, false,
1967 &spec->speaker_path);
1973 static int via_fill_adcs(struct hda_codec *codec)
1975 struct via_spec *spec = codec->spec;
1976 hda_nid_t nid = codec->start_nid;
1979 for (i = 0; i < codec->num_nodes; i++, nid++) {
1980 unsigned int wcaps = get_wcaps(codec, nid);
1981 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1983 if (wcaps & AC_WCAP_DIGITAL)
1985 if (!(wcaps & AC_WCAP_CONN_LIST))
1987 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1989 spec->adc_nids[spec->num_adc_nids++] = nid;
1994 /* input-src control */
1995 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1996 struct snd_ctl_elem_info *uinfo)
1998 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1999 struct via_spec *spec = codec->spec;
2001 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2003 uinfo->value.enumerated.items = spec->num_inputs;
2004 if (uinfo->value.enumerated.item >= spec->num_inputs)
2005 uinfo->value.enumerated.item = spec->num_inputs - 1;
2006 strcpy(uinfo->value.enumerated.name,
2007 spec->inputs[uinfo->value.enumerated.item].label);
2011 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
2012 struct snd_ctl_elem_value *ucontrol)
2014 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2015 struct via_spec *spec = codec->spec;
2016 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2018 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
2022 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
2023 struct snd_ctl_elem_value *ucontrol)
2025 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2026 struct via_spec *spec = codec->spec;
2027 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2031 cur = ucontrol->value.enumerated.item[0];
2032 if (cur < 0 || cur >= spec->num_inputs)
2034 if (spec->cur_mux[idx] == cur)
2036 spec->cur_mux[idx] = cur;
2037 if (spec->dyn_adc_switch) {
2038 int adc_idx = spec->inputs[cur].adc_idx;
2039 mux = spec->mux_nids[adc_idx];
2040 via_dyn_adc_pcm_resetup(codec, cur);
2042 mux = spec->mux_nids[idx];
2043 if (snd_BUG_ON(!mux))
2048 /* switch to D0 beofre change index */
2049 if (snd_hda_codec_read(codec, mux, 0,
2050 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
2051 snd_hda_codec_write(codec, mux, 0,
2052 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2053 snd_hda_codec_write(codec, mux, 0,
2054 AC_VERB_SET_CONNECT_SEL,
2055 spec->inputs[cur].mux_idx);
2058 /* update jack power state */
2059 set_widgets_power_state(codec);
2063 static const struct snd_kcontrol_new via_input_src_ctl = {
2064 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2065 /* The multiple "Capture Source" controls confuse alsamixer
2066 * So call somewhat different..
2068 /* .name = "Capture Source", */
2069 .name = "Input Source",
2070 .info = via_mux_enum_info,
2071 .get = via_mux_enum_get,
2072 .put = via_mux_enum_put,
2075 static int create_input_src_ctls(struct hda_codec *codec, int count)
2077 struct via_spec *spec = codec->spec;
2078 struct snd_kcontrol_new *knew;
2080 if (spec->num_inputs <= 1 || !count)
2081 return 0; /* no need for single src */
2083 knew = via_clone_control(spec, &via_input_src_ctl);
2086 knew->count = count;
2090 /* add the powersave loopback-list entry */
2091 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2093 struct hda_amp_list *list;
2095 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2097 list = spec->loopback_list + spec->num_loopbacks;
2099 list->dir = HDA_INPUT;
2101 spec->num_loopbacks++;
2102 spec->loopback.amplist = spec->loopback_list;
2105 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2108 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2111 /* add the input-route to the given pin */
2112 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2114 struct via_spec *spec = codec->spec;
2117 spec->inputs[spec->num_inputs].adc_idx = -1;
2118 spec->inputs[spec->num_inputs].pin = pin;
2119 for (c = 0; c < spec->num_adc_nids; c++) {
2120 if (spec->mux_nids[c]) {
2121 idx = get_connection_index(codec, spec->mux_nids[c],
2125 spec->inputs[spec->num_inputs].mux_idx = idx;
2127 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2130 spec->inputs[spec->num_inputs].adc_idx = c;
2131 /* Can primary ADC satisfy all inputs? */
2132 if (!spec->dyn_adc_switch &&
2133 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2134 snd_printd(KERN_INFO
2135 "via: dynamic ADC switching enabled\n");
2136 spec->dyn_adc_switch = 1;
2143 static int get_mux_nids(struct hda_codec *codec);
2145 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2146 static int parse_analog_inputs(struct hda_codec *codec)
2148 struct via_spec *spec = codec->spec;
2149 const struct auto_pin_cfg *cfg = &spec->autocfg;
2152 err = via_fill_adcs(codec);
2155 err = get_mux_nids(codec);
2159 /* fill all input-routes */
2160 for (i = 0; i < cfg->num_inputs; i++) {
2161 if (add_input_route(codec, cfg->inputs[i].pin))
2162 spec->inputs[spec->num_inputs++].label =
2163 hda_get_autocfg_input_label(codec, cfg, i);
2166 /* check for internal loopback recording */
2167 if (spec->aa_mix_nid &&
2168 add_input_route(codec, spec->aa_mix_nid))
2169 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2174 /* create analog-loopback volume/switch controls */
2175 static int create_loopback_ctls(struct hda_codec *codec)
2177 struct via_spec *spec = codec->spec;
2178 const struct auto_pin_cfg *cfg = &spec->autocfg;
2179 const char *prev_label = NULL;
2183 if (!spec->aa_mix_nid)
2186 for (i = 0; i < cfg->num_inputs; i++) {
2187 hda_nid_t pin = cfg->inputs[i].pin;
2188 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2190 if (prev_label && !strcmp(label, prev_label))
2195 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2197 err = via_new_analog_input(spec, label, type_idx,
2198 idx, spec->aa_mix_nid);
2201 add_loopback_list(spec, spec->aa_mix_nid, idx);
2204 /* remember the label for smart51 control */
2205 for (j = 0; j < spec->smart51_nums; j++) {
2206 if (spec->smart51_pins[j] == pin) {
2207 spec->smart51_idxs[j] = idx;
2208 spec->smart51_labels[j] = label;
2216 /* create mic-boost controls (if present) */
2217 static int create_mic_boost_ctls(struct hda_codec *codec)
2219 struct via_spec *spec = codec->spec;
2220 const struct auto_pin_cfg *cfg = &spec->autocfg;
2223 for (i = 0; i < cfg->num_inputs; i++) {
2224 hda_nid_t pin = cfg->inputs[i].pin;
2229 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2231 caps = query_amp_caps(codec, pin, HDA_INPUT);
2232 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2234 label = hda_get_autocfg_input_label(codec, cfg, i);
2235 snprintf(name, sizeof(name), "%s Boost Volume", label);
2236 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2237 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2244 /* create capture and input-src controls for multiple streams */
2245 static int create_multi_adc_ctls(struct hda_codec *codec)
2247 struct via_spec *spec = codec->spec;
2250 /* create capture mixer elements */
2251 for (i = 0; i < spec->num_adc_nids; i++) {
2252 hda_nid_t adc = spec->adc_nids[i];
2253 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2254 "Capture Volume", i,
2255 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2259 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2260 "Capture Switch", i,
2261 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2267 /* input-source control */
2268 for (i = 0; i < spec->num_adc_nids; i++)
2269 if (!spec->mux_nids[i])
2271 err = create_input_src_ctls(codec, i);
2277 /* bind capture volume/switch */
2278 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2279 HDA_BIND_VOL("Capture Volume", 0);
2280 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2281 HDA_BIND_SW("Capture Switch", 0);
2283 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2284 struct hda_ctl_ops *ops)
2286 struct hda_bind_ctls *ctl;
2289 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2293 for (i = 0; i < spec->num_adc_nids; i++)
2295 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2300 /* create capture and input-src controls for dynamic ADC-switch case */
2301 static int create_dyn_adc_ctls(struct hda_codec *codec)
2303 struct via_spec *spec = codec->spec;
2304 struct snd_kcontrol_new *knew;
2307 /* set up the bind capture ctls */
2308 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2311 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2315 /* create capture mixer elements */
2316 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2319 knew->private_value = (long)spec->bind_cap_vol;
2321 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2324 knew->private_value = (long)spec->bind_cap_sw;
2326 /* input-source control */
2327 err = create_input_src_ctls(codec, 1);
2333 /* parse and create capture-related stuff */
2334 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2336 struct via_spec *spec = codec->spec;
2339 err = parse_analog_inputs(codec);
2342 if (spec->dyn_adc_switch)
2343 err = create_dyn_adc_ctls(codec);
2345 err = create_multi_adc_ctls(codec);
2348 err = create_loopback_ctls(codec);
2351 err = create_mic_boost_ctls(codec);
2357 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2359 unsigned int def_conf;
2360 unsigned char seqassoc;
2362 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2363 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2364 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2365 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2366 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2367 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2368 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2374 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2375 struct snd_ctl_elem_value *ucontrol)
2377 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2378 struct via_spec *spec = codec->spec;
2380 if (spec->codec_type != VT1708)
2382 spec->vt1708_jack_detect =
2383 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2384 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2388 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2389 struct snd_ctl_elem_value *ucontrol)
2391 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2392 struct via_spec *spec = codec->spec;
2395 if (spec->codec_type != VT1708)
2397 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2398 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2399 == !spec->vt1708_jack_detect;
2400 if (spec->vt1708_jack_detect) {
2401 mute_aa_path(codec, 1);
2402 notify_aa_path_ctls(codec);
2407 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2408 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2409 .name = "Jack Detect",
2411 .info = snd_ctl_boolean_mono_info,
2412 .get = vt1708_jack_detect_get,
2413 .put = vt1708_jack_detect_put,
2416 static void fill_dig_outs(struct hda_codec *codec);
2417 static void fill_dig_in(struct hda_codec *codec);
2419 static int via_parse_auto_config(struct hda_codec *codec)
2421 struct via_spec *spec = codec->spec;
2424 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2427 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2430 err = via_auto_create_multi_out_ctls(codec);
2433 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2436 err = via_auto_create_speaker_ctls(codec);
2439 err = via_auto_create_analog_input_ctls(codec);
2443 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2445 fill_dig_outs(codec);
2448 if (spec->kctls.list)
2449 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2452 if (spec->hp_dac_nid && spec->hp_dep_path.depth) {
2453 err = via_hp_build(codec);
2458 err = via_smart51_build(codec);
2462 /* assign slave outs */
2463 if (spec->slave_dig_outs[0])
2464 codec->slave_dig_outs = spec->slave_dig_outs;
2469 static void via_auto_init_dig_outs(struct hda_codec *codec)
2471 struct via_spec *spec = codec->spec;
2472 if (spec->multiout.dig_out_nid)
2473 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2474 if (spec->slave_dig_outs[0])
2475 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2478 static void via_auto_init_dig_in(struct hda_codec *codec)
2480 struct via_spec *spec = codec->spec;
2481 if (!spec->dig_in_nid)
2483 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2484 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2487 /* initialize the unsolicited events */
2488 static void via_auto_init_unsol_event(struct hda_codec *codec)
2490 struct via_spec *spec = codec->spec;
2491 struct auto_pin_cfg *cfg = &spec->autocfg;
2495 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2496 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2497 AC_VERB_SET_UNSOLICITED_ENABLE,
2498 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2500 if (cfg->speaker_pins[0])
2501 ev = VIA_LINE_EVENT;
2504 for (i = 0; i < cfg->line_outs; i++) {
2505 if (cfg->line_out_pins[i] &&
2506 is_jack_detectable(codec, cfg->line_out_pins[i]))
2507 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
2508 AC_VERB_SET_UNSOLICITED_ENABLE,
2509 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2512 for (i = 0; i < cfg->num_inputs; i++) {
2513 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2514 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2515 AC_VERB_SET_UNSOLICITED_ENABLE,
2516 AC_USRSP_EN | VIA_JACK_EVENT);
2520 static int via_init(struct hda_codec *codec)
2522 struct via_spec *spec = codec->spec;
2525 for (i = 0; i < spec->num_iverbs; i++)
2526 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2528 via_auto_init_multi_out(codec);
2529 via_auto_init_hp_out(codec);
2530 via_auto_init_speaker_out(codec);
2531 via_auto_init_analog_input(codec);
2532 via_auto_init_dig_outs(codec);
2533 via_auto_init_dig_in(codec);
2535 via_auto_init_unsol_event(codec);
2537 via_hp_automute(codec);
2538 via_line_automute(codec, false);
2543 static void vt1708_update_hp_jack_state(struct work_struct *work)
2545 struct via_spec *spec = container_of(work, struct via_spec,
2546 vt1708_hp_work.work);
2547 if (spec->codec_type != VT1708)
2549 /* if jack state toggled */
2550 if (spec->vt1708_hp_present
2551 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2552 spec->vt1708_hp_present ^= 1;
2553 via_hp_automute(spec->codec);
2555 vt1708_start_hp_work(spec);
2558 static int get_mux_nids(struct hda_codec *codec)
2560 struct via_spec *spec = codec->spec;
2561 hda_nid_t nid, conn[8];
2565 for (i = 0; i < spec->num_adc_nids; i++) {
2566 nid = spec->adc_nids[i];
2568 type = get_wcaps_type(get_wcaps(codec, nid));
2569 if (type == AC_WID_PIN)
2571 n = snd_hda_get_connections(codec, nid, conn,
2576 spec->mux_nids[i] = nid;
2585 static int patch_vt1708(struct hda_codec *codec)
2587 struct via_spec *spec;
2590 /* create a codec specific record */
2591 spec = via_new_spec(codec);
2595 spec->aa_mix_nid = 0x17;
2597 /* Add HP and CD pin config connect bit re-config action */
2598 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2599 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2601 /* automatic parse from the BIOS config */
2602 err = via_parse_auto_config(codec);
2608 /* add jack detect on/off control */
2609 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2612 /* disable 32bit format on VT1708 */
2613 if (codec->vendor_id == 0x11061708)
2614 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2616 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2618 codec->patch_ops = via_patch_ops;
2620 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2624 static int patch_vt1709(struct hda_codec *codec)
2626 struct via_spec *spec;
2629 /* create a codec specific record */
2630 spec = via_new_spec(codec);
2634 spec->aa_mix_nid = 0x18;
2636 err = via_parse_auto_config(codec);
2642 codec->patch_ops = via_patch_ops;
2647 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2649 struct via_spec *spec = codec->spec;
2653 if ((spec->codec_type != VT1708B_4CH) &&
2654 (codec->vendor_id != 0x11064397))
2657 /* SW0 (17h) = stereo mixer */
2659 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2660 == ((spec->codec_type == VT1708S) ? 5 : 0));
2662 /* PW 1/2/5 (1ah/1bh/1eh) */
2664 set_pin_power_state(codec, 0x1a, &parm);
2665 set_pin_power_state(codec, 0x1b, &parm);
2666 set_pin_power_state(codec, 0x1e, &parm);
2669 /* SW0 (17h), AIW 0/1 (13h/14h) */
2670 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2671 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2672 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2675 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2677 set_pin_power_state(codec, 0x19, &parm);
2678 if (spec->smart51_enabled)
2679 set_pin_power_state(codec, 0x1b, &parm);
2680 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2681 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2683 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2686 set_pin_power_state(codec, 0x22, &parm);
2687 if (spec->smart51_enabled)
2688 set_pin_power_state(codec, 0x1a, &parm);
2689 snd_hda_codec_write(codec, 0x26, 0,
2690 AC_VERB_SET_POWER_STATE, parm);
2691 snd_hda_codec_write(codec, 0x24, 0,
2692 AC_VERB_SET_POWER_STATE, parm);
2693 } else if (codec->vendor_id == 0x11064397) {
2694 /* PW7(23h), SW2(27h), AOW2(25h) */
2696 set_pin_power_state(codec, 0x23, &parm);
2697 if (spec->smart51_enabled)
2698 set_pin_power_state(codec, 0x1a, &parm);
2699 snd_hda_codec_write(codec, 0x27, 0,
2700 AC_VERB_SET_POWER_STATE, parm);
2701 snd_hda_codec_write(codec, 0x25, 0,
2702 AC_VERB_SET_POWER_STATE, parm);
2705 /* PW 3/4/7 (1ch/1dh/23h) */
2707 /* force to D0 for internal Speaker */
2708 set_pin_power_state(codec, 0x1c, &parm);
2709 set_pin_power_state(codec, 0x1d, &parm);
2711 set_pin_power_state(codec, 0x23, &parm);
2713 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2714 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2715 imux_is_smixer ? AC_PWRST_D0 : parm);
2716 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2718 snd_hda_codec_write(codec, 0x25, 0,
2719 AC_VERB_SET_POWER_STATE, parm);
2720 snd_hda_codec_write(codec, 0x27, 0,
2721 AC_VERB_SET_POWER_STATE, parm);
2722 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2723 snd_hda_codec_write(codec, 0x25, 0,
2724 AC_VERB_SET_POWER_STATE, parm);
2727 static int patch_vt1708S(struct hda_codec *codec);
2728 static int patch_vt1708B(struct hda_codec *codec)
2730 struct via_spec *spec;
2733 if (get_codec_type(codec) == VT1708BCE)
2734 return patch_vt1708S(codec);
2736 /* create a codec specific record */
2737 spec = via_new_spec(codec);
2741 spec->aa_mix_nid = 0x16;
2743 /* automatic parse from the BIOS config */
2744 err = via_parse_auto_config(codec);
2750 codec->patch_ops = via_patch_ops;
2752 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2757 /* Patch for VT1708S */
2758 static const struct hda_verb vt1708S_init_verbs[] = {
2759 /* Enable Mic Boost Volume backdoor */
2761 /* don't bybass mixer */
2766 /* fill out digital output widgets; one for master and one for slave outputs */
2767 static void fill_dig_outs(struct hda_codec *codec)
2769 struct via_spec *spec = codec->spec;
2772 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2776 nid = spec->autocfg.dig_out_pins[i];
2779 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2782 if (!spec->multiout.dig_out_nid)
2783 spec->multiout.dig_out_nid = nid;
2785 spec->slave_dig_outs[0] = nid;
2786 break; /* at most two dig outs */
2791 static void fill_dig_in(struct hda_codec *codec)
2793 struct via_spec *spec = codec->spec;
2797 if (!spec->autocfg.dig_in_pin)
2800 dig_nid = codec->start_nid;
2801 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2802 unsigned int wcaps = get_wcaps(codec, dig_nid);
2803 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2805 if (!(wcaps & AC_WCAP_DIGITAL))
2807 if (!(wcaps & AC_WCAP_CONN_LIST))
2809 err = get_connection_index(codec, dig_nid,
2810 spec->autocfg.dig_in_pin);
2812 spec->dig_in_nid = dig_nid;
2818 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2819 int offset, int num_steps, int step_size)
2821 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2822 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2823 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2824 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2825 (0 << AC_AMPCAP_MUTE_SHIFT));
2828 static int patch_vt1708S(struct hda_codec *codec)
2830 struct via_spec *spec;
2833 /* create a codec specific record */
2834 spec = via_new_spec(codec);
2838 spec->aa_mix_nid = 0x16;
2839 override_mic_boost(codec, 0x1a, 0, 3, 40);
2840 override_mic_boost(codec, 0x1e, 0, 3, 40);
2842 /* automatic parse from the BIOS config */
2843 err = via_parse_auto_config(codec);
2849 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2851 codec->patch_ops = via_patch_ops;
2853 /* correct names for VT1708BCE */
2854 if (get_codec_type(codec) == VT1708BCE) {
2855 kfree(codec->chip_name);
2856 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2857 snprintf(codec->bus->card->mixername,
2858 sizeof(codec->bus->card->mixername),
2859 "%s %s", codec->vendor_name, codec->chip_name);
2861 /* correct names for VT1705 */
2862 if (codec->vendor_id == 0x11064397) {
2863 kfree(codec->chip_name);
2864 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2865 snprintf(codec->bus->card->mixername,
2866 sizeof(codec->bus->card->mixername),
2867 "%s %s", codec->vendor_name, codec->chip_name);
2869 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2873 /* Patch for VT1702 */
2875 static const struct hda_verb vt1702_init_verbs[] = {
2883 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2885 int imux_is_smixer =
2886 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2889 /* PW 1/2/5 (14h/15h/18h) */
2891 set_pin_power_state(codec, 0x14, &parm);
2892 set_pin_power_state(codec, 0x15, &parm);
2893 set_pin_power_state(codec, 0x18, &parm);
2895 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2896 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2897 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2898 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2899 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2900 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2903 /* PW 3/4 (16h/17h) */
2905 set_pin_power_state(codec, 0x17, &parm);
2906 set_pin_power_state(codec, 0x16, &parm);
2907 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2908 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2909 imux_is_smixer ? AC_PWRST_D0 : parm);
2910 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2911 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2914 static int patch_vt1702(struct hda_codec *codec)
2916 struct via_spec *spec;
2919 /* create a codec specific record */
2920 spec = via_new_spec(codec);
2924 spec->aa_mix_nid = 0x1a;
2926 /* limit AA path volume to 0 dB */
2927 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2928 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2929 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2930 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2931 (1 << AC_AMPCAP_MUTE_SHIFT));
2933 /* automatic parse from the BIOS config */
2934 err = via_parse_auto_config(codec);
2940 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
2942 codec->patch_ops = via_patch_ops;
2944 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
2948 /* Patch for VT1718S */
2950 static const struct hda_verb vt1718S_init_verbs[] = {
2951 /* Enable MW0 adjust Gain 5 */
2953 /* Enable Boost Volume backdoor */
2959 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2961 struct via_spec *spec = codec->spec;
2964 /* MUX6 (1eh) = stereo mixer */
2966 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2968 /* PW 5/6/7 (29h/2ah/2bh) */
2970 set_pin_power_state(codec, 0x29, &parm);
2971 set_pin_power_state(codec, 0x2a, &parm);
2972 set_pin_power_state(codec, 0x2b, &parm);
2975 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2976 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2977 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2978 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2979 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2982 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2984 set_pin_power_state(codec, 0x27, &parm);
2985 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2986 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2988 /* PW2 (26h), AOW2 (ah) */
2990 set_pin_power_state(codec, 0x26, &parm);
2991 if (spec->smart51_enabled)
2992 set_pin_power_state(codec, 0x2b, &parm);
2993 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
2995 /* PW0 (24h), AOW0 (8h) */
2997 set_pin_power_state(codec, 0x24, &parm);
2998 if (!spec->hp_independent_mode) /* check for redirected HP */
2999 set_pin_power_state(codec, 0x28, &parm);
3000 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3001 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
3002 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
3003 imux_is_smixer ? AC_PWRST_D0 : parm);
3005 /* PW1 (25h), AOW1 (9h) */
3007 set_pin_power_state(codec, 0x25, &parm);
3008 if (spec->smart51_enabled)
3009 set_pin_power_state(codec, 0x2a, &parm);
3010 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
3012 if (spec->hp_independent_mode) {
3013 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
3015 set_pin_power_state(codec, 0x28, &parm);
3016 snd_hda_codec_write(codec, 0x1b, 0,
3017 AC_VERB_SET_POWER_STATE, parm);
3018 snd_hda_codec_write(codec, 0x34, 0,
3019 AC_VERB_SET_POWER_STATE, parm);
3020 snd_hda_codec_write(codec, 0xc, 0,
3021 AC_VERB_SET_POWER_STATE, parm);
3025 static int patch_vt1718S(struct hda_codec *codec)
3027 struct via_spec *spec;
3030 /* create a codec specific record */
3031 spec = via_new_spec(codec);
3035 spec->aa_mix_nid = 0x21;
3036 override_mic_boost(codec, 0x2b, 0, 3, 40);
3037 override_mic_boost(codec, 0x29, 0, 3, 40);
3038 spec->dac_mixer_idx = 5;
3040 /* automatic parse from the BIOS config */
3041 err = via_parse_auto_config(codec);
3047 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
3049 codec->patch_ops = via_patch_ops;
3051 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
3056 /* Patch for VT1716S */
3058 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
3059 struct snd_ctl_elem_info *uinfo)
3061 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
3063 uinfo->value.integer.min = 0;
3064 uinfo->value.integer.max = 1;
3068 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
3069 struct snd_ctl_elem_value *ucontrol)
3071 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3074 index = snd_hda_codec_read(codec, 0x26, 0,
3075 AC_VERB_GET_CONNECT_SEL, 0);
3077 *ucontrol->value.integer.value = index;
3082 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3083 struct snd_ctl_elem_value *ucontrol)
3085 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3086 struct via_spec *spec = codec->spec;
3087 int index = *ucontrol->value.integer.value;
3089 snd_hda_codec_write(codec, 0x26, 0,
3090 AC_VERB_SET_CONNECT_SEL, index);
3091 spec->dmic_enabled = index;
3092 set_widgets_power_state(codec);
3096 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3097 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3099 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3100 .name = "Digital Mic Capture Switch",
3101 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3103 .info = vt1716s_dmic_info,
3104 .get = vt1716s_dmic_get,
3105 .put = vt1716s_dmic_put,
3111 /* mono-out mixer elements */
3112 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3113 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3117 static const struct hda_verb vt1716S_init_verbs[] = {
3118 /* Enable Boost Volume backdoor */
3120 /* don't bybass mixer */
3122 /* Enable mono output */
3127 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3129 struct via_spec *spec = codec->spec;
3132 unsigned int mono_out, present;
3133 /* SW0 (17h) = stereo mixer */
3135 (snd_hda_codec_read(codec, 0x17, 0,
3136 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3138 /* PW 1/2/5 (1ah/1bh/1eh) */
3140 set_pin_power_state(codec, 0x1a, &parm);
3141 set_pin_power_state(codec, 0x1b, &parm);
3142 set_pin_power_state(codec, 0x1e, &parm);
3145 /* SW0 (17h), AIW0(13h) */
3146 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3147 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3150 set_pin_power_state(codec, 0x1e, &parm);
3152 if (spec->dmic_enabled)
3153 set_pin_power_state(codec, 0x22, &parm);
3155 snd_hda_codec_write(codec, 0x22, 0,
3156 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3158 /* SW2(26h), AIW1(14h) */
3159 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3160 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3163 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3165 set_pin_power_state(codec, 0x19, &parm);
3166 /* Smart 5.1 PW2(1bh) */
3167 if (spec->smart51_enabled)
3168 set_pin_power_state(codec, 0x1b, &parm);
3169 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3170 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3172 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3174 set_pin_power_state(codec, 0x23, &parm);
3175 /* Smart 5.1 PW1(1ah) */
3176 if (spec->smart51_enabled)
3177 set_pin_power_state(codec, 0x1a, &parm);
3178 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3180 /* Smart 5.1 PW5(1eh) */
3181 if (spec->smart51_enabled)
3182 set_pin_power_state(codec, 0x1e, &parm);
3183 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3186 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3187 present = snd_hda_jack_detect(codec, 0x1c);
3192 present = snd_hda_jack_detect(codec, 0x1d);
3193 if (!spec->hp_independent_mode && present)
3198 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3199 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3200 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3201 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3203 /* PW 3/4 (1ch/1dh) */
3205 set_pin_power_state(codec, 0x1c, &parm);
3206 set_pin_power_state(codec, 0x1d, &parm);
3207 /* HP Independent Mode, power on AOW3 */
3208 if (spec->hp_independent_mode)
3209 snd_hda_codec_write(codec, 0x25, 0,
3210 AC_VERB_SET_POWER_STATE, parm);
3212 /* force to D0 for internal Speaker */
3213 /* MW0 (16h), AOW0 (10h) */
3214 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3215 imux_is_smixer ? AC_PWRST_D0 : parm);
3216 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3217 mono_out ? AC_PWRST_D0 : parm);
3220 static int patch_vt1716S(struct hda_codec *codec)
3222 struct via_spec *spec;
3225 /* create a codec specific record */
3226 spec = via_new_spec(codec);
3230 spec->aa_mix_nid = 0x16;
3231 override_mic_boost(codec, 0x1a, 0, 3, 40);
3232 override_mic_boost(codec, 0x1e, 0, 3, 40);
3234 /* automatic parse from the BIOS config */
3235 err = via_parse_auto_config(codec);
3241 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3243 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3246 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3248 codec->patch_ops = via_patch_ops;
3250 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3256 static const struct hda_verb vt2002P_init_verbs[] = {
3257 /* Class-D speaker related verbs */
3261 /* Enable Boost Volume backdoor */
3263 /* Enable AOW0 to MW9 */
3268 static const struct hda_verb vt1802_init_verbs[] = {
3269 /* Enable Boost Volume backdoor */
3271 /* Enable AOW0 to MW9 */
3276 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3278 struct via_spec *spec = codec->spec;
3281 unsigned int present;
3282 /* MUX9 (1eh) = stereo mixer */
3284 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3286 /* PW 5/6/7 (29h/2ah/2bh) */
3288 set_pin_power_state(codec, 0x29, &parm);
3289 set_pin_power_state(codec, 0x2a, &parm);
3290 set_pin_power_state(codec, 0x2b, &parm);
3292 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3293 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3294 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3295 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3296 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3300 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3302 if (spec->codec_type == VT1802) {
3303 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3305 set_pin_power_state(codec, 0x28, &parm);
3306 snd_hda_codec_write(codec, 0x18, 0,
3307 AC_VERB_SET_POWER_STATE, parm);
3308 snd_hda_codec_write(codec, 0x38, 0,
3309 AC_VERB_SET_POWER_STATE, parm);
3311 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3313 set_pin_power_state(codec, 0x26, &parm);
3314 snd_hda_codec_write(codec, 0x1c, 0,
3315 AC_VERB_SET_POWER_STATE, parm);
3316 snd_hda_codec_write(codec, 0x37, 0,
3317 AC_VERB_SET_POWER_STATE, parm);
3320 if (spec->codec_type == VT1802) {
3321 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3323 set_pin_power_state(codec, 0x25, &parm);
3324 snd_hda_codec_write(codec, 0x15, 0,
3325 AC_VERB_SET_POWER_STATE, parm);
3326 snd_hda_codec_write(codec, 0x35, 0,
3327 AC_VERB_SET_POWER_STATE, parm);
3329 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3331 set_pin_power_state(codec, 0x25, &parm);
3332 snd_hda_codec_write(codec, 0x19, 0,
3333 AC_VERB_SET_POWER_STATE, parm);
3334 snd_hda_codec_write(codec, 0x35, 0,
3335 AC_VERB_SET_POWER_STATE, parm);
3338 if (spec->hp_independent_mode)
3339 snd_hda_codec_write(codec, 0x9, 0,
3340 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3343 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3344 present = snd_hda_jack_detect(codec, 0x25);
3347 set_pin_power_state(codec, 0x24, &parm);
3348 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3349 if (spec->codec_type == VT1802)
3350 snd_hda_codec_write(codec, 0x14, 0,
3351 AC_VERB_SET_POWER_STATE, parm);
3353 snd_hda_codec_write(codec, 0x18, 0,
3354 AC_VERB_SET_POWER_STATE, parm);
3355 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3358 present = snd_hda_jack_detect(codec, 0x26);
3360 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3361 if (spec->codec_type == VT1802) {
3362 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3363 snd_hda_codec_write(codec, 0x33, 0,
3364 AC_VERB_SET_POWER_STATE, parm);
3365 snd_hda_codec_write(codec, 0x1c, 0,
3366 AC_VERB_SET_POWER_STATE, parm);
3367 snd_hda_codec_write(codec, 0x3c, 0,
3368 AC_VERB_SET_POWER_STATE, parm);
3370 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3371 snd_hda_codec_write(codec, 0x31, 0,
3372 AC_VERB_SET_POWER_STATE, parm);
3373 snd_hda_codec_write(codec, 0x17, 0,
3374 AC_VERB_SET_POWER_STATE, parm);
3375 snd_hda_codec_write(codec, 0x3b, 0,
3376 AC_VERB_SET_POWER_STATE, parm);
3379 if (imux_is_smixer || !is_aa_path_mute(codec))
3380 snd_hda_codec_write(codec, 0x21, 0,
3381 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3383 snd_hda_codec_write(codec, 0x21, 0,
3384 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3387 /* patch for vt2002P */
3388 static int patch_vt2002P(struct hda_codec *codec)
3390 struct via_spec *spec;
3393 /* create a codec specific record */
3394 spec = via_new_spec(codec);
3398 spec->aa_mix_nid = 0x21;
3399 spec->dac_mixer_idx = 3;
3400 override_mic_boost(codec, 0x2b, 0, 3, 40);
3401 override_mic_boost(codec, 0x29, 0, 3, 40);
3403 /* automatic parse from the BIOS config */
3404 err = via_parse_auto_config(codec);
3410 if (spec->codec_type == VT1802)
3411 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3413 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3415 codec->patch_ops = via_patch_ops;
3417 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3423 static const struct hda_verb vt1812_init_verbs[] = {
3424 /* Enable Boost Volume backdoor */
3426 /* Enable AOW0 to MW9 */
3431 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3433 struct via_spec *spec = codec->spec;
3434 int imux_is_smixer =
3435 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3437 unsigned int present;
3438 /* MUX10 (1eh) = stereo mixer */
3440 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3442 /* PW 5/6/7 (29h/2ah/2bh) */
3444 set_pin_power_state(codec, 0x29, &parm);
3445 set_pin_power_state(codec, 0x2a, &parm);
3446 set_pin_power_state(codec, 0x2b, &parm);
3448 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3449 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3450 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3451 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3452 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3456 snd_hda_codec_write(codec, 0x8, 0,
3457 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3459 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3461 set_pin_power_state(codec, 0x28, &parm);
3462 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3463 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3465 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3467 set_pin_power_state(codec, 0x25, &parm);
3468 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3469 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3470 if (spec->hp_independent_mode)
3471 snd_hda_codec_write(codec, 0x9, 0,
3472 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3474 /* Internal Speaker */
3475 /* PW0 (24h), MW0(14h), MUX0(34h) */
3476 present = snd_hda_jack_detect(codec, 0x25);
3479 set_pin_power_state(codec, 0x24, &parm);
3481 snd_hda_codec_write(codec, 0x14, 0,
3482 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3483 snd_hda_codec_write(codec, 0x34, 0,
3484 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3486 snd_hda_codec_write(codec, 0x14, 0,
3487 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3488 snd_hda_codec_write(codec, 0x34, 0,
3489 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3494 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3495 present = snd_hda_jack_detect(codec, 0x28);
3498 set_pin_power_state(codec, 0x31, &parm);
3500 snd_hda_codec_write(codec, 0x1c, 0,
3501 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3502 snd_hda_codec_write(codec, 0x3c, 0,
3503 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3504 snd_hda_codec_write(codec, 0x3e, 0,
3505 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3507 snd_hda_codec_write(codec, 0x1c, 0,
3508 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3509 snd_hda_codec_write(codec, 0x3c, 0,
3510 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3511 snd_hda_codec_write(codec, 0x3e, 0,
3512 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3515 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3517 set_pin_power_state(codec, 0x33, &parm);
3518 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3519 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3523 /* patch for vt1812 */
3524 static int patch_vt1812(struct hda_codec *codec)
3526 struct via_spec *spec;
3529 /* create a codec specific record */
3530 spec = via_new_spec(codec);
3534 spec->aa_mix_nid = 0x21;
3535 override_mic_boost(codec, 0x2b, 0, 3, 40);
3536 override_mic_boost(codec, 0x29, 0, 3, 40);
3537 spec->dac_mixer_idx = 5;
3539 /* automatic parse from the BIOS config */
3540 err = via_parse_auto_config(codec);
3546 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3548 codec->patch_ops = via_patch_ops;
3550 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3557 static const struct hda_codec_preset snd_hda_preset_via[] = {
3558 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3559 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3560 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3561 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3562 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3563 .patch = patch_vt1709},
3564 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3565 .patch = patch_vt1709},
3566 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3567 .patch = patch_vt1709},
3568 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3569 .patch = patch_vt1709},
3570 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3571 .patch = patch_vt1709},
3572 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3573 .patch = patch_vt1709},
3574 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3575 .patch = patch_vt1709},
3576 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3577 .patch = patch_vt1709},
3578 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3579 .patch = patch_vt1708B},
3580 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3581 .patch = patch_vt1708B},
3582 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3583 .patch = patch_vt1708B},
3584 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3585 .patch = patch_vt1708B},
3586 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3587 .patch = patch_vt1708B},
3588 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3589 .patch = patch_vt1708B},
3590 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3591 .patch = patch_vt1708B},
3592 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3593 .patch = patch_vt1708B},
3594 { .id = 0x11060397, .name = "VT1708S",
3595 .patch = patch_vt1708S},
3596 { .id = 0x11061397, .name = "VT1708S",
3597 .patch = patch_vt1708S},
3598 { .id = 0x11062397, .name = "VT1708S",
3599 .patch = patch_vt1708S},
3600 { .id = 0x11063397, .name = "VT1708S",
3601 .patch = patch_vt1708S},
3602 { .id = 0x11064397, .name = "VT1705",
3603 .patch = patch_vt1708S},
3604 { .id = 0x11065397, .name = "VT1708S",
3605 .patch = patch_vt1708S},
3606 { .id = 0x11066397, .name = "VT1708S",
3607 .patch = patch_vt1708S},
3608 { .id = 0x11067397, .name = "VT1708S",
3609 .patch = patch_vt1708S},
3610 { .id = 0x11060398, .name = "VT1702",
3611 .patch = patch_vt1702},
3612 { .id = 0x11061398, .name = "VT1702",
3613 .patch = patch_vt1702},
3614 { .id = 0x11062398, .name = "VT1702",
3615 .patch = patch_vt1702},
3616 { .id = 0x11063398, .name = "VT1702",
3617 .patch = patch_vt1702},
3618 { .id = 0x11064398, .name = "VT1702",
3619 .patch = patch_vt1702},
3620 { .id = 0x11065398, .name = "VT1702",
3621 .patch = patch_vt1702},
3622 { .id = 0x11066398, .name = "VT1702",
3623 .patch = patch_vt1702},
3624 { .id = 0x11067398, .name = "VT1702",
3625 .patch = patch_vt1702},
3626 { .id = 0x11060428, .name = "VT1718S",
3627 .patch = patch_vt1718S},
3628 { .id = 0x11064428, .name = "VT1718S",
3629 .patch = patch_vt1718S},
3630 { .id = 0x11060441, .name = "VT2020",
3631 .patch = patch_vt1718S},
3632 { .id = 0x11064441, .name = "VT1828S",
3633 .patch = patch_vt1718S},
3634 { .id = 0x11060433, .name = "VT1716S",
3635 .patch = patch_vt1716S},
3636 { .id = 0x1106a721, .name = "VT1716S",
3637 .patch = patch_vt1716S},
3638 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3639 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3640 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3641 { .id = 0x11060440, .name = "VT1818S",
3642 .patch = patch_vt1708S},
3643 { .id = 0x11060446, .name = "VT1802",
3644 .patch = patch_vt2002P},
3645 { .id = 0x11068446, .name = "VT1802",
3646 .patch = patch_vt2002P},
3650 MODULE_ALIAS("snd-hda-codec-id:1106*");
3652 static struct hda_codec_preset_list via_list = {
3653 .preset = snd_hda_preset_via,
3654 .owner = THIS_MODULE,
3657 MODULE_LICENSE("GPL");
3658 MODULE_DESCRIPTION("VIA HD-audio codec");
3660 static int __init patch_via_init(void)
3662 return snd_hda_add_codec_preset(&via_list);
3665 static void __exit patch_via_exit(void)
3667 snd_hda_delete_codec_preset(&via_list);
3670 module_init(patch_via_init)
3671 module_exit(patch_via_exit)