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) {
1619 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1620 AC_VERB_SET_PIN_WIDGET_CONTROL,
1621 present ? 0 : PIN_OUT);
1625 /* mute mono out if HP or Line out is plugged */
1626 static void via_mono_automute(struct hda_codec *codec)
1628 unsigned int hp_present, lineout_present;
1629 struct via_spec *spec = codec->spec;
1631 if (spec->codec_type != VT1716S)
1634 lineout_present = snd_hda_jack_detect(codec,
1635 spec->autocfg.line_out_pins[0]);
1637 /* Mute Mono Out if Line Out is plugged */
1638 if (lineout_present) {
1639 snd_hda_codec_write(codec, 0x2A, 0,
1640 AC_VERB_SET_PIN_WIDGET_CONTROL,
1641 lineout_present ? 0 : PIN_OUT);
1645 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1647 if (!spec->hp_independent_mode)
1648 snd_hda_codec_write(codec, 0x2A, 0,
1649 AC_VERB_SET_PIN_WIDGET_CONTROL,
1650 hp_present ? 0 : PIN_OUT);
1653 static void via_gpio_control(struct hda_codec *codec)
1655 unsigned int gpio_data;
1656 unsigned int vol_counter;
1658 unsigned int master_vol;
1660 struct via_spec *spec = codec->spec;
1662 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1663 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1665 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1666 0xF84, 0) & 0x3F0000) >> 16;
1668 vol = vol_counter & 0x1F;
1669 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1670 AC_VERB_GET_AMP_GAIN_MUTE,
1673 if (gpio_data == 0x02) {
1674 /* unmute line out */
1675 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1676 AC_VERB_SET_PIN_WIDGET_CONTROL,
1678 if (vol_counter & 0x20) {
1679 /* decrease volume */
1680 if (vol > master_vol)
1682 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1686 /* increase volume */
1687 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1689 ((master_vol+vol) > 0x2A) ? 0x2A :
1692 } else if (!(gpio_data & 0x02)) {
1694 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1695 AC_VERB_SET_PIN_WIDGET_CONTROL,
1700 /* mute Internal-Speaker if HP is plugged */
1701 static void via_speaker_automute(struct hda_codec *codec)
1703 unsigned int hp_present;
1704 struct via_spec *spec = codec->spec;
1706 if (!VT2002P_COMPATIBLE(spec))
1709 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1711 if (!spec->hp_independent_mode) {
1712 snd_hda_codec_write(codec, spec->autocfg.speaker_pins[0], 0,
1713 AC_VERB_SET_PIN_WIDGET_CONTROL,
1714 hp_present ? 0 : PIN_OUT);
1718 /* mute line-out and internal speaker if HP is plugged */
1719 static void via_hp_bind_automute(struct hda_codec *codec)
1721 /* use long instead of int below just to avoid an internal compiler
1722 * error with gcc 4.0.x
1724 unsigned long hp_present, present = 0;
1725 struct via_spec *spec = codec->spec;
1728 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1731 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1733 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
1735 if (!spec->hp_independent_mode) {
1736 /* Mute Line-Outs */
1737 for (i = 0; i < spec->autocfg.line_outs; i++)
1738 snd_hda_codec_write(codec,
1739 spec->autocfg.line_out_pins[i], 0,
1740 AC_VERB_SET_PIN_WIDGET_CONTROL,
1741 hp_present ? 0 : PIN_OUT);
1743 present = hp_present;
1746 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1747 snd_hda_codec_write(codec, spec->autocfg.speaker_pins[i], 0,
1748 AC_VERB_SET_PIN_WIDGET_CONTROL,
1749 present ? 0 : PIN_OUT);
1753 /* unsolicited event for jack sensing */
1754 static void via_unsol_event(struct hda_codec *codec,
1759 if (res & VIA_JACK_EVENT)
1760 set_widgets_power_state(codec);
1762 res &= ~VIA_JACK_EVENT;
1764 if (res == VIA_HP_EVENT)
1765 via_hp_automute(codec);
1766 else if (res == VIA_GPIO_EVENT)
1767 via_gpio_control(codec);
1768 else if (res == VIA_MONO_EVENT)
1769 via_mono_automute(codec);
1770 else if (res == VIA_SPEAKER_EVENT)
1771 via_speaker_automute(codec);
1772 else if (res == VIA_BIND_HP_EVENT)
1773 via_hp_bind_automute(codec);
1776 static int via_init(struct hda_codec *codec)
1778 struct via_spec *spec = codec->spec;
1780 for (i = 0; i < spec->num_iverbs; i++)
1781 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1783 /* Lydia Add for EAPD enable */
1784 if (!spec->dig_in_nid) { /* No Digital In connection */
1785 if (spec->dig_in_pin) {
1786 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1787 AC_VERB_SET_PIN_WIDGET_CONTROL,
1789 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1790 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1792 } else /* enable SPDIF-input pin */
1793 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1794 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1796 /* assign slave outs */
1797 if (spec->slave_dig_outs[0])
1798 codec->slave_dig_outs = spec->slave_dig_outs;
1803 #ifdef SND_HDA_NEEDS_RESUME
1804 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1806 struct via_spec *spec = codec->spec;
1807 vt1708_stop_hp_work(spec);
1812 #ifdef CONFIG_SND_HDA_POWER_SAVE
1813 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1815 struct via_spec *spec = codec->spec;
1816 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1822 static const struct hda_codec_ops via_patch_ops = {
1823 .build_controls = via_build_controls,
1824 .build_pcms = via_build_pcms,
1827 #ifdef SND_HDA_NEEDS_RESUME
1828 .suspend = via_suspend,
1830 #ifdef CONFIG_SND_HDA_POWER_SAVE
1831 .check_power_status = via_check_power_status,
1835 /* fill in the dac_nids table from the parsed pin configuration */
1836 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1837 const struct auto_pin_cfg *cfg)
1842 spec->multiout.num_dacs = cfg->line_outs;
1844 spec->multiout.dac_nids = spec->private_dac_nids;
1846 for (i = 0; i < 4; i++) {
1847 nid = cfg->line_out_pins[i];
1849 /* config dac list */
1851 case AUTO_SEQ_FRONT:
1852 spec->private_dac_nids[i] = 0x10;
1854 case AUTO_SEQ_CENLFE:
1855 spec->private_dac_nids[i] = 0x12;
1857 case AUTO_SEQ_SURROUND:
1858 spec->private_dac_nids[i] = 0x11;
1861 spec->private_dac_nids[i] = 0x13;
1870 /* add playback controls from the parsed DAC table */
1871 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1872 const struct auto_pin_cfg *cfg)
1875 static const char * const chname[4] = {
1876 "Front", "Surround", "C/LFE", "Side"
1878 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1881 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1882 nid = cfg->line_out_pins[i];
1887 nid_vol = nid_vols[i];
1889 if (i == AUTO_SEQ_CENLFE) {
1891 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1892 "Center Playback Volume",
1893 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1897 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1898 "LFE Playback Volume",
1899 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1903 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1904 "Center Playback Switch",
1905 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1909 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1910 "LFE Playback Switch",
1911 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1915 } else if (i == AUTO_SEQ_FRONT) {
1916 /* add control to mixer index 0 */
1917 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1918 "Master Front Playback Volume",
1919 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1923 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1924 "Master Front Playback Switch",
1925 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1930 /* add control to PW3 */
1931 sprintf(name, "%s Playback Volume", chname[i]);
1932 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1933 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1937 sprintf(name, "%s Playback Switch", chname[i]);
1938 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1939 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1944 sprintf(name, "%s Playback Volume", chname[i]);
1945 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1946 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1950 sprintf(name, "%s Playback Switch", chname[i]);
1951 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1952 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1962 static void create_hp_imux(struct via_spec *spec)
1965 struct hda_input_mux *imux = &spec->private_imux[1];
1966 static const char * const texts[] = { "OFF", "ON", NULL};
1968 /* for hp mode select */
1969 for (i = 0; texts[i]; i++)
1970 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1972 spec->hp_mux = &spec->private_imux[1];
1975 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1982 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1983 spec->hp_independent_mode_index = 1;
1985 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1986 "Headphone Playback Volume",
1987 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1990 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1991 "Headphone Playback Switch",
1992 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1996 create_hp_imux(spec);
2001 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
2004 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
2007 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
2008 for (i = 0; i < nums; i++)
2015 static int via_fill_adcs(struct hda_codec *codec)
2017 struct via_spec *spec = codec->spec;
2018 hda_nid_t nid = codec->start_nid;
2021 for (i = 0; i < codec->num_nodes; i++, nid++) {
2022 unsigned int wcaps = get_wcaps(codec, nid);
2023 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2025 if (wcaps & AC_WCAP_DIGITAL)
2027 if (!(wcaps & AC_WCAP_CONN_LIST))
2029 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2031 spec->adc_nids[spec->num_adc_nids++] = nid;
2036 static int get_mux_nids(struct hda_codec *codec);
2038 /* create playback/capture controls for input pins */
2039 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2040 const struct auto_pin_cfg *cfg,
2043 struct via_spec *spec = codec->spec;
2044 struct hda_input_mux *imux = &spec->private_imux[0];
2045 int i, err, idx, idx2, type, type_idx = 0;
2047 hda_nid_t pin_idxs[8];
2050 err = via_fill_adcs(codec);
2053 err = get_mux_nids(codec);
2056 cap_nid = spec->mux_nids[0];
2058 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2059 ARRAY_SIZE(pin_idxs));
2063 /* for internal loopback recording select */
2064 for (idx = 0; idx < num_idxs; idx++) {
2065 if (pin_idxs[idx] == mix_nid) {
2066 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2071 for (i = 0; i < cfg->num_inputs; i++) {
2073 type = cfg->inputs[i].type;
2074 for (idx = 0; idx < num_idxs; idx++)
2075 if (pin_idxs[idx] == cfg->inputs[i].pin)
2077 if (idx >= num_idxs)
2079 if (i > 0 && type == cfg->inputs[i - 1].type)
2083 label = hda_get_autocfg_input_label(codec, cfg, i);
2084 idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]);
2086 err = via_new_analog_input(spec, label, type_idx,
2090 snd_hda_add_imux_item(imux, label, idx, NULL);
2095 /* create playback/capture controls for input pins */
2096 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2097 const struct auto_pin_cfg *cfg)
2099 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17);
2102 #ifdef CONFIG_SND_HDA_POWER_SAVE
2103 static const struct hda_amp_list vt1708_loopbacks[] = {
2104 { 0x17, HDA_INPUT, 1 },
2105 { 0x17, HDA_INPUT, 2 },
2106 { 0x17, HDA_INPUT, 3 },
2107 { 0x17, HDA_INPUT, 4 },
2112 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2114 unsigned int def_conf;
2115 unsigned char seqassoc;
2117 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2118 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2119 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2120 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2121 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2122 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2123 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2129 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2130 struct snd_ctl_elem_value *ucontrol)
2132 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2133 struct via_spec *spec = codec->spec;
2135 if (spec->codec_type != VT1708)
2137 spec->vt1708_jack_detect =
2138 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2139 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2143 static int vt1708_jack_detect_put(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;
2150 if (spec->codec_type != VT1708)
2152 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2153 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2154 == !spec->vt1708_jack_detect;
2155 if (spec->vt1708_jack_detect) {
2156 mute_aa_path(codec, 1);
2157 notify_aa_path_ctls(codec);
2162 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2164 .name = "Jack Detect",
2166 .info = snd_ctl_boolean_mono_info,
2167 .get = vt1708_jack_detect_get,
2168 .put = vt1708_jack_detect_put,
2171 static int vt1708_parse_auto_config(struct hda_codec *codec)
2173 struct via_spec *spec = codec->spec;
2176 /* Add HP and CD pin config connect bit re-config action */
2177 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2178 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2180 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2183 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2186 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2187 return 0; /* can't find valid BIOS pin config */
2189 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2192 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2195 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2198 /* add jack detect on/off control */
2199 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2202 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2204 if (spec->autocfg.dig_outs)
2205 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2206 spec->dig_in_pin = VT1708_DIGIN_PIN;
2207 if (spec->autocfg.dig_in_pin)
2208 spec->dig_in_nid = VT1708_DIGIN_NID;
2210 if (spec->kctls.list)
2211 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2213 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2215 spec->input_mux = &spec->private_imux[0];
2218 via_hp_build(codec);
2220 via_smart51_build(spec);
2224 /* init callback for auto-configuration model -- overriding the default init */
2225 static int via_auto_init(struct hda_codec *codec)
2227 struct via_spec *spec = codec->spec;
2230 via_auto_init_multi_out(codec);
2231 via_auto_init_hp_out(codec);
2232 via_auto_init_analog_input(codec);
2234 if (VT2002P_COMPATIBLE(spec)) {
2235 via_hp_bind_automute(codec);
2237 via_hp_automute(codec);
2238 via_speaker_automute(codec);
2244 static void vt1708_update_hp_jack_state(struct work_struct *work)
2246 struct via_spec *spec = container_of(work, struct via_spec,
2247 vt1708_hp_work.work);
2248 if (spec->codec_type != VT1708)
2250 /* if jack state toggled */
2251 if (spec->vt1708_hp_present
2252 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2253 spec->vt1708_hp_present ^= 1;
2254 via_hp_automute(spec->codec);
2256 vt1708_start_hp_work(spec);
2259 static int get_mux_nids(struct hda_codec *codec)
2261 struct via_spec *spec = codec->spec;
2262 hda_nid_t nid, conn[8];
2266 for (i = 0; i < spec->num_adc_nids; i++) {
2267 nid = spec->adc_nids[i];
2269 type = get_wcaps_type(get_wcaps(codec, nid));
2270 if (type == AC_WID_PIN)
2272 n = snd_hda_get_connections(codec, nid, conn,
2277 spec->mux_nids[i] = nid;
2286 static int patch_vt1708(struct hda_codec *codec)
2288 struct via_spec *spec;
2291 /* create a codec specific record */
2292 spec = via_new_spec(codec);
2296 /* automatic parse from the BIOS config */
2297 err = vt1708_parse_auto_config(codec);
2302 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2303 "from BIOS. Using genenic mode...\n");
2307 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2308 /* disable 32bit format on VT1708 */
2309 if (codec->vendor_id == 0x11061708)
2310 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2311 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2313 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2314 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2316 if (spec->adc_nids && spec->input_mux) {
2317 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2321 codec->patch_ops = via_patch_ops;
2323 codec->patch_ops.init = via_auto_init;
2324 #ifdef CONFIG_SND_HDA_POWER_SAVE
2325 spec->loopback.amplist = vt1708_loopbacks;
2327 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2331 /* capture mixer elements */
2332 static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
2333 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2334 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2335 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2336 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2337 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2338 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2340 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2341 /* The multiple "Capture Source" controls confuse alsamixer
2342 * So call somewhat different..
2344 /* .name = "Capture Source", */
2345 .name = "Input Source",
2347 .info = via_mux_enum_info,
2348 .get = via_mux_enum_get,
2349 .put = via_mux_enum_put,
2354 static const struct hda_verb vt1709_uniwill_init_verbs[] = {
2355 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2356 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2361 * generic initialization of ADC, input mixers and output mixers
2363 static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2365 * Unmute ADC0-2 and set the default input to mic-in
2367 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2368 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2369 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2372 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2375 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2376 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2377 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2378 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2379 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2380 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2383 * Set up output selector (0x1a, 0x1b, 0x29)
2385 /* set vol=0 to output mixers */
2386 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2387 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2388 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2391 * Unmute PW3 and PW4
2393 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2394 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2396 /* Set input of PW4 as MW0 */
2397 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2398 /* PW9 Output enable */
2399 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2403 static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2407 .nid = 0x10, /* NID to query formats and rates */
2409 .open = via_playback_pcm_open,
2410 .prepare = via_playback_multi_pcm_prepare,
2411 .cleanup = via_playback_multi_pcm_cleanup,
2415 static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2419 .nid = 0x10, /* NID to query formats and rates */
2421 .open = via_playback_pcm_open,
2422 .prepare = via_playback_multi_pcm_prepare,
2423 .cleanup = via_playback_multi_pcm_cleanup,
2427 static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
2431 .nid = 0x14, /* NID to query formats and rates */
2433 .prepare = via_capture_pcm_prepare,
2434 .cleanup = via_capture_pcm_cleanup
2438 static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
2442 /* NID is set in via_build_pcms */
2444 .open = via_dig_playback_pcm_open,
2445 .close = via_dig_playback_pcm_close
2449 static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
2455 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2456 const struct auto_pin_cfg *cfg)
2461 if (cfg->line_outs == 4) /* 10 channels */
2462 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2463 else if (cfg->line_outs == 3) /* 6 channels */
2464 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2466 spec->multiout.dac_nids = spec->private_dac_nids;
2468 if (cfg->line_outs == 4) { /* 10 channels */
2469 for (i = 0; i < cfg->line_outs; i++) {
2470 nid = cfg->line_out_pins[i];
2472 /* config dac list */
2474 case AUTO_SEQ_FRONT:
2476 spec->private_dac_nids[i] = 0x10;
2478 case AUTO_SEQ_CENLFE:
2480 spec->private_dac_nids[i] = 0x12;
2482 case AUTO_SEQ_SURROUND:
2484 spec->private_dac_nids[i] = 0x11;
2488 spec->private_dac_nids[i] = 0x27;
2495 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2497 } else if (cfg->line_outs == 3) { /* 6 channels */
2498 for (i = 0; i < cfg->line_outs; i++) {
2499 nid = cfg->line_out_pins[i];
2501 /* config dac list */
2503 case AUTO_SEQ_FRONT:
2505 spec->private_dac_nids[i] = 0x10;
2507 case AUTO_SEQ_CENLFE:
2509 spec->private_dac_nids[i] = 0x12;
2511 case AUTO_SEQ_SURROUND:
2513 spec->private_dac_nids[i] = 0x11;
2525 /* add playback controls from the parsed DAC table */
2526 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2527 const struct auto_pin_cfg *cfg)
2530 static const char * const chname[4] = {
2531 "Front", "Surround", "C/LFE", "Side"
2533 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2536 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2537 nid = cfg->line_out_pins[i];
2542 nid_vol = nid_vols[i];
2544 if (i == AUTO_SEQ_CENLFE) {
2546 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2547 "Center Playback Volume",
2548 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2552 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2553 "LFE Playback Volume",
2554 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2558 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2559 "Center Playback Switch",
2560 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2564 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2565 "LFE Playback Switch",
2566 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2570 } else if (i == AUTO_SEQ_FRONT) {
2571 /* ADD control to mixer index 0 */
2572 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2573 "Master Front Playback Volume",
2574 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2578 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2579 "Master Front Playback Switch",
2580 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2585 /* add control to PW3 */
2586 sprintf(name, "%s Playback Volume", chname[i]);
2587 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2588 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2592 sprintf(name, "%s Playback Switch", chname[i]);
2593 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2594 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2598 } else if (i == AUTO_SEQ_SURROUND) {
2599 sprintf(name, "%s Playback Volume", chname[i]);
2600 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2601 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2605 sprintf(name, "%s Playback Switch", chname[i]);
2606 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2607 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2611 } else if (i == AUTO_SEQ_SIDE) {
2612 sprintf(name, "%s Playback Volume", chname[i]);
2613 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2614 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2618 sprintf(name, "%s Playback Switch", chname[i]);
2619 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2620 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2630 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2637 if (spec->multiout.num_dacs == 5) /* 10 channels */
2638 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2639 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2640 spec->multiout.hp_nid = 0;
2641 spec->hp_independent_mode_index = 1;
2643 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2644 "Headphone Playback Volume",
2645 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2648 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2649 "Headphone Playback Switch",
2650 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2657 /* create playback/capture controls for input pins */
2658 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
2659 const struct auto_pin_cfg *cfg)
2661 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18);
2664 static int vt1709_parse_auto_config(struct hda_codec *codec)
2666 struct via_spec *spec = codec->spec;
2669 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2672 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2675 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2676 return 0; /* can't find valid BIOS pin config */
2678 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2681 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2684 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
2688 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2690 if (spec->autocfg.dig_outs)
2691 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2692 spec->dig_in_pin = VT1709_DIGIN_PIN;
2693 if (spec->autocfg.dig_in_pin)
2694 spec->dig_in_nid = VT1709_DIGIN_NID;
2696 if (spec->kctls.list)
2697 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2699 spec->input_mux = &spec->private_imux[0];
2702 via_hp_build(codec);
2704 via_smart51_build(spec);
2708 #ifdef CONFIG_SND_HDA_POWER_SAVE
2709 static const struct hda_amp_list vt1709_loopbacks[] = {
2710 { 0x18, HDA_INPUT, 1 },
2711 { 0x18, HDA_INPUT, 2 },
2712 { 0x18, HDA_INPUT, 3 },
2713 { 0x18, HDA_INPUT, 4 },
2718 static int patch_vt1709_10ch(struct hda_codec *codec)
2720 struct via_spec *spec;
2723 /* create a codec specific record */
2724 spec = via_new_spec(codec);
2728 err = vt1709_parse_auto_config(codec);
2733 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2734 "Using genenic mode...\n");
2737 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2738 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2740 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2741 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2743 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2744 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2746 if (spec->adc_nids && spec->input_mux) {
2747 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2751 codec->patch_ops = via_patch_ops;
2753 codec->patch_ops.init = via_auto_init;
2754 codec->patch_ops.unsol_event = via_unsol_event;
2755 #ifdef CONFIG_SND_HDA_POWER_SAVE
2756 spec->loopback.amplist = vt1709_loopbacks;
2762 * generic initialization of ADC, input mixers and output mixers
2764 static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2766 * Unmute ADC0-2 and set the default input to mic-in
2768 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2769 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2770 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2773 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2776 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2777 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2778 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2779 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2780 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2781 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2784 * Set up output selector (0x1a, 0x1b, 0x29)
2786 /* set vol=0 to output mixers */
2787 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2788 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2789 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2792 * Unmute PW3 and PW4
2794 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2795 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2797 /* Set input of PW4 as MW0 */
2798 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2799 /* PW9 Output enable */
2800 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2804 static int patch_vt1709_6ch(struct hda_codec *codec)
2806 struct via_spec *spec;
2809 /* create a codec specific record */
2810 spec = via_new_spec(codec);
2814 err = vt1709_parse_auto_config(codec);
2819 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2820 "Using genenic mode...\n");
2823 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2824 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2826 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2827 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2829 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2830 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2832 if (spec->adc_nids && spec->input_mux) {
2833 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2837 codec->patch_ops = via_patch_ops;
2839 codec->patch_ops.init = via_auto_init;
2840 codec->patch_ops.unsol_event = via_unsol_event;
2841 #ifdef CONFIG_SND_HDA_POWER_SAVE
2842 spec->loopback.amplist = vt1709_loopbacks;
2847 /* capture mixer elements */
2848 static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2849 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2850 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2851 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2852 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2854 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2855 /* The multiple "Capture Source" controls confuse alsamixer
2856 * So call somewhat different..
2858 /* .name = "Capture Source", */
2859 .name = "Input Source",
2861 .info = via_mux_enum_info,
2862 .get = via_mux_enum_get,
2863 .put = via_mux_enum_put,
2868 * generic initialization of ADC, input mixers and output mixers
2870 static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2872 * Unmute ADC0-1 and set the default input to mic-in
2874 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2875 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2878 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2881 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2882 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2883 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2884 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2885 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2886 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2889 * Set up output mixers
2891 /* set vol=0 to output mixers */
2892 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2893 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2894 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2896 /* Setup default input to PW4 */
2897 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2898 /* PW9 Output enable */
2899 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2900 /* PW10 Input enable */
2901 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2905 static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2907 * Unmute ADC0-1 and set the default input to mic-in
2909 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2910 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2913 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2916 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2917 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2918 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2919 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2920 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2921 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2924 * Set up output mixers
2926 /* set vol=0 to output mixers */
2927 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2928 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2929 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2931 /* Setup default input of PW4 to MW0 */
2932 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2933 /* PW9 Output enable */
2934 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2935 /* PW10 Input enable */
2936 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2940 static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
2941 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2942 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2943 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2944 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2945 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2946 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2947 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2948 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2949 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2953 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2954 struct hda_codec *codec,
2955 struct snd_pcm_substream *substream)
2957 int idle = substream->pstr->substream_opened == 1
2958 && substream->ref_count == 0;
2960 analog_low_current_mode(codec, idle);
2964 static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2968 .nid = 0x10, /* NID to query formats and rates */
2970 .open = via_playback_pcm_open,
2971 .prepare = via_playback_multi_pcm_prepare,
2972 .cleanup = via_playback_multi_pcm_cleanup,
2973 .close = via_pcm_open_close
2977 static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2981 .nid = 0x10, /* NID to query formats and rates */
2983 .open = via_playback_pcm_open,
2984 .prepare = via_playback_multi_pcm_prepare,
2985 .cleanup = via_playback_multi_pcm_cleanup
2989 static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2993 .nid = 0x13, /* NID to query formats and rates */
2995 .open = via_pcm_open_close,
2996 .prepare = via_capture_pcm_prepare,
2997 .cleanup = via_capture_pcm_cleanup,
2998 .close = via_pcm_open_close
3002 static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3006 /* NID is set in via_build_pcms */
3008 .open = via_dig_playback_pcm_open,
3009 .close = via_dig_playback_pcm_close,
3010 .prepare = via_dig_playback_pcm_prepare,
3011 .cleanup = via_dig_playback_pcm_cleanup
3015 static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3021 /* fill in the dac_nids table from the parsed pin configuration */
3022 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3023 const struct auto_pin_cfg *cfg)
3028 spec->multiout.num_dacs = cfg->line_outs;
3030 spec->multiout.dac_nids = spec->private_dac_nids;
3032 for (i = 0; i < 4; i++) {
3033 nid = cfg->line_out_pins[i];
3035 /* config dac list */
3037 case AUTO_SEQ_FRONT:
3038 spec->private_dac_nids[i] = 0x10;
3040 case AUTO_SEQ_CENLFE:
3041 spec->private_dac_nids[i] = 0x24;
3043 case AUTO_SEQ_SURROUND:
3044 spec->private_dac_nids[i] = 0x11;
3047 spec->private_dac_nids[i] = 0x25;
3056 /* add playback controls from the parsed DAC table */
3057 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3058 const struct auto_pin_cfg *cfg)
3061 static const char * const chname[4] = {
3062 "Front", "Surround", "C/LFE", "Side"
3064 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3065 hda_nid_t nid, nid_vol = 0;
3068 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3069 nid = cfg->line_out_pins[i];
3074 nid_vol = nid_vols[i];
3076 if (i == AUTO_SEQ_CENLFE) {
3078 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3079 "Center Playback Volume",
3080 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3084 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3085 "LFE Playback Volume",
3086 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3090 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3091 "Center Playback Switch",
3092 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3096 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3097 "LFE Playback Switch",
3098 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3102 } else if (i == AUTO_SEQ_FRONT) {
3103 /* add control to mixer index 0 */
3104 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3105 "Master Front Playback Volume",
3106 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3110 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3111 "Master Front Playback Switch",
3112 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3117 /* add control to PW3 */
3118 sprintf(name, "%s Playback Volume", chname[i]);
3119 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3120 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3124 sprintf(name, "%s Playback Switch", chname[i]);
3125 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3126 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3131 sprintf(name, "%s Playback Volume", chname[i]);
3132 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3133 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3137 sprintf(name, "%s Playback Switch", chname[i]);
3138 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3139 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3149 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3156 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3157 spec->hp_independent_mode_index = 1;
3159 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3160 "Headphone Playback Volume",
3161 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3164 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3165 "Headphone Playback Switch",
3166 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3170 create_hp_imux(spec);
3175 /* create playback/capture controls for input pins */
3176 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3177 const struct auto_pin_cfg *cfg)
3179 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
3182 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3184 struct via_spec *spec = codec->spec;
3187 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3190 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3193 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3194 return 0; /* can't find valid BIOS pin config */
3196 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3199 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3202 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3206 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3208 if (spec->autocfg.dig_outs)
3209 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3210 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3211 if (spec->autocfg.dig_in_pin)
3212 spec->dig_in_nid = VT1708B_DIGIN_NID;
3214 if (spec->kctls.list)
3215 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3217 spec->input_mux = &spec->private_imux[0];
3220 via_hp_build(codec);
3222 via_smart51_build(spec);
3226 #ifdef CONFIG_SND_HDA_POWER_SAVE
3227 static const struct hda_amp_list vt1708B_loopbacks[] = {
3228 { 0x16, HDA_INPUT, 1 },
3229 { 0x16, HDA_INPUT, 2 },
3230 { 0x16, HDA_INPUT, 3 },
3231 { 0x16, HDA_INPUT, 4 },
3236 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3238 struct via_spec *spec = codec->spec;
3242 if ((spec->codec_type != VT1708B_4CH) &&
3243 (codec->vendor_id != 0x11064397))
3246 /* SW0 (17h) = stereo mixer */
3248 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3249 == ((spec->codec_type == VT1708S) ? 5 : 0));
3251 /* PW 1/2/5 (1ah/1bh/1eh) */
3253 set_pin_power_state(codec, 0x1a, &parm);
3254 set_pin_power_state(codec, 0x1b, &parm);
3255 set_pin_power_state(codec, 0x1e, &parm);
3258 /* SW0 (17h), AIW 0/1 (13h/14h) */
3259 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3260 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3261 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3264 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3266 set_pin_power_state(codec, 0x19, &parm);
3267 if (spec->smart51_enabled)
3268 set_pin_power_state(codec, 0x1b, &parm);
3269 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3270 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3272 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3275 set_pin_power_state(codec, 0x22, &parm);
3276 if (spec->smart51_enabled)
3277 set_pin_power_state(codec, 0x1a, &parm);
3278 snd_hda_codec_write(codec, 0x26, 0,
3279 AC_VERB_SET_POWER_STATE, parm);
3280 snd_hda_codec_write(codec, 0x24, 0,
3281 AC_VERB_SET_POWER_STATE, parm);
3282 } else if (codec->vendor_id == 0x11064397) {
3283 /* PW7(23h), SW2(27h), AOW2(25h) */
3285 set_pin_power_state(codec, 0x23, &parm);
3286 if (spec->smart51_enabled)
3287 set_pin_power_state(codec, 0x1a, &parm);
3288 snd_hda_codec_write(codec, 0x27, 0,
3289 AC_VERB_SET_POWER_STATE, parm);
3290 snd_hda_codec_write(codec, 0x25, 0,
3291 AC_VERB_SET_POWER_STATE, parm);
3294 /* PW 3/4/7 (1ch/1dh/23h) */
3296 /* force to D0 for internal Speaker */
3297 set_pin_power_state(codec, 0x1c, &parm);
3298 set_pin_power_state(codec, 0x1d, &parm);
3300 set_pin_power_state(codec, 0x23, &parm);
3302 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3303 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3304 imux_is_smixer ? AC_PWRST_D0 : parm);
3305 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3307 snd_hda_codec_write(codec, 0x25, 0,
3308 AC_VERB_SET_POWER_STATE, parm);
3309 snd_hda_codec_write(codec, 0x27, 0,
3310 AC_VERB_SET_POWER_STATE, parm);
3311 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3312 snd_hda_codec_write(codec, 0x25, 0,
3313 AC_VERB_SET_POWER_STATE, parm);
3316 static int patch_vt1708S(struct hda_codec *codec);
3317 static int patch_vt1708B_8ch(struct hda_codec *codec)
3319 struct via_spec *spec;
3322 if (get_codec_type(codec) == VT1708BCE)
3323 return patch_vt1708S(codec);
3324 /* create a codec specific record */
3325 spec = via_new_spec(codec);
3329 /* automatic parse from the BIOS config */
3330 err = vt1708B_parse_auto_config(codec);
3335 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3336 "from BIOS. Using genenic mode...\n");
3339 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3340 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3342 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3343 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3345 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3346 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3348 if (spec->adc_nids && spec->input_mux) {
3349 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3353 codec->patch_ops = via_patch_ops;
3355 codec->patch_ops.init = via_auto_init;
3356 codec->patch_ops.unsol_event = via_unsol_event;
3357 #ifdef CONFIG_SND_HDA_POWER_SAVE
3358 spec->loopback.amplist = vt1708B_loopbacks;
3361 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3366 static int patch_vt1708B_4ch(struct hda_codec *codec)
3368 struct via_spec *spec;
3371 /* create a codec specific record */
3372 spec = via_new_spec(codec);
3376 /* automatic parse from the BIOS config */
3377 err = vt1708B_parse_auto_config(codec);
3382 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3383 "from BIOS. Using genenic mode...\n");
3386 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3387 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3389 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3390 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3392 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3393 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3395 if (spec->adc_nids && spec->input_mux) {
3396 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3400 codec->patch_ops = via_patch_ops;
3402 codec->patch_ops.init = via_auto_init;
3403 codec->patch_ops.unsol_event = via_unsol_event;
3404 #ifdef CONFIG_SND_HDA_POWER_SAVE
3405 spec->loopback.amplist = vt1708B_loopbacks;
3408 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3413 /* Patch for VT1708S */
3415 /* capture mixer elements */
3416 static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3417 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3418 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3419 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3420 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3421 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3422 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3425 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3426 /* The multiple "Capture Source" controls confuse alsamixer
3427 * So call somewhat different..
3429 /* .name = "Capture Source", */
3430 .name = "Input Source",
3432 .info = via_mux_enum_info,
3433 .get = via_mux_enum_get,
3434 .put = via_mux_enum_put,
3439 static const struct hda_verb vt1708S_volume_init_verbs[] = {
3440 /* Unmute ADC0-1 and set the default input to mic-in */
3441 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3442 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3444 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3445 * analog-loopback mixer widget */
3446 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3447 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3448 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3449 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3450 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3451 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3453 /* Setup default input of PW4 to MW0 */
3454 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3455 /* PW9, PW10 Output enable */
3456 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3457 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3458 /* Enable Mic Boost Volume backdoor */
3460 /* don't bybass mixer */
3465 static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
3466 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3467 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3468 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3469 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3470 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3471 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3472 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3473 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3474 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3478 static const struct hda_verb vt1705_uniwill_init_verbs[] = {
3479 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3480 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3481 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3482 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3483 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3484 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3485 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3486 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3490 static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3494 .nid = 0x10, /* NID to query formats and rates */
3496 .open = via_playback_pcm_open,
3497 .prepare = via_playback_multi_pcm_prepare,
3498 .cleanup = via_playback_multi_pcm_cleanup,
3499 .close = via_pcm_open_close
3503 static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
3507 .nid = 0x10, /* NID to query formats and rates */
3509 .open = via_playback_pcm_open,
3510 .prepare = via_playback_multi_pcm_prepare,
3511 .cleanup = via_playback_multi_pcm_cleanup,
3512 .close = via_pcm_open_close
3516 static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3520 .nid = 0x13, /* NID to query formats and rates */
3522 .open = via_pcm_open_close,
3523 .prepare = via_capture_pcm_prepare,
3524 .cleanup = via_capture_pcm_cleanup,
3525 .close = via_pcm_open_close
3529 static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3533 /* NID is set in via_build_pcms */
3535 .open = via_dig_playback_pcm_open,
3536 .close = via_dig_playback_pcm_close,
3537 .prepare = via_dig_playback_pcm_prepare,
3538 .cleanup = via_dig_playback_pcm_cleanup
3542 /* fill in the dac_nids table from the parsed pin configuration */
3543 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3544 const struct auto_pin_cfg *cfg)
3549 spec->multiout.num_dacs = cfg->line_outs;
3551 spec->multiout.dac_nids = spec->private_dac_nids;
3553 for (i = 0; i < 4; i++) {
3554 nid = cfg->line_out_pins[i];
3556 /* config dac list */
3558 case AUTO_SEQ_FRONT:
3559 spec->private_dac_nids[i] = 0x10;
3561 case AUTO_SEQ_CENLFE:
3562 if (spec->codec->vendor_id == 0x11064397)
3563 spec->private_dac_nids[i] = 0x25;
3565 spec->private_dac_nids[i] = 0x24;
3567 case AUTO_SEQ_SURROUND:
3568 spec->private_dac_nids[i] = 0x11;
3571 spec->private_dac_nids[i] = 0x25;
3577 /* for Smart 5.1, line/mic inputs double as output pins */
3578 if (cfg->line_outs == 1) {
3579 spec->multiout.num_dacs = 3;
3580 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3581 if (spec->codec->vendor_id == 0x11064397)
3582 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
3584 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3590 /* add playback controls from the parsed DAC table */
3591 static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
3592 const struct auto_pin_cfg *cfg)
3594 struct via_spec *spec = codec->spec;
3596 static const char * const chname[4] = {
3597 "Front", "Surround", "C/LFE", "Side"
3599 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3600 {0x10, 0x11, 0x25, 0} };
3601 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3602 {0x1C, 0x18, 0x27, 0} };
3603 hda_nid_t nid, nid_vol, nid_mute;
3606 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3607 nid = cfg->line_out_pins[i];
3609 /* for Smart 5.1, there are always at least six channels */
3610 if (!nid && i > AUTO_SEQ_CENLFE)
3613 if (codec->vendor_id == 0x11064397) {
3614 nid_vol = nid_vols[1][i];
3615 nid_mute = nid_mutes[1][i];
3617 nid_vol = nid_vols[0][i];
3618 nid_mute = nid_mutes[0][i];
3620 if (!nid_vol && !nid_mute)
3623 if (i == AUTO_SEQ_CENLFE) {
3625 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3626 "Center Playback Volume",
3627 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3631 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3632 "LFE Playback Volume",
3633 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3637 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3638 "Center Playback Switch",
3639 HDA_COMPOSE_AMP_VAL(nid_mute,
3644 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3645 "LFE Playback Switch",
3646 HDA_COMPOSE_AMP_VAL(nid_mute,
3651 } else if (i == AUTO_SEQ_FRONT) {
3652 /* add control to mixer index 0 */
3653 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3654 "Master Front Playback Volume",
3655 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3659 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3660 "Master Front Playback Switch",
3661 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3667 sprintf(name, "%s Playback Volume", chname[i]);
3668 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3669 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3673 sprintf(name, "%s Playback Switch", chname[i]);
3674 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3675 HDA_COMPOSE_AMP_VAL(nid_mute,
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,
3700 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3707 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3708 spec->hp_independent_mode_index = 1;
3710 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3711 "Headphone Playback Volume",
3712 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3716 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3717 "Headphone Playback Switch",
3718 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3722 create_hp_imux(spec);
3727 /* create playback/capture controls for input pins */
3728 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3729 const struct auto_pin_cfg *cfg)
3731 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
3734 /* fill out digital output widgets; one for master and one for slave outputs */
3735 static void fill_dig_outs(struct hda_codec *codec)
3737 struct via_spec *spec = codec->spec;
3740 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3744 nid = spec->autocfg.dig_out_pins[i];
3747 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3750 if (!spec->multiout.dig_out_nid)
3751 spec->multiout.dig_out_nid = nid;
3753 spec->slave_dig_outs[0] = nid;
3754 break; /* at most two dig outs */
3759 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3761 struct via_spec *spec = codec->spec;
3764 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3767 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3770 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3771 return 0; /* can't find valid BIOS pin config */
3773 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
3776 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3779 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
3783 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3785 fill_dig_outs(codec);
3787 if (spec->kctls.list)
3788 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3790 spec->input_mux = &spec->private_imux[0];
3793 via_hp_build(codec);
3795 via_smart51_build(spec);
3799 #ifdef CONFIG_SND_HDA_POWER_SAVE
3800 static const struct hda_amp_list vt1708S_loopbacks[] = {
3801 { 0x16, HDA_INPUT, 1 },
3802 { 0x16, HDA_INPUT, 2 },
3803 { 0x16, HDA_INPUT, 3 },
3804 { 0x16, HDA_INPUT, 4 },
3809 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3810 int offset, int num_steps, int step_size)
3812 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3813 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3814 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3815 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3816 (0 << AC_AMPCAP_MUTE_SHIFT));
3819 static int patch_vt1708S(struct hda_codec *codec)
3821 struct via_spec *spec;
3824 /* create a codec specific record */
3825 spec = via_new_spec(codec);
3829 /* automatic parse from the BIOS config */
3830 err = vt1708S_parse_auto_config(codec);
3835 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3836 "from BIOS. Using genenic mode...\n");
3839 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3840 if (codec->vendor_id == 0x11064397)
3841 spec->init_verbs[spec->num_iverbs++] =
3842 vt1705_uniwill_init_verbs;
3844 spec->init_verbs[spec->num_iverbs++] =
3845 vt1708S_uniwill_init_verbs;
3847 if (codec->vendor_id == 0x11064397)
3848 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3850 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
3851 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3853 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3855 if (spec->adc_nids && spec->input_mux) {
3856 override_mic_boost(codec, 0x1a, 0, 3, 40);
3857 override_mic_boost(codec, 0x1e, 0, 3, 40);
3858 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3862 codec->patch_ops = via_patch_ops;
3864 codec->patch_ops.init = via_auto_init;
3865 codec->patch_ops.unsol_event = via_unsol_event;
3866 #ifdef CONFIG_SND_HDA_POWER_SAVE
3867 spec->loopback.amplist = vt1708S_loopbacks;
3870 /* correct names for VT1708BCE */
3871 if (get_codec_type(codec) == VT1708BCE) {
3872 kfree(codec->chip_name);
3873 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3874 snprintf(codec->bus->card->mixername,
3875 sizeof(codec->bus->card->mixername),
3876 "%s %s", codec->vendor_name, codec->chip_name);
3878 /* correct names for VT1705 */
3879 if (codec->vendor_id == 0x11064397) {
3880 kfree(codec->chip_name);
3881 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3882 snprintf(codec->bus->card->mixername,
3883 sizeof(codec->bus->card->mixername),
3884 "%s %s", codec->vendor_name, codec->chip_name);
3886 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3890 /* Patch for VT1702 */
3892 /* capture mixer elements */
3893 static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
3894 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3895 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3896 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3897 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3898 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3899 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3900 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3903 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3904 /* The multiple "Capture Source" controls confuse alsamixer
3905 * So call somewhat different..
3907 /* .name = "Capture Source", */
3908 .name = "Input Source",
3910 .info = via_mux_enum_info,
3911 .get = via_mux_enum_get,
3912 .put = via_mux_enum_put,
3917 static const struct hda_verb vt1702_volume_init_verbs[] = {
3919 * Unmute ADC0-1 and set the default input to mic-in
3921 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3922 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3923 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3926 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3929 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3930 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3931 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3932 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3933 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3934 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3936 /* Setup default input of PW4 to MW0 */
3937 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3938 /* PW6 PW7 Output enable */
3939 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3940 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3948 static const struct hda_verb vt1702_uniwill_init_verbs[] = {
3949 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3950 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3951 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3952 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3953 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3954 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3958 static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
3962 .nid = 0x10, /* NID to query formats and rates */
3964 .open = via_playback_pcm_open,
3965 .prepare = via_playback_multi_pcm_prepare,
3966 .cleanup = via_playback_multi_pcm_cleanup,
3967 .close = via_pcm_open_close
3971 static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
3975 .nid = 0x12, /* NID to query formats and rates */
3977 .open = via_pcm_open_close,
3978 .prepare = via_capture_pcm_prepare,
3979 .cleanup = via_capture_pcm_cleanup,
3980 .close = via_pcm_open_close
3984 static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
3988 /* NID is set in via_build_pcms */
3990 .open = via_dig_playback_pcm_open,
3991 .close = via_dig_playback_pcm_close,
3992 .prepare = via_dig_playback_pcm_prepare,
3993 .cleanup = via_dig_playback_pcm_cleanup
3997 /* fill in the dac_nids table from the parsed pin configuration */
3998 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
3999 const struct auto_pin_cfg *cfg)
4001 spec->multiout.num_dacs = 1;
4002 spec->multiout.dac_nids = spec->private_dac_nids;
4004 if (cfg->line_out_pins[0]) {
4005 /* config dac list */
4006 spec->private_dac_nids[0] = 0x10;
4012 /* add playback controls from the parsed DAC table */
4013 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4014 const struct auto_pin_cfg *cfg)
4018 if (!cfg->line_out_pins[0])
4021 /* add control to mixer index 0 */
4022 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4023 "Master Front Playback Volume",
4024 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4027 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4028 "Master Front Playback Switch",
4029 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4034 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4035 "Front Playback Volume",
4036 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4039 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4040 "Front Playback Switch",
4041 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4048 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4051 struct hda_input_mux *imux;
4052 static const char * const texts[] = { "ON", "OFF", NULL};
4055 spec->multiout.hp_nid = 0x1D;
4056 spec->hp_independent_mode_index = 0;
4058 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4059 "Headphone Playback Volume",
4060 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4064 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4065 "Headphone Playback Switch",
4066 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4070 imux = &spec->private_imux[1];
4072 /* for hp mode select */
4073 for (i = 0; texts[i]; i++)
4074 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4076 spec->hp_mux = &spec->private_imux[1];
4080 /* create playback/capture controls for input pins */
4081 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4082 const struct auto_pin_cfg *cfg)
4084 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a);
4087 static int vt1702_parse_auto_config(struct hda_codec *codec)
4089 struct via_spec *spec = codec->spec;
4092 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4095 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4098 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4099 return 0; /* can't find valid BIOS pin config */
4101 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4104 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4107 /* limit AA path volume to 0 dB */
4108 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4109 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4110 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4111 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4112 (1 << AC_AMPCAP_MUTE_SHIFT));
4113 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4117 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4119 fill_dig_outs(codec);
4121 if (spec->kctls.list)
4122 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4124 spec->input_mux = &spec->private_imux[0];
4127 via_hp_build(codec);
4132 #ifdef CONFIG_SND_HDA_POWER_SAVE
4133 static const struct hda_amp_list vt1702_loopbacks[] = {
4134 { 0x1A, HDA_INPUT, 1 },
4135 { 0x1A, HDA_INPUT, 2 },
4136 { 0x1A, HDA_INPUT, 3 },
4137 { 0x1A, HDA_INPUT, 4 },
4142 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4144 int imux_is_smixer =
4145 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4148 /* PW 1/2/5 (14h/15h/18h) */
4150 set_pin_power_state(codec, 0x14, &parm);
4151 set_pin_power_state(codec, 0x15, &parm);
4152 set_pin_power_state(codec, 0x18, &parm);
4154 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4155 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4156 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4157 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4158 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4159 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4162 /* PW 3/4 (16h/17h) */
4164 set_pin_power_state(codec, 0x17, &parm);
4165 set_pin_power_state(codec, 0x16, &parm);
4166 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4167 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4168 imux_is_smixer ? AC_PWRST_D0 : parm);
4169 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4170 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4173 static int patch_vt1702(struct hda_codec *codec)
4175 struct via_spec *spec;
4178 /* create a codec specific record */
4179 spec = via_new_spec(codec);
4183 /* automatic parse from the BIOS config */
4184 err = vt1702_parse_auto_config(codec);
4189 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4190 "from BIOS. Using genenic mode...\n");
4193 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4194 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4196 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4197 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4199 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4201 if (spec->adc_nids && spec->input_mux) {
4202 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4206 codec->patch_ops = via_patch_ops;
4208 codec->patch_ops.init = via_auto_init;
4209 codec->patch_ops.unsol_event = via_unsol_event;
4210 #ifdef CONFIG_SND_HDA_POWER_SAVE
4211 spec->loopback.amplist = vt1702_loopbacks;
4214 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
4218 /* Patch for VT1718S */
4220 /* capture mixer elements */
4221 static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4222 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4223 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4224 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4225 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4226 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4227 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4230 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4231 /* The multiple "Capture Source" controls confuse alsamixer
4232 * So call somewhat different..
4234 .name = "Input Source",
4236 .info = via_mux_enum_info,
4237 .get = via_mux_enum_get,
4238 .put = via_mux_enum_put,
4243 static const struct hda_verb vt1718S_volume_init_verbs[] = {
4245 * Unmute ADC0-1 and set the default input to mic-in
4247 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4248 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4250 /* Enable MW0 adjust Gain 5 */
4252 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4255 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4256 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4257 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4258 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4259 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4260 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
4262 /* Setup default input of Front HP to MW9 */
4263 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4264 /* PW9 PW10 Output enable */
4265 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4266 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4267 /* PW11 Input enable */
4268 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4269 /* Enable Boost Volume backdoor */
4271 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4272 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4273 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4274 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4275 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4276 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4277 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4278 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4279 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4280 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4281 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4282 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4283 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4284 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4285 /* Unmute MW4's index 0 */
4286 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4291 static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
4292 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4293 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4294 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4295 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4296 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4297 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4298 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4299 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4300 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4304 static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4308 .nid = 0x8, /* NID to query formats and rates */
4310 .open = via_playback_pcm_open,
4311 .prepare = via_playback_multi_pcm_prepare,
4312 .cleanup = via_playback_multi_pcm_cleanup,
4313 .close = via_pcm_open_close,
4317 static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4321 .nid = 0x10, /* NID to query formats and rates */
4323 .open = via_pcm_open_close,
4324 .prepare = via_capture_pcm_prepare,
4325 .cleanup = via_capture_pcm_cleanup,
4326 .close = via_pcm_open_close,
4330 static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4334 /* NID is set in via_build_pcms */
4336 .open = via_dig_playback_pcm_open,
4337 .close = via_dig_playback_pcm_close,
4338 .prepare = via_dig_playback_pcm_prepare,
4339 .cleanup = via_dig_playback_pcm_cleanup
4343 static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4349 /* fill in the dac_nids table from the parsed pin configuration */
4350 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4351 const struct auto_pin_cfg *cfg)
4356 spec->multiout.num_dacs = cfg->line_outs;
4358 spec->multiout.dac_nids = spec->private_dac_nids;
4360 for (i = 0; i < 4; i++) {
4361 nid = cfg->line_out_pins[i];
4363 /* config dac list */
4365 case AUTO_SEQ_FRONT:
4366 spec->private_dac_nids[i] = 0x8;
4368 case AUTO_SEQ_CENLFE:
4369 spec->private_dac_nids[i] = 0xa;
4371 case AUTO_SEQ_SURROUND:
4372 spec->private_dac_nids[i] = 0x9;
4375 spec->private_dac_nids[i] = 0xb;
4384 /* add playback controls from the parsed DAC table */
4385 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4386 const struct auto_pin_cfg *cfg)
4389 static const char * const chname[4] = {
4390 "Front", "Surround", "C/LFE", "Side"
4392 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4393 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4394 hda_nid_t nid, nid_vol, nid_mute = 0;
4397 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4398 nid = cfg->line_out_pins[i];
4402 nid_vol = nid_vols[i];
4403 nid_mute = nid_mutes[i];
4405 if (i == AUTO_SEQ_CENLFE) {
4407 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4408 "Center Playback Volume",
4409 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4413 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4414 "LFE Playback Volume",
4415 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4419 err = via_add_control(
4420 spec, VIA_CTL_WIDGET_MUTE,
4421 "Center Playback Switch",
4422 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4426 err = via_add_control(
4427 spec, VIA_CTL_WIDGET_MUTE,
4428 "LFE Playback Switch",
4429 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4433 } else if (i == AUTO_SEQ_FRONT) {
4435 sprintf(name, "%s Playback Volume", chname[i]);
4436 err = via_add_control(
4437 spec, VIA_CTL_WIDGET_VOL, name,
4438 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4441 sprintf(name, "%s Playback Switch", chname[i]);
4442 err = via_add_control(
4443 spec, VIA_CTL_WIDGET_MUTE, name,
4444 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
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,
4467 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4474 spec->multiout.hp_nid = 0xc; /* AOW4 */
4475 spec->hp_independent_mode_index = 1;
4477 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4478 "Headphone Playback Volume",
4479 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4483 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4484 "Headphone Playback Switch",
4485 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4489 create_hp_imux(spec);
4493 /* create playback/capture controls for input pins */
4494 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4495 const struct auto_pin_cfg *cfg)
4497 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
4500 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4502 struct via_spec *spec = codec->spec;
4505 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4509 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4512 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4513 return 0; /* can't find valid BIOS pin config */
4515 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4518 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4521 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4525 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4527 fill_dig_outs(codec);
4529 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4530 spec->dig_in_nid = 0x13;
4532 if (spec->kctls.list)
4533 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4535 spec->input_mux = &spec->private_imux[0];
4538 via_hp_build(codec);
4540 via_smart51_build(spec);
4545 #ifdef CONFIG_SND_HDA_POWER_SAVE
4546 static const struct hda_amp_list vt1718S_loopbacks[] = {
4547 { 0x21, HDA_INPUT, 1 },
4548 { 0x21, HDA_INPUT, 2 },
4549 { 0x21, HDA_INPUT, 3 },
4550 { 0x21, HDA_INPUT, 4 },
4555 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4557 struct via_spec *spec = codec->spec;
4560 /* MUX6 (1eh) = stereo mixer */
4562 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4564 /* PW 5/6/7 (29h/2ah/2bh) */
4566 set_pin_power_state(codec, 0x29, &parm);
4567 set_pin_power_state(codec, 0x2a, &parm);
4568 set_pin_power_state(codec, 0x2b, &parm);
4571 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4572 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4573 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4574 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4575 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4578 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4580 set_pin_power_state(codec, 0x27, &parm);
4581 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4582 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4584 /* PW2 (26h), AOW2 (ah) */
4586 set_pin_power_state(codec, 0x26, &parm);
4587 if (spec->smart51_enabled)
4588 set_pin_power_state(codec, 0x2b, &parm);
4589 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4591 /* PW0 (24h), AOW0 (8h) */
4593 set_pin_power_state(codec, 0x24, &parm);
4594 if (!spec->hp_independent_mode) /* check for redirected HP */
4595 set_pin_power_state(codec, 0x28, &parm);
4596 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4597 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4598 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4599 imux_is_smixer ? AC_PWRST_D0 : parm);
4601 /* PW1 (25h), AOW1 (9h) */
4603 set_pin_power_state(codec, 0x25, &parm);
4604 if (spec->smart51_enabled)
4605 set_pin_power_state(codec, 0x2a, &parm);
4606 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4608 if (spec->hp_independent_mode) {
4609 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4611 set_pin_power_state(codec, 0x28, &parm);
4612 snd_hda_codec_write(codec, 0x1b, 0,
4613 AC_VERB_SET_POWER_STATE, parm);
4614 snd_hda_codec_write(codec, 0x34, 0,
4615 AC_VERB_SET_POWER_STATE, parm);
4616 snd_hda_codec_write(codec, 0xc, 0,
4617 AC_VERB_SET_POWER_STATE, parm);
4621 static int patch_vt1718S(struct hda_codec *codec)
4623 struct via_spec *spec;
4626 /* create a codec specific record */
4627 spec = via_new_spec(codec);
4631 /* automatic parse from the BIOS config */
4632 err = vt1718S_parse_auto_config(codec);
4637 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4638 "from BIOS. Using genenic mode...\n");
4641 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4642 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4644 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4645 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4647 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4648 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4649 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4651 if (spec->adc_nids && spec->input_mux) {
4652 override_mic_boost(codec, 0x2b, 0, 3, 40);
4653 override_mic_boost(codec, 0x29, 0, 3, 40);
4654 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4658 codec->patch_ops = via_patch_ops;
4660 codec->patch_ops.init = via_auto_init;
4661 codec->patch_ops.unsol_event = via_unsol_event;
4663 #ifdef CONFIG_SND_HDA_POWER_SAVE
4664 spec->loopback.amplist = vt1718S_loopbacks;
4667 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4672 /* Patch for VT1716S */
4674 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4675 struct snd_ctl_elem_info *uinfo)
4677 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4679 uinfo->value.integer.min = 0;
4680 uinfo->value.integer.max = 1;
4684 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4685 struct snd_ctl_elem_value *ucontrol)
4687 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4690 index = snd_hda_codec_read(codec, 0x26, 0,
4691 AC_VERB_GET_CONNECT_SEL, 0);
4693 *ucontrol->value.integer.value = index;
4698 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4699 struct snd_ctl_elem_value *ucontrol)
4701 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4702 struct via_spec *spec = codec->spec;
4703 int index = *ucontrol->value.integer.value;
4705 snd_hda_codec_write(codec, 0x26, 0,
4706 AC_VERB_SET_CONNECT_SEL, index);
4707 spec->dmic_enabled = index;
4708 set_widgets_power_state(codec);
4712 /* capture mixer elements */
4713 static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4714 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4715 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4716 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4717 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4718 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4719 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4722 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4723 .name = "Input Source",
4725 .info = via_mux_enum_info,
4726 .get = via_mux_enum_get,
4727 .put = via_mux_enum_put,
4732 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4733 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4736 .name = "Digital Mic Capture Switch",
4737 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4739 .info = vt1716s_dmic_info,
4740 .get = vt1716s_dmic_get,
4741 .put = vt1716s_dmic_put,
4747 /* mono-out mixer elements */
4748 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4749 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4753 static const struct hda_verb vt1716S_volume_init_verbs[] = {
4755 * Unmute ADC0-1 and set the default input to mic-in
4757 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4761 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4764 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4765 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4766 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4767 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4768 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4769 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4771 /* MUX Indices: Stereo Mixer = 5 */
4772 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4774 /* Setup default input of PW4 to MW0 */
4775 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4777 /* Setup default input of SW1 as MW0 */
4778 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4780 /* Setup default input of SW4 as AOW0 */
4781 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4783 /* PW9 PW10 Output enable */
4784 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4785 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4787 /* Unmute SW1, PW12 */
4788 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4789 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4790 /* PW12 Output enable */
4791 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4792 /* Enable Boost Volume backdoor */
4794 /* don't bybass mixer */
4796 /* Enable mono output */
4802 static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
4803 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4804 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4805 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4806 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4807 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4808 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4809 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4810 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4811 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4815 static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4819 .nid = 0x10, /* NID to query formats and rates */
4821 .open = via_playback_pcm_open,
4822 .prepare = via_playback_multi_pcm_prepare,
4823 .cleanup = via_playback_multi_pcm_cleanup,
4824 .close = via_pcm_open_close,
4828 static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
4832 .nid = 0x13, /* NID to query formats and rates */
4834 .open = via_pcm_open_close,
4835 .prepare = via_capture_pcm_prepare,
4836 .cleanup = via_capture_pcm_cleanup,
4837 .close = via_pcm_open_close,
4841 static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
4845 /* NID is set in via_build_pcms */
4847 .open = via_dig_playback_pcm_open,
4848 .close = via_dig_playback_pcm_close,
4849 .prepare = via_dig_playback_pcm_prepare,
4850 .cleanup = via_dig_playback_pcm_cleanup
4854 /* fill in the dac_nids table from the parsed pin configuration */
4855 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4856 const struct auto_pin_cfg *cfg)
4860 spec->multiout.num_dacs = cfg->line_outs;
4862 spec->multiout.dac_nids = spec->private_dac_nids;
4864 for (i = 0; i < 3; i++) {
4865 nid = cfg->line_out_pins[i];
4867 /* config dac list */
4869 case AUTO_SEQ_FRONT:
4870 spec->private_dac_nids[i] = 0x10;
4872 case AUTO_SEQ_CENLFE:
4873 spec->private_dac_nids[i] = 0x25;
4875 case AUTO_SEQ_SURROUND:
4876 spec->private_dac_nids[i] = 0x11;
4885 /* add playback controls from the parsed DAC table */
4886 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4887 const struct auto_pin_cfg *cfg)
4890 static const char * const chname[3] = {
4891 "Front", "Surround", "C/LFE"
4893 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4894 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4895 hda_nid_t nid, nid_vol, nid_mute;
4898 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4899 nid = cfg->line_out_pins[i];
4904 nid_vol = nid_vols[i];
4905 nid_mute = nid_mutes[i];
4907 if (i == AUTO_SEQ_CENLFE) {
4908 err = via_add_control(
4909 spec, VIA_CTL_WIDGET_VOL,
4910 "Center Playback Volume",
4911 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4914 err = via_add_control(
4915 spec, VIA_CTL_WIDGET_VOL,
4916 "LFE Playback Volume",
4917 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4920 err = via_add_control(
4921 spec, VIA_CTL_WIDGET_MUTE,
4922 "Center Playback Switch",
4923 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4927 err = via_add_control(
4928 spec, VIA_CTL_WIDGET_MUTE,
4929 "LFE Playback Switch",
4930 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4934 } else if (i == AUTO_SEQ_FRONT) {
4936 err = via_add_control(
4937 spec, VIA_CTL_WIDGET_VOL,
4938 "Master Front Playback Volume",
4939 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4942 err = via_add_control(
4943 spec, VIA_CTL_WIDGET_MUTE,
4944 "Master Front Playback Switch",
4945 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4949 sprintf(name, "%s Playback Volume", chname[i]);
4950 err = via_add_control(
4951 spec, VIA_CTL_WIDGET_VOL, name,
4952 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4955 sprintf(name, "%s Playback Switch", chname[i]);
4956 err = via_add_control(
4957 spec, VIA_CTL_WIDGET_MUTE, name,
4958 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
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,
4981 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4988 spec->multiout.hp_nid = 0x25; /* AOW3 */
4989 spec->hp_independent_mode_index = 1;
4991 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4992 "Headphone Playback Volume",
4993 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
4997 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4998 "Headphone Playback Switch",
4999 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5003 create_hp_imux(spec);
5007 /* create playback/capture controls for input pins */
5008 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5009 const struct auto_pin_cfg *cfg)
5011 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
5014 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5016 struct via_spec *spec = codec->spec;
5019 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5022 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5025 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5026 return 0; /* can't find valid BIOS pin config */
5028 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5031 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5034 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5038 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5040 fill_dig_outs(codec);
5042 if (spec->kctls.list)
5043 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5045 spec->input_mux = &spec->private_imux[0];
5048 via_hp_build(codec);
5050 via_smart51_build(spec);
5055 #ifdef CONFIG_SND_HDA_POWER_SAVE
5056 static const struct hda_amp_list vt1716S_loopbacks[] = {
5057 { 0x16, HDA_INPUT, 1 },
5058 { 0x16, HDA_INPUT, 2 },
5059 { 0x16, HDA_INPUT, 3 },
5060 { 0x16, HDA_INPUT, 4 },
5065 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5067 struct via_spec *spec = codec->spec;
5070 unsigned int mono_out, present;
5071 /* SW0 (17h) = stereo mixer */
5073 (snd_hda_codec_read(codec, 0x17, 0,
5074 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5076 /* PW 1/2/5 (1ah/1bh/1eh) */
5078 set_pin_power_state(codec, 0x1a, &parm);
5079 set_pin_power_state(codec, 0x1b, &parm);
5080 set_pin_power_state(codec, 0x1e, &parm);
5083 /* SW0 (17h), AIW0(13h) */
5084 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5085 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5088 set_pin_power_state(codec, 0x1e, &parm);
5090 if (spec->dmic_enabled)
5091 set_pin_power_state(codec, 0x22, &parm);
5093 snd_hda_codec_write(codec, 0x22, 0,
5094 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5096 /* SW2(26h), AIW1(14h) */
5097 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5098 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5101 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5103 set_pin_power_state(codec, 0x19, &parm);
5104 /* Smart 5.1 PW2(1bh) */
5105 if (spec->smart51_enabled)
5106 set_pin_power_state(codec, 0x1b, &parm);
5107 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5108 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5110 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5112 set_pin_power_state(codec, 0x23, &parm);
5113 /* Smart 5.1 PW1(1ah) */
5114 if (spec->smart51_enabled)
5115 set_pin_power_state(codec, 0x1a, &parm);
5116 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5118 /* Smart 5.1 PW5(1eh) */
5119 if (spec->smart51_enabled)
5120 set_pin_power_state(codec, 0x1e, &parm);
5121 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5124 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5125 present = snd_hda_jack_detect(codec, 0x1c);
5130 present = snd_hda_jack_detect(codec, 0x1d);
5131 if (!spec->hp_independent_mode && present)
5136 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5137 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5138 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5139 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5141 /* PW 3/4 (1ch/1dh) */
5143 set_pin_power_state(codec, 0x1c, &parm);
5144 set_pin_power_state(codec, 0x1d, &parm);
5145 /* HP Independent Mode, power on AOW3 */
5146 if (spec->hp_independent_mode)
5147 snd_hda_codec_write(codec, 0x25, 0,
5148 AC_VERB_SET_POWER_STATE, parm);
5150 /* force to D0 for internal Speaker */
5151 /* MW0 (16h), AOW0 (10h) */
5152 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5153 imux_is_smixer ? AC_PWRST_D0 : parm);
5154 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5155 mono_out ? AC_PWRST_D0 : parm);
5158 static int patch_vt1716S(struct hda_codec *codec)
5160 struct via_spec *spec;
5163 /* create a codec specific record */
5164 spec = via_new_spec(codec);
5168 /* automatic parse from the BIOS config */
5169 err = vt1716S_parse_auto_config(codec);
5174 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5175 "from BIOS. Using genenic mode...\n");
5178 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5179 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5181 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5182 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5184 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5186 if (spec->adc_nids && spec->input_mux) {
5187 override_mic_boost(codec, 0x1a, 0, 3, 40);
5188 override_mic_boost(codec, 0x1e, 0, 3, 40);
5189 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5193 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5196 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5198 codec->patch_ops = via_patch_ops;
5200 codec->patch_ops.init = via_auto_init;
5201 codec->patch_ops.unsol_event = via_unsol_event;
5203 #ifdef CONFIG_SND_HDA_POWER_SAVE
5204 spec->loopback.amplist = vt1716S_loopbacks;
5207 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
5213 /* capture mixer elements */
5214 static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5215 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5216 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5217 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5218 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5219 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5220 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5223 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5224 /* The multiple "Capture Source" controls confuse alsamixer
5225 * So call somewhat different..
5227 /* .name = "Capture Source", */
5228 .name = "Input Source",
5230 .info = via_mux_enum_info,
5231 .get = via_mux_enum_get,
5232 .put = via_mux_enum_put,
5237 static const struct hda_verb vt2002P_volume_init_verbs[] = {
5238 /* Class-D speaker related verbs */
5243 * Unmute ADC0-1 and set the default input to mic-in
5245 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5246 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5249 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5252 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5253 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5254 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5255 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5256 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5257 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5259 /* MUX Indices: Mic = 0 */
5260 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5261 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5263 /* PW9 Output enable */
5264 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5266 /* Enable Boost Volume backdoor */
5269 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5270 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5271 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5272 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5273 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5274 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5275 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5276 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5277 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5279 /* set MUX0/1/4/8 = 0 (AOW0) */
5280 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5281 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5282 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5283 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5285 /* set PW0 index=0 (MW0) */
5286 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5288 /* Enable AOW0 to MW9 */
5292 static const struct hda_verb vt1802_volume_init_verbs[] = {
5294 * Unmute ADC0-1 and set the default input to mic-in
5296 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5297 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5300 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5303 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5304 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5305 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5306 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5307 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5308 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5310 /* MUX Indices: Mic = 0 */
5311 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5312 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5314 /* PW9 Output enable */
5315 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5317 /* Enable Boost Volume backdoor */
5320 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5321 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5322 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5323 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5324 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5325 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5326 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5327 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5328 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5330 /* set MUX0/1/4/8 = 0 (AOW0) */
5331 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5332 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5333 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5334 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5336 /* set PW0 index=0 (MW0) */
5337 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5339 /* Enable AOW0 to MW9 */
5345 static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
5346 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5347 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5348 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5349 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5350 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5351 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5352 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5355 static const struct hda_verb vt1802_uniwill_init_verbs[] = {
5356 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5357 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5358 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5359 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5360 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5361 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5362 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5366 static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5370 .nid = 0x8, /* NID to query formats and rates */
5372 .open = via_playback_pcm_open,
5373 .prepare = via_playback_multi_pcm_prepare,
5374 .cleanup = via_playback_multi_pcm_cleanup,
5375 .close = via_pcm_open_close,
5379 static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5383 .nid = 0x10, /* NID to query formats and rates */
5385 .open = via_pcm_open_close,
5386 .prepare = via_capture_pcm_prepare,
5387 .cleanup = via_capture_pcm_cleanup,
5388 .close = via_pcm_open_close,
5392 static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5396 /* NID is set in via_build_pcms */
5398 .open = via_dig_playback_pcm_open,
5399 .close = via_dig_playback_pcm_close,
5400 .prepare = via_dig_playback_pcm_prepare,
5401 .cleanup = via_dig_playback_pcm_cleanup
5405 /* fill in the dac_nids table from the parsed pin configuration */
5406 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5407 const struct auto_pin_cfg *cfg)
5409 spec->multiout.num_dacs = 1;
5410 spec->multiout.dac_nids = spec->private_dac_nids;
5411 if (cfg->line_out_pins[0])
5412 spec->private_dac_nids[0] = 0x8;
5416 /* add playback controls from the parsed DAC table */
5417 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5418 const struct auto_pin_cfg *cfg)
5423 if (!cfg->line_out_pins[0])
5426 if (spec->codec_type == VT1802)
5431 /* Line-Out: PortE */
5432 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5433 "Master Front Playback Volume",
5434 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5437 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5438 "Master Front Playback Switch",
5439 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
5446 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5453 spec->multiout.hp_nid = 0x9;
5454 spec->hp_independent_mode_index = 1;
5456 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5457 "Headphone Playback Volume",
5458 HDA_COMPOSE_AMP_VAL(
5459 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5463 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5464 "Headphone Playback Switch",
5465 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5469 create_hp_imux(spec);
5473 /* create playback/capture controls for input pins */
5474 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5475 const struct auto_pin_cfg *cfg)
5477 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
5480 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5482 struct via_spec *spec = codec->spec;
5486 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5490 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5494 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5495 return 0; /* can't find valid BIOS pin config */
5497 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5500 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5503 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5507 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5509 fill_dig_outs(codec);
5511 if (spec->kctls.list)
5512 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5514 spec->input_mux = &spec->private_imux[0];
5517 via_hp_build(codec);
5522 #ifdef CONFIG_SND_HDA_POWER_SAVE
5523 static const struct hda_amp_list vt2002P_loopbacks[] = {
5524 { 0x21, HDA_INPUT, 0 },
5525 { 0x21, HDA_INPUT, 1 },
5526 { 0x21, HDA_INPUT, 2 },
5531 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5533 struct via_spec *spec = codec->spec;
5536 unsigned int present;
5537 /* MUX9 (1eh) = stereo mixer */
5539 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5541 /* PW 5/6/7 (29h/2ah/2bh) */
5543 set_pin_power_state(codec, 0x29, &parm);
5544 set_pin_power_state(codec, 0x2a, &parm);
5545 set_pin_power_state(codec, 0x2b, &parm);
5547 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5548 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5549 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5550 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5551 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5555 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5557 if (spec->codec_type == VT1802) {
5558 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5560 set_pin_power_state(codec, 0x28, &parm);
5561 snd_hda_codec_write(codec, 0x18, 0,
5562 AC_VERB_SET_POWER_STATE, parm);
5563 snd_hda_codec_write(codec, 0x38, 0,
5564 AC_VERB_SET_POWER_STATE, parm);
5566 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5568 set_pin_power_state(codec, 0x26, &parm);
5569 snd_hda_codec_write(codec, 0x1c, 0,
5570 AC_VERB_SET_POWER_STATE, parm);
5571 snd_hda_codec_write(codec, 0x37, 0,
5572 AC_VERB_SET_POWER_STATE, parm);
5575 if (spec->codec_type == VT1802) {
5576 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5578 set_pin_power_state(codec, 0x25, &parm);
5579 snd_hda_codec_write(codec, 0x15, 0,
5580 AC_VERB_SET_POWER_STATE, parm);
5581 snd_hda_codec_write(codec, 0x35, 0,
5582 AC_VERB_SET_POWER_STATE, parm);
5584 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5586 set_pin_power_state(codec, 0x25, &parm);
5587 snd_hda_codec_write(codec, 0x19, 0,
5588 AC_VERB_SET_POWER_STATE, parm);
5589 snd_hda_codec_write(codec, 0x35, 0,
5590 AC_VERB_SET_POWER_STATE, parm);
5593 if (spec->hp_independent_mode)
5594 snd_hda_codec_write(codec, 0x9, 0,
5595 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5598 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5599 present = snd_hda_jack_detect(codec, 0x25);
5602 set_pin_power_state(codec, 0x24, &parm);
5603 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5604 if (spec->codec_type == VT1802)
5605 snd_hda_codec_write(codec, 0x14, 0,
5606 AC_VERB_SET_POWER_STATE, parm);
5608 snd_hda_codec_write(codec, 0x18, 0,
5609 AC_VERB_SET_POWER_STATE, parm);
5610 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5613 present = snd_hda_jack_detect(codec, 0x26);
5615 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5616 if (spec->codec_type == VT1802) {
5617 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5618 snd_hda_codec_write(codec, 0x33, 0,
5619 AC_VERB_SET_POWER_STATE, parm);
5620 snd_hda_codec_write(codec, 0x1c, 0,
5621 AC_VERB_SET_POWER_STATE, parm);
5622 snd_hda_codec_write(codec, 0x3c, 0,
5623 AC_VERB_SET_POWER_STATE, parm);
5625 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5626 snd_hda_codec_write(codec, 0x31, 0,
5627 AC_VERB_SET_POWER_STATE, parm);
5628 snd_hda_codec_write(codec, 0x17, 0,
5629 AC_VERB_SET_POWER_STATE, parm);
5630 snd_hda_codec_write(codec, 0x3b, 0,
5631 AC_VERB_SET_POWER_STATE, parm);
5634 if (imux_is_smixer || !is_aa_path_mute(codec))
5635 snd_hda_codec_write(codec, 0x21, 0,
5636 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5638 snd_hda_codec_write(codec, 0x21, 0,
5639 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5642 /* patch for vt2002P */
5643 static int patch_vt2002P(struct hda_codec *codec)
5645 struct via_spec *spec;
5648 /* create a codec specific record */
5649 spec = via_new_spec(codec);
5653 /* automatic parse from the BIOS config */
5654 err = vt2002P_parse_auto_config(codec);
5659 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5660 "from BIOS. Using genenic mode...\n");
5663 if (spec->codec_type == VT1802)
5664 spec->init_verbs[spec->num_iverbs++] =
5665 vt1802_volume_init_verbs;
5667 spec->init_verbs[spec->num_iverbs++] =
5668 vt2002P_volume_init_verbs;
5670 if (spec->codec_type == VT1802)
5671 spec->init_verbs[spec->num_iverbs++] =
5672 vt1802_uniwill_init_verbs;
5674 spec->init_verbs[spec->num_iverbs++] =
5675 vt2002P_uniwill_init_verbs;
5677 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5678 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5680 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5682 if (spec->adc_nids && spec->input_mux) {
5683 override_mic_boost(codec, 0x2b, 0, 3, 40);
5684 override_mic_boost(codec, 0x29, 0, 3, 40);
5685 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5689 codec->patch_ops = via_patch_ops;
5691 codec->patch_ops.init = via_auto_init;
5692 codec->patch_ops.unsol_event = via_unsol_event;
5694 #ifdef CONFIG_SND_HDA_POWER_SAVE
5695 spec->loopback.amplist = vt2002P_loopbacks;
5698 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
5704 /* capture mixer elements */
5705 static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
5706 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5707 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5708 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5709 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5710 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5711 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5714 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5715 /* The multiple "Capture Source" controls confuse alsamixer
5716 * So call somewhat different..
5718 .name = "Input Source",
5720 .info = via_mux_enum_info,
5721 .get = via_mux_enum_get,
5722 .put = via_mux_enum_put,
5727 static const struct hda_verb vt1812_volume_init_verbs[] = {
5729 * Unmute ADC0-1 and set the default input to mic-in
5731 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5732 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5735 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5738 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5739 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5740 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5741 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5742 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5743 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5745 /* MUX Indices: Mic = 0 */
5746 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5747 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5749 /* PW9 Output enable */
5750 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5752 /* Enable Boost Volume backdoor */
5755 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5756 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5757 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5758 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5759 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5760 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5761 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5762 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5763 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5764 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5765 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5767 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5768 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5769 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5770 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5771 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5772 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5774 /* Enable AOW0 to MW9 */
5780 static const struct hda_verb vt1812_uniwill_init_verbs[] = {
5781 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5782 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5783 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5784 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5785 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5786 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5787 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5788 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5792 static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
5796 .nid = 0x8, /* NID to query formats and rates */
5798 .open = via_playback_pcm_open,
5799 .prepare = via_playback_multi_pcm_prepare,
5800 .cleanup = via_playback_multi_pcm_cleanup,
5801 .close = via_pcm_open_close,
5805 static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
5809 .nid = 0x10, /* NID to query formats and rates */
5811 .open = via_pcm_open_close,
5812 .prepare = via_capture_pcm_prepare,
5813 .cleanup = via_capture_pcm_cleanup,
5814 .close = via_pcm_open_close,
5818 static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
5822 /* NID is set in via_build_pcms */
5824 .open = via_dig_playback_pcm_open,
5825 .close = via_dig_playback_pcm_close,
5826 .prepare = via_dig_playback_pcm_prepare,
5827 .cleanup = via_dig_playback_pcm_cleanup
5830 /* fill in the dac_nids table from the parsed pin configuration */
5831 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5832 const struct auto_pin_cfg *cfg)
5834 spec->multiout.num_dacs = 1;
5835 spec->multiout.dac_nids = spec->private_dac_nids;
5836 if (cfg->line_out_pins[0])
5837 spec->private_dac_nids[0] = 0x8;
5842 /* add playback controls from the parsed DAC table */
5843 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5844 const struct auto_pin_cfg *cfg)
5848 if (!cfg->line_out_pins[0])
5851 /* Line-Out: PortE */
5852 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5853 "Front Playback Volume",
5854 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5857 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5858 "Front Playback Switch",
5859 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5866 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5873 spec->multiout.hp_nid = 0x9;
5874 spec->hp_independent_mode_index = 1;
5877 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5878 "Headphone Playback Volume",
5879 HDA_COMPOSE_AMP_VAL(
5880 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5884 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5885 "Headphone Playback Switch",
5886 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5890 create_hp_imux(spec);
5894 /* create playback/capture controls for input pins */
5895 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5896 const struct auto_pin_cfg *cfg)
5898 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
5901 static int vt1812_parse_auto_config(struct hda_codec *codec)
5903 struct via_spec *spec = codec->spec;
5907 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5910 fill_dig_outs(codec);
5911 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5915 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5916 return 0; /* can't find valid BIOS pin config */
5918 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5921 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5924 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
5928 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5930 fill_dig_outs(codec);
5932 if (spec->kctls.list)
5933 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5935 spec->input_mux = &spec->private_imux[0];
5938 via_hp_build(codec);
5943 #ifdef CONFIG_SND_HDA_POWER_SAVE
5944 static const struct hda_amp_list vt1812_loopbacks[] = {
5945 { 0x21, HDA_INPUT, 0 },
5946 { 0x21, HDA_INPUT, 1 },
5947 { 0x21, HDA_INPUT, 2 },
5952 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
5954 struct via_spec *spec = codec->spec;
5955 int imux_is_smixer =
5956 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5958 unsigned int present;
5959 /* MUX10 (1eh) = stereo mixer */
5961 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
5963 /* PW 5/6/7 (29h/2ah/2bh) */
5965 set_pin_power_state(codec, 0x29, &parm);
5966 set_pin_power_state(codec, 0x2a, &parm);
5967 set_pin_power_state(codec, 0x2b, &parm);
5969 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
5970 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5971 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5972 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5973 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5977 snd_hda_codec_write(codec, 0x8, 0,
5978 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5980 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5982 set_pin_power_state(codec, 0x28, &parm);
5983 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5984 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
5986 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5988 set_pin_power_state(codec, 0x25, &parm);
5989 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
5990 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
5991 if (spec->hp_independent_mode)
5992 snd_hda_codec_write(codec, 0x9, 0,
5993 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5995 /* Internal Speaker */
5996 /* PW0 (24h), MW0(14h), MUX0(34h) */
5997 present = snd_hda_jack_detect(codec, 0x25);
6000 set_pin_power_state(codec, 0x24, &parm);
6002 snd_hda_codec_write(codec, 0x14, 0,
6003 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6004 snd_hda_codec_write(codec, 0x34, 0,
6005 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6007 snd_hda_codec_write(codec, 0x14, 0,
6008 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6009 snd_hda_codec_write(codec, 0x34, 0,
6010 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6015 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6016 present = snd_hda_jack_detect(codec, 0x28);
6019 set_pin_power_state(codec, 0x31, &parm);
6021 snd_hda_codec_write(codec, 0x1c, 0,
6022 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6023 snd_hda_codec_write(codec, 0x3c, 0,
6024 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6025 snd_hda_codec_write(codec, 0x3e, 0,
6026 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6028 snd_hda_codec_write(codec, 0x1c, 0,
6029 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6030 snd_hda_codec_write(codec, 0x3c, 0,
6031 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6032 snd_hda_codec_write(codec, 0x3e, 0,
6033 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6036 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6038 set_pin_power_state(codec, 0x33, &parm);
6039 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6040 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6044 /* patch for vt1812 */
6045 static int patch_vt1812(struct hda_codec *codec)
6047 struct via_spec *spec;
6050 /* create a codec specific record */
6051 spec = via_new_spec(codec);
6055 /* automatic parse from the BIOS config */
6056 err = vt1812_parse_auto_config(codec);
6061 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6062 "from BIOS. Using genenic mode...\n");
6066 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6067 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6069 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6070 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6072 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6074 if (spec->adc_nids && spec->input_mux) {
6075 override_mic_boost(codec, 0x2b, 0, 3, 40);
6076 override_mic_boost(codec, 0x29, 0, 3, 40);
6077 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6081 codec->patch_ops = via_patch_ops;
6083 codec->patch_ops.init = via_auto_init;
6084 codec->patch_ops.unsol_event = via_unsol_event;
6086 #ifdef CONFIG_SND_HDA_POWER_SAVE
6087 spec->loopback.amplist = vt1812_loopbacks;
6090 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
6097 static const struct hda_codec_preset snd_hda_preset_via[] = {
6098 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6099 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6100 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6101 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6102 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6103 .patch = patch_vt1709_10ch},
6104 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6105 .patch = patch_vt1709_10ch},
6106 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6107 .patch = patch_vt1709_10ch},
6108 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6109 .patch = patch_vt1709_10ch},
6110 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6111 .patch = patch_vt1709_6ch},
6112 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6113 .patch = patch_vt1709_6ch},
6114 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6115 .patch = patch_vt1709_6ch},
6116 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6117 .patch = patch_vt1709_6ch},
6118 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6119 .patch = patch_vt1708B_8ch},
6120 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6121 .patch = patch_vt1708B_8ch},
6122 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6123 .patch = patch_vt1708B_8ch},
6124 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6125 .patch = patch_vt1708B_8ch},
6126 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6127 .patch = patch_vt1708B_4ch},
6128 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6129 .patch = patch_vt1708B_4ch},
6130 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6131 .patch = patch_vt1708B_4ch},
6132 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6133 .patch = patch_vt1708B_4ch},
6134 { .id = 0x11060397, .name = "VT1708S",
6135 .patch = patch_vt1708S},
6136 { .id = 0x11061397, .name = "VT1708S",
6137 .patch = patch_vt1708S},
6138 { .id = 0x11062397, .name = "VT1708S",
6139 .patch = patch_vt1708S},
6140 { .id = 0x11063397, .name = "VT1708S",
6141 .patch = patch_vt1708S},
6142 { .id = 0x11064397, .name = "VT1705",
6143 .patch = patch_vt1708S},
6144 { .id = 0x11065397, .name = "VT1708S",
6145 .patch = patch_vt1708S},
6146 { .id = 0x11066397, .name = "VT1708S",
6147 .patch = patch_vt1708S},
6148 { .id = 0x11067397, .name = "VT1708S",
6149 .patch = patch_vt1708S},
6150 { .id = 0x11060398, .name = "VT1702",
6151 .patch = patch_vt1702},
6152 { .id = 0x11061398, .name = "VT1702",
6153 .patch = patch_vt1702},
6154 { .id = 0x11062398, .name = "VT1702",
6155 .patch = patch_vt1702},
6156 { .id = 0x11063398, .name = "VT1702",
6157 .patch = patch_vt1702},
6158 { .id = 0x11064398, .name = "VT1702",
6159 .patch = patch_vt1702},
6160 { .id = 0x11065398, .name = "VT1702",
6161 .patch = patch_vt1702},
6162 { .id = 0x11066398, .name = "VT1702",
6163 .patch = patch_vt1702},
6164 { .id = 0x11067398, .name = "VT1702",
6165 .patch = patch_vt1702},
6166 { .id = 0x11060428, .name = "VT1718S",
6167 .patch = patch_vt1718S},
6168 { .id = 0x11064428, .name = "VT1718S",
6169 .patch = patch_vt1718S},
6170 { .id = 0x11060441, .name = "VT2020",
6171 .patch = patch_vt1718S},
6172 { .id = 0x11064441, .name = "VT1828S",
6173 .patch = patch_vt1718S},
6174 { .id = 0x11060433, .name = "VT1716S",
6175 .patch = patch_vt1716S},
6176 { .id = 0x1106a721, .name = "VT1716S",
6177 .patch = patch_vt1716S},
6178 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6179 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6180 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6181 { .id = 0x11060440, .name = "VT1818S",
6182 .patch = patch_vt1708S},
6183 { .id = 0x11060446, .name = "VT1802",
6184 .patch = patch_vt2002P},
6185 { .id = 0x11068446, .name = "VT1802",
6186 .patch = patch_vt2002P},
6190 MODULE_ALIAS("snd-hda-codec-id:1106*");
6192 static struct hda_codec_preset_list via_list = {
6193 .preset = snd_hda_preset_via,
6194 .owner = THIS_MODULE,
6197 MODULE_LICENSE("GPL");
6198 MODULE_DESCRIPTION("VIA HD-audio codec");
6200 static int __init patch_via_init(void)
6202 return snd_hda_add_codec_preset(&via_list);
6205 static void __exit patch_via_exit(void)
6207 snd_hda_delete_codec_preset(&via_list);
6210 module_init(patch_via_init)
6211 module_exit(patch_via_exit)