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"
58 #define AMP_VAL_IDX_SHIFT 19
59 #define AMP_VAL_IDX_MASK (0x0f<<19)
62 #define VT1708_HP_NID 0x13
63 #define VT1708_DIGOUT_NID 0x14
64 #define VT1708_DIGIN_NID 0x16
65 #define VT1708_DIGIN_PIN 0x26
66 #define VT1708_HP_PIN_NID 0x20
67 #define VT1708_CD_PIN_NID 0x24
69 #define VT1709_HP_DAC_NID 0x28
70 #define VT1709_DIGOUT_NID 0x13
71 #define VT1709_DIGIN_NID 0x17
72 #define VT1709_DIGIN_PIN 0x25
74 #define VT1708B_HP_NID 0x25
75 #define VT1708B_DIGOUT_NID 0x12
76 #define VT1708B_DIGIN_NID 0x15
77 #define VT1708B_DIGIN_PIN 0x21
79 #define VT1708S_HP_NID 0x25
80 #define VT1708S_DIGOUT_NID 0x12
82 #define VT1702_HP_NID 0x17
83 #define VT1702_DIGOUT_NID 0x11
103 /* codec parameterization */
104 struct snd_kcontrol_new *mixers[6];
105 unsigned int num_mixers;
107 struct hda_verb *init_verbs[5];
108 unsigned int num_iverbs;
110 char *stream_name_analog;
111 struct hda_pcm_stream *stream_analog_playback;
112 struct hda_pcm_stream *stream_analog_capture;
114 char *stream_name_digital;
115 struct hda_pcm_stream *stream_digital_playback;
116 struct hda_pcm_stream *stream_digital_capture;
119 struct hda_multi_out multiout;
120 hda_nid_t slave_dig_outs[2];
123 unsigned int num_adc_nids;
125 hda_nid_t mux_nids[3];
126 hda_nid_t dig_in_nid;
127 hda_nid_t dig_in_pin;
130 const struct hda_input_mux *input_mux;
131 unsigned int cur_mux[3];
133 /* PCM information */
134 struct hda_pcm pcm_rec[3];
136 /* dynamic controls, init_verbs and input_mux */
137 struct auto_pin_cfg autocfg;
138 struct snd_array kctls;
139 struct hda_input_mux private_imux[2];
140 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
143 const struct hda_input_mux *hp_mux;
144 unsigned int hp_independent_mode;
145 unsigned int hp_independent_mode_index;
146 unsigned int smart51_enabled;
147 unsigned int dmic_enabled;
148 enum VIA_HDA_CODEC codec_type;
150 /* work to check hp jack state */
151 struct hda_codec *codec;
152 struct delayed_work vt1708_hp_work;
153 int vt1708_jack_detectect;
154 int vt1708_hp_present;
155 #ifdef CONFIG_SND_HDA_POWER_SAVE
156 struct hda_loopback_check loopback;
160 static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
162 u32 vendor_id = codec->vendor_id;
163 u16 ven_id = vendor_id >> 16;
164 u16 dev_id = vendor_id & 0xffff;
165 enum VIA_HDA_CODEC codec_type;
168 if (ven_id != 0x1106)
169 codec_type = UNKNOWN;
170 else if (dev_id >= 0x1708 && dev_id <= 0x170b)
172 else if (dev_id >= 0xe710 && dev_id <= 0xe713)
173 codec_type = VT1709_10CH;
174 else if (dev_id >= 0xe714 && dev_id <= 0xe717)
175 codec_type = VT1709_6CH;
176 else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
177 codec_type = VT1708B_8CH;
178 if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
179 codec_type = VT1708BCE;
180 } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
181 codec_type = VT1708B_4CH;
182 else if ((dev_id & 0xfff) == 0x397
183 && (dev_id >> 12) < 8)
184 codec_type = VT1708S;
185 else if ((dev_id & 0xfff) == 0x398
186 && (dev_id >> 12) < 8)
188 else if ((dev_id & 0xfff) == 0x428
189 && (dev_id >> 12) < 8)
190 codec_type = VT1718S;
191 else if (dev_id == 0x0433 || dev_id == 0xa721)
192 codec_type = VT1716S;
193 else if (dev_id == 0x0441 || dev_id == 0x4441)
194 codec_type = VT1718S;
195 else if (dev_id == 0x0438 || dev_id == 0x4438)
196 codec_type = VT2002P;
197 else if (dev_id == 0x0448)
199 else if (dev_id == 0x0440)
200 codec_type = VT1708S;
202 codec_type = UNKNOWN;
206 #define VIA_HP_EVENT 0x01
207 #define VIA_GPIO_EVENT 0x02
208 #define VIA_JACK_EVENT 0x04
209 #define VIA_MONO_EVENT 0x08
210 #define VIA_SPEAKER_EVENT 0x10
211 #define VIA_BIND_HP_EVENT 0x20
216 VIA_CTL_WIDGET_ANALOG_MUTE,
217 VIA_CTL_WIDGET_BIND_PIN_MUTE,
227 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
228 static void set_jack_power_state(struct hda_codec *codec);
229 static int is_aa_path_mute(struct hda_codec *codec);
231 static void vt1708_start_hp_work(struct via_spec *spec)
233 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
235 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
236 !spec->vt1708_jack_detectect);
237 if (!delayed_work_pending(&spec->vt1708_hp_work))
238 schedule_delayed_work(&spec->vt1708_hp_work,
239 msecs_to_jiffies(100));
242 static void vt1708_stop_hp_work(struct via_spec *spec)
244 if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
246 if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
247 && !is_aa_path_mute(spec->codec))
249 snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
250 !spec->vt1708_jack_detectect);
251 cancel_delayed_work(&spec->vt1708_hp_work);
252 flush_scheduled_work();
256 static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_value *ucontrol)
259 int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262 set_jack_power_state(codec);
263 analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
264 if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
265 if (is_aa_path_mute(codec))
266 vt1708_start_hp_work(codec->spec);
268 vt1708_stop_hp_work(codec->spec);
273 /* modify .put = snd_hda_mixer_amp_switch_put */
274 #define ANALOG_INPUT_MUTE \
275 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
278 .info = snd_hda_mixer_amp_switch_info, \
279 .get = snd_hda_mixer_amp_switch_get, \
280 .put = analog_input_switch_put, \
281 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
283 static void via_hp_bind_automute(struct hda_codec *codec);
285 static int bind_pin_switch_put(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_value *ucontrol)
288 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
289 struct via_spec *spec = codec->spec;
293 long *valp = ucontrol->value.integer.value;
295 if (strstr(kcontrol->id.name, "Switch") == NULL) {
296 snd_printd("Invalid control!\n");
299 change = snd_hda_mixer_amp_switch_put(kcontrol,
302 lmute = *valp ? 0 : HDA_AMP_MUTE;
304 rmute = *valp ? 0 : HDA_AMP_MUTE;
307 if (!spec->hp_independent_mode) {
308 for (i = 0; i < spec->autocfg.hp_outs; i++) {
309 snd_hda_codec_amp_update(
310 codec, spec->autocfg.hp_pins[i],
311 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
313 snd_hda_codec_amp_update(
314 codec, spec->autocfg.hp_pins[i],
315 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
320 if (!lmute && !rmute) {
322 for (i = 0; i < spec->autocfg.line_outs; i++)
323 snd_hda_codec_amp_stereo(
324 codec, spec->autocfg.line_out_pins[i],
325 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
327 for (i = 0; i < spec->autocfg.speaker_outs; i++)
328 snd_hda_codec_amp_stereo(
329 codec, spec->autocfg.speaker_pins[i],
330 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
332 via_hp_bind_automute(codec);
336 /* Mute all left channels */
337 for (i = 1; i < spec->autocfg.line_outs; i++)
338 snd_hda_codec_amp_update(
340 spec->autocfg.line_out_pins[i],
341 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
343 for (i = 0; i < spec->autocfg.speaker_outs; i++)
344 snd_hda_codec_amp_update(
346 spec->autocfg.speaker_pins[i],
347 0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
351 /* mute all right 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 1, 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 1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
369 #define BIND_PIN_MUTE \
370 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
373 .info = snd_hda_mixer_amp_switch_info, \
374 .get = snd_hda_mixer_amp_switch_get, \
375 .put = bind_pin_switch_put, \
376 .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
378 static struct snd_kcontrol_new via_control_templates[] = {
379 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
380 HDA_CODEC_MUTE(NULL, 0, 0, 0),
385 static hda_nid_t vt1708_adc_nids[2] = {
390 static hda_nid_t vt1709_adc_nids[3] = {
395 static hda_nid_t vt1708B_adc_nids[2] = {
400 static hda_nid_t vt1708S_adc_nids[2] = {
405 static hda_nid_t vt1702_adc_nids[3] = {
410 static hda_nid_t vt1718S_adc_nids[2] = {
415 static hda_nid_t vt1716S_adc_nids[2] = {
420 static hda_nid_t vt2002P_adc_nids[2] = {
425 static hda_nid_t vt1812_adc_nids[2] = {
431 /* add dynamic controls */
432 static int via_add_control(struct via_spec *spec, int type, const char *name,
435 struct snd_kcontrol_new *knew;
437 snd_array_init(&spec->kctls, sizeof(*knew), 32);
438 knew = snd_array_new(&spec->kctls);
441 *knew = via_control_templates[type];
442 knew->name = kstrdup(name, GFP_KERNEL);
445 if (get_amp_nid_(val))
446 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
447 knew->private_value = val;
451 static void via_free_kctls(struct hda_codec *codec)
453 struct via_spec *spec = codec->spec;
455 if (spec->kctls.list) {
456 struct snd_kcontrol_new *kctl = spec->kctls.list;
458 for (i = 0; i < spec->kctls.used; i++)
461 snd_array_free(&spec->kctls);
464 /* create input playback/capture controls for the given pin */
465 static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
466 int idx, int mix_nid)
471 sprintf(name, "%s Playback Volume", ctlname);
472 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
473 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
476 sprintf(name, "%s Playback Switch", ctlname);
477 err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
478 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
484 static void via_auto_set_output_and_unmute(struct hda_codec *codec,
485 hda_nid_t nid, int pin_type,
489 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
491 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
493 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
494 snd_hda_codec_write(codec, nid, 0,
495 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
499 static void via_auto_init_multi_out(struct hda_codec *codec)
501 struct via_spec *spec = codec->spec;
504 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
505 hda_nid_t nid = spec->autocfg.line_out_pins[i];
507 via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
511 static void via_auto_init_hp_out(struct hda_codec *codec)
513 struct via_spec *spec = codec->spec;
517 for (i = 0; i < spec->autocfg.hp_outs; i++) {
518 pin = spec->autocfg.hp_pins[i];
519 if (pin) /* connect to front */
520 via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
524 static void via_auto_init_analog_input(struct hda_codec *codec)
526 struct via_spec *spec = codec->spec;
529 for (i = 0; i < AUTO_PIN_LAST; i++) {
530 hda_nid_t nid = spec->autocfg.input_pins[i];
532 snd_hda_codec_write(codec, nid, 0,
533 AC_VERB_SET_PIN_WIDGET_CONTROL,
534 (i <= AUTO_PIN_FRONT_MIC ?
535 PIN_VREF50 : PIN_IN));
540 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
542 static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
543 unsigned int *affected_parm)
546 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
547 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
548 >> AC_DEFCFG_MISC_SHIFT
549 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
550 unsigned present = snd_hda_codec_read(codec, nid, 0,
551 AC_VERB_GET_PIN_SENSE, 0) >> 31;
552 struct via_spec *spec = codec->spec;
553 if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
554 || ((no_presence || present)
555 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
556 *affected_parm = AC_PWRST_D0; /* if it's connected */
561 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
564 static void set_jack_power_state(struct hda_codec *codec)
566 struct via_spec *spec = codec->spec;
570 if (spec->codec_type == VT1702) {
571 imux_is_smixer = snd_hda_codec_read(
572 codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
574 /* PW 1/2/5 (14h/15h/18h) */
576 set_pin_power_state(codec, 0x14, &parm);
577 set_pin_power_state(codec, 0x15, &parm);
578 set_pin_power_state(codec, 0x18, &parm);
580 parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */
581 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
582 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
584 snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
586 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
588 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
592 /* PW 3/4 (16h/17h) */
594 set_pin_power_state(codec, 0x16, &parm);
595 set_pin_power_state(codec, 0x17, &parm);
596 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
597 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
598 imux_is_smixer ? AC_PWRST_D0 : parm);
599 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
601 snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
603 } else if (spec->codec_type == VT1708B_8CH
604 || spec->codec_type == VT1708B_4CH
605 || spec->codec_type == VT1708S) {
606 /* SW0 (17h) = stereo mixer */
607 int is_8ch = spec->codec_type != VT1708B_4CH;
608 imux_is_smixer = snd_hda_codec_read(
609 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
610 == ((spec->codec_type == VT1708S) ? 5 : 0);
612 /* PW 1/2/5 (1ah/1bh/1eh) */
614 set_pin_power_state(codec, 0x1a, &parm);
615 set_pin_power_state(codec, 0x1b, &parm);
616 set_pin_power_state(codec, 0x1e, &parm);
619 /* SW0 (17h), AIW 0/1 (13h/14h) */
620 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
622 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
624 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
628 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
630 set_pin_power_state(codec, 0x19, &parm);
631 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
633 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
636 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
639 set_pin_power_state(codec, 0x22, &parm);
640 snd_hda_codec_write(codec, 0x26, 0,
641 AC_VERB_SET_POWER_STATE, parm);
642 snd_hda_codec_write(codec, 0x24, 0,
643 AC_VERB_SET_POWER_STATE, parm);
646 /* PW 3/4/7 (1ch/1dh/23h) */
648 /* force to D0 for internal Speaker */
649 set_pin_power_state(codec, 0x1c, &parm);
650 set_pin_power_state(codec, 0x1d, &parm);
652 set_pin_power_state(codec, 0x23, &parm);
653 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
654 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
655 imux_is_smixer ? AC_PWRST_D0 : parm);
656 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
659 snd_hda_codec_write(codec, 0x25, 0,
660 AC_VERB_SET_POWER_STATE, parm);
661 snd_hda_codec_write(codec, 0x27, 0,
662 AC_VERB_SET_POWER_STATE, parm);
664 } else if (spec->codec_type == VT1718S) {
665 /* MUX6 (1eh) = stereo mixer */
666 imux_is_smixer = snd_hda_codec_read(
667 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
669 /* PW 5/6/7 (29h/2ah/2bh) */
671 set_pin_power_state(codec, 0x29, &parm);
672 set_pin_power_state(codec, 0x2a, &parm);
673 set_pin_power_state(codec, 0x2b, &parm);
676 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
677 snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
679 snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
681 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
683 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
687 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
689 set_pin_power_state(codec, 0x27, &parm);
690 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
692 snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
695 /* PW2 (26h), AOW2 (ah) */
697 set_pin_power_state(codec, 0x26, &parm);
698 snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
701 /* PW0/1 (24h/25h) */
703 set_pin_power_state(codec, 0x24, &parm);
704 set_pin_power_state(codec, 0x25, &parm);
705 if (!spec->hp_independent_mode) /* check for redirected HP */
706 set_pin_power_state(codec, 0x28, &parm);
707 snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
709 snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
711 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
712 snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
713 imux_is_smixer ? AC_PWRST_D0 : parm);
714 if (spec->hp_independent_mode) {
715 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
717 set_pin_power_state(codec, 0x28, &parm);
718 snd_hda_codec_write(codec, 0x1b, 0,
719 AC_VERB_SET_POWER_STATE, parm);
720 snd_hda_codec_write(codec, 0x34, 0,
721 AC_VERB_SET_POWER_STATE, parm);
722 snd_hda_codec_write(codec, 0xc, 0,
723 AC_VERB_SET_POWER_STATE, parm);
725 } else if (spec->codec_type == VT1716S) {
726 unsigned int mono_out, present;
727 /* SW0 (17h) = stereo mixer */
728 imux_is_smixer = snd_hda_codec_read(
729 codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
731 /* PW 1/2/5 (1ah/1bh/1eh) */
733 set_pin_power_state(codec, 0x1a, &parm);
734 set_pin_power_state(codec, 0x1b, &parm);
735 set_pin_power_state(codec, 0x1e, &parm);
738 /* SW0 (17h), AIW0(13h) */
739 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
741 snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
745 set_pin_power_state(codec, 0x1e, &parm);
747 if (spec->dmic_enabled)
748 set_pin_power_state(codec, 0x22, &parm);
752 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
754 /* SW2(26h), AIW1(14h) */
755 snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
757 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
761 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
763 set_pin_power_state(codec, 0x19, &parm);
764 /* Smart 5.1 PW2(1bh) */
765 if (spec->smart51_enabled)
766 set_pin_power_state(codec, 0x1b, &parm);
767 snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
769 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
772 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
774 set_pin_power_state(codec, 0x23, &parm);
775 /* Smart 5.1 PW1(1ah) */
776 if (spec->smart51_enabled)
777 set_pin_power_state(codec, 0x1a, &parm);
778 snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
781 /* Smart 5.1 PW5(1eh) */
782 if (spec->smart51_enabled)
783 set_pin_power_state(codec, 0x1e, &parm);
784 snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
788 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
789 present = snd_hda_codec_read(
790 codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
794 present = snd_hda_codec_read(
795 codec, 0x1d, 0, AC_VERB_GET_PIN_SENSE, 0)
797 if (!spec->hp_independent_mode && present)
802 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
803 snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
805 snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
807 snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
810 /* PW 3/4 (1ch/1dh) */
812 set_pin_power_state(codec, 0x1c, &parm);
813 set_pin_power_state(codec, 0x1d, &parm);
814 /* HP Independent Mode, power on AOW3 */
815 if (spec->hp_independent_mode)
816 snd_hda_codec_write(codec, 0x25, 0,
817 AC_VERB_SET_POWER_STATE, parm);
819 /* force to D0 for internal Speaker */
820 /* MW0 (16h), AOW0 (10h) */
821 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
822 imux_is_smixer ? AC_PWRST_D0 : parm);
823 snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
824 mono_out ? AC_PWRST_D0 : parm);
825 } else if (spec->codec_type == VT2002P) {
826 unsigned int present;
827 /* MUX9 (1eh) = stereo mixer */
828 imux_is_smixer = snd_hda_codec_read(
829 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
831 /* PW 5/6/7 (29h/2ah/2bh) */
833 set_pin_power_state(codec, 0x29, &parm);
834 set_pin_power_state(codec, 0x2a, &parm);
835 set_pin_power_state(codec, 0x2b, &parm);
838 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
839 snd_hda_codec_write(codec, 0x1e, 0,
840 AC_VERB_SET_POWER_STATE, parm);
841 snd_hda_codec_write(codec, 0x1f, 0,
842 AC_VERB_SET_POWER_STATE, parm);
843 snd_hda_codec_write(codec, 0x10, 0,
844 AC_VERB_SET_POWER_STATE, parm);
845 snd_hda_codec_write(codec, 0x11, 0,
846 AC_VERB_SET_POWER_STATE, parm);
850 snd_hda_codec_write(codec, 0x8, 0,
851 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
853 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
855 set_pin_power_state(codec, 0x26, &parm);
856 snd_hda_codec_write(codec, 0x1c, 0,
857 AC_VERB_SET_POWER_STATE, parm);
858 snd_hda_codec_write(codec, 0x37,
859 0, AC_VERB_SET_POWER_STATE, parm);
861 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
863 set_pin_power_state(codec, 0x25, &parm);
864 snd_hda_codec_write(codec, 0x19, 0,
865 AC_VERB_SET_POWER_STATE, parm);
866 snd_hda_codec_write(codec, 0x35, 0,
867 AC_VERB_SET_POWER_STATE, parm);
868 if (spec->hp_independent_mode) {
869 snd_hda_codec_write(codec, 0x9, 0,
870 AC_VERB_SET_POWER_STATE, parm);
874 /* PW0 (24h), MW0(18h), MUX0(34h) */
875 present = snd_hda_codec_read(
876 codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
878 set_pin_power_state(codec, 0x24, &parm);
882 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
885 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
889 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
892 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
896 /* PW15 (31h), MW8(17h), MUX8(3bh) */
897 present = snd_hda_codec_read(
898 codec, 0x26, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
900 set_pin_power_state(codec, 0x31, &parm);
904 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
907 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
911 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
914 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
918 if (imux_is_smixer || !is_aa_path_mute(codec))
921 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
925 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
926 } else if (spec->codec_type == VT1812) {
927 unsigned int present;
928 /* MUX10 (1eh) = stereo mixer */
929 imux_is_smixer = snd_hda_codec_read(
930 codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
932 /* PW 5/6/7 (29h/2ah/2bh) */
934 set_pin_power_state(codec, 0x29, &parm);
935 set_pin_power_state(codec, 0x2a, &parm);
936 set_pin_power_state(codec, 0x2b, &parm);
939 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
940 snd_hda_codec_write(codec, 0x1e, 0,
941 AC_VERB_SET_POWER_STATE, parm);
942 snd_hda_codec_write(codec, 0x1f, 0,
943 AC_VERB_SET_POWER_STATE, parm);
944 snd_hda_codec_write(codec, 0x10, 0,
945 AC_VERB_SET_POWER_STATE, parm);
946 snd_hda_codec_write(codec, 0x11, 0,
947 AC_VERB_SET_POWER_STATE, parm);
951 snd_hda_codec_write(codec, 0x8, 0,
952 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
954 /* PW4 (28h), MW4 (18h), MUX4(38h) */
956 set_pin_power_state(codec, 0x28, &parm);
957 snd_hda_codec_write(codec, 0x18, 0,
958 AC_VERB_SET_POWER_STATE, parm);
959 snd_hda_codec_write(codec, 0x38, 0,
960 AC_VERB_SET_POWER_STATE, parm);
962 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
964 set_pin_power_state(codec, 0x25, &parm);
965 snd_hda_codec_write(codec, 0x15, 0,
966 AC_VERB_SET_POWER_STATE, parm);
967 snd_hda_codec_write(codec, 0x35, 0,
968 AC_VERB_SET_POWER_STATE, parm);
969 if (spec->hp_independent_mode) {
970 snd_hda_codec_write(codec, 0x9, 0,
971 AC_VERB_SET_POWER_STATE, parm);
974 /* Internal Speaker */
975 /* PW0 (24h), MW0(14h), MUX0(34h) */
976 present = snd_hda_codec_read(
977 codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
979 set_pin_power_state(codec, 0x24, &parm);
981 snd_hda_codec_write(codec, 0x14, 0,
982 AC_VERB_SET_POWER_STATE,
984 snd_hda_codec_write(codec, 0x34, 0,
985 AC_VERB_SET_POWER_STATE,
988 snd_hda_codec_write(codec, 0x14, 0,
989 AC_VERB_SET_POWER_STATE,
991 snd_hda_codec_write(codec, 0x34, 0,
992 AC_VERB_SET_POWER_STATE,
996 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
997 present = snd_hda_codec_read(
998 codec, 0x28, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1000 set_pin_power_state(codec, 0x31, &parm);
1002 snd_hda_codec_write(codec, 0x1c, 0,
1003 AC_VERB_SET_POWER_STATE,
1005 snd_hda_codec_write(codec, 0x3c, 0,
1006 AC_VERB_SET_POWER_STATE,
1008 snd_hda_codec_write(codec, 0x3e, 0,
1009 AC_VERB_SET_POWER_STATE,
1012 snd_hda_codec_write(codec, 0x1c, 0,
1013 AC_VERB_SET_POWER_STATE,
1015 snd_hda_codec_write(codec, 0x3c, 0,
1016 AC_VERB_SET_POWER_STATE,
1018 snd_hda_codec_write(codec, 0x3e, 0,
1019 AC_VERB_SET_POWER_STATE,
1023 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1025 set_pin_power_state(codec, 0x33, &parm);
1026 snd_hda_codec_write(codec, 0x1d, 0,
1027 AC_VERB_SET_POWER_STATE, parm);
1028 snd_hda_codec_write(codec, 0x3d, 0,
1029 AC_VERB_SET_POWER_STATE, parm);
1032 if (imux_is_smixer || !is_aa_path_mute(codec))
1033 snd_hda_codec_write(
1035 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1037 snd_hda_codec_write(
1039 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
1044 * input MUX handling
1046 static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
1047 struct snd_ctl_elem_info *uinfo)
1049 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1050 struct via_spec *spec = codec->spec;
1051 return snd_hda_input_mux_info(spec->input_mux, uinfo);
1054 static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
1055 struct snd_ctl_elem_value *ucontrol)
1057 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1058 struct via_spec *spec = codec->spec;
1059 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1061 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
1065 static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
1066 struct snd_ctl_elem_value *ucontrol)
1068 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1069 struct via_spec *spec = codec->spec;
1070 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1072 if (!spec->mux_nids[adc_idx])
1074 /* switch to D0 beofre change index */
1075 if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
1076 AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
1077 snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
1078 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
1079 /* update jack power state */
1080 set_jack_power_state(codec);
1082 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
1083 spec->mux_nids[adc_idx],
1084 &spec->cur_mux[adc_idx]);
1087 static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
1088 struct snd_ctl_elem_info *uinfo)
1090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1091 struct via_spec *spec = codec->spec;
1092 return snd_hda_input_mux_info(spec->hp_mux, uinfo);
1095 static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
1096 struct snd_ctl_elem_value *ucontrol)
1098 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1099 struct via_spec *spec = codec->spec;
1101 unsigned int pinsel;
1103 switch (spec->codec_type) {
1114 nid = spec->autocfg.hp_pins[0];
1117 /* use !! to translate conn sel 2 for VT1718S */
1118 pinsel = !!snd_hda_codec_read(codec, nid, 0,
1119 AC_VERB_GET_CONNECT_SEL,
1121 ucontrol->value.enumerated.item[0] = pinsel;
1126 static void activate_ctl(struct hda_codec *codec, const char *name, int active)
1128 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
1130 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1131 ctl->vd[0].access |= active
1132 ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1133 snd_ctl_notify(codec->bus->card,
1134 SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
1138 static int update_side_mute_status(struct hda_codec *codec)
1140 /* mute side channel */
1141 struct via_spec *spec = codec->spec;
1142 unsigned int parm = spec->hp_independent_mode
1143 ? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
1146 switch (spec->codec_type) {
1163 snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1168 static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
1169 struct snd_ctl_elem_value *ucontrol)
1171 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1172 struct via_spec *spec = codec->spec;
1173 hda_nid_t nid = spec->autocfg.hp_pins[0];
1174 unsigned int pinsel = ucontrol->value.enumerated.item[0];
1175 /* Get Independent Mode index of headphone pin widget */
1176 spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
1179 switch (spec->codec_type) {
1182 pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
1183 spec->multiout.num_dacs = 4;
1192 nid = spec->autocfg.hp_pins[0];
1195 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
1197 if (spec->multiout.hp_nid && spec->multiout.hp_nid
1198 != spec->multiout.dac_nids[HDA_FRONT])
1199 snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
1202 update_side_mute_status(codec);
1203 /* update HP volume/swtich active state */
1204 if (spec->codec_type == VT1708S
1205 || spec->codec_type == VT1702
1206 || spec->codec_type == VT1718S
1207 || spec->codec_type == VT1716S
1208 || spec->codec_type == VT2002P
1209 || spec->codec_type == VT1812) {
1210 activate_ctl(codec, "Headphone Playback Volume",
1211 spec->hp_independent_mode);
1212 activate_ctl(codec, "Headphone Playback Switch",
1213 spec->hp_independent_mode);
1218 static struct snd_kcontrol_new via_hp_mixer[] = {
1220 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1221 .name = "Independent HP",
1223 .info = via_independent_hp_info,
1224 .get = via_independent_hp_get,
1225 .put = via_independent_hp_put,
1230 static void notify_aa_path_ctls(struct hda_codec *codec)
1233 struct snd_ctl_elem_id id;
1234 const char *labels[] = {"Mic", "Front Mic", "Line"};
1236 memset(&id, 0, sizeof(id));
1237 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1238 for (i = 0; i < ARRAY_SIZE(labels); i++) {
1239 sprintf(id.name, "%s Playback Volume", labels[i]);
1240 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1245 static void mute_aa_path(struct hda_codec *codec, int mute)
1247 struct via_spec *spec = codec->spec;
1248 hda_nid_t nid_mixer;
1252 /* get nid of MW0 and start & end index */
1253 switch (spec->codec_type) {
1276 /* check AA path's mute status */
1277 for (i = start_idx; i <= end_idx; i++) {
1278 int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
1279 snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
1283 static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
1287 for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
1288 if (pin == spec->autocfg.input_pins[index]) {
1296 static int via_smart51_info(struct snd_kcontrol *kcontrol,
1297 struct snd_ctl_elem_info *uinfo)
1299 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1301 uinfo->value.integer.min = 0;
1302 uinfo->value.integer.max = 1;
1306 static int via_smart51_get(struct snd_kcontrol *kcontrol,
1307 struct snd_ctl_elem_value *ucontrol)
1309 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1310 struct via_spec *spec = codec->spec;
1311 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1315 for (i = 0; i < ARRAY_SIZE(index); i++) {
1316 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1319 snd_hda_codec_read(codec, nid, 0,
1320 AC_VERB_GET_PIN_WIDGET_CONTROL,
1322 if (i == AUTO_PIN_FRONT_MIC
1323 && spec->hp_independent_mode
1324 && spec->codec_type != VT1718S)
1325 continue; /* ignore FMic for independent HP */
1326 if (ctl & AC_PINCTL_IN_EN
1327 && !(ctl & AC_PINCTL_OUT_EN))
1331 *ucontrol->value.integer.value = on;
1335 static int via_smart51_put(struct snd_kcontrol *kcontrol,
1336 struct snd_ctl_elem_value *ucontrol)
1338 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1339 struct via_spec *spec = codec->spec;
1340 int out_in = *ucontrol->value.integer.value
1341 ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
1342 int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
1345 for (i = 0; i < ARRAY_SIZE(index); i++) {
1346 hda_nid_t nid = spec->autocfg.input_pins[index[i]];
1347 if (i == AUTO_PIN_FRONT_MIC
1348 && spec->hp_independent_mode
1349 && spec->codec_type != VT1718S)
1350 continue; /* don't retask FMic for independent HP */
1352 unsigned int parm = snd_hda_codec_read(
1354 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
1355 parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
1357 snd_hda_codec_write(codec, nid, 0,
1358 AC_VERB_SET_PIN_WIDGET_CONTROL,
1360 if (out_in == AC_PINCTL_OUT_EN) {
1361 mute_aa_path(codec, 1);
1362 notify_aa_path_ctls(codec);
1364 if (spec->codec_type == VT1718S)
1365 snd_hda_codec_amp_stereo(
1366 codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1369 if (i == AUTO_PIN_FRONT_MIC) {
1370 if (spec->codec_type == VT1708S
1371 || spec->codec_type == VT1716S) {
1372 /* input = index 1 (AOW3) */
1373 snd_hda_codec_write(
1375 AC_VERB_SET_CONNECT_SEL, 1);
1376 snd_hda_codec_amp_stereo(
1377 codec, nid, HDA_OUTPUT,
1378 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
1382 spec->smart51_enabled = *ucontrol->value.integer.value;
1383 set_jack_power_state(codec);
1387 static struct snd_kcontrol_new via_smart51_mixer[] = {
1389 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1390 .name = "Smart 5.1",
1392 .info = via_smart51_info,
1393 .get = via_smart51_get,
1394 .put = via_smart51_put,
1399 /* capture mixer elements */
1400 static struct snd_kcontrol_new vt1708_capture_mixer[] = {
1401 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
1402 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
1403 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
1404 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
1406 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1407 /* The multiple "Capture Source" controls confuse alsamixer
1408 * So call somewhat different..
1410 /* .name = "Capture Source", */
1411 .name = "Input Source",
1413 .info = via_mux_enum_info,
1414 .get = via_mux_enum_get,
1415 .put = via_mux_enum_put,
1420 /* check AA path's mute statue */
1421 static int is_aa_path_mute(struct hda_codec *codec)
1424 hda_nid_t nid_mixer;
1428 struct via_spec *spec = codec->spec;
1429 /* get nid of MW0 and start & end index */
1430 switch (spec->codec_type) {
1458 /* check AA path's mute status */
1459 for (i = start_idx; i <= end_idx; i++) {
1460 unsigned int con_list = snd_hda_codec_read(
1461 codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
1462 int shift = 8 * (i % 4);
1463 hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
1464 unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
1465 if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
1466 /* check mute status while the pin is connected */
1467 int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
1469 int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
1471 if (!mute_l || !mute_r) {
1480 /* enter/exit analog low-current mode */
1481 static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
1483 struct via_spec *spec = codec->spec;
1484 static int saved_stream_idle = 1; /* saved stream idle status */
1485 int enable = is_aa_path_mute(codec);
1486 unsigned int verb = 0;
1487 unsigned int parm = 0;
1489 if (stream_idle == -1) /* stream status did not change */
1490 enable = enable && saved_stream_idle;
1492 enable = enable && stream_idle;
1493 saved_stream_idle = stream_idle;
1496 /* decide low current mode's verb & parameter */
1497 switch (spec->codec_type) {
1501 parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
1507 parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
1511 parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
1516 parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
1519 return; /* other codecs are not supported */
1522 snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
1526 * generic initialization of ADC, input mixers and output mixers
1528 static struct hda_verb vt1708_volume_init_verbs[] = {
1530 * Unmute ADC0-1 and set the default input to mic-in
1532 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1533 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1536 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1539 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
1540 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1541 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1542 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1543 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1544 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1547 * Set up output mixers (0x19 - 0x1b)
1549 /* set vol=0 to output mixers */
1550 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1551 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1552 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1554 /* Setup default input MW0 to PW4 */
1555 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
1556 /* PW9 Output enable */
1557 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
1561 static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
1562 struct hda_codec *codec,
1563 struct snd_pcm_substream *substream)
1565 struct via_spec *spec = codec->spec;
1566 int idle = substream->pstr->substream_opened == 1
1567 && substream->ref_count == 0;
1568 analog_low_current_mode(codec, idle);
1569 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1573 static void playback_multi_pcm_prep_0(struct hda_codec *codec,
1574 unsigned int stream_tag,
1575 unsigned int format,
1576 struct snd_pcm_substream *substream)
1578 struct via_spec *spec = codec->spec;
1579 struct hda_multi_out *mout = &spec->multiout;
1580 hda_nid_t *nids = mout->dac_nids;
1581 int chs = substream->runtime->channels;
1584 mutex_lock(&codec->spdif_mutex);
1585 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
1587 snd_hda_is_supported_format(codec, mout->dig_out_nid,
1589 !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
1590 mout->dig_out_used = HDA_DIG_ANALOG_DUP;
1591 /* turn off SPDIF once; otherwise the IEC958 bits won't
1593 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1594 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1595 AC_VERB_SET_DIGI_CONVERT_1,
1597 ~AC_DIG1_ENABLE & 0xff);
1598 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1599 stream_tag, 0, format);
1600 /* turn on again (if needed) */
1601 if (codec->spdif_ctls & AC_DIG1_ENABLE)
1602 snd_hda_codec_write(codec, mout->dig_out_nid, 0,
1603 AC_VERB_SET_DIGI_CONVERT_1,
1604 codec->spdif_ctls & 0xff);
1606 mout->dig_out_used = 0;
1607 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1611 mutex_unlock(&codec->spdif_mutex);
1614 snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
1617 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
1618 && !spec->hp_independent_mode)
1619 /* headphone out will just decode front left/right (stereo) */
1620 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
1623 /* extra outputs copied from front */
1624 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1625 if (mout->extra_out_nid[i])
1626 snd_hda_codec_setup_stream(codec,
1627 mout->extra_out_nid[i],
1628 stream_tag, 0, format);
1631 for (i = 1; i < mout->num_dacs; i++) {
1632 if (chs >= (i + 1) * 2) /* independent out */
1633 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1635 else /* copy front */
1636 snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
1641 static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
1642 struct hda_codec *codec,
1643 unsigned int stream_tag,
1644 unsigned int format,
1645 struct snd_pcm_substream *substream)
1647 struct via_spec *spec = codec->spec;
1648 struct hda_multi_out *mout = &spec->multiout;
1649 hda_nid_t *nids = mout->dac_nids;
1651 if (substream->number == 0)
1652 playback_multi_pcm_prep_0(codec, stream_tag, format,
1655 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1656 spec->hp_independent_mode)
1657 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1658 stream_tag, 0, format);
1660 vt1708_start_hp_work(spec);
1664 static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
1665 struct hda_codec *codec,
1666 struct snd_pcm_substream *substream)
1668 struct via_spec *spec = codec->spec;
1669 struct hda_multi_out *mout = &spec->multiout;
1670 hda_nid_t *nids = mout->dac_nids;
1673 if (substream->number == 0) {
1674 for (i = 0; i < mout->num_dacs; i++)
1675 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
1677 if (mout->hp_nid && !spec->hp_independent_mode)
1678 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1681 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
1682 if (mout->extra_out_nid[i])
1683 snd_hda_codec_setup_stream(codec,
1684 mout->extra_out_nid[i],
1686 mutex_lock(&codec->spdif_mutex);
1687 if (mout->dig_out_nid &&
1688 mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
1689 snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
1691 mout->dig_out_used = 0;
1693 mutex_unlock(&codec->spdif_mutex);
1695 if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
1696 spec->hp_independent_mode)
1697 snd_hda_codec_setup_stream(codec, mout->hp_nid,
1700 vt1708_stop_hp_work(spec);
1707 static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1708 struct hda_codec *codec,
1709 struct snd_pcm_substream *substream)
1711 struct via_spec *spec = codec->spec;
1712 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1715 static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1716 struct hda_codec *codec,
1717 struct snd_pcm_substream *substream)
1719 struct via_spec *spec = codec->spec;
1720 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1723 static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1724 struct hda_codec *codec,
1725 unsigned int stream_tag,
1726 unsigned int format,
1727 struct snd_pcm_substream *substream)
1729 struct via_spec *spec = codec->spec;
1730 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1731 stream_tag, format, substream);
1734 static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1735 struct hda_codec *codec,
1736 struct snd_pcm_substream *substream)
1738 struct via_spec *spec = codec->spec;
1739 snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1746 static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1747 struct hda_codec *codec,
1748 unsigned int stream_tag,
1749 unsigned int format,
1750 struct snd_pcm_substream *substream)
1752 struct via_spec *spec = codec->spec;
1754 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1755 stream_tag, 0, format);
1759 static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1760 struct hda_codec *codec,
1761 struct snd_pcm_substream *substream)
1763 struct via_spec *spec = codec->spec;
1764 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1768 static struct hda_pcm_stream vt1708_pcm_analog_playback = {
1772 .nid = 0x10, /* NID to query formats and rates */
1774 .open = via_playback_pcm_open,
1775 .prepare = via_playback_multi_pcm_prepare,
1776 .cleanup = via_playback_multi_pcm_cleanup
1780 static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
1784 .nid = 0x10, /* NID to query formats and rates */
1785 /* We got noisy outputs on the right channel on VT1708 when
1786 * 24bit samples are used. Until any workaround is found,
1787 * disable the 24bit format, so far.
1789 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1791 .open = via_playback_pcm_open,
1792 .prepare = via_playback_multi_pcm_prepare,
1793 .cleanup = via_playback_multi_pcm_cleanup
1797 static struct hda_pcm_stream vt1708_pcm_analog_capture = {
1801 .nid = 0x15, /* NID to query formats and rates */
1803 .prepare = via_capture_pcm_prepare,
1804 .cleanup = via_capture_pcm_cleanup
1808 static struct hda_pcm_stream vt1708_pcm_digital_playback = {
1812 /* NID is set in via_build_pcms */
1814 .open = via_dig_playback_pcm_open,
1815 .close = via_dig_playback_pcm_close,
1816 .prepare = via_dig_playback_pcm_prepare,
1817 .cleanup = via_dig_playback_pcm_cleanup
1821 static struct hda_pcm_stream vt1708_pcm_digital_capture = {
1827 static int via_build_controls(struct hda_codec *codec)
1829 struct via_spec *spec = codec->spec;
1833 for (i = 0; i < spec->num_mixers; i++) {
1834 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1839 if (spec->multiout.dig_out_nid) {
1840 err = snd_hda_create_spdif_out_ctls(codec,
1841 spec->multiout.dig_out_nid);
1844 err = snd_hda_create_spdif_share_sw(codec,
1848 spec->multiout.share_spdif = 1;
1850 if (spec->dig_in_nid) {
1851 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1856 /* init power states */
1857 set_jack_power_state(codec);
1858 analog_low_current_mode(codec, 1);
1860 via_free_kctls(codec); /* no longer needed */
1864 static int via_build_pcms(struct hda_codec *codec)
1866 struct via_spec *spec = codec->spec;
1867 struct hda_pcm *info = spec->pcm_rec;
1869 codec->num_pcms = 1;
1870 codec->pcm_info = info;
1872 info->name = spec->stream_name_analog;
1873 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1874 *(spec->stream_analog_playback);
1875 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1876 spec->multiout.dac_nids[0];
1877 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
1878 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1880 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1881 spec->multiout.max_channels;
1883 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1886 info->name = spec->stream_name_digital;
1887 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1888 if (spec->multiout.dig_out_nid) {
1889 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1890 *(spec->stream_digital_playback);
1891 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1892 spec->multiout.dig_out_nid;
1894 if (spec->dig_in_nid) {
1895 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1896 *(spec->stream_digital_capture);
1897 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1905 static void via_free(struct hda_codec *codec)
1907 struct via_spec *spec = codec->spec;
1912 via_free_kctls(codec);
1913 vt1708_stop_hp_work(spec);
1917 /* mute internal speaker if HP is plugged */
1918 static void via_hp_automute(struct hda_codec *codec)
1920 unsigned int present = 0;
1921 struct via_spec *spec = codec->spec;
1923 present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
1924 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1926 if (!spec->hp_independent_mode) {
1927 struct snd_ctl_elem_id id;
1929 snd_hda_codec_amp_stereo(
1930 codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
1931 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1933 memset(&id, 0, sizeof(id));
1934 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1935 strcpy(id.name, "Front Playback Switch");
1936 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
1941 /* mute mono out if HP or Line out is plugged */
1942 static void via_mono_automute(struct hda_codec *codec)
1944 unsigned int hp_present, lineout_present;
1945 struct via_spec *spec = codec->spec;
1947 if (spec->codec_type != VT1716S)
1950 lineout_present = snd_hda_codec_read(
1951 codec, spec->autocfg.line_out_pins[0], 0,
1952 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1954 /* Mute Mono Out if Line Out is plugged */
1955 if (lineout_present) {
1956 snd_hda_codec_amp_stereo(
1957 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
1961 hp_present = snd_hda_codec_read(
1962 codec, spec->autocfg.hp_pins[0], 0,
1963 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1965 if (!spec->hp_independent_mode)
1966 snd_hda_codec_amp_stereo(
1967 codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
1968 hp_present ? HDA_AMP_MUTE : 0);
1971 static void via_gpio_control(struct hda_codec *codec)
1973 unsigned int gpio_data;
1974 unsigned int vol_counter;
1976 unsigned int master_vol;
1978 struct via_spec *spec = codec->spec;
1980 gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
1981 AC_VERB_GET_GPIO_DATA, 0) & 0x03;
1983 vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
1984 0xF84, 0) & 0x3F0000) >> 16;
1986 vol = vol_counter & 0x1F;
1987 master_vol = snd_hda_codec_read(codec, 0x1A, 0,
1988 AC_VERB_GET_AMP_GAIN_MUTE,
1991 if (gpio_data == 0x02) {
1992 /* unmute line out */
1993 snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
1994 HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
1996 if (vol_counter & 0x20) {
1997 /* decrease volume */
1998 if (vol > master_vol)
2000 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
2004 /* increase volume */
2005 snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
2007 ((master_vol+vol) > 0x2A) ? 0x2A :
2010 } else if (!(gpio_data & 0x02)) {
2012 snd_hda_codec_amp_stereo(codec,
2013 spec->autocfg.line_out_pins[0],
2014 HDA_OUTPUT, 0, HDA_AMP_MUTE,
2019 /* mute Internal-Speaker if HP is plugged */
2020 static void via_speaker_automute(struct hda_codec *codec)
2022 unsigned int hp_present;
2023 struct via_spec *spec = codec->spec;
2025 if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
2028 hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
2029 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2031 if (!spec->hp_independent_mode) {
2032 struct snd_ctl_elem_id id;
2033 snd_hda_codec_amp_stereo(
2034 codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
2035 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2037 memset(&id, 0, sizeof(id));
2038 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2039 strcpy(id.name, "Speaker Playback Switch");
2040 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
2045 /* mute line-out and internal speaker if HP is plugged */
2046 static void via_hp_bind_automute(struct hda_codec *codec)
2048 /* use long instead of int below just to avoid an internal compiler
2049 * error with gcc 4.0.x
2051 unsigned long hp_present, present = 0;
2052 struct via_spec *spec = codec->spec;
2055 if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
2058 hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
2059 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2061 present = snd_hda_codec_read(codec, spec->autocfg.line_out_pins[0], 0,
2062 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2064 if (!spec->hp_independent_mode) {
2065 /* Mute Line-Outs */
2066 for (i = 0; i < spec->autocfg.line_outs; i++)
2067 snd_hda_codec_amp_stereo(
2068 codec, spec->autocfg.line_out_pins[i],
2070 HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
2072 present = hp_present;
2075 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2076 snd_hda_codec_amp_stereo(
2077 codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
2078 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
2082 /* unsolicited event for jack sensing */
2083 static void via_unsol_event(struct hda_codec *codec,
2087 if (res & VIA_HP_EVENT)
2088 via_hp_automute(codec);
2089 if (res & VIA_GPIO_EVENT)
2090 via_gpio_control(codec);
2091 if (res & VIA_JACK_EVENT)
2092 set_jack_power_state(codec);
2093 if (res & VIA_MONO_EVENT)
2094 via_mono_automute(codec);
2095 if (res & VIA_SPEAKER_EVENT)
2096 via_speaker_automute(codec);
2097 if (res & VIA_BIND_HP_EVENT)
2098 via_hp_bind_automute(codec);
2101 static int via_init(struct hda_codec *codec)
2103 struct via_spec *spec = codec->spec;
2105 for (i = 0; i < spec->num_iverbs; i++)
2106 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2108 spec->codec_type = get_codec_type(codec);
2109 if (spec->codec_type == VT1708BCE)
2110 spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
2112 /* Lydia Add for EAPD enable */
2113 if (!spec->dig_in_nid) { /* No Digital In connection */
2114 if (spec->dig_in_pin) {
2115 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2116 AC_VERB_SET_PIN_WIDGET_CONTROL,
2118 snd_hda_codec_write(codec, spec->dig_in_pin, 0,
2119 AC_VERB_SET_EAPD_BTLENABLE, 0x02);
2121 } else /* enable SPDIF-input pin */
2122 snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
2123 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
2125 /* assign slave outs */
2126 if (spec->slave_dig_outs[0])
2127 codec->slave_dig_outs = spec->slave_dig_outs;
2132 #ifdef SND_HDA_NEEDS_RESUME
2133 static int via_suspend(struct hda_codec *codec, pm_message_t state)
2135 struct via_spec *spec = codec->spec;
2136 vt1708_stop_hp_work(spec);
2141 #ifdef CONFIG_SND_HDA_POWER_SAVE
2142 static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2144 struct via_spec *spec = codec->spec;
2145 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2151 static struct hda_codec_ops via_patch_ops = {
2152 .build_controls = via_build_controls,
2153 .build_pcms = via_build_pcms,
2156 #ifdef SND_HDA_NEEDS_RESUME
2157 .suspend = via_suspend,
2159 #ifdef CONFIG_SND_HDA_POWER_SAVE
2160 .check_power_status = via_check_power_status,
2164 /* fill in the dac_nids table from the parsed pin configuration */
2165 static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
2166 const struct auto_pin_cfg *cfg)
2171 spec->multiout.num_dacs = cfg->line_outs;
2173 spec->multiout.dac_nids = spec->private_dac_nids;
2175 for (i = 0; i < 4; i++) {
2176 nid = cfg->line_out_pins[i];
2178 /* config dac list */
2180 case AUTO_SEQ_FRONT:
2181 spec->multiout.dac_nids[i] = 0x10;
2183 case AUTO_SEQ_CENLFE:
2184 spec->multiout.dac_nids[i] = 0x12;
2186 case AUTO_SEQ_SURROUND:
2187 spec->multiout.dac_nids[i] = 0x11;
2190 spec->multiout.dac_nids[i] = 0x13;
2199 /* add playback controls from the parsed DAC table */
2200 static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
2201 const struct auto_pin_cfg *cfg)
2204 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2205 hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b};
2208 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2209 nid = cfg->line_out_pins[i];
2214 nid_vol = nid_vols[i];
2216 if (i == AUTO_SEQ_CENLFE) {
2218 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2219 "Center Playback Volume",
2220 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2224 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2225 "LFE Playback Volume",
2226 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2230 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2231 "Center Playback Switch",
2232 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2236 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2237 "LFE Playback Switch",
2238 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2242 } else if (i == AUTO_SEQ_FRONT) {
2243 /* add control to mixer index 0 */
2244 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2245 "Master Front Playback Volume",
2246 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2250 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2251 "Master Front Playback Switch",
2252 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2257 /* add control to PW3 */
2258 sprintf(name, "%s Playback Volume", chname[i]);
2259 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2260 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2264 sprintf(name, "%s Playback Switch", chname[i]);
2265 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2266 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2271 sprintf(name, "%s Playback Volume", chname[i]);
2272 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2273 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2277 sprintf(name, "%s Playback Switch", chname[i]);
2278 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2279 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2289 static void create_hp_imux(struct via_spec *spec)
2292 struct hda_input_mux *imux = &spec->private_imux[1];
2293 static const char *texts[] = { "OFF", "ON", NULL};
2295 /* for hp mode select */
2297 while (texts[i] != NULL) {
2298 imux->items[imux->num_items].label = texts[i];
2299 imux->items[imux->num_items].index = i;
2304 spec->hp_mux = &spec->private_imux[1];
2307 static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2314 spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
2315 spec->hp_independent_mode_index = 1;
2317 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2318 "Headphone Playback Volume",
2319 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2322 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2323 "Headphone Playback Switch",
2324 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2328 create_hp_imux(spec);
2333 /* create playback/capture controls for input pins */
2334 static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
2335 const struct auto_pin_cfg *cfg)
2337 static char *labels[] = {
2338 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2340 struct hda_input_mux *imux = &spec->private_imux[0];
2341 int i, err, idx = 0;
2343 /* for internal loopback recording select */
2344 imux->items[imux->num_items].label = "Stereo Mixer";
2345 imux->items[imux->num_items].index = idx;
2348 for (i = 0; i < AUTO_PIN_LAST; i++) {
2349 if (!cfg->input_pins[i])
2352 switch (cfg->input_pins[i]) {
2353 case 0x1d: /* Mic */
2357 case 0x1e: /* Line In */
2361 case 0x21: /* Front Mic */
2369 err = via_new_analog_input(spec, labels[i], idx, 0x17);
2372 imux->items[imux->num_items].label = labels[i];
2373 imux->items[imux->num_items].index = idx;
2379 #ifdef CONFIG_SND_HDA_POWER_SAVE
2380 static struct hda_amp_list vt1708_loopbacks[] = {
2381 { 0x17, HDA_INPUT, 1 },
2382 { 0x17, HDA_INPUT, 2 },
2383 { 0x17, HDA_INPUT, 3 },
2384 { 0x17, HDA_INPUT, 4 },
2389 static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
2391 unsigned int def_conf;
2392 unsigned char seqassoc;
2394 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2395 seqassoc = (unsigned char) get_defcfg_association(def_conf);
2396 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
2397 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
2398 && (seqassoc == 0xf0 || seqassoc == 0xff)) {
2399 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
2400 snd_hda_codec_set_pincfg(codec, nid, def_conf);
2406 static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol,
2407 struct snd_ctl_elem_value *ucontrol)
2409 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2410 struct via_spec *spec = codec->spec;
2412 if (spec->codec_type != VT1708)
2414 spec->vt1708_jack_detectect =
2415 !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
2416 ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
2420 static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol,
2421 struct snd_ctl_elem_value *ucontrol)
2423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2424 struct via_spec *spec = codec->spec;
2427 if (spec->codec_type != VT1708)
2429 spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
2430 change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
2431 == !spec->vt1708_jack_detectect;
2432 if (spec->vt1708_jack_detectect) {
2433 mute_aa_path(codec, 1);
2434 notify_aa_path_ctls(codec);
2439 static struct snd_kcontrol_new vt1708_jack_detectect[] = {
2441 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2442 .name = "Jack Detect",
2444 .info = snd_ctl_boolean_mono_info,
2445 .get = vt1708_jack_detectect_get,
2446 .put = vt1708_jack_detectect_put,
2451 static int vt1708_parse_auto_config(struct hda_codec *codec)
2453 struct via_spec *spec = codec->spec;
2456 /* Add HP and CD pin config connect bit re-config action */
2457 vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
2458 vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
2460 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2463 err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
2466 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
2467 return 0; /* can't find valid BIOS pin config */
2469 err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
2472 err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
2475 err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
2478 /* add jack detect on/off control */
2479 err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
2483 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2485 if (spec->autocfg.dig_outs)
2486 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
2487 spec->dig_in_pin = VT1708_DIGIN_PIN;
2488 if (spec->autocfg.dig_in_pin)
2489 spec->dig_in_nid = VT1708_DIGIN_NID;
2491 if (spec->kctls.list)
2492 spec->mixers[spec->num_mixers++] = spec->kctls.list;
2494 spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
2496 spec->input_mux = &spec->private_imux[0];
2499 spec->mixers[spec->num_mixers++] = via_hp_mixer;
2501 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
2505 /* init callback for auto-configuration model -- overriding the default init */
2506 static int via_auto_init(struct hda_codec *codec)
2508 struct via_spec *spec = codec->spec;
2511 via_auto_init_multi_out(codec);
2512 via_auto_init_hp_out(codec);
2513 via_auto_init_analog_input(codec);
2514 if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
2515 via_hp_bind_automute(codec);
2517 via_hp_automute(codec);
2518 via_speaker_automute(codec);
2524 static void vt1708_update_hp_jack_state(struct work_struct *work)
2526 struct via_spec *spec = container_of(work, struct via_spec,
2527 vt1708_hp_work.work);
2528 if (spec->codec_type != VT1708)
2530 /* if jack state toggled */
2531 if (spec->vt1708_hp_present
2532 != (snd_hda_codec_read(spec->codec, spec->autocfg.hp_pins[0], 0,
2533 AC_VERB_GET_PIN_SENSE, 0) >> 31)) {
2534 spec->vt1708_hp_present ^= 1;
2535 via_hp_automute(spec->codec);
2537 vt1708_start_hp_work(spec);
2540 static int get_mux_nids(struct hda_codec *codec)
2542 struct via_spec *spec = codec->spec;
2543 hda_nid_t nid, conn[8];
2547 for (i = 0; i < spec->num_adc_nids; i++) {
2548 nid = spec->adc_nids[i];
2550 type = get_wcaps_type(get_wcaps(codec, nid));
2551 if (type == AC_WID_PIN)
2553 n = snd_hda_get_connections(codec, nid, conn,
2558 spec->mux_nids[i] = nid;
2567 static int patch_vt1708(struct hda_codec *codec)
2569 struct via_spec *spec;
2572 /* create a codec specific record */
2573 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2579 /* automatic parse from the BIOS config */
2580 err = vt1708_parse_auto_config(codec);
2585 printk(KERN_INFO "hda_codec: Cannot set up configuration "
2586 "from BIOS. Using genenic mode...\n");
2590 spec->stream_name_analog = "VT1708 Analog";
2591 spec->stream_analog_playback = &vt1708_pcm_analog_playback;
2592 /* disable 32bit format on VT1708 */
2593 if (codec->vendor_id == 0x11061708)
2594 spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
2595 spec->stream_analog_capture = &vt1708_pcm_analog_capture;
2597 spec->stream_name_digital = "VT1708 Digital";
2598 spec->stream_digital_playback = &vt1708_pcm_digital_playback;
2599 spec->stream_digital_capture = &vt1708_pcm_digital_capture;
2602 if (!spec->adc_nids && spec->input_mux) {
2603 spec->adc_nids = vt1708_adc_nids;
2604 spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
2605 get_mux_nids(codec);
2606 spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
2610 codec->patch_ops = via_patch_ops;
2612 codec->patch_ops.init = via_auto_init;
2613 #ifdef CONFIG_SND_HDA_POWER_SAVE
2614 spec->loopback.amplist = vt1708_loopbacks;
2616 spec->codec = codec;
2617 INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
2621 /* capture mixer elements */
2622 static struct snd_kcontrol_new vt1709_capture_mixer[] = {
2623 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
2624 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
2625 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
2626 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
2627 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
2628 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
2630 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2631 /* The multiple "Capture Source" controls confuse alsamixer
2632 * So call somewhat different..
2634 /* .name = "Capture Source", */
2635 .name = "Input Source",
2637 .info = via_mux_enum_info,
2638 .get = via_mux_enum_get,
2639 .put = via_mux_enum_put,
2644 static struct hda_verb vt1709_uniwill_init_verbs[] = {
2645 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
2646 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
2651 * generic initialization of ADC, input mixers and output mixers
2653 static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
2655 * Unmute ADC0-2 and set the default input to mic-in
2657 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2658 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2659 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2662 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2665 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
2666 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2667 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2668 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
2669 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
2670 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
2673 * Set up output selector (0x1a, 0x1b, 0x29)
2675 /* set vol=0 to output mixers */
2676 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2677 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2678 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2681 * Unmute PW3 and PW4
2683 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2684 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2686 /* Set input of PW4 as MW0 */
2687 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
2688 /* PW9 Output enable */
2689 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
2693 static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
2697 .nid = 0x10, /* NID to query formats and rates */
2699 .open = via_playback_pcm_open,
2700 .prepare = via_playback_multi_pcm_prepare,
2701 .cleanup = via_playback_multi_pcm_cleanup,
2705 static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
2709 .nid = 0x10, /* NID to query formats and rates */
2711 .open = via_playback_pcm_open,
2712 .prepare = via_playback_multi_pcm_prepare,
2713 .cleanup = via_playback_multi_pcm_cleanup,
2717 static struct hda_pcm_stream vt1709_pcm_analog_capture = {
2721 .nid = 0x14, /* NID to query formats and rates */
2723 .prepare = via_capture_pcm_prepare,
2724 .cleanup = via_capture_pcm_cleanup
2728 static struct hda_pcm_stream vt1709_pcm_digital_playback = {
2732 /* NID is set in via_build_pcms */
2734 .open = via_dig_playback_pcm_open,
2735 .close = via_dig_playback_pcm_close
2739 static struct hda_pcm_stream vt1709_pcm_digital_capture = {
2745 static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
2746 const struct auto_pin_cfg *cfg)
2751 if (cfg->line_outs == 4) /* 10 channels */
2752 spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
2753 else if (cfg->line_outs == 3) /* 6 channels */
2754 spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
2756 spec->multiout.dac_nids = spec->private_dac_nids;
2758 if (cfg->line_outs == 4) { /* 10 channels */
2759 for (i = 0; i < cfg->line_outs; i++) {
2760 nid = cfg->line_out_pins[i];
2762 /* config dac list */
2764 case AUTO_SEQ_FRONT:
2766 spec->multiout.dac_nids[i] = 0x10;
2768 case AUTO_SEQ_CENLFE:
2770 spec->multiout.dac_nids[i] = 0x12;
2772 case AUTO_SEQ_SURROUND:
2774 spec->multiout.dac_nids[i] = 0x11;
2778 spec->multiout.dac_nids[i] = 0x27;
2785 spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
2787 } else if (cfg->line_outs == 3) { /* 6 channels */
2788 for (i = 0; i < cfg->line_outs; i++) {
2789 nid = cfg->line_out_pins[i];
2791 /* config dac list */
2793 case AUTO_SEQ_FRONT:
2795 spec->multiout.dac_nids[i] = 0x10;
2797 case AUTO_SEQ_CENLFE:
2799 spec->multiout.dac_nids[i] = 0x12;
2801 case AUTO_SEQ_SURROUND:
2803 spec->multiout.dac_nids[i] = 0x11;
2815 /* add playback controls from the parsed DAC table */
2816 static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
2817 const struct auto_pin_cfg *cfg)
2820 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
2821 hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29};
2824 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
2825 nid = cfg->line_out_pins[i];
2830 nid_vol = nid_vols[i];
2832 if (i == AUTO_SEQ_CENLFE) {
2834 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2835 "Center Playback Volume",
2836 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2840 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2841 "LFE Playback Volume",
2842 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2846 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2847 "Center Playback Switch",
2848 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
2852 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2853 "LFE Playback Switch",
2854 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
2858 } else if (i == AUTO_SEQ_FRONT) {
2859 /* ADD control to mixer index 0 */
2860 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2861 "Master Front Playback Volume",
2862 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2866 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2867 "Master Front Playback Switch",
2868 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2873 /* add control to PW3 */
2874 sprintf(name, "%s Playback Volume", chname[i]);
2875 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2876 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2880 sprintf(name, "%s Playback Switch", chname[i]);
2881 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2882 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
2886 } else if (i == AUTO_SEQ_SURROUND) {
2887 sprintf(name, "%s Playback Volume", chname[i]);
2888 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2889 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2893 sprintf(name, "%s Playback Switch", chname[i]);
2894 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2895 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2899 } else if (i == AUTO_SEQ_SIDE) {
2900 sprintf(name, "%s Playback Volume", chname[i]);
2901 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
2902 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2906 sprintf(name, "%s Playback Switch", chname[i]);
2907 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
2908 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
2918 static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
2925 if (spec->multiout.num_dacs == 5) /* 10 channels */
2926 spec->multiout.hp_nid = VT1709_HP_DAC_NID;
2927 else if (spec->multiout.num_dacs == 3) /* 6 channels */
2928 spec->multiout.hp_nid = 0;
2929 spec->hp_independent_mode_index = 1;
2931 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
2932 "Headphone Playback Volume",
2933 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2936 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
2937 "Headphone Playback Switch",
2938 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
2945 /* create playback/capture controls for input pins */
2946 static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
2947 const struct auto_pin_cfg *cfg)
2949 static char *labels[] = {
2950 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
2952 struct hda_input_mux *imux = &spec->private_imux[0];
2953 int i, err, idx = 0;
2955 /* for internal loopback recording select */
2956 imux->items[imux->num_items].label = "Stereo Mixer";
2957 imux->items[imux->num_items].index = idx;
2960 for (i = 0; i < AUTO_PIN_LAST; i++) {
2961 if (!cfg->input_pins[i])
2964 switch (cfg->input_pins[i]) {
2965 case 0x1d: /* Mic */
2969 case 0x1e: /* Line In */
2973 case 0x21: /* Front Mic */
2981 err = via_new_analog_input(spec, labels[i], idx, 0x18);
2984 imux->items[imux->num_items].label = labels[i];
2985 imux->items[imux->num_items].index = idx;
2991 static int vt1709_parse_auto_config(struct hda_codec *codec)
2993 struct via_spec *spec = codec->spec;
2996 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
2999 err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
3002 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3003 return 0; /* can't find valid BIOS pin config */
3005 err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
3008 err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3011 err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
3015 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3017 if (spec->autocfg.dig_outs)
3018 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
3019 spec->dig_in_pin = VT1709_DIGIN_PIN;
3020 if (spec->autocfg.dig_in_pin)
3021 spec->dig_in_nid = VT1709_DIGIN_NID;
3023 if (spec->kctls.list)
3024 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3026 spec->input_mux = &spec->private_imux[0];
3029 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3031 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3035 #ifdef CONFIG_SND_HDA_POWER_SAVE
3036 static struct hda_amp_list vt1709_loopbacks[] = {
3037 { 0x18, HDA_INPUT, 1 },
3038 { 0x18, HDA_INPUT, 2 },
3039 { 0x18, HDA_INPUT, 3 },
3040 { 0x18, HDA_INPUT, 4 },
3045 static int patch_vt1709_10ch(struct hda_codec *codec)
3047 struct via_spec *spec;
3050 /* create a codec specific record */
3051 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3057 err = vt1709_parse_auto_config(codec);
3062 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3063 "Using genenic mode...\n");
3066 spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
3067 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3069 spec->stream_name_analog = "VT1709 Analog";
3070 spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
3071 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3073 spec->stream_name_digital = "VT1709 Digital";
3074 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3075 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3078 if (!spec->adc_nids && spec->input_mux) {
3079 spec->adc_nids = vt1709_adc_nids;
3080 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3081 get_mux_nids(codec);
3082 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3086 codec->patch_ops = via_patch_ops;
3088 codec->patch_ops.init = via_auto_init;
3089 codec->patch_ops.unsol_event = via_unsol_event;
3090 #ifdef CONFIG_SND_HDA_POWER_SAVE
3091 spec->loopback.amplist = vt1709_loopbacks;
3097 * generic initialization of ADC, input mixers and output mixers
3099 static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
3101 * Unmute ADC0-2 and set the default input to mic-in
3103 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3104 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3105 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3108 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3111 /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3112 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3113 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3114 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3115 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3116 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3119 * Set up output selector (0x1a, 0x1b, 0x29)
3121 /* set vol=0 to output mixers */
3122 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3123 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3124 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3127 * Unmute PW3 and PW4
3129 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3130 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3132 /* Set input of PW4 as MW0 */
3133 {0x20, AC_VERB_SET_CONNECT_SEL, 0},
3134 /* PW9 Output enable */
3135 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3139 static int patch_vt1709_6ch(struct hda_codec *codec)
3141 struct via_spec *spec;
3144 /* create a codec specific record */
3145 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3151 err = vt1709_parse_auto_config(codec);
3156 printk(KERN_INFO "hda_codec: Cannot set up configuration. "
3157 "Using genenic mode...\n");
3160 spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
3161 spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
3163 spec->stream_name_analog = "VT1709 Analog";
3164 spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
3165 spec->stream_analog_capture = &vt1709_pcm_analog_capture;
3167 spec->stream_name_digital = "VT1709 Digital";
3168 spec->stream_digital_playback = &vt1709_pcm_digital_playback;
3169 spec->stream_digital_capture = &vt1709_pcm_digital_capture;
3172 if (!spec->adc_nids && spec->input_mux) {
3173 spec->adc_nids = vt1709_adc_nids;
3174 spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
3175 get_mux_nids(codec);
3176 spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
3180 codec->patch_ops = via_patch_ops;
3182 codec->patch_ops.init = via_auto_init;
3183 codec->patch_ops.unsol_event = via_unsol_event;
3184 #ifdef CONFIG_SND_HDA_POWER_SAVE
3185 spec->loopback.amplist = vt1709_loopbacks;
3190 /* capture mixer elements */
3191 static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
3192 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3193 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3194 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3195 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3197 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3198 /* The multiple "Capture Source" controls confuse alsamixer
3199 * So call somewhat different..
3201 /* .name = "Capture Source", */
3202 .name = "Input Source",
3204 .info = via_mux_enum_info,
3205 .get = via_mux_enum_get,
3206 .put = via_mux_enum_put,
3211 * generic initialization of ADC, input mixers and output mixers
3213 static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
3215 * Unmute ADC0-1 and set the default input to mic-in
3217 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3218 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3221 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3224 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3225 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3226 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3227 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3228 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3229 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3232 * Set up output mixers
3234 /* set vol=0 to output mixers */
3235 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3236 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3237 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3239 /* Setup default input to PW4 */
3240 {0x1d, AC_VERB_SET_CONNECT_SEL, 0},
3241 /* PW9 Output enable */
3242 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3243 /* PW10 Input enable */
3244 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3248 static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
3250 * Unmute ADC0-1 and set the default input to mic-in
3252 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3253 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3256 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3259 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3260 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3261 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3262 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3263 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3264 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3267 * Set up output mixers
3269 /* set vol=0 to output mixers */
3270 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3271 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3272 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3274 /* Setup default input of PW4 to MW0 */
3275 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3276 /* PW9 Output enable */
3277 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3278 /* PW10 Input enable */
3279 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3283 static struct hda_verb vt1708B_uniwill_init_verbs[] = {
3284 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3285 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3286 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3287 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3288 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3289 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3290 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3291 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3292 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3296 static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
3297 struct hda_codec *codec,
3298 struct snd_pcm_substream *substream)
3300 int idle = substream->pstr->substream_opened == 1
3301 && substream->ref_count == 0;
3303 analog_low_current_mode(codec, idle);
3307 static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
3311 .nid = 0x10, /* NID to query formats and rates */
3313 .open = via_playback_pcm_open,
3314 .prepare = via_playback_multi_pcm_prepare,
3315 .cleanup = via_playback_multi_pcm_cleanup,
3316 .close = via_pcm_open_close
3320 static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
3324 .nid = 0x10, /* NID to query formats and rates */
3326 .open = via_playback_pcm_open,
3327 .prepare = via_playback_multi_pcm_prepare,
3328 .cleanup = via_playback_multi_pcm_cleanup
3332 static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
3336 .nid = 0x13, /* NID to query formats and rates */
3338 .open = via_pcm_open_close,
3339 .prepare = via_capture_pcm_prepare,
3340 .cleanup = via_capture_pcm_cleanup,
3341 .close = via_pcm_open_close
3345 static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
3349 /* NID is set in via_build_pcms */
3351 .open = via_dig_playback_pcm_open,
3352 .close = via_dig_playback_pcm_close,
3353 .prepare = via_dig_playback_pcm_prepare,
3354 .cleanup = via_dig_playback_pcm_cleanup
3358 static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
3364 /* fill in the dac_nids table from the parsed pin configuration */
3365 static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
3366 const struct auto_pin_cfg *cfg)
3371 spec->multiout.num_dacs = cfg->line_outs;
3373 spec->multiout.dac_nids = spec->private_dac_nids;
3375 for (i = 0; i < 4; i++) {
3376 nid = cfg->line_out_pins[i];
3378 /* config dac list */
3380 case AUTO_SEQ_FRONT:
3381 spec->multiout.dac_nids[i] = 0x10;
3383 case AUTO_SEQ_CENLFE:
3384 spec->multiout.dac_nids[i] = 0x24;
3386 case AUTO_SEQ_SURROUND:
3387 spec->multiout.dac_nids[i] = 0x11;
3390 spec->multiout.dac_nids[i] = 0x25;
3399 /* add playback controls from the parsed DAC table */
3400 static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
3401 const struct auto_pin_cfg *cfg)
3404 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3405 hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
3406 hda_nid_t nid, nid_vol = 0;
3409 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3410 nid = cfg->line_out_pins[i];
3415 nid_vol = nid_vols[i];
3417 if (i == AUTO_SEQ_CENLFE) {
3419 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3420 "Center Playback Volume",
3421 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3425 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3426 "LFE Playback Volume",
3427 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3431 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3432 "Center Playback Switch",
3433 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3437 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3438 "LFE Playback Switch",
3439 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3443 } else if (i == AUTO_SEQ_FRONT) {
3444 /* add control to mixer index 0 */
3445 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3446 "Master Front Playback Volume",
3447 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3451 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3452 "Master Front Playback Switch",
3453 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3458 /* add control to PW3 */
3459 sprintf(name, "%s Playback Volume", chname[i]);
3460 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3461 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3465 sprintf(name, "%s Playback Switch", chname[i]);
3466 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3467 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3472 sprintf(name, "%s Playback Volume", chname[i]);
3473 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3474 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3478 sprintf(name, "%s Playback Switch", chname[i]);
3479 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3480 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3490 static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3497 spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
3498 spec->hp_independent_mode_index = 1;
3500 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3501 "Headphone Playback Volume",
3502 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3505 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3506 "Headphone Playback Switch",
3507 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3511 create_hp_imux(spec);
3516 /* create playback/capture controls for input pins */
3517 static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
3518 const struct auto_pin_cfg *cfg)
3520 static char *labels[] = {
3521 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3523 struct hda_input_mux *imux = &spec->private_imux[0];
3524 int i, err, idx = 0;
3526 /* for internal loopback recording select */
3527 imux->items[imux->num_items].label = "Stereo Mixer";
3528 imux->items[imux->num_items].index = idx;
3531 for (i = 0; i < AUTO_PIN_LAST; i++) {
3532 if (!cfg->input_pins[i])
3535 switch (cfg->input_pins[i]) {
3536 case 0x1a: /* Mic */
3540 case 0x1b: /* Line In */
3544 case 0x1e: /* Front Mic */
3552 err = via_new_analog_input(spec, labels[i], idx, 0x16);
3555 imux->items[imux->num_items].label = labels[i];
3556 imux->items[imux->num_items].index = idx;
3562 static int vt1708B_parse_auto_config(struct hda_codec *codec)
3564 struct via_spec *spec = codec->spec;
3567 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3570 err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
3573 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
3574 return 0; /* can't find valid BIOS pin config */
3576 err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
3579 err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
3582 err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
3586 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3588 if (spec->autocfg.dig_outs)
3589 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
3590 spec->dig_in_pin = VT1708B_DIGIN_PIN;
3591 if (spec->autocfg.dig_in_pin)
3592 spec->dig_in_nid = VT1708B_DIGIN_NID;
3594 if (spec->kctls.list)
3595 spec->mixers[spec->num_mixers++] = spec->kctls.list;
3597 spec->input_mux = &spec->private_imux[0];
3600 spec->mixers[spec->num_mixers++] = via_hp_mixer;
3602 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
3606 #ifdef CONFIG_SND_HDA_POWER_SAVE
3607 static struct hda_amp_list vt1708B_loopbacks[] = {
3608 { 0x16, HDA_INPUT, 1 },
3609 { 0x16, HDA_INPUT, 2 },
3610 { 0x16, HDA_INPUT, 3 },
3611 { 0x16, HDA_INPUT, 4 },
3615 static int patch_vt1708S(struct hda_codec *codec);
3616 static int patch_vt1708B_8ch(struct hda_codec *codec)
3618 struct via_spec *spec;
3621 if (get_codec_type(codec) == VT1708BCE)
3622 return patch_vt1708S(codec);
3623 /* create a codec specific record */
3624 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3630 /* automatic parse from the BIOS config */
3631 err = vt1708B_parse_auto_config(codec);
3636 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3637 "from BIOS. Using genenic mode...\n");
3640 spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
3641 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3643 spec->stream_name_analog = "VT1708B Analog";
3644 spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
3645 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3647 spec->stream_name_digital = "VT1708B Digital";
3648 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3649 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3651 if (!spec->adc_nids && spec->input_mux) {
3652 spec->adc_nids = vt1708B_adc_nids;
3653 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3654 get_mux_nids(codec);
3655 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3659 codec->patch_ops = via_patch_ops;
3661 codec->patch_ops.init = via_auto_init;
3662 codec->patch_ops.unsol_event = via_unsol_event;
3663 #ifdef CONFIG_SND_HDA_POWER_SAVE
3664 spec->loopback.amplist = vt1708B_loopbacks;
3670 static int patch_vt1708B_4ch(struct hda_codec *codec)
3672 struct via_spec *spec;
3675 /* create a codec specific record */
3676 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3682 /* automatic parse from the BIOS config */
3683 err = vt1708B_parse_auto_config(codec);
3688 printk(KERN_INFO "hda_codec: Cannot set up configuration "
3689 "from BIOS. Using genenic mode...\n");
3692 spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
3693 spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
3695 spec->stream_name_analog = "VT1708B Analog";
3696 spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
3697 spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
3699 spec->stream_name_digital = "VT1708B Digital";
3700 spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
3701 spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
3703 if (!spec->adc_nids && spec->input_mux) {
3704 spec->adc_nids = vt1708B_adc_nids;
3705 spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
3706 get_mux_nids(codec);
3707 spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
3711 codec->patch_ops = via_patch_ops;
3713 codec->patch_ops.init = via_auto_init;
3714 codec->patch_ops.unsol_event = via_unsol_event;
3715 #ifdef CONFIG_SND_HDA_POWER_SAVE
3716 spec->loopback.amplist = vt1708B_loopbacks;
3722 /* Patch for VT1708S */
3724 /* capture mixer elements */
3725 static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
3726 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
3727 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
3728 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
3729 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
3730 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
3731 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
3734 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3735 /* The multiple "Capture Source" controls confuse alsamixer
3736 * So call somewhat different..
3738 /* .name = "Capture Source", */
3739 .name = "Input Source",
3741 .info = via_mux_enum_info,
3742 .get = via_mux_enum_get,
3743 .put = via_mux_enum_put,
3748 static struct hda_verb vt1708S_volume_init_verbs[] = {
3749 /* Unmute ADC0-1 and set the default input to mic-in */
3750 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3751 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3753 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
3754 * analog-loopback mixer widget */
3755 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
3756 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3757 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3758 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3759 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
3760 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3762 /* Setup default input of PW4 to MW0 */
3763 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
3764 /* PW9, PW10 Output enable */
3765 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3766 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3767 /* Enable Mic Boost Volume backdoor */
3769 /* don't bybass mixer */
3774 static struct hda_verb vt1708S_uniwill_init_verbs[] = {
3775 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
3776 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
3777 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3778 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3779 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3780 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3781 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3782 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3783 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
3787 static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
3791 .nid = 0x10, /* NID to query formats and rates */
3793 .open = via_playback_pcm_open,
3794 .prepare = via_playback_multi_pcm_prepare,
3795 .cleanup = via_playback_multi_pcm_cleanup,
3796 .close = via_pcm_open_close
3800 static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
3804 .nid = 0x13, /* NID to query formats and rates */
3806 .open = via_pcm_open_close,
3807 .prepare = via_capture_pcm_prepare,
3808 .cleanup = via_capture_pcm_cleanup,
3809 .close = via_pcm_open_close
3813 static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
3817 /* NID is set in via_build_pcms */
3819 .open = via_dig_playback_pcm_open,
3820 .close = via_dig_playback_pcm_close,
3821 .prepare = via_dig_playback_pcm_prepare,
3822 .cleanup = via_dig_playback_pcm_cleanup
3826 /* fill in the dac_nids table from the parsed pin configuration */
3827 static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
3828 const struct auto_pin_cfg *cfg)
3833 spec->multiout.num_dacs = cfg->line_outs;
3835 spec->multiout.dac_nids = spec->private_dac_nids;
3837 for (i = 0; i < 4; i++) {
3838 nid = cfg->line_out_pins[i];
3840 /* config dac list */
3842 case AUTO_SEQ_FRONT:
3843 spec->multiout.dac_nids[i] = 0x10;
3845 case AUTO_SEQ_CENLFE:
3846 spec->multiout.dac_nids[i] = 0x24;
3848 case AUTO_SEQ_SURROUND:
3849 spec->multiout.dac_nids[i] = 0x11;
3852 spec->multiout.dac_nids[i] = 0x25;
3861 /* add playback controls from the parsed DAC table */
3862 static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
3863 const struct auto_pin_cfg *cfg)
3866 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
3867 hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
3868 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
3869 hda_nid_t nid, nid_vol, nid_mute;
3872 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
3873 nid = cfg->line_out_pins[i];
3878 nid_vol = nid_vols[i];
3879 nid_mute = nid_mutes[i];
3881 if (i == AUTO_SEQ_CENLFE) {
3883 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3884 "Center Playback Volume",
3885 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
3889 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3890 "LFE Playback Volume",
3891 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
3895 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3896 "Center Playback Switch",
3897 HDA_COMPOSE_AMP_VAL(nid_mute,
3902 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3903 "LFE Playback Switch",
3904 HDA_COMPOSE_AMP_VAL(nid_mute,
3909 } else if (i == AUTO_SEQ_FRONT) {
3910 /* add control to mixer index 0 */
3911 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3912 "Master Front Playback Volume",
3913 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3917 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3918 "Master Front Playback Switch",
3919 HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
3925 sprintf(name, "%s Playback Volume", chname[i]);
3926 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3927 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3931 sprintf(name, "%s Playback Switch", chname[i]);
3932 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3933 HDA_COMPOSE_AMP_VAL(nid_mute,
3939 sprintf(name, "%s Playback Volume", chname[i]);
3940 err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
3941 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
3945 sprintf(name, "%s Playback Switch", chname[i]);
3946 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
3947 HDA_COMPOSE_AMP_VAL(nid_mute,
3958 static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
3965 spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
3966 spec->hp_independent_mode_index = 1;
3968 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
3969 "Headphone Playback Volume",
3970 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
3974 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
3975 "Headphone Playback Switch",
3976 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3980 create_hp_imux(spec);
3985 /* create playback/capture controls for input pins */
3986 static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
3987 const struct auto_pin_cfg *cfg)
3989 static char *labels[] = {
3990 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
3992 struct hda_input_mux *imux = &spec->private_imux[0];
3993 int i, err, idx = 0;
3995 /* for internal loopback recording select */
3996 imux->items[imux->num_items].label = "Stereo Mixer";
3997 imux->items[imux->num_items].index = 5;
4000 for (i = 0; i < AUTO_PIN_LAST; i++) {
4001 if (!cfg->input_pins[i])
4004 switch (cfg->input_pins[i]) {
4005 case 0x1a: /* Mic */
4009 case 0x1b: /* Line In */
4013 case 0x1e: /* Front Mic */
4021 err = via_new_analog_input(spec, labels[i], idx, 0x16);
4024 imux->items[imux->num_items].label = labels[i];
4025 imux->items[imux->num_items].index = idx-1;
4031 /* fill out digital output widgets; one for master and one for slave outputs */
4032 static void fill_dig_outs(struct hda_codec *codec)
4034 struct via_spec *spec = codec->spec;
4037 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4041 nid = spec->autocfg.dig_out_pins[i];
4044 conn = snd_hda_get_connections(codec, nid, &nid, 1);
4047 if (!spec->multiout.dig_out_nid)
4048 spec->multiout.dig_out_nid = nid;
4050 spec->slave_dig_outs[0] = nid;
4051 break; /* at most two dig outs */
4056 static int vt1708S_parse_auto_config(struct hda_codec *codec)
4058 struct via_spec *spec = codec->spec;
4061 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4064 err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
4067 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4068 return 0; /* can't find valid BIOS pin config */
4070 err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4073 err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4076 err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4080 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4082 fill_dig_outs(codec);
4084 if (spec->kctls.list)
4085 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4087 spec->input_mux = &spec->private_imux[0];
4090 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4092 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4096 #ifdef CONFIG_SND_HDA_POWER_SAVE
4097 static struct hda_amp_list vt1708S_loopbacks[] = {
4098 { 0x16, HDA_INPUT, 1 },
4099 { 0x16, HDA_INPUT, 2 },
4100 { 0x16, HDA_INPUT, 3 },
4101 { 0x16, HDA_INPUT, 4 },
4106 static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
4107 int offset, int num_steps, int step_size)
4109 snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
4110 (offset << AC_AMPCAP_OFFSET_SHIFT) |
4111 (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
4112 (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
4113 (0 << AC_AMPCAP_MUTE_SHIFT));
4116 static int patch_vt1708S(struct hda_codec *codec)
4118 struct via_spec *spec;
4121 /* create a codec specific record */
4122 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4128 /* automatic parse from the BIOS config */
4129 err = vt1708S_parse_auto_config(codec);
4134 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4135 "from BIOS. Using genenic mode...\n");
4138 spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
4139 spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
4141 if (codec->vendor_id == 0x11060440)
4142 spec->stream_name_analog = "VT1818S Analog";
4144 spec->stream_name_analog = "VT1708S Analog";
4145 spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
4146 spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
4148 if (codec->vendor_id == 0x11060440)
4149 spec->stream_name_digital = "VT1818S Digital";
4151 spec->stream_name_digital = "VT1708S Digital";
4152 spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
4154 if (!spec->adc_nids && spec->input_mux) {
4155 spec->adc_nids = vt1708S_adc_nids;
4156 spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
4157 get_mux_nids(codec);
4158 override_mic_boost(codec, 0x1a, 0, 3, 40);
4159 override_mic_boost(codec, 0x1e, 0, 3, 40);
4160 spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
4164 codec->patch_ops = via_patch_ops;
4166 codec->patch_ops.init = via_auto_init;
4167 codec->patch_ops.unsol_event = via_unsol_event;
4168 #ifdef CONFIG_SND_HDA_POWER_SAVE
4169 spec->loopback.amplist = vt1708S_loopbacks;
4172 /* correct names for VT1708BCE */
4173 if (get_codec_type(codec) == VT1708BCE) {
4174 kfree(codec->chip_name);
4175 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
4176 snprintf(codec->bus->card->mixername,
4177 sizeof(codec->bus->card->mixername),
4178 "%s %s", codec->vendor_name, codec->chip_name);
4179 spec->stream_name_analog = "VT1708BCE Analog";
4180 spec->stream_name_digital = "VT1708BCE Digital";
4185 /* Patch for VT1702 */
4187 /* capture mixer elements */
4188 static struct snd_kcontrol_new vt1702_capture_mixer[] = {
4189 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
4190 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
4191 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
4192 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
4193 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
4194 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
4195 HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
4198 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4199 /* The multiple "Capture Source" controls confuse alsamixer
4200 * So call somewhat different..
4202 /* .name = "Capture Source", */
4203 .name = "Input Source",
4205 .info = via_mux_enum_info,
4206 .get = via_mux_enum_get,
4207 .put = via_mux_enum_put,
4212 static struct hda_verb vt1702_volume_init_verbs[] = {
4214 * Unmute ADC0-1 and set the default input to mic-in
4216 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4217 {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4218 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4221 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4224 /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
4225 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4226 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4227 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4228 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4229 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4231 /* Setup default input of PW4 to MW0 */
4232 {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
4233 /* PW6 PW7 Output enable */
4234 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4235 {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4243 static struct hda_verb vt1702_uniwill_init_verbs[] = {
4244 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
4245 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4246 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4247 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4248 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4249 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4253 static struct hda_pcm_stream vt1702_pcm_analog_playback = {
4257 .nid = 0x10, /* NID to query formats and rates */
4259 .open = via_playback_pcm_open,
4260 .prepare = via_playback_multi_pcm_prepare,
4261 .cleanup = via_playback_multi_pcm_cleanup,
4262 .close = via_pcm_open_close
4266 static struct hda_pcm_stream vt1702_pcm_analog_capture = {
4270 .nid = 0x12, /* NID to query formats and rates */
4272 .open = via_pcm_open_close,
4273 .prepare = via_capture_pcm_prepare,
4274 .cleanup = via_capture_pcm_cleanup,
4275 .close = via_pcm_open_close
4279 static struct hda_pcm_stream vt1702_pcm_digital_playback = {
4283 /* NID is set in via_build_pcms */
4285 .open = via_dig_playback_pcm_open,
4286 .close = via_dig_playback_pcm_close,
4287 .prepare = via_dig_playback_pcm_prepare,
4288 .cleanup = via_dig_playback_pcm_cleanup
4292 /* fill in the dac_nids table from the parsed pin configuration */
4293 static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
4294 const struct auto_pin_cfg *cfg)
4296 spec->multiout.num_dacs = 1;
4297 spec->multiout.dac_nids = spec->private_dac_nids;
4299 if (cfg->line_out_pins[0]) {
4300 /* config dac list */
4301 spec->multiout.dac_nids[0] = 0x10;
4307 /* add playback controls from the parsed DAC table */
4308 static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
4309 const struct auto_pin_cfg *cfg)
4313 if (!cfg->line_out_pins[0])
4316 /* add control to mixer index 0 */
4317 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4318 "Master Front Playback Volume",
4319 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4322 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4323 "Master Front Playback Switch",
4324 HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
4329 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4330 "Front Playback Volume",
4331 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
4334 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4335 "Front Playback Switch",
4336 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
4343 static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4346 struct hda_input_mux *imux;
4347 static const char *texts[] = { "ON", "OFF", NULL};
4350 spec->multiout.hp_nid = 0x1D;
4351 spec->hp_independent_mode_index = 0;
4353 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4354 "Headphone Playback Volume",
4355 HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
4359 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4360 "Headphone Playback Switch",
4361 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4365 imux = &spec->private_imux[1];
4367 /* for hp mode select */
4369 while (texts[i] != NULL) {
4370 imux->items[imux->num_items].label = texts[i];
4371 imux->items[imux->num_items].index = i;
4376 spec->hp_mux = &spec->private_imux[1];
4380 /* create playback/capture controls for input pins */
4381 static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
4382 const struct auto_pin_cfg *cfg)
4384 static char *labels[] = {
4385 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4387 struct hda_input_mux *imux = &spec->private_imux[0];
4388 int i, err, idx = 0;
4390 /* for internal loopback recording select */
4391 imux->items[imux->num_items].label = "Stereo Mixer";
4392 imux->items[imux->num_items].index = 3;
4395 for (i = 0; i < AUTO_PIN_LAST; i++) {
4396 if (!cfg->input_pins[i])
4399 switch (cfg->input_pins[i]) {
4400 case 0x14: /* Mic */
4404 case 0x15: /* Line In */
4408 case 0x18: /* Front Mic */
4412 err = via_new_analog_input(spec, labels[i], idx, 0x1A);
4415 imux->items[imux->num_items].label = labels[i];
4416 imux->items[imux->num_items].index = idx-1;
4422 static int vt1702_parse_auto_config(struct hda_codec *codec)
4424 struct via_spec *spec = codec->spec;
4427 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4430 err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
4433 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4434 return 0; /* can't find valid BIOS pin config */
4436 err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
4439 err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4442 /* limit AA path volume to 0 dB */
4443 snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
4444 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4445 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4446 (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4447 (1 << AC_AMPCAP_MUTE_SHIFT));
4448 err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
4452 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4454 fill_dig_outs(codec);
4456 if (spec->kctls.list)
4457 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4459 spec->input_mux = &spec->private_imux[0];
4462 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4467 #ifdef CONFIG_SND_HDA_POWER_SAVE
4468 static struct hda_amp_list vt1702_loopbacks[] = {
4469 { 0x1A, HDA_INPUT, 1 },
4470 { 0x1A, HDA_INPUT, 2 },
4471 { 0x1A, HDA_INPUT, 3 },
4472 { 0x1A, HDA_INPUT, 4 },
4477 static int patch_vt1702(struct hda_codec *codec)
4479 struct via_spec *spec;
4482 /* create a codec specific record */
4483 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4489 /* automatic parse from the BIOS config */
4490 err = vt1702_parse_auto_config(codec);
4495 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4496 "from BIOS. Using genenic mode...\n");
4499 spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
4500 spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
4502 spec->stream_name_analog = "VT1702 Analog";
4503 spec->stream_analog_playback = &vt1702_pcm_analog_playback;
4504 spec->stream_analog_capture = &vt1702_pcm_analog_capture;
4506 spec->stream_name_digital = "VT1702 Digital";
4507 spec->stream_digital_playback = &vt1702_pcm_digital_playback;
4509 if (!spec->adc_nids && spec->input_mux) {
4510 spec->adc_nids = vt1702_adc_nids;
4511 spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
4512 get_mux_nids(codec);
4513 spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
4517 codec->patch_ops = via_patch_ops;
4519 codec->patch_ops.init = via_auto_init;
4520 codec->patch_ops.unsol_event = via_unsol_event;
4521 #ifdef CONFIG_SND_HDA_POWER_SAVE
4522 spec->loopback.amplist = vt1702_loopbacks;
4528 /* Patch for VT1718S */
4530 /* capture mixer elements */
4531 static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
4532 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
4533 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
4534 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
4535 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
4536 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
4537 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
4540 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4541 /* The multiple "Capture Source" controls confuse alsamixer
4542 * So call somewhat different..
4544 .name = "Input Source",
4546 .info = via_mux_enum_info,
4547 .get = via_mux_enum_get,
4548 .put = via_mux_enum_put,
4553 static struct hda_verb vt1718S_volume_init_verbs[] = {
4555 * Unmute ADC0-1 and set the default input to mic-in
4557 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4558 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4561 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4564 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
4565 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4566 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4567 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4568 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4569 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4571 /* Setup default input of Front HP to MW9 */
4572 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
4573 /* PW9 PW10 Output enable */
4574 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4575 {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
4576 /* PW11 Input enable */
4577 {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
4578 /* Enable Boost Volume backdoor */
4580 /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
4581 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4582 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4583 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4584 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4585 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4586 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4587 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4588 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4589 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4590 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4591 /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
4592 {0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
4593 {0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
4594 /* Unmute MW4's index 0 */
4595 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4600 static struct hda_verb vt1718S_uniwill_init_verbs[] = {
4601 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
4602 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
4603 {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4604 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4605 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4606 {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4607 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4608 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4609 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
4613 static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
4617 .nid = 0x8, /* NID to query formats and rates */
4619 .open = via_playback_pcm_open,
4620 .prepare = via_playback_multi_pcm_prepare,
4621 .cleanup = via_playback_multi_pcm_cleanup,
4622 .close = via_pcm_open_close,
4626 static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
4630 .nid = 0x10, /* NID to query formats and rates */
4632 .open = via_pcm_open_close,
4633 .prepare = via_capture_pcm_prepare,
4634 .cleanup = via_capture_pcm_cleanup,
4635 .close = via_pcm_open_close,
4639 static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
4643 /* NID is set in via_build_pcms */
4645 .open = via_dig_playback_pcm_open,
4646 .close = via_dig_playback_pcm_close,
4647 .prepare = via_dig_playback_pcm_prepare,
4648 .cleanup = via_dig_playback_pcm_cleanup
4652 static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
4658 /* fill in the dac_nids table from the parsed pin configuration */
4659 static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
4660 const struct auto_pin_cfg *cfg)
4665 spec->multiout.num_dacs = cfg->line_outs;
4667 spec->multiout.dac_nids = spec->private_dac_nids;
4669 for (i = 0; i < 4; i++) {
4670 nid = cfg->line_out_pins[i];
4672 /* config dac list */
4674 case AUTO_SEQ_FRONT:
4675 spec->multiout.dac_nids[i] = 0x8;
4677 case AUTO_SEQ_CENLFE:
4678 spec->multiout.dac_nids[i] = 0xa;
4680 case AUTO_SEQ_SURROUND:
4681 spec->multiout.dac_nids[i] = 0x9;
4684 spec->multiout.dac_nids[i] = 0xb;
4693 /* add playback controls from the parsed DAC table */
4694 static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
4695 const struct auto_pin_cfg *cfg)
4698 static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
4699 hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
4700 hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
4701 hda_nid_t nid, nid_vol, nid_mute = 0;
4704 for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
4705 nid = cfg->line_out_pins[i];
4709 nid_vol = nid_vols[i];
4710 nid_mute = nid_mutes[i];
4712 if (i == AUTO_SEQ_CENLFE) {
4714 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4715 "Center Playback Volume",
4716 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
4720 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4721 "LFE Playback Volume",
4722 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
4726 err = via_add_control(
4727 spec, VIA_CTL_WIDGET_MUTE,
4728 "Center Playback Switch",
4729 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
4733 err = via_add_control(
4734 spec, VIA_CTL_WIDGET_MUTE,
4735 "LFE Playback Switch",
4736 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
4740 } else if (i == AUTO_SEQ_FRONT) {
4742 sprintf(name, "%s Playback Volume", chname[i]);
4743 err = via_add_control(
4744 spec, VIA_CTL_WIDGET_VOL, name,
4745 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4748 sprintf(name, "%s Playback Switch", chname[i]);
4749 err = via_add_control(
4750 spec, VIA_CTL_WIDGET_MUTE, name,
4751 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4756 sprintf(name, "%s Playback Volume", chname[i]);
4757 err = via_add_control(
4758 spec, VIA_CTL_WIDGET_VOL, name,
4759 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
4762 sprintf(name, "%s Playback Switch", chname[i]);
4763 err = via_add_control(
4764 spec, VIA_CTL_WIDGET_MUTE, name,
4765 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
4774 static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
4781 spec->multiout.hp_nid = 0xc; /* AOW4 */
4782 spec->hp_independent_mode_index = 1;
4784 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
4785 "Headphone Playback Volume",
4786 HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
4790 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
4791 "Headphone Playback Switch",
4792 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4796 create_hp_imux(spec);
4800 /* create playback/capture controls for input pins */
4801 static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
4802 const struct auto_pin_cfg *cfg)
4804 static char *labels[] = {
4805 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
4807 struct hda_input_mux *imux = &spec->private_imux[0];
4808 int i, err, idx = 0;
4810 /* for internal loopback recording select */
4811 imux->items[imux->num_items].label = "Stereo Mixer";
4812 imux->items[imux->num_items].index = 5;
4815 for (i = 0; i < AUTO_PIN_LAST; i++) {
4816 if (!cfg->input_pins[i])
4819 switch (cfg->input_pins[i]) {
4820 case 0x2b: /* Mic */
4824 case 0x2a: /* Line In */
4828 case 0x29: /* Front Mic */
4836 err = via_new_analog_input(spec, labels[i], idx, 0x21);
4839 imux->items[imux->num_items].label = labels[i];
4840 imux->items[imux->num_items].index = idx;
4846 static int vt1718S_parse_auto_config(struct hda_codec *codec)
4848 struct via_spec *spec = codec->spec;
4851 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
4855 err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
4858 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
4859 return 0; /* can't find valid BIOS pin config */
4861 err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
4864 err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
4867 err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
4871 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4873 fill_dig_outs(codec);
4875 if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
4876 spec->dig_in_nid = 0x13;
4878 if (spec->kctls.list)
4879 spec->mixers[spec->num_mixers++] = spec->kctls.list;
4881 spec->input_mux = &spec->private_imux[0];
4884 spec->mixers[spec->num_mixers++] = via_hp_mixer;
4886 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
4891 #ifdef CONFIG_SND_HDA_POWER_SAVE
4892 static struct hda_amp_list vt1718S_loopbacks[] = {
4893 { 0x21, HDA_INPUT, 1 },
4894 { 0x21, HDA_INPUT, 2 },
4895 { 0x21, HDA_INPUT, 3 },
4896 { 0x21, HDA_INPUT, 4 },
4901 static int patch_vt1718S(struct hda_codec *codec)
4903 struct via_spec *spec;
4906 /* create a codec specific record */
4907 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4913 /* automatic parse from the BIOS config */
4914 err = vt1718S_parse_auto_config(codec);
4919 printk(KERN_INFO "hda_codec: Cannot set up configuration "
4920 "from BIOS. Using genenic mode...\n");
4923 spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
4924 spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
4926 if (codec->vendor_id == 0x11060441)
4927 spec->stream_name_analog = "VT2020 Analog";
4928 else if (codec->vendor_id == 0x11064441)
4929 spec->stream_name_analog = "VT1828S Analog";
4931 spec->stream_name_analog = "VT1718S Analog";
4932 spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
4933 spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
4935 if (codec->vendor_id == 0x11060441)
4936 spec->stream_name_digital = "VT2020 Digital";
4937 else if (codec->vendor_id == 0x11064441)
4938 spec->stream_name_digital = "VT1828S Digital";
4940 spec->stream_name_digital = "VT1718S Digital";
4941 spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
4942 if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
4943 spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
4945 if (!spec->adc_nids && spec->input_mux) {
4946 spec->adc_nids = vt1718S_adc_nids;
4947 spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
4948 get_mux_nids(codec);
4949 override_mic_boost(codec, 0x2b, 0, 3, 40);
4950 override_mic_boost(codec, 0x29, 0, 3, 40);
4951 spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
4955 codec->patch_ops = via_patch_ops;
4957 codec->patch_ops.init = via_auto_init;
4958 codec->patch_ops.unsol_event = via_unsol_event;
4960 #ifdef CONFIG_SND_HDA_POWER_SAVE
4961 spec->loopback.amplist = vt1718S_loopbacks;
4967 /* Patch for VT1716S */
4969 static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
4970 struct snd_ctl_elem_info *uinfo)
4972 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4974 uinfo->value.integer.min = 0;
4975 uinfo->value.integer.max = 1;
4979 static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
4980 struct snd_ctl_elem_value *ucontrol)
4982 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4985 index = snd_hda_codec_read(codec, 0x26, 0,
4986 AC_VERB_GET_CONNECT_SEL, 0);
4988 *ucontrol->value.integer.value = index;
4993 static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
4994 struct snd_ctl_elem_value *ucontrol)
4996 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4997 struct via_spec *spec = codec->spec;
4998 int index = *ucontrol->value.integer.value;
5000 snd_hda_codec_write(codec, 0x26, 0,
5001 AC_VERB_SET_CONNECT_SEL, index);
5002 spec->dmic_enabled = index;
5003 set_jack_power_state(codec);
5008 /* capture mixer elements */
5009 static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
5010 HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
5011 HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
5012 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
5013 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
5014 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
5015 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
5018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5019 .name = "Input Source",
5021 .info = via_mux_enum_info,
5022 .get = via_mux_enum_get,
5023 .put = via_mux_enum_put,
5028 static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
5029 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
5031 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5032 .name = "Digital Mic Capture Switch",
5034 .info = vt1716s_dmic_info,
5035 .get = vt1716s_dmic_get,
5036 .put = vt1716s_dmic_put,
5042 /* mono-out mixer elements */
5043 static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
5044 HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
5048 static struct hda_verb vt1716S_volume_init_verbs[] = {
5050 * Unmute ADC0-1 and set the default input to mic-in
5052 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5053 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5056 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5059 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5060 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5061 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5062 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5063 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5064 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5066 /* MUX Indices: Stereo Mixer = 5 */
5067 {0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
5069 /* Setup default input of PW4 to MW0 */
5070 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
5072 /* Setup default input of SW1 as MW0 */
5073 {0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
5075 /* Setup default input of SW4 as AOW0 */
5076 {0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
5078 /* PW9 PW10 Output enable */
5079 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5080 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5082 /* Unmute SW1, PW12 */
5083 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5084 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5085 /* PW12 Output enable */
5086 {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5087 /* Enable Boost Volume backdoor */
5089 /* don't bybass mixer */
5091 /* Enable mono output */
5097 static struct hda_verb vt1716S_uniwill_init_verbs[] = {
5098 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
5099 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
5100 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5101 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5102 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5103 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
5104 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
5105 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5106 {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5110 static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
5114 .nid = 0x10, /* NID to query formats and rates */
5116 .open = via_playback_pcm_open,
5117 .prepare = via_playback_multi_pcm_prepare,
5118 .cleanup = via_playback_multi_pcm_cleanup,
5119 .close = via_pcm_open_close,
5123 static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
5127 .nid = 0x13, /* NID to query formats and rates */
5129 .open = via_pcm_open_close,
5130 .prepare = via_capture_pcm_prepare,
5131 .cleanup = via_capture_pcm_cleanup,
5132 .close = via_pcm_open_close,
5136 static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
5140 /* NID is set in via_build_pcms */
5142 .open = via_dig_playback_pcm_open,
5143 .close = via_dig_playback_pcm_close,
5144 .prepare = via_dig_playback_pcm_prepare,
5145 .cleanup = via_dig_playback_pcm_cleanup
5149 /* fill in the dac_nids table from the parsed pin configuration */
5150 static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
5151 const struct auto_pin_cfg *cfg)
5155 spec->multiout.num_dacs = cfg->line_outs;
5157 spec->multiout.dac_nids = spec->private_dac_nids;
5159 for (i = 0; i < 3; i++) {
5160 nid = cfg->line_out_pins[i];
5162 /* config dac list */
5164 case AUTO_SEQ_FRONT:
5165 spec->multiout.dac_nids[i] = 0x10;
5167 case AUTO_SEQ_CENLFE:
5168 spec->multiout.dac_nids[i] = 0x25;
5170 case AUTO_SEQ_SURROUND:
5171 spec->multiout.dac_nids[i] = 0x11;
5180 /* add playback controls from the parsed DAC table */
5181 static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
5182 const struct auto_pin_cfg *cfg)
5185 static const char *chname[3] = { "Front", "Surround", "C/LFE" };
5186 hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
5187 hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
5188 hda_nid_t nid, nid_vol, nid_mute;
5191 for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
5192 nid = cfg->line_out_pins[i];
5197 nid_vol = nid_vols[i];
5198 nid_mute = nid_mutes[i];
5200 if (i == AUTO_SEQ_CENLFE) {
5201 err = via_add_control(
5202 spec, VIA_CTL_WIDGET_VOL,
5203 "Center Playback Volume",
5204 HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
5207 err = via_add_control(
5208 spec, VIA_CTL_WIDGET_VOL,
5209 "LFE Playback Volume",
5210 HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
5213 err = via_add_control(
5214 spec, VIA_CTL_WIDGET_MUTE,
5215 "Center Playback Switch",
5216 HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
5220 err = via_add_control(
5221 spec, VIA_CTL_WIDGET_MUTE,
5222 "LFE Playback Switch",
5223 HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
5227 } else if (i == AUTO_SEQ_FRONT) {
5229 err = via_add_control(
5230 spec, VIA_CTL_WIDGET_VOL,
5231 "Master Front Playback Volume",
5232 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5235 err = via_add_control(
5236 spec, VIA_CTL_WIDGET_MUTE,
5237 "Master Front Playback Switch",
5238 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
5242 sprintf(name, "%s Playback Volume", chname[i]);
5243 err = via_add_control(
5244 spec, VIA_CTL_WIDGET_VOL, name,
5245 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5248 sprintf(name, "%s Playback Switch", chname[i]);
5249 err = via_add_control(
5250 spec, VIA_CTL_WIDGET_MUTE, name,
5251 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5256 sprintf(name, "%s Playback Volume", chname[i]);
5257 err = via_add_control(
5258 spec, VIA_CTL_WIDGET_VOL, name,
5259 HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
5262 sprintf(name, "%s Playback Switch", chname[i]);
5263 err = via_add_control(
5264 spec, VIA_CTL_WIDGET_MUTE, name,
5265 HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
5274 static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5281 spec->multiout.hp_nid = 0x25; /* AOW3 */
5282 spec->hp_independent_mode_index = 1;
5284 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5285 "Headphone Playback Volume",
5286 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5290 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5291 "Headphone Playback Switch",
5292 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5296 create_hp_imux(spec);
5300 /* create playback/capture controls for input pins */
5301 static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
5302 const struct auto_pin_cfg *cfg)
5304 static char *labels[] = {
5305 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5307 struct hda_input_mux *imux = &spec->private_imux[0];
5308 int i, err, idx = 0;
5310 /* for internal loopback recording select */
5311 imux->items[imux->num_items].label = "Stereo Mixer";
5312 imux->items[imux->num_items].index = 5;
5315 for (i = 0; i < AUTO_PIN_LAST; i++) {
5316 if (!cfg->input_pins[i])
5319 switch (cfg->input_pins[i]) {
5320 case 0x1a: /* Mic */
5324 case 0x1b: /* Line In */
5328 case 0x1e: /* Front Mic */
5336 err = via_new_analog_input(spec, labels[i], idx, 0x16);
5339 imux->items[imux->num_items].label = labels[i];
5340 imux->items[imux->num_items].index = idx-1;
5346 static int vt1716S_parse_auto_config(struct hda_codec *codec)
5348 struct via_spec *spec = codec->spec;
5351 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5354 err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
5357 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5358 return 0; /* can't find valid BIOS pin config */
5360 err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
5363 err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5366 err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
5370 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5372 fill_dig_outs(codec);
5374 if (spec->kctls.list)
5375 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5377 spec->input_mux = &spec->private_imux[0];
5380 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5382 spec->mixers[spec->num_mixers++] = via_smart51_mixer;
5387 #ifdef CONFIG_SND_HDA_POWER_SAVE
5388 static struct hda_amp_list vt1716S_loopbacks[] = {
5389 { 0x16, HDA_INPUT, 1 },
5390 { 0x16, HDA_INPUT, 2 },
5391 { 0x16, HDA_INPUT, 3 },
5392 { 0x16, HDA_INPUT, 4 },
5397 static int patch_vt1716S(struct hda_codec *codec)
5399 struct via_spec *spec;
5402 /* create a codec specific record */
5403 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5409 /* automatic parse from the BIOS config */
5410 err = vt1716S_parse_auto_config(codec);
5415 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5416 "from BIOS. Using genenic mode...\n");
5419 spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs;
5420 spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
5422 spec->stream_name_analog = "VT1716S Analog";
5423 spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
5424 spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
5426 spec->stream_name_digital = "VT1716S Digital";
5427 spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
5429 if (!spec->adc_nids && spec->input_mux) {
5430 spec->adc_nids = vt1716S_adc_nids;
5431 spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
5432 get_mux_nids(codec);
5433 override_mic_boost(codec, 0x1a, 0, 3, 40);
5434 override_mic_boost(codec, 0x1e, 0, 3, 40);
5435 spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
5439 spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
5442 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
5444 codec->patch_ops = via_patch_ops;
5446 codec->patch_ops.init = via_auto_init;
5447 codec->patch_ops.unsol_event = via_unsol_event;
5449 #ifdef CONFIG_SND_HDA_POWER_SAVE
5450 spec->loopback.amplist = vt1716S_loopbacks;
5458 /* capture mixer elements */
5459 static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
5460 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5461 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5462 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5463 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5464 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5465 HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
5468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5469 /* The multiple "Capture Source" controls confuse alsamixer
5470 * So call somewhat different..
5472 /* .name = "Capture Source", */
5473 .name = "Input Source",
5475 .info = via_mux_enum_info,
5476 .get = via_mux_enum_get,
5477 .put = via_mux_enum_put,
5482 static struct hda_verb vt2002P_volume_init_verbs[] = {
5484 * Unmute ADC0-1 and set the default input to mic-in
5486 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5487 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5490 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5493 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5494 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5495 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5496 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5497 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5498 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5500 /* MUX Indices: Mic = 0 */
5501 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5502 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5504 /* PW9 Output enable */
5505 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5507 /* Enable Boost Volume backdoor */
5510 /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5511 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5512 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5513 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5514 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5515 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5516 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5517 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5518 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5520 /* set MUX0/1/4/8 = 0 (AOW0) */
5521 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5522 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5523 {0x37, AC_VERB_SET_CONNECT_SEL, 0},
5524 {0x3b, AC_VERB_SET_CONNECT_SEL, 0},
5526 /* set PW0 index=0 (MW0) */
5527 {0x24, AC_VERB_SET_CONNECT_SEL, 0},
5529 /* Enable AOW0 to MW9 */
5535 static struct hda_verb vt2002P_uniwill_init_verbs[] = {
5536 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
5537 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5538 {0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
5539 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5540 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5541 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5542 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5546 static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
5550 .nid = 0x8, /* NID to query formats and rates */
5552 .open = via_playback_pcm_open,
5553 .prepare = via_playback_multi_pcm_prepare,
5554 .cleanup = via_playback_multi_pcm_cleanup,
5555 .close = via_pcm_open_close,
5559 static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
5563 .nid = 0x10, /* NID to query formats and rates */
5565 .open = via_pcm_open_close,
5566 .prepare = via_capture_pcm_prepare,
5567 .cleanup = via_capture_pcm_cleanup,
5568 .close = via_pcm_open_close,
5572 static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
5576 /* NID is set in via_build_pcms */
5578 .open = via_dig_playback_pcm_open,
5579 .close = via_dig_playback_pcm_close,
5580 .prepare = via_dig_playback_pcm_prepare,
5581 .cleanup = via_dig_playback_pcm_cleanup
5585 /* fill in the dac_nids table from the parsed pin configuration */
5586 static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
5587 const struct auto_pin_cfg *cfg)
5589 spec->multiout.num_dacs = 1;
5590 spec->multiout.dac_nids = spec->private_dac_nids;
5591 if (cfg->line_out_pins[0])
5592 spec->multiout.dac_nids[0] = 0x8;
5596 /* add playback controls from the parsed DAC table */
5597 static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
5598 const struct auto_pin_cfg *cfg)
5602 if (!cfg->line_out_pins[0])
5606 /* Line-Out: PortE */
5607 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5608 "Master Front Playback Volume",
5609 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5612 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5613 "Master Front Playback Switch",
5614 HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
5621 static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5628 spec->multiout.hp_nid = 0x9;
5629 spec->hp_independent_mode_index = 1;
5631 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5632 "Headphone Playback Volume",
5633 HDA_COMPOSE_AMP_VAL(
5634 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5638 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5639 "Headphone Playback Switch",
5640 HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
5644 create_hp_imux(spec);
5648 /* create playback/capture controls for input pins */
5649 static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
5650 const struct auto_pin_cfg *cfg)
5652 static char *labels[] = {
5653 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
5655 struct hda_input_mux *imux = &spec->private_imux[0];
5656 int i, err, idx = 0;
5658 for (i = 0; i < AUTO_PIN_LAST; i++) {
5659 if (!cfg->input_pins[i])
5662 switch (cfg->input_pins[i]) {
5663 case 0x2b: /* Mic */
5667 case 0x2a: /* Line In */
5671 case 0x29: /* Front Mic */
5675 err = via_new_analog_input(spec, labels[i], idx, 0x21);
5678 imux->items[imux->num_items].label = labels[i];
5679 imux->items[imux->num_items].index = idx;
5683 /* build volume/mute control of loopback */
5684 err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
5688 /* for internal loopback recording select */
5689 imux->items[imux->num_items].label = "Stereo Mixer";
5690 imux->items[imux->num_items].index = 3;
5693 /* for digital mic select */
5694 imux->items[imux->num_items].label = "Digital Mic";
5695 imux->items[imux->num_items].index = 4;
5701 static int vt2002P_parse_auto_config(struct hda_codec *codec)
5703 struct via_spec *spec = codec->spec;
5707 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
5711 err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
5715 if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
5716 return 0; /* can't find valid BIOS pin config */
5718 err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
5721 err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
5724 err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
5728 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5730 fill_dig_outs(codec);
5732 if (spec->kctls.list)
5733 spec->mixers[spec->num_mixers++] = spec->kctls.list;
5735 spec->input_mux = &spec->private_imux[0];
5738 spec->mixers[spec->num_mixers++] = via_hp_mixer;
5743 #ifdef CONFIG_SND_HDA_POWER_SAVE
5744 static struct hda_amp_list vt2002P_loopbacks[] = {
5745 { 0x21, HDA_INPUT, 0 },
5746 { 0x21, HDA_INPUT, 1 },
5747 { 0x21, HDA_INPUT, 2 },
5753 /* patch for vt2002P */
5754 static int patch_vt2002P(struct hda_codec *codec)
5756 struct via_spec *spec;
5759 /* create a codec specific record */
5760 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5766 /* automatic parse from the BIOS config */
5767 err = vt2002P_parse_auto_config(codec);
5772 printk(KERN_INFO "hda_codec: Cannot set up configuration "
5773 "from BIOS. Using genenic mode...\n");
5776 spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs;
5777 spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
5779 spec->stream_name_analog = "VT2002P Analog";
5780 spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
5781 spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
5783 spec->stream_name_digital = "VT2002P Digital";
5784 spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
5786 if (!spec->adc_nids && spec->input_mux) {
5787 spec->adc_nids = vt2002P_adc_nids;
5788 spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
5789 get_mux_nids(codec);
5790 override_mic_boost(codec, 0x2b, 0, 3, 40);
5791 override_mic_boost(codec, 0x29, 0, 3, 40);
5792 spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
5796 codec->patch_ops = via_patch_ops;
5798 codec->patch_ops.init = via_auto_init;
5799 codec->patch_ops.unsol_event = via_unsol_event;
5801 #ifdef CONFIG_SND_HDA_POWER_SAVE
5802 spec->loopback.amplist = vt2002P_loopbacks;
5810 /* capture mixer elements */
5811 static struct snd_kcontrol_new vt1812_capture_mixer[] = {
5812 HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
5813 HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
5814 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
5815 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
5816 HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
5817 HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
5820 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5821 /* The multiple "Capture Source" controls confuse alsamixer
5822 * So call somewhat different..
5824 .name = "Input Source",
5826 .info = via_mux_enum_info,
5827 .get = via_mux_enum_get,
5828 .put = via_mux_enum_put,
5833 static struct hda_verb vt1812_volume_init_verbs[] = {
5835 * Unmute ADC0-1 and set the default input to mic-in
5837 {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5838 {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5841 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5844 /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
5845 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5846 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5847 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5848 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5849 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5851 /* MUX Indices: Mic = 0 */
5852 {0x1e, AC_VERB_SET_CONNECT_SEL, 0},
5853 {0x1f, AC_VERB_SET_CONNECT_SEL, 0},
5855 /* PW9 Output enable */
5856 {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
5858 /* Enable Boost Volume backdoor */
5861 /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
5862 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5863 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5864 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5865 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5866 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5867 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5868 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5869 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5870 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5871 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5873 /* set MUX0/1/4/13/15 = 0 (AOW0) */
5874 {0x34, AC_VERB_SET_CONNECT_SEL, 0},
5875 {0x35, AC_VERB_SET_CONNECT_SEL, 0},
5876 {0x38, AC_VERB_SET_CONNECT_SEL, 0},
5877 {0x3c, AC_VERB_SET_CONNECT_SEL, 0},
5878 {0x3d, AC_VERB_SET_CONNECT_SEL, 0},
5880 /* Enable AOW0 to MW9 */
5886 static struct hda_verb vt1812_uniwill_init_verbs[] = {
5887 {0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
5888 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5889 {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
5890 {0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
5891 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
5892 {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5893 {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5894 {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
5898 static struct hda_pcm_stream vt1812_pcm_analog_playback = {
5902 .nid = 0x8, /* NID to query formats and rates */
5904 .open = via_playback_pcm_open,
5905 .prepare = via_playback_multi_pcm_prepare,
5906 .cleanup = via_playback_multi_pcm_cleanup,
5907 .close = via_pcm_open_close,
5911 static struct hda_pcm_stream vt1812_pcm_analog_capture = {
5915 .nid = 0x10, /* NID to query formats and rates */
5917 .open = via_pcm_open_close,
5918 .prepare = via_capture_pcm_prepare,
5919 .cleanup = via_capture_pcm_cleanup,
5920 .close = via_pcm_open_close,
5924 static struct hda_pcm_stream vt1812_pcm_digital_playback = {
5928 /* NID is set in via_build_pcms */
5930 .open = via_dig_playback_pcm_open,
5931 .close = via_dig_playback_pcm_close,
5932 .prepare = via_dig_playback_pcm_prepare,
5933 .cleanup = via_dig_playback_pcm_cleanup
5936 /* fill in the dac_nids table from the parsed pin configuration */
5937 static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
5938 const struct auto_pin_cfg *cfg)
5940 spec->multiout.num_dacs = 1;
5941 spec->multiout.dac_nids = spec->private_dac_nids;
5942 if (cfg->line_out_pins[0])
5943 spec->multiout.dac_nids[0] = 0x8;
5948 /* add playback controls from the parsed DAC table */
5949 static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
5950 const struct auto_pin_cfg *cfg)
5954 if (!cfg->line_out_pins[0])
5957 /* Line-Out: PortE */
5958 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5959 "Master Front Playback Volume",
5960 HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
5963 err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
5964 "Master Front Playback Switch",
5965 HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
5972 static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
5979 spec->multiout.hp_nid = 0x9;
5980 spec->hp_independent_mode_index = 1;
5983 err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
5984 "Headphone Playback Volume",
5985 HDA_COMPOSE_AMP_VAL(
5986 spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
5990 err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
5991 "Headphone Playback Switch",
5992 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5996 create_hp_imux(spec);
6000 /* create playback/capture controls for input pins */
6001 static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
6002 const struct auto_pin_cfg *cfg)
6004 static char *labels[] = {
6005 "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
6007 struct hda_input_mux *imux = &spec->private_imux[0];
6008 int i, err, idx = 0;
6010 for (i = 0; i < AUTO_PIN_LAST; i++) {
6011 if (!cfg->input_pins[i])
6014 switch (cfg->input_pins[i]) {
6015 case 0x2b: /* Mic */
6019 case 0x2a: /* Line In */
6023 case 0x29: /* Front Mic */
6027 err = via_new_analog_input(spec, labels[i], idx, 0x21);
6030 imux->items[imux->num_items].label = labels[i];
6031 imux->items[imux->num_items].index = idx;
6034 /* build volume/mute control of loopback */
6035 err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
6039 /* for internal loopback recording select */
6040 imux->items[imux->num_items].label = "Stereo Mixer";
6041 imux->items[imux->num_items].index = 5;
6044 /* for digital mic select */
6045 imux->items[imux->num_items].label = "Digital Mic";
6046 imux->items[imux->num_items].index = 6;
6052 static int vt1812_parse_auto_config(struct hda_codec *codec)
6054 struct via_spec *spec = codec->spec;
6058 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
6061 fill_dig_outs(codec);
6062 err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
6066 if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
6067 return 0; /* can't find valid BIOS pin config */
6069 err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
6072 err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
6075 err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
6079 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
6081 fill_dig_outs(codec);
6083 if (spec->kctls.list)
6084 spec->mixers[spec->num_mixers++] = spec->kctls.list;
6086 spec->input_mux = &spec->private_imux[0];
6089 spec->mixers[spec->num_mixers++] = via_hp_mixer;
6094 #ifdef CONFIG_SND_HDA_POWER_SAVE
6095 static struct hda_amp_list vt1812_loopbacks[] = {
6096 { 0x21, HDA_INPUT, 0 },
6097 { 0x21, HDA_INPUT, 1 },
6098 { 0x21, HDA_INPUT, 2 },
6104 /* patch for vt1812 */
6105 static int patch_vt1812(struct hda_codec *codec)
6107 struct via_spec *spec;
6110 /* create a codec specific record */
6111 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6117 /* automatic parse from the BIOS config */
6118 err = vt1812_parse_auto_config(codec);
6123 printk(KERN_INFO "hda_codec: Cannot set up configuration "
6124 "from BIOS. Using genenic mode...\n");
6128 spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs;
6129 spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
6131 spec->stream_name_analog = "VT1812 Analog";
6132 spec->stream_analog_playback = &vt1812_pcm_analog_playback;
6133 spec->stream_analog_capture = &vt1812_pcm_analog_capture;
6135 spec->stream_name_digital = "VT1812 Digital";
6136 spec->stream_digital_playback = &vt1812_pcm_digital_playback;
6139 if (!spec->adc_nids && spec->input_mux) {
6140 spec->adc_nids = vt1812_adc_nids;
6141 spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
6142 get_mux_nids(codec);
6143 override_mic_boost(codec, 0x2b, 0, 3, 40);
6144 override_mic_boost(codec, 0x29, 0, 3, 40);
6145 spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
6149 codec->patch_ops = via_patch_ops;
6151 codec->patch_ops.init = via_auto_init;
6152 codec->patch_ops.unsol_event = via_unsol_event;
6154 #ifdef CONFIG_SND_HDA_POWER_SAVE
6155 spec->loopback.amplist = vt1812_loopbacks;
6164 static struct hda_codec_preset snd_hda_preset_via[] = {
6165 { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
6166 { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
6167 { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
6168 { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
6169 { .id = 0x1106e710, .name = "VT1709 10-Ch",
6170 .patch = patch_vt1709_10ch},
6171 { .id = 0x1106e711, .name = "VT1709 10-Ch",
6172 .patch = patch_vt1709_10ch},
6173 { .id = 0x1106e712, .name = "VT1709 10-Ch",
6174 .patch = patch_vt1709_10ch},
6175 { .id = 0x1106e713, .name = "VT1709 10-Ch",
6176 .patch = patch_vt1709_10ch},
6177 { .id = 0x1106e714, .name = "VT1709 6-Ch",
6178 .patch = patch_vt1709_6ch},
6179 { .id = 0x1106e715, .name = "VT1709 6-Ch",
6180 .patch = patch_vt1709_6ch},
6181 { .id = 0x1106e716, .name = "VT1709 6-Ch",
6182 .patch = patch_vt1709_6ch},
6183 { .id = 0x1106e717, .name = "VT1709 6-Ch",
6184 .patch = patch_vt1709_6ch},
6185 { .id = 0x1106e720, .name = "VT1708B 8-Ch",
6186 .patch = patch_vt1708B_8ch},
6187 { .id = 0x1106e721, .name = "VT1708B 8-Ch",
6188 .patch = patch_vt1708B_8ch},
6189 { .id = 0x1106e722, .name = "VT1708B 8-Ch",
6190 .patch = patch_vt1708B_8ch},
6191 { .id = 0x1106e723, .name = "VT1708B 8-Ch",
6192 .patch = patch_vt1708B_8ch},
6193 { .id = 0x1106e724, .name = "VT1708B 4-Ch",
6194 .patch = patch_vt1708B_4ch},
6195 { .id = 0x1106e725, .name = "VT1708B 4-Ch",
6196 .patch = patch_vt1708B_4ch},
6197 { .id = 0x1106e726, .name = "VT1708B 4-Ch",
6198 .patch = patch_vt1708B_4ch},
6199 { .id = 0x1106e727, .name = "VT1708B 4-Ch",
6200 .patch = patch_vt1708B_4ch},
6201 { .id = 0x11060397, .name = "VT1708S",
6202 .patch = patch_vt1708S},
6203 { .id = 0x11061397, .name = "VT1708S",
6204 .patch = patch_vt1708S},
6205 { .id = 0x11062397, .name = "VT1708S",
6206 .patch = patch_vt1708S},
6207 { .id = 0x11063397, .name = "VT1708S",
6208 .patch = patch_vt1708S},
6209 { .id = 0x11064397, .name = "VT1708S",
6210 .patch = patch_vt1708S},
6211 { .id = 0x11065397, .name = "VT1708S",
6212 .patch = patch_vt1708S},
6213 { .id = 0x11066397, .name = "VT1708S",
6214 .patch = patch_vt1708S},
6215 { .id = 0x11067397, .name = "VT1708S",
6216 .patch = patch_vt1708S},
6217 { .id = 0x11060398, .name = "VT1702",
6218 .patch = patch_vt1702},
6219 { .id = 0x11061398, .name = "VT1702",
6220 .patch = patch_vt1702},
6221 { .id = 0x11062398, .name = "VT1702",
6222 .patch = patch_vt1702},
6223 { .id = 0x11063398, .name = "VT1702",
6224 .patch = patch_vt1702},
6225 { .id = 0x11064398, .name = "VT1702",
6226 .patch = patch_vt1702},
6227 { .id = 0x11065398, .name = "VT1702",
6228 .patch = patch_vt1702},
6229 { .id = 0x11066398, .name = "VT1702",
6230 .patch = patch_vt1702},
6231 { .id = 0x11067398, .name = "VT1702",
6232 .patch = patch_vt1702},
6233 { .id = 0x11060428, .name = "VT1718S",
6234 .patch = patch_vt1718S},
6235 { .id = 0x11064428, .name = "VT1718S",
6236 .patch = patch_vt1718S},
6237 { .id = 0x11060441, .name = "VT2020",
6238 .patch = patch_vt1718S},
6239 { .id = 0x11064441, .name = "VT1828S",
6240 .patch = patch_vt1718S},
6241 { .id = 0x11060433, .name = "VT1716S",
6242 .patch = patch_vt1716S},
6243 { .id = 0x1106a721, .name = "VT1716S",
6244 .patch = patch_vt1716S},
6245 { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
6246 { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
6247 { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
6248 { .id = 0x11060440, .name = "VT1818S",
6249 .patch = patch_vt1708S},
6253 MODULE_ALIAS("snd-hda-codec-id:1106*");
6255 static struct hda_codec_preset_list via_list = {
6256 .preset = snd_hda_preset_via,
6257 .owner = THIS_MODULE,
6260 MODULE_LICENSE("GPL");
6261 MODULE_DESCRIPTION("VIA HD-audio codec");
6263 static int __init patch_via_init(void)
6265 return snd_hda_add_codec_preset(&via_list);
6268 static void __exit patch_via_exit(void)
6270 snd_hda_delete_codec_preset(&via_list);
6273 module_init(patch_via_init)
6274 module_exit(patch_via_exit)