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);
380 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
381 struct hda_codec *codec,
382 unsigned int stream_tag,
384 struct snd_pcm_substream *substream)
386 struct via_spec *spec = codec->spec;
387 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
388 stream_tag, format, substream);
394 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
395 struct hda_codec *codec,
396 unsigned int stream_tag,
398 struct snd_pcm_substream *substream)
400 struct via_spec *spec = codec->spec;
402 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
403 stream_tag, 0, format);
407 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
408 struct hda_codec *codec,
409 struct snd_pcm_substream *substream)
411 struct via_spec *spec = codec->spec;
412 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
417 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
421 .nid = 0x10, /* NID to query formats and rates */
423 .open = via_playback_pcm_open,
424 .prepare = via_playback_pcm_prepare,
425 .cleanup = via_playback_pcm_cleanup
429 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
433 .nid = 0x15, /* NID to query formats and rates */
435 .prepare = via_capture_pcm_prepare,
436 .cleanup = via_capture_pcm_cleanup
440 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
444 /* NID is set in via_build_pcms */
446 .open = via_dig_playback_pcm_open,
447 .close = via_dig_playback_pcm_close,
448 .prepare = via_dig_playback_pcm_prepare
452 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
458 static int via_build_controls(struct hda_codec *codec)
460 struct via_spec *spec = codec->spec;
464 for (i = 0; i < spec->num_mixers; i++) {
465 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
470 if (spec->multiout.dig_out_nid) {
471 err = snd_hda_create_spdif_out_ctls(codec,
472 spec->multiout.dig_out_nid);
476 if (spec->dig_in_nid) {
477 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
484 static int via_build_pcms(struct hda_codec *codec)
486 struct via_spec *spec = codec->spec;
487 struct hda_pcm *info = spec->pcm_rec;
490 codec->pcm_info = info;
492 info->name = spec->stream_name_analog;
493 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
494 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
495 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
496 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
498 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
499 spec->multiout.max_channels;
501 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
504 info->name = spec->stream_name_digital;
505 if (spec->multiout.dig_out_nid) {
506 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
507 *(spec->stream_digital_playback);
508 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
509 spec->multiout.dig_out_nid;
511 if (spec->dig_in_nid) {
512 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
513 *(spec->stream_digital_capture);
514 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
522 static void via_free(struct hda_codec *codec)
524 struct via_spec *spec = codec->spec;
530 if (spec->kctl_alloc) {
531 for (i = 0; i < spec->num_kctl_used; i++)
532 kfree(spec->kctl_alloc[i].name);
533 kfree(spec->kctl_alloc);
539 static int via_init(struct hda_codec *codec)
541 struct via_spec *spec = codec->spec;
542 snd_hda_sequence_write(codec, spec->init_verbs);
548 static struct hda_codec_ops via_patch_ops = {
549 .build_controls = via_build_controls,
550 .build_pcms = via_build_pcms,
555 /* fill in the dac_nids table from the parsed pin configuration */
556 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
557 const struct auto_pin_cfg *cfg)
562 spec->multiout.num_dacs = cfg->line_outs;
564 spec->multiout.dac_nids = spec->private_dac_nids;
566 for(i = 0; i < 4; i++) {
567 nid = cfg->line_out_pins[i];
569 /* config dac list */
572 spec->multiout.dac_nids[i] = 0x10;
574 case AUTO_SEQ_CENLFE:
575 spec->multiout.dac_nids[i] = 0x12;
577 case AUTO_SEQ_SURROUND:
578 spec->multiout.dac_nids[i] = 0x13;
581 spec->multiout.dac_nids[i] = 0x11;
590 /* add playback controls from the parsed DAC table */
591 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
592 const struct auto_pin_cfg *cfg)
595 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
596 hda_nid_t nid, nid_vol = 0;
599 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
600 nid = cfg->line_out_pins[i];
605 if (i != AUTO_SEQ_FRONT)
606 nid_vol = 0x1b - i + 1;
608 if (i == AUTO_SEQ_CENLFE) {
610 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
611 "Center Playback Volume",
612 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
615 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
616 "LFE Playback Volume",
617 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
620 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
621 "Center Playback Switch",
622 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
625 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
626 "LFE Playback Switch",
627 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
630 } else if (i == AUTO_SEQ_FRONT){
631 /* add control to mixer index 0 */
632 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
633 "Master Front Playback Volume",
634 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT));
637 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
638 "Master Front Playback Switch",
639 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT));
643 /* add control to PW3 */
644 sprintf(name, "%s Playback Volume", chname[i]);
645 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
646 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
649 sprintf(name, "%s Playback Switch", chname[i]);
650 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
651 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
655 sprintf(name, "%s Playback Volume", chname[i]);
656 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
657 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
660 sprintf(name, "%s Playback Switch", chname[i]);
661 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
662 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
671 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
678 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
680 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
681 "Headphone Playback Volume",
682 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
685 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
686 "Headphone Playback Switch",
687 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
694 /* create playback/capture controls for input pins */
695 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
696 const struct auto_pin_cfg *cfg)
698 static char *labels[] = {
699 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
701 struct hda_input_mux *imux = &spec->private_imux;
704 /* for internal loopback recording select */
705 imux->items[imux->num_items].label = "Stereo Mixer";
706 imux->items[imux->num_items].index = idx;
709 for (i = 0; i < AUTO_PIN_LAST; i++) {
710 if (!cfg->input_pins[i])
713 switch (cfg->input_pins[i]) {
718 case 0x1e: /* Line In */
722 case 0x21: /* Front Mic */
730 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
734 imux->items[imux->num_items].label = labels[i];
735 imux->items[imux->num_items].index = idx;
741 static int vt1708_parse_auto_config(struct hda_codec *codec)
743 struct via_spec *spec = codec->spec;
746 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
749 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
752 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
753 return 0; /* can't find valid BIOS pin config */
755 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
758 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
761 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
765 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
767 if (spec->autocfg.dig_out_pin)
768 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
769 if (spec->autocfg.dig_in_pin)
770 spec->dig_in_nid = VT1708_DIGIN_NID;
772 if (spec->kctl_alloc)
773 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
775 spec->init_verbs = vt1708_volume_init_verbs;
777 spec->input_mux = &spec->private_imux;
782 /* init callback for auto-configuration model -- overriding the default init */
783 static int via_auto_init(struct hda_codec *codec)
786 via_auto_init_multi_out(codec);
787 via_auto_init_hp_out(codec);
788 via_auto_init_analog_input(codec);
792 static int patch_vt1708(struct hda_codec *codec)
794 struct via_spec *spec;
797 /* create a codec specific record */
798 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
804 /* automatic parse from the BIOS config */
805 err = vt1708_parse_auto_config(codec);
810 printk(KERN_INFO "hda_codec: Cannot set up configuration "
811 "from BIOS. Using genenic mode...\n");
815 spec->stream_name_analog = "VT1708 Analog";
816 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
817 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
819 spec->stream_name_digital = "VT1708 Digital";
820 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
821 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
824 if (!spec->adc_nids && spec->input_mux) {
825 spec->adc_nids = vt1708_adc_nids;
826 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
827 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
831 codec->patch_ops = via_patch_ops;
833 codec->patch_ops.init = via_auto_init;
838 /* capture mixer elements */
839 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
840 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
841 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
842 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
843 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
844 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
845 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
847 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
848 /* The multiple "Capture Source" controls confuse alsamixer
849 * So call somewhat different..
850 * FIXME: the controls appear in the "playback" view!
852 /* .name = "Capture Source", */
853 .name = "Input Source",
855 .info = via_mux_enum_info,
856 .get = via_mux_enum_get,
857 .put = via_mux_enum_put,
863 * generic initialization of ADC, input mixers and output mixers
865 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
867 * Unmute ADC0-2 and set the default input to mic-in
869 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
870 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
871 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
874 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
877 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
878 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
879 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
880 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
881 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
882 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
885 * Set up output selector (0x1a, 0x1b, 0x29)
887 /* set vol=0 to output mixers */
888 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
889 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
890 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
895 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
896 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
898 /* Set input of PW4 as AOW4 */
899 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
900 /* Set mic as default input of sw0 */
901 {0x19, AC_VERB_SET_CONNECT_SEL, 0x2},
902 /* PW9 Output enable */
903 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
907 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
911 .nid = 0x10, /* NID to query formats and rates */
913 .open = via_playback_pcm_open,
914 .prepare = via_playback_pcm_prepare,
915 .cleanup = via_playback_pcm_cleanup
919 static struct hda_pcm_stream vt1709_6ch_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_pcm_analog_capture = {
935 .nid = 0x14, /* NID to query formats and rates */
937 .prepare = via_capture_pcm_prepare,
938 .cleanup = via_capture_pcm_cleanup
942 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
946 /* NID is set in via_build_pcms */
948 .open = via_dig_playback_pcm_open,
949 .close = via_dig_playback_pcm_close
953 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
959 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
960 const struct auto_pin_cfg *cfg)
965 if (cfg->line_outs == 4) /* 10 channels */
966 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
967 else if (cfg->line_outs == 3) /* 6 channels */
968 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
970 spec->multiout.dac_nids = spec->private_dac_nids;
972 if (cfg->line_outs == 4) { /* 10 channels */
973 for (i = 0; i < cfg->line_outs; i++) {
974 nid = cfg->line_out_pins[i];
976 /* config dac list */
980 spec->multiout.dac_nids[i] = 0x10;
982 case AUTO_SEQ_CENLFE:
984 spec->multiout.dac_nids[i] = 0x12;
986 case AUTO_SEQ_SURROUND:
988 spec->multiout.dac_nids[i] = 0x27;
992 spec->multiout.dac_nids[i] = 0x11;
999 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1001 } else if (cfg->line_outs == 3) { /* 6 channels */
1002 for(i = 0; i < cfg->line_outs; i++) {
1003 nid = cfg->line_out_pins[i];
1005 /* config dac list */
1007 case AUTO_SEQ_FRONT:
1009 spec->multiout.dac_nids[i] = 0x10;
1011 case AUTO_SEQ_CENLFE:
1013 spec->multiout.dac_nids[i] = 0x12;
1015 case AUTO_SEQ_SURROUND:
1017 spec->multiout.dac_nids[i] = 0x11;
1029 /* add playback controls from the parsed DAC table */
1030 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1031 const struct auto_pin_cfg *cfg)
1034 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1038 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1039 nid = cfg->line_out_pins[i];
1044 if (i == AUTO_SEQ_CENLFE) {
1046 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1047 "Center Playback Volume",
1048 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, HDA_OUTPUT));
1051 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1052 "LFE Playback Volume",
1053 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, HDA_OUTPUT));
1056 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1057 "Center Playback Switch",
1058 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, HDA_OUTPUT));
1061 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1062 "LFE Playback Switch",
1063 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, HDA_OUTPUT));
1066 } else if (i == AUTO_SEQ_FRONT){
1067 /* add control to mixer index 0 */
1068 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1069 "Master Front Playback Volume",
1070 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT));
1073 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1074 "Master Front Playback Switch",
1075 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT));
1079 /* add control to PW3 */
1080 sprintf(name, "%s Playback Volume", chname[i]);
1081 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1082 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
1085 sprintf(name, "%s Playback Switch", chname[i]);
1086 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1087 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
1090 } else if (i == AUTO_SEQ_SURROUND) {
1091 sprintf(name, "%s Playback Volume", chname[i]);
1092 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1093 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, HDA_OUTPUT));
1096 sprintf(name, "%s Playback Switch", chname[i]);
1097 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1098 HDA_COMPOSE_AMP_VAL(0x29, 3, 0, HDA_OUTPUT));
1101 } else if (i == AUTO_SEQ_SIDE) {
1102 sprintf(name, "%s Playback Volume", chname[i]);
1103 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1104 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT));
1107 sprintf(name, "%s Playback Switch", chname[i]);
1108 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1109 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT));
1118 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1125 if (spec->multiout.num_dacs == 5) /* 10 channels */
1126 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1127 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1128 spec->multiout.hp_nid = 0;
1130 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1131 "Headphone Playback Volume",
1132 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1135 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1136 "Headphone Playback Switch",
1137 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1144 /* create playback/capture controls for input pins */
1145 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1146 const struct auto_pin_cfg *cfg)
1148 static char *labels[] = {
1149 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1151 struct hda_input_mux *imux = &spec->private_imux;
1152 int i, err, idx = 0;
1154 /* for internal loopback recording select */
1155 imux->items[imux->num_items].label = "Stereo Mixer";
1156 imux->items[imux->num_items].index = idx;
1159 for (i = 0; i < AUTO_PIN_LAST; i++) {
1160 if (!cfg->input_pins[i])
1163 switch (cfg->input_pins[i]) {
1164 case 0x1d: /* Mic */
1168 case 0x1e: /* Line In */
1172 case 0x21: /* Front Mic */
1180 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1184 imux->items[imux->num_items].label = labels[i];
1185 imux->items[imux->num_items].index = idx;
1191 static int vt1709_parse_auto_config(struct hda_codec *codec)
1193 struct via_spec *spec = codec->spec;
1196 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1199 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1202 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1203 return 0; /* can't find valid BIOS pin config */
1205 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1208 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1211 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1215 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1217 if (spec->autocfg.dig_out_pin)
1218 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1219 if (spec->autocfg.dig_in_pin)
1220 spec->dig_in_nid = VT1709_DIGIN_NID;
1222 if (spec->kctl_alloc)
1223 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1225 spec->input_mux = &spec->private_imux;
1230 static int patch_vt1709_10ch(struct hda_codec *codec)
1232 struct via_spec *spec;
1235 /* create a codec specific record */
1236 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1242 err = vt1709_parse_auto_config(codec);
1247 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1248 "Using genenic mode...\n");
1251 spec->init_verbs = vt1709_10ch_volume_init_verbs;
1253 spec->stream_name_analog = "VT1709 Analog";
1254 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1255 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1257 spec->stream_name_digital = "VT1709 Digital";
1258 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1259 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1262 if (!spec->adc_nids && spec->input_mux) {
1263 spec->adc_nids = vt1709_adc_nids;
1264 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1265 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1269 codec->patch_ops = via_patch_ops;
1271 codec->patch_ops.init = via_auto_init;
1276 * generic initialization of ADC, input mixers and output mixers
1278 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1280 * Unmute ADC0-2 and set the default input to mic-in
1282 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1283 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1284 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1287 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1290 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1291 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1292 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1293 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1294 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1295 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1298 * Set up output selector (0x1a, 0x1b, 0x29)
1300 /* set vol=0 to output mixers */
1301 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1302 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1303 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1306 * Unmute PW3 and PW4
1308 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1309 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1311 /* Set input of PW4 as MW0 */
1312 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1313 /* Set mic as default input of sw0 */
1314 {0x19, AC_VERB_SET_CONNECT_SEL, 0x2},
1315 /* PW9 Output enable */
1316 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1320 static int patch_vt1709_6ch(struct hda_codec *codec)
1322 struct via_spec *spec;
1325 /* create a codec specific record */
1326 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1332 err = vt1709_parse_auto_config(codec);
1337 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1338 "Using genenic mode...\n");
1341 spec->init_verbs = vt1709_6ch_volume_init_verbs;
1343 spec->stream_name_analog = "VT1709 Analog";
1344 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1345 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1347 spec->stream_name_digital = "VT1709 Digital";
1348 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1349 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1352 if (!spec->adc_nids && spec->input_mux) {
1353 spec->adc_nids = vt1709_adc_nids;
1354 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1355 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1359 codec->patch_ops = via_patch_ops;
1361 codec->patch_ops.init = via_auto_init;
1369 struct hda_codec_preset snd_hda_preset_via[] = {
1370 { .id = 0x11061708, .name = "VIA VT1708", .patch = patch_vt1708},
1371 { .id = 0x11061709, .name = "VIA VT1708", .patch = patch_vt1708},
1372 { .id = 0x1106170A, .name = "VIA VT1708", .patch = patch_vt1708},
1373 { .id = 0x1106170B, .name = "VIA VT1708", .patch = patch_vt1708},
1374 { .id = 0x1106E710, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
1375 { .id = 0x1106E711, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
1376 { .id = 0x1106E712, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
1377 { .id = 0x1106E713, .name = "VIA VT1709 10-Ch", .patch = patch_vt1709_10ch},
1378 { .id = 0x1106E714, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
1379 { .id = 0x1106E715, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
1380 { .id = 0x1106E716, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},
1381 { .id = 0x1106E717, .name = "VIA VT1709 6-Ch", .patch = patch_vt1709_6ch},