2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 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 */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
57 #define NID_MAPPING (-1)
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
64 #define VT1708_HP_NID 0x13
65 #define VT1708_DIGOUT_NID 0x14
66 #define VT1708_DIGIN_NID 0x16
67 #define VT1708_DIGIN_PIN 0x26
68 #define VT1708_HP_PIN_NID 0x20
69 #define VT1708_CD_PIN_NID 0x24
71 #define VT1709_HP_DAC_NID 0x28
72 #define VT1709_DIGOUT_NID 0x13
73 #define VT1709_DIGIN_NID 0x17
74 #define VT1709_DIGIN_PIN 0x25
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
105 /* codec parameterization */
106 struct snd_kcontrol_new *mixers[6];
107 unsigned int num_mixers;
109 struct hda_verb *init_verbs[5];
110 unsigned int num_iverbs;
112 char *stream_name_analog;
113 struct hda_pcm_stream *stream_analog_playback;
114 struct hda_pcm_stream *stream_analog_capture;
116 char *stream_name_digital;
117 struct hda_pcm_stream *stream_digital_playback;
118 struct hda_pcm_stream *stream_digital_capture;
121 struct hda_multi_out multiout;
122 hda_nid_t slave_dig_outs[2];
125 unsigned int num_adc_nids;
127 hda_nid_t mux_nids[3];
128 hda_nid_t dig_in_nid;
129 hda_nid_t dig_in_pin;
132 const struct hda_input_mux *input_mux;
133 unsigned int cur_mux[3];
135 /* PCM information */
136 struct hda_pcm pcm_rec[3];
138 /* dynamic controls, init_verbs and input_mux */
139 struct auto_pin_cfg autocfg;
140 struct snd_array kctls;
141 struct hda_input_mux private_imux[2];
142 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
145 const struct hda_input_mux *hp_mux;
146 unsigned int hp_independent_mode;
147 unsigned int hp_independent_mode_index;
148 unsigned int smart51_enabled;
149 unsigned int dmic_enabled;
150 enum VIA_HDA_CODEC codec_type;
152 /* work to check hp jack state */
153 struct hda_codec *codec;
154 struct delayed_work vt1708_hp_work;
155 int vt1708_jack_detectect;
156 int vt1708_hp_present;
157 #ifdef CONFIG_SND_HDA_POWER_SAVE
158 struct hda_loopback_check loopback;
162 static struct via_spec * via_new_spec(struct hda_codec *codec)
164 struct via_spec *spec;
166 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
175 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
177 u32 vendor_id = codec->vendor_id;
178 u16 ven_id = vendor_id >> 16;
179 u16 dev_id = vendor_id & 0xffff;
180 enum VIA_HDA_CODEC codec_type;
183 if (ven_id != 0x1106)
184 codec_type = UNKNOWN;
185 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
187 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
188 codec_type = VT1709_10CH;
189 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
190 codec_type = VT1709_6CH;
191 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
192 codec_type = VT1708B_8CH;
193 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
194 codec_type = VT1708BCE;
195 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
196 codec_type = VT1708B_4CH;
197 else if ((dev_id & 0xfff) == 0x397
198 && (dev_id >> 12) < 8)
199 codec_type = VT1708S;
200 else if ((dev_id & 0xfff) == 0x398
201 && (dev_id >> 12) < 8)
203 else if ((dev_id & 0xfff) == 0x428
204 && (dev_id >> 12) < 8)
205 codec_type = VT1718S;
206 else if (dev_id == 0x0433 || dev_id == 0xa721)
207 codec_type = VT1716S;
208 else if (dev_id == 0x0441 || dev_id == 0x4441)
209 codec_type = VT1718S;
210 else if (dev_id == 0x0438 || dev_id == 0x4438)
211 codec_type = VT2002P;
212 else if (dev_id == 0x0448)
214 else if (dev_id == 0x0440)
215 codec_type = VT1708S;
217 codec_type = UNKNOWN;
221 #define VIA_HP_EVENT 0x01
222 #define VIA_GPIO_EVENT 0x02
223 #define VIA_JACK_EVENT 0x04
224 #define VIA_MONO_EVENT 0x08
225 #define VIA_SPEAKER_EVENT 0x10
226 #define VIA_BIND_HP_EVENT 0x20
231 VIA_CTL_WIDGET_ANALOG_MUTE,
232 VIA_CTL_WIDGET_BIND_PIN_MUTE,
242 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
243 static void set_jack_power_state(struct hda_codec *codec);
244 static int is_aa_path_mute(struct hda_codec *codec);
246 static void vt1708_start_hp_work(struct via_spec *spec)
248 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
250 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
251 !spec->vt1708_jack_detectect);
252 if (!delayed_work_pending(&spec->vt1708_hp_work))
253 schedule_delayed_work(&spec->vt1708_hp_work,
254 msecs_to_jiffies(100));
257 static void vt1708_stop_hp_work(struct via_spec *spec)
259 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
261 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
262 && !is_aa_path_mute(spec->codec))
264 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
265 !spec->vt1708_jack_detectect);
266 cancel_delayed_work_sync(&spec->vt1708_hp_work);
270 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
271 struct snd_ctl_elem_value *ucontrol)
273 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
274 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
276 set_jack_power_state(codec);
277 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
278 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
279 if (is_aa_path_mute(codec))
280 vt1708_start_hp_work(codec->spec);
282 vt1708_stop_hp_work(codec->spec);
287 /* modify .put = snd_hda_mixer_amp_switch_put */
288 #define ANALOG_INPUT_MUTE \
289 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
292 .info = snd_hda_mixer_amp_switch_info, \
293 .get = snd_hda_mixer_amp_switch_get, \
294 .put = analog_input_switch_put, \
295 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
297 static void via_hp_bind_automute(struct hda_codec *codec);
299 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
300 struct snd_ctl_elem_value *ucontrol)
302 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
303 struct via_spec *spec = codec->spec;
307 long *valp = ucontrol->value.integer.value;
309 if (strstr(kcontrol->id.name, "Switch") == NULL) {
310 snd_printd("Invalid control!\n");
313 change = snd_hda_mixer_amp_switch_put(kcontrol,
316 lmute = *valp ? 0 : HDA_AMP_MUTE;
318 rmute = *valp ? 0 : HDA_AMP_MUTE;
321 if (!spec->hp_independent_mode) {
322 for (i = 0; i < spec->autocfg.hp_outs; i++) {
323 snd_hda_codec_amp_update(
324 codec, spec->autocfg.hp_pins[i],
325 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
327 snd_hda_codec_amp_update(
328 codec, spec->autocfg.hp_pins[i],
329 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
334 if (!lmute && !rmute) {
336 for (i = 0; i < spec->autocfg.line_outs; i++)
337 snd_hda_codec_amp_stereo(
338 codec, spec->autocfg.line_out_pins[i],
339 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
341 for (i = 0; i < spec->autocfg.speaker_outs; i++)
342 snd_hda_codec_amp_stereo(
343 codec, spec->autocfg.speaker_pins[i],
344 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
346 via_hp_bind_automute(codec);
350 /* Mute all left channels */
351 for (i = 1; i < spec->autocfg.line_outs; i++)
352 snd_hda_codec_amp_update(
354 spec->autocfg.line_out_pins[i],
355 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
357 for (i = 0; i < spec->autocfg.speaker_outs; i++)
358 snd_hda_codec_amp_update(
360 spec->autocfg.speaker_pins[i],
361 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
365 /* mute all right channels */
366 for (i = 1; i < spec->autocfg.line_outs; i++)
367 snd_hda_codec_amp_update(
369 spec->autocfg.line_out_pins[i],
370 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
372 for (i = 0; i < spec->autocfg.speaker_outs; i++)
373 snd_hda_codec_amp_update(
375 spec->autocfg.speaker_pins[i],
376 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
383 #define BIND_PIN_MUTE \
384 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
387 .info = snd_hda_mixer_amp_switch_info, \
388 .get = snd_hda_mixer_amp_switch_get, \
389 .put = bind_pin_switch_put, \
390 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
392 static struct snd_kcontrol_new via_control_templates[] = {
393 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
394 HDA_CODEC_MUTE(NULL, 0, 0, 0),
399 static hda_nid_t vt1708_adc_nids[2] = {
404 static hda_nid_t vt1709_adc_nids[3] = {
409 static hda_nid_t vt1708B_adc_nids[2] = {
414 static hda_nid_t vt1708S_adc_nids[2] = {
419 static hda_nid_t vt1702_adc_nids[3] = {
424 static hda_nid_t vt1718S_adc_nids[2] = {
429 static hda_nid_t vt1716S_adc_nids[2] = {
434 static hda_nid_t vt2002P_adc_nids[2] = {
439 static hda_nid_t vt1812_adc_nids[2] = {
445 /* add dynamic controls */
446 static int __via_add_control(struct via_spec *spec, int type, const char *name,
447 int idx, unsigned long val)
449 struct snd_kcontrol_new *knew;
451 snd_array_init(&spec->kctls, sizeof(*knew), 32);
452 knew = snd_array_new(&spec->kctls);
455 *knew = via_control_templates[type];
456 knew->name = kstrdup(name, GFP_KERNEL);
459 if (get_amp_nid_(val))
460 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
461 knew->private_value = val;
465 #define via_add_control(spec, type, name, val) \
466 __via_add_control(spec, type, name, 0, val)
468 static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
469 struct snd_kcontrol_new *tmpl)
471 struct snd_kcontrol_new *knew;
473 snd_array_init(&spec->kctls, sizeof(*knew), 32);
474 knew = snd_array_new(&spec->kctls);
478 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
484 static void via_free_kctls(struct hda_codec *codec)
486 struct via_spec *spec = codec->spec;
488 if (spec->kctls.list) {
489 struct snd_kcontrol_new *kctl = spec->kctls.list;
491 for (i = 0; i < spec->kctls.used; i++)
494 snd_array_free(&spec->kctls);
497 /* create input playback/capture controls for the given pin */
498 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
499 int type_idx, int idx, int mix_nid)
504 sprintf(name, "%s Playback Volume", ctlname);
505 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
506 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
509 sprintf(name, "%s Playback Switch", ctlname);
510 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
511 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
517 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
518 hda_nid_t nid, int pin_type,
522 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
524 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
526 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
527 snd_hda_codec_write(codec, nid, 0,
528 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
532 static void via_auto_init_multi_out(struct hda_codec *codec)
534 struct via_spec *spec = codec->spec;
537 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
538 hda_nid_t nid = spec->autocfg.line_out_pins[i];
540 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
544 static void via_auto_init_hp_out(struct hda_codec *codec)
546 struct via_spec *spec = codec->spec;
550 for (i = 0; i < spec->autocfg.hp_outs; i++) {
551 pin = spec->autocfg.hp_pins[i];
552 if (pin) /* connect to front */
553 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
557 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
559 static void via_auto_init_analog_input(struct hda_codec *codec)
561 struct via_spec *spec = codec->spec;
562 const struct auto_pin_cfg *cfg = &spec->autocfg;
566 for (i = 0; i < cfg->num_inputs; i++) {
567 hda_nid_t nid = cfg->inputs[i].pin;
568 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
570 else if (i == AUTO_PIN_MIC)
574 snd_hda_codec_write(codec, nid, 0,
575 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
579 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
580 unsigned int *affected_parm)
583 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
584 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
585 >> AC_DEFCFG_MISC_SHIFT
586 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
587 unsigned present = snd_hda_jack_detect(codec, nid);
588 struct via_spec *spec = codec->spec;
589 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
590 || ((no_presence || present)
591 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
592 *affected_parm = AC_PWRST_D0; /* if it's connected */
597 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
600 static void set_jack_power_state(struct hda_codec *codec)
602 struct via_spec *spec = codec->spec;
606 if (spec->codec_type == VT1702) {
607 imux_is_smixer = snd_hda_codec_read(
608 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
610 /* PW 1/2/5 (14h/15h/18h) */
612 set_pin_power_state(codec, 0x14, &parm);
613 set_pin_power_state(codec, 0x15, &parm);
614 set_pin_power_state(codec, 0x18, &parm);
616 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
617 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
618 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
620 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
622 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
624 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
628 /* PW 3/4 (16h/17h) */
630 set_pin_power_state(codec, 0x16, &parm);
631 set_pin_power_state(codec, 0x17, &parm);
632 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
633 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
634 imux_is_smixer ? AC_PWRST_D0 : parm);
635 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
637 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
639 } else if (spec->codec_type == VT1708B_8CH
640 || spec->codec_type == VT1708B_4CH
641 || spec->codec_type == VT1708S) {
642 /* SW0 (17h) = stereo mixer */
643 int is_8ch = spec->codec_type != VT1708B_4CH;
644 imux_is_smixer = snd_hda_codec_read(
645 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
646 == ((spec->codec_type == VT1708S) ? 5 : 0);
648 /* PW 1/2/5 (1ah/1bh/1eh) */
650 set_pin_power_state(codec, 0x1a, &parm);
651 set_pin_power_state(codec, 0x1b, &parm);
652 set_pin_power_state(codec, 0x1e, &parm);
655 /* SW0 (17h), AIW 0/1 (13h/14h) */
656 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
658 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
660 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
664 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
666 set_pin_power_state(codec, 0x19, &parm);
667 if (spec->smart51_enabled)
669 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
671 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
674 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
677 set_pin_power_state(codec, 0x22, &parm);
678 if (spec->smart51_enabled)
680 snd_hda_codec_write(codec, 0x26, 0,
681 AC_VERB_SET_POWER_STATE, parm);
682 snd_hda_codec_write(codec, 0x24, 0,
683 AC_VERB_SET_POWER_STATE, parm);
686 /* PW 3/4/7 (1ch/1dh/23h) */
688 /* force to D0 for internal Speaker */
689 set_pin_power_state(codec, 0x1c, &parm);
690 set_pin_power_state(codec, 0x1d, &parm);
692 set_pin_power_state(codec, 0x23, &parm);
693 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
694 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
695 imux_is_smixer ? AC_PWRST_D0 : parm);
696 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
699 snd_hda_codec_write(codec, 0x25, 0,
700 AC_VERB_SET_POWER_STATE, parm);
701 snd_hda_codec_write(codec, 0x27, 0,
702 AC_VERB_SET_POWER_STATE, parm);
704 } else if (spec->codec_type == VT1718S) {
705 /* MUX6 (1eh) = stereo mixer */
706 imux_is_smixer = snd_hda_codec_read(
707 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
709 /* PW 5/6/7 (29h/2ah/2bh) */
711 set_pin_power_state(codec, 0x29, &parm);
712 set_pin_power_state(codec, 0x2a, &parm);
713 set_pin_power_state(codec, 0x2b, &parm);
716 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
717 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
719 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
721 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
723 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
727 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
729 set_pin_power_state(codec, 0x27, &parm);
730 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
732 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
735 /* PW2 (26h), AOW2 (ah) */
737 set_pin_power_state(codec, 0x26, &parm);
738 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
741 /* PW0/1 (24h/25h) */
743 set_pin_power_state(codec, 0x24, &parm);
744 set_pin_power_state(codec, 0x25, &parm);
745 if (!spec->hp_independent_mode) /* check for redirected HP */
746 set_pin_power_state(codec, 0x28, &parm);
747 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
749 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
751 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
752 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
753 imux_is_smixer ? AC_PWRST_D0 : parm);
754 if (spec->hp_independent_mode) {
755 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
757 set_pin_power_state(codec, 0x28, &parm);
758 snd_hda_codec_write(codec, 0x1b, 0,
759 AC_VERB_SET_POWER_STATE, parm);
760 snd_hda_codec_write(codec, 0x34, 0,
761 AC_VERB_SET_POWER_STATE, parm);
762 snd_hda_codec_write(codec, 0xc, 0,
763 AC_VERB_SET_POWER_STATE, parm);
765 } else if (spec->codec_type == VT1716S) {
766 unsigned int mono_out, present;
767 /* SW0 (17h) = stereo mixer */
768 imux_is_smixer = snd_hda_codec_read(
769 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
771 /* PW 1/2/5 (1ah/1bh/1eh) */
773 set_pin_power_state(codec, 0x1a, &parm);
774 set_pin_power_state(codec, 0x1b, &parm);
775 set_pin_power_state(codec, 0x1e, &parm);
778 /* SW0 (17h), AIW0(13h) */
779 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
781 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
785 set_pin_power_state(codec, 0x1e, &parm);
787 if (spec->dmic_enabled)
788 set_pin_power_state(codec, 0x22, &parm);
792 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
794 /* SW2(26h), AIW1(14h) */
795 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
797 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
801 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
803 set_pin_power_state(codec, 0x19, &parm);
804 /* Smart 5.1 PW2(1bh) */
805 if (spec->smart51_enabled)
806 set_pin_power_state(codec, 0x1b, &parm);
807 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
809 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
812 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
814 set_pin_power_state(codec, 0x23, &parm);
815 /* Smart 5.1 PW1(1ah) */
816 if (spec->smart51_enabled)
817 set_pin_power_state(codec, 0x1a, &parm);
818 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
821 /* Smart 5.1 PW5(1eh) */
822 if (spec->smart51_enabled)
823 set_pin_power_state(codec, 0x1e, &parm);
824 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
828 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
829 present = snd_hda_jack_detect(codec, 0x1c);
833 present = snd_hda_jack_detect(codec, 0x1d);
834 if (!spec->hp_independent_mode && present)
839 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
840 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
842 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
844 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
847 /* PW 3/4 (1ch/1dh) */
849 set_pin_power_state(codec, 0x1c, &parm);
850 set_pin_power_state(codec, 0x1d, &parm);
851 /* HP Independent Mode, power on AOW3 */
852 if (spec->hp_independent_mode)
853 snd_hda_codec_write(codec, 0x25, 0,
854 AC_VERB_SET_POWER_STATE, parm);
856 /* force to D0 for internal Speaker */
857 /* MW0 (16h), AOW0 (10h) */
858 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
859 imux_is_smixer ? AC_PWRST_D0 : parm);
860 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
861 mono_out ? AC_PWRST_D0 : parm);
862 } else if (spec->codec_type == VT2002P) {
863 unsigned int present;
864 /* MUX9 (1eh) = stereo mixer */
865 imux_is_smixer = snd_hda_codec_read(
866 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
868 /* PW 5/6/7 (29h/2ah/2bh) */
870 set_pin_power_state(codec, 0x29, &parm);
871 set_pin_power_state(codec, 0x2a, &parm);
872 set_pin_power_state(codec, 0x2b, &parm);
875 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
876 snd_hda_codec_write(codec, 0x1e, 0,
877 AC_VERB_SET_POWER_STATE, parm);
878 snd_hda_codec_write(codec, 0x1f, 0,
879 AC_VERB_SET_POWER_STATE, parm);
880 snd_hda_codec_write(codec, 0x10, 0,
881 AC_VERB_SET_POWER_STATE, parm);
882 snd_hda_codec_write(codec, 0x11, 0,
883 AC_VERB_SET_POWER_STATE, parm);
887 snd_hda_codec_write(codec, 0x8, 0,
888 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
890 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
892 set_pin_power_state(codec, 0x26, &parm);
893 snd_hda_codec_write(codec, 0x1c, 0,
894 AC_VERB_SET_POWER_STATE, parm);
895 snd_hda_codec_write(codec, 0x37,
896 0, AC_VERB_SET_POWER_STATE, parm);
898 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
900 set_pin_power_state(codec, 0x25, &parm);
901 snd_hda_codec_write(codec, 0x19, 0,
902 AC_VERB_SET_POWER_STATE, parm);
903 snd_hda_codec_write(codec, 0x35, 0,
904 AC_VERB_SET_POWER_STATE, parm);
905 if (spec->hp_independent_mode) {
906 snd_hda_codec_write(codec, 0x9, 0,
907 AC_VERB_SET_POWER_STATE, parm);
911 /* PW0 (24h), MW0(18h), MUX0(34h) */
912 present = snd_hda_jack_detect(codec, 0x25);
914 set_pin_power_state(codec, 0x24, &parm);
918 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
921 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
925 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
928 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
932 /* PW15 (31h), MW8(17h), MUX8(3bh) */
933 present = snd_hda_jack_detect(codec, 0x26);
935 set_pin_power_state(codec, 0x31, &parm);
939 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
942 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
946 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
949 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
953 if (imux_is_smixer || !is_aa_path_mute(codec))
956 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
960 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
961 } else if (spec->codec_type == VT1812) {
962 unsigned int present;
963 /* MUX10 (1eh) = stereo mixer */
964 imux_is_smixer = snd_hda_codec_read(
965 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
967 /* PW 5/6/7 (29h/2ah/2bh) */
969 set_pin_power_state(codec, 0x29, &parm);
970 set_pin_power_state(codec, 0x2a, &parm);
971 set_pin_power_state(codec, 0x2b, &parm);
974 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
975 snd_hda_codec_write(codec, 0x1e, 0,
976 AC_VERB_SET_POWER_STATE, parm);
977 snd_hda_codec_write(codec, 0x1f, 0,
978 AC_VERB_SET_POWER_STATE, parm);
979 snd_hda_codec_write(codec, 0x10, 0,
980 AC_VERB_SET_POWER_STATE, parm);
981 snd_hda_codec_write(codec, 0x11, 0,
982 AC_VERB_SET_POWER_STATE, parm);
986 snd_hda_codec_write(codec, 0x8, 0,
987 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
989 /* PW4 (28h), MW4 (18h), MUX4(38h) */
991 set_pin_power_state(codec, 0x28, &parm);
992 snd_hda_codec_write(codec, 0x18, 0,
993 AC_VERB_SET_POWER_STATE, parm);
994 snd_hda_codec_write(codec, 0x38, 0,
995 AC_VERB_SET_POWER_STATE, parm);
997 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
999 set_pin_power_state(codec, 0x25, &parm);
1000 snd_hda_codec_write(codec, 0x15, 0,
1001 AC_VERB_SET_POWER_STATE, parm);
1002 snd_hda_codec_write(codec, 0x35, 0,
1003 AC_VERB_SET_POWER_STATE, parm);
1004 if (spec->hp_independent_mode) {
1005 snd_hda_codec_write(codec, 0x9, 0,
1006 AC_VERB_SET_POWER_STATE, parm);
1009 /* Internal Speaker */
1010 /* PW0 (24h), MW0(14h), MUX0(34h) */
1011 present = snd_hda_jack_detect(codec, 0x25);
1013 set_pin_power_state(codec, 0x24, &parm);
1015 snd_hda_codec_write(codec, 0x14, 0,
1016 AC_VERB_SET_POWER_STATE,
1018 snd_hda_codec_write(codec, 0x34, 0,
1019 AC_VERB_SET_POWER_STATE,
1022 snd_hda_codec_write(codec, 0x14, 0,
1023 AC_VERB_SET_POWER_STATE,
1025 snd_hda_codec_write(codec, 0x34, 0,
1026 AC_VERB_SET_POWER_STATE,
1030 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1031 present = snd_hda_jack_detect(codec, 0x28);
1033 set_pin_power_state(codec, 0x31, &parm);
1035 snd_hda_codec_write(codec, 0x1c, 0,
1036 AC_VERB_SET_POWER_STATE,
1038 snd_hda_codec_write(codec, 0x3c, 0,
1039 AC_VERB_SET_POWER_STATE,
1041 snd_hda_codec_write(codec, 0x3e, 0,
1042 AC_VERB_SET_POWER_STATE,
1045 snd_hda_codec_write(codec, 0x1c, 0,
1046 AC_VERB_SET_POWER_STATE,
1048 snd_hda_codec_write(codec, 0x3c, 0,
1049 AC_VERB_SET_POWER_STATE,
1051 snd_hda_codec_write(codec, 0x3e, 0,
1052 AC_VERB_SET_POWER_STATE,
1056 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1058 set_pin_power_state(codec, 0x33, &parm);
1059 snd_hda_codec_write(codec, 0x1d, 0,
1060 AC_VERB_SET_POWER_STATE, parm);
1061 snd_hda_codec_write(codec, 0x3d, 0,
1062 AC_VERB_SET_POWER_STATE, parm);
1065 if (imux_is_smixer || !is_aa_path_mute(codec))
1066 snd_hda_codec_write(
1068 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1070 snd_hda_codec_write(
1072 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1077 * input MUX handling
1079 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1080 struct snd_ctl_elem_info *uinfo)
1082 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1083 struct via_spec *spec = codec->spec;
1084 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1087 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1088 struct snd_ctl_elem_value *ucontrol)
1090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1091 struct via_spec *spec = codec->spec;
1092 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1094 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1098 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1099 struct snd_ctl_elem_value *ucontrol)
1101 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1102 struct via_spec *spec = codec->spec;
1103 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1105 if (!spec->mux_nids[adc_idx])
1107 /* switch to D0 beofre change index */
1108 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1109 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1110 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1111 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1112 /* update jack power state */
1113 set_jack_power_state(codec);
1115 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1116 spec->mux_nids[adc_idx],
1117 &spec->cur_mux[adc_idx]);
1120 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1121 struct snd_ctl_elem_info *uinfo)
1123 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1124 struct via_spec *spec = codec->spec;
1125 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1128 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1129 struct snd_ctl_elem_value *ucontrol)
1131 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1132 hda_nid_t nid = kcontrol->private_value;
1133 unsigned int pinsel;
1135 /* use !! to translate conn sel 2 for VT1718S */
1136 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1137 AC_VERB_GET_CONNECT_SEL,
1139 ucontrol->value.enumerated.item[0] = pinsel;
1144 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1146 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1148 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1149 ctl->vd[0].access |= active
1150 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1151 snd_ctl_notify(codec->bus->card,
1152 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1156 static hda_nid_t side_mute_channel(struct via_spec *spec)
1158 switch (spec->codec_type) {
1159 case VT1708: return 0x1b;
1160 case VT1709_10CH: return 0x29;
1161 case VT1708B_8CH: /* fall thru */
1162 case VT1708S: return 0x27;
1167 static int update_side_mute_status(struct hda_codec *codec)
1169 /* mute side channel */
1170 struct via_spec *spec = codec->spec;
1171 unsigned int parm = spec->hp_independent_mode
1172 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1173 hda_nid_t sw3 = side_mute_channel(spec);
1176 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1181 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1182 struct snd_ctl_elem_value *ucontrol)
1184 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1185 struct via_spec *spec = codec->spec;
1186 hda_nid_t nid = kcontrol->private_value;
1187 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1188 /* Get Independent Mode index of headphone pin widget */
1189 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1191 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
1193 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1194 != spec->multiout.dac_nids[HDA_FRONT])
1195 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1198 update_side_mute_status(codec);
1199 /* update HP volume/swtich active state */
1200 if (spec->codec_type == VT1708S
1201 || spec->codec_type == VT1702
1202 || spec->codec_type == VT1718S
1203 || spec->codec_type == VT1716S
1204 || spec->codec_type == VT2002P
1205 || spec->codec_type == VT1812) {
1206 activate_ctl(codec, "Headphone Playback Volume",
1207 spec->hp_independent_mode);
1208 activate_ctl(codec, "Headphone Playback Switch",
1209 spec->hp_independent_mode);
1214 static struct snd_kcontrol_new via_hp_mixer[2] = {
1216 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1217 .name = "Independent HP",
1218 .info = via_independent_hp_info,
1219 .get = via_independent_hp_get,
1220 .put = via_independent_hp_put,
1223 .iface = NID_MAPPING,
1224 .name = "Independent HP",
1228 static int via_hp_build(struct hda_codec *codec)
1230 struct via_spec *spec = codec->spec;
1231 struct snd_kcontrol_new *knew;
1234 hda_nid_t conn[HDA_MAX_CONNECTIONS];
1236 switch (spec->codec_type) {
1247 nid = spec->autocfg.hp_pins[0];
1251 nums = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS);
1255 knew = via_clone_control(spec, &via_hp_mixer[0]);
1259 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1260 knew->private_value = nid;
1262 knew = via_clone_control(spec, &via_hp_mixer[1]);
1265 knew->subdevice = side_mute_channel(spec);
1270 static void notify_aa_path_ctls(struct hda_codec *codec)
1273 struct snd_ctl_elem_id id;
1274 const char *labels[] = {"Mic", "Front Mic", "Line"};
1276 memset(&id, 0, sizeof(id));
1277 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1278 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1279 sprintf(id.name, "%s Playback Volume", labels[i]);
1280 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1285 static void mute_aa_path(struct hda_codec *codec, int mute)
1287 struct via_spec *spec = codec->spec;
1288 hda_nid_t nid_mixer;
1292 /* get nid of MW0 and start & end index */
1293 switch (spec->codec_type) {
1316 /* check AA path's mute status */
1317 for (i = start_idx; i <= end_idx; i++) {
1318 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1319 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1323 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1325 const struct auto_pin_cfg *cfg = &spec->autocfg;
1328 for (i = 0; i < cfg->num_inputs; i++) {
1329 if (pin == cfg->inputs[i].pin)
1330 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
1335 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1336 struct snd_ctl_elem_info *uinfo)
1338 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1340 uinfo->value.integer.min = 0;
1341 uinfo->value.integer.max = 1;
1345 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1346 struct snd_ctl_elem_value *ucontrol)
1348 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1349 struct via_spec *spec = codec->spec;
1350 const struct auto_pin_cfg *cfg = &spec->autocfg;
1354 for (i = 0; i < cfg->num_inputs; i++) {
1355 hda_nid_t nid = cfg->inputs[i].pin;
1356 int ctl = snd_hda_codec_read(codec, nid, 0,
1357 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1358 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1360 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1361 spec->hp_independent_mode && spec->codec_type != VT1718S)
1362 continue; /* ignore FMic for independent HP */
1363 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
1366 *ucontrol->value.integer.value = on;
1370 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1371 struct snd_ctl_elem_value *ucontrol)
1373 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1374 struct via_spec *spec = codec->spec;
1375 const struct auto_pin_cfg *cfg = &spec->autocfg;
1376 int out_in = *ucontrol->value.integer.value
1377 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1380 for (i = 0; i < cfg->num_inputs; i++) {
1381 hda_nid_t nid = cfg->inputs[i].pin;
1384 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1386 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1387 spec->hp_independent_mode && spec->codec_type != VT1718S)
1388 continue; /* don't retask FMic for independent HP */
1390 parm = snd_hda_codec_read(codec, nid, 0,
1391 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1392 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1394 snd_hda_codec_write(codec, nid, 0,
1395 AC_VERB_SET_PIN_WIDGET_CONTROL,
1397 if (out_in == AC_PINCTL_OUT_EN) {
1398 mute_aa_path(codec, 1);
1399 notify_aa_path_ctls(codec);
1401 if (spec->codec_type == VT1718S) {
1402 snd_hda_codec_amp_stereo(
1403 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1406 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
1407 if (spec->codec_type == VT1708S
1408 || spec->codec_type == VT1716S) {
1409 /* input = index 1 (AOW3) */
1410 snd_hda_codec_write(
1412 AC_VERB_SET_CONNECT_SEL, 1);
1413 snd_hda_codec_amp_stereo(
1414 codec, nid, HDA_OUTPUT,
1415 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1419 spec->smart51_enabled = *ucontrol->value.integer.value;
1420 set_jack_power_state(codec);
1424 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1426 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1427 .name = "Smart 5.1",
1429 .info = via_smart51_info,
1430 .get = via_smart51_get,
1431 .put = via_smart51_put,
1434 .iface = NID_MAPPING,
1435 .name = "Smart 5.1",
1439 static int via_smart51_build(struct via_spec *spec)
1441 struct snd_kcontrol_new *knew;
1442 const struct auto_pin_cfg *cfg = &spec->autocfg;
1446 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1450 for (i = 0; i < cfg->num_inputs; i++) {
1451 nid = cfg->inputs[i].pin;
1452 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1453 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1456 knew->subdevice = nid;
1464 /* capture mixer elements */
1465 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1466 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1467 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1468 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1469 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1471 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1472 /* The multiple "Capture Source" controls confuse alsamixer
1473 * So call somewhat different..
1475 /* .name = "Capture Source", */
1476 .name = "Input Source",
1478 .info = via_mux_enum_info,
1479 .get = via_mux_enum_get,
1480 .put = via_mux_enum_put,
1485 /* check AA path's mute statue */
1486 static int is_aa_path_mute(struct hda_codec *codec)
1489 hda_nid_t nid_mixer;
1493 struct via_spec *spec = codec->spec;
1494 /* get nid of MW0 and start & end index */
1495 switch (spec->codec_type) {
1523 /* check AA path's mute status */
1524 for (i = start_idx; i <= end_idx; i++) {
1525 unsigned int con_list = snd_hda_codec_read(
1526 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1527 int shift = 8 * (i % 4);
1528 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1529 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1530 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1531 /* check mute status while the pin is connected */
1532 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1534 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1536 if (!mute_l || !mute_r) {
1545 /* enter/exit analog low-current mode */
1546 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1548 struct via_spec *spec = codec->spec;
1549 static int saved_stream_idle = 1; /* saved stream idle status */
1550 int enable = is_aa_path_mute(codec);
1551 unsigned int verb = 0;
1552 unsigned int parm = 0;
1554 if (stream_idle == -1) /* stream status did not change */
1555 enable = enable && saved_stream_idle;
1557 enable = enable && stream_idle;
1558 saved_stream_idle = stream_idle;
1561 /* decide low current mode's verb & parameter */
1562 switch (spec->codec_type) {
1566 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1572 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1576 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1581 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1584 return; /* other codecs are not supported */
1587 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1591 * generic initialization of ADC, input mixers and output mixers
1593 static struct hda_verb vt1708_volume_init_verbs[] = {
1595 * Unmute ADC0-1 and set the default input to mic-in
1597 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1598 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1601 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1604 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1605 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1606 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1607 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1608 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1609 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1612 * Set up output mixers (0x19 - 0x1b)
1614 /* set vol=0 to output mixers */
1615 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1616 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1617 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1619 /* Setup default input MW0 to PW4 */
1620 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1621 /* PW9 Output enable */
1622 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1626 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1627 struct hda_codec *codec,
1628 struct snd_pcm_substream *substream)
1630 struct via_spec *spec = codec->spec;
1631 int idle = substream->pstr->substream_opened == 1
1632 && substream->ref_count == 0;
1633 analog_low_current_mode(codec, idle);
1634 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1638 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1639 unsigned int stream_tag,
1640 unsigned int format,
1641 struct snd_pcm_substream *substream)
1643 struct via_spec *spec = codec->spec;
1644 struct hda_multi_out *mout = &spec->multiout;
1645 hda_nid_t *nids = mout->dac_nids;
1646 int chs = substream->runtime->channels;
1649 mutex_lock(&codec->spdif_mutex);
1650 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1652 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1654 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1655 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1656 /* turn off SPDIF once; otherwise the IEC958 bits won't
1658 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1659 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1660 AC_VERB_SET_DIGI_CONVERT_1,
1662 ~AC_DIG1_ENABLE & 0xff);
1663 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1664 stream_tag, 0, format);
1665 /* turn on again (if needed) */
1666 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1667 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1668 AC_VERB_SET_DIGI_CONVERT_1,
1669 codec->spdif_ctls & 0xff);
1671 mout->dig_out_used = 0;
1672 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1676 mutex_unlock(&codec->spdif_mutex);
1679 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1682 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1683 && !spec->hp_independent_mode)
1684 /* headphone out will just decode front left/right (stereo) */
1685 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1688 /* extra outputs copied from front */
1689 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1690 if (mout->extra_out_nid[i])
1691 snd_hda_codec_setup_stream(codec,
1692 mout->extra_out_nid[i],
1693 stream_tag, 0, format);
1696 for (i = 1; i < mout->num_dacs; i++) {
1697 if (chs >= (i + 1) * 2) /* independent out */
1698 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1700 else /* copy front */
1701 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1706 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1707 struct hda_codec *codec,
1708 unsigned int stream_tag,
1709 unsigned int format,
1710 struct snd_pcm_substream *substream)
1712 struct via_spec *spec = codec->spec;
1713 struct hda_multi_out *mout = &spec->multiout;
1714 hda_nid_t *nids = mout->dac_nids;
1716 if (substream->number == 0)
1717 playback_multi_pcm_prep_0(codec, stream_tag, format,
1720 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1721 spec->hp_independent_mode)
1722 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1723 stream_tag, 0, format);
1725 vt1708_start_hp_work(spec);
1729 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1730 struct hda_codec *codec,
1731 struct snd_pcm_substream *substream)
1733 struct via_spec *spec = codec->spec;
1734 struct hda_multi_out *mout = &spec->multiout;
1735 hda_nid_t *nids = mout->dac_nids;
1738 if (substream->number == 0) {
1739 for (i = 0; i < mout->num_dacs; i++)
1740 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1742 if (mout->hp_nid && !spec->hp_independent_mode)
1743 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1746 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1747 if (mout->extra_out_nid[i])
1748 snd_hda_codec_setup_stream(codec,
1749 mout->extra_out_nid[i],
1751 mutex_lock(&codec->spdif_mutex);
1752 if (mout->dig_out_nid &&
1753 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1754 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1756 mout->dig_out_used = 0;
1758 mutex_unlock(&codec->spdif_mutex);
1760 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1761 spec->hp_independent_mode)
1762 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1765 vt1708_stop_hp_work(spec);
1772 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1773 struct hda_codec *codec,
1774 struct snd_pcm_substream *substream)
1776 struct via_spec *spec = codec->spec;
1777 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1780 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1781 struct hda_codec *codec,
1782 struct snd_pcm_substream *substream)
1784 struct via_spec *spec = codec->spec;
1785 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1788 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1789 struct hda_codec *codec,
1790 unsigned int stream_tag,
1791 unsigned int format,
1792 struct snd_pcm_substream *substream)
1794 struct via_spec *spec = codec->spec;
1795 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1796 stream_tag, format, substream);
1799 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1800 struct hda_codec *codec,
1801 struct snd_pcm_substream *substream)
1803 struct via_spec *spec = codec->spec;
1804 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1811 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1812 struct hda_codec *codec,
1813 unsigned int stream_tag,
1814 unsigned int format,
1815 struct snd_pcm_substream *substream)
1817 struct via_spec *spec = codec->spec;
1819 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1820 stream_tag, 0, format);
1824 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1825 struct hda_codec *codec,
1826 struct snd_pcm_substream *substream)
1828 struct via_spec *spec = codec->spec;
1829 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1833 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1837 .nid = 0x10, /* NID to query formats and rates */
1839 .open = via_playback_pcm_open,
1840 .prepare = via_playback_multi_pcm_prepare,
1841 .cleanup = via_playback_multi_pcm_cleanup
1845 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1849 .nid = 0x10, /* NID to query formats and rates */
1850 /* We got noisy outputs on the right channel on VT1708 when
1851 * 24bit samples are used. Until any workaround is found,
1852 * disable the 24bit format, so far.
1854 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1856 .open = via_playback_pcm_open,
1857 .prepare = via_playback_multi_pcm_prepare,
1858 .cleanup = via_playback_multi_pcm_cleanup
1862 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1866 .nid = 0x15, /* NID to query formats and rates */
1868 .prepare = via_capture_pcm_prepare,
1869 .cleanup = via_capture_pcm_cleanup
1873 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1877 /* NID is set in via_build_pcms */
1879 .open = via_dig_playback_pcm_open,
1880 .close = via_dig_playback_pcm_close,
1881 .prepare = via_dig_playback_pcm_prepare,
1882 .cleanup = via_dig_playback_pcm_cleanup
1886 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1892 static int via_build_controls(struct hda_codec *codec)
1894 struct via_spec *spec = codec->spec;
1895 struct snd_kcontrol *kctl;
1896 struct snd_kcontrol_new *knew;
1899 for (i = 0; i < spec->num_mixers; i++) {
1900 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1905 if (spec->multiout.dig_out_nid) {
1906 err = snd_hda_create_spdif_out_ctls(codec,
1907 spec->multiout.dig_out_nid);
1910 err = snd_hda_create_spdif_share_sw(codec,
1914 spec->multiout.share_spdif = 1;
1916 if (spec->dig_in_nid) {
1917 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1922 /* assign Capture Source enums to NID */
1923 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1924 for (i = 0; kctl && i < kctl->count; i++) {
1925 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1930 /* other nid->control mapping */
1931 for (i = 0; i < spec->num_mixers; i++) {
1932 for (knew = spec->mixers[i]; knew->name; knew++) {
1933 if (knew->iface != NID_MAPPING)
1935 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1938 err = snd_hda_add_nid(codec, kctl, 0,
1943 /* init power states */
1944 set_jack_power_state(codec);
1945 analog_low_current_mode(codec, 1);
1947 via_free_kctls(codec); /* no longer needed */
1951 static int via_build_pcms(struct hda_codec *codec)
1953 struct via_spec *spec = codec->spec;
1954 struct hda_pcm *info = spec->pcm_rec;
1956 codec->num_pcms = 1;
1957 codec->pcm_info = info;
1959 info->name = spec->stream_name_analog;
1960 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1961 *(spec->stream_analog_playback);
1962 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1963 spec->multiout.dac_nids[0];
1964 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1965 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1967 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1968 spec->multiout.max_channels;
1970 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1973 info->name = spec->stream_name_digital;
1974 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1975 if (spec->multiout.dig_out_nid) {
1976 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1977 *(spec->stream_digital_playback);
1978 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1979 spec->multiout.dig_out_nid;
1981 if (spec->dig_in_nid) {
1982 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1983 *(spec->stream_digital_capture);
1984 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1992 static void via_free(struct hda_codec *codec)
1994 struct via_spec *spec = codec->spec;
1999 via_free_kctls(codec);
2000 vt1708_stop_hp_work(spec);
2004 /* mute internal speaker if HP is plugged */
2005 static void via_hp_automute(struct hda_codec *codec)
2007 unsigned int present = 0;
2008 struct via_spec *spec = codec->spec;
2010 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2012 if (!spec->hp_independent_mode) {
2013 struct snd_ctl_elem_id id;
2015 snd_hda_codec_amp_stereo(
2016 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2017 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2019 memset(&id, 0, sizeof(id));
2020 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2021 strcpy(id.name, "Front Playback Switch");
2022 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2027 /* mute mono out if HP or Line out is plugged */
2028 static void via_mono_automute(struct hda_codec *codec)
2030 unsigned int hp_present, lineout_present;
2031 struct via_spec *spec = codec->spec;
2033 if (spec->codec_type != VT1716S)
2036 lineout_present = snd_hda_jack_detect(codec,
2037 spec->autocfg.line_out_pins[0]);
2039 /* Mute Mono Out if Line Out is plugged */
2040 if (lineout_present) {
2041 snd_hda_codec_amp_stereo(
2042 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2046 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2048 if (!spec->hp_independent_mode)
2049 snd_hda_codec_amp_stereo(
2050 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2051 hp_present ? HDA_AMP_MUTE : 0);
2054 static void via_gpio_control(struct hda_codec *codec)
2056 unsigned int gpio_data;
2057 unsigned int vol_counter;
2059 unsigned int master_vol;
2061 struct via_spec *spec = codec->spec;
2063 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2064 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2066 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2067 0xF84, 0) & 0x3F0000) >> 16;
2069 vol = vol_counter & 0x1F;
2070 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2071 AC_VERB_GET_AMP_GAIN_MUTE,
2074 if (gpio_data == 0x02) {
2075 /* unmute line out */
2076 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2077 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2079 if (vol_counter & 0x20) {
2080 /* decrease volume */
2081 if (vol > master_vol)
2083 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2087 /* increase volume */
2088 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2090 ((master_vol+vol) > 0x2A) ? 0x2A :
2093 } else if (!(gpio_data & 0x02)) {
2095 snd_hda_codec_amp_stereo(codec,
2096 spec->autocfg.line_out_pins[0],
2097 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2102 /* mute Internal-Speaker if HP is plugged */
2103 static void via_speaker_automute(struct hda_codec *codec)
2105 unsigned int hp_present;
2106 struct via_spec *spec = codec->spec;
2108 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2111 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2113 if (!spec->hp_independent_mode) {
2114 struct snd_ctl_elem_id id;
2115 snd_hda_codec_amp_stereo(
2116 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2117 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2119 memset(&id, 0, sizeof(id));
2120 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2121 strcpy(id.name, "Speaker Playback Switch");
2122 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2127 /* mute line-out and internal speaker if HP is plugged */
2128 static void via_hp_bind_automute(struct hda_codec *codec)
2130 /* use long instead of int below just to avoid an internal compiler
2131 * error with gcc 4.0.x
2133 unsigned long hp_present, present = 0;
2134 struct via_spec *spec = codec->spec;
2137 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2140 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2142 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2144 if (!spec->hp_independent_mode) {
2145 /* Mute Line-Outs */
2146 for (i = 0; i < spec->autocfg.line_outs; i++)
2147 snd_hda_codec_amp_stereo(
2148 codec, spec->autocfg.line_out_pins[i],
2150 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2152 present = hp_present;
2155 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2156 snd_hda_codec_amp_stereo(
2157 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2158 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2162 /* unsolicited event for jack sensing */
2163 static void via_unsol_event(struct hda_codec *codec,
2167 if (res & VIA_HP_EVENT)
2168 via_hp_automute(codec);
2169 if (res & VIA_GPIO_EVENT)
2170 via_gpio_control(codec);
2171 if (res & VIA_JACK_EVENT)
2172 set_jack_power_state(codec);
2173 if (res & VIA_MONO_EVENT)
2174 via_mono_automute(codec);
2175 if (res & VIA_SPEAKER_EVENT)
2176 via_speaker_automute(codec);
2177 if (res & VIA_BIND_HP_EVENT)
2178 via_hp_bind_automute(codec);
2181 static int via_init(struct hda_codec *codec)
2183 struct via_spec *spec = codec->spec;
2185 for (i = 0; i < spec->num_iverbs; i++)
2186 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2188 spec->codec_type = get_codec_type(codec);
2189 if (spec->codec_type == VT1708BCE)
2190 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2192 /* Lydia Add for EAPD enable */
2193 if (!spec->dig_in_nid) { /* No Digital In connection */
2194 if (spec->dig_in_pin) {
2195 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2196 AC_VERB_SET_PIN_WIDGET_CONTROL,
2198 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2199 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2201 } else /* enable SPDIF-input pin */
2202 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2203 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2205 /* assign slave outs */
2206 if (spec->slave_dig_outs[0])
2207 codec->slave_dig_outs = spec->slave_dig_outs;
2212 #ifdef SND_HDA_NEEDS_RESUME
2213 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2215 struct via_spec *spec = codec->spec;
2216 vt1708_stop_hp_work(spec);
2221 #ifdef CONFIG_SND_HDA_POWER_SAVE
2222 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2224 struct via_spec *spec = codec->spec;
2225 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2231 static struct hda_codec_ops via_patch_ops = {
2232 .build_controls = via_build_controls,
2233 .build_pcms = via_build_pcms,
2236 #ifdef SND_HDA_NEEDS_RESUME
2237 .suspend = via_suspend,
2239 #ifdef CONFIG_SND_HDA_POWER_SAVE
2240 .check_power_status = via_check_power_status,
2244 /* fill in the dac_nids table from the parsed pin configuration */
2245 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2246 const struct auto_pin_cfg *cfg)
2251 spec->multiout.num_dacs = cfg->line_outs;
2253 spec->multiout.dac_nids = spec->private_dac_nids;
2255 for (i = 0; i < 4; i++) {
2256 nid = cfg->line_out_pins[i];
2258 /* config dac list */
2260 case AUTO_SEQ_FRONT:
2261 spec->multiout.dac_nids[i] = 0x10;
2263 case AUTO_SEQ_CENLFE:
2264 spec->multiout.dac_nids[i] = 0x12;
2266 case AUTO_SEQ_SURROUND:
2267 spec->multiout.dac_nids[i] = 0x11;
2270 spec->multiout.dac_nids[i] = 0x13;
2279 /* add playback controls from the parsed DAC table */
2280 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2281 const struct auto_pin_cfg *cfg)
2284 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2285 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2288 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2289 nid = cfg->line_out_pins[i];
2294 nid_vol = nid_vols[i];
2296 if (i == AUTO_SEQ_CENLFE) {
2298 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2299 "Center Playback Volume",
2300 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2304 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2305 "LFE Playback Volume",
2306 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2310 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2311 "Center Playback Switch",
2312 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2316 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2317 "LFE Playback Switch",
2318 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2322 } else if (i == AUTO_SEQ_FRONT) {
2323 /* add control to mixer index 0 */
2324 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2325 "Master Front Playback Volume",
2326 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2330 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2331 "Master Front Playback Switch",
2332 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2337 /* add control to PW3 */
2338 sprintf(name, "%s Playback Volume", chname[i]);
2339 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2340 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2344 sprintf(name, "%s Playback Switch", chname[i]);
2345 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2346 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2351 sprintf(name, "%s Playback Volume", chname[i]);
2352 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2353 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2357 sprintf(name, "%s Playback Switch", chname[i]);
2358 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2359 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2369 static void create_hp_imux(struct via_spec *spec)
2372 struct hda_input_mux *imux = &spec->private_imux[1];
2373 static const char *texts[] = { "OFF", "ON", NULL};
2375 /* for hp mode select */
2376 for (i = 0; texts[i]; i++)
2377 snd_hda_add_imux_item(imux, texts[i], i, NULL);
2379 spec->hp_mux = &spec->private_imux[1];
2382 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2389 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2390 spec->hp_independent_mode_index = 1;
2392 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2393 "Headphone Playback Volume",
2394 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2397 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2398 "Headphone Playback Switch",
2399 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2403 create_hp_imux(spec);
2408 /* create playback/capture controls for input pins */
2409 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2410 const struct auto_pin_cfg *cfg,
2412 hda_nid_t pin_idxs[], int num_idxs)
2414 struct via_spec *spec = codec->spec;
2415 struct hda_input_mux *imux = &spec->private_imux[0];
2416 int i, err, idx, type, type_idx = 0;
2418 /* for internal loopback recording select */
2419 for (idx = 0; idx < num_idxs; idx++) {
2420 if (pin_idxs[idx] == 0xff) {
2421 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2426 for (i = 0; i < cfg->num_inputs; i++) {
2428 type = cfg->inputs[i].type;
2429 for (idx = 0; idx < num_idxs; idx++)
2430 if (pin_idxs[idx] == cfg->inputs[i].pin)
2432 if (idx >= num_idxs)
2434 if (i > 0 && type == cfg->inputs[i - 1].type)
2438 label = hda_get_autocfg_input_label(codec, cfg, i);
2439 err = via_new_analog_input(spec, label, type_idx, idx, cap_nid);
2442 snd_hda_add_imux_item(imux, label, idx, NULL);
2447 /* create playback/capture controls for input pins */
2448 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2449 const struct auto_pin_cfg *cfg)
2451 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2452 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2453 ARRAY_SIZE(pin_idxs));
2456 #ifdef CONFIG_SND_HDA_POWER_SAVE
2457 static struct hda_amp_list vt1708_loopbacks[] = {
2458 { 0x17, HDA_INPUT, 1 },
2459 { 0x17, HDA_INPUT, 2 },
2460 { 0x17, HDA_INPUT, 3 },
2461 { 0x17, HDA_INPUT, 4 },
2466 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2468 unsigned int def_conf;
2469 unsigned char seqassoc;
2471 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2472 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2473 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2474 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2475 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2476 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2477 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2483 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2484 struct snd_ctl_elem_value *ucontrol)
2486 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2487 struct via_spec *spec = codec->spec;
2489 if (spec->codec_type != VT1708)
2491 spec->vt1708_jack_detectect =
2492 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2493 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2497 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2498 struct snd_ctl_elem_value *ucontrol)
2500 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2501 struct via_spec *spec = codec->spec;
2504 if (spec->codec_type != VT1708)
2506 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2507 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2508 == !spec->vt1708_jack_detectect;
2509 if (spec->vt1708_jack_detectect) {
2510 mute_aa_path(codec, 1);
2511 notify_aa_path_ctls(codec);
2516 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2518 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2519 .name = "Jack Detect",
2521 .info = snd_ctl_boolean_mono_info,
2522 .get = vt1708_jack_detectect_get,
2523 .put = vt1708_jack_detectect_put,
2528 static int vt1708_parse_auto_config(struct hda_codec *codec)
2530 struct via_spec *spec = codec->spec;
2533 /* Add HP and CD pin config connect bit re-config action */
2534 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2535 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2537 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2540 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2543 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2544 return 0; /* can't find valid BIOS pin config */
2546 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2549 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2552 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2555 /* add jack detect on/off control */
2556 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2560 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2562 if (spec->autocfg.dig_outs)
2563 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2564 spec->dig_in_pin = VT1708_DIGIN_PIN;
2565 if (spec->autocfg.dig_in_pin)
2566 spec->dig_in_nid = VT1708_DIGIN_NID;
2568 if (spec->kctls.list)
2569 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2571 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2573 spec->input_mux = &spec->private_imux[0];
2576 via_hp_build(codec);
2578 via_smart51_build(spec);
2582 /* init callback for auto-configuration model -- overriding the default init */
2583 static int via_auto_init(struct hda_codec *codec)
2585 struct via_spec *spec = codec->spec;
2588 via_auto_init_multi_out(codec);
2589 via_auto_init_hp_out(codec);
2590 via_auto_init_analog_input(codec);
2591 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2592 via_hp_bind_automute(codec);
2594 via_hp_automute(codec);
2595 via_speaker_automute(codec);
2601 static void vt1708_update_hp_jack_state(struct work_struct *work)
2603 struct via_spec *spec = container_of(work, struct via_spec,
2604 vt1708_hp_work.work);
2605 if (spec->codec_type != VT1708)
2607 /* if jack state toggled */
2608 if (spec->vt1708_hp_present
2609 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2610 spec->vt1708_hp_present ^= 1;
2611 via_hp_automute(spec->codec);
2613 vt1708_start_hp_work(spec);
2616 static int get_mux_nids(struct hda_codec *codec)
2618 struct via_spec *spec = codec->spec;
2619 hda_nid_t nid, conn[8];
2623 for (i = 0; i < spec->num_adc_nids; i++) {
2624 nid = spec->adc_nids[i];
2626 type = get_wcaps_type(get_wcaps(codec, nid));
2627 if (type == AC_WID_PIN)
2629 n = snd_hda_get_connections(codec, nid, conn,
2634 spec->mux_nids[i] = nid;
2643 static int patch_vt1708(struct hda_codec *codec)
2645 struct via_spec *spec;
2648 /* create a codec specific record */
2649 spec = via_new_spec(codec);
2653 /* automatic parse from the BIOS config */
2654 err = vt1708_parse_auto_config(codec);
2659 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2660 "from BIOS. Using genenic mode...\n");
2664 spec->stream_name_analog = "VT1708 Analog";
2665 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2666 /* disable 32bit format on VT1708 */
2667 if (codec->vendor_id == 0x11061708)
2668 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2669 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2671 spec->stream_name_digital = "VT1708 Digital";
2672 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2673 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2676 if (!spec->adc_nids && spec->input_mux) {
2677 spec->adc_nids = vt1708_adc_nids;
2678 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2679 get_mux_nids(codec);
2680 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2684 codec->patch_ops = via_patch_ops;
2686 codec->patch_ops.init = via_auto_init;
2687 #ifdef CONFIG_SND_HDA_POWER_SAVE
2688 spec->loopback.amplist = vt1708_loopbacks;
2690 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2694 /* capture mixer elements */
2695 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2696 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2697 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2698 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2699 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2700 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2701 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2703 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2704 /* The multiple "Capture Source" controls confuse alsamixer
2705 * So call somewhat different..
2707 /* .name = "Capture Source", */
2708 .name = "Input Source",
2710 .info = via_mux_enum_info,
2711 .get = via_mux_enum_get,
2712 .put = via_mux_enum_put,
2717 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2718 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2719 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2724 * generic initialization of ADC, input mixers and output mixers
2726 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2728 * Unmute ADC0-2 and set the default input to mic-in
2730 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2731 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2732 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2735 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2738 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2739 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2740 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2741 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2742 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2743 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2746 * Set up output selector (0x1a, 0x1b, 0x29)
2748 /* set vol=0 to output mixers */
2749 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2750 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2751 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2754 * Unmute PW3 and PW4
2756 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2757 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2759 /* Set input of PW4 as MW0 */
2760 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2761 /* PW9 Output enable */
2762 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2766 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2770 .nid = 0x10, /* NID to query formats and rates */
2772 .open = via_playback_pcm_open,
2773 .prepare = via_playback_multi_pcm_prepare,
2774 .cleanup = via_playback_multi_pcm_cleanup,
2778 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2782 .nid = 0x10, /* NID to query formats and rates */
2784 .open = via_playback_pcm_open,
2785 .prepare = via_playback_multi_pcm_prepare,
2786 .cleanup = via_playback_multi_pcm_cleanup,
2790 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2794 .nid = 0x14, /* NID to query formats and rates */
2796 .prepare = via_capture_pcm_prepare,
2797 .cleanup = via_capture_pcm_cleanup
2801 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2805 /* NID is set in via_build_pcms */
2807 .open = via_dig_playback_pcm_open,
2808 .close = via_dig_playback_pcm_close
2812 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2818 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2819 const struct auto_pin_cfg *cfg)
2824 if (cfg->line_outs == 4) /* 10 channels */
2825 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2826 else if (cfg->line_outs == 3) /* 6 channels */
2827 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2829 spec->multiout.dac_nids = spec->private_dac_nids;
2831 if (cfg->line_outs == 4) { /* 10 channels */
2832 for (i = 0; i < cfg->line_outs; i++) {
2833 nid = cfg->line_out_pins[i];
2835 /* config dac list */
2837 case AUTO_SEQ_FRONT:
2839 spec->multiout.dac_nids[i] = 0x10;
2841 case AUTO_SEQ_CENLFE:
2843 spec->multiout.dac_nids[i] = 0x12;
2845 case AUTO_SEQ_SURROUND:
2847 spec->multiout.dac_nids[i] = 0x11;
2851 spec->multiout.dac_nids[i] = 0x27;
2858 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2860 } else if (cfg->line_outs == 3) { /* 6 channels */
2861 for (i = 0; i < cfg->line_outs; i++) {
2862 nid = cfg->line_out_pins[i];
2864 /* config dac list */
2866 case AUTO_SEQ_FRONT:
2868 spec->multiout.dac_nids[i] = 0x10;
2870 case AUTO_SEQ_CENLFE:
2872 spec->multiout.dac_nids[i] = 0x12;
2874 case AUTO_SEQ_SURROUND:
2876 spec->multiout.dac_nids[i] = 0x11;
2888 /* add playback controls from the parsed DAC table */
2889 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2890 const struct auto_pin_cfg *cfg)
2893 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2894 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2897 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2898 nid = cfg->line_out_pins[i];
2903 nid_vol = nid_vols[i];
2905 if (i == AUTO_SEQ_CENLFE) {
2907 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2908 "Center Playback Volume",
2909 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2913 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2914 "LFE Playback Volume",
2915 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2919 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2920 "Center Playback Switch",
2921 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2925 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2926 "LFE Playback Switch",
2927 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2931 } else if (i == AUTO_SEQ_FRONT) {
2932 /* ADD control to mixer index 0 */
2933 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2934 "Master Front Playback Volume",
2935 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2939 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2940 "Master Front Playback Switch",
2941 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2946 /* add control to PW3 */
2947 sprintf(name, "%s Playback Volume", chname[i]);
2948 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2949 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2953 sprintf(name, "%s Playback Switch", chname[i]);
2954 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2955 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2959 } else if (i == AUTO_SEQ_SURROUND) {
2960 sprintf(name, "%s Playback Volume", chname[i]);
2961 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2962 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2966 sprintf(name, "%s Playback Switch", chname[i]);
2967 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2968 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2972 } else if (i == AUTO_SEQ_SIDE) {
2973 sprintf(name, "%s Playback Volume", chname[i]);
2974 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2975 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2979 sprintf(name, "%s Playback Switch", chname[i]);
2980 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2981 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2991 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2998 if (spec->multiout.num_dacs == 5) /* 10 channels */
2999 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
3000 else if (spec->multiout.num_dacs == 3) /* 6 channels */
3001 spec->multiout.hp_nid = 0;
3002 spec->hp_independent_mode_index = 1;
3004 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3005 "Headphone Playback Volume",
3006 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3009 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3010 "Headphone Playback Switch",
3011 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3018 /* create playback/capture controls for input pins */
3019 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
3020 const struct auto_pin_cfg *cfg)
3022 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
3023 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
3024 ARRAY_SIZE(pin_idxs));
3027 static int vt1709_parse_auto_config(struct hda_codec *codec)
3029 struct via_spec *spec = codec->spec;
3032 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3035 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3038 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3039 return 0; /* can't find valid BIOS pin config */
3041 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3044 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3047 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
3051 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3053 if (spec->autocfg.dig_outs)
3054 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3055 spec->dig_in_pin = VT1709_DIGIN_PIN;
3056 if (spec->autocfg.dig_in_pin)
3057 spec->dig_in_nid = VT1709_DIGIN_NID;
3059 if (spec->kctls.list)
3060 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3062 spec->input_mux = &spec->private_imux[0];
3065 via_hp_build(codec);
3067 via_smart51_build(spec);
3071 #ifdef CONFIG_SND_HDA_POWER_SAVE
3072 static struct hda_amp_list vt1709_loopbacks[] = {
3073 { 0x18, HDA_INPUT, 1 },
3074 { 0x18, HDA_INPUT, 2 },
3075 { 0x18, HDA_INPUT, 3 },
3076 { 0x18, HDA_INPUT, 4 },
3081 static int patch_vt1709_10ch(struct hda_codec *codec)
3083 struct via_spec *spec;
3086 /* create a codec specific record */
3087 spec = via_new_spec(codec);
3091 err = vt1709_parse_auto_config(codec);
3096 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3097 "Using genenic mode...\n");
3100 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3101 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3103 spec->stream_name_analog = "VT1709 Analog";
3104 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3105 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3107 spec->stream_name_digital = "VT1709 Digital";
3108 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3109 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3112 if (!spec->adc_nids && spec->input_mux) {
3113 spec->adc_nids = vt1709_adc_nids;
3114 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3115 get_mux_nids(codec);
3116 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3120 codec->patch_ops = via_patch_ops;
3122 codec->patch_ops.init = via_auto_init;
3123 codec->patch_ops.unsol_event = via_unsol_event;
3124 #ifdef CONFIG_SND_HDA_POWER_SAVE
3125 spec->loopback.amplist = vt1709_loopbacks;
3131 * generic initialization of ADC, input mixers and output mixers
3133 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3135 * Unmute ADC0-2 and set the default input to mic-in
3137 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3138 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3139 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3142 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3145 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3146 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3147 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3148 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3149 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3150 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3153 * Set up output selector (0x1a, 0x1b, 0x29)
3155 /* set vol=0 to output mixers */
3156 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3157 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3158 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3161 * Unmute PW3 and PW4
3163 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3164 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3166 /* Set input of PW4 as MW0 */
3167 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3168 /* PW9 Output enable */
3169 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3173 static int patch_vt1709_6ch(struct hda_codec *codec)
3175 struct via_spec *spec;
3178 /* create a codec specific record */
3179 spec = via_new_spec(codec);
3183 err = vt1709_parse_auto_config(codec);
3188 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3189 "Using genenic mode...\n");
3192 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3193 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3195 spec->stream_name_analog = "VT1709 Analog";
3196 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3197 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3199 spec->stream_name_digital = "VT1709 Digital";
3200 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3201 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3204 if (!spec->adc_nids && spec->input_mux) {
3205 spec->adc_nids = vt1709_adc_nids;
3206 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3207 get_mux_nids(codec);
3208 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3212 codec->patch_ops = via_patch_ops;
3214 codec->patch_ops.init = via_auto_init;
3215 codec->patch_ops.unsol_event = via_unsol_event;
3216 #ifdef CONFIG_SND_HDA_POWER_SAVE
3217 spec->loopback.amplist = vt1709_loopbacks;
3222 /* capture mixer elements */
3223 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3224 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3225 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3226 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3227 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3229 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3230 /* The multiple "Capture Source" controls confuse alsamixer
3231 * So call somewhat different..
3233 /* .name = "Capture Source", */
3234 .name = "Input Source",
3236 .info = via_mux_enum_info,
3237 .get = via_mux_enum_get,
3238 .put = via_mux_enum_put,
3243 * generic initialization of ADC, input mixers and output mixers
3245 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3247 * Unmute ADC0-1 and set the default input to mic-in
3249 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3250 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3253 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3256 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3257 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3258 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3259 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3260 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3261 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3264 * Set up output mixers
3266 /* set vol=0 to output mixers */
3267 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3268 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3269 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3271 /* Setup default input to PW4 */
3272 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3273 /* PW9 Output enable */
3274 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3275 /* PW10 Input enable */
3276 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3280 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3282 * Unmute ADC0-1 and set the default input to mic-in
3284 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3285 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3288 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3291 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3292 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3293 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3294 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3295 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3296 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3299 * Set up output mixers
3301 /* set vol=0 to output mixers */
3302 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3303 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3304 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3306 /* Setup default input of PW4 to MW0 */
3307 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3308 /* PW9 Output enable */
3309 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3310 /* PW10 Input enable */
3311 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3315 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3316 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3317 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3318 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3319 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3320 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3321 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3322 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3323 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3324 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3328 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3329 struct hda_codec *codec,
3330 struct snd_pcm_substream *substream)
3332 int idle = substream->pstr->substream_opened == 1
3333 && substream->ref_count == 0;
3335 analog_low_current_mode(codec, idle);
3339 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3343 .nid = 0x10, /* NID to query formats and rates */
3345 .open = via_playback_pcm_open,
3346 .prepare = via_playback_multi_pcm_prepare,
3347 .cleanup = via_playback_multi_pcm_cleanup,
3348 .close = via_pcm_open_close
3352 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3356 .nid = 0x10, /* NID to query formats and rates */
3358 .open = via_playback_pcm_open,
3359 .prepare = via_playback_multi_pcm_prepare,
3360 .cleanup = via_playback_multi_pcm_cleanup
3364 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3368 .nid = 0x13, /* NID to query formats and rates */
3370 .open = via_pcm_open_close,
3371 .prepare = via_capture_pcm_prepare,
3372 .cleanup = via_capture_pcm_cleanup,
3373 .close = via_pcm_open_close
3377 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3381 /* NID is set in via_build_pcms */
3383 .open = via_dig_playback_pcm_open,
3384 .close = via_dig_playback_pcm_close,
3385 .prepare = via_dig_playback_pcm_prepare,
3386 .cleanup = via_dig_playback_pcm_cleanup
3390 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3396 /* fill in the dac_nids table from the parsed pin configuration */
3397 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3398 const struct auto_pin_cfg *cfg)
3403 spec->multiout.num_dacs = cfg->line_outs;
3405 spec->multiout.dac_nids = spec->private_dac_nids;
3407 for (i = 0; i < 4; i++) {
3408 nid = cfg->line_out_pins[i];
3410 /* config dac list */
3412 case AUTO_SEQ_FRONT:
3413 spec->multiout.dac_nids[i] = 0x10;
3415 case AUTO_SEQ_CENLFE:
3416 spec->multiout.dac_nids[i] = 0x24;
3418 case AUTO_SEQ_SURROUND:
3419 spec->multiout.dac_nids[i] = 0x11;
3422 spec->multiout.dac_nids[i] = 0x25;
3431 /* add playback controls from the parsed DAC table */
3432 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3433 const struct auto_pin_cfg *cfg)
3436 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3437 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3438 hda_nid_t nid, nid_vol = 0;
3441 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3442 nid = cfg->line_out_pins[i];
3447 nid_vol = nid_vols[i];
3449 if (i == AUTO_SEQ_CENLFE) {
3451 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3452 "Center Playback Volume",
3453 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3457 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3458 "LFE Playback Volume",
3459 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3463 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3464 "Center Playback Switch",
3465 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3469 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3470 "LFE Playback Switch",
3471 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3475 } else if (i == AUTO_SEQ_FRONT) {
3476 /* add control to mixer index 0 */
3477 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3478 "Master Front Playback Volume",
3479 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3483 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3484 "Master Front Playback Switch",
3485 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3490 /* add control to PW3 */
3491 sprintf(name, "%s Playback Volume", chname[i]);
3492 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3493 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3497 sprintf(name, "%s Playback Switch", chname[i]);
3498 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3499 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3504 sprintf(name, "%s Playback Volume", chname[i]);
3505 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3506 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3510 sprintf(name, "%s Playback Switch", chname[i]);
3511 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3512 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3522 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3529 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3530 spec->hp_independent_mode_index = 1;
3532 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3533 "Headphone Playback Volume",
3534 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3537 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3538 "Headphone Playback Switch",
3539 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3543 create_hp_imux(spec);
3548 /* create playback/capture controls for input pins */
3549 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3550 const struct auto_pin_cfg *cfg)
3552 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3553 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3554 ARRAY_SIZE(pin_idxs));
3557 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3559 struct via_spec *spec = codec->spec;
3562 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3565 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3568 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3569 return 0; /* can't find valid BIOS pin config */
3571 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3574 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3577 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3581 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3583 if (spec->autocfg.dig_outs)
3584 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3585 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3586 if (spec->autocfg.dig_in_pin)
3587 spec->dig_in_nid = VT1708B_DIGIN_NID;
3589 if (spec->kctls.list)
3590 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3592 spec->input_mux = &spec->private_imux[0];
3595 via_hp_build(codec);
3597 via_smart51_build(spec);
3601 #ifdef CONFIG_SND_HDA_POWER_SAVE
3602 static struct hda_amp_list vt1708B_loopbacks[] = {
3603 { 0x16, HDA_INPUT, 1 },
3604 { 0x16, HDA_INPUT, 2 },
3605 { 0x16, HDA_INPUT, 3 },
3606 { 0x16, HDA_INPUT, 4 },
3610 static int patch_vt1708S(struct hda_codec *codec);
3611 static int patch_vt1708B_8ch(struct hda_codec *codec)
3613 struct via_spec *spec;
3616 if (get_codec_type(codec) == VT1708BCE)
3617 return patch_vt1708S(codec);
3618 /* create a codec specific record */
3619 spec = via_new_spec(codec);
3623 /* automatic parse from the BIOS config */
3624 err = vt1708B_parse_auto_config(codec);
3629 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3630 "from BIOS. Using genenic mode...\n");
3633 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3634 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3636 spec->stream_name_analog = "VT1708B Analog";
3637 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3638 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3640 spec->stream_name_digital = "VT1708B Digital";
3641 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3642 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3644 if (!spec->adc_nids && spec->input_mux) {
3645 spec->adc_nids = vt1708B_adc_nids;
3646 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3647 get_mux_nids(codec);
3648 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3652 codec->patch_ops = via_patch_ops;
3654 codec->patch_ops.init = via_auto_init;
3655 codec->patch_ops.unsol_event = via_unsol_event;
3656 #ifdef CONFIG_SND_HDA_POWER_SAVE
3657 spec->loopback.amplist = vt1708B_loopbacks;
3663 static int patch_vt1708B_4ch(struct hda_codec *codec)
3665 struct via_spec *spec;
3668 /* create a codec specific record */
3669 spec = via_new_spec(codec);
3673 /* automatic parse from the BIOS config */
3674 err = vt1708B_parse_auto_config(codec);
3679 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3680 "from BIOS. Using genenic mode...\n");
3683 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3684 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3686 spec->stream_name_analog = "VT1708B Analog";
3687 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3688 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3690 spec->stream_name_digital = "VT1708B Digital";
3691 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3692 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3694 if (!spec->adc_nids && spec->input_mux) {
3695 spec->adc_nids = vt1708B_adc_nids;
3696 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3697 get_mux_nids(codec);
3698 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3702 codec->patch_ops = via_patch_ops;
3704 codec->patch_ops.init = via_auto_init;
3705 codec->patch_ops.unsol_event = via_unsol_event;
3706 #ifdef CONFIG_SND_HDA_POWER_SAVE
3707 spec->loopback.amplist = vt1708B_loopbacks;
3713 /* Patch for VT1708S */
3715 /* capture mixer elements */
3716 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3717 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3718 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3719 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3720 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3721 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3722 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3725 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3726 /* The multiple "Capture Source" controls confuse alsamixer
3727 * So call somewhat different..
3729 /* .name = "Capture Source", */
3730 .name = "Input Source",
3732 .info = via_mux_enum_info,
3733 .get = via_mux_enum_get,
3734 .put = via_mux_enum_put,
3739 static struct hda_verb vt1708S_volume_init_verbs[] = {
3740 /* Unmute ADC0-1 and set the default input to mic-in */
3741 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3742 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3744 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3745 * analog-loopback mixer widget */
3746 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3747 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3748 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3749 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3750 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3751 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3753 /* Setup default input of PW4 to MW0 */
3754 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3755 /* PW9, PW10 Output enable */
3756 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3757 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3758 /* Enable Mic Boost Volume backdoor */
3760 /* don't bybass mixer */
3765 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3766 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3767 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3768 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3769 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3770 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3771 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3772 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3773 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3774 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3778 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3782 .nid = 0x10, /* NID to query formats and rates */
3784 .open = via_playback_pcm_open,
3785 .prepare = via_playback_multi_pcm_prepare,
3786 .cleanup = via_playback_multi_pcm_cleanup,
3787 .close = via_pcm_open_close
3791 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3795 .nid = 0x13, /* NID to query formats and rates */
3797 .open = via_pcm_open_close,
3798 .prepare = via_capture_pcm_prepare,
3799 .cleanup = via_capture_pcm_cleanup,
3800 .close = via_pcm_open_close
3804 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3808 /* NID is set in via_build_pcms */
3810 .open = via_dig_playback_pcm_open,
3811 .close = via_dig_playback_pcm_close,
3812 .prepare = via_dig_playback_pcm_prepare,
3813 .cleanup = via_dig_playback_pcm_cleanup
3817 /* fill in the dac_nids table from the parsed pin configuration */
3818 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3819 const struct auto_pin_cfg *cfg)
3824 spec->multiout.num_dacs = cfg->line_outs;
3826 spec->multiout.dac_nids = spec->private_dac_nids;
3828 for (i = 0; i < 4; i++) {
3829 nid = cfg->line_out_pins[i];
3831 /* config dac list */
3833 case AUTO_SEQ_FRONT:
3834 spec->multiout.dac_nids[i] = 0x10;
3836 case AUTO_SEQ_CENLFE:
3837 spec->multiout.dac_nids[i] = 0x24;
3839 case AUTO_SEQ_SURROUND:
3840 spec->multiout.dac_nids[i] = 0x11;
3843 spec->multiout.dac_nids[i] = 0x25;
3849 /* for Smart 5.1, line/mic inputs double as output pins */
3850 if (cfg->line_outs == 1) {
3851 spec->multiout.num_dacs = 3;
3852 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3853 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3859 /* add playback controls from the parsed DAC table */
3860 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3861 const struct auto_pin_cfg *cfg)
3864 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3865 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3866 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3867 hda_nid_t nid, nid_vol, nid_mute;
3870 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3871 nid = cfg->line_out_pins[i];
3873 /* for Smart 5.1, there are always at least six channels */
3874 if (!nid && i > AUTO_SEQ_CENLFE)
3877 nid_vol = nid_vols[i];
3878 nid_mute = nid_mutes[i];
3880 if (i == AUTO_SEQ_CENLFE) {
3882 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3883 "Center Playback Volume",
3884 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3888 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3889 "LFE Playback Volume",
3890 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3894 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3895 "Center Playback Switch",
3896 HDA_COMPOSE_AMP_VAL(nid_mute,
3901 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3902 "LFE Playback Switch",
3903 HDA_COMPOSE_AMP_VAL(nid_mute,
3908 } else if (i == AUTO_SEQ_FRONT) {
3909 /* add control to mixer index 0 */
3910 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3911 "Master Front Playback Volume",
3912 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3916 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3917 "Master Front Playback Switch",
3918 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3924 sprintf(name, "%s Playback Volume", chname[i]);
3925 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3926 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3930 sprintf(name, "%s Playback Switch", chname[i]);
3931 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3932 HDA_COMPOSE_AMP_VAL(nid_mute,
3938 sprintf(name, "%s Playback Volume", chname[i]);
3939 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3940 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3944 sprintf(name, "%s Playback Switch", chname[i]);
3945 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3946 HDA_COMPOSE_AMP_VAL(nid_mute,
3957 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3964 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3965 spec->hp_independent_mode_index = 1;
3967 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3968 "Headphone Playback Volume",
3969 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3973 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3974 "Headphone Playback Switch",
3975 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3979 create_hp_imux(spec);
3984 /* create playback/capture controls for input pins */
3985 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
3986 const struct auto_pin_cfg *cfg)
3988 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
3989 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3990 ARRAY_SIZE(pin_idxs));
3993 /* fill out digital output widgets; one for master and one for slave outputs */
3994 static void fill_dig_outs(struct hda_codec *codec)
3996 struct via_spec *spec = codec->spec;
3999 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4003 nid = spec->autocfg.dig_out_pins[i];
4006 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4009 if (!spec->multiout.dig_out_nid)
4010 spec->multiout.dig_out_nid = nid;
4012 spec->slave_dig_outs[0] = nid;
4013 break; /* at most two dig outs */
4018 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4020 struct via_spec *spec = codec->spec;
4023 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4026 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4029 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4030 return 0; /* can't find valid BIOS pin config */
4032 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4035 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4038 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4042 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4044 fill_dig_outs(codec);
4046 if (spec->kctls.list)
4047 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4049 spec->input_mux = &spec->private_imux[0];
4052 via_hp_build(codec);
4054 via_smart51_build(spec);
4058 #ifdef CONFIG_SND_HDA_POWER_SAVE
4059 static struct hda_amp_list vt1708S_loopbacks[] = {
4060 { 0x16, HDA_INPUT, 1 },
4061 { 0x16, HDA_INPUT, 2 },
4062 { 0x16, HDA_INPUT, 3 },
4063 { 0x16, HDA_INPUT, 4 },
4068 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4069 int offset, int num_steps, int step_size)
4071 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4072 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4073 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4074 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4075 (0 << AC_AMPCAP_MUTE_SHIFT));
4078 static int patch_vt1708S(struct hda_codec *codec)
4080 struct via_spec *spec;
4083 /* create a codec specific record */
4084 spec = via_new_spec(codec);
4088 /* automatic parse from the BIOS config */
4089 err = vt1708S_parse_auto_config(codec);
4094 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4095 "from BIOS. Using genenic mode...\n");
4098 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4099 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4101 if (codec->vendor_id == 0x11060440)
4102 spec->stream_name_analog = "VT1818S Analog";
4104 spec->stream_name_analog = "VT1708S Analog";
4105 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4106 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4108 if (codec->vendor_id == 0x11060440)
4109 spec->stream_name_digital = "VT1818S Digital";
4111 spec->stream_name_digital = "VT1708S Digital";
4112 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4114 if (!spec->adc_nids && spec->input_mux) {
4115 spec->adc_nids = vt1708S_adc_nids;
4116 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4117 get_mux_nids(codec);
4118 override_mic_boost(codec, 0x1a, 0, 3, 40);
4119 override_mic_boost(codec, 0x1e, 0, 3, 40);
4120 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4124 codec->patch_ops = via_patch_ops;
4126 codec->patch_ops.init = via_auto_init;
4127 codec->patch_ops.unsol_event = via_unsol_event;
4128 #ifdef CONFIG_SND_HDA_POWER_SAVE
4129 spec->loopback.amplist = vt1708S_loopbacks;
4132 /* correct names for VT1708BCE */
4133 if (get_codec_type(codec) == VT1708BCE) {
4134 kfree(codec->chip_name);
4135 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4136 snprintf(codec->bus->card->mixername,
4137 sizeof(codec->bus->card->mixername),
4138 "%s %s", codec->vendor_name, codec->chip_name);
4139 spec->stream_name_analog = "VT1708BCE Analog";
4140 spec->stream_name_digital = "VT1708BCE Digital";
4145 /* Patch for VT1702 */
4147 /* capture mixer elements */
4148 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4149 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4150 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4151 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4152 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4153 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4154 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4155 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4159 /* The multiple "Capture Source" controls confuse alsamixer
4160 * So call somewhat different..
4162 /* .name = "Capture Source", */
4163 .name = "Input Source",
4165 .info = via_mux_enum_info,
4166 .get = via_mux_enum_get,
4167 .put = via_mux_enum_put,
4172 static struct hda_verb vt1702_volume_init_verbs[] = {
4174 * Unmute ADC0-1 and set the default input to mic-in
4176 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4177 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4178 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4181 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4184 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4185 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4186 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4187 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4188 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4189 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4191 /* Setup default input of PW4 to MW0 */
4192 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4193 /* PW6 PW7 Output enable */
4194 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4195 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4203 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4204 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4205 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4206 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4207 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4208 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4209 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4213 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4217 .nid = 0x10, /* NID to query formats and rates */
4219 .open = via_playback_pcm_open,
4220 .prepare = via_playback_multi_pcm_prepare,
4221 .cleanup = via_playback_multi_pcm_cleanup,
4222 .close = via_pcm_open_close
4226 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4230 .nid = 0x12, /* NID to query formats and rates */
4232 .open = via_pcm_open_close,
4233 .prepare = via_capture_pcm_prepare,
4234 .cleanup = via_capture_pcm_cleanup,
4235 .close = via_pcm_open_close
4239 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4243 /* NID is set in via_build_pcms */
4245 .open = via_dig_playback_pcm_open,
4246 .close = via_dig_playback_pcm_close,
4247 .prepare = via_dig_playback_pcm_prepare,
4248 .cleanup = via_dig_playback_pcm_cleanup
4252 /* fill in the dac_nids table from the parsed pin configuration */
4253 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4254 const struct auto_pin_cfg *cfg)
4256 spec->multiout.num_dacs = 1;
4257 spec->multiout.dac_nids = spec->private_dac_nids;
4259 if (cfg->line_out_pins[0]) {
4260 /* config dac list */
4261 spec->multiout.dac_nids[0] = 0x10;
4267 /* add playback controls from the parsed DAC table */
4268 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4269 const struct auto_pin_cfg *cfg)
4273 if (!cfg->line_out_pins[0])
4276 /* add control to mixer index 0 */
4277 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4278 "Master Front Playback Volume",
4279 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4282 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4283 "Master Front Playback Switch",
4284 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4289 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4290 "Front Playback Volume",
4291 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4294 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4295 "Front Playback Switch",
4296 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4303 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4306 struct hda_input_mux *imux;
4307 static const char *texts[] = { "ON", "OFF", NULL};
4310 spec->multiout.hp_nid = 0x1D;
4311 spec->hp_independent_mode_index = 0;
4313 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4314 "Headphone Playback Volume",
4315 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4319 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4320 "Headphone Playback Switch",
4321 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4325 imux = &spec->private_imux[1];
4327 /* for hp mode select */
4328 for (i = 0; texts[i]; i++)
4329 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4331 spec->hp_mux = &spec->private_imux[1];
4335 /* create playback/capture controls for input pins */
4336 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4337 const struct auto_pin_cfg *cfg)
4339 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4340 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4341 ARRAY_SIZE(pin_idxs));
4344 static int vt1702_parse_auto_config(struct hda_codec *codec)
4346 struct via_spec *spec = codec->spec;
4349 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4352 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4355 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4356 return 0; /* can't find valid BIOS pin config */
4358 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4361 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4364 /* limit AA path volume to 0 dB */
4365 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4366 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4367 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4368 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4369 (1 << AC_AMPCAP_MUTE_SHIFT));
4370 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4374 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4376 fill_dig_outs(codec);
4378 if (spec->kctls.list)
4379 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4381 spec->input_mux = &spec->private_imux[0];
4384 via_hp_build(codec);
4389 #ifdef CONFIG_SND_HDA_POWER_SAVE
4390 static struct hda_amp_list vt1702_loopbacks[] = {
4391 { 0x1A, HDA_INPUT, 1 },
4392 { 0x1A, HDA_INPUT, 2 },
4393 { 0x1A, HDA_INPUT, 3 },
4394 { 0x1A, HDA_INPUT, 4 },
4399 static int patch_vt1702(struct hda_codec *codec)
4401 struct via_spec *spec;
4404 /* create a codec specific record */
4405 spec = via_new_spec(codec);
4409 /* automatic parse from the BIOS config */
4410 err = vt1702_parse_auto_config(codec);
4415 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4416 "from BIOS. Using genenic mode...\n");
4419 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4420 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4422 spec->stream_name_analog = "VT1702 Analog";
4423 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4424 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4426 spec->stream_name_digital = "VT1702 Digital";
4427 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4429 if (!spec->adc_nids && spec->input_mux) {
4430 spec->adc_nids = vt1702_adc_nids;
4431 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4432 get_mux_nids(codec);
4433 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4437 codec->patch_ops = via_patch_ops;
4439 codec->patch_ops.init = via_auto_init;
4440 codec->patch_ops.unsol_event = via_unsol_event;
4441 #ifdef CONFIG_SND_HDA_POWER_SAVE
4442 spec->loopback.amplist = vt1702_loopbacks;
4448 /* Patch for VT1718S */
4450 /* capture mixer elements */
4451 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4452 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4453 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4454 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4455 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4456 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4457 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4460 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4461 /* The multiple "Capture Source" controls confuse alsamixer
4462 * So call somewhat different..
4464 .name = "Input Source",
4466 .info = via_mux_enum_info,
4467 .get = via_mux_enum_get,
4468 .put = via_mux_enum_put,
4473 static struct hda_verb vt1718S_volume_init_verbs[] = {
4475 * Unmute ADC0-1 and set the default input to mic-in
4477 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4478 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4481 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4484 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4485 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4486 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4487 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4488 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4489 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4491 /* Setup default input of Front HP to MW9 */
4492 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4493 /* PW9 PW10 Output enable */
4494 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4495 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4496 /* PW11 Input enable */
4497 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4498 /* Enable Boost Volume backdoor */
4500 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4501 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4502 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4503 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4504 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4505 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4506 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4507 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4508 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4509 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4510 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4511 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4512 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4513 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4514 /* Unmute MW4's index 0 */
4515 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4520 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4521 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4522 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4523 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4524 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4525 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4526 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4527 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4528 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4529 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4533 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4537 .nid = 0x8, /* NID to query formats and rates */
4539 .open = via_playback_pcm_open,
4540 .prepare = via_playback_multi_pcm_prepare,
4541 .cleanup = via_playback_multi_pcm_cleanup,
4542 .close = via_pcm_open_close,
4546 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4550 .nid = 0x10, /* NID to query formats and rates */
4552 .open = via_pcm_open_close,
4553 .prepare = via_capture_pcm_prepare,
4554 .cleanup = via_capture_pcm_cleanup,
4555 .close = via_pcm_open_close,
4559 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4563 /* NID is set in via_build_pcms */
4565 .open = via_dig_playback_pcm_open,
4566 .close = via_dig_playback_pcm_close,
4567 .prepare = via_dig_playback_pcm_prepare,
4568 .cleanup = via_dig_playback_pcm_cleanup
4572 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4578 /* fill in the dac_nids table from the parsed pin configuration */
4579 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4580 const struct auto_pin_cfg *cfg)
4585 spec->multiout.num_dacs = cfg->line_outs;
4587 spec->multiout.dac_nids = spec->private_dac_nids;
4589 for (i = 0; i < 4; i++) {
4590 nid = cfg->line_out_pins[i];
4592 /* config dac list */
4594 case AUTO_SEQ_FRONT:
4595 spec->multiout.dac_nids[i] = 0x8;
4597 case AUTO_SEQ_CENLFE:
4598 spec->multiout.dac_nids[i] = 0xa;
4600 case AUTO_SEQ_SURROUND:
4601 spec->multiout.dac_nids[i] = 0x9;
4604 spec->multiout.dac_nids[i] = 0xb;
4613 /* add playback controls from the parsed DAC table */
4614 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4615 const struct auto_pin_cfg *cfg)
4618 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4619 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4620 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4621 hda_nid_t nid, nid_vol, nid_mute = 0;
4624 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4625 nid = cfg->line_out_pins[i];
4629 nid_vol = nid_vols[i];
4630 nid_mute = nid_mutes[i];
4632 if (i == AUTO_SEQ_CENLFE) {
4634 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4635 "Center Playback Volume",
4636 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4640 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4641 "LFE Playback Volume",
4642 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4646 err = via_add_control(
4647 spec, VIA_CTL_WIDGET_MUTE,
4648 "Center Playback Switch",
4649 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4653 err = via_add_control(
4654 spec, VIA_CTL_WIDGET_MUTE,
4655 "LFE Playback Switch",
4656 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4660 } else if (i == AUTO_SEQ_FRONT) {
4662 sprintf(name, "%s Playback Volume", chname[i]);
4663 err = via_add_control(
4664 spec, VIA_CTL_WIDGET_VOL, name,
4665 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4668 sprintf(name, "%s Playback Switch", chname[i]);
4669 err = via_add_control(
4670 spec, VIA_CTL_WIDGET_MUTE, name,
4671 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4676 sprintf(name, "%s Playback Volume", chname[i]);
4677 err = via_add_control(
4678 spec, VIA_CTL_WIDGET_VOL, name,
4679 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4682 sprintf(name, "%s Playback Switch", chname[i]);
4683 err = via_add_control(
4684 spec, VIA_CTL_WIDGET_MUTE, name,
4685 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4694 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4701 spec->multiout.hp_nid = 0xc; /* AOW4 */
4702 spec->hp_independent_mode_index = 1;
4704 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4705 "Headphone Playback Volume",
4706 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4710 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4711 "Headphone Playback Switch",
4712 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4716 create_hp_imux(spec);
4720 /* create playback/capture controls for input pins */
4721 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4722 const struct auto_pin_cfg *cfg)
4724 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4725 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4726 ARRAY_SIZE(pin_idxs));
4729 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4731 struct via_spec *spec = codec->spec;
4734 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4738 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4741 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4742 return 0; /* can't find valid BIOS pin config */
4744 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4747 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4750 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4754 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4756 fill_dig_outs(codec);
4758 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4759 spec->dig_in_nid = 0x13;
4761 if (spec->kctls.list)
4762 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4764 spec->input_mux = &spec->private_imux[0];
4767 via_hp_build(codec);
4769 via_smart51_build(spec);
4774 #ifdef CONFIG_SND_HDA_POWER_SAVE
4775 static struct hda_amp_list vt1718S_loopbacks[] = {
4776 { 0x21, HDA_INPUT, 1 },
4777 { 0x21, HDA_INPUT, 2 },
4778 { 0x21, HDA_INPUT, 3 },
4779 { 0x21, HDA_INPUT, 4 },
4784 static int patch_vt1718S(struct hda_codec *codec)
4786 struct via_spec *spec;
4789 /* create a codec specific record */
4790 spec = via_new_spec(codec);
4794 /* automatic parse from the BIOS config */
4795 err = vt1718S_parse_auto_config(codec);
4800 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4801 "from BIOS. Using genenic mode...\n");
4804 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4805 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4807 if (codec->vendor_id == 0x11060441)
4808 spec->stream_name_analog = "VT2020 Analog";
4809 else if (codec->vendor_id == 0x11064441)
4810 spec->stream_name_analog = "VT1828S Analog";
4812 spec->stream_name_analog = "VT1718S Analog";
4813 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4814 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4816 if (codec->vendor_id == 0x11060441)
4817 spec->stream_name_digital = "VT2020 Digital";
4818 else if (codec->vendor_id == 0x11064441)
4819 spec->stream_name_digital = "VT1828S Digital";
4821 spec->stream_name_digital = "VT1718S Digital";
4822 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4823 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4824 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4826 if (!spec->adc_nids && spec->input_mux) {
4827 spec->adc_nids = vt1718S_adc_nids;
4828 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4829 get_mux_nids(codec);
4830 override_mic_boost(codec, 0x2b, 0, 3, 40);
4831 override_mic_boost(codec, 0x29, 0, 3, 40);
4832 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4836 codec->patch_ops = via_patch_ops;
4838 codec->patch_ops.init = via_auto_init;
4839 codec->patch_ops.unsol_event = via_unsol_event;
4841 #ifdef CONFIG_SND_HDA_POWER_SAVE
4842 spec->loopback.amplist = vt1718S_loopbacks;
4848 /* Patch for VT1716S */
4850 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4851 struct snd_ctl_elem_info *uinfo)
4853 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4855 uinfo->value.integer.min = 0;
4856 uinfo->value.integer.max = 1;
4860 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4861 struct snd_ctl_elem_value *ucontrol)
4863 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4866 index = snd_hda_codec_read(codec, 0x26, 0,
4867 AC_VERB_GET_CONNECT_SEL, 0);
4869 *ucontrol->value.integer.value = index;
4874 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4875 struct snd_ctl_elem_value *ucontrol)
4877 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4878 struct via_spec *spec = codec->spec;
4879 int index = *ucontrol->value.integer.value;
4881 snd_hda_codec_write(codec, 0x26, 0,
4882 AC_VERB_SET_CONNECT_SEL, index);
4883 spec->dmic_enabled = index;
4884 set_jack_power_state(codec);
4889 /* capture mixer elements */
4890 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4891 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4892 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4893 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4894 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4895 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4896 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4899 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4900 .name = "Input Source",
4902 .info = via_mux_enum_info,
4903 .get = via_mux_enum_get,
4904 .put = via_mux_enum_put,
4909 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4910 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4912 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4913 .name = "Digital Mic Capture Switch",
4914 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4916 .info = vt1716s_dmic_info,
4917 .get = vt1716s_dmic_get,
4918 .put = vt1716s_dmic_put,
4924 /* mono-out mixer elements */
4925 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4926 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4930 static struct hda_verb vt1716S_volume_init_verbs[] = {
4932 * Unmute ADC0-1 and set the default input to mic-in
4934 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4935 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4938 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4941 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4942 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4943 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4944 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4945 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4946 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4948 /* MUX Indices: Stereo Mixer = 5 */
4949 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4951 /* Setup default input of PW4 to MW0 */
4952 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4954 /* Setup default input of SW1 as MW0 */
4955 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4957 /* Setup default input of SW4 as AOW0 */
4958 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4960 /* PW9 PW10 Output enable */
4961 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4962 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4964 /* Unmute SW1, PW12 */
4965 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4966 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4967 /* PW12 Output enable */
4968 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4969 /* Enable Boost Volume backdoor */
4971 /* don't bybass mixer */
4973 /* Enable mono output */
4979 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
4980 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
4981 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4982 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4983 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4984 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4985 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
4986 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
4987 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4988 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4992 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
4996 .nid = 0x10, /* NID to query formats and rates */
4998 .open = via_playback_pcm_open,
4999 .prepare = via_playback_multi_pcm_prepare,
5000 .cleanup = via_playback_multi_pcm_cleanup,
5001 .close = via_pcm_open_close,
5005 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5009 .nid = 0x13, /* NID to query formats and rates */
5011 .open = via_pcm_open_close,
5012 .prepare = via_capture_pcm_prepare,
5013 .cleanup = via_capture_pcm_cleanup,
5014 .close = via_pcm_open_close,
5018 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5022 /* NID is set in via_build_pcms */
5024 .open = via_dig_playback_pcm_open,
5025 .close = via_dig_playback_pcm_close,
5026 .prepare = via_dig_playback_pcm_prepare,
5027 .cleanup = via_dig_playback_pcm_cleanup
5031 /* fill in the dac_nids table from the parsed pin configuration */
5032 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5033 const struct auto_pin_cfg *cfg)
5037 spec->multiout.num_dacs = cfg->line_outs;
5039 spec->multiout.dac_nids = spec->private_dac_nids;
5041 for (i = 0; i < 3; i++) {
5042 nid = cfg->line_out_pins[i];
5044 /* config dac list */
5046 case AUTO_SEQ_FRONT:
5047 spec->multiout.dac_nids[i] = 0x10;
5049 case AUTO_SEQ_CENLFE:
5050 spec->multiout.dac_nids[i] = 0x25;
5052 case AUTO_SEQ_SURROUND:
5053 spec->multiout.dac_nids[i] = 0x11;
5062 /* add playback controls from the parsed DAC table */
5063 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5064 const struct auto_pin_cfg *cfg)
5067 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5068 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5069 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5070 hda_nid_t nid, nid_vol, nid_mute;
5073 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5074 nid = cfg->line_out_pins[i];
5079 nid_vol = nid_vols[i];
5080 nid_mute = nid_mutes[i];
5082 if (i == AUTO_SEQ_CENLFE) {
5083 err = via_add_control(
5084 spec, VIA_CTL_WIDGET_VOL,
5085 "Center Playback Volume",
5086 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5089 err = via_add_control(
5090 spec, VIA_CTL_WIDGET_VOL,
5091 "LFE Playback Volume",
5092 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5095 err = via_add_control(
5096 spec, VIA_CTL_WIDGET_MUTE,
5097 "Center Playback Switch",
5098 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5102 err = via_add_control(
5103 spec, VIA_CTL_WIDGET_MUTE,
5104 "LFE Playback Switch",
5105 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5109 } else if (i == AUTO_SEQ_FRONT) {
5111 err = via_add_control(
5112 spec, VIA_CTL_WIDGET_VOL,
5113 "Master Front Playback Volume",
5114 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5117 err = via_add_control(
5118 spec, VIA_CTL_WIDGET_MUTE,
5119 "Master Front Playback Switch",
5120 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5124 sprintf(name, "%s Playback Volume", chname[i]);
5125 err = via_add_control(
5126 spec, VIA_CTL_WIDGET_VOL, name,
5127 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5130 sprintf(name, "%s Playback Switch", chname[i]);
5131 err = via_add_control(
5132 spec, VIA_CTL_WIDGET_MUTE, name,
5133 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5138 sprintf(name, "%s Playback Volume", chname[i]);
5139 err = via_add_control(
5140 spec, VIA_CTL_WIDGET_VOL, name,
5141 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5144 sprintf(name, "%s Playback Switch", chname[i]);
5145 err = via_add_control(
5146 spec, VIA_CTL_WIDGET_MUTE, name,
5147 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5156 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5163 spec->multiout.hp_nid = 0x25; /* AOW3 */
5164 spec->hp_independent_mode_index = 1;
5166 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5167 "Headphone Playback Volume",
5168 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5172 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5173 "Headphone Playback Switch",
5174 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5178 create_hp_imux(spec);
5182 /* create playback/capture controls for input pins */
5183 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5184 const struct auto_pin_cfg *cfg)
5186 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5187 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5188 ARRAY_SIZE(pin_idxs));
5191 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5193 struct via_spec *spec = codec->spec;
5196 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5199 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5202 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5203 return 0; /* can't find valid BIOS pin config */
5205 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5208 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5211 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5215 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5217 fill_dig_outs(codec);
5219 if (spec->kctls.list)
5220 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5222 spec->input_mux = &spec->private_imux[0];
5225 via_hp_build(codec);
5227 via_smart51_build(spec);
5232 #ifdef CONFIG_SND_HDA_POWER_SAVE
5233 static struct hda_amp_list vt1716S_loopbacks[] = {
5234 { 0x16, HDA_INPUT, 1 },
5235 { 0x16, HDA_INPUT, 2 },
5236 { 0x16, HDA_INPUT, 3 },
5237 { 0x16, HDA_INPUT, 4 },
5242 static int patch_vt1716S(struct hda_codec *codec)
5244 struct via_spec *spec;
5247 /* create a codec specific record */
5248 spec = via_new_spec(codec);
5252 /* automatic parse from the BIOS config */
5253 err = vt1716S_parse_auto_config(codec);
5258 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5259 "from BIOS. Using genenic mode...\n");
5262 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5263 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5265 spec->stream_name_analog = "VT1716S Analog";
5266 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5267 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5269 spec->stream_name_digital = "VT1716S Digital";
5270 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5272 if (!spec->adc_nids && spec->input_mux) {
5273 spec->adc_nids = vt1716S_adc_nids;
5274 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5275 get_mux_nids(codec);
5276 override_mic_boost(codec, 0x1a, 0, 3, 40);
5277 override_mic_boost(codec, 0x1e, 0, 3, 40);
5278 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5282 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5285 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5287 codec->patch_ops = via_patch_ops;
5289 codec->patch_ops.init = via_auto_init;
5290 codec->patch_ops.unsol_event = via_unsol_event;
5292 #ifdef CONFIG_SND_HDA_POWER_SAVE
5293 spec->loopback.amplist = vt1716S_loopbacks;
5301 /* capture mixer elements */
5302 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5303 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5304 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5305 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5306 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5307 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5308 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5311 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5312 /* The multiple "Capture Source" controls confuse alsamixer
5313 * So call somewhat different..
5315 /* .name = "Capture Source", */
5316 .name = "Input Source",
5318 .info = via_mux_enum_info,
5319 .get = via_mux_enum_get,
5320 .put = via_mux_enum_put,
5325 static struct hda_verb vt2002P_volume_init_verbs[] = {
5327 * Unmute ADC0-1 and set the default input to mic-in
5329 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5330 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5333 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5336 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5337 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5338 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5339 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5340 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5341 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5343 /* MUX Indices: Mic = 0 */
5344 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5345 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5347 /* PW9 Output enable */
5348 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5350 /* Enable Boost Volume backdoor */
5353 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5354 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5355 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5356 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5357 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5358 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5359 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5360 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5361 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5363 /* set MUX0/1/4/8 = 0 (AOW0) */
5364 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5365 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5366 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5367 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5369 /* set PW0 index=0 (MW0) */
5370 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5372 /* Enable AOW0 to MW9 */
5378 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5379 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5380 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5381 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5382 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5383 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5384 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5385 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5389 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5393 .nid = 0x8, /* NID to query formats and rates */
5395 .open = via_playback_pcm_open,
5396 .prepare = via_playback_multi_pcm_prepare,
5397 .cleanup = via_playback_multi_pcm_cleanup,
5398 .close = via_pcm_open_close,
5402 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5406 .nid = 0x10, /* NID to query formats and rates */
5408 .open = via_pcm_open_close,
5409 .prepare = via_capture_pcm_prepare,
5410 .cleanup = via_capture_pcm_cleanup,
5411 .close = via_pcm_open_close,
5415 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5419 /* NID is set in via_build_pcms */
5421 .open = via_dig_playback_pcm_open,
5422 .close = via_dig_playback_pcm_close,
5423 .prepare = via_dig_playback_pcm_prepare,
5424 .cleanup = via_dig_playback_pcm_cleanup
5428 /* fill in the dac_nids table from the parsed pin configuration */
5429 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5430 const struct auto_pin_cfg *cfg)
5432 spec->multiout.num_dacs = 1;
5433 spec->multiout.dac_nids = spec->private_dac_nids;
5434 if (cfg->line_out_pins[0])
5435 spec->multiout.dac_nids[0] = 0x8;
5439 /* add playback controls from the parsed DAC table */
5440 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5441 const struct auto_pin_cfg *cfg)
5445 if (!cfg->line_out_pins[0])
5449 /* Line-Out: PortE */
5450 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5451 "Master Front Playback Volume",
5452 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5455 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5456 "Master Front Playback Switch",
5457 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5464 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5471 spec->multiout.hp_nid = 0x9;
5472 spec->hp_independent_mode_index = 1;
5474 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5475 "Headphone Playback Volume",
5476 HDA_COMPOSE_AMP_VAL(
5477 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5481 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5482 "Headphone Playback Switch",
5483 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5487 create_hp_imux(spec);
5491 /* create playback/capture controls for input pins */
5492 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5493 const struct auto_pin_cfg *cfg)
5495 struct via_spec *spec = codec->spec;
5496 struct hda_input_mux *imux = &spec->private_imux[0];
5497 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5500 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5501 ARRAY_SIZE(pin_idxs));
5504 /* build volume/mute control of loopback */
5505 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5509 /* for digital mic select */
5510 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5515 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5517 struct via_spec *spec = codec->spec;
5521 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5525 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5529 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5530 return 0; /* can't find valid BIOS pin config */
5532 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5535 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5538 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5542 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5544 fill_dig_outs(codec);
5546 if (spec->kctls.list)
5547 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5549 spec->input_mux = &spec->private_imux[0];
5552 via_hp_build(codec);
5557 #ifdef CONFIG_SND_HDA_POWER_SAVE
5558 static struct hda_amp_list vt2002P_loopbacks[] = {
5559 { 0x21, HDA_INPUT, 0 },
5560 { 0x21, HDA_INPUT, 1 },
5561 { 0x21, HDA_INPUT, 2 },
5567 /* patch for vt2002P */
5568 static int patch_vt2002P(struct hda_codec *codec)
5570 struct via_spec *spec;
5573 /* create a codec specific record */
5574 spec = via_new_spec(codec);
5578 /* automatic parse from the BIOS config */
5579 err = vt2002P_parse_auto_config(codec);
5584 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5585 "from BIOS. Using genenic mode...\n");
5588 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5589 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5591 spec->stream_name_analog = "VT2002P Analog";
5592 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5593 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5595 spec->stream_name_digital = "VT2002P Digital";
5596 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5598 if (!spec->adc_nids && spec->input_mux) {
5599 spec->adc_nids = vt2002P_adc_nids;
5600 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5601 get_mux_nids(codec);
5602 override_mic_boost(codec, 0x2b, 0, 3, 40);
5603 override_mic_boost(codec, 0x29, 0, 3, 40);
5604 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5608 codec->patch_ops = via_patch_ops;
5610 codec->patch_ops.init = via_auto_init;
5611 codec->patch_ops.unsol_event = via_unsol_event;
5613 #ifdef CONFIG_SND_HDA_POWER_SAVE
5614 spec->loopback.amplist = vt2002P_loopbacks;
5622 /* capture mixer elements */
5623 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5624 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5625 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5626 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5627 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5628 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5629 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5632 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5633 /* The multiple "Capture Source" controls confuse alsamixer
5634 * So call somewhat different..
5636 .name = "Input Source",
5638 .info = via_mux_enum_info,
5639 .get = via_mux_enum_get,
5640 .put = via_mux_enum_put,
5645 static struct hda_verb vt1812_volume_init_verbs[] = {
5647 * Unmute ADC0-1 and set the default input to mic-in
5649 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5650 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5653 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5656 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5657 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5658 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5659 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5660 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5661 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5663 /* MUX Indices: Mic = 0 */
5664 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5665 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5667 /* PW9 Output enable */
5668 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5670 /* Enable Boost Volume backdoor */
5673 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5674 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5675 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5676 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5677 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5678 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5679 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5680 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5681 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5682 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5683 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5685 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5686 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5687 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5688 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5689 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5690 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5692 /* Enable AOW0 to MW9 */
5698 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5699 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5700 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5701 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5702 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5703 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5704 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5705 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5706 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5710 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5714 .nid = 0x8, /* NID to query formats and rates */
5716 .open = via_playback_pcm_open,
5717 .prepare = via_playback_multi_pcm_prepare,
5718 .cleanup = via_playback_multi_pcm_cleanup,
5719 .close = via_pcm_open_close,
5723 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5727 .nid = 0x10, /* NID to query formats and rates */
5729 .open = via_pcm_open_close,
5730 .prepare = via_capture_pcm_prepare,
5731 .cleanup = via_capture_pcm_cleanup,
5732 .close = via_pcm_open_close,
5736 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5740 /* NID is set in via_build_pcms */
5742 .open = via_dig_playback_pcm_open,
5743 .close = via_dig_playback_pcm_close,
5744 .prepare = via_dig_playback_pcm_prepare,
5745 .cleanup = via_dig_playback_pcm_cleanup
5748 /* fill in the dac_nids table from the parsed pin configuration */
5749 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5750 const struct auto_pin_cfg *cfg)
5752 spec->multiout.num_dacs = 1;
5753 spec->multiout.dac_nids = spec->private_dac_nids;
5754 if (cfg->line_out_pins[0])
5755 spec->multiout.dac_nids[0] = 0x8;
5760 /* add playback controls from the parsed DAC table */
5761 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5762 const struct auto_pin_cfg *cfg)
5766 if (!cfg->line_out_pins[0])
5769 /* Line-Out: PortE */
5770 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5771 "Front Playback Volume",
5772 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5775 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5776 "Front Playback Switch",
5777 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5784 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5791 spec->multiout.hp_nid = 0x9;
5792 spec->hp_independent_mode_index = 1;
5795 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5796 "Headphone Playback Volume",
5797 HDA_COMPOSE_AMP_VAL(
5798 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5802 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5803 "Headphone Playback Switch",
5804 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5808 create_hp_imux(spec);
5812 /* create playback/capture controls for input pins */
5813 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5814 const struct auto_pin_cfg *cfg)
5816 struct via_spec *spec = codec->spec;
5817 struct hda_input_mux *imux = &spec->private_imux[0];
5818 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5821 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5822 ARRAY_SIZE(pin_idxs));
5826 /* build volume/mute control of loopback */
5827 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5831 /* for digital mic select */
5832 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5837 static int vt1812_parse_auto_config(struct hda_codec *codec)
5839 struct via_spec *spec = codec->spec;
5843 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5846 fill_dig_outs(codec);
5847 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5851 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5852 return 0; /* can't find valid BIOS pin config */
5854 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5857 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5860 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
5864 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5866 fill_dig_outs(codec);
5868 if (spec->kctls.list)
5869 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5871 spec->input_mux = &spec->private_imux[0];
5874 via_hp_build(codec);
5879 #ifdef CONFIG_SND_HDA_POWER_SAVE
5880 static struct hda_amp_list vt1812_loopbacks[] = {
5881 { 0x21, HDA_INPUT, 0 },
5882 { 0x21, HDA_INPUT, 1 },
5883 { 0x21, HDA_INPUT, 2 },
5889 /* patch for vt1812 */
5890 static int patch_vt1812(struct hda_codec *codec)
5892 struct via_spec *spec;
5895 /* create a codec specific record */
5896 spec = via_new_spec(codec);
5900 /* automatic parse from the BIOS config */
5901 err = vt1812_parse_auto_config(codec);
5906 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5907 "from BIOS. Using genenic mode...\n");
5911 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
5912 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
5914 spec->stream_name_analog = "VT1812 Analog";
5915 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
5916 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
5918 spec->stream_name_digital = "VT1812 Digital";
5919 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
5922 if (!spec->adc_nids && spec->input_mux) {
5923 spec->adc_nids = vt1812_adc_nids;
5924 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
5925 get_mux_nids(codec);
5926 override_mic_boost(codec, 0x2b, 0, 3, 40);
5927 override_mic_boost(codec, 0x29, 0, 3, 40);
5928 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
5932 codec->patch_ops = via_patch_ops;
5934 codec->patch_ops.init = via_auto_init;
5935 codec->patch_ops.unsol_event = via_unsol_event;
5937 #ifdef CONFIG_SND_HDA_POWER_SAVE
5938 spec->loopback.amplist = vt1812_loopbacks;
5947 static struct hda_codec_preset snd_hda_preset_via[] = {
5948 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
5949 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
5950 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
5951 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
5952 { .id = 0x1106e710, .name = "VT1709 10-Ch",
5953 .patch = patch_vt1709_10ch},
5954 { .id = 0x1106e711, .name = "VT1709 10-Ch",
5955 .patch = patch_vt1709_10ch},
5956 { .id = 0x1106e712, .name = "VT1709 10-Ch",
5957 .patch = patch_vt1709_10ch},
5958 { .id = 0x1106e713, .name = "VT1709 10-Ch",
5959 .patch = patch_vt1709_10ch},
5960 { .id = 0x1106e714, .name = "VT1709 6-Ch",
5961 .patch = patch_vt1709_6ch},
5962 { .id = 0x1106e715, .name = "VT1709 6-Ch",
5963 .patch = patch_vt1709_6ch},
5964 { .id = 0x1106e716, .name = "VT1709 6-Ch",
5965 .patch = patch_vt1709_6ch},
5966 { .id = 0x1106e717, .name = "VT1709 6-Ch",
5967 .patch = patch_vt1709_6ch},
5968 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
5969 .patch = patch_vt1708B_8ch},
5970 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
5971 .patch = patch_vt1708B_8ch},
5972 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
5973 .patch = patch_vt1708B_8ch},
5974 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
5975 .patch = patch_vt1708B_8ch},
5976 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
5977 .patch = patch_vt1708B_4ch},
5978 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
5979 .patch = patch_vt1708B_4ch},
5980 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
5981 .patch = patch_vt1708B_4ch},
5982 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
5983 .patch = patch_vt1708B_4ch},
5984 { .id = 0x11060397, .name = "VT1708S",
5985 .patch = patch_vt1708S},
5986 { .id = 0x11061397, .name = "VT1708S",
5987 .patch = patch_vt1708S},
5988 { .id = 0x11062397, .name = "VT1708S",
5989 .patch = patch_vt1708S},
5990 { .id = 0x11063397, .name = "VT1708S",
5991 .patch = patch_vt1708S},
5992 { .id = 0x11064397, .name = "VT1708S",
5993 .patch = patch_vt1708S},
5994 { .id = 0x11065397, .name = "VT1708S",
5995 .patch = patch_vt1708S},
5996 { .id = 0x11066397, .name = "VT1708S",
5997 .patch = patch_vt1708S},
5998 { .id = 0x11067397, .name = "VT1708S",
5999 .patch = patch_vt1708S},
6000 { .id = 0x11060398, .name = "VT1702",
6001 .patch = patch_vt1702},
6002 { .id = 0x11061398, .name = "VT1702",
6003 .patch = patch_vt1702},
6004 { .id = 0x11062398, .name = "VT1702",
6005 .patch = patch_vt1702},
6006 { .id = 0x11063398, .name = "VT1702",
6007 .patch = patch_vt1702},
6008 { .id = 0x11064398, .name = "VT1702",
6009 .patch = patch_vt1702},
6010 { .id = 0x11065398, .name = "VT1702",
6011 .patch = patch_vt1702},
6012 { .id = 0x11066398, .name = "VT1702",
6013 .patch = patch_vt1702},
6014 { .id = 0x11067398, .name = "VT1702",
6015 .patch = patch_vt1702},
6016 { .id = 0x11060428, .name = "VT1718S",
6017 .patch = patch_vt1718S},
6018 { .id = 0x11064428, .name = "VT1718S",
6019 .patch = patch_vt1718S},
6020 { .id = 0x11060441, .name = "VT2020",
6021 .patch = patch_vt1718S},
6022 { .id = 0x11064441, .name = "VT1828S",
6023 .patch = patch_vt1718S},
6024 { .id = 0x11060433, .name = "VT1716S",
6025 .patch = patch_vt1716S},
6026 { .id = 0x1106a721, .name = "VT1716S",
6027 .patch = patch_vt1716S},
6028 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6029 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6030 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6031 { .id = 0x11060440, .name = "VT1818S",
6032 .patch = patch_vt1708S},
6036 MODULE_ALIAS("snd-hda-codec-id:1106*");
6038 static struct hda_codec_preset_list via_list = {
6039 .preset = snd_hda_preset_via,
6040 .owner = THIS_MODULE,
6043 MODULE_LICENSE("GPL");
6044 MODULE_DESCRIPTION("VIA HD-audio codec");
6046 static int __init patch_via_init(void)
6048 return snd_hda_add_codec_preset(&via_list);
6051 static void __exit patch_via_exit(void)
6053 snd_hda_delete_codec_preset(&via_list);
6056 module_init(patch_via_init)
6057 module_exit(patch_via_exit)