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;
119 const struct hda_pcm_stream *stream_analog_playback;
120 const struct hda_pcm_stream *stream_analog_capture;
122 char *stream_name_digital;
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 const hda_nid_t *adc_nids;
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 enum VIA_HDA_CODEC codec_type;
158 /* work to check hp jack state */
159 struct hda_codec *codec;
160 struct delayed_work vt1708_hp_work;
161 int vt1708_jack_detectect;
162 int vt1708_hp_present;
164 void (*set_widgets_power_state)(struct hda_codec *codec);
166 #ifdef CONFIG_SND_HDA_POWER_SAVE
167 struct hda_loopback_check loopback;
171 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
172 static struct via_spec * via_new_spec(struct hda_codec *codec)
174 struct via_spec *spec;
176 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
182 spec->codec_type = get_codec_type(codec);
183 /* VT1708BCE & VT1708S are almost same */
184 if (spec->codec_type == VT1708BCE)
185 spec->codec_type = VT1708S;
189 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
191 u32 vendor_id = codec->vendor_id;
192 u16 ven_id = vendor_id >> 16;
193 u16 dev_id = vendor_id & 0xffff;
194 enum VIA_HDA_CODEC codec_type;
197 if (ven_id != 0x1106)
198 codec_type = UNKNOWN;
199 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
201 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
202 codec_type = VT1709_10CH;
203 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
204 codec_type = VT1709_6CH;
205 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
206 codec_type = VT1708B_8CH;
207 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
208 codec_type = VT1708BCE;
209 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
210 codec_type = VT1708B_4CH;
211 else if ((dev_id & 0xfff) == 0x397
212 && (dev_id >> 12) < 8)
213 codec_type = VT1708S;
214 else if ((dev_id & 0xfff) == 0x398
215 && (dev_id >> 12) < 8)
217 else if ((dev_id & 0xfff) == 0x428
218 && (dev_id >> 12) < 8)
219 codec_type = VT1718S;
220 else if (dev_id == 0x0433 || dev_id == 0xa721)
221 codec_type = VT1716S;
222 else if (dev_id == 0x0441 || dev_id == 0x4441)
223 codec_type = VT1718S;
224 else if (dev_id == 0x0438 || dev_id == 0x4438)
225 codec_type = VT2002P;
226 else if (dev_id == 0x0448)
228 else if (dev_id == 0x0440)
229 codec_type = VT1708S;
230 else if ((dev_id & 0xfff) == 0x446)
233 codec_type = UNKNOWN;
237 #define VIA_JACK_EVENT 0x20
238 #define VIA_HP_EVENT 0x01
239 #define VIA_GPIO_EVENT 0x02
240 #define VIA_MONO_EVENT 0x03
241 #define VIA_SPEAKER_EVENT 0x04
242 #define VIA_BIND_HP_EVENT 0x05
247 VIA_CTL_WIDGET_ANALOG_MUTE,
248 VIA_CTL_WIDGET_BIND_PIN_MUTE,
258 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
259 static int is_aa_path_mute(struct hda_codec *codec);
261 static void vt1708_start_hp_work(struct via_spec *spec)
263 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
265 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
266 !spec->vt1708_jack_detectect);
267 if (!delayed_work_pending(&spec->vt1708_hp_work))
268 schedule_delayed_work(&spec->vt1708_hp_work,
269 msecs_to_jiffies(100));
272 static void vt1708_stop_hp_work(struct via_spec *spec)
274 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
276 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
277 && !is_aa_path_mute(spec->codec))
279 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
280 !spec->vt1708_jack_detectect);
281 cancel_delayed_work_sync(&spec->vt1708_hp_work);
284 static void set_widgets_power_state(struct hda_codec *codec)
286 struct via_spec *spec = codec->spec;
287 if (spec->set_widgets_power_state)
288 spec->set_widgets_power_state(codec);
291 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
292 struct snd_ctl_elem_value *ucontrol)
294 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
297 set_widgets_power_state(codec);
298 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
299 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
300 if (is_aa_path_mute(codec))
301 vt1708_start_hp_work(codec->spec);
303 vt1708_stop_hp_work(codec->spec);
308 /* modify .put = snd_hda_mixer_amp_switch_put */
309 #define ANALOG_INPUT_MUTE \
310 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
313 .info = snd_hda_mixer_amp_switch_info, \
314 .get = snd_hda_mixer_amp_switch_get, \
315 .put = analog_input_switch_put, \
316 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
318 static void via_hp_bind_automute(struct hda_codec *codec);
320 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_value *ucontrol)
323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
324 struct via_spec *spec = codec->spec;
328 long *valp = ucontrol->value.integer.value;
330 if (strstr(kcontrol->id.name, "Switch") == NULL) {
331 snd_printd("Invalid control!\n");
334 change = snd_hda_mixer_amp_switch_put(kcontrol,
337 lmute = *valp ? 0 : HDA_AMP_MUTE;
339 rmute = *valp ? 0 : HDA_AMP_MUTE;
342 if (!spec->hp_independent_mode) {
343 for (i = 0; i < spec->autocfg.hp_outs; i++) {
344 snd_hda_codec_amp_update(
345 codec, spec->autocfg.hp_pins[i],
346 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
348 snd_hda_codec_amp_update(
349 codec, spec->autocfg.hp_pins[i],
350 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
355 if (!lmute && !rmute) {
357 for (i = 0; i < spec->autocfg.line_outs; i++)
358 snd_hda_codec_amp_stereo(
359 codec, spec->autocfg.line_out_pins[i],
360 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
362 for (i = 0; i < spec->autocfg.speaker_outs; i++)
363 snd_hda_codec_amp_stereo(
364 codec, spec->autocfg.speaker_pins[i],
365 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
367 via_hp_bind_automute(codec);
371 /* Mute all left channels */
372 for (i = 1; i < spec->autocfg.line_outs; i++)
373 snd_hda_codec_amp_update(
375 spec->autocfg.line_out_pins[i],
376 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
378 for (i = 0; i < spec->autocfg.speaker_outs; i++)
379 snd_hda_codec_amp_update(
381 spec->autocfg.speaker_pins[i],
382 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
386 /* mute all right channels */
387 for (i = 1; i < spec->autocfg.line_outs; i++)
388 snd_hda_codec_amp_update(
390 spec->autocfg.line_out_pins[i],
391 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
393 for (i = 0; i < spec->autocfg.speaker_outs; i++)
394 snd_hda_codec_amp_update(
396 spec->autocfg.speaker_pins[i],
397 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
404 #define BIND_PIN_MUTE \
405 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
408 .info = snd_hda_mixer_amp_switch_info, \
409 .get = snd_hda_mixer_amp_switch_get, \
410 .put = bind_pin_switch_put, \
411 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
413 static const struct snd_kcontrol_new via_control_templates[] = {
414 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
415 HDA_CODEC_MUTE(NULL, 0, 0, 0),
420 static const hda_nid_t vt1708_adc_nids[2] = {
425 static const hda_nid_t vt1709_adc_nids[3] = {
430 static const hda_nid_t vt1708B_adc_nids[2] = {
435 static const hda_nid_t vt1708S_adc_nids[2] = {
440 static const hda_nid_t vt1702_adc_nids[3] = {
445 static const hda_nid_t vt1718S_adc_nids[2] = {
450 static const hda_nid_t vt1716S_adc_nids[2] = {
455 static const hda_nid_t vt2002P_adc_nids[2] = {
460 static const hda_nid_t vt1812_adc_nids[2] = {
466 /* add dynamic controls */
467 static int __via_add_control(struct via_spec *spec, int type, const char *name,
468 int idx, unsigned long val)
470 struct snd_kcontrol_new *knew;
472 snd_array_init(&spec->kctls, sizeof(*knew), 32);
473 knew = snd_array_new(&spec->kctls);
476 *knew = via_control_templates[type];
477 knew->name = kstrdup(name, GFP_KERNEL);
480 if (get_amp_nid_(val))
481 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
482 knew->private_value = val;
486 #define via_add_control(spec, type, name, val) \
487 __via_add_control(spec, type, name, 0, val)
489 static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
490 const struct snd_kcontrol_new *tmpl)
492 struct snd_kcontrol_new *knew;
494 snd_array_init(&spec->kctls, sizeof(*knew), 32);
495 knew = snd_array_new(&spec->kctls);
499 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
505 static void via_free_kctls(struct hda_codec *codec)
507 struct via_spec *spec = codec->spec;
509 if (spec->kctls.list) {
510 struct snd_kcontrol_new *kctl = spec->kctls.list;
512 for (i = 0; i < spec->kctls.used; i++)
515 snd_array_free(&spec->kctls);
518 /* create input playback/capture controls for the given pin */
519 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
520 int type_idx, int idx, int mix_nid)
525 sprintf(name, "%s Playback Volume", ctlname);
526 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
527 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
530 sprintf(name, "%s Playback Switch", ctlname);
531 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
532 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
538 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
539 hda_nid_t nid, int pin_type,
543 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
545 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
547 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
548 snd_hda_codec_write(codec, nid, 0,
549 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
553 static void via_auto_init_multi_out(struct hda_codec *codec)
555 struct via_spec *spec = codec->spec;
558 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
559 hda_nid_t nid = spec->autocfg.line_out_pins[i];
561 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
565 static void via_auto_init_hp_out(struct hda_codec *codec)
567 struct via_spec *spec = codec->spec;
571 for (i = 0; i < spec->autocfg.hp_outs; i++) {
572 pin = spec->autocfg.hp_pins[i];
573 if (pin) /* connect to front */
574 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
578 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
580 static void via_auto_init_analog_input(struct hda_codec *codec)
582 struct via_spec *spec = codec->spec;
583 const struct auto_pin_cfg *cfg = &spec->autocfg;
587 for (i = 0; i < cfg->num_inputs; i++) {
588 hda_nid_t nid = cfg->inputs[i].pin;
589 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
591 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
595 snd_hda_codec_write(codec, nid, 0,
596 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
600 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
601 unsigned int *affected_parm)
604 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
605 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
606 >> AC_DEFCFG_MISC_SHIFT
607 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
608 unsigned present = snd_hda_jack_detect(codec, nid);
609 struct via_spec *spec = codec->spec;
610 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
611 || ((no_presence || present)
612 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
613 *affected_parm = AC_PWRST_D0; /* if it's connected */
618 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
624 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_info *uinfo)
627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628 struct via_spec *spec = codec->spec;
629 return snd_hda_input_mux_info(spec->input_mux, uinfo);
632 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct via_spec *spec = codec->spec;
637 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
639 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
643 static int via_mux_enum_put(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);
651 if (!spec->mux_nids[adc_idx])
653 /* switch to D0 beofre change index */
654 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
655 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
656 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
657 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
659 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
660 spec->mux_nids[adc_idx],
661 &spec->cur_mux[adc_idx]);
662 /* update jack power state */
663 set_widgets_power_state(codec);
668 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
669 struct snd_ctl_elem_info *uinfo)
671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
672 struct via_spec *spec = codec->spec;
673 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
676 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
680 hda_nid_t nid = kcontrol->private_value;
683 /* use !! to translate conn sel 2 for VT1718S */
684 pinsel = !!snd_hda_codec_read(codec, nid, 0,
685 AC_VERB_GET_CONNECT_SEL,
687 ucontrol->value.enumerated.item[0] = pinsel;
692 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
694 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
696 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
697 ctl->vd[0].access |= active
698 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
699 snd_ctl_notify(codec->bus->card,
700 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
704 static hda_nid_t side_mute_channel(struct via_spec *spec)
706 switch (spec->codec_type) {
707 case VT1708: return 0x1b;
708 case VT1709_10CH: return 0x29;
709 case VT1708B_8CH: /* fall thru */
710 case VT1708S: return 0x27;
711 case VT2002P: return 0x19;
712 case VT1802: return 0x15;
713 case VT1812: return 0x15;
718 static int update_side_mute_status(struct hda_codec *codec)
720 /* mute side channel */
721 struct via_spec *spec = codec->spec;
723 hda_nid_t sw3 = side_mute_channel(spec);
726 if (VT2002P_COMPATIBLE(spec))
727 parm = spec->hp_independent_mode ?
728 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
730 parm = spec->hp_independent_mode ?
731 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
732 snd_hda_codec_write(codec, sw3, 0,
733 AC_VERB_SET_AMP_GAIN_MUTE, parm);
734 if (spec->codec_type == VT1812)
735 snd_hda_codec_write(codec, 0x1d, 0,
736 AC_VERB_SET_AMP_GAIN_MUTE, parm);
741 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
742 struct snd_ctl_elem_value *ucontrol)
744 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745 struct via_spec *spec = codec->spec;
746 hda_nid_t nid = kcontrol->private_value;
747 unsigned int pinsel = ucontrol->value.enumerated.item[0];
748 unsigned int parm0, parm1;
749 /* Get Independent Mode index of headphone pin widget */
750 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
752 if (spec->codec_type == VT1718S) {
753 snd_hda_codec_write(codec, nid, 0,
754 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
755 /* Set correct mute switch for MW3 */
756 parm0 = spec->hp_independent_mode ?
757 AMP_IN_UNMUTE(0) : AMP_IN_MUTE(0);
758 parm1 = spec->hp_independent_mode ?
759 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
760 snd_hda_codec_write(codec, 0x1b, 0,
761 AC_VERB_SET_AMP_GAIN_MUTE, parm0);
762 snd_hda_codec_write(codec, 0x1b, 0,
763 AC_VERB_SET_AMP_GAIN_MUTE, parm1);
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 nid = side_mute_channel(spec);
848 knew = via_clone_control(spec, &via_hp_mixer[1]);
851 knew->subdevice = nid;
857 static void notify_aa_path_ctls(struct hda_codec *codec)
860 struct snd_ctl_elem_id id;
861 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
862 struct snd_kcontrol *ctl;
864 memset(&id, 0, sizeof(id));
865 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
866 for (i = 0; i < ARRAY_SIZE(labels); i++) {
867 sprintf(id.name, "%s Playback Volume", labels[i]);
868 ctl = snd_hda_find_mixer_ctl(codec, id.name);
870 snd_ctl_notify(codec->bus->card,
871 SNDRV_CTL_EVENT_MASK_VALUE,
876 static void mute_aa_path(struct hda_codec *codec, int mute)
878 struct via_spec *spec = codec->spec;
883 /* get nid of MW0 and start & end index */
884 switch (spec->codec_type) {
912 /* check AA path's mute status */
913 for (i = start_idx; i <= end_idx; i++) {
914 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
915 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
919 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
921 const struct auto_pin_cfg *cfg = &spec->autocfg;
924 for (i = 0; i < cfg->num_inputs; i++) {
925 if (pin == cfg->inputs[i].pin)
926 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
931 static int via_smart51_info(struct snd_kcontrol *kcontrol,
932 struct snd_ctl_elem_info *uinfo)
934 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
936 uinfo->value.integer.min = 0;
937 uinfo->value.integer.max = 1;
941 static int via_smart51_get(struct snd_kcontrol *kcontrol,
942 struct snd_ctl_elem_value *ucontrol)
944 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
945 struct via_spec *spec = codec->spec;
946 const struct auto_pin_cfg *cfg = &spec->autocfg;
950 for (i = 0; i < cfg->num_inputs; i++) {
951 hda_nid_t nid = cfg->inputs[i].pin;
952 int ctl = snd_hda_codec_read(codec, nid, 0,
953 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
954 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
956 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
957 spec->hp_independent_mode && spec->codec_type != VT1718S)
958 continue; /* ignore FMic for independent HP */
959 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
962 *ucontrol->value.integer.value = on;
966 static int via_smart51_put(struct snd_kcontrol *kcontrol,
967 struct snd_ctl_elem_value *ucontrol)
969 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
970 struct via_spec *spec = codec->spec;
971 const struct auto_pin_cfg *cfg = &spec->autocfg;
972 int out_in = *ucontrol->value.integer.value
973 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
976 for (i = 0; i < cfg->num_inputs; i++) {
977 hda_nid_t nid = cfg->inputs[i].pin;
980 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
982 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
983 spec->hp_independent_mode && spec->codec_type != VT1718S)
984 continue; /* don't retask FMic for independent HP */
986 parm = snd_hda_codec_read(codec, nid, 0,
987 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
988 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
990 snd_hda_codec_write(codec, nid, 0,
991 AC_VERB_SET_PIN_WIDGET_CONTROL,
993 if (out_in == AC_PINCTL_OUT_EN) {
994 mute_aa_path(codec, 1);
995 notify_aa_path_ctls(codec);
997 if (spec->codec_type == VT1718S) {
998 snd_hda_codec_amp_stereo(
999 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1002 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
1003 if (spec->codec_type == VT1708S
1004 || spec->codec_type == VT1716S) {
1005 /* input = index 1 (AOW3) */
1006 snd_hda_codec_write(
1008 AC_VERB_SET_CONNECT_SEL, 1);
1009 snd_hda_codec_amp_stereo(
1010 codec, nid, HDA_OUTPUT,
1011 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1015 spec->smart51_enabled = *ucontrol->value.integer.value;
1016 set_widgets_power_state(codec);
1020 static const struct snd_kcontrol_new via_smart51_mixer[2] = {
1022 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1023 .name = "Smart 5.1",
1025 .info = via_smart51_info,
1026 .get = via_smart51_get,
1027 .put = via_smart51_put,
1030 .iface = NID_MAPPING,
1031 .name = "Smart 5.1",
1035 static int via_smart51_build(struct via_spec *spec)
1037 struct snd_kcontrol_new *knew;
1038 const struct auto_pin_cfg *cfg = &spec->autocfg;
1044 if (cfg->line_outs > 2)
1047 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1051 for (i = 0; i < cfg->num_inputs; i++) {
1052 nid = cfg->inputs[i].pin;
1053 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1054 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1057 knew->subdevice = nid;
1065 /* capture mixer elements */
1066 static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
1067 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1068 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1069 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1070 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1072 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1073 /* The multiple "Capture Source" controls confuse alsamixer
1074 * So call somewhat different..
1076 /* .name = "Capture Source", */
1077 .name = "Input Source",
1079 .info = via_mux_enum_info,
1080 .get = via_mux_enum_get,
1081 .put = via_mux_enum_put,
1086 /* check AA path's mute statue */
1087 static int is_aa_path_mute(struct hda_codec *codec)
1090 hda_nid_t nid_mixer;
1094 struct via_spec *spec = codec->spec;
1095 /* get nid of MW0 and start & end index */
1096 switch (spec->codec_type) {
1125 /* check AA path's mute status */
1126 for (i = start_idx; i <= end_idx; i++) {
1127 unsigned int con_list = snd_hda_codec_read(
1128 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1129 int shift = 8 * (i % 4);
1130 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1131 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1132 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1133 /* check mute status while the pin is connected */
1134 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1136 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1138 if (!mute_l || !mute_r) {
1147 /* enter/exit analog low-current mode */
1148 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1150 struct via_spec *spec = codec->spec;
1151 static int saved_stream_idle = 1; /* saved stream idle status */
1152 int enable = is_aa_path_mute(codec);
1153 unsigned int verb = 0;
1154 unsigned int parm = 0;
1156 if (stream_idle == -1) /* stream status did not change */
1157 enable = enable && saved_stream_idle;
1159 enable = enable && stream_idle;
1160 saved_stream_idle = stream_idle;
1163 /* decide low current mode's verb & parameter */
1164 switch (spec->codec_type) {
1168 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1174 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1178 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1184 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1187 return; /* other codecs are not supported */
1190 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1194 * generic initialization of ADC, input mixers and output mixers
1196 static const struct hda_verb vt1708_volume_init_verbs[] = {
1198 * Unmute ADC0-1 and set the default input to mic-in
1200 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1201 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1204 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1207 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1208 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1209 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1210 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1211 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1212 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1215 * Set up output mixers (0x19 - 0x1b)
1217 /* set vol=0 to output mixers */
1218 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1219 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1220 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1222 /* Setup default input MW0 to PW4 */
1223 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1224 /* PW9 Output enable */
1225 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1226 /* power down jack detect function */
1231 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1232 struct hda_codec *codec,
1233 struct snd_pcm_substream *substream)
1235 struct via_spec *spec = codec->spec;
1236 int idle = substream->pstr->substream_opened == 1
1237 && substream->ref_count == 0;
1238 analog_low_current_mode(codec, idle);
1239 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1243 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1244 unsigned int stream_tag,
1245 unsigned int format,
1246 struct snd_pcm_substream *substream)
1248 struct via_spec *spec = codec->spec;
1249 struct hda_multi_out *mout = &spec->multiout;
1250 const hda_nid_t *nids = mout->dac_nids;
1251 int chs = substream->runtime->channels;
1254 mutex_lock(&codec->spdif_mutex);
1255 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1257 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1259 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1260 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1261 /* turn off SPDIF once; otherwise the IEC958 bits won't
1263 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1264 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1265 AC_VERB_SET_DIGI_CONVERT_1,
1267 ~AC_DIG1_ENABLE & 0xff);
1268 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1269 stream_tag, 0, format);
1270 /* turn on again (if needed) */
1271 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1272 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1273 AC_VERB_SET_DIGI_CONVERT_1,
1274 codec->spdif_ctls & 0xff);
1276 mout->dig_out_used = 0;
1277 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1281 mutex_unlock(&codec->spdif_mutex);
1284 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1287 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1288 && !spec->hp_independent_mode)
1289 /* headphone out will just decode front left/right (stereo) */
1290 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1293 /* extra outputs copied from front */
1294 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1295 if (mout->extra_out_nid[i])
1296 snd_hda_codec_setup_stream(codec,
1297 mout->extra_out_nid[i],
1298 stream_tag, 0, format);
1301 for (i = 1; i < mout->num_dacs; i++) {
1302 if (chs >= (i + 1) * 2) /* independent out */
1303 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1305 else /* copy front */
1306 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1311 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1312 struct hda_codec *codec,
1313 unsigned int stream_tag,
1314 unsigned int format,
1315 struct snd_pcm_substream *substream)
1317 struct via_spec *spec = codec->spec;
1318 struct hda_multi_out *mout = &spec->multiout;
1319 const hda_nid_t *nids = mout->dac_nids;
1321 if (substream->number == 0)
1322 playback_multi_pcm_prep_0(codec, stream_tag, format,
1325 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1326 spec->hp_independent_mode)
1327 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1328 stream_tag, 0, format);
1330 vt1708_start_hp_work(spec);
1334 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1335 struct hda_codec *codec,
1336 struct snd_pcm_substream *substream)
1338 struct via_spec *spec = codec->spec;
1339 struct hda_multi_out *mout = &spec->multiout;
1340 const hda_nid_t *nids = mout->dac_nids;
1343 if (substream->number == 0) {
1344 for (i = 0; i < mout->num_dacs; i++)
1345 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1347 if (mout->hp_nid && !spec->hp_independent_mode)
1348 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1351 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1352 if (mout->extra_out_nid[i])
1353 snd_hda_codec_setup_stream(codec,
1354 mout->extra_out_nid[i],
1356 mutex_lock(&codec->spdif_mutex);
1357 if (mout->dig_out_nid &&
1358 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1359 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1361 mout->dig_out_used = 0;
1363 mutex_unlock(&codec->spdif_mutex);
1365 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1366 spec->hp_independent_mode)
1367 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1370 vt1708_stop_hp_work(spec);
1377 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1378 struct hda_codec *codec,
1379 struct snd_pcm_substream *substream)
1381 struct via_spec *spec = codec->spec;
1382 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1385 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1386 struct hda_codec *codec,
1387 struct snd_pcm_substream *substream)
1389 struct via_spec *spec = codec->spec;
1390 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1393 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1394 struct hda_codec *codec,
1395 unsigned int stream_tag,
1396 unsigned int format,
1397 struct snd_pcm_substream *substream)
1399 struct via_spec *spec = codec->spec;
1400 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1401 stream_tag, format, substream);
1404 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1405 struct hda_codec *codec,
1406 struct snd_pcm_substream *substream)
1408 struct via_spec *spec = codec->spec;
1409 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1416 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1417 struct hda_codec *codec,
1418 unsigned int stream_tag,
1419 unsigned int format,
1420 struct snd_pcm_substream *substream)
1422 struct via_spec *spec = codec->spec;
1424 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1425 stream_tag, 0, format);
1429 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1430 struct hda_codec *codec,
1431 struct snd_pcm_substream *substream)
1433 struct via_spec *spec = codec->spec;
1434 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1438 static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
1442 .nid = 0x10, /* NID to query formats and rates */
1444 .open = via_playback_pcm_open,
1445 .prepare = via_playback_multi_pcm_prepare,
1446 .cleanup = via_playback_multi_pcm_cleanup
1450 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1454 .nid = 0x10, /* NID to query formats and rates */
1455 /* We got noisy outputs on the right channel on VT1708 when
1456 * 24bit samples are used. Until any workaround is found,
1457 * disable the 24bit format, so far.
1459 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1461 .open = via_playback_pcm_open,
1462 .prepare = via_playback_multi_pcm_prepare,
1463 .cleanup = via_playback_multi_pcm_cleanup
1467 static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
1471 .nid = 0x15, /* NID to query formats and rates */
1473 .prepare = via_capture_pcm_prepare,
1474 .cleanup = via_capture_pcm_cleanup
1478 static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
1482 /* NID is set in via_build_pcms */
1484 .open = via_dig_playback_pcm_open,
1485 .close = via_dig_playback_pcm_close,
1486 .prepare = via_dig_playback_pcm_prepare,
1487 .cleanup = via_dig_playback_pcm_cleanup
1491 static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
1497 static int via_build_controls(struct hda_codec *codec)
1499 struct via_spec *spec = codec->spec;
1500 struct snd_kcontrol *kctl;
1501 const struct snd_kcontrol_new *knew;
1504 for (i = 0; i < spec->num_mixers; i++) {
1505 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1510 if (spec->multiout.dig_out_nid) {
1511 err = snd_hda_create_spdif_out_ctls(codec,
1512 spec->multiout.dig_out_nid);
1515 err = snd_hda_create_spdif_share_sw(codec,
1519 spec->multiout.share_spdif = 1;
1521 if (spec->dig_in_nid) {
1522 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1527 /* assign Capture Source enums to NID */
1528 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1529 for (i = 0; kctl && i < kctl->count; i++) {
1530 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1535 /* other nid->control mapping */
1536 for (i = 0; i < spec->num_mixers; i++) {
1537 for (knew = spec->mixers[i]; knew->name; knew++) {
1538 if (knew->iface != NID_MAPPING)
1540 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1543 err = snd_hda_add_nid(codec, kctl, 0,
1548 /* init power states */
1549 set_widgets_power_state(codec);
1550 analog_low_current_mode(codec, 1);
1552 via_free_kctls(codec); /* no longer needed */
1556 static int via_build_pcms(struct hda_codec *codec)
1558 struct via_spec *spec = codec->spec;
1559 struct hda_pcm *info = spec->pcm_rec;
1561 codec->num_pcms = 1;
1562 codec->pcm_info = info;
1564 info->name = spec->stream_name_analog;
1565 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1566 *(spec->stream_analog_playback);
1567 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1568 spec->multiout.dac_nids[0];
1569 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1570 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1572 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1573 spec->multiout.max_channels;
1575 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1578 info->name = spec->stream_name_digital;
1579 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1580 if (spec->multiout.dig_out_nid) {
1581 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1582 *(spec->stream_digital_playback);
1583 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1584 spec->multiout.dig_out_nid;
1586 if (spec->dig_in_nid) {
1587 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1588 *(spec->stream_digital_capture);
1589 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1597 static void via_free(struct hda_codec *codec)
1599 struct via_spec *spec = codec->spec;
1604 via_free_kctls(codec);
1605 vt1708_stop_hp_work(spec);
1609 /* mute internal speaker if HP is plugged */
1610 static void via_hp_automute(struct hda_codec *codec)
1612 unsigned int present = 0;
1613 struct via_spec *spec = codec->spec;
1615 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1617 if (!spec->hp_independent_mode) {
1618 struct snd_ctl_elem_id id;
1620 snd_hda_codec_amp_stereo(
1621 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1622 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1624 memset(&id, 0, sizeof(id));
1625 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1626 strcpy(id.name, "Front Playback Switch");
1627 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1632 /* mute mono out if HP or Line out is plugged */
1633 static void via_mono_automute(struct hda_codec *codec)
1635 unsigned int hp_present, lineout_present;
1636 struct via_spec *spec = codec->spec;
1638 if (spec->codec_type != VT1716S)
1641 lineout_present = snd_hda_jack_detect(codec,
1642 spec->autocfg.line_out_pins[0]);
1644 /* Mute Mono Out if Line Out is plugged */
1645 if (lineout_present) {
1646 snd_hda_codec_amp_stereo(
1647 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1651 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1653 if (!spec->hp_independent_mode)
1654 snd_hda_codec_amp_stereo(
1655 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1656 hp_present ? HDA_AMP_MUTE : 0);
1659 static void via_gpio_control(struct hda_codec *codec)
1661 unsigned int gpio_data;
1662 unsigned int vol_counter;
1664 unsigned int master_vol;
1666 struct via_spec *spec = codec->spec;
1668 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1669 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1671 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1672 0xF84, 0) & 0x3F0000) >> 16;
1674 vol = vol_counter & 0x1F;
1675 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1676 AC_VERB_GET_AMP_GAIN_MUTE,
1679 if (gpio_data == 0x02) {
1680 /* unmute line out */
1681 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1682 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1684 if (vol_counter & 0x20) {
1685 /* decrease volume */
1686 if (vol > master_vol)
1688 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1692 /* increase volume */
1693 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1695 ((master_vol+vol) > 0x2A) ? 0x2A :
1698 } else if (!(gpio_data & 0x02)) {
1700 snd_hda_codec_amp_stereo(codec,
1701 spec->autocfg.line_out_pins[0],
1702 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1707 /* mute Internal-Speaker if HP is plugged */
1708 static void via_speaker_automute(struct hda_codec *codec)
1710 unsigned int hp_present;
1711 struct via_spec *spec = codec->spec;
1713 if (!VT2002P_COMPATIBLE(spec))
1716 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1718 if (!spec->hp_independent_mode) {
1719 struct snd_ctl_elem_id id;
1720 snd_hda_codec_amp_stereo(
1721 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1722 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1724 memset(&id, 0, sizeof(id));
1725 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1726 strcpy(id.name, "Speaker Playback Switch");
1727 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1732 /* mute line-out and internal speaker if HP is plugged */
1733 static void via_hp_bind_automute(struct hda_codec *codec)
1735 /* use long instead of int below just to avoid an internal compiler
1736 * error with gcc 4.0.x
1738 unsigned long hp_present, present = 0;
1739 struct via_spec *spec = codec->spec;
1742 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1745 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1747 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
1749 if (!spec->hp_independent_mode) {
1750 /* Mute Line-Outs */
1751 for (i = 0; i < spec->autocfg.line_outs; i++)
1752 snd_hda_codec_amp_stereo(
1753 codec, spec->autocfg.line_out_pins[i],
1755 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1757 present = hp_present;
1760 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1761 snd_hda_codec_amp_stereo(
1762 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1763 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1767 /* unsolicited event for jack sensing */
1768 static void via_unsol_event(struct hda_codec *codec,
1773 if (res & VIA_JACK_EVENT)
1774 set_widgets_power_state(codec);
1776 res &= ~VIA_JACK_EVENT;
1778 if (res == VIA_HP_EVENT)
1779 via_hp_automute(codec);
1780 else if (res == VIA_GPIO_EVENT)
1781 via_gpio_control(codec);
1782 else if (res == VIA_MONO_EVENT)
1783 via_mono_automute(codec);
1784 else if (res == VIA_SPEAKER_EVENT)
1785 via_speaker_automute(codec);
1786 else if (res == VIA_BIND_HP_EVENT)
1787 via_hp_bind_automute(codec);
1790 static int via_init(struct hda_codec *codec)
1792 struct via_spec *spec = codec->spec;
1794 for (i = 0; i < spec->num_iverbs; i++)
1795 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1797 /* Lydia Add for EAPD enable */
1798 if (!spec->dig_in_nid) { /* No Digital In connection */
1799 if (spec->dig_in_pin) {
1800 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1801 AC_VERB_SET_PIN_WIDGET_CONTROL,
1803 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1804 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1806 } else /* enable SPDIF-input pin */
1807 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1808 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1810 /* assign slave outs */
1811 if (spec->slave_dig_outs[0])
1812 codec->slave_dig_outs = spec->slave_dig_outs;
1817 #ifdef SND_HDA_NEEDS_RESUME
1818 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1820 struct via_spec *spec = codec->spec;
1821 vt1708_stop_hp_work(spec);
1826 #ifdef CONFIG_SND_HDA_POWER_SAVE
1827 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1829 struct via_spec *spec = codec->spec;
1830 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1836 static const struct hda_codec_ops via_patch_ops = {
1837 .build_controls = via_build_controls,
1838 .build_pcms = via_build_pcms,
1841 #ifdef SND_HDA_NEEDS_RESUME
1842 .suspend = via_suspend,
1844 #ifdef CONFIG_SND_HDA_POWER_SAVE
1845 .check_power_status = via_check_power_status,
1849 /* fill in the dac_nids table from the parsed pin configuration */
1850 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1851 const struct auto_pin_cfg *cfg)
1856 spec->multiout.num_dacs = cfg->line_outs;
1858 spec->multiout.dac_nids = spec->private_dac_nids;
1860 for (i = 0; i < 4; i++) {
1861 nid = cfg->line_out_pins[i];
1863 /* config dac list */
1865 case AUTO_SEQ_FRONT:
1866 spec->private_dac_nids[i] = 0x10;
1868 case AUTO_SEQ_CENLFE:
1869 spec->private_dac_nids[i] = 0x12;
1871 case AUTO_SEQ_SURROUND:
1872 spec->private_dac_nids[i] = 0x11;
1875 spec->private_dac_nids[i] = 0x13;
1884 /* add playback controls from the parsed DAC table */
1885 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1886 const struct auto_pin_cfg *cfg)
1889 static const char * const chname[4] = {
1890 "Front", "Surround", "C/LFE", "Side"
1892 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1895 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1896 nid = cfg->line_out_pins[i];
1901 nid_vol = nid_vols[i];
1903 if (i == AUTO_SEQ_CENLFE) {
1905 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1906 "Center Playback Volume",
1907 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1911 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1912 "LFE Playback Volume",
1913 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1917 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1918 "Center Playback Switch",
1919 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1923 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1924 "LFE Playback Switch",
1925 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1929 } else if (i == AUTO_SEQ_FRONT) {
1930 /* add control to mixer index 0 */
1931 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1932 "Master Front Playback Volume",
1933 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1937 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1938 "Master Front Playback Switch",
1939 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1944 /* add control to PW3 */
1945 sprintf(name, "%s Playback Volume", chname[i]);
1946 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1947 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1951 sprintf(name, "%s Playback Switch", chname[i]);
1952 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1953 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1958 sprintf(name, "%s Playback Volume", chname[i]);
1959 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1960 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1964 sprintf(name, "%s Playback Switch", chname[i]);
1965 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1966 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1976 static void create_hp_imux(struct via_spec *spec)
1979 struct hda_input_mux *imux = &spec->private_imux[1];
1980 static const char * const texts[] = { "OFF", "ON", NULL};
1982 /* for hp mode select */
1983 for (i = 0; texts[i]; i++)
1984 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1986 spec->hp_mux = &spec->private_imux[1];
1989 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1996 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1997 spec->hp_independent_mode_index = 1;
1999 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2000 "Headphone Playback Volume",
2001 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2004 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2005 "Headphone Playback Switch",
2006 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2010 create_hp_imux(spec);
2015 /* create playback/capture controls for input pins */
2016 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2017 const struct auto_pin_cfg *cfg,
2019 const hda_nid_t pin_idxs[],
2022 struct via_spec *spec = codec->spec;
2023 struct hda_input_mux *imux = &spec->private_imux[0];
2024 int i, err, idx, type, type_idx = 0;
2026 /* for internal loopback recording select */
2027 for (idx = 0; idx < num_idxs; idx++) {
2028 if (pin_idxs[idx] == 0xff) {
2029 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2034 for (i = 0; i < cfg->num_inputs; i++) {
2036 type = cfg->inputs[i].type;
2037 for (idx = 0; idx < num_idxs; idx++)
2038 if (pin_idxs[idx] == cfg->inputs[i].pin)
2040 if (idx >= num_idxs)
2042 if (i > 0 && type == cfg->inputs[i - 1].type)
2046 label = hda_get_autocfg_input_label(codec, cfg, i);
2047 if (spec->codec_type == VT1708S ||
2048 spec->codec_type == VT1702 ||
2049 spec->codec_type == VT1716S)
2050 err = via_new_analog_input(spec, label, type_idx,
2053 err = via_new_analog_input(spec, label, type_idx,
2057 snd_hda_add_imux_item(imux, label, idx, NULL);
2062 /* create playback/capture controls for input pins */
2063 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2064 const struct auto_pin_cfg *cfg)
2066 static const hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2067 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2068 ARRAY_SIZE(pin_idxs));
2071 #ifdef CONFIG_SND_HDA_POWER_SAVE
2072 static const struct hda_amp_list vt1708_loopbacks[] = {
2073 { 0x17, HDA_INPUT, 1 },
2074 { 0x17, HDA_INPUT, 2 },
2075 { 0x17, HDA_INPUT, 3 },
2076 { 0x17, HDA_INPUT, 4 },
2081 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2083 unsigned int def_conf;
2084 unsigned char seqassoc;
2086 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2087 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2088 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2089 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2090 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2091 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2092 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2098 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2099 struct snd_ctl_elem_value *ucontrol)
2101 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2102 struct via_spec *spec = codec->spec;
2104 if (spec->codec_type != VT1708)
2106 spec->vt1708_jack_detectect =
2107 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2108 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2112 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2113 struct snd_ctl_elem_value *ucontrol)
2115 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2116 struct via_spec *spec = codec->spec;
2119 if (spec->codec_type != VT1708)
2121 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2122 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2123 == !spec->vt1708_jack_detectect;
2124 if (spec->vt1708_jack_detectect) {
2125 mute_aa_path(codec, 1);
2126 notify_aa_path_ctls(codec);
2131 static const struct snd_kcontrol_new vt1708_jack_detectect[] = {
2133 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2134 .name = "Jack Detect",
2136 .info = snd_ctl_boolean_mono_info,
2137 .get = vt1708_jack_detectect_get,
2138 .put = vt1708_jack_detectect_put,
2143 static int vt1708_parse_auto_config(struct hda_codec *codec)
2145 struct via_spec *spec = codec->spec;
2148 /* Add HP and CD pin config connect bit re-config action */
2149 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2150 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2152 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2155 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2158 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2159 return 0; /* can't find valid BIOS pin config */
2161 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2164 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2167 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2170 /* add jack detect on/off control */
2171 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2175 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2177 if (spec->autocfg.dig_outs)
2178 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2179 spec->dig_in_pin = VT1708_DIGIN_PIN;
2180 if (spec->autocfg.dig_in_pin)
2181 spec->dig_in_nid = VT1708_DIGIN_NID;
2183 if (spec->kctls.list)
2184 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2186 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2188 spec->input_mux = &spec->private_imux[0];
2191 via_hp_build(codec);
2193 via_smart51_build(spec);
2197 /* init callback for auto-configuration model -- overriding the default init */
2198 static int via_auto_init(struct hda_codec *codec)
2200 struct via_spec *spec = codec->spec;
2203 via_auto_init_multi_out(codec);
2204 via_auto_init_hp_out(codec);
2205 via_auto_init_analog_input(codec);
2207 if (VT2002P_COMPATIBLE(spec)) {
2208 via_hp_bind_automute(codec);
2210 via_hp_automute(codec);
2211 via_speaker_automute(codec);
2217 static void vt1708_update_hp_jack_state(struct work_struct *work)
2219 struct via_spec *spec = container_of(work, struct via_spec,
2220 vt1708_hp_work.work);
2221 if (spec->codec_type != VT1708)
2223 /* if jack state toggled */
2224 if (spec->vt1708_hp_present
2225 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2226 spec->vt1708_hp_present ^= 1;
2227 via_hp_automute(spec->codec);
2229 vt1708_start_hp_work(spec);
2232 static int get_mux_nids(struct hda_codec *codec)
2234 struct via_spec *spec = codec->spec;
2235 hda_nid_t nid, conn[8];
2239 for (i = 0; i < spec->num_adc_nids; i++) {
2240 nid = spec->adc_nids[i];
2242 type = get_wcaps_type(get_wcaps(codec, nid));
2243 if (type == AC_WID_PIN)
2245 n = snd_hda_get_connections(codec, nid, conn,
2250 spec->mux_nids[i] = nid;
2259 static int patch_vt1708(struct hda_codec *codec)
2261 struct via_spec *spec;
2264 /* create a codec specific record */
2265 spec = via_new_spec(codec);
2269 /* automatic parse from the BIOS config */
2270 err = vt1708_parse_auto_config(codec);
2275 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2276 "from BIOS. Using genenic mode...\n");
2280 spec->stream_name_analog = "VT1708 Analog";
2281 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2282 /* disable 32bit format on VT1708 */
2283 if (codec->vendor_id == 0x11061708)
2284 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2285 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2287 spec->stream_name_digital = "VT1708 Digital";
2288 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2289 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2292 if (!spec->adc_nids && spec->input_mux) {
2293 spec->adc_nids = vt1708_adc_nids;
2294 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2295 get_mux_nids(codec);
2296 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2300 codec->patch_ops = via_patch_ops;
2302 codec->patch_ops.init = via_auto_init;
2303 #ifdef CONFIG_SND_HDA_POWER_SAVE
2304 spec->loopback.amplist = vt1708_loopbacks;
2306 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2310 /* capture mixer elements */
2311 static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
2312 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2313 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2314 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2315 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2316 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2317 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2319 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2320 /* The multiple "Capture Source" controls confuse alsamixer
2321 * So call somewhat different..
2323 /* .name = "Capture Source", */
2324 .name = "Input Source",
2326 .info = via_mux_enum_info,
2327 .get = via_mux_enum_get,
2328 .put = via_mux_enum_put,
2333 static const struct hda_verb vt1709_uniwill_init_verbs[] = {
2334 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2335 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2340 * generic initialization of ADC, input mixers and output mixers
2342 static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2344 * Unmute ADC0-2 and set the default input to mic-in
2346 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2347 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2348 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2351 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2354 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2355 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2356 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2357 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2358 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2359 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2362 * Set up output selector (0x1a, 0x1b, 0x29)
2364 /* set vol=0 to output mixers */
2365 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2366 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2367 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2370 * Unmute PW3 and PW4
2372 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2373 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2375 /* Set input of PW4 as MW0 */
2376 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2377 /* PW9 Output enable */
2378 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2382 static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2386 .nid = 0x10, /* NID to query formats and rates */
2388 .open = via_playback_pcm_open,
2389 .prepare = via_playback_multi_pcm_prepare,
2390 .cleanup = via_playback_multi_pcm_cleanup,
2394 static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2398 .nid = 0x10, /* NID to query formats and rates */
2400 .open = via_playback_pcm_open,
2401 .prepare = via_playback_multi_pcm_prepare,
2402 .cleanup = via_playback_multi_pcm_cleanup,
2406 static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
2410 .nid = 0x14, /* NID to query formats and rates */
2412 .prepare = via_capture_pcm_prepare,
2413 .cleanup = via_capture_pcm_cleanup
2417 static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
2421 /* NID is set in via_build_pcms */
2423 .open = via_dig_playback_pcm_open,
2424 .close = via_dig_playback_pcm_close
2428 static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
2434 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2435 const struct auto_pin_cfg *cfg)
2440 if (cfg->line_outs == 4) /* 10 channels */
2441 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2442 else if (cfg->line_outs == 3) /* 6 channels */
2443 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2445 spec->multiout.dac_nids = spec->private_dac_nids;
2447 if (cfg->line_outs == 4) { /* 10 channels */
2448 for (i = 0; i < cfg->line_outs; i++) {
2449 nid = cfg->line_out_pins[i];
2451 /* config dac list */
2453 case AUTO_SEQ_FRONT:
2455 spec->private_dac_nids[i] = 0x10;
2457 case AUTO_SEQ_CENLFE:
2459 spec->private_dac_nids[i] = 0x12;
2461 case AUTO_SEQ_SURROUND:
2463 spec->private_dac_nids[i] = 0x11;
2467 spec->private_dac_nids[i] = 0x27;
2474 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2476 } else if (cfg->line_outs == 3) { /* 6 channels */
2477 for (i = 0; i < cfg->line_outs; i++) {
2478 nid = cfg->line_out_pins[i];
2480 /* config dac list */
2482 case AUTO_SEQ_FRONT:
2484 spec->private_dac_nids[i] = 0x10;
2486 case AUTO_SEQ_CENLFE:
2488 spec->private_dac_nids[i] = 0x12;
2490 case AUTO_SEQ_SURROUND:
2492 spec->private_dac_nids[i] = 0x11;
2504 /* add playback controls from the parsed DAC table */
2505 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2506 const struct auto_pin_cfg *cfg)
2509 static const char * const chname[4] = {
2510 "Front", "Surround", "C/LFE", "Side"
2512 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2515 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2516 nid = cfg->line_out_pins[i];
2521 nid_vol = nid_vols[i];
2523 if (i == AUTO_SEQ_CENLFE) {
2525 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2526 "Center Playback Volume",
2527 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2531 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2532 "LFE Playback Volume",
2533 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2537 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2538 "Center Playback Switch",
2539 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2543 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2544 "LFE Playback Switch",
2545 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2549 } else if (i == AUTO_SEQ_FRONT) {
2550 /* ADD control to mixer index 0 */
2551 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2552 "Master Front Playback Volume",
2553 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2557 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2558 "Master Front Playback Switch",
2559 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2564 /* add control to PW3 */
2565 sprintf(name, "%s Playback Volume", chname[i]);
2566 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2567 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2571 sprintf(name, "%s Playback Switch", chname[i]);
2572 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2573 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2577 } else if (i == AUTO_SEQ_SURROUND) {
2578 sprintf(name, "%s Playback Volume", chname[i]);
2579 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2580 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2584 sprintf(name, "%s Playback Switch", chname[i]);
2585 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2586 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2590 } else if (i == AUTO_SEQ_SIDE) {
2591 sprintf(name, "%s Playback Volume", chname[i]);
2592 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2593 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2597 sprintf(name, "%s Playback Switch", chname[i]);
2598 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2599 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2609 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2616 if (spec->multiout.num_dacs == 5) /* 10 channels */
2617 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2618 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2619 spec->multiout.hp_nid = 0;
2620 spec->hp_independent_mode_index = 1;
2622 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2623 "Headphone Playback Volume",
2624 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2627 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2628 "Headphone Playback Switch",
2629 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2636 /* create playback/capture controls for input pins */
2637 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
2638 const struct auto_pin_cfg *cfg)
2640 static const hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
2641 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
2642 ARRAY_SIZE(pin_idxs));
2645 static int vt1709_parse_auto_config(struct hda_codec *codec)
2647 struct via_spec *spec = codec->spec;
2650 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2653 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2656 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2657 return 0; /* can't find valid BIOS pin config */
2659 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2662 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2665 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
2669 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2671 if (spec->autocfg.dig_outs)
2672 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2673 spec->dig_in_pin = VT1709_DIGIN_PIN;
2674 if (spec->autocfg.dig_in_pin)
2675 spec->dig_in_nid = VT1709_DIGIN_NID;
2677 if (spec->kctls.list)
2678 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2680 spec->input_mux = &spec->private_imux[0];
2683 via_hp_build(codec);
2685 via_smart51_build(spec);
2689 #ifdef CONFIG_SND_HDA_POWER_SAVE
2690 static const struct hda_amp_list vt1709_loopbacks[] = {
2691 { 0x18, HDA_INPUT, 1 },
2692 { 0x18, HDA_INPUT, 2 },
2693 { 0x18, HDA_INPUT, 3 },
2694 { 0x18, HDA_INPUT, 4 },
2699 static int patch_vt1709_10ch(struct hda_codec *codec)
2701 struct via_spec *spec;
2704 /* create a codec specific record */
2705 spec = via_new_spec(codec);
2709 err = vt1709_parse_auto_config(codec);
2714 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2715 "Using genenic mode...\n");
2718 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2719 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2721 spec->stream_name_analog = "VT1709 Analog";
2722 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2723 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2725 spec->stream_name_digital = "VT1709 Digital";
2726 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2727 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2730 if (!spec->adc_nids && spec->input_mux) {
2731 spec->adc_nids = vt1709_adc_nids;
2732 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2733 get_mux_nids(codec);
2734 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2738 codec->patch_ops = via_patch_ops;
2740 codec->patch_ops.init = via_auto_init;
2741 codec->patch_ops.unsol_event = via_unsol_event;
2742 #ifdef CONFIG_SND_HDA_POWER_SAVE
2743 spec->loopback.amplist = vt1709_loopbacks;
2749 * generic initialization of ADC, input mixers and output mixers
2751 static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2753 * Unmute ADC0-2 and set the default input to mic-in
2755 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2756 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2757 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2760 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2763 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2764 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2765 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2766 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2767 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2768 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2771 * Set up output selector (0x1a, 0x1b, 0x29)
2773 /* set vol=0 to output mixers */
2774 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2775 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2776 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2779 * Unmute PW3 and PW4
2781 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2782 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2784 /* Set input of PW4 as MW0 */
2785 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2786 /* PW9 Output enable */
2787 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2791 static int patch_vt1709_6ch(struct hda_codec *codec)
2793 struct via_spec *spec;
2796 /* create a codec specific record */
2797 spec = via_new_spec(codec);
2801 err = vt1709_parse_auto_config(codec);
2806 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2807 "Using genenic mode...\n");
2810 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2811 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2813 spec->stream_name_analog = "VT1709 Analog";
2814 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2815 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2817 spec->stream_name_digital = "VT1709 Digital";
2818 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2819 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2822 if (!spec->adc_nids && spec->input_mux) {
2823 spec->adc_nids = vt1709_adc_nids;
2824 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2825 get_mux_nids(codec);
2826 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2830 codec->patch_ops = via_patch_ops;
2832 codec->patch_ops.init = via_auto_init;
2833 codec->patch_ops.unsol_event = via_unsol_event;
2834 #ifdef CONFIG_SND_HDA_POWER_SAVE
2835 spec->loopback.amplist = vt1709_loopbacks;
2840 /* capture mixer elements */
2841 static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2842 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2843 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2844 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2845 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2847 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2848 /* The multiple "Capture Source" controls confuse alsamixer
2849 * So call somewhat different..
2851 /* .name = "Capture Source", */
2852 .name = "Input Source",
2854 .info = via_mux_enum_info,
2855 .get = via_mux_enum_get,
2856 .put = via_mux_enum_put,
2861 * generic initialization of ADC, input mixers and output mixers
2863 static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2865 * Unmute ADC0-1 and set the default input to mic-in
2867 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2871 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2874 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2875 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2876 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2877 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2878 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2879 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2882 * Set up output mixers
2884 /* set vol=0 to output mixers */
2885 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2886 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2887 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2889 /* Setup default input to PW4 */
2890 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2891 /* PW9 Output enable */
2892 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2893 /* PW10 Input enable */
2894 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2898 static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2900 * Unmute ADC0-1 and set the default input to mic-in
2902 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2903 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2906 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2909 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2910 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2911 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2912 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2913 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2914 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2917 * Set up output mixers
2919 /* set vol=0 to output mixers */
2920 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2921 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2922 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2924 /* Setup default input of PW4 to MW0 */
2925 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2926 /* PW9 Output enable */
2927 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2928 /* PW10 Input enable */
2929 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2933 static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
2934 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2935 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2936 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2937 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2938 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2939 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2940 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2941 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2942 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2946 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2947 struct hda_codec *codec,
2948 struct snd_pcm_substream *substream)
2950 int idle = substream->pstr->substream_opened == 1
2951 && substream->ref_count == 0;
2953 analog_low_current_mode(codec, idle);
2957 static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2961 .nid = 0x10, /* NID to query formats and rates */
2963 .open = via_playback_pcm_open,
2964 .prepare = via_playback_multi_pcm_prepare,
2965 .cleanup = via_playback_multi_pcm_cleanup,
2966 .close = via_pcm_open_close
2970 static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2974 .nid = 0x10, /* NID to query formats and rates */
2976 .open = via_playback_pcm_open,
2977 .prepare = via_playback_multi_pcm_prepare,
2978 .cleanup = via_playback_multi_pcm_cleanup
2982 static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2986 .nid = 0x13, /* NID to query formats and rates */
2988 .open = via_pcm_open_close,
2989 .prepare = via_capture_pcm_prepare,
2990 .cleanup = via_capture_pcm_cleanup,
2991 .close = via_pcm_open_close
2995 static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2999 /* NID is set in via_build_pcms */
3001 .open = via_dig_playback_pcm_open,
3002 .close = via_dig_playback_pcm_close,
3003 .prepare = via_dig_playback_pcm_prepare,
3004 .cleanup = via_dig_playback_pcm_cleanup
3008 static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3014 /* fill in the dac_nids table from the parsed pin configuration */
3015 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3016 const struct auto_pin_cfg *cfg)
3021 spec->multiout.num_dacs = cfg->line_outs;
3023 spec->multiout.dac_nids = spec->private_dac_nids;
3025 for (i = 0; i < 4; i++) {
3026 nid = cfg->line_out_pins[i];
3028 /* config dac list */
3030 case AUTO_SEQ_FRONT:
3031 spec->private_dac_nids[i] = 0x10;
3033 case AUTO_SEQ_CENLFE:
3034 spec->private_dac_nids[i] = 0x24;
3036 case AUTO_SEQ_SURROUND:
3037 spec->private_dac_nids[i] = 0x11;
3040 spec->private_dac_nids[i] = 0x25;
3049 /* add playback controls from the parsed DAC table */
3050 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3051 const struct auto_pin_cfg *cfg)
3054 static const char * const chname[4] = {
3055 "Front", "Surround", "C/LFE", "Side"
3057 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3058 hda_nid_t nid, nid_vol = 0;
3061 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3062 nid = cfg->line_out_pins[i];
3067 nid_vol = nid_vols[i];
3069 if (i == AUTO_SEQ_CENLFE) {
3071 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3072 "Center Playback Volume",
3073 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3077 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3078 "LFE Playback Volume",
3079 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3083 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3084 "Center Playback Switch",
3085 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3089 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3090 "LFE Playback Switch",
3091 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3095 } else if (i == AUTO_SEQ_FRONT) {
3096 /* add control to mixer index 0 */
3097 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3098 "Master Front Playback Volume",
3099 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3103 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3104 "Master Front Playback Switch",
3105 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3110 /* add control to PW3 */
3111 sprintf(name, "%s Playback Volume", chname[i]);
3112 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3113 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3117 sprintf(name, "%s Playback Switch", chname[i]);
3118 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3119 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3124 sprintf(name, "%s Playback Volume", chname[i]);
3125 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3126 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3130 sprintf(name, "%s Playback Switch", chname[i]);
3131 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3132 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3142 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3149 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3150 spec->hp_independent_mode_index = 1;
3152 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3153 "Headphone Playback Volume",
3154 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3157 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3158 "Headphone Playback Switch",
3159 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3163 create_hp_imux(spec);
3168 /* create playback/capture controls for input pins */
3169 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3170 const struct auto_pin_cfg *cfg)
3172 static const hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3173 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3174 ARRAY_SIZE(pin_idxs));
3177 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3179 struct via_spec *spec = codec->spec;
3182 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3185 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3188 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3189 return 0; /* can't find valid BIOS pin config */
3191 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3194 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3197 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3201 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3203 if (spec->autocfg.dig_outs)
3204 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3205 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3206 if (spec->autocfg.dig_in_pin)
3207 spec->dig_in_nid = VT1708B_DIGIN_NID;
3209 if (spec->kctls.list)
3210 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3212 spec->input_mux = &spec->private_imux[0];
3215 via_hp_build(codec);
3217 via_smart51_build(spec);
3221 #ifdef CONFIG_SND_HDA_POWER_SAVE
3222 static const struct hda_amp_list vt1708B_loopbacks[] = {
3223 { 0x16, HDA_INPUT, 1 },
3224 { 0x16, HDA_INPUT, 2 },
3225 { 0x16, HDA_INPUT, 3 },
3226 { 0x16, HDA_INPUT, 4 },
3231 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3233 struct via_spec *spec = codec->spec;
3237 if ((spec->codec_type != VT1708B_4CH) &&
3238 (codec->vendor_id != 0x11064397))
3241 /* SW0 (17h) = stereo mixer */
3243 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3244 == ((spec->codec_type == VT1708S) ? 5 : 0));
3246 /* PW 1/2/5 (1ah/1bh/1eh) */
3248 set_pin_power_state(codec, 0x1a, &parm);
3249 set_pin_power_state(codec, 0x1b, &parm);
3250 set_pin_power_state(codec, 0x1e, &parm);
3253 /* SW0 (17h), AIW 0/1 (13h/14h) */
3254 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3255 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3256 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3259 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3261 set_pin_power_state(codec, 0x19, &parm);
3262 if (spec->smart51_enabled)
3263 set_pin_power_state(codec, 0x1b, &parm);
3264 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3265 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3267 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3270 set_pin_power_state(codec, 0x22, &parm);
3271 if (spec->smart51_enabled)
3272 set_pin_power_state(codec, 0x1a, &parm);
3273 snd_hda_codec_write(codec, 0x26, 0,
3274 AC_VERB_SET_POWER_STATE, parm);
3275 snd_hda_codec_write(codec, 0x24, 0,
3276 AC_VERB_SET_POWER_STATE, parm);
3277 } else if (codec->vendor_id == 0x11064397) {
3278 /* PW7(23h), SW2(27h), AOW2(25h) */
3280 set_pin_power_state(codec, 0x23, &parm);
3281 if (spec->smart51_enabled)
3282 set_pin_power_state(codec, 0x1a, &parm);
3283 snd_hda_codec_write(codec, 0x27, 0,
3284 AC_VERB_SET_POWER_STATE, parm);
3285 snd_hda_codec_write(codec, 0x25, 0,
3286 AC_VERB_SET_POWER_STATE, parm);
3289 /* PW 3/4/7 (1ch/1dh/23h) */
3291 /* force to D0 for internal Speaker */
3292 set_pin_power_state(codec, 0x1c, &parm);
3293 set_pin_power_state(codec, 0x1d, &parm);
3295 set_pin_power_state(codec, 0x23, &parm);
3297 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3298 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3299 imux_is_smixer ? AC_PWRST_D0 : parm);
3300 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3302 snd_hda_codec_write(codec, 0x25, 0,
3303 AC_VERB_SET_POWER_STATE, parm);
3304 snd_hda_codec_write(codec, 0x27, 0,
3305 AC_VERB_SET_POWER_STATE, parm);
3306 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3307 snd_hda_codec_write(codec, 0x25, 0,
3308 AC_VERB_SET_POWER_STATE, parm);
3311 static int patch_vt1708S(struct hda_codec *codec);
3312 static int patch_vt1708B_8ch(struct hda_codec *codec)
3314 struct via_spec *spec;
3317 if (get_codec_type(codec) == VT1708BCE)
3318 return patch_vt1708S(codec);
3319 /* create a codec specific record */
3320 spec = via_new_spec(codec);
3324 /* automatic parse from the BIOS config */
3325 err = vt1708B_parse_auto_config(codec);
3330 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3331 "from BIOS. Using genenic mode...\n");
3334 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3335 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3337 spec->stream_name_analog = "VT1708B Analog";
3338 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3339 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3341 spec->stream_name_digital = "VT1708B Digital";
3342 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3343 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3345 if (!spec->adc_nids && spec->input_mux) {
3346 spec->adc_nids = vt1708B_adc_nids;
3347 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3348 get_mux_nids(codec);
3349 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3353 codec->patch_ops = via_patch_ops;
3355 codec->patch_ops.init = via_auto_init;
3356 codec->patch_ops.unsol_event = via_unsol_event;
3357 #ifdef CONFIG_SND_HDA_POWER_SAVE
3358 spec->loopback.amplist = vt1708B_loopbacks;
3361 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3366 static int patch_vt1708B_4ch(struct hda_codec *codec)
3368 struct via_spec *spec;
3371 /* create a codec specific record */
3372 spec = via_new_spec(codec);
3376 /* automatic parse from the BIOS config */
3377 err = vt1708B_parse_auto_config(codec);
3382 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3383 "from BIOS. Using genenic mode...\n");
3386 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3387 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3389 spec->stream_name_analog = "VT1708B Analog";
3390 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3391 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3393 spec->stream_name_digital = "VT1708B Digital";
3394 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3395 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3397 if (!spec->adc_nids && spec->input_mux) {
3398 spec->adc_nids = vt1708B_adc_nids;
3399 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3400 get_mux_nids(codec);
3401 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3405 codec->patch_ops = via_patch_ops;
3407 codec->patch_ops.init = via_auto_init;
3408 codec->patch_ops.unsol_event = via_unsol_event;
3409 #ifdef CONFIG_SND_HDA_POWER_SAVE
3410 spec->loopback.amplist = vt1708B_loopbacks;
3413 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3418 /* Patch for VT1708S */
3420 /* capture mixer elements */
3421 static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3422 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3423 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3424 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3425 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3426 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3427 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3430 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3431 /* The multiple "Capture Source" controls confuse alsamixer
3432 * So call somewhat different..
3434 /* .name = "Capture Source", */
3435 .name = "Input Source",
3437 .info = via_mux_enum_info,
3438 .get = via_mux_enum_get,
3439 .put = via_mux_enum_put,
3444 static const struct hda_verb vt1708S_volume_init_verbs[] = {
3445 /* Unmute ADC0-1 and set the default input to mic-in */
3446 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3447 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3449 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3450 * analog-loopback mixer widget */
3451 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3452 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3453 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3454 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3455 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3456 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3458 /* Setup default input of PW4 to MW0 */
3459 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3460 /* PW9, PW10 Output enable */
3461 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3462 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3463 /* Enable Mic Boost Volume backdoor */
3465 /* don't bybass mixer */
3470 static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
3471 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3472 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3473 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3474 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3475 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3476 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3477 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3478 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3479 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3483 static const struct hda_verb vt1705_uniwill_init_verbs[] = {
3484 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3485 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3486 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3487 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3488 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3489 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3490 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3491 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3495 static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3499 .nid = 0x10, /* NID to query formats and rates */
3501 .open = via_playback_pcm_open,
3502 .prepare = via_playback_multi_pcm_prepare,
3503 .cleanup = via_playback_multi_pcm_cleanup,
3504 .close = via_pcm_open_close
3508 static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
3512 .nid = 0x10, /* NID to query formats and rates */
3514 .open = via_playback_pcm_open,
3515 .prepare = via_playback_multi_pcm_prepare,
3516 .cleanup = via_playback_multi_pcm_cleanup,
3517 .close = via_pcm_open_close
3521 static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3525 .nid = 0x13, /* NID to query formats and rates */
3527 .open = via_pcm_open_close,
3528 .prepare = via_capture_pcm_prepare,
3529 .cleanup = via_capture_pcm_cleanup,
3530 .close = via_pcm_open_close
3534 static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3538 /* NID is set in via_build_pcms */
3540 .open = via_dig_playback_pcm_open,
3541 .close = via_dig_playback_pcm_close,
3542 .prepare = via_dig_playback_pcm_prepare,
3543 .cleanup = via_dig_playback_pcm_cleanup
3547 /* fill in the dac_nids table from the parsed pin configuration */
3548 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3549 const struct auto_pin_cfg *cfg)
3554 spec->multiout.num_dacs = cfg->line_outs;
3556 spec->multiout.dac_nids = spec->private_dac_nids;
3558 for (i = 0; i < 4; i++) {
3559 nid = cfg->line_out_pins[i];
3561 /* config dac list */
3563 case AUTO_SEQ_FRONT:
3564 spec->private_dac_nids[i] = 0x10;
3566 case AUTO_SEQ_CENLFE:
3567 if (spec->codec->vendor_id == 0x11064397)
3568 spec->private_dac_nids[i] = 0x25;
3570 spec->private_dac_nids[i] = 0x24;
3572 case AUTO_SEQ_SURROUND:
3573 spec->private_dac_nids[i] = 0x11;
3576 spec->private_dac_nids[i] = 0x25;
3582 /* for Smart 5.1, line/mic inputs double as output pins */
3583 if (cfg->line_outs == 1) {
3584 spec->multiout.num_dacs = 3;
3585 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3586 if (spec->codec->vendor_id == 0x11064397)
3587 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
3589 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3595 /* add playback controls from the parsed DAC table */
3596 static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
3597 const struct auto_pin_cfg *cfg)
3599 struct via_spec *spec = codec->spec;
3601 static const char * const chname[4] = {
3602 "Front", "Surround", "C/LFE", "Side"
3604 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3605 {0x10, 0x11, 0x25, 0} };
3606 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3607 {0x1C, 0x18, 0x27, 0} };
3608 hda_nid_t nid, nid_vol, nid_mute;
3611 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3612 nid = cfg->line_out_pins[i];
3614 /* for Smart 5.1, there are always at least six channels */
3615 if (!nid && i > AUTO_SEQ_CENLFE)
3618 if (codec->vendor_id == 0x11064397) {
3619 nid_vol = nid_vols[1][i];
3620 nid_mute = nid_mutes[1][i];
3622 nid_vol = nid_vols[0][i];
3623 nid_mute = nid_mutes[0][i];
3625 if (!nid_vol && !nid_mute)
3628 if (i == AUTO_SEQ_CENLFE) {
3630 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3631 "Center Playback Volume",
3632 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3636 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3637 "LFE Playback Volume",
3638 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3642 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3643 "Center Playback Switch",
3644 HDA_COMPOSE_AMP_VAL(nid_mute,
3649 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3650 "LFE Playback Switch",
3651 HDA_COMPOSE_AMP_VAL(nid_mute,
3656 } else if (i == AUTO_SEQ_FRONT) {
3657 /* add control to mixer index 0 */
3658 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3659 "Master Front Playback Volume",
3660 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3664 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3665 "Master Front Playback Switch",
3666 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3672 sprintf(name, "%s Playback Volume", chname[i]);
3673 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3674 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3678 sprintf(name, "%s Playback Switch", chname[i]);
3679 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3680 HDA_COMPOSE_AMP_VAL(nid_mute,
3686 sprintf(name, "%s Playback Volume", chname[i]);
3687 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3688 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3692 sprintf(name, "%s Playback Switch", chname[i]);
3693 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3694 HDA_COMPOSE_AMP_VAL(nid_mute,
3705 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3712 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3713 spec->hp_independent_mode_index = 1;
3715 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3716 "Headphone Playback Volume",
3717 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3721 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3722 "Headphone Playback Switch",
3723 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3727 create_hp_imux(spec);
3732 /* create playback/capture controls for input pins */
3733 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3734 const struct auto_pin_cfg *cfg)
3736 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
3737 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3738 ARRAY_SIZE(pin_idxs));
3741 /* fill out digital output widgets; one for master and one for slave outputs */
3742 static void fill_dig_outs(struct hda_codec *codec)
3744 struct via_spec *spec = codec->spec;
3747 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3751 nid = spec->autocfg.dig_out_pins[i];
3754 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3757 if (!spec->multiout.dig_out_nid)
3758 spec->multiout.dig_out_nid = nid;
3760 spec->slave_dig_outs[0] = nid;
3761 break; /* at most two dig outs */
3766 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3768 struct via_spec *spec = codec->spec;
3771 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3774 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3777 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3778 return 0; /* can't find valid BIOS pin config */
3780 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
3783 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3786 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
3790 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3792 fill_dig_outs(codec);
3794 if (spec->kctls.list)
3795 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3797 spec->input_mux = &spec->private_imux[0];
3800 via_hp_build(codec);
3802 via_smart51_build(spec);
3806 #ifdef CONFIG_SND_HDA_POWER_SAVE
3807 static const struct hda_amp_list vt1708S_loopbacks[] = {
3808 { 0x16, HDA_INPUT, 1 },
3809 { 0x16, HDA_INPUT, 2 },
3810 { 0x16, HDA_INPUT, 3 },
3811 { 0x16, HDA_INPUT, 4 },
3816 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3817 int offset, int num_steps, int step_size)
3819 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3820 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3821 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3822 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3823 (0 << AC_AMPCAP_MUTE_SHIFT));
3826 static int patch_vt1708S(struct hda_codec *codec)
3828 struct via_spec *spec;
3831 /* create a codec specific record */
3832 spec = via_new_spec(codec);
3836 /* automatic parse from the BIOS config */
3837 err = vt1708S_parse_auto_config(codec);
3842 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3843 "from BIOS. Using genenic mode...\n");
3846 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3847 if (codec->vendor_id == 0x11064397)
3848 spec->init_verbs[spec->num_iverbs++] =
3849 vt1705_uniwill_init_verbs;
3851 spec->init_verbs[spec->num_iverbs++] =
3852 vt1708S_uniwill_init_verbs;
3854 if (codec->vendor_id == 0x11060440)
3855 spec->stream_name_analog = "VT1818S Analog";
3856 else if (codec->vendor_id == 0x11064397)
3857 spec->stream_name_analog = "VT1705 Analog";
3859 spec->stream_name_analog = "VT1708S Analog";
3860 if (codec->vendor_id == 0x11064397)
3861 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3863 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
3864 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3866 if (codec->vendor_id == 0x11060440)
3867 spec->stream_name_digital = "VT1818S Digital";
3868 else if (codec->vendor_id == 0x11064397)
3869 spec->stream_name_digital = "VT1705 Digital";
3871 spec->stream_name_digital = "VT1708S Digital";
3872 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3874 if (!spec->adc_nids && spec->input_mux) {
3875 spec->adc_nids = vt1708S_adc_nids;
3876 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
3877 get_mux_nids(codec);
3878 override_mic_boost(codec, 0x1a, 0, 3, 40);
3879 override_mic_boost(codec, 0x1e, 0, 3, 40);
3880 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3884 codec->patch_ops = via_patch_ops;
3886 codec->patch_ops.init = via_auto_init;
3887 codec->patch_ops.unsol_event = via_unsol_event;
3888 #ifdef CONFIG_SND_HDA_POWER_SAVE
3889 spec->loopback.amplist = vt1708S_loopbacks;
3892 /* correct names for VT1708BCE */
3893 if (get_codec_type(codec) == VT1708BCE) {
3894 kfree(codec->chip_name);
3895 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3896 snprintf(codec->bus->card->mixername,
3897 sizeof(codec->bus->card->mixername),
3898 "%s %s", codec->vendor_name, codec->chip_name);
3899 spec->stream_name_analog = "VT1708BCE Analog";
3900 spec->stream_name_digital = "VT1708BCE Digital";
3902 /* correct names for VT1818S */
3903 if (codec->vendor_id == 0x11060440) {
3904 spec->stream_name_analog = "VT1818S Analog";
3905 spec->stream_name_digital = "VT1818S Digital";
3907 /* correct names for VT1705 */
3908 if (codec->vendor_id == 0x11064397) {
3909 kfree(codec->chip_name);
3910 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3911 snprintf(codec->bus->card->mixername,
3912 sizeof(codec->bus->card->mixername),
3913 "%s %s", codec->vendor_name, codec->chip_name);
3915 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3919 /* Patch for VT1702 */
3921 /* capture mixer elements */
3922 static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
3923 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3924 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3925 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3926 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3927 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3928 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3929 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3932 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3933 /* The multiple "Capture Source" controls confuse alsamixer
3934 * So call somewhat different..
3936 /* .name = "Capture Source", */
3937 .name = "Input Source",
3939 .info = via_mux_enum_info,
3940 .get = via_mux_enum_get,
3941 .put = via_mux_enum_put,
3946 static const struct hda_verb vt1702_volume_init_verbs[] = {
3948 * Unmute ADC0-1 and set the default input to mic-in
3950 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3951 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3952 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3955 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3958 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3959 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3960 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3961 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3962 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3963 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3965 /* Setup default input of PW4 to MW0 */
3966 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3967 /* PW6 PW7 Output enable */
3968 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3969 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3977 static const struct hda_verb vt1702_uniwill_init_verbs[] = {
3978 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3979 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3980 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3981 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3982 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3983 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3987 static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
3991 .nid = 0x10, /* NID to query formats and rates */
3993 .open = via_playback_pcm_open,
3994 .prepare = via_playback_multi_pcm_prepare,
3995 .cleanup = via_playback_multi_pcm_cleanup,
3996 .close = via_pcm_open_close
4000 static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
4004 .nid = 0x12, /* NID to query formats and rates */
4006 .open = via_pcm_open_close,
4007 .prepare = via_capture_pcm_prepare,
4008 .cleanup = via_capture_pcm_cleanup,
4009 .close = via_pcm_open_close
4013 static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
4017 /* NID is set in via_build_pcms */
4019 .open = via_dig_playback_pcm_open,
4020 .close = via_dig_playback_pcm_close,
4021 .prepare = via_dig_playback_pcm_prepare,
4022 .cleanup = via_dig_playback_pcm_cleanup
4026 /* fill in the dac_nids table from the parsed pin configuration */
4027 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4028 const struct auto_pin_cfg *cfg)
4030 spec->multiout.num_dacs = 1;
4031 spec->multiout.dac_nids = spec->private_dac_nids;
4033 if (cfg->line_out_pins[0]) {
4034 /* config dac list */
4035 spec->private_dac_nids[0] = 0x10;
4041 /* add playback controls from the parsed DAC table */
4042 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4043 const struct auto_pin_cfg *cfg)
4047 if (!cfg->line_out_pins[0])
4050 /* add control to mixer index 0 */
4051 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4052 "Master Front Playback Volume",
4053 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4056 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4057 "Master Front Playback Switch",
4058 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4063 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4064 "Front Playback Volume",
4065 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4068 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4069 "Front Playback Switch",
4070 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4077 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4080 struct hda_input_mux *imux;
4081 static const char * const texts[] = { "ON", "OFF", NULL};
4084 spec->multiout.hp_nid = 0x1D;
4085 spec->hp_independent_mode_index = 0;
4087 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4088 "Headphone Playback Volume",
4089 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4093 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4094 "Headphone Playback Switch",
4095 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4099 imux = &spec->private_imux[1];
4101 /* for hp mode select */
4102 for (i = 0; texts[i]; i++)
4103 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4105 spec->hp_mux = &spec->private_imux[1];
4109 /* create playback/capture controls for input pins */
4110 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4111 const struct auto_pin_cfg *cfg)
4113 static const hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4114 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4115 ARRAY_SIZE(pin_idxs));
4118 static int vt1702_parse_auto_config(struct hda_codec *codec)
4120 struct via_spec *spec = codec->spec;
4123 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4126 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4129 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4130 return 0; /* can't find valid BIOS pin config */
4132 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4135 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4138 /* limit AA path volume to 0 dB */
4139 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4140 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4141 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4142 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4143 (1 << AC_AMPCAP_MUTE_SHIFT));
4144 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4148 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4150 fill_dig_outs(codec);
4152 if (spec->kctls.list)
4153 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4155 spec->input_mux = &spec->private_imux[0];
4158 via_hp_build(codec);
4163 #ifdef CONFIG_SND_HDA_POWER_SAVE
4164 static const struct hda_amp_list vt1702_loopbacks[] = {
4165 { 0x1A, HDA_INPUT, 1 },
4166 { 0x1A, HDA_INPUT, 2 },
4167 { 0x1A, HDA_INPUT, 3 },
4168 { 0x1A, HDA_INPUT, 4 },
4173 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4175 int imux_is_smixer =
4176 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4179 /* PW 1/2/5 (14h/15h/18h) */
4181 set_pin_power_state(codec, 0x14, &parm);
4182 set_pin_power_state(codec, 0x15, &parm);
4183 set_pin_power_state(codec, 0x18, &parm);
4185 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4186 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4187 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4188 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4189 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4190 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4193 /* PW 3/4 (16h/17h) */
4195 set_pin_power_state(codec, 0x17, &parm);
4196 set_pin_power_state(codec, 0x16, &parm);
4197 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4198 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4199 imux_is_smixer ? AC_PWRST_D0 : parm);
4200 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4201 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4204 static int patch_vt1702(struct hda_codec *codec)
4206 struct via_spec *spec;
4209 /* create a codec specific record */
4210 spec = via_new_spec(codec);
4214 /* automatic parse from the BIOS config */
4215 err = vt1702_parse_auto_config(codec);
4220 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4221 "from BIOS. Using genenic mode...\n");
4224 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4225 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4227 spec->stream_name_analog = "VT1702 Analog";
4228 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4229 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4231 spec->stream_name_digital = "VT1702 Digital";
4232 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4234 if (!spec->adc_nids && spec->input_mux) {
4235 spec->adc_nids = vt1702_adc_nids;
4236 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4237 get_mux_nids(codec);
4238 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4242 codec->patch_ops = via_patch_ops;
4244 codec->patch_ops.init = via_auto_init;
4245 codec->patch_ops.unsol_event = via_unsol_event;
4246 #ifdef CONFIG_SND_HDA_POWER_SAVE
4247 spec->loopback.amplist = vt1702_loopbacks;
4250 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
4254 /* Patch for VT1718S */
4256 /* capture mixer elements */
4257 static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4258 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4259 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4260 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4261 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4262 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4263 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4266 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4267 /* The multiple "Capture Source" controls confuse alsamixer
4268 * So call somewhat different..
4270 .name = "Input Source",
4272 .info = via_mux_enum_info,
4273 .get = via_mux_enum_get,
4274 .put = via_mux_enum_put,
4279 static const struct hda_verb vt1718S_volume_init_verbs[] = {
4281 * Unmute ADC0-1 and set the default input to mic-in
4283 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4284 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4286 /* Enable MW0 adjust Gain 5 */
4288 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4291 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4292 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4293 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4294 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4295 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4296 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
4297 /* PW9 PW10 Output enable */
4298 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4299 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4300 /* PW11 Input enable */
4301 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4302 /* Enable Boost Volume backdoor */
4304 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4305 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4306 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4307 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4308 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4309 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4310 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4311 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4312 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4313 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4314 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4315 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4316 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4317 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4322 static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
4323 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4324 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4325 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4326 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4327 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4328 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4329 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4330 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4331 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4335 static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4339 .nid = 0x8, /* NID to query formats and rates */
4341 .open = via_playback_pcm_open,
4342 .prepare = via_playback_multi_pcm_prepare,
4343 .cleanup = via_playback_multi_pcm_cleanup,
4344 .close = via_pcm_open_close,
4348 static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4352 .nid = 0x10, /* NID to query formats and rates */
4354 .open = via_pcm_open_close,
4355 .prepare = via_capture_pcm_prepare,
4356 .cleanup = via_capture_pcm_cleanup,
4357 .close = via_pcm_open_close,
4361 static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4365 /* NID is set in via_build_pcms */
4367 .open = via_dig_playback_pcm_open,
4368 .close = via_dig_playback_pcm_close,
4369 .prepare = via_dig_playback_pcm_prepare,
4370 .cleanup = via_dig_playback_pcm_cleanup
4374 static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4380 /* fill in the dac_nids table from the parsed pin configuration */
4381 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4382 const struct auto_pin_cfg *cfg)
4387 spec->multiout.num_dacs = cfg->line_outs;
4389 spec->multiout.dac_nids = spec->private_dac_nids;
4391 for (i = 0; i < 4; i++) {
4392 nid = cfg->line_out_pins[i];
4394 /* config dac list */
4396 case AUTO_SEQ_FRONT:
4397 spec->private_dac_nids[i] = 0x8;
4399 case AUTO_SEQ_CENLFE:
4400 spec->private_dac_nids[i] = 0xa;
4402 case AUTO_SEQ_SURROUND:
4403 spec->private_dac_nids[i] = 0x9;
4406 spec->private_dac_nids[i] = 0xb;
4415 /* add playback controls from the parsed DAC table */
4416 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4417 const struct auto_pin_cfg *cfg)
4420 static const char * const chname[4] = {
4421 "Front", "Surround", "C/LFE", "Side"
4423 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4424 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4425 hda_nid_t nid, nid_vol, nid_mute = 0;
4428 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4429 nid = cfg->line_out_pins[i];
4433 nid_vol = nid_vols[i];
4434 nid_mute = nid_mutes[i];
4436 if (i == AUTO_SEQ_CENLFE) {
4438 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4439 "Center Playback Volume",
4440 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4444 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4445 "LFE Playback Volume",
4446 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4450 err = via_add_control(
4451 spec, VIA_CTL_WIDGET_MUTE,
4452 "Center Playback Switch",
4453 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4457 err = via_add_control(
4458 spec, VIA_CTL_WIDGET_MUTE,
4459 "LFE Playback Switch",
4460 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4464 } else if (i == AUTO_SEQ_FRONT) {
4465 /* add control to mixer index 0 */
4466 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4467 "Master Front Playback Volume",
4468 HDA_COMPOSE_AMP_VAL(0x21, 3, 5,
4472 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4473 "Master Front Playback Switch",
4474 HDA_COMPOSE_AMP_VAL(0x21, 3, 5,
4479 sprintf(name, "%s Playback Volume", chname[i]);
4480 err = via_add_control(
4481 spec, VIA_CTL_WIDGET_VOL, name,
4482 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4485 sprintf(name, "%s Playback Switch", chname[i]);
4486 err = via_add_control(
4487 spec, VIA_CTL_WIDGET_MUTE, name,
4488 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4493 sprintf(name, "%s Playback Volume", chname[i]);
4494 err = via_add_control(
4495 spec, VIA_CTL_WIDGET_VOL, name,
4496 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4499 sprintf(name, "%s Playback Switch", chname[i]);
4500 err = via_add_control(
4501 spec, VIA_CTL_WIDGET_MUTE, name,
4502 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4511 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4518 spec->multiout.hp_nid = 0xc; /* AOW4 */
4519 spec->hp_independent_mode_index = 1;
4521 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4522 "Headphone Playback Volume",
4523 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4527 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4528 "Headphone Playback Switch",
4529 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4533 create_hp_imux(spec);
4537 /* create playback/capture controls for input pins */
4538 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4539 const struct auto_pin_cfg *cfg)
4541 static const hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4542 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4543 ARRAY_SIZE(pin_idxs));
4546 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4548 struct via_spec *spec = codec->spec;
4551 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4555 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4558 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4559 return 0; /* can't find valid BIOS pin config */
4561 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4564 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4567 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4571 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4573 fill_dig_outs(codec);
4575 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4576 spec->dig_in_nid = 0x13;
4578 if (spec->kctls.list)
4579 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4581 spec->input_mux = &spec->private_imux[0];
4584 via_hp_build(codec);
4586 via_smart51_build(spec);
4591 #ifdef CONFIG_SND_HDA_POWER_SAVE
4592 static const struct hda_amp_list vt1718S_loopbacks[] = {
4593 { 0x21, HDA_INPUT, 1 },
4594 { 0x21, HDA_INPUT, 2 },
4595 { 0x21, HDA_INPUT, 3 },
4596 { 0x21, HDA_INPUT, 4 },
4601 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4603 struct via_spec *spec = codec->spec;
4606 /* MUX6 (1eh) = stereo mixer */
4608 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4610 /* PW 5/6/7 (29h/2ah/2bh) */
4612 set_pin_power_state(codec, 0x29, &parm);
4613 set_pin_power_state(codec, 0x2a, &parm);
4614 set_pin_power_state(codec, 0x2b, &parm);
4617 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4618 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4619 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4620 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4621 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4624 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4626 set_pin_power_state(codec, 0x27, &parm);
4627 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4628 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4630 /* PW2 (26h), AOW2 (ah) */
4632 set_pin_power_state(codec, 0x26, &parm);
4633 if (spec->smart51_enabled)
4634 set_pin_power_state(codec, 0x2b, &parm);
4635 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4637 /* PW0 (24h), AOW0 (8h) */
4639 set_pin_power_state(codec, 0x24, &parm);
4640 if (!spec->hp_independent_mode) /* check for redirected HP */
4641 set_pin_power_state(codec, 0x28, &parm);
4642 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4643 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4644 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4645 imux_is_smixer ? AC_PWRST_D0 : parm);
4647 /* PW1 (25h), AOW1 (9h) */
4649 set_pin_power_state(codec, 0x25, &parm);
4650 if (spec->smart51_enabled)
4651 set_pin_power_state(codec, 0x2a, &parm);
4652 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4654 if (spec->hp_independent_mode) {
4655 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4657 set_pin_power_state(codec, 0x28, &parm);
4658 snd_hda_codec_write(codec, 0x1b, 0,
4659 AC_VERB_SET_POWER_STATE, parm);
4660 snd_hda_codec_write(codec, 0x34, 0,
4661 AC_VERB_SET_POWER_STATE, parm);
4662 snd_hda_codec_write(codec, 0xc, 0,
4663 AC_VERB_SET_POWER_STATE, parm);
4667 static int patch_vt1718S(struct hda_codec *codec)
4669 struct via_spec *spec;
4672 /* create a codec specific record */
4673 spec = via_new_spec(codec);
4677 /* automatic parse from the BIOS config */
4678 err = vt1718S_parse_auto_config(codec);
4683 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4684 "from BIOS. Using genenic mode...\n");
4687 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4688 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4690 if (codec->vendor_id == 0x11060441)
4691 spec->stream_name_analog = "VT2020 Analog";
4692 else if (codec->vendor_id == 0x11064441)
4693 spec->stream_name_analog = "VT1828S Analog";
4695 spec->stream_name_analog = "VT1718S Analog";
4696 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4697 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4699 if (codec->vendor_id == 0x11060441)
4700 spec->stream_name_digital = "VT2020 Digital";
4701 else if (codec->vendor_id == 0x11064441)
4702 spec->stream_name_digital = "VT1828S Digital";
4704 spec->stream_name_digital = "VT1718S Digital";
4705 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4706 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4707 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4709 if (!spec->adc_nids && spec->input_mux) {
4710 spec->adc_nids = vt1718S_adc_nids;
4711 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4712 get_mux_nids(codec);
4713 override_mic_boost(codec, 0x2b, 0, 3, 40);
4714 override_mic_boost(codec, 0x29, 0, 3, 40);
4715 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4719 codec->patch_ops = via_patch_ops;
4721 codec->patch_ops.init = via_auto_init;
4722 codec->patch_ops.unsol_event = via_unsol_event;
4724 #ifdef CONFIG_SND_HDA_POWER_SAVE
4725 spec->loopback.amplist = vt1718S_loopbacks;
4728 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4733 /* Patch for VT1716S */
4735 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4736 struct snd_ctl_elem_info *uinfo)
4738 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4740 uinfo->value.integer.min = 0;
4741 uinfo->value.integer.max = 1;
4745 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4746 struct snd_ctl_elem_value *ucontrol)
4748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4751 index = snd_hda_codec_read(codec, 0x26, 0,
4752 AC_VERB_GET_CONNECT_SEL, 0);
4754 *ucontrol->value.integer.value = index;
4759 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4760 struct snd_ctl_elem_value *ucontrol)
4762 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4763 struct via_spec *spec = codec->spec;
4764 int index = *ucontrol->value.integer.value;
4766 snd_hda_codec_write(codec, 0x26, 0,
4767 AC_VERB_SET_CONNECT_SEL, index);
4768 spec->dmic_enabled = index;
4769 set_widgets_power_state(codec);
4773 /* capture mixer elements */
4774 static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4775 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4776 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4777 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4778 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4779 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4780 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4783 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4784 .name = "Input Source",
4786 .info = via_mux_enum_info,
4787 .get = via_mux_enum_get,
4788 .put = via_mux_enum_put,
4793 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4794 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4797 .name = "Digital Mic Capture Switch",
4798 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4800 .info = vt1716s_dmic_info,
4801 .get = vt1716s_dmic_get,
4802 .put = vt1716s_dmic_put,
4808 /* mono-out mixer elements */
4809 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4810 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4814 static const struct hda_verb vt1716S_volume_init_verbs[] = {
4816 * Unmute ADC0-1 and set the default input to mic-in
4818 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4819 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4822 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4825 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4826 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4827 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4828 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4829 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4830 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4832 /* MUX Indices: Stereo Mixer = 5 */
4833 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4835 /* Setup default input of PW4 to MW0 */
4836 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4838 /* Setup default input of SW1 as MW0 */
4839 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4841 /* Setup default input of SW4 as AOW0 */
4842 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4844 /* PW9 PW10 Output enable */
4845 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4846 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4848 /* Unmute SW1, PW12 */
4849 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4850 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4851 /* PW12 Output enable */
4852 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4853 /* Enable Boost Volume backdoor */
4855 /* don't bybass mixer */
4857 /* Enable mono output */
4863 static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
4864 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4865 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4866 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4867 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4868 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4869 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4870 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4871 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4872 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4876 static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4880 .nid = 0x10, /* NID to query formats and rates */
4882 .open = via_playback_pcm_open,
4883 .prepare = via_playback_multi_pcm_prepare,
4884 .cleanup = via_playback_multi_pcm_cleanup,
4885 .close = via_pcm_open_close,
4889 static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
4893 .nid = 0x13, /* NID to query formats and rates */
4895 .open = via_pcm_open_close,
4896 .prepare = via_capture_pcm_prepare,
4897 .cleanup = via_capture_pcm_cleanup,
4898 .close = via_pcm_open_close,
4902 static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
4906 /* NID is set in via_build_pcms */
4908 .open = via_dig_playback_pcm_open,
4909 .close = via_dig_playback_pcm_close,
4910 .prepare = via_dig_playback_pcm_prepare,
4911 .cleanup = via_dig_playback_pcm_cleanup
4915 /* fill in the dac_nids table from the parsed pin configuration */
4916 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4917 const struct auto_pin_cfg *cfg)
4921 spec->multiout.num_dacs = cfg->line_outs;
4923 spec->multiout.dac_nids = spec->private_dac_nids;
4925 for (i = 0; i < 3; i++) {
4926 nid = cfg->line_out_pins[i];
4928 /* config dac list */
4930 case AUTO_SEQ_FRONT:
4931 spec->private_dac_nids[i] = 0x10;
4933 case AUTO_SEQ_CENLFE:
4934 spec->private_dac_nids[i] = 0x25;
4936 case AUTO_SEQ_SURROUND:
4937 spec->private_dac_nids[i] = 0x11;
4946 /* add playback controls from the parsed DAC table */
4947 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4948 const struct auto_pin_cfg *cfg)
4951 static const char * const chname[3] = {
4952 "Front", "Surround", "C/LFE"
4954 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4955 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4956 hda_nid_t nid, nid_vol, nid_mute;
4959 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4960 nid = cfg->line_out_pins[i];
4965 nid_vol = nid_vols[i];
4966 nid_mute = nid_mutes[i];
4968 if (i == AUTO_SEQ_CENLFE) {
4969 err = via_add_control(
4970 spec, VIA_CTL_WIDGET_VOL,
4971 "Center Playback Volume",
4972 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4975 err = via_add_control(
4976 spec, VIA_CTL_WIDGET_VOL,
4977 "LFE Playback Volume",
4978 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4981 err = via_add_control(
4982 spec, VIA_CTL_WIDGET_MUTE,
4983 "Center Playback Switch",
4984 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4988 err = via_add_control(
4989 spec, VIA_CTL_WIDGET_MUTE,
4990 "LFE Playback Switch",
4991 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4995 } else if (i == AUTO_SEQ_FRONT) {
4997 err = via_add_control(
4998 spec, VIA_CTL_WIDGET_VOL,
4999 "Master Front Playback Volume",
5000 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5003 err = via_add_control(
5004 spec, VIA_CTL_WIDGET_MUTE,
5005 "Master Front Playback Switch",
5006 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5010 sprintf(name, "%s Playback Volume", chname[i]);
5011 err = via_add_control(
5012 spec, VIA_CTL_WIDGET_VOL, name,
5013 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5016 sprintf(name, "%s Playback Switch", chname[i]);
5017 err = via_add_control(
5018 spec, VIA_CTL_WIDGET_MUTE, name,
5019 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5024 sprintf(name, "%s Playback Volume", chname[i]);
5025 err = via_add_control(
5026 spec, VIA_CTL_WIDGET_VOL, name,
5027 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5030 sprintf(name, "%s Playback Switch", chname[i]);
5031 err = via_add_control(
5032 spec, VIA_CTL_WIDGET_MUTE, name,
5033 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5042 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5049 spec->multiout.hp_nid = 0x25; /* AOW3 */
5050 spec->hp_independent_mode_index = 1;
5052 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5053 "Headphone Playback Volume",
5054 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5058 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5059 "Headphone Playback Switch",
5060 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5064 create_hp_imux(spec);
5068 /* create playback/capture controls for input pins */
5069 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5070 const struct auto_pin_cfg *cfg)
5072 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5073 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5074 ARRAY_SIZE(pin_idxs));
5077 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5079 struct via_spec *spec = codec->spec;
5082 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5085 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5088 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5089 return 0; /* can't find valid BIOS pin config */
5091 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5094 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5097 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5101 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5103 fill_dig_outs(codec);
5105 if (spec->kctls.list)
5106 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5108 spec->input_mux = &spec->private_imux[0];
5111 via_hp_build(codec);
5113 via_smart51_build(spec);
5118 #ifdef CONFIG_SND_HDA_POWER_SAVE
5119 static const struct hda_amp_list vt1716S_loopbacks[] = {
5120 { 0x16, HDA_INPUT, 1 },
5121 { 0x16, HDA_INPUT, 2 },
5122 { 0x16, HDA_INPUT, 3 },
5123 { 0x16, HDA_INPUT, 4 },
5128 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5130 struct via_spec *spec = codec->spec;
5133 unsigned int mono_out, present;
5134 /* SW0 (17h) = stereo mixer */
5136 (snd_hda_codec_read(codec, 0x17, 0,
5137 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5139 /* PW 1/2/5 (1ah/1bh/1eh) */
5141 set_pin_power_state(codec, 0x1a, &parm);
5142 set_pin_power_state(codec, 0x1b, &parm);
5143 set_pin_power_state(codec, 0x1e, &parm);
5146 /* SW0 (17h), AIW0(13h) */
5147 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5148 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5151 set_pin_power_state(codec, 0x1e, &parm);
5153 if (spec->dmic_enabled)
5154 set_pin_power_state(codec, 0x22, &parm);
5156 snd_hda_codec_write(codec, 0x22, 0,
5157 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5159 /* SW2(26h), AIW1(14h) */
5160 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5161 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5164 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5166 set_pin_power_state(codec, 0x19, &parm);
5167 /* Smart 5.1 PW2(1bh) */
5168 if (spec->smart51_enabled)
5169 set_pin_power_state(codec, 0x1b, &parm);
5170 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5171 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5173 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5175 set_pin_power_state(codec, 0x23, &parm);
5176 /* Smart 5.1 PW1(1ah) */
5177 if (spec->smart51_enabled)
5178 set_pin_power_state(codec, 0x1a, &parm);
5179 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5181 /* Smart 5.1 PW5(1eh) */
5182 if (spec->smart51_enabled)
5183 set_pin_power_state(codec, 0x1e, &parm);
5184 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5187 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5188 present = snd_hda_jack_detect(codec, 0x1c);
5193 present = snd_hda_jack_detect(codec, 0x1d);
5194 if (!spec->hp_independent_mode && present)
5199 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5200 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5201 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5202 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5204 /* PW 3/4 (1ch/1dh) */
5206 set_pin_power_state(codec, 0x1c, &parm);
5207 set_pin_power_state(codec, 0x1d, &parm);
5208 /* HP Independent Mode, power on AOW3 */
5209 if (spec->hp_independent_mode)
5210 snd_hda_codec_write(codec, 0x25, 0,
5211 AC_VERB_SET_POWER_STATE, parm);
5213 /* force to D0 for internal Speaker */
5214 /* MW0 (16h), AOW0 (10h) */
5215 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5216 imux_is_smixer ? AC_PWRST_D0 : parm);
5217 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5218 mono_out ? AC_PWRST_D0 : parm);
5221 static int patch_vt1716S(struct hda_codec *codec)
5223 struct via_spec *spec;
5226 /* create a codec specific record */
5227 spec = via_new_spec(codec);
5231 /* automatic parse from the BIOS config */
5232 err = vt1716S_parse_auto_config(codec);
5237 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5238 "from BIOS. Using genenic mode...\n");
5241 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5242 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5244 spec->stream_name_analog = "VT1716S Analog";
5245 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5246 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5248 spec->stream_name_digital = "VT1716S Digital";
5249 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5251 if (!spec->adc_nids && spec->input_mux) {
5252 spec->adc_nids = vt1716S_adc_nids;
5253 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5254 get_mux_nids(codec);
5255 override_mic_boost(codec, 0x1a, 0, 3, 40);
5256 override_mic_boost(codec, 0x1e, 0, 3, 40);
5257 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5261 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5264 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5266 codec->patch_ops = via_patch_ops;
5268 codec->patch_ops.init = via_auto_init;
5269 codec->patch_ops.unsol_event = via_unsol_event;
5271 #ifdef CONFIG_SND_HDA_POWER_SAVE
5272 spec->loopback.amplist = vt1716S_loopbacks;
5275 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
5281 /* capture mixer elements */
5282 static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5283 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5284 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5285 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5286 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5287 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5288 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5291 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5292 /* The multiple "Capture Source" controls confuse alsamixer
5293 * So call somewhat different..
5295 /* .name = "Capture Source", */
5296 .name = "Input Source",
5298 .info = via_mux_enum_info,
5299 .get = via_mux_enum_get,
5300 .put = via_mux_enum_put,
5305 static const struct hda_verb vt2002P_volume_init_verbs[] = {
5306 /* Class-D speaker related verbs */
5311 * Unmute ADC0-1 and set the default input to mic-in
5313 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5314 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5317 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5320 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5321 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5322 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5323 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5324 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5325 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5327 /* MUX Indices: Mic = 0 */
5328 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5329 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5331 /* PW9 Output enable */
5332 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5334 /* Enable Boost Volume backdoor */
5337 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5338 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5339 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5340 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5341 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5342 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5343 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5344 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5345 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5347 /* set MUX0/1/4/8 = 0 (AOW0) */
5348 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5349 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5350 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5351 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5353 /* set PW0 index=0 (MW0) */
5354 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5356 /* Enable AOW0 to MW9 */
5360 static const struct hda_verb vt1802_volume_init_verbs[] = {
5362 * Unmute ADC0-1 and set the default input to mic-in
5364 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5365 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5368 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5371 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5372 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5373 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5374 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5375 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5376 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5378 /* MUX Indices: Mic = 0 */
5379 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5380 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5382 /* PW9 Output enable */
5383 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5385 /* Enable Boost Volume backdoor */
5388 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5389 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5390 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5391 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5392 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5393 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5394 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5395 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5396 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5398 /* set MUX0/1/4/8 = 0 (AOW0) */
5399 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5400 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5401 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5402 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5404 /* set PW0 index=0 (MW0) */
5405 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5407 /* Enable AOW0 to MW9 */
5413 static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
5414 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5415 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5416 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5417 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5418 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5419 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5420 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5423 static const struct hda_verb vt1802_uniwill_init_verbs[] = {
5424 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5425 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5426 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5427 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5428 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5429 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5430 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5434 static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5438 .nid = 0x8, /* NID to query formats and rates */
5440 .open = via_playback_pcm_open,
5441 .prepare = via_playback_multi_pcm_prepare,
5442 .cleanup = via_playback_multi_pcm_cleanup,
5443 .close = via_pcm_open_close,
5447 static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5451 .nid = 0x10, /* NID to query formats and rates */
5453 .open = via_pcm_open_close,
5454 .prepare = via_capture_pcm_prepare,
5455 .cleanup = via_capture_pcm_cleanup,
5456 .close = via_pcm_open_close,
5460 static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5464 /* NID is set in via_build_pcms */
5466 .open = via_dig_playback_pcm_open,
5467 .close = via_dig_playback_pcm_close,
5468 .prepare = via_dig_playback_pcm_prepare,
5469 .cleanup = via_dig_playback_pcm_cleanup
5473 /* fill in the dac_nids table from the parsed pin configuration */
5474 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5475 const struct auto_pin_cfg *cfg)
5477 spec->multiout.num_dacs = 1;
5478 spec->multiout.dac_nids = spec->private_dac_nids;
5479 if (cfg->line_out_pins[0])
5480 spec->private_dac_nids[0] = 0x8;
5484 /* add playback controls from the parsed DAC table */
5485 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5486 const struct auto_pin_cfg *cfg)
5491 if (!cfg->line_out_pins[0])
5494 if (spec->codec_type == VT1802)
5499 /* Line-Out: PortE */
5500 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5501 "Master Front Playback Volume",
5502 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5505 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5506 "Master Front Playback Switch",
5507 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
5514 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5521 spec->multiout.hp_nid = 0x9;
5522 spec->hp_independent_mode_index = 1;
5524 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5525 "Headphone Playback Volume",
5526 HDA_COMPOSE_AMP_VAL(
5527 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5531 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5532 "Headphone Playback Switch",
5533 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5537 create_hp_imux(spec);
5541 /* create playback/capture controls for input pins */
5542 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5543 const struct auto_pin_cfg *cfg)
5545 struct via_spec *spec = codec->spec;
5546 struct hda_input_mux *imux = &spec->private_imux[0];
5547 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5550 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5551 ARRAY_SIZE(pin_idxs));
5554 /* build volume/mute control of loopback */
5555 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5559 /* for digital mic select */
5560 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5565 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5567 struct via_spec *spec = codec->spec;
5571 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5575 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5579 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5580 return 0; /* can't find valid BIOS pin config */
5582 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5585 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5588 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5592 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5594 fill_dig_outs(codec);
5596 if (spec->kctls.list)
5597 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5599 spec->input_mux = &spec->private_imux[0];
5602 via_hp_build(codec);
5607 #ifdef CONFIG_SND_HDA_POWER_SAVE
5608 static const struct hda_amp_list vt2002P_loopbacks[] = {
5609 { 0x21, HDA_INPUT, 0 },
5610 { 0x21, HDA_INPUT, 1 },
5611 { 0x21, HDA_INPUT, 2 },
5616 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5618 struct via_spec *spec = codec->spec;
5621 unsigned int present;
5622 /* MUX9 (1eh) = stereo mixer */
5624 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5626 /* PW 5/6/7 (29h/2ah/2bh) */
5628 set_pin_power_state(codec, 0x29, &parm);
5629 set_pin_power_state(codec, 0x2a, &parm);
5630 set_pin_power_state(codec, 0x2b, &parm);
5632 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5633 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5634 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5635 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5636 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5640 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5642 if (spec->codec_type == VT1802) {
5643 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5645 set_pin_power_state(codec, 0x28, &parm);
5646 snd_hda_codec_write(codec, 0x18, 0,
5647 AC_VERB_SET_POWER_STATE, parm);
5648 snd_hda_codec_write(codec, 0x38, 0,
5649 AC_VERB_SET_POWER_STATE, parm);
5651 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5653 set_pin_power_state(codec, 0x26, &parm);
5654 snd_hda_codec_write(codec, 0x1c, 0,
5655 AC_VERB_SET_POWER_STATE, parm);
5656 snd_hda_codec_write(codec, 0x37, 0,
5657 AC_VERB_SET_POWER_STATE, parm);
5660 if (spec->codec_type == VT1802) {
5661 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5663 set_pin_power_state(codec, 0x25, &parm);
5664 snd_hda_codec_write(codec, 0x15, 0,
5665 AC_VERB_SET_POWER_STATE, parm);
5666 snd_hda_codec_write(codec, 0x35, 0,
5667 AC_VERB_SET_POWER_STATE, parm);
5669 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5671 set_pin_power_state(codec, 0x25, &parm);
5672 snd_hda_codec_write(codec, 0x19, 0,
5673 AC_VERB_SET_POWER_STATE, parm);
5674 snd_hda_codec_write(codec, 0x35, 0,
5675 AC_VERB_SET_POWER_STATE, parm);
5678 if (spec->hp_independent_mode)
5679 snd_hda_codec_write(codec, 0x9, 0,
5680 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5683 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5684 present = snd_hda_jack_detect(codec, 0x25);
5687 set_pin_power_state(codec, 0x24, &parm);
5688 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5689 if (spec->codec_type == VT1802)
5690 snd_hda_codec_write(codec, 0x14, 0,
5691 AC_VERB_SET_POWER_STATE, parm);
5693 snd_hda_codec_write(codec, 0x18, 0,
5694 AC_VERB_SET_POWER_STATE, parm);
5695 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5698 present = snd_hda_jack_detect(codec, 0x26);
5700 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5701 if (spec->codec_type == VT1802) {
5702 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5703 snd_hda_codec_write(codec, 0x33, 0,
5704 AC_VERB_SET_POWER_STATE, parm);
5705 snd_hda_codec_write(codec, 0x1c, 0,
5706 AC_VERB_SET_POWER_STATE, parm);
5707 snd_hda_codec_write(codec, 0x3c, 0,
5708 AC_VERB_SET_POWER_STATE, parm);
5710 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5711 snd_hda_codec_write(codec, 0x31, 0,
5712 AC_VERB_SET_POWER_STATE, parm);
5713 snd_hda_codec_write(codec, 0x17, 0,
5714 AC_VERB_SET_POWER_STATE, parm);
5715 snd_hda_codec_write(codec, 0x3b, 0,
5716 AC_VERB_SET_POWER_STATE, parm);
5719 if (imux_is_smixer || !is_aa_path_mute(codec))
5720 snd_hda_codec_write(codec, 0x21, 0,
5721 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5723 snd_hda_codec_write(codec, 0x21, 0,
5724 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5727 /* patch for vt2002P */
5728 static int patch_vt2002P(struct hda_codec *codec)
5730 struct via_spec *spec;
5733 /* create a codec specific record */
5734 spec = via_new_spec(codec);
5738 /* automatic parse from the BIOS config */
5739 err = vt2002P_parse_auto_config(codec);
5744 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5745 "from BIOS. Using genenic mode...\n");
5748 if (spec->codec_type == VT1802)
5749 spec->init_verbs[spec->num_iverbs++] =
5750 vt1802_volume_init_verbs;
5752 spec->init_verbs[spec->num_iverbs++] =
5753 vt2002P_volume_init_verbs;
5755 if (spec->codec_type == VT1802)
5756 spec->init_verbs[spec->num_iverbs++] =
5757 vt1802_uniwill_init_verbs;
5759 spec->init_verbs[spec->num_iverbs++] =
5760 vt2002P_uniwill_init_verbs;
5762 if (spec->codec_type == VT1802)
5763 spec->stream_name_analog = "VT1802 Analog";
5765 spec->stream_name_analog = "VT2002P Analog";
5766 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5767 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5769 if (spec->codec_type == VT1802)
5770 spec->stream_name_digital = "VT1802 Digital";
5772 spec->stream_name_digital = "VT2002P Digital";
5773 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5775 if (!spec->adc_nids && spec->input_mux) {
5776 spec->adc_nids = vt2002P_adc_nids;
5777 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5778 get_mux_nids(codec);
5779 override_mic_boost(codec, 0x2b, 0, 3, 40);
5780 override_mic_boost(codec, 0x29, 0, 3, 40);
5781 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5785 codec->patch_ops = via_patch_ops;
5787 codec->patch_ops.init = via_auto_init;
5788 codec->patch_ops.unsol_event = via_unsol_event;
5790 #ifdef CONFIG_SND_HDA_POWER_SAVE
5791 spec->loopback.amplist = vt2002P_loopbacks;
5794 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
5800 /* capture mixer elements */
5801 static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
5802 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5803 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5804 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5805 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5806 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5807 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5811 /* The multiple "Capture Source" controls confuse alsamixer
5812 * So call somewhat different..
5814 .name = "Input Source",
5816 .info = via_mux_enum_info,
5817 .get = via_mux_enum_get,
5818 .put = via_mux_enum_put,
5823 static const struct hda_verb vt1812_volume_init_verbs[] = {
5825 * Unmute ADC0-1 and set the default input to mic-in
5827 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5828 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5831 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5834 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5835 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5836 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5837 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5838 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5839 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5841 /* MUX Indices: Mic = 0 */
5842 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5843 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5845 /* PW9 Output enable */
5846 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5848 /* Enable Boost Volume backdoor */
5851 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5852 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5853 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5854 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5855 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5856 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5857 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5858 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5859 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5860 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5861 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5863 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5864 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5865 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5866 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5867 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5868 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5870 /* Enable AOW0 to MW9 */
5876 static const struct hda_verb vt1812_uniwill_init_verbs[] = {
5877 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5878 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5879 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5880 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5881 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5882 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5883 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5884 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5888 static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
5892 .nid = 0x8, /* NID to query formats and rates */
5894 .open = via_playback_pcm_open,
5895 .prepare = via_playback_multi_pcm_prepare,
5896 .cleanup = via_playback_multi_pcm_cleanup,
5897 .close = via_pcm_open_close,
5901 static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
5905 .nid = 0x10, /* NID to query formats and rates */
5907 .open = via_pcm_open_close,
5908 .prepare = via_capture_pcm_prepare,
5909 .cleanup = via_capture_pcm_cleanup,
5910 .close = via_pcm_open_close,
5914 static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
5918 /* NID is set in via_build_pcms */
5920 .open = via_dig_playback_pcm_open,
5921 .close = via_dig_playback_pcm_close,
5922 .prepare = via_dig_playback_pcm_prepare,
5923 .cleanup = via_dig_playback_pcm_cleanup
5926 /* fill in the dac_nids table from the parsed pin configuration */
5927 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5928 const struct auto_pin_cfg *cfg)
5930 spec->multiout.num_dacs = 1;
5931 spec->multiout.dac_nids = spec->private_dac_nids;
5932 if (cfg->line_out_pins[0])
5933 spec->private_dac_nids[0] = 0x8;
5938 /* add playback controls from the parsed DAC table */
5939 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5940 const struct auto_pin_cfg *cfg)
5944 if (!cfg->line_out_pins[0])
5947 /* Line-Out: PortE */
5948 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5949 "Front Playback Volume",
5950 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5953 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5954 "Front Playback Switch",
5955 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5962 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5969 spec->multiout.hp_nid = 0x9;
5970 spec->hp_independent_mode_index = 1;
5973 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5974 "Headphone Playback Volume",
5975 HDA_COMPOSE_AMP_VAL(
5976 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5980 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5981 "Headphone Playback Switch",
5982 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5986 create_hp_imux(spec);
5990 /* create playback/capture controls for input pins */
5991 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5992 const struct auto_pin_cfg *cfg)
5994 struct via_spec *spec = codec->spec;
5995 struct hda_input_mux *imux = &spec->private_imux[0];
5996 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5999 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
6000 ARRAY_SIZE(pin_idxs));
6004 /* build volume/mute control of loopback */
6005 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
6009 /* for digital mic select */
6010 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
6015 static int vt1812_parse_auto_config(struct hda_codec *codec)
6017 struct via_spec *spec = codec->spec;
6021 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6024 fill_dig_outs(codec);
6025 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6029 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6030 return 0; /* can't find valid BIOS pin config */
6032 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6035 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6038 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
6042 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6044 fill_dig_outs(codec);
6046 if (spec->kctls.list)
6047 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6049 spec->input_mux = &spec->private_imux[0];
6052 via_hp_build(codec);
6057 #ifdef CONFIG_SND_HDA_POWER_SAVE
6058 static const struct hda_amp_list vt1812_loopbacks[] = {
6059 { 0x21, HDA_INPUT, 0 },
6060 { 0x21, HDA_INPUT, 1 },
6061 { 0x21, HDA_INPUT, 2 },
6066 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
6068 struct via_spec *spec = codec->spec;
6069 int imux_is_smixer =
6070 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
6072 unsigned int present;
6073 /* MUX10 (1eh) = stereo mixer */
6075 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
6077 /* PW 5/6/7 (29h/2ah/2bh) */
6079 set_pin_power_state(codec, 0x29, &parm);
6080 set_pin_power_state(codec, 0x2a, &parm);
6081 set_pin_power_state(codec, 0x2b, &parm);
6083 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
6084 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
6085 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
6086 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
6087 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
6091 snd_hda_codec_write(codec, 0x8, 0,
6092 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6094 /* PW4 (28h), MW4 (18h), MUX4(38h) */
6096 set_pin_power_state(codec, 0x28, &parm);
6097 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
6098 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6100 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6102 set_pin_power_state(codec, 0x25, &parm);
6103 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6104 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6105 if (spec->hp_independent_mode)
6106 snd_hda_codec_write(codec, 0x9, 0,
6107 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6109 /* Internal Speaker */
6110 /* PW0 (24h), MW0(14h), MUX0(34h) */
6111 present = snd_hda_jack_detect(codec, 0x25);
6114 set_pin_power_state(codec, 0x24, &parm);
6116 snd_hda_codec_write(codec, 0x14, 0,
6117 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6118 snd_hda_codec_write(codec, 0x34, 0,
6119 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6121 snd_hda_codec_write(codec, 0x14, 0,
6122 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6123 snd_hda_codec_write(codec, 0x34, 0,
6124 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6129 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6130 present = snd_hda_jack_detect(codec, 0x28);
6133 set_pin_power_state(codec, 0x31, &parm);
6135 snd_hda_codec_write(codec, 0x1c, 0,
6136 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6137 snd_hda_codec_write(codec, 0x3c, 0,
6138 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6139 snd_hda_codec_write(codec, 0x3e, 0,
6140 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6142 snd_hda_codec_write(codec, 0x1c, 0,
6143 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6144 snd_hda_codec_write(codec, 0x3c, 0,
6145 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6146 snd_hda_codec_write(codec, 0x3e, 0,
6147 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6150 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6152 set_pin_power_state(codec, 0x33, &parm);
6153 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6154 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6158 /* patch for vt1812 */
6159 static int patch_vt1812(struct hda_codec *codec)
6161 struct via_spec *spec;
6164 /* create a codec specific record */
6165 spec = via_new_spec(codec);
6169 /* automatic parse from the BIOS config */
6170 err = vt1812_parse_auto_config(codec);
6175 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6176 "from BIOS. Using genenic mode...\n");
6180 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6181 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6183 spec->stream_name_analog = "VT1812 Analog";
6184 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6185 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6187 spec->stream_name_digital = "VT1812 Digital";
6188 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6191 if (!spec->adc_nids && spec->input_mux) {
6192 spec->adc_nids = vt1812_adc_nids;
6193 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6194 get_mux_nids(codec);
6195 override_mic_boost(codec, 0x2b, 0, 3, 40);
6196 override_mic_boost(codec, 0x29, 0, 3, 40);
6197 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6201 codec->patch_ops = via_patch_ops;
6203 codec->patch_ops.init = via_auto_init;
6204 codec->patch_ops.unsol_event = via_unsol_event;
6206 #ifdef CONFIG_SND_HDA_POWER_SAVE
6207 spec->loopback.amplist = vt1812_loopbacks;
6210 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
6217 static const struct hda_codec_preset snd_hda_preset_via[] = {
6218 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6219 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6220 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6221 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6222 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6223 .patch = patch_vt1709_10ch},
6224 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6225 .patch = patch_vt1709_10ch},
6226 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6227 .patch = patch_vt1709_10ch},
6228 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6229 .patch = patch_vt1709_10ch},
6230 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6231 .patch = patch_vt1709_6ch},
6232 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6233 .patch = patch_vt1709_6ch},
6234 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6235 .patch = patch_vt1709_6ch},
6236 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6237 .patch = patch_vt1709_6ch},
6238 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6239 .patch = patch_vt1708B_8ch},
6240 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6241 .patch = patch_vt1708B_8ch},
6242 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6243 .patch = patch_vt1708B_8ch},
6244 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6245 .patch = patch_vt1708B_8ch},
6246 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6247 .patch = patch_vt1708B_4ch},
6248 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6249 .patch = patch_vt1708B_4ch},
6250 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6251 .patch = patch_vt1708B_4ch},
6252 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6253 .patch = patch_vt1708B_4ch},
6254 { .id = 0x11060397, .name = "VT1708S",
6255 .patch = patch_vt1708S},
6256 { .id = 0x11061397, .name = "VT1708S",
6257 .patch = patch_vt1708S},
6258 { .id = 0x11062397, .name = "VT1708S",
6259 .patch = patch_vt1708S},
6260 { .id = 0x11063397, .name = "VT1708S",
6261 .patch = patch_vt1708S},
6262 { .id = 0x11064397, .name = "VT1705",
6263 .patch = patch_vt1708S},
6264 { .id = 0x11065397, .name = "VT1708S",
6265 .patch = patch_vt1708S},
6266 { .id = 0x11066397, .name = "VT1708S",
6267 .patch = patch_vt1708S},
6268 { .id = 0x11067397, .name = "VT1708S",
6269 .patch = patch_vt1708S},
6270 { .id = 0x11060398, .name = "VT1702",
6271 .patch = patch_vt1702},
6272 { .id = 0x11061398, .name = "VT1702",
6273 .patch = patch_vt1702},
6274 { .id = 0x11062398, .name = "VT1702",
6275 .patch = patch_vt1702},
6276 { .id = 0x11063398, .name = "VT1702",
6277 .patch = patch_vt1702},
6278 { .id = 0x11064398, .name = "VT1702",
6279 .patch = patch_vt1702},
6280 { .id = 0x11065398, .name = "VT1702",
6281 .patch = patch_vt1702},
6282 { .id = 0x11066398, .name = "VT1702",
6283 .patch = patch_vt1702},
6284 { .id = 0x11067398, .name = "VT1702",
6285 .patch = patch_vt1702},
6286 { .id = 0x11060428, .name = "VT1718S",
6287 .patch = patch_vt1718S},
6288 { .id = 0x11064428, .name = "VT1718S",
6289 .patch = patch_vt1718S},
6290 { .id = 0x11060441, .name = "VT2020",
6291 .patch = patch_vt1718S},
6292 { .id = 0x11064441, .name = "VT1828S",
6293 .patch = patch_vt1718S},
6294 { .id = 0x11060433, .name = "VT1716S",
6295 .patch = patch_vt1716S},
6296 { .id = 0x1106a721, .name = "VT1716S",
6297 .patch = patch_vt1716S},
6298 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6299 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6300 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6301 { .id = 0x11060440, .name = "VT1818S",
6302 .patch = patch_vt1708S},
6303 { .id = 0x11060446, .name = "VT1802",
6304 .patch = patch_vt2002P},
6305 { .id = 0x11068446, .name = "VT1802",
6306 .patch = patch_vt2002P},
6310 MODULE_ALIAS("snd-hda-codec-id:1106*");
6312 static struct hda_codec_preset_list via_list = {
6313 .preset = snd_hda_preset_via,
6314 .owner = THIS_MODULE,
6317 MODULE_LICENSE("GPL");
6318 MODULE_DESCRIPTION("VIA HD-audio codec");
6320 static int __init patch_via_init(void)
6322 return snd_hda_add_codec_preset(&via_list);
6325 static void __exit patch_via_exit(void)
6327 snd_hda_delete_codec_preset(&via_list);
6330 module_init(patch_via_init)
6331 module_exit(patch_via_exit)