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 if (spec->codec_type != VT1708) {
1270 nums = snd_hda_get_connections(codec, nid,
1271 conn, HDA_MAX_CONNECTIONS);
1276 knew = via_clone_control(spec, &via_hp_mixer[0]);
1280 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1281 knew->private_value = nid;
1283 knew = via_clone_control(spec, &via_hp_mixer[1]);
1286 knew->subdevice = side_mute_channel(spec);
1291 static void notify_aa_path_ctls(struct hda_codec *codec)
1294 struct snd_ctl_elem_id id;
1295 const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"};
1296 struct snd_kcontrol *ctl;
1298 memset(&id, 0, sizeof(id));
1299 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1300 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1301 sprintf(id.name, "%s Playback Volume", labels[i]);
1302 ctl = snd_hda_find_mixer_ctl(codec, id.name);
1304 snd_ctl_notify(codec->bus->card,
1305 SNDRV_CTL_EVENT_MASK_VALUE,
1310 static void mute_aa_path(struct hda_codec *codec, int mute)
1312 struct via_spec *spec = codec->spec;
1313 hda_nid_t nid_mixer;
1317 /* get nid of MW0 and start & end index */
1318 switch (spec->codec_type) {
1346 /* check AA path's mute status */
1347 for (i = start_idx; i <= end_idx; i++) {
1348 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1349 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1353 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1355 const struct auto_pin_cfg *cfg = &spec->autocfg;
1358 for (i = 0; i < cfg->num_inputs; i++) {
1359 if (pin == cfg->inputs[i].pin)
1360 return cfg->inputs[i].type <= AUTO_PIN_LINE_IN;
1365 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1366 struct snd_ctl_elem_info *uinfo)
1368 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1370 uinfo->value.integer.min = 0;
1371 uinfo->value.integer.max = 1;
1375 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1376 struct snd_ctl_elem_value *ucontrol)
1378 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1379 struct via_spec *spec = codec->spec;
1380 const struct auto_pin_cfg *cfg = &spec->autocfg;
1384 for (i = 0; i < cfg->num_inputs; i++) {
1385 hda_nid_t nid = cfg->inputs[i].pin;
1386 int ctl = snd_hda_codec_read(codec, nid, 0,
1387 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1388 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1390 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1391 spec->hp_independent_mode && spec->codec_type != VT1718S)
1392 continue; /* ignore FMic for independent HP */
1393 if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN))
1396 *ucontrol->value.integer.value = on;
1400 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1401 struct snd_ctl_elem_value *ucontrol)
1403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1404 struct via_spec *spec = codec->spec;
1405 const struct auto_pin_cfg *cfg = &spec->autocfg;
1406 int out_in = *ucontrol->value.integer.value
1407 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1410 for (i = 0; i < cfg->num_inputs; i++) {
1411 hda_nid_t nid = cfg->inputs[i].pin;
1414 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1416 if (cfg->inputs[i].type == AUTO_PIN_MIC &&
1417 spec->hp_independent_mode && spec->codec_type != VT1718S)
1418 continue; /* don't retask FMic for independent HP */
1420 parm = snd_hda_codec_read(codec, nid, 0,
1421 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1422 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1424 snd_hda_codec_write(codec, nid, 0,
1425 AC_VERB_SET_PIN_WIDGET_CONTROL,
1427 if (out_in == AC_PINCTL_OUT_EN) {
1428 mute_aa_path(codec, 1);
1429 notify_aa_path_ctls(codec);
1431 if (spec->codec_type == VT1718S) {
1432 snd_hda_codec_amp_stereo(
1433 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1436 if (cfg->inputs[i].type == AUTO_PIN_MIC) {
1437 if (spec->codec_type == VT1708S
1438 || spec->codec_type == VT1716S) {
1439 /* input = index 1 (AOW3) */
1440 snd_hda_codec_write(
1442 AC_VERB_SET_CONNECT_SEL, 1);
1443 snd_hda_codec_amp_stereo(
1444 codec, nid, HDA_OUTPUT,
1445 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1449 spec->smart51_enabled = *ucontrol->value.integer.value;
1450 set_jack_power_state(codec);
1454 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1456 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1457 .name = "Smart 5.1",
1459 .info = via_smart51_info,
1460 .get = via_smart51_get,
1461 .put = via_smart51_put,
1464 .iface = NID_MAPPING,
1465 .name = "Smart 5.1",
1469 static int via_smart51_build(struct via_spec *spec)
1471 struct snd_kcontrol_new *knew;
1472 const struct auto_pin_cfg *cfg = &spec->autocfg;
1476 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1480 for (i = 0; i < cfg->num_inputs; i++) {
1481 nid = cfg->inputs[i].pin;
1482 if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) {
1483 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1486 knew->subdevice = nid;
1494 /* capture mixer elements */
1495 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1496 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1497 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1498 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1499 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1501 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1502 /* The multiple "Capture Source" controls confuse alsamixer
1503 * So call somewhat different..
1505 /* .name = "Capture Source", */
1506 .name = "Input Source",
1508 .info = via_mux_enum_info,
1509 .get = via_mux_enum_get,
1510 .put = via_mux_enum_put,
1515 /* check AA path's mute statue */
1516 static int is_aa_path_mute(struct hda_codec *codec)
1519 hda_nid_t nid_mixer;
1523 struct via_spec *spec = codec->spec;
1524 /* get nid of MW0 and start & end index */
1525 switch (spec->codec_type) {
1553 /* check AA path's mute status */
1554 for (i = start_idx; i <= end_idx; i++) {
1555 unsigned int con_list = snd_hda_codec_read(
1556 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1557 int shift = 8 * (i % 4);
1558 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1559 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1560 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1561 /* check mute status while the pin is connected */
1562 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1564 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1566 if (!mute_l || !mute_r) {
1575 /* enter/exit analog low-current mode */
1576 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1578 struct via_spec *spec = codec->spec;
1579 static int saved_stream_idle = 1; /* saved stream idle status */
1580 int enable = is_aa_path_mute(codec);
1581 unsigned int verb = 0;
1582 unsigned int parm = 0;
1584 if (stream_idle == -1) /* stream status did not change */
1585 enable = enable && saved_stream_idle;
1587 enable = enable && stream_idle;
1588 saved_stream_idle = stream_idle;
1591 /* decide low current mode's verb & parameter */
1592 switch (spec->codec_type) {
1596 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1602 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1606 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1611 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1614 return; /* other codecs are not supported */
1617 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1621 * generic initialization of ADC, input mixers and output mixers
1623 static struct hda_verb vt1708_volume_init_verbs[] = {
1625 * Unmute ADC0-1 and set the default input to mic-in
1627 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1628 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1631 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1634 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1635 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1636 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1637 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1638 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1639 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1642 * Set up output mixers (0x19 - 0x1b)
1644 /* set vol=0 to output mixers */
1645 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1646 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1647 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1649 /* Setup default input MW0 to PW4 */
1650 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1651 /* PW9 Output enable */
1652 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1656 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1657 struct hda_codec *codec,
1658 struct snd_pcm_substream *substream)
1660 struct via_spec *spec = codec->spec;
1661 int idle = substream->pstr->substream_opened == 1
1662 && substream->ref_count == 0;
1663 analog_low_current_mode(codec, idle);
1664 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1668 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1669 unsigned int stream_tag,
1670 unsigned int format,
1671 struct snd_pcm_substream *substream)
1673 struct via_spec *spec = codec->spec;
1674 struct hda_multi_out *mout = &spec->multiout;
1675 hda_nid_t *nids = mout->dac_nids;
1676 int chs = substream->runtime->channels;
1679 mutex_lock(&codec->spdif_mutex);
1680 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1682 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1684 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1685 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1686 /* turn off SPDIF once; otherwise the IEC958 bits won't
1688 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1689 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1690 AC_VERB_SET_DIGI_CONVERT_1,
1692 ~AC_DIG1_ENABLE & 0xff);
1693 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1694 stream_tag, 0, format);
1695 /* turn on again (if needed) */
1696 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1697 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1698 AC_VERB_SET_DIGI_CONVERT_1,
1699 codec->spdif_ctls & 0xff);
1701 mout->dig_out_used = 0;
1702 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1706 mutex_unlock(&codec->spdif_mutex);
1709 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1712 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1713 && !spec->hp_independent_mode)
1714 /* headphone out will just decode front left/right (stereo) */
1715 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1718 /* extra outputs copied from front */
1719 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1720 if (mout->extra_out_nid[i])
1721 snd_hda_codec_setup_stream(codec,
1722 mout->extra_out_nid[i],
1723 stream_tag, 0, format);
1726 for (i = 1; i < mout->num_dacs; i++) {
1727 if (chs >= (i + 1) * 2) /* independent out */
1728 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1730 else /* copy front */
1731 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1736 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1737 struct hda_codec *codec,
1738 unsigned int stream_tag,
1739 unsigned int format,
1740 struct snd_pcm_substream *substream)
1742 struct via_spec *spec = codec->spec;
1743 struct hda_multi_out *mout = &spec->multiout;
1744 hda_nid_t *nids = mout->dac_nids;
1746 if (substream->number == 0)
1747 playback_multi_pcm_prep_0(codec, stream_tag, format,
1750 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1751 spec->hp_independent_mode)
1752 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1753 stream_tag, 0, format);
1755 vt1708_start_hp_work(spec);
1759 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1760 struct hda_codec *codec,
1761 struct snd_pcm_substream *substream)
1763 struct via_spec *spec = codec->spec;
1764 struct hda_multi_out *mout = &spec->multiout;
1765 hda_nid_t *nids = mout->dac_nids;
1768 if (substream->number == 0) {
1769 for (i = 0; i < mout->num_dacs; i++)
1770 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1772 if (mout->hp_nid && !spec->hp_independent_mode)
1773 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1776 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1777 if (mout->extra_out_nid[i])
1778 snd_hda_codec_setup_stream(codec,
1779 mout->extra_out_nid[i],
1781 mutex_lock(&codec->spdif_mutex);
1782 if (mout->dig_out_nid &&
1783 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1784 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1786 mout->dig_out_used = 0;
1788 mutex_unlock(&codec->spdif_mutex);
1790 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1791 spec->hp_independent_mode)
1792 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1795 vt1708_stop_hp_work(spec);
1802 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1803 struct hda_codec *codec,
1804 struct snd_pcm_substream *substream)
1806 struct via_spec *spec = codec->spec;
1807 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1810 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1811 struct hda_codec *codec,
1812 struct snd_pcm_substream *substream)
1814 struct via_spec *spec = codec->spec;
1815 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1818 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1819 struct hda_codec *codec,
1820 unsigned int stream_tag,
1821 unsigned int format,
1822 struct snd_pcm_substream *substream)
1824 struct via_spec *spec = codec->spec;
1825 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1826 stream_tag, format, substream);
1829 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1830 struct hda_codec *codec,
1831 struct snd_pcm_substream *substream)
1833 struct via_spec *spec = codec->spec;
1834 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1841 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1842 struct hda_codec *codec,
1843 unsigned int stream_tag,
1844 unsigned int format,
1845 struct snd_pcm_substream *substream)
1847 struct via_spec *spec = codec->spec;
1849 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1850 stream_tag, 0, format);
1854 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1855 struct hda_codec *codec,
1856 struct snd_pcm_substream *substream)
1858 struct via_spec *spec = codec->spec;
1859 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1863 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1867 .nid = 0x10, /* NID to query formats and rates */
1869 .open = via_playback_pcm_open,
1870 .prepare = via_playback_multi_pcm_prepare,
1871 .cleanup = via_playback_multi_pcm_cleanup
1875 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1879 .nid = 0x10, /* NID to query formats and rates */
1880 /* We got noisy outputs on the right channel on VT1708 when
1881 * 24bit samples are used. Until any workaround is found,
1882 * disable the 24bit format, so far.
1884 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1886 .open = via_playback_pcm_open,
1887 .prepare = via_playback_multi_pcm_prepare,
1888 .cleanup = via_playback_multi_pcm_cleanup
1892 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1896 .nid = 0x15, /* NID to query formats and rates */
1898 .prepare = via_capture_pcm_prepare,
1899 .cleanup = via_capture_pcm_cleanup
1903 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1907 /* NID is set in via_build_pcms */
1909 .open = via_dig_playback_pcm_open,
1910 .close = via_dig_playback_pcm_close,
1911 .prepare = via_dig_playback_pcm_prepare,
1912 .cleanup = via_dig_playback_pcm_cleanup
1916 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1922 static int via_build_controls(struct hda_codec *codec)
1924 struct via_spec *spec = codec->spec;
1925 struct snd_kcontrol *kctl;
1926 struct snd_kcontrol_new *knew;
1929 for (i = 0; i < spec->num_mixers; i++) {
1930 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1935 if (spec->multiout.dig_out_nid) {
1936 err = snd_hda_create_spdif_out_ctls(codec,
1937 spec->multiout.dig_out_nid);
1940 err = snd_hda_create_spdif_share_sw(codec,
1944 spec->multiout.share_spdif = 1;
1946 if (spec->dig_in_nid) {
1947 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1952 /* assign Capture Source enums to NID */
1953 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1954 for (i = 0; kctl && i < kctl->count; i++) {
1955 err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
1960 /* other nid->control mapping */
1961 for (i = 0; i < spec->num_mixers; i++) {
1962 for (knew = spec->mixers[i]; knew->name; knew++) {
1963 if (knew->iface != NID_MAPPING)
1965 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1968 err = snd_hda_add_nid(codec, kctl, 0,
1973 /* init power states */
1974 set_jack_power_state(codec);
1975 analog_low_current_mode(codec, 1);
1977 via_free_kctls(codec); /* no longer needed */
1981 static int via_build_pcms(struct hda_codec *codec)
1983 struct via_spec *spec = codec->spec;
1984 struct hda_pcm *info = spec->pcm_rec;
1986 codec->num_pcms = 1;
1987 codec->pcm_info = info;
1989 info->name = spec->stream_name_analog;
1990 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1991 *(spec->stream_analog_playback);
1992 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1993 spec->multiout.dac_nids[0];
1994 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1995 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1997 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1998 spec->multiout.max_channels;
2000 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2003 info->name = spec->stream_name_digital;
2004 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2005 if (spec->multiout.dig_out_nid) {
2006 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2007 *(spec->stream_digital_playback);
2008 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2009 spec->multiout.dig_out_nid;
2011 if (spec->dig_in_nid) {
2012 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2013 *(spec->stream_digital_capture);
2014 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2022 static void via_free(struct hda_codec *codec)
2024 struct via_spec *spec = codec->spec;
2029 via_free_kctls(codec);
2030 vt1708_stop_hp_work(spec);
2034 /* mute internal speaker if HP is plugged */
2035 static void via_hp_automute(struct hda_codec *codec)
2037 unsigned int present = 0;
2038 struct via_spec *spec = codec->spec;
2040 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2042 if (!spec->hp_independent_mode) {
2043 struct snd_ctl_elem_id id;
2045 snd_hda_codec_amp_stereo(
2046 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2047 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2049 memset(&id, 0, sizeof(id));
2050 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2051 strcpy(id.name, "Front Playback Switch");
2052 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2057 /* mute mono out if HP or Line out is plugged */
2058 static void via_mono_automute(struct hda_codec *codec)
2060 unsigned int hp_present, lineout_present;
2061 struct via_spec *spec = codec->spec;
2063 if (spec->codec_type != VT1716S)
2066 lineout_present = snd_hda_jack_detect(codec,
2067 spec->autocfg.line_out_pins[0]);
2069 /* Mute Mono Out if Line Out is plugged */
2070 if (lineout_present) {
2071 snd_hda_codec_amp_stereo(
2072 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2076 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2078 if (!spec->hp_independent_mode)
2079 snd_hda_codec_amp_stereo(
2080 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2081 hp_present ? HDA_AMP_MUTE : 0);
2084 static void via_gpio_control(struct hda_codec *codec)
2086 unsigned int gpio_data;
2087 unsigned int vol_counter;
2089 unsigned int master_vol;
2091 struct via_spec *spec = codec->spec;
2093 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2094 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2096 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2097 0xF84, 0) & 0x3F0000) >> 16;
2099 vol = vol_counter & 0x1F;
2100 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2101 AC_VERB_GET_AMP_GAIN_MUTE,
2104 if (gpio_data == 0x02) {
2105 /* unmute line out */
2106 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2107 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2109 if (vol_counter & 0x20) {
2110 /* decrease volume */
2111 if (vol > master_vol)
2113 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2117 /* increase volume */
2118 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2120 ((master_vol+vol) > 0x2A) ? 0x2A :
2123 } else if (!(gpio_data & 0x02)) {
2125 snd_hda_codec_amp_stereo(codec,
2126 spec->autocfg.line_out_pins[0],
2127 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2132 /* mute Internal-Speaker if HP is plugged */
2133 static void via_speaker_automute(struct hda_codec *codec)
2135 unsigned int hp_present;
2136 struct via_spec *spec = codec->spec;
2138 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2141 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2143 if (!spec->hp_independent_mode) {
2144 struct snd_ctl_elem_id id;
2145 snd_hda_codec_amp_stereo(
2146 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2147 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2149 memset(&id, 0, sizeof(id));
2150 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2151 strcpy(id.name, "Speaker Playback Switch");
2152 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2157 /* mute line-out and internal speaker if HP is plugged */
2158 static void via_hp_bind_automute(struct hda_codec *codec)
2160 /* use long instead of int below just to avoid an internal compiler
2161 * error with gcc 4.0.x
2163 unsigned long hp_present, present = 0;
2164 struct via_spec *spec = codec->spec;
2167 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2170 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2172 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2174 if (!spec->hp_independent_mode) {
2175 /* Mute Line-Outs */
2176 for (i = 0; i < spec->autocfg.line_outs; i++)
2177 snd_hda_codec_amp_stereo(
2178 codec, spec->autocfg.line_out_pins[i],
2180 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2182 present = hp_present;
2185 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2186 snd_hda_codec_amp_stereo(
2187 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2188 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2192 /* unsolicited event for jack sensing */
2193 static void via_unsol_event(struct hda_codec *codec,
2197 if (res & VIA_HP_EVENT)
2198 via_hp_automute(codec);
2199 if (res & VIA_GPIO_EVENT)
2200 via_gpio_control(codec);
2201 if (res & VIA_JACK_EVENT)
2202 set_jack_power_state(codec);
2203 if (res & VIA_MONO_EVENT)
2204 via_mono_automute(codec);
2205 if (res & VIA_SPEAKER_EVENT)
2206 via_speaker_automute(codec);
2207 if (res & VIA_BIND_HP_EVENT)
2208 via_hp_bind_automute(codec);
2211 static int via_init(struct hda_codec *codec)
2213 struct via_spec *spec = codec->spec;
2215 for (i = 0; i < spec->num_iverbs; i++)
2216 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2218 /* Lydia Add for EAPD enable */
2219 if (!spec->dig_in_nid) { /* No Digital In connection */
2220 if (spec->dig_in_pin) {
2221 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2222 AC_VERB_SET_PIN_WIDGET_CONTROL,
2224 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2225 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2227 } else /* enable SPDIF-input pin */
2228 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2229 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2231 /* assign slave outs */
2232 if (spec->slave_dig_outs[0])
2233 codec->slave_dig_outs = spec->slave_dig_outs;
2238 #ifdef SND_HDA_NEEDS_RESUME
2239 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2241 struct via_spec *spec = codec->spec;
2242 vt1708_stop_hp_work(spec);
2247 #ifdef CONFIG_SND_HDA_POWER_SAVE
2248 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2250 struct via_spec *spec = codec->spec;
2251 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2257 static struct hda_codec_ops via_patch_ops = {
2258 .build_controls = via_build_controls,
2259 .build_pcms = via_build_pcms,
2262 #ifdef SND_HDA_NEEDS_RESUME
2263 .suspend = via_suspend,
2265 #ifdef CONFIG_SND_HDA_POWER_SAVE
2266 .check_power_status = via_check_power_status,
2270 /* fill in the dac_nids table from the parsed pin configuration */
2271 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2272 const struct auto_pin_cfg *cfg)
2277 spec->multiout.num_dacs = cfg->line_outs;
2279 spec->multiout.dac_nids = spec->private_dac_nids;
2281 for (i = 0; i < 4; i++) {
2282 nid = cfg->line_out_pins[i];
2284 /* config dac list */
2286 case AUTO_SEQ_FRONT:
2287 spec->multiout.dac_nids[i] = 0x10;
2289 case AUTO_SEQ_CENLFE:
2290 spec->multiout.dac_nids[i] = 0x12;
2292 case AUTO_SEQ_SURROUND:
2293 spec->multiout.dac_nids[i] = 0x11;
2296 spec->multiout.dac_nids[i] = 0x13;
2305 /* add playback controls from the parsed DAC table */
2306 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2307 const struct auto_pin_cfg *cfg)
2310 static const char * const chname[4] = {
2311 "Front", "Surround", "C/LFE", "Side"
2313 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2316 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2317 nid = cfg->line_out_pins[i];
2322 nid_vol = nid_vols[i];
2324 if (i == AUTO_SEQ_CENLFE) {
2326 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2327 "Center Playback Volume",
2328 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2332 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2333 "LFE Playback Volume",
2334 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2338 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2339 "Center Playback Switch",
2340 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2344 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2345 "LFE Playback Switch",
2346 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2350 } else if (i == AUTO_SEQ_FRONT) {
2351 /* add control to mixer index 0 */
2352 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2353 "Master Front Playback Volume",
2354 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2358 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2359 "Master Front Playback Switch",
2360 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2365 /* add control to PW3 */
2366 sprintf(name, "%s Playback Volume", chname[i]);
2367 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2368 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2372 sprintf(name, "%s Playback Switch", chname[i]);
2373 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2374 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2379 sprintf(name, "%s Playback Volume", chname[i]);
2380 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2381 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2385 sprintf(name, "%s Playback Switch", chname[i]);
2386 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2387 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2397 static void create_hp_imux(struct via_spec *spec)
2400 struct hda_input_mux *imux = &spec->private_imux[1];
2401 static const char * const texts[] = { "OFF", "ON", NULL};
2403 /* for hp mode select */
2404 for (i = 0; texts[i]; i++)
2405 snd_hda_add_imux_item(imux, texts[i], i, NULL);
2407 spec->hp_mux = &spec->private_imux[1];
2410 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2417 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2418 spec->hp_independent_mode_index = 1;
2420 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2421 "Headphone Playback Volume",
2422 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2425 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2426 "Headphone Playback Switch",
2427 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2431 create_hp_imux(spec);
2436 /* create playback/capture controls for input pins */
2437 static int vt_auto_create_analog_input_ctls(struct hda_codec *codec,
2438 const struct auto_pin_cfg *cfg,
2440 hda_nid_t pin_idxs[], int num_idxs)
2442 struct via_spec *spec = codec->spec;
2443 struct hda_input_mux *imux = &spec->private_imux[0];
2444 int i, err, idx, type, type_idx = 0;
2446 /* for internal loopback recording select */
2447 for (idx = 0; idx < num_idxs; idx++) {
2448 if (pin_idxs[idx] == 0xff) {
2449 snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL);
2454 for (i = 0; i < cfg->num_inputs; i++) {
2456 type = cfg->inputs[i].type;
2457 for (idx = 0; idx < num_idxs; idx++)
2458 if (pin_idxs[idx] == cfg->inputs[i].pin)
2460 if (idx >= num_idxs)
2462 if (i > 0 && type == cfg->inputs[i - 1].type)
2466 label = hda_get_autocfg_input_label(codec, cfg, i);
2467 if (spec->codec_type == VT1708S ||
2468 spec->codec_type == VT1702 ||
2469 spec->codec_type == VT1716S)
2470 err = via_new_analog_input(spec, label, type_idx,
2473 err = via_new_analog_input(spec, label, type_idx,
2477 snd_hda_add_imux_item(imux, label, idx, NULL);
2482 /* create playback/capture controls for input pins */
2483 static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec,
2484 const struct auto_pin_cfg *cfg)
2486 static hda_nid_t pin_idxs[] = { 0xff, 0x24, 0x1d, 0x1e, 0x21 };
2487 return vt_auto_create_analog_input_ctls(codec, cfg, 0x17, pin_idxs,
2488 ARRAY_SIZE(pin_idxs));
2491 #ifdef CONFIG_SND_HDA_POWER_SAVE
2492 static struct hda_amp_list vt1708_loopbacks[] = {
2493 { 0x17, HDA_INPUT, 1 },
2494 { 0x17, HDA_INPUT, 2 },
2495 { 0x17, HDA_INPUT, 3 },
2496 { 0x17, HDA_INPUT, 4 },
2501 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2503 unsigned int def_conf;
2504 unsigned char seqassoc;
2506 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2507 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2508 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2509 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2510 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2511 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2512 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2518 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2519 struct snd_ctl_elem_value *ucontrol)
2521 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2522 struct via_spec *spec = codec->spec;
2524 if (spec->codec_type != VT1708)
2526 spec->vt1708_jack_detectect =
2527 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2528 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2532 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2533 struct snd_ctl_elem_value *ucontrol)
2535 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2536 struct via_spec *spec = codec->spec;
2539 if (spec->codec_type != VT1708)
2541 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2542 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2543 == !spec->vt1708_jack_detectect;
2544 if (spec->vt1708_jack_detectect) {
2545 mute_aa_path(codec, 1);
2546 notify_aa_path_ctls(codec);
2551 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2553 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2554 .name = "Jack Detect",
2556 .info = snd_ctl_boolean_mono_info,
2557 .get = vt1708_jack_detectect_get,
2558 .put = vt1708_jack_detectect_put,
2563 static int vt1708_parse_auto_config(struct hda_codec *codec)
2565 struct via_spec *spec = codec->spec;
2568 /* Add HP and CD pin config connect bit re-config action */
2569 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2570 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2572 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2575 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2578 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2579 return 0; /* can't find valid BIOS pin config */
2581 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2584 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2587 err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg);
2590 /* add jack detect on/off control */
2591 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2595 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2597 if (spec->autocfg.dig_outs)
2598 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2599 spec->dig_in_pin = VT1708_DIGIN_PIN;
2600 if (spec->autocfg.dig_in_pin)
2601 spec->dig_in_nid = VT1708_DIGIN_NID;
2603 if (spec->kctls.list)
2604 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2606 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2608 spec->input_mux = &spec->private_imux[0];
2611 via_hp_build(codec);
2613 via_smart51_build(spec);
2617 /* init callback for auto-configuration model -- overriding the default init */
2618 static int via_auto_init(struct hda_codec *codec)
2620 struct via_spec *spec = codec->spec;
2623 via_auto_init_multi_out(codec);
2624 via_auto_init_hp_out(codec);
2625 via_auto_init_analog_input(codec);
2626 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2627 via_hp_bind_automute(codec);
2629 via_hp_automute(codec);
2630 via_speaker_automute(codec);
2636 static void vt1708_update_hp_jack_state(struct work_struct *work)
2638 struct via_spec *spec = container_of(work, struct via_spec,
2639 vt1708_hp_work.work);
2640 if (spec->codec_type != VT1708)
2642 /* if jack state toggled */
2643 if (spec->vt1708_hp_present
2644 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2645 spec->vt1708_hp_present ^= 1;
2646 via_hp_automute(spec->codec);
2648 vt1708_start_hp_work(spec);
2651 static int get_mux_nids(struct hda_codec *codec)
2653 struct via_spec *spec = codec->spec;
2654 hda_nid_t nid, conn[8];
2658 for (i = 0; i < spec->num_adc_nids; i++) {
2659 nid = spec->adc_nids[i];
2661 type = get_wcaps_type(get_wcaps(codec, nid));
2662 if (type == AC_WID_PIN)
2664 n = snd_hda_get_connections(codec, nid, conn,
2669 spec->mux_nids[i] = nid;
2678 static int patch_vt1708(struct hda_codec *codec)
2680 struct via_spec *spec;
2683 /* create a codec specific record */
2684 spec = via_new_spec(codec);
2688 /* automatic parse from the BIOS config */
2689 err = vt1708_parse_auto_config(codec);
2694 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2695 "from BIOS. Using genenic mode...\n");
2699 spec->stream_name_analog = "VT1708 Analog";
2700 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2701 /* disable 32bit format on VT1708 */
2702 if (codec->vendor_id == 0x11061708)
2703 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2704 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2706 spec->stream_name_digital = "VT1708 Digital";
2707 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2708 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2711 if (!spec->adc_nids && spec->input_mux) {
2712 spec->adc_nids = vt1708_adc_nids;
2713 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2714 get_mux_nids(codec);
2715 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2719 codec->patch_ops = via_patch_ops;
2721 codec->patch_ops.init = via_auto_init;
2722 #ifdef CONFIG_SND_HDA_POWER_SAVE
2723 spec->loopback.amplist = vt1708_loopbacks;
2725 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2729 /* capture mixer elements */
2730 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2731 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2732 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2733 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2734 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2735 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2736 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2738 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2739 /* The multiple "Capture Source" controls confuse alsamixer
2740 * So call somewhat different..
2742 /* .name = "Capture Source", */
2743 .name = "Input Source",
2745 .info = via_mux_enum_info,
2746 .get = via_mux_enum_get,
2747 .put = via_mux_enum_put,
2752 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2753 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2754 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2759 * generic initialization of ADC, input mixers and output mixers
2761 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2763 * Unmute ADC0-2 and set the default input to mic-in
2765 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2766 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2767 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2770 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2773 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2774 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2775 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2776 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2777 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2778 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2781 * Set up output selector (0x1a, 0x1b, 0x29)
2783 /* set vol=0 to output mixers */
2784 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2785 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2786 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2789 * Unmute PW3 and PW4
2791 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2792 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2794 /* Set input of PW4 as MW0 */
2795 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2796 /* PW9 Output enable */
2797 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2801 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2805 .nid = 0x10, /* NID to query formats and rates */
2807 .open = via_playback_pcm_open,
2808 .prepare = via_playback_multi_pcm_prepare,
2809 .cleanup = via_playback_multi_pcm_cleanup,
2813 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2817 .nid = 0x10, /* NID to query formats and rates */
2819 .open = via_playback_pcm_open,
2820 .prepare = via_playback_multi_pcm_prepare,
2821 .cleanup = via_playback_multi_pcm_cleanup,
2825 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2829 .nid = 0x14, /* NID to query formats and rates */
2831 .prepare = via_capture_pcm_prepare,
2832 .cleanup = via_capture_pcm_cleanup
2836 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2840 /* NID is set in via_build_pcms */
2842 .open = via_dig_playback_pcm_open,
2843 .close = via_dig_playback_pcm_close
2847 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2853 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2854 const struct auto_pin_cfg *cfg)
2859 if (cfg->line_outs == 4) /* 10 channels */
2860 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2861 else if (cfg->line_outs == 3) /* 6 channels */
2862 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2864 spec->multiout.dac_nids = spec->private_dac_nids;
2866 if (cfg->line_outs == 4) { /* 10 channels */
2867 for (i = 0; i < cfg->line_outs; i++) {
2868 nid = cfg->line_out_pins[i];
2870 /* config dac list */
2872 case AUTO_SEQ_FRONT:
2874 spec->multiout.dac_nids[i] = 0x10;
2876 case AUTO_SEQ_CENLFE:
2878 spec->multiout.dac_nids[i] = 0x12;
2880 case AUTO_SEQ_SURROUND:
2882 spec->multiout.dac_nids[i] = 0x11;
2886 spec->multiout.dac_nids[i] = 0x27;
2893 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2895 } else if (cfg->line_outs == 3) { /* 6 channels */
2896 for (i = 0; i < cfg->line_outs; i++) {
2897 nid = cfg->line_out_pins[i];
2899 /* config dac list */
2901 case AUTO_SEQ_FRONT:
2903 spec->multiout.dac_nids[i] = 0x10;
2905 case AUTO_SEQ_CENLFE:
2907 spec->multiout.dac_nids[i] = 0x12;
2909 case AUTO_SEQ_SURROUND:
2911 spec->multiout.dac_nids[i] = 0x11;
2923 /* add playback controls from the parsed DAC table */
2924 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2925 const struct auto_pin_cfg *cfg)
2928 static const char * const chname[4] = {
2929 "Front", "Surround", "C/LFE", "Side"
2931 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2934 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2935 nid = cfg->line_out_pins[i];
2940 nid_vol = nid_vols[i];
2942 if (i == AUTO_SEQ_CENLFE) {
2944 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2945 "Center Playback Volume",
2946 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2950 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2951 "LFE Playback Volume",
2952 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2956 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2957 "Center Playback Switch",
2958 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2962 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2963 "LFE Playback Switch",
2964 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2968 } else if (i == AUTO_SEQ_FRONT) {
2969 /* ADD control to mixer index 0 */
2970 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2971 "Master Front Playback Volume",
2972 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2976 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2977 "Master Front Playback Switch",
2978 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2983 /* add control to PW3 */
2984 sprintf(name, "%s Playback Volume", chname[i]);
2985 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2986 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2990 sprintf(name, "%s Playback Switch", chname[i]);
2991 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2992 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2996 } else if (i == AUTO_SEQ_SURROUND) {
2997 sprintf(name, "%s Playback Volume", chname[i]);
2998 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2999 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3003 sprintf(name, "%s Playback Switch", chname[i]);
3004 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3005 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3009 } else if (i == AUTO_SEQ_SIDE) {
3010 sprintf(name, "%s Playback Volume", chname[i]);
3011 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3012 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3016 sprintf(name, "%s Playback Switch", chname[i]);
3017 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3018 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3028 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3035 if (spec->multiout.num_dacs == 5) /* 10 channels */
3036 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
3037 else if (spec->multiout.num_dacs == 3) /* 6 channels */
3038 spec->multiout.hp_nid = 0;
3039 spec->hp_independent_mode_index = 1;
3041 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3042 "Headphone Playback Volume",
3043 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3046 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3047 "Headphone Playback Switch",
3048 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3055 /* create playback/capture controls for input pins */
3056 static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec,
3057 const struct auto_pin_cfg *cfg)
3059 static hda_nid_t pin_idxs[] = { 0xff, 0x23, 0x1d, 0x1e, 0x21 };
3060 return vt_auto_create_analog_input_ctls(codec, cfg, 0x18, pin_idxs,
3061 ARRAY_SIZE(pin_idxs));
3064 static int vt1709_parse_auto_config(struct hda_codec *codec)
3066 struct via_spec *spec = codec->spec;
3069 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3072 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3075 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3076 return 0; /* can't find valid BIOS pin config */
3078 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3081 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3084 err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg);
3088 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3090 if (spec->autocfg.dig_outs)
3091 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3092 spec->dig_in_pin = VT1709_DIGIN_PIN;
3093 if (spec->autocfg.dig_in_pin)
3094 spec->dig_in_nid = VT1709_DIGIN_NID;
3096 if (spec->kctls.list)
3097 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3099 spec->input_mux = &spec->private_imux[0];
3102 via_hp_build(codec);
3104 via_smart51_build(spec);
3108 #ifdef CONFIG_SND_HDA_POWER_SAVE
3109 static struct hda_amp_list vt1709_loopbacks[] = {
3110 { 0x18, HDA_INPUT, 1 },
3111 { 0x18, HDA_INPUT, 2 },
3112 { 0x18, HDA_INPUT, 3 },
3113 { 0x18, HDA_INPUT, 4 },
3118 static int patch_vt1709_10ch(struct hda_codec *codec)
3120 struct via_spec *spec;
3123 /* create a codec specific record */
3124 spec = via_new_spec(codec);
3128 err = vt1709_parse_auto_config(codec);
3133 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3134 "Using genenic mode...\n");
3137 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3138 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3140 spec->stream_name_analog = "VT1709 Analog";
3141 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3142 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3144 spec->stream_name_digital = "VT1709 Digital";
3145 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3146 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3149 if (!spec->adc_nids && spec->input_mux) {
3150 spec->adc_nids = vt1709_adc_nids;
3151 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3152 get_mux_nids(codec);
3153 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3157 codec->patch_ops = via_patch_ops;
3159 codec->patch_ops.init = via_auto_init;
3160 codec->patch_ops.unsol_event = via_unsol_event;
3161 #ifdef CONFIG_SND_HDA_POWER_SAVE
3162 spec->loopback.amplist = vt1709_loopbacks;
3168 * generic initialization of ADC, input mixers and output mixers
3170 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3172 * Unmute ADC0-2 and set the default input to mic-in
3174 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3175 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3176 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3179 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3182 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3183 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3184 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3185 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3186 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3187 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3190 * Set up output selector (0x1a, 0x1b, 0x29)
3192 /* set vol=0 to output mixers */
3193 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3194 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3195 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3198 * Unmute PW3 and PW4
3200 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3201 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3203 /* Set input of PW4 as MW0 */
3204 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3205 /* PW9 Output enable */
3206 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3210 static int patch_vt1709_6ch(struct hda_codec *codec)
3212 struct via_spec *spec;
3215 /* create a codec specific record */
3216 spec = via_new_spec(codec);
3220 err = vt1709_parse_auto_config(codec);
3225 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3226 "Using genenic mode...\n");
3229 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3230 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3232 spec->stream_name_analog = "VT1709 Analog";
3233 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3234 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3236 spec->stream_name_digital = "VT1709 Digital";
3237 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3238 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3241 if (!spec->adc_nids && spec->input_mux) {
3242 spec->adc_nids = vt1709_adc_nids;
3243 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3244 get_mux_nids(codec);
3245 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3249 codec->patch_ops = via_patch_ops;
3251 codec->patch_ops.init = via_auto_init;
3252 codec->patch_ops.unsol_event = via_unsol_event;
3253 #ifdef CONFIG_SND_HDA_POWER_SAVE
3254 spec->loopback.amplist = vt1709_loopbacks;
3259 /* capture mixer elements */
3260 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3261 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3262 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3263 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3264 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3266 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3267 /* The multiple "Capture Source" controls confuse alsamixer
3268 * So call somewhat different..
3270 /* .name = "Capture Source", */
3271 .name = "Input Source",
3273 .info = via_mux_enum_info,
3274 .get = via_mux_enum_get,
3275 .put = via_mux_enum_put,
3280 * generic initialization of ADC, input mixers and output mixers
3282 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3284 * Unmute ADC0-1 and set the default input to mic-in
3286 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3287 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3290 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3293 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3294 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3295 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3296 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3297 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3298 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3301 * Set up output mixers
3303 /* set vol=0 to output mixers */
3304 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3305 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3306 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3308 /* Setup default input to PW4 */
3309 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3310 /* PW9 Output enable */
3311 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3312 /* PW10 Input enable */
3313 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3317 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3319 * Unmute ADC0-1 and set the default input to mic-in
3321 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3322 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3325 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3328 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3329 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3330 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3331 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3332 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3333 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3336 * Set up output mixers
3338 /* set vol=0 to output mixers */
3339 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3340 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3341 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3343 /* Setup default input of PW4 to MW0 */
3344 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3345 /* PW9 Output enable */
3346 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3347 /* PW10 Input enable */
3348 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3352 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3353 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3354 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3355 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3356 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3357 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3358 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3359 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3360 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3361 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3365 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3366 struct hda_codec *codec,
3367 struct snd_pcm_substream *substream)
3369 int idle = substream->pstr->substream_opened == 1
3370 && substream->ref_count == 0;
3372 analog_low_current_mode(codec, idle);
3376 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3380 .nid = 0x10, /* NID to query formats and rates */
3382 .open = via_playback_pcm_open,
3383 .prepare = via_playback_multi_pcm_prepare,
3384 .cleanup = via_playback_multi_pcm_cleanup,
3385 .close = via_pcm_open_close
3389 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3393 .nid = 0x10, /* NID to query formats and rates */
3395 .open = via_playback_pcm_open,
3396 .prepare = via_playback_multi_pcm_prepare,
3397 .cleanup = via_playback_multi_pcm_cleanup
3401 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3405 .nid = 0x13, /* NID to query formats and rates */
3407 .open = via_pcm_open_close,
3408 .prepare = via_capture_pcm_prepare,
3409 .cleanup = via_capture_pcm_cleanup,
3410 .close = via_pcm_open_close
3414 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3418 /* NID is set in via_build_pcms */
3420 .open = via_dig_playback_pcm_open,
3421 .close = via_dig_playback_pcm_close,
3422 .prepare = via_dig_playback_pcm_prepare,
3423 .cleanup = via_dig_playback_pcm_cleanup
3427 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3433 /* fill in the dac_nids table from the parsed pin configuration */
3434 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3435 const struct auto_pin_cfg *cfg)
3440 spec->multiout.num_dacs = cfg->line_outs;
3442 spec->multiout.dac_nids = spec->private_dac_nids;
3444 for (i = 0; i < 4; i++) {
3445 nid = cfg->line_out_pins[i];
3447 /* config dac list */
3449 case AUTO_SEQ_FRONT:
3450 spec->multiout.dac_nids[i] = 0x10;
3452 case AUTO_SEQ_CENLFE:
3453 spec->multiout.dac_nids[i] = 0x24;
3455 case AUTO_SEQ_SURROUND:
3456 spec->multiout.dac_nids[i] = 0x11;
3459 spec->multiout.dac_nids[i] = 0x25;
3468 /* add playback controls from the parsed DAC table */
3469 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3470 const struct auto_pin_cfg *cfg)
3473 static const char * const chname[4] = {
3474 "Front", "Surround", "C/LFE", "Side"
3476 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3477 hda_nid_t nid, nid_vol = 0;
3480 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3481 nid = cfg->line_out_pins[i];
3486 nid_vol = nid_vols[i];
3488 if (i == AUTO_SEQ_CENLFE) {
3490 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3491 "Center Playback Volume",
3492 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3496 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3497 "LFE Playback Volume",
3498 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3502 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3503 "Center Playback Switch",
3504 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3508 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3509 "LFE Playback Switch",
3510 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3514 } else if (i == AUTO_SEQ_FRONT) {
3515 /* add control to mixer index 0 */
3516 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3517 "Master Front Playback Volume",
3518 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3522 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3523 "Master Front Playback Switch",
3524 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3529 /* add control to PW3 */
3530 sprintf(name, "%s Playback Volume", chname[i]);
3531 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3532 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3536 sprintf(name, "%s Playback Switch", chname[i]);
3537 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3538 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3543 sprintf(name, "%s Playback Volume", chname[i]);
3544 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3545 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3549 sprintf(name, "%s Playback Switch", chname[i]);
3550 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3551 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3561 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3568 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3569 spec->hp_independent_mode_index = 1;
3571 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3572 "Headphone Playback Volume",
3573 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3576 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3577 "Headphone Playback Switch",
3578 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3582 create_hp_imux(spec);
3587 /* create playback/capture controls for input pins */
3588 static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec,
3589 const struct auto_pin_cfg *cfg)
3591 static hda_nid_t pin_idxs[] = { 0xff, 0x1f, 0x1a, 0x1b, 0x1e };
3592 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
3593 ARRAY_SIZE(pin_idxs));
3596 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3598 struct via_spec *spec = codec->spec;
3601 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3604 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3607 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3608 return 0; /* can't find valid BIOS pin config */
3610 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3613 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3616 err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg);
3620 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3622 if (spec->autocfg.dig_outs)
3623 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3624 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3625 if (spec->autocfg.dig_in_pin)
3626 spec->dig_in_nid = VT1708B_DIGIN_NID;
3628 if (spec->kctls.list)
3629 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3631 spec->input_mux = &spec->private_imux[0];
3634 via_hp_build(codec);
3636 via_smart51_build(spec);
3640 #ifdef CONFIG_SND_HDA_POWER_SAVE
3641 static struct hda_amp_list vt1708B_loopbacks[] = {
3642 { 0x16, HDA_INPUT, 1 },
3643 { 0x16, HDA_INPUT, 2 },
3644 { 0x16, HDA_INPUT, 3 },
3645 { 0x16, HDA_INPUT, 4 },
3649 static int patch_vt1708S(struct hda_codec *codec);
3650 static int patch_vt1708B_8ch(struct hda_codec *codec)
3652 struct via_spec *spec;
3655 if (get_codec_type(codec) == VT1708BCE)
3656 return patch_vt1708S(codec);
3657 /* create a codec specific record */
3658 spec = via_new_spec(codec);
3662 /* automatic parse from the BIOS config */
3663 err = vt1708B_parse_auto_config(codec);
3668 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3669 "from BIOS. Using genenic mode...\n");
3672 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3673 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3675 spec->stream_name_analog = "VT1708B Analog";
3676 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3677 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3679 spec->stream_name_digital = "VT1708B Digital";
3680 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3681 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3683 if (!spec->adc_nids && spec->input_mux) {
3684 spec->adc_nids = vt1708B_adc_nids;
3685 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3686 get_mux_nids(codec);
3687 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3691 codec->patch_ops = via_patch_ops;
3693 codec->patch_ops.init = via_auto_init;
3694 codec->patch_ops.unsol_event = via_unsol_event;
3695 #ifdef CONFIG_SND_HDA_POWER_SAVE
3696 spec->loopback.amplist = vt1708B_loopbacks;
3702 static int patch_vt1708B_4ch(struct hda_codec *codec)
3704 struct via_spec *spec;
3707 /* create a codec specific record */
3708 spec = via_new_spec(codec);
3712 /* automatic parse from the BIOS config */
3713 err = vt1708B_parse_auto_config(codec);
3718 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3719 "from BIOS. Using genenic mode...\n");
3722 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3723 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3725 spec->stream_name_analog = "VT1708B Analog";
3726 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3727 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3729 spec->stream_name_digital = "VT1708B Digital";
3730 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3731 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3733 if (!spec->adc_nids && spec->input_mux) {
3734 spec->adc_nids = vt1708B_adc_nids;
3735 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3736 get_mux_nids(codec);
3737 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3741 codec->patch_ops = via_patch_ops;
3743 codec->patch_ops.init = via_auto_init;
3744 codec->patch_ops.unsol_event = via_unsol_event;
3745 #ifdef CONFIG_SND_HDA_POWER_SAVE
3746 spec->loopback.amplist = vt1708B_loopbacks;
3752 /* Patch for VT1708S */
3754 /* capture mixer elements */
3755 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3756 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3757 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3758 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3759 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3760 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3761 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3765 /* The multiple "Capture Source" controls confuse alsamixer
3766 * So call somewhat different..
3768 /* .name = "Capture Source", */
3769 .name = "Input Source",
3771 .info = via_mux_enum_info,
3772 .get = via_mux_enum_get,
3773 .put = via_mux_enum_put,
3778 static struct hda_verb vt1708S_volume_init_verbs[] = {
3779 /* Unmute ADC0-1 and set the default input to mic-in */
3780 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3781 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3783 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3784 * analog-loopback mixer widget */
3785 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3786 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3787 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3788 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3789 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3790 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3792 /* Setup default input of PW4 to MW0 */
3793 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3794 /* PW9, PW10 Output enable */
3795 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3796 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3797 /* Enable Mic Boost Volume backdoor */
3799 /* don't bybass mixer */
3804 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3805 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3806 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3807 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3808 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3809 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3810 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3811 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3812 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3813 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3817 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3821 .nid = 0x10, /* NID to query formats and rates */
3823 .open = via_playback_pcm_open,
3824 .prepare = via_playback_multi_pcm_prepare,
3825 .cleanup = via_playback_multi_pcm_cleanup,
3826 .close = via_pcm_open_close
3830 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3834 .nid = 0x13, /* NID to query formats and rates */
3836 .open = via_pcm_open_close,
3837 .prepare = via_capture_pcm_prepare,
3838 .cleanup = via_capture_pcm_cleanup,
3839 .close = via_pcm_open_close
3843 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3847 /* NID is set in via_build_pcms */
3849 .open = via_dig_playback_pcm_open,
3850 .close = via_dig_playback_pcm_close,
3851 .prepare = via_dig_playback_pcm_prepare,
3852 .cleanup = via_dig_playback_pcm_cleanup
3856 /* fill in the dac_nids table from the parsed pin configuration */
3857 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3858 const struct auto_pin_cfg *cfg)
3863 spec->multiout.num_dacs = cfg->line_outs;
3865 spec->multiout.dac_nids = spec->private_dac_nids;
3867 for (i = 0; i < 4; i++) {
3868 nid = cfg->line_out_pins[i];
3870 /* config dac list */
3872 case AUTO_SEQ_FRONT:
3873 spec->multiout.dac_nids[i] = 0x10;
3875 case AUTO_SEQ_CENLFE:
3876 spec->multiout.dac_nids[i] = 0x24;
3878 case AUTO_SEQ_SURROUND:
3879 spec->multiout.dac_nids[i] = 0x11;
3882 spec->multiout.dac_nids[i] = 0x25;
3888 /* for Smart 5.1, line/mic inputs double as output pins */
3889 if (cfg->line_outs == 1) {
3890 spec->multiout.num_dacs = 3;
3891 spec->multiout.dac_nids[AUTO_SEQ_SURROUND] = 0x11;
3892 spec->multiout.dac_nids[AUTO_SEQ_CENLFE] = 0x24;
3898 /* add playback controls from the parsed DAC table */
3899 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3900 const struct auto_pin_cfg *cfg)
3903 static const char * const chname[4] = {
3904 "Front", "Surround", "C/LFE", "Side"
3906 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3907 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3908 hda_nid_t nid, nid_vol, nid_mute;
3911 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3912 nid = cfg->line_out_pins[i];
3914 /* for Smart 5.1, there are always at least six channels */
3915 if (!nid && i > AUTO_SEQ_CENLFE)
3918 nid_vol = nid_vols[i];
3919 nid_mute = nid_mutes[i];
3921 if (i == AUTO_SEQ_CENLFE) {
3923 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3924 "Center Playback Volume",
3925 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3929 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3930 "LFE Playback Volume",
3931 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3935 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3936 "Center Playback Switch",
3937 HDA_COMPOSE_AMP_VAL(nid_mute,
3942 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3943 "LFE Playback Switch",
3944 HDA_COMPOSE_AMP_VAL(nid_mute,
3949 } else if (i == AUTO_SEQ_FRONT) {
3950 /* add control to mixer index 0 */
3951 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3952 "Master Front Playback Volume",
3953 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3957 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3958 "Master Front Playback Switch",
3959 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3965 sprintf(name, "%s Playback Volume", chname[i]);
3966 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3967 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3971 sprintf(name, "%s Playback Switch", chname[i]);
3972 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3973 HDA_COMPOSE_AMP_VAL(nid_mute,
3979 sprintf(name, "%s Playback Volume", chname[i]);
3980 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3981 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3985 sprintf(name, "%s Playback Switch", chname[i]);
3986 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3987 HDA_COMPOSE_AMP_VAL(nid_mute,
3998 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4005 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
4006 spec->hp_independent_mode_index = 1;
4008 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4009 "Headphone Playback Volume",
4010 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
4014 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4015 "Headphone Playback Switch",
4016 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4020 create_hp_imux(spec);
4025 /* create playback/capture controls for input pins */
4026 static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec,
4027 const struct auto_pin_cfg *cfg)
4029 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
4030 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
4031 ARRAY_SIZE(pin_idxs));
4034 /* fill out digital output widgets; one for master and one for slave outputs */
4035 static void fill_dig_outs(struct hda_codec *codec)
4037 struct via_spec *spec = codec->spec;
4040 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4044 nid = spec->autocfg.dig_out_pins[i];
4047 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4050 if (!spec->multiout.dig_out_nid)
4051 spec->multiout.dig_out_nid = nid;
4053 spec->slave_dig_outs[0] = nid;
4054 break; /* at most two dig outs */
4059 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4061 struct via_spec *spec = codec->spec;
4064 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4067 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4070 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4071 return 0; /* can't find valid BIOS pin config */
4073 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4076 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4079 err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4083 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4085 fill_dig_outs(codec);
4087 if (spec->kctls.list)
4088 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4090 spec->input_mux = &spec->private_imux[0];
4093 via_hp_build(codec);
4095 via_smart51_build(spec);
4099 #ifdef CONFIG_SND_HDA_POWER_SAVE
4100 static struct hda_amp_list vt1708S_loopbacks[] = {
4101 { 0x16, HDA_INPUT, 1 },
4102 { 0x16, HDA_INPUT, 2 },
4103 { 0x16, HDA_INPUT, 3 },
4104 { 0x16, HDA_INPUT, 4 },
4109 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4110 int offset, int num_steps, int step_size)
4112 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4113 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4114 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4115 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4116 (0 << AC_AMPCAP_MUTE_SHIFT));
4119 static int patch_vt1708S(struct hda_codec *codec)
4121 struct via_spec *spec;
4124 /* create a codec specific record */
4125 spec = via_new_spec(codec);
4129 /* automatic parse from the BIOS config */
4130 err = vt1708S_parse_auto_config(codec);
4135 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4136 "from BIOS. Using genenic mode...\n");
4139 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4140 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4142 if (codec->vendor_id == 0x11060440)
4143 spec->stream_name_analog = "VT1818S Analog";
4145 spec->stream_name_analog = "VT1708S Analog";
4146 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4147 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4149 if (codec->vendor_id == 0x11060440)
4150 spec->stream_name_digital = "VT1818S Digital";
4152 spec->stream_name_digital = "VT1708S Digital";
4153 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4155 if (!spec->adc_nids && spec->input_mux) {
4156 spec->adc_nids = vt1708S_adc_nids;
4157 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4158 get_mux_nids(codec);
4159 override_mic_boost(codec, 0x1a, 0, 3, 40);
4160 override_mic_boost(codec, 0x1e, 0, 3, 40);
4161 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4165 codec->patch_ops = via_patch_ops;
4167 codec->patch_ops.init = via_auto_init;
4168 codec->patch_ops.unsol_event = via_unsol_event;
4169 #ifdef CONFIG_SND_HDA_POWER_SAVE
4170 spec->loopback.amplist = vt1708S_loopbacks;
4173 /* correct names for VT1708BCE */
4174 if (get_codec_type(codec) == VT1708BCE) {
4175 kfree(codec->chip_name);
4176 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4177 snprintf(codec->bus->card->mixername,
4178 sizeof(codec->bus->card->mixername),
4179 "%s %s", codec->vendor_name, codec->chip_name);
4180 spec->stream_name_analog = "VT1708BCE Analog";
4181 spec->stream_name_digital = "VT1708BCE Digital";
4183 /* correct names for VT1818S */
4184 if (codec->vendor_id == 0x11060440) {
4185 spec->stream_name_analog = "VT1818S Analog";
4186 spec->stream_name_digital = "VT1818S Digital";
4191 /* Patch for VT1702 */
4193 /* capture mixer elements */
4194 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4195 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4196 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4197 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4198 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4199 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4200 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4201 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4204 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4205 /* The multiple "Capture Source" controls confuse alsamixer
4206 * So call somewhat different..
4208 /* .name = "Capture Source", */
4209 .name = "Input Source",
4211 .info = via_mux_enum_info,
4212 .get = via_mux_enum_get,
4213 .put = via_mux_enum_put,
4218 static struct hda_verb vt1702_volume_init_verbs[] = {
4220 * Unmute ADC0-1 and set the default input to mic-in
4222 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4223 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4224 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4227 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4230 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4231 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4232 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4233 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4234 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4235 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4237 /* Setup default input of PW4 to MW0 */
4238 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4239 /* PW6 PW7 Output enable */
4240 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4241 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4249 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4250 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4251 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4252 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4253 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4254 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4255 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4259 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4263 .nid = 0x10, /* NID to query formats and rates */
4265 .open = via_playback_pcm_open,
4266 .prepare = via_playback_multi_pcm_prepare,
4267 .cleanup = via_playback_multi_pcm_cleanup,
4268 .close = via_pcm_open_close
4272 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4276 .nid = 0x12, /* NID to query formats and rates */
4278 .open = via_pcm_open_close,
4279 .prepare = via_capture_pcm_prepare,
4280 .cleanup = via_capture_pcm_cleanup,
4281 .close = via_pcm_open_close
4285 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4289 /* NID is set in via_build_pcms */
4291 .open = via_dig_playback_pcm_open,
4292 .close = via_dig_playback_pcm_close,
4293 .prepare = via_dig_playback_pcm_prepare,
4294 .cleanup = via_dig_playback_pcm_cleanup
4298 /* fill in the dac_nids table from the parsed pin configuration */
4299 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4300 const struct auto_pin_cfg *cfg)
4302 spec->multiout.num_dacs = 1;
4303 spec->multiout.dac_nids = spec->private_dac_nids;
4305 if (cfg->line_out_pins[0]) {
4306 /* config dac list */
4307 spec->multiout.dac_nids[0] = 0x10;
4313 /* add playback controls from the parsed DAC table */
4314 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4315 const struct auto_pin_cfg *cfg)
4319 if (!cfg->line_out_pins[0])
4322 /* add control to mixer index 0 */
4323 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4324 "Master Front Playback Volume",
4325 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4328 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4329 "Master Front Playback Switch",
4330 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4335 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4336 "Front Playback Volume",
4337 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4340 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4341 "Front Playback Switch",
4342 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4349 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4352 struct hda_input_mux *imux;
4353 static const char * const texts[] = { "ON", "OFF", NULL};
4356 spec->multiout.hp_nid = 0x1D;
4357 spec->hp_independent_mode_index = 0;
4359 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4360 "Headphone Playback Volume",
4361 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4365 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4366 "Headphone Playback Switch",
4367 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4371 imux = &spec->private_imux[1];
4373 /* for hp mode select */
4374 for (i = 0; texts[i]; i++)
4375 snd_hda_add_imux_item(imux, texts[i], i, NULL);
4377 spec->hp_mux = &spec->private_imux[1];
4381 /* create playback/capture controls for input pins */
4382 static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec,
4383 const struct auto_pin_cfg *cfg)
4385 static hda_nid_t pin_idxs[] = { 0x14, 0x15, 0x18, 0xff };
4386 return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a, pin_idxs,
4387 ARRAY_SIZE(pin_idxs));
4390 static int vt1702_parse_auto_config(struct hda_codec *codec)
4392 struct via_spec *spec = codec->spec;
4395 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4398 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4401 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4402 return 0; /* can't find valid BIOS pin config */
4404 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4407 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4410 /* limit AA path volume to 0 dB */
4411 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4412 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4413 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4414 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4415 (1 << AC_AMPCAP_MUTE_SHIFT));
4416 err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg);
4420 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4422 fill_dig_outs(codec);
4424 if (spec->kctls.list)
4425 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4427 spec->input_mux = &spec->private_imux[0];
4430 via_hp_build(codec);
4435 #ifdef CONFIG_SND_HDA_POWER_SAVE
4436 static struct hda_amp_list vt1702_loopbacks[] = {
4437 { 0x1A, HDA_INPUT, 1 },
4438 { 0x1A, HDA_INPUT, 2 },
4439 { 0x1A, HDA_INPUT, 3 },
4440 { 0x1A, HDA_INPUT, 4 },
4445 static int patch_vt1702(struct hda_codec *codec)
4447 struct via_spec *spec;
4450 /* create a codec specific record */
4451 spec = via_new_spec(codec);
4455 /* automatic parse from the BIOS config */
4456 err = vt1702_parse_auto_config(codec);
4461 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4462 "from BIOS. Using genenic mode...\n");
4465 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4466 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4468 spec->stream_name_analog = "VT1702 Analog";
4469 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4470 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4472 spec->stream_name_digital = "VT1702 Digital";
4473 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4475 if (!spec->adc_nids && spec->input_mux) {
4476 spec->adc_nids = vt1702_adc_nids;
4477 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4478 get_mux_nids(codec);
4479 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4483 codec->patch_ops = via_patch_ops;
4485 codec->patch_ops.init = via_auto_init;
4486 codec->patch_ops.unsol_event = via_unsol_event;
4487 #ifdef CONFIG_SND_HDA_POWER_SAVE
4488 spec->loopback.amplist = vt1702_loopbacks;
4494 /* Patch for VT1718S */
4496 /* capture mixer elements */
4497 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4498 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4499 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4500 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4501 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4502 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4503 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4506 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4507 /* The multiple "Capture Source" controls confuse alsamixer
4508 * So call somewhat different..
4510 .name = "Input Source",
4512 .info = via_mux_enum_info,
4513 .get = via_mux_enum_get,
4514 .put = via_mux_enum_put,
4519 static struct hda_verb vt1718S_volume_init_verbs[] = {
4521 * Unmute ADC0-1 and set the default input to mic-in
4523 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4524 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4527 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4530 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4531 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4532 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4533 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4534 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4535 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4537 /* Setup default input of Front HP to MW9 */
4538 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4539 /* PW9 PW10 Output enable */
4540 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4541 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4542 /* PW11 Input enable */
4543 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4544 /* Enable Boost Volume backdoor */
4546 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4547 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4548 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4549 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4550 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4551 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4552 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4553 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4554 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4555 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4556 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4557 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4558 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4559 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4560 /* Unmute MW4's index 0 */
4561 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4566 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4567 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4568 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4569 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4570 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4571 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4572 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4573 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4574 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4575 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4579 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4583 .nid = 0x8, /* NID to query formats and rates */
4585 .open = via_playback_pcm_open,
4586 .prepare = via_playback_multi_pcm_prepare,
4587 .cleanup = via_playback_multi_pcm_cleanup,
4588 .close = via_pcm_open_close,
4592 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4596 .nid = 0x10, /* NID to query formats and rates */
4598 .open = via_pcm_open_close,
4599 .prepare = via_capture_pcm_prepare,
4600 .cleanup = via_capture_pcm_cleanup,
4601 .close = via_pcm_open_close,
4605 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4609 /* NID is set in via_build_pcms */
4611 .open = via_dig_playback_pcm_open,
4612 .close = via_dig_playback_pcm_close,
4613 .prepare = via_dig_playback_pcm_prepare,
4614 .cleanup = via_dig_playback_pcm_cleanup
4618 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4624 /* fill in the dac_nids table from the parsed pin configuration */
4625 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4626 const struct auto_pin_cfg *cfg)
4631 spec->multiout.num_dacs = cfg->line_outs;
4633 spec->multiout.dac_nids = spec->private_dac_nids;
4635 for (i = 0; i < 4; i++) {
4636 nid = cfg->line_out_pins[i];
4638 /* config dac list */
4640 case AUTO_SEQ_FRONT:
4641 spec->multiout.dac_nids[i] = 0x8;
4643 case AUTO_SEQ_CENLFE:
4644 spec->multiout.dac_nids[i] = 0xa;
4646 case AUTO_SEQ_SURROUND:
4647 spec->multiout.dac_nids[i] = 0x9;
4650 spec->multiout.dac_nids[i] = 0xb;
4659 /* add playback controls from the parsed DAC table */
4660 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4661 const struct auto_pin_cfg *cfg)
4664 static const char * const chname[4] = {
4665 "Front", "Surround", "C/LFE", "Side"
4667 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4668 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4669 hda_nid_t nid, nid_vol, nid_mute = 0;
4672 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4673 nid = cfg->line_out_pins[i];
4677 nid_vol = nid_vols[i];
4678 nid_mute = nid_mutes[i];
4680 if (i == AUTO_SEQ_CENLFE) {
4682 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4683 "Center Playback Volume",
4684 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4688 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4689 "LFE Playback Volume",
4690 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4694 err = via_add_control(
4695 spec, VIA_CTL_WIDGET_MUTE,
4696 "Center Playback Switch",
4697 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4701 err = via_add_control(
4702 spec, VIA_CTL_WIDGET_MUTE,
4703 "LFE Playback Switch",
4704 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4708 } else if (i == AUTO_SEQ_FRONT) {
4710 sprintf(name, "%s Playback Volume", chname[i]);
4711 err = via_add_control(
4712 spec, VIA_CTL_WIDGET_VOL, name,
4713 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4716 sprintf(name, "%s Playback Switch", chname[i]);
4717 err = via_add_control(
4718 spec, VIA_CTL_WIDGET_MUTE, name,
4719 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4724 sprintf(name, "%s Playback Volume", chname[i]);
4725 err = via_add_control(
4726 spec, VIA_CTL_WIDGET_VOL, name,
4727 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4730 sprintf(name, "%s Playback Switch", chname[i]);
4731 err = via_add_control(
4732 spec, VIA_CTL_WIDGET_MUTE, name,
4733 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4742 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4749 spec->multiout.hp_nid = 0xc; /* AOW4 */
4750 spec->hp_independent_mode_index = 1;
4752 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4753 "Headphone Playback Volume",
4754 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4758 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4759 "Headphone Playback Switch",
4760 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4764 create_hp_imux(spec);
4768 /* create playback/capture controls for input pins */
4769 static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec,
4770 const struct auto_pin_cfg *cfg)
4772 static hda_nid_t pin_idxs[] = { 0x2c, 0x2b, 0x2a, 0x29, 0, 0xff };
4773 return vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
4774 ARRAY_SIZE(pin_idxs));
4777 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4779 struct via_spec *spec = codec->spec;
4782 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4786 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4789 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4790 return 0; /* can't find valid BIOS pin config */
4792 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4795 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4798 err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg);
4802 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4804 fill_dig_outs(codec);
4806 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4807 spec->dig_in_nid = 0x13;
4809 if (spec->kctls.list)
4810 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4812 spec->input_mux = &spec->private_imux[0];
4815 via_hp_build(codec);
4817 via_smart51_build(spec);
4822 #ifdef CONFIG_SND_HDA_POWER_SAVE
4823 static struct hda_amp_list vt1718S_loopbacks[] = {
4824 { 0x21, HDA_INPUT, 1 },
4825 { 0x21, HDA_INPUT, 2 },
4826 { 0x21, HDA_INPUT, 3 },
4827 { 0x21, HDA_INPUT, 4 },
4832 static int patch_vt1718S(struct hda_codec *codec)
4834 struct via_spec *spec;
4837 /* create a codec specific record */
4838 spec = via_new_spec(codec);
4842 /* automatic parse from the BIOS config */
4843 err = vt1718S_parse_auto_config(codec);
4848 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4849 "from BIOS. Using genenic mode...\n");
4852 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4853 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4855 if (codec->vendor_id == 0x11060441)
4856 spec->stream_name_analog = "VT2020 Analog";
4857 else if (codec->vendor_id == 0x11064441)
4858 spec->stream_name_analog = "VT1828S Analog";
4860 spec->stream_name_analog = "VT1718S Analog";
4861 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4862 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4864 if (codec->vendor_id == 0x11060441)
4865 spec->stream_name_digital = "VT2020 Digital";
4866 else if (codec->vendor_id == 0x11064441)
4867 spec->stream_name_digital = "VT1828S Digital";
4869 spec->stream_name_digital = "VT1718S Digital";
4870 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4871 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4872 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4874 if (!spec->adc_nids && spec->input_mux) {
4875 spec->adc_nids = vt1718S_adc_nids;
4876 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4877 get_mux_nids(codec);
4878 override_mic_boost(codec, 0x2b, 0, 3, 40);
4879 override_mic_boost(codec, 0x29, 0, 3, 40);
4880 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4884 codec->patch_ops = via_patch_ops;
4886 codec->patch_ops.init = via_auto_init;
4887 codec->patch_ops.unsol_event = via_unsol_event;
4889 #ifdef CONFIG_SND_HDA_POWER_SAVE
4890 spec->loopback.amplist = vt1718S_loopbacks;
4896 /* Patch for VT1716S */
4898 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4899 struct snd_ctl_elem_info *uinfo)
4901 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4903 uinfo->value.integer.min = 0;
4904 uinfo->value.integer.max = 1;
4908 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4909 struct snd_ctl_elem_value *ucontrol)
4911 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4914 index = snd_hda_codec_read(codec, 0x26, 0,
4915 AC_VERB_GET_CONNECT_SEL, 0);
4917 *ucontrol->value.integer.value = index;
4922 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4923 struct snd_ctl_elem_value *ucontrol)
4925 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4926 struct via_spec *spec = codec->spec;
4927 int index = *ucontrol->value.integer.value;
4929 snd_hda_codec_write(codec, 0x26, 0,
4930 AC_VERB_SET_CONNECT_SEL, index);
4931 spec->dmic_enabled = index;
4932 set_jack_power_state(codec);
4937 /* capture mixer elements */
4938 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
4939 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
4940 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
4941 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
4942 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
4943 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
4944 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
4947 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4948 .name = "Input Source",
4950 .info = via_mux_enum_info,
4951 .get = via_mux_enum_get,
4952 .put = via_mux_enum_put,
4957 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
4958 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
4960 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4961 .name = "Digital Mic Capture Switch",
4962 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
4964 .info = vt1716s_dmic_info,
4965 .get = vt1716s_dmic_get,
4966 .put = vt1716s_dmic_put,
4972 /* mono-out mixer elements */
4973 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
4974 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
4978 static struct hda_verb vt1716S_volume_init_verbs[] = {
4980 * Unmute ADC0-1 and set the default input to mic-in
4982 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4983 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4986 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4989 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4990 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4991 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4992 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4993 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4994 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4996 /* MUX Indices: Stereo Mixer = 5 */
4997 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
4999 /* Setup default input of PW4 to MW0 */
5000 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5002 /* Setup default input of SW1 as MW0 */
5003 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5005 /* Setup default input of SW4 as AOW0 */
5006 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5008 /* PW9 PW10 Output enable */
5009 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5010 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5012 /* Unmute SW1, PW12 */
5013 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5014 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5015 /* PW12 Output enable */
5016 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5017 /* Enable Boost Volume backdoor */
5019 /* don't bybass mixer */
5021 /* Enable mono output */
5027 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5028 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5029 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5030 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5031 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5032 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5033 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5034 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5035 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5036 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5040 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5044 .nid = 0x10, /* NID to query formats and rates */
5046 .open = via_playback_pcm_open,
5047 .prepare = via_playback_multi_pcm_prepare,
5048 .cleanup = via_playback_multi_pcm_cleanup,
5049 .close = via_pcm_open_close,
5053 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5057 .nid = 0x13, /* NID to query formats and rates */
5059 .open = via_pcm_open_close,
5060 .prepare = via_capture_pcm_prepare,
5061 .cleanup = via_capture_pcm_cleanup,
5062 .close = via_pcm_open_close,
5066 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5070 /* NID is set in via_build_pcms */
5072 .open = via_dig_playback_pcm_open,
5073 .close = via_dig_playback_pcm_close,
5074 .prepare = via_dig_playback_pcm_prepare,
5075 .cleanup = via_dig_playback_pcm_cleanup
5079 /* fill in the dac_nids table from the parsed pin configuration */
5080 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5081 const struct auto_pin_cfg *cfg)
5085 spec->multiout.num_dacs = cfg->line_outs;
5087 spec->multiout.dac_nids = spec->private_dac_nids;
5089 for (i = 0; i < 3; i++) {
5090 nid = cfg->line_out_pins[i];
5092 /* config dac list */
5094 case AUTO_SEQ_FRONT:
5095 spec->multiout.dac_nids[i] = 0x10;
5097 case AUTO_SEQ_CENLFE:
5098 spec->multiout.dac_nids[i] = 0x25;
5100 case AUTO_SEQ_SURROUND:
5101 spec->multiout.dac_nids[i] = 0x11;
5110 /* add playback controls from the parsed DAC table */
5111 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5112 const struct auto_pin_cfg *cfg)
5115 static const char * const chname[3] = {
5116 "Front", "Surround", "C/LFE"
5118 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5119 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5120 hda_nid_t nid, nid_vol, nid_mute;
5123 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5124 nid = cfg->line_out_pins[i];
5129 nid_vol = nid_vols[i];
5130 nid_mute = nid_mutes[i];
5132 if (i == AUTO_SEQ_CENLFE) {
5133 err = via_add_control(
5134 spec, VIA_CTL_WIDGET_VOL,
5135 "Center Playback Volume",
5136 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5139 err = via_add_control(
5140 spec, VIA_CTL_WIDGET_VOL,
5141 "LFE Playback Volume",
5142 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5145 err = via_add_control(
5146 spec, VIA_CTL_WIDGET_MUTE,
5147 "Center Playback Switch",
5148 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5152 err = via_add_control(
5153 spec, VIA_CTL_WIDGET_MUTE,
5154 "LFE Playback Switch",
5155 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5159 } else if (i == AUTO_SEQ_FRONT) {
5161 err = via_add_control(
5162 spec, VIA_CTL_WIDGET_VOL,
5163 "Master Front Playback Volume",
5164 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5167 err = via_add_control(
5168 spec, VIA_CTL_WIDGET_MUTE,
5169 "Master Front Playback Switch",
5170 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5174 sprintf(name, "%s Playback Volume", chname[i]);
5175 err = via_add_control(
5176 spec, VIA_CTL_WIDGET_VOL, name,
5177 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5180 sprintf(name, "%s Playback Switch", chname[i]);
5181 err = via_add_control(
5182 spec, VIA_CTL_WIDGET_MUTE, name,
5183 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5188 sprintf(name, "%s Playback Volume", chname[i]);
5189 err = via_add_control(
5190 spec, VIA_CTL_WIDGET_VOL, name,
5191 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5194 sprintf(name, "%s Playback Switch", chname[i]);
5195 err = via_add_control(
5196 spec, VIA_CTL_WIDGET_MUTE, name,
5197 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5206 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5213 spec->multiout.hp_nid = 0x25; /* AOW3 */
5214 spec->hp_independent_mode_index = 1;
5216 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5217 "Headphone Playback Volume",
5218 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5222 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5223 "Headphone Playback Switch",
5224 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5228 create_hp_imux(spec);
5232 /* create playback/capture controls for input pins */
5233 static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec,
5234 const struct auto_pin_cfg *cfg)
5236 static hda_nid_t pin_idxs[] = { 0x1f, 0x1a, 0x1b, 0x1e, 0, 0xff };
5237 return vt_auto_create_analog_input_ctls(codec, cfg, 0x16, pin_idxs,
5238 ARRAY_SIZE(pin_idxs));
5241 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5243 struct via_spec *spec = codec->spec;
5246 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5249 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5252 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5253 return 0; /* can't find valid BIOS pin config */
5255 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5258 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5261 err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg);
5265 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5267 fill_dig_outs(codec);
5269 if (spec->kctls.list)
5270 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5272 spec->input_mux = &spec->private_imux[0];
5275 via_hp_build(codec);
5277 via_smart51_build(spec);
5282 #ifdef CONFIG_SND_HDA_POWER_SAVE
5283 static struct hda_amp_list vt1716S_loopbacks[] = {
5284 { 0x16, HDA_INPUT, 1 },
5285 { 0x16, HDA_INPUT, 2 },
5286 { 0x16, HDA_INPUT, 3 },
5287 { 0x16, HDA_INPUT, 4 },
5292 static int patch_vt1716S(struct hda_codec *codec)
5294 struct via_spec *spec;
5297 /* create a codec specific record */
5298 spec = via_new_spec(codec);
5302 /* automatic parse from the BIOS config */
5303 err = vt1716S_parse_auto_config(codec);
5308 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5309 "from BIOS. Using genenic mode...\n");
5312 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5313 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5315 spec->stream_name_analog = "VT1716S Analog";
5316 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5317 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5319 spec->stream_name_digital = "VT1716S Digital";
5320 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5322 if (!spec->adc_nids && spec->input_mux) {
5323 spec->adc_nids = vt1716S_adc_nids;
5324 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5325 get_mux_nids(codec);
5326 override_mic_boost(codec, 0x1a, 0, 3, 40);
5327 override_mic_boost(codec, 0x1e, 0, 3, 40);
5328 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5332 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5335 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5337 codec->patch_ops = via_patch_ops;
5339 codec->patch_ops.init = via_auto_init;
5340 codec->patch_ops.unsol_event = via_unsol_event;
5342 #ifdef CONFIG_SND_HDA_POWER_SAVE
5343 spec->loopback.amplist = vt1716S_loopbacks;
5351 /* capture mixer elements */
5352 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5353 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5354 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5355 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5356 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5357 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5358 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5361 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5362 /* The multiple "Capture Source" controls confuse alsamixer
5363 * So call somewhat different..
5365 /* .name = "Capture Source", */
5366 .name = "Input Source",
5368 .info = via_mux_enum_info,
5369 .get = via_mux_enum_get,
5370 .put = via_mux_enum_put,
5375 static struct hda_verb vt2002P_volume_init_verbs[] = {
5377 * Unmute ADC0-1 and set the default input to mic-in
5379 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5380 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5383 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5386 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5387 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5388 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5389 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5390 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5391 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5393 /* MUX Indices: Mic = 0 */
5394 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5395 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5397 /* PW9 Output enable */
5398 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5400 /* Enable Boost Volume backdoor */
5403 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5404 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5405 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5406 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5407 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5408 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5409 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5410 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5411 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5413 /* set MUX0/1/4/8 = 0 (AOW0) */
5414 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5415 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5416 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5417 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5419 /* set PW0 index=0 (MW0) */
5420 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5422 /* Enable AOW0 to MW9 */
5428 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5429 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5430 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5431 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5432 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5433 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5434 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5435 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5439 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5443 .nid = 0x8, /* NID to query formats and rates */
5445 .open = via_playback_pcm_open,
5446 .prepare = via_playback_multi_pcm_prepare,
5447 .cleanup = via_playback_multi_pcm_cleanup,
5448 .close = via_pcm_open_close,
5452 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5456 .nid = 0x10, /* NID to query formats and rates */
5458 .open = via_pcm_open_close,
5459 .prepare = via_capture_pcm_prepare,
5460 .cleanup = via_capture_pcm_cleanup,
5461 .close = via_pcm_open_close,
5465 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5469 /* NID is set in via_build_pcms */
5471 .open = via_dig_playback_pcm_open,
5472 .close = via_dig_playback_pcm_close,
5473 .prepare = via_dig_playback_pcm_prepare,
5474 .cleanup = via_dig_playback_pcm_cleanup
5478 /* fill in the dac_nids table from the parsed pin configuration */
5479 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5480 const struct auto_pin_cfg *cfg)
5482 spec->multiout.num_dacs = 1;
5483 spec->multiout.dac_nids = spec->private_dac_nids;
5484 if (cfg->line_out_pins[0])
5485 spec->multiout.dac_nids[0] = 0x8;
5489 /* add playback controls from the parsed DAC table */
5490 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5491 const struct auto_pin_cfg *cfg)
5495 if (!cfg->line_out_pins[0])
5499 /* Line-Out: PortE */
5500 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5501 "Master Front Playback Volume",
5502 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5505 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5506 "Master Front Playback Switch",
5507 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5514 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5521 spec->multiout.hp_nid = 0x9;
5522 spec->hp_independent_mode_index = 1;
5524 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5525 "Headphone Playback Volume",
5526 HDA_COMPOSE_AMP_VAL(
5527 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5531 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5532 "Headphone Playback Switch",
5533 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5537 create_hp_imux(spec);
5541 /* create playback/capture controls for input pins */
5542 static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec,
5543 const struct auto_pin_cfg *cfg)
5545 struct via_spec *spec = codec->spec;
5546 struct hda_input_mux *imux = &spec->private_imux[0];
5547 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0xff };
5550 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5551 ARRAY_SIZE(pin_idxs));
5554 /* build volume/mute control of loopback */
5555 err = via_new_analog_input(spec, "Stereo Mixer", 0, 3, 0x21);
5559 /* for digital mic select */
5560 snd_hda_add_imux_item(imux, "Digital Mic", 4, NULL);
5565 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5567 struct via_spec *spec = codec->spec;
5571 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5575 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5579 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5580 return 0; /* can't find valid BIOS pin config */
5582 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5585 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5588 err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg);
5592 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5594 fill_dig_outs(codec);
5596 if (spec->kctls.list)
5597 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5599 spec->input_mux = &spec->private_imux[0];
5602 via_hp_build(codec);
5607 #ifdef CONFIG_SND_HDA_POWER_SAVE
5608 static struct hda_amp_list vt2002P_loopbacks[] = {
5609 { 0x21, HDA_INPUT, 0 },
5610 { 0x21, HDA_INPUT, 1 },
5611 { 0x21, HDA_INPUT, 2 },
5617 /* patch for vt2002P */
5618 static int patch_vt2002P(struct hda_codec *codec)
5620 struct via_spec *spec;
5623 /* create a codec specific record */
5624 spec = via_new_spec(codec);
5628 /* automatic parse from the BIOS config */
5629 err = vt2002P_parse_auto_config(codec);
5634 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5635 "from BIOS. Using genenic mode...\n");
5638 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5639 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5641 spec->stream_name_analog = "VT2002P Analog";
5642 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5643 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5645 spec->stream_name_digital = "VT2002P Digital";
5646 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5648 if (!spec->adc_nids && spec->input_mux) {
5649 spec->adc_nids = vt2002P_adc_nids;
5650 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5651 get_mux_nids(codec);
5652 override_mic_boost(codec, 0x2b, 0, 3, 40);
5653 override_mic_boost(codec, 0x29, 0, 3, 40);
5654 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5658 codec->patch_ops = via_patch_ops;
5660 codec->patch_ops.init = via_auto_init;
5661 codec->patch_ops.unsol_event = via_unsol_event;
5663 #ifdef CONFIG_SND_HDA_POWER_SAVE
5664 spec->loopback.amplist = vt2002P_loopbacks;
5672 /* capture mixer elements */
5673 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5674 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5675 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5676 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5677 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5678 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5679 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5682 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5683 /* The multiple "Capture Source" controls confuse alsamixer
5684 * So call somewhat different..
5686 .name = "Input Source",
5688 .info = via_mux_enum_info,
5689 .get = via_mux_enum_get,
5690 .put = via_mux_enum_put,
5695 static struct hda_verb vt1812_volume_init_verbs[] = {
5697 * Unmute ADC0-1 and set the default input to mic-in
5699 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5700 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5703 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5706 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5707 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5708 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5709 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5710 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5711 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5713 /* MUX Indices: Mic = 0 */
5714 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5715 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5717 /* PW9 Output enable */
5718 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5720 /* Enable Boost Volume backdoor */
5723 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5724 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5725 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5726 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5727 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5728 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5729 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5730 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5731 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5732 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5733 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5735 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5736 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5737 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5738 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5739 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5740 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5742 /* Enable AOW0 to MW9 */
5748 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5749 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5750 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5751 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5752 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5753 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5754 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5755 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5756 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5760 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5764 .nid = 0x8, /* NID to query formats and rates */
5766 .open = via_playback_pcm_open,
5767 .prepare = via_playback_multi_pcm_prepare,
5768 .cleanup = via_playback_multi_pcm_cleanup,
5769 .close = via_pcm_open_close,
5773 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5777 .nid = 0x10, /* NID to query formats and rates */
5779 .open = via_pcm_open_close,
5780 .prepare = via_capture_pcm_prepare,
5781 .cleanup = via_capture_pcm_cleanup,
5782 .close = via_pcm_open_close,
5786 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5790 /* NID is set in via_build_pcms */
5792 .open = via_dig_playback_pcm_open,
5793 .close = via_dig_playback_pcm_close,
5794 .prepare = via_dig_playback_pcm_prepare,
5795 .cleanup = via_dig_playback_pcm_cleanup
5798 /* fill in the dac_nids table from the parsed pin configuration */
5799 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5800 const struct auto_pin_cfg *cfg)
5802 spec->multiout.num_dacs = 1;
5803 spec->multiout.dac_nids = spec->private_dac_nids;
5804 if (cfg->line_out_pins[0])
5805 spec->multiout.dac_nids[0] = 0x8;
5810 /* add playback controls from the parsed DAC table */
5811 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5812 const struct auto_pin_cfg *cfg)
5816 if (!cfg->line_out_pins[0])
5819 /* Line-Out: PortE */
5820 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5821 "Front Playback Volume",
5822 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5825 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5826 "Front Playback Switch",
5827 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5834 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5841 spec->multiout.hp_nid = 0x9;
5842 spec->hp_independent_mode_index = 1;
5845 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5846 "Headphone Playback Volume",
5847 HDA_COMPOSE_AMP_VAL(
5848 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5852 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5853 "Headphone Playback Switch",
5854 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5858 create_hp_imux(spec);
5862 /* create playback/capture controls for input pins */
5863 static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec,
5864 const struct auto_pin_cfg *cfg)
5866 struct via_spec *spec = codec->spec;
5867 struct hda_input_mux *imux = &spec->private_imux[0];
5868 static hda_nid_t pin_idxs[] = { 0x2b, 0x2a, 0x29, 0, 0, 0xff };
5871 err = vt_auto_create_analog_input_ctls(codec, cfg, 0x21, pin_idxs,
5872 ARRAY_SIZE(pin_idxs));
5876 /* build volume/mute control of loopback */
5877 err = via_new_analog_input(spec, "Stereo Mixer", 0, 5, 0x21);
5881 /* for digital mic select */
5882 snd_hda_add_imux_item(imux, "Digital Mic", 6, NULL);
5887 static int vt1812_parse_auto_config(struct hda_codec *codec)
5889 struct via_spec *spec = codec->spec;
5893 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5896 fill_dig_outs(codec);
5897 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
5901 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
5902 return 0; /* can't find valid BIOS pin config */
5904 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
5907 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5910 err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg);
5914 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5916 fill_dig_outs(codec);
5918 if (spec->kctls.list)
5919 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5921 spec->input_mux = &spec->private_imux[0];
5924 via_hp_build(codec);
5929 #ifdef CONFIG_SND_HDA_POWER_SAVE
5930 static struct hda_amp_list vt1812_loopbacks[] = {
5931 { 0x21, HDA_INPUT, 0 },
5932 { 0x21, HDA_INPUT, 1 },
5933 { 0x21, HDA_INPUT, 2 },
5939 /* patch for vt1812 */
5940 static int patch_vt1812(struct hda_codec *codec)
5942 struct via_spec *spec;
5945 /* create a codec specific record */
5946 spec = via_new_spec(codec);
5950 /* automatic parse from the BIOS config */
5951 err = vt1812_parse_auto_config(codec);
5956 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5957 "from BIOS. Using genenic mode...\n");
5961 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
5962 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
5964 spec->stream_name_analog = "VT1812 Analog";
5965 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
5966 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
5968 spec->stream_name_digital = "VT1812 Digital";
5969 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
5972 if (!spec->adc_nids && spec->input_mux) {
5973 spec->adc_nids = vt1812_adc_nids;
5974 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
5975 get_mux_nids(codec);
5976 override_mic_boost(codec, 0x2b, 0, 3, 40);
5977 override_mic_boost(codec, 0x29, 0, 3, 40);
5978 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
5982 codec->patch_ops = via_patch_ops;
5984 codec->patch_ops.init = via_auto_init;
5985 codec->patch_ops.unsol_event = via_unsol_event;
5987 #ifdef CONFIG_SND_HDA_POWER_SAVE
5988 spec->loopback.amplist = vt1812_loopbacks;
5997 static struct hda_codec_preset snd_hda_preset_via[] = {
5998 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
5999 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6000 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6001 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6002 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6003 .patch = patch_vt1709_10ch},
6004 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6005 .patch = patch_vt1709_10ch},
6006 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6007 .patch = patch_vt1709_10ch},
6008 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6009 .patch = patch_vt1709_10ch},
6010 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6011 .patch = patch_vt1709_6ch},
6012 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6013 .patch = patch_vt1709_6ch},
6014 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6015 .patch = patch_vt1709_6ch},
6016 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6017 .patch = patch_vt1709_6ch},
6018 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6019 .patch = patch_vt1708B_8ch},
6020 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6021 .patch = patch_vt1708B_8ch},
6022 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6023 .patch = patch_vt1708B_8ch},
6024 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6025 .patch = patch_vt1708B_8ch},
6026 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6027 .patch = patch_vt1708B_4ch},
6028 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6029 .patch = patch_vt1708B_4ch},
6030 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6031 .patch = patch_vt1708B_4ch},
6032 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6033 .patch = patch_vt1708B_4ch},
6034 { .id = 0x11060397, .name = "VT1708S",
6035 .patch = patch_vt1708S},
6036 { .id = 0x11061397, .name = "VT1708S",
6037 .patch = patch_vt1708S},
6038 { .id = 0x11062397, .name = "VT1708S",
6039 .patch = patch_vt1708S},
6040 { .id = 0x11063397, .name = "VT1708S",
6041 .patch = patch_vt1708S},
6042 { .id = 0x11064397, .name = "VT1708S",
6043 .patch = patch_vt1708S},
6044 { .id = 0x11065397, .name = "VT1708S",
6045 .patch = patch_vt1708S},
6046 { .id = 0x11066397, .name = "VT1708S",
6047 .patch = patch_vt1708S},
6048 { .id = 0x11067397, .name = "VT1708S",
6049 .patch = patch_vt1708S},
6050 { .id = 0x11060398, .name = "VT1702",
6051 .patch = patch_vt1702},
6052 { .id = 0x11061398, .name = "VT1702",
6053 .patch = patch_vt1702},
6054 { .id = 0x11062398, .name = "VT1702",
6055 .patch = patch_vt1702},
6056 { .id = 0x11063398, .name = "VT1702",
6057 .patch = patch_vt1702},
6058 { .id = 0x11064398, .name = "VT1702",
6059 .patch = patch_vt1702},
6060 { .id = 0x11065398, .name = "VT1702",
6061 .patch = patch_vt1702},
6062 { .id = 0x11066398, .name = "VT1702",
6063 .patch = patch_vt1702},
6064 { .id = 0x11067398, .name = "VT1702",
6065 .patch = patch_vt1702},
6066 { .id = 0x11060428, .name = "VT1718S",
6067 .patch = patch_vt1718S},
6068 { .id = 0x11064428, .name = "VT1718S",
6069 .patch = patch_vt1718S},
6070 { .id = 0x11060441, .name = "VT2020",
6071 .patch = patch_vt1718S},
6072 { .id = 0x11064441, .name = "VT1828S",
6073 .patch = patch_vt1718S},
6074 { .id = 0x11060433, .name = "VT1716S",
6075 .patch = patch_vt1716S},
6076 { .id = 0x1106a721, .name = "VT1716S",
6077 .patch = patch_vt1716S},
6078 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6079 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6080 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6081 { .id = 0x11060440, .name = "VT1818S",
6082 .patch = patch_vt1708S},
6086 MODULE_ALIAS("snd-hda-codec-id:1106*");
6088 static struct hda_codec_preset_list via_list = {
6089 .preset = snd_hda_preset_via,
6090 .owner = THIS_MODULE,
6093 MODULE_LICENSE("GPL");
6094 MODULE_DESCRIPTION("VIA HD-audio codec");
6096 static int __init patch_via_init(void)
6098 return snd_hda_add_codec_preset(&via_list);
6101 static void __exit patch_via_exit(void)
6103 snd_hda_delete_codec_preset(&via_list);
6106 module_init(patch_via_init)
6107 module_exit(patch_via_exit)