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"
50 #include "hda_patch.h"
53 #define AMP_VAL_IDX_SHIFT 19
54 #define AMP_VAL_IDX_MASK (0x0f<<19)
57 #define VT1708_HP_NID 0x13
58 #define VT1708_DIGOUT_NID 0x14
59 #define VT1708_DIGIN_NID 0x16
60 #define VT1708_DIGIN_PIN 0x26
61 #define VT1708_HP_PIN_NID 0x20
62 #define VT1708_CD_PIN_NID 0x24
64 #define VT1709_HP_DAC_NID 0x28
65 #define VT1709_DIGOUT_NID 0x13
66 #define VT1709_DIGIN_NID 0x17
67 #define VT1709_DIGIN_PIN 0x25
69 #define VT1708B_HP_NID 0x25
70 #define VT1708B_DIGOUT_NID 0x12
71 #define VT1708B_DIGIN_NID 0x15
72 #define VT1708B_DIGIN_PIN 0x21
74 #define VT1708S_HP_NID 0x25
75 #define VT1708S_DIGOUT_NID 0x12
77 #define VT1702_HP_NID 0x17
78 #define VT1702_DIGOUT_NID 0x11
80 #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
81 #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
82 #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
83 #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
84 #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
85 #define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
86 #define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
100 static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
102 u16 ven_id = vendor_id >> 16;
103 u16 dev_id = vendor_id & 0xffff;
104 enum VIA_HDA_CODEC codec_type;
107 if (ven_id != 0x1106)
108 codec_type = UNKNOWN;
109 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
111 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
112 codec_type = VT1709_10CH;
113 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
114 codec_type = VT1709_6CH;
115 else if (dev_id >= 0xe720 && dev_id <= 0xe723)
116 codec_type = VT1708B_8CH;
117 else if (dev_id >= 0xe724 && dev_id <= 0xe727)
118 codec_type = VT1708B_4CH;
119 else if ((dev_id & 0xfff) == 0x397
120 && (dev_id >> 12) < 8)
121 codec_type = VT1708S;
122 else if ((dev_id & 0xfff) == 0x398
123 && (dev_id >> 12) < 8)
126 codec_type = UNKNOWN;
130 #define VIA_HP_EVENT 0x01
131 #define VIA_GPIO_EVENT 0x02
145 #define get_amp_nid(kc) ((kc)->private_value & 0xffff)
147 /* Some VT1708S based boards gets the micboost setting wrong, so we have
148 * to apply some brute-force and re-write the TLV's by software. */
149 static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
150 unsigned int size, unsigned int __user *_tlv)
152 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
153 hda_nid_t nid = get_amp_nid(kcontrol);
155 if (get_codec_type(codec->vendor_id) == VT1708S
156 && (nid == 0x1a || nid == 0x1e)) {
157 if (size < 4 * sizeof(unsigned int))
159 if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */
161 if (put_user(2 * sizeof(unsigned int), _tlv + 1))
163 if (put_user(0, _tlv + 2)) /* offset = 0 */
165 if (put_user(1000, _tlv + 3)) /* step size = 10 dB */
171 static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
172 struct snd_ctl_elem_info *uinfo)
174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
175 hda_nid_t nid = get_amp_nid(kcontrol);
177 if (get_codec_type(codec->vendor_id) == VT1708S
178 && (nid == 0x1a || nid == 0x1e)) {
179 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
181 uinfo->value.integer.min = 0;
182 uinfo->value.integer.max = 3;
187 static struct snd_kcontrol_new vt1708_control_templates[] = {
188 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
189 HDA_CODEC_MUTE(NULL, 0, 0, 0),
194 /* codec parameterization */
195 struct snd_kcontrol_new *mixers[3];
196 unsigned int num_mixers;
198 struct hda_verb *init_verbs[5];
199 unsigned int num_iverbs;
201 char *stream_name_analog;
202 struct hda_pcm_stream *stream_analog_playback;
203 struct hda_pcm_stream *stream_analog_capture;
205 char *stream_name_digital;
206 struct hda_pcm_stream *stream_digital_playback;
207 struct hda_pcm_stream *stream_digital_capture;
210 struct hda_multi_out multiout;
211 hda_nid_t extra_dig_out_nid;
214 unsigned int num_adc_nids;
216 hda_nid_t dig_in_nid;
219 const struct hda_input_mux *input_mux;
220 unsigned int cur_mux[3];
222 /* PCM information */
223 struct hda_pcm pcm_rec[3];
225 /* dynamic controls, init_verbs and input_mux */
226 struct auto_pin_cfg autocfg;
227 struct snd_array kctls;
228 struct hda_input_mux private_imux[2];
229 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
232 const struct hda_input_mux *hp_mux;
233 unsigned int hp_independent_mode;
235 #ifdef CONFIG_SND_HDA_POWER_SAVE
236 struct hda_loopback_check loopback;
240 static hda_nid_t vt1708_adc_nids[2] = {
245 static hda_nid_t vt1709_adc_nids[3] = {
250 static hda_nid_t vt1708B_adc_nids[2] = {
255 static hda_nid_t vt1708S_adc_nids[2] = {
260 static hda_nid_t vt1702_adc_nids[3] = {
265 /* add dynamic controls */
266 static int via_add_control(struct via_spec *spec, int type, const char *name,
269 struct snd_kcontrol_new *knew;
271 snd_array_init(&spec->kctls, sizeof(*knew), 32);
272 knew = snd_array_new(&spec->kctls);
275 *knew = vt1708_control_templates[type];
276 knew->name = kstrdup(name, GFP_KERNEL);
279 knew->private_value = val;
283 static void via_free_kctls(struct hda_codec *codec)
285 struct via_spec *spec = codec->spec;
287 if (spec->kctls.list) {
288 struct snd_kcontrol_new *kctl = spec->kctls.list;
290 for (i = 0; i < spec->kctls.used; i++)
293 snd_array_free(&spec->kctls);
296 /* create input playback/capture controls for the given pin */
297 static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
298 const char *ctlname, int idx, int mix_nid)
303 sprintf(name, "%s Playback Volume", ctlname);
304 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
305 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
308 sprintf(name, "%s Playback Switch", ctlname);
309 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
310 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
316 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
317 hda_nid_t nid, int pin_type,
321 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
323 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
328 static void via_auto_init_multi_out(struct hda_codec *codec)
330 struct via_spec *spec = codec->spec;
333 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
334 hda_nid_t nid = spec->autocfg.line_out_pins[i];
336 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
340 static void via_auto_init_hp_out(struct hda_codec *codec)
342 struct via_spec *spec = codec->spec;
345 pin = spec->autocfg.hp_pins[0];
346 if (pin) /* connect to front */
347 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
350 static void via_auto_init_analog_input(struct hda_codec *codec)
352 struct via_spec *spec = codec->spec;
355 for (i = 0; i < AUTO_PIN_LAST; i++) {
356 hda_nid_t nid = spec->autocfg.input_pins[i];
358 snd_hda_codec_write(codec, nid, 0,
359 AC_VERB_SET_PIN_WIDGET_CONTROL,
360 (i <= AUTO_PIN_FRONT_MIC ?
361 PIN_VREF50 : PIN_IN));
368 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
369 struct snd_ctl_elem_info *uinfo)
371 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372 struct via_spec *spec = codec->spec;
373 return snd_hda_input_mux_info(spec->input_mux, uinfo);
376 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
377 struct snd_ctl_elem_value *ucontrol)
379 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
380 struct via_spec *spec = codec->spec;
381 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
383 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
387 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_value *ucontrol)
390 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
391 struct via_spec *spec = codec->spec;
392 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
393 unsigned int vendor_id = codec->vendor_id;
395 /* AIW0 lydia 060801 add for correct sw0 input select */
396 if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
397 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
398 0x18, &spec->cur_mux[adc_idx]);
399 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
400 IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0))
401 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
402 0x19, &spec->cur_mux[adc_idx]);
403 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
404 IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0))
405 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
406 0x17, &spec->cur_mux[adc_idx]);
407 else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0))
408 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
409 0x13, &spec->cur_mux[adc_idx]);
411 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
412 spec->adc_nids[adc_idx],
413 &spec->cur_mux[adc_idx]);
416 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
417 struct snd_ctl_elem_info *uinfo)
419 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
420 struct via_spec *spec = codec->spec;
421 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
424 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
425 struct snd_ctl_elem_value *ucontrol)
427 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
428 struct via_spec *spec = codec->spec;
429 hda_nid_t nid = spec->autocfg.hp_pins[0];
430 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
431 AC_VERB_GET_CONNECT_SEL,
434 ucontrol->value.enumerated.item[0] = pinsel;
439 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
440 struct snd_ctl_elem_value *ucontrol)
442 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
443 struct via_spec *spec = codec->spec;
444 hda_nid_t nid = spec->autocfg.hp_pins[0];
445 unsigned int pinsel = ucontrol->value.enumerated.item[0];
446 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
447 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
449 if (con_nid == spec->multiout.hp_nid) {
451 if (!spec->hp_independent_mode) {
452 if (spec->multiout.num_dacs > 1)
453 spec->multiout.num_dacs -= 1;
454 spec->hp_independent_mode = 1;
456 } else if (pinsel == 1) {
457 if (spec->hp_independent_mode) {
458 if (spec->multiout.num_dacs > 1)
459 spec->multiout.num_dacs += 1;
460 spec->hp_independent_mode = 0;
465 if (spec->hp_independent_mode) {
466 if (spec->multiout.num_dacs > 1)
467 spec->multiout.num_dacs += 1;
468 spec->hp_independent_mode = 0;
470 } else if (pinsel == 1) {
471 if (!spec->hp_independent_mode) {
472 if (spec->multiout.num_dacs > 1)
473 spec->multiout.num_dacs -= 1;
474 spec->hp_independent_mode = 1;
478 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
481 if (spec->multiout.hp_nid &&
482 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
483 snd_hda_codec_setup_stream(codec,
484 spec->multiout.hp_nid,
490 static struct snd_kcontrol_new via_hp_mixer[] = {
492 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
493 .name = "Independent HP",
495 .info = via_independent_hp_info,
496 .get = via_independent_hp_get,
497 .put = via_independent_hp_put,
502 /* capture mixer elements */
503 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
504 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
505 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
506 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
507 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
510 /* The multiple "Capture Source" controls confuse alsamixer
511 * So call somewhat different..
513 /* .name = "Capture Source", */
514 .name = "Input Source",
516 .info = via_mux_enum_info,
517 .get = via_mux_enum_get,
518 .put = via_mux_enum_put,
523 * generic initialization of ADC, input mixers and output mixers
525 static struct hda_verb vt1708_volume_init_verbs[] = {
527 * Unmute ADC0-1 and set the default input to mic-in
529 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
530 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
533 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
536 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
537 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
538 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
539 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
540 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
541 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
544 * Set up output mixers (0x19 - 0x1b)
546 /* set vol=0 to output mixers */
547 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
548 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
549 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
551 /* Setup default input to PW4 */
552 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
553 /* PW9 Output enable */
554 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
558 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
559 struct hda_codec *codec,
560 struct snd_pcm_substream *substream)
562 struct via_spec *spec = codec->spec;
563 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
567 static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
568 struct hda_codec *codec,
569 unsigned int stream_tag,
571 struct snd_pcm_substream *substream)
573 struct via_spec *spec = codec->spec;
574 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
575 stream_tag, format, substream);
578 static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
579 struct hda_codec *codec,
580 struct snd_pcm_substream *substream)
582 struct via_spec *spec = codec->spec;
583 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
587 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
588 unsigned int stream_tag,
590 struct snd_pcm_substream *substream)
592 struct via_spec *spec = codec->spec;
593 struct hda_multi_out *mout = &spec->multiout;
594 hda_nid_t *nids = mout->dac_nids;
595 int chs = substream->runtime->channels;
598 mutex_lock(&codec->spdif_mutex);
599 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
601 snd_hda_is_supported_format(codec, mout->dig_out_nid,
603 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
604 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
605 /* turn off SPDIF once; otherwise the IEC958 bits won't
607 if (codec->spdif_ctls & AC_DIG1_ENABLE)
608 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
609 AC_VERB_SET_DIGI_CONVERT_1,
611 ~AC_DIG1_ENABLE & 0xff);
612 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
613 stream_tag, 0, format);
614 /* turn on again (if needed) */
615 if (codec->spdif_ctls & AC_DIG1_ENABLE)
616 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
617 AC_VERB_SET_DIGI_CONVERT_1,
618 codec->spdif_ctls & 0xff);
620 mout->dig_out_used = 0;
621 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
625 mutex_unlock(&codec->spdif_mutex);
628 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
631 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
632 !spec->hp_independent_mode)
633 /* headphone out will just decode front left/right (stereo) */
634 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
637 /* extra outputs copied from front */
638 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
639 if (mout->extra_out_nid[i])
640 snd_hda_codec_setup_stream(codec,
641 mout->extra_out_nid[i],
642 stream_tag, 0, format);
645 for (i = 1; i < mout->num_dacs; i++) {
646 if (chs >= (i + 1) * 2) /* independent out */
647 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
649 else /* copy front */
650 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
655 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
656 struct hda_codec *codec,
657 unsigned int stream_tag,
659 struct snd_pcm_substream *substream)
661 struct via_spec *spec = codec->spec;
662 struct hda_multi_out *mout = &spec->multiout;
663 hda_nid_t *nids = mout->dac_nids;
665 if (substream->number == 0)
666 playback_multi_pcm_prep_0(codec, stream_tag, format,
669 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
670 spec->hp_independent_mode)
671 snd_hda_codec_setup_stream(codec, mout->hp_nid,
672 stream_tag, 0, format);
678 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
679 struct hda_codec *codec,
680 struct snd_pcm_substream *substream)
682 struct via_spec *spec = codec->spec;
683 struct hda_multi_out *mout = &spec->multiout;
684 hda_nid_t *nids = mout->dac_nids;
687 if (substream->number == 0) {
688 for (i = 0; i < mout->num_dacs; i++)
689 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
691 if (mout->hp_nid && !spec->hp_independent_mode)
692 snd_hda_codec_setup_stream(codec, mout->hp_nid,
695 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
696 if (mout->extra_out_nid[i])
697 snd_hda_codec_setup_stream(codec,
698 mout->extra_out_nid[i],
700 mutex_lock(&codec->spdif_mutex);
701 if (mout->dig_out_nid &&
702 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
703 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
705 mout->dig_out_used = 0;
707 mutex_unlock(&codec->spdif_mutex);
709 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
710 spec->hp_independent_mode)
711 snd_hda_codec_setup_stream(codec, mout->hp_nid,
721 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
722 struct hda_codec *codec,
723 struct snd_pcm_substream *substream)
725 struct via_spec *spec = codec->spec;
726 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
729 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
730 struct hda_codec *codec,
731 struct snd_pcm_substream *substream)
733 struct via_spec *spec = codec->spec;
734 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
737 /* setup SPDIF output stream */
738 static void setup_dig_playback_stream(struct hda_codec *codec, hda_nid_t nid,
739 unsigned int stream_tag, unsigned int format)
741 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
742 if (codec->spdif_ctls & AC_DIG1_ENABLE)
743 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
744 codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
745 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
746 /* turn on again (if needed) */
747 if (codec->spdif_ctls & AC_DIG1_ENABLE)
748 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
749 codec->spdif_ctls & 0xff);
752 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
753 struct hda_codec *codec,
754 unsigned int stream_tag,
756 struct snd_pcm_substream *substream)
758 struct via_spec *spec = codec->spec;
761 /* 1st or 2nd S/PDIF */
762 if (substream->number == 0)
763 nid = spec->multiout.dig_out_nid;
764 else if (substream->number == 1)
765 nid = spec->extra_dig_out_nid;
769 mutex_lock(&codec->spdif_mutex);
770 setup_dig_playback_stream(codec, nid, stream_tag, format);
771 mutex_unlock(&codec->spdif_mutex);
778 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
779 struct hda_codec *codec,
780 unsigned int stream_tag,
782 struct snd_pcm_substream *substream)
784 struct via_spec *spec = codec->spec;
786 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
787 stream_tag, 0, format);
791 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
792 struct hda_codec *codec,
793 struct snd_pcm_substream *substream)
795 struct via_spec *spec = codec->spec;
796 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
800 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
804 .nid = 0x10, /* NID to query formats and rates */
806 .open = via_playback_pcm_open,
807 .prepare = via_playback_multi_pcm_prepare,
808 .cleanup = via_playback_multi_pcm_cleanup
812 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
816 .nid = 0x10, /* NID to query formats and rates */
817 /* We got noisy outputs on the right channel on VT1708 when
818 * 24bit samples are used. Until any workaround is found,
819 * disable the 24bit format, so far.
821 .formats = SNDRV_PCM_FMTBIT_S16_LE,
823 .open = via_playback_pcm_open,
824 .prepare = via_playback_pcm_prepare,
825 .cleanup = via_playback_pcm_cleanup
829 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
833 .nid = 0x15, /* NID to query formats and rates */
835 .prepare = via_capture_pcm_prepare,
836 .cleanup = via_capture_pcm_cleanup
840 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
844 /* NID is set in via_build_pcms */
846 .open = via_dig_playback_pcm_open,
847 .close = via_dig_playback_pcm_close,
848 .prepare = via_dig_playback_pcm_prepare
852 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
858 static int via_build_controls(struct hda_codec *codec)
860 struct via_spec *spec = codec->spec;
864 for (i = 0; i < spec->num_mixers; i++) {
865 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
870 if (spec->multiout.dig_out_nid) {
871 err = snd_hda_create_spdif_out_ctls(codec,
872 spec->multiout.dig_out_nid);
875 err = snd_hda_create_spdif_share_sw(codec,
879 spec->multiout.share_spdif = 1;
881 if (spec->extra_dig_out_nid) {
882 err = snd_hda_create_spdif_out_ctls(codec,
883 spec->extra_dig_out_nid);
888 if (spec->dig_in_nid) {
889 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
893 via_free_kctls(codec); /* no longer needed */
897 static int via_build_pcms(struct hda_codec *codec)
899 struct via_spec *spec = codec->spec;
900 struct hda_pcm *info = spec->pcm_rec;
903 codec->pcm_info = info;
905 info->name = spec->stream_name_analog;
906 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
907 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
908 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
909 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
911 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
912 spec->multiout.max_channels;
914 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
917 info->name = spec->stream_name_digital;
918 info->pcm_type = HDA_PCM_TYPE_SPDIF;
919 if (spec->multiout.dig_out_nid) {
920 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
921 *(spec->stream_digital_playback);
922 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
923 spec->multiout.dig_out_nid;
925 if (spec->dig_in_nid) {
926 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
927 *(spec->stream_digital_capture);
928 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
936 static void via_free(struct hda_codec *codec)
938 struct via_spec *spec = codec->spec;
943 via_free_kctls(codec);
947 /* mute internal speaker if HP is plugged */
948 static void via_hp_automute(struct hda_codec *codec)
950 unsigned int present;
951 struct via_spec *spec = codec->spec;
953 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
954 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
955 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
956 HDA_OUTPUT, 0, HDA_AMP_MUTE,
957 present ? HDA_AMP_MUTE : 0);
960 static void via_gpio_control(struct hda_codec *codec)
962 unsigned int gpio_data;
963 unsigned int vol_counter;
965 unsigned int master_vol;
967 struct via_spec *spec = codec->spec;
969 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
970 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
972 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
973 0xF84, 0) & 0x3F0000) >> 16;
975 vol = vol_counter & 0x1F;
976 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
977 AC_VERB_GET_AMP_GAIN_MUTE,
980 if (gpio_data == 0x02) {
981 /* unmute line out */
982 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
983 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
985 if (vol_counter & 0x20) {
986 /* decrease volume */
987 if (vol > master_vol)
989 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
993 /* increase volume */
994 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
996 ((master_vol+vol) > 0x2A) ? 0x2A :
999 } else if (!(gpio_data & 0x02)) {
1001 snd_hda_codec_amp_stereo(codec,
1002 spec->autocfg.line_out_pins[0],
1003 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1008 /* unsolicited event for jack sensing */
1009 static void via_unsol_event(struct hda_codec *codec,
1013 if (res == VIA_HP_EVENT)
1014 via_hp_automute(codec);
1015 else if (res == VIA_GPIO_EVENT)
1016 via_gpio_control(codec);
1019 static hda_nid_t slave_dig_outs[] = {
1023 static int via_init(struct hda_codec *codec)
1025 struct via_spec *spec = codec->spec;
1027 for (i = 0; i < spec->num_iverbs; i++)
1028 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1030 /* Lydia Add for EAPD enable */
1031 if (!spec->dig_in_nid) { /* No Digital In connection */
1032 if (IS_VT1708_VENDORID(codec->vendor_id)) {
1033 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
1034 AC_VERB_SET_PIN_WIDGET_CONTROL,
1036 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
1037 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1038 } else if (IS_VT1709_10CH_VENDORID(codec->vendor_id) ||
1039 IS_VT1709_6CH_VENDORID(codec->vendor_id)) {
1040 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
1041 AC_VERB_SET_PIN_WIDGET_CONTROL,
1043 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
1044 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1045 } else if (IS_VT1708B_8CH_VENDORID(codec->vendor_id) ||
1046 IS_VT1708B_4CH_VENDORID(codec->vendor_id)) {
1047 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
1048 AC_VERB_SET_PIN_WIDGET_CONTROL,
1050 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
1051 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1053 } else /* enable SPDIF-input pin */
1054 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1055 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1058 codec->slave_dig_outs = slave_dig_outs;
1063 #ifdef CONFIG_SND_HDA_POWER_SAVE
1064 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1066 struct via_spec *spec = codec->spec;
1067 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1073 static struct hda_codec_ops via_patch_ops = {
1074 .build_controls = via_build_controls,
1075 .build_pcms = via_build_pcms,
1078 #ifdef CONFIG_SND_HDA_POWER_SAVE
1079 .check_power_status = via_check_power_status,
1083 /* fill in the dac_nids table from the parsed pin configuration */
1084 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1085 const struct auto_pin_cfg *cfg)
1090 spec->multiout.num_dacs = cfg->line_outs;
1092 spec->multiout.dac_nids = spec->private_dac_nids;
1094 for(i = 0; i < 4; i++) {
1095 nid = cfg->line_out_pins[i];
1097 /* config dac list */
1099 case AUTO_SEQ_FRONT:
1100 spec->multiout.dac_nids[i] = 0x10;
1102 case AUTO_SEQ_CENLFE:
1103 spec->multiout.dac_nids[i] = 0x12;
1105 case AUTO_SEQ_SURROUND:
1106 spec->multiout.dac_nids[i] = 0x11;
1109 spec->multiout.dac_nids[i] = 0x13;
1118 /* add playback controls from the parsed DAC table */
1119 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1120 const struct auto_pin_cfg *cfg)
1123 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1124 hda_nid_t nid, nid_vol = 0;
1127 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1128 nid = cfg->line_out_pins[i];
1133 if (i != AUTO_SEQ_FRONT)
1136 if (i == AUTO_SEQ_CENLFE) {
1138 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1139 "Center Playback Volume",
1140 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1144 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1145 "LFE Playback Volume",
1146 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1150 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1151 "Center Playback Switch",
1152 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1156 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1157 "LFE Playback Switch",
1158 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1162 } else if (i == AUTO_SEQ_FRONT){
1163 /* add control to mixer index 0 */
1164 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1165 "Master Front Playback Volume",
1166 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1170 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1171 "Master Front Playback Switch",
1172 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1177 /* add control to PW3 */
1178 sprintf(name, "%s Playback Volume", chname[i]);
1179 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1180 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1184 sprintf(name, "%s Playback Switch", chname[i]);
1185 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1186 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1191 sprintf(name, "%s Playback Volume", chname[i]);
1192 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1193 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1197 sprintf(name, "%s Playback Switch", chname[i]);
1198 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1199 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1209 static void create_hp_imux(struct via_spec *spec)
1212 struct hda_input_mux *imux = &spec->private_imux[1];
1213 static const char *texts[] = { "OFF", "ON", NULL};
1215 /* for hp mode select */
1217 while (texts[i] != NULL) {
1218 imux->items[imux->num_items].label = texts[i];
1219 imux->items[imux->num_items].index = i;
1224 spec->hp_mux = &spec->private_imux[1];
1227 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1234 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1236 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1237 "Headphone Playback Volume",
1238 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1241 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1242 "Headphone Playback Switch",
1243 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1247 create_hp_imux(spec);
1252 /* create playback/capture controls for input pins */
1253 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1254 const struct auto_pin_cfg *cfg)
1256 static char *labels[] = {
1257 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1259 struct hda_input_mux *imux = &spec->private_imux[0];
1260 int i, err, idx = 0;
1262 /* for internal loopback recording select */
1263 imux->items[imux->num_items].label = "Stereo Mixer";
1264 imux->items[imux->num_items].index = idx;
1267 for (i = 0; i < AUTO_PIN_LAST; i++) {
1268 if (!cfg->input_pins[i])
1271 switch (cfg->input_pins[i]) {
1272 case 0x1d: /* Mic */
1276 case 0x1e: /* Line In */
1280 case 0x21: /* Front Mic */
1288 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1292 imux->items[imux->num_items].label = labels[i];
1293 imux->items[imux->num_items].index = idx;
1299 #ifdef CONFIG_SND_HDA_POWER_SAVE
1300 static struct hda_amp_list vt1708_loopbacks[] = {
1301 { 0x17, HDA_INPUT, 1 },
1302 { 0x17, HDA_INPUT, 2 },
1303 { 0x17, HDA_INPUT, 3 },
1304 { 0x17, HDA_INPUT, 4 },
1309 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1311 unsigned int def_conf;
1312 unsigned char seqassoc;
1314 def_conf = snd_hda_codec_read(codec, nid, 0,
1315 AC_VERB_GET_CONFIG_DEFAULT, 0);
1316 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1317 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1318 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1319 if (seqassoc == 0xff) {
1320 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1321 snd_hda_codec_write(codec, nid, 0,
1322 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1330 static int vt1708_parse_auto_config(struct hda_codec *codec)
1332 struct via_spec *spec = codec->spec;
1335 /* Add HP and CD pin config connect bit re-config action */
1336 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
1337 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
1339 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1342 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
1345 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1346 return 0; /* can't find valid BIOS pin config */
1348 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
1351 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1354 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1358 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1360 if (spec->autocfg.dig_out_pin)
1361 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
1362 if (spec->autocfg.dig_in_pin)
1363 spec->dig_in_nid = VT1708_DIGIN_NID;
1365 if (spec->kctls.list)
1366 spec->mixers[spec->num_mixers++] = spec->kctls.list;
1368 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
1370 spec->input_mux = &spec->private_imux[0];
1373 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1378 /* init callback for auto-configuration model -- overriding the default init */
1379 static int via_auto_init(struct hda_codec *codec)
1382 via_auto_init_multi_out(codec);
1383 via_auto_init_hp_out(codec);
1384 via_auto_init_analog_input(codec);
1388 static int patch_vt1708(struct hda_codec *codec)
1390 struct via_spec *spec;
1393 /* create a codec specific record */
1394 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1400 /* automatic parse from the BIOS config */
1401 err = vt1708_parse_auto_config(codec);
1406 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1407 "from BIOS. Using genenic mode...\n");
1411 spec->stream_name_analog = "VT1708 Analog";
1412 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1413 /* disable 32bit format on VT1708 */
1414 if (codec->vendor_id == 0x11061708)
1415 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
1416 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
1418 spec->stream_name_digital = "VT1708 Digital";
1419 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1420 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1423 if (!spec->adc_nids && spec->input_mux) {
1424 spec->adc_nids = vt1708_adc_nids;
1425 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1426 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1430 codec->patch_ops = via_patch_ops;
1432 codec->patch_ops.init = via_auto_init;
1433 #ifdef CONFIG_SND_HDA_POWER_SAVE
1434 spec->loopback.amplist = vt1708_loopbacks;
1440 /* capture mixer elements */
1441 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1442 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
1443 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
1444 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
1445 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
1446 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
1447 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
1449 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1450 /* The multiple "Capture Source" controls confuse alsamixer
1451 * So call somewhat different..
1453 /* .name = "Capture Source", */
1454 .name = "Input Source",
1456 .info = via_mux_enum_info,
1457 .get = via_mux_enum_get,
1458 .put = via_mux_enum_put,
1463 static struct hda_verb vt1709_uniwill_init_verbs[] = {
1464 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1469 * generic initialization of ADC, input mixers and output mixers
1471 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1473 * Unmute ADC0-2 and set the default input to mic-in
1475 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1476 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1477 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1480 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1483 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1484 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1485 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1486 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1487 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1488 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1491 * Set up output selector (0x1a, 0x1b, 0x29)
1493 /* set vol=0 to output mixers */
1494 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1495 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1496 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1499 * Unmute PW3 and PW4
1501 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1502 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1504 /* Set input of PW4 as AOW4 */
1505 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
1506 /* PW9 Output enable */
1507 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1511 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1515 .nid = 0x10, /* NID to query formats and rates */
1517 .open = via_playback_pcm_open,
1518 .prepare = via_playback_pcm_prepare,
1519 .cleanup = via_playback_pcm_cleanup
1523 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1527 .nid = 0x10, /* NID to query formats and rates */
1529 .open = via_playback_pcm_open,
1530 .prepare = via_playback_pcm_prepare,
1531 .cleanup = via_playback_pcm_cleanup
1535 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1539 .nid = 0x14, /* NID to query formats and rates */
1541 .prepare = via_capture_pcm_prepare,
1542 .cleanup = via_capture_pcm_cleanup
1546 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1550 /* NID is set in via_build_pcms */
1552 .open = via_dig_playback_pcm_open,
1553 .close = via_dig_playback_pcm_close
1557 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1563 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1564 const struct auto_pin_cfg *cfg)
1569 if (cfg->line_outs == 4) /* 10 channels */
1570 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1571 else if (cfg->line_outs == 3) /* 6 channels */
1572 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1574 spec->multiout.dac_nids = spec->private_dac_nids;
1576 if (cfg->line_outs == 4) { /* 10 channels */
1577 for (i = 0; i < cfg->line_outs; i++) {
1578 nid = cfg->line_out_pins[i];
1580 /* config dac list */
1582 case AUTO_SEQ_FRONT:
1584 spec->multiout.dac_nids[i] = 0x10;
1586 case AUTO_SEQ_CENLFE:
1588 spec->multiout.dac_nids[i] = 0x12;
1590 case AUTO_SEQ_SURROUND:
1592 spec->multiout.dac_nids[i] = 0x11;
1596 spec->multiout.dac_nids[i] = 0x27;
1603 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1605 } else if (cfg->line_outs == 3) { /* 6 channels */
1606 for(i = 0; i < cfg->line_outs; i++) {
1607 nid = cfg->line_out_pins[i];
1609 /* config dac list */
1611 case AUTO_SEQ_FRONT:
1613 spec->multiout.dac_nids[i] = 0x10;
1615 case AUTO_SEQ_CENLFE:
1617 spec->multiout.dac_nids[i] = 0x12;
1619 case AUTO_SEQ_SURROUND:
1621 spec->multiout.dac_nids[i] = 0x11;
1633 /* add playback controls from the parsed DAC table */
1634 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1635 const struct auto_pin_cfg *cfg)
1638 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1642 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1643 nid = cfg->line_out_pins[i];
1648 if (i == AUTO_SEQ_CENLFE) {
1650 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1651 "Center Playback Volume",
1652 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1656 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1657 "LFE Playback Volume",
1658 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1662 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1663 "Center Playback Switch",
1664 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1668 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1669 "LFE Playback Switch",
1670 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1674 } else if (i == AUTO_SEQ_FRONT){
1675 /* add control to mixer index 0 */
1676 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1677 "Master Front Playback Volume",
1678 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1682 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1683 "Master Front Playback Switch",
1684 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1689 /* add control to PW3 */
1690 sprintf(name, "%s Playback Volume", chname[i]);
1691 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1692 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1696 sprintf(name, "%s Playback Switch", chname[i]);
1697 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1698 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1702 } else if (i == AUTO_SEQ_SURROUND) {
1703 sprintf(name, "%s Playback Volume", chname[i]);
1704 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1705 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1709 sprintf(name, "%s Playback Switch", chname[i]);
1710 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1711 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1715 } else if (i == AUTO_SEQ_SIDE) {
1716 sprintf(name, "%s Playback Volume", chname[i]);
1717 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1718 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1722 sprintf(name, "%s Playback Switch", chname[i]);
1723 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1724 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1734 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1741 if (spec->multiout.num_dacs == 5) /* 10 channels */
1742 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1743 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1744 spec->multiout.hp_nid = 0;
1746 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1747 "Headphone Playback Volume",
1748 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1751 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1752 "Headphone Playback Switch",
1753 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1760 /* create playback/capture controls for input pins */
1761 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1762 const struct auto_pin_cfg *cfg)
1764 static char *labels[] = {
1765 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1767 struct hda_input_mux *imux = &spec->private_imux[0];
1768 int i, err, idx = 0;
1770 /* for internal loopback recording select */
1771 imux->items[imux->num_items].label = "Stereo Mixer";
1772 imux->items[imux->num_items].index = idx;
1775 for (i = 0; i < AUTO_PIN_LAST; i++) {
1776 if (!cfg->input_pins[i])
1779 switch (cfg->input_pins[i]) {
1780 case 0x1d: /* Mic */
1784 case 0x1e: /* Line In */
1788 case 0x21: /* Front Mic */
1796 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1800 imux->items[imux->num_items].label = labels[i];
1801 imux->items[imux->num_items].index = idx;
1807 static int vt1709_parse_auto_config(struct hda_codec *codec)
1809 struct via_spec *spec = codec->spec;
1812 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1815 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1818 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1819 return 0; /* can't find valid BIOS pin config */
1821 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1824 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1827 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1831 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1833 if (spec->autocfg.dig_out_pin)
1834 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1835 if (spec->autocfg.dig_in_pin)
1836 spec->dig_in_nid = VT1709_DIGIN_NID;
1838 if (spec->kctls.list)
1839 spec->mixers[spec->num_mixers++] = spec->kctls.list;
1841 spec->input_mux = &spec->private_imux[0];
1844 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1849 #ifdef CONFIG_SND_HDA_POWER_SAVE
1850 static struct hda_amp_list vt1709_loopbacks[] = {
1851 { 0x18, HDA_INPUT, 1 },
1852 { 0x18, HDA_INPUT, 2 },
1853 { 0x18, HDA_INPUT, 3 },
1854 { 0x18, HDA_INPUT, 4 },
1859 static int patch_vt1709_10ch(struct hda_codec *codec)
1861 struct via_spec *spec;
1864 /* create a codec specific record */
1865 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1871 err = vt1709_parse_auto_config(codec);
1876 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1877 "Using genenic mode...\n");
1880 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
1881 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1883 spec->stream_name_analog = "VT1709 Analog";
1884 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1885 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1887 spec->stream_name_digital = "VT1709 Digital";
1888 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1889 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1892 if (!spec->adc_nids && spec->input_mux) {
1893 spec->adc_nids = vt1709_adc_nids;
1894 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1895 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1899 codec->patch_ops = via_patch_ops;
1901 codec->patch_ops.init = via_auto_init;
1902 codec->patch_ops.unsol_event = via_unsol_event;
1903 #ifdef CONFIG_SND_HDA_POWER_SAVE
1904 spec->loopback.amplist = vt1709_loopbacks;
1910 * generic initialization of ADC, input mixers and output mixers
1912 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1914 * Unmute ADC0-2 and set the default input to mic-in
1916 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1917 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1918 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1921 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1924 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1925 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1926 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1927 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1928 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1929 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1932 * Set up output selector (0x1a, 0x1b, 0x29)
1934 /* set vol=0 to output mixers */
1935 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1936 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1937 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1940 * Unmute PW3 and PW4
1942 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1943 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1945 /* Set input of PW4 as MW0 */
1946 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1947 /* PW9 Output enable */
1948 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1952 static int patch_vt1709_6ch(struct hda_codec *codec)
1954 struct via_spec *spec;
1957 /* create a codec specific record */
1958 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1964 err = vt1709_parse_auto_config(codec);
1969 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1970 "Using genenic mode...\n");
1973 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
1974 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1976 spec->stream_name_analog = "VT1709 Analog";
1977 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1978 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1980 spec->stream_name_digital = "VT1709 Digital";
1981 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1982 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1985 if (!spec->adc_nids && spec->input_mux) {
1986 spec->adc_nids = vt1709_adc_nids;
1987 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1988 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1992 codec->patch_ops = via_patch_ops;
1994 codec->patch_ops.init = via_auto_init;
1995 codec->patch_ops.unsol_event = via_unsol_event;
1996 #ifdef CONFIG_SND_HDA_POWER_SAVE
1997 spec->loopback.amplist = vt1709_loopbacks;
2002 /* capture mixer elements */
2003 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2004 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2005 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2006 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2007 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2009 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2010 /* The multiple "Capture Source" controls confuse alsamixer
2011 * So call somewhat different..
2013 /* .name = "Capture Source", */
2014 .name = "Input Source",
2016 .info = via_mux_enum_info,
2017 .get = via_mux_enum_get,
2018 .put = via_mux_enum_put,
2023 * generic initialization of ADC, input mixers and output mixers
2025 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2027 * Unmute ADC0-1 and set the default input to mic-in
2029 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2030 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2033 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2036 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2037 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2038 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2039 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2040 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2041 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2044 * Set up output mixers
2046 /* set vol=0 to output mixers */
2047 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2048 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2049 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2051 /* Setup default input to PW4 */
2052 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
2053 /* PW9 Output enable */
2054 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2055 /* PW10 Input enable */
2056 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2060 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2062 * Unmute ADC0-1 and set the default input to mic-in
2064 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2065 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2068 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2071 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2072 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2073 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2074 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2075 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2076 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2079 * Set up output mixers
2081 /* set vol=0 to output mixers */
2082 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2083 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2084 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2086 /* Setup default input of PW4 to MW0 */
2087 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2088 /* PW9 Output enable */
2089 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2090 /* PW10 Input enable */
2091 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2095 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2096 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2100 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2104 .nid = 0x10, /* NID to query formats and rates */
2106 .open = via_playback_pcm_open,
2107 .prepare = via_playback_multi_pcm_prepare,
2108 .cleanup = via_playback_multi_pcm_cleanup
2112 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2116 .nid = 0x10, /* NID to query formats and rates */
2118 .open = via_playback_pcm_open,
2119 .prepare = via_playback_multi_pcm_prepare,
2120 .cleanup = via_playback_multi_pcm_cleanup
2124 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2128 .nid = 0x13, /* NID to query formats and rates */
2130 .prepare = via_capture_pcm_prepare,
2131 .cleanup = via_capture_pcm_cleanup
2135 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2139 /* NID is set in via_build_pcms */
2141 .open = via_dig_playback_pcm_open,
2142 .close = via_dig_playback_pcm_close,
2143 .prepare = via_dig_playback_pcm_prepare
2147 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2153 /* fill in the dac_nids table from the parsed pin configuration */
2154 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2155 const struct auto_pin_cfg *cfg)
2160 spec->multiout.num_dacs = cfg->line_outs;
2162 spec->multiout.dac_nids = spec->private_dac_nids;
2164 for (i = 0; i < 4; i++) {
2165 nid = cfg->line_out_pins[i];
2167 /* config dac list */
2169 case AUTO_SEQ_FRONT:
2170 spec->multiout.dac_nids[i] = 0x10;
2172 case AUTO_SEQ_CENLFE:
2173 spec->multiout.dac_nids[i] = 0x24;
2175 case AUTO_SEQ_SURROUND:
2176 spec->multiout.dac_nids[i] = 0x11;
2179 spec->multiout.dac_nids[i] = 0x25;
2188 /* add playback controls from the parsed DAC table */
2189 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
2190 const struct auto_pin_cfg *cfg)
2193 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2194 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
2195 hda_nid_t nid, nid_vol = 0;
2198 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2199 nid = cfg->line_out_pins[i];
2204 nid_vol = nid_vols[i];
2206 if (i == AUTO_SEQ_CENLFE) {
2208 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2209 "Center Playback Volume",
2210 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2214 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2215 "LFE Playback Volume",
2216 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2220 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2221 "Center Playback Switch",
2222 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2226 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2227 "LFE Playback Switch",
2228 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2232 } else if (i == AUTO_SEQ_FRONT) {
2233 /* add control to mixer index 0 */
2234 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2235 "Master Front Playback Volume",
2236 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2240 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2241 "Master Front Playback Switch",
2242 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2247 /* add control to PW3 */
2248 sprintf(name, "%s Playback Volume", chname[i]);
2249 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2250 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2254 sprintf(name, "%s Playback Switch", chname[i]);
2255 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2256 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2261 sprintf(name, "%s Playback Volume", chname[i]);
2262 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2263 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2267 sprintf(name, "%s Playback Switch", chname[i]);
2268 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2269 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2279 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2286 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
2288 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2289 "Headphone Playback Volume",
2290 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2293 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2294 "Headphone Playback Switch",
2295 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2299 create_hp_imux(spec);
2304 /* create playback/capture controls for input pins */
2305 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2306 const struct auto_pin_cfg *cfg)
2308 static char *labels[] = {
2309 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2311 struct hda_input_mux *imux = &spec->private_imux[0];
2312 int i, err, idx = 0;
2314 /* for internal loopback recording select */
2315 imux->items[imux->num_items].label = "Stereo Mixer";
2316 imux->items[imux->num_items].index = idx;
2319 for (i = 0; i < AUTO_PIN_LAST; i++) {
2320 if (!cfg->input_pins[i])
2323 switch (cfg->input_pins[i]) {
2324 case 0x1a: /* Mic */
2328 case 0x1b: /* Line In */
2332 case 0x1e: /* Front Mic */
2340 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2344 imux->items[imux->num_items].label = labels[i];
2345 imux->items[imux->num_items].index = idx;
2351 static int vt1708B_parse_auto_config(struct hda_codec *codec)
2353 struct via_spec *spec = codec->spec;
2356 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2359 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
2362 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2363 return 0; /* can't find valid BIOS pin config */
2365 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
2368 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2371 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
2375 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2377 if (spec->autocfg.dig_out_pin)
2378 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2379 if (spec->autocfg.dig_in_pin)
2380 spec->dig_in_nid = VT1708B_DIGIN_NID;
2382 if (spec->kctls.list)
2383 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2385 spec->input_mux = &spec->private_imux[0];
2388 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2393 #ifdef CONFIG_SND_HDA_POWER_SAVE
2394 static struct hda_amp_list vt1708B_loopbacks[] = {
2395 { 0x16, HDA_INPUT, 1 },
2396 { 0x16, HDA_INPUT, 2 },
2397 { 0x16, HDA_INPUT, 3 },
2398 { 0x16, HDA_INPUT, 4 },
2403 static int patch_vt1708B_8ch(struct hda_codec *codec)
2405 struct via_spec *spec;
2408 /* create a codec specific record */
2409 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2415 /* automatic parse from the BIOS config */
2416 err = vt1708B_parse_auto_config(codec);
2421 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2422 "from BIOS. Using genenic mode...\n");
2425 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2426 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2428 spec->stream_name_analog = "VT1708B Analog";
2429 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
2430 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2432 spec->stream_name_digital = "VT1708B Digital";
2433 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2434 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2436 if (!spec->adc_nids && spec->input_mux) {
2437 spec->adc_nids = vt1708B_adc_nids;
2438 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2439 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2443 codec->patch_ops = via_patch_ops;
2445 codec->patch_ops.init = via_auto_init;
2446 codec->patch_ops.unsol_event = via_unsol_event;
2447 #ifdef CONFIG_SND_HDA_POWER_SAVE
2448 spec->loopback.amplist = vt1708B_loopbacks;
2454 static int patch_vt1708B_4ch(struct hda_codec *codec)
2456 struct via_spec *spec;
2459 /* create a codec specific record */
2460 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2466 /* automatic parse from the BIOS config */
2467 err = vt1708B_parse_auto_config(codec);
2472 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2473 "from BIOS. Using genenic mode...\n");
2476 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2477 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2479 spec->stream_name_analog = "VT1708B Analog";
2480 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
2481 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2483 spec->stream_name_digital = "VT1708B Digital";
2484 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2485 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2487 if (!spec->adc_nids && spec->input_mux) {
2488 spec->adc_nids = vt1708B_adc_nids;
2489 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2490 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2494 codec->patch_ops = via_patch_ops;
2496 codec->patch_ops.init = via_auto_init;
2497 codec->patch_ops.unsol_event = via_unsol_event;
2498 #ifdef CONFIG_SND_HDA_POWER_SAVE
2499 spec->loopback.amplist = vt1708B_loopbacks;
2505 /* Patch for VT1708S */
2507 /* VT1708S software backdoor based override for buggy hardware micboost
2509 #define MIC_BOOST_VOLUME(xname, nid) { \
2510 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2513 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2514 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2515 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2516 .info = mic_boost_volume_info, \
2517 .get = snd_hda_mixer_amp_volume_get, \
2518 .put = snd_hda_mixer_amp_volume_put, \
2519 .tlv = { .c = mic_boost_tlv }, \
2520 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2522 /* capture mixer elements */
2523 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2524 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2525 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2526 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2527 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2528 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2529 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2531 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2532 /* The multiple "Capture Source" controls confuse alsamixer
2533 * So call somewhat different..
2535 /* .name = "Capture Source", */
2536 .name = "Input Source",
2538 .info = via_mux_enum_info,
2539 .get = via_mux_enum_get,
2540 .put = via_mux_enum_put,
2545 static struct hda_verb vt1708S_volume_init_verbs[] = {
2546 /* Unmute ADC0-1 and set the default input to mic-in */
2547 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2548 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2550 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2551 * analog-loopback mixer widget */
2552 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2553 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2554 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2555 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2556 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2557 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2559 /* Setup default input of PW4 to MW0 */
2560 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2561 /* PW9, PW10 Output enable */
2562 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2563 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2564 /* Enable Mic Boost Volume backdoor */
2569 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2570 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2574 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2578 .nid = 0x10, /* NID to query formats and rates */
2580 .open = via_playback_pcm_open,
2581 .prepare = via_playback_pcm_prepare,
2582 .cleanup = via_playback_pcm_cleanup
2586 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2590 .nid = 0x13, /* NID to query formats and rates */
2592 .prepare = via_capture_pcm_prepare,
2593 .cleanup = via_capture_pcm_cleanup
2597 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
2601 /* NID is set in via_build_pcms */
2603 .open = via_dig_playback_pcm_open,
2604 .close = via_dig_playback_pcm_close,
2605 .prepare = via_dig_playback_pcm_prepare
2609 /* fill in the dac_nids table from the parsed pin configuration */
2610 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
2611 const struct auto_pin_cfg *cfg)
2616 spec->multiout.num_dacs = cfg->line_outs;
2618 spec->multiout.dac_nids = spec->private_dac_nids;
2620 for (i = 0; i < 4; i++) {
2621 nid = cfg->line_out_pins[i];
2623 /* config dac list */
2625 case AUTO_SEQ_FRONT:
2626 spec->multiout.dac_nids[i] = 0x10;
2628 case AUTO_SEQ_CENLFE:
2629 spec->multiout.dac_nids[i] = 0x24;
2631 case AUTO_SEQ_SURROUND:
2632 spec->multiout.dac_nids[i] = 0x11;
2635 spec->multiout.dac_nids[i] = 0x25;
2644 /* add playback controls from the parsed DAC table */
2645 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
2646 const struct auto_pin_cfg *cfg)
2649 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2650 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
2651 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
2652 hda_nid_t nid, nid_vol, nid_mute;
2655 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2656 nid = cfg->line_out_pins[i];
2661 nid_vol = nid_vols[i];
2662 nid_mute = nid_mutes[i];
2664 if (i == AUTO_SEQ_CENLFE) {
2666 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2667 "Center Playback Volume",
2668 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2672 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2673 "LFE Playback Volume",
2674 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2678 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2679 "Center Playback Switch",
2680 HDA_COMPOSE_AMP_VAL(nid_mute,
2685 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2686 "LFE Playback Switch",
2687 HDA_COMPOSE_AMP_VAL(nid_mute,
2692 } else if (i == AUTO_SEQ_FRONT) {
2693 /* add control to mixer index 0 */
2694 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2695 "Master Front Playback Volume",
2696 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2700 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2701 "Master Front Playback Switch",
2702 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2708 sprintf(name, "%s Playback Volume", chname[i]);
2709 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2710 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2714 sprintf(name, "%s Playback Switch", chname[i]);
2715 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2716 HDA_COMPOSE_AMP_VAL(nid_mute,
2722 sprintf(name, "%s Playback Volume", chname[i]);
2723 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2724 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2728 sprintf(name, "%s Playback Switch", chname[i]);
2729 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2730 HDA_COMPOSE_AMP_VAL(nid_mute,
2741 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2748 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
2750 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2751 "Headphone Playback Volume",
2752 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
2756 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2757 "Headphone Playback Switch",
2758 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2762 create_hp_imux(spec);
2767 /* create playback/capture controls for input pins */
2768 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2769 const struct auto_pin_cfg *cfg)
2771 static char *labels[] = {
2772 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2774 struct hda_input_mux *imux = &spec->private_imux[0];
2775 int i, err, idx = 0;
2777 /* for internal loopback recording select */
2778 imux->items[imux->num_items].label = "Stereo Mixer";
2779 imux->items[imux->num_items].index = 5;
2782 for (i = 0; i < AUTO_PIN_LAST; i++) {
2783 if (!cfg->input_pins[i])
2786 switch (cfg->input_pins[i]) {
2787 case 0x1a: /* Mic */
2791 case 0x1b: /* Line In */
2795 case 0x1e: /* Front Mic */
2803 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2807 imux->items[imux->num_items].label = labels[i];
2808 imux->items[imux->num_items].index = idx-1;
2814 static int vt1708S_parse_auto_config(struct hda_codec *codec)
2816 struct via_spec *spec = codec->spec;
2818 static hda_nid_t vt1708s_ignore[] = {0x21, 0};
2820 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
2824 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
2827 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2828 return 0; /* can't find valid BIOS pin config */
2830 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
2833 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2836 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
2840 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2842 if (spec->autocfg.dig_out_pin)
2843 spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID;
2845 spec->extra_dig_out_nid = 0x15;
2847 if (spec->kctls.list)
2848 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2850 spec->input_mux = &spec->private_imux[0];
2853 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2858 #ifdef CONFIG_SND_HDA_POWER_SAVE
2859 static struct hda_amp_list vt1708S_loopbacks[] = {
2860 { 0x16, HDA_INPUT, 1 },
2861 { 0x16, HDA_INPUT, 2 },
2862 { 0x16, HDA_INPUT, 3 },
2863 { 0x16, HDA_INPUT, 4 },
2868 static int patch_vt1708S(struct hda_codec *codec)
2870 struct via_spec *spec;
2873 /* create a codec specific record */
2874 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2880 /* automatic parse from the BIOS config */
2881 err = vt1708S_parse_auto_config(codec);
2886 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2887 "from BIOS. Using genenic mode...\n");
2890 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2891 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2893 spec->stream_name_analog = "VT1708S Analog";
2894 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2895 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2897 spec->stream_name_digital = "VT1708S Digital";
2898 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2900 if (!spec->adc_nids && spec->input_mux) {
2901 spec->adc_nids = vt1708S_adc_nids;
2902 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2903 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2907 codec->patch_ops = via_patch_ops;
2909 codec->patch_ops.init = via_auto_init;
2910 codec->patch_ops.unsol_event = via_unsol_event;
2911 #ifdef CONFIG_SND_HDA_POWER_SAVE
2912 spec->loopback.amplist = vt1708S_loopbacks;
2918 /* Patch for VT1702 */
2920 /* capture mixer elements */
2921 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
2922 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
2923 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
2924 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
2925 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
2926 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
2927 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
2928 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2931 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2932 /* The multiple "Capture Source" controls confuse alsamixer
2933 * So call somewhat different..
2935 /* .name = "Capture Source", */
2936 .name = "Input Source",
2938 .info = via_mux_enum_info,
2939 .get = via_mux_enum_get,
2940 .put = via_mux_enum_put,
2945 static struct hda_verb vt1702_volume_init_verbs[] = {
2947 * Unmute ADC0-1 and set the default input to mic-in
2949 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2950 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2951 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2954 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2957 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2958 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2959 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2960 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2961 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2962 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2964 /* Setup default input of PW4 to MW0 */
2965 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
2966 /* PW6 PW7 Output enable */
2967 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2968 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2972 static struct hda_verb vt1702_uniwill_init_verbs[] = {
2973 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
2974 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2978 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
2982 .nid = 0x10, /* NID to query formats and rates */
2984 .open = via_playback_pcm_open,
2985 .prepare = via_playback_multi_pcm_prepare,
2986 .cleanup = via_playback_multi_pcm_cleanup
2990 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2994 .nid = 0x12, /* NID to query formats and rates */
2996 .prepare = via_capture_pcm_prepare,
2997 .cleanup = via_capture_pcm_cleanup
3001 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
3005 /* NID is set in via_build_pcms */
3007 .open = via_dig_playback_pcm_open,
3008 .close = via_dig_playback_pcm_close,
3009 .prepare = via_dig_playback_pcm_prepare
3013 /* fill in the dac_nids table from the parsed pin configuration */
3014 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
3015 const struct auto_pin_cfg *cfg)
3017 spec->multiout.num_dacs = 1;
3018 spec->multiout.dac_nids = spec->private_dac_nids;
3020 if (cfg->line_out_pins[0]) {
3021 /* config dac list */
3022 spec->multiout.dac_nids[0] = 0x10;
3028 /* add playback controls from the parsed DAC table */
3029 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3030 const struct auto_pin_cfg *cfg)
3034 if (!cfg->line_out_pins[0])
3037 /* add control to mixer index 0 */
3038 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3039 "Master Front Playback Volume",
3040 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3043 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3044 "Master Front Playback Switch",
3045 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3050 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3051 "Front Playback Volume",
3052 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
3055 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3056 "Front Playback Switch",
3057 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
3064 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3071 spec->multiout.hp_nid = 0x1D;
3073 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3074 "Headphone Playback Volume",
3075 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
3079 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3080 "Headphone Playback Switch",
3081 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3085 create_hp_imux(spec);
3090 /* create playback/capture controls for input pins */
3091 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3092 const struct auto_pin_cfg *cfg)
3094 static char *labels[] = {
3095 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3097 struct hda_input_mux *imux = &spec->private_imux[0];
3098 int i, err, idx = 0;
3100 /* for internal loopback recording select */
3101 imux->items[imux->num_items].label = "Stereo Mixer";
3102 imux->items[imux->num_items].index = 3;
3105 for (i = 0; i < AUTO_PIN_LAST; i++) {
3106 if (!cfg->input_pins[i])
3109 switch (cfg->input_pins[i]) {
3110 case 0x14: /* Mic */
3114 case 0x15: /* Line In */
3118 case 0x18: /* Front Mic */
3122 err = via_new_analog_input(spec, cfg->input_pins[i],
3123 labels[i], idx, 0x1A);
3126 imux->items[imux->num_items].label = labels[i];
3127 imux->items[imux->num_items].index = idx-1;
3133 static int vt1702_parse_auto_config(struct hda_codec *codec)
3135 struct via_spec *spec = codec->spec;
3137 static hda_nid_t vt1702_ignore[] = {0x1C, 0};
3139 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3143 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3146 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3147 return 0; /* can't find valid BIOS pin config */
3149 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3152 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3155 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3159 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3161 if (spec->autocfg.dig_out_pin)
3162 spec->multiout.dig_out_nid = VT1702_DIGOUT_NID;
3164 spec->extra_dig_out_nid = 0x1B;
3166 if (spec->kctls.list)
3167 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3169 spec->input_mux = &spec->private_imux[0];
3172 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3177 #ifdef CONFIG_SND_HDA_POWER_SAVE
3178 static struct hda_amp_list vt1702_loopbacks[] = {
3179 { 0x1A, HDA_INPUT, 1 },
3180 { 0x1A, HDA_INPUT, 2 },
3181 { 0x1A, HDA_INPUT, 3 },
3182 { 0x1A, HDA_INPUT, 4 },
3187 static int patch_vt1702(struct hda_codec *codec)
3189 struct via_spec *spec;
3191 unsigned int response;
3192 unsigned char control;
3194 /* create a codec specific record */
3195 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3201 /* automatic parse from the BIOS config */
3202 err = vt1702_parse_auto_config(codec);
3207 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3208 "from BIOS. Using genenic mode...\n");
3211 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3212 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
3214 spec->stream_name_analog = "VT1702 Analog";
3215 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3216 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3218 spec->stream_name_digital = "VT1702 Digital";
3219 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3221 if (!spec->adc_nids && spec->input_mux) {
3222 spec->adc_nids = vt1702_adc_nids;
3223 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3224 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3228 codec->patch_ops = via_patch_ops;
3230 codec->patch_ops.init = via_auto_init;
3231 codec->patch_ops.unsol_event = via_unsol_event;
3232 #ifdef CONFIG_SND_HDA_POWER_SAVE
3233 spec->loopback.amplist = vt1702_loopbacks;
3237 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3238 control = (unsigned char)(response & 0xff);
3240 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
3242 /* Enable GPIO 0&1 for volume&mute control */
3243 /* Enable GPIO 2 for DMIC-DATA */
3244 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3245 control = (unsigned char)((response >> 16) & 0x3f);
3246 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
3254 struct hda_codec_preset snd_hda_preset_via[] = {
3255 { .id = 0x11061708, .name = "VIA VT1708", .patch = patch_vt1708},
3256 { .id = 0x11061709, .name = "VIA VT1708", .patch = patch_vt1708},
3257 { .id = 0x1106170A, .name = "VIA VT1708", .patch = patch_vt1708},
3258 { .id = 0x1106170B, .name = "VIA VT1708", .patch = patch_vt1708},
3259 { .id = 0x1106E710, .name = "VIA VT1709 10-Ch",
3260 .patch = patch_vt1709_10ch},
3261 { .id = 0x1106E711, .name = "VIA VT1709 10-Ch",
3262 .patch = patch_vt1709_10ch},
3263 { .id = 0x1106E712, .name = "VIA VT1709 10-Ch",
3264 .patch = patch_vt1709_10ch},
3265 { .id = 0x1106E713, .name = "VIA VT1709 10-Ch",
3266 .patch = patch_vt1709_10ch},
3267 { .id = 0x1106E714, .name = "VIA VT1709 6-Ch",
3268 .patch = patch_vt1709_6ch},
3269 { .id = 0x1106E715, .name = "VIA VT1709 6-Ch",
3270 .patch = patch_vt1709_6ch},
3271 { .id = 0x1106E716, .name = "VIA VT1709 6-Ch",
3272 .patch = patch_vt1709_6ch},
3273 { .id = 0x1106E717, .name = "VIA VT1709 6-Ch",
3274 .patch = patch_vt1709_6ch},
3275 { .id = 0x1106E720, .name = "VIA VT1708B 8-Ch",
3276 .patch = patch_vt1708B_8ch},
3277 { .id = 0x1106E721, .name = "VIA VT1708B 8-Ch",
3278 .patch = patch_vt1708B_8ch},
3279 { .id = 0x1106E722, .name = "VIA VT1708B 8-Ch",
3280 .patch = patch_vt1708B_8ch},
3281 { .id = 0x1106E723, .name = "VIA VT1708B 8-Ch",
3282 .patch = patch_vt1708B_8ch},
3283 { .id = 0x1106E724, .name = "VIA VT1708B 4-Ch",
3284 .patch = patch_vt1708B_4ch},
3285 { .id = 0x1106E725, .name = "VIA VT1708B 4-Ch",
3286 .patch = patch_vt1708B_4ch},
3287 { .id = 0x1106E726, .name = "VIA VT1708B 4-Ch",
3288 .patch = patch_vt1708B_4ch},
3289 { .id = 0x1106E727, .name = "VIA VT1708B 4-Ch",
3290 .patch = patch_vt1708B_4ch},
3291 { .id = 0x11060397, .name = "VIA VT1708S",
3292 .patch = patch_vt1708S},
3293 { .id = 0x11061397, .name = "VIA VT1708S",
3294 .patch = patch_vt1708S},
3295 { .id = 0x11062397, .name = "VIA VT1708S",
3296 .patch = patch_vt1708S},
3297 { .id = 0x11063397, .name = "VIA VT1708S",
3298 .patch = patch_vt1708S},
3299 { .id = 0x11064397, .name = "VIA VT1708S",
3300 .patch = patch_vt1708S},
3301 { .id = 0x11065397, .name = "VIA VT1708S",
3302 .patch = patch_vt1708S},
3303 { .id = 0x11066397, .name = "VIA VT1708S",
3304 .patch = patch_vt1708S},
3305 { .id = 0x11067397, .name = "VIA VT1708S",
3306 .patch = patch_vt1708S},
3307 { .id = 0x11060398, .name = "VIA VT1702",
3308 .patch = patch_vt1702},
3309 { .id = 0x11061398, .name = "VIA VT1702",
3310 .patch = patch_vt1702},
3311 { .id = 0x11062398, .name = "VIA VT1702",
3312 .patch = patch_vt1702},
3313 { .id = 0x11063398, .name = "VIA VT1702",
3314 .patch = patch_vt1702},
3315 { .id = 0x11064398, .name = "VIA VT1702",
3316 .patch = patch_vt1702},
3317 { .id = 0x11065398, .name = "VIA VT1702",
3318 .patch = patch_vt1702},
3319 { .id = 0x11066398, .name = "VIA VT1702",
3320 .patch = patch_vt1702},
3321 { .id = 0x11067398, .name = "VIA VT1702",
3322 .patch = patch_vt1702},