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 */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
40 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 #include <linux/init.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <sound/core.h>
47 #include <sound/asoundef.h>
48 #include "hda_codec.h"
49 #include "hda_local.h"
52 #define AMP_VAL_IDX_SHIFT 19
53 #define AMP_VAL_IDX_MASK (0x0f<<19)
56 #define VT1708_HP_NID 0x13
57 #define VT1708_DIGOUT_NID 0x14
58 #define VT1708_DIGIN_NID 0x16
59 #define VT1708_DIGIN_PIN 0x26
60 #define VT1708_HP_PIN_NID 0x20
61 #define VT1708_CD_PIN_NID 0x24
63 #define VT1709_HP_DAC_NID 0x28
64 #define VT1709_DIGOUT_NID 0x13
65 #define VT1709_DIGIN_NID 0x17
66 #define VT1709_DIGIN_PIN 0x25
68 #define VT1708B_HP_NID 0x25
69 #define VT1708B_DIGOUT_NID 0x12
70 #define VT1708B_DIGIN_NID 0x15
71 #define VT1708B_DIGIN_PIN 0x21
73 #define VT1708S_HP_NID 0x25
74 #define VT1708S_DIGOUT_NID 0x12
76 #define VT1702_HP_NID 0x17
77 #define VT1702_DIGOUT_NID 0x11
92 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
94 u32 vendor_id = codec->vendor_id;
95 u16 ven_id = vendor_id >> 16;
96 u16 dev_id = vendor_id & 0xffff;
97 enum VIA_HDA_CODEC codec_type;
100 if (ven_id != 0x1106)
101 codec_type = UNKNOWN;
102 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
104 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
105 codec_type = VT1709_10CH;
106 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
107 codec_type = VT1709_6CH;
108 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
109 codec_type = VT1708B_8CH;
110 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
111 codec_type = VT1708BCE;
112 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
113 codec_type = VT1708B_4CH;
114 else if ((dev_id & 0xfff) == 0x397
115 && (dev_id >> 12) < 8)
116 codec_type = VT1708S;
117 else if ((dev_id & 0xfff) == 0x398
118 && (dev_id >> 12) < 8)
121 codec_type = UNKNOWN;
125 #define VIA_HP_EVENT 0x01
126 #define VIA_GPIO_EVENT 0x02
131 VIA_CTL_WIDGET_ANALOG_MUTE,
141 /* Some VT1708S based boards gets the micboost setting wrong, so we have
142 * to apply some brute-force and re-write the TLV's by software. */
143 static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
144 unsigned int size, unsigned int __user *_tlv)
146 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
147 hda_nid_t nid = get_amp_nid(kcontrol);
149 if (get_codec_type(codec) == VT1708S
150 && (nid == 0x1a || nid == 0x1e)) {
151 if (size < 4 * sizeof(unsigned int))
153 if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */
155 if (put_user(2 * sizeof(unsigned int), _tlv + 1))
157 if (put_user(0, _tlv + 2)) /* offset = 0 */
159 if (put_user(1000, _tlv + 3)) /* step size = 10 dB */
165 static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
166 struct snd_ctl_elem_info *uinfo)
168 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
169 hda_nid_t nid = get_amp_nid(kcontrol);
171 if (get_codec_type(codec) == VT1708S
172 && (nid == 0x1a || nid == 0x1e)) {
173 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
175 uinfo->value.integer.min = 0;
176 uinfo->value.integer.max = 3;
181 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
182 static void set_jack_power_state(struct hda_codec *codec);
184 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
185 struct snd_ctl_elem_value *ucontrol)
187 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
188 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
190 set_jack_power_state(codec);
191 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
195 /* modify .put = snd_hda_mixer_amp_switch_put */
196 #define ANALOG_INPUT_MUTE \
197 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
200 .info = snd_hda_mixer_amp_switch_info, \
201 .get = snd_hda_mixer_amp_switch_get, \
202 .put = analog_input_switch_put, \
203 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
205 static struct snd_kcontrol_new vt1708_control_templates[] = {
206 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
207 HDA_CODEC_MUTE(NULL, 0, 0, 0),
213 /* codec parameterization */
214 struct snd_kcontrol_new *mixers[4];
215 unsigned int num_mixers;
217 struct hda_verb *init_verbs[5];
218 unsigned int num_iverbs;
220 char *stream_name_analog;
221 struct hda_pcm_stream *stream_analog_playback;
222 struct hda_pcm_stream *stream_analog_capture;
224 char *stream_name_digital;
225 struct hda_pcm_stream *stream_digital_playback;
226 struct hda_pcm_stream *stream_digital_capture;
229 struct hda_multi_out multiout;
230 hda_nid_t slave_dig_outs[2];
233 unsigned int num_adc_nids;
235 hda_nid_t mux_nids[3];
236 hda_nid_t dig_in_nid;
237 hda_nid_t dig_in_pin;
240 const struct hda_input_mux *input_mux;
241 unsigned int cur_mux[3];
243 /* PCM information */
244 struct hda_pcm pcm_rec[3];
246 /* dynamic controls, init_verbs and input_mux */
247 struct auto_pin_cfg autocfg;
248 struct snd_array kctls;
249 struct hda_input_mux private_imux[2];
250 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
253 const struct hda_input_mux *hp_mux;
254 unsigned int hp_independent_mode;
255 unsigned int hp_independent_mode_index;
256 unsigned int smart51_enabled;
258 enum VIA_HDA_CODEC codec_type;
260 #ifdef CONFIG_SND_HDA_POWER_SAVE
261 struct hda_loopback_check loopback;
265 static hda_nid_t vt1708_adc_nids[2] = {
270 static hda_nid_t vt1709_adc_nids[3] = {
275 static hda_nid_t vt1708B_adc_nids[2] = {
280 static hda_nid_t vt1708S_adc_nids[2] = {
285 static hda_nid_t vt1702_adc_nids[3] = {
290 /* add dynamic controls */
291 static int via_add_control(struct via_spec *spec, int type, const char *name,
294 struct snd_kcontrol_new *knew;
296 snd_array_init(&spec->kctls, sizeof(*knew), 32);
297 knew = snd_array_new(&spec->kctls);
300 *knew = vt1708_control_templates[type];
301 knew->name = kstrdup(name, GFP_KERNEL);
304 knew->private_value = val;
308 static void via_free_kctls(struct hda_codec *codec)
310 struct via_spec *spec = codec->spec;
312 if (spec->kctls.list) {
313 struct snd_kcontrol_new *kctl = spec->kctls.list;
315 for (i = 0; i < spec->kctls.used; i++)
318 snd_array_free(&spec->kctls);
321 /* create input playback/capture controls for the given pin */
322 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
323 int idx, int mix_nid)
328 sprintf(name, "%s Playback Volume", ctlname);
329 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
330 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
333 sprintf(name, "%s Playback Switch", ctlname);
334 err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
335 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
341 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
342 hda_nid_t nid, int pin_type,
346 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
348 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
350 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
351 snd_hda_codec_write(codec, nid, 0,
352 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
356 static void via_auto_init_multi_out(struct hda_codec *codec)
358 struct via_spec *spec = codec->spec;
361 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
362 hda_nid_t nid = spec->autocfg.line_out_pins[i];
364 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
368 static void via_auto_init_hp_out(struct hda_codec *codec)
370 struct via_spec *spec = codec->spec;
373 pin = spec->autocfg.hp_pins[0];
374 if (pin) /* connect to front */
375 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
378 static void via_auto_init_analog_input(struct hda_codec *codec)
380 struct via_spec *spec = codec->spec;
383 for (i = 0; i < AUTO_PIN_LAST; i++) {
384 hda_nid_t nid = spec->autocfg.input_pins[i];
386 snd_hda_codec_write(codec, nid, 0,
387 AC_VERB_SET_PIN_WIDGET_CONTROL,
388 (i <= AUTO_PIN_FRONT_MIC ?
389 PIN_VREF50 : PIN_IN));
394 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
396 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
397 unsigned int *affected_parm)
400 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
401 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
402 >> AC_DEFCFG_MISC_SHIFT
403 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
404 unsigned present = snd_hda_codec_read(codec, nid, 0,
405 AC_VERB_GET_PIN_SENSE, 0) >> 31;
406 struct via_spec *spec = codec->spec;
407 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
408 || ((no_presence || present)
409 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
410 *affected_parm = AC_PWRST_D0; /* if it's connected */
415 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
418 static void set_jack_power_state(struct hda_codec *codec)
420 struct via_spec *spec = codec->spec;
424 if (spec->codec_type == VT1702) {
425 imux_is_smixer = snd_hda_codec_read(
426 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
428 /* PW 1/2/5 (14h/15h/18h) */
430 set_pin_power_state(codec, 0x14, &parm);
431 set_pin_power_state(codec, 0x15, &parm);
432 set_pin_power_state(codec, 0x18, &parm);
434 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
435 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
436 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
438 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
440 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
442 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
446 /* PW 3/4 (16h/17h) */
448 set_pin_power_state(codec, 0x16, &parm);
449 set_pin_power_state(codec, 0x17, &parm);
450 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
451 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
452 imux_is_smixer ? AC_PWRST_D0 : parm);
453 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
455 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
457 } else if (spec->codec_type == VT1708B_8CH
458 || spec->codec_type == VT1708B_4CH
459 || spec->codec_type == VT1708S) {
460 /* SW0 (17h) = stereo mixer */
461 int is_8ch = spec->codec_type != VT1708B_4CH;
462 imux_is_smixer = snd_hda_codec_read(
463 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
464 == ((spec->codec_type == VT1708S) ? 5 : 0);
466 /* PW 1/2/5 (1ah/1bh/1eh) */
468 set_pin_power_state(codec, 0x1a, &parm);
469 set_pin_power_state(codec, 0x1b, &parm);
470 set_pin_power_state(codec, 0x1e, &parm);
473 /* SW0 (17h), AIW 0/1 (13h/14h) */
474 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
476 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
478 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
482 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
484 set_pin_power_state(codec, 0x19, &parm);
485 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
487 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
490 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
493 set_pin_power_state(codec, 0x22, &parm);
494 snd_hda_codec_write(codec, 0x26, 0,
495 AC_VERB_SET_POWER_STATE, parm);
496 snd_hda_codec_write(codec, 0x24, 0,
497 AC_VERB_SET_POWER_STATE, parm);
500 /* PW 3/4/7 (1ch/1dh/23h) */
502 /* force to D0 for internal Speaker */
503 set_pin_power_state(codec, 0x1c, &parm);
504 set_pin_power_state(codec, 0x1d, &parm);
506 set_pin_power_state(codec, 0x23, &parm);
507 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
508 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
509 imux_is_smixer ? AC_PWRST_D0 : parm);
510 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
513 snd_hda_codec_write(codec, 0x25, 0,
514 AC_VERB_SET_POWER_STATE, parm);
515 snd_hda_codec_write(codec, 0x27, 0,
516 AC_VERB_SET_POWER_STATE, parm);
524 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
525 struct snd_ctl_elem_info *uinfo)
527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
528 struct via_spec *spec = codec->spec;
529 return snd_hda_input_mux_info(spec->input_mux, uinfo);
532 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
533 struct snd_ctl_elem_value *ucontrol)
535 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
536 struct via_spec *spec = codec->spec;
537 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
539 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
543 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
544 struct snd_ctl_elem_value *ucontrol)
546 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
547 struct via_spec *spec = codec->spec;
548 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
550 if (!spec->mux_nids[adc_idx])
552 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
553 spec->mux_nids[adc_idx],
554 &spec->cur_mux[adc_idx]);
557 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
558 struct snd_ctl_elem_info *uinfo)
560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
561 struct via_spec *spec = codec->spec;
562 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
565 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
566 struct snd_ctl_elem_value *ucontrol)
568 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
569 struct via_spec *spec = codec->spec;
570 hda_nid_t nid = spec->autocfg.hp_pins[0];
571 unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
572 AC_VERB_GET_CONNECT_SEL,
575 ucontrol->value.enumerated.item[0] = pinsel;
580 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
582 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
584 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
585 ctl->vd[0].access |= active
586 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
587 snd_ctl_notify(codec->bus->card,
588 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
592 static int update_side_mute_status(struct hda_codec *codec)
594 /* mute side channel */
595 struct via_spec *spec = codec->spec;
596 unsigned int parm = spec->hp_independent_mode
597 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
600 switch (spec->codec_type) {
617 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
622 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
623 struct snd_ctl_elem_value *ucontrol)
625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
626 struct via_spec *spec = codec->spec;
627 hda_nid_t nid = spec->autocfg.hp_pins[0];
628 unsigned int pinsel = ucontrol->value.enumerated.item[0];
629 /* Get Independent Mode index of headphone pin widget */
630 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
633 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
635 if (spec->multiout.hp_nid && spec->multiout.hp_nid
636 != spec->multiout.dac_nids[HDA_FRONT])
637 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
640 update_side_mute_status(codec);
641 /* update HP volume/swtich active state */
642 if (spec->codec_type == VT1708S
643 || spec->codec_type == VT1702) {
644 activate_ctl(codec, "Headphone Playback Volume",
645 spec->hp_independent_mode);
646 activate_ctl(codec, "Headphone Playback Switch",
647 spec->hp_independent_mode);
652 static struct snd_kcontrol_new via_hp_mixer[] = {
654 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
655 .name = "Independent HP",
657 .info = via_independent_hp_info,
658 .get = via_independent_hp_get,
659 .put = via_independent_hp_put,
664 static void notify_aa_path_ctls(struct hda_codec *codec)
667 struct snd_ctl_elem_id id;
668 const char *labels[] = {"Mic", "Front Mic", "Line"};
670 memset(&id, 0, sizeof(id));
671 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
672 for (i = 0; i < ARRAY_SIZE(labels); i++) {
673 sprintf(id.name, "%s Playback Volume", labels[i]);
674 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
679 static void mute_aa_path(struct hda_codec *codec, int mute)
681 struct via_spec *spec = codec->spec;
686 /* get nid of MW0 and start & end index */
687 switch (spec->codec_type) {
709 /* check AA path's mute status */
710 for (i = start_idx; i <= end_idx; i++) {
711 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
712 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
716 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
720 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
721 if (pin == spec->autocfg.input_pins[index]) {
729 static int via_smart51_info(struct snd_kcontrol *kcontrol,
730 struct snd_ctl_elem_info *uinfo)
732 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
734 uinfo->value.integer.min = 0;
735 uinfo->value.integer.max = 1;
739 static int via_smart51_get(struct snd_kcontrol *kcontrol,
740 struct snd_ctl_elem_value *ucontrol)
742 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
743 struct via_spec *spec = codec->spec;
744 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
748 for (i = 0; i < ARRAY_SIZE(index); i++) {
749 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
752 snd_hda_codec_read(codec, nid, 0,
753 AC_VERB_GET_PIN_WIDGET_CONTROL,
755 if (i == AUTO_PIN_FRONT_MIC
756 && spec->hp_independent_mode)
757 continue; /* ignore FMic for independent HP */
758 if (ctl & AC_PINCTL_IN_EN
759 && !(ctl & AC_PINCTL_OUT_EN))
763 *ucontrol->value.integer.value = on;
767 static int via_smart51_put(struct snd_kcontrol *kcontrol,
768 struct snd_ctl_elem_value *ucontrol)
770 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
771 struct via_spec *spec = codec->spec;
772 int out_in = *ucontrol->value.integer.value
773 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
774 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
777 for (i = 0; i < ARRAY_SIZE(index); i++) {
778 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
779 if (i == AUTO_PIN_FRONT_MIC
780 && spec->hp_independent_mode)
781 continue; /* don't retask FMic for independent HP */
783 unsigned int parm = snd_hda_codec_read(
785 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
786 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
788 snd_hda_codec_write(codec, nid, 0,
789 AC_VERB_SET_PIN_WIDGET_CONTROL,
791 if (out_in == AC_PINCTL_OUT_EN) {
792 mute_aa_path(codec, 1);
793 notify_aa_path_ctls(codec);
796 if (i == AUTO_PIN_FRONT_MIC) {
797 if (spec->codec_type == VT1708S) {
798 /* input = index 1 (AOW3) */
801 AC_VERB_SET_CONNECT_SEL, 1);
802 snd_hda_codec_amp_stereo(
803 codec, nid, HDA_OUTPUT,
804 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
808 spec->smart51_enabled = *ucontrol->value.integer.value;
809 set_jack_power_state(codec);
813 static struct snd_kcontrol_new via_smart51_mixer[] = {
815 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
818 .info = via_smart51_info,
819 .get = via_smart51_get,
820 .put = via_smart51_put,
825 /* capture mixer elements */
826 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
827 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
828 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
829 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
830 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
832 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
833 /* The multiple "Capture Source" controls confuse alsamixer
834 * So call somewhat different..
836 /* .name = "Capture Source", */
837 .name = "Input Source",
839 .info = via_mux_enum_info,
840 .get = via_mux_enum_get,
841 .put = via_mux_enum_put,
846 /* check AA path's mute statue */
847 static int is_aa_path_mute(struct hda_codec *codec)
854 struct via_spec *spec = codec->spec;
855 /* get nid of MW0 and start & end index */
856 switch (spec->codec_type) {
872 /* check AA path's mute status */
873 for (i = start_idx; i <= end_idx; i++) {
874 unsigned int con_list = snd_hda_codec_read(
875 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
876 int shift = 8 * (i % 4);
877 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
878 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
879 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
880 /* check mute status while the pin is connected */
881 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
883 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
885 if (!mute_l || !mute_r) {
894 /* enter/exit analog low-current mode */
895 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
897 struct via_spec *spec = codec->spec;
898 static int saved_stream_idle = 1; /* saved stream idle status */
899 int enable = is_aa_path_mute(codec);
900 unsigned int verb = 0;
901 unsigned int parm = 0;
903 if (stream_idle == -1) /* stream status did not change */
904 enable = enable && saved_stream_idle;
906 enable = enable && stream_idle;
907 saved_stream_idle = stream_idle;
910 /* decide low current mode's verb & parameter */
911 switch (spec->codec_type) {
915 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
919 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
923 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
926 return; /* other codecs are not supported */
929 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
933 * generic initialization of ADC, input mixers and output mixers
935 static struct hda_verb vt1708_volume_init_verbs[] = {
937 * Unmute ADC0-1 and set the default input to mic-in
939 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
940 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
943 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
946 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
947 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
948 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
949 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
950 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
951 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
954 * Set up output mixers (0x19 - 0x1b)
956 /* set vol=0 to output mixers */
957 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
958 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
959 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
961 /* Setup default input to PW4 */
962 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
963 /* PW9 Output enable */
964 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
968 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
969 struct hda_codec *codec,
970 struct snd_pcm_substream *substream)
972 struct via_spec *spec = codec->spec;
973 int idle = substream->pstr->substream_opened == 1
974 && substream->ref_count == 0;
976 analog_low_current_mode(codec, idle);
977 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
981 static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
982 struct hda_codec *codec,
983 unsigned int stream_tag,
985 struct snd_pcm_substream *substream)
987 struct via_spec *spec = codec->spec;
988 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
989 stream_tag, format, substream);
992 static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
993 struct hda_codec *codec,
994 struct snd_pcm_substream *substream)
996 struct via_spec *spec = codec->spec;
997 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1001 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1002 unsigned int stream_tag,
1003 unsigned int format,
1004 struct snd_pcm_substream *substream)
1006 struct via_spec *spec = codec->spec;
1007 struct hda_multi_out *mout = &spec->multiout;
1008 hda_nid_t *nids = mout->dac_nids;
1009 int chs = substream->runtime->channels;
1012 mutex_lock(&codec->spdif_mutex);
1013 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1015 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1017 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1018 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1019 /* turn off SPDIF once; otherwise the IEC958 bits won't
1021 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1022 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1023 AC_VERB_SET_DIGI_CONVERT_1,
1025 ~AC_DIG1_ENABLE & 0xff);
1026 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1027 stream_tag, 0, format);
1028 /* turn on again (if needed) */
1029 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1030 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1031 AC_VERB_SET_DIGI_CONVERT_1,
1032 codec->spdif_ctls & 0xff);
1034 mout->dig_out_used = 0;
1035 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1039 mutex_unlock(&codec->spdif_mutex);
1042 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1045 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1046 !spec->hp_independent_mode)
1047 /* headphone out will just decode front left/right (stereo) */
1048 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1051 /* extra outputs copied from front */
1052 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1053 if (mout->extra_out_nid[i])
1054 snd_hda_codec_setup_stream(codec,
1055 mout->extra_out_nid[i],
1056 stream_tag, 0, format);
1059 for (i = 1; i < mout->num_dacs; i++) {
1060 if (chs >= (i + 1) * 2) /* independent out */
1061 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1063 else /* copy front */
1064 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1069 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1070 struct hda_codec *codec,
1071 unsigned int stream_tag,
1072 unsigned int format,
1073 struct snd_pcm_substream *substream)
1075 struct via_spec *spec = codec->spec;
1076 struct hda_multi_out *mout = &spec->multiout;
1077 hda_nid_t *nids = mout->dac_nids;
1079 if (substream->number == 0)
1080 playback_multi_pcm_prep_0(codec, stream_tag, format,
1083 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1084 spec->hp_independent_mode)
1085 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1086 stream_tag, 0, format);
1092 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1093 struct hda_codec *codec,
1094 struct snd_pcm_substream *substream)
1096 struct via_spec *spec = codec->spec;
1097 struct hda_multi_out *mout = &spec->multiout;
1098 hda_nid_t *nids = mout->dac_nids;
1101 if (substream->number == 0) {
1102 for (i = 0; i < mout->num_dacs; i++)
1103 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1105 if (mout->hp_nid && !spec->hp_independent_mode)
1106 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1109 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1110 if (mout->extra_out_nid[i])
1111 snd_hda_codec_setup_stream(codec,
1112 mout->extra_out_nid[i],
1114 mutex_lock(&codec->spdif_mutex);
1115 if (mout->dig_out_nid &&
1116 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1117 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1119 mout->dig_out_used = 0;
1121 mutex_unlock(&codec->spdif_mutex);
1123 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1124 spec->hp_independent_mode)
1125 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1135 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1136 struct hda_codec *codec,
1137 struct snd_pcm_substream *substream)
1139 struct via_spec *spec = codec->spec;
1140 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1143 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1144 struct hda_codec *codec,
1145 struct snd_pcm_substream *substream)
1147 struct via_spec *spec = codec->spec;
1148 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1151 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1152 struct hda_codec *codec,
1153 unsigned int stream_tag,
1154 unsigned int format,
1155 struct snd_pcm_substream *substream)
1157 struct via_spec *spec = codec->spec;
1158 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1159 stream_tag, format, substream);
1162 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1163 struct hda_codec *codec,
1164 struct snd_pcm_substream *substream)
1166 struct via_spec *spec = codec->spec;
1167 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1174 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1175 struct hda_codec *codec,
1176 unsigned int stream_tag,
1177 unsigned int format,
1178 struct snd_pcm_substream *substream)
1180 struct via_spec *spec = codec->spec;
1182 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1183 stream_tag, 0, format);
1187 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1188 struct hda_codec *codec,
1189 struct snd_pcm_substream *substream)
1191 struct via_spec *spec = codec->spec;
1192 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1196 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1200 .nid = 0x10, /* NID to query formats and rates */
1202 .open = via_playback_pcm_open,
1203 .prepare = via_playback_multi_pcm_prepare,
1204 .cleanup = via_playback_multi_pcm_cleanup
1208 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1212 .nid = 0x10, /* NID to query formats and rates */
1213 /* We got noisy outputs on the right channel on VT1708 when
1214 * 24bit samples are used. Until any workaround is found,
1215 * disable the 24bit format, so far.
1217 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1219 .open = via_playback_pcm_open,
1220 .prepare = via_playback_pcm_prepare,
1221 .cleanup = via_playback_pcm_cleanup
1225 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1229 .nid = 0x15, /* NID to query formats and rates */
1231 .prepare = via_capture_pcm_prepare,
1232 .cleanup = via_capture_pcm_cleanup
1236 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1240 /* NID is set in via_build_pcms */
1242 .open = via_dig_playback_pcm_open,
1243 .close = via_dig_playback_pcm_close,
1244 .prepare = via_dig_playback_pcm_prepare,
1245 .cleanup = via_dig_playback_pcm_cleanup
1249 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1255 static int via_build_controls(struct hda_codec *codec)
1257 struct via_spec *spec = codec->spec;
1261 for (i = 0; i < spec->num_mixers; i++) {
1262 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1267 if (spec->multiout.dig_out_nid) {
1268 err = snd_hda_create_spdif_out_ctls(codec,
1269 spec->multiout.dig_out_nid);
1272 err = snd_hda_create_spdif_share_sw(codec,
1276 spec->multiout.share_spdif = 1;
1278 if (spec->dig_in_nid) {
1279 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1284 /* init power states */
1285 set_jack_power_state(codec);
1286 analog_low_current_mode(codec, 1);
1288 via_free_kctls(codec); /* no longer needed */
1292 static int via_build_pcms(struct hda_codec *codec)
1294 struct via_spec *spec = codec->spec;
1295 struct hda_pcm *info = spec->pcm_rec;
1297 codec->num_pcms = 1;
1298 codec->pcm_info = info;
1300 info->name = spec->stream_name_analog;
1301 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
1302 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
1303 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1304 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1306 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1307 spec->multiout.max_channels;
1309 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1312 info->name = spec->stream_name_digital;
1313 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1314 if (spec->multiout.dig_out_nid) {
1315 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1316 *(spec->stream_digital_playback);
1317 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1318 spec->multiout.dig_out_nid;
1320 if (spec->dig_in_nid) {
1321 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1322 *(spec->stream_digital_capture);
1323 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1331 static void via_free(struct hda_codec *codec)
1333 struct via_spec *spec = codec->spec;
1338 via_free_kctls(codec);
1342 /* mute internal speaker if HP is plugged */
1343 static void via_hp_automute(struct hda_codec *codec)
1345 unsigned int present;
1346 struct via_spec *spec = codec->spec;
1348 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
1349 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1350 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1351 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1352 present ? HDA_AMP_MUTE : 0);
1355 static void via_gpio_control(struct hda_codec *codec)
1357 unsigned int gpio_data;
1358 unsigned int vol_counter;
1360 unsigned int master_vol;
1362 struct via_spec *spec = codec->spec;
1364 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1365 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1367 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1368 0xF84, 0) & 0x3F0000) >> 16;
1370 vol = vol_counter & 0x1F;
1371 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1372 AC_VERB_GET_AMP_GAIN_MUTE,
1375 if (gpio_data == 0x02) {
1376 /* unmute line out */
1377 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1378 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1380 if (vol_counter & 0x20) {
1381 /* decrease volume */
1382 if (vol > master_vol)
1384 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
1388 /* increase volume */
1389 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
1391 ((master_vol+vol) > 0x2A) ? 0x2A :
1394 } else if (!(gpio_data & 0x02)) {
1396 snd_hda_codec_amp_stereo(codec,
1397 spec->autocfg.line_out_pins[0],
1398 HDA_OUTPUT, 0, HDA_AMP_MUTE,
1403 /* unsolicited event for jack sensing */
1404 static void via_unsol_event(struct hda_codec *codec,
1408 if (res == VIA_HP_EVENT)
1409 via_hp_automute(codec);
1410 else if (res == VIA_GPIO_EVENT)
1411 via_gpio_control(codec);
1414 static int via_init(struct hda_codec *codec)
1416 struct via_spec *spec = codec->spec;
1418 for (i = 0; i < spec->num_iverbs; i++)
1419 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1421 spec->codec_type = get_codec_type(codec);
1422 if (spec->codec_type == VT1708BCE)
1423 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
1425 /* Lydia Add for EAPD enable */
1426 if (!spec->dig_in_nid) { /* No Digital In connection */
1427 if (spec->dig_in_pin) {
1428 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1429 AC_VERB_SET_PIN_WIDGET_CONTROL,
1431 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
1432 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
1434 } else /* enable SPDIF-input pin */
1435 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
1436 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
1438 /* assign slave outs */
1439 if (spec->slave_dig_outs[0])
1440 codec->slave_dig_outs = spec->slave_dig_outs;
1445 #ifdef CONFIG_SND_HDA_POWER_SAVE
1446 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1448 struct via_spec *spec = codec->spec;
1449 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1455 static struct hda_codec_ops via_patch_ops = {
1456 .build_controls = via_build_controls,
1457 .build_pcms = via_build_pcms,
1460 #ifdef CONFIG_SND_HDA_POWER_SAVE
1461 .check_power_status = via_check_power_status,
1465 /* fill in the dac_nids table from the parsed pin configuration */
1466 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
1467 const struct auto_pin_cfg *cfg)
1472 spec->multiout.num_dacs = cfg->line_outs;
1474 spec->multiout.dac_nids = spec->private_dac_nids;
1476 for(i = 0; i < 4; i++) {
1477 nid = cfg->line_out_pins[i];
1479 /* config dac list */
1481 case AUTO_SEQ_FRONT:
1482 spec->multiout.dac_nids[i] = 0x10;
1484 case AUTO_SEQ_CENLFE:
1485 spec->multiout.dac_nids[i] = 0x12;
1487 case AUTO_SEQ_SURROUND:
1488 spec->multiout.dac_nids[i] = 0x11;
1491 spec->multiout.dac_nids[i] = 0x13;
1500 /* add playback controls from the parsed DAC table */
1501 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
1502 const struct auto_pin_cfg *cfg)
1505 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
1506 hda_nid_t nid, nid_vol = 0;
1509 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
1510 nid = cfg->line_out_pins[i];
1515 if (i != AUTO_SEQ_FRONT)
1518 if (i == AUTO_SEQ_CENLFE) {
1520 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1521 "Center Playback Volume",
1522 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1526 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1527 "LFE Playback Volume",
1528 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1532 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1533 "Center Playback Switch",
1534 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
1538 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1539 "LFE Playback Switch",
1540 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
1544 } else if (i == AUTO_SEQ_FRONT){
1545 /* add control to mixer index 0 */
1546 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1547 "Master Front Playback Volume",
1548 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1552 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1553 "Master Front Playback Switch",
1554 HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
1559 /* add control to PW3 */
1560 sprintf(name, "%s Playback Volume", chname[i]);
1561 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1562 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1566 sprintf(name, "%s Playback Switch", chname[i]);
1567 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1568 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
1573 sprintf(name, "%s Playback Volume", chname[i]);
1574 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
1575 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1579 sprintf(name, "%s Playback Switch", chname[i]);
1580 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
1581 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
1591 static void create_hp_imux(struct via_spec *spec)
1594 struct hda_input_mux *imux = &spec->private_imux[1];
1595 static const char *texts[] = { "OFF", "ON", NULL};
1597 /* for hp mode select */
1599 while (texts[i] != NULL) {
1600 imux->items[imux->num_items].label = texts[i];
1601 imux->items[imux->num_items].index = i;
1606 spec->hp_mux = &spec->private_imux[1];
1609 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
1616 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
1617 spec->hp_independent_mode_index = 1;
1619 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
1620 "Headphone Playback Volume",
1621 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1624 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
1625 "Headphone Playback Switch",
1626 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
1630 create_hp_imux(spec);
1635 /* create playback/capture controls for input pins */
1636 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
1637 const struct auto_pin_cfg *cfg)
1639 static char *labels[] = {
1640 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
1642 struct hda_input_mux *imux = &spec->private_imux[0];
1643 int i, err, idx = 0;
1645 /* for internal loopback recording select */
1646 imux->items[imux->num_items].label = "Stereo Mixer";
1647 imux->items[imux->num_items].index = idx;
1650 for (i = 0; i < AUTO_PIN_LAST; i++) {
1651 if (!cfg->input_pins[i])
1654 switch (cfg->input_pins[i]) {
1655 case 0x1d: /* Mic */
1659 case 0x1e: /* Line In */
1663 case 0x21: /* Front Mic */
1671 err = via_new_analog_input(spec, labels[i], idx, 0x17);
1674 imux->items[imux->num_items].label = labels[i];
1675 imux->items[imux->num_items].index = idx;
1681 #ifdef CONFIG_SND_HDA_POWER_SAVE
1682 static struct hda_amp_list vt1708_loopbacks[] = {
1683 { 0x17, HDA_INPUT, 1 },
1684 { 0x17, HDA_INPUT, 2 },
1685 { 0x17, HDA_INPUT, 3 },
1686 { 0x17, HDA_INPUT, 4 },
1691 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1693 unsigned int def_conf;
1694 unsigned char seqassoc;
1696 def_conf = snd_hda_codec_get_pincfg(codec, nid);
1697 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1698 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1699 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1700 if (seqassoc == 0xff) {
1701 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1702 snd_hda_codec_set_pincfg(codec, nid, def_conf);
1709 static int vt1708_parse_auto_config(struct hda_codec *codec)
1711 struct via_spec *spec = codec->spec;
1714 /* Add HP and CD pin config connect bit re-config action */
1715 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
1716 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
1718 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
1721 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
1724 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
1725 return 0; /* can't find valid BIOS pin config */
1727 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
1730 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
1733 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
1737 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1739 if (spec->autocfg.dig_outs)
1740 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
1741 spec->dig_in_pin = VT1708_DIGIN_PIN;
1742 if (spec->autocfg.dig_in_pin)
1743 spec->dig_in_nid = VT1708_DIGIN_NID;
1745 if (spec->kctls.list)
1746 spec->mixers[spec->num_mixers++] = spec->kctls.list;
1748 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
1750 spec->input_mux = &spec->private_imux[0];
1753 spec->mixers[spec->num_mixers++] = via_hp_mixer;
1755 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
1759 /* init callback for auto-configuration model -- overriding the default init */
1760 static int via_auto_init(struct hda_codec *codec)
1763 via_auto_init_multi_out(codec);
1764 via_auto_init_hp_out(codec);
1765 via_auto_init_analog_input(codec);
1769 static int get_mux_nids(struct hda_codec *codec)
1771 struct via_spec *spec = codec->spec;
1772 hda_nid_t nid, conn[8];
1776 for (i = 0; i < spec->num_adc_nids; i++) {
1777 nid = spec->adc_nids[i];
1779 type = get_wcaps_type(get_wcaps(codec, nid));
1780 if (type == AC_WID_PIN)
1782 n = snd_hda_get_connections(codec, nid, conn,
1787 spec->mux_nids[i] = nid;
1796 static int patch_vt1708(struct hda_codec *codec)
1798 struct via_spec *spec;
1801 /* create a codec specific record */
1802 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1808 /* automatic parse from the BIOS config */
1809 err = vt1708_parse_auto_config(codec);
1814 printk(KERN_INFO "hda_codec: Cannot set up configuration "
1815 "from BIOS. Using genenic mode...\n");
1819 spec->stream_name_analog = "VT1708 Analog";
1820 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
1821 /* disable 32bit format on VT1708 */
1822 if (codec->vendor_id == 0x11061708)
1823 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
1824 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
1826 spec->stream_name_digital = "VT1708 Digital";
1827 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
1828 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
1831 if (!spec->adc_nids && spec->input_mux) {
1832 spec->adc_nids = vt1708_adc_nids;
1833 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
1834 get_mux_nids(codec);
1835 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
1839 codec->patch_ops = via_patch_ops;
1841 codec->patch_ops.init = via_auto_init;
1842 #ifdef CONFIG_SND_HDA_POWER_SAVE
1843 spec->loopback.amplist = vt1708_loopbacks;
1849 /* capture mixer elements */
1850 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
1851 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
1852 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
1853 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
1854 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
1855 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
1856 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
1858 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1859 /* The multiple "Capture Source" controls confuse alsamixer
1860 * So call somewhat different..
1862 /* .name = "Capture Source", */
1863 .name = "Input Source",
1865 .info = via_mux_enum_info,
1866 .get = via_mux_enum_get,
1867 .put = via_mux_enum_put,
1872 static struct hda_verb vt1709_uniwill_init_verbs[] = {
1873 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
1878 * generic initialization of ADC, input mixers and output mixers
1880 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
1882 * Unmute ADC0-2 and set the default input to mic-in
1884 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1885 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1886 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1889 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1892 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1893 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1894 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1895 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1896 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1897 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1900 * Set up output selector (0x1a, 0x1b, 0x29)
1902 /* set vol=0 to output mixers */
1903 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1904 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1905 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1908 * Unmute PW3 and PW4
1910 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1911 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1913 /* Set input of PW4 as AOW4 */
1914 {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
1915 /* PW9 Output enable */
1916 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1920 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
1924 .nid = 0x10, /* NID to query formats and rates */
1926 .open = via_playback_pcm_open,
1927 .prepare = via_playback_pcm_prepare,
1928 .cleanup = via_playback_pcm_cleanup
1932 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
1936 .nid = 0x10, /* NID to query formats and rates */
1938 .open = via_playback_pcm_open,
1939 .prepare = via_playback_pcm_prepare,
1940 .cleanup = via_playback_pcm_cleanup
1944 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
1948 .nid = 0x14, /* NID to query formats and rates */
1950 .prepare = via_capture_pcm_prepare,
1951 .cleanup = via_capture_pcm_cleanup
1955 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
1959 /* NID is set in via_build_pcms */
1961 .open = via_dig_playback_pcm_open,
1962 .close = via_dig_playback_pcm_close
1966 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
1972 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
1973 const struct auto_pin_cfg *cfg)
1978 if (cfg->line_outs == 4) /* 10 channels */
1979 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
1980 else if (cfg->line_outs == 3) /* 6 channels */
1981 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
1983 spec->multiout.dac_nids = spec->private_dac_nids;
1985 if (cfg->line_outs == 4) { /* 10 channels */
1986 for (i = 0; i < cfg->line_outs; i++) {
1987 nid = cfg->line_out_pins[i];
1989 /* config dac list */
1991 case AUTO_SEQ_FRONT:
1993 spec->multiout.dac_nids[i] = 0x10;
1995 case AUTO_SEQ_CENLFE:
1997 spec->multiout.dac_nids[i] = 0x12;
1999 case AUTO_SEQ_SURROUND:
2001 spec->multiout.dac_nids[i] = 0x11;
2005 spec->multiout.dac_nids[i] = 0x27;
2012 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2014 } else if (cfg->line_outs == 3) { /* 6 channels */
2015 for(i = 0; i < cfg->line_outs; i++) {
2016 nid = cfg->line_out_pins[i];
2018 /* config dac list */
2020 case AUTO_SEQ_FRONT:
2022 spec->multiout.dac_nids[i] = 0x10;
2024 case AUTO_SEQ_CENLFE:
2026 spec->multiout.dac_nids[i] = 0x12;
2028 case AUTO_SEQ_SURROUND:
2030 spec->multiout.dac_nids[i] = 0x11;
2042 /* add playback controls from the parsed DAC table */
2043 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2044 const struct auto_pin_cfg *cfg)
2047 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2051 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2052 nid = cfg->line_out_pins[i];
2057 if (i == AUTO_SEQ_CENLFE) {
2059 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2060 "Center Playback Volume",
2061 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
2065 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2066 "LFE Playback Volume",
2067 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
2071 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2072 "Center Playback Switch",
2073 HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
2077 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2078 "LFE Playback Switch",
2079 HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
2083 } else if (i == AUTO_SEQ_FRONT){
2084 /* add control to mixer index 0 */
2085 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2086 "Master Front Playback Volume",
2087 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
2091 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2092 "Master Front Playback Switch",
2093 HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
2098 /* add control to PW3 */
2099 sprintf(name, "%s Playback Volume", chname[i]);
2100 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2101 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2105 sprintf(name, "%s Playback Switch", chname[i]);
2106 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2107 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2111 } else if (i == AUTO_SEQ_SURROUND) {
2112 sprintf(name, "%s Playback Volume", chname[i]);
2113 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2114 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
2118 sprintf(name, "%s Playback Switch", chname[i]);
2119 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2120 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
2124 } else if (i == AUTO_SEQ_SIDE) {
2125 sprintf(name, "%s Playback Volume", chname[i]);
2126 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2127 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
2131 sprintf(name, "%s Playback Switch", chname[i]);
2132 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2133 HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
2143 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2150 if (spec->multiout.num_dacs == 5) /* 10 channels */
2151 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2152 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2153 spec->multiout.hp_nid = 0;
2154 spec->hp_independent_mode_index = 1;
2156 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2157 "Headphone Playback Volume",
2158 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2161 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2162 "Headphone Playback Switch",
2163 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2170 /* create playback/capture controls for input pins */
2171 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
2172 const struct auto_pin_cfg *cfg)
2174 static char *labels[] = {
2175 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2177 struct hda_input_mux *imux = &spec->private_imux[0];
2178 int i, err, idx = 0;
2180 /* for internal loopback recording select */
2181 imux->items[imux->num_items].label = "Stereo Mixer";
2182 imux->items[imux->num_items].index = idx;
2185 for (i = 0; i < AUTO_PIN_LAST; i++) {
2186 if (!cfg->input_pins[i])
2189 switch (cfg->input_pins[i]) {
2190 case 0x1d: /* Mic */
2194 case 0x1e: /* Line In */
2198 case 0x21: /* Front Mic */
2206 err = via_new_analog_input(spec, labels[i], idx, 0x18);
2209 imux->items[imux->num_items].label = labels[i];
2210 imux->items[imux->num_items].index = idx;
2216 static int vt1709_parse_auto_config(struct hda_codec *codec)
2218 struct via_spec *spec = codec->spec;
2221 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2224 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
2227 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2228 return 0; /* can't find valid BIOS pin config */
2230 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
2233 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2236 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
2240 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2242 if (spec->autocfg.dig_outs)
2243 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
2244 spec->dig_in_pin = VT1709_DIGIN_PIN;
2245 if (spec->autocfg.dig_in_pin)
2246 spec->dig_in_nid = VT1709_DIGIN_NID;
2248 if (spec->kctls.list)
2249 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2251 spec->input_mux = &spec->private_imux[0];
2254 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2256 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2260 #ifdef CONFIG_SND_HDA_POWER_SAVE
2261 static struct hda_amp_list vt1709_loopbacks[] = {
2262 { 0x18, HDA_INPUT, 1 },
2263 { 0x18, HDA_INPUT, 2 },
2264 { 0x18, HDA_INPUT, 3 },
2265 { 0x18, HDA_INPUT, 4 },
2270 static int patch_vt1709_10ch(struct hda_codec *codec)
2272 struct via_spec *spec;
2275 /* create a codec specific record */
2276 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2282 err = vt1709_parse_auto_config(codec);
2287 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2288 "Using genenic mode...\n");
2291 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
2292 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2294 spec->stream_name_analog = "VT1709 Analog";
2295 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
2296 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2298 spec->stream_name_digital = "VT1709 Digital";
2299 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2300 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2303 if (!spec->adc_nids && spec->input_mux) {
2304 spec->adc_nids = vt1709_adc_nids;
2305 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2306 get_mux_nids(codec);
2307 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2311 codec->patch_ops = via_patch_ops;
2313 codec->patch_ops.init = via_auto_init;
2314 codec->patch_ops.unsol_event = via_unsol_event;
2315 #ifdef CONFIG_SND_HDA_POWER_SAVE
2316 spec->loopback.amplist = vt1709_loopbacks;
2322 * generic initialization of ADC, input mixers and output mixers
2324 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
2326 * Unmute ADC0-2 and set the default input to mic-in
2328 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2329 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2330 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2333 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2336 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2337 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2338 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2339 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2340 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2341 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2344 * Set up output selector (0x1a, 0x1b, 0x29)
2346 /* set vol=0 to output mixers */
2347 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2348 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2349 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2352 * Unmute PW3 and PW4
2354 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2355 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2357 /* Set input of PW4 as MW0 */
2358 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2359 /* PW9 Output enable */
2360 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2364 static int patch_vt1709_6ch(struct hda_codec *codec)
2366 struct via_spec *spec;
2369 /* create a codec specific record */
2370 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2376 err = vt1709_parse_auto_config(codec);
2381 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
2382 "Using genenic mode...\n");
2385 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
2386 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
2388 spec->stream_name_analog = "VT1709 Analog";
2389 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
2390 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
2392 spec->stream_name_digital = "VT1709 Digital";
2393 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
2394 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
2397 if (!spec->adc_nids && spec->input_mux) {
2398 spec->adc_nids = vt1709_adc_nids;
2399 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
2400 get_mux_nids(codec);
2401 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
2405 codec->patch_ops = via_patch_ops;
2407 codec->patch_ops.init = via_auto_init;
2408 codec->patch_ops.unsol_event = via_unsol_event;
2409 #ifdef CONFIG_SND_HDA_POWER_SAVE
2410 spec->loopback.amplist = vt1709_loopbacks;
2415 /* capture mixer elements */
2416 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
2417 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2418 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2419 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2420 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2422 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2423 /* The multiple "Capture Source" controls confuse alsamixer
2424 * So call somewhat different..
2426 /* .name = "Capture Source", */
2427 .name = "Input Source",
2429 .info = via_mux_enum_info,
2430 .get = via_mux_enum_get,
2431 .put = via_mux_enum_put,
2436 * generic initialization of ADC, input mixers and output mixers
2438 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
2440 * Unmute ADC0-1 and set the default input to mic-in
2442 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2443 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2446 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2449 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2450 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2451 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2452 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2453 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2454 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2457 * Set up output mixers
2459 /* set vol=0 to output mixers */
2460 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2461 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2462 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2464 /* Setup default input to PW4 */
2465 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
2466 /* PW9 Output enable */
2467 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2468 /* PW10 Input enable */
2469 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2473 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
2475 * Unmute ADC0-1 and set the default input to mic-in
2477 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2478 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2481 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2484 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2485 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2486 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2487 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2488 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2489 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2492 * Set up output mixers
2494 /* set vol=0 to output mixers */
2495 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2496 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2497 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2499 /* Setup default input of PW4 to MW0 */
2500 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2501 /* PW9 Output enable */
2502 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2503 /* PW10 Input enable */
2504 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
2508 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
2509 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
2513 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
2514 struct hda_codec *codec,
2515 struct snd_pcm_substream *substream)
2517 int idle = substream->pstr->substream_opened == 1
2518 && substream->ref_count == 0;
2520 analog_low_current_mode(codec, idle);
2524 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
2528 .nid = 0x10, /* NID to query formats and rates */
2530 .open = via_playback_pcm_open,
2531 .prepare = via_playback_multi_pcm_prepare,
2532 .cleanup = via_playback_multi_pcm_cleanup,
2533 .close = via_pcm_open_close
2537 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
2541 .nid = 0x10, /* NID to query formats and rates */
2543 .open = via_playback_pcm_open,
2544 .prepare = via_playback_multi_pcm_prepare,
2545 .cleanup = via_playback_multi_pcm_cleanup
2549 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
2553 .nid = 0x13, /* NID to query formats and rates */
2555 .open = via_pcm_open_close,
2556 .prepare = via_capture_pcm_prepare,
2557 .cleanup = via_capture_pcm_cleanup,
2558 .close = via_pcm_open_close
2562 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
2566 /* NID is set in via_build_pcms */
2568 .open = via_dig_playback_pcm_open,
2569 .close = via_dig_playback_pcm_close,
2570 .prepare = via_dig_playback_pcm_prepare,
2571 .cleanup = via_dig_playback_pcm_cleanup
2575 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
2581 /* fill in the dac_nids table from the parsed pin configuration */
2582 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
2583 const struct auto_pin_cfg *cfg)
2588 spec->multiout.num_dacs = cfg->line_outs;
2590 spec->multiout.dac_nids = spec->private_dac_nids;
2592 for (i = 0; i < 4; i++) {
2593 nid = cfg->line_out_pins[i];
2595 /* config dac list */
2597 case AUTO_SEQ_FRONT:
2598 spec->multiout.dac_nids[i] = 0x10;
2600 case AUTO_SEQ_CENLFE:
2601 spec->multiout.dac_nids[i] = 0x24;
2603 case AUTO_SEQ_SURROUND:
2604 spec->multiout.dac_nids[i] = 0x11;
2607 spec->multiout.dac_nids[i] = 0x25;
2616 /* add playback controls from the parsed DAC table */
2617 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
2618 const struct auto_pin_cfg *cfg)
2621 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2622 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
2623 hda_nid_t nid, nid_vol = 0;
2626 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2627 nid = cfg->line_out_pins[i];
2632 nid_vol = nid_vols[i];
2634 if (i == AUTO_SEQ_CENLFE) {
2636 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2637 "Center Playback Volume",
2638 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2642 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2643 "LFE Playback Volume",
2644 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2648 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2649 "Center Playback Switch",
2650 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2654 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2655 "LFE Playback Switch",
2656 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2660 } else if (i == AUTO_SEQ_FRONT) {
2661 /* add control to mixer index 0 */
2662 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2663 "Master Front Playback Volume",
2664 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2668 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2669 "Master Front Playback Switch",
2670 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2675 /* add control to PW3 */
2676 sprintf(name, "%s Playback Volume", chname[i]);
2677 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2678 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2682 sprintf(name, "%s Playback Switch", chname[i]);
2683 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2684 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2689 sprintf(name, "%s Playback Volume", chname[i]);
2690 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2691 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2695 sprintf(name, "%s Playback Switch", chname[i]);
2696 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2697 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2707 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2714 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
2715 spec->hp_independent_mode_index = 1;
2717 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2718 "Headphone Playback Volume",
2719 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2722 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2723 "Headphone Playback Switch",
2724 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2728 create_hp_imux(spec);
2733 /* create playback/capture controls for input pins */
2734 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
2735 const struct auto_pin_cfg *cfg)
2737 static char *labels[] = {
2738 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2740 struct hda_input_mux *imux = &spec->private_imux[0];
2741 int i, err, idx = 0;
2743 /* for internal loopback recording select */
2744 imux->items[imux->num_items].label = "Stereo Mixer";
2745 imux->items[imux->num_items].index = idx;
2748 for (i = 0; i < AUTO_PIN_LAST; i++) {
2749 if (!cfg->input_pins[i])
2752 switch (cfg->input_pins[i]) {
2753 case 0x1a: /* Mic */
2757 case 0x1b: /* Line In */
2761 case 0x1e: /* Front Mic */
2769 err = via_new_analog_input(spec, labels[i], idx, 0x16);
2772 imux->items[imux->num_items].label = labels[i];
2773 imux->items[imux->num_items].index = idx;
2779 static int vt1708B_parse_auto_config(struct hda_codec *codec)
2781 struct via_spec *spec = codec->spec;
2784 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2787 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
2790 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2791 return 0; /* can't find valid BIOS pin config */
2793 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
2796 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2799 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
2803 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2805 if (spec->autocfg.dig_outs)
2806 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2807 spec->dig_in_pin = VT1708B_DIGIN_PIN;
2808 if (spec->autocfg.dig_in_pin)
2809 spec->dig_in_nid = VT1708B_DIGIN_NID;
2811 if (spec->kctls.list)
2812 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2814 spec->input_mux = &spec->private_imux[0];
2817 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2819 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2823 #ifdef CONFIG_SND_HDA_POWER_SAVE
2824 static struct hda_amp_list vt1708B_loopbacks[] = {
2825 { 0x16, HDA_INPUT, 1 },
2826 { 0x16, HDA_INPUT, 2 },
2827 { 0x16, HDA_INPUT, 3 },
2828 { 0x16, HDA_INPUT, 4 },
2832 static int patch_vt1708S(struct hda_codec *codec);
2833 static int patch_vt1708B_8ch(struct hda_codec *codec)
2835 struct via_spec *spec;
2838 if (get_codec_type(codec) == VT1708BCE)
2839 return patch_vt1708S(codec);
2840 /* create a codec specific record */
2841 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2847 /* automatic parse from the BIOS config */
2848 err = vt1708B_parse_auto_config(codec);
2853 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2854 "from BIOS. Using genenic mode...\n");
2857 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
2858 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2860 spec->stream_name_analog = "VT1708B Analog";
2861 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
2862 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2864 spec->stream_name_digital = "VT1708B Digital";
2865 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2866 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2868 if (!spec->adc_nids && spec->input_mux) {
2869 spec->adc_nids = vt1708B_adc_nids;
2870 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2871 get_mux_nids(codec);
2872 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2876 codec->patch_ops = via_patch_ops;
2878 codec->patch_ops.init = via_auto_init;
2879 codec->patch_ops.unsol_event = via_unsol_event;
2880 #ifdef CONFIG_SND_HDA_POWER_SAVE
2881 spec->loopback.amplist = vt1708B_loopbacks;
2887 static int patch_vt1708B_4ch(struct hda_codec *codec)
2889 struct via_spec *spec;
2892 /* create a codec specific record */
2893 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2899 /* automatic parse from the BIOS config */
2900 err = vt1708B_parse_auto_config(codec);
2905 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2906 "from BIOS. Using genenic mode...\n");
2909 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
2910 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
2912 spec->stream_name_analog = "VT1708B Analog";
2913 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
2914 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
2916 spec->stream_name_digital = "VT1708B Digital";
2917 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
2918 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
2920 if (!spec->adc_nids && spec->input_mux) {
2921 spec->adc_nids = vt1708B_adc_nids;
2922 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
2923 get_mux_nids(codec);
2924 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
2928 codec->patch_ops = via_patch_ops;
2930 codec->patch_ops.init = via_auto_init;
2931 codec->patch_ops.unsol_event = via_unsol_event;
2932 #ifdef CONFIG_SND_HDA_POWER_SAVE
2933 spec->loopback.amplist = vt1708B_loopbacks;
2939 /* Patch for VT1708S */
2941 /* VT1708S software backdoor based override for buggy hardware micboost
2943 #define MIC_BOOST_VOLUME(xname, nid) { \
2944 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2947 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2948 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2949 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
2950 .info = mic_boost_volume_info, \
2951 .get = snd_hda_mixer_amp_volume_get, \
2952 .put = snd_hda_mixer_amp_volume_put, \
2953 .tlv = { .c = mic_boost_tlv }, \
2954 .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
2956 /* capture mixer elements */
2957 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
2958 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
2959 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
2960 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
2961 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
2962 MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
2963 MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
2965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2966 /* The multiple "Capture Source" controls confuse alsamixer
2967 * So call somewhat different..
2969 /* .name = "Capture Source", */
2970 .name = "Input Source",
2972 .info = via_mux_enum_info,
2973 .get = via_mux_enum_get,
2974 .put = via_mux_enum_put,
2979 static struct hda_verb vt1708S_volume_init_verbs[] = {
2980 /* Unmute ADC0-1 and set the default input to mic-in */
2981 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2982 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2984 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
2985 * analog-loopback mixer widget */
2986 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2987 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2988 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2989 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2990 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2991 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2993 /* Setup default input of PW4 to MW0 */
2994 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
2995 /* PW9, PW10 Output enable */
2996 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2997 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2998 /* Enable Mic Boost Volume backdoor */
3003 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3004 {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
3008 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3012 .nid = 0x10, /* NID to query formats and rates */
3014 .open = via_playback_pcm_open,
3015 .prepare = via_playback_pcm_prepare,
3016 .cleanup = via_playback_pcm_cleanup,
3017 .close = via_pcm_open_close
3021 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3025 .nid = 0x13, /* NID to query formats and rates */
3027 .open = via_pcm_open_close,
3028 .prepare = via_capture_pcm_prepare,
3029 .cleanup = via_capture_pcm_cleanup,
3030 .close = via_pcm_open_close
3034 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3038 /* NID is set in via_build_pcms */
3040 .open = via_dig_playback_pcm_open,
3041 .close = via_dig_playback_pcm_close,
3042 .prepare = via_dig_playback_pcm_prepare,
3043 .cleanup = via_dig_playback_pcm_cleanup
3047 /* fill in the dac_nids table from the parsed pin configuration */
3048 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3049 const struct auto_pin_cfg *cfg)
3054 spec->multiout.num_dacs = cfg->line_outs;
3056 spec->multiout.dac_nids = spec->private_dac_nids;
3058 for (i = 0; i < 4; i++) {
3059 nid = cfg->line_out_pins[i];
3061 /* config dac list */
3063 case AUTO_SEQ_FRONT:
3064 spec->multiout.dac_nids[i] = 0x10;
3066 case AUTO_SEQ_CENLFE:
3067 spec->multiout.dac_nids[i] = 0x24;
3069 case AUTO_SEQ_SURROUND:
3070 spec->multiout.dac_nids[i] = 0x11;
3073 spec->multiout.dac_nids[i] = 0x25;
3082 /* add playback controls from the parsed DAC table */
3083 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3084 const struct auto_pin_cfg *cfg)
3087 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3088 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3089 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3090 hda_nid_t nid, nid_vol, nid_mute;
3093 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3094 nid = cfg->line_out_pins[i];
3099 nid_vol = nid_vols[i];
3100 nid_mute = nid_mutes[i];
3102 if (i == AUTO_SEQ_CENLFE) {
3104 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3105 "Center Playback Volume",
3106 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3110 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3111 "LFE Playback Volume",
3112 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3116 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3117 "Center Playback Switch",
3118 HDA_COMPOSE_AMP_VAL(nid_mute,
3123 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3124 "LFE Playback Switch",
3125 HDA_COMPOSE_AMP_VAL(nid_mute,
3130 } else if (i == AUTO_SEQ_FRONT) {
3131 /* add control to mixer index 0 */
3132 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3133 "Master Front Playback Volume",
3134 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3138 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3139 "Master Front Playback Switch",
3140 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3146 sprintf(name, "%s Playback Volume", chname[i]);
3147 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3148 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3152 sprintf(name, "%s Playback Switch", chname[i]);
3153 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3154 HDA_COMPOSE_AMP_VAL(nid_mute,
3160 sprintf(name, "%s Playback Volume", chname[i]);
3161 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3162 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3166 sprintf(name, "%s Playback Switch", chname[i]);
3167 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3168 HDA_COMPOSE_AMP_VAL(nid_mute,
3179 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3186 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3187 spec->hp_independent_mode_index = 1;
3189 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3190 "Headphone Playback Volume",
3191 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3195 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3196 "Headphone Playback Switch",
3197 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3201 create_hp_imux(spec);
3206 /* create playback/capture controls for input pins */
3207 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
3208 const struct auto_pin_cfg *cfg)
3210 static char *labels[] = {
3211 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3213 struct hda_input_mux *imux = &spec->private_imux[0];
3214 int i, err, idx = 0;
3216 /* for internal loopback recording select */
3217 imux->items[imux->num_items].label = "Stereo Mixer";
3218 imux->items[imux->num_items].index = 5;
3221 for (i = 0; i < AUTO_PIN_LAST; i++) {
3222 if (!cfg->input_pins[i])
3225 switch (cfg->input_pins[i]) {
3226 case 0x1a: /* Mic */
3230 case 0x1b: /* Line In */
3234 case 0x1e: /* Front Mic */
3242 err = via_new_analog_input(spec, labels[i], idx, 0x16);
3245 imux->items[imux->num_items].label = labels[i];
3246 imux->items[imux->num_items].index = idx-1;
3252 /* fill out digital output widgets; one for master and one for slave outputs */
3253 static void fill_dig_outs(struct hda_codec *codec)
3255 struct via_spec *spec = codec->spec;
3258 for (i = 0; i < spec->autocfg.dig_outs; i++) {
3262 nid = spec->autocfg.dig_out_pins[i];
3265 conn = snd_hda_get_connections(codec, nid, &nid, 1);
3268 if (!spec->multiout.dig_out_nid)
3269 spec->multiout.dig_out_nid = nid;
3271 spec->slave_dig_outs[0] = nid;
3272 break; /* at most two dig outs */
3277 static int vt1708S_parse_auto_config(struct hda_codec *codec)
3279 struct via_spec *spec = codec->spec;
3282 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3285 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
3288 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3289 return 0; /* can't find valid BIOS pin config */
3291 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
3294 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3297 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
3301 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3303 fill_dig_outs(codec);
3305 if (spec->kctls.list)
3306 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3308 spec->input_mux = &spec->private_imux[0];
3311 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3313 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3317 #ifdef CONFIG_SND_HDA_POWER_SAVE
3318 static struct hda_amp_list vt1708S_loopbacks[] = {
3319 { 0x16, HDA_INPUT, 1 },
3320 { 0x16, HDA_INPUT, 2 },
3321 { 0x16, HDA_INPUT, 3 },
3322 { 0x16, HDA_INPUT, 4 },
3327 static int patch_vt1708S(struct hda_codec *codec)
3329 struct via_spec *spec;
3332 /* create a codec specific record */
3333 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3339 /* automatic parse from the BIOS config */
3340 err = vt1708S_parse_auto_config(codec);
3345 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3346 "from BIOS. Using genenic mode...\n");
3349 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
3350 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
3352 spec->stream_name_analog = "VT1708S Analog";
3353 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
3354 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
3356 spec->stream_name_digital = "VT1708S Digital";
3357 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
3359 if (!spec->adc_nids && spec->input_mux) {
3360 spec->adc_nids = vt1708S_adc_nids;
3361 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
3362 get_mux_nids(codec);
3363 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
3367 codec->patch_ops = via_patch_ops;
3369 codec->patch_ops.init = via_auto_init;
3370 codec->patch_ops.unsol_event = via_unsol_event;
3371 #ifdef CONFIG_SND_HDA_POWER_SAVE
3372 spec->loopback.amplist = vt1708S_loopbacks;
3375 /* correct names for VT1708BCE */
3376 if (get_codec_type(codec) == VT1708BCE) {
3377 kfree(codec->chip_name);
3378 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
3379 snprintf(codec->bus->card->mixername,
3380 sizeof(codec->bus->card->mixername),
3381 "%s %s", codec->vendor_name, codec->chip_name);
3382 spec->stream_name_analog = "VT1708BCE Analog";
3383 spec->stream_name_digital = "VT1708BCE Digital";
3388 /* Patch for VT1702 */
3390 /* capture mixer elements */
3391 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
3392 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
3393 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
3394 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
3395 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
3396 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
3397 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
3398 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
3401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3402 /* The multiple "Capture Source" controls confuse alsamixer
3403 * So call somewhat different..
3405 /* .name = "Capture Source", */
3406 .name = "Input Source",
3408 .info = via_mux_enum_info,
3409 .get = via_mux_enum_get,
3410 .put = via_mux_enum_put,
3415 static struct hda_verb vt1702_volume_init_verbs[] = {
3417 * Unmute ADC0-1 and set the default input to mic-in
3419 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3420 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3421 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3424 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3427 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
3428 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3429 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3430 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3431 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3432 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3434 /* Setup default input of PW4 to MW0 */
3435 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
3436 /* PW6 PW7 Output enable */
3437 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3438 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3442 static struct hda_verb vt1702_uniwill_init_verbs[] = {
3443 {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
3444 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
3448 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
3452 .nid = 0x10, /* NID to query formats and rates */
3454 .open = via_playback_pcm_open,
3455 .prepare = via_playback_multi_pcm_prepare,
3456 .cleanup = via_playback_multi_pcm_cleanup,
3457 .close = via_pcm_open_close
3461 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
3465 .nid = 0x12, /* NID to query formats and rates */
3467 .open = via_pcm_open_close,
3468 .prepare = via_capture_pcm_prepare,
3469 .cleanup = via_capture_pcm_cleanup,
3470 .close = via_pcm_open_close
3474 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
3478 /* NID is set in via_build_pcms */
3480 .open = via_dig_playback_pcm_open,
3481 .close = via_dig_playback_pcm_close,
3482 .prepare = via_dig_playback_pcm_prepare,
3483 .cleanup = via_dig_playback_pcm_cleanup
3487 /* fill in the dac_nids table from the parsed pin configuration */
3488 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
3489 const struct auto_pin_cfg *cfg)
3491 spec->multiout.num_dacs = 1;
3492 spec->multiout.dac_nids = spec->private_dac_nids;
3494 if (cfg->line_out_pins[0]) {
3495 /* config dac list */
3496 spec->multiout.dac_nids[0] = 0x10;
3502 /* add playback controls from the parsed DAC table */
3503 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
3504 const struct auto_pin_cfg *cfg)
3508 if (!cfg->line_out_pins[0])
3511 /* add control to mixer index 0 */
3512 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3513 "Master Front Playback Volume",
3514 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3517 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3518 "Master Front Playback Switch",
3519 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
3524 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3525 "Front Playback Volume",
3526 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
3529 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3530 "Front Playback Switch",
3531 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
3538 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3541 struct hda_input_mux *imux;
3542 static const char *texts[] = { "ON", "OFF", NULL};
3545 spec->multiout.hp_nid = 0x1D;
3546 spec->hp_independent_mode_index = 0;
3548 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3549 "Headphone Playback Volume",
3550 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
3554 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3555 "Headphone Playback Switch",
3556 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3560 imux = &spec->private_imux[1];
3562 /* for hp mode select */
3564 while (texts[i] != NULL) {
3565 imux->items[imux->num_items].label = texts[i];
3566 imux->items[imux->num_items].index = i;
3571 spec->hp_mux = &spec->private_imux[1];
3575 /* create playback/capture controls for input pins */
3576 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
3577 const struct auto_pin_cfg *cfg)
3579 static char *labels[] = {
3580 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3582 struct hda_input_mux *imux = &spec->private_imux[0];
3583 int i, err, idx = 0;
3585 /* for internal loopback recording select */
3586 imux->items[imux->num_items].label = "Stereo Mixer";
3587 imux->items[imux->num_items].index = 3;
3590 for (i = 0; i < AUTO_PIN_LAST; i++) {
3591 if (!cfg->input_pins[i])
3594 switch (cfg->input_pins[i]) {
3595 case 0x14: /* Mic */
3599 case 0x15: /* Line In */
3603 case 0x18: /* Front Mic */
3607 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
3610 imux->items[imux->num_items].label = labels[i];
3611 imux->items[imux->num_items].index = idx-1;
3617 static int vt1702_parse_auto_config(struct hda_codec *codec)
3619 struct via_spec *spec = codec->spec;
3622 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3625 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
3628 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3629 return 0; /* can't find valid BIOS pin config */
3631 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
3634 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3637 /* limit AA path volume to 0 dB */
3638 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
3639 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3640 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3641 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3642 (1 << AC_AMPCAP_MUTE_SHIFT));
3643 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
3647 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3649 fill_dig_outs(codec);
3651 if (spec->kctls.list)
3652 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3654 spec->input_mux = &spec->private_imux[0];
3657 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3662 #ifdef CONFIG_SND_HDA_POWER_SAVE
3663 static struct hda_amp_list vt1702_loopbacks[] = {
3664 { 0x1A, HDA_INPUT, 1 },
3665 { 0x1A, HDA_INPUT, 2 },
3666 { 0x1A, HDA_INPUT, 3 },
3667 { 0x1A, HDA_INPUT, 4 },
3672 static int patch_vt1702(struct hda_codec *codec)
3674 struct via_spec *spec;
3676 unsigned int response;
3677 unsigned char control;
3679 /* create a codec specific record */
3680 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3686 /* automatic parse from the BIOS config */
3687 err = vt1702_parse_auto_config(codec);
3692 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3693 "from BIOS. Using genenic mode...\n");
3696 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
3697 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
3699 spec->stream_name_analog = "VT1702 Analog";
3700 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
3701 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
3703 spec->stream_name_digital = "VT1702 Digital";
3704 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
3706 if (!spec->adc_nids && spec->input_mux) {
3707 spec->adc_nids = vt1702_adc_nids;
3708 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
3709 get_mux_nids(codec);
3710 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
3714 codec->patch_ops = via_patch_ops;
3716 codec->patch_ops.init = via_auto_init;
3717 codec->patch_ops.unsol_event = via_unsol_event;
3718 #ifdef CONFIG_SND_HDA_POWER_SAVE
3719 spec->loopback.amplist = vt1702_loopbacks;
3723 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
3724 control = (unsigned char)(response & 0xff);
3726 snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
3728 /* Enable GPIO 0&1 for volume&mute control */
3729 /* Enable GPIO 2 for DMIC-DATA */
3730 response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
3731 control = (unsigned char)((response >> 16) & 0x3f);
3732 snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
3740 static struct hda_codec_preset snd_hda_preset_via[] = {
3741 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
3742 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
3743 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
3744 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
3745 { .id = 0x1106e710, .name = "VT1709 10-Ch",
3746 .patch = patch_vt1709_10ch},
3747 { .id = 0x1106e711, .name = "VT1709 10-Ch",
3748 .patch = patch_vt1709_10ch},
3749 { .id = 0x1106e712, .name = "VT1709 10-Ch",
3750 .patch = patch_vt1709_10ch},
3751 { .id = 0x1106e713, .name = "VT1709 10-Ch",
3752 .patch = patch_vt1709_10ch},
3753 { .id = 0x1106e714, .name = "VT1709 6-Ch",
3754 .patch = patch_vt1709_6ch},
3755 { .id = 0x1106e715, .name = "VT1709 6-Ch",
3756 .patch = patch_vt1709_6ch},
3757 { .id = 0x1106e716, .name = "VT1709 6-Ch",
3758 .patch = patch_vt1709_6ch},
3759 { .id = 0x1106e717, .name = "VT1709 6-Ch",
3760 .patch = patch_vt1709_6ch},
3761 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
3762 .patch = patch_vt1708B_8ch},
3763 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
3764 .patch = patch_vt1708B_8ch},
3765 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
3766 .patch = patch_vt1708B_8ch},
3767 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
3768 .patch = patch_vt1708B_8ch},
3769 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
3770 .patch = patch_vt1708B_4ch},
3771 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
3772 .patch = patch_vt1708B_4ch},
3773 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
3774 .patch = patch_vt1708B_4ch},
3775 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
3776 .patch = patch_vt1708B_4ch},
3777 { .id = 0x11060397, .name = "VT1708S",
3778 .patch = patch_vt1708S},
3779 { .id = 0x11061397, .name = "VT1708S",
3780 .patch = patch_vt1708S},
3781 { .id = 0x11062397, .name = "VT1708S",
3782 .patch = patch_vt1708S},
3783 { .id = 0x11063397, .name = "VT1708S",
3784 .patch = patch_vt1708S},
3785 { .id = 0x11064397, .name = "VT1708S",
3786 .patch = patch_vt1708S},
3787 { .id = 0x11065397, .name = "VT1708S",
3788 .patch = patch_vt1708S},
3789 { .id = 0x11066397, .name = "VT1708S",
3790 .patch = patch_vt1708S},
3791 { .id = 0x11067397, .name = "VT1708S",
3792 .patch = patch_vt1708S},
3793 { .id = 0x11060398, .name = "VT1702",
3794 .patch = patch_vt1702},
3795 { .id = 0x11061398, .name = "VT1702",
3796 .patch = patch_vt1702},
3797 { .id = 0x11062398, .name = "VT1702",
3798 .patch = patch_vt1702},
3799 { .id = 0x11063398, .name = "VT1702",
3800 .patch = patch_vt1702},
3801 { .id = 0x11064398, .name = "VT1702",
3802 .patch = patch_vt1702},
3803 { .id = 0x11065398, .name = "VT1702",
3804 .patch = patch_vt1702},
3805 { .id = 0x11066398, .name = "VT1702",
3806 .patch = patch_vt1702},
3807 { .id = 0x11067398, .name = "VT1702",
3808 .patch = patch_vt1702},
3812 MODULE_ALIAS("snd-hda-codec-id:1106*");
3814 static struct hda_codec_preset_list via_list = {
3815 .preset = snd_hda_preset_via,
3816 .owner = THIS_MODULE,
3819 MODULE_LICENSE("GPL");
3820 MODULE_DESCRIPTION("VIA HD-audio codec");
3822 static int __init patch_via_init(void)
3824 return snd_hda_add_codec_preset(&via_list);
3827 static void __exit patch_via_exit(void)
3829 snd_hda_delete_codec_preset(&via_list);
3832 module_init(patch_via_init)
3833 module_exit(patch_via_exit)