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"
57 #define NID_MAPPING (-1)
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
64 #define VT1708_HP_NID 0x13
65 #define VT1708_DIGOUT_NID 0x14
66 #define VT1708_DIGIN_NID 0x16
67 #define VT1708_DIGIN_PIN 0x26
68 #define VT1708_HP_PIN_NID 0x20
69 #define VT1708_CD_PIN_NID 0x24
71 #define VT1709_HP_DAC_NID 0x28
72 #define VT1709_DIGOUT_NID 0x13
73 #define VT1709_DIGIN_NID 0x17
74 #define VT1709_DIGIN_PIN 0x25
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
105 #define VT2002P_COMPATIBLE(spec) \
106 ((spec)->codec_type == VT2002P ||\
107 (spec)->codec_type == VT1812 ||\
108 (spec)->codec_type == VT1802)
111 /* codec parameterization */
112 const struct snd_kcontrol_new *mixers[6];
113 unsigned int num_mixers;
115 const struct hda_verb *init_verbs[5];
116 unsigned int num_iverbs;
118 char stream_name_analog[32];
119 const struct hda_pcm_stream *stream_analog_playback;
120 const struct hda_pcm_stream *stream_analog_capture;
122 char stream_name_digital[32];
123 const struct hda_pcm_stream *stream_digital_playback;
124 const struct hda_pcm_stream *stream_digital_capture;
127 struct hda_multi_out multiout;
128 hda_nid_t slave_dig_outs[2];
131 unsigned int num_adc_nids;
132 hda_nid_t adc_nids[3];
133 hda_nid_t mux_nids[3];
134 hda_nid_t dig_in_nid;
135 hda_nid_t dig_in_pin;
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 const struct hda_input_mux *hp_mux;
152 unsigned int hp_independent_mode;
153 unsigned int hp_independent_mode_index;
154 unsigned int smart51_enabled;
155 unsigned int dmic_enabled;
156 unsigned int no_pin_power_ctl;
157 enum VIA_HDA_CODEC codec_type;
159 /* work to check hp jack state */
160 struct hda_codec *codec;
161 struct delayed_work vt1708_hp_work;
162 int vt1708_jack_detect;
163 int vt1708_hp_present;
165 void (*set_widgets_power_state)(struct hda_codec *codec);
167 #ifdef CONFIG_SND_HDA_POWER_SAVE
168 struct hda_loopback_check loopback;
172 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
173 static struct via_spec * via_new_spec(struct hda_codec *codec)
175 struct via_spec *spec;
177 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
183 spec->codec_type = get_codec_type(codec);
184 /* VT1708BCE & VT1708S are almost same */
185 if (spec->codec_type == VT1708BCE)
186 spec->codec_type = VT1708S;
190 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
192 u32 vendor_id = codec->vendor_id;
193 u16 ven_id = vendor_id >> 16;
194 u16 dev_id = vendor_id & 0xffff;
195 enum VIA_HDA_CODEC codec_type;
198 if (ven_id != 0x1106)
199 codec_type = UNKNOWN;
200 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
202 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
203 codec_type = VT1709_10CH;
204 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
205 codec_type = VT1709_6CH;
206 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
207 codec_type = VT1708B_8CH;
208 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
209 codec_type = VT1708BCE;
210 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
211 codec_type = VT1708B_4CH;
212 else if ((dev_id & 0xfff) == 0x397
213 && (dev_id >> 12) < 8)
214 codec_type = VT1708S;
215 else if ((dev_id & 0xfff) == 0x398
216 && (dev_id >> 12) < 8)
218 else if ((dev_id & 0xfff) == 0x428
219 && (dev_id >> 12) < 8)
220 codec_type = VT1718S;
221 else if (dev_id == 0x0433 || dev_id == 0xa721)
222 codec_type = VT1716S;
223 else if (dev_id == 0x0441 || dev_id == 0x4441)
224 codec_type = VT1718S;
225 else if (dev_id == 0x0438 || dev_id == 0x4438)
226 codec_type = VT2002P;
227 else if (dev_id == 0x0448)
229 else if (dev_id == 0x0440)
230 codec_type = VT1708S;
231 else if ((dev_id & 0xfff) == 0x446)
234 codec_type = UNKNOWN;
238 #define VIA_JACK_EVENT 0x20
239 #define VIA_HP_EVENT 0x01
240 #define VIA_GPIO_EVENT 0x02
241 #define VIA_MONO_EVENT 0x03
242 #define VIA_SPEAKER_EVENT 0x04
243 #define VIA_BIND_HP_EVENT 0x05
248 VIA_CTL_WIDGET_ANALOG_MUTE,
249 VIA_CTL_WIDGET_BIND_PIN_MUTE,
259 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
260 static int is_aa_path_mute(struct hda_codec *codec);
262 static void vt1708_start_hp_work(struct via_spec *spec)
264 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
266 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
267 !spec->vt1708_jack_detect);
268 if (!delayed_work_pending(&spec->vt1708_hp_work))
269 schedule_delayed_work(&spec->vt1708_hp_work,
270 msecs_to_jiffies(100));
273 static void vt1708_stop_hp_work(struct via_spec *spec)
275 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
277 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
278 && !is_aa_path_mute(spec->codec))
280 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
281 !spec->vt1708_jack_detect);
282 cancel_delayed_work_sync(&spec->vt1708_hp_work);
285 static void set_widgets_power_state(struct hda_codec *codec)
287 struct via_spec *spec = codec->spec;
288 if (spec->set_widgets_power_state)
289 spec->set_widgets_power_state(codec);
292 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
295 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
298 set_widgets_power_state(codec);
299 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
300 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
301 if (is_aa_path_mute(codec))
302 vt1708_start_hp_work(codec->spec);
304 vt1708_stop_hp_work(codec->spec);
309 /* modify .put = snd_hda_mixer_amp_switch_put */
310 #define ANALOG_INPUT_MUTE \
311 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
314 .info = snd_hda_mixer_amp_switch_info, \
315 .get = snd_hda_mixer_amp_switch_get, \
316 .put = analog_input_switch_put, \
317 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
319 static void via_hp_bind_automute(struct hda_codec *codec);
321 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
322 struct snd_ctl_elem_value *ucontrol)
324 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
325 struct via_spec *spec = codec->spec;
329 long *valp = ucontrol->value.integer.value;
331 if (strstr(kcontrol->id.name, "Switch") == NULL) {
332 snd_printd("Invalid control!\n");
335 change = snd_hda_mixer_amp_switch_put(kcontrol,
338 lmute = *valp ? 0 : HDA_AMP_MUTE;
340 rmute = *valp ? 0 : HDA_AMP_MUTE;
343 if (!spec->hp_independent_mode) {
344 for (i = 0; i < spec->autocfg.hp_outs; i++) {
345 snd_hda_codec_amp_update(
346 codec, spec->autocfg.hp_pins[i],
347 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
349 snd_hda_codec_amp_update(
350 codec, spec->autocfg.hp_pins[i],
351 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
356 if (!lmute && !rmute) {
358 for (i = 0; i < spec->autocfg.line_outs; i++)
359 snd_hda_codec_amp_stereo(
360 codec, spec->autocfg.line_out_pins[i],
361 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
363 for (i = 0; i < spec->autocfg.speaker_outs; i++)
364 snd_hda_codec_amp_stereo(
365 codec, spec->autocfg.speaker_pins[i],
366 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
368 via_hp_bind_automute(codec);
372 /* Mute all left channels */
373 for (i = 1; i < spec->autocfg.line_outs; i++)
374 snd_hda_codec_amp_update(
376 spec->autocfg.line_out_pins[i],
377 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
379 for (i = 0; i < spec->autocfg.speaker_outs; i++)
380 snd_hda_codec_amp_update(
382 spec->autocfg.speaker_pins[i],
383 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
387 /* mute all right channels */
388 for (i = 1; i < spec->autocfg.line_outs; i++)
389 snd_hda_codec_amp_update(
391 spec->autocfg.line_out_pins[i],
392 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
394 for (i = 0; i < spec->autocfg.speaker_outs; i++)
395 snd_hda_codec_amp_update(
397 spec->autocfg.speaker_pins[i],
398 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
405 #define BIND_PIN_MUTE \
406 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
409 .info = snd_hda_mixer_amp_switch_info, \
410 .get = snd_hda_mixer_amp_switch_get, \
411 .put = bind_pin_switch_put, \
412 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
414 static const struct snd_kcontrol_new via_control_templates[] = {
415 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
416 HDA_CODEC_MUTE(NULL, 0, 0, 0),
422 /* add dynamic controls */
423 static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
424 const struct snd_kcontrol_new *tmpl,
427 struct snd_kcontrol_new *knew;
429 snd_array_init(&spec->kctls, sizeof(*knew), 32);
430 knew = snd_array_new(&spec->kctls);
437 knew->name = kstrdup(name, GFP_KERNEL);
444 static int __via_add_control(struct via_spec *spec, int type, const char *name,
445 int idx, unsigned long val)
447 struct snd_kcontrol_new *knew;
449 knew = __via_clone_ctl(spec, &via_control_templates[type], name);
452 if (get_amp_nid_(val))
453 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
454 knew->private_value = val;
458 #define via_add_control(spec, type, name, val) \
459 __via_add_control(spec, type, name, 0, val)
461 #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
463 static void via_free_kctls(struct hda_codec *codec)
465 struct via_spec *spec = codec->spec;
467 if (spec->kctls.list) {
468 struct snd_kcontrol_new *kctl = spec->kctls.list;
470 for (i = 0; i < spec->kctls.used; i++)
473 snd_array_free(&spec->kctls);
476 /* create input playback/capture controls for the given pin */
477 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
478 int type_idx, int idx, int mix_nid)
483 sprintf(name, "%s Playback Volume", ctlname);
484 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
485 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
488 sprintf(name, "%s Playback Switch", ctlname);
489 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
490 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
496 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
497 hda_nid_t nid, int pin_type,
501 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
503 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
505 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
506 snd_hda_codec_write(codec, nid, 0,
507 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
511 static void via_auto_init_multi_out(struct hda_codec *codec)
513 struct via_spec *spec = codec->spec;
516 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
517 hda_nid_t nid = spec->autocfg.line_out_pins[i];
519 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
523 static void via_auto_init_hp_out(struct hda_codec *codec)
525 struct via_spec *spec = codec->spec;
529 for (i = 0; i < spec->autocfg.hp_outs; i++) {
530 pin = spec->autocfg.hp_pins[i];
531 if (pin) /* connect to front */
532 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
536 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
538 static void via_auto_init_analog_input(struct hda_codec *codec)
540 struct via_spec *spec = codec->spec;
541 const struct auto_pin_cfg *cfg = &spec->autocfg;
545 for (i = 0; i < cfg->num_inputs; i++) {
546 hda_nid_t nid = cfg->inputs[i].pin;
547 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
549 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
553 snd_hda_codec_write(codec, nid, 0,
554 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
558 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
559 unsigned int *affected_parm)
562 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
563 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
564 >> AC_DEFCFG_MISC_SHIFT
565 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
566 struct via_spec *spec = codec->spec;
567 unsigned present = 0;
569 no_presence |= spec->no_pin_power_ctl;
571 present = snd_hda_jack_detect(codec, nid);
572 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
573 || ((no_presence || present)
574 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
575 *affected_parm = AC_PWRST_D0; /* if it's connected */
580 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
583 static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
584 struct snd_ctl_elem_info *uinfo)
586 static const char * const texts[] = {
587 "Disabled", "Enabled"
590 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
592 uinfo->value.enumerated.items = 2;
593 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
594 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
595 strcpy(uinfo->value.enumerated.name,
596 texts[uinfo->value.enumerated.item]);
600 static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
601 struct snd_ctl_elem_value *ucontrol)
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct via_spec *spec = codec->spec;
605 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
609 static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol)
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct via_spec *spec = codec->spec;
614 unsigned int val = !ucontrol->value.enumerated.item[0];
616 if (val == spec->no_pin_power_ctl)
618 spec->no_pin_power_ctl = val;
619 set_widgets_power_state(codec);
623 static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
625 .name = "Dynamic Power-Control",
626 .info = via_pin_power_ctl_info,
627 .get = via_pin_power_ctl_get,
628 .put = via_pin_power_ctl_put,
635 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_info *uinfo)
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct via_spec *spec = codec->spec;
640 return snd_hda_input_mux_info(spec->input_mux, uinfo);
643 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct via_spec *spec = codec->spec;
648 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
650 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
654 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
655 struct snd_ctl_elem_value *ucontrol)
657 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
658 struct via_spec *spec = codec->spec;
659 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
662 if (!spec->mux_nids[adc_idx])
664 /* switch to D0 beofre change index */
665 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
666 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
667 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
668 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
670 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
671 spec->mux_nids[adc_idx],
672 &spec->cur_mux[adc_idx]);
673 /* update jack power state */
674 set_widgets_power_state(codec);
679 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
680 struct snd_ctl_elem_info *uinfo)
682 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
683 struct via_spec *spec = codec->spec;
684 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
687 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
688 struct snd_ctl_elem_value *ucontrol)
690 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
691 hda_nid_t nid = kcontrol->private_value;
694 /* use !! to translate conn sel 2 for VT1718S */
695 pinsel = !!snd_hda_codec_read(codec, nid, 0,
696 AC_VERB_GET_CONNECT_SEL,
698 ucontrol->value.enumerated.item[0] = pinsel;
703 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
705 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
707 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
708 ctl->vd[0].access |= active
709 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
710 snd_ctl_notify(codec->bus->card,
711 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
715 static hda_nid_t side_mute_channel(struct via_spec *spec)
717 switch (spec->codec_type) {
718 case VT1708: return 0x1b;
719 case VT1709_10CH: return 0x29;
720 case VT1708B_8CH: /* fall thru */
721 case VT1708S: return 0x27;
722 case VT2002P: return 0x19;
723 case VT1802: return 0x15;
724 case VT1812: return 0x15;
729 static int update_side_mute_status(struct hda_codec *codec)
731 /* mute side channel */
732 struct via_spec *spec = codec->spec;
734 hda_nid_t sw3 = side_mute_channel(spec);
737 if (VT2002P_COMPATIBLE(spec))
738 parm = spec->hp_independent_mode ?
739 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
741 parm = spec->hp_independent_mode ?
742 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
743 snd_hda_codec_write(codec, sw3, 0,
744 AC_VERB_SET_AMP_GAIN_MUTE, parm);
745 if (spec->codec_type == VT1812)
746 snd_hda_codec_write(codec, 0x1d, 0,
747 AC_VERB_SET_AMP_GAIN_MUTE, parm);
752 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
753 struct snd_ctl_elem_value *ucontrol)
755 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
756 struct via_spec *spec = codec->spec;
757 hda_nid_t nid = kcontrol->private_value;
758 unsigned int pinsel = ucontrol->value.enumerated.item[0];
759 /* Get Independent Mode index of headphone pin widget */
760 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
762 if (spec->codec_type == VT1718S)
763 snd_hda_codec_write(codec, nid, 0,
764 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
766 snd_hda_codec_write(codec, nid, 0,
767 AC_VERB_SET_CONNECT_SEL, pinsel);
769 if (spec->codec_type == VT1812)
770 snd_hda_codec_write(codec, 0x35, 0,
771 AC_VERB_SET_CONNECT_SEL, pinsel);
772 if (spec->multiout.hp_nid && spec->multiout.hp_nid
773 != spec->multiout.dac_nids[HDA_FRONT])
774 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
777 update_side_mute_status(codec);
778 /* update HP volume/swtich active state */
779 if (spec->codec_type == VT1708S
780 || spec->codec_type == VT1702
781 || spec->codec_type == VT1718S
782 || spec->codec_type == VT1716S
783 || VT2002P_COMPATIBLE(spec)) {
784 activate_ctl(codec, "Headphone Playback Volume",
785 spec->hp_independent_mode);
786 activate_ctl(codec, "Headphone Playback Switch",
787 spec->hp_independent_mode);
789 /* update jack power state */
790 set_widgets_power_state(codec);
794 static const struct snd_kcontrol_new via_hp_mixer[2] = {
796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
797 .name = "Independent HP",
798 .info = via_independent_hp_info,
799 .get = via_independent_hp_get,
800 .put = via_independent_hp_put,
803 .iface = NID_MAPPING,
804 .name = "Independent HP",
808 static int via_hp_build(struct hda_codec *codec)
810 struct via_spec *spec = codec->spec;
811 struct snd_kcontrol_new *knew;
814 hda_nid_t conn[HDA_MAX_CONNECTIONS];
816 switch (spec->codec_type) {
828 nid = spec->autocfg.hp_pins[0];
832 if (spec->codec_type != VT1708) {
833 nums = snd_hda_get_connections(codec, nid,
834 conn, HDA_MAX_CONNECTIONS);
839 knew = via_clone_control(spec, &via_hp_mixer[0]);
843 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
844 knew->private_value = nid;
846 knew = via_clone_control(spec, &via_hp_mixer[1]);
849 knew->subdevice = side_mute_channel(spec);
854 static void notify_aa_path_ctls(struct hda_codec *codec)
857 struct snd_ctl_elem_id id;
858 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
859 struct snd_kcontrol *ctl;
861 memset(&id, 0, sizeof(id));
862 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
863 for (i = 0; i < ARRAY_SIZE(labels); i++) {
864 sprintf(id.name, "%s Playback Volume", labels[i]);
865 ctl = snd_hda_find_mixer_ctl(codec, id.name);
867 snd_ctl_notify(codec->bus->card,
868 SNDRV_CTL_EVENT_MASK_VALUE,
873 static void mute_aa_path(struct hda_codec *codec, int mute)
875 struct via_spec *spec = codec->spec;
880 /* get nid of MW0 and start & end index */
881 switch (spec->codec_type) {
909 /* check AA path's mute status */
910 for (i = start_idx; i <= end_idx; i++) {
911 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
912 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
916 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
918 const struct auto_pin_cfg *cfg = &spec->autocfg;
921 for (i = 0; i < cfg->num_inputs; i++) {
922 if (pin == cfg->inputs[i].pin)
923 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
928 static int via_smart51_info(struct snd_kcontrol *kcontrol,
929 struct snd_ctl_elem_info *uinfo)
931 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
933 uinfo->value.integer.min = 0;
934 uinfo->value.integer.max = 1;
938 static int via_smart51_get(struct snd_kcontrol *kcontrol,
939 struct snd_ctl_elem_value *ucontrol)
941 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
942 struct via_spec *spec = codec->spec;
943 const struct auto_pin_cfg *cfg = &spec->autocfg;
947 for (i = 0; i < cfg->num_inputs; i++) {
948 hda_nid_t nid = cfg->inputs[i].pin;
949 int ctl = snd_hda_codec_read(codec, nid, 0,
950 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
951 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
953 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
954 spec->hp_independent_mode && spec->codec_type != VT1718S)
955 continue; /* ignore FMic for independent HP */
956 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
959 *ucontrol->value.integer.value = on;
963 static int via_smart51_put(struct snd_kcontrol *kcontrol,
964 struct snd_ctl_elem_value *ucontrol)
966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
967 struct via_spec *spec = codec->spec;
968 const struct auto_pin_cfg *cfg = &spec->autocfg;
969 int out_in = *ucontrol->value.integer.value
970 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
973 for (i = 0; i < cfg->num_inputs; i++) {
974 hda_nid_t nid = cfg->inputs[i].pin;
977 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
979 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
980 spec->hp_independent_mode && spec->codec_type != VT1718S)
981 continue; /* don't retask FMic for independent HP */
983 parm = snd_hda_codec_read(codec, nid, 0,
984 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
985 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
987 snd_hda_codec_write(codec, nid, 0,
988 AC_VERB_SET_PIN_WIDGET_CONTROL,
990 if (out_in == AC_PINCTL_OUT_EN) {
991 mute_aa_path(codec, 1);
992 notify_aa_path_ctls(codec);
994 if (spec->codec_type == VT1718S) {
995 snd_hda_codec_amp_stereo(
996 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
999 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
1000 if (spec->codec_type == VT1708S
1001 || spec->codec_type == VT1716S) {
1002 /* input = index 1 (AOW3) */
1003 snd_hda_codec_write(
1005 AC_VERB_SET_CONNECT_SEL, 1);
1006 snd_hda_codec_amp_stereo(
1007 codec, nid, HDA_OUTPUT,
1008 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1012 spec->smart51_enabled = *ucontrol->value.integer.value;
1013 set_widgets_power_state(codec);
1017 static const struct snd_kcontrol_new via_smart51_mixer = {
1018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1019 .name = "Smart 5.1",
1021 .info = via_smart51_info,
1022 .get = via_smart51_get,
1023 .put = via_smart51_put,
1026 static int via_smart51_build(struct via_spec *spec)
1028 struct snd_kcontrol_new *knew;
1029 const struct auto_pin_cfg *cfg = &spec->autocfg;
1035 if (cfg->line_outs > 2)
1038 knew = via_clone_control(spec, &via_smart51_mixer);
1042 for (i = 0; i < cfg->num_inputs; i++) {
1043 nid = cfg->inputs[i].pin;
1044 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1045 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1053 /* capture mixer elements */
1054 static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
1055 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1056 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1057 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1058 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1060 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1061 /* The multiple "Capture Source" controls confuse alsamixer
1062 * So call somewhat different..
1064 /* .name = "Capture Source", */
1065 .name = "Input Source",
1067 .info = via_mux_enum_info,
1068 .get = via_mux_enum_get,
1069 .put = via_mux_enum_put,
1074 /* check AA path's mute statue */
1075 static int is_aa_path_mute(struct hda_codec *codec)
1078 hda_nid_t nid_mixer;
1082 struct via_spec *spec = codec->spec;
1083 /* get nid of MW0 and start & end index */
1084 switch (spec->codec_type) {
1113 /* check AA path's mute status */
1114 for (i = start_idx; i <= end_idx; i++) {
1115 unsigned int con_list = snd_hda_codec_read(
1116 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1117 int shift = 8 * (i % 4);
1118 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1119 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1120 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1121 /* check mute status while the pin is connected */
1122 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1124 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1126 if (!mute_l || !mute_r) {
1135 /* enter/exit analog low-current mode */
1136 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1138 struct via_spec *spec = codec->spec;
1139 static int saved_stream_idle = 1; /* saved stream idle status */
1140 int enable = is_aa_path_mute(codec);
1141 unsigned int verb = 0;
1142 unsigned int parm = 0;
1144 if (stream_idle == -1) /* stream status did not change */
1145 enable = enable && saved_stream_idle;
1147 enable = enable && stream_idle;
1148 saved_stream_idle = stream_idle;
1151 /* decide low current mode's verb & parameter */
1152 switch (spec->codec_type) {
1156 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1162 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1166 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1172 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1175 return; /* other codecs are not supported */
1178 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1182 * generic initialization of ADC, input mixers and output mixers
1184 static const struct hda_verb vt1708_volume_init_verbs[] = {
1186 * Unmute ADC0-1 and set the default input to mic-in
1188 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1189 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1192 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1195 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1196 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1197 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1198 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1199 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1200 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1203 * Set up output mixers (0x19 - 0x1b)
1205 /* set vol=0 to output mixers */
1206 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1207 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1208 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1210 /* Setup default input MW0 to PW4 */
1211 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1212 /* PW9 Output enable */
1213 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1214 /* power down jack detect function */
1219 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1220 struct hda_codec *codec,
1221 struct snd_pcm_substream *substream)
1223 struct via_spec *spec = codec->spec;
1224 int idle = substream->pstr->substream_opened == 1
1225 && substream->ref_count == 0;
1226 analog_low_current_mode(codec, idle);
1227 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1231 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1232 unsigned int stream_tag,
1233 unsigned int format,
1234 struct snd_pcm_substream *substream)
1236 struct via_spec *spec = codec->spec;
1237 struct hda_multi_out *mout = &spec->multiout;
1238 const hda_nid_t *nids = mout->dac_nids;
1239 int chs = substream->runtime->channels;
1241 struct hda_spdif_out *spdif =
1242 snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid);
1244 mutex_lock(&codec->spdif_mutex);
1245 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1247 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1249 !(spdif->status & IEC958_AES0_NONAUDIO)) {
1250 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1251 /* turn off SPDIF once; otherwise the IEC958 bits won't
1253 if (spdif->ctls & AC_DIG1_ENABLE)
1254 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1255 AC_VERB_SET_DIGI_CONVERT_1,
1257 ~AC_DIG1_ENABLE & 0xff);
1258 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1259 stream_tag, 0, format);
1260 /* turn on again (if needed) */
1261 if (spdif->ctls & AC_DIG1_ENABLE)
1262 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1263 AC_VERB_SET_DIGI_CONVERT_1,
1264 spdif->ctls & 0xff);
1266 mout->dig_out_used = 0;
1267 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1271 mutex_unlock(&codec->spdif_mutex);
1274 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1277 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1278 && !spec->hp_independent_mode)
1279 /* headphone out will just decode front left/right (stereo) */
1280 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1283 /* extra outputs copied from front */
1284 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1285 if (mout->extra_out_nid[i])
1286 snd_hda_codec_setup_stream(codec,
1287 mout->extra_out_nid[i],
1288 stream_tag, 0, format);
1291 for (i = 1; i < mout->num_dacs; i++) {
1292 if (chs >= (i + 1) * 2) /* independent out */
1293 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1295 else /* copy front */
1296 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1301 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1302 struct hda_codec *codec,
1303 unsigned int stream_tag,
1304 unsigned int format,
1305 struct snd_pcm_substream *substream)
1307 struct via_spec *spec = codec->spec;
1308 struct hda_multi_out *mout = &spec->multiout;
1309 const hda_nid_t *nids = mout->dac_nids;
1311 if (substream->number == 0)
1312 playback_multi_pcm_prep_0(codec, stream_tag, format,
1315 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1316 spec->hp_independent_mode)
1317 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1318 stream_tag, 0, format);
1320 vt1708_start_hp_work(spec);
1324 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1325 struct hda_codec *codec,
1326 struct snd_pcm_substream *substream)
1328 struct via_spec *spec = codec->spec;
1329 struct hda_multi_out *mout = &spec->multiout;
1330 const hda_nid_t *nids = mout->dac_nids;
1333 if (substream->number == 0) {
1334 for (i = 0; i < mout->num_dacs; i++)
1335 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1337 if (mout->hp_nid && !spec->hp_independent_mode)
1338 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1341 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1342 if (mout->extra_out_nid[i])
1343 snd_hda_codec_setup_stream(codec,
1344 mout->extra_out_nid[i],
1346 mutex_lock(&codec->spdif_mutex);
1347 if (mout->dig_out_nid &&
1348 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1349 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1351 mout->dig_out_used = 0;
1353 mutex_unlock(&codec->spdif_mutex);
1355 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1356 spec->hp_independent_mode)
1357 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1360 vt1708_stop_hp_work(spec);
1367 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1368 struct hda_codec *codec,
1369 struct snd_pcm_substream *substream)
1371 struct via_spec *spec = codec->spec;
1372 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1375 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1376 struct hda_codec *codec,
1377 struct snd_pcm_substream *substream)
1379 struct via_spec *spec = codec->spec;
1380 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1383 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1384 struct hda_codec *codec,
1385 unsigned int stream_tag,
1386 unsigned int format,
1387 struct snd_pcm_substream *substream)
1389 struct via_spec *spec = codec->spec;
1390 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1391 stream_tag, format, substream);
1394 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1395 struct hda_codec *codec,
1396 struct snd_pcm_substream *substream)
1398 struct via_spec *spec = codec->spec;
1399 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1406 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1407 struct hda_codec *codec,
1408 unsigned int stream_tag,
1409 unsigned int format,
1410 struct snd_pcm_substream *substream)
1412 struct via_spec *spec = codec->spec;
1414 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1415 stream_tag, 0, format);
1419 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1420 struct hda_codec *codec,
1421 struct snd_pcm_substream *substream)
1423 struct via_spec *spec = codec->spec;
1424 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1428 static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
1432 .nid = 0x10, /* NID to query formats and rates */
1434 .open = via_playback_pcm_open,
1435 .prepare = via_playback_multi_pcm_prepare,
1436 .cleanup = via_playback_multi_pcm_cleanup
1440 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1444 .nid = 0x10, /* NID to query formats and rates */
1445 /* We got noisy outputs on the right channel on VT1708 when
1446 * 24bit samples are used. Until any workaround is found,
1447 * disable the 24bit format, so far.
1449 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1451 .open = via_playback_pcm_open,
1452 .prepare = via_playback_multi_pcm_prepare,
1453 .cleanup = via_playback_multi_pcm_cleanup
1457 static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
1461 .nid = 0x15, /* NID to query formats and rates */
1463 .prepare = via_capture_pcm_prepare,
1464 .cleanup = via_capture_pcm_cleanup
1468 static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
1472 /* NID is set in via_build_pcms */
1474 .open = via_dig_playback_pcm_open,
1475 .close = via_dig_playback_pcm_close,
1476 .prepare = via_dig_playback_pcm_prepare,
1477 .cleanup = via_dig_playback_pcm_cleanup
1481 static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
1487 static int via_build_controls(struct hda_codec *codec)
1489 struct via_spec *spec = codec->spec;
1490 struct snd_kcontrol *kctl;
1491 const struct snd_kcontrol_new *knew;
1494 if (spec->set_widgets_power_state)
1495 if (!via_clone_control(spec, &via_pin_power_ctl_enum))
1498 for (i = 0; i < spec->num_mixers; i++) {
1499 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1504 if (spec->multiout.dig_out_nid) {
1505 err = snd_hda_create_spdif_out_ctls(codec,
1506 spec->multiout.dig_out_nid,
1507 spec->multiout.dig_out_nid);
1510 err = snd_hda_create_spdif_share_sw(codec,
1514 spec->multiout.share_spdif = 1;
1516 if (spec->dig_in_nid) {
1517 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1522 /* assign Capture Source enums to NID */
1523 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1524 for (i = 0; kctl && i < kctl->count; i++) {
1525 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1530 /* other nid->control mapping */
1531 for (i = 0; i < spec->num_mixers; i++) {
1532 for (knew = spec->mixers[i]; knew->name; knew++) {
1533 if (knew->iface != NID_MAPPING)
1535 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1538 err = snd_hda_add_nid(codec, kctl, 0,
1543 /* init power states */
1544 set_widgets_power_state(codec);
1545 analog_low_current_mode(codec, 1);
1547 via_free_kctls(codec); /* no longer needed */
1551 static int via_build_pcms(struct hda_codec *codec)
1553 struct via_spec *spec = codec->spec;
1554 struct hda_pcm *info = spec->pcm_rec;
1556 codec->num_pcms = 1;
1557 codec->pcm_info = info;
1559 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
1560 "%s Analog", codec->chip_name);
1561 info->name = spec->stream_name_analog;
1562 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1563 *(spec->stream_analog_playback);
1564 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1565 spec->multiout.dac_nids[0];
1566 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1567 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1569 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1570 spec->multiout.max_channels;
1572 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1575 snprintf(spec->stream_name_digital,
1576 sizeof(spec->stream_name_digital),
1577 "%s Digital", codec->chip_name);
1578 info->name = spec->stream_name_digital;
1579 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1580 if (spec->multiout.dig_out_nid) {
1581 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1582 *(spec->stream_digital_playback);
1583 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1584 spec->multiout.dig_out_nid;
1586 if (spec->dig_in_nid) {
1587 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1588 *(spec->stream_digital_capture);
1589 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1597 static void via_free(struct hda_codec *codec)
1599 struct via_spec *spec = codec->spec;
1604 via_free_kctls(codec);
1605 vt1708_stop_hp_work(spec);
1609 /* mute internal speaker if HP is plugged */
1610 static void via_hp_automute(struct hda_codec *codec)
1612 unsigned int present = 0;
1613 struct via_spec *spec = codec->spec;
1615 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1617 if (!spec->hp_independent_mode) {
1618 struct snd_ctl_elem_id id;
1620 snd_hda_codec_amp_stereo(
1621 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1622 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1624 memset(&id, 0, sizeof(id));
1625 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1626 strcpy(id.name, "Front Playback Switch");
1627 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1632 /* mute mono out if HP or Line out is plugged */
1633 static void via_mono_automute(struct hda_codec *codec)
1635 unsigned int hp_present, lineout_present;
1636 struct via_spec *spec = codec->spec;
1638 if (spec->codec_type != VT1716S)
1641 lineout_present = snd_hda_jack_detect(codec,
1642 spec->autocfg.line_out_pins[0]);
1644 /* Mute Mono Out if Line Out is plugged */
1645 if (lineout_present) {
1646 snd_hda_codec_amp_stereo(
1647 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1651 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1653 if (!spec->hp_independent_mode)
1654 snd_hda_codec_amp_stereo(
1655 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1656 hp_present ? HDA_AMP_MUTE : 0);
1659 static void via_gpio_control(struct hda_codec *codec)
1661 unsigned int gpio_data;
1662 unsigned int vol_counter;
1664 unsigned int master_vol;
1666 struct via_spec *spec = codec->spec;
1668 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1669 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1671 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1672 0xF84, 0) & 0x3F0000) >> 16;
1674 vol = vol_counter & 0x1F;
1675 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1676 AC_VERB_GET_AMP_GAIN_MUTE,
1679 if (gpio_data == 0x02) {
1680 /* unmute line out */
1681 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1682 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1684 if (vol_counter & 0x20) {
1685 /* decrease volume */
1686 if (vol > master_vol)
1688 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1692 /* increase volume */
1693 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1695 ((master_vol+vol) > 0x2A) ? 0x2A :
1698 } else if (!(gpio_data & 0x02)) {
1700 snd_hda_codec_amp_stereo(codec,
1701 spec->autocfg.line_out_pins[0],
1702 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1707 /* mute Internal-Speaker if HP is plugged */
1708 static void via_speaker_automute(struct hda_codec *codec)
1710 unsigned int hp_present;
1711 struct via_spec *spec = codec->spec;
1713 if (!VT2002P_COMPATIBLE(spec))
1716 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1718 if (!spec->hp_independent_mode) {
1719 struct snd_ctl_elem_id id;
1720 snd_hda_codec_amp_stereo(
1721 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1722 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1724 memset(&id, 0, sizeof(id));
1725 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1726 strcpy(id.name, "Speaker Playback Switch");
1727 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1732 /* mute line-out and internal speaker if HP is plugged */
1733 static void via_hp_bind_automute(struct hda_codec *codec)
1735 /* use long instead of int below just to avoid an internal compiler
1736 * error with gcc 4.0.x
1738 unsigned long hp_present, present = 0;
1739 struct via_spec *spec = codec->spec;
1742 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1745 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1747 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
1749 if (!spec->hp_independent_mode) {
1750 /* Mute Line-Outs */
1751 for (i = 0; i < spec->autocfg.line_outs; i++)
1752 snd_hda_codec_amp_stereo(
1753 codec, spec->autocfg.line_out_pins[i],
1755 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1757 present = hp_present;
1760 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1761 snd_hda_codec_amp_stereo(
1762 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1763 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1767 /* unsolicited event for jack sensing */
1768 static void via_unsol_event(struct hda_codec *codec,
1773 if (res & VIA_JACK_EVENT)
1774 set_widgets_power_state(codec);
1776 res &= ~VIA_JACK_EVENT;
1778 if (res == VIA_HP_EVENT)
1779 via_hp_automute(codec);
1780 else if (res == VIA_GPIO_EVENT)
1781 via_gpio_control(codec);
1782 else if (res == VIA_MONO_EVENT)
1783 via_mono_automute(codec);
1784 else if (res == VIA_SPEAKER_EVENT)
1785 via_speaker_automute(codec);
1786 else if (res == VIA_BIND_HP_EVENT)
1787 via_hp_bind_automute(codec);
1790 static int via_init(struct hda_codec *codec)
1792 struct via_spec *spec = codec->spec;
1794 for (i = 0; i < spec->num_iverbs; i++)
1795 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1797 /* Lydia Add for EAPD enable */
1798 if (!spec->dig_in_nid) { /* No Digital In connection */
1799 if (spec->dig_in_pin) {
1800 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1801 AC_VERB_SET_PIN_WIDGET_CONTROL,
1803 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1804 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1806 } else /* enable SPDIF-input pin */
1807 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1808 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1810 /* assign slave outs */
1811 if (spec->slave_dig_outs[0])
1812 codec->slave_dig_outs = spec->slave_dig_outs;
1817 #ifdef SND_HDA_NEEDS_RESUME
1818 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1820 struct via_spec *spec = codec->spec;
1821 vt1708_stop_hp_work(spec);
1826 #ifdef CONFIG_SND_HDA_POWER_SAVE
1827 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1829 struct via_spec *spec = codec->spec;
1830 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1836 static const struct hda_codec_ops via_patch_ops = {
1837 .build_controls = via_build_controls,
1838 .build_pcms = via_build_pcms,
1841 #ifdef SND_HDA_NEEDS_RESUME
1842 .suspend = via_suspend,
1844 #ifdef CONFIG_SND_HDA_POWER_SAVE
1845 .check_power_status = via_check_power_status,
1849 /* fill in the dac_nids table from the parsed pin configuration */
1850 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1851 const struct auto_pin_cfg *cfg)
1856 spec->multiout.num_dacs = cfg->line_outs;
1858 spec->multiout.dac_nids = spec->private_dac_nids;
1860 for (i = 0; i < 4; i++) {
1861 nid = cfg->line_out_pins[i];
1863 /* config dac list */
1865 case AUTO_SEQ_FRONT:
1866 spec->private_dac_nids[i] = 0x10;
1868 case AUTO_SEQ_CENLFE:
1869 spec->private_dac_nids[i] = 0x12;
1871 case AUTO_SEQ_SURROUND:
1872 spec->private_dac_nids[i] = 0x11;
1875 spec->private_dac_nids[i] = 0x13;
1884 /* add playback controls from the parsed DAC table */
1885 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1886 const struct auto_pin_cfg *cfg)
1889 static const char * const chname[4] = {
1890 "Front", "Surround", "C/LFE", "Side"
1892 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1895 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1896 nid = cfg->line_out_pins[i];
1901 nid_vol = nid_vols[i];
1903 if (i == AUTO_SEQ_CENLFE) {
1905 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1906 "Center Playback Volume",
1907 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1911 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1912 "LFE Playback Volume",
1913 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1917 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1918 "Center Playback Switch",
1919 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1923 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1924 "LFE Playback Switch",
1925 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1929 } else if (i == AUTO_SEQ_FRONT) {
1930 /* add control to mixer index 0 */
1931 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1932 "Master Front Playback Volume",
1933 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1937 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1938 "Master Front Playback Switch",
1939 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1944 /* add control to PW3 */
1945 sprintf(name, "%s Playback Volume", chname[i]);
1946 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1947 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1951 sprintf(name, "%s Playback Switch", chname[i]);
1952 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1953 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1958 sprintf(name, "%s Playback Volume", chname[i]);
1959 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1960 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1964 sprintf(name, "%s Playback Switch", chname[i]);
1965 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1966 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1976 static void create_hp_imux(struct via_spec *spec)
1979 struct hda_input_mux *imux = &spec->private_imux[1];
1980 static const char * const texts[] = { "OFF", "ON", NULL};
1982 /* for hp mode select */
1983 for (i = 0; texts[i]; i++)
1984 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1986 spec->hp_mux = &spec->private_imux[1];
1989 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1996 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1997 spec->hp_independent_mode_index = 1;
1999 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2000 "Headphone Playback Volume",
2001 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2004 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2005 "Headphone Playback Switch",
2006 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2010 create_hp_imux(spec);
2015 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
2018 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
2021 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
2022 for (i = 0; i < nums; i++)
2029 static int via_fill_adcs(struct hda_codec *codec)
2031 struct via_spec *spec = codec->spec;
2032 hda_nid_t nid = codec->start_nid;
2035 for (i = 0; i < codec->num_nodes; i++, nid++) {
2036 unsigned int wcaps = get_wcaps(codec, nid);
2037 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2039 if (wcaps & AC_WCAP_DIGITAL)
2041 if (!(wcaps & AC_WCAP_CONN_LIST))
2043 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2045 spec->adc_nids[spec->num_adc_nids++] = nid;
2050 static int get_mux_nids(struct hda_codec *codec);
2052 /* create playback/capture controls for input pins */
2053 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2054 const struct auto_pin_cfg *cfg,
2057 struct via_spec *spec = codec->spec;
2058 struct hda_input_mux *imux = &spec->private_imux[0];
2059 int i, err, idx, idx2, type, type_idx = 0;
2061 hda_nid_t pin_idxs[8];
2064 err = via_fill_adcs(codec);
2067 err = get_mux_nids(codec);
2070 cap_nid = spec->mux_nids[0];
2072 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2073 ARRAY_SIZE(pin_idxs));
2077 /* for internal loopback recording select */
2078 for (idx = 0; idx < num_idxs; idx++) {
2079 if (pin_idxs[idx] == mix_nid) {
2080 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2085 for (i = 0; i < cfg->num_inputs; i++) {
2087 type = cfg->inputs[i].type;
2088 for (idx = 0; idx < num_idxs; idx++)
2089 if (pin_idxs[idx] == cfg->inputs[i].pin)
2091 if (idx >= num_idxs)
2093 if (i > 0 && type == cfg->inputs[i - 1].type)
2097 label = hda_get_autocfg_input_label(codec, cfg, i);
2098 idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]);
2100 err = via_new_analog_input(spec, label, type_idx,
2104 snd_hda_add_imux_item(imux, label, idx, NULL);
2109 /* create playback/capture controls for input pins */
2110 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2111 const struct auto_pin_cfg *cfg)
2113 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17);
2116 #ifdef CONFIG_SND_HDA_POWER_SAVE
2117 static const struct hda_amp_list vt1708_loopbacks[] = {
2118 { 0x17, HDA_INPUT, 1 },
2119 { 0x17, HDA_INPUT, 2 },
2120 { 0x17, HDA_INPUT, 3 },
2121 { 0x17, HDA_INPUT, 4 },
2126 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2128 unsigned int def_conf;
2129 unsigned char seqassoc;
2131 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2132 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2133 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2134 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2135 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2136 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2137 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2143 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2144 struct snd_ctl_elem_value *ucontrol)
2146 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2147 struct via_spec *spec = codec->spec;
2149 if (spec->codec_type != VT1708)
2151 spec->vt1708_jack_detect =
2152 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2153 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2157 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2158 struct snd_ctl_elem_value *ucontrol)
2160 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2161 struct via_spec *spec = codec->spec;
2164 if (spec->codec_type != VT1708)
2166 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2167 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2168 == !spec->vt1708_jack_detect;
2169 if (spec->vt1708_jack_detect) {
2170 mute_aa_path(codec, 1);
2171 notify_aa_path_ctls(codec);
2176 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2177 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2178 .name = "Jack Detect",
2180 .info = snd_ctl_boolean_mono_info,
2181 .get = vt1708_jack_detect_get,
2182 .put = vt1708_jack_detect_put,
2185 static int vt1708_parse_auto_config(struct hda_codec *codec)
2187 struct via_spec *spec = codec->spec;
2190 /* Add HP and CD pin config connect bit re-config action */
2191 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2192 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2194 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2197 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2200 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2201 return 0; /* can't find valid BIOS pin config */
2203 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2206 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2209 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2212 /* add jack detect on/off control */
2213 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2216 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2218 if (spec->autocfg.dig_outs)
2219 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2220 spec->dig_in_pin = VT1708_DIGIN_PIN;
2221 if (spec->autocfg.dig_in_pin)
2222 spec->dig_in_nid = VT1708_DIGIN_NID;
2224 if (spec->kctls.list)
2225 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2227 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2229 spec->input_mux = &spec->private_imux[0];
2232 via_hp_build(codec);
2234 via_smart51_build(spec);
2238 /* init callback for auto-configuration model -- overriding the default init */
2239 static int via_auto_init(struct hda_codec *codec)
2241 struct via_spec *spec = codec->spec;
2244 via_auto_init_multi_out(codec);
2245 via_auto_init_hp_out(codec);
2246 via_auto_init_analog_input(codec);
2248 if (VT2002P_COMPATIBLE(spec)) {
2249 via_hp_bind_automute(codec);
2251 via_hp_automute(codec);
2252 via_speaker_automute(codec);
2258 static void vt1708_update_hp_jack_state(struct work_struct *work)
2260 struct via_spec *spec = container_of(work, struct via_spec,
2261 vt1708_hp_work.work);
2262 if (spec->codec_type != VT1708)
2264 /* if jack state toggled */
2265 if (spec->vt1708_hp_present
2266 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2267 spec->vt1708_hp_present ^= 1;
2268 via_hp_automute(spec->codec);
2270 vt1708_start_hp_work(spec);
2273 static int get_mux_nids(struct hda_codec *codec)
2275 struct via_spec *spec = codec->spec;
2276 hda_nid_t nid, conn[8];
2280 for (i = 0; i < spec->num_adc_nids; i++) {
2281 nid = spec->adc_nids[i];
2283 type = get_wcaps_type(get_wcaps(codec, nid));
2284 if (type == AC_WID_PIN)
2286 n = snd_hda_get_connections(codec, nid, conn,
2291 spec->mux_nids[i] = nid;
2300 static int patch_vt1708(struct hda_codec *codec)
2302 struct via_spec *spec;
2305 /* create a codec specific record */
2306 spec = via_new_spec(codec);
2310 /* automatic parse from the BIOS config */
2311 err = vt1708_parse_auto_config(codec);
2316 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2317 "from BIOS. Using genenic mode...\n");
2321 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2322 /* disable 32bit format on VT1708 */
2323 if (codec->vendor_id == 0x11061708)
2324 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2325 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2327 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2328 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2330 if (spec->adc_nids && spec->input_mux) {
2331 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2335 codec->patch_ops = via_patch_ops;
2337 codec->patch_ops.init = via_auto_init;
2338 #ifdef CONFIG_SND_HDA_POWER_SAVE
2339 spec->loopback.amplist = vt1708_loopbacks;
2341 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2345 /* capture mixer elements */
2346 static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
2347 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2348 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2349 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2350 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2351 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2352 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2354 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2355 /* The multiple "Capture Source" controls confuse alsamixer
2356 * So call somewhat different..
2358 /* .name = "Capture Source", */
2359 .name = "Input Source",
2361 .info = via_mux_enum_info,
2362 .get = via_mux_enum_get,
2363 .put = via_mux_enum_put,
2368 static const struct hda_verb vt1709_uniwill_init_verbs[] = {
2369 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2370 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2375 * generic initialization of ADC, input mixers and output mixers
2377 static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2379 * Unmute ADC0-2 and set the default input to mic-in
2381 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2382 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2383 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2386 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2389 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2390 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2391 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2392 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2393 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2394 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2397 * Set up output selector (0x1a, 0x1b, 0x29)
2399 /* set vol=0 to output mixers */
2400 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2401 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2402 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2405 * Unmute PW3 and PW4
2407 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2408 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2410 /* Set input of PW4 as MW0 */
2411 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2412 /* PW9 Output enable */
2413 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2417 static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2421 .nid = 0x10, /* NID to query formats and rates */
2423 .open = via_playback_pcm_open,
2424 .prepare = via_playback_multi_pcm_prepare,
2425 .cleanup = via_playback_multi_pcm_cleanup,
2429 static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2433 .nid = 0x10, /* NID to query formats and rates */
2435 .open = via_playback_pcm_open,
2436 .prepare = via_playback_multi_pcm_prepare,
2437 .cleanup = via_playback_multi_pcm_cleanup,
2441 static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
2445 .nid = 0x14, /* NID to query formats and rates */
2447 .prepare = via_capture_pcm_prepare,
2448 .cleanup = via_capture_pcm_cleanup
2452 static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
2456 /* NID is set in via_build_pcms */
2458 .open = via_dig_playback_pcm_open,
2459 .close = via_dig_playback_pcm_close
2463 static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
2469 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2470 const struct auto_pin_cfg *cfg)
2475 if (cfg->line_outs == 4) /* 10 channels */
2476 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2477 else if (cfg->line_outs == 3) /* 6 channels */
2478 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2480 spec->multiout.dac_nids = spec->private_dac_nids;
2482 if (cfg->line_outs == 4) { /* 10 channels */
2483 for (i = 0; i < cfg->line_outs; i++) {
2484 nid = cfg->line_out_pins[i];
2486 /* config dac list */
2488 case AUTO_SEQ_FRONT:
2490 spec->private_dac_nids[i] = 0x10;
2492 case AUTO_SEQ_CENLFE:
2494 spec->private_dac_nids[i] = 0x12;
2496 case AUTO_SEQ_SURROUND:
2498 spec->private_dac_nids[i] = 0x11;
2502 spec->private_dac_nids[i] = 0x27;
2509 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2511 } else if (cfg->line_outs == 3) { /* 6 channels */
2512 for (i = 0; i < cfg->line_outs; i++) {
2513 nid = cfg->line_out_pins[i];
2515 /* config dac list */
2517 case AUTO_SEQ_FRONT:
2519 spec->private_dac_nids[i] = 0x10;
2521 case AUTO_SEQ_CENLFE:
2523 spec->private_dac_nids[i] = 0x12;
2525 case AUTO_SEQ_SURROUND:
2527 spec->private_dac_nids[i] = 0x11;
2539 /* add playback controls from the parsed DAC table */
2540 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2541 const struct auto_pin_cfg *cfg)
2544 static const char * const chname[4] = {
2545 "Front", "Surround", "C/LFE", "Side"
2547 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2550 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2551 nid = cfg->line_out_pins[i];
2556 nid_vol = nid_vols[i];
2558 if (i == AUTO_SEQ_CENLFE) {
2560 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2561 "Center Playback Volume",
2562 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2566 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2567 "LFE Playback Volume",
2568 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2572 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2573 "Center Playback Switch",
2574 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2578 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2579 "LFE Playback Switch",
2580 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2584 } else if (i == AUTO_SEQ_FRONT) {
2585 /* ADD control to mixer index 0 */
2586 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2587 "Master Front Playback Volume",
2588 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2592 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2593 "Master Front Playback Switch",
2594 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2599 /* add control to PW3 */
2600 sprintf(name, "%s Playback Volume", chname[i]);
2601 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2602 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2606 sprintf(name, "%s Playback Switch", chname[i]);
2607 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2608 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2612 } else if (i == AUTO_SEQ_SURROUND) {
2613 sprintf(name, "%s Playback Volume", chname[i]);
2614 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2615 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2619 sprintf(name, "%s Playback Switch", chname[i]);
2620 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2621 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2625 } else if (i == AUTO_SEQ_SIDE) {
2626 sprintf(name, "%s Playback Volume", chname[i]);
2627 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2628 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2632 sprintf(name, "%s Playback Switch", chname[i]);
2633 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2634 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2644 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2651 if (spec->multiout.num_dacs == 5) /* 10 channels */
2652 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2653 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2654 spec->multiout.hp_nid = 0;
2655 spec->hp_independent_mode_index = 1;
2657 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2658 "Headphone Playback Volume",
2659 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2662 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2663 "Headphone Playback Switch",
2664 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2671 /* create playback/capture controls for input pins */
2672 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
2673 const struct auto_pin_cfg *cfg)
2675 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18);
2678 static int vt1709_parse_auto_config(struct hda_codec *codec)
2680 struct via_spec *spec = codec->spec;
2683 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2686 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2689 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2690 return 0; /* can't find valid BIOS pin config */
2692 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2695 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2698 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
2702 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2704 if (spec->autocfg.dig_outs)
2705 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2706 spec->dig_in_pin = VT1709_DIGIN_PIN;
2707 if (spec->autocfg.dig_in_pin)
2708 spec->dig_in_nid = VT1709_DIGIN_NID;
2710 if (spec->kctls.list)
2711 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2713 spec->input_mux = &spec->private_imux[0];
2716 via_hp_build(codec);
2718 via_smart51_build(spec);
2722 #ifdef CONFIG_SND_HDA_POWER_SAVE
2723 static const struct hda_amp_list vt1709_loopbacks[] = {
2724 { 0x18, HDA_INPUT, 1 },
2725 { 0x18, HDA_INPUT, 2 },
2726 { 0x18, HDA_INPUT, 3 },
2727 { 0x18, HDA_INPUT, 4 },
2732 static int patch_vt1709_10ch(struct hda_codec *codec)
2734 struct via_spec *spec;
2737 /* create a codec specific record */
2738 spec = via_new_spec(codec);
2742 err = vt1709_parse_auto_config(codec);
2747 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2748 "Using genenic mode...\n");
2751 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2752 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2754 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2755 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2757 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2758 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2760 if (spec->adc_nids && spec->input_mux) {
2761 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2765 codec->patch_ops = via_patch_ops;
2767 codec->patch_ops.init = via_auto_init;
2768 codec->patch_ops.unsol_event = via_unsol_event;
2769 #ifdef CONFIG_SND_HDA_POWER_SAVE
2770 spec->loopback.amplist = vt1709_loopbacks;
2776 * generic initialization of ADC, input mixers and output mixers
2778 static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2780 * Unmute ADC0-2 and set the default input to mic-in
2782 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2783 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2784 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2787 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2790 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2791 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2792 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2793 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2794 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2795 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2798 * Set up output selector (0x1a, 0x1b, 0x29)
2800 /* set vol=0 to output mixers */
2801 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2802 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2803 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2806 * Unmute PW3 and PW4
2808 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2809 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2811 /* Set input of PW4 as MW0 */
2812 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2813 /* PW9 Output enable */
2814 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2818 static int patch_vt1709_6ch(struct hda_codec *codec)
2820 struct via_spec *spec;
2823 /* create a codec specific record */
2824 spec = via_new_spec(codec);
2828 err = vt1709_parse_auto_config(codec);
2833 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2834 "Using genenic mode...\n");
2837 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2838 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2840 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2841 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2843 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2844 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2846 if (spec->adc_nids && spec->input_mux) {
2847 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2851 codec->patch_ops = via_patch_ops;
2853 codec->patch_ops.init = via_auto_init;
2854 codec->patch_ops.unsol_event = via_unsol_event;
2855 #ifdef CONFIG_SND_HDA_POWER_SAVE
2856 spec->loopback.amplist = vt1709_loopbacks;
2861 /* capture mixer elements */
2862 static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2863 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2864 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2865 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2866 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2868 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2869 /* The multiple "Capture Source" controls confuse alsamixer
2870 * So call somewhat different..
2872 /* .name = "Capture Source", */
2873 .name = "Input Source",
2875 .info = via_mux_enum_info,
2876 .get = via_mux_enum_get,
2877 .put = via_mux_enum_put,
2882 * generic initialization of ADC, input mixers and output mixers
2884 static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2886 * Unmute ADC0-1 and set the default input to mic-in
2888 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2889 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2892 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2895 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2896 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2897 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2898 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2899 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2900 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2903 * Set up output mixers
2905 /* set vol=0 to output mixers */
2906 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2907 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2908 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2910 /* Setup default input to PW4 */
2911 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2912 /* PW9 Output enable */
2913 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2914 /* PW10 Input enable */
2915 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2919 static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2921 * Unmute ADC0-1 and set the default input to mic-in
2923 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2924 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2927 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2930 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2931 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2932 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2933 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2934 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2935 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2938 * Set up output mixers
2940 /* set vol=0 to output mixers */
2941 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2942 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2943 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2945 /* Setup default input of PW4 to MW0 */
2946 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2947 /* PW9 Output enable */
2948 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2949 /* PW10 Input enable */
2950 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2954 static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
2955 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2956 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2957 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2958 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2959 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2960 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2961 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2962 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2963 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2967 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2968 struct hda_codec *codec,
2969 struct snd_pcm_substream *substream)
2971 int idle = substream->pstr->substream_opened == 1
2972 && substream->ref_count == 0;
2974 analog_low_current_mode(codec, idle);
2978 static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2982 .nid = 0x10, /* NID to query formats and rates */
2984 .open = via_playback_pcm_open,
2985 .prepare = via_playback_multi_pcm_prepare,
2986 .cleanup = via_playback_multi_pcm_cleanup,
2987 .close = via_pcm_open_close
2991 static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2995 .nid = 0x10, /* NID to query formats and rates */
2997 .open = via_playback_pcm_open,
2998 .prepare = via_playback_multi_pcm_prepare,
2999 .cleanup = via_playback_multi_pcm_cleanup
3003 static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3007 .nid = 0x13, /* NID to query formats and rates */
3009 .open = via_pcm_open_close,
3010 .prepare = via_capture_pcm_prepare,
3011 .cleanup = via_capture_pcm_cleanup,
3012 .close = via_pcm_open_close
3016 static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3020 /* NID is set in via_build_pcms */
3022 .open = via_dig_playback_pcm_open,
3023 .close = via_dig_playback_pcm_close,
3024 .prepare = via_dig_playback_pcm_prepare,
3025 .cleanup = via_dig_playback_pcm_cleanup
3029 static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3035 /* fill in the dac_nids table from the parsed pin configuration */
3036 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3037 const struct auto_pin_cfg *cfg)
3042 spec->multiout.num_dacs = cfg->line_outs;
3044 spec->multiout.dac_nids = spec->private_dac_nids;
3046 for (i = 0; i < 4; i++) {
3047 nid = cfg->line_out_pins[i];
3049 /* config dac list */
3051 case AUTO_SEQ_FRONT:
3052 spec->private_dac_nids[i] = 0x10;
3054 case AUTO_SEQ_CENLFE:
3055 spec->private_dac_nids[i] = 0x24;
3057 case AUTO_SEQ_SURROUND:
3058 spec->private_dac_nids[i] = 0x11;
3061 spec->private_dac_nids[i] = 0x25;
3070 /* add playback controls from the parsed DAC table */
3071 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3072 const struct auto_pin_cfg *cfg)
3075 static const char * const chname[4] = {
3076 "Front", "Surround", "C/LFE", "Side"
3078 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3079 hda_nid_t nid, nid_vol = 0;
3082 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3083 nid = cfg->line_out_pins[i];
3088 nid_vol = nid_vols[i];
3090 if (i == AUTO_SEQ_CENLFE) {
3092 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3093 "Center Playback Volume",
3094 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3098 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3099 "LFE Playback Volume",
3100 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3104 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3105 "Center Playback Switch",
3106 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3110 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3111 "LFE Playback Switch",
3112 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3116 } else if (i == AUTO_SEQ_FRONT) {
3117 /* add control to mixer index 0 */
3118 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3119 "Master Front Playback Volume",
3120 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3124 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3125 "Master Front Playback Switch",
3126 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3131 /* add control to PW3 */
3132 sprintf(name, "%s Playback Volume", chname[i]);
3133 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3134 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3138 sprintf(name, "%s Playback Switch", chname[i]);
3139 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3140 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3145 sprintf(name, "%s Playback Volume", chname[i]);
3146 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3147 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3151 sprintf(name, "%s Playback Switch", chname[i]);
3152 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3153 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3163 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3170 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3171 spec->hp_independent_mode_index = 1;
3173 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3174 "Headphone Playback Volume",
3175 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3178 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3179 "Headphone Playback Switch",
3180 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3184 create_hp_imux(spec);
3189 /* create playback/capture controls for input pins */
3190 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3191 const struct auto_pin_cfg *cfg)
3193 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
3196 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3198 struct via_spec *spec = codec->spec;
3201 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3204 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3207 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3208 return 0; /* can't find valid BIOS pin config */
3210 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3213 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3216 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3220 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3222 if (spec->autocfg.dig_outs)
3223 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3224 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3225 if (spec->autocfg.dig_in_pin)
3226 spec->dig_in_nid = VT1708B_DIGIN_NID;
3228 if (spec->kctls.list)
3229 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3231 spec->input_mux = &spec->private_imux[0];
3234 via_hp_build(codec);
3236 via_smart51_build(spec);
3240 #ifdef CONFIG_SND_HDA_POWER_SAVE
3241 static const struct hda_amp_list vt1708B_loopbacks[] = {
3242 { 0x16, HDA_INPUT, 1 },
3243 { 0x16, HDA_INPUT, 2 },
3244 { 0x16, HDA_INPUT, 3 },
3245 { 0x16, HDA_INPUT, 4 },
3250 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3252 struct via_spec *spec = codec->spec;
3256 if ((spec->codec_type != VT1708B_4CH) &&
3257 (codec->vendor_id != 0x11064397))
3260 /* SW0 (17h) = stereo mixer */
3262 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3263 == ((spec->codec_type == VT1708S) ? 5 : 0));
3265 /* PW 1/2/5 (1ah/1bh/1eh) */
3267 set_pin_power_state(codec, 0x1a, &parm);
3268 set_pin_power_state(codec, 0x1b, &parm);
3269 set_pin_power_state(codec, 0x1e, &parm);
3272 /* SW0 (17h), AIW 0/1 (13h/14h) */
3273 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3274 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3275 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3278 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3280 set_pin_power_state(codec, 0x19, &parm);
3281 if (spec->smart51_enabled)
3282 set_pin_power_state(codec, 0x1b, &parm);
3283 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3284 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3286 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3289 set_pin_power_state(codec, 0x22, &parm);
3290 if (spec->smart51_enabled)
3291 set_pin_power_state(codec, 0x1a, &parm);
3292 snd_hda_codec_write(codec, 0x26, 0,
3293 AC_VERB_SET_POWER_STATE, parm);
3294 snd_hda_codec_write(codec, 0x24, 0,
3295 AC_VERB_SET_POWER_STATE, parm);
3296 } else if (codec->vendor_id == 0x11064397) {
3297 /* PW7(23h), SW2(27h), AOW2(25h) */
3299 set_pin_power_state(codec, 0x23, &parm);
3300 if (spec->smart51_enabled)
3301 set_pin_power_state(codec, 0x1a, &parm);
3302 snd_hda_codec_write(codec, 0x27, 0,
3303 AC_VERB_SET_POWER_STATE, parm);
3304 snd_hda_codec_write(codec, 0x25, 0,
3305 AC_VERB_SET_POWER_STATE, parm);
3308 /* PW 3/4/7 (1ch/1dh/23h) */
3310 /* force to D0 for internal Speaker */
3311 set_pin_power_state(codec, 0x1c, &parm);
3312 set_pin_power_state(codec, 0x1d, &parm);
3314 set_pin_power_state(codec, 0x23, &parm);
3316 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3317 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3318 imux_is_smixer ? AC_PWRST_D0 : parm);
3319 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3321 snd_hda_codec_write(codec, 0x25, 0,
3322 AC_VERB_SET_POWER_STATE, parm);
3323 snd_hda_codec_write(codec, 0x27, 0,
3324 AC_VERB_SET_POWER_STATE, parm);
3325 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3326 snd_hda_codec_write(codec, 0x25, 0,
3327 AC_VERB_SET_POWER_STATE, parm);
3330 static int patch_vt1708S(struct hda_codec *codec);
3331 static int patch_vt1708B_8ch(struct hda_codec *codec)
3333 struct via_spec *spec;
3336 if (get_codec_type(codec) == VT1708BCE)
3337 return patch_vt1708S(codec);
3338 /* create a codec specific record */
3339 spec = via_new_spec(codec);
3343 /* automatic parse from the BIOS config */
3344 err = vt1708B_parse_auto_config(codec);
3349 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3350 "from BIOS. Using genenic mode...\n");
3353 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3354 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3356 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3357 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3359 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3360 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3362 if (spec->adc_nids && spec->input_mux) {
3363 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3367 codec->patch_ops = via_patch_ops;
3369 codec->patch_ops.init = via_auto_init;
3370 codec->patch_ops.unsol_event = via_unsol_event;
3371 #ifdef CONFIG_SND_HDA_POWER_SAVE
3372 spec->loopback.amplist = vt1708B_loopbacks;
3375 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3380 static int patch_vt1708B_4ch(struct hda_codec *codec)
3382 struct via_spec *spec;
3385 /* create a codec specific record */
3386 spec = via_new_spec(codec);
3390 /* automatic parse from the BIOS config */
3391 err = vt1708B_parse_auto_config(codec);
3396 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3397 "from BIOS. Using genenic mode...\n");
3400 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3401 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3403 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3404 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3406 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3407 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3409 if (spec->adc_nids && spec->input_mux) {
3410 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3414 codec->patch_ops = via_patch_ops;
3416 codec->patch_ops.init = via_auto_init;
3417 codec->patch_ops.unsol_event = via_unsol_event;
3418 #ifdef CONFIG_SND_HDA_POWER_SAVE
3419 spec->loopback.amplist = vt1708B_loopbacks;
3422 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3427 /* Patch for VT1708S */
3429 /* capture mixer elements */
3430 static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3431 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3432 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3433 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3434 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3435 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3436 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3439 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3440 /* The multiple "Capture Source" controls confuse alsamixer
3441 * So call somewhat different..
3443 /* .name = "Capture Source", */
3444 .name = "Input Source",
3446 .info = via_mux_enum_info,
3447 .get = via_mux_enum_get,
3448 .put = via_mux_enum_put,
3453 static const struct hda_verb vt1708S_volume_init_verbs[] = {
3454 /* Unmute ADC0-1 and set the default input to mic-in */
3455 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3456 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3458 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3459 * analog-loopback mixer widget */
3460 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3461 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3462 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3463 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3464 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3465 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3467 /* Setup default input of PW4 to MW0 */
3468 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3469 /* PW9, PW10 Output enable */
3470 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3471 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3472 /* Enable Mic Boost Volume backdoor */
3474 /* don't bybass mixer */
3479 static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
3480 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3481 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3482 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3483 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3484 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3485 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3486 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3487 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3488 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3492 static const struct hda_verb vt1705_uniwill_init_verbs[] = {
3493 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3494 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3495 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3496 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3497 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3498 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3499 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3500 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3504 static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3508 .nid = 0x10, /* NID to query formats and rates */
3510 .open = via_playback_pcm_open,
3511 .prepare = via_playback_multi_pcm_prepare,
3512 .cleanup = via_playback_multi_pcm_cleanup,
3513 .close = via_pcm_open_close
3517 static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
3521 .nid = 0x10, /* NID to query formats and rates */
3523 .open = via_playback_pcm_open,
3524 .prepare = via_playback_multi_pcm_prepare,
3525 .cleanup = via_playback_multi_pcm_cleanup,
3526 .close = via_pcm_open_close
3530 static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3534 .nid = 0x13, /* NID to query formats and rates */
3536 .open = via_pcm_open_close,
3537 .prepare = via_capture_pcm_prepare,
3538 .cleanup = via_capture_pcm_cleanup,
3539 .close = via_pcm_open_close
3543 static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3547 /* NID is set in via_build_pcms */
3549 .open = via_dig_playback_pcm_open,
3550 .close = via_dig_playback_pcm_close,
3551 .prepare = via_dig_playback_pcm_prepare,
3552 .cleanup = via_dig_playback_pcm_cleanup
3556 /* fill in the dac_nids table from the parsed pin configuration */
3557 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3558 const struct auto_pin_cfg *cfg)
3563 spec->multiout.num_dacs = cfg->line_outs;
3565 spec->multiout.dac_nids = spec->private_dac_nids;
3567 for (i = 0; i < 4; i++) {
3568 nid = cfg->line_out_pins[i];
3570 /* config dac list */
3572 case AUTO_SEQ_FRONT:
3573 spec->private_dac_nids[i] = 0x10;
3575 case AUTO_SEQ_CENLFE:
3576 if (spec->codec->vendor_id == 0x11064397)
3577 spec->private_dac_nids[i] = 0x25;
3579 spec->private_dac_nids[i] = 0x24;
3581 case AUTO_SEQ_SURROUND:
3582 spec->private_dac_nids[i] = 0x11;
3585 spec->private_dac_nids[i] = 0x25;
3591 /* for Smart 5.1, line/mic inputs double as output pins */
3592 if (cfg->line_outs == 1) {
3593 spec->multiout.num_dacs = 3;
3594 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3595 if (spec->codec->vendor_id == 0x11064397)
3596 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
3598 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3604 /* add playback controls from the parsed DAC table */
3605 static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
3606 const struct auto_pin_cfg *cfg)
3608 struct via_spec *spec = codec->spec;
3610 static const char * const chname[4] = {
3611 "Front", "Surround", "C/LFE", "Side"
3613 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3614 {0x10, 0x11, 0x25, 0} };
3615 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3616 {0x1C, 0x18, 0x27, 0} };
3617 hda_nid_t nid, nid_vol, nid_mute;
3620 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3621 nid = cfg->line_out_pins[i];
3623 /* for Smart 5.1, there are always at least six channels */
3624 if (!nid && i > AUTO_SEQ_CENLFE)
3627 if (codec->vendor_id == 0x11064397) {
3628 nid_vol = nid_vols[1][i];
3629 nid_mute = nid_mutes[1][i];
3631 nid_vol = nid_vols[0][i];
3632 nid_mute = nid_mutes[0][i];
3634 if (!nid_vol && !nid_mute)
3637 if (i == AUTO_SEQ_CENLFE) {
3639 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3640 "Center Playback Volume",
3641 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3645 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3646 "LFE Playback Volume",
3647 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3651 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3652 "Center Playback Switch",
3653 HDA_COMPOSE_AMP_VAL(nid_mute,
3658 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3659 "LFE Playback Switch",
3660 HDA_COMPOSE_AMP_VAL(nid_mute,
3665 } else if (i == AUTO_SEQ_FRONT) {
3666 /* add control to mixer index 0 */
3667 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3668 "Master Front Playback Volume",
3669 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3673 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3674 "Master Front Playback Switch",
3675 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3681 sprintf(name, "%s Playback Volume", chname[i]);
3682 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3683 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3687 sprintf(name, "%s Playback Switch", chname[i]);
3688 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3689 HDA_COMPOSE_AMP_VAL(nid_mute,
3695 sprintf(name, "%s Playback Volume", chname[i]);
3696 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3697 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3701 sprintf(name, "%s Playback Switch", chname[i]);
3702 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3703 HDA_COMPOSE_AMP_VAL(nid_mute,
3714 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3721 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3722 spec->hp_independent_mode_index = 1;
3724 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3725 "Headphone Playback Volume",
3726 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3730 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3731 "Headphone Playback Switch",
3732 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3736 create_hp_imux(spec);
3741 /* create playback/capture controls for input pins */
3742 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3743 const struct auto_pin_cfg *cfg)
3745 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
3748 /* fill out digital output widgets; one for master and one for slave outputs */
3749 static void fill_dig_outs(struct hda_codec *codec)
3751 struct via_spec *spec = codec->spec;
3754 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3758 nid = spec->autocfg.dig_out_pins[i];
3761 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3764 if (!spec->multiout.dig_out_nid)
3765 spec->multiout.dig_out_nid = nid;
3767 spec->slave_dig_outs[0] = nid;
3768 break; /* at most two dig outs */
3773 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3775 struct via_spec *spec = codec->spec;
3778 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3781 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3784 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3785 return 0; /* can't find valid BIOS pin config */
3787 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
3790 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3793 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
3797 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3799 fill_dig_outs(codec);
3801 if (spec->kctls.list)
3802 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3804 spec->input_mux = &spec->private_imux[0];
3807 via_hp_build(codec);
3809 via_smart51_build(spec);
3813 #ifdef CONFIG_SND_HDA_POWER_SAVE
3814 static const struct hda_amp_list vt1708S_loopbacks[] = {
3815 { 0x16, HDA_INPUT, 1 },
3816 { 0x16, HDA_INPUT, 2 },
3817 { 0x16, HDA_INPUT, 3 },
3818 { 0x16, HDA_INPUT, 4 },
3823 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3824 int offset, int num_steps, int step_size)
3826 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3827 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3828 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3829 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3830 (0 << AC_AMPCAP_MUTE_SHIFT));
3833 static int patch_vt1708S(struct hda_codec *codec)
3835 struct via_spec *spec;
3838 /* create a codec specific record */
3839 spec = via_new_spec(codec);
3843 /* automatic parse from the BIOS config */
3844 err = vt1708S_parse_auto_config(codec);
3849 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3850 "from BIOS. Using genenic mode...\n");
3853 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3854 if (codec->vendor_id == 0x11064397)
3855 spec->init_verbs[spec->num_iverbs++] =
3856 vt1705_uniwill_init_verbs;
3858 spec->init_verbs[spec->num_iverbs++] =
3859 vt1708S_uniwill_init_verbs;
3861 if (codec->vendor_id == 0x11064397)
3862 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3864 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
3865 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3867 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3869 if (spec->adc_nids && spec->input_mux) {
3870 override_mic_boost(codec, 0x1a, 0, 3, 40);
3871 override_mic_boost(codec, 0x1e, 0, 3, 40);
3872 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3876 codec->patch_ops = via_patch_ops;
3878 codec->patch_ops.init = via_auto_init;
3879 codec->patch_ops.unsol_event = via_unsol_event;
3880 #ifdef CONFIG_SND_HDA_POWER_SAVE
3881 spec->loopback.amplist = vt1708S_loopbacks;
3884 /* correct names for VT1708BCE */
3885 if (get_codec_type(codec) == VT1708BCE) {
3886 kfree(codec->chip_name);
3887 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3888 snprintf(codec->bus->card->mixername,
3889 sizeof(codec->bus->card->mixername),
3890 "%s %s", codec->vendor_name, codec->chip_name);
3892 /* correct names for VT1705 */
3893 if (codec->vendor_id == 0x11064397) {
3894 kfree(codec->chip_name);
3895 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3896 snprintf(codec->bus->card->mixername,
3897 sizeof(codec->bus->card->mixername),
3898 "%s %s", codec->vendor_name, codec->chip_name);
3900 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3904 /* Patch for VT1702 */
3906 /* capture mixer elements */
3907 static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
3908 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3909 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3910 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3911 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3912 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3913 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3914 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3917 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3918 /* The multiple "Capture Source" controls confuse alsamixer
3919 * So call somewhat different..
3921 /* .name = "Capture Source", */
3922 .name = "Input Source",
3924 .info = via_mux_enum_info,
3925 .get = via_mux_enum_get,
3926 .put = via_mux_enum_put,
3931 static const struct hda_verb vt1702_volume_init_verbs[] = {
3933 * Unmute ADC0-1 and set the default input to mic-in
3935 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3936 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3937 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3940 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3943 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3944 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3945 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3946 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3947 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3948 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3950 /* Setup default input of PW4 to MW0 */
3951 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3952 /* PW6 PW7 Output enable */
3953 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3954 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3962 static const struct hda_verb vt1702_uniwill_init_verbs[] = {
3963 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3964 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3965 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3966 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3967 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3968 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3972 static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
3976 .nid = 0x10, /* NID to query formats and rates */
3978 .open = via_playback_pcm_open,
3979 .prepare = via_playback_multi_pcm_prepare,
3980 .cleanup = via_playback_multi_pcm_cleanup,
3981 .close = via_pcm_open_close
3985 static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
3989 .nid = 0x12, /* NID to query formats and rates */
3991 .open = via_pcm_open_close,
3992 .prepare = via_capture_pcm_prepare,
3993 .cleanup = via_capture_pcm_cleanup,
3994 .close = via_pcm_open_close
3998 static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
4002 /* NID is set in via_build_pcms */
4004 .open = via_dig_playback_pcm_open,
4005 .close = via_dig_playback_pcm_close,
4006 .prepare = via_dig_playback_pcm_prepare,
4007 .cleanup = via_dig_playback_pcm_cleanup
4011 /* fill in the dac_nids table from the parsed pin configuration */
4012 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4013 const struct auto_pin_cfg *cfg)
4015 spec->multiout.num_dacs = 1;
4016 spec->multiout.dac_nids = spec->private_dac_nids;
4018 if (cfg->line_out_pins[0]) {
4019 /* config dac list */
4020 spec->private_dac_nids[0] = 0x10;
4026 /* add playback controls from the parsed DAC table */
4027 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4028 const struct auto_pin_cfg *cfg)
4032 if (!cfg->line_out_pins[0])
4035 /* add control to mixer index 0 */
4036 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4037 "Master Front Playback Volume",
4038 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4041 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4042 "Master Front Playback Switch",
4043 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4048 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4049 "Front Playback Volume",
4050 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4053 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4054 "Front Playback Switch",
4055 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4062 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4065 struct hda_input_mux *imux;
4066 static const char * const texts[] = { "ON", "OFF", NULL};
4069 spec->multiout.hp_nid = 0x1D;
4070 spec->hp_independent_mode_index = 0;
4072 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4073 "Headphone Playback Volume",
4074 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4078 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4079 "Headphone Playback Switch",
4080 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4084 imux = &spec->private_imux[1];
4086 /* for hp mode select */
4087 for (i = 0; texts[i]; i++)
4088 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4090 spec->hp_mux = &spec->private_imux[1];
4094 /* create playback/capture controls for input pins */
4095 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4096 const struct auto_pin_cfg *cfg)
4098 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a);
4101 static int vt1702_parse_auto_config(struct hda_codec *codec)
4103 struct via_spec *spec = codec->spec;
4106 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4109 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4112 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4113 return 0; /* can't find valid BIOS pin config */
4115 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4118 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4121 /* limit AA path volume to 0 dB */
4122 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4123 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4124 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4125 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4126 (1 << AC_AMPCAP_MUTE_SHIFT));
4127 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4131 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4133 fill_dig_outs(codec);
4135 if (spec->kctls.list)
4136 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4138 spec->input_mux = &spec->private_imux[0];
4141 via_hp_build(codec);
4146 #ifdef CONFIG_SND_HDA_POWER_SAVE
4147 static const struct hda_amp_list vt1702_loopbacks[] = {
4148 { 0x1A, HDA_INPUT, 1 },
4149 { 0x1A, HDA_INPUT, 2 },
4150 { 0x1A, HDA_INPUT, 3 },
4151 { 0x1A, HDA_INPUT, 4 },
4156 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4158 int imux_is_smixer =
4159 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4162 /* PW 1/2/5 (14h/15h/18h) */
4164 set_pin_power_state(codec, 0x14, &parm);
4165 set_pin_power_state(codec, 0x15, &parm);
4166 set_pin_power_state(codec, 0x18, &parm);
4168 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4169 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4170 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4171 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4172 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4173 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4176 /* PW 3/4 (16h/17h) */
4178 set_pin_power_state(codec, 0x17, &parm);
4179 set_pin_power_state(codec, 0x16, &parm);
4180 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4181 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4182 imux_is_smixer ? AC_PWRST_D0 : parm);
4183 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4184 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4187 static int patch_vt1702(struct hda_codec *codec)
4189 struct via_spec *spec;
4192 /* create a codec specific record */
4193 spec = via_new_spec(codec);
4197 /* automatic parse from the BIOS config */
4198 err = vt1702_parse_auto_config(codec);
4203 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4204 "from BIOS. Using genenic mode...\n");
4207 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4208 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4210 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4211 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4213 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4215 if (spec->adc_nids && spec->input_mux) {
4216 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4220 codec->patch_ops = via_patch_ops;
4222 codec->patch_ops.init = via_auto_init;
4223 codec->patch_ops.unsol_event = via_unsol_event;
4224 #ifdef CONFIG_SND_HDA_POWER_SAVE
4225 spec->loopback.amplist = vt1702_loopbacks;
4228 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
4232 /* Patch for VT1718S */
4234 /* capture mixer elements */
4235 static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4236 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4237 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4238 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4239 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4240 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4241 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4245 /* The multiple "Capture Source" controls confuse alsamixer
4246 * So call somewhat different..
4248 .name = "Input Source",
4250 .info = via_mux_enum_info,
4251 .get = via_mux_enum_get,
4252 .put = via_mux_enum_put,
4257 static const struct hda_verb vt1718S_volume_init_verbs[] = {
4259 * Unmute ADC0-1 and set the default input to mic-in
4261 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4262 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4264 /* Enable MW0 adjust Gain 5 */
4266 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4269 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4270 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4271 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4272 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4273 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4274 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
4276 /* Setup default input of Front HP to MW9 */
4277 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4278 /* PW9 PW10 Output enable */
4279 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4280 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4281 /* PW11 Input enable */
4282 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4283 /* Enable Boost Volume backdoor */
4285 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4286 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4287 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4288 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4289 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4290 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4291 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4292 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4293 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4294 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4295 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4296 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4297 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4298 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4299 /* Unmute MW4's index 0 */
4300 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4305 static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
4306 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4307 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4308 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4309 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4310 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4311 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4312 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4313 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4314 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4318 static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4322 .nid = 0x8, /* NID to query formats and rates */
4324 .open = via_playback_pcm_open,
4325 .prepare = via_playback_multi_pcm_prepare,
4326 .cleanup = via_playback_multi_pcm_cleanup,
4327 .close = via_pcm_open_close,
4331 static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4335 .nid = 0x10, /* NID to query formats and rates */
4337 .open = via_pcm_open_close,
4338 .prepare = via_capture_pcm_prepare,
4339 .cleanup = via_capture_pcm_cleanup,
4340 .close = via_pcm_open_close,
4344 static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4348 /* NID is set in via_build_pcms */
4350 .open = via_dig_playback_pcm_open,
4351 .close = via_dig_playback_pcm_close,
4352 .prepare = via_dig_playback_pcm_prepare,
4353 .cleanup = via_dig_playback_pcm_cleanup
4357 static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4363 /* fill in the dac_nids table from the parsed pin configuration */
4364 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4365 const struct auto_pin_cfg *cfg)
4370 spec->multiout.num_dacs = cfg->line_outs;
4372 spec->multiout.dac_nids = spec->private_dac_nids;
4374 for (i = 0; i < 4; i++) {
4375 nid = cfg->line_out_pins[i];
4377 /* config dac list */
4379 case AUTO_SEQ_FRONT:
4380 spec->private_dac_nids[i] = 0x8;
4382 case AUTO_SEQ_CENLFE:
4383 spec->private_dac_nids[i] = 0xa;
4385 case AUTO_SEQ_SURROUND:
4386 spec->private_dac_nids[i] = 0x9;
4389 spec->private_dac_nids[i] = 0xb;
4398 /* add playback controls from the parsed DAC table */
4399 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4400 const struct auto_pin_cfg *cfg)
4403 static const char * const chname[4] = {
4404 "Front", "Surround", "C/LFE", "Side"
4406 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4407 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4408 hda_nid_t nid, nid_vol, nid_mute = 0;
4411 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4412 nid = cfg->line_out_pins[i];
4416 nid_vol = nid_vols[i];
4417 nid_mute = nid_mutes[i];
4419 if (i == AUTO_SEQ_CENLFE) {
4421 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4422 "Center Playback Volume",
4423 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4427 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4428 "LFE Playback Volume",
4429 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4433 err = via_add_control(
4434 spec, VIA_CTL_WIDGET_MUTE,
4435 "Center Playback Switch",
4436 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4440 err = via_add_control(
4441 spec, VIA_CTL_WIDGET_MUTE,
4442 "LFE Playback Switch",
4443 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4447 } else if (i == AUTO_SEQ_FRONT) {
4449 sprintf(name, "%s Playback Volume", chname[i]);
4450 err = via_add_control(
4451 spec, VIA_CTL_WIDGET_VOL, name,
4452 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4455 sprintf(name, "%s Playback Switch", chname[i]);
4456 err = via_add_control(
4457 spec, VIA_CTL_WIDGET_MUTE, name,
4458 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4463 sprintf(name, "%s Playback Volume", chname[i]);
4464 err = via_add_control(
4465 spec, VIA_CTL_WIDGET_VOL, name,
4466 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4469 sprintf(name, "%s Playback Switch", chname[i]);
4470 err = via_add_control(
4471 spec, VIA_CTL_WIDGET_MUTE, name,
4472 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4481 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4488 spec->multiout.hp_nid = 0xc; /* AOW4 */
4489 spec->hp_independent_mode_index = 1;
4491 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4492 "Headphone Playback Volume",
4493 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4497 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4498 "Headphone Playback Switch",
4499 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4503 create_hp_imux(spec);
4507 /* create playback/capture controls for input pins */
4508 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4509 const struct auto_pin_cfg *cfg)
4511 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
4514 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4516 struct via_spec *spec = codec->spec;
4519 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4523 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4526 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4527 return 0; /* can't find valid BIOS pin config */
4529 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4532 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4535 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4539 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4541 fill_dig_outs(codec);
4543 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4544 spec->dig_in_nid = 0x13;
4546 if (spec->kctls.list)
4547 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4549 spec->input_mux = &spec->private_imux[0];
4552 via_hp_build(codec);
4554 via_smart51_build(spec);
4559 #ifdef CONFIG_SND_HDA_POWER_SAVE
4560 static const struct hda_amp_list vt1718S_loopbacks[] = {
4561 { 0x21, HDA_INPUT, 1 },
4562 { 0x21, HDA_INPUT, 2 },
4563 { 0x21, HDA_INPUT, 3 },
4564 { 0x21, HDA_INPUT, 4 },
4569 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4571 struct via_spec *spec = codec->spec;
4574 /* MUX6 (1eh) = stereo mixer */
4576 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4578 /* PW 5/6/7 (29h/2ah/2bh) */
4580 set_pin_power_state(codec, 0x29, &parm);
4581 set_pin_power_state(codec, 0x2a, &parm);
4582 set_pin_power_state(codec, 0x2b, &parm);
4585 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4586 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4587 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4588 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4589 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4592 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4594 set_pin_power_state(codec, 0x27, &parm);
4595 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4596 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4598 /* PW2 (26h), AOW2 (ah) */
4600 set_pin_power_state(codec, 0x26, &parm);
4601 if (spec->smart51_enabled)
4602 set_pin_power_state(codec, 0x2b, &parm);
4603 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4605 /* PW0 (24h), AOW0 (8h) */
4607 set_pin_power_state(codec, 0x24, &parm);
4608 if (!spec->hp_independent_mode) /* check for redirected HP */
4609 set_pin_power_state(codec, 0x28, &parm);
4610 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4611 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4612 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4613 imux_is_smixer ? AC_PWRST_D0 : parm);
4615 /* PW1 (25h), AOW1 (9h) */
4617 set_pin_power_state(codec, 0x25, &parm);
4618 if (spec->smart51_enabled)
4619 set_pin_power_state(codec, 0x2a, &parm);
4620 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4622 if (spec->hp_independent_mode) {
4623 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4625 set_pin_power_state(codec, 0x28, &parm);
4626 snd_hda_codec_write(codec, 0x1b, 0,
4627 AC_VERB_SET_POWER_STATE, parm);
4628 snd_hda_codec_write(codec, 0x34, 0,
4629 AC_VERB_SET_POWER_STATE, parm);
4630 snd_hda_codec_write(codec, 0xc, 0,
4631 AC_VERB_SET_POWER_STATE, parm);
4635 static int patch_vt1718S(struct hda_codec *codec)
4637 struct via_spec *spec;
4640 /* create a codec specific record */
4641 spec = via_new_spec(codec);
4645 /* automatic parse from the BIOS config */
4646 err = vt1718S_parse_auto_config(codec);
4651 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4652 "from BIOS. Using genenic mode...\n");
4655 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4656 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4658 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4659 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4661 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4662 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4663 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4665 if (spec->adc_nids && spec->input_mux) {
4666 override_mic_boost(codec, 0x2b, 0, 3, 40);
4667 override_mic_boost(codec, 0x29, 0, 3, 40);
4668 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4672 codec->patch_ops = via_patch_ops;
4674 codec->patch_ops.init = via_auto_init;
4675 codec->patch_ops.unsol_event = via_unsol_event;
4677 #ifdef CONFIG_SND_HDA_POWER_SAVE
4678 spec->loopback.amplist = vt1718S_loopbacks;
4681 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4686 /* Patch for VT1716S */
4688 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4689 struct snd_ctl_elem_info *uinfo)
4691 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4693 uinfo->value.integer.min = 0;
4694 uinfo->value.integer.max = 1;
4698 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4699 struct snd_ctl_elem_value *ucontrol)
4701 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4704 index = snd_hda_codec_read(codec, 0x26, 0,
4705 AC_VERB_GET_CONNECT_SEL, 0);
4707 *ucontrol->value.integer.value = index;
4712 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4713 struct snd_ctl_elem_value *ucontrol)
4715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4716 struct via_spec *spec = codec->spec;
4717 int index = *ucontrol->value.integer.value;
4719 snd_hda_codec_write(codec, 0x26, 0,
4720 AC_VERB_SET_CONNECT_SEL, index);
4721 spec->dmic_enabled = index;
4722 set_widgets_power_state(codec);
4726 /* capture mixer elements */
4727 static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4728 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4729 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4730 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4731 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4732 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4733 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4736 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4737 .name = "Input Source",
4739 .info = via_mux_enum_info,
4740 .get = via_mux_enum_get,
4741 .put = via_mux_enum_put,
4746 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4747 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4749 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4750 .name = "Digital Mic Capture Switch",
4751 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4753 .info = vt1716s_dmic_info,
4754 .get = vt1716s_dmic_get,
4755 .put = vt1716s_dmic_put,
4761 /* mono-out mixer elements */
4762 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4763 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4767 static const struct hda_verb vt1716S_volume_init_verbs[] = {
4769 * Unmute ADC0-1 and set the default input to mic-in
4771 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4772 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4775 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4778 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4779 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4780 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4781 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4782 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4783 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4785 /* MUX Indices: Stereo Mixer = 5 */
4786 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4788 /* Setup default input of PW4 to MW0 */
4789 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4791 /* Setup default input of SW1 as MW0 */
4792 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4794 /* Setup default input of SW4 as AOW0 */
4795 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4797 /* PW9 PW10 Output enable */
4798 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4799 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4801 /* Unmute SW1, PW12 */
4802 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4803 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4804 /* PW12 Output enable */
4805 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4806 /* Enable Boost Volume backdoor */
4808 /* don't bybass mixer */
4810 /* Enable mono output */
4816 static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
4817 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4818 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4819 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4820 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4821 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4822 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4823 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4824 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4825 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4829 static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4833 .nid = 0x10, /* NID to query formats and rates */
4835 .open = via_playback_pcm_open,
4836 .prepare = via_playback_multi_pcm_prepare,
4837 .cleanup = via_playback_multi_pcm_cleanup,
4838 .close = via_pcm_open_close,
4842 static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
4846 .nid = 0x13, /* NID to query formats and rates */
4848 .open = via_pcm_open_close,
4849 .prepare = via_capture_pcm_prepare,
4850 .cleanup = via_capture_pcm_cleanup,
4851 .close = via_pcm_open_close,
4855 static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
4859 /* NID is set in via_build_pcms */
4861 .open = via_dig_playback_pcm_open,
4862 .close = via_dig_playback_pcm_close,
4863 .prepare = via_dig_playback_pcm_prepare,
4864 .cleanup = via_dig_playback_pcm_cleanup
4868 /* fill in the dac_nids table from the parsed pin configuration */
4869 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4870 const struct auto_pin_cfg *cfg)
4874 spec->multiout.num_dacs = cfg->line_outs;
4876 spec->multiout.dac_nids = spec->private_dac_nids;
4878 for (i = 0; i < 3; i++) {
4879 nid = cfg->line_out_pins[i];
4881 /* config dac list */
4883 case AUTO_SEQ_FRONT:
4884 spec->private_dac_nids[i] = 0x10;
4886 case AUTO_SEQ_CENLFE:
4887 spec->private_dac_nids[i] = 0x25;
4889 case AUTO_SEQ_SURROUND:
4890 spec->private_dac_nids[i] = 0x11;
4899 /* add playback controls from the parsed DAC table */
4900 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4901 const struct auto_pin_cfg *cfg)
4904 static const char * const chname[3] = {
4905 "Front", "Surround", "C/LFE"
4907 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4908 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4909 hda_nid_t nid, nid_vol, nid_mute;
4912 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4913 nid = cfg->line_out_pins[i];
4918 nid_vol = nid_vols[i];
4919 nid_mute = nid_mutes[i];
4921 if (i == AUTO_SEQ_CENLFE) {
4922 err = via_add_control(
4923 spec, VIA_CTL_WIDGET_VOL,
4924 "Center Playback Volume",
4925 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4928 err = via_add_control(
4929 spec, VIA_CTL_WIDGET_VOL,
4930 "LFE Playback Volume",
4931 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4934 err = via_add_control(
4935 spec, VIA_CTL_WIDGET_MUTE,
4936 "Center Playback Switch",
4937 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4941 err = via_add_control(
4942 spec, VIA_CTL_WIDGET_MUTE,
4943 "LFE Playback Switch",
4944 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4948 } else if (i == AUTO_SEQ_FRONT) {
4950 err = via_add_control(
4951 spec, VIA_CTL_WIDGET_VOL,
4952 "Master Front Playback Volume",
4953 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4956 err = via_add_control(
4957 spec, VIA_CTL_WIDGET_MUTE,
4958 "Master Front Playback Switch",
4959 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4963 sprintf(name, "%s Playback Volume", chname[i]);
4964 err = via_add_control(
4965 spec, VIA_CTL_WIDGET_VOL, name,
4966 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4969 sprintf(name, "%s Playback Switch", chname[i]);
4970 err = via_add_control(
4971 spec, VIA_CTL_WIDGET_MUTE, name,
4972 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4977 sprintf(name, "%s Playback Volume", chname[i]);
4978 err = via_add_control(
4979 spec, VIA_CTL_WIDGET_VOL, name,
4980 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4983 sprintf(name, "%s Playback Switch", chname[i]);
4984 err = via_add_control(
4985 spec, VIA_CTL_WIDGET_MUTE, name,
4986 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4995 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5002 spec->multiout.hp_nid = 0x25; /* AOW3 */
5003 spec->hp_independent_mode_index = 1;
5005 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5006 "Headphone Playback Volume",
5007 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5011 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5012 "Headphone Playback Switch",
5013 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5017 create_hp_imux(spec);
5021 /* create playback/capture controls for input pins */
5022 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5023 const struct auto_pin_cfg *cfg)
5025 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
5028 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5030 struct via_spec *spec = codec->spec;
5033 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5036 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5039 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5040 return 0; /* can't find valid BIOS pin config */
5042 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5045 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5048 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5052 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5054 fill_dig_outs(codec);
5056 if (spec->kctls.list)
5057 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5059 spec->input_mux = &spec->private_imux[0];
5062 via_hp_build(codec);
5064 via_smart51_build(spec);
5069 #ifdef CONFIG_SND_HDA_POWER_SAVE
5070 static const struct hda_amp_list vt1716S_loopbacks[] = {
5071 { 0x16, HDA_INPUT, 1 },
5072 { 0x16, HDA_INPUT, 2 },
5073 { 0x16, HDA_INPUT, 3 },
5074 { 0x16, HDA_INPUT, 4 },
5079 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5081 struct via_spec *spec = codec->spec;
5084 unsigned int mono_out, present;
5085 /* SW0 (17h) = stereo mixer */
5087 (snd_hda_codec_read(codec, 0x17, 0,
5088 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5090 /* PW 1/2/5 (1ah/1bh/1eh) */
5092 set_pin_power_state(codec, 0x1a, &parm);
5093 set_pin_power_state(codec, 0x1b, &parm);
5094 set_pin_power_state(codec, 0x1e, &parm);
5097 /* SW0 (17h), AIW0(13h) */
5098 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5099 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5102 set_pin_power_state(codec, 0x1e, &parm);
5104 if (spec->dmic_enabled)
5105 set_pin_power_state(codec, 0x22, &parm);
5107 snd_hda_codec_write(codec, 0x22, 0,
5108 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5110 /* SW2(26h), AIW1(14h) */
5111 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5112 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5115 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5117 set_pin_power_state(codec, 0x19, &parm);
5118 /* Smart 5.1 PW2(1bh) */
5119 if (spec->smart51_enabled)
5120 set_pin_power_state(codec, 0x1b, &parm);
5121 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5122 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5124 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5126 set_pin_power_state(codec, 0x23, &parm);
5127 /* Smart 5.1 PW1(1ah) */
5128 if (spec->smart51_enabled)
5129 set_pin_power_state(codec, 0x1a, &parm);
5130 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5132 /* Smart 5.1 PW5(1eh) */
5133 if (spec->smart51_enabled)
5134 set_pin_power_state(codec, 0x1e, &parm);
5135 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5138 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5139 present = snd_hda_jack_detect(codec, 0x1c);
5144 present = snd_hda_jack_detect(codec, 0x1d);
5145 if (!spec->hp_independent_mode && present)
5150 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5151 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5152 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5153 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5155 /* PW 3/4 (1ch/1dh) */
5157 set_pin_power_state(codec, 0x1c, &parm);
5158 set_pin_power_state(codec, 0x1d, &parm);
5159 /* HP Independent Mode, power on AOW3 */
5160 if (spec->hp_independent_mode)
5161 snd_hda_codec_write(codec, 0x25, 0,
5162 AC_VERB_SET_POWER_STATE, parm);
5164 /* force to D0 for internal Speaker */
5165 /* MW0 (16h), AOW0 (10h) */
5166 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5167 imux_is_smixer ? AC_PWRST_D0 : parm);
5168 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5169 mono_out ? AC_PWRST_D0 : parm);
5172 static int patch_vt1716S(struct hda_codec *codec)
5174 struct via_spec *spec;
5177 /* create a codec specific record */
5178 spec = via_new_spec(codec);
5182 /* automatic parse from the BIOS config */
5183 err = vt1716S_parse_auto_config(codec);
5188 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5189 "from BIOS. Using genenic mode...\n");
5192 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5193 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5195 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5196 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5198 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5200 if (spec->adc_nids && spec->input_mux) {
5201 override_mic_boost(codec, 0x1a, 0, 3, 40);
5202 override_mic_boost(codec, 0x1e, 0, 3, 40);
5203 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5207 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5210 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5212 codec->patch_ops = via_patch_ops;
5214 codec->patch_ops.init = via_auto_init;
5215 codec->patch_ops.unsol_event = via_unsol_event;
5217 #ifdef CONFIG_SND_HDA_POWER_SAVE
5218 spec->loopback.amplist = vt1716S_loopbacks;
5221 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
5227 /* capture mixer elements */
5228 static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5229 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5230 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5231 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5232 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5233 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5234 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5238 /* The multiple "Capture Source" controls confuse alsamixer
5239 * So call somewhat different..
5241 /* .name = "Capture Source", */
5242 .name = "Input Source",
5244 .info = via_mux_enum_info,
5245 .get = via_mux_enum_get,
5246 .put = via_mux_enum_put,
5251 static const struct hda_verb vt2002P_volume_init_verbs[] = {
5252 /* Class-D speaker related verbs */
5257 * Unmute ADC0-1 and set the default input to mic-in
5259 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5260 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5263 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5266 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5267 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5268 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5269 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5270 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5271 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5273 /* MUX Indices: Mic = 0 */
5274 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5275 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5277 /* PW9 Output enable */
5278 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5280 /* Enable Boost Volume backdoor */
5283 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5284 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5285 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5286 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5287 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5288 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5289 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5290 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5291 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5293 /* set MUX0/1/4/8 = 0 (AOW0) */
5294 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5295 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5296 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5297 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5299 /* set PW0 index=0 (MW0) */
5300 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5302 /* Enable AOW0 to MW9 */
5306 static const struct hda_verb vt1802_volume_init_verbs[] = {
5308 * Unmute ADC0-1 and set the default input to mic-in
5310 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5311 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5314 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5317 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5318 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5319 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5320 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5321 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5322 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5324 /* MUX Indices: Mic = 0 */
5325 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5326 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5328 /* PW9 Output enable */
5329 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5331 /* Enable Boost Volume backdoor */
5334 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5335 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5336 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5337 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5338 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5339 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5340 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5341 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5342 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5344 /* set MUX0/1/4/8 = 0 (AOW0) */
5345 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5346 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5347 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5348 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5350 /* set PW0 index=0 (MW0) */
5351 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5353 /* Enable AOW0 to MW9 */
5359 static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
5360 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5361 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5362 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5363 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5364 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5365 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5366 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5369 static const struct hda_verb vt1802_uniwill_init_verbs[] = {
5370 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5371 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5372 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5373 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5374 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5375 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5376 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5380 static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5384 .nid = 0x8, /* NID to query formats and rates */
5386 .open = via_playback_pcm_open,
5387 .prepare = via_playback_multi_pcm_prepare,
5388 .cleanup = via_playback_multi_pcm_cleanup,
5389 .close = via_pcm_open_close,
5393 static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5397 .nid = 0x10, /* NID to query formats and rates */
5399 .open = via_pcm_open_close,
5400 .prepare = via_capture_pcm_prepare,
5401 .cleanup = via_capture_pcm_cleanup,
5402 .close = via_pcm_open_close,
5406 static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5410 /* NID is set in via_build_pcms */
5412 .open = via_dig_playback_pcm_open,
5413 .close = via_dig_playback_pcm_close,
5414 .prepare = via_dig_playback_pcm_prepare,
5415 .cleanup = via_dig_playback_pcm_cleanup
5419 /* fill in the dac_nids table from the parsed pin configuration */
5420 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5421 const struct auto_pin_cfg *cfg)
5423 spec->multiout.num_dacs = 1;
5424 spec->multiout.dac_nids = spec->private_dac_nids;
5425 if (cfg->line_out_pins[0])
5426 spec->private_dac_nids[0] = 0x8;
5430 /* add playback controls from the parsed DAC table */
5431 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5432 const struct auto_pin_cfg *cfg)
5437 if (!cfg->line_out_pins[0])
5440 if (spec->codec_type == VT1802)
5445 /* Line-Out: PortE */
5446 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5447 "Master Front Playback Volume",
5448 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5451 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5452 "Master Front Playback Switch",
5453 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
5460 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5467 spec->multiout.hp_nid = 0x9;
5468 spec->hp_independent_mode_index = 1;
5470 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5471 "Headphone Playback Volume",
5472 HDA_COMPOSE_AMP_VAL(
5473 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5477 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5478 "Headphone Playback Switch",
5479 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5483 create_hp_imux(spec);
5487 /* create playback/capture controls for input pins */
5488 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5489 const struct auto_pin_cfg *cfg)
5491 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
5494 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5496 struct via_spec *spec = codec->spec;
5500 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5504 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5508 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5509 return 0; /* can't find valid BIOS pin config */
5511 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5514 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5517 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5521 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5523 fill_dig_outs(codec);
5525 if (spec->kctls.list)
5526 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5528 spec->input_mux = &spec->private_imux[0];
5531 via_hp_build(codec);
5536 #ifdef CONFIG_SND_HDA_POWER_SAVE
5537 static const struct hda_amp_list vt2002P_loopbacks[] = {
5538 { 0x21, HDA_INPUT, 0 },
5539 { 0x21, HDA_INPUT, 1 },
5540 { 0x21, HDA_INPUT, 2 },
5545 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5547 struct via_spec *spec = codec->spec;
5550 unsigned int present;
5551 /* MUX9 (1eh) = stereo mixer */
5553 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5555 /* PW 5/6/7 (29h/2ah/2bh) */
5557 set_pin_power_state(codec, 0x29, &parm);
5558 set_pin_power_state(codec, 0x2a, &parm);
5559 set_pin_power_state(codec, 0x2b, &parm);
5561 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5562 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5563 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5564 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5565 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5569 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5571 if (spec->codec_type == VT1802) {
5572 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5574 set_pin_power_state(codec, 0x28, &parm);
5575 snd_hda_codec_write(codec, 0x18, 0,
5576 AC_VERB_SET_POWER_STATE, parm);
5577 snd_hda_codec_write(codec, 0x38, 0,
5578 AC_VERB_SET_POWER_STATE, parm);
5580 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5582 set_pin_power_state(codec, 0x26, &parm);
5583 snd_hda_codec_write(codec, 0x1c, 0,
5584 AC_VERB_SET_POWER_STATE, parm);
5585 snd_hda_codec_write(codec, 0x37, 0,
5586 AC_VERB_SET_POWER_STATE, parm);
5589 if (spec->codec_type == VT1802) {
5590 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5592 set_pin_power_state(codec, 0x25, &parm);
5593 snd_hda_codec_write(codec, 0x15, 0,
5594 AC_VERB_SET_POWER_STATE, parm);
5595 snd_hda_codec_write(codec, 0x35, 0,
5596 AC_VERB_SET_POWER_STATE, parm);
5598 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5600 set_pin_power_state(codec, 0x25, &parm);
5601 snd_hda_codec_write(codec, 0x19, 0,
5602 AC_VERB_SET_POWER_STATE, parm);
5603 snd_hda_codec_write(codec, 0x35, 0,
5604 AC_VERB_SET_POWER_STATE, parm);
5607 if (spec->hp_independent_mode)
5608 snd_hda_codec_write(codec, 0x9, 0,
5609 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5612 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5613 present = snd_hda_jack_detect(codec, 0x25);
5616 set_pin_power_state(codec, 0x24, &parm);
5617 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5618 if (spec->codec_type == VT1802)
5619 snd_hda_codec_write(codec, 0x14, 0,
5620 AC_VERB_SET_POWER_STATE, parm);
5622 snd_hda_codec_write(codec, 0x18, 0,
5623 AC_VERB_SET_POWER_STATE, parm);
5624 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5627 present = snd_hda_jack_detect(codec, 0x26);
5629 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5630 if (spec->codec_type == VT1802) {
5631 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5632 snd_hda_codec_write(codec, 0x33, 0,
5633 AC_VERB_SET_POWER_STATE, parm);
5634 snd_hda_codec_write(codec, 0x1c, 0,
5635 AC_VERB_SET_POWER_STATE, parm);
5636 snd_hda_codec_write(codec, 0x3c, 0,
5637 AC_VERB_SET_POWER_STATE, parm);
5639 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5640 snd_hda_codec_write(codec, 0x31, 0,
5641 AC_VERB_SET_POWER_STATE, parm);
5642 snd_hda_codec_write(codec, 0x17, 0,
5643 AC_VERB_SET_POWER_STATE, parm);
5644 snd_hda_codec_write(codec, 0x3b, 0,
5645 AC_VERB_SET_POWER_STATE, parm);
5648 if (imux_is_smixer || !is_aa_path_mute(codec))
5649 snd_hda_codec_write(codec, 0x21, 0,
5650 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5652 snd_hda_codec_write(codec, 0x21, 0,
5653 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5656 /* patch for vt2002P */
5657 static int patch_vt2002P(struct hda_codec *codec)
5659 struct via_spec *spec;
5662 /* create a codec specific record */
5663 spec = via_new_spec(codec);
5667 /* automatic parse from the BIOS config */
5668 err = vt2002P_parse_auto_config(codec);
5673 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5674 "from BIOS. Using genenic mode...\n");
5677 if (spec->codec_type == VT1802)
5678 spec->init_verbs[spec->num_iverbs++] =
5679 vt1802_volume_init_verbs;
5681 spec->init_verbs[spec->num_iverbs++] =
5682 vt2002P_volume_init_verbs;
5684 if (spec->codec_type == VT1802)
5685 spec->init_verbs[spec->num_iverbs++] =
5686 vt1802_uniwill_init_verbs;
5688 spec->init_verbs[spec->num_iverbs++] =
5689 vt2002P_uniwill_init_verbs;
5691 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5692 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5694 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5696 if (spec->adc_nids && spec->input_mux) {
5697 override_mic_boost(codec, 0x2b, 0, 3, 40);
5698 override_mic_boost(codec, 0x29, 0, 3, 40);
5699 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5703 codec->patch_ops = via_patch_ops;
5705 codec->patch_ops.init = via_auto_init;
5706 codec->patch_ops.unsol_event = via_unsol_event;
5708 #ifdef CONFIG_SND_HDA_POWER_SAVE
5709 spec->loopback.amplist = vt2002P_loopbacks;
5712 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
5718 /* capture mixer elements */
5719 static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
5720 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5721 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5722 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5723 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5724 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5725 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5728 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5729 /* The multiple "Capture Source" controls confuse alsamixer
5730 * So call somewhat different..
5732 .name = "Input Source",
5734 .info = via_mux_enum_info,
5735 .get = via_mux_enum_get,
5736 .put = via_mux_enum_put,
5741 static const struct hda_verb vt1812_volume_init_verbs[] = {
5743 * Unmute ADC0-1 and set the default input to mic-in
5745 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5746 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5749 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5752 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5753 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5754 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5755 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5756 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5757 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5759 /* MUX Indices: Mic = 0 */
5760 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5761 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5763 /* PW9 Output enable */
5764 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5766 /* Enable Boost Volume backdoor */
5769 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5770 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5771 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5772 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5773 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5774 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5775 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5776 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5777 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5778 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5779 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5781 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5782 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5783 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5784 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5785 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5786 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5788 /* Enable AOW0 to MW9 */
5794 static const struct hda_verb vt1812_uniwill_init_verbs[] = {
5795 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5796 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5797 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5798 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5799 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5800 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5801 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5802 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5806 static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
5810 .nid = 0x8, /* NID to query formats and rates */
5812 .open = via_playback_pcm_open,
5813 .prepare = via_playback_multi_pcm_prepare,
5814 .cleanup = via_playback_multi_pcm_cleanup,
5815 .close = via_pcm_open_close,
5819 static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
5823 .nid = 0x10, /* NID to query formats and rates */
5825 .open = via_pcm_open_close,
5826 .prepare = via_capture_pcm_prepare,
5827 .cleanup = via_capture_pcm_cleanup,
5828 .close = via_pcm_open_close,
5832 static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
5836 /* NID is set in via_build_pcms */
5838 .open = via_dig_playback_pcm_open,
5839 .close = via_dig_playback_pcm_close,
5840 .prepare = via_dig_playback_pcm_prepare,
5841 .cleanup = via_dig_playback_pcm_cleanup
5844 /* fill in the dac_nids table from the parsed pin configuration */
5845 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5846 const struct auto_pin_cfg *cfg)
5848 spec->multiout.num_dacs = 1;
5849 spec->multiout.dac_nids = spec->private_dac_nids;
5850 if (cfg->line_out_pins[0])
5851 spec->private_dac_nids[0] = 0x8;
5856 /* add playback controls from the parsed DAC table */
5857 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5858 const struct auto_pin_cfg *cfg)
5862 if (!cfg->line_out_pins[0])
5865 /* Line-Out: PortE */
5866 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5867 "Front Playback Volume",
5868 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5871 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5872 "Front Playback Switch",
5873 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5880 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5887 spec->multiout.hp_nid = 0x9;
5888 spec->hp_independent_mode_index = 1;
5891 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5892 "Headphone Playback Volume",
5893 HDA_COMPOSE_AMP_VAL(
5894 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5898 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5899 "Headphone Playback Switch",
5900 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5904 create_hp_imux(spec);
5908 /* create playback/capture controls for input pins */
5909 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5910 const struct auto_pin_cfg *cfg)
5912 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
5915 static int vt1812_parse_auto_config(struct hda_codec *codec)
5917 struct via_spec *spec = codec->spec;
5921 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5924 fill_dig_outs(codec);
5925 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5929 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5930 return 0; /* can't find valid BIOS pin config */
5932 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5935 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5938 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
5942 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5944 fill_dig_outs(codec);
5946 if (spec->kctls.list)
5947 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5949 spec->input_mux = &spec->private_imux[0];
5952 via_hp_build(codec);
5957 #ifdef CONFIG_SND_HDA_POWER_SAVE
5958 static const struct hda_amp_list vt1812_loopbacks[] = {
5959 { 0x21, HDA_INPUT, 0 },
5960 { 0x21, HDA_INPUT, 1 },
5961 { 0x21, HDA_INPUT, 2 },
5966 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
5968 struct via_spec *spec = codec->spec;
5969 int imux_is_smixer =
5970 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5972 unsigned int present;
5973 /* MUX10 (1eh) = stereo mixer */
5975 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
5977 /* PW 5/6/7 (29h/2ah/2bh) */
5979 set_pin_power_state(codec, 0x29, &parm);
5980 set_pin_power_state(codec, 0x2a, &parm);
5981 set_pin_power_state(codec, 0x2b, &parm);
5983 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
5984 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5985 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5986 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5987 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5991 snd_hda_codec_write(codec, 0x8, 0,
5992 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5994 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5996 set_pin_power_state(codec, 0x28, &parm);
5997 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5998 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6000 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6002 set_pin_power_state(codec, 0x25, &parm);
6003 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6004 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6005 if (spec->hp_independent_mode)
6006 snd_hda_codec_write(codec, 0x9, 0,
6007 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6009 /* Internal Speaker */
6010 /* PW0 (24h), MW0(14h), MUX0(34h) */
6011 present = snd_hda_jack_detect(codec, 0x25);
6014 set_pin_power_state(codec, 0x24, &parm);
6016 snd_hda_codec_write(codec, 0x14, 0,
6017 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6018 snd_hda_codec_write(codec, 0x34, 0,
6019 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6021 snd_hda_codec_write(codec, 0x14, 0,
6022 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6023 snd_hda_codec_write(codec, 0x34, 0,
6024 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6029 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6030 present = snd_hda_jack_detect(codec, 0x28);
6033 set_pin_power_state(codec, 0x31, &parm);
6035 snd_hda_codec_write(codec, 0x1c, 0,
6036 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6037 snd_hda_codec_write(codec, 0x3c, 0,
6038 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6039 snd_hda_codec_write(codec, 0x3e, 0,
6040 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6042 snd_hda_codec_write(codec, 0x1c, 0,
6043 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6044 snd_hda_codec_write(codec, 0x3c, 0,
6045 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6046 snd_hda_codec_write(codec, 0x3e, 0,
6047 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6050 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6052 set_pin_power_state(codec, 0x33, &parm);
6053 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6054 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6058 /* patch for vt1812 */
6059 static int patch_vt1812(struct hda_codec *codec)
6061 struct via_spec *spec;
6064 /* create a codec specific record */
6065 spec = via_new_spec(codec);
6069 /* automatic parse from the BIOS config */
6070 err = vt1812_parse_auto_config(codec);
6075 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6076 "from BIOS. Using genenic mode...\n");
6080 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6081 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6083 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6084 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6086 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6088 if (spec->adc_nids && spec->input_mux) {
6089 override_mic_boost(codec, 0x2b, 0, 3, 40);
6090 override_mic_boost(codec, 0x29, 0, 3, 40);
6091 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6095 codec->patch_ops = via_patch_ops;
6097 codec->patch_ops.init = via_auto_init;
6098 codec->patch_ops.unsol_event = via_unsol_event;
6100 #ifdef CONFIG_SND_HDA_POWER_SAVE
6101 spec->loopback.amplist = vt1812_loopbacks;
6104 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
6111 static const struct hda_codec_preset snd_hda_preset_via[] = {
6112 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6113 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6114 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6115 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6116 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6117 .patch = patch_vt1709_10ch},
6118 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6119 .patch = patch_vt1709_10ch},
6120 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6121 .patch = patch_vt1709_10ch},
6122 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6123 .patch = patch_vt1709_10ch},
6124 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6125 .patch = patch_vt1709_6ch},
6126 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6127 .patch = patch_vt1709_6ch},
6128 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6129 .patch = patch_vt1709_6ch},
6130 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6131 .patch = patch_vt1709_6ch},
6132 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6133 .patch = patch_vt1708B_8ch},
6134 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6135 .patch = patch_vt1708B_8ch},
6136 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6137 .patch = patch_vt1708B_8ch},
6138 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6139 .patch = patch_vt1708B_8ch},
6140 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6141 .patch = patch_vt1708B_4ch},
6142 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6143 .patch = patch_vt1708B_4ch},
6144 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6145 .patch = patch_vt1708B_4ch},
6146 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6147 .patch = patch_vt1708B_4ch},
6148 { .id = 0x11060397, .name = "VT1708S",
6149 .patch = patch_vt1708S},
6150 { .id = 0x11061397, .name = "VT1708S",
6151 .patch = patch_vt1708S},
6152 { .id = 0x11062397, .name = "VT1708S",
6153 .patch = patch_vt1708S},
6154 { .id = 0x11063397, .name = "VT1708S",
6155 .patch = patch_vt1708S},
6156 { .id = 0x11064397, .name = "VT1705",
6157 .patch = patch_vt1708S},
6158 { .id = 0x11065397, .name = "VT1708S",
6159 .patch = patch_vt1708S},
6160 { .id = 0x11066397, .name = "VT1708S",
6161 .patch = patch_vt1708S},
6162 { .id = 0x11067397, .name = "VT1708S",
6163 .patch = patch_vt1708S},
6164 { .id = 0x11060398, .name = "VT1702",
6165 .patch = patch_vt1702},
6166 { .id = 0x11061398, .name = "VT1702",
6167 .patch = patch_vt1702},
6168 { .id = 0x11062398, .name = "VT1702",
6169 .patch = patch_vt1702},
6170 { .id = 0x11063398, .name = "VT1702",
6171 .patch = patch_vt1702},
6172 { .id = 0x11064398, .name = "VT1702",
6173 .patch = patch_vt1702},
6174 { .id = 0x11065398, .name = "VT1702",
6175 .patch = patch_vt1702},
6176 { .id = 0x11066398, .name = "VT1702",
6177 .patch = patch_vt1702},
6178 { .id = 0x11067398, .name = "VT1702",
6179 .patch = patch_vt1702},
6180 { .id = 0x11060428, .name = "VT1718S",
6181 .patch = patch_vt1718S},
6182 { .id = 0x11064428, .name = "VT1718S",
6183 .patch = patch_vt1718S},
6184 { .id = 0x11060441, .name = "VT2020",
6185 .patch = patch_vt1718S},
6186 { .id = 0x11064441, .name = "VT1828S",
6187 .patch = patch_vt1718S},
6188 { .id = 0x11060433, .name = "VT1716S",
6189 .patch = patch_vt1716S},
6190 { .id = 0x1106a721, .name = "VT1716S",
6191 .patch = patch_vt1716S},
6192 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6193 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6194 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6195 { .id = 0x11060440, .name = "VT1818S",
6196 .patch = patch_vt1708S},
6197 { .id = 0x11060446, .name = "VT1802",
6198 .patch = patch_vt2002P},
6199 { .id = 0x11068446, .name = "VT1802",
6200 .patch = patch_vt2002P},
6204 MODULE_ALIAS("snd-hda-codec-id:1106*");
6206 static struct hda_codec_preset_list via_list = {
6207 .preset = snd_hda_preset_via,
6208 .owner = THIS_MODULE,
6211 MODULE_LICENSE("GPL");
6212 MODULE_DESCRIPTION("VIA HD-audio codec");
6214 static int __init patch_via_init(void)
6216 return snd_hda_add_codec_preset(&via_list);
6219 static void __exit patch_via_exit(void)
6221 snd_hda_delete_codec_preset(&via_list);
6224 module_init(patch_via_init)
6225 module_exit(patch_via_exit)