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_nid(codec, kctl, i, spec->mux_nids[i]);
1915 /* other nid->control mapping */
1916 for (i = 0; i < spec->num_mixers; i++) {
1917 for (knew = spec->mixers[i]; knew->name; knew++) {
1918 if (knew->iface != NID_MAPPING)
1920 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1923 err = snd_hda_add_nid(codec, kctl, 0,
1928 /* init power states */
1929 set_jack_power_state(codec);
1930 analog_low_current_mode(codec, 1);
1932 via_free_kctls(codec); /* no longer needed */
1936 static int via_build_pcms(struct hda_codec *codec)
1938 struct via_spec *spec = codec->spec;
1939 struct hda_pcm *info = spec->pcm_rec;
1941 codec->num_pcms = 1;
1942 codec->pcm_info = info;
1944 info->name = spec->stream_name_analog;
1945 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1946 *(spec->stream_analog_playback);
1947 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1948 spec->multiout.dac_nids[0];
1949 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1950 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1952 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1953 spec->multiout.max_channels;
1955 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1958 info->name = spec->stream_name_digital;
1959 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1960 if (spec->multiout.dig_out_nid) {
1961 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1962 *(spec->stream_digital_playback);
1963 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1964 spec->multiout.dig_out_nid;
1966 if (spec->dig_in_nid) {
1967 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1968 *(spec->stream_digital_capture);
1969 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1977 static void via_free(struct hda_codec *codec)
1979 struct via_spec *spec = codec->spec;
1984 via_free_kctls(codec);
1985 vt1708_stop_hp_work(spec);
1989 /* mute internal speaker if HP is plugged */
1990 static void via_hp_automute(struct hda_codec *codec)
1992 unsigned int present = 0;
1993 struct via_spec *spec = codec->spec;
1995 present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
1997 if (!spec->hp_independent_mode) {
1998 struct snd_ctl_elem_id id;
2000 snd_hda_codec_amp_stereo(
2001 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
2002 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2004 memset(&id, 0, sizeof(id));
2005 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2006 strcpy(id.name, "Front Playback Switch");
2007 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2012 /* mute mono out if HP or Line out is plugged */
2013 static void via_mono_automute(struct hda_codec *codec)
2015 unsigned int hp_present, lineout_present;
2016 struct via_spec *spec = codec->spec;
2018 if (spec->codec_type != VT1716S)
2021 lineout_present = snd_hda_jack_detect(codec,
2022 spec->autocfg.line_out_pins[0]);
2024 /* Mute Mono Out if Line Out is plugged */
2025 if (lineout_present) {
2026 snd_hda_codec_amp_stereo(
2027 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
2031 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2033 if (!spec->hp_independent_mode)
2034 snd_hda_codec_amp_stereo(
2035 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
2036 hp_present ? HDA_AMP_MUTE : 0);
2039 static void via_gpio_control(struct hda_codec *codec)
2041 unsigned int gpio_data;
2042 unsigned int vol_counter;
2044 unsigned int master_vol;
2046 struct via_spec *spec = codec->spec;
2048 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
2049 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
2051 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
2052 0xF84, 0) & 0x3F0000) >> 16;
2054 vol = vol_counter & 0x1F;
2055 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
2056 AC_VERB_GET_AMP_GAIN_MUTE,
2059 if (gpio_data == 0x02) {
2060 /* unmute line out */
2061 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
2062 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
2064 if (vol_counter & 0x20) {
2065 /* decrease volume */
2066 if (vol > master_vol)
2068 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2072 /* increase volume */
2073 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2075 ((master_vol+vol) > 0x2A) ? 0x2A :
2078 } else if (!(gpio_data & 0x02)) {
2080 snd_hda_codec_amp_stereo(codec,
2081 spec->autocfg.line_out_pins[0],
2082 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2087 /* mute Internal-Speaker if HP is plugged */
2088 static void via_speaker_automute(struct hda_codec *codec)
2090 unsigned int hp_present;
2091 struct via_spec *spec = codec->spec;
2093 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2096 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2098 if (!spec->hp_independent_mode) {
2099 struct snd_ctl_elem_id id;
2100 snd_hda_codec_amp_stereo(
2101 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2102 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2104 memset(&id, 0, sizeof(id));
2105 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2106 strcpy(id.name, "Speaker Playback Switch");
2107 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2112 /* mute line-out and internal speaker if HP is plugged */
2113 static void via_hp_bind_automute(struct hda_codec *codec)
2115 /* use long instead of int below just to avoid an internal compiler
2116 * error with gcc 4.0.x
2118 unsigned long hp_present, present = 0;
2119 struct via_spec *spec = codec->spec;
2122 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2125 hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
2127 present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
2129 if (!spec->hp_independent_mode) {
2130 /* Mute Line-Outs */
2131 for (i = 0; i < spec->autocfg.line_outs; i++)
2132 snd_hda_codec_amp_stereo(
2133 codec, spec->autocfg.line_out_pins[i],
2135 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2137 present = hp_present;
2140 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2141 snd_hda_codec_amp_stereo(
2142 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2143 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2147 /* unsolicited event for jack sensing */
2148 static void via_unsol_event(struct hda_codec *codec,
2152 if (res & VIA_HP_EVENT)
2153 via_hp_automute(codec);
2154 if (res & VIA_GPIO_EVENT)
2155 via_gpio_control(codec);
2156 if (res & VIA_JACK_EVENT)
2157 set_jack_power_state(codec);
2158 if (res & VIA_MONO_EVENT)
2159 via_mono_automute(codec);
2160 if (res & VIA_SPEAKER_EVENT)
2161 via_speaker_automute(codec);
2162 if (res & VIA_BIND_HP_EVENT)
2163 via_hp_bind_automute(codec);
2166 static int via_init(struct hda_codec *codec)
2168 struct via_spec *spec = codec->spec;
2170 for (i = 0; i < spec->num_iverbs; i++)
2171 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2173 spec->codec_type = get_codec_type(codec);
2174 if (spec->codec_type == VT1708BCE)
2175 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2177 /* Lydia Add for EAPD enable */
2178 if (!spec->dig_in_nid) { /* No Digital In connection */
2179 if (spec->dig_in_pin) {
2180 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2181 AC_VERB_SET_PIN_WIDGET_CONTROL,
2183 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2184 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2186 } else /* enable SPDIF-input pin */
2187 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2188 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2190 /* assign slave outs */
2191 if (spec->slave_dig_outs[0])
2192 codec->slave_dig_outs = spec->slave_dig_outs;
2197 #ifdef SND_HDA_NEEDS_RESUME
2198 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2200 struct via_spec *spec = codec->spec;
2201 vt1708_stop_hp_work(spec);
2206 #ifdef CONFIG_SND_HDA_POWER_SAVE
2207 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2209 struct via_spec *spec = codec->spec;
2210 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2216 static struct hda_codec_ops via_patch_ops = {
2217 .build_controls = via_build_controls,
2218 .build_pcms = via_build_pcms,
2221 #ifdef SND_HDA_NEEDS_RESUME
2222 .suspend = via_suspend,
2224 #ifdef CONFIG_SND_HDA_POWER_SAVE
2225 .check_power_status = via_check_power_status,
2229 /* fill in the dac_nids table from the parsed pin configuration */
2230 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2231 const struct auto_pin_cfg *cfg)
2236 spec->multiout.num_dacs = cfg->line_outs;
2238 spec->multiout.dac_nids = spec->private_dac_nids;
2240 for (i = 0; i < 4; i++) {
2241 nid = cfg->line_out_pins[i];
2243 /* config dac list */
2245 case AUTO_SEQ_FRONT:
2246 spec->multiout.dac_nids[i] = 0x10;
2248 case AUTO_SEQ_CENLFE:
2249 spec->multiout.dac_nids[i] = 0x12;
2251 case AUTO_SEQ_SURROUND:
2252 spec->multiout.dac_nids[i] = 0x11;
2255 spec->multiout.dac_nids[i] = 0x13;
2264 /* add playback controls from the parsed DAC table */
2265 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2266 const struct auto_pin_cfg *cfg)
2269 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2270 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2273 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2274 nid = cfg->line_out_pins[i];
2279 nid_vol = nid_vols[i];
2281 if (i == AUTO_SEQ_CENLFE) {
2283 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2284 "Center Playback Volume",
2285 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2289 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2290 "LFE Playback Volume",
2291 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2295 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2296 "Center Playback Switch",
2297 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2301 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2302 "LFE Playback Switch",
2303 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2307 } else if (i == AUTO_SEQ_FRONT) {
2308 /* add control to mixer index 0 */
2309 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2310 "Master Front Playback Volume",
2311 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2315 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2316 "Master Front Playback Switch",
2317 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2322 /* add control to PW3 */
2323 sprintf(name, "%s Playback Volume", chname[i]);
2324 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2325 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2329 sprintf(name, "%s Playback Switch", chname[i]);
2330 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2331 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2336 sprintf(name, "%s Playback Volume", chname[i]);
2337 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2338 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2342 sprintf(name, "%s Playback Switch", chname[i]);
2343 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2344 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2354 static void create_hp_imux(struct via_spec *spec)
2357 struct hda_input_mux *imux = &spec->private_imux[1];
2358 static const char *texts[] = { "OFF", "ON", NULL};
2360 /* for hp mode select */
2362 while (texts[i] != NULL) {
2363 imux->items[imux->num_items].label = texts[i];
2364 imux->items[imux->num_items].index = i;
2369 spec->hp_mux = &spec->private_imux[1];
2372 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2379 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2380 spec->hp_independent_mode_index = 1;
2382 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2383 "Headphone Playback Volume",
2384 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2387 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2388 "Headphone Playback Switch",
2389 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2393 create_hp_imux(spec);
2398 /* create playback/capture controls for input pins */
2399 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
2400 const struct auto_pin_cfg *cfg)
2402 static char *labels[] = {
2403 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2405 struct hda_input_mux *imux = &spec->private_imux[0];
2406 int i, err, idx = 0;
2408 /* for internal loopback recording select */
2409 imux->items[imux->num_items].label = "Stereo Mixer";
2410 imux->items[imux->num_items].index = idx;
2413 for (i = 0; i < AUTO_PIN_LAST; i++) {
2414 if (!cfg->input_pins[i])
2417 switch (cfg->input_pins[i]) {
2418 case 0x1d: /* Mic */
2422 case 0x1e: /* Line In */
2426 case 0x21: /* Front Mic */
2434 err = via_new_analog_input(spec, labels[i], idx, 0x17);
2437 imux->items[imux->num_items].label = labels[i];
2438 imux->items[imux->num_items].index = idx;
2444 #ifdef CONFIG_SND_HDA_POWER_SAVE
2445 static struct hda_amp_list vt1708_loopbacks[] = {
2446 { 0x17, HDA_INPUT, 1 },
2447 { 0x17, HDA_INPUT, 2 },
2448 { 0x17, HDA_INPUT, 3 },
2449 { 0x17, HDA_INPUT, 4 },
2454 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2456 unsigned int def_conf;
2457 unsigned char seqassoc;
2459 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2460 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2461 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2462 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2463 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2464 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2465 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2471 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2472 struct snd_ctl_elem_value *ucontrol)
2474 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2475 struct via_spec *spec = codec->spec;
2477 if (spec->codec_type != VT1708)
2479 spec->vt1708_jack_detectect =
2480 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2481 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2485 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2486 struct snd_ctl_elem_value *ucontrol)
2488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2489 struct via_spec *spec = codec->spec;
2492 if (spec->codec_type != VT1708)
2494 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2495 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2496 == !spec->vt1708_jack_detectect;
2497 if (spec->vt1708_jack_detectect) {
2498 mute_aa_path(codec, 1);
2499 notify_aa_path_ctls(codec);
2504 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2506 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2507 .name = "Jack Detect",
2509 .info = snd_ctl_boolean_mono_info,
2510 .get = vt1708_jack_detectect_get,
2511 .put = vt1708_jack_detectect_put,
2516 static int vt1708_parse_auto_config(struct hda_codec *codec)
2518 struct via_spec *spec = codec->spec;
2521 /* Add HP and CD pin config connect bit re-config action */
2522 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2523 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2525 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2528 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2531 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2532 return 0; /* can't find valid BIOS pin config */
2534 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2537 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2540 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
2543 /* add jack detect on/off control */
2544 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2548 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2550 if (spec->autocfg.dig_outs)
2551 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2552 spec->dig_in_pin = VT1708_DIGIN_PIN;
2553 if (spec->autocfg.dig_in_pin)
2554 spec->dig_in_nid = VT1708_DIGIN_NID;
2556 if (spec->kctls.list)
2557 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2559 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2561 spec->input_mux = &spec->private_imux[0];
2566 via_smart51_build(spec);
2570 /* init callback for auto-configuration model -- overriding the default init */
2571 static int via_auto_init(struct hda_codec *codec)
2573 struct via_spec *spec = codec->spec;
2576 via_auto_init_multi_out(codec);
2577 via_auto_init_hp_out(codec);
2578 via_auto_init_analog_input(codec);
2579 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2580 via_hp_bind_automute(codec);
2582 via_hp_automute(codec);
2583 via_speaker_automute(codec);
2589 static void vt1708_update_hp_jack_state(struct work_struct *work)
2591 struct via_spec *spec = container_of(work, struct via_spec,
2592 vt1708_hp_work.work);
2593 if (spec->codec_type != VT1708)
2595 /* if jack state toggled */
2596 if (spec->vt1708_hp_present
2597 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
2598 spec->vt1708_hp_present ^= 1;
2599 via_hp_automute(spec->codec);
2601 vt1708_start_hp_work(spec);
2604 static int get_mux_nids(struct hda_codec *codec)
2606 struct via_spec *spec = codec->spec;
2607 hda_nid_t nid, conn[8];
2611 for (i = 0; i < spec->num_adc_nids; i++) {
2612 nid = spec->adc_nids[i];
2614 type = get_wcaps_type(get_wcaps(codec, nid));
2615 if (type == AC_WID_PIN)
2617 n = snd_hda_get_connections(codec, nid, conn,
2622 spec->mux_nids[i] = nid;
2631 static int patch_vt1708(struct hda_codec *codec)
2633 struct via_spec *spec;
2636 /* create a codec specific record */
2637 spec = via_new_spec(codec);
2641 /* automatic parse from the BIOS config */
2642 err = vt1708_parse_auto_config(codec);
2647 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2648 "from BIOS. Using genenic mode...\n");
2652 spec->stream_name_analog = "VT1708 Analog";
2653 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2654 /* disable 32bit format on VT1708 */
2655 if (codec->vendor_id == 0x11061708)
2656 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2657 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2659 spec->stream_name_digital = "VT1708 Digital";
2660 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2661 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2664 if (!spec->adc_nids && spec->input_mux) {
2665 spec->adc_nids = vt1708_adc_nids;
2666 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2667 get_mux_nids(codec);
2668 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2672 codec->patch_ops = via_patch_ops;
2674 codec->patch_ops.init = via_auto_init;
2675 #ifdef CONFIG_SND_HDA_POWER_SAVE
2676 spec->loopback.amplist = vt1708_loopbacks;
2678 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2682 /* capture mixer elements */
2683 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2684 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2685 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2686 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2687 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2688 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2689 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2691 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2692 /* The multiple "Capture Source" controls confuse alsamixer
2693 * So call somewhat different..
2695 /* .name = "Capture Source", */
2696 .name = "Input Source",
2698 .info = via_mux_enum_info,
2699 .get = via_mux_enum_get,
2700 .put = via_mux_enum_put,
2705 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2706 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2707 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2712 * generic initialization of ADC, input mixers and output mixers
2714 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2716 * Unmute ADC0-2 and set the default input to mic-in
2718 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2719 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2720 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2723 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2726 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2727 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2728 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2729 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2730 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2731 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2734 * Set up output selector (0x1a, 0x1b, 0x29)
2736 /* set vol=0 to output mixers */
2737 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2738 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2739 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2742 * Unmute PW3 and PW4
2744 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2745 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2747 /* Set input of PW4 as MW0 */
2748 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2749 /* PW9 Output enable */
2750 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2754 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2758 .nid = 0x10, /* NID to query formats and rates */
2760 .open = via_playback_pcm_open,
2761 .prepare = via_playback_multi_pcm_prepare,
2762 .cleanup = via_playback_multi_pcm_cleanup,
2766 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2770 .nid = 0x10, /* NID to query formats and rates */
2772 .open = via_playback_pcm_open,
2773 .prepare = via_playback_multi_pcm_prepare,
2774 .cleanup = via_playback_multi_pcm_cleanup,
2778 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2782 .nid = 0x14, /* NID to query formats and rates */
2784 .prepare = via_capture_pcm_prepare,
2785 .cleanup = via_capture_pcm_cleanup
2789 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2793 /* NID is set in via_build_pcms */
2795 .open = via_dig_playback_pcm_open,
2796 .close = via_dig_playback_pcm_close
2800 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2806 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2807 const struct auto_pin_cfg *cfg)
2812 if (cfg->line_outs == 4) /* 10 channels */
2813 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2814 else if (cfg->line_outs == 3) /* 6 channels */
2815 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2817 spec->multiout.dac_nids = spec->private_dac_nids;
2819 if (cfg->line_outs == 4) { /* 10 channels */
2820 for (i = 0; i < cfg->line_outs; i++) {
2821 nid = cfg->line_out_pins[i];
2823 /* config dac list */
2825 case AUTO_SEQ_FRONT:
2827 spec->multiout.dac_nids[i] = 0x10;
2829 case AUTO_SEQ_CENLFE:
2831 spec->multiout.dac_nids[i] = 0x12;
2833 case AUTO_SEQ_SURROUND:
2835 spec->multiout.dac_nids[i] = 0x11;
2839 spec->multiout.dac_nids[i] = 0x27;
2846 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2848 } else if (cfg->line_outs == 3) { /* 6 channels */
2849 for (i = 0; i < cfg->line_outs; i++) {
2850 nid = cfg->line_out_pins[i];
2852 /* config dac list */
2854 case AUTO_SEQ_FRONT:
2856 spec->multiout.dac_nids[i] = 0x10;
2858 case AUTO_SEQ_CENLFE:
2860 spec->multiout.dac_nids[i] = 0x12;
2862 case AUTO_SEQ_SURROUND:
2864 spec->multiout.dac_nids[i] = 0x11;
2876 /* add playback controls from the parsed DAC table */
2877 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2878 const struct auto_pin_cfg *cfg)
2881 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2882 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2885 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2886 nid = cfg->line_out_pins[i];
2891 nid_vol = nid_vols[i];
2893 if (i == AUTO_SEQ_CENLFE) {
2895 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2896 "Center Playback Volume",
2897 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2901 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2902 "LFE Playback Volume",
2903 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2907 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2908 "Center Playback Switch",
2909 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2913 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2914 "LFE Playback Switch",
2915 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2919 } else if (i == AUTO_SEQ_FRONT) {
2920 /* ADD control to mixer index 0 */
2921 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2922 "Master Front Playback Volume",
2923 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2927 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2928 "Master Front Playback Switch",
2929 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2934 /* add control to PW3 */
2935 sprintf(name, "%s Playback Volume", chname[i]);
2936 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2937 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2941 sprintf(name, "%s Playback Switch", chname[i]);
2942 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2943 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2947 } else if (i == AUTO_SEQ_SURROUND) {
2948 sprintf(name, "%s Playback Volume", chname[i]);
2949 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2950 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2954 sprintf(name, "%s Playback Switch", chname[i]);
2955 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2956 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2960 } else if (i == AUTO_SEQ_SIDE) {
2961 sprintf(name, "%s Playback Volume", chname[i]);
2962 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2963 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2967 sprintf(name, "%s Playback Switch", chname[i]);
2968 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2969 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2979 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2986 if (spec->multiout.num_dacs == 5) /* 10 channels */
2987 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2988 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2989 spec->multiout.hp_nid = 0;
2990 spec->hp_independent_mode_index = 1;
2992 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2993 "Headphone Playback Volume",
2994 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2997 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2998 "Headphone Playback Switch",
2999 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3006 /* create playback/capture controls for input pins */
3007 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
3008 const struct auto_pin_cfg *cfg)
3010 static char *labels[] = {
3011 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3013 struct hda_input_mux *imux = &spec->private_imux[0];
3014 int i, err, idx = 0;
3016 /* for internal loopback recording select */
3017 imux->items[imux->num_items].label = "Stereo Mixer";
3018 imux->items[imux->num_items].index = idx;
3021 for (i = 0; i < AUTO_PIN_LAST; i++) {
3022 if (!cfg->input_pins[i])
3025 switch (cfg->input_pins[i]) {
3026 case 0x1d: /* Mic */
3030 case 0x1e: /* Line In */
3034 case 0x21: /* Front Mic */
3042 err = via_new_analog_input(spec, labels[i], idx, 0x18);
3045 imux->items[imux->num_items].label = labels[i];
3046 imux->items[imux->num_items].index = idx;
3052 static int vt1709_parse_auto_config(struct hda_codec *codec)
3054 struct via_spec *spec = codec->spec;
3057 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3060 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3063 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3064 return 0; /* can't find valid BIOS pin config */
3066 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3069 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3072 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
3076 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3078 if (spec->autocfg.dig_outs)
3079 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3080 spec->dig_in_pin = VT1709_DIGIN_PIN;
3081 if (spec->autocfg.dig_in_pin)
3082 spec->dig_in_nid = VT1709_DIGIN_NID;
3084 if (spec->kctls.list)
3085 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3087 spec->input_mux = &spec->private_imux[0];
3092 via_smart51_build(spec);
3096 #ifdef CONFIG_SND_HDA_POWER_SAVE
3097 static struct hda_amp_list vt1709_loopbacks[] = {
3098 { 0x18, HDA_INPUT, 1 },
3099 { 0x18, HDA_INPUT, 2 },
3100 { 0x18, HDA_INPUT, 3 },
3101 { 0x18, HDA_INPUT, 4 },
3106 static int patch_vt1709_10ch(struct hda_codec *codec)
3108 struct via_spec *spec;
3111 /* create a codec specific record */
3112 spec = via_new_spec(codec);
3116 err = vt1709_parse_auto_config(codec);
3121 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3122 "Using genenic mode...\n");
3125 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3126 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3128 spec->stream_name_analog = "VT1709 Analog";
3129 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3130 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3132 spec->stream_name_digital = "VT1709 Digital";
3133 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3134 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3137 if (!spec->adc_nids && spec->input_mux) {
3138 spec->adc_nids = vt1709_adc_nids;
3139 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3140 get_mux_nids(codec);
3141 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3145 codec->patch_ops = via_patch_ops;
3147 codec->patch_ops.init = via_auto_init;
3148 codec->patch_ops.unsol_event = via_unsol_event;
3149 #ifdef CONFIG_SND_HDA_POWER_SAVE
3150 spec->loopback.amplist = vt1709_loopbacks;
3156 * generic initialization of ADC, input mixers and output mixers
3158 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3160 * Unmute ADC0-2 and set the default input to mic-in
3162 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3163 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3164 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3167 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3170 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3171 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3172 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3173 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3174 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3175 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3178 * Set up output selector (0x1a, 0x1b, 0x29)
3180 /* set vol=0 to output mixers */
3181 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3182 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3183 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3186 * Unmute PW3 and PW4
3188 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3189 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3191 /* Set input of PW4 as MW0 */
3192 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3193 /* PW9 Output enable */
3194 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3198 static int patch_vt1709_6ch(struct hda_codec *codec)
3200 struct via_spec *spec;
3203 /* create a codec specific record */
3204 spec = via_new_spec(codec);
3208 err = vt1709_parse_auto_config(codec);
3213 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3214 "Using genenic mode...\n");
3217 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3218 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3220 spec->stream_name_analog = "VT1709 Analog";
3221 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3222 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3224 spec->stream_name_digital = "VT1709 Digital";
3225 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3226 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3229 if (!spec->adc_nids && spec->input_mux) {
3230 spec->adc_nids = vt1709_adc_nids;
3231 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3232 get_mux_nids(codec);
3233 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3237 codec->patch_ops = via_patch_ops;
3239 codec->patch_ops.init = via_auto_init;
3240 codec->patch_ops.unsol_event = via_unsol_event;
3241 #ifdef CONFIG_SND_HDA_POWER_SAVE
3242 spec->loopback.amplist = vt1709_loopbacks;
3247 /* capture mixer elements */
3248 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3249 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3250 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3251 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3252 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3254 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3255 /* The multiple "Capture Source" controls confuse alsamixer
3256 * So call somewhat different..
3258 /* .name = "Capture Source", */
3259 .name = "Input Source",
3261 .info = via_mux_enum_info,
3262 .get = via_mux_enum_get,
3263 .put = via_mux_enum_put,
3268 * generic initialization of ADC, input mixers and output mixers
3270 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3272 * Unmute ADC0-1 and set the default input to mic-in
3274 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3275 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3278 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3281 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3282 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3283 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3284 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3285 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3286 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3289 * Set up output mixers
3291 /* set vol=0 to output mixers */
3292 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3293 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3294 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3296 /* Setup default input to PW4 */
3297 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3298 /* PW9 Output enable */
3299 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3300 /* PW10 Input enable */
3301 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3305 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3307 * Unmute ADC0-1 and set the default input to mic-in
3309 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3310 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3313 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3316 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3317 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3318 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3319 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3320 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3321 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3324 * Set up output mixers
3326 /* set vol=0 to output mixers */
3327 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3328 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3329 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3331 /* Setup default input of PW4 to MW0 */
3332 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3333 /* PW9 Output enable */
3334 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3335 /* PW10 Input enable */
3336 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3340 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3341 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3342 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3343 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3344 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3345 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3346 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3347 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3348 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3349 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3353 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3354 struct hda_codec *codec,
3355 struct snd_pcm_substream *substream)
3357 int idle = substream->pstr->substream_opened == 1
3358 && substream->ref_count == 0;
3360 analog_low_current_mode(codec, idle);
3364 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3368 .nid = 0x10, /* NID to query formats and rates */
3370 .open = via_playback_pcm_open,
3371 .prepare = via_playback_multi_pcm_prepare,
3372 .cleanup = via_playback_multi_pcm_cleanup,
3373 .close = via_pcm_open_close
3377 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3381 .nid = 0x10, /* NID to query formats and rates */
3383 .open = via_playback_pcm_open,
3384 .prepare = via_playback_multi_pcm_prepare,
3385 .cleanup = via_playback_multi_pcm_cleanup
3389 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3393 .nid = 0x13, /* NID to query formats and rates */
3395 .open = via_pcm_open_close,
3396 .prepare = via_capture_pcm_prepare,
3397 .cleanup = via_capture_pcm_cleanup,
3398 .close = via_pcm_open_close
3402 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3406 /* NID is set in via_build_pcms */
3408 .open = via_dig_playback_pcm_open,
3409 .close = via_dig_playback_pcm_close,
3410 .prepare = via_dig_playback_pcm_prepare,
3411 .cleanup = via_dig_playback_pcm_cleanup
3415 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3421 /* fill in the dac_nids table from the parsed pin configuration */
3422 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3423 const struct auto_pin_cfg *cfg)
3428 spec->multiout.num_dacs = cfg->line_outs;
3430 spec->multiout.dac_nids = spec->private_dac_nids;
3432 for (i = 0; i < 4; i++) {
3433 nid = cfg->line_out_pins[i];
3435 /* config dac list */
3437 case AUTO_SEQ_FRONT:
3438 spec->multiout.dac_nids[i] = 0x10;
3440 case AUTO_SEQ_CENLFE:
3441 spec->multiout.dac_nids[i] = 0x24;
3443 case AUTO_SEQ_SURROUND:
3444 spec->multiout.dac_nids[i] = 0x11;
3447 spec->multiout.dac_nids[i] = 0x25;
3456 /* add playback controls from the parsed DAC table */
3457 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3458 const struct auto_pin_cfg *cfg)
3461 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3462 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3463 hda_nid_t nid, nid_vol = 0;
3466 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3467 nid = cfg->line_out_pins[i];
3472 nid_vol = nid_vols[i];
3474 if (i == AUTO_SEQ_CENLFE) {
3476 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3477 "Center Playback Volume",
3478 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3482 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3483 "LFE Playback Volume",
3484 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3488 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3489 "Center Playback Switch",
3490 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3494 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3495 "LFE Playback Switch",
3496 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3500 } else if (i == AUTO_SEQ_FRONT) {
3501 /* add control to mixer index 0 */
3502 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3503 "Master Front Playback Volume",
3504 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3508 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3509 "Master Front Playback Switch",
3510 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3515 /* add control to PW3 */
3516 sprintf(name, "%s Playback Volume", chname[i]);
3517 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3518 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3522 sprintf(name, "%s Playback Switch", chname[i]);
3523 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3524 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3529 sprintf(name, "%s Playback Volume", chname[i]);
3530 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3531 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3535 sprintf(name, "%s Playback Switch", chname[i]);
3536 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3537 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3547 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3554 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3555 spec->hp_independent_mode_index = 1;
3557 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3558 "Headphone Playback Volume",
3559 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3562 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3563 "Headphone Playback Switch",
3564 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3568 create_hp_imux(spec);
3573 /* create playback/capture controls for input pins */
3574 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
3575 const struct auto_pin_cfg *cfg)
3577 static char *labels[] = {
3578 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3580 struct hda_input_mux *imux = &spec->private_imux[0];
3581 int i, err, idx = 0;
3583 /* for internal loopback recording select */
3584 imux->items[imux->num_items].label = "Stereo Mixer";
3585 imux->items[imux->num_items].index = idx;
3588 for (i = 0; i < AUTO_PIN_LAST; i++) {
3589 if (!cfg->input_pins[i])
3592 switch (cfg->input_pins[i]) {
3593 case 0x1a: /* Mic */
3597 case 0x1b: /* Line In */
3601 case 0x1e: /* Front Mic */
3609 err = via_new_analog_input(spec, labels[i], idx, 0x16);
3612 imux->items[imux->num_items].label = labels[i];
3613 imux->items[imux->num_items].index = idx;
3619 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3621 struct via_spec *spec = codec->spec;
3624 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3627 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3630 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3631 return 0; /* can't find valid BIOS pin config */
3633 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3636 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3639 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
3643 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3645 if (spec->autocfg.dig_outs)
3646 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3647 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3648 if (spec->autocfg.dig_in_pin)
3649 spec->dig_in_nid = VT1708B_DIGIN_NID;
3651 if (spec->kctls.list)
3652 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3654 spec->input_mux = &spec->private_imux[0];
3659 via_smart51_build(spec);
3663 #ifdef CONFIG_SND_HDA_POWER_SAVE
3664 static struct hda_amp_list vt1708B_loopbacks[] = {
3665 { 0x16, HDA_INPUT, 1 },
3666 { 0x16, HDA_INPUT, 2 },
3667 { 0x16, HDA_INPUT, 3 },
3668 { 0x16, HDA_INPUT, 4 },
3672 static int patch_vt1708S(struct hda_codec *codec);
3673 static int patch_vt1708B_8ch(struct hda_codec *codec)
3675 struct via_spec *spec;
3678 if (get_codec_type(codec) == VT1708BCE)
3679 return patch_vt1708S(codec);
3680 /* create a codec specific record */
3681 spec = via_new_spec(codec);
3685 /* automatic parse from the BIOS config */
3686 err = vt1708B_parse_auto_config(codec);
3691 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3692 "from BIOS. Using genenic mode...\n");
3695 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3696 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3698 spec->stream_name_analog = "VT1708B Analog";
3699 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3700 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3702 spec->stream_name_digital = "VT1708B Digital";
3703 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3704 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3706 if (!spec->adc_nids && spec->input_mux) {
3707 spec->adc_nids = vt1708B_adc_nids;
3708 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3709 get_mux_nids(codec);
3710 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3714 codec->patch_ops = via_patch_ops;
3716 codec->patch_ops.init = via_auto_init;
3717 codec->patch_ops.unsol_event = via_unsol_event;
3718 #ifdef CONFIG_SND_HDA_POWER_SAVE
3719 spec->loopback.amplist = vt1708B_loopbacks;
3725 static int patch_vt1708B_4ch(struct hda_codec *codec)
3727 struct via_spec *spec;
3730 /* create a codec specific record */
3731 spec = via_new_spec(codec);
3735 /* automatic parse from the BIOS config */
3736 err = vt1708B_parse_auto_config(codec);
3741 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3742 "from BIOS. Using genenic mode...\n");
3745 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3746 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3748 spec->stream_name_analog = "VT1708B Analog";
3749 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3750 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3752 spec->stream_name_digital = "VT1708B Digital";
3753 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3754 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3756 if (!spec->adc_nids && spec->input_mux) {
3757 spec->adc_nids = vt1708B_adc_nids;
3758 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3759 get_mux_nids(codec);
3760 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3764 codec->patch_ops = via_patch_ops;
3766 codec->patch_ops.init = via_auto_init;
3767 codec->patch_ops.unsol_event = via_unsol_event;
3768 #ifdef CONFIG_SND_HDA_POWER_SAVE
3769 spec->loopback.amplist = vt1708B_loopbacks;
3775 /* Patch for VT1708S */
3777 /* capture mixer elements */
3778 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3779 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3780 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3781 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3782 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3783 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3784 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3787 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3788 /* The multiple "Capture Source" controls confuse alsamixer
3789 * So call somewhat different..
3791 /* .name = "Capture Source", */
3792 .name = "Input Source",
3794 .info = via_mux_enum_info,
3795 .get = via_mux_enum_get,
3796 .put = via_mux_enum_put,
3801 static struct hda_verb vt1708S_volume_init_verbs[] = {
3802 /* Unmute ADC0-1 and set the default input to mic-in */
3803 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3804 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3806 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3807 * analog-loopback mixer widget */
3808 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3809 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3810 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3811 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3812 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3813 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3815 /* Setup default input of PW4 to MW0 */
3816 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3817 /* PW9, PW10 Output enable */
3818 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3819 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3820 /* Enable Mic Boost Volume backdoor */
3822 /* don't bybass mixer */
3827 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3828 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3829 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3830 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3831 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3832 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3833 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3834 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3835 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3836 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3840 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3844 .nid = 0x10, /* NID to query formats and rates */
3846 .open = via_playback_pcm_open,
3847 .prepare = via_playback_multi_pcm_prepare,
3848 .cleanup = via_playback_multi_pcm_cleanup,
3849 .close = via_pcm_open_close
3853 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3857 .nid = 0x13, /* NID to query formats and rates */
3859 .open = via_pcm_open_close,
3860 .prepare = via_capture_pcm_prepare,
3861 .cleanup = via_capture_pcm_cleanup,
3862 .close = via_pcm_open_close
3866 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3870 /* NID is set in via_build_pcms */
3872 .open = via_dig_playback_pcm_open,
3873 .close = via_dig_playback_pcm_close,
3874 .prepare = via_dig_playback_pcm_prepare,
3875 .cleanup = via_dig_playback_pcm_cleanup
3879 /* fill in the dac_nids table from the parsed pin configuration */
3880 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3881 const struct auto_pin_cfg *cfg)
3886 spec->multiout.num_dacs = cfg->line_outs;
3888 spec->multiout.dac_nids = spec->private_dac_nids;
3890 for (i = 0; i < 4; i++) {
3891 nid = cfg->line_out_pins[i];
3893 /* config dac list */
3895 case AUTO_SEQ_FRONT:
3896 spec->multiout.dac_nids[i] = 0x10;
3898 case AUTO_SEQ_CENLFE:
3899 spec->multiout.dac_nids[i] = 0x24;
3901 case AUTO_SEQ_SURROUND:
3902 spec->multiout.dac_nids[i] = 0x11;
3905 spec->multiout.dac_nids[i] = 0x25;
3914 /* add playback controls from the parsed DAC table */
3915 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3916 const struct auto_pin_cfg *cfg)
3919 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3920 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3921 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3922 hda_nid_t nid, nid_vol, nid_mute;
3925 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3926 nid = cfg->line_out_pins[i];
3931 nid_vol = nid_vols[i];
3932 nid_mute = nid_mutes[i];
3934 if (i == AUTO_SEQ_CENLFE) {
3936 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3937 "Center Playback Volume",
3938 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3942 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3943 "LFE Playback Volume",
3944 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3948 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3949 "Center Playback Switch",
3950 HDA_COMPOSE_AMP_VAL(nid_mute,
3955 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3956 "LFE Playback Switch",
3957 HDA_COMPOSE_AMP_VAL(nid_mute,
3962 } else if (i == AUTO_SEQ_FRONT) {
3963 /* add control to mixer index 0 */
3964 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3965 "Master Front Playback Volume",
3966 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3970 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3971 "Master Front Playback Switch",
3972 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3978 sprintf(name, "%s Playback Volume", chname[i]);
3979 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3980 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3984 sprintf(name, "%s Playback Switch", chname[i]);
3985 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3986 HDA_COMPOSE_AMP_VAL(nid_mute,
3992 sprintf(name, "%s Playback Volume", chname[i]);
3993 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3994 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3998 sprintf(name, "%s Playback Switch", chname[i]);
3999 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
4000 HDA_COMPOSE_AMP_VAL(nid_mute,
4011 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4018 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
4019 spec->hp_independent_mode_index = 1;
4021 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4022 "Headphone Playback Volume",
4023 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
4027 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4028 "Headphone Playback Switch",
4029 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4033 create_hp_imux(spec);
4038 /* create playback/capture controls for input pins */
4039 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
4040 const struct auto_pin_cfg *cfg)
4042 static char *labels[] = {
4043 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4045 struct hda_input_mux *imux = &spec->private_imux[0];
4046 int i, err, idx = 0;
4048 /* for internal loopback recording select */
4049 imux->items[imux->num_items].label = "Stereo Mixer";
4050 imux->items[imux->num_items].index = 5;
4053 for (i = 0; i < AUTO_PIN_LAST; i++) {
4054 if (!cfg->input_pins[i])
4057 switch (cfg->input_pins[i]) {
4058 case 0x1a: /* Mic */
4062 case 0x1b: /* Line In */
4066 case 0x1e: /* Front Mic */
4074 err = via_new_analog_input(spec, labels[i], idx, 0x16);
4077 imux->items[imux->num_items].label = labels[i];
4078 imux->items[imux->num_items].index = idx-1;
4084 /* fill out digital output widgets; one for master and one for slave outputs */
4085 static void fill_dig_outs(struct hda_codec *codec)
4087 struct via_spec *spec = codec->spec;
4090 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4094 nid = spec->autocfg.dig_out_pins[i];
4097 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4100 if (!spec->multiout.dig_out_nid)
4101 spec->multiout.dig_out_nid = nid;
4103 spec->slave_dig_outs[0] = nid;
4104 break; /* at most two dig outs */
4109 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4111 struct via_spec *spec = codec->spec;
4114 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4117 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4120 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4121 return 0; /* can't find valid BIOS pin config */
4123 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4126 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4129 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4133 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4135 fill_dig_outs(codec);
4137 if (spec->kctls.list)
4138 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4140 spec->input_mux = &spec->private_imux[0];
4145 via_smart51_build(spec);
4149 #ifdef CONFIG_SND_HDA_POWER_SAVE
4150 static struct hda_amp_list vt1708S_loopbacks[] = {
4151 { 0x16, HDA_INPUT, 1 },
4152 { 0x16, HDA_INPUT, 2 },
4153 { 0x16, HDA_INPUT, 3 },
4154 { 0x16, HDA_INPUT, 4 },
4159 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4160 int offset, int num_steps, int step_size)
4162 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4163 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4164 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4165 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4166 (0 << AC_AMPCAP_MUTE_SHIFT));
4169 static int patch_vt1708S(struct hda_codec *codec)
4171 struct via_spec *spec;
4174 /* create a codec specific record */
4175 spec = via_new_spec(codec);
4179 /* automatic parse from the BIOS config */
4180 err = vt1708S_parse_auto_config(codec);
4185 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4186 "from BIOS. Using genenic mode...\n");
4189 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4190 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4192 if (codec->vendor_id == 0x11060440)
4193 spec->stream_name_analog = "VT1818S Analog";
4195 spec->stream_name_analog = "VT1708S Analog";
4196 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4197 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4199 if (codec->vendor_id == 0x11060440)
4200 spec->stream_name_digital = "VT1818S Digital";
4202 spec->stream_name_digital = "VT1708S Digital";
4203 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4205 if (!spec->adc_nids && spec->input_mux) {
4206 spec->adc_nids = vt1708S_adc_nids;
4207 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4208 get_mux_nids(codec);
4209 override_mic_boost(codec, 0x1a, 0, 3, 40);
4210 override_mic_boost(codec, 0x1e, 0, 3, 40);
4211 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4215 codec->patch_ops = via_patch_ops;
4217 codec->patch_ops.init = via_auto_init;
4218 codec->patch_ops.unsol_event = via_unsol_event;
4219 #ifdef CONFIG_SND_HDA_POWER_SAVE
4220 spec->loopback.amplist = vt1708S_loopbacks;
4223 /* correct names for VT1708BCE */
4224 if (get_codec_type(codec) == VT1708BCE) {
4225 kfree(codec->chip_name);
4226 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4227 snprintf(codec->bus->card->mixername,
4228 sizeof(codec->bus->card->mixername),
4229 "%s %s", codec->vendor_name, codec->chip_name);
4230 spec->stream_name_analog = "VT1708BCE Analog";
4231 spec->stream_name_digital = "VT1708BCE Digital";
4236 /* Patch for VT1702 */
4238 /* capture mixer elements */
4239 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4240 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4241 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4242 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4243 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4244 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4245 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4246 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4249 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4250 /* The multiple "Capture Source" controls confuse alsamixer
4251 * So call somewhat different..
4253 /* .name = "Capture Source", */
4254 .name = "Input Source",
4256 .info = via_mux_enum_info,
4257 .get = via_mux_enum_get,
4258 .put = via_mux_enum_put,
4263 static struct hda_verb vt1702_volume_init_verbs[] = {
4265 * Unmute ADC0-1 and set the default input to mic-in
4267 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4268 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4269 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4272 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4275 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4276 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4277 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4278 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4279 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4280 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4282 /* Setup default input of PW4 to MW0 */
4283 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4284 /* PW6 PW7 Output enable */
4285 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4286 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4294 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4295 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4296 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4297 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4298 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4299 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4300 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4304 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4308 .nid = 0x10, /* NID to query formats and rates */
4310 .open = via_playback_pcm_open,
4311 .prepare = via_playback_multi_pcm_prepare,
4312 .cleanup = via_playback_multi_pcm_cleanup,
4313 .close = via_pcm_open_close
4317 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4321 .nid = 0x12, /* NID to query formats and rates */
4323 .open = via_pcm_open_close,
4324 .prepare = via_capture_pcm_prepare,
4325 .cleanup = via_capture_pcm_cleanup,
4326 .close = via_pcm_open_close
4330 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4334 /* NID is set in via_build_pcms */
4336 .open = via_dig_playback_pcm_open,
4337 .close = via_dig_playback_pcm_close,
4338 .prepare = via_dig_playback_pcm_prepare,
4339 .cleanup = via_dig_playback_pcm_cleanup
4343 /* fill in the dac_nids table from the parsed pin configuration */
4344 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4345 const struct auto_pin_cfg *cfg)
4347 spec->multiout.num_dacs = 1;
4348 spec->multiout.dac_nids = spec->private_dac_nids;
4350 if (cfg->line_out_pins[0]) {
4351 /* config dac list */
4352 spec->multiout.dac_nids[0] = 0x10;
4358 /* add playback controls from the parsed DAC table */
4359 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4360 const struct auto_pin_cfg *cfg)
4364 if (!cfg->line_out_pins[0])
4367 /* add control to mixer index 0 */
4368 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4369 "Master Front Playback Volume",
4370 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4373 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4374 "Master Front Playback Switch",
4375 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4380 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4381 "Front Playback Volume",
4382 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4385 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4386 "Front Playback Switch",
4387 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4394 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4397 struct hda_input_mux *imux;
4398 static const char *texts[] = { "ON", "OFF", NULL};
4401 spec->multiout.hp_nid = 0x1D;
4402 spec->hp_independent_mode_index = 0;
4404 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4405 "Headphone Playback Volume",
4406 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4410 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4411 "Headphone Playback Switch",
4412 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4416 imux = &spec->private_imux[1];
4418 /* for hp mode select */
4420 while (texts[i] != NULL) {
4421 imux->items[imux->num_items].label = texts[i];
4422 imux->items[imux->num_items].index = i;
4427 spec->hp_mux = &spec->private_imux[1];
4431 /* create playback/capture controls for input pins */
4432 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
4433 const struct auto_pin_cfg *cfg)
4435 static char *labels[] = {
4436 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4438 struct hda_input_mux *imux = &spec->private_imux[0];
4439 int i, err, idx = 0;
4441 /* for internal loopback recording select */
4442 imux->items[imux->num_items].label = "Stereo Mixer";
4443 imux->items[imux->num_items].index = 3;
4446 for (i = 0; i < AUTO_PIN_LAST; i++) {
4447 if (!cfg->input_pins[i])
4450 switch (cfg->input_pins[i]) {
4451 case 0x14: /* Mic */
4455 case 0x15: /* Line In */
4459 case 0x18: /* Front Mic */
4463 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
4466 imux->items[imux->num_items].label = labels[i];
4467 imux->items[imux->num_items].index = idx-1;
4473 static int vt1702_parse_auto_config(struct hda_codec *codec)
4475 struct via_spec *spec = codec->spec;
4478 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4481 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4484 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4485 return 0; /* can't find valid BIOS pin config */
4487 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4490 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4493 /* limit AA path volume to 0 dB */
4494 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4495 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4496 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4497 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4498 (1 << AC_AMPCAP_MUTE_SHIFT));
4499 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
4503 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4505 fill_dig_outs(codec);
4507 if (spec->kctls.list)
4508 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4510 spec->input_mux = &spec->private_imux[0];
4518 #ifdef CONFIG_SND_HDA_POWER_SAVE
4519 static struct hda_amp_list vt1702_loopbacks[] = {
4520 { 0x1A, HDA_INPUT, 1 },
4521 { 0x1A, HDA_INPUT, 2 },
4522 { 0x1A, HDA_INPUT, 3 },
4523 { 0x1A, HDA_INPUT, 4 },
4528 static int patch_vt1702(struct hda_codec *codec)
4530 struct via_spec *spec;
4533 /* create a codec specific record */
4534 spec = via_new_spec(codec);
4538 /* automatic parse from the BIOS config */
4539 err = vt1702_parse_auto_config(codec);
4544 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4545 "from BIOS. Using genenic mode...\n");
4548 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4549 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4551 spec->stream_name_analog = "VT1702 Analog";
4552 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4553 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4555 spec->stream_name_digital = "VT1702 Digital";
4556 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4558 if (!spec->adc_nids && spec->input_mux) {
4559 spec->adc_nids = vt1702_adc_nids;
4560 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4561 get_mux_nids(codec);
4562 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4566 codec->patch_ops = via_patch_ops;
4568 codec->patch_ops.init = via_auto_init;
4569 codec->patch_ops.unsol_event = via_unsol_event;
4570 #ifdef CONFIG_SND_HDA_POWER_SAVE
4571 spec->loopback.amplist = vt1702_loopbacks;
4577 /* Patch for VT1718S */
4579 /* capture mixer elements */
4580 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4581 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4582 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4583 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4584 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4585 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4586 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4589 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4590 /* The multiple "Capture Source" controls confuse alsamixer
4591 * So call somewhat different..
4593 .name = "Input Source",
4595 .info = via_mux_enum_info,
4596 .get = via_mux_enum_get,
4597 .put = via_mux_enum_put,
4602 static struct hda_verb vt1718S_volume_init_verbs[] = {
4604 * Unmute ADC0-1 and set the default input to mic-in
4606 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4607 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4610 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4613 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4614 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4615 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4616 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4617 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4618 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4620 /* Setup default input of Front HP to MW9 */
4621 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4622 /* PW9 PW10 Output enable */
4623 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4624 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4625 /* PW11 Input enable */
4626 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4627 /* Enable Boost Volume backdoor */
4629 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4630 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4631 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4632 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4633 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4634 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4635 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4636 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4637 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4638 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4639 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4640 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4641 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4642 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4643 /* Unmute MW4's index 0 */
4644 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4649 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4650 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4651 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4652 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4653 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4654 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4655 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4656 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4657 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4658 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4662 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4666 .nid = 0x8, /* NID to query formats and rates */
4668 .open = via_playback_pcm_open,
4669 .prepare = via_playback_multi_pcm_prepare,
4670 .cleanup = via_playback_multi_pcm_cleanup,
4671 .close = via_pcm_open_close,
4675 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4679 .nid = 0x10, /* NID to query formats and rates */
4681 .open = via_pcm_open_close,
4682 .prepare = via_capture_pcm_prepare,
4683 .cleanup = via_capture_pcm_cleanup,
4684 .close = via_pcm_open_close,
4688 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4692 /* NID is set in via_build_pcms */
4694 .open = via_dig_playback_pcm_open,
4695 .close = via_dig_playback_pcm_close,
4696 .prepare = via_dig_playback_pcm_prepare,
4697 .cleanup = via_dig_playback_pcm_cleanup
4701 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4707 /* fill in the dac_nids table from the parsed pin configuration */
4708 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4709 const struct auto_pin_cfg *cfg)
4714 spec->multiout.num_dacs = cfg->line_outs;
4716 spec->multiout.dac_nids = spec->private_dac_nids;
4718 for (i = 0; i < 4; i++) {
4719 nid = cfg->line_out_pins[i];
4721 /* config dac list */
4723 case AUTO_SEQ_FRONT:
4724 spec->multiout.dac_nids[i] = 0x8;
4726 case AUTO_SEQ_CENLFE:
4727 spec->multiout.dac_nids[i] = 0xa;
4729 case AUTO_SEQ_SURROUND:
4730 spec->multiout.dac_nids[i] = 0x9;
4733 spec->multiout.dac_nids[i] = 0xb;
4742 /* add playback controls from the parsed DAC table */
4743 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4744 const struct auto_pin_cfg *cfg)
4747 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4748 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4749 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4750 hda_nid_t nid, nid_vol, nid_mute = 0;
4753 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4754 nid = cfg->line_out_pins[i];
4758 nid_vol = nid_vols[i];
4759 nid_mute = nid_mutes[i];
4761 if (i == AUTO_SEQ_CENLFE) {
4763 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4764 "Center Playback Volume",
4765 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4769 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4770 "LFE Playback Volume",
4771 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4775 err = via_add_control(
4776 spec, VIA_CTL_WIDGET_MUTE,
4777 "Center Playback Switch",
4778 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4782 err = via_add_control(
4783 spec, VIA_CTL_WIDGET_MUTE,
4784 "LFE Playback Switch",
4785 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4789 } else if (i == AUTO_SEQ_FRONT) {
4791 sprintf(name, "%s Playback Volume", chname[i]);
4792 err = via_add_control(
4793 spec, VIA_CTL_WIDGET_VOL, name,
4794 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4797 sprintf(name, "%s Playback Switch", chname[i]);
4798 err = via_add_control(
4799 spec, VIA_CTL_WIDGET_MUTE, name,
4800 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4805 sprintf(name, "%s Playback Volume", chname[i]);
4806 err = via_add_control(
4807 spec, VIA_CTL_WIDGET_VOL, name,
4808 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4811 sprintf(name, "%s Playback Switch", chname[i]);
4812 err = via_add_control(
4813 spec, VIA_CTL_WIDGET_MUTE, name,
4814 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4823 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4830 spec->multiout.hp_nid = 0xc; /* AOW4 */
4831 spec->hp_independent_mode_index = 1;
4833 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4834 "Headphone Playback Volume",
4835 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4839 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4840 "Headphone Playback Switch",
4841 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4845 create_hp_imux(spec);
4849 /* create playback/capture controls for input pins */
4850 static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4851 const struct auto_pin_cfg *cfg)
4853 static char *labels[] = {
4854 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4856 struct hda_input_mux *imux = &spec->private_imux[0];
4857 int i, err, idx = 0;
4859 /* for internal loopback recording select */
4860 imux->items[imux->num_items].label = "Stereo Mixer";
4861 imux->items[imux->num_items].index = 5;
4864 for (i = 0; i < AUTO_PIN_LAST; i++) {
4865 if (!cfg->input_pins[i])
4868 switch (cfg->input_pins[i]) {
4869 case 0x2b: /* Mic */
4873 case 0x2a: /* Line In */
4877 case 0x29: /* Front Mic */
4885 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4888 imux->items[imux->num_items].label = labels[i];
4889 imux->items[imux->num_items].index = idx;
4895 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4897 struct via_spec *spec = codec->spec;
4900 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4904 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4907 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4908 return 0; /* can't find valid BIOS pin config */
4910 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4913 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4916 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4920 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4922 fill_dig_outs(codec);
4924 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4925 spec->dig_in_nid = 0x13;
4927 if (spec->kctls.list)
4928 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4930 spec->input_mux = &spec->private_imux[0];
4935 via_smart51_build(spec);
4940 #ifdef CONFIG_SND_HDA_POWER_SAVE
4941 static struct hda_amp_list vt1718S_loopbacks[] = {
4942 { 0x21, HDA_INPUT, 1 },
4943 { 0x21, HDA_INPUT, 2 },
4944 { 0x21, HDA_INPUT, 3 },
4945 { 0x21, HDA_INPUT, 4 },
4950 static int patch_vt1718S(struct hda_codec *codec)
4952 struct via_spec *spec;
4955 /* create a codec specific record */
4956 spec = via_new_spec(codec);
4960 /* automatic parse from the BIOS config */
4961 err = vt1718S_parse_auto_config(codec);
4966 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4967 "from BIOS. Using genenic mode...\n");
4970 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4971 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4973 if (codec->vendor_id == 0x11060441)
4974 spec->stream_name_analog = "VT2020 Analog";
4975 else if (codec->vendor_id == 0x11064441)
4976 spec->stream_name_analog = "VT1828S Analog";
4978 spec->stream_name_analog = "VT1718S Analog";
4979 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4980 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4982 if (codec->vendor_id == 0x11060441)
4983 spec->stream_name_digital = "VT2020 Digital";
4984 else if (codec->vendor_id == 0x11064441)
4985 spec->stream_name_digital = "VT1828S Digital";
4987 spec->stream_name_digital = "VT1718S Digital";
4988 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4989 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4990 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4992 if (!spec->adc_nids && spec->input_mux) {
4993 spec->adc_nids = vt1718S_adc_nids;
4994 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4995 get_mux_nids(codec);
4996 override_mic_boost(codec, 0x2b, 0, 3, 40);
4997 override_mic_boost(codec, 0x29, 0, 3, 40);
4998 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
5002 codec->patch_ops = via_patch_ops;
5004 codec->patch_ops.init = via_auto_init;
5005 codec->patch_ops.unsol_event = via_unsol_event;
5007 #ifdef CONFIG_SND_HDA_POWER_SAVE
5008 spec->loopback.amplist = vt1718S_loopbacks;
5014 /* Patch for VT1716S */
5016 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
5017 struct snd_ctl_elem_info *uinfo)
5019 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
5021 uinfo->value.integer.min = 0;
5022 uinfo->value.integer.max = 1;
5026 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
5027 struct snd_ctl_elem_value *ucontrol)
5029 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5032 index = snd_hda_codec_read(codec, 0x26, 0,
5033 AC_VERB_GET_CONNECT_SEL, 0);
5035 *ucontrol->value.integer.value = index;
5040 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
5041 struct snd_ctl_elem_value *ucontrol)
5043 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5044 struct via_spec *spec = codec->spec;
5045 int index = *ucontrol->value.integer.value;
5047 snd_hda_codec_write(codec, 0x26, 0,
5048 AC_VERB_SET_CONNECT_SEL, index);
5049 spec->dmic_enabled = index;
5050 set_jack_power_state(codec);
5055 /* capture mixer elements */
5056 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
5057 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
5058 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
5059 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
5060 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
5061 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
5062 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5065 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5066 .name = "Input Source",
5068 .info = via_mux_enum_info,
5069 .get = via_mux_enum_get,
5070 .put = via_mux_enum_put,
5075 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5076 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5078 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5079 .name = "Digital Mic Capture Switch",
5080 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
5082 .info = vt1716s_dmic_info,
5083 .get = vt1716s_dmic_get,
5084 .put = vt1716s_dmic_put,
5090 /* mono-out mixer elements */
5091 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5092 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5096 static struct hda_verb vt1716S_volume_init_verbs[] = {
5098 * Unmute ADC0-1 and set the default input to mic-in
5100 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5101 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5104 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5107 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5108 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5109 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5110 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5111 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5112 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5114 /* MUX Indices: Stereo Mixer = 5 */
5115 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5117 /* Setup default input of PW4 to MW0 */
5118 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5120 /* Setup default input of SW1 as MW0 */
5121 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5123 /* Setup default input of SW4 as AOW0 */
5124 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5126 /* PW9 PW10 Output enable */
5127 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5128 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5130 /* Unmute SW1, PW12 */
5131 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5132 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5133 /* PW12 Output enable */
5134 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5135 /* Enable Boost Volume backdoor */
5137 /* don't bybass mixer */
5139 /* Enable mono output */
5145 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5146 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5147 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5148 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5149 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5150 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5151 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5152 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5153 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5154 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5158 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5162 .nid = 0x10, /* NID to query formats and rates */
5164 .open = via_playback_pcm_open,
5165 .prepare = via_playback_multi_pcm_prepare,
5166 .cleanup = via_playback_multi_pcm_cleanup,
5167 .close = via_pcm_open_close,
5171 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5175 .nid = 0x13, /* NID to query formats and rates */
5177 .open = via_pcm_open_close,
5178 .prepare = via_capture_pcm_prepare,
5179 .cleanup = via_capture_pcm_cleanup,
5180 .close = via_pcm_open_close,
5184 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5188 /* NID is set in via_build_pcms */
5190 .open = via_dig_playback_pcm_open,
5191 .close = via_dig_playback_pcm_close,
5192 .prepare = via_dig_playback_pcm_prepare,
5193 .cleanup = via_dig_playback_pcm_cleanup
5197 /* fill in the dac_nids table from the parsed pin configuration */
5198 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5199 const struct auto_pin_cfg *cfg)
5203 spec->multiout.num_dacs = cfg->line_outs;
5205 spec->multiout.dac_nids = spec->private_dac_nids;
5207 for (i = 0; i < 3; i++) {
5208 nid = cfg->line_out_pins[i];
5210 /* config dac list */
5212 case AUTO_SEQ_FRONT:
5213 spec->multiout.dac_nids[i] = 0x10;
5215 case AUTO_SEQ_CENLFE:
5216 spec->multiout.dac_nids[i] = 0x25;
5218 case AUTO_SEQ_SURROUND:
5219 spec->multiout.dac_nids[i] = 0x11;
5228 /* add playback controls from the parsed DAC table */
5229 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5230 const struct auto_pin_cfg *cfg)
5233 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5234 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5235 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5236 hda_nid_t nid, nid_vol, nid_mute;
5239 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5240 nid = cfg->line_out_pins[i];
5245 nid_vol = nid_vols[i];
5246 nid_mute = nid_mutes[i];
5248 if (i == AUTO_SEQ_CENLFE) {
5249 err = via_add_control(
5250 spec, VIA_CTL_WIDGET_VOL,
5251 "Center Playback Volume",
5252 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5255 err = via_add_control(
5256 spec, VIA_CTL_WIDGET_VOL,
5257 "LFE Playback Volume",
5258 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5261 err = via_add_control(
5262 spec, VIA_CTL_WIDGET_MUTE,
5263 "Center Playback Switch",
5264 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5268 err = via_add_control(
5269 spec, VIA_CTL_WIDGET_MUTE,
5270 "LFE Playback Switch",
5271 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5275 } else if (i == AUTO_SEQ_FRONT) {
5277 err = via_add_control(
5278 spec, VIA_CTL_WIDGET_VOL,
5279 "Master Front Playback Volume",
5280 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5283 err = via_add_control(
5284 spec, VIA_CTL_WIDGET_MUTE,
5285 "Master Front Playback Switch",
5286 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5290 sprintf(name, "%s Playback Volume", chname[i]);
5291 err = via_add_control(
5292 spec, VIA_CTL_WIDGET_VOL, name,
5293 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5296 sprintf(name, "%s Playback Switch", chname[i]);
5297 err = via_add_control(
5298 spec, VIA_CTL_WIDGET_MUTE, name,
5299 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5304 sprintf(name, "%s Playback Volume", chname[i]);
5305 err = via_add_control(
5306 spec, VIA_CTL_WIDGET_VOL, name,
5307 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5310 sprintf(name, "%s Playback Switch", chname[i]);
5311 err = via_add_control(
5312 spec, VIA_CTL_WIDGET_MUTE, name,
5313 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5322 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5329 spec->multiout.hp_nid = 0x25; /* AOW3 */
5330 spec->hp_independent_mode_index = 1;
5332 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5333 "Headphone Playback Volume",
5334 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5338 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5339 "Headphone Playback Switch",
5340 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5344 create_hp_imux(spec);
5348 /* create playback/capture controls for input pins */
5349 static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5350 const struct auto_pin_cfg *cfg)
5352 static char *labels[] = {
5353 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5355 struct hda_input_mux *imux = &spec->private_imux[0];
5356 int i, err, idx = 0;
5358 /* for internal loopback recording select */
5359 imux->items[imux->num_items].label = "Stereo Mixer";
5360 imux->items[imux->num_items].index = 5;
5363 for (i = 0; i < AUTO_PIN_LAST; i++) {
5364 if (!cfg->input_pins[i])
5367 switch (cfg->input_pins[i]) {
5368 case 0x1a: /* Mic */
5372 case 0x1b: /* Line In */
5376 case 0x1e: /* Front Mic */
5384 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5387 imux->items[imux->num_items].label = labels[i];
5388 imux->items[imux->num_items].index = idx-1;
5394 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5396 struct via_spec *spec = codec->spec;
5399 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5402 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5405 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5406 return 0; /* can't find valid BIOS pin config */
5408 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5411 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5414 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5418 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5420 fill_dig_outs(codec);
5422 if (spec->kctls.list)
5423 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5425 spec->input_mux = &spec->private_imux[0];
5430 via_smart51_build(spec);
5435 #ifdef CONFIG_SND_HDA_POWER_SAVE
5436 static struct hda_amp_list vt1716S_loopbacks[] = {
5437 { 0x16, HDA_INPUT, 1 },
5438 { 0x16, HDA_INPUT, 2 },
5439 { 0x16, HDA_INPUT, 3 },
5440 { 0x16, HDA_INPUT, 4 },
5445 static int patch_vt1716S(struct hda_codec *codec)
5447 struct via_spec *spec;
5450 /* create a codec specific record */
5451 spec = via_new_spec(codec);
5455 /* automatic parse from the BIOS config */
5456 err = vt1716S_parse_auto_config(codec);
5461 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5462 "from BIOS. Using genenic mode...\n");
5465 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5466 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5468 spec->stream_name_analog = "VT1716S Analog";
5469 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5470 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5472 spec->stream_name_digital = "VT1716S Digital";
5473 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5475 if (!spec->adc_nids && spec->input_mux) {
5476 spec->adc_nids = vt1716S_adc_nids;
5477 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5478 get_mux_nids(codec);
5479 override_mic_boost(codec, 0x1a, 0, 3, 40);
5480 override_mic_boost(codec, 0x1e, 0, 3, 40);
5481 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5485 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5488 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5490 codec->patch_ops = via_patch_ops;
5492 codec->patch_ops.init = via_auto_init;
5493 codec->patch_ops.unsol_event = via_unsol_event;
5495 #ifdef CONFIG_SND_HDA_POWER_SAVE
5496 spec->loopback.amplist = vt1716S_loopbacks;
5504 /* capture mixer elements */
5505 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5506 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5507 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5508 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5509 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5510 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5511 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5514 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5515 /* The multiple "Capture Source" controls confuse alsamixer
5516 * So call somewhat different..
5518 /* .name = "Capture Source", */
5519 .name = "Input Source",
5521 .info = via_mux_enum_info,
5522 .get = via_mux_enum_get,
5523 .put = via_mux_enum_put,
5528 static struct hda_verb vt2002P_volume_init_verbs[] = {
5530 * Unmute ADC0-1 and set the default input to mic-in
5532 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5533 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5536 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5539 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5540 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5541 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5542 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5543 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5544 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5546 /* MUX Indices: Mic = 0 */
5547 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5548 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5550 /* PW9 Output enable */
5551 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5553 /* Enable Boost Volume backdoor */
5556 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5557 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5558 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5559 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5560 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5561 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5562 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5563 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5564 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5566 /* set MUX0/1/4/8 = 0 (AOW0) */
5567 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5568 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5569 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5570 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5572 /* set PW0 index=0 (MW0) */
5573 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5575 /* Enable AOW0 to MW9 */
5581 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5582 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5583 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5584 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5585 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5586 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5587 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5588 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5592 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5596 .nid = 0x8, /* NID to query formats and rates */
5598 .open = via_playback_pcm_open,
5599 .prepare = via_playback_multi_pcm_prepare,
5600 .cleanup = via_playback_multi_pcm_cleanup,
5601 .close = via_pcm_open_close,
5605 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5609 .nid = 0x10, /* NID to query formats and rates */
5611 .open = via_pcm_open_close,
5612 .prepare = via_capture_pcm_prepare,
5613 .cleanup = via_capture_pcm_cleanup,
5614 .close = via_pcm_open_close,
5618 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5622 /* NID is set in via_build_pcms */
5624 .open = via_dig_playback_pcm_open,
5625 .close = via_dig_playback_pcm_close,
5626 .prepare = via_dig_playback_pcm_prepare,
5627 .cleanup = via_dig_playback_pcm_cleanup
5631 /* fill in the dac_nids table from the parsed pin configuration */
5632 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5633 const struct auto_pin_cfg *cfg)
5635 spec->multiout.num_dacs = 1;
5636 spec->multiout.dac_nids = spec->private_dac_nids;
5637 if (cfg->line_out_pins[0])
5638 spec->multiout.dac_nids[0] = 0x8;
5642 /* add playback controls from the parsed DAC table */
5643 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5644 const struct auto_pin_cfg *cfg)
5648 if (!cfg->line_out_pins[0])
5652 /* Line-Out: PortE */
5653 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5654 "Master Front Playback Volume",
5655 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5658 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5659 "Master Front Playback Switch",
5660 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5667 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5674 spec->multiout.hp_nid = 0x9;
5675 spec->hp_independent_mode_index = 1;
5677 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5678 "Headphone Playback Volume",
5679 HDA_COMPOSE_AMP_VAL(
5680 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5684 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5685 "Headphone Playback Switch",
5686 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5690 create_hp_imux(spec);
5694 /* create playback/capture controls for input pins */
5695 static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5696 const struct auto_pin_cfg *cfg)
5698 static char *labels[] = {
5699 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5701 struct hda_input_mux *imux = &spec->private_imux[0];
5702 int i, err, idx = 0;
5704 for (i = 0; i < AUTO_PIN_LAST; i++) {
5705 if (!cfg->input_pins[i])
5708 switch (cfg->input_pins[i]) {
5709 case 0x2b: /* Mic */
5713 case 0x2a: /* Line In */
5717 case 0x29: /* Front Mic */
5721 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5724 imux->items[imux->num_items].label = labels[i];
5725 imux->items[imux->num_items].index = idx;
5729 /* build volume/mute control of loopback */
5730 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5734 /* for internal loopback recording select */
5735 imux->items[imux->num_items].label = "Stereo Mixer";
5736 imux->items[imux->num_items].index = 3;
5739 /* for digital mic select */
5740 imux->items[imux->num_items].label = "Digital Mic";
5741 imux->items[imux->num_items].index = 4;
5747 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5749 struct via_spec *spec = codec->spec;
5753 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5757 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5761 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5762 return 0; /* can't find valid BIOS pin config */
5764 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5767 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5770 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5774 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5776 fill_dig_outs(codec);
5778 if (spec->kctls.list)
5779 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5781 spec->input_mux = &spec->private_imux[0];
5789 #ifdef CONFIG_SND_HDA_POWER_SAVE
5790 static struct hda_amp_list vt2002P_loopbacks[] = {
5791 { 0x21, HDA_INPUT, 0 },
5792 { 0x21, HDA_INPUT, 1 },
5793 { 0x21, HDA_INPUT, 2 },
5799 /* patch for vt2002P */
5800 static int patch_vt2002P(struct hda_codec *codec)
5802 struct via_spec *spec;
5805 /* create a codec specific record */
5806 spec = via_new_spec(codec);
5810 /* automatic parse from the BIOS config */
5811 err = vt2002P_parse_auto_config(codec);
5816 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5817 "from BIOS. Using genenic mode...\n");
5820 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5821 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5823 spec->stream_name_analog = "VT2002P Analog";
5824 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5825 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5827 spec->stream_name_digital = "VT2002P Digital";
5828 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5830 if (!spec->adc_nids && spec->input_mux) {
5831 spec->adc_nids = vt2002P_adc_nids;
5832 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5833 get_mux_nids(codec);
5834 override_mic_boost(codec, 0x2b, 0, 3, 40);
5835 override_mic_boost(codec, 0x29, 0, 3, 40);
5836 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5840 codec->patch_ops = via_patch_ops;
5842 codec->patch_ops.init = via_auto_init;
5843 codec->patch_ops.unsol_event = via_unsol_event;
5845 #ifdef CONFIG_SND_HDA_POWER_SAVE
5846 spec->loopback.amplist = vt2002P_loopbacks;
5854 /* capture mixer elements */
5855 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5856 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5857 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5858 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5859 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5860 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5861 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5864 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5865 /* The multiple "Capture Source" controls confuse alsamixer
5866 * So call somewhat different..
5868 .name = "Input Source",
5870 .info = via_mux_enum_info,
5871 .get = via_mux_enum_get,
5872 .put = via_mux_enum_put,
5877 static struct hda_verb vt1812_volume_init_verbs[] = {
5879 * Unmute ADC0-1 and set the default input to mic-in
5881 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5882 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5885 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5888 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5889 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5890 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5891 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5892 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5893 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5895 /* MUX Indices: Mic = 0 */
5896 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5897 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5899 /* PW9 Output enable */
5900 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5902 /* Enable Boost Volume backdoor */
5905 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5906 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5907 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5908 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5909 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5910 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5911 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5912 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5913 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5914 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5915 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5917 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5918 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5919 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5920 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5921 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5922 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5924 /* Enable AOW0 to MW9 */
5930 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5931 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5932 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5933 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5934 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5935 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5936 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5937 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5938 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5942 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5946 .nid = 0x8, /* NID to query formats and rates */
5948 .open = via_playback_pcm_open,
5949 .prepare = via_playback_multi_pcm_prepare,
5950 .cleanup = via_playback_multi_pcm_cleanup,
5951 .close = via_pcm_open_close,
5955 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5959 .nid = 0x10, /* NID to query formats and rates */
5961 .open = via_pcm_open_close,
5962 .prepare = via_capture_pcm_prepare,
5963 .cleanup = via_capture_pcm_cleanup,
5964 .close = via_pcm_open_close,
5968 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5972 /* NID is set in via_build_pcms */
5974 .open = via_dig_playback_pcm_open,
5975 .close = via_dig_playback_pcm_close,
5976 .prepare = via_dig_playback_pcm_prepare,
5977 .cleanup = via_dig_playback_pcm_cleanup
5980 /* fill in the dac_nids table from the parsed pin configuration */
5981 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5982 const struct auto_pin_cfg *cfg)
5984 spec->multiout.num_dacs = 1;
5985 spec->multiout.dac_nids = spec->private_dac_nids;
5986 if (cfg->line_out_pins[0])
5987 spec->multiout.dac_nids[0] = 0x8;
5992 /* add playback controls from the parsed DAC table */
5993 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5994 const struct auto_pin_cfg *cfg)
5998 if (!cfg->line_out_pins[0])
6001 /* Line-Out: PortE */
6002 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
6003 "Master Front Playback Volume",
6004 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
6007 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
6008 "Master Front Playback Switch",
6009 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
6016 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
6023 spec->multiout.hp_nid = 0x9;
6024 spec->hp_independent_mode_index = 1;
6027 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
6028 "Headphone Playback Volume",
6029 HDA_COMPOSE_AMP_VAL(
6030 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
6034 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
6035 "Headphone Playback Switch",
6036 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
6040 create_hp_imux(spec);
6044 /* create playback/capture controls for input pins */
6045 static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
6046 const struct auto_pin_cfg *cfg)
6048 static char *labels[] = {
6049 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
6051 struct hda_input_mux *imux = &spec->private_imux[0];
6052 int i, err, idx = 0;
6054 for (i = 0; i < AUTO_PIN_LAST; i++) {
6055 if (!cfg->input_pins[i])
6058 switch (cfg->input_pins[i]) {
6059 case 0x2b: /* Mic */
6063 case 0x2a: /* Line In */
6067 case 0x29: /* Front Mic */
6071 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6074 imux->items[imux->num_items].label = labels[i];
6075 imux->items[imux->num_items].index = idx;
6078 /* build volume/mute control of loopback */
6079 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6083 /* for internal loopback recording select */
6084 imux->items[imux->num_items].label = "Stereo Mixer";
6085 imux->items[imux->num_items].index = 5;
6088 /* for digital mic select */
6089 imux->items[imux->num_items].label = "Digital Mic";
6090 imux->items[imux->num_items].index = 6;
6096 static int vt1812_parse_auto_config(struct hda_codec *codec)
6098 struct via_spec *spec = codec->spec;
6102 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6105 fill_dig_outs(codec);
6106 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6110 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6111 return 0; /* can't find valid BIOS pin config */
6113 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6116 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6119 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6123 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6125 fill_dig_outs(codec);
6127 if (spec->kctls.list)
6128 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6130 spec->input_mux = &spec->private_imux[0];
6138 #ifdef CONFIG_SND_HDA_POWER_SAVE
6139 static struct hda_amp_list vt1812_loopbacks[] = {
6140 { 0x21, HDA_INPUT, 0 },
6141 { 0x21, HDA_INPUT, 1 },
6142 { 0x21, HDA_INPUT, 2 },
6148 /* patch for vt1812 */
6149 static int patch_vt1812(struct hda_codec *codec)
6151 struct via_spec *spec;
6154 /* create a codec specific record */
6155 spec = via_new_spec(codec);
6159 /* automatic parse from the BIOS config */
6160 err = vt1812_parse_auto_config(codec);
6165 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6166 "from BIOS. Using genenic mode...\n");
6170 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6171 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6173 spec->stream_name_analog = "VT1812 Analog";
6174 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6175 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6177 spec->stream_name_digital = "VT1812 Digital";
6178 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6181 if (!spec->adc_nids && spec->input_mux) {
6182 spec->adc_nids = vt1812_adc_nids;
6183 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6184 get_mux_nids(codec);
6185 override_mic_boost(codec, 0x2b, 0, 3, 40);
6186 override_mic_boost(codec, 0x29, 0, 3, 40);
6187 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6191 codec->patch_ops = via_patch_ops;
6193 codec->patch_ops.init = via_auto_init;
6194 codec->patch_ops.unsol_event = via_unsol_event;
6196 #ifdef CONFIG_SND_HDA_POWER_SAVE
6197 spec->loopback.amplist = vt1812_loopbacks;
6206 static struct hda_codec_preset snd_hda_preset_via[] = {
6207 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6208 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6209 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6210 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6211 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6212 .patch = patch_vt1709_10ch},
6213 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6214 .patch = patch_vt1709_10ch},
6215 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6216 .patch = patch_vt1709_10ch},
6217 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6218 .patch = patch_vt1709_10ch},
6219 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6220 .patch = patch_vt1709_6ch},
6221 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6222 .patch = patch_vt1709_6ch},
6223 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6224 .patch = patch_vt1709_6ch},
6225 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6226 .patch = patch_vt1709_6ch},
6227 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6228 .patch = patch_vt1708B_8ch},
6229 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6230 .patch = patch_vt1708B_8ch},
6231 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6232 .patch = patch_vt1708B_8ch},
6233 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6234 .patch = patch_vt1708B_8ch},
6235 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6236 .patch = patch_vt1708B_4ch},
6237 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6238 .patch = patch_vt1708B_4ch},
6239 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6240 .patch = patch_vt1708B_4ch},
6241 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6242 .patch = patch_vt1708B_4ch},
6243 { .id = 0x11060397, .name = "VT1708S",
6244 .patch = patch_vt1708S},
6245 { .id = 0x11061397, .name = "VT1708S",
6246 .patch = patch_vt1708S},
6247 { .id = 0x11062397, .name = "VT1708S",
6248 .patch = patch_vt1708S},
6249 { .id = 0x11063397, .name = "VT1708S",
6250 .patch = patch_vt1708S},
6251 { .id = 0x11064397, .name = "VT1708S",
6252 .patch = patch_vt1708S},
6253 { .id = 0x11065397, .name = "VT1708S",
6254 .patch = patch_vt1708S},
6255 { .id = 0x11066397, .name = "VT1708S",
6256 .patch = patch_vt1708S},
6257 { .id = 0x11067397, .name = "VT1708S",
6258 .patch = patch_vt1708S},
6259 { .id = 0x11060398, .name = "VT1702",
6260 .patch = patch_vt1702},
6261 { .id = 0x11061398, .name = "VT1702",
6262 .patch = patch_vt1702},
6263 { .id = 0x11062398, .name = "VT1702",
6264 .patch = patch_vt1702},
6265 { .id = 0x11063398, .name = "VT1702",
6266 .patch = patch_vt1702},
6267 { .id = 0x11064398, .name = "VT1702",
6268 .patch = patch_vt1702},
6269 { .id = 0x11065398, .name = "VT1702",
6270 .patch = patch_vt1702},
6271 { .id = 0x11066398, .name = "VT1702",
6272 .patch = patch_vt1702},
6273 { .id = 0x11067398, .name = "VT1702",
6274 .patch = patch_vt1702},
6275 { .id = 0x11060428, .name = "VT1718S",
6276 .patch = patch_vt1718S},
6277 { .id = 0x11064428, .name = "VT1718S",
6278 .patch = patch_vt1718S},
6279 { .id = 0x11060441, .name = "VT2020",
6280 .patch = patch_vt1718S},
6281 { .id = 0x11064441, .name = "VT1828S",
6282 .patch = patch_vt1718S},
6283 { .id = 0x11060433, .name = "VT1716S",
6284 .patch = patch_vt1716S},
6285 { .id = 0x1106a721, .name = "VT1716S",
6286 .patch = patch_vt1716S},
6287 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6288 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6289 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6290 { .id = 0x11060440, .name = "VT1818S",
6291 .patch = patch_vt1708S},
6295 MODULE_ALIAS("snd-hda-codec-id:1106*");
6297 static struct hda_codec_preset_list via_list = {
6298 .preset = snd_hda_preset_via,
6299 .owner = THIS_MODULE,
6302 MODULE_LICENSE("GPL");
6303 MODULE_DESCRIPTION("VIA HD-audio codec");
6305 static int __init patch_via_init(void)
6307 return snd_hda_add_codec_preset(&via_list);
6310 static void __exit patch_via_exit(void)
6312 snd_hda_delete_codec_preset(&via_list);
6315 module_init(patch_via_init)
6316 module_exit(patch_via_exit)