2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
6 * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
7 * 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 */
40 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 #include <linux/init.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <sound/core.h>
47 #include <sound/asoundef.h>
48 #include "hda_codec.h"
49 #include "hda_local.h"
52 #define AMP_VAL_IDX_SHIFT 19
53 #define AMP_VAL_IDX_MASK (0x0f<<19)
56 #define VT1708_HP_NID 0x13
57 #define VT1708_DIGOUT_NID 0x14
58 #define VT1708_DIGIN_NID 0x16
59 #define VT1708_DIGIN_PIN 0x26
60 #define VT1708_HP_PIN_NID 0x20
61 #define VT1708_CD_PIN_NID 0x24
63 #define VT1709_HP_DAC_NID 0x28
64 #define VT1709_DIGOUT_NID 0x13
65 #define VT1709_DIGIN_NID 0x17
66 #define VT1709_DIGIN_PIN 0x25
68 #define VT1708B_HP_NID 0x25
69 #define VT1708B_DIGOUT_NID 0x12
70 #define VT1708B_DIGIN_NID 0x15
71 #define VT1708B_DIGIN_PIN 0x21
73 #define VT1708S_HP_NID 0x25
74 #define VT1708S_DIGOUT_NID 0x12
76 #define VT1702_HP_NID 0x17
77 #define VT1702_DIGOUT_NID 0x11
79 #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
80 #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
81 #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
82 #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
83 #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
84 #define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
85 #define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
99 static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
101 u16 ven_id = vendor_id >> 16;
102 u16 dev_id = vendor_id & 0xffff;
103 enum VIA_HDA_CODEC codec_type;
106 if (ven_id != 0x1106)
107 codec_type = UNKNOWN;
108 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
110 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
111 codec_type = VT1709_10CH;
112 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
113 codec_type = VT1709_6CH;
114 else if (dev_id >= 0xe720 && dev_id <= 0xe723)
115 codec_type = VT1708B_8CH;
116 else if (dev_id >= 0xe724 && dev_id <= 0xe727)
117 codec_type = VT1708B_4CH;
118 else if ((dev_id & 0xfff) == 0x397
119 && (dev_id >> 12) < 8)
120 codec_type = VT1708S;
121 else if ((dev_id & 0xfff) == 0x398
122 && (dev_id >> 12) < 8)
125 codec_type = UNKNOWN;
129 #define VIA_HP_EVENT 0x01
130 #define VIA_GPIO_EVENT 0x02
144 /* Some VT1708S based boards gets the micboost setting wrong, so we have
145 * to apply some brute-force and re-write the TLV's by software. */
146 static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
147 unsigned int size, unsigned int __user *_tlv)
149 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
150 hda_nid_t nid = get_amp_nid(kcontrol);
152 if (get_codec_type(codec->vendor_id) == VT1708S
153 && (nid == 0x1a || nid == 0x1e)) {
154 if (size < 4 * sizeof(unsigned int))
156 if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */
158 if (put_user(2 * sizeof(unsigned int), _tlv + 1))
160 if (put_user(0, _tlv + 2)) /* offset = 0 */
162 if (put_user(1000, _tlv + 3)) /* step size = 10 dB */
168 static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
169 struct snd_ctl_elem_info *uinfo)
171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
172 hda_nid_t nid = get_amp_nid(kcontrol);
174 if (get_codec_type(codec->vendor_id) == VT1708S
175 && (nid == 0x1a || nid == 0x1e)) {
176 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
178 uinfo->value.integer.min = 0;
179 uinfo->value.integer.max = 3;
184 static struct snd_kcontrol_new vt1708_control_templates[] = {
185 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
186 HDA_CODEC_MUTE(NULL, 0, 0, 0),
191 /* codec parameterization */
192 struct snd_kcontrol_new *mixers[3];
193 unsigned int num_mixers;
195 struct hda_verb *init_verbs[5];
196 unsigned int num_iverbs;
198 char *stream_name_analog;
199 struct hda_pcm_stream *stream_analog_playback;
200 struct hda_pcm_stream *stream_analog_capture;
202 char *stream_name_digital;
203 struct hda_pcm_stream *stream_digital_playback;
204 struct hda_pcm_stream *stream_digital_capture;
207 struct hda_multi_out multiout;
208 hda_nid_t extra_dig_out_nid;
211 unsigned int num_adc_nids;
213 hda_nid_t dig_in_nid;
216 const struct hda_input_mux *input_mux;
217 unsigned int cur_mux[3];
219 /* PCM information */
220 struct hda_pcm pcm_rec[3];
222 /* dynamic controls, init_verbs and input_mux */
223 struct auto_pin_cfg autocfg;
224 struct snd_array kctls;
225 struct hda_input_mux private_imux[2];
226 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
229 const struct hda_input_mux *hp_mux;
230 unsigned int hp_independent_mode;
232 #ifdef CONFIG_SND_HDA_POWER_SAVE
233 struct hda_loopback_check loopback;
237 static hda_nid_t vt1708_adc_nids[2] = {
242 static hda_nid_t vt1709_adc_nids[3] = {
247 static hda_nid_t vt1708B_adc_nids[2] = {
252 static hda_nid_t vt1708S_adc_nids[2] = {
257 static hda_nid_t vt1702_adc_nids[3] = {
262 /* add dynamic controls */
263 static int via_add_control(struct via_spec *spec, int type, const char *name,
266 struct snd_kcontrol_new *knew;
268 snd_array_init(&spec->kctls, sizeof(*knew), 32);
269 knew = snd_array_new(&spec->kctls);
272 *knew = vt1708_control_templates[type];
273 knew->name = kstrdup(name, GFP_KERNEL);
276 knew->private_value = val;
280 static void via_free_kctls(struct hda_codec *codec)
282 struct via_spec *spec = codec->spec;
284 if (spec->kctls.list) {
285 struct snd_kcontrol_new *kctl = spec->kctls.list;
287 for (i = 0; i < spec->kctls.used; i++)
290 snd_array_free(&spec->kctls);
293 /* create input playback/capture controls for the given pin */
294 static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
295 const char *ctlname, int idx, int mix_nid)
300 sprintf(name, "%s Playback Volume", ctlname);
301 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
302 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
305 sprintf(name, "%s Playback Switch", ctlname);
306 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
307 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
313 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
314 hda_nid_t nid, int pin_type,
318 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
320 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
325 static void via_auto_init_multi_out(struct hda_codec *codec)
327 struct via_spec *spec = codec->spec;
330 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
331 hda_nid_t nid = spec->autocfg.line_out_pins[i];
333 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
337 static void via_auto_init_hp_out(struct hda_codec *codec)
339 struct via_spec *spec = codec->spec;
342 pin = spec->autocfg.hp_pins[0];
343 if (pin) /* connect to front */
344 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
347 static void via_auto_init_analog_input(struct hda_codec *codec)
349 struct via_spec *spec = codec->spec;
352 for (i = 0; i < AUTO_PIN_LAST; i++) {
353 hda_nid_t nid = spec->autocfg.input_pins[i];
355 snd_hda_codec_write(codec, nid, 0,
356 AC_VERB_SET_PIN_WIDGET_CONTROL,
357 (i <= AUTO_PIN_FRONT_MIC ?
358 PIN_VREF50 : PIN_IN));
365 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
366 struct snd_ctl_elem_info *uinfo)
368 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
369 struct via_spec *spec = codec->spec;
370 return snd_hda_input_mux_info(spec->input_mux, uinfo);
373 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
374 struct snd_ctl_elem_value *ucontrol)
376 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377 struct via_spec *spec = codec->spec;
378 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
380 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
384 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
385 struct snd_ctl_elem_value *ucontrol)
387 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388 struct via_spec *spec = codec->spec;
389 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
390 unsigned int vendor_id = codec->vendor_id;
392 /* AIW0 lydia 060801 add for correct sw0 input select */
393 if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
394 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
395 0x18, &spec->cur_mux[adc_idx]);
396 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
397 IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0))
398 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
399 0x19, &spec->cur_mux[adc_idx]);
400 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
401 IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0))
402 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
403 0x17, &spec->cur_mux[adc_idx]);
404 else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0))
405 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
406 0x13, &spec->cur_mux[adc_idx]);
408 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
409 spec->adc_nids[adc_idx],
410 &spec->cur_mux[adc_idx]);
413 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
414 struct snd_ctl_elem_info *uinfo)
416 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
417 struct via_spec *spec = codec->spec;
418 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
421 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
422 struct snd_ctl_elem_value *ucontrol)
424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
425 struct via_spec *spec = codec->spec;
426 hda_nid_t nid = spec->autocfg.hp_pins[0];
427 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
428 AC_VERB_GET_CONNECT_SEL,
431 ucontrol->value.enumerated.item[0] = pinsel;
436 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
437 struct snd_ctl_elem_value *ucontrol)
439 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
440 struct via_spec *spec = codec->spec;
441 hda_nid_t nid = spec->autocfg.hp_pins[0];
442 unsigned int pinsel = ucontrol->value.enumerated.item[0];
443 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
444 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
446 if (con_nid == spec->multiout.hp_nid) {
448 if (!spec->hp_independent_mode) {
449 if (spec->multiout.num_dacs > 1)
450 spec->multiout.num_dacs -= 1;
451 spec->hp_independent_mode = 1;
453 } else if (pinsel == 1) {
454 if (spec->hp_independent_mode) {
455 if (spec->multiout.num_dacs > 1)
456 spec->multiout.num_dacs += 1;
457 spec->hp_independent_mode = 0;
462 if (spec->hp_independent_mode) {
463 if (spec->multiout.num_dacs > 1)
464 spec->multiout.num_dacs += 1;
465 spec->hp_independent_mode = 0;
467 } else if (pinsel == 1) {
468 if (!spec->hp_independent_mode) {
469 if (spec->multiout.num_dacs > 1)
470 spec->multiout.num_dacs -= 1;
471 spec->hp_independent_mode = 1;
475 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
478 if (spec->multiout.hp_nid &&
479 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
480 snd_hda_codec_setup_stream(codec,
481 spec->multiout.hp_nid,
487 static struct snd_kcontrol_new via_hp_mixer[] = {
489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
490 .name = "Independent HP",
492 .info = via_independent_hp_info,
493 .get = via_independent_hp_get,
494 .put = via_independent_hp_put,
499 /* capture mixer elements */
500 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
501 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
502 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
503 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
504 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
506 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
507 /* The multiple "Capture Source" controls confuse alsamixer
508 * So call somewhat different..
510 /* .name = "Capture Source", */
511 .name = "Input Source",
513 .info = via_mux_enum_info,
514 .get = via_mux_enum_get,
515 .put = via_mux_enum_put,
520 * generic initialization of ADC, input mixers and output mixers
522 static struct hda_verb vt1708_volume_init_verbs[] = {
524 * Unmute ADC0-1 and set the default input to mic-in
526 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
527 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
530 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
533 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
534 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
535 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
536 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
537 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
538 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
541 * Set up output mixers (0x19 - 0x1b)
543 /* set vol=0 to output mixers */
544 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
545 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
546 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
548 /* Setup default input to PW4 */
549 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
550 /* PW9 Output enable */
551 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
555 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
556 struct hda_codec *codec,
557 struct snd_pcm_substream *substream)
559 struct via_spec *spec = codec->spec;
560 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
564 static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
565 struct hda_codec *codec,
566 unsigned int stream_tag,
568 struct snd_pcm_substream *substream)
570 struct via_spec *spec = codec->spec;
571 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
572 stream_tag, format, substream);
575 static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
576 struct hda_codec *codec,
577 struct snd_pcm_substream *substream)
579 struct via_spec *spec = codec->spec;
580 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
584 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
585 unsigned int stream_tag,
587 struct snd_pcm_substream *substream)
589 struct via_spec *spec = codec->spec;
590 struct hda_multi_out *mout = &spec->multiout;
591 hda_nid_t *nids = mout->dac_nids;
592 int chs = substream->runtime->channels;
595 mutex_lock(&codec->spdif_mutex);
596 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
598 snd_hda_is_supported_format(codec, mout->dig_out_nid,
600 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
601 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
602 /* turn off SPDIF once; otherwise the IEC958 bits won't
604 if (codec->spdif_ctls & AC_DIG1_ENABLE)
605 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
606 AC_VERB_SET_DIGI_CONVERT_1,
608 ~AC_DIG1_ENABLE & 0xff);
609 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
610 stream_tag, 0, format);
611 /* turn on again (if needed) */
612 if (codec->spdif_ctls & AC_DIG1_ENABLE)
613 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
614 AC_VERB_SET_DIGI_CONVERT_1,
615 codec->spdif_ctls & 0xff);
617 mout->dig_out_used = 0;
618 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
622 mutex_unlock(&codec->spdif_mutex);
625 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
628 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
629 !spec->hp_independent_mode)
630 /* headphone out will just decode front left/right (stereo) */
631 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
634 /* extra outputs copied from front */
635 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
636 if (mout->extra_out_nid[i])
637 snd_hda_codec_setup_stream(codec,
638 mout->extra_out_nid[i],
639 stream_tag, 0, format);
642 for (i = 1; i < mout->num_dacs; i++) {
643 if (chs >= (i + 1) * 2) /* independent out */
644 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
646 else /* copy front */
647 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
652 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
653 struct hda_codec *codec,
654 unsigned int stream_tag,
656 struct snd_pcm_substream *substream)
658 struct via_spec *spec = codec->spec;
659 struct hda_multi_out *mout = &spec->multiout;
660 hda_nid_t *nids = mout->dac_nids;
662 if (substream->number == 0)
663 playback_multi_pcm_prep_0(codec, stream_tag, format,
666 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
667 spec->hp_independent_mode)
668 snd_hda_codec_setup_stream(codec, mout->hp_nid,
669 stream_tag, 0, format);
675 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
676 struct hda_codec *codec,
677 struct snd_pcm_substream *substream)
679 struct via_spec *spec = codec->spec;
680 struct hda_multi_out *mout = &spec->multiout;
681 hda_nid_t *nids = mout->dac_nids;
684 if (substream->number == 0) {
685 for (i = 0; i < mout->num_dacs; i++)
686 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
688 if (mout->hp_nid && !spec->hp_independent_mode)
689 snd_hda_codec_setup_stream(codec, mout->hp_nid,
692 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
693 if (mout->extra_out_nid[i])
694 snd_hda_codec_setup_stream(codec,
695 mout->extra_out_nid[i],
697 mutex_lock(&codec->spdif_mutex);
698 if (mout->dig_out_nid &&
699 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
700 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
702 mout->dig_out_used = 0;
704 mutex_unlock(&codec->spdif_mutex);
706 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
707 spec->hp_independent_mode)
708 snd_hda_codec_setup_stream(codec, mout->hp_nid,
718 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
719 struct hda_codec *codec,
720 struct snd_pcm_substream *substream)
722 struct via_spec *spec = codec->spec;
723 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
726 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
727 struct hda_codec *codec,
728 struct snd_pcm_substream *substream)
730 struct via_spec *spec = codec->spec;
731 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
734 /* setup SPDIF output stream */
735 static void setup_dig_playback_stream(struct hda_codec *codec, hda_nid_t nid,
736 unsigned int stream_tag, unsigned int format)
738 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
739 if (codec->spdif_ctls & AC_DIG1_ENABLE)
740 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
741 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
742 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
743 /* turn on again (if needed) */
744 if (codec->spdif_ctls & AC_DIG1_ENABLE)
745 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
746 codec->spdif_ctls & 0xff);
749 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
750 struct hda_codec *codec,
751 unsigned int stream_tag,
753 struct snd_pcm_substream *substream)
755 struct via_spec *spec = codec->spec;
758 /* 1st or 2nd S/PDIF */
759 if (substream->number == 0)
760 nid = spec->multiout.dig_out_nid;
761 else if (substream->number == 1)
762 nid = spec->extra_dig_out_nid;
766 mutex_lock(&codec->spdif_mutex);
767 setup_dig_playback_stream(codec, nid, stream_tag, format);
768 mutex_unlock(&codec->spdif_mutex);
775 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
776 struct hda_codec *codec,
777 unsigned int stream_tag,
779 struct snd_pcm_substream *substream)
781 struct via_spec *spec = codec->spec;
783 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
784 stream_tag, 0, format);
788 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
789 struct hda_codec *codec,
790 struct snd_pcm_substream *substream)
792 struct via_spec *spec = codec->spec;
793 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
797 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
801 .nid = 0x10, /* NID to query formats and rates */
803 .open = via_playback_pcm_open,
804 .prepare = via_playback_multi_pcm_prepare,
805 .cleanup = via_playback_multi_pcm_cleanup
809 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
813 .nid = 0x10, /* NID to query formats and rates */
814 /* We got noisy outputs on the right channel on VT1708 when
815 * 24bit samples are used. Until any workaround is found,
816 * disable the 24bit format, so far.
818 .formats = SNDRV_PCM_FMTBIT_S16_LE,
820 .open = via_playback_pcm_open,
821 .prepare = via_playback_pcm_prepare,
822 .cleanup = via_playback_pcm_cleanup
826 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
830 .nid = 0x15, /* NID to query formats and rates */
832 .prepare = via_capture_pcm_prepare,
833 .cleanup = via_capture_pcm_cleanup
837 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
841 /* NID is set in via_build_pcms */
843 .open = via_dig_playback_pcm_open,
844 .close = via_dig_playback_pcm_close,
845 .prepare = via_dig_playback_pcm_prepare
849 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
855 static int via_build_controls(struct hda_codec *codec)
857 struct via_spec *spec = codec->spec;
861 for (i = 0; i < spec->num_mixers; i++) {
862 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
867 if (spec->multiout.dig_out_nid) {
868 err = snd_hda_create_spdif_out_ctls(codec,
869 spec->multiout.dig_out_nid);
872 err = snd_hda_create_spdif_share_sw(codec,
876 spec->multiout.share_spdif = 1;
878 if (spec->extra_dig_out_nid) {
879 err = snd_hda_create_spdif_out_ctls(codec,
880 spec->extra_dig_out_nid);
885 if (spec->dig_in_nid) {
886 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
890 via_free_kctls(codec); /* no longer needed */
894 static int via_build_pcms(struct hda_codec *codec)
896 struct via_spec *spec = codec->spec;
897 struct hda_pcm *info = spec->pcm_rec;
900 codec->pcm_info = info;
902 info->name = spec->stream_name_analog;
903 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
904 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
905 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
906 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
908 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
909 spec->multiout.max_channels;
911 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
914 info->name = spec->stream_name_digital;
915 info->pcm_type = HDA_PCM_TYPE_SPDIF;
916 if (spec->multiout.dig_out_nid) {
917 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
918 *(spec->stream_digital_playback);
919 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
920 spec->multiout.dig_out_nid;
922 if (spec->dig_in_nid) {
923 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
924 *(spec->stream_digital_capture);
925 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
933 static void via_free(struct hda_codec *codec)
935 struct via_spec *spec = codec->spec;
940 via_free_kctls(codec);
944 /* mute internal speaker if HP is plugged */
945 static void via_hp_automute(struct hda_codec *codec)
947 unsigned int present;
948 struct via_spec *spec = codec->spec;
950 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
951 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
952 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
953 HDA_OUTPUT, 0, HDA_AMP_MUTE,
954 present ? HDA_AMP_MUTE : 0);
957 static void via_gpio_control(struct hda_codec *codec)
959 unsigned int gpio_data;
960 unsigned int vol_counter;
962 unsigned int master_vol;
964 struct via_spec *spec = codec->spec;
966 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
967 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
969 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
970 0xF84, 0) & 0x3F0000) >> 16;
972 vol = vol_counter & 0x1F;
973 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
974 AC_VERB_GET_AMP_GAIN_MUTE,
977 if (gpio_data == 0x02) {
978 /* unmute line out */
979 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
980 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
982 if (vol_counter & 0x20) {
983 /* decrease volume */
984 if (vol > master_vol)
986 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
990 /* increase volume */
991 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
993 ((master_vol+vol) > 0x2A) ? 0x2A :
996 } else if (!(gpio_data & 0x02)) {
998 snd_hda_codec_amp_stereo(codec,
999 spec->autocfg.line_out_pins[0],
1000 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1005 /* unsolicited event for jack sensing */
1006 static void via_unsol_event(struct hda_codec *codec,
1010 if (res == VIA_HP_EVENT)
1011 via_hp_automute(codec);
1012 else if (res == VIA_GPIO_EVENT)
1013 via_gpio_control(codec);
1016 static hda_nid_t slave_dig_outs[] = {
1020 static int via_init(struct hda_codec *codec)
1022 struct via_spec *spec = codec->spec;
1024 for (i = 0; i < spec->num_iverbs; i++)
1025 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1027 /* Lydia Add for EAPD enable */
1028 if (!spec->dig_in_nid) { /* No Digital In connection */
1029 if (IS_VT1708_VENDORID(codec->vendor_id)) {
1030 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
1031 AC_VERB_SET_PIN_WIDGET_CONTROL,
1033 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
1034 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1035 } else if (IS_VT1709_10CH_VENDORID(codec->vendor_id) ||
1036 IS_VT1709_6CH_VENDORID(codec->vendor_id)) {
1037 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
1038 AC_VERB_SET_PIN_WIDGET_CONTROL,
1040 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
1041 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1042 } else if (IS_VT1708B_8CH_VENDORID(codec->vendor_id) ||
1043 IS_VT1708B_4CH_VENDORID(codec->vendor_id)) {
1044 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
1045 AC_VERB_SET_PIN_WIDGET_CONTROL,
1047 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
1048 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1050 } else /* enable SPDIF-input pin */
1051 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1052 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1055 codec->slave_dig_outs = slave_dig_outs;
1060 #ifdef CONFIG_SND_HDA_POWER_SAVE
1061 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1063 struct via_spec *spec = codec->spec;
1064 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1070 static struct hda_codec_ops via_patch_ops = {
1071 .build_controls = via_build_controls,
1072 .build_pcms = via_build_pcms,
1075 #ifdef CONFIG_SND_HDA_POWER_SAVE
1076 .check_power_status = via_check_power_status,
1080 /* fill in the dac_nids table from the parsed pin configuration */
1081 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1082 const struct auto_pin_cfg *cfg)
1087 spec->multiout.num_dacs = cfg->line_outs;
1089 spec->multiout.dac_nids = spec->private_dac_nids;
1091 for(i = 0; i < 4; i++) {
1092 nid = cfg->line_out_pins[i];
1094 /* config dac list */
1096 case AUTO_SEQ_FRONT:
1097 spec->multiout.dac_nids[i] = 0x10;
1099 case AUTO_SEQ_CENLFE:
1100 spec->multiout.dac_nids[i] = 0x12;
1102 case AUTO_SEQ_SURROUND:
1103 spec->multiout.dac_nids[i] = 0x11;
1106 spec->multiout.dac_nids[i] = 0x13;
1115 /* add playback controls from the parsed DAC table */
1116 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1117 const struct auto_pin_cfg *cfg)
1120 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1121 hda_nid_t nid, nid_vol = 0;
1124 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1125 nid = cfg->line_out_pins[i];
1130 if (i != AUTO_SEQ_FRONT)
1133 if (i == AUTO_SEQ_CENLFE) {
1135 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1136 "Center Playback Volume",
1137 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1141 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1142 "LFE Playback Volume",
1143 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1147 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1148 "Center Playback Switch",
1149 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1153 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1154 "LFE Playback Switch",
1155 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1159 } else if (i == AUTO_SEQ_FRONT){
1160 /* add control to mixer index 0 */
1161 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1162 "Master Front Playback Volume",
1163 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1167 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1168 "Master Front Playback Switch",
1169 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1174 /* add control to PW3 */
1175 sprintf(name, "%s Playback Volume", chname[i]);
1176 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1177 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1181 sprintf(name, "%s Playback Switch", chname[i]);
1182 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1183 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1188 sprintf(name, "%s Playback Volume", chname[i]);
1189 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1190 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1194 sprintf(name, "%s Playback Switch", chname[i]);
1195 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1196 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1206 static void create_hp_imux(struct via_spec *spec)
1209 struct hda_input_mux *imux = &spec->private_imux[1];
1210 static const char *texts[] = { "OFF", "ON", NULL};
1212 /* for hp mode select */
1214 while (texts[i] != NULL) {
1215 imux->items[imux->num_items].label = texts[i];
1216 imux->items[imux->num_items].index = i;
1221 spec->hp_mux = &spec->private_imux[1];
1224 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1231 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1233 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1234 "Headphone Playback Volume",
1235 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1238 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1239 "Headphone Playback Switch",
1240 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1244 create_hp_imux(spec);
1249 /* create playback/capture controls for input pins */
1250 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1251 const struct auto_pin_cfg *cfg)
1253 static char *labels[] = {
1254 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1256 struct hda_input_mux *imux = &spec->private_imux[0];
1257 int i, err, idx = 0;
1259 /* for internal loopback recording select */
1260 imux->items[imux->num_items].label = "Stereo Mixer";
1261 imux->items[imux->num_items].index = idx;
1264 for (i = 0; i < AUTO_PIN_LAST; i++) {
1265 if (!cfg->input_pins[i])
1268 switch (cfg->input_pins[i]) {
1269 case 0x1d: /* Mic */
1273 case 0x1e: /* Line In */
1277 case 0x21: /* Front Mic */
1285 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1289 imux->items[imux->num_items].label = labels[i];
1290 imux->items[imux->num_items].index = idx;
1296 #ifdef CONFIG_SND_HDA_POWER_SAVE
1297 static struct hda_amp_list vt1708_loopbacks[] = {
1298 { 0x17, HDA_INPUT, 1 },
1299 { 0x17, HDA_INPUT, 2 },
1300 { 0x17, HDA_INPUT, 3 },
1301 { 0x17, HDA_INPUT, 4 },
1306 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1308 unsigned int def_conf;
1309 unsigned char seqassoc;
1311 def_conf = snd_hda_codec_get_pincfg(codec, nid);
1312 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1313 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1314 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1315 if (seqassoc == 0xff) {
1316 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1317 snd_hda_codec_set_pincfg(codec, nid, def_conf);
1324 static int vt1708_parse_auto_config(struct hda_codec *codec)
1326 struct via_spec *spec = codec->spec;
1329 /* Add HP and CD pin config connect bit re-config action */
1330 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
1331 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
1333 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1336 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
1339 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1340 return 0; /* can't find valid BIOS pin config */
1342 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
1345 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1348 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1352 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1354 if (spec->autocfg.dig_outs)
1355 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
1356 if (spec->autocfg.dig_in_pin)
1357 spec->dig_in_nid = VT1708_DIGIN_NID;
1359 if (spec->kctls.list)
1360 spec->mixers[spec->num_mixers++] = spec->kctls.list;
1362 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
1364 spec->input_mux = &spec->private_imux[0];
1367 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1372 /* init callback for auto-configuration model -- overriding the default init */
1373 static int via_auto_init(struct hda_codec *codec)
1376 via_auto_init_multi_out(codec);
1377 via_auto_init_hp_out(codec);
1378 via_auto_init_analog_input(codec);
1382 static int patch_vt1708(struct hda_codec *codec)
1384 struct via_spec *spec;
1387 /* create a codec specific record */
1388 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1394 /* automatic parse from the BIOS config */
1395 err = vt1708_parse_auto_config(codec);
1400 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1401 "from BIOS. Using genenic mode...\n");
1405 spec->stream_name_analog = "VT1708 Analog";
1406 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1407 /* disable 32bit format on VT1708 */
1408 if (codec->vendor_id == 0x11061708)
1409 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
1410 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
1412 spec->stream_name_digital = "VT1708 Digital";
1413 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1414 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1417 if (!spec->adc_nids && spec->input_mux) {
1418 spec->adc_nids = vt1708_adc_nids;
1419 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1420 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1424 codec->patch_ops = via_patch_ops;
1426 codec->patch_ops.init = via_auto_init;
1427 #ifdef CONFIG_SND_HDA_POWER_SAVE
1428 spec->loopback.amplist = vt1708_loopbacks;
1434 /* capture mixer elements */
1435 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1436 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
1437 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
1438 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
1439 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
1440 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
1441 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
1443 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1444 /* The multiple "Capture Source" controls confuse alsamixer
1445 * So call somewhat different..
1447 /* .name = "Capture Source", */
1448 .name = "Input Source",
1450 .info = via_mux_enum_info,
1451 .get = via_mux_enum_get,
1452 .put = via_mux_enum_put,
1457 static struct hda_verb vt1709_uniwill_init_verbs[] = {
1458 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1463 * generic initialization of ADC, input mixers and output mixers
1465 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1467 * Unmute ADC0-2 and set the default input to mic-in
1469 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1470 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1471 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1474 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1477 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1478 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1479 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1480 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1481 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1482 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1485 * Set up output selector (0x1a, 0x1b, 0x29)
1487 /* set vol=0 to output mixers */
1488 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1489 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1490 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1493 * Unmute PW3 and PW4
1495 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1496 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1498 /* Set input of PW4 as AOW4 */
1499 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
1500 /* PW9 Output enable */
1501 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1505 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1509 .nid = 0x10, /* NID to query formats and rates */
1511 .open = via_playback_pcm_open,
1512 .prepare = via_playback_pcm_prepare,
1513 .cleanup = via_playback_pcm_cleanup
1517 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1521 .nid = 0x10, /* NID to query formats and rates */
1523 .open = via_playback_pcm_open,
1524 .prepare = via_playback_pcm_prepare,
1525 .cleanup = via_playback_pcm_cleanup
1529 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1533 .nid = 0x14, /* NID to query formats and rates */
1535 .prepare = via_capture_pcm_prepare,
1536 .cleanup = via_capture_pcm_cleanup
1540 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1544 /* NID is set in via_build_pcms */
1546 .open = via_dig_playback_pcm_open,
1547 .close = via_dig_playback_pcm_close
1551 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1557 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1558 const struct auto_pin_cfg *cfg)
1563 if (cfg->line_outs == 4) /* 10 channels */
1564 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1565 else if (cfg->line_outs == 3) /* 6 channels */
1566 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1568 spec->multiout.dac_nids = spec->private_dac_nids;
1570 if (cfg->line_outs == 4) { /* 10 channels */
1571 for (i = 0; i < cfg->line_outs; i++) {
1572 nid = cfg->line_out_pins[i];
1574 /* config dac list */
1576 case AUTO_SEQ_FRONT:
1578 spec->multiout.dac_nids[i] = 0x10;
1580 case AUTO_SEQ_CENLFE:
1582 spec->multiout.dac_nids[i] = 0x12;
1584 case AUTO_SEQ_SURROUND:
1586 spec->multiout.dac_nids[i] = 0x11;
1590 spec->multiout.dac_nids[i] = 0x27;
1597 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1599 } else if (cfg->line_outs == 3) { /* 6 channels */
1600 for(i = 0; i < cfg->line_outs; i++) {
1601 nid = cfg->line_out_pins[i];
1603 /* config dac list */
1605 case AUTO_SEQ_FRONT:
1607 spec->multiout.dac_nids[i] = 0x10;
1609 case AUTO_SEQ_CENLFE:
1611 spec->multiout.dac_nids[i] = 0x12;
1613 case AUTO_SEQ_SURROUND:
1615 spec->multiout.dac_nids[i] = 0x11;
1627 /* add playback controls from the parsed DAC table */
1628 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1629 const struct auto_pin_cfg *cfg)
1632 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1636 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1637 nid = cfg->line_out_pins[i];
1642 if (i == AUTO_SEQ_CENLFE) {
1644 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1645 "Center Playback Volume",
1646 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1650 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1651 "LFE Playback Volume",
1652 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1656 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1657 "Center Playback Switch",
1658 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1662 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1663 "LFE Playback Switch",
1664 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1668 } else if (i == AUTO_SEQ_FRONT){
1669 /* add control to mixer index 0 */
1670 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1671 "Master Front Playback Volume",
1672 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1676 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1677 "Master Front Playback Switch",
1678 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1683 /* add control to PW3 */
1684 sprintf(name, "%s Playback Volume", chname[i]);
1685 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1686 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1690 sprintf(name, "%s Playback Switch", chname[i]);
1691 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1692 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1696 } else if (i == AUTO_SEQ_SURROUND) {
1697 sprintf(name, "%s Playback Volume", chname[i]);
1698 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1699 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1703 sprintf(name, "%s Playback Switch", chname[i]);
1704 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1705 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1709 } else if (i == AUTO_SEQ_SIDE) {
1710 sprintf(name, "%s Playback Volume", chname[i]);
1711 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1712 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1716 sprintf(name, "%s Playback Switch", chname[i]);
1717 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1718 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1728 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1735 if (spec->multiout.num_dacs == 5) /* 10 channels */
1736 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1737 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1738 spec->multiout.hp_nid = 0;
1740 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1741 "Headphone Playback Volume",
1742 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1745 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1746 "Headphone Playback Switch",
1747 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1754 /* create playback/capture controls for input pins */
1755 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1756 const struct auto_pin_cfg *cfg)
1758 static char *labels[] = {
1759 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1761 struct hda_input_mux *imux = &spec->private_imux[0];
1762 int i, err, idx = 0;
1764 /* for internal loopback recording select */
1765 imux->items[imux->num_items].label = "Stereo Mixer";
1766 imux->items[imux->num_items].index = idx;
1769 for (i = 0; i < AUTO_PIN_LAST; i++) {
1770 if (!cfg->input_pins[i])
1773 switch (cfg->input_pins[i]) {
1774 case 0x1d: /* Mic */
1778 case 0x1e: /* Line In */
1782 case 0x21: /* Front Mic */
1790 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1794 imux->items[imux->num_items].label = labels[i];
1795 imux->items[imux->num_items].index = idx;
1801 static int vt1709_parse_auto_config(struct hda_codec *codec)
1803 struct via_spec *spec = codec->spec;
1806 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1809 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1812 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1813 return 0; /* can't find valid BIOS pin config */
1815 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1818 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1821 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1825 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1827 if (spec->autocfg.dig_outs)
1828 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1829 if (spec->autocfg.dig_in_pin)
1830 spec->dig_in_nid = VT1709_DIGIN_NID;
1832 if (spec->kctls.list)
1833 spec->mixers[spec->num_mixers++] = spec->kctls.list;
1835 spec->input_mux = &spec->private_imux[0];
1838 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1843 #ifdef CONFIG_SND_HDA_POWER_SAVE
1844 static struct hda_amp_list vt1709_loopbacks[] = {
1845 { 0x18, HDA_INPUT, 1 },
1846 { 0x18, HDA_INPUT, 2 },
1847 { 0x18, HDA_INPUT, 3 },
1848 { 0x18, HDA_INPUT, 4 },
1853 static int patch_vt1709_10ch(struct hda_codec *codec)
1855 struct via_spec *spec;
1858 /* create a codec specific record */
1859 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1865 err = vt1709_parse_auto_config(codec);
1870 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1871 "Using genenic mode...\n");
1874 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
1875 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1877 spec->stream_name_analog = "VT1709 Analog";
1878 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1879 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1881 spec->stream_name_digital = "VT1709 Digital";
1882 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1883 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1886 if (!spec->adc_nids && spec->input_mux) {
1887 spec->adc_nids = vt1709_adc_nids;
1888 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1889 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1893 codec->patch_ops = via_patch_ops;
1895 codec->patch_ops.init = via_auto_init;
1896 codec->patch_ops.unsol_event = via_unsol_event;
1897 #ifdef CONFIG_SND_HDA_POWER_SAVE
1898 spec->loopback.amplist = vt1709_loopbacks;
1904 * generic initialization of ADC, input mixers and output mixers
1906 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1908 * Unmute ADC0-2 and set the default input to mic-in
1910 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1911 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1912 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1915 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1918 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1919 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1920 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1921 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1922 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1923 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1926 * Set up output selector (0x1a, 0x1b, 0x29)
1928 /* set vol=0 to output mixers */
1929 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1930 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1931 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1934 * Unmute PW3 and PW4
1936 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1937 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1939 /* Set input of PW4 as MW0 */
1940 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1941 /* PW9 Output enable */
1942 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1946 static int patch_vt1709_6ch(struct hda_codec *codec)
1948 struct via_spec *spec;
1951 /* create a codec specific record */
1952 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1958 err = vt1709_parse_auto_config(codec);
1963 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1964 "Using genenic mode...\n");
1967 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
1968 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1970 spec->stream_name_analog = "VT1709 Analog";
1971 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1972 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1974 spec->stream_name_digital = "VT1709 Digital";
1975 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1976 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1979 if (!spec->adc_nids && spec->input_mux) {
1980 spec->adc_nids = vt1709_adc_nids;
1981 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1982 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1986 codec->patch_ops = via_patch_ops;
1988 codec->patch_ops.init = via_auto_init;
1989 codec->patch_ops.unsol_event = via_unsol_event;
1990 #ifdef CONFIG_SND_HDA_POWER_SAVE
1991 spec->loopback.amplist = vt1709_loopbacks;
1996 /* capture mixer elements */
1997 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
1998 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
1999 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2000 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2001 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2003 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2004 /* The multiple "Capture Source" controls confuse alsamixer
2005 * So call somewhat different..
2007 /* .name = "Capture Source", */
2008 .name = "Input Source",
2010 .info = via_mux_enum_info,
2011 .get = via_mux_enum_get,
2012 .put = via_mux_enum_put,
2017 * generic initialization of ADC, input mixers and output mixers
2019 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2021 * Unmute ADC0-1 and set the default input to mic-in
2023 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2024 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2027 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2030 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2031 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2032 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2033 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2034 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2035 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2038 * Set up output mixers
2040 /* set vol=0 to output mixers */
2041 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2042 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2043 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2045 /* Setup default input to PW4 */
2046 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
2047 /* PW9 Output enable */
2048 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2049 /* PW10 Input enable */
2050 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2054 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2056 * Unmute ADC0-1 and set the default input to mic-in
2058 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2059 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2062 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2065 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2066 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2067 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2068 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2069 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2070 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2073 * Set up output mixers
2075 /* set vol=0 to output mixers */
2076 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2077 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2078 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2080 /* Setup default input of PW4 to MW0 */
2081 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2082 /* PW9 Output enable */
2083 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2084 /* PW10 Input enable */
2085 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2089 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2090 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2094 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2098 .nid = 0x10, /* NID to query formats and rates */
2100 .open = via_playback_pcm_open,
2101 .prepare = via_playback_multi_pcm_prepare,
2102 .cleanup = via_playback_multi_pcm_cleanup
2106 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2110 .nid = 0x10, /* NID to query formats and rates */
2112 .open = via_playback_pcm_open,
2113 .prepare = via_playback_multi_pcm_prepare,
2114 .cleanup = via_playback_multi_pcm_cleanup
2118 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2122 .nid = 0x13, /* NID to query formats and rates */
2124 .prepare = via_capture_pcm_prepare,
2125 .cleanup = via_capture_pcm_cleanup
2129 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2133 /* NID is set in via_build_pcms */
2135 .open = via_dig_playback_pcm_open,
2136 .close = via_dig_playback_pcm_close,
2137 .prepare = via_dig_playback_pcm_prepare
2141 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2147 /* fill in the dac_nids table from the parsed pin configuration */
2148 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2149 const struct auto_pin_cfg *cfg)
2154 spec->multiout.num_dacs = cfg->line_outs;
2156 spec->multiout.dac_nids = spec->private_dac_nids;
2158 for (i = 0; i < 4; i++) {
2159 nid = cfg->line_out_pins[i];
2161 /* config dac list */
2163 case AUTO_SEQ_FRONT:
2164 spec->multiout.dac_nids[i] = 0x10;
2166 case AUTO_SEQ_CENLFE:
2167 spec->multiout.dac_nids[i] = 0x24;
2169 case AUTO_SEQ_SURROUND:
2170 spec->multiout.dac_nids[i] = 0x11;
2173 spec->multiout.dac_nids[i] = 0x25;
2182 /* add playback controls from the parsed DAC table */
2183 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
2184 const struct auto_pin_cfg *cfg)
2187 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2188 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
2189 hda_nid_t nid, nid_vol = 0;
2192 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2193 nid = cfg->line_out_pins[i];
2198 nid_vol = nid_vols[i];
2200 if (i == AUTO_SEQ_CENLFE) {
2202 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2203 "Center Playback Volume",
2204 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2208 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2209 "LFE Playback Volume",
2210 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2214 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2215 "Center Playback Switch",
2216 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2220 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2221 "LFE Playback Switch",
2222 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2226 } else if (i == AUTO_SEQ_FRONT) {
2227 /* add control to mixer index 0 */
2228 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2229 "Master Front Playback Volume",
2230 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2234 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2235 "Master Front Playback Switch",
2236 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2241 /* add control to PW3 */
2242 sprintf(name, "%s Playback Volume", chname[i]);
2243 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2244 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2248 sprintf(name, "%s Playback Switch", chname[i]);
2249 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2250 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2255 sprintf(name, "%s Playback Volume", chname[i]);
2256 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2257 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2261 sprintf(name, "%s Playback Switch", chname[i]);
2262 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2263 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2273 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2280 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
2282 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2283 "Headphone Playback Volume",
2284 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2287 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2288 "Headphone Playback Switch",
2289 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2293 create_hp_imux(spec);
2298 /* create playback/capture controls for input pins */
2299 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2300 const struct auto_pin_cfg *cfg)
2302 static char *labels[] = {
2303 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2305 struct hda_input_mux *imux = &spec->private_imux[0];
2306 int i, err, idx = 0;
2308 /* for internal loopback recording select */
2309 imux->items[imux->num_items].label = "Stereo Mixer";
2310 imux->items[imux->num_items].index = idx;
2313 for (i = 0; i < AUTO_PIN_LAST; i++) {
2314 if (!cfg->input_pins[i])
2317 switch (cfg->input_pins[i]) {
2318 case 0x1a: /* Mic */
2322 case 0x1b: /* Line In */
2326 case 0x1e: /* Front Mic */
2334 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2338 imux->items[imux->num_items].label = labels[i];
2339 imux->items[imux->num_items].index = idx;
2345 static int vt1708B_parse_auto_config(struct hda_codec *codec)
2347 struct via_spec *spec = codec->spec;
2350 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2353 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
2356 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2357 return 0; /* can't find valid BIOS pin config */
2359 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
2362 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2365 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
2369 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2371 if (spec->autocfg.dig_outs)
2372 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2373 if (spec->autocfg.dig_in_pin)
2374 spec->dig_in_nid = VT1708B_DIGIN_NID;
2376 if (spec->kctls.list)
2377 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2379 spec->input_mux = &spec->private_imux[0];
2382 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2387 #ifdef CONFIG_SND_HDA_POWER_SAVE
2388 static struct hda_amp_list vt1708B_loopbacks[] = {
2389 { 0x16, HDA_INPUT, 1 },
2390 { 0x16, HDA_INPUT, 2 },
2391 { 0x16, HDA_INPUT, 3 },
2392 { 0x16, HDA_INPUT, 4 },
2397 static int patch_vt1708B_8ch(struct hda_codec *codec)
2399 struct via_spec *spec;
2402 /* create a codec specific record */
2403 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2409 /* automatic parse from the BIOS config */
2410 err = vt1708B_parse_auto_config(codec);
2415 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2416 "from BIOS. Using genenic mode...\n");
2419 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2420 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2422 spec->stream_name_analog = "VT1708B Analog";
2423 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
2424 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2426 spec->stream_name_digital = "VT1708B Digital";
2427 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2428 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2430 if (!spec->adc_nids && spec->input_mux) {
2431 spec->adc_nids = vt1708B_adc_nids;
2432 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2433 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2437 codec->patch_ops = via_patch_ops;
2439 codec->patch_ops.init = via_auto_init;
2440 codec->patch_ops.unsol_event = via_unsol_event;
2441 #ifdef CONFIG_SND_HDA_POWER_SAVE
2442 spec->loopback.amplist = vt1708B_loopbacks;
2448 static int patch_vt1708B_4ch(struct hda_codec *codec)
2450 struct via_spec *spec;
2453 /* create a codec specific record */
2454 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2460 /* automatic parse from the BIOS config */
2461 err = vt1708B_parse_auto_config(codec);
2466 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2467 "from BIOS. Using genenic mode...\n");
2470 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2471 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2473 spec->stream_name_analog = "VT1708B Analog";
2474 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
2475 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2477 spec->stream_name_digital = "VT1708B Digital";
2478 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2479 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2481 if (!spec->adc_nids && spec->input_mux) {
2482 spec->adc_nids = vt1708B_adc_nids;
2483 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2484 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2488 codec->patch_ops = via_patch_ops;
2490 codec->patch_ops.init = via_auto_init;
2491 codec->patch_ops.unsol_event = via_unsol_event;
2492 #ifdef CONFIG_SND_HDA_POWER_SAVE
2493 spec->loopback.amplist = vt1708B_loopbacks;
2499 /* Patch for VT1708S */
2501 /* VT1708S software backdoor based override for buggy hardware micboost
2503 #define MIC_BOOST_VOLUME(xname, nid) { \
2504 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2507 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2508 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2509 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2510 .info = mic_boost_volume_info, \
2511 .get = snd_hda_mixer_amp_volume_get, \
2512 .put = snd_hda_mixer_amp_volume_put, \
2513 .tlv = { .c = mic_boost_tlv }, \
2514 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2516 /* capture mixer elements */
2517 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2518 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2519 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2520 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2521 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2522 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2523 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2525 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2526 /* The multiple "Capture Source" controls confuse alsamixer
2527 * So call somewhat different..
2529 /* .name = "Capture Source", */
2530 .name = "Input Source",
2532 .info = via_mux_enum_info,
2533 .get = via_mux_enum_get,
2534 .put = via_mux_enum_put,
2539 static struct hda_verb vt1708S_volume_init_verbs[] = {
2540 /* Unmute ADC0-1 and set the default input to mic-in */
2541 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2542 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2544 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2545 * analog-loopback mixer widget */
2546 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2547 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2548 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2549 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2550 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2551 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2553 /* Setup default input of PW4 to MW0 */
2554 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2555 /* PW9, PW10 Output enable */
2556 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2557 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2558 /* Enable Mic Boost Volume backdoor */
2563 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2564 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2568 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2572 .nid = 0x10, /* NID to query formats and rates */
2574 .open = via_playback_pcm_open,
2575 .prepare = via_playback_pcm_prepare,
2576 .cleanup = via_playback_pcm_cleanup
2580 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2584 .nid = 0x13, /* NID to query formats and rates */
2586 .prepare = via_capture_pcm_prepare,
2587 .cleanup = via_capture_pcm_cleanup
2591 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
2595 /* NID is set in via_build_pcms */
2597 .open = via_dig_playback_pcm_open,
2598 .close = via_dig_playback_pcm_close,
2599 .prepare = via_dig_playback_pcm_prepare
2603 /* fill in the dac_nids table from the parsed pin configuration */
2604 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
2605 const struct auto_pin_cfg *cfg)
2610 spec->multiout.num_dacs = cfg->line_outs;
2612 spec->multiout.dac_nids = spec->private_dac_nids;
2614 for (i = 0; i < 4; i++) {
2615 nid = cfg->line_out_pins[i];
2617 /* config dac list */
2619 case AUTO_SEQ_FRONT:
2620 spec->multiout.dac_nids[i] = 0x10;
2622 case AUTO_SEQ_CENLFE:
2623 spec->multiout.dac_nids[i] = 0x24;
2625 case AUTO_SEQ_SURROUND:
2626 spec->multiout.dac_nids[i] = 0x11;
2629 spec->multiout.dac_nids[i] = 0x25;
2638 /* add playback controls from the parsed DAC table */
2639 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
2640 const struct auto_pin_cfg *cfg)
2643 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2644 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
2645 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
2646 hda_nid_t nid, nid_vol, nid_mute;
2649 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2650 nid = cfg->line_out_pins[i];
2655 nid_vol = nid_vols[i];
2656 nid_mute = nid_mutes[i];
2658 if (i == AUTO_SEQ_CENLFE) {
2660 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2661 "Center Playback Volume",
2662 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2666 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2667 "LFE Playback Volume",
2668 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2672 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2673 "Center Playback Switch",
2674 HDA_COMPOSE_AMP_VAL(nid_mute,
2679 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2680 "LFE Playback Switch",
2681 HDA_COMPOSE_AMP_VAL(nid_mute,
2686 } else if (i == AUTO_SEQ_FRONT) {
2687 /* add control to mixer index 0 */
2688 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2689 "Master Front Playback Volume",
2690 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2694 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2695 "Master Front Playback Switch",
2696 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2702 sprintf(name, "%s Playback Volume", chname[i]);
2703 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2704 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2708 sprintf(name, "%s Playback Switch", chname[i]);
2709 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2710 HDA_COMPOSE_AMP_VAL(nid_mute,
2716 sprintf(name, "%s Playback Volume", chname[i]);
2717 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2718 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2722 sprintf(name, "%s Playback Switch", chname[i]);
2723 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2724 HDA_COMPOSE_AMP_VAL(nid_mute,
2735 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2742 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
2744 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2745 "Headphone Playback Volume",
2746 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
2750 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2751 "Headphone Playback Switch",
2752 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2756 create_hp_imux(spec);
2761 /* create playback/capture controls for input pins */
2762 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2763 const struct auto_pin_cfg *cfg)
2765 static char *labels[] = {
2766 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2768 struct hda_input_mux *imux = &spec->private_imux[0];
2769 int i, err, idx = 0;
2771 /* for internal loopback recording select */
2772 imux->items[imux->num_items].label = "Stereo Mixer";
2773 imux->items[imux->num_items].index = 5;
2776 for (i = 0; i < AUTO_PIN_LAST; i++) {
2777 if (!cfg->input_pins[i])
2780 switch (cfg->input_pins[i]) {
2781 case 0x1a: /* Mic */
2785 case 0x1b: /* Line In */
2789 case 0x1e: /* Front Mic */
2797 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2801 imux->items[imux->num_items].label = labels[i];
2802 imux->items[imux->num_items].index = idx-1;
2808 static int vt1708S_parse_auto_config(struct hda_codec *codec)
2810 struct via_spec *spec = codec->spec;
2812 static hda_nid_t vt1708s_ignore[] = {0x21, 0};
2814 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
2818 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
2821 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2822 return 0; /* can't find valid BIOS pin config */
2824 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
2827 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2830 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
2834 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2836 if (spec->autocfg.dig_outs)
2837 spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID;
2839 spec->extra_dig_out_nid = 0x15;
2841 if (spec->kctls.list)
2842 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2844 spec->input_mux = &spec->private_imux[0];
2847 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2852 #ifdef CONFIG_SND_HDA_POWER_SAVE
2853 static struct hda_amp_list vt1708S_loopbacks[] = {
2854 { 0x16, HDA_INPUT, 1 },
2855 { 0x16, HDA_INPUT, 2 },
2856 { 0x16, HDA_INPUT, 3 },
2857 { 0x16, HDA_INPUT, 4 },
2862 static int patch_vt1708S(struct hda_codec *codec)
2864 struct via_spec *spec;
2867 /* create a codec specific record */
2868 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2874 /* automatic parse from the BIOS config */
2875 err = vt1708S_parse_auto_config(codec);
2880 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2881 "from BIOS. Using genenic mode...\n");
2884 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2885 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2887 spec->stream_name_analog = "VT1708S Analog";
2888 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2889 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2891 spec->stream_name_digital = "VT1708S Digital";
2892 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2894 if (!spec->adc_nids && spec->input_mux) {
2895 spec->adc_nids = vt1708S_adc_nids;
2896 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2897 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2901 codec->patch_ops = via_patch_ops;
2903 codec->patch_ops.init = via_auto_init;
2904 codec->patch_ops.unsol_event = via_unsol_event;
2905 #ifdef CONFIG_SND_HDA_POWER_SAVE
2906 spec->loopback.amplist = vt1708S_loopbacks;
2912 /* Patch for VT1702 */
2914 /* capture mixer elements */
2915 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
2916 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
2917 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
2918 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
2919 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
2920 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
2921 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
2922 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2925 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2926 /* The multiple "Capture Source" controls confuse alsamixer
2927 * So call somewhat different..
2929 /* .name = "Capture Source", */
2930 .name = "Input Source",
2932 .info = via_mux_enum_info,
2933 .get = via_mux_enum_get,
2934 .put = via_mux_enum_put,
2939 static struct hda_verb vt1702_volume_init_verbs[] = {
2941 * Unmute ADC0-1 and set the default input to mic-in
2943 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2944 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2945 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2948 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2951 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2952 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2953 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2954 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2955 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2956 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2958 /* Setup default input of PW4 to MW0 */
2959 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
2960 /* PW6 PW7 Output enable */
2961 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2962 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2966 static struct hda_verb vt1702_uniwill_init_verbs[] = {
2967 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
2968 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2972 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
2976 .nid = 0x10, /* NID to query formats and rates */
2978 .open = via_playback_pcm_open,
2979 .prepare = via_playback_multi_pcm_prepare,
2980 .cleanup = via_playback_multi_pcm_cleanup
2984 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2988 .nid = 0x12, /* NID to query formats and rates */
2990 .prepare = via_capture_pcm_prepare,
2991 .cleanup = via_capture_pcm_cleanup
2995 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
2999 /* NID is set in via_build_pcms */
3001 .open = via_dig_playback_pcm_open,
3002 .close = via_dig_playback_pcm_close,
3003 .prepare = via_dig_playback_pcm_prepare
3007 /* fill in the dac_nids table from the parsed pin configuration */
3008 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
3009 const struct auto_pin_cfg *cfg)
3011 spec->multiout.num_dacs = 1;
3012 spec->multiout.dac_nids = spec->private_dac_nids;
3014 if (cfg->line_out_pins[0]) {
3015 /* config dac list */
3016 spec->multiout.dac_nids[0] = 0x10;
3022 /* add playback controls from the parsed DAC table */
3023 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3024 const struct auto_pin_cfg *cfg)
3028 if (!cfg->line_out_pins[0])
3031 /* add control to mixer index 0 */
3032 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3033 "Master Front Playback Volume",
3034 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3037 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3038 "Master Front Playback Switch",
3039 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3044 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3045 "Front Playback Volume",
3046 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
3049 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3050 "Front Playback Switch",
3051 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
3058 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3065 spec->multiout.hp_nid = 0x1D;
3067 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3068 "Headphone Playback Volume",
3069 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
3073 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3074 "Headphone Playback Switch",
3075 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3079 create_hp_imux(spec);
3084 /* create playback/capture controls for input pins */
3085 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3086 const struct auto_pin_cfg *cfg)
3088 static char *labels[] = {
3089 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3091 struct hda_input_mux *imux = &spec->private_imux[0];
3092 int i, err, idx = 0;
3094 /* for internal loopback recording select */
3095 imux->items[imux->num_items].label = "Stereo Mixer";
3096 imux->items[imux->num_items].index = 3;
3099 for (i = 0; i < AUTO_PIN_LAST; i++) {
3100 if (!cfg->input_pins[i])
3103 switch (cfg->input_pins[i]) {
3104 case 0x14: /* Mic */
3108 case 0x15: /* Line In */
3112 case 0x18: /* Front Mic */
3116 err = via_new_analog_input(spec, cfg->input_pins[i],
3117 labels[i], idx, 0x1A);
3120 imux->items[imux->num_items].label = labels[i];
3121 imux->items[imux->num_items].index = idx-1;
3127 static int vt1702_parse_auto_config(struct hda_codec *codec)
3129 struct via_spec *spec = codec->spec;
3131 static hda_nid_t vt1702_ignore[] = {0x1C, 0};
3133 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3137 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3140 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3141 return 0; /* can't find valid BIOS pin config */
3143 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3146 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3149 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3153 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3155 if (spec->autocfg.dig_outs)
3156 spec->multiout.dig_out_nid = VT1702_DIGOUT_NID;
3158 spec->extra_dig_out_nid = 0x1B;
3160 if (spec->kctls.list)
3161 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3163 spec->input_mux = &spec->private_imux[0];
3166 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3171 #ifdef CONFIG_SND_HDA_POWER_SAVE
3172 static struct hda_amp_list vt1702_loopbacks[] = {
3173 { 0x1A, HDA_INPUT, 1 },
3174 { 0x1A, HDA_INPUT, 2 },
3175 { 0x1A, HDA_INPUT, 3 },
3176 { 0x1A, HDA_INPUT, 4 },
3181 static int patch_vt1702(struct hda_codec *codec)
3183 struct via_spec *spec;
3185 unsigned int response;
3186 unsigned char control;
3188 /* create a codec specific record */
3189 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3195 /* automatic parse from the BIOS config */
3196 err = vt1702_parse_auto_config(codec);
3201 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3202 "from BIOS. Using genenic mode...\n");
3205 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3206 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
3208 spec->stream_name_analog = "VT1702 Analog";
3209 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3210 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3212 spec->stream_name_digital = "VT1702 Digital";
3213 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3215 if (!spec->adc_nids && spec->input_mux) {
3216 spec->adc_nids = vt1702_adc_nids;
3217 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3218 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3222 codec->patch_ops = via_patch_ops;
3224 codec->patch_ops.init = via_auto_init;
3225 codec->patch_ops.unsol_event = via_unsol_event;
3226 #ifdef CONFIG_SND_HDA_POWER_SAVE
3227 spec->loopback.amplist = vt1702_loopbacks;
3231 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3232 control = (unsigned char)(response & 0xff);
3234 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
3236 /* Enable GPIO 0&1 for volume&mute control */
3237 /* Enable GPIO 2 for DMIC-DATA */
3238 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3239 control = (unsigned char)((response >> 16) & 0x3f);
3240 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
3248 static struct hda_codec_preset snd_hda_preset_via[] = {
3249 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3250 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3251 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3252 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3253 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3254 .patch = patch_vt1709_10ch},
3255 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3256 .patch = patch_vt1709_10ch},
3257 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3258 .patch = patch_vt1709_10ch},
3259 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3260 .patch = patch_vt1709_10ch},
3261 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3262 .patch = patch_vt1709_6ch},
3263 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3264 .patch = patch_vt1709_6ch},
3265 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3266 .patch = patch_vt1709_6ch},
3267 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3268 .patch = patch_vt1709_6ch},
3269 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3270 .patch = patch_vt1708B_8ch},
3271 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3272 .patch = patch_vt1708B_8ch},
3273 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3274 .patch = patch_vt1708B_8ch},
3275 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3276 .patch = patch_vt1708B_8ch},
3277 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3278 .patch = patch_vt1708B_4ch},
3279 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3280 .patch = patch_vt1708B_4ch},
3281 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3282 .patch = patch_vt1708B_4ch},
3283 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3284 .patch = patch_vt1708B_4ch},
3285 { .id = 0x11060397, .name = "VT1708S",
3286 .patch = patch_vt1708S},
3287 { .id = 0x11061397, .name = "VT1708S",
3288 .patch = patch_vt1708S},
3289 { .id = 0x11062397, .name = "VT1708S",
3290 .patch = patch_vt1708S},
3291 { .id = 0x11063397, .name = "VT1708S",
3292 .patch = patch_vt1708S},
3293 { .id = 0x11064397, .name = "VT1708S",
3294 .patch = patch_vt1708S},
3295 { .id = 0x11065397, .name = "VT1708S",
3296 .patch = patch_vt1708S},
3297 { .id = 0x11066397, .name = "VT1708S",
3298 .patch = patch_vt1708S},
3299 { .id = 0x11067397, .name = "VT1708S",
3300 .patch = patch_vt1708S},
3301 { .id = 0x11060398, .name = "VT1702",
3302 .patch = patch_vt1702},
3303 { .id = 0x11061398, .name = "VT1702",
3304 .patch = patch_vt1702},
3305 { .id = 0x11062398, .name = "VT1702",
3306 .patch = patch_vt1702},
3307 { .id = 0x11063398, .name = "VT1702",
3308 .patch = patch_vt1702},
3309 { .id = 0x11064398, .name = "VT1702",
3310 .patch = patch_vt1702},
3311 { .id = 0x11065398, .name = "VT1702",
3312 .patch = patch_vt1702},
3313 { .id = 0x11066398, .name = "VT1702",
3314 .patch = patch_vt1702},
3315 { .id = 0x11067398, .name = "VT1702",
3316 .patch = patch_vt1702},
3320 MODULE_ALIAS("snd-hda-codec-id:1106*");
3322 static struct hda_codec_preset_list via_list = {
3323 .preset = snd_hda_preset_via,
3324 .owner = THIS_MODULE,
3327 MODULE_LICENSE("GPL");
3328 MODULE_DESCRIPTION("VIA HD-audio codec");
3330 static int __init patch_via_init(void)
3332 return snd_hda_add_codec_preset(&via_list);
3335 static void __exit patch_via_exit(void)
3337 snd_hda_delete_codec_preset(&via_list);
3340 module_init(patch_via_init)
3341 module_exit(patch_via_exit)