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 <linux/init.h>
37 #include <linux/delay.h>
38 #include <linux/slab.h>
39 #include <sound/core.h>
40 #include "hda_codec.h"
41 #include "hda_local.h"
45 #define AMP_VAL_IDX_SHIFT 19
46 #define AMP_VAL_IDX_MASK (0x0f<<19)
48 #define NUM_CONTROL_ALLOC 32
49 #define NUM_VERB_ALLOC 32
52 #define VT1708_HP_NID 0x13
53 #define VT1708_DIGOUT_NID 0x14
54 #define VT1708_DIGIN_NID 0x16
55 #define VT1708_DIGIN_PIN 0x26
57 #define VT1709_HP_DAC_NID 0x28
58 #define VT1709_DIGOUT_NID 0x13
59 #define VT1709_DIGIN_NID 0x17
60 #define VT1709_DIGIN_PIN 0x25
62 #define VT1708B_HP_NID 0x25
63 #define VT1708B_DIGOUT_NID 0x12
64 #define VT1708B_DIGIN_NID 0x15
65 #define VT1708B_DIGIN_PIN 0x21
67 #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
68 #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
69 #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
70 #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
71 #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
86 static struct snd_kcontrol_new vt1708_control_templates[] = {
87 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
88 HDA_CODEC_MUTE(NULL, 0, 0, 0),
93 /* codec parameterization */
94 struct snd_kcontrol_new *mixers[3];
95 unsigned int num_mixers;
97 struct hda_verb *init_verbs;
99 char *stream_name_analog;
100 struct hda_pcm_stream *stream_analog_playback;
101 struct hda_pcm_stream *stream_analog_capture;
103 char *stream_name_digital;
104 struct hda_pcm_stream *stream_digital_playback;
105 struct hda_pcm_stream *stream_digital_capture;
108 struct hda_multi_out multiout;
111 unsigned int num_adc_nids;
113 hda_nid_t dig_in_nid;
116 const struct hda_input_mux *input_mux;
117 unsigned int cur_mux[3];
119 /* PCM information */
120 struct hda_pcm pcm_rec[2];
122 /* dynamic controls, init_verbs and input_mux */
123 struct auto_pin_cfg autocfg;
124 unsigned int num_kctl_alloc, num_kctl_used;
125 struct snd_kcontrol_new *kctl_alloc;
126 struct hda_input_mux private_imux;
127 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
129 #ifdef CONFIG_SND_HDA_POWER_SAVE
130 struct hda_loopback_check loopback;
134 static hda_nid_t vt1708_adc_nids[2] = {
139 static hda_nid_t vt1709_adc_nids[3] = {
144 static hda_nid_t vt1708B_adc_nids[2] = {
149 /* add dynamic controls */
150 static int via_add_control(struct via_spec *spec, int type, const char *name,
153 struct snd_kcontrol_new *knew;
155 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
156 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
158 /* array + terminator */
159 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
162 if (spec->kctl_alloc) {
163 memcpy(knew, spec->kctl_alloc,
164 sizeof(*knew) * spec->num_kctl_alloc);
165 kfree(spec->kctl_alloc);
167 spec->kctl_alloc = knew;
168 spec->num_kctl_alloc = num;
171 knew = &spec->kctl_alloc[spec->num_kctl_used];
172 *knew = vt1708_control_templates[type];
173 knew->name = kstrdup(name, GFP_KERNEL);
177 knew->private_value = val;
178 spec->num_kctl_used++;
182 /* create input playback/capture controls for the given pin */
183 static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
184 const char *ctlname, int idx, int mix_nid)
189 sprintf(name, "%s Playback Volume", ctlname);
190 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
191 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
194 sprintf(name, "%s Playback Switch", ctlname);
195 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
196 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
202 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
203 hda_nid_t nid, int pin_type,
207 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
209 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
214 static void via_auto_init_multi_out(struct hda_codec *codec)
216 struct via_spec *spec = codec->spec;
219 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
220 hda_nid_t nid = spec->autocfg.line_out_pins[i];
222 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
226 static void via_auto_init_hp_out(struct hda_codec *codec)
228 struct via_spec *spec = codec->spec;
231 pin = spec->autocfg.hp_pins[0];
232 if (pin) /* connect to front */
233 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
236 static void via_auto_init_analog_input(struct hda_codec *codec)
238 struct via_spec *spec = codec->spec;
241 for (i = 0; i < AUTO_PIN_LAST; i++) {
242 hda_nid_t nid = spec->autocfg.input_pins[i];
244 snd_hda_codec_write(codec, nid, 0,
245 AC_VERB_SET_PIN_WIDGET_CONTROL,
246 (i <= AUTO_PIN_FRONT_MIC ?
247 PIN_VREF50 : PIN_IN));
254 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_info *uinfo)
257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
258 struct via_spec *spec = codec->spec;
259 return snd_hda_input_mux_info(spec->input_mux, uinfo);
262 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
263 struct snd_ctl_elem_value *ucontrol)
265 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
266 struct via_spec *spec = codec->spec;
267 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
269 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
273 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
274 struct snd_ctl_elem_value *ucontrol)
276 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
277 struct via_spec *spec = codec->spec;
278 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
279 unsigned int vendor_id = codec->vendor_id;
281 /* AIW0 lydia 060801 add for correct sw0 input select */
282 if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
283 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
284 0x18, &spec->cur_mux[adc_idx]);
285 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
286 IS_VT1709_6CH_VENDORID(vendor_id)) && adc_idx == 0)
287 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
288 0x19, &spec->cur_mux[adc_idx]);
289 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
290 IS_VT1708B_4CH_VENDORID(vendor_id)) && adc_idx == 0)
291 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
292 0x17, &spec->cur_mux[adc_idx]);
294 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
295 spec->adc_nids[adc_idx],
296 &spec->cur_mux[adc_idx]);
299 /* capture mixer elements */
300 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
301 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
302 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
303 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
304 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
306 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
307 /* The multiple "Capture Source" controls confuse alsamixer
308 * So call somewhat different..
310 /* .name = "Capture Source", */
311 .name = "Input Source",
313 .info = via_mux_enum_info,
314 .get = via_mux_enum_get,
315 .put = via_mux_enum_put,
320 * generic initialization of ADC, input mixers and output mixers
322 static struct hda_verb vt1708_volume_init_verbs[] = {
324 * Unmute ADC0-1 and set the default input to mic-in
326 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
327 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
330 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
333 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
334 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
335 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
336 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
337 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
338 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
341 * Set up output mixers (0x19 - 0x1b)
343 /* set vol=0 to output mixers */
344 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
345 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
346 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
348 /* Setup default input to PW4 */
349 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
350 /* PW9 Output enable */
351 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
355 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
356 struct hda_codec *codec,
357 struct snd_pcm_substream *substream)
359 struct via_spec *spec = codec->spec;
360 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
363 static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
364 struct hda_codec *codec,
365 unsigned int stream_tag,
367 struct snd_pcm_substream *substream)
369 struct via_spec *spec = codec->spec;
370 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
371 stream_tag, format, substream);
374 static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
375 struct hda_codec *codec,
376 struct snd_pcm_substream *substream)
378 struct via_spec *spec = codec->spec;
379 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
385 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
386 struct hda_codec *codec,
387 struct snd_pcm_substream *substream)
389 struct via_spec *spec = codec->spec;
390 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
393 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
394 struct hda_codec *codec,
395 struct snd_pcm_substream *substream)
397 struct via_spec *spec = codec->spec;
398 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
401 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
402 struct hda_codec *codec,
403 unsigned int stream_tag,
405 struct snd_pcm_substream *substream)
407 struct via_spec *spec = codec->spec;
408 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
409 stream_tag, format, substream);
415 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
416 struct hda_codec *codec,
417 unsigned int stream_tag,
419 struct snd_pcm_substream *substream)
421 struct via_spec *spec = codec->spec;
423 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
424 stream_tag, 0, format);
428 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
429 struct hda_codec *codec,
430 struct snd_pcm_substream *substream)
432 struct via_spec *spec = codec->spec;
433 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
438 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
442 .nid = 0x10, /* NID to query formats and rates */
444 .open = via_playback_pcm_open,
445 .prepare = via_playback_pcm_prepare,
446 .cleanup = via_playback_pcm_cleanup
450 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
454 .nid = 0x15, /* NID to query formats and rates */
456 .prepare = via_capture_pcm_prepare,
457 .cleanup = via_capture_pcm_cleanup
461 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
465 /* NID is set in via_build_pcms */
467 .open = via_dig_playback_pcm_open,
468 .close = via_dig_playback_pcm_close,
469 .prepare = via_dig_playback_pcm_prepare
473 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
479 static int via_build_controls(struct hda_codec *codec)
481 struct via_spec *spec = codec->spec;
485 for (i = 0; i < spec->num_mixers; i++) {
486 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
491 if (spec->multiout.dig_out_nid) {
492 err = snd_hda_create_spdif_out_ctls(codec,
493 spec->multiout.dig_out_nid);
497 if (spec->dig_in_nid) {
498 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
505 static int via_build_pcms(struct hda_codec *codec)
507 struct via_spec *spec = codec->spec;
508 struct hda_pcm *info = spec->pcm_rec;
511 codec->pcm_info = info;
513 info->name = spec->stream_name_analog;
514 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
515 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
516 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
517 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
519 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
520 spec->multiout.max_channels;
522 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
525 info->name = spec->stream_name_digital;
526 info->pcm_type = HDA_PCM_TYPE_SPDIF;
527 if (spec->multiout.dig_out_nid) {
528 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
529 *(spec->stream_digital_playback);
530 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
531 spec->multiout.dig_out_nid;
533 if (spec->dig_in_nid) {
534 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
535 *(spec->stream_digital_capture);
536 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
544 static void via_free(struct hda_codec *codec)
546 struct via_spec *spec = codec->spec;
552 if (spec->kctl_alloc) {
553 for (i = 0; i < spec->num_kctl_used; i++)
554 kfree(spec->kctl_alloc[i].name);
555 kfree(spec->kctl_alloc);
561 static int via_init(struct hda_codec *codec)
563 struct via_spec *spec = codec->spec;
564 snd_hda_sequence_write(codec, spec->init_verbs);
565 /* Lydia Add for EAPD enable */
566 if (!spec->dig_in_nid) { /* No Digital In connection */
567 if (IS_VT1708_VENDORID(codec->vendor_id)) {
568 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
569 AC_VERB_SET_PIN_WIDGET_CONTROL,
571 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
572 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
573 } else if (IS_VT1709_10CH_VENDORID(codec->vendor_id) ||
574 IS_VT1709_6CH_VENDORID(codec->vendor_id)) {
575 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
576 AC_VERB_SET_PIN_WIDGET_CONTROL,
578 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
579 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
580 } else if (IS_VT1708B_8CH_VENDORID(codec->vendor_id) ||
581 IS_VT1708B_4CH_VENDORID(codec->vendor_id)) {
582 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
583 AC_VERB_SET_PIN_WIDGET_CONTROL,
585 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
586 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
588 } else /* enable SPDIF-input pin */
589 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
590 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
595 #ifdef CONFIG_SND_HDA_POWER_SAVE
596 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
598 struct via_spec *spec = codec->spec;
599 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
605 static struct hda_codec_ops via_patch_ops = {
606 .build_controls = via_build_controls,
607 .build_pcms = via_build_pcms,
610 #ifdef CONFIG_SND_HDA_POWER_SAVE
611 .check_power_status = via_check_power_status,
615 /* fill in the dac_nids table from the parsed pin configuration */
616 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
617 const struct auto_pin_cfg *cfg)
622 spec->multiout.num_dacs = cfg->line_outs;
624 spec->multiout.dac_nids = spec->private_dac_nids;
626 for(i = 0; i < 4; i++) {
627 nid = cfg->line_out_pins[i];
629 /* config dac list */
632 spec->multiout.dac_nids[i] = 0x10;
634 case AUTO_SEQ_CENLFE:
635 spec->multiout.dac_nids[i] = 0x12;
637 case AUTO_SEQ_SURROUND:
638 spec->multiout.dac_nids[i] = 0x13;
641 spec->multiout.dac_nids[i] = 0x11;
650 /* add playback controls from the parsed DAC table */
651 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
652 const struct auto_pin_cfg *cfg)
655 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
656 hda_nid_t nid, nid_vol = 0;
659 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
660 nid = cfg->line_out_pins[i];
665 if (i != AUTO_SEQ_FRONT)
666 nid_vol = 0x1b - i + 1;
668 if (i == AUTO_SEQ_CENLFE) {
670 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
671 "Center Playback Volume",
672 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
676 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
677 "LFE Playback Volume",
678 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
682 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
683 "Center Playback Switch",
684 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
688 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
689 "LFE Playback Switch",
690 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
694 } else if (i == AUTO_SEQ_FRONT){
695 /* add control to mixer index 0 */
696 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
697 "Master Front Playback Volume",
698 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
702 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
703 "Master Front Playback Switch",
704 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
709 /* add control to PW3 */
710 sprintf(name, "%s Playback Volume", chname[i]);
711 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
712 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
716 sprintf(name, "%s Playback Switch", chname[i]);
717 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
718 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
723 sprintf(name, "%s Playback Volume", chname[i]);
724 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
725 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
729 sprintf(name, "%s Playback Switch", chname[i]);
730 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
731 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
741 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
748 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
750 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
751 "Headphone Playback Volume",
752 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
755 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
756 "Headphone Playback Switch",
757 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
764 /* create playback/capture controls for input pins */
765 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
766 const struct auto_pin_cfg *cfg)
768 static char *labels[] = {
769 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
771 struct hda_input_mux *imux = &spec->private_imux;
774 /* for internal loopback recording select */
775 imux->items[imux->num_items].label = "Stereo Mixer";
776 imux->items[imux->num_items].index = idx;
779 for (i = 0; i < AUTO_PIN_LAST; i++) {
780 if (!cfg->input_pins[i])
783 switch (cfg->input_pins[i]) {
788 case 0x1e: /* Line In */
792 case 0x21: /* Front Mic */
800 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
804 imux->items[imux->num_items].label = labels[i];
805 imux->items[imux->num_items].index = idx;
811 #ifdef CONFIG_SND_HDA_POWER_SAVE
812 static struct hda_amp_list vt1708_loopbacks[] = {
813 { 0x17, HDA_INPUT, 1 },
814 { 0x17, HDA_INPUT, 2 },
815 { 0x17, HDA_INPUT, 3 },
816 { 0x17, HDA_INPUT, 4 },
821 static int vt1708_parse_auto_config(struct hda_codec *codec)
823 struct via_spec *spec = codec->spec;
826 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
829 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
832 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
833 return 0; /* can't find valid BIOS pin config */
835 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
838 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
841 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
845 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
847 if (spec->autocfg.dig_out_pin)
848 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
849 if (spec->autocfg.dig_in_pin)
850 spec->dig_in_nid = VT1708_DIGIN_NID;
852 if (spec->kctl_alloc)
853 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
855 spec->init_verbs = vt1708_volume_init_verbs;
857 spec->input_mux = &spec->private_imux;
862 /* init callback for auto-configuration model -- overriding the default init */
863 static int via_auto_init(struct hda_codec *codec)
866 via_auto_init_multi_out(codec);
867 via_auto_init_hp_out(codec);
868 via_auto_init_analog_input(codec);
872 static int patch_vt1708(struct hda_codec *codec)
874 struct via_spec *spec;
877 /* create a codec specific record */
878 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
884 /* automatic parse from the BIOS config */
885 err = vt1708_parse_auto_config(codec);
890 printk(KERN_INFO "hda_codec: Cannot set up configuration "
891 "from BIOS. Using genenic mode...\n");
895 spec->stream_name_analog = "VT1708 Analog";
896 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
897 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
899 spec->stream_name_digital = "VT1708 Digital";
900 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
901 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
904 if (!spec->adc_nids && spec->input_mux) {
905 spec->adc_nids = vt1708_adc_nids;
906 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
907 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
911 codec->patch_ops = via_patch_ops;
913 codec->patch_ops.init = via_auto_init;
914 #ifdef CONFIG_SND_HDA_POWER_SAVE
915 spec->loopback.amplist = vt1708_loopbacks;
921 /* capture mixer elements */
922 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
923 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
924 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
925 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
926 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
927 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
928 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
930 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
931 /* The multiple "Capture Source" controls confuse alsamixer
932 * So call somewhat different..
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..
1482 /* .name = "Capture Source", */
1483 .name = "Input Source",
1485 .info = via_mux_enum_info,
1486 .get = via_mux_enum_get,
1487 .put = via_mux_enum_put,
1492 * generic initialization of ADC, input mixers and output mixers
1494 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
1496 * Unmute ADC0-1 and set the default input to mic-in
1498 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1499 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1502 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1505 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1506 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1507 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1508 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1509 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1510 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1513 * Set up output mixers
1515 /* set vol=0 to output mixers */
1516 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1517 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1518 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1520 /* Setup default input to PW4 */
1521 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
1522 /* PW9 Output enable */
1523 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1524 /* PW10 Input enable */
1525 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
1529 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
1531 * Unmute ADC0-1 and set the default input to mic-in
1533 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1534 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1537 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1540 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1541 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1542 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1543 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1544 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1545 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1548 * Set up output mixers
1550 /* set vol=0 to output mixers */
1551 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1552 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1553 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1555 /* Setup default input of PW4 to MW0 */
1556 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
1557 /* PW9 Output enable */
1558 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1559 /* PW10 Input enable */
1560 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
1564 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
1568 .nid = 0x10, /* NID to query formats and rates */
1570 .open = via_playback_pcm_open,
1571 .prepare = via_playback_pcm_prepare,
1572 .cleanup = via_playback_pcm_cleanup
1576 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
1580 .nid = 0x10, /* NID to query formats and rates */
1582 .open = via_playback_pcm_open,
1583 .prepare = via_playback_pcm_prepare,
1584 .cleanup = via_playback_pcm_cleanup
1588 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
1592 .nid = 0x13, /* NID to query formats and rates */
1594 .prepare = via_capture_pcm_prepare,
1595 .cleanup = via_capture_pcm_cleanup
1599 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
1603 /* NID is set in via_build_pcms */
1605 .open = via_dig_playback_pcm_open,
1606 .close = via_dig_playback_pcm_close,
1607 .prepare = via_dig_playback_pcm_prepare
1611 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
1617 /* fill in the dac_nids table from the parsed pin configuration */
1618 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
1619 const struct auto_pin_cfg *cfg)
1624 spec->multiout.num_dacs = cfg->line_outs;
1626 spec->multiout.dac_nids = spec->private_dac_nids;
1628 for (i = 0; i < 4; i++) {
1629 nid = cfg->line_out_pins[i];
1631 /* config dac list */
1633 case AUTO_SEQ_FRONT:
1634 spec->multiout.dac_nids[i] = 0x10;
1636 case AUTO_SEQ_CENLFE:
1637 spec->multiout.dac_nids[i] = 0x24;
1639 case AUTO_SEQ_SURROUND:
1640 spec->multiout.dac_nids[i] = 0x25;
1643 spec->multiout.dac_nids[i] = 0x11;
1652 /* add playback controls from the parsed DAC table */
1653 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
1654 const struct auto_pin_cfg *cfg)
1657 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1658 hda_nid_t nid_vols[] = {0x16, 0x27, 0x26, 0x18};
1659 hda_nid_t nid, nid_vol = 0;
1662 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1663 nid = cfg->line_out_pins[i];
1668 nid_vol = nid_vols[i];
1670 if (i == AUTO_SEQ_CENLFE) {
1672 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1673 "Center Playback Volume",
1674 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1678 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1679 "LFE Playback Volume",
1680 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1684 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1685 "Center Playback Switch",
1686 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1690 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1691 "LFE Playback Switch",
1692 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1696 } else if (i == AUTO_SEQ_FRONT) {
1697 /* add control to mixer index 0 */
1698 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1699 "Master Front Playback Volume",
1700 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1704 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1705 "Master Front Playback Switch",
1706 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1711 /* add control to PW3 */
1712 sprintf(name, "%s Playback Volume", chname[i]);
1713 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1714 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1718 sprintf(name, "%s Playback Switch", chname[i]);
1719 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1720 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1725 sprintf(name, "%s Playback Volume", chname[i]);
1726 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1727 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1731 sprintf(name, "%s Playback Switch", chname[i]);
1732 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1733 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1743 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1750 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
1752 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1753 "Headphone Playback Volume",
1754 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1757 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1758 "Headphone Playback Switch",
1759 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1766 /* create playback/capture controls for input pins */
1767 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
1768 const struct auto_pin_cfg *cfg)
1770 static char *labels[] = {
1771 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1773 struct hda_input_mux *imux = &spec->private_imux;
1774 int i, err, idx = 0;
1776 /* for internal loopback recording select */
1777 imux->items[imux->num_items].label = "Stereo Mixer";
1778 imux->items[imux->num_items].index = idx;
1781 for (i = 0; i < AUTO_PIN_LAST; i++) {
1782 if (!cfg->input_pins[i])
1785 switch (cfg->input_pins[i]) {
1786 case 0x1a: /* Mic */
1790 case 0x1b: /* Line In */
1794 case 0x1e: /* Front Mic */
1802 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1806 imux->items[imux->num_items].label = labels[i];
1807 imux->items[imux->num_items].index = idx;
1813 static int vt1708B_parse_auto_config(struct hda_codec *codec)
1815 struct via_spec *spec = codec->spec;
1818 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1821 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
1824 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1825 return 0; /* can't find valid BIOS pin config */
1827 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
1830 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1833 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
1837 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1839 if (spec->autocfg.dig_out_pin)
1840 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
1841 if (spec->autocfg.dig_in_pin)
1842 spec->dig_in_nid = VT1708B_DIGIN_NID;
1844 if (spec->kctl_alloc)
1845 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1847 spec->input_mux = &spec->private_imux;
1852 #ifdef CONFIG_SND_HDA_POWER_SAVE
1853 static struct hda_amp_list vt1708B_loopbacks[] = {
1854 { 0x16, HDA_INPUT, 1 },
1855 { 0x16, HDA_INPUT, 2 },
1856 { 0x16, HDA_INPUT, 3 },
1857 { 0x16, HDA_INPUT, 4 },
1862 static int patch_vt1708B_8ch(struct hda_codec *codec)
1864 struct via_spec *spec;
1867 /* create a codec specific record */
1868 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1874 /* automatic parse from the BIOS config */
1875 err = vt1708B_parse_auto_config(codec);
1880 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1881 "from BIOS. Using genenic mode...\n");
1884 spec->init_verbs = vt1708B_8ch_volume_init_verbs;
1886 spec->stream_name_analog = "VT1708B Analog";
1887 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
1888 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
1890 spec->stream_name_digital = "VT1708B Digital";
1891 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
1892 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
1894 if (!spec->adc_nids && spec->input_mux) {
1895 spec->adc_nids = vt1708B_adc_nids;
1896 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
1897 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
1901 codec->patch_ops = via_patch_ops;
1903 codec->patch_ops.init = via_auto_init;
1904 #ifdef CONFIG_SND_HDA_POWER_SAVE
1905 spec->loopback.amplist = vt1708B_loopbacks;
1911 static int patch_vt1708B_4ch(struct hda_codec *codec)
1913 struct via_spec *spec;
1916 /* create a codec specific record */
1917 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
1923 /* automatic parse from the BIOS config */
1924 err = vt1708B_parse_auto_config(codec);
1929 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1930 "from BIOS. Using genenic mode...\n");
1933 spec->init_verbs = vt1708B_4ch_volume_init_verbs;
1935 spec->stream_name_analog = "VT1708B Analog";
1936 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
1937 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
1939 spec->stream_name_digital = "VT1708B Digital";
1940 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
1941 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
1943 if (!spec->adc_nids && spec->input_mux) {
1944 spec->adc_nids = vt1708B_adc_nids;
1945 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
1946 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
1950 codec->patch_ops = via_patch_ops;
1952 codec->patch_ops.init = via_auto_init;
1953 #ifdef CONFIG_SND_HDA_POWER_SAVE
1954 spec->loopback.amplist = vt1708B_loopbacks;
1963 struct hda_codec_preset snd_hda_preset_via[] = {
1964 { .id = 0x11061708, .name = "VIA VT1708", .patch = patch_vt1708},
1965 { .id = 0x11061709, .name = "VIA VT1708", .patch = patch_vt1708},
1966 { .id = 0x1106170A, .name = "VIA VT1708", .patch = patch_vt1708},
1967 { .id = 0x1106170B, .name = "VIA VT1708", .patch = patch_vt1708},
1968 { .id = 0x1106E710, .name = "VIA VT1709 10-Ch",
1969 .patch = patch_vt1709_10ch},
1970 { .id = 0x1106E711, .name = "VIA VT1709 10-Ch",
1971 .patch = patch_vt1709_10ch},
1972 { .id = 0x1106E712, .name = "VIA VT1709 10-Ch",
1973 .patch = patch_vt1709_10ch},
1974 { .id = 0x1106E713, .name = "VIA VT1709 10-Ch",
1975 .patch = patch_vt1709_10ch},
1976 { .id = 0x1106E714, .name = "VIA VT1709 6-Ch",
1977 .patch = patch_vt1709_6ch},
1978 { .id = 0x1106E715, .name = "VIA VT1709 6-Ch",
1979 .patch = patch_vt1709_6ch},
1980 { .id = 0x1106E716, .name = "VIA VT1709 6-Ch",
1981 .patch = patch_vt1709_6ch},
1982 { .id = 0x1106E717, .name = "VIA VT1709 6-Ch",
1983 .patch = patch_vt1709_6ch},
1984 { .id = 0x1106E720, .name = "VIA VT1708B 8-Ch",
1985 .patch = patch_vt1708B_8ch},
1986 { .id = 0x1106E721, .name = "VIA VT1708B 8-Ch",
1987 .patch = patch_vt1708B_8ch},
1988 { .id = 0x1106E722, .name = "VIA VT1708B 8-Ch",
1989 .patch = patch_vt1708B_8ch},
1990 { .id = 0x1106E723, .name = "VIA VT1708B 8-Ch",
1991 .patch = patch_vt1708B_8ch},
1992 { .id = 0x1106E724, .name = "VIA VT1708B 4-Ch",
1993 .patch = patch_vt1708B_4ch},
1994 { .id = 0x1106E725, .name = "VIA VT1708B 4-Ch",
1995 .patch = patch_vt1708B_4ch},
1996 { .id = 0x1106E726, .name = "VIA VT1708B 4-Ch",
1997 .patch = patch_vt1708B_4ch},
1998 { .id = 0x1106E727, .name = "VIA VT1708B 4-Ch",
1999 .patch = patch_vt1708B_4ch},