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 bool hp_indep_shared; /* indep HP-DAC is shared with side ch */
132 int num_active_streams;
134 struct nid_path out_path[4];
135 struct nid_path hp_path;
136 struct nid_path hp_dep_path;
137 struct nid_path speaker_path;
140 unsigned int num_adc_nids;
141 hda_nid_t adc_nids[3];
142 hda_nid_t mux_nids[3];
143 hda_nid_t aa_mix_nid;
144 hda_nid_t dig_in_nid;
149 struct via_input inputs[AUTO_CFG_MAX_INS + 1];
150 unsigned int cur_mux[3];
152 /* dynamic ADC switching */
154 unsigned int cur_adc_stream_tag;
155 unsigned int cur_adc_format;
157 /* PCM information */
158 struct hda_pcm pcm_rec[3];
160 /* dynamic controls, init_verbs and input_mux */
161 struct auto_pin_cfg autocfg;
162 struct snd_array kctls;
163 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
166 unsigned int hp_independent_mode;
167 unsigned int dmic_enabled;
168 unsigned int no_pin_power_ctl;
169 enum VIA_HDA_CODEC codec_type;
172 unsigned int smart51_nums;
173 hda_nid_t smart51_pins[2];
175 const char *smart51_labels[2];
176 unsigned int smart51_enabled;
178 /* work to check hp jack state */
179 struct hda_codec *codec;
180 struct delayed_work vt1708_hp_work;
181 int vt1708_jack_detect;
182 int vt1708_hp_present;
184 void (*set_widgets_power_state)(struct hda_codec *codec);
186 struct hda_loopback_check loopback;
188 struct hda_amp_list loopback_list[8];
190 /* bind capture-volume */
191 struct hda_bind_ctls *bind_cap_vol;
192 struct hda_bind_ctls *bind_cap_sw;
195 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
196 static struct via_spec * via_new_spec(struct hda_codec *codec)
198 struct via_spec *spec;
200 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
206 spec->codec_type = get_codec_type(codec);
207 /* VT1708BCE & VT1708S are almost same */
208 if (spec->codec_type == VT1708BCE)
209 spec->codec_type = VT1708S;
213 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
215 u32 vendor_id = codec->vendor_id;
216 u16 ven_id = vendor_id >> 16;
217 u16 dev_id = vendor_id & 0xffff;
218 enum VIA_HDA_CODEC codec_type;
221 if (ven_id != 0x1106)
222 codec_type = UNKNOWN;
223 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
225 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
226 codec_type = VT1709_10CH;
227 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
228 codec_type = VT1709_6CH;
229 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
230 codec_type = VT1708B_8CH;
231 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
232 codec_type = VT1708BCE;
233 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
234 codec_type = VT1708B_4CH;
235 else if ((dev_id & 0xfff) == 0x397
236 && (dev_id >> 12) < 8)
237 codec_type = VT1708S;
238 else if ((dev_id & 0xfff) == 0x398
239 && (dev_id >> 12) < 8)
241 else if ((dev_id & 0xfff) == 0x428
242 && (dev_id >> 12) < 8)
243 codec_type = VT1718S;
244 else if (dev_id == 0x0433 || dev_id == 0xa721)
245 codec_type = VT1716S;
246 else if (dev_id == 0x0441 || dev_id == 0x4441)
247 codec_type = VT1718S;
248 else if (dev_id == 0x0438 || dev_id == 0x4438)
249 codec_type = VT2002P;
250 else if (dev_id == 0x0448)
252 else if (dev_id == 0x0440)
253 codec_type = VT1708S;
254 else if ((dev_id & 0xfff) == 0x446)
257 codec_type = UNKNOWN;
261 #define VIA_JACK_EVENT 0x20
262 #define VIA_HP_EVENT 0x01
263 #define VIA_GPIO_EVENT 0x02
264 #define VIA_LINE_EVENT 0x03
269 VIA_CTL_WIDGET_ANALOG_MUTE,
272 static void analog_low_current_mode(struct hda_codec *codec);
273 static bool is_aa_path_mute(struct hda_codec *codec);
275 static void vt1708_start_hp_work(struct via_spec *spec)
277 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
279 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
280 !spec->vt1708_jack_detect);
281 if (!delayed_work_pending(&spec->vt1708_hp_work))
282 schedule_delayed_work(&spec->vt1708_hp_work,
283 msecs_to_jiffies(100));
286 static void vt1708_stop_hp_work(struct via_spec *spec)
288 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
290 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
291 && !is_aa_path_mute(spec->codec))
293 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
294 !spec->vt1708_jack_detect);
295 cancel_delayed_work_sync(&spec->vt1708_hp_work);
298 static void set_widgets_power_state(struct hda_codec *codec)
300 struct via_spec *spec = codec->spec;
301 if (spec->set_widgets_power_state)
302 spec->set_widgets_power_state(codec);
305 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
306 struct snd_ctl_elem_value *ucontrol)
308 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
309 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
311 set_widgets_power_state(codec);
312 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
313 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
314 if (is_aa_path_mute(codec))
315 vt1708_start_hp_work(codec->spec);
317 vt1708_stop_hp_work(codec->spec);
322 /* modify .put = snd_hda_mixer_amp_switch_put */
323 #define ANALOG_INPUT_MUTE \
324 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
327 .info = snd_hda_mixer_amp_switch_info, \
328 .get = snd_hda_mixer_amp_switch_get, \
329 .put = analog_input_switch_put, \
330 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
332 static const struct snd_kcontrol_new via_control_templates[] = {
333 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
334 HDA_CODEC_MUTE(NULL, 0, 0, 0),
339 /* add dynamic controls */
340 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
341 const struct snd_kcontrol_new *tmpl,
344 struct snd_kcontrol_new *knew;
346 snd_array_init(&spec->kctls, sizeof(*knew), 32);
347 knew = snd_array_new(&spec->kctls);
354 knew->name = kstrdup(name, GFP_KERNEL);
361 static int __via_add_control(struct via_spec *spec, int type, const char *name,
362 int idx, unsigned long val)
364 struct snd_kcontrol_new *knew;
366 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
370 if (get_amp_nid_(val))
371 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
372 knew->private_value = val;
376 #define via_add_control(spec, type, name, val) \
377 __via_add_control(spec, type, name, 0, val)
379 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
381 static void via_free_kctls(struct hda_codec *codec)
383 struct via_spec *spec = codec->spec;
385 if (spec->kctls.list) {
386 struct snd_kcontrol_new *kctl = spec->kctls.list;
388 for (i = 0; i < spec->kctls.used; i++)
391 snd_array_free(&spec->kctls);
394 /* create input playback/capture controls for the given pin */
395 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
396 int type_idx, int idx, int mix_nid)
401 sprintf(name, "%s Playback Volume", ctlname);
402 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
403 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
406 sprintf(name, "%s Playback Switch", ctlname);
407 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
408 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
414 #define get_connection_index(codec, mux, nid) \
415 snd_hda_get_conn_index(codec, mux, nid, 0)
417 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
423 caps = get_wcaps(codec, nid);
424 if (dir == HDA_INPUT)
425 caps &= AC_WCAP_IN_AMP;
427 caps &= AC_WCAP_OUT_AMP;
430 if (query_amp_caps(codec, nid, dir) & mask)
435 #define have_mute(codec, nid, dir) \
436 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
438 /* enable/disable the output-route */
439 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
440 bool enable, bool force)
443 for (i = 0; i < path->depth; i++) {
445 int idx = path->idx[i];
447 if (i < path->depth - 1)
448 dst = path->path[i + 1];
451 if (enable && path->multi[i])
452 snd_hda_codec_write(codec, dst, 0,
453 AC_VERB_SET_CONNECT_SEL, idx);
454 if (get_wcaps_type(get_wcaps(codec, src)) == AC_WID_AUD_OUT &&
455 get_wcaps_type(get_wcaps(codec, dst)) == AC_WID_AUD_MIX)
457 if (have_mute(codec, dst, HDA_INPUT)) {
458 int val = enable ? AMP_IN_UNMUTE(idx) :
460 snd_hda_codec_write(codec, dst, 0,
461 AC_VERB_SET_AMP_GAIN_MUTE, val);
463 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
465 if (have_mute(codec, src, HDA_OUTPUT)) {
466 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
467 snd_hda_codec_write(codec, src, 0,
468 AC_VERB_SET_AMP_GAIN_MUTE, val);
473 /* set the given pin as output */
474 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
479 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
481 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
482 snd_hda_codec_write(codec, pin, 0,
483 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
486 static void via_auto_init_output(struct hda_codec *codec,
487 struct nid_path *path, int pin_type,
490 struct via_spec *spec = codec->spec;
497 pin = path->path[path->depth - 1];
499 init_output_pin(codec, pin, pin_type);
500 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
501 if (caps & AC_AMPCAP_MUTE) {
503 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
504 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
508 activate_output_path(codec, path, true, force);
510 /* initialize the AA-path */
511 if (!spec->aa_mix_nid)
513 for (i = path->depth - 1; i > 0; i--) {
515 idx = get_connection_index(codec, nid, spec->aa_mix_nid);
517 if (have_mute(codec, nid, HDA_INPUT))
518 snd_hda_codec_write(codec, nid, 0,
519 AC_VERB_SET_AMP_GAIN_MUTE,
526 static void via_auto_init_multi_out(struct hda_codec *codec)
528 struct via_spec *spec = codec->spec;
531 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++)
532 via_auto_init_output(codec, &spec->out_path[i], PIN_OUT, true);
535 static void via_auto_init_hp_out(struct hda_codec *codec)
537 struct via_spec *spec = codec->spec;
539 if (!spec->hp_dac_nid) {
540 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true);
543 if (spec->hp_independent_mode) {
544 activate_output_path(codec, &spec->hp_dep_path, false, false);
545 via_auto_init_output(codec, &spec->hp_path, PIN_HP, true);
547 activate_output_path(codec, &spec->hp_path, false, false);
548 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true);
552 static void via_auto_init_speaker_out(struct hda_codec *codec)
554 struct via_spec *spec = codec->spec;
556 if (spec->autocfg.speaker_outs)
557 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT, true);
560 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
562 static void via_auto_init_analog_input(struct hda_codec *codec)
564 struct via_spec *spec = codec->spec;
565 const struct auto_pin_cfg *cfg = &spec->autocfg;
566 hda_nid_t conn[HDA_MAX_CONNECTIONS];
571 for (i = 0; i < spec->num_adc_nids; i++) {
572 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
573 AC_VERB_SET_AMP_GAIN_MUTE,
578 for (i = 0; i < cfg->num_inputs; i++) {
579 hda_nid_t nid = cfg->inputs[i].pin;
580 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
582 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
586 snd_hda_codec_write(codec, nid, 0,
587 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
591 for (i = 0; i < spec->num_adc_nids; i++) {
592 int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
593 if (spec->mux_nids[adc_idx]) {
594 int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
595 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
596 AC_VERB_SET_CONNECT_SEL,
599 if (spec->dyn_adc_switch)
600 break; /* only one input-src */
604 if (!spec->aa_mix_nid)
606 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
608 for (i = 0; i < num_conns; i++) {
609 unsigned int caps = get_wcaps(codec, conn[i]);
610 if (get_wcaps_type(caps) == AC_WID_PIN)
611 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
612 AC_VERB_SET_AMP_GAIN_MUTE,
617 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
618 unsigned int *affected_parm)
621 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
622 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
623 >> AC_DEFCFG_MISC_SHIFT
624 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
625 struct via_spec *spec = codec->spec;
626 unsigned present = 0;
628 no_presence |= spec->no_pin_power_ctl;
630 present = snd_hda_jack_detect(codec, nid);
631 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
632 || ((no_presence || present)
633 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
634 *affected_parm = AC_PWRST_D0; /* if it's connected */
639 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
642 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
643 struct snd_ctl_elem_info *uinfo)
645 static const char * const texts[] = {
646 "Disabled", "Enabled"
649 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
651 uinfo->value.enumerated.items = 2;
652 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
653 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
654 strcpy(uinfo->value.enumerated.name,
655 texts[uinfo->value.enumerated.item]);
659 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
660 struct snd_ctl_elem_value *ucontrol)
662 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
663 struct via_spec *spec = codec->spec;
664 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
668 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
669 struct snd_ctl_elem_value *ucontrol)
671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
672 struct via_spec *spec = codec->spec;
673 unsigned int val = !ucontrol->value.enumerated.item[0];
675 if (val == spec->no_pin_power_ctl)
677 spec->no_pin_power_ctl = val;
678 set_widgets_power_state(codec);
682 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
683 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
684 .name = "Dynamic Power-Control",
685 .info = via_pin_power_ctl_info,
686 .get = via_pin_power_ctl_get,
687 .put = via_pin_power_ctl_put,
691 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_info *uinfo)
694 static const char * const texts[] = { "OFF", "ON" };
696 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
698 uinfo->value.enumerated.items = 2;
699 if (uinfo->value.enumerated.item >= 2)
700 uinfo->value.enumerated.item = 1;
701 strcpy(uinfo->value.enumerated.name,
702 texts[uinfo->value.enumerated.item]);
706 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
707 struct snd_ctl_elem_value *ucontrol)
709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
710 struct via_spec *spec = codec->spec;
712 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
716 static int via_independent_hp_put(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;
723 /* no independent-hp status change during PCM playback is running */
724 if (spec->num_active_streams)
727 cur = !!ucontrol->value.enumerated.item[0];
728 if (spec->hp_independent_mode == cur)
730 spec->hp_independent_mode = cur;
732 activate_output_path(codec, &spec->hp_dep_path, false, false);
733 activate_output_path(codec, &spec->hp_path, true, false);
734 if (spec->hp_indep_shared)
735 activate_output_path(codec, &spec->out_path[HDA_SIDE],
738 activate_output_path(codec, &spec->hp_path, false, false);
739 activate_output_path(codec, &spec->hp_dep_path, true, false);
740 if (spec->hp_indep_shared)
741 activate_output_path(codec, &spec->out_path[HDA_SIDE],
745 /* update jack power state */
746 set_widgets_power_state(codec);
750 static const struct snd_kcontrol_new via_hp_mixer = {
751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
752 .name = "Independent HP",
753 .info = via_independent_hp_info,
754 .get = via_independent_hp_get,
755 .put = via_independent_hp_put,
758 static int via_hp_build(struct hda_codec *codec)
760 struct via_spec *spec = codec->spec;
761 struct snd_kcontrol_new *knew;
764 nid = spec->autocfg.hp_pins[0];
765 knew = via_clone_control(spec, &via_hp_mixer);
769 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
774 static void notify_aa_path_ctls(struct hda_codec *codec)
776 struct via_spec *spec = codec->spec;
779 for (i = 0; i < spec->smart51_nums; i++) {
780 struct snd_kcontrol *ctl;
781 struct snd_ctl_elem_id id;
782 memset(&id, 0, sizeof(id));
783 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
784 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
785 ctl = snd_hda_find_mixer_ctl(codec, id.name);
787 snd_ctl_notify(codec->bus->card,
788 SNDRV_CTL_EVENT_MASK_VALUE,
793 static void mute_aa_path(struct hda_codec *codec, int mute)
795 struct via_spec *spec = codec->spec;
796 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
799 /* check AA path's mute status */
800 for (i = 0; i < spec->smart51_nums; i++) {
801 if (spec->smart51_idxs[i] < 0)
803 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
804 HDA_INPUT, spec->smart51_idxs[i],
809 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
811 struct via_spec *spec = codec->spec;
814 for (i = 0; i < spec->smart51_nums; i++)
815 if (spec->smart51_pins[i] == pin)
820 static int via_smart51_get(struct snd_kcontrol *kcontrol,
821 struct snd_ctl_elem_value *ucontrol)
823 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
824 struct via_spec *spec = codec->spec;
826 *ucontrol->value.integer.value = spec->smart51_enabled;
830 static int via_smart51_put(struct snd_kcontrol *kcontrol,
831 struct snd_ctl_elem_value *ucontrol)
833 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
834 struct via_spec *spec = codec->spec;
835 int out_in = *ucontrol->value.integer.value
836 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
839 for (i = 0; i < spec->smart51_nums; i++) {
840 hda_nid_t nid = spec->smart51_pins[i];
843 parm = snd_hda_codec_read(codec, nid, 0,
844 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
845 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
847 snd_hda_codec_write(codec, nid, 0,
848 AC_VERB_SET_PIN_WIDGET_CONTROL,
850 if (out_in == AC_PINCTL_OUT_EN) {
851 mute_aa_path(codec, 1);
852 notify_aa_path_ctls(codec);
855 spec->smart51_enabled = *ucontrol->value.integer.value;
856 set_widgets_power_state(codec);
860 static const struct snd_kcontrol_new via_smart51_mixer = {
861 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
864 .info = snd_ctl_boolean_mono_info,
865 .get = via_smart51_get,
866 .put = via_smart51_put,
869 static int via_smart51_build(struct hda_codec *codec)
871 struct via_spec *spec = codec->spec;
873 if (!spec->smart51_nums)
875 if (!via_clone_control(spec, &via_smart51_mixer))
880 /* check AA path's mute status */
881 static bool is_aa_path_mute(struct hda_codec *codec)
883 struct via_spec *spec = codec->spec;
884 const struct hda_amp_list *p;
887 for (i = 0; i < spec->num_loopbacks; i++) {
888 p = &spec->loopback_list[i];
889 for (ch = 0; ch < 2; ch++) {
890 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
892 if (!(v & HDA_AMP_MUTE) && v > 0)
899 /* enter/exit analog low-current mode */
900 static void analog_low_current_mode(struct hda_codec *codec)
902 struct via_spec *spec = codec->spec;
904 unsigned int verb, parm;
906 enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0);
908 /* decide low current mode's verb & parameter */
909 switch (spec->codec_type) {
913 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
919 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
923 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
929 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
932 return; /* other codecs are not supported */
935 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
939 * generic initialization of ADC, input mixers and output mixers
941 static const struct hda_verb vt1708_init_verbs[] = {
942 /* power down jack detect function */
947 static void set_stream_active(struct hda_codec *codec, bool active)
949 struct via_spec *spec = codec->spec;
952 spec->num_active_streams++;
954 spec->num_active_streams--;
955 analog_low_current_mode(codec);
958 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
959 struct hda_codec *codec,
960 struct snd_pcm_substream *substream)
962 struct via_spec *spec = codec->spec;
963 const struct auto_pin_cfg *cfg = &spec->autocfg;
966 spec->multiout.hp_nid = 0;
967 spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
968 if (!spec->hp_independent_mode) {
969 if (!spec->hp_indep_shared)
970 spec->multiout.hp_nid = spec->hp_dac_nid;
972 if (spec->hp_indep_shared)
973 spec->multiout.num_dacs = cfg->line_outs - 1;
975 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
976 set_stream_active(codec, true);
977 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
980 spec->multiout.hp_nid = 0;
981 set_stream_active(codec, false);
987 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
988 struct hda_codec *codec,
989 struct snd_pcm_substream *substream)
991 struct via_spec *spec = codec->spec;
993 spec->multiout.hp_nid = 0;
994 set_stream_active(codec, false);
998 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
999 struct hda_codec *codec,
1000 struct snd_pcm_substream *substream)
1002 struct via_spec *spec = codec->spec;
1004 if (snd_BUG_ON(!spec->hp_dac_nid))
1006 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1008 set_stream_active(codec, true);
1012 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1013 struct hda_codec *codec,
1014 struct snd_pcm_substream *substream)
1016 set_stream_active(codec, false);
1020 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1021 struct hda_codec *codec,
1022 unsigned int stream_tag,
1023 unsigned int format,
1024 struct snd_pcm_substream *substream)
1026 struct via_spec *spec = codec->spec;
1028 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1030 vt1708_start_hp_work(spec);
1034 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1035 struct hda_codec *codec,
1036 unsigned int stream_tag,
1037 unsigned int format,
1038 struct snd_pcm_substream *substream)
1040 struct via_spec *spec = codec->spec;
1042 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1043 stream_tag, 0, format);
1044 vt1708_start_hp_work(spec);
1048 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1049 struct hda_codec *codec,
1050 struct snd_pcm_substream *substream)
1052 struct via_spec *spec = codec->spec;
1054 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1055 vt1708_stop_hp_work(spec);
1059 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1060 struct hda_codec *codec,
1061 struct snd_pcm_substream *substream)
1063 struct via_spec *spec = codec->spec;
1065 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1066 vt1708_stop_hp_work(spec);
1073 static int via_dig_playback_pcm_open(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_open(codec, &spec->multiout);
1081 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1082 struct hda_codec *codec,
1083 struct snd_pcm_substream *substream)
1085 struct via_spec *spec = codec->spec;
1086 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1089 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1090 struct hda_codec *codec,
1091 unsigned int stream_tag,
1092 unsigned int format,
1093 struct snd_pcm_substream *substream)
1095 struct via_spec *spec = codec->spec;
1096 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1097 stream_tag, format, substream);
1100 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1101 struct hda_codec *codec,
1102 struct snd_pcm_substream *substream)
1104 struct via_spec *spec = codec->spec;
1105 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1112 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1113 struct hda_codec *codec,
1114 unsigned int stream_tag,
1115 unsigned int format,
1116 struct snd_pcm_substream *substream)
1118 struct via_spec *spec = codec->spec;
1120 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1121 stream_tag, 0, format);
1125 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1126 struct hda_codec *codec,
1127 struct snd_pcm_substream *substream)
1129 struct via_spec *spec = codec->spec;
1130 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1134 /* analog capture with dynamic ADC switching */
1135 static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1136 struct hda_codec *codec,
1137 unsigned int stream_tag,
1138 unsigned int format,
1139 struct snd_pcm_substream *substream)
1141 struct via_spec *spec = codec->spec;
1142 int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
1144 spec->cur_adc = spec->adc_nids[adc_idx];
1145 spec->cur_adc_stream_tag = stream_tag;
1146 spec->cur_adc_format = format;
1147 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
1151 static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1152 struct hda_codec *codec,
1153 struct snd_pcm_substream *substream)
1155 struct via_spec *spec = codec->spec;
1157 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1162 /* re-setup the stream if running; called from input-src put */
1163 static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
1165 struct via_spec *spec = codec->spec;
1166 int adc_idx = spec->inputs[cur].adc_idx;
1167 hda_nid_t adc = spec->adc_nids[adc_idx];
1169 if (spec->cur_adc && spec->cur_adc != adc) {
1170 /* stream is running, let's swap the current ADC */
1171 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1172 spec->cur_adc = adc;
1173 snd_hda_codec_setup_stream(codec, adc,
1174 spec->cur_adc_stream_tag, 0,
1175 spec->cur_adc_format);
1181 static const struct hda_pcm_stream via_pcm_analog_playback = {
1185 /* NID is set in via_build_pcms */
1187 .open = via_playback_multi_pcm_open,
1188 .close = via_playback_multi_pcm_close,
1189 .prepare = via_playback_multi_pcm_prepare,
1190 .cleanup = via_playback_multi_pcm_cleanup
1194 static const struct hda_pcm_stream via_pcm_hp_playback = {
1198 /* NID is set in via_build_pcms */
1200 .open = via_playback_hp_pcm_open,
1201 .close = via_playback_hp_pcm_close,
1202 .prepare = via_playback_hp_pcm_prepare,
1203 .cleanup = via_playback_hp_pcm_cleanup
1207 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1211 /* NID is set in via_build_pcms */
1212 /* We got noisy outputs on the right channel on VT1708 when
1213 * 24bit samples are used. Until any workaround is found,
1214 * disable the 24bit format, so far.
1216 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1218 .open = via_playback_multi_pcm_open,
1219 .close = via_playback_multi_pcm_close,
1220 .prepare = via_playback_multi_pcm_prepare,
1221 .cleanup = via_playback_multi_pcm_cleanup
1225 static const struct hda_pcm_stream via_pcm_analog_capture = {
1226 .substreams = 1, /* will be changed in via_build_pcms() */
1229 /* NID is set in via_build_pcms */
1231 .prepare = via_capture_pcm_prepare,
1232 .cleanup = via_capture_pcm_cleanup
1236 static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
1240 /* NID is set in via_build_pcms */
1242 .prepare = via_dyn_adc_capture_pcm_prepare,
1243 .cleanup = via_dyn_adc_capture_pcm_cleanup,
1247 static const struct hda_pcm_stream via_pcm_digital_playback = {
1251 /* NID is set in via_build_pcms */
1253 .open = via_dig_playback_pcm_open,
1254 .close = via_dig_playback_pcm_close,
1255 .prepare = via_dig_playback_pcm_prepare,
1256 .cleanup = via_dig_playback_pcm_cleanup
1260 static const struct hda_pcm_stream via_pcm_digital_capture = {
1267 * slave controls for virtual master
1269 static const char * const via_slave_vols[] = {
1270 "Front Playback Volume",
1271 "Surround Playback Volume",
1272 "Center Playback Volume",
1273 "LFE Playback Volume",
1274 "Side Playback Volume",
1275 "Headphone Playback Volume",
1276 "Speaker Playback Volume",
1280 static const char * const via_slave_sws[] = {
1281 "Front Playback Switch",
1282 "Surround Playback Switch",
1283 "Center Playback Switch",
1284 "LFE Playback Switch",
1285 "Side Playback Switch",
1286 "Headphone Playback Switch",
1287 "Speaker Playback Switch",
1291 static int via_build_controls(struct hda_codec *codec)
1293 struct via_spec *spec = codec->spec;
1294 struct snd_kcontrol *kctl;
1297 if (spec->set_widgets_power_state)
1298 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1301 for (i = 0; i < spec->num_mixers; i++) {
1302 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1307 if (spec->multiout.dig_out_nid) {
1308 err = snd_hda_create_spdif_out_ctls(codec,
1309 spec->multiout.dig_out_nid,
1310 spec->multiout.dig_out_nid);
1313 err = snd_hda_create_spdif_share_sw(codec,
1317 spec->multiout.share_spdif = 1;
1319 if (spec->dig_in_nid) {
1320 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1325 /* if we have no master control, let's create it */
1326 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1327 unsigned int vmaster_tlv[4];
1328 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1329 HDA_OUTPUT, vmaster_tlv);
1330 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1331 vmaster_tlv, via_slave_vols);
1335 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1336 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1337 NULL, via_slave_sws);
1342 /* assign Capture Source enums to NID */
1343 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1344 for (i = 0; kctl && i < kctl->count; i++) {
1345 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1350 /* init power states */
1351 set_widgets_power_state(codec);
1352 analog_low_current_mode(codec);
1354 via_free_kctls(codec); /* no longer needed */
1358 static int via_build_pcms(struct hda_codec *codec)
1360 struct via_spec *spec = codec->spec;
1361 struct hda_pcm *info = spec->pcm_rec;
1363 codec->num_pcms = 1;
1364 codec->pcm_info = info;
1366 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1367 "%s Analog", codec->chip_name);
1368 info->name = spec->stream_name_analog;
1370 if (!spec->stream_analog_playback)
1371 spec->stream_analog_playback = &via_pcm_analog_playback;
1372 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1373 *spec->stream_analog_playback;
1374 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1375 spec->multiout.dac_nids[0];
1376 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1377 spec->multiout.max_channels;
1379 if (!spec->stream_analog_capture) {
1380 if (spec->dyn_adc_switch)
1381 spec->stream_analog_capture =
1382 &via_pcm_dyn_adc_analog_capture;
1384 spec->stream_analog_capture = &via_pcm_analog_capture;
1386 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1387 *spec->stream_analog_capture;
1388 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1389 if (!spec->dyn_adc_switch)
1390 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1393 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1396 snprintf(spec->stream_name_digital,
1397 sizeof(spec->stream_name_digital),
1398 "%s Digital", codec->chip_name);
1399 info->name = spec->stream_name_digital;
1400 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1401 if (spec->multiout.dig_out_nid) {
1402 if (!spec->stream_digital_playback)
1403 spec->stream_digital_playback =
1404 &via_pcm_digital_playback;
1405 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1406 *spec->stream_digital_playback;
1407 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1408 spec->multiout.dig_out_nid;
1410 if (spec->dig_in_nid) {
1411 if (!spec->stream_digital_capture)
1412 spec->stream_digital_capture =
1413 &via_pcm_digital_capture;
1414 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1415 *spec->stream_digital_capture;
1416 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1421 if (spec->hp_dac_nid) {
1424 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1425 "%s HP", codec->chip_name);
1426 info->name = spec->stream_name_hp;
1427 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1428 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1434 static void via_free(struct hda_codec *codec)
1436 struct via_spec *spec = codec->spec;
1441 via_free_kctls(codec);
1442 vt1708_stop_hp_work(spec);
1443 kfree(spec->bind_cap_vol);
1444 kfree(spec->bind_cap_sw);
1448 /* mute/unmute outputs */
1449 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1450 hda_nid_t *pins, bool mute)
1453 for (i = 0; i < num_pins; i++)
1454 snd_hda_codec_write(codec, pins[i], 0,
1455 AC_VERB_SET_PIN_WIDGET_CONTROL,
1456 mute ? 0 : PIN_OUT);
1459 /* mute internal speaker if line-out is plugged */
1460 static void via_line_automute(struct hda_codec *codec, int present)
1462 struct via_spec *spec = codec->spec;
1464 if (!spec->autocfg.speaker_outs)
1467 present = snd_hda_jack_detect(codec,
1468 spec->autocfg.line_out_pins[0]);
1469 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1470 spec->autocfg.speaker_pins,
1474 /* mute internal speaker if HP is plugged */
1475 static void via_hp_automute(struct hda_codec *codec)
1478 struct via_spec *spec = codec->spec;
1480 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) {
1482 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1483 if (spec->smart51_enabled)
1484 nums = spec->autocfg.line_outs + spec->smart51_nums;
1486 nums = spec->autocfg.line_outs;
1487 toggle_output_mutes(codec, nums,
1488 spec->autocfg.line_out_pins,
1491 via_line_automute(codec, present);
1494 static void via_gpio_control(struct hda_codec *codec)
1496 unsigned int gpio_data;
1497 unsigned int vol_counter;
1499 unsigned int master_vol;
1501 struct via_spec *spec = codec->spec;
1503 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1504 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1506 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1507 0xF84, 0) & 0x3F0000) >> 16;
1509 vol = vol_counter & 0x1F;
1510 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1511 AC_VERB_GET_AMP_GAIN_MUTE,
1514 if (gpio_data == 0x02) {
1515 /* unmute line out */
1516 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1517 AC_VERB_SET_PIN_WIDGET_CONTROL,
1519 if (vol_counter & 0x20) {
1520 /* decrease volume */
1521 if (vol > master_vol)
1523 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1527 /* increase volume */
1528 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1530 ((master_vol+vol) > 0x2A) ? 0x2A :
1533 } else if (!(gpio_data & 0x02)) {
1535 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1536 AC_VERB_SET_PIN_WIDGET_CONTROL,
1541 /* unsolicited event for jack sensing */
1542 static void via_unsol_event(struct hda_codec *codec,
1547 if (res & VIA_JACK_EVENT)
1548 set_widgets_power_state(codec);
1550 res &= ~VIA_JACK_EVENT;
1552 if (res == VIA_HP_EVENT)
1553 via_hp_automute(codec);
1554 else if (res == VIA_GPIO_EVENT)
1555 via_gpio_control(codec);
1556 else if (res == VIA_LINE_EVENT)
1557 via_line_automute(codec, false);
1560 #ifdef SND_HDA_NEEDS_RESUME
1561 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1563 struct via_spec *spec = codec->spec;
1564 vt1708_stop_hp_work(spec);
1569 #ifdef CONFIG_SND_HDA_POWER_SAVE
1570 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1572 struct via_spec *spec = codec->spec;
1573 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1580 static int via_init(struct hda_codec *codec);
1582 static const struct hda_codec_ops via_patch_ops = {
1583 .build_controls = via_build_controls,
1584 .build_pcms = via_build_pcms,
1587 .unsol_event = via_unsol_event,
1588 #ifdef SND_HDA_NEEDS_RESUME
1589 .suspend = via_suspend,
1591 #ifdef CONFIG_SND_HDA_POWER_SAVE
1592 .check_power_status = via_check_power_status,
1596 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1598 struct via_spec *spec = codec->spec;
1601 for (i = 0; i < spec->multiout.num_dacs; i++) {
1602 if (spec->multiout.dac_nids[i] == dac)
1605 if (spec->hp_dac_nid == dac)
1610 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1611 hda_nid_t target_dac, struct nid_path *path,
1612 int depth, int wid_type)
1617 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1618 for (i = 0; i < nums; i++) {
1619 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1621 if (conn[i] == target_dac || is_empty_dac(codec, conn[i]))
1624 if (depth >= MAX_NID_PATH_DEPTH)
1626 for (i = 0; i < nums; i++) {
1628 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1629 if (type == AC_WID_AUD_OUT ||
1630 (wid_type != -1 && type != wid_type))
1632 if (__parse_output_path(codec, conn[i], target_dac,
1633 path, depth + 1, AC_WID_AUD_SEL))
1639 path->path[path->depth] = conn[i];
1640 path->idx[path->depth] = i;
1641 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1642 path->multi[path->depth] = 1;
1647 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1648 hda_nid_t target_dac, struct nid_path *path)
1650 if (__parse_output_path(codec, nid, target_dac, path, 1, -1)) {
1651 path->path[path->depth] = nid;
1658 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1660 struct via_spec *spec = codec->spec;
1661 const struct auto_pin_cfg *cfg = &spec->autocfg;
1665 spec->multiout.dac_nids = spec->private_dac_nids;
1666 spec->multiout.num_dacs = cfg->line_outs;
1667 for (i = 0; i < cfg->line_outs; i++) {
1668 nid = cfg->line_out_pins[i];
1671 if (parse_output_path(codec, nid, 0, &spec->out_path[i]))
1672 spec->private_dac_nids[i] = spec->out_path[i].path[0];
1677 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1678 int chs, bool check_dac, struct nid_path *path)
1680 struct via_spec *spec = codec->spec;
1682 hda_nid_t dac, pin, sel, nid;
1685 dac = check_dac ? path->path[0] : 0;
1686 pin = path->path[path->depth - 1];
1687 sel = path->depth > 1 ? path->path[1] : 0;
1689 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1691 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1693 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1698 sprintf(name, "%s Playback Volume", pfx);
1699 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1700 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1703 path->vol_ctl = nid;
1706 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1708 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1710 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1715 sprintf(name, "%s Playback Switch", pfx);
1716 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1717 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1720 path->mute_ctl = nid;
1725 static void mangle_smart51(struct hda_codec *codec)
1727 struct via_spec *spec = codec->spec;
1728 struct auto_pin_cfg *cfg = &spec->autocfg;
1729 struct auto_pin_cfg_item *ins = cfg->inputs;
1730 int i, j, nums, attr;
1731 int pins[AUTO_CFG_MAX_INS];
1733 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1735 for (i = 0; i < cfg->num_inputs; i++) {
1737 if (ins[i].type > AUTO_PIN_LINE_IN)
1739 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1740 if (snd_hda_get_input_pin_attr(def) != attr)
1742 for (j = 0; j < nums; j++)
1743 if (ins[pins[j]].type < ins[i].type) {
1744 memmove(pins + j + 1, pins + j,
1745 (nums - j - 1) * sizeof(int));
1751 if (cfg->line_outs + nums < 3)
1753 for (i = 0; i < nums; i++) {
1754 hda_nid_t pin = ins[pins[i]].pin;
1755 spec->smart51_pins[spec->smart51_nums++] = pin;
1756 cfg->line_out_pins[cfg->line_outs++] = pin;
1757 if (cfg->line_outs == 3)
1764 /* add playback controls from the parsed DAC table */
1765 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1767 struct via_spec *spec = codec->spec;
1768 struct auto_pin_cfg *cfg = &spec->autocfg;
1769 static const char * const chname[4] = {
1770 "Front", "Surround", "C/LFE", "Side"
1776 old_line_outs = cfg->line_outs;
1777 if (cfg->line_outs == 1)
1778 mangle_smart51(codec);
1780 err = via_auto_fill_dac_nids(codec);
1784 for (i = 0; i < cfg->line_outs; i++) {
1786 pin = cfg->line_out_pins[i];
1787 dac = spec->multiout.dac_nids[i];
1790 if (i == HDA_CLFE) {
1791 err = create_ch_ctls(codec, "Center", 1, true,
1792 &spec->out_path[i]);
1795 err = create_ch_ctls(codec, "LFE", 2, true,
1796 &spec->out_path[i]);
1800 const char *pfx = chname[i];
1801 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1802 cfg->line_outs == 1)
1804 err = create_ch_ctls(codec, pfx, 3, true,
1805 &spec->out_path[i]);
1811 idx = get_connection_index(codec, spec->aa_mix_nid,
1812 spec->multiout.dac_nids[0]);
1814 /* add control to mixer */
1815 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1816 "PCM Playback Volume",
1817 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1821 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1822 "PCM Playback Switch",
1823 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1829 cfg->line_outs = old_line_outs;
1834 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1836 struct via_spec *spec = codec->spec;
1837 struct nid_path *path;
1843 if (parse_output_path(codec, pin, 0, &spec->hp_path))
1844 spec->hp_dac_nid = spec->hp_path.path[0];
1845 else if (spec->multiout.dac_nids[HDA_SIDE] &&
1846 parse_output_path(codec, pin,
1847 spec->multiout.dac_nids[HDA_SIDE],
1849 spec->hp_dac_nid = spec->hp_path.path[0];
1850 spec->hp_indep_shared = true;
1853 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1854 &spec->hp_dep_path) &&
1858 if (spec->hp_dac_nid && !spec->hp_indep_shared)
1859 path = &spec->hp_path;
1861 path = &spec->hp_dep_path;
1862 err = create_ch_ctls(codec, "Headphone", 3, false, path);
1865 if (spec->hp_dac_nid) {
1866 spec->hp_dep_path.vol_ctl = spec->hp_path.vol_ctl;
1867 spec->hp_dep_path.mute_ctl = spec->hp_path.mute_ctl;
1873 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1875 struct via_spec *spec = codec->spec;
1878 pin = spec->autocfg.speaker_pins[0];
1879 if (!spec->autocfg.speaker_outs || !pin)
1882 if (parse_output_path(codec, pin, 0, &spec->speaker_path)) {
1883 dac = spec->speaker_path.path[0];
1884 spec->multiout.extra_out_nid[0] = dac;
1885 return create_ch_ctls(codec, "Speaker", 3, true,
1886 &spec->speaker_path);
1888 if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1889 &spec->speaker_path))
1890 return create_ch_ctls(codec, "Speaker", 3, false,
1891 &spec->speaker_path);
1897 static int via_fill_adcs(struct hda_codec *codec)
1899 struct via_spec *spec = codec->spec;
1900 hda_nid_t nid = codec->start_nid;
1903 for (i = 0; i < codec->num_nodes; i++, nid++) {
1904 unsigned int wcaps = get_wcaps(codec, nid);
1905 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1907 if (wcaps & AC_WCAP_DIGITAL)
1909 if (!(wcaps & AC_WCAP_CONN_LIST))
1911 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1913 spec->adc_nids[spec->num_adc_nids++] = nid;
1918 /* input-src control */
1919 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1920 struct snd_ctl_elem_info *uinfo)
1922 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1923 struct via_spec *spec = codec->spec;
1925 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1927 uinfo->value.enumerated.items = spec->num_inputs;
1928 if (uinfo->value.enumerated.item >= spec->num_inputs)
1929 uinfo->value.enumerated.item = spec->num_inputs - 1;
1930 strcpy(uinfo->value.enumerated.name,
1931 spec->inputs[uinfo->value.enumerated.item].label);
1935 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1936 struct snd_ctl_elem_value *ucontrol)
1938 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1939 struct via_spec *spec = codec->spec;
1940 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1942 ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
1946 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1947 struct snd_ctl_elem_value *ucontrol)
1949 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1950 struct via_spec *spec = codec->spec;
1951 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1955 cur = ucontrol->value.enumerated.item[0];
1956 if (cur < 0 || cur >= spec->num_inputs)
1958 if (spec->cur_mux[idx] == cur)
1960 spec->cur_mux[idx] = cur;
1961 if (spec->dyn_adc_switch) {
1962 int adc_idx = spec->inputs[cur].adc_idx;
1963 mux = spec->mux_nids[adc_idx];
1964 via_dyn_adc_pcm_resetup(codec, cur);
1966 mux = spec->mux_nids[idx];
1967 if (snd_BUG_ON(!mux))
1972 /* switch to D0 beofre change index */
1973 if (snd_hda_codec_read(codec, mux, 0,
1974 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1975 snd_hda_codec_write(codec, mux, 0,
1976 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1977 snd_hda_codec_write(codec, mux, 0,
1978 AC_VERB_SET_CONNECT_SEL,
1979 spec->inputs[cur].mux_idx);
1982 /* update jack power state */
1983 set_widgets_power_state(codec);
1987 static const struct snd_kcontrol_new via_input_src_ctl = {
1988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1989 /* The multiple "Capture Source" controls confuse alsamixer
1990 * So call somewhat different..
1992 /* .name = "Capture Source", */
1993 .name = "Input Source",
1994 .info = via_mux_enum_info,
1995 .get = via_mux_enum_get,
1996 .put = via_mux_enum_put,
1999 static int create_input_src_ctls(struct hda_codec *codec, int count)
2001 struct via_spec *spec = codec->spec;
2002 struct snd_kcontrol_new *knew;
2004 if (spec->num_inputs <= 1 || !count)
2005 return 0; /* no need for single src */
2007 knew = via_clone_control(spec, &via_input_src_ctl);
2010 knew->count = count;
2014 /* add the powersave loopback-list entry */
2015 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
2017 struct hda_amp_list *list;
2019 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2021 list = spec->loopback_list + spec->num_loopbacks;
2023 list->dir = HDA_INPUT;
2025 spec->num_loopbacks++;
2026 spec->loopback.amplist = spec->loopback_list;
2029 static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
2032 return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
2035 /* add the input-route to the given pin */
2036 static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
2038 struct via_spec *spec = codec->spec;
2041 spec->inputs[spec->num_inputs].adc_idx = -1;
2042 spec->inputs[spec->num_inputs].pin = pin;
2043 for (c = 0; c < spec->num_adc_nids; c++) {
2044 if (spec->mux_nids[c]) {
2045 idx = get_connection_index(codec, spec->mux_nids[c],
2049 spec->inputs[spec->num_inputs].mux_idx = idx;
2051 if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
2054 spec->inputs[spec->num_inputs].adc_idx = c;
2055 /* Can primary ADC satisfy all inputs? */
2056 if (!spec->dyn_adc_switch &&
2057 spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
2058 snd_printd(KERN_INFO
2059 "via: dynamic ADC switching enabled\n");
2060 spec->dyn_adc_switch = 1;
2067 static int get_mux_nids(struct hda_codec *codec);
2069 /* parse input-routes; fill ADCs, MUXs and input-src entries */
2070 static int parse_analog_inputs(struct hda_codec *codec)
2072 struct via_spec *spec = codec->spec;
2073 const struct auto_pin_cfg *cfg = &spec->autocfg;
2076 err = via_fill_adcs(codec);
2079 err = get_mux_nids(codec);
2083 /* fill all input-routes */
2084 for (i = 0; i < cfg->num_inputs; i++) {
2085 if (add_input_route(codec, cfg->inputs[i].pin))
2086 spec->inputs[spec->num_inputs++].label =
2087 hda_get_autocfg_input_label(codec, cfg, i);
2090 /* check for internal loopback recording */
2091 if (spec->aa_mix_nid &&
2092 add_input_route(codec, spec->aa_mix_nid))
2093 spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
2098 /* create analog-loopback volume/switch controls */
2099 static int create_loopback_ctls(struct hda_codec *codec)
2101 struct via_spec *spec = codec->spec;
2102 const struct auto_pin_cfg *cfg = &spec->autocfg;
2103 const char *prev_label = NULL;
2107 if (!spec->aa_mix_nid)
2110 for (i = 0; i < cfg->num_inputs; i++) {
2111 hda_nid_t pin = cfg->inputs[i].pin;
2112 const char *label = hda_get_autocfg_input_label(codec, cfg, i);
2114 if (prev_label && !strcmp(label, prev_label))
2119 idx = get_connection_index(codec, spec->aa_mix_nid, pin);
2121 err = via_new_analog_input(spec, label, type_idx,
2122 idx, spec->aa_mix_nid);
2125 add_loopback_list(spec, spec->aa_mix_nid, idx);
2128 /* remember the label for smart51 control */
2129 for (j = 0; j < spec->smart51_nums; j++) {
2130 if (spec->smart51_pins[j] == pin) {
2131 spec->smart51_idxs[j] = idx;
2132 spec->smart51_labels[j] = label;
2140 /* create mic-boost controls (if present) */
2141 static int create_mic_boost_ctls(struct hda_codec *codec)
2143 struct via_spec *spec = codec->spec;
2144 const struct auto_pin_cfg *cfg = &spec->autocfg;
2147 for (i = 0; i < cfg->num_inputs; i++) {
2148 hda_nid_t pin = cfg->inputs[i].pin;
2153 if (cfg->inputs[i].type != AUTO_PIN_MIC)
2155 caps = query_amp_caps(codec, pin, HDA_INPUT);
2156 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2158 label = hda_get_autocfg_input_label(codec, cfg, i);
2159 snprintf(name, sizeof(name), "%s Boost Volume", label);
2160 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2161 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2168 /* create capture and input-src controls for multiple streams */
2169 static int create_multi_adc_ctls(struct hda_codec *codec)
2171 struct via_spec *spec = codec->spec;
2174 /* create capture mixer elements */
2175 for (i = 0; i < spec->num_adc_nids; i++) {
2176 hda_nid_t adc = spec->adc_nids[i];
2177 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
2178 "Capture Volume", i,
2179 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2183 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2184 "Capture Switch", i,
2185 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
2191 /* input-source control */
2192 for (i = 0; i < spec->num_adc_nids; i++)
2193 if (!spec->mux_nids[i])
2195 err = create_input_src_ctls(codec, i);
2201 /* bind capture volume/switch */
2202 static struct snd_kcontrol_new via_bind_cap_vol_ctl =
2203 HDA_BIND_VOL("Capture Volume", 0);
2204 static struct snd_kcontrol_new via_bind_cap_sw_ctl =
2205 HDA_BIND_SW("Capture Switch", 0);
2207 static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
2208 struct hda_ctl_ops *ops)
2210 struct hda_bind_ctls *ctl;
2213 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
2217 for (i = 0; i < spec->num_adc_nids; i++)
2219 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
2224 /* create capture and input-src controls for dynamic ADC-switch case */
2225 static int create_dyn_adc_ctls(struct hda_codec *codec)
2227 struct via_spec *spec = codec->spec;
2228 struct snd_kcontrol_new *knew;
2231 /* set up the bind capture ctls */
2232 err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
2235 err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
2239 /* create capture mixer elements */
2240 knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
2243 knew->private_value = (long)spec->bind_cap_vol;
2245 knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
2248 knew->private_value = (long)spec->bind_cap_sw;
2250 /* input-source control */
2251 err = create_input_src_ctls(codec, 1);
2257 /* parse and create capture-related stuff */
2258 static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
2260 struct via_spec *spec = codec->spec;
2263 err = parse_analog_inputs(codec);
2266 if (spec->dyn_adc_switch)
2267 err = create_dyn_adc_ctls(codec);
2269 err = create_multi_adc_ctls(codec);
2272 err = create_loopback_ctls(codec);
2275 err = create_mic_boost_ctls(codec);
2281 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2283 unsigned int def_conf;
2284 unsigned char seqassoc;
2286 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2287 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2288 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2289 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2290 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2291 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2292 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2298 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2299 struct snd_ctl_elem_value *ucontrol)
2301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2302 struct via_spec *spec = codec->spec;
2304 if (spec->codec_type != VT1708)
2306 spec->vt1708_jack_detect =
2307 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2308 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2312 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2313 struct snd_ctl_elem_value *ucontrol)
2315 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2316 struct via_spec *spec = codec->spec;
2319 if (spec->codec_type != VT1708)
2321 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2322 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2323 == !spec->vt1708_jack_detect;
2324 if (spec->vt1708_jack_detect) {
2325 mute_aa_path(codec, 1);
2326 notify_aa_path_ctls(codec);
2331 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2332 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2333 .name = "Jack Detect",
2335 .info = snd_ctl_boolean_mono_info,
2336 .get = vt1708_jack_detect_get,
2337 .put = vt1708_jack_detect_put,
2340 static void fill_dig_outs(struct hda_codec *codec);
2341 static void fill_dig_in(struct hda_codec *codec);
2343 static int via_parse_auto_config(struct hda_codec *codec)
2345 struct via_spec *spec = codec->spec;
2348 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2351 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2354 err = via_auto_create_multi_out_ctls(codec);
2357 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2360 err = via_auto_create_speaker_ctls(codec);
2363 err = via_auto_create_analog_input_ctls(codec);
2367 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2369 fill_dig_outs(codec);
2372 if (spec->kctls.list)
2373 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2376 if (spec->hp_dac_nid && spec->hp_dep_path.depth) {
2377 err = via_hp_build(codec);
2382 err = via_smart51_build(codec);
2386 /* assign slave outs */
2387 if (spec->slave_dig_outs[0])
2388 codec->slave_dig_outs = spec->slave_dig_outs;
2393 static void via_auto_init_dig_outs(struct hda_codec *codec)
2395 struct via_spec *spec = codec->spec;
2396 if (spec->multiout.dig_out_nid)
2397 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2398 if (spec->slave_dig_outs[0])
2399 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2402 static void via_auto_init_dig_in(struct hda_codec *codec)
2404 struct via_spec *spec = codec->spec;
2405 if (!spec->dig_in_nid)
2407 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2408 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2411 /* initialize the unsolicited events */
2412 static void via_auto_init_unsol_event(struct hda_codec *codec)
2414 struct via_spec *spec = codec->spec;
2415 struct auto_pin_cfg *cfg = &spec->autocfg;
2419 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2420 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2421 AC_VERB_SET_UNSOLICITED_ENABLE,
2422 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2424 if (cfg->speaker_pins[0])
2425 ev = VIA_LINE_EVENT;
2428 for (i = 0; i < cfg->line_outs; i++) {
2429 if (cfg->line_out_pins[i] &&
2430 is_jack_detectable(codec, cfg->line_out_pins[i]))
2431 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
2432 AC_VERB_SET_UNSOLICITED_ENABLE,
2433 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2436 for (i = 0; i < cfg->num_inputs; i++) {
2437 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2438 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2439 AC_VERB_SET_UNSOLICITED_ENABLE,
2440 AC_USRSP_EN | VIA_JACK_EVENT);
2444 static int via_init(struct hda_codec *codec)
2446 struct via_spec *spec = codec->spec;
2449 for (i = 0; i < spec->num_iverbs; i++)
2450 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2452 via_auto_init_multi_out(codec);
2453 via_auto_init_hp_out(codec);
2454 via_auto_init_speaker_out(codec);
2455 via_auto_init_analog_input(codec);
2456 via_auto_init_dig_outs(codec);
2457 via_auto_init_dig_in(codec);
2459 via_auto_init_unsol_event(codec);
2461 via_hp_automute(codec);
2462 via_line_automute(codec, false);
2467 static void vt1708_update_hp_jack_state(struct work_struct *work)
2469 struct via_spec *spec = container_of(work, struct via_spec,
2470 vt1708_hp_work.work);
2471 if (spec->codec_type != VT1708)
2473 /* if jack state toggled */
2474 if (spec->vt1708_hp_present
2475 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2476 spec->vt1708_hp_present ^= 1;
2477 via_hp_automute(spec->codec);
2479 vt1708_start_hp_work(spec);
2482 static int get_mux_nids(struct hda_codec *codec)
2484 struct via_spec *spec = codec->spec;
2485 hda_nid_t nid, conn[8];
2489 for (i = 0; i < spec->num_adc_nids; i++) {
2490 nid = spec->adc_nids[i];
2492 type = get_wcaps_type(get_wcaps(codec, nid));
2493 if (type == AC_WID_PIN)
2495 n = snd_hda_get_connections(codec, nid, conn,
2500 spec->mux_nids[i] = nid;
2509 static int patch_vt1708(struct hda_codec *codec)
2511 struct via_spec *spec;
2514 /* create a codec specific record */
2515 spec = via_new_spec(codec);
2519 spec->aa_mix_nid = 0x17;
2521 /* Add HP and CD pin config connect bit re-config action */
2522 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2523 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2525 /* automatic parse from the BIOS config */
2526 err = via_parse_auto_config(codec);
2532 /* add jack detect on/off control */
2533 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2536 /* disable 32bit format on VT1708 */
2537 if (codec->vendor_id == 0x11061708)
2538 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2540 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2542 codec->patch_ops = via_patch_ops;
2544 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2548 static int patch_vt1709(struct hda_codec *codec)
2550 struct via_spec *spec;
2553 /* create a codec specific record */
2554 spec = via_new_spec(codec);
2558 spec->aa_mix_nid = 0x18;
2560 err = via_parse_auto_config(codec);
2566 codec->patch_ops = via_patch_ops;
2571 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2573 struct via_spec *spec = codec->spec;
2577 if ((spec->codec_type != VT1708B_4CH) &&
2578 (codec->vendor_id != 0x11064397))
2581 /* SW0 (17h) = stereo mixer */
2583 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2584 == ((spec->codec_type == VT1708S) ? 5 : 0));
2586 /* PW 1/2/5 (1ah/1bh/1eh) */
2588 set_pin_power_state(codec, 0x1a, &parm);
2589 set_pin_power_state(codec, 0x1b, &parm);
2590 set_pin_power_state(codec, 0x1e, &parm);
2593 /* SW0 (17h), AIW 0/1 (13h/14h) */
2594 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2595 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2596 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2599 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2601 set_pin_power_state(codec, 0x19, &parm);
2602 if (spec->smart51_enabled)
2603 set_pin_power_state(codec, 0x1b, &parm);
2604 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2605 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2607 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2610 set_pin_power_state(codec, 0x22, &parm);
2611 if (spec->smart51_enabled)
2612 set_pin_power_state(codec, 0x1a, &parm);
2613 snd_hda_codec_write(codec, 0x26, 0,
2614 AC_VERB_SET_POWER_STATE, parm);
2615 snd_hda_codec_write(codec, 0x24, 0,
2616 AC_VERB_SET_POWER_STATE, parm);
2617 } else if (codec->vendor_id == 0x11064397) {
2618 /* PW7(23h), SW2(27h), AOW2(25h) */
2620 set_pin_power_state(codec, 0x23, &parm);
2621 if (spec->smart51_enabled)
2622 set_pin_power_state(codec, 0x1a, &parm);
2623 snd_hda_codec_write(codec, 0x27, 0,
2624 AC_VERB_SET_POWER_STATE, parm);
2625 snd_hda_codec_write(codec, 0x25, 0,
2626 AC_VERB_SET_POWER_STATE, parm);
2629 /* PW 3/4/7 (1ch/1dh/23h) */
2631 /* force to D0 for internal Speaker */
2632 set_pin_power_state(codec, 0x1c, &parm);
2633 set_pin_power_state(codec, 0x1d, &parm);
2635 set_pin_power_state(codec, 0x23, &parm);
2637 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2638 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2639 imux_is_smixer ? AC_PWRST_D0 : parm);
2640 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2642 snd_hda_codec_write(codec, 0x25, 0,
2643 AC_VERB_SET_POWER_STATE, parm);
2644 snd_hda_codec_write(codec, 0x27, 0,
2645 AC_VERB_SET_POWER_STATE, parm);
2646 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2647 snd_hda_codec_write(codec, 0x25, 0,
2648 AC_VERB_SET_POWER_STATE, parm);
2651 static int patch_vt1708S(struct hda_codec *codec);
2652 static int patch_vt1708B(struct hda_codec *codec)
2654 struct via_spec *spec;
2657 if (get_codec_type(codec) == VT1708BCE)
2658 return patch_vt1708S(codec);
2660 /* create a codec specific record */
2661 spec = via_new_spec(codec);
2665 spec->aa_mix_nid = 0x16;
2667 /* automatic parse from the BIOS config */
2668 err = via_parse_auto_config(codec);
2674 codec->patch_ops = via_patch_ops;
2676 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2681 /* Patch for VT1708S */
2682 static const struct hda_verb vt1708S_init_verbs[] = {
2683 /* Enable Mic Boost Volume backdoor */
2685 /* don't bybass mixer */
2690 /* fill out digital output widgets; one for master and one for slave outputs */
2691 static void fill_dig_outs(struct hda_codec *codec)
2693 struct via_spec *spec = codec->spec;
2696 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2700 nid = spec->autocfg.dig_out_pins[i];
2703 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2706 if (!spec->multiout.dig_out_nid)
2707 spec->multiout.dig_out_nid = nid;
2709 spec->slave_dig_outs[0] = nid;
2710 break; /* at most two dig outs */
2715 static void fill_dig_in(struct hda_codec *codec)
2717 struct via_spec *spec = codec->spec;
2721 if (!spec->autocfg.dig_in_pin)
2724 dig_nid = codec->start_nid;
2725 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2726 unsigned int wcaps = get_wcaps(codec, dig_nid);
2727 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2729 if (!(wcaps & AC_WCAP_DIGITAL))
2731 if (!(wcaps & AC_WCAP_CONN_LIST))
2733 err = get_connection_index(codec, dig_nid,
2734 spec->autocfg.dig_in_pin);
2736 spec->dig_in_nid = dig_nid;
2742 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2743 int offset, int num_steps, int step_size)
2745 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2746 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2747 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2748 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2749 (0 << AC_AMPCAP_MUTE_SHIFT));
2752 static int patch_vt1708S(struct hda_codec *codec)
2754 struct via_spec *spec;
2757 /* create a codec specific record */
2758 spec = via_new_spec(codec);
2762 spec->aa_mix_nid = 0x16;
2763 override_mic_boost(codec, 0x1a, 0, 3, 40);
2764 override_mic_boost(codec, 0x1e, 0, 3, 40);
2766 /* automatic parse from the BIOS config */
2767 err = via_parse_auto_config(codec);
2773 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2775 codec->patch_ops = via_patch_ops;
2777 /* correct names for VT1708BCE */
2778 if (get_codec_type(codec) == VT1708BCE) {
2779 kfree(codec->chip_name);
2780 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2781 snprintf(codec->bus->card->mixername,
2782 sizeof(codec->bus->card->mixername),
2783 "%s %s", codec->vendor_name, codec->chip_name);
2785 /* correct names for VT1705 */
2786 if (codec->vendor_id == 0x11064397) {
2787 kfree(codec->chip_name);
2788 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2789 snprintf(codec->bus->card->mixername,
2790 sizeof(codec->bus->card->mixername),
2791 "%s %s", codec->vendor_name, codec->chip_name);
2793 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2797 /* Patch for VT1702 */
2799 static const struct hda_verb vt1702_init_verbs[] = {
2807 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2809 int imux_is_smixer =
2810 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2813 /* PW 1/2/5 (14h/15h/18h) */
2815 set_pin_power_state(codec, 0x14, &parm);
2816 set_pin_power_state(codec, 0x15, &parm);
2817 set_pin_power_state(codec, 0x18, &parm);
2819 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2820 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2821 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2822 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2823 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2824 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2827 /* PW 3/4 (16h/17h) */
2829 set_pin_power_state(codec, 0x17, &parm);
2830 set_pin_power_state(codec, 0x16, &parm);
2831 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2832 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2833 imux_is_smixer ? AC_PWRST_D0 : parm);
2834 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2835 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2838 static int patch_vt1702(struct hda_codec *codec)
2840 struct via_spec *spec;
2843 /* create a codec specific record */
2844 spec = via_new_spec(codec);
2848 spec->aa_mix_nid = 0x1a;
2850 /* limit AA path volume to 0 dB */
2851 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2852 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2853 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2854 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2855 (1 << AC_AMPCAP_MUTE_SHIFT));
2857 /* automatic parse from the BIOS config */
2858 err = via_parse_auto_config(codec);
2864 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
2866 codec->patch_ops = via_patch_ops;
2868 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
2872 /* Patch for VT1718S */
2874 static const struct hda_verb vt1718S_init_verbs[] = {
2875 /* Enable MW0 adjust Gain 5 */
2877 /* Enable Boost Volume backdoor */
2883 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2885 struct via_spec *spec = codec->spec;
2888 /* MUX6 (1eh) = stereo mixer */
2890 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2892 /* PW 5/6/7 (29h/2ah/2bh) */
2894 set_pin_power_state(codec, 0x29, &parm);
2895 set_pin_power_state(codec, 0x2a, &parm);
2896 set_pin_power_state(codec, 0x2b, &parm);
2899 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2900 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2901 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2902 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2903 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2906 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2908 set_pin_power_state(codec, 0x27, &parm);
2909 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2910 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2912 /* PW2 (26h), AOW2 (ah) */
2914 set_pin_power_state(codec, 0x26, &parm);
2915 if (spec->smart51_enabled)
2916 set_pin_power_state(codec, 0x2b, &parm);
2917 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
2919 /* PW0 (24h), AOW0 (8h) */
2921 set_pin_power_state(codec, 0x24, &parm);
2922 if (!spec->hp_independent_mode) /* check for redirected HP */
2923 set_pin_power_state(codec, 0x28, &parm);
2924 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2925 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
2926 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
2927 imux_is_smixer ? AC_PWRST_D0 : parm);
2929 /* PW1 (25h), AOW1 (9h) */
2931 set_pin_power_state(codec, 0x25, &parm);
2932 if (spec->smart51_enabled)
2933 set_pin_power_state(codec, 0x2a, &parm);
2934 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
2936 if (spec->hp_independent_mode) {
2937 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
2939 set_pin_power_state(codec, 0x28, &parm);
2940 snd_hda_codec_write(codec, 0x1b, 0,
2941 AC_VERB_SET_POWER_STATE, parm);
2942 snd_hda_codec_write(codec, 0x34, 0,
2943 AC_VERB_SET_POWER_STATE, parm);
2944 snd_hda_codec_write(codec, 0xc, 0,
2945 AC_VERB_SET_POWER_STATE, parm);
2949 static int patch_vt1718S(struct hda_codec *codec)
2951 struct via_spec *spec;
2954 /* create a codec specific record */
2955 spec = via_new_spec(codec);
2959 spec->aa_mix_nid = 0x21;
2960 override_mic_boost(codec, 0x2b, 0, 3, 40);
2961 override_mic_boost(codec, 0x29, 0, 3, 40);
2963 /* automatic parse from the BIOS config */
2964 err = via_parse_auto_config(codec);
2970 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
2972 codec->patch_ops = via_patch_ops;
2974 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
2979 /* Patch for VT1716S */
2981 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
2982 struct snd_ctl_elem_info *uinfo)
2984 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2986 uinfo->value.integer.min = 0;
2987 uinfo->value.integer.max = 1;
2991 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
2992 struct snd_ctl_elem_value *ucontrol)
2994 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2997 index = snd_hda_codec_read(codec, 0x26, 0,
2998 AC_VERB_GET_CONNECT_SEL, 0);
3000 *ucontrol->value.integer.value = index;
3005 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
3006 struct snd_ctl_elem_value *ucontrol)
3008 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3009 struct via_spec *spec = codec->spec;
3010 int index = *ucontrol->value.integer.value;
3012 snd_hda_codec_write(codec, 0x26, 0,
3013 AC_VERB_SET_CONNECT_SEL, index);
3014 spec->dmic_enabled = index;
3015 set_widgets_power_state(codec);
3019 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
3020 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
3022 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3023 .name = "Digital Mic Capture Switch",
3024 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
3026 .info = vt1716s_dmic_info,
3027 .get = vt1716s_dmic_get,
3028 .put = vt1716s_dmic_put,
3034 /* mono-out mixer elements */
3035 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
3036 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
3040 static const struct hda_verb vt1716S_init_verbs[] = {
3041 /* Enable Boost Volume backdoor */
3043 /* don't bybass mixer */
3045 /* Enable mono output */
3050 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
3052 struct via_spec *spec = codec->spec;
3055 unsigned int mono_out, present;
3056 /* SW0 (17h) = stereo mixer */
3058 (snd_hda_codec_read(codec, 0x17, 0,
3059 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
3061 /* PW 1/2/5 (1ah/1bh/1eh) */
3063 set_pin_power_state(codec, 0x1a, &parm);
3064 set_pin_power_state(codec, 0x1b, &parm);
3065 set_pin_power_state(codec, 0x1e, &parm);
3068 /* SW0 (17h), AIW0(13h) */
3069 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3070 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3073 set_pin_power_state(codec, 0x1e, &parm);
3075 if (spec->dmic_enabled)
3076 set_pin_power_state(codec, 0x22, &parm);
3078 snd_hda_codec_write(codec, 0x22, 0,
3079 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3081 /* SW2(26h), AIW1(14h) */
3082 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
3083 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3086 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3088 set_pin_power_state(codec, 0x19, &parm);
3089 /* Smart 5.1 PW2(1bh) */
3090 if (spec->smart51_enabled)
3091 set_pin_power_state(codec, 0x1b, &parm);
3092 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3093 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3095 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
3097 set_pin_power_state(codec, 0x23, &parm);
3098 /* Smart 5.1 PW1(1ah) */
3099 if (spec->smart51_enabled)
3100 set_pin_power_state(codec, 0x1a, &parm);
3101 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
3103 /* Smart 5.1 PW5(1eh) */
3104 if (spec->smart51_enabled)
3105 set_pin_power_state(codec, 0x1e, &parm);
3106 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
3109 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
3110 present = snd_hda_jack_detect(codec, 0x1c);
3115 present = snd_hda_jack_detect(codec, 0x1d);
3116 if (!spec->hp_independent_mode && present)
3121 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
3122 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
3123 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
3124 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
3126 /* PW 3/4 (1ch/1dh) */
3128 set_pin_power_state(codec, 0x1c, &parm);
3129 set_pin_power_state(codec, 0x1d, &parm);
3130 /* HP Independent Mode, power on AOW3 */
3131 if (spec->hp_independent_mode)
3132 snd_hda_codec_write(codec, 0x25, 0,
3133 AC_VERB_SET_POWER_STATE, parm);
3135 /* force to D0 for internal Speaker */
3136 /* MW0 (16h), AOW0 (10h) */
3137 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3138 imux_is_smixer ? AC_PWRST_D0 : parm);
3139 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
3140 mono_out ? AC_PWRST_D0 : parm);
3143 static int patch_vt1716S(struct hda_codec *codec)
3145 struct via_spec *spec;
3148 /* create a codec specific record */
3149 spec = via_new_spec(codec);
3153 spec->aa_mix_nid = 0x16;
3154 override_mic_boost(codec, 0x1a, 0, 3, 40);
3155 override_mic_boost(codec, 0x1e, 0, 3, 40);
3157 /* automatic parse from the BIOS config */
3158 err = via_parse_auto_config(codec);
3164 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
3166 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
3169 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
3171 codec->patch_ops = via_patch_ops;
3173 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
3179 static const struct hda_verb vt2002P_init_verbs[] = {
3180 /* Class-D speaker related verbs */
3184 /* Enable Boost Volume backdoor */
3186 /* Enable AOW0 to MW9 */
3191 static const struct hda_verb vt1802_init_verbs[] = {
3192 /* Enable Boost Volume backdoor */
3194 /* Enable AOW0 to MW9 */
3199 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
3201 struct via_spec *spec = codec->spec;
3204 unsigned int present;
3205 /* MUX9 (1eh) = stereo mixer */
3207 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3209 /* PW 5/6/7 (29h/2ah/2bh) */
3211 set_pin_power_state(codec, 0x29, &parm);
3212 set_pin_power_state(codec, 0x2a, &parm);
3213 set_pin_power_state(codec, 0x2b, &parm);
3215 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
3216 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3217 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3218 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3219 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3223 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
3225 if (spec->codec_type == VT1802) {
3226 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3228 set_pin_power_state(codec, 0x28, &parm);
3229 snd_hda_codec_write(codec, 0x18, 0,
3230 AC_VERB_SET_POWER_STATE, parm);
3231 snd_hda_codec_write(codec, 0x38, 0,
3232 AC_VERB_SET_POWER_STATE, parm);
3234 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
3236 set_pin_power_state(codec, 0x26, &parm);
3237 snd_hda_codec_write(codec, 0x1c, 0,
3238 AC_VERB_SET_POWER_STATE, parm);
3239 snd_hda_codec_write(codec, 0x37, 0,
3240 AC_VERB_SET_POWER_STATE, parm);
3243 if (spec->codec_type == VT1802) {
3244 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3246 set_pin_power_state(codec, 0x25, &parm);
3247 snd_hda_codec_write(codec, 0x15, 0,
3248 AC_VERB_SET_POWER_STATE, parm);
3249 snd_hda_codec_write(codec, 0x35, 0,
3250 AC_VERB_SET_POWER_STATE, parm);
3252 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
3254 set_pin_power_state(codec, 0x25, &parm);
3255 snd_hda_codec_write(codec, 0x19, 0,
3256 AC_VERB_SET_POWER_STATE, parm);
3257 snd_hda_codec_write(codec, 0x35, 0,
3258 AC_VERB_SET_POWER_STATE, parm);
3261 if (spec->hp_independent_mode)
3262 snd_hda_codec_write(codec, 0x9, 0,
3263 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3266 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3267 present = snd_hda_jack_detect(codec, 0x25);
3270 set_pin_power_state(codec, 0x24, &parm);
3271 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3272 if (spec->codec_type == VT1802)
3273 snd_hda_codec_write(codec, 0x14, 0,
3274 AC_VERB_SET_POWER_STATE, parm);
3276 snd_hda_codec_write(codec, 0x18, 0,
3277 AC_VERB_SET_POWER_STATE, parm);
3278 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3281 present = snd_hda_jack_detect(codec, 0x26);
3283 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3284 if (spec->codec_type == VT1802) {
3285 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3286 snd_hda_codec_write(codec, 0x33, 0,
3287 AC_VERB_SET_POWER_STATE, parm);
3288 snd_hda_codec_write(codec, 0x1c, 0,
3289 AC_VERB_SET_POWER_STATE, parm);
3290 snd_hda_codec_write(codec, 0x3c, 0,
3291 AC_VERB_SET_POWER_STATE, parm);
3293 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3294 snd_hda_codec_write(codec, 0x31, 0,
3295 AC_VERB_SET_POWER_STATE, parm);
3296 snd_hda_codec_write(codec, 0x17, 0,
3297 AC_VERB_SET_POWER_STATE, parm);
3298 snd_hda_codec_write(codec, 0x3b, 0,
3299 AC_VERB_SET_POWER_STATE, parm);
3302 if (imux_is_smixer || !is_aa_path_mute(codec))
3303 snd_hda_codec_write(codec, 0x21, 0,
3304 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3306 snd_hda_codec_write(codec, 0x21, 0,
3307 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3310 /* patch for vt2002P */
3311 static int patch_vt2002P(struct hda_codec *codec)
3313 struct via_spec *spec;
3316 /* create a codec specific record */
3317 spec = via_new_spec(codec);
3321 spec->aa_mix_nid = 0x21;
3322 override_mic_boost(codec, 0x2b, 0, 3, 40);
3323 override_mic_boost(codec, 0x29, 0, 3, 40);
3325 /* automatic parse from the BIOS config */
3326 err = via_parse_auto_config(codec);
3332 if (spec->codec_type == VT1802)
3333 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3335 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3337 codec->patch_ops = via_patch_ops;
3339 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3345 static const struct hda_verb vt1812_init_verbs[] = {
3346 /* Enable Boost Volume backdoor */
3348 /* Enable AOW0 to MW9 */
3353 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3355 struct via_spec *spec = codec->spec;
3356 int imux_is_smixer =
3357 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3359 unsigned int present;
3360 /* MUX10 (1eh) = stereo mixer */
3362 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3364 /* PW 5/6/7 (29h/2ah/2bh) */
3366 set_pin_power_state(codec, 0x29, &parm);
3367 set_pin_power_state(codec, 0x2a, &parm);
3368 set_pin_power_state(codec, 0x2b, &parm);
3370 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3371 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3372 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3373 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3374 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3378 snd_hda_codec_write(codec, 0x8, 0,
3379 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3381 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3383 set_pin_power_state(codec, 0x28, &parm);
3384 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3385 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3387 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3389 set_pin_power_state(codec, 0x25, &parm);
3390 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3391 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3392 if (spec->hp_independent_mode)
3393 snd_hda_codec_write(codec, 0x9, 0,
3394 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3396 /* Internal Speaker */
3397 /* PW0 (24h), MW0(14h), MUX0(34h) */
3398 present = snd_hda_jack_detect(codec, 0x25);
3401 set_pin_power_state(codec, 0x24, &parm);
3403 snd_hda_codec_write(codec, 0x14, 0,
3404 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3405 snd_hda_codec_write(codec, 0x34, 0,
3406 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3408 snd_hda_codec_write(codec, 0x14, 0,
3409 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3410 snd_hda_codec_write(codec, 0x34, 0,
3411 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3416 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3417 present = snd_hda_jack_detect(codec, 0x28);
3420 set_pin_power_state(codec, 0x31, &parm);
3422 snd_hda_codec_write(codec, 0x1c, 0,
3423 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3424 snd_hda_codec_write(codec, 0x3c, 0,
3425 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3426 snd_hda_codec_write(codec, 0x3e, 0,
3427 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3429 snd_hda_codec_write(codec, 0x1c, 0,
3430 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3431 snd_hda_codec_write(codec, 0x3c, 0,
3432 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3433 snd_hda_codec_write(codec, 0x3e, 0,
3434 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3437 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3439 set_pin_power_state(codec, 0x33, &parm);
3440 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3441 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3445 /* patch for vt1812 */
3446 static int patch_vt1812(struct hda_codec *codec)
3448 struct via_spec *spec;
3451 /* create a codec specific record */
3452 spec = via_new_spec(codec);
3456 spec->aa_mix_nid = 0x21;
3457 override_mic_boost(codec, 0x2b, 0, 3, 40);
3458 override_mic_boost(codec, 0x29, 0, 3, 40);
3460 /* automatic parse from the BIOS config */
3461 err = via_parse_auto_config(codec);
3467 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3469 codec->patch_ops = via_patch_ops;
3471 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3478 static const struct hda_codec_preset snd_hda_preset_via[] = {
3479 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3480 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3481 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3482 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3483 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3484 .patch = patch_vt1709},
3485 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3486 .patch = patch_vt1709},
3487 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3488 .patch = patch_vt1709},
3489 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3490 .patch = patch_vt1709},
3491 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3492 .patch = patch_vt1709},
3493 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3494 .patch = patch_vt1709},
3495 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3496 .patch = patch_vt1709},
3497 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3498 .patch = patch_vt1709},
3499 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3500 .patch = patch_vt1708B},
3501 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3502 .patch = patch_vt1708B},
3503 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3504 .patch = patch_vt1708B},
3505 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3506 .patch = patch_vt1708B},
3507 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3508 .patch = patch_vt1708B},
3509 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3510 .patch = patch_vt1708B},
3511 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3512 .patch = patch_vt1708B},
3513 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3514 .patch = patch_vt1708B},
3515 { .id = 0x11060397, .name = "VT1708S",
3516 .patch = patch_vt1708S},
3517 { .id = 0x11061397, .name = "VT1708S",
3518 .patch = patch_vt1708S},
3519 { .id = 0x11062397, .name = "VT1708S",
3520 .patch = patch_vt1708S},
3521 { .id = 0x11063397, .name = "VT1708S",
3522 .patch = patch_vt1708S},
3523 { .id = 0x11064397, .name = "VT1705",
3524 .patch = patch_vt1708S},
3525 { .id = 0x11065397, .name = "VT1708S",
3526 .patch = patch_vt1708S},
3527 { .id = 0x11066397, .name = "VT1708S",
3528 .patch = patch_vt1708S},
3529 { .id = 0x11067397, .name = "VT1708S",
3530 .patch = patch_vt1708S},
3531 { .id = 0x11060398, .name = "VT1702",
3532 .patch = patch_vt1702},
3533 { .id = 0x11061398, .name = "VT1702",
3534 .patch = patch_vt1702},
3535 { .id = 0x11062398, .name = "VT1702",
3536 .patch = patch_vt1702},
3537 { .id = 0x11063398, .name = "VT1702",
3538 .patch = patch_vt1702},
3539 { .id = 0x11064398, .name = "VT1702",
3540 .patch = patch_vt1702},
3541 { .id = 0x11065398, .name = "VT1702",
3542 .patch = patch_vt1702},
3543 { .id = 0x11066398, .name = "VT1702",
3544 .patch = patch_vt1702},
3545 { .id = 0x11067398, .name = "VT1702",
3546 .patch = patch_vt1702},
3547 { .id = 0x11060428, .name = "VT1718S",
3548 .patch = patch_vt1718S},
3549 { .id = 0x11064428, .name = "VT1718S",
3550 .patch = patch_vt1718S},
3551 { .id = 0x11060441, .name = "VT2020",
3552 .patch = patch_vt1718S},
3553 { .id = 0x11064441, .name = "VT1828S",
3554 .patch = patch_vt1718S},
3555 { .id = 0x11060433, .name = "VT1716S",
3556 .patch = patch_vt1716S},
3557 { .id = 0x1106a721, .name = "VT1716S",
3558 .patch = patch_vt1716S},
3559 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3560 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3561 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3562 { .id = 0x11060440, .name = "VT1818S",
3563 .patch = patch_vt1708S},
3564 { .id = 0x11060446, .name = "VT1802",
3565 .patch = patch_vt2002P},
3566 { .id = 0x11068446, .name = "VT1802",
3567 .patch = patch_vt2002P},
3571 MODULE_ALIAS("snd-hda-codec-id:1106*");
3573 static struct hda_codec_preset_list via_list = {
3574 .preset = snd_hda_preset_via,
3575 .owner = THIS_MODULE,
3578 MODULE_LICENSE("GPL");
3579 MODULE_DESCRIPTION("VIA HD-audio codec");
3581 static int __init patch_via_init(void)
3583 return snd_hda_add_codec_preset(&via_list);
3586 static void __exit patch_via_exit(void)
3588 snd_hda_delete_codec_preset(&via_list);
3591 module_init(patch_via_init)
3592 module_exit(patch_via_exit)