2 * Universal Interface for Intel High Definition Audio Codec
4 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
6 * (C) 2006-2009 VIA Technology, Inc.
7 * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
26 /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
27 /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
28 /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
29 /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
30 /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
31 /* 2007-09-17 Lydia Wang Add VT1708B codec support */
32 /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
33 /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
34 /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
35 /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
36 /* 2008-04-09 Lydia Wang Add Independent HP feature */
37 /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
38 /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
39 /* 2009-02-16 Logan Li Add support for VT1718S */
40 /* 2009-03-13 Logan Li Add support for VT1716S */
41 /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
42 /* 2009-07-08 Lydia Wang Add support for VT2002P */
43 /* 2009-07-21 Lydia Wang Add support for VT1812 */
44 /* 2009-09-19 Lydia Wang Add support for VT1818S */
46 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 #include <linux/init.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <sound/core.h>
53 #include <sound/asoundef.h>
54 #include "hda_codec.h"
55 #include "hda_local.h"
57 #define NID_MAPPING (-1)
60 #define AMP_VAL_IDX_SHIFT 19
61 #define AMP_VAL_IDX_MASK (0x0f<<19)
64 #define VT1708_HP_NID 0x13
65 #define VT1708_DIGOUT_NID 0x14
66 #define VT1708_DIGIN_NID 0x16
67 #define VT1708_DIGIN_PIN 0x26
68 #define VT1708_HP_PIN_NID 0x20
69 #define VT1708_CD_PIN_NID 0x24
71 #define VT1709_HP_DAC_NID 0x28
72 #define VT1709_DIGOUT_NID 0x13
73 #define VT1709_DIGIN_NID 0x17
74 #define VT1709_DIGIN_PIN 0x25
76 #define VT1708B_HP_NID 0x25
77 #define VT1708B_DIGOUT_NID 0x12
78 #define VT1708B_DIGIN_NID 0x15
79 #define VT1708B_DIGIN_PIN 0x21
81 #define VT1708S_HP_NID 0x25
82 #define VT1708S_DIGOUT_NID 0x12
84 #define VT1702_HP_NID 0x17
85 #define VT1702_DIGOUT_NID 0x11
105 /* codec parameterization */
106 struct snd_kcontrol_new *mixers[6];
107 unsigned int num_mixers;
109 struct hda_verb *init_verbs[5];
110 unsigned int num_iverbs;
112 char *stream_name_analog;
113 struct hda_pcm_stream *stream_analog_playback;
114 struct hda_pcm_stream *stream_analog_capture;
116 char *stream_name_digital;
117 struct hda_pcm_stream *stream_digital_playback;
118 struct hda_pcm_stream *stream_digital_capture;
121 struct hda_multi_out multiout;
122 hda_nid_t slave_dig_outs[2];
125 unsigned int num_adc_nids;
127 hda_nid_t mux_nids[3];
128 hda_nid_t dig_in_nid;
129 hda_nid_t dig_in_pin;
132 const struct hda_input_mux *input_mux;
133 unsigned int cur_mux[3];
135 /* PCM information */
136 struct hda_pcm pcm_rec[3];
138 /* dynamic controls, init_verbs and input_mux */
139 struct auto_pin_cfg autocfg;
140 struct snd_array kctls;
141 struct hda_input_mux private_imux[2];
142 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
145 const struct hda_input_mux *hp_mux;
146 unsigned int hp_independent_mode;
147 unsigned int hp_independent_mode_index;
148 unsigned int smart51_enabled;
149 unsigned int dmic_enabled;
150 enum VIA_HDA_CODEC codec_type;
152 /* work to check hp jack state */
153 struct hda_codec *codec;
154 struct delayed_work vt1708_hp_work;
155 int vt1708_jack_detectect;
156 int vt1708_hp_present;
157 #ifdef CONFIG_SND_HDA_POWER_SAVE
158 struct hda_loopback_check loopback;
162 static struct via_spec * via_new_spec(struct hda_codec *codec)
164 struct via_spec *spec;
166 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
175 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
177 u32 vendor_id = codec->vendor_id;
178 u16 ven_id = vendor_id >> 16;
179 u16 dev_id = vendor_id & 0xffff;
180 enum VIA_HDA_CODEC codec_type;
183 if (ven_id != 0x1106)
184 codec_type = UNKNOWN;
185 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
187 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
188 codec_type = VT1709_10CH;
189 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
190 codec_type = VT1709_6CH;
191 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
192 codec_type = VT1708B_8CH;
193 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
194 codec_type = VT1708BCE;
195 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
196 codec_type = VT1708B_4CH;
197 else if ((dev_id & 0xfff) == 0x397
198 && (dev_id >> 12) < 8)
199 codec_type = VT1708S;
200 else if ((dev_id & 0xfff) == 0x398
201 && (dev_id >> 12) < 8)
203 else if ((dev_id & 0xfff) == 0x428
204 && (dev_id >> 12) < 8)
205 codec_type = VT1718S;
206 else if (dev_id == 0x0433 || dev_id == 0xa721)
207 codec_type = VT1716S;
208 else if (dev_id == 0x0441 || dev_id == 0x4441)
209 codec_type = VT1718S;
210 else if (dev_id == 0x0438 || dev_id == 0x4438)
211 codec_type = VT2002P;
212 else if (dev_id == 0x0448)
214 else if (dev_id == 0x0440)
215 codec_type = VT1708S;
217 codec_type = UNKNOWN;
221 #define VIA_HP_EVENT 0x01
222 #define VIA_GPIO_EVENT 0x02
223 #define VIA_JACK_EVENT 0x04
224 #define VIA_MONO_EVENT 0x08
225 #define VIA_SPEAKER_EVENT 0x10
226 #define VIA_BIND_HP_EVENT 0x20
231 VIA_CTL_WIDGET_ANALOG_MUTE,
232 VIA_CTL_WIDGET_BIND_PIN_MUTE,
242 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
243 static void set_jack_power_state(struct hda_codec *codec);
244 static int is_aa_path_mute(struct hda_codec *codec);
246 static void vt1708_start_hp_work(struct via_spec *spec)
248 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
250 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
251 !spec->vt1708_jack_detectect);
252 if (!delayed_work_pending(&spec->vt1708_hp_work))
253 schedule_delayed_work(&spec->vt1708_hp_work,
254 msecs_to_jiffies(100));
257 static void vt1708_stop_hp_work(struct via_spec *spec)
259 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
261 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
262 && !is_aa_path_mute(spec->codec))
264 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
265 !spec->vt1708_jack_detectect);
266 cancel_delayed_work(&spec->vt1708_hp_work);
267 flush_scheduled_work();
271 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
272 struct snd_ctl_elem_value *ucontrol)
274 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
275 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
277 set_jack_power_state(codec);
278 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
279 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
280 if (is_aa_path_mute(codec))
281 vt1708_start_hp_work(codec->spec);
283 vt1708_stop_hp_work(codec->spec);
288 /* modify .put = snd_hda_mixer_amp_switch_put */
289 #define ANALOG_INPUT_MUTE \
290 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
293 .info = snd_hda_mixer_amp_switch_info, \
294 .get = snd_hda_mixer_amp_switch_get, \
295 .put = analog_input_switch_put, \
296 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
298 static void via_hp_bind_automute(struct hda_codec *codec);
300 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol)
303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
304 struct via_spec *spec = codec->spec;
308 long *valp = ucontrol->value.integer.value;
310 if (strstr(kcontrol->id.name, "Switch") == NULL) {
311 snd_printd("Invalid control!\n");
314 change = snd_hda_mixer_amp_switch_put(kcontrol,
317 lmute = *valp ? 0 : HDA_AMP_MUTE;
319 rmute = *valp ? 0 : HDA_AMP_MUTE;
322 if (!spec->hp_independent_mode) {
323 for (i = 0; i < spec->autocfg.hp_outs; i++) {
324 snd_hda_codec_amp_update(
325 codec, spec->autocfg.hp_pins[i],
326 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
328 snd_hda_codec_amp_update(
329 codec, spec->autocfg.hp_pins[i],
330 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
335 if (!lmute && !rmute) {
337 for (i = 0; i < spec->autocfg.line_outs; i++)
338 snd_hda_codec_amp_stereo(
339 codec, spec->autocfg.line_out_pins[i],
340 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
342 for (i = 0; i < spec->autocfg.speaker_outs; i++)
343 snd_hda_codec_amp_stereo(
344 codec, spec->autocfg.speaker_pins[i],
345 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
347 via_hp_bind_automute(codec);
351 /* Mute all left channels */
352 for (i = 1; i < spec->autocfg.line_outs; i++)
353 snd_hda_codec_amp_update(
355 spec->autocfg.line_out_pins[i],
356 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
358 for (i = 0; i < spec->autocfg.speaker_outs; i++)
359 snd_hda_codec_amp_update(
361 spec->autocfg.speaker_pins[i],
362 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
366 /* mute all right channels */
367 for (i = 1; i < spec->autocfg.line_outs; i++)
368 snd_hda_codec_amp_update(
370 spec->autocfg.line_out_pins[i],
371 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
373 for (i = 0; i < spec->autocfg.speaker_outs; i++)
374 snd_hda_codec_amp_update(
376 spec->autocfg.speaker_pins[i],
377 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
384 #define BIND_PIN_MUTE \
385 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
388 .info = snd_hda_mixer_amp_switch_info, \
389 .get = snd_hda_mixer_amp_switch_get, \
390 .put = bind_pin_switch_put, \
391 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
393 static struct snd_kcontrol_new via_control_templates[] = {
394 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
395 HDA_CODEC_MUTE(NULL, 0, 0, 0),
400 static hda_nid_t vt1708_adc_nids[2] = {
405 static hda_nid_t vt1709_adc_nids[3] = {
410 static hda_nid_t vt1708B_adc_nids[2] = {
415 static hda_nid_t vt1708S_adc_nids[2] = {
420 static hda_nid_t vt1702_adc_nids[3] = {
425 static hda_nid_t vt1718S_adc_nids[2] = {
430 static hda_nid_t vt1716S_adc_nids[2] = {
435 static hda_nid_t vt2002P_adc_nids[2] = {
440 static hda_nid_t vt1812_adc_nids[2] = {
446 /* add dynamic controls */
447 static int via_add_control(struct via_spec *spec, int type, const char *name,
450 struct snd_kcontrol_new *knew;
452 snd_array_init(&spec->kctls, sizeof(*knew), 32);
453 knew = snd_array_new(&spec->kctls);
456 *knew = via_control_templates[type];
457 knew->name = kstrdup(name, GFP_KERNEL);
460 if (get_amp_nid_(val))
461 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
462 knew->private_value = val;
466 static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec,
467 struct snd_kcontrol_new *tmpl)
469 struct snd_kcontrol_new *knew;
471 snd_array_init(&spec->kctls, sizeof(*knew), 32);
472 knew = snd_array_new(&spec->kctls);
476 knew->name = kstrdup(tmpl->name, GFP_KERNEL);
482 static void via_free_kctls(struct hda_codec *codec)
484 struct via_spec *spec = codec->spec;
486 if (spec->kctls.list) {
487 struct snd_kcontrol_new *kctl = spec->kctls.list;
489 for (i = 0; i < spec->kctls.used; i++)
492 snd_array_free(&spec->kctls);
495 /* create input playback/capture controls for the given pin */
496 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
497 int idx, int mix_nid)
502 sprintf(name, "%s Playback Volume", ctlname);
503 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
504 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
507 sprintf(name, "%s Playback Switch", ctlname);
508 err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
509 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
515 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
516 hda_nid_t nid, int pin_type,
520 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
522 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
524 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
525 snd_hda_codec_write(codec, nid, 0,
526 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
530 static void via_auto_init_multi_out(struct hda_codec *codec)
532 struct via_spec *spec = codec->spec;
535 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
536 hda_nid_t nid = spec->autocfg.line_out_pins[i];
538 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
542 static void via_auto_init_hp_out(struct hda_codec *codec)
544 struct via_spec *spec = codec->spec;
548 for (i = 0; i < spec->autocfg.hp_outs; i++) {
549 pin = spec->autocfg.hp_pins[i];
550 if (pin) /* connect to front */
551 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
555 static void via_auto_init_analog_input(struct hda_codec *codec)
557 struct via_spec *spec = codec->spec;
560 for (i = 0; i < AUTO_PIN_LAST; i++) {
561 hda_nid_t nid = spec->autocfg.input_pins[i];
563 snd_hda_codec_write(codec, nid, 0,
564 AC_VERB_SET_PIN_WIDGET_CONTROL,
565 (i <= AUTO_PIN_FRONT_MIC ?
566 PIN_VREF50 : PIN_IN));
571 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
573 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
574 unsigned int *affected_parm)
577 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
578 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
579 >> AC_DEFCFG_MISC_SHIFT
580 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
581 unsigned present = snd_hda_jack_detect(codec, nid);
582 struct via_spec *spec = codec->spec;
583 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
584 || ((no_presence || present)
585 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
586 *affected_parm = AC_PWRST_D0; /* if it's connected */
591 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
594 static void set_jack_power_state(struct hda_codec *codec)
596 struct via_spec *spec = codec->spec;
600 if (spec->codec_type == VT1702) {
601 imux_is_smixer = snd_hda_codec_read(
602 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
604 /* PW 1/2/5 (14h/15h/18h) */
606 set_pin_power_state(codec, 0x14, &parm);
607 set_pin_power_state(codec, 0x15, &parm);
608 set_pin_power_state(codec, 0x18, &parm);
610 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
611 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
612 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
614 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
616 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
618 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
622 /* PW 3/4 (16h/17h) */
624 set_pin_power_state(codec, 0x16, &parm);
625 set_pin_power_state(codec, 0x17, &parm);
626 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
627 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
628 imux_is_smixer ? AC_PWRST_D0 : parm);
629 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
631 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
633 } else if (spec->codec_type == VT1708B_8CH
634 || spec->codec_type == VT1708B_4CH
635 || spec->codec_type == VT1708S) {
636 /* SW0 (17h) = stereo mixer */
637 int is_8ch = spec->codec_type != VT1708B_4CH;
638 imux_is_smixer = snd_hda_codec_read(
639 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
640 == ((spec->codec_type == VT1708S) ? 5 : 0);
642 /* PW 1/2/5 (1ah/1bh/1eh) */
644 set_pin_power_state(codec, 0x1a, &parm);
645 set_pin_power_state(codec, 0x1b, &parm);
646 set_pin_power_state(codec, 0x1e, &parm);
649 /* SW0 (17h), AIW 0/1 (13h/14h) */
650 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
652 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
654 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
658 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
660 set_pin_power_state(codec, 0x19, &parm);
661 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
663 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
666 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
669 set_pin_power_state(codec, 0x22, &parm);
670 snd_hda_codec_write(codec, 0x26, 0,
671 AC_VERB_SET_POWER_STATE, parm);
672 snd_hda_codec_write(codec, 0x24, 0,
673 AC_VERB_SET_POWER_STATE, parm);
676 /* PW 3/4/7 (1ch/1dh/23h) */
678 /* force to D0 for internal Speaker */
679 set_pin_power_state(codec, 0x1c, &parm);
680 set_pin_power_state(codec, 0x1d, &parm);
682 set_pin_power_state(codec, 0x23, &parm);
683 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
684 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
685 imux_is_smixer ? AC_PWRST_D0 : parm);
686 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
689 snd_hda_codec_write(codec, 0x25, 0,
690 AC_VERB_SET_POWER_STATE, parm);
691 snd_hda_codec_write(codec, 0x27, 0,
692 AC_VERB_SET_POWER_STATE, parm);
694 } else if (spec->codec_type == VT1718S) {
695 /* MUX6 (1eh) = stereo mixer */
696 imux_is_smixer = snd_hda_codec_read(
697 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
699 /* PW 5/6/7 (29h/2ah/2bh) */
701 set_pin_power_state(codec, 0x29, &parm);
702 set_pin_power_state(codec, 0x2a, &parm);
703 set_pin_power_state(codec, 0x2b, &parm);
706 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
707 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
709 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
711 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
713 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
717 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
719 set_pin_power_state(codec, 0x27, &parm);
720 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
722 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
725 /* PW2 (26h), AOW2 (ah) */
727 set_pin_power_state(codec, 0x26, &parm);
728 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
731 /* PW0/1 (24h/25h) */
733 set_pin_power_state(codec, 0x24, &parm);
734 set_pin_power_state(codec, 0x25, &parm);
735 if (!spec->hp_independent_mode) /* check for redirected HP */
736 set_pin_power_state(codec, 0x28, &parm);
737 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
739 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
741 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
742 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
743 imux_is_smixer ? AC_PWRST_D0 : parm);
744 if (spec->hp_independent_mode) {
745 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
747 set_pin_power_state(codec, 0x28, &parm);
748 snd_hda_codec_write(codec, 0x1b, 0,
749 AC_VERB_SET_POWER_STATE, parm);
750 snd_hda_codec_write(codec, 0x34, 0,
751 AC_VERB_SET_POWER_STATE, parm);
752 snd_hda_codec_write(codec, 0xc, 0,
753 AC_VERB_SET_POWER_STATE, parm);
755 } else if (spec->codec_type == VT1716S) {
756 unsigned int mono_out, present;
757 /* SW0 (17h) = stereo mixer */
758 imux_is_smixer = snd_hda_codec_read(
759 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
761 /* PW 1/2/5 (1ah/1bh/1eh) */
763 set_pin_power_state(codec, 0x1a, &parm);
764 set_pin_power_state(codec, 0x1b, &parm);
765 set_pin_power_state(codec, 0x1e, &parm);
768 /* SW0 (17h), AIW0(13h) */
769 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
771 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
775 set_pin_power_state(codec, 0x1e, &parm);
777 if (spec->dmic_enabled)
778 set_pin_power_state(codec, 0x22, &parm);
782 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
784 /* SW2(26h), AIW1(14h) */
785 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
787 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
791 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
793 set_pin_power_state(codec, 0x19, &parm);
794 /* Smart 5.1 PW2(1bh) */
795 if (spec->smart51_enabled)
796 set_pin_power_state(codec, 0x1b, &parm);
797 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
799 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
802 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
804 set_pin_power_state(codec, 0x23, &parm);
805 /* Smart 5.1 PW1(1ah) */
806 if (spec->smart51_enabled)
807 set_pin_power_state(codec, 0x1a, &parm);
808 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
811 /* Smart 5.1 PW5(1eh) */
812 if (spec->smart51_enabled)
813 set_pin_power_state(codec, 0x1e, &parm);
814 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
818 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
819 present = snd_hda_jack_detect(codec, 0x1c);
823 present = snd_hda_jack_detect(codec, 0x1d);
824 if (!spec->hp_independent_mode && present)
829 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
830 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
832 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
834 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
837 /* PW 3/4 (1ch/1dh) */
839 set_pin_power_state(codec, 0x1c, &parm);
840 set_pin_power_state(codec, 0x1d, &parm);
841 /* HP Independent Mode, power on AOW3 */
842 if (spec->hp_independent_mode)
843 snd_hda_codec_write(codec, 0x25, 0,
844 AC_VERB_SET_POWER_STATE, parm);
846 /* force to D0 for internal Speaker */
847 /* MW0 (16h), AOW0 (10h) */
848 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
849 imux_is_smixer ? AC_PWRST_D0 : parm);
850 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
851 mono_out ? AC_PWRST_D0 : parm);
852 } else if (spec->codec_type == VT2002P) {
853 unsigned int present;
854 /* MUX9 (1eh) = stereo mixer */
855 imux_is_smixer = snd_hda_codec_read(
856 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
858 /* PW 5/6/7 (29h/2ah/2bh) */
860 set_pin_power_state(codec, 0x29, &parm);
861 set_pin_power_state(codec, 0x2a, &parm);
862 set_pin_power_state(codec, 0x2b, &parm);
865 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
866 snd_hda_codec_write(codec, 0x1e, 0,
867 AC_VERB_SET_POWER_STATE, parm);
868 snd_hda_codec_write(codec, 0x1f, 0,
869 AC_VERB_SET_POWER_STATE, parm);
870 snd_hda_codec_write(codec, 0x10, 0,
871 AC_VERB_SET_POWER_STATE, parm);
872 snd_hda_codec_write(codec, 0x11, 0,
873 AC_VERB_SET_POWER_STATE, parm);
877 snd_hda_codec_write(codec, 0x8, 0,
878 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
880 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
882 set_pin_power_state(codec, 0x26, &parm);
883 snd_hda_codec_write(codec, 0x1c, 0,
884 AC_VERB_SET_POWER_STATE, parm);
885 snd_hda_codec_write(codec, 0x37,
886 0, AC_VERB_SET_POWER_STATE, parm);
888 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
890 set_pin_power_state(codec, 0x25, &parm);
891 snd_hda_codec_write(codec, 0x19, 0,
892 AC_VERB_SET_POWER_STATE, parm);
893 snd_hda_codec_write(codec, 0x35, 0,
894 AC_VERB_SET_POWER_STATE, parm);
895 if (spec->hp_independent_mode) {
896 snd_hda_codec_write(codec, 0x9, 0,
897 AC_VERB_SET_POWER_STATE, parm);
901 /* PW0 (24h), MW0(18h), MUX0(34h) */
902 present = snd_hda_jack_detect(codec, 0x25);
904 set_pin_power_state(codec, 0x24, &parm);
908 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
911 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
915 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
918 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
922 /* PW15 (31h), MW8(17h), MUX8(3bh) */
923 present = snd_hda_jack_detect(codec, 0x26);
925 set_pin_power_state(codec, 0x31, &parm);
929 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
932 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
936 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
939 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
943 if (imux_is_smixer || !is_aa_path_mute(codec))
946 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
950 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
951 } else if (spec->codec_type == VT1812) {
952 unsigned int present;
953 /* MUX10 (1eh) = stereo mixer */
954 imux_is_smixer = snd_hda_codec_read(
955 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
957 /* PW 5/6/7 (29h/2ah/2bh) */
959 set_pin_power_state(codec, 0x29, &parm);
960 set_pin_power_state(codec, 0x2a, &parm);
961 set_pin_power_state(codec, 0x2b, &parm);
964 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
965 snd_hda_codec_write(codec, 0x1e, 0,
966 AC_VERB_SET_POWER_STATE, parm);
967 snd_hda_codec_write(codec, 0x1f, 0,
968 AC_VERB_SET_POWER_STATE, parm);
969 snd_hda_codec_write(codec, 0x10, 0,
970 AC_VERB_SET_POWER_STATE, parm);
971 snd_hda_codec_write(codec, 0x11, 0,
972 AC_VERB_SET_POWER_STATE, parm);
976 snd_hda_codec_write(codec, 0x8, 0,
977 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
979 /* PW4 (28h), MW4 (18h), MUX4(38h) */
981 set_pin_power_state(codec, 0x28, &parm);
982 snd_hda_codec_write(codec, 0x18, 0,
983 AC_VERB_SET_POWER_STATE, parm);
984 snd_hda_codec_write(codec, 0x38, 0,
985 AC_VERB_SET_POWER_STATE, parm);
987 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
989 set_pin_power_state(codec, 0x25, &parm);
990 snd_hda_codec_write(codec, 0x15, 0,
991 AC_VERB_SET_POWER_STATE, parm);
992 snd_hda_codec_write(codec, 0x35, 0,
993 AC_VERB_SET_POWER_STATE, parm);
994 if (spec->hp_independent_mode) {
995 snd_hda_codec_write(codec, 0x9, 0,
996 AC_VERB_SET_POWER_STATE, parm);
999 /* Internal Speaker */
1000 /* PW0 (24h), MW0(14h), MUX0(34h) */
1001 present = snd_hda_jack_detect(codec, 0x25);
1003 set_pin_power_state(codec, 0x24, &parm);
1005 snd_hda_codec_write(codec, 0x14, 0,
1006 AC_VERB_SET_POWER_STATE,
1008 snd_hda_codec_write(codec, 0x34, 0,
1009 AC_VERB_SET_POWER_STATE,
1012 snd_hda_codec_write(codec, 0x14, 0,
1013 AC_VERB_SET_POWER_STATE,
1015 snd_hda_codec_write(codec, 0x34, 0,
1016 AC_VERB_SET_POWER_STATE,
1020 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1021 present = snd_hda_jack_detect(codec, 0x28);
1023 set_pin_power_state(codec, 0x31, &parm);
1025 snd_hda_codec_write(codec, 0x1c, 0,
1026 AC_VERB_SET_POWER_STATE,
1028 snd_hda_codec_write(codec, 0x3c, 0,
1029 AC_VERB_SET_POWER_STATE,
1031 snd_hda_codec_write(codec, 0x3e, 0,
1032 AC_VERB_SET_POWER_STATE,
1035 snd_hda_codec_write(codec, 0x1c, 0,
1036 AC_VERB_SET_POWER_STATE,
1038 snd_hda_codec_write(codec, 0x3c, 0,
1039 AC_VERB_SET_POWER_STATE,
1041 snd_hda_codec_write(codec, 0x3e, 0,
1042 AC_VERB_SET_POWER_STATE,
1046 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1048 set_pin_power_state(codec, 0x33, &parm);
1049 snd_hda_codec_write(codec, 0x1d, 0,
1050 AC_VERB_SET_POWER_STATE, parm);
1051 snd_hda_codec_write(codec, 0x3d, 0,
1052 AC_VERB_SET_POWER_STATE, parm);
1055 if (imux_is_smixer || !is_aa_path_mute(codec))
1056 snd_hda_codec_write(
1058 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1060 snd_hda_codec_write(
1062 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1067 * input MUX handling
1069 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1070 struct snd_ctl_elem_info *uinfo)
1072 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1073 struct via_spec *spec = codec->spec;
1074 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1077 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1078 struct snd_ctl_elem_value *ucontrol)
1080 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1081 struct via_spec *spec = codec->spec;
1082 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1084 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1088 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1089 struct snd_ctl_elem_value *ucontrol)
1091 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1092 struct via_spec *spec = codec->spec;
1093 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1095 if (!spec->mux_nids[adc_idx])
1097 /* switch to D0 beofre change index */
1098 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1099 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1100 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1101 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1102 /* update jack power state */
1103 set_jack_power_state(codec);
1105 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1106 spec->mux_nids[adc_idx],
1107 &spec->cur_mux[adc_idx]);
1110 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1111 struct snd_ctl_elem_info *uinfo)
1113 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1114 struct via_spec *spec = codec->spec;
1115 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1118 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1119 struct snd_ctl_elem_value *ucontrol)
1121 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1122 hda_nid_t nid = kcontrol->private_value;
1123 unsigned int pinsel;
1125 /* use !! to translate conn sel 2 for VT1718S */
1126 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1127 AC_VERB_GET_CONNECT_SEL,
1129 ucontrol->value.enumerated.item[0] = pinsel;
1134 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1136 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1138 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1139 ctl->vd[0].access |= active
1140 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1141 snd_ctl_notify(codec->bus->card,
1142 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1146 static hda_nid_t side_mute_channel(struct via_spec *spec)
1148 switch (spec->codec_type) {
1149 case VT1708: return 0x1b;
1150 case VT1709_10CH: return 0x29;
1151 case VT1708B_8CH: /* fall thru */
1152 case VT1708S: return 0x27;
1157 static int update_side_mute_status(struct hda_codec *codec)
1159 /* mute side channel */
1160 struct via_spec *spec = codec->spec;
1161 unsigned int parm = spec->hp_independent_mode
1162 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1163 hda_nid_t sw3 = side_mute_channel(spec);
1166 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1171 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1172 struct snd_ctl_elem_value *ucontrol)
1174 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1175 struct via_spec *spec = codec->spec;
1176 hda_nid_t nid = kcontrol->private_value;
1177 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1178 /* Get Independent Mode index of headphone pin widget */
1179 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1181 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
1183 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1184 != spec->multiout.dac_nids[HDA_FRONT])
1185 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1188 update_side_mute_status(codec);
1189 /* update HP volume/swtich active state */
1190 if (spec->codec_type == VT1708S
1191 || spec->codec_type == VT1702
1192 || spec->codec_type == VT1718S
1193 || spec->codec_type == VT1716S
1194 || spec->codec_type == VT2002P
1195 || spec->codec_type == VT1812) {
1196 activate_ctl(codec, "Headphone Playback Volume",
1197 spec->hp_independent_mode);
1198 activate_ctl(codec, "Headphone Playback Switch",
1199 spec->hp_independent_mode);
1204 static struct snd_kcontrol_new via_hp_mixer[2] = {
1206 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1207 .name = "Independent HP",
1208 .info = via_independent_hp_info,
1209 .get = via_independent_hp_get,
1210 .put = via_independent_hp_put,
1213 .iface = NID_MAPPING,
1214 .name = "Independent HP",
1218 static int via_hp_build(struct via_spec *spec)
1220 struct snd_kcontrol_new *knew;
1223 knew = via_clone_control(spec, &via_hp_mixer[0]);
1227 switch (spec->codec_type) {
1238 nid = spec->autocfg.hp_pins[0];
1242 knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
1243 knew->private_value = nid;
1245 knew = via_clone_control(spec, &via_hp_mixer[1]);
1248 knew->subdevice = side_mute_channel(spec);
1253 static void notify_aa_path_ctls(struct hda_codec *codec)
1256 struct snd_ctl_elem_id id;
1257 const char *labels[] = {"Mic", "Front Mic", "Line"};
1259 memset(&id, 0, sizeof(id));
1260 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1261 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1262 sprintf(id.name, "%s Playback Volume", labels[i]);
1263 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1268 static void mute_aa_path(struct hda_codec *codec, int mute)
1270 struct via_spec *spec = codec->spec;
1271 hda_nid_t nid_mixer;
1275 /* get nid of MW0 and start & end index */
1276 switch (spec->codec_type) {
1299 /* check AA path's mute status */
1300 for (i = start_idx; i <= end_idx; i++) {
1301 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1302 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1306 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1310 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
1311 if (pin == spec->autocfg.input_pins[index]) {
1319 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1320 struct snd_ctl_elem_info *uinfo)
1322 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1324 uinfo->value.integer.min = 0;
1325 uinfo->value.integer.max = 1;
1329 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1330 struct snd_ctl_elem_value *ucontrol)
1332 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1333 struct via_spec *spec = codec->spec;
1334 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1338 for (i = 0; i < ARRAY_SIZE(index); i++) {
1339 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1342 snd_hda_codec_read(codec, nid, 0,
1343 AC_VERB_GET_PIN_WIDGET_CONTROL,
1345 if (i == AUTO_PIN_FRONT_MIC
1346 && spec->hp_independent_mode
1347 && spec->codec_type != VT1718S)
1348 continue; /* ignore FMic for independent HP */
1349 if (ctl & AC_PINCTL_IN_EN
1350 && !(ctl & AC_PINCTL_OUT_EN))
1354 *ucontrol->value.integer.value = on;
1358 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1359 struct snd_ctl_elem_value *ucontrol)
1361 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1362 struct via_spec *spec = codec->spec;
1363 int out_in = *ucontrol->value.integer.value
1364 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1365 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1368 for (i = 0; i < ARRAY_SIZE(index); i++) {
1369 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1370 if (i == AUTO_PIN_FRONT_MIC
1371 && spec->hp_independent_mode
1372 && spec->codec_type != VT1718S)
1373 continue; /* don't retask FMic for independent HP */
1375 unsigned int parm = snd_hda_codec_read(
1377 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1378 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1380 snd_hda_codec_write(codec, nid, 0,
1381 AC_VERB_SET_PIN_WIDGET_CONTROL,
1383 if (out_in == AC_PINCTL_OUT_EN) {
1384 mute_aa_path(codec, 1);
1385 notify_aa_path_ctls(codec);
1387 if (spec->codec_type == VT1718S)
1388 snd_hda_codec_amp_stereo(
1389 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1392 if (i == AUTO_PIN_FRONT_MIC) {
1393 if (spec->codec_type == VT1708S
1394 || spec->codec_type == VT1716S) {
1395 /* input = index 1 (AOW3) */
1396 snd_hda_codec_write(
1398 AC_VERB_SET_CONNECT_SEL, 1);
1399 snd_hda_codec_amp_stereo(
1400 codec, nid, HDA_OUTPUT,
1401 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1405 spec->smart51_enabled = *ucontrol->value.integer.value;
1406 set_jack_power_state(codec);
1410 static struct snd_kcontrol_new via_smart51_mixer[2] = {
1412 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1413 .name = "Smart 5.1",
1415 .info = via_smart51_info,
1416 .get = via_smart51_get,
1417 .put = via_smart51_put,
1420 .iface = NID_MAPPING,
1421 .name = "Smart 5.1",
1425 static int via_smart51_build(struct via_spec *spec)
1427 struct snd_kcontrol_new *knew;
1428 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1432 knew = via_clone_control(spec, &via_smart51_mixer[0]);
1436 for (i = 0; i < ARRAY_SIZE(index); i++) {
1437 nid = spec->autocfg.input_pins[index[i]];
1439 knew = via_clone_control(spec, &via_smart51_mixer[1]);
1442 knew->subdevice = nid;
1449 /* capture mixer elements */
1450 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1451 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1452 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1453 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1454 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1456 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1457 /* The multiple "Capture Source" controls confuse alsamixer
1458 * So call somewhat different..
1460 /* .name = "Capture Source", */
1461 .name = "Input Source",
1463 .info = via_mux_enum_info,
1464 .get = via_mux_enum_get,
1465 .put = via_mux_enum_put,
1470 /* check AA path's mute statue */
1471 static int is_aa_path_mute(struct hda_codec *codec)
1474 hda_nid_t nid_mixer;
1478 struct via_spec *spec = codec->spec;
1479 /* get nid of MW0 and start & end index */
1480 switch (spec->codec_type) {
1508 /* check AA path's mute status */
1509 for (i = start_idx; i <= end_idx; i++) {
1510 unsigned int con_list = snd_hda_codec_read(
1511 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1512 int shift = 8 * (i % 4);
1513 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1514 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1515 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1516 /* check mute status while the pin is connected */
1517 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1519 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1521 if (!mute_l || !mute_r) {
1530 /* enter/exit analog low-current mode */
1531 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1533 struct via_spec *spec = codec->spec;
1534 static int saved_stream_idle = 1; /* saved stream idle status */
1535 int enable = is_aa_path_mute(codec);
1536 unsigned int verb = 0;
1537 unsigned int parm = 0;
1539 if (stream_idle == -1) /* stream status did not change */
1540 enable = enable && saved_stream_idle;
1542 enable = enable && stream_idle;
1543 saved_stream_idle = stream_idle;
1546 /* decide low current mode's verb & parameter */
1547 switch (spec->codec_type) {
1551 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1557 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1561 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1566 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1569 return; /* other codecs are not supported */
1572 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1576 * generic initialization of ADC, input mixers and output mixers
1578 static struct hda_verb vt1708_volume_init_verbs[] = {
1580 * Unmute ADC0-1 and set the default input to mic-in
1582 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1583 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1586 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1589 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1590 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1591 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1592 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1593 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1594 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1597 * Set up output mixers (0x19 - 0x1b)
1599 /* set vol=0 to output mixers */
1600 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1601 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1602 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1604 /* Setup default input MW0 to PW4 */
1605 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1606 /* PW9 Output enable */
1607 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1611 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1612 struct hda_codec *codec,
1613 struct snd_pcm_substream *substream)
1615 struct via_spec *spec = codec->spec;
1616 int idle = substream->pstr->substream_opened == 1
1617 && substream->ref_count == 0;
1618 analog_low_current_mode(codec, idle);
1619 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1623 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1624 unsigned int stream_tag,
1625 unsigned int format,
1626 struct snd_pcm_substream *substream)
1628 struct via_spec *spec = codec->spec;
1629 struct hda_multi_out *mout = &spec->multiout;
1630 hda_nid_t *nids = mout->dac_nids;
1631 int chs = substream->runtime->channels;
1634 mutex_lock(&codec->spdif_mutex);
1635 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1637 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1639 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1640 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1641 /* turn off SPDIF once; otherwise the IEC958 bits won't
1643 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1644 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1645 AC_VERB_SET_DIGI_CONVERT_1,
1647 ~AC_DIG1_ENABLE & 0xff);
1648 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1649 stream_tag, 0, format);
1650 /* turn on again (if needed) */
1651 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1652 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1653 AC_VERB_SET_DIGI_CONVERT_1,
1654 codec->spdif_ctls & 0xff);
1656 mout->dig_out_used = 0;
1657 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1661 mutex_unlock(&codec->spdif_mutex);
1664 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1667 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1668 && !spec->hp_independent_mode)
1669 /* headphone out will just decode front left/right (stereo) */
1670 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1673 /* extra outputs copied from front */
1674 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1675 if (mout->extra_out_nid[i])
1676 snd_hda_codec_setup_stream(codec,
1677 mout->extra_out_nid[i],
1678 stream_tag, 0, format);
1681 for (i = 1; i < mout->num_dacs; i++) {
1682 if (chs >= (i + 1) * 2) /* independent out */
1683 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1685 else /* copy front */
1686 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1691 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1692 struct hda_codec *codec,
1693 unsigned int stream_tag,
1694 unsigned int format,
1695 struct snd_pcm_substream *substream)
1697 struct via_spec *spec = codec->spec;
1698 struct hda_multi_out *mout = &spec->multiout;
1699 hda_nid_t *nids = mout->dac_nids;
1701 if (substream->number == 0)
1702 playback_multi_pcm_prep_0(codec, stream_tag, format,
1705 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1706 spec->hp_independent_mode)
1707 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1708 stream_tag, 0, format);
1710 vt1708_start_hp_work(spec);
1714 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1715 struct hda_codec *codec,
1716 struct snd_pcm_substream *substream)
1718 struct via_spec *spec = codec->spec;
1719 struct hda_multi_out *mout = &spec->multiout;
1720 hda_nid_t *nids = mout->dac_nids;
1723 if (substream->number == 0) {
1724 for (i = 0; i < mout->num_dacs; i++)
1725 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1727 if (mout->hp_nid && !spec->hp_independent_mode)
1728 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1731 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1732 if (mout->extra_out_nid[i])
1733 snd_hda_codec_setup_stream(codec,
1734 mout->extra_out_nid[i],
1736 mutex_lock(&codec->spdif_mutex);
1737 if (mout->dig_out_nid &&
1738 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1739 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1741 mout->dig_out_used = 0;
1743 mutex_unlock(&codec->spdif_mutex);
1745 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1746 spec->hp_independent_mode)
1747 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1750 vt1708_stop_hp_work(spec);
1757 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1758 struct hda_codec *codec,
1759 struct snd_pcm_substream *substream)
1761 struct via_spec *spec = codec->spec;
1762 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1765 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1766 struct hda_codec *codec,
1767 struct snd_pcm_substream *substream)
1769 struct via_spec *spec = codec->spec;
1770 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1773 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1774 struct hda_codec *codec,
1775 unsigned int stream_tag,
1776 unsigned int format,
1777 struct snd_pcm_substream *substream)
1779 struct via_spec *spec = codec->spec;
1780 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1781 stream_tag, format, substream);
1784 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1785 struct hda_codec *codec,
1786 struct snd_pcm_substream *substream)
1788 struct via_spec *spec = codec->spec;
1789 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1796 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1797 struct hda_codec *codec,
1798 unsigned int stream_tag,
1799 unsigned int format,
1800 struct snd_pcm_substream *substream)
1802 struct via_spec *spec = codec->spec;
1804 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1805 stream_tag, 0, format);
1809 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1810 struct hda_codec *codec,
1811 struct snd_pcm_substream *substream)
1813 struct via_spec *spec = codec->spec;
1814 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1818 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1822 .nid = 0x10, /* NID to query formats and rates */
1824 .open = via_playback_pcm_open,
1825 .prepare = via_playback_multi_pcm_prepare,
1826 .cleanup = via_playback_multi_pcm_cleanup
1830 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1834 .nid = 0x10, /* NID to query formats and rates */
1835 /* We got noisy outputs on the right channel on VT1708 when
1836 * 24bit samples are used. Until any workaround is found,
1837 * disable the 24bit format, so far.
1839 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1841 .open = via_playback_pcm_open,
1842 .prepare = via_playback_multi_pcm_prepare,
1843 .cleanup = via_playback_multi_pcm_cleanup
1847 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1851 .nid = 0x15, /* NID to query formats and rates */
1853 .prepare = via_capture_pcm_prepare,
1854 .cleanup = via_capture_pcm_cleanup
1858 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1862 /* NID is set in via_build_pcms */
1864 .open = via_dig_playback_pcm_open,
1865 .close = via_dig_playback_pcm_close,
1866 .prepare = via_dig_playback_pcm_prepare,
1867 .cleanup = via_dig_playback_pcm_cleanup
1871 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1877 static int via_build_controls(struct hda_codec *codec)
1879 struct via_spec *spec = codec->spec;
1880 struct snd_kcontrol *kctl;
1881 struct snd_kcontrol_new *knew;
1884 for (i = 0; i < spec->num_mixers; i++) {
1885 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1890 if (spec->multiout.dig_out_nid) {
1891 err = snd_hda_create_spdif_out_ctls(codec,
1892 spec->multiout.dig_out_nid);
1895 err = snd_hda_create_spdif_share_sw(codec,
1899 spec->multiout.share_spdif = 1;
1901 if (spec->dig_in_nid) {
1902 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1907 /* assign Capture Source enums to NID */
1908 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1909 for (i = 0; kctl && i < kctl->count; i++) {
1910 err = snd_hda_add_nids(codec, kctl, i, spec->mux_nids,
1911 spec->input_mux->num_items);
1916 /* other nid->control mapping */
1917 for (i = 0; i < spec->num_mixers; i++) {
1918 for (knew = spec->mixers[i]; knew->name; knew++) {
1919 if (knew->iface != NID_MAPPING)
1921 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1924 err = snd_hda_add_nid(codec, kctl, 0,
1929 /* init power states */
1930 set_jack_power_state(codec);
1931 analog_low_current_mode(codec, 1);
1933 via_free_kctls(codec); /* no longer needed */
1937 static int via_build_pcms(struct hda_codec *codec)
1939 struct via_spec *spec = codec->spec;
1940 struct hda_pcm *info = spec->pcm_rec;
1942 codec->num_pcms = 1;
1943 codec->pcm_info = info;
1945 info->name = spec->stream_name_analog;
1946 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1947 *(spec->stream_analog_playback);
1948 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1949 spec->multiout.dac_nids[0];
1950 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1951 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1953 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1954 spec->multiout.max_channels;
1956 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1959 info->name = spec->stream_name_digital;
1960 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1961 if (spec->multiout.dig_out_nid) {
1962 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1963 *(spec->stream_digital_playback);
1964 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1965 spec->multiout.dig_out_nid;
1967 if (spec->dig_in_nid) {
1968 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1969 *(spec->stream_digital_capture);
1970 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1978 static void via_free(struct hda_codec *codec)
1980 struct via_spec *spec = codec->spec;
1985 via_free_kctls(codec);
1986 vt1708_stop_hp_work(spec);
1990 /* mute internal speaker if HP is plugged */
1991 static void via_hp_automute(struct hda_codec *codec)
1993 unsigned int present = 0;
1994 struct via_spec *spec = codec->spec;
1996 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1998 if (!spec->hp_independent_mode) {
1999 struct snd_ctl_elem_id id;
2001 snd_hda_codec_amp_stereo(
2002 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2003 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2005 memset(&id, 0, sizeof(id));
2006 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2007 strcpy(id.name, "Front Playback Switch");
2008 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2013 /* mute mono out if HP or Line out is plugged */
2014 static void via_mono_automute(struct hda_codec *codec)
2016 unsigned int hp_present, lineout_present;
2017 struct via_spec *spec = codec->spec;
2019 if (spec->codec_type != VT1716S)
2022 lineout_present = snd_hda_jack_detect(codec,
2023 spec->autocfg.line_out_pins[0]);
2025 /* Mute Mono Out if Line Out is plugged */
2026 if (lineout_present) {
2027 snd_hda_codec_amp_stereo(
2028 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2032 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2034 if (!spec->hp_independent_mode)
2035 snd_hda_codec_amp_stereo(
2036 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2037 hp_present ? HDA_AMP_MUTE : 0);
2040 static void via_gpio_control(struct hda_codec *codec)
2042 unsigned int gpio_data;
2043 unsigned int vol_counter;
2045 unsigned int master_vol;
2047 struct via_spec *spec = codec->spec;
2049 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2050 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2052 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2053 0xF84, 0) & 0x3F0000) >> 16;
2055 vol = vol_counter & 0x1F;
2056 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2057 AC_VERB_GET_AMP_GAIN_MUTE,
2060 if (gpio_data == 0x02) {
2061 /* unmute line out */
2062 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2063 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2065 if (vol_counter & 0x20) {
2066 /* decrease volume */
2067 if (vol > master_vol)
2069 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2073 /* increase volume */
2074 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2076 ((master_vol+vol) > 0x2A) ? 0x2A :
2079 } else if (!(gpio_data & 0x02)) {
2081 snd_hda_codec_amp_stereo(codec,
2082 spec->autocfg.line_out_pins[0],
2083 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2088 /* mute Internal-Speaker if HP is plugged */
2089 static void via_speaker_automute(struct hda_codec *codec)
2091 unsigned int hp_present;
2092 struct via_spec *spec = codec->spec;
2094 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2097 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2099 if (!spec->hp_independent_mode) {
2100 struct snd_ctl_elem_id id;
2101 snd_hda_codec_amp_stereo(
2102 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2103 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2105 memset(&id, 0, sizeof(id));
2106 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2107 strcpy(id.name, "Speaker Playback Switch");
2108 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2113 /* mute line-out and internal speaker if HP is plugged */
2114 static void via_hp_bind_automute(struct hda_codec *codec)
2116 /* use long instead of int below just to avoid an internal compiler
2117 * error with gcc 4.0.x
2119 unsigned long hp_present, present = 0;
2120 struct via_spec *spec = codec->spec;
2123 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2126 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2128 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2130 if (!spec->hp_independent_mode) {
2131 /* Mute Line-Outs */
2132 for (i = 0; i < spec->autocfg.line_outs; i++)
2133 snd_hda_codec_amp_stereo(
2134 codec, spec->autocfg.line_out_pins[i],
2136 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2138 present = hp_present;
2141 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2142 snd_hda_codec_amp_stereo(
2143 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2144 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2148 /* unsolicited event for jack sensing */
2149 static void via_unsol_event(struct hda_codec *codec,
2153 if (res & VIA_HP_EVENT)
2154 via_hp_automute(codec);
2155 if (res & VIA_GPIO_EVENT)
2156 via_gpio_control(codec);
2157 if (res & VIA_JACK_EVENT)
2158 set_jack_power_state(codec);
2159 if (res & VIA_MONO_EVENT)
2160 via_mono_automute(codec);
2161 if (res & VIA_SPEAKER_EVENT)
2162 via_speaker_automute(codec);
2163 if (res & VIA_BIND_HP_EVENT)
2164 via_hp_bind_automute(codec);
2167 static int via_init(struct hda_codec *codec)
2169 struct via_spec *spec = codec->spec;
2171 for (i = 0; i < spec->num_iverbs; i++)
2172 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2174 spec->codec_type = get_codec_type(codec);
2175 if (spec->codec_type == VT1708BCE)
2176 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2178 /* Lydia Add for EAPD enable */
2179 if (!spec->dig_in_nid) { /* No Digital In connection */
2180 if (spec->dig_in_pin) {
2181 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2182 AC_VERB_SET_PIN_WIDGET_CONTROL,
2184 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2185 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2187 } else /* enable SPDIF-input pin */
2188 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2189 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2191 /* assign slave outs */
2192 if (spec->slave_dig_outs[0])
2193 codec->slave_dig_outs = spec->slave_dig_outs;
2198 #ifdef SND_HDA_NEEDS_RESUME
2199 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2201 struct via_spec *spec = codec->spec;
2202 vt1708_stop_hp_work(spec);
2207 #ifdef CONFIG_SND_HDA_POWER_SAVE
2208 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2210 struct via_spec *spec = codec->spec;
2211 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2217 static struct hda_codec_ops via_patch_ops = {
2218 .build_controls = via_build_controls,
2219 .build_pcms = via_build_pcms,
2222 #ifdef SND_HDA_NEEDS_RESUME
2223 .suspend = via_suspend,
2225 #ifdef CONFIG_SND_HDA_POWER_SAVE
2226 .check_power_status = via_check_power_status,
2230 /* fill in the dac_nids table from the parsed pin configuration */
2231 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2232 const struct auto_pin_cfg *cfg)
2237 spec->multiout.num_dacs = cfg->line_outs;
2239 spec->multiout.dac_nids = spec->private_dac_nids;
2241 for (i = 0; i < 4; i++) {
2242 nid = cfg->line_out_pins[i];
2244 /* config dac list */
2246 case AUTO_SEQ_FRONT:
2247 spec->multiout.dac_nids[i] = 0x10;
2249 case AUTO_SEQ_CENLFE:
2250 spec->multiout.dac_nids[i] = 0x12;
2252 case AUTO_SEQ_SURROUND:
2253 spec->multiout.dac_nids[i] = 0x11;
2256 spec->multiout.dac_nids[i] = 0x13;
2265 /* add playback controls from the parsed DAC table */
2266 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2267 const struct auto_pin_cfg *cfg)
2270 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2271 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2274 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2275 nid = cfg->line_out_pins[i];
2280 nid_vol = nid_vols[i];
2282 if (i == AUTO_SEQ_CENLFE) {
2284 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2285 "Center Playback Volume",
2286 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2290 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2291 "LFE Playback Volume",
2292 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2296 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2297 "Center Playback Switch",
2298 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2302 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2303 "LFE Playback Switch",
2304 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2308 } else if (i == AUTO_SEQ_FRONT) {
2309 /* add control to mixer index 0 */
2310 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2311 "Master Front Playback Volume",
2312 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2316 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2317 "Master Front Playback Switch",
2318 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2323 /* add control to PW3 */
2324 sprintf(name, "%s Playback Volume", chname[i]);
2325 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2326 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2330 sprintf(name, "%s Playback Switch", chname[i]);
2331 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2332 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2337 sprintf(name, "%s Playback Volume", chname[i]);
2338 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2339 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2343 sprintf(name, "%s Playback Switch", chname[i]);
2344 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2345 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2355 static void create_hp_imux(struct via_spec *spec)
2358 struct hda_input_mux *imux = &spec->private_imux[1];
2359 static const char *texts[] = { "OFF", "ON", NULL};
2361 /* for hp mode select */
2363 while (texts[i] != NULL) {
2364 imux->items[imux->num_items].label = texts[i];
2365 imux->items[imux->num_items].index = i;
2370 spec->hp_mux = &spec->private_imux[1];
2373 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2380 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2381 spec->hp_independent_mode_index = 1;
2383 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2384 "Headphone Playback Volume",
2385 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2388 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2389 "Headphone Playback Switch",
2390 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2394 create_hp_imux(spec);
2399 /* create playback/capture controls for input pins */
2400 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
2401 const struct auto_pin_cfg *cfg)
2403 static char *labels[] = {
2404 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2406 struct hda_input_mux *imux = &spec->private_imux[0];
2407 int i, err, idx = 0;
2409 /* for internal loopback recording select */
2410 imux->items[imux->num_items].label = "Stereo Mixer";
2411 imux->items[imux->num_items].index = idx;
2414 for (i = 0; i < AUTO_PIN_LAST; i++) {
2415 if (!cfg->input_pins[i])
2418 switch (cfg->input_pins[i]) {
2419 case 0x1d: /* Mic */
2423 case 0x1e: /* Line In */
2427 case 0x21: /* Front Mic */
2435 err = via_new_analog_input(spec, labels[i], idx, 0x17);
2438 imux->items[imux->num_items].label = labels[i];
2439 imux->items[imux->num_items].index = idx;
2445 #ifdef CONFIG_SND_HDA_POWER_SAVE
2446 static struct hda_amp_list vt1708_loopbacks[] = {
2447 { 0x17, HDA_INPUT, 1 },
2448 { 0x17, HDA_INPUT, 2 },
2449 { 0x17, HDA_INPUT, 3 },
2450 { 0x17, HDA_INPUT, 4 },
2455 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2457 unsigned int def_conf;
2458 unsigned char seqassoc;
2460 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2461 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2462 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2463 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2464 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2465 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2466 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2472 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2473 struct snd_ctl_elem_value *ucontrol)
2475 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2476 struct via_spec *spec = codec->spec;
2478 if (spec->codec_type != VT1708)
2480 spec->vt1708_jack_detectect =
2481 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2482 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2486 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2487 struct snd_ctl_elem_value *ucontrol)
2489 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2490 struct via_spec *spec = codec->spec;
2493 if (spec->codec_type != VT1708)
2495 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2496 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2497 == !spec->vt1708_jack_detectect;
2498 if (spec->vt1708_jack_detectect) {
2499 mute_aa_path(codec, 1);
2500 notify_aa_path_ctls(codec);
2505 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2508 .name = "Jack Detect",
2510 .info = snd_ctl_boolean_mono_info,
2511 .get = vt1708_jack_detectect_get,
2512 .put = vt1708_jack_detectect_put,
2517 static int vt1708_parse_auto_config(struct hda_codec *codec)
2519 struct via_spec *spec = codec->spec;
2522 /* Add HP and CD pin config connect bit re-config action */
2523 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2524 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2526 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2529 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2532 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2533 return 0; /* can't find valid BIOS pin config */
2535 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2538 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2541 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
2544 /* add jack detect on/off control */
2545 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2549 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2551 if (spec->autocfg.dig_outs)
2552 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2553 spec->dig_in_pin = VT1708_DIGIN_PIN;
2554 if (spec->autocfg.dig_in_pin)
2555 spec->dig_in_nid = VT1708_DIGIN_NID;
2557 if (spec->kctls.list)
2558 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2560 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2562 spec->input_mux = &spec->private_imux[0];
2567 via_smart51_build(spec);
2571 /* init callback for auto-configuration model -- overriding the default init */
2572 static int via_auto_init(struct hda_codec *codec)
2574 struct via_spec *spec = codec->spec;
2577 via_auto_init_multi_out(codec);
2578 via_auto_init_hp_out(codec);
2579 via_auto_init_analog_input(codec);
2580 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2581 via_hp_bind_automute(codec);
2583 via_hp_automute(codec);
2584 via_speaker_automute(codec);
2590 static void vt1708_update_hp_jack_state(struct work_struct *work)
2592 struct via_spec *spec = container_of(work, struct via_spec,
2593 vt1708_hp_work.work);
2594 if (spec->codec_type != VT1708)
2596 /* if jack state toggled */
2597 if (spec->vt1708_hp_present
2598 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2599 spec->vt1708_hp_present ^= 1;
2600 via_hp_automute(spec->codec);
2602 vt1708_start_hp_work(spec);
2605 static int get_mux_nids(struct hda_codec *codec)
2607 struct via_spec *spec = codec->spec;
2608 hda_nid_t nid, conn[8];
2612 for (i = 0; i < spec->num_adc_nids; i++) {
2613 nid = spec->adc_nids[i];
2615 type = get_wcaps_type(get_wcaps(codec, nid));
2616 if (type == AC_WID_PIN)
2618 n = snd_hda_get_connections(codec, nid, conn,
2623 spec->mux_nids[i] = nid;
2632 static int patch_vt1708(struct hda_codec *codec)
2634 struct via_spec *spec;
2637 /* create a codec specific record */
2638 spec = via_new_spec(codec);
2642 /* automatic parse from the BIOS config */
2643 err = vt1708_parse_auto_config(codec);
2648 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2649 "from BIOS. Using genenic mode...\n");
2653 spec->stream_name_analog = "VT1708 Analog";
2654 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2655 /* disable 32bit format on VT1708 */
2656 if (codec->vendor_id == 0x11061708)
2657 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2658 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2660 spec->stream_name_digital = "VT1708 Digital";
2661 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2662 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2665 if (!spec->adc_nids && spec->input_mux) {
2666 spec->adc_nids = vt1708_adc_nids;
2667 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2668 get_mux_nids(codec);
2669 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2673 codec->patch_ops = via_patch_ops;
2675 codec->patch_ops.init = via_auto_init;
2676 #ifdef CONFIG_SND_HDA_POWER_SAVE
2677 spec->loopback.amplist = vt1708_loopbacks;
2679 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2683 /* capture mixer elements */
2684 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2685 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2686 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2687 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2688 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2689 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2690 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2692 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2693 /* The multiple "Capture Source" controls confuse alsamixer
2694 * So call somewhat different..
2696 /* .name = "Capture Source", */
2697 .name = "Input Source",
2699 .info = via_mux_enum_info,
2700 .get = via_mux_enum_get,
2701 .put = via_mux_enum_put,
2706 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2707 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2708 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2713 * generic initialization of ADC, input mixers and output mixers
2715 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2717 * Unmute ADC0-2 and set the default input to mic-in
2719 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2720 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2721 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2724 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2727 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2728 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2729 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2730 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2731 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2732 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2735 * Set up output selector (0x1a, 0x1b, 0x29)
2737 /* set vol=0 to output mixers */
2738 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2739 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2740 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2743 * Unmute PW3 and PW4
2745 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2746 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2748 /* Set input of PW4 as MW0 */
2749 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2750 /* PW9 Output enable */
2751 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2755 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2759 .nid = 0x10, /* NID to query formats and rates */
2761 .open = via_playback_pcm_open,
2762 .prepare = via_playback_multi_pcm_prepare,
2763 .cleanup = via_playback_multi_pcm_cleanup,
2767 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2771 .nid = 0x10, /* NID to query formats and rates */
2773 .open = via_playback_pcm_open,
2774 .prepare = via_playback_multi_pcm_prepare,
2775 .cleanup = via_playback_multi_pcm_cleanup,
2779 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2783 .nid = 0x14, /* NID to query formats and rates */
2785 .prepare = via_capture_pcm_prepare,
2786 .cleanup = via_capture_pcm_cleanup
2790 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2794 /* NID is set in via_build_pcms */
2796 .open = via_dig_playback_pcm_open,
2797 .close = via_dig_playback_pcm_close
2801 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2807 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2808 const struct auto_pin_cfg *cfg)
2813 if (cfg->line_outs == 4) /* 10 channels */
2814 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2815 else if (cfg->line_outs == 3) /* 6 channels */
2816 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2818 spec->multiout.dac_nids = spec->private_dac_nids;
2820 if (cfg->line_outs == 4) { /* 10 channels */
2821 for (i = 0; i < cfg->line_outs; i++) {
2822 nid = cfg->line_out_pins[i];
2824 /* config dac list */
2826 case AUTO_SEQ_FRONT:
2828 spec->multiout.dac_nids[i] = 0x10;
2830 case AUTO_SEQ_CENLFE:
2832 spec->multiout.dac_nids[i] = 0x12;
2834 case AUTO_SEQ_SURROUND:
2836 spec->multiout.dac_nids[i] = 0x11;
2840 spec->multiout.dac_nids[i] = 0x27;
2847 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2849 } else if (cfg->line_outs == 3) { /* 6 channels */
2850 for (i = 0; i < cfg->line_outs; i++) {
2851 nid = cfg->line_out_pins[i];
2853 /* config dac list */
2855 case AUTO_SEQ_FRONT:
2857 spec->multiout.dac_nids[i] = 0x10;
2859 case AUTO_SEQ_CENLFE:
2861 spec->multiout.dac_nids[i] = 0x12;
2863 case AUTO_SEQ_SURROUND:
2865 spec->multiout.dac_nids[i] = 0x11;
2877 /* add playback controls from the parsed DAC table */
2878 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2879 const struct auto_pin_cfg *cfg)
2882 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2883 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2886 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2887 nid = cfg->line_out_pins[i];
2892 nid_vol = nid_vols[i];
2894 if (i == AUTO_SEQ_CENLFE) {
2896 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2897 "Center Playback Volume",
2898 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2902 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2903 "LFE Playback Volume",
2904 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2908 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2909 "Center Playback Switch",
2910 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2914 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2915 "LFE Playback Switch",
2916 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2920 } else if (i == AUTO_SEQ_FRONT) {
2921 /* ADD control to mixer index 0 */
2922 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2923 "Master Front Playback Volume",
2924 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2928 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2929 "Master Front Playback Switch",
2930 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2935 /* add control to PW3 */
2936 sprintf(name, "%s Playback Volume", chname[i]);
2937 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2938 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2942 sprintf(name, "%s Playback Switch", chname[i]);
2943 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2944 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2948 } else if (i == AUTO_SEQ_SURROUND) {
2949 sprintf(name, "%s Playback Volume", chname[i]);
2950 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2951 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2955 sprintf(name, "%s Playback Switch", chname[i]);
2956 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2957 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2961 } else if (i == AUTO_SEQ_SIDE) {
2962 sprintf(name, "%s Playback Volume", chname[i]);
2963 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2964 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2968 sprintf(name, "%s Playback Switch", chname[i]);
2969 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2970 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2980 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2987 if (spec->multiout.num_dacs == 5) /* 10 channels */
2988 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2989 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2990 spec->multiout.hp_nid = 0;
2991 spec->hp_independent_mode_index = 1;
2993 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2994 "Headphone Playback Volume",
2995 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2998 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2999 "Headphone Playback Switch",
3000 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3007 /* create playback/capture controls for input pins */
3008 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
3009 const struct auto_pin_cfg *cfg)
3011 static char *labels[] = {
3012 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3014 struct hda_input_mux *imux = &spec->private_imux[0];
3015 int i, err, idx = 0;
3017 /* for internal loopback recording select */
3018 imux->items[imux->num_items].label = "Stereo Mixer";
3019 imux->items[imux->num_items].index = idx;
3022 for (i = 0; i < AUTO_PIN_LAST; i++) {
3023 if (!cfg->input_pins[i])
3026 switch (cfg->input_pins[i]) {
3027 case 0x1d: /* Mic */
3031 case 0x1e: /* Line In */
3035 case 0x21: /* Front Mic */
3043 err = via_new_analog_input(spec, labels[i], idx, 0x18);
3046 imux->items[imux->num_items].label = labels[i];
3047 imux->items[imux->num_items].index = idx;
3053 static int vt1709_parse_auto_config(struct hda_codec *codec)
3055 struct via_spec *spec = codec->spec;
3058 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3061 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3064 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3065 return 0; /* can't find valid BIOS pin config */
3067 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3070 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3073 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
3077 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3079 if (spec->autocfg.dig_outs)
3080 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3081 spec->dig_in_pin = VT1709_DIGIN_PIN;
3082 if (spec->autocfg.dig_in_pin)
3083 spec->dig_in_nid = VT1709_DIGIN_NID;
3085 if (spec->kctls.list)
3086 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3088 spec->input_mux = &spec->private_imux[0];
3093 via_smart51_build(spec);
3097 #ifdef CONFIG_SND_HDA_POWER_SAVE
3098 static struct hda_amp_list vt1709_loopbacks[] = {
3099 { 0x18, HDA_INPUT, 1 },
3100 { 0x18, HDA_INPUT, 2 },
3101 { 0x18, HDA_INPUT, 3 },
3102 { 0x18, HDA_INPUT, 4 },
3107 static int patch_vt1709_10ch(struct hda_codec *codec)
3109 struct via_spec *spec;
3112 /* create a codec specific record */
3113 spec = via_new_spec(codec);
3117 err = vt1709_parse_auto_config(codec);
3122 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3123 "Using genenic mode...\n");
3126 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3127 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3129 spec->stream_name_analog = "VT1709 Analog";
3130 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3131 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3133 spec->stream_name_digital = "VT1709 Digital";
3134 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3135 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3138 if (!spec->adc_nids && spec->input_mux) {
3139 spec->adc_nids = vt1709_adc_nids;
3140 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3141 get_mux_nids(codec);
3142 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3146 codec->patch_ops = via_patch_ops;
3148 codec->patch_ops.init = via_auto_init;
3149 codec->patch_ops.unsol_event = via_unsol_event;
3150 #ifdef CONFIG_SND_HDA_POWER_SAVE
3151 spec->loopback.amplist = vt1709_loopbacks;
3157 * generic initialization of ADC, input mixers and output mixers
3159 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3161 * Unmute ADC0-2 and set the default input to mic-in
3163 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3164 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3165 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3168 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3171 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3172 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3173 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3174 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3175 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3176 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3179 * Set up output selector (0x1a, 0x1b, 0x29)
3181 /* set vol=0 to output mixers */
3182 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3183 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3184 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3187 * Unmute PW3 and PW4
3189 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3190 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3192 /* Set input of PW4 as MW0 */
3193 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3194 /* PW9 Output enable */
3195 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3199 static int patch_vt1709_6ch(struct hda_codec *codec)
3201 struct via_spec *spec;
3204 /* create a codec specific record */
3205 spec = via_new_spec(codec);
3209 err = vt1709_parse_auto_config(codec);
3214 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3215 "Using genenic mode...\n");
3218 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3219 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3221 spec->stream_name_analog = "VT1709 Analog";
3222 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3223 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3225 spec->stream_name_digital = "VT1709 Digital";
3226 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3227 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3230 if (!spec->adc_nids && spec->input_mux) {
3231 spec->adc_nids = vt1709_adc_nids;
3232 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3233 get_mux_nids(codec);
3234 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3238 codec->patch_ops = via_patch_ops;
3240 codec->patch_ops.init = via_auto_init;
3241 codec->patch_ops.unsol_event = via_unsol_event;
3242 #ifdef CONFIG_SND_HDA_POWER_SAVE
3243 spec->loopback.amplist = vt1709_loopbacks;
3248 /* capture mixer elements */
3249 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3250 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3251 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3252 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3253 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3256 /* The multiple "Capture Source" controls confuse alsamixer
3257 * So call somewhat different..
3259 /* .name = "Capture Source", */
3260 .name = "Input Source",
3262 .info = via_mux_enum_info,
3263 .get = via_mux_enum_get,
3264 .put = via_mux_enum_put,
3269 * generic initialization of ADC, input mixers and output mixers
3271 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3273 * Unmute ADC0-1 and set the default input to mic-in
3275 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3276 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3279 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3282 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3283 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3284 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3285 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3286 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3287 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3290 * Set up output mixers
3292 /* set vol=0 to output mixers */
3293 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3294 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3295 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3297 /* Setup default input to PW4 */
3298 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3299 /* PW9 Output enable */
3300 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3301 /* PW10 Input enable */
3302 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3306 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3308 * Unmute ADC0-1 and set the default input to mic-in
3310 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3311 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3314 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3317 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3318 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3319 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3320 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3321 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3322 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3325 * Set up output mixers
3327 /* set vol=0 to output mixers */
3328 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3329 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3330 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3332 /* Setup default input of PW4 to MW0 */
3333 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3334 /* PW9 Output enable */
3335 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3336 /* PW10 Input enable */
3337 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3341 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3342 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3343 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3344 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3345 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3346 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3347 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3348 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3349 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3350 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3354 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3355 struct hda_codec *codec,
3356 struct snd_pcm_substream *substream)
3358 int idle = substream->pstr->substream_opened == 1
3359 && substream->ref_count == 0;
3361 analog_low_current_mode(codec, idle);
3365 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3369 .nid = 0x10, /* NID to query formats and rates */
3371 .open = via_playback_pcm_open,
3372 .prepare = via_playback_multi_pcm_prepare,
3373 .cleanup = via_playback_multi_pcm_cleanup,
3374 .close = via_pcm_open_close
3378 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3382 .nid = 0x10, /* NID to query formats and rates */
3384 .open = via_playback_pcm_open,
3385 .prepare = via_playback_multi_pcm_prepare,
3386 .cleanup = via_playback_multi_pcm_cleanup
3390 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3394 .nid = 0x13, /* NID to query formats and rates */
3396 .open = via_pcm_open_close,
3397 .prepare = via_capture_pcm_prepare,
3398 .cleanup = via_capture_pcm_cleanup,
3399 .close = via_pcm_open_close
3403 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3407 /* NID is set in via_build_pcms */
3409 .open = via_dig_playback_pcm_open,
3410 .close = via_dig_playback_pcm_close,
3411 .prepare = via_dig_playback_pcm_prepare,
3412 .cleanup = via_dig_playback_pcm_cleanup
3416 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3422 /* fill in the dac_nids table from the parsed pin configuration */
3423 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3424 const struct auto_pin_cfg *cfg)
3429 spec->multiout.num_dacs = cfg->line_outs;
3431 spec->multiout.dac_nids = spec->private_dac_nids;
3433 for (i = 0; i < 4; i++) {
3434 nid = cfg->line_out_pins[i];
3436 /* config dac list */
3438 case AUTO_SEQ_FRONT:
3439 spec->multiout.dac_nids[i] = 0x10;
3441 case AUTO_SEQ_CENLFE:
3442 spec->multiout.dac_nids[i] = 0x24;
3444 case AUTO_SEQ_SURROUND:
3445 spec->multiout.dac_nids[i] = 0x11;
3448 spec->multiout.dac_nids[i] = 0x25;
3457 /* add playback controls from the parsed DAC table */
3458 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3459 const struct auto_pin_cfg *cfg)
3462 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3463 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3464 hda_nid_t nid, nid_vol = 0;
3467 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3468 nid = cfg->line_out_pins[i];
3473 nid_vol = nid_vols[i];
3475 if (i == AUTO_SEQ_CENLFE) {
3477 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3478 "Center Playback Volume",
3479 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3483 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3484 "LFE Playback Volume",
3485 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3489 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3490 "Center Playback Switch",
3491 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3495 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3496 "LFE Playback Switch",
3497 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3501 } else if (i == AUTO_SEQ_FRONT) {
3502 /* add control to mixer index 0 */
3503 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3504 "Master Front Playback Volume",
3505 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3509 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3510 "Master Front Playback Switch",
3511 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3516 /* add control to PW3 */
3517 sprintf(name, "%s Playback Volume", chname[i]);
3518 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3519 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3523 sprintf(name, "%s Playback Switch", chname[i]);
3524 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3525 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
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_vol, 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_vol, 3, 0,
3548 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3555 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3556 spec->hp_independent_mode_index = 1;
3558 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3559 "Headphone Playback Volume",
3560 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3563 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3564 "Headphone Playback Switch",
3565 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3569 create_hp_imux(spec);
3574 /* create playback/capture controls for input pins */
3575 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
3576 const struct auto_pin_cfg *cfg)
3578 static char *labels[] = {
3579 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3581 struct hda_input_mux *imux = &spec->private_imux[0];
3582 int i, err, idx = 0;
3584 /* for internal loopback recording select */
3585 imux->items[imux->num_items].label = "Stereo Mixer";
3586 imux->items[imux->num_items].index = idx;
3589 for (i = 0; i < AUTO_PIN_LAST; i++) {
3590 if (!cfg->input_pins[i])
3593 switch (cfg->input_pins[i]) {
3594 case 0x1a: /* Mic */
3598 case 0x1b: /* Line In */
3602 case 0x1e: /* Front Mic */
3610 err = via_new_analog_input(spec, labels[i], idx, 0x16);
3613 imux->items[imux->num_items].label = labels[i];
3614 imux->items[imux->num_items].index = idx;
3620 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3622 struct via_spec *spec = codec->spec;
3625 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3628 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3631 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3632 return 0; /* can't find valid BIOS pin config */
3634 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3637 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3640 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
3644 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3646 if (spec->autocfg.dig_outs)
3647 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3648 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3649 if (spec->autocfg.dig_in_pin)
3650 spec->dig_in_nid = VT1708B_DIGIN_NID;
3652 if (spec->kctls.list)
3653 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3655 spec->input_mux = &spec->private_imux[0];
3660 via_smart51_build(spec);
3664 #ifdef CONFIG_SND_HDA_POWER_SAVE
3665 static struct hda_amp_list vt1708B_loopbacks[] = {
3666 { 0x16, HDA_INPUT, 1 },
3667 { 0x16, HDA_INPUT, 2 },
3668 { 0x16, HDA_INPUT, 3 },
3669 { 0x16, HDA_INPUT, 4 },
3673 static int patch_vt1708S(struct hda_codec *codec);
3674 static int patch_vt1708B_8ch(struct hda_codec *codec)
3676 struct via_spec *spec;
3679 if (get_codec_type(codec) == VT1708BCE)
3680 return patch_vt1708S(codec);
3681 /* create a codec specific record */
3682 spec = via_new_spec(codec);
3686 /* automatic parse from the BIOS config */
3687 err = vt1708B_parse_auto_config(codec);
3692 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3693 "from BIOS. Using genenic mode...\n");
3696 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3697 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3699 spec->stream_name_analog = "VT1708B Analog";
3700 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3701 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3703 spec->stream_name_digital = "VT1708B Digital";
3704 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3705 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3707 if (!spec->adc_nids && spec->input_mux) {
3708 spec->adc_nids = vt1708B_adc_nids;
3709 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3710 get_mux_nids(codec);
3711 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3715 codec->patch_ops = via_patch_ops;
3717 codec->patch_ops.init = via_auto_init;
3718 codec->patch_ops.unsol_event = via_unsol_event;
3719 #ifdef CONFIG_SND_HDA_POWER_SAVE
3720 spec->loopback.amplist = vt1708B_loopbacks;
3726 static int patch_vt1708B_4ch(struct hda_codec *codec)
3728 struct via_spec *spec;
3731 /* create a codec specific record */
3732 spec = via_new_spec(codec);
3736 /* automatic parse from the BIOS config */
3737 err = vt1708B_parse_auto_config(codec);
3742 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3743 "from BIOS. Using genenic mode...\n");
3746 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3747 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3749 spec->stream_name_analog = "VT1708B Analog";
3750 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3751 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3753 spec->stream_name_digital = "VT1708B Digital";
3754 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3755 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3757 if (!spec->adc_nids && spec->input_mux) {
3758 spec->adc_nids = vt1708B_adc_nids;
3759 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3760 get_mux_nids(codec);
3761 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3765 codec->patch_ops = via_patch_ops;
3767 codec->patch_ops.init = via_auto_init;
3768 codec->patch_ops.unsol_event = via_unsol_event;
3769 #ifdef CONFIG_SND_HDA_POWER_SAVE
3770 spec->loopback.amplist = vt1708B_loopbacks;
3776 /* Patch for VT1708S */
3778 /* capture mixer elements */
3779 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3780 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3781 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3782 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3783 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3784 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3785 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3789 /* The multiple "Capture Source" controls confuse alsamixer
3790 * So call somewhat different..
3792 /* .name = "Capture Source", */
3793 .name = "Input Source",
3795 .info = via_mux_enum_info,
3796 .get = via_mux_enum_get,
3797 .put = via_mux_enum_put,
3802 static struct hda_verb vt1708S_volume_init_verbs[] = {
3803 /* Unmute ADC0-1 and set the default input to mic-in */
3804 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3805 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3807 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3808 * analog-loopback mixer widget */
3809 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3810 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3811 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3812 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3813 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3814 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3816 /* Setup default input of PW4 to MW0 */
3817 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3818 /* PW9, PW10 Output enable */
3819 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3820 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3821 /* Enable Mic Boost Volume backdoor */
3823 /* don't bybass mixer */
3828 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3829 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3830 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3831 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3832 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3833 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3834 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3835 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3836 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3837 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3841 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3845 .nid = 0x10, /* NID to query formats and rates */
3847 .open = via_playback_pcm_open,
3848 .prepare = via_playback_multi_pcm_prepare,
3849 .cleanup = via_playback_multi_pcm_cleanup,
3850 .close = via_pcm_open_close
3854 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3858 .nid = 0x13, /* NID to query formats and rates */
3860 .open = via_pcm_open_close,
3861 .prepare = via_capture_pcm_prepare,
3862 .cleanup = via_capture_pcm_cleanup,
3863 .close = via_pcm_open_close
3867 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3871 /* NID is set in via_build_pcms */
3873 .open = via_dig_playback_pcm_open,
3874 .close = via_dig_playback_pcm_close,
3875 .prepare = via_dig_playback_pcm_prepare,
3876 .cleanup = via_dig_playback_pcm_cleanup
3880 /* fill in the dac_nids table from the parsed pin configuration */
3881 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3882 const struct auto_pin_cfg *cfg)
3887 spec->multiout.num_dacs = cfg->line_outs;
3889 spec->multiout.dac_nids = spec->private_dac_nids;
3891 for (i = 0; i < 4; i++) {
3892 nid = cfg->line_out_pins[i];
3894 /* config dac list */
3896 case AUTO_SEQ_FRONT:
3897 spec->multiout.dac_nids[i] = 0x10;
3899 case AUTO_SEQ_CENLFE:
3900 spec->multiout.dac_nids[i] = 0x24;
3902 case AUTO_SEQ_SURROUND:
3903 spec->multiout.dac_nids[i] = 0x11;
3906 spec->multiout.dac_nids[i] = 0x25;
3915 /* add playback controls from the parsed DAC table */
3916 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3917 const struct auto_pin_cfg *cfg)
3920 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3921 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3922 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3923 hda_nid_t nid, nid_vol, nid_mute;
3926 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3927 nid = cfg->line_out_pins[i];
3932 nid_vol = nid_vols[i];
3933 nid_mute = nid_mutes[i];
3935 if (i == AUTO_SEQ_CENLFE) {
3937 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3938 "Center Playback Volume",
3939 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3943 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3944 "LFE Playback Volume",
3945 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3949 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3950 "Center Playback Switch",
3951 HDA_COMPOSE_AMP_VAL(nid_mute,
3956 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3957 "LFE Playback Switch",
3958 HDA_COMPOSE_AMP_VAL(nid_mute,
3963 } else if (i == AUTO_SEQ_FRONT) {
3964 /* add control to mixer index 0 */
3965 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3966 "Master Front Playback Volume",
3967 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3971 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3972 "Master Front Playback Switch",
3973 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
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,
3993 sprintf(name, "%s Playback Volume", chname[i]);
3994 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3995 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3999 sprintf(name, "%s Playback Switch", chname[i]);
4000 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
4001 HDA_COMPOSE_AMP_VAL(nid_mute,
4012 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4019 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
4020 spec->hp_independent_mode_index = 1;
4022 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4023 "Headphone Playback Volume",
4024 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
4028 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4029 "Headphone Playback Switch",
4030 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4034 create_hp_imux(spec);
4039 /* create playback/capture controls for input pins */
4040 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
4041 const struct auto_pin_cfg *cfg)
4043 static char *labels[] = {
4044 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4046 struct hda_input_mux *imux = &spec->private_imux[0];
4047 int i, err, idx = 0;
4049 /* for internal loopback recording select */
4050 imux->items[imux->num_items].label = "Stereo Mixer";
4051 imux->items[imux->num_items].index = 5;
4054 for (i = 0; i < AUTO_PIN_LAST; i++) {
4055 if (!cfg->input_pins[i])
4058 switch (cfg->input_pins[i]) {
4059 case 0x1a: /* Mic */
4063 case 0x1b: /* Line In */
4067 case 0x1e: /* Front Mic */
4075 err = via_new_analog_input(spec, labels[i], idx, 0x16);
4078 imux->items[imux->num_items].label = labels[i];
4079 imux->items[imux->num_items].index = idx-1;
4085 /* fill out digital output widgets; one for master and one for slave outputs */
4086 static void fill_dig_outs(struct hda_codec *codec)
4088 struct via_spec *spec = codec->spec;
4091 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4095 nid = spec->autocfg.dig_out_pins[i];
4098 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4101 if (!spec->multiout.dig_out_nid)
4102 spec->multiout.dig_out_nid = nid;
4104 spec->slave_dig_outs[0] = nid;
4105 break; /* at most two dig outs */
4110 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4112 struct via_spec *spec = codec->spec;
4115 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4118 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4121 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4122 return 0; /* can't find valid BIOS pin config */
4124 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4127 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4130 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4134 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4136 fill_dig_outs(codec);
4138 if (spec->kctls.list)
4139 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4141 spec->input_mux = &spec->private_imux[0];
4146 via_smart51_build(spec);
4150 #ifdef CONFIG_SND_HDA_POWER_SAVE
4151 static struct hda_amp_list vt1708S_loopbacks[] = {
4152 { 0x16, HDA_INPUT, 1 },
4153 { 0x16, HDA_INPUT, 2 },
4154 { 0x16, HDA_INPUT, 3 },
4155 { 0x16, HDA_INPUT, 4 },
4160 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4161 int offset, int num_steps, int step_size)
4163 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4164 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4165 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4166 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4167 (0 << AC_AMPCAP_MUTE_SHIFT));
4170 static int patch_vt1708S(struct hda_codec *codec)
4172 struct via_spec *spec;
4175 /* create a codec specific record */
4176 spec = via_new_spec(codec);
4180 /* automatic parse from the BIOS config */
4181 err = vt1708S_parse_auto_config(codec);
4186 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4187 "from BIOS. Using genenic mode...\n");
4190 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4191 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4193 if (codec->vendor_id == 0x11060440)
4194 spec->stream_name_analog = "VT1818S Analog";
4196 spec->stream_name_analog = "VT1708S Analog";
4197 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4198 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4200 if (codec->vendor_id == 0x11060440)
4201 spec->stream_name_digital = "VT1818S Digital";
4203 spec->stream_name_digital = "VT1708S Digital";
4204 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4206 if (!spec->adc_nids && spec->input_mux) {
4207 spec->adc_nids = vt1708S_adc_nids;
4208 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4209 get_mux_nids(codec);
4210 override_mic_boost(codec, 0x1a, 0, 3, 40);
4211 override_mic_boost(codec, 0x1e, 0, 3, 40);
4212 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4216 codec->patch_ops = via_patch_ops;
4218 codec->patch_ops.init = via_auto_init;
4219 codec->patch_ops.unsol_event = via_unsol_event;
4220 #ifdef CONFIG_SND_HDA_POWER_SAVE
4221 spec->loopback.amplist = vt1708S_loopbacks;
4224 /* correct names for VT1708BCE */
4225 if (get_codec_type(codec) == VT1708BCE) {
4226 kfree(codec->chip_name);
4227 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4228 snprintf(codec->bus->card->mixername,
4229 sizeof(codec->bus->card->mixername),
4230 "%s %s", codec->vendor_name, codec->chip_name);
4231 spec->stream_name_analog = "VT1708BCE Analog";
4232 spec->stream_name_digital = "VT1708BCE Digital";
4237 /* Patch for VT1702 */
4239 /* capture mixer elements */
4240 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4241 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4242 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4243 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4244 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4245 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4246 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4247 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4250 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4251 /* The multiple "Capture Source" controls confuse alsamixer
4252 * So call somewhat different..
4254 /* .name = "Capture Source", */
4255 .name = "Input Source",
4257 .info = via_mux_enum_info,
4258 .get = via_mux_enum_get,
4259 .put = via_mux_enum_put,
4264 static struct hda_verb vt1702_volume_init_verbs[] = {
4266 * Unmute ADC0-1 and set the default input to mic-in
4268 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4269 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4270 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4273 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4276 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4277 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4278 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4279 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4280 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4281 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4283 /* Setup default input of PW4 to MW0 */
4284 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4285 /* PW6 PW7 Output enable */
4286 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4287 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4295 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4296 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4297 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4298 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4299 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4300 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4301 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4305 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4309 .nid = 0x10, /* NID to query formats and rates */
4311 .open = via_playback_pcm_open,
4312 .prepare = via_playback_multi_pcm_prepare,
4313 .cleanup = via_playback_multi_pcm_cleanup,
4314 .close = via_pcm_open_close
4318 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4322 .nid = 0x12, /* NID to query formats and rates */
4324 .open = via_pcm_open_close,
4325 .prepare = via_capture_pcm_prepare,
4326 .cleanup = via_capture_pcm_cleanup,
4327 .close = via_pcm_open_close
4331 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4335 /* NID is set in via_build_pcms */
4337 .open = via_dig_playback_pcm_open,
4338 .close = via_dig_playback_pcm_close,
4339 .prepare = via_dig_playback_pcm_prepare,
4340 .cleanup = via_dig_playback_pcm_cleanup
4344 /* fill in the dac_nids table from the parsed pin configuration */
4345 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4346 const struct auto_pin_cfg *cfg)
4348 spec->multiout.num_dacs = 1;
4349 spec->multiout.dac_nids = spec->private_dac_nids;
4351 if (cfg->line_out_pins[0]) {
4352 /* config dac list */
4353 spec->multiout.dac_nids[0] = 0x10;
4359 /* add playback controls from the parsed DAC table */
4360 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4361 const struct auto_pin_cfg *cfg)
4365 if (!cfg->line_out_pins[0])
4368 /* add control to mixer index 0 */
4369 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4370 "Master Front Playback Volume",
4371 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4374 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4375 "Master Front Playback Switch",
4376 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4381 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4382 "Front Playback Volume",
4383 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4386 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4387 "Front Playback Switch",
4388 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4395 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4398 struct hda_input_mux *imux;
4399 static const char *texts[] = { "ON", "OFF", NULL};
4402 spec->multiout.hp_nid = 0x1D;
4403 spec->hp_independent_mode_index = 0;
4405 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4406 "Headphone Playback Volume",
4407 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4411 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4412 "Headphone Playback Switch",
4413 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4417 imux = &spec->private_imux[1];
4419 /* for hp mode select */
4421 while (texts[i] != NULL) {
4422 imux->items[imux->num_items].label = texts[i];
4423 imux->items[imux->num_items].index = i;
4428 spec->hp_mux = &spec->private_imux[1];
4432 /* create playback/capture controls for input pins */
4433 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
4434 const struct auto_pin_cfg *cfg)
4436 static char *labels[] = {
4437 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4439 struct hda_input_mux *imux = &spec->private_imux[0];
4440 int i, err, idx = 0;
4442 /* for internal loopback recording select */
4443 imux->items[imux->num_items].label = "Stereo Mixer";
4444 imux->items[imux->num_items].index = 3;
4447 for (i = 0; i < AUTO_PIN_LAST; i++) {
4448 if (!cfg->input_pins[i])
4451 switch (cfg->input_pins[i]) {
4452 case 0x14: /* Mic */
4456 case 0x15: /* Line In */
4460 case 0x18: /* Front Mic */
4464 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
4467 imux->items[imux->num_items].label = labels[i];
4468 imux->items[imux->num_items].index = idx-1;
4474 static int vt1702_parse_auto_config(struct hda_codec *codec)
4476 struct via_spec *spec = codec->spec;
4479 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4482 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4485 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4486 return 0; /* can't find valid BIOS pin config */
4488 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4491 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4494 /* limit AA path volume to 0 dB */
4495 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4496 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4497 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4498 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4499 (1 << AC_AMPCAP_MUTE_SHIFT));
4500 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
4504 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4506 fill_dig_outs(codec);
4508 if (spec->kctls.list)
4509 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4511 spec->input_mux = &spec->private_imux[0];
4519 #ifdef CONFIG_SND_HDA_POWER_SAVE
4520 static struct hda_amp_list vt1702_loopbacks[] = {
4521 { 0x1A, HDA_INPUT, 1 },
4522 { 0x1A, HDA_INPUT, 2 },
4523 { 0x1A, HDA_INPUT, 3 },
4524 { 0x1A, HDA_INPUT, 4 },
4529 static int patch_vt1702(struct hda_codec *codec)
4531 struct via_spec *spec;
4534 /* create a codec specific record */
4535 spec = via_new_spec(codec);
4539 /* automatic parse from the BIOS config */
4540 err = vt1702_parse_auto_config(codec);
4545 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4546 "from BIOS. Using genenic mode...\n");
4549 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4550 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4552 spec->stream_name_analog = "VT1702 Analog";
4553 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4554 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4556 spec->stream_name_digital = "VT1702 Digital";
4557 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4559 if (!spec->adc_nids && spec->input_mux) {
4560 spec->adc_nids = vt1702_adc_nids;
4561 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4562 get_mux_nids(codec);
4563 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4567 codec->patch_ops = via_patch_ops;
4569 codec->patch_ops.init = via_auto_init;
4570 codec->patch_ops.unsol_event = via_unsol_event;
4571 #ifdef CONFIG_SND_HDA_POWER_SAVE
4572 spec->loopback.amplist = vt1702_loopbacks;
4578 /* Patch for VT1718S */
4580 /* capture mixer elements */
4581 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4582 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4583 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4584 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4585 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4586 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4587 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4590 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4591 /* The multiple "Capture Source" controls confuse alsamixer
4592 * So call somewhat different..
4594 .name = "Input Source",
4596 .info = via_mux_enum_info,
4597 .get = via_mux_enum_get,
4598 .put = via_mux_enum_put,
4603 static struct hda_verb vt1718S_volume_init_verbs[] = {
4605 * Unmute ADC0-1 and set the default input to mic-in
4607 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4608 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4611 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4614 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4615 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4616 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4617 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4618 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4619 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4621 /* Setup default input of Front HP to MW9 */
4622 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4623 /* PW9 PW10 Output enable */
4624 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4625 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4626 /* PW11 Input enable */
4627 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4628 /* Enable Boost Volume backdoor */
4630 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4631 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4632 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4633 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4634 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4635 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4636 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4637 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4638 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4639 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4640 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4641 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4642 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4643 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4644 /* Unmute MW4's index 0 */
4645 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4650 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4651 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4652 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4653 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4654 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4655 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4656 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4657 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4658 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4659 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4663 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4667 .nid = 0x8, /* NID to query formats and rates */
4669 .open = via_playback_pcm_open,
4670 .prepare = via_playback_multi_pcm_prepare,
4671 .cleanup = via_playback_multi_pcm_cleanup,
4672 .close = via_pcm_open_close,
4676 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4680 .nid = 0x10, /* NID to query formats and rates */
4682 .open = via_pcm_open_close,
4683 .prepare = via_capture_pcm_prepare,
4684 .cleanup = via_capture_pcm_cleanup,
4685 .close = via_pcm_open_close,
4689 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4693 /* NID is set in via_build_pcms */
4695 .open = via_dig_playback_pcm_open,
4696 .close = via_dig_playback_pcm_close,
4697 .prepare = via_dig_playback_pcm_prepare,
4698 .cleanup = via_dig_playback_pcm_cleanup
4702 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4708 /* fill in the dac_nids table from the parsed pin configuration */
4709 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4710 const struct auto_pin_cfg *cfg)
4715 spec->multiout.num_dacs = cfg->line_outs;
4717 spec->multiout.dac_nids = spec->private_dac_nids;
4719 for (i = 0; i < 4; i++) {
4720 nid = cfg->line_out_pins[i];
4722 /* config dac list */
4724 case AUTO_SEQ_FRONT:
4725 spec->multiout.dac_nids[i] = 0x8;
4727 case AUTO_SEQ_CENLFE:
4728 spec->multiout.dac_nids[i] = 0xa;
4730 case AUTO_SEQ_SURROUND:
4731 spec->multiout.dac_nids[i] = 0x9;
4734 spec->multiout.dac_nids[i] = 0xb;
4743 /* add playback controls from the parsed DAC table */
4744 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4745 const struct auto_pin_cfg *cfg)
4748 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4749 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4750 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4751 hda_nid_t nid, nid_vol, nid_mute = 0;
4754 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4755 nid = cfg->line_out_pins[i];
4759 nid_vol = nid_vols[i];
4760 nid_mute = nid_mutes[i];
4762 if (i == AUTO_SEQ_CENLFE) {
4764 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4765 "Center Playback Volume",
4766 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4770 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4771 "LFE Playback Volume",
4772 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4776 err = via_add_control(
4777 spec, VIA_CTL_WIDGET_MUTE,
4778 "Center Playback Switch",
4779 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4783 err = via_add_control(
4784 spec, VIA_CTL_WIDGET_MUTE,
4785 "LFE Playback Switch",
4786 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4790 } else if (i == AUTO_SEQ_FRONT) {
4792 sprintf(name, "%s Playback Volume", chname[i]);
4793 err = via_add_control(
4794 spec, VIA_CTL_WIDGET_VOL, name,
4795 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4798 sprintf(name, "%s Playback Switch", chname[i]);
4799 err = via_add_control(
4800 spec, VIA_CTL_WIDGET_MUTE, name,
4801 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4806 sprintf(name, "%s Playback Volume", chname[i]);
4807 err = via_add_control(
4808 spec, VIA_CTL_WIDGET_VOL, name,
4809 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4812 sprintf(name, "%s Playback Switch", chname[i]);
4813 err = via_add_control(
4814 spec, VIA_CTL_WIDGET_MUTE, name,
4815 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4824 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4831 spec->multiout.hp_nid = 0xc; /* AOW4 */
4832 spec->hp_independent_mode_index = 1;
4834 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4835 "Headphone Playback Volume",
4836 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4840 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4841 "Headphone Playback Switch",
4842 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4846 create_hp_imux(spec);
4850 /* create playback/capture controls for input pins */
4851 static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4852 const struct auto_pin_cfg *cfg)
4854 static char *labels[] = {
4855 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4857 struct hda_input_mux *imux = &spec->private_imux[0];
4858 int i, err, idx = 0;
4860 /* for internal loopback recording select */
4861 imux->items[imux->num_items].label = "Stereo Mixer";
4862 imux->items[imux->num_items].index = 5;
4865 for (i = 0; i < AUTO_PIN_LAST; i++) {
4866 if (!cfg->input_pins[i])
4869 switch (cfg->input_pins[i]) {
4870 case 0x2b: /* Mic */
4874 case 0x2a: /* Line In */
4878 case 0x29: /* Front Mic */
4886 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4889 imux->items[imux->num_items].label = labels[i];
4890 imux->items[imux->num_items].index = idx;
4896 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4898 struct via_spec *spec = codec->spec;
4901 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4905 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4908 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4909 return 0; /* can't find valid BIOS pin config */
4911 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4914 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4917 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4921 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4923 fill_dig_outs(codec);
4925 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4926 spec->dig_in_nid = 0x13;
4928 if (spec->kctls.list)
4929 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4931 spec->input_mux = &spec->private_imux[0];
4936 via_smart51_build(spec);
4941 #ifdef CONFIG_SND_HDA_POWER_SAVE
4942 static struct hda_amp_list vt1718S_loopbacks[] = {
4943 { 0x21, HDA_INPUT, 1 },
4944 { 0x21, HDA_INPUT, 2 },
4945 { 0x21, HDA_INPUT, 3 },
4946 { 0x21, HDA_INPUT, 4 },
4951 static int patch_vt1718S(struct hda_codec *codec)
4953 struct via_spec *spec;
4956 /* create a codec specific record */
4957 spec = via_new_spec(codec);
4961 /* automatic parse from the BIOS config */
4962 err = vt1718S_parse_auto_config(codec);
4967 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4968 "from BIOS. Using genenic mode...\n");
4971 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4972 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4974 if (codec->vendor_id == 0x11060441)
4975 spec->stream_name_analog = "VT2020 Analog";
4976 else if (codec->vendor_id == 0x11064441)
4977 spec->stream_name_analog = "VT1828S Analog";
4979 spec->stream_name_analog = "VT1718S Analog";
4980 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4981 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4983 if (codec->vendor_id == 0x11060441)
4984 spec->stream_name_digital = "VT2020 Digital";
4985 else if (codec->vendor_id == 0x11064441)
4986 spec->stream_name_digital = "VT1828S Digital";
4988 spec->stream_name_digital = "VT1718S Digital";
4989 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4990 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4991 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4993 if (!spec->adc_nids && spec->input_mux) {
4994 spec->adc_nids = vt1718S_adc_nids;
4995 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4996 get_mux_nids(codec);
4997 override_mic_boost(codec, 0x2b, 0, 3, 40);
4998 override_mic_boost(codec, 0x29, 0, 3, 40);
4999 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
5003 codec->patch_ops = via_patch_ops;
5005 codec->patch_ops.init = via_auto_init;
5006 codec->patch_ops.unsol_event = via_unsol_event;
5008 #ifdef CONFIG_SND_HDA_POWER_SAVE
5009 spec->loopback.amplist = vt1718S_loopbacks;
5015 /* Patch for VT1716S */
5017 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
5018 struct snd_ctl_elem_info *uinfo)
5020 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
5022 uinfo->value.integer.min = 0;
5023 uinfo->value.integer.max = 1;
5027 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
5028 struct snd_ctl_elem_value *ucontrol)
5030 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5033 index = snd_hda_codec_read(codec, 0x26, 0,
5034 AC_VERB_GET_CONNECT_SEL, 0);
5036 *ucontrol->value.integer.value = index;
5041 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
5042 struct snd_ctl_elem_value *ucontrol)
5044 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5045 struct via_spec *spec = codec->spec;
5046 int index = *ucontrol->value.integer.value;
5048 snd_hda_codec_write(codec, 0x26, 0,
5049 AC_VERB_SET_CONNECT_SEL, index);
5050 spec->dmic_enabled = index;
5051 set_jack_power_state(codec);
5056 /* capture mixer elements */
5057 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
5058 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
5059 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
5060 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
5061 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
5062 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
5063 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5066 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5067 .name = "Input Source",
5069 .info = via_mux_enum_info,
5070 .get = via_mux_enum_get,
5071 .put = via_mux_enum_put,
5076 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5077 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5079 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5080 .name = "Digital Mic Capture Switch",
5081 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
5083 .info = vt1716s_dmic_info,
5084 .get = vt1716s_dmic_get,
5085 .put = vt1716s_dmic_put,
5091 /* mono-out mixer elements */
5092 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5093 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5097 static struct hda_verb vt1716S_volume_init_verbs[] = {
5099 * Unmute ADC0-1 and set the default input to mic-in
5101 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5102 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5105 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5108 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5109 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5110 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5111 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5112 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5113 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5115 /* MUX Indices: Stereo Mixer = 5 */
5116 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5118 /* Setup default input of PW4 to MW0 */
5119 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5121 /* Setup default input of SW1 as MW0 */
5122 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5124 /* Setup default input of SW4 as AOW0 */
5125 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5127 /* PW9 PW10 Output enable */
5128 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5129 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5131 /* Unmute SW1, PW12 */
5132 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5133 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5134 /* PW12 Output enable */
5135 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5136 /* Enable Boost Volume backdoor */
5138 /* don't bybass mixer */
5140 /* Enable mono output */
5146 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5147 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5148 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5149 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5150 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5151 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5152 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5153 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5154 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5155 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5159 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5163 .nid = 0x10, /* NID to query formats and rates */
5165 .open = via_playback_pcm_open,
5166 .prepare = via_playback_multi_pcm_prepare,
5167 .cleanup = via_playback_multi_pcm_cleanup,
5168 .close = via_pcm_open_close,
5172 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5176 .nid = 0x13, /* NID to query formats and rates */
5178 .open = via_pcm_open_close,
5179 .prepare = via_capture_pcm_prepare,
5180 .cleanup = via_capture_pcm_cleanup,
5181 .close = via_pcm_open_close,
5185 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5189 /* NID is set in via_build_pcms */
5191 .open = via_dig_playback_pcm_open,
5192 .close = via_dig_playback_pcm_close,
5193 .prepare = via_dig_playback_pcm_prepare,
5194 .cleanup = via_dig_playback_pcm_cleanup
5198 /* fill in the dac_nids table from the parsed pin configuration */
5199 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5200 const struct auto_pin_cfg *cfg)
5204 spec->multiout.num_dacs = cfg->line_outs;
5206 spec->multiout.dac_nids = spec->private_dac_nids;
5208 for (i = 0; i < 3; i++) {
5209 nid = cfg->line_out_pins[i];
5211 /* config dac list */
5213 case AUTO_SEQ_FRONT:
5214 spec->multiout.dac_nids[i] = 0x10;
5216 case AUTO_SEQ_CENLFE:
5217 spec->multiout.dac_nids[i] = 0x25;
5219 case AUTO_SEQ_SURROUND:
5220 spec->multiout.dac_nids[i] = 0x11;
5229 /* add playback controls from the parsed DAC table */
5230 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5231 const struct auto_pin_cfg *cfg)
5234 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5235 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5236 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5237 hda_nid_t nid, nid_vol, nid_mute;
5240 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5241 nid = cfg->line_out_pins[i];
5246 nid_vol = nid_vols[i];
5247 nid_mute = nid_mutes[i];
5249 if (i == AUTO_SEQ_CENLFE) {
5250 err = via_add_control(
5251 spec, VIA_CTL_WIDGET_VOL,
5252 "Center Playback Volume",
5253 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5256 err = via_add_control(
5257 spec, VIA_CTL_WIDGET_VOL,
5258 "LFE Playback Volume",
5259 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5262 err = via_add_control(
5263 spec, VIA_CTL_WIDGET_MUTE,
5264 "Center Playback Switch",
5265 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5269 err = via_add_control(
5270 spec, VIA_CTL_WIDGET_MUTE,
5271 "LFE Playback Switch",
5272 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5276 } else if (i == AUTO_SEQ_FRONT) {
5278 err = via_add_control(
5279 spec, VIA_CTL_WIDGET_VOL,
5280 "Master Front Playback Volume",
5281 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5284 err = via_add_control(
5285 spec, VIA_CTL_WIDGET_MUTE,
5286 "Master Front Playback Switch",
5287 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5291 sprintf(name, "%s Playback Volume", chname[i]);
5292 err = via_add_control(
5293 spec, VIA_CTL_WIDGET_VOL, name,
5294 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5297 sprintf(name, "%s Playback Switch", chname[i]);
5298 err = via_add_control(
5299 spec, VIA_CTL_WIDGET_MUTE, name,
5300 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5305 sprintf(name, "%s Playback Volume", chname[i]);
5306 err = via_add_control(
5307 spec, VIA_CTL_WIDGET_VOL, name,
5308 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5311 sprintf(name, "%s Playback Switch", chname[i]);
5312 err = via_add_control(
5313 spec, VIA_CTL_WIDGET_MUTE, name,
5314 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5323 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5330 spec->multiout.hp_nid = 0x25; /* AOW3 */
5331 spec->hp_independent_mode_index = 1;
5333 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5334 "Headphone Playback Volume",
5335 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5339 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5340 "Headphone Playback Switch",
5341 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5345 create_hp_imux(spec);
5349 /* create playback/capture controls for input pins */
5350 static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5351 const struct auto_pin_cfg *cfg)
5353 static char *labels[] = {
5354 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5356 struct hda_input_mux *imux = &spec->private_imux[0];
5357 int i, err, idx = 0;
5359 /* for internal loopback recording select */
5360 imux->items[imux->num_items].label = "Stereo Mixer";
5361 imux->items[imux->num_items].index = 5;
5364 for (i = 0; i < AUTO_PIN_LAST; i++) {
5365 if (!cfg->input_pins[i])
5368 switch (cfg->input_pins[i]) {
5369 case 0x1a: /* Mic */
5373 case 0x1b: /* Line In */
5377 case 0x1e: /* Front Mic */
5385 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5388 imux->items[imux->num_items].label = labels[i];
5389 imux->items[imux->num_items].index = idx-1;
5395 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5397 struct via_spec *spec = codec->spec;
5400 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5403 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5406 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5407 return 0; /* can't find valid BIOS pin config */
5409 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5412 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5415 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5419 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5421 fill_dig_outs(codec);
5423 if (spec->kctls.list)
5424 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5426 spec->input_mux = &spec->private_imux[0];
5431 via_smart51_build(spec);
5436 #ifdef CONFIG_SND_HDA_POWER_SAVE
5437 static struct hda_amp_list vt1716S_loopbacks[] = {
5438 { 0x16, HDA_INPUT, 1 },
5439 { 0x16, HDA_INPUT, 2 },
5440 { 0x16, HDA_INPUT, 3 },
5441 { 0x16, HDA_INPUT, 4 },
5446 static int patch_vt1716S(struct hda_codec *codec)
5448 struct via_spec *spec;
5451 /* create a codec specific record */
5452 spec = via_new_spec(codec);
5456 /* automatic parse from the BIOS config */
5457 err = vt1716S_parse_auto_config(codec);
5462 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5463 "from BIOS. Using genenic mode...\n");
5466 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5467 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5469 spec->stream_name_analog = "VT1716S Analog";
5470 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5471 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5473 spec->stream_name_digital = "VT1716S Digital";
5474 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5476 if (!spec->adc_nids && spec->input_mux) {
5477 spec->adc_nids = vt1716S_adc_nids;
5478 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5479 get_mux_nids(codec);
5480 override_mic_boost(codec, 0x1a, 0, 3, 40);
5481 override_mic_boost(codec, 0x1e, 0, 3, 40);
5482 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5486 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5489 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5491 codec->patch_ops = via_patch_ops;
5493 codec->patch_ops.init = via_auto_init;
5494 codec->patch_ops.unsol_event = via_unsol_event;
5496 #ifdef CONFIG_SND_HDA_POWER_SAVE
5497 spec->loopback.amplist = vt1716S_loopbacks;
5505 /* capture mixer elements */
5506 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5507 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5508 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5509 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5510 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5511 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5512 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5515 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5516 /* The multiple "Capture Source" controls confuse alsamixer
5517 * So call somewhat different..
5519 /* .name = "Capture Source", */
5520 .name = "Input Source",
5522 .info = via_mux_enum_info,
5523 .get = via_mux_enum_get,
5524 .put = via_mux_enum_put,
5529 static struct hda_verb vt2002P_volume_init_verbs[] = {
5531 * Unmute ADC0-1 and set the default input to mic-in
5533 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5534 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5537 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5540 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5541 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5542 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5543 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5544 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5545 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5547 /* MUX Indices: Mic = 0 */
5548 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5549 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5551 /* PW9 Output enable */
5552 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5554 /* Enable Boost Volume backdoor */
5557 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5558 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5559 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5560 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5561 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5562 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5563 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5564 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5565 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5567 /* set MUX0/1/4/8 = 0 (AOW0) */
5568 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5569 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5570 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5571 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5573 /* set PW0 index=0 (MW0) */
5574 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5576 /* Enable AOW0 to MW9 */
5582 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5583 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5584 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5585 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5586 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5587 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5588 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5589 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5593 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5597 .nid = 0x8, /* NID to query formats and rates */
5599 .open = via_playback_pcm_open,
5600 .prepare = via_playback_multi_pcm_prepare,
5601 .cleanup = via_playback_multi_pcm_cleanup,
5602 .close = via_pcm_open_close,
5606 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5610 .nid = 0x10, /* NID to query formats and rates */
5612 .open = via_pcm_open_close,
5613 .prepare = via_capture_pcm_prepare,
5614 .cleanup = via_capture_pcm_cleanup,
5615 .close = via_pcm_open_close,
5619 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5623 /* NID is set in via_build_pcms */
5625 .open = via_dig_playback_pcm_open,
5626 .close = via_dig_playback_pcm_close,
5627 .prepare = via_dig_playback_pcm_prepare,
5628 .cleanup = via_dig_playback_pcm_cleanup
5632 /* fill in the dac_nids table from the parsed pin configuration */
5633 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5634 const struct auto_pin_cfg *cfg)
5636 spec->multiout.num_dacs = 1;
5637 spec->multiout.dac_nids = spec->private_dac_nids;
5638 if (cfg->line_out_pins[0])
5639 spec->multiout.dac_nids[0] = 0x8;
5643 /* add playback controls from the parsed DAC table */
5644 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5645 const struct auto_pin_cfg *cfg)
5649 if (!cfg->line_out_pins[0])
5653 /* Line-Out: PortE */
5654 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5655 "Master Front Playback Volume",
5656 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5659 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5660 "Master Front Playback Switch",
5661 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5668 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5675 spec->multiout.hp_nid = 0x9;
5676 spec->hp_independent_mode_index = 1;
5678 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5679 "Headphone Playback Volume",
5680 HDA_COMPOSE_AMP_VAL(
5681 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5685 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5686 "Headphone Playback Switch",
5687 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5691 create_hp_imux(spec);
5695 /* create playback/capture controls for input pins */
5696 static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5697 const struct auto_pin_cfg *cfg)
5699 static char *labels[] = {
5700 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5702 struct hda_input_mux *imux = &spec->private_imux[0];
5703 int i, err, idx = 0;
5705 for (i = 0; i < AUTO_PIN_LAST; i++) {
5706 if (!cfg->input_pins[i])
5709 switch (cfg->input_pins[i]) {
5710 case 0x2b: /* Mic */
5714 case 0x2a: /* Line In */
5718 case 0x29: /* Front Mic */
5722 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5725 imux->items[imux->num_items].label = labels[i];
5726 imux->items[imux->num_items].index = idx;
5730 /* build volume/mute control of loopback */
5731 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5735 /* for internal loopback recording select */
5736 imux->items[imux->num_items].label = "Stereo Mixer";
5737 imux->items[imux->num_items].index = 3;
5740 /* for digital mic select */
5741 imux->items[imux->num_items].label = "Digital Mic";
5742 imux->items[imux->num_items].index = 4;
5748 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5750 struct via_spec *spec = codec->spec;
5754 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5758 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5762 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5763 return 0; /* can't find valid BIOS pin config */
5765 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5768 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5771 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5775 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5777 fill_dig_outs(codec);
5779 if (spec->kctls.list)
5780 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5782 spec->input_mux = &spec->private_imux[0];
5790 #ifdef CONFIG_SND_HDA_POWER_SAVE
5791 static struct hda_amp_list vt2002P_loopbacks[] = {
5792 { 0x21, HDA_INPUT, 0 },
5793 { 0x21, HDA_INPUT, 1 },
5794 { 0x21, HDA_INPUT, 2 },
5800 /* patch for vt2002P */
5801 static int patch_vt2002P(struct hda_codec *codec)
5803 struct via_spec *spec;
5806 /* create a codec specific record */
5807 spec = via_new_spec(codec);
5811 /* automatic parse from the BIOS config */
5812 err = vt2002P_parse_auto_config(codec);
5817 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5818 "from BIOS. Using genenic mode...\n");
5821 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5822 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5824 spec->stream_name_analog = "VT2002P Analog";
5825 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5826 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5828 spec->stream_name_digital = "VT2002P Digital";
5829 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5831 if (!spec->adc_nids && spec->input_mux) {
5832 spec->adc_nids = vt2002P_adc_nids;
5833 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5834 get_mux_nids(codec);
5835 override_mic_boost(codec, 0x2b, 0, 3, 40);
5836 override_mic_boost(codec, 0x29, 0, 3, 40);
5837 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5841 codec->patch_ops = via_patch_ops;
5843 codec->patch_ops.init = via_auto_init;
5844 codec->patch_ops.unsol_event = via_unsol_event;
5846 #ifdef CONFIG_SND_HDA_POWER_SAVE
5847 spec->loopback.amplist = vt2002P_loopbacks;
5855 /* capture mixer elements */
5856 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5857 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5858 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5859 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5860 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5861 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5862 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5865 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5866 /* The multiple "Capture Source" controls confuse alsamixer
5867 * So call somewhat different..
5869 .name = "Input Source",
5871 .info = via_mux_enum_info,
5872 .get = via_mux_enum_get,
5873 .put = via_mux_enum_put,
5878 static struct hda_verb vt1812_volume_init_verbs[] = {
5880 * Unmute ADC0-1 and set the default input to mic-in
5882 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5883 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5886 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5889 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5890 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5891 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5892 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5893 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5894 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5896 /* MUX Indices: Mic = 0 */
5897 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5898 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5900 /* PW9 Output enable */
5901 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5903 /* Enable Boost Volume backdoor */
5906 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5907 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5908 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5909 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5910 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5911 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5912 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5913 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5914 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5915 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5916 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5918 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5919 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5920 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5921 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5922 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5923 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5925 /* Enable AOW0 to MW9 */
5931 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5932 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5933 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5934 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5935 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5936 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5937 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5938 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5939 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5943 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5947 .nid = 0x8, /* NID to query formats and rates */
5949 .open = via_playback_pcm_open,
5950 .prepare = via_playback_multi_pcm_prepare,
5951 .cleanup = via_playback_multi_pcm_cleanup,
5952 .close = via_pcm_open_close,
5956 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5960 .nid = 0x10, /* NID to query formats and rates */
5962 .open = via_pcm_open_close,
5963 .prepare = via_capture_pcm_prepare,
5964 .cleanup = via_capture_pcm_cleanup,
5965 .close = via_pcm_open_close,
5969 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5973 /* NID is set in via_build_pcms */
5975 .open = via_dig_playback_pcm_open,
5976 .close = via_dig_playback_pcm_close,
5977 .prepare = via_dig_playback_pcm_prepare,
5978 .cleanup = via_dig_playback_pcm_cleanup
5981 /* fill in the dac_nids table from the parsed pin configuration */
5982 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5983 const struct auto_pin_cfg *cfg)
5985 spec->multiout.num_dacs = 1;
5986 spec->multiout.dac_nids = spec->private_dac_nids;
5987 if (cfg->line_out_pins[0])
5988 spec->multiout.dac_nids[0] = 0x8;
5993 /* add playback controls from the parsed DAC table */
5994 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5995 const struct auto_pin_cfg *cfg)
5999 if (!cfg->line_out_pins[0])
6002 /* Line-Out: PortE */
6003 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
6004 "Master Front Playback Volume",
6005 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
6008 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
6009 "Master Front Playback Switch",
6010 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
6017 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
6024 spec->multiout.hp_nid = 0x9;
6025 spec->hp_independent_mode_index = 1;
6028 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
6029 "Headphone Playback Volume",
6030 HDA_COMPOSE_AMP_VAL(
6031 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
6035 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
6036 "Headphone Playback Switch",
6037 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
6041 create_hp_imux(spec);
6045 /* create playback/capture controls for input pins */
6046 static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
6047 const struct auto_pin_cfg *cfg)
6049 static char *labels[] = {
6050 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
6052 struct hda_input_mux *imux = &spec->private_imux[0];
6053 int i, err, idx = 0;
6055 for (i = 0; i < AUTO_PIN_LAST; i++) {
6056 if (!cfg->input_pins[i])
6059 switch (cfg->input_pins[i]) {
6060 case 0x2b: /* Mic */
6064 case 0x2a: /* Line In */
6068 case 0x29: /* Front Mic */
6072 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6075 imux->items[imux->num_items].label = labels[i];
6076 imux->items[imux->num_items].index = idx;
6079 /* build volume/mute control of loopback */
6080 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6084 /* for internal loopback recording select */
6085 imux->items[imux->num_items].label = "Stereo Mixer";
6086 imux->items[imux->num_items].index = 5;
6089 /* for digital mic select */
6090 imux->items[imux->num_items].label = "Digital Mic";
6091 imux->items[imux->num_items].index = 6;
6097 static int vt1812_parse_auto_config(struct hda_codec *codec)
6099 struct via_spec *spec = codec->spec;
6103 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6106 fill_dig_outs(codec);
6107 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6111 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6112 return 0; /* can't find valid BIOS pin config */
6114 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6117 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6120 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6124 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6126 fill_dig_outs(codec);
6128 if (spec->kctls.list)
6129 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6131 spec->input_mux = &spec->private_imux[0];
6139 #ifdef CONFIG_SND_HDA_POWER_SAVE
6140 static struct hda_amp_list vt1812_loopbacks[] = {
6141 { 0x21, HDA_INPUT, 0 },
6142 { 0x21, HDA_INPUT, 1 },
6143 { 0x21, HDA_INPUT, 2 },
6149 /* patch for vt1812 */
6150 static int patch_vt1812(struct hda_codec *codec)
6152 struct via_spec *spec;
6155 /* create a codec specific record */
6156 spec = via_new_spec(codec);
6160 /* automatic parse from the BIOS config */
6161 err = vt1812_parse_auto_config(codec);
6166 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6167 "from BIOS. Using genenic mode...\n");
6171 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6172 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6174 spec->stream_name_analog = "VT1812 Analog";
6175 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6176 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6178 spec->stream_name_digital = "VT1812 Digital";
6179 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6182 if (!spec->adc_nids && spec->input_mux) {
6183 spec->adc_nids = vt1812_adc_nids;
6184 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6185 get_mux_nids(codec);
6186 override_mic_boost(codec, 0x2b, 0, 3, 40);
6187 override_mic_boost(codec, 0x29, 0, 3, 40);
6188 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6192 codec->patch_ops = via_patch_ops;
6194 codec->patch_ops.init = via_auto_init;
6195 codec->patch_ops.unsol_event = via_unsol_event;
6197 #ifdef CONFIG_SND_HDA_POWER_SAVE
6198 spec->loopback.amplist = vt1812_loopbacks;
6207 static struct hda_codec_preset snd_hda_preset_via[] = {
6208 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6209 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6210 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6211 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6212 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6213 .patch = patch_vt1709_10ch},
6214 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6215 .patch = patch_vt1709_10ch},
6216 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6217 .patch = patch_vt1709_10ch},
6218 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6219 .patch = patch_vt1709_10ch},
6220 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6221 .patch = patch_vt1709_6ch},
6222 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6223 .patch = patch_vt1709_6ch},
6224 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6225 .patch = patch_vt1709_6ch},
6226 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6227 .patch = patch_vt1709_6ch},
6228 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6229 .patch = patch_vt1708B_8ch},
6230 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6231 .patch = patch_vt1708B_8ch},
6232 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6233 .patch = patch_vt1708B_8ch},
6234 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6235 .patch = patch_vt1708B_8ch},
6236 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6237 .patch = patch_vt1708B_4ch},
6238 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6239 .patch = patch_vt1708B_4ch},
6240 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6241 .patch = patch_vt1708B_4ch},
6242 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6243 .patch = patch_vt1708B_4ch},
6244 { .id = 0x11060397, .name = "VT1708S",
6245 .patch = patch_vt1708S},
6246 { .id = 0x11061397, .name = "VT1708S",
6247 .patch = patch_vt1708S},
6248 { .id = 0x11062397, .name = "VT1708S",
6249 .patch = patch_vt1708S},
6250 { .id = 0x11063397, .name = "VT1708S",
6251 .patch = patch_vt1708S},
6252 { .id = 0x11064397, .name = "VT1708S",
6253 .patch = patch_vt1708S},
6254 { .id = 0x11065397, .name = "VT1708S",
6255 .patch = patch_vt1708S},
6256 { .id = 0x11066397, .name = "VT1708S",
6257 .patch = patch_vt1708S},
6258 { .id = 0x11067397, .name = "VT1708S",
6259 .patch = patch_vt1708S},
6260 { .id = 0x11060398, .name = "VT1702",
6261 .patch = patch_vt1702},
6262 { .id = 0x11061398, .name = "VT1702",
6263 .patch = patch_vt1702},
6264 { .id = 0x11062398, .name = "VT1702",
6265 .patch = patch_vt1702},
6266 { .id = 0x11063398, .name = "VT1702",
6267 .patch = patch_vt1702},
6268 { .id = 0x11064398, .name = "VT1702",
6269 .patch = patch_vt1702},
6270 { .id = 0x11065398, .name = "VT1702",
6271 .patch = patch_vt1702},
6272 { .id = 0x11066398, .name = "VT1702",
6273 .patch = patch_vt1702},
6274 { .id = 0x11067398, .name = "VT1702",
6275 .patch = patch_vt1702},
6276 { .id = 0x11060428, .name = "VT1718S",
6277 .patch = patch_vt1718S},
6278 { .id = 0x11064428, .name = "VT1718S",
6279 .patch = patch_vt1718S},
6280 { .id = 0x11060441, .name = "VT2020",
6281 .patch = patch_vt1718S},
6282 { .id = 0x11064441, .name = "VT1828S",
6283 .patch = patch_vt1718S},
6284 { .id = 0x11060433, .name = "VT1716S",
6285 .patch = patch_vt1716S},
6286 { .id = 0x1106a721, .name = "VT1716S",
6287 .patch = patch_vt1716S},
6288 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6289 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6290 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6291 { .id = 0x11060440, .name = "VT1818S",
6292 .patch = patch_vt1708S},
6296 MODULE_ALIAS("snd-hda-codec-id:1106*");
6298 static struct hda_codec_preset_list via_list = {
6299 .preset = snd_hda_preset_via,
6300 .owner = THIS_MODULE,
6303 MODULE_LICENSE("GPL");
6304 MODULE_DESCRIPTION("VIA HD-audio codec");
6306 static int __init patch_via_init(void)
6308 return snd_hda_add_codec_preset(&via_list);
6311 static void __exit patch_via_exit(void)
6313 snd_hda_delete_codec_preset(&via_list);
6316 module_init(patch_via_init)
6317 module_exit(patch_via_exit)