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_read(codec, nid, 0,
1312 AC_VERB_GET_CONFIG_DEFAULT, 0);
1313 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1314 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1315 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1316 if (seqassoc == 0xff) {
1317 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1318 snd_hda_codec_write(codec, nid, 0,
1319 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1327 static int vt1708_parse_auto_config(struct hda_codec *codec)
1329 struct via_spec *spec = codec->spec;
1332 /* Add HP and CD pin config connect bit re-config action */
1333 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
1334 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
1336 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1339 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
1342 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1343 return 0; /* can't find valid BIOS pin config */
1345 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
1348 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1351 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1355 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1357 if (spec->autocfg.dig_out_pin)
1358 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
1359 if (spec->autocfg.dig_in_pin)
1360 spec->dig_in_nid = VT1708_DIGIN_NID;
1362 if (spec->kctls.list)
1363 spec->mixers[spec->num_mixers++] = spec->kctls.list;
1365 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
1367 spec->input_mux = &spec->private_imux[0];
1370 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1375 /* init callback for auto-configuration model -- overriding the default init */
1376 static int via_auto_init(struct hda_codec *codec)
1379 via_auto_init_multi_out(codec);
1380 via_auto_init_hp_out(codec);
1381 via_auto_init_analog_input(codec);
1385 static int patch_vt1708(struct hda_codec *codec)
1387 struct via_spec *spec;
1390 /* create a codec specific record */
1391 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1397 /* automatic parse from the BIOS config */
1398 err = vt1708_parse_auto_config(codec);
1403 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1404 "from BIOS. Using genenic mode...\n");
1408 spec->stream_name_analog = "VT1708 Analog";
1409 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1410 /* disable 32bit format on VT1708 */
1411 if (codec->vendor_id == 0x11061708)
1412 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
1413 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
1415 spec->stream_name_digital = "VT1708 Digital";
1416 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1417 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1420 if (!spec->adc_nids && spec->input_mux) {
1421 spec->adc_nids = vt1708_adc_nids;
1422 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1423 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1427 codec->patch_ops = via_patch_ops;
1429 codec->patch_ops.init = via_auto_init;
1430 #ifdef CONFIG_SND_HDA_POWER_SAVE
1431 spec->loopback.amplist = vt1708_loopbacks;
1437 /* capture mixer elements */
1438 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1439 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
1440 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
1441 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
1442 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
1443 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
1444 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
1446 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1447 /* The multiple "Capture Source" controls confuse alsamixer
1448 * So call somewhat different..
1450 /* .name = "Capture Source", */
1451 .name = "Input Source",
1453 .info = via_mux_enum_info,
1454 .get = via_mux_enum_get,
1455 .put = via_mux_enum_put,
1460 static struct hda_verb vt1709_uniwill_init_verbs[] = {
1461 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1466 * generic initialization of ADC, input mixers and output mixers
1468 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1470 * Unmute ADC0-2 and set the default input to mic-in
1472 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1473 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1474 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1477 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1480 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1481 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1482 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1483 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1484 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1485 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1488 * Set up output selector (0x1a, 0x1b, 0x29)
1490 /* set vol=0 to output mixers */
1491 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1492 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1493 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1496 * Unmute PW3 and PW4
1498 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1499 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1501 /* Set input of PW4 as AOW4 */
1502 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
1503 /* PW9 Output enable */
1504 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1508 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1512 .nid = 0x10, /* NID to query formats and rates */
1514 .open = via_playback_pcm_open,
1515 .prepare = via_playback_pcm_prepare,
1516 .cleanup = via_playback_pcm_cleanup
1520 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1524 .nid = 0x10, /* NID to query formats and rates */
1526 .open = via_playback_pcm_open,
1527 .prepare = via_playback_pcm_prepare,
1528 .cleanup = via_playback_pcm_cleanup
1532 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1536 .nid = 0x14, /* NID to query formats and rates */
1538 .prepare = via_capture_pcm_prepare,
1539 .cleanup = via_capture_pcm_cleanup
1543 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1547 /* NID is set in via_build_pcms */
1549 .open = via_dig_playback_pcm_open,
1550 .close = via_dig_playback_pcm_close
1554 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1560 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1561 const struct auto_pin_cfg *cfg)
1566 if (cfg->line_outs == 4) /* 10 channels */
1567 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1568 else if (cfg->line_outs == 3) /* 6 channels */
1569 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1571 spec->multiout.dac_nids = spec->private_dac_nids;
1573 if (cfg->line_outs == 4) { /* 10 channels */
1574 for (i = 0; i < cfg->line_outs; i++) {
1575 nid = cfg->line_out_pins[i];
1577 /* config dac list */
1579 case AUTO_SEQ_FRONT:
1581 spec->multiout.dac_nids[i] = 0x10;
1583 case AUTO_SEQ_CENLFE:
1585 spec->multiout.dac_nids[i] = 0x12;
1587 case AUTO_SEQ_SURROUND:
1589 spec->multiout.dac_nids[i] = 0x11;
1593 spec->multiout.dac_nids[i] = 0x27;
1600 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1602 } else if (cfg->line_outs == 3) { /* 6 channels */
1603 for(i = 0; i < cfg->line_outs; i++) {
1604 nid = cfg->line_out_pins[i];
1606 /* config dac list */
1608 case AUTO_SEQ_FRONT:
1610 spec->multiout.dac_nids[i] = 0x10;
1612 case AUTO_SEQ_CENLFE:
1614 spec->multiout.dac_nids[i] = 0x12;
1616 case AUTO_SEQ_SURROUND:
1618 spec->multiout.dac_nids[i] = 0x11;
1630 /* add playback controls from the parsed DAC table */
1631 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1632 const struct auto_pin_cfg *cfg)
1635 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1639 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1640 nid = cfg->line_out_pins[i];
1645 if (i == AUTO_SEQ_CENLFE) {
1647 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1648 "Center Playback Volume",
1649 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1653 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1654 "LFE Playback Volume",
1655 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1659 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1660 "Center Playback Switch",
1661 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1665 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1666 "LFE Playback Switch",
1667 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1671 } else if (i == AUTO_SEQ_FRONT){
1672 /* add control to mixer index 0 */
1673 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1674 "Master Front Playback Volume",
1675 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1679 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1680 "Master Front Playback Switch",
1681 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1686 /* add control to PW3 */
1687 sprintf(name, "%s Playback Volume", chname[i]);
1688 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1689 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1693 sprintf(name, "%s Playback Switch", chname[i]);
1694 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1695 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1699 } else if (i == AUTO_SEQ_SURROUND) {
1700 sprintf(name, "%s Playback Volume", chname[i]);
1701 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1702 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1706 sprintf(name, "%s Playback Switch", chname[i]);
1707 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1708 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1712 } else if (i == AUTO_SEQ_SIDE) {
1713 sprintf(name, "%s Playback Volume", chname[i]);
1714 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1715 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1719 sprintf(name, "%s Playback Switch", chname[i]);
1720 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1721 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1731 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1738 if (spec->multiout.num_dacs == 5) /* 10 channels */
1739 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1740 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1741 spec->multiout.hp_nid = 0;
1743 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1744 "Headphone Playback Volume",
1745 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1748 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1749 "Headphone Playback Switch",
1750 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1757 /* create playback/capture controls for input pins */
1758 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1759 const struct auto_pin_cfg *cfg)
1761 static char *labels[] = {
1762 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1764 struct hda_input_mux *imux = &spec->private_imux[0];
1765 int i, err, idx = 0;
1767 /* for internal loopback recording select */
1768 imux->items[imux->num_items].label = "Stereo Mixer";
1769 imux->items[imux->num_items].index = idx;
1772 for (i = 0; i < AUTO_PIN_LAST; i++) {
1773 if (!cfg->input_pins[i])
1776 switch (cfg->input_pins[i]) {
1777 case 0x1d: /* Mic */
1781 case 0x1e: /* Line In */
1785 case 0x21: /* Front Mic */
1793 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1797 imux->items[imux->num_items].label = labels[i];
1798 imux->items[imux->num_items].index = idx;
1804 static int vt1709_parse_auto_config(struct hda_codec *codec)
1806 struct via_spec *spec = codec->spec;
1809 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1812 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1815 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1816 return 0; /* can't find valid BIOS pin config */
1818 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1821 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1824 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1828 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1830 if (spec->autocfg.dig_out_pin)
1831 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1832 if (spec->autocfg.dig_in_pin)
1833 spec->dig_in_nid = VT1709_DIGIN_NID;
1835 if (spec->kctls.list)
1836 spec->mixers[spec->num_mixers++] = spec->kctls.list;
1838 spec->input_mux = &spec->private_imux[0];
1841 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1846 #ifdef CONFIG_SND_HDA_POWER_SAVE
1847 static struct hda_amp_list vt1709_loopbacks[] = {
1848 { 0x18, HDA_INPUT, 1 },
1849 { 0x18, HDA_INPUT, 2 },
1850 { 0x18, HDA_INPUT, 3 },
1851 { 0x18, HDA_INPUT, 4 },
1856 static int patch_vt1709_10ch(struct hda_codec *codec)
1858 struct via_spec *spec;
1861 /* create a codec specific record */
1862 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1868 err = vt1709_parse_auto_config(codec);
1873 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1874 "Using genenic mode...\n");
1877 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
1878 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1880 spec->stream_name_analog = "VT1709 Analog";
1881 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1882 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1884 spec->stream_name_digital = "VT1709 Digital";
1885 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1886 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1889 if (!spec->adc_nids && spec->input_mux) {
1890 spec->adc_nids = vt1709_adc_nids;
1891 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1892 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1896 codec->patch_ops = via_patch_ops;
1898 codec->patch_ops.init = via_auto_init;
1899 codec->patch_ops.unsol_event = via_unsol_event;
1900 #ifdef CONFIG_SND_HDA_POWER_SAVE
1901 spec->loopback.amplist = vt1709_loopbacks;
1907 * generic initialization of ADC, input mixers and output mixers
1909 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1911 * Unmute ADC0-2 and set the default input to mic-in
1913 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1914 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1915 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1918 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1921 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1922 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1923 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1924 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1925 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1926 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1929 * Set up output selector (0x1a, 0x1b, 0x29)
1931 /* set vol=0 to output mixers */
1932 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1933 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1934 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1937 * Unmute PW3 and PW4
1939 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1940 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1942 /* Set input of PW4 as MW0 */
1943 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1944 /* PW9 Output enable */
1945 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1949 static int patch_vt1709_6ch(struct hda_codec *codec)
1951 struct via_spec *spec;
1954 /* create a codec specific record */
1955 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1961 err = vt1709_parse_auto_config(codec);
1966 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1967 "Using genenic mode...\n");
1970 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
1971 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1973 spec->stream_name_analog = "VT1709 Analog";
1974 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1975 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1977 spec->stream_name_digital = "VT1709 Digital";
1978 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1979 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1982 if (!spec->adc_nids && spec->input_mux) {
1983 spec->adc_nids = vt1709_adc_nids;
1984 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1985 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1989 codec->patch_ops = via_patch_ops;
1991 codec->patch_ops.init = via_auto_init;
1992 codec->patch_ops.unsol_event = via_unsol_event;
1993 #ifdef CONFIG_SND_HDA_POWER_SAVE
1994 spec->loopback.amplist = vt1709_loopbacks;
1999 /* capture mixer elements */
2000 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2001 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2002 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2003 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2004 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2006 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2007 /* The multiple "Capture Source" controls confuse alsamixer
2008 * So call somewhat different..
2010 /* .name = "Capture Source", */
2011 .name = "Input Source",
2013 .info = via_mux_enum_info,
2014 .get = via_mux_enum_get,
2015 .put = via_mux_enum_put,
2020 * generic initialization of ADC, input mixers and output mixers
2022 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2024 * Unmute ADC0-1 and set the default input to mic-in
2026 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2027 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2030 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2033 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2034 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2035 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2036 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2037 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2038 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2041 * Set up output mixers
2043 /* set vol=0 to output mixers */
2044 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2045 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2046 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2048 /* Setup default input to PW4 */
2049 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
2050 /* PW9 Output enable */
2051 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2052 /* PW10 Input enable */
2053 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2057 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2059 * Unmute ADC0-1 and set the default input to mic-in
2061 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2062 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2065 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2068 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2069 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2070 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2071 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2072 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2073 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2076 * Set up output mixers
2078 /* set vol=0 to output mixers */
2079 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2080 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2081 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2083 /* Setup default input of PW4 to MW0 */
2084 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2085 /* PW9 Output enable */
2086 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2087 /* PW10 Input enable */
2088 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2092 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2093 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2097 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2101 .nid = 0x10, /* NID to query formats and rates */
2103 .open = via_playback_pcm_open,
2104 .prepare = via_playback_multi_pcm_prepare,
2105 .cleanup = via_playback_multi_pcm_cleanup
2109 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2113 .nid = 0x10, /* NID to query formats and rates */
2115 .open = via_playback_pcm_open,
2116 .prepare = via_playback_multi_pcm_prepare,
2117 .cleanup = via_playback_multi_pcm_cleanup
2121 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2125 .nid = 0x13, /* NID to query formats and rates */
2127 .prepare = via_capture_pcm_prepare,
2128 .cleanup = via_capture_pcm_cleanup
2132 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2136 /* NID is set in via_build_pcms */
2138 .open = via_dig_playback_pcm_open,
2139 .close = via_dig_playback_pcm_close,
2140 .prepare = via_dig_playback_pcm_prepare
2144 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2150 /* fill in the dac_nids table from the parsed pin configuration */
2151 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2152 const struct auto_pin_cfg *cfg)
2157 spec->multiout.num_dacs = cfg->line_outs;
2159 spec->multiout.dac_nids = spec->private_dac_nids;
2161 for (i = 0; i < 4; i++) {
2162 nid = cfg->line_out_pins[i];
2164 /* config dac list */
2166 case AUTO_SEQ_FRONT:
2167 spec->multiout.dac_nids[i] = 0x10;
2169 case AUTO_SEQ_CENLFE:
2170 spec->multiout.dac_nids[i] = 0x24;
2172 case AUTO_SEQ_SURROUND:
2173 spec->multiout.dac_nids[i] = 0x11;
2176 spec->multiout.dac_nids[i] = 0x25;
2185 /* add playback controls from the parsed DAC table */
2186 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
2187 const struct auto_pin_cfg *cfg)
2190 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2191 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
2192 hda_nid_t nid, nid_vol = 0;
2195 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2196 nid = cfg->line_out_pins[i];
2201 nid_vol = nid_vols[i];
2203 if (i == AUTO_SEQ_CENLFE) {
2205 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2206 "Center Playback Volume",
2207 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2211 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2212 "LFE Playback Volume",
2213 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2217 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2218 "Center Playback Switch",
2219 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2223 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2224 "LFE Playback Switch",
2225 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2229 } else if (i == AUTO_SEQ_FRONT) {
2230 /* add control to mixer index 0 */
2231 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2232 "Master Front Playback Volume",
2233 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2237 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2238 "Master Front Playback Switch",
2239 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2244 /* add control to PW3 */
2245 sprintf(name, "%s Playback Volume", chname[i]);
2246 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2247 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2251 sprintf(name, "%s Playback Switch", chname[i]);
2252 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2253 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2258 sprintf(name, "%s Playback Volume", chname[i]);
2259 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2260 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2264 sprintf(name, "%s Playback Switch", chname[i]);
2265 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2266 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2276 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2283 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
2285 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2286 "Headphone Playback Volume",
2287 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2290 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2291 "Headphone Playback Switch",
2292 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2296 create_hp_imux(spec);
2301 /* create playback/capture controls for input pins */
2302 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2303 const struct auto_pin_cfg *cfg)
2305 static char *labels[] = {
2306 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2308 struct hda_input_mux *imux = &spec->private_imux[0];
2309 int i, err, idx = 0;
2311 /* for internal loopback recording select */
2312 imux->items[imux->num_items].label = "Stereo Mixer";
2313 imux->items[imux->num_items].index = idx;
2316 for (i = 0; i < AUTO_PIN_LAST; i++) {
2317 if (!cfg->input_pins[i])
2320 switch (cfg->input_pins[i]) {
2321 case 0x1a: /* Mic */
2325 case 0x1b: /* Line In */
2329 case 0x1e: /* Front Mic */
2337 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2341 imux->items[imux->num_items].label = labels[i];
2342 imux->items[imux->num_items].index = idx;
2348 static int vt1708B_parse_auto_config(struct hda_codec *codec)
2350 struct via_spec *spec = codec->spec;
2353 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2356 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
2359 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2360 return 0; /* can't find valid BIOS pin config */
2362 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
2365 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2368 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
2372 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2374 if (spec->autocfg.dig_out_pin)
2375 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2376 if (spec->autocfg.dig_in_pin)
2377 spec->dig_in_nid = VT1708B_DIGIN_NID;
2379 if (spec->kctls.list)
2380 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2382 spec->input_mux = &spec->private_imux[0];
2385 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2390 #ifdef CONFIG_SND_HDA_POWER_SAVE
2391 static struct hda_amp_list vt1708B_loopbacks[] = {
2392 { 0x16, HDA_INPUT, 1 },
2393 { 0x16, HDA_INPUT, 2 },
2394 { 0x16, HDA_INPUT, 3 },
2395 { 0x16, HDA_INPUT, 4 },
2400 static int patch_vt1708B_8ch(struct hda_codec *codec)
2402 struct via_spec *spec;
2405 /* create a codec specific record */
2406 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2412 /* automatic parse from the BIOS config */
2413 err = vt1708B_parse_auto_config(codec);
2418 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2419 "from BIOS. Using genenic mode...\n");
2422 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2423 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2425 spec->stream_name_analog = "VT1708B Analog";
2426 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
2427 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2429 spec->stream_name_digital = "VT1708B Digital";
2430 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2431 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2433 if (!spec->adc_nids && spec->input_mux) {
2434 spec->adc_nids = vt1708B_adc_nids;
2435 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2436 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2440 codec->patch_ops = via_patch_ops;
2442 codec->patch_ops.init = via_auto_init;
2443 codec->patch_ops.unsol_event = via_unsol_event;
2444 #ifdef CONFIG_SND_HDA_POWER_SAVE
2445 spec->loopback.amplist = vt1708B_loopbacks;
2451 static int patch_vt1708B_4ch(struct hda_codec *codec)
2453 struct via_spec *spec;
2456 /* create a codec specific record */
2457 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2463 /* automatic parse from the BIOS config */
2464 err = vt1708B_parse_auto_config(codec);
2469 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2470 "from BIOS. Using genenic mode...\n");
2473 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2474 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2476 spec->stream_name_analog = "VT1708B Analog";
2477 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
2478 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2480 spec->stream_name_digital = "VT1708B Digital";
2481 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2482 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2484 if (!spec->adc_nids && spec->input_mux) {
2485 spec->adc_nids = vt1708B_adc_nids;
2486 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2487 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2491 codec->patch_ops = via_patch_ops;
2493 codec->patch_ops.init = via_auto_init;
2494 codec->patch_ops.unsol_event = via_unsol_event;
2495 #ifdef CONFIG_SND_HDA_POWER_SAVE
2496 spec->loopback.amplist = vt1708B_loopbacks;
2502 /* Patch for VT1708S */
2504 /* VT1708S software backdoor based override for buggy hardware micboost
2506 #define MIC_BOOST_VOLUME(xname, nid) { \
2507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2510 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2511 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2512 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2513 .info = mic_boost_volume_info, \
2514 .get = snd_hda_mixer_amp_volume_get, \
2515 .put = snd_hda_mixer_amp_volume_put, \
2516 .tlv = { .c = mic_boost_tlv }, \
2517 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2519 /* capture mixer elements */
2520 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2521 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2522 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2523 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2524 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2525 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2526 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2528 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2529 /* The multiple "Capture Source" controls confuse alsamixer
2530 * So call somewhat different..
2532 /* .name = "Capture Source", */
2533 .name = "Input Source",
2535 .info = via_mux_enum_info,
2536 .get = via_mux_enum_get,
2537 .put = via_mux_enum_put,
2542 static struct hda_verb vt1708S_volume_init_verbs[] = {
2543 /* Unmute ADC0-1 and set the default input to mic-in */
2544 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2545 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2547 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2548 * analog-loopback mixer widget */
2549 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2550 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2551 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2552 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2553 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2554 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2556 /* Setup default input of PW4 to MW0 */
2557 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2558 /* PW9, PW10 Output enable */
2559 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2560 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2561 /* Enable Mic Boost Volume backdoor */
2566 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2567 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2571 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2575 .nid = 0x10, /* NID to query formats and rates */
2577 .open = via_playback_pcm_open,
2578 .prepare = via_playback_pcm_prepare,
2579 .cleanup = via_playback_pcm_cleanup
2583 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2587 .nid = 0x13, /* NID to query formats and rates */
2589 .prepare = via_capture_pcm_prepare,
2590 .cleanup = via_capture_pcm_cleanup
2594 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
2598 /* NID is set in via_build_pcms */
2600 .open = via_dig_playback_pcm_open,
2601 .close = via_dig_playback_pcm_close,
2602 .prepare = via_dig_playback_pcm_prepare
2606 /* fill in the dac_nids table from the parsed pin configuration */
2607 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
2608 const struct auto_pin_cfg *cfg)
2613 spec->multiout.num_dacs = cfg->line_outs;
2615 spec->multiout.dac_nids = spec->private_dac_nids;
2617 for (i = 0; i < 4; i++) {
2618 nid = cfg->line_out_pins[i];
2620 /* config dac list */
2622 case AUTO_SEQ_FRONT:
2623 spec->multiout.dac_nids[i] = 0x10;
2625 case AUTO_SEQ_CENLFE:
2626 spec->multiout.dac_nids[i] = 0x24;
2628 case AUTO_SEQ_SURROUND:
2629 spec->multiout.dac_nids[i] = 0x11;
2632 spec->multiout.dac_nids[i] = 0x25;
2641 /* add playback controls from the parsed DAC table */
2642 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
2643 const struct auto_pin_cfg *cfg)
2646 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2647 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
2648 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
2649 hda_nid_t nid, nid_vol, nid_mute;
2652 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2653 nid = cfg->line_out_pins[i];
2658 nid_vol = nid_vols[i];
2659 nid_mute = nid_mutes[i];
2661 if (i == AUTO_SEQ_CENLFE) {
2663 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2664 "Center Playback Volume",
2665 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2669 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2670 "LFE Playback Volume",
2671 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2675 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2676 "Center Playback Switch",
2677 HDA_COMPOSE_AMP_VAL(nid_mute,
2682 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2683 "LFE Playback Switch",
2684 HDA_COMPOSE_AMP_VAL(nid_mute,
2689 } else if (i == AUTO_SEQ_FRONT) {
2690 /* add control to mixer index 0 */
2691 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2692 "Master Front Playback Volume",
2693 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2697 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2698 "Master Front Playback Switch",
2699 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2705 sprintf(name, "%s Playback Volume", chname[i]);
2706 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2707 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2711 sprintf(name, "%s Playback Switch", chname[i]);
2712 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2713 HDA_COMPOSE_AMP_VAL(nid_mute,
2719 sprintf(name, "%s Playback Volume", chname[i]);
2720 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2721 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2725 sprintf(name, "%s Playback Switch", chname[i]);
2726 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2727 HDA_COMPOSE_AMP_VAL(nid_mute,
2738 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2745 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
2747 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2748 "Headphone Playback Volume",
2749 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
2753 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2754 "Headphone Playback Switch",
2755 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2759 create_hp_imux(spec);
2764 /* create playback/capture controls for input pins */
2765 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2766 const struct auto_pin_cfg *cfg)
2768 static char *labels[] = {
2769 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2771 struct hda_input_mux *imux = &spec->private_imux[0];
2772 int i, err, idx = 0;
2774 /* for internal loopback recording select */
2775 imux->items[imux->num_items].label = "Stereo Mixer";
2776 imux->items[imux->num_items].index = 5;
2779 for (i = 0; i < AUTO_PIN_LAST; i++) {
2780 if (!cfg->input_pins[i])
2783 switch (cfg->input_pins[i]) {
2784 case 0x1a: /* Mic */
2788 case 0x1b: /* Line In */
2792 case 0x1e: /* Front Mic */
2800 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2804 imux->items[imux->num_items].label = labels[i];
2805 imux->items[imux->num_items].index = idx-1;
2811 static int vt1708S_parse_auto_config(struct hda_codec *codec)
2813 struct via_spec *spec = codec->spec;
2815 static hda_nid_t vt1708s_ignore[] = {0x21, 0};
2817 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
2821 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
2824 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2825 return 0; /* can't find valid BIOS pin config */
2827 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
2830 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2833 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
2837 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2839 if (spec->autocfg.dig_out_pin)
2840 spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID;
2842 spec->extra_dig_out_nid = 0x15;
2844 if (spec->kctls.list)
2845 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2847 spec->input_mux = &spec->private_imux[0];
2850 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2855 #ifdef CONFIG_SND_HDA_POWER_SAVE
2856 static struct hda_amp_list vt1708S_loopbacks[] = {
2857 { 0x16, HDA_INPUT, 1 },
2858 { 0x16, HDA_INPUT, 2 },
2859 { 0x16, HDA_INPUT, 3 },
2860 { 0x16, HDA_INPUT, 4 },
2865 static int patch_vt1708S(struct hda_codec *codec)
2867 struct via_spec *spec;
2870 /* create a codec specific record */
2871 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2877 /* automatic parse from the BIOS config */
2878 err = vt1708S_parse_auto_config(codec);
2883 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2884 "from BIOS. Using genenic mode...\n");
2887 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2888 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2890 spec->stream_name_analog = "VT1708S Analog";
2891 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2892 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2894 spec->stream_name_digital = "VT1708S Digital";
2895 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2897 if (!spec->adc_nids && spec->input_mux) {
2898 spec->adc_nids = vt1708S_adc_nids;
2899 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2900 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2904 codec->patch_ops = via_patch_ops;
2906 codec->patch_ops.init = via_auto_init;
2907 codec->patch_ops.unsol_event = via_unsol_event;
2908 #ifdef CONFIG_SND_HDA_POWER_SAVE
2909 spec->loopback.amplist = vt1708S_loopbacks;
2915 /* Patch for VT1702 */
2917 /* capture mixer elements */
2918 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
2919 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
2920 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
2921 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
2922 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
2923 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
2924 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
2925 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2928 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2929 /* The multiple "Capture Source" controls confuse alsamixer
2930 * So call somewhat different..
2932 /* .name = "Capture Source", */
2933 .name = "Input Source",
2935 .info = via_mux_enum_info,
2936 .get = via_mux_enum_get,
2937 .put = via_mux_enum_put,
2942 static struct hda_verb vt1702_volume_init_verbs[] = {
2944 * Unmute ADC0-1 and set the default input to mic-in
2946 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2947 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2948 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2951 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2954 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2955 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2956 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2957 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2958 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2959 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2961 /* Setup default input of PW4 to MW0 */
2962 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
2963 /* PW6 PW7 Output enable */
2964 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2965 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2969 static struct hda_verb vt1702_uniwill_init_verbs[] = {
2970 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
2971 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2975 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
2979 .nid = 0x10, /* NID to query formats and rates */
2981 .open = via_playback_pcm_open,
2982 .prepare = via_playback_multi_pcm_prepare,
2983 .cleanup = via_playback_multi_pcm_cleanup
2987 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2991 .nid = 0x12, /* NID to query formats and rates */
2993 .prepare = via_capture_pcm_prepare,
2994 .cleanup = via_capture_pcm_cleanup
2998 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
3002 /* NID is set in via_build_pcms */
3004 .open = via_dig_playback_pcm_open,
3005 .close = via_dig_playback_pcm_close,
3006 .prepare = via_dig_playback_pcm_prepare
3010 /* fill in the dac_nids table from the parsed pin configuration */
3011 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
3012 const struct auto_pin_cfg *cfg)
3014 spec->multiout.num_dacs = 1;
3015 spec->multiout.dac_nids = spec->private_dac_nids;
3017 if (cfg->line_out_pins[0]) {
3018 /* config dac list */
3019 spec->multiout.dac_nids[0] = 0x10;
3025 /* add playback controls from the parsed DAC table */
3026 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3027 const struct auto_pin_cfg *cfg)
3031 if (!cfg->line_out_pins[0])
3034 /* add control to mixer index 0 */
3035 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3036 "Master Front Playback Volume",
3037 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3040 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3041 "Master Front Playback Switch",
3042 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3047 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3048 "Front Playback Volume",
3049 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
3052 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3053 "Front Playback Switch",
3054 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
3061 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3068 spec->multiout.hp_nid = 0x1D;
3070 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3071 "Headphone Playback Volume",
3072 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
3076 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3077 "Headphone Playback Switch",
3078 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3082 create_hp_imux(spec);
3087 /* create playback/capture controls for input pins */
3088 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3089 const struct auto_pin_cfg *cfg)
3091 static char *labels[] = {
3092 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3094 struct hda_input_mux *imux = &spec->private_imux[0];
3095 int i, err, idx = 0;
3097 /* for internal loopback recording select */
3098 imux->items[imux->num_items].label = "Stereo Mixer";
3099 imux->items[imux->num_items].index = 3;
3102 for (i = 0; i < AUTO_PIN_LAST; i++) {
3103 if (!cfg->input_pins[i])
3106 switch (cfg->input_pins[i]) {
3107 case 0x14: /* Mic */
3111 case 0x15: /* Line In */
3115 case 0x18: /* Front Mic */
3119 err = via_new_analog_input(spec, cfg->input_pins[i],
3120 labels[i], idx, 0x1A);
3123 imux->items[imux->num_items].label = labels[i];
3124 imux->items[imux->num_items].index = idx-1;
3130 static int vt1702_parse_auto_config(struct hda_codec *codec)
3132 struct via_spec *spec = codec->spec;
3134 static hda_nid_t vt1702_ignore[] = {0x1C, 0};
3136 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3140 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3143 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3144 return 0; /* can't find valid BIOS pin config */
3146 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3149 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3152 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3156 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3158 if (spec->autocfg.dig_out_pin)
3159 spec->multiout.dig_out_nid = VT1702_DIGOUT_NID;
3161 spec->extra_dig_out_nid = 0x1B;
3163 if (spec->kctls.list)
3164 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3166 spec->input_mux = &spec->private_imux[0];
3169 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3174 #ifdef CONFIG_SND_HDA_POWER_SAVE
3175 static struct hda_amp_list vt1702_loopbacks[] = {
3176 { 0x1A, HDA_INPUT, 1 },
3177 { 0x1A, HDA_INPUT, 2 },
3178 { 0x1A, HDA_INPUT, 3 },
3179 { 0x1A, HDA_INPUT, 4 },
3184 static int patch_vt1702(struct hda_codec *codec)
3186 struct via_spec *spec;
3188 unsigned int response;
3189 unsigned char control;
3191 /* create a codec specific record */
3192 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3198 /* automatic parse from the BIOS config */
3199 err = vt1702_parse_auto_config(codec);
3204 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3205 "from BIOS. Using genenic mode...\n");
3208 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3209 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
3211 spec->stream_name_analog = "VT1702 Analog";
3212 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3213 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3215 spec->stream_name_digital = "VT1702 Digital";
3216 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3218 if (!spec->adc_nids && spec->input_mux) {
3219 spec->adc_nids = vt1702_adc_nids;
3220 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3221 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3225 codec->patch_ops = via_patch_ops;
3227 codec->patch_ops.init = via_auto_init;
3228 codec->patch_ops.unsol_event = via_unsol_event;
3229 #ifdef CONFIG_SND_HDA_POWER_SAVE
3230 spec->loopback.amplist = vt1702_loopbacks;
3234 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3235 control = (unsigned char)(response & 0xff);
3237 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
3239 /* Enable GPIO 0&1 for volume&mute control */
3240 /* Enable GPIO 2 for DMIC-DATA */
3241 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3242 control = (unsigned char)((response >> 16) & 0x3f);
3243 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
3251 static struct hda_codec_preset snd_hda_preset_via[] = {
3252 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3253 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3254 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3255 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3256 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3257 .patch = patch_vt1709_10ch},
3258 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3259 .patch = patch_vt1709_10ch},
3260 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3261 .patch = patch_vt1709_10ch},
3262 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3263 .patch = patch_vt1709_10ch},
3264 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3265 .patch = patch_vt1709_6ch},
3266 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3267 .patch = patch_vt1709_6ch},
3268 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3269 .patch = patch_vt1709_6ch},
3270 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3271 .patch = patch_vt1709_6ch},
3272 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3273 .patch = patch_vt1708B_8ch},
3274 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3275 .patch = patch_vt1708B_8ch},
3276 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3277 .patch = patch_vt1708B_8ch},
3278 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3279 .patch = patch_vt1708B_8ch},
3280 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3281 .patch = patch_vt1708B_4ch},
3282 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3283 .patch = patch_vt1708B_4ch},
3284 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3285 .patch = patch_vt1708B_4ch},
3286 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3287 .patch = patch_vt1708B_4ch},
3288 { .id = 0x11060397, .name = "VT1708S",
3289 .patch = patch_vt1708S},
3290 { .id = 0x11061397, .name = "VT1708S",
3291 .patch = patch_vt1708S},
3292 { .id = 0x11062397, .name = "VT1708S",
3293 .patch = patch_vt1708S},
3294 { .id = 0x11063397, .name = "VT1708S",
3295 .patch = patch_vt1708S},
3296 { .id = 0x11064397, .name = "VT1708S",
3297 .patch = patch_vt1708S},
3298 { .id = 0x11065397, .name = "VT1708S",
3299 .patch = patch_vt1708S},
3300 { .id = 0x11066397, .name = "VT1708S",
3301 .patch = patch_vt1708S},
3302 { .id = 0x11067397, .name = "VT1708S",
3303 .patch = patch_vt1708S},
3304 { .id = 0x11060398, .name = "VT1702",
3305 .patch = patch_vt1702},
3306 { .id = 0x11061398, .name = "VT1702",
3307 .patch = patch_vt1702},
3308 { .id = 0x11062398, .name = "VT1702",
3309 .patch = patch_vt1702},
3310 { .id = 0x11063398, .name = "VT1702",
3311 .patch = patch_vt1702},
3312 { .id = 0x11064398, .name = "VT1702",
3313 .patch = patch_vt1702},
3314 { .id = 0x11065398, .name = "VT1702",
3315 .patch = patch_vt1702},
3316 { .id = 0x11066398, .name = "VT1702",
3317 .patch = patch_vt1702},
3318 { .id = 0x11067398, .name = "VT1702",
3319 .patch = patch_vt1702},
3323 MODULE_ALIAS("snd-hda-codec-id:1106*");
3325 static struct hda_codec_preset_list via_list = {
3326 .preset = snd_hda_preset_via,
3327 .owner = THIS_MODULE,
3330 MODULE_LICENSE("GPL");
3331 MODULE_DESCRIPTION("VIA HD-audio codec");
3333 static int __init patch_via_init(void)
3335 return snd_hda_add_codec_preset(&via_list);
3338 static void __exit patch_via_exit(void)
3340 snd_hda_delete_codec_preset(&via_list);
3343 module_init(patch_via_init)
3344 module_exit(patch_via_exit)