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 */
31 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
34 #include <sound/driver.h>
35 #include <linux/init.h>
36 #include <linux/delay.h>
37 #include <linux/slab.h>
38 #include <sound/core.h>
39 #include "hda_codec.h"
40 #include "hda_local.h"
44 #define AMP_VAL_IDX_SHIFT 19
45 #define AMP_VAL_IDX_MASK (0x0f<<19)
47 #define NUM_CONTROL_ALLOC 32
48 #define NUM_VERB_ALLOC 32
51 #define VT1708_HP_NID 0x13
52 #define VT1708_DIGOUT_NID 0x14
53 #define VT1708_DIGIN_NID 0x16
55 #define VT1709_HP_DAC_NID 0x28
56 #define VT1709_DIGOUT_NID 0x13
57 #define VT1709_DIGIN_NID 0x17
59 #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
60 #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
61 #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
76 static struct snd_kcontrol_new vt1708_control_templates[] = {
77 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
78 HDA_CODEC_MUTE(NULL, 0, 0, 0),
83 /* codec parameterization */
84 struct snd_kcontrol_new *mixers[3];
85 unsigned int num_mixers;
87 struct hda_verb *init_verbs;
89 char *stream_name_analog;
90 struct hda_pcm_stream *stream_analog_playback;
91 struct hda_pcm_stream *stream_analog_capture;
93 char *stream_name_digital;
94 struct hda_pcm_stream *stream_digital_playback;
95 struct hda_pcm_stream *stream_digital_capture;
98 struct hda_multi_out multiout;
101 unsigned int num_adc_nids;
103 hda_nid_t dig_in_nid;
106 const struct hda_input_mux *input_mux;
107 unsigned int cur_mux[3];
109 /* PCM information */
110 struct hda_pcm pcm_rec[2];
112 /* dynamic controls, init_verbs and input_mux */
113 struct auto_pin_cfg autocfg;
114 unsigned int num_kctl_alloc, num_kctl_used;
115 struct snd_kcontrol_new *kctl_alloc;
116 struct hda_input_mux private_imux;
117 hda_nid_t private_dac_nids[4];
120 static hda_nid_t vt1708_adc_nids[2] = {
125 static hda_nid_t vt1709_adc_nids[3] = {
130 /* add dynamic controls */
131 static int via_add_control(struct via_spec *spec, int type, const char *name,
134 struct snd_kcontrol_new *knew;
136 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
137 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
139 /* array + terminator */
140 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
143 if (spec->kctl_alloc) {
144 memcpy(knew, spec->kctl_alloc,
145 sizeof(*knew) * spec->num_kctl_alloc);
146 kfree(spec->kctl_alloc);
148 spec->kctl_alloc = knew;
149 spec->num_kctl_alloc = num;
152 knew = &spec->kctl_alloc[spec->num_kctl_used];
153 *knew = vt1708_control_templates[type];
154 knew->name = kstrdup(name, GFP_KERNEL);
158 knew->private_value = val;
159 spec->num_kctl_used++;
163 /* create input playback/capture controls for the given pin */
164 static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
165 const char *ctlname, int idx, int mix_nid)
170 sprintf(name, "%s Playback Volume", ctlname);
171 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
172 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
175 sprintf(name, "%s Playback Switch", ctlname);
176 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
177 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
183 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
184 hda_nid_t nid, int pin_type,
188 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
190 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
195 static void via_auto_init_multi_out(struct hda_codec *codec)
197 struct via_spec *spec = codec->spec;
200 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
201 hda_nid_t nid = spec->autocfg.line_out_pins[i];
203 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
207 static void via_auto_init_hp_out(struct hda_codec *codec)
209 struct via_spec *spec = codec->spec;
212 pin = spec->autocfg.hp_pins[0];
213 if (pin) /* connect to front */
214 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
217 static void via_auto_init_analog_input(struct hda_codec *codec)
219 struct via_spec *spec = codec->spec;
222 for (i = 0; i < AUTO_PIN_LAST; i++) {
223 hda_nid_t nid = spec->autocfg.input_pins[i];
225 snd_hda_codec_write(codec, nid, 0,
226 AC_VERB_SET_PIN_WIDGET_CONTROL,
227 (i <= AUTO_PIN_FRONT_MIC ?
228 PIN_VREF50 : PIN_IN));
235 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
236 struct snd_ctl_elem_info *uinfo)
238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
239 struct via_spec *spec = codec->spec;
240 return snd_hda_input_mux_info(spec->input_mux, uinfo);
243 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
244 struct snd_ctl_elem_value *ucontrol)
246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
247 struct via_spec *spec = codec->spec;
248 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
250 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
254 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_value *ucontrol)
257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
258 struct via_spec *spec = codec->spec;
259 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
260 unsigned int vendor_id = codec->vendor_id;
262 /* AIW0 lydia 060801 add for correct sw0 input select */
263 if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
264 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
265 0x18, &spec->cur_mux[adc_idx]);
266 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
267 IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0) )
268 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
269 0x19, &spec->cur_mux[adc_idx]);
271 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
272 spec->adc_nids[adc_idx],
273 &spec->cur_mux[adc_idx]);
276 /* capture mixer elements */
277 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
278 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
279 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
280 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
281 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
283 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
284 /* The multiple "Capture Source" controls confuse alsamixer
285 * So call somewhat different..
286 * FIXME: the controls appear in the "playback" view!
288 /* .name = "Capture Source", */
289 .name = "Input Source",
291 .info = via_mux_enum_info,
292 .get = via_mux_enum_get,
293 .put = via_mux_enum_put,
298 * generic initialization of ADC, input mixers and output mixers
300 static struct hda_verb vt1708_volume_init_verbs[] = {
302 * Unmute ADC0-1 and set the default input to mic-in
304 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
305 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
308 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
311 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
312 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
313 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
314 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
315 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
316 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
319 * Set up output mixers (0x19 - 0x1b)
321 /* set vol=0 to output mixers */
322 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
323 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
324 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
326 /* Setup default input to PW4 */
327 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
328 /* Set mic as default input of sw0 */
329 {0x18, AC_VERB_SET_CONNECT_SEL, 0x2},
330 /* PW9 Output enable */
331 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
334 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
335 struct hda_codec *codec,
336 struct snd_pcm_substream *substream)
338 struct via_spec *spec = codec->spec;
339 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
342 static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
343 struct hda_codec *codec,
344 unsigned int stream_tag,
346 struct snd_pcm_substream *substream)
348 struct via_spec *spec = codec->spec;
349 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
350 stream_tag, format, substream);
353 static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
354 struct hda_codec *codec,
355 struct snd_pcm_substream *substream)
357 struct via_spec *spec = codec->spec;
358 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
364 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
365 struct hda_codec *codec,
366 struct snd_pcm_substream *substream)
368 struct via_spec *spec = codec->spec;
369 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
372 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
373 struct hda_codec *codec,
374 struct snd_pcm_substream *substream)
376 struct via_spec *spec = codec->spec;
377 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
383 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
384 struct hda_codec *codec,
385 unsigned int stream_tag,
387 struct snd_pcm_substream *substream)
389 struct via_spec *spec = codec->spec;
391 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
392 stream_tag, 0, format);
396 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
397 struct hda_codec *codec,
398 struct snd_pcm_substream *substream)
400 struct via_spec *spec = codec->spec;
401 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
406 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
410 .nid = 0x10, /* NID to query formats and rates */
412 .open = via_playback_pcm_open,
413 .prepare = via_playback_pcm_prepare,
414 .cleanup = via_playback_pcm_cleanup
418 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
422 .nid = 0x15, /* NID to query formats and rates */
424 .prepare = via_capture_pcm_prepare,
425 .cleanup = via_capture_pcm_cleanup
429 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
433 /* NID is set in via_build_pcms */
435 .open = via_dig_playback_pcm_open,
436 .close = via_dig_playback_pcm_close
440 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
446 static int via_build_controls(struct hda_codec *codec)
448 struct via_spec *spec = codec->spec;
452 for (i = 0; i < spec->num_mixers; i++) {
453 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
458 if (spec->multiout.dig_out_nid) {
459 err = snd_hda_create_spdif_out_ctls(codec,
460 spec->multiout.dig_out_nid);
464 if (spec->dig_in_nid) {
465 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
472 static int via_build_pcms(struct hda_codec *codec)
474 struct via_spec *spec = codec->spec;
475 struct hda_pcm *info = spec->pcm_rec;
478 codec->pcm_info = info;
480 info->name = spec->stream_name_analog;
481 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
482 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
483 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
484 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
486 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
487 spec->multiout.max_channels;
489 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
492 info->name = spec->stream_name_digital;
493 if (spec->multiout.dig_out_nid) {
494 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
495 *(spec->stream_digital_playback);
496 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
497 spec->multiout.dig_out_nid;
499 if (spec->dig_in_nid) {
500 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
501 *(spec->stream_digital_capture);
502 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
510 static void via_free(struct hda_codec *codec)
512 struct via_spec *spec = codec->spec;
518 if (spec->kctl_alloc) {
519 for (i = 0; i < spec->num_kctl_used; i++)
520 kfree(spec->kctl_alloc[i].name);
521 kfree(spec->kctl_alloc);
527 static int via_init(struct hda_codec *codec)
529 struct via_spec *spec = codec->spec;
530 snd_hda_sequence_write(codec, spec->init_verbs);
538 static int via_resume(struct hda_codec *codec)
540 struct via_spec *spec = codec->spec;
544 for (i = 0; i < spec->num_mixers; i++)
545 snd_hda_resume_ctls(codec, spec->mixers[i]);
546 if (spec->multiout.dig_out_nid)
547 snd_hda_resume_spdif_out(codec);
548 if (spec->dig_in_nid)
549 snd_hda_resume_spdif_in(codec);
557 static struct hda_codec_ops via_patch_ops = {
558 .build_controls = via_build_controls,
559 .build_pcms = via_build_pcms,
563 .resume = via_resume,
567 /* fill in the dac_nids table from the parsed pin configuration */
568 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
569 const struct auto_pin_cfg *cfg)
574 spec->multiout.num_dacs = cfg->line_outs;
576 spec->multiout.dac_nids = spec->private_dac_nids;
578 for(i = 0; i < 4; i++) {
579 nid = cfg->line_out_pins[i];
581 /* config dac list */
584 spec->multiout.dac_nids[i] = 0x10;
586 case AUTO_SEQ_CENLFE:
587 spec->multiout.dac_nids[i] = 0x12;
589 case AUTO_SEQ_SURROUND:
590 spec->multiout.dac_nids[i] = 0x13;
593 spec->multiout.dac_nids[i] = 0x11;
602 /* add playback controls from the parsed DAC table */
603 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
604 const struct auto_pin_cfg *cfg)
607 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
608 hda_nid_t nid, nid_vol = 0;
611 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
612 nid = cfg->line_out_pins[i];
617 if (i != AUTO_SEQ_FRONT)
618 nid_vol = 0x1b - i + 1;
620 if (i == AUTO_SEQ_CENLFE) {
622 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
623 "Center Playback Volume",
624 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
627 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
628 "LFE Playback Volume",
629 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
632 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
633 "Center Playback Switch",
634 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
637 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
638 "LFE Playback Switch",
639 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
642 } else if (i == AUTO_SEQ_FRONT){
643 /* add control to mixer index 0 */
644 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
645 "Master Front Playback Volume",
646 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT));
649 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
650 "Master Front Playback Switch",
651 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT));
655 /* add control to PW3 */
656 sprintf(name, "%s Playback Volume", chname[i]);
657 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
658 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
661 sprintf(name, "%s Playback Switch", chname[i]);
662 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
663 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
667 sprintf(name, "%s Playback Volume", chname[i]);
668 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
669 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
672 sprintf(name, "%s Playback Switch", chname[i]);
673 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
674 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
683 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
690 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
692 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
693 "Headphone Playback Volume",
694 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
697 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
698 "Headphone Playback Switch",
699 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
706 /* create playback/capture controls for input pins */
707 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
708 const struct auto_pin_cfg *cfg)
710 static char *labels[] = {
711 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
713 struct hda_input_mux *imux = &spec->private_imux;
716 /* for internal loopback recording select */
717 imux->items[imux->num_items].label = "Stereo Mixer";
718 imux->items[imux->num_items].index = idx;
721 for (i = 0; i < AUTO_PIN_LAST; i++) {
722 if (!cfg->input_pins[i])
725 switch (cfg->input_pins[i]) {
730 case 0x1e: /* Line In */
734 case 0x21: /* Front Mic */
742 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
746 imux->items[imux->num_items].label = labels[i];
747 imux->items[imux->num_items].index = idx;
753 static int vt1708_parse_auto_config(struct hda_codec *codec)
755 struct via_spec *spec = codec->spec;
758 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
761 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
764 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
765 return 0; /* can't find valid BIOS pin config */
767 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
770 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
773 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
777 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
779 if (spec->autocfg.dig_out_pin)
780 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
781 if (spec->autocfg.dig_in_pin)
782 spec->dig_in_nid = VT1708_DIGIN_NID;
784 if (spec->kctl_alloc)
785 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
787 spec->init_verbs = vt1708_volume_init_verbs;
789 spec->input_mux = &spec->private_imux;
794 /* init callback for auto-configuration model -- overriding the default init */
795 static int via_auto_init(struct hda_codec *codec)
798 via_auto_init_multi_out(codec);
799 via_auto_init_hp_out(codec);
800 via_auto_init_analog_input(codec);
804 static int patch_vt1708(struct hda_codec *codec)
806 struct via_spec *spec;
809 /* create a codec specific record */
810 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
816 /* automatic parse from the BIOS config */
817 err = vt1708_parse_auto_config(codec);
822 printk(KERN_INFO "hda_codec: Cannot set up configuration "
823 "from BIOS. Using genenic mode...\n");
827 spec->stream_name_analog = "VT1708 Analog";
828 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
829 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
831 spec->stream_name_digital = "VT1708 Digital";
832 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
833 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
836 if (!spec->adc_nids && spec->input_mux) {
837 spec->adc_nids = vt1708_adc_nids;
838 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
839 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
843 codec->patch_ops = via_patch_ops;
845 codec->patch_ops.init = via_auto_init;
850 /* capture mixer elements */
851 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
852 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
853 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
854 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
855 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
856 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
857 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
859 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
860 /* The multiple "Capture Source" controls confuse alsamixer
861 * So call somewhat different..
862 * FIXME: the controls appear in the "playback" view!
864 /* .name = "Capture Source", */
865 .name = "Input Source",
867 .info = via_mux_enum_info,
868 .get = via_mux_enum_get,
869 .put = via_mux_enum_put,
875 * generic initialization of ADC, input mixers and output mixers
877 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
879 * Unmute ADC0-2 and set the default input to mic-in
881 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
882 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
883 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
886 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
889 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
890 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
891 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
892 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
893 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
894 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
897 * Set up output selector (0x1a, 0x1b, 0x29)
899 /* set vol=0 to output mixers */
900 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
901 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
902 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
907 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
908 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
910 /* Set input of PW4 as AOW4 */
911 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
912 /* Set mic as default input of sw0 */
913 {0x19, AC_VERB_SET_CONNECT_SEL, 0x2},
914 /* PW9 Output enable */
915 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
919 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
923 .nid = 0x10, /* NID to query formats and rates */
925 .open = via_playback_pcm_open,
926 .prepare = via_playback_pcm_prepare,
927 .cleanup = via_playback_pcm_cleanup
931 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
935 .nid = 0x10, /* NID to query formats and rates */
937 .open = via_playback_pcm_open,
938 .prepare = via_playback_pcm_prepare,
939 .cleanup = via_playback_pcm_cleanup
943 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
947 .nid = 0x14, /* NID to query formats and rates */
949 .prepare = via_capture_pcm_prepare,
950 .cleanup = via_capture_pcm_cleanup
954 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
958 /* NID is set in via_build_pcms */
960 .open = via_dig_playback_pcm_open,
961 .close = via_dig_playback_pcm_close
965 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
971 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
972 const struct auto_pin_cfg *cfg)
977 if (cfg->line_outs == 4) /* 10 channels */
978 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
979 else if (cfg->line_outs == 3) /* 6 channels */
980 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
982 spec->multiout.dac_nids = spec->private_dac_nids;
984 if (cfg->line_outs == 4) { /* 10 channels */
985 for (i = 0; i < cfg->line_outs; i++) {
986 nid = cfg->line_out_pins[i];
988 /* config dac list */
992 spec->multiout.dac_nids[i] = 0x10;
994 case AUTO_SEQ_CENLFE:
996 spec->multiout.dac_nids[i] = 0x12;
998 case AUTO_SEQ_SURROUND:
1000 spec->multiout.dac_nids[i] = 0x27;
1004 spec->multiout.dac_nids[i] = 0x11;
1011 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1013 } else if (cfg->line_outs == 3) { /* 6 channels */
1014 for(i = 0; i < cfg->line_outs; i++) {
1015 nid = cfg->line_out_pins[i];
1017 /* config dac list */
1019 case AUTO_SEQ_FRONT:
1021 spec->multiout.dac_nids[i] = 0x10;
1023 case AUTO_SEQ_CENLFE:
1025 spec->multiout.dac_nids[i] = 0x12;
1027 case AUTO_SEQ_SURROUND:
1029 spec->multiout.dac_nids[i] = 0x11;
1041 /* add playback controls from the parsed DAC table */
1042 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1043 const struct auto_pin_cfg *cfg)
1046 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1050 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1051 nid = cfg->line_out_pins[i];
1056 if (i == AUTO_SEQ_CENLFE) {
1058 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1059 "Center Playback Volume",
1060 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, HDA_OUTPUT));
1063 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1064 "LFE Playback Volume",
1065 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, HDA_OUTPUT));
1068 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1069 "Center Playback Switch",
1070 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, HDA_OUTPUT));
1073 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1074 "LFE Playback Switch",
1075 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, HDA_OUTPUT));
1078 } else if (i == AUTO_SEQ_FRONT){
1079 /* add control to mixer index 0 */
1080 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1081 "Master Front Playback Volume",
1082 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT));
1085 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1086 "Master Front Playback Switch",
1087 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT));
1091 /* add control to PW3 */
1092 sprintf(name, "%s Playback Volume", chname[i]);
1093 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1094 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
1097 sprintf(name, "%s Playback Switch", chname[i]);
1098 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1099 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
1102 } else if (i == AUTO_SEQ_SURROUND) {
1103 sprintf(name, "%s Playback Volume", chname[i]);
1104 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1105 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, HDA_OUTPUT));
1108 sprintf(name, "%s Playback Switch", chname[i]);
1109 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1110 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, HDA_OUTPUT));
1113 } else if (i == AUTO_SEQ_SIDE) {
1114 sprintf(name, "%s Playback Volume", chname[i]);
1115 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1116 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT));
1119 sprintf(name, "%s Playback Switch", chname[i]);
1120 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1121 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT));
1130 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1137 if (spec->multiout.num_dacs == 5) /* 10 channels */
1138 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1139 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1140 spec->multiout.hp_nid = 0;
1142 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1143 "Headphone Playback Volume",
1144 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1147 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1148 "Headphone Playback Switch",
1149 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1156 /* create playback/capture controls for input pins */
1157 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1158 const struct auto_pin_cfg *cfg)
1160 static char *labels[] = {
1161 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1163 struct hda_input_mux *imux = &spec->private_imux;
1164 int i, err, idx = 0;
1166 /* for internal loopback recording select */
1167 imux->items[imux->num_items].label = "Stereo Mixer";
1168 imux->items[imux->num_items].index = idx;
1171 for (i = 0; i < AUTO_PIN_LAST; i++) {
1172 if (!cfg->input_pins[i])
1175 switch (cfg->input_pins[i]) {
1176 case 0x1d: /* Mic */
1180 case 0x1e: /* Line In */
1184 case 0x21: /* Front Mic */
1192 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1196 imux->items[imux->num_items].label = labels[i];
1197 imux->items[imux->num_items].index = idx;
1203 static int vt1709_parse_auto_config(struct hda_codec *codec)
1205 struct via_spec *spec = codec->spec;
1208 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1211 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1214 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1215 return 0; /* can't find valid BIOS pin config */
1217 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1220 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1223 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1227 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1229 if (spec->autocfg.dig_out_pin)
1230 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1231 if (spec->autocfg.dig_in_pin)
1232 spec->dig_in_nid = VT1709_DIGIN_NID;
1234 if (spec->kctl_alloc)
1235 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1237 spec->input_mux = &spec->private_imux;
1242 static int patch_vt1709_10ch(struct hda_codec *codec)
1244 struct via_spec *spec;
1247 /* create a codec specific record */
1248 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1254 err = vt1709_parse_auto_config(codec);
1259 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1260 "Using genenic mode...\n");
1263 spec->init_verbs = vt1709_10ch_volume_init_verbs;
1265 spec->stream_name_analog = "VT1709 Analog";
1266 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1267 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1269 spec->stream_name_digital = "VT1709 Digital";
1270 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1271 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1274 if (!spec->adc_nids && spec->input_mux) {
1275 spec->adc_nids = vt1709_adc_nids;
1276 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1277 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1281 codec->patch_ops = via_patch_ops;
1283 codec->patch_ops.init = via_auto_init;
1288 * generic initialization of ADC, input mixers and output mixers
1290 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1292 * Unmute ADC0-2 and set the default input to mic-in
1294 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1295 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1296 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1299 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1302 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1303 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1304 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1305 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1306 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1307 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1310 * Set up output selector (0x1a, 0x1b, 0x29)
1312 /* set vol=0 to output mixers */
1313 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1314 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1315 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1318 * Unmute PW3 and PW4
1320 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1321 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1323 /* Set input of PW4 as MW0 */
1324 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1325 /* Set mic as default input of sw0 */
1326 {0x19, AC_VERB_SET_CONNECT_SEL, 0x2},
1327 /* PW9 Output enable */
1328 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1332 static int patch_vt1709_6ch(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_6ch_volume_init_verbs;
1355 spec->stream_name_analog = "VT1709 Analog";
1356 spec->stream_analog_playback = &vt1709_6ch_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;
1381 struct hda_codec_preset snd_hda_preset_via[] = {
1382 { .id = 0x11061708, .name = "VIA VT1708", .patch = patch_vt1708},
1383 { .id = 0x11061709, .name = "VIA VT1708", .patch = patch_vt1708},
1384 { .id = 0x1106170A, .name = "VIA VT1708", .patch = patch_vt1708},
1385 { .id = 0x1106170B, .name = "VIA VT1708", .patch = patch_vt1708},
1386 { .id = 0x1106E710, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
1387 { .id = 0x1106E711, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
1388 { .id = 0x1106E712, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
1389 { .id = 0x1106E713, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
1390 { .id = 0x1106E714, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
1391 { .id = 0x1106E715, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
1392 { .id = 0x1106E716, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
1393 { .id = 0x1106E717, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},