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
88 hda_nid_t path[MAX_NID_PATH_DEPTH];
89 short idx[MAX_NID_PATH_DEPTH];
93 /* codec parameterization */
94 const struct snd_kcontrol_new *mixers[6];
95 unsigned int num_mixers;
97 const struct hda_verb *init_verbs[5];
98 unsigned int num_iverbs;
100 char stream_name_analog[32];
101 char stream_name_hp[32];
102 const struct hda_pcm_stream *stream_analog_playback;
103 const struct hda_pcm_stream *stream_analog_capture;
105 char stream_name_digital[32];
106 const struct hda_pcm_stream *stream_digital_playback;
107 const struct hda_pcm_stream *stream_digital_capture;
110 struct hda_multi_out multiout;
111 hda_nid_t slave_dig_outs[2];
112 hda_nid_t hp_dac_nid;
113 int num_active_streams;
115 struct nid_path out_path[4];
116 struct nid_path hp_path;
117 struct nid_path hp_dep_path;
118 struct nid_path speaker_path;
121 unsigned int num_adc_nids;
122 hda_nid_t adc_nids[3];
123 hda_nid_t mux_nids[3];
124 hda_nid_t aa_mix_nid;
125 hda_nid_t dig_in_nid;
128 const struct hda_input_mux *input_mux;
129 unsigned int cur_mux[3];
131 /* PCM information */
132 struct hda_pcm pcm_rec[3];
134 /* dynamic controls, init_verbs and input_mux */
135 struct auto_pin_cfg autocfg;
136 struct snd_array kctls;
137 struct hda_input_mux private_imux[2];
138 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
141 const struct hda_input_mux *hp_mux;
142 unsigned int hp_independent_mode;
143 unsigned int hp_independent_mode_index;
144 unsigned int dmic_enabled;
145 unsigned int no_pin_power_ctl;
146 enum VIA_HDA_CODEC codec_type;
149 unsigned int smart51_nums;
150 hda_nid_t smart51_pins[2];
152 const char *smart51_labels[2];
153 unsigned int smart51_enabled;
155 /* work to check hp jack state */
156 struct hda_codec *codec;
157 struct delayed_work vt1708_hp_work;
158 int vt1708_jack_detect;
159 int vt1708_hp_present;
161 void (*set_widgets_power_state)(struct hda_codec *codec);
163 struct hda_loopback_check loopback;
165 struct hda_amp_list loopback_list[8];
168 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
169 static struct via_spec * via_new_spec(struct hda_codec *codec)
171 struct via_spec *spec;
173 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
179 spec->codec_type = get_codec_type(codec);
180 /* VT1708BCE & VT1708S are almost same */
181 if (spec->codec_type == VT1708BCE)
182 spec->codec_type = VT1708S;
186 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
188 u32 vendor_id = codec->vendor_id;
189 u16 ven_id = vendor_id >> 16;
190 u16 dev_id = vendor_id & 0xffff;
191 enum VIA_HDA_CODEC codec_type;
194 if (ven_id != 0x1106)
195 codec_type = UNKNOWN;
196 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
198 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
199 codec_type = VT1709_10CH;
200 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
201 codec_type = VT1709_6CH;
202 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
203 codec_type = VT1708B_8CH;
204 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
205 codec_type = VT1708BCE;
206 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
207 codec_type = VT1708B_4CH;
208 else if ((dev_id & 0xfff) == 0x397
209 && (dev_id >> 12) < 8)
210 codec_type = VT1708S;
211 else if ((dev_id & 0xfff) == 0x398
212 && (dev_id >> 12) < 8)
214 else if ((dev_id & 0xfff) == 0x428
215 && (dev_id >> 12) < 8)
216 codec_type = VT1718S;
217 else if (dev_id == 0x0433 || dev_id == 0xa721)
218 codec_type = VT1716S;
219 else if (dev_id == 0x0441 || dev_id == 0x4441)
220 codec_type = VT1718S;
221 else if (dev_id == 0x0438 || dev_id == 0x4438)
222 codec_type = VT2002P;
223 else if (dev_id == 0x0448)
225 else if (dev_id == 0x0440)
226 codec_type = VT1708S;
227 else if ((dev_id & 0xfff) == 0x446)
230 codec_type = UNKNOWN;
234 #define VIA_JACK_EVENT 0x20
235 #define VIA_HP_EVENT 0x01
236 #define VIA_GPIO_EVENT 0x02
237 #define VIA_LINE_EVENT 0x03
242 VIA_CTL_WIDGET_ANALOG_MUTE,
245 static void analog_low_current_mode(struct hda_codec *codec);
246 static bool is_aa_path_mute(struct hda_codec *codec);
248 static void vt1708_start_hp_work(struct via_spec *spec)
250 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
252 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
253 !spec->vt1708_jack_detect);
254 if (!delayed_work_pending(&spec->vt1708_hp_work))
255 schedule_delayed_work(&spec->vt1708_hp_work,
256 msecs_to_jiffies(100));
259 static void vt1708_stop_hp_work(struct via_spec *spec)
261 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
263 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
264 && !is_aa_path_mute(spec->codec))
266 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
267 !spec->vt1708_jack_detect);
268 cancel_delayed_work_sync(&spec->vt1708_hp_work);
271 static void set_widgets_power_state(struct hda_codec *codec)
273 struct via_spec *spec = codec->spec;
274 if (spec->set_widgets_power_state)
275 spec->set_widgets_power_state(codec);
278 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
279 struct snd_ctl_elem_value *ucontrol)
281 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
282 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
284 set_widgets_power_state(codec);
285 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
286 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
287 if (is_aa_path_mute(codec))
288 vt1708_start_hp_work(codec->spec);
290 vt1708_stop_hp_work(codec->spec);
295 /* modify .put = snd_hda_mixer_amp_switch_put */
296 #define ANALOG_INPUT_MUTE \
297 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
300 .info = snd_hda_mixer_amp_switch_info, \
301 .get = snd_hda_mixer_amp_switch_get, \
302 .put = analog_input_switch_put, \
303 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
305 static const struct snd_kcontrol_new via_control_templates[] = {
306 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
307 HDA_CODEC_MUTE(NULL, 0, 0, 0),
312 /* add dynamic controls */
313 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
314 const struct snd_kcontrol_new *tmpl,
317 struct snd_kcontrol_new *knew;
319 snd_array_init(&spec->kctls, sizeof(*knew), 32);
320 knew = snd_array_new(&spec->kctls);
327 knew->name = kstrdup(name, GFP_KERNEL);
334 static int __via_add_control(struct via_spec *spec, int type, const char *name,
335 int idx, unsigned long val)
337 struct snd_kcontrol_new *knew;
339 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
343 if (get_amp_nid_(val))
344 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
345 knew->private_value = val;
349 #define via_add_control(spec, type, name, val) \
350 __via_add_control(spec, type, name, 0, val)
352 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
354 static void via_free_kctls(struct hda_codec *codec)
356 struct via_spec *spec = codec->spec;
358 if (spec->kctls.list) {
359 struct snd_kcontrol_new *kctl = spec->kctls.list;
361 for (i = 0; i < spec->kctls.used; i++)
364 snd_array_free(&spec->kctls);
367 /* create input playback/capture controls for the given pin */
368 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
369 int type_idx, int idx, int mix_nid)
374 sprintf(name, "%s Playback Volume", ctlname);
375 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
376 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
379 sprintf(name, "%s Playback Switch", ctlname);
380 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
381 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
387 /* return the index of the given widget nid as the source of mux;
388 * return -1 if not found;
389 * if num_conns is non-NULL, set the total number of connections
391 static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux,
392 hda_nid_t nid, int *num_conns)
394 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
397 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
400 for (i = 0; i < nums; i++)
406 #define get_connection_index(codec, mux, nid) \
407 __get_connection_index(codec, mux, nid, NULL)
409 /* unmute input amp and select the specificed source */
410 static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid,
411 hda_nid_t src, hda_nid_t mix)
415 idx = __get_connection_index(codec, nid, src, &num_conns);
419 /* select the route explicitly when multiple connections exist */
421 get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
422 snd_hda_codec_write(codec, nid, 0,
423 AC_VERB_SET_CONNECT_SEL, idx);
425 /* unmute if the input amp is present */
426 if (query_amp_caps(codec, nid, HDA_INPUT) &
427 (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE))
428 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
431 /* unmute the src output */
432 if (query_amp_caps(codec, src, HDA_OUTPUT) &
433 (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE))
434 snd_hda_codec_write(codec, src, 0, AC_VERB_SET_AMP_GAIN_MUTE,
437 /* unmute AA-path if present */
440 idx = __get_connection_index(codec, nid, mix, NULL);
442 snd_hda_codec_write(codec, nid, 0,
443 AC_VERB_SET_AMP_GAIN_MUTE,
447 /* set the given pin as output */
448 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
453 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
455 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
456 snd_hda_codec_write(codec, pin, 0,
457 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
460 static void via_auto_init_output(struct hda_codec *codec, hda_nid_t pin,
461 int pin_type, struct nid_path *path)
463 struct via_spec *spec = codec->spec;
471 init_output_pin(codec, pin, pin_type);
472 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
473 if (caps & AC_AMPCAP_MUTE) {
475 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
476 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
480 /* initialize the output path */
481 for (i = path->depth - 1; i > 0; i--) {
482 nid = path->path[i - 1];
483 unmute_and_select(codec, path->path[i], nid, spec->aa_mix_nid);
488 static void via_auto_init_multi_out(struct hda_codec *codec)
490 struct via_spec *spec = codec->spec;
493 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++)
494 via_auto_init_output(codec, spec->autocfg.line_out_pins[i],
495 PIN_OUT, &spec->out_path[i]);
498 static void via_auto_init_hp_out(struct hda_codec *codec)
500 struct via_spec *spec = codec->spec;
502 if (spec->hp_dac_nid)
503 via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP,
506 via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP,
510 static void via_auto_init_speaker_out(struct hda_codec *codec)
512 struct via_spec *spec = codec->spec;
514 if (spec->autocfg.speaker_outs)
515 via_auto_init_output(codec, spec->autocfg.speaker_pins[0],
516 PIN_OUT, &spec->speaker_path);
519 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
521 static void via_auto_init_analog_input(struct hda_codec *codec)
523 struct via_spec *spec = codec->spec;
524 const struct auto_pin_cfg *cfg = &spec->autocfg;
525 hda_nid_t conn[HDA_MAX_CONNECTIONS];
530 for (i = 0; i < spec->num_adc_nids; i++) {
531 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
532 AC_VERB_SET_AMP_GAIN_MUTE,
537 for (i = 0; i < cfg->num_inputs; i++) {
538 hda_nid_t nid = cfg->inputs[i].pin;
539 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
541 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
545 snd_hda_codec_write(codec, nid, 0,
546 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
550 for (i = 0; i < spec->num_adc_nids; i++) {
551 const struct hda_input_mux *imux = spec->input_mux;
552 if (!imux || !spec->mux_nids[i])
554 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
555 AC_VERB_SET_CONNECT_SEL,
556 imux->items[spec->cur_mux[i]].index);
560 if (!spec->aa_mix_nid)
562 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
564 for (i = 0; i < num_conns; i++) {
565 unsigned int caps = get_wcaps(codec, conn[i]);
566 if (get_wcaps_type(caps) == AC_WID_PIN)
567 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
568 AC_VERB_SET_AMP_GAIN_MUTE,
573 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
574 unsigned int *affected_parm)
577 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
578 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
579 >> AC_DEFCFG_MISC_SHIFT
580 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
581 struct via_spec *spec = codec->spec;
582 unsigned present = 0;
584 no_presence |= spec->no_pin_power_ctl;
586 present = snd_hda_jack_detect(codec, nid);
587 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
588 || ((no_presence || present)
589 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
590 *affected_parm = AC_PWRST_D0; /* if it's connected */
595 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
598 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
599 struct snd_ctl_elem_info *uinfo)
601 static const char * const texts[] = {
602 "Disabled", "Enabled"
605 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
607 uinfo->value.enumerated.items = 2;
608 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
609 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
610 strcpy(uinfo->value.enumerated.name,
611 texts[uinfo->value.enumerated.item]);
615 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
616 struct snd_ctl_elem_value *ucontrol)
618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
619 struct via_spec *spec = codec->spec;
620 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
624 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_value *ucontrol)
627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628 struct via_spec *spec = codec->spec;
629 unsigned int val = !ucontrol->value.enumerated.item[0];
631 if (val == spec->no_pin_power_ctl)
633 spec->no_pin_power_ctl = val;
634 set_widgets_power_state(codec);
638 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
639 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
640 .name = "Dynamic Power-Control",
641 .info = via_pin_power_ctl_info,
642 .get = via_pin_power_ctl_get,
643 .put = via_pin_power_ctl_put,
650 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_info *uinfo)
653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
654 struct via_spec *spec = codec->spec;
655 return snd_hda_input_mux_info(spec->input_mux, uinfo);
658 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_value *ucontrol)
661 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
662 struct via_spec *spec = codec->spec;
663 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
665 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
669 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
670 struct snd_ctl_elem_value *ucontrol)
672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
673 struct via_spec *spec = codec->spec;
674 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
677 if (!spec->mux_nids[adc_idx])
679 /* switch to D0 beofre change index */
680 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
681 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
682 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
683 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
685 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
686 spec->mux_nids[adc_idx],
687 &spec->cur_mux[adc_idx]);
688 /* update jack power state */
689 set_widgets_power_state(codec);
694 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
695 struct snd_ctl_elem_info *uinfo)
697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
698 struct via_spec *spec = codec->spec;
699 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
702 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_value *ucontrol)
705 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
706 struct via_spec *spec = codec->spec;
708 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
712 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
713 struct snd_ctl_elem_value *ucontrol)
715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
716 struct via_spec *spec = codec->spec;
717 hda_nid_t nid = kcontrol->private_value;
718 unsigned int pinsel = ucontrol->value.enumerated.item[0];
719 /* Get Independent Mode index of headphone pin widget */
720 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
722 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
724 /* update jack power state */
725 set_widgets_power_state(codec);
729 static const struct snd_kcontrol_new via_hp_mixer = {
730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
731 .name = "Independent HP",
732 .info = via_independent_hp_info,
733 .get = via_independent_hp_get,
734 .put = via_independent_hp_put,
737 static int via_hp_build(struct hda_codec *codec)
739 struct via_spec *spec = codec->spec;
740 struct snd_kcontrol_new *knew;
743 nid = spec->autocfg.hp_pins[0];
744 knew = via_clone_control(spec, &via_hp_mixer);
748 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
749 knew->private_value = nid;
754 static void notify_aa_path_ctls(struct hda_codec *codec)
756 struct via_spec *spec = codec->spec;
759 for (i = 0; i < spec->smart51_nums; i++) {
760 struct snd_kcontrol *ctl;
761 struct snd_ctl_elem_id id;
762 memset(&id, 0, sizeof(id));
763 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
764 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
765 ctl = snd_hda_find_mixer_ctl(codec, id.name);
767 snd_ctl_notify(codec->bus->card,
768 SNDRV_CTL_EVENT_MASK_VALUE,
773 static void mute_aa_path(struct hda_codec *codec, int mute)
775 struct via_spec *spec = codec->spec;
776 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
779 /* check AA path's mute status */
780 for (i = 0; i < spec->smart51_nums; i++) {
781 if (spec->smart51_idxs[i] < 0)
783 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
784 HDA_INPUT, spec->smart51_idxs[i],
789 static bool is_smart51_candidate(struct hda_codec *codec, hda_nid_t pin)
791 struct via_spec *spec = codec->spec;
792 const struct auto_pin_cfg *cfg = &spec->autocfg;
795 for (i = 0; i < cfg->num_inputs; i++) {
797 if (pin != cfg->inputs[i].pin)
799 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
801 defcfg = snd_hda_codec_get_pincfg(codec, pin);
802 if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL)
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_info(struct snd_kcontrol *kcontrol,
821 struct snd_ctl_elem_info *uinfo)
823 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
825 uinfo->value.integer.min = 0;
826 uinfo->value.integer.max = 1;
830 static int via_smart51_get(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;
838 for (i = 0; i < spec->smart51_nums; i++) {
839 hda_nid_t nid = spec->smart51_pins[i];
841 ctl = snd_hda_codec_read(codec, nid, 0,
842 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
843 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
846 *ucontrol->value.integer.value = on;
850 static int via_smart51_put(struct snd_kcontrol *kcontrol,
851 struct snd_ctl_elem_value *ucontrol)
853 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
854 struct via_spec *spec = codec->spec;
855 int out_in = *ucontrol->value.integer.value
856 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
859 for (i = 0; i < spec->smart51_nums; i++) {
860 hda_nid_t nid = spec->smart51_pins[i];
863 parm = snd_hda_codec_read(codec, nid, 0,
864 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
865 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
867 snd_hda_codec_write(codec, nid, 0,
868 AC_VERB_SET_PIN_WIDGET_CONTROL,
870 if (out_in == AC_PINCTL_OUT_EN) {
871 mute_aa_path(codec, 1);
872 notify_aa_path_ctls(codec);
875 spec->smart51_enabled = *ucontrol->value.integer.value;
876 set_widgets_power_state(codec);
880 static const struct snd_kcontrol_new via_smart51_mixer = {
881 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
884 .info = via_smart51_info,
885 .get = via_smart51_get,
886 .put = via_smart51_put,
889 static int via_smart51_build(struct hda_codec *codec)
891 struct via_spec *spec = codec->spec;
893 if (!spec->smart51_nums)
895 if (!via_clone_control(spec, &via_smart51_mixer))
900 /* check AA path's mute status */
901 static bool is_aa_path_mute(struct hda_codec *codec)
903 struct via_spec *spec = codec->spec;
904 const struct hda_amp_list *p;
907 for (i = 0; i < spec->num_loopbacks; i++) {
908 p = &spec->loopback_list[i];
909 for (ch = 0; ch < 2; ch++) {
910 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
912 if (!(v & HDA_AMP_MUTE) && v > 0)
919 /* enter/exit analog low-current mode */
920 static void analog_low_current_mode(struct hda_codec *codec)
922 struct via_spec *spec = codec->spec;
924 unsigned int verb, parm;
926 enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0);
928 /* decide low current mode's verb & parameter */
929 switch (spec->codec_type) {
933 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
939 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
943 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
949 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
952 return; /* other codecs are not supported */
955 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
959 * generic initialization of ADC, input mixers and output mixers
961 static const struct hda_verb vt1708_init_verbs[] = {
962 /* power down jack detect function */
967 static void set_stream_active(struct hda_codec *codec, bool active)
969 struct via_spec *spec = codec->spec;
972 spec->num_active_streams++;
974 spec->num_active_streams--;
975 analog_low_current_mode(codec);
978 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
979 struct hda_codec *codec,
980 struct snd_pcm_substream *substream)
982 struct via_spec *spec = codec->spec;
985 if (!spec->hp_independent_mode)
986 spec->multiout.hp_nid = spec->hp_dac_nid;
987 set_stream_active(codec, true);
988 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
991 spec->multiout.hp_nid = 0;
992 set_stream_active(codec, false);
998 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
999 struct hda_codec *codec,
1000 struct snd_pcm_substream *substream)
1002 struct via_spec *spec = codec->spec;
1004 spec->multiout.hp_nid = 0;
1005 set_stream_active(codec, false);
1009 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1010 struct hda_codec *codec,
1011 struct snd_pcm_substream *substream)
1013 struct via_spec *spec = codec->spec;
1015 if (snd_BUG_ON(!spec->hp_dac_nid))
1017 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1019 set_stream_active(codec, true);
1023 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1024 struct hda_codec *codec,
1025 struct snd_pcm_substream *substream)
1027 set_stream_active(codec, false);
1031 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1032 struct hda_codec *codec,
1033 unsigned int stream_tag,
1034 unsigned int format,
1035 struct snd_pcm_substream *substream)
1037 struct via_spec *spec = codec->spec;
1039 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1041 vt1708_start_hp_work(spec);
1045 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1046 struct hda_codec *codec,
1047 unsigned int stream_tag,
1048 unsigned int format,
1049 struct snd_pcm_substream *substream)
1051 struct via_spec *spec = codec->spec;
1053 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1054 stream_tag, 0, format);
1055 vt1708_start_hp_work(spec);
1059 static int via_playback_multi_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_multi_out_analog_cleanup(codec, &spec->multiout);
1066 vt1708_stop_hp_work(spec);
1070 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1071 struct hda_codec *codec,
1072 struct snd_pcm_substream *substream)
1074 struct via_spec *spec = codec->spec;
1076 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1077 vt1708_stop_hp_work(spec);
1084 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1085 struct hda_codec *codec,
1086 struct snd_pcm_substream *substream)
1088 struct via_spec *spec = codec->spec;
1089 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1092 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1093 struct hda_codec *codec,
1094 struct snd_pcm_substream *substream)
1096 struct via_spec *spec = codec->spec;
1097 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1100 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1101 struct hda_codec *codec,
1102 unsigned int stream_tag,
1103 unsigned int format,
1104 struct snd_pcm_substream *substream)
1106 struct via_spec *spec = codec->spec;
1107 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1108 stream_tag, format, substream);
1111 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1112 struct hda_codec *codec,
1113 struct snd_pcm_substream *substream)
1115 struct via_spec *spec = codec->spec;
1116 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1123 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1124 struct hda_codec *codec,
1125 unsigned int stream_tag,
1126 unsigned int format,
1127 struct snd_pcm_substream *substream)
1129 struct via_spec *spec = codec->spec;
1131 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1132 stream_tag, 0, format);
1136 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1137 struct hda_codec *codec,
1138 struct snd_pcm_substream *substream)
1140 struct via_spec *spec = codec->spec;
1141 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1145 static const struct hda_pcm_stream via_pcm_analog_playback = {
1149 /* NID is set in via_build_pcms */
1151 .open = via_playback_multi_pcm_open,
1152 .close = via_playback_multi_pcm_close,
1153 .prepare = via_playback_multi_pcm_prepare,
1154 .cleanup = via_playback_multi_pcm_cleanup
1158 static const struct hda_pcm_stream via_pcm_hp_playback = {
1162 /* NID is set in via_build_pcms */
1164 .open = via_playback_hp_pcm_open,
1165 .close = via_playback_hp_pcm_close,
1166 .prepare = via_playback_hp_pcm_prepare,
1167 .cleanup = via_playback_hp_pcm_cleanup
1171 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1175 /* NID is set in via_build_pcms */
1176 /* We got noisy outputs on the right channel on VT1708 when
1177 * 24bit samples are used. Until any workaround is found,
1178 * disable the 24bit format, so far.
1180 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1182 .open = via_playback_multi_pcm_open,
1183 .close = via_playback_multi_pcm_close,
1184 .prepare = via_playback_multi_pcm_prepare,
1185 .cleanup = via_playback_multi_pcm_cleanup
1189 static const struct hda_pcm_stream via_pcm_analog_capture = {
1190 .substreams = 1, /* will be changed in via_build_pcms() */
1193 /* NID is set in via_build_pcms */
1195 .prepare = via_capture_pcm_prepare,
1196 .cleanup = via_capture_pcm_cleanup
1200 static const struct hda_pcm_stream via_pcm_digital_playback = {
1204 /* NID is set in via_build_pcms */
1206 .open = via_dig_playback_pcm_open,
1207 .close = via_dig_playback_pcm_close,
1208 .prepare = via_dig_playback_pcm_prepare,
1209 .cleanup = via_dig_playback_pcm_cleanup
1213 static const struct hda_pcm_stream via_pcm_digital_capture = {
1220 * slave controls for virtual master
1222 static const char * const via_slave_vols[] = {
1223 "Front Playback Volume",
1224 "Surround Playback Volume",
1225 "Center Playback Volume",
1226 "LFE Playback Volume",
1227 "Side Playback Volume",
1228 "Headphone Playback Volume",
1229 "Speaker Playback Volume",
1233 static const char * const via_slave_sws[] = {
1234 "Front Playback Switch",
1235 "Surround Playback Switch",
1236 "Center Playback Switch",
1237 "LFE Playback Switch",
1238 "Side Playback Switch",
1239 "Headphone Playback Switch",
1240 "Speaker Playback Switch",
1244 static int via_build_controls(struct hda_codec *codec)
1246 struct via_spec *spec = codec->spec;
1247 struct snd_kcontrol *kctl;
1250 if (spec->set_widgets_power_state)
1251 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1254 for (i = 0; i < spec->num_mixers; i++) {
1255 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1260 if (spec->multiout.dig_out_nid) {
1261 err = snd_hda_create_spdif_out_ctls(codec,
1262 spec->multiout.dig_out_nid,
1263 spec->multiout.dig_out_nid);
1266 err = snd_hda_create_spdif_share_sw(codec,
1270 spec->multiout.share_spdif = 1;
1272 if (spec->dig_in_nid) {
1273 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1278 /* if we have no master control, let's create it */
1279 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1280 unsigned int vmaster_tlv[4];
1281 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1282 HDA_OUTPUT, vmaster_tlv);
1283 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1284 vmaster_tlv, via_slave_vols);
1288 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1289 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1290 NULL, via_slave_sws);
1295 /* assign Capture Source enums to NID */
1296 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1297 for (i = 0; kctl && i < kctl->count; i++) {
1298 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1303 /* init power states */
1304 set_widgets_power_state(codec);
1305 analog_low_current_mode(codec);
1307 via_free_kctls(codec); /* no longer needed */
1311 static int via_build_pcms(struct hda_codec *codec)
1313 struct via_spec *spec = codec->spec;
1314 struct hda_pcm *info = spec->pcm_rec;
1316 codec->num_pcms = 1;
1317 codec->pcm_info = info;
1319 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1320 "%s Analog", codec->chip_name);
1321 info->name = spec->stream_name_analog;
1323 if (!spec->stream_analog_playback)
1324 spec->stream_analog_playback = &via_pcm_analog_playback;
1325 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1326 *spec->stream_analog_playback;
1327 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1328 spec->multiout.dac_nids[0];
1329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1330 spec->multiout.max_channels;
1332 if (!spec->stream_analog_capture)
1333 spec->stream_analog_capture = &via_pcm_analog_capture;
1334 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1335 *spec->stream_analog_capture;
1336 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1337 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1340 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1343 snprintf(spec->stream_name_digital,
1344 sizeof(spec->stream_name_digital),
1345 "%s Digital", codec->chip_name);
1346 info->name = spec->stream_name_digital;
1347 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1348 if (spec->multiout.dig_out_nid) {
1349 if (!spec->stream_digital_playback)
1350 spec->stream_digital_playback =
1351 &via_pcm_digital_playback;
1352 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1353 *spec->stream_digital_playback;
1354 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1355 spec->multiout.dig_out_nid;
1357 if (spec->dig_in_nid) {
1358 if (!spec->stream_digital_capture)
1359 spec->stream_digital_capture =
1360 &via_pcm_digital_capture;
1361 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1362 *spec->stream_digital_capture;
1363 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1368 if (spec->hp_dac_nid) {
1371 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1372 "%s HP", codec->chip_name);
1373 info->name = spec->stream_name_hp;
1374 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1375 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1381 static void via_free(struct hda_codec *codec)
1383 struct via_spec *spec = codec->spec;
1388 via_free_kctls(codec);
1389 vt1708_stop_hp_work(spec);
1393 /* mute/unmute outputs */
1394 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1395 hda_nid_t *pins, bool mute)
1398 for (i = 0; i < num_pins; i++)
1399 snd_hda_codec_write(codec, pins[i], 0,
1400 AC_VERB_SET_PIN_WIDGET_CONTROL,
1401 mute ? 0 : PIN_OUT);
1404 /* mute internal speaker if line-out is plugged */
1405 static void via_line_automute(struct hda_codec *codec, int present)
1407 struct via_spec *spec = codec->spec;
1409 if (!spec->autocfg.speaker_outs)
1412 present = snd_hda_jack_detect(codec,
1413 spec->autocfg.line_out_pins[0]);
1414 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1415 spec->autocfg.speaker_pins,
1419 /* mute internal speaker if HP is plugged */
1420 static void via_hp_automute(struct hda_codec *codec)
1423 struct via_spec *spec = codec->spec;
1425 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) {
1426 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1427 toggle_output_mutes(codec, spec->autocfg.line_outs,
1428 spec->autocfg.line_out_pins,
1431 via_line_automute(codec, present);
1434 static void via_gpio_control(struct hda_codec *codec)
1436 unsigned int gpio_data;
1437 unsigned int vol_counter;
1439 unsigned int master_vol;
1441 struct via_spec *spec = codec->spec;
1443 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1444 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1446 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1447 0xF84, 0) & 0x3F0000) >> 16;
1449 vol = vol_counter & 0x1F;
1450 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1451 AC_VERB_GET_AMP_GAIN_MUTE,
1454 if (gpio_data == 0x02) {
1455 /* unmute line out */
1456 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1457 AC_VERB_SET_PIN_WIDGET_CONTROL,
1459 if (vol_counter & 0x20) {
1460 /* decrease volume */
1461 if (vol > master_vol)
1463 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1467 /* increase volume */
1468 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1470 ((master_vol+vol) > 0x2A) ? 0x2A :
1473 } else if (!(gpio_data & 0x02)) {
1475 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1476 AC_VERB_SET_PIN_WIDGET_CONTROL,
1481 /* unsolicited event for jack sensing */
1482 static void via_unsol_event(struct hda_codec *codec,
1487 if (res & VIA_JACK_EVENT)
1488 set_widgets_power_state(codec);
1490 res &= ~VIA_JACK_EVENT;
1492 if (res == VIA_HP_EVENT)
1493 via_hp_automute(codec);
1494 else if (res == VIA_GPIO_EVENT)
1495 via_gpio_control(codec);
1496 else if (res == VIA_LINE_EVENT)
1497 via_line_automute(codec, false);
1500 #ifdef SND_HDA_NEEDS_RESUME
1501 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1503 struct via_spec *spec = codec->spec;
1504 vt1708_stop_hp_work(spec);
1509 #ifdef CONFIG_SND_HDA_POWER_SAVE
1510 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1512 struct via_spec *spec = codec->spec;
1513 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1520 static int via_init(struct hda_codec *codec);
1522 static const struct hda_codec_ops via_patch_ops = {
1523 .build_controls = via_build_controls,
1524 .build_pcms = via_build_pcms,
1527 .unsol_event = via_unsol_event,
1528 #ifdef SND_HDA_NEEDS_RESUME
1529 .suspend = via_suspend,
1531 #ifdef CONFIG_SND_HDA_POWER_SAVE
1532 .check_power_status = via_check_power_status,
1536 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1538 struct via_spec *spec = codec->spec;
1541 for (i = 0; i < spec->multiout.num_dacs; i++) {
1542 if (spec->multiout.dac_nids[i] == dac)
1545 if (spec->hp_dac_nid == dac)
1550 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1551 hda_nid_t target_dac, struct nid_path *path,
1552 int depth, int wid_type)
1557 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1558 for (i = 0; i < nums; i++) {
1559 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1561 if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
1562 path->path[0] = conn[i];
1568 if (depth >= MAX_NID_PATH_DEPTH)
1570 for (i = 0; i < nums; i++) {
1572 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1573 if (type == AC_WID_AUD_OUT ||
1574 (wid_type != -1 && type != wid_type))
1576 if (__parse_output_path(codec, conn[i], target_dac,
1577 path, depth + 1, AC_WID_AUD_SEL)) {
1578 path->path[path->depth] = conn[i];
1579 path->idx[path->depth] = i;
1587 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1588 hda_nid_t target_dac, struct nid_path *path)
1590 if (__parse_output_path(codec, nid, target_dac, path, 1, -1)) {
1591 path->path[path->depth] = nid;
1598 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1600 struct via_spec *spec = codec->spec;
1601 const struct auto_pin_cfg *cfg = &spec->autocfg;
1605 spec->multiout.dac_nids = spec->private_dac_nids;
1606 spec->multiout.num_dacs = cfg->line_outs;
1607 for (i = 0; i < cfg->line_outs; i++) {
1608 nid = cfg->line_out_pins[i];
1611 if (parse_output_path(codec, nid, 0, &spec->out_path[i]))
1612 spec->private_dac_nids[i] = spec->out_path[i].path[0];
1617 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1618 hda_nid_t pin, hda_nid_t dac, int chs)
1620 struct via_spec *spec = codec->spec;
1625 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1627 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS)
1632 sprintf(name, "%s Playback Volume", pfx);
1633 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1634 HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT));
1639 if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1641 else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE)
1646 sprintf(name, "%s Playback Switch", pfx);
1647 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1648 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1655 static void mangle_smart51(struct hda_codec *codec)
1657 struct via_spec *spec = codec->spec;
1658 struct auto_pin_cfg *cfg = &spec->autocfg;
1661 for (i = 0; i < cfg->num_inputs; i++) {
1662 if (is_smart51_candidate(codec, cfg->inputs[i].pin))
1665 if (cfg->line_outs + nums < 3)
1667 for (i = 0; i < cfg->num_inputs; i++) {
1668 if (!is_smart51_candidate(codec, cfg->inputs[i].pin))
1670 spec->smart51_pins[spec->smart51_nums++] = cfg->inputs[i].pin;
1671 cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin;
1672 if (cfg->line_outs == 3)
1677 /* add playback controls from the parsed DAC table */
1678 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1680 struct via_spec *spec = codec->spec;
1681 struct auto_pin_cfg *cfg = &spec->autocfg;
1682 static const char * const chname[4] = {
1683 "Front", "Surround", "C/LFE", "Side"
1689 old_line_outs = cfg->line_outs;
1690 if (cfg->line_outs == 1)
1691 mangle_smart51(codec);
1693 err = via_auto_fill_dac_nids(codec);
1697 for (i = 0; i < cfg->line_outs; i++) {
1699 pin = cfg->line_out_pins[i];
1700 dac = spec->multiout.dac_nids[i];
1703 if (i == HDA_CLFE) {
1704 err = create_ch_ctls(codec, "Center", pin, dac, 1);
1707 err = create_ch_ctls(codec, "LFE", pin, dac, 2);
1711 const char *pfx = chname[i];
1712 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1713 cfg->line_outs == 1)
1715 err = create_ch_ctls(codec, pfx, pin, dac, 3);
1721 idx = get_connection_index(codec, spec->aa_mix_nid,
1722 spec->multiout.dac_nids[0]);
1724 /* add control to mixer */
1725 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1726 "PCM Playback Volume",
1727 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1731 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1732 "PCM Playback Switch",
1733 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1739 cfg->line_outs = old_line_outs;
1744 static void create_hp_imux(struct via_spec *spec)
1747 struct hda_input_mux *imux = &spec->private_imux[1];
1748 static const char * const texts[] = { "OFF", "ON", NULL};
1750 /* for hp mode select */
1751 for (i = 0; texts[i]; i++)
1752 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1754 spec->hp_mux = &spec->private_imux[1];
1757 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1759 struct via_spec *spec = codec->spec;
1765 if (parse_output_path(codec, pin, 0, &spec->hp_path)) {
1766 spec->hp_dac_nid = spec->hp_path.path[0];
1767 spec->hp_independent_mode_index = spec->hp_path.idx[0];
1768 create_hp_imux(spec);
1771 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1772 &spec->hp_dep_path) &&
1777 err = create_ch_ctls(codec, "Headphone", pin, spec->hp_dac_nid, 3);
1784 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1786 struct via_spec *spec = codec->spec;
1789 pin = spec->autocfg.speaker_pins[0];
1790 if (!spec->autocfg.speaker_outs || !pin)
1793 if (parse_output_path(codec, pin, 0, &spec->speaker_path)) {
1794 dac = spec->speaker_path.path[0];
1795 spec->multiout.extra_out_nid[0] = dac;
1796 return create_ch_ctls(codec, "Speaker", pin, dac, 3);
1798 if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1799 &spec->speaker_path))
1800 return create_ch_ctls(codec, "Speaker", pin, 0, 3);
1806 static int via_fill_adcs(struct hda_codec *codec)
1808 struct via_spec *spec = codec->spec;
1809 hda_nid_t nid = codec->start_nid;
1812 for (i = 0; i < codec->num_nodes; i++, nid++) {
1813 unsigned int wcaps = get_wcaps(codec, nid);
1814 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1816 if (wcaps & AC_WCAP_DIGITAL)
1818 if (!(wcaps & AC_WCAP_CONN_LIST))
1820 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1822 spec->adc_nids[spec->num_adc_nids++] = nid;
1827 static int get_mux_nids(struct hda_codec *codec);
1829 static const struct snd_kcontrol_new via_input_src_ctl = {
1830 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1831 /* The multiple "Capture Source" controls confuse alsamixer
1832 * So call somewhat different..
1834 /* .name = "Capture Source", */
1835 .name = "Input Source",
1836 .info = via_mux_enum_info,
1837 .get = via_mux_enum_get,
1838 .put = via_mux_enum_put,
1841 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
1843 struct hda_amp_list *list;
1845 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
1847 list = spec->loopback_list + spec->num_loopbacks;
1849 list->dir = HDA_INPUT;
1851 spec->num_loopbacks++;
1852 spec->loopback.amplist = spec->loopback_list;
1855 /* create playback/capture controls for input pins */
1856 static int via_auto_create_analog_input_ctls(struct hda_codec *codec,
1857 const struct auto_pin_cfg *cfg)
1859 struct via_spec *spec = codec->spec;
1860 struct hda_input_mux *imux = &spec->private_imux[0];
1861 int i, j, err, idx, idx2, type, type_idx = 0;
1863 hda_nid_t pin_idxs[8];
1866 err = via_fill_adcs(codec);
1869 err = get_mux_nids(codec);
1872 cap_nid = spec->mux_nids[0];
1874 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
1875 ARRAY_SIZE(pin_idxs));
1879 /* for internal loopback recording select */
1880 for (idx = 0; idx < num_idxs; idx++) {
1881 if (pin_idxs[idx] == spec->aa_mix_nid) {
1882 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
1887 for (i = 0; i < cfg->num_inputs; i++) {
1889 type = cfg->inputs[i].type;
1890 for (idx = 0; idx < num_idxs; idx++)
1891 if (pin_idxs[idx] == cfg->inputs[i].pin)
1893 if (idx >= num_idxs)
1895 if (i > 0 && type == cfg->inputs[i - 1].type)
1899 label = hda_get_autocfg_input_label(codec, cfg, i);
1900 idx2 = get_connection_index(codec, spec->aa_mix_nid,
1903 err = via_new_analog_input(spec, label, type_idx,
1904 idx2, spec->aa_mix_nid);
1907 add_loopback_list(spec, spec->aa_mix_nid, idx2);
1909 snd_hda_add_imux_item(imux, label, idx, NULL);
1911 /* remember the label for smart51 control */
1912 for (j = 0; j < spec->smart51_nums; j++) {
1913 if (spec->smart51_pins[j] == cfg->inputs[i].pin) {
1914 spec->smart51_idxs[j] = idx;
1915 spec->smart51_labels[j] = label;
1921 /* create capture mixer elements */
1922 for (i = 0; i < spec->num_adc_nids; i++) {
1923 hda_nid_t adc = spec->adc_nids[i];
1924 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
1925 "Capture Volume", i,
1926 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
1930 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1931 "Capture Switch", i,
1932 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
1938 /* input-source control */
1939 for (i = 0; i < spec->num_adc_nids; i++)
1940 if (!spec->mux_nids[i])
1943 struct snd_kcontrol_new *knew;
1944 knew = via_clone_control(spec, &via_input_src_ctl);
1951 for (i = 0; i < cfg->num_inputs; i++) {
1952 hda_nid_t pin = cfg->inputs[i].pin;
1957 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1959 caps = query_amp_caps(codec, pin, HDA_INPUT);
1960 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
1962 label = hda_get_autocfg_input_label(codec, cfg, i);
1963 snprintf(name, sizeof(name), "%s Boost Volume", label);
1964 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1965 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
1973 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1975 unsigned int def_conf;
1976 unsigned char seqassoc;
1978 def_conf = snd_hda_codec_get_pincfg(codec, nid);
1979 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1980 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1981 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
1982 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
1983 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1984 snd_hda_codec_set_pincfg(codec, nid, def_conf);
1990 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
1991 struct snd_ctl_elem_value *ucontrol)
1993 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1994 struct via_spec *spec = codec->spec;
1996 if (spec->codec_type != VT1708)
1998 spec->vt1708_jack_detect =
1999 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2000 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2004 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2005 struct snd_ctl_elem_value *ucontrol)
2007 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2008 struct via_spec *spec = codec->spec;
2011 if (spec->codec_type != VT1708)
2013 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2014 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2015 == !spec->vt1708_jack_detect;
2016 if (spec->vt1708_jack_detect) {
2017 mute_aa_path(codec, 1);
2018 notify_aa_path_ctls(codec);
2023 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2024 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2025 .name = "Jack Detect",
2027 .info = snd_ctl_boolean_mono_info,
2028 .get = vt1708_jack_detect_get,
2029 .put = vt1708_jack_detect_put,
2032 static void fill_dig_outs(struct hda_codec *codec);
2033 static void fill_dig_in(struct hda_codec *codec);
2035 static int via_parse_auto_config(struct hda_codec *codec)
2037 struct via_spec *spec = codec->spec;
2040 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2043 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2046 err = via_auto_create_multi_out_ctls(codec);
2049 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2052 err = via_auto_create_speaker_ctls(codec);
2055 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
2059 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2061 fill_dig_outs(codec);
2064 if (spec->kctls.list)
2065 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2067 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2069 spec->input_mux = &spec->private_imux[0];
2072 err = via_hp_build(codec);
2077 err = via_smart51_build(codec);
2081 /* assign slave outs */
2082 if (spec->slave_dig_outs[0])
2083 codec->slave_dig_outs = spec->slave_dig_outs;
2088 static void via_auto_init_dig_outs(struct hda_codec *codec)
2090 struct via_spec *spec = codec->spec;
2091 if (spec->multiout.dig_out_nid)
2092 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2093 if (spec->slave_dig_outs[0])
2094 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2097 static void via_auto_init_dig_in(struct hda_codec *codec)
2099 struct via_spec *spec = codec->spec;
2100 if (!spec->dig_in_nid)
2102 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2103 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2106 /* initialize the unsolicited events */
2107 static void via_auto_init_unsol_event(struct hda_codec *codec)
2109 struct via_spec *spec = codec->spec;
2110 struct auto_pin_cfg *cfg = &spec->autocfg;
2114 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2115 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2116 AC_VERB_SET_UNSOLICITED_ENABLE,
2117 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2119 if (cfg->speaker_pins[0])
2120 ev = VIA_LINE_EVENT;
2123 for (i = 0; i < cfg->line_outs; i++) {
2124 if (cfg->line_out_pins[i] &&
2125 is_jack_detectable(codec, cfg->line_out_pins[i]))
2126 snd_hda_codec_write(codec, cfg->line_out_pins[0], 0,
2127 AC_VERB_SET_UNSOLICITED_ENABLE,
2128 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2131 for (i = 0; i < cfg->num_inputs; i++) {
2132 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2133 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2134 AC_VERB_SET_UNSOLICITED_ENABLE,
2135 AC_USRSP_EN | VIA_JACK_EVENT);
2139 static int via_init(struct hda_codec *codec)
2141 struct via_spec *spec = codec->spec;
2144 for (i = 0; i < spec->num_iverbs; i++)
2145 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2147 via_auto_init_multi_out(codec);
2148 via_auto_init_hp_out(codec);
2149 via_auto_init_speaker_out(codec);
2150 via_auto_init_analog_input(codec);
2151 via_auto_init_dig_outs(codec);
2152 via_auto_init_dig_in(codec);
2154 via_auto_init_unsol_event(codec);
2156 via_hp_automute(codec);
2157 via_line_automute(codec, false);
2162 static void vt1708_update_hp_jack_state(struct work_struct *work)
2164 struct via_spec *spec = container_of(work, struct via_spec,
2165 vt1708_hp_work.work);
2166 if (spec->codec_type != VT1708)
2168 /* if jack state toggled */
2169 if (spec->vt1708_hp_present
2170 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2171 spec->vt1708_hp_present ^= 1;
2172 via_hp_automute(spec->codec);
2174 vt1708_start_hp_work(spec);
2177 static int get_mux_nids(struct hda_codec *codec)
2179 struct via_spec *spec = codec->spec;
2180 hda_nid_t nid, conn[8];
2184 for (i = 0; i < spec->num_adc_nids; i++) {
2185 nid = spec->adc_nids[i];
2187 type = get_wcaps_type(get_wcaps(codec, nid));
2188 if (type == AC_WID_PIN)
2190 n = snd_hda_get_connections(codec, nid, conn,
2195 spec->mux_nids[i] = nid;
2204 static int patch_vt1708(struct hda_codec *codec)
2206 struct via_spec *spec;
2209 /* create a codec specific record */
2210 spec = via_new_spec(codec);
2214 spec->aa_mix_nid = 0x17;
2216 /* Add HP and CD pin config connect bit re-config action */
2217 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2218 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2220 /* automatic parse from the BIOS config */
2221 err = via_parse_auto_config(codec);
2227 /* add jack detect on/off control */
2228 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2231 /* disable 32bit format on VT1708 */
2232 if (codec->vendor_id == 0x11061708)
2233 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2235 codec->patch_ops = via_patch_ops;
2237 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2241 static int patch_vt1709_10ch(struct hda_codec *codec)
2243 struct via_spec *spec;
2246 /* create a codec specific record */
2247 spec = via_new_spec(codec);
2251 spec->aa_mix_nid = 0x18;
2253 err = via_parse_auto_config(codec);
2259 codec->patch_ops = via_patch_ops;
2264 * generic initialization of ADC, input mixers and output mixers
2266 static int patch_vt1709_6ch(struct hda_codec *codec)
2268 struct via_spec *spec;
2271 /* create a codec specific record */
2272 spec = via_new_spec(codec);
2276 spec->aa_mix_nid = 0x18;
2278 err = via_parse_auto_config(codec);
2284 codec->patch_ops = via_patch_ops;
2289 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2291 struct via_spec *spec = codec->spec;
2295 if ((spec->codec_type != VT1708B_4CH) &&
2296 (codec->vendor_id != 0x11064397))
2299 /* SW0 (17h) = stereo mixer */
2301 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2302 == ((spec->codec_type == VT1708S) ? 5 : 0));
2304 /* PW 1/2/5 (1ah/1bh/1eh) */
2306 set_pin_power_state(codec, 0x1a, &parm);
2307 set_pin_power_state(codec, 0x1b, &parm);
2308 set_pin_power_state(codec, 0x1e, &parm);
2311 /* SW0 (17h), AIW 0/1 (13h/14h) */
2312 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2313 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2314 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2317 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2319 set_pin_power_state(codec, 0x19, &parm);
2320 if (spec->smart51_enabled)
2321 set_pin_power_state(codec, 0x1b, &parm);
2322 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2323 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2325 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2328 set_pin_power_state(codec, 0x22, &parm);
2329 if (spec->smart51_enabled)
2330 set_pin_power_state(codec, 0x1a, &parm);
2331 snd_hda_codec_write(codec, 0x26, 0,
2332 AC_VERB_SET_POWER_STATE, parm);
2333 snd_hda_codec_write(codec, 0x24, 0,
2334 AC_VERB_SET_POWER_STATE, parm);
2335 } else if (codec->vendor_id == 0x11064397) {
2336 /* PW7(23h), SW2(27h), AOW2(25h) */
2338 set_pin_power_state(codec, 0x23, &parm);
2339 if (spec->smart51_enabled)
2340 set_pin_power_state(codec, 0x1a, &parm);
2341 snd_hda_codec_write(codec, 0x27, 0,
2342 AC_VERB_SET_POWER_STATE, parm);
2343 snd_hda_codec_write(codec, 0x25, 0,
2344 AC_VERB_SET_POWER_STATE, parm);
2347 /* PW 3/4/7 (1ch/1dh/23h) */
2349 /* force to D0 for internal Speaker */
2350 set_pin_power_state(codec, 0x1c, &parm);
2351 set_pin_power_state(codec, 0x1d, &parm);
2353 set_pin_power_state(codec, 0x23, &parm);
2355 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2356 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2357 imux_is_smixer ? AC_PWRST_D0 : parm);
2358 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2360 snd_hda_codec_write(codec, 0x25, 0,
2361 AC_VERB_SET_POWER_STATE, parm);
2362 snd_hda_codec_write(codec, 0x27, 0,
2363 AC_VERB_SET_POWER_STATE, parm);
2364 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2365 snd_hda_codec_write(codec, 0x25, 0,
2366 AC_VERB_SET_POWER_STATE, parm);
2369 static int patch_vt1708S(struct hda_codec *codec);
2370 static int patch_vt1708B_8ch(struct hda_codec *codec)
2372 struct via_spec *spec;
2375 if (get_codec_type(codec) == VT1708BCE)
2376 return patch_vt1708S(codec);
2377 /* create a codec specific record */
2378 spec = via_new_spec(codec);
2382 spec->aa_mix_nid = 0x16;
2384 /* automatic parse from the BIOS config */
2385 err = via_parse_auto_config(codec);
2391 codec->patch_ops = via_patch_ops;
2393 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2398 static int patch_vt1708B_4ch(struct hda_codec *codec)
2400 struct via_spec *spec;
2403 /* create a codec specific record */
2404 spec = via_new_spec(codec);
2408 /* automatic parse from the BIOS config */
2409 err = via_parse_auto_config(codec);
2415 codec->patch_ops = via_patch_ops;
2417 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2422 /* Patch for VT1708S */
2423 static const struct hda_verb vt1708S_init_verbs[] = {
2424 /* Enable Mic Boost Volume backdoor */
2426 /* don't bybass mixer */
2431 /* fill out digital output widgets; one for master and one for slave outputs */
2432 static void fill_dig_outs(struct hda_codec *codec)
2434 struct via_spec *spec = codec->spec;
2437 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2441 nid = spec->autocfg.dig_out_pins[i];
2444 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2447 if (!spec->multiout.dig_out_nid)
2448 spec->multiout.dig_out_nid = nid;
2450 spec->slave_dig_outs[0] = nid;
2451 break; /* at most two dig outs */
2456 static void fill_dig_in(struct hda_codec *codec)
2458 struct via_spec *spec = codec->spec;
2462 if (!spec->autocfg.dig_in_pin)
2465 dig_nid = codec->start_nid;
2466 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2467 unsigned int wcaps = get_wcaps(codec, dig_nid);
2468 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2470 if (!(wcaps & AC_WCAP_DIGITAL))
2472 if (!(wcaps & AC_WCAP_CONN_LIST))
2474 err = get_connection_index(codec, dig_nid,
2475 spec->autocfg.dig_in_pin);
2477 spec->dig_in_nid = dig_nid;
2483 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2484 int offset, int num_steps, int step_size)
2486 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2487 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2488 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2489 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2490 (0 << AC_AMPCAP_MUTE_SHIFT));
2493 static int patch_vt1708S(struct hda_codec *codec)
2495 struct via_spec *spec;
2498 /* create a codec specific record */
2499 spec = via_new_spec(codec);
2503 spec->aa_mix_nid = 0x16;
2504 override_mic_boost(codec, 0x1a, 0, 3, 40);
2505 override_mic_boost(codec, 0x1e, 0, 3, 40);
2507 /* automatic parse from the BIOS config */
2508 err = via_parse_auto_config(codec);
2514 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2516 codec->patch_ops = via_patch_ops;
2518 /* correct names for VT1708BCE */
2519 if (get_codec_type(codec) == VT1708BCE) {
2520 kfree(codec->chip_name);
2521 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2522 snprintf(codec->bus->card->mixername,
2523 sizeof(codec->bus->card->mixername),
2524 "%s %s", codec->vendor_name, codec->chip_name);
2526 /* correct names for VT1705 */
2527 if (codec->vendor_id == 0x11064397) {
2528 kfree(codec->chip_name);
2529 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2530 snprintf(codec->bus->card->mixername,
2531 sizeof(codec->bus->card->mixername),
2532 "%s %s", codec->vendor_name, codec->chip_name);
2534 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2538 /* Patch for VT1702 */
2540 static const struct hda_verb vt1702_init_verbs[] = {
2548 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2550 int imux_is_smixer =
2551 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2554 /* PW 1/2/5 (14h/15h/18h) */
2556 set_pin_power_state(codec, 0x14, &parm);
2557 set_pin_power_state(codec, 0x15, &parm);
2558 set_pin_power_state(codec, 0x18, &parm);
2560 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2561 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2562 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2563 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2564 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2565 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2568 /* PW 3/4 (16h/17h) */
2570 set_pin_power_state(codec, 0x17, &parm);
2571 set_pin_power_state(codec, 0x16, &parm);
2572 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2573 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2574 imux_is_smixer ? AC_PWRST_D0 : parm);
2575 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2576 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2579 static int patch_vt1702(struct hda_codec *codec)
2581 struct via_spec *spec;
2584 /* create a codec specific record */
2585 spec = via_new_spec(codec);
2589 spec->aa_mix_nid = 0x1a;
2591 /* limit AA path volume to 0 dB */
2592 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2593 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2594 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2595 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2596 (1 << AC_AMPCAP_MUTE_SHIFT));
2598 /* automatic parse from the BIOS config */
2599 err = via_parse_auto_config(codec);
2605 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
2607 codec->patch_ops = via_patch_ops;
2609 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
2613 /* Patch for VT1718S */
2615 static const struct hda_verb vt1718S_init_verbs[] = {
2616 /* Enable MW0 adjust Gain 5 */
2618 /* Enable Boost Volume backdoor */
2624 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2626 struct via_spec *spec = codec->spec;
2629 /* MUX6 (1eh) = stereo mixer */
2631 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2633 /* PW 5/6/7 (29h/2ah/2bh) */
2635 set_pin_power_state(codec, 0x29, &parm);
2636 set_pin_power_state(codec, 0x2a, &parm);
2637 set_pin_power_state(codec, 0x2b, &parm);
2640 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2641 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2642 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2643 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2644 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2647 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2649 set_pin_power_state(codec, 0x27, &parm);
2650 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2651 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2653 /* PW2 (26h), AOW2 (ah) */
2655 set_pin_power_state(codec, 0x26, &parm);
2656 if (spec->smart51_enabled)
2657 set_pin_power_state(codec, 0x2b, &parm);
2658 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
2660 /* PW0 (24h), AOW0 (8h) */
2662 set_pin_power_state(codec, 0x24, &parm);
2663 if (!spec->hp_independent_mode) /* check for redirected HP */
2664 set_pin_power_state(codec, 0x28, &parm);
2665 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2666 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
2667 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
2668 imux_is_smixer ? AC_PWRST_D0 : parm);
2670 /* PW1 (25h), AOW1 (9h) */
2672 set_pin_power_state(codec, 0x25, &parm);
2673 if (spec->smart51_enabled)
2674 set_pin_power_state(codec, 0x2a, &parm);
2675 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
2677 if (spec->hp_independent_mode) {
2678 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
2680 set_pin_power_state(codec, 0x28, &parm);
2681 snd_hda_codec_write(codec, 0x1b, 0,
2682 AC_VERB_SET_POWER_STATE, parm);
2683 snd_hda_codec_write(codec, 0x34, 0,
2684 AC_VERB_SET_POWER_STATE, parm);
2685 snd_hda_codec_write(codec, 0xc, 0,
2686 AC_VERB_SET_POWER_STATE, parm);
2690 static int patch_vt1718S(struct hda_codec *codec)
2692 struct via_spec *spec;
2695 /* create a codec specific record */
2696 spec = via_new_spec(codec);
2700 spec->aa_mix_nid = 0x21;
2701 override_mic_boost(codec, 0x2b, 0, 3, 40);
2702 override_mic_boost(codec, 0x29, 0, 3, 40);
2704 /* automatic parse from the BIOS config */
2705 err = via_parse_auto_config(codec);
2711 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
2713 codec->patch_ops = via_patch_ops;
2715 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
2720 /* Patch for VT1716S */
2722 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
2723 struct snd_ctl_elem_info *uinfo)
2725 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2727 uinfo->value.integer.min = 0;
2728 uinfo->value.integer.max = 1;
2732 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
2733 struct snd_ctl_elem_value *ucontrol)
2735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2738 index = snd_hda_codec_read(codec, 0x26, 0,
2739 AC_VERB_GET_CONNECT_SEL, 0);
2741 *ucontrol->value.integer.value = index;
2746 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
2747 struct snd_ctl_elem_value *ucontrol)
2749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2750 struct via_spec *spec = codec->spec;
2751 int index = *ucontrol->value.integer.value;
2753 snd_hda_codec_write(codec, 0x26, 0,
2754 AC_VERB_SET_CONNECT_SEL, index);
2755 spec->dmic_enabled = index;
2756 set_widgets_power_state(codec);
2760 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
2761 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
2763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2764 .name = "Digital Mic Capture Switch",
2765 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
2767 .info = vt1716s_dmic_info,
2768 .get = vt1716s_dmic_get,
2769 .put = vt1716s_dmic_put,
2775 /* mono-out mixer elements */
2776 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
2777 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
2781 static const struct hda_verb vt1716S_init_verbs[] = {
2782 /* Enable Boost Volume backdoor */
2784 /* don't bybass mixer */
2786 /* Enable mono output */
2791 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
2793 struct via_spec *spec = codec->spec;
2796 unsigned int mono_out, present;
2797 /* SW0 (17h) = stereo mixer */
2799 (snd_hda_codec_read(codec, 0x17, 0,
2800 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
2802 /* PW 1/2/5 (1ah/1bh/1eh) */
2804 set_pin_power_state(codec, 0x1a, &parm);
2805 set_pin_power_state(codec, 0x1b, &parm);
2806 set_pin_power_state(codec, 0x1e, &parm);
2809 /* SW0 (17h), AIW0(13h) */
2810 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2811 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2814 set_pin_power_state(codec, 0x1e, &parm);
2816 if (spec->dmic_enabled)
2817 set_pin_power_state(codec, 0x22, &parm);
2819 snd_hda_codec_write(codec, 0x22, 0,
2820 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2822 /* SW2(26h), AIW1(14h) */
2823 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
2824 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2827 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2829 set_pin_power_state(codec, 0x19, &parm);
2830 /* Smart 5.1 PW2(1bh) */
2831 if (spec->smart51_enabled)
2832 set_pin_power_state(codec, 0x1b, &parm);
2833 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2834 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2836 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
2838 set_pin_power_state(codec, 0x23, &parm);
2839 /* Smart 5.1 PW1(1ah) */
2840 if (spec->smart51_enabled)
2841 set_pin_power_state(codec, 0x1a, &parm);
2842 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
2844 /* Smart 5.1 PW5(1eh) */
2845 if (spec->smart51_enabled)
2846 set_pin_power_state(codec, 0x1e, &parm);
2847 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
2850 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
2851 present = snd_hda_jack_detect(codec, 0x1c);
2856 present = snd_hda_jack_detect(codec, 0x1d);
2857 if (!spec->hp_independent_mode && present)
2862 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
2863 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
2864 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
2865 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
2867 /* PW 3/4 (1ch/1dh) */
2869 set_pin_power_state(codec, 0x1c, &parm);
2870 set_pin_power_state(codec, 0x1d, &parm);
2871 /* HP Independent Mode, power on AOW3 */
2872 if (spec->hp_independent_mode)
2873 snd_hda_codec_write(codec, 0x25, 0,
2874 AC_VERB_SET_POWER_STATE, parm);
2876 /* force to D0 for internal Speaker */
2877 /* MW0 (16h), AOW0 (10h) */
2878 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2879 imux_is_smixer ? AC_PWRST_D0 : parm);
2880 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
2881 mono_out ? AC_PWRST_D0 : parm);
2884 static int patch_vt1716S(struct hda_codec *codec)
2886 struct via_spec *spec;
2889 /* create a codec specific record */
2890 spec = via_new_spec(codec);
2894 spec->aa_mix_nid = 0x16;
2895 override_mic_boost(codec, 0x1a, 0, 3, 40);
2896 override_mic_boost(codec, 0x1e, 0, 3, 40);
2898 /* automatic parse from the BIOS config */
2899 err = via_parse_auto_config(codec);
2905 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
2907 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
2910 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
2912 codec->patch_ops = via_patch_ops;
2914 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
2920 static const struct hda_verb vt2002P_init_verbs[] = {
2921 /* Class-D speaker related verbs */
2925 /* Enable Boost Volume backdoor */
2927 /* Enable AOW0 to MW9 */
2932 static const struct hda_verb vt1802_init_verbs[] = {
2933 /* Enable Boost Volume backdoor */
2935 /* Enable AOW0 to MW9 */
2940 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
2942 struct via_spec *spec = codec->spec;
2945 unsigned int present;
2946 /* MUX9 (1eh) = stereo mixer */
2948 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2950 /* PW 5/6/7 (29h/2ah/2bh) */
2952 set_pin_power_state(codec, 0x29, &parm);
2953 set_pin_power_state(codec, 0x2a, &parm);
2954 set_pin_power_state(codec, 0x2b, &parm);
2956 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
2957 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2958 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2959 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2960 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2964 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2966 if (spec->codec_type == VT1802) {
2967 /* PW4 (28h), MW4 (18h), MUX4(38h) */
2969 set_pin_power_state(codec, 0x28, &parm);
2970 snd_hda_codec_write(codec, 0x18, 0,
2971 AC_VERB_SET_POWER_STATE, parm);
2972 snd_hda_codec_write(codec, 0x38, 0,
2973 AC_VERB_SET_POWER_STATE, parm);
2975 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
2977 set_pin_power_state(codec, 0x26, &parm);
2978 snd_hda_codec_write(codec, 0x1c, 0,
2979 AC_VERB_SET_POWER_STATE, parm);
2980 snd_hda_codec_write(codec, 0x37, 0,
2981 AC_VERB_SET_POWER_STATE, parm);
2984 if (spec->codec_type == VT1802) {
2985 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
2987 set_pin_power_state(codec, 0x25, &parm);
2988 snd_hda_codec_write(codec, 0x15, 0,
2989 AC_VERB_SET_POWER_STATE, parm);
2990 snd_hda_codec_write(codec, 0x35, 0,
2991 AC_VERB_SET_POWER_STATE, parm);
2993 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
2995 set_pin_power_state(codec, 0x25, &parm);
2996 snd_hda_codec_write(codec, 0x19, 0,
2997 AC_VERB_SET_POWER_STATE, parm);
2998 snd_hda_codec_write(codec, 0x35, 0,
2999 AC_VERB_SET_POWER_STATE, parm);
3002 if (spec->hp_independent_mode)
3003 snd_hda_codec_write(codec, 0x9, 0,
3004 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3007 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
3008 present = snd_hda_jack_detect(codec, 0x25);
3011 set_pin_power_state(codec, 0x24, &parm);
3012 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3013 if (spec->codec_type == VT1802)
3014 snd_hda_codec_write(codec, 0x14, 0,
3015 AC_VERB_SET_POWER_STATE, parm);
3017 snd_hda_codec_write(codec, 0x18, 0,
3018 AC_VERB_SET_POWER_STATE, parm);
3019 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3022 present = snd_hda_jack_detect(codec, 0x26);
3024 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3025 if (spec->codec_type == VT1802) {
3026 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3027 snd_hda_codec_write(codec, 0x33, 0,
3028 AC_VERB_SET_POWER_STATE, parm);
3029 snd_hda_codec_write(codec, 0x1c, 0,
3030 AC_VERB_SET_POWER_STATE, parm);
3031 snd_hda_codec_write(codec, 0x3c, 0,
3032 AC_VERB_SET_POWER_STATE, parm);
3034 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3035 snd_hda_codec_write(codec, 0x31, 0,
3036 AC_VERB_SET_POWER_STATE, parm);
3037 snd_hda_codec_write(codec, 0x17, 0,
3038 AC_VERB_SET_POWER_STATE, parm);
3039 snd_hda_codec_write(codec, 0x3b, 0,
3040 AC_VERB_SET_POWER_STATE, parm);
3043 if (imux_is_smixer || !is_aa_path_mute(codec))
3044 snd_hda_codec_write(codec, 0x21, 0,
3045 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3047 snd_hda_codec_write(codec, 0x21, 0,
3048 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3051 /* patch for vt2002P */
3052 static int patch_vt2002P(struct hda_codec *codec)
3054 struct via_spec *spec;
3057 /* create a codec specific record */
3058 spec = via_new_spec(codec);
3062 spec->aa_mix_nid = 0x21;
3063 override_mic_boost(codec, 0x2b, 0, 3, 40);
3064 override_mic_boost(codec, 0x29, 0, 3, 40);
3066 /* automatic parse from the BIOS config */
3067 err = via_parse_auto_config(codec);
3073 if (spec->codec_type == VT1802)
3074 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3076 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3078 codec->patch_ops = via_patch_ops;
3080 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3086 static const struct hda_verb vt1812_init_verbs[] = {
3087 /* Enable Boost Volume backdoor */
3089 /* Enable AOW0 to MW9 */
3094 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3096 struct via_spec *spec = codec->spec;
3097 int imux_is_smixer =
3098 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3100 unsigned int present;
3101 /* MUX10 (1eh) = stereo mixer */
3103 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3105 /* PW 5/6/7 (29h/2ah/2bh) */
3107 set_pin_power_state(codec, 0x29, &parm);
3108 set_pin_power_state(codec, 0x2a, &parm);
3109 set_pin_power_state(codec, 0x2b, &parm);
3111 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3112 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3113 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3114 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3115 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3119 snd_hda_codec_write(codec, 0x8, 0,
3120 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3122 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3124 set_pin_power_state(codec, 0x28, &parm);
3125 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3126 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3128 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3130 set_pin_power_state(codec, 0x25, &parm);
3131 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3132 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3133 if (spec->hp_independent_mode)
3134 snd_hda_codec_write(codec, 0x9, 0,
3135 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3137 /* Internal Speaker */
3138 /* PW0 (24h), MW0(14h), MUX0(34h) */
3139 present = snd_hda_jack_detect(codec, 0x25);
3142 set_pin_power_state(codec, 0x24, &parm);
3144 snd_hda_codec_write(codec, 0x14, 0,
3145 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3146 snd_hda_codec_write(codec, 0x34, 0,
3147 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3149 snd_hda_codec_write(codec, 0x14, 0,
3150 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3151 snd_hda_codec_write(codec, 0x34, 0,
3152 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3157 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3158 present = snd_hda_jack_detect(codec, 0x28);
3161 set_pin_power_state(codec, 0x31, &parm);
3163 snd_hda_codec_write(codec, 0x1c, 0,
3164 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3165 snd_hda_codec_write(codec, 0x3c, 0,
3166 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3167 snd_hda_codec_write(codec, 0x3e, 0,
3168 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3170 snd_hda_codec_write(codec, 0x1c, 0,
3171 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3172 snd_hda_codec_write(codec, 0x3c, 0,
3173 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3174 snd_hda_codec_write(codec, 0x3e, 0,
3175 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3178 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3180 set_pin_power_state(codec, 0x33, &parm);
3181 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3182 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3186 /* patch for vt1812 */
3187 static int patch_vt1812(struct hda_codec *codec)
3189 struct via_spec *spec;
3192 /* create a codec specific record */
3193 spec = via_new_spec(codec);
3197 spec->aa_mix_nid = 0x21;
3198 override_mic_boost(codec, 0x2b, 0, 3, 40);
3199 override_mic_boost(codec, 0x29, 0, 3, 40);
3201 /* automatic parse from the BIOS config */
3202 err = via_parse_auto_config(codec);
3208 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3210 codec->patch_ops = via_patch_ops;
3212 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3219 static const struct hda_codec_preset snd_hda_preset_via[] = {
3220 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3221 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3222 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3223 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3224 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3225 .patch = patch_vt1709_10ch},
3226 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3227 .patch = patch_vt1709_10ch},
3228 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3229 .patch = patch_vt1709_10ch},
3230 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3231 .patch = patch_vt1709_10ch},
3232 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3233 .patch = patch_vt1709_6ch},
3234 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3235 .patch = patch_vt1709_6ch},
3236 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3237 .patch = patch_vt1709_6ch},
3238 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3239 .patch = patch_vt1709_6ch},
3240 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3241 .patch = patch_vt1708B_8ch},
3242 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3243 .patch = patch_vt1708B_8ch},
3244 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3245 .patch = patch_vt1708B_8ch},
3246 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3247 .patch = patch_vt1708B_8ch},
3248 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3249 .patch = patch_vt1708B_4ch},
3250 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3251 .patch = patch_vt1708B_4ch},
3252 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3253 .patch = patch_vt1708B_4ch},
3254 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3255 .patch = patch_vt1708B_4ch},
3256 { .id = 0x11060397, .name = "VT1708S",
3257 .patch = patch_vt1708S},
3258 { .id = 0x11061397, .name = "VT1708S",
3259 .patch = patch_vt1708S},
3260 { .id = 0x11062397, .name = "VT1708S",
3261 .patch = patch_vt1708S},
3262 { .id = 0x11063397, .name = "VT1708S",
3263 .patch = patch_vt1708S},
3264 { .id = 0x11064397, .name = "VT1705",
3265 .patch = patch_vt1708S},
3266 { .id = 0x11065397, .name = "VT1708S",
3267 .patch = patch_vt1708S},
3268 { .id = 0x11066397, .name = "VT1708S",
3269 .patch = patch_vt1708S},
3270 { .id = 0x11067397, .name = "VT1708S",
3271 .patch = patch_vt1708S},
3272 { .id = 0x11060398, .name = "VT1702",
3273 .patch = patch_vt1702},
3274 { .id = 0x11061398, .name = "VT1702",
3275 .patch = patch_vt1702},
3276 { .id = 0x11062398, .name = "VT1702",
3277 .patch = patch_vt1702},
3278 { .id = 0x11063398, .name = "VT1702",
3279 .patch = patch_vt1702},
3280 { .id = 0x11064398, .name = "VT1702",
3281 .patch = patch_vt1702},
3282 { .id = 0x11065398, .name = "VT1702",
3283 .patch = patch_vt1702},
3284 { .id = 0x11066398, .name = "VT1702",
3285 .patch = patch_vt1702},
3286 { .id = 0x11067398, .name = "VT1702",
3287 .patch = patch_vt1702},
3288 { .id = 0x11060428, .name = "VT1718S",
3289 .patch = patch_vt1718S},
3290 { .id = 0x11064428, .name = "VT1718S",
3291 .patch = patch_vt1718S},
3292 { .id = 0x11060441, .name = "VT2020",
3293 .patch = patch_vt1718S},
3294 { .id = 0x11064441, .name = "VT1828S",
3295 .patch = patch_vt1718S},
3296 { .id = 0x11060433, .name = "VT1716S",
3297 .patch = patch_vt1716S},
3298 { .id = 0x1106a721, .name = "VT1716S",
3299 .patch = patch_vt1716S},
3300 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3301 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3302 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3303 { .id = 0x11060440, .name = "VT1818S",
3304 .patch = patch_vt1708S},
3305 { .id = 0x11060446, .name = "VT1802",
3306 .patch = patch_vt2002P},
3307 { .id = 0x11068446, .name = "VT1802",
3308 .patch = patch_vt2002P},
3312 MODULE_ALIAS("snd-hda-codec-id:1106*");
3314 static struct hda_codec_preset_list via_list = {
3315 .preset = snd_hda_preset_via,
3316 .owner = THIS_MODULE,
3319 MODULE_LICENSE("GPL");
3320 MODULE_DESCRIPTION("VIA HD-audio codec");
3322 static int __init patch_via_init(void)
3324 return snd_hda_add_codec_preset(&via_list);
3327 static void __exit patch_via_exit(void)
3329 snd_hda_delete_codec_preset(&via_list);
3332 module_init(patch_via_init)
3333 module_exit(patch_via_exit)