1 From: Takashi Iwai <tiwai@suse.de>
2 Subject: ALSA: hda - VIA codecs updates
3 Patch-mainline: 2.6.28-rc1
6 A pile of updates for VIA HD-audio codecs.
8 Signed-off-by: Takashi Iwai <tiwai@suse.de>
11 diff -ruN a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
12 --- a/sound/pci/hda/patch_via.c
13 +++ b/sound/pci/hda/patch_via.c
16 * Universal Interface for Intel High Definition Audio Codec
18 - * HD audio interface patch for VIA VT1708 codec
19 + * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
21 - * Copyright (c) 2006 Lydia Wang <lydiawang@viatech.com>
22 - * Takashi Iwai <tiwai@suse.de>
23 + * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
24 + * Takashi Iwai <tiwai@suse.de>
26 * This driver is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
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/delay.h>
44 #include <linux/slab.h>
45 #include <sound/core.h>
46 +#include <sound/asoundef.h>
47 #include "hda_codec.h"
48 #include "hda_local.h"
49 #include "hda_patch.h"
51 #define VT1708_DIGOUT_NID 0x14
52 #define VT1708_DIGIN_NID 0x16
53 #define VT1708_DIGIN_PIN 0x26
54 +#define VT1708_HP_PIN_NID 0x20
55 +#define VT1708_CD_PIN_NID 0x24
57 #define VT1709_HP_DAC_NID 0x28
58 #define VT1709_DIGOUT_NID 0x13
60 #define VT1708B_DIGIN_NID 0x15
61 #define VT1708B_DIGIN_PIN 0x21
63 +#define VT1708S_HP_NID 0x25
64 +#define VT1708S_DIGOUT_NID 0x12
66 +#define VT1702_HP_NID 0x17
67 +#define VT1702_DIGOUT_NID 0x11
69 #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
70 #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
71 #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
72 #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
73 #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
74 +#define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
75 +#define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
89 +static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
91 + u16 ven_id = vendor_id >> 16;
92 + u16 dev_id = vendor_id & 0xffff;
93 + enum VIA_HDA_CODEC codec_type;
95 + /* get codec type */
96 + if (ven_id != 0x1106)
97 + codec_type = UNKNOWN;
98 + else if (dev_id >= 0x1708 && dev_id <= 0x170b)
99 + codec_type = VT1708;
100 + else if (dev_id >= 0xe710 && dev_id <= 0xe713)
101 + codec_type = VT1709_10CH;
102 + else if (dev_id >= 0xe714 && dev_id <= 0xe717)
103 + codec_type = VT1709_6CH;
104 + else if (dev_id >= 0xe720 && dev_id <= 0xe723)
105 + codec_type = VT1708B_8CH;
106 + else if (dev_id >= 0xe724 && dev_id <= 0xe727)
107 + codec_type = VT1708B_4CH;
108 + else if ((dev_id & 0xfff) == 0x397
109 + && (dev_id >> 12) < 8)
110 + codec_type = VT1708S;
111 + else if ((dev_id & 0xfff) == 0x398
112 + && (dev_id >> 12) < 8)
113 + codec_type = VT1702;
115 + codec_type = UNKNOWN;
119 +#define VIA_HP_EVENT 0x01
120 +#define VIA_GPIO_EVENT 0x02
129 + AUTO_SEQ_FRONT = 0,
135 +#define get_amp_nid(kc) ((kc)->private_value & 0xffff)
137 +/* Some VT1708S based boards gets the micboost setting wrong, so we have
138 + * to apply some brute-force and re-write the TLV's by software. */
139 +static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
140 + unsigned int size, unsigned int __user *_tlv)
142 + struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
143 + hda_nid_t nid = get_amp_nid(kcontrol);
145 + if (get_codec_type(codec->vendor_id) == VT1708S
146 + && (nid == 0x1a || nid == 0x1e)) {
147 + if (size < 4 * sizeof(unsigned int))
149 + if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */
151 + if (put_user(2 * sizeof(unsigned int), _tlv + 1))
153 + if (put_user(0, _tlv + 2)) /* offset = 0 */
155 + if (put_user(1000, _tlv + 3)) /* step size = 10 dB */
161 +static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
162 + struct snd_ctl_elem_info *uinfo)
164 + struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
165 + hda_nid_t nid = get_amp_nid(kcontrol);
167 + if (get_codec_type(codec->vendor_id) == VT1708S
168 + && (nid == 0x1a || nid == 0x1e)) {
169 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
171 + uinfo->value.integer.min = 0;
172 + uinfo->value.integer.max = 3;
177 static struct snd_kcontrol_new vt1708_control_templates[] = {
178 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
179 HDA_CODEC_MUTE(NULL, 0, 0, 0),
181 struct snd_kcontrol_new *mixers[3];
182 unsigned int num_mixers;
184 - struct hda_verb *init_verbs;
185 + struct hda_verb *init_verbs[5];
186 + unsigned int num_iverbs;
188 char *stream_name_analog;
189 struct hda_pcm_stream *stream_analog_playback;
193 struct hda_multi_out multiout;
194 + hda_nid_t extra_dig_out_nid;
197 unsigned int num_adc_nids;
198 @@ -117,15 +223,19 @@
199 unsigned int cur_mux[3];
201 /* PCM information */
202 - struct hda_pcm pcm_rec[2];
203 + struct hda_pcm pcm_rec[3];
205 /* dynamic controls, init_verbs and input_mux */
206 struct auto_pin_cfg autocfg;
207 unsigned int num_kctl_alloc, num_kctl_used;
208 struct snd_kcontrol_new *kctl_alloc;
209 - struct hda_input_mux private_imux;
210 + struct hda_input_mux private_imux[2];
211 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
213 + /* HP mode source */
214 + const struct hda_input_mux *hp_mux;
215 + unsigned int hp_independent_mode;
217 #ifdef CONFIG_SND_HDA_POWER_SAVE
218 struct hda_loopback_check loopback;
224 +static hda_nid_t vt1708S_adc_nids[2] = {
229 +static hda_nid_t vt1702_adc_nids[3] = {
234 /* add dynamic controls */
235 static int via_add_control(struct via_spec *spec, int type, const char *name,
237 @@ -283,19 +403,108 @@
238 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
239 0x18, &spec->cur_mux[adc_idx]);
240 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
241 - IS_VT1709_6CH_VENDORID(vendor_id)) && adc_idx == 0)
242 + IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0))
243 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
244 0x19, &spec->cur_mux[adc_idx]);
245 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
246 - IS_VT1708B_4CH_VENDORID(vendor_id)) && adc_idx == 0)
247 + IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0))
248 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
249 0x17, &spec->cur_mux[adc_idx]);
250 + else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0))
251 + return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
252 + 0x13, &spec->cur_mux[adc_idx]);
254 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
255 spec->adc_nids[adc_idx],
256 &spec->cur_mux[adc_idx]);
259 +static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
260 + struct snd_ctl_elem_info *uinfo)
262 + struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
263 + struct via_spec *spec = codec->spec;
264 + return snd_hda_input_mux_info(spec->hp_mux, uinfo);
267 +static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
268 + struct snd_ctl_elem_value *ucontrol)
270 + struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
271 + struct via_spec *spec = codec->spec;
272 + hda_nid_t nid = spec->autocfg.hp_pins[0];
273 + unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
274 + AC_VERB_GET_CONNECT_SEL,
277 + ucontrol->value.enumerated.item[0] = pinsel;
282 +static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
283 + struct snd_ctl_elem_value *ucontrol)
285 + struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
286 + struct via_spec *spec = codec->spec;
287 + hda_nid_t nid = spec->autocfg.hp_pins[0];
288 + unsigned int pinsel = ucontrol->value.enumerated.item[0];
289 + unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
290 + AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
292 + if (con_nid == spec->multiout.hp_nid) {
294 + if (!spec->hp_independent_mode) {
295 + if (spec->multiout.num_dacs > 1)
296 + spec->multiout.num_dacs -= 1;
297 + spec->hp_independent_mode = 1;
299 + } else if (pinsel == 1) {
300 + if (spec->hp_independent_mode) {
301 + if (spec->multiout.num_dacs > 1)
302 + spec->multiout.num_dacs += 1;
303 + spec->hp_independent_mode = 0;
308 + if (spec->hp_independent_mode) {
309 + if (spec->multiout.num_dacs > 1)
310 + spec->multiout.num_dacs += 1;
311 + spec->hp_independent_mode = 0;
313 + } else if (pinsel == 1) {
314 + if (!spec->hp_independent_mode) {
315 + if (spec->multiout.num_dacs > 1)
316 + spec->multiout.num_dacs -= 1;
317 + spec->hp_independent_mode = 1;
321 + snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
324 + if (spec->multiout.hp_nid &&
325 + spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
326 + snd_hda_codec_setup_stream(codec,
327 + spec->multiout.hp_nid,
333 +static struct snd_kcontrol_new via_hp_mixer[] = {
335 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
336 + .name = "Independent HP",
338 + .info = via_independent_hp_info,
339 + .get = via_independent_hp_get,
340 + .put = via_independent_hp_put,
345 /* capture mixer elements */
346 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
347 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
348 @@ -380,6 +589,138 @@
349 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
353 +static void playback_multi_pcm_prep_0(struct hda_codec *codec,
354 + unsigned int stream_tag,
355 + unsigned int format,
356 + struct snd_pcm_substream *substream)
358 + struct via_spec *spec = codec->spec;
359 + struct hda_multi_out *mout = &spec->multiout;
360 + hda_nid_t *nids = mout->dac_nids;
361 + int chs = substream->runtime->channels;
364 + mutex_lock(&codec->spdif_mutex);
365 + if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
367 + snd_hda_is_supported_format(codec, mout->dig_out_nid,
369 + !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
370 + mout->dig_out_used = HDA_DIG_ANALOG_DUP;
371 + /* turn off SPDIF once; otherwise the IEC958 bits won't
373 + if (codec->spdif_ctls & AC_DIG1_ENABLE)
374 + snd_hda_codec_write(codec, mout->dig_out_nid, 0,
375 + AC_VERB_SET_DIGI_CONVERT_1,
376 + codec->spdif_ctls &
377 + ~AC_DIG1_ENABLE & 0xff);
378 + snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
379 + stream_tag, 0, format);
380 + /* turn on again (if needed) */
381 + if (codec->spdif_ctls & AC_DIG1_ENABLE)
382 + snd_hda_codec_write(codec, mout->dig_out_nid, 0,
383 + AC_VERB_SET_DIGI_CONVERT_1,
384 + codec->spdif_ctls & 0xff);
386 + mout->dig_out_used = 0;
387 + snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
391 + mutex_unlock(&codec->spdif_mutex);
394 + snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
397 + if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
398 + !spec->hp_independent_mode)
399 + /* headphone out will just decode front left/right (stereo) */
400 + snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
403 + /* extra outputs copied from front */
404 + for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
405 + if (mout->extra_out_nid[i])
406 + snd_hda_codec_setup_stream(codec,
407 + mout->extra_out_nid[i],
408 + stream_tag, 0, format);
411 + for (i = 1; i < mout->num_dacs; i++) {
412 + if (chs >= (i + 1) * 2) /* independent out */
413 + snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
415 + else /* copy front */
416 + snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
421 +static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
422 + struct hda_codec *codec,
423 + unsigned int stream_tag,
424 + unsigned int format,
425 + struct snd_pcm_substream *substream)
427 + struct via_spec *spec = codec->spec;
428 + struct hda_multi_out *mout = &spec->multiout;
429 + hda_nid_t *nids = mout->dac_nids;
431 + if (substream->number == 0)
432 + playback_multi_pcm_prep_0(codec, stream_tag, format,
435 + if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
436 + spec->hp_independent_mode)
437 + snd_hda_codec_setup_stream(codec, mout->hp_nid,
438 + stream_tag, 0, format);
444 +static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
445 + struct hda_codec *codec,
446 + struct snd_pcm_substream *substream)
448 + struct via_spec *spec = codec->spec;
449 + struct hda_multi_out *mout = &spec->multiout;
450 + hda_nid_t *nids = mout->dac_nids;
453 + if (substream->number == 0) {
454 + for (i = 0; i < mout->num_dacs; i++)
455 + snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
457 + if (mout->hp_nid && !spec->hp_independent_mode)
458 + snd_hda_codec_setup_stream(codec, mout->hp_nid,
461 + for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
462 + if (mout->extra_out_nid[i])
463 + snd_hda_codec_setup_stream(codec,
464 + mout->extra_out_nid[i],
466 + mutex_lock(&codec->spdif_mutex);
467 + if (mout->dig_out_nid &&
468 + mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
469 + snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
471 + mout->dig_out_used = 0;
473 + mutex_unlock(&codec->spdif_mutex);
475 + if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
476 + spec->hp_independent_mode)
477 + snd_hda_codec_setup_stream(codec, mout->hp_nid,
488 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
491 +/* setup SPDIF output stream */
492 +static void setup_dig_playback_stream(struct hda_codec *codec, hda_nid_t nid,
493 + unsigned int stream_tag, unsigned int format)
495 + /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
496 + if (codec->spdif_ctls & AC_DIG1_ENABLE)
497 + snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
498 + codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
499 + snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
500 + /* turn on again (if needed) */
501 + if (codec->spdif_ctls & AC_DIG1_ENABLE)
502 + snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
503 + codec->spdif_ctls & 0xff);
506 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
507 struct hda_codec *codec,
508 unsigned int stream_tag,
510 struct snd_pcm_substream *substream)
512 struct via_spec *spec = codec->spec;
513 - return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
514 - stream_tag, format, substream);
517 + /* 1st or 2nd S/PDIF */
518 + if (substream->number == 0)
519 + nid = spec->multiout.dig_out_nid;
520 + else if (substream->number == 1)
521 + nid = spec->extra_dig_out_nid;
525 + mutex_lock(&codec->spdif_mutex);
526 + setup_dig_playback_stream(codec, nid, stream_tag, format);
527 + mutex_unlock(&codec->spdif_mutex);
532 @@ -436,14 +804,14 @@
535 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
540 .nid = 0x10, /* NID to query formats and rates */
542 .open = via_playback_pcm_open,
543 - .prepare = via_playback_pcm_prepare,
544 - .cleanup = via_playback_pcm_cleanup
545 + .prepare = via_playback_multi_pcm_prepare,
546 + .cleanup = via_playback_multi_pcm_cleanup
553 spec->multiout.share_spdif = 1;
555 + if (spec->extra_dig_out_nid) {
556 + err = snd_hda_create_spdif_out_ctls(codec,
557 + spec->extra_dig_out_nid);
562 if (spec->dig_in_nid) {
563 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
564 @@ -580,10 +955,89 @@
568 +/* mute internal speaker if HP is plugged */
569 +static void via_hp_automute(struct hda_codec *codec)
571 + unsigned int present;
572 + struct via_spec *spec = codec->spec;
574 + present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
575 + AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
576 + snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
577 + HDA_OUTPUT, 0, HDA_AMP_MUTE,
578 + present ? HDA_AMP_MUTE : 0);
581 +static void via_gpio_control(struct hda_codec *codec)
583 + unsigned int gpio_data;
584 + unsigned int vol_counter;
586 + unsigned int master_vol;
588 + struct via_spec *spec = codec->spec;
590 + gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
591 + AC_VERB_GET_GPIO_DATA, 0) & 0x03;
593 + vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
594 + 0xF84, 0) & 0x3F0000) >> 16;
596 + vol = vol_counter & 0x1F;
597 + master_vol = snd_hda_codec_read(codec, 0x1A, 0,
598 + AC_VERB_GET_AMP_GAIN_MUTE,
601 + if (gpio_data == 0x02) {
602 + /* unmute line out */
603 + snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
604 + HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
606 + if (vol_counter & 0x20) {
607 + /* decrease volume */
608 + if (vol > master_vol)
610 + snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
611 + 0, HDA_AMP_VOLMASK,
614 + /* increase volume */
615 + snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
617 + ((master_vol+vol) > 0x2A) ? 0x2A :
620 + } else if (!(gpio_data & 0x02)) {
621 + /* mute line out */
622 + snd_hda_codec_amp_stereo(codec,
623 + spec->autocfg.line_out_pins[0],
624 + HDA_OUTPUT, 0, HDA_AMP_MUTE,
629 +/* unsolicited event for jack sensing */
630 +static void via_unsol_event(struct hda_codec *codec,
634 + if (res == VIA_HP_EVENT)
635 + via_hp_automute(codec);
636 + else if (res == VIA_GPIO_EVENT)
637 + via_gpio_control(codec);
640 +static hda_nid_t slave_dig_outs[] = {
644 static int via_init(struct hda_codec *codec)
646 struct via_spec *spec = codec->spec;
647 - snd_hda_sequence_write(codec, spec->init_verbs);
649 + for (i = 0; i < spec->num_iverbs; i++)
650 + snd_hda_sequence_write(codec, spec->init_verbs[i]);
652 /* Lydia Add for EAPD enable */
653 if (!spec->dig_in_nid) { /* No Digital In connection */
654 if (IS_VT1708_VENDORID(codec->vendor_id)) {
656 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
657 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
659 + /* no slave outs */
660 + codec->slave_dig_outs = slave_dig_outs;
665 @@ -657,10 +1114,10 @@
666 spec->multiout.dac_nids[i] = 0x12;
668 case AUTO_SEQ_SURROUND:
669 - spec->multiout.dac_nids[i] = 0x13;
670 + spec->multiout.dac_nids[i] = 0x11;
673 - spec->multiout.dac_nids[i] = 0x11;
674 + spec->multiout.dac_nids[i] = 0x13;
681 if (i != AUTO_SEQ_FRONT)
682 - nid_vol = 0x1b - i + 1;
683 + nid_vol = 0x18 + i;
685 if (i == AUTO_SEQ_CENLFE) {
687 @@ -760,6 +1217,24 @@
691 +static void create_hp_imux(struct via_spec *spec)
694 + struct hda_input_mux *imux = &spec->private_imux[1];
695 + static const char *texts[] = { "OFF", "ON", NULL};
697 + /* for hp mode select */
699 + while (texts[i] != NULL) {
700 + imux->items[imux->num_items].label = texts[i];
701 + imux->items[imux->num_items].index = i;
706 + spec->hp_mux = &spec->private_imux[1];
709 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
716 + create_hp_imux(spec);
722 static char *labels[] = {
723 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
725 - struct hda_input_mux *imux = &spec->private_imux;
726 + struct hda_input_mux *imux = &spec->private_imux[0];
729 /* for internal loopback recording select */
730 @@ -840,11 +1317,36 @@
734 +static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
736 + unsigned int def_conf;
737 + unsigned char seqassoc;
739 + def_conf = snd_hda_codec_read(codec, nid, 0,
740 + AC_VERB_GET_CONFIG_DEFAULT, 0);
741 + seqassoc = (unsigned char) get_defcfg_association(def_conf);
742 + seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
743 + if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
744 + if (seqassoc == 0xff) {
745 + def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
746 + snd_hda_codec_write(codec, nid, 0,
747 + AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
755 static int vt1708_parse_auto_config(struct hda_codec *codec)
757 struct via_spec *spec = codec->spec;
760 + /* Add HP and CD pin config connect bit re-config action */
761 + vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
762 + vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
764 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
767 @@ -874,9 +1376,12 @@
768 if (spec->kctl_alloc)
769 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
771 - spec->init_verbs = vt1708_volume_init_verbs;
772 + spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
774 + spec->input_mux = &spec->private_imux[0];
776 - spec->input_mux = &spec->private_imux;
778 + spec->mixers[spec->num_mixers++] = via_hp_mixer;
785 /* create a codec specific record */
786 - spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
787 + spec = kzalloc(sizeof(*spec), GFP_KERNEL);
791 @@ -966,6 +1471,11 @@
795 +static struct hda_verb vt1709_uniwill_init_verbs[] = {
796 + {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
801 * generic initialization of ADC, input mixers and output mixers
803 @@ -1090,11 +1600,11 @@
805 case AUTO_SEQ_SURROUND:
807 - spec->multiout.dac_nids[i] = 0x27;
808 + spec->multiout.dac_nids[i] = 0x11;
812 - spec->multiout.dac_nids[i] = 0x11;
813 + spec->multiout.dac_nids[i] = 0x27;
817 @@ -1203,26 +1713,26 @@
818 } else if (i == AUTO_SEQ_SURROUND) {
819 sprintf(name, "%s Playback Volume", chname[i]);
820 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
821 - HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
822 + HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
826 sprintf(name, "%s Playback Switch", chname[i]);
827 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
828 - HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
829 + HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
833 } else if (i == AUTO_SEQ_SIDE) {
834 sprintf(name, "%s Playback Volume", chname[i]);
835 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
836 - HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
837 + HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
841 sprintf(name, "%s Playback Switch", chname[i]);
842 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
843 - HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
844 + HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
848 @@ -1265,7 +1775,7 @@
849 static char *labels[] = {
850 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
852 - struct hda_input_mux *imux = &spec->private_imux;
853 + struct hda_input_mux *imux = &spec->private_imux[0];
856 /* for internal loopback recording select */
857 @@ -1339,7 +1849,10 @@
858 if (spec->kctl_alloc)
859 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
861 - spec->input_mux = &spec->private_imux;
862 + spec->input_mux = &spec->private_imux[0];
865 + spec->mixers[spec->num_mixers++] = via_hp_mixer;
869 @@ -1360,7 +1873,7 @@
872 /* create a codec specific record */
873 - spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
874 + spec = kzalloc(sizeof(*spec), GFP_KERNEL);
878 @@ -1375,7 +1888,8 @@
879 "Using genenic mode...\n");
882 - spec->init_verbs = vt1709_10ch_volume_init_verbs;
883 + spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
884 + spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
886 spec->stream_name_analog = "VT1709 Analog";
887 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
888 @@ -1396,6 +1910,7 @@
889 codec->patch_ops = via_patch_ops;
891 codec->patch_ops.init = via_auto_init;
892 + codec->patch_ops.unsol_event = via_unsol_event;
893 #ifdef CONFIG_SND_HDA_POWER_SAVE
894 spec->loopback.amplist = vt1709_loopbacks;
896 @@ -1451,7 +1966,7 @@
899 /* create a codec specific record */
900 - spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
901 + spec = kzalloc(sizeof(*spec), GFP_KERNEL);
905 @@ -1466,7 +1981,8 @@
906 "Using genenic mode...\n");
909 - spec->init_verbs = vt1709_6ch_volume_init_verbs;
910 + spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
911 + spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
913 spec->stream_name_analog = "VT1709 Analog";
914 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
915 @@ -1487,6 +2003,7 @@
916 codec->patch_ops = via_patch_ops;
918 codec->patch_ops.init = via_auto_init;
919 + codec->patch_ops.unsol_event = via_unsol_event;
920 #ifdef CONFIG_SND_HDA_POWER_SAVE
921 spec->loopback.amplist = vt1709_loopbacks;
923 @@ -1586,27 +2103,32 @@
927 +static struct hda_verb vt1708B_uniwill_init_verbs[] = {
928 + {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
932 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
937 .nid = 0x10, /* NID to query formats and rates */
939 .open = via_playback_pcm_open,
940 - .prepare = via_playback_pcm_prepare,
941 - .cleanup = via_playback_pcm_cleanup
942 + .prepare = via_playback_multi_pcm_prepare,
943 + .cleanup = via_playback_multi_pcm_cleanup
947 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
952 .nid = 0x10, /* NID to query formats and rates */
954 .open = via_playback_pcm_open,
955 - .prepare = via_playback_pcm_prepare,
956 - .cleanup = via_playback_pcm_cleanup
957 + .prepare = via_playback_multi_pcm_prepare,
958 + .cleanup = via_playback_multi_pcm_cleanup
962 @@ -1662,10 +2184,10 @@
963 spec->multiout.dac_nids[i] = 0x24;
965 case AUTO_SEQ_SURROUND:
966 - spec->multiout.dac_nids[i] = 0x25;
967 + spec->multiout.dac_nids[i] = 0x11;
970 - spec->multiout.dac_nids[i] = 0x11;
971 + spec->multiout.dac_nids[i] = 0x25;
975 @@ -1680,7 +2202,7 @@
978 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
979 - hda_nid_t nid_vols[] = {0x16, 0x27, 0x26, 0x18};
980 + hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
981 hda_nid_t nid, nid_vol = 0;
984 @@ -1785,6 +2307,8 @@
988 + create_hp_imux(spec);
993 @@ -1795,7 +2319,7 @@
994 static char *labels[] = {
995 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
997 - struct hda_input_mux *imux = &spec->private_imux;
998 + struct hda_input_mux *imux = &spec->private_imux[0];
1001 /* for internal loopback recording select */
1002 @@ -1869,7 +2393,10 @@
1003 if (spec->kctl_alloc)
1004 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1006 - spec->input_mux = &spec->private_imux;
1007 + spec->input_mux = &spec->private_imux[0];
1010 + spec->mixers[spec->num_mixers++] = via_hp_mixer;
1014 @@ -1890,7 +2417,7 @@
1017 /* create a codec specific record */
1018 - spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1019 + spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1023 @@ -1906,7 +2433,8 @@
1024 "from BIOS. Using genenic mode...\n");
1027 - spec->init_verbs = vt1708B_8ch_volume_init_verbs;
1028 + spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
1029 + spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
1031 spec->stream_name_analog = "VT1708B Analog";
1032 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
1033 @@ -1926,6 +2454,7 @@
1034 codec->patch_ops = via_patch_ops;
1036 codec->patch_ops.init = via_auto_init;
1037 + codec->patch_ops.unsol_event = via_unsol_event;
1038 #ifdef CONFIG_SND_HDA_POWER_SAVE
1039 spec->loopback.amplist = vt1708B_loopbacks;
1041 @@ -1939,7 +2468,7 @@
1044 /* create a codec specific record */
1045 - spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1046 + spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1050 @@ -1955,7 +2484,8 @@
1051 "from BIOS. Using genenic mode...\n");
1054 - spec->init_verbs = vt1708B_4ch_volume_init_verbs;
1055 + spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
1056 + spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
1058 spec->stream_name_analog = "VT1708B Analog";
1059 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
1060 @@ -1975,6 +2505,7 @@
1061 codec->patch_ops = via_patch_ops;
1063 codec->patch_ops.init = via_auto_init;
1064 + codec->patch_ops.unsol_event = via_unsol_event;
1065 #ifdef CONFIG_SND_HDA_POWER_SAVE
1066 spec->loopback.amplist = vt1708B_loopbacks;
1068 @@ -1982,6 +2513,752 @@
1072 +/* Patch for VT1708S */
1074 +/* VT1708S software backdoor based override for buggy hardware micboost
1076 +#define MIC_BOOST_VOLUME(xname, nid) { \
1077 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1080 + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1081 + SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1082 + SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1083 + .info = mic_boost_volume_info, \
1084 + .get = snd_hda_mixer_amp_volume_get, \
1085 + .put = snd_hda_mixer_amp_volume_put, \
1086 + .tlv = { .c = mic_boost_tlv }, \
1087 + .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
1089 +/* capture mixer elements */
1090 +static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
1091 + HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
1092 + HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
1093 + HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
1094 + HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
1095 + MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
1096 + MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
1098 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1099 + /* The multiple "Capture Source" controls confuse alsamixer
1100 + * So call somewhat different..
1102 + /* .name = "Capture Source", */
1103 + .name = "Input Source",
1105 + .info = via_mux_enum_info,
1106 + .get = via_mux_enum_get,
1107 + .put = via_mux_enum_put,
1112 +static struct hda_verb vt1708S_volume_init_verbs[] = {
1113 + /* Unmute ADC0-1 and set the default input to mic-in */
1114 + {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1115 + {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1117 + /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
1118 + * analog-loopback mixer widget */
1119 + /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1120 + {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1121 + {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1122 + {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1123 + {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1124 + {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1126 + /* Setup default input of PW4 to MW0 */
1127 + {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
1128 + /* PW9, PW10 Output enable */
1129 + {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1130 + {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1131 + /* Enable Mic Boost Volume backdoor */
1132 + {0x1, 0xf98, 0x1},
1136 +static struct hda_verb vt1708S_uniwill_init_verbs[] = {
1137 + {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1141 +static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
1143 + .channels_min = 2,
1144 + .channels_max = 8,
1145 + .nid = 0x10, /* NID to query formats and rates */
1147 + .open = via_playback_pcm_open,
1148 + .prepare = via_playback_pcm_prepare,
1149 + .cleanup = via_playback_pcm_cleanup
1153 +static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
1155 + .channels_min = 2,
1156 + .channels_max = 2,
1157 + .nid = 0x13, /* NID to query formats and rates */
1159 + .prepare = via_capture_pcm_prepare,
1160 + .cleanup = via_capture_pcm_cleanup
1164 +static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
1166 + .channels_min = 2,
1167 + .channels_max = 2,
1168 + /* NID is set in via_build_pcms */
1170 + .open = via_dig_playback_pcm_open,
1171 + .close = via_dig_playback_pcm_close,
1172 + .prepare = via_dig_playback_pcm_prepare
1176 +/* fill in the dac_nids table from the parsed pin configuration */
1177 +static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
1178 + const struct auto_pin_cfg *cfg)
1183 + spec->multiout.num_dacs = cfg->line_outs;
1185 + spec->multiout.dac_nids = spec->private_dac_nids;
1187 + for (i = 0; i < 4; i++) {
1188 + nid = cfg->line_out_pins[i];
1190 + /* config dac list */
1192 + case AUTO_SEQ_FRONT:
1193 + spec->multiout.dac_nids[i] = 0x10;
1195 + case AUTO_SEQ_CENLFE:
1196 + spec->multiout.dac_nids[i] = 0x24;
1198 + case AUTO_SEQ_SURROUND:
1199 + spec->multiout.dac_nids[i] = 0x11;
1201 + case AUTO_SEQ_SIDE:
1202 + spec->multiout.dac_nids[i] = 0x25;
1211 +/* add playback controls from the parsed DAC table */
1212 +static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
1213 + const struct auto_pin_cfg *cfg)
1216 + static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1217 + hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
1218 + hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
1219 + hda_nid_t nid, nid_vol, nid_mute;
1222 + for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1223 + nid = cfg->line_out_pins[i];
1228 + nid_vol = nid_vols[i];
1229 + nid_mute = nid_mutes[i];
1231 + if (i == AUTO_SEQ_CENLFE) {
1233 + err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1234 + "Center Playback Volume",
1235 + HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1239 + err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1240 + "LFE Playback Volume",
1241 + HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1245 + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1246 + "Center Playback Switch",
1247 + HDA_COMPOSE_AMP_VAL(nid_mute,
1252 + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1253 + "LFE Playback Switch",
1254 + HDA_COMPOSE_AMP_VAL(nid_mute,
1259 + } else if (i == AUTO_SEQ_FRONT) {
1260 + /* add control to mixer index 0 */
1261 + err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1262 + "Master Front Playback Volume",
1263 + HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
1267 + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1268 + "Master Front Playback Switch",
1269 + HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
1275 + sprintf(name, "%s Playback Volume", chname[i]);
1276 + err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1277 + HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1281 + sprintf(name, "%s Playback Switch", chname[i]);
1282 + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1283 + HDA_COMPOSE_AMP_VAL(nid_mute,
1289 + sprintf(name, "%s Playback Volume", chname[i]);
1290 + err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1291 + HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1295 + sprintf(name, "%s Playback Switch", chname[i]);
1296 + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1297 + HDA_COMPOSE_AMP_VAL(nid_mute,
1308 +static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1315 + spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
1317 + err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1318 + "Headphone Playback Volume",
1319 + HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
1323 + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1324 + "Headphone Playback Switch",
1325 + HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1329 + create_hp_imux(spec);
1334 +/* create playback/capture controls for input pins */
1335 +static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
1336 + const struct auto_pin_cfg *cfg)
1338 + static char *labels[] = {
1339 + "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1341 + struct hda_input_mux *imux = &spec->private_imux[0];
1342 + int i, err, idx = 0;
1344 + /* for internal loopback recording select */
1345 + imux->items[imux->num_items].label = "Stereo Mixer";
1346 + imux->items[imux->num_items].index = 5;
1347 + imux->num_items++;
1349 + for (i = 0; i < AUTO_PIN_LAST; i++) {
1350 + if (!cfg->input_pins[i])
1353 + switch (cfg->input_pins[i]) {
1354 + case 0x1a: /* Mic */
1358 + case 0x1b: /* Line In */
1362 + case 0x1e: /* Front Mic */
1366 + case 0x1f: /* CD */
1370 + err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1374 + imux->items[imux->num_items].label = labels[i];
1375 + imux->items[imux->num_items].index = idx-1;
1376 + imux->num_items++;
1381 +static int vt1708S_parse_auto_config(struct hda_codec *codec)
1383 + struct via_spec *spec = codec->spec;
1385 + static hda_nid_t vt1708s_ignore[] = {0x21, 0};
1387 + err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
1391 + err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
1394 + if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1395 + return 0; /* can't find valid BIOS pin config */
1397 + err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
1400 + err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1403 + err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
1407 + spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1409 + if (spec->autocfg.dig_out_pin)
1410 + spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID;
1412 + spec->extra_dig_out_nid = 0x15;
1414 + if (spec->kctl_alloc)
1415 + spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1417 + spec->input_mux = &spec->private_imux[0];
1420 + spec->mixers[spec->num_mixers++] = via_hp_mixer;
1425 +#ifdef CONFIG_SND_HDA_POWER_SAVE
1426 +static struct hda_amp_list vt1708S_loopbacks[] = {
1427 + { 0x16, HDA_INPUT, 1 },
1428 + { 0x16, HDA_INPUT, 2 },
1429 + { 0x16, HDA_INPUT, 3 },
1430 + { 0x16, HDA_INPUT, 4 },
1435 +static int patch_vt1708S(struct hda_codec *codec)
1437 + struct via_spec *spec;
1440 + /* create a codec specific record */
1441 + spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1445 + codec->spec = spec;
1447 + /* automatic parse from the BIOS config */
1448 + err = vt1708S_parse_auto_config(codec);
1452 + } else if (!err) {
1453 + printk(KERN_INFO "hda_codec: Cannot set up configuration "
1454 + "from BIOS. Using genenic mode...\n");
1457 + spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
1458 + spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
1460 + spec->stream_name_analog = "VT1708S Analog";
1461 + spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
1462 + spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
1464 + spec->stream_name_digital = "VT1708S Digital";
1465 + spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
1467 + if (!spec->adc_nids && spec->input_mux) {
1468 + spec->adc_nids = vt1708S_adc_nids;
1469 + spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
1470 + spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
1471 + spec->num_mixers++;
1474 + codec->patch_ops = via_patch_ops;
1476 + codec->patch_ops.init = via_auto_init;
1477 + codec->patch_ops.unsol_event = via_unsol_event;
1478 +#ifdef CONFIG_SND_HDA_POWER_SAVE
1479 + spec->loopback.amplist = vt1708S_loopbacks;
1485 +/* Patch for VT1702 */
1487 +/* capture mixer elements */
1488 +static struct snd_kcontrol_new vt1702_capture_mixer[] = {
1489 + HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
1490 + HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
1491 + HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
1492 + HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
1493 + HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
1494 + HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
1495 + HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
1498 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1499 + /* The multiple "Capture Source" controls confuse alsamixer
1500 + * So call somewhat different..
1502 + /* .name = "Capture Source", */
1503 + .name = "Input Source",
1505 + .info = via_mux_enum_info,
1506 + .get = via_mux_enum_get,
1507 + .put = via_mux_enum_put,
1512 +static struct hda_verb vt1702_volume_init_verbs[] = {
1514 + * Unmute ADC0-1 and set the default input to mic-in
1516 + {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1517 + {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1518 + {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1521 + /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1524 + /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
1525 + {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1526 + {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1527 + {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1528 + {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1529 + {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1531 + /* Setup default input of PW4 to MW0 */
1532 + {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
1533 + /* PW6 PW7 Output enable */
1534 + {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1535 + {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1539 +static struct hda_verb vt1702_uniwill_init_verbs[] = {
1540 + {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
1541 + {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1545 +static struct hda_pcm_stream vt1702_pcm_analog_playback = {
1547 + .channels_min = 2,
1548 + .channels_max = 2,
1549 + .nid = 0x10, /* NID to query formats and rates */
1551 + .open = via_playback_pcm_open,
1552 + .prepare = via_playback_multi_pcm_prepare,
1553 + .cleanup = via_playback_multi_pcm_cleanup
1557 +static struct hda_pcm_stream vt1702_pcm_analog_capture = {
1559 + .channels_min = 2,
1560 + .channels_max = 2,
1561 + .nid = 0x12, /* NID to query formats and rates */
1563 + .prepare = via_capture_pcm_prepare,
1564 + .cleanup = via_capture_pcm_cleanup
1568 +static struct hda_pcm_stream vt1702_pcm_digital_playback = {
1570 + .channels_min = 2,
1571 + .channels_max = 2,
1572 + /* NID is set in via_build_pcms */
1574 + .open = via_dig_playback_pcm_open,
1575 + .close = via_dig_playback_pcm_close,
1576 + .prepare = via_dig_playback_pcm_prepare
1580 +/* fill in the dac_nids table from the parsed pin configuration */
1581 +static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
1582 + const struct auto_pin_cfg *cfg)
1584 + spec->multiout.num_dacs = 1;
1585 + spec->multiout.dac_nids = spec->private_dac_nids;
1587 + if (cfg->line_out_pins[0]) {
1588 + /* config dac list */
1589 + spec->multiout.dac_nids[0] = 0x10;
1595 +/* add playback controls from the parsed DAC table */
1596 +static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
1597 + const struct auto_pin_cfg *cfg)
1601 + if (!cfg->line_out_pins[0])
1604 + /* add control to mixer index 0 */
1605 + err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1606 + "Master Front Playback Volume",
1607 + HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
1610 + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1611 + "Master Front Playback Switch",
1612 + HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
1617 + err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1618 + "Front Playback Volume",
1619 + HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
1622 + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1623 + "Front Playback Switch",
1624 + HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
1631 +static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1638 + spec->multiout.hp_nid = 0x1D;
1640 + err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1641 + "Headphone Playback Volume",
1642 + HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
1646 + err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1647 + "Headphone Playback Switch",
1648 + HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1652 + create_hp_imux(spec);
1657 +/* create playback/capture controls for input pins */
1658 +static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
1659 + const struct auto_pin_cfg *cfg)
1661 + static char *labels[] = {
1662 + "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1664 + struct hda_input_mux *imux = &spec->private_imux[0];
1665 + int i, err, idx = 0;
1667 + /* for internal loopback recording select */
1668 + imux->items[imux->num_items].label = "Stereo Mixer";
1669 + imux->items[imux->num_items].index = 3;
1670 + imux->num_items++;
1672 + for (i = 0; i < AUTO_PIN_LAST; i++) {
1673 + if (!cfg->input_pins[i])
1676 + switch (cfg->input_pins[i]) {
1677 + case 0x14: /* Mic */
1681 + case 0x15: /* Line In */
1685 + case 0x18: /* Front Mic */
1689 + err = via_new_analog_input(spec, cfg->input_pins[i],
1690 + labels[i], idx, 0x1A);
1693 + imux->items[imux->num_items].label = labels[i];
1694 + imux->items[imux->num_items].index = idx-1;
1695 + imux->num_items++;
1700 +static int vt1702_parse_auto_config(struct hda_codec *codec)
1702 + struct via_spec *spec = codec->spec;
1704 + static hda_nid_t vt1702_ignore[] = {0x1C, 0};
1706 + err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
1710 + err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
1713 + if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1714 + return 0; /* can't find valid BIOS pin config */
1716 + err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
1719 + err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1722 + err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
1726 + spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1728 + if (spec->autocfg.dig_out_pin)
1729 + spec->multiout.dig_out_nid = VT1702_DIGOUT_NID;
1731 + spec->extra_dig_out_nid = 0x1B;
1733 + if (spec->kctl_alloc)
1734 + spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1736 + spec->input_mux = &spec->private_imux[0];
1739 + spec->mixers[spec->num_mixers++] = via_hp_mixer;
1744 +#ifdef CONFIG_SND_HDA_POWER_SAVE
1745 +static struct hda_amp_list vt1702_loopbacks[] = {
1746 + { 0x1A, HDA_INPUT, 1 },
1747 + { 0x1A, HDA_INPUT, 2 },
1748 + { 0x1A, HDA_INPUT, 3 },
1749 + { 0x1A, HDA_INPUT, 4 },
1754 +static int patch_vt1702(struct hda_codec *codec)
1756 + struct via_spec *spec;
1758 + unsigned int response;
1759 + unsigned char control;
1761 + /* create a codec specific record */
1762 + spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1766 + codec->spec = spec;
1768 + /* automatic parse from the BIOS config */
1769 + err = vt1702_parse_auto_config(codec);
1773 + } else if (!err) {
1774 + printk(KERN_INFO "hda_codec: Cannot set up configuration "
1775 + "from BIOS. Using genenic mode...\n");
1778 + spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
1779 + spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
1781 + spec->stream_name_analog = "VT1702 Analog";
1782 + spec->stream_analog_playback = &vt1702_pcm_analog_playback;
1783 + spec->stream_analog_capture = &vt1702_pcm_analog_capture;
1785 + spec->stream_name_digital = "VT1702 Digital";
1786 + spec->stream_digital_playback = &vt1702_pcm_digital_playback;
1788 + if (!spec->adc_nids && spec->input_mux) {
1789 + spec->adc_nids = vt1702_adc_nids;
1790 + spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
1791 + spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
1792 + spec->num_mixers++;
1795 + codec->patch_ops = via_patch_ops;
1797 + codec->patch_ops.init = via_auto_init;
1798 + codec->patch_ops.unsol_event = via_unsol_event;
1799 +#ifdef CONFIG_SND_HDA_POWER_SAVE
1800 + spec->loopback.amplist = vt1702_loopbacks;
1803 + /* Open backdoor */
1804 + response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
1805 + control = (unsigned char)(response & 0xff);
1807 + snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
1809 + /* Enable GPIO 0&1 for volume&mute control */
1810 + /* Enable GPIO 2 for DMIC-DATA */
1811 + response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
1812 + control = (unsigned char)((response >> 16) & 0x3f);
1813 + snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
1821 @@ -2022,5 +3299,37 @@
1822 .patch = patch_vt1708B_4ch},
1823 { .id = 0x1106E727, .name = "VIA VT1708B 4-Ch",
1824 .patch = patch_vt1708B_4ch},
1825 + { .id = 0x11060397, .name = "VIA VT1708S",
1826 + .patch = patch_vt1708S},
1827 + { .id = 0x11061397, .name = "VIA VT1708S",
1828 + .patch = patch_vt1708S},
1829 + { .id = 0x11062397, .name = "VIA VT1708S",
1830 + .patch = patch_vt1708S},
1831 + { .id = 0x11063397, .name = "VIA VT1708S",
1832 + .patch = patch_vt1708S},
1833 + { .id = 0x11064397, .name = "VIA VT1708S",
1834 + .patch = patch_vt1708S},
1835 + { .id = 0x11065397, .name = "VIA VT1708S",
1836 + .patch = patch_vt1708S},
1837 + { .id = 0x11066397, .name = "VIA VT1708S",
1838 + .patch = patch_vt1708S},
1839 + { .id = 0x11067397, .name = "VIA VT1708S",
1840 + .patch = patch_vt1708S},
1841 + { .id = 0x11060398, .name = "VIA VT1702",
1842 + .patch = patch_vt1702},
1843 + { .id = 0x11061398, .name = "VIA VT1702",
1844 + .patch = patch_vt1702},
1845 + { .id = 0x11062398, .name = "VIA VT1702",
1846 + .patch = patch_vt1702},
1847 + { .id = 0x11063398, .name = "VIA VT1702",
1848 + .patch = patch_vt1702},
1849 + { .id = 0x11064398, .name = "VIA VT1702",
1850 + .patch = patch_vt1702},
1851 + { .id = 0x11065398, .name = "VIA VT1702",
1852 + .patch = patch_vt1702},
1853 + { .id = 0x11066398, .name = "VIA VT1702",
1854 + .patch = patch_vt1702},
1855 + { .id = 0x11067398, .name = "VIA VT1702",
1856 + .patch = patch_vt1702},