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 struct snd_kcontrol_new *mixers[6];
113 unsigned int num_mixers;
115 struct hda_verb *init_verbs[5];
116 unsigned int num_iverbs;
118 char *stream_name_analog;
119 struct hda_pcm_stream *stream_analog_playback;
120 struct hda_pcm_stream *stream_analog_capture;
122 char *stream_name_digital;
123 struct hda_pcm_stream *stream_digital_playback;
124 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;
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_HP_EVENT 0x01
238 #define VIA_GPIO_EVENT 0x02
239 #define VIA_JACK_EVENT 0x04
240 #define VIA_MONO_EVENT 0x08
241 #define VIA_SPEAKER_EVENT 0x10
242 #define VIA_BIND_HP_EVENT 0x20
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 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 hda_nid_t vt1708_adc_nids[2] = {
425 static hda_nid_t vt1709_adc_nids[3] = {
430 static hda_nid_t vt1708B_adc_nids[2] = {
435 static hda_nid_t vt1708S_adc_nids[2] = {
440 static hda_nid_t vt1702_adc_nids[3] = {
445 static hda_nid_t vt1718S_adc_nids[2] = {
450 static hda_nid_t vt1716S_adc_nids[2] = {
455 static hda_nid_t vt2002P_adc_nids[2] = {
460 static 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 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 /* Get Independent Mode index of headphone pin widget */
749 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
751 if (spec->codec_type == VT1718S)
752 snd_hda_codec_write(codec, nid, 0,
753 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
755 snd_hda_codec_write(codec, nid, 0,
756 AC_VERB_SET_CONNECT_SEL, pinsel);
758 if (spec->codec_type == VT1812)
759 snd_hda_codec_write(codec, 0x35, 0,
760 AC_VERB_SET_CONNECT_SEL, pinsel);
761 if (spec->multiout.hp_nid && spec->multiout.hp_nid
762 != spec->multiout.dac_nids[HDA_FRONT])
763 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
766 update_side_mute_status(codec);
767 /* update HP volume/swtich active state */
768 if (spec->codec_type == VT1708S
769 || spec->codec_type == VT1702
770 || spec->codec_type == VT1718S
771 || spec->codec_type == VT1716S
772 || VT2002P_COMPATIBLE(spec)) {
773 activate_ctl(codec, "Headphone Playback Volume",
774 spec->hp_independent_mode);
775 activate_ctl(codec, "Headphone Playback Switch",
776 spec->hp_independent_mode);
778 /* update jack power state */
779 set_widgets_power_state(codec);
783 static struct snd_kcontrol_new via_hp_mixer[2] = {
785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
786 .name = "Independent HP",
787 .info = via_independent_hp_info,
788 .get = via_independent_hp_get,
789 .put = via_independent_hp_put,
792 .iface = NID_MAPPING,
793 .name = "Independent HP",
797 static int via_hp_build(struct hda_codec *codec)
799 struct via_spec *spec = codec->spec;
800 struct snd_kcontrol_new *knew;
803 hda_nid_t conn[HDA_MAX_CONNECTIONS];
805 switch (spec->codec_type) {
817 nid = spec->autocfg.hp_pins[0];
821 if (spec->codec_type != VT1708) {
822 nums = snd_hda_get_connections(codec, nid,
823 conn, HDA_MAX_CONNECTIONS);
828 knew = via_clone_control(spec, &via_hp_mixer[0]);
832 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
833 knew->private_value = nid;
835 knew = via_clone_control(spec, &via_hp_mixer[1]);
838 knew->subdevice = side_mute_channel(spec);
843 static void notify_aa_path_ctls(struct hda_codec *codec)
846 struct snd_ctl_elem_id id;
847 const char *labels[] = {"Mic", "Front Mic", "Line"};
849 memset(&id, 0, sizeof(id));
850 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
851 for (i = 0; i < ARRAY_SIZE(labels); i++) {
852 sprintf(id.name, "%s Playback Volume", labels[i]);
853 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
858 static void mute_aa_path(struct hda_codec *codec, int mute)
860 struct via_spec *spec = codec->spec;
865 /* get nid of MW0 and start & end index */
866 switch (spec->codec_type) {
894 /* check AA path's mute status */
895 for (i = start_idx; i <= end_idx; i++) {
896 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
897 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
901 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
903 const struct auto_pin_cfg *cfg = &spec->autocfg;
906 for (i = 0; i < cfg->num_inputs; i++) {
907 if (pin == cfg->inputs[i].pin)
908 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
913 static int via_smart51_info(struct snd_kcontrol *kcontrol,
914 struct snd_ctl_elem_info *uinfo)
916 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
918 uinfo->value.integer.min = 0;
919 uinfo->value.integer.max = 1;
923 static int via_smart51_get(struct snd_kcontrol *kcontrol,
924 struct snd_ctl_elem_value *ucontrol)
926 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
927 struct via_spec *spec = codec->spec;
928 const struct auto_pin_cfg *cfg = &spec->autocfg;
932 for (i = 0; i < cfg->num_inputs; i++) {
933 hda_nid_t nid = cfg->inputs[i].pin;
934 int ctl = snd_hda_codec_read(codec, nid, 0,
935 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
936 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
938 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
939 spec->hp_independent_mode && spec->codec_type != VT1718S)
940 continue; /* ignore FMic for independent HP */
941 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
944 *ucontrol->value.integer.value = on;
948 static int via_smart51_put(struct snd_kcontrol *kcontrol,
949 struct snd_ctl_elem_value *ucontrol)
951 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
952 struct via_spec *spec = codec->spec;
953 const struct auto_pin_cfg *cfg = &spec->autocfg;
954 int out_in = *ucontrol->value.integer.value
955 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
958 for (i = 0; i < cfg->num_inputs; i++) {
959 hda_nid_t nid = cfg->inputs[i].pin;
962 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
964 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
965 spec->hp_independent_mode && spec->codec_type != VT1718S)
966 continue; /* don't retask FMic for independent HP */
968 parm = snd_hda_codec_read(codec, nid, 0,
969 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
970 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
972 snd_hda_codec_write(codec, nid, 0,
973 AC_VERB_SET_PIN_WIDGET_CONTROL,
975 if (out_in == AC_PINCTL_OUT_EN) {
976 mute_aa_path(codec, 1);
977 notify_aa_path_ctls(codec);
979 if (spec->codec_type == VT1718S) {
980 snd_hda_codec_amp_stereo(
981 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
984 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
985 if (spec->codec_type == VT1708S
986 || spec->codec_type == VT1716S) {
987 /* input = index 1 (AOW3) */
990 AC_VERB_SET_CONNECT_SEL, 1);
991 snd_hda_codec_amp_stereo(
992 codec, nid, HDA_OUTPUT,
993 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
997 spec->smart51_enabled = *ucontrol->value.integer.value;
998 set_widgets_power_state(codec);
1002 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1004 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1005 .name = "Smart 5.1",
1007 .info = via_smart51_info,
1008 .get = via_smart51_get,
1009 .put = via_smart51_put,
1012 .iface = NID_MAPPING,
1013 .name = "Smart 5.1",
1017 static int via_smart51_build(struct via_spec *spec)
1019 struct snd_kcontrol_new *knew;
1020 const struct auto_pin_cfg *cfg = &spec->autocfg;
1024 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1028 for (i = 0; i < cfg->num_inputs; i++) {
1029 nid = cfg->inputs[i].pin;
1030 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1031 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1034 knew->subdevice = nid;
1042 /* capture mixer elements */
1043 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1044 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1045 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1046 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1047 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1050 /* The multiple "Capture Source" controls confuse alsamixer
1051 * So call somewhat different..
1053 /* .name = "Capture Source", */
1054 .name = "Input Source",
1056 .info = via_mux_enum_info,
1057 .get = via_mux_enum_get,
1058 .put = via_mux_enum_put,
1063 /* check AA path's mute statue */
1064 static int is_aa_path_mute(struct hda_codec *codec)
1067 hda_nid_t nid_mixer;
1071 struct via_spec *spec = codec->spec;
1072 /* get nid of MW0 and start & end index */
1073 switch (spec->codec_type) {
1102 /* check AA path's mute status */
1103 for (i = start_idx; i <= end_idx; i++) {
1104 unsigned int con_list = snd_hda_codec_read(
1105 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1106 int shift = 8 * (i % 4);
1107 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1108 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1109 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1110 /* check mute status while the pin is connected */
1111 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1113 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1115 if (!mute_l || !mute_r) {
1124 /* enter/exit analog low-current mode */
1125 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1127 struct via_spec *spec = codec->spec;
1128 static int saved_stream_idle = 1; /* saved stream idle status */
1129 int enable = is_aa_path_mute(codec);
1130 unsigned int verb = 0;
1131 unsigned int parm = 0;
1133 if (stream_idle == -1) /* stream status did not change */
1134 enable = enable && saved_stream_idle;
1136 enable = enable && stream_idle;
1137 saved_stream_idle = stream_idle;
1140 /* decide low current mode's verb & parameter */
1141 switch (spec->codec_type) {
1145 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1151 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1155 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1161 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1164 return; /* other codecs are not supported */
1167 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1171 * generic initialization of ADC, input mixers and output mixers
1173 static struct hda_verb vt1708_volume_init_verbs[] = {
1175 * Unmute ADC0-1 and set the default input to mic-in
1177 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1178 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1181 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1184 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1185 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1186 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1187 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1188 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1189 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1192 * Set up output mixers (0x19 - 0x1b)
1194 /* set vol=0 to output mixers */
1195 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1196 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1197 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1199 /* Setup default input MW0 to PW4 */
1200 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1201 /* PW9 Output enable */
1202 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1203 /* power down jack detect function */
1208 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1209 struct hda_codec *codec,
1210 struct snd_pcm_substream *substream)
1212 struct via_spec *spec = codec->spec;
1213 int idle = substream->pstr->substream_opened == 1
1214 && substream->ref_count == 0;
1215 analog_low_current_mode(codec, idle);
1216 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1220 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1221 unsigned int stream_tag,
1222 unsigned int format,
1223 struct snd_pcm_substream *substream)
1225 struct via_spec *spec = codec->spec;
1226 struct hda_multi_out *mout = &spec->multiout;
1227 hda_nid_t *nids = mout->dac_nids;
1228 int chs = substream->runtime->channels;
1231 mutex_lock(&codec->spdif_mutex);
1232 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1234 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1236 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1237 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1238 /* turn off SPDIF once; otherwise the IEC958 bits won't
1240 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1241 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1242 AC_VERB_SET_DIGI_CONVERT_1,
1244 ~AC_DIG1_ENABLE & 0xff);
1245 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1246 stream_tag, 0, format);
1247 /* turn on again (if needed) */
1248 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1249 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1250 AC_VERB_SET_DIGI_CONVERT_1,
1251 codec->spdif_ctls & 0xff);
1253 mout->dig_out_used = 0;
1254 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1258 mutex_unlock(&codec->spdif_mutex);
1261 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1264 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1265 && !spec->hp_independent_mode)
1266 /* headphone out will just decode front left/right (stereo) */
1267 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1270 /* extra outputs copied from front */
1271 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1272 if (mout->extra_out_nid[i])
1273 snd_hda_codec_setup_stream(codec,
1274 mout->extra_out_nid[i],
1275 stream_tag, 0, format);
1278 for (i = 1; i < mout->num_dacs; i++) {
1279 if (chs >= (i + 1) * 2) /* independent out */
1280 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1282 else /* copy front */
1283 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1288 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1289 struct hda_codec *codec,
1290 unsigned int stream_tag,
1291 unsigned int format,
1292 struct snd_pcm_substream *substream)
1294 struct via_spec *spec = codec->spec;
1295 struct hda_multi_out *mout = &spec->multiout;
1296 hda_nid_t *nids = mout->dac_nids;
1298 if (substream->number == 0)
1299 playback_multi_pcm_prep_0(codec, stream_tag, format,
1302 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1303 spec->hp_independent_mode)
1304 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1305 stream_tag, 0, format);
1307 vt1708_start_hp_work(spec);
1311 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1312 struct hda_codec *codec,
1313 struct snd_pcm_substream *substream)
1315 struct via_spec *spec = codec->spec;
1316 struct hda_multi_out *mout = &spec->multiout;
1317 hda_nid_t *nids = mout->dac_nids;
1320 if (substream->number == 0) {
1321 for (i = 0; i < mout->num_dacs; i++)
1322 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1324 if (mout->hp_nid && !spec->hp_independent_mode)
1325 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1328 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1329 if (mout->extra_out_nid[i])
1330 snd_hda_codec_setup_stream(codec,
1331 mout->extra_out_nid[i],
1333 mutex_lock(&codec->spdif_mutex);
1334 if (mout->dig_out_nid &&
1335 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1336 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1338 mout->dig_out_used = 0;
1340 mutex_unlock(&codec->spdif_mutex);
1342 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1343 spec->hp_independent_mode)
1344 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1347 vt1708_stop_hp_work(spec);
1354 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1355 struct hda_codec *codec,
1356 struct snd_pcm_substream *substream)
1358 struct via_spec *spec = codec->spec;
1359 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1362 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1363 struct hda_codec *codec,
1364 struct snd_pcm_substream *substream)
1366 struct via_spec *spec = codec->spec;
1367 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1370 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1371 struct hda_codec *codec,
1372 unsigned int stream_tag,
1373 unsigned int format,
1374 struct snd_pcm_substream *substream)
1376 struct via_spec *spec = codec->spec;
1377 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1378 stream_tag, format, substream);
1381 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1382 struct hda_codec *codec,
1383 struct snd_pcm_substream *substream)
1385 struct via_spec *spec = codec->spec;
1386 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1393 static int via_capture_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;
1401 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1402 stream_tag, 0, format);
1406 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1407 struct hda_codec *codec,
1408 struct snd_pcm_substream *substream)
1410 struct via_spec *spec = codec->spec;
1411 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1415 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1419 .nid = 0x10, /* NID to query formats and rates */
1421 .open = via_playback_pcm_open,
1422 .prepare = via_playback_multi_pcm_prepare,
1423 .cleanup = via_playback_multi_pcm_cleanup
1427 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1431 .nid = 0x10, /* NID to query formats and rates */
1432 /* We got noisy outputs on the right channel on VT1708 when
1433 * 24bit samples are used. Until any workaround is found,
1434 * disable the 24bit format, so far.
1436 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1438 .open = via_playback_pcm_open,
1439 .prepare = via_playback_multi_pcm_prepare,
1440 .cleanup = via_playback_multi_pcm_cleanup
1444 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1448 .nid = 0x15, /* NID to query formats and rates */
1450 .prepare = via_capture_pcm_prepare,
1451 .cleanup = via_capture_pcm_cleanup
1455 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1459 /* NID is set in via_build_pcms */
1461 .open = via_dig_playback_pcm_open,
1462 .close = via_dig_playback_pcm_close,
1463 .prepare = via_dig_playback_pcm_prepare,
1464 .cleanup = via_dig_playback_pcm_cleanup
1468 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1474 static int via_build_controls(struct hda_codec *codec)
1476 struct via_spec *spec = codec->spec;
1477 struct snd_kcontrol *kctl;
1478 struct snd_kcontrol_new *knew;
1481 for (i = 0; i < spec->num_mixers; i++) {
1482 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1487 if (spec->multiout.dig_out_nid) {
1488 err = snd_hda_create_spdif_out_ctls(codec,
1489 spec->multiout.dig_out_nid);
1492 err = snd_hda_create_spdif_share_sw(codec,
1496 spec->multiout.share_spdif = 1;
1498 if (spec->dig_in_nid) {
1499 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1504 /* assign Capture Source enums to NID */
1505 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1506 for (i = 0; kctl && i < kctl->count; i++) {
1507 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1512 /* other nid->control mapping */
1513 for (i = 0; i < spec->num_mixers; i++) {
1514 for (knew = spec->mixers[i]; knew->name; knew++) {
1515 if (knew->iface != NID_MAPPING)
1517 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1520 err = snd_hda_add_nid(codec, kctl, 0,
1525 /* init power states */
1526 set_widgets_power_state(codec);
1527 analog_low_current_mode(codec, 1);
1529 via_free_kctls(codec); /* no longer needed */
1533 static int via_build_pcms(struct hda_codec *codec)
1535 struct via_spec *spec = codec->spec;
1536 struct hda_pcm *info = spec->pcm_rec;
1538 codec->num_pcms = 1;
1539 codec->pcm_info = info;
1541 info->name = spec->stream_name_analog;
1542 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1543 *(spec->stream_analog_playback);
1544 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1545 spec->multiout.dac_nids[0];
1546 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1547 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1549 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1550 spec->multiout.max_channels;
1552 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1555 info->name = spec->stream_name_digital;
1556 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1557 if (spec->multiout.dig_out_nid) {
1558 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1559 *(spec->stream_digital_playback);
1560 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1561 spec->multiout.dig_out_nid;
1563 if (spec->dig_in_nid) {
1564 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1565 *(spec->stream_digital_capture);
1566 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1574 static void via_free(struct hda_codec *codec)
1576 struct via_spec *spec = codec->spec;
1581 via_free_kctls(codec);
1582 vt1708_stop_hp_work(spec);
1586 /* mute internal speaker if HP is plugged */
1587 static void via_hp_automute(struct hda_codec *codec)
1589 unsigned int present = 0;
1590 struct via_spec *spec = codec->spec;
1592 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1594 if (!spec->hp_independent_mode) {
1595 struct snd_ctl_elem_id id;
1597 snd_hda_codec_amp_stereo(
1598 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1599 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1601 memset(&id, 0, sizeof(id));
1602 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1603 strcpy(id.name, "Front Playback Switch");
1604 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1609 /* mute mono out if HP or Line out is plugged */
1610 static void via_mono_automute(struct hda_codec *codec)
1612 unsigned int hp_present, lineout_present;
1613 struct via_spec *spec = codec->spec;
1615 if (spec->codec_type != VT1716S)
1618 lineout_present = snd_hda_jack_detect(codec,
1619 spec->autocfg.line_out_pins[0]);
1621 /* Mute Mono Out if Line Out is plugged */
1622 if (lineout_present) {
1623 snd_hda_codec_amp_stereo(
1624 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1628 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1630 if (!spec->hp_independent_mode)
1631 snd_hda_codec_amp_stereo(
1632 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1633 hp_present ? HDA_AMP_MUTE : 0);
1636 static void via_gpio_control(struct hda_codec *codec)
1638 unsigned int gpio_data;
1639 unsigned int vol_counter;
1641 unsigned int master_vol;
1643 struct via_spec *spec = codec->spec;
1645 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1646 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1648 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1649 0xF84, 0) & 0x3F0000) >> 16;
1651 vol = vol_counter & 0x1F;
1652 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1653 AC_VERB_GET_AMP_GAIN_MUTE,
1656 if (gpio_data == 0x02) {
1657 /* unmute line out */
1658 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1659 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1661 if (vol_counter & 0x20) {
1662 /* decrease volume */
1663 if (vol > master_vol)
1665 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1669 /* increase volume */
1670 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1672 ((master_vol+vol) > 0x2A) ? 0x2A :
1675 } else if (!(gpio_data & 0x02)) {
1677 snd_hda_codec_amp_stereo(codec,
1678 spec->autocfg.line_out_pins[0],
1679 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1684 /* mute Internal-Speaker if HP is plugged */
1685 static void via_speaker_automute(struct hda_codec *codec)
1687 unsigned int hp_present;
1688 struct via_spec *spec = codec->spec;
1690 if (!VT2002P_COMPATIBLE(spec))
1693 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1695 if (!spec->hp_independent_mode) {
1696 struct snd_ctl_elem_id id;
1697 snd_hda_codec_amp_stereo(
1698 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1699 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1701 memset(&id, 0, sizeof(id));
1702 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1703 strcpy(id.name, "Speaker Playback Switch");
1704 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1709 /* mute line-out and internal speaker if HP is plugged */
1710 static void via_hp_bind_automute(struct hda_codec *codec)
1712 /* use long instead of int below just to avoid an internal compiler
1713 * error with gcc 4.0.x
1715 unsigned long hp_present, present = 0;
1716 struct via_spec *spec = codec->spec;
1719 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1722 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1724 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
1726 if (!spec->hp_independent_mode) {
1727 /* Mute Line-Outs */
1728 for (i = 0; i < spec->autocfg.line_outs; i++)
1729 snd_hda_codec_amp_stereo(
1730 codec, spec->autocfg.line_out_pins[i],
1732 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1734 present = hp_present;
1737 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1738 snd_hda_codec_amp_stereo(
1739 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1740 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1744 /* unsolicited event for jack sensing */
1745 static void via_unsol_event(struct hda_codec *codec,
1749 if (res & VIA_HP_EVENT)
1750 via_hp_automute(codec);
1751 if (res & VIA_GPIO_EVENT)
1752 via_gpio_control(codec);
1753 if (res & VIA_JACK_EVENT)
1754 set_widgets_power_state(codec);
1755 if (res & VIA_MONO_EVENT)
1756 via_mono_automute(codec);
1757 if (res & VIA_SPEAKER_EVENT)
1758 via_speaker_automute(codec);
1759 if (res & VIA_BIND_HP_EVENT)
1760 via_hp_bind_automute(codec);
1763 static int via_init(struct hda_codec *codec)
1765 struct via_spec *spec = codec->spec;
1767 for (i = 0; i < spec->num_iverbs; i++)
1768 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1770 /* Lydia Add for EAPD enable */
1771 if (!spec->dig_in_nid) { /* No Digital In connection */
1772 if (spec->dig_in_pin) {
1773 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1774 AC_VERB_SET_PIN_WIDGET_CONTROL,
1776 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1777 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1779 } else /* enable SPDIF-input pin */
1780 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1781 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1783 /* assign slave outs */
1784 if (spec->slave_dig_outs[0])
1785 codec->slave_dig_outs = spec->slave_dig_outs;
1790 #ifdef SND_HDA_NEEDS_RESUME
1791 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1793 struct via_spec *spec = codec->spec;
1794 vt1708_stop_hp_work(spec);
1799 #ifdef CONFIG_SND_HDA_POWER_SAVE
1800 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1802 struct via_spec *spec = codec->spec;
1803 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1809 static struct hda_codec_ops via_patch_ops = {
1810 .build_controls = via_build_controls,
1811 .build_pcms = via_build_pcms,
1814 #ifdef SND_HDA_NEEDS_RESUME
1815 .suspend = via_suspend,
1817 #ifdef CONFIG_SND_HDA_POWER_SAVE
1818 .check_power_status = via_check_power_status,
1822 /* fill in the dac_nids table from the parsed pin configuration */
1823 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1824 const struct auto_pin_cfg *cfg)
1829 spec->multiout.num_dacs = cfg->line_outs;
1831 spec->multiout.dac_nids = spec->private_dac_nids;
1833 for (i = 0; i < 4; i++) {
1834 nid = cfg->line_out_pins[i];
1836 /* config dac list */
1838 case AUTO_SEQ_FRONT:
1839 spec->multiout.dac_nids[i] = 0x10;
1841 case AUTO_SEQ_CENLFE:
1842 spec->multiout.dac_nids[i] = 0x12;
1844 case AUTO_SEQ_SURROUND:
1845 spec->multiout.dac_nids[i] = 0x11;
1848 spec->multiout.dac_nids[i] = 0x13;
1857 /* add playback controls from the parsed DAC table */
1858 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1859 const struct auto_pin_cfg *cfg)
1862 static const char * const chname[4] = {
1863 "Front", "Surround", "C/LFE", "Side"
1865 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1868 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1869 nid = cfg->line_out_pins[i];
1874 nid_vol = nid_vols[i];
1876 if (i == AUTO_SEQ_CENLFE) {
1878 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1879 "Center Playback Volume",
1880 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1884 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1885 "LFE Playback Volume",
1886 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1890 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1891 "Center Playback Switch",
1892 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1896 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1897 "LFE Playback Switch",
1898 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1902 } else if (i == AUTO_SEQ_FRONT) {
1903 /* add control to mixer index 0 */
1904 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1905 "Master Front Playback Volume",
1906 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1910 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1911 "Master Front Playback Switch",
1912 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1917 /* add control to PW3 */
1918 sprintf(name, "%s Playback Volume", chname[i]);
1919 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1920 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1924 sprintf(name, "%s Playback Switch", chname[i]);
1925 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1926 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1931 sprintf(name, "%s Playback Volume", chname[i]);
1932 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1933 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1937 sprintf(name, "%s Playback Switch", chname[i]);
1938 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1939 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1949 static void create_hp_imux(struct via_spec *spec)
1952 struct hda_input_mux *imux = &spec->private_imux[1];
1953 static const char * const texts[] = { "OFF", "ON", NULL};
1955 /* for hp mode select */
1956 for (i = 0; texts[i]; i++)
1957 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1959 spec->hp_mux = &spec->private_imux[1];
1962 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1969 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1970 spec->hp_independent_mode_index = 1;
1972 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1973 "Headphone Playback Volume",
1974 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1977 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1978 "Headphone Playback Switch",
1979 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1983 create_hp_imux(spec);
1988 /* create playback/capture controls for input pins */
1989 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
1990 const struct auto_pin_cfg *cfg,
1992 hda_nid_t pin_idxs[], int num_idxs)
1994 struct via_spec *spec = codec->spec;
1995 struct hda_input_mux *imux = &spec->private_imux[0];
1996 int i, err, idx, type, type_idx = 0;
1998 /* for internal loopback recording select */
1999 for (idx = 0; idx < num_idxs; idx++) {
2000 if (pin_idxs[idx] == 0xff) {
2001 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2006 for (i = 0; i < cfg->num_inputs; i++) {
2008 type = cfg->inputs[i].type;
2009 for (idx = 0; idx < num_idxs; idx++)
2010 if (pin_idxs[idx] == cfg->inputs[i].pin)
2012 if (idx >= num_idxs)
2014 if (i > 0 && type == cfg->inputs[i - 1].type)
2018 label = hda_get_autocfg_input_label(codec, cfg, i);
2019 if (spec->codec_type == VT1708S ||
2020 spec->codec_type == VT1702 ||
2021 spec->codec_type == VT1716S)
2022 err = via_new_analog_input(spec, label, type_idx,
2025 err = via_new_analog_input(spec, label, type_idx,
2029 snd_hda_add_imux_item(imux, label, idx, NULL);
2034 /* create playback/capture controls for input pins */
2035 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2036 const struct auto_pin_cfg *cfg)
2038 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2039 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2040 ARRAY_SIZE(pin_idxs));
2043 #ifdef CONFIG_SND_HDA_POWER_SAVE
2044 static struct hda_amp_list vt1708_loopbacks[] = {
2045 { 0x17, HDA_INPUT, 1 },
2046 { 0x17, HDA_INPUT, 2 },
2047 { 0x17, HDA_INPUT, 3 },
2048 { 0x17, HDA_INPUT, 4 },
2053 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2055 unsigned int def_conf;
2056 unsigned char seqassoc;
2058 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2059 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2060 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2061 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2062 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2063 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2064 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2070 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2071 struct snd_ctl_elem_value *ucontrol)
2073 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2074 struct via_spec *spec = codec->spec;
2076 if (spec->codec_type != VT1708)
2078 spec->vt1708_jack_detectect =
2079 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2080 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2084 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2085 struct snd_ctl_elem_value *ucontrol)
2087 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2088 struct via_spec *spec = codec->spec;
2091 if (spec->codec_type != VT1708)
2093 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2094 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2095 == !spec->vt1708_jack_detectect;
2096 if (spec->vt1708_jack_detectect) {
2097 mute_aa_path(codec, 1);
2098 notify_aa_path_ctls(codec);
2103 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2105 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2106 .name = "Jack Detect",
2108 .info = snd_ctl_boolean_mono_info,
2109 .get = vt1708_jack_detectect_get,
2110 .put = vt1708_jack_detectect_put,
2115 static int vt1708_parse_auto_config(struct hda_codec *codec)
2117 struct via_spec *spec = codec->spec;
2120 /* Add HP and CD pin config connect bit re-config action */
2121 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2122 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2124 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2127 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2130 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2131 return 0; /* can't find valid BIOS pin config */
2133 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2136 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2139 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2142 /* add jack detect on/off control */
2143 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2147 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2149 if (spec->autocfg.dig_outs)
2150 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2151 spec->dig_in_pin = VT1708_DIGIN_PIN;
2152 if (spec->autocfg.dig_in_pin)
2153 spec->dig_in_nid = VT1708_DIGIN_NID;
2155 if (spec->kctls.list)
2156 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2158 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2160 spec->input_mux = &spec->private_imux[0];
2163 via_hp_build(codec);
2165 via_smart51_build(spec);
2169 /* init callback for auto-configuration model -- overriding the default init */
2170 static int via_auto_init(struct hda_codec *codec)
2172 struct via_spec *spec = codec->spec;
2175 via_auto_init_multi_out(codec);
2176 via_auto_init_hp_out(codec);
2177 via_auto_init_analog_input(codec);
2179 if (VT2002P_COMPATIBLE(spec)) {
2180 via_hp_bind_automute(codec);
2182 via_hp_automute(codec);
2183 via_speaker_automute(codec);
2189 static void vt1708_update_hp_jack_state(struct work_struct *work)
2191 struct via_spec *spec = container_of(work, struct via_spec,
2192 vt1708_hp_work.work);
2193 if (spec->codec_type != VT1708)
2195 /* if jack state toggled */
2196 if (spec->vt1708_hp_present
2197 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2198 spec->vt1708_hp_present ^= 1;
2199 via_hp_automute(spec->codec);
2201 vt1708_start_hp_work(spec);
2204 static int get_mux_nids(struct hda_codec *codec)
2206 struct via_spec *spec = codec->spec;
2207 hda_nid_t nid, conn[8];
2211 for (i = 0; i < spec->num_adc_nids; i++) {
2212 nid = spec->adc_nids[i];
2214 type = get_wcaps_type(get_wcaps(codec, nid));
2215 if (type == AC_WID_PIN)
2217 n = snd_hda_get_connections(codec, nid, conn,
2222 spec->mux_nids[i] = nid;
2231 static int patch_vt1708(struct hda_codec *codec)
2233 struct via_spec *spec;
2236 /* create a codec specific record */
2237 spec = via_new_spec(codec);
2241 /* automatic parse from the BIOS config */
2242 err = vt1708_parse_auto_config(codec);
2247 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2248 "from BIOS. Using genenic mode...\n");
2252 spec->stream_name_analog = "VT1708 Analog";
2253 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2254 /* disable 32bit format on VT1708 */
2255 if (codec->vendor_id == 0x11061708)
2256 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2257 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2259 spec->stream_name_digital = "VT1708 Digital";
2260 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2261 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2264 if (!spec->adc_nids && spec->input_mux) {
2265 spec->adc_nids = vt1708_adc_nids;
2266 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2267 get_mux_nids(codec);
2268 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2272 codec->patch_ops = via_patch_ops;
2274 codec->patch_ops.init = via_auto_init;
2275 #ifdef CONFIG_SND_HDA_POWER_SAVE
2276 spec->loopback.amplist = vt1708_loopbacks;
2278 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2282 /* capture mixer elements */
2283 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2284 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2285 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2286 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2287 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2288 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2289 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2291 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2292 /* The multiple "Capture Source" controls confuse alsamixer
2293 * So call somewhat different..
2295 /* .name = "Capture Source", */
2296 .name = "Input Source",
2298 .info = via_mux_enum_info,
2299 .get = via_mux_enum_get,
2300 .put = via_mux_enum_put,
2305 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2306 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2307 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2312 * generic initialization of ADC, input mixers and output mixers
2314 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2316 * Unmute ADC0-2 and set the default input to mic-in
2318 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2319 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2320 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2323 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2326 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2327 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2328 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2329 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2330 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2331 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2334 * Set up output selector (0x1a, 0x1b, 0x29)
2336 /* set vol=0 to output mixers */
2337 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2338 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2339 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2342 * Unmute PW3 and PW4
2344 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2345 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2347 /* Set input of PW4 as MW0 */
2348 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2349 /* PW9 Output enable */
2350 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2354 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2358 .nid = 0x10, /* NID to query formats and rates */
2360 .open = via_playback_pcm_open,
2361 .prepare = via_playback_multi_pcm_prepare,
2362 .cleanup = via_playback_multi_pcm_cleanup,
2366 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2370 .nid = 0x10, /* NID to query formats and rates */
2372 .open = via_playback_pcm_open,
2373 .prepare = via_playback_multi_pcm_prepare,
2374 .cleanup = via_playback_multi_pcm_cleanup,
2378 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2382 .nid = 0x14, /* NID to query formats and rates */
2384 .prepare = via_capture_pcm_prepare,
2385 .cleanup = via_capture_pcm_cleanup
2389 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2393 /* NID is set in via_build_pcms */
2395 .open = via_dig_playback_pcm_open,
2396 .close = via_dig_playback_pcm_close
2400 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2406 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2407 const struct auto_pin_cfg *cfg)
2412 if (cfg->line_outs == 4) /* 10 channels */
2413 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2414 else if (cfg->line_outs == 3) /* 6 channels */
2415 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2417 spec->multiout.dac_nids = spec->private_dac_nids;
2419 if (cfg->line_outs == 4) { /* 10 channels */
2420 for (i = 0; i < cfg->line_outs; i++) {
2421 nid = cfg->line_out_pins[i];
2423 /* config dac list */
2425 case AUTO_SEQ_FRONT:
2427 spec->multiout.dac_nids[i] = 0x10;
2429 case AUTO_SEQ_CENLFE:
2431 spec->multiout.dac_nids[i] = 0x12;
2433 case AUTO_SEQ_SURROUND:
2435 spec->multiout.dac_nids[i] = 0x11;
2439 spec->multiout.dac_nids[i] = 0x27;
2446 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2448 } else if (cfg->line_outs == 3) { /* 6 channels */
2449 for (i = 0; i < cfg->line_outs; i++) {
2450 nid = cfg->line_out_pins[i];
2452 /* config dac list */
2454 case AUTO_SEQ_FRONT:
2456 spec->multiout.dac_nids[i] = 0x10;
2458 case AUTO_SEQ_CENLFE:
2460 spec->multiout.dac_nids[i] = 0x12;
2462 case AUTO_SEQ_SURROUND:
2464 spec->multiout.dac_nids[i] = 0x11;
2476 /* add playback controls from the parsed DAC table */
2477 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2478 const struct auto_pin_cfg *cfg)
2481 static const char * const chname[4] = {
2482 "Front", "Surround", "C/LFE", "Side"
2484 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2487 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2488 nid = cfg->line_out_pins[i];
2493 nid_vol = nid_vols[i];
2495 if (i == AUTO_SEQ_CENLFE) {
2497 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2498 "Center Playback Volume",
2499 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2503 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2504 "LFE Playback Volume",
2505 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2509 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2510 "Center Playback Switch",
2511 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2515 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2516 "LFE Playback Switch",
2517 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2521 } else if (i == AUTO_SEQ_FRONT) {
2522 /* ADD control to mixer index 0 */
2523 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2524 "Master Front Playback Volume",
2525 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2529 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2530 "Master Front Playback Switch",
2531 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2536 /* add control to PW3 */
2537 sprintf(name, "%s Playback Volume", chname[i]);
2538 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2539 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2543 sprintf(name, "%s Playback Switch", chname[i]);
2544 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2545 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2549 } else if (i == AUTO_SEQ_SURROUND) {
2550 sprintf(name, "%s Playback Volume", chname[i]);
2551 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2552 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2556 sprintf(name, "%s Playback Switch", chname[i]);
2557 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2558 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2562 } else if (i == AUTO_SEQ_SIDE) {
2563 sprintf(name, "%s Playback Volume", chname[i]);
2564 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2565 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2569 sprintf(name, "%s Playback Switch", chname[i]);
2570 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2571 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2581 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2588 if (spec->multiout.num_dacs == 5) /* 10 channels */
2589 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2590 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2591 spec->multiout.hp_nid = 0;
2592 spec->hp_independent_mode_index = 1;
2594 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2595 "Headphone Playback Volume",
2596 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2599 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2600 "Headphone Playback Switch",
2601 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2608 /* create playback/capture controls for input pins */
2609 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
2610 const struct auto_pin_cfg *cfg)
2612 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
2613 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
2614 ARRAY_SIZE(pin_idxs));
2617 static int vt1709_parse_auto_config(struct hda_codec *codec)
2619 struct via_spec *spec = codec->spec;
2622 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2625 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2628 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2629 return 0; /* can't find valid BIOS pin config */
2631 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2634 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2637 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
2641 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2643 if (spec->autocfg.dig_outs)
2644 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2645 spec->dig_in_pin = VT1709_DIGIN_PIN;
2646 if (spec->autocfg.dig_in_pin)
2647 spec->dig_in_nid = VT1709_DIGIN_NID;
2649 if (spec->kctls.list)
2650 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2652 spec->input_mux = &spec->private_imux[0];
2655 via_hp_build(codec);
2657 via_smart51_build(spec);
2661 #ifdef CONFIG_SND_HDA_POWER_SAVE
2662 static struct hda_amp_list vt1709_loopbacks[] = {
2663 { 0x18, HDA_INPUT, 1 },
2664 { 0x18, HDA_INPUT, 2 },
2665 { 0x18, HDA_INPUT, 3 },
2666 { 0x18, HDA_INPUT, 4 },
2671 static int patch_vt1709_10ch(struct hda_codec *codec)
2673 struct via_spec *spec;
2676 /* create a codec specific record */
2677 spec = via_new_spec(codec);
2681 err = vt1709_parse_auto_config(codec);
2686 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2687 "Using genenic mode...\n");
2690 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2691 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2693 spec->stream_name_analog = "VT1709 Analog";
2694 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2695 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2697 spec->stream_name_digital = "VT1709 Digital";
2698 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2699 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2702 if (!spec->adc_nids && spec->input_mux) {
2703 spec->adc_nids = vt1709_adc_nids;
2704 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2705 get_mux_nids(codec);
2706 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2710 codec->patch_ops = via_patch_ops;
2712 codec->patch_ops.init = via_auto_init;
2713 codec->patch_ops.unsol_event = via_unsol_event;
2714 #ifdef CONFIG_SND_HDA_POWER_SAVE
2715 spec->loopback.amplist = vt1709_loopbacks;
2721 * generic initialization of ADC, input mixers and output mixers
2723 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2725 * Unmute ADC0-2 and set the default input to mic-in
2727 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2728 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2729 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2732 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2735 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2736 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2737 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2738 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2739 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2740 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2743 * Set up output selector (0x1a, 0x1b, 0x29)
2745 /* set vol=0 to output mixers */
2746 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2747 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2748 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2751 * Unmute PW3 and PW4
2753 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2754 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2756 /* Set input of PW4 as MW0 */
2757 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2758 /* PW9 Output enable */
2759 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2763 static int patch_vt1709_6ch(struct hda_codec *codec)
2765 struct via_spec *spec;
2768 /* create a codec specific record */
2769 spec = via_new_spec(codec);
2773 err = vt1709_parse_auto_config(codec);
2778 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2779 "Using genenic mode...\n");
2782 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2783 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2785 spec->stream_name_analog = "VT1709 Analog";
2786 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2787 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2789 spec->stream_name_digital = "VT1709 Digital";
2790 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2791 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2794 if (!spec->adc_nids && spec->input_mux) {
2795 spec->adc_nids = vt1709_adc_nids;
2796 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2797 get_mux_nids(codec);
2798 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2802 codec->patch_ops = via_patch_ops;
2804 codec->patch_ops.init = via_auto_init;
2805 codec->patch_ops.unsol_event = via_unsol_event;
2806 #ifdef CONFIG_SND_HDA_POWER_SAVE
2807 spec->loopback.amplist = vt1709_loopbacks;
2812 /* capture mixer elements */
2813 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2814 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2815 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2816 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2817 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2819 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2820 /* The multiple "Capture Source" controls confuse alsamixer
2821 * So call somewhat different..
2823 /* .name = "Capture Source", */
2824 .name = "Input Source",
2826 .info = via_mux_enum_info,
2827 .get = via_mux_enum_get,
2828 .put = via_mux_enum_put,
2833 * generic initialization of ADC, input mixers and output mixers
2835 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2837 * Unmute ADC0-1 and set the default input to mic-in
2839 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2840 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2843 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2846 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2847 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2848 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2849 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2850 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2851 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2854 * Set up output mixers
2856 /* set vol=0 to output mixers */
2857 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2858 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2859 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2861 /* Setup default input to PW4 */
2862 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2863 /* PW9 Output enable */
2864 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2865 /* PW10 Input enable */
2866 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2870 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2872 * Unmute ADC0-1 and set the default input to mic-in
2874 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2875 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2878 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2881 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2882 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2883 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2884 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2885 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2886 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2889 * Set up output mixers
2891 /* set vol=0 to output mixers */
2892 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2893 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2894 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2896 /* Setup default input of PW4 to MW0 */
2897 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2898 /* PW9 Output enable */
2899 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2900 /* PW10 Input enable */
2901 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2905 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2906 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2907 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2908 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2909 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2910 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2911 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2912 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2913 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2914 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2918 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2919 struct hda_codec *codec,
2920 struct snd_pcm_substream *substream)
2922 int idle = substream->pstr->substream_opened == 1
2923 && substream->ref_count == 0;
2925 analog_low_current_mode(codec, idle);
2929 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2933 .nid = 0x10, /* NID to query formats and rates */
2935 .open = via_playback_pcm_open,
2936 .prepare = via_playback_multi_pcm_prepare,
2937 .cleanup = via_playback_multi_pcm_cleanup,
2938 .close = via_pcm_open_close
2942 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2946 .nid = 0x10, /* NID to query formats and rates */
2948 .open = via_playback_pcm_open,
2949 .prepare = via_playback_multi_pcm_prepare,
2950 .cleanup = via_playback_multi_pcm_cleanup
2954 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2958 .nid = 0x13, /* NID to query formats and rates */
2960 .open = via_pcm_open_close,
2961 .prepare = via_capture_pcm_prepare,
2962 .cleanup = via_capture_pcm_cleanup,
2963 .close = via_pcm_open_close
2967 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2971 /* NID is set in via_build_pcms */
2973 .open = via_dig_playback_pcm_open,
2974 .close = via_dig_playback_pcm_close,
2975 .prepare = via_dig_playback_pcm_prepare,
2976 .cleanup = via_dig_playback_pcm_cleanup
2980 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2986 /* fill in the dac_nids table from the parsed pin configuration */
2987 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2988 const struct auto_pin_cfg *cfg)
2993 spec->multiout.num_dacs = cfg->line_outs;
2995 spec->multiout.dac_nids = spec->private_dac_nids;
2997 for (i = 0; i < 4; i++) {
2998 nid = cfg->line_out_pins[i];
3000 /* config dac list */
3002 case AUTO_SEQ_FRONT:
3003 spec->multiout.dac_nids[i] = 0x10;
3005 case AUTO_SEQ_CENLFE:
3006 spec->multiout.dac_nids[i] = 0x24;
3008 case AUTO_SEQ_SURROUND:
3009 spec->multiout.dac_nids[i] = 0x11;
3012 spec->multiout.dac_nids[i] = 0x25;
3021 /* add playback controls from the parsed DAC table */
3022 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3023 const struct auto_pin_cfg *cfg)
3026 static const char * const chname[4] = {
3027 "Front", "Surround", "C/LFE", "Side"
3029 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3030 hda_nid_t nid, nid_vol = 0;
3033 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3034 nid = cfg->line_out_pins[i];
3039 nid_vol = nid_vols[i];
3041 if (i == AUTO_SEQ_CENLFE) {
3043 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3044 "Center Playback Volume",
3045 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3049 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3050 "LFE Playback Volume",
3051 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3055 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3056 "Center Playback Switch",
3057 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3061 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3062 "LFE Playback Switch",
3063 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3067 } else if (i == AUTO_SEQ_FRONT) {
3068 /* add control to mixer index 0 */
3069 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3070 "Master Front Playback Volume",
3071 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3075 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3076 "Master Front Playback Switch",
3077 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3082 /* add control to PW3 */
3083 sprintf(name, "%s Playback Volume", chname[i]);
3084 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3085 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3089 sprintf(name, "%s Playback Switch", chname[i]);
3090 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3091 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3096 sprintf(name, "%s Playback Volume", chname[i]);
3097 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3098 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3102 sprintf(name, "%s Playback Switch", chname[i]);
3103 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3104 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3114 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3121 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3122 spec->hp_independent_mode_index = 1;
3124 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3125 "Headphone Playback Volume",
3126 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3129 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3130 "Headphone Playback Switch",
3131 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3135 create_hp_imux(spec);
3140 /* create playback/capture controls for input pins */
3141 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3142 const struct auto_pin_cfg *cfg)
3144 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3145 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3146 ARRAY_SIZE(pin_idxs));
3149 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3151 struct via_spec *spec = codec->spec;
3154 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3157 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3160 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3161 return 0; /* can't find valid BIOS pin config */
3163 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3166 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3169 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3173 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3175 if (spec->autocfg.dig_outs)
3176 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3177 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3178 if (spec->autocfg.dig_in_pin)
3179 spec->dig_in_nid = VT1708B_DIGIN_NID;
3181 if (spec->kctls.list)
3182 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3184 spec->input_mux = &spec->private_imux[0];
3187 via_hp_build(codec);
3189 via_smart51_build(spec);
3193 #ifdef CONFIG_SND_HDA_POWER_SAVE
3194 static struct hda_amp_list vt1708B_loopbacks[] = {
3195 { 0x16, HDA_INPUT, 1 },
3196 { 0x16, HDA_INPUT, 2 },
3197 { 0x16, HDA_INPUT, 3 },
3198 { 0x16, HDA_INPUT, 4 },
3203 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3205 struct via_spec *spec = codec->spec;
3209 if ((spec->codec_type != VT1708B_4CH) &&
3210 (codec->vendor_id != 0x11064397))
3213 /* SW0 (17h) = stereo mixer */
3215 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3216 == ((spec->codec_type == VT1708S) ? 5 : 0));
3218 /* PW 1/2/5 (1ah/1bh/1eh) */
3220 set_pin_power_state(codec, 0x1a, &parm);
3221 set_pin_power_state(codec, 0x1b, &parm);
3222 set_pin_power_state(codec, 0x1e, &parm);
3225 /* SW0 (17h), AIW 0/1 (13h/14h) */
3226 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3227 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3228 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3231 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3233 set_pin_power_state(codec, 0x19, &parm);
3234 if (spec->smart51_enabled)
3235 set_pin_power_state(codec, 0x1b, &parm);
3236 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3237 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3239 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3242 set_pin_power_state(codec, 0x22, &parm);
3243 if (spec->smart51_enabled)
3244 set_pin_power_state(codec, 0x1a, &parm);
3245 snd_hda_codec_write(codec, 0x26, 0,
3246 AC_VERB_SET_POWER_STATE, parm);
3247 snd_hda_codec_write(codec, 0x24, 0,
3248 AC_VERB_SET_POWER_STATE, parm);
3249 } else if (codec->vendor_id == 0x11064397) {
3250 /* PW7(23h), SW2(27h), AOW2(25h) */
3252 set_pin_power_state(codec, 0x23, &parm);
3253 if (spec->smart51_enabled)
3254 set_pin_power_state(codec, 0x1a, &parm);
3255 snd_hda_codec_write(codec, 0x27, 0,
3256 AC_VERB_SET_POWER_STATE, parm);
3257 snd_hda_codec_write(codec, 0x25, 0,
3258 AC_VERB_SET_POWER_STATE, parm);
3261 /* PW 3/4/7 (1ch/1dh/23h) */
3263 /* force to D0 for internal Speaker */
3264 set_pin_power_state(codec, 0x1c, &parm);
3265 set_pin_power_state(codec, 0x1d, &parm);
3267 set_pin_power_state(codec, 0x23, &parm);
3269 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3270 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3271 imux_is_smixer ? AC_PWRST_D0 : parm);
3272 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3274 snd_hda_codec_write(codec, 0x25, 0,
3275 AC_VERB_SET_POWER_STATE, parm);
3276 snd_hda_codec_write(codec, 0x27, 0,
3277 AC_VERB_SET_POWER_STATE, parm);
3278 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3279 snd_hda_codec_write(codec, 0x25, 0,
3280 AC_VERB_SET_POWER_STATE, parm);
3283 static int patch_vt1708S(struct hda_codec *codec);
3284 static int patch_vt1708B_8ch(struct hda_codec *codec)
3286 struct via_spec *spec;
3289 if (get_codec_type(codec) == VT1708BCE)
3290 return patch_vt1708S(codec);
3291 /* create a codec specific record */
3292 spec = via_new_spec(codec);
3296 /* automatic parse from the BIOS config */
3297 err = vt1708B_parse_auto_config(codec);
3302 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3303 "from BIOS. Using genenic mode...\n");
3306 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3307 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3309 spec->stream_name_analog = "VT1708B Analog";
3310 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3311 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3313 spec->stream_name_digital = "VT1708B Digital";
3314 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3315 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3317 if (!spec->adc_nids && spec->input_mux) {
3318 spec->adc_nids = vt1708B_adc_nids;
3319 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3320 get_mux_nids(codec);
3321 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3325 codec->patch_ops = via_patch_ops;
3327 codec->patch_ops.init = via_auto_init;
3328 codec->patch_ops.unsol_event = via_unsol_event;
3329 #ifdef CONFIG_SND_HDA_POWER_SAVE
3330 spec->loopback.amplist = vt1708B_loopbacks;
3333 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3338 static int patch_vt1708B_4ch(struct hda_codec *codec)
3340 struct via_spec *spec;
3343 /* create a codec specific record */
3344 spec = via_new_spec(codec);
3348 /* automatic parse from the BIOS config */
3349 err = vt1708B_parse_auto_config(codec);
3354 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3355 "from BIOS. Using genenic mode...\n");
3358 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3359 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3361 spec->stream_name_analog = "VT1708B Analog";
3362 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3363 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3365 spec->stream_name_digital = "VT1708B Digital";
3366 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3367 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3369 if (!spec->adc_nids && spec->input_mux) {
3370 spec->adc_nids = vt1708B_adc_nids;
3371 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3372 get_mux_nids(codec);
3373 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3377 codec->patch_ops = via_patch_ops;
3379 codec->patch_ops.init = via_auto_init;
3380 codec->patch_ops.unsol_event = via_unsol_event;
3381 #ifdef CONFIG_SND_HDA_POWER_SAVE
3382 spec->loopback.amplist = vt1708B_loopbacks;
3385 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3390 /* Patch for VT1708S */
3392 /* capture mixer elements */
3393 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3394 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3395 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3396 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3397 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3398 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3399 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3402 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3403 /* The multiple "Capture Source" controls confuse alsamixer
3404 * So call somewhat different..
3406 /* .name = "Capture Source", */
3407 .name = "Input Source",
3409 .info = via_mux_enum_info,
3410 .get = via_mux_enum_get,
3411 .put = via_mux_enum_put,
3416 static struct hda_verb vt1708S_volume_init_verbs[] = {
3417 /* Unmute ADC0-1 and set the default input to mic-in */
3418 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3419 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3421 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3422 * analog-loopback mixer widget */
3423 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3424 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3425 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3426 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3427 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3428 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3430 /* Setup default input of PW4 to MW0 */
3431 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3432 /* PW9, PW10 Output enable */
3433 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3434 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3435 /* Enable Mic Boost Volume backdoor */
3437 /* don't bybass mixer */
3442 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3443 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3444 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3445 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3446 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3447 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3448 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3449 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3450 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3451 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3455 static struct hda_verb vt1705_uniwill_init_verbs[] = {
3456 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3457 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3458 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3459 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3460 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3461 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3462 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3463 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3467 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3471 .nid = 0x10, /* NID to query formats and rates */
3473 .open = via_playback_pcm_open,
3474 .prepare = via_playback_multi_pcm_prepare,
3475 .cleanup = via_playback_multi_pcm_cleanup,
3476 .close = via_pcm_open_close
3480 static struct hda_pcm_stream vt1705_pcm_analog_playback = {
3484 .nid = 0x10, /* NID to query formats and rates */
3486 .open = via_playback_pcm_open,
3487 .prepare = via_playback_multi_pcm_prepare,
3488 .cleanup = via_playback_multi_pcm_cleanup,
3489 .close = via_pcm_open_close
3493 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3497 .nid = 0x13, /* NID to query formats and rates */
3499 .open = via_pcm_open_close,
3500 .prepare = via_capture_pcm_prepare,
3501 .cleanup = via_capture_pcm_cleanup,
3502 .close = via_pcm_open_close
3506 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3510 /* NID is set in via_build_pcms */
3512 .open = via_dig_playback_pcm_open,
3513 .close = via_dig_playback_pcm_close,
3514 .prepare = via_dig_playback_pcm_prepare,
3515 .cleanup = via_dig_playback_pcm_cleanup
3519 /* fill in the dac_nids table from the parsed pin configuration */
3520 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3521 const struct auto_pin_cfg *cfg)
3526 spec->multiout.num_dacs = cfg->line_outs;
3528 spec->multiout.dac_nids = spec->private_dac_nids;
3530 for (i = 0; i < 4; i++) {
3531 nid = cfg->line_out_pins[i];
3533 /* config dac list */
3535 case AUTO_SEQ_FRONT:
3536 spec->multiout.dac_nids[i] = 0x10;
3538 case AUTO_SEQ_CENLFE:
3539 if (spec->codec->vendor_id == 0x11064397)
3540 spec->multiout.dac_nids[i] = 0x25;
3542 spec->multiout.dac_nids[i] = 0x24;
3544 case AUTO_SEQ_SURROUND:
3545 spec->multiout.dac_nids[i] = 0x11;
3548 spec->multiout.dac_nids[i] = 0x25;
3554 /* for Smart 5.1, line/mic inputs double as output pins */
3555 if (cfg->line_outs == 1) {
3556 spec->multiout.num_dacs = 3;
3557 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3558 if (spec->codec->vendor_id == 0x11064397)
3559 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x25;
3561 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3567 /* add playback controls from the parsed DAC table */
3568 static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
3569 const struct auto_pin_cfg *cfg)
3571 struct via_spec *spec = codec->spec;
3573 static const char * const chname[4] = {
3574 "Front", "Surround", "C/LFE", "Side"
3576 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3577 {0x10, 0x11, 0x25, 0} };
3578 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3579 {0x1C, 0x18, 0x27, 0} };
3580 hda_nid_t nid, nid_vol, nid_mute;
3583 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3584 nid = cfg->line_out_pins[i];
3586 /* for Smart 5.1, there are always at least six channels */
3587 if (!nid && i > AUTO_SEQ_CENLFE)
3590 if (codec->vendor_id == 0x11064397) {
3591 nid_vol = nid_vols[1][i];
3592 nid_mute = nid_mutes[1][i];
3594 nid_vol = nid_vols[0][i];
3595 nid_mute = nid_mutes[0][i];
3597 if (!nid_vol && !nid_mute)
3600 if (i == AUTO_SEQ_CENLFE) {
3602 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3603 "Center Playback Volume",
3604 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3608 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3609 "LFE Playback Volume",
3610 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3614 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3615 "Center Playback Switch",
3616 HDA_COMPOSE_AMP_VAL(nid_mute,
3621 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3622 "LFE Playback Switch",
3623 HDA_COMPOSE_AMP_VAL(nid_mute,
3628 } else if (i == AUTO_SEQ_FRONT) {
3629 /* add control to mixer index 0 */
3630 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3631 "Master Front Playback Volume",
3632 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3636 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3637 "Master Front Playback Switch",
3638 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3644 sprintf(name, "%s Playback Volume", chname[i]);
3645 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3646 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3650 sprintf(name, "%s Playback Switch", chname[i]);
3651 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3652 HDA_COMPOSE_AMP_VAL(nid_mute,
3658 sprintf(name, "%s Playback Volume", chname[i]);
3659 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3660 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3664 sprintf(name, "%s Playback Switch", chname[i]);
3665 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3666 HDA_COMPOSE_AMP_VAL(nid_mute,
3677 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3684 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3685 spec->hp_independent_mode_index = 1;
3687 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3688 "Headphone Playback Volume",
3689 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3693 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3694 "Headphone Playback Switch",
3695 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3699 create_hp_imux(spec);
3704 /* create playback/capture controls for input pins */
3705 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3706 const struct auto_pin_cfg *cfg)
3708 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
3709 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3710 ARRAY_SIZE(pin_idxs));
3713 /* fill out digital output widgets; one for master and one for slave outputs */
3714 static void fill_dig_outs(struct hda_codec *codec)
3716 struct via_spec *spec = codec->spec;
3719 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3723 nid = spec->autocfg.dig_out_pins[i];
3726 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3729 if (!spec->multiout.dig_out_nid)
3730 spec->multiout.dig_out_nid = nid;
3732 spec->slave_dig_outs[0] = nid;
3733 break; /* at most two dig outs */
3738 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3740 struct via_spec *spec = codec->spec;
3743 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3746 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3749 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3750 return 0; /* can't find valid BIOS pin config */
3752 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
3755 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3758 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
3762 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3764 fill_dig_outs(codec);
3766 if (spec->kctls.list)
3767 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3769 spec->input_mux = &spec->private_imux[0];
3772 via_hp_build(codec);
3774 via_smart51_build(spec);
3778 #ifdef CONFIG_SND_HDA_POWER_SAVE
3779 static struct hda_amp_list vt1708S_loopbacks[] = {
3780 { 0x16, HDA_INPUT, 1 },
3781 { 0x16, HDA_INPUT, 2 },
3782 { 0x16, HDA_INPUT, 3 },
3783 { 0x16, HDA_INPUT, 4 },
3788 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3789 int offset, int num_steps, int step_size)
3791 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3792 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3793 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3794 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3795 (0 << AC_AMPCAP_MUTE_SHIFT));
3798 static int patch_vt1708S(struct hda_codec *codec)
3800 struct via_spec *spec;
3803 /* create a codec specific record */
3804 spec = via_new_spec(codec);
3808 /* automatic parse from the BIOS config */
3809 err = vt1708S_parse_auto_config(codec);
3814 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3815 "from BIOS. Using genenic mode...\n");
3818 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3819 if (codec->vendor_id == 0x11064397)
3820 spec->init_verbs[spec->num_iverbs++] =
3821 vt1705_uniwill_init_verbs;
3823 spec->init_verbs[spec->num_iverbs++] =
3824 vt1708S_uniwill_init_verbs;
3826 if (codec->vendor_id == 0x11060440)
3827 spec->stream_name_analog = "VT1818S Analog";
3828 else if (codec->vendor_id == 0x11064397)
3829 spec->stream_name_analog = "VT1705 Analog";
3831 spec->stream_name_analog = "VT1708S Analog";
3832 if (codec->vendor_id == 0x11064397)
3833 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3835 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
3836 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3838 if (codec->vendor_id == 0x11060440)
3839 spec->stream_name_digital = "VT1818S Digital";
3840 else if (codec->vendor_id == 0x11064397)
3841 spec->stream_name_digital = "VT1705 Digital";
3843 spec->stream_name_digital = "VT1708S Digital";
3844 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3846 if (!spec->adc_nids && spec->input_mux) {
3847 spec->adc_nids = vt1708S_adc_nids;
3848 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
3849 get_mux_nids(codec);
3850 override_mic_boost(codec, 0x1a, 0, 3, 40);
3851 override_mic_boost(codec, 0x1e, 0, 3, 40);
3852 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3856 codec->patch_ops = via_patch_ops;
3858 codec->patch_ops.init = via_auto_init;
3859 codec->patch_ops.unsol_event = via_unsol_event;
3860 #ifdef CONFIG_SND_HDA_POWER_SAVE
3861 spec->loopback.amplist = vt1708S_loopbacks;
3864 /* correct names for VT1708BCE */
3865 if (get_codec_type(codec) == VT1708BCE) {
3866 kfree(codec->chip_name);
3867 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3868 snprintf(codec->bus->card->mixername,
3869 sizeof(codec->bus->card->mixername),
3870 "%s %s", codec->vendor_name, codec->chip_name);
3871 spec->stream_name_analog = "VT1708BCE Analog";
3872 spec->stream_name_digital = "VT1708BCE Digital";
3874 /* correct names for VT1818S */
3875 if (codec->vendor_id == 0x11060440) {
3876 spec->stream_name_analog = "VT1818S Analog";
3877 spec->stream_name_digital = "VT1818S Digital";
3879 /* correct names for VT1705 */
3880 if (codec->vendor_id == 0x11064397) {
3881 kfree(codec->chip_name);
3882 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3883 snprintf(codec->bus->card->mixername,
3884 sizeof(codec->bus->card->mixername),
3885 "%s %s", codec->vendor_name, codec->chip_name);
3887 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3891 /* Patch for VT1702 */
3893 /* capture mixer elements */
3894 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
3895 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3896 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3897 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3898 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3899 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3900 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3901 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3904 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3905 /* The multiple "Capture Source" controls confuse alsamixer
3906 * So call somewhat different..
3908 /* .name = "Capture Source", */
3909 .name = "Input Source",
3911 .info = via_mux_enum_info,
3912 .get = via_mux_enum_get,
3913 .put = via_mux_enum_put,
3918 static struct hda_verb vt1702_volume_init_verbs[] = {
3920 * Unmute ADC0-1 and set the default input to mic-in
3922 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3923 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3924 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3927 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3930 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3931 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3932 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3933 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3934 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3935 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3937 /* Setup default input of PW4 to MW0 */
3938 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3939 /* PW6 PW7 Output enable */
3940 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3941 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3949 static struct hda_verb vt1702_uniwill_init_verbs[] = {
3950 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3951 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3952 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3953 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3954 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3955 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3959 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
3963 .nid = 0x10, /* NID to query formats and rates */
3965 .open = via_playback_pcm_open,
3966 .prepare = via_playback_multi_pcm_prepare,
3967 .cleanup = via_playback_multi_pcm_cleanup,
3968 .close = via_pcm_open_close
3972 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
3976 .nid = 0x12, /* NID to query formats and rates */
3978 .open = via_pcm_open_close,
3979 .prepare = via_capture_pcm_prepare,
3980 .cleanup = via_capture_pcm_cleanup,
3981 .close = via_pcm_open_close
3985 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
3989 /* NID is set in via_build_pcms */
3991 .open = via_dig_playback_pcm_open,
3992 .close = via_dig_playback_pcm_close,
3993 .prepare = via_dig_playback_pcm_prepare,
3994 .cleanup = via_dig_playback_pcm_cleanup
3998 /* fill in the dac_nids table from the parsed pin configuration */
3999 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4000 const struct auto_pin_cfg *cfg)
4002 spec->multiout.num_dacs = 1;
4003 spec->multiout.dac_nids = spec->private_dac_nids;
4005 if (cfg->line_out_pins[0]) {
4006 /* config dac list */
4007 spec->multiout.dac_nids[0] = 0x10;
4013 /* add playback controls from the parsed DAC table */
4014 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4015 const struct auto_pin_cfg *cfg)
4019 if (!cfg->line_out_pins[0])
4022 /* add control to mixer index 0 */
4023 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4024 "Master Front Playback Volume",
4025 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4028 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4029 "Master Front Playback Switch",
4030 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4035 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4036 "Front Playback Volume",
4037 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4040 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4041 "Front Playback Switch",
4042 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4049 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4052 struct hda_input_mux *imux;
4053 static const char * const texts[] = { "ON", "OFF", NULL};
4056 spec->multiout.hp_nid = 0x1D;
4057 spec->hp_independent_mode_index = 0;
4059 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4060 "Headphone Playback Volume",
4061 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4065 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4066 "Headphone Playback Switch",
4067 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4071 imux = &spec->private_imux[1];
4073 /* for hp mode select */
4074 for (i = 0; texts[i]; i++)
4075 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4077 spec->hp_mux = &spec->private_imux[1];
4081 /* create playback/capture controls for input pins */
4082 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4083 const struct auto_pin_cfg *cfg)
4085 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4086 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4087 ARRAY_SIZE(pin_idxs));
4090 static int vt1702_parse_auto_config(struct hda_codec *codec)
4092 struct via_spec *spec = codec->spec;
4095 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4098 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4101 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4102 return 0; /* can't find valid BIOS pin config */
4104 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4107 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4110 /* limit AA path volume to 0 dB */
4111 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4112 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4113 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4114 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4115 (1 << AC_AMPCAP_MUTE_SHIFT));
4116 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4120 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4122 fill_dig_outs(codec);
4124 if (spec->kctls.list)
4125 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4127 spec->input_mux = &spec->private_imux[0];
4130 via_hp_build(codec);
4135 #ifdef CONFIG_SND_HDA_POWER_SAVE
4136 static struct hda_amp_list vt1702_loopbacks[] = {
4137 { 0x1A, HDA_INPUT, 1 },
4138 { 0x1A, HDA_INPUT, 2 },
4139 { 0x1A, HDA_INPUT, 3 },
4140 { 0x1A, HDA_INPUT, 4 },
4145 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4147 int imux_is_smixer =
4148 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4151 /* PW 1/2/5 (14h/15h/18h) */
4153 set_pin_power_state(codec, 0x14, &parm);
4154 set_pin_power_state(codec, 0x15, &parm);
4155 set_pin_power_state(codec, 0x18, &parm);
4157 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4158 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4159 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4160 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4161 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4162 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4165 /* PW 3/4 (16h/17h) */
4167 set_pin_power_state(codec, 0x17, &parm);
4168 set_pin_power_state(codec, 0x16, &parm);
4169 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4170 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4171 imux_is_smixer ? AC_PWRST_D0 : parm);
4172 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4173 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4176 static int patch_vt1702(struct hda_codec *codec)
4178 struct via_spec *spec;
4181 /* create a codec specific record */
4182 spec = via_new_spec(codec);
4186 /* automatic parse from the BIOS config */
4187 err = vt1702_parse_auto_config(codec);
4192 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4193 "from BIOS. Using genenic mode...\n");
4196 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4197 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4199 spec->stream_name_analog = "VT1702 Analog";
4200 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4201 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4203 spec->stream_name_digital = "VT1702 Digital";
4204 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4206 if (!spec->adc_nids && spec->input_mux) {
4207 spec->adc_nids = vt1702_adc_nids;
4208 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4209 get_mux_nids(codec);
4210 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4214 codec->patch_ops = via_patch_ops;
4216 codec->patch_ops.init = via_auto_init;
4217 codec->patch_ops.unsol_event = via_unsol_event;
4218 #ifdef CONFIG_SND_HDA_POWER_SAVE
4219 spec->loopback.amplist = vt1702_loopbacks;
4222 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
4226 /* Patch for VT1718S */
4228 /* capture mixer elements */
4229 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4230 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4231 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4232 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4233 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4234 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4235 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4238 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4239 /* The multiple "Capture Source" controls confuse alsamixer
4240 * So call somewhat different..
4242 .name = "Input Source",
4244 .info = via_mux_enum_info,
4245 .get = via_mux_enum_get,
4246 .put = via_mux_enum_put,
4251 static struct hda_verb vt1718S_volume_init_verbs[] = {
4253 * Unmute ADC0-1 and set the default input to mic-in
4255 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4256 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4258 /* Enable MW0 adjust Gain 5 */
4260 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4263 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4264 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4265 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4266 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4267 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4268 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
4270 /* Setup default input of Front HP to MW9 */
4271 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4272 /* PW9 PW10 Output enable */
4273 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4274 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4275 /* PW11 Input enable */
4276 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4277 /* Enable Boost Volume backdoor */
4279 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4280 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4281 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4282 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4283 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4284 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4285 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4286 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4287 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4288 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4289 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4290 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4291 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4292 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4293 /* Unmute MW4's index 0 */
4294 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4299 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4300 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4301 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4302 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4303 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4304 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4305 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4306 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4307 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4308 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4312 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4316 .nid = 0x8, /* NID to query formats and rates */
4318 .open = via_playback_pcm_open,
4319 .prepare = via_playback_multi_pcm_prepare,
4320 .cleanup = via_playback_multi_pcm_cleanup,
4321 .close = via_pcm_open_close,
4325 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4329 .nid = 0x10, /* NID to query formats and rates */
4331 .open = via_pcm_open_close,
4332 .prepare = via_capture_pcm_prepare,
4333 .cleanup = via_capture_pcm_cleanup,
4334 .close = via_pcm_open_close,
4338 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4342 /* NID is set in via_build_pcms */
4344 .open = via_dig_playback_pcm_open,
4345 .close = via_dig_playback_pcm_close,
4346 .prepare = via_dig_playback_pcm_prepare,
4347 .cleanup = via_dig_playback_pcm_cleanup
4351 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4357 /* fill in the dac_nids table from the parsed pin configuration */
4358 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4359 const struct auto_pin_cfg *cfg)
4364 spec->multiout.num_dacs = cfg->line_outs;
4366 spec->multiout.dac_nids = spec->private_dac_nids;
4368 for (i = 0; i < 4; i++) {
4369 nid = cfg->line_out_pins[i];
4371 /* config dac list */
4373 case AUTO_SEQ_FRONT:
4374 spec->multiout.dac_nids[i] = 0x8;
4376 case AUTO_SEQ_CENLFE:
4377 spec->multiout.dac_nids[i] = 0xa;
4379 case AUTO_SEQ_SURROUND:
4380 spec->multiout.dac_nids[i] = 0x9;
4383 spec->multiout.dac_nids[i] = 0xb;
4392 /* add playback controls from the parsed DAC table */
4393 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4394 const struct auto_pin_cfg *cfg)
4397 static const char * const chname[4] = {
4398 "Front", "Surround", "C/LFE", "Side"
4400 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4401 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4402 hda_nid_t nid, nid_vol, nid_mute = 0;
4405 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4406 nid = cfg->line_out_pins[i];
4410 nid_vol = nid_vols[i];
4411 nid_mute = nid_mutes[i];
4413 if (i == AUTO_SEQ_CENLFE) {
4415 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4416 "Center Playback Volume",
4417 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4421 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4422 "LFE Playback Volume",
4423 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4427 err = via_add_control(
4428 spec, VIA_CTL_WIDGET_MUTE,
4429 "Center Playback Switch",
4430 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4434 err = via_add_control(
4435 spec, VIA_CTL_WIDGET_MUTE,
4436 "LFE Playback Switch",
4437 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4441 } else if (i == AUTO_SEQ_FRONT) {
4443 sprintf(name, "%s Playback Volume", chname[i]);
4444 err = via_add_control(
4445 spec, VIA_CTL_WIDGET_VOL, name,
4446 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4449 sprintf(name, "%s Playback Switch", chname[i]);
4450 err = via_add_control(
4451 spec, VIA_CTL_WIDGET_MUTE, name,
4452 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4457 sprintf(name, "%s Playback Volume", chname[i]);
4458 err = via_add_control(
4459 spec, VIA_CTL_WIDGET_VOL, name,
4460 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4463 sprintf(name, "%s Playback Switch", chname[i]);
4464 err = via_add_control(
4465 spec, VIA_CTL_WIDGET_MUTE, name,
4466 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4475 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4482 spec->multiout.hp_nid = 0xc; /* AOW4 */
4483 spec->hp_independent_mode_index = 1;
4485 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4486 "Headphone Playback Volume",
4487 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4491 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4492 "Headphone Playback Switch",
4493 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4497 create_hp_imux(spec);
4501 /* create playback/capture controls for input pins */
4502 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4503 const struct auto_pin_cfg *cfg)
4505 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4506 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4507 ARRAY_SIZE(pin_idxs));
4510 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4512 struct via_spec *spec = codec->spec;
4515 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4519 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4522 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4523 return 0; /* can't find valid BIOS pin config */
4525 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4528 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4531 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4535 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4537 fill_dig_outs(codec);
4539 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4540 spec->dig_in_nid = 0x13;
4542 if (spec->kctls.list)
4543 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4545 spec->input_mux = &spec->private_imux[0];
4548 via_hp_build(codec);
4550 via_smart51_build(spec);
4555 #ifdef CONFIG_SND_HDA_POWER_SAVE
4556 static struct hda_amp_list vt1718S_loopbacks[] = {
4557 { 0x21, HDA_INPUT, 1 },
4558 { 0x21, HDA_INPUT, 2 },
4559 { 0x21, HDA_INPUT, 3 },
4560 { 0x21, HDA_INPUT, 4 },
4565 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4567 struct via_spec *spec = codec->spec;
4570 /* MUX6 (1eh) = stereo mixer */
4572 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4574 /* PW 5/6/7 (29h/2ah/2bh) */
4576 set_pin_power_state(codec, 0x29, &parm);
4577 set_pin_power_state(codec, 0x2a, &parm);
4578 set_pin_power_state(codec, 0x2b, &parm);
4581 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4582 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4583 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4584 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4585 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4588 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4590 set_pin_power_state(codec, 0x27, &parm);
4591 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4592 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4594 /* PW2 (26h), AOW2 (ah) */
4596 set_pin_power_state(codec, 0x26, &parm);
4597 if (spec->smart51_enabled)
4598 set_pin_power_state(codec, 0x2b, &parm);
4599 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4601 /* PW0 (24h), AOW0 (8h) */
4603 set_pin_power_state(codec, 0x24, &parm);
4604 if (!spec->hp_independent_mode) /* check for redirected HP */
4605 set_pin_power_state(codec, 0x28, &parm);
4606 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4607 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4608 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4609 imux_is_smixer ? AC_PWRST_D0 : parm);
4611 /* PW1 (25h), AOW1 (9h) */
4613 set_pin_power_state(codec, 0x25, &parm);
4614 if (spec->smart51_enabled)
4615 set_pin_power_state(codec, 0x2a, &parm);
4616 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4618 if (spec->hp_independent_mode) {
4619 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4621 set_pin_power_state(codec, 0x28, &parm);
4622 snd_hda_codec_write(codec, 0x1b, 0,
4623 AC_VERB_SET_POWER_STATE, parm);
4624 snd_hda_codec_write(codec, 0x34, 0,
4625 AC_VERB_SET_POWER_STATE, parm);
4626 snd_hda_codec_write(codec, 0xc, 0,
4627 AC_VERB_SET_POWER_STATE, parm);
4631 static int patch_vt1718S(struct hda_codec *codec)
4633 struct via_spec *spec;
4636 /* create a codec specific record */
4637 spec = via_new_spec(codec);
4641 /* automatic parse from the BIOS config */
4642 err = vt1718S_parse_auto_config(codec);
4647 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4648 "from BIOS. Using genenic mode...\n");
4651 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4652 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4654 if (codec->vendor_id == 0x11060441)
4655 spec->stream_name_analog = "VT2020 Analog";
4656 else if (codec->vendor_id == 0x11064441)
4657 spec->stream_name_analog = "VT1828S Analog";
4659 spec->stream_name_analog = "VT1718S Analog";
4660 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4661 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4663 if (codec->vendor_id == 0x11060441)
4664 spec->stream_name_digital = "VT2020 Digital";
4665 else if (codec->vendor_id == 0x11064441)
4666 spec->stream_name_digital = "VT1828S Digital";
4668 spec->stream_name_digital = "VT1718S Digital";
4669 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4670 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4671 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4673 if (!spec->adc_nids && spec->input_mux) {
4674 spec->adc_nids = vt1718S_adc_nids;
4675 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4676 get_mux_nids(codec);
4677 override_mic_boost(codec, 0x2b, 0, 3, 40);
4678 override_mic_boost(codec, 0x29, 0, 3, 40);
4679 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4683 codec->patch_ops = via_patch_ops;
4685 codec->patch_ops.init = via_auto_init;
4686 codec->patch_ops.unsol_event = via_unsol_event;
4688 #ifdef CONFIG_SND_HDA_POWER_SAVE
4689 spec->loopback.amplist = vt1718S_loopbacks;
4692 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4697 /* Patch for VT1716S */
4699 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4700 struct snd_ctl_elem_info *uinfo)
4702 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4704 uinfo->value.integer.min = 0;
4705 uinfo->value.integer.max = 1;
4709 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4710 struct snd_ctl_elem_value *ucontrol)
4712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4715 index = snd_hda_codec_read(codec, 0x26, 0,
4716 AC_VERB_GET_CONNECT_SEL, 0);
4718 *ucontrol->value.integer.value = index;
4723 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4724 struct snd_ctl_elem_value *ucontrol)
4726 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4727 struct via_spec *spec = codec->spec;
4728 int index = *ucontrol->value.integer.value;
4730 snd_hda_codec_write(codec, 0x26, 0,
4731 AC_VERB_SET_CONNECT_SEL, index);
4732 spec->dmic_enabled = index;
4733 set_widgets_power_state(codec);
4737 /* capture mixer elements */
4738 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4739 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4740 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4741 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4742 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4743 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4744 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4747 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4748 .name = "Input Source",
4750 .info = via_mux_enum_info,
4751 .get = via_mux_enum_get,
4752 .put = via_mux_enum_put,
4757 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4758 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4761 .name = "Digital Mic Capture Switch",
4762 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4764 .info = vt1716s_dmic_info,
4765 .get = vt1716s_dmic_get,
4766 .put = vt1716s_dmic_put,
4772 /* mono-out mixer elements */
4773 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4774 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4778 static struct hda_verb vt1716S_volume_init_verbs[] = {
4780 * Unmute ADC0-1 and set the default input to mic-in
4782 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4786 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4789 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4790 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4791 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4792 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4793 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4794 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4796 /* MUX Indices: Stereo Mixer = 5 */
4797 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4799 /* Setup default input of PW4 to MW0 */
4800 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4802 /* Setup default input of SW1 as MW0 */
4803 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4805 /* Setup default input of SW4 as AOW0 */
4806 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4808 /* PW9 PW10 Output enable */
4809 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4810 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4812 /* Unmute SW1, PW12 */
4813 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4814 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4815 /* PW12 Output enable */
4816 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4817 /* Enable Boost Volume backdoor */
4819 /* don't bybass mixer */
4821 /* Enable mono output */
4827 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
4828 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4829 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4830 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4831 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4832 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4833 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4834 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4835 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4836 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4840 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4844 .nid = 0x10, /* NID to query formats and rates */
4846 .open = via_playback_pcm_open,
4847 .prepare = via_playback_multi_pcm_prepare,
4848 .cleanup = via_playback_multi_pcm_cleanup,
4849 .close = via_pcm_open_close,
4853 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
4857 .nid = 0x13, /* NID to query formats and rates */
4859 .open = via_pcm_open_close,
4860 .prepare = via_capture_pcm_prepare,
4861 .cleanup = via_capture_pcm_cleanup,
4862 .close = via_pcm_open_close,
4866 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
4870 /* NID is set in via_build_pcms */
4872 .open = via_dig_playback_pcm_open,
4873 .close = via_dig_playback_pcm_close,
4874 .prepare = via_dig_playback_pcm_prepare,
4875 .cleanup = via_dig_playback_pcm_cleanup
4879 /* fill in the dac_nids table from the parsed pin configuration */
4880 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4881 const struct auto_pin_cfg *cfg)
4885 spec->multiout.num_dacs = cfg->line_outs;
4887 spec->multiout.dac_nids = spec->private_dac_nids;
4889 for (i = 0; i < 3; i++) {
4890 nid = cfg->line_out_pins[i];
4892 /* config dac list */
4894 case AUTO_SEQ_FRONT:
4895 spec->multiout.dac_nids[i] = 0x10;
4897 case AUTO_SEQ_CENLFE:
4898 spec->multiout.dac_nids[i] = 0x25;
4900 case AUTO_SEQ_SURROUND:
4901 spec->multiout.dac_nids[i] = 0x11;
4910 /* add playback controls from the parsed DAC table */
4911 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4912 const struct auto_pin_cfg *cfg)
4915 static const char * const chname[3] = {
4916 "Front", "Surround", "C/LFE"
4918 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4919 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4920 hda_nid_t nid, nid_vol, nid_mute;
4923 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4924 nid = cfg->line_out_pins[i];
4929 nid_vol = nid_vols[i];
4930 nid_mute = nid_mutes[i];
4932 if (i == AUTO_SEQ_CENLFE) {
4933 err = via_add_control(
4934 spec, VIA_CTL_WIDGET_VOL,
4935 "Center Playback Volume",
4936 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4939 err = via_add_control(
4940 spec, VIA_CTL_WIDGET_VOL,
4941 "LFE Playback Volume",
4942 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4945 err = via_add_control(
4946 spec, VIA_CTL_WIDGET_MUTE,
4947 "Center Playback Switch",
4948 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4952 err = via_add_control(
4953 spec, VIA_CTL_WIDGET_MUTE,
4954 "LFE Playback Switch",
4955 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4959 } else if (i == AUTO_SEQ_FRONT) {
4961 err = via_add_control(
4962 spec, VIA_CTL_WIDGET_VOL,
4963 "Master Front Playback Volume",
4964 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4967 err = via_add_control(
4968 spec, VIA_CTL_WIDGET_MUTE,
4969 "Master Front Playback Switch",
4970 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4974 sprintf(name, "%s Playback Volume", chname[i]);
4975 err = via_add_control(
4976 spec, VIA_CTL_WIDGET_VOL, name,
4977 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4980 sprintf(name, "%s Playback Switch", chname[i]);
4981 err = via_add_control(
4982 spec, VIA_CTL_WIDGET_MUTE, name,
4983 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4988 sprintf(name, "%s Playback Volume", chname[i]);
4989 err = via_add_control(
4990 spec, VIA_CTL_WIDGET_VOL, name,
4991 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4994 sprintf(name, "%s Playback Switch", chname[i]);
4995 err = via_add_control(
4996 spec, VIA_CTL_WIDGET_MUTE, name,
4997 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5006 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5013 spec->multiout.hp_nid = 0x25; /* AOW3 */
5014 spec->hp_independent_mode_index = 1;
5016 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5017 "Headphone Playback Volume",
5018 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5022 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5023 "Headphone Playback Switch",
5024 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5028 create_hp_imux(spec);
5032 /* create playback/capture controls for input pins */
5033 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5034 const struct auto_pin_cfg *cfg)
5036 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5037 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5038 ARRAY_SIZE(pin_idxs));
5041 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5043 struct via_spec *spec = codec->spec;
5046 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5049 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5052 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5053 return 0; /* can't find valid BIOS pin config */
5055 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5058 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5061 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5065 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5067 fill_dig_outs(codec);
5069 if (spec->kctls.list)
5070 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5072 spec->input_mux = &spec->private_imux[0];
5075 via_hp_build(codec);
5077 via_smart51_build(spec);
5082 #ifdef CONFIG_SND_HDA_POWER_SAVE
5083 static struct hda_amp_list vt1716S_loopbacks[] = {
5084 { 0x16, HDA_INPUT, 1 },
5085 { 0x16, HDA_INPUT, 2 },
5086 { 0x16, HDA_INPUT, 3 },
5087 { 0x16, HDA_INPUT, 4 },
5092 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5094 struct via_spec *spec = codec->spec;
5097 unsigned int mono_out, present;
5098 /* SW0 (17h) = stereo mixer */
5100 (snd_hda_codec_read(codec, 0x17, 0,
5101 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5103 /* PW 1/2/5 (1ah/1bh/1eh) */
5105 set_pin_power_state(codec, 0x1a, &parm);
5106 set_pin_power_state(codec, 0x1b, &parm);
5107 set_pin_power_state(codec, 0x1e, &parm);
5110 /* SW0 (17h), AIW0(13h) */
5111 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5112 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5115 set_pin_power_state(codec, 0x1e, &parm);
5117 if (spec->dmic_enabled)
5118 set_pin_power_state(codec, 0x22, &parm);
5120 snd_hda_codec_write(codec, 0x22, 0,
5121 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5123 /* SW2(26h), AIW1(14h) */
5124 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5125 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5128 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5130 set_pin_power_state(codec, 0x19, &parm);
5131 /* Smart 5.1 PW2(1bh) */
5132 if (spec->smart51_enabled)
5133 set_pin_power_state(codec, 0x1b, &parm);
5134 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5135 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5137 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5139 set_pin_power_state(codec, 0x23, &parm);
5140 /* Smart 5.1 PW1(1ah) */
5141 if (spec->smart51_enabled)
5142 set_pin_power_state(codec, 0x1a, &parm);
5143 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5145 /* Smart 5.1 PW5(1eh) */
5146 if (spec->smart51_enabled)
5147 set_pin_power_state(codec, 0x1e, &parm);
5148 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5151 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5152 present = snd_hda_jack_detect(codec, 0x1c);
5157 present = snd_hda_jack_detect(codec, 0x1d);
5158 if (!spec->hp_independent_mode && present)
5163 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5164 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5165 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5166 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5168 /* PW 3/4 (1ch/1dh) */
5170 set_pin_power_state(codec, 0x1c, &parm);
5171 set_pin_power_state(codec, 0x1d, &parm);
5172 /* HP Independent Mode, power on AOW3 */
5173 if (spec->hp_independent_mode)
5174 snd_hda_codec_write(codec, 0x25, 0,
5175 AC_VERB_SET_POWER_STATE, parm);
5177 /* force to D0 for internal Speaker */
5178 /* MW0 (16h), AOW0 (10h) */
5179 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5180 imux_is_smixer ? AC_PWRST_D0 : parm);
5181 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5182 mono_out ? AC_PWRST_D0 : parm);
5185 static int patch_vt1716S(struct hda_codec *codec)
5187 struct via_spec *spec;
5190 /* create a codec specific record */
5191 spec = via_new_spec(codec);
5195 /* automatic parse from the BIOS config */
5196 err = vt1716S_parse_auto_config(codec);
5201 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5202 "from BIOS. Using genenic mode...\n");
5205 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5206 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5208 spec->stream_name_analog = "VT1716S Analog";
5209 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5210 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5212 spec->stream_name_digital = "VT1716S Digital";
5213 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5215 if (!spec->adc_nids && spec->input_mux) {
5216 spec->adc_nids = vt1716S_adc_nids;
5217 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5218 get_mux_nids(codec);
5219 override_mic_boost(codec, 0x1a, 0, 3, 40);
5220 override_mic_boost(codec, 0x1e, 0, 3, 40);
5221 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5225 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5228 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5230 codec->patch_ops = via_patch_ops;
5232 codec->patch_ops.init = via_auto_init;
5233 codec->patch_ops.unsol_event = via_unsol_event;
5235 #ifdef CONFIG_SND_HDA_POWER_SAVE
5236 spec->loopback.amplist = vt1716S_loopbacks;
5239 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
5245 /* capture mixer elements */
5246 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5247 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5248 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5249 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5250 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5251 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5252 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5256 /* The multiple "Capture Source" controls confuse alsamixer
5257 * So call somewhat different..
5259 /* .name = "Capture Source", */
5260 .name = "Input Source",
5262 .info = via_mux_enum_info,
5263 .get = via_mux_enum_get,
5264 .put = via_mux_enum_put,
5269 static struct hda_verb vt2002P_volume_init_verbs[] = {
5271 * Unmute ADC0-1 and set the default input to mic-in
5273 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5274 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5277 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5280 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5281 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5282 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5283 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5284 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5285 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5287 /* MUX Indices: Mic = 0 */
5288 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5289 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5291 /* PW9 Output enable */
5292 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5294 /* Enable Boost Volume backdoor */
5297 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5298 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5299 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5300 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5301 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5302 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5303 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5304 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5305 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5307 /* set MUX0/1/4/8 = 0 (AOW0) */
5308 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5309 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5310 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5311 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5313 /* set PW0 index=0 (MW0) */
5314 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5316 /* Enable AOW0 to MW9 */
5320 static struct hda_verb vt1802_volume_init_verbs[] = {
5322 * Unmute ADC0-1 and set the default input to mic-in
5324 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5325 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5328 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5331 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5332 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5333 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5334 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5335 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5336 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5338 /* MUX Indices: Mic = 0 */
5339 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5340 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5342 /* PW9 Output enable */
5343 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5345 /* Enable Boost Volume backdoor */
5348 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5349 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5350 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5351 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5352 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5353 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5354 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5355 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5356 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5358 /* set MUX0/1/4/8 = 0 (AOW0) */
5359 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5360 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5361 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5362 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5364 /* set PW0 index=0 (MW0) */
5365 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5367 /* Enable AOW0 to MW9 */
5373 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5374 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5375 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5376 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5377 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5378 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5379 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5380 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5383 static struct hda_verb vt1802_uniwill_init_verbs[] = {
5384 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5385 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5386 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5387 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5388 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5389 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5390 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5394 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5398 .nid = 0x8, /* NID to query formats and rates */
5400 .open = via_playback_pcm_open,
5401 .prepare = via_playback_multi_pcm_prepare,
5402 .cleanup = via_playback_multi_pcm_cleanup,
5403 .close = via_pcm_open_close,
5407 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5411 .nid = 0x10, /* NID to query formats and rates */
5413 .open = via_pcm_open_close,
5414 .prepare = via_capture_pcm_prepare,
5415 .cleanup = via_capture_pcm_cleanup,
5416 .close = via_pcm_open_close,
5420 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5424 /* NID is set in via_build_pcms */
5426 .open = via_dig_playback_pcm_open,
5427 .close = via_dig_playback_pcm_close,
5428 .prepare = via_dig_playback_pcm_prepare,
5429 .cleanup = via_dig_playback_pcm_cleanup
5433 /* fill in the dac_nids table from the parsed pin configuration */
5434 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5435 const struct auto_pin_cfg *cfg)
5437 spec->multiout.num_dacs = 1;
5438 spec->multiout.dac_nids = spec->private_dac_nids;
5439 if (cfg->line_out_pins[0])
5440 spec->multiout.dac_nids[0] = 0x8;
5444 /* add playback controls from the parsed DAC table */
5445 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5446 const struct auto_pin_cfg *cfg)
5451 if (!cfg->line_out_pins[0])
5454 if (spec->codec_type == VT1802)
5459 /* Line-Out: PortE */
5460 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5461 "Master Front Playback Volume",
5462 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5465 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5466 "Master Front Playback Switch",
5467 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
5474 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5481 spec->multiout.hp_nid = 0x9;
5482 spec->hp_independent_mode_index = 1;
5484 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5485 "Headphone Playback Volume",
5486 HDA_COMPOSE_AMP_VAL(
5487 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5491 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5492 "Headphone Playback Switch",
5493 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5497 create_hp_imux(spec);
5501 /* create playback/capture controls for input pins */
5502 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5503 const struct auto_pin_cfg *cfg)
5505 struct via_spec *spec = codec->spec;
5506 struct hda_input_mux *imux = &spec->private_imux[0];
5507 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5510 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5511 ARRAY_SIZE(pin_idxs));
5514 /* build volume/mute control of loopback */
5515 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5519 /* for digital mic select */
5520 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5525 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5527 struct via_spec *spec = codec->spec;
5531 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5535 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5539 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5540 return 0; /* can't find valid BIOS pin config */
5542 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5545 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5548 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5552 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5554 fill_dig_outs(codec);
5556 if (spec->kctls.list)
5557 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5559 spec->input_mux = &spec->private_imux[0];
5562 via_hp_build(codec);
5567 #ifdef CONFIG_SND_HDA_POWER_SAVE
5568 static struct hda_amp_list vt2002P_loopbacks[] = {
5569 { 0x21, HDA_INPUT, 0 },
5570 { 0x21, HDA_INPUT, 1 },
5571 { 0x21, HDA_INPUT, 2 },
5576 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5578 struct via_spec *spec = codec->spec;
5581 unsigned int present;
5582 /* MUX9 (1eh) = stereo mixer */
5584 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5586 /* PW 5/6/7 (29h/2ah/2bh) */
5588 set_pin_power_state(codec, 0x29, &parm);
5589 set_pin_power_state(codec, 0x2a, &parm);
5590 set_pin_power_state(codec, 0x2b, &parm);
5592 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5593 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5594 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5595 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5596 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5600 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5602 if (spec->codec_type == VT1802) {
5603 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5605 set_pin_power_state(codec, 0x28, &parm);
5606 snd_hda_codec_write(codec, 0x18, 0,
5607 AC_VERB_SET_POWER_STATE, parm);
5608 snd_hda_codec_write(codec, 0x38, 0,
5609 AC_VERB_SET_POWER_STATE, parm);
5611 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5613 set_pin_power_state(codec, 0x26, &parm);
5614 snd_hda_codec_write(codec, 0x1c, 0,
5615 AC_VERB_SET_POWER_STATE, parm);
5616 snd_hda_codec_write(codec, 0x37, 0,
5617 AC_VERB_SET_POWER_STATE, parm);
5620 if (spec->codec_type == VT1802) {
5621 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5623 set_pin_power_state(codec, 0x25, &parm);
5624 snd_hda_codec_write(codec, 0x15, 0,
5625 AC_VERB_SET_POWER_STATE, parm);
5626 snd_hda_codec_write(codec, 0x35, 0,
5627 AC_VERB_SET_POWER_STATE, parm);
5629 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5631 set_pin_power_state(codec, 0x25, &parm);
5632 snd_hda_codec_write(codec, 0x19, 0,
5633 AC_VERB_SET_POWER_STATE, parm);
5634 snd_hda_codec_write(codec, 0x35, 0,
5635 AC_VERB_SET_POWER_STATE, parm);
5638 if (spec->hp_independent_mode)
5639 snd_hda_codec_write(codec, 0x9, 0,
5640 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5643 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5644 present = snd_hda_jack_detect(codec, 0x25);
5647 set_pin_power_state(codec, 0x24, &parm);
5648 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5649 if (spec->codec_type == VT1802)
5650 snd_hda_codec_write(codec, 0x14, 0,
5651 AC_VERB_SET_POWER_STATE, parm);
5653 snd_hda_codec_write(codec, 0x18, 0,
5654 AC_VERB_SET_POWER_STATE, parm);
5655 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5658 present = snd_hda_jack_detect(codec, 0x26);
5660 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5661 if (spec->codec_type == VT1802) {
5662 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5663 snd_hda_codec_write(codec, 0x33, 0,
5664 AC_VERB_SET_POWER_STATE, parm);
5665 snd_hda_codec_write(codec, 0x1c, 0,
5666 AC_VERB_SET_POWER_STATE, parm);
5667 snd_hda_codec_write(codec, 0x3c, 0,
5668 AC_VERB_SET_POWER_STATE, parm);
5670 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5671 snd_hda_codec_write(codec, 0x31, 0,
5672 AC_VERB_SET_POWER_STATE, parm);
5673 snd_hda_codec_write(codec, 0x17, 0,
5674 AC_VERB_SET_POWER_STATE, parm);
5675 snd_hda_codec_write(codec, 0x3b, 0,
5676 AC_VERB_SET_POWER_STATE, parm);
5679 if (imux_is_smixer || !is_aa_path_mute(codec))
5680 snd_hda_codec_write(codec, 0x21, 0,
5681 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5683 snd_hda_codec_write(codec, 0x21, 0,
5684 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5687 /* patch for vt2002P */
5688 static int patch_vt2002P(struct hda_codec *codec)
5690 struct via_spec *spec;
5693 /* create a codec specific record */
5694 spec = via_new_spec(codec);
5698 /* automatic parse from the BIOS config */
5699 err = vt2002P_parse_auto_config(codec);
5704 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5705 "from BIOS. Using genenic mode...\n");
5708 if (spec->codec_type == VT1802)
5709 spec->init_verbs[spec->num_iverbs++] =
5710 vt1802_volume_init_verbs;
5712 spec->init_verbs[spec->num_iverbs++] =
5713 vt2002P_volume_init_verbs;
5715 if (spec->codec_type == VT1802)
5716 spec->init_verbs[spec->num_iverbs++] =
5717 vt1802_uniwill_init_verbs;
5719 spec->init_verbs[spec->num_iverbs++] =
5720 vt2002P_uniwill_init_verbs;
5722 if (spec->codec_type == VT1802)
5723 spec->stream_name_analog = "VT1802 Analog";
5725 spec->stream_name_analog = "VT2002P Analog";
5726 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5727 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5729 if (spec->codec_type == VT1802)
5730 spec->stream_name_digital = "VT1802 Digital";
5732 spec->stream_name_digital = "VT2002P Digital";
5733 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5735 if (!spec->adc_nids && spec->input_mux) {
5736 spec->adc_nids = vt2002P_adc_nids;
5737 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5738 get_mux_nids(codec);
5739 override_mic_boost(codec, 0x2b, 0, 3, 40);
5740 override_mic_boost(codec, 0x29, 0, 3, 40);
5741 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5745 codec->patch_ops = via_patch_ops;
5747 codec->patch_ops.init = via_auto_init;
5748 codec->patch_ops.unsol_event = via_unsol_event;
5750 #ifdef CONFIG_SND_HDA_POWER_SAVE
5751 spec->loopback.amplist = vt2002P_loopbacks;
5754 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
5760 /* capture mixer elements */
5761 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5762 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5763 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5764 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5765 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5766 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5767 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5770 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5771 /* The multiple "Capture Source" controls confuse alsamixer
5772 * So call somewhat different..
5774 .name = "Input Source",
5776 .info = via_mux_enum_info,
5777 .get = via_mux_enum_get,
5778 .put = via_mux_enum_put,
5783 static struct hda_verb vt1812_volume_init_verbs[] = {
5785 * Unmute ADC0-1 and set the default input to mic-in
5787 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5788 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5791 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5794 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5795 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5796 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5797 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5798 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5799 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5801 /* MUX Indices: Mic = 0 */
5802 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5803 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5805 /* PW9 Output enable */
5806 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5808 /* Enable Boost Volume backdoor */
5811 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5813 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5814 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5815 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5816 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5817 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5818 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5819 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5820 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5821 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5823 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5824 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5825 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5826 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5827 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5828 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5830 /* Enable AOW0 to MW9 */
5836 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5837 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5838 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5839 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5840 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5841 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5842 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5843 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5844 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5848 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5852 .nid = 0x8, /* NID to query formats and rates */
5854 .open = via_playback_pcm_open,
5855 .prepare = via_playback_multi_pcm_prepare,
5856 .cleanup = via_playback_multi_pcm_cleanup,
5857 .close = via_pcm_open_close,
5861 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5865 .nid = 0x10, /* NID to query formats and rates */
5867 .open = via_pcm_open_close,
5868 .prepare = via_capture_pcm_prepare,
5869 .cleanup = via_capture_pcm_cleanup,
5870 .close = via_pcm_open_close,
5874 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5878 /* NID is set in via_build_pcms */
5880 .open = via_dig_playback_pcm_open,
5881 .close = via_dig_playback_pcm_close,
5882 .prepare = via_dig_playback_pcm_prepare,
5883 .cleanup = via_dig_playback_pcm_cleanup
5886 /* fill in the dac_nids table from the parsed pin configuration */
5887 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5888 const struct auto_pin_cfg *cfg)
5890 spec->multiout.num_dacs = 1;
5891 spec->multiout.dac_nids = spec->private_dac_nids;
5892 if (cfg->line_out_pins[0])
5893 spec->multiout.dac_nids[0] = 0x8;
5898 /* add playback controls from the parsed DAC table */
5899 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5900 const struct auto_pin_cfg *cfg)
5904 if (!cfg->line_out_pins[0])
5907 /* Line-Out: PortE */
5908 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5909 "Front Playback Volume",
5910 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5913 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5914 "Front Playback Switch",
5915 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5922 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5929 spec->multiout.hp_nid = 0x9;
5930 spec->hp_independent_mode_index = 1;
5933 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5934 "Headphone Playback Volume",
5935 HDA_COMPOSE_AMP_VAL(
5936 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5940 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5941 "Headphone Playback Switch",
5942 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5946 create_hp_imux(spec);
5950 /* create playback/capture controls for input pins */
5951 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5952 const struct auto_pin_cfg *cfg)
5954 struct via_spec *spec = codec->spec;
5955 struct hda_input_mux *imux = &spec->private_imux[0];
5956 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5959 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5960 ARRAY_SIZE(pin_idxs));
5964 /* build volume/mute control of loopback */
5965 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5969 /* for digital mic select */
5970 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5975 static int vt1812_parse_auto_config(struct hda_codec *codec)
5977 struct via_spec *spec = codec->spec;
5981 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5984 fill_dig_outs(codec);
5985 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5989 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5990 return 0; /* can't find valid BIOS pin config */
5992 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5995 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5998 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
6002 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6004 fill_dig_outs(codec);
6006 if (spec->kctls.list)
6007 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6009 spec->input_mux = &spec->private_imux[0];
6012 via_hp_build(codec);
6017 #ifdef CONFIG_SND_HDA_POWER_SAVE
6018 static struct hda_amp_list vt1812_loopbacks[] = {
6019 { 0x21, HDA_INPUT, 0 },
6020 { 0x21, HDA_INPUT, 1 },
6021 { 0x21, HDA_INPUT, 2 },
6026 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
6028 struct via_spec *spec = codec->spec;
6029 int imux_is_smixer =
6030 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
6032 unsigned int present;
6033 /* MUX10 (1eh) = stereo mixer */
6035 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
6037 /* PW 5/6/7 (29h/2ah/2bh) */
6039 set_pin_power_state(codec, 0x29, &parm);
6040 set_pin_power_state(codec, 0x2a, &parm);
6041 set_pin_power_state(codec, 0x2b, &parm);
6043 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
6044 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
6045 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
6046 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
6047 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
6051 snd_hda_codec_write(codec, 0x8, 0,
6052 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6054 /* PW4 (28h), MW4 (18h), MUX4(38h) */
6056 set_pin_power_state(codec, 0x28, &parm);
6057 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
6058 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6060 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6062 set_pin_power_state(codec, 0x25, &parm);
6063 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6064 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6065 if (spec->hp_independent_mode)
6066 snd_hda_codec_write(codec, 0x9, 0,
6067 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6069 /* Internal Speaker */
6070 /* PW0 (24h), MW0(14h), MUX0(34h) */
6071 present = snd_hda_jack_detect(codec, 0x25);
6074 set_pin_power_state(codec, 0x24, &parm);
6076 snd_hda_codec_write(codec, 0x14, 0,
6077 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6078 snd_hda_codec_write(codec, 0x34, 0,
6079 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6081 snd_hda_codec_write(codec, 0x14, 0,
6082 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6083 snd_hda_codec_write(codec, 0x34, 0,
6084 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6089 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6090 present = snd_hda_jack_detect(codec, 0x28);
6093 set_pin_power_state(codec, 0x31, &parm);
6095 snd_hda_codec_write(codec, 0x1c, 0,
6096 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6097 snd_hda_codec_write(codec, 0x3c, 0,
6098 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6099 snd_hda_codec_write(codec, 0x3e, 0,
6100 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6102 snd_hda_codec_write(codec, 0x1c, 0,
6103 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6104 snd_hda_codec_write(codec, 0x3c, 0,
6105 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6106 snd_hda_codec_write(codec, 0x3e, 0,
6107 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6110 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6112 set_pin_power_state(codec, 0x33, &parm);
6113 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6114 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6118 /* patch for vt1812 */
6119 static int patch_vt1812(struct hda_codec *codec)
6121 struct via_spec *spec;
6124 /* create a codec specific record */
6125 spec = via_new_spec(codec);
6129 /* automatic parse from the BIOS config */
6130 err = vt1812_parse_auto_config(codec);
6135 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6136 "from BIOS. Using genenic mode...\n");
6140 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6141 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6143 spec->stream_name_analog = "VT1812 Analog";
6144 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6145 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6147 spec->stream_name_digital = "VT1812 Digital";
6148 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6151 if (!spec->adc_nids && spec->input_mux) {
6152 spec->adc_nids = vt1812_adc_nids;
6153 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6154 get_mux_nids(codec);
6155 override_mic_boost(codec, 0x2b, 0, 3, 40);
6156 override_mic_boost(codec, 0x29, 0, 3, 40);
6157 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6161 codec->patch_ops = via_patch_ops;
6163 codec->patch_ops.init = via_auto_init;
6164 codec->patch_ops.unsol_event = via_unsol_event;
6166 #ifdef CONFIG_SND_HDA_POWER_SAVE
6167 spec->loopback.amplist = vt1812_loopbacks;
6170 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
6177 static struct hda_codec_preset snd_hda_preset_via[] = {
6178 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6179 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6180 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6181 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6182 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6183 .patch = patch_vt1709_10ch},
6184 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6185 .patch = patch_vt1709_10ch},
6186 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6187 .patch = patch_vt1709_10ch},
6188 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6189 .patch = patch_vt1709_10ch},
6190 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6191 .patch = patch_vt1709_6ch},
6192 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6193 .patch = patch_vt1709_6ch},
6194 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6195 .patch = patch_vt1709_6ch},
6196 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6197 .patch = patch_vt1709_6ch},
6198 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6199 .patch = patch_vt1708B_8ch},
6200 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6201 .patch = patch_vt1708B_8ch},
6202 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6203 .patch = patch_vt1708B_8ch},
6204 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6205 .patch = patch_vt1708B_8ch},
6206 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6207 .patch = patch_vt1708B_4ch},
6208 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6209 .patch = patch_vt1708B_4ch},
6210 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6211 .patch = patch_vt1708B_4ch},
6212 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6213 .patch = patch_vt1708B_4ch},
6214 { .id = 0x11060397, .name = "VT1708S",
6215 .patch = patch_vt1708S},
6216 { .id = 0x11061397, .name = "VT1708S",
6217 .patch = patch_vt1708S},
6218 { .id = 0x11062397, .name = "VT1708S",
6219 .patch = patch_vt1708S},
6220 { .id = 0x11063397, .name = "VT1708S",
6221 .patch = patch_vt1708S},
6222 { .id = 0x11064397, .name = "VT1705",
6223 .patch = patch_vt1708S},
6224 { .id = 0x11065397, .name = "VT1708S",
6225 .patch = patch_vt1708S},
6226 { .id = 0x11066397, .name = "VT1708S",
6227 .patch = patch_vt1708S},
6228 { .id = 0x11067397, .name = "VT1708S",
6229 .patch = patch_vt1708S},
6230 { .id = 0x11060398, .name = "VT1702",
6231 .patch = patch_vt1702},
6232 { .id = 0x11061398, .name = "VT1702",
6233 .patch = patch_vt1702},
6234 { .id = 0x11062398, .name = "VT1702",
6235 .patch = patch_vt1702},
6236 { .id = 0x11063398, .name = "VT1702",
6237 .patch = patch_vt1702},
6238 { .id = 0x11064398, .name = "VT1702",
6239 .patch = patch_vt1702},
6240 { .id = 0x11065398, .name = "VT1702",
6241 .patch = patch_vt1702},
6242 { .id = 0x11066398, .name = "VT1702",
6243 .patch = patch_vt1702},
6244 { .id = 0x11067398, .name = "VT1702",
6245 .patch = patch_vt1702},
6246 { .id = 0x11060428, .name = "VT1718S",
6247 .patch = patch_vt1718S},
6248 { .id = 0x11064428, .name = "VT1718S",
6249 .patch = patch_vt1718S},
6250 { .id = 0x11060441, .name = "VT2020",
6251 .patch = patch_vt1718S},
6252 { .id = 0x11064441, .name = "VT1828S",
6253 .patch = patch_vt1718S},
6254 { .id = 0x11060433, .name = "VT1716S",
6255 .patch = patch_vt1716S},
6256 { .id = 0x1106a721, .name = "VT1716S",
6257 .patch = patch_vt1716S},
6258 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6259 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6260 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6261 { .id = 0x11060440, .name = "VT1818S",
6262 .patch = patch_vt1708S},
6263 { .id = 0x11060446, .name = "VT1802",
6264 .patch = patch_vt2002P},
6265 { .id = 0x11068446, .name = "VT1802",
6266 .patch = patch_vt2002P},
6270 MODULE_ALIAS("snd-hda-codec-id:1106*");
6272 static struct hda_codec_preset_list via_list = {
6273 .preset = snd_hda_preset_via,
6274 .owner = THIS_MODULE,
6277 MODULE_LICENSE("GPL");
6278 MODULE_DESCRIPTION("VIA HD-audio codec");
6280 static int __init patch_via_init(void)
6282 return snd_hda_add_codec_preset(&via_list);
6285 static void __exit patch_via_exit(void)
6287 snd_hda_delete_codec_preset(&via_list);
6290 module_init(patch_via_init)
6291 module_exit(patch_via_exit)