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 (cfg->inputs[i].type == 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);
1106 if (!spec->mux_nids[adc_idx])
1108 /* switch to D0 beofre change index */
1109 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1110 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1111 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1112 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1114 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1115 spec->mux_nids[adc_idx],
1116 &spec->cur_mux[adc_idx]);
1117 /* update jack power state */
1118 set_jack_power_state(codec);
1123 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1124 struct snd_ctl_elem_info *uinfo)
1126 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1127 struct via_spec *spec = codec->spec;
1128 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1131 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1132 struct snd_ctl_elem_value *ucontrol)
1134 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1135 hda_nid_t nid = kcontrol->private_value;
1136 unsigned int pinsel;
1138 /* use !! to translate conn sel 2 for VT1718S */
1139 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1140 AC_VERB_GET_CONNECT_SEL,
1142 ucontrol->value.enumerated.item[0] = pinsel;
1147 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1149 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1151 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1152 ctl->vd[0].access |= active
1153 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1154 snd_ctl_notify(codec->bus->card,
1155 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1159 static hda_nid_t side_mute_channel(struct via_spec *spec)
1161 switch (spec->codec_type) {
1162 case VT1708: return 0x1b;
1163 case VT1709_10CH: return 0x29;
1164 case VT1708B_8CH: /* fall thru */
1165 case VT1708S: return 0x27;
1170 static int update_side_mute_status(struct hda_codec *codec)
1172 /* mute side channel */
1173 struct via_spec *spec = codec->spec;
1174 unsigned int parm = spec->hp_independent_mode
1175 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1176 hda_nid_t sw3 = side_mute_channel(spec);
1179 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1184 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1185 struct snd_ctl_elem_value *ucontrol)
1187 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1188 struct via_spec *spec = codec->spec;
1189 hda_nid_t nid = kcontrol->private_value;
1190 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1191 /* Get Independent Mode index of headphone pin widget */
1192 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1194 if (spec->codec_type == VT1718S)
1195 snd_hda_codec_write(codec, nid, 0,
1196 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
1198 snd_hda_codec_write(codec, nid, 0,
1199 AC_VERB_SET_CONNECT_SEL, pinsel);
1201 if (spec->codec_type == VT1812)
1202 snd_hda_codec_write(codec, 0x35, 0,
1203 AC_VERB_SET_CONNECT_SEL, pinsel);
1204 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1205 != spec->multiout.dac_nids[HDA_FRONT])
1206 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1209 update_side_mute_status(codec);
1210 /* update HP volume/swtich active state */
1211 if (spec->codec_type == VT1708S
1212 || spec->codec_type == VT1702
1213 || spec->codec_type == VT1718S
1214 || spec->codec_type == VT1716S
1215 || spec->codec_type == VT2002P
1216 || spec->codec_type == VT1812) {
1217 activate_ctl(codec, "Headphone Playback Volume",
1218 spec->hp_independent_mode);
1219 activate_ctl(codec, "Headphone Playback Switch",
1220 spec->hp_independent_mode);
1222 /* update jack power state */
1223 set_jack_power_state(codec);
1227 static struct snd_kcontrol_new via_hp_mixer[2] = {
1229 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1230 .name = "Independent HP",
1231 .info = via_independent_hp_info,
1232 .get = via_independent_hp_get,
1233 .put = via_independent_hp_put,
1236 .iface = NID_MAPPING,
1237 .name = "Independent HP",
1241 static int via_hp_build(struct hda_codec *codec)
1243 struct via_spec *spec = codec->spec;
1244 struct snd_kcontrol_new *knew;
1247 hda_nid_t conn[HDA_MAX_CONNECTIONS];
1249 switch (spec->codec_type) {
1260 nid = spec->autocfg.hp_pins[0];
1264 nums = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS);
1268 knew = via_clone_control(spec, &via_hp_mixer[0]);
1272 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1273 knew->private_value = nid;
1275 knew = via_clone_control(spec, &via_hp_mixer[1]);
1278 knew->subdevice = side_mute_channel(spec);
1283 static void notify_aa_path_ctls(struct hda_codec *codec)
1286 struct snd_ctl_elem_id id;
1287 const char *labels[] = {"Mic", "Front Mic", "Line"};
1289 memset(&id, 0, sizeof(id));
1290 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1291 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1292 sprintf(id.name, "%s Playback Volume", labels[i]);
1293 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1298 static void mute_aa_path(struct hda_codec *codec, int mute)
1300 struct via_spec *spec = codec->spec;
1301 hda_nid_t nid_mixer;
1305 /* get nid of MW0 and start & end index */
1306 switch (spec->codec_type) {
1334 /* check AA path's mute status */
1335 for (i = start_idx; i <= end_idx; i++) {
1336 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1337 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1341 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1343 const struct auto_pin_cfg *cfg = &spec->autocfg;
1346 for (i = 0; i < cfg->num_inputs; i++) {
1347 if (pin == cfg->inputs[i].pin)
1348 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
1353 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1354 struct snd_ctl_elem_info *uinfo)
1356 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1358 uinfo->value.integer.min = 0;
1359 uinfo->value.integer.max = 1;
1363 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1364 struct snd_ctl_elem_value *ucontrol)
1366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1367 struct via_spec *spec = codec->spec;
1368 const struct auto_pin_cfg *cfg = &spec->autocfg;
1372 for (i = 0; i < cfg->num_inputs; i++) {
1373 hda_nid_t nid = cfg->inputs[i].pin;
1374 int ctl = snd_hda_codec_read(codec, nid, 0,
1375 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1376 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1378 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1379 spec->hp_independent_mode && spec->codec_type != VT1718S)
1380 continue; /* ignore FMic for independent HP */
1381 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
1384 *ucontrol->value.integer.value = on;
1388 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1389 struct snd_ctl_elem_value *ucontrol)
1391 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1392 struct via_spec *spec = codec->spec;
1393 const struct auto_pin_cfg *cfg = &spec->autocfg;
1394 int out_in = *ucontrol->value.integer.value
1395 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1398 for (i = 0; i < cfg->num_inputs; i++) {
1399 hda_nid_t nid = cfg->inputs[i].pin;
1402 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1404 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1405 spec->hp_independent_mode && spec->codec_type != VT1718S)
1406 continue; /* don't retask FMic for independent HP */
1408 parm = snd_hda_codec_read(codec, nid, 0,
1409 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1410 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1412 snd_hda_codec_write(codec, nid, 0,
1413 AC_VERB_SET_PIN_WIDGET_CONTROL,
1415 if (out_in == AC_PINCTL_OUT_EN) {
1416 mute_aa_path(codec, 1);
1417 notify_aa_path_ctls(codec);
1419 if (spec->codec_type == VT1718S) {
1420 snd_hda_codec_amp_stereo(
1421 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1424 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
1425 if (spec->codec_type == VT1708S
1426 || spec->codec_type == VT1716S) {
1427 /* input = index 1 (AOW3) */
1428 snd_hda_codec_write(
1430 AC_VERB_SET_CONNECT_SEL, 1);
1431 snd_hda_codec_amp_stereo(
1432 codec, nid, HDA_OUTPUT,
1433 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1437 spec->smart51_enabled = *ucontrol->value.integer.value;
1438 set_jack_power_state(codec);
1442 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1444 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1445 .name = "Smart 5.1",
1447 .info = via_smart51_info,
1448 .get = via_smart51_get,
1449 .put = via_smart51_put,
1452 .iface = NID_MAPPING,
1453 .name = "Smart 5.1",
1457 static int via_smart51_build(struct via_spec *spec)
1459 struct snd_kcontrol_new *knew;
1460 const struct auto_pin_cfg *cfg = &spec->autocfg;
1464 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1468 for (i = 0; i < cfg->num_inputs; i++) {
1469 nid = cfg->inputs[i].pin;
1470 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1471 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1474 knew->subdevice = nid;
1482 /* capture mixer elements */
1483 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1484 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1485 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1486 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1487 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1490 /* The multiple "Capture Source" controls confuse alsamixer
1491 * So call somewhat different..
1493 /* .name = "Capture Source", */
1494 .name = "Input Source",
1496 .info = via_mux_enum_info,
1497 .get = via_mux_enum_get,
1498 .put = via_mux_enum_put,
1503 /* check AA path's mute statue */
1504 static int is_aa_path_mute(struct hda_codec *codec)
1507 hda_nid_t nid_mixer;
1511 struct via_spec *spec = codec->spec;
1512 /* get nid of MW0 and start & end index */
1513 switch (spec->codec_type) {
1541 /* check AA path's mute status */
1542 for (i = start_idx; i <= end_idx; i++) {
1543 unsigned int con_list = snd_hda_codec_read(
1544 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1545 int shift = 8 * (i % 4);
1546 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1547 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1548 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1549 /* check mute status while the pin is connected */
1550 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1552 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1554 if (!mute_l || !mute_r) {
1563 /* enter/exit analog low-current mode */
1564 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1566 struct via_spec *spec = codec->spec;
1567 static int saved_stream_idle = 1; /* saved stream idle status */
1568 int enable = is_aa_path_mute(codec);
1569 unsigned int verb = 0;
1570 unsigned int parm = 0;
1572 if (stream_idle == -1) /* stream status did not change */
1573 enable = enable && saved_stream_idle;
1575 enable = enable && stream_idle;
1576 saved_stream_idle = stream_idle;
1579 /* decide low current mode's verb & parameter */
1580 switch (spec->codec_type) {
1584 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1590 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1594 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1599 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1602 return; /* other codecs are not supported */
1605 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1609 * generic initialization of ADC, input mixers and output mixers
1611 static struct hda_verb vt1708_volume_init_verbs[] = {
1613 * Unmute ADC0-1 and set the default input to mic-in
1615 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1616 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1619 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1622 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1623 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1624 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1625 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1626 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1627 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1630 * Set up output mixers (0x19 - 0x1b)
1632 /* set vol=0 to output mixers */
1633 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1634 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1635 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1637 /* Setup default input MW0 to PW4 */
1638 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1639 /* PW9 Output enable */
1640 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1644 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1645 struct hda_codec *codec,
1646 struct snd_pcm_substream *substream)
1648 struct via_spec *spec = codec->spec;
1649 int idle = substream->pstr->substream_opened == 1
1650 && substream->ref_count == 0;
1651 analog_low_current_mode(codec, idle);
1652 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1656 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1657 unsigned int stream_tag,
1658 unsigned int format,
1659 struct snd_pcm_substream *substream)
1661 struct via_spec *spec = codec->spec;
1662 struct hda_multi_out *mout = &spec->multiout;
1663 hda_nid_t *nids = mout->dac_nids;
1664 int chs = substream->runtime->channels;
1667 mutex_lock(&codec->spdif_mutex);
1668 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1670 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1672 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1673 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1674 /* turn off SPDIF once; otherwise the IEC958 bits won't
1676 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1677 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1678 AC_VERB_SET_DIGI_CONVERT_1,
1680 ~AC_DIG1_ENABLE & 0xff);
1681 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1682 stream_tag, 0, format);
1683 /* turn on again (if needed) */
1684 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1685 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1686 AC_VERB_SET_DIGI_CONVERT_1,
1687 codec->spdif_ctls & 0xff);
1689 mout->dig_out_used = 0;
1690 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1694 mutex_unlock(&codec->spdif_mutex);
1697 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1700 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1701 && !spec->hp_independent_mode)
1702 /* headphone out will just decode front left/right (stereo) */
1703 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1706 /* extra outputs copied from front */
1707 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1708 if (mout->extra_out_nid[i])
1709 snd_hda_codec_setup_stream(codec,
1710 mout->extra_out_nid[i],
1711 stream_tag, 0, format);
1714 for (i = 1; i < mout->num_dacs; i++) {
1715 if (chs >= (i + 1) * 2) /* independent out */
1716 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1718 else /* copy front */
1719 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1724 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1725 struct hda_codec *codec,
1726 unsigned int stream_tag,
1727 unsigned int format,
1728 struct snd_pcm_substream *substream)
1730 struct via_spec *spec = codec->spec;
1731 struct hda_multi_out *mout = &spec->multiout;
1732 hda_nid_t *nids = mout->dac_nids;
1734 if (substream->number == 0)
1735 playback_multi_pcm_prep_0(codec, stream_tag, format,
1738 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1739 spec->hp_independent_mode)
1740 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1741 stream_tag, 0, format);
1743 vt1708_start_hp_work(spec);
1747 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1748 struct hda_codec *codec,
1749 struct snd_pcm_substream *substream)
1751 struct via_spec *spec = codec->spec;
1752 struct hda_multi_out *mout = &spec->multiout;
1753 hda_nid_t *nids = mout->dac_nids;
1756 if (substream->number == 0) {
1757 for (i = 0; i < mout->num_dacs; i++)
1758 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1760 if (mout->hp_nid && !spec->hp_independent_mode)
1761 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1764 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1765 if (mout->extra_out_nid[i])
1766 snd_hda_codec_setup_stream(codec,
1767 mout->extra_out_nid[i],
1769 mutex_lock(&codec->spdif_mutex);
1770 if (mout->dig_out_nid &&
1771 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1772 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1774 mout->dig_out_used = 0;
1776 mutex_unlock(&codec->spdif_mutex);
1778 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1779 spec->hp_independent_mode)
1780 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1783 vt1708_stop_hp_work(spec);
1790 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1791 struct hda_codec *codec,
1792 struct snd_pcm_substream *substream)
1794 struct via_spec *spec = codec->spec;
1795 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1798 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1799 struct hda_codec *codec,
1800 struct snd_pcm_substream *substream)
1802 struct via_spec *spec = codec->spec;
1803 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1806 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1807 struct hda_codec *codec,
1808 unsigned int stream_tag,
1809 unsigned int format,
1810 struct snd_pcm_substream *substream)
1812 struct via_spec *spec = codec->spec;
1813 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1814 stream_tag, format, substream);
1817 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1818 struct hda_codec *codec,
1819 struct snd_pcm_substream *substream)
1821 struct via_spec *spec = codec->spec;
1822 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1829 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1830 struct hda_codec *codec,
1831 unsigned int stream_tag,
1832 unsigned int format,
1833 struct snd_pcm_substream *substream)
1835 struct via_spec *spec = codec->spec;
1837 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1838 stream_tag, 0, format);
1842 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1843 struct hda_codec *codec,
1844 struct snd_pcm_substream *substream)
1846 struct via_spec *spec = codec->spec;
1847 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1851 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1855 .nid = 0x10, /* NID to query formats and rates */
1857 .open = via_playback_pcm_open,
1858 .prepare = via_playback_multi_pcm_prepare,
1859 .cleanup = via_playback_multi_pcm_cleanup
1863 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1867 .nid = 0x10, /* NID to query formats and rates */
1868 /* We got noisy outputs on the right channel on VT1708 when
1869 * 24bit samples are used. Until any workaround is found,
1870 * disable the 24bit format, so far.
1872 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1874 .open = via_playback_pcm_open,
1875 .prepare = via_playback_multi_pcm_prepare,
1876 .cleanup = via_playback_multi_pcm_cleanup
1880 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1884 .nid = 0x15, /* NID to query formats and rates */
1886 .prepare = via_capture_pcm_prepare,
1887 .cleanup = via_capture_pcm_cleanup
1891 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1895 /* NID is set in via_build_pcms */
1897 .open = via_dig_playback_pcm_open,
1898 .close = via_dig_playback_pcm_close,
1899 .prepare = via_dig_playback_pcm_prepare,
1900 .cleanup = via_dig_playback_pcm_cleanup
1904 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1910 static int via_build_controls(struct hda_codec *codec)
1912 struct via_spec *spec = codec->spec;
1913 struct snd_kcontrol *kctl;
1914 struct snd_kcontrol_new *knew;
1917 for (i = 0; i < spec->num_mixers; i++) {
1918 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1923 if (spec->multiout.dig_out_nid) {
1924 err = snd_hda_create_spdif_out_ctls(codec,
1925 spec->multiout.dig_out_nid);
1928 err = snd_hda_create_spdif_share_sw(codec,
1932 spec->multiout.share_spdif = 1;
1934 if (spec->dig_in_nid) {
1935 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1940 /* assign Capture Source enums to NID */
1941 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1942 for (i = 0; kctl && i < kctl->count; i++) {
1943 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1948 /* other nid->control mapping */
1949 for (i = 0; i < spec->num_mixers; i++) {
1950 for (knew = spec->mixers[i]; knew->name; knew++) {
1951 if (knew->iface != NID_MAPPING)
1953 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1956 err = snd_hda_add_nid(codec, kctl, 0,
1961 /* init power states */
1962 set_jack_power_state(codec);
1963 analog_low_current_mode(codec, 1);
1965 via_free_kctls(codec); /* no longer needed */
1969 static int via_build_pcms(struct hda_codec *codec)
1971 struct via_spec *spec = codec->spec;
1972 struct hda_pcm *info = spec->pcm_rec;
1974 codec->num_pcms = 1;
1975 codec->pcm_info = info;
1977 info->name = spec->stream_name_analog;
1978 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1979 *(spec->stream_analog_playback);
1980 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1981 spec->multiout.dac_nids[0];
1982 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1983 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1985 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1986 spec->multiout.max_channels;
1988 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1991 info->name = spec->stream_name_digital;
1992 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1993 if (spec->multiout.dig_out_nid) {
1994 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1995 *(spec->stream_digital_playback);
1996 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1997 spec->multiout.dig_out_nid;
1999 if (spec->dig_in_nid) {
2000 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2001 *(spec->stream_digital_capture);
2002 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2010 static void via_free(struct hda_codec *codec)
2012 struct via_spec *spec = codec->spec;
2017 via_free_kctls(codec);
2018 vt1708_stop_hp_work(spec);
2022 /* mute internal speaker if HP is plugged */
2023 static void via_hp_automute(struct hda_codec *codec)
2025 unsigned int present = 0;
2026 struct via_spec *spec = codec->spec;
2028 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2030 if (!spec->hp_independent_mode) {
2031 struct snd_ctl_elem_id id;
2033 snd_hda_codec_amp_stereo(
2034 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2035 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2037 memset(&id, 0, sizeof(id));
2038 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2039 strcpy(id.name, "Front Playback Switch");
2040 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2045 /* mute mono out if HP or Line out is plugged */
2046 static void via_mono_automute(struct hda_codec *codec)
2048 unsigned int hp_present, lineout_present;
2049 struct via_spec *spec = codec->spec;
2051 if (spec->codec_type != VT1716S)
2054 lineout_present = snd_hda_jack_detect(codec,
2055 spec->autocfg.line_out_pins[0]);
2057 /* Mute Mono Out if Line Out is plugged */
2058 if (lineout_present) {
2059 snd_hda_codec_amp_stereo(
2060 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2064 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2066 if (!spec->hp_independent_mode)
2067 snd_hda_codec_amp_stereo(
2068 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2069 hp_present ? HDA_AMP_MUTE : 0);
2072 static void via_gpio_control(struct hda_codec *codec)
2074 unsigned int gpio_data;
2075 unsigned int vol_counter;
2077 unsigned int master_vol;
2079 struct via_spec *spec = codec->spec;
2081 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2082 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2084 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2085 0xF84, 0) & 0x3F0000) >> 16;
2087 vol = vol_counter & 0x1F;
2088 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2089 AC_VERB_GET_AMP_GAIN_MUTE,
2092 if (gpio_data == 0x02) {
2093 /* unmute line out */
2094 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2095 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2097 if (vol_counter & 0x20) {
2098 /* decrease volume */
2099 if (vol > master_vol)
2101 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2105 /* increase volume */
2106 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2108 ((master_vol+vol) > 0x2A) ? 0x2A :
2111 } else if (!(gpio_data & 0x02)) {
2113 snd_hda_codec_amp_stereo(codec,
2114 spec->autocfg.line_out_pins[0],
2115 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2120 /* mute Internal-Speaker if HP is plugged */
2121 static void via_speaker_automute(struct hda_codec *codec)
2123 unsigned int hp_present;
2124 struct via_spec *spec = codec->spec;
2126 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2129 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2131 if (!spec->hp_independent_mode) {
2132 struct snd_ctl_elem_id id;
2133 snd_hda_codec_amp_stereo(
2134 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2135 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2137 memset(&id, 0, sizeof(id));
2138 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2139 strcpy(id.name, "Speaker Playback Switch");
2140 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2145 /* mute line-out and internal speaker if HP is plugged */
2146 static void via_hp_bind_automute(struct hda_codec *codec)
2148 /* use long instead of int below just to avoid an internal compiler
2149 * error with gcc 4.0.x
2151 unsigned long hp_present, present = 0;
2152 struct via_spec *spec = codec->spec;
2155 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2158 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2160 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2162 if (!spec->hp_independent_mode) {
2163 /* Mute Line-Outs */
2164 for (i = 0; i < spec->autocfg.line_outs; i++)
2165 snd_hda_codec_amp_stereo(
2166 codec, spec->autocfg.line_out_pins[i],
2168 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2170 present = hp_present;
2173 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2174 snd_hda_codec_amp_stereo(
2175 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2176 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2180 /* unsolicited event for jack sensing */
2181 static void via_unsol_event(struct hda_codec *codec,
2185 if (res & VIA_HP_EVENT)
2186 via_hp_automute(codec);
2187 if (res & VIA_GPIO_EVENT)
2188 via_gpio_control(codec);
2189 if (res & VIA_JACK_EVENT)
2190 set_jack_power_state(codec);
2191 if (res & VIA_MONO_EVENT)
2192 via_mono_automute(codec);
2193 if (res & VIA_SPEAKER_EVENT)
2194 via_speaker_automute(codec);
2195 if (res & VIA_BIND_HP_EVENT)
2196 via_hp_bind_automute(codec);
2199 static int via_init(struct hda_codec *codec)
2201 struct via_spec *spec = codec->spec;
2203 for (i = 0; i < spec->num_iverbs; i++)
2204 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2206 spec->codec_type = get_codec_type(codec);
2207 if (spec->codec_type == VT1708BCE)
2208 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2210 /* Lydia Add for EAPD enable */
2211 if (!spec->dig_in_nid) { /* No Digital In connection */
2212 if (spec->dig_in_pin) {
2213 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2214 AC_VERB_SET_PIN_WIDGET_CONTROL,
2216 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2217 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2219 } else /* enable SPDIF-input pin */
2220 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2221 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2223 /* assign slave outs */
2224 if (spec->slave_dig_outs[0])
2225 codec->slave_dig_outs = spec->slave_dig_outs;
2230 #ifdef SND_HDA_NEEDS_RESUME
2231 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2233 struct via_spec *spec = codec->spec;
2234 vt1708_stop_hp_work(spec);
2239 #ifdef CONFIG_SND_HDA_POWER_SAVE
2240 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2242 struct via_spec *spec = codec->spec;
2243 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2249 static struct hda_codec_ops via_patch_ops = {
2250 .build_controls = via_build_controls,
2251 .build_pcms = via_build_pcms,
2254 #ifdef SND_HDA_NEEDS_RESUME
2255 .suspend = via_suspend,
2257 #ifdef CONFIG_SND_HDA_POWER_SAVE
2258 .check_power_status = via_check_power_status,
2262 /* fill in the dac_nids table from the parsed pin configuration */
2263 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2264 const struct auto_pin_cfg *cfg)
2269 spec->multiout.num_dacs = cfg->line_outs;
2271 spec->multiout.dac_nids = spec->private_dac_nids;
2273 for (i = 0; i < 4; i++) {
2274 nid = cfg->line_out_pins[i];
2276 /* config dac list */
2278 case AUTO_SEQ_FRONT:
2279 spec->multiout.dac_nids[i] = 0x10;
2281 case AUTO_SEQ_CENLFE:
2282 spec->multiout.dac_nids[i] = 0x12;
2284 case AUTO_SEQ_SURROUND:
2285 spec->multiout.dac_nids[i] = 0x11;
2288 spec->multiout.dac_nids[i] = 0x13;
2297 /* add playback controls from the parsed DAC table */
2298 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2299 const struct auto_pin_cfg *cfg)
2302 static const char * const chname[4] = {
2303 "Front", "Surround", "C/LFE", "Side"
2305 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2308 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2309 nid = cfg->line_out_pins[i];
2314 nid_vol = nid_vols[i];
2316 if (i == AUTO_SEQ_CENLFE) {
2318 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2319 "Center Playback Volume",
2320 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2324 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2325 "LFE Playback Volume",
2326 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2330 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2331 "Center Playback Switch",
2332 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2336 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2337 "LFE Playback Switch",
2338 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2342 } else if (i == AUTO_SEQ_FRONT) {
2343 /* add control to mixer index 0 */
2344 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2345 "Master Front Playback Volume",
2346 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2350 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2351 "Master Front Playback Switch",
2352 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2357 /* add control to PW3 */
2358 sprintf(name, "%s Playback Volume", chname[i]);
2359 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2360 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2364 sprintf(name, "%s Playback Switch", chname[i]);
2365 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2366 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2371 sprintf(name, "%s Playback Volume", chname[i]);
2372 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2373 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2377 sprintf(name, "%s Playback Switch", chname[i]);
2378 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2379 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2389 static void create_hp_imux(struct via_spec *spec)
2392 struct hda_input_mux *imux = &spec->private_imux[1];
2393 static const char * const texts[] = { "OFF", "ON", NULL};
2395 /* for hp mode select */
2396 for (i = 0; texts[i]; i++)
2397 snd_hda_add_imux_item(imux, texts[i], i, NULL);
2399 spec->hp_mux = &spec->private_imux[1];
2402 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2409 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2410 spec->hp_independent_mode_index = 1;
2412 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2413 "Headphone Playback Volume",
2414 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2417 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2418 "Headphone Playback Switch",
2419 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2423 create_hp_imux(spec);
2428 /* create playback/capture controls for input pins */
2429 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2430 const struct auto_pin_cfg *cfg,
2432 hda_nid_t pin_idxs[], int num_idxs)
2434 struct via_spec *spec = codec->spec;
2435 struct hda_input_mux *imux = &spec->private_imux[0];
2436 int i, err, idx, type, type_idx = 0;
2438 /* for internal loopback recording select */
2439 for (idx = 0; idx < num_idxs; idx++) {
2440 if (pin_idxs[idx] == 0xff) {
2441 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2446 for (i = 0; i < cfg->num_inputs; i++) {
2448 type = cfg->inputs[i].type;
2449 for (idx = 0; idx < num_idxs; idx++)
2450 if (pin_idxs[idx] == cfg->inputs[i].pin)
2452 if (idx >= num_idxs)
2454 if (i > 0 && type == cfg->inputs[i - 1].type)
2458 label = hda_get_autocfg_input_label(codec, cfg, i);
2459 err = via_new_analog_input(spec, label, type_idx, idx, cap_nid);
2462 snd_hda_add_imux_item(imux, label, idx, NULL);
2467 /* create playback/capture controls for input pins */
2468 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2469 const struct auto_pin_cfg *cfg)
2471 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2472 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2473 ARRAY_SIZE(pin_idxs));
2476 #ifdef CONFIG_SND_HDA_POWER_SAVE
2477 static struct hda_amp_list vt1708_loopbacks[] = {
2478 { 0x17, HDA_INPUT, 1 },
2479 { 0x17, HDA_INPUT, 2 },
2480 { 0x17, HDA_INPUT, 3 },
2481 { 0x17, HDA_INPUT, 4 },
2486 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2488 unsigned int def_conf;
2489 unsigned char seqassoc;
2491 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2492 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2493 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2494 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2495 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2496 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2497 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2503 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2504 struct snd_ctl_elem_value *ucontrol)
2506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2507 struct via_spec *spec = codec->spec;
2509 if (spec->codec_type != VT1708)
2511 spec->vt1708_jack_detectect =
2512 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2513 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2517 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2518 struct snd_ctl_elem_value *ucontrol)
2520 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2521 struct via_spec *spec = codec->spec;
2524 if (spec->codec_type != VT1708)
2526 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2527 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2528 == !spec->vt1708_jack_detectect;
2529 if (spec->vt1708_jack_detectect) {
2530 mute_aa_path(codec, 1);
2531 notify_aa_path_ctls(codec);
2536 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2538 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2539 .name = "Jack Detect",
2541 .info = snd_ctl_boolean_mono_info,
2542 .get = vt1708_jack_detectect_get,
2543 .put = vt1708_jack_detectect_put,
2548 static int vt1708_parse_auto_config(struct hda_codec *codec)
2550 struct via_spec *spec = codec->spec;
2553 /* Add HP and CD pin config connect bit re-config action */
2554 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2555 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2557 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2560 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2563 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2564 return 0; /* can't find valid BIOS pin config */
2566 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2569 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2572 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2575 /* add jack detect on/off control */
2576 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2580 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2582 if (spec->autocfg.dig_outs)
2583 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2584 spec->dig_in_pin = VT1708_DIGIN_PIN;
2585 if (spec->autocfg.dig_in_pin)
2586 spec->dig_in_nid = VT1708_DIGIN_NID;
2588 if (spec->kctls.list)
2589 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2591 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2593 spec->input_mux = &spec->private_imux[0];
2596 via_hp_build(codec);
2598 via_smart51_build(spec);
2602 /* init callback for auto-configuration model -- overriding the default init */
2603 static int via_auto_init(struct hda_codec *codec)
2605 struct via_spec *spec = codec->spec;
2608 via_auto_init_multi_out(codec);
2609 via_auto_init_hp_out(codec);
2610 via_auto_init_analog_input(codec);
2611 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2612 via_hp_bind_automute(codec);
2614 via_hp_automute(codec);
2615 via_speaker_automute(codec);
2621 static void vt1708_update_hp_jack_state(struct work_struct *work)
2623 struct via_spec *spec = container_of(work, struct via_spec,
2624 vt1708_hp_work.work);
2625 if (spec->codec_type != VT1708)
2627 /* if jack state toggled */
2628 if (spec->vt1708_hp_present
2629 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2630 spec->vt1708_hp_present ^= 1;
2631 via_hp_automute(spec->codec);
2633 vt1708_start_hp_work(spec);
2636 static int get_mux_nids(struct hda_codec *codec)
2638 struct via_spec *spec = codec->spec;
2639 hda_nid_t nid, conn[8];
2643 for (i = 0; i < spec->num_adc_nids; i++) {
2644 nid = spec->adc_nids[i];
2646 type = get_wcaps_type(get_wcaps(codec, nid));
2647 if (type == AC_WID_PIN)
2649 n = snd_hda_get_connections(codec, nid, conn,
2654 spec->mux_nids[i] = nid;
2663 static int patch_vt1708(struct hda_codec *codec)
2665 struct via_spec *spec;
2668 /* create a codec specific record */
2669 spec = via_new_spec(codec);
2673 /* automatic parse from the BIOS config */
2674 err = vt1708_parse_auto_config(codec);
2679 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2680 "from BIOS. Using genenic mode...\n");
2684 spec->stream_name_analog = "VT1708 Analog";
2685 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2686 /* disable 32bit format on VT1708 */
2687 if (codec->vendor_id == 0x11061708)
2688 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2689 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2691 spec->stream_name_digital = "VT1708 Digital";
2692 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2693 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2696 if (!spec->adc_nids && spec->input_mux) {
2697 spec->adc_nids = vt1708_adc_nids;
2698 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2699 get_mux_nids(codec);
2700 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2704 codec->patch_ops = via_patch_ops;
2706 codec->patch_ops.init = via_auto_init;
2707 #ifdef CONFIG_SND_HDA_POWER_SAVE
2708 spec->loopback.amplist = vt1708_loopbacks;
2710 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2714 /* capture mixer elements */
2715 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2716 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2717 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2718 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2719 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2720 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2721 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2724 /* The multiple "Capture Source" controls confuse alsamixer
2725 * So call somewhat different..
2727 /* .name = "Capture Source", */
2728 .name = "Input Source",
2730 .info = via_mux_enum_info,
2731 .get = via_mux_enum_get,
2732 .put = via_mux_enum_put,
2737 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2738 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2739 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2744 * generic initialization of ADC, input mixers and output mixers
2746 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2748 * Unmute ADC0-2 and set the default input to mic-in
2750 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2751 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2752 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2755 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2758 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2759 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2760 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2761 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2762 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2763 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2766 * Set up output selector (0x1a, 0x1b, 0x29)
2768 /* set vol=0 to output mixers */
2769 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2770 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2771 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2774 * Unmute PW3 and PW4
2776 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2777 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2779 /* Set input of PW4 as MW0 */
2780 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2781 /* PW9 Output enable */
2782 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2786 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2790 .nid = 0x10, /* NID to query formats and rates */
2792 .open = via_playback_pcm_open,
2793 .prepare = via_playback_multi_pcm_prepare,
2794 .cleanup = via_playback_multi_pcm_cleanup,
2798 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2802 .nid = 0x10, /* NID to query formats and rates */
2804 .open = via_playback_pcm_open,
2805 .prepare = via_playback_multi_pcm_prepare,
2806 .cleanup = via_playback_multi_pcm_cleanup,
2810 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2814 .nid = 0x14, /* NID to query formats and rates */
2816 .prepare = via_capture_pcm_prepare,
2817 .cleanup = via_capture_pcm_cleanup
2821 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2825 /* NID is set in via_build_pcms */
2827 .open = via_dig_playback_pcm_open,
2828 .close = via_dig_playback_pcm_close
2832 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2838 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2839 const struct auto_pin_cfg *cfg)
2844 if (cfg->line_outs == 4) /* 10 channels */
2845 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2846 else if (cfg->line_outs == 3) /* 6 channels */
2847 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2849 spec->multiout.dac_nids = spec->private_dac_nids;
2851 if (cfg->line_outs == 4) { /* 10 channels */
2852 for (i = 0; i < cfg->line_outs; i++) {
2853 nid = cfg->line_out_pins[i];
2855 /* config dac list */
2857 case AUTO_SEQ_FRONT:
2859 spec->multiout.dac_nids[i] = 0x10;
2861 case AUTO_SEQ_CENLFE:
2863 spec->multiout.dac_nids[i] = 0x12;
2865 case AUTO_SEQ_SURROUND:
2867 spec->multiout.dac_nids[i] = 0x11;
2871 spec->multiout.dac_nids[i] = 0x27;
2878 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2880 } else if (cfg->line_outs == 3) { /* 6 channels */
2881 for (i = 0; i < cfg->line_outs; i++) {
2882 nid = cfg->line_out_pins[i];
2884 /* config dac list */
2886 case AUTO_SEQ_FRONT:
2888 spec->multiout.dac_nids[i] = 0x10;
2890 case AUTO_SEQ_CENLFE:
2892 spec->multiout.dac_nids[i] = 0x12;
2894 case AUTO_SEQ_SURROUND:
2896 spec->multiout.dac_nids[i] = 0x11;
2908 /* add playback controls from the parsed DAC table */
2909 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2910 const struct auto_pin_cfg *cfg)
2913 static const char * const chname[4] = {
2914 "Front", "Surround", "C/LFE", "Side"
2916 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2919 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2920 nid = cfg->line_out_pins[i];
2925 nid_vol = nid_vols[i];
2927 if (i == AUTO_SEQ_CENLFE) {
2929 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2930 "Center Playback Volume",
2931 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2935 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2936 "LFE Playback Volume",
2937 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2941 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2942 "Center Playback Switch",
2943 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2947 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2948 "LFE Playback Switch",
2949 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2953 } else if (i == AUTO_SEQ_FRONT) {
2954 /* ADD control to mixer index 0 */
2955 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2956 "Master Front Playback Volume",
2957 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2961 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2962 "Master Front Playback Switch",
2963 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2968 /* add control to PW3 */
2969 sprintf(name, "%s Playback Volume", chname[i]);
2970 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2971 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2975 sprintf(name, "%s Playback Switch", chname[i]);
2976 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2977 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2981 } else if (i == AUTO_SEQ_SURROUND) {
2982 sprintf(name, "%s Playback Volume", chname[i]);
2983 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2984 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2988 sprintf(name, "%s Playback Switch", chname[i]);
2989 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2990 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2994 } else if (i == AUTO_SEQ_SIDE) {
2995 sprintf(name, "%s Playback Volume", chname[i]);
2996 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2997 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3001 sprintf(name, "%s Playback Switch", chname[i]);
3002 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3003 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3013 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3020 if (spec->multiout.num_dacs == 5) /* 10 channels */
3021 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
3022 else if (spec->multiout.num_dacs == 3) /* 6 channels */
3023 spec->multiout.hp_nid = 0;
3024 spec->hp_independent_mode_index = 1;
3026 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3027 "Headphone Playback Volume",
3028 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3031 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3032 "Headphone Playback Switch",
3033 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3040 /* create playback/capture controls for input pins */
3041 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
3042 const struct auto_pin_cfg *cfg)
3044 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
3045 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
3046 ARRAY_SIZE(pin_idxs));
3049 static int vt1709_parse_auto_config(struct hda_codec *codec)
3051 struct via_spec *spec = codec->spec;
3054 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3057 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3060 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3061 return 0; /* can't find valid BIOS pin config */
3063 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3066 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3069 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
3073 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3075 if (spec->autocfg.dig_outs)
3076 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3077 spec->dig_in_pin = VT1709_DIGIN_PIN;
3078 if (spec->autocfg.dig_in_pin)
3079 spec->dig_in_nid = VT1709_DIGIN_NID;
3081 if (spec->kctls.list)
3082 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3084 spec->input_mux = &spec->private_imux[0];
3087 via_hp_build(codec);
3089 via_smart51_build(spec);
3093 #ifdef CONFIG_SND_HDA_POWER_SAVE
3094 static struct hda_amp_list vt1709_loopbacks[] = {
3095 { 0x18, HDA_INPUT, 1 },
3096 { 0x18, HDA_INPUT, 2 },
3097 { 0x18, HDA_INPUT, 3 },
3098 { 0x18, HDA_INPUT, 4 },
3103 static int patch_vt1709_10ch(struct hda_codec *codec)
3105 struct via_spec *spec;
3108 /* create a codec specific record */
3109 spec = via_new_spec(codec);
3113 err = vt1709_parse_auto_config(codec);
3118 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3119 "Using genenic mode...\n");
3122 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3123 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3125 spec->stream_name_analog = "VT1709 Analog";
3126 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3127 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3129 spec->stream_name_digital = "VT1709 Digital";
3130 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3131 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3134 if (!spec->adc_nids && spec->input_mux) {
3135 spec->adc_nids = vt1709_adc_nids;
3136 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3137 get_mux_nids(codec);
3138 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3142 codec->patch_ops = via_patch_ops;
3144 codec->patch_ops.init = via_auto_init;
3145 codec->patch_ops.unsol_event = via_unsol_event;
3146 #ifdef CONFIG_SND_HDA_POWER_SAVE
3147 spec->loopback.amplist = vt1709_loopbacks;
3153 * generic initialization of ADC, input mixers and output mixers
3155 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3157 * Unmute ADC0-2 and set the default input to mic-in
3159 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3160 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3161 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3164 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3167 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3168 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3169 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3170 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3171 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3172 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3175 * Set up output selector (0x1a, 0x1b, 0x29)
3177 /* set vol=0 to output mixers */
3178 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3179 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3180 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3183 * Unmute PW3 and PW4
3185 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3186 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3188 /* Set input of PW4 as MW0 */
3189 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3190 /* PW9 Output enable */
3191 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3195 static int patch_vt1709_6ch(struct hda_codec *codec)
3197 struct via_spec *spec;
3200 /* create a codec specific record */
3201 spec = via_new_spec(codec);
3205 err = vt1709_parse_auto_config(codec);
3210 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3211 "Using genenic mode...\n");
3214 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3215 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3217 spec->stream_name_analog = "VT1709 Analog";
3218 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3219 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3221 spec->stream_name_digital = "VT1709 Digital";
3222 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3223 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3226 if (!spec->adc_nids && spec->input_mux) {
3227 spec->adc_nids = vt1709_adc_nids;
3228 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3229 get_mux_nids(codec);
3230 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3234 codec->patch_ops = via_patch_ops;
3236 codec->patch_ops.init = via_auto_init;
3237 codec->patch_ops.unsol_event = via_unsol_event;
3238 #ifdef CONFIG_SND_HDA_POWER_SAVE
3239 spec->loopback.amplist = vt1709_loopbacks;
3244 /* capture mixer elements */
3245 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3246 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3247 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3248 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3249 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3251 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3252 /* The multiple "Capture Source" controls confuse alsamixer
3253 * So call somewhat different..
3255 /* .name = "Capture Source", */
3256 .name = "Input Source",
3258 .info = via_mux_enum_info,
3259 .get = via_mux_enum_get,
3260 .put = via_mux_enum_put,
3265 * generic initialization of ADC, input mixers and output mixers
3267 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3269 * Unmute ADC0-1 and set the default input to mic-in
3271 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3272 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3275 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3278 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3279 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3280 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3281 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3282 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3283 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3286 * Set up output mixers
3288 /* set vol=0 to output mixers */
3289 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3290 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3291 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3293 /* Setup default input to PW4 */
3294 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3295 /* PW9 Output enable */
3296 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3297 /* PW10 Input enable */
3298 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3302 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3304 * Unmute ADC0-1 and set the default input to mic-in
3306 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3307 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3310 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3313 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3314 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3315 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3316 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3317 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3318 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3321 * Set up output mixers
3323 /* set vol=0 to output mixers */
3324 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3325 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3326 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3328 /* Setup default input of PW4 to MW0 */
3329 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3330 /* PW9 Output enable */
3331 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3332 /* PW10 Input enable */
3333 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3337 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3338 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3339 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3340 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3341 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3342 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3343 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3344 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3345 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3346 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3350 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3351 struct hda_codec *codec,
3352 struct snd_pcm_substream *substream)
3354 int idle = substream->pstr->substream_opened == 1
3355 && substream->ref_count == 0;
3357 analog_low_current_mode(codec, idle);
3361 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3365 .nid = 0x10, /* NID to query formats and rates */
3367 .open = via_playback_pcm_open,
3368 .prepare = via_playback_multi_pcm_prepare,
3369 .cleanup = via_playback_multi_pcm_cleanup,
3370 .close = via_pcm_open_close
3374 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3378 .nid = 0x10, /* NID to query formats and rates */
3380 .open = via_playback_pcm_open,
3381 .prepare = via_playback_multi_pcm_prepare,
3382 .cleanup = via_playback_multi_pcm_cleanup
3386 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3390 .nid = 0x13, /* NID to query formats and rates */
3392 .open = via_pcm_open_close,
3393 .prepare = via_capture_pcm_prepare,
3394 .cleanup = via_capture_pcm_cleanup,
3395 .close = via_pcm_open_close
3399 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3403 /* NID is set in via_build_pcms */
3405 .open = via_dig_playback_pcm_open,
3406 .close = via_dig_playback_pcm_close,
3407 .prepare = via_dig_playback_pcm_prepare,
3408 .cleanup = via_dig_playback_pcm_cleanup
3412 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3418 /* fill in the dac_nids table from the parsed pin configuration */
3419 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3420 const struct auto_pin_cfg *cfg)
3425 spec->multiout.num_dacs = cfg->line_outs;
3427 spec->multiout.dac_nids = spec->private_dac_nids;
3429 for (i = 0; i < 4; i++) {
3430 nid = cfg->line_out_pins[i];
3432 /* config dac list */
3434 case AUTO_SEQ_FRONT:
3435 spec->multiout.dac_nids[i] = 0x10;
3437 case AUTO_SEQ_CENLFE:
3438 spec->multiout.dac_nids[i] = 0x24;
3440 case AUTO_SEQ_SURROUND:
3441 spec->multiout.dac_nids[i] = 0x11;
3444 spec->multiout.dac_nids[i] = 0x25;
3453 /* add playback controls from the parsed DAC table */
3454 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3455 const struct auto_pin_cfg *cfg)
3458 static const char * const chname[4] = {
3459 "Front", "Surround", "C/LFE", "Side"
3461 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3462 hda_nid_t nid, nid_vol = 0;
3465 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3466 nid = cfg->line_out_pins[i];
3471 nid_vol = nid_vols[i];
3473 if (i == AUTO_SEQ_CENLFE) {
3475 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3476 "Center Playback Volume",
3477 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3481 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3482 "LFE Playback Volume",
3483 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3487 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3488 "Center Playback Switch",
3489 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3493 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3494 "LFE Playback Switch",
3495 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3499 } else if (i == AUTO_SEQ_FRONT) {
3500 /* add control to mixer index 0 */
3501 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3502 "Master Front Playback Volume",
3503 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3507 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3508 "Master Front Playback Switch",
3509 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3514 /* add control to PW3 */
3515 sprintf(name, "%s Playback Volume", chname[i]);
3516 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3517 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3521 sprintf(name, "%s Playback Switch", chname[i]);
3522 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3523 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3528 sprintf(name, "%s Playback Volume", chname[i]);
3529 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3530 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3534 sprintf(name, "%s Playback Switch", chname[i]);
3535 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3536 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3546 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3553 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3554 spec->hp_independent_mode_index = 1;
3556 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3557 "Headphone Playback Volume",
3558 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3561 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3562 "Headphone Playback Switch",
3563 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3567 create_hp_imux(spec);
3572 /* create playback/capture controls for input pins */
3573 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3574 const struct auto_pin_cfg *cfg)
3576 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3577 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3578 ARRAY_SIZE(pin_idxs));
3581 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3583 struct via_spec *spec = codec->spec;
3586 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3589 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3592 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3593 return 0; /* can't find valid BIOS pin config */
3595 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3598 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3601 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3605 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3607 if (spec->autocfg.dig_outs)
3608 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3609 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3610 if (spec->autocfg.dig_in_pin)
3611 spec->dig_in_nid = VT1708B_DIGIN_NID;
3613 if (spec->kctls.list)
3614 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3616 spec->input_mux = &spec->private_imux[0];
3619 via_hp_build(codec);
3621 via_smart51_build(spec);
3625 #ifdef CONFIG_SND_HDA_POWER_SAVE
3626 static struct hda_amp_list vt1708B_loopbacks[] = {
3627 { 0x16, HDA_INPUT, 1 },
3628 { 0x16, HDA_INPUT, 2 },
3629 { 0x16, HDA_INPUT, 3 },
3630 { 0x16, HDA_INPUT, 4 },
3634 static int patch_vt1708S(struct hda_codec *codec);
3635 static int patch_vt1708B_8ch(struct hda_codec *codec)
3637 struct via_spec *spec;
3640 if (get_codec_type(codec) == VT1708BCE)
3641 return patch_vt1708S(codec);
3642 /* create a codec specific record */
3643 spec = via_new_spec(codec);
3647 /* automatic parse from the BIOS config */
3648 err = vt1708B_parse_auto_config(codec);
3653 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3654 "from BIOS. Using genenic mode...\n");
3657 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3658 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3660 spec->stream_name_analog = "VT1708B Analog";
3661 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3662 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3664 spec->stream_name_digital = "VT1708B Digital";
3665 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3666 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3668 if (!spec->adc_nids && spec->input_mux) {
3669 spec->adc_nids = vt1708B_adc_nids;
3670 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3671 get_mux_nids(codec);
3672 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3676 codec->patch_ops = via_patch_ops;
3678 codec->patch_ops.init = via_auto_init;
3679 codec->patch_ops.unsol_event = via_unsol_event;
3680 #ifdef CONFIG_SND_HDA_POWER_SAVE
3681 spec->loopback.amplist = vt1708B_loopbacks;
3687 static int patch_vt1708B_4ch(struct hda_codec *codec)
3689 struct via_spec *spec;
3692 /* create a codec specific record */
3693 spec = via_new_spec(codec);
3697 /* automatic parse from the BIOS config */
3698 err = vt1708B_parse_auto_config(codec);
3703 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3704 "from BIOS. Using genenic mode...\n");
3707 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3708 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3710 spec->stream_name_analog = "VT1708B Analog";
3711 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3712 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3714 spec->stream_name_digital = "VT1708B Digital";
3715 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3716 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3718 if (!spec->adc_nids && spec->input_mux) {
3719 spec->adc_nids = vt1708B_adc_nids;
3720 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3721 get_mux_nids(codec);
3722 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3726 codec->patch_ops = via_patch_ops;
3728 codec->patch_ops.init = via_auto_init;
3729 codec->patch_ops.unsol_event = via_unsol_event;
3730 #ifdef CONFIG_SND_HDA_POWER_SAVE
3731 spec->loopback.amplist = vt1708B_loopbacks;
3737 /* Patch for VT1708S */
3739 /* capture mixer elements */
3740 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3741 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3742 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3743 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3744 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3745 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3746 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3749 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3750 /* The multiple "Capture Source" controls confuse alsamixer
3751 * So call somewhat different..
3753 /* .name = "Capture Source", */
3754 .name = "Input Source",
3756 .info = via_mux_enum_info,
3757 .get = via_mux_enum_get,
3758 .put = via_mux_enum_put,
3763 static struct hda_verb vt1708S_volume_init_verbs[] = {
3764 /* Unmute ADC0-1 and set the default input to mic-in */
3765 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3766 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3768 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3769 * analog-loopback mixer widget */
3770 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3771 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3772 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3773 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3774 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3775 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3777 /* Setup default input of PW4 to MW0 */
3778 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3779 /* PW9, PW10 Output enable */
3780 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3781 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3782 /* Enable Mic Boost Volume backdoor */
3784 /* don't bybass mixer */
3789 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3790 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3791 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3792 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3793 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3794 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3795 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3796 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3797 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3798 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3802 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3806 .nid = 0x10, /* NID to query formats and rates */
3808 .open = via_playback_pcm_open,
3809 .prepare = via_playback_multi_pcm_prepare,
3810 .cleanup = via_playback_multi_pcm_cleanup,
3811 .close = via_pcm_open_close
3815 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3819 .nid = 0x13, /* NID to query formats and rates */
3821 .open = via_pcm_open_close,
3822 .prepare = via_capture_pcm_prepare,
3823 .cleanup = via_capture_pcm_cleanup,
3824 .close = via_pcm_open_close
3828 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3832 /* NID is set in via_build_pcms */
3834 .open = via_dig_playback_pcm_open,
3835 .close = via_dig_playback_pcm_close,
3836 .prepare = via_dig_playback_pcm_prepare,
3837 .cleanup = via_dig_playback_pcm_cleanup
3841 /* fill in the dac_nids table from the parsed pin configuration */
3842 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3843 const struct auto_pin_cfg *cfg)
3848 spec->multiout.num_dacs = cfg->line_outs;
3850 spec->multiout.dac_nids = spec->private_dac_nids;
3852 for (i = 0; i < 4; i++) {
3853 nid = cfg->line_out_pins[i];
3855 /* config dac list */
3857 case AUTO_SEQ_FRONT:
3858 spec->multiout.dac_nids[i] = 0x10;
3860 case AUTO_SEQ_CENLFE:
3861 spec->multiout.dac_nids[i] = 0x24;
3863 case AUTO_SEQ_SURROUND:
3864 spec->multiout.dac_nids[i] = 0x11;
3867 spec->multiout.dac_nids[i] = 0x25;
3873 /* for Smart 5.1, line/mic inputs double as output pins */
3874 if (cfg->line_outs == 1) {
3875 spec->multiout.num_dacs = 3;
3876 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3877 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3883 /* add playback controls from the parsed DAC table */
3884 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3885 const struct auto_pin_cfg *cfg)
3888 static const char * const chname[4] = {
3889 "Front", "Surround", "C/LFE", "Side"
3891 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3892 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3893 hda_nid_t nid, nid_vol, nid_mute;
3896 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3897 nid = cfg->line_out_pins[i];
3899 /* for Smart 5.1, there are always at least six channels */
3900 if (!nid && i > AUTO_SEQ_CENLFE)
3903 nid_vol = nid_vols[i];
3904 nid_mute = nid_mutes[i];
3906 if (i == AUTO_SEQ_CENLFE) {
3908 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3909 "Center Playback Volume",
3910 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3914 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3915 "LFE Playback Volume",
3916 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3920 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3921 "Center Playback Switch",
3922 HDA_COMPOSE_AMP_VAL(nid_mute,
3927 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3928 "LFE Playback Switch",
3929 HDA_COMPOSE_AMP_VAL(nid_mute,
3934 } else if (i == AUTO_SEQ_FRONT) {
3935 /* add control to mixer index 0 */
3936 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3937 "Master Front Playback Volume",
3938 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3942 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3943 "Master Front Playback Switch",
3944 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3950 sprintf(name, "%s Playback Volume", chname[i]);
3951 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3952 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3956 sprintf(name, "%s Playback Switch", chname[i]);
3957 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3958 HDA_COMPOSE_AMP_VAL(nid_mute,
3964 sprintf(name, "%s Playback Volume", chname[i]);
3965 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3966 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3970 sprintf(name, "%s Playback Switch", chname[i]);
3971 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3972 HDA_COMPOSE_AMP_VAL(nid_mute,
3983 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3990 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3991 spec->hp_independent_mode_index = 1;
3993 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3994 "Headphone Playback Volume",
3995 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3999 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4000 "Headphone Playback Switch",
4001 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4005 create_hp_imux(spec);
4010 /* create playback/capture controls for input pins */
4011 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
4012 const struct auto_pin_cfg *cfg)
4014 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
4015 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
4016 ARRAY_SIZE(pin_idxs));
4019 /* fill out digital output widgets; one for master and one for slave outputs */
4020 static void fill_dig_outs(struct hda_codec *codec)
4022 struct via_spec *spec = codec->spec;
4025 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4029 nid = spec->autocfg.dig_out_pins[i];
4032 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4035 if (!spec->multiout.dig_out_nid)
4036 spec->multiout.dig_out_nid = nid;
4038 spec->slave_dig_outs[0] = nid;
4039 break; /* at most two dig outs */
4044 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4046 struct via_spec *spec = codec->spec;
4049 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4052 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4055 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4056 return 0; /* can't find valid BIOS pin config */
4058 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4061 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4064 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4068 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4070 fill_dig_outs(codec);
4072 if (spec->kctls.list)
4073 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4075 spec->input_mux = &spec->private_imux[0];
4078 via_hp_build(codec);
4080 via_smart51_build(spec);
4084 #ifdef CONFIG_SND_HDA_POWER_SAVE
4085 static struct hda_amp_list vt1708S_loopbacks[] = {
4086 { 0x16, HDA_INPUT, 1 },
4087 { 0x16, HDA_INPUT, 2 },
4088 { 0x16, HDA_INPUT, 3 },
4089 { 0x16, HDA_INPUT, 4 },
4094 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4095 int offset, int num_steps, int step_size)
4097 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4098 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4099 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4100 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4101 (0 << AC_AMPCAP_MUTE_SHIFT));
4104 static int patch_vt1708S(struct hda_codec *codec)
4106 struct via_spec *spec;
4109 /* create a codec specific record */
4110 spec = via_new_spec(codec);
4114 /* automatic parse from the BIOS config */
4115 err = vt1708S_parse_auto_config(codec);
4120 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4121 "from BIOS. Using genenic mode...\n");
4124 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4125 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4127 if (codec->vendor_id == 0x11060440)
4128 spec->stream_name_analog = "VT1818S Analog";
4130 spec->stream_name_analog = "VT1708S Analog";
4131 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4132 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4134 if (codec->vendor_id == 0x11060440)
4135 spec->stream_name_digital = "VT1818S Digital";
4137 spec->stream_name_digital = "VT1708S Digital";
4138 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4140 if (!spec->adc_nids && spec->input_mux) {
4141 spec->adc_nids = vt1708S_adc_nids;
4142 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4143 get_mux_nids(codec);
4144 override_mic_boost(codec, 0x1a, 0, 3, 40);
4145 override_mic_boost(codec, 0x1e, 0, 3, 40);
4146 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4150 codec->patch_ops = via_patch_ops;
4152 codec->patch_ops.init = via_auto_init;
4153 codec->patch_ops.unsol_event = via_unsol_event;
4154 #ifdef CONFIG_SND_HDA_POWER_SAVE
4155 spec->loopback.amplist = vt1708S_loopbacks;
4158 /* correct names for VT1708BCE */
4159 if (get_codec_type(codec) == VT1708BCE) {
4160 kfree(codec->chip_name);
4161 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4162 snprintf(codec->bus->card->mixername,
4163 sizeof(codec->bus->card->mixername),
4164 "%s %s", codec->vendor_name, codec->chip_name);
4165 spec->stream_name_analog = "VT1708BCE Analog";
4166 spec->stream_name_digital = "VT1708BCE Digital";
4171 /* Patch for VT1702 */
4173 /* capture mixer elements */
4174 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4175 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4176 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4177 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4178 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4179 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4180 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4181 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4184 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4185 /* The multiple "Capture Source" controls confuse alsamixer
4186 * So call somewhat different..
4188 /* .name = "Capture Source", */
4189 .name = "Input Source",
4191 .info = via_mux_enum_info,
4192 .get = via_mux_enum_get,
4193 .put = via_mux_enum_put,
4198 static struct hda_verb vt1702_volume_init_verbs[] = {
4200 * Unmute ADC0-1 and set the default input to mic-in
4202 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4203 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4204 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4207 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4210 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4211 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4212 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4213 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4214 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4215 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4217 /* Setup default input of PW4 to MW0 */
4218 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4219 /* PW6 PW7 Output enable */
4220 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4221 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4229 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4230 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4231 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4232 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4233 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4234 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4235 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4239 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4243 .nid = 0x10, /* NID to query formats and rates */
4245 .open = via_playback_pcm_open,
4246 .prepare = via_playback_multi_pcm_prepare,
4247 .cleanup = via_playback_multi_pcm_cleanup,
4248 .close = via_pcm_open_close
4252 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4256 .nid = 0x12, /* NID to query formats and rates */
4258 .open = via_pcm_open_close,
4259 .prepare = via_capture_pcm_prepare,
4260 .cleanup = via_capture_pcm_cleanup,
4261 .close = via_pcm_open_close
4265 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4269 /* NID is set in via_build_pcms */
4271 .open = via_dig_playback_pcm_open,
4272 .close = via_dig_playback_pcm_close,
4273 .prepare = via_dig_playback_pcm_prepare,
4274 .cleanup = via_dig_playback_pcm_cleanup
4278 /* fill in the dac_nids table from the parsed pin configuration */
4279 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4280 const struct auto_pin_cfg *cfg)
4282 spec->multiout.num_dacs = 1;
4283 spec->multiout.dac_nids = spec->private_dac_nids;
4285 if (cfg->line_out_pins[0]) {
4286 /* config dac list */
4287 spec->multiout.dac_nids[0] = 0x10;
4293 /* add playback controls from the parsed DAC table */
4294 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4295 const struct auto_pin_cfg *cfg)
4299 if (!cfg->line_out_pins[0])
4302 /* add control to mixer index 0 */
4303 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4304 "Master Front Playback Volume",
4305 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4308 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4309 "Master Front Playback Switch",
4310 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4315 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4316 "Front Playback Volume",
4317 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4320 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4321 "Front Playback Switch",
4322 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4329 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4332 struct hda_input_mux *imux;
4333 static const char * const texts[] = { "ON", "OFF", NULL};
4336 spec->multiout.hp_nid = 0x1D;
4337 spec->hp_independent_mode_index = 0;
4339 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4340 "Headphone Playback Volume",
4341 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4345 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4346 "Headphone Playback Switch",
4347 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4351 imux = &spec->private_imux[1];
4353 /* for hp mode select */
4354 for (i = 0; texts[i]; i++)
4355 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4357 spec->hp_mux = &spec->private_imux[1];
4361 /* create playback/capture controls for input pins */
4362 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4363 const struct auto_pin_cfg *cfg)
4365 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4366 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4367 ARRAY_SIZE(pin_idxs));
4370 static int vt1702_parse_auto_config(struct hda_codec *codec)
4372 struct via_spec *spec = codec->spec;
4375 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4378 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4381 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4382 return 0; /* can't find valid BIOS pin config */
4384 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4387 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4390 /* limit AA path volume to 0 dB */
4391 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4392 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4393 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4394 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4395 (1 << AC_AMPCAP_MUTE_SHIFT));
4396 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4400 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4402 fill_dig_outs(codec);
4404 if (spec->kctls.list)
4405 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4407 spec->input_mux = &spec->private_imux[0];
4410 via_hp_build(codec);
4415 #ifdef CONFIG_SND_HDA_POWER_SAVE
4416 static struct hda_amp_list vt1702_loopbacks[] = {
4417 { 0x1A, HDA_INPUT, 1 },
4418 { 0x1A, HDA_INPUT, 2 },
4419 { 0x1A, HDA_INPUT, 3 },
4420 { 0x1A, HDA_INPUT, 4 },
4425 static int patch_vt1702(struct hda_codec *codec)
4427 struct via_spec *spec;
4430 /* create a codec specific record */
4431 spec = via_new_spec(codec);
4435 /* automatic parse from the BIOS config */
4436 err = vt1702_parse_auto_config(codec);
4441 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4442 "from BIOS. Using genenic mode...\n");
4445 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4446 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4448 spec->stream_name_analog = "VT1702 Analog";
4449 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4450 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4452 spec->stream_name_digital = "VT1702 Digital";
4453 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4455 if (!spec->adc_nids && spec->input_mux) {
4456 spec->adc_nids = vt1702_adc_nids;
4457 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4458 get_mux_nids(codec);
4459 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4463 codec->patch_ops = via_patch_ops;
4465 codec->patch_ops.init = via_auto_init;
4466 codec->patch_ops.unsol_event = via_unsol_event;
4467 #ifdef CONFIG_SND_HDA_POWER_SAVE
4468 spec->loopback.amplist = vt1702_loopbacks;
4474 /* Patch for VT1718S */
4476 /* capture mixer elements */
4477 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4478 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4479 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4480 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4481 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4482 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4483 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4486 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4487 /* The multiple "Capture Source" controls confuse alsamixer
4488 * So call somewhat different..
4490 .name = "Input Source",
4492 .info = via_mux_enum_info,
4493 .get = via_mux_enum_get,
4494 .put = via_mux_enum_put,
4499 static struct hda_verb vt1718S_volume_init_verbs[] = {
4501 * Unmute ADC0-1 and set the default input to mic-in
4503 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4504 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4507 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4510 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4511 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4512 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4513 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4514 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4515 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4517 /* Setup default input of Front HP to MW9 */
4518 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4519 /* PW9 PW10 Output enable */
4520 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4521 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4522 /* PW11 Input enable */
4523 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4524 /* Enable Boost Volume backdoor */
4526 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4527 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4528 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4529 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4530 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4531 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4532 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4533 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4534 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4535 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4536 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4537 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4538 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4539 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4540 /* Unmute MW4's index 0 */
4541 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4546 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4547 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4548 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4549 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4550 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4551 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4552 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4553 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4554 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4555 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4559 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4563 .nid = 0x8, /* NID to query formats and rates */
4565 .open = via_playback_pcm_open,
4566 .prepare = via_playback_multi_pcm_prepare,
4567 .cleanup = via_playback_multi_pcm_cleanup,
4568 .close = via_pcm_open_close,
4572 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4576 .nid = 0x10, /* NID to query formats and rates */
4578 .open = via_pcm_open_close,
4579 .prepare = via_capture_pcm_prepare,
4580 .cleanup = via_capture_pcm_cleanup,
4581 .close = via_pcm_open_close,
4585 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4589 /* NID is set in via_build_pcms */
4591 .open = via_dig_playback_pcm_open,
4592 .close = via_dig_playback_pcm_close,
4593 .prepare = via_dig_playback_pcm_prepare,
4594 .cleanup = via_dig_playback_pcm_cleanup
4598 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4604 /* fill in the dac_nids table from the parsed pin configuration */
4605 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4606 const struct auto_pin_cfg *cfg)
4611 spec->multiout.num_dacs = cfg->line_outs;
4613 spec->multiout.dac_nids = spec->private_dac_nids;
4615 for (i = 0; i < 4; i++) {
4616 nid = cfg->line_out_pins[i];
4618 /* config dac list */
4620 case AUTO_SEQ_FRONT:
4621 spec->multiout.dac_nids[i] = 0x8;
4623 case AUTO_SEQ_CENLFE:
4624 spec->multiout.dac_nids[i] = 0xa;
4626 case AUTO_SEQ_SURROUND:
4627 spec->multiout.dac_nids[i] = 0x9;
4630 spec->multiout.dac_nids[i] = 0xb;
4639 /* add playback controls from the parsed DAC table */
4640 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4641 const struct auto_pin_cfg *cfg)
4644 static const char * const chname[4] = {
4645 "Front", "Surround", "C/LFE", "Side"
4647 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4648 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4649 hda_nid_t nid, nid_vol, nid_mute = 0;
4652 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4653 nid = cfg->line_out_pins[i];
4657 nid_vol = nid_vols[i];
4658 nid_mute = nid_mutes[i];
4660 if (i == AUTO_SEQ_CENLFE) {
4662 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4663 "Center Playback Volume",
4664 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4668 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4669 "LFE Playback Volume",
4670 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4674 err = via_add_control(
4675 spec, VIA_CTL_WIDGET_MUTE,
4676 "Center Playback Switch",
4677 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4681 err = via_add_control(
4682 spec, VIA_CTL_WIDGET_MUTE,
4683 "LFE Playback Switch",
4684 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4688 } else if (i == AUTO_SEQ_FRONT) {
4690 sprintf(name, "%s Playback Volume", chname[i]);
4691 err = via_add_control(
4692 spec, VIA_CTL_WIDGET_VOL, name,
4693 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4696 sprintf(name, "%s Playback Switch", chname[i]);
4697 err = via_add_control(
4698 spec, VIA_CTL_WIDGET_MUTE, name,
4699 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4704 sprintf(name, "%s Playback Volume", chname[i]);
4705 err = via_add_control(
4706 spec, VIA_CTL_WIDGET_VOL, name,
4707 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4710 sprintf(name, "%s Playback Switch", chname[i]);
4711 err = via_add_control(
4712 spec, VIA_CTL_WIDGET_MUTE, name,
4713 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4722 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4729 spec->multiout.hp_nid = 0xc; /* AOW4 */
4730 spec->hp_independent_mode_index = 1;
4732 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4733 "Headphone Playback Volume",
4734 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4738 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4739 "Headphone Playback Switch",
4740 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4744 create_hp_imux(spec);
4748 /* create playback/capture controls for input pins */
4749 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4750 const struct auto_pin_cfg *cfg)
4752 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4753 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4754 ARRAY_SIZE(pin_idxs));
4757 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4759 struct via_spec *spec = codec->spec;
4762 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4766 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4769 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4770 return 0; /* can't find valid BIOS pin config */
4772 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4775 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4778 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4782 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4784 fill_dig_outs(codec);
4786 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4787 spec->dig_in_nid = 0x13;
4789 if (spec->kctls.list)
4790 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4792 spec->input_mux = &spec->private_imux[0];
4795 via_hp_build(codec);
4797 via_smart51_build(spec);
4802 #ifdef CONFIG_SND_HDA_POWER_SAVE
4803 static struct hda_amp_list vt1718S_loopbacks[] = {
4804 { 0x21, HDA_INPUT, 1 },
4805 { 0x21, HDA_INPUT, 2 },
4806 { 0x21, HDA_INPUT, 3 },
4807 { 0x21, HDA_INPUT, 4 },
4812 static int patch_vt1718S(struct hda_codec *codec)
4814 struct via_spec *spec;
4817 /* create a codec specific record */
4818 spec = via_new_spec(codec);
4822 /* automatic parse from the BIOS config */
4823 err = vt1718S_parse_auto_config(codec);
4828 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4829 "from BIOS. Using genenic mode...\n");
4832 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4833 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4835 if (codec->vendor_id == 0x11060441)
4836 spec->stream_name_analog = "VT2020 Analog";
4837 else if (codec->vendor_id == 0x11064441)
4838 spec->stream_name_analog = "VT1828S Analog";
4840 spec->stream_name_analog = "VT1718S Analog";
4841 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4842 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4844 if (codec->vendor_id == 0x11060441)
4845 spec->stream_name_digital = "VT2020 Digital";
4846 else if (codec->vendor_id == 0x11064441)
4847 spec->stream_name_digital = "VT1828S Digital";
4849 spec->stream_name_digital = "VT1718S Digital";
4850 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4851 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4852 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4854 if (!spec->adc_nids && spec->input_mux) {
4855 spec->adc_nids = vt1718S_adc_nids;
4856 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4857 get_mux_nids(codec);
4858 override_mic_boost(codec, 0x2b, 0, 3, 40);
4859 override_mic_boost(codec, 0x29, 0, 3, 40);
4860 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4864 codec->patch_ops = via_patch_ops;
4866 codec->patch_ops.init = via_auto_init;
4867 codec->patch_ops.unsol_event = via_unsol_event;
4869 #ifdef CONFIG_SND_HDA_POWER_SAVE
4870 spec->loopback.amplist = vt1718S_loopbacks;
4876 /* Patch for VT1716S */
4878 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4879 struct snd_ctl_elem_info *uinfo)
4881 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4883 uinfo->value.integer.min = 0;
4884 uinfo->value.integer.max = 1;
4888 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4889 struct snd_ctl_elem_value *ucontrol)
4891 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4894 index = snd_hda_codec_read(codec, 0x26, 0,
4895 AC_VERB_GET_CONNECT_SEL, 0);
4897 *ucontrol->value.integer.value = index;
4902 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4903 struct snd_ctl_elem_value *ucontrol)
4905 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4906 struct via_spec *spec = codec->spec;
4907 int index = *ucontrol->value.integer.value;
4909 snd_hda_codec_write(codec, 0x26, 0,
4910 AC_VERB_SET_CONNECT_SEL, index);
4911 spec->dmic_enabled = index;
4912 set_jack_power_state(codec);
4917 /* capture mixer elements */
4918 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4919 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4920 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4921 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4922 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4923 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4924 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4927 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4928 .name = "Input Source",
4930 .info = via_mux_enum_info,
4931 .get = via_mux_enum_get,
4932 .put = via_mux_enum_put,
4937 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4938 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4940 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4941 .name = "Digital Mic Capture Switch",
4942 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4944 .info = vt1716s_dmic_info,
4945 .get = vt1716s_dmic_get,
4946 .put = vt1716s_dmic_put,
4952 /* mono-out mixer elements */
4953 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4954 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4958 static struct hda_verb vt1716S_volume_init_verbs[] = {
4960 * Unmute ADC0-1 and set the default input to mic-in
4962 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4963 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4966 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4969 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4970 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4971 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4972 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4973 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4974 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4976 /* MUX Indices: Stereo Mixer = 5 */
4977 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4979 /* Setup default input of PW4 to MW0 */
4980 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4982 /* Setup default input of SW1 as MW0 */
4983 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4985 /* Setup default input of SW4 as AOW0 */
4986 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4988 /* PW9 PW10 Output enable */
4989 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4990 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4992 /* Unmute SW1, PW12 */
4993 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4994 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4995 /* PW12 Output enable */
4996 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4997 /* Enable Boost Volume backdoor */
4999 /* don't bybass mixer */
5001 /* Enable mono output */
5007 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5008 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5009 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5010 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5011 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5012 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5013 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5014 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5015 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5016 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5020 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5024 .nid = 0x10, /* NID to query formats and rates */
5026 .open = via_playback_pcm_open,
5027 .prepare = via_playback_multi_pcm_prepare,
5028 .cleanup = via_playback_multi_pcm_cleanup,
5029 .close = via_pcm_open_close,
5033 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5037 .nid = 0x13, /* NID to query formats and rates */
5039 .open = via_pcm_open_close,
5040 .prepare = via_capture_pcm_prepare,
5041 .cleanup = via_capture_pcm_cleanup,
5042 .close = via_pcm_open_close,
5046 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5050 /* NID is set in via_build_pcms */
5052 .open = via_dig_playback_pcm_open,
5053 .close = via_dig_playback_pcm_close,
5054 .prepare = via_dig_playback_pcm_prepare,
5055 .cleanup = via_dig_playback_pcm_cleanup
5059 /* fill in the dac_nids table from the parsed pin configuration */
5060 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5061 const struct auto_pin_cfg *cfg)
5065 spec->multiout.num_dacs = cfg->line_outs;
5067 spec->multiout.dac_nids = spec->private_dac_nids;
5069 for (i = 0; i < 3; i++) {
5070 nid = cfg->line_out_pins[i];
5072 /* config dac list */
5074 case AUTO_SEQ_FRONT:
5075 spec->multiout.dac_nids[i] = 0x10;
5077 case AUTO_SEQ_CENLFE:
5078 spec->multiout.dac_nids[i] = 0x25;
5080 case AUTO_SEQ_SURROUND:
5081 spec->multiout.dac_nids[i] = 0x11;
5090 /* add playback controls from the parsed DAC table */
5091 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5092 const struct auto_pin_cfg *cfg)
5095 static const char * const chname[3] = {
5096 "Front", "Surround", "C/LFE"
5098 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5099 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5100 hda_nid_t nid, nid_vol, nid_mute;
5103 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5104 nid = cfg->line_out_pins[i];
5109 nid_vol = nid_vols[i];
5110 nid_mute = nid_mutes[i];
5112 if (i == AUTO_SEQ_CENLFE) {
5113 err = via_add_control(
5114 spec, VIA_CTL_WIDGET_VOL,
5115 "Center Playback Volume",
5116 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5119 err = via_add_control(
5120 spec, VIA_CTL_WIDGET_VOL,
5121 "LFE Playback Volume",
5122 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5125 err = via_add_control(
5126 spec, VIA_CTL_WIDGET_MUTE,
5127 "Center Playback Switch",
5128 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5132 err = via_add_control(
5133 spec, VIA_CTL_WIDGET_MUTE,
5134 "LFE Playback Switch",
5135 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5139 } else if (i == AUTO_SEQ_FRONT) {
5141 err = via_add_control(
5142 spec, VIA_CTL_WIDGET_VOL,
5143 "Master Front Playback Volume",
5144 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5147 err = via_add_control(
5148 spec, VIA_CTL_WIDGET_MUTE,
5149 "Master Front Playback Switch",
5150 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5154 sprintf(name, "%s Playback Volume", chname[i]);
5155 err = via_add_control(
5156 spec, VIA_CTL_WIDGET_VOL, name,
5157 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5160 sprintf(name, "%s Playback Switch", chname[i]);
5161 err = via_add_control(
5162 spec, VIA_CTL_WIDGET_MUTE, name,
5163 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5168 sprintf(name, "%s Playback Volume", chname[i]);
5169 err = via_add_control(
5170 spec, VIA_CTL_WIDGET_VOL, name,
5171 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5174 sprintf(name, "%s Playback Switch", chname[i]);
5175 err = via_add_control(
5176 spec, VIA_CTL_WIDGET_MUTE, name,
5177 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5186 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5193 spec->multiout.hp_nid = 0x25; /* AOW3 */
5194 spec->hp_independent_mode_index = 1;
5196 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5197 "Headphone Playback Volume",
5198 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5202 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5203 "Headphone Playback Switch",
5204 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5208 create_hp_imux(spec);
5212 /* create playback/capture controls for input pins */
5213 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5214 const struct auto_pin_cfg *cfg)
5216 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5217 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5218 ARRAY_SIZE(pin_idxs));
5221 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5223 struct via_spec *spec = codec->spec;
5226 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5229 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5232 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5233 return 0; /* can't find valid BIOS pin config */
5235 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5238 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5241 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5245 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5247 fill_dig_outs(codec);
5249 if (spec->kctls.list)
5250 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5252 spec->input_mux = &spec->private_imux[0];
5255 via_hp_build(codec);
5257 via_smart51_build(spec);
5262 #ifdef CONFIG_SND_HDA_POWER_SAVE
5263 static struct hda_amp_list vt1716S_loopbacks[] = {
5264 { 0x16, HDA_INPUT, 1 },
5265 { 0x16, HDA_INPUT, 2 },
5266 { 0x16, HDA_INPUT, 3 },
5267 { 0x16, HDA_INPUT, 4 },
5272 static int patch_vt1716S(struct hda_codec *codec)
5274 struct via_spec *spec;
5277 /* create a codec specific record */
5278 spec = via_new_spec(codec);
5282 /* automatic parse from the BIOS config */
5283 err = vt1716S_parse_auto_config(codec);
5288 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5289 "from BIOS. Using genenic mode...\n");
5292 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5293 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5295 spec->stream_name_analog = "VT1716S Analog";
5296 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5297 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5299 spec->stream_name_digital = "VT1716S Digital";
5300 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5302 if (!spec->adc_nids && spec->input_mux) {
5303 spec->adc_nids = vt1716S_adc_nids;
5304 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5305 get_mux_nids(codec);
5306 override_mic_boost(codec, 0x1a, 0, 3, 40);
5307 override_mic_boost(codec, 0x1e, 0, 3, 40);
5308 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5312 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5315 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5317 codec->patch_ops = via_patch_ops;
5319 codec->patch_ops.init = via_auto_init;
5320 codec->patch_ops.unsol_event = via_unsol_event;
5322 #ifdef CONFIG_SND_HDA_POWER_SAVE
5323 spec->loopback.amplist = vt1716S_loopbacks;
5331 /* capture mixer elements */
5332 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5333 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5334 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5335 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5336 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5337 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5338 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5341 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5342 /* The multiple "Capture Source" controls confuse alsamixer
5343 * So call somewhat different..
5345 /* .name = "Capture Source", */
5346 .name = "Input Source",
5348 .info = via_mux_enum_info,
5349 .get = via_mux_enum_get,
5350 .put = via_mux_enum_put,
5355 static struct hda_verb vt2002P_volume_init_verbs[] = {
5357 * Unmute ADC0-1 and set the default input to mic-in
5359 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5360 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5363 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5366 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5367 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5368 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5369 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5370 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5371 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5373 /* MUX Indices: Mic = 0 */
5374 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5375 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5377 /* PW9 Output enable */
5378 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5380 /* Enable Boost Volume backdoor */
5383 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5384 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5385 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5386 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5387 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5388 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5389 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5390 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5391 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5393 /* set MUX0/1/4/8 = 0 (AOW0) */
5394 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5395 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5396 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5397 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5399 /* set PW0 index=0 (MW0) */
5400 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5402 /* Enable AOW0 to MW9 */
5408 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5409 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5410 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5411 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5412 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5413 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5414 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5415 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5419 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5423 .nid = 0x8, /* NID to query formats and rates */
5425 .open = via_playback_pcm_open,
5426 .prepare = via_playback_multi_pcm_prepare,
5427 .cleanup = via_playback_multi_pcm_cleanup,
5428 .close = via_pcm_open_close,
5432 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5436 .nid = 0x10, /* NID to query formats and rates */
5438 .open = via_pcm_open_close,
5439 .prepare = via_capture_pcm_prepare,
5440 .cleanup = via_capture_pcm_cleanup,
5441 .close = via_pcm_open_close,
5445 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5449 /* NID is set in via_build_pcms */
5451 .open = via_dig_playback_pcm_open,
5452 .close = via_dig_playback_pcm_close,
5453 .prepare = via_dig_playback_pcm_prepare,
5454 .cleanup = via_dig_playback_pcm_cleanup
5458 /* fill in the dac_nids table from the parsed pin configuration */
5459 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5460 const struct auto_pin_cfg *cfg)
5462 spec->multiout.num_dacs = 1;
5463 spec->multiout.dac_nids = spec->private_dac_nids;
5464 if (cfg->line_out_pins[0])
5465 spec->multiout.dac_nids[0] = 0x8;
5469 /* add playback controls from the parsed DAC table */
5470 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5471 const struct auto_pin_cfg *cfg)
5475 if (!cfg->line_out_pins[0])
5479 /* Line-Out: PortE */
5480 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5481 "Master Front Playback Volume",
5482 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5485 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5486 "Master Front Playback Switch",
5487 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5494 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5501 spec->multiout.hp_nid = 0x9;
5502 spec->hp_independent_mode_index = 1;
5504 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5505 "Headphone Playback Volume",
5506 HDA_COMPOSE_AMP_VAL(
5507 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5511 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5512 "Headphone Playback Switch",
5513 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5517 create_hp_imux(spec);
5521 /* create playback/capture controls for input pins */
5522 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5523 const struct auto_pin_cfg *cfg)
5525 struct via_spec *spec = codec->spec;
5526 struct hda_input_mux *imux = &spec->private_imux[0];
5527 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5530 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5531 ARRAY_SIZE(pin_idxs));
5534 /* build volume/mute control of loopback */
5535 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5539 /* for digital mic select */
5540 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5545 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5547 struct via_spec *spec = codec->spec;
5551 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5555 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5559 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5560 return 0; /* can't find valid BIOS pin config */
5562 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5565 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5568 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5572 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5574 fill_dig_outs(codec);
5576 if (spec->kctls.list)
5577 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5579 spec->input_mux = &spec->private_imux[0];
5582 via_hp_build(codec);
5587 #ifdef CONFIG_SND_HDA_POWER_SAVE
5588 static struct hda_amp_list vt2002P_loopbacks[] = {
5589 { 0x21, HDA_INPUT, 0 },
5590 { 0x21, HDA_INPUT, 1 },
5591 { 0x21, HDA_INPUT, 2 },
5597 /* patch for vt2002P */
5598 static int patch_vt2002P(struct hda_codec *codec)
5600 struct via_spec *spec;
5603 /* create a codec specific record */
5604 spec = via_new_spec(codec);
5608 /* automatic parse from the BIOS config */
5609 err = vt2002P_parse_auto_config(codec);
5614 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5615 "from BIOS. Using genenic mode...\n");
5618 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5619 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5621 spec->stream_name_analog = "VT2002P Analog";
5622 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5623 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5625 spec->stream_name_digital = "VT2002P Digital";
5626 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5628 if (!spec->adc_nids && spec->input_mux) {
5629 spec->adc_nids = vt2002P_adc_nids;
5630 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5631 get_mux_nids(codec);
5632 override_mic_boost(codec, 0x2b, 0, 3, 40);
5633 override_mic_boost(codec, 0x29, 0, 3, 40);
5634 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5638 codec->patch_ops = via_patch_ops;
5640 codec->patch_ops.init = via_auto_init;
5641 codec->patch_ops.unsol_event = via_unsol_event;
5643 #ifdef CONFIG_SND_HDA_POWER_SAVE
5644 spec->loopback.amplist = vt2002P_loopbacks;
5652 /* capture mixer elements */
5653 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5654 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5655 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5656 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5657 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5658 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5659 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5663 /* The multiple "Capture Source" controls confuse alsamixer
5664 * So call somewhat different..
5666 .name = "Input Source",
5668 .info = via_mux_enum_info,
5669 .get = via_mux_enum_get,
5670 .put = via_mux_enum_put,
5675 static struct hda_verb vt1812_volume_init_verbs[] = {
5677 * Unmute ADC0-1 and set the default input to mic-in
5679 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5680 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5683 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5686 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5687 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5688 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5689 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5690 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5691 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5693 /* MUX Indices: Mic = 0 */
5694 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5695 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5697 /* PW9 Output enable */
5698 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5700 /* Enable Boost Volume backdoor */
5703 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5704 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5705 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5706 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5707 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5708 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5709 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5710 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5711 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5712 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5713 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5715 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5716 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5717 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5718 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5719 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5720 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5722 /* Enable AOW0 to MW9 */
5728 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5729 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5730 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5731 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5732 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5733 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5734 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5735 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5736 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5740 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5744 .nid = 0x8, /* NID to query formats and rates */
5746 .open = via_playback_pcm_open,
5747 .prepare = via_playback_multi_pcm_prepare,
5748 .cleanup = via_playback_multi_pcm_cleanup,
5749 .close = via_pcm_open_close,
5753 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5757 .nid = 0x10, /* NID to query formats and rates */
5759 .open = via_pcm_open_close,
5760 .prepare = via_capture_pcm_prepare,
5761 .cleanup = via_capture_pcm_cleanup,
5762 .close = via_pcm_open_close,
5766 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5770 /* NID is set in via_build_pcms */
5772 .open = via_dig_playback_pcm_open,
5773 .close = via_dig_playback_pcm_close,
5774 .prepare = via_dig_playback_pcm_prepare,
5775 .cleanup = via_dig_playback_pcm_cleanup
5778 /* fill in the dac_nids table from the parsed pin configuration */
5779 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5780 const struct auto_pin_cfg *cfg)
5782 spec->multiout.num_dacs = 1;
5783 spec->multiout.dac_nids = spec->private_dac_nids;
5784 if (cfg->line_out_pins[0])
5785 spec->multiout.dac_nids[0] = 0x8;
5790 /* add playback controls from the parsed DAC table */
5791 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5792 const struct auto_pin_cfg *cfg)
5796 if (!cfg->line_out_pins[0])
5799 /* Line-Out: PortE */
5800 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5801 "Front Playback Volume",
5802 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5805 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5806 "Front Playback Switch",
5807 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5814 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5821 spec->multiout.hp_nid = 0x9;
5822 spec->hp_independent_mode_index = 1;
5825 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5826 "Headphone Playback Volume",
5827 HDA_COMPOSE_AMP_VAL(
5828 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5832 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5833 "Headphone Playback Switch",
5834 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5838 create_hp_imux(spec);
5842 /* create playback/capture controls for input pins */
5843 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5844 const struct auto_pin_cfg *cfg)
5846 struct via_spec *spec = codec->spec;
5847 struct hda_input_mux *imux = &spec->private_imux[0];
5848 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5851 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5852 ARRAY_SIZE(pin_idxs));
5856 /* build volume/mute control of loopback */
5857 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5861 /* for digital mic select */
5862 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5867 static int vt1812_parse_auto_config(struct hda_codec *codec)
5869 struct via_spec *spec = codec->spec;
5873 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5876 fill_dig_outs(codec);
5877 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5881 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5882 return 0; /* can't find valid BIOS pin config */
5884 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5887 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5890 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
5894 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5896 fill_dig_outs(codec);
5898 if (spec->kctls.list)
5899 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5901 spec->input_mux = &spec->private_imux[0];
5904 via_hp_build(codec);
5909 #ifdef CONFIG_SND_HDA_POWER_SAVE
5910 static struct hda_amp_list vt1812_loopbacks[] = {
5911 { 0x21, HDA_INPUT, 0 },
5912 { 0x21, HDA_INPUT, 1 },
5913 { 0x21, HDA_INPUT, 2 },
5919 /* patch for vt1812 */
5920 static int patch_vt1812(struct hda_codec *codec)
5922 struct via_spec *spec;
5925 /* create a codec specific record */
5926 spec = via_new_spec(codec);
5930 /* automatic parse from the BIOS config */
5931 err = vt1812_parse_auto_config(codec);
5936 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5937 "from BIOS. Using genenic mode...\n");
5941 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
5942 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
5944 spec->stream_name_analog = "VT1812 Analog";
5945 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
5946 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
5948 spec->stream_name_digital = "VT1812 Digital";
5949 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
5952 if (!spec->adc_nids && spec->input_mux) {
5953 spec->adc_nids = vt1812_adc_nids;
5954 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
5955 get_mux_nids(codec);
5956 override_mic_boost(codec, 0x2b, 0, 3, 40);
5957 override_mic_boost(codec, 0x29, 0, 3, 40);
5958 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
5962 codec->patch_ops = via_patch_ops;
5964 codec->patch_ops.init = via_auto_init;
5965 codec->patch_ops.unsol_event = via_unsol_event;
5967 #ifdef CONFIG_SND_HDA_POWER_SAVE
5968 spec->loopback.amplist = vt1812_loopbacks;
5977 static struct hda_codec_preset snd_hda_preset_via[] = {
5978 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
5979 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
5980 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
5981 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
5982 { .id = 0x1106e710, .name = "VT1709 10-Ch",
5983 .patch = patch_vt1709_10ch},
5984 { .id = 0x1106e711, .name = "VT1709 10-Ch",
5985 .patch = patch_vt1709_10ch},
5986 { .id = 0x1106e712, .name = "VT1709 10-Ch",
5987 .patch = patch_vt1709_10ch},
5988 { .id = 0x1106e713, .name = "VT1709 10-Ch",
5989 .patch = patch_vt1709_10ch},
5990 { .id = 0x1106e714, .name = "VT1709 6-Ch",
5991 .patch = patch_vt1709_6ch},
5992 { .id = 0x1106e715, .name = "VT1709 6-Ch",
5993 .patch = patch_vt1709_6ch},
5994 { .id = 0x1106e716, .name = "VT1709 6-Ch",
5995 .patch = patch_vt1709_6ch},
5996 { .id = 0x1106e717, .name = "VT1709 6-Ch",
5997 .patch = patch_vt1709_6ch},
5998 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
5999 .patch = patch_vt1708B_8ch},
6000 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6001 .patch = patch_vt1708B_8ch},
6002 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6003 .patch = patch_vt1708B_8ch},
6004 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6005 .patch = patch_vt1708B_8ch},
6006 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6007 .patch = patch_vt1708B_4ch},
6008 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6009 .patch = patch_vt1708B_4ch},
6010 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6011 .patch = patch_vt1708B_4ch},
6012 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6013 .patch = patch_vt1708B_4ch},
6014 { .id = 0x11060397, .name = "VT1708S",
6015 .patch = patch_vt1708S},
6016 { .id = 0x11061397, .name = "VT1708S",
6017 .patch = patch_vt1708S},
6018 { .id = 0x11062397, .name = "VT1708S",
6019 .patch = patch_vt1708S},
6020 { .id = 0x11063397, .name = "VT1708S",
6021 .patch = patch_vt1708S},
6022 { .id = 0x11064397, .name = "VT1708S",
6023 .patch = patch_vt1708S},
6024 { .id = 0x11065397, .name = "VT1708S",
6025 .patch = patch_vt1708S},
6026 { .id = 0x11066397, .name = "VT1708S",
6027 .patch = patch_vt1708S},
6028 { .id = 0x11067397, .name = "VT1708S",
6029 .patch = patch_vt1708S},
6030 { .id = 0x11060398, .name = "VT1702",
6031 .patch = patch_vt1702},
6032 { .id = 0x11061398, .name = "VT1702",
6033 .patch = patch_vt1702},
6034 { .id = 0x11062398, .name = "VT1702",
6035 .patch = patch_vt1702},
6036 { .id = 0x11063398, .name = "VT1702",
6037 .patch = patch_vt1702},
6038 { .id = 0x11064398, .name = "VT1702",
6039 .patch = patch_vt1702},
6040 { .id = 0x11065398, .name = "VT1702",
6041 .patch = patch_vt1702},
6042 { .id = 0x11066398, .name = "VT1702",
6043 .patch = patch_vt1702},
6044 { .id = 0x11067398, .name = "VT1702",
6045 .patch = patch_vt1702},
6046 { .id = 0x11060428, .name = "VT1718S",
6047 .patch = patch_vt1718S},
6048 { .id = 0x11064428, .name = "VT1718S",
6049 .patch = patch_vt1718S},
6050 { .id = 0x11060441, .name = "VT2020",
6051 .patch = patch_vt1718S},
6052 { .id = 0x11064441, .name = "VT1828S",
6053 .patch = patch_vt1718S},
6054 { .id = 0x11060433, .name = "VT1716S",
6055 .patch = patch_vt1716S},
6056 { .id = 0x1106a721, .name = "VT1716S",
6057 .patch = patch_vt1716S},
6058 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6059 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6060 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6061 { .id = 0x11060440, .name = "VT1818S",
6062 .patch = patch_vt1708S},
6066 MODULE_ALIAS("snd-hda-codec-id:1106*");
6068 static struct hda_codec_preset_list via_list = {
6069 .preset = snd_hda_preset_via,
6070 .owner = THIS_MODULE,
6073 MODULE_LICENSE("GPL");
6074 MODULE_DESCRIPTION("VIA HD-audio codec");
6076 static int __init patch_via_init(void)
6078 return snd_hda_add_codec_preset(&via_list);
6081 static void __exit patch_via_exit(void)
6083 snd_hda_delete_codec_preset(&via_list);
6086 module_init(patch_via_init)
6087 module_exit(patch_via_exit)