2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT1708 codec
6 * Copyright (c) 2006 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 */
33 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
36 #include <sound/driver.h>
37 #include <linux/init.h>
38 #include <linux/delay.h>
39 #include <linux/slab.h>
40 #include <sound/core.h>
41 #include "hda_codec.h"
42 #include "hda_local.h"
46 #define AMP_VAL_IDX_SHIFT 19
47 #define AMP_VAL_IDX_MASK (0x0f<<19)
49 #define NUM_CONTROL_ALLOC 32
50 #define NUM_VERB_ALLOC 32
53 #define VT1708_HP_NID 0x13
54 #define VT1708_DIGOUT_NID 0x14
55 #define VT1708_DIGIN_NID 0x16
56 #define VT1708_DIGIN_PIN 0x26
58 #define VT1709_HP_DAC_NID 0x28
59 #define VT1709_DIGOUT_NID 0x13
60 #define VT1709_DIGIN_NID 0x17
61 #define VT1709_DIGIN_PIN 0x25
63 #define VT1708B_HP_NID 0x25
64 #define VT1708B_DIGOUT_NID 0x12
65 #define VT1708B_DIGIN_NID 0x15
66 #define VT1708B_DIGIN_PIN 0x21
68 #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
69 #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
70 #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
71 #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
72 #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
87 static struct snd_kcontrol_new vt1708_control_templates[] = {
88 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
89 HDA_CODEC_MUTE(NULL, 0, 0, 0),
94 /* codec parameterization */
95 struct snd_kcontrol_new *mixers[3];
96 unsigned int num_mixers;
98 struct hda_verb *init_verbs;
100 char *stream_name_analog;
101 struct hda_pcm_stream *stream_analog_playback;
102 struct hda_pcm_stream *stream_analog_capture;
104 char *stream_name_digital;
105 struct hda_pcm_stream *stream_digital_playback;
106 struct hda_pcm_stream *stream_digital_capture;
109 struct hda_multi_out multiout;
112 unsigned int num_adc_nids;
114 hda_nid_t dig_in_nid;
117 const struct hda_input_mux *input_mux;
118 unsigned int cur_mux[3];
120 /* PCM information */
121 struct hda_pcm pcm_rec[2];
123 /* dynamic controls, init_verbs and input_mux */
124 struct auto_pin_cfg autocfg;
125 unsigned int num_kctl_alloc, num_kctl_used;
126 struct snd_kcontrol_new *kctl_alloc;
127 struct hda_input_mux private_imux;
128 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
130 #ifdef CONFIG_SND_HDA_POWER_SAVE
131 struct hda_loopback_check loopback;
135 static hda_nid_t vt1708_adc_nids[2] = {
140 static hda_nid_t vt1709_adc_nids[3] = {
145 static hda_nid_t vt1708B_adc_nids[2] = {
150 /* add dynamic controls */
151 static int via_add_control(struct via_spec *spec, int type, const char *name,
154 struct snd_kcontrol_new *knew;
156 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
157 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
159 /* array + terminator */
160 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
163 if (spec->kctl_alloc) {
164 memcpy(knew, spec->kctl_alloc,
165 sizeof(*knew) * spec->num_kctl_alloc);
166 kfree(spec->kctl_alloc);
168 spec->kctl_alloc = knew;
169 spec->num_kctl_alloc = num;
172 knew = &spec->kctl_alloc[spec->num_kctl_used];
173 *knew = vt1708_control_templates[type];
174 knew->name = kstrdup(name, GFP_KERNEL);
178 knew->private_value = val;
179 spec->num_kctl_used++;
183 /* create input playback/capture controls for the given pin */
184 static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
185 const char *ctlname, int idx, int mix_nid)
190 sprintf(name, "%s Playback Volume", ctlname);
191 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
192 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
195 sprintf(name, "%s Playback Switch", ctlname);
196 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
197 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
203 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
204 hda_nid_t nid, int pin_type,
208 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
210 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
215 static void via_auto_init_multi_out(struct hda_codec *codec)
217 struct via_spec *spec = codec->spec;
220 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
221 hda_nid_t nid = spec->autocfg.line_out_pins[i];
223 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
227 static void via_auto_init_hp_out(struct hda_codec *codec)
229 struct via_spec *spec = codec->spec;
232 pin = spec->autocfg.hp_pins[0];
233 if (pin) /* connect to front */
234 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
237 static void via_auto_init_analog_input(struct hda_codec *codec)
239 struct via_spec *spec = codec->spec;
242 for (i = 0; i < AUTO_PIN_LAST; i++) {
243 hda_nid_t nid = spec->autocfg.input_pins[i];
245 snd_hda_codec_write(codec, nid, 0,
246 AC_VERB_SET_PIN_WIDGET_CONTROL,
247 (i <= AUTO_PIN_FRONT_MIC ?
248 PIN_VREF50 : PIN_IN));
255 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_info *uinfo)
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct via_spec *spec = codec->spec;
260 return snd_hda_input_mux_info(spec->input_mux, uinfo);
263 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
264 struct snd_ctl_elem_value *ucontrol)
266 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
267 struct via_spec *spec = codec->spec;
268 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
270 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
274 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
275 struct snd_ctl_elem_value *ucontrol)
277 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
278 struct via_spec *spec = codec->spec;
279 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
280 unsigned int vendor_id = codec->vendor_id;
282 /* AIW0 lydia 060801 add for correct sw0 input select */
283 if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
284 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
285 0x18, &spec->cur_mux[adc_idx]);
286 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
287 IS_VT1709_6CH_VENDORID(vendor_id)) && adc_idx == 0)
288 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
289 0x19, &spec->cur_mux[adc_idx]);
290 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
291 IS_VT1708B_4CH_VENDORID(vendor_id)) && adc_idx == 0)
292 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
293 0x17, &spec->cur_mux[adc_idx]);
295 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
296 spec->adc_nids[adc_idx],
297 &spec->cur_mux[adc_idx]);
300 /* capture mixer elements */
301 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
302 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
303 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
304 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
305 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
307 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
308 /* The multiple "Capture Source" controls confuse alsamixer
309 * So call somewhat different..
310 * FIXME: the controls appear in the "playback" view!
312 /* .name = "Capture Source", */
313 .name = "Input Source",
315 .info = via_mux_enum_info,
316 .get = via_mux_enum_get,
317 .put = via_mux_enum_put,
322 * generic initialization of ADC, input mixers and output mixers
324 static struct hda_verb vt1708_volume_init_verbs[] = {
326 * Unmute ADC0-1 and set the default input to mic-in
328 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
329 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
332 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
335 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
336 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
337 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
338 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
339 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
340 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
343 * Set up output mixers (0x19 - 0x1b)
345 /* set vol=0 to output mixers */
346 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
347 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
348 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
350 /* Setup default input to PW4 */
351 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
352 /* PW9 Output enable */
353 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
357 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
358 struct hda_codec *codec,
359 struct snd_pcm_substream *substream)
361 struct via_spec *spec = codec->spec;
362 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
365 static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
366 struct hda_codec *codec,
367 unsigned int stream_tag,
369 struct snd_pcm_substream *substream)
371 struct via_spec *spec = codec->spec;
372 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
373 stream_tag, format, substream);
376 static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
377 struct hda_codec *codec,
378 struct snd_pcm_substream *substream)
380 struct via_spec *spec = codec->spec;
381 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
387 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
388 struct hda_codec *codec,
389 struct snd_pcm_substream *substream)
391 struct via_spec *spec = codec->spec;
392 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
395 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
396 struct hda_codec *codec,
397 struct snd_pcm_substream *substream)
399 struct via_spec *spec = codec->spec;
400 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
403 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
404 struct hda_codec *codec,
405 unsigned int stream_tag,
407 struct snd_pcm_substream *substream)
409 struct via_spec *spec = codec->spec;
410 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
411 stream_tag, format, substream);
417 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
418 struct hda_codec *codec,
419 unsigned int stream_tag,
421 struct snd_pcm_substream *substream)
423 struct via_spec *spec = codec->spec;
425 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
426 stream_tag, 0, format);
430 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
431 struct hda_codec *codec,
432 struct snd_pcm_substream *substream)
434 struct via_spec *spec = codec->spec;
435 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
440 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
444 .nid = 0x10, /* NID to query formats and rates */
446 .open = via_playback_pcm_open,
447 .prepare = via_playback_pcm_prepare,
448 .cleanup = via_playback_pcm_cleanup
452 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
456 .nid = 0x15, /* NID to query formats and rates */
458 .prepare = via_capture_pcm_prepare,
459 .cleanup = via_capture_pcm_cleanup
463 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
467 /* NID is set in via_build_pcms */
469 .open = via_dig_playback_pcm_open,
470 .close = via_dig_playback_pcm_close,
471 .prepare = via_dig_playback_pcm_prepare
475 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
481 static int via_build_controls(struct hda_codec *codec)
483 struct via_spec *spec = codec->spec;
487 for (i = 0; i < spec->num_mixers; i++) {
488 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
493 if (spec->multiout.dig_out_nid) {
494 err = snd_hda_create_spdif_out_ctls(codec,
495 spec->multiout.dig_out_nid);
499 if (spec->dig_in_nid) {
500 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
507 static int via_build_pcms(struct hda_codec *codec)
509 struct via_spec *spec = codec->spec;
510 struct hda_pcm *info = spec->pcm_rec;
513 codec->pcm_info = info;
515 info->name = spec->stream_name_analog;
516 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
517 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
518 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
519 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
521 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
522 spec->multiout.max_channels;
524 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
527 info->name = spec->stream_name_digital;
528 if (spec->multiout.dig_out_nid) {
529 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
530 *(spec->stream_digital_playback);
531 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
532 spec->multiout.dig_out_nid;
534 if (spec->dig_in_nid) {
535 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
536 *(spec->stream_digital_capture);
537 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
545 static void via_free(struct hda_codec *codec)
547 struct via_spec *spec = codec->spec;
553 if (spec->kctl_alloc) {
554 for (i = 0; i < spec->num_kctl_used; i++)
555 kfree(spec->kctl_alloc[i].name);
556 kfree(spec->kctl_alloc);
562 static int via_init(struct hda_codec *codec)
564 struct via_spec *spec = codec->spec;
565 snd_hda_sequence_write(codec, spec->init_verbs);
566 /* Lydia Add for EAPD enable */
567 if (!spec->dig_in_nid) { /* No Digital In connection */
568 if (IS_VT1708_VENDORID(codec->vendor_id)) {
569 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
570 AC_VERB_SET_PIN_WIDGET_CONTROL,
572 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
573 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
574 } else if (IS_VT1709_10CH_VENDORID(codec->vendor_id) ||
575 IS_VT1709_6CH_VENDORID(codec->vendor_id)) {
576 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
577 AC_VERB_SET_PIN_WIDGET_CONTROL,
579 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
580 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
581 } else if (IS_VT1708B_8CH_VENDORID(codec->vendor_id) ||
582 IS_VT1708B_4CH_VENDORID(codec->vendor_id)) {
583 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
584 AC_VERB_SET_PIN_WIDGET_CONTROL,
586 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
587 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
594 #ifdef CONFIG_SND_HDA_POWER_SAVE
595 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
597 struct via_spec *spec = codec->spec;
598 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
604 static struct hda_codec_ops via_patch_ops = {
605 .build_controls = via_build_controls,
606 .build_pcms = via_build_pcms,
609 #ifdef CONFIG_SND_HDA_POWER_SAVE
610 .check_power_status = via_check_power_status,
614 /* fill in the dac_nids table from the parsed pin configuration */
615 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
616 const struct auto_pin_cfg *cfg)
621 spec->multiout.num_dacs = cfg->line_outs;
623 spec->multiout.dac_nids = spec->private_dac_nids;
625 for(i = 0; i < 4; i++) {
626 nid = cfg->line_out_pins[i];
628 /* config dac list */
631 spec->multiout.dac_nids[i] = 0x10;
633 case AUTO_SEQ_CENLFE:
634 spec->multiout.dac_nids[i] = 0x12;
636 case AUTO_SEQ_SURROUND:
637 spec->multiout.dac_nids[i] = 0x13;
640 spec->multiout.dac_nids[i] = 0x11;
649 /* add playback controls from the parsed DAC table */
650 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
651 const struct auto_pin_cfg *cfg)
654 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
655 hda_nid_t nid, nid_vol = 0;
658 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
659 nid = cfg->line_out_pins[i];
664 if (i != AUTO_SEQ_FRONT)
665 nid_vol = 0x1b - i + 1;
667 if (i == AUTO_SEQ_CENLFE) {
669 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
670 "Center Playback Volume",
671 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
675 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
676 "LFE Playback Volume",
677 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
681 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
682 "Center Playback Switch",
683 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
687 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
688 "LFE Playback Switch",
689 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
693 } else if (i == AUTO_SEQ_FRONT){
694 /* add control to mixer index 0 */
695 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
696 "Master Front Playback Volume",
697 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
701 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
702 "Master Front Playback Switch",
703 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
708 /* add control to PW3 */
709 sprintf(name, "%s Playback Volume", chname[i]);
710 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
711 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
715 sprintf(name, "%s Playback Switch", chname[i]);
716 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
717 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
722 sprintf(name, "%s Playback Volume", chname[i]);
723 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
724 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
728 sprintf(name, "%s Playback Switch", chname[i]);
729 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
730 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
740 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
747 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
749 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
750 "Headphone Playback Volume",
751 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
754 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
755 "Headphone Playback Switch",
756 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
763 /* create playback/capture controls for input pins */
764 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
765 const struct auto_pin_cfg *cfg)
767 static char *labels[] = {
768 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
770 struct hda_input_mux *imux = &spec->private_imux;
773 /* for internal loopback recording select */
774 imux->items[imux->num_items].label = "Stereo Mixer";
775 imux->items[imux->num_items].index = idx;
778 for (i = 0; i < AUTO_PIN_LAST; i++) {
779 if (!cfg->input_pins[i])
782 switch (cfg->input_pins[i]) {
787 case 0x1e: /* Line In */
791 case 0x21: /* Front Mic */
799 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
803 imux->items[imux->num_items].label = labels[i];
804 imux->items[imux->num_items].index = idx;
810 #ifdef CONFIG_SND_HDA_POWER_SAVE
811 static struct hda_amp_list vt1708_loopbacks[] = {
812 { 0x17, HDA_INPUT, 1 },
813 { 0x17, HDA_INPUT, 2 },
814 { 0x17, HDA_INPUT, 3 },
815 { 0x17, HDA_INPUT, 4 },
820 static int vt1708_parse_auto_config(struct hda_codec *codec)
822 struct via_spec *spec = codec->spec;
825 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
828 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
831 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
832 return 0; /* can't find valid BIOS pin config */
834 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
837 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
840 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
844 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
846 if (spec->autocfg.dig_out_pin)
847 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
848 if (spec->autocfg.dig_in_pin)
849 spec->dig_in_nid = VT1708_DIGIN_NID;
851 if (spec->kctl_alloc)
852 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
854 spec->init_verbs = vt1708_volume_init_verbs;
856 spec->input_mux = &spec->private_imux;
861 /* init callback for auto-configuration model -- overriding the default init */
862 static int via_auto_init(struct hda_codec *codec)
865 via_auto_init_multi_out(codec);
866 via_auto_init_hp_out(codec);
867 via_auto_init_analog_input(codec);
871 static int patch_vt1708(struct hda_codec *codec)
873 struct via_spec *spec;
876 /* create a codec specific record */
877 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
883 /* automatic parse from the BIOS config */
884 err = vt1708_parse_auto_config(codec);
889 printk(KERN_INFO "hda_codec: Cannot set up configuration "
890 "from BIOS. Using genenic mode...\n");
894 spec->stream_name_analog = "VT1708 Analog";
895 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
896 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
898 spec->stream_name_digital = "VT1708 Digital";
899 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
900 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
903 if (!spec->adc_nids && spec->input_mux) {
904 spec->adc_nids = vt1708_adc_nids;
905 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
906 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
910 codec->patch_ops = via_patch_ops;
912 codec->patch_ops.init = via_auto_init;
913 #ifdef CONFIG_SND_HDA_POWER_SAVE
914 spec->loopback.amplist = vt1708_loopbacks;
920 /* capture mixer elements */
921 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
922 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
923 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
924 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
925 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
926 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
927 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
929 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
930 /* The multiple "Capture Source" controls confuse alsamixer
931 * So call somewhat different..
932 * FIXME: the controls appear in the "playback" view!
934 /* .name = "Capture Source", */
935 .name = "Input Source",
937 .info = via_mux_enum_info,
938 .get = via_mux_enum_get,
939 .put = via_mux_enum_put,
945 * generic initialization of ADC, input mixers and output mixers
947 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
949 * Unmute ADC0-2 and set the default input to mic-in
951 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
952 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
953 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
956 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
959 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
960 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
961 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
962 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
963 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
964 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
967 * Set up output selector (0x1a, 0x1b, 0x29)
969 /* set vol=0 to output mixers */
970 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
971 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
972 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
977 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
978 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
980 /* Set input of PW4 as AOW4 */
981 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
982 /* PW9 Output enable */
983 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
987 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
991 .nid = 0x10, /* NID to query formats and rates */
993 .open = via_playback_pcm_open,
994 .prepare = via_playback_pcm_prepare,
995 .cleanup = via_playback_pcm_cleanup
999 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1003 .nid = 0x10, /* NID to query formats and rates */
1005 .open = via_playback_pcm_open,
1006 .prepare = via_playback_pcm_prepare,
1007 .cleanup = via_playback_pcm_cleanup
1011 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1015 .nid = 0x14, /* NID to query formats and rates */
1017 .prepare = via_capture_pcm_prepare,
1018 .cleanup = via_capture_pcm_cleanup
1022 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1026 /* NID is set in via_build_pcms */
1028 .open = via_dig_playback_pcm_open,
1029 .close = via_dig_playback_pcm_close
1033 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1039 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1040 const struct auto_pin_cfg *cfg)
1045 if (cfg->line_outs == 4) /* 10 channels */
1046 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1047 else if (cfg->line_outs == 3) /* 6 channels */
1048 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1050 spec->multiout.dac_nids = spec->private_dac_nids;
1052 if (cfg->line_outs == 4) { /* 10 channels */
1053 for (i = 0; i < cfg->line_outs; i++) {
1054 nid = cfg->line_out_pins[i];
1056 /* config dac list */
1058 case AUTO_SEQ_FRONT:
1060 spec->multiout.dac_nids[i] = 0x10;
1062 case AUTO_SEQ_CENLFE:
1064 spec->multiout.dac_nids[i] = 0x12;
1066 case AUTO_SEQ_SURROUND:
1068 spec->multiout.dac_nids[i] = 0x27;
1072 spec->multiout.dac_nids[i] = 0x11;
1079 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1081 } else if (cfg->line_outs == 3) { /* 6 channels */
1082 for(i = 0; i < cfg->line_outs; i++) {
1083 nid = cfg->line_out_pins[i];
1085 /* config dac list */
1087 case AUTO_SEQ_FRONT:
1089 spec->multiout.dac_nids[i] = 0x10;
1091 case AUTO_SEQ_CENLFE:
1093 spec->multiout.dac_nids[i] = 0x12;
1095 case AUTO_SEQ_SURROUND:
1097 spec->multiout.dac_nids[i] = 0x11;
1109 /* add playback controls from the parsed DAC table */
1110 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1111 const struct auto_pin_cfg *cfg)
1114 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1118 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1119 nid = cfg->line_out_pins[i];
1124 if (i == AUTO_SEQ_CENLFE) {
1126 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1127 "Center Playback Volume",
1128 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1132 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1133 "LFE Playback Volume",
1134 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1138 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1139 "Center Playback Switch",
1140 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1144 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1145 "LFE Playback Switch",
1146 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1150 } else if (i == AUTO_SEQ_FRONT){
1151 /* add control to mixer index 0 */
1152 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1153 "Master Front Playback Volume",
1154 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1158 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1159 "Master Front Playback Switch",
1160 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1165 /* add control to PW3 */
1166 sprintf(name, "%s Playback Volume", chname[i]);
1167 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1168 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1172 sprintf(name, "%s Playback Switch", chname[i]);
1173 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1174 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1178 } else if (i == AUTO_SEQ_SURROUND) {
1179 sprintf(name, "%s Playback Volume", chname[i]);
1180 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1181 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1185 sprintf(name, "%s Playback Switch", chname[i]);
1186 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1187 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1191 } else if (i == AUTO_SEQ_SIDE) {
1192 sprintf(name, "%s Playback Volume", chname[i]);
1193 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1194 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1198 sprintf(name, "%s Playback Switch", chname[i]);
1199 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1200 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1210 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1217 if (spec->multiout.num_dacs == 5) /* 10 channels */
1218 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1219 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1220 spec->multiout.hp_nid = 0;
1222 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1223 "Headphone Playback Volume",
1224 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1227 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1228 "Headphone Playback Switch",
1229 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1236 /* create playback/capture controls for input pins */
1237 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1238 const struct auto_pin_cfg *cfg)
1240 static char *labels[] = {
1241 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1243 struct hda_input_mux *imux = &spec->private_imux;
1244 int i, err, idx = 0;
1246 /* for internal loopback recording select */
1247 imux->items[imux->num_items].label = "Stereo Mixer";
1248 imux->items[imux->num_items].index = idx;
1251 for (i = 0; i < AUTO_PIN_LAST; i++) {
1252 if (!cfg->input_pins[i])
1255 switch (cfg->input_pins[i]) {
1256 case 0x1d: /* Mic */
1260 case 0x1e: /* Line In */
1264 case 0x21: /* Front Mic */
1272 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1276 imux->items[imux->num_items].label = labels[i];
1277 imux->items[imux->num_items].index = idx;
1283 static int vt1709_parse_auto_config(struct hda_codec *codec)
1285 struct via_spec *spec = codec->spec;
1288 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1291 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1294 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1295 return 0; /* can't find valid BIOS pin config */
1297 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1300 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1303 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1307 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1309 if (spec->autocfg.dig_out_pin)
1310 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1311 if (spec->autocfg.dig_in_pin)
1312 spec->dig_in_nid = VT1709_DIGIN_NID;
1314 if (spec->kctl_alloc)
1315 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1317 spec->input_mux = &spec->private_imux;
1322 #ifdef CONFIG_SND_HDA_POWER_SAVE
1323 static struct hda_amp_list vt1709_loopbacks[] = {
1324 { 0x18, HDA_INPUT, 1 },
1325 { 0x18, HDA_INPUT, 2 },
1326 { 0x18, HDA_INPUT, 3 },
1327 { 0x18, HDA_INPUT, 4 },
1332 static int patch_vt1709_10ch(struct hda_codec *codec)
1334 struct via_spec *spec;
1337 /* create a codec specific record */
1338 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1344 err = vt1709_parse_auto_config(codec);
1349 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1350 "Using genenic mode...\n");
1353 spec->init_verbs = vt1709_10ch_volume_init_verbs;
1355 spec->stream_name_analog = "VT1709 Analog";
1356 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1357 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1359 spec->stream_name_digital = "VT1709 Digital";
1360 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1361 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1364 if (!spec->adc_nids && spec->input_mux) {
1365 spec->adc_nids = vt1709_adc_nids;
1366 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1367 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1371 codec->patch_ops = via_patch_ops;
1373 codec->patch_ops.init = via_auto_init;
1374 #ifdef CONFIG_SND_HDA_POWER_SAVE
1375 spec->loopback.amplist = vt1709_loopbacks;
1381 * generic initialization of ADC, input mixers and output mixers
1383 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1385 * Unmute ADC0-2 and set the default input to mic-in
1387 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1388 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1389 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1392 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1395 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1396 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1397 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1398 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1399 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1400 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1403 * Set up output selector (0x1a, 0x1b, 0x29)
1405 /* set vol=0 to output mixers */
1406 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1407 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1408 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1411 * Unmute PW3 and PW4
1413 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1414 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1416 /* Set input of PW4 as MW0 */
1417 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1418 /* PW9 Output enable */
1419 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1423 static int patch_vt1709_6ch(struct hda_codec *codec)
1425 struct via_spec *spec;
1428 /* create a codec specific record */
1429 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1435 err = vt1709_parse_auto_config(codec);
1440 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1441 "Using genenic mode...\n");
1444 spec->init_verbs = vt1709_6ch_volume_init_verbs;
1446 spec->stream_name_analog = "VT1709 Analog";
1447 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1448 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1450 spec->stream_name_digital = "VT1709 Digital";
1451 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1452 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1455 if (!spec->adc_nids && spec->input_mux) {
1456 spec->adc_nids = vt1709_adc_nids;
1457 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1458 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1462 codec->patch_ops = via_patch_ops;
1464 codec->patch_ops.init = via_auto_init;
1465 #ifdef CONFIG_SND_HDA_POWER_SAVE
1466 spec->loopback.amplist = vt1709_loopbacks;
1471 /* capture mixer elements */
1472 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
1473 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
1474 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
1475 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
1476 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
1478 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1479 /* The multiple "Capture Source" controls confuse alsamixer
1480 * So call somewhat different..
1481 * FIXME: the controls appear in the "playback" view!
1483 /* .name = "Capture Source", */
1484 .name = "Input Source",
1486 .info = via_mux_enum_info,
1487 .get = via_mux_enum_get,
1488 .put = via_mux_enum_put,
1493 * generic initialization of ADC, input mixers and output mixers
1495 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
1497 * Unmute ADC0-1 and set the default input to mic-in
1499 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1500 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1503 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1506 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1507 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1508 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1509 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1510 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1511 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1514 * Set up output mixers
1516 /* set vol=0 to output mixers */
1517 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1518 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1519 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1521 /* Setup default input to PW4 */
1522 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
1523 /* PW9 Output enable */
1524 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1525 /* PW10 Input enable */
1526 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
1530 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
1532 * Unmute ADC0-1 and set the default input to mic-in
1534 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1535 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1538 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1541 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1542 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1543 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1544 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1545 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1546 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1549 * Set up output mixers
1551 /* set vol=0 to output mixers */
1552 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1553 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1554 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1556 /* Setup default input of PW4 to MW0 */
1557 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
1558 /* PW9 Output enable */
1559 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1560 /* PW10 Input enable */
1561 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
1565 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
1569 .nid = 0x10, /* NID to query formats and rates */
1571 .open = via_playback_pcm_open,
1572 .prepare = via_playback_pcm_prepare,
1573 .cleanup = via_playback_pcm_cleanup
1577 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
1581 .nid = 0x10, /* NID to query formats and rates */
1583 .open = via_playback_pcm_open,
1584 .prepare = via_playback_pcm_prepare,
1585 .cleanup = via_playback_pcm_cleanup
1589 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
1593 .nid = 0x13, /* NID to query formats and rates */
1595 .prepare = via_capture_pcm_prepare,
1596 .cleanup = via_capture_pcm_cleanup
1600 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
1604 /* NID is set in via_build_pcms */
1606 .open = via_dig_playback_pcm_open,
1607 .close = via_dig_playback_pcm_close,
1608 .prepare = via_dig_playback_pcm_prepare
1612 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
1618 /* fill in the dac_nids table from the parsed pin configuration */
1619 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
1620 const struct auto_pin_cfg *cfg)
1625 spec->multiout.num_dacs = cfg->line_outs;
1627 spec->multiout.dac_nids = spec->private_dac_nids;
1629 for (i = 0; i < 4; i++) {
1630 nid = cfg->line_out_pins[i];
1632 /* config dac list */
1634 case AUTO_SEQ_FRONT:
1635 spec->multiout.dac_nids[i] = 0x10;
1637 case AUTO_SEQ_CENLFE:
1638 spec->multiout.dac_nids[i] = 0x24;
1640 case AUTO_SEQ_SURROUND:
1641 spec->multiout.dac_nids[i] = 0x25;
1644 spec->multiout.dac_nids[i] = 0x11;
1653 /* add playback controls from the parsed DAC table */
1654 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
1655 const struct auto_pin_cfg *cfg)
1658 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1659 hda_nid_t nid_vols[] = {0x16, 0x27, 0x26, 0x18};
1660 hda_nid_t nid, nid_vol = 0;
1663 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1664 nid = cfg->line_out_pins[i];
1669 nid_vol = nid_vols[i];
1671 if (i == AUTO_SEQ_CENLFE) {
1673 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1674 "Center Playback Volume",
1675 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1679 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1680 "LFE Playback Volume",
1681 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1685 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1686 "Center Playback Switch",
1687 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1691 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1692 "LFE Playback Switch",
1693 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1697 } else if (i == AUTO_SEQ_FRONT) {
1698 /* add control to mixer index 0 */
1699 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1700 "Master Front Playback Volume",
1701 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1705 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1706 "Master Front Playback Switch",
1707 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1712 /* add control to PW3 */
1713 sprintf(name, "%s Playback Volume", chname[i]);
1714 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1715 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1719 sprintf(name, "%s Playback Switch", chname[i]);
1720 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1721 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1726 sprintf(name, "%s Playback Volume", chname[i]);
1727 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1728 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1732 sprintf(name, "%s Playback Switch", chname[i]);
1733 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1734 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1744 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1751 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
1753 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1754 "Headphone Playback Volume",
1755 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1758 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1759 "Headphone Playback Switch",
1760 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1767 /* create playback/capture controls for input pins */
1768 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
1769 const struct auto_pin_cfg *cfg)
1771 static char *labels[] = {
1772 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1774 struct hda_input_mux *imux = &spec->private_imux;
1775 int i, err, idx = 0;
1777 /* for internal loopback recording select */
1778 imux->items[imux->num_items].label = "Stereo Mixer";
1779 imux->items[imux->num_items].index = idx;
1782 for (i = 0; i < AUTO_PIN_LAST; i++) {
1783 if (!cfg->input_pins[i])
1786 switch (cfg->input_pins[i]) {
1787 case 0x1a: /* Mic */
1791 case 0x1b: /* Line In */
1795 case 0x1e: /* Front Mic */
1803 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1807 imux->items[imux->num_items].label = labels[i];
1808 imux->items[imux->num_items].index = idx;
1814 static int vt1708B_parse_auto_config(struct hda_codec *codec)
1816 struct via_spec *spec = codec->spec;
1819 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1822 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
1825 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1826 return 0; /* can't find valid BIOS pin config */
1828 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
1831 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1834 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
1838 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1840 if (spec->autocfg.dig_out_pin)
1841 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
1842 if (spec->autocfg.dig_in_pin)
1843 spec->dig_in_nid = VT1708B_DIGIN_NID;
1845 if (spec->kctl_alloc)
1846 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1848 spec->input_mux = &spec->private_imux;
1853 #ifdef CONFIG_SND_HDA_POWER_SAVE
1854 static struct hda_amp_list vt1708B_loopbacks[] = {
1855 { 0x16, HDA_INPUT, 1 },
1856 { 0x16, HDA_INPUT, 2 },
1857 { 0x16, HDA_INPUT, 3 },
1858 { 0x16, HDA_INPUT, 4 },
1863 static int patch_vt1708B_8ch(struct hda_codec *codec)
1865 struct via_spec *spec;
1868 /* create a codec specific record */
1869 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1875 /* automatic parse from the BIOS config */
1876 err = vt1708B_parse_auto_config(codec);
1881 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1882 "from BIOS. Using genenic mode...\n");
1885 spec->init_verbs = vt1708B_8ch_volume_init_verbs;
1887 spec->stream_name_analog = "VT1708B Analog";
1888 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
1889 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
1891 spec->stream_name_digital = "VT1708B Digital";
1892 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
1893 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
1895 if (!spec->adc_nids && spec->input_mux) {
1896 spec->adc_nids = vt1708B_adc_nids;
1897 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
1898 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
1902 codec->patch_ops = via_patch_ops;
1904 codec->patch_ops.init = via_auto_init;
1905 #ifdef CONFIG_SND_HDA_POWER_SAVE
1906 spec->loopback.amplist = vt1708B_loopbacks;
1912 static int patch_vt1708B_4ch(struct hda_codec *codec)
1914 struct via_spec *spec;
1917 /* create a codec specific record */
1918 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1924 /* automatic parse from the BIOS config */
1925 err = vt1708B_parse_auto_config(codec);
1930 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1931 "from BIOS. Using genenic mode...\n");
1934 spec->init_verbs = vt1708B_4ch_volume_init_verbs;
1936 spec->stream_name_analog = "VT1708B Analog";
1937 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
1938 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
1940 spec->stream_name_digital = "VT1708B Digital";
1941 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
1942 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
1944 if (!spec->adc_nids && spec->input_mux) {
1945 spec->adc_nids = vt1708B_adc_nids;
1946 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
1947 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
1951 codec->patch_ops = via_patch_ops;
1953 codec->patch_ops.init = via_auto_init;
1954 #ifdef CONFIG_SND_HDA_POWER_SAVE
1955 spec->loopback.amplist = vt1708B_loopbacks;
1964 struct hda_codec_preset snd_hda_preset_via[] = {
1965 { .id = 0x11061708, .name = "VIA VT1708", .patch = patch_vt1708},
1966 { .id = 0x11061709, .name = "VIA VT1708", .patch = patch_vt1708},
1967 { .id = 0x1106170A, .name = "VIA VT1708", .patch = patch_vt1708},
1968 { .id = 0x1106170B, .name = "VIA VT1708", .patch = patch_vt1708},
1969 { .id = 0x1106E710, .name = "VIA VT1709 10-Ch",
1970 .patch = patch_vt1709_10ch},
1971 { .id = 0x1106E711, .name = "VIA VT1709 10-Ch",
1972 .patch = patch_vt1709_10ch},
1973 { .id = 0x1106E712, .name = "VIA VT1709 10-Ch",
1974 .patch = patch_vt1709_10ch},
1975 { .id = 0x1106E713, .name = "VIA VT1709 10-Ch",
1976 .patch = patch_vt1709_10ch},
1977 { .id = 0x1106E714, .name = "VIA VT1709 6-Ch",
1978 .patch = patch_vt1709_6ch},
1979 { .id = 0x1106E715, .name = "VIA VT1709 6-Ch",
1980 .patch = patch_vt1709_6ch},
1981 { .id = 0x1106E716, .name = "VIA VT1709 6-Ch",
1982 .patch = patch_vt1709_6ch},
1983 { .id = 0x1106E717, .name = "VIA VT1709 6-Ch",
1984 .patch = patch_vt1709_6ch},
1985 { .id = 0x1106E720, .name = "VIA VT1708B 8-Ch",
1986 .patch = patch_vt1708B_8ch},
1987 { .id = 0x1106E721, .name = "VIA VT1708B 8-Ch",
1988 .patch = patch_vt1708B_8ch},
1989 { .id = 0x1106E722, .name = "VIA VT1708B 8-Ch",
1990 .patch = patch_vt1708B_8ch},
1991 { .id = 0x1106E723, .name = "VIA VT1708B 8-Ch",
1992 .patch = patch_vt1708B_8ch},
1993 { .id = 0x1106E724, .name = "VIA VT1708B 4-Ch",
1994 .patch = patch_vt1708B_4ch},
1995 { .id = 0x1106E725, .name = "VIA VT1708B 4-Ch",
1996 .patch = patch_vt1708B_4ch},
1997 { .id = 0x1106E726, .name = "VIA VT1708B 4-Ch",
1998 .patch = patch_vt1708B_4ch},
1999 { .id = 0x1106E727, .name = "VIA VT1708B 4-Ch",
2000 .patch = patch_vt1708B_4ch},