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 */
111 /* codec parameterization */
112 const struct snd_kcontrol_new *mixers[6];
113 unsigned int num_mixers;
115 const struct hda_verb *init_verbs[5];
116 unsigned int num_iverbs;
118 char stream_name_analog[32];
119 char stream_name_hp[32];
120 const struct hda_pcm_stream *stream_analog_playback;
121 const struct hda_pcm_stream *stream_analog_capture;
123 char stream_name_digital[32];
124 const struct hda_pcm_stream *stream_digital_playback;
125 const struct hda_pcm_stream *stream_digital_capture;
128 struct hda_multi_out multiout;
129 hda_nid_t slave_dig_outs[2];
130 hda_nid_t hp_dac_nid;
131 int num_active_streams;
133 struct nid_path out_path[4];
134 struct nid_path hp_path;
135 struct nid_path hp_dep_path;
136 struct nid_path speaker_path;
139 unsigned int num_adc_nids;
140 hda_nid_t adc_nids[3];
141 hda_nid_t mux_nids[3];
142 hda_nid_t aa_mix_nid;
143 hda_nid_t dig_in_nid;
148 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
149 unsigned int cur_mux[3];
151 /* dynamic ADC switching */
153 unsigned int cur_adc_stream_tag;
154 unsigned int cur_adc_format;
156 /* PCM information */
157 struct hda_pcm pcm_rec[3];
159 /* dynamic controls, init_verbs and input_mux */
160 struct auto_pin_cfg autocfg;
161 struct snd_array kctls;
162 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
165 unsigned int hp_independent_mode;
166 unsigned int dmic_enabled;
167 unsigned int no_pin_power_ctl;
168 enum VIA_HDA_CODEC codec_type;
171 unsigned int smart51_nums;
172 hda_nid_t smart51_pins[2];
174 const char *smart51_labels[2];
175 unsigned int smart51_enabled;
177 /* work to check hp jack state */
178 struct hda_codec *codec;
179 struct delayed_work vt1708_hp_work;
180 int vt1708_jack_detect;
181 int vt1708_hp_present;
183 void (*set_widgets_power_state)(struct hda_codec *codec);
185 struct hda_loopback_check loopback;
187 struct hda_amp_list loopback_list[8];
189 /* bind capture-volume */
190 struct hda_bind_ctls *bind_cap_vol;
191 struct hda_bind_ctls *bind_cap_sw;
194 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
195 static struct via_spec * via_new_spec(struct hda_codec *codec)
197 struct via_spec *spec;
199 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
205 spec->codec_type = get_codec_type(codec);
206 /* VT1708BCE & VT1708S are almost same */
207 if (spec->codec_type == VT1708BCE)
208 spec->codec_type = VT1708S;
212 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
214 u32 vendor_id = codec->vendor_id;
215 u16 ven_id = vendor_id >> 16;
216 u16 dev_id = vendor_id & 0xffff;
217 enum VIA_HDA_CODEC codec_type;
220 if (ven_id != 0x1106)
221 codec_type = UNKNOWN;
222 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
224 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
225 codec_type = VT1709_10CH;
226 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
227 codec_type = VT1709_6CH;
228 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
229 codec_type = VT1708B_8CH;
230 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
231 codec_type = VT1708BCE;
232 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
233 codec_type = VT1708B_4CH;
234 else if ((dev_id & 0xfff) == 0x397
235 && (dev_id >> 12) < 8)
236 codec_type = VT1708S;
237 else if ((dev_id & 0xfff) == 0x398
238 && (dev_id >> 12) < 8)
240 else if ((dev_id & 0xfff) == 0x428
241 && (dev_id >> 12) < 8)
242 codec_type = VT1718S;
243 else if (dev_id == 0x0433 || dev_id == 0xa721)
244 codec_type = VT1716S;
245 else if (dev_id == 0x0441 || dev_id == 0x4441)
246 codec_type = VT1718S;
247 else if (dev_id == 0x0438 || dev_id == 0x4438)
248 codec_type = VT2002P;
249 else if (dev_id == 0x0448)
251 else if (dev_id == 0x0440)
252 codec_type = VT1708S;
253 else if ((dev_id & 0xfff) == 0x446)
256 codec_type = UNKNOWN;
260 #define VIA_JACK_EVENT 0x20
261 #define VIA_HP_EVENT 0x01
262 #define VIA_GPIO_EVENT 0x02
263 #define VIA_LINE_EVENT 0x03
268 VIA_CTL_WIDGET_ANALOG_MUTE,
271 static void analog_low_current_mode(struct hda_codec *codec);
272 static bool is_aa_path_mute(struct hda_codec *codec);
274 static void vt1708_start_hp_work(struct via_spec *spec)
276 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
278 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
279 !spec->vt1708_jack_detect);
280 if (!delayed_work_pending(&spec->vt1708_hp_work))
281 schedule_delayed_work(&spec->vt1708_hp_work,
282 msecs_to_jiffies(100));
285 static void vt1708_stop_hp_work(struct via_spec *spec)
287 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
289 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
290 && !is_aa_path_mute(spec->codec))
292 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
293 !spec->vt1708_jack_detect);
294 cancel_delayed_work_sync(&spec->vt1708_hp_work);
297 static void set_widgets_power_state(struct hda_codec *codec)
299 struct via_spec *spec = codec->spec;
300 if (spec->set_widgets_power_state)
301 spec->set_widgets_power_state(codec);
304 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_value *ucontrol)
307 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
308 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
310 set_widgets_power_state(codec);
311 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
312 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
313 if (is_aa_path_mute(codec))
314 vt1708_start_hp_work(codec->spec);
316 vt1708_stop_hp_work(codec->spec);
321 /* modify .put = snd_hda_mixer_amp_switch_put */
322 #define ANALOG_INPUT_MUTE \
323 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
326 .info = snd_hda_mixer_amp_switch_info, \
327 .get = snd_hda_mixer_amp_switch_get, \
328 .put = analog_input_switch_put, \
329 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
331 static const struct snd_kcontrol_new via_control_templates[] = {
332 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
333 HDA_CODEC_MUTE(NULL, 0, 0, 0),
338 /* add dynamic controls */
339 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
340 const struct snd_kcontrol_new *tmpl,
343 struct snd_kcontrol_new *knew;
345 snd_array_init(&spec->kctls, sizeof(*knew), 32);
346 knew = snd_array_new(&spec->kctls);
353 knew->name = kstrdup(name, GFP_KERNEL);
360 static int __via_add_control(struct via_spec *spec, int type, const char *name,
361 int idx, unsigned long val)
363 struct snd_kcontrol_new *knew;
365 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
369 if (get_amp_nid_(val))
370 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
371 knew->private_value = val;
375 #define via_add_control(spec, type, name, val) \
376 __via_add_control(spec, type, name, 0, val)
378 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
380 static void via_free_kctls(struct hda_codec *codec)
382 struct via_spec *spec = codec->spec;
384 if (spec->kctls.list) {
385 struct snd_kcontrol_new *kctl = spec->kctls.list;
387 for (i = 0; i < spec->kctls.used; i++)
390 snd_array_free(&spec->kctls);
393 /* create input playback/capture controls for the given pin */
394 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
395 int type_idx, int idx, int mix_nid)
400 sprintf(name, "%s Playback Volume", ctlname);
401 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
402 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
405 sprintf(name, "%s Playback Switch", ctlname);
406 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
407 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
413 /* return the index of the given widget nid as the source of mux;
414 * return -1 if not found;
415 * if num_conns is non-NULL, set the total number of connections
417 static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux,
418 hda_nid_t nid, int *num_conns)
420 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
423 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
426 for (i = 0; i < nums; i++)
432 #define get_connection_index(codec, mux, nid) \
433 __get_connection_index(codec, mux, nid, NULL)
435 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
441 caps = get_wcaps(codec, nid);
442 if (dir == HDA_INPUT)
443 caps &= AC_WCAP_IN_AMP;
445 caps &= AC_WCAP_OUT_AMP;
448 if (query_amp_caps(codec, nid, dir) & mask)
453 #define have_mute(codec, nid, dir) \
454 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
456 /* enable/disable the output-route */
457 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
458 bool enable, bool force)
461 for (i = 0; i < path->depth; i++) {
463 int idx = path->idx[i];
465 if (i < path->depth - 1)
466 dst = path->path[i + 1];
469 if (enable && path->multi[i])
470 snd_hda_codec_write(codec, dst, 0,
471 AC_VERB_SET_CONNECT_SEL, idx);
472 if (have_mute(codec, dst, HDA_INPUT)) {
473 int val = enable ? AMP_IN_UNMUTE(idx) :
475 snd_hda_codec_write(codec, dst, 0,
476 AC_VERB_SET_AMP_GAIN_MUTE, val);
478 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
480 if (have_mute(codec, src, HDA_OUTPUT)) {
481 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
482 snd_hda_codec_write(codec, src, 0,
483 AC_VERB_SET_AMP_GAIN_MUTE, val);
488 /* set the given pin as output */
489 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
494 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
496 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
497 snd_hda_codec_write(codec, pin, 0,
498 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
501 static void via_auto_init_output(struct hda_codec *codec,
502 struct nid_path *path, int pin_type,
505 struct via_spec *spec = codec->spec;
512 pin = path->path[path->depth - 1];
514 init_output_pin(codec, pin, pin_type);
515 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
516 if (caps & AC_AMPCAP_MUTE) {
518 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
519 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
523 activate_output_path(codec, path, true, force);
525 /* initialize the AA-path */
526 if (!spec->aa_mix_nid)
528 for (i = path->depth - 1; i > 0; i--) {
530 idx = get_connection_index(codec, nid, spec->aa_mix_nid);
532 if (have_mute(codec, nid, HDA_INPUT))
533 snd_hda_codec_write(codec, nid, 0,
534 AC_VERB_SET_AMP_GAIN_MUTE,
541 static void via_auto_init_multi_out(struct hda_codec *codec)
543 struct via_spec *spec = codec->spec;
546 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++)
547 via_auto_init_output(codec, &spec->out_path[i], PIN_OUT, true);
550 static void via_auto_init_hp_out(struct hda_codec *codec)
552 struct via_spec *spec = codec->spec;
554 if (!spec->hp_dac_nid) {
555 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true);
558 if (spec->hp_independent_mode) {
559 activate_output_path(codec, &spec->hp_dep_path, false, false);
560 via_auto_init_output(codec, &spec->hp_path, PIN_HP, true);
562 activate_output_path(codec, &spec->hp_path, false, false);
563 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true);
567 static void via_auto_init_speaker_out(struct hda_codec *codec)
569 struct via_spec *spec = codec->spec;
571 if (spec->autocfg.speaker_outs)
572 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT, true);
575 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
577 static void via_auto_init_analog_input(struct hda_codec *codec)
579 struct via_spec *spec = codec->spec;
580 const struct auto_pin_cfg *cfg = &spec->autocfg;
581 hda_nid_t conn[HDA_MAX_CONNECTIONS];
586 for (i = 0; i < spec->num_adc_nids; i++) {
587 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
588 AC_VERB_SET_AMP_GAIN_MUTE,
593 for (i = 0; i < cfg->num_inputs; i++) {
594 hda_nid_t nid = cfg->inputs[i].pin;
595 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
597 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
601 snd_hda_codec_write(codec, nid, 0,
602 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
606 for (i = 0; i < spec->num_adc_nids; i++) {
607 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
608 if (spec->mux_nids[adc_idx]) {
609 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
610 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
611 AC_VERB_SET_CONNECT_SEL,
614 if (spec->dyn_adc_switch)
615 break; /* only one input-src */
619 if (!spec->aa_mix_nid)
621 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
623 for (i = 0; i < num_conns; i++) {
624 unsigned int caps = get_wcaps(codec, conn[i]);
625 if (get_wcaps_type(caps) == AC_WID_PIN)
626 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
627 AC_VERB_SET_AMP_GAIN_MUTE,
632 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
633 unsigned int *affected_parm)
636 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
637 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
638 >> AC_DEFCFG_MISC_SHIFT
639 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
640 struct via_spec *spec = codec->spec;
641 unsigned present = 0;
643 no_presence |= spec->no_pin_power_ctl;
645 present = snd_hda_jack_detect(codec, nid);
646 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
647 || ((no_presence || present)
648 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
649 *affected_parm = AC_PWRST_D0; /* if it's connected */
654 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
657 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
658 struct snd_ctl_elem_info *uinfo)
660 static const char * const texts[] = {
661 "Disabled", "Enabled"
664 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
666 uinfo->value.enumerated.items = 2;
667 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
668 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
669 strcpy(uinfo->value.enumerated.name,
670 texts[uinfo->value.enumerated.item]);
674 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
675 struct snd_ctl_elem_value *ucontrol)
677 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
678 struct via_spec *spec = codec->spec;
679 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
683 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
684 struct snd_ctl_elem_value *ucontrol)
686 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
687 struct via_spec *spec = codec->spec;
688 unsigned int val = !ucontrol->value.enumerated.item[0];
690 if (val == spec->no_pin_power_ctl)
692 spec->no_pin_power_ctl = val;
693 set_widgets_power_state(codec);
697 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
699 .name = "Dynamic Power-Control",
700 .info = via_pin_power_ctl_info,
701 .get = via_pin_power_ctl_get,
702 .put = via_pin_power_ctl_put,
706 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
707 struct snd_ctl_elem_info *uinfo)
709 static const char * const texts[] = { "OFF", "ON" };
711 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
713 uinfo->value.enumerated.items = 2;
714 if (uinfo->value.enumerated.item >= 2)
715 uinfo->value.enumerated.item = 1;
716 strcpy(uinfo->value.enumerated.name,
717 texts[uinfo->value.enumerated.item]);
721 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
722 struct snd_ctl_elem_value *ucontrol)
724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
725 struct via_spec *spec = codec->spec;
727 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
731 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
732 struct snd_ctl_elem_value *ucontrol)
734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
735 struct via_spec *spec = codec->spec;
737 spec->hp_independent_mode = !!ucontrol->value.enumerated.item[0];
738 if (spec->hp_independent_mode) {
739 activate_output_path(codec, &spec->hp_dep_path, false, false);
740 activate_output_path(codec, &spec->hp_path, true, false);
742 activate_output_path(codec, &spec->hp_path, false, false);
743 activate_output_path(codec, &spec->hp_dep_path, true, false);
746 /* update jack power state */
747 set_widgets_power_state(codec);
751 static const struct snd_kcontrol_new via_hp_mixer = {
752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
753 .name = "Independent HP",
754 .info = via_independent_hp_info,
755 .get = via_independent_hp_get,
756 .put = via_independent_hp_put,
759 static int via_hp_build(struct hda_codec *codec)
761 struct via_spec *spec = codec->spec;
762 struct snd_kcontrol_new *knew;
765 nid = spec->autocfg.hp_pins[0];
766 knew = via_clone_control(spec, &via_hp_mixer);
770 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
775 static void notify_aa_path_ctls(struct hda_codec *codec)
777 struct via_spec *spec = codec->spec;
780 for (i = 0; i < spec->smart51_nums; i++) {
781 struct snd_kcontrol *ctl;
782 struct snd_ctl_elem_id id;
783 memset(&id, 0, sizeof(id));
784 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
785 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
786 ctl = snd_hda_find_mixer_ctl(codec, id.name);
788 snd_ctl_notify(codec->bus->card,
789 SNDRV_CTL_EVENT_MASK_VALUE,
794 static void mute_aa_path(struct hda_codec *codec, int mute)
796 struct via_spec *spec = codec->spec;
797 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
800 /* check AA path's mute status */
801 for (i = 0; i < spec->smart51_nums; i++) {
802 if (spec->smart51_idxs[i] < 0)
804 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
805 HDA_INPUT, spec->smart51_idxs[i],
810 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
812 struct via_spec *spec = codec->spec;
815 for (i = 0; i < spec->smart51_nums; i++)
816 if (spec->smart51_pins[i] == pin)
821 static int via_smart51_get(struct snd_kcontrol *kcontrol,
822 struct snd_ctl_elem_value *ucontrol)
824 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
825 struct via_spec *spec = codec->spec;
827 *ucontrol->value.integer.value = spec->smart51_enabled;
831 static int via_smart51_put(struct snd_kcontrol *kcontrol,
832 struct snd_ctl_elem_value *ucontrol)
834 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
835 struct via_spec *spec = codec->spec;
836 int out_in = *ucontrol->value.integer.value
837 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
840 for (i = 0; i < spec->smart51_nums; i++) {
841 hda_nid_t nid = spec->smart51_pins[i];
844 parm = snd_hda_codec_read(codec, nid, 0,
845 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
846 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
848 snd_hda_codec_write(codec, nid, 0,
849 AC_VERB_SET_PIN_WIDGET_CONTROL,
851 if (out_in == AC_PINCTL_OUT_EN) {
852 mute_aa_path(codec, 1);
853 notify_aa_path_ctls(codec);
856 spec->smart51_enabled = *ucontrol->value.integer.value;
857 set_widgets_power_state(codec);
861 static const struct snd_kcontrol_new via_smart51_mixer = {
862 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
865 .info = snd_ctl_boolean_mono_info,
866 .get = via_smart51_get,
867 .put = via_smart51_put,
870 static int via_smart51_build(struct hda_codec *codec)
872 struct via_spec *spec = codec->spec;
874 if (!spec->smart51_nums)
876 if (!via_clone_control(spec, &via_smart51_mixer))
881 /* check AA path's mute status */
882 static bool is_aa_path_mute(struct hda_codec *codec)
884 struct via_spec *spec = codec->spec;
885 const struct hda_amp_list *p;
888 for (i = 0; i < spec->num_loopbacks; i++) {
889 p = &spec->loopback_list[i];
890 for (ch = 0; ch < 2; ch++) {
891 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
893 if (!(v & HDA_AMP_MUTE) && v > 0)
900 /* enter/exit analog low-current mode */
901 static void analog_low_current_mode(struct hda_codec *codec)
903 struct via_spec *spec = codec->spec;
905 unsigned int verb, parm;
907 enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0);
909 /* decide low current mode's verb & parameter */
910 switch (spec->codec_type) {
914 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
920 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
924 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
930 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
933 return; /* other codecs are not supported */
936 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
940 * generic initialization of ADC, input mixers and output mixers
942 static const struct hda_verb vt1708_init_verbs[] = {
943 /* power down jack detect function */
948 static void set_stream_active(struct hda_codec *codec, bool active)
950 struct via_spec *spec = codec->spec;
953 spec->num_active_streams++;
955 spec->num_active_streams--;
956 analog_low_current_mode(codec);
959 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
960 struct hda_codec *codec,
961 struct snd_pcm_substream *substream)
963 struct via_spec *spec = codec->spec;
966 if (!spec->hp_independent_mode)
967 spec->multiout.hp_nid = spec->hp_dac_nid;
968 set_stream_active(codec, true);
969 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
972 spec->multiout.hp_nid = 0;
973 set_stream_active(codec, false);
979 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
980 struct hda_codec *codec,
981 struct snd_pcm_substream *substream)
983 struct via_spec *spec = codec->spec;
985 spec->multiout.hp_nid = 0;
986 set_stream_active(codec, false);
990 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
991 struct hda_codec *codec,
992 struct snd_pcm_substream *substream)
994 struct via_spec *spec = codec->spec;
996 if (snd_BUG_ON(!spec->hp_dac_nid))
998 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1000 set_stream_active(codec, true);
1004 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1005 struct hda_codec *codec,
1006 struct snd_pcm_substream *substream)
1008 set_stream_active(codec, false);
1012 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1013 struct hda_codec *codec,
1014 unsigned int stream_tag,
1015 unsigned int format,
1016 struct snd_pcm_substream *substream)
1018 struct via_spec *spec = codec->spec;
1020 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1022 vt1708_start_hp_work(spec);
1026 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1027 struct hda_codec *codec,
1028 unsigned int stream_tag,
1029 unsigned int format,
1030 struct snd_pcm_substream *substream)
1032 struct via_spec *spec = codec->spec;
1034 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1035 stream_tag, 0, format);
1036 vt1708_start_hp_work(spec);
1040 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1041 struct hda_codec *codec,
1042 struct snd_pcm_substream *substream)
1044 struct via_spec *spec = codec->spec;
1046 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1047 vt1708_stop_hp_work(spec);
1051 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1052 struct hda_codec *codec,
1053 struct snd_pcm_substream *substream)
1055 struct via_spec *spec = codec->spec;
1057 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1058 vt1708_stop_hp_work(spec);
1065 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1066 struct hda_codec *codec,
1067 struct snd_pcm_substream *substream)
1069 struct via_spec *spec = codec->spec;
1070 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1073 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1074 struct hda_codec *codec,
1075 struct snd_pcm_substream *substream)
1077 struct via_spec *spec = codec->spec;
1078 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1081 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1082 struct hda_codec *codec,
1083 unsigned int stream_tag,
1084 unsigned int format,
1085 struct snd_pcm_substream *substream)
1087 struct via_spec *spec = codec->spec;
1088 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1089 stream_tag, format, substream);
1092 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1093 struct hda_codec *codec,
1094 struct snd_pcm_substream *substream)
1096 struct via_spec *spec = codec->spec;
1097 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1104 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1105 struct hda_codec *codec,
1106 unsigned int stream_tag,
1107 unsigned int format,
1108 struct snd_pcm_substream *substream)
1110 struct via_spec *spec = codec->spec;
1112 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1113 stream_tag, 0, format);
1117 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1118 struct hda_codec *codec,
1119 struct snd_pcm_substream *substream)
1121 struct via_spec *spec = codec->spec;
1122 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1126 /* analog capture with dynamic ADC switching */
1127 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1128 struct hda_codec *codec,
1129 unsigned int stream_tag,
1130 unsigned int format,
1131 struct snd_pcm_substream *substream)
1133 struct via_spec *spec = codec->spec;
1134 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1136 spec->cur_adc = spec->adc_nids[adc_idx];
1137 spec->cur_adc_stream_tag = stream_tag;
1138 spec->cur_adc_format = format;
1139 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1143 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1144 struct hda_codec *codec,
1145 struct snd_pcm_substream *substream)
1147 struct via_spec *spec = codec->spec;
1149 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1154 /* re-setup the stream if running; called from input-src put */
1155 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1157 struct via_spec *spec = codec->spec;
1158 int adc_idx = spec->inputs[cur].adc_idx;
1159 hda_nid_t adc = spec->adc_nids[adc_idx];
1161 if (spec->cur_adc && spec->cur_adc != adc) {
1162 /* stream is running, let's swap the current ADC */
1163 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1164 spec->cur_adc = adc;
1165 snd_hda_codec_setup_stream(codec, adc,
1166 spec->cur_adc_stream_tag, 0,
1167 spec->cur_adc_format);
1173 static const struct hda_pcm_stream via_pcm_analog_playback = {
1177 /* NID is set in via_build_pcms */
1179 .open = via_playback_multi_pcm_open,
1180 .close = via_playback_multi_pcm_close,
1181 .prepare = via_playback_multi_pcm_prepare,
1182 .cleanup = via_playback_multi_pcm_cleanup
1186 static const struct hda_pcm_stream via_pcm_hp_playback = {
1190 /* NID is set in via_build_pcms */
1192 .open = via_playback_hp_pcm_open,
1193 .close = via_playback_hp_pcm_close,
1194 .prepare = via_playback_hp_pcm_prepare,
1195 .cleanup = via_playback_hp_pcm_cleanup
1199 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1203 /* NID is set in via_build_pcms */
1204 /* We got noisy outputs on the right channel on VT1708 when
1205 * 24bit samples are used. Until any workaround is found,
1206 * disable the 24bit format, so far.
1208 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1210 .open = via_playback_multi_pcm_open,
1211 .close = via_playback_multi_pcm_close,
1212 .prepare = via_playback_multi_pcm_prepare,
1213 .cleanup = via_playback_multi_pcm_cleanup
1217 static const struct hda_pcm_stream via_pcm_analog_capture = {
1218 .substreams = 1, /* will be changed in via_build_pcms() */
1221 /* NID is set in via_build_pcms */
1223 .prepare = via_capture_pcm_prepare,
1224 .cleanup = via_capture_pcm_cleanup
1228 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1232 /* NID is set in via_build_pcms */
1234 .prepare = via_dyn_adc_capture_pcm_prepare,
1235 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1239 static const struct hda_pcm_stream via_pcm_digital_playback = {
1243 /* NID is set in via_build_pcms */
1245 .open = via_dig_playback_pcm_open,
1246 .close = via_dig_playback_pcm_close,
1247 .prepare = via_dig_playback_pcm_prepare,
1248 .cleanup = via_dig_playback_pcm_cleanup
1252 static const struct hda_pcm_stream via_pcm_digital_capture = {
1259 * slave controls for virtual master
1261 static const char * const via_slave_vols[] = {
1262 "Front Playback Volume",
1263 "Surround Playback Volume",
1264 "Center Playback Volume",
1265 "LFE Playback Volume",
1266 "Side Playback Volume",
1267 "Headphone Playback Volume",
1268 "Speaker Playback Volume",
1272 static const char * const via_slave_sws[] = {
1273 "Front Playback Switch",
1274 "Surround Playback Switch",
1275 "Center Playback Switch",
1276 "LFE Playback Switch",
1277 "Side Playback Switch",
1278 "Headphone Playback Switch",
1279 "Speaker Playback Switch",
1283 static int via_build_controls(struct hda_codec *codec)
1285 struct via_spec *spec = codec->spec;
1286 struct snd_kcontrol *kctl;
1289 if (spec->set_widgets_power_state)
1290 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1293 for (i = 0; i < spec->num_mixers; i++) {
1294 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1299 if (spec->multiout.dig_out_nid) {
1300 err = snd_hda_create_spdif_out_ctls(codec,
1301 spec->multiout.dig_out_nid,
1302 spec->multiout.dig_out_nid);
1305 err = snd_hda_create_spdif_share_sw(codec,
1309 spec->multiout.share_spdif = 1;
1311 if (spec->dig_in_nid) {
1312 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1317 /* if we have no master control, let's create it */
1318 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1319 unsigned int vmaster_tlv[4];
1320 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1321 HDA_OUTPUT, vmaster_tlv);
1322 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1323 vmaster_tlv, via_slave_vols);
1327 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1328 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1329 NULL, via_slave_sws);
1334 /* assign Capture Source enums to NID */
1335 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1336 for (i = 0; kctl && i < kctl->count; i++) {
1337 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1342 /* init power states */
1343 set_widgets_power_state(codec);
1344 analog_low_current_mode(codec);
1346 via_free_kctls(codec); /* no longer needed */
1350 static int via_build_pcms(struct hda_codec *codec)
1352 struct via_spec *spec = codec->spec;
1353 struct hda_pcm *info = spec->pcm_rec;
1355 codec->num_pcms = 1;
1356 codec->pcm_info = info;
1358 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1359 "%s Analog", codec->chip_name);
1360 info->name = spec->stream_name_analog;
1362 if (!spec->stream_analog_playback)
1363 spec->stream_analog_playback = &via_pcm_analog_playback;
1364 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1365 *spec->stream_analog_playback;
1366 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1367 spec->multiout.dac_nids[0];
1368 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1369 spec->multiout.max_channels;
1371 if (!spec->stream_analog_capture) {
1372 if (spec->dyn_adc_switch)
1373 spec->stream_analog_capture =
1374 &via_pcm_dyn_adc_analog_capture;
1376 spec->stream_analog_capture = &via_pcm_analog_capture;
1378 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1379 *spec->stream_analog_capture;
1380 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1381 if (!spec->dyn_adc_switch)
1382 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1385 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1388 snprintf(spec->stream_name_digital,
1389 sizeof(spec->stream_name_digital),
1390 "%s Digital", codec->chip_name);
1391 info->name = spec->stream_name_digital;
1392 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1393 if (spec->multiout.dig_out_nid) {
1394 if (!spec->stream_digital_playback)
1395 spec->stream_digital_playback =
1396 &via_pcm_digital_playback;
1397 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1398 *spec->stream_digital_playback;
1399 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1400 spec->multiout.dig_out_nid;
1402 if (spec->dig_in_nid) {
1403 if (!spec->stream_digital_capture)
1404 spec->stream_digital_capture =
1405 &via_pcm_digital_capture;
1406 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1407 *spec->stream_digital_capture;
1408 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1413 if (spec->hp_dac_nid) {
1416 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1417 "%s HP", codec->chip_name);
1418 info->name = spec->stream_name_hp;
1419 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1420 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1426 static void via_free(struct hda_codec *codec)
1428 struct via_spec *spec = codec->spec;
1433 via_free_kctls(codec);
1434 vt1708_stop_hp_work(spec);
1435 kfree(spec->bind_cap_vol);
1436 kfree(spec->bind_cap_sw);
1440 /* mute/unmute outputs */
1441 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1442 hda_nid_t *pins, bool mute)
1445 for (i = 0; i < num_pins; i++)
1446 snd_hda_codec_write(codec, pins[i], 0,
1447 AC_VERB_SET_PIN_WIDGET_CONTROL,
1448 mute ? 0 : PIN_OUT);
1451 /* mute internal speaker if line-out is plugged */
1452 static void via_line_automute(struct hda_codec *codec, int present)
1454 struct via_spec *spec = codec->spec;
1456 if (!spec->autocfg.speaker_outs)
1459 present = snd_hda_jack_detect(codec,
1460 spec->autocfg.line_out_pins[0]);
1461 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1462 spec->autocfg.speaker_pins,
1466 /* mute internal speaker if HP is plugged */
1467 static void via_hp_automute(struct hda_codec *codec)
1470 struct via_spec *spec = codec->spec;
1472 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) {
1474 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1475 if (spec->smart51_enabled)
1476 nums = spec->autocfg.line_outs + spec->smart51_nums;
1478 nums = spec->autocfg.line_outs;
1479 toggle_output_mutes(codec, nums,
1480 spec->autocfg.line_out_pins,
1483 via_line_automute(codec, present);
1486 static void via_gpio_control(struct hda_codec *codec)
1488 unsigned int gpio_data;
1489 unsigned int vol_counter;
1491 unsigned int master_vol;
1493 struct via_spec *spec = codec->spec;
1495 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1496 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1498 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1499 0xF84, 0) & 0x3F0000) >> 16;
1501 vol = vol_counter & 0x1F;
1502 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1503 AC_VERB_GET_AMP_GAIN_MUTE,
1506 if (gpio_data == 0x02) {
1507 /* unmute line out */
1508 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1509 AC_VERB_SET_PIN_WIDGET_CONTROL,
1511 if (vol_counter & 0x20) {
1512 /* decrease volume */
1513 if (vol > master_vol)
1515 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1519 /* increase volume */
1520 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1522 ((master_vol+vol) > 0x2A) ? 0x2A :
1525 } else if (!(gpio_data & 0x02)) {
1527 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1528 AC_VERB_SET_PIN_WIDGET_CONTROL,
1533 /* unsolicited event for jack sensing */
1534 static void via_unsol_event(struct hda_codec *codec,
1539 if (res & VIA_JACK_EVENT)
1540 set_widgets_power_state(codec);
1542 res &= ~VIA_JACK_EVENT;
1544 if (res == VIA_HP_EVENT)
1545 via_hp_automute(codec);
1546 else if (res == VIA_GPIO_EVENT)
1547 via_gpio_control(codec);
1548 else if (res == VIA_LINE_EVENT)
1549 via_line_automute(codec, false);
1552 #ifdef SND_HDA_NEEDS_RESUME
1553 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1555 struct via_spec *spec = codec->spec;
1556 vt1708_stop_hp_work(spec);
1561 #ifdef CONFIG_SND_HDA_POWER_SAVE
1562 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1564 struct via_spec *spec = codec->spec;
1565 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1572 static int via_init(struct hda_codec *codec);
1574 static const struct hda_codec_ops via_patch_ops = {
1575 .build_controls = via_build_controls,
1576 .build_pcms = via_build_pcms,
1579 .unsol_event = via_unsol_event,
1580 #ifdef SND_HDA_NEEDS_RESUME
1581 .suspend = via_suspend,
1583 #ifdef CONFIG_SND_HDA_POWER_SAVE
1584 .check_power_status = via_check_power_status,
1588 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1590 struct via_spec *spec = codec->spec;
1593 for (i = 0; i < spec->multiout.num_dacs; i++) {
1594 if (spec->multiout.dac_nids[i] == dac)
1597 if (spec->hp_dac_nid == dac)
1602 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1603 hda_nid_t target_dac, struct nid_path *path,
1604 int depth, int wid_type)
1609 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1610 for (i = 0; i < nums; i++) {
1611 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1613 if (conn[i] == target_dac || is_empty_dac(codec, conn[i]))
1616 if (depth >= MAX_NID_PATH_DEPTH)
1618 for (i = 0; i < nums; i++) {
1620 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1621 if (type == AC_WID_AUD_OUT ||
1622 (wid_type != -1 && type != wid_type))
1624 if (__parse_output_path(codec, conn[i], target_dac,
1625 path, depth + 1, AC_WID_AUD_SEL))
1631 path->path[path->depth] = conn[i];
1632 path->idx[path->depth] = i;
1633 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1634 path->multi[path->depth] = 1;
1639 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1640 hda_nid_t target_dac, struct nid_path *path)
1642 if (__parse_output_path(codec, nid, target_dac, path, 1, -1)) {
1643 path->path[path->depth] = nid;
1650 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1652 struct via_spec *spec = codec->spec;
1653 const struct auto_pin_cfg *cfg = &spec->autocfg;
1657 spec->multiout.dac_nids = spec->private_dac_nids;
1658 spec->multiout.num_dacs = cfg->line_outs;
1659 for (i = 0; i < cfg->line_outs; i++) {
1660 nid = cfg->line_out_pins[i];
1663 if (parse_output_path(codec, nid, 0, &spec->out_path[i]))
1664 spec->private_dac_nids[i] = spec->out_path[i].path[0];
1669 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1670 int chs, bool check_dac, struct nid_path *path)
1672 struct via_spec *spec = codec->spec;
1674 hda_nid_t dac, pin, sel, nid;
1677 dac = check_dac ? path->path[0] : 0;
1678 pin = path->path[path->depth - 1];
1679 sel = path->depth > 1 ? path->path[1] : 0;
1681 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1683 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1685 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1690 sprintf(name, "%s Playback Volume", pfx);
1691 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1692 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1695 path->vol_ctl = nid;
1698 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1700 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1702 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1707 sprintf(name, "%s Playback Switch", pfx);
1708 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1709 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1712 path->mute_ctl = nid;
1717 static void mangle_smart51(struct hda_codec *codec)
1719 struct via_spec *spec = codec->spec;
1720 struct auto_pin_cfg *cfg = &spec->autocfg;
1721 struct auto_pin_cfg_item *ins = cfg->inputs;
1722 int i, j, nums, attr;
1723 int pins[AUTO_CFG_MAX_INS];
1725 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1727 for (i = 0; i < cfg->num_inputs; i++) {
1729 if (ins[i].type > AUTO_PIN_LINE_IN)
1731 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1732 if (snd_hda_get_input_pin_attr(def) != attr)
1734 for (j = 0; j < nums; j++)
1735 if (ins[pins[j]].type < ins[i].type) {
1736 memmove(pins + j + 1, pins + j,
1737 (nums - j - 1) * sizeof(int));
1743 if (cfg->line_outs + nums < 3)
1745 for (i = 0; i < nums; i++) {
1746 hda_nid_t pin = ins[pins[i]].pin;
1747 spec->smart51_pins[spec->smart51_nums++] = pin;
1748 cfg->line_out_pins[cfg->line_outs++] = pin;
1749 if (cfg->line_outs == 3)
1756 /* add playback controls from the parsed DAC table */
1757 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1759 struct via_spec *spec = codec->spec;
1760 struct auto_pin_cfg *cfg = &spec->autocfg;
1761 static const char * const chname[4] = {
1762 "Front", "Surround", "C/LFE", "Side"
1768 old_line_outs = cfg->line_outs;
1769 if (cfg->line_outs == 1)
1770 mangle_smart51(codec);
1772 err = via_auto_fill_dac_nids(codec);
1776 for (i = 0; i < cfg->line_outs; i++) {
1778 pin = cfg->line_out_pins[i];
1779 dac = spec->multiout.dac_nids[i];
1782 if (i == HDA_CLFE) {
1783 err = create_ch_ctls(codec, "Center", 1, true,
1784 &spec->out_path[i]);
1787 err = create_ch_ctls(codec, "LFE", 2, true,
1788 &spec->out_path[i]);
1792 const char *pfx = chname[i];
1793 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1794 cfg->line_outs == 1)
1796 err = create_ch_ctls(codec, pfx, 3, true,
1797 &spec->out_path[i]);
1803 idx = get_connection_index(codec, spec->aa_mix_nid,
1804 spec->multiout.dac_nids[0]);
1806 /* add control to mixer */
1807 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1808 "PCM Playback Volume",
1809 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1813 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1814 "PCM Playback Switch",
1815 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1821 cfg->line_outs = old_line_outs;
1826 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1828 struct via_spec *spec = codec->spec;
1829 struct nid_path *path;
1835 if (parse_output_path(codec, pin, 0, &spec->hp_path))
1836 spec->hp_dac_nid = spec->hp_path.path[0];
1838 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1839 &spec->hp_dep_path) &&
1843 if (spec->hp_dac_nid)
1844 path = &spec->hp_path;
1846 path = &spec->hp_dep_path;
1847 err = create_ch_ctls(codec, "Headphone", 3, false, path);
1850 if (spec->hp_dac_nid) {
1851 spec->hp_dep_path.vol_ctl = spec->hp_path.vol_ctl;
1852 spec->hp_dep_path.mute_ctl = spec->hp_path.mute_ctl;
1858 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1860 struct via_spec *spec = codec->spec;
1863 pin = spec->autocfg.speaker_pins[0];
1864 if (!spec->autocfg.speaker_outs || !pin)
1867 if (parse_output_path(codec, pin, 0, &spec->speaker_path)) {
1868 dac = spec->speaker_path.path[0];
1869 spec->multiout.extra_out_nid[0] = dac;
1870 return create_ch_ctls(codec, "Speaker", 3, true,
1871 &spec->speaker_path);
1873 if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1874 &spec->speaker_path))
1875 return create_ch_ctls(codec, "Speaker", 3, false,
1876 &spec->speaker_path);
1882 static int via_fill_adcs(struct hda_codec *codec)
1884 struct via_spec *spec = codec->spec;
1885 hda_nid_t nid = codec->start_nid;
1888 for (i = 0; i < codec->num_nodes; i++, nid++) {
1889 unsigned int wcaps = get_wcaps(codec, nid);
1890 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1892 if (wcaps & AC_WCAP_DIGITAL)
1894 if (!(wcaps & AC_WCAP_CONN_LIST))
1896 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1898 spec->adc_nids[spec->num_adc_nids++] = nid;
1903 /* input-src control */
1904 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1905 struct snd_ctl_elem_info *uinfo)
1907 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1908 struct via_spec *spec = codec->spec;
1910 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1912 uinfo->value.enumerated.items = spec->num_inputs;
1913 if (uinfo->value.enumerated.item >= spec->num_inputs)
1914 uinfo->value.enumerated.item = spec->num_inputs - 1;
1915 strcpy(uinfo->value.enumerated.name,
1916 spec->inputs[uinfo->value.enumerated.item].label);
1920 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1921 struct snd_ctl_elem_value *ucontrol)
1923 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1924 struct via_spec *spec = codec->spec;
1925 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1927 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
1931 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1932 struct snd_ctl_elem_value *ucontrol)
1934 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1935 struct via_spec *spec = codec->spec;
1936 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1940 cur = ucontrol->value.enumerated.item[0];
1941 if (cur < 0 || cur >= spec->num_inputs)
1943 if (spec->cur_mux[idx] == cur)
1945 spec->cur_mux[idx] = cur;
1946 if (spec->dyn_adc_switch) {
1947 int adc_idx = spec->inputs[cur].adc_idx;
1948 mux = spec->mux_nids[adc_idx];
1949 via_dyn_adc_pcm_resetup(codec, cur);
1951 mux = spec->mux_nids[idx];
1952 if (snd_BUG_ON(!mux))
1957 /* switch to D0 beofre change index */
1958 if (snd_hda_codec_read(codec, mux, 0,
1959 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1960 snd_hda_codec_write(codec, mux, 0,
1961 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1962 snd_hda_codec_write(codec, mux, 0,
1963 AC_VERB_SET_CONNECT_SEL,
1964 spec->inputs[cur].mux_idx);
1967 /* update jack power state */
1968 set_widgets_power_state(codec);
1972 static const struct snd_kcontrol_new via_input_src_ctl = {
1973 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1974 /* The multiple "Capture Source" controls confuse alsamixer
1975 * So call somewhat different..
1977 /* .name = "Capture Source", */
1978 .name = "Input Source",
1979 .info = via_mux_enum_info,
1980 .get = via_mux_enum_get,
1981 .put = via_mux_enum_put,
1984 static int create_input_src_ctls(struct hda_codec *codec, int count)
1986 struct via_spec *spec = codec->spec;
1987 struct snd_kcontrol_new *knew;
1989 if (spec->num_inputs <= 1 || !count)
1990 return 0; /* no need for single src */
1992 knew = via_clone_control(spec, &via_input_src_ctl);
1995 knew->count = count;
1999 /* add the powersave loopback-list entry */
2000 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2002 struct hda_amp_list *list;
2004 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2006 list = spec->loopback_list + spec->num_loopbacks;
2008 list->dir = HDA_INPUT;
2010 spec->num_loopbacks++;
2011 spec->loopback.amplist = spec->loopback_list;
2014 /* check whether the path from src to dst is reachable */
2015 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2016 hda_nid_t dst, int depth)
2021 nums = snd_hda_get_connections(codec, src, conn, ARRAY_SIZE(conn));
2022 for (i = 0; i < nums; i++)
2025 if (++depth > MAX_NID_PATH_DEPTH)
2027 for (i = 0; i < nums; i++)
2028 if (is_reachable_nid(codec, conn[i], dst, depth))
2033 /* add the input-route to the given pin */
2034 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2036 struct via_spec *spec = codec->spec;
2039 spec->inputs[spec->num_inputs].adc_idx = -1;
2040 spec->inputs[spec->num_inputs].pin = pin;
2041 for (c = 0; c < spec->num_adc_nids; c++) {
2042 if (spec->mux_nids[c]) {
2043 idx = get_connection_index(codec, spec->mux_nids[c],
2047 spec->inputs[spec->num_inputs].mux_idx = idx;
2049 if (!is_reachable_nid(codec, spec->adc_nids[c], pin, 0))
2052 spec->inputs[spec->num_inputs].adc_idx = c;
2053 /* Can primary ADC satisfy all inputs? */
2054 if (!spec->dyn_adc_switch &&
2055 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2056 snd_printd(KERN_INFO
2057 "via: dynamic ADC switching enabled\n");
2058 spec->dyn_adc_switch = 1;
2065 static int get_mux_nids(struct hda_codec *codec);
2067 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2068 static int parse_analog_inputs(struct hda_codec *codec)
2070 struct via_spec *spec = codec->spec;
2071 const struct auto_pin_cfg *cfg = &spec->autocfg;
2074 err = via_fill_adcs(codec);
2077 err = get_mux_nids(codec);
2081 /* fill all input-routes */
2082 for (i = 0; i < cfg->num_inputs; i++) {
2083 if (add_input_route(codec, cfg->inputs[i].pin))
2084 spec->inputs[spec->num_inputs++].label =
2085 hda_get_autocfg_input_label(codec, cfg, i);
2088 /* check for internal loopback recording */
2089 if (spec->aa_mix_nid &&
2090 add_input_route(codec, spec->aa_mix_nid))
2091 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2096 /* create analog-loopback volume/switch controls */
2097 static int create_loopback_ctls(struct hda_codec *codec)
2099 struct via_spec *spec = codec->spec;
2100 const struct auto_pin_cfg *cfg = &spec->autocfg;
2101 const char *prev_label = NULL;
2105 if (!spec->aa_mix_nid)
2108 for (i = 0; i < cfg->num_inputs; i++) {
2109 hda_nid_t pin = cfg->inputs[i].pin;
2110 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2112 if (prev_label && !strcmp(label, prev_label))
2117 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2119 err = via_new_analog_input(spec, label, type_idx,
2120 idx, spec->aa_mix_nid);
2123 add_loopback_list(spec, spec->aa_mix_nid, idx);
2126 /* remember the label for smart51 control */
2127 for (j = 0; j < spec->smart51_nums; j++) {
2128 if (spec->smart51_pins[j] == pin) {
2129 spec->smart51_idxs[j] = idx;
2130 spec->smart51_labels[j] = label;
2138 /* create mic-boost controls (if present) */
2139 static int create_mic_boost_ctls(struct hda_codec *codec)
2141 struct via_spec *spec = codec->spec;
2142 const struct auto_pin_cfg *cfg = &spec->autocfg;
2145 for (i = 0; i < cfg->num_inputs; i++) {
2146 hda_nid_t pin = cfg->inputs[i].pin;
2151 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2153 caps = query_amp_caps(codec, pin, HDA_INPUT);
2154 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2156 label = hda_get_autocfg_input_label(codec, cfg, i);
2157 snprintf(name, sizeof(name), "%s Boost Volume", label);
2158 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2159 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2166 /* create capture and input-src controls for multiple streams */
2167 static int create_multi_adc_ctls(struct hda_codec *codec)
2169 struct via_spec *spec = codec->spec;
2172 /* create capture mixer elements */
2173 for (i = 0; i < spec->num_adc_nids; i++) {
2174 hda_nid_t adc = spec->adc_nids[i];
2175 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2176 "Capture Volume", i,
2177 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2181 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2182 "Capture Switch", i,
2183 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2189 /* input-source control */
2190 for (i = 0; i < spec->num_adc_nids; i++)
2191 if (!spec->mux_nids[i])
2193 err = create_input_src_ctls(codec, i);
2199 /* bind capture volume/switch */
2200 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2201 HDA_BIND_VOL("Capture Volume", 0);
2202 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2203 HDA_BIND_SW("Capture Switch", 0);
2205 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2206 struct hda_ctl_ops *ops)
2208 struct hda_bind_ctls *ctl;
2211 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2215 for (i = 0; i < spec->num_adc_nids; i++)
2217 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2222 /* create capture and input-src controls for dynamic ADC-switch case */
2223 static int create_dyn_adc_ctls(struct hda_codec *codec)
2225 struct via_spec *spec = codec->spec;
2226 struct snd_kcontrol_new *knew;
2229 /* set up the bind capture ctls */
2230 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2233 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2237 /* create capture mixer elements */
2238 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2241 knew->private_value = (long)spec->bind_cap_vol;
2243 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2246 knew->private_value = (long)spec->bind_cap_sw;
2248 /* input-source control */
2249 err = create_input_src_ctls(codec, 1);
2255 /* parse and create capture-related stuff */
2256 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2258 struct via_spec *spec = codec->spec;
2261 err = parse_analog_inputs(codec);
2264 if (spec->dyn_adc_switch)
2265 err = create_dyn_adc_ctls(codec);
2267 err = create_multi_adc_ctls(codec);
2270 err = create_loopback_ctls(codec);
2273 err = create_mic_boost_ctls(codec);
2279 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2281 unsigned int def_conf;
2282 unsigned char seqassoc;
2284 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2285 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2286 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2287 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2288 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2289 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2290 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2296 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2297 struct snd_ctl_elem_value *ucontrol)
2299 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2300 struct via_spec *spec = codec->spec;
2302 if (spec->codec_type != VT1708)
2304 spec->vt1708_jack_detect =
2305 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2306 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2310 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2311 struct snd_ctl_elem_value *ucontrol)
2313 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2314 struct via_spec *spec = codec->spec;
2317 if (spec->codec_type != VT1708)
2319 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2320 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2321 == !spec->vt1708_jack_detect;
2322 if (spec->vt1708_jack_detect) {
2323 mute_aa_path(codec, 1);
2324 notify_aa_path_ctls(codec);
2329 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2330 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2331 .name = "Jack Detect",
2333 .info = snd_ctl_boolean_mono_info,
2334 .get = vt1708_jack_detect_get,
2335 .put = vt1708_jack_detect_put,
2338 static void fill_dig_outs(struct hda_codec *codec);
2339 static void fill_dig_in(struct hda_codec *codec);
2341 static int via_parse_auto_config(struct hda_codec *codec)
2343 struct via_spec *spec = codec->spec;
2346 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2349 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2352 err = via_auto_create_multi_out_ctls(codec);
2355 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2358 err = via_auto_create_speaker_ctls(codec);
2361 err = via_auto_create_analog_input_ctls(codec);
2365 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2367 fill_dig_outs(codec);
2370 if (spec->kctls.list)
2371 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2373 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2375 if (spec->hp_dac_nid && spec->hp_dep_path.depth) {
2376 err = via_hp_build(codec);
2381 err = via_smart51_build(codec);
2385 /* assign slave outs */
2386 if (spec->slave_dig_outs[0])
2387 codec->slave_dig_outs = spec->slave_dig_outs;
2392 static void via_auto_init_dig_outs(struct hda_codec *codec)
2394 struct via_spec *spec = codec->spec;
2395 if (spec->multiout.dig_out_nid)
2396 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2397 if (spec->slave_dig_outs[0])
2398 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2401 static void via_auto_init_dig_in(struct hda_codec *codec)
2403 struct via_spec *spec = codec->spec;
2404 if (!spec->dig_in_nid)
2406 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2407 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2410 /* initialize the unsolicited events */
2411 static void via_auto_init_unsol_event(struct hda_codec *codec)
2413 struct via_spec *spec = codec->spec;
2414 struct auto_pin_cfg *cfg = &spec->autocfg;
2418 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2419 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2420 AC_VERB_SET_UNSOLICITED_ENABLE,
2421 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2423 if (cfg->speaker_pins[0])
2424 ev = VIA_LINE_EVENT;
2427 for (i = 0; i < cfg->line_outs; i++) {
2428 if (cfg->line_out_pins[i] &&
2429 is_jack_detectable(codec, cfg->line_out_pins[i]))
2430 snd_hda_codec_write(codec, cfg->line_out_pins[0], 0,
2431 AC_VERB_SET_UNSOLICITED_ENABLE,
2432 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2435 for (i = 0; i < cfg->num_inputs; i++) {
2436 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2437 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2438 AC_VERB_SET_UNSOLICITED_ENABLE,
2439 AC_USRSP_EN | VIA_JACK_EVENT);
2443 static int via_init(struct hda_codec *codec)
2445 struct via_spec *spec = codec->spec;
2448 for (i = 0; i < spec->num_iverbs; i++)
2449 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2451 via_auto_init_multi_out(codec);
2452 via_auto_init_hp_out(codec);
2453 via_auto_init_speaker_out(codec);
2454 via_auto_init_analog_input(codec);
2455 via_auto_init_dig_outs(codec);
2456 via_auto_init_dig_in(codec);
2458 via_auto_init_unsol_event(codec);
2460 via_hp_automute(codec);
2461 via_line_automute(codec, false);
2466 static void vt1708_update_hp_jack_state(struct work_struct *work)
2468 struct via_spec *spec = container_of(work, struct via_spec,
2469 vt1708_hp_work.work);
2470 if (spec->codec_type != VT1708)
2472 /* if jack state toggled */
2473 if (spec->vt1708_hp_present
2474 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2475 spec->vt1708_hp_present ^= 1;
2476 via_hp_automute(spec->codec);
2478 vt1708_start_hp_work(spec);
2481 static int get_mux_nids(struct hda_codec *codec)
2483 struct via_spec *spec = codec->spec;
2484 hda_nid_t nid, conn[8];
2488 for (i = 0; i < spec->num_adc_nids; i++) {
2489 nid = spec->adc_nids[i];
2491 type = get_wcaps_type(get_wcaps(codec, nid));
2492 if (type == AC_WID_PIN)
2494 n = snd_hda_get_connections(codec, nid, conn,
2499 spec->mux_nids[i] = nid;
2508 static int patch_vt1708(struct hda_codec *codec)
2510 struct via_spec *spec;
2513 /* create a codec specific record */
2514 spec = via_new_spec(codec);
2518 spec->aa_mix_nid = 0x17;
2520 /* Add HP and CD pin config connect bit re-config action */
2521 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2522 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2524 /* automatic parse from the BIOS config */
2525 err = via_parse_auto_config(codec);
2531 /* add jack detect on/off control */
2532 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2535 /* disable 32bit format on VT1708 */
2536 if (codec->vendor_id == 0x11061708)
2537 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2539 codec->patch_ops = via_patch_ops;
2541 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2545 static int patch_vt1709(struct hda_codec *codec)
2547 struct via_spec *spec;
2550 /* create a codec specific record */
2551 spec = via_new_spec(codec);
2555 spec->aa_mix_nid = 0x18;
2557 err = via_parse_auto_config(codec);
2563 codec->patch_ops = via_patch_ops;
2568 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2570 struct via_spec *spec = codec->spec;
2574 if ((spec->codec_type != VT1708B_4CH) &&
2575 (codec->vendor_id != 0x11064397))
2578 /* SW0 (17h) = stereo mixer */
2580 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2581 == ((spec->codec_type == VT1708S) ? 5 : 0));
2583 /* PW 1/2/5 (1ah/1bh/1eh) */
2585 set_pin_power_state(codec, 0x1a, &parm);
2586 set_pin_power_state(codec, 0x1b, &parm);
2587 set_pin_power_state(codec, 0x1e, &parm);
2590 /* SW0 (17h), AIW 0/1 (13h/14h) */
2591 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2592 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2593 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2596 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2598 set_pin_power_state(codec, 0x19, &parm);
2599 if (spec->smart51_enabled)
2600 set_pin_power_state(codec, 0x1b, &parm);
2601 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2602 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2604 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2607 set_pin_power_state(codec, 0x22, &parm);
2608 if (spec->smart51_enabled)
2609 set_pin_power_state(codec, 0x1a, &parm);
2610 snd_hda_codec_write(codec, 0x26, 0,
2611 AC_VERB_SET_POWER_STATE, parm);
2612 snd_hda_codec_write(codec, 0x24, 0,
2613 AC_VERB_SET_POWER_STATE, parm);
2614 } else if (codec->vendor_id == 0x11064397) {
2615 /* PW7(23h), SW2(27h), AOW2(25h) */
2617 set_pin_power_state(codec, 0x23, &parm);
2618 if (spec->smart51_enabled)
2619 set_pin_power_state(codec, 0x1a, &parm);
2620 snd_hda_codec_write(codec, 0x27, 0,
2621 AC_VERB_SET_POWER_STATE, parm);
2622 snd_hda_codec_write(codec, 0x25, 0,
2623 AC_VERB_SET_POWER_STATE, parm);
2626 /* PW 3/4/7 (1ch/1dh/23h) */
2628 /* force to D0 for internal Speaker */
2629 set_pin_power_state(codec, 0x1c, &parm);
2630 set_pin_power_state(codec, 0x1d, &parm);
2632 set_pin_power_state(codec, 0x23, &parm);
2634 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2635 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2636 imux_is_smixer ? AC_PWRST_D0 : parm);
2637 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2639 snd_hda_codec_write(codec, 0x25, 0,
2640 AC_VERB_SET_POWER_STATE, parm);
2641 snd_hda_codec_write(codec, 0x27, 0,
2642 AC_VERB_SET_POWER_STATE, parm);
2643 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2644 snd_hda_codec_write(codec, 0x25, 0,
2645 AC_VERB_SET_POWER_STATE, parm);
2648 static int patch_vt1708S(struct hda_codec *codec);
2649 static int patch_vt1708B(struct hda_codec *codec)
2651 struct via_spec *spec;
2654 if (get_codec_type(codec) == VT1708BCE)
2655 return patch_vt1708S(codec);
2657 /* create a codec specific record */
2658 spec = via_new_spec(codec);
2662 spec->aa_mix_nid = 0x16;
2664 /* automatic parse from the BIOS config */
2665 err = via_parse_auto_config(codec);
2671 codec->patch_ops = via_patch_ops;
2673 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2678 /* Patch for VT1708S */
2679 static const struct hda_verb vt1708S_init_verbs[] = {
2680 /* Enable Mic Boost Volume backdoor */
2682 /* don't bybass mixer */
2687 /* fill out digital output widgets; one for master and one for slave outputs */
2688 static void fill_dig_outs(struct hda_codec *codec)
2690 struct via_spec *spec = codec->spec;
2693 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2697 nid = spec->autocfg.dig_out_pins[i];
2700 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2703 if (!spec->multiout.dig_out_nid)
2704 spec->multiout.dig_out_nid = nid;
2706 spec->slave_dig_outs[0] = nid;
2707 break; /* at most two dig outs */
2712 static void fill_dig_in(struct hda_codec *codec)
2714 struct via_spec *spec = codec->spec;
2718 if (!spec->autocfg.dig_in_pin)
2721 dig_nid = codec->start_nid;
2722 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2723 unsigned int wcaps = get_wcaps(codec, dig_nid);
2724 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2726 if (!(wcaps & AC_WCAP_DIGITAL))
2728 if (!(wcaps & AC_WCAP_CONN_LIST))
2730 err = get_connection_index(codec, dig_nid,
2731 spec->autocfg.dig_in_pin);
2733 spec->dig_in_nid = dig_nid;
2739 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2740 int offset, int num_steps, int step_size)
2742 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2743 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2744 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2745 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2746 (0 << AC_AMPCAP_MUTE_SHIFT));
2749 static int patch_vt1708S(struct hda_codec *codec)
2751 struct via_spec *spec;
2754 /* create a codec specific record */
2755 spec = via_new_spec(codec);
2759 spec->aa_mix_nid = 0x16;
2760 override_mic_boost(codec, 0x1a, 0, 3, 40);
2761 override_mic_boost(codec, 0x1e, 0, 3, 40);
2763 /* automatic parse from the BIOS config */
2764 err = via_parse_auto_config(codec);
2770 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2772 codec->patch_ops = via_patch_ops;
2774 /* correct names for VT1708BCE */
2775 if (get_codec_type(codec) == VT1708BCE) {
2776 kfree(codec->chip_name);
2777 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2778 snprintf(codec->bus->card->mixername,
2779 sizeof(codec->bus->card->mixername),
2780 "%s %s", codec->vendor_name, codec->chip_name);
2782 /* correct names for VT1705 */
2783 if (codec->vendor_id == 0x11064397) {
2784 kfree(codec->chip_name);
2785 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2786 snprintf(codec->bus->card->mixername,
2787 sizeof(codec->bus->card->mixername),
2788 "%s %s", codec->vendor_name, codec->chip_name);
2790 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2794 /* Patch for VT1702 */
2796 static const struct hda_verb vt1702_init_verbs[] = {
2804 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2806 int imux_is_smixer =
2807 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2810 /* PW 1/2/5 (14h/15h/18h) */
2812 set_pin_power_state(codec, 0x14, &parm);
2813 set_pin_power_state(codec, 0x15, &parm);
2814 set_pin_power_state(codec, 0x18, &parm);
2816 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2817 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2818 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2819 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2820 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2821 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2824 /* PW 3/4 (16h/17h) */
2826 set_pin_power_state(codec, 0x17, &parm);
2827 set_pin_power_state(codec, 0x16, &parm);
2828 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2829 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2830 imux_is_smixer ? AC_PWRST_D0 : parm);
2831 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2832 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2835 static int patch_vt1702(struct hda_codec *codec)
2837 struct via_spec *spec;
2840 /* create a codec specific record */
2841 spec = via_new_spec(codec);
2845 spec->aa_mix_nid = 0x1a;
2847 /* limit AA path volume to 0 dB */
2848 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2849 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2850 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2851 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2852 (1 << AC_AMPCAP_MUTE_SHIFT));
2854 /* automatic parse from the BIOS config */
2855 err = via_parse_auto_config(codec);
2861 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
2863 codec->patch_ops = via_patch_ops;
2865 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
2869 /* Patch for VT1718S */
2871 static const struct hda_verb vt1718S_init_verbs[] = {
2872 /* Enable MW0 adjust Gain 5 */
2874 /* Enable Boost Volume backdoor */
2880 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2882 struct via_spec *spec = codec->spec;
2885 /* MUX6 (1eh) = stereo mixer */
2887 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2889 /* PW 5/6/7 (29h/2ah/2bh) */
2891 set_pin_power_state(codec, 0x29, &parm);
2892 set_pin_power_state(codec, 0x2a, &parm);
2893 set_pin_power_state(codec, 0x2b, &parm);
2896 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2897 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2898 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2899 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2900 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2903 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2905 set_pin_power_state(codec, 0x27, &parm);
2906 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2907 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2909 /* PW2 (26h), AOW2 (ah) */
2911 set_pin_power_state(codec, 0x26, &parm);
2912 if (spec->smart51_enabled)
2913 set_pin_power_state(codec, 0x2b, &parm);
2914 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
2916 /* PW0 (24h), AOW0 (8h) */
2918 set_pin_power_state(codec, 0x24, &parm);
2919 if (!spec->hp_independent_mode) /* check for redirected HP */
2920 set_pin_power_state(codec, 0x28, &parm);
2921 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2922 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
2923 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
2924 imux_is_smixer ? AC_PWRST_D0 : parm);
2926 /* PW1 (25h), AOW1 (9h) */
2928 set_pin_power_state(codec, 0x25, &parm);
2929 if (spec->smart51_enabled)
2930 set_pin_power_state(codec, 0x2a, &parm);
2931 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
2933 if (spec->hp_independent_mode) {
2934 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
2936 set_pin_power_state(codec, 0x28, &parm);
2937 snd_hda_codec_write(codec, 0x1b, 0,
2938 AC_VERB_SET_POWER_STATE, parm);
2939 snd_hda_codec_write(codec, 0x34, 0,
2940 AC_VERB_SET_POWER_STATE, parm);
2941 snd_hda_codec_write(codec, 0xc, 0,
2942 AC_VERB_SET_POWER_STATE, parm);
2946 static int patch_vt1718S(struct hda_codec *codec)
2948 struct via_spec *spec;
2951 /* create a codec specific record */
2952 spec = via_new_spec(codec);
2956 spec->aa_mix_nid = 0x21;
2957 override_mic_boost(codec, 0x2b, 0, 3, 40);
2958 override_mic_boost(codec, 0x29, 0, 3, 40);
2960 /* automatic parse from the BIOS config */
2961 err = via_parse_auto_config(codec);
2967 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
2969 codec->patch_ops = via_patch_ops;
2971 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
2976 /* Patch for VT1716S */
2978 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
2979 struct snd_ctl_elem_info *uinfo)
2981 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2983 uinfo->value.integer.min = 0;
2984 uinfo->value.integer.max = 1;
2988 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
2989 struct snd_ctl_elem_value *ucontrol)
2991 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2994 index = snd_hda_codec_read(codec, 0x26, 0,
2995 AC_VERB_GET_CONNECT_SEL, 0);
2997 *ucontrol->value.integer.value = index;
3002 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3003 struct snd_ctl_elem_value *ucontrol)
3005 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3006 struct via_spec *spec = codec->spec;
3007 int index = *ucontrol->value.integer.value;
3009 snd_hda_codec_write(codec, 0x26, 0,
3010 AC_VERB_SET_CONNECT_SEL, index);
3011 spec->dmic_enabled = index;
3012 set_widgets_power_state(codec);
3016 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3017 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3019 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3020 .name = "Digital Mic Capture Switch",
3021 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3023 .info = vt1716s_dmic_info,
3024 .get = vt1716s_dmic_get,
3025 .put = vt1716s_dmic_put,
3031 /* mono-out mixer elements */
3032 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3033 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3037 static const struct hda_verb vt1716S_init_verbs[] = {
3038 /* Enable Boost Volume backdoor */
3040 /* don't bybass mixer */
3042 /* Enable mono output */
3047 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3049 struct via_spec *spec = codec->spec;
3052 unsigned int mono_out, present;
3053 /* SW0 (17h) = stereo mixer */
3055 (snd_hda_codec_read(codec, 0x17, 0,
3056 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3058 /* PW 1/2/5 (1ah/1bh/1eh) */
3060 set_pin_power_state(codec, 0x1a, &parm);
3061 set_pin_power_state(codec, 0x1b, &parm);
3062 set_pin_power_state(codec, 0x1e, &parm);
3065 /* SW0 (17h), AIW0(13h) */
3066 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3067 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3070 set_pin_power_state(codec, 0x1e, &parm);
3072 if (spec->dmic_enabled)
3073 set_pin_power_state(codec, 0x22, &parm);
3075 snd_hda_codec_write(codec, 0x22, 0,
3076 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3078 /* SW2(26h), AIW1(14h) */
3079 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3080 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3083 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3085 set_pin_power_state(codec, 0x19, &parm);
3086 /* Smart 5.1 PW2(1bh) */
3087 if (spec->smart51_enabled)
3088 set_pin_power_state(codec, 0x1b, &parm);
3089 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3090 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3092 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3094 set_pin_power_state(codec, 0x23, &parm);
3095 /* Smart 5.1 PW1(1ah) */
3096 if (spec->smart51_enabled)
3097 set_pin_power_state(codec, 0x1a, &parm);
3098 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3100 /* Smart 5.1 PW5(1eh) */
3101 if (spec->smart51_enabled)
3102 set_pin_power_state(codec, 0x1e, &parm);
3103 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3106 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3107 present = snd_hda_jack_detect(codec, 0x1c);
3112 present = snd_hda_jack_detect(codec, 0x1d);
3113 if (!spec->hp_independent_mode && present)
3118 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3119 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3120 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3121 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3123 /* PW 3/4 (1ch/1dh) */
3125 set_pin_power_state(codec, 0x1c, &parm);
3126 set_pin_power_state(codec, 0x1d, &parm);
3127 /* HP Independent Mode, power on AOW3 */
3128 if (spec->hp_independent_mode)
3129 snd_hda_codec_write(codec, 0x25, 0,
3130 AC_VERB_SET_POWER_STATE, parm);
3132 /* force to D0 for internal Speaker */
3133 /* MW0 (16h), AOW0 (10h) */
3134 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3135 imux_is_smixer ? AC_PWRST_D0 : parm);
3136 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3137 mono_out ? AC_PWRST_D0 : parm);
3140 static int patch_vt1716S(struct hda_codec *codec)
3142 struct via_spec *spec;
3145 /* create a codec specific record */
3146 spec = via_new_spec(codec);
3150 spec->aa_mix_nid = 0x16;
3151 override_mic_boost(codec, 0x1a, 0, 3, 40);
3152 override_mic_boost(codec, 0x1e, 0, 3, 40);
3154 /* automatic parse from the BIOS config */
3155 err = via_parse_auto_config(codec);
3161 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3163 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3166 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3168 codec->patch_ops = via_patch_ops;
3170 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3176 static const struct hda_verb vt2002P_init_verbs[] = {
3177 /* Class-D speaker related verbs */
3181 /* Enable Boost Volume backdoor */
3183 /* Enable AOW0 to MW9 */
3188 static const struct hda_verb vt1802_init_verbs[] = {
3189 /* Enable Boost Volume backdoor */
3191 /* Enable AOW0 to MW9 */
3196 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3198 struct via_spec *spec = codec->spec;
3201 unsigned int present;
3202 /* MUX9 (1eh) = stereo mixer */
3204 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3206 /* PW 5/6/7 (29h/2ah/2bh) */
3208 set_pin_power_state(codec, 0x29, &parm);
3209 set_pin_power_state(codec, 0x2a, &parm);
3210 set_pin_power_state(codec, 0x2b, &parm);
3212 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3213 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3214 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3215 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3216 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3220 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3222 if (spec->codec_type == VT1802) {
3223 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3225 set_pin_power_state(codec, 0x28, &parm);
3226 snd_hda_codec_write(codec, 0x18, 0,
3227 AC_VERB_SET_POWER_STATE, parm);
3228 snd_hda_codec_write(codec, 0x38, 0,
3229 AC_VERB_SET_POWER_STATE, parm);
3231 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3233 set_pin_power_state(codec, 0x26, &parm);
3234 snd_hda_codec_write(codec, 0x1c, 0,
3235 AC_VERB_SET_POWER_STATE, parm);
3236 snd_hda_codec_write(codec, 0x37, 0,
3237 AC_VERB_SET_POWER_STATE, parm);
3240 if (spec->codec_type == VT1802) {
3241 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3243 set_pin_power_state(codec, 0x25, &parm);
3244 snd_hda_codec_write(codec, 0x15, 0,
3245 AC_VERB_SET_POWER_STATE, parm);
3246 snd_hda_codec_write(codec, 0x35, 0,
3247 AC_VERB_SET_POWER_STATE, parm);
3249 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3251 set_pin_power_state(codec, 0x25, &parm);
3252 snd_hda_codec_write(codec, 0x19, 0,
3253 AC_VERB_SET_POWER_STATE, parm);
3254 snd_hda_codec_write(codec, 0x35, 0,
3255 AC_VERB_SET_POWER_STATE, parm);
3258 if (spec->hp_independent_mode)
3259 snd_hda_codec_write(codec, 0x9, 0,
3260 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3263 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3264 present = snd_hda_jack_detect(codec, 0x25);
3267 set_pin_power_state(codec, 0x24, &parm);
3268 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3269 if (spec->codec_type == VT1802)
3270 snd_hda_codec_write(codec, 0x14, 0,
3271 AC_VERB_SET_POWER_STATE, parm);
3273 snd_hda_codec_write(codec, 0x18, 0,
3274 AC_VERB_SET_POWER_STATE, parm);
3275 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3278 present = snd_hda_jack_detect(codec, 0x26);
3280 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3281 if (spec->codec_type == VT1802) {
3282 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3283 snd_hda_codec_write(codec, 0x33, 0,
3284 AC_VERB_SET_POWER_STATE, parm);
3285 snd_hda_codec_write(codec, 0x1c, 0,
3286 AC_VERB_SET_POWER_STATE, parm);
3287 snd_hda_codec_write(codec, 0x3c, 0,
3288 AC_VERB_SET_POWER_STATE, parm);
3290 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3291 snd_hda_codec_write(codec, 0x31, 0,
3292 AC_VERB_SET_POWER_STATE, parm);
3293 snd_hda_codec_write(codec, 0x17, 0,
3294 AC_VERB_SET_POWER_STATE, parm);
3295 snd_hda_codec_write(codec, 0x3b, 0,
3296 AC_VERB_SET_POWER_STATE, parm);
3299 if (imux_is_smixer || !is_aa_path_mute(codec))
3300 snd_hda_codec_write(codec, 0x21, 0,
3301 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3303 snd_hda_codec_write(codec, 0x21, 0,
3304 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3307 /* patch for vt2002P */
3308 static int patch_vt2002P(struct hda_codec *codec)
3310 struct via_spec *spec;
3313 /* create a codec specific record */
3314 spec = via_new_spec(codec);
3318 spec->aa_mix_nid = 0x21;
3319 override_mic_boost(codec, 0x2b, 0, 3, 40);
3320 override_mic_boost(codec, 0x29, 0, 3, 40);
3322 /* automatic parse from the BIOS config */
3323 err = via_parse_auto_config(codec);
3329 if (spec->codec_type == VT1802)
3330 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3332 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3334 codec->patch_ops = via_patch_ops;
3336 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3342 static const struct hda_verb vt1812_init_verbs[] = {
3343 /* Enable Boost Volume backdoor */
3345 /* Enable AOW0 to MW9 */
3350 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3352 struct via_spec *spec = codec->spec;
3353 int imux_is_smixer =
3354 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3356 unsigned int present;
3357 /* MUX10 (1eh) = stereo mixer */
3359 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3361 /* PW 5/6/7 (29h/2ah/2bh) */
3363 set_pin_power_state(codec, 0x29, &parm);
3364 set_pin_power_state(codec, 0x2a, &parm);
3365 set_pin_power_state(codec, 0x2b, &parm);
3367 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3368 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3369 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3370 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3371 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3375 snd_hda_codec_write(codec, 0x8, 0,
3376 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3378 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3380 set_pin_power_state(codec, 0x28, &parm);
3381 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3382 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3384 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3386 set_pin_power_state(codec, 0x25, &parm);
3387 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3388 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3389 if (spec->hp_independent_mode)
3390 snd_hda_codec_write(codec, 0x9, 0,
3391 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3393 /* Internal Speaker */
3394 /* PW0 (24h), MW0(14h), MUX0(34h) */
3395 present = snd_hda_jack_detect(codec, 0x25);
3398 set_pin_power_state(codec, 0x24, &parm);
3400 snd_hda_codec_write(codec, 0x14, 0,
3401 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3402 snd_hda_codec_write(codec, 0x34, 0,
3403 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3405 snd_hda_codec_write(codec, 0x14, 0,
3406 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3407 snd_hda_codec_write(codec, 0x34, 0,
3408 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3413 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3414 present = snd_hda_jack_detect(codec, 0x28);
3417 set_pin_power_state(codec, 0x31, &parm);
3419 snd_hda_codec_write(codec, 0x1c, 0,
3420 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3421 snd_hda_codec_write(codec, 0x3c, 0,
3422 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3423 snd_hda_codec_write(codec, 0x3e, 0,
3424 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3426 snd_hda_codec_write(codec, 0x1c, 0,
3427 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3428 snd_hda_codec_write(codec, 0x3c, 0,
3429 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3430 snd_hda_codec_write(codec, 0x3e, 0,
3431 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3434 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3436 set_pin_power_state(codec, 0x33, &parm);
3437 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3438 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3442 /* patch for vt1812 */
3443 static int patch_vt1812(struct hda_codec *codec)
3445 struct via_spec *spec;
3448 /* create a codec specific record */
3449 spec = via_new_spec(codec);
3453 spec->aa_mix_nid = 0x21;
3454 override_mic_boost(codec, 0x2b, 0, 3, 40);
3455 override_mic_boost(codec, 0x29, 0, 3, 40);
3457 /* automatic parse from the BIOS config */
3458 err = via_parse_auto_config(codec);
3464 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3466 codec->patch_ops = via_patch_ops;
3468 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3475 static const struct hda_codec_preset snd_hda_preset_via[] = {
3476 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3477 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3478 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3479 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3480 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3481 .patch = patch_vt1709},
3482 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3483 .patch = patch_vt1709},
3484 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3485 .patch = patch_vt1709},
3486 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3487 .patch = patch_vt1709},
3488 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3489 .patch = patch_vt1709},
3490 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3491 .patch = patch_vt1709},
3492 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3493 .patch = patch_vt1709},
3494 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3495 .patch = patch_vt1709},
3496 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3497 .patch = patch_vt1708B},
3498 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3499 .patch = patch_vt1708B},
3500 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3501 .patch = patch_vt1708B},
3502 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3503 .patch = patch_vt1708B},
3504 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3505 .patch = patch_vt1708B},
3506 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3507 .patch = patch_vt1708B},
3508 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3509 .patch = patch_vt1708B},
3510 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3511 .patch = patch_vt1708B},
3512 { .id = 0x11060397, .name = "VT1708S",
3513 .patch = patch_vt1708S},
3514 { .id = 0x11061397, .name = "VT1708S",
3515 .patch = patch_vt1708S},
3516 { .id = 0x11062397, .name = "VT1708S",
3517 .patch = patch_vt1708S},
3518 { .id = 0x11063397, .name = "VT1708S",
3519 .patch = patch_vt1708S},
3520 { .id = 0x11064397, .name = "VT1705",
3521 .patch = patch_vt1708S},
3522 { .id = 0x11065397, .name = "VT1708S",
3523 .patch = patch_vt1708S},
3524 { .id = 0x11066397, .name = "VT1708S",
3525 .patch = patch_vt1708S},
3526 { .id = 0x11067397, .name = "VT1708S",
3527 .patch = patch_vt1708S},
3528 { .id = 0x11060398, .name = "VT1702",
3529 .patch = patch_vt1702},
3530 { .id = 0x11061398, .name = "VT1702",
3531 .patch = patch_vt1702},
3532 { .id = 0x11062398, .name = "VT1702",
3533 .patch = patch_vt1702},
3534 { .id = 0x11063398, .name = "VT1702",
3535 .patch = patch_vt1702},
3536 { .id = 0x11064398, .name = "VT1702",
3537 .patch = patch_vt1702},
3538 { .id = 0x11065398, .name = "VT1702",
3539 .patch = patch_vt1702},
3540 { .id = 0x11066398, .name = "VT1702",
3541 .patch = patch_vt1702},
3542 { .id = 0x11067398, .name = "VT1702",
3543 .patch = patch_vt1702},
3544 { .id = 0x11060428, .name = "VT1718S",
3545 .patch = patch_vt1718S},
3546 { .id = 0x11064428, .name = "VT1718S",
3547 .patch = patch_vt1718S},
3548 { .id = 0x11060441, .name = "VT2020",
3549 .patch = patch_vt1718S},
3550 { .id = 0x11064441, .name = "VT1828S",
3551 .patch = patch_vt1718S},
3552 { .id = 0x11060433, .name = "VT1716S",
3553 .patch = patch_vt1716S},
3554 { .id = 0x1106a721, .name = "VT1716S",
3555 .patch = patch_vt1716S},
3556 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3557 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3558 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3559 { .id = 0x11060440, .name = "VT1818S",
3560 .patch = patch_vt1708S},
3561 { .id = 0x11060446, .name = "VT1802",
3562 .patch = patch_vt2002P},
3563 { .id = 0x11068446, .name = "VT1802",
3564 .patch = patch_vt2002P},
3568 MODULE_ALIAS("snd-hda-codec-id:1106*");
3570 static struct hda_codec_preset_list via_list = {
3571 .preset = snd_hda_preset_via,
3572 .owner = THIS_MODULE,
3575 MODULE_LICENSE("GPL");
3576 MODULE_DESCRIPTION("VIA HD-audio codec");
3578 static int __init patch_via_init(void)
3580 return snd_hda_add_codec_preset(&via_list);
3583 static void __exit patch_via_exit(void)
3585 snd_hda_delete_codec_preset(&via_list);
3588 module_init(patch_via_init)
3589 module_exit(patch_via_exit)