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/unmute outputs */
1610 static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
1611 hda_nid_t *pins, bool mute)
1614 for (i = 0; i < num_pins; i++)
1615 snd_hda_codec_write(codec, pins[i], 0,
1616 AC_VERB_SET_PIN_WIDGET_CONTROL,
1617 mute ? 0 : PIN_OUT);
1620 /* mute internal speaker if HP is plugged */
1621 static void via_hp_automute(struct hda_codec *codec)
1623 unsigned int present = 0;
1624 struct via_spec *spec = codec->spec;
1626 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1628 if (!spec->hp_independent_mode)
1629 toggle_output_mutes(codec, spec->autocfg.line_outs,
1630 spec->autocfg.line_out_pins,
1634 /* mute mono out if HP or Line out is plugged */
1635 static void via_mono_automute(struct hda_codec *codec)
1637 unsigned int hp_present, lineout_present;
1638 struct via_spec *spec = codec->spec;
1640 if (spec->codec_type != VT1716S)
1643 lineout_present = snd_hda_jack_detect(codec,
1644 spec->autocfg.line_out_pins[0]);
1646 /* Mute Mono Out if Line Out is plugged */
1647 if (lineout_present) {
1648 snd_hda_codec_write(codec, 0x2A, 0,
1649 AC_VERB_SET_PIN_WIDGET_CONTROL,
1650 lineout_present ? 0 : PIN_OUT);
1654 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1656 if (!spec->hp_independent_mode)
1657 snd_hda_codec_write(codec, 0x2A, 0,
1658 AC_VERB_SET_PIN_WIDGET_CONTROL,
1659 hp_present ? 0 : PIN_OUT);
1662 static void via_gpio_control(struct hda_codec *codec)
1664 unsigned int gpio_data;
1665 unsigned int vol_counter;
1667 unsigned int master_vol;
1669 struct via_spec *spec = codec->spec;
1671 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1672 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1674 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1675 0xF84, 0) & 0x3F0000) >> 16;
1677 vol = vol_counter & 0x1F;
1678 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1679 AC_VERB_GET_AMP_GAIN_MUTE,
1682 if (gpio_data == 0x02) {
1683 /* unmute line out */
1684 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1685 AC_VERB_SET_PIN_WIDGET_CONTROL,
1687 if (vol_counter & 0x20) {
1688 /* decrease volume */
1689 if (vol > master_vol)
1691 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1695 /* increase volume */
1696 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1698 ((master_vol+vol) > 0x2A) ? 0x2A :
1701 } else if (!(gpio_data & 0x02)) {
1703 snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
1704 AC_VERB_SET_PIN_WIDGET_CONTROL,
1709 /* mute Internal-Speaker if HP is plugged */
1710 static void via_speaker_automute(struct hda_codec *codec)
1712 unsigned int hp_present;
1713 struct via_spec *spec = codec->spec;
1715 if (!VT2002P_COMPATIBLE(spec))
1718 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1720 if (!spec->hp_independent_mode)
1721 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1722 spec->autocfg.speaker_pins,
1726 /* mute line-out and internal speaker if HP is plugged */
1727 static void via_hp_bind_automute(struct hda_codec *codec)
1730 struct via_spec *spec = codec->spec;
1732 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1735 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1736 if (!spec->hp_independent_mode)
1737 toggle_output_mutes(codec, spec->autocfg.line_outs,
1738 spec->autocfg.line_out_pins,
1742 present = snd_hda_jack_detect(codec,
1743 spec->autocfg.line_out_pins[0]);
1746 toggle_output_mutes(codec, spec->autocfg.speaker_outs,
1747 spec->autocfg.speaker_pins,
1752 /* unsolicited event for jack sensing */
1753 static void via_unsol_event(struct hda_codec *codec,
1758 if (res & VIA_JACK_EVENT)
1759 set_widgets_power_state(codec);
1761 res &= ~VIA_JACK_EVENT;
1763 if (res == VIA_HP_EVENT)
1764 via_hp_automute(codec);
1765 else if (res == VIA_GPIO_EVENT)
1766 via_gpio_control(codec);
1767 else if (res == VIA_MONO_EVENT)
1768 via_mono_automute(codec);
1769 else if (res == VIA_SPEAKER_EVENT)
1770 via_speaker_automute(codec);
1771 else if (res == VIA_BIND_HP_EVENT)
1772 via_hp_bind_automute(codec);
1775 static int via_init(struct hda_codec *codec)
1777 struct via_spec *spec = codec->spec;
1779 for (i = 0; i < spec->num_iverbs; i++)
1780 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1782 /* Lydia Add for EAPD enable */
1783 if (!spec->dig_in_nid) { /* No Digital In connection */
1784 if (spec->dig_in_pin) {
1785 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1786 AC_VERB_SET_PIN_WIDGET_CONTROL,
1788 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1789 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1791 } else /* enable SPDIF-input pin */
1792 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1793 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1795 /* assign slave outs */
1796 if (spec->slave_dig_outs[0])
1797 codec->slave_dig_outs = spec->slave_dig_outs;
1802 #ifdef SND_HDA_NEEDS_RESUME
1803 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1805 struct via_spec *spec = codec->spec;
1806 vt1708_stop_hp_work(spec);
1811 #ifdef CONFIG_SND_HDA_POWER_SAVE
1812 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1814 struct via_spec *spec = codec->spec;
1815 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1821 static const struct hda_codec_ops via_patch_ops = {
1822 .build_controls = via_build_controls,
1823 .build_pcms = via_build_pcms,
1826 #ifdef SND_HDA_NEEDS_RESUME
1827 .suspend = via_suspend,
1829 #ifdef CONFIG_SND_HDA_POWER_SAVE
1830 .check_power_status = via_check_power_status,
1834 /* fill in the dac_nids table from the parsed pin configuration */
1835 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1836 const struct auto_pin_cfg *cfg)
1841 spec->multiout.num_dacs = cfg->line_outs;
1843 spec->multiout.dac_nids = spec->private_dac_nids;
1845 for (i = 0; i < 4; i++) {
1846 nid = cfg->line_out_pins[i];
1848 /* config dac list */
1850 case AUTO_SEQ_FRONT:
1851 spec->private_dac_nids[i] = 0x10;
1853 case AUTO_SEQ_CENLFE:
1854 spec->private_dac_nids[i] = 0x12;
1856 case AUTO_SEQ_SURROUND:
1857 spec->private_dac_nids[i] = 0x11;
1860 spec->private_dac_nids[i] = 0x13;
1869 /* add playback controls from the parsed DAC table */
1870 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1871 const struct auto_pin_cfg *cfg)
1874 static const char * const chname[4] = {
1875 "Front", "Surround", "C/LFE", "Side"
1877 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1880 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1881 nid = cfg->line_out_pins[i];
1886 nid_vol = nid_vols[i];
1888 if (i == AUTO_SEQ_CENLFE) {
1890 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1891 "Center Playback Volume",
1892 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1896 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1897 "LFE Playback Volume",
1898 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1902 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1903 "Center Playback Switch",
1904 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1908 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1909 "LFE Playback Switch",
1910 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1914 } else if (i == AUTO_SEQ_FRONT) {
1915 /* add control to mixer index 0 */
1916 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1917 "Master Front Playback Volume",
1918 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1922 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1923 "Master Front Playback Switch",
1924 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1929 /* add control to PW3 */
1930 sprintf(name, "%s Playback Volume", chname[i]);
1931 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1932 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1936 sprintf(name, "%s Playback Switch", chname[i]);
1937 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1938 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1943 sprintf(name, "%s Playback Volume", chname[i]);
1944 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1945 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1949 sprintf(name, "%s Playback Switch", chname[i]);
1950 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1951 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1961 static void create_hp_imux(struct via_spec *spec)
1964 struct hda_input_mux *imux = &spec->private_imux[1];
1965 static const char * const texts[] = { "OFF", "ON", NULL};
1967 /* for hp mode select */
1968 for (i = 0; texts[i]; i++)
1969 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1971 spec->hp_mux = &spec->private_imux[1];
1974 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1981 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1982 spec->hp_independent_mode_index = 1;
1984 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1985 "Headphone Playback Volume",
1986 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1989 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1990 "Headphone Playback Switch",
1991 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1995 create_hp_imux(spec);
2000 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
2003 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
2006 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
2007 for (i = 0; i < nums; i++)
2014 static int via_fill_adcs(struct hda_codec *codec)
2016 struct via_spec *spec = codec->spec;
2017 hda_nid_t nid = codec->start_nid;
2020 for (i = 0; i < codec->num_nodes; i++, nid++) {
2021 unsigned int wcaps = get_wcaps(codec, nid);
2022 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
2024 if (wcaps & AC_WCAP_DIGITAL)
2026 if (!(wcaps & AC_WCAP_CONN_LIST))
2028 if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
2030 spec->adc_nids[spec->num_adc_nids++] = nid;
2035 static int get_mux_nids(struct hda_codec *codec);
2037 /* create playback/capture controls for input pins */
2038 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2039 const struct auto_pin_cfg *cfg,
2042 struct via_spec *spec = codec->spec;
2043 struct hda_input_mux *imux = &spec->private_imux[0];
2044 int i, err, idx, idx2, type, type_idx = 0;
2046 hda_nid_t pin_idxs[8];
2049 err = via_fill_adcs(codec);
2052 err = get_mux_nids(codec);
2055 cap_nid = spec->mux_nids[0];
2057 num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs,
2058 ARRAY_SIZE(pin_idxs));
2062 /* for internal loopback recording select */
2063 for (idx = 0; idx < num_idxs; idx++) {
2064 if (pin_idxs[idx] == mix_nid) {
2065 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2070 for (i = 0; i < cfg->num_inputs; i++) {
2072 type = cfg->inputs[i].type;
2073 for (idx = 0; idx < num_idxs; idx++)
2074 if (pin_idxs[idx] == cfg->inputs[i].pin)
2076 if (idx >= num_idxs)
2078 if (i > 0 && type == cfg->inputs[i - 1].type)
2082 label = hda_get_autocfg_input_label(codec, cfg, i);
2083 idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]);
2085 err = via_new_analog_input(spec, label, type_idx,
2089 snd_hda_add_imux_item(imux, label, idx, NULL);
2094 /* create playback/capture controls for input pins */
2095 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2096 const struct auto_pin_cfg *cfg)
2098 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17);
2101 #ifdef CONFIG_SND_HDA_POWER_SAVE
2102 static const struct hda_amp_list vt1708_loopbacks[] = {
2103 { 0x17, HDA_INPUT, 1 },
2104 { 0x17, HDA_INPUT, 2 },
2105 { 0x17, HDA_INPUT, 3 },
2106 { 0x17, HDA_INPUT, 4 },
2111 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2113 unsigned int def_conf;
2114 unsigned char seqassoc;
2116 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2117 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2118 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2119 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2120 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2121 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2122 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2128 static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
2129 struct snd_ctl_elem_value *ucontrol)
2131 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2132 struct via_spec *spec = codec->spec;
2134 if (spec->codec_type != VT1708)
2136 spec->vt1708_jack_detect =
2137 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2138 ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
2142 static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
2143 struct snd_ctl_elem_value *ucontrol)
2145 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2146 struct via_spec *spec = codec->spec;
2149 if (spec->codec_type != VT1708)
2151 spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
2152 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2153 == !spec->vt1708_jack_detect;
2154 if (spec->vt1708_jack_detect) {
2155 mute_aa_path(codec, 1);
2156 notify_aa_path_ctls(codec);
2161 static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
2162 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2163 .name = "Jack Detect",
2165 .info = snd_ctl_boolean_mono_info,
2166 .get = vt1708_jack_detect_get,
2167 .put = vt1708_jack_detect_put,
2170 static int vt1708_parse_auto_config(struct hda_codec *codec)
2172 struct via_spec *spec = codec->spec;
2175 /* Add HP and CD pin config connect bit re-config action */
2176 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2177 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2179 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2182 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2185 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2186 return 0; /* can't find valid BIOS pin config */
2188 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2191 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2194 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2197 /* add jack detect on/off control */
2198 if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
2201 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2203 if (spec->autocfg.dig_outs)
2204 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2205 spec->dig_in_pin = VT1708_DIGIN_PIN;
2206 if (spec->autocfg.dig_in_pin)
2207 spec->dig_in_nid = VT1708_DIGIN_NID;
2209 if (spec->kctls.list)
2210 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2212 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2214 spec->input_mux = &spec->private_imux[0];
2217 via_hp_build(codec);
2219 via_smart51_build(spec);
2223 /* init callback for auto-configuration model -- overriding the default init */
2224 static int via_auto_init(struct hda_codec *codec)
2226 struct via_spec *spec = codec->spec;
2229 via_auto_init_multi_out(codec);
2230 via_auto_init_hp_out(codec);
2231 via_auto_init_analog_input(codec);
2233 if (VT2002P_COMPATIBLE(spec)) {
2234 via_hp_bind_automute(codec);
2236 via_hp_automute(codec);
2237 via_speaker_automute(codec);
2243 static void vt1708_update_hp_jack_state(struct work_struct *work)
2245 struct via_spec *spec = container_of(work, struct via_spec,
2246 vt1708_hp_work.work);
2247 if (spec->codec_type != VT1708)
2249 /* if jack state toggled */
2250 if (spec->vt1708_hp_present
2251 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2252 spec->vt1708_hp_present ^= 1;
2253 via_hp_automute(spec->codec);
2255 vt1708_start_hp_work(spec);
2258 static int get_mux_nids(struct hda_codec *codec)
2260 struct via_spec *spec = codec->spec;
2261 hda_nid_t nid, conn[8];
2265 for (i = 0; i < spec->num_adc_nids; i++) {
2266 nid = spec->adc_nids[i];
2268 type = get_wcaps_type(get_wcaps(codec, nid));
2269 if (type == AC_WID_PIN)
2271 n = snd_hda_get_connections(codec, nid, conn,
2276 spec->mux_nids[i] = nid;
2285 static int patch_vt1708(struct hda_codec *codec)
2287 struct via_spec *spec;
2290 /* create a codec specific record */
2291 spec = via_new_spec(codec);
2295 /* automatic parse from the BIOS config */
2296 err = vt1708_parse_auto_config(codec);
2301 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2302 "from BIOS. Using genenic mode...\n");
2306 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2307 /* disable 32bit format on VT1708 */
2308 if (codec->vendor_id == 0x11061708)
2309 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2310 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2312 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2313 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2315 if (spec->adc_nids && spec->input_mux) {
2316 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2320 codec->patch_ops = via_patch_ops;
2322 codec->patch_ops.init = via_auto_init;
2323 #ifdef CONFIG_SND_HDA_POWER_SAVE
2324 spec->loopback.amplist = vt1708_loopbacks;
2326 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2330 /* capture mixer elements */
2331 static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
2332 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2333 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2334 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2335 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2336 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2337 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2339 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2340 /* The multiple "Capture Source" controls confuse alsamixer
2341 * So call somewhat different..
2343 /* .name = "Capture Source", */
2344 .name = "Input Source",
2346 .info = via_mux_enum_info,
2347 .get = via_mux_enum_get,
2348 .put = via_mux_enum_put,
2353 static const struct hda_verb vt1709_uniwill_init_verbs[] = {
2354 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2355 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2360 * generic initialization of ADC, input mixers and output mixers
2362 static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2364 * Unmute ADC0-2 and set the default input to mic-in
2366 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2367 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2368 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2371 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2374 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2375 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2376 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2377 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2378 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2379 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2382 * Set up output selector (0x1a, 0x1b, 0x29)
2384 /* set vol=0 to output mixers */
2385 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2386 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2387 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2390 * Unmute PW3 and PW4
2392 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2393 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2395 /* Set input of PW4 as MW0 */
2396 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2397 /* PW9 Output enable */
2398 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2402 static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2406 .nid = 0x10, /* NID to query formats and rates */
2408 .open = via_playback_pcm_open,
2409 .prepare = via_playback_multi_pcm_prepare,
2410 .cleanup = via_playback_multi_pcm_cleanup,
2414 static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2418 .nid = 0x10, /* NID to query formats and rates */
2420 .open = via_playback_pcm_open,
2421 .prepare = via_playback_multi_pcm_prepare,
2422 .cleanup = via_playback_multi_pcm_cleanup,
2426 static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
2430 .nid = 0x14, /* NID to query formats and rates */
2432 .prepare = via_capture_pcm_prepare,
2433 .cleanup = via_capture_pcm_cleanup
2437 static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
2441 /* NID is set in via_build_pcms */
2443 .open = via_dig_playback_pcm_open,
2444 .close = via_dig_playback_pcm_close
2448 static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
2454 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2455 const struct auto_pin_cfg *cfg)
2460 if (cfg->line_outs == 4) /* 10 channels */
2461 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2462 else if (cfg->line_outs == 3) /* 6 channels */
2463 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2465 spec->multiout.dac_nids = spec->private_dac_nids;
2467 if (cfg->line_outs == 4) { /* 10 channels */
2468 for (i = 0; i < cfg->line_outs; i++) {
2469 nid = cfg->line_out_pins[i];
2471 /* config dac list */
2473 case AUTO_SEQ_FRONT:
2475 spec->private_dac_nids[i] = 0x10;
2477 case AUTO_SEQ_CENLFE:
2479 spec->private_dac_nids[i] = 0x12;
2481 case AUTO_SEQ_SURROUND:
2483 spec->private_dac_nids[i] = 0x11;
2487 spec->private_dac_nids[i] = 0x27;
2494 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2496 } else if (cfg->line_outs == 3) { /* 6 channels */
2497 for (i = 0; i < cfg->line_outs; i++) {
2498 nid = cfg->line_out_pins[i];
2500 /* config dac list */
2502 case AUTO_SEQ_FRONT:
2504 spec->private_dac_nids[i] = 0x10;
2506 case AUTO_SEQ_CENLFE:
2508 spec->private_dac_nids[i] = 0x12;
2510 case AUTO_SEQ_SURROUND:
2512 spec->private_dac_nids[i] = 0x11;
2524 /* add playback controls from the parsed DAC table */
2525 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2526 const struct auto_pin_cfg *cfg)
2529 static const char * const chname[4] = {
2530 "Front", "Surround", "C/LFE", "Side"
2532 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2535 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2536 nid = cfg->line_out_pins[i];
2541 nid_vol = nid_vols[i];
2543 if (i == AUTO_SEQ_CENLFE) {
2545 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2546 "Center Playback Volume",
2547 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2551 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2552 "LFE Playback Volume",
2553 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2557 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2558 "Center Playback Switch",
2559 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2563 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2564 "LFE Playback Switch",
2565 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2569 } else if (i == AUTO_SEQ_FRONT) {
2570 /* ADD control to mixer index 0 */
2571 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2572 "Master Front Playback Volume",
2573 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2577 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2578 "Master Front Playback Switch",
2579 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2584 /* add control to PW3 */
2585 sprintf(name, "%s Playback Volume", chname[i]);
2586 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2587 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2591 sprintf(name, "%s Playback Switch", chname[i]);
2592 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2593 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2597 } else if (i == AUTO_SEQ_SURROUND) {
2598 sprintf(name, "%s Playback Volume", chname[i]);
2599 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2600 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2604 sprintf(name, "%s Playback Switch", chname[i]);
2605 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2606 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2610 } else if (i == AUTO_SEQ_SIDE) {
2611 sprintf(name, "%s Playback Volume", chname[i]);
2612 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2613 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2617 sprintf(name, "%s Playback Switch", chname[i]);
2618 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2619 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2629 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2636 if (spec->multiout.num_dacs == 5) /* 10 channels */
2637 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2638 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2639 spec->multiout.hp_nid = 0;
2640 spec->hp_independent_mode_index = 1;
2642 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2643 "Headphone Playback Volume",
2644 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2647 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2648 "Headphone Playback Switch",
2649 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2656 /* create playback/capture controls for input pins */
2657 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
2658 const struct auto_pin_cfg *cfg)
2660 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18);
2663 static int vt1709_parse_auto_config(struct hda_codec *codec)
2665 struct via_spec *spec = codec->spec;
2668 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2671 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2674 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2675 return 0; /* can't find valid BIOS pin config */
2677 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2680 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2683 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
2687 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2689 if (spec->autocfg.dig_outs)
2690 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2691 spec->dig_in_pin = VT1709_DIGIN_PIN;
2692 if (spec->autocfg.dig_in_pin)
2693 spec->dig_in_nid = VT1709_DIGIN_NID;
2695 if (spec->kctls.list)
2696 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2698 spec->input_mux = &spec->private_imux[0];
2701 via_hp_build(codec);
2703 via_smart51_build(spec);
2707 #ifdef CONFIG_SND_HDA_POWER_SAVE
2708 static const struct hda_amp_list vt1709_loopbacks[] = {
2709 { 0x18, HDA_INPUT, 1 },
2710 { 0x18, HDA_INPUT, 2 },
2711 { 0x18, HDA_INPUT, 3 },
2712 { 0x18, HDA_INPUT, 4 },
2717 static int patch_vt1709_10ch(struct hda_codec *codec)
2719 struct via_spec *spec;
2722 /* create a codec specific record */
2723 spec = via_new_spec(codec);
2727 err = vt1709_parse_auto_config(codec);
2732 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2733 "Using genenic mode...\n");
2736 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2737 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2739 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2740 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2742 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2743 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2745 if (spec->adc_nids && spec->input_mux) {
2746 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2750 codec->patch_ops = via_patch_ops;
2752 codec->patch_ops.init = via_auto_init;
2753 codec->patch_ops.unsol_event = via_unsol_event;
2754 #ifdef CONFIG_SND_HDA_POWER_SAVE
2755 spec->loopback.amplist = vt1709_loopbacks;
2761 * generic initialization of ADC, input mixers and output mixers
2763 static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2765 * Unmute ADC0-2 and set the default input to mic-in
2767 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2768 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2769 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2772 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2775 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2776 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2777 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2778 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2779 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2780 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2783 * Set up output selector (0x1a, 0x1b, 0x29)
2785 /* set vol=0 to output mixers */
2786 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2787 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2788 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2791 * Unmute PW3 and PW4
2793 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2794 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2796 /* Set input of PW4 as MW0 */
2797 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2798 /* PW9 Output enable */
2799 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2803 static int patch_vt1709_6ch(struct hda_codec *codec)
2805 struct via_spec *spec;
2808 /* create a codec specific record */
2809 spec = via_new_spec(codec);
2813 err = vt1709_parse_auto_config(codec);
2818 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2819 "Using genenic mode...\n");
2822 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2823 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2825 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2826 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2828 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2829 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2831 if (spec->adc_nids && spec->input_mux) {
2832 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2836 codec->patch_ops = via_patch_ops;
2838 codec->patch_ops.init = via_auto_init;
2839 codec->patch_ops.unsol_event = via_unsol_event;
2840 #ifdef CONFIG_SND_HDA_POWER_SAVE
2841 spec->loopback.amplist = vt1709_loopbacks;
2846 /* capture mixer elements */
2847 static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2848 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2849 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2850 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2851 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2853 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2854 /* The multiple "Capture Source" controls confuse alsamixer
2855 * So call somewhat different..
2857 /* .name = "Capture Source", */
2858 .name = "Input Source",
2860 .info = via_mux_enum_info,
2861 .get = via_mux_enum_get,
2862 .put = via_mux_enum_put,
2867 * generic initialization of ADC, input mixers and output mixers
2869 static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2871 * Unmute ADC0-1 and set the default input to mic-in
2873 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2874 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2877 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2880 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2881 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2882 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2883 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2884 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2885 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2888 * Set up output mixers
2890 /* set vol=0 to output mixers */
2891 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2892 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2893 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2895 /* Setup default input to PW4 */
2896 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2897 /* PW9 Output enable */
2898 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2899 /* PW10 Input enable */
2900 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2904 static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2906 * Unmute ADC0-1 and set the default input to mic-in
2908 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2909 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2912 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2915 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2916 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2917 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2918 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2919 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2920 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2923 * Set up output mixers
2925 /* set vol=0 to output mixers */
2926 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2927 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2928 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2930 /* Setup default input of PW4 to MW0 */
2931 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2932 /* PW9 Output enable */
2933 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2934 /* PW10 Input enable */
2935 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2939 static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
2940 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2941 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2942 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2943 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2944 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2945 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2946 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2947 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2948 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2952 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2953 struct hda_codec *codec,
2954 struct snd_pcm_substream *substream)
2956 int idle = substream->pstr->substream_opened == 1
2957 && substream->ref_count == 0;
2959 analog_low_current_mode(codec, idle);
2963 static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2967 .nid = 0x10, /* NID to query formats and rates */
2969 .open = via_playback_pcm_open,
2970 .prepare = via_playback_multi_pcm_prepare,
2971 .cleanup = via_playback_multi_pcm_cleanup,
2972 .close = via_pcm_open_close
2976 static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2980 .nid = 0x10, /* NID to query formats and rates */
2982 .open = via_playback_pcm_open,
2983 .prepare = via_playback_multi_pcm_prepare,
2984 .cleanup = via_playback_multi_pcm_cleanup
2988 static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2992 .nid = 0x13, /* NID to query formats and rates */
2994 .open = via_pcm_open_close,
2995 .prepare = via_capture_pcm_prepare,
2996 .cleanup = via_capture_pcm_cleanup,
2997 .close = via_pcm_open_close
3001 static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3005 /* NID is set in via_build_pcms */
3007 .open = via_dig_playback_pcm_open,
3008 .close = via_dig_playback_pcm_close,
3009 .prepare = via_dig_playback_pcm_prepare,
3010 .cleanup = via_dig_playback_pcm_cleanup
3014 static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3020 /* fill in the dac_nids table from the parsed pin configuration */
3021 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3022 const struct auto_pin_cfg *cfg)
3027 spec->multiout.num_dacs = cfg->line_outs;
3029 spec->multiout.dac_nids = spec->private_dac_nids;
3031 for (i = 0; i < 4; i++) {
3032 nid = cfg->line_out_pins[i];
3034 /* config dac list */
3036 case AUTO_SEQ_FRONT:
3037 spec->private_dac_nids[i] = 0x10;
3039 case AUTO_SEQ_CENLFE:
3040 spec->private_dac_nids[i] = 0x24;
3042 case AUTO_SEQ_SURROUND:
3043 spec->private_dac_nids[i] = 0x11;
3046 spec->private_dac_nids[i] = 0x25;
3055 /* add playback controls from the parsed DAC table */
3056 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3057 const struct auto_pin_cfg *cfg)
3060 static const char * const chname[4] = {
3061 "Front", "Surround", "C/LFE", "Side"
3063 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3064 hda_nid_t nid, nid_vol = 0;
3067 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3068 nid = cfg->line_out_pins[i];
3073 nid_vol = nid_vols[i];
3075 if (i == AUTO_SEQ_CENLFE) {
3077 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3078 "Center Playback Volume",
3079 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3083 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3084 "LFE Playback Volume",
3085 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3089 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3090 "Center Playback Switch",
3091 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3095 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3096 "LFE Playback Switch",
3097 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3101 } else if (i == AUTO_SEQ_FRONT) {
3102 /* add control to mixer index 0 */
3103 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3104 "Master Front Playback Volume",
3105 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3109 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3110 "Master Front Playback Switch",
3111 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3116 /* add control to PW3 */
3117 sprintf(name, "%s Playback Volume", chname[i]);
3118 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3119 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3123 sprintf(name, "%s Playback Switch", chname[i]);
3124 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3125 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3130 sprintf(name, "%s Playback Volume", chname[i]);
3131 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3132 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3136 sprintf(name, "%s Playback Switch", chname[i]);
3137 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3138 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3148 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3155 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3156 spec->hp_independent_mode_index = 1;
3158 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3159 "Headphone Playback Volume",
3160 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3163 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3164 "Headphone Playback Switch",
3165 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3169 create_hp_imux(spec);
3174 /* create playback/capture controls for input pins */
3175 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3176 const struct auto_pin_cfg *cfg)
3178 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
3181 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3183 struct via_spec *spec = codec->spec;
3186 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3189 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3192 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3193 return 0; /* can't find valid BIOS pin config */
3195 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3198 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3201 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3205 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3207 if (spec->autocfg.dig_outs)
3208 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3209 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3210 if (spec->autocfg.dig_in_pin)
3211 spec->dig_in_nid = VT1708B_DIGIN_NID;
3213 if (spec->kctls.list)
3214 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3216 spec->input_mux = &spec->private_imux[0];
3219 via_hp_build(codec);
3221 via_smart51_build(spec);
3225 #ifdef CONFIG_SND_HDA_POWER_SAVE
3226 static const struct hda_amp_list vt1708B_loopbacks[] = {
3227 { 0x16, HDA_INPUT, 1 },
3228 { 0x16, HDA_INPUT, 2 },
3229 { 0x16, HDA_INPUT, 3 },
3230 { 0x16, HDA_INPUT, 4 },
3235 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3237 struct via_spec *spec = codec->spec;
3241 if ((spec->codec_type != VT1708B_4CH) &&
3242 (codec->vendor_id != 0x11064397))
3245 /* SW0 (17h) = stereo mixer */
3247 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3248 == ((spec->codec_type == VT1708S) ? 5 : 0));
3250 /* PW 1/2/5 (1ah/1bh/1eh) */
3252 set_pin_power_state(codec, 0x1a, &parm);
3253 set_pin_power_state(codec, 0x1b, &parm);
3254 set_pin_power_state(codec, 0x1e, &parm);
3257 /* SW0 (17h), AIW 0/1 (13h/14h) */
3258 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3259 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3260 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3263 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3265 set_pin_power_state(codec, 0x19, &parm);
3266 if (spec->smart51_enabled)
3267 set_pin_power_state(codec, 0x1b, &parm);
3268 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3269 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3271 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3274 set_pin_power_state(codec, 0x22, &parm);
3275 if (spec->smart51_enabled)
3276 set_pin_power_state(codec, 0x1a, &parm);
3277 snd_hda_codec_write(codec, 0x26, 0,
3278 AC_VERB_SET_POWER_STATE, parm);
3279 snd_hda_codec_write(codec, 0x24, 0,
3280 AC_VERB_SET_POWER_STATE, parm);
3281 } else if (codec->vendor_id == 0x11064397) {
3282 /* PW7(23h), SW2(27h), AOW2(25h) */
3284 set_pin_power_state(codec, 0x23, &parm);
3285 if (spec->smart51_enabled)
3286 set_pin_power_state(codec, 0x1a, &parm);
3287 snd_hda_codec_write(codec, 0x27, 0,
3288 AC_VERB_SET_POWER_STATE, parm);
3289 snd_hda_codec_write(codec, 0x25, 0,
3290 AC_VERB_SET_POWER_STATE, parm);
3293 /* PW 3/4/7 (1ch/1dh/23h) */
3295 /* force to D0 for internal Speaker */
3296 set_pin_power_state(codec, 0x1c, &parm);
3297 set_pin_power_state(codec, 0x1d, &parm);
3299 set_pin_power_state(codec, 0x23, &parm);
3301 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3302 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3303 imux_is_smixer ? AC_PWRST_D0 : parm);
3304 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3306 snd_hda_codec_write(codec, 0x25, 0,
3307 AC_VERB_SET_POWER_STATE, parm);
3308 snd_hda_codec_write(codec, 0x27, 0,
3309 AC_VERB_SET_POWER_STATE, parm);
3310 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3311 snd_hda_codec_write(codec, 0x25, 0,
3312 AC_VERB_SET_POWER_STATE, parm);
3315 static int patch_vt1708S(struct hda_codec *codec);
3316 static int patch_vt1708B_8ch(struct hda_codec *codec)
3318 struct via_spec *spec;
3321 if (get_codec_type(codec) == VT1708BCE)
3322 return patch_vt1708S(codec);
3323 /* create a codec specific record */
3324 spec = via_new_spec(codec);
3328 /* automatic parse from the BIOS config */
3329 err = vt1708B_parse_auto_config(codec);
3334 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3335 "from BIOS. Using genenic mode...\n");
3338 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3339 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3341 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3342 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3344 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3345 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3347 if (spec->adc_nids && spec->input_mux) {
3348 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3352 codec->patch_ops = via_patch_ops;
3354 codec->patch_ops.init = via_auto_init;
3355 codec->patch_ops.unsol_event = via_unsol_event;
3356 #ifdef CONFIG_SND_HDA_POWER_SAVE
3357 spec->loopback.amplist = vt1708B_loopbacks;
3360 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3365 static int patch_vt1708B_4ch(struct hda_codec *codec)
3367 struct via_spec *spec;
3370 /* create a codec specific record */
3371 spec = via_new_spec(codec);
3375 /* automatic parse from the BIOS config */
3376 err = vt1708B_parse_auto_config(codec);
3381 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3382 "from BIOS. Using genenic mode...\n");
3385 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3386 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3388 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3389 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3391 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3392 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3394 if (spec->adc_nids && spec->input_mux) {
3395 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3399 codec->patch_ops = via_patch_ops;
3401 codec->patch_ops.init = via_auto_init;
3402 codec->patch_ops.unsol_event = via_unsol_event;
3403 #ifdef CONFIG_SND_HDA_POWER_SAVE
3404 spec->loopback.amplist = vt1708B_loopbacks;
3407 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3412 /* Patch for VT1708S */
3414 /* capture mixer elements */
3415 static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3416 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3417 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3418 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3419 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3420 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3421 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3424 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3425 /* The multiple "Capture Source" controls confuse alsamixer
3426 * So call somewhat different..
3428 /* .name = "Capture Source", */
3429 .name = "Input Source",
3431 .info = via_mux_enum_info,
3432 .get = via_mux_enum_get,
3433 .put = via_mux_enum_put,
3438 static const struct hda_verb vt1708S_volume_init_verbs[] = {
3439 /* Unmute ADC0-1 and set the default input to mic-in */
3440 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3441 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3443 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3444 * analog-loopback mixer widget */
3445 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3446 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3447 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3448 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3449 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3450 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3452 /* Setup default input of PW4 to MW0 */
3453 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3454 /* PW9, PW10 Output enable */
3455 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3456 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3457 /* Enable Mic Boost Volume backdoor */
3459 /* don't bybass mixer */
3464 static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
3465 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3466 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3467 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3468 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3469 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3470 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3471 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3472 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3473 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3477 static const struct hda_verb vt1705_uniwill_init_verbs[] = {
3478 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3479 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3480 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3481 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3482 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3483 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3484 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3485 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3489 static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3493 .nid = 0x10, /* NID to query formats and rates */
3495 .open = via_playback_pcm_open,
3496 .prepare = via_playback_multi_pcm_prepare,
3497 .cleanup = via_playback_multi_pcm_cleanup,
3498 .close = via_pcm_open_close
3502 static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
3506 .nid = 0x10, /* NID to query formats and rates */
3508 .open = via_playback_pcm_open,
3509 .prepare = via_playback_multi_pcm_prepare,
3510 .cleanup = via_playback_multi_pcm_cleanup,
3511 .close = via_pcm_open_close
3515 static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3519 .nid = 0x13, /* NID to query formats and rates */
3521 .open = via_pcm_open_close,
3522 .prepare = via_capture_pcm_prepare,
3523 .cleanup = via_capture_pcm_cleanup,
3524 .close = via_pcm_open_close
3528 static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3532 /* NID is set in via_build_pcms */
3534 .open = via_dig_playback_pcm_open,
3535 .close = via_dig_playback_pcm_close,
3536 .prepare = via_dig_playback_pcm_prepare,
3537 .cleanup = via_dig_playback_pcm_cleanup
3541 /* fill in the dac_nids table from the parsed pin configuration */
3542 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3543 const struct auto_pin_cfg *cfg)
3548 spec->multiout.num_dacs = cfg->line_outs;
3550 spec->multiout.dac_nids = spec->private_dac_nids;
3552 for (i = 0; i < 4; i++) {
3553 nid = cfg->line_out_pins[i];
3555 /* config dac list */
3557 case AUTO_SEQ_FRONT:
3558 spec->private_dac_nids[i] = 0x10;
3560 case AUTO_SEQ_CENLFE:
3561 if (spec->codec->vendor_id == 0x11064397)
3562 spec->private_dac_nids[i] = 0x25;
3564 spec->private_dac_nids[i] = 0x24;
3566 case AUTO_SEQ_SURROUND:
3567 spec->private_dac_nids[i] = 0x11;
3570 spec->private_dac_nids[i] = 0x25;
3576 /* for Smart 5.1, line/mic inputs double as output pins */
3577 if (cfg->line_outs == 1) {
3578 spec->multiout.num_dacs = 3;
3579 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3580 if (spec->codec->vendor_id == 0x11064397)
3581 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
3583 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3589 /* add playback controls from the parsed DAC table */
3590 static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
3591 const struct auto_pin_cfg *cfg)
3593 struct via_spec *spec = codec->spec;
3595 static const char * const chname[4] = {
3596 "Front", "Surround", "C/LFE", "Side"
3598 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3599 {0x10, 0x11, 0x25, 0} };
3600 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3601 {0x1C, 0x18, 0x27, 0} };
3602 hda_nid_t nid, nid_vol, nid_mute;
3605 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3606 nid = cfg->line_out_pins[i];
3608 /* for Smart 5.1, there are always at least six channels */
3609 if (!nid && i > AUTO_SEQ_CENLFE)
3612 if (codec->vendor_id == 0x11064397) {
3613 nid_vol = nid_vols[1][i];
3614 nid_mute = nid_mutes[1][i];
3616 nid_vol = nid_vols[0][i];
3617 nid_mute = nid_mutes[0][i];
3619 if (!nid_vol && !nid_mute)
3622 if (i == AUTO_SEQ_CENLFE) {
3624 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3625 "Center Playback Volume",
3626 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3630 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3631 "LFE Playback Volume",
3632 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3636 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3637 "Center Playback Switch",
3638 HDA_COMPOSE_AMP_VAL(nid_mute,
3643 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3644 "LFE Playback Switch",
3645 HDA_COMPOSE_AMP_VAL(nid_mute,
3650 } else if (i == AUTO_SEQ_FRONT) {
3651 /* add control to mixer index 0 */
3652 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3653 "Master Front Playback Volume",
3654 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3658 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3659 "Master Front Playback Switch",
3660 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3666 sprintf(name, "%s Playback Volume", chname[i]);
3667 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3668 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3672 sprintf(name, "%s Playback Switch", chname[i]);
3673 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3674 HDA_COMPOSE_AMP_VAL(nid_mute,
3680 sprintf(name, "%s Playback Volume", chname[i]);
3681 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3682 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3686 sprintf(name, "%s Playback Switch", chname[i]);
3687 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3688 HDA_COMPOSE_AMP_VAL(nid_mute,
3699 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3706 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3707 spec->hp_independent_mode_index = 1;
3709 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3710 "Headphone Playback Volume",
3711 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3715 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3716 "Headphone Playback Switch",
3717 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3721 create_hp_imux(spec);
3726 /* create playback/capture controls for input pins */
3727 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3728 const struct auto_pin_cfg *cfg)
3730 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
3733 /* fill out digital output widgets; one for master and one for slave outputs */
3734 static void fill_dig_outs(struct hda_codec *codec)
3736 struct via_spec *spec = codec->spec;
3739 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3743 nid = spec->autocfg.dig_out_pins[i];
3746 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3749 if (!spec->multiout.dig_out_nid)
3750 spec->multiout.dig_out_nid = nid;
3752 spec->slave_dig_outs[0] = nid;
3753 break; /* at most two dig outs */
3758 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3760 struct via_spec *spec = codec->spec;
3763 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3766 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3769 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3770 return 0; /* can't find valid BIOS pin config */
3772 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
3775 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3778 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
3782 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3784 fill_dig_outs(codec);
3786 if (spec->kctls.list)
3787 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3789 spec->input_mux = &spec->private_imux[0];
3792 via_hp_build(codec);
3794 via_smart51_build(spec);
3798 #ifdef CONFIG_SND_HDA_POWER_SAVE
3799 static const struct hda_amp_list vt1708S_loopbacks[] = {
3800 { 0x16, HDA_INPUT, 1 },
3801 { 0x16, HDA_INPUT, 2 },
3802 { 0x16, HDA_INPUT, 3 },
3803 { 0x16, HDA_INPUT, 4 },
3808 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3809 int offset, int num_steps, int step_size)
3811 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3812 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3813 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3814 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3815 (0 << AC_AMPCAP_MUTE_SHIFT));
3818 static int patch_vt1708S(struct hda_codec *codec)
3820 struct via_spec *spec;
3823 /* create a codec specific record */
3824 spec = via_new_spec(codec);
3828 /* automatic parse from the BIOS config */
3829 err = vt1708S_parse_auto_config(codec);
3834 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3835 "from BIOS. Using genenic mode...\n");
3838 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3839 if (codec->vendor_id == 0x11064397)
3840 spec->init_verbs[spec->num_iverbs++] =
3841 vt1705_uniwill_init_verbs;
3843 spec->init_verbs[spec->num_iverbs++] =
3844 vt1708S_uniwill_init_verbs;
3846 if (codec->vendor_id == 0x11064397)
3847 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3849 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
3850 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3852 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3854 if (spec->adc_nids && spec->input_mux) {
3855 override_mic_boost(codec, 0x1a, 0, 3, 40);
3856 override_mic_boost(codec, 0x1e, 0, 3, 40);
3857 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3861 codec->patch_ops = via_patch_ops;
3863 codec->patch_ops.init = via_auto_init;
3864 codec->patch_ops.unsol_event = via_unsol_event;
3865 #ifdef CONFIG_SND_HDA_POWER_SAVE
3866 spec->loopback.amplist = vt1708S_loopbacks;
3869 /* correct names for VT1708BCE */
3870 if (get_codec_type(codec) == VT1708BCE) {
3871 kfree(codec->chip_name);
3872 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3873 snprintf(codec->bus->card->mixername,
3874 sizeof(codec->bus->card->mixername),
3875 "%s %s", codec->vendor_name, codec->chip_name);
3877 /* correct names for VT1705 */
3878 if (codec->vendor_id == 0x11064397) {
3879 kfree(codec->chip_name);
3880 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3881 snprintf(codec->bus->card->mixername,
3882 sizeof(codec->bus->card->mixername),
3883 "%s %s", codec->vendor_name, codec->chip_name);
3885 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3889 /* Patch for VT1702 */
3891 /* capture mixer elements */
3892 static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
3893 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3894 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3895 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3896 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3897 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3898 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3899 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3902 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3903 /* The multiple "Capture Source" controls confuse alsamixer
3904 * So call somewhat different..
3906 /* .name = "Capture Source", */
3907 .name = "Input Source",
3909 .info = via_mux_enum_info,
3910 .get = via_mux_enum_get,
3911 .put = via_mux_enum_put,
3916 static const struct hda_verb vt1702_volume_init_verbs[] = {
3918 * Unmute ADC0-1 and set the default input to mic-in
3920 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3921 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3922 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3925 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3928 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3929 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3930 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3931 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3932 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3933 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3935 /* Setup default input of PW4 to MW0 */
3936 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3937 /* PW6 PW7 Output enable */
3938 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3939 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3947 static const struct hda_verb vt1702_uniwill_init_verbs[] = {
3948 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3949 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3950 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3951 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3952 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3953 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3957 static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
3961 .nid = 0x10, /* NID to query formats and rates */
3963 .open = via_playback_pcm_open,
3964 .prepare = via_playback_multi_pcm_prepare,
3965 .cleanup = via_playback_multi_pcm_cleanup,
3966 .close = via_pcm_open_close
3970 static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
3974 .nid = 0x12, /* NID to query formats and rates */
3976 .open = via_pcm_open_close,
3977 .prepare = via_capture_pcm_prepare,
3978 .cleanup = via_capture_pcm_cleanup,
3979 .close = via_pcm_open_close
3983 static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
3987 /* NID is set in via_build_pcms */
3989 .open = via_dig_playback_pcm_open,
3990 .close = via_dig_playback_pcm_close,
3991 .prepare = via_dig_playback_pcm_prepare,
3992 .cleanup = via_dig_playback_pcm_cleanup
3996 /* fill in the dac_nids table from the parsed pin configuration */
3997 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
3998 const struct auto_pin_cfg *cfg)
4000 spec->multiout.num_dacs = 1;
4001 spec->multiout.dac_nids = spec->private_dac_nids;
4003 if (cfg->line_out_pins[0]) {
4004 /* config dac list */
4005 spec->private_dac_nids[0] = 0x10;
4011 /* add playback controls from the parsed DAC table */
4012 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4013 const struct auto_pin_cfg *cfg)
4017 if (!cfg->line_out_pins[0])
4020 /* add control to mixer index 0 */
4021 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4022 "Master Front Playback Volume",
4023 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4026 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4027 "Master Front Playback Switch",
4028 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4033 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4034 "Front Playback Volume",
4035 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4038 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4039 "Front Playback Switch",
4040 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4047 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4050 struct hda_input_mux *imux;
4051 static const char * const texts[] = { "ON", "OFF", NULL};
4054 spec->multiout.hp_nid = 0x1D;
4055 spec->hp_independent_mode_index = 0;
4057 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4058 "Headphone Playback Volume",
4059 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4063 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4064 "Headphone Playback Switch",
4065 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4069 imux = &spec->private_imux[1];
4071 /* for hp mode select */
4072 for (i = 0; texts[i]; i++)
4073 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4075 spec->hp_mux = &spec->private_imux[1];
4079 /* create playback/capture controls for input pins */
4080 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4081 const struct auto_pin_cfg *cfg)
4083 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a);
4086 static int vt1702_parse_auto_config(struct hda_codec *codec)
4088 struct via_spec *spec = codec->spec;
4091 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4094 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4097 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4098 return 0; /* can't find valid BIOS pin config */
4100 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4103 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4106 /* limit AA path volume to 0 dB */
4107 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4108 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4109 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4110 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4111 (1 << AC_AMPCAP_MUTE_SHIFT));
4112 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4116 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4118 fill_dig_outs(codec);
4120 if (spec->kctls.list)
4121 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4123 spec->input_mux = &spec->private_imux[0];
4126 via_hp_build(codec);
4131 #ifdef CONFIG_SND_HDA_POWER_SAVE
4132 static const struct hda_amp_list vt1702_loopbacks[] = {
4133 { 0x1A, HDA_INPUT, 1 },
4134 { 0x1A, HDA_INPUT, 2 },
4135 { 0x1A, HDA_INPUT, 3 },
4136 { 0x1A, HDA_INPUT, 4 },
4141 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4143 int imux_is_smixer =
4144 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4147 /* PW 1/2/5 (14h/15h/18h) */
4149 set_pin_power_state(codec, 0x14, &parm);
4150 set_pin_power_state(codec, 0x15, &parm);
4151 set_pin_power_state(codec, 0x18, &parm);
4153 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4154 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4155 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4156 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4157 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4158 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4161 /* PW 3/4 (16h/17h) */
4163 set_pin_power_state(codec, 0x17, &parm);
4164 set_pin_power_state(codec, 0x16, &parm);
4165 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4166 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4167 imux_is_smixer ? AC_PWRST_D0 : parm);
4168 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4169 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4172 static int patch_vt1702(struct hda_codec *codec)
4174 struct via_spec *spec;
4177 /* create a codec specific record */
4178 spec = via_new_spec(codec);
4182 /* automatic parse from the BIOS config */
4183 err = vt1702_parse_auto_config(codec);
4188 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4189 "from BIOS. Using genenic mode...\n");
4192 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4193 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4195 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4196 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4198 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4200 if (spec->adc_nids && spec->input_mux) {
4201 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4205 codec->patch_ops = via_patch_ops;
4207 codec->patch_ops.init = via_auto_init;
4208 codec->patch_ops.unsol_event = via_unsol_event;
4209 #ifdef CONFIG_SND_HDA_POWER_SAVE
4210 spec->loopback.amplist = vt1702_loopbacks;
4213 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
4217 /* Patch for VT1718S */
4219 /* capture mixer elements */
4220 static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4221 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4222 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4223 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4224 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4225 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4226 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4229 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4230 /* The multiple "Capture Source" controls confuse alsamixer
4231 * So call somewhat different..
4233 .name = "Input Source",
4235 .info = via_mux_enum_info,
4236 .get = via_mux_enum_get,
4237 .put = via_mux_enum_put,
4242 static const struct hda_verb vt1718S_volume_init_verbs[] = {
4244 * Unmute ADC0-1 and set the default input to mic-in
4246 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4247 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4249 /* Enable MW0 adjust Gain 5 */
4251 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4254 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4255 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4256 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4257 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4258 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4259 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
4261 /* Setup default input of Front HP to MW9 */
4262 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4263 /* PW9 PW10 Output enable */
4264 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4265 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4266 /* PW11 Input enable */
4267 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4268 /* Enable Boost Volume backdoor */
4270 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4271 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4272 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4273 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4274 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4275 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4276 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4277 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4278 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4279 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4280 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4281 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4282 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4283 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4284 /* Unmute MW4's index 0 */
4285 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4290 static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
4291 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4292 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4293 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4294 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4295 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4296 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4297 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4298 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4299 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4303 static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4307 .nid = 0x8, /* NID to query formats and rates */
4309 .open = via_playback_pcm_open,
4310 .prepare = via_playback_multi_pcm_prepare,
4311 .cleanup = via_playback_multi_pcm_cleanup,
4312 .close = via_pcm_open_close,
4316 static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4320 .nid = 0x10, /* NID to query formats and rates */
4322 .open = via_pcm_open_close,
4323 .prepare = via_capture_pcm_prepare,
4324 .cleanup = via_capture_pcm_cleanup,
4325 .close = via_pcm_open_close,
4329 static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4333 /* NID is set in via_build_pcms */
4335 .open = via_dig_playback_pcm_open,
4336 .close = via_dig_playback_pcm_close,
4337 .prepare = via_dig_playback_pcm_prepare,
4338 .cleanup = via_dig_playback_pcm_cleanup
4342 static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4348 /* fill in the dac_nids table from the parsed pin configuration */
4349 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4350 const struct auto_pin_cfg *cfg)
4355 spec->multiout.num_dacs = cfg->line_outs;
4357 spec->multiout.dac_nids = spec->private_dac_nids;
4359 for (i = 0; i < 4; i++) {
4360 nid = cfg->line_out_pins[i];
4362 /* config dac list */
4364 case AUTO_SEQ_FRONT:
4365 spec->private_dac_nids[i] = 0x8;
4367 case AUTO_SEQ_CENLFE:
4368 spec->private_dac_nids[i] = 0xa;
4370 case AUTO_SEQ_SURROUND:
4371 spec->private_dac_nids[i] = 0x9;
4374 spec->private_dac_nids[i] = 0xb;
4383 /* add playback controls from the parsed DAC table */
4384 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4385 const struct auto_pin_cfg *cfg)
4388 static const char * const chname[4] = {
4389 "Front", "Surround", "C/LFE", "Side"
4391 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4392 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4393 hda_nid_t nid, nid_vol, nid_mute = 0;
4396 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4397 nid = cfg->line_out_pins[i];
4401 nid_vol = nid_vols[i];
4402 nid_mute = nid_mutes[i];
4404 if (i == AUTO_SEQ_CENLFE) {
4406 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4407 "Center Playback Volume",
4408 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4412 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4413 "LFE Playback Volume",
4414 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4418 err = via_add_control(
4419 spec, VIA_CTL_WIDGET_MUTE,
4420 "Center Playback Switch",
4421 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4425 err = via_add_control(
4426 spec, VIA_CTL_WIDGET_MUTE,
4427 "LFE Playback Switch",
4428 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4432 } else if (i == AUTO_SEQ_FRONT) {
4434 sprintf(name, "%s Playback Volume", chname[i]);
4435 err = via_add_control(
4436 spec, VIA_CTL_WIDGET_VOL, name,
4437 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4440 sprintf(name, "%s Playback Switch", chname[i]);
4441 err = via_add_control(
4442 spec, VIA_CTL_WIDGET_MUTE, name,
4443 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4448 sprintf(name, "%s Playback Volume", chname[i]);
4449 err = via_add_control(
4450 spec, VIA_CTL_WIDGET_VOL, name,
4451 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4454 sprintf(name, "%s Playback Switch", chname[i]);
4455 err = via_add_control(
4456 spec, VIA_CTL_WIDGET_MUTE, name,
4457 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4466 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4473 spec->multiout.hp_nid = 0xc; /* AOW4 */
4474 spec->hp_independent_mode_index = 1;
4476 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4477 "Headphone Playback Volume",
4478 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4482 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4483 "Headphone Playback Switch",
4484 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4488 create_hp_imux(spec);
4492 /* create playback/capture controls for input pins */
4493 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4494 const struct auto_pin_cfg *cfg)
4496 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
4499 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4501 struct via_spec *spec = codec->spec;
4504 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4508 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4511 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4512 return 0; /* can't find valid BIOS pin config */
4514 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4517 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4520 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4524 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4526 fill_dig_outs(codec);
4528 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4529 spec->dig_in_nid = 0x13;
4531 if (spec->kctls.list)
4532 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4534 spec->input_mux = &spec->private_imux[0];
4537 via_hp_build(codec);
4539 via_smart51_build(spec);
4544 #ifdef CONFIG_SND_HDA_POWER_SAVE
4545 static const struct hda_amp_list vt1718S_loopbacks[] = {
4546 { 0x21, HDA_INPUT, 1 },
4547 { 0x21, HDA_INPUT, 2 },
4548 { 0x21, HDA_INPUT, 3 },
4549 { 0x21, HDA_INPUT, 4 },
4554 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4556 struct via_spec *spec = codec->spec;
4559 /* MUX6 (1eh) = stereo mixer */
4561 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4563 /* PW 5/6/7 (29h/2ah/2bh) */
4565 set_pin_power_state(codec, 0x29, &parm);
4566 set_pin_power_state(codec, 0x2a, &parm);
4567 set_pin_power_state(codec, 0x2b, &parm);
4570 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4571 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4572 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4573 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4574 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4577 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4579 set_pin_power_state(codec, 0x27, &parm);
4580 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4581 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4583 /* PW2 (26h), AOW2 (ah) */
4585 set_pin_power_state(codec, 0x26, &parm);
4586 if (spec->smart51_enabled)
4587 set_pin_power_state(codec, 0x2b, &parm);
4588 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4590 /* PW0 (24h), AOW0 (8h) */
4592 set_pin_power_state(codec, 0x24, &parm);
4593 if (!spec->hp_independent_mode) /* check for redirected HP */
4594 set_pin_power_state(codec, 0x28, &parm);
4595 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4596 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4597 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4598 imux_is_smixer ? AC_PWRST_D0 : parm);
4600 /* PW1 (25h), AOW1 (9h) */
4602 set_pin_power_state(codec, 0x25, &parm);
4603 if (spec->smart51_enabled)
4604 set_pin_power_state(codec, 0x2a, &parm);
4605 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4607 if (spec->hp_independent_mode) {
4608 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4610 set_pin_power_state(codec, 0x28, &parm);
4611 snd_hda_codec_write(codec, 0x1b, 0,
4612 AC_VERB_SET_POWER_STATE, parm);
4613 snd_hda_codec_write(codec, 0x34, 0,
4614 AC_VERB_SET_POWER_STATE, parm);
4615 snd_hda_codec_write(codec, 0xc, 0,
4616 AC_VERB_SET_POWER_STATE, parm);
4620 static int patch_vt1718S(struct hda_codec *codec)
4622 struct via_spec *spec;
4625 /* create a codec specific record */
4626 spec = via_new_spec(codec);
4630 /* automatic parse from the BIOS config */
4631 err = vt1718S_parse_auto_config(codec);
4636 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4637 "from BIOS. Using genenic mode...\n");
4640 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4641 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4643 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4644 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4646 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4647 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4648 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4650 if (spec->adc_nids && spec->input_mux) {
4651 override_mic_boost(codec, 0x2b, 0, 3, 40);
4652 override_mic_boost(codec, 0x29, 0, 3, 40);
4653 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4657 codec->patch_ops = via_patch_ops;
4659 codec->patch_ops.init = via_auto_init;
4660 codec->patch_ops.unsol_event = via_unsol_event;
4662 #ifdef CONFIG_SND_HDA_POWER_SAVE
4663 spec->loopback.amplist = vt1718S_loopbacks;
4666 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4671 /* Patch for VT1716S */
4673 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4674 struct snd_ctl_elem_info *uinfo)
4676 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4678 uinfo->value.integer.min = 0;
4679 uinfo->value.integer.max = 1;
4683 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4684 struct snd_ctl_elem_value *ucontrol)
4686 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4689 index = snd_hda_codec_read(codec, 0x26, 0,
4690 AC_VERB_GET_CONNECT_SEL, 0);
4692 *ucontrol->value.integer.value = index;
4697 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4698 struct snd_ctl_elem_value *ucontrol)
4700 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4701 struct via_spec *spec = codec->spec;
4702 int index = *ucontrol->value.integer.value;
4704 snd_hda_codec_write(codec, 0x26, 0,
4705 AC_VERB_SET_CONNECT_SEL, index);
4706 spec->dmic_enabled = index;
4707 set_widgets_power_state(codec);
4711 /* capture mixer elements */
4712 static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4713 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4714 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4715 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4716 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4717 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4718 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4721 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4722 .name = "Input Source",
4724 .info = via_mux_enum_info,
4725 .get = via_mux_enum_get,
4726 .put = via_mux_enum_put,
4731 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4732 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4734 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4735 .name = "Digital Mic Capture Switch",
4736 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4738 .info = vt1716s_dmic_info,
4739 .get = vt1716s_dmic_get,
4740 .put = vt1716s_dmic_put,
4746 /* mono-out mixer elements */
4747 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4748 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4752 static const struct hda_verb vt1716S_volume_init_verbs[] = {
4754 * Unmute ADC0-1 and set the default input to mic-in
4756 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4760 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4763 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4764 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4765 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4766 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4767 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4768 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4770 /* MUX Indices: Stereo Mixer = 5 */
4771 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4773 /* Setup default input of PW4 to MW0 */
4774 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4776 /* Setup default input of SW1 as MW0 */
4777 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4779 /* Setup default input of SW4 as AOW0 */
4780 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4782 /* PW9 PW10 Output enable */
4783 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4784 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4786 /* Unmute SW1, PW12 */
4787 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4788 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4789 /* PW12 Output enable */
4790 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4791 /* Enable Boost Volume backdoor */
4793 /* don't bybass mixer */
4795 /* Enable mono output */
4801 static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
4802 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4803 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4804 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4805 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4806 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4807 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4808 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4809 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4810 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4814 static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4818 .nid = 0x10, /* NID to query formats and rates */
4820 .open = via_playback_pcm_open,
4821 .prepare = via_playback_multi_pcm_prepare,
4822 .cleanup = via_playback_multi_pcm_cleanup,
4823 .close = via_pcm_open_close,
4827 static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
4831 .nid = 0x13, /* NID to query formats and rates */
4833 .open = via_pcm_open_close,
4834 .prepare = via_capture_pcm_prepare,
4835 .cleanup = via_capture_pcm_cleanup,
4836 .close = via_pcm_open_close,
4840 static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
4844 /* NID is set in via_build_pcms */
4846 .open = via_dig_playback_pcm_open,
4847 .close = via_dig_playback_pcm_close,
4848 .prepare = via_dig_playback_pcm_prepare,
4849 .cleanup = via_dig_playback_pcm_cleanup
4853 /* fill in the dac_nids table from the parsed pin configuration */
4854 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4855 const struct auto_pin_cfg *cfg)
4859 spec->multiout.num_dacs = cfg->line_outs;
4861 spec->multiout.dac_nids = spec->private_dac_nids;
4863 for (i = 0; i < 3; i++) {
4864 nid = cfg->line_out_pins[i];
4866 /* config dac list */
4868 case AUTO_SEQ_FRONT:
4869 spec->private_dac_nids[i] = 0x10;
4871 case AUTO_SEQ_CENLFE:
4872 spec->private_dac_nids[i] = 0x25;
4874 case AUTO_SEQ_SURROUND:
4875 spec->private_dac_nids[i] = 0x11;
4884 /* add playback controls from the parsed DAC table */
4885 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4886 const struct auto_pin_cfg *cfg)
4889 static const char * const chname[3] = {
4890 "Front", "Surround", "C/LFE"
4892 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4893 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4894 hda_nid_t nid, nid_vol, nid_mute;
4897 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4898 nid = cfg->line_out_pins[i];
4903 nid_vol = nid_vols[i];
4904 nid_mute = nid_mutes[i];
4906 if (i == AUTO_SEQ_CENLFE) {
4907 err = via_add_control(
4908 spec, VIA_CTL_WIDGET_VOL,
4909 "Center Playback Volume",
4910 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4913 err = via_add_control(
4914 spec, VIA_CTL_WIDGET_VOL,
4915 "LFE Playback Volume",
4916 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4919 err = via_add_control(
4920 spec, VIA_CTL_WIDGET_MUTE,
4921 "Center Playback Switch",
4922 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4926 err = via_add_control(
4927 spec, VIA_CTL_WIDGET_MUTE,
4928 "LFE Playback Switch",
4929 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4933 } else if (i == AUTO_SEQ_FRONT) {
4935 err = via_add_control(
4936 spec, VIA_CTL_WIDGET_VOL,
4937 "Master Front Playback Volume",
4938 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4941 err = via_add_control(
4942 spec, VIA_CTL_WIDGET_MUTE,
4943 "Master Front Playback Switch",
4944 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4948 sprintf(name, "%s Playback Volume", chname[i]);
4949 err = via_add_control(
4950 spec, VIA_CTL_WIDGET_VOL, name,
4951 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4954 sprintf(name, "%s Playback Switch", chname[i]);
4955 err = via_add_control(
4956 spec, VIA_CTL_WIDGET_MUTE, name,
4957 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4962 sprintf(name, "%s Playback Volume", chname[i]);
4963 err = via_add_control(
4964 spec, VIA_CTL_WIDGET_VOL, name,
4965 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4968 sprintf(name, "%s Playback Switch", chname[i]);
4969 err = via_add_control(
4970 spec, VIA_CTL_WIDGET_MUTE, name,
4971 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4980 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4987 spec->multiout.hp_nid = 0x25; /* AOW3 */
4988 spec->hp_independent_mode_index = 1;
4990 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4991 "Headphone Playback Volume",
4992 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
4996 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4997 "Headphone Playback Switch",
4998 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5002 create_hp_imux(spec);
5006 /* create playback/capture controls for input pins */
5007 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5008 const struct auto_pin_cfg *cfg)
5010 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16);
5013 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5015 struct via_spec *spec = codec->spec;
5018 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5021 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5024 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5025 return 0; /* can't find valid BIOS pin config */
5027 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5030 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5033 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5037 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5039 fill_dig_outs(codec);
5041 if (spec->kctls.list)
5042 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5044 spec->input_mux = &spec->private_imux[0];
5047 via_hp_build(codec);
5049 via_smart51_build(spec);
5054 #ifdef CONFIG_SND_HDA_POWER_SAVE
5055 static const struct hda_amp_list vt1716S_loopbacks[] = {
5056 { 0x16, HDA_INPUT, 1 },
5057 { 0x16, HDA_INPUT, 2 },
5058 { 0x16, HDA_INPUT, 3 },
5059 { 0x16, HDA_INPUT, 4 },
5064 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5066 struct via_spec *spec = codec->spec;
5069 unsigned int mono_out, present;
5070 /* SW0 (17h) = stereo mixer */
5072 (snd_hda_codec_read(codec, 0x17, 0,
5073 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5075 /* PW 1/2/5 (1ah/1bh/1eh) */
5077 set_pin_power_state(codec, 0x1a, &parm);
5078 set_pin_power_state(codec, 0x1b, &parm);
5079 set_pin_power_state(codec, 0x1e, &parm);
5082 /* SW0 (17h), AIW0(13h) */
5083 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5084 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5087 set_pin_power_state(codec, 0x1e, &parm);
5089 if (spec->dmic_enabled)
5090 set_pin_power_state(codec, 0x22, &parm);
5092 snd_hda_codec_write(codec, 0x22, 0,
5093 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5095 /* SW2(26h), AIW1(14h) */
5096 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5097 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5100 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5102 set_pin_power_state(codec, 0x19, &parm);
5103 /* Smart 5.1 PW2(1bh) */
5104 if (spec->smart51_enabled)
5105 set_pin_power_state(codec, 0x1b, &parm);
5106 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5107 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5109 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5111 set_pin_power_state(codec, 0x23, &parm);
5112 /* Smart 5.1 PW1(1ah) */
5113 if (spec->smart51_enabled)
5114 set_pin_power_state(codec, 0x1a, &parm);
5115 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5117 /* Smart 5.1 PW5(1eh) */
5118 if (spec->smart51_enabled)
5119 set_pin_power_state(codec, 0x1e, &parm);
5120 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5123 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5124 present = snd_hda_jack_detect(codec, 0x1c);
5129 present = snd_hda_jack_detect(codec, 0x1d);
5130 if (!spec->hp_independent_mode && present)
5135 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5136 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5137 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5138 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5140 /* PW 3/4 (1ch/1dh) */
5142 set_pin_power_state(codec, 0x1c, &parm);
5143 set_pin_power_state(codec, 0x1d, &parm);
5144 /* HP Independent Mode, power on AOW3 */
5145 if (spec->hp_independent_mode)
5146 snd_hda_codec_write(codec, 0x25, 0,
5147 AC_VERB_SET_POWER_STATE, parm);
5149 /* force to D0 for internal Speaker */
5150 /* MW0 (16h), AOW0 (10h) */
5151 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5152 imux_is_smixer ? AC_PWRST_D0 : parm);
5153 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5154 mono_out ? AC_PWRST_D0 : parm);
5157 static int patch_vt1716S(struct hda_codec *codec)
5159 struct via_spec *spec;
5162 /* create a codec specific record */
5163 spec = via_new_spec(codec);
5167 /* automatic parse from the BIOS config */
5168 err = vt1716S_parse_auto_config(codec);
5173 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5174 "from BIOS. Using genenic mode...\n");
5177 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5178 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5180 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5181 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5183 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5185 if (spec->adc_nids && spec->input_mux) {
5186 override_mic_boost(codec, 0x1a, 0, 3, 40);
5187 override_mic_boost(codec, 0x1e, 0, 3, 40);
5188 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5192 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5195 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5197 codec->patch_ops = via_patch_ops;
5199 codec->patch_ops.init = via_auto_init;
5200 codec->patch_ops.unsol_event = via_unsol_event;
5202 #ifdef CONFIG_SND_HDA_POWER_SAVE
5203 spec->loopback.amplist = vt1716S_loopbacks;
5206 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
5212 /* capture mixer elements */
5213 static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5214 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5215 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5216 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5217 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5218 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5219 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5222 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5223 /* The multiple "Capture Source" controls confuse alsamixer
5224 * So call somewhat different..
5226 /* .name = "Capture Source", */
5227 .name = "Input Source",
5229 .info = via_mux_enum_info,
5230 .get = via_mux_enum_get,
5231 .put = via_mux_enum_put,
5236 static const struct hda_verb vt2002P_volume_init_verbs[] = {
5237 /* Class-D speaker related verbs */
5242 * Unmute ADC0-1 and set the default input to mic-in
5244 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5245 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5248 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5251 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5252 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5253 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5254 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5255 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5256 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5258 /* MUX Indices: Mic = 0 */
5259 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5260 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5262 /* PW9 Output enable */
5263 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5265 /* Enable Boost Volume backdoor */
5268 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5269 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5270 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5271 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5272 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5273 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5274 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5275 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5276 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5278 /* set MUX0/1/4/8 = 0 (AOW0) */
5279 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5280 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5281 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5282 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5284 /* set PW0 index=0 (MW0) */
5285 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5287 /* Enable AOW0 to MW9 */
5291 static const struct hda_verb vt1802_volume_init_verbs[] = {
5293 * Unmute ADC0-1 and set the default input to mic-in
5295 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5296 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5299 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5302 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5303 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5304 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5305 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5306 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5307 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5309 /* MUX Indices: Mic = 0 */
5310 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5311 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5313 /* PW9 Output enable */
5314 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5316 /* Enable Boost Volume backdoor */
5319 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5320 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5321 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5322 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5323 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5324 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5325 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5326 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5327 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5329 /* set MUX0/1/4/8 = 0 (AOW0) */
5330 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5331 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5332 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5333 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5335 /* set PW0 index=0 (MW0) */
5336 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5338 /* Enable AOW0 to MW9 */
5344 static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
5345 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5346 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5347 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5348 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5349 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5350 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5351 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5354 static const struct hda_verb vt1802_uniwill_init_verbs[] = {
5355 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5356 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5357 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5358 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5359 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5360 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5361 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5365 static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5369 .nid = 0x8, /* NID to query formats and rates */
5371 .open = via_playback_pcm_open,
5372 .prepare = via_playback_multi_pcm_prepare,
5373 .cleanup = via_playback_multi_pcm_cleanup,
5374 .close = via_pcm_open_close,
5378 static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5382 .nid = 0x10, /* NID to query formats and rates */
5384 .open = via_pcm_open_close,
5385 .prepare = via_capture_pcm_prepare,
5386 .cleanup = via_capture_pcm_cleanup,
5387 .close = via_pcm_open_close,
5391 static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5395 /* NID is set in via_build_pcms */
5397 .open = via_dig_playback_pcm_open,
5398 .close = via_dig_playback_pcm_close,
5399 .prepare = via_dig_playback_pcm_prepare,
5400 .cleanup = via_dig_playback_pcm_cleanup
5404 /* fill in the dac_nids table from the parsed pin configuration */
5405 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5406 const struct auto_pin_cfg *cfg)
5408 spec->multiout.num_dacs = 1;
5409 spec->multiout.dac_nids = spec->private_dac_nids;
5410 if (cfg->line_out_pins[0])
5411 spec->private_dac_nids[0] = 0x8;
5415 /* add playback controls from the parsed DAC table */
5416 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5417 const struct auto_pin_cfg *cfg)
5422 if (!cfg->line_out_pins[0])
5425 if (spec->codec_type == VT1802)
5430 /* Line-Out: PortE */
5431 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5432 "Master Front Playback Volume",
5433 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5436 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5437 "Master Front Playback Switch",
5438 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
5445 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5452 spec->multiout.hp_nid = 0x9;
5453 spec->hp_independent_mode_index = 1;
5455 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5456 "Headphone Playback Volume",
5457 HDA_COMPOSE_AMP_VAL(
5458 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5462 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5463 "Headphone Playback Switch",
5464 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5468 create_hp_imux(spec);
5472 /* create playback/capture controls for input pins */
5473 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5474 const struct auto_pin_cfg *cfg)
5476 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
5479 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5481 struct via_spec *spec = codec->spec;
5485 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5489 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5493 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5494 return 0; /* can't find valid BIOS pin config */
5496 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5499 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5502 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5506 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5508 fill_dig_outs(codec);
5510 if (spec->kctls.list)
5511 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5513 spec->input_mux = &spec->private_imux[0];
5516 via_hp_build(codec);
5521 #ifdef CONFIG_SND_HDA_POWER_SAVE
5522 static const struct hda_amp_list vt2002P_loopbacks[] = {
5523 { 0x21, HDA_INPUT, 0 },
5524 { 0x21, HDA_INPUT, 1 },
5525 { 0x21, HDA_INPUT, 2 },
5530 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5532 struct via_spec *spec = codec->spec;
5535 unsigned int present;
5536 /* MUX9 (1eh) = stereo mixer */
5538 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5540 /* PW 5/6/7 (29h/2ah/2bh) */
5542 set_pin_power_state(codec, 0x29, &parm);
5543 set_pin_power_state(codec, 0x2a, &parm);
5544 set_pin_power_state(codec, 0x2b, &parm);
5546 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5547 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5548 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5549 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5550 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5554 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5556 if (spec->codec_type == VT1802) {
5557 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5559 set_pin_power_state(codec, 0x28, &parm);
5560 snd_hda_codec_write(codec, 0x18, 0,
5561 AC_VERB_SET_POWER_STATE, parm);
5562 snd_hda_codec_write(codec, 0x38, 0,
5563 AC_VERB_SET_POWER_STATE, parm);
5565 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5567 set_pin_power_state(codec, 0x26, &parm);
5568 snd_hda_codec_write(codec, 0x1c, 0,
5569 AC_VERB_SET_POWER_STATE, parm);
5570 snd_hda_codec_write(codec, 0x37, 0,
5571 AC_VERB_SET_POWER_STATE, parm);
5574 if (spec->codec_type == VT1802) {
5575 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5577 set_pin_power_state(codec, 0x25, &parm);
5578 snd_hda_codec_write(codec, 0x15, 0,
5579 AC_VERB_SET_POWER_STATE, parm);
5580 snd_hda_codec_write(codec, 0x35, 0,
5581 AC_VERB_SET_POWER_STATE, parm);
5583 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5585 set_pin_power_state(codec, 0x25, &parm);
5586 snd_hda_codec_write(codec, 0x19, 0,
5587 AC_VERB_SET_POWER_STATE, parm);
5588 snd_hda_codec_write(codec, 0x35, 0,
5589 AC_VERB_SET_POWER_STATE, parm);
5592 if (spec->hp_independent_mode)
5593 snd_hda_codec_write(codec, 0x9, 0,
5594 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5597 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5598 present = snd_hda_jack_detect(codec, 0x25);
5601 set_pin_power_state(codec, 0x24, &parm);
5602 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5603 if (spec->codec_type == VT1802)
5604 snd_hda_codec_write(codec, 0x14, 0,
5605 AC_VERB_SET_POWER_STATE, parm);
5607 snd_hda_codec_write(codec, 0x18, 0,
5608 AC_VERB_SET_POWER_STATE, parm);
5609 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5612 present = snd_hda_jack_detect(codec, 0x26);
5614 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5615 if (spec->codec_type == VT1802) {
5616 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5617 snd_hda_codec_write(codec, 0x33, 0,
5618 AC_VERB_SET_POWER_STATE, parm);
5619 snd_hda_codec_write(codec, 0x1c, 0,
5620 AC_VERB_SET_POWER_STATE, parm);
5621 snd_hda_codec_write(codec, 0x3c, 0,
5622 AC_VERB_SET_POWER_STATE, parm);
5624 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5625 snd_hda_codec_write(codec, 0x31, 0,
5626 AC_VERB_SET_POWER_STATE, parm);
5627 snd_hda_codec_write(codec, 0x17, 0,
5628 AC_VERB_SET_POWER_STATE, parm);
5629 snd_hda_codec_write(codec, 0x3b, 0,
5630 AC_VERB_SET_POWER_STATE, parm);
5633 if (imux_is_smixer || !is_aa_path_mute(codec))
5634 snd_hda_codec_write(codec, 0x21, 0,
5635 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5637 snd_hda_codec_write(codec, 0x21, 0,
5638 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5641 /* patch for vt2002P */
5642 static int patch_vt2002P(struct hda_codec *codec)
5644 struct via_spec *spec;
5647 /* create a codec specific record */
5648 spec = via_new_spec(codec);
5652 /* automatic parse from the BIOS config */
5653 err = vt2002P_parse_auto_config(codec);
5658 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5659 "from BIOS. Using genenic mode...\n");
5662 if (spec->codec_type == VT1802)
5663 spec->init_verbs[spec->num_iverbs++] =
5664 vt1802_volume_init_verbs;
5666 spec->init_verbs[spec->num_iverbs++] =
5667 vt2002P_volume_init_verbs;
5669 if (spec->codec_type == VT1802)
5670 spec->init_verbs[spec->num_iverbs++] =
5671 vt1802_uniwill_init_verbs;
5673 spec->init_verbs[spec->num_iverbs++] =
5674 vt2002P_uniwill_init_verbs;
5676 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5677 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5679 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5681 if (spec->adc_nids && spec->input_mux) {
5682 override_mic_boost(codec, 0x2b, 0, 3, 40);
5683 override_mic_boost(codec, 0x29, 0, 3, 40);
5684 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5688 codec->patch_ops = via_patch_ops;
5690 codec->patch_ops.init = via_auto_init;
5691 codec->patch_ops.unsol_event = via_unsol_event;
5693 #ifdef CONFIG_SND_HDA_POWER_SAVE
5694 spec->loopback.amplist = vt2002P_loopbacks;
5697 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
5703 /* capture mixer elements */
5704 static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
5705 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5706 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5707 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5708 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5709 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5710 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5713 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5714 /* The multiple "Capture Source" controls confuse alsamixer
5715 * So call somewhat different..
5717 .name = "Input Source",
5719 .info = via_mux_enum_info,
5720 .get = via_mux_enum_get,
5721 .put = via_mux_enum_put,
5726 static const struct hda_verb vt1812_volume_init_verbs[] = {
5728 * Unmute ADC0-1 and set the default input to mic-in
5730 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5731 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5734 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5737 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5738 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5739 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5740 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5741 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5742 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5744 /* MUX Indices: Mic = 0 */
5745 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5746 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5748 /* PW9 Output enable */
5749 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5751 /* Enable Boost Volume backdoor */
5754 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5756 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5757 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5758 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5759 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5760 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5761 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5762 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5763 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5764 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5766 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5767 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5768 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5769 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5770 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5771 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5773 /* Enable AOW0 to MW9 */
5779 static const struct hda_verb vt1812_uniwill_init_verbs[] = {
5780 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5781 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5782 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5783 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5784 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5785 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5786 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5787 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5791 static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
5795 .nid = 0x8, /* NID to query formats and rates */
5797 .open = via_playback_pcm_open,
5798 .prepare = via_playback_multi_pcm_prepare,
5799 .cleanup = via_playback_multi_pcm_cleanup,
5800 .close = via_pcm_open_close,
5804 static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
5808 .nid = 0x10, /* NID to query formats and rates */
5810 .open = via_pcm_open_close,
5811 .prepare = via_capture_pcm_prepare,
5812 .cleanup = via_capture_pcm_cleanup,
5813 .close = via_pcm_open_close,
5817 static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
5821 /* NID is set in via_build_pcms */
5823 .open = via_dig_playback_pcm_open,
5824 .close = via_dig_playback_pcm_close,
5825 .prepare = via_dig_playback_pcm_prepare,
5826 .cleanup = via_dig_playback_pcm_cleanup
5829 /* fill in the dac_nids table from the parsed pin configuration */
5830 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5831 const struct auto_pin_cfg *cfg)
5833 spec->multiout.num_dacs = 1;
5834 spec->multiout.dac_nids = spec->private_dac_nids;
5835 if (cfg->line_out_pins[0])
5836 spec->private_dac_nids[0] = 0x8;
5841 /* add playback controls from the parsed DAC table */
5842 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5843 const struct auto_pin_cfg *cfg)
5847 if (!cfg->line_out_pins[0])
5850 /* Line-Out: PortE */
5851 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5852 "Front Playback Volume",
5853 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5856 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5857 "Front Playback Switch",
5858 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5865 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5872 spec->multiout.hp_nid = 0x9;
5873 spec->hp_independent_mode_index = 1;
5876 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5877 "Headphone Playback Volume",
5878 HDA_COMPOSE_AMP_VAL(
5879 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5883 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5884 "Headphone Playback Switch",
5885 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5889 create_hp_imux(spec);
5893 /* create playback/capture controls for input pins */
5894 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5895 const struct auto_pin_cfg *cfg)
5897 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21);
5900 static int vt1812_parse_auto_config(struct hda_codec *codec)
5902 struct via_spec *spec = codec->spec;
5906 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5909 fill_dig_outs(codec);
5910 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5914 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5915 return 0; /* can't find valid BIOS pin config */
5917 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5920 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5923 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
5927 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5929 fill_dig_outs(codec);
5931 if (spec->kctls.list)
5932 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5934 spec->input_mux = &spec->private_imux[0];
5937 via_hp_build(codec);
5942 #ifdef CONFIG_SND_HDA_POWER_SAVE
5943 static const struct hda_amp_list vt1812_loopbacks[] = {
5944 { 0x21, HDA_INPUT, 0 },
5945 { 0x21, HDA_INPUT, 1 },
5946 { 0x21, HDA_INPUT, 2 },
5951 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
5953 struct via_spec *spec = codec->spec;
5954 int imux_is_smixer =
5955 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5957 unsigned int present;
5958 /* MUX10 (1eh) = stereo mixer */
5960 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
5962 /* PW 5/6/7 (29h/2ah/2bh) */
5964 set_pin_power_state(codec, 0x29, &parm);
5965 set_pin_power_state(codec, 0x2a, &parm);
5966 set_pin_power_state(codec, 0x2b, &parm);
5968 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
5969 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5970 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5971 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5972 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5976 snd_hda_codec_write(codec, 0x8, 0,
5977 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5979 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5981 set_pin_power_state(codec, 0x28, &parm);
5982 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5983 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
5985 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5987 set_pin_power_state(codec, 0x25, &parm);
5988 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
5989 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
5990 if (spec->hp_independent_mode)
5991 snd_hda_codec_write(codec, 0x9, 0,
5992 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5994 /* Internal Speaker */
5995 /* PW0 (24h), MW0(14h), MUX0(34h) */
5996 present = snd_hda_jack_detect(codec, 0x25);
5999 set_pin_power_state(codec, 0x24, &parm);
6001 snd_hda_codec_write(codec, 0x14, 0,
6002 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6003 snd_hda_codec_write(codec, 0x34, 0,
6004 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6006 snd_hda_codec_write(codec, 0x14, 0,
6007 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6008 snd_hda_codec_write(codec, 0x34, 0,
6009 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6014 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6015 present = snd_hda_jack_detect(codec, 0x28);
6018 set_pin_power_state(codec, 0x31, &parm);
6020 snd_hda_codec_write(codec, 0x1c, 0,
6021 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6022 snd_hda_codec_write(codec, 0x3c, 0,
6023 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6024 snd_hda_codec_write(codec, 0x3e, 0,
6025 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6027 snd_hda_codec_write(codec, 0x1c, 0,
6028 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6029 snd_hda_codec_write(codec, 0x3c, 0,
6030 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6031 snd_hda_codec_write(codec, 0x3e, 0,
6032 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6035 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6037 set_pin_power_state(codec, 0x33, &parm);
6038 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6039 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6043 /* patch for vt1812 */
6044 static int patch_vt1812(struct hda_codec *codec)
6046 struct via_spec *spec;
6049 /* create a codec specific record */
6050 spec = via_new_spec(codec);
6054 /* automatic parse from the BIOS config */
6055 err = vt1812_parse_auto_config(codec);
6060 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6061 "from BIOS. Using genenic mode...\n");
6065 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6066 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6068 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6069 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6071 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6073 if (spec->adc_nids && spec->input_mux) {
6074 override_mic_boost(codec, 0x2b, 0, 3, 40);
6075 override_mic_boost(codec, 0x29, 0, 3, 40);
6076 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6080 codec->patch_ops = via_patch_ops;
6082 codec->patch_ops.init = via_auto_init;
6083 codec->patch_ops.unsol_event = via_unsol_event;
6085 #ifdef CONFIG_SND_HDA_POWER_SAVE
6086 spec->loopback.amplist = vt1812_loopbacks;
6089 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
6096 static const struct hda_codec_preset snd_hda_preset_via[] = {
6097 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6098 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6099 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6100 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6101 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6102 .patch = patch_vt1709_10ch},
6103 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6104 .patch = patch_vt1709_10ch},
6105 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6106 .patch = patch_vt1709_10ch},
6107 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6108 .patch = patch_vt1709_10ch},
6109 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6110 .patch = patch_vt1709_6ch},
6111 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6112 .patch = patch_vt1709_6ch},
6113 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6114 .patch = patch_vt1709_6ch},
6115 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6116 .patch = patch_vt1709_6ch},
6117 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6118 .patch = patch_vt1708B_8ch},
6119 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6120 .patch = patch_vt1708B_8ch},
6121 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6122 .patch = patch_vt1708B_8ch},
6123 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6124 .patch = patch_vt1708B_8ch},
6125 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6126 .patch = patch_vt1708B_4ch},
6127 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6128 .patch = patch_vt1708B_4ch},
6129 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6130 .patch = patch_vt1708B_4ch},
6131 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6132 .patch = patch_vt1708B_4ch},
6133 { .id = 0x11060397, .name = "VT1708S",
6134 .patch = patch_vt1708S},
6135 { .id = 0x11061397, .name = "VT1708S",
6136 .patch = patch_vt1708S},
6137 { .id = 0x11062397, .name = "VT1708S",
6138 .patch = patch_vt1708S},
6139 { .id = 0x11063397, .name = "VT1708S",
6140 .patch = patch_vt1708S},
6141 { .id = 0x11064397, .name = "VT1705",
6142 .patch = patch_vt1708S},
6143 { .id = 0x11065397, .name = "VT1708S",
6144 .patch = patch_vt1708S},
6145 { .id = 0x11066397, .name = "VT1708S",
6146 .patch = patch_vt1708S},
6147 { .id = 0x11067397, .name = "VT1708S",
6148 .patch = patch_vt1708S},
6149 { .id = 0x11060398, .name = "VT1702",
6150 .patch = patch_vt1702},
6151 { .id = 0x11061398, .name = "VT1702",
6152 .patch = patch_vt1702},
6153 { .id = 0x11062398, .name = "VT1702",
6154 .patch = patch_vt1702},
6155 { .id = 0x11063398, .name = "VT1702",
6156 .patch = patch_vt1702},
6157 { .id = 0x11064398, .name = "VT1702",
6158 .patch = patch_vt1702},
6159 { .id = 0x11065398, .name = "VT1702",
6160 .patch = patch_vt1702},
6161 { .id = 0x11066398, .name = "VT1702",
6162 .patch = patch_vt1702},
6163 { .id = 0x11067398, .name = "VT1702",
6164 .patch = patch_vt1702},
6165 { .id = 0x11060428, .name = "VT1718S",
6166 .patch = patch_vt1718S},
6167 { .id = 0x11064428, .name = "VT1718S",
6168 .patch = patch_vt1718S},
6169 { .id = 0x11060441, .name = "VT2020",
6170 .patch = patch_vt1718S},
6171 { .id = 0x11064441, .name = "VT1828S",
6172 .patch = patch_vt1718S},
6173 { .id = 0x11060433, .name = "VT1716S",
6174 .patch = patch_vt1716S},
6175 { .id = 0x1106a721, .name = "VT1716S",
6176 .patch = patch_vt1716S},
6177 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6178 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6179 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6180 { .id = 0x11060440, .name = "VT1818S",
6181 .patch = patch_vt1708S},
6182 { .id = 0x11060446, .name = "VT1802",
6183 .patch = patch_vt2002P},
6184 { .id = 0x11068446, .name = "VT1802",
6185 .patch = patch_vt2002P},
6189 MODULE_ALIAS("snd-hda-codec-id:1106*");
6191 static struct hda_codec_preset_list via_list = {
6192 .preset = snd_hda_preset_via,
6193 .owner = THIS_MODULE,
6196 MODULE_LICENSE("GPL");
6197 MODULE_DESCRIPTION("VIA HD-audio codec");
6199 static int __init patch_via_init(void)
6201 return snd_hda_add_codec_preset(&via_list);
6204 static void __exit patch_via_exit(void)
6206 snd_hda_delete_codec_preset(&via_list);
6209 module_init(patch_via_init)
6210 module_exit(patch_via_exit)