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)
91 /* codec parameterization */
92 const struct snd_kcontrol_new *mixers[6];
93 unsigned int num_mixers;
95 const struct hda_verb *init_verbs[5];
96 unsigned int num_iverbs;
98 char stream_name_analog[32];
99 char stream_name_hp[32];
100 const struct hda_pcm_stream *stream_analog_playback;
101 const struct hda_pcm_stream *stream_analog_capture;
103 char stream_name_digital[32];
104 const struct hda_pcm_stream *stream_digital_playback;
105 const struct hda_pcm_stream *stream_digital_capture;
108 struct hda_multi_out multiout;
109 hda_nid_t slave_dig_outs[2];
110 hda_nid_t hp_dac_nid;
111 int num_active_streams;
113 struct nid_path out_path[4];
114 struct nid_path hp_path;
115 struct nid_path hp_dep_path;
116 struct nid_path speaker_path;
119 unsigned int num_adc_nids;
120 hda_nid_t adc_nids[3];
121 hda_nid_t mux_nids[3];
122 hda_nid_t aa_mix_nid;
123 hda_nid_t dig_in_nid;
126 const struct hda_input_mux *input_mux;
127 unsigned int cur_mux[3];
129 /* PCM information */
130 struct hda_pcm pcm_rec[3];
132 /* dynamic controls, init_verbs and input_mux */
133 struct auto_pin_cfg autocfg;
134 struct snd_array kctls;
135 struct hda_input_mux private_imux[2];
136 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
139 const struct hda_input_mux *hp_mux;
140 unsigned int hp_independent_mode;
141 unsigned int hp_independent_mode_index;
142 unsigned int dmic_enabled;
143 unsigned int no_pin_power_ctl;
144 enum VIA_HDA_CODEC codec_type;
147 unsigned int smart51_nums;
148 hda_nid_t smart51_pins[2];
150 const char *smart51_labels[2];
151 unsigned int smart51_enabled;
153 /* work to check hp jack state */
154 struct hda_codec *codec;
155 struct delayed_work vt1708_hp_work;
156 int vt1708_jack_detect;
157 int vt1708_hp_present;
159 void (*set_widgets_power_state)(struct hda_codec *codec);
161 struct hda_loopback_check loopback;
163 struct hda_amp_list loopback_list[8];
166 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
167 static struct via_spec * via_new_spec(struct hda_codec *codec)
169 struct via_spec *spec;
171 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
177 spec->codec_type = get_codec_type(codec);
178 /* VT1708BCE & VT1708S are almost same */
179 if (spec->codec_type == VT1708BCE)
180 spec->codec_type = VT1708S;
184 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
186 u32 vendor_id = codec->vendor_id;
187 u16 ven_id = vendor_id >> 16;
188 u16 dev_id = vendor_id & 0xffff;
189 enum VIA_HDA_CODEC codec_type;
192 if (ven_id != 0x1106)
193 codec_type = UNKNOWN;
194 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
196 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
197 codec_type = VT1709_10CH;
198 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
199 codec_type = VT1709_6CH;
200 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
201 codec_type = VT1708B_8CH;
202 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
203 codec_type = VT1708BCE;
204 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
205 codec_type = VT1708B_4CH;
206 else if ((dev_id & 0xfff) == 0x397
207 && (dev_id >> 12) < 8)
208 codec_type = VT1708S;
209 else if ((dev_id & 0xfff) == 0x398
210 && (dev_id >> 12) < 8)
212 else if ((dev_id & 0xfff) == 0x428
213 && (dev_id >> 12) < 8)
214 codec_type = VT1718S;
215 else if (dev_id == 0x0433 || dev_id == 0xa721)
216 codec_type = VT1716S;
217 else if (dev_id == 0x0441 || dev_id == 0x4441)
218 codec_type = VT1718S;
219 else if (dev_id == 0x0438 || dev_id == 0x4438)
220 codec_type = VT2002P;
221 else if (dev_id == 0x0448)
223 else if (dev_id == 0x0440)
224 codec_type = VT1708S;
225 else if ((dev_id & 0xfff) == 0x446)
228 codec_type = UNKNOWN;
232 #define VIA_JACK_EVENT 0x20
233 #define VIA_HP_EVENT 0x01
234 #define VIA_GPIO_EVENT 0x02
235 #define VIA_LINE_EVENT 0x03
240 VIA_CTL_WIDGET_ANALOG_MUTE,
243 static void analog_low_current_mode(struct hda_codec *codec);
244 static bool is_aa_path_mute(struct hda_codec *codec);
246 static void vt1708_start_hp_work(struct via_spec *spec)
248 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
250 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
251 !spec->vt1708_jack_detect);
252 if (!delayed_work_pending(&spec->vt1708_hp_work))
253 schedule_delayed_work(&spec->vt1708_hp_work,
254 msecs_to_jiffies(100));
257 static void vt1708_stop_hp_work(struct via_spec *spec)
259 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
261 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
262 && !is_aa_path_mute(spec->codec))
264 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
265 !spec->vt1708_jack_detect);
266 cancel_delayed_work_sync(&spec->vt1708_hp_work);
269 static void set_widgets_power_state(struct hda_codec *codec)
271 struct via_spec *spec = codec->spec;
272 if (spec->set_widgets_power_state)
273 spec->set_widgets_power_state(codec);
276 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
277 struct snd_ctl_elem_value *ucontrol)
279 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
280 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
282 set_widgets_power_state(codec);
283 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
284 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
285 if (is_aa_path_mute(codec))
286 vt1708_start_hp_work(codec->spec);
288 vt1708_stop_hp_work(codec->spec);
293 /* modify .put = snd_hda_mixer_amp_switch_put */
294 #define ANALOG_INPUT_MUTE \
295 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
298 .info = snd_hda_mixer_amp_switch_info, \
299 .get = snd_hda_mixer_amp_switch_get, \
300 .put = analog_input_switch_put, \
301 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
303 static const struct snd_kcontrol_new via_control_templates[] = {
304 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
305 HDA_CODEC_MUTE(NULL, 0, 0, 0),
310 /* add dynamic controls */
311 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
312 const struct snd_kcontrol_new *tmpl,
315 struct snd_kcontrol_new *knew;
317 snd_array_init(&spec->kctls, sizeof(*knew), 32);
318 knew = snd_array_new(&spec->kctls);
325 knew->name = kstrdup(name, GFP_KERNEL);
332 static int __via_add_control(struct via_spec *spec, int type, const char *name,
333 int idx, unsigned long val)
335 struct snd_kcontrol_new *knew;
337 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
341 if (get_amp_nid_(val))
342 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
343 knew->private_value = val;
347 #define via_add_control(spec, type, name, val) \
348 __via_add_control(spec, type, name, 0, val)
350 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
352 static void via_free_kctls(struct hda_codec *codec)
354 struct via_spec *spec = codec->spec;
356 if (spec->kctls.list) {
357 struct snd_kcontrol_new *kctl = spec->kctls.list;
359 for (i = 0; i < spec->kctls.used; i++)
362 snd_array_free(&spec->kctls);
365 /* create input playback/capture controls for the given pin */
366 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
367 int type_idx, int idx, int mix_nid)
372 sprintf(name, "%s Playback Volume", ctlname);
373 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
374 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
377 sprintf(name, "%s Playback Switch", ctlname);
378 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
379 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
385 /* return the index of the given widget nid as the source of mux;
386 * return -1 if not found;
387 * if num_conns is non-NULL, set the total number of connections
389 static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux,
390 hda_nid_t nid, int *num_conns)
392 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
395 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
398 for (i = 0; i < nums; i++)
404 #define get_connection_index(codec, mux, nid) \
405 __get_connection_index(codec, mux, nid, NULL)
407 /* unmute input amp and select the specificed source */
408 static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid,
409 hda_nid_t src, hda_nid_t mix)
413 idx = __get_connection_index(codec, nid, src, &num_conns);
417 /* select the route explicitly when multiple connections exist */
419 snd_hda_codec_write(codec, nid, 0,
420 AC_VERB_SET_CONNECT_SEL, idx);
421 /* unmute if the input amp is present */
422 if (!(query_amp_caps(codec, nid, HDA_INPUT) &
423 (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)))
425 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
428 /* unmute AA-path if present */
431 idx = __get_connection_index(codec, nid, mix, NULL);
433 snd_hda_codec_write(codec, nid, 0,
434 AC_VERB_SET_AMP_GAIN_MUTE,
438 /* set the given pin as output */
439 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
444 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
446 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
447 snd_hda_codec_write(codec, pin, 0,
448 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
451 static void via_auto_init_output(struct hda_codec *codec, hda_nid_t pin,
452 int pin_type, struct nid_path *path)
454 struct via_spec *spec = codec->spec;
462 init_output_pin(codec, pin, pin_type);
463 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
464 if (caps & AC_AMPCAP_MUTE) {
466 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
467 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
471 /* initialize the output path */
473 for (i = 0; i < path->depth; i++) {
474 unmute_and_select(codec, nid, path->idx[i], spec->aa_mix_nid);
476 if (query_amp_caps(codec, nid, HDA_OUTPUT) &
477 (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE))
478 snd_hda_codec_write(codec, nid, 0,
479 AC_VERB_SET_AMP_GAIN_MUTE,
485 static void via_auto_init_multi_out(struct hda_codec *codec)
487 struct via_spec *spec = codec->spec;
490 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++)
491 via_auto_init_output(codec, spec->autocfg.line_out_pins[i],
492 PIN_OUT, &spec->out_path[i]);
495 static void via_auto_init_hp_out(struct hda_codec *codec)
497 struct via_spec *spec = codec->spec;
499 if (spec->hp_dac_nid)
500 via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP,
503 via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP,
507 static void via_auto_init_speaker_out(struct hda_codec *codec)
509 struct via_spec *spec = codec->spec;
511 if (spec->autocfg.speaker_outs)
512 via_auto_init_output(codec, spec->autocfg.speaker_pins[0],
513 PIN_OUT, &spec->speaker_path);
516 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
518 static void via_auto_init_analog_input(struct hda_codec *codec)
520 struct via_spec *spec = codec->spec;
521 const struct auto_pin_cfg *cfg = &spec->autocfg;
522 hda_nid_t conn[HDA_MAX_CONNECTIONS];
527 for (i = 0; i < spec->num_adc_nids; i++) {
528 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
529 AC_VERB_SET_AMP_GAIN_MUTE,
534 for (i = 0; i < cfg->num_inputs; i++) {
535 hda_nid_t nid = cfg->inputs[i].pin;
536 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
538 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
542 snd_hda_codec_write(codec, nid, 0,
543 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
547 for (i = 0; i < spec->num_adc_nids; i++) {
548 const struct hda_input_mux *imux = spec->input_mux;
549 if (!imux || !spec->mux_nids[i])
551 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
552 AC_VERB_SET_CONNECT_SEL,
553 imux->items[spec->cur_mux[i]].index);
557 if (!spec->aa_mix_nid)
559 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
561 for (i = 0; i < num_conns; i++) {
562 unsigned int caps = get_wcaps(codec, conn[i]);
563 if (get_wcaps_type(caps) == AC_WID_PIN)
564 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
565 AC_VERB_SET_AMP_GAIN_MUTE,
570 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
571 unsigned int *affected_parm)
574 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
575 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
576 >> AC_DEFCFG_MISC_SHIFT
577 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
578 struct via_spec *spec = codec->spec;
579 unsigned present = 0;
581 no_presence |= spec->no_pin_power_ctl;
583 present = snd_hda_jack_detect(codec, nid);
584 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
585 || ((no_presence || present)
586 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
587 *affected_parm = AC_PWRST_D0; /* if it's connected */
592 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
595 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
596 struct snd_ctl_elem_info *uinfo)
598 static const char * const texts[] = {
599 "Disabled", "Enabled"
602 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
604 uinfo->value.enumerated.items = 2;
605 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
606 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
607 strcpy(uinfo->value.enumerated.name,
608 texts[uinfo->value.enumerated.item]);
612 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
613 struct snd_ctl_elem_value *ucontrol)
615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
616 struct via_spec *spec = codec->spec;
617 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
621 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_value *ucontrol)
624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625 struct via_spec *spec = codec->spec;
626 unsigned int val = !ucontrol->value.enumerated.item[0];
628 if (val == spec->no_pin_power_ctl)
630 spec->no_pin_power_ctl = val;
631 set_widgets_power_state(codec);
635 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
636 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
637 .name = "Dynamic Power-Control",
638 .info = via_pin_power_ctl_info,
639 .get = via_pin_power_ctl_get,
640 .put = via_pin_power_ctl_put,
647 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_info *uinfo)
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct via_spec *spec = codec->spec;
652 return snd_hda_input_mux_info(spec->input_mux, uinfo);
655 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
656 struct snd_ctl_elem_value *ucontrol)
658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659 struct via_spec *spec = codec->spec;
660 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
662 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
666 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct via_spec *spec = codec->spec;
671 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
674 if (!spec->mux_nids[adc_idx])
676 /* switch to D0 beofre change index */
677 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
678 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
679 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
680 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
682 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
683 spec->mux_nids[adc_idx],
684 &spec->cur_mux[adc_idx]);
685 /* update jack power state */
686 set_widgets_power_state(codec);
691 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_info *uinfo)
694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
695 struct via_spec *spec = codec->spec;
696 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
699 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_value *ucontrol)
702 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
703 struct via_spec *spec = codec->spec;
705 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
709 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
710 struct snd_ctl_elem_value *ucontrol)
712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
713 struct via_spec *spec = codec->spec;
714 hda_nid_t nid = kcontrol->private_value;
715 unsigned int pinsel = ucontrol->value.enumerated.item[0];
716 /* Get Independent Mode index of headphone pin widget */
717 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
719 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
721 /* update jack power state */
722 set_widgets_power_state(codec);
726 static const struct snd_kcontrol_new via_hp_mixer = {
727 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
728 .name = "Independent HP",
729 .info = via_independent_hp_info,
730 .get = via_independent_hp_get,
731 .put = via_independent_hp_put,
734 static int via_hp_build(struct hda_codec *codec)
736 struct via_spec *spec = codec->spec;
737 struct snd_kcontrol_new *knew;
740 nid = spec->autocfg.hp_pins[0];
741 knew = via_clone_control(spec, &via_hp_mixer);
745 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
746 knew->private_value = nid;
751 static void notify_aa_path_ctls(struct hda_codec *codec)
753 struct via_spec *spec = codec->spec;
756 for (i = 0; i < spec->smart51_nums; i++) {
757 struct snd_kcontrol *ctl;
758 struct snd_ctl_elem_id id;
759 memset(&id, 0, sizeof(id));
760 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
761 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
762 ctl = snd_hda_find_mixer_ctl(codec, id.name);
764 snd_ctl_notify(codec->bus->card,
765 SNDRV_CTL_EVENT_MASK_VALUE,
770 static void mute_aa_path(struct hda_codec *codec, int mute)
772 struct via_spec *spec = codec->spec;
773 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
776 /* check AA path's mute status */
777 for (i = 0; i < spec->smart51_nums; i++) {
778 if (spec->smart51_idxs[i] < 0)
780 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
781 HDA_INPUT, spec->smart51_idxs[i],
786 static bool is_smart51_candidate(struct hda_codec *codec, hda_nid_t pin)
788 struct via_spec *spec = codec->spec;
789 const struct auto_pin_cfg *cfg = &spec->autocfg;
792 for (i = 0; i < cfg->num_inputs; i++) {
794 if (pin != cfg->inputs[i].pin)
796 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
798 defcfg = snd_hda_codec_get_pincfg(codec, pin);
799 if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL)
806 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
808 struct via_spec *spec = codec->spec;
811 for (i = 0; i < spec->smart51_nums; i++)
812 if (spec->smart51_pins[i] == pin)
817 static int via_smart51_info(struct snd_kcontrol *kcontrol,
818 struct snd_ctl_elem_info *uinfo)
820 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
822 uinfo->value.integer.min = 0;
823 uinfo->value.integer.max = 1;
827 static int via_smart51_get(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_value *ucontrol)
830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831 struct via_spec *spec = codec->spec;
835 for (i = 0; i < spec->smart51_nums; i++) {
836 hda_nid_t nid = spec->smart51_pins[i];
838 ctl = snd_hda_codec_read(codec, nid, 0,
839 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
840 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
843 *ucontrol->value.integer.value = on;
847 static int via_smart51_put(struct snd_kcontrol *kcontrol,
848 struct snd_ctl_elem_value *ucontrol)
850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
851 struct via_spec *spec = codec->spec;
852 int out_in = *ucontrol->value.integer.value
853 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
856 for (i = 0; i < spec->smart51_nums; i++) {
857 hda_nid_t nid = spec->smart51_pins[i];
860 parm = snd_hda_codec_read(codec, nid, 0,
861 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
862 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
864 snd_hda_codec_write(codec, nid, 0,
865 AC_VERB_SET_PIN_WIDGET_CONTROL,
867 if (out_in == AC_PINCTL_OUT_EN) {
868 mute_aa_path(codec, 1);
869 notify_aa_path_ctls(codec);
872 spec->smart51_enabled = *ucontrol->value.integer.value;
873 set_widgets_power_state(codec);
877 static const struct snd_kcontrol_new via_smart51_mixer = {
878 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
881 .info = via_smart51_info,
882 .get = via_smart51_get,
883 .put = via_smart51_put,
886 static int via_smart51_build(struct hda_codec *codec)
888 struct via_spec *spec = codec->spec;
890 if (!spec->smart51_nums)
892 if (!via_clone_control(spec, &via_smart51_mixer))
897 /* check AA path's mute status */
898 static bool is_aa_path_mute(struct hda_codec *codec)
900 struct via_spec *spec = codec->spec;
901 const struct hda_amp_list *p;
904 for (i = 0; i < spec->num_loopbacks; i++) {
905 p = &spec->loopback_list[i];
906 for (ch = 0; ch < 2; ch++) {
907 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
909 if (!(v & HDA_AMP_MUTE) && v > 0)
916 /* enter/exit analog low-current mode */
917 static void analog_low_current_mode(struct hda_codec *codec)
919 struct via_spec *spec = codec->spec;
921 unsigned int verb, parm;
923 enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0);
925 /* decide low current mode's verb & parameter */
926 switch (spec->codec_type) {
930 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
936 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
940 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
946 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
949 return; /* other codecs are not supported */
952 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
956 * generic initialization of ADC, input mixers and output mixers
958 static const struct hda_verb vt1708_init_verbs[] = {
959 /* power down jack detect function */
964 static void set_stream_active(struct hda_codec *codec, bool active)
966 struct via_spec *spec = codec->spec;
969 spec->num_active_streams++;
971 spec->num_active_streams--;
972 analog_low_current_mode(codec);
975 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
976 struct hda_codec *codec,
977 struct snd_pcm_substream *substream)
979 struct via_spec *spec = codec->spec;
982 if (!spec->hp_independent_mode)
983 spec->multiout.hp_nid = spec->hp_dac_nid;
984 set_stream_active(codec, true);
985 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
988 spec->multiout.hp_nid = 0;
989 set_stream_active(codec, false);
995 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
996 struct hda_codec *codec,
997 struct snd_pcm_substream *substream)
999 struct via_spec *spec = codec->spec;
1001 spec->multiout.hp_nid = 0;
1002 set_stream_active(codec, false);
1006 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1007 struct hda_codec *codec,
1008 struct snd_pcm_substream *substream)
1010 struct via_spec *spec = codec->spec;
1012 if (snd_BUG_ON(!spec->hp_dac_nid))
1014 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1016 set_stream_active(codec, true);
1020 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1021 struct hda_codec *codec,
1022 struct snd_pcm_substream *substream)
1024 set_stream_active(codec, false);
1028 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1029 struct hda_codec *codec,
1030 unsigned int stream_tag,
1031 unsigned int format,
1032 struct snd_pcm_substream *substream)
1034 struct via_spec *spec = codec->spec;
1036 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1038 vt1708_start_hp_work(spec);
1042 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1043 struct hda_codec *codec,
1044 unsigned int stream_tag,
1045 unsigned int format,
1046 struct snd_pcm_substream *substream)
1048 struct via_spec *spec = codec->spec;
1050 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1051 stream_tag, 0, format);
1052 vt1708_start_hp_work(spec);
1056 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1057 struct hda_codec *codec,
1058 struct snd_pcm_substream *substream)
1060 struct via_spec *spec = codec->spec;
1062 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1063 vt1708_stop_hp_work(spec);
1067 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1068 struct hda_codec *codec,
1069 struct snd_pcm_substream *substream)
1071 struct via_spec *spec = codec->spec;
1073 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1074 vt1708_stop_hp_work(spec);
1081 static int via_dig_playback_pcm_open(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_open(codec, &spec->multiout);
1089 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1090 struct hda_codec *codec,
1091 struct snd_pcm_substream *substream)
1093 struct via_spec *spec = codec->spec;
1094 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1097 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1098 struct hda_codec *codec,
1099 unsigned int stream_tag,
1100 unsigned int format,
1101 struct snd_pcm_substream *substream)
1103 struct via_spec *spec = codec->spec;
1104 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1105 stream_tag, format, substream);
1108 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1109 struct hda_codec *codec,
1110 struct snd_pcm_substream *substream)
1112 struct via_spec *spec = codec->spec;
1113 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1120 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1121 struct hda_codec *codec,
1122 unsigned int stream_tag,
1123 unsigned int format,
1124 struct snd_pcm_substream *substream)
1126 struct via_spec *spec = codec->spec;
1128 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1129 stream_tag, 0, format);
1133 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1134 struct hda_codec *codec,
1135 struct snd_pcm_substream *substream)
1137 struct via_spec *spec = codec->spec;
1138 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1142 static const struct hda_pcm_stream via_pcm_analog_playback = {
1146 /* NID is set in via_build_pcms */
1148 .open = via_playback_multi_pcm_open,
1149 .close = via_playback_multi_pcm_close,
1150 .prepare = via_playback_multi_pcm_prepare,
1151 .cleanup = via_playback_multi_pcm_cleanup
1155 static const struct hda_pcm_stream via_pcm_hp_playback = {
1159 /* NID is set in via_build_pcms */
1161 .open = via_playback_hp_pcm_open,
1162 .close = via_playback_hp_pcm_close,
1163 .prepare = via_playback_hp_pcm_prepare,
1164 .cleanup = via_playback_hp_pcm_cleanup
1168 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1172 /* NID is set in via_build_pcms */
1173 /* We got noisy outputs on the right channel on VT1708 when
1174 * 24bit samples are used. Until any workaround is found,
1175 * disable the 24bit format, so far.
1177 .formats = SNDRV_PCM_FMTBIT_S16_LE,
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_analog_capture = {
1187 .substreams = 1, /* will be changed in via_build_pcms() */
1190 /* NID is set in via_build_pcms */
1192 .prepare = via_capture_pcm_prepare,
1193 .cleanup = via_capture_pcm_cleanup
1197 static const struct hda_pcm_stream via_pcm_digital_playback = {
1201 /* NID is set in via_build_pcms */
1203 .open = via_dig_playback_pcm_open,
1204 .close = via_dig_playback_pcm_close,
1205 .prepare = via_dig_playback_pcm_prepare,
1206 .cleanup = via_dig_playback_pcm_cleanup
1210 static const struct hda_pcm_stream via_pcm_digital_capture = {
1217 * slave controls for virtual master
1219 static const char * const via_slave_vols[] = {
1220 "Front Playback Volume",
1221 "Surround Playback Volume",
1222 "Center Playback Volume",
1223 "LFE Playback Volume",
1224 "Side Playback Volume",
1225 "Headphone Playback Volume",
1226 "Speaker Playback Volume",
1230 static const char * const via_slave_sws[] = {
1231 "Front Playback Switch",
1232 "Surround Playback Switch",
1233 "Center Playback Switch",
1234 "LFE Playback Switch",
1235 "Side Playback Switch",
1236 "Headphone Playback Switch",
1237 "Speaker Playback Switch",
1241 static int via_build_controls(struct hda_codec *codec)
1243 struct via_spec *spec = codec->spec;
1244 struct snd_kcontrol *kctl;
1247 if (spec->set_widgets_power_state)
1248 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1251 for (i = 0; i < spec->num_mixers; i++) {
1252 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1257 if (spec->multiout.dig_out_nid) {
1258 err = snd_hda_create_spdif_out_ctls(codec,
1259 spec->multiout.dig_out_nid,
1260 spec->multiout.dig_out_nid);
1263 err = snd_hda_create_spdif_share_sw(codec,
1267 spec->multiout.share_spdif = 1;
1269 if (spec->dig_in_nid) {
1270 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1275 /* if we have no master control, let's create it */
1276 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1277 unsigned int vmaster_tlv[4];
1278 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1279 HDA_OUTPUT, vmaster_tlv);
1280 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1281 vmaster_tlv, via_slave_vols);
1285 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1286 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1287 NULL, via_slave_sws);
1292 /* assign Capture Source enums to NID */
1293 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1294 for (i = 0; kctl && i < kctl->count; i++) {
1295 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1300 /* init power states */
1301 set_widgets_power_state(codec);
1302 analog_low_current_mode(codec);
1304 via_free_kctls(codec); /* no longer needed */
1308 static int via_build_pcms(struct hda_codec *codec)
1310 struct via_spec *spec = codec->spec;
1311 struct hda_pcm *info = spec->pcm_rec;
1313 codec->num_pcms = 1;
1314 codec->pcm_info = info;
1316 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1317 "%s Analog", codec->chip_name);
1318 info->name = spec->stream_name_analog;
1320 if (!spec->stream_analog_playback)
1321 spec->stream_analog_playback = &via_pcm_analog_playback;
1322 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1323 *spec->stream_analog_playback;
1324 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1325 spec->multiout.dac_nids[0];
1326 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1327 spec->multiout.max_channels;
1329 if (!spec->stream_analog_capture)
1330 spec->stream_analog_capture = &via_pcm_analog_capture;
1331 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1332 *spec->stream_analog_capture;
1333 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1334 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1337 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1340 snprintf(spec->stream_name_digital,
1341 sizeof(spec->stream_name_digital),
1342 "%s Digital", codec->chip_name);
1343 info->name = spec->stream_name_digital;
1344 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1345 if (spec->multiout.dig_out_nid) {
1346 if (!spec->stream_digital_playback)
1347 spec->stream_digital_playback =
1348 &via_pcm_digital_playback;
1349 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1350 *spec->stream_digital_playback;
1351 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1352 spec->multiout.dig_out_nid;
1354 if (spec->dig_in_nid) {
1355 if (!spec->stream_digital_capture)
1356 spec->stream_digital_capture =
1357 &via_pcm_digital_capture;
1358 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1359 *spec->stream_digital_capture;
1360 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1365 if (spec->hp_dac_nid) {
1368 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1369 "%s HP", codec->chip_name);
1370 info->name = spec->stream_name_hp;
1371 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1372 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1378 static void via_free(struct hda_codec *codec)
1380 struct via_spec *spec = codec->spec;
1385 via_free_kctls(codec);
1386 vt1708_stop_hp_work(spec);
1390 /* mute/unmute outputs */
1391 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1392 hda_nid_t *pins, bool mute)
1395 for (i = 0; i < num_pins; i++)
1396 snd_hda_codec_write(codec, pins[i], 0,
1397 AC_VERB_SET_PIN_WIDGET_CONTROL,
1398 mute ? 0 : PIN_OUT);
1401 /* mute internal speaker if line-out is plugged */
1402 static void via_line_automute(struct hda_codec *codec, int present)
1404 struct via_spec *spec = codec->spec;
1406 if (!spec->autocfg.speaker_outs)
1409 present = snd_hda_jack_detect(codec,
1410 spec->autocfg.line_out_pins[0]);
1411 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1412 spec->autocfg.speaker_pins,
1416 /* mute internal speaker if HP is plugged */
1417 static void via_hp_automute(struct hda_codec *codec)
1420 struct via_spec *spec = codec->spec;
1422 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) {
1423 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1424 toggle_output_mutes(codec, spec->autocfg.line_outs,
1425 spec->autocfg.line_out_pins,
1428 via_line_automute(codec, present);
1431 static void via_gpio_control(struct hda_codec *codec)
1433 unsigned int gpio_data;
1434 unsigned int vol_counter;
1436 unsigned int master_vol;
1438 struct via_spec *spec = codec->spec;
1440 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1441 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1443 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1444 0xF84, 0) & 0x3F0000) >> 16;
1446 vol = vol_counter & 0x1F;
1447 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1448 AC_VERB_GET_AMP_GAIN_MUTE,
1451 if (gpio_data == 0x02) {
1452 /* unmute line out */
1453 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1454 AC_VERB_SET_PIN_WIDGET_CONTROL,
1456 if (vol_counter & 0x20) {
1457 /* decrease volume */
1458 if (vol > master_vol)
1460 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1464 /* increase volume */
1465 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1467 ((master_vol+vol) > 0x2A) ? 0x2A :
1470 } else if (!(gpio_data & 0x02)) {
1472 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1473 AC_VERB_SET_PIN_WIDGET_CONTROL,
1478 /* unsolicited event for jack sensing */
1479 static void via_unsol_event(struct hda_codec *codec,
1484 if (res & VIA_JACK_EVENT)
1485 set_widgets_power_state(codec);
1487 res &= ~VIA_JACK_EVENT;
1489 if (res == VIA_HP_EVENT)
1490 via_hp_automute(codec);
1491 else if (res == VIA_GPIO_EVENT)
1492 via_gpio_control(codec);
1493 else if (res == VIA_LINE_EVENT)
1494 via_line_automute(codec, false);
1497 #ifdef SND_HDA_NEEDS_RESUME
1498 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1500 struct via_spec *spec = codec->spec;
1501 vt1708_stop_hp_work(spec);
1506 #ifdef CONFIG_SND_HDA_POWER_SAVE
1507 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1509 struct via_spec *spec = codec->spec;
1510 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1517 static int via_init(struct hda_codec *codec);
1519 static const struct hda_codec_ops via_patch_ops = {
1520 .build_controls = via_build_controls,
1521 .build_pcms = via_build_pcms,
1524 .unsol_event = via_unsol_event,
1525 #ifdef SND_HDA_NEEDS_RESUME
1526 .suspend = via_suspend,
1528 #ifdef CONFIG_SND_HDA_POWER_SAVE
1529 .check_power_status = via_check_power_status,
1533 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1535 struct via_spec *spec = codec->spec;
1538 for (i = 0; i < spec->multiout.num_dacs; i++) {
1539 if (spec->multiout.dac_nids[i] == dac)
1542 if (spec->hp_dac_nid == dac)
1547 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1548 hda_nid_t target_dac, struct nid_path *path,
1549 int depth, int wid_type)
1554 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1555 for (i = 0; i < nums; i++) {
1556 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1558 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1559 path->path[depth] = conn[i];
1560 path->idx[depth] = i;
1561 path->depth = ++depth;
1567 for (i = 0; i < nums; i++) {
1569 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1570 if (type == AC_WID_AUD_OUT ||
1571 (wid_type != -1 && type != wid_type))
1573 if (parse_output_path(codec, conn[i], target_dac,
1574 path, depth + 1, AC_WID_AUD_SEL)) {
1575 path->path[depth] = conn[i];
1576 path->idx[depth] = i;
1583 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1585 struct via_spec *spec = codec->spec;
1586 const struct auto_pin_cfg *cfg = &spec->autocfg;
1590 spec->multiout.dac_nids = spec->private_dac_nids;
1591 spec->multiout.num_dacs = cfg->line_outs;
1592 for (i = 0; i < cfg->line_outs; i++) {
1593 nid = cfg->line_out_pins[i];
1596 if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1))
1597 spec->private_dac_nids[i] =
1598 spec->out_path[i].path[spec->out_path[i].depth - 1];
1603 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1604 hda_nid_t pin, hda_nid_t dac, int chs)
1606 struct via_spec *spec = codec->spec;
1611 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1613 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1618 sprintf(name, "%s Playback Volume", pfx);
1619 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1620 HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT));
1625 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1627 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1632 sprintf(name, "%s Playback Switch", pfx);
1633 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1634 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1641 static void mangle_smart51(struct hda_codec *codec)
1643 struct via_spec *spec = codec->spec;
1644 struct auto_pin_cfg *cfg = &spec->autocfg;
1647 for (i = 0; i < cfg->num_inputs; i++) {
1648 if (is_smart51_candidate(codec, cfg->inputs[i].pin))
1651 if (cfg->line_outs + nums < 3)
1653 for (i = 0; i < cfg->num_inputs; i++) {
1654 if (!is_smart51_candidate(codec, cfg->inputs[i].pin))
1656 spec->smart51_pins[spec->smart51_nums++] = cfg->inputs[i].pin;
1657 cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin;
1658 if (cfg->line_outs == 3)
1663 /* add playback controls from the parsed DAC table */
1664 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1666 struct via_spec *spec = codec->spec;
1667 struct auto_pin_cfg *cfg = &spec->autocfg;
1668 static const char * const chname[4] = {
1669 "Front", "Surround", "C/LFE", "Side"
1675 old_line_outs = cfg->line_outs;
1676 if (cfg->line_outs == 1)
1677 mangle_smart51(codec);
1679 err = via_auto_fill_dac_nids(codec);
1683 for (i = 0; i < cfg->line_outs; i++) {
1685 pin = cfg->line_out_pins[i];
1686 dac = spec->multiout.dac_nids[i];
1689 if (i == HDA_CLFE) {
1690 err = create_ch_ctls(codec, "Center", pin, dac, 1);
1693 err = create_ch_ctls(codec, "LFE", pin, dac, 2);
1697 const char *pfx = chname[i];
1698 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1699 cfg->line_outs == 1)
1701 err = create_ch_ctls(codec, pfx, pin, dac, 3);
1707 idx = get_connection_index(codec, spec->aa_mix_nid,
1708 spec->multiout.dac_nids[0]);
1710 /* add control to mixer */
1711 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1712 "PCM Playback Volume",
1713 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1717 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1718 "PCM Playback Switch",
1719 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1725 cfg->line_outs = old_line_outs;
1730 static void create_hp_imux(struct via_spec *spec)
1733 struct hda_input_mux *imux = &spec->private_imux[1];
1734 static const char * const texts[] = { "OFF", "ON", NULL};
1736 /* for hp mode select */
1737 for (i = 0; texts[i]; i++)
1738 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1740 spec->hp_mux = &spec->private_imux[1];
1743 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1745 struct via_spec *spec = codec->spec;
1751 if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) {
1752 spec->hp_dac_nid = spec->hp_path.path[spec->hp_path.depth - 1];
1753 spec->hp_independent_mode_index =
1754 spec->hp_path.idx[spec->hp_path.depth - 1];
1755 create_hp_imux(spec);
1758 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1759 &spec->hp_dep_path, 0, -1) &&
1764 err = create_ch_ctls(codec, "Headphone", pin, spec->hp_dac_nid, 3);
1771 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1773 struct via_spec *spec = codec->spec;
1776 pin = spec->autocfg.speaker_pins[0];
1777 if (!spec->autocfg.speaker_outs || !pin)
1780 if (parse_output_path(codec, pin, 0, &spec->speaker_path, 0, -1)) {
1781 dac = spec->speaker_path.path[spec->speaker_path.depth - 1];
1782 spec->multiout.extra_out_nid[0] = dac;
1783 return create_ch_ctls(codec, "Speaker", pin, dac, 3);
1785 if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1786 &spec->speaker_path, 0, -1))
1787 return create_ch_ctls(codec, "Headphone", pin, 0, 3);
1793 static int via_fill_adcs(struct hda_codec *codec)
1795 struct via_spec *spec = codec->spec;
1796 hda_nid_t nid = codec->start_nid;
1799 for (i = 0; i < codec->num_nodes; i++, nid++) {
1800 unsigned int wcaps = get_wcaps(codec, nid);
1801 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1803 if (wcaps & AC_WCAP_DIGITAL)
1805 if (!(wcaps & AC_WCAP_CONN_LIST))
1807 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1809 spec->adc_nids[spec->num_adc_nids++] = nid;
1814 static int get_mux_nids(struct hda_codec *codec);
1816 static const struct snd_kcontrol_new via_input_src_ctl = {
1817 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1818 /* The multiple "Capture Source" controls confuse alsamixer
1819 * So call somewhat different..
1821 /* .name = "Capture Source", */
1822 .name = "Input Source",
1823 .info = via_mux_enum_info,
1824 .get = via_mux_enum_get,
1825 .put = via_mux_enum_put,
1828 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
1830 struct hda_amp_list *list;
1832 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
1834 list = spec->loopback_list + spec->num_loopbacks;
1836 list->dir = HDA_INPUT;
1838 spec->num_loopbacks++;
1839 spec->loopback.amplist = spec->loopback_list;
1842 /* create playback/capture controls for input pins */
1843 static int via_auto_create_analog_input_ctls(struct hda_codec *codec,
1844 const struct auto_pin_cfg *cfg)
1846 struct via_spec *spec = codec->spec;
1847 struct hda_input_mux *imux = &spec->private_imux[0];
1848 int i, j, err, idx, idx2, type, type_idx = 0;
1850 hda_nid_t pin_idxs[8];
1853 err = via_fill_adcs(codec);
1856 err = get_mux_nids(codec);
1859 cap_nid = spec->mux_nids[0];
1861 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
1862 ARRAY_SIZE(pin_idxs));
1866 /* for internal loopback recording select */
1867 for (idx = 0; idx < num_idxs; idx++) {
1868 if (pin_idxs[idx] == spec->aa_mix_nid) {
1869 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
1874 for (i = 0; i < cfg->num_inputs; i++) {
1876 type = cfg->inputs[i].type;
1877 for (idx = 0; idx < num_idxs; idx++)
1878 if (pin_idxs[idx] == cfg->inputs[i].pin)
1880 if (idx >= num_idxs)
1882 if (i > 0 && type == cfg->inputs[i - 1].type)
1886 label = hda_get_autocfg_input_label(codec, cfg, i);
1887 idx2 = get_connection_index(codec, spec->aa_mix_nid,
1890 err = via_new_analog_input(spec, label, type_idx,
1891 idx2, spec->aa_mix_nid);
1894 add_loopback_list(spec, spec->aa_mix_nid, idx2);
1896 snd_hda_add_imux_item(imux, label, idx, NULL);
1898 /* remember the label for smart51 control */
1899 for (j = 0; j < spec->smart51_nums; j++) {
1900 if (spec->smart51_pins[j] == cfg->inputs[i].pin) {
1901 spec->smart51_idxs[j] = idx;
1902 spec->smart51_labels[j] = label;
1908 /* create capture mixer elements */
1909 for (i = 0; i < spec->num_adc_nids; i++) {
1910 hda_nid_t adc = spec->adc_nids[i];
1911 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
1912 "Capture Volume", i,
1913 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
1917 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1918 "Capture Switch", i,
1919 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
1925 /* input-source control */
1926 for (i = 0; i < spec->num_adc_nids; i++)
1927 if (!spec->mux_nids[i])
1930 struct snd_kcontrol_new *knew;
1931 knew = via_clone_control(spec, &via_input_src_ctl);
1938 for (i = 0; i < cfg->num_inputs; i++) {
1939 hda_nid_t pin = cfg->inputs[i].pin;
1944 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1946 caps = query_amp_caps(codec, pin, HDA_INPUT);
1947 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
1949 label = hda_get_autocfg_input_label(codec, cfg, i);
1950 snprintf(name, sizeof(name), "%s Boost Volume", label);
1951 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1952 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
1960 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1962 unsigned int def_conf;
1963 unsigned char seqassoc;
1965 def_conf = snd_hda_codec_get_pincfg(codec, nid);
1966 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1967 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1968 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
1969 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
1970 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1971 snd_hda_codec_set_pincfg(codec, nid, def_conf);
1977 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
1978 struct snd_ctl_elem_value *ucontrol)
1980 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1981 struct via_spec *spec = codec->spec;
1983 if (spec->codec_type != VT1708)
1985 spec->vt1708_jack_detect =
1986 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
1987 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
1991 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
1992 struct snd_ctl_elem_value *ucontrol)
1994 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1995 struct via_spec *spec = codec->spec;
1998 if (spec->codec_type != VT1708)
2000 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2001 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2002 == !spec->vt1708_jack_detect;
2003 if (spec->vt1708_jack_detect) {
2004 mute_aa_path(codec, 1);
2005 notify_aa_path_ctls(codec);
2010 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2011 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2012 .name = "Jack Detect",
2014 .info = snd_ctl_boolean_mono_info,
2015 .get = vt1708_jack_detect_get,
2016 .put = vt1708_jack_detect_put,
2019 static void fill_dig_outs(struct hda_codec *codec);
2020 static void fill_dig_in(struct hda_codec *codec);
2022 static int via_parse_auto_config(struct hda_codec *codec)
2024 struct via_spec *spec = codec->spec;
2027 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2030 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2033 err = via_auto_create_multi_out_ctls(codec);
2036 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2039 err = via_auto_create_speaker_ctls(codec);
2042 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
2046 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2048 fill_dig_outs(codec);
2051 if (spec->kctls.list)
2052 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2054 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2056 spec->input_mux = &spec->private_imux[0];
2059 err = via_hp_build(codec);
2064 err = via_smart51_build(codec);
2068 /* assign slave outs */
2069 if (spec->slave_dig_outs[0])
2070 codec->slave_dig_outs = spec->slave_dig_outs;
2075 static void via_auto_init_dig_outs(struct hda_codec *codec)
2077 struct via_spec *spec = codec->spec;
2078 if (spec->multiout.dig_out_nid)
2079 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2080 if (spec->slave_dig_outs[0])
2081 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2084 static void via_auto_init_dig_in(struct hda_codec *codec)
2086 struct via_spec *spec = codec->spec;
2087 if (!spec->dig_in_nid)
2089 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2090 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2093 /* initialize the unsolicited events */
2094 static void via_auto_init_unsol_event(struct hda_codec *codec)
2096 struct via_spec *spec = codec->spec;
2097 struct auto_pin_cfg *cfg = &spec->autocfg;
2101 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2102 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2103 AC_VERB_SET_UNSOLICITED_ENABLE,
2104 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2106 if (cfg->speaker_pins[0])
2107 ev = VIA_LINE_EVENT;
2110 for (i = 0; i < cfg->line_outs; i++) {
2111 if (cfg->line_out_pins[i] &&
2112 is_jack_detectable(codec, cfg->line_out_pins[i]))
2113 snd_hda_codec_write(codec, cfg->line_out_pins[0], 0,
2114 AC_VERB_SET_UNSOLICITED_ENABLE,
2115 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2118 for (i = 0; i < cfg->num_inputs; i++) {
2119 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2120 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2121 AC_VERB_SET_UNSOLICITED_ENABLE,
2122 AC_USRSP_EN | VIA_JACK_EVENT);
2126 static int via_init(struct hda_codec *codec)
2128 struct via_spec *spec = codec->spec;
2131 for (i = 0; i < spec->num_iverbs; i++)
2132 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2134 via_auto_init_multi_out(codec);
2135 via_auto_init_hp_out(codec);
2136 via_auto_init_speaker_out(codec);
2137 via_auto_init_analog_input(codec);
2138 via_auto_init_dig_outs(codec);
2139 via_auto_init_dig_in(codec);
2141 via_auto_init_unsol_event(codec);
2143 via_hp_automute(codec);
2144 via_line_automute(codec, false);
2149 static void vt1708_update_hp_jack_state(struct work_struct *work)
2151 struct via_spec *spec = container_of(work, struct via_spec,
2152 vt1708_hp_work.work);
2153 if (spec->codec_type != VT1708)
2155 /* if jack state toggled */
2156 if (spec->vt1708_hp_present
2157 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2158 spec->vt1708_hp_present ^= 1;
2159 via_hp_automute(spec->codec);
2161 vt1708_start_hp_work(spec);
2164 static int get_mux_nids(struct hda_codec *codec)
2166 struct via_spec *spec = codec->spec;
2167 hda_nid_t nid, conn[8];
2171 for (i = 0; i < spec->num_adc_nids; i++) {
2172 nid = spec->adc_nids[i];
2174 type = get_wcaps_type(get_wcaps(codec, nid));
2175 if (type == AC_WID_PIN)
2177 n = snd_hda_get_connections(codec, nid, conn,
2182 spec->mux_nids[i] = nid;
2191 static int patch_vt1708(struct hda_codec *codec)
2193 struct via_spec *spec;
2196 /* create a codec specific record */
2197 spec = via_new_spec(codec);
2201 spec->aa_mix_nid = 0x17;
2203 /* Add HP and CD pin config connect bit re-config action */
2204 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2205 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2207 /* automatic parse from the BIOS config */
2208 err = via_parse_auto_config(codec);
2214 /* add jack detect on/off control */
2215 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2218 /* disable 32bit format on VT1708 */
2219 if (codec->vendor_id == 0x11061708)
2220 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2222 codec->patch_ops = via_patch_ops;
2224 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2228 static int patch_vt1709_10ch(struct hda_codec *codec)
2230 struct via_spec *spec;
2233 /* create a codec specific record */
2234 spec = via_new_spec(codec);
2238 spec->aa_mix_nid = 0x18;
2240 err = via_parse_auto_config(codec);
2246 codec->patch_ops = via_patch_ops;
2251 * generic initialization of ADC, input mixers and output mixers
2253 static int patch_vt1709_6ch(struct hda_codec *codec)
2255 struct via_spec *spec;
2258 /* create a codec specific record */
2259 spec = via_new_spec(codec);
2263 spec->aa_mix_nid = 0x18;
2265 err = via_parse_auto_config(codec);
2271 codec->patch_ops = via_patch_ops;
2276 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2278 struct via_spec *spec = codec->spec;
2282 if ((spec->codec_type != VT1708B_4CH) &&
2283 (codec->vendor_id != 0x11064397))
2286 /* SW0 (17h) = stereo mixer */
2288 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2289 == ((spec->codec_type == VT1708S) ? 5 : 0));
2291 /* PW 1/2/5 (1ah/1bh/1eh) */
2293 set_pin_power_state(codec, 0x1a, &parm);
2294 set_pin_power_state(codec, 0x1b, &parm);
2295 set_pin_power_state(codec, 0x1e, &parm);
2298 /* SW0 (17h), AIW 0/1 (13h/14h) */
2299 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2300 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2301 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2304 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2306 set_pin_power_state(codec, 0x19, &parm);
2307 if (spec->smart51_enabled)
2308 set_pin_power_state(codec, 0x1b, &parm);
2309 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2310 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2312 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2315 set_pin_power_state(codec, 0x22, &parm);
2316 if (spec->smart51_enabled)
2317 set_pin_power_state(codec, 0x1a, &parm);
2318 snd_hda_codec_write(codec, 0x26, 0,
2319 AC_VERB_SET_POWER_STATE, parm);
2320 snd_hda_codec_write(codec, 0x24, 0,
2321 AC_VERB_SET_POWER_STATE, parm);
2322 } else if (codec->vendor_id == 0x11064397) {
2323 /* PW7(23h), SW2(27h), AOW2(25h) */
2325 set_pin_power_state(codec, 0x23, &parm);
2326 if (spec->smart51_enabled)
2327 set_pin_power_state(codec, 0x1a, &parm);
2328 snd_hda_codec_write(codec, 0x27, 0,
2329 AC_VERB_SET_POWER_STATE, parm);
2330 snd_hda_codec_write(codec, 0x25, 0,
2331 AC_VERB_SET_POWER_STATE, parm);
2334 /* PW 3/4/7 (1ch/1dh/23h) */
2336 /* force to D0 for internal Speaker */
2337 set_pin_power_state(codec, 0x1c, &parm);
2338 set_pin_power_state(codec, 0x1d, &parm);
2340 set_pin_power_state(codec, 0x23, &parm);
2342 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2343 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2344 imux_is_smixer ? AC_PWRST_D0 : parm);
2345 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2347 snd_hda_codec_write(codec, 0x25, 0,
2348 AC_VERB_SET_POWER_STATE, parm);
2349 snd_hda_codec_write(codec, 0x27, 0,
2350 AC_VERB_SET_POWER_STATE, parm);
2351 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2352 snd_hda_codec_write(codec, 0x25, 0,
2353 AC_VERB_SET_POWER_STATE, parm);
2356 static int patch_vt1708S(struct hda_codec *codec);
2357 static int patch_vt1708B_8ch(struct hda_codec *codec)
2359 struct via_spec *spec;
2362 if (get_codec_type(codec) == VT1708BCE)
2363 return patch_vt1708S(codec);
2364 /* create a codec specific record */
2365 spec = via_new_spec(codec);
2369 spec->aa_mix_nid = 0x16;
2371 /* automatic parse from the BIOS config */
2372 err = via_parse_auto_config(codec);
2378 codec->patch_ops = via_patch_ops;
2380 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2385 static int patch_vt1708B_4ch(struct hda_codec *codec)
2387 struct via_spec *spec;
2390 /* create a codec specific record */
2391 spec = via_new_spec(codec);
2395 /* automatic parse from the BIOS config */
2396 err = via_parse_auto_config(codec);
2402 codec->patch_ops = via_patch_ops;
2404 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2409 /* Patch for VT1708S */
2410 static const struct hda_verb vt1708S_init_verbs[] = {
2411 /* Enable Mic Boost Volume backdoor */
2413 /* don't bybass mixer */
2418 /* fill out digital output widgets; one for master and one for slave outputs */
2419 static void fill_dig_outs(struct hda_codec *codec)
2421 struct via_spec *spec = codec->spec;
2424 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2428 nid = spec->autocfg.dig_out_pins[i];
2431 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2434 if (!spec->multiout.dig_out_nid)
2435 spec->multiout.dig_out_nid = nid;
2437 spec->slave_dig_outs[0] = nid;
2438 break; /* at most two dig outs */
2443 static void fill_dig_in(struct hda_codec *codec)
2445 struct via_spec *spec = codec->spec;
2449 if (!spec->autocfg.dig_in_pin)
2452 dig_nid = codec->start_nid;
2453 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2454 unsigned int wcaps = get_wcaps(codec, dig_nid);
2455 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2457 if (!(wcaps & AC_WCAP_DIGITAL))
2459 if (!(wcaps & AC_WCAP_CONN_LIST))
2461 err = get_connection_index(codec, dig_nid,
2462 spec->autocfg.dig_in_pin);
2464 spec->dig_in_nid = dig_nid;
2470 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2471 int offset, int num_steps, int step_size)
2473 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2474 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2475 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2476 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2477 (0 << AC_AMPCAP_MUTE_SHIFT));
2480 static int patch_vt1708S(struct hda_codec *codec)
2482 struct via_spec *spec;
2485 /* create a codec specific record */
2486 spec = via_new_spec(codec);
2490 spec->aa_mix_nid = 0x16;
2491 override_mic_boost(codec, 0x1a, 0, 3, 40);
2492 override_mic_boost(codec, 0x1e, 0, 3, 40);
2494 /* automatic parse from the BIOS config */
2495 err = via_parse_auto_config(codec);
2501 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2503 codec->patch_ops = via_patch_ops;
2505 /* correct names for VT1708BCE */
2506 if (get_codec_type(codec) == VT1708BCE) {
2507 kfree(codec->chip_name);
2508 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2509 snprintf(codec->bus->card->mixername,
2510 sizeof(codec->bus->card->mixername),
2511 "%s %s", codec->vendor_name, codec->chip_name);
2513 /* correct names for VT1705 */
2514 if (codec->vendor_id == 0x11064397) {
2515 kfree(codec->chip_name);
2516 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2517 snprintf(codec->bus->card->mixername,
2518 sizeof(codec->bus->card->mixername),
2519 "%s %s", codec->vendor_name, codec->chip_name);
2521 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2525 /* Patch for VT1702 */
2527 static const struct hda_verb vt1702_init_verbs[] = {
2535 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2537 int imux_is_smixer =
2538 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2541 /* PW 1/2/5 (14h/15h/18h) */
2543 set_pin_power_state(codec, 0x14, &parm);
2544 set_pin_power_state(codec, 0x15, &parm);
2545 set_pin_power_state(codec, 0x18, &parm);
2547 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2548 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2549 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2550 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2551 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2552 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2555 /* PW 3/4 (16h/17h) */
2557 set_pin_power_state(codec, 0x17, &parm);
2558 set_pin_power_state(codec, 0x16, &parm);
2559 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2560 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2561 imux_is_smixer ? AC_PWRST_D0 : parm);
2562 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2563 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2566 static int patch_vt1702(struct hda_codec *codec)
2568 struct via_spec *spec;
2571 /* create a codec specific record */
2572 spec = via_new_spec(codec);
2576 spec->aa_mix_nid = 0x1a;
2578 /* limit AA path volume to 0 dB */
2579 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2580 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2581 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2582 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2583 (1 << AC_AMPCAP_MUTE_SHIFT));
2585 /* automatic parse from the BIOS config */
2586 err = via_parse_auto_config(codec);
2592 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
2594 codec->patch_ops = via_patch_ops;
2596 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
2600 /* Patch for VT1718S */
2602 static const struct hda_verb vt1718S_init_verbs[] = {
2603 /* Enable MW0 adjust Gain 5 */
2605 /* Enable Boost Volume backdoor */
2611 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2613 struct via_spec *spec = codec->spec;
2616 /* MUX6 (1eh) = stereo mixer */
2618 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2620 /* PW 5/6/7 (29h/2ah/2bh) */
2622 set_pin_power_state(codec, 0x29, &parm);
2623 set_pin_power_state(codec, 0x2a, &parm);
2624 set_pin_power_state(codec, 0x2b, &parm);
2627 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2628 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2629 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2630 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2631 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2634 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2636 set_pin_power_state(codec, 0x27, &parm);
2637 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2638 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2640 /* PW2 (26h), AOW2 (ah) */
2642 set_pin_power_state(codec, 0x26, &parm);
2643 if (spec->smart51_enabled)
2644 set_pin_power_state(codec, 0x2b, &parm);
2645 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
2647 /* PW0 (24h), AOW0 (8h) */
2649 set_pin_power_state(codec, 0x24, &parm);
2650 if (!spec->hp_independent_mode) /* check for redirected HP */
2651 set_pin_power_state(codec, 0x28, &parm);
2652 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2653 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
2654 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
2655 imux_is_smixer ? AC_PWRST_D0 : parm);
2657 /* PW1 (25h), AOW1 (9h) */
2659 set_pin_power_state(codec, 0x25, &parm);
2660 if (spec->smart51_enabled)
2661 set_pin_power_state(codec, 0x2a, &parm);
2662 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
2664 if (spec->hp_independent_mode) {
2665 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
2667 set_pin_power_state(codec, 0x28, &parm);
2668 snd_hda_codec_write(codec, 0x1b, 0,
2669 AC_VERB_SET_POWER_STATE, parm);
2670 snd_hda_codec_write(codec, 0x34, 0,
2671 AC_VERB_SET_POWER_STATE, parm);
2672 snd_hda_codec_write(codec, 0xc, 0,
2673 AC_VERB_SET_POWER_STATE, parm);
2677 static int patch_vt1718S(struct hda_codec *codec)
2679 struct via_spec *spec;
2682 /* create a codec specific record */
2683 spec = via_new_spec(codec);
2687 spec->aa_mix_nid = 0x21;
2688 override_mic_boost(codec, 0x2b, 0, 3, 40);
2689 override_mic_boost(codec, 0x29, 0, 3, 40);
2691 /* automatic parse from the BIOS config */
2692 err = via_parse_auto_config(codec);
2698 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
2700 codec->patch_ops = via_patch_ops;
2702 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
2707 /* Patch for VT1716S */
2709 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
2710 struct snd_ctl_elem_info *uinfo)
2712 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2714 uinfo->value.integer.min = 0;
2715 uinfo->value.integer.max = 1;
2719 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
2720 struct snd_ctl_elem_value *ucontrol)
2722 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2725 index = snd_hda_codec_read(codec, 0x26, 0,
2726 AC_VERB_GET_CONNECT_SEL, 0);
2728 *ucontrol->value.integer.value = index;
2733 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
2734 struct snd_ctl_elem_value *ucontrol)
2736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2737 struct via_spec *spec = codec->spec;
2738 int index = *ucontrol->value.integer.value;
2740 snd_hda_codec_write(codec, 0x26, 0,
2741 AC_VERB_SET_CONNECT_SEL, index);
2742 spec->dmic_enabled = index;
2743 set_widgets_power_state(codec);
2747 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
2748 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
2750 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2751 .name = "Digital Mic Capture Switch",
2752 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
2754 .info = vt1716s_dmic_info,
2755 .get = vt1716s_dmic_get,
2756 .put = vt1716s_dmic_put,
2762 /* mono-out mixer elements */
2763 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
2764 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
2768 static const struct hda_verb vt1716S_init_verbs[] = {
2769 /* Enable Boost Volume backdoor */
2771 /* don't bybass mixer */
2773 /* Enable mono output */
2778 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
2780 struct via_spec *spec = codec->spec;
2783 unsigned int mono_out, present;
2784 /* SW0 (17h) = stereo mixer */
2786 (snd_hda_codec_read(codec, 0x17, 0,
2787 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
2789 /* PW 1/2/5 (1ah/1bh/1eh) */
2791 set_pin_power_state(codec, 0x1a, &parm);
2792 set_pin_power_state(codec, 0x1b, &parm);
2793 set_pin_power_state(codec, 0x1e, &parm);
2796 /* SW0 (17h), AIW0(13h) */
2797 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2798 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2801 set_pin_power_state(codec, 0x1e, &parm);
2803 if (spec->dmic_enabled)
2804 set_pin_power_state(codec, 0x22, &parm);
2806 snd_hda_codec_write(codec, 0x22, 0,
2807 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2809 /* SW2(26h), AIW1(14h) */
2810 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
2811 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2814 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2816 set_pin_power_state(codec, 0x19, &parm);
2817 /* Smart 5.1 PW2(1bh) */
2818 if (spec->smart51_enabled)
2819 set_pin_power_state(codec, 0x1b, &parm);
2820 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2821 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2823 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
2825 set_pin_power_state(codec, 0x23, &parm);
2826 /* Smart 5.1 PW1(1ah) */
2827 if (spec->smart51_enabled)
2828 set_pin_power_state(codec, 0x1a, &parm);
2829 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
2831 /* Smart 5.1 PW5(1eh) */
2832 if (spec->smart51_enabled)
2833 set_pin_power_state(codec, 0x1e, &parm);
2834 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
2837 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
2838 present = snd_hda_jack_detect(codec, 0x1c);
2843 present = snd_hda_jack_detect(codec, 0x1d);
2844 if (!spec->hp_independent_mode && present)
2849 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
2850 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
2851 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
2852 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
2854 /* PW 3/4 (1ch/1dh) */
2856 set_pin_power_state(codec, 0x1c, &parm);
2857 set_pin_power_state(codec, 0x1d, &parm);
2858 /* HP Independent Mode, power on AOW3 */
2859 if (spec->hp_independent_mode)
2860 snd_hda_codec_write(codec, 0x25, 0,
2861 AC_VERB_SET_POWER_STATE, parm);
2863 /* force to D0 for internal Speaker */
2864 /* MW0 (16h), AOW0 (10h) */
2865 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2866 imux_is_smixer ? AC_PWRST_D0 : parm);
2867 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
2868 mono_out ? AC_PWRST_D0 : parm);
2871 static int patch_vt1716S(struct hda_codec *codec)
2873 struct via_spec *spec;
2876 /* create a codec specific record */
2877 spec = via_new_spec(codec);
2881 spec->aa_mix_nid = 0x16;
2882 override_mic_boost(codec, 0x1a, 0, 3, 40);
2883 override_mic_boost(codec, 0x1e, 0, 3, 40);
2885 /* automatic parse from the BIOS config */
2886 err = via_parse_auto_config(codec);
2892 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
2894 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
2897 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
2899 codec->patch_ops = via_patch_ops;
2901 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
2907 static const struct hda_verb vt2002P_init_verbs[] = {
2908 /* Class-D speaker related verbs */
2912 /* Enable Boost Volume backdoor */
2914 /* Enable AOW0 to MW9 */
2919 static const struct hda_verb vt1802_init_verbs[] = {
2920 /* Enable Boost Volume backdoor */
2922 /* Enable AOW0 to MW9 */
2927 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
2929 struct via_spec *spec = codec->spec;
2932 unsigned int present;
2933 /* MUX9 (1eh) = stereo mixer */
2935 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2937 /* PW 5/6/7 (29h/2ah/2bh) */
2939 set_pin_power_state(codec, 0x29, &parm);
2940 set_pin_power_state(codec, 0x2a, &parm);
2941 set_pin_power_state(codec, 0x2b, &parm);
2943 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
2944 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2945 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2946 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2947 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2951 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2953 if (spec->codec_type == VT1802) {
2954 /* PW4 (28h), MW4 (18h), MUX4(38h) */
2956 set_pin_power_state(codec, 0x28, &parm);
2957 snd_hda_codec_write(codec, 0x18, 0,
2958 AC_VERB_SET_POWER_STATE, parm);
2959 snd_hda_codec_write(codec, 0x38, 0,
2960 AC_VERB_SET_POWER_STATE, parm);
2962 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
2964 set_pin_power_state(codec, 0x26, &parm);
2965 snd_hda_codec_write(codec, 0x1c, 0,
2966 AC_VERB_SET_POWER_STATE, parm);
2967 snd_hda_codec_write(codec, 0x37, 0,
2968 AC_VERB_SET_POWER_STATE, parm);
2971 if (spec->codec_type == VT1802) {
2972 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
2974 set_pin_power_state(codec, 0x25, &parm);
2975 snd_hda_codec_write(codec, 0x15, 0,
2976 AC_VERB_SET_POWER_STATE, parm);
2977 snd_hda_codec_write(codec, 0x35, 0,
2978 AC_VERB_SET_POWER_STATE, parm);
2980 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
2982 set_pin_power_state(codec, 0x25, &parm);
2983 snd_hda_codec_write(codec, 0x19, 0,
2984 AC_VERB_SET_POWER_STATE, parm);
2985 snd_hda_codec_write(codec, 0x35, 0,
2986 AC_VERB_SET_POWER_STATE, parm);
2989 if (spec->hp_independent_mode)
2990 snd_hda_codec_write(codec, 0x9, 0,
2991 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2994 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
2995 present = snd_hda_jack_detect(codec, 0x25);
2998 set_pin_power_state(codec, 0x24, &parm);
2999 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3000 if (spec->codec_type == VT1802)
3001 snd_hda_codec_write(codec, 0x14, 0,
3002 AC_VERB_SET_POWER_STATE, parm);
3004 snd_hda_codec_write(codec, 0x18, 0,
3005 AC_VERB_SET_POWER_STATE, parm);
3006 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3009 present = snd_hda_jack_detect(codec, 0x26);
3011 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3012 if (spec->codec_type == VT1802) {
3013 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3014 snd_hda_codec_write(codec, 0x33, 0,
3015 AC_VERB_SET_POWER_STATE, parm);
3016 snd_hda_codec_write(codec, 0x1c, 0,
3017 AC_VERB_SET_POWER_STATE, parm);
3018 snd_hda_codec_write(codec, 0x3c, 0,
3019 AC_VERB_SET_POWER_STATE, parm);
3021 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3022 snd_hda_codec_write(codec, 0x31, 0,
3023 AC_VERB_SET_POWER_STATE, parm);
3024 snd_hda_codec_write(codec, 0x17, 0,
3025 AC_VERB_SET_POWER_STATE, parm);
3026 snd_hda_codec_write(codec, 0x3b, 0,
3027 AC_VERB_SET_POWER_STATE, parm);
3030 if (imux_is_smixer || !is_aa_path_mute(codec))
3031 snd_hda_codec_write(codec, 0x21, 0,
3032 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3034 snd_hda_codec_write(codec, 0x21, 0,
3035 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3038 /* patch for vt2002P */
3039 static int patch_vt2002P(struct hda_codec *codec)
3041 struct via_spec *spec;
3044 /* create a codec specific record */
3045 spec = via_new_spec(codec);
3049 spec->aa_mix_nid = 0x21;
3050 override_mic_boost(codec, 0x2b, 0, 3, 40);
3051 override_mic_boost(codec, 0x29, 0, 3, 40);
3053 /* automatic parse from the BIOS config */
3054 err = via_parse_auto_config(codec);
3060 if (spec->codec_type == VT1802)
3061 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3063 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3065 codec->patch_ops = via_patch_ops;
3067 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3073 static const struct hda_verb vt1812_init_verbs[] = {
3074 /* Enable Boost Volume backdoor */
3076 /* Enable AOW0 to MW9 */
3081 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3083 struct via_spec *spec = codec->spec;
3084 int imux_is_smixer =
3085 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3087 unsigned int present;
3088 /* MUX10 (1eh) = stereo mixer */
3090 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3092 /* PW 5/6/7 (29h/2ah/2bh) */
3094 set_pin_power_state(codec, 0x29, &parm);
3095 set_pin_power_state(codec, 0x2a, &parm);
3096 set_pin_power_state(codec, 0x2b, &parm);
3098 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3099 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3100 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3101 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3102 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3106 snd_hda_codec_write(codec, 0x8, 0,
3107 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3109 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3111 set_pin_power_state(codec, 0x28, &parm);
3112 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3113 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3115 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3117 set_pin_power_state(codec, 0x25, &parm);
3118 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3119 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3120 if (spec->hp_independent_mode)
3121 snd_hda_codec_write(codec, 0x9, 0,
3122 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3124 /* Internal Speaker */
3125 /* PW0 (24h), MW0(14h), MUX0(34h) */
3126 present = snd_hda_jack_detect(codec, 0x25);
3129 set_pin_power_state(codec, 0x24, &parm);
3131 snd_hda_codec_write(codec, 0x14, 0,
3132 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3133 snd_hda_codec_write(codec, 0x34, 0,
3134 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3136 snd_hda_codec_write(codec, 0x14, 0,
3137 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3138 snd_hda_codec_write(codec, 0x34, 0,
3139 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3144 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3145 present = snd_hda_jack_detect(codec, 0x28);
3148 set_pin_power_state(codec, 0x31, &parm);
3150 snd_hda_codec_write(codec, 0x1c, 0,
3151 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3152 snd_hda_codec_write(codec, 0x3c, 0,
3153 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3154 snd_hda_codec_write(codec, 0x3e, 0,
3155 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3157 snd_hda_codec_write(codec, 0x1c, 0,
3158 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3159 snd_hda_codec_write(codec, 0x3c, 0,
3160 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3161 snd_hda_codec_write(codec, 0x3e, 0,
3162 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3165 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3167 set_pin_power_state(codec, 0x33, &parm);
3168 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3169 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3173 /* patch for vt1812 */
3174 static int patch_vt1812(struct hda_codec *codec)
3176 struct via_spec *spec;
3179 /* create a codec specific record */
3180 spec = via_new_spec(codec);
3184 spec->aa_mix_nid = 0x21;
3185 override_mic_boost(codec, 0x2b, 0, 3, 40);
3186 override_mic_boost(codec, 0x29, 0, 3, 40);
3188 /* automatic parse from the BIOS config */
3189 err = via_parse_auto_config(codec);
3195 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3197 codec->patch_ops = via_patch_ops;
3199 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3206 static const struct hda_codec_preset snd_hda_preset_via[] = {
3207 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3208 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3209 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3210 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3211 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3212 .patch = patch_vt1709_10ch},
3213 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3214 .patch = patch_vt1709_10ch},
3215 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3216 .patch = patch_vt1709_10ch},
3217 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3218 .patch = patch_vt1709_10ch},
3219 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3220 .patch = patch_vt1709_6ch},
3221 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3222 .patch = patch_vt1709_6ch},
3223 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3224 .patch = patch_vt1709_6ch},
3225 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3226 .patch = patch_vt1709_6ch},
3227 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3228 .patch = patch_vt1708B_8ch},
3229 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3230 .patch = patch_vt1708B_8ch},
3231 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3232 .patch = patch_vt1708B_8ch},
3233 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3234 .patch = patch_vt1708B_8ch},
3235 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3236 .patch = patch_vt1708B_4ch},
3237 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3238 .patch = patch_vt1708B_4ch},
3239 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3240 .patch = patch_vt1708B_4ch},
3241 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3242 .patch = patch_vt1708B_4ch},
3243 { .id = 0x11060397, .name = "VT1708S",
3244 .patch = patch_vt1708S},
3245 { .id = 0x11061397, .name = "VT1708S",
3246 .patch = patch_vt1708S},
3247 { .id = 0x11062397, .name = "VT1708S",
3248 .patch = patch_vt1708S},
3249 { .id = 0x11063397, .name = "VT1708S",
3250 .patch = patch_vt1708S},
3251 { .id = 0x11064397, .name = "VT1705",
3252 .patch = patch_vt1708S},
3253 { .id = 0x11065397, .name = "VT1708S",
3254 .patch = patch_vt1708S},
3255 { .id = 0x11066397, .name = "VT1708S",
3256 .patch = patch_vt1708S},
3257 { .id = 0x11067397, .name = "VT1708S",
3258 .patch = patch_vt1708S},
3259 { .id = 0x11060398, .name = "VT1702",
3260 .patch = patch_vt1702},
3261 { .id = 0x11061398, .name = "VT1702",
3262 .patch = patch_vt1702},
3263 { .id = 0x11062398, .name = "VT1702",
3264 .patch = patch_vt1702},
3265 { .id = 0x11063398, .name = "VT1702",
3266 .patch = patch_vt1702},
3267 { .id = 0x11064398, .name = "VT1702",
3268 .patch = patch_vt1702},
3269 { .id = 0x11065398, .name = "VT1702",
3270 .patch = patch_vt1702},
3271 { .id = 0x11066398, .name = "VT1702",
3272 .patch = patch_vt1702},
3273 { .id = 0x11067398, .name = "VT1702",
3274 .patch = patch_vt1702},
3275 { .id = 0x11060428, .name = "VT1718S",
3276 .patch = patch_vt1718S},
3277 { .id = 0x11064428, .name = "VT1718S",
3278 .patch = patch_vt1718S},
3279 { .id = 0x11060441, .name = "VT2020",
3280 .patch = patch_vt1718S},
3281 { .id = 0x11064441, .name = "VT1828S",
3282 .patch = patch_vt1718S},
3283 { .id = 0x11060433, .name = "VT1716S",
3284 .patch = patch_vt1716S},
3285 { .id = 0x1106a721, .name = "VT1716S",
3286 .patch = patch_vt1716S},
3287 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3288 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3289 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3290 { .id = 0x11060440, .name = "VT1818S",
3291 .patch = patch_vt1708S},
3292 { .id = 0x11060446, .name = "VT1802",
3293 .patch = patch_vt2002P},
3294 { .id = 0x11068446, .name = "VT1802",
3295 .patch = patch_vt2002P},
3299 MODULE_ALIAS("snd-hda-codec-id:1106*");
3301 static struct hda_codec_preset_list via_list = {
3302 .preset = snd_hda_preset_via,
3303 .owner = THIS_MODULE,
3306 MODULE_LICENSE("GPL");
3307 MODULE_DESCRIPTION("VIA HD-audio codec");
3309 static int __init patch_via_init(void)
3311 return snd_hda_add_codec_preset(&via_list);
3314 static void __exit patch_via_exit(void)
3316 snd_hda_delete_codec_preset(&via_list);
3319 module_init(patch_via_init)
3320 module_exit(patch_via_exit)