2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
58 #define VT1708_HP_PIN_NID 0x20
59 #define VT1708_CD_PIN_NID 0x24
79 #define VT2002P_COMPATIBLE(spec) \
80 ((spec)->codec_type == VT2002P ||\
81 (spec)->codec_type == VT1812 ||\
82 (spec)->codec_type == VT1802)
84 #define MAX_NID_PATH_DEPTH 5
86 /* output-path: DAC -> ... -> pin
87 * idx[] contains the source index number of the next widget;
88 * e.g. idx[0] is the index of the DAC selected by path[1] widget
89 * multi[] indicates whether it's a selector widget with multi-connectors
90 * (i.e. the connection selection is mandatory)
91 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
95 hda_nid_t path[MAX_NID_PATH_DEPTH];
96 unsigned char idx[MAX_NID_PATH_DEPTH];
97 unsigned char multi[MAX_NID_PATH_DEPTH];
99 unsigned int mute_ctl;
103 /* codec parameterization */
104 const struct snd_kcontrol_new *mixers[6];
105 unsigned int num_mixers;
107 const struct hda_verb *init_verbs[5];
108 unsigned int num_iverbs;
110 char stream_name_analog[32];
111 char stream_name_hp[32];
112 const struct hda_pcm_stream *stream_analog_playback;
113 const struct hda_pcm_stream *stream_analog_capture;
115 char stream_name_digital[32];
116 const struct hda_pcm_stream *stream_digital_playback;
117 const struct hda_pcm_stream *stream_digital_capture;
120 struct hda_multi_out multiout;
121 hda_nid_t slave_dig_outs[2];
122 hda_nid_t hp_dac_nid;
123 int num_active_streams;
125 struct nid_path out_path[4];
126 struct nid_path hp_path;
127 struct nid_path hp_dep_path;
128 struct nid_path speaker_path;
131 unsigned int num_adc_nids;
132 hda_nid_t adc_nids[3];
133 hda_nid_t mux_nids[3];
134 hda_nid_t aa_mix_nid;
135 hda_nid_t dig_in_nid;
138 const struct hda_input_mux *input_mux;
139 unsigned int cur_mux[3];
141 /* PCM information */
142 struct hda_pcm pcm_rec[3];
144 /* dynamic controls, init_verbs and input_mux */
145 struct auto_pin_cfg autocfg;
146 struct snd_array kctls;
147 struct hda_input_mux private_imux[2];
148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
151 unsigned int hp_independent_mode;
152 unsigned int dmic_enabled;
153 unsigned int no_pin_power_ctl;
154 enum VIA_HDA_CODEC codec_type;
157 unsigned int smart51_nums;
158 hda_nid_t smart51_pins[2];
160 const char *smart51_labels[2];
161 unsigned int smart51_enabled;
163 /* work to check hp jack state */
164 struct hda_codec *codec;
165 struct delayed_work vt1708_hp_work;
166 int vt1708_jack_detect;
167 int vt1708_hp_present;
169 void (*set_widgets_power_state)(struct hda_codec *codec);
171 struct hda_loopback_check loopback;
173 struct hda_amp_list loopback_list[8];
176 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
177 static struct via_spec * via_new_spec(struct hda_codec *codec)
179 struct via_spec *spec;
181 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
187 spec->codec_type = get_codec_type(codec);
188 /* VT1708BCE & VT1708S are almost same */
189 if (spec->codec_type == VT1708BCE)
190 spec->codec_type = VT1708S;
194 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
196 u32 vendor_id = codec->vendor_id;
197 u16 ven_id = vendor_id >> 16;
198 u16 dev_id = vendor_id & 0xffff;
199 enum VIA_HDA_CODEC codec_type;
202 if (ven_id != 0x1106)
203 codec_type = UNKNOWN;
204 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
206 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
207 codec_type = VT1709_10CH;
208 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
209 codec_type = VT1709_6CH;
210 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
211 codec_type = VT1708B_8CH;
212 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
213 codec_type = VT1708BCE;
214 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
215 codec_type = VT1708B_4CH;
216 else if ((dev_id & 0xfff) == 0x397
217 && (dev_id >> 12) < 8)
218 codec_type = VT1708S;
219 else if ((dev_id & 0xfff) == 0x398
220 && (dev_id >> 12) < 8)
222 else if ((dev_id & 0xfff) == 0x428
223 && (dev_id >> 12) < 8)
224 codec_type = VT1718S;
225 else if (dev_id == 0x0433 || dev_id == 0xa721)
226 codec_type = VT1716S;
227 else if (dev_id == 0x0441 || dev_id == 0x4441)
228 codec_type = VT1718S;
229 else if (dev_id == 0x0438 || dev_id == 0x4438)
230 codec_type = VT2002P;
231 else if (dev_id == 0x0448)
233 else if (dev_id == 0x0440)
234 codec_type = VT1708S;
235 else if ((dev_id & 0xfff) == 0x446)
238 codec_type = UNKNOWN;
242 #define VIA_JACK_EVENT 0x20
243 #define VIA_HP_EVENT 0x01
244 #define VIA_GPIO_EVENT 0x02
245 #define VIA_LINE_EVENT 0x03
250 VIA_CTL_WIDGET_ANALOG_MUTE,
253 static void analog_low_current_mode(struct hda_codec *codec);
254 static bool is_aa_path_mute(struct hda_codec *codec);
256 static void vt1708_start_hp_work(struct via_spec *spec)
258 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
260 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
261 !spec->vt1708_jack_detect);
262 if (!delayed_work_pending(&spec->vt1708_hp_work))
263 schedule_delayed_work(&spec->vt1708_hp_work,
264 msecs_to_jiffies(100));
267 static void vt1708_stop_hp_work(struct via_spec *spec)
269 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
271 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
272 && !is_aa_path_mute(spec->codec))
274 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
275 !spec->vt1708_jack_detect);
276 cancel_delayed_work_sync(&spec->vt1708_hp_work);
279 static void set_widgets_power_state(struct hda_codec *codec)
281 struct via_spec *spec = codec->spec;
282 if (spec->set_widgets_power_state)
283 spec->set_widgets_power_state(codec);
286 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
287 struct snd_ctl_elem_value *ucontrol)
289 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
290 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
292 set_widgets_power_state(codec);
293 analog_low_current_mode(snd_kcontrol_chip(kcontrol));
294 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
295 if (is_aa_path_mute(codec))
296 vt1708_start_hp_work(codec->spec);
298 vt1708_stop_hp_work(codec->spec);
303 /* modify .put = snd_hda_mixer_amp_switch_put */
304 #define ANALOG_INPUT_MUTE \
305 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
308 .info = snd_hda_mixer_amp_switch_info, \
309 .get = snd_hda_mixer_amp_switch_get, \
310 .put = analog_input_switch_put, \
311 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
313 static const struct snd_kcontrol_new via_control_templates[] = {
314 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
315 HDA_CODEC_MUTE(NULL, 0, 0, 0),
320 /* add dynamic controls */
321 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
322 const struct snd_kcontrol_new *tmpl,
325 struct snd_kcontrol_new *knew;
327 snd_array_init(&spec->kctls, sizeof(*knew), 32);
328 knew = snd_array_new(&spec->kctls);
335 knew->name = kstrdup(name, GFP_KERNEL);
342 static int __via_add_control(struct via_spec *spec, int type, const char *name,
343 int idx, unsigned long val)
345 struct snd_kcontrol_new *knew;
347 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
351 if (get_amp_nid_(val))
352 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
353 knew->private_value = val;
357 #define via_add_control(spec, type, name, val) \
358 __via_add_control(spec, type, name, 0, val)
360 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
362 static void via_free_kctls(struct hda_codec *codec)
364 struct via_spec *spec = codec->spec;
366 if (spec->kctls.list) {
367 struct snd_kcontrol_new *kctl = spec->kctls.list;
369 for (i = 0; i < spec->kctls.used; i++)
372 snd_array_free(&spec->kctls);
375 /* create input playback/capture controls for the given pin */
376 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
377 int type_idx, int idx, int mix_nid)
382 sprintf(name, "%s Playback Volume", ctlname);
383 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
384 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
387 sprintf(name, "%s Playback Switch", ctlname);
388 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
389 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
395 /* return the index of the given widget nid as the source of mux;
396 * return -1 if not found;
397 * if num_conns is non-NULL, set the total number of connections
399 static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux,
400 hda_nid_t nid, int *num_conns)
402 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
405 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
408 for (i = 0; i < nums; i++)
414 #define get_connection_index(codec, mux, nid) \
415 __get_connection_index(codec, mux, nid, NULL)
417 static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
423 caps = get_wcaps(codec, nid);
424 if (dir == HDA_INPUT)
425 caps &= AC_WCAP_IN_AMP;
427 caps &= AC_WCAP_OUT_AMP;
430 if (query_amp_caps(codec, nid, dir) & mask)
435 #define have_mute(codec, nid, dir) \
436 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
438 /* enable/disable the output-route */
439 static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
440 bool enable, bool force)
443 for (i = 0; i < path->depth; i++) {
445 int idx = path->idx[i];
447 if (i < path->depth - 1)
448 dst = path->path[i + 1];
451 if (enable && path->multi[i])
452 snd_hda_codec_write(codec, dst, 0,
453 AC_VERB_SET_CONNECT_SEL, idx);
454 if (have_mute(codec, dst, HDA_INPUT)) {
455 int val = enable ? AMP_IN_UNMUTE(idx) :
457 snd_hda_codec_write(codec, dst, 0,
458 AC_VERB_SET_AMP_GAIN_MUTE, val);
460 if (!force && (src == path->vol_ctl || src == path->mute_ctl))
462 if (have_mute(codec, src, HDA_OUTPUT)) {
463 int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
464 snd_hda_codec_write(codec, src, 0,
465 AC_VERB_SET_AMP_GAIN_MUTE, val);
470 /* set the given pin as output */
471 static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
476 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
478 if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
479 snd_hda_codec_write(codec, pin, 0,
480 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
483 static void via_auto_init_output(struct hda_codec *codec,
484 struct nid_path *path, int pin_type,
487 struct via_spec *spec = codec->spec;
494 pin = path->path[path->depth - 1];
496 init_output_pin(codec, pin, pin_type);
497 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
498 if (caps & AC_AMPCAP_MUTE) {
500 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
501 snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
505 activate_output_path(codec, path, true, force);
507 /* initialize the AA-path */
508 if (!spec->aa_mix_nid)
510 for (i = path->depth - 1; i > 0; i--) {
512 idx = get_connection_index(codec, nid, spec->aa_mix_nid);
514 if (have_mute(codec, nid, HDA_INPUT))
515 snd_hda_codec_write(codec, nid, 0,
516 AC_VERB_SET_AMP_GAIN_MUTE,
523 static void via_auto_init_multi_out(struct hda_codec *codec)
525 struct via_spec *spec = codec->spec;
528 for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++)
529 via_auto_init_output(codec, &spec->out_path[i], PIN_OUT, true);
532 static void via_auto_init_hp_out(struct hda_codec *codec)
534 struct via_spec *spec = codec->spec;
536 if (!spec->hp_dac_nid) {
537 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true);
540 if (spec->hp_independent_mode) {
541 activate_output_path(codec, &spec->hp_dep_path, false, false);
542 via_auto_init_output(codec, &spec->hp_path, PIN_HP, true);
544 activate_output_path(codec, &spec->hp_path, false, false);
545 via_auto_init_output(codec, &spec->hp_dep_path, PIN_HP, true);
549 static void via_auto_init_speaker_out(struct hda_codec *codec)
551 struct via_spec *spec = codec->spec;
553 if (spec->autocfg.speaker_outs)
554 via_auto_init_output(codec, &spec->speaker_path, PIN_OUT, true);
557 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
559 static void via_auto_init_analog_input(struct hda_codec *codec)
561 struct via_spec *spec = codec->spec;
562 const struct auto_pin_cfg *cfg = &spec->autocfg;
563 hda_nid_t conn[HDA_MAX_CONNECTIONS];
568 for (i = 0; i < spec->num_adc_nids; i++) {
569 snd_hda_codec_write(codec, spec->adc_nids[i], 0,
570 AC_VERB_SET_AMP_GAIN_MUTE,
575 for (i = 0; i < cfg->num_inputs; i++) {
576 hda_nid_t nid = cfg->inputs[i].pin;
577 if (spec->smart51_enabled && is_smart51_pins(codec, nid))
579 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
583 snd_hda_codec_write(codec, nid, 0,
584 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
588 for (i = 0; i < spec->num_adc_nids; i++) {
589 const struct hda_input_mux *imux = spec->input_mux;
590 if (!imux || !spec->mux_nids[i])
592 snd_hda_codec_write(codec, spec->mux_nids[i], 0,
593 AC_VERB_SET_CONNECT_SEL,
594 imux->items[spec->cur_mux[i]].index);
598 if (!spec->aa_mix_nid)
600 num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
602 for (i = 0; i < num_conns; i++) {
603 unsigned int caps = get_wcaps(codec, conn[i]);
604 if (get_wcaps_type(caps) == AC_WID_PIN)
605 snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
606 AC_VERB_SET_AMP_GAIN_MUTE,
611 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
612 unsigned int *affected_parm)
615 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
616 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
617 >> AC_DEFCFG_MISC_SHIFT
618 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
619 struct via_spec *spec = codec->spec;
620 unsigned present = 0;
622 no_presence |= spec->no_pin_power_ctl;
624 present = snd_hda_jack_detect(codec, nid);
625 if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
626 || ((no_presence || present)
627 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
628 *affected_parm = AC_PWRST_D0; /* if it's connected */
633 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
636 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
637 struct snd_ctl_elem_info *uinfo)
639 static const char * const texts[] = {
640 "Disabled", "Enabled"
643 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
645 uinfo->value.enumerated.items = 2;
646 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
647 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
648 strcpy(uinfo->value.enumerated.name,
649 texts[uinfo->value.enumerated.item]);
653 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_value *ucontrol)
656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657 struct via_spec *spec = codec->spec;
658 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
662 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
663 struct snd_ctl_elem_value *ucontrol)
665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
666 struct via_spec *spec = codec->spec;
667 unsigned int val = !ucontrol->value.enumerated.item[0];
669 if (val == spec->no_pin_power_ctl)
671 spec->no_pin_power_ctl = val;
672 set_widgets_power_state(codec);
676 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
677 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
678 .name = "Dynamic Power-Control",
679 .info = via_pin_power_ctl_info,
680 .get = via_pin_power_ctl_get,
681 .put = via_pin_power_ctl_put,
688 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
689 struct snd_ctl_elem_info *uinfo)
691 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
692 struct via_spec *spec = codec->spec;
693 return snd_hda_input_mux_info(spec->input_mux, uinfo);
696 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
697 struct snd_ctl_elem_value *ucontrol)
699 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700 struct via_spec *spec = codec->spec;
701 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
703 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
707 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
708 struct snd_ctl_elem_value *ucontrol)
710 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
711 struct via_spec *spec = codec->spec;
712 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
715 if (!spec->mux_nids[adc_idx])
717 /* switch to D0 beofre change index */
718 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
719 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
720 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
721 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
723 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
724 spec->mux_nids[adc_idx],
725 &spec->cur_mux[adc_idx]);
726 /* update jack power state */
727 set_widgets_power_state(codec);
732 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
733 struct snd_ctl_elem_info *uinfo)
735 static const char * const texts[] = { "OFF", "ON" };
737 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
739 uinfo->value.enumerated.items = 2;
740 if (uinfo->value.enumerated.item >= 2)
741 uinfo->value.enumerated.item = 1;
742 strcpy(uinfo->value.enumerated.name,
743 texts[uinfo->value.enumerated.item]);
747 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
748 struct snd_ctl_elem_value *ucontrol)
750 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
751 struct via_spec *spec = codec->spec;
753 ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
757 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
758 struct snd_ctl_elem_value *ucontrol)
760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
761 struct via_spec *spec = codec->spec;
763 spec->hp_independent_mode = !!ucontrol->value.enumerated.item[0];
764 if (spec->hp_independent_mode) {
765 activate_output_path(codec, &spec->hp_dep_path, false, false);
766 activate_output_path(codec, &spec->hp_path, true, false);
768 activate_output_path(codec, &spec->hp_path, false, false);
769 activate_output_path(codec, &spec->hp_dep_path, true, false);
772 /* update jack power state */
773 set_widgets_power_state(codec);
777 static const struct snd_kcontrol_new via_hp_mixer = {
778 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
779 .name = "Independent HP",
780 .info = via_independent_hp_info,
781 .get = via_independent_hp_get,
782 .put = via_independent_hp_put,
785 static int via_hp_build(struct hda_codec *codec)
787 struct via_spec *spec = codec->spec;
788 struct snd_kcontrol_new *knew;
791 nid = spec->autocfg.hp_pins[0];
792 knew = via_clone_control(spec, &via_hp_mixer);
796 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
801 static void notify_aa_path_ctls(struct hda_codec *codec)
803 struct via_spec *spec = codec->spec;
806 for (i = 0; i < spec->smart51_nums; i++) {
807 struct snd_kcontrol *ctl;
808 struct snd_ctl_elem_id id;
809 memset(&id, 0, sizeof(id));
810 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
811 sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
812 ctl = snd_hda_find_mixer_ctl(codec, id.name);
814 snd_ctl_notify(codec->bus->card,
815 SNDRV_CTL_EVENT_MASK_VALUE,
820 static void mute_aa_path(struct hda_codec *codec, int mute)
822 struct via_spec *spec = codec->spec;
823 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
826 /* check AA path's mute status */
827 for (i = 0; i < spec->smart51_nums; i++) {
828 if (spec->smart51_idxs[i] < 0)
830 snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
831 HDA_INPUT, spec->smart51_idxs[i],
836 static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
838 struct via_spec *spec = codec->spec;
841 for (i = 0; i < spec->smart51_nums; i++)
842 if (spec->smart51_pins[i] == pin)
847 static int via_smart51_get(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;
853 *ucontrol->value.integer.value = spec->smart51_enabled;
857 static int via_smart51_put(struct snd_kcontrol *kcontrol,
858 struct snd_ctl_elem_value *ucontrol)
860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
861 struct via_spec *spec = codec->spec;
862 int out_in = *ucontrol->value.integer.value
863 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
866 for (i = 0; i < spec->smart51_nums; i++) {
867 hda_nid_t nid = spec->smart51_pins[i];
870 parm = snd_hda_codec_read(codec, nid, 0,
871 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
872 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
874 snd_hda_codec_write(codec, nid, 0,
875 AC_VERB_SET_PIN_WIDGET_CONTROL,
877 if (out_in == AC_PINCTL_OUT_EN) {
878 mute_aa_path(codec, 1);
879 notify_aa_path_ctls(codec);
882 spec->smart51_enabled = *ucontrol->value.integer.value;
883 set_widgets_power_state(codec);
887 static const struct snd_kcontrol_new via_smart51_mixer = {
888 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
891 .info = snd_ctl_boolean_mono_info,
892 .get = via_smart51_get,
893 .put = via_smart51_put,
896 static int via_smart51_build(struct hda_codec *codec)
898 struct via_spec *spec = codec->spec;
900 if (!spec->smart51_nums)
902 if (!via_clone_control(spec, &via_smart51_mixer))
907 /* check AA path's mute status */
908 static bool is_aa_path_mute(struct hda_codec *codec)
910 struct via_spec *spec = codec->spec;
911 const struct hda_amp_list *p;
914 for (i = 0; i < spec->num_loopbacks; i++) {
915 p = &spec->loopback_list[i];
916 for (ch = 0; ch < 2; ch++) {
917 v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
919 if (!(v & HDA_AMP_MUTE) && v > 0)
926 /* enter/exit analog low-current mode */
927 static void analog_low_current_mode(struct hda_codec *codec)
929 struct via_spec *spec = codec->spec;
931 unsigned int verb, parm;
933 enable = is_aa_path_mute(codec) && (spec->num_active_streams > 0);
935 /* decide low current mode's verb & parameter */
936 switch (spec->codec_type) {
940 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
946 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
950 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
956 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
959 return; /* other codecs are not supported */
962 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
966 * generic initialization of ADC, input mixers and output mixers
968 static const struct hda_verb vt1708_init_verbs[] = {
969 /* power down jack detect function */
974 static void set_stream_active(struct hda_codec *codec, bool active)
976 struct via_spec *spec = codec->spec;
979 spec->num_active_streams++;
981 spec->num_active_streams--;
982 analog_low_current_mode(codec);
985 static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
986 struct hda_codec *codec,
987 struct snd_pcm_substream *substream)
989 struct via_spec *spec = codec->spec;
992 if (!spec->hp_independent_mode)
993 spec->multiout.hp_nid = spec->hp_dac_nid;
994 set_stream_active(codec, true);
995 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
998 spec->multiout.hp_nid = 0;
999 set_stream_active(codec, false);
1005 static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
1006 struct hda_codec *codec,
1007 struct snd_pcm_substream *substream)
1009 struct via_spec *spec = codec->spec;
1011 spec->multiout.hp_nid = 0;
1012 set_stream_active(codec, false);
1016 static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
1017 struct hda_codec *codec,
1018 struct snd_pcm_substream *substream)
1020 struct via_spec *spec = codec->spec;
1022 if (snd_BUG_ON(!spec->hp_dac_nid))
1024 if (!spec->hp_independent_mode || spec->multiout.hp_nid)
1026 set_stream_active(codec, true);
1030 static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
1031 struct hda_codec *codec,
1032 struct snd_pcm_substream *substream)
1034 set_stream_active(codec, false);
1038 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1039 struct hda_codec *codec,
1040 unsigned int stream_tag,
1041 unsigned int format,
1042 struct snd_pcm_substream *substream)
1044 struct via_spec *spec = codec->spec;
1046 snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
1048 vt1708_start_hp_work(spec);
1052 static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
1053 struct hda_codec *codec,
1054 unsigned int stream_tag,
1055 unsigned int format,
1056 struct snd_pcm_substream *substream)
1058 struct via_spec *spec = codec->spec;
1060 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
1061 stream_tag, 0, format);
1062 vt1708_start_hp_work(spec);
1066 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1067 struct hda_codec *codec,
1068 struct snd_pcm_substream *substream)
1070 struct via_spec *spec = codec->spec;
1072 snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1073 vt1708_stop_hp_work(spec);
1077 static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
1078 struct hda_codec *codec,
1079 struct snd_pcm_substream *substream)
1081 struct via_spec *spec = codec->spec;
1083 snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
1084 vt1708_stop_hp_work(spec);
1091 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1092 struct hda_codec *codec,
1093 struct snd_pcm_substream *substream)
1095 struct via_spec *spec = codec->spec;
1096 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1099 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1100 struct hda_codec *codec,
1101 struct snd_pcm_substream *substream)
1103 struct via_spec *spec = codec->spec;
1104 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1107 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1108 struct hda_codec *codec,
1109 unsigned int stream_tag,
1110 unsigned int format,
1111 struct snd_pcm_substream *substream)
1113 struct via_spec *spec = codec->spec;
1114 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1115 stream_tag, format, substream);
1118 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1119 struct hda_codec *codec,
1120 struct snd_pcm_substream *substream)
1122 struct via_spec *spec = codec->spec;
1123 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1130 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1131 struct hda_codec *codec,
1132 unsigned int stream_tag,
1133 unsigned int format,
1134 struct snd_pcm_substream *substream)
1136 struct via_spec *spec = codec->spec;
1138 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1139 stream_tag, 0, format);
1143 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1144 struct hda_codec *codec,
1145 struct snd_pcm_substream *substream)
1147 struct via_spec *spec = codec->spec;
1148 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1152 static const struct hda_pcm_stream via_pcm_analog_playback = {
1156 /* NID is set in via_build_pcms */
1158 .open = via_playback_multi_pcm_open,
1159 .close = via_playback_multi_pcm_close,
1160 .prepare = via_playback_multi_pcm_prepare,
1161 .cleanup = via_playback_multi_pcm_cleanup
1165 static const struct hda_pcm_stream via_pcm_hp_playback = {
1169 /* NID is set in via_build_pcms */
1171 .open = via_playback_hp_pcm_open,
1172 .close = via_playback_hp_pcm_close,
1173 .prepare = via_playback_hp_pcm_prepare,
1174 .cleanup = via_playback_hp_pcm_cleanup
1178 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1182 /* NID is set in via_build_pcms */
1183 /* We got noisy outputs on the right channel on VT1708 when
1184 * 24bit samples are used. Until any workaround is found,
1185 * disable the 24bit format, so far.
1187 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1189 .open = via_playback_multi_pcm_open,
1190 .close = via_playback_multi_pcm_close,
1191 .prepare = via_playback_multi_pcm_prepare,
1192 .cleanup = via_playback_multi_pcm_cleanup
1196 static const struct hda_pcm_stream via_pcm_analog_capture = {
1197 .substreams = 1, /* will be changed in via_build_pcms() */
1200 /* NID is set in via_build_pcms */
1202 .prepare = via_capture_pcm_prepare,
1203 .cleanup = via_capture_pcm_cleanup
1207 static const struct hda_pcm_stream via_pcm_digital_playback = {
1211 /* NID is set in via_build_pcms */
1213 .open = via_dig_playback_pcm_open,
1214 .close = via_dig_playback_pcm_close,
1215 .prepare = via_dig_playback_pcm_prepare,
1216 .cleanup = via_dig_playback_pcm_cleanup
1220 static const struct hda_pcm_stream via_pcm_digital_capture = {
1227 * slave controls for virtual master
1229 static const char * const via_slave_vols[] = {
1230 "Front Playback Volume",
1231 "Surround Playback Volume",
1232 "Center Playback Volume",
1233 "LFE Playback Volume",
1234 "Side Playback Volume",
1235 "Headphone Playback Volume",
1236 "Speaker Playback Volume",
1240 static const char * const via_slave_sws[] = {
1241 "Front Playback Switch",
1242 "Surround Playback Switch",
1243 "Center Playback Switch",
1244 "LFE Playback Switch",
1245 "Side Playback Switch",
1246 "Headphone Playback Switch",
1247 "Speaker Playback Switch",
1251 static int via_build_controls(struct hda_codec *codec)
1253 struct via_spec *spec = codec->spec;
1254 struct snd_kcontrol *kctl;
1257 if (spec->set_widgets_power_state)
1258 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1261 for (i = 0; i < spec->num_mixers; i++) {
1262 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1267 if (spec->multiout.dig_out_nid) {
1268 err = snd_hda_create_spdif_out_ctls(codec,
1269 spec->multiout.dig_out_nid,
1270 spec->multiout.dig_out_nid);
1273 err = snd_hda_create_spdif_share_sw(codec,
1277 spec->multiout.share_spdif = 1;
1279 if (spec->dig_in_nid) {
1280 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1285 /* if we have no master control, let's create it */
1286 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1287 unsigned int vmaster_tlv[4];
1288 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1289 HDA_OUTPUT, vmaster_tlv);
1290 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1291 vmaster_tlv, via_slave_vols);
1295 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1296 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1297 NULL, via_slave_sws);
1302 /* assign Capture Source enums to NID */
1303 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1304 for (i = 0; kctl && i < kctl->count; i++) {
1305 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1310 /* init power states */
1311 set_widgets_power_state(codec);
1312 analog_low_current_mode(codec);
1314 via_free_kctls(codec); /* no longer needed */
1318 static int via_build_pcms(struct hda_codec *codec)
1320 struct via_spec *spec = codec->spec;
1321 struct hda_pcm *info = spec->pcm_rec;
1323 codec->num_pcms = 1;
1324 codec->pcm_info = info;
1326 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1327 "%s Analog", codec->chip_name);
1328 info->name = spec->stream_name_analog;
1330 if (!spec->stream_analog_playback)
1331 spec->stream_analog_playback = &via_pcm_analog_playback;
1332 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1333 *spec->stream_analog_playback;
1334 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1335 spec->multiout.dac_nids[0];
1336 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1337 spec->multiout.max_channels;
1339 if (!spec->stream_analog_capture)
1340 spec->stream_analog_capture = &via_pcm_analog_capture;
1341 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1342 *spec->stream_analog_capture;
1343 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1344 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1347 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1350 snprintf(spec->stream_name_digital,
1351 sizeof(spec->stream_name_digital),
1352 "%s Digital", codec->chip_name);
1353 info->name = spec->stream_name_digital;
1354 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1355 if (spec->multiout.dig_out_nid) {
1356 if (!spec->stream_digital_playback)
1357 spec->stream_digital_playback =
1358 &via_pcm_digital_playback;
1359 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1360 *spec->stream_digital_playback;
1361 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1362 spec->multiout.dig_out_nid;
1364 if (spec->dig_in_nid) {
1365 if (!spec->stream_digital_capture)
1366 spec->stream_digital_capture =
1367 &via_pcm_digital_capture;
1368 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1369 *spec->stream_digital_capture;
1370 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1375 if (spec->hp_dac_nid) {
1378 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1379 "%s HP", codec->chip_name);
1380 info->name = spec->stream_name_hp;
1381 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1382 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1388 static void via_free(struct hda_codec *codec)
1390 struct via_spec *spec = codec->spec;
1395 via_free_kctls(codec);
1396 vt1708_stop_hp_work(spec);
1400 /* mute/unmute outputs */
1401 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1402 hda_nid_t *pins, bool mute)
1405 for (i = 0; i < num_pins; i++)
1406 snd_hda_codec_write(codec, pins[i], 0,
1407 AC_VERB_SET_PIN_WIDGET_CONTROL,
1408 mute ? 0 : PIN_OUT);
1411 /* mute internal speaker if line-out is plugged */
1412 static void via_line_automute(struct hda_codec *codec, int present)
1414 struct via_spec *spec = codec->spec;
1416 if (!spec->autocfg.speaker_outs)
1419 present = snd_hda_jack_detect(codec,
1420 spec->autocfg.line_out_pins[0]);
1421 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1422 spec->autocfg.speaker_pins,
1426 /* mute internal speaker if HP is plugged */
1427 static void via_hp_automute(struct hda_codec *codec)
1430 struct via_spec *spec = codec->spec;
1432 if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) {
1434 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1435 if (spec->smart51_enabled)
1436 nums = spec->autocfg.line_outs + spec->smart51_nums;
1438 nums = spec->autocfg.line_outs;
1439 toggle_output_mutes(codec, nums,
1440 spec->autocfg.line_out_pins,
1443 via_line_automute(codec, present);
1446 static void via_gpio_control(struct hda_codec *codec)
1448 unsigned int gpio_data;
1449 unsigned int vol_counter;
1451 unsigned int master_vol;
1453 struct via_spec *spec = codec->spec;
1455 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1456 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1458 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1459 0xF84, 0) & 0x3F0000) >> 16;
1461 vol = vol_counter & 0x1F;
1462 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1463 AC_VERB_GET_AMP_GAIN_MUTE,
1466 if (gpio_data == 0x02) {
1467 /* unmute line out */
1468 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1469 AC_VERB_SET_PIN_WIDGET_CONTROL,
1471 if (vol_counter & 0x20) {
1472 /* decrease volume */
1473 if (vol > master_vol)
1475 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1479 /* increase volume */
1480 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1482 ((master_vol+vol) > 0x2A) ? 0x2A :
1485 } else if (!(gpio_data & 0x02)) {
1487 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1488 AC_VERB_SET_PIN_WIDGET_CONTROL,
1493 /* unsolicited event for jack sensing */
1494 static void via_unsol_event(struct hda_codec *codec,
1499 if (res & VIA_JACK_EVENT)
1500 set_widgets_power_state(codec);
1502 res &= ~VIA_JACK_EVENT;
1504 if (res == VIA_HP_EVENT)
1505 via_hp_automute(codec);
1506 else if (res == VIA_GPIO_EVENT)
1507 via_gpio_control(codec);
1508 else if (res == VIA_LINE_EVENT)
1509 via_line_automute(codec, false);
1512 #ifdef SND_HDA_NEEDS_RESUME
1513 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1515 struct via_spec *spec = codec->spec;
1516 vt1708_stop_hp_work(spec);
1521 #ifdef CONFIG_SND_HDA_POWER_SAVE
1522 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1524 struct via_spec *spec = codec->spec;
1525 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1532 static int via_init(struct hda_codec *codec);
1534 static const struct hda_codec_ops via_patch_ops = {
1535 .build_controls = via_build_controls,
1536 .build_pcms = via_build_pcms,
1539 .unsol_event = via_unsol_event,
1540 #ifdef SND_HDA_NEEDS_RESUME
1541 .suspend = via_suspend,
1543 #ifdef CONFIG_SND_HDA_POWER_SAVE
1544 .check_power_status = via_check_power_status,
1548 static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
1550 struct via_spec *spec = codec->spec;
1553 for (i = 0; i < spec->multiout.num_dacs; i++) {
1554 if (spec->multiout.dac_nids[i] == dac)
1557 if (spec->hp_dac_nid == dac)
1562 static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1563 hda_nid_t target_dac, struct nid_path *path,
1564 int depth, int wid_type)
1569 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
1570 for (i = 0; i < nums; i++) {
1571 if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
1573 if (conn[i] == target_dac || is_empty_dac(codec, conn[i]))
1576 if (depth >= MAX_NID_PATH_DEPTH)
1578 for (i = 0; i < nums; i++) {
1580 type = get_wcaps_type(get_wcaps(codec, conn[i]));
1581 if (type == AC_WID_AUD_OUT ||
1582 (wid_type != -1 && type != wid_type))
1584 if (__parse_output_path(codec, conn[i], target_dac,
1585 path, depth + 1, AC_WID_AUD_SEL))
1591 path->path[path->depth] = conn[i];
1592 path->idx[path->depth] = i;
1593 if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
1594 path->multi[path->depth] = 1;
1599 static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
1600 hda_nid_t target_dac, struct nid_path *path)
1602 if (__parse_output_path(codec, nid, target_dac, path, 1, -1)) {
1603 path->path[path->depth] = nid;
1610 static int via_auto_fill_dac_nids(struct hda_codec *codec)
1612 struct via_spec *spec = codec->spec;
1613 const struct auto_pin_cfg *cfg = &spec->autocfg;
1617 spec->multiout.dac_nids = spec->private_dac_nids;
1618 spec->multiout.num_dacs = cfg->line_outs;
1619 for (i = 0; i < cfg->line_outs; i++) {
1620 nid = cfg->line_out_pins[i];
1623 if (parse_output_path(codec, nid, 0, &spec->out_path[i]))
1624 spec->private_dac_nids[i] = spec->out_path[i].path[0];
1629 static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
1630 int chs, bool check_dac, struct nid_path *path)
1632 struct via_spec *spec = codec->spec;
1634 hda_nid_t dac, pin, sel, nid;
1637 dac = check_dac ? path->path[0] : 0;
1638 pin = path->path[path->depth - 1];
1639 sel = path->depth > 1 ? path->path[1] : 0;
1641 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1643 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1645 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
1650 sprintf(name, "%s Playback Volume", pfx);
1651 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1652 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1655 path->vol_ctl = nid;
1658 if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
1660 else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
1662 else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
1667 sprintf(name, "%s Playback Switch", pfx);
1668 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1669 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1672 path->mute_ctl = nid;
1677 static void mangle_smart51(struct hda_codec *codec)
1679 struct via_spec *spec = codec->spec;
1680 struct auto_pin_cfg *cfg = &spec->autocfg;
1681 struct auto_pin_cfg_item *ins = cfg->inputs;
1682 int i, j, nums, attr;
1683 int pins[AUTO_CFG_MAX_INS];
1685 for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
1687 for (i = 0; i < cfg->num_inputs; i++) {
1689 if (ins[i].type > AUTO_PIN_LINE_IN)
1691 def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
1692 if (snd_hda_get_input_pin_attr(def) != attr)
1694 for (j = 0; j < nums; j++)
1695 if (ins[pins[j]].type < ins[i].type) {
1696 memmove(pins + j + 1, pins + j,
1697 (nums - j - 1) * sizeof(int));
1703 if (cfg->line_outs + nums < 3)
1705 for (i = 0; i < nums; i++) {
1706 hda_nid_t pin = ins[pins[i]].pin;
1707 spec->smart51_pins[spec->smart51_nums++] = pin;
1708 cfg->line_out_pins[cfg->line_outs++] = pin;
1709 if (cfg->line_outs == 3)
1716 /* add playback controls from the parsed DAC table */
1717 static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
1719 struct via_spec *spec = codec->spec;
1720 struct auto_pin_cfg *cfg = &spec->autocfg;
1721 static const char * const chname[4] = {
1722 "Front", "Surround", "C/LFE", "Side"
1728 old_line_outs = cfg->line_outs;
1729 if (cfg->line_outs == 1)
1730 mangle_smart51(codec);
1732 err = via_auto_fill_dac_nids(codec);
1736 for (i = 0; i < cfg->line_outs; i++) {
1738 pin = cfg->line_out_pins[i];
1739 dac = spec->multiout.dac_nids[i];
1742 if (i == HDA_CLFE) {
1743 err = create_ch_ctls(codec, "Center", 1, true,
1744 &spec->out_path[i]);
1747 err = create_ch_ctls(codec, "LFE", 2, true,
1748 &spec->out_path[i]);
1752 const char *pfx = chname[i];
1753 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
1754 cfg->line_outs == 1)
1756 err = create_ch_ctls(codec, pfx, 3, true,
1757 &spec->out_path[i]);
1763 idx = get_connection_index(codec, spec->aa_mix_nid,
1764 spec->multiout.dac_nids[0]);
1766 /* add control to mixer */
1767 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1768 "PCM Playback Volume",
1769 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1773 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1774 "PCM Playback Switch",
1775 HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
1781 cfg->line_outs = old_line_outs;
1786 static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
1788 struct via_spec *spec = codec->spec;
1789 struct nid_path *path;
1795 if (parse_output_path(codec, pin, 0, &spec->hp_path))
1796 spec->hp_dac_nid = spec->hp_path.path[0];
1798 if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1799 &spec->hp_dep_path) &&
1803 if (spec->hp_dac_nid)
1804 path = &spec->hp_path;
1806 path = &spec->hp_dep_path;
1807 err = create_ch_ctls(codec, "Headphone", 3, false, path);
1810 if (spec->hp_dac_nid) {
1811 spec->hp_dep_path.vol_ctl = spec->hp_path.vol_ctl;
1812 spec->hp_dep_path.mute_ctl = spec->hp_path.mute_ctl;
1818 static int via_auto_create_speaker_ctls(struct hda_codec *codec)
1820 struct via_spec *spec = codec->spec;
1823 pin = spec->autocfg.speaker_pins[0];
1824 if (!spec->autocfg.speaker_outs || !pin)
1827 if (parse_output_path(codec, pin, 0, &spec->speaker_path)) {
1828 dac = spec->speaker_path.path[0];
1829 spec->multiout.extra_out_nid[0] = dac;
1830 return create_ch_ctls(codec, "Speaker", 3, true,
1831 &spec->speaker_path);
1833 if (parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
1834 &spec->speaker_path))
1835 return create_ch_ctls(codec, "Speaker", 3, false,
1836 &spec->speaker_path);
1842 static int via_fill_adcs(struct hda_codec *codec)
1844 struct via_spec *spec = codec->spec;
1845 hda_nid_t nid = codec->start_nid;
1848 for (i = 0; i < codec->num_nodes; i++, nid++) {
1849 unsigned int wcaps = get_wcaps(codec, nid);
1850 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1852 if (wcaps & AC_WCAP_DIGITAL)
1854 if (!(wcaps & AC_WCAP_CONN_LIST))
1856 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
1858 spec->adc_nids[spec->num_adc_nids++] = nid;
1863 static int get_mux_nids(struct hda_codec *codec);
1865 static const struct snd_kcontrol_new via_input_src_ctl = {
1866 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1867 /* The multiple "Capture Source" controls confuse alsamixer
1868 * So call somewhat different..
1870 /* .name = "Capture Source", */
1871 .name = "Input Source",
1872 .info = via_mux_enum_info,
1873 .get = via_mux_enum_get,
1874 .put = via_mux_enum_put,
1877 static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
1879 struct hda_amp_list *list;
1881 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
1883 list = spec->loopback_list + spec->num_loopbacks;
1885 list->dir = HDA_INPUT;
1887 spec->num_loopbacks++;
1888 spec->loopback.amplist = spec->loopback_list;
1891 /* create playback/capture controls for input pins */
1892 static int via_auto_create_analog_input_ctls(struct hda_codec *codec,
1893 const struct auto_pin_cfg *cfg)
1895 struct via_spec *spec = codec->spec;
1896 struct hda_input_mux *imux = &spec->private_imux[0];
1897 int i, j, err, idx, idx2, type, type_idx = 0;
1898 const char *prev_label = NULL;
1900 hda_nid_t pin_idxs[8];
1903 err = via_fill_adcs(codec);
1906 err = get_mux_nids(codec);
1909 cap_nid = spec->mux_nids[0];
1911 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
1912 ARRAY_SIZE(pin_idxs));
1916 /* for internal loopback recording select */
1917 for (idx = 0; idx < num_idxs; idx++) {
1918 if (pin_idxs[idx] == spec->aa_mix_nid) {
1919 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
1924 for (i = 0; i < cfg->num_inputs; i++) {
1926 type = cfg->inputs[i].type;
1927 for (idx = 0; idx < num_idxs; idx++)
1928 if (pin_idxs[idx] == cfg->inputs[i].pin)
1930 if (idx >= num_idxs)
1932 label = hda_get_autocfg_input_label(codec, cfg, i);
1933 if (prev_label && !strcmp(label, prev_label))
1938 idx2 = get_connection_index(codec, spec->aa_mix_nid,
1941 err = via_new_analog_input(spec, label, type_idx,
1942 idx2, spec->aa_mix_nid);
1945 add_loopback_list(spec, spec->aa_mix_nid, idx2);
1947 snd_hda_add_imux_item(imux, label, idx, NULL);
1949 /* remember the label for smart51 control */
1950 for (j = 0; j < spec->smart51_nums; j++) {
1951 if (spec->smart51_pins[j] == cfg->inputs[i].pin) {
1952 spec->smart51_idxs[j] = idx;
1953 spec->smart51_labels[j] = label;
1959 /* create capture mixer elements */
1960 for (i = 0; i < spec->num_adc_nids; i++) {
1961 hda_nid_t adc = spec->adc_nids[i];
1962 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
1963 "Capture Volume", i,
1964 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
1968 err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1969 "Capture Switch", i,
1970 HDA_COMPOSE_AMP_VAL(adc, 3, 0,
1976 /* input-source control */
1977 for (i = 0; i < spec->num_adc_nids; i++)
1978 if (!spec->mux_nids[i])
1981 struct snd_kcontrol_new *knew;
1982 knew = via_clone_control(spec, &via_input_src_ctl);
1989 for (i = 0; i < cfg->num_inputs; i++) {
1990 hda_nid_t pin = cfg->inputs[i].pin;
1995 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1997 caps = query_amp_caps(codec, pin, HDA_INPUT);
1998 if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
2000 label = hda_get_autocfg_input_label(codec, cfg, i);
2001 snprintf(name, sizeof(name), "%s Boost Volume", label);
2002 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2003 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
2011 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2013 unsigned int def_conf;
2014 unsigned char seqassoc;
2016 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2017 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2018 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2019 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2020 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2021 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2022 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2028 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2029 struct snd_ctl_elem_value *ucontrol)
2031 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2032 struct via_spec *spec = codec->spec;
2034 if (spec->codec_type != VT1708)
2036 spec->vt1708_jack_detect =
2037 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2038 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2042 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2043 struct snd_ctl_elem_value *ucontrol)
2045 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2046 struct via_spec *spec = codec->spec;
2049 if (spec->codec_type != VT1708)
2051 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2052 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2053 == !spec->vt1708_jack_detect;
2054 if (spec->vt1708_jack_detect) {
2055 mute_aa_path(codec, 1);
2056 notify_aa_path_ctls(codec);
2061 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2062 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2063 .name = "Jack Detect",
2065 .info = snd_ctl_boolean_mono_info,
2066 .get = vt1708_jack_detect_get,
2067 .put = vt1708_jack_detect_put,
2070 static void fill_dig_outs(struct hda_codec *codec);
2071 static void fill_dig_in(struct hda_codec *codec);
2073 static int via_parse_auto_config(struct hda_codec *codec)
2075 struct via_spec *spec = codec->spec;
2078 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2081 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2084 err = via_auto_create_multi_out_ctls(codec);
2087 err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
2090 err = via_auto_create_speaker_ctls(codec);
2093 err = via_auto_create_analog_input_ctls(codec, &spec->autocfg);
2097 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2099 fill_dig_outs(codec);
2102 if (spec->kctls.list)
2103 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2105 spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
2107 spec->input_mux = &spec->private_imux[0];
2109 if (spec->hp_dac_nid && spec->hp_dep_path.depth) {
2110 err = via_hp_build(codec);
2115 err = via_smart51_build(codec);
2119 /* assign slave outs */
2120 if (spec->slave_dig_outs[0])
2121 codec->slave_dig_outs = spec->slave_dig_outs;
2126 static void via_auto_init_dig_outs(struct hda_codec *codec)
2128 struct via_spec *spec = codec->spec;
2129 if (spec->multiout.dig_out_nid)
2130 init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
2131 if (spec->slave_dig_outs[0])
2132 init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
2135 static void via_auto_init_dig_in(struct hda_codec *codec)
2137 struct via_spec *spec = codec->spec;
2138 if (!spec->dig_in_nid)
2140 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2141 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2144 /* initialize the unsolicited events */
2145 static void via_auto_init_unsol_event(struct hda_codec *codec)
2147 struct via_spec *spec = codec->spec;
2148 struct auto_pin_cfg *cfg = &spec->autocfg;
2152 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2153 snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
2154 AC_VERB_SET_UNSOLICITED_ENABLE,
2155 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2157 if (cfg->speaker_pins[0])
2158 ev = VIA_LINE_EVENT;
2161 for (i = 0; i < cfg->line_outs; i++) {
2162 if (cfg->line_out_pins[i] &&
2163 is_jack_detectable(codec, cfg->line_out_pins[i]))
2164 snd_hda_codec_write(codec, cfg->line_out_pins[0], 0,
2165 AC_VERB_SET_UNSOLICITED_ENABLE,
2166 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2169 for (i = 0; i < cfg->num_inputs; i++) {
2170 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2171 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
2172 AC_VERB_SET_UNSOLICITED_ENABLE,
2173 AC_USRSP_EN | VIA_JACK_EVENT);
2177 static int via_init(struct hda_codec *codec)
2179 struct via_spec *spec = codec->spec;
2182 for (i = 0; i < spec->num_iverbs; i++)
2183 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2185 via_auto_init_multi_out(codec);
2186 via_auto_init_hp_out(codec);
2187 via_auto_init_speaker_out(codec);
2188 via_auto_init_analog_input(codec);
2189 via_auto_init_dig_outs(codec);
2190 via_auto_init_dig_in(codec);
2192 via_auto_init_unsol_event(codec);
2194 via_hp_automute(codec);
2195 via_line_automute(codec, false);
2200 static void vt1708_update_hp_jack_state(struct work_struct *work)
2202 struct via_spec *spec = container_of(work, struct via_spec,
2203 vt1708_hp_work.work);
2204 if (spec->codec_type != VT1708)
2206 /* if jack state toggled */
2207 if (spec->vt1708_hp_present
2208 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2209 spec->vt1708_hp_present ^= 1;
2210 via_hp_automute(spec->codec);
2212 vt1708_start_hp_work(spec);
2215 static int get_mux_nids(struct hda_codec *codec)
2217 struct via_spec *spec = codec->spec;
2218 hda_nid_t nid, conn[8];
2222 for (i = 0; i < spec->num_adc_nids; i++) {
2223 nid = spec->adc_nids[i];
2225 type = get_wcaps_type(get_wcaps(codec, nid));
2226 if (type == AC_WID_PIN)
2228 n = snd_hda_get_connections(codec, nid, conn,
2233 spec->mux_nids[i] = nid;
2242 static int patch_vt1708(struct hda_codec *codec)
2244 struct via_spec *spec;
2247 /* create a codec specific record */
2248 spec = via_new_spec(codec);
2252 spec->aa_mix_nid = 0x17;
2254 /* Add HP and CD pin config connect bit re-config action */
2255 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2256 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2258 /* automatic parse from the BIOS config */
2259 err = via_parse_auto_config(codec);
2265 /* add jack detect on/off control */
2266 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2269 /* disable 32bit format on VT1708 */
2270 if (codec->vendor_id == 0x11061708)
2271 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2273 codec->patch_ops = via_patch_ops;
2275 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2279 static int patch_vt1709(struct hda_codec *codec)
2281 struct via_spec *spec;
2284 /* create a codec specific record */
2285 spec = via_new_spec(codec);
2289 spec->aa_mix_nid = 0x18;
2291 err = via_parse_auto_config(codec);
2297 codec->patch_ops = via_patch_ops;
2302 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
2304 struct via_spec *spec = codec->spec;
2308 if ((spec->codec_type != VT1708B_4CH) &&
2309 (codec->vendor_id != 0x11064397))
2312 /* SW0 (17h) = stereo mixer */
2314 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
2315 == ((spec->codec_type == VT1708S) ? 5 : 0));
2317 /* PW 1/2/5 (1ah/1bh/1eh) */
2319 set_pin_power_state(codec, 0x1a, &parm);
2320 set_pin_power_state(codec, 0x1b, &parm);
2321 set_pin_power_state(codec, 0x1e, &parm);
2324 /* SW0 (17h), AIW 0/1 (13h/14h) */
2325 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2326 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2327 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2330 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2332 set_pin_power_state(codec, 0x19, &parm);
2333 if (spec->smart51_enabled)
2334 set_pin_power_state(codec, 0x1b, &parm);
2335 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2336 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2338 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
2341 set_pin_power_state(codec, 0x22, &parm);
2342 if (spec->smart51_enabled)
2343 set_pin_power_state(codec, 0x1a, &parm);
2344 snd_hda_codec_write(codec, 0x26, 0,
2345 AC_VERB_SET_POWER_STATE, parm);
2346 snd_hda_codec_write(codec, 0x24, 0,
2347 AC_VERB_SET_POWER_STATE, parm);
2348 } else if (codec->vendor_id == 0x11064397) {
2349 /* PW7(23h), SW2(27h), AOW2(25h) */
2351 set_pin_power_state(codec, 0x23, &parm);
2352 if (spec->smart51_enabled)
2353 set_pin_power_state(codec, 0x1a, &parm);
2354 snd_hda_codec_write(codec, 0x27, 0,
2355 AC_VERB_SET_POWER_STATE, parm);
2356 snd_hda_codec_write(codec, 0x25, 0,
2357 AC_VERB_SET_POWER_STATE, parm);
2360 /* PW 3/4/7 (1ch/1dh/23h) */
2362 /* force to D0 for internal Speaker */
2363 set_pin_power_state(codec, 0x1c, &parm);
2364 set_pin_power_state(codec, 0x1d, &parm);
2366 set_pin_power_state(codec, 0x23, &parm);
2368 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
2369 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2370 imux_is_smixer ? AC_PWRST_D0 : parm);
2371 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2373 snd_hda_codec_write(codec, 0x25, 0,
2374 AC_VERB_SET_POWER_STATE, parm);
2375 snd_hda_codec_write(codec, 0x27, 0,
2376 AC_VERB_SET_POWER_STATE, parm);
2377 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
2378 snd_hda_codec_write(codec, 0x25, 0,
2379 AC_VERB_SET_POWER_STATE, parm);
2382 static int patch_vt1708S(struct hda_codec *codec);
2383 static int patch_vt1708B(struct hda_codec *codec)
2385 struct via_spec *spec;
2388 if (get_codec_type(codec) == VT1708BCE)
2389 return patch_vt1708S(codec);
2391 /* create a codec specific record */
2392 spec = via_new_spec(codec);
2396 spec->aa_mix_nid = 0x16;
2398 /* automatic parse from the BIOS config */
2399 err = via_parse_auto_config(codec);
2405 codec->patch_ops = via_patch_ops;
2407 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2412 /* Patch for VT1708S */
2413 static const struct hda_verb vt1708S_init_verbs[] = {
2414 /* Enable Mic Boost Volume backdoor */
2416 /* don't bybass mixer */
2421 /* fill out digital output widgets; one for master and one for slave outputs */
2422 static void fill_dig_outs(struct hda_codec *codec)
2424 struct via_spec *spec = codec->spec;
2427 for (i = 0; i < spec->autocfg.dig_outs; i++) {
2431 nid = spec->autocfg.dig_out_pins[i];
2434 conn = snd_hda_get_connections(codec, nid, &nid, 1);
2437 if (!spec->multiout.dig_out_nid)
2438 spec->multiout.dig_out_nid = nid;
2440 spec->slave_dig_outs[0] = nid;
2441 break; /* at most two dig outs */
2446 static void fill_dig_in(struct hda_codec *codec)
2448 struct via_spec *spec = codec->spec;
2452 if (!spec->autocfg.dig_in_pin)
2455 dig_nid = codec->start_nid;
2456 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
2457 unsigned int wcaps = get_wcaps(codec, dig_nid);
2458 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2460 if (!(wcaps & AC_WCAP_DIGITAL))
2462 if (!(wcaps & AC_WCAP_CONN_LIST))
2464 err = get_connection_index(codec, dig_nid,
2465 spec->autocfg.dig_in_pin);
2467 spec->dig_in_nid = dig_nid;
2473 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
2474 int offset, int num_steps, int step_size)
2476 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
2477 (offset << AC_AMPCAP_OFFSET_SHIFT) |
2478 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
2479 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
2480 (0 << AC_AMPCAP_MUTE_SHIFT));
2483 static int patch_vt1708S(struct hda_codec *codec)
2485 struct via_spec *spec;
2488 /* create a codec specific record */
2489 spec = via_new_spec(codec);
2493 spec->aa_mix_nid = 0x16;
2494 override_mic_boost(codec, 0x1a, 0, 3, 40);
2495 override_mic_boost(codec, 0x1e, 0, 3, 40);
2497 /* automatic parse from the BIOS config */
2498 err = via_parse_auto_config(codec);
2504 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
2506 codec->patch_ops = via_patch_ops;
2508 /* correct names for VT1708BCE */
2509 if (get_codec_type(codec) == VT1708BCE) {
2510 kfree(codec->chip_name);
2511 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
2512 snprintf(codec->bus->card->mixername,
2513 sizeof(codec->bus->card->mixername),
2514 "%s %s", codec->vendor_name, codec->chip_name);
2516 /* correct names for VT1705 */
2517 if (codec->vendor_id == 0x11064397) {
2518 kfree(codec->chip_name);
2519 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
2520 snprintf(codec->bus->card->mixername,
2521 sizeof(codec->bus->card->mixername),
2522 "%s %s", codec->vendor_name, codec->chip_name);
2524 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
2528 /* Patch for VT1702 */
2530 static const struct hda_verb vt1702_init_verbs[] = {
2538 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
2540 int imux_is_smixer =
2541 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2544 /* PW 1/2/5 (14h/15h/18h) */
2546 set_pin_power_state(codec, 0x14, &parm);
2547 set_pin_power_state(codec, 0x15, &parm);
2548 set_pin_power_state(codec, 0x18, &parm);
2550 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
2551 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
2552 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2553 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
2554 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2555 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
2558 /* PW 3/4 (16h/17h) */
2560 set_pin_power_state(codec, 0x17, &parm);
2561 set_pin_power_state(codec, 0x16, &parm);
2562 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
2563 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
2564 imux_is_smixer ? AC_PWRST_D0 : parm);
2565 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2566 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
2569 static int patch_vt1702(struct hda_codec *codec)
2571 struct via_spec *spec;
2574 /* create a codec specific record */
2575 spec = via_new_spec(codec);
2579 spec->aa_mix_nid = 0x1a;
2581 /* limit AA path volume to 0 dB */
2582 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
2583 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
2584 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2585 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2586 (1 << AC_AMPCAP_MUTE_SHIFT));
2588 /* automatic parse from the BIOS config */
2589 err = via_parse_auto_config(codec);
2595 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
2597 codec->patch_ops = via_patch_ops;
2599 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
2603 /* Patch for VT1718S */
2605 static const struct hda_verb vt1718S_init_verbs[] = {
2606 /* Enable MW0 adjust Gain 5 */
2608 /* Enable Boost Volume backdoor */
2614 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
2616 struct via_spec *spec = codec->spec;
2619 /* MUX6 (1eh) = stereo mixer */
2621 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
2623 /* PW 5/6/7 (29h/2ah/2bh) */
2625 set_pin_power_state(codec, 0x29, &parm);
2626 set_pin_power_state(codec, 0x2a, &parm);
2627 set_pin_power_state(codec, 0x2b, &parm);
2630 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
2631 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2632 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2633 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2634 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2637 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
2639 set_pin_power_state(codec, 0x27, &parm);
2640 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
2641 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
2643 /* PW2 (26h), AOW2 (ah) */
2645 set_pin_power_state(codec, 0x26, &parm);
2646 if (spec->smart51_enabled)
2647 set_pin_power_state(codec, 0x2b, &parm);
2648 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
2650 /* PW0 (24h), AOW0 (8h) */
2652 set_pin_power_state(codec, 0x24, &parm);
2653 if (!spec->hp_independent_mode) /* check for redirected HP */
2654 set_pin_power_state(codec, 0x28, &parm);
2655 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2656 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
2657 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
2658 imux_is_smixer ? AC_PWRST_D0 : parm);
2660 /* PW1 (25h), AOW1 (9h) */
2662 set_pin_power_state(codec, 0x25, &parm);
2663 if (spec->smart51_enabled)
2664 set_pin_power_state(codec, 0x2a, &parm);
2665 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
2667 if (spec->hp_independent_mode) {
2668 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
2670 set_pin_power_state(codec, 0x28, &parm);
2671 snd_hda_codec_write(codec, 0x1b, 0,
2672 AC_VERB_SET_POWER_STATE, parm);
2673 snd_hda_codec_write(codec, 0x34, 0,
2674 AC_VERB_SET_POWER_STATE, parm);
2675 snd_hda_codec_write(codec, 0xc, 0,
2676 AC_VERB_SET_POWER_STATE, parm);
2680 static int patch_vt1718S(struct hda_codec *codec)
2682 struct via_spec *spec;
2685 /* create a codec specific record */
2686 spec = via_new_spec(codec);
2690 spec->aa_mix_nid = 0x21;
2691 override_mic_boost(codec, 0x2b, 0, 3, 40);
2692 override_mic_boost(codec, 0x29, 0, 3, 40);
2694 /* automatic parse from the BIOS config */
2695 err = via_parse_auto_config(codec);
2701 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
2703 codec->patch_ops = via_patch_ops;
2705 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
2710 /* Patch for VT1716S */
2712 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
2713 struct snd_ctl_elem_info *uinfo)
2715 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2717 uinfo->value.integer.min = 0;
2718 uinfo->value.integer.max = 1;
2722 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
2723 struct snd_ctl_elem_value *ucontrol)
2725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2728 index = snd_hda_codec_read(codec, 0x26, 0,
2729 AC_VERB_GET_CONNECT_SEL, 0);
2731 *ucontrol->value.integer.value = index;
2736 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
2737 struct snd_ctl_elem_value *ucontrol)
2739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2740 struct via_spec *spec = codec->spec;
2741 int index = *ucontrol->value.integer.value;
2743 snd_hda_codec_write(codec, 0x26, 0,
2744 AC_VERB_SET_CONNECT_SEL, index);
2745 spec->dmic_enabled = index;
2746 set_widgets_power_state(codec);
2750 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
2751 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
2753 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2754 .name = "Digital Mic Capture Switch",
2755 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
2757 .info = vt1716s_dmic_info,
2758 .get = vt1716s_dmic_get,
2759 .put = vt1716s_dmic_put,
2765 /* mono-out mixer elements */
2766 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
2767 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
2771 static const struct hda_verb vt1716S_init_verbs[] = {
2772 /* Enable Boost Volume backdoor */
2774 /* don't bybass mixer */
2776 /* Enable mono output */
2781 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
2783 struct via_spec *spec = codec->spec;
2786 unsigned int mono_out, present;
2787 /* SW0 (17h) = stereo mixer */
2789 (snd_hda_codec_read(codec, 0x17, 0,
2790 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
2792 /* PW 1/2/5 (1ah/1bh/1eh) */
2794 set_pin_power_state(codec, 0x1a, &parm);
2795 set_pin_power_state(codec, 0x1b, &parm);
2796 set_pin_power_state(codec, 0x1e, &parm);
2799 /* SW0 (17h), AIW0(13h) */
2800 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
2801 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
2804 set_pin_power_state(codec, 0x1e, &parm);
2806 if (spec->dmic_enabled)
2807 set_pin_power_state(codec, 0x22, &parm);
2809 snd_hda_codec_write(codec, 0x22, 0,
2810 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2812 /* SW2(26h), AIW1(14h) */
2813 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
2814 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
2817 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
2819 set_pin_power_state(codec, 0x19, &parm);
2820 /* Smart 5.1 PW2(1bh) */
2821 if (spec->smart51_enabled)
2822 set_pin_power_state(codec, 0x1b, &parm);
2823 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
2824 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2826 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
2828 set_pin_power_state(codec, 0x23, &parm);
2829 /* Smart 5.1 PW1(1ah) */
2830 if (spec->smart51_enabled)
2831 set_pin_power_state(codec, 0x1a, &parm);
2832 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
2834 /* Smart 5.1 PW5(1eh) */
2835 if (spec->smart51_enabled)
2836 set_pin_power_state(codec, 0x1e, &parm);
2837 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
2840 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
2841 present = snd_hda_jack_detect(codec, 0x1c);
2846 present = snd_hda_jack_detect(codec, 0x1d);
2847 if (!spec->hp_independent_mode && present)
2852 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
2853 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
2854 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
2855 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
2857 /* PW 3/4 (1ch/1dh) */
2859 set_pin_power_state(codec, 0x1c, &parm);
2860 set_pin_power_state(codec, 0x1d, &parm);
2861 /* HP Independent Mode, power on AOW3 */
2862 if (spec->hp_independent_mode)
2863 snd_hda_codec_write(codec, 0x25, 0,
2864 AC_VERB_SET_POWER_STATE, parm);
2866 /* force to D0 for internal Speaker */
2867 /* MW0 (16h), AOW0 (10h) */
2868 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
2869 imux_is_smixer ? AC_PWRST_D0 : parm);
2870 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
2871 mono_out ? AC_PWRST_D0 : parm);
2874 static int patch_vt1716S(struct hda_codec *codec)
2876 struct via_spec *spec;
2879 /* create a codec specific record */
2880 spec = via_new_spec(codec);
2884 spec->aa_mix_nid = 0x16;
2885 override_mic_boost(codec, 0x1a, 0, 3, 40);
2886 override_mic_boost(codec, 0x1e, 0, 3, 40);
2888 /* automatic parse from the BIOS config */
2889 err = via_parse_auto_config(codec);
2895 spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
2897 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
2900 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
2902 codec->patch_ops = via_patch_ops;
2904 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
2910 static const struct hda_verb vt2002P_init_verbs[] = {
2911 /* Class-D speaker related verbs */
2915 /* Enable Boost Volume backdoor */
2917 /* Enable AOW0 to MW9 */
2922 static const struct hda_verb vt1802_init_verbs[] = {
2923 /* Enable Boost Volume backdoor */
2925 /* Enable AOW0 to MW9 */
2930 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
2932 struct via_spec *spec = codec->spec;
2935 unsigned int present;
2936 /* MUX9 (1eh) = stereo mixer */
2938 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
2940 /* PW 5/6/7 (29h/2ah/2bh) */
2942 set_pin_power_state(codec, 0x29, &parm);
2943 set_pin_power_state(codec, 0x2a, &parm);
2944 set_pin_power_state(codec, 0x2b, &parm);
2946 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
2947 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
2948 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
2949 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
2950 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
2954 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
2956 if (spec->codec_type == VT1802) {
2957 /* PW4 (28h), MW4 (18h), MUX4(38h) */
2959 set_pin_power_state(codec, 0x28, &parm);
2960 snd_hda_codec_write(codec, 0x18, 0,
2961 AC_VERB_SET_POWER_STATE, parm);
2962 snd_hda_codec_write(codec, 0x38, 0,
2963 AC_VERB_SET_POWER_STATE, parm);
2965 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
2967 set_pin_power_state(codec, 0x26, &parm);
2968 snd_hda_codec_write(codec, 0x1c, 0,
2969 AC_VERB_SET_POWER_STATE, parm);
2970 snd_hda_codec_write(codec, 0x37, 0,
2971 AC_VERB_SET_POWER_STATE, parm);
2974 if (spec->codec_type == VT1802) {
2975 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
2977 set_pin_power_state(codec, 0x25, &parm);
2978 snd_hda_codec_write(codec, 0x15, 0,
2979 AC_VERB_SET_POWER_STATE, parm);
2980 snd_hda_codec_write(codec, 0x35, 0,
2981 AC_VERB_SET_POWER_STATE, parm);
2983 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
2985 set_pin_power_state(codec, 0x25, &parm);
2986 snd_hda_codec_write(codec, 0x19, 0,
2987 AC_VERB_SET_POWER_STATE, parm);
2988 snd_hda_codec_write(codec, 0x35, 0,
2989 AC_VERB_SET_POWER_STATE, parm);
2992 if (spec->hp_independent_mode)
2993 snd_hda_codec_write(codec, 0x9, 0,
2994 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2997 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
2998 present = snd_hda_jack_detect(codec, 0x25);
3001 set_pin_power_state(codec, 0x24, &parm);
3002 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3003 if (spec->codec_type == VT1802)
3004 snd_hda_codec_write(codec, 0x14, 0,
3005 AC_VERB_SET_POWER_STATE, parm);
3007 snd_hda_codec_write(codec, 0x18, 0,
3008 AC_VERB_SET_POWER_STATE, parm);
3009 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
3012 present = snd_hda_jack_detect(codec, 0x26);
3014 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
3015 if (spec->codec_type == VT1802) {
3016 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
3017 snd_hda_codec_write(codec, 0x33, 0,
3018 AC_VERB_SET_POWER_STATE, parm);
3019 snd_hda_codec_write(codec, 0x1c, 0,
3020 AC_VERB_SET_POWER_STATE, parm);
3021 snd_hda_codec_write(codec, 0x3c, 0,
3022 AC_VERB_SET_POWER_STATE, parm);
3024 /* PW15 (31h), MW8(17h), MUX8(3bh) */
3025 snd_hda_codec_write(codec, 0x31, 0,
3026 AC_VERB_SET_POWER_STATE, parm);
3027 snd_hda_codec_write(codec, 0x17, 0,
3028 AC_VERB_SET_POWER_STATE, parm);
3029 snd_hda_codec_write(codec, 0x3b, 0,
3030 AC_VERB_SET_POWER_STATE, parm);
3033 if (imux_is_smixer || !is_aa_path_mute(codec))
3034 snd_hda_codec_write(codec, 0x21, 0,
3035 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3037 snd_hda_codec_write(codec, 0x21, 0,
3038 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3041 /* patch for vt2002P */
3042 static int patch_vt2002P(struct hda_codec *codec)
3044 struct via_spec *spec;
3047 /* create a codec specific record */
3048 spec = via_new_spec(codec);
3052 spec->aa_mix_nid = 0x21;
3053 override_mic_boost(codec, 0x2b, 0, 3, 40);
3054 override_mic_boost(codec, 0x29, 0, 3, 40);
3056 /* automatic parse from the BIOS config */
3057 err = via_parse_auto_config(codec);
3063 if (spec->codec_type == VT1802)
3064 spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
3066 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
3068 codec->patch_ops = via_patch_ops;
3070 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
3076 static const struct hda_verb vt1812_init_verbs[] = {
3077 /* Enable Boost Volume backdoor */
3079 /* Enable AOW0 to MW9 */
3084 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3086 struct via_spec *spec = codec->spec;
3087 int imux_is_smixer =
3088 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3090 unsigned int present;
3091 /* MUX10 (1eh) = stereo mixer */
3093 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3095 /* PW 5/6/7 (29h/2ah/2bh) */
3097 set_pin_power_state(codec, 0x29, &parm);
3098 set_pin_power_state(codec, 0x2a, &parm);
3099 set_pin_power_state(codec, 0x2b, &parm);
3101 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
3102 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
3103 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
3104 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3105 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3109 snd_hda_codec_write(codec, 0x8, 0,
3110 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3112 /* PW4 (28h), MW4 (18h), MUX4(38h) */
3114 set_pin_power_state(codec, 0x28, &parm);
3115 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3116 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
3118 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
3120 set_pin_power_state(codec, 0x25, &parm);
3121 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
3122 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
3123 if (spec->hp_independent_mode)
3124 snd_hda_codec_write(codec, 0x9, 0,
3125 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3127 /* Internal Speaker */
3128 /* PW0 (24h), MW0(14h), MUX0(34h) */
3129 present = snd_hda_jack_detect(codec, 0x25);
3132 set_pin_power_state(codec, 0x24, &parm);
3134 snd_hda_codec_write(codec, 0x14, 0,
3135 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3136 snd_hda_codec_write(codec, 0x34, 0,
3137 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3139 snd_hda_codec_write(codec, 0x14, 0,
3140 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3141 snd_hda_codec_write(codec, 0x34, 0,
3142 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3147 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
3148 present = snd_hda_jack_detect(codec, 0x28);
3151 set_pin_power_state(codec, 0x31, &parm);
3153 snd_hda_codec_write(codec, 0x1c, 0,
3154 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3155 snd_hda_codec_write(codec, 0x3c, 0,
3156 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3157 snd_hda_codec_write(codec, 0x3e, 0,
3158 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3160 snd_hda_codec_write(codec, 0x1c, 0,
3161 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3162 snd_hda_codec_write(codec, 0x3c, 0,
3163 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3164 snd_hda_codec_write(codec, 0x3e, 0,
3165 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
3168 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
3170 set_pin_power_state(codec, 0x33, &parm);
3171 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
3172 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
3176 /* patch for vt1812 */
3177 static int patch_vt1812(struct hda_codec *codec)
3179 struct via_spec *spec;
3182 /* create a codec specific record */
3183 spec = via_new_spec(codec);
3187 spec->aa_mix_nid = 0x21;
3188 override_mic_boost(codec, 0x2b, 0, 3, 40);
3189 override_mic_boost(codec, 0x29, 0, 3, 40);
3191 /* automatic parse from the BIOS config */
3192 err = via_parse_auto_config(codec);
3198 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
3200 codec->patch_ops = via_patch_ops;
3202 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
3209 static const struct hda_codec_preset snd_hda_preset_via[] = {
3210 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3211 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3212 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3213 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3214 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3215 .patch = patch_vt1709},
3216 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3217 .patch = patch_vt1709},
3218 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3219 .patch = patch_vt1709},
3220 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3221 .patch = patch_vt1709},
3222 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3223 .patch = patch_vt1709},
3224 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3225 .patch = patch_vt1709},
3226 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3227 .patch = patch_vt1709},
3228 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3229 .patch = patch_vt1709},
3230 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3231 .patch = patch_vt1708B},
3232 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3233 .patch = patch_vt1708B},
3234 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3235 .patch = patch_vt1708B},
3236 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3237 .patch = patch_vt1708B},
3238 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3239 .patch = patch_vt1708B},
3240 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3241 .patch = patch_vt1708B},
3242 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3243 .patch = patch_vt1708B},
3244 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3245 .patch = patch_vt1708B},
3246 { .id = 0x11060397, .name = "VT1708S",
3247 .patch = patch_vt1708S},
3248 { .id = 0x11061397, .name = "VT1708S",
3249 .patch = patch_vt1708S},
3250 { .id = 0x11062397, .name = "VT1708S",
3251 .patch = patch_vt1708S},
3252 { .id = 0x11063397, .name = "VT1708S",
3253 .patch = patch_vt1708S},
3254 { .id = 0x11064397, .name = "VT1705",
3255 .patch = patch_vt1708S},
3256 { .id = 0x11065397, .name = "VT1708S",
3257 .patch = patch_vt1708S},
3258 { .id = 0x11066397, .name = "VT1708S",
3259 .patch = patch_vt1708S},
3260 { .id = 0x11067397, .name = "VT1708S",
3261 .patch = patch_vt1708S},
3262 { .id = 0x11060398, .name = "VT1702",
3263 .patch = patch_vt1702},
3264 { .id = 0x11061398, .name = "VT1702",
3265 .patch = patch_vt1702},
3266 { .id = 0x11062398, .name = "VT1702",
3267 .patch = patch_vt1702},
3268 { .id = 0x11063398, .name = "VT1702",
3269 .patch = patch_vt1702},
3270 { .id = 0x11064398, .name = "VT1702",
3271 .patch = patch_vt1702},
3272 { .id = 0x11065398, .name = "VT1702",
3273 .patch = patch_vt1702},
3274 { .id = 0x11066398, .name = "VT1702",
3275 .patch = patch_vt1702},
3276 { .id = 0x11067398, .name = "VT1702",
3277 .patch = patch_vt1702},
3278 { .id = 0x11060428, .name = "VT1718S",
3279 .patch = patch_vt1718S},
3280 { .id = 0x11064428, .name = "VT1718S",
3281 .patch = patch_vt1718S},
3282 { .id = 0x11060441, .name = "VT2020",
3283 .patch = patch_vt1718S},
3284 { .id = 0x11064441, .name = "VT1828S",
3285 .patch = patch_vt1718S},
3286 { .id = 0x11060433, .name = "VT1716S",
3287 .patch = patch_vt1716S},
3288 { .id = 0x1106a721, .name = "VT1716S",
3289 .patch = patch_vt1716S},
3290 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
3291 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
3292 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
3293 { .id = 0x11060440, .name = "VT1818S",
3294 .patch = patch_vt1708S},
3295 { .id = 0x11060446, .name = "VT1802",
3296 .patch = patch_vt2002P},
3297 { .id = 0x11068446, .name = "VT1802",
3298 .patch = patch_vt2002P},
3302 MODULE_ALIAS("snd-hda-codec-id:1106*");
3304 static struct hda_codec_preset_list via_list = {
3305 .preset = snd_hda_preset_via,
3306 .owner = THIS_MODULE,
3309 MODULE_LICENSE("GPL");
3310 MODULE_DESCRIPTION("VIA HD-audio codec");
3312 static int __init patch_via_init(void)
3314 return snd_hda_add_codec_preset(&via_list);
3317 static void __exit patch_via_exit(void)
3319 snd_hda_delete_codec_preset(&via_list);
3322 module_init(patch_via_init)
3323 module_exit(patch_via_exit)