2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
57 #define NID_MAPPING (-1)
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
64 #define VT1708_HP_NID 0x13
65 #define VT1708_DIGOUT_NID 0x14
66 #define VT1708_DIGIN_NID 0x16
67 #define VT1708_DIGIN_PIN 0x26
68 #define VT1708_HP_PIN_NID 0x20
69 #define VT1708_CD_PIN_NID 0x24
71 #define VT1709_HP_DAC_NID 0x28
72 #define VT1709_DIGOUT_NID 0x13
73 #define VT1709_DIGIN_NID 0x17
74 #define VT1709_DIGIN_PIN 0x25
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
105 #define VT2002P_COMPATIBLE(spec) \
106 ((spec)->codec_type == VT2002P ||\
107 (spec)->codec_type == VT1812 ||\
108 (spec)->codec_type == VT1802)
111 /* codec parameterization */
112 const struct snd_kcontrol_new *mixers[6];
113 unsigned int num_mixers;
115 const struct hda_verb *init_verbs[5];
116 unsigned int num_iverbs;
118 char *stream_name_analog;
119 const struct hda_pcm_stream *stream_analog_playback;
120 const struct hda_pcm_stream *stream_analog_capture;
122 char *stream_name_digital;
123 const struct hda_pcm_stream *stream_digital_playback;
124 const struct hda_pcm_stream *stream_digital_capture;
127 struct hda_multi_out multiout;
128 hda_nid_t slave_dig_outs[2];
131 unsigned int num_adc_nids;
132 const hda_nid_t *adc_nids;
133 hda_nid_t mux_nids[3];
134 hda_nid_t dig_in_nid;
135 hda_nid_t dig_in_pin;
138 const struct hda_input_mux *input_mux;
139 unsigned int cur_mux[3];
141 /* PCM information */
142 struct hda_pcm pcm_rec[3];
144 /* dynamic controls, init_verbs and input_mux */
145 struct auto_pin_cfg autocfg;
146 struct snd_array kctls;
147 struct hda_input_mux private_imux[2];
148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
151 const struct hda_input_mux *hp_mux;
152 unsigned int hp_independent_mode;
153 unsigned int hp_independent_mode_index;
154 unsigned int smart51_enabled;
155 unsigned int dmic_enabled;
156 enum VIA_HDA_CODEC codec_type;
158 /* work to check hp jack state */
159 struct hda_codec *codec;
160 struct delayed_work vt1708_hp_work;
161 int vt1708_jack_detectect;
162 int vt1708_hp_present;
164 void (*set_widgets_power_state)(struct hda_codec *codec);
166 #ifdef CONFIG_SND_HDA_POWER_SAVE
167 struct hda_loopback_check loopback;
171 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
172 static struct via_spec * via_new_spec(struct hda_codec *codec)
174 struct via_spec *spec;
176 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
182 spec->codec_type = get_codec_type(codec);
183 /* VT1708BCE & VT1708S are almost same */
184 if (spec->codec_type == VT1708BCE)
185 spec->codec_type = VT1708S;
189 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
191 u32 vendor_id = codec->vendor_id;
192 u16 ven_id = vendor_id >> 16;
193 u16 dev_id = vendor_id & 0xffff;
194 enum VIA_HDA_CODEC codec_type;
197 if (ven_id != 0x1106)
198 codec_type = UNKNOWN;
199 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
201 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
202 codec_type = VT1709_10CH;
203 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
204 codec_type = VT1709_6CH;
205 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
206 codec_type = VT1708B_8CH;
207 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
208 codec_type = VT1708BCE;
209 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
210 codec_type = VT1708B_4CH;
211 else if ((dev_id & 0xfff) == 0x397
212 && (dev_id >> 12) < 8)
213 codec_type = VT1708S;
214 else if ((dev_id & 0xfff) == 0x398
215 && (dev_id >> 12) < 8)
217 else if ((dev_id & 0xfff) == 0x428
218 && (dev_id >> 12) < 8)
219 codec_type = VT1718S;
220 else if (dev_id == 0x0433 || dev_id == 0xa721)
221 codec_type = VT1716S;
222 else if (dev_id == 0x0441 || dev_id == 0x4441)
223 codec_type = VT1718S;
224 else if (dev_id == 0x0438 || dev_id == 0x4438)
225 codec_type = VT2002P;
226 else if (dev_id == 0x0448)
228 else if (dev_id == 0x0440)
229 codec_type = VT1708S;
230 else if ((dev_id & 0xfff) == 0x446)
233 codec_type = UNKNOWN;
237 #define VIA_JACK_EVENT 0x20
238 #define VIA_HP_EVENT 0x01
239 #define VIA_GPIO_EVENT 0x02
240 #define VIA_MONO_EVENT 0x03
241 #define VIA_SPEAKER_EVENT 0x04
242 #define VIA_BIND_HP_EVENT 0x05
247 VIA_CTL_WIDGET_ANALOG_MUTE,
248 VIA_CTL_WIDGET_BIND_PIN_MUTE,
258 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
259 static int is_aa_path_mute(struct hda_codec *codec);
261 static void vt1708_start_hp_work(struct via_spec *spec)
263 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
265 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
266 !spec->vt1708_jack_detectect);
267 if (!delayed_work_pending(&spec->vt1708_hp_work))
268 schedule_delayed_work(&spec->vt1708_hp_work,
269 msecs_to_jiffies(100));
272 static void vt1708_stop_hp_work(struct via_spec *spec)
274 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
276 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
277 && !is_aa_path_mute(spec->codec))
279 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
280 !spec->vt1708_jack_detectect);
281 cancel_delayed_work_sync(&spec->vt1708_hp_work);
284 static void set_widgets_power_state(struct hda_codec *codec)
286 struct via_spec *spec = codec->spec;
287 if (spec->set_widgets_power_state)
288 spec->set_widgets_power_state(codec);
291 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
292 struct snd_ctl_elem_value *ucontrol)
294 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
297 set_widgets_power_state(codec);
298 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
299 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
300 if (is_aa_path_mute(codec))
301 vt1708_start_hp_work(codec->spec);
303 vt1708_stop_hp_work(codec->spec);
308 /* modify .put = snd_hda_mixer_amp_switch_put */
309 #define ANALOG_INPUT_MUTE \
310 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
313 .info = snd_hda_mixer_amp_switch_info, \
314 .get = snd_hda_mixer_amp_switch_get, \
315 .put = analog_input_switch_put, \
316 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
318 static void via_hp_bind_automute(struct hda_codec *codec);
320 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
321 struct snd_ctl_elem_value *ucontrol)
323 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
324 struct via_spec *spec = codec->spec;
328 long *valp = ucontrol->value.integer.value;
330 if (strstr(kcontrol->id.name, "Switch") == NULL) {
331 snd_printd("Invalid control!\n");
334 change = snd_hda_mixer_amp_switch_put(kcontrol,
337 lmute = *valp ? 0 : HDA_AMP_MUTE;
339 rmute = *valp ? 0 : HDA_AMP_MUTE;
342 if (!spec->hp_independent_mode) {
343 for (i = 0; i < spec->autocfg.hp_outs; i++) {
344 snd_hda_codec_amp_update(
345 codec, spec->autocfg.hp_pins[i],
346 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
348 snd_hda_codec_amp_update(
349 codec, spec->autocfg.hp_pins[i],
350 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
355 if (!lmute && !rmute) {
357 for (i = 0; i < spec->autocfg.line_outs; i++)
358 snd_hda_codec_amp_stereo(
359 codec, spec->autocfg.line_out_pins[i],
360 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
362 for (i = 0; i < spec->autocfg.speaker_outs; i++)
363 snd_hda_codec_amp_stereo(
364 codec, spec->autocfg.speaker_pins[i],
365 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
367 via_hp_bind_automute(codec);
371 /* Mute all left channels */
372 for (i = 1; i < spec->autocfg.line_outs; i++)
373 snd_hda_codec_amp_update(
375 spec->autocfg.line_out_pins[i],
376 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
378 for (i = 0; i < spec->autocfg.speaker_outs; i++)
379 snd_hda_codec_amp_update(
381 spec->autocfg.speaker_pins[i],
382 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
386 /* mute all right channels */
387 for (i = 1; i < spec->autocfg.line_outs; i++)
388 snd_hda_codec_amp_update(
390 spec->autocfg.line_out_pins[i],
391 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
393 for (i = 0; i < spec->autocfg.speaker_outs; i++)
394 snd_hda_codec_amp_update(
396 spec->autocfg.speaker_pins[i],
397 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
404 #define BIND_PIN_MUTE \
405 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
408 .info = snd_hda_mixer_amp_switch_info, \
409 .get = snd_hda_mixer_amp_switch_get, \
410 .put = bind_pin_switch_put, \
411 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
413 static const struct snd_kcontrol_new via_control_templates[] = {
414 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
415 HDA_CODEC_MUTE(NULL, 0, 0, 0),
420 static const hda_nid_t vt1708_adc_nids[2] = {
425 static const hda_nid_t vt1709_adc_nids[3] = {
430 static const hda_nid_t vt1708B_adc_nids[2] = {
435 static const hda_nid_t vt1708S_adc_nids[2] = {
440 static const hda_nid_t vt1702_adc_nids[3] = {
445 static const hda_nid_t vt1718S_adc_nids[2] = {
450 static const hda_nid_t vt1716S_adc_nids[2] = {
455 static const hda_nid_t vt2002P_adc_nids[2] = {
460 static const hda_nid_t vt1812_adc_nids[2] = {
466 /* add dynamic controls */
467 static int __via_add_control(struct via_spec *spec, int type, const char *name,
468 int idx, unsigned long val)
470 struct snd_kcontrol_new *knew;
472 snd_array_init(&spec->kctls, sizeof(*knew), 32);
473 knew = snd_array_new(&spec->kctls);
476 *knew = via_control_templates[type];
477 knew->name = kstrdup(name, GFP_KERNEL);
480 if (get_amp_nid_(val))
481 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
482 knew->private_value = val;
486 #define via_add_control(spec, type, name, val) \
487 __via_add_control(spec, type, name, 0, val)
489 static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
490 const struct snd_kcontrol_new *tmpl)
492 struct snd_kcontrol_new *knew;
494 snd_array_init(&spec->kctls, sizeof(*knew), 32);
495 knew = snd_array_new(&spec->kctls);
499 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
505 static void via_free_kctls(struct hda_codec *codec)
507 struct via_spec *spec = codec->spec;
509 if (spec->kctls.list) {
510 struct snd_kcontrol_new *kctl = spec->kctls.list;
512 for (i = 0; i < spec->kctls.used; i++)
515 snd_array_free(&spec->kctls);
518 /* create input playback/capture controls for the given pin */
519 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
520 int type_idx, int idx, int mix_nid)
525 sprintf(name, "%s Playback Volume", ctlname);
526 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
527 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
530 sprintf(name, "%s Playback Switch", ctlname);
531 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
532 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
538 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
539 hda_nid_t nid, int pin_type,
543 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
545 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
547 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
548 snd_hda_codec_write(codec, nid, 0,
549 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
553 static void via_auto_init_multi_out(struct hda_codec *codec)
555 struct via_spec *spec = codec->spec;
558 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
559 hda_nid_t nid = spec->autocfg.line_out_pins[i];
561 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
565 static void via_auto_init_hp_out(struct hda_codec *codec)
567 struct via_spec *spec = codec->spec;
571 for (i = 0; i < spec->autocfg.hp_outs; i++) {
572 pin = spec->autocfg.hp_pins[i];
573 if (pin) /* connect to front */
574 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
578 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
580 static void via_auto_init_analog_input(struct hda_codec *codec)
582 struct via_spec *spec = codec->spec;
583 const struct auto_pin_cfg *cfg = &spec->autocfg;
587 for (i = 0; i < cfg->num_inputs; i++) {
588 hda_nid_t nid = cfg->inputs[i].pin;
589 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
591 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
595 snd_hda_codec_write(codec, nid, 0,
596 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
600 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
601 unsigned int *affected_parm)
604 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
605 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
606 >> AC_DEFCFG_MISC_SHIFT
607 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
608 unsigned present = snd_hda_jack_detect(codec, nid);
609 struct via_spec *spec = codec->spec;
610 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
611 || ((no_presence || present)
612 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
613 *affected_parm = AC_PWRST_D0; /* if it's connected */
618 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
624 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_info *uinfo)
627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628 struct via_spec *spec = codec->spec;
629 return snd_hda_input_mux_info(spec->input_mux, uinfo);
632 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct via_spec *spec = codec->spec;
637 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
639 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
643 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct via_spec *spec = codec->spec;
648 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
651 if (!spec->mux_nids[adc_idx])
653 /* switch to D0 beofre change index */
654 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
655 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
656 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
657 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
659 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
660 spec->mux_nids[adc_idx],
661 &spec->cur_mux[adc_idx]);
662 /* update jack power state */
663 set_widgets_power_state(codec);
668 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
669 struct snd_ctl_elem_info *uinfo)
671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
672 struct via_spec *spec = codec->spec;
673 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
676 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
680 hda_nid_t nid = kcontrol->private_value;
683 /* use !! to translate conn sel 2 for VT1718S */
684 pinsel = !!snd_hda_codec_read(codec, nid, 0,
685 AC_VERB_GET_CONNECT_SEL,
687 ucontrol->value.enumerated.item[0] = pinsel;
692 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
694 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
696 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
697 ctl->vd[0].access |= active
698 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
699 snd_ctl_notify(codec->bus->card,
700 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
704 static hda_nid_t side_mute_channel(struct via_spec *spec)
706 switch (spec->codec_type) {
707 case VT1708: return 0x1b;
708 case VT1709_10CH: return 0x29;
709 case VT1708B_8CH: /* fall thru */
710 case VT1708S: return 0x27;
711 case VT2002P: return 0x19;
712 case VT1802: return 0x15;
713 case VT1812: return 0x15;
718 static int update_side_mute_status(struct hda_codec *codec)
720 /* mute side channel */
721 struct via_spec *spec = codec->spec;
723 hda_nid_t sw3 = side_mute_channel(spec);
726 if (VT2002P_COMPATIBLE(spec))
727 parm = spec->hp_independent_mode ?
728 AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1);
730 parm = spec->hp_independent_mode ?
731 AMP_OUT_MUTE : AMP_OUT_UNMUTE;
732 snd_hda_codec_write(codec, sw3, 0,
733 AC_VERB_SET_AMP_GAIN_MUTE, parm);
734 if (spec->codec_type == VT1812)
735 snd_hda_codec_write(codec, 0x1d, 0,
736 AC_VERB_SET_AMP_GAIN_MUTE, parm);
741 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
742 struct snd_ctl_elem_value *ucontrol)
744 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745 struct via_spec *spec = codec->spec;
746 hda_nid_t nid = kcontrol->private_value;
747 unsigned int pinsel = ucontrol->value.enumerated.item[0];
748 /* 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 const 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", "Rear Mic"};
848 struct snd_kcontrol *ctl;
850 memset(&id, 0, sizeof(id));
851 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
852 for (i = 0; i < ARRAY_SIZE(labels); i++) {
853 sprintf(id.name, "%s Playback Volume", labels[i]);
854 ctl = snd_hda_find_mixer_ctl(codec, id.name);
856 snd_ctl_notify(codec->bus->card,
857 SNDRV_CTL_EVENT_MASK_VALUE,
862 static void mute_aa_path(struct hda_codec *codec, int mute)
864 struct via_spec *spec = codec->spec;
869 /* get nid of MW0 and start & end index */
870 switch (spec->codec_type) {
898 /* check AA path's mute status */
899 for (i = start_idx; i <= end_idx; i++) {
900 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
901 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
905 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
907 const struct auto_pin_cfg *cfg = &spec->autocfg;
910 for (i = 0; i < cfg->num_inputs; i++) {
911 if (pin == cfg->inputs[i].pin)
912 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
917 static int via_smart51_info(struct snd_kcontrol *kcontrol,
918 struct snd_ctl_elem_info *uinfo)
920 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
922 uinfo->value.integer.min = 0;
923 uinfo->value.integer.max = 1;
927 static int via_smart51_get(struct snd_kcontrol *kcontrol,
928 struct snd_ctl_elem_value *ucontrol)
930 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
931 struct via_spec *spec = codec->spec;
932 const struct auto_pin_cfg *cfg = &spec->autocfg;
936 for (i = 0; i < cfg->num_inputs; i++) {
937 hda_nid_t nid = cfg->inputs[i].pin;
938 int ctl = snd_hda_codec_read(codec, nid, 0,
939 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
940 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
942 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
943 spec->hp_independent_mode && spec->codec_type != VT1718S)
944 continue; /* ignore FMic for independent HP */
945 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
948 *ucontrol->value.integer.value = on;
952 static int via_smart51_put(struct snd_kcontrol *kcontrol,
953 struct snd_ctl_elem_value *ucontrol)
955 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
956 struct via_spec *spec = codec->spec;
957 const struct auto_pin_cfg *cfg = &spec->autocfg;
958 int out_in = *ucontrol->value.integer.value
959 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
962 for (i = 0; i < cfg->num_inputs; i++) {
963 hda_nid_t nid = cfg->inputs[i].pin;
966 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
968 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
969 spec->hp_independent_mode && spec->codec_type != VT1718S)
970 continue; /* don't retask FMic for independent HP */
972 parm = snd_hda_codec_read(codec, nid, 0,
973 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
974 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
976 snd_hda_codec_write(codec, nid, 0,
977 AC_VERB_SET_PIN_WIDGET_CONTROL,
979 if (out_in == AC_PINCTL_OUT_EN) {
980 mute_aa_path(codec, 1);
981 notify_aa_path_ctls(codec);
983 if (spec->codec_type == VT1718S) {
984 snd_hda_codec_amp_stereo(
985 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
988 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
989 if (spec->codec_type == VT1708S
990 || spec->codec_type == VT1716S) {
991 /* input = index 1 (AOW3) */
994 AC_VERB_SET_CONNECT_SEL, 1);
995 snd_hda_codec_amp_stereo(
996 codec, nid, HDA_OUTPUT,
997 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1001 spec->smart51_enabled = *ucontrol->value.integer.value;
1002 set_widgets_power_state(codec);
1006 static const struct snd_kcontrol_new via_smart51_mixer[2] = {
1008 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1009 .name = "Smart 5.1",
1011 .info = via_smart51_info,
1012 .get = via_smart51_get,
1013 .put = via_smart51_put,
1016 .iface = NID_MAPPING,
1017 .name = "Smart 5.1",
1021 static int via_smart51_build(struct via_spec *spec)
1023 struct snd_kcontrol_new *knew;
1024 const struct auto_pin_cfg *cfg = &spec->autocfg;
1030 if (cfg->line_outs > 2)
1033 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1037 for (i = 0; i < cfg->num_inputs; i++) {
1038 nid = cfg->inputs[i].pin;
1039 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1040 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1043 knew->subdevice = nid;
1051 /* capture mixer elements */
1052 static const struct snd_kcontrol_new vt1708_capture_mixer[] = {
1053 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1054 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1055 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1056 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1058 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1059 /* The multiple "Capture Source" controls confuse alsamixer
1060 * So call somewhat different..
1062 /* .name = "Capture Source", */
1063 .name = "Input Source",
1065 .info = via_mux_enum_info,
1066 .get = via_mux_enum_get,
1067 .put = via_mux_enum_put,
1072 /* check AA path's mute statue */
1073 static int is_aa_path_mute(struct hda_codec *codec)
1076 hda_nid_t nid_mixer;
1080 struct via_spec *spec = codec->spec;
1081 /* get nid of MW0 and start & end index */
1082 switch (spec->codec_type) {
1111 /* check AA path's mute status */
1112 for (i = start_idx; i <= end_idx; i++) {
1113 unsigned int con_list = snd_hda_codec_read(
1114 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1115 int shift = 8 * (i % 4);
1116 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1117 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1118 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1119 /* check mute status while the pin is connected */
1120 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1122 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1124 if (!mute_l || !mute_r) {
1133 /* enter/exit analog low-current mode */
1134 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1136 struct via_spec *spec = codec->spec;
1137 static int saved_stream_idle = 1; /* saved stream idle status */
1138 int enable = is_aa_path_mute(codec);
1139 unsigned int verb = 0;
1140 unsigned int parm = 0;
1142 if (stream_idle == -1) /* stream status did not change */
1143 enable = enable && saved_stream_idle;
1145 enable = enable && stream_idle;
1146 saved_stream_idle = stream_idle;
1149 /* decide low current mode's verb & parameter */
1150 switch (spec->codec_type) {
1154 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1160 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1164 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1170 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1173 return; /* other codecs are not supported */
1176 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1180 * generic initialization of ADC, input mixers and output mixers
1182 static const struct hda_verb vt1708_volume_init_verbs[] = {
1184 * Unmute ADC0-1 and set the default input to mic-in
1186 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1187 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1190 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1193 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1194 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1195 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1196 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1197 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1198 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1201 * Set up output mixers (0x19 - 0x1b)
1203 /* set vol=0 to output mixers */
1204 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1205 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1206 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1208 /* Setup default input MW0 to PW4 */
1209 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1210 /* PW9 Output enable */
1211 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1212 /* power down jack detect function */
1217 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1218 struct hda_codec *codec,
1219 struct snd_pcm_substream *substream)
1221 struct via_spec *spec = codec->spec;
1222 int idle = substream->pstr->substream_opened == 1
1223 && substream->ref_count == 0;
1224 analog_low_current_mode(codec, idle);
1225 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1229 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1230 unsigned int stream_tag,
1231 unsigned int format,
1232 struct snd_pcm_substream *substream)
1234 struct via_spec *spec = codec->spec;
1235 struct hda_multi_out *mout = &spec->multiout;
1236 const hda_nid_t *nids = mout->dac_nids;
1237 int chs = substream->runtime->channels;
1240 mutex_lock(&codec->spdif_mutex);
1241 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1243 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1245 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1246 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1247 /* turn off SPDIF once; otherwise the IEC958 bits won't
1249 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1250 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1251 AC_VERB_SET_DIGI_CONVERT_1,
1253 ~AC_DIG1_ENABLE & 0xff);
1254 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1255 stream_tag, 0, format);
1256 /* turn on again (if needed) */
1257 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1258 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1259 AC_VERB_SET_DIGI_CONVERT_1,
1260 codec->spdif_ctls & 0xff);
1262 mout->dig_out_used = 0;
1263 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1267 mutex_unlock(&codec->spdif_mutex);
1270 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1273 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1274 && !spec->hp_independent_mode)
1275 /* headphone out will just decode front left/right (stereo) */
1276 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1279 /* extra outputs copied from front */
1280 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1281 if (mout->extra_out_nid[i])
1282 snd_hda_codec_setup_stream(codec,
1283 mout->extra_out_nid[i],
1284 stream_tag, 0, format);
1287 for (i = 1; i < mout->num_dacs; i++) {
1288 if (chs >= (i + 1) * 2) /* independent out */
1289 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1291 else /* copy front */
1292 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1297 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1298 struct hda_codec *codec,
1299 unsigned int stream_tag,
1300 unsigned int format,
1301 struct snd_pcm_substream *substream)
1303 struct via_spec *spec = codec->spec;
1304 struct hda_multi_out *mout = &spec->multiout;
1305 const hda_nid_t *nids = mout->dac_nids;
1307 if (substream->number == 0)
1308 playback_multi_pcm_prep_0(codec, stream_tag, format,
1311 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1312 spec->hp_independent_mode)
1313 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1314 stream_tag, 0, format);
1316 vt1708_start_hp_work(spec);
1320 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1321 struct hda_codec *codec,
1322 struct snd_pcm_substream *substream)
1324 struct via_spec *spec = codec->spec;
1325 struct hda_multi_out *mout = &spec->multiout;
1326 const hda_nid_t *nids = mout->dac_nids;
1329 if (substream->number == 0) {
1330 for (i = 0; i < mout->num_dacs; i++)
1331 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1333 if (mout->hp_nid && !spec->hp_independent_mode)
1334 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1337 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1338 if (mout->extra_out_nid[i])
1339 snd_hda_codec_setup_stream(codec,
1340 mout->extra_out_nid[i],
1342 mutex_lock(&codec->spdif_mutex);
1343 if (mout->dig_out_nid &&
1344 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1345 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1347 mout->dig_out_used = 0;
1349 mutex_unlock(&codec->spdif_mutex);
1351 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1352 spec->hp_independent_mode)
1353 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1356 vt1708_stop_hp_work(spec);
1363 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1364 struct hda_codec *codec,
1365 struct snd_pcm_substream *substream)
1367 struct via_spec *spec = codec->spec;
1368 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1371 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1372 struct hda_codec *codec,
1373 struct snd_pcm_substream *substream)
1375 struct via_spec *spec = codec->spec;
1376 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1379 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1380 struct hda_codec *codec,
1381 unsigned int stream_tag,
1382 unsigned int format,
1383 struct snd_pcm_substream *substream)
1385 struct via_spec *spec = codec->spec;
1386 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1387 stream_tag, format, substream);
1390 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1391 struct hda_codec *codec,
1392 struct snd_pcm_substream *substream)
1394 struct via_spec *spec = codec->spec;
1395 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1402 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1403 struct hda_codec *codec,
1404 unsigned int stream_tag,
1405 unsigned int format,
1406 struct snd_pcm_substream *substream)
1408 struct via_spec *spec = codec->spec;
1410 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1411 stream_tag, 0, format);
1415 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1416 struct hda_codec *codec,
1417 struct snd_pcm_substream *substream)
1419 struct via_spec *spec = codec->spec;
1420 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1424 static const struct hda_pcm_stream vt1708_pcm_analog_playback = {
1428 .nid = 0x10, /* NID to query formats and rates */
1430 .open = via_playback_pcm_open,
1431 .prepare = via_playback_multi_pcm_prepare,
1432 .cleanup = via_playback_multi_pcm_cleanup
1436 static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1440 .nid = 0x10, /* NID to query formats and rates */
1441 /* We got noisy outputs on the right channel on VT1708 when
1442 * 24bit samples are used. Until any workaround is found,
1443 * disable the 24bit format, so far.
1445 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1447 .open = via_playback_pcm_open,
1448 .prepare = via_playback_multi_pcm_prepare,
1449 .cleanup = via_playback_multi_pcm_cleanup
1453 static const struct hda_pcm_stream vt1708_pcm_analog_capture = {
1457 .nid = 0x15, /* NID to query formats and rates */
1459 .prepare = via_capture_pcm_prepare,
1460 .cleanup = via_capture_pcm_cleanup
1464 static const struct hda_pcm_stream vt1708_pcm_digital_playback = {
1468 /* NID is set in via_build_pcms */
1470 .open = via_dig_playback_pcm_open,
1471 .close = via_dig_playback_pcm_close,
1472 .prepare = via_dig_playback_pcm_prepare,
1473 .cleanup = via_dig_playback_pcm_cleanup
1477 static const struct hda_pcm_stream vt1708_pcm_digital_capture = {
1483 static int via_build_controls(struct hda_codec *codec)
1485 struct via_spec *spec = codec->spec;
1486 struct snd_kcontrol *kctl;
1487 const struct snd_kcontrol_new *knew;
1490 for (i = 0; i < spec->num_mixers; i++) {
1491 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1496 if (spec->multiout.dig_out_nid) {
1497 err = snd_hda_create_spdif_out_ctls(codec,
1498 spec->multiout.dig_out_nid);
1501 err = snd_hda_create_spdif_share_sw(codec,
1505 spec->multiout.share_spdif = 1;
1507 if (spec->dig_in_nid) {
1508 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1513 /* assign Capture Source enums to NID */
1514 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1515 for (i = 0; kctl && i < kctl->count; i++) {
1516 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1521 /* other nid->control mapping */
1522 for (i = 0; i < spec->num_mixers; i++) {
1523 for (knew = spec->mixers[i]; knew->name; knew++) {
1524 if (knew->iface != NID_MAPPING)
1526 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1529 err = snd_hda_add_nid(codec, kctl, 0,
1534 /* init power states */
1535 set_widgets_power_state(codec);
1536 analog_low_current_mode(codec, 1);
1538 via_free_kctls(codec); /* no longer needed */
1542 static int via_build_pcms(struct hda_codec *codec)
1544 struct via_spec *spec = codec->spec;
1545 struct hda_pcm *info = spec->pcm_rec;
1547 codec->num_pcms = 1;
1548 codec->pcm_info = info;
1550 info->name = spec->stream_name_analog;
1551 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1552 *(spec->stream_analog_playback);
1553 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1554 spec->multiout.dac_nids[0];
1555 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1556 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1558 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1559 spec->multiout.max_channels;
1561 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1564 info->name = spec->stream_name_digital;
1565 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1566 if (spec->multiout.dig_out_nid) {
1567 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1568 *(spec->stream_digital_playback);
1569 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1570 spec->multiout.dig_out_nid;
1572 if (spec->dig_in_nid) {
1573 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1574 *(spec->stream_digital_capture);
1575 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1583 static void via_free(struct hda_codec *codec)
1585 struct via_spec *spec = codec->spec;
1590 via_free_kctls(codec);
1591 vt1708_stop_hp_work(spec);
1595 /* mute internal speaker if HP is plugged */
1596 static void via_hp_automute(struct hda_codec *codec)
1598 unsigned int present = 0;
1599 struct via_spec *spec = codec->spec;
1601 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1603 if (!spec->hp_independent_mode) {
1604 struct snd_ctl_elem_id id;
1606 snd_hda_codec_amp_stereo(
1607 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1608 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1610 memset(&id, 0, sizeof(id));
1611 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1612 strcpy(id.name, "Front Playback Switch");
1613 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1618 /* mute mono out if HP or Line out is plugged */
1619 static void via_mono_automute(struct hda_codec *codec)
1621 unsigned int hp_present, lineout_present;
1622 struct via_spec *spec = codec->spec;
1624 if (spec->codec_type != VT1716S)
1627 lineout_present = snd_hda_jack_detect(codec,
1628 spec->autocfg.line_out_pins[0]);
1630 /* Mute Mono Out if Line Out is plugged */
1631 if (lineout_present) {
1632 snd_hda_codec_amp_stereo(
1633 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1637 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1639 if (!spec->hp_independent_mode)
1640 snd_hda_codec_amp_stereo(
1641 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1642 hp_present ? HDA_AMP_MUTE : 0);
1645 static void via_gpio_control(struct hda_codec *codec)
1647 unsigned int gpio_data;
1648 unsigned int vol_counter;
1650 unsigned int master_vol;
1652 struct via_spec *spec = codec->spec;
1654 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1655 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1657 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1658 0xF84, 0) & 0x3F0000) >> 16;
1660 vol = vol_counter & 0x1F;
1661 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1662 AC_VERB_GET_AMP_GAIN_MUTE,
1665 if (gpio_data == 0x02) {
1666 /* unmute line out */
1667 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1668 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1670 if (vol_counter & 0x20) {
1671 /* decrease volume */
1672 if (vol > master_vol)
1674 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1678 /* increase volume */
1679 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1681 ((master_vol+vol) > 0x2A) ? 0x2A :
1684 } else if (!(gpio_data & 0x02)) {
1686 snd_hda_codec_amp_stereo(codec,
1687 spec->autocfg.line_out_pins[0],
1688 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1693 /* mute Internal-Speaker if HP is plugged */
1694 static void via_speaker_automute(struct hda_codec *codec)
1696 unsigned int hp_present;
1697 struct via_spec *spec = codec->spec;
1699 if (!VT2002P_COMPATIBLE(spec))
1702 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1704 if (!spec->hp_independent_mode) {
1705 struct snd_ctl_elem_id id;
1706 snd_hda_codec_amp_stereo(
1707 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
1708 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1710 memset(&id, 0, sizeof(id));
1711 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1712 strcpy(id.name, "Speaker Playback Switch");
1713 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1718 /* mute line-out and internal speaker if HP is plugged */
1719 static void via_hp_bind_automute(struct hda_codec *codec)
1721 /* use long instead of int below just to avoid an internal compiler
1722 * error with gcc 4.0.x
1724 unsigned long hp_present, present = 0;
1725 struct via_spec *spec = codec->spec;
1728 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
1731 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1733 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
1735 if (!spec->hp_independent_mode) {
1736 /* Mute Line-Outs */
1737 for (i = 0; i < spec->autocfg.line_outs; i++)
1738 snd_hda_codec_amp_stereo(
1739 codec, spec->autocfg.line_out_pins[i],
1741 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
1743 present = hp_present;
1746 for (i = 0; i < spec->autocfg.speaker_outs; i++)
1747 snd_hda_codec_amp_stereo(
1748 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
1749 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1753 /* unsolicited event for jack sensing */
1754 static void via_unsol_event(struct hda_codec *codec,
1759 if (res & VIA_JACK_EVENT)
1760 set_widgets_power_state(codec);
1762 res &= ~VIA_JACK_EVENT;
1764 if (res == VIA_HP_EVENT)
1765 via_hp_automute(codec);
1766 else if (res == VIA_GPIO_EVENT)
1767 via_gpio_control(codec);
1768 else if (res == VIA_MONO_EVENT)
1769 via_mono_automute(codec);
1770 else if (res == VIA_SPEAKER_EVENT)
1771 via_speaker_automute(codec);
1772 else if (res == VIA_BIND_HP_EVENT)
1773 via_hp_bind_automute(codec);
1776 static int via_init(struct hda_codec *codec)
1778 struct via_spec *spec = codec->spec;
1780 for (i = 0; i < spec->num_iverbs; i++)
1781 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1783 /* Lydia Add for EAPD enable */
1784 if (!spec->dig_in_nid) { /* No Digital In connection */
1785 if (spec->dig_in_pin) {
1786 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1787 AC_VERB_SET_PIN_WIDGET_CONTROL,
1789 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1790 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1792 } else /* enable SPDIF-input pin */
1793 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1794 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1796 /* assign slave outs */
1797 if (spec->slave_dig_outs[0])
1798 codec->slave_dig_outs = spec->slave_dig_outs;
1803 #ifdef SND_HDA_NEEDS_RESUME
1804 static int via_suspend(struct hda_codec *codec, pm_message_t state)
1806 struct via_spec *spec = codec->spec;
1807 vt1708_stop_hp_work(spec);
1812 #ifdef CONFIG_SND_HDA_POWER_SAVE
1813 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1815 struct via_spec *spec = codec->spec;
1816 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1822 static const struct hda_codec_ops via_patch_ops = {
1823 .build_controls = via_build_controls,
1824 .build_pcms = via_build_pcms,
1827 #ifdef SND_HDA_NEEDS_RESUME
1828 .suspend = via_suspend,
1830 #ifdef CONFIG_SND_HDA_POWER_SAVE
1831 .check_power_status = via_check_power_status,
1835 /* fill in the dac_nids table from the parsed pin configuration */
1836 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1837 const struct auto_pin_cfg *cfg)
1842 spec->multiout.num_dacs = cfg->line_outs;
1844 spec->multiout.dac_nids = spec->private_dac_nids;
1846 for (i = 0; i < 4; i++) {
1847 nid = cfg->line_out_pins[i];
1849 /* config dac list */
1851 case AUTO_SEQ_FRONT:
1852 spec->private_dac_nids[i] = 0x10;
1854 case AUTO_SEQ_CENLFE:
1855 spec->private_dac_nids[i] = 0x12;
1857 case AUTO_SEQ_SURROUND:
1858 spec->private_dac_nids[i] = 0x11;
1861 spec->private_dac_nids[i] = 0x13;
1870 /* add playback controls from the parsed DAC table */
1871 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1872 const struct auto_pin_cfg *cfg)
1875 static const char * const chname[4] = {
1876 "Front", "Surround", "C/LFE", "Side"
1878 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
1881 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1882 nid = cfg->line_out_pins[i];
1887 nid_vol = nid_vols[i];
1889 if (i == AUTO_SEQ_CENLFE) {
1891 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1892 "Center Playback Volume",
1893 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1897 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1898 "LFE Playback Volume",
1899 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1903 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1904 "Center Playback Switch",
1905 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1909 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1910 "LFE Playback Switch",
1911 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1915 } else if (i == AUTO_SEQ_FRONT) {
1916 /* add control to mixer index 0 */
1917 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1918 "Master Front Playback Volume",
1919 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1923 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1924 "Master Front Playback Switch",
1925 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1930 /* add control to PW3 */
1931 sprintf(name, "%s Playback Volume", chname[i]);
1932 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1933 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1937 sprintf(name, "%s Playback Switch", chname[i]);
1938 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1939 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1944 sprintf(name, "%s Playback Volume", chname[i]);
1945 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1946 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1950 sprintf(name, "%s Playback Switch", chname[i]);
1951 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1952 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1962 static void create_hp_imux(struct via_spec *spec)
1965 struct hda_input_mux *imux = &spec->private_imux[1];
1966 static const char * const texts[] = { "OFF", "ON", NULL};
1968 /* for hp mode select */
1969 for (i = 0; texts[i]; i++)
1970 snd_hda_add_imux_item(imux, texts[i], i, NULL);
1972 spec->hp_mux = &spec->private_imux[1];
1975 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1982 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1983 spec->hp_independent_mode_index = 1;
1985 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1986 "Headphone Playback Volume",
1987 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1990 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1991 "Headphone Playback Switch",
1992 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1996 create_hp_imux(spec);
2001 /* create playback/capture controls for input pins */
2002 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2003 const struct auto_pin_cfg *cfg,
2005 const hda_nid_t pin_idxs[],
2008 struct via_spec *spec = codec->spec;
2009 struct hda_input_mux *imux = &spec->private_imux[0];
2010 int i, err, idx, type, type_idx = 0;
2012 /* for internal loopback recording select */
2013 for (idx = 0; idx < num_idxs; idx++) {
2014 if (pin_idxs[idx] == 0xff) {
2015 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2020 for (i = 0; i < cfg->num_inputs; i++) {
2022 type = cfg->inputs[i].type;
2023 for (idx = 0; idx < num_idxs; idx++)
2024 if (pin_idxs[idx] == cfg->inputs[i].pin)
2026 if (idx >= num_idxs)
2028 if (i > 0 && type == cfg->inputs[i - 1].type)
2032 label = hda_get_autocfg_input_label(codec, cfg, i);
2033 if (spec->codec_type == VT1708S ||
2034 spec->codec_type == VT1702 ||
2035 spec->codec_type == VT1716S)
2036 err = via_new_analog_input(spec, label, type_idx,
2039 err = via_new_analog_input(spec, label, type_idx,
2043 snd_hda_add_imux_item(imux, label, idx, NULL);
2048 /* create playback/capture controls for input pins */
2049 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2050 const struct auto_pin_cfg *cfg)
2052 static const hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2053 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2054 ARRAY_SIZE(pin_idxs));
2057 #ifdef CONFIG_SND_HDA_POWER_SAVE
2058 static const struct hda_amp_list vt1708_loopbacks[] = {
2059 { 0x17, HDA_INPUT, 1 },
2060 { 0x17, HDA_INPUT, 2 },
2061 { 0x17, HDA_INPUT, 3 },
2062 { 0x17, HDA_INPUT, 4 },
2067 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2069 unsigned int def_conf;
2070 unsigned char seqassoc;
2072 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2073 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2074 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2075 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2076 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2077 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2078 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2084 static int vt1708_jack_detectect_get(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;
2090 if (spec->codec_type != VT1708)
2092 spec->vt1708_jack_detectect =
2093 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2094 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2098 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2099 struct snd_ctl_elem_value *ucontrol)
2101 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2102 struct via_spec *spec = codec->spec;
2105 if (spec->codec_type != VT1708)
2107 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2108 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2109 == !spec->vt1708_jack_detectect;
2110 if (spec->vt1708_jack_detectect) {
2111 mute_aa_path(codec, 1);
2112 notify_aa_path_ctls(codec);
2117 static const struct snd_kcontrol_new vt1708_jack_detectect[] = {
2119 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2120 .name = "Jack Detect",
2122 .info = snd_ctl_boolean_mono_info,
2123 .get = vt1708_jack_detectect_get,
2124 .put = vt1708_jack_detectect_put,
2129 static int vt1708_parse_auto_config(struct hda_codec *codec)
2131 struct via_spec *spec = codec->spec;
2134 /* Add HP and CD pin config connect bit re-config action */
2135 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2136 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2138 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2141 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2144 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2145 return 0; /* can't find valid BIOS pin config */
2147 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2150 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2153 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2156 /* add jack detect on/off control */
2157 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2161 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2163 if (spec->autocfg.dig_outs)
2164 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2165 spec->dig_in_pin = VT1708_DIGIN_PIN;
2166 if (spec->autocfg.dig_in_pin)
2167 spec->dig_in_nid = VT1708_DIGIN_NID;
2169 if (spec->kctls.list)
2170 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2172 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2174 spec->input_mux = &spec->private_imux[0];
2177 via_hp_build(codec);
2179 via_smart51_build(spec);
2183 /* init callback for auto-configuration model -- overriding the default init */
2184 static int via_auto_init(struct hda_codec *codec)
2186 struct via_spec *spec = codec->spec;
2189 via_auto_init_multi_out(codec);
2190 via_auto_init_hp_out(codec);
2191 via_auto_init_analog_input(codec);
2193 if (VT2002P_COMPATIBLE(spec)) {
2194 via_hp_bind_automute(codec);
2196 via_hp_automute(codec);
2197 via_speaker_automute(codec);
2203 static void vt1708_update_hp_jack_state(struct work_struct *work)
2205 struct via_spec *spec = container_of(work, struct via_spec,
2206 vt1708_hp_work.work);
2207 if (spec->codec_type != VT1708)
2209 /* if jack state toggled */
2210 if (spec->vt1708_hp_present
2211 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2212 spec->vt1708_hp_present ^= 1;
2213 via_hp_automute(spec->codec);
2215 vt1708_start_hp_work(spec);
2218 static int get_mux_nids(struct hda_codec *codec)
2220 struct via_spec *spec = codec->spec;
2221 hda_nid_t nid, conn[8];
2225 for (i = 0; i < spec->num_adc_nids; i++) {
2226 nid = spec->adc_nids[i];
2228 type = get_wcaps_type(get_wcaps(codec, nid));
2229 if (type == AC_WID_PIN)
2231 n = snd_hda_get_connections(codec, nid, conn,
2236 spec->mux_nids[i] = nid;
2245 static int patch_vt1708(struct hda_codec *codec)
2247 struct via_spec *spec;
2250 /* create a codec specific record */
2251 spec = via_new_spec(codec);
2255 /* automatic parse from the BIOS config */
2256 err = vt1708_parse_auto_config(codec);
2261 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2262 "from BIOS. Using genenic mode...\n");
2266 spec->stream_name_analog = "VT1708 Analog";
2267 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2268 /* disable 32bit format on VT1708 */
2269 if (codec->vendor_id == 0x11061708)
2270 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2271 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2273 spec->stream_name_digital = "VT1708 Digital";
2274 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2275 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2278 if (!spec->adc_nids && spec->input_mux) {
2279 spec->adc_nids = vt1708_adc_nids;
2280 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2281 get_mux_nids(codec);
2282 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2286 codec->patch_ops = via_patch_ops;
2288 codec->patch_ops.init = via_auto_init;
2289 #ifdef CONFIG_SND_HDA_POWER_SAVE
2290 spec->loopback.amplist = vt1708_loopbacks;
2292 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2296 /* capture mixer elements */
2297 static const struct snd_kcontrol_new vt1709_capture_mixer[] = {
2298 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2299 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2300 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2301 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2302 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2303 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2305 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2306 /* The multiple "Capture Source" controls confuse alsamixer
2307 * So call somewhat different..
2309 /* .name = "Capture Source", */
2310 .name = "Input Source",
2312 .info = via_mux_enum_info,
2313 .get = via_mux_enum_get,
2314 .put = via_mux_enum_put,
2319 static const struct hda_verb vt1709_uniwill_init_verbs[] = {
2320 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2321 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2326 * generic initialization of ADC, input mixers and output mixers
2328 static const struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2330 * Unmute ADC0-2 and set the default input to mic-in
2332 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2333 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2334 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2337 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2340 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2341 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2342 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2343 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2344 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2345 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2348 * Set up output selector (0x1a, 0x1b, 0x29)
2350 /* set vol=0 to output mixers */
2351 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2352 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2353 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2356 * Unmute PW3 and PW4
2358 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2359 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2361 /* Set input of PW4 as MW0 */
2362 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2363 /* PW9 Output enable */
2364 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2368 static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2372 .nid = 0x10, /* NID to query formats and rates */
2374 .open = via_playback_pcm_open,
2375 .prepare = via_playback_multi_pcm_prepare,
2376 .cleanup = via_playback_multi_pcm_cleanup,
2380 static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2384 .nid = 0x10, /* NID to query formats and rates */
2386 .open = via_playback_pcm_open,
2387 .prepare = via_playback_multi_pcm_prepare,
2388 .cleanup = via_playback_multi_pcm_cleanup,
2392 static const struct hda_pcm_stream vt1709_pcm_analog_capture = {
2396 .nid = 0x14, /* NID to query formats and rates */
2398 .prepare = via_capture_pcm_prepare,
2399 .cleanup = via_capture_pcm_cleanup
2403 static const struct hda_pcm_stream vt1709_pcm_digital_playback = {
2407 /* NID is set in via_build_pcms */
2409 .open = via_dig_playback_pcm_open,
2410 .close = via_dig_playback_pcm_close
2414 static const struct hda_pcm_stream vt1709_pcm_digital_capture = {
2420 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2421 const struct auto_pin_cfg *cfg)
2426 if (cfg->line_outs == 4) /* 10 channels */
2427 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2428 else if (cfg->line_outs == 3) /* 6 channels */
2429 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2431 spec->multiout.dac_nids = spec->private_dac_nids;
2433 if (cfg->line_outs == 4) { /* 10 channels */
2434 for (i = 0; i < cfg->line_outs; i++) {
2435 nid = cfg->line_out_pins[i];
2437 /* config dac list */
2439 case AUTO_SEQ_FRONT:
2441 spec->private_dac_nids[i] = 0x10;
2443 case AUTO_SEQ_CENLFE:
2445 spec->private_dac_nids[i] = 0x12;
2447 case AUTO_SEQ_SURROUND:
2449 spec->private_dac_nids[i] = 0x11;
2453 spec->private_dac_nids[i] = 0x27;
2460 spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2462 } else if (cfg->line_outs == 3) { /* 6 channels */
2463 for (i = 0; i < cfg->line_outs; i++) {
2464 nid = cfg->line_out_pins[i];
2466 /* config dac list */
2468 case AUTO_SEQ_FRONT:
2470 spec->private_dac_nids[i] = 0x10;
2472 case AUTO_SEQ_CENLFE:
2474 spec->private_dac_nids[i] = 0x12;
2476 case AUTO_SEQ_SURROUND:
2478 spec->private_dac_nids[i] = 0x11;
2490 /* add playback controls from the parsed DAC table */
2491 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2492 const struct auto_pin_cfg *cfg)
2495 static const char * const chname[4] = {
2496 "Front", "Surround", "C/LFE", "Side"
2498 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2501 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2502 nid = cfg->line_out_pins[i];
2507 nid_vol = nid_vols[i];
2509 if (i == AUTO_SEQ_CENLFE) {
2511 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2512 "Center Playback Volume",
2513 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2517 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2518 "LFE Playback Volume",
2519 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2523 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2524 "Center Playback Switch",
2525 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2529 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2530 "LFE Playback Switch",
2531 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2535 } else if (i == AUTO_SEQ_FRONT) {
2536 /* ADD control to mixer index 0 */
2537 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2538 "Master Front Playback Volume",
2539 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2543 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2544 "Master Front Playback Switch",
2545 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2550 /* add control to PW3 */
2551 sprintf(name, "%s Playback Volume", chname[i]);
2552 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2553 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2557 sprintf(name, "%s Playback Switch", chname[i]);
2558 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2559 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2563 } else if (i == AUTO_SEQ_SURROUND) {
2564 sprintf(name, "%s Playback Volume", chname[i]);
2565 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2566 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2570 sprintf(name, "%s Playback Switch", chname[i]);
2571 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2572 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2576 } else if (i == AUTO_SEQ_SIDE) {
2577 sprintf(name, "%s Playback Volume", chname[i]);
2578 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2579 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2583 sprintf(name, "%s Playback Switch", chname[i]);
2584 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2585 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2595 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2602 if (spec->multiout.num_dacs == 5) /* 10 channels */
2603 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2604 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2605 spec->multiout.hp_nid = 0;
2606 spec->hp_independent_mode_index = 1;
2608 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2609 "Headphone Playback Volume",
2610 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2613 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2614 "Headphone Playback Switch",
2615 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2622 /* create playback/capture controls for input pins */
2623 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
2624 const struct auto_pin_cfg *cfg)
2626 static const hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
2627 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
2628 ARRAY_SIZE(pin_idxs));
2631 static int vt1709_parse_auto_config(struct hda_codec *codec)
2633 struct via_spec *spec = codec->spec;
2636 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2639 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2642 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2643 return 0; /* can't find valid BIOS pin config */
2645 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2648 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2651 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
2655 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2657 if (spec->autocfg.dig_outs)
2658 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2659 spec->dig_in_pin = VT1709_DIGIN_PIN;
2660 if (spec->autocfg.dig_in_pin)
2661 spec->dig_in_nid = VT1709_DIGIN_NID;
2663 if (spec->kctls.list)
2664 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2666 spec->input_mux = &spec->private_imux[0];
2669 via_hp_build(codec);
2671 via_smart51_build(spec);
2675 #ifdef CONFIG_SND_HDA_POWER_SAVE
2676 static const struct hda_amp_list vt1709_loopbacks[] = {
2677 { 0x18, HDA_INPUT, 1 },
2678 { 0x18, HDA_INPUT, 2 },
2679 { 0x18, HDA_INPUT, 3 },
2680 { 0x18, HDA_INPUT, 4 },
2685 static int patch_vt1709_10ch(struct hda_codec *codec)
2687 struct via_spec *spec;
2690 /* create a codec specific record */
2691 spec = via_new_spec(codec);
2695 err = vt1709_parse_auto_config(codec);
2700 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2701 "Using genenic mode...\n");
2704 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2705 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2707 spec->stream_name_analog = "VT1709 Analog";
2708 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2709 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2711 spec->stream_name_digital = "VT1709 Digital";
2712 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2713 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2716 if (!spec->adc_nids && spec->input_mux) {
2717 spec->adc_nids = vt1709_adc_nids;
2718 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2719 get_mux_nids(codec);
2720 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2724 codec->patch_ops = via_patch_ops;
2726 codec->patch_ops.init = via_auto_init;
2727 codec->patch_ops.unsol_event = via_unsol_event;
2728 #ifdef CONFIG_SND_HDA_POWER_SAVE
2729 spec->loopback.amplist = vt1709_loopbacks;
2735 * generic initialization of ADC, input mixers and output mixers
2737 static const struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2739 * Unmute ADC0-2 and set the default input to mic-in
2741 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2742 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2743 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2746 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2749 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2750 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2751 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2752 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2753 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2754 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2757 * Set up output selector (0x1a, 0x1b, 0x29)
2759 /* set vol=0 to output mixers */
2760 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2761 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2762 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2765 * Unmute PW3 and PW4
2767 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2768 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2770 /* Set input of PW4 as MW0 */
2771 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2772 /* PW9 Output enable */
2773 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2777 static int patch_vt1709_6ch(struct hda_codec *codec)
2779 struct via_spec *spec;
2782 /* create a codec specific record */
2783 spec = via_new_spec(codec);
2787 err = vt1709_parse_auto_config(codec);
2792 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2793 "Using genenic mode...\n");
2796 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2797 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2799 spec->stream_name_analog = "VT1709 Analog";
2800 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2801 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2803 spec->stream_name_digital = "VT1709 Digital";
2804 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2805 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2808 if (!spec->adc_nids && spec->input_mux) {
2809 spec->adc_nids = vt1709_adc_nids;
2810 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2811 get_mux_nids(codec);
2812 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2816 codec->patch_ops = via_patch_ops;
2818 codec->patch_ops.init = via_auto_init;
2819 codec->patch_ops.unsol_event = via_unsol_event;
2820 #ifdef CONFIG_SND_HDA_POWER_SAVE
2821 spec->loopback.amplist = vt1709_loopbacks;
2826 /* capture mixer elements */
2827 static const struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2828 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2829 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2830 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2831 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2833 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2834 /* The multiple "Capture Source" controls confuse alsamixer
2835 * So call somewhat different..
2837 /* .name = "Capture Source", */
2838 .name = "Input Source",
2840 .info = via_mux_enum_info,
2841 .get = via_mux_enum_get,
2842 .put = via_mux_enum_put,
2847 * generic initialization of ADC, input mixers and output mixers
2849 static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2851 * Unmute ADC0-1 and set the default input to mic-in
2853 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2854 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2857 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2860 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2861 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2862 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2863 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2864 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2865 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2868 * Set up output mixers
2870 /* set vol=0 to output mixers */
2871 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2872 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2873 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2875 /* Setup default input to PW4 */
2876 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
2877 /* PW9 Output enable */
2878 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2879 /* PW10 Input enable */
2880 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2884 static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2886 * Unmute ADC0-1 and set the default input to mic-in
2888 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2889 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2892 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2895 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2896 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2897 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2898 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2899 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2900 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2903 * Set up output mixers
2905 /* set vol=0 to output mixers */
2906 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2907 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2908 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2910 /* Setup default input of PW4 to MW0 */
2911 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2912 /* PW9 Output enable */
2913 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2914 /* PW10 Input enable */
2915 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2919 static const struct hda_verb vt1708B_uniwill_init_verbs[] = {
2920 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
2921 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2922 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2923 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2924 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2925 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2926 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2927 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2928 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
2932 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2933 struct hda_codec *codec,
2934 struct snd_pcm_substream *substream)
2936 int idle = substream->pstr->substream_opened == 1
2937 && substream->ref_count == 0;
2939 analog_low_current_mode(codec, idle);
2943 static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2947 .nid = 0x10, /* NID to query formats and rates */
2949 .open = via_playback_pcm_open,
2950 .prepare = via_playback_multi_pcm_prepare,
2951 .cleanup = via_playback_multi_pcm_cleanup,
2952 .close = via_pcm_open_close
2956 static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2960 .nid = 0x10, /* NID to query formats and rates */
2962 .open = via_playback_pcm_open,
2963 .prepare = via_playback_multi_pcm_prepare,
2964 .cleanup = via_playback_multi_pcm_cleanup
2968 static const struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2972 .nid = 0x13, /* NID to query formats and rates */
2974 .open = via_pcm_open_close,
2975 .prepare = via_capture_pcm_prepare,
2976 .cleanup = via_capture_pcm_cleanup,
2977 .close = via_pcm_open_close
2981 static const struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2985 /* NID is set in via_build_pcms */
2987 .open = via_dig_playback_pcm_open,
2988 .close = via_dig_playback_pcm_close,
2989 .prepare = via_dig_playback_pcm_prepare,
2990 .cleanup = via_dig_playback_pcm_cleanup
2994 static const struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3000 /* fill in the dac_nids table from the parsed pin configuration */
3001 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3002 const struct auto_pin_cfg *cfg)
3007 spec->multiout.num_dacs = cfg->line_outs;
3009 spec->multiout.dac_nids = spec->private_dac_nids;
3011 for (i = 0; i < 4; i++) {
3012 nid = cfg->line_out_pins[i];
3014 /* config dac list */
3016 case AUTO_SEQ_FRONT:
3017 spec->private_dac_nids[i] = 0x10;
3019 case AUTO_SEQ_CENLFE:
3020 spec->private_dac_nids[i] = 0x24;
3022 case AUTO_SEQ_SURROUND:
3023 spec->private_dac_nids[i] = 0x11;
3026 spec->private_dac_nids[i] = 0x25;
3035 /* add playback controls from the parsed DAC table */
3036 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3037 const struct auto_pin_cfg *cfg)
3040 static const char * const chname[4] = {
3041 "Front", "Surround", "C/LFE", "Side"
3043 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3044 hda_nid_t nid, nid_vol = 0;
3047 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3048 nid = cfg->line_out_pins[i];
3053 nid_vol = nid_vols[i];
3055 if (i == AUTO_SEQ_CENLFE) {
3057 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3058 "Center Playback Volume",
3059 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3063 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3064 "LFE Playback Volume",
3065 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3069 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3070 "Center Playback Switch",
3071 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3075 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3076 "LFE Playback Switch",
3077 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3081 } else if (i == AUTO_SEQ_FRONT) {
3082 /* add control to mixer index 0 */
3083 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3084 "Master Front Playback Volume",
3085 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3089 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3090 "Master Front Playback Switch",
3091 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3096 /* add control to PW3 */
3097 sprintf(name, "%s Playback Volume", chname[i]);
3098 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3099 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3103 sprintf(name, "%s Playback Switch", chname[i]);
3104 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3105 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3110 sprintf(name, "%s Playback Volume", chname[i]);
3111 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3112 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3116 sprintf(name, "%s Playback Switch", chname[i]);
3117 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3118 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3128 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3135 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3136 spec->hp_independent_mode_index = 1;
3138 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3139 "Headphone Playback Volume",
3140 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3143 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3144 "Headphone Playback Switch",
3145 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3149 create_hp_imux(spec);
3154 /* create playback/capture controls for input pins */
3155 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3156 const struct auto_pin_cfg *cfg)
3158 static const hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3159 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3160 ARRAY_SIZE(pin_idxs));
3163 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3165 struct via_spec *spec = codec->spec;
3168 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3171 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3174 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3175 return 0; /* can't find valid BIOS pin config */
3177 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3180 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3183 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3187 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3189 if (spec->autocfg.dig_outs)
3190 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3191 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3192 if (spec->autocfg.dig_in_pin)
3193 spec->dig_in_nid = VT1708B_DIGIN_NID;
3195 if (spec->kctls.list)
3196 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3198 spec->input_mux = &spec->private_imux[0];
3201 via_hp_build(codec);
3203 via_smart51_build(spec);
3207 #ifdef CONFIG_SND_HDA_POWER_SAVE
3208 static const struct hda_amp_list vt1708B_loopbacks[] = {
3209 { 0x16, HDA_INPUT, 1 },
3210 { 0x16, HDA_INPUT, 2 },
3211 { 0x16, HDA_INPUT, 3 },
3212 { 0x16, HDA_INPUT, 4 },
3217 static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
3219 struct via_spec *spec = codec->spec;
3223 if ((spec->codec_type != VT1708B_4CH) &&
3224 (codec->vendor_id != 0x11064397))
3227 /* SW0 (17h) = stereo mixer */
3229 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
3230 == ((spec->codec_type == VT1708S) ? 5 : 0));
3232 /* PW 1/2/5 (1ah/1bh/1eh) */
3234 set_pin_power_state(codec, 0x1a, &parm);
3235 set_pin_power_state(codec, 0x1b, &parm);
3236 set_pin_power_state(codec, 0x1e, &parm);
3239 /* SW0 (17h), AIW 0/1 (13h/14h) */
3240 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
3241 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
3242 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
3245 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
3247 set_pin_power_state(codec, 0x19, &parm);
3248 if (spec->smart51_enabled)
3249 set_pin_power_state(codec, 0x1b, &parm);
3250 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
3251 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
3253 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
3256 set_pin_power_state(codec, 0x22, &parm);
3257 if (spec->smart51_enabled)
3258 set_pin_power_state(codec, 0x1a, &parm);
3259 snd_hda_codec_write(codec, 0x26, 0,
3260 AC_VERB_SET_POWER_STATE, parm);
3261 snd_hda_codec_write(codec, 0x24, 0,
3262 AC_VERB_SET_POWER_STATE, parm);
3263 } else if (codec->vendor_id == 0x11064397) {
3264 /* PW7(23h), SW2(27h), AOW2(25h) */
3266 set_pin_power_state(codec, 0x23, &parm);
3267 if (spec->smart51_enabled)
3268 set_pin_power_state(codec, 0x1a, &parm);
3269 snd_hda_codec_write(codec, 0x27, 0,
3270 AC_VERB_SET_POWER_STATE, parm);
3271 snd_hda_codec_write(codec, 0x25, 0,
3272 AC_VERB_SET_POWER_STATE, parm);
3275 /* PW 3/4/7 (1ch/1dh/23h) */
3277 /* force to D0 for internal Speaker */
3278 set_pin_power_state(codec, 0x1c, &parm);
3279 set_pin_power_state(codec, 0x1d, &parm);
3281 set_pin_power_state(codec, 0x23, &parm);
3283 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
3284 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
3285 imux_is_smixer ? AC_PWRST_D0 : parm);
3286 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
3288 snd_hda_codec_write(codec, 0x25, 0,
3289 AC_VERB_SET_POWER_STATE, parm);
3290 snd_hda_codec_write(codec, 0x27, 0,
3291 AC_VERB_SET_POWER_STATE, parm);
3292 } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
3293 snd_hda_codec_write(codec, 0x25, 0,
3294 AC_VERB_SET_POWER_STATE, parm);
3297 static int patch_vt1708S(struct hda_codec *codec);
3298 static int patch_vt1708B_8ch(struct hda_codec *codec)
3300 struct via_spec *spec;
3303 if (get_codec_type(codec) == VT1708BCE)
3304 return patch_vt1708S(codec);
3305 /* create a codec specific record */
3306 spec = via_new_spec(codec);
3310 /* automatic parse from the BIOS config */
3311 err = vt1708B_parse_auto_config(codec);
3316 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3317 "from BIOS. Using genenic mode...\n");
3320 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3321 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3323 spec->stream_name_analog = "VT1708B Analog";
3324 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3325 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3327 spec->stream_name_digital = "VT1708B Digital";
3328 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3329 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3331 if (!spec->adc_nids && spec->input_mux) {
3332 spec->adc_nids = vt1708B_adc_nids;
3333 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3334 get_mux_nids(codec);
3335 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3339 codec->patch_ops = via_patch_ops;
3341 codec->patch_ops.init = via_auto_init;
3342 codec->patch_ops.unsol_event = via_unsol_event;
3343 #ifdef CONFIG_SND_HDA_POWER_SAVE
3344 spec->loopback.amplist = vt1708B_loopbacks;
3347 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3352 static int patch_vt1708B_4ch(struct hda_codec *codec)
3354 struct via_spec *spec;
3357 /* create a codec specific record */
3358 spec = via_new_spec(codec);
3362 /* automatic parse from the BIOS config */
3363 err = vt1708B_parse_auto_config(codec);
3368 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3369 "from BIOS. Using genenic mode...\n");
3372 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3373 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3375 spec->stream_name_analog = "VT1708B Analog";
3376 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3377 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3379 spec->stream_name_digital = "VT1708B Digital";
3380 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3381 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3383 if (!spec->adc_nids && spec->input_mux) {
3384 spec->adc_nids = vt1708B_adc_nids;
3385 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3386 get_mux_nids(codec);
3387 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3391 codec->patch_ops = via_patch_ops;
3393 codec->patch_ops.init = via_auto_init;
3394 codec->patch_ops.unsol_event = via_unsol_event;
3395 #ifdef CONFIG_SND_HDA_POWER_SAVE
3396 spec->loopback.amplist = vt1708B_loopbacks;
3399 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3404 /* Patch for VT1708S */
3406 /* capture mixer elements */
3407 static const struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3408 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3409 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3410 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3411 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3412 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3413 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3416 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3417 /* The multiple "Capture Source" controls confuse alsamixer
3418 * So call somewhat different..
3420 /* .name = "Capture Source", */
3421 .name = "Input Source",
3423 .info = via_mux_enum_info,
3424 .get = via_mux_enum_get,
3425 .put = via_mux_enum_put,
3430 static const struct hda_verb vt1708S_volume_init_verbs[] = {
3431 /* Unmute ADC0-1 and set the default input to mic-in */
3432 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3433 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3435 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3436 * analog-loopback mixer widget */
3437 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3438 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3439 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3440 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3441 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3442 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3444 /* Setup default input of PW4 to MW0 */
3445 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3446 /* PW9, PW10 Output enable */
3447 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3448 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3449 /* Enable Mic Boost Volume backdoor */
3451 /* don't bybass mixer */
3456 static const struct hda_verb vt1708S_uniwill_init_verbs[] = {
3457 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3458 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3459 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3460 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3461 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3462 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3463 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3464 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3465 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3469 static const struct hda_verb vt1705_uniwill_init_verbs[] = {
3470 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3471 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3472 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3473 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3474 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3475 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3476 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3477 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3481 static const struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3485 .nid = 0x10, /* NID to query formats and rates */
3487 .open = via_playback_pcm_open,
3488 .prepare = via_playback_multi_pcm_prepare,
3489 .cleanup = via_playback_multi_pcm_cleanup,
3490 .close = via_pcm_open_close
3494 static const struct hda_pcm_stream vt1705_pcm_analog_playback = {
3498 .nid = 0x10, /* NID to query formats and rates */
3500 .open = via_playback_pcm_open,
3501 .prepare = via_playback_multi_pcm_prepare,
3502 .cleanup = via_playback_multi_pcm_cleanup,
3503 .close = via_pcm_open_close
3507 static const struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3511 .nid = 0x13, /* NID to query formats and rates */
3513 .open = via_pcm_open_close,
3514 .prepare = via_capture_pcm_prepare,
3515 .cleanup = via_capture_pcm_cleanup,
3516 .close = via_pcm_open_close
3520 static const struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3524 /* NID is set in via_build_pcms */
3526 .open = via_dig_playback_pcm_open,
3527 .close = via_dig_playback_pcm_close,
3528 .prepare = via_dig_playback_pcm_prepare,
3529 .cleanup = via_dig_playback_pcm_cleanup
3533 /* fill in the dac_nids table from the parsed pin configuration */
3534 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3535 const struct auto_pin_cfg *cfg)
3540 spec->multiout.num_dacs = cfg->line_outs;
3542 spec->multiout.dac_nids = spec->private_dac_nids;
3544 for (i = 0; i < 4; i++) {
3545 nid = cfg->line_out_pins[i];
3547 /* config dac list */
3549 case AUTO_SEQ_FRONT:
3550 spec->private_dac_nids[i] = 0x10;
3552 case AUTO_SEQ_CENLFE:
3553 if (spec->codec->vendor_id == 0x11064397)
3554 spec->private_dac_nids[i] = 0x25;
3556 spec->private_dac_nids[i] = 0x24;
3558 case AUTO_SEQ_SURROUND:
3559 spec->private_dac_nids[i] = 0x11;
3562 spec->private_dac_nids[i] = 0x25;
3568 /* for Smart 5.1, line/mic inputs double as output pins */
3569 if (cfg->line_outs == 1) {
3570 spec->multiout.num_dacs = 3;
3571 spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3572 if (spec->codec->vendor_id == 0x11064397)
3573 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25;
3575 spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3581 /* add playback controls from the parsed DAC table */
3582 static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec,
3583 const struct auto_pin_cfg *cfg)
3585 struct via_spec *spec = codec->spec;
3587 static const char * const chname[4] = {
3588 "Front", "Surround", "C/LFE", "Side"
3590 hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25},
3591 {0x10, 0x11, 0x25, 0} };
3592 hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27},
3593 {0x1C, 0x18, 0x27, 0} };
3594 hda_nid_t nid, nid_vol, nid_mute;
3597 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3598 nid = cfg->line_out_pins[i];
3600 /* for Smart 5.1, there are always at least six channels */
3601 if (!nid && i > AUTO_SEQ_CENLFE)
3604 if (codec->vendor_id == 0x11064397) {
3605 nid_vol = nid_vols[1][i];
3606 nid_mute = nid_mutes[1][i];
3608 nid_vol = nid_vols[0][i];
3609 nid_mute = nid_mutes[0][i];
3611 if (!nid_vol && !nid_mute)
3614 if (i == AUTO_SEQ_CENLFE) {
3616 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3617 "Center Playback Volume",
3618 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3622 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3623 "LFE Playback Volume",
3624 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3628 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3629 "Center Playback Switch",
3630 HDA_COMPOSE_AMP_VAL(nid_mute,
3635 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3636 "LFE Playback Switch",
3637 HDA_COMPOSE_AMP_VAL(nid_mute,
3642 } else if (i == AUTO_SEQ_FRONT) {
3643 /* add control to mixer index 0 */
3644 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3645 "Master Front Playback Volume",
3646 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3650 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3651 "Master Front Playback Switch",
3652 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
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,
3672 sprintf(name, "%s Playback Volume", chname[i]);
3673 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3674 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3678 sprintf(name, "%s Playback Switch", chname[i]);
3679 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3680 HDA_COMPOSE_AMP_VAL(nid_mute,
3691 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3698 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3699 spec->hp_independent_mode_index = 1;
3701 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3702 "Headphone Playback Volume",
3703 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3707 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3708 "Headphone Playback Switch",
3709 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3713 create_hp_imux(spec);
3718 /* create playback/capture controls for input pins */
3719 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3720 const struct auto_pin_cfg *cfg)
3722 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
3723 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3724 ARRAY_SIZE(pin_idxs));
3727 /* fill out digital output widgets; one for master and one for slave outputs */
3728 static void fill_dig_outs(struct hda_codec *codec)
3730 struct via_spec *spec = codec->spec;
3733 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3737 nid = spec->autocfg.dig_out_pins[i];
3740 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3743 if (!spec->multiout.dig_out_nid)
3744 spec->multiout.dig_out_nid = nid;
3746 spec->slave_dig_outs[0] = nid;
3747 break; /* at most two dig outs */
3752 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3754 struct via_spec *spec = codec->spec;
3757 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3760 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3763 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3764 return 0; /* can't find valid BIOS pin config */
3766 err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg);
3769 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3772 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
3776 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3778 fill_dig_outs(codec);
3780 if (spec->kctls.list)
3781 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3783 spec->input_mux = &spec->private_imux[0];
3786 via_hp_build(codec);
3788 via_smart51_build(spec);
3792 #ifdef CONFIG_SND_HDA_POWER_SAVE
3793 static const struct hda_amp_list vt1708S_loopbacks[] = {
3794 { 0x16, HDA_INPUT, 1 },
3795 { 0x16, HDA_INPUT, 2 },
3796 { 0x16, HDA_INPUT, 3 },
3797 { 0x16, HDA_INPUT, 4 },
3802 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
3803 int offset, int num_steps, int step_size)
3805 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
3806 (offset << AC_AMPCAP_OFFSET_SHIFT) |
3807 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
3808 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
3809 (0 << AC_AMPCAP_MUTE_SHIFT));
3812 static int patch_vt1708S(struct hda_codec *codec)
3814 struct via_spec *spec;
3817 /* create a codec specific record */
3818 spec = via_new_spec(codec);
3822 /* automatic parse from the BIOS config */
3823 err = vt1708S_parse_auto_config(codec);
3828 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3829 "from BIOS. Using genenic mode...\n");
3832 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3833 if (codec->vendor_id == 0x11064397)
3834 spec->init_verbs[spec->num_iverbs++] =
3835 vt1705_uniwill_init_verbs;
3837 spec->init_verbs[spec->num_iverbs++] =
3838 vt1708S_uniwill_init_verbs;
3840 if (codec->vendor_id == 0x11060440)
3841 spec->stream_name_analog = "VT1818S Analog";
3842 else if (codec->vendor_id == 0x11064397)
3843 spec->stream_name_analog = "VT1705 Analog";
3845 spec->stream_name_analog = "VT1708S Analog";
3846 if (codec->vendor_id == 0x11064397)
3847 spec->stream_analog_playback = &vt1705_pcm_analog_playback;
3849 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
3850 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3852 if (codec->vendor_id == 0x11060440)
3853 spec->stream_name_digital = "VT1818S Digital";
3854 else if (codec->vendor_id == 0x11064397)
3855 spec->stream_name_digital = "VT1705 Digital";
3857 spec->stream_name_digital = "VT1708S Digital";
3858 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3860 if (!spec->adc_nids && spec->input_mux) {
3861 spec->adc_nids = vt1708S_adc_nids;
3862 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
3863 get_mux_nids(codec);
3864 override_mic_boost(codec, 0x1a, 0, 3, 40);
3865 override_mic_boost(codec, 0x1e, 0, 3, 40);
3866 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3870 codec->patch_ops = via_patch_ops;
3872 codec->patch_ops.init = via_auto_init;
3873 codec->patch_ops.unsol_event = via_unsol_event;
3874 #ifdef CONFIG_SND_HDA_POWER_SAVE
3875 spec->loopback.amplist = vt1708S_loopbacks;
3878 /* correct names for VT1708BCE */
3879 if (get_codec_type(codec) == VT1708BCE) {
3880 kfree(codec->chip_name);
3881 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3882 snprintf(codec->bus->card->mixername,
3883 sizeof(codec->bus->card->mixername),
3884 "%s %s", codec->vendor_name, codec->chip_name);
3885 spec->stream_name_analog = "VT1708BCE Analog";
3886 spec->stream_name_digital = "VT1708BCE Digital";
3888 /* correct names for VT1818S */
3889 if (codec->vendor_id == 0x11060440) {
3890 spec->stream_name_analog = "VT1818S Analog";
3891 spec->stream_name_digital = "VT1818S Digital";
3893 /* correct names for VT1705 */
3894 if (codec->vendor_id == 0x11064397) {
3895 kfree(codec->chip_name);
3896 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
3897 snprintf(codec->bus->card->mixername,
3898 sizeof(codec->bus->card->mixername),
3899 "%s %s", codec->vendor_name, codec->chip_name);
3901 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
3905 /* Patch for VT1702 */
3907 /* capture mixer elements */
3908 static const struct snd_kcontrol_new vt1702_capture_mixer[] = {
3909 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3910 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3911 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3912 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3913 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3914 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3915 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3919 /* The multiple "Capture Source" controls confuse alsamixer
3920 * So call somewhat different..
3922 /* .name = "Capture Source", */
3923 .name = "Input Source",
3925 .info = via_mux_enum_info,
3926 .get = via_mux_enum_get,
3927 .put = via_mux_enum_put,
3932 static const struct hda_verb vt1702_volume_init_verbs[] = {
3934 * Unmute ADC0-1 and set the default input to mic-in
3936 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3937 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3938 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3941 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3944 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3945 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3946 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3947 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3948 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3949 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3951 /* Setup default input of PW4 to MW0 */
3952 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3953 /* PW6 PW7 Output enable */
3954 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3955 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3963 static const struct hda_verb vt1702_uniwill_init_verbs[] = {
3964 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
3965 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3966 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3967 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3968 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3969 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3973 static const struct hda_pcm_stream vt1702_pcm_analog_playback = {
3977 .nid = 0x10, /* NID to query formats and rates */
3979 .open = via_playback_pcm_open,
3980 .prepare = via_playback_multi_pcm_prepare,
3981 .cleanup = via_playback_multi_pcm_cleanup,
3982 .close = via_pcm_open_close
3986 static const struct hda_pcm_stream vt1702_pcm_analog_capture = {
3990 .nid = 0x12, /* NID to query formats and rates */
3992 .open = via_pcm_open_close,
3993 .prepare = via_capture_pcm_prepare,
3994 .cleanup = via_capture_pcm_cleanup,
3995 .close = via_pcm_open_close
3999 static const struct hda_pcm_stream vt1702_pcm_digital_playback = {
4003 /* NID is set in via_build_pcms */
4005 .open = via_dig_playback_pcm_open,
4006 .close = via_dig_playback_pcm_close,
4007 .prepare = via_dig_playback_pcm_prepare,
4008 .cleanup = via_dig_playback_pcm_cleanup
4012 /* fill in the dac_nids table from the parsed pin configuration */
4013 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4014 const struct auto_pin_cfg *cfg)
4016 spec->multiout.num_dacs = 1;
4017 spec->multiout.dac_nids = spec->private_dac_nids;
4019 if (cfg->line_out_pins[0]) {
4020 /* config dac list */
4021 spec->private_dac_nids[0] = 0x10;
4027 /* add playback controls from the parsed DAC table */
4028 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4029 const struct auto_pin_cfg *cfg)
4033 if (!cfg->line_out_pins[0])
4036 /* add control to mixer index 0 */
4037 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4038 "Master Front Playback Volume",
4039 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4042 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4043 "Master Front Playback Switch",
4044 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4049 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4050 "Front Playback Volume",
4051 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4054 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4055 "Front Playback Switch",
4056 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4063 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4066 struct hda_input_mux *imux;
4067 static const char * const texts[] = { "ON", "OFF", NULL};
4070 spec->multiout.hp_nid = 0x1D;
4071 spec->hp_independent_mode_index = 0;
4073 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4074 "Headphone Playback Volume",
4075 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4079 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4080 "Headphone Playback Switch",
4081 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4085 imux = &spec->private_imux[1];
4087 /* for hp mode select */
4088 for (i = 0; texts[i]; i++)
4089 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4091 spec->hp_mux = &spec->private_imux[1];
4095 /* create playback/capture controls for input pins */
4096 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4097 const struct auto_pin_cfg *cfg)
4099 static const hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4100 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4101 ARRAY_SIZE(pin_idxs));
4104 static int vt1702_parse_auto_config(struct hda_codec *codec)
4106 struct via_spec *spec = codec->spec;
4109 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4112 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4115 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4116 return 0; /* can't find valid BIOS pin config */
4118 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4121 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4124 /* limit AA path volume to 0 dB */
4125 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4126 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4127 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4128 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4129 (1 << AC_AMPCAP_MUTE_SHIFT));
4130 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4134 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4136 fill_dig_outs(codec);
4138 if (spec->kctls.list)
4139 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4141 spec->input_mux = &spec->private_imux[0];
4144 via_hp_build(codec);
4149 #ifdef CONFIG_SND_HDA_POWER_SAVE
4150 static const struct hda_amp_list vt1702_loopbacks[] = {
4151 { 0x1A, HDA_INPUT, 1 },
4152 { 0x1A, HDA_INPUT, 2 },
4153 { 0x1A, HDA_INPUT, 3 },
4154 { 0x1A, HDA_INPUT, 4 },
4159 static void set_widgets_power_state_vt1702(struct hda_codec *codec)
4161 int imux_is_smixer =
4162 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
4165 /* PW 1/2/5 (14h/15h/18h) */
4167 set_pin_power_state(codec, 0x14, &parm);
4168 set_pin_power_state(codec, 0x15, &parm);
4169 set_pin_power_state(codec, 0x18, &parm);
4171 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
4172 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
4173 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
4174 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
4175 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4176 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
4179 /* PW 3/4 (16h/17h) */
4181 set_pin_power_state(codec, 0x17, &parm);
4182 set_pin_power_state(codec, 0x16, &parm);
4183 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
4184 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
4185 imux_is_smixer ? AC_PWRST_D0 : parm);
4186 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4187 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
4190 static int patch_vt1702(struct hda_codec *codec)
4192 struct via_spec *spec;
4195 /* create a codec specific record */
4196 spec = via_new_spec(codec);
4200 /* automatic parse from the BIOS config */
4201 err = vt1702_parse_auto_config(codec);
4206 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4207 "from BIOS. Using genenic mode...\n");
4210 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4211 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4213 spec->stream_name_analog = "VT1702 Analog";
4214 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4215 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4217 spec->stream_name_digital = "VT1702 Digital";
4218 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4220 if (!spec->adc_nids && spec->input_mux) {
4221 spec->adc_nids = vt1702_adc_nids;
4222 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4223 get_mux_nids(codec);
4224 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4228 codec->patch_ops = via_patch_ops;
4230 codec->patch_ops.init = via_auto_init;
4231 codec->patch_ops.unsol_event = via_unsol_event;
4232 #ifdef CONFIG_SND_HDA_POWER_SAVE
4233 spec->loopback.amplist = vt1702_loopbacks;
4236 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
4240 /* Patch for VT1718S */
4242 /* capture mixer elements */
4243 static const struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4244 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4245 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4246 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4247 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4248 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4249 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4252 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4253 /* The multiple "Capture Source" controls confuse alsamixer
4254 * So call somewhat different..
4256 .name = "Input Source",
4258 .info = via_mux_enum_info,
4259 .get = via_mux_enum_get,
4260 .put = via_mux_enum_put,
4265 static const struct hda_verb vt1718S_volume_init_verbs[] = {
4267 * Unmute ADC0-1 and set the default input to mic-in
4269 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4270 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4272 /* Enable MW0 adjust Gain 5 */
4274 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4277 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4278 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4279 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4280 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4281 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4282 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
4284 /* Setup default input of Front HP to MW9 */
4285 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4286 /* PW9 PW10 Output enable */
4287 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4288 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4289 /* PW11 Input enable */
4290 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4291 /* Enable Boost Volume backdoor */
4293 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4294 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4295 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4296 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4297 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4298 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4299 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4300 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4301 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4302 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4303 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4304 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4305 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4306 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4307 /* Unmute MW4's index 0 */
4308 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4313 static const struct hda_verb vt1718S_uniwill_init_verbs[] = {
4314 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4315 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4316 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4317 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4318 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4319 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4320 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4321 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4322 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4326 static const struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4330 .nid = 0x8, /* NID to query formats and rates */
4332 .open = via_playback_pcm_open,
4333 .prepare = via_playback_multi_pcm_prepare,
4334 .cleanup = via_playback_multi_pcm_cleanup,
4335 .close = via_pcm_open_close,
4339 static const struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4343 .nid = 0x10, /* NID to query formats and rates */
4345 .open = via_pcm_open_close,
4346 .prepare = via_capture_pcm_prepare,
4347 .cleanup = via_capture_pcm_cleanup,
4348 .close = via_pcm_open_close,
4352 static const struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4356 /* NID is set in via_build_pcms */
4358 .open = via_dig_playback_pcm_open,
4359 .close = via_dig_playback_pcm_close,
4360 .prepare = via_dig_playback_pcm_prepare,
4361 .cleanup = via_dig_playback_pcm_cleanup
4365 static const struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4371 /* fill in the dac_nids table from the parsed pin configuration */
4372 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4373 const struct auto_pin_cfg *cfg)
4378 spec->multiout.num_dacs = cfg->line_outs;
4380 spec->multiout.dac_nids = spec->private_dac_nids;
4382 for (i = 0; i < 4; i++) {
4383 nid = cfg->line_out_pins[i];
4385 /* config dac list */
4387 case AUTO_SEQ_FRONT:
4388 spec->private_dac_nids[i] = 0x8;
4390 case AUTO_SEQ_CENLFE:
4391 spec->private_dac_nids[i] = 0xa;
4393 case AUTO_SEQ_SURROUND:
4394 spec->private_dac_nids[i] = 0x9;
4397 spec->private_dac_nids[i] = 0xb;
4406 /* add playback controls from the parsed DAC table */
4407 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4408 const struct auto_pin_cfg *cfg)
4411 static const char * const chname[4] = {
4412 "Front", "Surround", "C/LFE", "Side"
4414 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4415 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4416 hda_nid_t nid, nid_vol, nid_mute = 0;
4419 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4420 nid = cfg->line_out_pins[i];
4424 nid_vol = nid_vols[i];
4425 nid_mute = nid_mutes[i];
4427 if (i == AUTO_SEQ_CENLFE) {
4429 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4430 "Center Playback Volume",
4431 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4435 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4436 "LFE Playback Volume",
4437 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4441 err = via_add_control(
4442 spec, VIA_CTL_WIDGET_MUTE,
4443 "Center Playback Switch",
4444 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4448 err = via_add_control(
4449 spec, VIA_CTL_WIDGET_MUTE,
4450 "LFE Playback Switch",
4451 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4455 } else if (i == AUTO_SEQ_FRONT) {
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,
4471 sprintf(name, "%s Playback Volume", chname[i]);
4472 err = via_add_control(
4473 spec, VIA_CTL_WIDGET_VOL, name,
4474 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4477 sprintf(name, "%s Playback Switch", chname[i]);
4478 err = via_add_control(
4479 spec, VIA_CTL_WIDGET_MUTE, name,
4480 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4489 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4496 spec->multiout.hp_nid = 0xc; /* AOW4 */
4497 spec->hp_independent_mode_index = 1;
4499 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4500 "Headphone Playback Volume",
4501 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4505 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4506 "Headphone Playback Switch",
4507 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4511 create_hp_imux(spec);
4515 /* create playback/capture controls for input pins */
4516 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4517 const struct auto_pin_cfg *cfg)
4519 static const hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4520 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4521 ARRAY_SIZE(pin_idxs));
4524 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4526 struct via_spec *spec = codec->spec;
4529 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4533 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4536 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4537 return 0; /* can't find valid BIOS pin config */
4539 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4542 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4545 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4549 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4551 fill_dig_outs(codec);
4553 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4554 spec->dig_in_nid = 0x13;
4556 if (spec->kctls.list)
4557 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4559 spec->input_mux = &spec->private_imux[0];
4562 via_hp_build(codec);
4564 via_smart51_build(spec);
4569 #ifdef CONFIG_SND_HDA_POWER_SAVE
4570 static const struct hda_amp_list vt1718S_loopbacks[] = {
4571 { 0x21, HDA_INPUT, 1 },
4572 { 0x21, HDA_INPUT, 2 },
4573 { 0x21, HDA_INPUT, 3 },
4574 { 0x21, HDA_INPUT, 4 },
4579 static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
4581 struct via_spec *spec = codec->spec;
4584 /* MUX6 (1eh) = stereo mixer */
4586 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
4588 /* PW 5/6/7 (29h/2ah/2bh) */
4590 set_pin_power_state(codec, 0x29, &parm);
4591 set_pin_power_state(codec, 0x2a, &parm);
4592 set_pin_power_state(codec, 0x2b, &parm);
4595 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
4596 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
4597 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
4598 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
4599 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
4602 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
4604 set_pin_power_state(codec, 0x27, &parm);
4605 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
4606 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
4608 /* PW2 (26h), AOW2 (ah) */
4610 set_pin_power_state(codec, 0x26, &parm);
4611 if (spec->smart51_enabled)
4612 set_pin_power_state(codec, 0x2b, &parm);
4613 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
4615 /* PW0 (24h), AOW0 (8h) */
4617 set_pin_power_state(codec, 0x24, &parm);
4618 if (!spec->hp_independent_mode) /* check for redirected HP */
4619 set_pin_power_state(codec, 0x28, &parm);
4620 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
4621 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
4622 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
4623 imux_is_smixer ? AC_PWRST_D0 : parm);
4625 /* PW1 (25h), AOW1 (9h) */
4627 set_pin_power_state(codec, 0x25, &parm);
4628 if (spec->smart51_enabled)
4629 set_pin_power_state(codec, 0x2a, &parm);
4630 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
4632 if (spec->hp_independent_mode) {
4633 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
4635 set_pin_power_state(codec, 0x28, &parm);
4636 snd_hda_codec_write(codec, 0x1b, 0,
4637 AC_VERB_SET_POWER_STATE, parm);
4638 snd_hda_codec_write(codec, 0x34, 0,
4639 AC_VERB_SET_POWER_STATE, parm);
4640 snd_hda_codec_write(codec, 0xc, 0,
4641 AC_VERB_SET_POWER_STATE, parm);
4645 static int patch_vt1718S(struct hda_codec *codec)
4647 struct via_spec *spec;
4650 /* create a codec specific record */
4651 spec = via_new_spec(codec);
4655 /* automatic parse from the BIOS config */
4656 err = vt1718S_parse_auto_config(codec);
4661 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4662 "from BIOS. Using genenic mode...\n");
4665 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4666 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4668 if (codec->vendor_id == 0x11060441)
4669 spec->stream_name_analog = "VT2020 Analog";
4670 else if (codec->vendor_id == 0x11064441)
4671 spec->stream_name_analog = "VT1828S Analog";
4673 spec->stream_name_analog = "VT1718S Analog";
4674 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4675 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4677 if (codec->vendor_id == 0x11060441)
4678 spec->stream_name_digital = "VT2020 Digital";
4679 else if (codec->vendor_id == 0x11064441)
4680 spec->stream_name_digital = "VT1828S Digital";
4682 spec->stream_name_digital = "VT1718S Digital";
4683 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4684 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4685 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4687 if (!spec->adc_nids && spec->input_mux) {
4688 spec->adc_nids = vt1718S_adc_nids;
4689 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4690 get_mux_nids(codec);
4691 override_mic_boost(codec, 0x2b, 0, 3, 40);
4692 override_mic_boost(codec, 0x29, 0, 3, 40);
4693 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4697 codec->patch_ops = via_patch_ops;
4699 codec->patch_ops.init = via_auto_init;
4700 codec->patch_ops.unsol_event = via_unsol_event;
4702 #ifdef CONFIG_SND_HDA_POWER_SAVE
4703 spec->loopback.amplist = vt1718S_loopbacks;
4706 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
4711 /* Patch for VT1716S */
4713 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4714 struct snd_ctl_elem_info *uinfo)
4716 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4718 uinfo->value.integer.min = 0;
4719 uinfo->value.integer.max = 1;
4723 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4724 struct snd_ctl_elem_value *ucontrol)
4726 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4729 index = snd_hda_codec_read(codec, 0x26, 0,
4730 AC_VERB_GET_CONNECT_SEL, 0);
4732 *ucontrol->value.integer.value = index;
4737 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4738 struct snd_ctl_elem_value *ucontrol)
4740 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4741 struct via_spec *spec = codec->spec;
4742 int index = *ucontrol->value.integer.value;
4744 snd_hda_codec_write(codec, 0x26, 0,
4745 AC_VERB_SET_CONNECT_SEL, index);
4746 spec->dmic_enabled = index;
4747 set_widgets_power_state(codec);
4751 /* capture mixer elements */
4752 static const struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4753 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4754 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4755 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4756 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4757 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4758 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4761 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4762 .name = "Input Source",
4764 .info = via_mux_enum_info,
4765 .get = via_mux_enum_get,
4766 .put = via_mux_enum_put,
4771 static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4772 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4774 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4775 .name = "Digital Mic Capture Switch",
4776 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4778 .info = vt1716s_dmic_info,
4779 .get = vt1716s_dmic_get,
4780 .put = vt1716s_dmic_put,
4786 /* mono-out mixer elements */
4787 static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4788 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4792 static const struct hda_verb vt1716S_volume_init_verbs[] = {
4794 * Unmute ADC0-1 and set the default input to mic-in
4796 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4797 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4800 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4803 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4804 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4805 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4806 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4807 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4808 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4810 /* MUX Indices: Stereo Mixer = 5 */
4811 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4813 /* Setup default input of PW4 to MW0 */
4814 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4816 /* Setup default input of SW1 as MW0 */
4817 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4819 /* Setup default input of SW4 as AOW0 */
4820 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4822 /* PW9 PW10 Output enable */
4823 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4824 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4826 /* Unmute SW1, PW12 */
4827 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4828 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4829 /* PW12 Output enable */
4830 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4831 /* Enable Boost Volume backdoor */
4833 /* don't bybass mixer */
4835 /* Enable mono output */
4841 static const struct hda_verb vt1716S_uniwill_init_verbs[] = {
4842 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4843 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4844 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4845 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4846 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4847 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4848 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4849 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4850 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4854 static const struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4858 .nid = 0x10, /* NID to query formats and rates */
4860 .open = via_playback_pcm_open,
4861 .prepare = via_playback_multi_pcm_prepare,
4862 .cleanup = via_playback_multi_pcm_cleanup,
4863 .close = via_pcm_open_close,
4867 static const struct hda_pcm_stream vt1716S_pcm_analog_capture = {
4871 .nid = 0x13, /* NID to query formats and rates */
4873 .open = via_pcm_open_close,
4874 .prepare = via_capture_pcm_prepare,
4875 .cleanup = via_capture_pcm_cleanup,
4876 .close = via_pcm_open_close,
4880 static const struct hda_pcm_stream vt1716S_pcm_digital_playback = {
4884 /* NID is set in via_build_pcms */
4886 .open = via_dig_playback_pcm_open,
4887 .close = via_dig_playback_pcm_close,
4888 .prepare = via_dig_playback_pcm_prepare,
4889 .cleanup = via_dig_playback_pcm_cleanup
4893 /* fill in the dac_nids table from the parsed pin configuration */
4894 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
4895 const struct auto_pin_cfg *cfg)
4899 spec->multiout.num_dacs = cfg->line_outs;
4901 spec->multiout.dac_nids = spec->private_dac_nids;
4903 for (i = 0; i < 3; i++) {
4904 nid = cfg->line_out_pins[i];
4906 /* config dac list */
4908 case AUTO_SEQ_FRONT:
4909 spec->private_dac_nids[i] = 0x10;
4911 case AUTO_SEQ_CENLFE:
4912 spec->private_dac_nids[i] = 0x25;
4914 case AUTO_SEQ_SURROUND:
4915 spec->private_dac_nids[i] = 0x11;
4924 /* add playback controls from the parsed DAC table */
4925 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
4926 const struct auto_pin_cfg *cfg)
4929 static const char * const chname[3] = {
4930 "Front", "Surround", "C/LFE"
4932 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
4933 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
4934 hda_nid_t nid, nid_vol, nid_mute;
4937 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
4938 nid = cfg->line_out_pins[i];
4943 nid_vol = nid_vols[i];
4944 nid_mute = nid_mutes[i];
4946 if (i == AUTO_SEQ_CENLFE) {
4947 err = via_add_control(
4948 spec, VIA_CTL_WIDGET_VOL,
4949 "Center Playback Volume",
4950 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
4953 err = via_add_control(
4954 spec, VIA_CTL_WIDGET_VOL,
4955 "LFE Playback Volume",
4956 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
4959 err = via_add_control(
4960 spec, VIA_CTL_WIDGET_MUTE,
4961 "Center Playback Switch",
4962 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4966 err = via_add_control(
4967 spec, VIA_CTL_WIDGET_MUTE,
4968 "LFE Playback Switch",
4969 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4973 } else if (i == AUTO_SEQ_FRONT) {
4975 err = via_add_control(
4976 spec, VIA_CTL_WIDGET_VOL,
4977 "Master Front Playback Volume",
4978 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
4981 err = via_add_control(
4982 spec, VIA_CTL_WIDGET_MUTE,
4983 "Master Front Playback Switch",
4984 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
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,
5002 sprintf(name, "%s Playback Volume", chname[i]);
5003 err = via_add_control(
5004 spec, VIA_CTL_WIDGET_VOL, name,
5005 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5008 sprintf(name, "%s Playback Switch", chname[i]);
5009 err = via_add_control(
5010 spec, VIA_CTL_WIDGET_MUTE, name,
5011 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5020 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5027 spec->multiout.hp_nid = 0x25; /* AOW3 */
5028 spec->hp_independent_mode_index = 1;
5030 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5031 "Headphone Playback Volume",
5032 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5036 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5037 "Headphone Playback Switch",
5038 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5042 create_hp_imux(spec);
5046 /* create playback/capture controls for input pins */
5047 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5048 const struct auto_pin_cfg *cfg)
5050 static const hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5051 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5052 ARRAY_SIZE(pin_idxs));
5055 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5057 struct via_spec *spec = codec->spec;
5060 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5063 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5066 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5067 return 0; /* can't find valid BIOS pin config */
5069 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5072 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5075 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5079 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5081 fill_dig_outs(codec);
5083 if (spec->kctls.list)
5084 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5086 spec->input_mux = &spec->private_imux[0];
5089 via_hp_build(codec);
5091 via_smart51_build(spec);
5096 #ifdef CONFIG_SND_HDA_POWER_SAVE
5097 static const struct hda_amp_list vt1716S_loopbacks[] = {
5098 { 0x16, HDA_INPUT, 1 },
5099 { 0x16, HDA_INPUT, 2 },
5100 { 0x16, HDA_INPUT, 3 },
5101 { 0x16, HDA_INPUT, 4 },
5106 static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
5108 struct via_spec *spec = codec->spec;
5111 unsigned int mono_out, present;
5112 /* SW0 (17h) = stereo mixer */
5114 (snd_hda_codec_read(codec, 0x17, 0,
5115 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
5117 /* PW 1/2/5 (1ah/1bh/1eh) */
5119 set_pin_power_state(codec, 0x1a, &parm);
5120 set_pin_power_state(codec, 0x1b, &parm);
5121 set_pin_power_state(codec, 0x1e, &parm);
5124 /* SW0 (17h), AIW0(13h) */
5125 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
5126 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
5129 set_pin_power_state(codec, 0x1e, &parm);
5131 if (spec->dmic_enabled)
5132 set_pin_power_state(codec, 0x22, &parm);
5134 snd_hda_codec_write(codec, 0x22, 0,
5135 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5137 /* SW2(26h), AIW1(14h) */
5138 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
5139 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
5142 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
5144 set_pin_power_state(codec, 0x19, &parm);
5145 /* Smart 5.1 PW2(1bh) */
5146 if (spec->smart51_enabled)
5147 set_pin_power_state(codec, 0x1b, &parm);
5148 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
5149 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5151 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
5153 set_pin_power_state(codec, 0x23, &parm);
5154 /* Smart 5.1 PW1(1ah) */
5155 if (spec->smart51_enabled)
5156 set_pin_power_state(codec, 0x1a, &parm);
5157 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
5159 /* Smart 5.1 PW5(1eh) */
5160 if (spec->smart51_enabled)
5161 set_pin_power_state(codec, 0x1e, &parm);
5162 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
5165 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
5166 present = snd_hda_jack_detect(codec, 0x1c);
5171 present = snd_hda_jack_detect(codec, 0x1d);
5172 if (!spec->hp_independent_mode && present)
5177 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
5178 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
5179 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
5180 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
5182 /* PW 3/4 (1ch/1dh) */
5184 set_pin_power_state(codec, 0x1c, &parm);
5185 set_pin_power_state(codec, 0x1d, &parm);
5186 /* HP Independent Mode, power on AOW3 */
5187 if (spec->hp_independent_mode)
5188 snd_hda_codec_write(codec, 0x25, 0,
5189 AC_VERB_SET_POWER_STATE, parm);
5191 /* force to D0 for internal Speaker */
5192 /* MW0 (16h), AOW0 (10h) */
5193 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
5194 imux_is_smixer ? AC_PWRST_D0 : parm);
5195 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
5196 mono_out ? AC_PWRST_D0 : parm);
5199 static int patch_vt1716S(struct hda_codec *codec)
5201 struct via_spec *spec;
5204 /* create a codec specific record */
5205 spec = via_new_spec(codec);
5209 /* automatic parse from the BIOS config */
5210 err = vt1716S_parse_auto_config(codec);
5215 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5216 "from BIOS. Using genenic mode...\n");
5219 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5220 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5222 spec->stream_name_analog = "VT1716S Analog";
5223 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5224 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5226 spec->stream_name_digital = "VT1716S Digital";
5227 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5229 if (!spec->adc_nids && spec->input_mux) {
5230 spec->adc_nids = vt1716S_adc_nids;
5231 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5232 get_mux_nids(codec);
5233 override_mic_boost(codec, 0x1a, 0, 3, 40);
5234 override_mic_boost(codec, 0x1e, 0, 3, 40);
5235 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5239 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5242 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5244 codec->patch_ops = via_patch_ops;
5246 codec->patch_ops.init = via_auto_init;
5247 codec->patch_ops.unsol_event = via_unsol_event;
5249 #ifdef CONFIG_SND_HDA_POWER_SAVE
5250 spec->loopback.amplist = vt1716S_loopbacks;
5253 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
5259 /* capture mixer elements */
5260 static const struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5261 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5262 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5263 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5264 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5265 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5266 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5269 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5270 /* The multiple "Capture Source" controls confuse alsamixer
5271 * So call somewhat different..
5273 /* .name = "Capture Source", */
5274 .name = "Input Source",
5276 .info = via_mux_enum_info,
5277 .get = via_mux_enum_get,
5278 .put = via_mux_enum_put,
5283 static const struct hda_verb vt2002P_volume_init_verbs[] = {
5284 /* Class-D speaker related verbs */
5289 * Unmute ADC0-1 and set the default input to mic-in
5291 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5292 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5295 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5298 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5299 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5300 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5301 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5302 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5303 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5305 /* MUX Indices: Mic = 0 */
5306 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5307 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5309 /* PW9 Output enable */
5310 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5312 /* Enable Boost Volume backdoor */
5315 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5316 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5317 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5318 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5319 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5320 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5321 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5322 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5323 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5325 /* set MUX0/1/4/8 = 0 (AOW0) */
5326 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5327 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5328 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5329 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5331 /* set PW0 index=0 (MW0) */
5332 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5334 /* Enable AOW0 to MW9 */
5338 static const struct hda_verb vt1802_volume_init_verbs[] = {
5340 * Unmute ADC0-1 and set the default input to mic-in
5342 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5343 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5346 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5349 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5350 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5351 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5352 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5353 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5354 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5356 /* MUX Indices: Mic = 0 */
5357 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5358 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5360 /* PW9 Output enable */
5361 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5363 /* Enable Boost Volume backdoor */
5366 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5367 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5368 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5369 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5370 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5371 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5372 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5373 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5374 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5376 /* set MUX0/1/4/8 = 0 (AOW0) */
5377 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5378 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5379 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5380 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5382 /* set PW0 index=0 (MW0) */
5383 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5385 /* Enable AOW0 to MW9 */
5391 static const struct hda_verb vt2002P_uniwill_init_verbs[] = {
5392 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5393 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5394 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5395 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5396 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5397 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5398 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5401 static const struct hda_verb vt1802_uniwill_init_verbs[] = {
5402 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5403 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5404 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5405 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5406 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5407 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5408 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5412 static const struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5416 .nid = 0x8, /* NID to query formats and rates */
5418 .open = via_playback_pcm_open,
5419 .prepare = via_playback_multi_pcm_prepare,
5420 .cleanup = via_playback_multi_pcm_cleanup,
5421 .close = via_pcm_open_close,
5425 static const struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5429 .nid = 0x10, /* NID to query formats and rates */
5431 .open = via_pcm_open_close,
5432 .prepare = via_capture_pcm_prepare,
5433 .cleanup = via_capture_pcm_cleanup,
5434 .close = via_pcm_open_close,
5438 static const struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5442 /* NID is set in via_build_pcms */
5444 .open = via_dig_playback_pcm_open,
5445 .close = via_dig_playback_pcm_close,
5446 .prepare = via_dig_playback_pcm_prepare,
5447 .cleanup = via_dig_playback_pcm_cleanup
5451 /* fill in the dac_nids table from the parsed pin configuration */
5452 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5453 const struct auto_pin_cfg *cfg)
5455 spec->multiout.num_dacs = 1;
5456 spec->multiout.dac_nids = spec->private_dac_nids;
5457 if (cfg->line_out_pins[0])
5458 spec->private_dac_nids[0] = 0x8;
5462 /* add playback controls from the parsed DAC table */
5463 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5464 const struct auto_pin_cfg *cfg)
5469 if (!cfg->line_out_pins[0])
5472 if (spec->codec_type == VT1802)
5477 /* Line-Out: PortE */
5478 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5479 "Master Front Playback Volume",
5480 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5483 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5484 "Master Front Playback Switch",
5485 HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT));
5492 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5499 spec->multiout.hp_nid = 0x9;
5500 spec->hp_independent_mode_index = 1;
5502 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5503 "Headphone Playback Volume",
5504 HDA_COMPOSE_AMP_VAL(
5505 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5509 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5510 "Headphone Playback Switch",
5511 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5515 create_hp_imux(spec);
5519 /* create playback/capture controls for input pins */
5520 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5521 const struct auto_pin_cfg *cfg)
5523 struct via_spec *spec = codec->spec;
5524 struct hda_input_mux *imux = &spec->private_imux[0];
5525 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5528 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5529 ARRAY_SIZE(pin_idxs));
5532 /* build volume/mute control of loopback */
5533 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5537 /* for digital mic select */
5538 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5543 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5545 struct via_spec *spec = codec->spec;
5549 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5553 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5557 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5558 return 0; /* can't find valid BIOS pin config */
5560 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5563 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5566 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5570 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5572 fill_dig_outs(codec);
5574 if (spec->kctls.list)
5575 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5577 spec->input_mux = &spec->private_imux[0];
5580 via_hp_build(codec);
5585 #ifdef CONFIG_SND_HDA_POWER_SAVE
5586 static const struct hda_amp_list vt2002P_loopbacks[] = {
5587 { 0x21, HDA_INPUT, 0 },
5588 { 0x21, HDA_INPUT, 1 },
5589 { 0x21, HDA_INPUT, 2 },
5594 static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
5596 struct via_spec *spec = codec->spec;
5599 unsigned int present;
5600 /* MUX9 (1eh) = stereo mixer */
5602 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
5604 /* PW 5/6/7 (29h/2ah/2bh) */
5606 set_pin_power_state(codec, 0x29, &parm);
5607 set_pin_power_state(codec, 0x2a, &parm);
5608 set_pin_power_state(codec, 0x2b, &parm);
5610 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
5611 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
5612 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
5613 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
5614 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
5618 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
5620 if (spec->codec_type == VT1802) {
5621 /* PW4 (28h), MW4 (18h), MUX4(38h) */
5623 set_pin_power_state(codec, 0x28, &parm);
5624 snd_hda_codec_write(codec, 0x18, 0,
5625 AC_VERB_SET_POWER_STATE, parm);
5626 snd_hda_codec_write(codec, 0x38, 0,
5627 AC_VERB_SET_POWER_STATE, parm);
5629 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
5631 set_pin_power_state(codec, 0x26, &parm);
5632 snd_hda_codec_write(codec, 0x1c, 0,
5633 AC_VERB_SET_POWER_STATE, parm);
5634 snd_hda_codec_write(codec, 0x37, 0,
5635 AC_VERB_SET_POWER_STATE, parm);
5638 if (spec->codec_type == VT1802) {
5639 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
5641 set_pin_power_state(codec, 0x25, &parm);
5642 snd_hda_codec_write(codec, 0x15, 0,
5643 AC_VERB_SET_POWER_STATE, parm);
5644 snd_hda_codec_write(codec, 0x35, 0,
5645 AC_VERB_SET_POWER_STATE, parm);
5647 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
5649 set_pin_power_state(codec, 0x25, &parm);
5650 snd_hda_codec_write(codec, 0x19, 0,
5651 AC_VERB_SET_POWER_STATE, parm);
5652 snd_hda_codec_write(codec, 0x35, 0,
5653 AC_VERB_SET_POWER_STATE, parm);
5656 if (spec->hp_independent_mode)
5657 snd_hda_codec_write(codec, 0x9, 0,
5658 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5661 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
5662 present = snd_hda_jack_detect(codec, 0x25);
5665 set_pin_power_state(codec, 0x24, &parm);
5666 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5667 if (spec->codec_type == VT1802)
5668 snd_hda_codec_write(codec, 0x14, 0,
5669 AC_VERB_SET_POWER_STATE, parm);
5671 snd_hda_codec_write(codec, 0x18, 0,
5672 AC_VERB_SET_POWER_STATE, parm);
5673 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
5676 present = snd_hda_jack_detect(codec, 0x26);
5678 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
5679 if (spec->codec_type == VT1802) {
5680 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
5681 snd_hda_codec_write(codec, 0x33, 0,
5682 AC_VERB_SET_POWER_STATE, parm);
5683 snd_hda_codec_write(codec, 0x1c, 0,
5684 AC_VERB_SET_POWER_STATE, parm);
5685 snd_hda_codec_write(codec, 0x3c, 0,
5686 AC_VERB_SET_POWER_STATE, parm);
5688 /* PW15 (31h), MW8(17h), MUX8(3bh) */
5689 snd_hda_codec_write(codec, 0x31, 0,
5690 AC_VERB_SET_POWER_STATE, parm);
5691 snd_hda_codec_write(codec, 0x17, 0,
5692 AC_VERB_SET_POWER_STATE, parm);
5693 snd_hda_codec_write(codec, 0x3b, 0,
5694 AC_VERB_SET_POWER_STATE, parm);
5697 if (imux_is_smixer || !is_aa_path_mute(codec))
5698 snd_hda_codec_write(codec, 0x21, 0,
5699 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
5701 snd_hda_codec_write(codec, 0x21, 0,
5702 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5705 /* patch for vt2002P */
5706 static int patch_vt2002P(struct hda_codec *codec)
5708 struct via_spec *spec;
5711 /* create a codec specific record */
5712 spec = via_new_spec(codec);
5716 /* automatic parse from the BIOS config */
5717 err = vt2002P_parse_auto_config(codec);
5722 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5723 "from BIOS. Using genenic mode...\n");
5726 if (spec->codec_type == VT1802)
5727 spec->init_verbs[spec->num_iverbs++] =
5728 vt1802_volume_init_verbs;
5730 spec->init_verbs[spec->num_iverbs++] =
5731 vt2002P_volume_init_verbs;
5733 if (spec->codec_type == VT1802)
5734 spec->init_verbs[spec->num_iverbs++] =
5735 vt1802_uniwill_init_verbs;
5737 spec->init_verbs[spec->num_iverbs++] =
5738 vt2002P_uniwill_init_verbs;
5740 if (spec->codec_type == VT1802)
5741 spec->stream_name_analog = "VT1802 Analog";
5743 spec->stream_name_analog = "VT2002P Analog";
5744 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5745 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5747 if (spec->codec_type == VT1802)
5748 spec->stream_name_digital = "VT1802 Digital";
5750 spec->stream_name_digital = "VT2002P Digital";
5751 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5753 if (!spec->adc_nids && spec->input_mux) {
5754 spec->adc_nids = vt2002P_adc_nids;
5755 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5756 get_mux_nids(codec);
5757 override_mic_boost(codec, 0x2b, 0, 3, 40);
5758 override_mic_boost(codec, 0x29, 0, 3, 40);
5759 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5763 codec->patch_ops = via_patch_ops;
5765 codec->patch_ops.init = via_auto_init;
5766 codec->patch_ops.unsol_event = via_unsol_event;
5768 #ifdef CONFIG_SND_HDA_POWER_SAVE
5769 spec->loopback.amplist = vt2002P_loopbacks;
5772 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
5778 /* capture mixer elements */
5779 static const struct snd_kcontrol_new vt1812_capture_mixer[] = {
5780 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5781 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5782 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5783 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5784 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5785 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5789 /* The multiple "Capture Source" controls confuse alsamixer
5790 * So call somewhat different..
5792 .name = "Input Source",
5794 .info = via_mux_enum_info,
5795 .get = via_mux_enum_get,
5796 .put = via_mux_enum_put,
5801 static const struct hda_verb vt1812_volume_init_verbs[] = {
5803 * Unmute ADC0-1 and set the default input to mic-in
5805 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5806 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5809 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5812 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5813 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5814 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5815 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5816 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5817 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5819 /* MUX Indices: Mic = 0 */
5820 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5821 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5823 /* PW9 Output enable */
5824 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5826 /* Enable Boost Volume backdoor */
5829 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5830 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5831 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5832 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5833 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5834 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5835 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5836 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5837 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5838 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5839 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5841 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5842 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5843 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5844 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5845 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5846 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5848 /* Enable AOW0 to MW9 */
5854 static const struct hda_verb vt1812_uniwill_init_verbs[] = {
5855 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5856 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5857 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5858 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5859 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5860 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5861 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5862 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5866 static const struct hda_pcm_stream vt1812_pcm_analog_playback = {
5870 .nid = 0x8, /* NID to query formats and rates */
5872 .open = via_playback_pcm_open,
5873 .prepare = via_playback_multi_pcm_prepare,
5874 .cleanup = via_playback_multi_pcm_cleanup,
5875 .close = via_pcm_open_close,
5879 static const struct hda_pcm_stream vt1812_pcm_analog_capture = {
5883 .nid = 0x10, /* NID to query formats and rates */
5885 .open = via_pcm_open_close,
5886 .prepare = via_capture_pcm_prepare,
5887 .cleanup = via_capture_pcm_cleanup,
5888 .close = via_pcm_open_close,
5892 static const struct hda_pcm_stream vt1812_pcm_digital_playback = {
5896 /* NID is set in via_build_pcms */
5898 .open = via_dig_playback_pcm_open,
5899 .close = via_dig_playback_pcm_close,
5900 .prepare = via_dig_playback_pcm_prepare,
5901 .cleanup = via_dig_playback_pcm_cleanup
5904 /* fill in the dac_nids table from the parsed pin configuration */
5905 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5906 const struct auto_pin_cfg *cfg)
5908 spec->multiout.num_dacs = 1;
5909 spec->multiout.dac_nids = spec->private_dac_nids;
5910 if (cfg->line_out_pins[0])
5911 spec->private_dac_nids[0] = 0x8;
5916 /* add playback controls from the parsed DAC table */
5917 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5918 const struct auto_pin_cfg *cfg)
5922 if (!cfg->line_out_pins[0])
5925 /* Line-Out: PortE */
5926 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5927 "Front Playback Volume",
5928 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5931 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5932 "Front Playback Switch",
5933 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5940 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5947 spec->multiout.hp_nid = 0x9;
5948 spec->hp_independent_mode_index = 1;
5951 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5952 "Headphone Playback Volume",
5953 HDA_COMPOSE_AMP_VAL(
5954 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5958 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5959 "Headphone Playback Switch",
5960 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5964 create_hp_imux(spec);
5968 /* create playback/capture controls for input pins */
5969 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5970 const struct auto_pin_cfg *cfg)
5972 struct via_spec *spec = codec->spec;
5973 struct hda_input_mux *imux = &spec->private_imux[0];
5974 static const hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5977 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5978 ARRAY_SIZE(pin_idxs));
5982 /* build volume/mute control of loopback */
5983 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5987 /* for digital mic select */
5988 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5993 static int vt1812_parse_auto_config(struct hda_codec *codec)
5995 struct via_spec *spec = codec->spec;
5999 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6002 fill_dig_outs(codec);
6003 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6007 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6008 return 0; /* can't find valid BIOS pin config */
6010 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6013 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6016 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
6020 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6022 fill_dig_outs(codec);
6024 if (spec->kctls.list)
6025 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6027 spec->input_mux = &spec->private_imux[0];
6030 via_hp_build(codec);
6035 #ifdef CONFIG_SND_HDA_POWER_SAVE
6036 static const struct hda_amp_list vt1812_loopbacks[] = {
6037 { 0x21, HDA_INPUT, 0 },
6038 { 0x21, HDA_INPUT, 1 },
6039 { 0x21, HDA_INPUT, 2 },
6044 static void set_widgets_power_state_vt1812(struct hda_codec *codec)
6046 struct via_spec *spec = codec->spec;
6047 int imux_is_smixer =
6048 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
6050 unsigned int present;
6051 /* MUX10 (1eh) = stereo mixer */
6053 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
6055 /* PW 5/6/7 (29h/2ah/2bh) */
6057 set_pin_power_state(codec, 0x29, &parm);
6058 set_pin_power_state(codec, 0x2a, &parm);
6059 set_pin_power_state(codec, 0x2b, &parm);
6061 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
6062 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
6063 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
6064 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
6065 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
6069 snd_hda_codec_write(codec, 0x8, 0,
6070 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6072 /* PW4 (28h), MW4 (18h), MUX4(38h) */
6074 set_pin_power_state(codec, 0x28, &parm);
6075 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
6076 snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
6078 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
6080 set_pin_power_state(codec, 0x25, &parm);
6081 snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
6082 snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
6083 if (spec->hp_independent_mode)
6084 snd_hda_codec_write(codec, 0x9, 0,
6085 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6087 /* Internal Speaker */
6088 /* PW0 (24h), MW0(14h), MUX0(34h) */
6089 present = snd_hda_jack_detect(codec, 0x25);
6092 set_pin_power_state(codec, 0x24, &parm);
6094 snd_hda_codec_write(codec, 0x14, 0,
6095 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6096 snd_hda_codec_write(codec, 0x34, 0,
6097 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6099 snd_hda_codec_write(codec, 0x14, 0,
6100 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6101 snd_hda_codec_write(codec, 0x34, 0,
6102 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6107 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
6108 present = snd_hda_jack_detect(codec, 0x28);
6111 set_pin_power_state(codec, 0x31, &parm);
6113 snd_hda_codec_write(codec, 0x1c, 0,
6114 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6115 snd_hda_codec_write(codec, 0x3c, 0,
6116 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6117 snd_hda_codec_write(codec, 0x3e, 0,
6118 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
6120 snd_hda_codec_write(codec, 0x1c, 0,
6121 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6122 snd_hda_codec_write(codec, 0x3c, 0,
6123 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6124 snd_hda_codec_write(codec, 0x3e, 0,
6125 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
6128 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
6130 set_pin_power_state(codec, 0x33, &parm);
6131 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
6132 snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
6136 /* patch for vt1812 */
6137 static int patch_vt1812(struct hda_codec *codec)
6139 struct via_spec *spec;
6142 /* create a codec specific record */
6143 spec = via_new_spec(codec);
6147 /* automatic parse from the BIOS config */
6148 err = vt1812_parse_auto_config(codec);
6153 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6154 "from BIOS. Using genenic mode...\n");
6158 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6159 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6161 spec->stream_name_analog = "VT1812 Analog";
6162 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6163 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6165 spec->stream_name_digital = "VT1812 Digital";
6166 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6169 if (!spec->adc_nids && spec->input_mux) {
6170 spec->adc_nids = vt1812_adc_nids;
6171 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6172 get_mux_nids(codec);
6173 override_mic_boost(codec, 0x2b, 0, 3, 40);
6174 override_mic_boost(codec, 0x29, 0, 3, 40);
6175 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6179 codec->patch_ops = via_patch_ops;
6181 codec->patch_ops.init = via_auto_init;
6182 codec->patch_ops.unsol_event = via_unsol_event;
6184 #ifdef CONFIG_SND_HDA_POWER_SAVE
6185 spec->loopback.amplist = vt1812_loopbacks;
6188 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
6195 static const struct hda_codec_preset snd_hda_preset_via[] = {
6196 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6197 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6198 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6199 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6200 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6201 .patch = patch_vt1709_10ch},
6202 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6203 .patch = patch_vt1709_10ch},
6204 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6205 .patch = patch_vt1709_10ch},
6206 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6207 .patch = patch_vt1709_10ch},
6208 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6209 .patch = patch_vt1709_6ch},
6210 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6211 .patch = patch_vt1709_6ch},
6212 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6213 .patch = patch_vt1709_6ch},
6214 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6215 .patch = patch_vt1709_6ch},
6216 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6217 .patch = patch_vt1708B_8ch},
6218 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6219 .patch = patch_vt1708B_8ch},
6220 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6221 .patch = patch_vt1708B_8ch},
6222 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6223 .patch = patch_vt1708B_8ch},
6224 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6225 .patch = patch_vt1708B_4ch},
6226 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6227 .patch = patch_vt1708B_4ch},
6228 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6229 .patch = patch_vt1708B_4ch},
6230 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6231 .patch = patch_vt1708B_4ch},
6232 { .id = 0x11060397, .name = "VT1708S",
6233 .patch = patch_vt1708S},
6234 { .id = 0x11061397, .name = "VT1708S",
6235 .patch = patch_vt1708S},
6236 { .id = 0x11062397, .name = "VT1708S",
6237 .patch = patch_vt1708S},
6238 { .id = 0x11063397, .name = "VT1708S",
6239 .patch = patch_vt1708S},
6240 { .id = 0x11064397, .name = "VT1705",
6241 .patch = patch_vt1708S},
6242 { .id = 0x11065397, .name = "VT1708S",
6243 .patch = patch_vt1708S},
6244 { .id = 0x11066397, .name = "VT1708S",
6245 .patch = patch_vt1708S},
6246 { .id = 0x11067397, .name = "VT1708S",
6247 .patch = patch_vt1708S},
6248 { .id = 0x11060398, .name = "VT1702",
6249 .patch = patch_vt1702},
6250 { .id = 0x11061398, .name = "VT1702",
6251 .patch = patch_vt1702},
6252 { .id = 0x11062398, .name = "VT1702",
6253 .patch = patch_vt1702},
6254 { .id = 0x11063398, .name = "VT1702",
6255 .patch = patch_vt1702},
6256 { .id = 0x11064398, .name = "VT1702",
6257 .patch = patch_vt1702},
6258 { .id = 0x11065398, .name = "VT1702",
6259 .patch = patch_vt1702},
6260 { .id = 0x11066398, .name = "VT1702",
6261 .patch = patch_vt1702},
6262 { .id = 0x11067398, .name = "VT1702",
6263 .patch = patch_vt1702},
6264 { .id = 0x11060428, .name = "VT1718S",
6265 .patch = patch_vt1718S},
6266 { .id = 0x11064428, .name = "VT1718S",
6267 .patch = patch_vt1718S},
6268 { .id = 0x11060441, .name = "VT2020",
6269 .patch = patch_vt1718S},
6270 { .id = 0x11064441, .name = "VT1828S",
6271 .patch = patch_vt1718S},
6272 { .id = 0x11060433, .name = "VT1716S",
6273 .patch = patch_vt1716S},
6274 { .id = 0x1106a721, .name = "VT1716S",
6275 .patch = patch_vt1716S},
6276 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6277 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6278 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6279 { .id = 0x11060440, .name = "VT1818S",
6280 .patch = patch_vt1708S},
6281 { .id = 0x11060446, .name = "VT1802",
6282 .patch = patch_vt2002P},
6283 { .id = 0x11068446, .name = "VT1802",
6284 .patch = patch_vt2002P},
6288 MODULE_ALIAS("snd-hda-codec-id:1106*");
6290 static struct hda_codec_preset_list via_list = {
6291 .preset = snd_hda_preset_via,
6292 .owner = THIS_MODULE,
6295 MODULE_LICENSE("GPL");
6296 MODULE_DESCRIPTION("VIA HD-audio codec");
6298 static int __init patch_via_init(void)
6300 return snd_hda_add_codec_preset(&via_list);
6303 static void __exit patch_via_exit(void)
6305 snd_hda_delete_codec_preset(&via_list);
6308 module_init(patch_via_init)
6309 module_exit(patch_via_exit)