2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
6 * Copyright (c) 2006-2008 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 */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
38 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
41 #include <linux/init.h>
42 #include <linux/delay.h>
43 #include <linux/slab.h>
44 #include <sound/core.h>
45 #include <sound/asoundef.h>
46 #include "hda_codec.h"
47 #include "hda_local.h"
48 #include "hda_patch.h"
51 #define AMP_VAL_IDX_SHIFT 19
52 #define AMP_VAL_IDX_MASK (0x0f<<19)
54 #define NUM_CONTROL_ALLOC 32
55 #define NUM_VERB_ALLOC 32
58 #define VT1708_HP_NID 0x13
59 #define VT1708_DIGOUT_NID 0x14
60 #define VT1708_DIGIN_NID 0x16
61 #define VT1708_DIGIN_PIN 0x26
62 #define VT1708_HP_PIN_NID 0x20
63 #define VT1708_CD_PIN_NID 0x24
65 #define VT1709_HP_DAC_NID 0x28
66 #define VT1709_DIGOUT_NID 0x13
67 #define VT1709_DIGIN_NID 0x17
68 #define VT1709_DIGIN_PIN 0x25
70 #define VT1708B_HP_NID 0x25
71 #define VT1708B_DIGOUT_NID 0x12
72 #define VT1708B_DIGIN_NID 0x15
73 #define VT1708B_DIGIN_PIN 0x21
75 #define VT1708S_HP_NID 0x25
76 #define VT1708S_DIGOUT_NID 0x12
78 #define VT1702_HP_NID 0x17
79 #define VT1702_DIGOUT_NID 0x11
81 #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
82 #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
83 #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
84 #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
85 #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
86 #define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
87 #define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
89 #define VIA_HP_EVENT 0x01
90 #define VIA_GPIO_EVENT 0x02
104 static struct snd_kcontrol_new vt1708_control_templates[] = {
105 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
106 HDA_CODEC_MUTE(NULL, 0, 0, 0),
111 /* codec parameterization */
112 struct snd_kcontrol_new *mixers[3];
113 unsigned int num_mixers;
115 struct hda_verb *init_verbs[5];
116 unsigned int num_iverbs;
118 char *stream_name_analog;
119 struct hda_pcm_stream *stream_analog_playback;
120 struct hda_pcm_stream *stream_analog_capture;
122 char *stream_name_digital;
123 struct hda_pcm_stream *stream_digital_playback;
124 struct hda_pcm_stream *stream_digital_capture;
127 struct hda_multi_out multiout;
130 unsigned int num_adc_nids;
132 hda_nid_t dig_in_nid;
135 const struct hda_input_mux *input_mux;
136 unsigned int cur_mux[3];
138 /* PCM information */
139 struct hda_pcm pcm_rec[2];
141 /* dynamic controls, init_verbs and input_mux */
142 struct auto_pin_cfg autocfg;
143 unsigned int num_kctl_alloc, num_kctl_used;
144 struct snd_kcontrol_new *kctl_alloc;
145 struct hda_input_mux private_imux[2];
146 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
149 const struct hda_input_mux *hp_mux;
150 unsigned int hp_independent_mode;
152 #ifdef CONFIG_SND_HDA_POWER_SAVE
153 struct hda_loopback_check loopback;
157 static hda_nid_t vt1708_adc_nids[2] = {
162 static hda_nid_t vt1709_adc_nids[3] = {
167 static hda_nid_t vt1708B_adc_nids[2] = {
172 static hda_nid_t vt1708S_adc_nids[2] = {
177 static hda_nid_t vt1702_adc_nids[3] = {
182 /* add dynamic controls */
183 static int via_add_control(struct via_spec *spec, int type, const char *name,
186 struct snd_kcontrol_new *knew;
188 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
189 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
191 /* array + terminator */
192 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
195 if (spec->kctl_alloc) {
196 memcpy(knew, spec->kctl_alloc,
197 sizeof(*knew) * spec->num_kctl_alloc);
198 kfree(spec->kctl_alloc);
200 spec->kctl_alloc = knew;
201 spec->num_kctl_alloc = num;
204 knew = &spec->kctl_alloc[spec->num_kctl_used];
205 *knew = vt1708_control_templates[type];
206 knew->name = kstrdup(name, GFP_KERNEL);
210 knew->private_value = val;
211 spec->num_kctl_used++;
215 /* create input playback/capture controls for the given pin */
216 static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
217 const char *ctlname, int idx, int mix_nid)
222 sprintf(name, "%s Playback Volume", ctlname);
223 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
224 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
227 sprintf(name, "%s Playback Switch", ctlname);
228 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
229 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
235 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
236 hda_nid_t nid, int pin_type,
240 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
242 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
247 static void via_auto_init_multi_out(struct hda_codec *codec)
249 struct via_spec *spec = codec->spec;
252 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
253 hda_nid_t nid = spec->autocfg.line_out_pins[i];
255 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
259 static void via_auto_init_hp_out(struct hda_codec *codec)
261 struct via_spec *spec = codec->spec;
264 pin = spec->autocfg.hp_pins[0];
265 if (pin) /* connect to front */
266 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
269 static void via_auto_init_analog_input(struct hda_codec *codec)
271 struct via_spec *spec = codec->spec;
274 for (i = 0; i < AUTO_PIN_LAST; i++) {
275 hda_nid_t nid = spec->autocfg.input_pins[i];
277 snd_hda_codec_write(codec, nid, 0,
278 AC_VERB_SET_PIN_WIDGET_CONTROL,
279 (i <= AUTO_PIN_FRONT_MIC ?
280 PIN_VREF50 : PIN_IN));
287 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
288 struct snd_ctl_elem_info *uinfo)
290 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
291 struct via_spec *spec = codec->spec;
292 return snd_hda_input_mux_info(spec->input_mux, uinfo);
295 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
296 struct snd_ctl_elem_value *ucontrol)
298 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
299 struct via_spec *spec = codec->spec;
300 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
302 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
306 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
307 struct snd_ctl_elem_value *ucontrol)
309 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
310 struct via_spec *spec = codec->spec;
311 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
312 unsigned int vendor_id = codec->vendor_id;
314 /* AIW0 lydia 060801 add for correct sw0 input select */
315 if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0))
316 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
317 0x18, &spec->cur_mux[adc_idx]);
318 else if ((IS_VT1709_10CH_VENDORID(vendor_id) ||
319 IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0))
320 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
321 0x19, &spec->cur_mux[adc_idx]);
322 else if ((IS_VT1708B_8CH_VENDORID(vendor_id) ||
323 IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0))
324 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
325 0x17, &spec->cur_mux[adc_idx]);
326 else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0))
327 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
328 0x13, &spec->cur_mux[adc_idx]);
330 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
331 spec->adc_nids[adc_idx],
332 &spec->cur_mux[adc_idx]);
335 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
336 struct snd_ctl_elem_info *uinfo)
338 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
339 struct via_spec *spec = codec->spec;
340 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
343 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
346 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
347 struct via_spec *spec = codec->spec;
348 hda_nid_t nid = spec->autocfg.hp_pins[0];
349 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
350 AC_VERB_GET_CONNECT_SEL,
353 ucontrol->value.enumerated.item[0] = pinsel;
358 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
359 struct snd_ctl_elem_value *ucontrol)
361 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
362 struct via_spec *spec = codec->spec;
363 hda_nid_t nid = spec->autocfg.hp_pins[0];
364 unsigned int pinsel = ucontrol->value.enumerated.item[0];
365 unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
366 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
368 if (con_nid == spec->multiout.hp_nid) {
370 if (!spec->hp_independent_mode) {
371 if (spec->multiout.num_dacs > 1)
372 spec->multiout.num_dacs -= 1;
373 spec->hp_independent_mode = 1;
375 } else if (pinsel == 1) {
376 if (spec->hp_independent_mode) {
377 if (spec->multiout.num_dacs > 1)
378 spec->multiout.num_dacs += 1;
379 spec->hp_independent_mode = 0;
384 if (spec->hp_independent_mode) {
385 if (spec->multiout.num_dacs > 1)
386 spec->multiout.num_dacs += 1;
387 spec->hp_independent_mode = 0;
389 } else if (pinsel == 1) {
390 if (!spec->hp_independent_mode) {
391 if (spec->multiout.num_dacs > 1)
392 spec->multiout.num_dacs -= 1;
393 spec->hp_independent_mode = 1;
397 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
400 if (spec->multiout.hp_nid &&
401 spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
402 snd_hda_codec_setup_stream(codec,
403 spec->multiout.hp_nid,
409 static struct snd_kcontrol_new via_hp_mixer[] = {
411 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
412 .name = "Independent HP",
414 .info = via_independent_hp_info,
415 .get = via_independent_hp_get,
416 .put = via_independent_hp_put,
421 /* capture mixer elements */
422 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
423 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
424 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
425 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
426 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
428 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
429 /* The multiple "Capture Source" controls confuse alsamixer
430 * So call somewhat different..
432 /* .name = "Capture Source", */
433 .name = "Input Source",
435 .info = via_mux_enum_info,
436 .get = via_mux_enum_get,
437 .put = via_mux_enum_put,
442 * generic initialization of ADC, input mixers and output mixers
444 static struct hda_verb vt1708_volume_init_verbs[] = {
446 * Unmute ADC0-1 and set the default input to mic-in
448 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
449 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
452 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
455 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
456 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
457 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
458 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
459 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
460 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
463 * Set up output mixers (0x19 - 0x1b)
465 /* set vol=0 to output mixers */
466 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
467 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
468 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
470 /* Setup default input to PW4 */
471 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
472 /* PW9 Output enable */
473 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
477 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
478 struct hda_codec *codec,
479 struct snd_pcm_substream *substream)
481 struct via_spec *spec = codec->spec;
482 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
486 static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
487 struct hda_codec *codec,
488 unsigned int stream_tag,
490 struct snd_pcm_substream *substream)
492 struct via_spec *spec = codec->spec;
493 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
494 stream_tag, format, substream);
497 static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
498 struct hda_codec *codec,
499 struct snd_pcm_substream *substream)
501 struct via_spec *spec = codec->spec;
502 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
506 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
507 unsigned int stream_tag,
509 struct snd_pcm_substream *substream)
511 struct via_spec *spec = codec->spec;
512 struct hda_multi_out *mout = &spec->multiout;
513 hda_nid_t *nids = mout->dac_nids;
514 int chs = substream->runtime->channels;
517 mutex_lock(&codec->spdif_mutex);
518 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
520 snd_hda_is_supported_format(codec, mout->dig_out_nid,
522 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
523 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
524 /* turn off SPDIF once; otherwise the IEC958 bits won't
526 if (codec->spdif_ctls & AC_DIG1_ENABLE)
527 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
528 AC_VERB_SET_DIGI_CONVERT_1,
530 ~AC_DIG1_ENABLE & 0xff);
531 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
532 stream_tag, 0, format);
533 /* turn on again (if needed) */
534 if (codec->spdif_ctls & AC_DIG1_ENABLE)
535 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
536 AC_VERB_SET_DIGI_CONVERT_1,
537 codec->spdif_ctls & 0xff);
539 mout->dig_out_used = 0;
540 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
544 mutex_unlock(&codec->spdif_mutex);
547 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
550 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
551 !spec->hp_independent_mode)
552 /* headphone out will just decode front left/right (stereo) */
553 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
556 /* extra outputs copied from front */
557 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
558 if (mout->extra_out_nid[i])
559 snd_hda_codec_setup_stream(codec,
560 mout->extra_out_nid[i],
561 stream_tag, 0, format);
564 for (i = 1; i < mout->num_dacs; i++) {
565 if (chs >= (i + 1) * 2) /* independent out */
566 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
568 else /* copy front */
569 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
574 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
575 struct hda_codec *codec,
576 unsigned int stream_tag,
578 struct snd_pcm_substream *substream)
580 struct via_spec *spec = codec->spec;
581 struct hda_multi_out *mout = &spec->multiout;
582 hda_nid_t *nids = mout->dac_nids;
584 if (substream->number == 0)
585 playback_multi_pcm_prep_0(codec, stream_tag, format,
588 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
589 spec->hp_independent_mode)
590 snd_hda_codec_setup_stream(codec, mout->hp_nid,
591 stream_tag, 0, format);
597 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
598 struct hda_codec *codec,
599 struct snd_pcm_substream *substream)
601 struct via_spec *spec = codec->spec;
602 struct hda_multi_out *mout = &spec->multiout;
603 hda_nid_t *nids = mout->dac_nids;
606 if (substream->number == 0) {
607 for (i = 0; i < mout->num_dacs; i++)
608 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
610 if (mout->hp_nid && !spec->hp_independent_mode)
611 snd_hda_codec_setup_stream(codec, mout->hp_nid,
614 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
615 if (mout->extra_out_nid[i])
616 snd_hda_codec_setup_stream(codec,
617 mout->extra_out_nid[i],
619 mutex_lock(&codec->spdif_mutex);
620 if (mout->dig_out_nid &&
621 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
622 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
624 mout->dig_out_used = 0;
626 mutex_unlock(&codec->spdif_mutex);
628 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
629 spec->hp_independent_mode)
630 snd_hda_codec_setup_stream(codec, mout->hp_nid,
640 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
641 struct hda_codec *codec,
642 struct snd_pcm_substream *substream)
644 struct via_spec *spec = codec->spec;
645 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
648 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
649 struct hda_codec *codec,
650 struct snd_pcm_substream *substream)
652 struct via_spec *spec = codec->spec;
653 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
656 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
657 struct hda_codec *codec,
658 unsigned int stream_tag,
660 struct snd_pcm_substream *substream)
662 struct via_spec *spec = codec->spec;
663 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
664 stream_tag, format, substream);
670 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
671 struct hda_codec *codec,
672 unsigned int stream_tag,
674 struct snd_pcm_substream *substream)
676 struct via_spec *spec = codec->spec;
678 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
679 stream_tag, 0, format);
683 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
684 struct hda_codec *codec,
685 struct snd_pcm_substream *substream)
687 struct via_spec *spec = codec->spec;
688 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
692 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
696 .nid = 0x10, /* NID to query formats and rates */
698 .open = via_playback_pcm_open,
699 .prepare = via_playback_multi_pcm_prepare,
700 .cleanup = via_playback_multi_pcm_cleanup
704 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
708 .nid = 0x10, /* NID to query formats and rates */
709 /* We got noisy outputs on the right channel on VT1708 when
710 * 24bit samples are used. Until any workaround is found,
711 * disable the 24bit format, so far.
713 .formats = SNDRV_PCM_FMTBIT_S16_LE,
715 .open = via_playback_pcm_open,
716 .prepare = via_playback_pcm_prepare,
717 .cleanup = via_playback_pcm_cleanup
721 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
725 .nid = 0x15, /* NID to query formats and rates */
727 .prepare = via_capture_pcm_prepare,
728 .cleanup = via_capture_pcm_cleanup
732 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
736 /* NID is set in via_build_pcms */
738 .open = via_dig_playback_pcm_open,
739 .close = via_dig_playback_pcm_close,
740 .prepare = via_dig_playback_pcm_prepare
744 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
750 static int via_build_controls(struct hda_codec *codec)
752 struct via_spec *spec = codec->spec;
756 for (i = 0; i < spec->num_mixers; i++) {
757 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
762 if (spec->multiout.dig_out_nid) {
763 err = snd_hda_create_spdif_out_ctls(codec,
764 spec->multiout.dig_out_nid);
767 err = snd_hda_create_spdif_share_sw(codec,
771 spec->multiout.share_spdif = 1;
773 if (spec->dig_in_nid) {
774 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
781 static int via_build_pcms(struct hda_codec *codec)
783 struct via_spec *spec = codec->spec;
784 struct hda_pcm *info = spec->pcm_rec;
787 codec->pcm_info = info;
789 info->name = spec->stream_name_analog;
790 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
791 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
792 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
793 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
795 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
796 spec->multiout.max_channels;
798 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
801 info->name = spec->stream_name_digital;
802 info->pcm_type = HDA_PCM_TYPE_SPDIF;
803 if (spec->multiout.dig_out_nid) {
804 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
805 *(spec->stream_digital_playback);
806 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
807 spec->multiout.dig_out_nid;
809 if (spec->dig_in_nid) {
810 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
811 *(spec->stream_digital_capture);
812 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
820 static void via_free(struct hda_codec *codec)
822 struct via_spec *spec = codec->spec;
828 if (spec->kctl_alloc) {
829 for (i = 0; i < spec->num_kctl_used; i++)
830 kfree(spec->kctl_alloc[i].name);
831 kfree(spec->kctl_alloc);
837 /* mute internal speaker if HP is plugged */
838 static void via_hp_automute(struct hda_codec *codec)
840 unsigned int present;
841 struct via_spec *spec = codec->spec;
843 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
844 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
845 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
846 HDA_OUTPUT, 0, HDA_AMP_MUTE,
847 present ? HDA_AMP_MUTE : 0);
850 static void via_gpio_control(struct hda_codec *codec)
852 unsigned int gpio_data;
853 unsigned int vol_counter;
855 unsigned int master_vol;
857 struct via_spec *spec = codec->spec;
859 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
860 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
862 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
863 0xF84, 0) & 0x3F0000) >> 16;
865 vol = vol_counter & 0x1F;
866 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
867 AC_VERB_GET_AMP_GAIN_MUTE,
870 if (gpio_data == 0x02) {
871 /* unmute line out */
872 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
873 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
875 if (vol_counter & 0x20) {
876 /* decrease volume */
877 if (vol > master_vol)
879 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
883 /* increase volume */
884 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
886 ((master_vol+vol) > 0x2A) ? 0x2A :
889 } else if (!(gpio_data & 0x02)) {
891 snd_hda_codec_amp_stereo(codec,
892 spec->autocfg.line_out_pins[0],
893 HDA_OUTPUT, 0, HDA_AMP_MUTE,
898 /* unsolicited event for jack sensing */
899 static void via_unsol_event(struct hda_codec *codec,
903 if (res == VIA_HP_EVENT)
904 via_hp_automute(codec);
905 else if (res == VIA_GPIO_EVENT)
906 via_gpio_control(codec);
909 static int via_init(struct hda_codec *codec)
911 struct via_spec *spec = codec->spec;
913 for (i = 0; i < spec->num_iverbs; i++)
914 snd_hda_sequence_write(codec, spec->init_verbs[i]);
916 /* Lydia Add for EAPD enable */
917 if (!spec->dig_in_nid) { /* No Digital In connection */
918 if (IS_VT1708_VENDORID(codec->vendor_id)) {
919 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
920 AC_VERB_SET_PIN_WIDGET_CONTROL,
922 snd_hda_codec_write(codec, VT1708_DIGIN_PIN, 0,
923 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
924 } else if (IS_VT1709_10CH_VENDORID(codec->vendor_id) ||
925 IS_VT1709_6CH_VENDORID(codec->vendor_id)) {
926 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
927 AC_VERB_SET_PIN_WIDGET_CONTROL,
929 snd_hda_codec_write(codec, VT1709_DIGIN_PIN, 0,
930 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
931 } else if (IS_VT1708B_8CH_VENDORID(codec->vendor_id) ||
932 IS_VT1708B_4CH_VENDORID(codec->vendor_id)) {
933 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
934 AC_VERB_SET_PIN_WIDGET_CONTROL,
936 snd_hda_codec_write(codec, VT1708B_DIGIN_PIN, 0,
937 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
939 } else /* enable SPDIF-input pin */
940 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
941 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
946 #ifdef CONFIG_SND_HDA_POWER_SAVE
947 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
949 struct via_spec *spec = codec->spec;
950 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
956 static struct hda_codec_ops via_patch_ops = {
957 .build_controls = via_build_controls,
958 .build_pcms = via_build_pcms,
961 #ifdef CONFIG_SND_HDA_POWER_SAVE
962 .check_power_status = via_check_power_status,
966 /* fill in the dac_nids table from the parsed pin configuration */
967 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
968 const struct auto_pin_cfg *cfg)
973 spec->multiout.num_dacs = cfg->line_outs;
975 spec->multiout.dac_nids = spec->private_dac_nids;
977 for(i = 0; i < 4; i++) {
978 nid = cfg->line_out_pins[i];
980 /* config dac list */
983 spec->multiout.dac_nids[i] = 0x10;
985 case AUTO_SEQ_CENLFE:
986 spec->multiout.dac_nids[i] = 0x12;
988 case AUTO_SEQ_SURROUND:
989 spec->multiout.dac_nids[i] = 0x11;
992 spec->multiout.dac_nids[i] = 0x13;
1001 /* add playback controls from the parsed DAC table */
1002 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1003 const struct auto_pin_cfg *cfg)
1006 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1007 hda_nid_t nid, nid_vol = 0;
1010 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1011 nid = cfg->line_out_pins[i];
1016 if (i != AUTO_SEQ_FRONT)
1019 if (i == AUTO_SEQ_CENLFE) {
1021 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1022 "Center Playback Volume",
1023 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1027 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1028 "LFE Playback Volume",
1029 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1033 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1034 "Center Playback Switch",
1035 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1039 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1040 "LFE Playback Switch",
1041 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1045 } else if (i == AUTO_SEQ_FRONT){
1046 /* add control to mixer index 0 */
1047 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1048 "Master Front Playback Volume",
1049 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1053 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1054 "Master Front Playback Switch",
1055 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1060 /* add control to PW3 */
1061 sprintf(name, "%s Playback Volume", chname[i]);
1062 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1063 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1067 sprintf(name, "%s Playback Switch", chname[i]);
1068 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1069 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1074 sprintf(name, "%s Playback Volume", chname[i]);
1075 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1076 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1080 sprintf(name, "%s Playback Switch", chname[i]);
1081 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1082 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1092 static void create_hp_imux(struct via_spec *spec)
1095 struct hda_input_mux *imux = &spec->private_imux[1];
1096 static const char *texts[] = { "OFF", "ON", NULL};
1098 /* for hp mode select */
1100 while (texts[i] != NULL) {
1101 imux->items[imux->num_items].label = texts[i];
1102 imux->items[imux->num_items].index = i;
1107 spec->hp_mux = &spec->private_imux[1];
1110 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1117 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1119 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1120 "Headphone Playback Volume",
1121 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1124 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1125 "Headphone Playback Switch",
1126 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1130 create_hp_imux(spec);
1135 /* create playback/capture controls for input pins */
1136 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1137 const struct auto_pin_cfg *cfg)
1139 static char *labels[] = {
1140 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1142 struct hda_input_mux *imux = &spec->private_imux[0];
1143 int i, err, idx = 0;
1145 /* for internal loopback recording select */
1146 imux->items[imux->num_items].label = "Stereo Mixer";
1147 imux->items[imux->num_items].index = idx;
1150 for (i = 0; i < AUTO_PIN_LAST; i++) {
1151 if (!cfg->input_pins[i])
1154 switch (cfg->input_pins[i]) {
1155 case 0x1d: /* Mic */
1159 case 0x1e: /* Line In */
1163 case 0x21: /* Front Mic */
1171 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1175 imux->items[imux->num_items].label = labels[i];
1176 imux->items[imux->num_items].index = idx;
1182 #ifdef CONFIG_SND_HDA_POWER_SAVE
1183 static struct hda_amp_list vt1708_loopbacks[] = {
1184 { 0x17, HDA_INPUT, 1 },
1185 { 0x17, HDA_INPUT, 2 },
1186 { 0x17, HDA_INPUT, 3 },
1187 { 0x17, HDA_INPUT, 4 },
1192 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1194 unsigned int def_conf;
1195 unsigned char seqassoc;
1197 def_conf = snd_hda_codec_read(codec, nid, 0,
1198 AC_VERB_GET_CONFIG_DEFAULT, 0);
1199 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1200 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1201 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1202 if (seqassoc == 0xff) {
1203 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1204 snd_hda_codec_write(codec, nid, 0,
1205 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1213 static int vt1708_parse_auto_config(struct hda_codec *codec)
1215 struct via_spec *spec = codec->spec;
1218 /* Add HP and CD pin config connect bit re-config action */
1219 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
1220 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
1222 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1225 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
1228 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1229 return 0; /* can't find valid BIOS pin config */
1231 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
1234 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1237 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1241 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1243 if (spec->autocfg.dig_out_pin)
1244 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
1245 if (spec->autocfg.dig_in_pin)
1246 spec->dig_in_nid = VT1708_DIGIN_NID;
1248 if (spec->kctl_alloc)
1249 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1251 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
1253 spec->input_mux = &spec->private_imux[0];
1255 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1260 /* init callback for auto-configuration model -- overriding the default init */
1261 static int via_auto_init(struct hda_codec *codec)
1264 via_auto_init_multi_out(codec);
1265 via_auto_init_hp_out(codec);
1266 via_auto_init_analog_input(codec);
1270 static int patch_vt1708(struct hda_codec *codec)
1272 struct via_spec *spec;
1275 /* create a codec specific record */
1276 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1282 /* automatic parse from the BIOS config */
1283 err = vt1708_parse_auto_config(codec);
1288 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1289 "from BIOS. Using genenic mode...\n");
1293 spec->stream_name_analog = "VT1708 Analog";
1294 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1295 /* disable 32bit format on VT1708 */
1296 if (codec->vendor_id == 0x11061708)
1297 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
1298 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
1300 spec->stream_name_digital = "VT1708 Digital";
1301 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1302 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1305 if (!spec->adc_nids && spec->input_mux) {
1306 spec->adc_nids = vt1708_adc_nids;
1307 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1308 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1312 codec->patch_ops = via_patch_ops;
1314 codec->patch_ops.init = via_auto_init;
1315 #ifdef CONFIG_SND_HDA_POWER_SAVE
1316 spec->loopback.amplist = vt1708_loopbacks;
1322 /* capture mixer elements */
1323 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1324 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
1325 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
1326 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
1327 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
1328 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
1329 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
1331 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1332 /* The multiple "Capture Source" controls confuse alsamixer
1333 * So call somewhat different..
1335 /* .name = "Capture Source", */
1336 .name = "Input Source",
1338 .info = via_mux_enum_info,
1339 .get = via_mux_enum_get,
1340 .put = via_mux_enum_put,
1345 static struct hda_verb vt1709_uniwill_init_verbs[] = {
1346 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1351 * generic initialization of ADC, input mixers and output mixers
1353 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1355 * Unmute ADC0-2 and set the default input to mic-in
1357 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1358 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1359 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1362 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1365 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1366 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1367 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1368 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1369 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1370 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1373 * Set up output selector (0x1a, 0x1b, 0x29)
1375 /* set vol=0 to output mixers */
1376 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1377 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1378 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1381 * Unmute PW3 and PW4
1383 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1384 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1386 /* Set input of PW4 as AOW4 */
1387 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
1388 /* PW9 Output enable */
1389 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1393 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1397 .nid = 0x10, /* NID to query formats and rates */
1399 .open = via_playback_pcm_open,
1400 .prepare = via_playback_pcm_prepare,
1401 .cleanup = via_playback_pcm_cleanup
1405 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1409 .nid = 0x10, /* NID to query formats and rates */
1411 .open = via_playback_pcm_open,
1412 .prepare = via_playback_pcm_prepare,
1413 .cleanup = via_playback_pcm_cleanup
1417 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1421 .nid = 0x14, /* NID to query formats and rates */
1423 .prepare = via_capture_pcm_prepare,
1424 .cleanup = via_capture_pcm_cleanup
1428 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1432 /* NID is set in via_build_pcms */
1434 .open = via_dig_playback_pcm_open,
1435 .close = via_dig_playback_pcm_close
1439 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1445 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1446 const struct auto_pin_cfg *cfg)
1451 if (cfg->line_outs == 4) /* 10 channels */
1452 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1453 else if (cfg->line_outs == 3) /* 6 channels */
1454 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1456 spec->multiout.dac_nids = spec->private_dac_nids;
1458 if (cfg->line_outs == 4) { /* 10 channels */
1459 for (i = 0; i < cfg->line_outs; i++) {
1460 nid = cfg->line_out_pins[i];
1462 /* config dac list */
1464 case AUTO_SEQ_FRONT:
1466 spec->multiout.dac_nids[i] = 0x10;
1468 case AUTO_SEQ_CENLFE:
1470 spec->multiout.dac_nids[i] = 0x12;
1472 case AUTO_SEQ_SURROUND:
1474 spec->multiout.dac_nids[i] = 0x11;
1478 spec->multiout.dac_nids[i] = 0x27;
1485 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
1487 } else if (cfg->line_outs == 3) { /* 6 channels */
1488 for(i = 0; i < cfg->line_outs; i++) {
1489 nid = cfg->line_out_pins[i];
1491 /* config dac list */
1493 case AUTO_SEQ_FRONT:
1495 spec->multiout.dac_nids[i] = 0x10;
1497 case AUTO_SEQ_CENLFE:
1499 spec->multiout.dac_nids[i] = 0x12;
1501 case AUTO_SEQ_SURROUND:
1503 spec->multiout.dac_nids[i] = 0x11;
1515 /* add playback controls from the parsed DAC table */
1516 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
1517 const struct auto_pin_cfg *cfg)
1520 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1524 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1525 nid = cfg->line_out_pins[i];
1530 if (i == AUTO_SEQ_CENLFE) {
1532 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1533 "Center Playback Volume",
1534 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1538 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1539 "LFE Playback Volume",
1540 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1544 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1545 "Center Playback Switch",
1546 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
1550 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1551 "LFE Playback Switch",
1552 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
1556 } else if (i == AUTO_SEQ_FRONT){
1557 /* add control to mixer index 0 */
1558 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1559 "Master Front Playback Volume",
1560 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1564 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1565 "Master Front Playback Switch",
1566 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
1571 /* add control to PW3 */
1572 sprintf(name, "%s Playback Volume", chname[i]);
1573 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1574 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1578 sprintf(name, "%s Playback Switch", chname[i]);
1579 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1580 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1584 } else if (i == AUTO_SEQ_SURROUND) {
1585 sprintf(name, "%s Playback Volume", chname[i]);
1586 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1587 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1591 sprintf(name, "%s Playback Switch", chname[i]);
1592 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1593 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
1597 } else if (i == AUTO_SEQ_SIDE) {
1598 sprintf(name, "%s Playback Volume", chname[i]);
1599 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1600 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1604 sprintf(name, "%s Playback Switch", chname[i]);
1605 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1606 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
1616 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1623 if (spec->multiout.num_dacs == 5) /* 10 channels */
1624 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
1625 else if (spec->multiout.num_dacs == 3) /* 6 channels */
1626 spec->multiout.hp_nid = 0;
1628 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1629 "Headphone Playback Volume",
1630 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1633 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1634 "Headphone Playback Switch",
1635 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1642 /* create playback/capture controls for input pins */
1643 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
1644 const struct auto_pin_cfg *cfg)
1646 static char *labels[] = {
1647 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1649 struct hda_input_mux *imux = &spec->private_imux[0];
1650 int i, err, idx = 0;
1652 /* for internal loopback recording select */
1653 imux->items[imux->num_items].label = "Stereo Mixer";
1654 imux->items[imux->num_items].index = idx;
1657 for (i = 0; i < AUTO_PIN_LAST; i++) {
1658 if (!cfg->input_pins[i])
1661 switch (cfg->input_pins[i]) {
1662 case 0x1d: /* Mic */
1666 case 0x1e: /* Line In */
1670 case 0x21: /* Front Mic */
1678 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
1682 imux->items[imux->num_items].label = labels[i];
1683 imux->items[imux->num_items].index = idx;
1689 static int vt1709_parse_auto_config(struct hda_codec *codec)
1691 struct via_spec *spec = codec->spec;
1694 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1697 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
1700 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1701 return 0; /* can't find valid BIOS pin config */
1703 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
1706 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1709 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
1713 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1715 if (spec->autocfg.dig_out_pin)
1716 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1717 if (spec->autocfg.dig_in_pin)
1718 spec->dig_in_nid = VT1709_DIGIN_NID;
1720 if (spec->kctl_alloc)
1721 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
1723 spec->input_mux = &spec->private_imux[0];
1728 #ifdef CONFIG_SND_HDA_POWER_SAVE
1729 static struct hda_amp_list vt1709_loopbacks[] = {
1730 { 0x18, HDA_INPUT, 1 },
1731 { 0x18, HDA_INPUT, 2 },
1732 { 0x18, HDA_INPUT, 3 },
1733 { 0x18, HDA_INPUT, 4 },
1738 static int patch_vt1709_10ch(struct hda_codec *codec)
1740 struct via_spec *spec;
1743 /* create a codec specific record */
1744 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1750 err = vt1709_parse_auto_config(codec);
1755 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1756 "Using genenic mode...\n");
1759 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
1760 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1762 spec->stream_name_analog = "VT1709 Analog";
1763 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
1764 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1766 spec->stream_name_digital = "VT1709 Digital";
1767 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1768 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1771 if (!spec->adc_nids && spec->input_mux) {
1772 spec->adc_nids = vt1709_adc_nids;
1773 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1774 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1778 codec->patch_ops = via_patch_ops;
1780 codec->patch_ops.init = via_auto_init;
1781 codec->patch_ops.unsol_event = via_unsol_event;
1782 #ifdef CONFIG_SND_HDA_POWER_SAVE
1783 spec->loopback.amplist = vt1709_loopbacks;
1789 * generic initialization of ADC, input mixers and output mixers
1791 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
1793 * Unmute ADC0-2 and set the default input to mic-in
1795 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1796 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1797 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1800 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1803 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1804 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1805 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1806 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1807 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1808 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1811 * Set up output selector (0x1a, 0x1b, 0x29)
1813 /* set vol=0 to output mixers */
1814 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1815 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1816 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1819 * Unmute PW3 and PW4
1821 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1822 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1824 /* Set input of PW4 as MW0 */
1825 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1826 /* PW9 Output enable */
1827 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1831 static int patch_vt1709_6ch(struct hda_codec *codec)
1833 struct via_spec *spec;
1836 /* create a codec specific record */
1837 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1843 err = vt1709_parse_auto_config(codec);
1848 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
1849 "Using genenic mode...\n");
1852 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
1853 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
1855 spec->stream_name_analog = "VT1709 Analog";
1856 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
1857 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
1859 spec->stream_name_digital = "VT1709 Digital";
1860 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
1861 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
1864 if (!spec->adc_nids && spec->input_mux) {
1865 spec->adc_nids = vt1709_adc_nids;
1866 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
1867 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
1871 codec->patch_ops = via_patch_ops;
1873 codec->patch_ops.init = via_auto_init;
1874 codec->patch_ops.unsol_event = via_unsol_event;
1875 #ifdef CONFIG_SND_HDA_POWER_SAVE
1876 spec->loopback.amplist = vt1709_loopbacks;
1881 /* capture mixer elements */
1882 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
1883 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
1884 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
1885 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
1886 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
1888 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1889 /* The multiple "Capture Source" controls confuse alsamixer
1890 * So call somewhat different..
1892 /* .name = "Capture Source", */
1893 .name = "Input Source",
1895 .info = via_mux_enum_info,
1896 .get = via_mux_enum_get,
1897 .put = via_mux_enum_put,
1902 * generic initialization of ADC, input mixers and output mixers
1904 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
1906 * Unmute ADC0-1 and set the default input to mic-in
1908 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1909 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1912 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1915 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1916 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1917 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1918 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1919 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1920 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1923 * Set up output mixers
1925 /* set vol=0 to output mixers */
1926 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1927 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1928 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1930 /* Setup default input to PW4 */
1931 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
1932 /* PW9 Output enable */
1933 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1934 /* PW10 Input enable */
1935 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
1939 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
1941 * Unmute ADC0-1 and set the default input to mic-in
1943 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1944 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1947 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1950 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1951 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1952 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1953 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1954 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1955 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1958 * Set up output mixers
1960 /* set vol=0 to output mixers */
1961 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1962 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1963 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1965 /* Setup default input of PW4 to MW0 */
1966 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
1967 /* PW9 Output enable */
1968 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1969 /* PW10 Input enable */
1970 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
1974 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
1975 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1979 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
1983 .nid = 0x10, /* NID to query formats and rates */
1985 .open = via_playback_pcm_open,
1986 .prepare = via_playback_multi_pcm_prepare,
1987 .cleanup = via_playback_multi_pcm_cleanup
1991 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
1995 .nid = 0x10, /* NID to query formats and rates */
1997 .open = via_playback_pcm_open,
1998 .prepare = via_playback_multi_pcm_prepare,
1999 .cleanup = via_playback_multi_pcm_cleanup
2003 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2007 .nid = 0x13, /* NID to query formats and rates */
2009 .prepare = via_capture_pcm_prepare,
2010 .cleanup = via_capture_pcm_cleanup
2014 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2018 /* NID is set in via_build_pcms */
2020 .open = via_dig_playback_pcm_open,
2021 .close = via_dig_playback_pcm_close,
2022 .prepare = via_dig_playback_pcm_prepare
2026 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2032 /* fill in the dac_nids table from the parsed pin configuration */
2033 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2034 const struct auto_pin_cfg *cfg)
2039 spec->multiout.num_dacs = cfg->line_outs;
2041 spec->multiout.dac_nids = spec->private_dac_nids;
2043 for (i = 0; i < 4; i++) {
2044 nid = cfg->line_out_pins[i];
2046 /* config dac list */
2048 case AUTO_SEQ_FRONT:
2049 spec->multiout.dac_nids[i] = 0x10;
2051 case AUTO_SEQ_CENLFE:
2052 spec->multiout.dac_nids[i] = 0x24;
2054 case AUTO_SEQ_SURROUND:
2055 spec->multiout.dac_nids[i] = 0x11;
2058 spec->multiout.dac_nids[i] = 0x25;
2067 /* add playback controls from the parsed DAC table */
2068 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
2069 const struct auto_pin_cfg *cfg)
2072 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2073 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
2074 hda_nid_t nid, nid_vol = 0;
2077 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2078 nid = cfg->line_out_pins[i];
2083 nid_vol = nid_vols[i];
2085 if (i == AUTO_SEQ_CENLFE) {
2087 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2088 "Center Playback Volume",
2089 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2093 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2094 "LFE Playback Volume",
2095 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2099 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2100 "Center Playback Switch",
2101 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2105 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2106 "LFE Playback Switch",
2107 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2111 } else if (i == AUTO_SEQ_FRONT) {
2112 /* add control to mixer index 0 */
2113 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2114 "Master Front Playback Volume",
2115 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2119 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2120 "Master Front Playback Switch",
2121 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2126 /* add control to PW3 */
2127 sprintf(name, "%s Playback Volume", chname[i]);
2128 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2129 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2133 sprintf(name, "%s Playback Switch", chname[i]);
2134 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2135 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2140 sprintf(name, "%s Playback Volume", chname[i]);
2141 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2142 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2146 sprintf(name, "%s Playback Switch", chname[i]);
2147 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2148 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2158 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2165 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
2167 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2168 "Headphone Playback Volume",
2169 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2172 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2173 "Headphone Playback Switch",
2174 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2178 create_hp_imux(spec);
2183 /* create playback/capture controls for input pins */
2184 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2185 const struct auto_pin_cfg *cfg)
2187 static char *labels[] = {
2188 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2190 struct hda_input_mux *imux = &spec->private_imux[0];
2191 int i, err, idx = 0;
2193 /* for internal loopback recording select */
2194 imux->items[imux->num_items].label = "Stereo Mixer";
2195 imux->items[imux->num_items].index = idx;
2198 for (i = 0; i < AUTO_PIN_LAST; i++) {
2199 if (!cfg->input_pins[i])
2202 switch (cfg->input_pins[i]) {
2203 case 0x1a: /* Mic */
2207 case 0x1b: /* Line In */
2211 case 0x1e: /* Front Mic */
2219 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2223 imux->items[imux->num_items].label = labels[i];
2224 imux->items[imux->num_items].index = idx;
2230 static int vt1708B_parse_auto_config(struct hda_codec *codec)
2232 struct via_spec *spec = codec->spec;
2235 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2238 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
2241 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2242 return 0; /* can't find valid BIOS pin config */
2244 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
2247 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2250 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
2254 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2256 if (spec->autocfg.dig_out_pin)
2257 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2258 if (spec->autocfg.dig_in_pin)
2259 spec->dig_in_nid = VT1708B_DIGIN_NID;
2261 if (spec->kctl_alloc)
2262 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2264 spec->input_mux = &spec->private_imux[0];
2266 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2271 #ifdef CONFIG_SND_HDA_POWER_SAVE
2272 static struct hda_amp_list vt1708B_loopbacks[] = {
2273 { 0x16, HDA_INPUT, 1 },
2274 { 0x16, HDA_INPUT, 2 },
2275 { 0x16, HDA_INPUT, 3 },
2276 { 0x16, HDA_INPUT, 4 },
2281 static int patch_vt1708B_8ch(struct hda_codec *codec)
2283 struct via_spec *spec;
2286 /* create a codec specific record */
2287 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2293 /* automatic parse from the BIOS config */
2294 err = vt1708B_parse_auto_config(codec);
2299 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2300 "from BIOS. Using genenic mode...\n");
2303 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2304 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2306 spec->stream_name_analog = "VT1708B Analog";
2307 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
2308 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2310 spec->stream_name_digital = "VT1708B Digital";
2311 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2312 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2314 if (!spec->adc_nids && spec->input_mux) {
2315 spec->adc_nids = vt1708B_adc_nids;
2316 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2317 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2321 codec->patch_ops = via_patch_ops;
2323 codec->patch_ops.init = via_auto_init;
2324 codec->patch_ops.unsol_event = via_unsol_event;
2325 #ifdef CONFIG_SND_HDA_POWER_SAVE
2326 spec->loopback.amplist = vt1708B_loopbacks;
2332 static int patch_vt1708B_4ch(struct hda_codec *codec)
2334 struct via_spec *spec;
2337 /* create a codec specific record */
2338 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2344 /* automatic parse from the BIOS config */
2345 err = vt1708B_parse_auto_config(codec);
2350 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2351 "from BIOS. Using genenic mode...\n");
2354 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2355 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2357 spec->stream_name_analog = "VT1708B Analog";
2358 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
2359 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2361 spec->stream_name_digital = "VT1708B Digital";
2362 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2363 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2365 if (!spec->adc_nids && spec->input_mux) {
2366 spec->adc_nids = vt1708B_adc_nids;
2367 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2368 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2372 codec->patch_ops = via_patch_ops;
2374 codec->patch_ops.init = via_auto_init;
2375 codec->patch_ops.unsol_event = via_unsol_event;
2376 #ifdef CONFIG_SND_HDA_POWER_SAVE
2377 spec->loopback.amplist = vt1708B_loopbacks;
2383 /* Patch for VT1708S */
2385 /* capture mixer elements */
2386 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2387 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2388 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2389 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2390 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2391 HDA_CODEC_VOLUME("Mic Boost", 0x1A, 0x0, HDA_INPUT),
2392 HDA_CODEC_VOLUME("Front Mic Boost", 0x1E, 0x0, HDA_INPUT),
2394 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2395 /* The multiple "Capture Source" controls confuse alsamixer
2396 * So call somewhat different..
2398 /* .name = "Capture Source", */
2399 .name = "Input Source",
2401 .info = via_mux_enum_info,
2402 .get = via_mux_enum_get,
2403 .put = via_mux_enum_put,
2408 static struct hda_verb vt1708S_volume_init_verbs[] = {
2409 /* Unmute ADC0-1 and set the default input to mic-in */
2410 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2411 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2413 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2414 * analog-loopback mixer widget */
2415 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2416 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2417 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2418 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2419 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2420 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2422 /* Setup default input of PW4 to MW0 */
2423 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2424 /* PW9 Output enable */
2425 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2429 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
2430 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2434 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
2438 .nid = 0x10, /* NID to query formats and rates */
2440 .open = via_playback_pcm_open,
2441 .prepare = via_playback_pcm_prepare,
2442 .cleanup = via_playback_pcm_cleanup
2446 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
2450 .nid = 0x13, /* NID to query formats and rates */
2452 .prepare = via_capture_pcm_prepare,
2453 .cleanup = via_capture_pcm_cleanup
2457 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
2461 /* NID is set in via_build_pcms */
2463 .open = via_dig_playback_pcm_open,
2464 .close = via_dig_playback_pcm_close,
2465 .prepare = via_dig_playback_pcm_prepare
2469 /* fill in the dac_nids table from the parsed pin configuration */
2470 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
2471 const struct auto_pin_cfg *cfg)
2476 spec->multiout.num_dacs = cfg->line_outs;
2478 spec->multiout.dac_nids = spec->private_dac_nids;
2480 for (i = 0; i < 4; i++) {
2481 nid = cfg->line_out_pins[i];
2483 /* config dac list */
2485 case AUTO_SEQ_FRONT:
2486 spec->multiout.dac_nids[i] = 0x10;
2488 case AUTO_SEQ_CENLFE:
2489 spec->multiout.dac_nids[i] = 0x24;
2491 case AUTO_SEQ_SURROUND:
2492 spec->multiout.dac_nids[i] = 0x11;
2495 spec->multiout.dac_nids[i] = 0x25;
2504 /* add playback controls from the parsed DAC table */
2505 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
2506 const struct auto_pin_cfg *cfg)
2509 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2510 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
2511 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
2512 hda_nid_t nid, nid_vol, nid_mute;
2515 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2516 nid = cfg->line_out_pins[i];
2521 nid_vol = nid_vols[i];
2522 nid_mute = nid_mutes[i];
2524 if (i == AUTO_SEQ_CENLFE) {
2526 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2527 "Center Playback Volume",
2528 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2532 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2533 "LFE Playback Volume",
2534 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2538 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2539 "Center Playback Switch",
2540 HDA_COMPOSE_AMP_VAL(nid_mute,
2545 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2546 "LFE Playback Switch",
2547 HDA_COMPOSE_AMP_VAL(nid_mute,
2552 } else if (i == AUTO_SEQ_FRONT) {
2553 /* add control to mixer index 0 */
2554 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2555 "Master Front Playback Volume",
2556 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2560 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2561 "Master Front Playback Switch",
2562 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
2568 sprintf(name, "%s Playback Volume", chname[i]);
2569 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2570 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2574 sprintf(name, "%s Playback Switch", chname[i]);
2575 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2576 HDA_COMPOSE_AMP_VAL(nid_mute,
2582 sprintf(name, "%s Playback Volume", chname[i]);
2583 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2584 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2588 sprintf(name, "%s Playback Switch", chname[i]);
2589 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2590 HDA_COMPOSE_AMP_VAL(nid_mute,
2601 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2608 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
2610 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2611 "Headphone Playback Volume",
2612 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
2616 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2617 "Headphone Playback Switch",
2618 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2622 create_hp_imux(spec);
2627 /* create playback/capture controls for input pins */
2628 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
2629 const struct auto_pin_cfg *cfg)
2631 static char *labels[] = {
2632 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2634 struct hda_input_mux *imux = &spec->private_imux[0];
2635 int i, err, idx = 0;
2637 /* for internal loopback recording select */
2638 imux->items[imux->num_items].label = "Stereo Mixer";
2639 imux->items[imux->num_items].index = 5;
2642 for (i = 0; i < AUTO_PIN_LAST; i++) {
2643 if (!cfg->input_pins[i])
2646 switch (cfg->input_pins[i]) {
2647 case 0x1a: /* Mic */
2651 case 0x1b: /* Line In */
2655 case 0x1e: /* Front Mic */
2663 err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
2667 imux->items[imux->num_items].label = labels[i];
2668 imux->items[imux->num_items].index = idx-1;
2674 static int vt1708S_parse_auto_config(struct hda_codec *codec)
2676 struct via_spec *spec = codec->spec;
2678 static hda_nid_t vt1708s_ignore[] = {0x21, 0};
2680 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
2684 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
2687 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2688 return 0; /* can't find valid BIOS pin config */
2690 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
2693 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2696 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
2700 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2702 if (spec->autocfg.dig_out_pin)
2703 spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID;
2705 if (spec->kctl_alloc)
2706 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2708 spec->input_mux = &spec->private_imux[0];
2710 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2715 #ifdef CONFIG_SND_HDA_POWER_SAVE
2716 static struct hda_amp_list vt1708S_loopbacks[] = {
2717 { 0x16, HDA_INPUT, 1 },
2718 { 0x16, HDA_INPUT, 2 },
2719 { 0x16, HDA_INPUT, 3 },
2720 { 0x16, HDA_INPUT, 4 },
2725 static int patch_vt1708S(struct hda_codec *codec)
2727 struct via_spec *spec;
2730 /* create a codec specific record */
2731 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2737 /* automatic parse from the BIOS config */
2738 err = vt1708S_parse_auto_config(codec);
2743 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2744 "from BIOS. Using genenic mode...\n");
2747 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
2748 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
2750 spec->stream_name_analog = "VT1708S Analog";
2751 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
2752 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
2754 spec->stream_name_digital = "VT1708S Digital";
2755 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
2757 if (!spec->adc_nids && spec->input_mux) {
2758 spec->adc_nids = vt1708S_adc_nids;
2759 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
2760 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
2764 codec->patch_ops = via_patch_ops;
2766 codec->patch_ops.init = via_auto_init;
2767 codec->patch_ops.unsol_event = via_unsol_event;
2768 #ifdef CONFIG_SND_HDA_POWER_SAVE
2769 spec->loopback.amplist = vt1708S_loopbacks;
2775 /* Patch for VT1702 */
2777 /* capture mixer elements */
2778 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
2779 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
2780 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
2781 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
2782 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
2783 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
2784 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
2785 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
2788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2789 /* The multiple "Capture Source" controls confuse alsamixer
2790 * So call somewhat different..
2792 /* .name = "Capture Source", */
2793 .name = "Input Source",
2795 .info = via_mux_enum_info,
2796 .get = via_mux_enum_get,
2797 .put = via_mux_enum_put,
2802 static struct hda_verb vt1702_volume_init_verbs[] = {
2804 * Unmute ADC0-1 and set the default input to mic-in
2806 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2807 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2808 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2811 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2814 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
2815 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2816 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2817 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2818 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2819 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2821 /* Setup default input of PW4 to MW0 */
2822 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
2823 /* PW6 PW7 Output enable */
2824 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2825 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2829 static struct hda_verb vt1702_uniwill_init_verbs[] = {
2830 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
2831 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2835 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
2839 .nid = 0x10, /* NID to query formats and rates */
2841 .open = via_playback_pcm_open,
2842 .prepare = via_playback_multi_pcm_prepare,
2843 .cleanup = via_playback_multi_pcm_cleanup
2847 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
2851 .nid = 0x12, /* NID to query formats and rates */
2853 .prepare = via_capture_pcm_prepare,
2854 .cleanup = via_capture_pcm_cleanup
2858 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
2862 /* NID is set in via_build_pcms */
2864 .open = via_dig_playback_pcm_open,
2865 .close = via_dig_playback_pcm_close,
2866 .prepare = via_dig_playback_pcm_prepare
2870 /* fill in the dac_nids table from the parsed pin configuration */
2871 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
2872 const struct auto_pin_cfg *cfg)
2874 spec->multiout.num_dacs = 1;
2875 spec->multiout.dac_nids = spec->private_dac_nids;
2877 if (cfg->line_out_pins[0]) {
2878 /* config dac list */
2879 spec->multiout.dac_nids[0] = 0x10;
2885 /* add playback controls from the parsed DAC table */
2886 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
2887 const struct auto_pin_cfg *cfg)
2891 if (!cfg->line_out_pins[0])
2894 /* add control to mixer index 0 */
2895 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2896 "Master Front Playback Volume",
2897 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
2900 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2901 "Master Front Playback Switch",
2902 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
2907 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2908 "Front Playback Volume",
2909 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
2912 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2913 "Front Playback Switch",
2914 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
2921 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2928 spec->multiout.hp_nid = 0x1D;
2930 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2931 "Headphone Playback Volume",
2932 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
2936 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2937 "Headphone Playback Switch",
2938 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2942 create_hp_imux(spec);
2947 /* create playback/capture controls for input pins */
2948 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
2949 const struct auto_pin_cfg *cfg)
2951 static char *labels[] = {
2952 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2954 struct hda_input_mux *imux = &spec->private_imux[0];
2955 int i, err, idx = 0;
2957 /* for internal loopback recording select */
2958 imux->items[imux->num_items].label = "Stereo Mixer";
2959 imux->items[imux->num_items].index = 3;
2962 for (i = 0; i < AUTO_PIN_LAST; i++) {
2963 if (!cfg->input_pins[i])
2966 switch (cfg->input_pins[i]) {
2967 case 0x14: /* Mic */
2971 case 0x15: /* Line In */
2975 case 0x18: /* Front Mic */
2979 err = via_new_analog_input(spec, cfg->input_pins[i],
2980 labels[i], idx, 0x1A);
2983 imux->items[imux->num_items].label = labels[i];
2984 imux->items[imux->num_items].index = idx-1;
2990 static int vt1702_parse_auto_config(struct hda_codec *codec)
2992 struct via_spec *spec = codec->spec;
2994 static hda_nid_t vt1702_ignore[] = {0x1C, 0};
2996 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3000 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3003 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3004 return 0; /* can't find valid BIOS pin config */
3006 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3009 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3012 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3016 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3018 if (spec->autocfg.dig_out_pin)
3019 spec->multiout.dig_out_nid = VT1702_DIGOUT_NID;
3021 if (spec->kctl_alloc)
3022 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3024 spec->input_mux = &spec->private_imux[0];
3026 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3031 #ifdef CONFIG_SND_HDA_POWER_SAVE
3032 static struct hda_amp_list vt1702_loopbacks[] = {
3033 { 0x1A, HDA_INPUT, 1 },
3034 { 0x1A, HDA_INPUT, 2 },
3035 { 0x1A, HDA_INPUT, 3 },
3036 { 0x1A, HDA_INPUT, 4 },
3041 static int patch_vt1702(struct hda_codec *codec)
3043 struct via_spec *spec;
3045 unsigned int response;
3046 unsigned char control;
3048 /* create a codec specific record */
3049 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3055 /* automatic parse from the BIOS config */
3056 err = vt1702_parse_auto_config(codec);
3061 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3062 "from BIOS. Using genenic mode...\n");
3065 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3066 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
3068 spec->stream_name_analog = "VT1702 Analog";
3069 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3070 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3072 spec->stream_name_digital = "VT1702 Digital";
3073 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3075 if (!spec->adc_nids && spec->input_mux) {
3076 spec->adc_nids = vt1702_adc_nids;
3077 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3078 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3082 codec->patch_ops = via_patch_ops;
3084 codec->patch_ops.init = via_auto_init;
3085 codec->patch_ops.unsol_event = via_unsol_event;
3086 #ifdef CONFIG_SND_HDA_POWER_SAVE
3087 spec->loopback.amplist = vt1702_loopbacks;
3091 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3092 control = (unsigned char)(response & 0xff);
3094 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
3096 /* Enable GPIO 0&1 for volume&mute control */
3097 /* Enable GPIO 2 for DMIC-DATA */
3098 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3099 control = (unsigned char)((response >> 16) & 0x3f);
3100 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
3108 struct hda_codec_preset snd_hda_preset_via[] = {
3109 { .id = 0x11061708, .name = "VIA VT1708", .patch = patch_vt1708},
3110 { .id = 0x11061709, .name = "VIA VT1708", .patch = patch_vt1708},
3111 { .id = 0x1106170A, .name = "VIA VT1708", .patch = patch_vt1708},
3112 { .id = 0x1106170B, .name = "VIA VT1708", .patch = patch_vt1708},
3113 { .id = 0x1106E710, .name = "VIA VT1709 10-Ch",
3114 .patch = patch_vt1709_10ch},
3115 { .id = 0x1106E711, .name = "VIA VT1709 10-Ch",
3116 .patch = patch_vt1709_10ch},
3117 { .id = 0x1106E712, .name = "VIA VT1709 10-Ch",
3118 .patch = patch_vt1709_10ch},
3119 { .id = 0x1106E713, .name = "VIA VT1709 10-Ch",
3120 .patch = patch_vt1709_10ch},
3121 { .id = 0x1106E714, .name = "VIA VT1709 6-Ch",
3122 .patch = patch_vt1709_6ch},
3123 { .id = 0x1106E715, .name = "VIA VT1709 6-Ch",
3124 .patch = patch_vt1709_6ch},
3125 { .id = 0x1106E716, .name = "VIA VT1709 6-Ch",
3126 .patch = patch_vt1709_6ch},
3127 { .id = 0x1106E717, .name = "VIA VT1709 6-Ch",
3128 .patch = patch_vt1709_6ch},
3129 { .id = 0x1106E720, .name = "VIA VT1708B 8-Ch",
3130 .patch = patch_vt1708B_8ch},
3131 { .id = 0x1106E721, .name = "VIA VT1708B 8-Ch",
3132 .patch = patch_vt1708B_8ch},
3133 { .id = 0x1106E722, .name = "VIA VT1708B 8-Ch",
3134 .patch = patch_vt1708B_8ch},
3135 { .id = 0x1106E723, .name = "VIA VT1708B 8-Ch",
3136 .patch = patch_vt1708B_8ch},
3137 { .id = 0x1106E724, .name = "VIA VT1708B 4-Ch",
3138 .patch = patch_vt1708B_4ch},
3139 { .id = 0x1106E725, .name = "VIA VT1708B 4-Ch",
3140 .patch = patch_vt1708B_4ch},
3141 { .id = 0x1106E726, .name = "VIA VT1708B 4-Ch",
3142 .patch = patch_vt1708B_4ch},
3143 { .id = 0x1106E727, .name = "VIA VT1708B 4-Ch",
3144 .patch = patch_vt1708B_4ch},
3145 { .id = 0x11060397, .name = "VIA VT1708S",
3146 .patch = patch_vt1708S},
3147 { .id = 0x11061397, .name = "VIA VT1708S",
3148 .patch = patch_vt1708S},
3149 { .id = 0x11062397, .name = "VIA VT1708S",
3150 .patch = patch_vt1708S},
3151 { .id = 0x11063397, .name = "VIA VT1708S",
3152 .patch = patch_vt1708S},
3153 { .id = 0x11064397, .name = "VIA VT1708S",
3154 .patch = patch_vt1708S},
3155 { .id = 0x11065397, .name = "VIA VT1708S",
3156 .patch = patch_vt1708S},
3157 { .id = 0x11066397, .name = "VIA VT1708S",
3158 .patch = patch_vt1708S},
3159 { .id = 0x11067397, .name = "VIA VT1708S",
3160 .patch = patch_vt1708S},
3161 { .id = 0x11060398, .name = "VIA VT1702",
3162 .patch = patch_vt1702},
3163 { .id = 0x11061398, .name = "VIA VT1702",
3164 .patch = patch_vt1702},
3165 { .id = 0x11062398, .name = "VIA VT1702",
3166 .patch = patch_vt1702},
3167 { .id = 0x11063398, .name = "VIA VT1702",
3168 .patch = patch_vt1702},
3169 { .id = 0x11064398, .name = "VIA VT1702",
3170 .patch = patch_vt1702},
3171 { .id = 0x11065398, .name = "VIA VT1702",
3172 .patch = patch_vt1702},
3173 { .id = 0x11066398, .name = "VIA VT1702",
3174 .patch = patch_vt1702},
3175 { .id = 0x11067398, .name = "VIA VT1702",
3176 .patch = patch_vt1702},