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 enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
163 static struct via_spec * via_new_spec(struct hda_codec *codec)
165 struct via_spec *spec;
167 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
173 spec->codec_type = get_codec_type(codec);
174 /* VT1708BCE & VT1708S are almost same */
175 if (spec->codec_type == VT1708BCE)
176 spec->codec_type = VT1708S;
180 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
182 u32 vendor_id = codec->vendor_id;
183 u16 ven_id = vendor_id >> 16;
184 u16 dev_id = vendor_id & 0xffff;
185 enum VIA_HDA_CODEC codec_type;
188 if (ven_id != 0x1106)
189 codec_type = UNKNOWN;
190 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
192 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
193 codec_type = VT1709_10CH;
194 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
195 codec_type = VT1709_6CH;
196 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
197 codec_type = VT1708B_8CH;
198 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
199 codec_type = VT1708BCE;
200 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
201 codec_type = VT1708B_4CH;
202 else if ((dev_id & 0xfff) == 0x397
203 && (dev_id >> 12) < 8)
204 codec_type = VT1708S;
205 else if ((dev_id & 0xfff) == 0x398
206 && (dev_id >> 12) < 8)
208 else if ((dev_id & 0xfff) == 0x428
209 && (dev_id >> 12) < 8)
210 codec_type = VT1718S;
211 else if (dev_id == 0x0433 || dev_id == 0xa721)
212 codec_type = VT1716S;
213 else if (dev_id == 0x0441 || dev_id == 0x4441)
214 codec_type = VT1718S;
215 else if (dev_id == 0x0438 || dev_id == 0x4438)
216 codec_type = VT2002P;
217 else if (dev_id == 0x0448)
219 else if (dev_id == 0x0440)
220 codec_type = VT1708S;
222 codec_type = UNKNOWN;
226 #define VIA_HP_EVENT 0x01
227 #define VIA_GPIO_EVENT 0x02
228 #define VIA_JACK_EVENT 0x04
229 #define VIA_MONO_EVENT 0x08
230 #define VIA_SPEAKER_EVENT 0x10
231 #define VIA_BIND_HP_EVENT 0x20
236 VIA_CTL_WIDGET_ANALOG_MUTE,
237 VIA_CTL_WIDGET_BIND_PIN_MUTE,
247 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
248 static void set_jack_power_state(struct hda_codec *codec);
249 static int is_aa_path_mute(struct hda_codec *codec);
251 static void vt1708_start_hp_work(struct via_spec *spec)
253 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
255 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
256 !spec->vt1708_jack_detectect);
257 if (!delayed_work_pending(&spec->vt1708_hp_work))
258 schedule_delayed_work(&spec->vt1708_hp_work,
259 msecs_to_jiffies(100));
262 static void vt1708_stop_hp_work(struct via_spec *spec)
264 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
266 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
267 && !is_aa_path_mute(spec->codec))
269 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
270 !spec->vt1708_jack_detectect);
271 cancel_delayed_work_sync(&spec->vt1708_hp_work);
275 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
276 struct snd_ctl_elem_value *ucontrol)
278 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
279 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
281 set_jack_power_state(codec);
282 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
283 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
284 if (is_aa_path_mute(codec))
285 vt1708_start_hp_work(codec->spec);
287 vt1708_stop_hp_work(codec->spec);
292 /* modify .put = snd_hda_mixer_amp_switch_put */
293 #define ANALOG_INPUT_MUTE \
294 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
297 .info = snd_hda_mixer_amp_switch_info, \
298 .get = snd_hda_mixer_amp_switch_get, \
299 .put = analog_input_switch_put, \
300 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
302 static void via_hp_bind_automute(struct hda_codec *codec);
304 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
305 struct snd_ctl_elem_value *ucontrol)
307 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
308 struct via_spec *spec = codec->spec;
312 long *valp = ucontrol->value.integer.value;
314 if (strstr(kcontrol->id.name, "Switch") == NULL) {
315 snd_printd("Invalid control!\n");
318 change = snd_hda_mixer_amp_switch_put(kcontrol,
321 lmute = *valp ? 0 : HDA_AMP_MUTE;
323 rmute = *valp ? 0 : HDA_AMP_MUTE;
326 if (!spec->hp_independent_mode) {
327 for (i = 0; i < spec->autocfg.hp_outs; i++) {
328 snd_hda_codec_amp_update(
329 codec, spec->autocfg.hp_pins[i],
330 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
332 snd_hda_codec_amp_update(
333 codec, spec->autocfg.hp_pins[i],
334 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
339 if (!lmute && !rmute) {
341 for (i = 0; i < spec->autocfg.line_outs; i++)
342 snd_hda_codec_amp_stereo(
343 codec, spec->autocfg.line_out_pins[i],
344 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
346 for (i = 0; i < spec->autocfg.speaker_outs; i++)
347 snd_hda_codec_amp_stereo(
348 codec, spec->autocfg.speaker_pins[i],
349 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
351 via_hp_bind_automute(codec);
355 /* Mute all left channels */
356 for (i = 1; i < spec->autocfg.line_outs; i++)
357 snd_hda_codec_amp_update(
359 spec->autocfg.line_out_pins[i],
360 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
362 for (i = 0; i < spec->autocfg.speaker_outs; i++)
363 snd_hda_codec_amp_update(
365 spec->autocfg.speaker_pins[i],
366 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
370 /* mute all right channels */
371 for (i = 1; i < spec->autocfg.line_outs; i++)
372 snd_hda_codec_amp_update(
374 spec->autocfg.line_out_pins[i],
375 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
377 for (i = 0; i < spec->autocfg.speaker_outs; i++)
378 snd_hda_codec_amp_update(
380 spec->autocfg.speaker_pins[i],
381 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
388 #define BIND_PIN_MUTE \
389 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
392 .info = snd_hda_mixer_amp_switch_info, \
393 .get = snd_hda_mixer_amp_switch_get, \
394 .put = bind_pin_switch_put, \
395 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
397 static struct snd_kcontrol_new via_control_templates[] = {
398 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
399 HDA_CODEC_MUTE(NULL, 0, 0, 0),
404 static hda_nid_t vt1708_adc_nids[2] = {
409 static hda_nid_t vt1709_adc_nids[3] = {
414 static hda_nid_t vt1708B_adc_nids[2] = {
419 static hda_nid_t vt1708S_adc_nids[2] = {
424 static hda_nid_t vt1702_adc_nids[3] = {
429 static hda_nid_t vt1718S_adc_nids[2] = {
434 static hda_nid_t vt1716S_adc_nids[2] = {
439 static hda_nid_t vt2002P_adc_nids[2] = {
444 static hda_nid_t vt1812_adc_nids[2] = {
450 /* add dynamic controls */
451 static int __via_add_control(struct via_spec *spec, int type, const char *name,
452 int idx, unsigned long val)
454 struct snd_kcontrol_new *knew;
456 snd_array_init(&spec->kctls, sizeof(*knew), 32);
457 knew = snd_array_new(&spec->kctls);
460 *knew = via_control_templates[type];
461 knew->name = kstrdup(name, GFP_KERNEL);
464 if (get_amp_nid_(val))
465 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
466 knew->private_value = val;
470 #define via_add_control(spec, type, name, val) \
471 __via_add_control(spec, type, name, 0, val)
473 static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
474 struct snd_kcontrol_new *tmpl)
476 struct snd_kcontrol_new *knew;
478 snd_array_init(&spec->kctls, sizeof(*knew), 32);
479 knew = snd_array_new(&spec->kctls);
483 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
489 static void via_free_kctls(struct hda_codec *codec)
491 struct via_spec *spec = codec->spec;
493 if (spec->kctls.list) {
494 struct snd_kcontrol_new *kctl = spec->kctls.list;
496 for (i = 0; i < spec->kctls.used; i++)
499 snd_array_free(&spec->kctls);
502 /* create input playback/capture controls for the given pin */
503 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
504 int type_idx, int idx, int mix_nid)
509 sprintf(name, "%s Playback Volume", ctlname);
510 err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
511 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
514 sprintf(name, "%s Playback Switch", ctlname);
515 err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
516 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
522 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
523 hda_nid_t nid, int pin_type,
527 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
529 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
531 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
532 snd_hda_codec_write(codec, nid, 0,
533 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
537 static void via_auto_init_multi_out(struct hda_codec *codec)
539 struct via_spec *spec = codec->spec;
542 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
543 hda_nid_t nid = spec->autocfg.line_out_pins[i];
545 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
549 static void via_auto_init_hp_out(struct hda_codec *codec)
551 struct via_spec *spec = codec->spec;
555 for (i = 0; i < spec->autocfg.hp_outs; i++) {
556 pin = spec->autocfg.hp_pins[i];
557 if (pin) /* connect to front */
558 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
562 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
564 static void via_auto_init_analog_input(struct hda_codec *codec)
566 struct via_spec *spec = codec->spec;
567 const struct auto_pin_cfg *cfg = &spec->autocfg;
571 for (i = 0; i < cfg->num_inputs; i++) {
572 hda_nid_t nid = cfg->inputs[i].pin;
573 if (spec->smart51_enabled && is_smart51_pins(spec, nid))
575 else if (cfg->inputs[i].type == AUTO_PIN_MIC)
579 snd_hda_codec_write(codec, nid, 0,
580 AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
584 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
585 unsigned int *affected_parm)
588 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
589 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
590 >> AC_DEFCFG_MISC_SHIFT
591 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
592 unsigned present = snd_hda_jack_detect(codec, nid);
593 struct via_spec *spec = codec->spec;
594 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
595 || ((no_presence || present)
596 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
597 *affected_parm = AC_PWRST_D0; /* if it's connected */
602 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
605 static void set_jack_power_state(struct hda_codec *codec)
607 struct via_spec *spec = codec->spec;
611 if (spec->codec_type == VT1702) {
612 imux_is_smixer = snd_hda_codec_read(
613 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
615 /* PW 1/2/5 (14h/15h/18h) */
617 set_pin_power_state(codec, 0x14, &parm);
618 set_pin_power_state(codec, 0x15, &parm);
619 set_pin_power_state(codec, 0x18, &parm);
621 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
622 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
623 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
625 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
627 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
629 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
633 /* PW 3/4 (16h/17h) */
635 set_pin_power_state(codec, 0x16, &parm);
636 set_pin_power_state(codec, 0x17, &parm);
637 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
638 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
639 imux_is_smixer ? AC_PWRST_D0 : parm);
640 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
642 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
644 } else if (spec->codec_type == VT1708B_8CH
645 || spec->codec_type == VT1708B_4CH
646 || spec->codec_type == VT1708S) {
647 /* SW0 (17h) = stereo mixer */
648 int is_8ch = spec->codec_type != VT1708B_4CH;
649 imux_is_smixer = snd_hda_codec_read(
650 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
651 == ((spec->codec_type == VT1708S) ? 5 : 0);
653 /* PW 1/2/5 (1ah/1bh/1eh) */
655 set_pin_power_state(codec, 0x1a, &parm);
656 set_pin_power_state(codec, 0x1b, &parm);
657 set_pin_power_state(codec, 0x1e, &parm);
660 /* SW0 (17h), AIW 0/1 (13h/14h) */
661 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
663 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
665 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
669 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
671 set_pin_power_state(codec, 0x19, &parm);
672 if (spec->smart51_enabled)
674 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
676 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
679 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
682 set_pin_power_state(codec, 0x22, &parm);
683 if (spec->smart51_enabled)
685 snd_hda_codec_write(codec, 0x26, 0,
686 AC_VERB_SET_POWER_STATE, parm);
687 snd_hda_codec_write(codec, 0x24, 0,
688 AC_VERB_SET_POWER_STATE, parm);
691 /* PW 3/4/7 (1ch/1dh/23h) */
693 /* force to D0 for internal Speaker */
694 set_pin_power_state(codec, 0x1c, &parm);
695 set_pin_power_state(codec, 0x1d, &parm);
697 set_pin_power_state(codec, 0x23, &parm);
698 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
699 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
700 imux_is_smixer ? AC_PWRST_D0 : parm);
701 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
704 snd_hda_codec_write(codec, 0x25, 0,
705 AC_VERB_SET_POWER_STATE, parm);
706 snd_hda_codec_write(codec, 0x27, 0,
707 AC_VERB_SET_POWER_STATE, parm);
709 } else if (spec->codec_type == VT1718S) {
710 /* MUX6 (1eh) = stereo mixer */
711 imux_is_smixer = snd_hda_codec_read(
712 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
714 /* PW 5/6/7 (29h/2ah/2bh) */
716 set_pin_power_state(codec, 0x29, &parm);
717 set_pin_power_state(codec, 0x2a, &parm);
718 set_pin_power_state(codec, 0x2b, &parm);
721 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
722 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
724 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
726 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
728 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
732 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
734 set_pin_power_state(codec, 0x27, &parm);
735 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
737 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
740 /* PW2 (26h), AOW2 (ah) */
742 set_pin_power_state(codec, 0x26, &parm);
743 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
746 /* PW0/1 (24h/25h) */
748 set_pin_power_state(codec, 0x24, &parm);
749 set_pin_power_state(codec, 0x25, &parm);
750 if (!spec->hp_independent_mode) /* check for redirected HP */
751 set_pin_power_state(codec, 0x28, &parm);
752 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
754 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
756 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
757 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
758 imux_is_smixer ? AC_PWRST_D0 : parm);
759 if (spec->hp_independent_mode) {
760 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
762 set_pin_power_state(codec, 0x28, &parm);
763 snd_hda_codec_write(codec, 0x1b, 0,
764 AC_VERB_SET_POWER_STATE, parm);
765 snd_hda_codec_write(codec, 0x34, 0,
766 AC_VERB_SET_POWER_STATE, parm);
767 snd_hda_codec_write(codec, 0xc, 0,
768 AC_VERB_SET_POWER_STATE, parm);
770 } else if (spec->codec_type == VT1716S) {
771 unsigned int mono_out, present;
772 /* SW0 (17h) = stereo mixer */
773 imux_is_smixer = snd_hda_codec_read(
774 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
776 /* PW 1/2/5 (1ah/1bh/1eh) */
778 set_pin_power_state(codec, 0x1a, &parm);
779 set_pin_power_state(codec, 0x1b, &parm);
780 set_pin_power_state(codec, 0x1e, &parm);
783 /* SW0 (17h), AIW0(13h) */
784 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
786 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
790 set_pin_power_state(codec, 0x1e, &parm);
792 if (spec->dmic_enabled)
793 set_pin_power_state(codec, 0x22, &parm);
797 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
799 /* SW2(26h), AIW1(14h) */
800 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
802 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
806 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
808 set_pin_power_state(codec, 0x19, &parm);
809 /* Smart 5.1 PW2(1bh) */
810 if (spec->smart51_enabled)
811 set_pin_power_state(codec, 0x1b, &parm);
812 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
814 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
817 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
819 set_pin_power_state(codec, 0x23, &parm);
820 /* Smart 5.1 PW1(1ah) */
821 if (spec->smart51_enabled)
822 set_pin_power_state(codec, 0x1a, &parm);
823 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
826 /* Smart 5.1 PW5(1eh) */
827 if (spec->smart51_enabled)
828 set_pin_power_state(codec, 0x1e, &parm);
829 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
833 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
834 present = snd_hda_jack_detect(codec, 0x1c);
838 present = snd_hda_jack_detect(codec, 0x1d);
839 if (!spec->hp_independent_mode && present)
844 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
845 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
847 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
849 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
852 /* PW 3/4 (1ch/1dh) */
854 set_pin_power_state(codec, 0x1c, &parm);
855 set_pin_power_state(codec, 0x1d, &parm);
856 /* HP Independent Mode, power on AOW3 */
857 if (spec->hp_independent_mode)
858 snd_hda_codec_write(codec, 0x25, 0,
859 AC_VERB_SET_POWER_STATE, parm);
861 /* force to D0 for internal Speaker */
862 /* MW0 (16h), AOW0 (10h) */
863 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
864 imux_is_smixer ? AC_PWRST_D0 : parm);
865 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
866 mono_out ? AC_PWRST_D0 : parm);
867 } else if (spec->codec_type == VT2002P) {
868 unsigned int present;
869 /* MUX9 (1eh) = stereo mixer */
870 imux_is_smixer = snd_hda_codec_read(
871 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
873 /* PW 5/6/7 (29h/2ah/2bh) */
875 set_pin_power_state(codec, 0x29, &parm);
876 set_pin_power_state(codec, 0x2a, &parm);
877 set_pin_power_state(codec, 0x2b, &parm);
880 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
881 snd_hda_codec_write(codec, 0x1e, 0,
882 AC_VERB_SET_POWER_STATE, parm);
883 snd_hda_codec_write(codec, 0x1f, 0,
884 AC_VERB_SET_POWER_STATE, parm);
885 snd_hda_codec_write(codec, 0x10, 0,
886 AC_VERB_SET_POWER_STATE, parm);
887 snd_hda_codec_write(codec, 0x11, 0,
888 AC_VERB_SET_POWER_STATE, parm);
892 snd_hda_codec_write(codec, 0x8, 0,
893 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
895 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
897 set_pin_power_state(codec, 0x26, &parm);
898 snd_hda_codec_write(codec, 0x1c, 0,
899 AC_VERB_SET_POWER_STATE, parm);
900 snd_hda_codec_write(codec, 0x37,
901 0, AC_VERB_SET_POWER_STATE, parm);
903 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
905 set_pin_power_state(codec, 0x25, &parm);
906 snd_hda_codec_write(codec, 0x19, 0,
907 AC_VERB_SET_POWER_STATE, parm);
908 snd_hda_codec_write(codec, 0x35, 0,
909 AC_VERB_SET_POWER_STATE, parm);
910 if (spec->hp_independent_mode) {
911 snd_hda_codec_write(codec, 0x9, 0,
912 AC_VERB_SET_POWER_STATE, parm);
916 /* PW0 (24h), MW0(18h), MUX0(34h) */
917 present = snd_hda_jack_detect(codec, 0x25);
919 set_pin_power_state(codec, 0x24, &parm);
923 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
926 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
930 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
933 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
937 /* PW15 (31h), MW8(17h), MUX8(3bh) */
938 present = snd_hda_jack_detect(codec, 0x26);
940 set_pin_power_state(codec, 0x31, &parm);
944 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
947 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
951 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
954 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
958 if (imux_is_smixer || !is_aa_path_mute(codec))
961 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
965 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
966 } else if (spec->codec_type == VT1812) {
967 unsigned int present;
968 /* MUX10 (1eh) = stereo mixer */
969 imux_is_smixer = snd_hda_codec_read(
970 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
972 /* PW 5/6/7 (29h/2ah/2bh) */
974 set_pin_power_state(codec, 0x29, &parm);
975 set_pin_power_state(codec, 0x2a, &parm);
976 set_pin_power_state(codec, 0x2b, &parm);
979 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
980 snd_hda_codec_write(codec, 0x1e, 0,
981 AC_VERB_SET_POWER_STATE, parm);
982 snd_hda_codec_write(codec, 0x1f, 0,
983 AC_VERB_SET_POWER_STATE, parm);
984 snd_hda_codec_write(codec, 0x10, 0,
985 AC_VERB_SET_POWER_STATE, parm);
986 snd_hda_codec_write(codec, 0x11, 0,
987 AC_VERB_SET_POWER_STATE, parm);
991 snd_hda_codec_write(codec, 0x8, 0,
992 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
994 /* PW4 (28h), MW4 (18h), MUX4(38h) */
996 set_pin_power_state(codec, 0x28, &parm);
997 snd_hda_codec_write(codec, 0x18, 0,
998 AC_VERB_SET_POWER_STATE, parm);
999 snd_hda_codec_write(codec, 0x38, 0,
1000 AC_VERB_SET_POWER_STATE, parm);
1002 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1004 set_pin_power_state(codec, 0x25, &parm);
1005 snd_hda_codec_write(codec, 0x15, 0,
1006 AC_VERB_SET_POWER_STATE, parm);
1007 snd_hda_codec_write(codec, 0x35, 0,
1008 AC_VERB_SET_POWER_STATE, parm);
1009 if (spec->hp_independent_mode) {
1010 snd_hda_codec_write(codec, 0x9, 0,
1011 AC_VERB_SET_POWER_STATE, parm);
1014 /* Internal Speaker */
1015 /* PW0 (24h), MW0(14h), MUX0(34h) */
1016 present = snd_hda_jack_detect(codec, 0x25);
1018 set_pin_power_state(codec, 0x24, &parm);
1020 snd_hda_codec_write(codec, 0x14, 0,
1021 AC_VERB_SET_POWER_STATE,
1023 snd_hda_codec_write(codec, 0x34, 0,
1024 AC_VERB_SET_POWER_STATE,
1027 snd_hda_codec_write(codec, 0x14, 0,
1028 AC_VERB_SET_POWER_STATE,
1030 snd_hda_codec_write(codec, 0x34, 0,
1031 AC_VERB_SET_POWER_STATE,
1035 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1036 present = snd_hda_jack_detect(codec, 0x28);
1038 set_pin_power_state(codec, 0x31, &parm);
1040 snd_hda_codec_write(codec, 0x1c, 0,
1041 AC_VERB_SET_POWER_STATE,
1043 snd_hda_codec_write(codec, 0x3c, 0,
1044 AC_VERB_SET_POWER_STATE,
1046 snd_hda_codec_write(codec, 0x3e, 0,
1047 AC_VERB_SET_POWER_STATE,
1050 snd_hda_codec_write(codec, 0x1c, 0,
1051 AC_VERB_SET_POWER_STATE,
1053 snd_hda_codec_write(codec, 0x3c, 0,
1054 AC_VERB_SET_POWER_STATE,
1056 snd_hda_codec_write(codec, 0x3e, 0,
1057 AC_VERB_SET_POWER_STATE,
1061 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1063 set_pin_power_state(codec, 0x33, &parm);
1064 snd_hda_codec_write(codec, 0x1d, 0,
1065 AC_VERB_SET_POWER_STATE, parm);
1066 snd_hda_codec_write(codec, 0x3d, 0,
1067 AC_VERB_SET_POWER_STATE, parm);
1070 if (imux_is_smixer || !is_aa_path_mute(codec))
1071 snd_hda_codec_write(
1073 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1075 snd_hda_codec_write(
1077 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1082 * input MUX handling
1084 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1085 struct snd_ctl_elem_info *uinfo)
1087 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1088 struct via_spec *spec = codec->spec;
1089 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1092 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1093 struct snd_ctl_elem_value *ucontrol)
1095 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1096 struct via_spec *spec = codec->spec;
1097 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1099 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1103 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1104 struct snd_ctl_elem_value *ucontrol)
1106 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1107 struct via_spec *spec = codec->spec;
1108 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1111 if (!spec->mux_nids[adc_idx])
1113 /* switch to D0 beofre change index */
1114 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1115 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1116 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1117 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1119 ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1120 spec->mux_nids[adc_idx],
1121 &spec->cur_mux[adc_idx]);
1122 /* update jack power state */
1123 set_jack_power_state(codec);
1128 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1129 struct snd_ctl_elem_info *uinfo)
1131 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1132 struct via_spec *spec = codec->spec;
1133 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1136 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1137 struct snd_ctl_elem_value *ucontrol)
1139 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1140 hda_nid_t nid = kcontrol->private_value;
1141 unsigned int pinsel;
1143 /* use !! to translate conn sel 2 for VT1718S */
1144 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1145 AC_VERB_GET_CONNECT_SEL,
1147 ucontrol->value.enumerated.item[0] = pinsel;
1152 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1154 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1156 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1157 ctl->vd[0].access |= active
1158 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1159 snd_ctl_notify(codec->bus->card,
1160 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1164 static hda_nid_t side_mute_channel(struct via_spec *spec)
1166 switch (spec->codec_type) {
1167 case VT1708: return 0x1b;
1168 case VT1709_10CH: return 0x29;
1169 case VT1708B_8CH: /* fall thru */
1170 case VT1708S: return 0x27;
1175 static int update_side_mute_status(struct hda_codec *codec)
1177 /* mute side channel */
1178 struct via_spec *spec = codec->spec;
1179 unsigned int parm = spec->hp_independent_mode
1180 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1181 hda_nid_t sw3 = side_mute_channel(spec);
1184 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1189 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1190 struct snd_ctl_elem_value *ucontrol)
1192 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1193 struct via_spec *spec = codec->spec;
1194 hda_nid_t nid = kcontrol->private_value;
1195 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1196 /* Get Independent Mode index of headphone pin widget */
1197 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1199 if (spec->codec_type == VT1718S)
1200 snd_hda_codec_write(codec, nid, 0,
1201 AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0);
1203 snd_hda_codec_write(codec, nid, 0,
1204 AC_VERB_SET_CONNECT_SEL, pinsel);
1206 if (spec->codec_type == VT1812)
1207 snd_hda_codec_write(codec, 0x35, 0,
1208 AC_VERB_SET_CONNECT_SEL, pinsel);
1209 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1210 != spec->multiout.dac_nids[HDA_FRONT])
1211 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1214 update_side_mute_status(codec);
1215 /* update HP volume/swtich active state */
1216 if (spec->codec_type == VT1708S
1217 || spec->codec_type == VT1702
1218 || spec->codec_type == VT1718S
1219 || spec->codec_type == VT1716S
1220 || spec->codec_type == VT2002P
1221 || spec->codec_type == VT1812) {
1222 activate_ctl(codec, "Headphone Playback Volume",
1223 spec->hp_independent_mode);
1224 activate_ctl(codec, "Headphone Playback Switch",
1225 spec->hp_independent_mode);
1227 /* update jack power state */
1228 set_jack_power_state(codec);
1232 static struct snd_kcontrol_new via_hp_mixer[2] = {
1234 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1235 .name = "Independent HP",
1236 .info = via_independent_hp_info,
1237 .get = via_independent_hp_get,
1238 .put = via_independent_hp_put,
1241 .iface = NID_MAPPING,
1242 .name = "Independent HP",
1246 static int via_hp_build(struct hda_codec *codec)
1248 struct via_spec *spec = codec->spec;
1249 struct snd_kcontrol_new *knew;
1252 hda_nid_t conn[HDA_MAX_CONNECTIONS];
1254 switch (spec->codec_type) {
1265 nid = spec->autocfg.hp_pins[0];
1269 nums = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS);
1273 knew = via_clone_control(spec, &via_hp_mixer[0]);
1277 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1278 knew->private_value = nid;
1280 knew = via_clone_control(spec, &via_hp_mixer[1]);
1283 knew->subdevice = side_mute_channel(spec);
1288 static void notify_aa_path_ctls(struct hda_codec *codec)
1291 struct snd_ctl_elem_id id;
1292 const char *labels[] = {"Mic", "Front Mic", "Line"};
1294 memset(&id, 0, sizeof(id));
1295 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1296 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1297 sprintf(id.name, "%s Playback Volume", labels[i]);
1298 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1303 static void mute_aa_path(struct hda_codec *codec, int mute)
1305 struct via_spec *spec = codec->spec;
1306 hda_nid_t nid_mixer;
1310 /* get nid of MW0 and start & end index */
1311 switch (spec->codec_type) {
1339 /* check AA path's mute status */
1340 for (i = start_idx; i <= end_idx; i++) {
1341 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1342 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1346 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1348 const struct auto_pin_cfg *cfg = &spec->autocfg;
1351 for (i = 0; i < cfg->num_inputs; i++) {
1352 if (pin == cfg->inputs[i].pin)
1353 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
1358 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1359 struct snd_ctl_elem_info *uinfo)
1361 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1363 uinfo->value.integer.min = 0;
1364 uinfo->value.integer.max = 1;
1368 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1369 struct snd_ctl_elem_value *ucontrol)
1371 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1372 struct via_spec *spec = codec->spec;
1373 const struct auto_pin_cfg *cfg = &spec->autocfg;
1377 for (i = 0; i < cfg->num_inputs; i++) {
1378 hda_nid_t nid = cfg->inputs[i].pin;
1379 int ctl = snd_hda_codec_read(codec, nid, 0,
1380 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1381 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1383 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1384 spec->hp_independent_mode && spec->codec_type != VT1718S)
1385 continue; /* ignore FMic for independent HP */
1386 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
1389 *ucontrol->value.integer.value = on;
1393 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1394 struct snd_ctl_elem_value *ucontrol)
1396 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1397 struct via_spec *spec = codec->spec;
1398 const struct auto_pin_cfg *cfg = &spec->autocfg;
1399 int out_in = *ucontrol->value.integer.value
1400 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1403 for (i = 0; i < cfg->num_inputs; i++) {
1404 hda_nid_t nid = cfg->inputs[i].pin;
1407 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1409 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1410 spec->hp_independent_mode && spec->codec_type != VT1718S)
1411 continue; /* don't retask FMic for independent HP */
1413 parm = snd_hda_codec_read(codec, nid, 0,
1414 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1415 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1417 snd_hda_codec_write(codec, nid, 0,
1418 AC_VERB_SET_PIN_WIDGET_CONTROL,
1420 if (out_in == AC_PINCTL_OUT_EN) {
1421 mute_aa_path(codec, 1);
1422 notify_aa_path_ctls(codec);
1424 if (spec->codec_type == VT1718S) {
1425 snd_hda_codec_amp_stereo(
1426 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1429 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
1430 if (spec->codec_type == VT1708S
1431 || spec->codec_type == VT1716S) {
1432 /* input = index 1 (AOW3) */
1433 snd_hda_codec_write(
1435 AC_VERB_SET_CONNECT_SEL, 1);
1436 snd_hda_codec_amp_stereo(
1437 codec, nid, HDA_OUTPUT,
1438 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1442 spec->smart51_enabled = *ucontrol->value.integer.value;
1443 set_jack_power_state(codec);
1447 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1449 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1450 .name = "Smart 5.1",
1452 .info = via_smart51_info,
1453 .get = via_smart51_get,
1454 .put = via_smart51_put,
1457 .iface = NID_MAPPING,
1458 .name = "Smart 5.1",
1462 static int via_smart51_build(struct via_spec *spec)
1464 struct snd_kcontrol_new *knew;
1465 const struct auto_pin_cfg *cfg = &spec->autocfg;
1469 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1473 for (i = 0; i < cfg->num_inputs; i++) {
1474 nid = cfg->inputs[i].pin;
1475 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1476 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1479 knew->subdevice = nid;
1487 /* capture mixer elements */
1488 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1489 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1490 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1491 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1492 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1494 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1495 /* The multiple "Capture Source" controls confuse alsamixer
1496 * So call somewhat different..
1498 /* .name = "Capture Source", */
1499 .name = "Input Source",
1501 .info = via_mux_enum_info,
1502 .get = via_mux_enum_get,
1503 .put = via_mux_enum_put,
1508 /* check AA path's mute statue */
1509 static int is_aa_path_mute(struct hda_codec *codec)
1512 hda_nid_t nid_mixer;
1516 struct via_spec *spec = codec->spec;
1517 /* get nid of MW0 and start & end index */
1518 switch (spec->codec_type) {
1546 /* check AA path's mute status */
1547 for (i = start_idx; i <= end_idx; i++) {
1548 unsigned int con_list = snd_hda_codec_read(
1549 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1550 int shift = 8 * (i % 4);
1551 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1552 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1553 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1554 /* check mute status while the pin is connected */
1555 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1557 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1559 if (!mute_l || !mute_r) {
1568 /* enter/exit analog low-current mode */
1569 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1571 struct via_spec *spec = codec->spec;
1572 static int saved_stream_idle = 1; /* saved stream idle status */
1573 int enable = is_aa_path_mute(codec);
1574 unsigned int verb = 0;
1575 unsigned int parm = 0;
1577 if (stream_idle == -1) /* stream status did not change */
1578 enable = enable && saved_stream_idle;
1580 enable = enable && stream_idle;
1581 saved_stream_idle = stream_idle;
1584 /* decide low current mode's verb & parameter */
1585 switch (spec->codec_type) {
1589 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1595 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1599 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1604 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1607 return; /* other codecs are not supported */
1610 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1614 * generic initialization of ADC, input mixers and output mixers
1616 static struct hda_verb vt1708_volume_init_verbs[] = {
1618 * Unmute ADC0-1 and set the default input to mic-in
1620 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1621 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1624 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1627 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1628 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1629 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1630 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1631 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1632 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1635 * Set up output mixers (0x19 - 0x1b)
1637 /* set vol=0 to output mixers */
1638 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1639 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1640 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1642 /* Setup default input MW0 to PW4 */
1643 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1644 /* PW9 Output enable */
1645 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1649 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1650 struct hda_codec *codec,
1651 struct snd_pcm_substream *substream)
1653 struct via_spec *spec = codec->spec;
1654 int idle = substream->pstr->substream_opened == 1
1655 && substream->ref_count == 0;
1656 analog_low_current_mode(codec, idle);
1657 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1661 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1662 unsigned int stream_tag,
1663 unsigned int format,
1664 struct snd_pcm_substream *substream)
1666 struct via_spec *spec = codec->spec;
1667 struct hda_multi_out *mout = &spec->multiout;
1668 hda_nid_t *nids = mout->dac_nids;
1669 int chs = substream->runtime->channels;
1672 mutex_lock(&codec->spdif_mutex);
1673 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1675 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1677 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1678 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1679 /* turn off SPDIF once; otherwise the IEC958 bits won't
1681 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1682 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1683 AC_VERB_SET_DIGI_CONVERT_1,
1685 ~AC_DIG1_ENABLE & 0xff);
1686 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1687 stream_tag, 0, format);
1688 /* turn on again (if needed) */
1689 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1690 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1691 AC_VERB_SET_DIGI_CONVERT_1,
1692 codec->spdif_ctls & 0xff);
1694 mout->dig_out_used = 0;
1695 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1699 mutex_unlock(&codec->spdif_mutex);
1702 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1705 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1706 && !spec->hp_independent_mode)
1707 /* headphone out will just decode front left/right (stereo) */
1708 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1711 /* extra outputs copied from front */
1712 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1713 if (mout->extra_out_nid[i])
1714 snd_hda_codec_setup_stream(codec,
1715 mout->extra_out_nid[i],
1716 stream_tag, 0, format);
1719 for (i = 1; i < mout->num_dacs; i++) {
1720 if (chs >= (i + 1) * 2) /* independent out */
1721 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1723 else /* copy front */
1724 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1729 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1730 struct hda_codec *codec,
1731 unsigned int stream_tag,
1732 unsigned int format,
1733 struct snd_pcm_substream *substream)
1735 struct via_spec *spec = codec->spec;
1736 struct hda_multi_out *mout = &spec->multiout;
1737 hda_nid_t *nids = mout->dac_nids;
1739 if (substream->number == 0)
1740 playback_multi_pcm_prep_0(codec, stream_tag, format,
1743 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1744 spec->hp_independent_mode)
1745 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1746 stream_tag, 0, format);
1748 vt1708_start_hp_work(spec);
1752 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1753 struct hda_codec *codec,
1754 struct snd_pcm_substream *substream)
1756 struct via_spec *spec = codec->spec;
1757 struct hda_multi_out *mout = &spec->multiout;
1758 hda_nid_t *nids = mout->dac_nids;
1761 if (substream->number == 0) {
1762 for (i = 0; i < mout->num_dacs; i++)
1763 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1765 if (mout->hp_nid && !spec->hp_independent_mode)
1766 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1769 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1770 if (mout->extra_out_nid[i])
1771 snd_hda_codec_setup_stream(codec,
1772 mout->extra_out_nid[i],
1774 mutex_lock(&codec->spdif_mutex);
1775 if (mout->dig_out_nid &&
1776 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1777 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1779 mout->dig_out_used = 0;
1781 mutex_unlock(&codec->spdif_mutex);
1783 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1784 spec->hp_independent_mode)
1785 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1788 vt1708_stop_hp_work(spec);
1795 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1796 struct hda_codec *codec,
1797 struct snd_pcm_substream *substream)
1799 struct via_spec *spec = codec->spec;
1800 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1803 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1804 struct hda_codec *codec,
1805 struct snd_pcm_substream *substream)
1807 struct via_spec *spec = codec->spec;
1808 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1811 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1812 struct hda_codec *codec,
1813 unsigned int stream_tag,
1814 unsigned int format,
1815 struct snd_pcm_substream *substream)
1817 struct via_spec *spec = codec->spec;
1818 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1819 stream_tag, format, substream);
1822 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1823 struct hda_codec *codec,
1824 struct snd_pcm_substream *substream)
1826 struct via_spec *spec = codec->spec;
1827 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1834 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1835 struct hda_codec *codec,
1836 unsigned int stream_tag,
1837 unsigned int format,
1838 struct snd_pcm_substream *substream)
1840 struct via_spec *spec = codec->spec;
1842 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1843 stream_tag, 0, format);
1847 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1848 struct hda_codec *codec,
1849 struct snd_pcm_substream *substream)
1851 struct via_spec *spec = codec->spec;
1852 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1856 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1860 .nid = 0x10, /* NID to query formats and rates */
1862 .open = via_playback_pcm_open,
1863 .prepare = via_playback_multi_pcm_prepare,
1864 .cleanup = via_playback_multi_pcm_cleanup
1868 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1872 .nid = 0x10, /* NID to query formats and rates */
1873 /* We got noisy outputs on the right channel on VT1708 when
1874 * 24bit samples are used. Until any workaround is found,
1875 * disable the 24bit format, so far.
1877 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1879 .open = via_playback_pcm_open,
1880 .prepare = via_playback_multi_pcm_prepare,
1881 .cleanup = via_playback_multi_pcm_cleanup
1885 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1889 .nid = 0x15, /* NID to query formats and rates */
1891 .prepare = via_capture_pcm_prepare,
1892 .cleanup = via_capture_pcm_cleanup
1896 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1900 /* NID is set in via_build_pcms */
1902 .open = via_dig_playback_pcm_open,
1903 .close = via_dig_playback_pcm_close,
1904 .prepare = via_dig_playback_pcm_prepare,
1905 .cleanup = via_dig_playback_pcm_cleanup
1909 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1915 static int via_build_controls(struct hda_codec *codec)
1917 struct via_spec *spec = codec->spec;
1918 struct snd_kcontrol *kctl;
1919 struct snd_kcontrol_new *knew;
1922 for (i = 0; i < spec->num_mixers; i++) {
1923 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1928 if (spec->multiout.dig_out_nid) {
1929 err = snd_hda_create_spdif_out_ctls(codec,
1930 spec->multiout.dig_out_nid);
1933 err = snd_hda_create_spdif_share_sw(codec,
1937 spec->multiout.share_spdif = 1;
1939 if (spec->dig_in_nid) {
1940 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1945 /* assign Capture Source enums to NID */
1946 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1947 for (i = 0; kctl && i < kctl->count; i++) {
1948 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1953 /* other nid->control mapping */
1954 for (i = 0; i < spec->num_mixers; i++) {
1955 for (knew = spec->mixers[i]; knew->name; knew++) {
1956 if (knew->iface != NID_MAPPING)
1958 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1961 err = snd_hda_add_nid(codec, kctl, 0,
1966 /* init power states */
1967 set_jack_power_state(codec);
1968 analog_low_current_mode(codec, 1);
1970 via_free_kctls(codec); /* no longer needed */
1974 static int via_build_pcms(struct hda_codec *codec)
1976 struct via_spec *spec = codec->spec;
1977 struct hda_pcm *info = spec->pcm_rec;
1979 codec->num_pcms = 1;
1980 codec->pcm_info = info;
1982 info->name = spec->stream_name_analog;
1983 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1984 *(spec->stream_analog_playback);
1985 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1986 spec->multiout.dac_nids[0];
1987 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1988 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1990 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1991 spec->multiout.max_channels;
1993 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1996 info->name = spec->stream_name_digital;
1997 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1998 if (spec->multiout.dig_out_nid) {
1999 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2000 *(spec->stream_digital_playback);
2001 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2002 spec->multiout.dig_out_nid;
2004 if (spec->dig_in_nid) {
2005 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2006 *(spec->stream_digital_capture);
2007 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2015 static void via_free(struct hda_codec *codec)
2017 struct via_spec *spec = codec->spec;
2022 via_free_kctls(codec);
2023 vt1708_stop_hp_work(spec);
2027 /* mute internal speaker if HP is plugged */
2028 static void via_hp_automute(struct hda_codec *codec)
2030 unsigned int present = 0;
2031 struct via_spec *spec = codec->spec;
2033 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2035 if (!spec->hp_independent_mode) {
2036 struct snd_ctl_elem_id id;
2038 snd_hda_codec_amp_stereo(
2039 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2040 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2042 memset(&id, 0, sizeof(id));
2043 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2044 strcpy(id.name, "Front Playback Switch");
2045 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2050 /* mute mono out if HP or Line out is plugged */
2051 static void via_mono_automute(struct hda_codec *codec)
2053 unsigned int hp_present, lineout_present;
2054 struct via_spec *spec = codec->spec;
2056 if (spec->codec_type != VT1716S)
2059 lineout_present = snd_hda_jack_detect(codec,
2060 spec->autocfg.line_out_pins[0]);
2062 /* Mute Mono Out if Line Out is plugged */
2063 if (lineout_present) {
2064 snd_hda_codec_amp_stereo(
2065 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2069 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2071 if (!spec->hp_independent_mode)
2072 snd_hda_codec_amp_stereo(
2073 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2074 hp_present ? HDA_AMP_MUTE : 0);
2077 static void via_gpio_control(struct hda_codec *codec)
2079 unsigned int gpio_data;
2080 unsigned int vol_counter;
2082 unsigned int master_vol;
2084 struct via_spec *spec = codec->spec;
2086 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2087 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2089 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2090 0xF84, 0) & 0x3F0000) >> 16;
2092 vol = vol_counter & 0x1F;
2093 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2094 AC_VERB_GET_AMP_GAIN_MUTE,
2097 if (gpio_data == 0x02) {
2098 /* unmute line out */
2099 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2100 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2102 if (vol_counter & 0x20) {
2103 /* decrease volume */
2104 if (vol > master_vol)
2106 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2110 /* increase volume */
2111 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2113 ((master_vol+vol) > 0x2A) ? 0x2A :
2116 } else if (!(gpio_data & 0x02)) {
2118 snd_hda_codec_amp_stereo(codec,
2119 spec->autocfg.line_out_pins[0],
2120 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2125 /* mute Internal-Speaker if HP is plugged */
2126 static void via_speaker_automute(struct hda_codec *codec)
2128 unsigned int hp_present;
2129 struct via_spec *spec = codec->spec;
2131 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2134 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2136 if (!spec->hp_independent_mode) {
2137 struct snd_ctl_elem_id id;
2138 snd_hda_codec_amp_stereo(
2139 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2140 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2142 memset(&id, 0, sizeof(id));
2143 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2144 strcpy(id.name, "Speaker Playback Switch");
2145 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2150 /* mute line-out and internal speaker if HP is plugged */
2151 static void via_hp_bind_automute(struct hda_codec *codec)
2153 /* use long instead of int below just to avoid an internal compiler
2154 * error with gcc 4.0.x
2156 unsigned long hp_present, present = 0;
2157 struct via_spec *spec = codec->spec;
2160 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2163 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2165 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2167 if (!spec->hp_independent_mode) {
2168 /* Mute Line-Outs */
2169 for (i = 0; i < spec->autocfg.line_outs; i++)
2170 snd_hda_codec_amp_stereo(
2171 codec, spec->autocfg.line_out_pins[i],
2173 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2175 present = hp_present;
2178 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2179 snd_hda_codec_amp_stereo(
2180 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2181 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2185 /* unsolicited event for jack sensing */
2186 static void via_unsol_event(struct hda_codec *codec,
2190 if (res & VIA_HP_EVENT)
2191 via_hp_automute(codec);
2192 if (res & VIA_GPIO_EVENT)
2193 via_gpio_control(codec);
2194 if (res & VIA_JACK_EVENT)
2195 set_jack_power_state(codec);
2196 if (res & VIA_MONO_EVENT)
2197 via_mono_automute(codec);
2198 if (res & VIA_SPEAKER_EVENT)
2199 via_speaker_automute(codec);
2200 if (res & VIA_BIND_HP_EVENT)
2201 via_hp_bind_automute(codec);
2204 static int via_init(struct hda_codec *codec)
2206 struct via_spec *spec = codec->spec;
2208 for (i = 0; i < spec->num_iverbs; i++)
2209 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2211 /* Lydia Add for EAPD enable */
2212 if (!spec->dig_in_nid) { /* No Digital In connection */
2213 if (spec->dig_in_pin) {
2214 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2215 AC_VERB_SET_PIN_WIDGET_CONTROL,
2217 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2218 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2220 } else /* enable SPDIF-input pin */
2221 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2222 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2224 /* assign slave outs */
2225 if (spec->slave_dig_outs[0])
2226 codec->slave_dig_outs = spec->slave_dig_outs;
2231 #ifdef SND_HDA_NEEDS_RESUME
2232 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2234 struct via_spec *spec = codec->spec;
2235 vt1708_stop_hp_work(spec);
2240 #ifdef CONFIG_SND_HDA_POWER_SAVE
2241 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2243 struct via_spec *spec = codec->spec;
2244 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2250 static struct hda_codec_ops via_patch_ops = {
2251 .build_controls = via_build_controls,
2252 .build_pcms = via_build_pcms,
2255 #ifdef SND_HDA_NEEDS_RESUME
2256 .suspend = via_suspend,
2258 #ifdef CONFIG_SND_HDA_POWER_SAVE
2259 .check_power_status = via_check_power_status,
2263 /* fill in the dac_nids table from the parsed pin configuration */
2264 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2265 const struct auto_pin_cfg *cfg)
2270 spec->multiout.num_dacs = cfg->line_outs;
2272 spec->multiout.dac_nids = spec->private_dac_nids;
2274 for (i = 0; i < 4; i++) {
2275 nid = cfg->line_out_pins[i];
2277 /* config dac list */
2279 case AUTO_SEQ_FRONT:
2280 spec->multiout.dac_nids[i] = 0x10;
2282 case AUTO_SEQ_CENLFE:
2283 spec->multiout.dac_nids[i] = 0x12;
2285 case AUTO_SEQ_SURROUND:
2286 spec->multiout.dac_nids[i] = 0x11;
2289 spec->multiout.dac_nids[i] = 0x13;
2298 /* add playback controls from the parsed DAC table */
2299 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2300 const struct auto_pin_cfg *cfg)
2303 static const char * const chname[4] = {
2304 "Front", "Surround", "C/LFE", "Side"
2306 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2309 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2310 nid = cfg->line_out_pins[i];
2315 nid_vol = nid_vols[i];
2317 if (i == AUTO_SEQ_CENLFE) {
2319 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2320 "Center Playback Volume",
2321 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2325 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2326 "LFE Playback Volume",
2327 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2331 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2332 "Center Playback Switch",
2333 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2337 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2338 "LFE Playback Switch",
2339 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2343 } else if (i == AUTO_SEQ_FRONT) {
2344 /* add control to mixer index 0 */
2345 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2346 "Master Front Playback Volume",
2347 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2351 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2352 "Master Front Playback Switch",
2353 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2358 /* add control to PW3 */
2359 sprintf(name, "%s Playback Volume", chname[i]);
2360 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2361 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2365 sprintf(name, "%s Playback Switch", chname[i]);
2366 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2367 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2372 sprintf(name, "%s Playback Volume", chname[i]);
2373 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2374 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2378 sprintf(name, "%s Playback Switch", chname[i]);
2379 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2380 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2390 static void create_hp_imux(struct via_spec *spec)
2393 struct hda_input_mux *imux = &spec->private_imux[1];
2394 static const char * const texts[] = { "OFF", "ON", NULL};
2396 /* for hp mode select */
2397 for (i = 0; texts[i]; i++)
2398 snd_hda_add_imux_item(imux, texts[i], i, NULL);
2400 spec->hp_mux = &spec->private_imux[1];
2403 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2410 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2411 spec->hp_independent_mode_index = 1;
2413 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2414 "Headphone Playback Volume",
2415 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2418 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2419 "Headphone Playback Switch",
2420 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2424 create_hp_imux(spec);
2429 /* create playback/capture controls for input pins */
2430 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2431 const struct auto_pin_cfg *cfg,
2433 hda_nid_t pin_idxs[], int num_idxs)
2435 struct via_spec *spec = codec->spec;
2436 struct hda_input_mux *imux = &spec->private_imux[0];
2437 int i, err, idx, type, type_idx = 0;
2439 /* for internal loopback recording select */
2440 for (idx = 0; idx < num_idxs; idx++) {
2441 if (pin_idxs[idx] == 0xff) {
2442 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2447 for (i = 0; i < cfg->num_inputs; i++) {
2449 type = cfg->inputs[i].type;
2450 for (idx = 0; idx < num_idxs; idx++)
2451 if (pin_idxs[idx] == cfg->inputs[i].pin)
2453 if (idx >= num_idxs)
2455 if (i > 0 && type == cfg->inputs[i - 1].type)
2459 label = hda_get_autocfg_input_label(codec, cfg, i);
2460 if (spec->codec_type == VT1708S ||
2461 spec->codec_type == VT1702 ||
2462 spec->codec_type == VT1716S)
2463 err = via_new_analog_input(spec, label, type_idx,
2466 err = via_new_analog_input(spec, label, type_idx,
2470 snd_hda_add_imux_item(imux, label, idx, NULL);
2475 /* create playback/capture controls for input pins */
2476 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2477 const struct auto_pin_cfg *cfg)
2479 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2480 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2481 ARRAY_SIZE(pin_idxs));
2484 #ifdef CONFIG_SND_HDA_POWER_SAVE
2485 static struct hda_amp_list vt1708_loopbacks[] = {
2486 { 0x17, HDA_INPUT, 1 },
2487 { 0x17, HDA_INPUT, 2 },
2488 { 0x17, HDA_INPUT, 3 },
2489 { 0x17, HDA_INPUT, 4 },
2494 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2496 unsigned int def_conf;
2497 unsigned char seqassoc;
2499 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2500 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2501 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2502 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2503 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2504 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2505 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2511 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2512 struct snd_ctl_elem_value *ucontrol)
2514 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2515 struct via_spec *spec = codec->spec;
2517 if (spec->codec_type != VT1708)
2519 spec->vt1708_jack_detectect =
2520 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2521 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2525 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2526 struct snd_ctl_elem_value *ucontrol)
2528 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2529 struct via_spec *spec = codec->spec;
2532 if (spec->codec_type != VT1708)
2534 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2535 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2536 == !spec->vt1708_jack_detectect;
2537 if (spec->vt1708_jack_detectect) {
2538 mute_aa_path(codec, 1);
2539 notify_aa_path_ctls(codec);
2544 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2546 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2547 .name = "Jack Detect",
2549 .info = snd_ctl_boolean_mono_info,
2550 .get = vt1708_jack_detectect_get,
2551 .put = vt1708_jack_detectect_put,
2556 static int vt1708_parse_auto_config(struct hda_codec *codec)
2558 struct via_spec *spec = codec->spec;
2561 /* Add HP and CD pin config connect bit re-config action */
2562 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2563 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2565 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2568 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2571 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2572 return 0; /* can't find valid BIOS pin config */
2574 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2577 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2580 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2583 /* add jack detect on/off control */
2584 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2588 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2590 if (spec->autocfg.dig_outs)
2591 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2592 spec->dig_in_pin = VT1708_DIGIN_PIN;
2593 if (spec->autocfg.dig_in_pin)
2594 spec->dig_in_nid = VT1708_DIGIN_NID;
2596 if (spec->kctls.list)
2597 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2599 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2601 spec->input_mux = &spec->private_imux[0];
2604 via_hp_build(codec);
2606 via_smart51_build(spec);
2610 /* init callback for auto-configuration model -- overriding the default init */
2611 static int via_auto_init(struct hda_codec *codec)
2613 struct via_spec *spec = codec->spec;
2616 via_auto_init_multi_out(codec);
2617 via_auto_init_hp_out(codec);
2618 via_auto_init_analog_input(codec);
2619 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2620 via_hp_bind_automute(codec);
2622 via_hp_automute(codec);
2623 via_speaker_automute(codec);
2629 static void vt1708_update_hp_jack_state(struct work_struct *work)
2631 struct via_spec *spec = container_of(work, struct via_spec,
2632 vt1708_hp_work.work);
2633 if (spec->codec_type != VT1708)
2635 /* if jack state toggled */
2636 if (spec->vt1708_hp_present
2637 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2638 spec->vt1708_hp_present ^= 1;
2639 via_hp_automute(spec->codec);
2641 vt1708_start_hp_work(spec);
2644 static int get_mux_nids(struct hda_codec *codec)
2646 struct via_spec *spec = codec->spec;
2647 hda_nid_t nid, conn[8];
2651 for (i = 0; i < spec->num_adc_nids; i++) {
2652 nid = spec->adc_nids[i];
2654 type = get_wcaps_type(get_wcaps(codec, nid));
2655 if (type == AC_WID_PIN)
2657 n = snd_hda_get_connections(codec, nid, conn,
2662 spec->mux_nids[i] = nid;
2671 static int patch_vt1708(struct hda_codec *codec)
2673 struct via_spec *spec;
2676 /* create a codec specific record */
2677 spec = via_new_spec(codec);
2681 /* automatic parse from the BIOS config */
2682 err = vt1708_parse_auto_config(codec);
2687 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2688 "from BIOS. Using genenic mode...\n");
2692 spec->stream_name_analog = "VT1708 Analog";
2693 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2694 /* disable 32bit format on VT1708 */
2695 if (codec->vendor_id == 0x11061708)
2696 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2697 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2699 spec->stream_name_digital = "VT1708 Digital";
2700 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2701 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2704 if (!spec->adc_nids && spec->input_mux) {
2705 spec->adc_nids = vt1708_adc_nids;
2706 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2707 get_mux_nids(codec);
2708 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2712 codec->patch_ops = via_patch_ops;
2714 codec->patch_ops.init = via_auto_init;
2715 #ifdef CONFIG_SND_HDA_POWER_SAVE
2716 spec->loopback.amplist = vt1708_loopbacks;
2718 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2722 /* capture mixer elements */
2723 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2724 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2725 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2726 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2727 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2728 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2729 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2732 /* The multiple "Capture Source" controls confuse alsamixer
2733 * So call somewhat different..
2735 /* .name = "Capture Source", */
2736 .name = "Input Source",
2738 .info = via_mux_enum_info,
2739 .get = via_mux_enum_get,
2740 .put = via_mux_enum_put,
2745 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2746 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2747 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2752 * generic initialization of ADC, input mixers and output mixers
2754 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2756 * Unmute ADC0-2 and set the default input to mic-in
2758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2759 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2760 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2763 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2766 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2767 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2768 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2769 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2770 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2771 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2774 * Set up output selector (0x1a, 0x1b, 0x29)
2776 /* set vol=0 to output mixers */
2777 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2778 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2779 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2782 * Unmute PW3 and PW4
2784 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2785 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2787 /* Set input of PW4 as MW0 */
2788 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2789 /* PW9 Output enable */
2790 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2794 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2798 .nid = 0x10, /* NID to query formats and rates */
2800 .open = via_playback_pcm_open,
2801 .prepare = via_playback_multi_pcm_prepare,
2802 .cleanup = via_playback_multi_pcm_cleanup,
2806 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2810 .nid = 0x10, /* NID to query formats and rates */
2812 .open = via_playback_pcm_open,
2813 .prepare = via_playback_multi_pcm_prepare,
2814 .cleanup = via_playback_multi_pcm_cleanup,
2818 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2822 .nid = 0x14, /* NID to query formats and rates */
2824 .prepare = via_capture_pcm_prepare,
2825 .cleanup = via_capture_pcm_cleanup
2829 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2833 /* NID is set in via_build_pcms */
2835 .open = via_dig_playback_pcm_open,
2836 .close = via_dig_playback_pcm_close
2840 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2846 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2847 const struct auto_pin_cfg *cfg)
2852 if (cfg->line_outs == 4) /* 10 channels */
2853 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2854 else if (cfg->line_outs == 3) /* 6 channels */
2855 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2857 spec->multiout.dac_nids = spec->private_dac_nids;
2859 if (cfg->line_outs == 4) { /* 10 channels */
2860 for (i = 0; i < cfg->line_outs; i++) {
2861 nid = cfg->line_out_pins[i];
2863 /* config dac list */
2865 case AUTO_SEQ_FRONT:
2867 spec->multiout.dac_nids[i] = 0x10;
2869 case AUTO_SEQ_CENLFE:
2871 spec->multiout.dac_nids[i] = 0x12;
2873 case AUTO_SEQ_SURROUND:
2875 spec->multiout.dac_nids[i] = 0x11;
2879 spec->multiout.dac_nids[i] = 0x27;
2886 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2888 } else if (cfg->line_outs == 3) { /* 6 channels */
2889 for (i = 0; i < cfg->line_outs; i++) {
2890 nid = cfg->line_out_pins[i];
2892 /* config dac list */
2894 case AUTO_SEQ_FRONT:
2896 spec->multiout.dac_nids[i] = 0x10;
2898 case AUTO_SEQ_CENLFE:
2900 spec->multiout.dac_nids[i] = 0x12;
2902 case AUTO_SEQ_SURROUND:
2904 spec->multiout.dac_nids[i] = 0x11;
2916 /* add playback controls from the parsed DAC table */
2917 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2918 const struct auto_pin_cfg *cfg)
2921 static const char * const chname[4] = {
2922 "Front", "Surround", "C/LFE", "Side"
2924 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2927 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2928 nid = cfg->line_out_pins[i];
2933 nid_vol = nid_vols[i];
2935 if (i == AUTO_SEQ_CENLFE) {
2937 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2938 "Center Playback Volume",
2939 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2943 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2944 "LFE Playback Volume",
2945 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2949 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2950 "Center Playback Switch",
2951 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2955 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2956 "LFE Playback Switch",
2957 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2961 } else if (i == AUTO_SEQ_FRONT) {
2962 /* ADD control to mixer index 0 */
2963 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2964 "Master Front Playback Volume",
2965 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2969 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2970 "Master Front Playback Switch",
2971 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2976 /* add control to PW3 */
2977 sprintf(name, "%s Playback Volume", chname[i]);
2978 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2979 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2983 sprintf(name, "%s Playback Switch", chname[i]);
2984 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2985 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2989 } else if (i == AUTO_SEQ_SURROUND) {
2990 sprintf(name, "%s Playback Volume", chname[i]);
2991 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2992 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2996 sprintf(name, "%s Playback Switch", chname[i]);
2997 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2998 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3002 } else if (i == AUTO_SEQ_SIDE) {
3003 sprintf(name, "%s Playback Volume", chname[i]);
3004 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3005 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3009 sprintf(name, "%s Playback Switch", chname[i]);
3010 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3011 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3021 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3028 if (spec->multiout.num_dacs == 5) /* 10 channels */
3029 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
3030 else if (spec->multiout.num_dacs == 3) /* 6 channels */
3031 spec->multiout.hp_nid = 0;
3032 spec->hp_independent_mode_index = 1;
3034 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3035 "Headphone Playback Volume",
3036 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3039 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3040 "Headphone Playback Switch",
3041 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3048 /* create playback/capture controls for input pins */
3049 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
3050 const struct auto_pin_cfg *cfg)
3052 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
3053 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
3054 ARRAY_SIZE(pin_idxs));
3057 static int vt1709_parse_auto_config(struct hda_codec *codec)
3059 struct via_spec *spec = codec->spec;
3062 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3065 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3068 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3069 return 0; /* can't find valid BIOS pin config */
3071 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3074 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3077 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
3081 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3083 if (spec->autocfg.dig_outs)
3084 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3085 spec->dig_in_pin = VT1709_DIGIN_PIN;
3086 if (spec->autocfg.dig_in_pin)
3087 spec->dig_in_nid = VT1709_DIGIN_NID;
3089 if (spec->kctls.list)
3090 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3092 spec->input_mux = &spec->private_imux[0];
3095 via_hp_build(codec);
3097 via_smart51_build(spec);
3101 #ifdef CONFIG_SND_HDA_POWER_SAVE
3102 static struct hda_amp_list vt1709_loopbacks[] = {
3103 { 0x18, HDA_INPUT, 1 },
3104 { 0x18, HDA_INPUT, 2 },
3105 { 0x18, HDA_INPUT, 3 },
3106 { 0x18, HDA_INPUT, 4 },
3111 static int patch_vt1709_10ch(struct hda_codec *codec)
3113 struct via_spec *spec;
3116 /* create a codec specific record */
3117 spec = via_new_spec(codec);
3121 err = vt1709_parse_auto_config(codec);
3126 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3127 "Using genenic mode...\n");
3130 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3131 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3133 spec->stream_name_analog = "VT1709 Analog";
3134 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3135 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3137 spec->stream_name_digital = "VT1709 Digital";
3138 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3139 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3142 if (!spec->adc_nids && spec->input_mux) {
3143 spec->adc_nids = vt1709_adc_nids;
3144 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3145 get_mux_nids(codec);
3146 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3150 codec->patch_ops = via_patch_ops;
3152 codec->patch_ops.init = via_auto_init;
3153 codec->patch_ops.unsol_event = via_unsol_event;
3154 #ifdef CONFIG_SND_HDA_POWER_SAVE
3155 spec->loopback.amplist = vt1709_loopbacks;
3161 * generic initialization of ADC, input mixers and output mixers
3163 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3165 * Unmute ADC0-2 and set the default input to mic-in
3167 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3168 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3169 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3172 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3175 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3176 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3177 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3178 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3179 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3180 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3183 * Set up output selector (0x1a, 0x1b, 0x29)
3185 /* set vol=0 to output mixers */
3186 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3187 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3188 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3191 * Unmute PW3 and PW4
3193 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3194 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3196 /* Set input of PW4 as MW0 */
3197 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3198 /* PW9 Output enable */
3199 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3203 static int patch_vt1709_6ch(struct hda_codec *codec)
3205 struct via_spec *spec;
3208 /* create a codec specific record */
3209 spec = via_new_spec(codec);
3213 err = vt1709_parse_auto_config(codec);
3218 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3219 "Using genenic mode...\n");
3222 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3223 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3225 spec->stream_name_analog = "VT1709 Analog";
3226 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3227 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3229 spec->stream_name_digital = "VT1709 Digital";
3230 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3231 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3234 if (!spec->adc_nids && spec->input_mux) {
3235 spec->adc_nids = vt1709_adc_nids;
3236 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3237 get_mux_nids(codec);
3238 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3242 codec->patch_ops = via_patch_ops;
3244 codec->patch_ops.init = via_auto_init;
3245 codec->patch_ops.unsol_event = via_unsol_event;
3246 #ifdef CONFIG_SND_HDA_POWER_SAVE
3247 spec->loopback.amplist = vt1709_loopbacks;
3252 /* capture mixer elements */
3253 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3254 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3255 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3256 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3257 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3259 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3260 /* The multiple "Capture Source" controls confuse alsamixer
3261 * So call somewhat different..
3263 /* .name = "Capture Source", */
3264 .name = "Input Source",
3266 .info = via_mux_enum_info,
3267 .get = via_mux_enum_get,
3268 .put = via_mux_enum_put,
3273 * generic initialization of ADC, input mixers and output mixers
3275 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3277 * Unmute ADC0-1 and set the default input to mic-in
3279 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3280 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3283 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3286 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3287 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3288 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3289 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3290 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3291 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3294 * Set up output mixers
3296 /* set vol=0 to output mixers */
3297 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3298 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3299 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3301 /* Setup default input to PW4 */
3302 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3303 /* PW9 Output enable */
3304 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3305 /* PW10 Input enable */
3306 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3310 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3312 * Unmute ADC0-1 and set the default input to mic-in
3314 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3315 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3318 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3321 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3322 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3323 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3324 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3325 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3326 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3329 * Set up output mixers
3331 /* set vol=0 to output mixers */
3332 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3333 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3334 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3336 /* Setup default input of PW4 to MW0 */
3337 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3338 /* PW9 Output enable */
3339 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3340 /* PW10 Input enable */
3341 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3345 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3346 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3347 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3348 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3349 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3350 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3351 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3352 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3353 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3354 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3358 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3359 struct hda_codec *codec,
3360 struct snd_pcm_substream *substream)
3362 int idle = substream->pstr->substream_opened == 1
3363 && substream->ref_count == 0;
3365 analog_low_current_mode(codec, idle);
3369 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3373 .nid = 0x10, /* NID to query formats and rates */
3375 .open = via_playback_pcm_open,
3376 .prepare = via_playback_multi_pcm_prepare,
3377 .cleanup = via_playback_multi_pcm_cleanup,
3378 .close = via_pcm_open_close
3382 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3386 .nid = 0x10, /* NID to query formats and rates */
3388 .open = via_playback_pcm_open,
3389 .prepare = via_playback_multi_pcm_prepare,
3390 .cleanup = via_playback_multi_pcm_cleanup
3394 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3398 .nid = 0x13, /* NID to query formats and rates */
3400 .open = via_pcm_open_close,
3401 .prepare = via_capture_pcm_prepare,
3402 .cleanup = via_capture_pcm_cleanup,
3403 .close = via_pcm_open_close
3407 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3411 /* NID is set in via_build_pcms */
3413 .open = via_dig_playback_pcm_open,
3414 .close = via_dig_playback_pcm_close,
3415 .prepare = via_dig_playback_pcm_prepare,
3416 .cleanup = via_dig_playback_pcm_cleanup
3420 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3426 /* fill in the dac_nids table from the parsed pin configuration */
3427 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3428 const struct auto_pin_cfg *cfg)
3433 spec->multiout.num_dacs = cfg->line_outs;
3435 spec->multiout.dac_nids = spec->private_dac_nids;
3437 for (i = 0; i < 4; i++) {
3438 nid = cfg->line_out_pins[i];
3440 /* config dac list */
3442 case AUTO_SEQ_FRONT:
3443 spec->multiout.dac_nids[i] = 0x10;
3445 case AUTO_SEQ_CENLFE:
3446 spec->multiout.dac_nids[i] = 0x24;
3448 case AUTO_SEQ_SURROUND:
3449 spec->multiout.dac_nids[i] = 0x11;
3452 spec->multiout.dac_nids[i] = 0x25;
3461 /* add playback controls from the parsed DAC table */
3462 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3463 const struct auto_pin_cfg *cfg)
3466 static const char * const chname[4] = {
3467 "Front", "Surround", "C/LFE", "Side"
3469 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3470 hda_nid_t nid, nid_vol = 0;
3473 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3474 nid = cfg->line_out_pins[i];
3479 nid_vol = nid_vols[i];
3481 if (i == AUTO_SEQ_CENLFE) {
3483 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3484 "Center Playback Volume",
3485 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3489 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3490 "LFE Playback Volume",
3491 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3495 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3496 "Center Playback Switch",
3497 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3501 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3502 "LFE Playback Switch",
3503 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3507 } else if (i == AUTO_SEQ_FRONT) {
3508 /* add control to mixer index 0 */
3509 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3510 "Master Front Playback Volume",
3511 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3515 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3516 "Master Front Playback Switch",
3517 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3522 /* add control to PW3 */
3523 sprintf(name, "%s Playback Volume", chname[i]);
3524 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3525 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3529 sprintf(name, "%s Playback Switch", chname[i]);
3530 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3531 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3536 sprintf(name, "%s Playback Volume", chname[i]);
3537 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3538 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3542 sprintf(name, "%s Playback Switch", chname[i]);
3543 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3544 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3554 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3561 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3562 spec->hp_independent_mode_index = 1;
3564 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3565 "Headphone Playback Volume",
3566 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3569 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3570 "Headphone Playback Switch",
3571 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3575 create_hp_imux(spec);
3580 /* create playback/capture controls for input pins */
3581 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3582 const struct auto_pin_cfg *cfg)
3584 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3585 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3586 ARRAY_SIZE(pin_idxs));
3589 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3591 struct via_spec *spec = codec->spec;
3594 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3597 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3600 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3601 return 0; /* can't find valid BIOS pin config */
3603 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3606 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3609 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3613 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3615 if (spec->autocfg.dig_outs)
3616 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3617 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3618 if (spec->autocfg.dig_in_pin)
3619 spec->dig_in_nid = VT1708B_DIGIN_NID;
3621 if (spec->kctls.list)
3622 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3624 spec->input_mux = &spec->private_imux[0];
3627 via_hp_build(codec);
3629 via_smart51_build(spec);
3633 #ifdef CONFIG_SND_HDA_POWER_SAVE
3634 static struct hda_amp_list vt1708B_loopbacks[] = {
3635 { 0x16, HDA_INPUT, 1 },
3636 { 0x16, HDA_INPUT, 2 },
3637 { 0x16, HDA_INPUT, 3 },
3638 { 0x16, HDA_INPUT, 4 },
3642 static int patch_vt1708S(struct hda_codec *codec);
3643 static int patch_vt1708B_8ch(struct hda_codec *codec)
3645 struct via_spec *spec;
3648 if (get_codec_type(codec) == VT1708BCE)
3649 return patch_vt1708S(codec);
3650 /* create a codec specific record */
3651 spec = via_new_spec(codec);
3655 /* automatic parse from the BIOS config */
3656 err = vt1708B_parse_auto_config(codec);
3661 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3662 "from BIOS. Using genenic mode...\n");
3665 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3666 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3668 spec->stream_name_analog = "VT1708B Analog";
3669 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3670 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3672 spec->stream_name_digital = "VT1708B Digital";
3673 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3674 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3676 if (!spec->adc_nids && spec->input_mux) {
3677 spec->adc_nids = vt1708B_adc_nids;
3678 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3679 get_mux_nids(codec);
3680 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3684 codec->patch_ops = via_patch_ops;
3686 codec->patch_ops.init = via_auto_init;
3687 codec->patch_ops.unsol_event = via_unsol_event;
3688 #ifdef CONFIG_SND_HDA_POWER_SAVE
3689 spec->loopback.amplist = vt1708B_loopbacks;
3695 static int patch_vt1708B_4ch(struct hda_codec *codec)
3697 struct via_spec *spec;
3700 /* create a codec specific record */
3701 spec = via_new_spec(codec);
3705 /* automatic parse from the BIOS config */
3706 err = vt1708B_parse_auto_config(codec);
3711 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3712 "from BIOS. Using genenic mode...\n");
3715 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3716 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3718 spec->stream_name_analog = "VT1708B Analog";
3719 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3720 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3722 spec->stream_name_digital = "VT1708B Digital";
3723 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3724 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3726 if (!spec->adc_nids && spec->input_mux) {
3727 spec->adc_nids = vt1708B_adc_nids;
3728 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3729 get_mux_nids(codec);
3730 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3734 codec->patch_ops = via_patch_ops;
3736 codec->patch_ops.init = via_auto_init;
3737 codec->patch_ops.unsol_event = via_unsol_event;
3738 #ifdef CONFIG_SND_HDA_POWER_SAVE
3739 spec->loopback.amplist = vt1708B_loopbacks;
3745 /* Patch for VT1708S */
3747 /* capture mixer elements */
3748 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3749 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3750 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3751 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3752 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3753 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3754 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3757 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3758 /* The multiple "Capture Source" controls confuse alsamixer
3759 * So call somewhat different..
3761 /* .name = "Capture Source", */
3762 .name = "Input Source",
3764 .info = via_mux_enum_info,
3765 .get = via_mux_enum_get,
3766 .put = via_mux_enum_put,
3771 static struct hda_verb vt1708S_volume_init_verbs[] = {
3772 /* Unmute ADC0-1 and set the default input to mic-in */
3773 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3774 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3776 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3777 * analog-loopback mixer widget */
3778 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3779 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3780 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3781 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3782 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3783 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3785 /* Setup default input of PW4 to MW0 */
3786 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3787 /* PW9, PW10 Output enable */
3788 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3789 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3790 /* Enable Mic Boost Volume backdoor */
3792 /* don't bybass mixer */
3797 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3798 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3799 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3800 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3801 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3802 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3803 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3804 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3805 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3806 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3810 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3814 .nid = 0x10, /* NID to query formats and rates */
3816 .open = via_playback_pcm_open,
3817 .prepare = via_playback_multi_pcm_prepare,
3818 .cleanup = via_playback_multi_pcm_cleanup,
3819 .close = via_pcm_open_close
3823 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3827 .nid = 0x13, /* NID to query formats and rates */
3829 .open = via_pcm_open_close,
3830 .prepare = via_capture_pcm_prepare,
3831 .cleanup = via_capture_pcm_cleanup,
3832 .close = via_pcm_open_close
3836 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3840 /* NID is set in via_build_pcms */
3842 .open = via_dig_playback_pcm_open,
3843 .close = via_dig_playback_pcm_close,
3844 .prepare = via_dig_playback_pcm_prepare,
3845 .cleanup = via_dig_playback_pcm_cleanup
3849 /* fill in the dac_nids table from the parsed pin configuration */
3850 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3851 const struct auto_pin_cfg *cfg)
3856 spec->multiout.num_dacs = cfg->line_outs;
3858 spec->multiout.dac_nids = spec->private_dac_nids;
3860 for (i = 0; i < 4; i++) {
3861 nid = cfg->line_out_pins[i];
3863 /* config dac list */
3865 case AUTO_SEQ_FRONT:
3866 spec->multiout.dac_nids[i] = 0x10;
3868 case AUTO_SEQ_CENLFE:
3869 spec->multiout.dac_nids[i] = 0x24;
3871 case AUTO_SEQ_SURROUND:
3872 spec->multiout.dac_nids[i] = 0x11;
3875 spec->multiout.dac_nids[i] = 0x25;
3881 /* for Smart 5.1, line/mic inputs double as output pins */
3882 if (cfg->line_outs == 1) {
3883 spec->multiout.num_dacs = 3;
3884 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3885 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3891 /* add playback controls from the parsed DAC table */
3892 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3893 const struct auto_pin_cfg *cfg)
3896 static const char * const chname[4] = {
3897 "Front", "Surround", "C/LFE", "Side"
3899 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3900 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3901 hda_nid_t nid, nid_vol, nid_mute;
3904 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3905 nid = cfg->line_out_pins[i];
3907 /* for Smart 5.1, there are always at least six channels */
3908 if (!nid && i > AUTO_SEQ_CENLFE)
3911 nid_vol = nid_vols[i];
3912 nid_mute = nid_mutes[i];
3914 if (i == AUTO_SEQ_CENLFE) {
3916 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3917 "Center Playback Volume",
3918 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3922 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3923 "LFE Playback Volume",
3924 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3928 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3929 "Center Playback Switch",
3930 HDA_COMPOSE_AMP_VAL(nid_mute,
3935 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3936 "LFE Playback Switch",
3937 HDA_COMPOSE_AMP_VAL(nid_mute,
3942 } else if (i == AUTO_SEQ_FRONT) {
3943 /* add control to mixer index 0 */
3944 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3945 "Master Front Playback Volume",
3946 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3950 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3951 "Master Front Playback Switch",
3952 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3958 sprintf(name, "%s Playback Volume", chname[i]);
3959 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3960 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3964 sprintf(name, "%s Playback Switch", chname[i]);
3965 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3966 HDA_COMPOSE_AMP_VAL(nid_mute,
3972 sprintf(name, "%s Playback Volume", chname[i]);
3973 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3974 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3978 sprintf(name, "%s Playback Switch", chname[i]);
3979 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3980 HDA_COMPOSE_AMP_VAL(nid_mute,
3991 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3998 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3999 spec->hp_independent_mode_index = 1;
4001 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4002 "Headphone Playback Volume",
4003 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
4007 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4008 "Headphone Playback Switch",
4009 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4013 create_hp_imux(spec);
4018 /* create playback/capture controls for input pins */
4019 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
4020 const struct auto_pin_cfg *cfg)
4022 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
4023 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
4024 ARRAY_SIZE(pin_idxs));
4027 /* fill out digital output widgets; one for master and one for slave outputs */
4028 static void fill_dig_outs(struct hda_codec *codec)
4030 struct via_spec *spec = codec->spec;
4033 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4037 nid = spec->autocfg.dig_out_pins[i];
4040 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4043 if (!spec->multiout.dig_out_nid)
4044 spec->multiout.dig_out_nid = nid;
4046 spec->slave_dig_outs[0] = nid;
4047 break; /* at most two dig outs */
4052 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4054 struct via_spec *spec = codec->spec;
4057 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4060 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4063 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4064 return 0; /* can't find valid BIOS pin config */
4066 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4069 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4072 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4076 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4078 fill_dig_outs(codec);
4080 if (spec->kctls.list)
4081 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4083 spec->input_mux = &spec->private_imux[0];
4086 via_hp_build(codec);
4088 via_smart51_build(spec);
4092 #ifdef CONFIG_SND_HDA_POWER_SAVE
4093 static struct hda_amp_list vt1708S_loopbacks[] = {
4094 { 0x16, HDA_INPUT, 1 },
4095 { 0x16, HDA_INPUT, 2 },
4096 { 0x16, HDA_INPUT, 3 },
4097 { 0x16, HDA_INPUT, 4 },
4102 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4103 int offset, int num_steps, int step_size)
4105 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4106 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4107 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4108 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4109 (0 << AC_AMPCAP_MUTE_SHIFT));
4112 static int patch_vt1708S(struct hda_codec *codec)
4114 struct via_spec *spec;
4117 /* create a codec specific record */
4118 spec = via_new_spec(codec);
4122 /* automatic parse from the BIOS config */
4123 err = vt1708S_parse_auto_config(codec);
4128 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4129 "from BIOS. Using genenic mode...\n");
4132 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4133 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4135 if (codec->vendor_id == 0x11060440)
4136 spec->stream_name_analog = "VT1818S Analog";
4138 spec->stream_name_analog = "VT1708S Analog";
4139 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4140 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4142 if (codec->vendor_id == 0x11060440)
4143 spec->stream_name_digital = "VT1818S Digital";
4145 spec->stream_name_digital = "VT1708S Digital";
4146 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4148 if (!spec->adc_nids && spec->input_mux) {
4149 spec->adc_nids = vt1708S_adc_nids;
4150 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4151 get_mux_nids(codec);
4152 override_mic_boost(codec, 0x1a, 0, 3, 40);
4153 override_mic_boost(codec, 0x1e, 0, 3, 40);
4154 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4158 codec->patch_ops = via_patch_ops;
4160 codec->patch_ops.init = via_auto_init;
4161 codec->patch_ops.unsol_event = via_unsol_event;
4162 #ifdef CONFIG_SND_HDA_POWER_SAVE
4163 spec->loopback.amplist = vt1708S_loopbacks;
4166 /* correct names for VT1708BCE */
4167 if (get_codec_type(codec) == VT1708BCE) {
4168 kfree(codec->chip_name);
4169 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4170 snprintf(codec->bus->card->mixername,
4171 sizeof(codec->bus->card->mixername),
4172 "%s %s", codec->vendor_name, codec->chip_name);
4173 spec->stream_name_analog = "VT1708BCE Analog";
4174 spec->stream_name_digital = "VT1708BCE Digital";
4179 /* Patch for VT1702 */
4181 /* capture mixer elements */
4182 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4183 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4184 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4185 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4186 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4187 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4188 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4189 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4192 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4193 /* The multiple "Capture Source" controls confuse alsamixer
4194 * So call somewhat different..
4196 /* .name = "Capture Source", */
4197 .name = "Input Source",
4199 .info = via_mux_enum_info,
4200 .get = via_mux_enum_get,
4201 .put = via_mux_enum_put,
4206 static struct hda_verb vt1702_volume_init_verbs[] = {
4208 * Unmute ADC0-1 and set the default input to mic-in
4210 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4211 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4212 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4215 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4218 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4219 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4220 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4221 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4222 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4223 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4225 /* Setup default input of PW4 to MW0 */
4226 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4227 /* PW6 PW7 Output enable */
4228 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4229 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4237 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4238 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4239 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4240 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4241 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4242 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4243 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4247 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4251 .nid = 0x10, /* NID to query formats and rates */
4253 .open = via_playback_pcm_open,
4254 .prepare = via_playback_multi_pcm_prepare,
4255 .cleanup = via_playback_multi_pcm_cleanup,
4256 .close = via_pcm_open_close
4260 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4264 .nid = 0x12, /* NID to query formats and rates */
4266 .open = via_pcm_open_close,
4267 .prepare = via_capture_pcm_prepare,
4268 .cleanup = via_capture_pcm_cleanup,
4269 .close = via_pcm_open_close
4273 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4277 /* NID is set in via_build_pcms */
4279 .open = via_dig_playback_pcm_open,
4280 .close = via_dig_playback_pcm_close,
4281 .prepare = via_dig_playback_pcm_prepare,
4282 .cleanup = via_dig_playback_pcm_cleanup
4286 /* fill in the dac_nids table from the parsed pin configuration */
4287 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4288 const struct auto_pin_cfg *cfg)
4290 spec->multiout.num_dacs = 1;
4291 spec->multiout.dac_nids = spec->private_dac_nids;
4293 if (cfg->line_out_pins[0]) {
4294 /* config dac list */
4295 spec->multiout.dac_nids[0] = 0x10;
4301 /* add playback controls from the parsed DAC table */
4302 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4303 const struct auto_pin_cfg *cfg)
4307 if (!cfg->line_out_pins[0])
4310 /* add control to mixer index 0 */
4311 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4312 "Master Front Playback Volume",
4313 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4316 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4317 "Master Front Playback Switch",
4318 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4323 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4324 "Front Playback Volume",
4325 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4328 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4329 "Front Playback Switch",
4330 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4337 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4340 struct hda_input_mux *imux;
4341 static const char * const texts[] = { "ON", "OFF", NULL};
4344 spec->multiout.hp_nid = 0x1D;
4345 spec->hp_independent_mode_index = 0;
4347 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4348 "Headphone Playback Volume",
4349 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4353 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4354 "Headphone Playback Switch",
4355 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4359 imux = &spec->private_imux[1];
4361 /* for hp mode select */
4362 for (i = 0; texts[i]; i++)
4363 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4365 spec->hp_mux = &spec->private_imux[1];
4369 /* create playback/capture controls for input pins */
4370 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4371 const struct auto_pin_cfg *cfg)
4373 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4374 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4375 ARRAY_SIZE(pin_idxs));
4378 static int vt1702_parse_auto_config(struct hda_codec *codec)
4380 struct via_spec *spec = codec->spec;
4383 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4386 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4389 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4390 return 0; /* can't find valid BIOS pin config */
4392 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4395 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4398 /* limit AA path volume to 0 dB */
4399 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4400 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4401 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4402 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4403 (1 << AC_AMPCAP_MUTE_SHIFT));
4404 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4408 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4410 fill_dig_outs(codec);
4412 if (spec->kctls.list)
4413 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4415 spec->input_mux = &spec->private_imux[0];
4418 via_hp_build(codec);
4423 #ifdef CONFIG_SND_HDA_POWER_SAVE
4424 static struct hda_amp_list vt1702_loopbacks[] = {
4425 { 0x1A, HDA_INPUT, 1 },
4426 { 0x1A, HDA_INPUT, 2 },
4427 { 0x1A, HDA_INPUT, 3 },
4428 { 0x1A, HDA_INPUT, 4 },
4433 static int patch_vt1702(struct hda_codec *codec)
4435 struct via_spec *spec;
4438 /* create a codec specific record */
4439 spec = via_new_spec(codec);
4443 /* automatic parse from the BIOS config */
4444 err = vt1702_parse_auto_config(codec);
4449 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4450 "from BIOS. Using genenic mode...\n");
4453 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4454 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4456 spec->stream_name_analog = "VT1702 Analog";
4457 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4458 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4460 spec->stream_name_digital = "VT1702 Digital";
4461 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4463 if (!spec->adc_nids && spec->input_mux) {
4464 spec->adc_nids = vt1702_adc_nids;
4465 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4466 get_mux_nids(codec);
4467 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4471 codec->patch_ops = via_patch_ops;
4473 codec->patch_ops.init = via_auto_init;
4474 codec->patch_ops.unsol_event = via_unsol_event;
4475 #ifdef CONFIG_SND_HDA_POWER_SAVE
4476 spec->loopback.amplist = vt1702_loopbacks;
4482 /* Patch for VT1718S */
4484 /* capture mixer elements */
4485 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4486 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4487 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4488 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4489 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4490 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4491 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4494 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4495 /* The multiple "Capture Source" controls confuse alsamixer
4496 * So call somewhat different..
4498 .name = "Input Source",
4500 .info = via_mux_enum_info,
4501 .get = via_mux_enum_get,
4502 .put = via_mux_enum_put,
4507 static struct hda_verb vt1718S_volume_init_verbs[] = {
4509 * Unmute ADC0-1 and set the default input to mic-in
4511 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4512 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4515 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4518 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4519 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4520 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4521 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4522 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4523 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4525 /* Setup default input of Front HP to MW9 */
4526 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4527 /* PW9 PW10 Output enable */
4528 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4529 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4530 /* PW11 Input enable */
4531 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4532 /* Enable Boost Volume backdoor */
4534 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4535 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4536 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4537 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4538 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4539 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4540 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4541 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4542 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4543 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4544 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4545 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4546 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4547 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4548 /* Unmute MW4's index 0 */
4549 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4554 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4555 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4556 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4557 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4558 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4559 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4560 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4561 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4562 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4563 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4567 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4571 .nid = 0x8, /* NID to query formats and rates */
4573 .open = via_playback_pcm_open,
4574 .prepare = via_playback_multi_pcm_prepare,
4575 .cleanup = via_playback_multi_pcm_cleanup,
4576 .close = via_pcm_open_close,
4580 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4584 .nid = 0x10, /* NID to query formats and rates */
4586 .open = via_pcm_open_close,
4587 .prepare = via_capture_pcm_prepare,
4588 .cleanup = via_capture_pcm_cleanup,
4589 .close = via_pcm_open_close,
4593 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4597 /* NID is set in via_build_pcms */
4599 .open = via_dig_playback_pcm_open,
4600 .close = via_dig_playback_pcm_close,
4601 .prepare = via_dig_playback_pcm_prepare,
4602 .cleanup = via_dig_playback_pcm_cleanup
4606 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4612 /* fill in the dac_nids table from the parsed pin configuration */
4613 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4614 const struct auto_pin_cfg *cfg)
4619 spec->multiout.num_dacs = cfg->line_outs;
4621 spec->multiout.dac_nids = spec->private_dac_nids;
4623 for (i = 0; i < 4; i++) {
4624 nid = cfg->line_out_pins[i];
4626 /* config dac list */
4628 case AUTO_SEQ_FRONT:
4629 spec->multiout.dac_nids[i] = 0x8;
4631 case AUTO_SEQ_CENLFE:
4632 spec->multiout.dac_nids[i] = 0xa;
4634 case AUTO_SEQ_SURROUND:
4635 spec->multiout.dac_nids[i] = 0x9;
4638 spec->multiout.dac_nids[i] = 0xb;
4647 /* add playback controls from the parsed DAC table */
4648 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4649 const struct auto_pin_cfg *cfg)
4652 static const char * const chname[4] = {
4653 "Front", "Surround", "C/LFE", "Side"
4655 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4656 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4657 hda_nid_t nid, nid_vol, nid_mute = 0;
4660 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4661 nid = cfg->line_out_pins[i];
4665 nid_vol = nid_vols[i];
4666 nid_mute = nid_mutes[i];
4668 if (i == AUTO_SEQ_CENLFE) {
4670 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4671 "Center Playback Volume",
4672 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4676 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4677 "LFE Playback Volume",
4678 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4682 err = via_add_control(
4683 spec, VIA_CTL_WIDGET_MUTE,
4684 "Center Playback Switch",
4685 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4689 err = via_add_control(
4690 spec, VIA_CTL_WIDGET_MUTE,
4691 "LFE Playback Switch",
4692 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4696 } else if (i == AUTO_SEQ_FRONT) {
4698 sprintf(name, "%s Playback Volume", chname[i]);
4699 err = via_add_control(
4700 spec, VIA_CTL_WIDGET_VOL, name,
4701 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4704 sprintf(name, "%s Playback Switch", chname[i]);
4705 err = via_add_control(
4706 spec, VIA_CTL_WIDGET_MUTE, name,
4707 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4712 sprintf(name, "%s Playback Volume", chname[i]);
4713 err = via_add_control(
4714 spec, VIA_CTL_WIDGET_VOL, name,
4715 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4718 sprintf(name, "%s Playback Switch", chname[i]);
4719 err = via_add_control(
4720 spec, VIA_CTL_WIDGET_MUTE, name,
4721 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4730 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4737 spec->multiout.hp_nid = 0xc; /* AOW4 */
4738 spec->hp_independent_mode_index = 1;
4740 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4741 "Headphone Playback Volume",
4742 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4746 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4747 "Headphone Playback Switch",
4748 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4752 create_hp_imux(spec);
4756 /* create playback/capture controls for input pins */
4757 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4758 const struct auto_pin_cfg *cfg)
4760 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4761 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4762 ARRAY_SIZE(pin_idxs));
4765 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4767 struct via_spec *spec = codec->spec;
4770 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4774 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4777 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4778 return 0; /* can't find valid BIOS pin config */
4780 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4783 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4786 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4790 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4792 fill_dig_outs(codec);
4794 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4795 spec->dig_in_nid = 0x13;
4797 if (spec->kctls.list)
4798 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4800 spec->input_mux = &spec->private_imux[0];
4803 via_hp_build(codec);
4805 via_smart51_build(spec);
4810 #ifdef CONFIG_SND_HDA_POWER_SAVE
4811 static struct hda_amp_list vt1718S_loopbacks[] = {
4812 { 0x21, HDA_INPUT, 1 },
4813 { 0x21, HDA_INPUT, 2 },
4814 { 0x21, HDA_INPUT, 3 },
4815 { 0x21, HDA_INPUT, 4 },
4820 static int patch_vt1718S(struct hda_codec *codec)
4822 struct via_spec *spec;
4825 /* create a codec specific record */
4826 spec = via_new_spec(codec);
4830 /* automatic parse from the BIOS config */
4831 err = vt1718S_parse_auto_config(codec);
4836 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4837 "from BIOS. Using genenic mode...\n");
4840 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4841 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4843 if (codec->vendor_id == 0x11060441)
4844 spec->stream_name_analog = "VT2020 Analog";
4845 else if (codec->vendor_id == 0x11064441)
4846 spec->stream_name_analog = "VT1828S Analog";
4848 spec->stream_name_analog = "VT1718S Analog";
4849 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4850 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4852 if (codec->vendor_id == 0x11060441)
4853 spec->stream_name_digital = "VT2020 Digital";
4854 else if (codec->vendor_id == 0x11064441)
4855 spec->stream_name_digital = "VT1828S Digital";
4857 spec->stream_name_digital = "VT1718S Digital";
4858 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4859 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4860 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4862 if (!spec->adc_nids && spec->input_mux) {
4863 spec->adc_nids = vt1718S_adc_nids;
4864 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4865 get_mux_nids(codec);
4866 override_mic_boost(codec, 0x2b, 0, 3, 40);
4867 override_mic_boost(codec, 0x29, 0, 3, 40);
4868 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4872 codec->patch_ops = via_patch_ops;
4874 codec->patch_ops.init = via_auto_init;
4875 codec->patch_ops.unsol_event = via_unsol_event;
4877 #ifdef CONFIG_SND_HDA_POWER_SAVE
4878 spec->loopback.amplist = vt1718S_loopbacks;
4884 /* Patch for VT1716S */
4886 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4887 struct snd_ctl_elem_info *uinfo)
4889 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4891 uinfo->value.integer.min = 0;
4892 uinfo->value.integer.max = 1;
4896 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4897 struct snd_ctl_elem_value *ucontrol)
4899 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4902 index = snd_hda_codec_read(codec, 0x26, 0,
4903 AC_VERB_GET_CONNECT_SEL, 0);
4905 *ucontrol->value.integer.value = index;
4910 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4911 struct snd_ctl_elem_value *ucontrol)
4913 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4914 struct via_spec *spec = codec->spec;
4915 int index = *ucontrol->value.integer.value;
4917 snd_hda_codec_write(codec, 0x26, 0,
4918 AC_VERB_SET_CONNECT_SEL, index);
4919 spec->dmic_enabled = index;
4920 set_jack_power_state(codec);
4925 /* capture mixer elements */
4926 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4927 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4928 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4929 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4930 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4931 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4932 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4935 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4936 .name = "Input Source",
4938 .info = via_mux_enum_info,
4939 .get = via_mux_enum_get,
4940 .put = via_mux_enum_put,
4945 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4946 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4948 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4949 .name = "Digital Mic Capture Switch",
4950 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4952 .info = vt1716s_dmic_info,
4953 .get = vt1716s_dmic_get,
4954 .put = vt1716s_dmic_put,
4960 /* mono-out mixer elements */
4961 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4962 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4966 static struct hda_verb vt1716S_volume_init_verbs[] = {
4968 * Unmute ADC0-1 and set the default input to mic-in
4970 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4971 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4974 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4977 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4978 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4979 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4980 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4981 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4982 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4984 /* MUX Indices: Stereo Mixer = 5 */
4985 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4987 /* Setup default input of PW4 to MW0 */
4988 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
4990 /* Setup default input of SW1 as MW0 */
4991 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
4993 /* Setup default input of SW4 as AOW0 */
4994 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4996 /* PW9 PW10 Output enable */
4997 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4998 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5000 /* Unmute SW1, PW12 */
5001 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5002 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5003 /* PW12 Output enable */
5004 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5005 /* Enable Boost Volume backdoor */
5007 /* don't bybass mixer */
5009 /* Enable mono output */
5015 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5016 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5017 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5018 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5019 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5020 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5021 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5022 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5023 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5024 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5028 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5032 .nid = 0x10, /* NID to query formats and rates */
5034 .open = via_playback_pcm_open,
5035 .prepare = via_playback_multi_pcm_prepare,
5036 .cleanup = via_playback_multi_pcm_cleanup,
5037 .close = via_pcm_open_close,
5041 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5045 .nid = 0x13, /* NID to query formats and rates */
5047 .open = via_pcm_open_close,
5048 .prepare = via_capture_pcm_prepare,
5049 .cleanup = via_capture_pcm_cleanup,
5050 .close = via_pcm_open_close,
5054 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5058 /* NID is set in via_build_pcms */
5060 .open = via_dig_playback_pcm_open,
5061 .close = via_dig_playback_pcm_close,
5062 .prepare = via_dig_playback_pcm_prepare,
5063 .cleanup = via_dig_playback_pcm_cleanup
5067 /* fill in the dac_nids table from the parsed pin configuration */
5068 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5069 const struct auto_pin_cfg *cfg)
5073 spec->multiout.num_dacs = cfg->line_outs;
5075 spec->multiout.dac_nids = spec->private_dac_nids;
5077 for (i = 0; i < 3; i++) {
5078 nid = cfg->line_out_pins[i];
5080 /* config dac list */
5082 case AUTO_SEQ_FRONT:
5083 spec->multiout.dac_nids[i] = 0x10;
5085 case AUTO_SEQ_CENLFE:
5086 spec->multiout.dac_nids[i] = 0x25;
5088 case AUTO_SEQ_SURROUND:
5089 spec->multiout.dac_nids[i] = 0x11;
5098 /* add playback controls from the parsed DAC table */
5099 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5100 const struct auto_pin_cfg *cfg)
5103 static const char * const chname[3] = {
5104 "Front", "Surround", "C/LFE"
5106 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5107 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5108 hda_nid_t nid, nid_vol, nid_mute;
5111 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5112 nid = cfg->line_out_pins[i];
5117 nid_vol = nid_vols[i];
5118 nid_mute = nid_mutes[i];
5120 if (i == AUTO_SEQ_CENLFE) {
5121 err = via_add_control(
5122 spec, VIA_CTL_WIDGET_VOL,
5123 "Center Playback Volume",
5124 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5127 err = via_add_control(
5128 spec, VIA_CTL_WIDGET_VOL,
5129 "LFE Playback Volume",
5130 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5133 err = via_add_control(
5134 spec, VIA_CTL_WIDGET_MUTE,
5135 "Center Playback Switch",
5136 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5140 err = via_add_control(
5141 spec, VIA_CTL_WIDGET_MUTE,
5142 "LFE Playback Switch",
5143 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5147 } else if (i == AUTO_SEQ_FRONT) {
5149 err = via_add_control(
5150 spec, VIA_CTL_WIDGET_VOL,
5151 "Master Front Playback Volume",
5152 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5155 err = via_add_control(
5156 spec, VIA_CTL_WIDGET_MUTE,
5157 "Master Front Playback Switch",
5158 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5162 sprintf(name, "%s Playback Volume", chname[i]);
5163 err = via_add_control(
5164 spec, VIA_CTL_WIDGET_VOL, name,
5165 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5168 sprintf(name, "%s Playback Switch", chname[i]);
5169 err = via_add_control(
5170 spec, VIA_CTL_WIDGET_MUTE, name,
5171 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5176 sprintf(name, "%s Playback Volume", chname[i]);
5177 err = via_add_control(
5178 spec, VIA_CTL_WIDGET_VOL, name,
5179 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5182 sprintf(name, "%s Playback Switch", chname[i]);
5183 err = via_add_control(
5184 spec, VIA_CTL_WIDGET_MUTE, name,
5185 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5194 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5201 spec->multiout.hp_nid = 0x25; /* AOW3 */
5202 spec->hp_independent_mode_index = 1;
5204 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5205 "Headphone Playback Volume",
5206 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5210 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5211 "Headphone Playback Switch",
5212 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5216 create_hp_imux(spec);
5220 /* create playback/capture controls for input pins */
5221 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5222 const struct auto_pin_cfg *cfg)
5224 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5225 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5226 ARRAY_SIZE(pin_idxs));
5229 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5231 struct via_spec *spec = codec->spec;
5234 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5237 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5240 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5241 return 0; /* can't find valid BIOS pin config */
5243 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5246 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5249 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5253 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5255 fill_dig_outs(codec);
5257 if (spec->kctls.list)
5258 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5260 spec->input_mux = &spec->private_imux[0];
5263 via_hp_build(codec);
5265 via_smart51_build(spec);
5270 #ifdef CONFIG_SND_HDA_POWER_SAVE
5271 static struct hda_amp_list vt1716S_loopbacks[] = {
5272 { 0x16, HDA_INPUT, 1 },
5273 { 0x16, HDA_INPUT, 2 },
5274 { 0x16, HDA_INPUT, 3 },
5275 { 0x16, HDA_INPUT, 4 },
5280 static int patch_vt1716S(struct hda_codec *codec)
5282 struct via_spec *spec;
5285 /* create a codec specific record */
5286 spec = via_new_spec(codec);
5290 /* automatic parse from the BIOS config */
5291 err = vt1716S_parse_auto_config(codec);
5296 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5297 "from BIOS. Using genenic mode...\n");
5300 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5301 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5303 spec->stream_name_analog = "VT1716S Analog";
5304 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5305 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5307 spec->stream_name_digital = "VT1716S Digital";
5308 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5310 if (!spec->adc_nids && spec->input_mux) {
5311 spec->adc_nids = vt1716S_adc_nids;
5312 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5313 get_mux_nids(codec);
5314 override_mic_boost(codec, 0x1a, 0, 3, 40);
5315 override_mic_boost(codec, 0x1e, 0, 3, 40);
5316 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5320 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5323 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5325 codec->patch_ops = via_patch_ops;
5327 codec->patch_ops.init = via_auto_init;
5328 codec->patch_ops.unsol_event = via_unsol_event;
5330 #ifdef CONFIG_SND_HDA_POWER_SAVE
5331 spec->loopback.amplist = vt1716S_loopbacks;
5339 /* capture mixer elements */
5340 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5341 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5342 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5343 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5344 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5345 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5346 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5349 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5350 /* The multiple "Capture Source" controls confuse alsamixer
5351 * So call somewhat different..
5353 /* .name = "Capture Source", */
5354 .name = "Input Source",
5356 .info = via_mux_enum_info,
5357 .get = via_mux_enum_get,
5358 .put = via_mux_enum_put,
5363 static struct hda_verb vt2002P_volume_init_verbs[] = {
5365 * Unmute ADC0-1 and set the default input to mic-in
5367 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5368 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5371 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5374 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5375 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5376 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5377 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5378 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5379 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5381 /* MUX Indices: Mic = 0 */
5382 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5383 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5385 /* PW9 Output enable */
5386 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5388 /* Enable Boost Volume backdoor */
5391 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5392 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5393 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5394 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5395 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5396 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5397 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5398 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5399 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5401 /* set MUX0/1/4/8 = 0 (AOW0) */
5402 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5403 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5404 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5405 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5407 /* set PW0 index=0 (MW0) */
5408 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5410 /* Enable AOW0 to MW9 */
5416 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5417 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5418 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5419 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5420 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5421 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5422 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5423 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5427 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5431 .nid = 0x8, /* NID to query formats and rates */
5433 .open = via_playback_pcm_open,
5434 .prepare = via_playback_multi_pcm_prepare,
5435 .cleanup = via_playback_multi_pcm_cleanup,
5436 .close = via_pcm_open_close,
5440 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5444 .nid = 0x10, /* NID to query formats and rates */
5446 .open = via_pcm_open_close,
5447 .prepare = via_capture_pcm_prepare,
5448 .cleanup = via_capture_pcm_cleanup,
5449 .close = via_pcm_open_close,
5453 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5457 /* NID is set in via_build_pcms */
5459 .open = via_dig_playback_pcm_open,
5460 .close = via_dig_playback_pcm_close,
5461 .prepare = via_dig_playback_pcm_prepare,
5462 .cleanup = via_dig_playback_pcm_cleanup
5466 /* fill in the dac_nids table from the parsed pin configuration */
5467 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5468 const struct auto_pin_cfg *cfg)
5470 spec->multiout.num_dacs = 1;
5471 spec->multiout.dac_nids = spec->private_dac_nids;
5472 if (cfg->line_out_pins[0])
5473 spec->multiout.dac_nids[0] = 0x8;
5477 /* add playback controls from the parsed DAC table */
5478 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5479 const struct auto_pin_cfg *cfg)
5483 if (!cfg->line_out_pins[0])
5487 /* Line-Out: PortE */
5488 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5489 "Master Front Playback Volume",
5490 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5493 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5494 "Master Front Playback Switch",
5495 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5502 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5509 spec->multiout.hp_nid = 0x9;
5510 spec->hp_independent_mode_index = 1;
5512 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5513 "Headphone Playback Volume",
5514 HDA_COMPOSE_AMP_VAL(
5515 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5519 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5520 "Headphone Playback Switch",
5521 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5525 create_hp_imux(spec);
5529 /* create playback/capture controls for input pins */
5530 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5531 const struct auto_pin_cfg *cfg)
5533 struct via_spec *spec = codec->spec;
5534 struct hda_input_mux *imux = &spec->private_imux[0];
5535 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5538 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5539 ARRAY_SIZE(pin_idxs));
5542 /* build volume/mute control of loopback */
5543 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5547 /* for digital mic select */
5548 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5553 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5555 struct via_spec *spec = codec->spec;
5559 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5563 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5567 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5568 return 0; /* can't find valid BIOS pin config */
5570 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5573 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5576 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5580 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5582 fill_dig_outs(codec);
5584 if (spec->kctls.list)
5585 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5587 spec->input_mux = &spec->private_imux[0];
5590 via_hp_build(codec);
5595 #ifdef CONFIG_SND_HDA_POWER_SAVE
5596 static struct hda_amp_list vt2002P_loopbacks[] = {
5597 { 0x21, HDA_INPUT, 0 },
5598 { 0x21, HDA_INPUT, 1 },
5599 { 0x21, HDA_INPUT, 2 },
5605 /* patch for vt2002P */
5606 static int patch_vt2002P(struct hda_codec *codec)
5608 struct via_spec *spec;
5611 /* create a codec specific record */
5612 spec = via_new_spec(codec);
5616 /* automatic parse from the BIOS config */
5617 err = vt2002P_parse_auto_config(codec);
5622 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5623 "from BIOS. Using genenic mode...\n");
5626 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5627 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5629 spec->stream_name_analog = "VT2002P Analog";
5630 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5631 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5633 spec->stream_name_digital = "VT2002P Digital";
5634 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5636 if (!spec->adc_nids && spec->input_mux) {
5637 spec->adc_nids = vt2002P_adc_nids;
5638 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5639 get_mux_nids(codec);
5640 override_mic_boost(codec, 0x2b, 0, 3, 40);
5641 override_mic_boost(codec, 0x29, 0, 3, 40);
5642 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5646 codec->patch_ops = via_patch_ops;
5648 codec->patch_ops.init = via_auto_init;
5649 codec->patch_ops.unsol_event = via_unsol_event;
5651 #ifdef CONFIG_SND_HDA_POWER_SAVE
5652 spec->loopback.amplist = vt2002P_loopbacks;
5660 /* capture mixer elements */
5661 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5662 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5663 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5664 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5665 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5666 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5667 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5670 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5671 /* The multiple "Capture Source" controls confuse alsamixer
5672 * So call somewhat different..
5674 .name = "Input Source",
5676 .info = via_mux_enum_info,
5677 .get = via_mux_enum_get,
5678 .put = via_mux_enum_put,
5683 static struct hda_verb vt1812_volume_init_verbs[] = {
5685 * Unmute ADC0-1 and set the default input to mic-in
5687 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5688 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5691 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5694 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5695 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5696 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5697 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5698 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5699 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5701 /* MUX Indices: Mic = 0 */
5702 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5703 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5705 /* PW9 Output enable */
5706 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5708 /* Enable Boost Volume backdoor */
5711 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5712 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5713 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5714 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5715 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5716 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5717 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5718 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5719 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5720 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5721 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5723 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5724 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5725 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5726 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5727 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5728 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5730 /* Enable AOW0 to MW9 */
5736 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5737 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5738 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5739 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5740 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5741 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5742 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5743 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5744 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5748 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5752 .nid = 0x8, /* NID to query formats and rates */
5754 .open = via_playback_pcm_open,
5755 .prepare = via_playback_multi_pcm_prepare,
5756 .cleanup = via_playback_multi_pcm_cleanup,
5757 .close = via_pcm_open_close,
5761 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5765 .nid = 0x10, /* NID to query formats and rates */
5767 .open = via_pcm_open_close,
5768 .prepare = via_capture_pcm_prepare,
5769 .cleanup = via_capture_pcm_cleanup,
5770 .close = via_pcm_open_close,
5774 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5778 /* NID is set in via_build_pcms */
5780 .open = via_dig_playback_pcm_open,
5781 .close = via_dig_playback_pcm_close,
5782 .prepare = via_dig_playback_pcm_prepare,
5783 .cleanup = via_dig_playback_pcm_cleanup
5786 /* fill in the dac_nids table from the parsed pin configuration */
5787 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5788 const struct auto_pin_cfg *cfg)
5790 spec->multiout.num_dacs = 1;
5791 spec->multiout.dac_nids = spec->private_dac_nids;
5792 if (cfg->line_out_pins[0])
5793 spec->multiout.dac_nids[0] = 0x8;
5798 /* add playback controls from the parsed DAC table */
5799 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5800 const struct auto_pin_cfg *cfg)
5804 if (!cfg->line_out_pins[0])
5807 /* Line-Out: PortE */
5808 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5809 "Front Playback Volume",
5810 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5813 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5814 "Front Playback Switch",
5815 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5822 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5829 spec->multiout.hp_nid = 0x9;
5830 spec->hp_independent_mode_index = 1;
5833 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5834 "Headphone Playback Volume",
5835 HDA_COMPOSE_AMP_VAL(
5836 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5840 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5841 "Headphone Playback Switch",
5842 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5846 create_hp_imux(spec);
5850 /* create playback/capture controls for input pins */
5851 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5852 const struct auto_pin_cfg *cfg)
5854 struct via_spec *spec = codec->spec;
5855 struct hda_input_mux *imux = &spec->private_imux[0];
5856 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5859 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5860 ARRAY_SIZE(pin_idxs));
5864 /* build volume/mute control of loopback */
5865 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5869 /* for digital mic select */
5870 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5875 static int vt1812_parse_auto_config(struct hda_codec *codec)
5877 struct via_spec *spec = codec->spec;
5881 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5884 fill_dig_outs(codec);
5885 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5889 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5890 return 0; /* can't find valid BIOS pin config */
5892 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5895 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5898 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
5902 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5904 fill_dig_outs(codec);
5906 if (spec->kctls.list)
5907 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5909 spec->input_mux = &spec->private_imux[0];
5912 via_hp_build(codec);
5917 #ifdef CONFIG_SND_HDA_POWER_SAVE
5918 static struct hda_amp_list vt1812_loopbacks[] = {
5919 { 0x21, HDA_INPUT, 0 },
5920 { 0x21, HDA_INPUT, 1 },
5921 { 0x21, HDA_INPUT, 2 },
5927 /* patch for vt1812 */
5928 static int patch_vt1812(struct hda_codec *codec)
5930 struct via_spec *spec;
5933 /* create a codec specific record */
5934 spec = via_new_spec(codec);
5938 /* automatic parse from the BIOS config */
5939 err = vt1812_parse_auto_config(codec);
5944 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5945 "from BIOS. Using genenic mode...\n");
5949 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
5950 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
5952 spec->stream_name_analog = "VT1812 Analog";
5953 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
5954 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
5956 spec->stream_name_digital = "VT1812 Digital";
5957 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
5960 if (!spec->adc_nids && spec->input_mux) {
5961 spec->adc_nids = vt1812_adc_nids;
5962 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
5963 get_mux_nids(codec);
5964 override_mic_boost(codec, 0x2b, 0, 3, 40);
5965 override_mic_boost(codec, 0x29, 0, 3, 40);
5966 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
5970 codec->patch_ops = via_patch_ops;
5972 codec->patch_ops.init = via_auto_init;
5973 codec->patch_ops.unsol_event = via_unsol_event;
5975 #ifdef CONFIG_SND_HDA_POWER_SAVE
5976 spec->loopback.amplist = vt1812_loopbacks;
5985 static struct hda_codec_preset snd_hda_preset_via[] = {
5986 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
5987 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
5988 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
5989 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
5990 { .id = 0x1106e710, .name = "VT1709 10-Ch",
5991 .patch = patch_vt1709_10ch},
5992 { .id = 0x1106e711, .name = "VT1709 10-Ch",
5993 .patch = patch_vt1709_10ch},
5994 { .id = 0x1106e712, .name = "VT1709 10-Ch",
5995 .patch = patch_vt1709_10ch},
5996 { .id = 0x1106e713, .name = "VT1709 10-Ch",
5997 .patch = patch_vt1709_10ch},
5998 { .id = 0x1106e714, .name = "VT1709 6-Ch",
5999 .patch = patch_vt1709_6ch},
6000 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6001 .patch = patch_vt1709_6ch},
6002 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6003 .patch = patch_vt1709_6ch},
6004 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6005 .patch = patch_vt1709_6ch},
6006 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6007 .patch = patch_vt1708B_8ch},
6008 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6009 .patch = patch_vt1708B_8ch},
6010 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6011 .patch = patch_vt1708B_8ch},
6012 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6013 .patch = patch_vt1708B_8ch},
6014 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6015 .patch = patch_vt1708B_4ch},
6016 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6017 .patch = patch_vt1708B_4ch},
6018 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6019 .patch = patch_vt1708B_4ch},
6020 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6021 .patch = patch_vt1708B_4ch},
6022 { .id = 0x11060397, .name = "VT1708S",
6023 .patch = patch_vt1708S},
6024 { .id = 0x11061397, .name = "VT1708S",
6025 .patch = patch_vt1708S},
6026 { .id = 0x11062397, .name = "VT1708S",
6027 .patch = patch_vt1708S},
6028 { .id = 0x11063397, .name = "VT1708S",
6029 .patch = patch_vt1708S},
6030 { .id = 0x11064397, .name = "VT1708S",
6031 .patch = patch_vt1708S},
6032 { .id = 0x11065397, .name = "VT1708S",
6033 .patch = patch_vt1708S},
6034 { .id = 0x11066397, .name = "VT1708S",
6035 .patch = patch_vt1708S},
6036 { .id = 0x11067397, .name = "VT1708S",
6037 .patch = patch_vt1708S},
6038 { .id = 0x11060398, .name = "VT1702",
6039 .patch = patch_vt1702},
6040 { .id = 0x11061398, .name = "VT1702",
6041 .patch = patch_vt1702},
6042 { .id = 0x11062398, .name = "VT1702",
6043 .patch = patch_vt1702},
6044 { .id = 0x11063398, .name = "VT1702",
6045 .patch = patch_vt1702},
6046 { .id = 0x11064398, .name = "VT1702",
6047 .patch = patch_vt1702},
6048 { .id = 0x11065398, .name = "VT1702",
6049 .patch = patch_vt1702},
6050 { .id = 0x11066398, .name = "VT1702",
6051 .patch = patch_vt1702},
6052 { .id = 0x11067398, .name = "VT1702",
6053 .patch = patch_vt1702},
6054 { .id = 0x11060428, .name = "VT1718S",
6055 .patch = patch_vt1718S},
6056 { .id = 0x11064428, .name = "VT1718S",
6057 .patch = patch_vt1718S},
6058 { .id = 0x11060441, .name = "VT2020",
6059 .patch = patch_vt1718S},
6060 { .id = 0x11064441, .name = "VT1828S",
6061 .patch = patch_vt1718S},
6062 { .id = 0x11060433, .name = "VT1716S",
6063 .patch = patch_vt1716S},
6064 { .id = 0x1106a721, .name = "VT1716S",
6065 .patch = patch_vt1716S},
6066 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6067 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6068 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6069 { .id = 0x11060440, .name = "VT1818S",
6070 .patch = patch_vt1708S},
6074 MODULE_ALIAS("snd-hda-codec-id:1106*");
6076 static struct hda_codec_preset_list via_list = {
6077 .preset = snd_hda_preset_via,
6078 .owner = THIS_MODULE,
6081 MODULE_LICENSE("GPL");
6082 MODULE_DESCRIPTION("VIA HD-audio codec");
6084 static int __init patch_via_init(void)
6086 return snd_hda_add_codec_preset(&via_list);
6089 static void __exit patch_via_exit(void)
6091 snd_hda_delete_codec_preset(&via_list);
6094 module_init(patch_via_init)
6095 module_exit(patch_via_exit)